| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.server.job.controllers; |
| 18 |
|
| 19 |
import static com.android.server.job.JobSchedulerService.DEBUG; |
| 20 |
|
| 21 |
import android.annotation.NonNull; |
| 22 |
import android.content.Context; |
| 23 |
import android.provider.DeviceConfig; |
| 24 |
import android.util.IndentingPrintWriter; |
| 25 |
import android.util.Slog; |
| 26 |
import android.util.proto.ProtoOutputStream; |
| 27 |
|
| 28 |
import com.android.internal.annotations.GuardedBy; |
| 29 |
import com.android.internal.util.FrameworkStatsLog; |
| 30 |
import com.android.server.job.JobSchedulerService; |
| 31 |
import com.android.server.job.JobSchedulerService.Constants; |
| 32 |
import com.android.server.job.StateChangedListener; |
| 33 |
|
| 34 |
import java.util.function.Predicate; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public abstract class StateController { |
| 42 |
private static final String TAG = "JobScheduler.SC"; |
| 43 |
|
| 44 |
protected final JobSchedulerService mService; |
| 45 |
protected final StateChangedListener mStateChangedListener; |
| 46 |
protected final Context mContext; |
| 47 |
protected final Object mLock; |
| 48 |
protected final Constants mConstants; |
| 49 |
|
| 50 |
StateController(JobSchedulerService service) { |
| 51 |
mService = service; |
| 52 |
mStateChangedListener = service; |
| 53 |
mContext = service.getTestableContext(); |
| 54 |
mLock = service.getLock(); |
| 55 |
mConstants = service.getConstants(); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public void onSystemServicesReady() { |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public abstract void maybeStartTrackingJobLocked(JobStatus jobStatus, JobStatus lastJob); |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public void prepareForExecutionLocked(JobStatus jobStatus) { |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public void unprepareFromExecutionLocked(JobStatus jobStatus) { |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public abstract void maybeStopTrackingJobLocked(JobStatus jobStatus, JobStatus incomingJob, |
| 89 |
boolean forUpdate); |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public void rescheduleForFailureLocked(JobStatus newJob, JobStatus failureToReschedule) { |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
public void prepareForUpdatedConstantsLocked() {} |
| 99 |
|
| 100 |
|
| 101 |
public void processConstantLocked(@NonNull DeviceConfig.Properties properties, |
| 102 |
@NonNull String key) {} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public void onConstantsUpdatedLocked() { |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
public void onAppRemovedLocked(String packageName, int uid) { |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
public void onUserAddedLocked(int userId) { |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
public void onUserRemovedLocked(int userId) { |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public void evaluateStateLocked(JobStatus jobStatus) { |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
public void reevaluateStateLocked(int uid) { |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
@GuardedBy("mLock") |
| 140 |
public void onBatteryStateChangedLocked() { |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
@GuardedBy("mLock") |
| 148 |
public void onUidBiasChangedLocked(int uid, int prevBias, int newBias) { |
| 149 |
} |
| 150 |
|
| 151 |
protected boolean wouldBeReadyWithConstraintLocked(JobStatus jobStatus, int constraint) { |
| 152 |
|
| 153 |
final boolean jobWouldBeReady = jobStatus.wouldBeReadyWithConstraint(constraint); |
| 154 |
if (DEBUG) { |
| 155 |
Slog.v(TAG, "wouldBeReadyWithConstraintLocked: " + jobStatus.toShortString() |
| 156 |
+ " constraint=" + constraint |
| 157 |
+ " readyWithConstraint=" + jobWouldBeReady); |
| 158 |
} |
| 159 |
if (!jobWouldBeReady) { |
| 160 |
|
| 161 |
return false; |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
return mService.areComponentsInPlaceLocked(jobStatus); |
| 167 |
} |
| 168 |
|
| 169 |
protected void logDeviceWideConstraintStateToStatsd(int constraint, boolean satisfied) { |
| 170 |
FrameworkStatsLog.write( |
| 171 |
FrameworkStatsLog.DEVICE_WIDE_JOB_CONSTRAINT_CHANGED, |
| 172 |
JobStatus.getProtoConstraint(constraint), |
| 173 |
satisfied |
| 174 |
? FrameworkStatsLog.DEVICE_WIDE_JOB_CONSTRAINT_CHANGED__STATE__SATISFIED |
| 175 |
: FrameworkStatsLog.DEVICE_WIDE_JOB_CONSTRAINT_CHANGED__STATE__UNSATISFIED); |
| 176 |
} |
| 177 |
|
| 178 |
public abstract void dumpControllerStateLocked(IndentingPrintWriter pw, |
| 179 |
Predicate<JobStatus> predicate); |
| 180 |
public void dumpControllerStateLocked(ProtoOutputStream proto, long fieldId, |
| 181 |
Predicate<JobStatus> predicate) {} |
| 182 |
|
| 183 |
|
| 184 |
public void dumpConstants(IndentingPrintWriter pw) { |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
public void dumpConstants(ProtoOutputStream proto) { |
| 189 |
} |
| 190 |
} |