diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt index 98be77dfa421f..ff8b0b287d37e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt @@ -155,18 +155,21 @@ class StatusBarContentInsetsProvider @Inject constructor( val isRtl = rotatedResources.configuration.layoutDirection == LAYOUT_DIRECTION_RTL val roundedCornerPadding = rotatedResources .getDimensionPixelSize(R.dimen.rounded_corner_content_padding) - val minDotWidth = if (isPrivacyDotEnabled) + val minDotPadding = if (isPrivacyDotEnabled) rotatedResources.getDimensionPixelSize(R.dimen.ongoing_appops_dot_min_padding) else 0 + val dotWidth = if (isPrivacyDotEnabled) + rotatedResources.getDimensionPixelSize(R.dimen.ongoing_appops_dot_diameter) + else 0 val minLeft: Int val minRight: Int if (isRtl) { - minLeft = max(minDotWidth, roundedCornerPadding) + minLeft = max(minDotPadding, roundedCornerPadding) minRight = roundedCornerPadding } else { minLeft = roundedCornerPadding - minRight = max(minDotWidth, roundedCornerPadding) + minRight = max(minDotPadding, roundedCornerPadding) } return calculateInsetsForRotationWithRotatedResources( @@ -176,7 +179,9 @@ class StatusBarContentInsetsProvider @Inject constructor( context.resources.configuration.windowConfiguration.maxBounds, rotatedResources.getDimensionPixelSize(R.dimen.status_bar_height), minLeft, - minRight) + minRight, + isRtl, + dotWidth) } override fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array) { @@ -240,10 +245,13 @@ fun getPrivacyChipBoundingRectForInsets( * * @param currentRotation current device rotation * @param targetRotation rotation for which to calculate the status bar content rect - * @param displayCutout [DisplayCutout] for the curren display. possibly null + * @param displayCutout [DisplayCutout] for the current display. possibly null * @param windowMetrics [WindowMetrics] for the current window * @param statusBarHeight height of the status bar for the target rotation - * @param roundedCornerPadding from rounded_corner_content_padding + * @param minLeft the minimum padding to enforce on the left + * @param minRight the minimum padding to enforce on the right + * @param isRtl current layout direction is Right-To-Left or not + * @param dotWidth privacy dot image width (0 if privacy dot is disabled) * * @see [RotationUtils#getResourcesForRotation] */ @@ -254,7 +262,9 @@ fun calculateInsetsForRotationWithRotatedResources( maxBounds: Rect, statusBarHeight: Int, minLeft: Int, - minRight: Int + minRight: Int, + isRtl: Boolean, + dotWidth: Int ): Rect { /* TODO: Check if this is ever used for devices with no rounded corners @@ -273,6 +283,8 @@ fun calculateInsetsForRotationWithRotatedResources( maxBounds.height(), minLeft, minRight, + isRtl, + dotWidth, targetRotation, currentRotation) @@ -290,6 +302,8 @@ fun calculateInsetsForRotationWithRotatedResources( * @param cHeight display height in our current rotation * @param minLeft the minimum padding to enforce on the left * @param minRight the minimum padding to enforce on the right + * @param isRtl current layout direction is Right-To-Left or not + * @param dotWidth privacy dot image width (0 if privacy dot is disabled) * @param targetRotation the rotation for which to calculate margins * @param currentRotation the rotation from which the display cutout was generated * @@ -305,6 +319,8 @@ private fun getStatusBarLeftRight( cHeight: Int, minLeft: Int, minRight: Int, + isRtl: Boolean, + dotWidth: Int, @Rotation targetRotation: Int, @Rotation currentRotation: Int ): Rect { @@ -339,13 +355,16 @@ private fun getStatusBarLeftRight( } if (cutoutRect.touchesLeftEdge(relativeRotation, cWidth, cHeight)) { - - val l = max(minLeft, cutoutRect.logicalWidth(relativeRotation)) - leftMargin = max(l, leftMargin) + var logicalWidth = cutoutRect.logicalWidth(relativeRotation) + if (isRtl) logicalWidth += dotWidth + leftMargin = max(logicalWidth, leftMargin) } else if (cutoutRect.touchesRightEdge(relativeRotation, cWidth, cHeight)) { - val logicalWidth = cutoutRect.logicalWidth(relativeRotation) - rightMargin = max(minRight, logicalWidth) + var logicalWidth = cutoutRect.logicalWidth(relativeRotation) + if (!isRtl) logicalWidth += dotWidth + rightMargin = max(rightMargin, logicalWidth) } + // TODO(b/203626889): Fix the scenario when config_mainBuiltInDisplayCutoutRectApproximation + // is very close to but not directly touch edges. } return Rect(leftMargin, 0, logicalDisplayWidth - rightMargin, sbHeight) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt index 1503af82545c1..e5158e74759ca 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt @@ -86,7 +86,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, - minRightPadding) + minRightPadding, + isRtl, + dotWidth) var chipBounds = getPrivacyChipBoundingRectForInsets(bounds, dotWidth, chipWidth, isRtl) /* 1080 - 20 (rounded corner) - 30 (chip), @@ -115,7 +117,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, - minRightPadding) + minRightPadding, + isRtl, + dotWidth) chipBounds = getPrivacyChipBoundingRectForInsets(bounds, dotWidth, chipWidth, isRtl) /* 2160 - 20 (rounded corner) - 30 (chip), @@ -146,6 +150,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { val sbHeightPortrait = 100 val sbHeightLandscape = 60 val currentRotation = ROTATION_NONE + val isRtl = false + val dotWidth = 10 `when`(dc.boundingRects).thenReturn(listOf(dcBounds)) @@ -164,7 +170,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, - minRightPadding) + minRightPadding, + isRtl, + dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) @@ -181,7 +189,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, - minRightPadding) + minRightPadding, + isRtl, + dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) @@ -200,7 +210,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, - minRightPadding) + minRightPadding, + isRtl, + dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) @@ -208,7 +220,7 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { targetRotation = ROTATION_SEASCAPE expectedBounds = Rect(minLeftPadding, 0, - screenBounds.height() - dcBounds.height(), + screenBounds.height() - dcBounds.height() - dotWidth, sbHeightLandscape) bounds = calculateInsetsForRotationWithRotatedResources( @@ -218,7 +230,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, - minRightPadding) + minRightPadding, + isRtl, + dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) } @@ -237,6 +251,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { val sbHeightPortrait = 100 val sbHeightLandscape = 60 val currentRotation = ROTATION_NONE + val isRtl = false + val dotWidth = 10 `when`(dc.boundingRects).thenReturn(listOf(dcBounds)) @@ -255,7 +271,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, - minRightPadding) + minRightPadding, + isRtl, + dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) @@ -272,7 +290,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, - minRightPadding) + minRightPadding, + isRtl, + dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) @@ -289,14 +309,16 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, - minRightPadding) + minRightPadding, + isRtl, + dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) targetRotation = ROTATION_SEASCAPE expectedBounds = Rect(minLeftPadding, 0, - screenBounds.height() - dcBounds.height(), + screenBounds.height() - dcBounds.height() - dotWidth, sbHeightLandscape) bounds = calculateInsetsForRotationWithRotatedResources( @@ -306,7 +328,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, - minRightPadding) + minRightPadding, + isRtl, + dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) } @@ -320,6 +344,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { val minRightPadding = 20 val sbHeightPortrait = 100 val sbHeightLandscape = 60 + val isRtl = false + val dotWidth = 10 // THEN content insets should only use rounded corner padding var targetRotation = ROTATION_NONE @@ -335,7 +361,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, - minRightPadding) + minRightPadding, + isRtl, + dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) targetRotation = ROTATION_LANDSCAPE @@ -351,7 +379,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, - minRightPadding) + minRightPadding, + isRtl, + dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) targetRotation = ROTATION_UPSIDE_DOWN @@ -367,7 +397,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, - minRightPadding) + minRightPadding, + isRtl, + dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) targetRotation = ROTATION_LANDSCAPE @@ -383,7 +415,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, - minRightPadding) + minRightPadding, + isRtl, + dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) } @@ -397,6 +431,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { val sbHeightPortrait = 100 val sbHeightLandscape = 60 val currentRotation = ROTATION_NONE + val isRtl = false + val dotWidth = 10 `when`(dc.boundingRects).thenReturn(listOf(dcBounds)) @@ -414,7 +450,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, - minRightPadding) + minRightPadding, + isRtl, + dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) }