Re-land "Support tuning sysui_rounded_size"

Previous sysui_rounded_size only works on device w/o rounded_corner_top
or rounded_corner_bottom. Support tuning sysui_rounded_size for all
cases.

Previous landed CL: ag/17200803
Previous reverted CL: ag/17352247

Bug: 220659061

Test: atest RoundedCornerResDelegateTest ScreenDecorHwcLayerTest \
            ScreenDecorationsTest
Test: Manually check rounded corner size on normal phone, hardware-layer
      phone with 'adb shell settings put secure sysui_rounded_size XX'
Change-Id: I9ad2410e69abe3626d054cdee63c7b0a44aa1da1
This commit is contained in:
Milton Wu
2022-03-24 13:23:25 +08:00
parent 82c6e424d2
commit 6e35c4b208
4 changed files with 25 additions and 38 deletions

View File

@@ -369,10 +369,15 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec
* Update the rounded corner size. * Update the rounded corner size.
*/ */
fun updateRoundedCornerSize(top: Int, bottom: Int) { fun updateRoundedCornerSize(top: Int, bottom: Int) {
if (roundedCornerTopSize == top && roundedCornerBottomSize == bottom) {
return
}
roundedCornerTopSize = top roundedCornerTopSize = top
roundedCornerBottomSize = bottom roundedCornerBottomSize = bottom
updateRoundedCornerDrawableBounds() updateRoundedCornerDrawableBounds()
invalidate()
// Use requestLayout() to trigger transparent region recalculated
requestLayout()
} }
private fun updateRoundedCornerDrawableBounds() { private fun updateRoundedCornerDrawableBounds() {

View File

@@ -1045,13 +1045,22 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
mExecutor.execute(() -> { mExecutor.execute(() -> {
if (mOverlays == null) return; if (mOverlays == null) return;
if (SIZE.equals(key)) { if (SIZE.equals(key)) {
boolean hasReloadRoundedCornerRes = false;
if (newValue != null) { if (newValue != null) {
try { try {
mRoundedCornerResDelegate.updateTuningSizeFactor( mRoundedCornerResDelegate.updateTuningSizeFactor(
Integer.parseInt(newValue)); Integer.parseInt(newValue));
hasReloadRoundedCornerRes = true;
} catch (Exception e) { } catch (Exception e) {
} }
} }
// When onTuningChanged() is not called through updateRoundedCornerRadii(),
// we need to reload rounded corner res to prevent incorrect dimen
if (!hasReloadRoundedCornerRes) {
mRoundedCornerResDelegate.reloadAll(mDisplayUniqueId);
}
updateRoundedCornerSize( updateRoundedCornerSize(
mRoundedCornerResDelegate.getTopRoundedSize(), mRoundedCornerResDelegate.getTopRoundedSize(),
mRoundedCornerResDelegate.getBottomRoundedSize()); mRoundedCornerResDelegate.getBottomRoundedSize());

View File

@@ -56,17 +56,17 @@ class RoundedCornerResDelegate(
private set private set
init { init {
reloadDrawables() reloadRes()
reloadMeasures() reloadMeasures()
} }
fun reloadAll(newDisplayUniqueId: String?) { fun reloadAll(newDisplayUniqueId: String?) {
displayUniqueId = newDisplayUniqueId displayUniqueId = newDisplayUniqueId
reloadDrawables() reloadRes()
reloadMeasures() reloadMeasures()
} }
private fun reloadDrawables() { private fun reloadRes() {
val configIdx = DisplayUtils.getDisplayUniqueIdConfigIndex(res, displayUniqueId) val configIdx = DisplayUtils.getDisplayUniqueIdConfigIndex(res, displayUniqueId)
isMultipleRadius = getIsMultipleRadius(configIdx) isMultipleRadius = getIsMultipleRadius(configIdx)
@@ -85,34 +85,6 @@ class RoundedCornerResDelegate(
arrayResId = R.array.config_roundedCornerBottomDrawableArray, arrayResId = R.array.config_roundedCornerBottomDrawableArray,
backupDrawableId = R.drawable.rounded_corner_bottom backupDrawableId = R.drawable.rounded_corner_bottom
) ?: roundedDrawable ) ?: roundedDrawable
// 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
}
if (bottomRoundedSize.width == 0) {
bottomRoundedSize = roundedSize
}
} }
private fun reloadMeasures(roundedSizeFactor: Int? = null) { private fun reloadMeasures(roundedSizeFactor: Int? = null) {
@@ -137,17 +109,18 @@ class RoundedCornerResDelegate(
bottomRoundedSize = Size(bottomRadius, bottomRadius) bottomRoundedSize = Size(bottomRadius, bottomRadius)
} }
roundedSizeFactor ?.let {
val length: Int = (it * density).toInt()
roundedSize = Size(length, length)
}
if (topRoundedSize.width == 0) { if (topRoundedSize.width == 0) {
topRoundedSize = roundedSize topRoundedSize = roundedSize
} }
if (bottomRoundedSize.width == 0) { if (bottomRoundedSize.width == 0) {
bottomRoundedSize = roundedSize bottomRoundedSize = roundedSize
} }
if (roundedSizeFactor != null && roundedSizeFactor > 0) {
val length: Int = (roundedSizeFactor * density).toInt()
topRoundedSize = Size(length, length)
bottomRoundedSize = Size(length, length)
}
} }
fun updateTuningSizeFactor(factor: Int) { fun updateTuningSizeFactor(factor: Int) {

View File

@@ -75,7 +75,7 @@ class RoundedCornerResDelegateTest : SysuiTestCase() {
fun testUpdateTuningSizeFactor() { fun testUpdateTuningSizeFactor() {
mContext.orCreateTestableResources.addOverrides( mContext.orCreateTestableResources.addOverrides(
mockTypeArray = mockTypedArray, mockTypeArray = mockTypedArray,
radiusTop = 0, radiusTop = 2,
radiusBottom = 0, radiusBottom = 0,
multipleRadius = false) multipleRadius = false)