Merge "Avoid sync when UID network is disconnected."

This commit is contained in:
Jeff Sharkey
2011-07-27 09:41:39 -07:00
committed by Android (Google) Code Review

View File

@@ -1691,12 +1691,28 @@ public class SyncManager implements OnAccountsUpdateListener {
continue;
}
// skip the sync if it isn't manual and auto sync or
// background data usage is disabled
final RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterInfo;
syncAdapterInfo = mSyncAdapters.getServiceInfo(
SyncAdapterType.newKey(op.authority, op.account.type));
// only proceed if network is connected for requesting UID
final boolean uidNetworkConnected;
if (syncAdapterInfo != null) {
final NetworkInfo networkInfo = getConnectivityManager()
.getActiveNetworkInfoForUid(syncAdapterInfo.uid);
uidNetworkConnected = networkInfo != null && networkInfo.isConnected();
} else {
uidNetworkConnected = false;
}
// skip the sync if it isn't manual, and auto sync or
// background data usage is disabled or network is
// disconnected for the target UID.
if (!op.extras.getBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, false)
&& (syncableState > 0)
&& (!masterSyncAutomatically
|| !backgroundDataUsageAllowed
|| !uidNetworkConnected
|| !mSyncStorageEngine.getSyncAutomatically(
op.account, op.authority))) {
operationIterator.remove();