Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a944a2c1 authored by Wei Sheng Shih's avatar Wei Sheng Shih Committed by Android (Google) Code Review
Browse files

Merge "Do not show task snapshot window if task bounds has changed." into tm-dev

parents 44b000a2 87640739
Loading
Loading
Loading
Loading
+1 −30
Original line number Diff line number Diff line
@@ -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;
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -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.
+29 −0
Original line number Diff line number Diff line
@@ -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();
+11 −3
Original line number Diff line number Diff line
@@ -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();