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

Commit 9a02e309 authored by Shawn Lin's avatar Shawn Lin Committed by Android (Google) Code Review
Browse files

Merge "Fixed listeners were unexpectedly unregistered when device rotated" into rvc-dev

parents 57ee1071 014c6876
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -99,7 +99,8 @@ public class ScreenDecorations extends SystemUI implements Tunable {
    private static final boolean DEBUG_COLOR = DEBUG_SCREENSHOT_ROUNDED_CORNERS;

    private DisplayManager mDisplayManager;
    private boolean mIsRegistered;
    @VisibleForTesting
    protected boolean mIsRegistered;
    private final BroadcastDispatcher mBroadcastDispatcher;
    private final Handler mMainHandler;
    private final TunerService mTunerService;
@@ -168,7 +169,6 @@ public class ScreenDecorations extends SystemUI implements Tunable {
        mDisplayManager = mContext.getSystemService(DisplayManager.class);
        updateRoundedCornerRadii();
        setupDecorations();

        mDisplayListener = new DisplayManager.DisplayListener() {
            @Override
            public void onDisplayAdded(int displayId) {
@@ -230,7 +230,10 @@ public class ScreenDecorations extends SystemUI implements Tunable {
            removeAllOverlays();
        }

        if (hasOverlays() && !mIsRegistered) {
        if (hasOverlays()) {
            if (mIsRegistered) {
                return;
            }
            DisplayMetrics metrics = new DisplayMetrics();
            mDisplayManager.getDisplay(DEFAULT_DISPLAY).getMetrics(metrics);
            mDensity = metrics.density;
@@ -271,7 +274,8 @@ public class ScreenDecorations extends SystemUI implements Tunable {
        return mContext.getDisplay().getCutout();
    }

    private boolean hasOverlays() {
    @VisibleForTesting
    boolean hasOverlays() {
        if (mOverlays == null) {
            return false;
        }
+48 −0
Original line number Diff line number Diff line
@@ -456,4 +456,52 @@ public class ScreenDecorationsTest extends SysuiTestCase {
        assertThat(rectsToRegion(Collections.singletonList(rect)).getBounds(), is(rect));
    }

    @Test
    public void testRegistration_From_NoOverlay_To_HasOverlays() {
        doReturn(false).when(mScreenDecorations).hasOverlays();
        mScreenDecorations.start();
        verify(mTunerService, times(0)).addTunable(any(), any());
        verify(mTunerService, times(1)).removeTunable(any());
        assertThat(mScreenDecorations.mIsRegistered, is(false));
        reset(mTunerService);

        doReturn(true).when(mScreenDecorations).hasOverlays();
        mScreenDecorations.onConfigurationChanged(new Configuration());
        verify(mTunerService, times(1)).addTunable(any(), any());
        verify(mTunerService, times(0)).removeTunable(any());
        assertThat(mScreenDecorations.mIsRegistered, is(true));
    }

    @Test
    public void testRegistration_From_HasOverlays_To_HasOverlays() {
        doReturn(true).when(mScreenDecorations).hasOverlays();

        mScreenDecorations.start();
        verify(mTunerService, times(1)).addTunable(any(), any());
        verify(mTunerService, times(0)).removeTunable(any());
        assertThat(mScreenDecorations.mIsRegistered, is(true));
        reset(mTunerService);

        mScreenDecorations.onConfigurationChanged(new Configuration());
        verify(mTunerService, times(0)).addTunable(any(), any());
        verify(mTunerService, times(0)).removeTunable(any());
        assertThat(mScreenDecorations.mIsRegistered, is(true));
    }

    @Test
    public void testRegistration_From_HasOverlays_To_NoOverlay() {
        doReturn(true).when(mScreenDecorations).hasOverlays();

        mScreenDecorations.start();
        verify(mTunerService, times(1)).addTunable(any(), any());
        verify(mTunerService, times(0)).removeTunable(any());
        assertThat(mScreenDecorations.mIsRegistered, is(true));
        reset(mTunerService);

        doReturn(false).when(mScreenDecorations).hasOverlays();
        mScreenDecorations.onConfigurationChanged(new Configuration());
        verify(mTunerService, times(0)).addTunable(any(), any());
        verify(mTunerService, times(1)).removeTunable(any());
        assertThat(mScreenDecorations.mIsRegistered, is(false));
    }
}