Loading libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/phone/PhoneStartingWindowTypeAlgorithm.java +1 −30 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading @@ -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; } } services/core/java/com/android/server/wm/ActivityRecord.java +7 −0 Original line number Diff line number Diff line Loading @@ -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. Loading services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +29 −0 Original line number Diff line number Diff line Loading @@ -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)); Loading @@ -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)); Loading @@ -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(); Loading services/tests/wmtests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java +11 −3 Original line number Diff line number Diff line Loading @@ -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() { Loading Loading @@ -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(); Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/phone/PhoneStartingWindowTypeAlgorithm.java +1 −30 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading @@ -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; } }
services/core/java/com/android/server/wm/ActivityRecord.java +7 −0 Original line number Diff line number Diff line Loading @@ -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. Loading
services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +29 −0 Original line number Diff line number Diff line Loading @@ -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)); Loading @@ -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)); Loading @@ -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(); Loading
services/tests/wmtests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java +11 −3 Original line number Diff line number Diff line Loading @@ -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() { Loading Loading @@ -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(); Loading