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

Commit e1d2b2b7 authored by shawnlin's avatar shawnlin
Browse files

Fixed cutout not being updated for non hwc layer

Call onDisplayChanged for non-hwc cutout view to update cutout.

Bug: 221242189
Test: manual:
      1. select double cutout emulation in settings
      2. reboot device and check the cutout
Test: atest ScreenDecorationsTest
Change-Id: I7272249a5a708d5c359d02f3330eb038c7747c78
parent ad724202
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -143,8 +143,9 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
    private int mProviderRefreshToken = 0;
    @VisibleForTesting
    protected OverlayWindow[] mOverlays = null;
    @VisibleForTesting
    @Nullable
    private DisplayCutoutView[] mCutoutViews;
    DisplayCutoutView[] mCutoutViews;
    @VisibleForTesting
    ViewGroup mScreenDecorHwcWindow;
    @VisibleForTesting
@@ -365,6 +366,16 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
                    }
                    updateHwLayerRoundedCornerDrawable();
                }
                if (mCutoutViews != null) {
                    final int size = mCutoutViews.length;
                    for (int i = 0; i < size; i++) {
                        final DisplayCutoutView cutoutView = mCutoutViews[i];
                        if (cutoutView == null) {
                            continue;
                        }
                        cutoutView.onDisplayChanged(displayId);
                    }
                }
                if (mScreenDecorHwcLayer != null) {
                    mScreenDecorHwcLayer.onDisplayChanged(displayId);
                }
+52 −0
Original line number Diff line number Diff line
@@ -126,6 +126,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
    private CornerDecorProvider mPrivacyDotBottomLeftDecorProvider;
    @Mock
    private CornerDecorProvider mPrivacyDotBottomRightDecorProvider;
    @Mock
    private Display.Mode mDisplayMode;

    @Before
    public void setup() {
@@ -1163,6 +1165,56 @@ public class ScreenDecorationsTest extends SysuiTestCase {

    }

    @Test
    public void testOnDisplayChanged_hwcLayer() {
        setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
                0 /* roundedPadding */, false /* multipleRadius */,
                true /* fillCutout */, false /* privacyDot */);
        final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport();
        decorationSupport.format = PixelFormat.R_8;
        doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport();

        // top cutout
        final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
        doReturn(getDisplayCutoutForRotation(Insets.of(0, 1, 0, 0), bounds))
                .when(mScreenDecorations).getCutout();

        mScreenDecorations.start();

        final ScreenDecorHwcLayer hwcLayer = mScreenDecorations.mScreenDecorHwcLayer;
        spyOn(hwcLayer);
        doReturn(mDisplay).when(hwcLayer).getDisplay();
        doReturn(mDisplayMode).when(mDisplay).getMode();

        mScreenDecorations.mDisplayListener.onDisplayChanged(1);

        verify(hwcLayer, times(1)).onDisplayChanged(1);
    }

    @Test
    public void testOnDisplayChanged_nonHwcLayer() {
        setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
                0 /* roundedPadding */, false /* multipleRadius */,
                true /* fillCutout */, false /* privacyDot */);

        // top cutout
        final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
        doReturn(getDisplayCutoutForRotation(Insets.of(0, 1, 0, 0), bounds))
                .when(mScreenDecorations).getCutout();

        mScreenDecorations.start();

        final ScreenDecorations.DisplayCutoutView cutoutView =
                mScreenDecorations.mCutoutViews[BOUNDS_POSITION_TOP];
        spyOn(cutoutView);
        doReturn(mDisplay).when(cutoutView).getDisplay();
        doReturn(mDisplayMode).when(mDisplay).getMode();

        mScreenDecorations.mDisplayListener.onDisplayChanged(1);

        verify(cutoutView, times(1)).onDisplayChanged(1);
    }

    private void setupResources(int radius, int radiusTop, int radiusBottom, int roundedPadding,
            boolean multipleRadius, boolean fillCutout, boolean privacyDot) {
        mContext.getOrCreateTestableResources().addOverride(