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

Commit 56d17127 authored by Pechetty Sravani (xWF)'s avatar Pechetty Sravani (xWF) Committed by Android (Google) Code Review
Browse files

Merge "Revert "Tile perf: offload tile state adapter to bg"" into main

parents 8e7dbbaf d7106799
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package com.android.systemui.qs.tiles.impl.custom.domain.interactor

import android.os.UserHandle
import android.service.quicksettings.Tile
import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.systemui.common.coroutine.ConflatedCallbackFlow
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.qs.tiles.base.interactor.DataUpdateTrigger
import com.android.systemui.qs.tiles.base.interactor.QSTileDataInteractor
@@ -28,7 +28,6 @@ import com.android.systemui.qs.tiles.impl.custom.data.repository.CustomTilePacka
import com.android.systemui.qs.tiles.impl.custom.domain.entity.CustomTileDataModel
import com.android.systemui.qs.tiles.impl.di.QSTileScope
import com.android.systemui.user.data.repository.UserRepository
import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -45,6 +44,7 @@ import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.shareIn
import com.android.app.tracing.coroutines.launchTraced as launch

@QSTileScope
@OptIn(ExperimentalCoroutinesApi::class)
@@ -64,7 +64,7 @@ constructor(
    private val bindingFlow =
        mutableUserFlow
            .flatMapLatest { user ->
                conflatedCallbackFlow {
                ConflatedCallbackFlow.conflatedCallbackFlow {
                    serviceInteractor.setUser(user)

                    // Wait for the CustomTileInteractor to become initialized first, because
@@ -79,7 +79,7 @@ constructor(
                            defaultsRepository.requestNewDefaults(
                                user,
                                tileSpec.componentName,
                                true,
                                true
                            )
                        }
                        .launchIn(this)
@@ -99,7 +99,7 @@ constructor(

    override fun tileData(
        user: UserHandle,
        triggers: Flow<DataUpdateTrigger>,
        triggers: Flow<DataUpdateTrigger>
    ): Flow<CustomTileDataModel> {
        tileScope.launch { mutableUserFlow.emit(user) }
        return bindingFlow.combine(triggers) { _, _ -> }.flatMapLatest { dataFlow(user) }
+12 −23
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import com.android.systemui.Dumpable
import com.android.systemui.animation.Expandable
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.UiBackground
import com.android.systemui.plugins.qs.QSTile
import com.android.systemui.qs.QSHost
import com.android.systemui.qs.tileimpl.QSTileImpl.DrawableIcon
@@ -36,17 +35,14 @@ import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import java.io.PrintWriter
import java.util.concurrent.CopyOnWriteArraySet
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collectIndexed
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.takeWhile
import kotlinx.coroutines.launch

// TODO(b/http://b/299909989): Use QSTileViewModel directly after the rollout
class QSTileViewModelAdapter
@@ -55,7 +51,6 @@ constructor(
    @Application private val applicationScope: CoroutineScope,
    private val qsHost: QSHost,
    @Assisted private val qsTileViewModel: QSTileViewModel,
    @UiBackground private val uiBgDispatcher: CoroutineDispatcher,
) : QSTile, Dumpable {

    private val context
@@ -167,12 +162,8 @@ constructor(
    override fun setListening(client: Any?, listening: Boolean) {
        client ?: return
        if (listening) {
            applicationScope.launch(uiBgDispatcher) {
                val shouldStartMappingJob =
                    listeningClients.add(client) // new client
                    && listeningClients.size == 1 // first client

                if (shouldStartMappingJob) {
            val clientWasNotAlreadyListening = listeningClients.add(client)
            if (clientWasNotAlreadyListening && listeningClients.size == 1) {
                stateJob =
                    qsTileViewModel.state
                        .filterNotNull()
@@ -183,10 +174,8 @@ constructor(
                                callbacks.forEach { it.onStateChanged(legacyState) }
                            }
                        }
                            .flowOn(uiBgDispatcher)
                        .launchIn(applicationScope)
            }
            }
        } else {
            listeningClients.remove(client)
            if (listeningClients.isEmpty()) {
+0 −2
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.qs.tiles.viewmodel

import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.util.mockito.mock

val Kosmos.qsTileViewModelAdaperFactory by
@@ -29,7 +28,6 @@ val Kosmos.qsTileViewModelAdaperFactory by
                    applicationCoroutineScope,
                    mock(),
                    qsTileViewModel,
                    testDispatcher,
                )
            }
        }