diff --git a/packages/SystemUI/src/com/android/systemui/qs/pipeline/dagger/QSPipelineModule.kt b/packages/SystemUI/src/com/android/systemui/qs/pipeline/dagger/QSPipelineModule.kt index d7ae575724dd4..a4600fbbf4bd0 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/pipeline/dagger/QSPipelineModule.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/pipeline/dagger/QSPipelineModule.kt @@ -26,7 +26,7 @@ import com.android.systemui.qs.pipeline.data.repository.TileSpecRepository import com.android.systemui.qs.pipeline.data.repository.TileSpecSettingsRepository import com.android.systemui.qs.pipeline.domain.interactor.CurrentTilesInteractor import com.android.systemui.qs.pipeline.domain.interactor.CurrentTilesInteractorImpl -import com.android.systemui.qs.pipeline.prototyping.PrototypeCoreStartable +import com.android.systemui.qs.pipeline.domain.startable.QSPipelineCoreStartable import com.android.systemui.qs.pipeline.shared.logging.QSPipelineLogger import dagger.Binds import dagger.Module @@ -53,8 +53,8 @@ abstract class QSPipelineModule { @Binds @IntoMap - @ClassKey(PrototypeCoreStartable::class) - abstract fun providePrototypeCoreStartable(startable: PrototypeCoreStartable): CoreStartable + @ClassKey(QSPipelineCoreStartable::class) + abstract fun provideCoreStartable(startable: QSPipelineCoreStartable): CoreStartable companion object { /** diff --git a/packages/SystemUI/src/com/android/systemui/qs/pipeline/domain/interactor/CurrentTilesInteractor.kt b/packages/SystemUI/src/com/android/systemui/qs/pipeline/domain/interactor/CurrentTilesInteractor.kt index 81b682a4836c1..ff881f767b877 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/pipeline/domain/interactor/CurrentTilesInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/pipeline/domain/interactor/CurrentTilesInteractor.kt @@ -125,7 +125,6 @@ interface CurrentTilesInteractor : ProtoDumpable { class CurrentTilesInteractorImpl @Inject constructor( - autoAddInteractor: AutoAddInteractor, private val tileSpecRepository: TileSpecRepository, private val installedTilesComponentRepository: InstalledTilesComponentRepository, private val userRepository: UserRepository, @@ -173,10 +172,6 @@ constructor( if (featureFlags.isEnabled(Flags.QS_PIPELINE_NEW_HOST)) { startTileCollection() } - - if (featureFlags.isEnabled(Flags.QS_PIPELINE_AUTO_ADD)) { - autoAddInteractor.init(this) - } } @OptIn(ExperimentalCoroutinesApi::class) diff --git a/packages/SystemUI/src/com/android/systemui/qs/pipeline/domain/startable/QSPipelineCoreStartable.kt b/packages/SystemUI/src/com/android/systemui/qs/pipeline/domain/startable/QSPipelineCoreStartable.kt new file mode 100644 index 0000000000000..224fc1ae864fd --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/qs/pipeline/domain/startable/QSPipelineCoreStartable.kt @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2023 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.qs.pipeline.domain.startable + +import com.android.systemui.CoreStartable +import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.flags.FeatureFlags +import com.android.systemui.flags.Flags +import com.android.systemui.qs.pipeline.domain.interactor.AutoAddInteractor +import com.android.systemui.qs.pipeline.domain.interactor.CurrentTilesInteractor +import javax.inject.Inject + +@SysUISingleton +class QSPipelineCoreStartable +@Inject +constructor( + private val currentTilesInteractor: CurrentTilesInteractor, + private val autoAddInteractor: AutoAddInteractor, + private val featureFlags: FeatureFlags, +) : CoreStartable { + + override fun start() { + if ( + featureFlags.isEnabled(Flags.QS_PIPELINE_NEW_HOST) && + featureFlags.isEnabled(Flags.QS_PIPELINE_AUTO_ADD) + ) { + autoAddInteractor.init(currentTilesInteractor) + } + } +} diff --git a/packages/SystemUI/src/com/android/systemui/qs/pipeline/prototyping/PrototypeCoreStartable.kt b/packages/SystemUI/src/com/android/systemui/qs/pipeline/prototyping/PrototypeCoreStartable.kt deleted file mode 100644 index bbd72341acc68..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/qs/pipeline/prototyping/PrototypeCoreStartable.kt +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2023 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.qs.pipeline.prototyping - -import android.util.Log -import com.android.systemui.CoreStartable -import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.dagger.qualifiers.Application -import com.android.systemui.flags.FeatureFlags -import com.android.systemui.flags.Flags -import com.android.systemui.qs.pipeline.data.repository.AutoAddRepository -import com.android.systemui.qs.pipeline.data.repository.TileSpecRepository -import com.android.systemui.qs.pipeline.shared.TileSpec -import com.android.systemui.statusbar.commandline.Command -import com.android.systemui.statusbar.commandline.CommandRegistry -import com.android.systemui.user.data.repository.UserRepository -import java.io.PrintWriter -import javax.inject.Inject -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.flow.flatMapLatest -import kotlinx.coroutines.launch - -/** - * Class for observing results while prototyping. - * - * The flows do their own logging, so we just need to make sure that they collect. - * - * This will be torn down together with the last of the new pipeline flags remaining here. - */ -// TODO(b/270385608) -@SysUISingleton -class PrototypeCoreStartable -@Inject -constructor( - private val tileSpecRepository: TileSpecRepository, - private val autoAddRepository: AutoAddRepository, - private val userRepository: UserRepository, - private val featureFlags: FeatureFlags, - @Application private val scope: CoroutineScope, - private val commandRegistry: CommandRegistry, -) : CoreStartable { - - @OptIn(ExperimentalCoroutinesApi::class) - override fun start() { - if (featureFlags.isEnabled(Flags.QS_PIPELINE_NEW_HOST)) { - scope.launch { - userRepository.selectedUserInfo - .flatMapLatest { user -> tileSpecRepository.tilesSpecs(user.id) } - .collect {} - } - if (featureFlags.isEnabled(Flags.QS_PIPELINE_AUTO_ADD)) { - scope.launch { - userRepository.selectedUserInfo - .flatMapLatest { user -> autoAddRepository.autoAddedTiles(user.id) } - .collect { tiles -> Log.d(TAG, "Auto-added tiles: $tiles") } - } - } - commandRegistry.registerCommand(COMMAND, ::CommandExecutor) - } - } - - private inner class CommandExecutor : Command { - override fun execute(pw: PrintWriter, args: List) { - if (args.size < 2) { - pw.println("Error: needs at least two arguments") - return - } - val spec = TileSpec.create(args[1]) - if (spec == TileSpec.Invalid) { - pw.println("Error: Invalid tile spec ${args[1]}") - } - if (args[0] == "add") { - performAdd(args, spec) - pw.println("Requested tile added") - } else if (args[0] == "remove") { - performRemove(args, spec) - pw.println("Requested tile removed") - } else { - pw.println("Error: unknown command") - } - } - - private fun performAdd(args: List, spec: TileSpec) { - val position = args.getOrNull(2)?.toInt() ?: TileSpecRepository.POSITION_AT_END - val user = args.getOrNull(3)?.toInt() ?: userRepository.getSelectedUserInfo().id - scope.launch { tileSpecRepository.addTile(user, spec, position) } - } - - private fun performRemove(args: List, spec: TileSpec) { - val user = args.getOrNull(2)?.toInt() ?: userRepository.getSelectedUserInfo().id - scope.launch { tileSpecRepository.removeTiles(user, listOf(spec)) } - } - - override fun help(pw: PrintWriter) { - pw.println("Usage: adb shell cmd statusbar $COMMAND:") - pw.println(" add [position] [user]") - pw.println(" remove [user]") - } - } - - companion object { - private const val COMMAND = "qs-pipeline" - private const val TAG = "PrototypeCoreStartable" - } -} diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/pipeline/domain/interactor/CurrentTilesInteractorImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/pipeline/domain/interactor/CurrentTilesInteractorImplTest.kt index 522ffc1d498ca..30cea2d3a4879 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/pipeline/domain/interactor/CurrentTilesInteractorImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/pipeline/domain/interactor/CurrentTilesInteractorImplTest.kt @@ -83,8 +83,6 @@ class CurrentTilesInteractorImplTest : SysuiTestCase() { @Mock private lateinit var customTileStatePersister: CustomTileStatePersister - @Mock private lateinit var autoAddInteractor: AutoAddInteractor - @Mock private lateinit var userTracker: UserTracker @Mock private lateinit var logger: QSPipelineLogger @@ -110,7 +108,6 @@ class CurrentTilesInteractorImplTest : SysuiTestCase() { underTest = CurrentTilesInteractorImpl( - autoAddInteractor = autoAddInteractor, tileSpecRepository = tileSpecRepository, installedTilesComponentRepository = installedTilesPackageRepository, userRepository = userRepository, @@ -651,11 +648,6 @@ class CurrentTilesInteractorImplTest : SysuiTestCase() { assertThat(tiles!![1].spec).isEqualTo(CUSTOM_TILE_SPEC) } - @Test - fun autoAddInteractor_initted() { - verify(autoAddInteractor).init(underTest) - } - private fun QSTile.State.fillIn(state: Int, label: CharSequence, secondaryLabel: CharSequence) { this.state = state this.label = label