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

Commit 86ca6ce9 authored by Merissa Mitchell's avatar Merissa Mitchell
Browse files

[PIP2] Add Shell requested remove PiP transition.

Recall: http://recall/clips/91a0fe99-d96b-4639-9812-03167a33c4b0

Bug: 372048924
Bug: 372320038
Test: Launch PiP and manually verify remove button on PiP menu removes
PiP window.
Flag: com.android.wm.shell.enable_pip2

Change-Id: Icad8428a6e28eb1d27d0220976e9acd93a32327d
parent fca8ee70
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 */);
        // mPipTaskOrganizer.removePip();
        mPipScheduler.removePipAfterAnimation();
    }

    /** Sets the movement bounds to use to constrain PIP position animations. */
+40 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.wm.shell.pip2.phone;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;

import static com.android.wm.shell.transition.Transitions.TRANSIT_EXIT_PIP;
import static com.android.wm.shell.transition.Transitions.TRANSIT_REMOVE_PIP;

import android.content.BroadcastReceiver;
import android.content.Context;
@@ -38,6 +39,8 @@ import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.pip.PipBoundsState;
import com.android.wm.shell.common.pip.PipUtils;
import com.android.wm.shell.pip.PipTransitionController;
import com.android.wm.shell.pip2.PipSurfaceTransactionHelper;
import com.android.wm.shell.pip2.animation.PipAlphaAnimator;
import com.android.wm.shell.protolog.ShellProtoLogGroup;

import java.lang.annotation.Retention;
@@ -56,6 +59,8 @@ public class PipScheduler {
    private final PipTransitionState mPipTransitionState;
    private PipSchedulerReceiver mSchedulerReceiver;
    private PipTransitionController mPipTransitionController;
    private final PipSurfaceTransactionHelper.SurfaceControlTransactionFactory
            mSurfaceControlTransactionFactory;

    @Nullable private Runnable mUpdateMovementBoundsRunnable;

@@ -109,6 +114,8 @@ public class PipScheduler {
            ContextCompat.registerReceiver(mContext, mSchedulerReceiver,
                    new IntentFilter(BROADCAST_FILTER), ContextCompat.RECEIVER_EXPORTED);
        }
        mSurfaceControlTransactionFactory =
                new PipSurfaceTransactionHelper.VsyncSurfaceControlTransactionFactory();
    }

    ShellExecutor getMainExecutor() {
@@ -133,6 +140,18 @@ public class PipScheduler {
        return wct;
    }

    @Nullable
    private WindowContainerTransaction getRemovePipTransaction() {
        if (mPipTransitionState.mPipTaskToken == null) {
            return null;
        }
        WindowContainerTransaction wct = new WindowContainerTransaction();
        wct.setBounds(mPipTransitionState.mPipTaskToken, null);
        wct.setWindowingMode(mPipTransitionState.mPipTaskToken, WINDOWING_MODE_UNDEFINED);
        wct.reorder(mPipTransitionState.mPipTaskToken, false);
        return wct;
    }

    /**
     * Schedules exit PiP via expand transition.
     */
@@ -146,6 +165,27 @@ public class PipScheduler {
        }
    }

    // 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 = new PipAlphaAnimator(mContext,
                mPipTransitionState.mPinnedTaskLeash, tx, PipAlphaAnimator.FADE_OUT);
        animator.setAnimationEndCallback(this::scheduleRemovePipImmediately);
        animator.start();
    }

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

    /**
     * Schedules resize PiP via double tap.
     */
+3 −2
Original line number Diff line number Diff line
@@ -90,9 +90,10 @@ public class PipTaskListener implements ShellTaskOrganizer.TaskListener,
        if (mPictureInPictureParams.equals(params)) {
            return;
        }
        if (PipUtils.remoteActionsChanged(params.getActions(), mPictureInPictureParams.getActions())
        if (params != null && (PipUtils.remoteActionsChanged(params.getActions(),
                mPictureInPictureParams.getActions())
                || !PipUtils.remoteActionsMatch(params.getCloseAction(),
                mPictureInPictureParams.getCloseAction())) {
                mPictureInPictureParams.getCloseAction()))) {
            for (PipParamsChangedCallback listener : mPipParamsChangedListeners) {
                listener.onActionsChanged(params.getActions(), params.getCloseAction());
            }
+6 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.view.WindowManager.TRANSIT_TO_BACK;
import static android.view.WindowManager.TRANSIT_TO_FRONT;

import static com.android.wm.shell.transition.Transitions.TRANSIT_EXIT_PIP;
import static com.android.wm.shell.transition.Transitions.TRANSIT_REMOVE_PIP;
import static com.android.wm.shell.transition.Transitions.TRANSIT_RESIZE_PIP;

import android.animation.Animator;
@@ -605,8 +606,11 @@ public class PipTransition extends PipTransitionController implements
                && pipChange.getMode() == TRANSIT_TO_BACK;
        boolean isPipClosed = info.getType() == TRANSIT_CLOSE
                && pipChange.getMode() == TRANSIT_CLOSE;
        // PiP is being removed if the pinned task is either moved to back or closed.
        return isPipMovedToBack || isPipClosed;
        // If PiP is dismissed by user (i.e. via dismiss button in PiP menu)
        boolean isPipDismissed = info.getType() == TRANSIT_REMOVE_PIP
                && pipChange.getMode() == TRANSIT_TO_BACK;
        // PiP is being removed if the pinned task is either moved to back, closed, or dismissed.
        return isPipMovedToBack || isPipClosed || isPipDismissed;
    }

    //