Loading packages/SystemUI/multivalentTests/src/com/android/systemui/ambientcue/data/repository/AmbientCueRepositoryTest.kt +17 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.ambientcue.data.repository import android.app.ActivityManager.RunningTaskInfo import android.app.smartspace.SmartspaceAction import android.app.smartspace.SmartspaceManager import android.app.smartspace.SmartspaceSession Loading @@ -32,6 +33,7 @@ import com.android.systemui.kosmos.backgroundScope import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runCurrent import com.android.systemui.kosmos.runTest import com.android.systemui.shade.data.repository.fakeFocusedDisplayRepository import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat import org.junit.Test Loading @@ -58,6 +60,7 @@ class AmbientCueRepositoryTest : SysuiTestCase() { smartSpaceManager = smartSpaceManager, executor = kosmos.fakeExecutor, applicationContext = kosmos.testableContext, focusdDisplayRepository = kosmos.fakeFocusedDisplayRepository, ) @Test Loading @@ -81,9 +84,7 @@ class AmbientCueRepositoryTest : SysuiTestCase() { runCurrent() verify(smartSpaceSession) .addOnTargetsAvailableListener(any(), onTargetsAvailableListenerCaptor.capture()) onTargetsAvailableListenerCaptor.firstValue.onTargetsAvailable( listOf(invalidTarget1) ) onTargetsAvailableListenerCaptor.firstValue.onTargetsAvailable(listOf(invalidTarget1)) advanceUntilIdle() assertThat(isVisible).isFalse() } Loading Loading @@ -112,6 +113,17 @@ class AmbientCueRepositoryTest : SysuiTestCase() { } } @Test fun globallyFocusedTaskId_whenFocusedTaskChange_taskIdUpdated() = kosmos.runTest { val globallyFocusedTaskId by collectLastValue(underTest.globallyFocusedTaskId) runCurrent() fakeFocusedDisplayRepository.setGlobalTask(RunningTaskInfo().apply { taskId = TASK_ID }) assertThat(globallyFocusedTaskId).isEqualTo(TASK_ID) } companion object { private const val TITLE_1 = "title 1" Loading Loading @@ -140,5 +152,7 @@ class AmbientCueRepositoryTest : SysuiTestCase() { } private val allTargets = listOf(validTarget, invalidTarget1) private const val TASK_ID = 1 } } packages/SystemUI/src/com/android/systemui/ambientcue/data/repository/AmbientCueRepository.kt +17 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.ambientcue.data.repository import android.app.ActivityTaskManager import android.app.smartspace.SmartspaceConfig import android.app.smartspace.SmartspaceManager import android.app.smartspace.SmartspaceSession.OnTargetsAvailableListener Loading @@ -26,6 +27,7 @@ import com.android.systemui.ambientcue.shared.model.ActionModel import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.display.data.repository.FocusedDisplayRepository import com.android.systemui.res.R import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow import java.util.concurrent.Executor Loading @@ -35,6 +37,7 @@ import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.update Loading @@ -49,6 +52,9 @@ interface AmbientCueRepository { /** If IME is visible or not. */ val isImeVisible: MutableStateFlow<Boolean> /** Task Id which is globally focused on display. */ val globallyFocusedTaskId: StateFlow<Int> } @SysUISingleton Loading @@ -59,6 +65,7 @@ constructor( private val smartSpaceManager: SmartspaceManager?, @Background executor: Executor, @Application applicationContext: Context, focusdDisplayRepository: FocusedDisplayRepository, ) : AmbientCueRepository { override val actions: StateFlow<List<ActionModel>> = Loading Loading @@ -114,11 +121,21 @@ constructor( override val isImeVisible: MutableStateFlow<Boolean> = MutableStateFlow(false) override val globallyFocusedTaskId: StateFlow<Int> = focusdDisplayRepository.globallyFocusedTask .map { it?.taskId ?: INVALID_TASK_ID } .stateIn( scope = backgroundScope, started = SharingStarted.WhileSubscribed(), initialValue = INVALID_TASK_ID, ) companion object { // Surface that PCC wants to push cards into @VisibleForTesting const val AMBIENT_CUE_SURFACE = "ambientcue" // Timeout to hide cuebar if it wasn't interacted with private const val TAG = "AmbientCueRepository" private const val DEBUG = false private const val INVALID_TASK_ID = ActivityTaskManager.INVALID_TASK_ID } } packages/SystemUI/tests/utils/src/com/android/systemui/ambientcue/data/repository/FakeAmbientCueRepository.kt +7 −0 Original line number Diff line number Diff line Loading @@ -33,7 +33,14 @@ class FakeAmbientCueRepository : AmbientCueRepository { override val isImeVisible: MutableStateFlow<Boolean> = MutableStateFlow(false) private val _globallyFocusedTaskId = MutableStateFlow(0) override val globallyFocusedTaskId: StateFlow<Int> = _globallyFocusedTaskId.asStateFlow() fun setActions(actions: List<ActionModel>) { _actions.update { actions } } fun setGloballyFocusedTaskId(taskId: Int) { _globallyFocusedTaskId.update { taskId } } } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/ambientcue/data/repository/AmbientCueRepositoryTest.kt +17 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.ambientcue.data.repository import android.app.ActivityManager.RunningTaskInfo import android.app.smartspace.SmartspaceAction import android.app.smartspace.SmartspaceManager import android.app.smartspace.SmartspaceSession Loading @@ -32,6 +33,7 @@ import com.android.systemui.kosmos.backgroundScope import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runCurrent import com.android.systemui.kosmos.runTest import com.android.systemui.shade.data.repository.fakeFocusedDisplayRepository import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat import org.junit.Test Loading @@ -58,6 +60,7 @@ class AmbientCueRepositoryTest : SysuiTestCase() { smartSpaceManager = smartSpaceManager, executor = kosmos.fakeExecutor, applicationContext = kosmos.testableContext, focusdDisplayRepository = kosmos.fakeFocusedDisplayRepository, ) @Test Loading @@ -81,9 +84,7 @@ class AmbientCueRepositoryTest : SysuiTestCase() { runCurrent() verify(smartSpaceSession) .addOnTargetsAvailableListener(any(), onTargetsAvailableListenerCaptor.capture()) onTargetsAvailableListenerCaptor.firstValue.onTargetsAvailable( listOf(invalidTarget1) ) onTargetsAvailableListenerCaptor.firstValue.onTargetsAvailable(listOf(invalidTarget1)) advanceUntilIdle() assertThat(isVisible).isFalse() } Loading Loading @@ -112,6 +113,17 @@ class AmbientCueRepositoryTest : SysuiTestCase() { } } @Test fun globallyFocusedTaskId_whenFocusedTaskChange_taskIdUpdated() = kosmos.runTest { val globallyFocusedTaskId by collectLastValue(underTest.globallyFocusedTaskId) runCurrent() fakeFocusedDisplayRepository.setGlobalTask(RunningTaskInfo().apply { taskId = TASK_ID }) assertThat(globallyFocusedTaskId).isEqualTo(TASK_ID) } companion object { private const val TITLE_1 = "title 1" Loading Loading @@ -140,5 +152,7 @@ class AmbientCueRepositoryTest : SysuiTestCase() { } private val allTargets = listOf(validTarget, invalidTarget1) private const val TASK_ID = 1 } }
packages/SystemUI/src/com/android/systemui/ambientcue/data/repository/AmbientCueRepository.kt +17 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.ambientcue.data.repository import android.app.ActivityTaskManager import android.app.smartspace.SmartspaceConfig import android.app.smartspace.SmartspaceManager import android.app.smartspace.SmartspaceSession.OnTargetsAvailableListener Loading @@ -26,6 +27,7 @@ import com.android.systemui.ambientcue.shared.model.ActionModel import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.display.data.repository.FocusedDisplayRepository import com.android.systemui.res.R import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow import java.util.concurrent.Executor Loading @@ -35,6 +37,7 @@ import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.update Loading @@ -49,6 +52,9 @@ interface AmbientCueRepository { /** If IME is visible or not. */ val isImeVisible: MutableStateFlow<Boolean> /** Task Id which is globally focused on display. */ val globallyFocusedTaskId: StateFlow<Int> } @SysUISingleton Loading @@ -59,6 +65,7 @@ constructor( private val smartSpaceManager: SmartspaceManager?, @Background executor: Executor, @Application applicationContext: Context, focusdDisplayRepository: FocusedDisplayRepository, ) : AmbientCueRepository { override val actions: StateFlow<List<ActionModel>> = Loading Loading @@ -114,11 +121,21 @@ constructor( override val isImeVisible: MutableStateFlow<Boolean> = MutableStateFlow(false) override val globallyFocusedTaskId: StateFlow<Int> = focusdDisplayRepository.globallyFocusedTask .map { it?.taskId ?: INVALID_TASK_ID } .stateIn( scope = backgroundScope, started = SharingStarted.WhileSubscribed(), initialValue = INVALID_TASK_ID, ) companion object { // Surface that PCC wants to push cards into @VisibleForTesting const val AMBIENT_CUE_SURFACE = "ambientcue" // Timeout to hide cuebar if it wasn't interacted with private const val TAG = "AmbientCueRepository" private const val DEBUG = false private const val INVALID_TASK_ID = ActivityTaskManager.INVALID_TASK_ID } }
packages/SystemUI/tests/utils/src/com/android/systemui/ambientcue/data/repository/FakeAmbientCueRepository.kt +7 −0 Original line number Diff line number Diff line Loading @@ -33,7 +33,14 @@ class FakeAmbientCueRepository : AmbientCueRepository { override val isImeVisible: MutableStateFlow<Boolean> = MutableStateFlow(false) private val _globallyFocusedTaskId = MutableStateFlow(0) override val globallyFocusedTaskId: StateFlow<Int> = _globallyFocusedTaskId.asStateFlow() fun setActions(actions: List<ActionModel>) { _actions.update { actions } } fun setGloballyFocusedTaskId(taskId: Int) { _globallyFocusedTaskId.update { taskId } } }