From 832730d33a389cd7f3e566a139a799a6d68c7bf6 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 17 Jun 2022 19:07:29 +0800 Subject: [PATCH] Use top activity for fixed rotation from snapshot starting window Assume T=trampoline activity, M=main activity. When launching T into an existing task which contains the existing M: The task will have Top = T (no window) = 'activity' Bottom = M (has window) = 'topFullscreenActivity' Because the real top launching activity is T, we should use it for checking whether to apply fix rotation. Otherwise fixed rotation will be skipped because M is not the current top activity, which will cause the snapshot starting window to be half cropped. Also make sure the trampoline activity has the same rotation as the snapshot. Because the snapshot starting window will be shown on the trampoline first and then transfer to the existing activity. This relates to commit a95bd4a that enables snapshot starting window to take effect across trampoline activity. Bug: 236200669 Test: Assume A,B are landscape singleTask activities with the same task affinity. A will be finished (clear-task-stack) after starting B. Launch the app and return to home and launch it again. The starting window should not be cropped. Change-Id: I11cea671c0e6b9a58ba28f28ce0f735eb576c55d --- .../java/com/android/server/wm/ActivityRecord.java | 12 ++++++++++-- .../android/server/wm/StartingSurfaceController.java | 5 ++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 5c473d8c67f51..ab936a6954d66 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -2462,8 +2462,16 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A if (!newTask && taskSwitch && processRunning && !activityCreated && task.intent != null && mActivityComponent.equals(task.intent.getComponent())) { final ActivityRecord topAttached = task.getActivity(ActivityRecord::attachedToProcess); - if (topAttached != null && topAttached.isSnapshotCompatible(snapshot)) { - return STARTING_WINDOW_TYPE_SNAPSHOT; + if (topAttached != null) { + if (topAttached.isSnapshotCompatible(snapshot) + // This trampoline must be the same rotation. + && mDisplayContent.getDisplayRotation().rotationForOrientation(mOrientation, + mDisplayContent.getRotation()) == snapshot.getRotation()) { + return STARTING_WINDOW_TYPE_SNAPSHOT; + } + // No usable snapshot. And a splash screen may also be weird because an existing + // activity may be shown right after the trampoline is finished. + return STARTING_WINDOW_TYPE_NONE; } } final boolean isActivityHome = isActivityTypeHome(); diff --git a/services/core/java/com/android/server/wm/StartingSurfaceController.java b/services/core/java/com/android/server/wm/StartingSurfaceController.java index e8445ab8c35e2..f83173bd46c01 100644 --- a/services/core/java/com/android/server/wm/StartingSurfaceController.java +++ b/services/core/java/com/android/server/wm/StartingSurfaceController.java @@ -158,14 +158,13 @@ public class StartingSurfaceController { + topFullscreenActivity); return null; } - if (topFullscreenActivity.getWindowConfiguration().getRotation() - != taskSnapshot.getRotation()) { + if (activity.mDisplayContent.getRotation() != taskSnapshot.getRotation()) { // The snapshot should have been checked by ActivityRecord#isSnapshotCompatible // that the activity will be updated to the same rotation as the snapshot. Since // the transition is not started yet, fixed rotation transform needs to be applied // earlier to make the snapshot show in a rotated container. activity.mDisplayContent.handleTopActivityLaunchingInDifferentOrientation( - topFullscreenActivity, false /* checkOpening */); + activity, false /* checkOpening */); } mService.mAtmService.mTaskOrganizerController.addStartingWindow(task, activity, 0 /* launchTheme */, taskSnapshot);