Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed1d2535 authored by Alon Albert's avatar Alon Albert
Browse files

Bring back auto clear backoff on reconnect

Also, make sure it works this time by calling onBackoffChanged()

Bug: 3460736
Change-Id: I0470d6cb0aabd798dab4116d5d135c7a2364ed28
parent f313e958
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -237,10 +237,28 @@ public class SyncManager implements OnAccountsUpdateListener {
    private BroadcastReceiver mConnectivityIntentReceiver =
            new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            final boolean wasConnected = mDataConnectionIsConnected;

            // don't use the intent to figure out if network is connected, just check
            // ConnectivityManager directly.
            mDataConnectionIsConnected = isNetworkConnected();
            if (mDataConnectionIsConnected) {
                if (!wasConnected) {
                    if (Log.isLoggable(TAG, Log.VERBOSE)) {
                        Log.v(TAG, "Reconnection detected: clearing all backoffs");
                    }
                    mSyncStorageEngine.clearAllBackoffs(mSyncQueue);
                }
                sendCheckAlarmsMessage();
            }
        }
    };

    private boolean isNetworkConnected() {
        NetworkInfo networkInfo = getConnectivityManager().getActiveNetworkInfo();
        return (networkInfo != null) && networkInfo.isConnected();
    }

    private BroadcastReceiver mShutdownIntentReceiver =
            new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
@@ -1411,8 +1429,7 @@ public class SyncManager implements OnAccountsUpdateListener {
            // to have the most recent value used.
            try {
                waitUntilReadyToRun();
                NetworkInfo networkInfo = getConnectivityManager().getActiveNetworkInfo();
                mDataConnectionIsConnected = (networkInfo != null) && networkInfo.isConnected();
                mDataConnectionIsConnected = isNetworkConnected();
                mSyncManagerWakeLock.acquire();
                // Always do this first so that we be sure that any periodic syncs that
                // are ready to run have been converted into pending syncs. This allows the
+2 −1
Original line number Diff line number Diff line
@@ -525,7 +525,7 @@ public class SyncStorageEngine extends Handler {
        }
    }

    public void clearAllBackoffs() {
    public void clearAllBackoffs(SyncQueue syncQueue) {
        boolean changed = false;
        synchronized (mAuthorities) {
            for (AccountInfo accountInfo : mAccounts.values()) {
@@ -541,6 +541,7 @@ public class SyncStorageEngine extends Handler {
                        }
                        authorityInfo.backoffTime = NOT_IN_BACKOFF_MODE;
                        authorityInfo.backoffDelay = NOT_IN_BACKOFF_MODE;
                        syncQueue.onBackoffChanged(accountInfo.account, authorityInfo.authority, 0);
                        changed = true;
                    }
                }