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

Commit a68b3eb1 authored by Chilun's avatar Chilun
Browse files

Do not use obsoleted snapshot as staring window

We will use splash screen as starting window if the activity is in
finishing state. Now we will not use the activity with finishing
state to show the starting window, so we check the top activity
component to avoid using obsoleted snapshot as starting window.

Bug: 180893837
Test: atest ActivityStarterTests ActivityRecordTests
Change-Id: I27fb40d6d4e8808caf803ef78c39050258eab1a2
parent ac40826e
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
@@ -2154,6 +2154,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,