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

Commit 9ea623ca authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Back off connect when launcher binder connects but service does not"

parents c00c60d6 ead8e5a6
Loading
Loading
Loading
Loading
+19 −8
Original line number Original line 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 BACKOFF_MILLIS = 1000;
    private static final long DEFERRED_CALLBACK_MILLIS = 5000;
    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
    // 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
    private static final int DEFAULT_DISABLE_SWIPE_UP_STATE = FLAG_DISABLE_SWIPE_UP
            | FLAG_SHOW_OVERVIEW_BUTTON;
            | FLAG_SHOW_OVERVIEW_BUTTON;
@@ -215,7 +218,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
    private final Runnable mDeferredConnectionCallback = () -> {
    private final Runnable mDeferredConnectionCallback = () -> {
        Log.w(TAG_OPS, "Binder supposed established connection but actual connection to service "
        Log.w(TAG_OPS, "Binder supposed established connection but actual connection to service "
            + "timed out, trying again");
            + "timed out, trying again");
        internalConnectToCurrentUser();
        retryConnectionWithBackoff();
    };
    };


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


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


        @Override
        @Override
@@ -357,13 +360,21 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
            mHandler.postDelayed(mDeferredConnectionCallback, DEFERRED_CALLBACK_MILLIS);
            mHandler.postDelayed(mDeferredConnectionCallback, DEFERRED_CALLBACK_MILLIS);
        } else {
        } else {
            // Retry after exponential backoff timeout
            // 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);
        mHandler.postDelayed(mConnectionRunnable, timeoutMs);
        mConnectionBackoffAttempts++;
        mConnectionBackoffAttempts++;
        Log.w(TAG_OPS, "Failed to connect on attempt " + mConnectionBackoffAttempts
        Log.w(TAG_OPS, "Failed to connect on attempt " + mConnectionBackoffAttempts
                + " will try again in " + timeoutMs + "ms");
                + " will try again in " + timeoutMs + "ms");
    }
    }
    }


    @Override
    @Override
    public void addCallback(OverviewProxyListener listener) {
    public void addCallback(OverviewProxyListener listener) {