summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chris Tate <ctate@android.com> 2017-03-18 00:39:53 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2017-03-18 00:39:59 +0000
commit02ffbf039fb44919ead94de04c991a0957c79431 (patch)
tree89b0d848517ddb27cb41be1d93c395a3eb2a6b59
parent02a2813ad2e4c4db0ce8fbb1049c2cd1630ca8e6 (diff)
parentb1d6448ec4f9af79776cc2e9eb951b659212b0bb (diff)
Merge "Correctly check expired jobs against active ones"
-rw-r--r--services/core/java/com/android/server/job/JobSchedulerService.java24
1 files changed, 19 insertions, 5 deletions
diff --git a/services/core/java/com/android/server/job/JobSchedulerService.java b/services/core/java/com/android/server/job/JobSchedulerService.java
index b316a3bd0639..940f621a47d1 100644
--- a/services/core/java/com/android/server/job/JobSchedulerService.java
+++ b/services/core/java/com/android/server/job/JobSchedulerService.java
@@ -1106,8 +1106,7 @@ public final class JobSchedulerService extends com.android.server.SystemService
JobStatus runNow = (JobStatus) message.obj;
// runNow can be null, which is a controller's way of indicating that its
// state is such that all ready jobs should be run immediately.
- if (runNow != null && !mPendingJobs.contains(runNow)
- && mJobs.containsJob(runNow)) {
+ if (runNow != null && isReadyToBeExecutedLocked(runNow)) {
mJobPackageTracker.notePending(runNow);
mPendingJobs.add(runNow);
}
@@ -1310,12 +1309,27 @@ public final class JobSchedulerService extends com.android.server.SystemService
* - The component is enabled and runnable.
*/
private boolean isReadyToBeExecutedLocked(JobStatus job) {
+ final boolean jobExists = mJobs.containsJob(job);
final boolean jobReady = job.isReady();
final boolean jobPending = mPendingJobs.contains(job);
final boolean jobActive = isCurrentlyActiveLocked(job);
final int userId = job.getUserId();
final boolean userStarted = ArrayUtils.contains(mStartedUsers, userId);
+
+ if (DEBUG) {
+ Slog.v(TAG, "isReadyToBeExecutedLocked: " + job.toShortString()
+ + " exists=" + jobExists
+ + " ready=" + jobReady + " pending=" + jobPending
+ + " active=" + jobActive + " userStarted=" + userStarted);
+ }
+
+ // Short circuit: don't do the expensive PM check unless we really think
+ // we might need to run this job now.
+ if (!jobExists || !userStarted || !jobReady || jobPending || jobActive) {
+ return false;
+ }
+
final boolean componentPresent;
try {
componentPresent = (AppGlobals.getPackageManager().getServiceInfo(
@@ -1327,11 +1341,11 @@ public final class JobSchedulerService extends com.android.server.SystemService
if (DEBUG) {
Slog.v(TAG, "isReadyToBeExecutedLocked: " + job.toShortString()
- + " ready=" + jobReady + " pending=" + jobPending
- + " active=" + jobActive + " userStarted=" + userStarted
+ " componentPresent=" + componentPresent);
}
- return userStarted && componentPresent && jobReady && !jobPending && !jobActive;
+
+ // Everything else checked out so far, so this is the final yes/no check
+ return componentPresent;
}
/**