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

Commit 39c26109 authored by Ats Jenk's avatar Ats Jenk
Browse files

Only determine stage to top when split screen is visible

When a bubbled task is moving out of split, only move another stage to
top if split screen is currently visible. If split screen is not
visible, nothing should move to top.

Bug: 429536432
Test: atest WMShellUnitTests:StageCoordinatorTests
Flag: EXEMPT BUGFIX
Change-Id: I0cbacb679e0588a75235c7a95459c1908509f42c
parent c31e8fbe
Loading
Loading
Loading
Loading
+21 −15
Original line number Diff line number Diff line
@@ -2379,6 +2379,7 @@ public class StageCoordinator extends StageCoordinatorAbstract {
            return;
        }
        int stageToTop = STAGE_TYPE_UNDEFINED;
        if (isSplitScreenVisible()) {
            if (enableFlexibleSplit()) {
                for (StageTaskListener activeStage : mStageOrderOperator.getActiveStages()) {
                    // See if any other stage still has children
@@ -2388,11 +2389,13 @@ public class StageCoordinator extends StageCoordinatorAbstract {
                    }
                }
            } else {
            final StageTaskListener remainingStage = stage == mMainStage ? mSideStage : mMainStage;
                final StageTaskListener remainingStage =
                        stage == mMainStage ? mSideStage : mMainStage;
                if (remainingStage.getChildCount() > 0) {
                    stageToTop = remainingStage.getId();
                }
            }
        }
        ProtoLog.d(WM_SHELL_SPLIT_SCREEN,
                "onChildTaskMovedToBubble: taskId=%d in stage=%s moved to bubble exit split "
                        + "stageToTop=%s",
@@ -3575,10 +3578,13 @@ public class StageCoordinator extends StageCoordinatorAbstract {
                recentTasks -> recentTasks.removeSplitPair(triggerTask.taskId));
        logExit(EXIT_REASON_CHILD_TASK_ENTER_BUBBLE);

        int topStage = STAGE_TYPE_UNDEFINED;
        if (isSplitScreenVisible()) {
            int stage = getStageOfTask(triggerTask.taskId);
        int topStage = (stage == STAGE_TYPE_MAIN)
            topStage = (stage == STAGE_TYPE_MAIN)
                    ? STAGE_TYPE_SIDE
                    : STAGE_TYPE_MAIN;
        }
        prepareExitSplitScreen(topStage, outWCT, EXIT_REASON_UNKNOWN);
    }

+52 −0
Original line number Diff line number Diff line
@@ -784,6 +784,7 @@ public class StageCoordinatorTests extends ShellTestCase {
        when(mMainStage.isActive()).thenReturn(true);
        when(mMainStage.getChildCount()).thenReturn(1);
        when(mSideStage.getChildCount()).thenReturn(0);
        when(mStageCoordinator.isSplitScreenVisible()).thenReturn(true);
        mStageCoordinator.onChildTaskMovedToBubble(mSideStage, /* taskId= */ 8);
        verify(mSplitScreenTransitions).startDismissTransition(any(), any(), eq(STAGE_TYPE_MAIN),
                eq(SplitScreenController.EXIT_REASON_CHILD_TASK_ENTER_BUBBLE));
@@ -794,6 +795,7 @@ public class StageCoordinatorTests extends ShellTestCase {
        when(mMainStage.isActive()).thenReturn(true);
        when(mMainStage.getChildCount()).thenReturn(0);
        when(mSideStage.getChildCount()).thenReturn(0);
        when(mStageCoordinator.isSplitScreenVisible()).thenReturn(true);
        mStageCoordinator.onChildTaskMovedToBubble(mSideStage, /* taskId= */ 8);
        verify(mSplitScreenTransitions).startDismissTransition(any(), any(),
                eq(STAGE_TYPE_UNDEFINED),
@@ -809,6 +811,20 @@ public class StageCoordinatorTests extends ShellTestCase {
                anyInt());
    }

    @Test
    public void testOnChildTaskMovedToBubble_splitNotVisible_dismissesSplitWithUndefinedTopStage() {
        when(mMainStage.isActive()).thenReturn(true);
        when(mMainStage.getChildCount()).thenReturn(1);
        when(mSideStage.getChildCount()).thenReturn(0);
        when(mStageCoordinator.isSplitScreenVisible()).thenReturn(false);

        mStageCoordinator.onChildTaskMovedToBubble(mSideStage, /* taskId= */ 8);

        verify(mSplitScreenTransitions).startDismissTransition(any(), any(),
                eq(STAGE_TYPE_UNDEFINED),
                eq(SplitScreenController.EXIT_REASON_CHILD_TASK_ENTER_BUBBLE));
    }

    @Test
    @EnableFlags(FLAG_ENABLE_FLEXIBLE_TWO_APP_SPLIT)
    public void startTasks_withFlexibleTwoAppSplit_hidesDividerWhenStagesInactive() {
@@ -876,6 +892,42 @@ public class StageCoordinatorTests extends ShellTestCase {
        verify(mStageCoordinator, never()).setDividerVisibility(eq(false), any());
    }

    @Test
    public void testAddExitForBubblesIfNeeded_splitVisible_hasStageToTop() {
        when(mStageCoordinator.isSplitActive()).thenReturn(true);
        when(mStageCoordinator.isSplitScreenVisible()).thenReturn(true);
        doReturn(STAGE_TYPE_MAIN).when(mStageCoordinator).getStageOfTask(anyInt());

        android.window.TransitionRequestInfo request =
                mock(android.window.TransitionRequestInfo.class);
        ActivityManager.RunningTaskInfo taskInfo = new TestRunningTaskInfoBuilder().build();
        when(request.getTriggerTask()).thenReturn(taskInfo);

        WindowContainerTransaction wct = new WindowContainerTransaction();
        mStageCoordinator.addExitForBubblesIfNeeded(request, wct);

        verify(mStageCoordinator).prepareExitSplitScreen(eq(STAGE_TYPE_SIDE),
                eq(wct), anyInt());
    }

    @Test
    public void testAddExitForBubblesIfNeeded_splitNotVisible_noStageToTop() {
        when(mStageCoordinator.isSplitActive()).thenReturn(true);
        when(mStageCoordinator.isSplitScreenVisible()).thenReturn(false);
        doReturn(STAGE_TYPE_MAIN).when(mStageCoordinator).getStageOfTask(anyInt());

        android.window.TransitionRequestInfo request =
                mock(android.window.TransitionRequestInfo.class);
        ActivityManager.RunningTaskInfo taskInfo = new TestRunningTaskInfoBuilder().build();
        when(request.getTriggerTask()).thenReturn(taskInfo);

        WindowContainerTransaction wct = new WindowContainerTransaction();
        mStageCoordinator.addExitForBubblesIfNeeded(request, wct);

        verify(mStageCoordinator).prepareExitSplitScreen(eq(STAGE_TYPE_UNDEFINED),
                eq(wct), anyInt());
    }

    private Transitions createTestTransitions() {
        ShellInit shellInit = new ShellInit(mMainExecutor);
        final Transitions t = new Transitions(mContext, shellInit, mock(ShellController.class),