Skip to content

Commit 76eb1a2

Browse files
fredquintanaAndroid (Google) Code Review
authored andcommitted
Merge "Revert "Make the SyncManager timeout syncs if it takes too long to bind to them.""
2 parents 6515f50 + 87b1466 commit 76eb1a2

File tree

1 file changed

+5
-51
lines changed

1 file changed

+5
-51
lines changed

core/java/android/content/SyncManager.java

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,6 @@ public void onReceive(Context context, Intent intent) {
191191
private static final long SYNC_ALARM_TIMEOUT_MIN = 30 * 1000; // 30 seconds
192192
private static final long SYNC_ALARM_TIMEOUT_MAX = 2 * 60 * 60 * 1000; // two hours
193193

194-
/**
195-
* The amount of time (in milliseconds) to wait after attempting a bind
196-
* before canceling a sync and disabling the sync adapter
197-
*/
198-
public static final long BIND_TIMEOUT_MS = 5 * 60 * 1000;
199-
200194
public void onAccountsUpdated(Account[] accounts) {
201195
// remember if this was the first time this was called after an update
202196
final boolean justBootedUp = mAccounts == INITIAL_ACCOUNTS_ARRAY;
@@ -1074,9 +1068,6 @@ protected void dumpSyncState(PrintWriter pw, StringBuilder sb) {
10741068
pw.print(" - ");
10751069
pw.print(activeSyncContext.mSyncOperation.dump(false));
10761070
pw.println();
1077-
if (activeSyncContext.mSyncAdapter == null) {
1078-
pw.println(" **** Waiting for onServiceConnected ****");
1079-
}
10801071
}
10811072

10821073
synchronized (mSyncQueue) {
@@ -1433,15 +1424,13 @@ public SyncHandler(Looper looper) {
14331424
public void handleMessage(Message msg) {
14341425
long earliestFuturePollTime = Long.MAX_VALUE;
14351426
long nextPendingSyncTime = Long.MAX_VALUE;
1436-
long nextBindTimeoutTime = Long.MAX_VALUE;
14371427

14381428
// Setting the value here instead of a method because we want the dumpsys logs
14391429
// to have the most recent value used.
14401430
try {
14411431
waitUntilReadyToRun();
14421432
mDataConnectionIsConnected = readDataConnectionState();
14431433
mSyncManagerWakeLock.acquire();
1444-
nextBindTimeoutTime = auditRunningSyncsForStuckBindsLocked();
14451434
// Always do this first so that we be sure that any periodic syncs that
14461435
// are ready to run have been converted into pending syncs. This allows the
14471436
// logic that considers the next steps to take based on the set of pending syncs
@@ -1543,44 +1532,13 @@ public void handleMessage(Message msg) {
15431532
break;
15441533
}
15451534
} finally {
1546-
nextPendingSyncTime = Math.min(nextBindTimeoutTime, nextPendingSyncTime);
15471535
manageSyncNotificationLocked();
15481536
manageSyncAlarmLocked(earliestFuturePollTime, nextPendingSyncTime);
15491537
mSyncTimeTracker.update();
15501538
mSyncManagerWakeLock.release();
15511539
}
15521540
}
15531541

1554-
/**
1555-
* Looks to see if any of the active syncs have been waiting for a bind for too long,
1556-
* and if so the sync is canceled and the sync adapter is disabled for that account.
1557-
* @return the earliest time that an active sync can have waited too long to bind,
1558-
* relative to {@link android.os.SystemClock#elapsedRealtime()}.
1559-
*/
1560-
private long auditRunningSyncsForStuckBindsLocked() {
1561-
final long now = SystemClock.elapsedRealtime();
1562-
long oldest = Long.MAX_VALUE;
1563-
for (ActiveSyncContext active : mActiveSyncContexts) {
1564-
if (active.mSyncAdapter == null) {
1565-
final long timeoutTime = active.mStartTime + BIND_TIMEOUT_MS;
1566-
if (timeoutTime < now) {
1567-
Log.w(TAG, "canceling long-running bind and disabling sync for "
1568-
+ active.mSyncOperation.account + ", authority "
1569-
+ active.mSyncOperation.authority);
1570-
runSyncFinishedOrCanceledLocked(null, active);
1571-
ContentResolver.setIsSyncable(active.mSyncOperation.account,
1572-
active.mSyncOperation.authority, 0);
1573-
} else {
1574-
if (oldest > timeoutTime) {
1575-
oldest = timeoutTime;
1576-
}
1577-
}
1578-
}
1579-
}
1580-
1581-
return oldest;
1582-
}
1583-
15841542
/**
15851543
* Turn any periodic sync operations that are ready to run into pending sync operations.
15861544
* @return the desired start time of the earliest future periodic sync operation,
@@ -1861,17 +1819,13 @@ private long maybeStartNextSyncLocked() {
18611819
synchronized (mSyncQueue){
18621820
mSyncQueue.remove(candidate);
18631821
}
1864-
ActiveSyncContext newSyncContext = dispatchSyncOperation(candidate);
1865-
if (newSyncContext != null) {
1866-
nextReadyToRunTime = Math.min(nextReadyToRunTime,
1867-
newSyncContext.mStartTime + BIND_TIMEOUT_MS);
1868-
}
1822+
dispatchSyncOperation(candidate);
18691823
}
18701824

18711825
return nextReadyToRunTime;
18721826
}
18731827

1874-
private ActiveSyncContext dispatchSyncOperation(SyncOperation op) {
1828+
private boolean dispatchSyncOperation(SyncOperation op) {
18751829
if (Log.isLoggable(TAG, Log.VERBOSE)) {
18761830
Log.v(TAG, "dispatchSyncOperation: we are going to sync " + op);
18771831
Log.v(TAG, "num active syncs: " + mActiveSyncContexts.size());
@@ -1888,7 +1842,7 @@ private ActiveSyncContext dispatchSyncOperation(SyncOperation op) {
18881842
Log.d(TAG, "can't find a sync adapter for " + syncAdapterType
18891843
+ ", removing settings for it");
18901844
mSyncStorageEngine.removeAuthority(op.account, op.authority);
1891-
return null;
1845+
return false;
18921846
}
18931847

18941848
ActiveSyncContext activeSyncContext =
@@ -1901,10 +1855,10 @@ private ActiveSyncContext dispatchSyncOperation(SyncOperation op) {
19011855
if (!activeSyncContext.bindToSyncAdapter(syncAdapterInfo)) {
19021856
Log.e(TAG, "Bind attempt failed to " + syncAdapterInfo);
19031857
closeActiveSyncContext(activeSyncContext);
1904-
return null;
1858+
return false;
19051859
}
19061860

1907-
return activeSyncContext;
1861+
return true;
19081862
}
19091863

19101864
private void runBoundToSyncAdapter(final ActiveSyncContext activeSyncContext,

0 commit comments

Comments
 (0)