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

Commit b695dbc7 authored by Calvin Huang's avatar Calvin Huang
Browse files

Fix nav bar flickering when dialog shows

Notify the remoteInsetsController after deciding the control targets for
both getStatusControlTarget and getNavControlTarget instead of notify on
the fly.

This is to avoid sending different requestedVisibleTypes with the same
compnent name when a floating window requests different vislbe types from
the top-fullscreen-app.

Bug: 395985750
Test: CTS-V: No Device Owner Test
Flag: NONE (bug fix)
Change-Id: I349a34e5b862f4f983d2fc2505dce8904878d7f9
parent 9a110e09
Loading
Loading
Loading
Loading
+66 −46
Original line number Original line Diff line number Diff line
@@ -113,25 +113,33 @@ class InsetsPolicy {
            abortTransient();
            abortTransient();
        }
        }
        mFocusedWin = focusedWin;
        mFocusedWin = focusedWin;
        final @InsetsType int[] requestedVisibleTypes =
                {focusedWin != null ? focusedWin.getRequestedVisibleTypes() : 0};
        final WindowState notificationShade = mPolicy.getNotificationShade();
        final WindowState notificationShade = mPolicy.getNotificationShade();
        final WindowState topApp = mPolicy.getTopFullscreenOpaqueWindow();
        final WindowState topApp = mPolicy.getTopFullscreenOpaqueWindow();
        final InsetsControlTarget statusControlTarget =
        final InsetsControlTarget statusControlTarget =
                getStatusControlTarget(focusedWin, false /* fake */);
                getStatusControlTarget(focusedWin, false /* fake */, requestedVisibleTypes);
        mFakeStatusControlTarget = statusControlTarget == mTransientControlTarget
        mFakeStatusControlTarget = statusControlTarget == mTransientControlTarget
                ? getStatusControlTarget(focusedWin, true /* fake */)
                ? getStatusControlTarget(focusedWin, true /* fake */, requestedVisibleTypes)
                : statusControlTarget == notificationShade
                : statusControlTarget == notificationShade
                        ? getStatusControlTarget(topApp, true /* fake */)
                        ? getStatusControlTarget(topApp, true /* fake */, requestedVisibleTypes)
                        : null;
                        : null;
        final InsetsControlTarget navControlTarget =
        final InsetsControlTarget navControlTarget =
                getNavControlTarget(focusedWin, false /* fake */);
                getNavControlTarget(focusedWin, false /* fake */, requestedVisibleTypes);
        mFakeNavControlTarget = navControlTarget == mTransientControlTarget
        mFakeNavControlTarget = navControlTarget == mTransientControlTarget
                ? getNavControlTarget(focusedWin, true /* fake */)
                ? getNavControlTarget(focusedWin, true /* fake */, requestedVisibleTypes)
                : navControlTarget == notificationShade
                : navControlTarget == notificationShade
                        ? getNavControlTarget(topApp, true /* fake */)
                        ? getNavControlTarget(topApp, true /* fake */, requestedVisibleTypes)
                        : null;
                        : null;
        mStateController.onBarControlTargetChanged(
        mStateController.onBarControlTargetChanged(
                statusControlTarget, mFakeStatusControlTarget,
                statusControlTarget, mFakeStatusControlTarget,
                navControlTarget, mFakeNavControlTarget);
                navControlTarget, mFakeNavControlTarget);

        if (statusControlTarget == mDisplayContent.mRemoteInsetsControlTarget
                && navControlTarget == mDisplayContent.mRemoteInsetsControlTarget) {
            notifyRemoteInsetsController(focusedWin, requestedVisibleTypes[0]);
        }

        mStatusBar.updateVisibility(statusControlTarget, Type.statusBars());
        mStatusBar.updateVisibility(statusControlTarget, Type.statusBars());
        mNavBar.updateVisibility(navControlTarget, Type.navigationBars());
        mNavBar.updateVisibility(navControlTarget, Type.navigationBars());
    }
    }
@@ -496,6 +504,18 @@ class InsetsPolicy {
    }
    }


    private @Nullable InsetsControlTarget getStatusControlTarget(@Nullable WindowState focusedWin,
    private @Nullable InsetsControlTarget getStatusControlTarget(@Nullable WindowState focusedWin,
            boolean fake, @InsetsType int[] requestedVisibleTypes) {
        final InsetsControlTarget target = getStatusControlTargetInner(focusedWin, fake);
        if (remoteInsetsControllerControlsSystemBars(target)) {
            requestedVisibleTypes[0] = (requestedVisibleTypes[0] & ~Type.statusBars()) | (
                    target.getRequestedVisibleTypes() & Type.statusBars());
            return mDisplayContent.mRemoteInsetsControlTarget;
        }
        return target;
    }

    private @Nullable InsetsControlTarget getStatusControlTargetInner(
            @Nullable WindowState focusedWin,
            boolean fake) {
            boolean fake) {
        if (!fake && isTransient(Type.statusBars())) {
        if (!fake && isTransient(Type.statusBars())) {
            return mTransientControlTarget;
            return mTransientControlTarget;
@@ -521,18 +541,8 @@ class InsetsPolicy {
                && (notificationShade == null || !notificationShade.canReceiveKeys())) {
                && (notificationShade == null || !notificationShade.canReceiveKeys())) {
            // Non-fullscreen focused window should not break the state that the top-fullscreen-app
            // Non-fullscreen focused window should not break the state that the top-fullscreen-app
            // window hides status bar, unless the notification shade can receive keys.
            // window hides status bar, unless the notification shade can receive keys.
            if (remoteInsetsControllerControlsSystemBars(
                    mPolicy.getTopFullscreenOpaqueWindow())) {
                notifyRemoteInsetsController(mPolicy.getTopFullscreenOpaqueWindow());
                return mDisplayContent.mRemoteInsetsControlTarget;
            } else {
            return mPolicy.getTopFullscreenOpaqueWindow();
            return mPolicy.getTopFullscreenOpaqueWindow();
        }
        }
        }
        if (remoteInsetsControllerControlsSystemBars(focusedWin)) {
            notifyRemoteInsetsController(focusedWin);
            return mDisplayContent.mRemoteInsetsControlTarget;
        }
        return focusedWin;
        return focusedWin;
    }
    }


@@ -547,6 +557,17 @@ class InsetsPolicy {
    }
    }


    private @Nullable InsetsControlTarget getNavControlTarget(@Nullable WindowState focusedWin,
    private @Nullable InsetsControlTarget getNavControlTarget(@Nullable WindowState focusedWin,
            boolean fake, @InsetsType int[] requestedVisibleTypes) {
        final InsetsControlTarget target = getNavControlTargetInner(focusedWin, fake);
        if (remoteInsetsControllerControlsSystemBars(target)) {
            requestedVisibleTypes[0] = (requestedVisibleTypes[0] & ~Type.navigationBars()) | (
                    target.getRequestedVisibleTypes() & Type.navigationBars());
            return mDisplayContent.mRemoteInsetsControlTarget;
        }
        return target;
    }

    private @Nullable InsetsControlTarget getNavControlTargetInner(@Nullable WindowState focusedWin,
            boolean fake) {
            boolean fake) {
        final WindowState imeWin = mDisplayContent.mInputMethodWindow;
        final WindowState imeWin = mDisplayContent.mInputMethodWindow;
        if (imeWin != null && imeWin.isVisible() && !mHideNavBarForKeyboard) {
        if (imeWin != null && imeWin.isVisible() && !mHideNavBarForKeyboard) {
@@ -585,29 +606,21 @@ class InsetsPolicy {
                && (notificationShade == null || !notificationShade.canReceiveKeys())) {
                && (notificationShade == null || !notificationShade.canReceiveKeys())) {
            // Non-fullscreen focused window should not break the state that the top-fullscreen-app
            // Non-fullscreen focused window should not break the state that the top-fullscreen-app
            // window hides navigation bar, unless the notification shade can receive keys.
            // window hides navigation bar, unless the notification shade can receive keys.
            if (remoteInsetsControllerControlsSystemBars(
                    mPolicy.getTopFullscreenOpaqueWindow())) {
                notifyRemoteInsetsController(mPolicy.getTopFullscreenOpaqueWindow());
                return mDisplayContent.mRemoteInsetsControlTarget;
            } else {
            return mPolicy.getTopFullscreenOpaqueWindow();
            return mPolicy.getTopFullscreenOpaqueWindow();
        }
        }
        }
        if (remoteInsetsControllerControlsSystemBars(focusedWin)) {
            notifyRemoteInsetsController(focusedWin);
            return mDisplayContent.mRemoteInsetsControlTarget;
        }
        return focusedWin;
        return focusedWin;
    }
    }


    private void notifyRemoteInsetsController(@Nullable WindowState win) {
    private void notifyRemoteInsetsController(@Nullable WindowState win,
            @InsetsType int requestVisibleTypes) {
        if (win == null) {
        if (win == null) {
            return;
            return;
        }
        }
        ComponentName component = win.mActivityRecord != null
        ComponentName component = win.mActivityRecord != null
                ? win.mActivityRecord.mActivityComponent : null;
                ? win.mActivityRecord.mActivityComponent : null;

        mDisplayContent.mRemoteInsetsControlTarget.topFocusedWindowChanged(
        mDisplayContent.mRemoteInsetsControlTarget.topFocusedWindowChanged(
                component, win.getRequestedVisibleTypes());
                component, requestVisibleTypes);
    }
    }


    boolean areTypesForciblyShowing(@InsetsType int types) {
    boolean areTypesForciblyShowing(@InsetsType int types) {
@@ -645,8 +658,8 @@ class InsetsPolicy {
     * Determines whether the remote insets controller should take control of system bars for all
     * Determines whether the remote insets controller should take control of system bars for all
     * windows.
     * windows.
     */
     */
    boolean remoteInsetsControllerControlsSystemBars(@Nullable WindowState focusedWin) {
    boolean remoteInsetsControllerControlsSystemBars(@Nullable InsetsControlTarget target) {
        if (focusedWin == null) {
        if (!(target instanceof WindowState win)) {
            return false;
            return false;
        }
        }


@@ -660,8 +673,8 @@ class InsetsPolicy {
        // If necessary, auto can control application windows when
        // If necessary, auto can control application windows when
        // config_remoteInsetsControllerControlsSystemBars is set to true. This is useful in cases
        // config_remoteInsetsControllerControlsSystemBars is set to true. This is useful in cases
        // where we want to dictate system bar inset state for applications.
        // where we want to dictate system bar inset state for applications.
        return focusedWin.getAttrs().type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
        return win.getAttrs().type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
                && focusedWin.getAttrs().type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
                && win.getAttrs().type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
    }
    }


    private void dispatchTransientSystemBarsVisibilityChanged(
    private void dispatchTransientSystemBarsVisibilityChanged(
@@ -790,11 +803,13 @@ class InsetsPolicy {
        }
        }


        @Override
        @Override
        public void notifyInsetsChanged() { }
        public void notifyInsetsChanged() {
        }


        @Override
        @Override
        public void dispatchWindowInsetsAnimationPrepare(
        public void dispatchWindowInsetsAnimationPrepare(
                @NonNull WindowInsetsAnimation animation) { }
                @NonNull WindowInsetsAnimation animation) {
        }


        @Override
        @Override
        public Bounds dispatchWindowInsetsAnimationStart(
        public Bounds dispatchWindowInsetsAnimationStart(
@@ -812,7 +827,8 @@ class InsetsPolicy {


        @Override
        @Override
        public void dispatchWindowInsetsAnimationEnd(
        public void dispatchWindowInsetsAnimationEnd(
                @NonNull WindowInsetsAnimation animation) { }
                @NonNull WindowInsetsAnimation animation) {
        }


        @Override
        @Override
        public void applySurfaceParams(SyncRtSurfaceTransactionApplier.SurfaceParams... p) {
        public void applySurfaceParams(SyncRtSurfaceTransactionApplier.SurfaceParams... p) {
@@ -834,7 +850,8 @@ class InsetsPolicy {
        }
        }


        @Override
        @Override
        public void setSystemBarsAppearance(int appearance, int mask) { }
        public void setSystemBarsAppearance(int appearance, int mask) {
        }


        @Override
        @Override
        public int getSystemBarsAppearance() {
        public int getSystemBarsAppearance() {
@@ -842,7 +859,8 @@ class InsetsPolicy {
        }
        }


        @Override
        @Override
        public void setSystemBarsBehavior(int behavior) { }
        public void setSystemBarsBehavior(int behavior) {
        }


        @Override
        @Override
        public int getSystemBarsBehavior() {
        public int getSystemBarsBehavior() {
@@ -855,10 +873,12 @@ class InsetsPolicy {
        }
        }


        @Override
        @Override
        public void addOnPreDrawRunnable(Runnable r) { }
        public void addOnPreDrawRunnable(Runnable r) {
        }


        @Override
        @Override
        public void postInsetsAnimationCallback(Runnable r) { }
        public void postInsetsAnimationCallback(Runnable r) {
        }


        @Override
        @Override
        public InputMethodManager getInputMethodManager() {
        public InputMethodManager getInputMethodManager() {