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

Commit 88700bbe authored by Tiger's avatar Tiger
Browse files

Enforce edge-to-edge policy to apps targeting SDK level 35+

- The app content will extend into the system bar and display cutout
  area. The app need to create space for these typs of insets on its own
  to avoid the critical items from getting obscured.

- The framework won't place any color views behind system bars for the
  app. The app can place its owner scrim behind proper types of insets
  (e.g., WindowInsets.Type#tappableElement) if needed.

- Non-floating PhoneWindow will extend into the display cutout area.

Bug: 309578419
Test: WindowInsetsTests
Change-Id: I8a375adb8edadf52fcd0a3fe91b9b074bdb8c715
parent af51f24d
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -3165,6 +3165,12 @@ public interface WindowManager extends ViewManager {
         */
        public static final int PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS = 1 << 10;

        /**
         * Flag to indicate that the window is forcibly to go edge-to-edge.
         * @hide
         */
        public static final int PRIVATE_FLAG_EDGE_TO_EDGE_ENFORCED = 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
@@ -3341,6 +3347,7 @@ public interface WindowManager extends ViewManager {
                PRIVATE_FLAG_SYSTEM_ERROR,
                PRIVATE_FLAG_OPTIMIZE_MEASURE,
                PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS,
                PRIVATE_FLAG_EDGE_TO_EDGE_ENFORCED,
                PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT,
                PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY,
                PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME,
@@ -3402,6 +3409,10 @@ 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_EDGE_TO_EDGE_ENFORCED,
                        equals = PRIVATE_FLAG_EDGE_TO_EDGE_ENFORCED,
                        name = "EDGE_TO_EDGE_ENFORCED"),
                @ViewDebug.FlagToString(
                        mask = PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT,
                        equals = PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT,
+27 −15
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATIO
import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
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;

@@ -294,9 +295,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
    private int mFrameResource = 0;

    private int mTextColor = 0;
    int mStatusBarColor = 0;
    int mNavigationBarColor = 0;
    int mNavigationBarDividerColor = 0;
    int mStatusBarColor = Color.TRANSPARENT;
    int mNavigationBarColor = Color.TRANSPARENT;
    int mNavigationBarDividerColor = Color.TRANSPARENT;
    private boolean mForcedStatusBarColor = false;
    private boolean mForcedNavigationBarColor = false;

@@ -393,6 +394,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
                        || (CompatChanges.isChangeEnabled(ENFORCE_EDGE_TO_EDGE)
                                && Flags.enforceEdgeToEdge());
        if (mEdgeToEdgeEnforced) {
            getAttributes().privateFlags |= PRIVATE_FLAG_EDGE_TO_EDGE_ENFORCED;
            mDecorFitsSystemWindows = false;
        }
    }
@@ -2548,17 +2550,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
        final boolean targetPreL = targetSdk < android.os.Build.VERSION_CODES.LOLLIPOP;
        final boolean targetPreQ = targetSdk < Build.VERSION_CODES.Q;

        if (!mForcedStatusBarColor) {
            final int statusBarCompatibleColor = context.getColor(R.color.status_bar_compatible);
            final int statusBarDefaultColor = context.getColor(R.color.status_bar_default);
            final int statusBarColor = a.getColor(R.styleable.Window_statusBarColor,
                    statusBarDefaultColor);

            mStatusBarColor = statusBarColor == statusBarDefaultColor && !mEdgeToEdgeEnforced
                    ? statusBarCompatibleColor
                    : statusBarColor;
        if (!mForcedStatusBarColor && !mEdgeToEdgeEnforced) {
            mStatusBarColor = a.getColor(R.styleable.Window_statusBarColor, Color.BLACK);
        }
        if (!mForcedNavigationBarColor) {
        if (!mForcedNavigationBarColor && !mEdgeToEdgeEnforced) {
            final int navBarCompatibleColor = context.getColor(R.color.navigation_bar_compatible);
            final int navBarDefaultColor = context.getColor(R.color.navigation_bar_default);
            final int navBarColor = a.getColor(R.styleable.Window_navigationBarColor,
@@ -2566,7 +2561,6 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {

            mNavigationBarColor =
                    navBarColor == navBarDefaultColor
                            && !mEdgeToEdgeEnforced
                            && !context.getResources().getBoolean(
                                    R.bool.config_navBarDefaultTransparent)
                    ? navBarCompatibleColor
@@ -2575,7 +2569,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            mNavigationBarDividerColor = a.getColor(R.styleable.Window_navigationBarDividerColor,
                    Color.TRANSPARENT);
        }
        if (!targetPreQ) {
        if (!targetPreQ && !mEdgeToEdgeEnforced) {
            mEnsureStatusBarContrastWhenTransparent = a.getBoolean(
                    R.styleable.Window_enforceStatusBarContrast, false);
            mEnsureNavigationBarContrastWhenTransparent = a.getBoolean(
@@ -3899,6 +3893,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {

    @Override
    public void setStatusBarColor(int color) {
        if (mEdgeToEdgeEnforced) {
            return;
        }
        if (mStatusBarColor == color && mForcedStatusBarColor) {
            return;
        }
@@ -3920,6 +3917,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {

    @Override
    public void setNavigationBarColor(int color) {
        if (mEdgeToEdgeEnforced) {
            return;
        }
        if (mNavigationBarColor == color && mForcedNavigationBarColor) {
            return;
        }
@@ -3936,6 +3936,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {

    @Override
    public void setNavigationBarDividerColor(int navigationBarDividerColor) {
        if (mEdgeToEdgeEnforced) {
            return;
        }
        mNavigationBarDividerColor = navigationBarDividerColor;
        if (mDecor != null) {
            mDecor.updateColorViews(null, false /* animate */);
@@ -3949,6 +3952,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {

    @Override
    public void setStatusBarContrastEnforced(boolean ensureContrast) {
        if (mEdgeToEdgeEnforced) {
            return;
        }
        mEnsureStatusBarContrastWhenTransparent = ensureContrast;
        if (mDecor != null) {
            mDecor.updateColorViews(null, false /* animate */);
@@ -3962,6 +3968,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {

    @Override
    public void setNavigationBarContrastEnforced(boolean enforceContrast) {
        if (mEdgeToEdgeEnforced) {
            return;
        }
        mEnsureNavigationBarContrastWhenTransparent = enforceContrast;
        if (mDecor != null) {
            mDecor.updateColorViews(null, false /* animate */);
@@ -4031,6 +4040,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {

    @Override
    public void setDecorFitsSystemWindows(boolean decorFitsSystemWindows) {
        if (mEdgeToEdgeEnforced) {
            return;
        }
        mDecorFitsSystemWindows = decorFitsSystemWindows;
        applyDecorFitsSystemWindows();
    }
+0 −4
Original line number Diff line number Diff line
@@ -568,10 +568,6 @@
    <color name="side_fps_button_color">#00677E</color>

    <!-- Color for system bars -->
    <color name="status_bar_compatible">@android:color/black</color>
    <!-- This uses non-regular transparent intentionally. It is used to tell if the transparent
         color is set by the framework or not. -->
    <color name="status_bar_default">#00808080</color>
    <color name="navigation_bar_compatible">@android:color/black</color>
    <!-- This uses non-regular transparent intentionally. It is used to tell if the transparent
         color is set by the framework or not. -->
+0 −2
Original line number Diff line number Diff line
@@ -3095,8 +3095,6 @@
  <java-symbol type="bool" name="config_navBarDefaultTransparent" />
  <java-symbol type="color" name="navigation_bar_default"/>
  <java-symbol type="color" name="navigation_bar_compatible"/>
  <java-symbol type="color" name="status_bar_default"/>
  <java-symbol type="color" name="status_bar_compatible"/>

  <!-- EditText suggestion popup. -->
  <java-symbol type="id" name="suggestionWindowContainer" />
+1 −1
Original line number Diff line number Diff line
@@ -190,7 +190,7 @@ please see themes_device_defaults.xml.
        <item name="windowTranslucentStatus">false</item>
        <item name="windowTranslucentNavigation">false</item>
        <item name="windowDrawsSystemBarBackgrounds">false</item>
        <item name="statusBarColor">@color/status_bar_default</item>
        <item name="statusBarColor">@color/black</item>
        <item name="navigationBarColor">@color/navigation_bar_default</item>
        <item name="windowActionBarFullscreenDecorLayout">@layout/screen_action_bar</item>
        <item name="windowContentTransitions">false</item>
Loading