Expand internal stop reasons.

Add explicit reasons for when a job is stopped because the real-time
clock was updated and for when a job called jobFinished() on its own
(...why did we not have this to begin with???).

Bug: 141645789
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/job
Test: atest frameworks/base/services/tests/mockingservicestests/src/com/android/server/job
Test: atest ContentResolverTest (all)
Test: atest CtsJobSchedulerTestCases
Test: atest CtsSyncManagerTest
Test: atest SyncManagerTest
Test: atest SyncOperationTest
Test: atest SyncRequestTest
Change-Id: I61392c55355d2526a32ea9597a0010b04f3875ac
This commit is contained in:
Kweku Adams
2021-04-21 15:03:53 -07:00
parent 805535cc55
commit 6decc507bf
3 changed files with 31 additions and 2 deletions

View File

@@ -82,6 +82,15 @@ public class JobParameters implements Parcelable {
* @hide
*/
public static final int INTERNAL_STOP_REASON_DATA_CLEARED = 8;
/**
* @hide
*/
public static final int INTERNAL_STOP_REASON_RTC_UPDATED = 9;
/**
* The app called jobFinished() on its own.
* @hide
*/
public static final int INTERNAL_STOP_REASON_SUCCESSFUL_FINISH = 10;
/**
* All the stop reason codes. This should be regarded as an immutable array at runtime.
@@ -116,6 +125,10 @@ public class JobParameters implements Parcelable {
case INTERNAL_STOP_REASON_DEVICE_IDLE: return "device_idle";
case INTERNAL_STOP_REASON_DEVICE_THERMAL: return "thermal";
case INTERNAL_STOP_REASON_RESTRICTED_BUCKET: return "restricted_bucket";
case INTERNAL_STOP_REASON_UNINSTALL: return "uninstall";
case INTERNAL_STOP_REASON_DATA_CLEARED: return "data_cleared";
case INTERNAL_STOP_REASON_RTC_UPDATED: return "rtc_updated";
case INTERNAL_STOP_REASON_SUCCESSFUL_FINISH: return "successful_finish";
default: return "unknown:" + reasonCode;
}
}

View File

@@ -1497,7 +1497,7 @@ public class JobSchedulerService extends com.android.server.SystemService
Slog.v(TAG, " replacing " + oldJob + " with " + newJob);
}
cancelJobImplLocked(oldJob, newJob, JobParameters.STOP_REASON_SYSTEM_PROCESSING,
JobParameters.INTERNAL_STOP_REASON_CANCELED, "deferred rtc calculation");
JobParameters.INTERNAL_STOP_REASON_RTC_UPDATED, "deferred rtc calculation");
}
}
};

View File

@@ -409,7 +409,20 @@ public final class JobServiceContext implements ServiceConnection {
}
void doJobFinished(JobCallback cb, int jobId, boolean reschedule) {
doCallback(cb, reschedule, "app called jobFinished");
final long ident = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
if (!verifyCallerLocked(cb)) {
return;
}
mParams.setStopReason(JobParameters.STOP_REASON_UNDEFINED,
JobParameters.INTERNAL_STOP_REASON_SUCCESSFUL_FINISH,
"app called jobFinished");
doCallbackLocked(reschedule, "app called jobFinished");
}
} finally {
Binder.restoreCallingIdentity(ident);
}
}
void doAcknowledgeStopMessage(JobCallback cb, int jobId, boolean reschedule) {
@@ -433,6 +446,9 @@ public final class JobServiceContext implements ServiceConnection {
}
final JobWorkItem work = mRunningJob.dequeueWorkLocked();
if (work == null && !mRunningJob.hasExecutingWorkLocked()) {
mParams.setStopReason(JobParameters.STOP_REASON_UNDEFINED,
JobParameters.INTERNAL_STOP_REASON_SUCCESSFUL_FINISH,
"last work dequeued");
// This will finish the job.
doCallbackLocked(false, "last work dequeued");
}