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

Commit a219020d authored by William Xiao's avatar William Xiao Committed by Android (Google) Code Review
Browse files

Merge "Add config to control whether UMO shows on hub" into main

parents 9d2af156 e556807f
Loading
Loading
Loading
Loading
+47 −27
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.Flags.FLAG_COMMUNAL_HUB
import com.android.systemui.SysuiTestCase
import com.android.systemui.communal.data.repository.communalMediaRepository
import com.android.systemui.communal.data.repository.communalSmartspaceRepository
import com.android.systemui.communal.data.repository.fakeCommunalMediaRepository
import com.android.systemui.communal.data.repository.fakeCommunalSmartspaceRepository
import com.android.systemui.communal.domain.interactor.communalInteractor
@@ -28,12 +30,12 @@ import com.android.systemui.communal.domain.interactor.communalSettingsInteracto
import com.android.systemui.communal.domain.interactor.setCommunalEnabled
import com.android.systemui.flags.Flags
import com.android.systemui.flags.fakeFeatureFlagsClassic
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -42,46 +44,64 @@ import org.junit.runner.RunWith
@EnableFlags(FLAG_COMMUNAL_HUB)
@RunWith(AndroidJUnit4::class)
class CommunalOngoingContentStartableTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val kosmos = testKosmos().useUnconfinedTestDispatcher()

    private val mediaRepository = kosmos.fakeCommunalMediaRepository
    private val smartspaceRepository = kosmos.fakeCommunalSmartspaceRepository
    private var showUmoOnHub = true

    private lateinit var underTest: CommunalOngoingContentStartable
    private val Kosmos.underTest by
        Kosmos.Fixture {
            CommunalOngoingContentStartable(
                bgScope = applicationCoroutineScope,
                communalInteractor = communalInteractor,
                communalMediaRepository = communalMediaRepository,
                communalSettingsInteractor = communalSettingsInteractor,
                communalSmartspaceRepository = communalSmartspaceRepository,
                showUmoOnHub = showUmoOnHub,
            )
        }

    @Before
    fun setUp() {
        kosmos.fakeFeatureFlagsClassic.set(Flags.COMMUNAL_SERVICE_ENABLED, true)
        underTest =
            CommunalOngoingContentStartable(
                bgScope = kosmos.applicationCoroutineScope,
                communalInteractor = kosmos.communalInteractor,
                communalMediaRepository = mediaRepository,
                communalSettingsInteractor = kosmos.communalSettingsInteractor,
                communalSmartspaceRepository = smartspaceRepository,
            )
    }

    @Test
    fun testListenForOngoingContentWhenCommunalIsEnabled() =
        testScope.runTest {
    fun testListenForOngoingContent() =
        kosmos.runTest {
            underTest.start()

            assertThat(fakeCommunalMediaRepository.isListening()).isFalse()
            assertThat(fakeCommunalSmartspaceRepository.isListening()).isFalse()

            kosmos.setCommunalEnabled(true)

            assertThat(fakeCommunalMediaRepository.isListening()).isTrue()
            assertThat(fakeCommunalSmartspaceRepository.isListening()).isTrue()

            kosmos.setCommunalEnabled(false)

            assertThat(fakeCommunalMediaRepository.isListening()).isFalse()
            assertThat(fakeCommunalSmartspaceRepository.isListening()).isFalse()
        }

    @Test
    fun testListenForOngoingContent_showUmoFalse() =
        kosmos.runTest {
            showUmoOnHub = false
            underTest.start()
            runCurrent()

            assertThat(mediaRepository.isListening()).isFalse()
            assertThat(smartspaceRepository.isListening()).isFalse()
            assertThat(fakeCommunalMediaRepository.isListening()).isFalse()
            assertThat(fakeCommunalSmartspaceRepository.isListening()).isFalse()

            kosmos.setCommunalEnabled(true)
            runCurrent()

            assertThat(mediaRepository.isListening()).isTrue()
            assertThat(smartspaceRepository.isListening()).isTrue()
            // Media listening does not start when UMO is disabled.
            assertThat(fakeCommunalMediaRepository.isListening()).isFalse()
            assertThat(fakeCommunalSmartspaceRepository.isListening()).isTrue()

            kosmos.setCommunalEnabled(false)
            runCurrent()

            assertThat(mediaRepository.isListening()).isFalse()
            assertThat(smartspaceRepository.isListening()).isFalse()
            assertThat(fakeCommunalMediaRepository.isListening()).isFalse()
            assertThat(fakeCommunalSmartspaceRepository.isListening()).isFalse()
        }
}
+3 −0
Original line number Diff line number Diff line
@@ -1125,4 +1125,7 @@

    <!-- Configuration to swipe to open glanceable hub -->
    <bool name="config_swipeToOpenGlanceableHub">false</bool>

    <!-- Whether or not to show the UMO on the glanceable hub when media is playing. -->
    <bool name="config_showUmoOnHub">false</bool>
</resources>
+10 −3
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@

package com.android.systemui.communal

import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.systemui.CoreStartable
import com.android.systemui.communal.dagger.CommunalModule.Companion.SHOW_UMO
import com.android.systemui.communal.data.repository.CommunalMediaRepository
import com.android.systemui.communal.data.repository.CommunalSmartspaceRepository
import com.android.systemui.communal.domain.interactor.CommunalInteractor
@@ -24,8 +26,8 @@ import com.android.systemui.communal.domain.interactor.CommunalSettingsInteracto
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import javax.inject.Inject
import javax.inject.Named
import kotlinx.coroutines.CoroutineScope
import com.android.app.tracing.coroutines.launchTraced as launch

@SysUISingleton
class CommunalOngoingContentStartable
@@ -36,6 +38,7 @@ constructor(
    private val communalMediaRepository: CommunalMediaRepository,
    private val communalSettingsInteractor: CommunalSettingsInteractor,
    private val communalSmartspaceRepository: CommunalSmartspaceRepository,
    @Named(SHOW_UMO) private val showUmoOnHub: Boolean,
) : CoreStartable {

    override fun start() {
@@ -46,10 +49,14 @@ constructor(
        bgScope.launch {
            communalInteractor.isCommunalEnabled.collect { enabled ->
                if (enabled) {
                    if (showUmoOnHub) {
                        communalMediaRepository.startListening()
                    }
                    communalSmartspaceRepository.startListening()
                } else {
                    if (showUmoOnHub) {
                        communalMediaRepository.stopListening()
                    }
                    communalSmartspaceRepository.stopListening()
                }
            }
+7 −0
Original line number Diff line number Diff line
@@ -105,6 +105,7 @@ interface CommunalModule {
        const val LOGGABLE_PREFIXES = "loggable_prefixes"
        const val LAUNCHER_PACKAGE = "launcher_package"
        const val SWIPE_TO_HUB = "swipe_to_hub"
        const val SHOW_UMO = "show_umo"

        @Provides
        @Communal
@@ -150,5 +151,11 @@ interface CommunalModule {
        fun provideSwipeToHub(@Main resources: Resources): Boolean {
            return resources.getBoolean(R.bool.config_swipeToOpenGlanceableHub)
        }

        @Provides
        @Named(SHOW_UMO)
        fun provideShowUmo(@Main resources: Resources): Boolean {
            return resources.getBoolean(R.bool.config_showUmoOnHub)
        }
    }
}