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

Commit 66799ad9 authored by Hongwei Wang's avatar Hongwei Wang Committed by Android (Google) Code Review
Browse files

Merge "Disallow enterPip from auto-pip-able while pausing" into main

parents 74e002c9 a1a9055d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -3736,6 +3736,14 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
            return false;
        }

        // If the app is using auto-enter, and it explicitly requests entering PiP while pausing,
        // return false immediately since auto-enter should take in place instead.
        if (fromClient && r.isState(PAUSING) && params.isAutoEnterEnabled()) {
            Slog.w(TAG, "Skip client enterPictureInPictureMode request while pausing,"
                    + " auto-enter-pip is enabled");
            return false;
        }

        if (isPip2ExperimentEnabled()) {
            // If PiP2 flag is on and request to enter PiP comes in,
            // we request a direct transition TRANSIT_PIP from Shell to get the right entry bounds.
+64 −0
Original line number Diff line number Diff line
@@ -316,6 +316,70 @@ public class ActivityTaskManagerServiceTests extends WindowTestsBase {
        //if record's null parent is not handled gracefully, test will fail with NPE
    }

    @Test
    public void testEnterPipModeWhenResumed_autoEnterEnabled_returnTrue() {
        final Task stack = new TaskBuilder(mSupervisor).setCreateActivity(true).build();
        final ActivityRecord activity = stack.getBottomMostTask().getTopNonFinishingActivity();
        PictureInPictureParams params = mock(PictureInPictureParams.class);
        activity.pictureInPictureArgs = params;

        doReturn(true).when(activity).isState(RESUMED);
        doReturn(false).when(activity).inPinnedWindowingMode();
        doReturn(true).when(activity).checkEnterPictureInPictureState(anyString(), anyBoolean());
        doReturn(true).when(params).isAutoEnterEnabled();

        assertTrue(mAtm.enterPictureInPictureMode(activity, params,
                true /* fromClient */, true /* isAutoEnter */));
    }

    @Test
    public void testEnterPipModeWhenResumed_autoEnterDisabled_returnTrue() {
        final Task stack = new TaskBuilder(mSupervisor).setCreateActivity(true).build();
        final ActivityRecord activity = stack.getBottomMostTask().getTopNonFinishingActivity();
        PictureInPictureParams params = mock(PictureInPictureParams.class);
        activity.pictureInPictureArgs = params;

        doReturn(true).when(activity).isState(RESUMED);
        doReturn(false).when(activity).inPinnedWindowingMode();
        doReturn(true).when(activity).checkEnterPictureInPictureState(anyString(), anyBoolean());
        doReturn(false).when(params).isAutoEnterEnabled();

        assertTrue(mAtm.enterPictureInPictureMode(activity, params,
                true /* fromClient */, false /* isAutoEnter */));
    }

    @Test
    public void testEnterPipModeWhenPausing_autoEnterEnabled_returnFalse() {
        final Task stack = new TaskBuilder(mSupervisor).setCreateActivity(true).build();
        final ActivityRecord activity = stack.getBottomMostTask().getTopNonFinishingActivity();
        PictureInPictureParams params = mock(PictureInPictureParams.class);
        activity.pictureInPictureArgs = params;

        doReturn(true).when(activity).isState(PAUSING);
        doReturn(false).when(activity).inPinnedWindowingMode();
        doReturn(true).when(activity).checkEnterPictureInPictureState(anyString(), anyBoolean());
        doReturn(true).when(params).isAutoEnterEnabled();

        assertFalse(mAtm.enterPictureInPictureMode(activity, params,
                true /* fromClient */, true /* isAutoEnter */));
    }

    @Test
    public void testEnterPipModeWhenPausing_autoEnterDisabled_returnTrue() {
        final Task stack = new TaskBuilder(mSupervisor).setCreateActivity(true).build();
        final ActivityRecord activity = stack.getBottomMostTask().getTopNonFinishingActivity();
        PictureInPictureParams params = mock(PictureInPictureParams.class);
        activity.pictureInPictureArgs = params;

        doReturn(true).when(activity).isState(PAUSING);
        doReturn(false).when(activity).inPinnedWindowingMode();
        doReturn(true).when(activity).checkEnterPictureInPictureState(anyString(), anyBoolean());
        doReturn(false).when(params).isAutoEnterEnabled();

        assertTrue(mAtm.enterPictureInPictureMode(activity, params,
                true /* fromClient */, false /* isAutoEnter */));
    }

    @Test
    public void testResumeNextActivityOnCrashedAppDied() {
        mSupervisor.beginDeferResume();