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

Commit 0de2ae33 authored by Jacqueline Bronger's avatar Jacqueline Bronger Committed by Android (Google) Code Review
Browse files

Merge "Use mobile code for TV Shell Transitions." into udc-dev

parents 93b5d6a3 f928c832
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -157,14 +157,21 @@ public abstract class TvPipModule {
    @WMSingleton
    @Provides
    static PipTransitionController provideTvPipTransition(
            Context context,
            ShellInit shellInit,
            ShellTaskOrganizer shellTaskOrganizer,
            Transitions transitions,
            PipAnimationController pipAnimationController,
            TvPipBoundsState tvPipBoundsState,
            PipDisplayLayoutState pipDisplayLayoutState,
            PipTransitionState pipTransitionState,
            TvPipMenuController pipMenuController,
            TvPipBoundsAlgorithm tvPipBoundsAlgorithm,
            TvPipBoundsState tvPipBoundsState, TvPipMenuController pipMenuController) {
        return new TvPipTransition(shellInit, shellTaskOrganizer, transitions, tvPipBoundsState,
                pipMenuController, tvPipBoundsAlgorithm, pipAnimationController);
            PipAnimationController pipAnimationController,
            PipSurfaceTransactionHelper pipSurfaceTransactionHelper) {
        return new TvPipTransition(context, shellInit, shellTaskOrganizer, transitions,
                tvPipBoundsState, pipDisplayLayoutState, pipTransitionState, pipMenuController,
                tvPipBoundsAlgorithm, pipAnimationController, pipSurfaceTransactionHelper,
                Optional.empty());
    }

    @WMSingleton
+33 −2
Original line number Diff line number Diff line
@@ -433,6 +433,26 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
        }
    }

    /**
     * Override if the PiP should always use a fade-in animation during PiP entry.
     *
     * @return true if the mOneShotAnimationType should always be
     * {@link PipAnimationController#ANIM_TYPE_ALPHA}.
     */
    protected boolean shouldAlwaysFadeIn() {
        return false;
    }

    /**
     * Whether the menu should get attached as early as possible when entering PiP.
     *
     * @return whether the menu should be attached before
     * {@link PipBoundsAlgorithm#getEntryDestinationBounds()} is called.
     */
    protected boolean shouldAttachMenuEarly() {
        return false;
    }

    /**
     * Callback when Launcher starts swipe-pip-to-home operation.
     * @return {@link Rect} for destination bounds.
@@ -727,17 +747,26 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
            return;
        }

        if (shouldAlwaysFadeIn()) {
            mOneShotAnimationType = ANIM_TYPE_ALPHA;
        }

        if (mWaitForFixedRotation) {
            onTaskAppearedWithFixedRotation();
            return;
        }

        if (shouldAttachMenuEarly()) {
            mPipMenuController.attach(mLeash);
        }
        final Rect destinationBounds = mPipBoundsAlgorithm.getEntryDestinationBounds();
        Objects.requireNonNull(destinationBounds, "Missing destination bounds");
        final Rect currentBounds = mTaskInfo.configuration.windowConfiguration.getBounds();

        if (mOneShotAnimationType == ANIM_TYPE_BOUNDS) {
            if (!shouldAttachMenuEarly()) {
                mPipMenuController.attach(mLeash);
            }
            final Rect sourceHintRect = PipBoundsAlgorithm.getValidSourceHintRect(
                    info.pictureInPictureParams, currentBounds);
            scheduleAnimateResizePip(currentBounds, destinationBounds, 0 /* startingAngle */,
@@ -852,7 +881,9 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
            @Nullable SurfaceControl.Transaction boundsChangeTransaction) {
        // PiP menu is attached late in the process here to avoid any artifacts on the leash
        // caused by addShellRoot when in gesture navigation mode.
        if (!shouldAttachMenuEarly()) {
            mPipMenuController.attach(mLeash);
        }
        final WindowContainerTransaction wct = new WindowContainerTransaction();
        wct.setActivityWindowingMode(mToken, WINDOWING_MODE_UNDEFINED);
        wct.setBounds(mToken, destinationBounds);
+16 −1
Original line number Diff line number Diff line
@@ -272,6 +272,8 @@ public class PipTransition extends PipTransitionController {
    public WindowContainerTransaction handleRequest(@NonNull IBinder transition,
            @NonNull TransitionRequestInfo request) {
        if (requestHasPipEnter(request)) {
            ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                    "%s: handle PiP enter request", TAG);
            WindowContainerTransaction wct = new WindowContainerTransaction();
            augmentRequest(transition, request, wct);
            return wct;
@@ -731,6 +733,11 @@ public class PipTransition extends PipTransitionController {

        setBoundsStateForEntry(taskInfo.topActivity, taskInfo.pictureInPictureParams,
                taskInfo.topActivityInfo);

        if (mPipOrganizer.shouldAttachMenuEarly()) {
            mPipMenuController.attach(leash);
        }

        final Rect destinationBounds = mPipBoundsAlgorithm.getEntryDestinationBounds();
        final Rect currentBounds = taskInfo.configuration.windowConfiguration.getBounds();
        int rotationDelta = deltaRotation(startRotation, endRotation);
@@ -745,7 +752,10 @@ public class PipTransition extends PipTransitionController {
        mSurfaceTransactionHelper
                .crop(finishTransaction, leash, destinationBounds)
                .round(finishTransaction, leash, true /* applyCornerRadius */);
        mTransitions.getMainExecutor().executeDelayed(() -> mPipMenuController.attach(leash), 0);
        if (!mPipOrganizer.shouldAttachMenuEarly()) {
            mTransitions.getMainExecutor().executeDelayed(
                    () -> mPipMenuController.attach(leash), 0);
        }

        if (taskInfo.pictureInPictureParams != null
                && taskInfo.pictureInPictureParams.isAutoEnterEnabled()
@@ -785,6 +795,11 @@ public class PipTransition extends PipTransitionController {
            tmpTransform.postRotate(rotationDelta);
            startTransaction.setMatrix(leash, tmpTransform, new float[9]);
        }

        if (mPipOrganizer.shouldAlwaysFadeIn()) {
            mOneShotAnimationType = ANIM_TYPE_ALPHA;
        }

        if (mOneShotAnimationType == ANIM_TYPE_ALPHA) {
            startTransaction.setAlpha(leash, 0f);
        }
+1 −12
Original line number Diff line number Diff line
@@ -446,7 +446,7 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
                    "%s: PiP has already been closed by custom close action", TAG);
            return;
        }
        removeTask(mPinnedTaskId);
        mPipTaskOrganizer.removePip();
        onPipDisappeared();
    }

@@ -673,17 +673,6 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
        }
    }

    private static void removeTask(int taskId) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: removeTask(), taskId=%d", TAG, taskId);
        try {
            ActivityTaskManager.getService().removeTask(taskId);
        } catch (Exception e) {
            ProtoLog.e(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                    "%s: Atm.removeTask() failed, %s", TAG, e);
        }
    }

    private static String stateToName(@State int state) {
        switch (state) {
            case STATE_NO_PIP:
+13 −0
Original line number Diff line number Diff line
@@ -85,4 +85,17 @@ public class TvPipTaskOrganizer extends PipTaskOrganizer {
            mPipParamsChangedForwarder.notifySubtitleChanged(params.getSubtitle());
        }
    }

    /**
     * Override for TV since the menu bounds affect the PiP location. Additionally, we want to
     * ensure that menu is shown immediately since it should always be visible on TV as it creates
     * a border with rounded corners around the PiP.
     */
    protected boolean shouldAttachMenuEarly() {
        return true;
    }

    protected boolean shouldAlwaysFadeIn() {
        return true;
    }
}
Loading