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

Commit 9aa8e567 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Pod] Define interface for TableLogBufferFactory." into main

parents 148fd323 41abc210
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.systemui.log.table
package com.android.systemui.log.table.impl

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
@@ -29,11 +29,11 @@ import org.mockito.kotlin.mock

@SmallTest
@RunWith(AndroidJUnit4::class)
class TableLogBufferFactoryTest : SysuiTestCase() {
class TableLogBufferFactoryImplTest : SysuiTestCase() {
    private val dumpManager: DumpManager = mock()
    private val systemClock = FakeSystemClock()
    private val underTest =
        TableLogBufferFactory(dumpManager, systemClock, LogcatEchoTrackerAlways())
        TableLogBufferFactoryImpl(dumpManager, systemClock, LogcatEchoTrackerAlways())

    @Test
    fun create_alwaysCreatesNewInstance() {
+45 −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.log.table

/** Factory for creating [TableLogBuffer] instances. */
public interface TableLogBufferFactory {
    /**
     * Creates a new [TableLogBuffer]. This method should only be called from static contexts, where
     * it is guaranteed only to be created one time. See [getOrCreate] for a cache-aware method of
     * obtaining a buffer.
     *
     * TODO(b/307607958): Remove this method and always use [getOrCreate] instead.
     *
     * @param name a unique table name
     * @param maxSize the buffer max size. See [com.android.systemui.log.adjustMaxSize]
     * @return a new [TableLogBuffer] registered with [com.android.systemui.dump.DumpManager]
     */
    public fun create(name: String, maxSize: Int): TableLogBuffer

    /**
     * Log buffers are retained indefinitely by [com.android.systemui.dump.DumpManager], so that
     * they can be represented in bugreports. Because of this, many of them are created statically
     * in the Dagger graph.
     *
     * In the case where you have to create a logbuffer with a name only known at runtime, this
     * method can be used to lazily create a table log buffer which is then cached for reuse.
     *
     * @return a [TableLogBuffer] suitable for reuse
     */
    public fun getOrCreate(name: String, maxSize: Int): TableLogBuffer
}
+2 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ import com.android.systemui.keyguard.ui.composable.LockscreenContent;
import com.android.systemui.log.dagger.LogModule;
import com.android.systemui.log.dagger.MonitorLog;
import com.android.systemui.log.table.TableLogBuffer;
import com.android.systemui.log.table.impl.TableLogBufferModule;
import com.android.systemui.lowlight.dagger.LowLightModule;
import com.android.systemui.lowlightclock.dagger.LowLightClockModule;
import com.android.systemui.mediaprojection.MediaProjectionModule;
@@ -294,6 +295,7 @@ import javax.inject.Named;
        SysUIConcurrencyModule.class,
        SysUICoroutinesModule.class,
        CommonSystemUIUnfoldModule.class,
        TableLogBufferModule.class,
        TelephonyRepositoryModule.class,
        TemporaryDisplayModule.class,
        ShadeDisplayAwareModule.class,
+9 −24
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 * 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.
@@ -14,52 +14,37 @@
 * limitations under the License.
 */

package com.android.systemui.log.table
package com.android.systemui.log.table.impl

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dump.DumpManager
import com.android.systemui.log.LogBufferHelper.Companion.adjustMaxSize
import com.android.systemui.log.LogcatEchoTracker
import com.android.systemui.log.table.TableLogBuffer
import com.android.systemui.log.table.TableLogBufferFactory
import com.android.systemui.log.table.TableLogBufferImpl
import com.android.systemui.util.time.SystemClock
import java.util.concurrent.ConcurrentHashMap
import javax.inject.Inject

@SysUISingleton
class TableLogBufferFactory
class TableLogBufferFactoryImpl
@Inject
constructor(
    private val dumpManager: DumpManager,
    private val systemClock: SystemClock,
    private val logcatEchoTracker: LogcatEchoTracker,
) {
) : TableLogBufferFactory {
    private val existingBuffers = ConcurrentHashMap<String, TableLogBuffer>()

    /**
     * Creates a new [TableLogBuffer]. This method should only be called from static contexts, where
     * it is guaranteed only to be created one time. See [getOrCreate] for a cache-aware method of
     * obtaining a buffer.
     *
     * @param name a unique table name
     * @param maxSize the buffer max size. See [adjustMaxSize]
     * @return a new [TableLogBuffer] registered with [DumpManager]
     */
    fun create(name: String, maxSize: Int): TableLogBuffer {
    override fun create(name: String, maxSize: Int): TableLogBuffer {
        val tableBuffer =
            TableLogBufferImpl(adjustMaxSize(maxSize), name, systemClock, logcatEchoTracker)
        dumpManager.registerTableLogBuffer(name, tableBuffer)
        return tableBuffer
    }

    /**
     * Log buffers are retained indefinitely by [DumpManager], so that they can be represented in
     * bugreports. Because of this, many of them are created statically in the Dagger graph.
     *
     * In the case where you have to create a logbuffer with a name only known at runtime, this
     * method can be used to lazily create a table log buffer which is then cached for reuse.
     *
     * @return a [TableLogBuffer] suitable for reuse
     */
    fun getOrCreate(name: String, maxSize: Int): TableLogBuffer =
    override fun getOrCreate(name: String, maxSize: Int): TableLogBuffer =
        synchronized(existingBuffers) {
            existingBuffers.getOrElse(name) {
                val buffer = create(name, maxSize)
+27 −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.log.table.impl

import com.android.systemui.log.table.TableLogBufferFactory
import dagger.Binds
import dagger.Module

@Module
abstract class TableLogBufferModule {
    @Binds
    abstract fun tableLogBufferFactory(impl: TableLogBufferFactoryImpl): TableLogBufferFactory
}
Loading