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

Commit 50e341f2 authored by Kweku Adams's avatar Kweku Adams
Browse files

Remove running jobs from pending list.

Already running jobs shouldn't be on the pending queue. Leaving them in
the queue could lead to incorrect behavior.

Bug: 228334264
Test: Android builds
Change-Id: I1016c6f74bfdba89907af1f1659566b3dedf1583
parent 9f3f150f
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -690,6 +690,12 @@ class JobConcurrencyManager {
        int projectedRunningCount = numRunningJobs;
        while ((nextPending = pendingJobQueue.next()) != null) {
            if (mRunningJobs.contains(nextPending)) {
                // Should never happen.
                Slog.wtf(TAG, "Pending queue contained a running job");
                if (DEBUG) {
                    Slog.e(TAG, "Pending+running job: " + nextPending);
                }
                pendingJobQueue.remove(nextPending);
                continue;
            }

@@ -1137,7 +1143,8 @@ class JobConcurrencyManager {
            }
        }

        if (mActiveServices.size() >= STANDARD_CONCURRENCY_LIMIT) {
        final PendingJobQueue pendingJobQueue = mService.getPendingJobQueue();
        if (mActiveServices.size() >= STANDARD_CONCURRENCY_LIMIT || pendingJobQueue.size() == 0) {
            worker.clearPreferredUid();
            // We're over the limit (because the TOP app scheduled a lot of EJs). Don't start
            // running anything new until we get back below the limit.
@@ -1145,7 +1152,6 @@ class JobConcurrencyManager {
            return;
        }

        final PendingJobQueue pendingJobQueue = mService.getPendingJobQueue();
        if (worker.getPreferredUid() != JobServiceContext.NO_PREFERRED_UID) {
            updateCounterConfigLocked();
            // Preemption case needs special care.
@@ -1162,6 +1168,12 @@ class JobConcurrencyManager {
            pendingJobQueue.resetIterator();
            while ((nextPending = pendingJobQueue.next()) != null) {
                if (mRunningJobs.contains(nextPending)) {
                    // Should never happen.
                    Slog.wtf(TAG, "Pending queue contained a running job");
                    if (DEBUG) {
                        Slog.e(TAG, "Pending+running job: " + nextPending);
                    }
                    pendingJobQueue.remove(nextPending);
                    continue;
                }

@@ -1239,6 +1251,12 @@ class JobConcurrencyManager {
            while ((nextPending = pendingJobQueue.next()) != null) {

                if (mRunningJobs.contains(nextPending)) {
                    // Should never happen.
                    Slog.wtf(TAG, "Pending queue contained a running job");
                    if (DEBUG) {
                        Slog.e(TAG, "Pending+running job: " + nextPending);
                    }
                    pendingJobQueue.remove(nextPending);
                    continue;
                }