Fix for JobScheduler dropping periodic jobs
Skip writing to disk when a periodic job is removed from jobStore after it completes execution. Change-Id: Ib4f2cf18554bf9c87138c1984c96cc62f8dbf7e2 Bug: 27147454
This commit is contained in:
@@ -330,7 +330,7 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
|
||||
private void cancelJobImpl(JobStatus cancelled) {
|
||||
if (DEBUG) Slog.d(TAG, "CANCEL: " + cancelled.toShortString());
|
||||
stopTrackingJob(cancelled);
|
||||
stopTrackingJob(cancelled, true /* writeBack */);
|
||||
synchronized (mJobs) {
|
||||
// Remove from pending queue.
|
||||
mPendingJobs.remove(cancelled);
|
||||
@@ -509,12 +509,12 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
* Called when we want to remove a JobStatus object that we've finished executing. Returns the
|
||||
* object removed.
|
||||
*/
|
||||
private boolean stopTrackingJob(JobStatus jobStatus) {
|
||||
private boolean stopTrackingJob(JobStatus jobStatus, boolean writeBack) {
|
||||
boolean removed;
|
||||
boolean rocking;
|
||||
synchronized (mJobs) {
|
||||
// Remove from store as well as controllers.
|
||||
removed = mJobs.remove(jobStatus);
|
||||
removed = mJobs.remove(jobStatus, writeBack);
|
||||
rocking = mReadyToRock;
|
||||
}
|
||||
if (removed && rocking) {
|
||||
@@ -645,7 +645,9 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Completed " + jobStatus + ", reschedule=" + needsReschedule);
|
||||
}
|
||||
if (!stopTrackingJob(jobStatus)) {
|
||||
// Do not write back immediately if this is a periodic job. The job may get lost if system
|
||||
// shuts down before it is added back.
|
||||
if (!stopTrackingJob(jobStatus, !jobStatus.getJob().isPeriodic())) {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Could not find job to remove. Was job removed while executing?");
|
||||
}
|
||||
|
||||
@@ -159,9 +159,10 @@ public class JobStore {
|
||||
|
||||
/**
|
||||
* Remove the provided job. Will also delete the job if it was persisted.
|
||||
* @param writeBack If true, the job will be deleted (if it was persisted) immediately.
|
||||
* @return Whether or not the job existed to be removed.
|
||||
*/
|
||||
public boolean remove(JobStatus jobStatus) {
|
||||
public boolean remove(JobStatus jobStatus, boolean writeBack) {
|
||||
boolean removed = mJobSet.remove(jobStatus);
|
||||
if (!removed) {
|
||||
if (DEBUG) {
|
||||
@@ -169,7 +170,7 @@ public class JobStore {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (jobStatus.isPersisted()) {
|
||||
if (writeBack && jobStatus.isPersisted()) {
|
||||
maybeWriteStatusToDiskAsync();
|
||||
}
|
||||
return removed;
|
||||
|
||||
Reference in New Issue
Block a user