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
This commit is contained in:
Christopher Tate
2019-10-09 14:26:52 -07:00
parent 6594be12c9
commit b0da63c202

View File

@@ -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,