From d23ce9610b2e67b9a0e35d4b39994dd63eff5d7c Mon Sep 17 00:00:00 2001 From: Kweku Adams Date: Fri, 30 Apr 2021 14:16:14 -0700 Subject: [PATCH] Fix EJ syncs. 1. Only downgrade an EJ that doesn't have the IGNORE_BACKOFF extra when we are actually attempting to back off the job. 2. Allow EJs to have the FLAG_EXEMPT_FROM_APP_STANDBY flag since that can only be set by the system and won't cause issues. Also propagate the scheduleEjAsRegularJob bit through the job extras to help with debugging. Bug: 178852366 Test: atest ContentResolverTest (all) Test: atest CtsJobSchedulerTestCases:JobInfoTest Test: atest CtsSyncManagerTest Test: atest SyncOperationTest Test: atest SyncManagerTest Test: atest SyncRequestTest Change-Id: I133d089a4d770a3cc37df72f8b38d234b24077df --- .../framework/java/android/app/job/JobInfo.java | 2 +- .../java/com/android/server/content/SyncManager.java | 9 ++++----- .../java/com/android/server/content/SyncOperation.java | 2 ++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apex/jobscheduler/framework/java/android/app/job/JobInfo.java b/apex/jobscheduler/framework/java/android/app/job/JobInfo.java index 17682a5b655a0..db3f9129412cd 100644 --- a/apex/jobscheduler/framework/java/android/app/job/JobInfo.java +++ b/apex/jobscheduler/framework/java/android/app/job/JobInfo.java @@ -1697,7 +1697,7 @@ public class JobInfo implements Parcelable { throw new IllegalArgumentException("An expedited job cannot be periodic"); } if ((constraintFlags & ~CONSTRAINT_FLAG_STORAGE_NOT_LOW) != 0 - || (flags & ~FLAG_EXPEDITED) != 0) { + || (flags & ~(FLAG_EXPEDITED | FLAG_EXEMPT_FROM_APP_STANDBY)) != 0) { throw new IllegalArgumentException( "An expedited job can only have network and storage-not-low constraints"); } diff --git a/services/core/java/com/android/server/content/SyncManager.java b/services/core/java/com/android/server/content/SyncManager.java index 4bd1fd8e44cc7..0314510b2b5a8 100644 --- a/services/core/java/com/android/server/content/SyncManager.java +++ b/services/core/java/com/android/server/content/SyncManager.java @@ -1478,12 +1478,11 @@ public class SyncManager { + logSafe(syncOperation.target)); backoff = new Pair(SyncStorageEngine.NOT_IN_BACKOFF_MODE, SyncStorageEngine.NOT_IN_BACKOFF_MODE); - } else { + } else if (backoff.first != SyncStorageEngine.NOT_IN_BACKOFF_MODE) { // if an EJ is being backed-off but doesn't have SYNC_EXTRAS_IGNORE_BACKOFF set, - // reschedule it as a regular job - if (syncOperation.isScheduledAsExpeditedJob()) { - syncOperation.scheduleEjAsRegularJob = true; - } + // reschedule it as a regular job. Immediately downgrade here in case minDelay is + // set to 0. + syncOperation.scheduleEjAsRegularJob = true; } long now = SystemClock.elapsedRealtime(); long backoffDelay = backoff.first == SyncStorageEngine.NOT_IN_BACKOFF_MODE ? 0 diff --git a/services/core/java/com/android/server/content/SyncOperation.java b/services/core/java/com/android/server/content/SyncOperation.java index c8654d1b36ee3..f6fad25006262 100644 --- a/services/core/java/com/android/server/content/SyncOperation.java +++ b/services/core/java/com/android/server/content/SyncOperation.java @@ -258,6 +258,7 @@ public class SyncOperation { jobInfoExtras.putLong("expectedRuntime", expectedRuntime); jobInfoExtras.putInt("retries", retries); jobInfoExtras.putInt("syncExemptionFlag", syncExemptionFlag); + jobInfoExtras.putBoolean("ejDowngradedToRegular", scheduleEjAsRegularJob); return jobInfoExtras; } @@ -325,6 +326,7 @@ public class SyncOperation { op.jobId = jobExtras.getInt("jobId"); op.expectedRuntime = jobExtras.getLong("expectedRuntime"); op.retries = jobExtras.getInt("retries"); + op.scheduleEjAsRegularJob = jobExtras.getBoolean("ejDowngradedToRegular"); return op; }