Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/HubOnboardingInteractorTest.kt +61 −9 Original line number Diff line number Diff line Loading @@ -20,38 +20,68 @@ import android.content.pm.UserInfo import android.content.pm.UserInfo.FLAG_MAIN import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags import androidx.test.ext.junit.runners.AndroidJUnit4 import android.platform.test.flag.junit.FlagsParameterization import androidx.test.filters.SmallTest import com.android.compose.animation.scene.ObservableTransitionState import com.android.compose.animation.scene.SceneKey import com.android.systemui.Flags.FLAG_GLANCEABLE_HUB_V2 import com.android.systemui.SysuiTestCase import com.android.systemui.communal.data.repository.fakeCommunalPrefsRepository import com.android.systemui.communal.data.repository.forceCommunalV2FlagState import com.android.systemui.communal.shared.model.CommunalScenes import com.android.systemui.flags.andSceneContainer import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.scene.domain.interactor.SceneInteractor import com.android.systemui.scene.domain.interactor.sceneInteractor import com.android.systemui.scene.shared.flag.SceneContainerFlag import com.android.systemui.scene.shared.model.Scenes import com.android.systemui.settings.fakeUserTracker import com.android.systemui.testKosmos import com.android.systemui.user.data.repository.fakeUserRepository import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.flow.MutableStateFlow import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import platform.test.runner.parameterized.ParameterizedAndroidJunit4 import platform.test.runner.parameterized.Parameters @SmallTest @RunWith(AndroidJUnit4::class) class HubOnboardingInteractorTest : SysuiTestCase() { private val kosmos = testKosmos().useUnconfinedTestDispatcher() private val sceneInteractor = kosmos.sceneInteractor @RunWith(ParameterizedAndroidJunit4::class) class HubOnboardingInteractorTest(flags: FlagsParameterization) : SysuiTestCase() { init { mSetFlagsRule.setFlagsParameterization(flags) } private lateinit var kosmos: Kosmos private lateinit var sceneInteractor: SceneInteractor private lateinit var underTest: HubOnboardingInteractor @Before fun setUp() { kosmos = testKosmos().useUnconfinedTestDispatcher() sceneInteractor = kosmos.sceneInteractor mContext.orCreateTestableResources.addOverride( com.android.internal.R.bool.config_glanceableHubEnabled, true, ) } private val underTest: HubOnboardingInteractor by lazy { kosmos.hubOnboardingInteractor } private fun initializeUnderTest(isV2Enabled: Boolean) { kosmos.forceCommunalV2FlagState = isV2Enabled underTest = kosmos.hubOnboardingInteractor } @Test @EnableFlags(FLAG_GLANCEABLE_HUB_V2) fun setHubOnboardingDismissed() = kosmos.runTest { initializeUnderTest(isV2Enabled = true) setSelectedUser(MAIN_USER) val isHubOnboardingDismissed by collectLastValue(fakeCommunalPrefsRepository.isHubOnboardingDismissed(MAIN_USER)) Loading @@ -65,6 +95,8 @@ class HubOnboardingInteractorTest : SysuiTestCase() { @EnableFlags(FLAG_GLANCEABLE_HUB_V2) fun shouldShowHubOnboarding_falseWhenDismissed() = kosmos.runTest { initializeUnderTest(isV2Enabled = true) setSelectedUser(MAIN_USER) val shouldShowHubOnboarding by collectLastValue(underTest.shouldShowHubOnboarding) Loading @@ -77,6 +109,8 @@ class HubOnboardingInteractorTest : SysuiTestCase() { @EnableFlags(FLAG_GLANCEABLE_HUB_V2) fun shouldShowHubOnboarding_falseWhenNotIdleOnCommunal() = kosmos.runTest { initializeUnderTest(isV2Enabled = true) setSelectedUser(MAIN_USER) val shouldShowHubOnboarding by collectLastValue(underTest.shouldShowHubOnboarding) Loading @@ -87,19 +121,31 @@ class HubOnboardingInteractorTest : SysuiTestCase() { @EnableFlags(FLAG_GLANCEABLE_HUB_V2) fun shouldShowHubOnboarding_trueWhenIdleOnCommunal() = kosmos.runTest { initializeUnderTest(isV2Enabled = true) setSelectedUser(MAIN_USER) val shouldShowHubOnboarding by collectLastValue(underTest.shouldShowHubOnboarding) // Change to Communal scene. if (SceneContainerFlag.isEnabled) { setIdleScene(Scenes.Communal) } else { @Suppress("DEPRECATION") kosmos.communalSceneInteractor.snapToScene( CommunalScenes.Communal, "test: set idle on legacy communal", ) } assertThat(shouldShowHubOnboarding).isFalse() assertThat(shouldShowHubOnboarding).isTrue() } @Test @DisableFlags(FLAG_GLANCEABLE_HUB_V2) fun shouldShowHubOnboarding_falseWhenFlagDisabled() = kosmos.runTest { initializeUnderTest(isV2Enabled = false) setSelectedUser(MAIN_USER) val shouldShowHubOnboarding by collectLastValue(underTest.shouldShowHubOnboarding) Loading @@ -125,6 +171,12 @@ class HubOnboardingInteractorTest : SysuiTestCase() { } companion object { @JvmStatic @Parameters(name = "{0}") fun getParams(): List<FlagsParameterization> { return FlagsParameterization.allCombinationsOf().andSceneContainer() } val MAIN_USER = UserInfo(0, "main", FLAG_MAIN) } } packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalSettingsRepository.kt +1 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,7 @@ interface CommunalSettingsRepository { } @SysUISingleton class CommunalSettingsRepositoryImpl open class CommunalSettingsRepositoryImpl @Inject constructor( @Background private val bgDispatcher: CoroutineDispatcher, Loading packages/SystemUI/tests/utils/src/com/android/systemui/communal/data/repository/CommunalSettingsRepositoryKosmos.kt +21 −9 Original line number Diff line number Diff line Loading @@ -26,6 +26,9 @@ import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.testDispatcher import com.android.systemui.util.settings.data.repository.userAwareSecureSettingsRepository // Kosmos flag that can be overridden in tests. var Kosmos.forceCommunalV2FlagState: Boolean? by Kosmos.Fixture { null } val Kosmos.communalDefaultBackground: CommunalBackgroundType by Kosmos.Fixture { if (Flags.glanceableHubBlurredBackground()) { Loading @@ -37,6 +40,7 @@ val Kosmos.communalDefaultBackground: CommunalBackgroundType by val Kosmos.communalSettingsRepository: CommunalSettingsRepository by Kosmos.Fixture { object : CommunalSettingsRepositoryImpl( bgDispatcher = testDispatcher, resources = mainResources, Loading @@ -45,5 +49,13 @@ val Kosmos.communalSettingsRepository: CommunalSettingsRepository by broadcastDispatcher = broadcastDispatcher, devicePolicyManager = devicePolicyManager, defaultBackgroundType = communalDefaultBackground, ) ) { override fun getV2FlagEnabled(): Boolean { return if (forceCommunalV2FlagState != null) { forceCommunalV2FlagState as Boolean } else { super.getV2FlagEnabled() } } } } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/HubOnboardingInteractorTest.kt +61 −9 Original line number Diff line number Diff line Loading @@ -20,38 +20,68 @@ import android.content.pm.UserInfo import android.content.pm.UserInfo.FLAG_MAIN import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags import androidx.test.ext.junit.runners.AndroidJUnit4 import android.platform.test.flag.junit.FlagsParameterization import androidx.test.filters.SmallTest import com.android.compose.animation.scene.ObservableTransitionState import com.android.compose.animation.scene.SceneKey import com.android.systemui.Flags.FLAG_GLANCEABLE_HUB_V2 import com.android.systemui.SysuiTestCase import com.android.systemui.communal.data.repository.fakeCommunalPrefsRepository import com.android.systemui.communal.data.repository.forceCommunalV2FlagState import com.android.systemui.communal.shared.model.CommunalScenes import com.android.systemui.flags.andSceneContainer import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.scene.domain.interactor.SceneInteractor import com.android.systemui.scene.domain.interactor.sceneInteractor import com.android.systemui.scene.shared.flag.SceneContainerFlag import com.android.systemui.scene.shared.model.Scenes import com.android.systemui.settings.fakeUserTracker import com.android.systemui.testKosmos import com.android.systemui.user.data.repository.fakeUserRepository import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.flow.MutableStateFlow import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import platform.test.runner.parameterized.ParameterizedAndroidJunit4 import platform.test.runner.parameterized.Parameters @SmallTest @RunWith(AndroidJUnit4::class) class HubOnboardingInteractorTest : SysuiTestCase() { private val kosmos = testKosmos().useUnconfinedTestDispatcher() private val sceneInteractor = kosmos.sceneInteractor @RunWith(ParameterizedAndroidJunit4::class) class HubOnboardingInteractorTest(flags: FlagsParameterization) : SysuiTestCase() { init { mSetFlagsRule.setFlagsParameterization(flags) } private lateinit var kosmos: Kosmos private lateinit var sceneInteractor: SceneInteractor private lateinit var underTest: HubOnboardingInteractor @Before fun setUp() { kosmos = testKosmos().useUnconfinedTestDispatcher() sceneInteractor = kosmos.sceneInteractor mContext.orCreateTestableResources.addOverride( com.android.internal.R.bool.config_glanceableHubEnabled, true, ) } private val underTest: HubOnboardingInteractor by lazy { kosmos.hubOnboardingInteractor } private fun initializeUnderTest(isV2Enabled: Boolean) { kosmos.forceCommunalV2FlagState = isV2Enabled underTest = kosmos.hubOnboardingInteractor } @Test @EnableFlags(FLAG_GLANCEABLE_HUB_V2) fun setHubOnboardingDismissed() = kosmos.runTest { initializeUnderTest(isV2Enabled = true) setSelectedUser(MAIN_USER) val isHubOnboardingDismissed by collectLastValue(fakeCommunalPrefsRepository.isHubOnboardingDismissed(MAIN_USER)) Loading @@ -65,6 +95,8 @@ class HubOnboardingInteractorTest : SysuiTestCase() { @EnableFlags(FLAG_GLANCEABLE_HUB_V2) fun shouldShowHubOnboarding_falseWhenDismissed() = kosmos.runTest { initializeUnderTest(isV2Enabled = true) setSelectedUser(MAIN_USER) val shouldShowHubOnboarding by collectLastValue(underTest.shouldShowHubOnboarding) Loading @@ -77,6 +109,8 @@ class HubOnboardingInteractorTest : SysuiTestCase() { @EnableFlags(FLAG_GLANCEABLE_HUB_V2) fun shouldShowHubOnboarding_falseWhenNotIdleOnCommunal() = kosmos.runTest { initializeUnderTest(isV2Enabled = true) setSelectedUser(MAIN_USER) val shouldShowHubOnboarding by collectLastValue(underTest.shouldShowHubOnboarding) Loading @@ -87,19 +121,31 @@ class HubOnboardingInteractorTest : SysuiTestCase() { @EnableFlags(FLAG_GLANCEABLE_HUB_V2) fun shouldShowHubOnboarding_trueWhenIdleOnCommunal() = kosmos.runTest { initializeUnderTest(isV2Enabled = true) setSelectedUser(MAIN_USER) val shouldShowHubOnboarding by collectLastValue(underTest.shouldShowHubOnboarding) // Change to Communal scene. if (SceneContainerFlag.isEnabled) { setIdleScene(Scenes.Communal) } else { @Suppress("DEPRECATION") kosmos.communalSceneInteractor.snapToScene( CommunalScenes.Communal, "test: set idle on legacy communal", ) } assertThat(shouldShowHubOnboarding).isFalse() assertThat(shouldShowHubOnboarding).isTrue() } @Test @DisableFlags(FLAG_GLANCEABLE_HUB_V2) fun shouldShowHubOnboarding_falseWhenFlagDisabled() = kosmos.runTest { initializeUnderTest(isV2Enabled = false) setSelectedUser(MAIN_USER) val shouldShowHubOnboarding by collectLastValue(underTest.shouldShowHubOnboarding) Loading @@ -125,6 +171,12 @@ class HubOnboardingInteractorTest : SysuiTestCase() { } companion object { @JvmStatic @Parameters(name = "{0}") fun getParams(): List<FlagsParameterization> { return FlagsParameterization.allCombinationsOf().andSceneContainer() } val MAIN_USER = UserInfo(0, "main", FLAG_MAIN) } }
packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalSettingsRepository.kt +1 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,7 @@ interface CommunalSettingsRepository { } @SysUISingleton class CommunalSettingsRepositoryImpl open class CommunalSettingsRepositoryImpl @Inject constructor( @Background private val bgDispatcher: CoroutineDispatcher, Loading
packages/SystemUI/tests/utils/src/com/android/systemui/communal/data/repository/CommunalSettingsRepositoryKosmos.kt +21 −9 Original line number Diff line number Diff line Loading @@ -26,6 +26,9 @@ import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.testDispatcher import com.android.systemui.util.settings.data.repository.userAwareSecureSettingsRepository // Kosmos flag that can be overridden in tests. var Kosmos.forceCommunalV2FlagState: Boolean? by Kosmos.Fixture { null } val Kosmos.communalDefaultBackground: CommunalBackgroundType by Kosmos.Fixture { if (Flags.glanceableHubBlurredBackground()) { Loading @@ -37,6 +40,7 @@ val Kosmos.communalDefaultBackground: CommunalBackgroundType by val Kosmos.communalSettingsRepository: CommunalSettingsRepository by Kosmos.Fixture { object : CommunalSettingsRepositoryImpl( bgDispatcher = testDispatcher, resources = mainResources, Loading @@ -45,5 +49,13 @@ val Kosmos.communalSettingsRepository: CommunalSettingsRepository by broadcastDispatcher = broadcastDispatcher, devicePolicyManager = devicePolicyManager, defaultBackgroundType = communalDefaultBackground, ) ) { override fun getV2FlagEnabled(): Boolean { return if (forceCommunalV2FlagState != null) { forceCommunalV2FlagState as Boolean } else { super.getV2FlagEnabled() } } } }