From b0da63c20214e4cb292398c7e5300c2cafbd746b Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Wed, 9 Oct 2019 14:26:52 -0700 Subject: [PATCH] Fix job enqueue bug when changing constraints If a job with pending work had new work enqueued but with a changed set of constraints (including temporal constraints), the system was accidentally discarding the new work item, leaving only the previously-pending ones. Now that's fixed: changing constraints works as expected, changing the execution criteria for the job, retaining all pending work, and adding the new work to the end of the queue. Bug: 141707520 Test: atest CtsJobSchedulerSharedUidTestCases:EnqueueJobWorkTest#testEnqueuedWorkNewConstraints Change-Id: I92e42049937847922f1fa9a10432ec87676408d0 --- .../com/android/server/job/JobSchedulerService.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java index 329d4b7c8f1e8..90659b5f10a52 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java +++ b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java @@ -979,17 +979,18 @@ public class JobSchedulerService extends com.android.server.SystemService // This may throw a SecurityException. jobStatus.prepareLocked(); - if (work != null) { - // If work has been supplied, enqueue it into the new job. - jobStatus.enqueueWorkLocked(work); - } - if (toCancel != null) { // Implicitly replaces the existing job record with the new instance cancelJobImplLocked(toCancel, jobStatus, "job rescheduled by app"); } else { startTrackingJobLocked(jobStatus, null); } + + if (work != null) { + // If work has been supplied, enqueue it into the new job. + jobStatus.enqueueWorkLocked(work); + } + StatsLog.write_non_chained(StatsLog.SCHEDULED_JOB_STATE_CHANGED, uId, null, jobStatus.getBatteryName(), StatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__SCHEDULED,