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

Commit d116bb49 authored by Mady Mellor's avatar Mady Mellor
Browse files

Fix bubble bar state after rotation on foldable

Currently when the views get updated for a mode change, it doesn't
take into account the expanded state. This change ensures that if
bubbles was expanded prior to a mode change, the expanded state
gets applied to the layer view & that the expanded and selected state
is sent over to launcher in the initial bubble bar state.

The real root cause of this is that when a foldable is rotated, we're
getting an unregister and then a register call for our bubble state
listener from launcher, which causes a mode change. It would be good
to check why that's happening because it seems incorrect, however, we
shouldn't rely on launcher's correctness / should ensure the current
state is applied which is what this CL does.

Flag: com.android.wm.shell.bubble_bar
Test: atest BubbleDataTest BubblesTest
Test: manual - enable bubble bar on a foldable
             - expand bubbles, rotate device
             => observe that bubbles are expanded still
             => collapse bubbles and check that swipe to home and
                overview works fine
Bug: 324443226
Change-Id: I12ec9755cc1d5de9d03ca2074eaac16a6bb1efa8
parent 488981a4
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -1550,6 +1550,12 @@ public class BubbleController implements ConfigurationChangeListener,
                    Log.w(TAG, "Tried to add a bubble to the stack but the stack is null");
                    Log.w(TAG, "Tried to add a bubble to the stack but the stack is null");
                }
                }
            };
            };
        } else if (mBubbleData.isExpanded() && mBubbleData.getSelectedBubble() != null) {
            callback = b -> {
                if (b.getKey().equals(mBubbleData.getSelectedBubbleKey())) {
                    mLayerView.showExpandedView(b);
                }
            };
        }
        }
        for (int i = mBubbleData.getBubbles().size() - 1; i >= 0; i--) {
        for (int i = mBubbleData.getBubbles().size() - 1; i >= 0; i--) {
            Bubble bubble = mBubbleData.getBubbles().get(i);
            Bubble bubble = mBubbleData.getBubbles().get(i);
+5 −1
Original line number Original line Diff line number Diff line
@@ -256,11 +256,15 @@ public class BubbleData {
    }
    }


    /**
    /**
     * Returns a bubble bar update populated with the current list of active bubbles.
     * Returns a bubble bar update populated with the current list of active bubbles, expanded,
     * and selected state.
     */
     */
    public BubbleBarUpdate getInitialStateForBubbleBar() {
    public BubbleBarUpdate getInitialStateForBubbleBar() {
        BubbleBarUpdate initialState = mStateChange.getInitialState();
        BubbleBarUpdate initialState = mStateChange.getInitialState();
        initialState.bubbleBarLocation = mPositioner.getBubbleBarLocation();
        initialState.bubbleBarLocation = mPositioner.getBubbleBarLocation();
        initialState.expanded = mExpanded;
        initialState.expandedChanged = mExpanded; // only matters if we're expanded
        initialState.selectedBubbleKey = getSelectedBubbleKey();
        return initialState;
        return initialState;
    }
    }


+19 −0
Original line number Original line Diff line number Diff line
@@ -1203,6 +1203,25 @@ public class BubbleDataTest extends ShellTestCase {
        assertThat(update.currentBubbleList.get(0).getKey()).isEqualTo(mEntryA2.getKey());
        assertThat(update.currentBubbleList.get(0).getKey()).isEqualTo(mEntryA2.getKey());
        assertThat(update.currentBubbleList.get(1).getKey()).isEqualTo(mEntryA1.getKey());
        assertThat(update.currentBubbleList.get(1).getKey()).isEqualTo(mEntryA1.getKey());
        assertThat(update.bubbleBarLocation).isEqualTo(BubbleBarLocation.LEFT);
        assertThat(update.bubbleBarLocation).isEqualTo(BubbleBarLocation.LEFT);
        assertThat(update.expandedChanged).isFalse();
        assertThat(update.selectedBubbleKey).isEqualTo(mEntryA2.getKey());
    }

    @Test
    public void test_getInitialStateForBubbleBar_includesExpandedState() {
        sendUpdatedEntryAtTime(mEntryA1, 1000);
        sendUpdatedEntryAtTime(mEntryA2, 2000);
        mPositioner.setBubbleBarLocation(BubbleBarLocation.LEFT);
        mBubbleData.setExpanded(true);

        BubbleBarUpdate update = mBubbleData.getInitialStateForBubbleBar();
        assertThat(update.currentBubbleList).hasSize(2);
        assertThat(update.currentBubbleList.get(0).getKey()).isEqualTo(mEntryA2.getKey());
        assertThat(update.currentBubbleList.get(1).getKey()).isEqualTo(mEntryA1.getKey());
        assertThat(update.bubbleBarLocation).isEqualTo(BubbleBarLocation.LEFT);
        assertThat(update.expandedChanged).isTrue();
        assertThat(update.expanded).isTrue();
        assertThat(update.selectedBubbleKey).isEqualTo(mEntryA2.getKey());
    }
    }


    @Test
    @Test
+28 −0
Original line number Original line Diff line number Diff line
@@ -169,6 +169,7 @@ import com.android.wm.shell.bubbles.BubbleViewInfoTask;
import com.android.wm.shell.bubbles.BubbleViewProvider;
import com.android.wm.shell.bubbles.BubbleViewProvider;
import com.android.wm.shell.bubbles.Bubbles;
import com.android.wm.shell.bubbles.Bubbles;
import com.android.wm.shell.bubbles.StackEducationView;
import com.android.wm.shell.bubbles.StackEducationView;
import com.android.wm.shell.bubbles.bar.BubbleBarLayerView;
import com.android.wm.shell.bubbles.properties.BubbleProperties;
import com.android.wm.shell.bubbles.properties.BubbleProperties;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.FloatingContentCoordinator;
import com.android.wm.shell.common.FloatingContentCoordinator;
@@ -2108,6 +2109,33 @@ public class BubblesTest extends SysuiTestCase {
        assertBubbleIsInflatedForStack(mBubbleData.getOverflow());
        assertBubbleIsInflatedForStack(mBubbleData.getOverflow());
    }
    }


    @Test
    public void registerBubbleBarListener_switchToBarWhileExpanded() {
        mBubbleProperties.mIsBubbleBarEnabled = true;
        mPositioner.setIsLargeScreen(true);

        mEntryListener.onEntryAdded(mRow);
        mBubbleController.updateBubble(mBubbleEntry);
        BubbleStackView stackView = mBubbleController.getStackView();
        spyOn(stackView);

        mBubbleData.setExpanded(true);

        assertStackMode();
        assertThat(mBubbleData.isExpanded()).isTrue();
        assertThat(stackView.isExpanded()).isTrue();

        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

        BubbleBarLayerView layerView = mBubbleController.getLayerView();
        spyOn(layerView);

        assertBarMode();
        assertThat(mBubbleData.isExpanded()).isTrue();
        assertThat(layerView.isExpanded()).isTrue();
    }

    @Test
    @Test
    public void switchBetweenBarAndStack_noBubbles_shouldBeIgnored() {
    public void switchBetweenBarAndStack_noBubbles_shouldBeIgnored() {
        mBubbleProperties.mIsBubbleBarEnabled = false;
        mBubbleProperties.mIsBubbleBarEnabled = false;