Merge "Fixed listeners were unexpectedly unregistered when device rotated" into rvc-dev am: 9a02e30990 am: 25ef7c55ba
Change-Id: I5243bf277a6feda67825a1c4335fd3de5cc02562
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user