feat: SystemUI Log Android 16 QPR1
This commit is contained in:
1 parent
3c432d6758
commit
58fcce45de
5 files changed
+144
-9
No files matched your search
+21
-1
@@ -22,15 +22,35 @@ package {
|
||||
default_applicable_licenses: ["frameworks_base_packages_SystemUI_license"],
|
||||
}
|
||||
|
||||
java_library {
|
||||
sdk_version: "current",
|
||||
name: "SystemUILogCoreLib",
|
||||
device_supported: true,
|
||||
srcs: [
|
||||
"src/**/core/*.java",
|
||||
"src/**/core/*.kt",
|
||||
],
|
||||
static_libs: [
|
||||
"error_prone_annotations",
|
||||
],
|
||||
|
||||
// Enforce compat with PluginCoreLib
|
||||
java_version: "1.8",
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "SystemUILogLib",
|
||||
srcs: [
|
||||
"src/**/*.java",
|
||||
"src/**/*.kt",
|
||||
],
|
||||
exclude_srcs: [
|
||||
"src/**/core/*.java",
|
||||
"src/**/core/*.kt",
|
||||
],
|
||||
static_libs: [
|
||||
"error_prone_annotations",
|
||||
"SystemUICommon",
|
||||
"SystemUILogCoreLib",
|
||||
],
|
||||
kotlincflags: ["-Xjvm-default=all"],
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* Implemented by classes who want to be in:
|
||||
* {@code adb shell dumpsys activity service com.android.systemui}
|
||||
*
|
||||
* @see com.android.systemui.dump.DumpManager
|
||||
*/
|
||||
public interface Dumpable {
|
||||
|
||||
/**
|
||||
* Called when it's time to dump the internal state
|
||||
* @param pw Where to write your dump to.
|
||||
* @param args Arguments.
|
||||
*/
|
||||
void dump(@NonNull PrintWriter pw, @NonNull String[] args);
|
||||
}
|
||||
@@ -41,6 +41,10 @@ data class LogMessageImpl(
|
||||
override var bool4: Boolean,
|
||||
) : LogMessage {
|
||||
|
||||
fun clear() {
|
||||
reset(DEFAULT_TAG, LogLevel.DEBUG, 0, DEFAULT_PRINTER)
|
||||
}
|
||||
|
||||
fun reset(
|
||||
tag: String,
|
||||
level: LogLevel,
|
||||
@@ -86,7 +90,7 @@ data class LogMessageImpl(
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
false,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.log
|
||||
|
||||
import com.android.systemui.log.core.LogLevel
|
||||
import com.android.systemui.log.core.LogMessage
|
||||
import com.android.systemui.log.core.MessageBuffer
|
||||
import com.android.systemui.log.core.MessagePrinter
|
||||
import kotlin.collections.ArrayDeque
|
||||
|
||||
/**
|
||||
* A simple implementation of [MessageBuffer] that forwards messages to [android.util.Log]
|
||||
* immediately. This defeats the intention behind [LogBuffer] and should only be used when
|
||||
* [LogBuffer]s are unavailable in a certain context.
|
||||
*/
|
||||
class LogcatOnlyMessageBuffer(
|
||||
private val targetLogLevel: LogLevel,
|
||||
private val maxMessageCount: Int,
|
||||
): MessageBuffer {
|
||||
private val messages = ArrayDeque<LogMessageImpl>(maxMessageCount)
|
||||
|
||||
constructor(targetLogLevel: LogLevel) : this(targetLogLevel, DEFAULT_MESSAGE_MAX_COUNT)
|
||||
|
||||
override fun obtain(
|
||||
tag: String,
|
||||
level: LogLevel,
|
||||
messagePrinter: MessagePrinter,
|
||||
exception: Throwable?,
|
||||
): LogMessage {
|
||||
val message =
|
||||
synchronized(messages) { messages.removeFirstOrNull() }
|
||||
?: LogMessageImpl.Factory.create()
|
||||
message.reset(tag, level, System.currentTimeMillis(), messagePrinter, exception)
|
||||
return message
|
||||
}
|
||||
|
||||
override fun commit(message: LogMessage) {
|
||||
if (message.level >= targetLogLevel) {
|
||||
val strMessage = message.messagePrinter(message)
|
||||
message.level.logcatFunc(message.tag, strMessage, message.exception)
|
||||
}
|
||||
|
||||
if (message is LogMessageImpl) {
|
||||
message.clear()
|
||||
synchronized(messages) {
|
||||
if (messages.size < maxMessageCount) {
|
||||
messages.addLast(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val DEFAULT_MESSAGE_MAX_COUNT = 4
|
||||
}
|
||||
}
|
||||
@@ -19,11 +19,15 @@ package com.android.systemui.log.core
|
||||
import android.util.Log
|
||||
|
||||
/** Enum version of @Log.Level */
|
||||
enum class LogLevel(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")
|
||||
enum class LogLevel(
|
||||
val nativeLevel: Int,
|
||||
val shortString: String,
|
||||
val logcatFunc: (String, String, Throwable?) -> Unit,
|
||||
) {
|
||||
VERBOSE(Log.VERBOSE, "V", Log::v),
|
||||
DEBUG(Log.DEBUG, "D", Log::d),
|
||||
INFO(Log.INFO, "I", Log::i),
|
||||
WARNING(Log.WARN, "W", Log::w),
|
||||
ERROR(Log.ERROR, "E", Log::e),
|
||||
WTF(Log.ASSERT, "WTF", Log::wtf),
|
||||
}
|
||||
Reference in new issue
Block a user