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

Commit 5fcd233d authored by Liran Binyamin's avatar Liran Binyamin
Browse files

Fix race condition in FloatingToBarConversion

Make sure that the bubble has an expanded bubble bar view before
starting the floating to bar transition.

Fixes: 438747107
Flag: com.android.wm.shell.enable_bubble_bar
Test: BubbleTransitionsTest
Change-Id: Ic8326bc1b7be1dad826dd6dfabf9cbad47f1997a
parent 307a7974
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -1672,6 +1672,8 @@ public class BubbleTransitions {
        private SurfaceControl mTaskLeash;
        private SurfaceControl.Transaction mFinishTransaction;
        private boolean mIsStarted = false;
        private boolean mHasBounds = false;
        private boolean mCanExpand = false;

        FloatingToBarConversion(Bubble bubble, BubblePositioner positioner) {
            this(bubble, SurfaceControl.Transaction::new, positioner);
@@ -1760,13 +1762,26 @@ public class BubbleTransitions {

        @Override
        public void continueConvert(BubbleBarLayerView layerView) {
            mHasBounds = true;
            mPositioner.getTaskViewRestBounds(mBounds);
            mWct.setBounds(mBubble.getTaskView().getTaskInfo().token, mBounds);
            if (!mIsStarted) {
            if (canStart()) {
                startTransition();
            }
        }

        @Override
        public void continueExpand() {
            mCanExpand = true;
            if (canStart()) {
                startTransition();
            }
        }

        private boolean canStart() {
            return mHasBounds && mCanExpand && !mIsStarted;
        }

        private void startTransition() {
            mIsStarted = true;
            final TaskView tv = mBubble.getTaskView();
+3 −0
Original line number Diff line number Diff line
@@ -227,6 +227,9 @@ public class BubbleViewInfoTask {
        if (mCallback != null) {
            mCallback.onBubbleViewsReady(mBubble);
        }
        if (mBubble.isConvertingToBar()) {
            mBubble.getPreparingTransition().continueExpand();
        }
    }

    private boolean verifyState() {
+20 −0
Original line number Diff line number Diff line
@@ -536,6 +536,7 @@ public class BubbleTransitionsTest extends ShellTestCase {
                .startTransition(eq(TRANSIT_BUBBLE_CONVERT_FLOATING_TO_BAR), any(), eq(bt)))
                .thenReturn(transition);

        bt.continueExpand();
        bt.continueConvert(mLayerView);

        verify(mTransitions)
@@ -609,6 +610,7 @@ public class BubbleTransitionsTest extends ShellTestCase {
                .startTransition(eq(TRANSIT_BUBBLE_CONVERT_FLOATING_TO_BAR), any(), eq(bt)))
                .thenReturn(transition);

        bt.continueExpand();
        bt.continueConvert(mLayerView);

        verify(mTransitions)
@@ -646,6 +648,7 @@ public class BubbleTransitionsTest extends ShellTestCase {
                mBubbleTransitions.new FloatingToBarConversion(mBubble, mBubblePositioner);

        verify(mTransitions, never()).startTransition(anyInt(), any(), eq(bt));
        bt.continueExpand();

        bt.continueConvert(mLayerView);
        // call continue convert again
@@ -656,6 +659,23 @@ public class BubbleTransitionsTest extends ShellTestCase {
                .startTransition(eq(TRANSIT_BUBBLE_CONVERT_FLOATING_TO_BAR), any(), eq(bt));
    }

    @Test
    public void convertFloatingBubbleToBarBubble_mustContinueExpand() {
        setupBubble();

        final BubbleTransitions.FloatingToBarConversion bt =
                mBubbleTransitions.new FloatingToBarConversion(mBubble, mBubblePositioner);
        bt.continueConvert(mLayerView);

        verify(mTransitions, never()).startTransition(anyInt(), any(), eq(bt));

        bt.continueExpand();

        // verify we only started the transition once
        verify(mTransitions, times(1))
                .startTransition(eq(TRANSIT_BUBBLE_CONVERT_FLOATING_TO_BAR), any(), eq(bt));
    }

    @Test
    @EnableFlags(FLAG_ENABLE_BUBBLE_BAR)
    public void notifyUnfoldTransitionStarting_bubbleBarEnabled_enqueuesExternal() {