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

Commit 3cf0f1e2 authored by Yunfan Chen's avatar Yunfan Chen
Browse files

Override layout in display cutout mode when needed

This patch introduce a compat change id to support layout in display
cutout mode override. If the flag for the app is set to true, the app
will always layout in display cutout, regardless of the value it sets.

However, if the app is explicitly opt out the edge to edge behavior, we
respect the app's choice and ignore the override.

Test: Check table top behavior of video apps with the flag set
Bug: 332679525
Change-Id: I24e922d2200f0a3c362aeef36512c716590ce4d9
Merged-In: I24e922d2200f0a3c362aeef36512c716590ce4d9
parent c813075a
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import static android.view.ViewRootImplProto.WINDOW_ATTRIBUTES;
import static android.view.ViewRootImplProto.WIN_FRAME;
import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
import static android.view.flags.Flags.sensitiveContentAppProtection;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_OVERRIDE_LAYOUT_IN_DISPLAY_CUTOUT_MODE;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;
import static android.view.WindowInsetsController.APPEARANCE_LOW_PROFILE_BARS;
@@ -2056,7 +2057,8 @@ public final class ViewRootImpl implements ViewParent,
    private int adjustLayoutInDisplayCutoutMode(WindowManager.LayoutParams attrs) {
        final int originalMode = attrs.layoutInDisplayCutoutMode;
        if ((attrs.privateFlags & PRIVATE_FLAG_EDGE_TO_EDGE_ENFORCED) != 0
        if ((attrs.privateFlags & (PRIVATE_FLAG_EDGE_TO_EDGE_ENFORCED
                | PRIVATE_FLAG_OVERRIDE_LAYOUT_IN_DISPLAY_CUTOUT_MODE)) != 0
                && attrs.isFullscreen()
                && attrs.getFitInsetsTypes() == 0
                && attrs.getFitInsetsSides() == 0) {
+11 −0
Original line number Diff line number Diff line
@@ -3313,6 +3313,12 @@ public interface WindowManager extends ViewManager {
         */
        public static final int PRIVATE_FLAG_IMMERSIVE_CONFIRMATION_WINDOW = 1 << 17;

        /**
         * Flag to indicate that the window is forcibly to layout under the display cutout.
         * @hide
         */
        public static final int PRIVATE_FLAG_OVERRIDE_LAYOUT_IN_DISPLAY_CUTOUT_MODE = 1 << 18;

        /**
         * Flag to indicate that any window added by an application process that is of type
         * {@link #TYPE_TOAST} or that requires
@@ -3447,6 +3453,7 @@ public interface WindowManager extends ViewManager {
                PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS,
                PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE,
                PRIVATE_FLAG_IMMERSIVE_CONFIRMATION_WINDOW,
                PRIVATE_FLAG_OVERRIDE_LAYOUT_IN_DISPLAY_CUTOUT_MODE,
                SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS,
                PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY,
                PRIVATE_FLAG_EXCLUDE_FROM_SCREEN_MAGNIFICATION,
@@ -3530,6 +3537,10 @@ public interface WindowManager extends ViewManager {
                        mask = PRIVATE_FLAG_IMMERSIVE_CONFIRMATION_WINDOW,
                        equals = PRIVATE_FLAG_IMMERSIVE_CONFIRMATION_WINDOW,
                        name = "IMMERSIVE_CONFIRMATION_WINDOW"),
                @ViewDebug.FlagToString(
                        mask = PRIVATE_FLAG_OVERRIDE_LAYOUT_IN_DISPLAY_CUTOUT_MODE,
                        equals = PRIVATE_FLAG_OVERRIDE_LAYOUT_IN_DISPLAY_CUTOUT_MODE,
                        name = "OVERRIDE_LAYOUT_IN_DISPLAY_CUTOUT_MODE"),
                @ViewDebug.FlagToString(
                        mask = SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS,
                        equals = SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS,
+17 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_M
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_EDGE_TO_EDGE_ENFORCED;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_OVERRIDE_LAYOUT_IN_DISPLAY_CUTOUT_MODE;

import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -43,7 +44,9 @@ import android.app.KeyguardManager;
import android.app.SearchManager;
import android.app.compat.CompatChanges;
import android.compat.annotation.ChangeId;
import android.compat.annotation.Disabled;
import android.compat.annotation.EnabledSince;
import android.compat.annotation.Overridable;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Intent;
@@ -177,6 +180,15 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
    @EnabledSince(targetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM)
    private static final long ENFORCE_EDGE_TO_EDGE = 309578419;

    /**
     * Override the layout in display cutout mode behavior. This will only apply if the edge to edge
     * is not enforced.
     */
    @ChangeId
    @Disabled
    @Overridable
    private static final long OVERRIDE_LAYOUT_IN_DISPLAY_CUTOUT_MODE = 332679525L;

    private static final int CUSTOM_TITLE_COMPATIBLE_FEATURES = DEFAULT_FEATURES |
            (1 << FEATURE_CUSTOM_TITLE) |
            (1 << FEATURE_CONTENT_TRANSITIONS) |
@@ -2475,6 +2487,11 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            getAttributes().privateFlags |= PRIVATE_FLAG_EDGE_TO_EDGE_ENFORCED;
            mDecorFitsSystemWindows = false;
        }
        if (CompatChanges.isChangeEnabled(OVERRIDE_LAYOUT_IN_DISPLAY_CUTOUT_MODE)
                && !a.getBoolean(R.styleable.Window_windowOptOutEdgeToEdgeEnforcement,
                false /* defValue */)) {
            getAttributes().privateFlags |= PRIVATE_FLAG_OVERRIDE_LAYOUT_IN_DISPLAY_CUTOUT_MODE;
        }

        mIsFloating = a.getBoolean(R.styleable.Window_windowIsFloating, false);
        int flagsToUpdate = (FLAG_LAYOUT_IN_SCREEN|FLAG_LAYOUT_INSET_DECOR)