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

Commit 9062198c authored by Graciela Wissen Putri's avatar Graciela Wissen Putri Committed by Graciela Putri
Browse files

[3/n] Update system override cache when activity restarted

If app is restarted from size compat mode restart button or with the
restart handle menu, activity and task resizeability should be updated
so it doesn't use values evaluated from the previous display.

Flag: com.android.window.flags.limit_system_fullscreen_override_to_default_display
Bug: 423802240
Test: atest AppCompatAspectRatioOverridesTest
Change-Id: If254187e7246133e5283645a2b82d6a586cc2b09
parent da316ca8
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -8804,6 +8804,8 @@ final class ActivityRecord extends WindowToken {
        // configuration.
        mAppCompatController.getSizeCompatModePolicy().clearSizeCompatMode();
        mAppCompatController.getDisplayCompatModePolicy().onProcessRestarted();
        final boolean fullscreenOverrideChanged =
                mAppCompatController.getAspectRatioOverrides().resetSystemFullscreenOverrideCache();

        if (!attachedToProcess()) {
            return;
@@ -8830,6 +8832,10 @@ final class ActivityRecord extends WindowToken {
            return;
        }

        if (fullscreenOverrideChanged) {
            task.updateForceResizeOverridesIfNeeded(this);
        }

        // Process restart may require trampoline activity launch, for which app switching needs to
        // be enabled. App switching may be allowed only for specific cases while/after Recents is
        // shown. As when a process is restarted, the user should be interacting with the app, so
+14 −0
Original line number Diff line number Diff line
@@ -193,6 +193,20 @@ class AppCompatAspectRatioOverrides {
        return baseOverride;
    }

    boolean hasSystemFullscreenOverrideCache() {
        return mIsSystemFullscreenOverrideEnabled == null
                && LIMIT_SYSTEM_FULLSCREEN_OVERRIDE_TO_DEFAULT_DISPLAY.isTrue();
    }

    boolean resetSystemFullscreenOverrideCache() {
        if (mIsSystemFullscreenOverrideEnabled != null) {
            mIsSystemFullscreenOverrideEnabled = null;
            return true;
        }
        return false;
    }


    /**
     * Whether we should enable users to resize the current app.
     */
+12 −0
Original line number Diff line number Diff line
@@ -1918,6 +1918,18 @@ class Task extends TaskFragment {
                -1 /* don't check PID */, -1 /* don't check UID */, this);
    }

    /**
     * Update task's force resize overrides if the system full-screen override cache has
     * been invalidated due to activity restart.
     */
    void updateForceResizeOverridesIfNeeded(@NonNull ActivityRecord r) {
        final AppCompatAspectRatioOverrides aspectRatioOverrides =
                r.mAppCompatController.getAspectRatioOverrides();
        if (aspectRatioOverrides.hasSystemFullscreenOverrideCache()) {
            updateForceResizeOverrides(r);
        }
    }

    private void updateForceResizeOverrides(@NonNull ActivityRecord r) {
        final AppCompatResizeOverrides resizeOverrides = r.mAppCompatController
                .getResizeOverrides();
+32 −0
Original line number Diff line number Diff line
@@ -438,6 +438,34 @@ public class AppCompatAspectRatioOverridesTest extends WindowTestsBase {
        });
    }

    @Test
    @EnableFlags(Flags.FLAG_LIMIT_SYSTEM_FULLSCREEN_OVERRIDE_TO_DEFAULT_DISPLAY)
    @EnableCompatChanges(ActivityInfo.OVERRIDE_ANY_ORIENTATION_TO_USER)
    public void testSystemFullscreenOverride_activityRestartedInDefaultDisplay_true() {
        runTestScenario((robot) -> {
            robot.applyOnActivity((a) -> {
                a.setDisplayId(DEFAULT_DISPLAY + 2);
                a.createActivityWithComponentInNewTask();
                a.top().mVisibleRequested = true;
                a.top().setSavedState(null);
                a.setIgnoreOrientationRequest(true);
                a.configureTopActivity(/* minAspect */ -1f, /* maxAspect */-1f,
                        SCREEN_ORIENTATION_LANDSCAPE, true);

                // Simulate display move.
                a.setDisplayId(DEFAULT_DISPLAY);
            });

            robot.checkHasFullscreenOverride(false);
            robot.checkTaskIsResizeable(false);

            robot.activity().top().restartProcessIfVisible();

            robot.checkHasFullscreenOverride(true);
            robot.checkTaskIsResizeable(true);
        });
    }

    /**
     * Runs a test scenario providing a Robot.
     */
@@ -521,6 +549,10 @@ public class AppCompatAspectRatioOverridesTest extends WindowTestsBase {
                    getTopActivityAppCompatAspectRatioOverrides().hasFullscreenOverride());
        }

        void checkTaskIsResizeable(boolean expected) {
            assertEquals(expected, activity().top().getTask().isResizeable());
        }

        private AppCompatAspectRatioOverrides getTopActivityAppCompatAspectRatioOverrides() {
            return activity().top().mAppCompatController.getAspectRatioOverrides();
        }