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

Commit 0e1a9766 authored by Mady Mellor's avatar Mady Mellor Committed by Android (Google) Code Review
Browse files

Merge "Clear out the taskId when the TaskView is removed" into main

parents d6b31e94 85ee9e19
Loading
Loading
Loading
Loading
+0 −48
Original line number Diff line number Diff line
@@ -135,52 +135,4 @@ class BubbleTaskStackListenerTest {
        verify(taskOrganizer).setInterceptBackPressedOnTaskRoot(task.token, false /* intercept */)
        verify(taskViewTaskController).notifyTaskRemovalStarted(task)
    }

    @Test
    fun onActivityRestartAttempt_overflowAppBubbleRestart_promotesFromOverflow() {
        bubbleData.stub {
            on { getOverflowBubbleWithTaskId(bubbleTaskId) } doReturn bubble
        }

        bubbleTaskStackListener.onActivityRestartAttempt(
            task,
            homeTaskVisible = false,
            clearedTask = false,
            wasVisible = false,
        )

        verify(bubbleController).promoteBubbleFromOverflow(bubble)
        verify(bubbleData).setExpanded(true)
    }

    @Test
    @EnableFlags(
        FLAG_ENABLE_CREATE_ANY_BUBBLE,
        FLAG_ENABLE_BUBBLE_ANYTHING,
        FLAG_EXCLUDE_TASK_FROM_RECENTS,
        FLAG_DISALLOW_BUBBLE_TO_ENTER_PIP,
    )
    fun onActivityRestartAttempt_overflowAppBubbleToFullscreen_notifiesTaskRemoval() {
        task.configuration.windowConfiguration.windowingMode = WINDOWING_MODE_FULLSCREEN
        bubbleData.stub {
            on { getOverflowBubbleWithTaskId(bubbleTaskId) } doReturn bubble
        }

        bubbleTaskStackListener.onActivityRestartAttempt(
            task,
            homeTaskVisible = false,
            clearedTask = false,
            wasVisible = false,
        )

        val taskViewTaskController = bubble.taskView.controller
        val taskOrganizer = taskViewTaskController.taskOrganizer
        val wct = argumentCaptor<WindowContainerTransaction>().let { wctCaptor ->
            verify(taskOrganizer).applyTransaction(wctCaptor.capture())
            wctCaptor.lastValue
        }
        verifyExitBubbleTransaction(wct, bubbleTaskToken.asBinder())
        verify(taskOrganizer).setInterceptBackPressedOnTaskRoot(task.token, false /* intercept */)
        verify(taskViewTaskController).notifyTaskRemovalStarted(task)
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -670,6 +670,7 @@ public class Bubble implements BubbleViewProvider {
            mBubbleTaskView.cleanup();
            mBubbleTaskView = null;
        }
        mTaskId = INVALID_TASK_ID;
    }

    /**
+0 −6
Original line number Diff line number Diff line
@@ -1259,12 +1259,6 @@ public class BubbleData {
                b.getIconView() != null && b.getIconView().equals(view));
    }

    /** @return the overflow bubble that matches the provided taskId. */
    @Nullable
    Bubble getOverflowBubbleWithTaskId(int taskId) {
        return getBubbleWithPredicate(mOverflowBubbles, b -> b.getTaskId() == taskId);
    }

    /** @return the overflow bubble that matches the provided key. */
    @Nullable
    public Bubble getOverflowBubbleWithKey(String key) {
+0 −38
Original line number Diff line number Diff line
@@ -64,14 +64,6 @@ class BubbleTaskStackListener(
            }
            return@onActivityRestartAttempt
        }

        bubbleData.getOverflowBubbleWithTaskId(taskId)?.let { bubble ->
            if (isBubbleToFullscreen(task)) {
                moveCollapsedOverflowBubbleToFullscreen(bubble, task)
            } else {
                selectAndExpandOverflowBubble(bubble, task)
            }
        }
    }

    /** Selects and expands a bubble that is currently in the stack. */
@@ -103,36 +95,6 @@ class BubbleTaskStackListener(
        collapsedBubbleToFullscreenInternal(bubble, task)
    }

    /** Selects and expands a bubble that is currently in the overflow. */
    private fun selectAndExpandOverflowBubble(
        bubble: Bubble,
        task: ActivityManager.RunningTaskInfo,
    ) {
        ProtoLog.d(
            WM_SHELL_BUBBLES,
            "selectAndExpandOverflowBubble - taskId=%d selecting matching overflow bubble=%s",
            task.taskId,
            bubble.key,
        )
        bubbleController.promoteBubbleFromOverflow(bubble)
        bubbleData.setExpanded(true)
    }

    /** Moves a collapsed overflow bubble to fullscreen. */
    private fun moveCollapsedOverflowBubbleToFullscreen(
        bubble: Bubble,
        task: ActivityManager.RunningTaskInfo,
    ) {
        ProtoLog.d(
            WM_SHELL_BUBBLES,
            "moveCollapsedOverflowBubbleToFullscreen - taskId=%d " +
                    "moving matching overflow bubble=%s to fullscreen",
            task.taskId,
            bubble.key,
        )
        collapsedBubbleToFullscreenInternal(bubble, task)
    }

    /** Internal function to move a collapsed bubble to fullscreen task. */
    private fun collapsedBubbleToFullscreenInternal(
        bubble: Bubble,
+16 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.wm.shell.bubbles;

import static android.app.ActivityTaskManager.INVALID_TASK_ID;

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

import static org.junit.Assert.assertEquals;
@@ -299,6 +301,20 @@ public class BubbleTest extends ShellTestCase {
        assertThat(bubbleInfo.getPackageName()).isEqualTo(bubble.getPackageName());
    }

    @Test
    public void testCleanupTaskView() {
        // Create a bubble with a task id
        TaskInfo info = mock(TaskInfo.class);
        info.taskId = 123;
        info.baseActivity = new ComponentName(mContext, "SomeActivity");
        Bubble bubble = Bubble.createTaskBubble(info, new UserHandle(1),
                null /* icon */, mMainExecutor, mBgExecutor);
        assertThat(bubble.getTaskId()).isEqualTo(123);

        bubble.cleanupTaskView();
        assertThat(bubble.getTaskId()).isEqualTo(INVALID_TASK_ID);
    }

    private Intent createIntent() {
        Intent intent = new Intent(mContext, BubblesTestActivity.class);
        intent.setPackage(mContext.getPackageName());