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.internal.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. All of its dependencies
27  * must be included in services.core.wm.protologgroups build target.
28  */
29 public enum ProtoLogGroup implements IProtoLogGroup {
30     WM_ERROR(true, true, true, Consts.TAG_WM),
31     WM_DEBUG_ORIENTATION(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
32             Consts.TAG_WM),
33     WM_DEBUG_FOCUS_LIGHT(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
34             Consts.TAG_WM),
35     WM_DEBUG_BOOT(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
36             Consts.TAG_WM),
37     WM_DEBUG_RESIZE(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
38             Consts.TAG_WM),
39     WM_DEBUG_ADD_REMOVE(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
40             Consts.TAG_WM),
41     WM_DEBUG_CONFIGURATION(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
42             Consts.TAG_WM),
43     WM_DEBUG_SWITCH(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
44             Consts.TAG_WM),
45     WM_DEBUG_CONTAINERS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
46             Consts.TAG_WM),
47     WM_DEBUG_FOCUS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
48             Consts.TAG_WM),
49     WM_DEBUG_IMMERSIVE(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
50             Consts.TAG_WM),
51     WM_DEBUG_LOCKTASK(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
52             Consts.TAG_WM),
53     WM_DEBUG_STATES(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
54             Consts.TAG_WM),
55     WM_DEBUG_TASKS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
56             Consts.TAG_WM),
57     WM_DEBUG_STARTING_WINDOW(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
58             Consts.TAG_WM),
59     WM_SHOW_TRANSACTIONS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
60             Consts.TAG_WM),
61     WM_SHOW_SURFACE_ALLOC(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
62             Consts.TAG_WM),
63     WM_DEBUG_APP_TRANSITIONS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
64             Consts.TAG_WM),
65     WM_DEBUG_ANIM(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false, Consts.TAG_WM),
66     WM_DEBUG_APP_TRANSITIONS_ANIM(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
67             Consts.TAG_WM),
68     WM_DEBUG_RECENTS_ANIMATIONS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
69             Consts.TAG_WM),
70     WM_DEBUG_DRAW(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false, Consts.TAG_WM),
71     WM_DEBUG_REMOTE_ANIMATIONS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
72             Consts.TAG_WM),
73     WM_DEBUG_SCREEN_ON(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false, Consts.TAG_WM),
74     WM_DEBUG_KEEP_SCREEN_ON(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
75             Consts.TAG_WM),
76     WM_DEBUG_WINDOW_MOVEMENT(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
77             Consts.TAG_WM),
78     WM_DEBUG_IME(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
79             Consts.TAG_WM),
80     WM_DEBUG_WINDOW_ORGANIZER(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
81             Consts.TAG_WM),
82     WM_DEBUG_SYNC_ENGINE(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
83             Consts.TAG_WM),
84     WM_DEBUG_WINDOW_TRANSITIONS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
85             Consts.TAG_WM),
86     WM_DEBUG_WINDOW_TRANSITIONS_MIN(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true,
87             Consts.TAG_WM),
88     WM_DEBUG_WINDOW_INSETS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
89             Consts.TAG_WM),
90     WM_DEBUG_CONTENT_RECORDING(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true,
91             Consts.TAG_WM),
92     WM_DEBUG_WALLPAPER(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false, Consts.TAG_WM),
93     WM_DEBUG_BACK_PREVIEW(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true,
94             "CoreBackPreview"),
95     WM_DEBUG_DREAM(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true, Consts.TAG_WM),
96 
97     WM_DEBUG_DIMMER(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false, Consts.TAG_WM),
98     WM_DEBUG_TPL(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false, Consts.TAG_WM),
99     WM_DEBUG_EMBEDDED_WINDOWS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
100             Consts.TAG_WM),
101     TEST_GROUP(true, true, false, "WindowManagerProtoLogTest");
102 
103     private final boolean mEnabled;
104     private volatile boolean mLogToProto;
105     private volatile boolean mLogToLogcat;
106     private final String mTag;
107 
108     /**
109      * @param enabled     set to false to exclude all log statements for this group from
110      *                    compilation,
111      *                    they will not be available in runtime.
112      * @param logToProto  enable binary logging for the group
113      * @param logToLogcat enable text logging for the group
114      * @param tag         name of the source of the logged message
115      */
ProtoLogGroup(boolean enabled, boolean logToProto, boolean logToLogcat, String tag)116     ProtoLogGroup(boolean enabled, boolean logToProto, boolean logToLogcat, String tag) {
117         this.mEnabled = enabled;
118         this.mLogToProto = logToProto;
119         this.mLogToLogcat = logToLogcat;
120         this.mTag = tag;
121     }
122 
123     @Override
isEnabled()124     public boolean isEnabled() {
125         return mEnabled;
126     }
127 
128     @Override
isLogToProto()129     public boolean isLogToProto() {
130         return mLogToProto;
131     }
132 
133     @Override
isLogToLogcat()134     public boolean isLogToLogcat() {
135         return mLogToLogcat;
136     }
137 
138     @Override
isLogToAny()139     public boolean isLogToAny() {
140         return mLogToLogcat || mLogToProto;
141     }
142 
143     @Override
getTag()144     public String getTag() {
145         return mTag;
146     }
147 
148     @Override
setLogToProto(boolean logToProto)149     public void setLogToProto(boolean logToProto) {
150         this.mLogToProto = logToProto;
151     }
152 
153     @Override
setLogToLogcat(boolean logToLogcat)154     public void setLogToLogcat(boolean logToLogcat) {
155         this.mLogToLogcat = logToLogcat;
156     }
157 
158     @Override
getId()159     public int getId() {
160         return Consts.START_ID + this.ordinal();
161     }
162 
163     private static class Consts {
164         private static final String TAG_WM = "WindowManager";
165 
166         private static final boolean ENABLE_DEBUG = true;
167         private static final boolean ENABLE_LOG_TO_PROTO_DEBUG = true;
168         private static final int START_ID = (int) (
169                 UUID.nameUUIDFromBytes(ProtoLogGroup.class.getName().getBytes())
170                         .getMostSignificantBits() % Integer.MAX_VALUE);
171     }
172 }
173