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

Commit 8621f658 authored by Ats Jenk's avatar Ats Jenk
Browse files

Always collapse expanded view when dragging a bubble from bubble bar

Previously we only collapsed the expanded view when the expanded bubble
was being dragged. This caused issues with the bubble bar reposition
logic. The expanded view got detached from the the bubble bar when the
bar moved to the other side.
Update the drag logic to always collapse the expanded view when any
bubble is dragged. When drag stops, expand the previously expanded
bubble again.

Bug: 330585402
Flag: ACONFIG com.android.wm.shell.enable_bubble_bar DEVELOPMENT
Test: atest BubblesTest
Test: check that expanded bubble collapses during drag
  - have 2 bubbles in the bubble bar (A, B)
  - select and expand bubble A
  - start dragging bubble B
  - bubble A should collapse
  - release bubble B
  - bubble A should expand again
Test: check that selected bubble expands after a bubble is dismissed
  - have 2 bubbles in the bubble bar (A, B)
  - select and expand bubble A
  - dismiss bubble B by dragging it to dismiss target
  - bubble A should expand

Change-Id: I5fc47461c1e857073c260c146f924fb444b39e45
parent f16e8ea2
Loading
Loading
Loading
Loading
+26 −19
Original line number Diff line number Diff line
@@ -1170,7 +1170,9 @@ public class BubbleController implements ConfigurationChangeListener,
     * @param bubbleKey key of the bubble being dragged
     */
    public void startBubbleDrag(String bubbleKey) {
        onBubbleDrag(bubbleKey, true /* isBeingDragged */);
        if (mBubbleData.getSelectedBubble() != null) {
            mBubbleBarViewCallback.expansionChanged(/* isExpanded = */ false);
        }
        if (mBubbleStateListener != null) {
            boolean overflow = BubbleOverflow.KEY.equals(bubbleKey);
            Rect rect = new Rect();
@@ -1183,23 +1185,29 @@ public class BubbleController implements ConfigurationChangeListener,
    }

    /**
     * A bubble is no longer being dragged in Launcher. As was released in given location.
     * A bubble is no longer being dragged in Launcher. And was released in given location.
     * Will be called only when bubble bar is expanded.
     *
     * @param bubbleKey key of the bubble being dragged
     * @param location  location where bubble was released
     */
    public void stopBubbleDrag(String bubbleKey, BubbleBarLocation location) {
    public void stopBubbleDrag(BubbleBarLocation location) {
        mBubblePositioner.setBubbleBarLocation(location);
        onBubbleDrag(bubbleKey, false /* isBeingDragged */);
        if (mBubbleData.getSelectedBubble() != null) {
            mBubbleBarViewCallback.expansionChanged(/* isExpanded = */ true);
        }
    }

    private void onBubbleDrag(String bubbleKey, boolean isBeingDragged) {
        // TODO(b/330585402): collapse stack if any bubble is dragged
        if (mBubbleData.getSelectedBubble() != null
                && mBubbleData.getSelectedBubble().getKey().equals(bubbleKey)) {
            // Should collapse/expand only if equals to selected bubble.
            mBubbleBarViewCallback.expansionChanged(/* isExpanded = */ !isBeingDragged);
    /**
     * A bubble was dragged and is released in dismiss target in Launcher.
     *
     * @param bubbleKey key of the bubble being dragged to dismiss target
     */
    public void dragBubbleToDismiss(String bubbleKey) {
        String selectedBubbleKey = mBubbleData.getSelectedBubbleKey();
        removeBubble(bubbleKey, Bubbles.DISMISS_USER_GESTURE);
        if (selectedBubbleKey != null && !selectedBubbleKey.equals(bubbleKey)) {
            // We did not remove the selected bubble. Expand it again
            mBubbleBarViewCallback.expansionChanged(/* isExpanded = */ true);
        }
    }

@@ -2357,12 +2365,6 @@ public class BubbleController implements ConfigurationChangeListener,
                            key, bubbleBarBounds));
        }

        @Override
        public void removeBubble(String key) {
            mMainExecutor.execute(
                    () -> mController.removeBubble(key, Bubbles.DISMISS_USER_GESTURE));
        }

        @Override
        public void removeAllBubbles() {
            mMainExecutor.execute(() -> mController.removeAllBubbles(Bubbles.DISMISS_USER_GESTURE));
@@ -2379,8 +2381,13 @@ public class BubbleController implements ConfigurationChangeListener,
        }

        @Override
        public void stopBubbleDrag(String bubbleKey, BubbleBarLocation location) {
            mMainExecutor.execute(() -> mController.stopBubbleDrag(bubbleKey, location));
        public void stopBubbleDrag(BubbleBarLocation location) {
            mMainExecutor.execute(() -> mController.stopBubbleDrag(location));
        }

        @Override
        public void dragBubbleToDismiss(String key) {
            mMainExecutor.execute(() -> mController.dragBubbleToDismiss(key));
        }

        @Override
+9 −3
Original line number Diff line number Diff line
@@ -327,6 +327,14 @@ public class BubbleData {
        return mSelectedBubble;
    }

    /**
     * Returns the key of the selected bubble, or null if no bubble is selected.
     */
    @Nullable
    public String getSelectedBubbleKey() {
        return mSelectedBubble != null ? mSelectedBubble.getKey() : null;
    }

    public BubbleOverflow getOverflow() {
        return mOverflow;
    }
@@ -1228,9 +1236,7 @@ public class BubbleData {
    public void dump(PrintWriter pw) {
        pw.println("BubbleData state:");
        pw.print("  selected: ");
        pw.println(mSelectedBubble != null
                ? mSelectedBubble.getKey()
                : "null");
        pw.println(getSelectedBubbleKey());
        pw.print("  expanded: ");
        pw.println(mExpanded);

+2 −2
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ interface IBubbles {

    oneway void showBubble(in String key, in Rect bubbleBarBounds) = 3;

    oneway void removeBubble(in String key) = 4;
    oneway void dragBubbleToDismiss(in String key) = 4;

    oneway void removeAllBubbles() = 5;

@@ -47,5 +47,5 @@ interface IBubbles {

    oneway void setBubbleBarBounds(in Rect bubbleBarBounds) = 10;

    oneway void stopBubbleDrag(in String key, in BubbleBarLocation location) = 11;
    oneway void stopBubbleDrag(in BubbleBarLocation location) = 11;
}
 No newline at end of file
+107 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static android.service.notification.NotificationListenerService.REASON_GR

import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.server.notification.Flags.FLAG_SCREENSHARE_NOTIFICATION_HIDING;
import static com.android.wm.shell.Flags.FLAG_ENABLE_BUBBLE_BAR;

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

@@ -138,7 +139,6 @@ import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.row.NotificationTestHelper;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.statusbar.phone.KeyguardBypassController;
import com.android.systemui.statusbar.phone.ScreenOffAnimationController;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
@@ -2142,6 +2142,112 @@ public class BubblesTest extends SysuiTestCase {
        assertThat(mBubbleController.getLayerView().isExpanded()).isFalse();
    }

    @EnableFlags(FLAG_ENABLE_BUBBLE_BAR)
    @Test
    public void dragBubbleBarBubble_selectedBubble_expandedViewCollapsesDuringDrag() {
        mBubbleProperties.mIsBubbleBarEnabled = true;
        mPositioner.setIsLargeScreen(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

        // Add 2 bubbles
        mEntryListener.onEntryAdded(mRow);
        mEntryListener.onEntryAdded(mRow2);
        mBubbleController.updateBubble(mBubbleEntry);
        mBubbleController.updateBubble(mBubbleEntry2);

        // Select first bubble
        mBubbleController.expandStackAndSelectBubbleFromLauncher(mBubbleEntry.getKey(), new Rect());
        assertThat(mBubbleData.getSelectedBubbleKey()).isEqualTo(mBubbleEntry.getKey());
        assertThat(mBubbleController.getLayerView().isExpanded()).isTrue();

        // Drag first bubble, bubble should collapse
        mBubbleController.startBubbleDrag(mBubbleEntry.getKey());
        assertThat(mBubbleController.getLayerView().isExpanded()).isFalse();

        // Stop dragging, first bubble should be expanded
        mBubbleController.stopBubbleDrag(BubbleBarLocation.LEFT);
        assertThat(mBubbleData.getSelectedBubbleKey()).isEqualTo(mBubbleEntry.getKey());
        assertThat(mBubbleController.getLayerView().isExpanded()).isTrue();
    }

    @EnableFlags(FLAG_ENABLE_BUBBLE_BAR)
    @Test
    public void dragBubbleBarBubble_unselectedBubble_expandedViewCollapsesDuringDrag() {
        mBubbleProperties.mIsBubbleBarEnabled = true;
        mPositioner.setIsLargeScreen(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

        // Add 2 bubbles
        mEntryListener.onEntryAdded(mRow);
        mEntryListener.onEntryAdded(mRow2);
        mBubbleController.updateBubble(mBubbleEntry);
        mBubbleController.updateBubble(mBubbleEntry2);

        // Select first bubble
        mBubbleController.expandStackAndSelectBubbleFromLauncher(mBubbleEntry.getKey(), new Rect());
        assertThat(mBubbleData.getSelectedBubbleKey()).isEqualTo(mBubbleEntry.getKey());
        assertThat(mBubbleController.getLayerView().isExpanded()).isTrue();

        // Drag second bubble, bubble should collapse
        mBubbleController.startBubbleDrag(mBubbleEntry2.getKey());
        assertThat(mBubbleController.getLayerView().isExpanded()).isFalse();

        // Stop dragging, first bubble should be expanded
        mBubbleController.stopBubbleDrag(BubbleBarLocation.LEFT);
        assertThat(mBubbleData.getSelectedBubbleKey()).isEqualTo(mBubbleEntry.getKey());
        assertThat(mBubbleController.getLayerView().isExpanded()).isTrue();
    }

    @EnableFlags(FLAG_ENABLE_BUBBLE_BAR)
    @Test
    public void dismissBubbleBarBubble_selected_selectsAndExpandsNext() {
        mBubbleProperties.mIsBubbleBarEnabled = true;
        mPositioner.setIsLargeScreen(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

        // Add 2 bubbles
        mEntryListener.onEntryAdded(mRow);
        mEntryListener.onEntryAdded(mRow2);
        mBubbleController.updateBubble(mBubbleEntry);
        mBubbleController.updateBubble(mBubbleEntry2);

        // Select first bubble
        mBubbleController.expandStackAndSelectBubbleFromLauncher(mBubbleEntry.getKey(), new Rect());
        // Drag first bubble to dismiss
        mBubbleController.startBubbleDrag(mBubbleEntry.getKey());
        mBubbleController.dragBubbleToDismiss(mBubbleEntry.getKey());
        // Second bubble is selected and expanded
        assertThat(mBubbleData.getSelectedBubbleKey()).isEqualTo(mBubbleEntry2.getKey());
        assertThat(mBubbleController.getLayerView().isExpanded()).isTrue();
    }

    @EnableFlags(FLAG_ENABLE_BUBBLE_BAR)
    @Test
    public void dismissBubbleBarBubble_unselected_selectionDoesNotChange() {
        mBubbleProperties.mIsBubbleBarEnabled = true;
        mPositioner.setIsLargeScreen(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

        // Add 2 bubbles
        mEntryListener.onEntryAdded(mRow);
        mEntryListener.onEntryAdded(mRow2);
        mBubbleController.updateBubble(mBubbleEntry);
        mBubbleController.updateBubble(mBubbleEntry2);

        // Select first bubble
        mBubbleController.expandStackAndSelectBubbleFromLauncher(mBubbleEntry.getKey(), new Rect());
        // Drag second bubble to dismiss
        mBubbleController.startBubbleDrag(mBubbleEntry2.getKey());
        mBubbleController.dragBubbleToDismiss(mBubbleEntry2.getKey());
        // First bubble remains selected and expanded
        assertThat(mBubbleData.getSelectedBubbleKey()).isEqualTo(mBubbleEntry.getKey());
        assertThat(mBubbleController.getLayerView().isExpanded()).isTrue();
    }

    @DisableFlags(FLAG_SCREENSHARE_NOTIFICATION_HIDING)
    @Test
    public void doesNotRegisterSensitiveStateListener() {