diff options
| author | 2024-08-15 18:23:53 +0000 | |
|---|---|---|
| committer | 2024-08-15 18:23:53 +0000 | |
| commit | 063a151fa1c8e8a90c7d8f66d855e9f99e245d0e (patch) | |
| tree | e9277e57e97eeafbf10f827a8fc0f81c59e76fb4 | |
| parent | f0b6d3c57983821cef817370f1cd2d943223c297 (diff) | |
| parent | b4784e8e08cc68a42c0ab2d3e9a915204a467185 (diff) | |
Merge changes I85b2f4db,I3fc03c1d into main
* changes:
[SB] Don't call SBWindowController#refreshSBHeight from PhoneSBView.
[SB] Remove Dependency.get(SBContentInsetsProvider) from PhoneSBView.
6 files changed, 136 insertions, 37 deletions
diff --git a/packages/SystemUI/aconfig/systemui.aconfig b/packages/SystemUI/aconfig/systemui.aconfig index 5632e300da35..df286546e9b6 100644 --- a/packages/SystemUI/aconfig/systemui.aconfig +++ b/packages/SystemUI/aconfig/systemui.aconfig @@ -380,6 +380,17 @@ flag { } flag { + name: "status_bar_stop_updating_window_height" + namespace: "systemui" + description: "Don't have PhoneStatusBarView manually trigger an update of the height in " + "StatusBarWindowController" + bug: "360115167" + metadata { + purpose: PURPOSE_BUGFIX + } +} + +flag { name: "compose_bouncer" namespace: "systemui" description: "Use the new compose bouncer in SystemUI" diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java index baf8f5aeba29..a30115568842 100644 --- a/packages/SystemUI/src/com/android/systemui/Dependency.java +++ b/packages/SystemUI/src/com/android/systemui/Dependency.java @@ -49,7 +49,6 @@ import com.android.systemui.statusbar.notification.stack.AmbientState; import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager; import com.android.systemui.statusbar.phone.LightBarController; import com.android.systemui.statusbar.phone.ScreenOffAnimationController; -import com.android.systemui.statusbar.phone.StatusBarContentInsetsProvider; import com.android.systemui.statusbar.phone.SystemUIDialogManager; import com.android.systemui.statusbar.policy.BluetoothController; import com.android.systemui.statusbar.policy.DeviceProvisionedController; @@ -140,7 +139,6 @@ public class Dependency { @Inject Lazy<SysUiState> mSysUiStateFlagsContainer; @Inject Lazy<CommandQueue> mCommandQueue; @Inject Lazy<UiEventLogger> mUiEventLogger; - @Inject Lazy<StatusBarContentInsetsProvider> mContentInsetsProviderLazy; @Inject Lazy<FeatureFlags> mFeatureFlagsLazy; @Inject Lazy<NotificationSectionsManager> mNotificationSectionsManagerLazy; @Inject Lazy<ScreenOffAnimationController> mScreenOffAnimationController; @@ -186,7 +184,6 @@ public class Dependency { mProviders.put(CommandQueue.class, mCommandQueue::get); mProviders.put(UiEventLogger.class, mUiEventLogger::get); mProviders.put(FeatureFlags.class, mFeatureFlagsLazy::get); - mProviders.put(StatusBarContentInsetsProvider.class, mContentInsetsProviderLazy::get); mProviders.put(NotificationSectionsManager.class, mNotificationSectionsManagerLazy::get); mProviders.put(ScreenOffAnimationController.class, mScreenOffAnimationController::get); mProviders.put(AmbientState.class, mAmbientStateLazy::get); 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 04604e0bb3f9..dda02db3f2ef 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java @@ -32,6 +32,8 @@ import android.view.accessibility.AccessibilityEvent; import android.widget.FrameLayout; import android.widget.LinearLayout; +import androidx.annotation.NonNull; + import com.android.internal.policy.SystemBarUtils; import com.android.systemui.Dependency; import com.android.systemui.Flags; @@ -47,7 +49,6 @@ import java.util.Objects; public class PhoneStatusBarView extends FrameLayout { private static final String TAG = "PhoneStatusBarView"; - private final StatusBarContentInsetsProvider mContentInsetsProvider; private final StatusBarWindowController mStatusBarWindowController; private int mRotationOrientation = -1; @@ -60,6 +61,10 @@ public class PhoneStatusBarView extends FrameLayout { private int mStatusBarHeight; @Nullable private Gefingerpoken mTouchEventHandler; + @Nullable + private HasCornerCutoutFetcher mHasCornerCutoutFetcher; + @Nullable + private InsetsFetcher mInsetsFetcher; private int mDensity; private float mFontScale; @@ -70,7 +75,6 @@ public class PhoneStatusBarView extends FrameLayout { public PhoneStatusBarView(Context context, AttributeSet attrs) { super(context, attrs); - mContentInsetsProvider = Dependency.get(StatusBarContentInsetsProvider.class); mStatusBarWindowController = Dependency.get(StatusBarWindowController.class); } @@ -78,6 +82,14 @@ public class PhoneStatusBarView extends FrameLayout { mTouchEventHandler = handler; } + void setHasCornerCutoutFetcher(@NonNull HasCornerCutoutFetcher cornerCutoutFetcher) { + mHasCornerCutoutFetcher = cornerCutoutFetcher; + } + + void setInsetsFetcher(@NonNull InsetsFetcher insetsFetcher) { + mInsetsFetcher = insetsFetcher; + } + void init(StatusBarUserChipViewModel viewModel) { StatusBarUserSwitcherContainer container = findViewById(R.id.user_switcher_container); StatusBarUserChipViewBinder.bind(container, viewModel); @@ -270,7 +282,14 @@ public class PhoneStatusBarView extends FrameLayout { return; } - boolean hasCornerCutout = mContentInsetsProvider.currentRotationHasCornerCutout(); + boolean hasCornerCutout; + if (mHasCornerCutoutFetcher != null) { + hasCornerCutout = mHasCornerCutoutFetcher.fetchHasCornerCutout(); + } else { + Log.e(TAG, "mHasCornerCutoutFetcher unexpectedly null"); + hasCornerCutout = true; + } + if (mDisplayCutout == null || mDisplayCutout.isEmpty() || hasCornerCutout) { mCutoutSpace.setVisibility(View.GONE); return; @@ -288,8 +307,12 @@ public class PhoneStatusBarView extends FrameLayout { } private void updateSafeInsets() { - Insets insets = mContentInsetsProvider - .getStatusBarContentInsetsForCurrentRotation(); + if (mInsetsFetcher == null) { + Log.e(TAG, "mInsetsFetcher unexpectedly null"); + return; + } + + Insets insets = mInsetsFetcher.fetchInsets(); setPadding( insets.left, insets.top, @@ -298,6 +321,17 @@ public class PhoneStatusBarView extends FrameLayout { } private void updateWindowHeight() { + if (Flags.statusBarStopUpdatingWindowHeight()) { + return; + } mStatusBarWindowController.refreshStatusBarHeight(); } + + interface HasCornerCutoutFetcher { + boolean fetchHasCornerCutout(); + } + + interface InsetsFetcher { + Insets fetchInsets(); + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt index 468a3c3a49a5..456265b27004 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt @@ -73,6 +73,7 @@ private constructor( private val configurationController: ConfigurationController, private val statusOverlayHoverListenerFactory: StatusOverlayHoverListenerFactory, private val darkIconDispatcher: DarkIconDispatcher, + private val statusBarContentInsetsProvider: StatusBarContentInsetsProvider, ) : ViewController<PhoneStatusBarView>(view) { private lateinit var battery: BatteryMeterView @@ -155,7 +156,14 @@ private constructor( } init { + // These should likely be done in `onInit`, not `init`. mView.setTouchEventHandler(PhoneStatusBarViewTouchHandler()) + mView.setHasCornerCutoutFetcher { + statusBarContentInsetsProvider.currentRotationHasCornerCutout() + } + mView.setInsetsFetcher { + statusBarContentInsetsProvider.getStatusBarContentInsetsForCurrentRotation() + } mView.init(userChipViewModel) } @@ -310,6 +318,7 @@ private constructor( private val configurationController: ConfigurationController, private val statusOverlayHoverListenerFactory: StatusOverlayHoverListenerFactory, private val darkIconDispatcher: DarkIconDispatcher, + private val statusBarContentInsetsProvider: StatusBarContentInsetsProvider, ) { fun create(view: PhoneStatusBarView): PhoneStatusBarViewController { val statusBarMoveFromCenterAnimationController = @@ -335,6 +344,7 @@ private constructor( configurationController, statusOverlayHoverListenerFactory, darkIconDispatcher, + statusBarContentInsetsProvider, ) } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewControllerTest.kt index 30e7247b325e..70ac31d99559 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewControllerTest.kt @@ -391,6 +391,7 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() { configurationController, mStatusOverlayHoverListenerFactory, fakeDarkIconDispatcher, + mock(StatusBarContentInsetsProvider::class.java), ) .create(view) .also { it.init() } 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 ed5ec7b2160a..648ddf847ea0 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 @@ -32,6 +32,7 @@ import android.view.View import android.view.WindowInsets import android.widget.FrameLayout import androidx.test.filters.SmallTest +import com.android.systemui.Flags.FLAG_STATUS_BAR_STOP_UPDATING_WINDOW_HEIGHT import com.android.systemui.Flags.FLAG_STATUS_BAR_SWIPE_OVER_CHIP import com.android.systemui.Gefingerpoken import com.android.systemui.SysuiTestCase @@ -42,6 +43,7 @@ import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import org.junit.Before import org.junit.Test +import org.mockito.Mockito.never import org.mockito.Mockito.spy import org.mockito.Mockito.times import org.mockito.Mockito.verify @@ -54,21 +56,14 @@ class PhoneStatusBarViewTest : SysuiTestCase() { private val systemIconsContainer: View get() = view.requireViewById(R.id.system_icons) - private val contentInsetsProvider = mock<StatusBarContentInsetsProvider>() private val windowController = mock<StatusBarWindowController>() @Before fun setUp() { - mDependency.injectTestDependency( - StatusBarContentInsetsProvider::class.java, - contentInsetsProvider - ) mDependency.injectTestDependency(StatusBarWindowController::class.java, windowController) context.ensureTestableResources() view = spy(createStatusBarView()) whenever(view.rootWindowInsets).thenReturn(emptyWindowInsets()) - whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) - .thenReturn(Insets.NONE) } @Test @@ -183,21 +178,40 @@ class PhoneStatusBarViewTest : SysuiTestCase() { } @Test - fun onAttachedToWindow_updatesWindowHeight() { + @DisableFlags(FLAG_STATUS_BAR_STOP_UPDATING_WINDOW_HEIGHT) + fun onAttachedToWindow_flagOff_updatesWindowHeight() { view.onAttachedToWindow() verify(windowController).refreshStatusBarHeight() } @Test - fun onConfigurationChanged_updatesWindowHeight() { + @EnableFlags(FLAG_STATUS_BAR_STOP_UPDATING_WINDOW_HEIGHT) + fun onAttachedToWindow_flagOn_doesNotUpdateWindowHeight() { + view.onAttachedToWindow() + + verify(windowController, never()).refreshStatusBarHeight() + } + + @Test + @DisableFlags(FLAG_STATUS_BAR_STOP_UPDATING_WINDOW_HEIGHT) + fun onConfigurationChanged_flagOff_updatesWindowHeight() { view.onConfigurationChanged(Configuration()) verify(windowController).refreshStatusBarHeight() } @Test - fun onConfigurationChanged_multipleCalls_updatesWindowHeightMultipleTimes() { + @EnableFlags(FLAG_STATUS_BAR_STOP_UPDATING_WINDOW_HEIGHT) + fun onConfigurationChanged_flagOn_doesNotUpdateWindowHeight() { + view.onConfigurationChanged(Configuration()) + + verify(windowController, never()).refreshStatusBarHeight() + } + + @Test + @DisableFlags(FLAG_STATUS_BAR_STOP_UPDATING_WINDOW_HEIGHT) + fun onConfigurationChanged_multipleCalls_flagOff_updatesWindowHeightMultipleTimes() { view.onConfigurationChanged(Configuration()) view.onConfigurationChanged(Configuration()) view.onConfigurationChanged(Configuration()) @@ -207,10 +221,20 @@ class PhoneStatusBarViewTest : SysuiTestCase() { } @Test + @EnableFlags(FLAG_STATUS_BAR_STOP_UPDATING_WINDOW_HEIGHT) + fun onConfigurationChanged_multipleCalls_flagOn_neverUpdatesWindowHeight() { + view.onConfigurationChanged(Configuration()) + view.onConfigurationChanged(Configuration()) + view.onConfigurationChanged(Configuration()) + view.onConfigurationChanged(Configuration()) + + verify(windowController, never()).refreshStatusBarHeight() + } + + @Test fun onAttachedToWindow_updatesLeftTopRightPaddingsBasedOnInsets() { val insets = Insets.of(/* left= */ 10, /* top= */ 20, /* right= */ 30, /* bottom= */ 40) - whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) - .thenReturn(insets) + view.setInsetsFetcher { insets } view.onAttachedToWindow() @@ -221,10 +245,23 @@ class PhoneStatusBarViewTest : SysuiTestCase() { } @Test + fun onAttachedToWindow_noInsetsFetcher_noCrash() { + // Don't call `PhoneStatusBarView.setInsetsFetcher` + + // WHEN the view is attached + view.onAttachedToWindow() + + // THEN there's no crash, and the padding stays as it was + assertThat(view.paddingLeft).isEqualTo(0) + assertThat(view.paddingTop).isEqualTo(0) + assertThat(view.paddingRight).isEqualTo(0) + assertThat(view.paddingBottom).isEqualTo(0) + } + + @Test fun onConfigurationChanged_updatesLeftTopRightPaddingsBasedOnInsets() { val insets = Insets.of(/* left= */ 40, /* top= */ 30, /* right= */ 20, /* bottom= */ 10) - whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) - .thenReturn(insets) + view.setInsetsFetcher { insets } view.onConfigurationChanged(Configuration()) @@ -235,17 +272,31 @@ class PhoneStatusBarViewTest : SysuiTestCase() { } @Test + fun onConfigurationChanged_noInsetsFetcher_noCrash() { + // Don't call `PhoneStatusBarView.setInsetsFetcher` + + // WHEN the view is attached + view.onConfigurationChanged(Configuration()) + + // THEN there's no crash, and the padding stays as it was + assertThat(view.paddingLeft).isEqualTo(0) + assertThat(view.paddingTop).isEqualTo(0) + assertThat(view.paddingRight).isEqualTo(0) + assertThat(view.paddingBottom).isEqualTo(0) + } + + @Test fun onConfigurationChanged_noRelevantChange_doesNotUpdateInsets() { val previousInsets = Insets.of(/* left= */ 40, /* top= */ 30, /* right= */ 20, /* bottom= */ 10) - whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) - .thenReturn(previousInsets) + view.setInsetsFetcher { previousInsets } + context.orCreateTestableResources.overrideConfiguration(Configuration()) view.onAttachedToWindow() val newInsets = Insets.NONE - whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) - .thenReturn(newInsets) + view.setInsetsFetcher { newInsets } + view.onConfigurationChanged(Configuration()) assertThat(view.paddingLeft).isEqualTo(previousInsets.left) @@ -258,16 +309,14 @@ class PhoneStatusBarViewTest : SysuiTestCase() { fun onConfigurationChanged_densityChanged_updatesInsets() { val previousInsets = Insets.of(/* left= */ 40, /* top= */ 30, /* right= */ 20, /* bottom= */ 10) - whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) - .thenReturn(previousInsets) + view.setInsetsFetcher { previousInsets } val configuration = Configuration() configuration.densityDpi = 123 context.orCreateTestableResources.overrideConfiguration(configuration) view.onAttachedToWindow() val newInsets = Insets.NONE - whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) - .thenReturn(newInsets) + view.setInsetsFetcher { newInsets } configuration.densityDpi = 456 view.onConfigurationChanged(configuration) @@ -281,16 +330,14 @@ class PhoneStatusBarViewTest : SysuiTestCase() { fun onConfigurationChanged_fontScaleChanged_updatesInsets() { val previousInsets = Insets.of(/* left= */ 40, /* top= */ 30, /* right= */ 20, /* bottom= */ 10) - whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) - .thenReturn(previousInsets) + view.setInsetsFetcher { previousInsets } val configuration = Configuration() configuration.fontScale = 1f context.orCreateTestableResources.overrideConfiguration(configuration) view.onAttachedToWindow() val newInsets = Insets.NONE - whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) - .thenReturn(newInsets) + view.setInsetsFetcher { newInsets } configuration.fontScale = 2f view.onConfigurationChanged(configuration) @@ -316,8 +363,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() { @Test fun onApplyWindowInsets_updatesLeftTopRightPaddingsBasedOnInsets() { val insets = Insets.of(/* left= */ 90, /* top= */ 10, /* right= */ 45, /* bottom= */ 50) - whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()) - .thenReturn(insets) + view.setInsetsFetcher { insets } view.onApplyWindowInsets(WindowInsets(Rect())) @@ -358,7 +404,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() { /* typeVisibilityMap = */ booleanArrayOf(), /* isRound = */ false, /* forceConsumingTypes = */ 0, - /* forceConsumingCaptionBar = */ false, + /* forceConsumingOpaqueCaptionBar = */ false, /* suppressScrimTypes = */ 0, /* displayCutout = */ DisplayCutout.NO_CUTOUT, /* roundedCorners = */ RoundedCorners.NO_ROUNDED_CORNERS, |