From be0c4175398ff5d7e13209e833b3037cdd0207d7 Mon Sep 17 00:00:00 2001 From: Matthew Williams Date: Wed, 6 Aug 2014 18:14:16 -0700 Subject: [PATCH] JobScheduler idle mode not being properly triggered Issue with how the pending intent was being created - the component name being explicitly set on the intent somehow caused the intent to not be delivered. Fix: no longer set the component name on the intent. BUG: 16798118 Change-Id: I86b08b2a47067dc9b8da8b85450bc338e0826aca --- .../android/server/job/JobSchedulerService.java | 32 +++++++++++++++++++--- .../server/job/controllers/IdleController.java | 15 ++++++---- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/services/core/java/com/android/server/job/JobSchedulerService.java b/services/core/java/com/android/server/job/JobSchedulerService.java index 9ac90dca1d2c..14457ec9c04c 100644 --- a/services/core/java/com/android/server/job/JobSchedulerService.java +++ b/services/core/java/com/android/server/job/JobSchedulerService.java @@ -74,7 +74,7 @@ public class JobSchedulerService extends com.android.server.SystemService static final boolean DEBUG = true; /** The number of concurrent jobs we run at one time. */ private static final int MAX_JOB_CONTEXTS_COUNT = 3; - static final String TAG = "JobManagerService"; + static final String TAG = "JobSchedulerService"; /** Master list of jobs. */ final JobStore mJobs; @@ -88,6 +88,11 @@ public class JobSchedulerService extends com.android.server.SystemService */ static final int MIN_IDLE_COUNT = 1; /** + * Minimum # of charging jobs that must be ready in order to force the JMS to schedule things + * early. + */ + static final int MIN_CHARGING_COUNT = 1; + /** * Minimum # of connectivity jobs that must be ready in order to force the JMS to schedule * things early. */ @@ -95,8 +100,9 @@ public class JobSchedulerService extends com.android.server.SystemService /** * Minimum # of jobs (with no particular constraints) for which the JMS will be happy running * some work early. + * This is correlated with the amount of batching we'll be able to do. */ - static final int MIN_READY_JOBS_COUNT = 4; + static final int MIN_READY_JOBS_COUNT = 2; /** * Track Services that have currently active or pending jobs. The index is provided by @@ -546,7 +552,8 @@ public class JobSchedulerService extends com.android.server.SystemService */ private void maybeQueueReadyJobsForExecutionH() { synchronized (mJobs) { - int idleCount = 0; + int chargingCount = 0; + int idleCount = 0; int backoffCount = 0; int connectivityCount = 0; List runnableJobs = new ArrayList(); @@ -563,17 +570,34 @@ public class JobSchedulerService extends com.android.server.SystemService if (job.hasConnectivityConstraint() || job.hasUnmeteredConstraint()) { connectivityCount++; } + if (job.hasChargingConstraint()) { + chargingCount++; + } runnableJobs.add(job); } else if (isReadyToBeCancelledLocked(job)) { stopJobOnServiceContextLocked(job); } } - if (backoffCount > 0 || idleCount >= MIN_IDLE_COUNT || + if (backoffCount > 0 || + idleCount >= MIN_IDLE_COUNT || connectivityCount >= MIN_CONNECTIVITY_COUNT || + chargingCount >= MIN_CHARGING_COUNT || runnableJobs.size() >= MIN_READY_JOBS_COUNT) { + if (DEBUG) { + Slog.d(TAG, "maybeQueueReadyJobsForExecutionH: Running jobs."); + } for (int i=0; i