From d89a58046c606c67ae3128d6388e40020e0aa2ca Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Wed, 20 Apr 2022 18:39:53 +0800 Subject: [PATCH] Consider requested orientation for snapshot compatible For example, the display is portrait so the task is also portrait. But the activity in the task requested landscape which will make the display update to landscape later. Then if the snapshot was taken in landscape, the snapshot should be compatible because the activity will be pre-rotated with fixed rotation. Bug: 216079545 Test: ActivityRecordTests#testIsSnapshotCompatibleTaskSizeChanged Test: Swipe quickstep to an existing activity with different orientation. There should not be splash screen window. Change-Id: Ic87ead99c918de19438f88472f01541208469a36 --- .../com/android/server/wm/ActivityRecord.java | 27 ++++++++++++------- .../server/wm/ActivityRecordTests.java | 19 +++++++++++-- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 1956cee11f900..e8094fbe5c692 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -2452,20 +2452,29 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // Obsoleted snapshot. return false; } - final Rect taskBounds = task.getBounds(); - final Point taskSize = snapshot.getTaskSize(); - // Task size has changed? e.g. foldable device. - if (Math.abs(((float) taskSize.x / Math.max(taskSize.y, 1)) - - ((float) taskBounds.width() / Math.max(taskBounds.height(), 1))) > 0.01f) { - return false; - } final int rotation = mDisplayContent.rotationForActivityInDifferentOrientation(this); + final int currentRotation = task.getWindowConfiguration().getRotation(); final int targetRotation = rotation != ROTATION_UNDEFINED // The display may rotate according to the orientation of this activity. ? rotation // The activity won't change display orientation. - : task.getWindowConfiguration().getRotation(); - return snapshot.getRotation() == targetRotation; + : currentRotation; + if (snapshot.getRotation() != targetRotation) { + return false; + } + final Rect taskBounds = task.getBounds(); + int w = taskBounds.width(); + int h = taskBounds.height(); + final Point taskSize = snapshot.getTaskSize(); + if ((Math.abs(currentRotation - targetRotation) % 2) == 1) { + // Flip the size if the activity will show in 90 degree difference. + final int t = w; + w = h; + h = t; + } + // Task size might be changed with the same rotation such as on a foldable device. + return Math.abs(((float) taskSize.x / Math.max(taskSize.y, 1)) + - ((float) w / Math.max(h, 1))) <= 0.01f; } /** diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java index 55147f3e59f60..d65e27d0f6427 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -1896,10 +1896,13 @@ public class ActivityRecordTests extends WindowTestsBase { final ActivityRecord activity = createActivityWithTask(); final Task task = activity.getTask(); final Rect taskBounds = task.getBounds(); + final int currentRotation = mDisplayContent.getRotation(); + final int w = taskBounds.width(); + final int h = taskBounds.height(); final TaskSnapshot snapshot = new TaskSnapshotPersisterTestBase.TaskSnapshotBuilder() .setTopActivityComponent(activity.mActivityComponent) - .setRotation(activity.getWindowConfiguration().getRotation()) - .setTaskSize(taskBounds.width(), taskBounds.height()) + .setRotation(currentRotation) + .setTaskSize(w, h) .build(); assertTrue(activity.isSnapshotCompatible(snapshot)); @@ -1909,6 +1912,18 @@ public class ActivityRecordTests extends WindowTestsBase { activity.getWindowConfiguration().setBounds(taskBounds); assertFalse(activity.isSnapshotCompatible(snapshot)); + + // Flipped size should be accepted if the activity will show with 90 degree rotation. + final int targetRotation = currentRotation + 1; + doReturn(targetRotation).when(mDisplayContent) + .rotationForActivityInDifferentOrientation(any()); + final TaskSnapshot rotatedSnapshot = new TaskSnapshotPersisterTestBase.TaskSnapshotBuilder() + .setTopActivityComponent(activity.mActivityComponent) + .setRotation(targetRotation) + .setTaskSize(h, w) + .build(); + task.getWindowConfiguration().getBounds().set(0, 0, w, h); + assertTrue(activity.isSnapshotCompatible(rotatedSnapshot)); } @Test