From 9ae18fa2d9bafbd2df4cfdbf93a9714b90be6b6a Mon Sep 17 00:00:00 2001 From: Bill Lin Date: Fri, 14 Feb 2020 15:08:13 +0800 Subject: [PATCH] DO NOT MERGE Respect rounded.xml size in ScreenDecorations Suppose vendors will customize rounded.xml with corresponding multiple radius path and size, ScreenDecorations should not resize it by rounded_corner_radius in case jagged edges problem Test: atest SystemUITests Test: atest ScreenDecorationsTest Bug: 145707162 Bug: 148912090 Change-Id: Ie33526214072ad324ca00a10074ad212dfbf4258 --- packages/SystemUI/res/values/config.xml | 3 + .../android/systemui/ScreenDecorations.java | 24 +++++-- .../systemui/ScreenDecorationsTest.java | 65 +++++++++++++++++++ 3 files changed, 86 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index 78318cb7e8584..7fd9d3c7e1e8f 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -480,4 +480,7 @@ -1 + + false + diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java index f38b4f259c88c..953e9f54ba280 100644 --- a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java +++ b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java @@ -45,6 +45,7 @@ import android.graphics.Path; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.Region; +import android.graphics.drawable.VectorDrawable; import android.hardware.display.DisplayManager; import android.os.Handler; import android.os.HandlerThread; @@ -129,6 +130,7 @@ public class ScreenDecorations extends SystemUI implements Tunable, private boolean mAssistHintBlocked = false; private boolean mIsReceivingNavBarColor = false; private boolean mInGesturalMode; + private boolean mIsRoundedCornerMultipleRadius; /** * Converts a set of {@link Rect}s into a {@link Region} @@ -323,6 +325,8 @@ public class ScreenDecorations extends SystemUI implements Tunable, private void startOnScreenDecorationsThread() { mRotation = RotationUtils.getExactRotation(mContext); mWindowManager = mContext.getSystemService(WindowManager.class); + mIsRoundedCornerMultipleRadius = mContext.getResources().getBoolean( + R.bool.config_roundedCornerMultipleRadius); updateRoundedCornerRadii(); if (hasRoundedCorners() || shouldDrawCutout() || shouldHostHandles()) { setupDecorations(); @@ -528,17 +532,24 @@ public class ScreenDecorations extends SystemUI implements Tunable, com.android.internal.R.dimen.rounded_corner_radius_top); final int newRoundedDefaultBottom = mContext.getResources().getDimensionPixelSize( com.android.internal.R.dimen.rounded_corner_radius_bottom); - final boolean roundedCornersChanged = mRoundedDefault != newRoundedDefault || mRoundedDefaultBottom != newRoundedDefaultBottom || mRoundedDefaultTop != newRoundedDefaultTop; if (roundedCornersChanged) { - mRoundedDefault = newRoundedDefault; - mRoundedDefaultTop = newRoundedDefaultTop; - mRoundedDefaultBottom = newRoundedDefaultBottom; - onTuningChanged(SIZE, null); + // If config_roundedCornerMultipleRadius set as true, ScreenDecorations respect the + // max(width, height) size of drawable/rounded.xml instead of rounded_corner_radius + if (mIsRoundedCornerMultipleRadius) { + final VectorDrawable d = (VectorDrawable) mContext.getDrawable(R.drawable.rounded); + mRoundedDefault = Math.max(d.getIntrinsicWidth(), d.getIntrinsicHeight()); + mRoundedDefaultTop = mRoundedDefaultBottom = mRoundedDefault; + } else { + mRoundedDefault = newRoundedDefault; + mRoundedDefaultTop = newRoundedDefaultTop; + mRoundedDefaultBottom = newRoundedDefaultBottom; + } } + onTuningChanged(SIZE, null); } private void updateViews() { @@ -637,7 +648,8 @@ public class ScreenDecorations extends SystemUI implements Tunable, } private boolean hasRoundedCorners() { - return mRoundedDefault > 0 || mRoundedDefaultBottom > 0 || mRoundedDefaultTop > 0; + return mRoundedDefault > 0 || mRoundedDefaultBottom > 0 || mRoundedDefaultTop > 0 + || mIsRoundedCornerMultipleRadius; } private boolean shouldDrawCutout() { diff --git a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java index 3b5e12c4ef961..11b256a4da010 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java @@ -20,6 +20,8 @@ import static com.android.systemui.ScreenDecorations.rectsToRegion; import static com.android.systemui.tuner.TunablePadding.FLAG_END; import static com.android.systemui.tuner.TunablePadding.FLAG_START; +import static com.google.common.truth.Truth.assertThat; + import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; @@ -38,6 +40,7 @@ import static org.mockito.Mockito.when; import android.app.Fragment; import android.content.res.Configuration; import android.graphics.Rect; +import android.graphics.drawable.VectorDrawable; import android.os.Handler; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; @@ -148,6 +151,8 @@ public class ScreenDecorationsTest extends SysuiTestCase { com.android.internal.R.dimen.rounded_corner_radius_bottom, 0); mContext.getOrCreateTestableResources() .addOverride(dimen.rounded_corner_content_padding, 0); + mContext.getOrCreateTestableResources() + .addOverride(R.bool.config_roundedCornerMultipleRadius, false); mScreenDecorations.start(); // No views added. @@ -166,6 +171,8 @@ public class ScreenDecorationsTest extends SysuiTestCase { com.android.internal.R.dimen.rounded_corner_radius, 20); mContext.getOrCreateTestableResources() .addOverride(dimen.rounded_corner_content_padding, 20); + mContext.getOrCreateTestableResources() + .addOverride(R.bool.config_roundedCornerMultipleRadius, false); mScreenDecorations.start(); // Add 2 windows for rounded corners (top and bottom). @@ -179,6 +186,57 @@ public class ScreenDecorationsTest extends SysuiTestCase { verify(mTunablePaddingService, times(1)).add(any(), anyString(), anyInt(), anyInt()); } + @Test + public void testRoundingRadius() { + final int testRadius = 1; + mContext.getOrCreateTestableResources().addOverride( + com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false); + mContext.getOrCreateTestableResources().addOverride( + com.android.internal.R.dimen.rounded_corner_radius, testRadius); + mContext.getOrCreateTestableResources().addOverride( + com.android.internal.R.dimen.rounded_corner_radius_top, testRadius); + mContext.getOrCreateTestableResources().addOverride( + com.android.internal.R.dimen.rounded_corner_radius_bottom, testRadius); + mContext.getOrCreateTestableResources() + .addOverride(R.bool.config_roundedCornerMultipleRadius, false); + + mScreenDecorations.start(); + // Size of corner view should same as rounded_corner_radius{_top|_bottom} + assertThat(mScreenDecorations.mRoundedDefault).isEqualTo(testRadius); + assertThat(mScreenDecorations.mRoundedDefaultTop).isEqualTo(testRadius); + assertThat(mScreenDecorations.mRoundedDefaultBottom).isEqualTo(testRadius); + } + + @Test + public void testRoundingMultipleRadius() { + final VectorDrawable d = (VectorDrawable) mContext.getDrawable(R.drawable.rounded); + final int multipleRadiusSize = Math.max(d.getIntrinsicWidth(), d.getIntrinsicHeight()); + + mContext.getOrCreateTestableResources().addOverride( + com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false); + mContext.getOrCreateTestableResources().addOverride( + com.android.internal.R.dimen.rounded_corner_radius, 9999); + mContext.getOrCreateTestableResources() + .addOverride(dimen.rounded_corner_content_padding, 9999); + mContext.getOrCreateTestableResources() + .addOverride(R.bool.config_roundedCornerMultipleRadius, true); + + mScreenDecorations.start(); + // Add 2 windows for rounded corners (top and bottom). + verify(mWindowManager, times(2)).addView(any(), any()); + + // Add 2 tag listeners for each of the fragments that are needed. + verify(mFragmentHostManager, times(2)).addTagListener(any(), any()); + // One tunable. + verify(mTunerService, times(1)).addTunable(any(), any()); + // One TunablePadding. + verify(mTunablePaddingService, times(1)).add(any(), anyString(), anyInt(), anyInt()); + // Size of corner view should exactly match max(width, height) of R.drawable.rounded + assertThat(mScreenDecorations.mRoundedDefault).isEqualTo(multipleRadiusSize); + assertThat(mScreenDecorations.mRoundedDefaultTop).isEqualTo(multipleRadiusSize); + assertThat(mScreenDecorations.mRoundedDefaultBottom).isEqualTo(multipleRadiusSize); + } + @Test public void testCutout() { mContext.getOrCreateTestableResources().addOverride( @@ -224,6 +282,9 @@ public class ScreenDecorationsTest extends SysuiTestCase { com.android.internal.R.dimen.rounded_corner_radius_bottom, 0); mContext.getOrCreateTestableResources() .addOverride(dimen.rounded_corner_content_padding, 0); + mContext.getOrCreateTestableResources() + .addOverride(R.bool.config_roundedCornerMultipleRadius, false); + when(mNavigationModeController.addListener(any())).thenReturn( WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL); @@ -245,6 +306,8 @@ public class ScreenDecorationsTest extends SysuiTestCase { com.android.internal.R.dimen.rounded_corner_radius_bottom, 0); mContext.getOrCreateTestableResources() .addOverride(dimen.rounded_corner_content_padding, 0); + mContext.getOrCreateTestableResources() + .addOverride(R.bool.config_roundedCornerMultipleRadius, false); when(mNavigationModeController.addListener(any())).thenReturn( WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON); @@ -296,6 +359,8 @@ public class ScreenDecorationsTest extends SysuiTestCase { com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false); mContext.getOrCreateTestableResources().addOverride( com.android.internal.R.dimen.rounded_corner_radius, 20); + mContext.getOrCreateTestableResources() + .addOverride(R.bool.config_roundedCornerMultipleRadius, false); mScreenDecorations.start(); assertEquals(mScreenDecorations.mRoundedDefault, 20);