From 3a3b8ed242707bc830acde6500f6a6bbffeb6ce2 Mon Sep 17 00:00:00 2001 From: Kweku Adams Date: Thu, 17 Dec 2020 10:36:58 -0800 Subject: [PATCH] Allow EJs to set storage-not-low constraint. Also improve documentation. Bug: 171305774 Test: atest CtsJobSchedulerTestCases Change-Id: I8bfc18fb7565bbac748a4299477bac6f4cf5e08a --- .../framework/java/android/app/job/JobInfo.java | 11 +++++++---- .../framework/java/android/app/job/JobParameters.java | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/apex/jobscheduler/framework/java/android/app/job/JobInfo.java b/apex/jobscheduler/framework/java/android/app/job/JobInfo.java index 31f05ba48b191..6eb44a74a3f3f 100644 --- a/apex/jobscheduler/framework/java/android/app/job/JobInfo.java +++ b/apex/jobscheduler/framework/java/android/app/job/JobInfo.java @@ -1472,6 +1472,7 @@ public class JobInfo implements Parcelable { *
  • Run as soon as possible
  • *
  • Be exempted from Doze and battery saver restrictions
  • *
  • Have network access
  • + *
  • Less likely to be killed than regular jobs
  • * * * Since these jobs have stronger guarantees than regular jobs, they will be subject to @@ -1483,10 +1484,11 @@ public class JobInfo implements Parcelable { * will immediately return {@link JobScheduler#RESULT_FAILURE} if the app does not have * available quota (and the job will not be successfully scheduled). * - * Expedited jobs may only set network constraints. No other constraints are allowed. + * Expedited jobs may only set network, storage-not-low, and persistence constraints. + * No other constraints are allowed. * * Note: Even though expedited jobs are meant to run as soon as possible, they may be - * deferred if the system is under heavy load or the network constraint is satisfied + * deferred if the system is under heavy load or requested constraints are not satisfied. * * @see JobInfo#isExpedited() */ @@ -1666,9 +1668,10 @@ public class JobInfo implements Parcelable { if (isPeriodic) { throw new IllegalArgumentException("An expedited job cannot be periodic"); } - if (constraintFlags != 0 || (flags & ~FLAG_EXPEDITED) != 0) { + if ((constraintFlags & ~CONSTRAINT_FLAG_STORAGE_NOT_LOW) != 0 + || (flags & ~FLAG_EXPEDITED) != 0) { throw new IllegalArgumentException( - "An expedited job can only have network constraints"); + "An expedited job can only have network and storage-not-low constraints"); } if (triggerContentUris != null && triggerContentUris.length > 0) { throw new IllegalArgumentException( diff --git a/apex/jobscheduler/framework/java/android/app/job/JobParameters.java b/apex/jobscheduler/framework/java/android/app/job/JobParameters.java index d4c78a0bd1c4e..0d3e0016fca09 100644 --- a/apex/jobscheduler/framework/java/android/app/job/JobParameters.java +++ b/apex/jobscheduler/framework/java/android/app/job/JobParameters.java @@ -202,6 +202,8 @@ public class JobParameters implements Parcelable { * {@code true}. This will return {@code false} if the job that wasn't requested to run as a * expedited job, or if it was requested to run as an expedited job but the app didn't have * any remaining expedited job quota at the time of execution. + * + * @see JobInfo.Builder#setExpedited(boolean) */ public boolean isExpeditedJob() { return mIsExpedited;