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

Commit 8c8ef107 authored by Winson Chung's avatar Winson Chung
Browse files

Only collapse if the removed bubble matches the expanded bubble

- With task trampolines, it is possible for the second task to have been
  created and expanded before the first task finishes & triggers a
  removal, so we need to verify the task matches before attempting to
  collapse the wrong expanded bubble

Bug: 409394438
Flag: EXEMPT bugfix
Test: atest BubbleBarLayerViewTest
Change-Id: I0a6df231f1641ef3c89cc571c457214911563fe8
parent ad562932
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -294,6 +294,25 @@ class BubbleBarLayerViewTest {
        assertThat(bubbleBarLayerView.children.last()).isEqualTo(secondBubble.bubbleBarExpandedView)
    }

    @Test
    fun twoBubbles_removeBubbleInTransition_skipCollapse() {
        val firstBubble = createBubble("first")
        val secondBubble = createBubble("second")


        getInstrumentation().runOnMainSync { bubbleBarLayerView.showExpandedView(firstBubble) }
        waitForExpandedViewAnimation()

        getInstrumentation().runOnMainSync { bubbleBarLayerView.showExpandedView(secondBubble) }
        waitForExpandedViewAnimation()

        firstBubble.preparingTransition = object : BubbleTransitions.BubbleTransition {}

        getInstrumentation().runOnMainSync { bubbleBarLayerView.removeBubble(firstBubble) {} }

        assertThat(bubbleBarLayerView.isExpanded).isTrue()
    }

    @Test
    fun testEventLogging_dismissExpandedViewViaDrag() {
        val bubble = createBubble("first")
+2 −1
Original line number Diff line number Diff line
@@ -711,7 +711,8 @@ public class Bubble implements BubbleViewProvider {
    /**
     * Sets the current bubble-transition that is coordinating a change in this bubble.
     */
    void setPreparingTransition(BubbleTransitions.BubbleTransition transit) {
    @VisibleForTesting
    public void setPreparingTransition(BubbleTransitions.BubbleTransition transit) {
        ProtoLog.d(WM_SHELL_BUBBLES_NOISY, "setPreparingTransition: transit=%s", transit);
        mPreparingTransition = transit;
    }
+1 −1
Original line number Diff line number Diff line
@@ -305,7 +305,7 @@ public class BubbleTransitions {
     * in order to coordinate with the bubble view logic. These steps are communicated on this
     * interface.
     */
    interface BubbleTransition {
    public interface BubbleTransition {
        default void surfaceCreated() {}
        default void continueExpand() {}
        default void skip() {}
+14 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.wm.shell.bubbles.bar;

import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_BUBBLES_NOISY;
import static com.android.wm.shell.shared.animation.Interpolators.ALPHA_IN;
import static com.android.wm.shell.shared.animation.Interpolators.ALPHA_OUT;
import static com.android.wm.shell.bubbles.Bubbles.DISMISS_USER_GESTURE;
@@ -39,6 +40,7 @@ import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;

import com.android.internal.protolog.ProtoLog;
import com.android.wm.shell.R;
import com.android.wm.shell.bubbles.Bubble;
import com.android.wm.shell.bubbles.BubbleController;
@@ -491,18 +493,25 @@ public class BubbleBarLayerView extends FrameLayout
        mAnimationHelper.getExpandedViewRestBounds(out);
    }

    /** Removes the given {@code bubble}. */
    public void removeBubble(Bubble bubble, Runnable endAction) {
    public void removeBubble(@NonNull Bubble bubble, @NonNull Runnable endAction) {
        final boolean inTransition = bubble.getPreparingTransition() != null;
        ProtoLog.d(WM_SHELL_BUBBLES_NOISY,
                "BBLayerView.removeBubble(): bubble=%s hasBubbles=%b inTransition=%b",
                bubble, !mBubbleData.getBubbles().isEmpty(), inTransition);
        Runnable cleanUp = () -> {
            // The transition is already managing the task/wm state.
            bubble.cleanupViews(!inTransition);
            endAction.run();
        };
        if (mBubbleData.getBubbles().isEmpty() || inTransition) {
            if (mExpandedBubble != null && mExpandedBubble.getKey().equals(bubble.getKey())) {
                // If we are removing the last bubble or removing the current bubble via transition,
                // collapse the expanded view and clean up bubbles at the end.
                collapse(cleanUp);
            } else {
                ProtoLog.d(WM_SHELL_BUBBLES_NOISY, "  Skipping, does not match expanded view");
                cleanUp.run();
            }
        } else {
            cleanUp.run();
        }