Debian Codegraph @

libs/WindowManager/Shell/src/com/android/wm/shell/ProtoLogController.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.android.wm.shell;
18
19 import com.android.wm.shell.protolog.ShellProtoLogImpl;
20 import com.android.wm.shell.sysui.ShellCommandHandler;
21 import com.android.wm.shell.sysui.ShellInit;
22
23 import java.io.PrintWriter;
24 import java.util.Arrays;
25
26 /**
27 * Controls the {@link ShellProtoLogImpl} in WMShell via adb shell commands.
28 *
29 * Use with {@code adb shell dumpsys activity service SystemUIService WMShell protolog ...}.
30 */
31 public class ProtoLogController implements ShellCommandHandler.ShellCommandActionHandler {
32 private final ShellCommandHandler mShellCommandHandler;
33 private final ShellProtoLogImpl mShellProtoLog;
34
35 public ProtoLogController(ShellInit shellInit,
36 ShellCommandHandler shellCommandHandler) {
37 shellInit.addInitCallback(this::onInit, this);
38 mShellCommandHandler = shellCommandHandler;
39 mShellProtoLog = ShellProtoLogImpl.getSingleInstance();
40 }
41
42 void onInit() {
43 mShellCommandHandler.addCommandCallback("protolog", this, this);
44 }
45
46 @Override
47 public boolean onShellCommand(String[] args, PrintWriter pw) {
48 switch (args[0]) {
49 case "status": {
50 pw.println(mShellProtoLog.getStatus());
51 return true;
52 }
53 case "start": {
54 mShellProtoLog.startProtoLog(pw);
55 return true;
56 }
57 case "stop": {
58 mShellProtoLog.stopProtoLog(pw, true /* writeToFile */);
59 return true;
60 }
61 case "enable-text": {
62 String[] groups = Arrays.copyOfRange(args, 1, args.length);
63 int result = mShellProtoLog.startTextLogging(groups, pw);
64 if (result == 0) {
65 pw.println("Starting logging on groups: " + Arrays.toString(groups));
66 return true;
67 }
68 return false;
69 }
70 case "disable-text": {
71 String[] groups = Arrays.copyOfRange(args, 1, args.length);
72 int result = mShellProtoLog.stopTextLogging(groups, pw);
73 if (result == 0) {
74 pw.println("Stopping logging on groups: " + Arrays.toString(groups));
75 return true;
76 }
77 return false;
78 }
79 case "enable": {
80 String[] groups = Arrays.copyOfRange(args, 1, args.length);
81 return mShellProtoLog.startTextLogging(groups, pw) == 0;
82 }
83 case "disable": {
84 String[] groups = Arrays.copyOfRange(args, 1, args.length);
85 return mShellProtoLog.stopTextLogging(groups, pw) == 0;
86 }
87 default: {
88 pw.println("Invalid command: " + args[0]);
89 printShellCommandHelp(pw, "");
90 return false;
91 }
92 }
93 }
94
95 @Override
96 public void printShellCommandHelp(PrintWriter pw, String prefix) {
97 pw.println(prefix + "status");
98 pw.println(prefix + " Get current ProtoLog status.");
99 pw.println(prefix + "start");
100 pw.println(prefix + " Start proto logging.");
101 pw.println(prefix + "stop");
102 pw.println(prefix + " Stop proto logging and flush to file.");
103 pw.println(prefix + "enable [group...]");
104 pw.println(prefix + " Enable proto logging for given groups.");
105 pw.println(prefix + "disable [group...]");
106 pw.println(prefix + " Disable proto logging for given groups.");
107 pw.println(prefix + "enable-text [group...]");
108 pw.println(prefix + " Enable logcat logging for given groups.");
109 pw.println(prefix + "disable-text [group...]");
110 pw.println(prefix + " Disable logcat logging for given groups.");
111 }
112 }