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

Commit 6a554350 authored by Ben Lin's avatar Ben Lin
Browse files

PiP: Move enter-PiP on-pause logic.

Previously, we rely on #makeInvisible in other situations as the last
place to enter PIP before activity gets put to stopped (e.g. ARC++).
However with Shell transitions, #makeInvisible is now immediately called
as user starts the transition into Recents, which would cause app to
enter PIP right away. Thus, removing this part of the code, and instead
we will wait until the Recents transition is finished and try to pause
the app with userLeaveHint before visibility is committed.

Also, when shell transition is enabled, make an explicit transition when
dmissing PIP to properly commit the necessary window container changes
to WM. The tranition will just have no animation.

Bug: 165793917
Test: Enable Shell transition, enter PIP via gesture (non-auto enter
case)
Test: Enable Shell transition, dismiss PIP via dismiss bubble

Change-Id: Ic2c8691f5a1f359b822b1874b16a327bc689f34d
parent 12e613d0
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -393,6 +393,11 @@ public interface WindowManager extends ViewManager {
     * @hide
     */
    int TRANSIT_KEYGUARD_UNOCCLUDE = 9;
    /**
     * A window is starting to enter PiP.
     * @hide
     */
    int TRANSIT_PIP = 10;
    /**
     * The first slot for custom transition types. Callers (like Shell) can make use of custom
     * transition types for dealing with special cases. These types are effectively ignored by
@@ -402,7 +407,7 @@ public interface WindowManager extends ViewManager {
     * implementation.
     * @hide
     */
    int TRANSIT_FIRST_CUSTOM = 10;
    int TRANSIT_FIRST_CUSTOM = 11;

    /**
     * @hide
@@ -418,6 +423,7 @@ public interface WindowManager extends ViewManager {
            TRANSIT_KEYGUARD_GOING_AWAY,
            TRANSIT_KEYGUARD_OCCLUDE,
            TRANSIT_KEYGUARD_UNOCCLUDE,
            TRANSIT_PIP,
            TRANSIT_FIRST_CUSTOM
    })
    @Retention(RetentionPolicy.SOURCE)
+11 −0
Original line number Diff line number Diff line
@@ -463,6 +463,15 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
    }

    private void removePipImmediately() {
        if (Transitions.ENABLE_SHELL_TRANSITIONS) {
            final WindowContainerTransaction wct = new WindowContainerTransaction();
            wct.setBounds(mToken, null);
            wct.setWindowingMode(mToken, WINDOWING_MODE_UNDEFINED);
            wct.reorder(mToken, false);
            mPipTransitionController.startTransition(null, wct);
            return;
        }

        try {
            // Reset the task bounds first to ensure the activity configuration is reset as well
            final WindowContainerTransaction wct = new WindowContainerTransaction();
@@ -524,6 +533,8 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
        if (Transitions.ENABLE_SHELL_TRANSITIONS) {
            if (mOneShotAnimationType == ANIM_TYPE_BOUNDS) {
                mPipMenuController.attach(mLeash);
            } else if (mOneShotAnimationType == ANIM_TYPE_ALPHA) {
                mOneShotAnimationType = ANIM_TYPE_BOUNDS;
            }
            return;
        }
+44 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.wm.shell.pip;

import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.view.WindowManager.TRANSIT_PIP;
import static android.window.TransitionInfo.FLAG_IS_WALLPAPER;

import static com.android.wm.shell.pip.PipAnimationController.ANIM_TYPE_ALPHA;
@@ -27,6 +28,7 @@ import static com.android.wm.shell.pip.PipAnimationController.TRANSITION_DIRECTI
import static com.android.wm.shell.pip.PipAnimationController.isInPipDirection;
import static com.android.wm.shell.pip.PipAnimationController.isOutPipDirection;
import static com.android.wm.shell.transition.Transitions.TRANSIT_EXIT_PIP;
import static com.android.wm.shell.transition.Transitions.TRANSIT_REMOVE_PIP;

import android.app.TaskInfo;
import android.content.Context;
@@ -73,10 +75,28 @@ public class PipTransition extends PipTransitionController {
                .getInteger(R.integer.config_pipResizeAnimationDuration);
    }

    @Override
    public void setIsFullAnimation(boolean isFullAnimation) {
        setOneShotAnimationType(isFullAnimation ? ANIM_TYPE_BOUNDS : ANIM_TYPE_ALPHA);
    }

    /**
     * Sets the preferred animation type for one time.
     * This is typically used to set the animation type to
     * {@link PipAnimationController#ANIM_TYPE_ALPHA}.
     */
    private void setOneShotAnimationType(@PipAnimationController.AnimationType int animationType) {
        mOneShotAnimationType = animationType;
    }

    @Override
    public void startTransition(Rect destinationBounds, WindowContainerTransaction out) {
        if (destinationBounds != null) {
            mExitDestinationBounds.set(destinationBounds);
            mTransitions.startTransition(TRANSIT_EXIT_PIP, out, this);
        } else {
            mTransitions.startTransition(TRANSIT_REMOVE_PIP, out, this);
        }
    }

    @Override
@@ -96,6 +116,14 @@ public class PipTransition extends PipTransitionController {
            return success;
        }

        if (info.getType() == TRANSIT_REMOVE_PIP) {
            startTransaction.apply();
            finishTransaction.setWindowCrop(info.getChanges().get(0).getLeash(),
                    mPipBoundsState.getDisplayBounds());
            finishCallback.onTransitionFinished(null, null);
            return true;
        }

        // Search for an Enter PiP transition (along with a show wallpaper one)
        TransitionInfo.Change enterPip = null;
        TransitionInfo.Change wallpaper = null;
@@ -129,13 +157,23 @@ public class PipTransition extends PipTransitionController {
    @Override
    public WindowContainerTransaction handleRequest(@NonNull IBinder transition,
            @NonNull TransitionRequestInfo request) {
        if (request.getType() == TRANSIT_PIP) {
            WindowContainerTransaction wct = new WindowContainerTransaction();
            mPipTransitionState.setTransitionState(PipTransitionState.ENTRY_SCHEDULED);
            final Rect destinationBounds = mPipBoundsAlgorithm.getEntryDestinationBounds();
            wct.setActivityWindowingMode(request.getTriggerTask().token, WINDOWING_MODE_UNDEFINED);
            wct.setBounds(request.getTriggerTask().token, destinationBounds);
            return wct;
        } else {
            return null;
        }
    }

    @Override
    public void onFinishResize(TaskInfo taskInfo, Rect destinationBounds,
            @PipAnimationController.TransitionDirection int direction,
            SurfaceControl.Transaction tx) {

        if (isInPipDirection(direction)) {
            mPipTransitionState.setTransitionState(PipTransitionState.ENTERED_PIP);
        }
@@ -185,6 +223,9 @@ public class PipTransition extends PipTransitionController {
                    0 /* startingAngle */, Surface.ROTATION_0);
        } else if (mOneShotAnimationType == ANIM_TYPE_ALPHA) {
            startTransaction.setAlpha(leash, 0f);
            // PiP menu is attached late in the process here to avoid any artifacts on the leash
            // caused by addShellRoot when in gesture navigation mode.
            mPipMenuController.attach(leash);
            animator = mPipAnimationController.getAnimator(taskInfo, leash, destinationBounds,
                    0f, 1f);
            mOneShotAnimationType = ANIM_TYPE_BOUNDS;
+9 −0
Original line number Diff line number Diff line
@@ -100,6 +100,15 @@ public abstract class PipTransitionController implements Transitions.TransitionH
            SurfaceControl.Transaction tx) {
    }

    /**
     * Called to inform the transition that the animation should start with the assumption that
     * PiP is not animating from its original bounds, but rather a continuation of another
     * animation. For example, gesture navigation would first fade out the PiP activity, and the
     * transition should be responsible to animate in (such as fade in) the PiP.
     */
    public void setIsFullAnimation(boolean isFullAnimation) {
    }

    /**
     * Called when the Shell wants to starts a transition/animation.
     */
+3 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import com.android.wm.shell.pip.IPip;
import com.android.wm.shell.pip.IPipAnimationListener;
import com.android.wm.shell.pip.PinnedStackListenerForwarder;
import com.android.wm.shell.pip.Pip;
import com.android.wm.shell.pip.PipAnimationController;
import com.android.wm.shell.pip.PipBoundsAlgorithm;
import com.android.wm.shell.pip.PipBoundsState;
import com.android.wm.shell.pip.PipMediaController;
@@ -528,6 +529,8 @@ public class PipController implements PipTransitionController.PipTransitionCallb

    private void setPinnedStackAnimationType(int animationType) {
        mPipTaskOrganizer.setOneShotAnimationType(animationType);
        mPipTransitionController.setIsFullAnimation(
                animationType == PipAnimationController.ANIM_TYPE_BOUNDS);
    }

    private void setPinnedStackAnimationListener(IPipAnimationListener callback) {
Loading