Merge "Fix ScreenDecorationsTest failures" into sc-v2-dev
This commit is contained in:
@@ -568,7 +568,8 @@ public class ScreenDecorations extends SystemUI implements Tunable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getBoundPositionFromRotation(@BoundsPosition int pos, int rotation) {
|
@VisibleForTesting
|
||||||
|
static int getBoundPositionFromRotation(@BoundsPosition int pos, int rotation) {
|
||||||
return (pos - rotation) < 0
|
return (pos - rotation) < 0
|
||||||
? pos - rotation + DisplayCutout.BOUNDS_POSITION_LENGTH
|
? pos - rotation + DisplayCutout.BOUNDS_POSITION_LENGTH
|
||||||
: pos - rotation;
|
: pos - rotation;
|
||||||
@@ -963,7 +964,8 @@ public class ScreenDecorations extends SystemUI implements Tunable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isTopRoundedCorner(@BoundsPosition int pos, int id) {
|
@VisibleForTesting
|
||||||
|
boolean isTopRoundedCorner(@BoundsPosition int pos, int id) {
|
||||||
switch (pos) {
|
switch (pos) {
|
||||||
case BOUNDS_POSITION_LEFT:
|
case BOUNDS_POSITION_LEFT:
|
||||||
case BOUNDS_POSITION_RIGHT:
|
case BOUNDS_POSITION_RIGHT:
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ package com.android.systemui;
|
|||||||
import static android.view.Display.DEFAULT_DISPLAY;
|
import static android.view.Display.DEFAULT_DISPLAY;
|
||||||
import static android.view.DisplayCutout.BOUNDS_POSITION_BOTTOM;
|
import static android.view.DisplayCutout.BOUNDS_POSITION_BOTTOM;
|
||||||
import static android.view.DisplayCutout.BOUNDS_POSITION_LEFT;
|
import static android.view.DisplayCutout.BOUNDS_POSITION_LEFT;
|
||||||
|
import static android.view.DisplayCutout.BOUNDS_POSITION_LENGTH;
|
||||||
import static android.view.DisplayCutout.BOUNDS_POSITION_RIGHT;
|
import static android.view.DisplayCutout.BOUNDS_POSITION_RIGHT;
|
||||||
import static android.view.DisplayCutout.BOUNDS_POSITION_TOP;
|
import static android.view.DisplayCutout.BOUNDS_POSITION_TOP;
|
||||||
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY;
|
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY;
|
||||||
@@ -53,6 +54,7 @@ import android.os.Handler;
|
|||||||
import android.testing.AndroidTestingRunner;
|
import android.testing.AndroidTestingRunner;
|
||||||
import android.testing.TestableLooper;
|
import android.testing.TestableLooper;
|
||||||
import android.testing.TestableLooper.RunWithLooper;
|
import android.testing.TestableLooper.RunWithLooper;
|
||||||
|
import android.util.RotationUtils;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.DisplayCutout;
|
import android.view.DisplayCutout;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -243,31 +245,36 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
false /* multipleRadius */, false /* fillCutout */);
|
false /* multipleRadius */, false /* fillCutout */);
|
||||||
|
|
||||||
// left cutout
|
// left cutout
|
||||||
doReturn(new DisplayCutout(
|
final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null};
|
||||||
Insets.of(0, 10, 0, 0),
|
doReturn(getDisplayCutoutForRotation(Insets.of(1, 0, 0, 0), bounds))
|
||||||
new Rect(0, 200, 1, 210),
|
.when(mScreenDecorations).getCutout();
|
||||||
ZERO_RECT,
|
|
||||||
ZERO_RECT,
|
|
||||||
ZERO_RECT,
|
|
||||||
Insets.NONE)).when(mScreenDecorations).getCutout();
|
|
||||||
|
|
||||||
mScreenDecorations.start();
|
mScreenDecorations.start();
|
||||||
|
final Point topRadius = new Point(testTopRadius, testTopRadius);
|
||||||
|
final Point bottomRadius = new Point(testBottomRadius, testBottomRadius);
|
||||||
View leftRoundedCorner =
|
View leftRoundedCorner =
|
||||||
mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT].findViewById(R.id.left);
|
mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT].findViewById(R.id.left);
|
||||||
|
boolean isTop = mScreenDecorations.isTopRoundedCorner(BOUNDS_POSITION_LEFT, R.id.left);
|
||||||
|
verify(mScreenDecorations, atLeastOnce())
|
||||||
|
.setSize(leftRoundedCorner, isTop ? topRadius : bottomRadius);
|
||||||
|
|
||||||
View rightRoundedCorner =
|
View rightRoundedCorner =
|
||||||
mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT].findViewById(R.id.right);
|
mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT].findViewById(R.id.right);
|
||||||
|
isTop = mScreenDecorations.isTopRoundedCorner(BOUNDS_POSITION_LEFT, R.id.right);
|
||||||
verify(mScreenDecorations, atLeastOnce())
|
verify(mScreenDecorations, atLeastOnce())
|
||||||
.setSize(leftRoundedCorner, new Point(testTopRadius, testTopRadius));
|
.setSize(rightRoundedCorner, isTop ? topRadius : bottomRadius);
|
||||||
verify(mScreenDecorations, atLeastOnce())
|
|
||||||
.setSize(rightRoundedCorner, new Point(testBottomRadius, testBottomRadius));
|
|
||||||
leftRoundedCorner =
|
leftRoundedCorner =
|
||||||
mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT].findViewById(R.id.left);
|
mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT].findViewById(R.id.left);
|
||||||
|
isTop = mScreenDecorations.isTopRoundedCorner(BOUNDS_POSITION_RIGHT, R.id.left);
|
||||||
|
verify(mScreenDecorations, atLeastOnce())
|
||||||
|
.setSize(leftRoundedCorner, isTop ? topRadius : bottomRadius);
|
||||||
|
|
||||||
rightRoundedCorner =
|
rightRoundedCorner =
|
||||||
mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT].findViewById(R.id.right);
|
mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT].findViewById(R.id.right);
|
||||||
|
isTop = mScreenDecorations.isTopRoundedCorner(BOUNDS_POSITION_RIGHT, R.id.right);
|
||||||
verify(mScreenDecorations, atLeastOnce())
|
verify(mScreenDecorations, atLeastOnce())
|
||||||
.setSize(leftRoundedCorner, new Point(testTopRadius, testTopRadius));
|
.setSize(rightRoundedCorner, isTop ? topRadius : bottomRadius);
|
||||||
verify(mScreenDecorations, atLeastOnce())
|
|
||||||
.setSize(rightRoundedCorner, new Point(testBottomRadius, testBottomRadius));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -308,13 +315,9 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
true /* fillCutout */);
|
true /* fillCutout */);
|
||||||
|
|
||||||
// top cutout
|
// top cutout
|
||||||
doReturn(new DisplayCutout(
|
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
|
||||||
Insets.of(0, 10, 0, 0),
|
doReturn(getDisplayCutoutForRotation(Insets.of(0, 1, 0, 0), bounds))
|
||||||
ZERO_RECT,
|
.when(mScreenDecorations).getCutout();
|
||||||
new Rect(9, 0, 10, 1),
|
|
||||||
ZERO_RECT,
|
|
||||||
ZERO_RECT,
|
|
||||||
Insets.NONE)).when(mScreenDecorations).getCutout();
|
|
||||||
|
|
||||||
mScreenDecorations.start();
|
mScreenDecorations.start();
|
||||||
// Top window is created for top cutout.
|
// Top window is created for top cutout.
|
||||||
@@ -335,13 +338,9 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
true /* fillCutout */);
|
true /* fillCutout */);
|
||||||
|
|
||||||
// left cutout
|
// left cutout
|
||||||
doReturn(new DisplayCutout(
|
final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null};
|
||||||
Insets.of(0, 10, 0, 0),
|
doReturn(getDisplayCutoutForRotation(Insets.of(1, 0, 0, 0), bounds))
|
||||||
new Rect(0, 200, 1, 210),
|
.when(mScreenDecorations).getCutout();
|
||||||
ZERO_RECT,
|
|
||||||
ZERO_RECT,
|
|
||||||
ZERO_RECT,
|
|
||||||
Insets.NONE)).when(mScreenDecorations).getCutout();
|
|
||||||
|
|
||||||
mScreenDecorations.start();
|
mScreenDecorations.start();
|
||||||
// Left window is created for left cutout.
|
// Left window is created for left cutout.
|
||||||
@@ -362,19 +361,15 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
true /* fillCutout */);
|
true /* fillCutout */);
|
||||||
|
|
||||||
// top cutout
|
// top cutout
|
||||||
doReturn(new DisplayCutout(
|
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
|
||||||
Insets.of(0, 10, 0, 0),
|
doReturn(getDisplayCutoutForRotation(Insets.of(0, 1, 0, 0), bounds))
|
||||||
ZERO_RECT,
|
.when(mScreenDecorations).getCutout();
|
||||||
new Rect(9, 0, 10, 1),
|
|
||||||
ZERO_RECT,
|
|
||||||
ZERO_RECT,
|
|
||||||
Insets.NONE)).when(mScreenDecorations).getCutout();
|
|
||||||
|
|
||||||
mScreenDecorations.start();
|
mScreenDecorations.start();
|
||||||
// Top window is created for rouned corner and top cutout.
|
// Top window is created for rounded corner and top cutout.
|
||||||
verify(mWindowManager, times(1))
|
verify(mWindowManager, times(1))
|
||||||
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]), any());
|
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]), any());
|
||||||
// Bottom window is created for rouned corner.
|
// Bottom window is created for rounded corner.
|
||||||
verify(mWindowManager, times(1))
|
verify(mWindowManager, times(1))
|
||||||
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]), any());
|
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]), any());
|
||||||
// Left window should be null.
|
// Left window should be null.
|
||||||
@@ -390,19 +385,15 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
true /* fillCutout */);
|
true /* fillCutout */);
|
||||||
|
|
||||||
// left cutout
|
// left cutout
|
||||||
doReturn(new DisplayCutout(
|
final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null};
|
||||||
Insets.of(0, 10, 0, 0),
|
doReturn(getDisplayCutoutForRotation(Insets.of(1, 0, 0, 0), bounds))
|
||||||
new Rect(0, 200, 1, 210),
|
.when(mScreenDecorations).getCutout();
|
||||||
ZERO_RECT,
|
|
||||||
ZERO_RECT,
|
|
||||||
ZERO_RECT,
|
|
||||||
Insets.NONE)).when(mScreenDecorations).getCutout();
|
|
||||||
|
|
||||||
mScreenDecorations.start();
|
mScreenDecorations.start();
|
||||||
// Left window is created for rouned corner and left cutout.
|
// Left window is created for rounded corner and left cutout.
|
||||||
verify(mWindowManager, times(1))
|
verify(mWindowManager, times(1))
|
||||||
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]), any());
|
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]), any());
|
||||||
// Right window is created for rouned corner.
|
// Right window is created for rounded corner.
|
||||||
verify(mWindowManager, times(1))
|
verify(mWindowManager, times(1))
|
||||||
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT]), any());
|
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT]), any());
|
||||||
// Top window should be null.
|
// Top window should be null.
|
||||||
@@ -418,19 +409,15 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
true /* fillCutout */);
|
true /* fillCutout */);
|
||||||
|
|
||||||
// top and left cutout
|
// top and left cutout
|
||||||
doReturn(new DisplayCutout(
|
final Rect[] bounds = {new Rect(0, 50, 1, 60), new Rect(9, 0, 10, 1), null, null};
|
||||||
Insets.of(0, 10, 0, 0),
|
doReturn(getDisplayCutoutForRotation(Insets.of(1, 1, 0, 0), bounds))
|
||||||
new Rect(0, 200, 1, 210),
|
.when(mScreenDecorations).getCutout();
|
||||||
new Rect(9, 0, 10, 1),
|
|
||||||
ZERO_RECT,
|
|
||||||
ZERO_RECT,
|
|
||||||
Insets.NONE)).when(mScreenDecorations).getCutout();
|
|
||||||
|
|
||||||
mScreenDecorations.start();
|
mScreenDecorations.start();
|
||||||
// Top window is created for rouned corner and top cutout.
|
// Top window is created for rounded corner and top cutout.
|
||||||
verify(mWindowManager, times(1))
|
verify(mWindowManager, times(1))
|
||||||
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]), any());
|
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP]), any());
|
||||||
// Bottom window is created for rouned corner.
|
// Bottom window is created for rounded corner.
|
||||||
verify(mWindowManager, times(1))
|
verify(mWindowManager, times(1))
|
||||||
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]), any());
|
.addView(eq(mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM]), any());
|
||||||
// Left window is created for left cutout.
|
// Left window is created for left cutout.
|
||||||
@@ -447,13 +434,9 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
true /* fillCutout */);
|
true /* fillCutout */);
|
||||||
|
|
||||||
// Set to short edge cutout(top).
|
// Set to short edge cutout(top).
|
||||||
doReturn(new DisplayCutout(
|
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
|
||||||
Insets.of(0, 10, 0, 0),
|
doReturn(getDisplayCutoutForRotation(Insets.of(0, 1, 0, 0), bounds))
|
||||||
ZERO_RECT,
|
.when(mScreenDecorations).getCutout();
|
||||||
new Rect(9, 0, 10, 1),
|
|
||||||
ZERO_RECT,
|
|
||||||
ZERO_RECT,
|
|
||||||
Insets.NONE)).when(mScreenDecorations).getCutout();
|
|
||||||
|
|
||||||
mScreenDecorations.start();
|
mScreenDecorations.start();
|
||||||
verify(mWindowManager, times(1))
|
verify(mWindowManager, times(1))
|
||||||
@@ -463,14 +446,9 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]);
|
assertNull(mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT]);
|
||||||
|
|
||||||
// Switch to long edge cutout(left).
|
// Switch to long edge cutout(left).
|
||||||
// left cutout
|
final Rect[] newBounds = {new Rect(0, 50, 1, 60), null, null, null};
|
||||||
doReturn(new DisplayCutout(
|
doReturn(getDisplayCutoutForRotation(Insets.of(1, 0, 0, 0), newBounds))
|
||||||
Insets.of(0, 10, 0, 0),
|
.when(mScreenDecorations).getCutout();
|
||||||
new Rect(0, 200, 1, 210),
|
|
||||||
ZERO_RECT,
|
|
||||||
ZERO_RECT,
|
|
||||||
ZERO_RECT,
|
|
||||||
Insets.NONE)).when(mScreenDecorations).getCutout();
|
|
||||||
|
|
||||||
mScreenDecorations.onConfigurationChanged(new Configuration());
|
mScreenDecorations.onConfigurationChanged(new Configuration());
|
||||||
verify(mWindowManager, times(1))
|
verify(mWindowManager, times(1))
|
||||||
@@ -487,13 +465,9 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
false /* fillCutout */);
|
false /* fillCutout */);
|
||||||
|
|
||||||
// top cutout
|
// top cutout
|
||||||
doReturn(new DisplayCutout(
|
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
|
||||||
Insets.of(0, 10, 0, 0),
|
doReturn(getDisplayCutoutForRotation(Insets.of(0, 1, 0, 0), bounds))
|
||||||
ZERO_RECT,
|
.when(mScreenDecorations).getCutout();
|
||||||
new Rect(9, 0, 10, 1),
|
|
||||||
ZERO_RECT,
|
|
||||||
ZERO_RECT,
|
|
||||||
Insets.NONE)).when(mScreenDecorations).getCutout();
|
|
||||||
|
|
||||||
mScreenDecorations.start();
|
mScreenDecorations.start();
|
||||||
assertNull(mScreenDecorations.mOverlays);
|
assertNull(mScreenDecorations.mOverlays);
|
||||||
@@ -652,4 +626,19 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
mContext.getOrCreateTestableResources().addOverride(
|
mContext.getOrCreateTestableResources().addOverride(
|
||||||
com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, fillCutout);
|
com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, fillCutout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DisplayCutout getDisplayCutoutForRotation(Insets safeInsets, Rect[] cutoutBounds) {
|
||||||
|
final int rotation = mContext.getDisplay().getRotation();
|
||||||
|
final Insets insets = RotationUtils.rotateInsets(safeInsets, rotation);
|
||||||
|
final Rect[] sorted = new Rect[BOUNDS_POSITION_LENGTH];
|
||||||
|
for (int i = 0; i < BOUNDS_POSITION_LENGTH; i++) {
|
||||||
|
final int rotatedPos = ScreenDecorations.getBoundPositionFromRotation(i, rotation);
|
||||||
|
if (cutoutBounds[i] != null) {
|
||||||
|
RotationUtils.rotateBounds(cutoutBounds[i], new Rect(0, 0, 100, 200), rotation);
|
||||||
|
}
|
||||||
|
sorted[rotatedPos] = cutoutBounds[i];
|
||||||
|
}
|
||||||
|
return new DisplayCutout(insets, sorted[BOUNDS_POSITION_LEFT], sorted[BOUNDS_POSITION_TOP],
|
||||||
|
sorted[BOUNDS_POSITION_RIGHT], sorted[BOUNDS_POSITION_BOTTOM]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user