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

Commit 53692005 authored by Tiger Huang's avatar Tiger Huang Committed by Android (Google) Code Review
Browse files

Merge "Reland: "Copy mCompatInsetTypes and mCompatIgnoreVisibility"" into main

parents 334f5925 0c0faa9d
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -1454,6 +1454,8 @@ public final class WindowInsets {
        private final Rect[][] mTypeBoundingRectsMap;
        @NonNull
        private final Rect[][] mTypeMaxBoundingRectsMap;
        private @InsetsType int mCompatInsetTypes = systemBars();
        private boolean mCompatIgnoreVisibility;
        private boolean mSystemInsetsConsumed = true;
        private boolean mStableInsetsConsumed = true;

@@ -1496,6 +1498,10 @@ public final class WindowInsets {
            mTypeInsetsMap = insets.mTypeInsetsMap.clone();
            mTypeMaxInsetsMap = insets.mTypeMaxInsetsMap.clone();
            mTypeVisibilityMap = insets.mTypeVisibilityMap.clone();
            if (com.android.window.flags.Flags.copyCompatFieldsOfWindowInsets()) {
                mCompatInsetTypes = insets.mCompatInsetsTypes;
                mCompatIgnoreVisibility = insets.mCompatIgnoreVisibility;
            }
            mSystemInsetsConsumed = insets.mSystemWindowInsetsConsumed;
            mStableInsetsConsumed = insets.mStableInsetsConsumed;
            mDisplayCutout = displayCutoutCopyConstructorArgument(insets);
@@ -1529,6 +1535,11 @@ public final class WindowInsets {
        public Builder setSystemWindowInsets(@NonNull Insets systemWindowInsets) {
            Objects.requireNonNull(systemWindowInsets);
            assignCompatInsets(mTypeInsetsMap, systemWindowInsets.toRect());
            if (com.android.window.flags.Flags.copyCompatFieldsOfWindowInsets()) {
                // This should match the types used in assignCompatInsets.
                mCompatInsetTypes = STATUS_BARS | NAVIGATION_BARS;
                mCompatIgnoreVisibility = false;
            }
            mSystemInsetsConsumed = false;
            return this;
        }
@@ -1871,7 +1882,7 @@ public final class WindowInsets {
                    mStableInsetsConsumed ? null : mTypeMaxInsetsMap, mTypeVisibilityMap,
                    mIsRound, mForceConsumingTypes, mForceConsumingOpaqueCaptionBar,
                    mSuppressScrimTypes, mDisplayCutout, mRoundedCorners, mPrivacyIndicatorBounds,
                    mDisplayShape, systemBars(), false /* compatIgnoreVisibility */,
                    mDisplayShape, mCompatInsetTypes, mCompatIgnoreVisibility,
                    mSystemInsetsConsumed ? null : mTypeBoundingRectsMap,
                    mStableInsetsConsumed ? null : mTypeMaxBoundingRectsMap,
                    mFrameWidth, mFrameHeight);
+11 −0
Original line number Diff line number Diff line
@@ -56,6 +56,17 @@ flag {
  is_fixed_read_only: true
}

flag {
  name: "copy_compat_fields_of_window_insets"
  namespace: "windowing_frontend"
  description: "Copy mCompatInsetTypes and mCompatIgnoreVisibility from WindowInsets"
  bug: "409469172"
  is_fixed_read_only: true
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
  name: "close_to_square_config_includes_status_bar"
  namespace: "windowing_frontend"
+60 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.view.WindowInsets.Type.TYPES;
import static android.view.WindowInsets.Type.captionBar;
import static android.view.WindowInsets.Type.displayCutout;
import static android.view.WindowInsets.Type.ime;
import static android.view.WindowInsets.Type.indexOf;
import static android.view.WindowInsets.Type.navigationBars;
import static android.view.WindowInsets.Type.statusBars;
import static android.view.WindowInsets.Type.systemBars;
@@ -29,6 +30,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;

import android.graphics.Insets;
import android.graphics.Rect;
@@ -169,6 +171,64 @@ public class WindowInsetsTest {
        assertEquals(Insets.of(0, 10, 0, 0), windowInsets.getSystemWindowInsets());
    }

    @Test
    public void builder_copy_compatInsetTypes() {
        assumeTrue(com.android.window.flags.Flags.copyCompatFieldsOfWindowInsets());
        final Insets[] insets = new Insets[TYPES.length];
        final Insets[] maxInsets = new Insets[TYPES.length];
        final boolean[] visible = new boolean[TYPES.length];
        final int compatInsetTypes = systemBars() | displayCutout() | ime();
        final WindowInsets windowInsets = new WindowInsets(insets, maxInsets, visible, false, 0,
                false, 0, null, null, null, DisplayShape.NONE, compatInsetTypes,
                false /* compatIgnoreVisibility */, null, null, 0, 0);
        final WindowInsets modified = new WindowInsets.Builder(windowInsets)
                .setInsets(statusBars(), Insets.of(0, 10, 0, 0))
                .setInsets(navigationBars(), Insets.of(0, 0, 20, 0))
                .setInsets(displayCutout(), Insets.of(30, 0, 0, 0))
                .setInsets(ime(), Insets.of(0, 0, 0, 40))
                .build();
        assertEquals(Insets.of(30, 10, 20, 40), modified.getSystemWindowInsets());
    }

    @Test
    public void builder_copy_compatIgnoreVisibility() {
        assumeTrue(com.android.window.flags.Flags.copyCompatFieldsOfWindowInsets());
        final Insets[] insets = new Insets[TYPES.length];
        final Insets[] maxInsets = new Insets[TYPES.length];
        final boolean[] visible = new boolean[TYPES.length];
        final int compatInsetTypes = systemBars() | displayCutout();
        final WindowInsets windowInsets = new WindowInsets(insets, maxInsets, visible, false, 0,
                false, 0, null, null, null, DisplayShape.NONE, compatInsetTypes,
                true /* compatIgnoreVisibility */, null, null, 0, 0);
        final WindowInsets modified = new WindowInsets.Builder(windowInsets)
                .setInsetsIgnoringVisibility(statusBars(), Insets.of(0, 10, 0, 0))
                .setInsetsIgnoringVisibility(navigationBars(), Insets.of(0, 0, 20, 0))
                .setInsetsIgnoringVisibility(displayCutout(), Insets.of(30, 0, 0, 0))
                .build();
        assertEquals(Insets.of(30, 10, 20, 0), modified.getSystemWindowInsets());
    }

    @Test
    public void builder_setSystemWindowInsets() {
        assumeTrue(com.android.window.flags.Flags.copyCompatFieldsOfWindowInsets());
        final Insets[] insets = new Insets[TYPES.length];
        final Insets[] maxInsets = new Insets[TYPES.length];
        final boolean[] visible = new boolean[TYPES.length];
        final int compatInsetTypes = systemBars() | displayCutout() | ime();
        maxInsets[indexOf(captionBar())] = Insets.of(0, 10, 0, 0);
        maxInsets[indexOf(navigationBars())] = Insets.of(0, 0, 20, 0);
        maxInsets[indexOf(displayCutout())] = Insets.of(30, 0, 0, 0);
        insets[indexOf(ime())] = Insets.of(0, 0, 0, 40);
        final WindowInsets windowInsets = new WindowInsets(insets, maxInsets, visible, false, 0,
                false, 0, null, null, null, DisplayShape.NONE, compatInsetTypes,
                true /* compatIgnoreVisibility */, null, null, 0, 0);
        assertEquals(Insets.of(30, 10, 20, 40), windowInsets.getSystemWindowInsets());
        final WindowInsets modified = new WindowInsets.Builder(windowInsets)
                .setSystemWindowInsets(Insets.of(1, 2, 3, 4))
                .build();
        assertEquals(Insets.of(1, 2, 3, 4), modified.getSystemWindowInsets());
    }

    @Test
    public void testSetBoundingRectsInBuilder_noInsets_preservedInWindowInsets() {
        final List<Rect> rects = List.of(new Rect(0, 0, 50, 100));