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

Commit 0cb3e5c4 authored by Tiger's avatar Tiger
Browse files

Add forciblyShownTypes for privileged window to show insets forcibly

It could be done by applying PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION
or PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR, but the caller must be
notification shade of status bar window. This CL enables privileged
window to achieve that, as long as the window has the permission to
provide insets. This CL creates a field for the purpose, and removes
those private flags.

Bug: 278078311
Test: atest InsetsPolicyTest
Test: Receive a heads up notification from Chat in an immersive app, and
      see if status bar is visible.
Test: Expand notification shade in an immersive app, and see if
      navigation bar is visible.
Change-Id: I3fd20435a282c39f6f94e389779fe6c7761cfde2
parent d73d60f4
Loading
Loading
Loading
Loading
+22 −28
Original line number Diff line number Diff line
@@ -3138,15 +3138,6 @@ public interface WindowManager extends ViewManager {
         */
        public static final int PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS = 1 << 10;

        /**
         * Flag to force the status bar window to be visible all the time. If the bar is hidden when
         * this flag is set it will be shown again.
         * This can only be set by {@link LayoutParams#TYPE_STATUS_BAR}.
         *
         * {@hide}
         */
        public static final int PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR = 1 << 11;

        /**
         * Flag to indicate that the window frame should be the requested frame adding the display
         * cutout frame. This will only be applied if a specific size smaller than the parent frame
@@ -3237,15 +3228,6 @@ public interface WindowManager extends ViewManager {
         */
        public static final int PRIVATE_FLAG_NOT_MAGNIFIABLE = 1 << 22;

        /**
         * Flag to indicate that the status bar window is in a state such that it forces showing
         * the navigation bar unless the navigation bar window is explicitly set to
         * {@link View#GONE}.
         * It only takes effects if this is set by {@link LayoutParams#TYPE_STATUS_BAR}.
         * @hide
         */
        public static final int PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION = 1 << 23;

        /**
         * Flag to indicate that the window is color space agnostic, and the color can be
         * interpreted to any color space.
@@ -3334,7 +3316,6 @@ public interface WindowManager extends ViewManager {
                PRIVATE_FLAG_SYSTEM_ERROR,
                PRIVATE_FLAG_OPTIMIZE_MEASURE,
                PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS,
                PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR,
                PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT,
                PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY,
                PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME,
@@ -3345,7 +3326,6 @@ public interface WindowManager extends ViewManager {
                PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY,
                PRIVATE_FLAG_EXCLUDE_FROM_SCREEN_MAGNIFICATION,
                PRIVATE_FLAG_NOT_MAGNIFIABLE,
                PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION,
                PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC,
                PRIVATE_FLAG_USE_BLAST,
                PRIVATE_FLAG_APPEARANCE_CONTROLLED,
@@ -3400,10 +3380,6 @@ public interface WindowManager extends ViewManager {
                        mask = PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS,
                        equals = PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS,
                        name = "DISABLE_WALLPAPER_TOUCH_EVENTS"),
                @ViewDebug.FlagToString(
                        mask = PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR,
                        equals = PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR,
                        name = "FORCE_STATUS_BAR_VISIBLE"),
                @ViewDebug.FlagToString(
                        mask = PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT,
                        equals = PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT,
@@ -3444,10 +3420,6 @@ public interface WindowManager extends ViewManager {
                        mask = PRIVATE_FLAG_NOT_MAGNIFIABLE,
                        equals = PRIVATE_FLAG_NOT_MAGNIFIABLE,
                        name = "NOT_MAGNIFIABLE"),
                @ViewDebug.FlagToString(
                        mask = PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION,
                        equals = PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION,
                        name = "STATUS_FORCE_SHOW_NAVIGATION"),
                @ViewDebug.FlagToString(
                        mask = PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC,
                        equals = PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC,
@@ -4411,6 +4383,16 @@ public interface WindowManager extends ViewManager {
         */
        public InsetsFrameProvider[] providedInsets;

        /**
         * Specifies which {@link InsetsType}s should be forcibly shown. The types shown by this
         * method won't affect the app's layout. This field only takes effects if the caller has
         * {@link android.Manifest.permission#STATUS_BAR_SERVICE} or the caller has the same uid as
         * the recents component.
         *
         * @hide
         */
        public @InsetsType int forciblyShownTypes;

        /**
         * {@link LayoutParams} to be applied to the window when layout with a assigned rotation.
         * This will make layout during rotation change smoothly.
@@ -4869,6 +4851,7 @@ public interface WindowManager extends ViewManager {
            out.writeInt(mBlurBehindRadius);
            out.writeBoolean(mWallpaperTouchEventsEnabled);
            out.writeTypedArray(providedInsets, 0 /* parcelableFlags */);
            out.writeInt(forciblyShownTypes);
            checkNonRecursiveParams();
            out.writeTypedArray(paramsForRotation, 0 /* parcelableFlags */);
            out.writeInt(mDisplayFlags);
@@ -4940,6 +4923,7 @@ public interface WindowManager extends ViewManager {
            mBlurBehindRadius = in.readInt();
            mWallpaperTouchEventsEnabled = in.readBoolean();
            providedInsets = in.createTypedArray(InsetsFrameProvider.CREATOR);
            forciblyShownTypes = in.readInt();
            paramsForRotation = in.createTypedArray(LayoutParams.CREATOR);
            mDisplayFlags = in.readInt();
        }
@@ -5245,6 +5229,11 @@ public interface WindowManager extends ViewManager {
                changes |= LAYOUT_CHANGED;
            }

            if (forciblyShownTypes != o.forciblyShownTypes) {
                forciblyShownTypes = o.forciblyShownTypes;
                changes |= PRIVATE_FLAGS_CHANGED;
            }

            if (paramsForRotation != o.paramsForRotation) {
                if ((changes & LAYOUT_CHANGED) == 0) {
                    if (paramsForRotation != null && o.paramsForRotation != null
@@ -5482,6 +5471,11 @@ public interface WindowManager extends ViewManager {
                    sb.append(prefix).append("    ").append(providedInsets[i]);
                }
            }
            if (forciblyShownTypes != 0) {
                sb.append(System.lineSeparator());
                sb.append(prefix).append("  forciblyShownTypes=").append(
                        WindowInsets.Type.toString(forciblyShownTypes));
            }
            if (paramsForRotation != null && paramsForRotation.length != 0) {
                sb.append(System.lineSeparator());
                sb.append(prefix).append("  paramsForRotation:");
+3 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.view.IWindow;
import android.view.IWindowSession;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.view.WindowManagerGlobal;
@@ -397,9 +398,9 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
    private void applyForceShowNavigationFlag(NotificationShadeWindowState state) {
        if (state.panelExpanded || state.bouncerShowing
                || ENABLE_REMOTE_INPUT && state.remoteInputActive) {
            mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
            mLpChanged.forciblyShownTypes |= WindowInsets.Type.navigationBars();
        } else {
            mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
            mLpChanged.forciblyShownTypes &= ~WindowInsets.Type.navigationBars();
        }
    }

+3 −3
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.view.WindowInsets.Type.statusBars;
import static android.view.WindowInsets.Type.tappableElement;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR;

import static com.android.systemui.util.leak.RotationUtils.ROTATION_LANDSCAPE;
import static com.android.systemui.util.leak.RotationUtils.ROTATION_NONE;
@@ -44,6 +43,7 @@ import android.view.InsetsFrameProvider;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.view.WindowManager;

import com.android.internal.policy.SystemBarUtils;
@@ -361,9 +361,9 @@ public class StatusBarWindowController {
                || state.mIsLaunchAnimationRunning
                // Don't force-show the status bar if the user has already dismissed it.
                || state.mOngoingProcessRequiresStatusBarVisible) {
            mLpChanged.privateFlags |= PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR;
            mLpChanged.forciblyShownTypes |= WindowInsets.Type.statusBars();
        } else {
            mLpChanged.privateFlags &= ~PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR;
            mLpChanged.forciblyShownTypes &= ~WindowInsets.Type.statusBars();
        }
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -268,6 +268,8 @@ public class DisplayPolicy {

    private boolean mIsFreeformWindowOverlappingWithNavBar;

    private @InsetsType int mForciblyShownTypes;

    private boolean mIsImmersiveMode;

    // The windows we were told about in focusChanged.
@@ -1401,6 +1403,7 @@ public class DisplayPolicy {
        mAllowLockscreenWhenOn = false;
        mShowingDream = false;
        mIsFreeformWindowOverlappingWithNavBar = false;
        mForciblyShownTypes = 0;
    }

    /**
@@ -1458,6 +1461,10 @@ public class DisplayPolicy {
            }
        }

        if (win.mSession.mCanForceShowingInsets) {
            mForciblyShownTypes |= win.mAttrs.forciblyShownTypes;
        }

        if (!affectsSystemUi) {
            return;
        }
@@ -1639,6 +1646,10 @@ public class DisplayPolicy {
        mService.mPolicy.setAllowLockscreenWhenOn(getDisplayId(), mAllowLockscreenWhenOn);
    }

    boolean areTypesForciblyShownTransiently(@InsetsType int types) {
        return (mForciblyShownTypes & types) == types;
    }

    /**
     * Applies the keyguard policy to a specific window.
     *
+3 −16
Original line number Diff line number Diff line
@@ -23,8 +23,6 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.view.InsetsSource.ID_IME;
import static android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;

import android.annotation.NonNull;
@@ -473,7 +471,7 @@ class InsetsPolicy {
            // we will dispatch the real visibility of status bar to the client.
            return mPermanentControlTarget;
        }
        if (forceShowsStatusBarTransiently() && !fake) {
        if (mPolicy.areTypesForciblyShownTransiently(Type.statusBars()) && !fake) {
            // Status bar is forcibly shown transiently, and its new visibility won't be
            // dispatched to the client so that we can keep the layout stable. We will dispatch the
            // fake control to the client, so that it can re-show the bar during this scenario.
@@ -505,7 +503,7 @@ class InsetsPolicy {
        if (imeWin != null && imeWin.isVisible() && !mHideNavBarForKeyboard) {
            // Force showing navigation bar while IME is visible and if navigation bar is not
            // configured to be hidden by the IME.
            return null;
            return mPermanentControlTarget;
        }
        if (!fake && isTransient(Type.navigationBars())) {
            return mTransientControlTarget;
@@ -533,7 +531,7 @@ class InsetsPolicy {
            // bar, and we will dispatch the real visibility of navigation bar to the client.
            return mPermanentControlTarget;
        }
        if (forceShowsNavigationBarTransiently() && !fake) {
        if (mPolicy.areTypesForciblyShownTransiently(Type.navigationBars()) && !fake) {
            // Navigation bar is forcibly shown transiently, and its new visibility won't be
            // dispatched to the client so that we can keep the layout stable. We will dispatch the
            // fake control to the client, so that it can re-show the bar during this scenario.
@@ -603,17 +601,6 @@ class InsetsPolicy {
                && focusedWin.getAttrs().type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
    }

    private boolean forceShowsStatusBarTransiently() {
        final WindowState win = mPolicy.getStatusBar();
        return win != null && (win.mAttrs.privateFlags & PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR) != 0;
    }

    private boolean forceShowsNavigationBarTransiently() {
        final WindowState win = mPolicy.getNotificationShade();
        return win != null
                && (win.mAttrs.privateFlags & PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION) != 0;
    }

    private void dispatchTransientSystemBarsVisibilityChanged(
            @Nullable WindowState focusedWindow,
            boolean areVisible,
Loading