Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a07fa827 authored by William Xiao's avatar William Xiao
Browse files

Fix UMO not showing on glanceable hub

The UMO is only shown in the hub if our MediaHost visible state is
true. The visible state reflects many factors, including whether or not
media is playing and the state of the "Show media on lock screen"
setting.

MediaHost listens for updates to media play/pause state upon creation
or when the glanceable hub UMO view is attached, but stops listeneing
when the view is detached, ie. the hub is closed. This means that if
the user opens the hub while the UMO is playing then dismisses the
media session, the hub UMO visibility will be stuck as false. Other UMO
locations do not have this issue as they do not ever detach the UMO
view.

This change forces a visibility state update whenever the value is
requested for the hub so that the value is fresh when the hub opens.

Bug: 354731260
Bug: 339085881
Fix: 354731260
Test: atest CommunalViewModelTest
      also manually verified on device, see bug for repro steps
Flag: com.android.systemui.communal_hub
Change-Id: I22ef39a99678acda87d52d6f62ea950982eb3171
parent ec6079d5
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -99,7 +99,9 @@ import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.eq
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.spy
import org.mockito.kotlin.spy
import org.mockito.kotlin.times
import org.mockito.kotlin.whenever
import org.mockito.kotlin.whenever
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.Parameters
import platform.test.runner.parameterized.Parameters
@@ -740,6 +742,18 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                .isInstanceOf(CommunalContentModel.CtaTileInViewMode::class.java)
                .isInstanceOf(CommunalContentModel.CtaTileInViewMode::class.java)
        }
        }


    @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
    @Test
    fun scrollPosition_persistedOnEditEntry() {
    fun scrollPosition_persistedOnEditEntry() {
        val index = 2
        val index = 2
+13 −4
Original line number Original line Diff line number Diff line
@@ -97,8 +97,10 @@ constructor(
    private val metricsLogger: CommunalMetricsLogger,
    private val metricsLogger: CommunalMetricsLogger,
) : BaseCommunalViewModel(communalSceneInteractor, communalInteractor, mediaHost) {
) : BaseCommunalViewModel(communalSceneInteractor, communalInteractor, mediaHost) {


    private val logger = Logger(logBuffer, "CommunalViewModel")

    private val _isMediaHostVisible =
    private val _isMediaHostVisible =
        conflatedCallbackFlow<Boolean> {
        conflatedCallbackFlow {
                val callback = { visible: Boolean ->
                val callback = { visible: Boolean ->
                    trySend(visible)
                    trySend(visible)
                    Unit
                    Unit
@@ -106,11 +108,18 @@ constructor(
                mediaHost.addVisibilityChangeListener(callback)
                mediaHost.addVisibilityChangeListener(callback)
                awaitClose { mediaHost.removeVisibilityChangeListener(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)
            .flowOn(mainDispatcher)


    private val logger = Logger(logBuffer, "CommunalViewModel")

    /** Communal content saved from the previous emission when the flow is active (not "frozen"). */
    /** Communal content saved from the previous emission when the flow is active (not "frozen"). */
    private var frozenCommunalContent: List<CommunalContentModel>? = null
    private var frozenCommunalContent: List<CommunalContentModel>? = null