Merge "Add privacy dot flag for SystemUI" into sc-v2-dev

This commit is contained in:
TreeHugger Robot
2021-09-30 04:25:35 +00:00
committed by Android (Google) Code Review
5 changed files with 540 additions and 146 deletions

View File

@@ -706,4 +706,8 @@
<item>@drawable/rounded_corner_bottom</item> <item>@drawable/rounded_corner_bottom</item>
<item>@drawable/rounded_corner_bottom_secondary</item> <item>@drawable/rounded_corner_bottom_secondary</item>
</array> </array>
<!-- Flag to enable privacy dot views, it shall be true for normal case -->
<bool name="config_enablePrivacyDot">true</bool>
</resources> </resources>

View File

@@ -160,6 +160,7 @@ public class ScreenDecorations extends SystemUI implements Tunable {
private Handler mHandler; private Handler mHandler;
private boolean mPendingRotationChange; private boolean mPendingRotationChange;
private boolean mIsRoundedCornerMultipleRadius; private boolean mIsRoundedCornerMultipleRadius;
private boolean mIsPrivacyDotEnabled;
private int mStatusBarHeightPortrait; private int mStatusBarHeightPortrait;
private int mStatusBarHeightLandscape; private int mStatusBarHeightLandscape;
private Drawable mRoundedCornerDrawable; private Drawable mRoundedCornerDrawable;
@@ -253,6 +254,7 @@ public class ScreenDecorations extends SystemUI implements Tunable {
mRotation = mContext.getDisplay().getRotation(); mRotation = mContext.getDisplay().getRotation();
mDisplayUniqueId = mContext.getDisplay().getUniqueId(); mDisplayUniqueId = mContext.getDisplay().getUniqueId();
mIsRoundedCornerMultipleRadius = isRoundedCornerMultipleRadius(mContext, mDisplayUniqueId); mIsRoundedCornerMultipleRadius = isRoundedCornerMultipleRadius(mContext, mDisplayUniqueId);
mIsPrivacyDotEnabled = mContext.getResources().getBoolean(R.bool.config_enablePrivacyDot);
mWindowManager = mContext.getSystemService(WindowManager.class); mWindowManager = mContext.getSystemService(WindowManager.class);
mDisplayManager = mContext.getSystemService(DisplayManager.class); mDisplayManager = mContext.getSystemService(DisplayManager.class);
updateRoundedCornerDrawable(); updateRoundedCornerDrawable();
@@ -312,24 +314,24 @@ public class ScreenDecorations extends SystemUI implements Tunable {
} }
private void setupDecorations() { private void setupDecorations() {
if (hasRoundedCorners() || shouldDrawCutout()) { if (hasRoundedCorners() || shouldDrawCutout() || mIsPrivacyDotEnabled) {
updateStatusBarHeight(); updateStatusBarHeight();
final DisplayCutout cutout = getCutout(); final DisplayCutout cutout = getCutout();
final Rect[] bounds = cutout == null ? null : cutout.getBoundingRectsAll();
int rotatedPos;
for (int i = 0; i < BOUNDS_POSITION_LENGTH; i++) { for (int i = 0; i < BOUNDS_POSITION_LENGTH; i++) {
rotatedPos = getBoundPositionFromRotation(i, mRotation); if (shouldShowCutout(i, cutout) || shouldShowRoundedCorner(i, cutout)
if ((bounds != null && !bounds[rotatedPos].isEmpty()) || shouldShowPrivacyDot(i, cutout)) {
|| shouldShowRoundedCorner(i)) { createOverlay(i, cutout);
createOverlay(i);
} else { } else {
removeOverlay(i); removeOverlay(i);
} }
} }
// Overlays have been created, send the dots to the controller
//TODO: need a better way to do this if (mIsPrivacyDotEnabled) {
mDotViewController.initialize( // Overlays have been created, send the dots to the controller
mTopLeftDot, mTopRightDot, mBottomLeftDot, mBottomRightDot); //TODO: need a better way to do this
mDotViewController.initialize(
mTopLeftDot, mTopRightDot, mBottomLeftDot, mBottomRightDot);
}
} else { } else {
removeAllOverlays(); removeAllOverlays();
} }
@@ -416,7 +418,7 @@ public class ScreenDecorations extends SystemUI implements Tunable {
mOverlays[pos] = null; mOverlays[pos] = null;
} }
private void createOverlay(@BoundsPosition int pos) { private void createOverlay(@BoundsPosition int pos, @Nullable DisplayCutout cutout) {
if (mOverlays == null) { if (mOverlays == null) {
mOverlays = new View[BOUNDS_POSITION_LENGTH]; mOverlays = new View[BOUNDS_POSITION_LENGTH];
} }
@@ -437,7 +439,7 @@ public class ScreenDecorations extends SystemUI implements Tunable {
mOverlays[pos].setAlpha(0); mOverlays[pos].setAlpha(0);
mOverlays[pos].setForceDarkAllowed(false); mOverlays[pos].setForceDarkAllowed(false);
updateView(pos); updateView(pos, cutout);
mWindowManager.addView(mOverlays[pos], getWindowLayoutParams(pos)); mWindowManager.addView(mOverlays[pos], getWindowLayoutParams(pos));
@@ -461,34 +463,19 @@ public class ScreenDecorations extends SystemUI implements Tunable {
* Allow overrides for top/bottom positions * Allow overrides for top/bottom positions
*/ */
private View overlayForPosition(@BoundsPosition int pos) { private View overlayForPosition(@BoundsPosition int pos) {
switch (pos) { final int layoutId = (pos == BOUNDS_POSITION_LEFT || pos == BOUNDS_POSITION_TOP)
case BOUNDS_POSITION_TOP: ? R.layout.rounded_corners_top : R.layout.rounded_corners_bottom;
case BOUNDS_POSITION_LEFT: return LayoutInflater.from(mContext).inflate(layoutId, null);
View top = LayoutInflater.from(mContext)
.inflate(R.layout.rounded_corners_top, null);
mTopLeftDot = top.findViewById(R.id.privacy_dot_left_container);
mTopRightDot = top.findViewById(R.id.privacy_dot_right_container);
return top;
case BOUNDS_POSITION_BOTTOM:
case BOUNDS_POSITION_RIGHT:
View bottom = LayoutInflater.from(mContext)
.inflate(R.layout.rounded_corners_bottom, null);
mBottomLeftDot = bottom.findViewById(R.id.privacy_dot_left_container);
mBottomRightDot = bottom.findViewById(R.id.privacy_dot_right_container);
return bottom;
default:
throw new IllegalArgumentException("Unknown bounds position");
}
} }
private void updateView(@BoundsPosition int pos) { private void updateView(@BoundsPosition int pos, @Nullable DisplayCutout cutout) {
if (mOverlays == null || mOverlays[pos] == null) { if (mOverlays == null || mOverlays[pos] == null) {
return; return;
} }
// update rounded corner view rotation // update rounded corner view rotation
updateRoundedCornerView(pos, R.id.left); updateRoundedCornerView(pos, R.id.left, cutout);
updateRoundedCornerView(pos, R.id.right); updateRoundedCornerView(pos, R.id.right, cutout);
updateRoundedCornerSize(mRoundedDefault, mRoundedDefaultTop, mRoundedDefaultBottom); updateRoundedCornerSize(mRoundedDefault, mRoundedDefaultTop, mRoundedDefaultBottom);
updateRoundedCornerImageView(); updateRoundedCornerImageView();
@@ -496,6 +483,8 @@ public class ScreenDecorations extends SystemUI implements Tunable {
if (mCutoutViews != null && mCutoutViews[pos] != null) { if (mCutoutViews != null && mCutoutViews[pos] != null) {
mCutoutViews[pos].setRotation(mRotation); mCutoutViews[pos].setRotation(mRotation);
} }
updatePrivacyDotView(pos, cutout);
} }
@VisibleForTesting @VisibleForTesting
@@ -671,11 +660,12 @@ public class ScreenDecorations extends SystemUI implements Tunable {
if (mOverlays != null) { if (mOverlays != null) {
updateLayoutParams(); updateLayoutParams();
final DisplayCutout cutout = getCutout();
for (int i = 0; i < BOUNDS_POSITION_LENGTH; i++) { for (int i = 0; i < BOUNDS_POSITION_LENGTH; i++) {
if (mOverlays[i] == null) { if (mOverlays[i] == null) {
continue; continue;
} }
updateView(i); updateView(i, cutout);
} }
} }
} }
@@ -807,13 +797,14 @@ public class ScreenDecorations extends SystemUI implements Tunable {
return drawable; return drawable;
} }
private void updateRoundedCornerView(@BoundsPosition int pos, int id) { private void updateRoundedCornerView(@BoundsPosition int pos, int id,
@Nullable DisplayCutout cutout) {
final View rounded = mOverlays[pos].findViewById(id); final View rounded = mOverlays[pos].findViewById(id);
if (rounded == null) { if (rounded == null) {
return; return;
} }
rounded.setVisibility(View.GONE); rounded.setVisibility(View.GONE);
if (shouldShowRoundedCorner(pos)) { if (shouldShowRoundedCorner(pos, cutout)) {
final int gravity = getRoundedCornerGravity(pos, id == R.id.left); final int gravity = getRoundedCornerGravity(pos, id == R.id.left);
((FrameLayout.LayoutParams) rounded.getLayoutParams()).gravity = gravity; ((FrameLayout.LayoutParams) rounded.getLayoutParams()).gravity = gravity;
setRoundedCornerOrientation(rounded, gravity); setRoundedCornerOrientation(rounded, gravity);
@@ -821,6 +812,26 @@ public class ScreenDecorations extends SystemUI implements Tunable {
} }
} }
private void updatePrivacyDotView(@BoundsPosition int pos, @Nullable DisplayCutout cutout) {
final ViewGroup viewGroup = (ViewGroup) mOverlays[pos];
final View left = viewGroup.findViewById(R.id.privacy_dot_left_container);
final View right = viewGroup.findViewById(R.id.privacy_dot_right_container);
if (shouldShowPrivacyDot(pos, cutout)) {
// TODO (b/201481944) Privacy Dots pos and var are wrong with long side cutout enable
if (pos == BOUNDS_POSITION_LEFT || pos == BOUNDS_POSITION_TOP) {
mTopLeftDot = left;
mTopRightDot = right;
} else {
mBottomLeftDot = left;
mBottomRightDot = right;
}
} else {
viewGroup.removeView(left);
viewGroup.removeView(right);
}
}
private int getRoundedCornerGravity(@BoundsPosition int pos, boolean isStart) { private int getRoundedCornerGravity(@BoundsPosition int pos, boolean isStart) {
final int rotatedPos = getBoundPositionFromRotation(pos, mRotation); final int rotatedPos = getBoundPositionFromRotation(pos, mRotation);
switch (rotatedPos) { switch (rotatedPos) {
@@ -872,12 +883,8 @@ public class ScreenDecorations extends SystemUI implements Tunable {
|| mIsRoundedCornerMultipleRadius; || mIsRoundedCornerMultipleRadius;
} }
private boolean shouldShowRoundedCorner(@BoundsPosition int pos) { private boolean isDefaultShownOverlayPos(@BoundsPosition int pos,
if (!hasRoundedCorners()) { @Nullable DisplayCutout cutout) {
return false;
}
DisplayCutout cutout = getCutout();
// for cutout is null or cutout with only waterfall. // for cutout is null or cutout with only waterfall.
final boolean emptyBoundsOrWaterfall = cutout == null || cutout.isBoundsEmpty(); final boolean emptyBoundsOrWaterfall = cutout == null || cutout.isBoundsEmpty();
// Shows rounded corner on left and right overlays only when there is no top or bottom // Shows rounded corner on left and right overlays only when there is no top or bottom
@@ -892,6 +899,21 @@ public class ScreenDecorations extends SystemUI implements Tunable {
} }
} }
private boolean shouldShowRoundedCorner(@BoundsPosition int pos,
@Nullable DisplayCutout cutout) {
return hasRoundedCorners() && isDefaultShownOverlayPos(pos, cutout);
}
private boolean shouldShowPrivacyDot(@BoundsPosition int pos, @Nullable DisplayCutout cutout) {
return mIsPrivacyDotEnabled && isDefaultShownOverlayPos(pos, cutout);
}
private boolean shouldShowCutout(@BoundsPosition int pos, @Nullable DisplayCutout cutout) {
final Rect[] bounds = cutout == null ? null : cutout.getBoundingRectsAll();
final int rotatedPos = getBoundPositionFromRotation(pos, mRotation);
return (bounds != null && !bounds[rotatedPos].isEmpty());
}
private boolean shouldDrawCutout() { private boolean shouldDrawCutout() {
return shouldDrawCutout(mContext); return shouldDrawCutout(mContext);
} }

View File

@@ -72,6 +72,7 @@ public class KeyguardStatusBarView extends RelativeLayout {
private boolean mKeyguardUserSwitcherEnabled; private boolean mKeyguardUserSwitcherEnabled;
private final UserManager mUserManager; private final UserManager mUserManager;
private boolean mIsPrivacyDotEnabled;
private int mSystemIconsSwitcherHiddenExpandedMargin; private int mSystemIconsSwitcherHiddenExpandedMargin;
private int mStatusBarPaddingEnd; private int mStatusBarPaddingEnd;
private int mMinDotWidth; private int mMinDotWidth;
@@ -112,7 +113,7 @@ public class KeyguardStatusBarView extends RelativeLayout {
mCutoutSpace = findViewById(R.id.cutout_space_view); mCutoutSpace = findViewById(R.id.cutout_space_view);
mStatusIconArea = findViewById(R.id.status_icon_area); mStatusIconArea = findViewById(R.id.status_icon_area);
mStatusIconContainer = findViewById(R.id.statusIcons); mStatusIconContainer = findViewById(R.id.statusIcons);
mIsPrivacyDotEnabled = mContext.getResources().getBoolean(R.bool.config_enablePrivacyDot);
loadDimens(); loadDimens();
} }
@@ -270,9 +271,10 @@ public class KeyguardStatusBarView extends RelativeLayout {
mDisplayCutout, cornerCutoutMargins, mRoundedCornerPadding); mDisplayCutout, cornerCutoutMargins, mRoundedCornerPadding);
// consider privacy dot space // consider privacy dot space
final int minLeft = isLayoutRtl() ? Math.max(mMinDotWidth, mPadding.first) : mPadding.first; final int minLeft = (isLayoutRtl() && mIsPrivacyDotEnabled)
final int minRight = isLayoutRtl() ? mPadding.second : ? Math.max(mMinDotWidth, mPadding.first) : mPadding.first;
Math.max(mMinDotWidth, mPadding.second); final int minRight = (!isLayoutRtl() && mIsPrivacyDotEnabled)
? Math.max(mMinDotWidth, mPadding.second) : mPadding.second;
setPadding(minLeft, waterfallTop, minRight, 0); setPadding(minLeft, waterfallTop, minRight, 0);
} }

View File

@@ -70,6 +70,9 @@ class StatusBarContentInsetsProvider @Inject constructor(
// (e.g. network displays) // (e.g. network displays)
private val insetsCache = LruCache<CacheKey, Rect>(MAX_CACHE_SIZE) private val insetsCache = LruCache<CacheKey, Rect>(MAX_CACHE_SIZE)
private val listeners = mutableSetOf<StatusBarContentInsetsChangedListener>() private val listeners = mutableSetOf<StatusBarContentInsetsChangedListener>()
private val isPrivacyDotEnabled: Boolean by lazy(LazyThreadSafetyMode.PUBLICATION) {
context.resources.getBoolean(R.bool.config_enablePrivacyDot)
}
init { init {
configurationController.addCallback(this) configurationController.addCallback(this)
@@ -152,8 +155,9 @@ class StatusBarContentInsetsProvider @Inject constructor(
val isRtl = rotatedResources.configuration.layoutDirection == LAYOUT_DIRECTION_RTL val isRtl = rotatedResources.configuration.layoutDirection == LAYOUT_DIRECTION_RTL
val roundedCornerPadding = rotatedResources val roundedCornerPadding = rotatedResources
.getDimensionPixelSize(R.dimen.rounded_corner_content_padding) .getDimensionPixelSize(R.dimen.rounded_corner_content_padding)
val minDotWidth = rotatedResources val minDotWidth = if (isPrivacyDotEnabled)
.getDimensionPixelSize(R.dimen.ongoing_appops_dot_min_padding) rotatedResources.getDimensionPixelSize(R.dimen.ongoing_appops_dot_min_padding)
else 0
val minLeft: Int val minLeft: Int
val minRight: Int val minRight: Int

View File

@@ -28,11 +28,13 @@ import static com.google.common.truth.Truth.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@@ -151,27 +153,155 @@ public class ScreenDecorationsTest extends SysuiTestCase {
reset(mTunerService); reset(mTunerService);
} }
private void verifyRoundedCornerViewsVisibility(
@DisplayCutout.BoundsPosition final int overlayId,
@View.Visibility final int visibility) {
final View overlay = mScreenDecorations.mOverlays[overlayId];
final View left = overlay.findViewById(R.id.left);
final View right = overlay.findViewById(R.id.right);
assertNotNull(left);
assertNotNull(right);
assertThat(left.getVisibility()).isEqualTo(visibility);
assertThat(right.getVisibility()).isEqualTo(visibility);
}
private void verifyTopDotViewsNullable(final boolean isAssertNull) {
if (isAssertNull) {
assertNull(mScreenDecorations.mTopLeftDot);
assertNull(mScreenDecorations.mTopRightDot);
} else {
assertNotNull(mScreenDecorations.mTopLeftDot);
assertNotNull(mScreenDecorations.mTopRightDot);
}
}
private void verifyBottomDotViewsNullable(final boolean isAssertNull) {
if (isAssertNull) {
assertNull(mScreenDecorations.mBottomLeftDot);
assertNull(mScreenDecorations.mBottomRightDot);
} else {
assertNotNull(mScreenDecorations.mBottomLeftDot);
assertNotNull(mScreenDecorations.mBottomRightDot);
}
}
private void verifyDotViewsNullable(final boolean isAssertNull) {
verifyTopDotViewsNullable(isAssertNull);
verifyBottomDotViewsNullable(isAssertNull);
}
private void verifyTopDotViewsVisibility(@View.Visibility final int visibility) {
verifyTopDotViewsNullable(false);
assertThat(mScreenDecorations.mTopLeftDot.getVisibility()).isEqualTo(visibility);
assertThat(mScreenDecorations.mTopRightDot.getVisibility()).isEqualTo(visibility);
}
private void verifyBottomDotViewsVisibility(@View.Visibility final int visibility) {
verifyBottomDotViewsNullable(false);
assertThat(mScreenDecorations.mBottomLeftDot.getVisibility()).isEqualTo(visibility);
assertThat(mScreenDecorations.mBottomRightDot.getVisibility()).isEqualTo(visibility);
}
private void verifyDotViewsVisibility(@View.Visibility final int visibility) {
verifyTopDotViewsVisibility(visibility);
verifyBottomDotViewsVisibility(visibility);
}
private void verifyOverlaysExistAndAdded(final boolean left, final boolean top,
final boolean right, final boolean bottom) {
if (left || top || right || bottom) {
assertNotNull(mScreenDecorations.mOverlays);
} else {
verify(mWindowManager, never()).addView(any(), any());
return;
}
if (left) {
assertNotNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]);
verify(mWindowManager, times(1))
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]), any());
} else {
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]);
}
if (top) {
assertNotNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]);
verify(mWindowManager, times(1))
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]), any());
} else {
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]);
}
if (right) {
assertNotNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT]);
verify(mWindowManager, times(1))
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT]), any());
} else {
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT]);
}
if (bottom) {
assertNotNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]);
verify(mWindowManager, times(1))
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]), any());
} else {
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]);
}
}
@Test @Test
public void testNoRounding_NoCutout() { public void testNoRounding_NoCutout_NoPrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, 0 /* roundedPadding */, false /* multipleRadius */,
false /* fillCutout */); false /* fillCutout */, false /* privacyDot */);
// no cutout // no cutout
doReturn(null).when(mScreenDecorations).getCutout(); doReturn(null).when(mScreenDecorations).getCutout();
mScreenDecorations.start(); mScreenDecorations.start();
// No views added. // No views added.
verify(mWindowManager, never()).addView(any(), any()); verifyOverlaysExistAndAdded(false, false, false, false);
// No Tuners tuned. // No Tuners tuned.
verify(mTunerService, never()).addTunable(any(), any()); verify(mTunerService, never()).addTunable(any(), any());
// No dot controller init
verify(mDotViewController, never()).initialize(any(), any(), any(), any());
} }
@Test @Test
public void testRounding_NoCutout() { public void testNoRounding_NoCutout_PrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */,
false /* fillCutout */, true /* privacyDot */);
// no cutout
doReturn(null).when(mScreenDecorations).getCutout();
mScreenDecorations.start();
// Top and bottom windows are created for privacy dot.
// Left and right window should be null.
verifyOverlaysExistAndAdded(false, true, false, true);
// Rounded corner views shall not exist
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_TOP, View.GONE);
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_BOTTOM, View.GONE);
// Privacy dots shall exist but invisible
verifyDotViewsVisibility(View.INVISIBLE);
// One tunable.
verify(mTunerService, times(1)).addTunable(any(), any());
// Dot controller init
verify(mDotViewController, times(1)).initialize(
isA(View.class), isA(View.class), isA(View.class), isA(View.class));
}
@Test
public void testRounding_NoCutout_NoPrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */, 20 /* roundedPadding */, false /* multipleRadius */,
false /* fillCutout */); false /* fillCutout */, false /* privacyDot */);
// no cutout // no cutout
doReturn(null).when(mScreenDecorations).getCutout(); doReturn(null).when(mScreenDecorations).getCutout();
@@ -179,17 +309,49 @@ public class ScreenDecorationsTest extends SysuiTestCase {
mScreenDecorations.start(); mScreenDecorations.start();
// Top and bottom windows are created for rounded corners. // Top and bottom windows are created for rounded corners.
verify(mWindowManager, times(1))
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]), any());
verify(mWindowManager, times(1))
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]), any());
// Left and right window should be null. // Left and right window should be null.
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]); verifyOverlaysExistAndAdded(false, true, false, true);
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT]);
// Rounded corner views shall exist
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_TOP, View.VISIBLE);
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_BOTTOM, View.VISIBLE);
// Privacy dots shall not exist
verifyDotViewsNullable(true);
// One tunable. // One tunable.
verify(mTunerService, times(1)).addTunable(any(), any()); verify(mTunerService, times(1)).addTunable(any(), any());
// No dot controller init
verify(mDotViewController, never()).initialize(any(), any(), any(), any());
}
@Test
public void testRounding_NoCutout_PrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */,
false /* fillCutout */, true /* privacyDot */);
// no cutout
doReturn(null).when(mScreenDecorations).getCutout();
mScreenDecorations.start();
// Top and bottom windows are created for rounded corners.
// Left and right window should be null.
verifyOverlaysExistAndAdded(false, true, false, true);
// Rounded corner views shall exist
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_TOP, View.VISIBLE);
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_BOTTOM, View.VISIBLE);
// Privacy dots shall exist but invisible
verifyDotViewsVisibility(View.INVISIBLE);
// One tunable.
verify(mTunerService, times(1)).addTunable(any(), any());
// Dot controller init
verify(mDotViewController, times(1)).initialize(
isA(View.class), isA(View.class), isA(View.class), isA(View.class));
} }
@Test @Test
@@ -197,7 +359,7 @@ public class ScreenDecorationsTest extends SysuiTestCase {
final Point testRadiusPoint = new Point(1, 1); final Point testRadiusPoint = new Point(1, 1);
setupResources(1 /* radius */, 1 /* radiusTop */, 1 /* radiusBottom */, setupResources(1 /* radius */, 1 /* radiusTop */, 1 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, 0 /* roundedPadding */, false /* multipleRadius */,
false /* fillCutout */); false /* fillCutout */, true /* privacyDot */);
// no cutout // no cutout
doReturn(null).when(mScreenDecorations).getCutout(); doReturn(null).when(mScreenDecorations).getCutout();
@@ -213,7 +375,7 @@ public class ScreenDecorationsTest extends SysuiTestCase {
final int testTopRadius = 1; final int testTopRadius = 1;
final int testBottomRadius = 5; final int testBottomRadius = 5;
setupResources(testTopRadius, testTopRadius, testBottomRadius, 0 /* roundedPadding */, setupResources(testTopRadius, testTopRadius, testBottomRadius, 0 /* roundedPadding */,
false /* multipleRadius */, false /* fillCutout */); false /* multipleRadius */, false /* fillCutout */, true /* privacyDot */);
// no cutout // no cutout
doReturn(null).when(mScreenDecorations).getCutout(); doReturn(null).when(mScreenDecorations).getCutout();
@@ -242,7 +404,7 @@ public class ScreenDecorationsTest extends SysuiTestCase {
final int testTopRadius = 1; final int testTopRadius = 1;
final int testBottomRadius = 5; final int testBottomRadius = 5;
setupResources(testTopRadius, testTopRadius, testBottomRadius, 0 /* roundedPadding */, setupResources(testTopRadius, testTopRadius, testBottomRadius, 0 /* roundedPadding */,
false /* multipleRadius */, false /* fillCutout */); false /* multipleRadius */, false /* fillCutout */, true /* privacyDot */);
// left cutout // left cutout
final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null}; final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null};
@@ -278,29 +440,32 @@ public class ScreenDecorationsTest extends SysuiTestCase {
} }
@Test @Test
public void testRoundingMultipleRadius_NoCutout() { public void testRoundingMultipleRadius_NoCutout_NoPrivacyDot() {
final VectorDrawable d = (VectorDrawable) mContext.getDrawable(R.drawable.rounded); final VectorDrawable d = (VectorDrawable) mContext.getDrawable(R.drawable.rounded);
final Point multipleRadiusSize = new Point(d.getIntrinsicWidth(), d.getIntrinsicHeight()); final Point multipleRadiusSize = new Point(d.getIntrinsicWidth(), d.getIntrinsicHeight());
setupResources(9999 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(9999 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
9999 /* roundedPadding */, true /* multipleRadius */, 9999 /* roundedPadding */, true /* multipleRadius */,
false /* fillCutout */); false /* fillCutout */, false /* privacyDot */);
// no cutout // no cutout
doReturn(null).when(mScreenDecorations).getCutout(); doReturn(null).when(mScreenDecorations).getCutout();
mScreenDecorations.start(); mScreenDecorations.start();
// Top and bottom windows are created for rounded corners. // Top and bottom windows are created for rounded corners.
verify(mWindowManager, times(1))
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]), any());
verify(mWindowManager, times(1))
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]), any());
// Left and right window should be null. // Left and right window should be null.
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]); verifyOverlaysExistAndAdded(false, true, false, true);
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT]);
// Rounded corner views shall exist
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_TOP, View.VISIBLE);
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_BOTTOM, View.VISIBLE);
// Privacy dots shall not exist
verifyDotViewsNullable(true);
// One tunable. // One tunable.
verify(mTunerService, times(1)).addTunable(any(), any()); verify(mTunerService, times(1)).addTunable(any(), any());
// No dot controller init
verify(mDotViewController, never()).initialize(any(), any(), any(), any());
// Size of corner view should exactly match max(width, height) of R.drawable.rounded // Size of corner view should exactly match max(width, height) of R.drawable.rounded
assertThat(mScreenDecorations.mRoundedDefault).isEqualTo(multipleRadiusSize); assertThat(mScreenDecorations.mRoundedDefault).isEqualTo(multipleRadiusSize);
@@ -309,10 +474,45 @@ public class ScreenDecorationsTest extends SysuiTestCase {
} }
@Test @Test
public void testNoRounding_CutoutShortEdge() { public void testRoundingMultipleRadius_NoCutout_PrivacyDot() {
final VectorDrawable d = (VectorDrawable) mContext.getDrawable(R.drawable.rounded);
final Point multipleRadiusSize = new Point(d.getIntrinsicWidth(), d.getIntrinsicHeight());
setupResources(9999 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
9999 /* roundedPadding */, true /* multipleRadius */,
false /* fillCutout */, true /* privacyDot */);
// no cutout
doReturn(null).when(mScreenDecorations).getCutout();
mScreenDecorations.start();
// Top and bottom windows are created for rounded corners.
// Left and right window should be null.
verifyOverlaysExistAndAdded(false, true, false, true);
// Rounded corner views shall exist
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_TOP, View.VISIBLE);
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_BOTTOM, View.VISIBLE);
// Privacy dots shall exist but invisible
verifyDotViewsVisibility(View.INVISIBLE);
// One tunable.
verify(mTunerService, times(1)).addTunable(any(), any());
// Dot controller init
verify(mDotViewController, times(1)).initialize(
isA(View.class), isA(View.class), isA(View.class), isA(View.class));
// Size of corner view should exactly match max(width, height) of R.drawable.rounded
assertThat(mScreenDecorations.mRoundedDefault).isEqualTo(multipleRadiusSize);
assertThat(mScreenDecorations.mRoundedDefaultTop).isEqualTo(multipleRadiusSize);
assertThat(mScreenDecorations.mRoundedDefaultBottom).isEqualTo(multipleRadiusSize);
}
@Test
public void testNoRounding_CutoutShortEdge_NoPrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, 0 /* roundedPadding */, false /* multipleRadius */,
true /* fillCutout */); true /* fillCutout */, false /* privacyDot */);
// top cutout // top cutout
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null}; final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
@@ -321,21 +521,53 @@ public class ScreenDecorationsTest extends SysuiTestCase {
mScreenDecorations.start(); mScreenDecorations.start();
// Top window is created for top cutout. // Top window is created for top cutout.
verify(mWindowManager, times(1)) // Bottom, left, or right window should be null.
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]), any()); verifyOverlaysExistAndAdded(false, true, false, false);
// Bottom window should be null.
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]); // Privacy dots shall not exist because of no privacy
// Left window should be null. verifyDotViewsNullable(true);
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]);
// Right window should be null. // No dot controller init
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT]); verify(mDotViewController, never()).initialize(any(), any(), any(), any());
} }
@Test @Test
public void testNoRounding_CutoutLongEdge() { public void testNoRounding_CutoutShortEdge_PrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, 0 /* roundedPadding */, false /* multipleRadius */,
true /* fillCutout */); true /* fillCutout */, true /* 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();
// Top window is created for top cutout.
// Bottom window is created for privacy dot.
// Left or right window should be null.
verifyOverlaysExistAndAdded(false, true, false, true);
// Top rounded corner views shall exist because of cutout
// but be gone because of no rounded corner
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_TOP, View.GONE);
// Bottom rounded corner views shall exist because of privacy dot
// but be gone because of no rounded corner
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_BOTTOM, View.GONE);
// Privacy dots shall exist but invisible
verifyDotViewsVisibility(View.INVISIBLE);
// Dot controller init
verify(mDotViewController, times(1)).initialize(
isA(View.class), isA(View.class), isA(View.class), isA(View.class));
}
@Test
public void testNoRounding_CutoutLongEdge_NoPrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */,
true /* fillCutout */, false /* privacyDot */);
// left cutout // left cutout
final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null}; final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null};
@@ -344,21 +576,50 @@ public class ScreenDecorationsTest extends SysuiTestCase {
mScreenDecorations.start(); mScreenDecorations.start();
// Left window is created for left cutout. // Left window is created for left cutout.
verify(mWindowManager, times(1)) // Bottom, top, or right window should be null.
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]), any()); verifyOverlaysExistAndAdded(true, false, false, false);
// Bottom window should be null.
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]); // Left rounded corner views shall exist because of cutout
// Top window should be null. // but be gone because of no rounded corner
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]); verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_LEFT, View.GONE);
// Right window should be null.
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT]); // Top privacy dots shall not exist because of no privacy
verifyDotViewsNullable(true);
// No dot controller init
verify(mDotViewController, never()).initialize(any(), any(), any(), any());
} }
@Test @Test
public void testRounding_CutoutShortEdge() { public void testNoRounding_CutoutLongEdge_PrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */,
true /* fillCutout */, true /* privacyDot */);
// left cutout
final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null};
doReturn(getDisplayCutoutForRotation(Insets.of(1, 0, 0, 0), bounds))
.when(mScreenDecorations).getCutout();
mScreenDecorations.start();
// Left window is created for left cutout.
// Right window is created for privacy.
// Bottom, or top window should be null.
verifyOverlaysExistAndAdded(true, false, true, false);
// Privacy dots shall exist but invisible
verifyDotViewsVisibility(View.INVISIBLE);
// Dot controller init
verify(mDotViewController, times(1)).initialize(
isA(View.class), isA(View.class), isA(View.class), isA(View.class));
}
@Test
public void testRounding_CutoutShortEdge_NoPrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */, 20 /* roundedPadding */, false /* multipleRadius */,
true /* fillCutout */); true /* fillCutout */, false /* privacyDot */);
// top cutout // top cutout
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null}; final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
@@ -367,22 +628,55 @@ public class ScreenDecorationsTest extends SysuiTestCase {
mScreenDecorations.start(); mScreenDecorations.start();
// Top window is created for rounded corner and top cutout. // Top window is created for rounded corner and top cutout.
verify(mWindowManager, times(1))
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]), any());
// Bottom window is created for rounded corner. // Bottom window is created for rounded corner.
verify(mWindowManager, times(1)) // Left, or right window should be null.
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]), any()); verifyOverlaysExistAndAdded(false, true, false, true);
// Left window should be null.
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]); // Rounded corner views shall exist
// Right window should be null. verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_TOP, View.VISIBLE);
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT]); verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_BOTTOM, View.VISIBLE);
// Top privacy dots shall not exist because of no privacy dot
verifyDotViewsNullable(true);
// No dot controller init
verify(mDotViewController, never()).initialize(any(), any(), any(), any());
} }
@Test @Test
public void testRounding_CutoutLongEdge() { public void testRounding_CutoutShortEdge_PrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */, 20 /* roundedPadding */, false /* multipleRadius */,
true /* fillCutout */); true /* fillCutout */, true /* 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();
// Top window is created for rounded corner and top cutout.
// Bottom window is created for rounded corner.
// Left, or right window should be null.
verifyOverlaysExistAndAdded(false, true, false, true);
// Rounded corner views shall exist
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_TOP, View.VISIBLE);
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_BOTTOM, View.VISIBLE);
// Top privacy dots shall exist but invisible
verifyDotViewsVisibility(View.INVISIBLE);
// Dot controller init
verify(mDotViewController, times(1)).initialize(
isA(View.class), isA(View.class), isA(View.class), isA(View.class));
}
@Test
public void testRounding_CutoutLongEdge_NoPrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */,
true /* fillCutout */, false /* privacyDot */);
// left cutout // left cutout
final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null}; final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null};
@@ -391,22 +685,34 @@ public class ScreenDecorationsTest extends SysuiTestCase {
mScreenDecorations.start(); mScreenDecorations.start();
// Left window is created for rounded corner and left cutout. // Left window is created for rounded corner and left cutout.
verify(mWindowManager, times(1))
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]), any());
// Right window is created for rounded corner. // Right window is created for rounded corner.
verify(mWindowManager, times(1)) // Top, or bottom window should be null.
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT]), any()); verifyOverlaysExistAndAdded(true, false, true, false);
// Top window should be null.
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]);
// Bottom window should be null.
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]);
} }
@Test @Test
public void testRounding_CutoutShortAndLongEdge() { public void testRounding_CutoutLongEdge_PrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */, 20 /* roundedPadding */, false /* multipleRadius */,
true /* fillCutout */); true /* fillCutout */, true /* privacyDot */);
// left cutout
final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null};
doReturn(getDisplayCutoutForRotation(Insets.of(1, 0, 0, 0), bounds))
.when(mScreenDecorations).getCutout();
mScreenDecorations.start();
// Left window is created for rounded corner, left cutout, and privacy.
// Right window is created for rounded corner and privacy dot.
// Top, or bottom window should be null.
verifyOverlaysExistAndAdded(true, false, true, false);
}
@Test
public void testRounding_CutoutShortAndLongEdge_NoPrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */,
true /* fillCutout */, false /* privacyDot */);
// top and left cutout // top and left cutout
final Rect[] bounds = {new Rect(0, 50, 1, 60), new Rect(9, 0, 10, 1), null, null}; final Rect[] bounds = {new Rect(0, 50, 1, 60), new Rect(9, 0, 10, 1), null, null};
@@ -415,23 +721,36 @@ public class ScreenDecorationsTest extends SysuiTestCase {
mScreenDecorations.start(); mScreenDecorations.start();
// Top window is created for rounded corner and top cutout. // Top window is created for rounded corner and top cutout.
verify(mWindowManager, times(1))
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]), any());
// Bottom window is created for rounded corner. // Bottom window is created for rounded corner.
verify(mWindowManager, times(1))
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]), any());
// Left window is created for left cutout. // Left window is created for left cutout.
verify(mWindowManager, times(1))
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]), any());
// Right window should be null. // Right window should be null.
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT]); verifyOverlaysExistAndAdded(true, true, false, true);
} }
@Test @Test
public void testNoRounding_SwitchFrom_ShortEdgeCutout_To_LongCutout() { public void testRounding_CutoutShortAndLongEdge_PrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */,
true /* fillCutout */, true /* privacyDot */);
// top and left cutout
final Rect[] bounds = {new Rect(0, 50, 1, 60), new Rect(9, 0, 10, 1), null, null};
doReturn(getDisplayCutoutForRotation(Insets.of(1, 1, 0, 0), bounds))
.when(mScreenDecorations).getCutout();
mScreenDecorations.start();
// Top window is created for rounded corner and top cutout.
// Bottom window is created for rounded corner.
// Left window is created for left cutout.
// Right window should be null.
verifyOverlaysExistAndAdded(true, true, false, true);
}
@Test
public void testNoRounding_SwitchFrom_ShortEdgeCutout_To_LongCutout_NoPrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, 0 /* roundedPadding */, false /* multipleRadius */,
true /* fillCutout */); true /* fillCutout */, false /* privacyDot */);
// Set to short edge cutout(top). // Set to short edge cutout(top).
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null}; final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
@@ -439,11 +758,7 @@ public class ScreenDecorationsTest extends SysuiTestCase {
.when(mScreenDecorations).getCutout(); .when(mScreenDecorations).getCutout();
mScreenDecorations.start(); mScreenDecorations.start();
verify(mWindowManager, times(1)) verifyOverlaysExistAndAdded(false, true, false, false);
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]), any());
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT]);
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]);
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]);
// Switch to long edge cutout(left). // Switch to long edge cutout(left).
final Rect[] newBounds = {new Rect(0, 50, 1, 60), null, null, null}; final Rect[] newBounds = {new Rect(0, 50, 1, 60), null, null, null};
@@ -451,18 +766,37 @@ public class ScreenDecorationsTest extends SysuiTestCase {
.when(mScreenDecorations).getCutout(); .when(mScreenDecorations).getCutout();
mScreenDecorations.onConfigurationChanged(new Configuration()); mScreenDecorations.onConfigurationChanged(new Configuration());
verify(mWindowManager, times(1)) verifyOverlaysExistAndAdded(true, false, false, false);
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]), any());
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT]);
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]);
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]);
} }
@Test @Test
public void testDelayedCutout() { public void testNoRounding_SwitchFrom_ShortEdgeCutout_To_LongCutout_PrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, 0 /* roundedPadding */, false /* multipleRadius */,
false /* fillCutout */); true /* fillCutout */, true /* privacyDot */);
// Set to short edge cutout(top).
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();
verifyOverlaysExistAndAdded(false, true, false, true);
// Switch to long edge cutout(left).
final Rect[] newBounds = {new Rect(0, 50, 1, 60), null, null, null};
doReturn(getDisplayCutoutForRotation(Insets.of(1, 0, 0, 0), newBounds))
.when(mScreenDecorations).getCutout();
mScreenDecorations.onConfigurationChanged(new Configuration());
verifyOverlaysExistAndAdded(true, false, true, false);
}
@Test
public void testDelayedCutout_NoPrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */,
false /* fillCutout */, false /* privacyDot */);
// top cutout // top cutout
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null}; final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
@@ -478,11 +812,38 @@ public class ScreenDecorationsTest extends SysuiTestCase {
mScreenDecorations.onConfigurationChanged(new Configuration()); mScreenDecorations.onConfigurationChanged(new Configuration());
// Only top windows should be added. // Only top windows should be added.
verify(mWindowManager, times(1)) verifyOverlaysExistAndAdded(false, true, false, false);
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]), any()); }
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]);
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]); @Test
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT]); public void testDelayedCutout_PrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */,
false /* fillCutout */, true /* 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();
// Both top and bottom windows should be added because of privacy dot,
// but their visibility shall be gone because of no rounding.
verifyOverlaysExistAndAdded(false, true, false, true);
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_TOP, View.GONE);
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_BOTTOM, View.GONE);
when(mContext.getResources().getBoolean(
com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout))
.thenReturn(true);
mScreenDecorations.onConfigurationChanged(new Configuration());
assertNotNull(mScreenDecorations.mOverlays);
// Both top and bottom windows should be added because of privacy dot,
// but their visibility shall be gone because of no rounding.
verifyOverlaysExistAndAdded(false, true, false, true);
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_TOP, View.GONE);
verifyRoundedCornerViewsVisibility(BOUNDS_POSITION_BOTTOM, View.GONE);
} }
@Test @Test
@@ -496,7 +857,7 @@ public class ScreenDecorationsTest extends SysuiTestCase {
public void testUpdateRoundedCorners() { public void testUpdateRoundedCorners() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, 0 /* roundedPadding */, false /* multipleRadius */,
false /* fillCutout */); false /* fillCutout */, true /* privacyDot */);
mScreenDecorations.start(); mScreenDecorations.start();
assertEquals(mScreenDecorations.mRoundedDefault, new Point(20, 20)); assertEquals(mScreenDecorations.mRoundedDefault, new Point(20, 20));
@@ -511,7 +872,7 @@ public class ScreenDecorationsTest extends SysuiTestCase {
public void testOnlyRoundedCornerRadiusTop() { public void testOnlyRoundedCornerRadiusTop() {
setupResources(0 /* radius */, 10 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 10 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, 0 /* roundedPadding */, false /* multipleRadius */,
false /* fillCutout */); false /* fillCutout */, true /* privacyDot */);
mScreenDecorations.start(); mScreenDecorations.start();
assertEquals(new Point(0, 0), mScreenDecorations.mRoundedDefault); assertEquals(new Point(0, 0), mScreenDecorations.mRoundedDefault);
@@ -523,7 +884,7 @@ public class ScreenDecorationsTest extends SysuiTestCase {
public void testOnlyRoundedCornerRadiusBottom() { public void testOnlyRoundedCornerRadiusBottom() {
setupResources(0 /* radius */, 0 /* radiusTop */, 20 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 20 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, 0 /* roundedPadding */, false /* multipleRadius */,
false /* fillCutout */); false /* fillCutout */, true /* privacyDot */);
mScreenDecorations.start(); mScreenDecorations.start();
assertEquals(new Point(0, 0), mScreenDecorations.mRoundedDefault); assertEquals(new Point(0, 0), mScreenDecorations.mRoundedDefault);
@@ -531,7 +892,6 @@ public class ScreenDecorationsTest extends SysuiTestCase {
assertEquals(new Point(20, 20), mScreenDecorations.mRoundedDefaultBottom); assertEquals(new Point(20, 20), mScreenDecorations.mRoundedDefaultBottom);
} }
@Test @Test
public void testBoundingRectsToRegion() throws Exception { public void testBoundingRectsToRegion() throws Exception {
Rect rect = new Rect(1, 2, 3, 4); Rect rect = new Rect(1, 2, 3, 4);
@@ -588,7 +948,7 @@ public class ScreenDecorationsTest extends SysuiTestCase {
} }
private void setupResources(int radius, int radiusTop, int radiusBottom, int roundedPadding, private void setupResources(int radius, int radiusTop, int radiusBottom, int roundedPadding,
boolean multipleRadius, boolean fillCutout) { boolean multipleRadius, boolean fillCutout, boolean privacyDot) {
mContext.getOrCreateTestableResources().addOverride( mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.array.config_displayUniqueIdArray, com.android.internal.R.array.config_displayUniqueIdArray,
new String[]{}); new String[]{});
@@ -625,6 +985,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
R.bool.config_roundedCornerMultipleRadius, multipleRadius); R.bool.config_roundedCornerMultipleRadius, multipleRadius);
mContext.getOrCreateTestableResources().addOverride( mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, fillCutout); com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, fillCutout);
mContext.getOrCreateTestableResources().addOverride(
R.bool.config_enablePrivacyDot, privacyDot);
} }
private DisplayCutout getDisplayCutoutForRotation(Insets safeInsets, Rect[] cutoutBounds) { private DisplayCutout getDisplayCutoutForRotation(Insets safeInsets, Rect[] cutoutBounds) {