From d92271849c98ede4d0a0222ef852594c884dbc0e Mon Sep 17 00:00:00 2001 From: Jordan Silva Date: Thu, 17 Aug 2023 15:53:59 +0100 Subject: [PATCH] Fix hotseat border space crash GSI Fix the calculation of the space between the icons for hotseat when the number of spaces needed is 0 or less. Fix: 285834082 Flag: N/A Test: HotseatWidthCalculationTest Change-Id: I73bc1950277c01ac0ae7202c1e08bf45266b59b8 --- src/com/android/launcher3/DeviceProfile.java | 7 ++++--- .../HotseatWidthCalculationTest.kt | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 7ece9a4145..a48c9288d3 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -1134,10 +1134,11 @@ public class DeviceProfile { * This method calculates the space between the icons to achieve a certain width. */ private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) { + int numBorders = (numShownHotseatIcons - 1 + numExtraBorder); + if (numBorders <= 0) return 0; + float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons; - int hotseatBorderSpacePx = - (int) (hotseatWidthPx - hotseatIconsTotalPx) - / (numShownHotseatIcons - 1 + numExtraBorder); + int hotseatBorderSpacePx = (int) (hotseatWidthPx - hotseatIconsTotalPx) / numBorders; return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx); } diff --git a/tests/src/com/android/launcher3/nonquickstep/HotseatWidthCalculationTest.kt b/tests/src/com/android/launcher3/nonquickstep/HotseatWidthCalculationTest.kt index 2a27487e3b..d10239762b 100644 --- a/tests/src/com/android/launcher3/nonquickstep/HotseatWidthCalculationTest.kt +++ b/tests/src/com/android/launcher3/nonquickstep/HotseatWidthCalculationTest.kt @@ -158,4 +158,25 @@ class HotseatWidthCalculationTest : FakeInvariantDeviceProfileTest() { assertThat(dp.isQsbInline).isFalse() assertThat(dp.hotseatQsbWidth).isEqualTo(1095) } + + @Test + fun border_space_should_be_zero_when_numHotseatIcons_is_smallerOrEqual_1() { + initializeVarsForTablet(isGestureMode = false) + windowBounds = WindowBounds(Rect(0, 0, 1800, 2560), Rect(0, 104, 0, 0)) + + val numShownHotseatIcons = listOf(-1, 0, 1) + for (numHotseatIcons in numShownHotseatIcons) { + inv?.numShownHotseatIcons = numHotseatIcons + + val dp = newDP() + dp.isTaskbarPresentInApps = true + + assertThat(dp.numShownHotseatIcons).isEqualTo(numHotseatIcons) + assertThat(dp.hotseatBorderSpace).isEqualTo(0) + + assertThat(dp.getHotseatLayoutPadding(context).left).isEqualTo(177) + assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(177) + assertThat(dp.hotseatQsbWidth).isEqualTo(1445) + } + } }