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

Commit 513d5e18 authored by Tiger Huang's avatar Tiger Huang
Browse files

Use last focused window to control SysUI while IMC dialog is shown

This change fixes a bug that if a child window hides the system UI
but its parent activity window doesn't, the system UI may keep
showing and hiding infinitely.

Bug: b/111490047
Test: 1. atest WindowManagerSmokeTest
      2. atest CtsWindowManagerDeviceTestCases:LayoutTests
Change-Id: Id8bd6e80fe19051b97918089a05f2a12fc1a673d
parent 401ea164
Loading
Loading
Loading
Loading
+20 −5
Original line number Diff line number Diff line
@@ -631,8 +631,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {

    int mPointerLocationMode = 0; // guarded by mLock

    // The last window we were told about in focusChanged.
    // The windows we were told about in focusChanged.
    WindowState mFocusedWindow;
    WindowState mLastFocusedWindow;

    IApplicationToken mFocusedApp;

    PointerLocationView mPointerLocationView;
@@ -3334,6 +3336,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mNavigationBar = null;
            mNavigationBarController.setWindow(null);
        }
        if (mLastFocusedWindow == win) {
            mLastFocusedWindow = null;
        }
        mScreenDecorWindows.remove(win);
    }

@@ -5879,6 +5884,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    @Override
    public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
        mFocusedWindow = newFocus;
        mLastFocusedWindow = lastFocus;
        if ((updateSystemUiVisibilityLw() & SYSTEM_UI_CHANGING_LAYOUT) != 0) {
            // If the navigation bar has been hidden or shown, we need to do another
            // layout pass to update that window.
@@ -8105,10 +8111,19 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        if (winCandidate == null) {
            return 0;
        }

        // The immersive mode confirmation should never affect the system bar visibility, otherwise
        // it will unhide the navigation bar and hide itself.
        if (winCandidate.getAttrs().token == mImmersiveModeConfirmation.getWindowToken()) {
            // The immersive mode confirmation should never affect the system bar visibility,
            // otherwise it will unhide the navigation bar and hide itself.
            winCandidate = isStatusBarKeyguard() ? mStatusBar : mTopFullscreenOpaqueWindowState;

            // The immersive mode confirmation took the focus from mLastFocusedWindow which was
            // controlling the system ui visibility. So if mLastFocusedWindow can still receive
            // keys, we let it keep controlling the visibility.
            final boolean lastFocusCanReceiveKeys =
                    (mLastFocusedWindow != null && mLastFocusedWindow.canReceiveKeys());
            winCandidate = isStatusBarKeyguard() ? mStatusBar
                    : lastFocusCanReceiveKeys ? mLastFocusedWindow
                    : mTopFullscreenOpaqueWindowState;
            if (winCandidate == null) {
                return 0;
            }
+3 −0
Original line number Diff line number Diff line
@@ -491,6 +491,9 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants {
         */
        boolean canAcquireSleepToken();

        /** @return true if this window desires key events. */
        boolean canReceiveKeys();

        /**
         * Writes {@link com.android.server.wm.IdentifierProto} to stream.
         */
+2 −2
Original line number Diff line number Diff line
@@ -2493,8 +2493,8 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
    }

    /** @return true if this window desires key events. */
    boolean canReceiveKeys() {
    @Override
    public boolean canReceiveKeys() {
        return isVisibleOrAdding()
                && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
                && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
+3 −0
Original line number Diff line number Diff line
@@ -254,6 +254,9 @@ public class FakeWindowState implements WindowManagerPolicy.WindowState {
        throw new UnsupportedOperationException("not implemented");
    }

    @Override
    public boolean canReceiveKeys() { return false; }

    @Override
    public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId){
        throw new UnsupportedOperationException("not implemented");