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

Commit 469f5c08 authored by Fabián Kozynski's avatar Fabián Kozynski Committed by Automerger Merge Worker
Browse files
parents b89998c8 bd1e4390
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -161,7 +161,9 @@ public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory>, P
            // finishes before creating any tiles.
            tunerService.addTunable(this, TILES_SETTING);
            // AutoTileManager can modify mTiles so make sure mTiles has already been initialized.
            if (!mFeatureFlags.isEnabled(Flags.QS_PIPELINE_AUTO_ADD)) {
                mAutoTiles = autoTiles.get();
            }
        });
    }

+22 −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.dagger

import javax.inject.Qualifier

/** A [LogBuffer] for the QS pipeline to track auto-added tiles */
@Qualifier @MustBeDocumented @Retention(AnnotationRetention.RUNTIME) annotation class QSAutoAddLog
+28 −1
Original line number Diff line number Diff line
@@ -16,13 +16,40 @@

package com.android.systemui.qs.pipeline.dagger

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogBufferFactory
import com.android.systemui.qs.pipeline.data.repository.AutoAddRepository
import com.android.systemui.qs.pipeline.data.repository.AutoAddSettingRepository
import com.android.systemui.qs.pipeline.domain.model.AutoAddable
import com.android.systemui.qs.pipeline.shared.logging.QSPipelineLogger
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.multibindings.Multibinds

@Module
@Module(
    includes =
        [
            BaseAutoAddableModule::class,
        ]
)
abstract class QSAutoAddModule {

    @Binds abstract fun bindAutoAddRepository(impl: AutoAddSettingRepository): AutoAddRepository

    @Multibinds abstract fun providesAutoAddableSet(): Set<AutoAddable>

    companion object {
        /**
         * Provides a logging buffer for all logs related to the new Quick Settings pipeline to log
         * auto added tiles.
         */
        @Provides
        @SysUISingleton
        @QSAutoAddLog
        fun provideQSAutoAddLogBuffer(factory: LogBufferFactory): LogBuffer {
            return factory.create(QSPipelineLogger.AUTO_ADD_TAG, maxSize = 100, systrace = false)
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -19,5 +19,5 @@ import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
import javax.inject.Qualifier

/** A {@link LogBuffer} for the new QS Pipeline for logging changes to the set of current tiles. */
/** A [LogBuffer] for the new QS Pipeline for logging changes to the set of current tiles. */
@Qualifier @MustBeDocumented @Retention(RetentionPolicy.RUNTIME) annotation class QSTileListLog
+123 −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.interactor

import com.android.systemui.Dumpable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dump.DumpManager
import com.android.systemui.qs.pipeline.data.repository.AutoAddRepository
import com.android.systemui.qs.pipeline.domain.model.AutoAddSignal
import com.android.systemui.qs.pipeline.domain.model.AutoAddTracking
import com.android.systemui.qs.pipeline.domain.model.AutoAddable
import com.android.systemui.qs.pipeline.shared.logging.QSPipelineLogger
import com.android.systemui.util.asIndenting
import com.android.systemui.util.indentIfPossible
import java.io.PrintWriter
import java.util.concurrent.atomic.AtomicBoolean
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.launch

/**
 * Collects the signals coming from all registered [AutoAddable] and adds/removes tiles accordingly.
 */
@SysUISingleton
class AutoAddInteractor
@Inject
constructor(
    private val autoAddables: Set<@JvmSuppressWildcards AutoAddable>,
    private val repository: AutoAddRepository,
    private val dumpManager: DumpManager,
    private val qsPipelineLogger: QSPipelineLogger,
    @Application private val scope: CoroutineScope,
) : Dumpable {

    private val initialized = AtomicBoolean(false)

    /** Start collection of signals following the user from [currentTilesInteractor]. */
    fun init(currentTilesInteractor: CurrentTilesInteractor) {
        if (!initialized.compareAndSet(false, true)) {
            return
        }

        dumpManager.registerNormalDumpable(TAG, this)

        scope.launch {
            currentTilesInteractor.userId.collectLatest { userId ->
                coroutineScope {
                    val previouslyAdded = repository.autoAddedTiles(userId).stateIn(this)

                    autoAddables
                        .map { addable ->
                            val autoAddSignal = addable.autoAddSignal(userId)
                            when (val lifecycle = addable.autoAddTracking) {
                                is AutoAddTracking.Always -> autoAddSignal
                                is AutoAddTracking.Disabled -> emptyFlow()
                                is AutoAddTracking.IfNotAdded -> {
                                    if (lifecycle.spec !in previouslyAdded.value) {
                                        autoAddSignal.filterIsInstance<AutoAddSignal.Add>().take(1)
                                    } else {
                                        emptyFlow()
                                    }
                                }
                            }
                        }
                        .merge()
                        .collect { signal ->
                            when (signal) {
                                is AutoAddSignal.Add -> {
                                    if (signal.spec !in previouslyAdded.value) {
                                        currentTilesInteractor.addTile(signal.spec, signal.position)
                                        qsPipelineLogger.logTileAutoAdded(
                                            userId,
                                            signal.spec,
                                            signal.position
                                        )
                                        repository.markTileAdded(userId, signal.spec)
                                    }
                                }
                                is AutoAddSignal.Remove -> {
                                    currentTilesInteractor.removeTiles(setOf(signal.spec))
                                    qsPipelineLogger.logTileAutoRemoved(userId, signal.spec)
                                    repository.unmarkTileAdded(userId, signal.spec)
                                }
                            }
                        }
                }
            }
        }
    }

    override fun dump(pw: PrintWriter, args: Array<out String>) {
        with(pw.asIndenting()) {
            println("AutoAddables:")
            indentIfPossible { autoAddables.forEach { println(it.description) } }
        }
    }

    companion object {
        private const val TAG = "AutoAddInteractor"
    }
}
Loading