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

Commit 525aacae authored by Shreyas Basarge's avatar Shreyas Basarge Committed by android-build-merger
Browse files

Fix for JobScheduler dropping periodic jobs

am: 73f1025f

* commit '73f1025f':
  Fix for JobScheduler dropping periodic jobs
parents 971203ed 73f1025f
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -330,7 +330,7 @@ public class JobSchedulerService extends com.android.server.SystemService


    private void cancelJobImpl(JobStatus cancelled) {
    private void cancelJobImpl(JobStatus cancelled) {
        if (DEBUG) Slog.d(TAG, "CANCEL: " + cancelled.toShortString());
        if (DEBUG) Slog.d(TAG, "CANCEL: " + cancelled.toShortString());
        stopTrackingJob(cancelled);
        stopTrackingJob(cancelled, true /* writeBack */);
        synchronized (mJobs) {
        synchronized (mJobs) {
            // Remove from pending queue.
            // Remove from pending queue.
            mPendingJobs.remove(cancelled);
            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
     * Called when we want to remove a JobStatus object that we've finished executing. Returns the
     * object removed.
     * object removed.
     */
     */
    private boolean stopTrackingJob(JobStatus jobStatus) {
    private boolean stopTrackingJob(JobStatus jobStatus, boolean writeBack) {
        boolean removed;
        boolean removed;
        boolean rocking;
        boolean rocking;
        synchronized (mJobs) {
        synchronized (mJobs) {
            // Remove from store as well as controllers.
            // Remove from store as well as controllers.
            removed = mJobs.remove(jobStatus);
            removed = mJobs.remove(jobStatus, writeBack);
            rocking = mReadyToRock;
            rocking = mReadyToRock;
        }
        }
        if (removed && rocking) {
        if (removed && rocking) {
@@ -645,7 +645,9 @@ public class JobSchedulerService extends com.android.server.SystemService
        if (DEBUG) {
        if (DEBUG) {
            Slog.d(TAG, "Completed " + jobStatus + ", reschedule=" + needsReschedule);
            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) {
            if (DEBUG) {
                Slog.d(TAG, "Could not find job to remove. Was job removed while executing?");
                Slog.d(TAG, "Could not find job to remove. Was job removed while executing?");
            }
            }
+3 −2
Original line number Original line Diff line number Diff line
@@ -159,9 +159,10 @@ public class JobStore {


    /**
    /**
     * Remove the provided job. Will also delete the job if it was persisted.
     * 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.
     * @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);
        boolean removed = mJobSet.remove(jobStatus);
        if (!removed) {
        if (!removed) {
            if (DEBUG) {
            if (DEBUG) {
@@ -169,7 +170,7 @@ public class JobStore {
            }
            }
            return false;
            return false;
        }
        }
        if (jobStatus.isPersisted()) {
        if (writeBack && jobStatus.isPersisted()) {
            maybeWriteStatusToDiskAsync();
            maybeWriteStatusToDiskAsync();
        }
        }
        return removed;
        return removed;