OSDN Git Service

Reschedule jobs that crash partway through
authorChristopher Tate <ctate@google.com>
Thu, 30 Mar 2017 00:42:39 +0000 (17:42 -0700)
committerChristopher Tate <ctate@google.com>
Thu, 30 Mar 2017 01:12:36 +0000 (18:12 -0700)
We were properly re-running jobs if the app hung during their
execution, but outright crashes wound up with the scheduled job
being dropped.  That's bad; it can easily lead to broken monitoring
in the case of content-triggered jobs.

We now reschedule with backoff when this happens.  In addition, to
mitigate the impact of repeatedly crashing apps, we now enforce a
minimum backoff interval of 10 seconds for automatic reschedules.

Bug 36030229
Test: manual

Change-Id: Ib5da583d7901d1255066c48558b35186eb641e17

core/java/android/app/job/JobInfo.java
services/core/java/com/android/server/job/JobServiceContext.java

index 78e4c0d..f9094c0 100644 (file)
@@ -83,6 +83,9 @@ public class JobInfo implements Parcelable {
     /* Minimum flex for a periodic job, in milliseconds. */
     private static final long MIN_FLEX_MILLIS = 5 * 60 * 1000L; // 5 minutes
 
+    /* Minimum backoff interval for a job, in milliseconds */
+    private static final long MIN_BACKOFF_MILLIS = 10 * 1000L;      // 10 seconds
+
     /**
      * Query the minimum interval allowed for periodic scheduled jobs.  Attempting
      * to declare a smaller period that this when scheduling a job will result in a
@@ -106,6 +109,14 @@ public class JobInfo implements Parcelable {
     }
 
     /**
+     * Query the minimum automatic-reschedule backoff interval permitted for jobs.
+     * @hide
+     */
+    public static final long getMinBackoffMillis() {
+        return MIN_BACKOFF_MILLIS;
+    }
+
+    /**
      * Default type of backoff.
      * @hide
      */
@@ -361,7 +372,8 @@ public class JobInfo implements Parcelable {
      * job does not recur periodically.
      */
     public long getIntervalMillis() {
-        return intervalMillis >= getMinPeriodMillis() ? intervalMillis : getMinPeriodMillis();
+        final long minInterval = getMinPeriodMillis();
+        return intervalMillis >= minInterval ? intervalMillis : minInterval;
     }
 
     /**
@@ -381,7 +393,8 @@ public class JobInfo implements Parcelable {
      * to 5 seconds.
      */
     public long getInitialBackoffMillis() {
-        return initialBackoffMillis;
+        final long minBackoff = getMinBackoffMillis();
+        return initialBackoffMillis >= minBackoff ? initialBackoffMillis : minBackoff;
     }
 
     /**
index 1337046..618feb1 100644 (file)
@@ -597,7 +597,8 @@ public class JobServiceContext extends IJobCallback.Stub implements ServiceConne
                 service.stopJob(mParams);
             } catch (RemoteException e) {
                 Slog.e(TAG, "Error sending onStopJob to client.", e);
-                closeAndCleanupJobH(false /* reschedule */);
+                // The job's host app apparently crashed during the job, so we should reschedule.
+                closeAndCleanupJobH(true /* reschedule */);
             }
         }