Fix letterbox overlapping with status bar icons after rotating device

When the device rotates or status bar icon bounds change, we re-use the
previously cached letterbox details that were sent from WindowManager.

Also, when calculating whether there was an overlap between the icons
and the letterbox, we were using the Rect#intersect API instead of
Rect#instersects, which actually mutates the Rect, which was then
cached, and used for the next calculation.

The fix is to use the API that doesn't mutate the Rect.

Fixes: 287508741
Test: LetterboxAppearanceCalculatorTest.kt
Change-Id: I3c6be62ef673b674f3305ae254494dd41c5cce29
(cherry picked from commit 6928a93447)
This commit is contained in:
Christian Göllner
2023-06-23 12:49:01 +01:00
committed by Christian Göllner
parent 68c74f4c51
commit 5e46200477
2 changed files with 25 additions and 1 deletions

View File

@@ -209,7 +209,7 @@ constructor(
if (this.contains(other) || other.contains(this)) {
return false
}
return this.intersect(other)
return this.intersects(other.left, other.top, other.right, other.bottom)
}
override fun dump(pw: PrintWriter, args: Array<out String>) {

View File

@@ -105,6 +105,30 @@ class LetterboxAppearanceCalculatorTest : SysuiTestCase() {
expect.that(letterboxAppearance.appearanceRegions).isEqualTo(TEST_APPEARANCE_REGIONS)
}
/** Regression test for b/287508741 */
@Test
fun getLetterboxAppearance_withOverlap_doesNotMutateOriginalBounds() {
val statusBarStartSideBounds = Rect(left = 0, top = 0, right = 100, bottom = 100)
val statusBarEndSideBounds = Rect(left = 200, top = 0, right = 300, bottom = 100)
val letterBoxInnerBounds = Rect(left = 150, top = 50, right = 250, bottom = 150)
val statusBarStartSideBoundsCopy = Rect(statusBarStartSideBounds)
val statusBarEndSideBoundsCopy = Rect(statusBarEndSideBounds)
val letterBoxInnerBoundsCopy = Rect(letterBoxInnerBounds)
whenever(statusBarBoundsProvider.visibleStartSideBounds)
.thenReturn(statusBarStartSideBounds)
whenever(statusBarBoundsProvider.visibleEndSideBounds).thenReturn(statusBarEndSideBounds)
calculator.getLetterboxAppearance(
TEST_APPEARANCE,
TEST_APPEARANCE_REGIONS,
arrayOf(letterboxWithInnerBounds(letterBoxInnerBounds))
)
expect.that(statusBarStartSideBounds).isEqualTo(statusBarStartSideBoundsCopy)
expect.that(statusBarEndSideBounds).isEqualTo(statusBarEndSideBoundsCopy)
expect.that(letterBoxInnerBounds).isEqualTo(letterBoxInnerBoundsCopy)
}
@Test
fun getLetterboxAppearance_noOverlap_BackgroundMultiColor_returnsAppearanceWithScrim() {
whenever(letterboxBackgroundProvider.isLetterboxBackgroundMultiColored).thenReturn(true)