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

Commit df8f1012 authored by Chilun Huang's avatar Chilun Huang Committed by Android (Google) Code Review
Browse files

Merge "Do not use obsoleted snapshot as staring window" into sc-dev

parents 69a14b8a a68b3eb1
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -150,6 +150,13 @@ public class StartingWindowController {
                }
                return false;
            }
            if (!snapshot.getTopActivityComponent().equals(windowInfo.taskInfo.topActivity)) {
                if (DEBUG_SPLASH_SCREEN || DEBUG_TASK_SNAPSHOT) {
                    Slog.d(TAG, "isSnapshotCompatible obsoleted snapshot "
                            + windowInfo.taskInfo.topActivity);
                }
                return false;
            }

            final int taskRotation = windowInfo.taskInfo.configuration
                    .windowConfiguration.getRotation();
+4 −0
Original line number Diff line number Diff line
@@ -2114,6 +2114,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        if (snapshot == null) {
            return false;
        }
        if (!snapshot.getTopActivityComponent().equals(mActivityComponent)) {
            // Obsoleted snapshot.
            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.
+21 −0
Original line number Diff line number Diff line
@@ -1687,6 +1687,7 @@ public class ActivityRecordTests extends WindowTestsBase {
    public void testIsSnapshotCompatible() {
        final ActivityRecord activity = createActivityWithTask();
        final TaskSnapshot snapshot = new TaskSnapshotPersisterTestBase.TaskSnapshotBuilder()
                .setTopActivityComponent(activity.mActivityComponent)
                .setRotation(activity.getWindowConfiguration().getRotation())
                .build();

@@ -1697,6 +1698,26 @@ public class ActivityRecordTests extends WindowTestsBase {
        assertFalse(activity.isSnapshotCompatible(snapshot));
    }

    /**
     * Test that the snapshot should be obsoleted if the top activity changed.
     */
    @Test
    public void testIsSnapshotCompatibleTopActivityChanged() {
        final ActivityRecord activity = createActivityWithTask();
        final ActivityRecord secondActivity = new ActivityBuilder(mAtm)
                .setTask(activity.getTask())
                .setOnTop(true)
                .build();
        final TaskSnapshot snapshot = new TaskSnapshotPersisterTestBase.TaskSnapshotBuilder()
                .setTopActivityComponent(secondActivity.mActivityComponent)
                .build();

        assertTrue(secondActivity.isSnapshotCompatible(snapshot));

        // Emulate the top activity changed.
        assertFalse(activity.isSnapshotCompatible(snapshot));
    }

    @Test
    public void testFixedRotationSnapshotStartingWindow() {
        final ActivityRecord activity = createActivityWithTask();
+8 −2
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import android.window.TaskSnapshot;
import android.content.ComponentName;
import android.content.ContextWrapper;
import android.content.res.Resources;
@@ -42,6 +41,7 @@ import android.graphics.Rect;
import android.hardware.HardwareBuffer;
import android.os.UserManager;
import android.view.Surface;
import android.window.TaskSnapshot;

import com.android.server.LocalServices;
import com.android.server.pm.UserManagerInternal;
@@ -154,10 +154,16 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
        private int mWindowingMode = WINDOWING_MODE_FULLSCREEN;
        private int mSystemUiVisibility = 0;
        private int mRotation = Surface.ROTATION_0;
        private ComponentName mTopActivityComponent = new ComponentName("", "");

        TaskSnapshotBuilder() {
        }

        TaskSnapshotBuilder setTopActivityComponent(ComponentName topActivityComponent) {
            mTopActivityComponent = topActivityComponent;
            return this;
        }

        TaskSnapshotBuilder setScaleFraction(float scale) {
            mScaleFraction = scale;
            return this;
@@ -199,7 +205,7 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
            Canvas c = buffer.lockCanvas();
            c.drawColor(Color.RED);
            buffer.unlockCanvasAndPost(c);
            return new TaskSnapshot(MOCK_SNAPSHOT_ID, new ComponentName("", ""),
            return new TaskSnapshot(MOCK_SNAPSHOT_ID, mTopActivityComponent,
                    HardwareBuffer.createFromGraphicBuffer(buffer),
                    ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT,
                    mRotation, taskSize, TEST_INSETS,