Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit efec6624 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Prevent privacy dot overlapped by cutout" into sc-v2-dev

parents cb7e987b a391fdc1
Loading
Loading
Loading
Loading
+31 −12
Original line number Diff line number Diff line
@@ -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(
@@ -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 {
@@ -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]
 */
@@ -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
@@ -279,6 +289,8 @@ fun calculateInsetsForRotationWithRotatedResources(
            maxBounds.height(),
            minLeft,
            minRight,
            isRtl,
            dotWidth,
            targetRotation,
            currentRotation)

@@ -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
 *
@@ -311,6 +325,8 @@ private fun getStatusBarLeftRight(
    cHeight: Int,
    minLeft: Int,
    minRight: Int,
    isRtl: Boolean,
    dotWidth: Int,
    @Rotation targetRotation: Int,
    @Rotation currentRotation: Int
): Rect {
@@ -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)
+55 −17
Original line number Diff line number Diff line
@@ -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)
    }