From 50e341f29cd211f802046b91a0e89884186ac912 Mon Sep 17 00:00:00 2001 From: Kweku Adams Date: Mon, 25 Apr 2022 17:45:15 +0000 Subject: [PATCH] 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 --- .../server/job/JobConcurrencyManager.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java b/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java index c8ec89475050f..c86353c844675 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java +++ b/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java @@ -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; }