summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/data/quickaffordance/GlanceableHubQuickAffordanceConfigTest.kt74
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/GlanceableHubQuickAffordanceConfig.kt13
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorKosmos.kt8
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/quickaffordance/GlanceableHubQuickAffordanceConfigKosmos.kt35
4 files changed, 80 insertions, 50 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/data/quickaffordance/GlanceableHubQuickAffordanceConfigTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/data/quickaffordance/GlanceableHubQuickAffordanceConfigTest.kt
index 789b10b7830c..ac06a3b9293c 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/data/quickaffordance/GlanceableHubQuickAffordanceConfigTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/data/quickaffordance/GlanceableHubQuickAffordanceConfigTest.kt
@@ -24,21 +24,19 @@ import androidx.test.filters.SmallTest
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.communal.data.repository.communalSceneRepository
-import com.android.systemui.communal.domain.interactor.communalInteractor
-import com.android.systemui.communal.domain.interactor.communalSettingsInteractor
+import com.android.systemui.communal.domain.interactor.setCommunalV2Available
import com.android.systemui.communal.domain.interactor.setCommunalV2Enabled
import com.android.systemui.communal.shared.model.CommunalScenes
-import com.android.systemui.coroutines.collectLastValue
-import com.android.systemui.flags.andSceneContainer
-import com.android.systemui.kosmos.testScope
+import com.android.systemui.flags.parameterizeSceneContainerFlag
+import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
+import com.android.systemui.kosmos.Kosmos
+import com.android.systemui.kosmos.collectLastValue
+import com.android.systemui.kosmos.runCurrent
+import com.android.systemui.kosmos.runTest
import com.android.systemui.scene.data.repository.sceneContainerRepository
-import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
-import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.test.runCurrent
-import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -47,14 +45,11 @@ import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.Parameters
@SmallTest
-@OptIn(ExperimentalCoroutinesApi::class)
-@EnableFlags(Flags.FLAG_GLANCEABLE_HUB_SHORTCUT_BUTTON, Flags.FLAG_GLANCEABLE_HUB_V2)
+@EnableFlags(Flags.FLAG_GLANCEABLE_HUB_V2)
@RunWith(ParameterizedAndroidJunit4::class)
class GlanceableHubQuickAffordanceConfigTest(flags: FlagsParameterization?) : SysuiTestCase() {
private val kosmos = testKosmos()
- private val testScope = kosmos.testScope
-
- private lateinit var underTest: GlanceableHubQuickAffordanceConfig
+ private val Kosmos.underTest by Kosmos.Fixture { glanceableHubQuickAffordanceConfig }
init {
mSetFlagsRule.setFlagsParameterization(flags!!)
@@ -64,20 +59,16 @@ class GlanceableHubQuickAffordanceConfigTest(flags: FlagsParameterization?) : Sy
fun setUp() {
MockitoAnnotations.initMocks(this)
- underTest =
- GlanceableHubQuickAffordanceConfig(
- context = context,
- communalInteractor = kosmos.communalInteractor,
- communalSceneRepository = kosmos.communalSceneRepository,
- communalSettingsInteractor = kosmos.communalSettingsInteractor,
- sceneInteractor = kosmos.sceneInteractor,
- )
+ // Access the class immediately so that flows are instantiated.
+ // GlanceableHubQuickAffordanceConfig accesses StateFlow.value directly so we need the flows
+ // to start flowing before runCurrent is called in the tests.
+ kosmos.underTest
}
@Test
fun lockscreenState_whenGlanceableHubEnabled_returnsVisible() =
- testScope.runTest {
- kosmos.setCommunalV2Enabled(true)
+ kosmos.runTest {
+ kosmos.setCommunalV2Available(true)
runCurrent()
val lockScreenState by collectLastValue(underTest.lockScreenState)
@@ -88,8 +79,21 @@ class GlanceableHubQuickAffordanceConfigTest(flags: FlagsParameterization?) : Sy
@Test
fun lockscreenState_whenGlanceableHubDisabled_returnsHidden() =
- testScope.runTest {
- kosmos.setCommunalV2Enabled(false)
+ kosmos.runTest {
+ setCommunalV2Enabled(false)
+ val lockScreenState by collectLastValue(underTest.lockScreenState)
+ runCurrent()
+
+ assertThat(lockScreenState)
+ .isEqualTo(KeyguardQuickAffordanceConfig.LockScreenState.Hidden)
+ }
+
+ @Test
+ fun lockscreenState_whenGlanceableHubNotAvailable_returnsHidden() =
+ kosmos.runTest {
+ // Hub is enabled, but not available.
+ setCommunalV2Enabled(true)
+ fakeKeyguardRepository.setKeyguardShowing(false)
val lockScreenState by collectLastValue(underTest.lockScreenState)
runCurrent()
@@ -99,8 +103,8 @@ class GlanceableHubQuickAffordanceConfigTest(flags: FlagsParameterization?) : Sy
@Test
fun pickerScreenState_whenGlanceableHubEnabled_returnsDefault() =
- testScope.runTest {
- kosmos.setCommunalV2Enabled(true)
+ kosmos.runTest {
+ setCommunalV2Enabled(true)
runCurrent()
assertThat(underTest.getPickerScreenState())
@@ -109,8 +113,8 @@ class GlanceableHubQuickAffordanceConfigTest(flags: FlagsParameterization?) : Sy
@Test
fun pickerScreenState_whenGlanceableHubDisabled_returnsDisabled() =
- testScope.runTest {
- kosmos.setCommunalV2Enabled(false)
+ kosmos.runTest {
+ setCommunalV2Enabled(false)
runCurrent()
assertThat(
@@ -122,7 +126,7 @@ class GlanceableHubQuickAffordanceConfigTest(flags: FlagsParameterization?) : Sy
@Test
@DisableFlags(Flags.FLAG_SCENE_CONTAINER)
fun onTriggered_changesSceneToCommunal() =
- testScope.runTest {
+ kosmos.runTest {
underTest.onTriggered(expandable = null)
runCurrent()
@@ -133,7 +137,7 @@ class GlanceableHubQuickAffordanceConfigTest(flags: FlagsParameterization?) : Sy
@Test
@EnableFlags(Flags.FLAG_SCENE_CONTAINER)
fun testTransitionToGlanceableHub_sceneContainer() =
- testScope.runTest {
+ kosmos.runTest {
underTest.onTriggered(expandable = null)
runCurrent()
@@ -145,11 +149,7 @@ class GlanceableHubQuickAffordanceConfigTest(flags: FlagsParameterization?) : Sy
@JvmStatic
@Parameters(name = "{0}")
fun getParams(): List<FlagsParameterization> {
- return FlagsParameterization.allCombinationsOf(
- Flags.FLAG_GLANCEABLE_HUB_SHORTCUT_BUTTON,
- Flags.FLAG_GLANCEABLE_HUB_V2,
- )
- .andSceneContainer()
+ return parameterizeSceneContainerFlag()
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/GlanceableHubQuickAffordanceConfig.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/GlanceableHubQuickAffordanceConfig.kt
index 06da281648a7..96b07cc84705 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/GlanceableHubQuickAffordanceConfig.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/GlanceableHubQuickAffordanceConfig.kt
@@ -36,7 +36,7 @@ import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.scene.shared.model.Scenes
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.flow.flow
+import kotlinx.coroutines.flow.map
/** Lockscreen affordance that opens the glanceable hub. */
@SysUISingleton
@@ -60,13 +60,13 @@ constructor(
get() = R.drawable.ic_widgets
override val lockScreenState: Flow<KeyguardQuickAffordanceConfig.LockScreenState>
- get() = flow {
- emit(
+ get() =
+ communalInteractor.isCommunalAvailable.map { available ->
if (!communalSettingsInteractor.isV2FlagEnabled()) {
Log.i(TAG, "Button hidden on lockscreen: flag not enabled.")
KeyguardQuickAffordanceConfig.LockScreenState.Hidden
- } else if (!communalInteractor.isCommunalEnabled.value) {
- Log.i(TAG, "Button hidden on lockscreen: hub not enabled in settings.")
+ } else if (!available) {
+ Log.i(TAG, "Button hidden on lockscreen: hub not available.")
KeyguardQuickAffordanceConfig.LockScreenState.Hidden
} else {
KeyguardQuickAffordanceConfig.LockScreenState.Visible(
@@ -77,8 +77,7 @@ constructor(
)
)
}
- )
- }
+ }
override suspend fun getPickerScreenState(): KeyguardQuickAffordanceConfig.PickerScreenState {
return if (!communalSettingsInteractor.isV2FlagEnabled()) {
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorKosmos.kt
index bfc424848900..89aad4be7cc0 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorKosmos.kt
@@ -99,10 +99,6 @@ suspend fun Kosmos.setCommunalAvailable(available: Boolean) {
}
suspend fun Kosmos.setCommunalV2Available(available: Boolean) {
- setCommunalV2ConfigEnabled(true)
- setCommunalEnabled(available)
- with(fakeKeyguardRepository) {
- setIsEncryptedOrLockdown(!available)
- setKeyguardShowing(available)
- }
+ setCommunalV2ConfigEnabled(available)
+ setCommunalAvailable(available)
}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/quickaffordance/GlanceableHubQuickAffordanceConfigKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/quickaffordance/GlanceableHubQuickAffordanceConfigKosmos.kt
new file mode 100644
index 000000000000..568324832b33
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/quickaffordance/GlanceableHubQuickAffordanceConfigKosmos.kt
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.keyguard.data.quickaffordance
+
+import android.content.applicationContext
+import com.android.systemui.communal.data.repository.communalSceneRepository
+import com.android.systemui.communal.domain.interactor.communalInteractor
+import com.android.systemui.communal.domain.interactor.communalSettingsInteractor
+import com.android.systemui.kosmos.Kosmos
+import com.android.systemui.scene.domain.interactor.sceneInteractor
+
+val Kosmos.glanceableHubQuickAffordanceConfig by
+ Kosmos.Fixture {
+ GlanceableHubQuickAffordanceConfig(
+ context = applicationContext,
+ communalInteractor = communalInteractor,
+ communalSceneRepository = communalSceneRepository,
+ communalSettingsInteractor = communalSettingsInteractor,
+ sceneInteractor = sceneInteractor,
+ )
+ }