Merge "Fixed listeners were unexpectedly unregistered when device rotated" into rvc-dev am: 9a02e30990

Change-Id: I28af5ca4281f60785792bc7d573416ffc32036c2
This commit is contained in:
Automerger Merge Worker
2020-02-27 03:15:39 +00:00
2 changed files with 56 additions and 4 deletions

View File

@@ -99,7 +99,8 @@ public class ScreenDecorations extends SystemUI implements Tunable {
private static final boolean DEBUG_COLOR = DEBUG_SCREENSHOT_ROUNDED_CORNERS; private static final boolean DEBUG_COLOR = DEBUG_SCREENSHOT_ROUNDED_CORNERS;
private DisplayManager mDisplayManager; private DisplayManager mDisplayManager;
private boolean mIsRegistered; @VisibleForTesting
protected boolean mIsRegistered;
private final BroadcastDispatcher mBroadcastDispatcher; private final BroadcastDispatcher mBroadcastDispatcher;
private final Handler mMainHandler; private final Handler mMainHandler;
private final TunerService mTunerService; private final TunerService mTunerService;
@@ -168,7 +169,6 @@ public class ScreenDecorations extends SystemUI implements Tunable {
mDisplayManager = mContext.getSystemService(DisplayManager.class); mDisplayManager = mContext.getSystemService(DisplayManager.class);
updateRoundedCornerRadii(); updateRoundedCornerRadii();
setupDecorations(); setupDecorations();
mDisplayListener = new DisplayManager.DisplayListener() { mDisplayListener = new DisplayManager.DisplayListener() {
@Override @Override
public void onDisplayAdded(int displayId) { public void onDisplayAdded(int displayId) {
@@ -230,7 +230,10 @@ public class ScreenDecorations extends SystemUI implements Tunable {
removeAllOverlays(); removeAllOverlays();
} }
if (hasOverlays() && !mIsRegistered) { if (hasOverlays()) {
if (mIsRegistered) {
return;
}
DisplayMetrics metrics = new DisplayMetrics(); DisplayMetrics metrics = new DisplayMetrics();
mDisplayManager.getDisplay(DEFAULT_DISPLAY).getMetrics(metrics); mDisplayManager.getDisplay(DEFAULT_DISPLAY).getMetrics(metrics);
mDensity = metrics.density; mDensity = metrics.density;
@@ -271,7 +274,8 @@ public class ScreenDecorations extends SystemUI implements Tunable {
return mContext.getDisplay().getCutout(); return mContext.getDisplay().getCutout();
} }
private boolean hasOverlays() { @VisibleForTesting
boolean hasOverlays() {
if (mOverlays == null) { if (mOverlays == null) {
return false; return false;
} }

View File

@@ -456,4 +456,52 @@ public class ScreenDecorationsTest extends SysuiTestCase {
assertThat(rectsToRegion(Collections.singletonList(rect)).getBounds(), is(rect)); 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));
}
} }