Merge "PiP Transition: Support auto-enter PIP" into sc-v2-dev am: 26ab789b77

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14950700

Change-Id: I76bf8a5b6eb05523d7e1c365e8fb7de1f9d2025b
This commit is contained in:
Ben Lin
2021-07-13 17:06:44 +00:00
committed by Automerger Merge Worker
6 changed files with 77 additions and 18 deletions

View File

@@ -614,6 +614,12 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
} }
private void onEndOfSwipePipToHomeTransition() { private void onEndOfSwipePipToHomeTransition() {
if (Transitions.ENABLE_SHELL_TRANSITIONS) {
mInSwipePipToHomeTransition = false;
mSwipePipToHomeOverlay = null;
return;
}
final Rect destinationBounds = mPipBoundsState.getBounds(); final Rect destinationBounds = mPipBoundsState.getBounds();
final SurfaceControl swipeToHomeOverlay = mSwipePipToHomeOverlay; final SurfaceControl swipeToHomeOverlay = mSwipePipToHomeOverlay;
final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction(); final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();

View File

@@ -32,6 +32,7 @@ import static com.android.wm.shell.transition.Transitions.TRANSIT_REMOVE_PIP;
import android.app.TaskInfo; import android.app.TaskInfo;
import android.content.Context; import android.content.Context;
import android.graphics.Matrix;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.IBinder; import android.os.IBinder;
import android.view.Surface; import android.view.Surface;
@@ -214,6 +215,25 @@ public class PipTransition extends PipTransitionController {
final Rect currentBounds = taskInfo.configuration.windowConfiguration.getBounds(); final Rect currentBounds = taskInfo.configuration.windowConfiguration.getBounds();
PipAnimationController.PipTransitionAnimator animator; PipAnimationController.PipTransitionAnimator animator;
finishTransaction.setPosition(leash, destinationBounds.left, destinationBounds.top); finishTransaction.setPosition(leash, destinationBounds.left, destinationBounds.top);
if (taskInfo.pictureInPictureParams != null
&& taskInfo.pictureInPictureParams.isAutoEnterEnabled()) {
mOneShotAnimationType = ANIM_TYPE_BOUNDS;
// 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);
SurfaceControl.Transaction tx = new SurfaceControl.Transaction();
tx.setMatrix(leash, Matrix.IDENTITY_MATRIX, new float[9])
.setPosition(leash, destinationBounds.left, destinationBounds.top)
.setWindowCrop(leash, destinationBounds.width(), destinationBounds.height());
startTransaction.merge(tx);
startTransaction.apply();
mPipBoundsState.setBounds(destinationBounds);
onFinishResize(taskInfo, destinationBounds, TRANSITION_DIRECTION_TO_PIP, tx);
sendOnPipTransitionFinished(TRANSITION_DIRECTION_TO_PIP);
mFinishCallback = null;
return true;
}
if (mOneShotAnimationType == ANIM_TYPE_BOUNDS) { if (mOneShotAnimationType == ANIM_TYPE_BOUNDS) {
final Rect sourceHintRect = final Rect sourceHintRect =
PipBoundsAlgorithm.getValidSourceHintRect( PipBoundsAlgorithm.getValidSourceHintRect(

View File

@@ -27,6 +27,7 @@ import static android.window.TransitionFilter.CONTAINER_ORDER_TOP;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.ActivityTaskManager; import android.app.ActivityTaskManager;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.IBinder; import android.os.IBinder;
@@ -122,15 +123,20 @@ public class RemoteTransitionCompat implements Parcelable {
// This transition is for opening recents, so recents is on-top. We want to draw // This transition is for opening recents, so recents is on-top. We want to draw
// the current going-away task on top of recents, though, so move it to front // the current going-away task on top of recents, though, so move it to front
WindowContainerToken pausingTask = null; WindowContainerToken pausingTask = null;
SurfaceControl pausingLeash = null; WindowContainerToken pipTask = null;
for (int i = info.getChanges().size() - 1; i >= 0; --i) { for (int i = info.getChanges().size() - 1; i >= 0; --i) {
final TransitionInfo.Change change = info.getChanges().get(i); final TransitionInfo.Change change = info.getChanges().get(i);
if (change.getMode() == TRANSIT_CLOSE || change.getMode() == TRANSIT_TO_BACK) { if (change.getMode() == TRANSIT_CLOSE || change.getMode() == TRANSIT_TO_BACK) {
t.setLayer(leashMap.get(change.getLeash()), t.setLayer(leashMap.get(change.getLeash()),
info.getChanges().size() * 3 - i); info.getChanges().size() * 3 - i);
if (change.getTaskInfo() != null) { final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo();
if (taskInfo != null) {
pausingTask = change.getTaskInfo().token; pausingTask = change.getTaskInfo().token;
} }
if (taskInfo.pictureInPictureParams != null
&& taskInfo.pictureInPictureParams.isAutoEnterEnabled()) {
pipTask = change.getTaskInfo().token;
}
} }
} }
// Also make all the wallpapers opaque since we want the visible from the start // Also make all the wallpapers opaque since we want the visible from the start
@@ -138,7 +144,7 @@ public class RemoteTransitionCompat implements Parcelable {
t.setAlpha(wallpapers[i].leash.mSurfaceControl, 1); t.setAlpha(wallpapers[i].leash.mSurfaceControl, 1);
} }
t.apply(); t.apply();
mRecentsSession.setup(controller, info, finishedCallback, pausingTask, mRecentsSession.setup(controller, info, finishedCallback, pausingTask, pipTask,
leashMap, mToken); leashMap, mToken);
recents.onAnimationStart(mRecentsSession, apps, wallpapers, new Rect(0, 0, 0, 0), recents.onAnimationStart(mRecentsSession, apps, wallpapers, new Rect(0, 0, 0, 0),
new Rect()); new Rect());
@@ -183,14 +189,17 @@ public class RemoteTransitionCompat implements Parcelable {
private RecentsAnimationControllerCompat mWrapped = null; private RecentsAnimationControllerCompat mWrapped = null;
private IRemoteTransitionFinishedCallback mFinishCB = null; private IRemoteTransitionFinishedCallback mFinishCB = null;
private WindowContainerToken mPausingTask = null; private WindowContainerToken mPausingTask = null;
private WindowContainerToken mPipTask = null;
private TransitionInfo mInfo = null; private TransitionInfo mInfo = null;
private SurfaceControl mOpeningLeash = null; private SurfaceControl mOpeningLeash = null;
private ArrayMap<SurfaceControl, SurfaceControl> mLeashMap = null; private ArrayMap<SurfaceControl, SurfaceControl> mLeashMap = null;
private PictureInPictureSurfaceTransaction mPipTransaction = null;
private IBinder mTransition = null; private IBinder mTransition = null;
void setup(RecentsAnimationControllerCompat wrapped, TransitionInfo info, void setup(RecentsAnimationControllerCompat wrapped, TransitionInfo info,
IRemoteTransitionFinishedCallback finishCB, WindowContainerToken pausingTask, IRemoteTransitionFinishedCallback finishCB, WindowContainerToken pausingTask,
ArrayMap<SurfaceControl, SurfaceControl> leashMap, IBinder transition) { WindowContainerToken pipTask, ArrayMap<SurfaceControl, SurfaceControl> leashMap,
IBinder transition) {
if (mInfo != null) { if (mInfo != null) {
throw new IllegalStateException("Trying to run a new recents animation while" throw new IllegalStateException("Trying to run a new recents animation while"
+ " recents is already active."); + " recents is already active.");
@@ -199,6 +208,7 @@ public class RemoteTransitionCompat implements Parcelable {
mInfo = info; mInfo = info;
mFinishCB = finishCB; mFinishCB = finishCB;
mPausingTask = pausingTask; mPausingTask = pausingTask;
mPipTask = pipTask;
mLeashMap = leashMap; mLeashMap = leashMap;
mTransition = transition; mTransition = transition;
} }
@@ -257,6 +267,7 @@ public class RemoteTransitionCompat implements Parcelable {
@Override public void setFinishTaskTransaction(int taskId, @Override public void setFinishTaskTransaction(int taskId,
PictureInPictureSurfaceTransaction finishTransaction, SurfaceControl overlay) { PictureInPictureSurfaceTransaction finishTransaction, SurfaceControl overlay) {
mPipTransaction = finishTransaction;
if (mWrapped != null) { if (mWrapped != null) {
mWrapped.setFinishTaskTransaction(taskId, finishTransaction, overlay); mWrapped.setFinishTaskTransaction(taskId, finishTransaction, overlay);
} }
@@ -288,7 +299,18 @@ public class RemoteTransitionCompat implements Parcelable {
t.setAlpha(mOpeningLeash, 1.f); t.setAlpha(mOpeningLeash, 1.f);
t.apply(); t.apply();
} }
mFinishCB.onTransitionFinished(null /* wct */, null /* sct */); if (mPipTask != null && mPipTransaction != null) {
final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
t.show(mInfo.getChange(mPipTask).getLeash());
PictureInPictureSurfaceTransaction.apply(mPipTransaction,
mInfo.getChange(mPipTask).getLeash(), t);
mPipTask = null;
mPipTransaction = null;
mFinishCB.onTransitionFinished(null /* wct */, t);
} else {
mFinishCB.onTransitionFinished(null /* wct */, null /* sct */);
}
} }
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e("RemoteTransitionCompat", "Failed to call animation finish callback", e); Log.e("RemoteTransitionCompat", "Failed to call animation finish callback", e);

View File

@@ -5274,7 +5274,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
// returns. Just need to confirm this reasoning makes sense. // returns. Just need to confirm this reasoning makes sense.
final boolean deferHidingClient = canEnterPictureInPicture final boolean deferHidingClient = canEnterPictureInPicture
&& !isState(STARTED, STOPPING, STOPPED, PAUSED); && !isState(STARTED, STOPPING, STOPPED, PAUSED);
if (deferHidingClient && pictureInPictureArgs.isAutoEnterEnabled()) { if (!mAtmService.getTransitionController().isShellTransitionsEnabled()
&& deferHidingClient && pictureInPictureArgs.isAutoEnterEnabled()) {
// Go ahead and just put the activity in pip if it supports auto-pip. // Go ahead and just put the activity in pip if it supports auto-pip.
mAtmService.enterPictureInPictureMode(this, pictureInPictureArgs); mAtmService.enterPictureInPictureMode(this, pictureInPictureArgs);
return; return;

View File

@@ -3365,9 +3365,9 @@ class Task extends TaskFragment {
private @Nullable PictureInPictureParams getPictureInPictureParams(Task top) { private @Nullable PictureInPictureParams getPictureInPictureParams(Task top) {
if (top == null) return null; if (top == null) return null;
final ActivityRecord topVisibleActivity = top.getTopVisibleActivity(); final ActivityRecord topMostActivity = top.getTopMostActivity();
return (topVisibleActivity == null || topVisibleActivity.pictureInPictureArgs.empty()) return (topMostActivity == null || topMostActivity.pictureInPictureArgs.empty())
? null : new PictureInPictureParams(topVisibleActivity.pictureInPictureArgs); ? null : new PictureInPictureParams(topMostActivity.pictureInPictureArgs);
} }
/** /**

View File

@@ -305,17 +305,27 @@ class Transition extends Binder implements BLASTSyncEngine.TransactionReadyListe
final ActivityRecord ar = mParticipants.valueAt(i).asActivityRecord(); final ActivityRecord ar = mParticipants.valueAt(i).asActivityRecord();
if (ar != null) { if (ar != null) {
if (!ar.isVisibleRequested()) { if (!ar.isVisibleRequested()) {
// If activity is capable of entering PiP, give it a chance to enter it now. boolean commitVisibility = true;
if (ar.getDeferHidingClient() && ar.getTask() != null) { if (ar.getDeferHidingClient() && ar.getTask() != null) {
mController.mAtm.mTaskSupervisor.mUserLeaving = true; if (ar.pictureInPictureArgs != null
ar.getTaskFragment().startPausing(false /* uiSleeping */, && ar.pictureInPictureArgs.isAutoEnterEnabled()) {
null /* resuming */, "finishTransition"); mController.mAtm.enterPictureInPictureMode(ar, ar.pictureInPictureArgs);
mController.mAtm.mTaskSupervisor.mUserLeaving = false; // Avoid commit visibility to false here, or else we will get a sudden
// "flash" / surface going invisible for a split second.
commitVisibility = false;
} else {
mController.mAtm.mTaskSupervisor.mUserLeaving = true;
ar.getTaskFragment().startPausing(false /* uiSleeping */,
null /* resuming */, "finishTransition");
mController.mAtm.mTaskSupervisor.mUserLeaving = false;
}
}
if (commitVisibility) {
ProtoLog.v(ProtoLogGroup.WM_DEBUG_WINDOW_TRANSITIONS,
" Commit activity becoming invisible: %s", ar);
ar.commitVisibility(false /* visible */, false /* performLayout */);
activitiesWentInvisible = true;
} }
ProtoLog.v(ProtoLogGroup.WM_DEBUG_WINDOW_TRANSITIONS,
" Commit activity becoming invisible: %s", ar);
ar.commitVisibility(false /* visible */, false /* performLayout */);
activitiesWentInvisible = true;
} }
if (mChanges.get(ar).mVisible != ar.isVisibleRequested()) { if (mChanges.get(ar).mVisible != ar.isVisibleRequested()) {
// Legacy dispatch relies on this (for now). // Legacy dispatch relies on this (for now).