1 /**
2  * Copyright (C) 2021 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 package android.accessibilityservice;
17 
18 import java.util.AbstractMap;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Set;
23 
24 /**
25  * Interface to log accessibility trace.
26  *
27  * @hide
28  */
29 public interface AccessibilityTrace {
30     String NAME_ACCESSIBILITY_SERVICE_CONNECTION = "IAccessibilityServiceConnection";
31     String NAME_ACCESSIBILITY_SERVICE_CLIENT = "IAccessibilityServiceClient";
32     String NAME_ACCESSIBILITY_MANAGER = "IAccessibilityManager";
33     String NAME_ACCESSIBILITY_MANAGER_CLIENT = "IAccessibilityManagerClient";
34     String NAME_ACCESSIBILITY_INTERACTION_CONNECTION = "IAccessibilityInteractionConnection";
35     String NAME_ACCESSIBILITY_INTERACTION_CONNECTION_CALLBACK =
36             "IAccessibilityInteractionConnectionCallback";
37     String NAME_REMOTE_MAGNIFICATION_ANIMATION_CALLBACK = "IRemoteMagnificationAnimationCallback";
38     String NAME_MAGNIFICATION_CONNECTION = "IMagnificationConnection";
39     String NAME_MAGNIFICATION_CONNECTION_CALLBACK = "IMagnificationConnectionCallback";
40     String NAME_WINDOW_MANAGER_INTERNAL = "WindowManagerInternal";
41     String NAME_WINDOWS_FOR_ACCESSIBILITY_CALLBACK = "WindowsForAccessibilityCallback";
42     String NAME_MAGNIFICATION_CALLBACK = "MagnificationCallbacks";
43     String NAME_INPUT_FILTER = "InputFilter";
44     String NAME_GESTURE = "Gesture";
45     String NAME_ACCESSIBILITY_SERVICE = "AccessibilityService";
46     String NAME_PACKAGE_BROADCAST_RECEIVER = "PMBroadcastReceiver";
47     String NAME_USER_BROADCAST_RECEIVER = "UserBroadcastReceiver";
48     String NAME_FINGERPRINT = "FingerprintGesture";
49     String NAME_ACCESSIBILITY_INTERACTION_CLIENT = "AccessibilityInteractionClient";
50 
51     String NAME_ALL_LOGGINGS = "AllLoggings";
52     String NAME_NONE = "None";
53 
54     long FLAGS_ACCESSIBILITY_SERVICE_CONNECTION = 0x0000000000000001L;
55     long FLAGS_ACCESSIBILITY_SERVICE_CLIENT = 0x0000000000000002L;
56     long FLAGS_ACCESSIBILITY_MANAGER = 0x0000000000000004L;
57     long FLAGS_ACCESSIBILITY_MANAGER_CLIENT = 0x0000000000000008L;
58     long FLAGS_ACCESSIBILITY_INTERACTION_CONNECTION = 0x0000000000000010L;
59     long FLAGS_ACCESSIBILITY_INTERACTION_CONNECTION_CALLBACK = 0x0000000000000020L;
60     long FLAGS_REMOTE_MAGNIFICATION_ANIMATION_CALLBACK = 0x0000000000000040L;
61     long FLAGS_MAGNIFICATION_CONNECTION = 0x0000000000000080L;
62     long FLAGS_MAGNIFICATION_CONNECTION_CALLBACK = 0x0000000000000100L;
63     long FLAGS_WINDOW_MANAGER_INTERNAL = 0x0000000000000200L;
64     long FLAGS_WINDOWS_FOR_ACCESSIBILITY_CALLBACK = 0x0000000000000400L;
65     long FLAGS_MAGNIFICATION_CALLBACK = 0x0000000000000800L;
66     long FLAGS_INPUT_FILTER = 0x0000000000001000L;
67     long FLAGS_GESTURE = 0x0000000000002000L;
68     long FLAGS_ACCESSIBILITY_SERVICE = 0x0000000000004000L;
69     long FLAGS_PACKAGE_BROADCAST_RECEIVER = 0x0000000000008000L;
70     long FLAGS_USER_BROADCAST_RECEIVER = 0x0000000000010000L;
71     long FLAGS_FINGERPRINT = 0x0000000000020000L;
72     long FLAGS_ACCESSIBILITY_INTERACTION_CLIENT = 0x0000000000040000L;
73 
74     long FLAGS_LOGGING_NONE = 0x0000000000000000L;
75     long FLAGS_LOGGING_ALL = 0xFFFFFFFFFFFFFFFFL;
76 
77     long FLAGS_ACCESSIBILITY_MANAGER_CLIENT_STATES = FLAGS_ACCESSIBILITY_INTERACTION_CLIENT
78             | FLAGS_ACCESSIBILITY_SERVICE
79             | FLAGS_ACCESSIBILITY_INTERACTION_CONNECTION
80             | FLAGS_ACCESSIBILITY_INTERACTION_CONNECTION_CALLBACK;
81 
82     Map<String, Long> sNamesToFlags = Map.ofEntries(
83             new AbstractMap.SimpleEntry<String, Long>(
84                     NAME_ACCESSIBILITY_SERVICE_CONNECTION, FLAGS_ACCESSIBILITY_SERVICE_CONNECTION),
85             new AbstractMap.SimpleEntry<String, Long>(
86                     NAME_ACCESSIBILITY_SERVICE_CLIENT, FLAGS_ACCESSIBILITY_SERVICE_CLIENT),
87             new AbstractMap.SimpleEntry<String, Long>(
88                     NAME_ACCESSIBILITY_MANAGER, FLAGS_ACCESSIBILITY_MANAGER),
89             new AbstractMap.SimpleEntry<String, Long>(
90                     NAME_ACCESSIBILITY_MANAGER_CLIENT, FLAGS_ACCESSIBILITY_MANAGER_CLIENT),
91             new AbstractMap.SimpleEntry<String, Long>(
92                     NAME_ACCESSIBILITY_INTERACTION_CONNECTION,
93                     FLAGS_ACCESSIBILITY_INTERACTION_CONNECTION),
94             new AbstractMap.SimpleEntry<String, Long>(
95                     NAME_ACCESSIBILITY_INTERACTION_CONNECTION_CALLBACK,
96                     FLAGS_ACCESSIBILITY_INTERACTION_CONNECTION_CALLBACK),
97             new AbstractMap.SimpleEntry<String, Long>(
98                     NAME_REMOTE_MAGNIFICATION_ANIMATION_CALLBACK,
99                     FLAGS_REMOTE_MAGNIFICATION_ANIMATION_CALLBACK),
100             new AbstractMap.SimpleEntry<String, Long>(
101                     NAME_MAGNIFICATION_CONNECTION, FLAGS_MAGNIFICATION_CONNECTION),
102             new AbstractMap.SimpleEntry<String, Long>(
103                     NAME_MAGNIFICATION_CONNECTION_CALLBACK,
104                     FLAGS_MAGNIFICATION_CONNECTION_CALLBACK),
105             new AbstractMap.SimpleEntry<String, Long>(
106                     NAME_WINDOW_MANAGER_INTERNAL, FLAGS_WINDOW_MANAGER_INTERNAL),
107             new AbstractMap.SimpleEntry<String, Long>(
108                     NAME_WINDOWS_FOR_ACCESSIBILITY_CALLBACK,
109                     FLAGS_WINDOWS_FOR_ACCESSIBILITY_CALLBACK),
110             new AbstractMap.SimpleEntry<String, Long>(
111                     NAME_MAGNIFICATION_CALLBACK, FLAGS_MAGNIFICATION_CALLBACK),
112             new AbstractMap.SimpleEntry<String, Long>(NAME_INPUT_FILTER, FLAGS_INPUT_FILTER),
113             new AbstractMap.SimpleEntry<String, Long>(NAME_GESTURE, FLAGS_GESTURE),
114             new AbstractMap.SimpleEntry<String, Long>(
115                     NAME_ACCESSIBILITY_SERVICE, FLAGS_ACCESSIBILITY_SERVICE),
116             new AbstractMap.SimpleEntry<String, Long>(
117                     NAME_PACKAGE_BROADCAST_RECEIVER, FLAGS_PACKAGE_BROADCAST_RECEIVER),
118             new AbstractMap.SimpleEntry<String, Long>(
119                     NAME_USER_BROADCAST_RECEIVER, FLAGS_USER_BROADCAST_RECEIVER),
120             new AbstractMap.SimpleEntry<String, Long>(NAME_FINGERPRINT, FLAGS_FINGERPRINT),
121             new AbstractMap.SimpleEntry<String, Long>(
122                     NAME_ACCESSIBILITY_INTERACTION_CLIENT, FLAGS_ACCESSIBILITY_INTERACTION_CLIENT),
123             new AbstractMap.SimpleEntry<String, Long>(NAME_NONE, FLAGS_LOGGING_NONE),
124             new AbstractMap.SimpleEntry<String, Long>(NAME_ALL_LOGGINGS, FLAGS_LOGGING_ALL));
125 
126     /**
127      * Get the flags of the logging types by the given names.
128      * The names list contains logging type names in lower case.
129      */
getLoggingFlagsFromNames(List<String> names)130     static long getLoggingFlagsFromNames(List<String> names) {
131         long types = FLAGS_LOGGING_NONE;
132         for (String name : names) {
133             long flag = sNamesToFlags.get(name);
134             types |= flag;
135         }
136         return types;
137     }
138 
139     /**
140      * Get the list of the names of logging types by the given flags.
141      */
getNamesOfLoggingTypes(long flags)142     static List<String> getNamesOfLoggingTypes(long flags) {
143         List<String> list = new ArrayList<String>();
144 
145         for (Map.Entry<String, Long> entry : sNamesToFlags.entrySet()) {
146             if ((entry.getValue() & flags) != FLAGS_LOGGING_NONE) {
147                 list.add(entry.getKey());
148             }
149         }
150 
151         return list;
152     }
153 
154     /**
155      * Whether the trace is enabled for any logging type.
156      */
isA11yTracingEnabled()157     boolean isA11yTracingEnabled();
158 
159     /**
160      * Whether the trace is enabled for any of the given logging type.
161      */
isA11yTracingEnabledForTypes(long typeIdFlags)162     boolean isA11yTracingEnabledForTypes(long typeIdFlags);
163 
164     /**
165      * Get trace state to be sent to AccessibilityManager.
166      */
getTraceStateForAccessibilityManagerClientState()167     int getTraceStateForAccessibilityManagerClientState();
168 
169     /**
170      * Start tracing for the given logging types.
171      */
startTrace(long flagss)172     void startTrace(long flagss);
173 
174     /**
175      * Stop tracing.
176      */
stopTrace()177     void stopTrace();
178 
179     /**
180      * Log one trace entry.
181      * @param where A string to identify this log entry, which can be used to search through the
182      *        tracing file.
183      * @param loggingFlags Flags to identify which logging types this entry belongs to. This
184      *        can be used to filter the log entries when generating tracing file.
185      */
logTrace(String where, long loggingFlags)186     void logTrace(String where, long loggingFlags);
187 
188     /**
189      * Log one trace entry.
190      * @param where A string to identify this log entry, which can be used to filter/search
191      *        through the tracing file.
192      * @param loggingFlags Flags to identify which logging types this entry belongs to. This
193      *        can be used to filter the log entries when generating tracing file.
194      * @param callingParams The parameters for the method to be logged.
195      */
logTrace(String where, long loggingFlags, String callingParams)196     void logTrace(String where, long loggingFlags, String callingParams);
197 
198     /**
199      * Log one trace entry. Accessibility services using AccessibilityInteractionClient to
200      * make screen content related requests use this API to log entry when receive callback.
201      * @param timestamp The timestamp when a callback is received.
202      * @param where A string to identify this log entry, which can be used to filter/search
203      *        through the tracing file.
204      * @param loggingFlags Flags to identify which logging types this entry belongs to. This
205      *        can be used to filter the log entries when generating tracing file.
206      * @param callingParams The parameters for the callback.
207      * @param processId The process id of the calling component.
208      * @param threadId The threadId of the calling component.
209      * @param callingUid The calling uid of the callback.
210      * @param callStack The call stack of the callback.
211      * @param ignoreStackElements ignore these call stack element
212      */
logTrace(long timestamp, String where, long loggingFlags, String callingParams, int processId, long threadId, int callingUid, StackTraceElement[] callStack, Set<String> ignoreStackElements)213     void logTrace(long timestamp, String where, long loggingFlags, String callingParams,
214             int processId, long threadId, int callingUid, StackTraceElement[] callStack,
215             Set<String> ignoreStackElements);
216 }
217