From ca89abc937a1182a6e30800fdf7ed31f62aa287e Mon Sep 17 00:00:00 2001 From: Ats Jenk Date: Fri, 19 May 2023 14:47:45 -0700 Subject: [PATCH] If ProtoLog is not required, add fallback to logcat Checks if logcat is enabled for a tag. If it is, logs directly to logcat from the stub class. Only applicable if REQUIRE_PROTOLOGTOOL is set to false which is only set in sysui studio based builds. Protolog tool does not run on the gradle based sysui studio build. Without the logcat fallback, sysui studio builds do not have any logging from protolog. This change does introduce a dependency on android.util.Log in ProtoLog class. This class is part of common sources for ProtoLog. And is imported in the protolog tool itself. Had to create a new filtered target of protolog common sources that excludes the ProtoLog class. Bug: 283499455 Test: m -j Test: build sysui from studio, enable ProtoLog to logcat for a tag, observe logs in logcat Change-Id: I9a085deaf39be1fb503c0df928a307e55c48ea4b --- core/java/Android.bp | 11 ++++++++++ .../internal/protolog/common/ProtoLog.java | 20 +++++++++++++++++++ tools/protologtool/Android.bp | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/core/java/Android.bp b/core/java/Android.bp index 02b14ad7a757e..f8f4cc3523f25 100644 --- a/core/java/Android.bp +++ b/core/java/Android.bp @@ -510,6 +510,17 @@ filegroup { ], } +// common protolog sources without classes that rely on Android SDK +filegroup { + name: "protolog-common-no-android-src", + srcs: [ + ":protolog-common-src", + ], + exclude_srcs: [ + "com/android/internal/protolog/common/ProtoLog.java", + ], +} + java_library { name: "protolog-lib", platform_apis: true, diff --git a/core/java/com/android/internal/protolog/common/ProtoLog.java b/core/java/com/android/internal/protolog/common/ProtoLog.java index 93765cdf0890a..8870096f3db7f 100644 --- a/core/java/com/android/internal/protolog/common/ProtoLog.java +++ b/core/java/com/android/internal/protolog/common/ProtoLog.java @@ -16,6 +16,8 @@ package com.android.internal.protolog.common; +import android.util.Log; + /** * ProtoLog API - exposes static logging methods. Usage of this API is similar * to {@code android.utils.Log} class. Instead of plain text log messages each call consists of @@ -53,6 +55,9 @@ public class ProtoLog { throw new UnsupportedOperationException( "ProtoLog calls MUST be processed with ProtoLogTool"); } + if (group.isLogToLogcat()) { + Log.d(group.getTag(), String.format(messageString, args)); + } } /** @@ -68,6 +73,9 @@ public class ProtoLog { throw new UnsupportedOperationException( "ProtoLog calls MUST be processed with ProtoLogTool"); } + if (group.isLogToLogcat()) { + Log.v(group.getTag(), String.format(messageString, args)); + } } /** @@ -83,6 +91,9 @@ public class ProtoLog { throw new UnsupportedOperationException( "ProtoLog calls MUST be processed with ProtoLogTool"); } + if (group.isLogToLogcat()) { + Log.i(group.getTag(), String.format(messageString, args)); + } } /** @@ -98,6 +109,9 @@ public class ProtoLog { throw new UnsupportedOperationException( "ProtoLog calls MUST be processed with ProtoLogTool"); } + if (group.isLogToLogcat()) { + Log.w(group.getTag(), String.format(messageString, args)); + } } /** @@ -113,6 +127,9 @@ public class ProtoLog { throw new UnsupportedOperationException( "ProtoLog calls MUST be processed with ProtoLogTool"); } + if (group.isLogToLogcat()) { + Log.e(group.getTag(), String.format(messageString, args)); + } } /** @@ -128,5 +145,8 @@ public class ProtoLog { throw new UnsupportedOperationException( "ProtoLog calls MUST be processed with ProtoLogTool"); } + if (group.isLogToLogcat()) { + Log.wtf(group.getTag(), String.format(messageString, args)); + } } } diff --git a/tools/protologtool/Android.bp b/tools/protologtool/Android.bp index 039bb4e2788c0..46745e995f645 100644 --- a/tools/protologtool/Android.bp +++ b/tools/protologtool/Android.bp @@ -11,7 +11,7 @@ java_library_host { name: "protologtool-lib", srcs: [ "src/com/android/protolog/tool/**/*.kt", - ":protolog-common-src", + ":protolog-common-no-android-src", ], static_libs: [ "javaparser",