OSDN Git Service

Skip cancelling jobs with FLAG_WILL_BE_FOREGROUND.
authorJeff Sharkey <jsharkey@android.com>
Wed, 1 Jun 2016 21:51:19 +0000 (15:51 -0600)
committerJeff Sharkey <jsharkey@android.com>
Wed, 1 Jun 2016 21:51:50 +0000 (15:51 -0600)
When FLAG_WILL_BE_FOREGROUND is set on a job (such as a download), we
need to treat the job as if it had a foreground service running so
it can continue making forward progress.  We already ignore the device
idle state when offering to start the job, so this just avoids the
hiccup of stopping the job only to restart it a minute later.

Bug: 26571724
Change-Id: I348903dd3a7dd7104b0c1bf4310e2a48655d2588

services/core/java/com/android/server/job/JobSchedulerService.java

index 899aada..27b3aa2 100644 (file)
@@ -662,11 +662,13 @@ public final class JobSchedulerService extends com.android.server.SystemService
     public void onDeviceIdleStateChanged(boolean deviceIdle) {
         synchronized (mLock) {
             if (deviceIdle) {
-                // When becoming idle, make sure no jobs are actively running.
+                // When becoming idle, make sure no jobs are actively running,
+                // except those using the idle exemption flag.
                 for (int i=0; i<mActiveServices.size(); i++) {
                     JobServiceContext jsc = mActiveServices.get(i);
                     final JobStatus executing = jsc.getRunningJob();
-                    if (executing != null) {
+                    if (executing != null
+                            && (executing.getFlags() & JobInfo.FLAG_WILL_BE_FOREGROUND) == 0) {
                         jsc.cancelExecutingJob(JobParameters.REASON_DEVICE_IDLE);
                     }
                 }