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

Commit 7f797623 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Prevent setting pending bind if we are bound" into main

parents 46ad05a4 220cebbb
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -224,6 +224,10 @@ public class TileLifecycleManager extends BroadcastReceiver implements
        });
    }

    boolean isBound() {
        return mBound.get();
    }

    @WorkerThread
    private void setBindService(boolean bind) {
        if (mBound.get() && mUnbindImmediate.get()) {
+5 −1
Original line number Diff line number Diff line
@@ -217,7 +217,11 @@ public class TileServiceManager {
            Log.e(TAG, "Service already bound");
            return;
        }
        if (!mStateManager.isBound()) {
            // If we are bound, we don't need to set a pending bind. There's either one already or
            // we are fully bound.
            mPendingBind = true;
        }
        mBound = true;
        mJustBound = true;
        mHandler.postDelayed(mJustBoundOver, MIN_BIND_TIME);
+21 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import static android.platform.test.flag.junit.FlagsParameterization.allCombinat
import static com.android.systemui.Flags.FLAG_QS_CUSTOM_TILE_CLICK_GUARANTEED_BUG_FIX;
import static com.android.systemui.util.concurrency.MockExecutorHandlerKt.mockExecutorHandler;

import static com.google.common.truth.Truth.assertThat;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
@@ -279,4 +281,23 @@ public class TileServiceManagerTest extends SysuiTestCase {
        verify(mTileLifecycle, never()).onStopListening();
        verify(mTileLifecycle, never()).executeSetBindService(false);
    }

    @Test
    public void testNoExtraPendingBindIfAlreadyBound() {
        mTileServiceManager.startLifecycleManagerAndAddTile();

        // As part of adding the tile, it will be bound and it will send a start successful to
        // TileServices. startSuccessful will clear pending bind
        mTileServiceManager.clearPendingBind();

        // Assume we are still bound
        when(mTileLifecycle.isBound()).thenReturn(true);

        // And we want to bind again
        mTileServiceManager.setBindAllowed(true);
        mTileServiceManager.setBindRequested(true);

        // Then the tile doesn't have pending bind
        assertThat(mTileServiceManager.hasPendingBind()).isFalse();
    }
}