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

Commit b6c9a433 authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Create ShadeStateTraceLogger

This new class logs some of the shade attributes to a perfetto trace, to make debugging of issues easier.

Bug: 362719719
Test: perfetto trace
Flag: NONE logging change
Change-Id: If52c45a9f61f6716a80f6829c847a15879fbf4a8
parent 26a84de2
Loading
Loading
Loading
Loading
+70 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.shade

import com.android.app.tracing.TraceStateLogger
import com.android.app.tracing.TrackGroupUtils.trackGroup
import com.android.app.tracing.coroutines.TrackTracer.Companion.instantForGroup
import com.android.app.tracing.coroutines.launchTraced
import com.android.systemui.CoreStartable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.shade.data.repository.ShadeDisplaysRepository
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

@SysUISingleton
class ShadeStateTraceLogger
@Inject
constructor(
    private val shadeInteractor: ShadeInteractor,
    private val shadeDisplaysRepository: ShadeDisplaysRepository,
    @Application private val scope: CoroutineScope,
) : CoreStartable {
    override fun start() {
        scope.launchTraced("ShadeStateTraceLogger") {
            launch {
                val stateLogger = createTraceStateLogger("isShadeLayoutWide")
                shadeInteractor.isShadeLayoutWide.collect { stateLogger.log(it.toString()) }
            }
            launch {
                val stateLogger = createTraceStateLogger("shadeMode")
                shadeInteractor.shadeMode.collect { stateLogger.log(it.toString()) }
            }
            launch {
                shadeInteractor.shadeExpansion.collect {
                    instantForGroup(TRACK_GROUP_NAME, "shadeExpansion", it)
                }
            }
            launch {
                shadeDisplaysRepository.displayId.collect {
                    instantForGroup(TRACK_GROUP_NAME, "displayId", it)
                }
            }
        }
    }

    private fun createTraceStateLogger(trackName: String): TraceStateLogger {
        return TraceStateLogger(trackGroup(TRACK_GROUP_NAME, trackName))
    }

    private companion object {
        const val TRACK_GROUP_NAME = "shade"
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -40,4 +40,9 @@ internal abstract class StartShadeModule {
    @IntoMap
    @ClassKey(ShadeStartable::class)
    abstract fun provideShadeStartable(startable: ShadeStartable): CoreStartable

    @Binds
    @IntoMap
    @ClassKey(ShadeStateTraceLogger::class)
    abstract fun provideShadeStateTraceLogger(startable: ShadeStateTraceLogger): CoreStartable
}