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

Commit 7c02512c authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Use source rect hint from stopSwipePipToHome of home" into main

parents acd050c5 1fc1fe5d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -53,9 +53,11 @@ interface IPip {
     * @param destinationBounds the destination bounds the PiP window lands into
     * @param overlay an optional overlay to fade out after entering PiP
     * @param appBounds the bounds used to set the buffer size of the optional content overlay
     * @param sourceRectHint the bounds to show in the transition to PiP
     */
    oneway void stopSwipePipToHome(int taskId, in ComponentName componentName,
            in Rect destinationBounds, in SurfaceControl overlay, in Rect appBounds) = 2;
            in Rect destinationBounds, in SurfaceControl overlay, in Rect appBounds,
            in Rect sourceRectHint) = 2;

    /**
     * Notifies the swiping Activity to PiP onto home transition is aborted
+20 −1
Original line number Diff line number Diff line
@@ -373,6 +373,10 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
    @NonNull
    final Rect mAppBounds = new Rect();

    /** The source rect hint from stopSwipePipToHome(). */
    @Nullable
    private Rect mSwipeSourceRectHint;

    public PipTaskOrganizer(Context context,
            @NonNull SyncTransactionQueue syncTransactionQueue,
            @NonNull PipTransitionState pipTransitionState,
@@ -504,7 +508,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
     * Expect {@link #onTaskAppeared(ActivityManager.RunningTaskInfo, SurfaceControl)} afterwards.
     */
    public void stopSwipePipToHome(int taskId, ComponentName componentName, Rect destinationBounds,
            SurfaceControl overlay, Rect appBounds) {
            SurfaceControl overlay, Rect appBounds, Rect sourceRectHint) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "stopSwipePipToHome: %s, stat=%s", componentName, mPipTransitionState);
        // do nothing if there is no startSwipePipToHome being called before
@@ -513,6 +517,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
        }
        mPipBoundsState.setBounds(destinationBounds);
        setContentOverlay(overlay, appBounds);
        mSwipeSourceRectHint = sourceRectHint;
        if (ENABLE_SHELL_TRANSITIONS && overlay != null) {
            // With Shell transition, the overlay was attached to the remote transition leash, which
            // will be removed when the current transition is finished, so we need to reparent it
@@ -529,6 +534,20 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
        }
    }

    /**
     * Returns non-null Rect if the pip is entering from swipe-to-home with a specified source hint.
     * This also consumes the rect hint.
     */
    @Nullable
    Rect takeSwipeSourceRectHint() {
        final Rect sourceRectHint = mSwipeSourceRectHint;
        if (sourceRectHint == null || sourceRectHint.isEmpty()) {
            return null;
        }
        mSwipeSourceRectHint = null;
        return mPipTransitionState.getInSwipePipToHomeTransition() ? sourceRectHint : null;
    }

    private void mayRemoveContentOverlay(SurfaceControl overlay) {
        final WeakReference<SurfaceControl> overlayRef = new WeakReference<>(overlay);
        final long timeoutDuration = (mEnterAnimationDuration
+5 −2
Original line number Diff line number Diff line
@@ -1004,8 +1004,11 @@ public class PipTransition extends PipTransitionController {
        final Rect currentBounds = pipChange.getStartAbsBounds();

        int rotationDelta = deltaRotation(startRotation, endRotation);
        Rect sourceHintRect = PipBoundsAlgorithm.getValidSourceHintRect(
        Rect sourceHintRect = mPipOrganizer.takeSwipeSourceRectHint();
        if (sourceHintRect == null) {
            sourceHintRect = PipBoundsAlgorithm.getValidSourceHintRect(
                    taskInfo.pictureInPictureParams, currentBounds, destinationBounds);
        }
        if (rotationDelta != Surface.ROTATION_0
                && endRotation != mPipDisplayLayoutState.getRotation()) {
            // Computes the destination bounds in new rotation.
+6 −4
Original line number Diff line number Diff line
@@ -1001,9 +1001,9 @@ public class PipController implements PipTransitionController.PipTransitionCallb
    }

    private void stopSwipePipToHome(int taskId, ComponentName componentName, Rect destinationBounds,
            SurfaceControl overlay, Rect appBounds) {
            SurfaceControl overlay, Rect appBounds, Rect sourceRectHint) {
        mPipTaskOrganizer.stopSwipePipToHome(taskId, componentName, destinationBounds, overlay,
                appBounds);
                appBounds, sourceRectHint);
    }

    private void abortSwipePipToHome(int taskId, ComponentName componentName) {
@@ -1291,13 +1291,15 @@ public class PipController implements PipTransitionController.PipTransitionCallb

        @Override
        public void stopSwipePipToHome(int taskId, ComponentName componentName,
                Rect destinationBounds, SurfaceControl overlay, Rect appBounds) {
                Rect destinationBounds, SurfaceControl overlay, Rect appBounds,
                Rect sourceRectHint) {
            if (overlay != null) {
                overlay.setUnreleasedWarningCallSite("PipController.stopSwipePipToHome");
            }
            executeRemoteCallWithTaskPermission(mController, "stopSwipePipToHome",
                    (controller) -> controller.stopSwipePipToHome(
                            taskId, componentName, destinationBounds, overlay, appBounds));
                            taskId, componentName, destinationBounds, overlay, appBounds,
                            sourceRectHint));
        }

        @Override
+6 −3
Original line number Diff line number Diff line
@@ -285,7 +285,8 @@ public class PipController implements ConfigurationChangeListener,
    }

    private void onSwipePipToHomeAnimationStart(int taskId, ComponentName componentName,
            Rect destinationBounds, SurfaceControl overlay, Rect appBounds) {
            Rect destinationBounds, SurfaceControl overlay, Rect appBounds,
            Rect sourceRectHint) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "onSwipePipToHomeAnimationStart: %s", componentName);
        Bundle extra = new Bundle();
@@ -409,13 +410,15 @@ public class PipController implements ConfigurationChangeListener,

        @Override
        public void stopSwipePipToHome(int taskId, ComponentName componentName,
                Rect destinationBounds, SurfaceControl overlay, Rect appBounds) {
                Rect destinationBounds, SurfaceControl overlay, Rect appBounds,
                Rect sourceRectHint) {
            if (overlay != null) {
                overlay.setUnreleasedWarningCallSite("PipController.stopSwipePipToHome");
            }
            executeRemoteCallWithTaskPermission(mController, "stopSwipePipToHome",
                    (controller) -> controller.onSwipePipToHomeAnimationStart(
                            taskId, componentName, destinationBounds, overlay, appBounds));
                            taskId, componentName, destinationBounds, overlay, appBounds,
                            sourceRectHint));
        }

        @Override