summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
author Winson Chung <winsonc@google.com> 2023-05-30 21:47:22 +0000
committer Winson Chung <winsonc@google.com> 2023-05-31 00:15:33 +0000
commit840d2778f84a815b6b2a47acc4af9677bb363fdb (patch)
treeb1811b5b02c864a904bced5c68a1bfc38c40e185 /libs
parented2f66c600d000f50a5dd961475a5b1ca4dd452b (diff)
Move screenshotting of the task earlier prior to the display change
- When canceling, snapshot the pausing tasks when handling the request for the display change transition otherwise the display change may affect the task snapshot data and report properties for the snapshot in the new orientation. Bug: 278189494 Test: Open letterboxed app and rotate while in overview Change-Id: Ifb66f4b187ee7e3635127e8f503e84d2b038345c
Diffstat (limited to 'libs')
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java50
1 files changed, 46 insertions, 4 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java
index c2869592dbb6..e5e06df003c9 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java
@@ -35,6 +35,7 @@ import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.ArrayMap;
+import android.util.Pair;
import android.util.Slog;
import android.view.Display;
import android.view.IRecentsAnimationController;
@@ -135,8 +136,12 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler {
@Override
public WindowContainerTransaction handleRequest(IBinder transition,
TransitionRequestInfo request) {
- // do not directly handle requests. Only entry point should be via startRecentsTransition
- // TODO: Only log an error if the transition is a recents transition
+ if (mControllers.isEmpty()) {
+ // Ignore if there is no running recents transition
+ return null;
+ }
+ final RecentsController controller = mControllers.get(mControllers.size() - 1);
+ controller.handleMidTransitionRequest(request);
return null;
}
@@ -239,6 +244,11 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler {
/** The latest state that the recents animation is operating in. */
private int mState = STATE_NORMAL;
+ // Snapshots taken when a new display change transition is requested, prior to the display
+ // change being applied. This pending set of snapshots will only be applied when cancel is
+ // next called.
+ private Pair<int[], TaskSnapshot[]> mPendingPauseSnapshotsForCancel;
+
RecentsController(IRecentsAnimationRunner listener) {
mInstanceId = System.identityHashCode(this);
mListener = listener;
@@ -290,6 +300,16 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler {
* "replace-with-screenshot" like behavior.
*/
private boolean sendCancelWithSnapshots() {
+ Pair<int[], TaskSnapshot[]> snapshots = mPendingPauseSnapshotsForCancel != null
+ ? mPendingPauseSnapshotsForCancel
+ : getSnapshotsForPausingTasks();
+ return sendCancel(snapshots.first, snapshots.second);
+ }
+
+ /**
+ * Snapshots the pausing tasks and returns the mapping of the taskId -> snapshot.
+ */
+ private Pair<int[], TaskSnapshot[]> getSnapshotsForPausingTasks() {
int[] taskIds = null;
TaskSnapshot[] snapshots = null;
if (mPausingTasks.size() > 0) {
@@ -298,6 +318,9 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler {
try {
for (int i = 0; i < mPausingTasks.size(); ++i) {
TaskState state = mPausingTasks.get(0);
+ ProtoLog.v(ShellProtoLogGroup.WM_SHELL_RECENTS_TRANSITION,
+ "[%d] RecentsController.sendCancel: Snapshotting task=%d",
+ mInstanceId, state.mTaskInfo.taskId);
snapshots[i] = ActivityTaskManager.getService().takeTaskSnapshot(
state.mTaskInfo.taskId, true /* updateCache */);
}
@@ -306,7 +329,7 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler {
snapshots = null;
}
}
- return sendCancel(taskIds, snapshots);
+ return new Pair(taskIds, snapshots);
}
/**
@@ -315,7 +338,7 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler {
private boolean sendCancel(@Nullable int[] taskIds,
@Nullable TaskSnapshot[] taskSnapshots) {
try {
- final String cancelDetails = taskSnapshots != null ? " with snapshots" : "";
+ final String cancelDetails = taskSnapshots != null ? "with snapshots" : "";
ProtoLog.v(ShellProtoLogGroup.WM_SHELL_RECENTS_TRANSITION,
"[%d] RecentsController.cancel: calling onAnimationCanceled %s",
mInstanceId, cancelDetails);
@@ -348,6 +371,7 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler {
mOpeningTasks = null;
mInfo = null;
mTransition = null;
+ mPendingPauseSnapshotsForCancel = null;
mControllers.remove(this);
}
@@ -460,6 +484,22 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler {
return true;
}
+ /**
+ * Updates this controller when a new transition is requested mid-recents transition.
+ */
+ void handleMidTransitionRequest(TransitionRequestInfo request) {
+ if (request.getType() == TRANSIT_CHANGE && request.getDisplayChange() != null) {
+ final TransitionRequestInfo.DisplayChange dispChange = request.getDisplayChange();
+ if (dispChange.getStartRotation() != dispChange.getEndRotation()) {
+ ProtoLog.v(ShellProtoLogGroup.WM_SHELL_RECENTS_TRANSITION,
+ "[%d] RecentsController.prepareForMerge: "
+ + "Snapshot due to requested display change",
+ mInstanceId);
+ mPendingPauseSnapshotsForCancel = getSnapshotsForPausingTasks();
+ }
+ }
+ }
+
@SuppressLint("NewApi")
void merge(TransitionInfo info, SurfaceControl.Transaction t,
Transitions.TransitionFinishCallback finishCallback) {
@@ -526,6 +566,8 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler {
// Finish recents animation if the display is changed, so the default
// transition handler can play the animation such as rotation effect.
if (change.hasFlags(TransitionInfo.FLAG_IS_DISPLAY)) {
+ // This call to cancel will use the screenshots taken preemptively in
+ // handleMidTransitionRequest() prior to the display changing
cancel(mWillFinishToHome, true /* withScreenshots */, "display change");
return;
}