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

Commit 51f099fa authored by Merissa Mitchell's avatar Merissa Mitchell
Browse files

[PiP2 on Desktop] Enter PiP with bounds change animation.

Recall: http://recall/clips/d4b0542f-424a-436a-8f17-a1eeb0d9e91b

This CL allows enter PiP on Desktop mode with bounds change animation.
If the task is minimizing to PiP, a PiP transition is started instead of
a minimize transition. If the PiP transition is aborted down the line, a
minimize transition will then be started.

Bug: 378745750
Bug: 377582265
Test: atest DesktopTasksControllerTest
Flag: com.android.window.flags.enable_desktop_windowing_pip

Change-Id: Icf309eaa4aa5092839b221ee2774eb309f112202
parent 72061cd0
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -77,6 +77,10 @@ class DesktopMixedTransitionHandler(
    override fun startMinimizedModeTransition(wct: WindowContainerTransaction?): IBinder =
        freeformTaskTransitionHandler.startMinimizedModeTransition(wct)

    /** Delegates starting PiP transition to [FreeformTaskTransitionHandler]. */
    override fun startPipTransition(wct: WindowContainerTransaction?): IBinder =
        freeformTaskTransitionHandler.startPipTransition(wct)

    /** Starts close transition and handles or delegates desktop task close animation. */
    override fun startRemoveTransition(wct: WindowContainerTransaction?): IBinder {
        if (!DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_EXIT_TRANSITIONS.isTrue) {
+37 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import android.view.WindowManager.TRANSIT_CHANGE
import android.view.WindowManager.TRANSIT_CLOSE
import android.view.WindowManager.TRANSIT_NONE
import android.view.WindowManager.TRANSIT_OPEN
import android.view.WindowManager.TRANSIT_PIP
import android.view.WindowManager.TRANSIT_TO_FRONT
import android.widget.Toast
import android.window.DesktopModeFlags
@@ -223,6 +224,7 @@ class DesktopTasksController(
    // Launch cookie used to identify a drag and drop transition to fullscreen after it has begun.
    // Used to prevent handleRequest from moving the new fullscreen task to freeform.
    private var dragAndDropFullscreenCookie: Binder? = null
    private var pendingPipTransitionAndTask: Pair<IBinder, Int>? = null

    init {
        desktopMode = DesktopModeImpl()
@@ -536,6 +538,26 @@ class DesktopTasksController(
    }

    fun minimizeTask(taskInfo: RunningTaskInfo) {
        val wct = WindowContainerTransaction()

        val isMinimizingToPip = taskInfo.pictureInPictureParams?.isAutoEnterEnabled() ?: false
        // If task is going to PiP, start a PiP transition instead of a minimize transition
        if (isMinimizingToPip) {
            val requestInfo = TransitionRequestInfo(
                TRANSIT_PIP, /* triggerTask= */ null, taskInfo, /* remoteTransition= */ null,
                /* displayChange= */ null, /* flags= */ 0
            )
            val requestRes = transitions.dispatchRequest(Binder(), requestInfo, /* skip= */ null)
            wct.merge(requestRes.second, true)
            pendingPipTransitionAndTask =
                freeformTaskTransitionStarter.startPipTransition(wct) to taskInfo.taskId
            return
        }

        minimizeTaskInner(taskInfo)
    }

    private fun minimizeTaskInner(taskInfo: RunningTaskInfo) {
        val taskId = taskInfo.taskId
        val displayId = taskInfo.displayId
        val wct = WindowContainerTransaction()
@@ -1298,6 +1320,21 @@ class DesktopTasksController(
        return false
    }

    override fun onTransitionConsumed(
        transition: IBinder,
        aborted: Boolean,
        finishT: Transaction?
    ) {
        pendingPipTransitionAndTask?.let { (pipTransition, taskId) ->
            if (transition == pipTransition) {
                if (aborted) {
                    shellTaskOrganizer.getRunningTaskInfo(taskId)?.let { minimizeTaskInner(it) }
                }
                pendingPipTransitionAndTask = null
            }
        }
    }

    override fun handleRequest(
        transition: IBinder,
        request: TransitionRequestInfo
+7 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.wm.shell.freeform;

import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.view.WindowManager.TRANSIT_PIP;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -99,6 +100,12 @@ public class FreeformTaskTransitionHandler
        return token;
    }

    @Override
    public IBinder startPipTransition(WindowContainerTransaction wct) {
        final IBinder token = mTransitions.startTransition(TRANSIT_PIP, wct, null);
        mPendingTransitionTokens.add(token);
        return token;
    }

    @Override
    public IBinder startRemoveTransition(WindowContainerTransaction wct) {
+9 −0
Original line number Diff line number Diff line
@@ -51,4 +51,13 @@ public interface FreeformTaskTransitionStarter {
     * @return the started transition
     */
    IBinder startRemoveTransition(WindowContainerTransaction wct);

    /**
     * Starts PiP transition
     *
     * @param wct the {@link WindowContainerTransaction} that launches the PiP
     *
     * @return the started transition
     */
    IBinder startPipTransition(WindowContainerTransaction wct);
}
 No newline at end of file
+5 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.window.WindowContainerTransaction;
import androidx.annotation.Nullable;

import com.android.internal.util.Preconditions;
import com.android.window.flags.Flags;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.common.pip.PipBoundsAlgorithm;
import com.android.wm.shell.common.pip.PipBoundsState;
@@ -713,6 +714,10 @@ public class PipTransition extends PipTransitionController implements
                    && getFixedRotationDelta(info, pipTaskChange) == ROTATION_90) {
                adjustedSourceRectHint.offset(cutoutInsets.left, cutoutInsets.top);
            }
            if (Flags.enableDesktopWindowingPip()) {
                adjustedSourceRectHint.offset(-pipActivityChange.getStartAbsBounds().left,
                        -pipActivityChange.getStartAbsBounds().top);
            }
        } else {
            // For non-valid app provided src-rect-hint, calculate one to crop into during
            // app icon overlay animation.
Loading