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

Commit ead8e5a6 authored by Matthew Ng's avatar Matthew Ng
Browse files

Back off connect when launcher binder connects but service does not

Also added a max back off duration of 5 minutes.

Test: manual - force crash launcher on onCreate(), view logs
Change-Id: Icaaaab8cbf73e30339a215310a9d31f874f34eab
Fixes: 112849413
parent b3d3dd21
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -70,6 +70,9 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
    private static final long BACKOFF_MILLIS = 1000;
    private static final long DEFERRED_CALLBACK_MILLIS = 5000;

    // Max backoff caps at 5 mins
    private static final long MAX_BACKOFF_MILLIS = 10 * 60 * 1000;

    // Default interaction flags if swipe up is disabled before connecting to launcher
    private static final int DEFAULT_DISABLE_SWIPE_UP_STATE = FLAG_DISABLE_SWIPE_UP
            | FLAG_SHOW_OVERVIEW_BUTTON;
@@ -215,7 +218,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
    private final Runnable mDeferredConnectionCallback = () -> {
        Log.w(TAG_OPS, "Binder supposed established connection but actual connection to service "
            + "timed out, trying again");
        internalConnectToCurrentUser();
        retryConnectionWithBackoff();
    };

    private final BroadcastReceiver mLauncherStateChangedReceiver = new BroadcastReceiver() {
@@ -260,14 +263,14 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
        public void onNullBinding(ComponentName name) {
            Log.w(TAG_OPS, "Null binding of '" + name + "', try reconnecting");
            mCurrentBoundedUserId = -1;
            internalConnectToCurrentUser();
            retryConnectionWithBackoff();
        }

        @Override
        public void onBindingDied(ComponentName name) {
            Log.w(TAG_OPS, "Binding died of '" + name + "', try reconnecting");
            mCurrentBoundedUserId = -1;
            internalConnectToCurrentUser();
            retryConnectionWithBackoff();
        }

        @Override
@@ -357,13 +360,21 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
            mHandler.postDelayed(mDeferredConnectionCallback, DEFERRED_CALLBACK_MILLIS);
        } else {
            // Retry after exponential backoff timeout
            final long timeoutMs = (long) Math.scalb(BACKOFF_MILLIS, mConnectionBackoffAttempts);
            retryConnectionWithBackoff();
        }
    }

    private void retryConnectionWithBackoff() {
        if (mHandler.hasCallbacks(mConnectionRunnable)) {
            return;
        }
        final long timeoutMs = (long) Math.min(
                Math.scalb(BACKOFF_MILLIS, mConnectionBackoffAttempts), MAX_BACKOFF_MILLIS);
        mHandler.postDelayed(mConnectionRunnable, timeoutMs);
        mConnectionBackoffAttempts++;
        Log.w(TAG_OPS, "Failed to connect on attempt " + mConnectionBackoffAttempts
                + " will try again in " + timeoutMs + "ms");
    }
    }

    @Override
    public void addCallback(OverviewProxyListener listener) {