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

Commit 3d4dbbea authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Introduce a logbuffer for Shade display changes

Bug: 362719719
Bug: 403570017
Test: checked for logcats in perfetto traces
Flag: com.android.systemui.shade_window_goes_around
Change-Id: Icf816e1831bd499735963b20d4bd56be4c8cdea7
parent 39f6dcef
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.view.WindowManager
import android.view.WindowManager.LayoutParams
import android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE
import android.window.WindowContext
import com.android.app.tracing.TrackGroupUtils.trackGroup
import com.android.systemui.CoreStartable
import com.android.systemui.common.ui.ConfigurationState
import com.android.systemui.common.ui.ConfigurationStateImpl
@@ -34,6 +35,8 @@ import com.android.systemui.common.ui.view.ChoreographerUtils
import com.android.systemui.common.ui.view.ChoreographerUtilsImpl
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogBufferFactory
import com.android.systemui.res.R
import com.android.systemui.scene.ui.view.WindowRootView
import com.android.systemui.shade.data.repository.MutableShadeDisplaysRepository
@@ -263,6 +266,20 @@ object ShadeDisplayAwareModule {
    @Provides
    @ShadeOnDefaultDisplayWhenLocked
    fun provideShadeOnDefaultDisplayWhenLocked(): Boolean = true

    /** Provides a [LogBuffer] for use by classes related to shade movement */
    @Provides
    @SysUISingleton
    @ShadeDisplayLog
    fun provideShadeDisplayLogLogBuffer(factory: LogBufferFactory): LogBuffer {
        val logBufferName = "ShadeDisplayLog"
        return factory.create(
            logBufferName,
            maxSize = 400,
            alwaysLogToLogcat = true,
            systraceTrackName = trackGroup("shade", logBufferName),
        )
    }
}

/** Module that should be included only if the shade window [WindowRootView] is available. */
@@ -295,3 +312,6 @@ object ShadeDisplayAwareWithShadeWindowModule {
 * how well this solution behaves from the performance point of view.
 */
@Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class ShadeOnDefaultDisplayWhenLocked

/** A [com.android.systemui.log.LogBuffer] for changes to the shade display. */
@Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class ShadeDisplayLog
+15 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import com.android.systemui.CoreStartable
import com.android.systemui.common.ui.data.repository.ConfigurationRepository
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.shade.data.repository.ShadeDisplaysRepository
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.shade.domain.interactor.ShadeModeInteractor
@@ -42,6 +44,7 @@ constructor(
    private val shadeDisplaysRepository: Lazy<ShadeDisplaysRepository>,
    @ShadeDisplayAware private val configurationRepository: ConfigurationRepository,
    @Application private val scope: CoroutineScope,
    @ShadeDisplayLog private val logBuffer: LogBuffer,
) : CoreStartable {
    override fun start() {
        scope.launchTraced("ShadeStateTraceLogger") {
@@ -72,6 +75,18 @@ constructor(
                        "configurationChange#smallestScreenWidthDp",
                        it.smallestScreenWidthDp,
                    )
                    logBuffer.log(
                        "ShadeStateTraceLogger",
                        LogLevel.DEBUG,
                        {
                            int1 = it.smallestScreenWidthDp
                            int2 = it.densityDpi
                        },
                        {
                            "New configuration change from Shade window. " +
                                "smallestScreenWidthDp: $int1, densityDpi: $int2"
                        },
                    )
                }
            }
        }
+24 −5
Original line number Diff line number Diff line
@@ -27,8 +27,11 @@ import com.android.systemui.common.ui.data.repository.ConfigurationRepository
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.shade.ShadeDisplayAware
import com.android.systemui.shade.ShadeDisplayChangeLatencyTracker
import com.android.systemui.shade.ShadeDisplayLog
import com.android.systemui.shade.ShadeTraceLogger.logMoveShadeWindowTo
import com.android.systemui.shade.ShadeTraceLogger.t
import com.android.systemui.shade.ShadeTraceLogger.traceReparenting
@@ -69,6 +72,7 @@ constructor(
    private val notificationRebindingTracker: NotificationRebindingTracker,
    private val notificationStackRebindingHider: NotificationStackRebindingHider,
    @ShadeDisplayAware private val configForwarder: ConfigurationForwarder,
    @ShadeDisplayLog private val logBuffer: LogBuffer,
) : CoreStartable {

    private val hasActiveNotifications: Boolean
@@ -101,7 +105,12 @@ constructor(

    /** Tries to move the shade. If anything wrong happens, fails gracefully without crashing. */
    private suspend fun moveShadeWindowTo(destinationId: Int) {
        Log.d(TAG, "Trying to move shade window to display with id $destinationId")
        logBuffer.log(
            TAG,
            LogLevel.DEBUG,
            { int1 = destinationId },
            { "Trying to move shade window to display with id $int1" },
        )
        logMoveShadeWindowTo(destinationId)
        var currentId = -1
        try {
@@ -113,7 +122,12 @@ constructor(
            val currentDisplay = shadeContext.display ?: error("Current shade display is null")
            currentId = currentDisplay.displayId
            if (currentId == destinationId) {
                Log.w(TAG, "Trying to move the shade to a display ($currentId) it was already in ")
                logBuffer.log(
                    TAG,
                    LogLevel.WARNING,
                    { int1 = currentId },
                    { "Trying to move the shade to a display ($int1) it was already in." },
                )
                return
            }

@@ -128,9 +142,14 @@ constructor(
                }
            }
        } catch (e: IllegalStateException) {
            Log.e(
            logBuffer.log(
                TAG,
                "Unable to move the shade window from display $currentId to $destinationId",
                LogLevel.ERROR,
                {
                    int1 = currentId
                    int2 = destinationId
                },
                { "Unable to move the shade window from display $int1 to $int2" },
                e,
            )
        }
@@ -200,7 +219,7 @@ constructor(
    }

    private fun errorLog(s: String) {
        Log.e(TAG, s)
        logBuffer.log(TAG, LogLevel.ERROR, s)
    }

    private fun checkContextDisplayMatchesExpected(destinationId: Int) {
+2 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.window.WindowContext
import com.android.systemui.common.ui.data.repository.configurationRepository
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testScope
import com.android.systemui.log.logcatLogBuffer
import com.android.systemui.shade.ShadeDisplayChangeLatencyTracker
import com.android.systemui.shade.ShadeWindowLayoutParams
import com.android.systemui.shade.data.repository.fakeShadeDisplaysRepository
@@ -60,5 +61,6 @@ val Kosmos.shadeDisplaysInteractor by
            notificationRebindingTracker,
            notificationStackRebindingHider,
            configurationController,
            logcatLogBuffer("ShadeDisplaysInteractor"),
        )
    }