diff options
| author | 2022-04-19 02:07:46 +0000 | |
|---|---|---|
| committer | 2022-04-19 02:07:46 +0000 | |
| commit | a944a2c1add58a28dcfa2dceddffcd04872a7096 (patch) | |
| tree | aff5f452d0b95cea8fb58a48d4a0f6611735bb13 | |
| parent | 44b000a2257ddbb0e0041143e5e48ea8a4f7984b (diff) | |
| parent | 876407397679914fc593847f157b14f50d12abdf (diff) | |
Merge "Do not show task snapshot window if task bounds has changed." into tm-dev
4 files changed, 48 insertions, 33 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/phone/PhoneStartingWindowTypeAlgorithm.java b/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/phone/PhoneStartingWindowTypeAlgorithm.java index 51722c46a7ae..bb43d7c1a090 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/phone/PhoneStartingWindowTypeAlgorithm.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/phone/PhoneStartingWindowTypeAlgorithm.java @@ -32,7 +32,6 @@ import static android.window.StartingWindowInfo.TYPE_PARAMETER_TASK_SWITCH; import static android.window.StartingWindowInfo.TYPE_PARAMETER_USE_SOLID_COLOR_SPLASH_SCREEN; import android.window.StartingWindowInfo; -import android.window.TaskSnapshot; import com.android.internal.protolog.common.ProtoLog; import com.android.wm.shell.protolog.ShellProtoLogGroup; @@ -80,7 +79,7 @@ public class PhoneStartingWindowTypeAlgorithm implements StartingWindowTypeAlgor if (taskSwitch) { if (allowTaskSnapshot) { - if (isSnapshotCompatible(windowInfo)) { + if (windowInfo.taskSnapshot != null) { return STARTING_WINDOW_TYPE_SNAPSHOT; } if (!topIsHome) { @@ -102,32 +101,4 @@ public class PhoneStartingWindowTypeAlgorithm implements StartingWindowTypeAlgor ? STARTING_WINDOW_TYPE_LEGACY_SPLASH_SCREEN : STARTING_WINDOW_TYPE_SPLASH_SCREEN; } - - /** - * Returns {@code true} if the task snapshot is compatible with this activity (at least the - * rotation must be the same). - */ - private boolean isSnapshotCompatible(StartingWindowInfo windowInfo) { - final TaskSnapshot snapshot = windowInfo.taskSnapshot; - if (snapshot == null) { - ProtoLog.v(ShellProtoLogGroup.WM_SHELL_STARTING_WINDOW, - "isSnapshotCompatible no snapshot, taskId=%d", - windowInfo.taskInfo.taskId); - return false; - } - if (!snapshot.getTopActivityComponent().equals(windowInfo.taskInfo.topActivity)) { - ProtoLog.v(ShellProtoLogGroup.WM_SHELL_STARTING_WINDOW, - "isSnapshotCompatible obsoleted snapshot for %s", - windowInfo.taskInfo.topActivity); - return false; - } - - final int taskRotation = windowInfo.taskInfo.configuration - .windowConfiguration.getRotation(); - final int snapshotRotation = snapshot.getRotation(); - ProtoLog.v(ShellProtoLogGroup.WM_SHELL_STARTING_WINDOW, - "isSnapshotCompatible taskRotation=%d, snapshotRotation=%d", - taskRotation, snapshotRotation); - return taskRotation == snapshotRotation; - } } diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index dc4e1174edf3..1956cee11f90 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -2452,6 +2452,13 @@ 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 targetRotation = rotation != ROTATION_UNDEFINED // The display may rotate according to the orientation of this activity. 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 31bc2818978d..55147f3e59f6 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -1850,9 +1850,12 @@ public class ActivityRecordTests extends WindowTestsBase { @Test public void testIsSnapshotCompatible() { final ActivityRecord activity = createActivityWithTask(); + final Task task = activity.getTask(); + final Rect taskBounds = task.getBounds(); final TaskSnapshot snapshot = new TaskSnapshotPersisterTestBase.TaskSnapshotBuilder() .setTopActivityComponent(activity.mActivityComponent) .setRotation(activity.getWindowConfiguration().getRotation()) + .setTaskSize(taskBounds.width(), taskBounds.height()) .build(); assertTrue(activity.isSnapshotCompatible(snapshot)); @@ -1872,8 +1875,11 @@ public class ActivityRecordTests extends WindowTestsBase { .setTask(activity.getTask()) .setOnTop(true) .build(); + final Task task = secondActivity.getTask(); + final Rect taskBounds = task.getBounds(); final TaskSnapshot snapshot = new TaskSnapshotPersisterTestBase.TaskSnapshotBuilder() .setTopActivityComponent(secondActivity.mActivityComponent) + .setTaskSize(taskBounds.width(), taskBounds.height()) .build(); assertTrue(secondActivity.isSnapshotCompatible(snapshot)); @@ -1882,6 +1888,29 @@ public class ActivityRecordTests extends WindowTestsBase { assertFalse(activity.isSnapshotCompatible(snapshot)); } + /** + * Test that the snapshot should be obsoleted if the task size changed. + */ + @Test + public void testIsSnapshotCompatibleTaskSizeChanged() { + final ActivityRecord activity = createActivityWithTask(); + final Task task = activity.getTask(); + final Rect taskBounds = task.getBounds(); + final TaskSnapshot snapshot = new TaskSnapshotPersisterTestBase.TaskSnapshotBuilder() + .setTopActivityComponent(activity.mActivityComponent) + .setRotation(activity.getWindowConfiguration().getRotation()) + .setTaskSize(taskBounds.width(), taskBounds.height()) + .build(); + + assertTrue(activity.isSnapshotCompatible(snapshot)); + + taskBounds.right = taskBounds.width() * 2; + task.getWindowConfiguration().setBounds(taskBounds); + activity.getWindowConfiguration().setBounds(taskBounds); + + assertFalse(activity.isSnapshotCompatible(snapshot)); + } + @Test public void testFixedRotationSnapshotStartingWindow() { final ActivityRecord activity = createActivityWithTask(); diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java b/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java index f71ed2f08a22..677359f5695c 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java @@ -154,6 +154,8 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase { private int mWindowingMode = WINDOWING_MODE_FULLSCREEN; private int mSystemUiVisibility = 0; private int mRotation = Surface.ROTATION_0; + private int mWidth = SNAPSHOT_WIDTH; + private int mHeight = SNAPSHOT_HEIGHT; private ComponentName mTopActivityComponent = new ComponentName("", ""); TaskSnapshotBuilder() { @@ -194,12 +196,18 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase { return this; } + TaskSnapshotBuilder setTaskSize(int width, int height) { + mWidth = width; + mHeight = height; + return this; + } + TaskSnapshot build() { // To satisfy existing tests, ensure the graphics buffer is always 100x100, and // compute the ize of the task according to mScaleFraction. - Point taskSize = new Point((int) (SNAPSHOT_WIDTH / mScaleFraction), - (int) (SNAPSHOT_HEIGHT / mScaleFraction)); - final GraphicBuffer buffer = GraphicBuffer.create(SNAPSHOT_WIDTH, SNAPSHOT_HEIGHT, + Point taskSize = new Point((int) (mWidth / mScaleFraction), + (int) (mHeight / mScaleFraction)); + final GraphicBuffer buffer = GraphicBuffer.create(mWidth, mHeight, PixelFormat.RGBA_8888, USAGE_HW_TEXTURE | USAGE_SW_READ_RARELY | USAGE_SW_READ_RARELY); Canvas c = buffer.lockCanvas(); |