Use JobScheduler's storage-not-low constraint.

Switch to using JobScheduler's storage-not-low constraint instead of
doing it inside of SyncManager. SyncManager used to handle the
constraint before JobScheduler existed and the code wasn't updated to
use the new constraint.

Bug: 185949373
Test: atest ContentResolverTest (all)
Test: atest CtsSyncManagerTest
Test: atest SyncOperationTest
Test: atest SyncManagerTest
Test: atest SyncRequestTest
Change-Id: I06b26388e50641e1233ce727693eab18b74066b2
This commit is contained in:
Kweku Adams
2021-04-20 18:41:17 -07:00
parent e5a10560c8
commit d835c4f5a0

View File

@@ -193,12 +193,6 @@ public class SyncManager {
*/
private static final int SYNC_MONITOR_PROGRESS_THRESHOLD_BYTES = 10; // 10 bytes
/**
* If a previously scheduled sync becomes ready and we are low on storage, it gets
* pushed back for this amount of time.
*/
private static final long SYNC_DELAY_ON_LOW_STORAGE = 60*60*1000; // 1 hour
/**
* If a sync becomes ready and it conflicts with an already running sync, it gets
* pushed back for this amount of time.
@@ -242,7 +236,6 @@ public class SyncManager {
volatile private PowerManager.WakeLock mSyncManagerWakeLock;
volatile private boolean mDataConnectionIsConnected = false;
volatile private boolean mStorageIsLow = false;
private volatile int mNextJobIdOffset = 0;
private final NotificationManager mNotificationMgr;
@@ -312,31 +305,6 @@ public class SyncManager {
return pendingSyncs;
}
private final BroadcastReceiver mStorageIntentReceiver =
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_DEVICE_STORAGE_LOW.equals(action)) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Slog.v(TAG, "Internal storage is low.");
}
mStorageIsLow = true;
cancelActiveSync(
SyncStorageEngine.EndPoint.USER_ALL_PROVIDER_ALL_ACCOUNTS_ALL,
null /* any sync */,
"storage low");
} else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(action)) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Slog.v(TAG, "Internal storage is ok.");
}
mStorageIsLow = false;
rescheduleSyncs(EndPoint.USER_ALL_PROVIDER_ALL_ACCOUNTS_ALL,
"storage ok");
}
}
};
private final BroadcastReceiver mAccountsUpdatedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -650,10 +618,6 @@ public class SyncManager {
IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
context.registerReceiver(mConnectivityIntentReceiver, intentFilter);
intentFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
context.registerReceiver(mStorageIntentReceiver, intentFilter);
intentFilter = new IntentFilter(Intent.ACTION_SHUTDOWN);
intentFilter.setPriority(100);
context.registerReceiver(mShutdownIntentReceiver, intentFilter);
@@ -1643,6 +1607,7 @@ public class SyncManager {
new ComponentName(mContext, SyncJobService.class))
.setExtras(syncOperation.toJobInfoExtras())
.setRequiredNetworkType(networkType)
.setRequiresStorageNotLow(true)
.setPersisted(true)
.setPriority(priority)
.setFlags(jobFlags);
@@ -2190,7 +2155,9 @@ public class SyncManager {
}
pw.println();
}
pw.print("Memory low: "); pw.println(mStorageIsLow);
Intent storageLowIntent =
mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW));
pw.print("Storage low: "); pw.println(storageLowIntent != null);
pw.print("Clock valid: "); pw.println(mSyncStorageEngine.isClockValid());
final AccountAndUser[] accounts = AccountManagerService.getSingleton().getAllAccounts();
@@ -3177,11 +3144,6 @@ public class SyncManager {
SyncJobService.markSyncStarted(op.jobId);
if (mStorageIsLow) {
deferSyncH(op, SYNC_DELAY_ON_LOW_STORAGE, "storage low");
return;
}
if (op.isPeriodic) {
// Don't allow this periodic to run if a previous instance failed and is currently
// scheduled according to some backoff criteria.