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

Commit 220cebbb authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Prevent setting pending bind if we are bound

If we are bound (or in the process of binding) do not set pending bind
again. This could happen if we are trying to bind shortly after the tile
was added, as that flow involves a temporary bind.

This was causing the tiles to show as Unavailable and preventing clicks
on them when `qs_new_tiles` flag was on.

Test: atest --iterations 20 CtsTileServiceTestCases with flag on and off
Test: atest TileServiceManagerTest
Fixes: 344449464
Flag: EXEMPT bugfix
Change-Id: I95108c24ef61127c99d8006354a30b993ba65c9f
parent f43c3308
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();
    }
}