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

Commit 92d2ed23 authored by Ats Jenk's avatar Ats Jenk Committed by Android (Google) Code Review
Browse files

Merge "Create API for Launcher to signal bubble bar state" into main

parents 473e877d 2bd8fea8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ class BubbleControllerBubbleBarTest {
        mainExecutor.flushAll()
        bgExecutor.flushAll()

        bubbleController.setLauncherHasBubbleBar(true)
        bubbleController.registerBubbleStateListener(FakeBubblesStateListener())
    }

+60 −18
Original line number Diff line number Diff line
@@ -295,8 +295,16 @@ public class BubbleController implements ConfigurationChangeListener,
    private final Optional<OneHandedController> mOneHandedOptional;
    /** Drag and drop controller to register listener for onDragStarted. */
    private final DragAndDropController mDragAndDropController;
    /** Used to send bubble events to launcher. */
    /**
     * Used to send bubble events to launcher.
     * Set when taskbar is created in launcher and bubble bar gets initialized.
     * Can be cleared during Launcher lifecycle changes, for example when taskbar gets recreated
     * during rotation.
     */
    @Nullable
    private Bubbles.BubbleStateListener mBubbleStateListener;
    /** True when launcher can show the bubble bar. */
    private boolean mLauncherHasBubbleBar;
    /**
     * Used to track previous navigation mode to detect switch to buttons navigation. Set to
     * true to switch the bubble bar to the opposite side for 3 nav buttons mode on device boot.
@@ -592,9 +600,8 @@ public class BubbleController implements ConfigurationChangeListener,
    /**
     * Sets a listener to be notified of bubble updates. This is used by launcher so that
     * it may render bubbles in itself. Only one listener is supported.
     *
     * <p>If bubble bar is supported, bubble views will be updated to switch to bar mode.
     */
    @VisibleForTesting
    public void registerBubbleStateListener(Bubbles.BubbleStateListener listener) {
        final boolean bubbleBarAllowed = Flags.enableBubbleBar()
                && (mBubblePositioner.isLargeScreen() || Flags.enableBubbleBarOnPhones())
@@ -602,8 +609,10 @@ public class BubbleController implements ConfigurationChangeListener,
        if (bubbleBarAllowed) {
            // Only set the listener if we can show the bubble bar.
            mBubbleStateListener = listener;
            setUpBubbleViewsForMode();
            if (mLauncherHasBubbleBar) {
                // Launcher is ready, send initial listener update.
                sendInitialListenerUpdate();
            }
        } else {
            mBubbleStateListener = null;
        }
@@ -611,13 +620,31 @@ public class BubbleController implements ConfigurationChangeListener,

    /**
     * Unregisters the {@link Bubbles.BubbleStateListener}.
     *
     * <p>If there's an existing listener, then we're switching back to stack mode and bubble views
     * will be updated accordingly.
     */
    @VisibleForTesting
    public void unregisterBubbleStateListener() {
        if (mBubbleStateListener != null) {
        mBubbleStateListener = null;
    }

    /**
     * Store whether Launcher can show bubbles in Bubble Bar.
     * <p>
     * If {@code launcherHasBubbleBar} is set to {@code true}, bubble views will be updated to
     * switch to bar mode. If it is set to {@code false}, bubble views will be updated to switch
     * to stack mode.
     */
    @VisibleForTesting
    public void setLauncherHasBubbleBar(boolean launcherHasBubbleBar) {
        if (launcherHasBubbleBar == mLauncherHasBubbleBar) return;
        mLauncherHasBubbleBar = launcherHasBubbleBar;
        if (mLauncherHasBubbleBar) {
            setUpBubbleViewsForMode();
            if (mBubbleStateListener != null) {
                // Listener got set first, send it an initial update.
                sendInitialListenerUpdate();
            }
        } else {
            unregisterBubbleStateListener();
            setUpBubbleViewsForMode();
        }
    }
@@ -788,7 +815,7 @@ public class BubbleController implements ConfigurationChangeListener,
    public boolean isShowingAsBubbleBar() {
        return Flags.enableBubbleBar()
                && (mBubblePositioner.isLargeScreen() || Flags.enableBubbleBarOnPhones())
                && mBubbleStateListener != null;
                && mLauncherHasBubbleBar;
    }

    /**
@@ -810,11 +837,13 @@ public class BubbleController implements ConfigurationChangeListener,
            @UpdateSource int source) {
        if (isShowingAsBubbleBar()) {
            updateExpandedViewForBubbleBarLocation(bubbleBarLocation, source);
            if (mBubbleStateListener != null) {
                BubbleBarUpdate bubbleBarUpdate = new BubbleBarUpdate();
                bubbleBarUpdate.bubbleBarLocation = bubbleBarLocation;
                mBubbleStateListener.onBubbleStateChange(bubbleBarUpdate);
            }
        }
    }

    private void updateExpandedViewForBubbleBarLocation(BubbleBarLocation bubbleBarLocation,
            @UpdateSource int source) {
@@ -874,7 +903,7 @@ public class BubbleController implements ConfigurationChangeListener,
     * {@link #setBubbleBarLocation(BubbleBarLocation, int)}.
     */
    public void animateBubbleBarLocation(BubbleBarLocation bubbleBarLocation) {
        if (isShowingAsBubbleBar()) {
        if (isShowingAsBubbleBar() && mBubbleStateListener != null) {
            mBubbleStateListener.animateBubbleBarLocation(bubbleBarLocation);
        }
    }
@@ -883,7 +912,9 @@ public class BubbleController implements ConfigurationChangeListener,
    public void onDragItemOverBubbleBarDragZone(@Nullable BubbleBarLocation bubbleBarLocation) {
        if (bubbleBarLocation == null) return;
        if (isShowingAsBubbleBar() && BubbleAnythingFlagHelper.enableCreateAnyBubble()) {
            if (mBubbleStateListener != null) {
                mBubbleStateListener.onDragItemOverBubbleBarDragZone(bubbleBarLocation);
            }
            showBubbleBarExpandedViewDropTarget(bubbleBarLocation);
        }
    }
@@ -891,7 +922,9 @@ public class BubbleController implements ConfigurationChangeListener,
    @Override
    public void onItemDraggedOutsideBubbleBarDropZone() {
        if (isShowingAsBubbleBar() && BubbleAnythingFlagHelper.enableCreateAnyBubble()) {
            if (mBubbleStateListener != null) {
                mBubbleStateListener.onItemDraggedOutsideBubbleBarDropZone();
            }
            hideBubbleBarExpandedViewDropTarget();
        }
    }
@@ -2531,7 +2564,7 @@ public class BubbleController implements ConfigurationChangeListener,
            if (isShowingAsBubbleBar()) {
                BubbleBarUpdate bubbleBarUpdate = update.toBubbleBarUpdate();
                // Some updates aren't relevant to the bubble bar so check first.
                if (bubbleBarUpdate.anythingChanged()) {
                if (bubbleBarUpdate.anythingChanged() && mBubbleStateListener != null) {
                    mBubbleStateListener.onBubbleStateChange(bubbleBarUpdate);
                }
            }
@@ -2770,6 +2803,10 @@ public class BubbleController implements ConfigurationChangeListener,
        pw.print(prefix); pw.println("  currentUserId= " + mCurrentUserId);
        pw.print(prefix); pw.println("  isStatusBarShade= " + mIsStatusBarShade);
        pw.print(prefix); pw.println("  isShowingAsBubbleBar= " + isShowingAsBubbleBar());
        pw.print(prefix); pw.println("  launcherHasBubbleBar= " + mLauncherHasBubbleBar);
        pw.print(prefix); pw.println("  bubbleStateListenerSet= " + (mBubbleStateListener != null));
        pw.print(prefix); pw.println("  stackViewSet= " + (mStackView != null));
        pw.print(prefix); pw.println("  layerViewSet= " + (mLayerView != null));
        pw.print(prefix); pw.println("  isImeVisible= " + mBubblePositioner.isImeVisible());
        pw.println();

@@ -3074,6 +3111,11 @@ public class BubbleController implements ConfigurationChangeListener,
            mMainExecutor.execute(
                    () -> mController.moveDraggedBubbleToFullscreen(key, dropLocation));
        }

        @Override
        public void setHasBubbleBar(boolean hasBubbleBar) {
            mMainExecutor.execute(() -> mController.setLauncherHasBubbleBar(hasBubbleBar));
        }
    }

    private class BubblesImpl implements Bubbles {
+2 −0
Original line number Diff line number Diff line
@@ -61,4 +61,6 @@ interface IBubbles {
    oneway void showDropTarget(in boolean show, in @nullable BubbleBarLocation location) = 15;

    oneway void moveDraggedBubbleToFullscreen(in String key, in Point dropLocation) = 16;

    oneway void setHasBubbleBar(in boolean hasBubbleBar) = 17;
}
 No newline at end of file
+30 −6
Original line number Diff line number Diff line
@@ -212,6 +212,9 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.stubbing.Answer;

import platform.test.runner.parameterized.ParameterizedAndroidJunit4;
import platform.test.runner.parameterized.Parameters;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -220,9 +223,6 @@ import java.util.List;
import java.util.Optional;
import java.util.concurrent.Executor;

import platform.test.runner.parameterized.ParameterizedAndroidJunit4;
import platform.test.runner.parameterized.Parameters;

@SmallTest
@RunWith(ParameterizedAndroidJunit4.class)
@TestableLooper.RunWithLooper(setAsMainLooper = true)
@@ -2397,6 +2397,7 @@ public class BubblesTest extends SysuiTestCase {

        assertStackMode();

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

@@ -2415,6 +2416,7 @@ public class BubblesTest extends SysuiTestCase {

        assertStackMode();

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

@@ -2437,17 +2439,20 @@ public class BubblesTest extends SysuiTestCase {
        assertBubbleIsInflatedForStack(mBubbleData.getBubbles().get(0));
        assertBubbleIsInflatedForStack(mBubbleData.getOverflow());

        mBubbleController.setLauncherHasBubbleBar(true);
        assertBarMode();

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

        assertBarMode();

        assertThat(mBubbleData.getBubbles()).hasSize(1);
        assertBubbleIsInflatedForBar(mBubbleData.getBubbles().get(0));
        assertBubbleIsInflatedForBar(mBubbleData.getOverflow());

        mBubbleController.unregisterBubbleStateListener();

        // Check that bubbles stay in bar mode until launcher switches back to stack
        assertBarMode();
        mBubbleController.setLauncherHasBubbleBar(false);
        assertStackMode();

        assertThat(mBubbleData.getBubbles()).hasSize(1);
@@ -2472,6 +2477,7 @@ public class BubblesTest extends SysuiTestCase {
        assertThat(stackView.isExpanded()).isTrue();

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

        BubbleBarLayerView layerView = mBubbleController.getLayerView();
@@ -2491,11 +2497,13 @@ public class BubblesTest extends SysuiTestCase {
        assertNoBubbleContainerViews();

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

        assertNoBubbleContainerViews();

        mBubbleController.unregisterBubbleStateListener();
        mBubbleController.setLauncherHasBubbleBar(false);

        assertNoBubbleContainerViews();
    }
@@ -2507,6 +2515,7 @@ public class BubblesTest extends SysuiTestCase {
        mEntryListener.onEntryAdded(mEntry);
        mBubbleController.updateBubble(mBubbleEntry);

        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);
        mBubbleController.expandStackAndSelectBubbleFromLauncher(mBubbleEntry.getKey(), 1000);
@@ -2522,6 +2531,7 @@ public class BubblesTest extends SysuiTestCase {
    @Test
    public void dragBubbleBarBubble_selectedBubble_expandedViewCollapsesDuringDrag() {
        mPositioner.setIsLargeScreen(true);
        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

@@ -2550,6 +2560,7 @@ public class BubblesTest extends SysuiTestCase {
    @Test
    public void dragBubbleBarBubble_unselectedBubble_expandedViewCollapsesDuringDrag() {
        mPositioner.setIsLargeScreen(true);
        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

@@ -2578,6 +2589,7 @@ public class BubblesTest extends SysuiTestCase {
    @Test
    public void dismissBubbleBarBubble_selected_selectsAndExpandsNext() {
        mPositioner.setIsLargeScreen(true);
        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

@@ -2601,6 +2613,7 @@ public class BubblesTest extends SysuiTestCase {
    @Test
    public void dismissBubbleBarBubble_unselected_selectionDoesNotChange() {
        mPositioner.setIsLargeScreen(true);
        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

@@ -2652,6 +2665,7 @@ public class BubblesTest extends SysuiTestCase {
    public void setBubbleBarLocation_listenerNotified() {
        mPositioner.setIsLargeScreen(true);

        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);
        mBubbleController.setBubbleBarLocation(BubbleBarLocation.LEFT,
@@ -2666,6 +2680,7 @@ public class BubblesTest extends SysuiTestCase {
    public void setBubbleBarLocation_barDisabled_shouldBeIgnored() {
        mPositioner.setIsLargeScreen(true);

        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);
        mBubbleController.setBubbleBarLocation(BubbleBarLocation.LEFT,
@@ -2737,6 +2752,7 @@ public class BubblesTest extends SysuiTestCase {
    @Test
    public void testEventLogging_bubbleBar_addBubble() {
        mPositioner.setIsLargeScreen(true);
        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

@@ -2750,6 +2766,7 @@ public class BubblesTest extends SysuiTestCase {
    @Test
    public void testEventLogging_bubbleBar_updateBubble() {
        mPositioner.setIsLargeScreen(true);
        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

@@ -2766,6 +2783,7 @@ public class BubblesTest extends SysuiTestCase {
    @Test
    public void testEventLogging_bubbleBar_dragSelectedBubbleToDismiss() {
        mPositioner.setIsLargeScreen(true);
        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

@@ -2792,6 +2810,7 @@ public class BubblesTest extends SysuiTestCase {
    @Test
    public void testEventLogging_bubbleBar_dragOtherBubbleToDismiss() {
        mPositioner.setIsLargeScreen(true);
        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

@@ -2830,6 +2849,7 @@ public class BubblesTest extends SysuiTestCase {
    @Test
    public void testEventLogging_bubbleBar_expandAndCollapse() {
        mPositioner.setIsLargeScreen(true);
        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

@@ -2849,6 +2869,7 @@ public class BubblesTest extends SysuiTestCase {
    @Test
    public void testEventLogging_bubbleBar_autoExpandingBubble() {
        mPositioner.setIsLargeScreen(true);
        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

@@ -2864,6 +2885,7 @@ public class BubblesTest extends SysuiTestCase {
    @Test
    public void testEventLogging_bubbleBar_switchBubble() {
        mPositioner.setIsLargeScreen(true);
        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

@@ -2889,6 +2911,7 @@ public class BubblesTest extends SysuiTestCase {
    @Test
    public void testEventLogging_bubbleBar_openOverflow() {
        mPositioner.setIsLargeScreen(true);
        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);

@@ -2904,6 +2927,7 @@ public class BubblesTest extends SysuiTestCase {
    @Test
    public void testEventLogging_bubbleBar_fromOverflowToBar() {
        mPositioner.setIsLargeScreen(true);
        mBubbleController.setLauncherHasBubbleBar(true);
        FakeBubbleStateListener bubbleStateListener = new FakeBubbleStateListener();
        mBubbleController.registerBubbleStateListener(bubbleStateListener);