From d942698ccca4f603e370b97a6ca2736824c2230b Mon Sep 17 00:00:00 2001 From: Kweku Adams Date: Thu, 25 Feb 2021 14:14:26 -0800 Subject: [PATCH] Disallow long regular jobs in Doze and battery saver. There are a subset of regular jobs that could run while the device is dozing or in battery saver. Make sure we don't let those jobs run longer than their minimum execution guarantee in those states. Bug: 171305774 Test: atest CtsJobSchedulerTestCases Change-Id: Ib2aa328225f0a485b3a62b6be6fc26d18e150519 --- .../server/job/JobConcurrencyManager.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 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 af9771553063d..e8e2c27f1554c 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java +++ b/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java @@ -753,13 +753,22 @@ class JobConcurrencyManager { return null; } + // We're over the minimum guaranteed runtime. Stop the job if we're over config limits, + // there are pending jobs that could replace this one, or the device state is not conducive + // to long runs. + + if (mPowerManager.isPowerSaveMode()) { + return "battery saver"; + } + if (mPowerManager.isDeviceIdleMode()) { + return "deep doze"; + } + // Update config in case memory usage has changed significantly. updateCounterConfigLocked(); @WorkType final int workType = context.getRunningJobWorkType(); - // We're over the minimum guaranteed runtime. Stop the job if we're over config limits or - // there are pending jobs that could replace this one. if (mRunningJobs.size() > mWorkTypeConfig.getMaxTotal() || mWorkCountTracker.isOverTypeLimit(workType)) { return "too many jobs running"; @@ -786,13 +795,6 @@ class JobConcurrencyManager { return "blocking " + workTypeToString(workType) + " queue"; } } - - if (mPowerManager.isPowerSaveMode()) { - return "battery saver"; - } - if (mPowerManager.isDeviceIdleMode()) { - return "deep doze"; - } } // Easy check. If there are pending jobs of the same work type, then we know that