From 1666e7cdf879937f21a342dbbca4645be224a99a Mon Sep 17 00:00:00 2001 From: Beverly Date: Mon, 17 Oct 2022 13:29:50 +0000 Subject: Move LogBuffer to sysui/plugins Consequently, RingBuffer is also moved to SysUI/plugins Test: builds, logs still work (see dumpsys) Test: atest SystemUITests Bug: 253490717 Change-Id: I91e3ef3ebdc6a2d929b2c1ae8ef158aeffa4c733 Merged-In: I91e3ef3ebdc6a2d929b2c1ae8ef158aeffa4c733 --- packages/SystemUI/plugin/Android.bp | 1 + .../com/android/systemui/plugins/log/LogBuffer.kt | 298 +++++++++++++++++++++ .../com/android/systemui/plugins/log/LogLevel.kt | 29 ++ .../com/android/systemui/plugins/log/LogMessage.kt | 95 +++++++ .../android/systemui/plugins/log/LogMessageImpl.kt | 92 +++++++ .../systemui/plugins/log/LogcatEchoTracker.kt | 29 ++ .../systemui/plugins/log/LogcatEchoTrackerDebug.kt | 128 +++++++++ .../systemui/plugins/log/LogcatEchoTrackerProd.kt | 30 +++ .../android/systemui/plugins/util/RingBuffer.kt | 118 ++++++++ .../SystemUI/plugin/tests/log/LogBufferTest.kt | 138 ++++++++++ .../logging/BiometricMessageDeferralLogger.kt | 4 +- .../com/android/keyguard/logging/KeyguardLogger.kt | 16 +- .../logging/KeyguardUpdateMonitorLogger.kt | 14 +- .../android/systemui/bluetooth/BluetoothLogger.kt | 4 +- .../broadcast/logging/BroadcastDispatcherLogger.kt | 10 +- .../src/com/android/systemui/doze/DozeLogger.kt | 8 +- .../src/com/android/systemui/dump/DumpHandler.kt | 2 +- .../src/com/android/systemui/dump/DumpManager.kt | 2 +- .../android/systemui/dump/LogBufferEulogizer.kt | 2 +- .../src/com/android/systemui/log/LogBuffer.kt | 291 -------------------- .../com/android/systemui/log/LogBufferFactory.kt | 5 +- .../src/com/android/systemui/log/LogLevel.kt | 34 --- .../src/com/android/systemui/log/LogMessage.kt | 96 ------- .../src/com/android/systemui/log/LogMessageImpl.kt | 93 ------- .../com/android/systemui/log/LogcatEchoTracker.kt | 37 --- .../android/systemui/log/LogcatEchoTrackerDebug.kt | 134 --------- .../android/systemui/log/LogcatEchoTrackerProd.kt | 32 --- .../systemui/log/dagger/BiometricMessagesLog.java | 2 +- .../log/dagger/BroadcastDispatcherLog.java | 2 +- .../log/dagger/CollapsedSbFragmentLog.java | 2 +- .../com/android/systemui/log/dagger/DozeLog.java | 2 +- .../systemui/log/dagger/LSShadeTransitionLog.java | 2 +- .../com/android/systemui/log/dagger/LogModule.java | 8 +- .../systemui/log/dagger/MediaBrowserLog.java | 2 +- .../log/dagger/MediaCarouselControllerLog.java | 2 +- .../systemui/log/dagger/MediaMuteAwaitLog.java | 2 +- .../log/dagger/MediaTimeoutListenerLog.java | 2 +- .../log/dagger/MediaTttReceiverLogBuffer.java | 2 +- .../log/dagger/MediaTttSenderLogBuffer.java | 2 +- .../android/systemui/log/dagger/MediaViewLog.java | 2 +- .../systemui/log/dagger/NearbyMediaDevicesLog.java | 2 +- .../systemui/log/dagger/NotifInteractionLog.java | 2 +- .../log/dagger/NotificationHeadsUpLog.java | 2 +- .../log/dagger/NotificationInterruptLog.java | 2 +- .../systemui/log/dagger/NotificationLog.java | 2 +- .../systemui/log/dagger/NotificationRenderLog.java | 2 +- .../log/dagger/NotificationSectionLog.java | 2 +- .../android/systemui/log/dagger/PrivacyLog.java | 2 +- .../systemui/log/dagger/QSFragmentDisableLog.java | 2 +- .../src/com/android/systemui/log/dagger/QSLog.java | 2 +- .../com/android/systemui/log/dagger/ShadeLog.java | 2 +- .../log/dagger/StatusBarConnectivityLog.java | 2 +- .../log/dagger/StatusBarNetworkControllerLog.java | 2 +- .../systemui/log/dagger/SwipeStatusBarAwayLog.java | 2 +- .../com/android/systemui/log/dagger/ToastLog.java | 2 +- .../media/MediaCarouselControllerLogger.kt | 4 +- .../android/systemui/media/MediaTimeoutLogger.kt | 5 +- .../com/android/systemui/media/MediaViewLogger.kt | 4 +- .../systemui/media/ResumeMediaBrowserLogger.kt | 4 +- .../android/systemui/media/dagger/MediaModule.java | 2 +- .../media/muteawait/MediaMuteAwaitLogger.kt | 4 +- .../media/nearby/NearbyMediaDevicesLogger.kt | 4 +- .../media/taptotransfer/common/MediaTttLogger.kt | 4 +- .../systemui/privacy/logging/PrivacyLogger.kt | 6 +- .../systemui/qs/QSFragmentDisableFlagsLogger.kt | 4 +- .../com/android/systemui/qs/logging/QSLogger.kt | 10 +- .../android/systemui/shade/NPVCDownEventState.kt | 2 +- .../src/com/android/systemui/shade/ShadeLogger.kt | 6 +- .../systemui/statusbar/ActionClickLogger.kt | 4 +- .../connectivity/NetworkControllerImpl.java | 4 +- .../gesture/SwipeStatusBarAwayGestureLogger.kt | 4 +- .../notification/NotificationClickerLogger.kt | 4 +- .../collection/coalescer/GroupCoalescerLogger.kt | 4 +- .../coordinator/GutsCoordinatorLogger.kt | 4 +- .../coordinator/HeadsUpCoordinatorLogger.kt | 5 +- .../coordinator/PreparationCoordinatorLogger.kt | 4 +- .../coordinator/ShadeEventCoordinatorLogger.kt | 4 +- .../listbuilder/ShadeListBuilderLogger.kt | 8 +- .../notifcollection/NotifCollectionLogger.kt | 12 +- .../collection/render/NodeSpecBuilderLogger.kt | 4 +- .../collection/render/ShadeViewDifferLogger.kt | 4 +- .../interruption/HeadsUpViewBinderLogger.kt | 4 +- .../interruption/NotificationInterruptLogger.kt | 8 +- .../logging/NotificationRoundnessLogger.kt | 4 +- .../notification/row/NotifBindPipelineLogger.kt | 4 +- .../notification/row/RowContentBindStageLogger.kt | 4 +- .../stack/NotificationSectionsLogger.kt | 4 +- .../stack/NotificationStackScrollLogger.kt | 4 +- .../notification/stack/StackStateLogger.kt | 4 +- .../statusbar/phone/LSShadeTransitionLogger.kt | 4 +- .../StatusBarNotificationActivityStarterLogger.kt | 10 +- .../fragment/CollapsedStatusBarFragmentLogger.kt | 4 +- .../pipeline/shared/ConnectivityPipelineLogger.kt | 6 +- .../statusbar/policy/HeadsUpManagerLogger.kt | 6 +- .../temporarydisplay/TemporaryViewLogger.kt | 4 +- .../src/com/android/systemui/toast/ToastLogger.kt | 8 +- .../android/systemui/util/collection/RingBuffer.kt | 122 --------- .../com/android/systemui/dump/DumpHandlerTest.kt | 2 +- .../com/android/systemui/dump/LogBufferHelper.kt | 6 +- .../src/com/android/systemui/log/LogBufferTest.kt | 138 ---------- .../taptotransfer/common/MediaTttLoggerTest.kt | 4 +- .../qs/QSFragmentDisableFlagsLoggerTest.kt | 2 +- .../statusbar/LSShadeTransitionLoggerTest.kt | 2 +- .../connectivity/NetworkControllerBaseTest.java | 2 +- .../connectivity/NetworkControllerDataTest.java | 2 +- .../connectivity/NetworkControllerSignalTest.java | 2 +- .../CollapsedStatusBarFragmentLoggerTest.kt | 2 +- .../fragment/CollapsedStatusBarFragmentTest.java | 4 +- .../shared/ConnectivityPipelineLoggerTest.kt | 2 +- .../temporarydisplay/TemporaryViewLoggerTest.kt | 4 +- .../systemui/util/collection/RingBufferTest.kt | 131 --------- 111 files changed, 1142 insertions(+), 1289 deletions(-) create mode 100644 packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogBuffer.kt create mode 100644 packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogLevel.kt create mode 100644 packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogMessage.kt create mode 100644 packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogMessageImpl.kt create mode 100644 packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogcatEchoTracker.kt create mode 100644 packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogcatEchoTrackerDebug.kt create mode 100644 packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogcatEchoTrackerProd.kt create mode 100644 packages/SystemUI/plugin/src/com/android/systemui/plugins/util/RingBuffer.kt create mode 100644 packages/SystemUI/plugin/tests/log/LogBufferTest.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/log/LogBuffer.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/log/LogLevel.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/log/LogMessage.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/log/LogMessageImpl.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/log/LogcatEchoTracker.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/log/LogcatEchoTrackerDebug.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/log/LogcatEchoTrackerProd.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/util/collection/RingBuffer.kt delete mode 100644 packages/SystemUI/tests/src/com/android/systemui/log/LogBufferTest.kt delete mode 100644 packages/SystemUI/tests/src/com/android/systemui/util/collection/RingBufferTest.kt diff --git a/packages/SystemUI/plugin/Android.bp b/packages/SystemUI/plugin/Android.bp index cafaaf854eed..7709f210f22f 100644 --- a/packages/SystemUI/plugin/Android.bp +++ b/packages/SystemUI/plugin/Android.bp @@ -33,6 +33,7 @@ java_library { static_libs: [ "androidx.annotation_annotation", + "error_prone_annotations", "PluginCoreLib", "SystemUIAnimationLib", ], diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogBuffer.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogBuffer.kt new file mode 100644 index 000000000000..6436dcb5f613 --- /dev/null +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogBuffer.kt @@ -0,0 +1,298 @@ +/* + * Copyright (C) 2020 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.plugins.log + +import android.os.Trace +import android.util.Log +import com.android.systemui.plugins.util.RingBuffer +import com.google.errorprone.annotations.CompileTimeConstant +import java.io.PrintWriter +import java.util.concurrent.ArrayBlockingQueue +import java.util.concurrent.BlockingQueue +import kotlin.concurrent.thread +import kotlin.math.max + +/** + * A simple ring buffer of recyclable log messages + * + * The goal of this class is to enable logging that is both extremely chatty and extremely + * lightweight. If done properly, logging a message will not result in any heap allocations or + * string generation. Messages are only converted to strings if the log is actually dumped (usually + * as the result of taking a bug report). + * + * You can dump the entire buffer at any time by running: + * + * ``` + * $ adb shell dumpsys activity service com.android.systemui/.SystemUIService + * ``` + * + * ...where `bufferName` is the (case-sensitive) [name] passed to the constructor. + * + * By default, only messages of WARN level or higher are echoed to logcat, but this can be adjusted + * locally (usually for debugging purposes). + * + * To enable logcat echoing for an entire buffer: + * + * ``` + * $ adb shell settings put global systemui/buffer/ + * ``` + * + * To enable logcat echoing for a specific tag: + * + * ``` + * $ adb shell settings put global systemui/tag/ + * ``` + * + * In either case, `level` can be any of `verbose`, `debug`, `info`, `warn`, `error`, `assert`, or + * the first letter of any of the previous. + * + * In SystemUI, buffers are provided by LogModule. Instances should be created using a SysUI + * LogBufferFactory. + * + * @param name The name of this buffer, printed when the buffer is dumped and in some other + * situations. + * @param maxSize The maximum number of messages to keep in memory at any one time. Buffers start + * out empty and grow up to [maxSize] as new messages are logged. Once the buffer's size reaches the + * maximum, it behaves like a ring buffer. + */ +class LogBuffer +@JvmOverloads +constructor( + private val name: String, + private val maxSize: Int, + private val logcatEchoTracker: LogcatEchoTracker, + private val systrace: Boolean = true, +) { + private val buffer = RingBuffer(maxSize) { LogMessageImpl.create() } + + private val echoMessageQueue: BlockingQueue? = + if (logcatEchoTracker.logInBackgroundThread) ArrayBlockingQueue(10) else null + + init { + if (logcatEchoTracker.logInBackgroundThread && echoMessageQueue != null) { + thread(start = true, name = "LogBuffer-$name", priority = Thread.NORM_PRIORITY) { + try { + while (true) { + echoToDesiredEndpoints(echoMessageQueue.take()) + } + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + } + } + } + } + + var frozen = false + private set + + private val mutable + get() = !frozen && maxSize > 0 + + /** + * Logs a message to the log buffer + * + * May also log the message to logcat if echoing is enabled for this buffer or tag. + * + * The actual string of the log message is not constructed until it is needed. To accomplish + * this, logging a message is a two-step process. First, a fresh instance of [LogMessage] is + * obtained and is passed to the [messageInitializer]. The initializer stores any relevant data + * on the message's fields. The message is then inserted into the buffer where it waits until it + * is either pushed out by newer messages or it needs to printed. If and when this latter moment + * occurs, the [messagePrinter] function is called on the message. It reads whatever data the + * initializer stored and converts it to a human-readable log message. + * + * @param tag A string of at most 23 characters, used for grouping logs into categories or + * subjects. If this message is echoed to logcat, this will be the tag that is used. + * @param level Which level to log the message at, both to the buffer and to logcat if it's + * echoed. In general, a module should split most of its logs into either INFO or DEBUG level. + * INFO level should be reserved for information that other parts of the system might care + * about, leaving the specifics of code's day-to-day operations to DEBUG. + * @param messageInitializer A function that will be called immediately to store relevant data + * on the log message. The value of `this` will be the LogMessage to be initialized. + * @param messagePrinter A function that will be called if and when the message needs to be + * dumped to logcat or a bug report. It should read the data stored by the initializer and + * convert it to a human-readable string. The value of `this` will be the LogMessage to be + * printed. **IMPORTANT:** The printer should ONLY ever reference fields on the LogMessage and + * NEVER any variables in its enclosing scope. Otherwise, the runtime will need to allocate a + * new instance of the printer for each call, thwarting our attempts at avoiding any sort of + * allocation. + * @param exception Provide any exception that need to be logged. This is saved as + * [LogMessage.exception] + */ + @JvmOverloads + inline fun log( + tag: String, + level: LogLevel, + messageInitializer: MessageInitializer, + noinline messagePrinter: MessagePrinter, + exception: Throwable? = null, + ) { + val message = obtain(tag, level, messagePrinter, exception) + messageInitializer(message) + commit(message) + } + + /** + * Logs a compile-time string constant [message] to the log buffer. Use sparingly. + * + * May also log the message to logcat if echoing is enabled for this buffer or tag. This is for + * simpler use-cases where [message] is a compile time string constant. For use-cases where the + * log message is built during runtime, use the [LogBuffer.log] overloaded method that takes in + * an initializer and a message printer. + * + * Log buffers are limited by the number of entries, so logging more frequently will limit the + * time window that the LogBuffer covers in a bug report. Richer logs, on the other hand, make a + * bug report more actionable, so using the [log] with a messagePrinter to add more detail to + * every log may do more to improve overall logging than adding more logs with this method. + */ + fun log(tag: String, level: LogLevel, @CompileTimeConstant message: String) = + log(tag, level, { str1 = message }, { str1!! }) + + /** + * You should call [log] instead of this method. + * + * Obtains the next [LogMessage] from the ring buffer. If the buffer is not yet at max size, + * grows the buffer by one. + * + * After calling [obtain], the message will now be at the end of the buffer. The caller must + * store any relevant data on the message and then call [commit]. + */ + @Synchronized + fun obtain( + tag: String, + level: LogLevel, + messagePrinter: MessagePrinter, + exception: Throwable? = null, + ): LogMessage { + if (!mutable) { + return FROZEN_MESSAGE + } + val message = buffer.advance() + message.reset(tag, level, System.currentTimeMillis(), messagePrinter, exception) + return message + } + + /** + * You should call [log] instead of this method. + * + * After acquiring a message via [obtain], call this method to signal to the buffer that you + * have finished filling in its data fields. The message will be echoed to logcat if necessary. + */ + @Synchronized + fun commit(message: LogMessage) { + if (!mutable) { + return + } + // Log in the background thread only if echoMessageQueue exists and has capacity (checking + // capacity avoids the possibility of blocking this thread) + if (echoMessageQueue != null && echoMessageQueue.remainingCapacity() > 0) { + try { + echoMessageQueue.put(message) + } catch (e: InterruptedException) { + // the background thread has been shut down, so just log on this one + echoToDesiredEndpoints(message) + } + } else { + echoToDesiredEndpoints(message) + } + } + + /** Sends message to echo after determining whether to use Logcat and/or systrace. */ + private fun echoToDesiredEndpoints(message: LogMessage) { + val includeInLogcat = + logcatEchoTracker.isBufferLoggable(name, message.level) || + logcatEchoTracker.isTagLoggable(message.tag, message.level) + echo(message, toLogcat = includeInLogcat, toSystrace = systrace) + } + + /** Converts the entire buffer to a newline-delimited string */ + @Synchronized + fun dump(pw: PrintWriter, tailLength: Int) { + val iterationStart = + if (tailLength <= 0) { + 0 + } else { + max(0, buffer.size - tailLength) + } + + for (i in iterationStart until buffer.size) { + buffer[i].dump(pw) + } + } + + /** + * "Freezes" the contents of the buffer, making it immutable until [unfreeze] is called. Calls + * to [log], [obtain], and [commit] will not affect the buffer and will return dummy values if + * necessary. + */ + @Synchronized + fun freeze() { + if (!frozen) { + log(TAG, LogLevel.DEBUG, { str1 = name }, { "$str1 frozen" }) + frozen = true + } + } + + /** Undoes the effects of calling [freeze]. */ + @Synchronized + fun unfreeze() { + if (frozen) { + log(TAG, LogLevel.DEBUG, { str1 = name }, { "$str1 unfrozen" }) + frozen = false + } + } + + private fun echo(message: LogMessage, toLogcat: Boolean, toSystrace: Boolean) { + if (toLogcat || toSystrace) { + val strMessage = message.messagePrinter(message) + if (toSystrace) { + echoToSystrace(message, strMessage) + } + if (toLogcat) { + echoToLogcat(message, strMessage) + } + } + } + + private fun echoToSystrace(message: LogMessage, strMessage: String) { + Trace.instantForTrack( + Trace.TRACE_TAG_APP, + "UI Events", + "$name - ${message.level.shortString} ${message.tag}: $strMessage" + ) + } + + private fun echoToLogcat(message: LogMessage, strMessage: String) { + when (message.level) { + LogLevel.VERBOSE -> Log.v(message.tag, strMessage, message.exception) + LogLevel.DEBUG -> Log.d(message.tag, strMessage, message.exception) + LogLevel.INFO -> Log.i(message.tag, strMessage, message.exception) + LogLevel.WARNING -> Log.w(message.tag, strMessage, message.exception) + LogLevel.ERROR -> Log.e(message.tag, strMessage, message.exception) + LogLevel.WTF -> Log.wtf(message.tag, strMessage, message.exception) + } + } +} + +/** + * A function that will be called immediately to store relevant data on the log message. The value + * of `this` will be the LogMessage to be initialized. + */ +typealias MessageInitializer = LogMessage.() -> Unit + +private const val TAG = "LogBuffer" +private val FROZEN_MESSAGE = LogMessageImpl.create() diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogLevel.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogLevel.kt new file mode 100644 index 000000000000..b036cf0be1d6 --- /dev/null +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogLevel.kt @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2020 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.plugins.log + +import android.util.Log + +/** Enum version of @Log.Level */ +enum class LogLevel(@Log.Level val nativeLevel: Int, val shortString: String) { + VERBOSE(Log.VERBOSE, "V"), + DEBUG(Log.DEBUG, "D"), + INFO(Log.INFO, "I"), + WARNING(Log.WARN, "W"), + ERROR(Log.ERROR, "E"), + WTF(Log.ASSERT, "WTF") +} diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogMessage.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogMessage.kt new file mode 100644 index 000000000000..9468681289bf --- /dev/null +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogMessage.kt @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2020 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.plugins.log + +import java.io.PrintWriter +import java.text.SimpleDateFormat +import java.util.Locale + +/** + * Generic data class for storing messages logged to a [LogBuffer] + * + * Each LogMessage has a few standard fields ([level], [tag], and [timestamp]). The rest are generic + * data slots that may or may not be used, depending on the nature of the specific message being + * logged. + * + * When a message is logged, the code doing the logging stores data in one or more of the generic + * fields ([str1], [int1], etc). When it comes time to dump the message to logcat/bugreport/etc, the + * [messagePrinter] function reads the data stored in the generic fields and converts that to a + * human- readable string. Thus, for every log type there must be a specialized initializer function + * that stores data specific to that log type and a specialized printer function that prints that + * data. + * + * See [LogBuffer.log] for more information. + */ +interface LogMessage { + val level: LogLevel + val tag: String + val timestamp: Long + val messagePrinter: MessagePrinter + val exception: Throwable? + + var str1: String? + var str2: String? + var str3: String? + var int1: Int + var int2: Int + var long1: Long + var long2: Long + var double1: Double + var bool1: Boolean + var bool2: Boolean + var bool3: Boolean + var bool4: Boolean + + /** Function that dumps the [LogMessage] to the provided [writer]. */ + fun dump(writer: PrintWriter) { + val formattedTimestamp = DATE_FORMAT.format(timestamp) + val shortLevel = level.shortString + val messageToPrint = messagePrinter(this) + printLikeLogcat(writer, formattedTimestamp, shortLevel, tag, messageToPrint) + exception?.printStackTrace(writer) + } +} + +/** + * A function that will be called if and when the message needs to be dumped to logcat or a bug + * report. It should read the data stored by the initializer and convert it to a human-readable + * string. The value of `this` will be the LogMessage to be printed. **IMPORTANT:** The printer + * should ONLY ever reference fields on the LogMessage and NEVER any variables in its enclosing + * scope. Otherwise, the runtime will need to allocate a new instance of the printer for each call, + * thwarting our attempts at avoiding any sort of allocation. + */ +typealias MessagePrinter = LogMessage.() -> String + +private fun printLikeLogcat( + pw: PrintWriter, + formattedTimestamp: String, + shortLogLevel: String, + tag: String, + message: String +) { + pw.print(formattedTimestamp) + pw.print(" ") + pw.print(shortLogLevel) + pw.print(" ") + pw.print(tag) + pw.print(": ") + pw.println(message) +} + +private val DATE_FORMAT = SimpleDateFormat("MM-dd HH:mm:ss.SSS", Locale.US) diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogMessageImpl.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogMessageImpl.kt new file mode 100644 index 000000000000..f2a6a91adcdf --- /dev/null +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogMessageImpl.kt @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2020 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.plugins.log + +/** Recyclable implementation of [LogMessage]. */ +data class LogMessageImpl( + override var level: LogLevel, + override var tag: String, + override var timestamp: Long, + override var messagePrinter: MessagePrinter, + override var exception: Throwable?, + override var str1: String?, + override var str2: String?, + override var str3: String?, + override var int1: Int, + override var int2: Int, + override var long1: Long, + override var long2: Long, + override var double1: Double, + override var bool1: Boolean, + override var bool2: Boolean, + override var bool3: Boolean, + override var bool4: Boolean, +) : LogMessage { + + fun reset( + tag: String, + level: LogLevel, + timestamp: Long, + renderer: MessagePrinter, + exception: Throwable? = null, + ) { + this.level = level + this.tag = tag + this.timestamp = timestamp + this.messagePrinter = renderer + this.exception = exception + str1 = null + str2 = null + str3 = null + int1 = 0 + int2 = 0 + long1 = 0 + long2 = 0 + double1 = 0.0 + bool1 = false + bool2 = false + bool3 = false + bool4 = false + } + + companion object Factory { + fun create(): LogMessageImpl { + return LogMessageImpl( + LogLevel.DEBUG, + DEFAULT_TAG, + 0, + DEFAULT_PRINTER, + null, + null, + null, + null, + 0, + 0, + 0, + 0, + 0.0, + false, + false, + false, + false + ) + } + } +} + +private const val DEFAULT_TAG = "UnknownTag" +private val DEFAULT_PRINTER: MessagePrinter = { "Unknown message: $this" } diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogcatEchoTracker.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogcatEchoTracker.kt new file mode 100644 index 000000000000..cfe894f276a0 --- /dev/null +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogcatEchoTracker.kt @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2020 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.plugins.log + +/** Keeps track of which [LogBuffer] messages should also appear in logcat. */ +interface LogcatEchoTracker { + /** Whether [bufferName] should echo messages of [level] or higher to logcat. */ + fun isBufferLoggable(bufferName: String, level: LogLevel): Boolean + + /** Whether [tagName] should echo messages of [level] or higher to logcat. */ + fun isTagLoggable(tagName: String, level: LogLevel): Boolean + + /** Whether to log messages in a background thread. */ + val logInBackgroundThread: Boolean +} diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogcatEchoTrackerDebug.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogcatEchoTrackerDebug.kt new file mode 100644 index 000000000000..d3fabaccb6d3 --- /dev/null +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogcatEchoTrackerDebug.kt @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2020 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.plugins.log + +import android.content.ContentResolver +import android.database.ContentObserver +import android.net.Uri +import android.os.Handler +import android.os.Looper +import android.provider.Settings + +/** + * Version of [LogcatEchoTracker] for debuggable builds + * + * The log level of individual buffers or tags can be controlled via global settings: + * + * ``` + * # Echo any message to of or higher + * $ adb shell settings put global systemui/buffer/ + * + * # Echo any message of and of or higher + * $ adb shell settings put global systemui/tag/ + * ``` + */ +class LogcatEchoTrackerDebug private constructor(private val contentResolver: ContentResolver) : + LogcatEchoTracker { + private val cachedBufferLevels: MutableMap = mutableMapOf() + private val cachedTagLevels: MutableMap = mutableMapOf() + override val logInBackgroundThread = true + + companion object Factory { + @JvmStatic + fun create(contentResolver: ContentResolver, mainLooper: Looper): LogcatEchoTrackerDebug { + val tracker = LogcatEchoTrackerDebug(contentResolver) + tracker.attach(mainLooper) + return tracker + } + } + + private fun attach(mainLooper: Looper) { + contentResolver.registerContentObserver( + Settings.Global.getUriFor(BUFFER_PATH), + true, + object : ContentObserver(Handler(mainLooper)) { + override fun onChange(selfChange: Boolean, uri: Uri?) { + super.onChange(selfChange, uri) + cachedBufferLevels.clear() + } + } + ) + + contentResolver.registerContentObserver( + Settings.Global.getUriFor(TAG_PATH), + true, + object : ContentObserver(Handler(mainLooper)) { + override fun onChange(selfChange: Boolean, uri: Uri?) { + super.onChange(selfChange, uri) + cachedTagLevels.clear() + } + } + ) + } + + /** Whether [bufferName] should echo messages of [level] or higher to logcat. */ + @Synchronized + override fun isBufferLoggable(bufferName: String, level: LogLevel): Boolean { + return level.ordinal >= getLogLevel(bufferName, BUFFER_PATH, cachedBufferLevels).ordinal + } + + /** Whether [tagName] should echo messages of [level] or higher to logcat. */ + @Synchronized + override fun isTagLoggable(tagName: String, level: LogLevel): Boolean { + return level >= getLogLevel(tagName, TAG_PATH, cachedTagLevels) + } + + private fun getLogLevel( + name: String, + path: String, + cache: MutableMap + ): LogLevel { + return cache[name] ?: readSetting("$path/$name").also { cache[name] = it } + } + + private fun readSetting(path: String): LogLevel { + return try { + parseProp(Settings.Global.getString(contentResolver, path)) + } catch (_: Settings.SettingNotFoundException) { + DEFAULT_LEVEL + } + } + + private fun parseProp(propValue: String?): LogLevel { + return when (propValue?.lowercase()) { + "verbose" -> LogLevel.VERBOSE + "v" -> LogLevel.VERBOSE + "debug" -> LogLevel.DEBUG + "d" -> LogLevel.DEBUG + "info" -> LogLevel.INFO + "i" -> LogLevel.INFO + "warning" -> LogLevel.WARNING + "warn" -> LogLevel.WARNING + "w" -> LogLevel.WARNING + "error" -> LogLevel.ERROR + "e" -> LogLevel.ERROR + "assert" -> LogLevel.WTF + "wtf" -> LogLevel.WTF + else -> DEFAULT_LEVEL + } + } +} + +private val DEFAULT_LEVEL = LogLevel.WARNING +private const val BUFFER_PATH = "systemui/buffer" +private const val TAG_PATH = "systemui/tag" diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogcatEchoTrackerProd.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogcatEchoTrackerProd.kt new file mode 100644 index 000000000000..3c8bda4a44e0 --- /dev/null +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogcatEchoTrackerProd.kt @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2020 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.plugins.log + +/** Production version of [LogcatEchoTracker] that isn't configurable. */ +class LogcatEchoTrackerProd : LogcatEchoTracker { + override val logInBackgroundThread = false + + override fun isBufferLoggable(bufferName: String, level: LogLevel): Boolean { + return level >= LogLevel.WARNING + } + + override fun isTagLoggable(tagName: String, level: LogLevel): Boolean { + return level >= LogLevel.WARNING + } +} diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/util/RingBuffer.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/util/RingBuffer.kt new file mode 100644 index 000000000000..68d78907f028 --- /dev/null +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/util/RingBuffer.kt @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2022 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.plugins.util + +import kotlin.math.max + +/** + * A simple ring buffer implementation + * + * Use [advance] to get the least recent item in the buffer (and then presumably fill it with + * appropriate data). This will cause it to become the most recent item. + * + * As the buffer is used, it will grow, allocating new instances of T using [factory] until it + * reaches [maxSize]. After this point, no new instances will be created. Instead, the "oldest" + * instances will be recycled from the back of the buffer and placed at the front. + * + * @param maxSize The maximum size the buffer can grow to before it begins functioning as a ring. + * @param factory A function that creates a fresh instance of T. Used by the buffer while it's + * growing to [maxSize]. + */ +class RingBuffer(private val maxSize: Int, private val factory: () -> T) : Iterable { + + private val buffer = MutableList(maxSize) { null } + + /** + * An abstract representation that points to the "end" of the buffer. Increments every time + * [advance] is called and never wraps. Use [indexOf] to calculate the associated index into the + * backing array. Always points to the "next" available slot in the buffer. Before the buffer + * has completely filled, the value pointed to will be null. Afterward, it will be the value at + * the "beginning" of the buffer. + * + * This value is unlikely to overflow. Assuming [advance] is called at rate of 100 calls/ms, + * omega will overflow after a little under three million years of continuous operation. + */ + private var omega: Long = 0 + + /** + * The number of items currently stored in the buffer. Calls to [advance] will cause this value + * to increase by one until it reaches [maxSize]. + */ + val size: Int + get() = if (omega < maxSize) omega.toInt() else maxSize + + /** + * Advances the buffer's position by one and returns the value that is now present at the "end" + * of the buffer. If the buffer is not yet full, uses [factory] to create a new item. Otherwise, + * reuses the value that was previously at the "beginning" of the buffer. + * + * IMPORTANT: The value is returned as-is, without being reset. It will retain any data that was + * previously stored on it. + */ + fun advance(): T { + val index = indexOf(omega) + omega += 1 + val entry = buffer[index] ?: factory().also { buffer[index] = it } + return entry + } + + /** + * Returns the value stored at [index], which can range from 0 (the "start", or oldest element + * of the buffer) to [size] + * - 1 (the "end", or newest element of the buffer). + */ + operator fun get(index: Int): T { + if (index < 0 || index >= size) { + throw IndexOutOfBoundsException("Index $index is out of bounds") + } + + // If omega is larger than the maxSize, then the buffer is full, and omega is equivalent + // to the "start" of the buffer. If omega is smaller than the maxSize, then the buffer is + // not yet full and our start should be 0. However, in modspace, maxSize and 0 are + // equivalent, so we can get away with using it as the start value instead. + val start = max(omega, maxSize.toLong()) + + return buffer[indexOf(start + index)]!! + } + + inline fun forEach(action: (T) -> Unit) { + for (i in 0 until size) { + action(get(i)) + } + } + + override fun iterator(): Iterator { + return object : Iterator { + private var position: Int = 0 + + override fun next(): T { + if (position >= size) { + throw NoSuchElementException() + } + return get(position).also { position += 1 } + } + + override fun hasNext(): Boolean { + return position < size + } + } + } + + private fun indexOf(position: Long): Int { + return (position % maxSize).toInt() + } +} diff --git a/packages/SystemUI/plugin/tests/log/LogBufferTest.kt b/packages/SystemUI/plugin/tests/log/LogBufferTest.kt new file mode 100644 index 000000000000..a39b856f0f49 --- /dev/null +++ b/packages/SystemUI/plugin/tests/log/LogBufferTest.kt @@ -0,0 +1,138 @@ +package com.android.systemui.log + +import androidx.test.filters.SmallTest +import com.android.systemui.SysuiTestCase +import com.android.systemui.plugins.log.LogBuffer +import com.google.common.truth.Truth.assertThat +import java.io.PrintWriter +import java.io.StringWriter +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.junit.MockitoJUnitRunner + +@SmallTest +@RunWith(MockitoJUnitRunner::class) +class LogBufferTest : SysuiTestCase() { + private lateinit var buffer: LogBuffer + + private lateinit var outputWriter: StringWriter + + @Mock private lateinit var logcatEchoTracker: LogcatEchoTracker + + @Before + fun setup() { + outputWriter = StringWriter() + buffer = createBuffer() + } + + private fun createBuffer(): LogBuffer { + return LogBuffer("TestBuffer", 1, logcatEchoTracker, false) + } + + @Test + fun log_shouldSaveLogToBuffer() { + buffer.log("Test", LogLevel.INFO, "Some test message") + + val dumpedString = dumpBuffer() + + assertThat(dumpedString).contains("Some test message") + } + + @Test + fun log_shouldRotateIfLogBufferIsFull() { + buffer.log("Test", LogLevel.INFO, "This should be rotated") + buffer.log("Test", LogLevel.INFO, "New test message") + + val dumpedString = dumpBuffer() + + assertThat(dumpedString).contains("New test message") + } + + @Test + fun dump_writesExceptionAndStacktrace() { + buffer = createBuffer() + val exception = createTestException("Exception message", "TestClass") + buffer.log("Tag", LogLevel.ERROR, { str1 = "Extra message" }, { str1!! }, exception) + + val dumpedString = dumpBuffer() + + assertThat(dumpedString).contains("Extra message") + assertThat(dumpedString).contains("java.lang.RuntimeException: Exception message") + assertThat(dumpedString).contains("at TestClass.TestMethod(TestClass.java:1)") + assertThat(dumpedString).contains("at TestClass.TestMethod(TestClass.java:2)") + } + + @Test + fun dump_writesCauseAndStacktrace() { + buffer = createBuffer() + val exception = + createTestException( + "Exception message", + "TestClass", + cause = createTestException("The real cause!", "TestClass") + ) + buffer.log("Tag", LogLevel.ERROR, { str1 = "Extra message" }, { str1!! }, exception) + + val dumpedString = dumpBuffer() + + assertThat(dumpedString).contains("Caused by: java.lang.RuntimeException: The real cause!") + assertThat(dumpedString).contains("at TestClass.TestMethod(TestClass.java:1)") + assertThat(dumpedString).contains("at TestClass.TestMethod(TestClass.java:2)") + } + + @Test + fun dump_writesSuppressedExceptionAndStacktrace() { + buffer = createBuffer() + val exception = RuntimeException("Root exception message") + exception.addSuppressed( + createTestException( + "First suppressed exception", + "FirstClass", + createTestException("Cause of suppressed exp", "ThirdClass") + ) + ) + exception.addSuppressed(createTestException("Second suppressed exception", "SecondClass")) + buffer.log("Tag", LogLevel.ERROR, { str1 = "Extra message" }, { str1!! }, exception) + + val dumpedStr = dumpBuffer() + + // first suppressed exception + assertThat(dumpedStr) + .contains("Suppressed: " + "java.lang.RuntimeException: First suppressed exception") + assertThat(dumpedStr).contains("at FirstClass.TestMethod(FirstClass.java:1)") + assertThat(dumpedStr).contains("at FirstClass.TestMethod(FirstClass.java:2)") + + assertThat(dumpedStr) + .contains("Caused by: java.lang.RuntimeException: Cause of suppressed exp") + assertThat(dumpedStr).contains("at ThirdClass.TestMethod(ThirdClass.java:1)") + assertThat(dumpedStr).contains("at ThirdClass.TestMethod(ThirdClass.java:2)") + + // second suppressed exception + assertThat(dumpedStr) + .contains("Suppressed: " + "java.lang.RuntimeException: Second suppressed exception") + assertThat(dumpedStr).contains("at SecondClass.TestMethod(SecondClass.java:1)") + assertThat(dumpedStr).contains("at SecondClass.TestMethod(SecondClass.java:2)") + } + + private fun createTestException( + message: String, + errorClass: String, + cause: Throwable? = null, + ): Exception { + val exception = RuntimeException(message, cause) + exception.stackTrace = + (1..5) + .map { lineNumber -> + StackTraceElement(errorClass, "TestMethod", "$errorClass.java", lineNumber) + } + .toTypedArray() + return exception + } + + private fun dumpBuffer(): String { + buffer.dump(PrintWriter(outputWriter), tailLength = 100) + return outputWriter.toString() + } +} diff --git a/packages/SystemUI/src/com/android/keyguard/logging/BiometricMessageDeferralLogger.kt b/packages/SystemUI/src/com/android/keyguard/logging/BiometricMessageDeferralLogger.kt index 2c2ab7b39161..6264ce7273f1 100644 --- a/packages/SystemUI/src/com/android/keyguard/logging/BiometricMessageDeferralLogger.kt +++ b/packages/SystemUI/src/com/android/keyguard/logging/BiometricMessageDeferralLogger.kt @@ -17,9 +17,9 @@ package com.android.keyguard.logging import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel.DEBUG import com.android.systemui.log.dagger.BiometricMessagesLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel.DEBUG import javax.inject.Inject /** Helper class for logging for [com.android.systemui.biometrics.FaceHelpMessageDeferral] */ diff --git a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardLogger.kt b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardLogger.kt index 50012a589b5a..46f3d4e5f6aa 100644 --- a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardLogger.kt +++ b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardLogger.kt @@ -16,15 +16,15 @@ package com.android.keyguard.logging -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel -import com.android.systemui.log.LogLevel.DEBUG -import com.android.systemui.log.LogLevel.ERROR -import com.android.systemui.log.LogLevel.VERBOSE -import com.android.systemui.log.LogLevel.WARNING -import com.android.systemui.log.MessageInitializer -import com.android.systemui.log.MessagePrinter import com.android.systemui.log.dagger.KeyguardLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel +import com.android.systemui.plugins.log.LogLevel.DEBUG +import com.android.systemui.plugins.log.LogLevel.ERROR +import com.android.systemui.plugins.log.LogLevel.VERBOSE +import com.android.systemui.plugins.log.LogLevel.WARNING +import com.android.systemui.plugins.log.MessageInitializer +import com.android.systemui.plugins.log.MessagePrinter import com.google.errorprone.annotations.CompileTimeConstant import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt index 2eee95738b7b..82b32cf616ec 100644 --- a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt +++ b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt @@ -22,13 +22,13 @@ import android.telephony.SubscriptionInfo import com.android.keyguard.ActiveUnlockConfig import com.android.keyguard.KeyguardListenModel import com.android.keyguard.KeyguardUpdateMonitorCallback -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel -import com.android.systemui.log.LogLevel.DEBUG -import com.android.systemui.log.LogLevel.ERROR -import com.android.systemui.log.LogLevel.INFO -import com.android.systemui.log.LogLevel.VERBOSE -import com.android.systemui.log.LogLevel.WARNING +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel +import com.android.systemui.plugins.log.LogLevel.DEBUG +import com.android.systemui.plugins.log.LogLevel.ERROR +import com.android.systemui.plugins.log.LogLevel.INFO +import com.android.systemui.plugins.log.LogLevel.VERBOSE +import com.android.systemui.plugins.log.LogLevel.WARNING import com.android.systemui.log.dagger.KeyguardUpdateMonitorLog import com.google.errorprone.annotations.CompileTimeConstant import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/bluetooth/BluetoothLogger.kt b/packages/SystemUI/src/com/android/systemui/bluetooth/BluetoothLogger.kt index 96af42bfda22..d99625a9fbf2 100644 --- a/packages/SystemUI/src/com/android/systemui/bluetooth/BluetoothLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/bluetooth/BluetoothLogger.kt @@ -17,9 +17,9 @@ package com.android.systemui.bluetooth import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.BluetoothLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import javax.inject.Inject /** Helper class for logging bluetooth events. */ diff --git a/packages/SystemUI/src/com/android/systemui/broadcast/logging/BroadcastDispatcherLogger.kt b/packages/SystemUI/src/com/android/systemui/broadcast/logging/BroadcastDispatcherLogger.kt index 5b3a982ab5e2..d27708fc04d7 100644 --- a/packages/SystemUI/src/com/android/systemui/broadcast/logging/BroadcastDispatcherLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/broadcast/logging/BroadcastDispatcherLogger.kt @@ -20,11 +20,11 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel -import com.android.systemui.log.LogLevel.DEBUG -import com.android.systemui.log.LogLevel.INFO -import com.android.systemui.log.LogMessage +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel +import com.android.systemui.plugins.log.LogLevel.DEBUG +import com.android.systemui.plugins.log.LogLevel.INFO +import com.android.systemui.plugins.log.LogMessage import com.android.systemui.log.dagger.BroadcastDispatcherLog import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeLogger.kt b/packages/SystemUI/src/com/android/systemui/doze/DozeLogger.kt index cc5766210406..0e1bfba8aadb 100644 --- a/packages/SystemUI/src/com/android/systemui/doze/DozeLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/doze/DozeLogger.kt @@ -19,10 +19,10 @@ package com.android.systemui.doze import android.view.Display import com.android.systemui.doze.DozeLog.Reason import com.android.systemui.doze.DozeLog.reasonToString -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel.DEBUG -import com.android.systemui.log.LogLevel.ERROR -import com.android.systemui.log.LogLevel.INFO +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel.DEBUG +import com.android.systemui.plugins.log.LogLevel.ERROR +import com.android.systemui.plugins.log.LogLevel.INFO import com.android.systemui.log.dagger.DozeLog import com.android.systemui.statusbar.policy.DevicePostureController import java.text.SimpleDateFormat diff --git a/packages/SystemUI/src/com/android/systemui/dump/DumpHandler.kt b/packages/SystemUI/src/com/android/systemui/dump/DumpHandler.kt index 08ef8f3d025f..5f3d8577348f 100644 --- a/packages/SystemUI/src/com/android/systemui/dump/DumpHandler.kt +++ b/packages/SystemUI/src/com/android/systemui/dump/DumpHandler.kt @@ -24,7 +24,7 @@ import com.android.systemui.R import com.android.systemui.dump.DumpHandler.Companion.PRIORITY_ARG_CRITICAL import com.android.systemui.dump.DumpHandler.Companion.PRIORITY_ARG_HIGH import com.android.systemui.dump.DumpHandler.Companion.PRIORITY_ARG_NORMAL -import com.android.systemui.log.LogBuffer +import com.android.systemui.plugins.log.LogBuffer import com.android.systemui.shared.system.UncaughtExceptionPreHandlerManager import java.io.PrintWriter import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/dump/DumpManager.kt b/packages/SystemUI/src/com/android/systemui/dump/DumpManager.kt index cca04da8f426..dbca65122fcb 100644 --- a/packages/SystemUI/src/com/android/systemui/dump/DumpManager.kt +++ b/packages/SystemUI/src/com/android/systemui/dump/DumpManager.kt @@ -18,7 +18,7 @@ package com.android.systemui.dump import android.util.ArrayMap import com.android.systemui.Dumpable -import com.android.systemui.log.LogBuffer +import com.android.systemui.plugins.log.LogBuffer import java.io.PrintWriter import javax.inject.Inject import javax.inject.Singleton diff --git a/packages/SystemUI/src/com/android/systemui/dump/LogBufferEulogizer.kt b/packages/SystemUI/src/com/android/systemui/dump/LogBufferEulogizer.kt index 0eab1afc4119..8299b13d305f 100644 --- a/packages/SystemUI/src/com/android/systemui/dump/LogBufferEulogizer.kt +++ b/packages/SystemUI/src/com/android/systemui/dump/LogBufferEulogizer.kt @@ -19,7 +19,7 @@ package com.android.systemui.dump import android.content.Context import android.util.Log import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.log.LogBuffer +import com.android.systemui.plugins.log.LogBuffer import com.android.systemui.util.io.Files import com.android.systemui.util.time.SystemClock import java.io.IOException diff --git a/packages/SystemUI/src/com/android/systemui/log/LogBuffer.kt b/packages/SystemUI/src/com/android/systemui/log/LogBuffer.kt deleted file mode 100644 index 6124e10144f2..000000000000 --- a/packages/SystemUI/src/com/android/systemui/log/LogBuffer.kt +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Copyright (C) 2020 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 - -import android.os.Trace -import android.util.Log -import com.android.systemui.log.dagger.LogModule -import com.android.systemui.util.collection.RingBuffer -import com.google.errorprone.annotations.CompileTimeConstant -import java.io.PrintWriter -import java.util.concurrent.ArrayBlockingQueue -import java.util.concurrent.BlockingQueue -import kotlin.concurrent.thread -import kotlin.math.max - -/** - * A simple ring buffer of recyclable log messages - * - * The goal of this class is to enable logging that is both extremely chatty and extremely - * lightweight. If done properly, logging a message will not result in any heap allocations or - * string generation. Messages are only converted to strings if the log is actually dumped (usually - * as the result of taking a bug report). - * - * You can dump the entire buffer at any time by running: - * - * ``` - * $ adb shell dumpsys activity service com.android.systemui/.SystemUIService - * ``` - * - * ...where `bufferName` is the (case-sensitive) [name] passed to the constructor. - * - * By default, only messages of WARN level or higher are echoed to logcat, but this can be adjusted - * locally (usually for debugging purposes). - * - * To enable logcat echoing for an entire buffer: - * - * ``` - * $ adb shell settings put global systemui/buffer/ - * ``` - * - * To enable logcat echoing for a specific tag: - * - * ``` - * $ adb shell settings put global systemui/tag/ - * ``` - * - * In either case, `level` can be any of `verbose`, `debug`, `info`, `warn`, `error`, `assert`, or - * the first letter of any of the previous. - * - * Buffers are provided by [LogModule]. Instances should be created using a [LogBufferFactory]. - * - * @param name The name of this buffer, printed when the buffer is dumped and in some other - * situations. - * @param maxSize The maximum number of messages to keep in memory at any one time. Buffers start - * out empty and grow up to [maxSize] as new messages are logged. Once the buffer's size reaches - * the maximum, it behaves like a ring buffer. - */ -class LogBuffer @JvmOverloads constructor( - private val name: String, - private val maxSize: Int, - private val logcatEchoTracker: LogcatEchoTracker, - private val systrace: Boolean = true, -) { - private val buffer = RingBuffer(maxSize) { LogMessageImpl.create() } - - private val echoMessageQueue: BlockingQueue? = - if (logcatEchoTracker.logInBackgroundThread) ArrayBlockingQueue(10) else null - - init { - if (logcatEchoTracker.logInBackgroundThread && echoMessageQueue != null) { - thread(start = true, name = "LogBuffer-$name", priority = Thread.NORM_PRIORITY) { - try { - while (true) { - echoToDesiredEndpoints(echoMessageQueue.take()) - } - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - } - } - } - } - - var frozen = false - private set - - private val mutable - get() = !frozen && maxSize > 0 - - /** - * Logs a message to the log buffer - * - * May also log the message to logcat if echoing is enabled for this buffer or tag. - * - * The actual string of the log message is not constructed until it is needed. To accomplish - * this, logging a message is a two-step process. First, a fresh instance of [LogMessage] is - * obtained and is passed to the [messageInitializer]. The initializer stores any relevant data - * on the message's fields. The message is then inserted into the buffer where it waits until it - * is either pushed out by newer messages or it needs to printed. If and when this latter moment - * occurs, the [messagePrinter] function is called on the message. It reads whatever data the - * initializer stored and converts it to a human-readable log message. - * - * @param tag A string of at most 23 characters, used for grouping logs into categories or - * subjects. If this message is echoed to logcat, this will be the tag that is used. - * @param level Which level to log the message at, both to the buffer and to logcat if it's - * echoed. In general, a module should split most of its logs into either INFO or DEBUG level. - * INFO level should be reserved for information that other parts of the system might care - * about, leaving the specifics of code's day-to-day operations to DEBUG. - * @param messageInitializer A function that will be called immediately to store relevant data - * on the log message. The value of `this` will be the LogMessage to be initialized. - * @param messagePrinter A function that will be called if and when the message needs to be - * dumped to logcat or a bug report. It should read the data stored by the initializer and - * convert it to a human-readable string. The value of `this` will be the LogMessage to be - * printed. **IMPORTANT:** The printer should ONLY ever reference fields on the LogMessage and - * NEVER any variables in its enclosing scope. Otherwise, the runtime will need to allocate a - * new instance of the printer for each call, thwarting our attempts at avoiding any sort of - * allocation. - * @param exception Provide any exception that need to be logged. This is saved as - * [LogMessage.exception] - */ - @JvmOverloads - inline fun log( - tag: String, - level: LogLevel, - messageInitializer: MessageInitializer, - noinline messagePrinter: MessagePrinter, - exception: Throwable? = null, - ) { - val message = obtain(tag, level, messagePrinter, exception) - messageInitializer(message) - commit(message) - } - - /** - * Logs a compile-time string constant [message] to the log buffer. Use sparingly. - * - * May also log the message to logcat if echoing is enabled for this buffer or tag. This is for - * simpler use-cases where [message] is a compile time string constant. For use-cases where the - * log message is built during runtime, use the [LogBuffer.log] overloaded method that takes in - * an initializer and a message printer. - * - * Log buffers are limited by the number of entries, so logging more frequently - * will limit the time window that the LogBuffer covers in a bug report. Richer logs, on the - * other hand, make a bug report more actionable, so using the [log] with a messagePrinter to - * add more detail to every log may do more to improve overall logging than adding more logs - * with this method. - */ - fun log(tag: String, level: LogLevel, @CompileTimeConstant message: String) = - log(tag, level, {str1 = message}, { str1!! }) - - /** - * You should call [log] instead of this method. - * - * Obtains the next [LogMessage] from the ring buffer. If the buffer is not yet at max size, - * grows the buffer by one. - * - * After calling [obtain], the message will now be at the end of the buffer. The caller must - * store any relevant data on the message and then call [commit]. - */ - @Synchronized - fun obtain( - tag: String, - level: LogLevel, - messagePrinter: MessagePrinter, - exception: Throwable? = null, - ): LogMessage { - if (!mutable) { - return FROZEN_MESSAGE - } - val message = buffer.advance() - message.reset(tag, level, System.currentTimeMillis(), messagePrinter, exception) - return message - } - - /** - * You should call [log] instead of this method. - * - * After acquiring a message via [obtain], call this method to signal to the buffer that you - * have finished filling in its data fields. The message will be echoed to logcat if - * necessary. - */ - @Synchronized - fun commit(message: LogMessage) { - if (!mutable) { - return - } - // Log in the background thread only if echoMessageQueue exists and has capacity (checking - // capacity avoids the possibility of blocking this thread) - if (echoMessageQueue != null && echoMessageQueue.remainingCapacity() > 0) { - try { - echoMessageQueue.put(message) - } catch (e: InterruptedException) { - // the background thread has been shut down, so just log on this one - echoToDesiredEndpoints(message) - } - } else { - echoToDesiredEndpoints(message) - } - } - - /** Sends message to echo after determining whether to use Logcat and/or systrace. */ - private fun echoToDesiredEndpoints(message: LogMessage) { - val includeInLogcat = logcatEchoTracker.isBufferLoggable(name, message.level) || - logcatEchoTracker.isTagLoggable(message.tag, message.level) - echo(message, toLogcat = includeInLogcat, toSystrace = systrace) - } - - /** Converts the entire buffer to a newline-delimited string */ - @Synchronized - fun dump(pw: PrintWriter, tailLength: Int) { - val iterationStart = if (tailLength <= 0) { 0 } else { max(0, buffer.size - tailLength) } - - for (i in iterationStart until buffer.size) { - buffer[i].dump(pw) - } - } - - /** - * "Freezes" the contents of the buffer, making it immutable until [unfreeze] is called. - * Calls to [log], [obtain], and [commit] will not affect the buffer and will return dummy - * values if necessary. - */ - @Synchronized - fun freeze() { - if (!frozen) { - log(TAG, LogLevel.DEBUG, { str1 = name }, { "$str1 frozen" }) - frozen = true - } - } - - /** - * Undoes the effects of calling [freeze]. - */ - @Synchronized - fun unfreeze() { - if (frozen) { - log(TAG, LogLevel.DEBUG, { str1 = name }, { "$str1 unfrozen" }) - frozen = false - } - } - - private fun echo(message: LogMessage, toLogcat: Boolean, toSystrace: Boolean) { - if (toLogcat || toSystrace) { - val strMessage = message.messagePrinter(message) - if (toSystrace) { - echoToSystrace(message, strMessage) - } - if (toLogcat) { - echoToLogcat(message, strMessage) - } - } - } - - private fun echoToSystrace(message: LogMessage, strMessage: String) { - Trace.instantForTrack(Trace.TRACE_TAG_APP, "UI Events", - "$name - ${message.level.shortString} ${message.tag}: $strMessage") - } - - private fun echoToLogcat(message: LogMessage, strMessage: String) { - when (message.level) { - LogLevel.VERBOSE -> Log.v(message.tag, strMessage, message.exception) - LogLevel.DEBUG -> Log.d(message.tag, strMessage, message.exception) - LogLevel.INFO -> Log.i(message.tag, strMessage, message.exception) - LogLevel.WARNING -> Log.w(message.tag, strMessage, message.exception) - LogLevel.ERROR -> Log.e(message.tag, strMessage, message.exception) - LogLevel.WTF -> Log.wtf(message.tag, strMessage, message.exception) - } - } -} - -/** - * A function that will be called immediately to store relevant data on the log message. The value - * of `this` will be the LogMessage to be initialized. - */ -typealias MessageInitializer = LogMessage.() -> Unit - -private const val TAG = "LogBuffer" -private val FROZEN_MESSAGE = LogMessageImpl.create() diff --git a/packages/SystemUI/src/com/android/systemui/log/LogBufferFactory.kt b/packages/SystemUI/src/com/android/systemui/log/LogBufferFactory.kt index 5651399cb891..f9e341c8629a 100644 --- a/packages/SystemUI/src/com/android/systemui/log/LogBufferFactory.kt +++ b/packages/SystemUI/src/com/android/systemui/log/LogBufferFactory.kt @@ -19,6 +19,9 @@ package com.android.systemui.log import android.app.ActivityManager import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dump.DumpManager +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogcatEchoTracker + import javax.inject.Inject @SysUISingleton @@ -26,7 +29,7 @@ class LogBufferFactory @Inject constructor( private val dumpManager: DumpManager, private val logcatEchoTracker: LogcatEchoTracker ) { - /* limit the size of maxPoolSize for low ram (Go) devices */ + /* limitiometricMessageDeferralLogger the size of maxPoolSize for low ram (Go) devices */ private fun adjustMaxSize(requestedMaxSize: Int): Int { return if (ActivityManager.isLowRamDeviceStatic()) { minOf(requestedMaxSize, 20) /* low ram max log size*/ diff --git a/packages/SystemUI/src/com/android/systemui/log/LogLevel.kt b/packages/SystemUI/src/com/android/systemui/log/LogLevel.kt deleted file mode 100644 index 53f231c9f9d2..000000000000 --- a/packages/SystemUI/src/com/android/systemui/log/LogLevel.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2020 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 - -import android.util.Log - -/** - * Enum version of @Log.Level - */ -enum class LogLevel( - @Log.Level val nativeLevel: Int, - val shortString: String -) { - VERBOSE(Log.VERBOSE, "V"), - DEBUG(Log.DEBUG, "D"), - INFO(Log.INFO, "I"), - WARNING(Log.WARN, "W"), - ERROR(Log.ERROR, "E"), - WTF(Log.ASSERT, "WTF") -} diff --git a/packages/SystemUI/src/com/android/systemui/log/LogMessage.kt b/packages/SystemUI/src/com/android/systemui/log/LogMessage.kt deleted file mode 100644 index dae2592e116c..000000000000 --- a/packages/SystemUI/src/com/android/systemui/log/LogMessage.kt +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2020 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 - -import java.io.PrintWriter -import java.text.SimpleDateFormat -import java.util.Locale - -/** - * Generic data class for storing messages logged to a [LogBuffer] - * - * Each LogMessage has a few standard fields ([level], [tag], and [timestamp]). The rest are generic - * data slots that may or may not be used, depending on the nature of the specific message being - * logged. - * - * When a message is logged, the code doing the logging stores data in one or more of the generic - * fields ([str1], [int1], etc). When it comes time to dump the message to logcat/bugreport/etc, the - * [messagePrinter] function reads the data stored in the generic fields and converts that to a human- - * readable string. Thus, for every log type there must be a specialized initializer function that - * stores data specific to that log type and a specialized printer function that prints that data. - * - * See [LogBuffer.log] for more information. - */ -interface LogMessage { - val level: LogLevel - val tag: String - val timestamp: Long - val messagePrinter: MessagePrinter - val exception: Throwable? - - var str1: String? - var str2: String? - var str3: String? - var int1: Int - var int2: Int - var long1: Long - var long2: Long - var double1: Double - var bool1: Boolean - var bool2: Boolean - var bool3: Boolean - var bool4: Boolean - - /** - * Function that dumps the [LogMessage] to the provided [writer]. - */ - fun dump(writer: PrintWriter) { - val formattedTimestamp = DATE_FORMAT.format(timestamp) - val shortLevel = level.shortString - val messageToPrint = messagePrinter(this) - printLikeLogcat(writer, formattedTimestamp, shortLevel, tag, messageToPrint) - exception?.printStackTrace(writer) - } -} - -/** - * A function that will be called if and when the message needs to be dumped to - * logcat or a bug report. It should read the data stored by the initializer and convert it to - * a human-readable string. The value of `this` will be the LogMessage to be printed. - * **IMPORTANT:** The printer should ONLY ever reference fields on the LogMessage and NEVER any - * variables in its enclosing scope. Otherwise, the runtime will need to allocate a new instance - * of the printer for each call, thwarting our attempts at avoiding any sort of allocation. - */ -typealias MessagePrinter = LogMessage.() -> String - -private fun printLikeLogcat( - pw: PrintWriter, - formattedTimestamp: String, - shortLogLevel: String, - tag: String, - message: String -) { - pw.print(formattedTimestamp) - pw.print(" ") - pw.print(shortLogLevel) - pw.print(" ") - pw.print(tag) - pw.print(": ") - pw.println(message) -} - -private val DATE_FORMAT = SimpleDateFormat("MM-dd HH:mm:ss.SSS", Locale.US) diff --git a/packages/SystemUI/src/com/android/systemui/log/LogMessageImpl.kt b/packages/SystemUI/src/com/android/systemui/log/LogMessageImpl.kt deleted file mode 100644 index 4dd6f652d1c7..000000000000 --- a/packages/SystemUI/src/com/android/systemui/log/LogMessageImpl.kt +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2020 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 - -/** - * Recyclable implementation of [LogMessage]. - */ -data class LogMessageImpl( - override var level: LogLevel, - override var tag: String, - override var timestamp: Long, - override var messagePrinter: MessagePrinter, - override var exception: Throwable?, - override var str1: String?, - override var str2: String?, - override var str3: String?, - override var int1: Int, - override var int2: Int, - override var long1: Long, - override var long2: Long, - override var double1: Double, - override var bool1: Boolean, - override var bool2: Boolean, - override var bool3: Boolean, - override var bool4: Boolean, -) : LogMessage { - - fun reset( - tag: String, - level: LogLevel, - timestamp: Long, - renderer: MessagePrinter, - exception: Throwable? = null, - ) { - this.level = level - this.tag = tag - this.timestamp = timestamp - this.messagePrinter = renderer - this.exception = exception - str1 = null - str2 = null - str3 = null - int1 = 0 - int2 = 0 - long1 = 0 - long2 = 0 - double1 = 0.0 - bool1 = false - bool2 = false - bool3 = false - bool4 = false - } - - companion object Factory { - fun create(): LogMessageImpl { - return LogMessageImpl( - LogLevel.DEBUG, - DEFAULT_TAG, - 0, - DEFAULT_PRINTER, - null, - null, - null, - null, - 0, - 0, - 0, - 0, - 0.0, - false, - false, - false, - false) - } - } -} - -private const val DEFAULT_TAG = "UnknownTag" -private val DEFAULT_PRINTER: MessagePrinter = { "Unknown message: $this" } diff --git a/packages/SystemUI/src/com/android/systemui/log/LogcatEchoTracker.kt b/packages/SystemUI/src/com/android/systemui/log/LogcatEchoTracker.kt deleted file mode 100644 index 8cda4236bc87..000000000000 --- a/packages/SystemUI/src/com/android/systemui/log/LogcatEchoTracker.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2020 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 - -/** - * Keeps track of which [LogBuffer] messages should also appear in logcat. - */ -interface LogcatEchoTracker { - /** - * Whether [bufferName] should echo messages of [level] or higher to logcat. - */ - fun isBufferLoggable(bufferName: String, level: LogLevel): Boolean - - /** - * Whether [tagName] should echo messages of [level] or higher to logcat. - */ - fun isTagLoggable(tagName: String, level: LogLevel): Boolean - - /** - * Whether to log messages in a background thread. - */ - val logInBackgroundThread: Boolean -} diff --git a/packages/SystemUI/src/com/android/systemui/log/LogcatEchoTrackerDebug.kt b/packages/SystemUI/src/com/android/systemui/log/LogcatEchoTrackerDebug.kt deleted file mode 100644 index 40b0cdc173d8..000000000000 --- a/packages/SystemUI/src/com/android/systemui/log/LogcatEchoTrackerDebug.kt +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2020 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 - -import android.content.ContentResolver -import android.database.ContentObserver -import android.net.Uri -import android.os.Handler -import android.os.Looper -import android.provider.Settings - -/** - * Version of [LogcatEchoTracker] for debuggable builds - * - * The log level of individual buffers or tags can be controlled via global settings: - * - * ``` - * # Echo any message to of or higher - * $ adb shell settings put global systemui/buffer/ - * - * # Echo any message of and of or higher - * $ adb shell settings put global systemui/tag/ - * ``` - */ -class LogcatEchoTrackerDebug private constructor( - private val contentResolver: ContentResolver -) : LogcatEchoTracker { - private val cachedBufferLevels: MutableMap = mutableMapOf() - private val cachedTagLevels: MutableMap = mutableMapOf() - override val logInBackgroundThread = true - - companion object Factory { - @JvmStatic - fun create( - contentResolver: ContentResolver, - mainLooper: Looper - ): LogcatEchoTrackerDebug { - val tracker = LogcatEchoTrackerDebug(contentResolver) - tracker.attach(mainLooper) - return tracker - } - } - - private fun attach(mainLooper: Looper) { - contentResolver.registerContentObserver( - Settings.Global.getUriFor(BUFFER_PATH), - true, - object : ContentObserver(Handler(mainLooper)) { - override fun onChange(selfChange: Boolean, uri: Uri?) { - super.onChange(selfChange, uri) - cachedBufferLevels.clear() - } - }) - - contentResolver.registerContentObserver( - Settings.Global.getUriFor(TAG_PATH), - true, - object : ContentObserver(Handler(mainLooper)) { - override fun onChange(selfChange: Boolean, uri: Uri?) { - super.onChange(selfChange, uri) - cachedTagLevels.clear() - } - }) - } - - /** - * Whether [bufferName] should echo messages of [level] or higher to logcat. - */ - @Synchronized - override fun isBufferLoggable(bufferName: String, level: LogLevel): Boolean { - return level.ordinal >= getLogLevel(bufferName, BUFFER_PATH, cachedBufferLevels).ordinal - } - - /** - * Whether [tagName] should echo messages of [level] or higher to logcat. - */ - @Synchronized - override fun isTagLoggable(tagName: String, level: LogLevel): Boolean { - return level >= getLogLevel(tagName, TAG_PATH, cachedTagLevels) - } - - private fun getLogLevel( - name: String, - path: String, - cache: MutableMap - ): LogLevel { - return cache[name] ?: readSetting("$path/$name").also { cache[name] = it } - } - - private fun readSetting(path: String): LogLevel { - return try { - parseProp(Settings.Global.getString(contentResolver, path)) - } catch (_: Settings.SettingNotFoundException) { - DEFAULT_LEVEL - } - } - - private fun parseProp(propValue: String?): LogLevel { - return when (propValue?.lowercase()) { - "verbose" -> LogLevel.VERBOSE - "v" -> LogLevel.VERBOSE - "debug" -> LogLevel.DEBUG - "d" -> LogLevel.DEBUG - "info" -> LogLevel.INFO - "i" -> LogLevel.INFO - "warning" -> LogLevel.WARNING - "warn" -> LogLevel.WARNING - "w" -> LogLevel.WARNING - "error" -> LogLevel.ERROR - "e" -> LogLevel.ERROR - "assert" -> LogLevel.WTF - "wtf" -> LogLevel.WTF - else -> DEFAULT_LEVEL - } - } -} - -private val DEFAULT_LEVEL = LogLevel.WARNING -private const val BUFFER_PATH = "systemui/buffer" -private const val TAG_PATH = "systemui/tag" diff --git a/packages/SystemUI/src/com/android/systemui/log/LogcatEchoTrackerProd.kt b/packages/SystemUI/src/com/android/systemui/log/LogcatEchoTrackerProd.kt deleted file mode 100644 index 1a4ad1907ff1..000000000000 --- a/packages/SystemUI/src/com/android/systemui/log/LogcatEchoTrackerProd.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2020 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 - -/** - * Production version of [LogcatEchoTracker] that isn't configurable. - */ -class LogcatEchoTrackerProd : LogcatEchoTracker { - override val logInBackgroundThread = false - - override fun isBufferLoggable(bufferName: String, level: LogLevel): Boolean { - return level >= LogLevel.WARNING - } - - override fun isTagLoggable(tagName: String, level: LogLevel): Boolean { - return level >= LogLevel.WARNING - } -} diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/BiometricMessagesLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/BiometricMessagesLog.java index 7f1ad6d20c16..eeadf406060d 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/BiometricMessagesLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/BiometricMessagesLog.java @@ -23,7 +23,7 @@ import java.lang.annotation.RetentionPolicy; import javax.inject.Qualifier; /** - * A {@link com.android.systemui.log.LogBuffer} for BiometricMessages processing such as + * A {@link com.android.systemui.plugins.log.LogBuffer} for BiometricMessages processing such as * {@link com.android.systemui.biometrics.FaceHelpMessageDeferral} */ @Qualifier diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/BroadcastDispatcherLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/BroadcastDispatcherLog.java index 7d1f1c2709fa..5cca1ab2abe7 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/BroadcastDispatcherLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/BroadcastDispatcherLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/CollapsedSbFragmentLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/CollapsedSbFragmentLog.java index 9ca0293fbd86..1d016d837b02 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/CollapsedSbFragmentLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/CollapsedSbFragmentLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/DozeLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/DozeLog.java index 7c5f4025117f..c9f78bcdeef8 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/DozeLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/DozeLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/LSShadeTransitionLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/LSShadeTransitionLog.java index 08d969b5eb77..76d20bea4bdf 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/LSShadeTransitionLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/LSShadeTransitionLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java index 1b81e88e62ba..92a7b5129995 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java @@ -22,11 +22,11 @@ import android.os.Looper; 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.log.LogcatEchoTracker; -import com.android.systemui.log.LogcatEchoTrackerDebug; -import com.android.systemui.log.LogcatEchoTrackerProd; +import com.android.systemui.plugins.log.LogBuffer; +import com.android.systemui.plugins.log.LogcatEchoTracker; +import com.android.systemui.plugins.log.LogcatEchoTrackerDebug; +import com.android.systemui.plugins.log.LogcatEchoTrackerProd; import com.android.systemui.statusbar.notification.NotifPipelineFlags; import com.android.systemui.util.Compile; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaBrowserLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaBrowserLog.java index 1d7ba94af4ed..90ced0291805 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaBrowserLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaBrowserLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaCarouselControllerLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaCarouselControllerLog.java index b03655a543f7..e5ac3e2e893b 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaCarouselControllerLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaCarouselControllerLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaMuteAwaitLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaMuteAwaitLog.java index c67d8bebe313..73690ab6c24d 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaMuteAwaitLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaMuteAwaitLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTimeoutListenerLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTimeoutListenerLog.java index 53963fc8d431..99ec05bc8d94 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTimeoutListenerLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTimeoutListenerLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTttReceiverLogBuffer.java b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTttReceiverLogBuffer.java index 5c572e8ef554..1570d434bc62 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTttReceiverLogBuffer.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTttReceiverLogBuffer.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTttSenderLogBuffer.java b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTttSenderLogBuffer.java index edab8c319f87..bf216c6991d2 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTttSenderLogBuffer.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTttSenderLogBuffer.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaViewLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaViewLog.java index 75a34fc22c3c..8c904eab409e 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaViewLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaViewLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/NearbyMediaDevicesLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/NearbyMediaDevicesLog.java index b1c6dcfcb13b..6d91f0c97c8a 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/NearbyMediaDevicesLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/NearbyMediaDevicesLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/NotifInteractionLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/NotifInteractionLog.java index 20fc6ff445a6..26af4964f7b8 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/NotifInteractionLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/NotifInteractionLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationHeadsUpLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationHeadsUpLog.java index fcc184a317b8..61daf9c8d71c 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationHeadsUpLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationHeadsUpLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationInterruptLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationInterruptLog.java index 760fbf3928b6..a59afa0fed1b 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationInterruptLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationInterruptLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationLog.java index a0b686487bec..6f8ea7ff2e9b 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationRenderLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationRenderLog.java index 8c8753a07339..835d3490293c 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationRenderLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationRenderLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationSectionLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationSectionLog.java index 7259eebf19b6..6e2bd7b2e1b5 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationSectionLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/NotificationSectionLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/PrivacyLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/PrivacyLog.java index e96e532f94bf..77b1bf5fd630 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/PrivacyLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/PrivacyLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/QSFragmentDisableLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/QSFragmentDisableLog.java index 557a254e5c09..9fd166b759d2 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/QSFragmentDisableLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/QSFragmentDisableLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/QSLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/QSLog.java index dd5010cf39a8..dd168bac5654 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/QSLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/QSLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/ShadeLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/ShadeLog.java index bd0d298ebdee..d24bfcb88188 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/ShadeLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/ShadeLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/StatusBarConnectivityLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/StatusBarConnectivityLog.java index b237f2d74483..67cdb722055b 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/StatusBarConnectivityLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/StatusBarConnectivityLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/StatusBarNetworkControllerLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/StatusBarNetworkControllerLog.java index f26b3164f488..af0f7c518e64 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/StatusBarNetworkControllerLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/StatusBarNetworkControllerLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/SwipeStatusBarAwayLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/SwipeStatusBarAwayLog.java index dd6837563a74..4c276e2bfaab 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/SwipeStatusBarAwayLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/SwipeStatusBarAwayLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/ToastLog.java b/packages/SystemUI/src/com/android/systemui/log/dagger/ToastLog.java index 8671dbfdf1fe..ba8b27c23ec1 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/ToastLog.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/ToastLog.java @@ -18,7 +18,7 @@ package com.android.systemui.log.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaCarouselControllerLogger.kt b/packages/SystemUI/src/com/android/systemui/media/MediaCarouselControllerLogger.kt index b1018f9544c0..d40624bfc63a 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaCarouselControllerLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaCarouselControllerLogger.kt @@ -17,9 +17,9 @@ package com.android.systemui.media import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.MediaCarouselControllerLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import javax.inject.Inject /** A debug logger for [MediaCarouselController]. */ diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaTimeoutLogger.kt b/packages/SystemUI/src/com/android/systemui/media/MediaTimeoutLogger.kt index d9c58c0d0d76..8c9e2d88c694 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaTimeoutLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaTimeoutLogger.kt @@ -18,11 +18,10 @@ package com.android.systemui.media import android.media.session.PlaybackState import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.MediaTimeoutListenerLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import javax.inject.Inject - private const val TAG = "MediaTimeout" /** diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaViewLogger.kt b/packages/SystemUI/src/com/android/systemui/media/MediaViewLogger.kt index 73868189b362..51c658cb6c54 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaViewLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaViewLogger.kt @@ -17,9 +17,9 @@ package com.android.systemui.media import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.MediaViewLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import javax.inject.Inject private const val TAG = "MediaView" diff --git a/packages/SystemUI/src/com/android/systemui/media/ResumeMediaBrowserLogger.kt b/packages/SystemUI/src/com/android/systemui/media/ResumeMediaBrowserLogger.kt index 41f735486c7e..a9c5c61dddbb 100644 --- a/packages/SystemUI/src/com/android/systemui/media/ResumeMediaBrowserLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/media/ResumeMediaBrowserLogger.kt @@ -18,9 +18,9 @@ package com.android.systemui.media import android.content.ComponentName import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.MediaBrowserLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import javax.inject.Inject /** A logger for events in [ResumeMediaBrowser]. */ diff --git a/packages/SystemUI/src/com/android/systemui/media/dagger/MediaModule.java b/packages/SystemUI/src/com/android/systemui/media/dagger/MediaModule.java index 66c036cee600..14b931f42b6f 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dagger/MediaModule.java +++ b/packages/SystemUI/src/com/android/systemui/media/dagger/MediaModule.java @@ -17,7 +17,6 @@ package com.android.systemui.media.dagger; import com.android.systemui.dagger.SysUISingleton; -import com.android.systemui.log.LogBuffer; import com.android.systemui.log.dagger.MediaTttReceiverLogBuffer; import com.android.systemui.log.dagger.MediaTttSenderLogBuffer; import com.android.systemui.media.MediaDataManager; @@ -35,6 +34,7 @@ import com.android.systemui.media.taptotransfer.receiver.MediaTttChipControllerR import com.android.systemui.media.taptotransfer.receiver.MediaTttReceiverLogger; import com.android.systemui.media.taptotransfer.sender.MediaTttChipControllerSender; import com.android.systemui.media.taptotransfer.sender.MediaTttSenderLogger; +import com.android.systemui.plugins.log.LogBuffer; import java.util.Optional; diff --git a/packages/SystemUI/src/com/android/systemui/media/muteawait/MediaMuteAwaitLogger.kt b/packages/SystemUI/src/com/android/systemui/media/muteawait/MediaMuteAwaitLogger.kt index 78f4e012da03..5ace3ea8a05b 100644 --- a/packages/SystemUI/src/com/android/systemui/media/muteawait/MediaMuteAwaitLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/media/muteawait/MediaMuteAwaitLogger.kt @@ -1,9 +1,9 @@ package com.android.systemui.media.muteawait import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.MediaMuteAwaitLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import javax.inject.Inject /** Log messages for [MediaMuteAwaitConnectionManager]. */ diff --git a/packages/SystemUI/src/com/android/systemui/media/nearby/NearbyMediaDevicesLogger.kt b/packages/SystemUI/src/com/android/systemui/media/nearby/NearbyMediaDevicesLogger.kt index 46b2cc141b3c..78408fce5a36 100644 --- a/packages/SystemUI/src/com/android/systemui/media/nearby/NearbyMediaDevicesLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/media/nearby/NearbyMediaDevicesLogger.kt @@ -1,9 +1,9 @@ package com.android.systemui.media.nearby import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.NearbyMediaDevicesLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import javax.inject.Inject /** Log messages for [NearbyMediaDevicesManager]. */ diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttLogger.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttLogger.kt index b565f3c22f24..38c971ed3f7d 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttLogger.kt @@ -16,8 +16,8 @@ package com.android.systemui.media.taptotransfer.common -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import com.android.systemui.temporarydisplay.TemporaryViewLogger /** diff --git a/packages/SystemUI/src/com/android/systemui/privacy/logging/PrivacyLogger.kt b/packages/SystemUI/src/com/android/systemui/privacy/logging/PrivacyLogger.kt index 1ea93474f954..03503fd1ff61 100644 --- a/packages/SystemUI/src/com/android/systemui/privacy/logging/PrivacyLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/privacy/logging/PrivacyLogger.kt @@ -17,10 +17,10 @@ package com.android.systemui.privacy.logging import android.permission.PermissionGroupUsage -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel -import com.android.systemui.log.LogMessage import com.android.systemui.log.dagger.PrivacyLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel +import com.android.systemui.plugins.log.LogMessage import com.android.systemui.privacy.PrivacyDialog import com.android.systemui.privacy.PrivacyItem import java.text.SimpleDateFormat diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSFragmentDisableFlagsLogger.kt b/packages/SystemUI/src/com/android/systemui/qs/QSFragmentDisableFlagsLogger.kt index 8544f61d7031..c663aa605ca2 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSFragmentDisableFlagsLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/QSFragmentDisableFlagsLogger.kt @@ -1,8 +1,8 @@ package com.android.systemui.qs -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.QSFragmentDisableLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import com.android.systemui.statusbar.DisableFlagsLogger import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/qs/logging/QSLogger.kt b/packages/SystemUI/src/com/android/systemui/qs/logging/QSLogger.kt index 60380064e098..931dc8df151a 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/logging/QSLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/logging/QSLogger.kt @@ -17,12 +17,12 @@ package com.android.systemui.qs.logging import android.service.quicksettings.Tile -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel -import com.android.systemui.log.LogLevel.DEBUG -import com.android.systemui.log.LogLevel.VERBOSE -import com.android.systemui.log.LogMessage import com.android.systemui.log.dagger.QSLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel +import com.android.systemui.plugins.log.LogLevel.DEBUG +import com.android.systemui.plugins.log.LogLevel.VERBOSE +import com.android.systemui.plugins.log.LogMessage import com.android.systemui.plugins.qs.QSTile import com.android.systemui.statusbar.StatusBarState import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/shade/NPVCDownEventState.kt b/packages/SystemUI/src/com/android/systemui/shade/NPVCDownEventState.kt index 07e8b9fe3123..754036d3baa9 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NPVCDownEventState.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/NPVCDownEventState.kt @@ -16,7 +16,7 @@ package com.android.systemui.shade import android.view.MotionEvent import com.android.systemui.dump.DumpsysTableLogger import com.android.systemui.dump.Row -import com.android.systemui.util.collection.RingBuffer +import com.android.systemui.plugins.util.RingBuffer import java.text.SimpleDateFormat import java.util.Locale diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeLogger.kt b/packages/SystemUI/src/com/android/systemui/shade/ShadeLogger.kt index f1e44ce5736e..b7ccc9894cf5 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/ShadeLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeLogger.kt @@ -1,10 +1,10 @@ package com.android.systemui.shade import android.view.MotionEvent -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel -import com.android.systemui.log.LogMessage import com.android.systemui.log.dagger.ShadeLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel +import com.android.systemui.plugins.log.LogMessage import com.google.errorprone.annotations.CompileTimeConstant import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ActionClickLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/ActionClickLogger.kt index 7f7ff9cf4881..90c52bd8c9f4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ActionClickLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ActionClickLogger.kt @@ -17,9 +17,9 @@ package com.android.systemui.statusbar import android.app.PendingIntent -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.NotifInteractionLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import com.android.systemui.statusbar.notification.collection.NotificationEntry import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/connectivity/NetworkControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/connectivity/NetworkControllerImpl.java index b3dd853cd2e1..402217dac185 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/connectivity/NetworkControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/connectivity/NetworkControllerImpl.java @@ -71,9 +71,9 @@ import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.demomode.DemoMode; import com.android.systemui.demomode.DemoModeController; import com.android.systemui.dump.DumpManager; -import com.android.systemui.log.LogBuffer; -import com.android.systemui.log.LogLevel; import com.android.systemui.log.dagger.StatusBarNetworkControllerLog; +import com.android.systemui.plugins.log.LogBuffer; +import com.android.systemui.plugins.log.LogLevel; import com.android.systemui.qs.tiles.dialog.InternetDialogFactory; import com.android.systemui.settings.CurrentUserTracker; import com.android.systemui.statusbar.policy.ConfigurationController; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeStatusBarAwayGestureLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeStatusBarAwayGestureLogger.kt index 17feaa842165..9bdff928c44b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeStatusBarAwayGestureLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeStatusBarAwayGestureLogger.kt @@ -16,9 +16,9 @@ package com.android.systemui.statusbar.gesture -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.SwipeStatusBarAwayLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import javax.inject.Inject /** Log messages for [SwipeStatusBarAwayGestureHandler]. */ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationClickerLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationClickerLogger.kt index ad3dfedcdb96..3058fbbc1031 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationClickerLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationClickerLogger.kt @@ -16,9 +16,9 @@ package com.android.systemui.statusbar.notification -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.NotifInteractionLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import com.android.systemui.statusbar.notification.collection.NotificationEntry import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coalescer/GroupCoalescerLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coalescer/GroupCoalescerLogger.kt index 211e37473a70..68d1319699d4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coalescer/GroupCoalescerLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coalescer/GroupCoalescerLogger.kt @@ -16,9 +16,9 @@ package com.android.systemui.statusbar.notification.collection.coalescer -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.NotificationLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import javax.inject.Inject class GroupCoalescerLogger @Inject constructor( diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/GutsCoordinatorLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/GutsCoordinatorLogger.kt index e8f352f60da0..2919def16304 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/GutsCoordinatorLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/GutsCoordinatorLogger.kt @@ -1,8 +1,8 @@ package com.android.systemui.statusbar.notification.collection.coordinator -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.NotificationLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import com.android.systemui.statusbar.notification.row.NotificationGuts import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorLogger.kt index 8625cdbc89d5..dfaa291c6bb6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorLogger.kt @@ -1,9 +1,10 @@ package com.android.systemui.statusbar.notification.collection.coordinator import android.util.Log -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel + import com.android.systemui.log.dagger.NotificationHeadsUpLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import javax.inject.Inject private const val TAG = "HeadsUpCoordinator" diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/PreparationCoordinatorLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/PreparationCoordinatorLogger.kt index c4f4ed54e2fa..9558f47af795 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/PreparationCoordinatorLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/PreparationCoordinatorLogger.kt @@ -16,9 +16,9 @@ package com.android.systemui.statusbar.notification.collection.coordinator -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.NotificationLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import com.android.systemui.statusbar.notification.collection.GroupEntry import com.android.systemui.statusbar.notification.collection.NotificationEntry import com.android.systemui.statusbar.notification.logKey diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/ShadeEventCoordinatorLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/ShadeEventCoordinatorLogger.kt index c687e1bacbc9..d80445491bda 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/ShadeEventCoordinatorLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/ShadeEventCoordinatorLogger.kt @@ -16,9 +16,9 @@ package com.android.systemui.statusbar.notification.collection.coordinator -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.NotificationLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import javax.inject.Inject private const val TAG = "ShadeEventCoordinator" diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/listbuilder/ShadeListBuilderLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/listbuilder/ShadeListBuilderLogger.kt index d8dae5d23f42..8e052c7dcc5d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/listbuilder/ShadeListBuilderLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/listbuilder/ShadeListBuilderLogger.kt @@ -16,11 +16,11 @@ package com.android.systemui.statusbar.notification.collection.listbuilder -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel.DEBUG -import com.android.systemui.log.LogLevel.INFO -import com.android.systemui.log.LogLevel.WARNING import com.android.systemui.log.dagger.NotificationLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel.DEBUG +import com.android.systemui.plugins.log.LogLevel.INFO +import com.android.systemui.plugins.log.LogLevel.WARNING import com.android.systemui.statusbar.notification.NotifPipelineFlags import com.android.systemui.statusbar.notification.collection.GroupEntry import com.android.systemui.statusbar.notification.collection.ListEntry diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt index aa27e1e407f0..911a2d0c2b36 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt @@ -20,13 +20,13 @@ import android.os.RemoteException import android.service.notification.NotificationListenerService import android.service.notification.NotificationListenerService.RankingMap import android.service.notification.StatusBarNotification -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel.DEBUG -import com.android.systemui.log.LogLevel.ERROR -import com.android.systemui.log.LogLevel.INFO -import com.android.systemui.log.LogLevel.WARNING -import com.android.systemui.log.LogLevel.WTF import com.android.systemui.log.dagger.NotificationLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel.DEBUG +import com.android.systemui.plugins.log.LogLevel.ERROR +import com.android.systemui.plugins.log.LogLevel.INFO +import com.android.systemui.plugins.log.LogLevel.WARNING +import com.android.systemui.plugins.log.LogLevel.WTF import com.android.systemui.statusbar.notification.collection.NotifCollection import com.android.systemui.statusbar.notification.collection.NotifCollection.CancellationReason import com.android.systemui.statusbar.notification.collection.NotifCollection.FutureDismissal diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/NodeSpecBuilderLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/NodeSpecBuilderLogger.kt index 38e3d496a60c..9c71e5c1054c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/NodeSpecBuilderLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/NodeSpecBuilderLogger.kt @@ -16,9 +16,9 @@ package com.android.systemui.statusbar.notification.collection.render -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.NotificationLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import com.android.systemui.statusbar.notification.NotifPipelineFlags import com.android.systemui.statusbar.notification.collection.listbuilder.NotifSection import com.android.systemui.util.Compile diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewDifferLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewDifferLogger.kt index 6d1071c283e3..b4b9438cd6be 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewDifferLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewDifferLogger.kt @@ -16,9 +16,9 @@ package com.android.systemui.statusbar.notification.collection.render -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.NotificationLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import java.lang.RuntimeException import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/HeadsUpViewBinderLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/HeadsUpViewBinderLogger.kt index 5dbec8dcba20..d4f11fc141f0 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/HeadsUpViewBinderLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/HeadsUpViewBinderLogger.kt @@ -1,8 +1,8 @@ package com.android.systemui.statusbar.notification.interruption -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel.INFO import com.android.systemui.log.dagger.NotificationHeadsUpLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel.INFO import com.android.systemui.statusbar.notification.collection.NotificationEntry import com.android.systemui.statusbar.notification.logKey import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptLogger.kt index 99d320d1c7ca..073b6b041b81 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptLogger.kt @@ -16,11 +16,11 @@ package com.android.systemui.statusbar.notification.interruption -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel.DEBUG -import com.android.systemui.log.LogLevel.INFO -import com.android.systemui.log.LogLevel.WARNING import com.android.systemui.log.dagger.NotificationInterruptLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel.DEBUG +import com.android.systemui.plugins.log.LogLevel.INFO +import com.android.systemui.plugins.log.LogLevel.WARNING import com.android.systemui.statusbar.notification.collection.NotificationEntry import com.android.systemui.statusbar.notification.logKey import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationRoundnessLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationRoundnessLogger.kt index fe03b2ad6a32..10197a38527e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationRoundnessLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationRoundnessLogger.kt @@ -16,9 +16,9 @@ package com.android.systemui.statusbar.notification.logging -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel.INFO import com.android.systemui.log.dagger.NotificationRenderLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel.INFO import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow import com.android.systemui.statusbar.notification.row.ExpandableView import com.android.systemui.statusbar.notification.stack.NotificationSection diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotifBindPipelineLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotifBindPipelineLogger.kt index ab91926d466a..46fef3f973a7 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotifBindPipelineLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotifBindPipelineLogger.kt @@ -16,9 +16,9 @@ package com.android.systemui.statusbar.notification.row -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel.INFO import com.android.systemui.log.dagger.NotificationLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel.INFO import com.android.systemui.statusbar.notification.collection.NotificationEntry import com.android.systemui.statusbar.notification.logKey import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/RowContentBindStageLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/RowContentBindStageLogger.kt index f9923b2254d7..8a5d29a1ae2d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/RowContentBindStageLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/RowContentBindStageLogger.kt @@ -16,9 +16,9 @@ package com.android.systemui.statusbar.notification.row -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel.INFO import com.android.systemui.log.dagger.NotificationLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel.INFO import com.android.systemui.statusbar.notification.collection.NotificationEntry import com.android.systemui.statusbar.notification.logKey import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsLogger.kt index cb7dfe87f7fb..b61c55edadcd 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsLogger.kt @@ -17,9 +17,9 @@ package com.android.systemui.statusbar.notification.stack import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.NotificationSectionLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import javax.inject.Inject private const val TAG = "NotifSections" diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLogger.kt index 5f79c0e3913a..4c52db7f8732 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLogger.kt @@ -1,8 +1,8 @@ package com.android.systemui.statusbar.notification.stack -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel.INFO import com.android.systemui.log.dagger.NotificationHeadsUpLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel.INFO import com.android.systemui.statusbar.notification.collection.NotificationEntry import com.android.systemui.statusbar.notification.logKey import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_ADD diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackStateLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackStateLogger.kt index cb4a0884fea4..f5de678a8536 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackStateLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackStateLogger.kt @@ -1,8 +1,8 @@ package com.android.systemui.statusbar.notification.stack -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.NotificationHeadsUpLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import com.android.systemui.statusbar.notification.logKey import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/LSShadeTransitionLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/LSShadeTransitionLogger.kt index 02b235493715..4839fe6a7bef 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/LSShadeTransitionLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/LSShadeTransitionLogger.kt @@ -19,9 +19,9 @@ package com.android.systemui.statusbar.phone import android.util.DisplayMetrics import android.view.View import com.android.internal.logging.nano.MetricsProto.MetricsEvent -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.LSShadeTransitionLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow import com.android.systemui.statusbar.notification.row.ExpandableView import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterLogger.kt index b9a1413ff791..81edff45c505 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterLogger.kt @@ -17,12 +17,12 @@ package com.android.systemui.statusbar.phone import android.app.PendingIntent -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel.DEBUG -import com.android.systemui.log.LogLevel.ERROR -import com.android.systemui.log.LogLevel.INFO -import com.android.systemui.log.LogLevel.WARNING import com.android.systemui.log.dagger.NotifInteractionLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel.DEBUG +import com.android.systemui.plugins.log.LogLevel.ERROR +import com.android.systemui.plugins.log.LogLevel.INFO +import com.android.systemui.plugins.log.LogLevel.WARNING import com.android.systemui.statusbar.notification.collection.NotificationEntry import com.android.systemui.statusbar.notification.logKey import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentLogger.kt index 9ae378f34fc0..0e6b7f253bcf 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentLogger.kt @@ -16,9 +16,9 @@ package com.android.systemui.statusbar.phone.fragment -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.CollapsedSbFragmentLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import com.android.systemui.statusbar.DisableFlagsLogger import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ConnectivityPipelineLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ConnectivityPipelineLogger.kt index dbb1aa54d8ee..d3cf32fb44ce 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ConnectivityPipelineLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ConnectivityPipelineLogger.kt @@ -18,10 +18,10 @@ package com.android.systemui.statusbar.pipeline.shared import android.net.Network import android.net.NetworkCapabilities -import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel import com.android.systemui.log.dagger.StatusBarConnectivityLog +import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger.Companion.toString import javax.inject.Inject import kotlinx.coroutines.flow.Flow diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManagerLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManagerLogger.kt index d7c81af53d8b..df1e80b78c9b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManagerLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManagerLogger.kt @@ -16,10 +16,10 @@ package com.android.systemui.statusbar.policy -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel.INFO -import com.android.systemui.log.LogLevel.VERBOSE import com.android.systemui.log.dagger.NotificationHeadsUpLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel.INFO +import com.android.systemui.plugins.log.LogLevel.VERBOSE import com.android.systemui.statusbar.notification.collection.NotificationEntry import com.android.systemui.statusbar.notification.logKey import javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewLogger.kt b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewLogger.kt index 606a11a84686..a7185cb18c40 100644 --- a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewLogger.kt @@ -16,8 +16,8 @@ package com.android.systemui.temporarydisplay -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel /** A logger for temporary view changes -- see [TemporaryViewDisplayController]. */ open class TemporaryViewLogger( diff --git a/packages/SystemUI/src/com/android/systemui/toast/ToastLogger.kt b/packages/SystemUI/src/com/android/systemui/toast/ToastLogger.kt index 51541bd3032e..fda511433143 100644 --- a/packages/SystemUI/src/com/android/systemui/toast/ToastLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/toast/ToastLogger.kt @@ -16,11 +16,11 @@ package com.android.systemui.toast -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel -import com.android.systemui.log.LogLevel.DEBUG -import com.android.systemui.log.LogMessage import com.android.systemui.log.dagger.ToastLog +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel +import com.android.systemui.plugins.log.LogLevel.DEBUG +import com.android.systemui.plugins.log.LogMessage import javax.inject.Inject private const val TAG = "ToastLog" diff --git a/packages/SystemUI/src/com/android/systemui/util/collection/RingBuffer.kt b/packages/SystemUI/src/com/android/systemui/util/collection/RingBuffer.kt deleted file mode 100644 index 97dc842ec699..000000000000 --- a/packages/SystemUI/src/com/android/systemui/util/collection/RingBuffer.kt +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2022 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.util.collection - -import kotlin.math.max - -/** - * A simple ring buffer implementation - * - * Use [advance] to get the least recent item in the buffer (and then presumably fill it with - * appropriate data). This will cause it to become the most recent item. - * - * As the buffer is used, it will grow, allocating new instances of T using [factory] until it - * reaches [maxSize]. After this point, no new instances will be created. Instead, the "oldest" - * instances will be recycled from the back of the buffer and placed at the front. - * - * @param maxSize The maximum size the buffer can grow to before it begins functioning as a ring. - * @param factory A function that creates a fresh instance of T. Used by the buffer while it's - * growing to [maxSize]. - */ -class RingBuffer( - private val maxSize: Int, - private val factory: () -> T -) : Iterable { - - private val buffer = MutableList(maxSize) { null } - - /** - * An abstract representation that points to the "end" of the buffer. Increments every time - * [advance] is called and never wraps. Use [indexOf] to calculate the associated index into - * the backing array. Always points to the "next" available slot in the buffer. Before the - * buffer has completely filled, the value pointed to will be null. Afterward, it will be the - * value at the "beginning" of the buffer. - * - * This value is unlikely to overflow. Assuming [advance] is called at rate of 100 calls/ms, - * omega will overflow after a little under three million years of continuous operation. - */ - private var omega: Long = 0 - - /** - * The number of items currently stored in the buffer. Calls to [advance] will cause this value - * to increase by one until it reaches [maxSize]. - */ - val size: Int - get() = if (omega < maxSize) omega.toInt() else maxSize - - /** - * Advances the buffer's position by one and returns the value that is now present at the "end" - * of the buffer. If the buffer is not yet full, uses [factory] to create a new item. - * Otherwise, reuses the value that was previously at the "beginning" of the buffer. - * - * IMPORTANT: The value is returned as-is, without being reset. It will retain any data that - * was previously stored on it. - */ - fun advance(): T { - val index = indexOf(omega) - omega += 1 - val entry = buffer[index] ?: factory().also { - buffer[index] = it - } - return entry - } - - /** - * Returns the value stored at [index], which can range from 0 (the "start", or oldest element - * of the buffer) to [size] - 1 (the "end", or newest element of the buffer). - */ - operator fun get(index: Int): T { - if (index < 0 || index >= size) { - throw IndexOutOfBoundsException("Index $index is out of bounds") - } - - // If omega is larger than the maxSize, then the buffer is full, and omega is equivalent - // to the "start" of the buffer. If omega is smaller than the maxSize, then the buffer is - // not yet full and our start should be 0. However, in modspace, maxSize and 0 are - // equivalent, so we can get away with using it as the start value instead. - val start = max(omega, maxSize.toLong()) - - return buffer[indexOf(start + index)]!! - } - - inline fun forEach(action: (T) -> Unit) { - for (i in 0 until size) { - action(get(i)) - } - } - - override fun iterator(): Iterator { - return object : Iterator { - private var position: Int = 0 - - override fun next(): T { - if (position >= size) { - throw NoSuchElementException() - } - return get(position).also { position += 1 } - } - - override fun hasNext(): Boolean { - return position < size - } - } - } - - private fun indexOf(position: Long): Int { - return (position % maxSize).toInt() - } -} diff --git a/packages/SystemUI/tests/src/com/android/systemui/dump/DumpHandlerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/dump/DumpHandlerTest.kt index fc672016a886..2397da6c0d76 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dump/DumpHandlerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/dump/DumpHandlerTest.kt @@ -19,7 +19,7 @@ package com.android.systemui.dump import androidx.test.filters.SmallTest import com.android.systemui.Dumpable import com.android.systemui.SysuiTestCase -import com.android.systemui.log.LogBuffer +import com.android.systemui.plugins.log.LogBuffer import com.android.systemui.shared.system.UncaughtExceptionPreHandlerManager import com.android.systemui.util.mockito.any import org.junit.Before diff --git a/packages/SystemUI/tests/src/com/android/systemui/dump/LogBufferHelper.kt b/packages/SystemUI/tests/src/com/android/systemui/dump/LogBufferHelper.kt index bd029a727ee3..64547f4463d1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dump/LogBufferHelper.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/dump/LogBufferHelper.kt @@ -16,9 +16,9 @@ package com.android.systemui.dump -import com.android.systemui.log.LogBuffer -import com.android.systemui.log.LogLevel -import com.android.systemui.log.LogcatEchoTracker +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel +import com.android.systemui.plugins.log.LogcatEchoTracker /** * Creates a LogBuffer that will echo everything to logcat, which is useful for debugging tests. diff --git a/packages/SystemUI/tests/src/com/android/systemui/log/LogBufferTest.kt b/packages/SystemUI/tests/src/com/android/systemui/log/LogBufferTest.kt deleted file mode 100644 index 56aff3c2fc8b..000000000000 --- a/packages/SystemUI/tests/src/com/android/systemui/log/LogBufferTest.kt +++ /dev/null @@ -1,138 +0,0 @@ -package com.android.systemui.log - -import androidx.test.filters.SmallTest -import com.android.systemui.SysuiTestCase -import com.google.common.truth.Truth.assertThat -import java.io.PrintWriter -import java.io.StringWriter -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.junit.MockitoJUnitRunner - -@SmallTest -@RunWith(MockitoJUnitRunner::class) -class LogBufferTest : SysuiTestCase() { - private lateinit var buffer: LogBuffer - - private lateinit var outputWriter: StringWriter - - @Mock - private lateinit var logcatEchoTracker: LogcatEchoTracker - - @Before - fun setup() { - outputWriter = StringWriter() - buffer = createBuffer() - } - - private fun createBuffer(): LogBuffer { - return LogBuffer("TestBuffer", 1, logcatEchoTracker, false) - } - - @Test - fun log_shouldSaveLogToBuffer() { - buffer.log("Test", LogLevel.INFO, "Some test message") - - val dumpedString = dumpBuffer() - - assertThat(dumpedString).contains("Some test message") - } - - @Test - fun log_shouldRotateIfLogBufferIsFull() { - buffer.log("Test", LogLevel.INFO, "This should be rotated") - buffer.log("Test", LogLevel.INFO, "New test message") - - val dumpedString = dumpBuffer() - - assertThat(dumpedString).contains("New test message") - } - - @Test - fun dump_writesExceptionAndStacktrace() { - buffer = createBuffer() - val exception = createTestException("Exception message", "TestClass") - buffer.log("Tag", LogLevel.ERROR, { str1 = "Extra message" }, { str1!! }, exception) - - val dumpedString = dumpBuffer() - - assertThat(dumpedString).contains("Extra message") - assertThat(dumpedString).contains("java.lang.RuntimeException: Exception message") - assertThat(dumpedString).contains("at TestClass.TestMethod(TestClass.java:1)") - assertThat(dumpedString).contains("at TestClass.TestMethod(TestClass.java:2)") - } - - @Test - fun dump_writesCauseAndStacktrace() { - buffer = createBuffer() - val exception = createTestException("Exception message", - "TestClass", - cause = createTestException("The real cause!", "TestClass")) - buffer.log("Tag", LogLevel.ERROR, { str1 = "Extra message" }, { str1!! }, exception) - - val dumpedString = dumpBuffer() - - assertThat(dumpedString) - .contains("Caused by: java.lang.RuntimeException: The real cause!") - assertThat(dumpedString).contains("at TestClass.TestMethod(TestClass.java:1)") - assertThat(dumpedString).contains("at TestClass.TestMethod(TestClass.java:2)") - } - - @Test - fun dump_writesSuppressedExceptionAndStacktrace() { - buffer = createBuffer() - val exception = RuntimeException("Root exception message") - exception.addSuppressed( - createTestException( - "First suppressed exception", - "FirstClass", - createTestException("Cause of suppressed exp", "ThirdClass") - )) - exception.addSuppressed( - createTestException("Second suppressed exception", "SecondClass")) - buffer.log("Tag", LogLevel.ERROR, { str1 = "Extra message" }, { str1!! }, exception) - - val dumpedStr = dumpBuffer() - - // first suppressed exception - assertThat(dumpedStr) - .contains("Suppressed: " + - "java.lang.RuntimeException: First suppressed exception") - assertThat(dumpedStr).contains("at FirstClass.TestMethod(FirstClass.java:1)") - assertThat(dumpedStr).contains("at FirstClass.TestMethod(FirstClass.java:2)") - - assertThat(dumpedStr) - .contains("Caused by: java.lang.RuntimeException: Cause of suppressed exp") - assertThat(dumpedStr).contains("at ThirdClass.TestMethod(ThirdClass.java:1)") - assertThat(dumpedStr).contains("at ThirdClass.TestMethod(ThirdClass.java:2)") - - // second suppressed exception - assertThat(dumpedStr) - .contains("Suppressed: " + - "java.lang.RuntimeException: Second suppressed exception") - assertThat(dumpedStr).contains("at SecondClass.TestMethod(SecondClass.java:1)") - assertThat(dumpedStr).contains("at SecondClass.TestMethod(SecondClass.java:2)") - } - - private fun createTestException( - message: String, - errorClass: String, - cause: Throwable? = null, - ): Exception { - val exception = RuntimeException(message, cause) - exception.stackTrace = (1..5).map { lineNumber -> - StackTraceElement(errorClass, - "TestMethod", - "$errorClass.java", - lineNumber) - }.toTypedArray() - return exception - } - - private fun dumpBuffer(): String { - buffer.dump(PrintWriter(outputWriter), tailLength = 100) - return outputWriter.toString() - } -} diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttLoggerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttLoggerTest.kt index 1078cdaa57c4..e009e8651f2a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttLoggerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttLoggerTest.kt @@ -19,9 +19,9 @@ package com.android.systemui.media.taptotransfer.common import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.dump.DumpManager -import com.android.systemui.log.LogBuffer import com.android.systemui.log.LogBufferFactory -import com.android.systemui.log.LogcatEchoTracker +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogcatEchoTracker import com.google.common.truth.Truth.assertThat import java.io.PrintWriter import java.io.StringWriter diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentDisableFlagsLoggerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentDisableFlagsLoggerTest.kt index e2c6ff996199..d6db62aa2f72 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentDisableFlagsLoggerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentDisableFlagsLoggerTest.kt @@ -20,7 +20,7 @@ import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.dump.DumpManager import com.android.systemui.log.LogBufferFactory -import com.android.systemui.log.LogcatEchoTracker +import com.android.systemui.plugins.log.LogcatEchoTracker import com.android.systemui.statusbar.DisableFlagsLogger import com.google.common.truth.Truth.assertThat import org.junit.Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/LSShadeTransitionLoggerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/LSShadeTransitionLoggerTest.kt index 8cb530c355bd..5fc0ffe42f55 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/LSShadeTransitionLoggerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/LSShadeTransitionLoggerTest.kt @@ -4,7 +4,7 @@ import android.testing.AndroidTestingRunner import android.util.DisplayMetrics import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase -import com.android.systemui.log.LogBuffer +import com.android.systemui.plugins.log.LogBuffer import com.android.systemui.statusbar.notification.row.ExpandableView import com.android.systemui.statusbar.phone.LSShadeTransitionLogger import com.android.systemui.statusbar.phone.LockscreenGestureLogger diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerBaseTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerBaseTest.java index f8a0d2fc415c..9c65fac1af45 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerBaseTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerBaseTest.java @@ -70,7 +70,7 @@ import com.android.systemui.SysuiTestCase; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.demomode.DemoModeController; import com.android.systemui.dump.DumpManager; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import com.android.systemui.statusbar.policy.DeviceProvisionedController; import com.android.systemui.statusbar.policy.DeviceProvisionedController.DeviceProvisionedListener; import com.android.systemui.telephony.TelephonyListenerManager; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerDataTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerDataTest.java index ed8a3e16cdd1..4bed4a19b3d9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerDataTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerDataTest.java @@ -38,7 +38,7 @@ import android.testing.TestableLooper.RunWithLooper; import com.android.settingslib.mobile.TelephonyIcons; import com.android.settingslib.net.DataUsageController; import com.android.systemui.dump.DumpManager; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import com.android.systemui.statusbar.policy.DeviceProvisionedController; import com.android.systemui.util.CarrierConfigTracker; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerSignalTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerSignalTest.java index a76676e01c15..d5f5105036d3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerSignalTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerSignalTest.java @@ -43,7 +43,7 @@ import com.android.settingslib.mobile.TelephonyIcons; import com.android.settingslib.net.DataUsageController; import com.android.systemui.R; import com.android.systemui.dump.DumpManager; -import com.android.systemui.log.LogBuffer; +import com.android.systemui.plugins.log.LogBuffer; import com.android.systemui.statusbar.policy.DeviceProvisionedController; import com.android.systemui.util.CarrierConfigTracker; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentLoggerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentLoggerTest.kt index 1ee8875eada8..78a4db1224cd 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentLoggerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentLoggerTest.kt @@ -20,7 +20,7 @@ import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.dump.DumpManager import com.android.systemui.log.LogBufferFactory -import com.android.systemui.log.LogcatEchoTracker +import com.android.systemui.plugins.log.LogcatEchoTracker import com.android.systemui.statusbar.DisableFlagsLogger import com.google.common.truth.Truth.assertThat import org.junit.Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentTest.java index 63467e7039d4..438271c489e6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentTest.java @@ -49,9 +49,9 @@ import com.android.systemui.R; import com.android.systemui.SysuiBaseFragmentTest; import com.android.systemui.dump.DumpManager; import com.android.systemui.flags.FeatureFlags; -import com.android.systemui.log.LogBuffer; -import com.android.systemui.log.LogcatEchoTracker; import com.android.systemui.plugins.DarkIconDispatcher; +import com.android.systemui.plugins.log.LogBuffer; +import com.android.systemui.plugins.log.LogcatEchoTracker; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.shade.NotificationPanelViewController; import com.android.systemui.shade.ShadeExpansionStateManager; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/shared/ConnectivityPipelineLoggerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/shared/ConnectivityPipelineLoggerTest.kt index 0e75c74ef6f5..b32058fca109 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/shared/ConnectivityPipelineLoggerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/shared/ConnectivityPipelineLoggerTest.kt @@ -22,7 +22,7 @@ import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.dump.DumpManager import com.android.systemui.log.LogBufferFactory -import com.android.systemui.log.LogcatEchoTracker +import com.android.systemui.plugins.log.LogcatEchoTracker import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger.Companion.logInputChange import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger.Companion.logOutputChange import com.google.common.truth.Truth.assertThat diff --git a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewLoggerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewLoggerTest.kt index c9f2b4db81ef..13e9f608158e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewLoggerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewLoggerTest.kt @@ -19,9 +19,9 @@ package com.android.systemui.temporarydisplay import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.dump.DumpManager -import com.android.systemui.log.LogBuffer import com.android.systemui.log.LogBufferFactory -import com.android.systemui.log.LogcatEchoTracker +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogcatEchoTracker import com.google.common.truth.Truth.assertThat import java.io.PrintWriter import java.io.StringWriter diff --git a/packages/SystemUI/tests/src/com/android/systemui/util/collection/RingBufferTest.kt b/packages/SystemUI/tests/src/com/android/systemui/util/collection/RingBufferTest.kt deleted file mode 100644 index 5e09b81da4e8..000000000000 --- a/packages/SystemUI/tests/src/com/android/systemui/util/collection/RingBufferTest.kt +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2022 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.util.collection - -import android.testing.AndroidTestingRunner -import androidx.test.filters.SmallTest -import com.android.systemui.SysuiTestCase -import org.junit.Assert.assertEquals -import org.junit.Assert.assertFalse -import org.junit.Assert.assertSame -import org.junit.Assert.assertThrows -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.MockitoAnnotations - -@SmallTest -@RunWith(AndroidTestingRunner::class) -class RingBufferTest : SysuiTestCase() { - - private val buffer = RingBuffer(5) { TestElement() } - - private val history = mutableListOf() - - @Before - fun setUp() { - MockitoAnnotations.initMocks(this) - } - - @Test - fun testBarelyFillBuffer() { - fillBuffer(5) - - assertEquals(0, buffer[0].id) - assertEquals(1, buffer[1].id) - assertEquals(2, buffer[2].id) - assertEquals(3, buffer[3].id) - assertEquals(4, buffer[4].id) - } - - @Test - fun testPartiallyFillBuffer() { - fillBuffer(3) - - assertEquals(3, buffer.size) - - assertEquals(0, buffer[0].id) - assertEquals(1, buffer[1].id) - assertEquals(2, buffer[2].id) - - assertThrows(IndexOutOfBoundsException::class.java) { buffer[3] } - assertThrows(IndexOutOfBoundsException::class.java) { buffer[4] } - } - - @Test - fun testSpinBuffer() { - fillBuffer(277) - - assertEquals(272, buffer[0].id) - assertEquals(273, buffer[1].id) - assertEquals(274, buffer[2].id) - assertEquals(275, buffer[3].id) - assertEquals(276, buffer[4].id) - assertThrows(IndexOutOfBoundsException::class.java) { buffer[5] } - - assertEquals(5, buffer.size) - } - - @Test - fun testElementsAreRecycled() { - fillBuffer(23) - - assertSame(history[4], buffer[1]) - assertSame(history[9], buffer[1]) - assertSame(history[14], buffer[1]) - assertSame(history[19], buffer[1]) - } - - @Test - fun testIterator() { - fillBuffer(13) - - val iterator = buffer.iterator() - - for (i in 0 until 5) { - assertEquals(history[8 + i], iterator.next()) - } - assertFalse(iterator.hasNext()) - assertThrows(NoSuchElementException::class.java) { iterator.next() } - } - - @Test - fun testForEach() { - fillBuffer(13) - var i = 8 - - buffer.forEach { - assertEquals(history[i], it) - i++ - } - assertEquals(13, i) - } - - private fun fillBuffer(count: Int) { - for (i in 0 until count) { - val elem = buffer.advance() - elem.id = history.size - history.add(elem) - } - } -} - -private class TestElement(var id: Int = 0) { - override fun toString(): String { - return "{TestElement $id}" - } -} \ No newline at end of file -- cgit v1.2.3-59-g8ed1b