From 2b227ee11da397003b1d67a97edc1817214f5f35 Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Fri, 19 Aug 2022 09:38:18 -0700 Subject: [PATCH] Save ProtoLog viewer configuration in WMShell In this changeset topic - Build WMShell with protolog viewer config - it's built with SystemUI{,Google} packages and installed as /system_ext/etc/wmshell.protolog.json.gz - Deprecated the viewer configuration as a bundled resource - The `required` keyword in Android.bp does not propagate, need to add it in individual Android.bp file such as SystemUIGoogle/Android.bp - Push the generated viewer config file onto device in makepush script (in a separate CL) Bug: 244642224 Test: mp sysuig Change-Id: Ib7f37ec55d12493d6beec3aba66883415966b521 --- libs/WindowManager/Shell/Android.bp | 18 +++++++++-- .../wm/shell/protolog/ShellProtoLogImpl.java | 30 +++++-------------- packages/SystemUI/Android.bp | 1 + 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/libs/WindowManager/Shell/Android.bp b/libs/WindowManager/Shell/Android.bp index 7960dec5080b8..9ee52ccaf3575 100644 --- a/libs/WindowManager/Shell/Android.bp +++ b/libs/WindowManager/Shell/Android.bp @@ -100,6 +100,21 @@ genrule { out: ["wm_shell_protolog.json"], } +genrule { + name: "protolog.json.gz", + srcs: [":generate-wm_shell_protolog.json"], + out: ["wmshell.protolog.json.gz"], + cmd: "$(location minigzip) -c < $(in) > $(out)", + tools: ["minigzip"], +} + +prebuilt_etc { + name: "wmshell.protolog.json.gz", + system_ext_specific: true, + src: ":protolog.json.gz", + filename_from_src: true, +} + // End ProtoLog java_library { @@ -123,9 +138,6 @@ android_library { resource_dirs: [ "res", ], - java_resources: [ - ":generate-wm_shell_protolog.json", - ], static_libs: [ "androidx.appcompat_appcompat", "androidx.arch.core_core-runtime", diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogImpl.java b/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogImpl.java index 552ebde052740..93ffb3dc8115e 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogImpl.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogImpl.java @@ -17,22 +17,14 @@ package com.android.wm.shell.protolog; import android.annotation.Nullable; -import android.content.Context; -import android.util.Log; -import com.android.internal.annotations.VisibleForTesting; import com.android.internal.protolog.BaseProtoLogImpl; import com.android.internal.protolog.ProtoLogViewerConfigReader; import com.android.internal.protolog.common.IProtoLogGroup; -import com.android.wm.shell.R; import java.io.File; -import java.io.IOException; -import java.io.InputStream; import java.io.PrintWriter; -import org.json.JSONException; - /** * A service for the ProtoLog logging system. @@ -40,8 +32,9 @@ import org.json.JSONException; public class ShellProtoLogImpl extends BaseProtoLogImpl { private static final String TAG = "ProtoLogImpl"; private static final int BUFFER_CAPACITY = 1024 * 1024; - // TODO: Get the right path for the proto log file when we initialize the shell components - private static final String LOG_FILENAME = new File("wm_shell_log.pb").getAbsolutePath(); + // TODO: find a proper location to save the protolog message file + private static final String LOG_FILENAME = "/data/misc/wmtrace/shell_log.winscope"; + private static final String VIEWER_CONFIG_FILENAME = "/system_ext/etc/wmshell.protolog.json.gz"; private static ShellProtoLogImpl sServiceInstance = null; @@ -111,18 +104,8 @@ public class ShellProtoLogImpl extends BaseProtoLogImpl { } public int startTextLogging(String[] groups, PrintWriter pw) { - try (InputStream is = - getClass().getClassLoader().getResourceAsStream("wm_shell_protolog.json")){ - mViewerConfig.loadViewerConfig(is); - return setLogging(true /* setTextLogging */, true, pw, groups); - } catch (IOException e) { - Log.i(TAG, "Unable to load log definitions: IOException while reading " - + "wm_shell_protolog. " + e); - } catch (JSONException e) { - Log.i(TAG, "Unable to load log definitions: JSON parsing exception while reading " - + "wm_shell_protolog. " + e); - } - return -1; + mViewerConfig.loadViewerConfig(pw, VIEWER_CONFIG_FILENAME); + return setLogging(true /* setTextLogging */, true, pw, groups); } public int stopTextLogging(String[] groups, PrintWriter pw) { @@ -130,7 +113,8 @@ public class ShellProtoLogImpl extends BaseProtoLogImpl { } private ShellProtoLogImpl() { - super(new File(LOG_FILENAME), null, BUFFER_CAPACITY, new ProtoLogViewerConfigReader()); + super(new File(LOG_FILENAME), VIEWER_CONFIG_FILENAME, BUFFER_CAPACITY, + new ProtoLogViewerConfigReader()); } } diff --git a/packages/SystemUI/Android.bp b/packages/SystemUI/Android.bp index df6f08df7c56c..2f5b5f456d0bb 100644 --- a/packages/SystemUI/Android.bp +++ b/packages/SystemUI/Android.bp @@ -294,5 +294,6 @@ android_app { dxflags: ["--multi-dex"], required: [ "privapp_whitelist_com.android.systemui", + "wmshell.protolog.json.gz", ], }