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

Commit 1b57a6f2 authored by Anton Potapov's avatar Anton Potapov
Browse files

Fix using separated buffers for each tile.

The problem was that each LogBuffer should have a unique name. Now the
buffers have a name associated with a tile spec they're logging.

Test: atest QSTileLoggerTest
Test: manual. Create multiple new tiles
Bug: 301055700
Change-Id: Ifff3b54091ded44f22c8630005344a74ef277b0f
parent ad48a441
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -190,17 +190,6 @@ public class LogModule {
        }
    }

    /**
     * Provides a logging buffer for all logs related to Quick Settings tiles. This LogBuffer is
     * unique for each tile.
     * go/qs-tile-refactor
     */
    @Provides
    @QSTilesDefaultLog
    public static LogBuffer provideQuickSettingsTilesLogBuffer(LogBufferFactory factory) {
        return factory.create("QSTileLog", 25 /* maxSize */, false /* systrace */);
    }

    @Provides
    @QSTilesLogBuffers
    public static Map<TileSpec, LogBuffer> provideQuickSettingsTilesLogBufferCache() {
+0 −28
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.log.dagger

import javax.inject.Qualifier

/**
 * A default [com.android.systemui.log.LogBuffer] for QS tiles messages. It's used exclusively in
 * [com.android.systemui.qs.tiles.base.logging.QSTileLogger]. If you need to increase it for you
 * tile, add one to the map provided by the [QSTilesLogBuffers]
 */
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
annotation class QSTilesDefaultLog
+10 −4
Original line number Diff line number Diff line
@@ -19,8 +19,8 @@ package com.android.systemui.qs.tiles.base.logging
import androidx.annotation.GuardedBy
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogBufferFactory
import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.dagger.QSTilesDefaultLog
import com.android.systemui.log.dagger.QSTilesLogBuffers
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.qs.pipeline.shared.TileSpec
@@ -29,14 +29,13 @@ import com.android.systemui.qs.tiles.viewmodel.QSTileState
import com.android.systemui.qs.tiles.viewmodel.QSTileUserAction
import com.android.systemui.statusbar.StatusBarState
import javax.inject.Inject
import javax.inject.Provider

@SysUISingleton
class QSTileLogger
@Inject
constructor(
    @QSTilesLogBuffers logBuffers: Map<TileSpec, LogBuffer>,
    @QSTilesDefaultLog private val defaultLogBufferProvider: Provider<LogBuffer>,
    private val factory: LogBufferFactory,
    private val mStatusBarStateController: StatusBarStateController,
) {
    @GuardedBy("logBufferCache") private val logBufferCache = logBuffers.toMutableMap()
@@ -154,7 +153,13 @@ constructor(

    private fun TileSpec.getLogBuffer(): LogBuffer =
        synchronized(logBufferCache) {
            logBufferCache.getOrPut(this) { defaultLogBufferProvider.get() }
            logBufferCache.getOrPut(this) {
                factory.create(
                    "QSTileLog_${this.getLogTag()}",
                    BUFFER_MAX_SIZE /* maxSize */,
                    false /* systrace */
                )
            }
        }

    private fun StateUpdateTrigger.toLogString(): String =
@@ -185,5 +190,6 @@ constructor(
    private companion object {
        const val TAG_FORMAT_PREFIX = "QSLog"
        const val DATA_MAX_LENGTH = 50
        const val BUFFER_MAX_SIZE = 25
    }
}
+6 −1
Original line number Diff line number Diff line
@@ -23,11 +23,14 @@ import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.dump.LogcatEchoTrackerAlways
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogBufferFactory
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.qs.tiles.base.interactor.StateUpdateTrigger
import com.android.systemui.qs.tiles.viewmodel.QSTileState
import com.android.systemui.qs.tiles.viewmodel.QSTileUserAction
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import java.io.PrintWriter
import java.io.StringWriter
@@ -42,6 +45,7 @@ import org.mockito.MockitoAnnotations
class QSTileLoggerTest : SysuiTestCase() {

    @Mock private lateinit var statusBarController: StatusBarStateController
    @Mock private lateinit var logBufferFactory: LogBufferFactory

    private val chattyLogBuffer = LogBuffer("TestChatty", 5, LogcatEchoTrackerAlways())
    private val logBuffer = LogBuffer("Test", 1, LogcatEchoTrackerAlways())
@@ -51,10 +55,11 @@ class QSTileLoggerTest : SysuiTestCase() {
    @Before
    fun setup() {
        MockitoAnnotations.initMocks(this)
        whenever(logBufferFactory.create(any(), any(), any())).thenReturn(logBuffer)
        underTest =
            QSTileLogger(
                mapOf(TileSpec.create("chatty_tile") to chattyLogBuffer),
                { logBuffer },
                logBufferFactory,
                statusBarController
            )
    }