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

Commit 33b821c2 authored by Ikram Gabiyev's avatar Ikram Gabiyev Committed by Android (Google) Code Review
Browse files

Merge "[1/2][PiP2] Move removePip animation to transition" into main

parents 8a5f1e18 44088155
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -350,7 +350,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
        }
        cancelPhysicsAnimation();
        mMenuController.hideMenu(ANIM_TYPE_DISMISS, false /* resize */);
        mPipScheduler.removePipAfterAnimation();
        mPipScheduler.scheduleRemovePip();
    }

    /** Sets the movement bounds to use to constrain PIP position animations. */
+13 −21
Original line number Diff line number Diff line
@@ -122,34 +122,26 @@ public class PipScheduler {
     * Schedules exit PiP via expand transition.
     */
    public void scheduleExitPipViaExpand() {
        mMainExecutor.execute(() -> {
            if (!mPipTransitionState.isInPip()) return;
            WindowContainerTransaction wct = getExitPipViaExpandTransaction();
            if (wct != null) {
            mMainExecutor.execute(() -> {
                mPipTransitionController.startExitTransition(TRANSIT_EXIT_PIP, wct,
                        null /* destinationBounds */);
            });
            }
    }

    // TODO: Optimize this by running the animation as part of the transition
    /** Runs remove PiP animation and schedules remove PiP transition after the animation ends. */
    public void removePipAfterAnimation() {
        SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();
        PipAlphaAnimator animator = mPipAlphaAnimatorSupplier.get(mContext,
                mPipTransitionState.getPinnedTaskLeash(), tx, PipAlphaAnimator.FADE_OUT);
        animator.setAnimationEndCallback(this::scheduleRemovePipImmediately);
        animator.start();
        });
    }

    /** Schedules remove PiP transition. */
    private void scheduleRemovePipImmediately() {
    public void scheduleRemovePip() {
        mMainExecutor.execute(() -> {
            if (!mPipTransitionState.isInPip()) return;
            WindowContainerTransaction wct = getRemovePipTransaction();
            if (wct != null) {
            mMainExecutor.execute(() -> {
                mPipTransitionController.startExitTransition(TRANSIT_REMOVE_PIP, wct,
                        null /* destinationBounds */);
            });
            }
        });
    }

    /**
+11 −5
Original line number Diff line number Diff line
@@ -278,7 +278,8 @@ public class PipTransition extends PipTransitionController implements
        }

        if (isRemovePipTransition(info)) {
            return removePipImmediately(info, startTransaction, finishTransaction, finishCallback);
            mPipTransitionState.setState(PipTransitionState.EXITING_PIP);
            return startRemoveAnimation(info, startTransaction, finishTransaction, finishCallback);
        }
        return false;
    }
@@ -668,13 +669,18 @@ public class PipTransition extends PipTransitionController implements
        return true;
    }

    private boolean removePipImmediately(@NonNull TransitionInfo info,
    private boolean startRemoveAnimation(@NonNull TransitionInfo info,
            @NonNull SurfaceControl.Transaction startTransaction,
            @NonNull SurfaceControl.Transaction finishTransaction,
            @NonNull Transitions.TransitionFinishCallback finishCallback) {
        startTransaction.apply();
        finishCallback.onTransitionFinished(null);
        mPipTransitionState.setState(PipTransitionState.EXITED_PIP);
        TransitionInfo.Change pipChange = getChangeByToken(info,
                mPipTransitionState.getPipTaskToken());
        mFinishCallback = finishCallback;
        PipAlphaAnimator animator = new PipAlphaAnimator(mContext, pipChange.getLeash(),
                startTransaction, PipAlphaAnimator.FADE_OUT);
        finishTransaction.setAlpha(pipChange.getLeash(), 0f);
        animator.setAnimationEndCallback(this::finishTransition);
        animator.start();
        return true;
    }

+10 −10
Original line number Diff line number Diff line
@@ -120,15 +120,22 @@ public class PipSchedulerTest {
    @Test
    public void scheduleExitPipViaExpand_nullTaskToken_noop() {
        setNullPipTaskToken();
        when(mMockPipTransitionState.isInPip()).thenReturn(true);

        mPipScheduler.scheduleExitPipViaExpand();

        verify(mMockMainExecutor, never()).execute(any());
        verify(mMockMainExecutor, times(1)).execute(mRunnableArgumentCaptor.capture());
        assertNotNull(mRunnableArgumentCaptor.getValue());
        mRunnableArgumentCaptor.getValue().run();

        verify(mMockPipTransitionController, never())
                .startExitTransition(eq(TRANSIT_EXIT_PIP), any(), isNull());
    }

    @Test
    public void scheduleExitPipViaExpand_exitTransitionCalled() {
        setMockPipTaskToken();
        when(mMockPipTransitionState.isInPip()).thenReturn(true);

        mPipScheduler.scheduleExitPipViaExpand();

@@ -142,20 +149,13 @@ public class PipSchedulerTest {

    @Test
    public void removePipAfterAnimation() {
        //TODO: Update once this is changed to run animation as part of transition
        setMockPipTaskToken();
        when(mMockPipTransitionState.isInPip()).thenReturn(true);

        mPipScheduler.removePipAfterAnimation();
        verify(mMockAlphaAnimator, times(1))
                .setAnimationEndCallback(mRunnableArgumentCaptor.capture());
        assertNotNull(mRunnableArgumentCaptor.getValue());
        verify(mMockAlphaAnimator, times(1)).start();

        mRunnableArgumentCaptor.getValue().run();
        mPipScheduler.scheduleRemovePip();

        verify(mMockMainExecutor, times(1)).execute(mRunnableArgumentCaptor.capture());
        assertNotNull(mRunnableArgumentCaptor.getValue());

        mRunnableArgumentCaptor.getValue().run();

        verify(mMockPipTransitionController, times(1))
+5 −1
Original line number Diff line number Diff line
@@ -225,6 +225,7 @@ import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_F
import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_NONE;
import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE;
import static com.android.server.wm.ActivityTaskManagerService.getInputDispatchingTimeoutMillisLocked;
import static com.android.server.wm.ActivityTaskManagerService.isPip2ExperimentEnabled;
import static com.android.server.wm.IdentifierProto.HASH_CODE;
import static com.android.server.wm.IdentifierProto.TITLE;
import static com.android.server.wm.IdentifierProto.USER_ID;
@@ -1495,7 +1496,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            // precede the configuration change from the resize.)
            mLastReportedPictureInPictureMode = inPictureInPictureMode;
            mLastReportedMultiWindowMode = inPictureInPictureMode;
            if (!isPip2ExperimentEnabled()) {
                // PiP2 should handle sending out the configuration as a part of Shell Transitions.
                ensureActivityConfiguration(true /* ignoreVisibility */);
            }
            if (inPictureInPictureMode && findMainWindow() == null
                    && task.topRunningActivity() == this) {
                // Prevent malicious app entering PiP without valid WindowState, which can in turn
Loading