From 331cde25702bdaf76344c63391b9626b6ae518bb Mon Sep 17 00:00:00 2001 From: Michael Mikhail Date: Fri, 10 Mar 2023 17:03:26 +0000 Subject: [PATCH] Check for block location change when configuration changes In foldables, we switch from landscape to portrait when we fold the device. This force media controls to update state. But we need to make sure it is not canceling the need to block location changes. Bug: 265312583 Test: atest MediaHierarchyManagerTest Test: checked the device many times to see if the flashing goes away. Change-Id: Icb93a114613901287bdcfd22584fd8c4844199f7 --- .../controls/ui/MediaHierarchyManager.kt | 4 +- .../controls/ui/MediaHierarchyManagerTest.kt | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHierarchyManager.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHierarchyManager.kt index 7fc7bdb872c97..e10d74db63339 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHierarchyManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHierarchyManager.kt @@ -639,7 +639,9 @@ constructor( ) = traceSection("MediaHierarchyManager#updateDesiredLocation") { val desiredLocation = calculateLocation() - if (desiredLocation != this.desiredLocation || forceStateUpdate) { + if ( + desiredLocation != this.desiredLocation || forceStateUpdate && !blockLocationChanges + ) { if (this.desiredLocation >= 0 && desiredLocation != this.desiredLocation) { // Only update previous location when it actually changes previousLocation = this.desiredLocation diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaHierarchyManagerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaHierarchyManagerTest.kt index a5795184b493b..feb429d2f0d4e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaHierarchyManagerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaHierarchyManagerTest.kt @@ -179,6 +179,57 @@ class MediaHierarchyManagerTest : SysuiTestCase() { ) } + @Test + fun testBlockedWhenConfigurationChangesAndScreenOff() { + // Let's set it onto QS: + mediaHierarchyManager.qsExpansion = 1.0f + verify(mediaCarouselController) + .onDesiredLocationChanged( + ArgumentMatchers.anyInt(), + any(MediaHostState::class.java), + anyBoolean(), + anyLong(), + anyLong() + ) + val observer = wakefullnessObserver.value + assertNotNull("lifecycle observer wasn't registered", observer) + observer.onStartedGoingToSleep() + clearInvocations(mediaCarouselController) + configurationController.notifyConfigurationChanged() + verify(mediaCarouselController, times(0)) + .onDesiredLocationChanged( + ArgumentMatchers.anyInt(), + any(MediaHostState::class.java), + anyBoolean(), + anyLong(), + anyLong() + ) + } + + @Test + fun testAllowedWhenConfigurationChanges() { + // Let's set it onto QS: + mediaHierarchyManager.qsExpansion = 1.0f + verify(mediaCarouselController) + .onDesiredLocationChanged( + ArgumentMatchers.anyInt(), + any(MediaHostState::class.java), + anyBoolean(), + anyLong(), + anyLong() + ) + clearInvocations(mediaCarouselController) + configurationController.notifyConfigurationChanged() + verify(mediaCarouselController) + .onDesiredLocationChanged( + ArgumentMatchers.anyInt(), + any(MediaHostState::class.java), + anyBoolean(), + anyLong(), + anyLong() + ) + } + @Test fun testAllowedWhenNotTurningOff() { // Let's set it onto QS: