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