Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd51b9b9 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Automerger Merge Worker
Browse files

Merge changes from topic "278577795" into udc-qpr-dev am: 4c79ccb1

parents 469f5c08 4c79ccb1
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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 {
        /**
+0 −5
Original line number Diff line number Diff line
@@ -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)
+44 −0
Original line number Diff line number Diff line
/*
 * 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)
        }
    }
}
+0 −120
Original line number Diff line number Diff line
/*
 * 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<String>) {
            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<String>, 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<String>, 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 <spec> [position] [user]")
            pw.println("  remove <spec> [user]")
        }
    }

    companion object {
        private const val COMMAND = "qs-pipeline"
        private const val TAG = "PrototypeCoreStartable"
    }
}
+0 −8
Original line number Diff line number Diff line
@@ -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