From c942339c09a5604025c363d090da8266719d0107 Mon Sep 17 00:00:00 2001 From: Kweku Adams Date: Thu, 6 May 2021 11:32:24 -0700 Subject: [PATCH] Handle out-of-ej-quota case. Downgrade a requested EJ-sync to a regular job if JobScheduler returns FAILURE. Bug: 178852366 Test: atest ContentResolverTest (all) Test: atest CtsSyncManagerTest Test: atest SyncOperationTest Test: atest SyncManagerTest Test: atest SyncRequestTest Change-Id: Ia10953e3ae56dab8c4ca120fd9f07ee1c45d6306 --- .../android/server/content/SyncManager.java | 20 ++++++++++++++++++- 1 file changed, 19 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 0314510b2b5a8..fb919fbe0a3df 100644 --- a/services/core/java/com/android/server/content/SyncManager.java +++ b/services/core/java/com/android/server/content/SyncManager.java @@ -1659,13 +1659,31 @@ public class SyncManager { final UsageStatsManagerInternal usmi = LocalServices.getService(UsageStatsManagerInternal.class); if (usmi != null) { + // This method name is unfortunate. It elevates apps to a higher bucket, so it ideally + // should be called before we attempt to schedule the job (especially as EJ). usmi.reportSyncScheduled(syncOperation.owningPackage, UserHandle.getUserId(syncOperation.owningUid), syncOperation.isAppStandbyExempted()); } - getJobScheduler().scheduleAsPackage(b.build(), syncOperation.owningPackage, + final JobInfo ji = b.build(); + int result = getJobScheduler().scheduleAsPackage(ji, syncOperation.owningPackage, syncOperation.target.userId, syncOperation.wakeLockName()); + if (result == JobScheduler.RESULT_FAILURE && ji.isExpedited()) { + if (isLoggable) { + Slog.i(TAG, "Failed to schedule EJ for " + syncOperation.owningPackage + + ". Downgrading to regular"); + } + syncOperation.scheduleEjAsRegularJob = true; + b.setExpedited(false).setExtras(syncOperation.toJobInfoExtras()); + result = getJobScheduler().scheduleAsPackage(b.build(), syncOperation.owningPackage, + syncOperation.target.userId, syncOperation.wakeLockName()); + } + if (result == JobScheduler.RESULT_FAILURE) { + Slog.e(TAG, "Failed to schedule job for " + syncOperation.owningPackage); + // TODO: notify AppStandbyController that the sync isn't actually scheduled so the + // bucket doesn't stay elevated + } } /**