Loading packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt +31 −12 Original line number Diff line number Diff line Loading @@ -156,18 +156,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( Loading @@ -177,7 +180,9 @@ class StatusBarContentInsetsProvider @Inject constructor( context.resources.configuration.windowConfiguration.maxBounds, SystemBarUtils.getStatusBarHeight(context), minLeft, minRight) minRight, isRtl, dotWidth) } fun getStatusBarPaddingTop(@Rotation rotation: Int? = null): Int { Loading Loading @@ -246,10 +251,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] */ Loading @@ -260,7 +268,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 Loading @@ -279,6 +289,8 @@ fun calculateInsetsForRotationWithRotatedResources( maxBounds.height(), minLeft, minRight, isRtl, dotWidth, targetRotation, currentRotation) Loading @@ -296,6 +308,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 * Loading @@ -311,6 +325,8 @@ private fun getStatusBarLeftRight( cHeight: Int, minLeft: Int, minRight: Int, isRtl: Boolean, dotWidth: Int, @Rotation targetRotation: Int, @Rotation currentRotation: Int ): Rect { Loading Loading @@ -345,13 +361,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) Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt +55 −17 Original line number Diff line number Diff line Loading @@ -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), Loading Loading @@ -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), Loading Loading @@ -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)) Loading @@ -164,7 +170,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) Loading @@ -181,7 +189,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) Loading @@ -200,7 +210,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) Loading @@ -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( Loading @@ -218,7 +230,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) } Loading @@ -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)) Loading @@ -255,7 +271,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) Loading @@ -272,7 +290,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) Loading @@ -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( Loading @@ -306,7 +328,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) } Loading @@ -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 Loading @@ -335,7 +361,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) targetRotation = ROTATION_LANDSCAPE Loading @@ -351,7 +379,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) targetRotation = ROTATION_UPSIDE_DOWN Loading @@ -367,7 +397,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) targetRotation = ROTATION_LANDSCAPE Loading @@ -383,7 +415,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) } Loading @@ -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)) Loading @@ -414,7 +450,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) } Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt +31 −12 Original line number Diff line number Diff line Loading @@ -156,18 +156,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( Loading @@ -177,7 +180,9 @@ class StatusBarContentInsetsProvider @Inject constructor( context.resources.configuration.windowConfiguration.maxBounds, SystemBarUtils.getStatusBarHeight(context), minLeft, minRight) minRight, isRtl, dotWidth) } fun getStatusBarPaddingTop(@Rotation rotation: Int? = null): Int { Loading Loading @@ -246,10 +251,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] */ Loading @@ -260,7 +268,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 Loading @@ -279,6 +289,8 @@ fun calculateInsetsForRotationWithRotatedResources( maxBounds.height(), minLeft, minRight, isRtl, dotWidth, targetRotation, currentRotation) Loading @@ -296,6 +308,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 * Loading @@ -311,6 +325,8 @@ private fun getStatusBarLeftRight( cHeight: Int, minLeft: Int, minRight: Int, isRtl: Boolean, dotWidth: Int, @Rotation targetRotation: Int, @Rotation currentRotation: Int ): Rect { Loading Loading @@ -345,13 +361,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) Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt +55 −17 Original line number Diff line number Diff line Loading @@ -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), Loading Loading @@ -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), Loading Loading @@ -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)) Loading @@ -164,7 +170,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) Loading @@ -181,7 +189,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) Loading @@ -200,7 +210,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) Loading @@ -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( Loading @@ -218,7 +230,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) } Loading @@ -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)) Loading @@ -255,7 +271,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) Loading @@ -272,7 +290,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) Loading @@ -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( Loading @@ -306,7 +328,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) } Loading @@ -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 Loading @@ -335,7 +361,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) targetRotation = ROTATION_LANDSCAPE Loading @@ -351,7 +379,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) targetRotation = ROTATION_UPSIDE_DOWN Loading @@ -367,7 +397,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) targetRotation = ROTATION_LANDSCAPE Loading @@ -383,7 +415,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightLandscape, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) } Loading @@ -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)) Loading @@ -414,7 +450,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { screenBounds, sbHeightPortrait, minLeftPadding, minRightPadding) minRightPadding, isRtl, dotWidth) assertRects(expectedBounds, bounds, currentRotation, targetRotation) } Loading