Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b0da63c2 authored by Christopher Tate's avatar Christopher Tate
Browse files

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
parent 6594be12
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -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,