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

Commit 2ba0baa9 authored by Chris Göllner's avatar Chris Göllner Committed by Chris Göllner
Browse files

Fix status bar content not being vertically centered on external display

On some devices a bottom aligned margin is defined in resources in order
to keep content aligned with a cutout.

This margin was being misapplied to external displays too, even when
they don't have a cutout.

Test: StatusBarContentInsetsProviderTest.kt
Flag: com.android.systemui.shared.status_bar_connected_displays
Fixes: 415946675
Change-Id: Ief6b46ee19981bc7ae38b2c073329c28f151afd6
parent 11908b1a
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -720,6 +720,27 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
        assertThat(bounds.top).isEqualTo(expectedTopInset)
    }

    @Test
    fun calculateInsetsForRotationWithRotatedResources_bottomAlignedMargin_noCutout_topIsZero() {
        val bounds =
            calculateInsetsForRotationWithRotatedResources(
                currentRotation = ROTATION_NONE,
                targetRotation = ROTATION_NONE,
                sysUICutout = null,
                maxBounds = Rect(0, 0, 1080, 2160),
                statusBarHeight = 100,
                minLeft = 0,
                minRight = 0,
                isRtl = false,
                dotWidth = 10,
                bottomAlignedMargin = 5,
                statusBarContentHeight = 15,
            )

        // Bottom aligned margin should only be take into account for displays with a cutout.
        assertThat(bounds.top).isEqualTo(0)
    }

    @Test
    fun testCalculateInsetsForRotationWithRotatedResources_nonCornerCutout() {
        // GIVEN phone in portrait mode, where width < height and the cutout is not in the corner
+5 −2
Original line number Diff line number Diff line
@@ -573,7 +573,7 @@ private fun getStatusBarContentBounds(
    bottomAlignedMargin: Int,
    statusBarContentHeight: Int,
): Rect {
    val insetTop = getInsetTop(bottomAlignedMargin, statusBarContentHeight, sbHeight)
    val insetTop = getInsetTop(bottomAlignedMargin, statusBarContentHeight, sbHeight, sysUICutout)

    val logicalDisplayWidth = if (targetRotation.isHorizontal()) height else width

@@ -666,8 +666,11 @@ private fun getInsetTop(
    bottomAlignedMargin: Int,
    statusBarContentHeight: Int,
    statusBarHeight: Int,
    sysUICutout: SysUICutoutInformation?,
): Int {
    val bottomAlignmentEnabled = bottomAlignedMargin >= 0
    // This bottom aligned margin is only intended for displays with a cutout, so that the
    // content can be aligned with the cutout, when it isn't centered.
    val bottomAlignmentEnabled = bottomAlignedMargin >= 0 && sysUICutout != null
    if (!bottomAlignmentEnabled) {
        return 0
    }