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

Commit 348bcc7e authored by Graciela Putri's avatar Graciela Putri Committed by Android (Google) Code Review
Browse files

Merge "[3/n] Update system override cache when activity restarted" into main

parents 48771cbe 9062198c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -8785,6 +8785,8 @@ final class ActivityRecord extends WindowToken {
        // configuration.
        mAppCompatController.getSizeCompatModePolicy().clearSizeCompatMode();
        mAppCompatController.getDisplayCompatModePolicy().onProcessRestarted();
        final boolean fullscreenOverrideChanged =
                mAppCompatController.getAspectRatioOverrides().resetSystemFullscreenOverrideCache();

        if (!attachedToProcess()) {
            return;
@@ -8811,6 +8813,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
@@ -1914,6 +1914,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();
        }