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

Commit 0e99af53 authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Send isTransitioningToPip when pip anim starts

This is to fix a regression from ag/28340648, which breaks the contract
that PictureInPictureUiState(isTransitioningToPip=true) should be sent
to the app at the very beginning of the enterign PiP animation.

In this change
- We explictly send the callback when SysUI is notified by the Launcher
  that the animation is started
- The path to trigger the callback for button navigation mode is kept
- A check for swipe-pip-to-home is added before sending the callback, to
  make sure there is no double callback when auto-enter-pip

Flag: EXEMPT bugfix
Video: http://recall/-/aaaaaabFQoRHlzixHdtY/cKlb6lqM1DHGk2hG4eaBYB
Video: http://recall/-/aaaaaabFQoRHlzixHdtY/dzrznErP2hQFLs7cajPFKx
Bug: 359264914
Test: Verify callback is sent at the beginning in both gesture and
      button navigation mode
Test: atest CtsWindowManagerDeviceOther:PinnedStackTests
Change-Id: Ibbfb78bb7b410b88587595be835f8d003c0bd619
parent 68be647c
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -496,7 +496,9 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "startSwipePipToHome: %s, state=%s", componentName, mPipTransitionState);
        mPipTransitionState.setInSwipePipToHomeTransition(true);
        if (!ENABLE_SHELL_TRANSITIONS) {
        if (ENABLE_SHELL_TRANSITIONS) {
            mPipTransitionController.onStartSwipePipToHome();
        } else {
            sendOnPipTransitionStarted(TRANSITION_DIRECTION_TO_PIP);
        }
        setBoundsStateForEntry(componentName, pictureInPictureParams, activityInfo);
+5 −0
Original line number Diff line number Diff line
@@ -190,6 +190,11 @@ public class PipTransition extends PipTransitionController {
        }
    }

    @Override
    protected boolean isInSwipePipToHomeTransition() {
        return mPipTransitionState.getInSwipePipToHomeTransition();
    }

    @Override
    public void startExitTransition(int type, WindowContainerTransaction out,
            @Nullable Rect destinationBounds) {
+28 −1
Original line number Diff line number Diff line
@@ -189,6 +189,32 @@ public abstract class PipTransitionController implements Transitions.TransitionH
        mPipTransitionCallbacks.put(callback, executor);
    }

    protected void onStartSwipePipToHome() {
        if (Flags.enablePipUiStateCallbackOnEntering()) {
            try {
                ActivityTaskManager.getService().onPictureInPictureUiStateChanged(
                        new PictureInPictureUiState.Builder()
                                .setTransitioningToPip(true)
                                .build());
            } catch (RemoteException | IllegalStateException e) {
                ProtoLog.e(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                        "Failed to set alert PiP state change.");
            }
        }
    }

    /**
     * Used in {@link #sendOnPipTransitionStarted(int)} to decide whether we should send the
     * PictureInPictureUiState change callback on transition start.
     * For instance, in auto-enter-pip case, {@link #onStartSwipePipToHome()} should have signaled
     * the app, and we can return {@code true} here to avoid double callback.
     *
     * @return {@code true} if there is a ongoing swipe pip to home transition.
     */
    protected boolean isInSwipePipToHomeTransition() {
        return false;
    }

    protected void sendOnPipTransitionStarted(
            @PipAnimationController.TransitionDirection int direction) {
        final Rect pipBounds = mPipBoundsState.getBounds();
@@ -199,7 +225,8 @@ public abstract class PipTransitionController implements Transitions.TransitionH
            entry.getValue().execute(
                    () -> entry.getKey().onPipTransitionStarted(direction, pipBounds));
        }
        if (isInPipDirection(direction) && Flags.enablePipUiStateCallbackOnEntering()) {
        if (isInPipDirection(direction) && Flags.enablePipUiStateCallbackOnEntering()
                && !isInSwipePipToHomeTransition()) {
            try {
                ActivityTaskManager.getService().onPictureInPictureUiStateChanged(
                        new PictureInPictureUiState.Builder()
+5 −0
Original line number Diff line number Diff line
@@ -137,6 +137,11 @@ public class PipTransition extends PipTransitionController implements
        }
    }

    @Override
    protected boolean isInSwipePipToHomeTransition() {
        return mPipTransitionState.isInSwipePipToHomeTransition();
    }

    //
    // Transition collection stage lifecycle hooks
    //