diff options
| author | 2024-02-06 16:54:30 +0000 | |
|---|---|---|
| committer | 2024-02-09 13:06:56 +0000 | |
| commit | d95713db7b98bb1b1b6516f4c6f2a61bb0bec974 (patch) | |
| tree | 9d1ff476efdc48f584dc60322ecbb070e444c1cf | |
| parent | c7858862b7ef5a5559ad4186d785a1dade39ce15 (diff) | |
Status Bar - Update paddings when density or font scaling changes
The status bar content insets might change when density or font scaling
changes.
Fixes: 321845195
Test: PhoneStatusBarViewTest
Test: Manually
Flag: NONE
Change-Id: Ide7b4ea79572b23814bde6ad90846e6b72998285
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java | 18 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt | 66 |
2 files changed, 81 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java index cb7bc256504e..db2f3a47a8fc 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java @@ -36,9 +36,9 @@ import android.widget.LinearLayout; import com.android.internal.policy.SystemBarUtils; import com.android.systemui.Dependency; import com.android.systemui.Gefingerpoken; -import com.android.systemui.res.R; import com.android.systemui.plugins.DarkIconDispatcher; import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver; +import com.android.systemui.res.R; import com.android.systemui.statusbar.phone.userswitcher.StatusBarUserSwitcherContainer; import com.android.systemui.statusbar.policy.Clock; import com.android.systemui.user.ui.binder.StatusBarUserChipViewBinder; @@ -63,6 +63,8 @@ public class PhoneStatusBarView extends FrameLayout { private int mStatusBarHeight; @Nullable private Gefingerpoken mTouchEventHandler; + private int mDensity; + private float mFontScale; /** * Draw this many pixels into the left/right side of the cutout to optimally use the space @@ -156,13 +158,23 @@ public class PhoneStatusBarView extends FrameLayout { mDisplayCutout = getRootWindowInsets().getDisplayCutout(); } - final Rect newSize = mContext.getResources().getConfiguration().windowConfiguration - .getMaxBounds(); + Configuration newConfiguration = mContext.getResources().getConfiguration(); + final Rect newSize = newConfiguration.windowConfiguration.getMaxBounds(); if (!Objects.equals(newSize, mDisplaySize)) { changed = true; mDisplaySize = newSize; } + int density = newConfiguration.densityDpi; + if (density != mDensity) { + changed = true; + mDensity = density; + } + float fontScale = newConfiguration.fontScale; + if (fontScale != mFontScale) { + changed = true; + mFontScale = fontScale; + } return changed; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt index 65d71f8b4540..5999525d0eeb 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt @@ -138,6 +138,72 @@ class PhoneStatusBarViewTest : SysuiTestCase() { } @Test + fun onConfigurationChanged_noRelevantChange_doesNotUpdateInsets() { + val previousInsets = + Insets.of(/* left = */ 40, /* top = */ 30, /* right = */ 20, /* bottom = */ 10) + whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) + .thenReturn(previousInsets) + context.orCreateTestableResources.overrideConfiguration(Configuration()) + view.onAttachedToWindow() + + val newInsets = Insets.NONE + whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) + .thenReturn(newInsets) + view.onConfigurationChanged(Configuration()) + + assertThat(view.paddingLeft).isEqualTo(previousInsets.left) + assertThat(view.paddingTop).isEqualTo(previousInsets.top) + assertThat(view.paddingRight).isEqualTo(previousInsets.right) + assertThat(view.paddingBottom).isEqualTo(0) + } + + @Test + fun onConfigurationChanged_densityChanged_updatesInsets() { + val previousInsets = + Insets.of(/* left = */ 40, /* top = */ 30, /* right = */ 20, /* bottom = */ 10) + whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) + .thenReturn(previousInsets) + val configuration = Configuration() + configuration.densityDpi = 123 + context.orCreateTestableResources.overrideConfiguration(configuration) + view.onAttachedToWindow() + + val newInsets = Insets.NONE + whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) + .thenReturn(newInsets) + configuration.densityDpi = 456 + view.onConfigurationChanged(configuration) + + assertThat(view.paddingLeft).isEqualTo(newInsets.left) + assertThat(view.paddingTop).isEqualTo(newInsets.top) + assertThat(view.paddingRight).isEqualTo(newInsets.right) + assertThat(view.paddingBottom).isEqualTo(0) + } + + @Test + fun onConfigurationChanged_fontScaleChanged_updatesInsets() { + val previousInsets = + Insets.of(/* left = */ 40, /* top = */ 30, /* right = */ 20, /* bottom = */ 10) + whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) + .thenReturn(previousInsets) + val configuration = Configuration() + configuration.fontScale = 1f + context.orCreateTestableResources.overrideConfiguration(configuration) + view.onAttachedToWindow() + + val newInsets = Insets.NONE + whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) + .thenReturn(newInsets) + configuration.fontScale = 2f + view.onConfigurationChanged(configuration) + + assertThat(view.paddingLeft).isEqualTo(newInsets.left) + assertThat(view.paddingTop).isEqualTo(newInsets.top) + assertThat(view.paddingRight).isEqualTo(newInsets.right) + assertThat(view.paddingBottom).isEqualTo(0) + } + + @Test fun onApplyWindowInsets_updatesLeftTopRightPaddingsBasedOnInsets() { val insets = Insets.of(/* left = */ 90, /* top = */ 10, /* right = */ 45, /* bottom = */ 50) whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) |