Merge "Phase out config_roundedCornerMultipleRadius" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-04-19 03:12:10 +00:00
committed by Android (Google) Code Review
11 changed files with 401 additions and 370 deletions

View File

@@ -60,6 +60,8 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec
private val debugTransparentRegionPaint: Paint? private val debugTransparentRegionPaint: Paint?
private val tempRect: Rect = Rect() private val tempRect: Rect = Rect()
private var hasTopRoundedCorner = false
private var hasBottomRoundedCorner = false
private var roundedCornerTopSize = 0 private var roundedCornerTopSize = 0
private var roundedCornerBottomSize = 0 private var roundedCornerBottomSize = 0
private var roundedCornerDrawableTop: Drawable? = null private var roundedCornerDrawableTop: Drawable? = null
@@ -300,7 +302,7 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec
} }
private fun drawRoundedCorners(canvas: Canvas) { private fun drawRoundedCorners(canvas: Canvas) {
if (roundedCornerTopSize == 0 && roundedCornerBottomSize == 0) { if (!hasTopRoundedCorner && !hasBottomRoundedCorner) {
return return
} }
var degree: Int var degree: Int
@@ -312,9 +314,11 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec
canvas.translate( canvas.translate(
getRoundedCornerTranslationX(degree).toFloat(), getRoundedCornerTranslationX(degree).toFloat(),
getRoundedCornerTranslationY(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) drawRoundedCorner(canvas, roundedCornerDrawableTop, roundedCornerTopSize)
} else { } else if (hasBottomRoundedCorner && (i == RoundedCorner.POSITION_BOTTOM_LEFT ||
i == RoundedCorner.POSITION_BOTTOM_RIGHT)) {
drawRoundedCorner(canvas, roundedCornerDrawableBottom, roundedCornerBottomSize) drawRoundedCorner(canvas, roundedCornerDrawableBottom, roundedCornerBottomSize)
} }
canvas.restore() 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) { fun updateRoundedCornerExistenceAndSize(
if (roundedCornerTopSize == top && roundedCornerBottomSize == bottom) { hasTop: Boolean,
hasBottom: Boolean,
topSize: Int,
bottomSize: Int
) {
if (hasTopRoundedCorner == hasTop &&
hasBottomRoundedCorner == hasBottom &&
roundedCornerBottomSize == bottomSize &&
roundedCornerBottomSize == bottomSize) {
return return
} }
roundedCornerTopSize = top hasTopRoundedCorner = hasTop
roundedCornerBottomSize = bottom hasBottomRoundedCorner = hasBottom
roundedCornerTopSize = topSize
roundedCornerBottomSize = bottomSize
updateRoundedCornerDrawableBounds() updateRoundedCornerDrawableBounds()
// Use requestLayout() to trigger transparent region recalculated // Use requestLayout() to trigger transparent region recalculated

View File

@@ -132,9 +132,6 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
private final ThreadFactory mThreadFactory; private final ThreadFactory mThreadFactory;
private final DecorProviderFactory mDotFactory; 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 @VisibleForTesting
protected RoundedCornerResDelegate mRoundedCornerResDelegate; protected RoundedCornerResDelegate mRoundedCornerResDelegate;
@VisibleForTesting @VisibleForTesting
@@ -406,7 +403,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
if (mScreenDecorHwcLayer != null) { if (mScreenDecorHwcLayer != null) {
updateHwLayerRoundedCornerDrawable(); updateHwLayerRoundedCornerDrawable();
updateHwLayerRoundedCornerSize(); updateHwLayerRoundedCornerExistAndSize();
} }
updateOverlayProviderViews(); updateOverlayProviderViews();
@@ -699,7 +696,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
mScreenDecorHwcWindow.addView(mScreenDecorHwcLayer, new FrameLayout.LayoutParams( mScreenDecorHwcWindow.addView(mScreenDecorHwcLayer, new FrameLayout.LayoutParams(
MATCH_PARENT, MATCH_PARENT, Gravity.TOP | Gravity.START)); MATCH_PARENT, MATCH_PARENT, Gravity.TOP | Gravity.START));
mWindowManager.addView(mScreenDecorHwcWindow, getHwcWindowLayoutParams()); mWindowManager.addView(mScreenDecorHwcWindow, getHwcWindowLayoutParams());
updateHwLayerRoundedCornerSize(); updateHwLayerRoundedCornerExistAndSize();
updateHwLayerRoundedCornerDrawable(); updateHwLayerRoundedCornerDrawable();
mScreenDecorHwcWindow.getViewTreeObserver().addOnPreDrawListener( mScreenDecorHwcWindow.getViewTreeObserver().addOnPreDrawListener(
new ValidatingPreDrawListener(mScreenDecorHwcWindow)); new ValidatingPreDrawListener(mScreenDecorHwcWindow));
@@ -961,7 +958,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
if (mScreenDecorHwcLayer != null) { if (mScreenDecorHwcLayer != null) {
mScreenDecorHwcLayer.pendingRotationChange = false; mScreenDecorHwcLayer.pendingRotationChange = false;
mScreenDecorHwcLayer.updateRotation(mRotation); mScreenDecorHwcLayer.updateRotation(mRotation);
updateHwLayerRoundedCornerSize(); updateHwLayerRoundedCornerExistAndSize();
updateHwLayerRoundedCornerDrawable(); updateHwLayerRoundedCornerDrawable();
} }
updateLayoutParams(); updateLayoutParams();
@@ -1090,7 +1087,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
overlay.onReloadResAndMeasure(filterIds, mProviderRefreshToken, mRotation, overlay.onReloadResAndMeasure(filterIds, mProviderRefreshToken, mRotation,
mDisplayUniqueId); mDisplayUniqueId);
} }
updateHwLayerRoundedCornerSize(); updateHwLayerRoundedCornerExistAndSize();
}); });
} }
@@ -1108,15 +1105,15 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
mScreenDecorHwcLayer.updateRoundedCornerDrawable(topDrawable, bottomDrawable); mScreenDecorHwcLayer.updateRoundedCornerDrawable(topDrawable, bottomDrawable);
} }
private void updateHwLayerRoundedCornerSize() { private void updateHwLayerRoundedCornerExistAndSize() {
if (mScreenDecorHwcLayer == null) { if (mScreenDecorHwcLayer == null) {
return; return;
} }
mScreenDecorHwcLayer.updateRoundedCornerExistenceAndSize(
final int topWidth = mRoundedCornerResDelegate.getTopRoundedSize().getWidth(); mRoundedCornerResDelegate.getHasTop(),
final int bottomWidth = mRoundedCornerResDelegate.getBottomRoundedSize().getWidth(); mRoundedCornerResDelegate.getHasBottom(),
mRoundedCornerResDelegate.getTopRoundedSize().getWidth(),
mScreenDecorHwcLayer.updateRoundedCornerSize(topWidth, bottomWidth); mRoundedCornerResDelegate.getBottomRoundedSize().getWidth());
} }
@VisibleForTesting @VisibleForTesting

View File

@@ -25,8 +25,7 @@ class RoundedCornerDecorProviderFactory(
override val hasProviders: Boolean override val hasProviders: Boolean
get() = roundedCornerResDelegate.run { get() = roundedCornerResDelegate.run {
// We don't consider isMultipleRadius here because it makes no sense if size is zero. hasTop || hasBottom
topRoundedSize.width > 0 || bottomRoundedSize.width > 0
} }
override fun onDisplayUniqueIdChanged(displayUniqueId: String?) { override fun onDisplayUniqueIdChanged(displayUniqueId: String?) {
@@ -35,8 +34,8 @@ class RoundedCornerDecorProviderFactory(
override val providers: List<DecorProvider> override val providers: List<DecorProvider>
get() { get() {
val hasTop = roundedCornerResDelegate.topRoundedSize.width > 0 val hasTop = roundedCornerResDelegate.hasTop
val hasBottom = roundedCornerResDelegate.bottomRoundedSize.width > 0 val hasBottom = roundedCornerResDelegate.hasBottom
return when { return when {
hasTop && hasBottom -> listOf( hasTop && hasBottom -> listOf(
RoundedCornerDecorProviderImpl( RoundedCornerDecorProviderImpl(

View File

@@ -37,10 +37,11 @@ class RoundedCornerResDelegate(
private var reloadToken: Int = 0 private var reloadToken: Int = 0
var isMultipleRadius: Boolean = false var hasTop: Boolean = false
private set private set
private var roundedDrawable: Drawable? = null var hasBottom: Boolean = false
private set
var topRoundedDrawable: Drawable? = null var topRoundedDrawable: Drawable? = null
private set private set
@@ -48,8 +49,6 @@ class RoundedCornerResDelegate(
var bottomRoundedDrawable: Drawable? = null var bottomRoundedDrawable: Drawable? = null
private set private set
private var roundedSize = Size(0, 0)
var topRoundedSize = Size(0, 0) var topRoundedSize = Size(0, 0)
private set private set
@@ -83,52 +82,31 @@ class RoundedCornerResDelegate(
private fun reloadRes() { private fun reloadRes() {
val configIdx = DisplayUtils.getDisplayUniqueIdConfigIndex(res, displayUniqueId) val configIdx = DisplayUtils.getDisplayUniqueIdConfigIndex(res, displayUniqueId)
isMultipleRadius = getIsMultipleRadius(configIdx)
roundedDrawable = getDrawable( val hasDefaultRadius = RoundedCorners.getRoundedCornerRadius(res, displayUniqueId) > 0
displayConfigIndex = configIdx, hasTop = hasDefaultRadius ||
arrayResId = R.array.config_roundedCornerDrawableArray, (RoundedCorners.getRoundedCornerTopRadius(res, displayUniqueId) > 0)
backupDrawableId = R.drawable.rounded hasBottom = hasDefaultRadius ||
) (RoundedCorners.getRoundedCornerBottomRadius(res, displayUniqueId) > 0)
topRoundedDrawable = getDrawable( topRoundedDrawable = getDrawable(
displayConfigIndex = configIdx, displayConfigIndex = configIdx,
arrayResId = R.array.config_roundedCornerTopDrawableArray, arrayResId = R.array.config_roundedCornerTopDrawableArray,
backupDrawableId = R.drawable.rounded_corner_top backupDrawableId = R.drawable.rounded_corner_top
) ?: roundedDrawable )
bottomRoundedDrawable = getDrawable( bottomRoundedDrawable = getDrawable(
displayConfigIndex = configIdx, displayConfigIndex = configIdx,
arrayResId = R.array.config_roundedCornerBottomDrawableArray, arrayResId = R.array.config_roundedCornerBottomDrawableArray,
backupDrawableId = R.drawable.rounded_corner_bottom backupDrawableId = R.drawable.rounded_corner_bottom
) ?: roundedDrawable )
} }
private fun reloadMeasures(roundedSizeFactor: Int? = null) { private fun reloadMeasures(roundedSizeFactor: Int? = null) {
// If config_roundedCornerMultipleRadius set as true, ScreenDecorations respect the topRoundedDrawable?.let {
// (width, height) size of drawable/rounded.xml instead of rounded_corner_radius topRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight)
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)
} }
bottomRoundedDrawable?.let {
if (topRoundedSize.width == 0) { bottomRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight)
topRoundedSize = roundedSize
}
if (bottomRoundedSize.width == 0) {
bottomRoundedSize = roundedSize
} }
if (roundedSizeFactor != null && roundedSizeFactor > 0) { if (roundedSizeFactor != null && roundedSizeFactor > 0) {
@@ -146,25 +124,6 @@ class RoundedCornerResDelegate(
reloadMeasures(factor) 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( private fun getDrawable(
displayConfigIndex: Int, displayConfigIndex: Int,
@ArrayRes arrayResId: Int, @ArrayRes arrayResId: Int,
@@ -184,8 +143,8 @@ class RoundedCornerResDelegate(
override fun dump(pw: PrintWriter, args: Array<out String>) { override fun dump(pw: PrintWriter, args: Array<out String>) {
pw.println("RoundedCornerResDelegate state:") pw.println("RoundedCornerResDelegate state:")
pw.println(" isMultipleRadius:$isMultipleRadius") pw.println(" hasTop=$hasTop")
pw.println(" roundedSize(w,h)=(${roundedSize.width},${roundedSize.height})") pw.println(" hasBottom=$hasBottom")
pw.println(" topRoundedSize(w,h)=(${topRoundedSize.width},${topRoundedSize.height})") pw.println(" topRoundedSize(w,h)=(${topRoundedSize.width},${topRoundedSize.height})")
pw.println(" bottomRoundedSize(w,h)=(${bottomRoundedSize.width}," + pw.println(" bottomRoundedSize(w,h)=(${bottomRoundedSize.width}," +
"${bottomRoundedSize.height})") "${bottomRoundedSize.height})")

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -85,37 +85,37 @@ class ScreenDecorHwcLayerTest : SysuiTestCase() {
@Test @Test
fun testTransparentRegion_noCutout_noRoundedCorner_noProtection() { fun testTransparentRegion_noCutout_noRoundedCorner_noProtection() {
setupConfigs(null, 0, 0, RectF(), 0f) setupConfigs(null, false, false, 0, 0, RectF(), 0f)
decorHwcLayer.calculateTransparentRect() decorHwcLayer.calculateTransparentRect()
assertThat(decorHwcLayer.transparentRect) assertThat(decorHwcLayer.transparentRect)
.isEqualTo(Rect(0, 0, decorHwcLayer.width, decorHwcLayer.height)) .isEqualTo(Rect(0, 0, decorHwcLayer.width, decorHwcLayer.height))
} }
@Test @Test
fun testTransparentRegion_onlyShortEdgeCutout() { fun testTransparentRegion_onlyShortEdgeCutout() {
setupConfigs(cutoutTop, 0, 0, RectF(), 0f) setupConfigs(cutoutTop, false, false, 0, 0, RectF(), 0f)
decorHwcLayer.calculateTransparentRect() decorHwcLayer.calculateTransparentRect()
assertThat(decorHwcLayer.transparentRect) assertThat(decorHwcLayer.transparentRect)
.isEqualTo(Rect(0, cutoutSize, decorHwcLayer.width, decorHwcLayer.height)) .isEqualTo(Rect(0, cutoutSize, decorHwcLayer.width, decorHwcLayer.height))
} }
@Test @Test
fun testTransparentRegion_onlyLongEdgeCutout() { fun testTransparentRegion_onlyLongEdgeCutout() {
setupConfigs(cutoutRight, 0, 0, RectF(), 0f) setupConfigs(cutoutRight, false, false, 0, 0, RectF(), 0f)
decorHwcLayer.calculateTransparentRect() decorHwcLayer.calculateTransparentRect()
assertThat(decorHwcLayer.transparentRect) assertThat(decorHwcLayer.transparentRect)
.isEqualTo(Rect(0, 0, decorHwcLayer.width - cutoutSize, decorHwcLayer.height)) .isEqualTo(Rect(0, 0, decorHwcLayer.width - cutoutSize, decorHwcLayer.height))
} }
@Test @Test
fun testTransparentRegion_onlyRoundedCorners() { fun testTransparentRegion_onlyRoundedCorners() {
setupConfigs(null, roundedSizeTop, roundedSizeBottom, RectF(), 0f) setupConfigs(null, true, true, roundedSizeTop, roundedSizeBottom, RectF(), 0f)
decorHwcLayer.calculateTransparentRect() decorHwcLayer.calculateTransparentRect()
@@ -126,7 +126,7 @@ class ScreenDecorHwcLayerTest : SysuiTestCase() {
@Test @Test
fun testTransparentRegion_onlyCutoutProtection() { 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() decorHwcLayer.calculateTransparentRect()
@@ -143,7 +143,8 @@ class ScreenDecorHwcLayerTest : SysuiTestCase() {
@Test @Test
fun testTransparentRegion_hasShortEdgeCutout_hasRoundedCorner_hasCutoutProtection() { 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() decorHwcLayer.calculateTransparentRect()
@@ -153,7 +154,8 @@ class ScreenDecorHwcLayerTest : SysuiTestCase() {
@Test @Test
fun testTransparentRegion_hasLongEdgeCutout_hasRoundedCorner_hasCutoutProtection() { 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() decorHwcLayer.calculateTransparentRect()
@@ -163,6 +165,8 @@ class ScreenDecorHwcLayerTest : SysuiTestCase() {
private fun setupConfigs( private fun setupConfigs(
cutout: DisplayCutout?, cutout: DisplayCutout?,
hasRoundedTop: Boolean,
hasRoundedBottom: Boolean,
roundedTop: Int, roundedTop: Int,
roundedBottom: Int, roundedBottom: Int,
protectionRect: RectF, protectionRect: RectF,
@@ -174,7 +178,8 @@ class ScreenDecorHwcLayerTest : SysuiTestCase() {
info.displayCutout = cutout info.displayCutout = cutout
return@then true return@then true
} }
decorHwcLayer.updateRoundedCornerSize(roundedTop, roundedBottom) decorHwcLayer.updateRoundedCornerExistenceAndSize(hasRoundedTop, hasRoundedBottom,
roundedTop, roundedBottom)
decorHwcLayer.protectionRect.set(protectionRect) decorHwcLayer.protectionRect.set(protectionRect)
decorHwcLayer.cameraProtectionProgress = protectionProgress decorHwcLayer.cameraProtectionProgress = protectionProgress
decorHwcLayer.updateCutout() decorHwcLayer.updateCutout()

View File

@@ -46,12 +46,13 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.annotation.IdRes; import android.annotation.IdRes;
import android.content.pm.PackageManager;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Insets; import android.graphics.Insets;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.VectorDrawable; import android.graphics.drawable.Drawable;
import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager;
import android.hardware.graphics.common.DisplayDecorationSupport; import android.hardware.graphics.common.DisplayDecorationSupport;
import android.os.Handler; import android.os.Handler;
@@ -67,6 +68,7 @@ import android.view.ViewGroup;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.WindowMetrics; import android.view.WindowMetrics;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
@@ -74,6 +76,7 @@ import androidx.test.filters.SmallTest;
import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.decor.CornerDecorProvider; import com.android.systemui.decor.CornerDecorProvider;
import com.android.systemui.decor.DecorProvider; import com.android.systemui.decor.DecorProvider;
import com.android.systemui.decor.DecorProviderFactory;
import com.android.systemui.decor.OverlayWindow; import com.android.systemui.decor.OverlayWindow;
import com.android.systemui.decor.PrivacyDotCornerDecorProviderImpl; import com.android.systemui.decor.PrivacyDotCornerDecorProviderImpl;
import com.android.systemui.decor.PrivacyDotDecorProviderFactory; import com.android.systemui.decor.PrivacyDotDecorProviderFactory;
@@ -94,6 +97,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
@RunWithLooper @RunWithLooper
@RunWith(AndroidTestingRunner.class) @RunWith(AndroidTestingRunner.class)
@@ -384,8 +388,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testNoRounding_NoCutout_NoPrivacyDot() { public void testNoRounding_NoCutout_NoPrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
false /* fillCutout */, false /* privacyDot */); 0 /* roundedPadding */, false /* fillCutout */, false /* privacyDot */);
// no cutout // no cutout
doReturn(null).when(mScreenDecorations).getCutout(); doReturn(null).when(mScreenDecorations).getCutout();
@@ -402,8 +406,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testNoRounding_NoCutout_PrivacyDot() { public void testNoRounding_NoCutout_PrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
false /* fillCutout */, true /* privacyDot */); 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
// no cutout // no cutout
doReturn(null).when(mScreenDecorations).getCutout(); doReturn(null).when(mScreenDecorations).getCutout();
@@ -434,8 +438,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testRounding_NoCutout_NoPrivacyDot() { public void testRounding_NoCutout_NoPrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
false /* fillCutout */, false /* privacyDot */); 20 /* roundedPadding */, false /* fillCutout */, false /* privacyDot */);
// no cutout // no cutout
doReturn(null).when(mScreenDecorations).getCutout(); doReturn(null).when(mScreenDecorations).getCutout();
@@ -462,8 +466,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testRounding_NoCutout_PrivacyDot() { public void testRounding_NoCutout_PrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
false /* fillCutout */, true /* privacyDot */); 20 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
// no cutout // no cutout
doReturn(null).when(mScreenDecorations).getCutout(); doReturn(null).when(mScreenDecorations).getCutout();
@@ -492,10 +496,13 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testRoundingRadius_NoCutout() { 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 */, setupResources(1 /* radius */, 1 /* radiusTop */, 1 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, getTestsDrawable(com.android.systemui.tests.R.drawable.rounded3px)
false /* fillCutout */, true /* privacyDot */); /* roundedTopDrawable */,
getTestsDrawable(com.android.systemui.tests.R.drawable.rounded3px)
/* roundedBottomDrawable */,
0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
// no cutout // no cutout
doReturn(null).when(mScreenDecorations).getCutout(); doReturn(null).when(mScreenDecorations).getCutout();
@@ -508,10 +515,12 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testRoundingTopBottomRadius_OnTopBottomOverlay() { public void testRoundingTopBottomRadius_OnTopBottomOverlay() {
final int testTopRadius = 1; setupResources(1 /* radius */, 1 /* radiusTop */, 1 /* radiusBottom */,
final int testBottomRadius = 5; getTestsDrawable(com.android.systemui.tests.R.drawable.rounded4px)
setupResources(testTopRadius, testTopRadius, testBottomRadius, 0 /* roundedPadding */, /* roundedTopDrawable */,
false /* multipleRadius */, false /* fillCutout */, true /* privacyDot */); getTestsDrawable(com.android.systemui.tests.R.drawable.rounded3px)
/* roundedBottomDrawable */,
0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
// no cutout // no cutout
doReturn(null).when(mScreenDecorations).getCutout(); doReturn(null).when(mScreenDecorations).getCutout();
@@ -523,10 +532,10 @@ public class ScreenDecorationsTest extends SysuiTestCase {
.findViewById(R.id.rounded_corner_top_right); .findViewById(R.id.rounded_corner_top_right);
ViewGroup.LayoutParams leftParams = leftRoundedCorner.getLayoutParams(); ViewGroup.LayoutParams leftParams = leftRoundedCorner.getLayoutParams();
ViewGroup.LayoutParams rightParams = rightRoundedCorner.getLayoutParams(); ViewGroup.LayoutParams rightParams = rightRoundedCorner.getLayoutParams();
assertEquals(leftParams.width, testTopRadius); assertEquals(4, leftParams.width);
assertEquals(leftParams.height, testTopRadius); assertEquals(4, leftParams.height);
assertEquals(rightParams.width, testTopRadius); assertEquals(4, rightParams.width);
assertEquals(rightParams.height, testTopRadius); assertEquals(4, rightParams.height);
leftRoundedCorner = mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM].getRootView() leftRoundedCorner = mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM].getRootView()
.findViewById(R.id.rounded_corner_bottom_left); .findViewById(R.id.rounded_corner_bottom_left);
@@ -534,18 +543,20 @@ public class ScreenDecorationsTest extends SysuiTestCase {
.findViewById(R.id.rounded_corner_bottom_right); .findViewById(R.id.rounded_corner_bottom_right);
leftParams = leftRoundedCorner.getLayoutParams(); leftParams = leftRoundedCorner.getLayoutParams();
rightParams = rightRoundedCorner.getLayoutParams(); rightParams = rightRoundedCorner.getLayoutParams();
assertEquals(leftParams.width, testBottomRadius); assertEquals(3, leftParams.width);
assertEquals(leftParams.height, testBottomRadius); assertEquals(3, leftParams.height);
assertEquals(rightParams.width, testBottomRadius); assertEquals(3, rightParams.width);
assertEquals(rightParams.height, testBottomRadius); assertEquals(3, rightParams.height);
} }
@Test @Test
public void testRoundingTopBottomRadius_OnLeftRightOverlay() { public void testRoundingTopBottomRadius_OnLeftRightOverlay() {
final int testTopRadius = 1; setupResources(1 /* radius */, 1 /* radiusTop */, 1 /* radiusBottom */,
final int testBottomRadius = 5; getTestsDrawable(com.android.systemui.tests.R.drawable.rounded3px)
setupResources(testTopRadius, testTopRadius, testBottomRadius, 0 /* roundedPadding */, /* roundedTopDrawable */,
false /* multipleRadius */, false /* fillCutout */, true /* privacyDot */); getTestsDrawable(com.android.systemui.tests.R.drawable.rounded5px)
/* roundedBottomDrawable */,
0 /* roundedPadding */, 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};
@@ -559,10 +570,10 @@ public class ScreenDecorationsTest extends SysuiTestCase {
.findViewById(R.id.rounded_corner_bottom_left); .findViewById(R.id.rounded_corner_bottom_left);
ViewGroup.LayoutParams topParams = topRoundedCorner.getLayoutParams(); ViewGroup.LayoutParams topParams = topRoundedCorner.getLayoutParams();
ViewGroup.LayoutParams bottomParams = bottomRoundedCorner.getLayoutParams(); ViewGroup.LayoutParams bottomParams = bottomRoundedCorner.getLayoutParams();
assertEquals(topParams.width, testTopRadius); assertEquals(3, topParams.width);
assertEquals(topParams.height, testTopRadius); assertEquals(3, topParams.height);
assertEquals(bottomParams.width, testBottomRadius); assertEquals(5, bottomParams.width);
assertEquals(bottomParams.height, testBottomRadius); assertEquals(5, bottomParams.height);
topRoundedCorner = mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT].getRootView() topRoundedCorner = mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT].getRootView()
.findViewById(R.id.rounded_corner_top_right); .findViewById(R.id.rounded_corner_top_right);
@@ -570,88 +581,17 @@ public class ScreenDecorationsTest extends SysuiTestCase {
.findViewById(R.id.rounded_corner_bottom_right); .findViewById(R.id.rounded_corner_bottom_right);
topParams = topRoundedCorner.getLayoutParams(); topParams = topRoundedCorner.getLayoutParams();
bottomParams = bottomRoundedCorner.getLayoutParams(); bottomParams = bottomRoundedCorner.getLayoutParams();
assertEquals(topParams.width, testTopRadius); assertEquals(3, topParams.width);
assertEquals(topParams.height, testTopRadius); assertEquals(3, topParams.height);
assertEquals(bottomParams.width, testBottomRadius); assertEquals(5, bottomParams.width);
assertEquals(bottomParams.height, testBottomRadius); assertEquals(5, bottomParams.height);
}
@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);
} }
@Test @Test
public void testNoRounding_CutoutShortEdge_NoPrivacyDot() { public void testNoRounding_CutoutShortEdge_NoPrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, false /* privacyDot */); 0 /* roundedPadding */, 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};
@@ -673,8 +613,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testNoRounding_CutoutShortEdge_PrivacyDot() { public void testNoRounding_CutoutShortEdge_PrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, true /* privacyDot */); 0 /* roundedPadding */, true /* fillCutout */, true /* 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};
@@ -707,8 +647,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testNoRounding_CutoutLongEdge_NoPrivacyDot() { public void testNoRounding_CutoutLongEdge_NoPrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, false /* privacyDot */); 0 /* roundedPadding */, 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};
@@ -734,8 +674,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testNoRounding_CutoutLongEdge_PrivacyDot() { public void testNoRounding_CutoutLongEdge_PrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, true /* privacyDot */); 0 /* roundedPadding */, true /* 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};
@@ -761,8 +701,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testRounding_CutoutShortEdge_NoPrivacyDot() { public void testRounding_CutoutShortEdge_NoPrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, false /* privacyDot */); 20 /* roundedPadding */, 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};
@@ -789,8 +729,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testRounding_CutoutShortEdge_PrivacyDot() { public void testRounding_CutoutShortEdge_PrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, true /* privacyDot */); 20 /* roundedPadding */, true /* fillCutout */, true /* 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};
@@ -820,8 +760,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testRounding_CutoutLongEdge_NoPrivacyDot() { public void testRounding_CutoutLongEdge_NoPrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, false /* privacyDot */); 20 /* roundedPadding */, 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};
@@ -838,8 +778,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testRounding_CutoutLongEdge_PrivacyDot() { public void testRounding_CutoutLongEdge_PrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, true /* privacyDot */); 20 /* roundedPadding */, true /* 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};
@@ -858,8 +798,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testRounding_CutoutShortAndLongEdge_NoPrivacyDot() { public void testRounding_CutoutShortAndLongEdge_NoPrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, false /* privacyDot */); 20 /* roundedPadding */, 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};
@@ -877,8 +817,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testRounding_CutoutShortAndLongEdge_PrivacyDot() { public void testRounding_CutoutShortAndLongEdge_PrivacyDot() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
20 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, true /* privacyDot */); 20 /* roundedPadding */, true /* fillCutout */, true /* 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};
@@ -898,8 +838,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testNoRounding_SwitchFrom_ShortEdgeCutout_To_LongCutout_NoPrivacyDot() { 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 */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, false /* privacyDot */); 0 /* roundedPadding */, 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};
@@ -921,8 +861,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testNoRounding_SwitchFrom_ShortEdgeCutout_To_LongCutout_PrivacyDot() { 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 */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, true /* privacyDot */); 0 /* roundedPadding */, true /* fillCutout */, true /* 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};
@@ -964,8 +904,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testDelayedCutout_NoPrivacyDot() { public void testDelayedCutout_NoPrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
false /* fillCutout */, false /* privacyDot */); 0 /* roundedPadding */, 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};
@@ -987,8 +927,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testDelayedCutout_PrivacyDot() { public void testDelayedCutout_PrivacyDot() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
false /* fillCutout */, true /* privacyDot */); 0 /* roundedPadding */, false /* fillCutout */, true /* 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};
@@ -1029,43 +969,71 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testUpdateRoundedCorners() { public void testUpdateRoundedCorners() {
setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(20 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, getTestsDrawable(com.android.systemui.tests.R.drawable.rounded3px)
false /* fillCutout */, true /* privacyDot */); /* roundedTopDrawable */,
getTestsDrawable(com.android.systemui.tests.R.drawable.rounded4px)
/* roundedBottomDrawable */,
0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
mScreenDecorations.start(); mScreenDecorations.start();
final RoundedCornerResDelegate resDelegate = mScreenDecorations.mRoundedCornerResDelegate;
assertEquals(resDelegate.getTopRoundedSize(), new Size(20, 20));
assertEquals(resDelegate.getBottomRoundedSize(), new Size(20, 20));
when(mContext.getResources().getDimensionPixelSize( final RoundedCornerResDelegate resDelegate = mScreenDecorations.mRoundedCornerResDelegate;
com.android.internal.R.dimen.rounded_corner_radius)).thenReturn(5); assertEquals(new Size(3, 3), resDelegate.getTopRoundedSize());
assertEquals(new Size(4, 4), resDelegate.getBottomRoundedSize());
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); 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 @Test
public void testOnlyRoundedCornerRadiusTop() { public void testOnlyRoundedCornerRadiusTop() {
setupResources(0 /* radius */, 10 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 10 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
false /* fillCutout */, true /* privacyDot */); 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
mScreenDecorations.start(); mScreenDecorations.start();
final RoundedCornerResDelegate resDelegate = mScreenDecorations.mRoundedCornerResDelegate; final RoundedCornerResDelegate resDelegate = mScreenDecorations.mRoundedCornerResDelegate;
assertEquals(new Size(10, 10), resDelegate.getTopRoundedSize()); assertEquals(true, resDelegate.getHasTop());
assertEquals(new Size(0, 0), resDelegate.getBottomRoundedSize()); 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 @Test
public void testOnlyRoundedCornerRadiusBottom() { public void testOnlyRoundedCornerRadiusBottom() {
setupResources(0 /* radius */, 0 /* radiusTop */, 20 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 20 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
false /* fillCutout */, true /* privacyDot */); 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
mScreenDecorations.start(); mScreenDecorations.start();
final RoundedCornerResDelegate resDelegate = mScreenDecorations.mRoundedCornerResDelegate; final RoundedCornerResDelegate resDelegate = mScreenDecorations.mRoundedCornerResDelegate;
assertEquals(new Size(0, 0), resDelegate.getTopRoundedSize()); assertEquals(false, resDelegate.getHasTop());
assertEquals(new Size(20, 20), resDelegate.getBottomRoundedSize()); 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 @Test
@@ -1120,8 +1088,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testSupportHwcLayer_SwitchFrom_NotSupport() { public void testSupportHwcLayer_SwitchFrom_NotSupport() {
setupResources(0 /* radius */, 10 /* radiusTop */, 20 /* radiusBottom */, setupResources(0 /* radius */, 10 /* radiusTop */, 20 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, false /* privacyDot */); 0 /* roundedPadding */, 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};
@@ -1148,8 +1116,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testNotSupportHwcLayer_SwitchFrom_Support() { public void testNotSupportHwcLayer_SwitchFrom_Support() {
setupResources(0 /* radius */, 10 /* radiusTop */, 20 /* radiusBottom */, setupResources(0 /* radius */, 10 /* radiusTop */, 20 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, false /* privacyDot */); 0 /* roundedPadding */, true /* fillCutout */, false /* privacyDot */);
final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport(); final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport();
decorationSupport.format = PixelFormat.R_8; decorationSupport.format = PixelFormat.R_8;
doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport(); doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport();
@@ -1183,8 +1151,11 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testAutoShowHideOverlayWindowWhenSupportHwcLayer() { public void testAutoShowHideOverlayWindowWhenSupportHwcLayer() {
setupResources(0 /* radius */, 10 /* radiusTop */, 20 /* radiusBottom */, setupResources(0 /* radius */, 10 /* radiusTop */, 20 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, getTestsDrawable(com.android.systemui.tests.R.drawable.rounded3px)
true /* fillCutout */, true /* privacyDot */); /* roundedTopDrawable */,
getTestsDrawable(com.android.systemui.tests.R.drawable.rounded4px)
/* roundedBottomDrawable */,
0 /* roundedPadding */, true /* fillCutout */, true /* privacyDot */);
final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport(); final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport();
decorationSupport.format = PixelFormat.R_8; decorationSupport.format = PixelFormat.R_8;
doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport(); doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport();
@@ -1212,8 +1183,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testAutoShowHideOverlayWindowWhenNoRoundedAndNoCutout() { public void testAutoShowHideOverlayWindowWhenNoRoundedAndNoCutout() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
false /* fillCutout */, true /* privacyDot */); 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */);
// no cutout // no cutout
doReturn(null).when(mScreenDecorations).getCutout(); doReturn(null).when(mScreenDecorations).getCutout();
@@ -1236,8 +1207,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testHwcLayer_noPrivacyDot() { public void testHwcLayer_noPrivacyDot() {
setupResources(0 /* radius */, 10 /* radiusTop */, 20 /* radiusBottom */, setupResources(0 /* radius */, 10 /* radiusTop */, 20 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, false /* privacyDot */); 0 /* roundedPadding */, true /* fillCutout */, false /* privacyDot */);
final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport(); final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport();
decorationSupport.format = PixelFormat.R_8; decorationSupport.format = PixelFormat.R_8;
doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport(); doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport();
@@ -1257,8 +1228,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testHwcLayer_PrivacyDot() { public void testHwcLayer_PrivacyDot() {
setupResources(0 /* radius */, 10 /* radiusTop */, 20 /* radiusBottom */, setupResources(0 /* radius */, 10 /* radiusTop */, 20 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, true /* privacyDot */); 0 /* roundedPadding */, true /* fillCutout */, true /* privacyDot */);
final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport(); final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport();
decorationSupport.format = PixelFormat.R_8; decorationSupport.format = PixelFormat.R_8;
doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport(); doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport();
@@ -1281,8 +1252,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testOnDisplayChanged_hwcLayer() { public void testOnDisplayChanged_hwcLayer() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, false /* privacyDot */); 0 /* roundedPadding */, true /* fillCutout */, false /* privacyDot */);
final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport(); final DisplayDecorationSupport decorationSupport = new DisplayDecorationSupport();
decorationSupport.format = PixelFormat.R_8; decorationSupport.format = PixelFormat.R_8;
doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport(); doReturn(decorationSupport).when(mDisplay).getDisplayDecorationSupport();
@@ -1307,8 +1278,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testOnDisplayChanged_nonHwcLayer() { public void testOnDisplayChanged_nonHwcLayer() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, false /* privacyDot */); 0 /* roundedPadding */, 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};
@@ -1331,8 +1302,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testHasSameProvidersWithNullOverlays() { public void testHasSameProvidersWithNullOverlays() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
false /* fillCutout */, false /* privacyDot */); 0 /* roundedPadding */, false /* fillCutout */, false /* privacyDot */);
mScreenDecorations.start(); mScreenDecorations.start();
@@ -1349,8 +1320,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
@Test @Test
public void testHasSameProvidersWithPrivacyDots() { public void testHasSameProvidersWithPrivacyDots() {
setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */, setupResources(0 /* radius */, 0 /* radiusTop */, 0 /* radiusBottom */,
0 /* roundedPadding */, false /* multipleRadius */, null /* roundedTopDrawable */, null /* roundedBottomDrawable */,
true /* fillCutout */, true /* privacyDot */); 0 /* roundedPadding */, true /* fillCutout */, true /* privacyDot */);
mScreenDecorations.start(); mScreenDecorations.start();
@@ -1370,8 +1341,24 @@ public class ScreenDecorationsTest extends SysuiTestCase {
assertTrue(mScreenDecorations.hasSameProviders(newProviders)); assertTrue(mScreenDecorations.hasSameProviders(newProviders));
} }
private void setupResources(int radius, int radiusTop, int radiusBottom, int roundedPadding, private Size getDrawableIntrinsicSize(@DrawableRes int drawableResId) {
boolean multipleRadius, boolean fillCutout, boolean privacyDot) { 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( mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.array.config_displayUniqueIdArray, com.android.internal.R.array.config_displayUniqueIdArray,
new String[]{}); new String[]{});
@@ -1393,19 +1380,24 @@ public class ScreenDecorationsTest extends SysuiTestCase {
mContext.getOrCreateTestableResources().addOverride( mContext.getOrCreateTestableResources().addOverride(
R.array.config_roundedCornerBottomDrawableArray, R.array.config_roundedCornerBottomDrawableArray,
mMockTypedArray); mMockTypedArray);
mContext.getOrCreateTestableResources().addOverride(
R.array.config_roundedCornerMultipleRadiusArray,
mMockTypedArray);
mContext.getOrCreateTestableResources().addOverride( mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.dimen.rounded_corner_radius, radius); com.android.internal.R.dimen.rounded_corner_radius, radius);
mContext.getOrCreateTestableResources().addOverride( mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.dimen.rounded_corner_radius_top, radiusTop); com.android.internal.R.dimen.rounded_corner_radius_top, radiusTop);
mContext.getOrCreateTestableResources().addOverride( mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.dimen.rounded_corner_radius_bottom, radiusBottom); 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( mContext.getOrCreateTestableResources().addOverride(
R.dimen.rounded_corner_content_padding, roundedPadding); R.dimen.rounded_corner_content_padding, roundedPadding);
mContext.getOrCreateTestableResources().addOverride(
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);

View File

@@ -44,9 +44,8 @@ class RoundedCornerDecorProviderFactoryTest : SysuiTestCase() {
@Test @Test
fun testNoRoundedCorners() { fun testNoRoundedCorners() {
Mockito.doReturn(Size(0, 0)).`when`(roundedCornerResDelegate).topRoundedSize Mockito.doReturn(false).`when`(roundedCornerResDelegate).hasTop
Mockito.doReturn(Size(0, 0)).`when`(roundedCornerResDelegate).bottomRoundedSize Mockito.doReturn(false).`when`(roundedCornerResDelegate).hasBottom
Mockito.doReturn(false).`when`(roundedCornerResDelegate).isMultipleRadius
roundedCornerDecorProviderFactory = roundedCornerDecorProviderFactory =
RoundedCornerDecorProviderFactory(roundedCornerResDelegate) RoundedCornerDecorProviderFactory(roundedCornerResDelegate)
@@ -56,10 +55,10 @@ class RoundedCornerDecorProviderFactoryTest : SysuiTestCase() {
} }
@Test @Test
fun testHasRoundedCornersIfTopWidthLargerThan0() { fun testOnlyHasTopRoundedCorners() {
Mockito.doReturn(Size(1, 0)).`when`(roundedCornerResDelegate).topRoundedSize Mockito.doReturn(true).`when`(roundedCornerResDelegate).hasTop
Mockito.doReturn(Size(0, 0)).`when`(roundedCornerResDelegate).bottomRoundedSize Mockito.doReturn(false).`when`(roundedCornerResDelegate).hasBottom
Mockito.doReturn(false).`when`(roundedCornerResDelegate).isMultipleRadius Mockito.doReturn(Size(1, 1)).`when`(roundedCornerResDelegate).topRoundedSize
roundedCornerDecorProviderFactory = roundedCornerDecorProviderFactory =
RoundedCornerDecorProviderFactory(roundedCornerResDelegate) RoundedCornerDecorProviderFactory(roundedCornerResDelegate)
@@ -82,9 +81,9 @@ class RoundedCornerDecorProviderFactoryTest : SysuiTestCase() {
@Test @Test
fun testHasRoundedCornersIfBottomWidthLargerThan0() { 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(Size(1, 1)).`when`(roundedCornerResDelegate).bottomRoundedSize
Mockito.doReturn(false).`when`(roundedCornerResDelegate).isMultipleRadius
roundedCornerDecorProviderFactory = roundedCornerDecorProviderFactory =
RoundedCornerDecorProviderFactory(roundedCornerResDelegate) RoundedCornerDecorProviderFactory(roundedCornerResDelegate)
@@ -107,9 +106,10 @@ class RoundedCornerDecorProviderFactoryTest : SysuiTestCase() {
@Test @Test
fun test4CornerDecorProvidersInfo() { 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).topRoundedSize
Mockito.doReturn(Size(10, 10)).`when`(roundedCornerResDelegate).bottomRoundedSize Mockito.doReturn(Size(10, 10)).`when`(roundedCornerResDelegate).bottomRoundedSize
Mockito.doReturn(true).`when`(roundedCornerResDelegate).isMultipleRadius
roundedCornerDecorProviderFactory = roundedCornerDecorProviderFactory =
RoundedCornerDecorProviderFactory(roundedCornerResDelegate) RoundedCornerDecorProviderFactory(roundedCornerResDelegate)

View File

@@ -17,12 +17,14 @@
package com.android.systemui.decor package com.android.systemui.decor
import android.content.res.TypedArray import android.content.res.TypedArray
import android.graphics.drawable.VectorDrawable import android.graphics.drawable.Drawable
import android.testing.AndroidTestingRunner import android.testing.AndroidTestingRunner
import android.testing.TestableResources
import android.util.Size import android.util.Size
import androidx.annotation.DrawableRes
import androidx.test.filters.SmallTest 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 com.android.systemui.SysuiTestCase
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Before import org.junit.Before
@@ -44,67 +46,77 @@ class RoundedCornerResDelegateTest : SysuiTestCase() {
MockitoAnnotations.initMocks(this) MockitoAnnotations.initMocks(this)
} }
@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 @Test
fun testUpdateDisplayUniqueId() { fun testUpdateDisplayUniqueId() {
mContext.orCreateTestableResources.addOverrides( setupResources(radius = 100,
mockTypeArray = mockTypedArray, roundedTopDrawable = getTestsDrawable(R.drawable.rounded3px),
radius = 3, roundedBottomDrawable = getTestsDrawable(R.drawable.rounded4px))
radiusTop = 0,
radiusBottom = 4,
multipleRadius = false)
roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null) roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
assertEquals(Size(3, 3), roundedCornerResDelegate.topRoundedSize) assertEquals(Size(3, 3), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(4, 4), roundedCornerResDelegate.bottomRoundedSize) assertEquals(Size(4, 4), roundedCornerResDelegate.bottomRoundedSize)
assertEquals(false, roundedCornerResDelegate.isMultipleRadius)
mContext.orCreateTestableResources.addOverrides( setupResources(radius = 100,
mockTypeArray = mockTypedArray, roundedTopDrawable = getTestsDrawable(R.drawable.rounded4px),
radius = 5, roundedBottomDrawable = getTestsDrawable(R.drawable.rounded5px))
radiusTop = 6,
radiusBottom = 0)
roundedCornerResDelegate.updateDisplayUniqueId("test", null) roundedCornerResDelegate.updateDisplayUniqueId("test", null)
assertEquals(Size(6, 6), roundedCornerResDelegate.topRoundedSize) assertEquals(Size(4, 4), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(5, 5), roundedCornerResDelegate.bottomRoundedSize) assertEquals(Size(5, 5), roundedCornerResDelegate.bottomRoundedSize)
} }
@Test @Test
fun testNotUpdateDisplayUniqueIdButChangeRefreshToken() { fun testNotUpdateDisplayUniqueIdButChangeRefreshToken() {
mContext.orCreateTestableResources.addOverrides( setupResources(radius = 100,
mockTypeArray = mockTypedArray, roundedTopDrawable = getTestsDrawable(R.drawable.rounded3px),
radius = 3, roundedBottomDrawable = getTestsDrawable(R.drawable.rounded4px))
radiusTop = 0,
radiusBottom = 4,
multipleRadius = false)
roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null) roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
assertEquals(Size(3, 3), roundedCornerResDelegate.topRoundedSize) assertEquals(Size(3, 3), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(4, 4), roundedCornerResDelegate.bottomRoundedSize) assertEquals(Size(4, 4), roundedCornerResDelegate.bottomRoundedSize)
assertEquals(false, roundedCornerResDelegate.isMultipleRadius)
mContext.orCreateTestableResources.addOverrides( setupResources(radius = 100,
mockTypeArray = mockTypedArray, roundedTopDrawable = getTestsDrawable(R.drawable.rounded4px),
radius = 5, roundedBottomDrawable = getTestsDrawable(R.drawable.rounded5px))
radiusTop = 6,
radiusBottom = 0)
roundedCornerResDelegate.updateDisplayUniqueId(null, 1) roundedCornerResDelegate.updateDisplayUniqueId(null, 1)
assertEquals(Size(6, 6), roundedCornerResDelegate.topRoundedSize) assertEquals(Size(4, 4), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(5, 5), roundedCornerResDelegate.bottomRoundedSize) assertEquals(Size(5, 5), roundedCornerResDelegate.bottomRoundedSize)
} }
@Test @Test
fun testUpdateTuningSizeFactor() { fun testUpdateTuningSizeFactor() {
mContext.orCreateTestableResources.addOverrides( setupResources(radius = 100,
mockTypeArray = mockTypedArray, roundedTopDrawable = getTestsDrawable(R.drawable.rounded3px),
radiusTop = 2, roundedBottomDrawable = getTestsDrawable(R.drawable.rounded4px))
radiusBottom = 0,
multipleRadius = false)
roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null) roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
@@ -115,62 +127,43 @@ class RoundedCornerResDelegateTest : SysuiTestCase() {
assertEquals(Size(length, length), roundedCornerResDelegate.topRoundedSize) assertEquals(Size(length, length), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(length, length), roundedCornerResDelegate.bottomRoundedSize) assertEquals(Size(length, length), roundedCornerResDelegate.bottomRoundedSize)
mContext.orCreateTestableResources.addOverrides(
mockTypeArray = mockTypedArray,
radiusTop = 1,
radiusBottom = 2,
multipleRadius = false)
roundedCornerResDelegate.updateTuningSizeFactor(null, 2) roundedCornerResDelegate.updateTuningSizeFactor(null, 2)
assertEquals(Size(1, 1), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(2, 2), 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.topRoundedSize)
assertEquals(Size(3, 3), roundedCornerResDelegate.bottomRoundedSize) assertEquals(Size(4, 4), roundedCornerResDelegate.bottomRoundedSize)
} }
@Test private fun getTestsDrawable(@DrawableRes drawableId: Int): Drawable? {
fun testReadMultipleRadius() { return mContext.createPackageContext("com.android.systemui.tests", 0)
val d = mContext.getDrawable(R.drawable.rounded) as VectorDrawable .getDrawable(drawableId)
val multipleRadiusSize = Size(d.intrinsicWidth, d.intrinsicHeight) }
mContext.orCreateTestableResources.addOverrides(
mockTypeArray = mockTypedArray, private fun setupResources(
multipleRadius = true) radius: Int? = null,
roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null) radiusTop: Int? = null,
assertEquals(multipleRadiusSize, roundedCornerResDelegate.topRoundedSize) radiusBottom: Int? = null,
assertEquals(multipleRadiusSize, roundedCornerResDelegate.bottomRoundedSize) 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) }
}