1 /*
2  * Copyright (C) 2020 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.protolog;
18 
19 import com.android.internal.protolog.common.IProtoLogGroup;
20 
21 /**
22  * Defines logging groups for ProtoLog.
23  *
24  * This file is used by the ProtoLogTool to generate optimized logging code.
25  */
26 public enum ShellProtoLogGroup implements IProtoLogGroup {
27     // NOTE: Since we enable these from the same WM ShellCommand, these names should not conflict
28     // with those in the framework ProtoLogGroup
29     WM_SHELL_INIT(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true,
30             Consts.TAG_WM_SHELL),
31     WM_SHELL_TASK_ORG(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
32             Consts.TAG_WM_SHELL),
33     WM_SHELL_TRANSITIONS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true,
34             Consts.TAG_WM_SHELL),
35     WM_SHELL_RECENTS_TRANSITION(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true,
36             "ShellRecents"),
37     WM_SHELL_DRAG_AND_DROP(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true,
38             "ShellDragAndDrop"),
39     WM_SHELL_STARTING_WINDOW(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
40             Consts.TAG_WM_STARTING_WINDOW),
41     WM_SHELL_BACK_PREVIEW(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true,
42             "ShellBackPreview"),
43     WM_SHELL_RECENT_TASKS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
44             Consts.TAG_WM_SHELL),
45     // TODO(b/282232877): turn logToLogcat to false.
46     WM_SHELL_PICTURE_IN_PICTURE(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true,
47             Consts.TAG_WM_SHELL),
48     WM_SHELL_SPLIT_SCREEN(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true,
49             Consts.TAG_WM_SPLIT_SCREEN),
50     WM_SHELL_SYSUI_EVENTS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
51             Consts.TAG_WM_SHELL),
52     WM_SHELL_DESKTOP_MODE(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true,
53             Consts.TAG_WM_SHELL),
54     WM_SHELL_FLOATING_APPS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
55             Consts.TAG_WM_SHELL),
56     WM_SHELL_FOLDABLE(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
57             Consts.TAG_WM_SHELL),
58     WM_SHELL_BUBBLES(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
59             "Bubbles"),
60     TEST_GROUP(true, true, false, "WindowManagerShellProtoLogTest");
61 
62     private final boolean mEnabled;
63     private volatile boolean mLogToProto;
64     private volatile boolean mLogToLogcat;
65     private final String mTag;
66 
67     /**
68      * @param enabled     set to false to exclude all log statements for this group from
69      *                    compilation,
70      *                    they will not be available in runtime.
71      * @param logToProto  enable binary logging for the group
72      * @param logToLogcat enable text logging for the group
73      * @param tag         name of the source of the logged message
74      */
ShellProtoLogGroup(boolean enabled, boolean logToProto, boolean logToLogcat, String tag)75     ShellProtoLogGroup(boolean enabled, boolean logToProto, boolean logToLogcat, String tag) {
76         this.mEnabled = enabled;
77         this.mLogToProto = logToProto;
78         this.mLogToLogcat = logToLogcat;
79         this.mTag = tag;
80     }
81 
82     @Override
isEnabled()83     public boolean isEnabled() {
84         return mEnabled;
85     }
86 
87     @Override
isLogToProto()88     public boolean isLogToProto() {
89         return mLogToProto;
90     }
91 
92     @Override
isLogToLogcat()93     public boolean isLogToLogcat() {
94         return mLogToLogcat;
95     }
96 
97     @Override
isLogToAny()98     public boolean isLogToAny() {
99         return mLogToLogcat || mLogToProto;
100     }
101 
102     @Override
getTag()103     public String getTag() {
104         return mTag;
105     }
106 
107     @Override
setLogToProto(boolean logToProto)108     public void setLogToProto(boolean logToProto) {
109         this.mLogToProto = logToProto;
110     }
111 
112     @Override
setLogToLogcat(boolean logToLogcat)113     public void setLogToLogcat(boolean logToLogcat) {
114         this.mLogToLogcat = logToLogcat;
115     }
116 
117     private static class Consts {
118         private static final String TAG_WM_SHELL = "WindowManagerShell";
119         private static final String TAG_WM_STARTING_WINDOW = "ShellStartingWindow";
120         private static final String TAG_WM_SPLIT_SCREEN = "ShellSplitScreen";
121 
122         private static final boolean ENABLE_DEBUG = true;
123         private static final boolean ENABLE_LOG_TO_PROTO_DEBUG = true;
124     }
125 }
126