summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/ScreenDecorHwcLayer.kt30
-rw-r--r--packages/SystemUI/src/com/android/systemui/ScreenDecorations.java23
-rw-r--r--packages/SystemUI/src/com/android/systemui/decor/RoundedCornerDecorProviderFactory.kt7
-rw-r--r--packages/SystemUI/src/com/android/systemui/decor/RoundedCornerResDelegate.kt75
-rw-r--r--packages/SystemUI/tests/res/drawable/rounded3px.xml24
-rw-r--r--packages/SystemUI/tests/res/drawable/rounded4px.xml24
-rw-r--r--packages/SystemUI/tests/res/drawable/rounded5px.xml24
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/ScreenDecorHwcLayerTest.kt27
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java350
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/decor/RoundedCornerDecorProviderFactoryTest.kt20
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/decor/RoundedCornerResDelegateTest.kt163
11 files changed, 399 insertions, 368 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorHwcLayer.kt b/packages/SystemUI/src/com/android/systemui/ScreenDecorHwcLayer.kt
index 011881354e35..3641e1d52144 100644
--- a/packages/SystemUI/src/com/android/systemui/ScreenDecorHwcLayer.kt
+++ b/packages/SystemUI/src/com/android/systemui/ScreenDecorHwcLayer.kt
@@ -60,6 +60,8 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec
private val debugTransparentRegionPaint: Paint?
private val tempRect: Rect = Rect()
+ private var hasTopRoundedCorner = false
+ private var hasBottomRoundedCorner = false
private var roundedCornerTopSize = 0
private var roundedCornerBottomSize = 0
private var roundedCornerDrawableTop: Drawable? = null
@@ -300,7 +302,7 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec
}
private fun drawRoundedCorners(canvas: Canvas) {
- if (roundedCornerTopSize == 0 && roundedCornerBottomSize == 0) {
+ if (!hasTopRoundedCorner && !hasBottomRoundedCorner) {
return
}
var degree: Int
@@ -312,9 +314,11 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec
canvas.translate(
getRoundedCornerTranslationX(degree).toFloat(),
getRoundedCornerTranslationY(degree).toFloat())
- if (i == RoundedCorner.POSITION_TOP_LEFT || i == RoundedCorner.POSITION_TOP_RIGHT) {
+ if (hasTopRoundedCorner && (i == RoundedCorner.POSITION_TOP_LEFT ||
+ i == RoundedCorner.POSITION_TOP_RIGHT)) {
drawRoundedCorner(canvas, roundedCornerDrawableTop, roundedCornerTopSize)
- } else {
+ } else if (hasBottomRoundedCorner && (i == RoundedCorner.POSITION_BOTTOM_LEFT ||
+ i == RoundedCorner.POSITION_BOTTOM_RIGHT)) {
drawRoundedCorner(canvas, roundedCornerDrawableBottom, roundedCornerBottomSize)
}
canvas.restore()
@@ -366,14 +370,24 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec
}
/**
- * Update the rounded corner size.
+ * Update the rounded corner existence and size.
*/
- fun updateRoundedCornerSize(top: Int, bottom: Int) {
- if (roundedCornerTopSize == top && roundedCornerBottomSize == bottom) {
+ fun updateRoundedCornerExistenceAndSize(
+ hasTop: Boolean,
+ hasBottom: Boolean,
+ topSize: Int,
+ bottomSize: Int
+ ) {
+ if (hasTopRoundedCorner == hasTop &&
+ hasBottomRoundedCorner == hasBottom &&
+ roundedCornerBottomSize == bottomSize &&
+ roundedCornerBottomSize == bottomSize) {
return
}
- roundedCornerTopSize = top
- roundedCornerBottomSize = bottom
+ hasTopRoundedCorner = hasTop
+ hasBottomRoundedCorner = hasBottom
+ roundedCornerTopSize = topSize
+ roundedCornerBottomSize = bottomSize
updateRoundedCornerDrawableBounds()
// Use requestLayout() to trigger transparent region recalculated
diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
index 9b091018de9f..7cc738a4e437 100644
--- a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
+++ b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
@@ -132,9 +132,6 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
private final ThreadFactory mThreadFactory;
private final DecorProviderFactory mDotFactory;
- //TODO: These are piecemeal being updated to Points for now to support non-square rounded
- // corners. for now it is only supposed when reading the intrinsic size from the drawables with
- // mIsRoundedCornerMultipleRadius is set
@VisibleForTesting
protected RoundedCornerResDelegate mRoundedCornerResDelegate;
@VisibleForTesting
@@ -406,7 +403,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
if (mScreenDecorHwcLayer != null) {
updateHwLayerRoundedCornerDrawable();
- updateHwLayerRoundedCornerSize();
+ updateHwLayerRoundedCornerExistAndSize();
}
updateOverlayProviderViews();
@@ -699,7 +696,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
mScreenDecorHwcWindow.addView(mScreenDecorHwcLayer, new FrameLayout.LayoutParams(
MATCH_PARENT, MATCH_PARENT, Gravity.TOP | Gravity.START));
mWindowManager.addView(mScreenDecorHwcWindow, getHwcWindowLayoutParams());
- updateHwLayerRoundedCornerSize();
+ updateHwLayerRoundedCornerExistAndSize();
updateHwLayerRoundedCornerDrawable();
mScreenDecorHwcWindow.getViewTreeObserver().addOnPreDrawListener(
new ValidatingPreDrawListener(mScreenDecorHwcWindow));
@@ -961,7 +958,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
if (mScreenDecorHwcLayer != null) {
mScreenDecorHwcLayer.pendingRotationChange = false;
mScreenDecorHwcLayer.updateRotation(mRotation);
- updateHwLayerRoundedCornerSize();
+ updateHwLayerRoundedCornerExistAndSize();
updateHwLayerRoundedCornerDrawable();
}
updateLayoutParams();
@@ -1090,7 +1087,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
overlay.onReloadResAndMeasure(filterIds, mProviderRefreshToken, mRotation,
mDisplayUniqueId);
}
- updateHwLayerRoundedCornerSize();
+ updateHwLayerRoundedCornerExistAndSize();
});
}
@@ -1108,15 +1105,15 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
mScreenDecorHwcLayer.updateRoundedCornerDrawable(topDrawable, bottomDrawable);
}
- private void updateHwLayerRoundedCornerSize() {
+ private void updateHwLayerRoundedCornerExistAndSize() {
if (mScreenDecorHwcLayer == null) {
return;
}
-
- final int topWidth = mRoundedCornerResDelegate.getTopRoundedSize().getWidth();
- final int bottomWidth = mRoundedCornerResDelegate.getBottomRoundedSize().getWidth();
-
- mScreenDecorHwcLayer.updateRoundedCornerSize(topWidth, bottomWidth);
+ mScreenDecorHwcLayer.updateRoundedCornerExistenceAndSize(
+ mRoundedCornerResDelegate.getHasTop(),
+ mRoundedCornerResDelegate.getHasBottom(),
+ mRoundedCornerResDelegate.getTopRoundedSize().getWidth(),
+ mRoundedCornerResDelegate.getBottomRoundedSize().getWidth());
}
@VisibleForTesting
diff --git a/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerDecorProviderFactory.kt b/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerDecorProviderFactory.kt
index a4f7a586ab97..4f075da7aaa7 100644
--- a/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerDecorProviderFactory.kt
+++ b/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerDecorProviderFactory.kt
@@ -25,8 +25,7 @@ class RoundedCornerDecorProviderFactory(
override val hasProviders: Boolean
get() = roundedCornerResDelegate.run {
- // We don't consider isMultipleRadius here because it makes no sense if size is zero.
- topRoundedSize.width > 0 || bottomRoundedSize.width > 0
+ hasTop || hasBottom
}
override fun onDisplayUniqueIdChanged(displayUniqueId: String?) {
@@ -35,8 +34,8 @@ class RoundedCornerDecorProviderFactory(
override val providers: List<DecorProvider>
get() {
- val hasTop = roundedCornerResDelegate.topRoundedSize.width > 0
- val hasBottom = roundedCornerResDelegate.bottomRoundedSize.width > 0
+ val hasTop = roundedCornerResDelegate.hasTop
+ val hasBottom = roundedCornerResDelegate.hasBottom
return when {
hasTop && hasBottom -> listOf(
RoundedCornerDecorProviderImpl(
diff --git a/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerResDelegate.kt b/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerResDelegate.kt
index c2bab269d396..3ab2f0881807 100644
--- a/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerResDelegate.kt
+++ b/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerResDelegate.kt
@@ -37,10 +37,11 @@ class RoundedCornerResDelegate(
private var reloadToken: Int = 0
- var isMultipleRadius: Boolean = false
+ var hasTop: Boolean = false
private set
- private var roundedDrawable: Drawable? = null
+ var hasBottom: Boolean = false
+ private set
var topRoundedDrawable: Drawable? = null
private set
@@ -48,8 +49,6 @@ class RoundedCornerResDelegate(
var bottomRoundedDrawable: Drawable? = null
private set
- private var roundedSize = Size(0, 0)
-
var topRoundedSize = Size(0, 0)
private set
@@ -83,52 +82,31 @@ class RoundedCornerResDelegate(
private fun reloadRes() {
val configIdx = DisplayUtils.getDisplayUniqueIdConfigIndex(res, displayUniqueId)
- isMultipleRadius = getIsMultipleRadius(configIdx)
- roundedDrawable = getDrawable(
- displayConfigIndex = configIdx,
- arrayResId = R.array.config_roundedCornerDrawableArray,
- backupDrawableId = R.drawable.rounded
- )
+ val hasDefaultRadius = RoundedCorners.getRoundedCornerRadius(res, displayUniqueId) > 0
+ hasTop = hasDefaultRadius ||
+ (RoundedCorners.getRoundedCornerTopRadius(res, displayUniqueId) > 0)
+ hasBottom = hasDefaultRadius ||
+ (RoundedCorners.getRoundedCornerBottomRadius(res, displayUniqueId) > 0)
+
topRoundedDrawable = getDrawable(
displayConfigIndex = configIdx,
arrayResId = R.array.config_roundedCornerTopDrawableArray,
backupDrawableId = R.drawable.rounded_corner_top
- ) ?: roundedDrawable
+ )
bottomRoundedDrawable = getDrawable(
displayConfigIndex = configIdx,
arrayResId = R.array.config_roundedCornerBottomDrawableArray,
backupDrawableId = R.drawable.rounded_corner_bottom
- ) ?: roundedDrawable
+ )
}
private fun reloadMeasures(roundedSizeFactor: Int? = null) {
- // If config_roundedCornerMultipleRadius set as true, ScreenDecorations respect the
- // (width, height) size of drawable/rounded.xml instead of rounded_corner_radius
- if (isMultipleRadius) {
- roundedSize = Size(
- roundedDrawable?.intrinsicWidth ?: 0,
- roundedDrawable?.intrinsicHeight ?: 0)
- topRoundedDrawable?.let {
- topRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight)
- }
- bottomRoundedDrawable?.let {
- bottomRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight)
- }
- } else {
- val defaultRadius = RoundedCorners.getRoundedCornerRadius(res, displayUniqueId)
- val topRadius = RoundedCorners.getRoundedCornerTopRadius(res, displayUniqueId)
- val bottomRadius = RoundedCorners.getRoundedCornerBottomRadius(res, displayUniqueId)
- roundedSize = Size(defaultRadius, defaultRadius)
- topRoundedSize = Size(topRadius, topRadius)
- bottomRoundedSize = Size(bottomRadius, bottomRadius)
- }
-
- if (topRoundedSize.width == 0) {
- topRoundedSize = roundedSize
+ topRoundedDrawable?.let {
+ topRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight)
}
- if (bottomRoundedSize.width == 0) {
- bottomRoundedSize = roundedSize
+ bottomRoundedDrawable?.let {
+ bottomRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight)
}
if (roundedSizeFactor != null && roundedSizeFactor > 0) {
@@ -146,25 +124,6 @@ class RoundedCornerResDelegate(
reloadMeasures(factor)
}
- /**
- * Gets whether the rounded corners are multiple radii for current display.
- *
- * Loads the default config {@link R.bool#config_roundedCornerMultipleRadius} if
- * {@link com.android.internal.R.array#config_displayUniqueIdArray} is not set.
- */
- private fun getIsMultipleRadius(displayConfigIndex: Int): Boolean {
- val isMultipleRadius: Boolean
- res.obtainTypedArray(R.array.config_roundedCornerMultipleRadiusArray).let { array ->
- isMultipleRadius = if (displayConfigIndex >= 0 && displayConfigIndex < array.length()) {
- array.getBoolean(displayConfigIndex, false)
- } else {
- res.getBoolean(R.bool.config_roundedCornerMultipleRadius)
- }
- array.recycle()
- }
- return isMultipleRadius
- }
-
private fun getDrawable(
displayConfigIndex: Int,
@ArrayRes arrayResId: Int,
@@ -184,8 +143,8 @@ class RoundedCornerResDelegate(
override fun dump(pw: PrintWriter, args: Array<out String>) {
pw.println("RoundedCornerResDelegate state:")
- pw.println(" isMultipleRadius:$isMultipleRadius")
- pw.println(" roundedSize(w,h)=(${roundedSize.width},${roundedSize.height})")
+ pw.println(" hasTop=$hasTop")
+ pw.println(" hasBottom=$hasBottom")
pw.println(" topRoundedSize(w,h)=(${topRoundedSize.width},${topRoundedSize.height})")
pw.println(" bottomRoundedSize(w,h)=(${bottomRoundedSize.width}," +
"${bottomRoundedSize.height})")
diff --git a/packages/SystemUI/tests/res/drawable/rounded3px.xml b/packages/SystemUI/tests/res/drawable/rounded3px.xml
new file mode 100644
index 000000000000..5929a0dc6631
--- /dev/null
+++ b/packages/SystemUI/tests/res/drawable/rounded3px.xml
@@ -0,0 +1,24 @@
+<!--
+ ~ Copyright (C) 2022 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="3px"
+ android:height="3px"
+ android:viewportWidth="3"
+ android:viewportHeight="3">
+ <path
+ android:fillColor="#000000"
+ android:pathData="M8,0H0v8C0,3.6,3.6,0,8,0z" />
+</vector>
diff --git a/packages/SystemUI/tests/res/drawable/rounded4px.xml b/packages/SystemUI/tests/res/drawable/rounded4px.xml
new file mode 100644
index 000000000000..4c3d6020c70b
--- /dev/null
+++ b/packages/SystemUI/tests/res/drawable/rounded4px.xml
@@ -0,0 +1,24 @@
+<!--
+ ~ Copyright (C) 2022 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="4px"
+ android:height="4px"
+ android:viewportWidth="4"
+ android:viewportHeight="4">
+ <path
+ android:fillColor="#000000"
+ android:pathData="M8,0H0v8C0,3.6,3.6,0,8,0z" />
+</vector>
diff --git a/packages/SystemUI/tests/res/drawable/rounded5px.xml b/packages/SystemUI/tests/res/drawable/rounded5px.xml
new file mode 100644
index 000000000000..b7ec68b4d5e1
--- /dev/null
+++ b/packages/SystemUI/tests/res/drawable/rounded5px.xml
@@ -0,0 +1,24 @@
+<!--
+ ~ Copyright (C) 2022 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="5px"
+ android:height="5px"
+ android:viewportWidth="5"
+ android:viewportHeight="5">
+ <path
+ android:fillColor="#000000"
+ android:pathData="M8,0H0v8C0,3.6,3.6,0,8,0z" />
+</vector>
diff --git a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorHwcLayerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorHwcLayerTest.kt
index 95aa08dff379..054650bb8a75 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorHwcLayerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorHwcLayerTest.kt
@@ -85,37 +85,37 @@ class ScreenDecorHwcLayerTest : SysuiTestCase() {
@Test
fun testTransparentRegion_noCutout_noRoundedCorner_noProtection() {
- setupConfigs(null, 0, 0, RectF(), 0f)
+ setupConfigs(null, false, false, 0, 0, RectF(), 0f)
decorHwcLayer.calculateTransparentRect()
assertThat(decorHwcLayer.transparentRect)
- .isEqualTo(Rect(0, 0, decorHwcLayer.width, decorHwcLayer.height))
+ .isEqualTo(Rect(0, 0, decorHwcLayer.width, decorHwcLayer.height))
}
@Test
fun testTransparentRegion_onlyShortEdgeCutout() {
- setupConfigs(cutoutTop, 0, 0, RectF(), 0f)
+ setupConfigs(cutoutTop, false, false, 0, 0, RectF(), 0f)
decorHwcLayer.calculateTransparentRect()
assertThat(decorHwcLayer.transparentRect)
- .isEqualTo(Rect(0, cutoutSize, decorHwcLayer.width, decorHwcLayer.height))
+ .isEqualTo(Rect(0, cutoutSize, decorHwcLayer.width, decorHwcLayer.height))
}
@Test
fun testTransparentRegion_onlyLongEdgeCutout() {
- setupConfigs(cutoutRight, 0, 0, RectF(), 0f)
+ setupConfigs(cutoutRight, false, false, 0, 0, RectF(), 0f)
decorHwcLayer.calculateTransparentRect()
assertThat(decorHwcLayer.transparentRect)
- .isEqualTo(Rect(0, 0, decorHwcLayer.width - cutoutSize, decorHwcLayer.height))
+ .isEqualTo(Rect(0, 0, decorHwcLayer.width - cutoutSize, decorHwcLayer.height))
}
@Test
fun testTransparentRegion_onlyRoundedCorners() {
- setupConfigs(null, roundedSizeTop, roundedSizeBottom, RectF(), 0f)
+ setupConfigs(null, true, true, roundedSizeTop, roundedSizeBottom, RectF(), 0f)
decorHwcLayer.calculateTransparentRect()
@@ -126,7 +126,7 @@ class ScreenDecorHwcLayerTest : SysuiTestCase() {
@Test
fun testTransparentRegion_onlyCutoutProtection() {
- setupConfigs(null, 0, 0, RectF(48f, 1f, 52f, 5f), 0.5f)
+ setupConfigs(null, false, false, 0, 0, RectF(48f, 1f, 52f, 5f), 0.5f)
decorHwcLayer.calculateTransparentRect()
@@ -143,7 +143,8 @@ class ScreenDecorHwcLayerTest : SysuiTestCase() {
@Test
fun testTransparentRegion_hasShortEdgeCutout_hasRoundedCorner_hasCutoutProtection() {
- setupConfigs(cutoutTop, roundedSizeTop, roundedSizeBottom, RectF(48f, 1f, 52f, 5f), 1f)
+ setupConfigs(cutoutTop, true, true, roundedSizeTop, roundedSizeBottom,
+ RectF(48f, 1f, 52f, 5f), 1f)
decorHwcLayer.calculateTransparentRect()
@@ -153,7 +154,8 @@ class ScreenDecorHwcLayerTest : SysuiTestCase() {
@Test
fun testTransparentRegion_hasLongEdgeCutout_hasRoundedCorner_hasCutoutProtection() {
- setupConfigs(cutoutRight, roundedSizeTop, roundedSizeBottom, RectF(48f, 1f, 52f, 5f), 1f)
+ setupConfigs(cutoutRight, true, true, roundedSizeTop, roundedSizeBottom,
+ RectF(48f, 1f, 52f, 5f), 1f)
decorHwcLayer.calculateTransparentRect()
@@ -163,6 +165,8 @@ class ScreenDecorHwcLayerTest : SysuiTestCase() {
private fun setupConfigs(
cutout: DisplayCutout?,
+ hasRoundedTop: Boolean,
+ hasRoundedBottom: Boolean,
roundedTop: Int,
roundedBottom: Int,
protectionRect: RectF,
@@ -174,7 +178,8 @@ class ScreenDecorHwcLayerTest : SysuiTestCase() {
info.displayCutout = cutout
return@then true
}
- decorHwcLayer.updateRoundedCornerSize(roundedTop, roundedBottom)
+ decorHwcLayer.updateRoundedCornerExistenceAndSize(hasRoundedTop, hasRoundedBottom,
+ roundedTop, roundedBottom)
decorHwcLayer.protectionRect.set(protectionRect)
decorHwcLayer.cameraProtectionProgress = protectionProgress
decorHwcLayer.updateCutout()
diff --git a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
index 6bb994f4368a..9760c6181ab2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
@@ -46,12 +46,13 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.annotation.IdRes;
+import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Insets;
import android.graphics.PixelFormat;
import android.graphics.Rect;
-import android.graphics.drawable.VectorDrawable;
+import android.graphics.drawable.Drawable;
import android.hardware.display.DisplayManager;
import android.hardware.graphics.common.DisplayDecorationSupport;
import android.os.Handler;
@@ -67,6 +68,7 @@ import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.WindowMetrics;
+import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.test.filters.SmallTest;
@@ -74,6 +76,7 @@ import androidx.test.filters.SmallTest;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.decor.CornerDecorProvider;
import com.android.systemui.decor.DecorProvider;
+import com.android.systemui.decor.DecorProviderFactory;
import com.android.systemui.decor.OverlayWindow;
import com.android.systemui.decor.PrivacyDotCornerDecorProviderImpl;
import com.android.systemui.decor.PrivacyDotDecorProviderFactory;
@@ -94,6 +97,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
+import java.util.List;
@RunWithLooper
@RunWith(AndroidTestingRunner.class)
@@ -384,8 +388,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testNoRounding_NoCutout_NoPrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- false /* fillCutout */, false /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, false /* fillCutout */, false /* privacyDot */);
// no cutout
doReturn(null).when(mScreenDecorations).getCutout();
@@ -402,8 +406,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testNoRounding_NoCutout_PrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- false /* fillCutout */, true /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
// no cutout
doReturn(null).when(mScreenDecorations).getCutout();
@@ -434,8 +438,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testRounding_NoCutout_NoPrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 20 /* roundedPadding */, false /* multipleRadius */,
- false /* fillCutout */, false /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 20 /* roundedPadding */, false /* fillCutout */, false /* privacyDot */);
// no cutout
doReturn(null).when(mScreenDecorations).getCutout();
@@ -462,8 +466,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testRounding_NoCutout_PrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 20 /* roundedPadding */, false /* multipleRadius */,
- false /* fillCutout */, true /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 20 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
// no cutout
doReturn(null).when(mScreenDecorations).getCutout();
@@ -492,10 +496,13 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testRoundingRadius_NoCutout() {
- final Size testRadiusPoint = new Size(1, 1);
+ final Size testRadiusPoint = new Size(3, 3);
setupResources(1 /* radius */, 1 /* radiusTop */, 1 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- false /* fillCutout */, true /* privacyDot */);
+ getTestsDrawable(com.android.systemui.tests.R.drawable.rounded3px)
+ /* roundedTopDrawable */,
+ getTestsDrawable(com.android.systemui.tests.R.drawable.rounded3px)
+ /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
// no cutout
doReturn(null).when(mScreenDecorations).getCutout();
@@ -508,10 +515,12 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testRoundingTopBottomRadius_OnTopBottomOverlay() {
- final int testTopRadius = 1;
- final int testBottomRadius = 5;
- setupResources(testTopRadius, testTopRadius, testBottomRadius, 0 /* roundedPadding */,
- false /* multipleRadius */, false /* fillCutout */, true /* privacyDot */);
+ setupResources(1 /* radius */, 1 /* radiusTop */, 1 /* radiusBottom */,
+ getTestsDrawable(com.android.systemui.tests.R.drawable.rounded4px)
+ /* roundedTopDrawable */,
+ getTestsDrawable(com.android.systemui.tests.R.drawable.rounded3px)
+ /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
// no cutout
doReturn(null).when(mScreenDecorations).getCutout();
@@ -523,10 +532,10 @@ public class ScreenDecorationsTest extends SysuiTestCase {
.findViewById(R.id.rounded_corner_top_right);
ViewGroup.LayoutParams leftParams = leftRoundedCorner.getLayoutParams();
ViewGroup.LayoutParams rightParams = rightRoundedCorner.getLayoutParams();
- assertEquals(leftParams.width, testTopRadius);
- assertEquals(leftParams.height, testTopRadius);
- assertEquals(rightParams.width, testTopRadius);
- assertEquals(rightParams.height, testTopRadius);
+ assertEquals(4, leftParams.width);
+ assertEquals(4, leftParams.height);
+ assertEquals(4, rightParams.width);
+ assertEquals(4, rightParams.height);
leftRoundedCorner = mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM].getRootView()
.findViewById(R.id.rounded_corner_bottom_left);
@@ -534,18 +543,20 @@ public class ScreenDecorationsTest extends SysuiTestCase {
.findViewById(R.id.rounded_corner_bottom_right);
leftParams = leftRoundedCorner.getLayoutParams();
rightParams = rightRoundedCorner.getLayoutParams();
- assertEquals(leftParams.width, testBottomRadius);
- assertEquals(leftParams.height, testBottomRadius);
- assertEquals(rightParams.width, testBottomRadius);
- assertEquals(rightParams.height, testBottomRadius);
+ assertEquals(3, leftParams.width);
+ assertEquals(3, leftParams.height);
+ assertEquals(3, rightParams.width);
+ assertEquals(3, rightParams.height);
}
@Test
public void testRoundingTopBottomRadius_OnLeftRightOverlay() {
- final int testTopRadius = 1;
- final int testBottomRadius = 5;
- setupResources(testTopRadius, testTopRadius, testBottomRadius, 0 /* roundedPadding */,
- false /* multipleRadius */, false /* fillCutout */, true /* privacyDot */);
+ setupResources(1 /* radius */, 1 /* radiusTop */, 1 /* radiusBottom */,
+ getTestsDrawable(com.android.systemui.tests.R.drawable.rounded3px)
+ /* roundedTopDrawable */,
+ getTestsDrawable(com.android.systemui.tests.R.drawable.rounded5px)
+ /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
// left cutout
final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null};
@@ -559,10 +570,10 @@ public class ScreenDecorationsTest extends SysuiTestCase {
.findViewById(R.id.rounded_corner_bottom_left);
ViewGroup.LayoutParams topParams = topRoundedCorner.getLayoutParams();
ViewGroup.LayoutParams bottomParams = bottomRoundedCorner.getLayoutParams();
- assertEquals(topParams.width, testTopRadius);
- assertEquals(topParams.height, testTopRadius);
- assertEquals(bottomParams.width, testBottomRadius);
- assertEquals(bottomParams.height, testBottomRadius);
+ assertEquals(3, topParams.width);
+ assertEquals(3, topParams.height);
+ assertEquals(5, bottomParams.width);
+ assertEquals(5, bottomParams.height);
topRoundedCorner = mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT].getRootView()
.findViewById(R.id.rounded_corner_top_right);
@@ -570,88 +581,17 @@ public class ScreenDecorationsTest extends SysuiTestCase {
.findViewById(R.id.rounded_corner_bottom_right);
topParams = topRoundedCorner.getLayoutParams();
bottomParams = bottomRoundedCorner.getLayoutParams();
- assertEquals(topParams.width, testTopRadius);
- assertEquals(topParams.height, testTopRadius);
- assertEquals(bottomParams.width, testBottomRadius);
- assertEquals(bottomParams.height, testBottomRadius);
- }
-
- @Test
- public void testRoundingMultipleRadius_NoCutout_NoPrivacyDot() {
- final VectorDrawable d = (VectorDrawable) mContext.getDrawable(R.drawable.rounded);
- final Size multipleRadiusSize = new Size(d.getIntrinsicWidth(), d.getIntrinsicHeight());
- setupResources(9999 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 9999 /* roundedPadding */, true /* multipleRadius */,
- false /* fillCutout */, false /* 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, View.VISIBLE);
-
- // Rounded corner views shall exist
- verifyRoundedCornerViewsExist(BOUNDS_POSITION_TOP, true);
- verifyRoundedCornerViewsExist(BOUNDS_POSITION_BOTTOM, true);
-
- // Privacy dots shall not exist
- verifyDotViewsNullable(true);
-
- // One tunable.
- 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
- final RoundedCornerResDelegate resDelegate = mScreenDecorations.mRoundedCornerResDelegate;
- assertThat(resDelegate.getTopRoundedSize()).isEqualTo(multipleRadiusSize);
- assertThat(resDelegate.getBottomRoundedSize()).isEqualTo(multipleRadiusSize);
- }
-
- @Test
- public void testRoundingMultipleRadius_NoCutout_PrivacyDot() {
- final VectorDrawable d = (VectorDrawable) mContext.getDrawable(R.drawable.rounded);
- final Size multipleRadiusSize = new Size(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, View.VISIBLE);
- verify(mDotViewController, times(1)).initialize(any(), any(), any(), any());
- verify(mDotViewController, times(1)).setShowingListener(null);
-
- // Rounded corner views shall exist
- verifyRoundedCornerViewsExist(BOUNDS_POSITION_TOP, true);
- verifyRoundedCornerViewsExist(BOUNDS_POSITION_BOTTOM, true);
-
- // 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
- final RoundedCornerResDelegate resDelegate = mScreenDecorations.mRoundedCornerResDelegate;
- assertThat(resDelegate.getTopRoundedSize()).isEqualTo(multipleRadiusSize);
- assertThat(resDelegate.getBottomRoundedSize()).isEqualTo(multipleRadiusSize);
+ assertEquals(3, topParams.width);
+ assertEquals(3, topParams.height);
+ assertEquals(5, bottomParams.width);
+ assertEquals(5, bottomParams.height);
}
@Test
public void testNoRounding_CutoutShortEdge_NoPrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, false /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, true /* fillCutout */, false /* privacyDot */);
// top cutout
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
@@ -673,8 +613,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testNoRounding_CutoutShortEdge_PrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, true /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, true /* fillCutout */, true /* privacyDot */);
// top cutout
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
@@ -707,8 +647,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testNoRounding_CutoutLongEdge_NoPrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, false /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, true /* fillCutout */, false /* privacyDot */);
// left cutout
final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null};
@@ -734,8 +674,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testNoRounding_CutoutLongEdge_PrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, true /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, true /* fillCutout */, true /* privacyDot */);
// left cutout
final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null};
@@ -761,8 +701,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testRounding_CutoutShortEdge_NoPrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 20 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, false /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 20 /* roundedPadding */, true /* fillCutout */, false /* privacyDot */);
// top cutout
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
@@ -789,8 +729,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testRounding_CutoutShortEdge_PrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 20 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, true /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 20 /* roundedPadding */, true /* fillCutout */, true /* privacyDot */);
// top cutout
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
@@ -820,8 +760,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testRounding_CutoutLongEdge_NoPrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 20 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, false /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 20 /* roundedPadding */, true /* fillCutout */, false /* privacyDot */);
// left cutout
final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null};
@@ -838,8 +778,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testRounding_CutoutLongEdge_PrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 20 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, true /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 20 /* roundedPadding */, true /* fillCutout */, true /* privacyDot */);
// left cutout
final Rect[] bounds = {new Rect(0, 50, 1, 60), null, null, null};
@@ -858,8 +798,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testRounding_CutoutShortAndLongEdge_NoPrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 20 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, false /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 20 /* roundedPadding */, true /* fillCutout */, false /* privacyDot */);
// top and left cutout
final Rect[] bounds = {new Rect(0, 50, 1, 60), new Rect(9, 0, 10, 1), null, null};
@@ -877,8 +817,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testRounding_CutoutShortAndLongEdge_PrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 20 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, true /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 20 /* roundedPadding */, 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};
@@ -898,8 +838,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testNoRounding_SwitchFrom_ShortEdgeCutout_To_LongCutout_NoPrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, false /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, true /* fillCutout */, false /* privacyDot */);
// Set to short edge cutout(top).
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
@@ -921,8 +861,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testNoRounding_SwitchFrom_ShortEdgeCutout_To_LongCutout_PrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, true /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, true /* fillCutout */, true /* privacyDot */);
// Set to short edge cutout(top).
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
@@ -964,8 +904,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testDelayedCutout_NoPrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- false /* fillCutout */, false /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, false /* fillCutout */, false /* privacyDot */);
// top cutout
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
@@ -987,8 +927,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testDelayedCutout_PrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- false /* fillCutout */, true /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
// top cutout
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
@@ -1029,43 +969,71 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testUpdateRoundedCorners() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- false /* fillCutout */, true /* privacyDot */);
+ getTestsDrawable(com.android.systemui.tests.R.drawable.rounded3px)
+ /* roundedTopDrawable */,
+ getTestsDrawable(com.android.systemui.tests.R.drawable.rounded4px)
+ /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
mScreenDecorations.start();
+
final RoundedCornerResDelegate resDelegate = mScreenDecorations.mRoundedCornerResDelegate;
- assertEquals(resDelegate.getTopRoundedSize(), new Size(20, 20));
- assertEquals(resDelegate.getBottomRoundedSize(), new Size(20, 20));
+ assertEquals(new Size(3, 3), resDelegate.getTopRoundedSize());
+ assertEquals(new Size(4, 4), resDelegate.getBottomRoundedSize());
- when(mContext.getResources().getDimensionPixelSize(
- com.android.internal.R.dimen.rounded_corner_radius)).thenReturn(5);
+ setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
+ getTestsDrawable(com.android.systemui.tests.R.drawable.rounded4px)
+ /* roundedTopDrawable */,
+ getTestsDrawable(com.android.systemui.tests.R.drawable.rounded5px)
+ /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
mScreenDecorations.onConfigurationChanged(null);
- assertEquals(resDelegate.getTopRoundedSize(), new Size(5, 5));
- assertEquals(resDelegate.getBottomRoundedSize(), new Size(5, 5));
+
+ assertEquals(new Size(4, 4), resDelegate.getTopRoundedSize());
+ assertEquals(new Size(5, 5), resDelegate.getBottomRoundedSize());
}
@Test
public void testOnlyRoundedCornerRadiusTop() {
setupResources(0 /* radius */, 10 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- false /* fillCutout */, true /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
mScreenDecorations.start();
+
final RoundedCornerResDelegate resDelegate = mScreenDecorations.mRoundedCornerResDelegate;
- assertEquals(new Size(10, 10), resDelegate.getTopRoundedSize());
- assertEquals(new Size(0, 0), resDelegate.getBottomRoundedSize());
- }
+ assertEquals(true, resDelegate.getHasTop());
+ assertEquals(false, resDelegate.getHasBottom());
+ assertEquals(getDrawableIntrinsicSize(R.drawable.rounded_corner_top),
+ resDelegate.getTopRoundedSize());
+
+ final DecorProviderFactory mRoundedCornerFactory = mScreenDecorations.mRoundedCornerFactory;
+ assertEquals(true, mRoundedCornerFactory.getHasProviders());
+ final List<DecorProvider> providers = mRoundedCornerFactory.getProviders();
+ assertEquals(2, providers.size());
+ assertEquals(true, providers.get(0).getAlignedBounds().contains(BOUNDS_POSITION_TOP));
+ assertEquals(true, providers.get(1).getAlignedBounds().contains(BOUNDS_POSITION_TOP)); }
@Test
public void testOnlyRoundedCornerRadiusBottom() {
setupResources(0 /* radius */, 0 /* radiusTop */, 20 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- false /* fillCutout */, true /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
mScreenDecorations.start();
+
final RoundedCornerResDelegate resDelegate = mScreenDecorations.mRoundedCornerResDelegate;
- assertEquals(new Size(0, 0), resDelegate.getTopRoundedSize());
- assertEquals(new Size(20, 20), resDelegate.getBottomRoundedSize());
+ assertEquals(false, resDelegate.getHasTop());
+ assertEquals(true, resDelegate.getHasBottom());
+ assertEquals(getDrawableIntrinsicSize(R.drawable.rounded_corner_bottom),
+ resDelegate.getBottomRoundedSize());
+
+ final DecorProviderFactory mRoundedCornerFactory = mScreenDecorations.mRoundedCornerFactory;
+ assertEquals(true, mRoundedCornerFactory.getHasProviders());
+ final List<DecorProvider> providers = mRoundedCornerFactory.getProviders();
+ assertEquals(2, providers.size());
+ assertEquals(true, providers.get(0).getAlignedBounds().contains(BOUNDS_POSITION_BOTTOM));
+ assertEquals(true, providers.get(1).getAlignedBounds().contains(BOUNDS_POSITION_BOTTOM));
}
@Test
@@ -1120,8 +1088,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testSupportHwcLayer_SwitchFrom_NotSupport() {
setupResources(0 /* radius */, 10 /* radiusTop */, 20 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, false /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, true /* fillCutout */, false /* privacyDot */);
// top cutout
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
@@ -1148,8 +1116,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testNotSupportHwcLayer_SwitchFrom_Support() {
setupResources(0 /* radius */, 10 /* radiusTop */, 20 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, false /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, true /* fillCutout */, false /* privacyDot */);
final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport();
decorationSupport.format = PixelFormat.R_8;
doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport();
@@ -1183,8 +1151,11 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testAutoShowHideOverlayWindowWhenSupportHwcLayer() {
setupResources(0 /* radius */, 10 /* radiusTop */, 20 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, true /* privacyDot */);
+ getTestsDrawable(com.android.systemui.tests.R.drawable.rounded3px)
+ /* roundedTopDrawable */,
+ getTestsDrawable(com.android.systemui.tests.R.drawable.rounded4px)
+ /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, true /* fillCutout */, true /* privacyDot */);
final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport();
decorationSupport.format = PixelFormat.R_8;
doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport();
@@ -1212,8 +1183,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testAutoShowHideOverlayWindowWhenNoRoundedAndNoCutout() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- false /* fillCutout */, true /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
// no cutout
doReturn(null).when(mScreenDecorations).getCutout();
@@ -1236,8 +1207,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testHwcLayer_noPrivacyDot() {
setupResources(0 /* radius */, 10 /* radiusTop */, 20 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, false /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, true /* fillCutout */, false /* privacyDot */);
final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport();
decorationSupport.format = PixelFormat.R_8;
doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport();
@@ -1257,8 +1228,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testHwcLayer_PrivacyDot() {
setupResources(0 /* radius */, 10 /* radiusTop */, 20 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, true /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, true /* fillCutout */, true /* privacyDot */);
final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport();
decorationSupport.format = PixelFormat.R_8;
doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport();
@@ -1281,8 +1252,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testOnDisplayChanged_hwcLayer() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, false /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, true /* fillCutout */, false /* privacyDot */);
final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport();
decorationSupport.format = PixelFormat.R_8;
doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport();
@@ -1307,8 +1278,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testOnDisplayChanged_nonHwcLayer() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, false /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, true /* fillCutout */, false /* privacyDot */);
// top cutout
final Rect[] bounds = {null, new Rect(9, 0, 10, 1), null, null};
@@ -1331,8 +1302,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testHasSameProvidersWithNullOverlays() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- false /* fillCutout */, false /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, false /* fillCutout */, false /* privacyDot */);
mScreenDecorations.start();
@@ -1349,8 +1320,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test
public void testHasSameProvidersWithPrivacyDots() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
- 0 /* roundedPadding */, false /* multipleRadius */,
- true /* fillCutout */, true /* privacyDot */);
+ null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
+ 0 /* roundedPadding */, true /* fillCutout */, true /* privacyDot */);
mScreenDecorations.start();
@@ -1370,8 +1341,24 @@ public class ScreenDecorationsTest extends SysuiTestCase {
assertTrue(mScreenDecorations.hasSameProviders(newProviders));
}
- private void setupResources(int radius, int radiusTop, int radiusBottom, int roundedPadding,
- boolean multipleRadius, boolean fillCutout, boolean privacyDot) {
+ private Size getDrawableIntrinsicSize(@DrawableRes int drawableResId) {
+ final Drawable d = mContext.getDrawable(drawableResId);
+ return new Size(d.getIntrinsicWidth(), d.getIntrinsicHeight());
+ }
+
+ @Nullable
+ private Drawable getTestsDrawable(@DrawableRes int drawableId) {
+ try {
+ return mContext.createPackageContext("com.android.systemui.tests", 0)
+ .getDrawable(drawableId);
+ } catch (PackageManager.NameNotFoundException exception) {
+ return null;
+ }
+ }
+
+ private void setupResources(int radius, int radiusTop, int radiusBottom,
+ @Nullable Drawable roundedTopDrawable, @Nullable Drawable roundedBottomDrawable,
+ int roundedPadding, boolean fillCutout, boolean privacyDot) {
mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.array.config_displayUniqueIdArray,
new String[]{});
@@ -1394,19 +1381,24 @@ public class ScreenDecorationsTest extends SysuiTestCase {
R.array.config_roundedCornerBottomDrawableArray,
mMockTypedArray);
mContext.getOrCreateTestableResources().addOverride(
- R.array.config_roundedCornerMultipleRadiusArray,
- mMockTypedArray);
- mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.dimen.rounded_corner_radius, radius);
mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.dimen.rounded_corner_radius_top, radiusTop);
mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.dimen.rounded_corner_radius_bottom, radiusBottom);
+ if (roundedTopDrawable != null) {
+ mContext.getOrCreateTestableResources().addOverride(
+ R.drawable.rounded_corner_top,
+ roundedTopDrawable);
+ }
+ if (roundedBottomDrawable != null) {
+ mContext.getOrCreateTestableResources().addOverride(
+ R.drawable.rounded_corner_bottom,
+ roundedBottomDrawable);
+ }
mContext.getOrCreateTestableResources().addOverride(
R.dimen.rounded_corner_content_padding, roundedPadding);
mContext.getOrCreateTestableResources().addOverride(
- R.bool.config_roundedCornerMultipleRadius, multipleRadius);
- mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, fillCutout);
mPrivacyDecorProviders = new ArrayList<>();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/decor/RoundedCornerDecorProviderFactoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/decor/RoundedCornerDecorProviderFactoryTest.kt
index 621bcf69bb03..fcc358982e6c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/decor/RoundedCornerDecorProviderFactoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/decor/RoundedCornerDecorProviderFactoryTest.kt
@@ -44,9 +44,8 @@ class RoundedCornerDecorProviderFactoryTest : SysuiTestCase() {
@Test
fun testNoRoundedCorners() {
- Mockito.doReturn(Size(0, 0)).`when`(roundedCornerResDelegate).topRoundedSize
- Mockito.doReturn(Size(0, 0)).`when`(roundedCornerResDelegate).bottomRoundedSize
- Mockito.doReturn(false).`when`(roundedCornerResDelegate).isMultipleRadius
+ Mockito.doReturn(false).`when`(roundedCornerResDelegate).hasTop
+ Mockito.doReturn(false).`when`(roundedCornerResDelegate).hasBottom
roundedCornerDecorProviderFactory =
RoundedCornerDecorProviderFactory(roundedCornerResDelegate)
@@ -56,10 +55,10 @@ class RoundedCornerDecorProviderFactoryTest : SysuiTestCase() {
}
@Test
- fun testHasRoundedCornersIfTopWidthLargerThan0() {
- Mockito.doReturn(Size(1, 0)).`when`(roundedCornerResDelegate).topRoundedSize
- Mockito.doReturn(Size(0, 0)).`when`(roundedCornerResDelegate).bottomRoundedSize
- Mockito.doReturn(false).`when`(roundedCornerResDelegate).isMultipleRadius
+ fun testOnlyHasTopRoundedCorners() {
+ Mockito.doReturn(true).`when`(roundedCornerResDelegate).hasTop
+ Mockito.doReturn(false).`when`(roundedCornerResDelegate).hasBottom
+ Mockito.doReturn(Size(1, 1)).`when`(roundedCornerResDelegate).topRoundedSize
roundedCornerDecorProviderFactory =
RoundedCornerDecorProviderFactory(roundedCornerResDelegate)
@@ -82,9 +81,9 @@ class RoundedCornerDecorProviderFactoryTest : SysuiTestCase() {
@Test
fun testHasRoundedCornersIfBottomWidthLargerThan0() {
- Mockito.doReturn(Size(0, 0)).`when`(roundedCornerResDelegate).topRoundedSize
+ Mockito.doReturn(false).`when`(roundedCornerResDelegate).hasTop
+ Mockito.doReturn(true).`when`(roundedCornerResDelegate).hasBottom
Mockito.doReturn(Size(1, 1)).`when`(roundedCornerResDelegate).bottomRoundedSize
- Mockito.doReturn(false).`when`(roundedCornerResDelegate).isMultipleRadius
roundedCornerDecorProviderFactory =
RoundedCornerDecorProviderFactory(roundedCornerResDelegate)
@@ -107,9 +106,10 @@ class RoundedCornerDecorProviderFactoryTest : SysuiTestCase() {
@Test
fun test4CornerDecorProvidersInfo() {
+ Mockito.doReturn(true).`when`(roundedCornerResDelegate).hasTop
+ Mockito.doReturn(true).`when`(roundedCornerResDelegate).hasBottom
Mockito.doReturn(Size(10, 10)).`when`(roundedCornerResDelegate).topRoundedSize
Mockito.doReturn(Size(10, 10)).`when`(roundedCornerResDelegate).bottomRoundedSize
- Mockito.doReturn(true).`when`(roundedCornerResDelegate).isMultipleRadius
roundedCornerDecorProviderFactory =
RoundedCornerDecorProviderFactory(roundedCornerResDelegate)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/decor/RoundedCornerResDelegateTest.kt b/packages/SystemUI/tests/src/com/android/systemui/decor/RoundedCornerResDelegateTest.kt
index 1fec38018f51..f629b3b9b97a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/decor/RoundedCornerResDelegateTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/decor/RoundedCornerResDelegateTest.kt
@@ -17,12 +17,14 @@
package com.android.systemui.decor
import android.content.res.TypedArray
-import android.graphics.drawable.VectorDrawable
+import android.graphics.drawable.Drawable
import android.testing.AndroidTestingRunner
-import android.testing.TestableResources
import android.util.Size
+import androidx.annotation.DrawableRes
import androidx.test.filters.SmallTest
-import com.android.systemui.R
+import com.android.internal.R as InternalR
+import com.android.systemui.R as SystemUIR
+import com.android.systemui.tests.R
import com.android.systemui.SysuiTestCase
import org.junit.Assert.assertEquals
import org.junit.Before
@@ -45,66 +47,76 @@ class RoundedCornerResDelegateTest : SysuiTestCase() {
}
@Test
+ fun testTopAndBottomRoundedCornerExist() {
+ setupResources(radius = 5)
+ roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
+ assertEquals(true, roundedCornerResDelegate.hasTop)
+ assertEquals(true, roundedCornerResDelegate.hasBottom)
+ }
+
+ @Test
+ fun testTopRoundedCornerExist() {
+ setupResources(radiusTop = 10)
+ roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
+ assertEquals(true, roundedCornerResDelegate.hasTop)
+ assertEquals(false, roundedCornerResDelegate.hasBottom)
+ }
+
+ @Test
+ fun testBottomRoundedCornerExist() {
+ setupResources(radiusBottom = 15)
+ roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
+ assertEquals(false, roundedCornerResDelegate.hasTop)
+ assertEquals(true, roundedCornerResDelegate.hasBottom)
+ }
+
+ @Test
fun testUpdateDisplayUniqueId() {
- mContext.orCreateTestableResources.addOverrides(
- mockTypeArray = mockTypedArray,
- radius = 3,
- radiusTop = 0,
- radiusBottom = 4,
- multipleRadius = false)
+ setupResources(radius = 100,
+ roundedTopDrawable = getTestsDrawable(R.drawable.rounded3px),
+ roundedBottomDrawable = getTestsDrawable(R.drawable.rounded4px))
roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
assertEquals(Size(3, 3), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(4, 4), roundedCornerResDelegate.bottomRoundedSize)
- assertEquals(false, roundedCornerResDelegate.isMultipleRadius)
- mContext.orCreateTestableResources.addOverrides(
- mockTypeArray = mockTypedArray,
- radius = 5,
- radiusTop = 6,
- radiusBottom = 0)
+ setupResources(radius = 100,
+ roundedTopDrawable = getTestsDrawable(R.drawable.rounded4px),
+ roundedBottomDrawable = getTestsDrawable(R.drawable.rounded5px))
roundedCornerResDelegate.updateDisplayUniqueId("test", null)
- assertEquals(Size(6, 6), roundedCornerResDelegate.topRoundedSize)
+ assertEquals(Size(4, 4), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(5, 5), roundedCornerResDelegate.bottomRoundedSize)
}
@Test
fun testNotUpdateDisplayUniqueIdButChangeRefreshToken() {
- mContext.orCreateTestableResources.addOverrides(
- mockTypeArray = mockTypedArray,
- radius = 3,
- radiusTop = 0,
- radiusBottom = 4,
- multipleRadius = false)
+ setupResources(radius = 100,
+ roundedTopDrawable = getTestsDrawable(R.drawable.rounded3px),
+ roundedBottomDrawable = getTestsDrawable(R.drawable.rounded4px))
roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
assertEquals(Size(3, 3), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(4, 4), roundedCornerResDelegate.bottomRoundedSize)
- assertEquals(false, roundedCornerResDelegate.isMultipleRadius)
- mContext.orCreateTestableResources.addOverrides(
- mockTypeArray = mockTypedArray,
- radius = 5,
- radiusTop = 6,
- radiusBottom = 0)
+ setupResources(radius = 100,
+ roundedTopDrawable = getTestsDrawable(R.drawable.rounded4px),
+ roundedBottomDrawable = getTestsDrawable(R.drawable.rounded5px))
roundedCornerResDelegate.updateDisplayUniqueId(null, 1)
- assertEquals(Size(6, 6), roundedCornerResDelegate.topRoundedSize)
+ assertEquals(Size(4, 4), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(5, 5), roundedCornerResDelegate.bottomRoundedSize)
}
@Test
fun testUpdateTuningSizeFactor() {
- mContext.orCreateTestableResources.addOverrides(
- mockTypeArray = mockTypedArray,
- radiusTop = 2,
- radiusBottom = 0,
- multipleRadius = false)
+ setupResources(radius = 100,
+ roundedTopDrawable = getTestsDrawable(R.drawable.rounded3px),
+ roundedBottomDrawable = getTestsDrawable(R.drawable.rounded4px))
roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
@@ -115,62 +127,43 @@ class RoundedCornerResDelegateTest : SysuiTestCase() {
assertEquals(Size(length, length), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(length, length), roundedCornerResDelegate.bottomRoundedSize)
- mContext.orCreateTestableResources.addOverrides(
- mockTypeArray = mockTypedArray,
- radiusTop = 1,
- radiusBottom = 2,
- multipleRadius = false)
roundedCornerResDelegate.updateTuningSizeFactor(null, 2)
- assertEquals(Size(1, 1), roundedCornerResDelegate.topRoundedSize)
- assertEquals(Size(2, 2), roundedCornerResDelegate.bottomRoundedSize)
+ assertEquals(Size(3, 3), roundedCornerResDelegate.topRoundedSize)
+ assertEquals(Size(4, 4), roundedCornerResDelegate.bottomRoundedSize)
}
- @Test
- fun testReadDefaultRadiusWhen0() {
- mContext.orCreateTestableResources.addOverrides(
- mockTypeArray = mockTypedArray,
- radius = 3,
- radiusTop = 0,
- radiusBottom = 0,
- multipleRadius = false)
-
- roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
-
- assertEquals(Size(3, 3), roundedCornerResDelegate.topRoundedSize)
- assertEquals(Size(3, 3), roundedCornerResDelegate.bottomRoundedSize)
+ private fun getTestsDrawable(@DrawableRes drawableId: Int): Drawable? {
+ return mContext.createPackageContext("com.android.systemui.tests", 0)
+ .getDrawable(drawableId)
}
- @Test
- fun testReadMultipleRadius() {
- val d = mContext.getDrawable(R.drawable.rounded) as VectorDrawable
- val multipleRadiusSize = Size(d.intrinsicWidth, d.intrinsicHeight)
- mContext.orCreateTestableResources.addOverrides(
- mockTypeArray = mockTypedArray,
- multipleRadius = true)
- roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
- assertEquals(multipleRadiusSize, roundedCornerResDelegate.topRoundedSize)
- assertEquals(multipleRadiusSize, roundedCornerResDelegate.bottomRoundedSize)
+ private fun setupResources(
+ radius: Int? = null,
+ radiusTop: Int? = null,
+ radiusBottom: Int? = null,
+ roundedTopDrawable: Drawable? = null,
+ roundedBottomDrawable: Drawable? = null
+ ) {
+ mContext.orCreateTestableResources.let { res ->
+ res.addOverride(InternalR.array.config_displayUniqueIdArray, arrayOf<String>())
+ res.addOverride(InternalR.array.config_roundedCornerRadiusArray, mockTypedArray)
+ res.addOverride(InternalR.array.config_roundedCornerTopRadiusArray, mockTypedArray)
+ res.addOverride(InternalR.array.config_roundedCornerBottomRadiusArray, mockTypedArray)
+ res.addOverride(SystemUIR.array.config_roundedCornerDrawableArray, mockTypedArray)
+ res.addOverride(SystemUIR.array.config_roundedCornerTopDrawableArray, mockTypedArray)
+ res.addOverride(SystemUIR.array.config_roundedCornerBottomDrawableArray, mockTypedArray)
+ res.addOverride(SystemUIR.array.config_roundedCornerMultipleRadiusArray, mockTypedArray)
+ res.addOverride(com.android.internal.R.dimen.rounded_corner_radius, radius ?: 0)
+ res.addOverride(com.android.internal.R.dimen.rounded_corner_radius_top, radiusTop ?: 0)
+ res.addOverride(com.android.internal.R.dimen.rounded_corner_radius_bottom,
+ radiusBottom ?: 0)
+ roundedTopDrawable?.let { drawable ->
+ res.addOverride(SystemUIR.drawable.rounded_corner_top, drawable)
+ }
+ roundedBottomDrawable?.let { drawable ->
+ res.addOverride(SystemUIR.drawable.rounded_corner_bottom, drawable)
+ }
+ }
}
}
-
-private fun TestableResources.addOverrides(
- mockTypeArray: TypedArray,
- radius: Int? = null,
- radiusTop: Int? = null,
- radiusBottom: Int? = null,
- multipleRadius: Boolean? = null
-) {
- addOverride(com.android.internal.R.array.config_displayUniqueIdArray, arrayOf<String>())
- addOverride(com.android.internal.R.array.config_roundedCornerRadiusArray, mockTypeArray)
- addOverride(com.android.internal.R.array.config_roundedCornerTopRadiusArray, mockTypeArray)
- addOverride(com.android.internal.R.array.config_roundedCornerBottomRadiusArray, mockTypeArray)
- addOverride(R.array.config_roundedCornerDrawableArray, mockTypeArray)
- addOverride(R.array.config_roundedCornerTopDrawableArray, mockTypeArray)
- addOverride(R.array.config_roundedCornerBottomDrawableArray, mockTypeArray)
- addOverride(R.array.config_roundedCornerMultipleRadiusArray, mockTypeArray)
- radius?.let { addOverride(com.android.internal.R.dimen.rounded_corner_radius, it) }
- radiusTop?.let { addOverride(com.android.internal.R.dimen.rounded_corner_radius_top, it) }
- radiusBottom?.let { addOverride(com.android.internal.R.dimen.rounded_corner_radius_bottom, it) }
- multipleRadius?.let { addOverride(R.bool.config_roundedCornerMultipleRadius, it) }
-} \ No newline at end of file