diff options
2 files changed, 27 insertions, 4 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt index 7a41bc6da176..12552489496d 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt @@ -99,7 +99,9 @@ import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations import org.mockito.kotlin.eq import org.mockito.kotlin.mock +import org.mockito.kotlin.never import org.mockito.kotlin.spy +import org.mockito.kotlin.times import org.mockito.kotlin.whenever import platform.test.runner.parameterized.ParameterizedAndroidJunit4 import platform.test.runner.parameterized.Parameters @@ -741,6 +743,18 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() { } @Test + fun communalContent_readTriggersUmoVisibilityUpdate() = + testScope.runTest { + verify(mediaHost, never()).updateViewVisibility() + + val communalContent by collectLastValue(underTest.communalContent) + + // updateViewVisibility is called when the flow is collected. + assertThat(communalContent).isNotNull() + verify(mediaHost).updateViewVisibility() + } + + @Test fun scrollPosition_persistedOnEditEntry() { val index = 2 val offset = 30 diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt index 3fc8b096a48b..b06cf3ffcf45 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt @@ -97,8 +97,10 @@ constructor( private val metricsLogger: CommunalMetricsLogger, ) : BaseCommunalViewModel(communalSceneInteractor, communalInteractor, mediaHost) { + private val logger = Logger(logBuffer, "CommunalViewModel") + private val _isMediaHostVisible = - conflatedCallbackFlow<Boolean> { + conflatedCallbackFlow { val callback = { visible: Boolean -> trySend(visible) Unit @@ -106,11 +108,18 @@ constructor( mediaHost.addVisibilityChangeListener(callback) awaitClose { mediaHost.removeVisibilityChangeListener(callback) } } - .onStart { emit(mediaHost.visible) } + .onStart { + // Ensure the visibility state is correct when the hub is opened and this flow is + // started so that the UMO is shown when needed. The visibility state in MediaHost + // is not updated once its view has been detached, aka the hub is closed, which can + // result in this getting stuck as False and never being updated as the UMO is not + // shown. + mediaHost.updateViewVisibility() + emit(mediaHost.visible) + } + .onEach { logger.d({ "_isMediaHostVisible: $bool1" }) { bool1 = it } } .flowOn(mainDispatcher) - private val logger = Logger(logBuffer, "CommunalViewModel") - /** Communal content saved from the previous emission when the flow is active (not "frozen"). */ private var frozenCommunalContent: List<CommunalContentModel>? = null |