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

Commit e966a135 authored by Tiger Huang's avatar Tiger Huang
Browse files

Don't change the controlling window when the new one is not ready yet

Previously, we allow the system UI controlling window to be null. That
was for stopping windows in non-fill-screen windowing mode controlling
system bar insets. However, when there is no multi-window mode involved,
both mFocusedWindow and mTopFullscreenOpaqueWindowState can still be
null if the next candidate window is not ready. In this case, we don't
change the system UI controlling window as we did before.

Bug: 329124127
Flag: com.android.window.flags.force_show_system_bar_for_bubble
Test: atest InsetsPolicyTest InsetsStateControllerTest
Change-Id: I6b672ab45e02dadef6514bc2abc63d079b8891d9
parent c28dfa68
Loading
Loading
Loading
Loading
+29 −11
Original line number Diff line number Diff line
@@ -332,7 +332,7 @@ public class DisplayPolicy {
     */
    private final ArrayList<LetterboxDetails> mLetterboxDetails = new ArrayList<>();

    private String mFocusedApp;
    private String mFocusedPackageName;
    private int mLastDisableFlags;
    private int mLastAppearance;
    private int mLastBehavior;
@@ -2619,13 +2619,25 @@ public class DisplayPolicy {
            // Always accept the window not in multi-window mode.
            return true;
        }
        // Accept the window in multi-window mode only if it fills the display.
        // Accept the window in multi-window mode only if its task fills the display.
        // e.g., A maximized free-form window.
        final Task task = win.getTask();
        final Rect bounds = task != null ? task.getBounds() : win.getBounds();
        return bounds.equals(mDisplayContent.getBounds());
    }

    private boolean fillsDisplayWindowingMode(@NonNull ActivityRecord app) {
        if (!WindowConfiguration.inMultiWindowMode(app.getWindowingMode())) {
            // Always accept the app not in multi-window mode.
            return true;
        }
        // Accept the app in multi-window mode only if its task fills the display.
        // e.g., A maximized free-form window.
        final Task task = app.getTask();
        final Rect bounds = task != null ? task.getBounds() : app.getBounds();
        return bounds.equals(mDisplayContent.getBounds());
    }

    void updateSystemBarAttributes() {
        // If there is no window focused, there will be nobody to handle the events
        // anyway, so just hang on in whatever state we're in until things settle down.
@@ -2633,9 +2645,6 @@ public class DisplayPolicy {
                mFocusedWindow != null && fillsDisplayWindowingMode(mFocusedWindow)
                        ? mFocusedWindow
                        : mTopFullscreenOpaqueWindowState;
        if (winCandidate == null && !com.android.window.flags.Flags.forceShowSystemBarForBubble()) {
            return;
        }

        // Immersive mode confirmation should never affect the system bar visibility, otherwise
        // it will unhide the navigation bar and hide itself.
@@ -2652,8 +2661,15 @@ public class DisplayPolicy {
            } else {
                winCandidate = mTopFullscreenOpaqueWindowState;
            }
            if (winCandidate == null
                    && !com.android.window.flags.Flags.forceShowSystemBarForBubble()) {
        }
        if (winCandidate == null) {
            if (!com.android.window.flags.Flags.forceShowSystemBarForBubble()) {
                // Before this feature, this method early returns when winCandidate is null.
                return;
            }
            final ActivityRecord focusedApp = mDisplayContent.mFocusedApp;
            if (focusedApp != null && fillsDisplayWindowingMode(focusedApp)) {
                // Don't change the system UI controlling window when the new one is not ready.
                return;
            }
        }
@@ -2682,7 +2698,9 @@ public class DisplayPolicy {
        final int behavior = navBarControlWin != null
                ? navBarControlWin.mAttrs.insetsFlags.behavior
                : BEHAVIOR_DEFAULT;
        final String focusedApp = win != null ? win.mAttrs.packageName : "none";
        final String focusedPackageName = win != null
                ? win.mAttrs.packageName
                : "none";
        final boolean isFullscreen = win != null && (!win.isRequestedVisible(Type.statusBars())
                || !win.isRequestedVisible(Type.navigationBars()));
        final AppearanceRegion[] statusBarAppearanceRegions =
@@ -2701,7 +2719,7 @@ public class DisplayPolicy {
        if (mLastAppearance == appearance
                && mLastBehavior == behavior
                && mLastRequestedVisibleTypes == requestedVisibleTypes
                && Objects.equals(mFocusedApp, focusedApp)
                && Objects.equals(mFocusedPackageName, focusedPackageName)
                && mLastFocusIsFullscreen == isFullscreen
                && Arrays.equals(mLastStatusBarAppearanceRegions, statusBarAppearanceRegions)
                && Arrays.equals(mLastLetterboxDetails, letterboxDetails)) {
@@ -2715,13 +2733,13 @@ public class DisplayPolicy {
        mLastAppearance = appearance;
        mLastBehavior = behavior;
        mLastRequestedVisibleTypes = requestedVisibleTypes;
        mFocusedApp = focusedApp;
        mFocusedPackageName = focusedPackageName;
        mLastFocusIsFullscreen = isFullscreen;
        mLastStatusBarAppearanceRegions = statusBarAppearanceRegions;
        mLastLetterboxDetails = letterboxDetails;
        callStatusBarSafely(statusBar -> statusBar.onSystemBarAttributesChanged(displayId,
                appearance, statusBarAppearanceRegions, isNavbarColorManagedByIme, behavior,
                requestedVisibleTypes, focusedApp, letterboxDetails));
                requestedVisibleTypes, focusedPackageName, letterboxDetails));
    }

    private void callStatusBarSafely(Consumer<StatusBarManagerInternal> consumer) {