Loading packages/SystemUI/multivalentTests/src/com/android/systemui/qs/pipeline/domain/interactor/AutoAddInteractorTest.kt +41 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import com.android.systemui.qs.pipeline.data.repository.FakeAutoAddRepository import com.android.systemui.qs.pipeline.domain.autoaddable.FakeAutoAddable import com.android.systemui.qs.pipeline.domain.model.AutoAddTracking import com.android.systemui.qs.pipeline.domain.model.AutoAddable import com.android.systemui.qs.pipeline.domain.model.TileModel import com.android.systemui.qs.pipeline.shared.TileSpec import com.android.systemui.qs.pipeline.shared.logging.QSPipelineLogger import com.android.systemui.util.mockito.any Loading Loading @@ -65,6 +66,7 @@ class AutoAddInteractorTest : SysuiTestCase() { MockitoAnnotations.initMocks(this) whenever(currentTilesInteractor.userId).thenReturn(MutableStateFlow(USER)) whenever(currentTilesInteractor.currentTiles).thenReturn(MutableStateFlow(emptyList())) } @Test Loading Loading @@ -201,6 +203,45 @@ class AutoAddInteractorTest : SysuiTestCase() { assertThat(autoAddedTiles).doesNotContain(SPEC) } @Test fun autoAddable_trackIfNotAdded_currentTile_markedAsAdded() = testScope.runTest { val fakeTile = FakeQSTile(USER).apply { tileSpec = SPEC.spec } val fakeCurrentTileModel = TileModel(SPEC, fakeTile) whenever(currentTilesInteractor.currentTiles) .thenReturn(MutableStateFlow(listOf(fakeCurrentTileModel))) val autoAddedTiles by collectLastValue(autoAddRepository.autoAddedTiles(USER)) val fakeAutoAddable = FakeAutoAddable(SPEC, AutoAddTracking.IfNotAdded(SPEC)) underTest = createInteractor(setOf(fakeAutoAddable)) runCurrent() assertThat(autoAddedTiles).contains(SPEC) } @Test fun autoAddable_trackIfNotAdded_tileAddedToCurrentTiles_markedAsAdded() = testScope.runTest { val fakeTile = FakeQSTile(USER).apply { tileSpec = SPEC.spec } val fakeCurrentTileModel = TileModel(SPEC, fakeTile) val currentTilesFlow = MutableStateFlow(emptyList<TileModel>()) whenever(currentTilesInteractor.currentTiles).thenReturn(currentTilesFlow) val autoAddedTiles by collectLastValue(autoAddRepository.autoAddedTiles(USER)) val fakeAutoAddable = FakeAutoAddable(SPEC, AutoAddTracking.IfNotAdded(SPEC)) underTest = createInteractor(setOf(fakeAutoAddable)) runCurrent() assertThat(autoAddedTiles).doesNotContain(SPEC) currentTilesFlow.value = listOf(fakeCurrentTileModel) assertThat(autoAddedTiles).contains(SPEC) } private fun createInteractor(autoAddables: Set<AutoAddable>): AutoAddInteractor { return AutoAddInteractor( autoAddables, Loading packages/SystemUI/src/com/android/systemui/qs/pipeline/domain/interactor/AutoAddInteractor.kt +58 −40 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.take Loading @@ -55,6 +56,7 @@ constructor( ) : Dumpable { private val initialized = AtomicBoolean(false) private lateinit var currentTilesInteractor: CurrentTilesInteractor /** Start collection of signals following the user from [currentTilesInteractor]. */ fun init(currentTilesInteractor: CurrentTilesInteractor) { Loading @@ -62,11 +64,34 @@ constructor( return } this.currentTilesInteractor = currentTilesInteractor dumpManager.registerNormalDumpable(TAG, this) scope.launch { currentTilesInteractor.userId.collectLatest { userId -> coroutineScope { launch { collectAutoAddSignalsForUser(userId) } launch { markTrackIfNotAddedTilesThatAreCurrent(userId) } } } } } private suspend fun markTrackIfNotAddedTilesThatAreCurrent(userId: Int) { val trackIfNotAddedSpecs = autoAddables .map { it.autoAddTracking } .filterIsInstance<AutoAddTracking.IfNotAdded>() .map { it.spec } currentTilesInteractor.currentTiles .map { tiles -> tiles.map { it.spec } } .collect { it.filter { it in trackIfNotAddedSpecs } .forEach { spec -> repository.markTileAdded(userId, spec) } } } private suspend fun CoroutineScope.collectAutoAddSignalsForUser(userId: Int) { val previouslyAdded = repository.autoAddedTiles(userId).stateIn(this) autoAddables Loading @@ -90,11 +115,7 @@ constructor( is AutoAddSignal.Add -> { if (signal.spec !in previouslyAdded.value) { currentTilesInteractor.addTile(signal.spec, signal.position) qsPipelineLogger.logTileAutoAdded( userId, signal.spec, signal.position ) qsPipelineLogger.logTileAutoAdded(userId, signal.spec, signal.position) repository.markTileAdded(userId, signal.spec) } } Loading @@ -110,9 +131,6 @@ constructor( } } } } } } override fun dump(pw: PrintWriter, args: Array<out String>) { with(pw.asIndenting()) { Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/pipeline/domain/interactor/AutoAddInteractorTest.kt +41 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import com.android.systemui.qs.pipeline.data.repository.FakeAutoAddRepository import com.android.systemui.qs.pipeline.domain.autoaddable.FakeAutoAddable import com.android.systemui.qs.pipeline.domain.model.AutoAddTracking import com.android.systemui.qs.pipeline.domain.model.AutoAddable import com.android.systemui.qs.pipeline.domain.model.TileModel import com.android.systemui.qs.pipeline.shared.TileSpec import com.android.systemui.qs.pipeline.shared.logging.QSPipelineLogger import com.android.systemui.util.mockito.any Loading Loading @@ -65,6 +66,7 @@ class AutoAddInteractorTest : SysuiTestCase() { MockitoAnnotations.initMocks(this) whenever(currentTilesInteractor.userId).thenReturn(MutableStateFlow(USER)) whenever(currentTilesInteractor.currentTiles).thenReturn(MutableStateFlow(emptyList())) } @Test Loading Loading @@ -201,6 +203,45 @@ class AutoAddInteractorTest : SysuiTestCase() { assertThat(autoAddedTiles).doesNotContain(SPEC) } @Test fun autoAddable_trackIfNotAdded_currentTile_markedAsAdded() = testScope.runTest { val fakeTile = FakeQSTile(USER).apply { tileSpec = SPEC.spec } val fakeCurrentTileModel = TileModel(SPEC, fakeTile) whenever(currentTilesInteractor.currentTiles) .thenReturn(MutableStateFlow(listOf(fakeCurrentTileModel))) val autoAddedTiles by collectLastValue(autoAddRepository.autoAddedTiles(USER)) val fakeAutoAddable = FakeAutoAddable(SPEC, AutoAddTracking.IfNotAdded(SPEC)) underTest = createInteractor(setOf(fakeAutoAddable)) runCurrent() assertThat(autoAddedTiles).contains(SPEC) } @Test fun autoAddable_trackIfNotAdded_tileAddedToCurrentTiles_markedAsAdded() = testScope.runTest { val fakeTile = FakeQSTile(USER).apply { tileSpec = SPEC.spec } val fakeCurrentTileModel = TileModel(SPEC, fakeTile) val currentTilesFlow = MutableStateFlow(emptyList<TileModel>()) whenever(currentTilesInteractor.currentTiles).thenReturn(currentTilesFlow) val autoAddedTiles by collectLastValue(autoAddRepository.autoAddedTiles(USER)) val fakeAutoAddable = FakeAutoAddable(SPEC, AutoAddTracking.IfNotAdded(SPEC)) underTest = createInteractor(setOf(fakeAutoAddable)) runCurrent() assertThat(autoAddedTiles).doesNotContain(SPEC) currentTilesFlow.value = listOf(fakeCurrentTileModel) assertThat(autoAddedTiles).contains(SPEC) } private fun createInteractor(autoAddables: Set<AutoAddable>): AutoAddInteractor { return AutoAddInteractor( autoAddables, Loading
packages/SystemUI/src/com/android/systemui/qs/pipeline/domain/interactor/AutoAddInteractor.kt +58 −40 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.take Loading @@ -55,6 +56,7 @@ constructor( ) : Dumpable { private val initialized = AtomicBoolean(false) private lateinit var currentTilesInteractor: CurrentTilesInteractor /** Start collection of signals following the user from [currentTilesInteractor]. */ fun init(currentTilesInteractor: CurrentTilesInteractor) { Loading @@ -62,11 +64,34 @@ constructor( return } this.currentTilesInteractor = currentTilesInteractor dumpManager.registerNormalDumpable(TAG, this) scope.launch { currentTilesInteractor.userId.collectLatest { userId -> coroutineScope { launch { collectAutoAddSignalsForUser(userId) } launch { markTrackIfNotAddedTilesThatAreCurrent(userId) } } } } } private suspend fun markTrackIfNotAddedTilesThatAreCurrent(userId: Int) { val trackIfNotAddedSpecs = autoAddables .map { it.autoAddTracking } .filterIsInstance<AutoAddTracking.IfNotAdded>() .map { it.spec } currentTilesInteractor.currentTiles .map { tiles -> tiles.map { it.spec } } .collect { it.filter { it in trackIfNotAddedSpecs } .forEach { spec -> repository.markTileAdded(userId, spec) } } } private suspend fun CoroutineScope.collectAutoAddSignalsForUser(userId: Int) { val previouslyAdded = repository.autoAddedTiles(userId).stateIn(this) autoAddables Loading @@ -90,11 +115,7 @@ constructor( is AutoAddSignal.Add -> { if (signal.spec !in previouslyAdded.value) { currentTilesInteractor.addTile(signal.spec, signal.position) qsPipelineLogger.logTileAutoAdded( userId, signal.spec, signal.position ) qsPipelineLogger.logTileAutoAdded(userId, signal.spec, signal.position) repository.markTileAdded(userId, signal.spec) } } Loading @@ -110,9 +131,6 @@ constructor( } } } } } } override fun dump(pw: PrintWriter, args: Array<out String>) { with(pw.asIndenting()) { Loading