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

Commit 7baaa82e authored by wilsonshih's avatar wilsonshih
Browse files

Fix snapshot window jump due to top window has another cutout mode

That jumping is because the WindowFrame of top fullscreen window isn't
align with app main window. In core there only check app main
window's cutout for layout, so for snapshot starting window, it should
use app's main window's cutout instead of top opaque window.

Another reason there doesn't need to use getTopFullscreenOpaqueWindow
is because core won't ask to create snapshot starting window if the
size/orientation of snapshot isn't align with the window configuration,
so the SnapshotDrawerUtils will not needs to draw background and bars,
since the aspectRatioMismatch should always return false.

Bug: 341020277
Test: manual, create a second window for an activity, verify snapshot
starting window won't jump when hot launch the app from background.

Change-Id: I4c6b0ccacc79730552cbf9b4928b5c842f4feb1e
parent 4e1de135
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -466,17 +466,17 @@ abstract class AbsAppSnapshotController<TYPE extends WindowContainer,
    }

    /**
     * @return The {@link WindowInsetsController.Appearance} flags for the top fullscreen opaque
     * window in the given {@param TYPE}.
     * @return The {@link WindowInsetsController.Appearance} flags for the top main app window in
     * the given {@param TYPE}.
     */
    @WindowInsetsController.Appearance
    private int getAppearance(TYPE source) {
        final ActivityRecord topFullscreenActivity = getTopFullscreenActivity(source);
        final WindowState topFullscreenOpaqueWindow = topFullscreenActivity != null
                ? topFullscreenActivity.getTopFullscreenOpaqueWindow()
        final WindowState topFullscreenWindow = topFullscreenActivity != null
                ? topFullscreenActivity.findMainWindow()
                : null;
        if (topFullscreenOpaqueWindow != null) {
            return topFullscreenOpaqueWindow.mAttrs.insetsFlags.appearance;
        if (topFullscreenWindow != null) {
            return topFullscreenWindow.mAttrs.insetsFlags.appearance;
        }
        return 0;
    }
+0 −14
Original line number Diff line number Diff line
@@ -7658,20 +7658,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
    }
    /**
     * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
     *         true and isn't fully transparent.
     */
    WindowState getTopFullscreenOpaqueWindow() {
        for (int i = mChildren.size() - 1; i >= 0; i--) {
            final WindowState win = mChildren.get(i);
            if (win != null && win.mAttrs.isFullscreen() && !win.isFullyTransparent()) {
                return win;
            }
        }
        return null;
    }
    WindowState findMainWindow() {
        return findMainWindow(true);
    }
+3 −11
Original line number Diff line number Diff line
@@ -140,23 +140,15 @@ public class StartingSurfaceController {
    }

    StartingSurface createTaskSnapshotSurface(ActivityRecord activity, TaskSnapshot taskSnapshot) {
        final WindowState topFullscreenOpaqueWindow;
        final Task task = activity.getTask();
        if (task == null) {
            Slog.w(TAG, "TaskSnapshotSurface.create: Failed to find task for activity="
                    + activity);
            return null;
        }
        final ActivityRecord topFullscreenActivity = task.getTopFullscreenActivity();
        if (topFullscreenActivity == null) {
            Slog.w(TAG, "TaskSnapshotSurface.create: Failed to find top fullscreen for task="
                    + task);
            return null;
        }
        topFullscreenOpaqueWindow = topFullscreenActivity.getTopFullscreenOpaqueWindow();
        if (topFullscreenOpaqueWindow == null) {
            Slog.w(TAG, "TaskSnapshotSurface.create: no opaque window in "
                    + topFullscreenActivity);
        final WindowState mainWindow = activity.findMainWindow(false);
        if (mainWindow == null) {
            Slog.w(TAG, "TaskSnapshotSurface.create: no main window in " + activity);
            return null;
        }
        if (activity.mDisplayContent.getRotation() != taskSnapshot.getRotation()) {
+4 −5
Original line number Diff line number Diff line
@@ -3626,12 +3626,11 @@ class Task extends TaskFragment {
        info.taskInfo.configuration.setTo(activity.getConfiguration());
        final ActivityRecord topFullscreenActivity = getTopFullscreenActivity();
        if (topFullscreenActivity != null) {
            final WindowState topFullscreenOpaqueWindow =
                    topFullscreenActivity.getTopFullscreenOpaqueWindow();
            if (topFullscreenOpaqueWindow != null) {
            final WindowState mainWindow = topFullscreenActivity.findMainWindow(false);
            if (mainWindow != null) {
                info.topOpaqueWindowInsetsState =
                        topFullscreenOpaqueWindow.getInsetsStateWithVisibilityOverride();
                info.topOpaqueWindowLayoutParams = topFullscreenOpaqueWindow.getAttrs();
                        mainWindow.getInsetsStateWithVisibilityOverride();
                info.topOpaqueWindowLayoutParams = mainWindow.getAttrs();
            }
        }
        return info;
+1 −20
Original line number Diff line number Diff line
@@ -2057,7 +2057,7 @@ public class ActivityRecordTests extends WindowTestsBase {
        final ActivityRecord activity = createActivityWithTask();
        // TaskSnapshotSurface requires a fullscreen opaque window.
        final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
                TYPE_BASE_APPLICATION);
        params.width = params.height = WindowManager.LayoutParams.MATCH_PARENT;
        final TestWindowState w = new TestWindowState(
                mAtm.mWindowManager, getTestSession(), new TestIWindow(), params, activity);
@@ -2504,25 +2504,6 @@ public class ActivityRecordTests extends WindowTestsBase {
        activity.removeImmediately();
    }

    @Test
    @Presubmit
    public void testGetTopFullscreenOpaqueWindow() {
        final ActivityRecord activity = new ActivityBuilder(mAtm).setCreateTask(true).build();
        assertNull(activity.getTopFullscreenOpaqueWindow());

        final WindowState window1 = createWindow(null, TYPE_BASE_APPLICATION, activity, "window1");
        final WindowState window11 = createWindow(null, TYPE_APPLICATION, activity, "window11");
        final WindowState window12 = createWindow(null, TYPE_APPLICATION, activity, "window12");
        assertEquals(window12, activity.getTopFullscreenOpaqueWindow());
        window12.mAttrs.width = 500;
        assertEquals(window11, activity.getTopFullscreenOpaqueWindow());
        window11.mAttrs.width = 500;
        assertEquals(window1, activity.getTopFullscreenOpaqueWindow());
        window1.mAttrs.alpha = 0f;
        assertNull(activity.getTopFullscreenOpaqueWindow());
        activity.removeImmediately();
    }

    @SetupWindows(addWindows = W_ACTIVITY)
    @Test
    public void testLandscapeSeascapeRotationByApp() {