From f19c7029e239c2236249fe7cd27d0b0a7c4ff941 Mon Sep 17 00:00:00 2001 From: Kweku Adams Date: Wed, 21 Apr 2021 08:00:36 -0700 Subject: [PATCH] Ensure SyncManager doesn't schedule an EJ with a delay. Expedited jobs are not allowed to be scheduled with explicit delays set and callers will crash if they try to do so. SyncManager sets delays in a variety of cases. Now, we demote an EJ to a regular job if a delay is set for any reason. Bug: 178852366 Test: atest ContentResolverTest (all) Test: atest CtsSyncManagerTest Test: atest SyncOperationTest Test: atest SyncManagerTest Test: atest SyncRequestTest Change-Id: Ibf9e7b1ce640bdc3b1f3796bbedf24ca79856c26 --- .../core/java/com/android/server/content/SyncManager.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/content/SyncManager.java b/services/core/java/com/android/server/content/SyncManager.java index 21595c44b054d..f3ed2b55bec7a 100644 --- a/services/core/java/com/android/server/content/SyncManager.java +++ b/services/core/java/com/android/server/content/SyncManager.java @@ -1525,6 +1525,10 @@ public class SyncManager { if (minDelay < 0) { minDelay = 0; + } else if (minDelay > 0) { + // We can't apply a delay to an EJ. If we want to delay it, we must demote it to a + // regular job. + syncOperation.scheduleEjAsRegularJob = true; } // Check if duplicate syncs are pending. If found, keep one with least expected run time. @@ -1735,6 +1739,8 @@ public class SyncManager { } operation.enableBackoff(); + // Never run a rescheduled requested-EJ-sync as an EJ. + operation.scheduleEjAsRegularJob = true; if (operation.hasDoNotRetry() && !syncResult.syncAlreadyInProgress) { // syncAlreadyInProgress flag is set by AbstractThreadedSyncAdapter. The sync adapter @@ -3142,7 +3148,7 @@ public class SyncManager { scheduleSyncOperationH(op.createOneTimeSyncOperation(), delay); } else { // mSyncJobService.callJobFinished is async, so cancel the job to ensure we don't - // find the this job in the pending jobs list while looking for duplicates + // find this job in the pending jobs list while looking for duplicates // before scheduling it at a later time. cancelJob(op, "deferSyncH()"); scheduleSyncOperationH(op, delay);