• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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 android.view.accessibility;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.compat.annotation.UnsupportedAppUsage;
22 import android.os.Build;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 import android.text.TextUtils;
26 import android.util.Log;
27 
28 import com.android.internal.util.BitUtils;
29 
30 import java.lang.annotation.Retention;
31 import java.lang.annotation.RetentionPolicy;
32 import java.util.ArrayList;
33 import java.util.List;
34 
35 /**
36  * <p>
37  * This class represents accessibility events that are sent by the system when
38  * something notable happens in the user interface. For example, when a
39  * {@link android.widget.Button} is clicked, a {@link android.view.View} is focused, etc.
40  * </p>
41  * <p>
42  * An accessibility event is fired by an individual view which populates the event with
43  * data for its state and requests from its parent to send the event to interested
44  * parties. The parent can optionally modify or even block the event based on its broader
45  * understanding of the user interface's context.
46  * </p>
47  * <p>
48  * The main purpose of an accessibility event is to communicate changes in the UI to an
49  * {@link android.accessibilityservice.AccessibilityService}. The service may then inspect,
50  * if needed the user interface by examining the View hierarchy, as represented by a tree of
51  * {@link AccessibilityNodeInfo}s (snapshot of a View state)
52  * which can be used for exploring the window content. Note that the privilege for accessing
53  * an event's source, thus the window content, has to be explicitly requested. For more
54  * details refer to {@link android.accessibilityservice.AccessibilityService}. If an
55  * accessibility service has not requested to retrieve the window content the event will
56  * not contain reference to its source. Also for events of type
57  * {@link #TYPE_NOTIFICATION_STATE_CHANGED} the source is never available.
58  * </p>
59  * <p>
60  * This class represents various semantically different accessibility event
61  * types. Each event type has an associated set of related properties. In other
62  * words, each event type is characterized via a subset of the properties exposed
63  * by this class. For each event type there is a corresponding constant defined
64  * in this class. Follows a specification of the event types and their associated properties:
65  * </p>
66  * <div class="special reference">
67  * <h3>Developer Guides</h3>
68  * <p>For more information about creating and processing AccessibilityEvents, read the
69  * <a href="{@docRoot}guide/topics/ui/accessibility/index.html">Accessibility</a>
70  * developer guide.</p>
71  * </div>
72  * <p>
73  * <b>VIEW TYPES</b></br>
74  * </p>
75  * <p>
76  * <b>View clicked</b> - represents the event of clicking on a {@link android.view.View}
77  * like {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc.</br>
78  * <em>Type:</em>{@link #TYPE_VIEW_CLICKED}</br>
79  * <em>Properties:</em></br>
80  * <ul>
81  *   <li>{@link #getEventType()} - The type of the event.</li>
82  *   <li>{@link #getSource()} - The source info (for registered clients).</li>
83  *   <li>{@link #getClassName()} - The class name of the source.</li>
84  *   <li>{@link #getPackageName()} - The package name of the source.</li>
85  *   <li>{@link #getEventTime()}  - The event time.</li>
86  * </ul>
87  * </p>
88  * <p>
89  * <b>View long clicked</b> - represents the event of long clicking on a {@link android.view.View}
90  * like {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc </br>
91  * <em>Type:</em>{@link #TYPE_VIEW_LONG_CLICKED}</br>
92  * <em>Properties:</em></br>
93  * <ul>
94  *   <li>{@link #getEventType()} - The type of the event.</li>
95  *   <li>{@link #getSource()} - The source info (for registered clients).</li>
96  *   <li>{@link #getClassName()} - The class name of the source.</li>
97  *   <li>{@link #getPackageName()} - The package name of the source.</li>
98  *   <li>{@link #getEventTime()}  - The event time.</li>
99  * </ul>
100  * </p>
101  * <p>
102  * <b>View selected</b> - represents the event of selecting an item usually in
103  * the context of an {@link android.widget.AdapterView}.</br>
104  * <em>Type:</em> {@link #TYPE_VIEW_SELECTED}</br>
105  * <em>Properties:</em></br>
106  * <ul>
107  *   <li>{@link #getEventType()} - The type of the event.</li>
108  *   <li>{@link #getSource()} - The source info (for registered clients).</li>
109  *   <li>{@link #getClassName()} - The class name of the source.</li>
110  *   <li>{@link #getPackageName()} - The package name of the source.</li>
111  *   <li>{@link #getEventTime()}  - The event time.</li>
112  * </ul>
113  * </p>
114  * <p>
115  * <b>View focused</b> - represents the event of focusing a
116  * {@link android.view.View}.</br>
117  * <em>Type:</em> {@link #TYPE_VIEW_FOCUSED}</br>
118  * <em>Properties:</em></br>
119  * <ul>
120  *   <li>{@link #getEventType()} - The type of the event.</li>
121  *   <li>{@link #getSource()} - The source info (for registered clients).</li>
122  *   <li>{@link #getClassName()} - The class name of the source.</li>
123  *   <li>{@link #getPackageName()} - The package name of the source.</li>
124  *   <li>{@link #getEventTime()}  - The event time.</li>
125  * </ul>
126  * </p>
127  * <p>
128  * <b>View text changed</b> - represents the event of changing the text of an
129  * {@link android.widget.EditText}.</br>
130  * <em>Type:</em> {@link #TYPE_VIEW_TEXT_CHANGED}</br>
131  * <em>Properties:</em></br>
132  * <ul>
133  *   <li>{@link #getEventType()} - The type of the event.</li>
134  *   <li>{@link #getSource()} - The source info (for registered clients).</li>
135  *   <li>{@link #getClassName()} - The class name of the source.</li>
136  *   <li>{@link #getPackageName()} - The package name of the source.</li>
137  *   <li>{@link #getEventTime()}  - The event time.</li>
138  *   <li>{@link #getText()} - The new text of the source.</li>
139  *   <li>{@link #getBeforeText()} - The text of the source before the change.</li>
140  *   <li>{@link #getFromIndex()} - The text change start index.</li>
141  *   <li>{@link #getAddedCount()} - The number of added characters.</li>
142  *   <li>{@link #getRemovedCount()} - The number of removed characters.</li>
143  * </ul>
144  * </p>
145  * <p>
146  * <b>View text selection changed</b> - represents the event of changing the text
147  * selection of an {@link android.widget.EditText}.</br>
148  * <em>Type:</em> {@link #TYPE_VIEW_TEXT_SELECTION_CHANGED} </br>
149  * <em>Properties:</em></br>
150  * <ul>
151  *   <li>{@link #getEventType()} - The type of the event.</li>
152  *   <li>{@link #getSource()} - The source info (for registered clients).</li>
153  *   <li>{@link #getClassName()} - The class name of the source.</li>
154  *   <li>{@link #getPackageName()} - The package name of the source.</li>
155  *   <li>{@link #getEventTime()}  - The event time.</li>
156  * </ul>
157  * </p>
158  * <b>View text traversed at movement granularity</b> - represents the event of traversing the
159  * text of a view at a given granularity. For example, moving to the next word.</br>
160  * <em>Type:</em> {@link #TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY} </br>
161  * <em>Properties:</em></br>
162  * <ul>
163  *   <li>{@link #getEventType()} - The type of the event.</li>
164  *   <li>{@link #getSource()} - The source info (for registered clients).</li>
165  *   <li>{@link #getClassName()} - The class name of the source.</li>
166  *   <li>{@link #getPackageName()} - The package name of the source.</li>
167  *   <li>{@link #getEventTime()}  - The event time.</li>
168  *   <li>{@link #getMovementGranularity()} - Sets the granularity at which a view's text
169  *       was traversed.</li>
170  *   <li>{@link #getText()} -  The text of the source's sub-tree.</li>
171  *   <li>{@link #getFromIndex()} - The start the text that was skipped over in this movement.
172  *       This is the starting point when moving forward through the text, but not when moving
173  *       back.</li>
174  *   <li>{@link #getToIndex()} - The end of the text that was skipped over in this movement.
175  *       This is the ending point when moving forward through the text, but not when moving
176  *       back.</li>
177  *   <li>{@link #getAction()} - Gets traversal action which specifies the direction.</li>
178  * </ul>
179  * </p>
180  * <p>
181  * <b>View scrolled</b> - represents the event of scrolling a view. </br>
182  * <em>Type:</em> {@link #TYPE_VIEW_SCROLLED}</br>
183  * <em>Properties:</em></br>
184  * <ul>
185  *   <li>{@link #getEventType()} - The type of the event.</li>
186  *   <li>{@link #getSource()} - The source info (for registered clients).</li>
187  *   <li>{@link #getClassName()} - The class name of the source.</li>
188  *   <li>{@link #getPackageName()} - The package name of the source.</li>
189  *   <li>{@link #getEventTime()}  - The event time.</li>
190  *   <li>{@link #getScrollDeltaX()} - The difference in the horizontal position.</li>
191  *   <li>{@link #getScrollDeltaY()} - The difference in the vertical position.</li>
192  * </ul>
193  * </p>
194  * <p>
195  * <b>TRANSITION TYPES</b></br>
196  * </p>
197  * <p>
198  * <b>Window state changed</b> - represents the event of a change to a section of
199  * the user interface that is visually distinct. Should be sent from either the
200  * root view of a window or from a view that is marked as a pane
201  * {@link android.view.View#setAccessibilityPaneTitle(CharSequence)}. Note that changes
202  * to true windows are represented by {@link #TYPE_WINDOWS_CHANGED}.</br>
203  * <em>Type:</em> {@link #TYPE_WINDOW_STATE_CHANGED}</br>
204  * <em>Properties:</em></br>
205  * <ul>
206  *   <li>{@link #getEventType()} - The type of the event.</li>
207  *   <li>{@link #getContentChangeTypes()} - The type of state changes.</li>
208  *   <li>{@link #getSource()} - The source info (for registered clients).</li>
209  *   <li>{@link #getClassName()} - The class name of the source.</li>
210  *   <li>{@link #getPackageName()} - The package name of the source.</li>
211  *   <li>{@link #getEventTime()}  - The event time.</li>
212  *   <li>{@link #getText()} - The text of the source's sub-tree, including the pane titles.</li>
213  * </ul>
214  * </p>
215  * <p>
216  * <b>Window content changed</b> - represents the event of change in the
217  * content of a window. This change can be adding/removing view, changing
218  * a view size, etc.</br>
219  * </p>
220  * <p>
221  * <em>Type:</em> {@link #TYPE_WINDOW_CONTENT_CHANGED}</br>
222  * <em>Properties:</em></br>
223  * <ul>
224  *   <li>{@link #getEventType()} - The type of the event.</li>
225  *   <li>{@link #getContentChangeTypes()} - The type of content changes.</li>
226  *   <li>{@link #getSource()} - The source info (for registered clients).</li>
227  *   <li>{@link #getClassName()} - The class name of the source.</li>
228  *   <li>{@link #getPackageName()} - The package name of the source.</li>
229  *   <li>{@link #getEventTime()}  - The event time.</li>
230  * </ul>
231  * </p>
232  * <p>
233  * <b>Windows changed</b> - represents a change in the windows shown on
234  * the screen such as a window appeared, a window disappeared, a window size changed,
235  * a window layer changed, etc. These events should only come from the system, which is responsible
236  * for managing windows. The list of windows is available from
237  * {@link android.accessibilityservice.AccessibilityService#getWindows()}.
238  * For regions of the user interface that are presented as windows but are
239  * controlled by an app's process, use {@link #TYPE_WINDOW_STATE_CHANGED}.</br>
240  * <em>Type:</em> {@link #TYPE_WINDOWS_CHANGED}</br>
241  * <em>Properties:</em></br>
242  * <ul>
243  *   <li>{@link #getEventType()} - The type of the event.</li>
244  *   <li>{@link #getEventTime()} - The event time.</li>
245  *   <li>{@link #getWindowChanges()}</li> - The specific change to the source window
246  * </ul>
247  * <em>Note:</em> You can retrieve the {@link AccessibilityWindowInfo} for the window
248  * source of the event by looking through the list returned by
249  * {@link android.accessibilityservice.AccessibilityService#getWindows()} for the window whose ID
250  * matches {@link #getWindowId()}.
251  * </p>
252  * <p>
253  * <b>NOTIFICATION TYPES</b></br>
254  * </p>
255  * <p>
256  * <b>Notification state changed</b> - represents the event showing a transient piece of information
257  * to the user. This information may be a {@link android.app.Notification} or
258  * {@link android.widget.Toast}.</br>
259  * <em>Type:</em> {@link #TYPE_NOTIFICATION_STATE_CHANGED}</br>
260  * <em>Properties:</em></br>
261  * <ul>
262  *   <li>{@link #getEventType()} - The type of the event.</li>
263  *   <li>{@link #getClassName()} - The class name of the source.</li>
264  *   <li>{@link #getPackageName()} - The package name of the source.</li>
265  *   <li>{@link #getEventTime()}  - The event time.</li>
266  *   <li>{@link #getParcelableData()} - The posted {@link android.app.Notification}, if
267  *   applicable.</li>
268  *   <li>{@link #getText()} - Displayed text of the {@link android.widget.Toast}, if applicable,
269  *   or may contain text from the {@link android.app.Notification}, although
270  *   {@link #getParcelableData()} is a richer set of data for {@link android.app.Notification}.</li>
271  * </ul>
272  * </p>
273  * <p>
274  * <b>EXPLORATION TYPES</b></br>
275  * </p>
276  * <p>
277  * <b>View hover enter</b> - represents the event of beginning to hover
278  * over a {@link android.view.View}. The hover may be generated via
279  * exploring the screen by touch or via a pointing device.</br>
280  * <em>Type:</em> {@link #TYPE_VIEW_HOVER_ENTER}</br>
281  * <em>Properties:</em></br>
282  * <ul>
283  *   <li>{@link #getEventType()} - The type of the event.</li>
284  *   <li>{@link #getSource()} - The source info (for registered clients).</li>
285  *   <li>{@link #getClassName()} - The class name of the source.</li>
286  *   <li>{@link #getPackageName()} - The package name of the source.</li>
287  *   <li>{@link #getEventTime()}  - The event time.</li>
288  * </ul>
289  * </p>
290  * <b>View hover exit</b> - represents the event of stopping to hover
291  * over a {@link android.view.View}. The hover may be generated via
292  * exploring the screen by touch or via a pointing device.</br>
293  * <em>Type:</em> {@link #TYPE_VIEW_HOVER_EXIT}</br>
294  * <em>Properties:</em></br>
295  * <ul>
296  *   <li>{@link #getEventType()} - The type of the event.</li>
297  *   <li>{@link #getSource()} - The source info (for registered clients).</li>
298  *   <li>{@link #getClassName()} - The class name of the source.</li>
299  *   <li>{@link #getPackageName()} - The package name of the source.</li>
300  *   <li>{@link #getEventTime()}  - The event time.</li>
301  * </ul>
302  * </p>
303  * <p>
304  * <b>Touch interaction start</b> - represents the event of starting a touch
305  * interaction, which is the user starts touching the screen.</br>
306  * <em>Type:</em> {@link #TYPE_TOUCH_INTERACTION_START}</br>
307  * <em>Properties:</em></br>
308  * <ul>
309  *   <li>{@link #getEventType()} - The type of the event.</li>
310  * </ul>
311  * <em>Note:</em> This event is fired only by the system and is not passed to the
312  * view tree to be populated.</br>
313  * </p>
314  * <p>
315  * <b>Touch interaction end</b> - represents the event of ending a touch
316  * interaction, which is the user stops touching the screen.</br>
317  * <em>Type:</em> {@link #TYPE_TOUCH_INTERACTION_END}</br>
318  * <em>Properties:</em></br>
319  * <ul>
320  *   <li>{@link #getEventType()} - The type of the event.</li>
321  * </ul>
322  * <em>Note:</em> This event is fired only by the system and is not passed to the
323  * view tree to be populated.</br>
324  * </p>
325  * <p>
326  * <b>Touch exploration gesture start</b> - represents the event of starting a touch
327  * exploring gesture.</br>
328  * <em>Type:</em> {@link #TYPE_TOUCH_EXPLORATION_GESTURE_START}</br>
329  * <em>Properties:</em></br>
330  * <ul>
331  *   <li>{@link #getEventType()} - The type of the event.</li>
332  * </ul>
333  * <em>Note:</em> This event is fired only by the system and is not passed to the
334  * view tree to be populated.</br>
335  * </p>
336  * <p>
337  * <b>Touch exploration gesture end</b> - represents the event of ending a touch
338  * exploring gesture.</br>
339  * <em>Type:</em> {@link #TYPE_TOUCH_EXPLORATION_GESTURE_END}</br>
340  * <em>Properties:</em></br>
341  * <ul>
342  *   <li>{@link #getEventType()} - The type of the event.</li>
343  * </ul>
344  * <em>Note:</em> This event is fired only by the system and is not passed to the
345  * view tree to be populated.</br>
346  * </p>
347  * <p>
348  * <b>Touch gesture detection start</b> - represents the event of starting a user
349  * gesture detection.</br>
350  * <em>Type:</em> {@link #TYPE_GESTURE_DETECTION_START}</br>
351  * <em>Properties:</em></br>
352  * <ul>
353  *   <li>{@link #getEventType()} - The type of the event.</li>
354  * </ul>
355  * <em>Note:</em> This event is fired only by the system and is not passed to the
356  * view tree to be populated.</br>
357  * </p>
358  * <p>
359  * <b>Touch gesture detection end</b> - represents the event of ending a user
360  * gesture detection.</br>
361  * <em>Type:</em> {@link #TYPE_GESTURE_DETECTION_END}</br>
362  * <em>Properties:</em></br>
363  * <ul>
364  *   <li>{@link #getEventType()} - The type of the event.</li>
365  * </ul>
366  * <em>Note:</em> This event is fired only by the system and is not passed to the
367  * view tree to be populated.</br>
368  * </p>
369  * <p>
370  * <b>MISCELLANEOUS TYPES</b></br>
371  * </p>
372  * <p>
373  * <b>Announcement</b> - represents the event of an application requesting a screen reader to make
374  * an announcement. Because the event carries no semantic meaning, this event is appropriate only
375  * in exceptional situations where additional screen reader output is needed but other types of
376  * accessibility services do not need to be aware of the change.</br>
377  * <em>Type:</em> {@link #TYPE_ANNOUNCEMENT}</br>
378  * <em>Properties:</em></br>
379  * <ul>
380  *   <li>{@link #getEventType()} - The type of the event.</li>
381  *   <li>{@link #getSource()} - The source info (for registered clients).</li>
382  *   <li>{@link #getClassName()} - The class name of the source.</li>
383  *   <li>{@link #getPackageName()} - The package name of the source.</li>
384  *   <li>{@link #getEventTime()}  - The event time.</li>
385  *   <li>{@link #getText()} - The text of the announcement.</li>
386  * </ul>
387  * </p>
388   * <p>
389  * <b>speechStateChanged</b>
390  * <em>Type:</em> {@link #TYPE_SPEECH_STATE_CHANGE}</br>
391  * Represents a change in the speech state defined by the
392  * bit mask of the speech state change types.
393  * A change in the speech state occurs when an application wants to signal that
394  * it is either speaking or listening for human speech.
395  * This event helps avoid conflicts where two applications want to speak or one listens
396  * when another speaks.
397  * When sending this event, the sender should ensure that  the accompanying state change types
398  * make sense. For example, the sender should not send
399  * {@link #SPEECH_STATE_SPEAKING_START} and {@link #SPEECH_STATE_SPEAKING_END} together.
400  * <em>Properties:</em></br>
401  * <ul>
402  *   <li>{@link #getSpeechStateChangeTypes()} - The type of state changes</li>
403  *   <li>{@link #getPackageName()} - The package name of the source.</li>
404  *   <li>{@link #getEventTime()}  - The event time.</li>
405  * </ul>
406  * </p>
407  *
408  * @see android.view.accessibility.AccessibilityManager
409  * @see android.accessibilityservice.AccessibilityService
410  * @see AccessibilityNodeInfo
411  */
412 public final class AccessibilityEvent extends AccessibilityRecord implements Parcelable {
413     private static final String LOG_TAG = "AccessibilityEvent";
414 
415     private static final boolean DEBUG = Log.isLoggable(LOG_TAG, Log.DEBUG) && Build.IS_DEBUGGABLE;
416 
417     /** @hide */
418     public static final boolean DEBUG_ORIGIN = false;
419 
420     /**
421      * Invalid selection/focus position.
422      *
423      * @see #getCurrentItemIndex()
424      */
425     public static final int INVALID_POSITION = -1;
426 
427     /**
428      * Maximum length of the text fields.
429      *
430      * @see #getBeforeText()
431      * @see #getText()
432      * </br>
433      * Note: This constant is no longer needed since there
434      *       is no limit on the length of text that is contained
435      *       in an accessibility event anymore.
436      */
437     @Deprecated
438     public static final int MAX_TEXT_LENGTH = 500;
439 
440     /**
441      * Represents the event of clicking on a {@link android.view.View} like
442      * {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc.
443      */
444     public static final int TYPE_VIEW_CLICKED = 0x00000001;
445 
446     /**
447      * Represents the event of long clicking on a {@link android.view.View} like
448      * {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc.
449      */
450     public static final int TYPE_VIEW_LONG_CLICKED = 0x00000002;
451 
452     /**
453      * Represents the event of selecting an item usually in the context of an
454      * {@link android.widget.AdapterView}.
455      */
456     public static final int TYPE_VIEW_SELECTED = 0x00000004;
457 
458     /**
459      * Represents the event of setting input focus of a {@link android.view.View}.
460      */
461     public static final int TYPE_VIEW_FOCUSED = 0x00000008;
462 
463     /**
464      * Represents the event of changing the text of an {@link android.widget.EditText}.
465      */
466     public static final int TYPE_VIEW_TEXT_CHANGED = 0x00000010;
467 
468     /**
469      * Represents the event of a change to a visually distinct section of the user interface.
470      * These events should only be dispatched from {@link android.view.View}s that have
471      * accessibility pane titles, and replaces {@link #TYPE_WINDOW_CONTENT_CHANGED} for those
472      * sources. Details about the change are available from {@link #getContentChangeTypes()}.
473      */
474     public static final int TYPE_WINDOW_STATE_CHANGED = 0x00000020;
475 
476     /**
477      * Represents the event showing a {@link android.app.Notification}.
478      */
479     public static final int TYPE_NOTIFICATION_STATE_CHANGED = 0x00000040;
480 
481     /**
482      * Represents the event of a hover enter over a {@link android.view.View}.
483      */
484     public static final int TYPE_VIEW_HOVER_ENTER = 0x00000080;
485 
486     /**
487      * Represents the event of a hover exit over a {@link android.view.View}.
488      */
489     public static final int TYPE_VIEW_HOVER_EXIT = 0x00000100;
490 
491     /**
492      * Represents the event of starting a touch exploration gesture.
493      */
494     public static final int TYPE_TOUCH_EXPLORATION_GESTURE_START = 0x00000200;
495 
496     /**
497      * Represents the event of ending a touch exploration gesture.
498      */
499     public static final int TYPE_TOUCH_EXPLORATION_GESTURE_END = 0x00000400;
500 
501     /**
502      * Represents the event of changing the content of a window and more
503      * specifically the sub-tree rooted at the event's source.
504      */
505     public static final int TYPE_WINDOW_CONTENT_CHANGED = 0x00000800;
506 
507     /**
508      * Represents the event of scrolling a view. This event type is generally not sent directly.
509      * @see android.view.View#onScrollChanged(int, int, int, int)
510      */
511     public static final int TYPE_VIEW_SCROLLED = 0x00001000;
512 
513     /**
514      * Represents the event of changing the selection in an {@link android.widget.EditText}.
515      */
516     public static final int TYPE_VIEW_TEXT_SELECTION_CHANGED = 0x00002000;
517 
518     /**
519      * Represents the event of an application making an announcement.
520      */
521     public static final int TYPE_ANNOUNCEMENT = 0x00004000;
522 
523     /**
524      * Represents the event of gaining accessibility focus.
525      */
526     public static final int TYPE_VIEW_ACCESSIBILITY_FOCUSED = 0x00008000;
527 
528     /**
529      * Represents the event of clearing accessibility focus.
530      */
531     public static final int TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED = 0x00010000;
532 
533     /**
534      * Represents the event of traversing the text of a view at a given movement granularity.
535      */
536     public static final int TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY = 0x00020000;
537 
538     /**
539      * Represents the event of beginning gesture detection.
540      */
541     public static final int TYPE_GESTURE_DETECTION_START = 0x00040000;
542 
543     /**
544      * Represents the event of ending gesture detection.
545      */
546     public static final int TYPE_GESTURE_DETECTION_END = 0x00080000;
547 
548     /**
549      * Represents the event of the user starting to touch the screen.
550      */
551     public static final int TYPE_TOUCH_INTERACTION_START = 0x00100000;
552 
553     /**
554      * Represents the event of the user ending to touch the screen.
555      */
556     public static final int TYPE_TOUCH_INTERACTION_END = 0x00200000;
557 
558     /**
559      * Represents the event change in the system windows shown on the screen. This event type should
560      * only be dispatched by the system.
561      */
562     public static final int TYPE_WINDOWS_CHANGED = 0x00400000;
563 
564     /**
565      * Represents the event of a context click on a {@link android.view.View}.
566      */
567     public static final int TYPE_VIEW_CONTEXT_CLICKED = 0x00800000;
568 
569     /**
570      * Represents the event of the assistant currently reading the users screen context.
571      */
572     public static final int TYPE_ASSIST_READING_CONTEXT = 0x01000000;
573 
574     /**
575      * Represents a change in the speech state defined by the speech state change types.
576      * A change in the speech state occurs when an application wants to signal that it is either
577      * speaking or listening for human speech.
578      * This event helps avoid conflicts where two applications want to speak or one listens
579      * when another speaks.
580      * When sending this event, the sender should ensure that  the accompanying state change types
581      * make sense. For example, the sender should not send
582      * {@link #SPEECH_STATE_SPEAKING_START} and {@link #SPEECH_STATE_SPEAKING_END} together.
583      * @see #SPEECH_STATE_SPEAKING_START
584      * @see #SPEECH_STATE_SPEAKING_END
585      * @see #SPEECH_STATE_LISTENING_START
586      * @see #SPEECH_STATE_LISTENING_END
587      * @see #getSpeechStateChangeTypes
588      * @see #setSpeechStateChangeTypes
589      */
590     public static final int TYPE_SPEECH_STATE_CHANGE = 0x02000000;
591 
592     /**
593      * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event: The type of change is not
594      * defined.
595      */
596     public static final int CONTENT_CHANGE_TYPE_UNDEFINED = 0x00000000;
597 
598     /**
599      * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
600      * One or more content changes occurred in the the subtree rooted at the source node,
601      * or the subtree's structure changed when a node was added or removed.
602      */
603     public static final int CONTENT_CHANGE_TYPE_SUBTREE = 0x00000001;
604 
605     /**
606      * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
607      * The node's text changed.
608      */
609     public static final int CONTENT_CHANGE_TYPE_TEXT = 0x00000002;
610 
611     /**
612      * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
613      * The node's content description changed.
614      */
615     public static final int CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION = 0x00000004;
616 
617     /**
618      * Change type for {@link #TYPE_WINDOW_STATE_CHANGED} event:
619      * The node's pane title changed.
620      * <p>
621      * If this makes the pane appear, {@link #CONTENT_CHANGE_TYPE_PANE_APPEARED} is sent
622      * instead. If this makes the pane disappear, {@link #CONTENT_CHANGE_TYPE_PANE_DISAPPEARED}
623      * is sent.
624      *
625      */
626     public static final int CONTENT_CHANGE_TYPE_PANE_TITLE = 0x00000008;
627 
628     /**
629      * Change type for {@link #TYPE_WINDOW_STATE_CHANGED} event:
630      * The node has a pane title, and either just appeared or just was assigned a title when it
631      * had none before.
632      */
633     public static final int CONTENT_CHANGE_TYPE_PANE_APPEARED = 0x00000010;
634 
635     /**
636      * Change type for {@link #TYPE_WINDOW_STATE_CHANGED} event:
637      * Can mean one of two slightly different things. The primary meaning is that the node has
638      * a pane title, and was removed from the node hierarchy. It will also be sent if the pane
639      * title is set to {@code null} after it contained a title.
640      * No source will be returned if the node is no longer on the screen. To make the change more
641      * clear for the user, the first entry in {@link #getText()} will return the value that would
642      * have been returned by {@code getSource().getPaneTitle()}.
643      */
644     public static final int CONTENT_CHANGE_TYPE_PANE_DISAPPEARED = 0x00000020;
645 
646     /**
647      * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
648      * state description of the node as returned by
649      * {@link AccessibilityNodeInfo#getStateDescription} changed. If part of the state description
650      * changes, the changed part can be put into event text. For example, if state description
651      * changed from "on, wifi signal full" to "on, wifi three bars", "wifi three bars" can be put
652      * into the event text.
653      */
654     public static final int CONTENT_CHANGE_TYPE_STATE_DESCRIPTION = 0x00000040;
655 
656     /**
657      * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
658      * A drag has started while accessibility is enabled. This is either via an
659      * AccessibilityAction, or via touch events. This is sent from the source that initiated the
660      * drag.
661      *
662      * @see AccessibilityNodeInfo.AccessibilityAction#ACTION_DRAG_START
663      */
664     public static final int CONTENT_CHANGE_TYPE_DRAG_STARTED = 0x00000080;
665 
666     /**
667      * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
668      * A drag in with accessibility enabled has ended. This means the content has been
669      * successfully dropped. This is sent from the target that accepted the dragged content.
670      *
671      * @see AccessibilityNodeInfo.AccessibilityAction#ACTION_DRAG_DROP
672      */
673     public static final int CONTENT_CHANGE_TYPE_DRAG_DROPPED = 0x00000100;
674 
675     /**
676      * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
677      * A drag in with accessibility enabled has ended. This means the content has been
678      * unsuccessfully dropped, the user has canceled the action via an AccessibilityAction, or
679      * no drop has been detected within a timeout and the drag was automatically cancelled. This is
680      * sent from the source that initiated the drag.
681      *
682      * @see AccessibilityNodeInfo.AccessibilityAction#ACTION_DRAG_CANCEL
683      */
684     public static final int CONTENT_CHANGE_TYPE_DRAG_CANCELLED = 0x0000200;
685 
686     /** Change type for {@link #TYPE_SPEECH_STATE_CHANGE} event: another service is speaking. */
687     public static final int SPEECH_STATE_SPEAKING_START = 0x00000001;
688 
689     /**
690      * Change type for {@link #TYPE_SPEECH_STATE_CHANGE} event: another service is no longer
691      * speaking.
692      */
693     public static final int SPEECH_STATE_SPEAKING_END = 0x00000002;
694 
695     /**
696      * Change type for {@link #TYPE_SPEECH_STATE_CHANGE} event: another service is listening to the
697      * microphone.
698      */
699     public static final int SPEECH_STATE_LISTENING_START = 0x00000004;
700 
701     /**
702      * Change type for {@link #TYPE_SPEECH_STATE_CHANGE} event: another service is no longer
703      * listening to the microphone.
704      */
705     public static final int SPEECH_STATE_LISTENING_END = 0x00000008;
706 
707     /**
708      * Change type for {@link #TYPE_WINDOWS_CHANGED} event:
709      * The window was added.
710      */
711     public static final int WINDOWS_CHANGE_ADDED = 0x00000001;
712 
713     /**
714      * Change type for {@link #TYPE_WINDOWS_CHANGED} event:
715      * A window was removed.
716      */
717     public static final int WINDOWS_CHANGE_REMOVED = 0x00000002;
718 
719     /**
720      * Change type for {@link #TYPE_WINDOWS_CHANGED} event:
721      * The window's title changed.
722      */
723     public static final int WINDOWS_CHANGE_TITLE = 0x00000004;
724 
725     /**
726      * Change type for {@link #TYPE_WINDOWS_CHANGED} event:
727      * The window's bounds changed.
728      * <p>
729      * Starting in {@link android.os.Build.VERSION_CODES#R R}, this event implies the window's
730      * region changed. It's also possible that region changed but bounds doesn't.
731      * </p>
732      */
733     public static final int WINDOWS_CHANGE_BOUNDS = 0x00000008;
734 
735     /**
736      * Change type for {@link #TYPE_WINDOWS_CHANGED} event:
737      * The window's layer changed.
738      */
739     public static final int WINDOWS_CHANGE_LAYER = 0x00000010;
740 
741     /**
742      * Change type for {@link #TYPE_WINDOWS_CHANGED} event:
743      * The window's {@link AccessibilityWindowInfo#isActive()} changed.
744      */
745     public static final int WINDOWS_CHANGE_ACTIVE = 0x00000020;
746 
747     /**
748      * Change type for {@link #TYPE_WINDOWS_CHANGED} event:
749      * The window's {@link AccessibilityWindowInfo#isFocused()} changed.
750      */
751     public static final int WINDOWS_CHANGE_FOCUSED = 0x00000040;
752 
753     /**
754      * Change type for {@link #TYPE_WINDOWS_CHANGED} event:
755      * The window's {@link AccessibilityWindowInfo#isAccessibilityFocused()} changed.
756      */
757     public static final int WINDOWS_CHANGE_ACCESSIBILITY_FOCUSED = 0x00000080;
758 
759     /**
760      * Change type for {@link #TYPE_WINDOWS_CHANGED} event:
761      * The window's parent changed.
762      */
763     public static final int WINDOWS_CHANGE_PARENT = 0x00000100;
764 
765     /**
766      * Change type for {@link #TYPE_WINDOWS_CHANGED} event:
767      * The window's children changed.
768      */
769     public static final int WINDOWS_CHANGE_CHILDREN = 0x00000200;
770 
771     /**
772      * Change type for {@link #TYPE_WINDOWS_CHANGED} event:
773      * The window either entered or exited picture-in-picture mode.
774      */
775     public static final int WINDOWS_CHANGE_PIP = 0x00000400;
776 
777     /** @hide */
778     @Retention(RetentionPolicy.SOURCE)
779     @IntDef(flag = true, prefix = { "WINDOWS_CHANGE_" }, value = {
780             WINDOWS_CHANGE_ADDED,
781             WINDOWS_CHANGE_REMOVED,
782             WINDOWS_CHANGE_TITLE,
783             WINDOWS_CHANGE_BOUNDS,
784             WINDOWS_CHANGE_LAYER,
785             WINDOWS_CHANGE_ACTIVE,
786             WINDOWS_CHANGE_FOCUSED,
787             WINDOWS_CHANGE_ACCESSIBILITY_FOCUSED,
788             WINDOWS_CHANGE_PARENT,
789             WINDOWS_CHANGE_CHILDREN,
790             WINDOWS_CHANGE_PIP
791     })
792     public @interface WindowsChangeTypes {}
793 
794     /** @hide */
795     @Retention(RetentionPolicy.SOURCE)
796     @IntDef(
797             flag = true,
798             prefix = {"CONTENT_CHANGE_TYPE_"},
799             value = {
800                 CONTENT_CHANGE_TYPE_UNDEFINED,
801                 CONTENT_CHANGE_TYPE_SUBTREE,
802                 CONTENT_CHANGE_TYPE_TEXT,
803                 CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION,
804                 CONTENT_CHANGE_TYPE_STATE_DESCRIPTION,
805                 CONTENT_CHANGE_TYPE_PANE_TITLE,
806                 CONTENT_CHANGE_TYPE_PANE_APPEARED,
807                 CONTENT_CHANGE_TYPE_PANE_DISAPPEARED,
808                 CONTENT_CHANGE_TYPE_DRAG_STARTED,
809                 CONTENT_CHANGE_TYPE_DRAG_DROPPED,
810                 CONTENT_CHANGE_TYPE_DRAG_CANCELLED,
811             })
812     public @interface ContentChangeTypes {}
813 
814     /** @hide */
815     @Retention(RetentionPolicy.SOURCE)
816     @IntDef(
817             flag = true,
818             prefix = {"SPEECH_STATE_"},
819             value = {
820                 SPEECH_STATE_SPEAKING_START,
821                 SPEECH_STATE_SPEAKING_END,
822                 SPEECH_STATE_LISTENING_START,
823                 SPEECH_STATE_LISTENING_END
824             })
825     public @interface SpeechStateChangeTypes {}
826 
827     /** @hide */
828     @IntDef(
829             flag = true,
830             prefix = {"TYPE_"},
831             value = {
832                 TYPE_VIEW_CLICKED,
833                 TYPE_VIEW_LONG_CLICKED,
834                 TYPE_VIEW_SELECTED,
835                 TYPE_VIEW_FOCUSED,
836                 TYPE_VIEW_TEXT_CHANGED,
837                 TYPE_WINDOW_STATE_CHANGED,
838                 TYPE_NOTIFICATION_STATE_CHANGED,
839                 TYPE_VIEW_HOVER_ENTER,
840                 TYPE_VIEW_HOVER_EXIT,
841                 TYPE_TOUCH_EXPLORATION_GESTURE_START,
842                 TYPE_TOUCH_EXPLORATION_GESTURE_END,
843                 TYPE_WINDOW_CONTENT_CHANGED,
844                 TYPE_VIEW_SCROLLED,
845                 TYPE_VIEW_TEXT_SELECTION_CHANGED,
846                 TYPE_ANNOUNCEMENT,
847                 TYPE_VIEW_ACCESSIBILITY_FOCUSED,
848                 TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED,
849                 TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY,
850                 TYPE_GESTURE_DETECTION_START,
851                 TYPE_GESTURE_DETECTION_END,
852                 TYPE_TOUCH_INTERACTION_START,
853                 TYPE_TOUCH_INTERACTION_END,
854                 TYPE_WINDOWS_CHANGED,
855                 TYPE_VIEW_CONTEXT_CLICKED,
856                 TYPE_ASSIST_READING_CONTEXT,
857                 TYPE_SPEECH_STATE_CHANGE
858             })
859     @Retention(RetentionPolicy.SOURCE)
860     public @interface EventType {}
861 
862     /**
863      * Mask for {@link AccessibilityEvent} all types.
864      *
865      * @see #TYPE_VIEW_CLICKED
866      * @see #TYPE_VIEW_LONG_CLICKED
867      * @see #TYPE_VIEW_SELECTED
868      * @see #TYPE_VIEW_FOCUSED
869      * @see #TYPE_VIEW_TEXT_CHANGED
870      * @see #TYPE_WINDOW_STATE_CHANGED
871      * @see #TYPE_NOTIFICATION_STATE_CHANGED
872      * @see #TYPE_VIEW_HOVER_ENTER
873      * @see #TYPE_VIEW_HOVER_EXIT
874      * @see #TYPE_TOUCH_EXPLORATION_GESTURE_START
875      * @see #TYPE_TOUCH_EXPLORATION_GESTURE_END
876      * @see #TYPE_WINDOW_CONTENT_CHANGED
877      * @see #TYPE_VIEW_SCROLLED
878      * @see #TYPE_VIEW_TEXT_SELECTION_CHANGED
879      * @see #TYPE_ANNOUNCEMENT
880      * @see #TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY
881      * @see #TYPE_GESTURE_DETECTION_START
882      * @see #TYPE_GESTURE_DETECTION_END
883      * @see #TYPE_TOUCH_INTERACTION_START
884      * @see #TYPE_TOUCH_INTERACTION_END
885      * @see #TYPE_WINDOWS_CHANGED
886      * @see #TYPE_VIEW_CONTEXT_CLICKED
887      */
888     public static final int TYPES_ALL_MASK = 0xFFFFFFFF;
889 
890     @UnsupportedAppUsage
891     private @EventType int mEventType;
892     private CharSequence mPackageName;
893     private long mEventTime;
894     int mMovementGranularity;
895     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
896     int mAction;
897     int mContentChangeTypes;
898     int mWindowChangeTypes;
899     int mSpeechStateChangeTypes;
900 
901     /**
902      * The stack trace describing where this event originated from on the app side.
903      * Only populated if {@link #DEBUG_ORIGIN} is enabled
904      * Can be inspected(e.g. printed) from an
905      * {@link android.accessibilityservice.AccessibilityService} to trace where particular events
906      * are being dispatched from.
907      *
908      * @hide
909      */
910     public StackTraceElement[] originStackTrace = null;
911 
912     private ArrayList<AccessibilityRecord> mRecords;
913 
914     /**
915      * Creates a new {@link AccessibilityEvent}.
916      */
AccessibilityEvent()917     public AccessibilityEvent() {
918         if (DEBUG_ORIGIN) originStackTrace = Thread.currentThread().getStackTrace();
919     }
920 
921 
922     /**
923      * Creates a new {@link AccessibilityEvent} with the given <code>eventType</code>.
924      *
925      * @param eventType The event type.
926      */
AccessibilityEvent(int eventType)927     public AccessibilityEvent(int eventType) {
928         mEventType = eventType;
929         if (DEBUG_ORIGIN) originStackTrace = Thread.currentThread().getStackTrace();
930     }
931 
932     /**
933      * Copy constructor. Creates a new {@link AccessibilityEvent}, and this instance is initialized
934      * from the given <code>event</code>.
935      *
936      * @param event The other event.
937      */
AccessibilityEvent(@onNull AccessibilityEvent event)938     public AccessibilityEvent(@NonNull AccessibilityEvent event) {
939         init(event);
940     }
941 
942     /**
943      * Initialize an event from another one.
944      *
945      * @param event The event to initialize from.
946      */
init(AccessibilityEvent event)947     void init(AccessibilityEvent event) {
948         super.init(event);
949         mEventType = event.mEventType;
950         mMovementGranularity = event.mMovementGranularity;
951         mAction = event.mAction;
952         mContentChangeTypes = event.mContentChangeTypes;
953         mSpeechStateChangeTypes = event.mSpeechStateChangeTypes;
954         mWindowChangeTypes = event.mWindowChangeTypes;
955         mEventTime = event.mEventTime;
956         mPackageName = event.mPackageName;
957         if (event.mRecords != null) {
958             final int recordCount = event.mRecords.size();
959             mRecords = new ArrayList<>(recordCount);
960             for (int i = 0; i < recordCount; i++) {
961                 final AccessibilityRecord record = event.mRecords.get(i);
962                 final AccessibilityRecord recordClone = new AccessibilityRecord(record);
963                 mRecords.add(recordClone);
964             }
965         }
966         if (DEBUG_ORIGIN) originStackTrace = event.originStackTrace;
967     }
968 
969     /**
970      * Sets if this instance is sealed.
971      *
972      * @param sealed Whether is sealed.
973      *
974      * @hide
975      */
976     @Override
setSealed(boolean sealed)977     public void setSealed(boolean sealed) {
978         super.setSealed(sealed);
979         final List<AccessibilityRecord> records = mRecords;
980         if (records != null) {
981             final int recordCount = records.size();
982             for (int i = 0; i < recordCount; i++) {
983                 AccessibilityRecord record = records.get(i);
984                 record.setSealed(sealed);
985             }
986         }
987     }
988 
989     /**
990      * Gets the number of records contained in the event.
991      *
992      * @return The number of records.
993      */
getRecordCount()994     public int getRecordCount() {
995         return mRecords == null ? 0 : mRecords.size();
996     }
997 
998     /**
999      * Appends an {@link AccessibilityRecord} to the end of event records.
1000      *
1001      * @param record The record to append.
1002      *
1003      * @throws IllegalStateException If called from an AccessibilityService.
1004      */
appendRecord(AccessibilityRecord record)1005     public void appendRecord(AccessibilityRecord record) {
1006         enforceNotSealed();
1007         if (mRecords == null) {
1008             mRecords = new ArrayList<AccessibilityRecord>();
1009         }
1010         mRecords.add(record);
1011     }
1012 
1013     /**
1014      * Gets the record at a given index.
1015      *
1016      * @param index The index.
1017      * @return The record at the specified index.
1018      */
getRecord(int index)1019     public AccessibilityRecord getRecord(int index) {
1020         if (mRecords == null) {
1021             throw new IndexOutOfBoundsException("Invalid index " + index + ", size is 0");
1022         }
1023         return mRecords.get(index);
1024     }
1025 
1026     /**
1027      * Gets the event type.
1028      *
1029      * @return The event type.
1030      */
getEventType()1031     public @EventType int getEventType() {
1032         return mEventType;
1033     }
1034 
1035     /**
1036      * Gets the bit mask of change types signaled by a
1037      * {@link #TYPE_WINDOW_CONTENT_CHANGED} event or {@link #TYPE_WINDOW_STATE_CHANGED}. A single
1038      * event may represent multiple change types.
1039      *
1040      * @return The bit mask of change types. One or more of:
1041      *         <ul>
1042      *         <li>{@link #CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION}
1043      *         <li>{@link #CONTENT_CHANGE_TYPE_STATE_DESCRIPTION}
1044      *         <li>{@link #CONTENT_CHANGE_TYPE_SUBTREE}
1045      *         <li>{@link #CONTENT_CHANGE_TYPE_TEXT}
1046      *         <li>{@link #CONTENT_CHANGE_TYPE_PANE_TITLE}
1047      *         <li>{@link #CONTENT_CHANGE_TYPE_UNDEFINED}
1048      *         <li>{@link #CONTENT_CHANGE_TYPE_PANE_APPEARED}
1049      *         <li>{@link #CONTENT_CHANGE_TYPE_PANE_DISAPPEARED}
1050      *         </ul>
1051      */
1052     @ContentChangeTypes
getContentChangeTypes()1053     public int getContentChangeTypes() {
1054         return mContentChangeTypes;
1055     }
1056 
contentChangeTypesToString(int types)1057     private static String contentChangeTypesToString(int types) {
1058         return BitUtils.flagsToString(types, AccessibilityEvent::singleContentChangeTypeToString);
1059     }
1060 
singleContentChangeTypeToString(int type)1061     private static String singleContentChangeTypeToString(int type) {
1062         switch (type) {
1063             case CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION:
1064                 return "CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION";
1065             case CONTENT_CHANGE_TYPE_STATE_DESCRIPTION:
1066                 return "CONTENT_CHANGE_TYPE_STATE_DESCRIPTION";
1067             case CONTENT_CHANGE_TYPE_SUBTREE: return "CONTENT_CHANGE_TYPE_SUBTREE";
1068             case CONTENT_CHANGE_TYPE_TEXT: return "CONTENT_CHANGE_TYPE_TEXT";
1069             case CONTENT_CHANGE_TYPE_PANE_TITLE: return "CONTENT_CHANGE_TYPE_PANE_TITLE";
1070             case CONTENT_CHANGE_TYPE_UNDEFINED: return "CONTENT_CHANGE_TYPE_UNDEFINED";
1071             case CONTENT_CHANGE_TYPE_PANE_APPEARED: return "CONTENT_CHANGE_TYPE_PANE_APPEARED";
1072             case CONTENT_CHANGE_TYPE_PANE_DISAPPEARED:
1073                 return "CONTENT_CHANGE_TYPE_PANE_DISAPPEARED";
1074             case CONTENT_CHANGE_TYPE_DRAG_STARTED: return "CONTENT_CHANGE_TYPE_DRAG_STARTED";
1075             case CONTENT_CHANGE_TYPE_DRAG_DROPPED: return "CONTENT_CHANGE_TYPE_DRAG_DROPPED";
1076             case CONTENT_CHANGE_TYPE_DRAG_CANCELLED: return "CONTENT_CHANGE_TYPE_DRAG_CANCELLED";
1077             default: return Integer.toHexString(type);
1078         }
1079     }
1080 
1081     /**
1082      * Sets the bit mask of node tree changes signaled by an
1083      * {@link #TYPE_WINDOW_CONTENT_CHANGED} event.
1084      *
1085      * @param changeTypes The bit mask of change types.
1086      * @throws IllegalStateException If called from an AccessibilityService.
1087      * @see #getContentChangeTypes()
1088      */
setContentChangeTypes(@ontentChangeTypes int changeTypes)1089     public void setContentChangeTypes(@ContentChangeTypes int changeTypes) {
1090         enforceNotSealed();
1091         mContentChangeTypes = changeTypes;
1092     }
1093 
1094     /**
1095      * Gets the bit mask of the speech state signaled by a {@link #TYPE_SPEECH_STATE_CHANGE} event
1096      *
1097      * @see #SPEECH_STATE_SPEAKING_START
1098      * @see #SPEECH_STATE_SPEAKING_END
1099      * @see #SPEECH_STATE_LISTENING_START
1100      * @see #SPEECH_STATE_LISTENING_END
1101      */
getSpeechStateChangeTypes()1102     public int getSpeechStateChangeTypes() {
1103         return mSpeechStateChangeTypes;
1104     }
1105 
speechStateChangeTypesToString(int types)1106     private static String speechStateChangeTypesToString(int types) {
1107         return BitUtils.flagsToString(
1108                 types, AccessibilityEvent::singleSpeechStateChangeTypeToString);
1109     }
1110 
singleSpeechStateChangeTypeToString(int type)1111     private static String singleSpeechStateChangeTypeToString(int type) {
1112         switch (type) {
1113             case SPEECH_STATE_SPEAKING_START:
1114                 return "SPEECH_STATE_SPEAKING_START";
1115             case SPEECH_STATE_LISTENING_START:
1116                 return "SPEECH_STATE_LISTENING_START";
1117             case SPEECH_STATE_SPEAKING_END:
1118                 return "SPEECH_STATE_SPEAKING_END";
1119             case SPEECH_STATE_LISTENING_END:
1120                 return "SPEECH_STATE_LISTENING_END";
1121             default:
1122                 return Integer.toHexString(type);
1123         }
1124     }
1125 
1126     /**
1127      * Sets the bit mask of the speech state change types
1128      * signaled by a {@link #TYPE_SPEECH_STATE_CHANGE} event.
1129      * The sender is responsible for ensuring that  the state change types  make sense. For example,
1130      * the sender should not send
1131      * {@link #SPEECH_STATE_SPEAKING_START} and {@link #SPEECH_STATE_SPEAKING_END} together.
1132      *
1133      * @see #SPEECH_STATE_SPEAKING_START
1134      * @see #SPEECH_STATE_SPEAKING_END
1135      * @see #SPEECH_STATE_LISTENING_START
1136      * @see #SPEECH_STATE_LISTENING_END
1137      */
setSpeechStateChangeTypes(@peechStateChangeTypes int state)1138     public void setSpeechStateChangeTypes(@SpeechStateChangeTypes int state) {
1139         enforceNotSealed();
1140         mSpeechStateChangeTypes = state;
1141     }
1142 
1143     /**
1144      * Get the bit mask of change types signaled by a {@link #TYPE_WINDOWS_CHANGED} event. A
1145      * single event may represent multiple change types.
1146      *
1147      * @return The bit mask of change types.
1148      */
1149     @WindowsChangeTypes
getWindowChanges()1150     public int getWindowChanges() {
1151         return mWindowChangeTypes;
1152     }
1153 
1154     /** @hide  */
setWindowChanges(@indowsChangeTypes int changes)1155     public void setWindowChanges(@WindowsChangeTypes int changes) {
1156         mWindowChangeTypes = changes;
1157     }
1158 
windowChangeTypesToString(@indowsChangeTypes int types)1159     private static String windowChangeTypesToString(@WindowsChangeTypes int types) {
1160         return BitUtils.flagsToString(types, AccessibilityEvent::singleWindowChangeTypeToString);
1161     }
1162 
singleWindowChangeTypeToString(int type)1163     private static String singleWindowChangeTypeToString(int type) {
1164         switch (type) {
1165             case WINDOWS_CHANGE_ADDED: return "WINDOWS_CHANGE_ADDED";
1166             case WINDOWS_CHANGE_REMOVED: return "WINDOWS_CHANGE_REMOVED";
1167             case WINDOWS_CHANGE_TITLE: return "WINDOWS_CHANGE_TITLE";
1168             case WINDOWS_CHANGE_BOUNDS: return "WINDOWS_CHANGE_BOUNDS";
1169             case WINDOWS_CHANGE_LAYER: return "WINDOWS_CHANGE_LAYER";
1170             case WINDOWS_CHANGE_ACTIVE: return "WINDOWS_CHANGE_ACTIVE";
1171             case WINDOWS_CHANGE_FOCUSED: return "WINDOWS_CHANGE_FOCUSED";
1172             case WINDOWS_CHANGE_ACCESSIBILITY_FOCUSED:
1173                 return "WINDOWS_CHANGE_ACCESSIBILITY_FOCUSED";
1174             case WINDOWS_CHANGE_PARENT: return "WINDOWS_CHANGE_PARENT";
1175             case WINDOWS_CHANGE_CHILDREN: return "WINDOWS_CHANGE_CHILDREN";
1176             case WINDOWS_CHANGE_PIP: return "WINDOWS_CHANGE_PIP";
1177             default: return Integer.toHexString(type);
1178         }
1179     }
1180 
1181     /**
1182      * Sets the event type.
1183      *
1184      * <b>Note: An event must represent a single event type.</b>
1185      * @param eventType The event type.
1186      *
1187      * @throws IllegalStateException If called from an AccessibilityService.
1188      */
setEventType(@ventType int eventType)1189     public void setEventType(@EventType int eventType) {
1190         enforceNotSealed();
1191         mEventType = eventType;
1192     }
1193 
1194     /**
1195      * Gets the time in which this event was sent.
1196      *
1197      * @return The event time.
1198      */
getEventTime()1199     public long getEventTime() {
1200         return mEventTime;
1201     }
1202 
1203     /**
1204      * Sets the time in which this event was sent.
1205      *
1206      * @param eventTime The event time.
1207      *
1208      * @throws IllegalStateException If called from an AccessibilityService.
1209      */
setEventTime(long eventTime)1210     public void setEventTime(long eventTime) {
1211         enforceNotSealed();
1212         mEventTime = eventTime;
1213     }
1214 
1215     /**
1216      * Gets the package name of the source.
1217      *
1218      * @return The package name.
1219      */
getPackageName()1220     public CharSequence getPackageName() {
1221         return mPackageName;
1222     }
1223 
1224     /**
1225      * Sets the package name of the source.
1226      *
1227      * @param packageName The package name.
1228      *
1229      * @throws IllegalStateException If called from an AccessibilityService.
1230      */
setPackageName(CharSequence packageName)1231     public void setPackageName(CharSequence packageName) {
1232         enforceNotSealed();
1233         mPackageName = packageName;
1234     }
1235 
1236     /**
1237      * Sets the movement granularity that was traversed.
1238      *
1239      * @param granularity The granularity.
1240      *
1241      * @throws IllegalStateException If called from an AccessibilityService.
1242      */
setMovementGranularity(int granularity)1243     public void setMovementGranularity(int granularity) {
1244         enforceNotSealed();
1245         mMovementGranularity = granularity;
1246     }
1247 
1248     /**
1249      * Gets the movement granularity that was traversed.
1250      *
1251      * @return The granularity.
1252      */
getMovementGranularity()1253     public int getMovementGranularity() {
1254         return mMovementGranularity;
1255     }
1256 
1257     /**
1258      * Sets the performed action that triggered this event.
1259      * <p>
1260      * Valid actions are defined in {@link AccessibilityNodeInfo}:
1261      * <ul>
1262      * <li>{@link AccessibilityNodeInfo#ACTION_ACCESSIBILITY_FOCUS}
1263      * <li>{@link AccessibilityNodeInfo#ACTION_CLEAR_ACCESSIBILITY_FOCUS}
1264      * <li>{@link AccessibilityNodeInfo#ACTION_CLEAR_FOCUS}
1265      * <li>{@link AccessibilityNodeInfo#ACTION_CLEAR_SELECTION}
1266      * <li>{@link AccessibilityNodeInfo#ACTION_CLICK}
1267      * <li>etc.
1268      * </ul>
1269      *
1270      * @param action The action.
1271      * @throws IllegalStateException If called from an AccessibilityService.
1272      * @see AccessibilityNodeInfo#performAction(int)
1273      */
setAction(int action)1274     public void setAction(int action) {
1275         enforceNotSealed();
1276         mAction = action;
1277     }
1278 
1279     /**
1280      * Gets the performed action that triggered this event.
1281      *
1282      * @return The action.
1283      */
getAction()1284     public int getAction() {
1285         return mAction;
1286     }
1287 
1288     /**
1289      * Convenience method to obtain a {@link #TYPE_WINDOWS_CHANGED} event for a specific window and
1290      * change set.
1291      *
1292      * @param windowId The ID of the window that changed
1293      * @param windowChangeTypes The changes to populate
1294      * @return An instance of a TYPE_WINDOWS_CHANGED, populated with the requested fields and with
1295      *         importantForAccessibility set to {@code true}.
1296      *
1297      * @hide
1298      */
obtainWindowsChangedEvent( int windowId, int windowChangeTypes)1299     public static AccessibilityEvent obtainWindowsChangedEvent(
1300             int windowId, int windowChangeTypes) {
1301         final AccessibilityEvent event = new AccessibilityEvent(TYPE_WINDOWS_CHANGED);
1302         event.setWindowId(windowId);
1303         event.setWindowChanges(windowChangeTypes);
1304         event.setImportantForAccessibility(true);
1305         return event;
1306     }
1307 
1308     /**
1309      * Instantiates a new AccessibilityEvent instance with its type property set.
1310      *
1311      * @deprecated Object pooling has been discontinued. Create a new instance using the
1312      * constructor {@link #AccessibilityEvent()} instead.
1313      * @param eventType The event type.
1314      * @return An instance.
1315      */
1316     @Deprecated
obtain(int eventType)1317     public static AccessibilityEvent obtain(int eventType) {
1318         AccessibilityEvent event = new AccessibilityEvent();
1319         event.setEventType(eventType);
1320         return event;
1321     }
1322 
1323     /**
1324      * Instantiates a new AccessibilityEvent instance.
1325      * The returned instance is initialized from the given
1326      * <code>event</code>.
1327      *
1328      * @deprecated Object pooling has been discontinued. Create a new instance using the
1329      * constructor {@link #AccessibilityEvent()} instead.
1330      * @param event The other event.
1331      * @return An instance.
1332      */
1333     @Deprecated
obtain(AccessibilityEvent event)1334     public static AccessibilityEvent obtain(AccessibilityEvent event) {
1335         AccessibilityEvent eventClone = new AccessibilityEvent();
1336         eventClone.init(event);
1337         return eventClone;
1338     }
1339 
1340     /**
1341      * Instantiates a new AccessibilityEvent instance.
1342      *
1343      * @deprecated Object pooling has been discontinued. Create a new instance using the
1344      * constructor {@link #AccessibilityEvent()} instead.
1345      * @return An instance.
1346      */
1347     @Deprecated
obtain()1348     public static AccessibilityEvent obtain() {
1349         return new AccessibilityEvent();
1350     }
1351 
1352     /**
1353      * Previously would recycle an instance back to be reused.
1354      *
1355      * @deprecated Object pooling has been discontinued. Calling this function now will have
1356      * no effect.
1357      */
1358     @Override
1359     @Deprecated
recycle()1360     public void recycle() {}
1361 
1362     /**
1363      * Clears the state of this instance.
1364      *
1365      * @hide
1366      */
1367     @Override
clear()1368     protected void clear() {
1369         super.clear();
1370         mEventType = 0;
1371         mMovementGranularity = 0;
1372         mAction = 0;
1373         mContentChangeTypes = 0;
1374         mWindowChangeTypes = 0;
1375         mSpeechStateChangeTypes = 0;
1376         mPackageName = null;
1377         mEventTime = 0;
1378         if (mRecords != null) {
1379             while (!mRecords.isEmpty()) {
1380                 AccessibilityRecord record = mRecords.remove(0);
1381             }
1382         }
1383         if (DEBUG_ORIGIN) originStackTrace = null;
1384     }
1385 
1386     /**
1387      * Creates a new instance from a {@link Parcel}.
1388      *
1389      * @param parcel A parcel containing the state of a {@link AccessibilityEvent}.
1390      */
initFromParcel(Parcel parcel)1391     public void initFromParcel(Parcel parcel) {
1392         mSealed = (parcel.readInt() == 1);
1393         mEventType = parcel.readInt();
1394         mMovementGranularity = parcel.readInt();
1395         mAction = parcel.readInt();
1396         mContentChangeTypes = parcel.readInt();
1397         mWindowChangeTypes = parcel.readInt();
1398         mSpeechStateChangeTypes = parcel.readInt();
1399         mPackageName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
1400         mEventTime = parcel.readLong();
1401         mConnectionId = parcel.readInt();
1402         readAccessibilityRecordFromParcel(this, parcel);
1403 
1404         // Read the records.
1405         final int recordCount = parcel.readInt();
1406         if (recordCount > 0) {
1407             mRecords = new ArrayList<>(recordCount);
1408             for (int i = 0; i < recordCount; i++) {
1409                 AccessibilityRecord record = new AccessibilityRecord();
1410                 readAccessibilityRecordFromParcel(record, parcel);
1411                 record.mConnectionId = mConnectionId;
1412                 mRecords.add(record);
1413             }
1414         }
1415 
1416         if (DEBUG_ORIGIN) {
1417             originStackTrace = new StackTraceElement[parcel.readInt()];
1418             for (int i = 0; i < originStackTrace.length; i++) {
1419                 originStackTrace[i] = new StackTraceElement(
1420                         parcel.readString(),
1421                         parcel.readString(),
1422                         parcel.readString(),
1423                         parcel.readInt());
1424             }
1425         }
1426     }
1427 
1428     /**
1429      * Reads an {@link AccessibilityRecord} from a parcel.
1430      *
1431      * @param record The record to initialize.
1432      * @param parcel The parcel to read from.
1433      */
readAccessibilityRecordFromParcel(AccessibilityRecord record, Parcel parcel)1434     private void readAccessibilityRecordFromParcel(AccessibilityRecord record,
1435             Parcel parcel) {
1436         record.mBooleanProperties = parcel.readInt();
1437         record.mCurrentItemIndex = parcel.readInt();
1438         record.mItemCount = parcel.readInt();
1439         record.mFromIndex = parcel.readInt();
1440         record.mToIndex = parcel.readInt();
1441         record.mScrollX = parcel.readInt();
1442         record.mScrollY =  parcel.readInt();
1443         record.mScrollDeltaX =  parcel.readInt();
1444         record.mScrollDeltaY =  parcel.readInt();
1445         record.mMaxScrollX = parcel.readInt();
1446         record.mMaxScrollY =  parcel.readInt();
1447         record.mAddedCount = parcel.readInt();
1448         record.mRemovedCount = parcel.readInt();
1449         record.mClassName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
1450         record.mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
1451         record.mBeforeText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
1452         record.mParcelableData = parcel.readParcelable(null);
1453         parcel.readList(record.mText, null, java.lang.CharSequence.class);
1454         record.mSourceWindowId = parcel.readInt();
1455         record.mSourceNodeId = parcel.readLong();
1456         record.mSourceDisplayId = parcel.readInt();
1457         record.mSealed = (parcel.readInt() == 1);
1458     }
1459 
1460     /**
1461      * {@inheritDoc}
1462      */
writeToParcel(Parcel parcel, int flags)1463     public void writeToParcel(Parcel parcel, int flags) {
1464         parcel.writeInt(isSealed() ? 1 : 0);
1465         parcel.writeInt(mEventType);
1466         parcel.writeInt(mMovementGranularity);
1467         parcel.writeInt(mAction);
1468         parcel.writeInt(mContentChangeTypes);
1469         parcel.writeInt(mWindowChangeTypes);
1470         parcel.writeInt(mSpeechStateChangeTypes);
1471         TextUtils.writeToParcel(mPackageName, parcel, 0);
1472         parcel.writeLong(mEventTime);
1473         parcel.writeInt(mConnectionId);
1474         writeAccessibilityRecordToParcel(this, parcel, flags);
1475 
1476         // Write the records.
1477         final int recordCount = getRecordCount();
1478         parcel.writeInt(recordCount);
1479         for (int i = 0; i < recordCount; i++) {
1480             AccessibilityRecord record = mRecords.get(i);
1481             writeAccessibilityRecordToParcel(record, parcel, flags);
1482         }
1483 
1484         if (DEBUG_ORIGIN) {
1485             if (originStackTrace == null) originStackTrace = Thread.currentThread().getStackTrace();
1486             parcel.writeInt(originStackTrace.length);
1487             for (StackTraceElement element : originStackTrace) {
1488                 parcel.writeString(element.getClassName());
1489                 parcel.writeString(element.getMethodName());
1490                 parcel.writeString(element.getFileName());
1491                 parcel.writeInt(element.getLineNumber());
1492             }
1493         }
1494     }
1495 
1496     /**
1497      * Writes an {@link AccessibilityRecord} to a parcel.
1498      *
1499      * @param record The record to write.
1500      * @param parcel The parcel to which to write.
1501      */
writeAccessibilityRecordToParcel(AccessibilityRecord record, Parcel parcel, int flags)1502     private void writeAccessibilityRecordToParcel(AccessibilityRecord record, Parcel parcel,
1503             int flags) {
1504         parcel.writeInt(record.mBooleanProperties);
1505         parcel.writeInt(record.mCurrentItemIndex);
1506         parcel.writeInt(record.mItemCount);
1507         parcel.writeInt(record.mFromIndex);
1508         parcel.writeInt(record.mToIndex);
1509         parcel.writeInt(record.mScrollX);
1510         parcel.writeInt(record.mScrollY);
1511         parcel.writeInt(record.mScrollDeltaX);
1512         parcel.writeInt(record.mScrollDeltaY);
1513         parcel.writeInt(record.mMaxScrollX);
1514         parcel.writeInt(record.mMaxScrollY);
1515         parcel.writeInt(record.mAddedCount);
1516         parcel.writeInt(record.mRemovedCount);
1517         TextUtils.writeToParcel(record.mClassName, parcel, flags);
1518         TextUtils.writeToParcel(record.mContentDescription, parcel, flags);
1519         TextUtils.writeToParcel(record.mBeforeText, parcel, flags);
1520         parcel.writeParcelable(record.mParcelableData, flags);
1521         parcel.writeList(record.mText);
1522         parcel.writeInt(record.mSourceWindowId);
1523         parcel.writeLong(record.mSourceNodeId);
1524         parcel.writeInt(record.mSourceDisplayId);
1525         parcel.writeInt(record.mSealed ? 1 : 0);
1526     }
1527 
1528     /**
1529      * {@inheritDoc}
1530      */
describeContents()1531     public int describeContents() {
1532         return 0;
1533     }
1534 
1535     @Override
toString()1536     public String toString() {
1537         StringBuilder builder = new StringBuilder();
1538         builder.append("EventType: ").append(eventTypeToString(mEventType));
1539         builder.append("; EventTime: ").append(mEventTime);
1540         builder.append("; PackageName: ").append(mPackageName);
1541         if (!DEBUG_CONCISE_TOSTRING || mMovementGranularity != 0) {
1542             builder.append("; MovementGranularity: ").append(mMovementGranularity);
1543         }
1544         if (!DEBUG_CONCISE_TOSTRING || mAction != 0) {
1545             builder.append("; Action: ").append(mAction);
1546         }
1547         if (!DEBUG_CONCISE_TOSTRING || mContentChangeTypes != 0) {
1548             builder.append("; ContentChangeTypes: ").append(
1549                     contentChangeTypesToString(mContentChangeTypes));
1550         }
1551         if (!DEBUG_CONCISE_TOSTRING || mWindowChangeTypes != 0) {
1552             builder.append("; WindowChangeTypes: ").append(
1553                     windowChangeTypesToString(mWindowChangeTypes));
1554         }
1555         super.appendTo(builder);
1556         if (DEBUG || DEBUG_CONCISE_TOSTRING) {
1557             if (!DEBUG_CONCISE_TOSTRING) {
1558                 builder.append("\n");
1559             }
1560             if (DEBUG) {
1561                 builder.append("; SourceWindowId: 0x").append(Long.toHexString(mSourceWindowId));
1562                 builder.append("; SourceNodeId: 0x").append(Long.toHexString(mSourceNodeId));
1563                 builder.append("; SourceDisplayId: ").append(mSourceDisplayId);
1564             }
1565             for (int i = 0; i < getRecordCount(); i++) {
1566                 builder.append("  Record ").append(i).append(":");
1567                 getRecord(i).appendTo(builder).append("\n");
1568             }
1569         } else {
1570             builder.append("; recordCount: ").append(getRecordCount());
1571         }
1572         return builder.toString();
1573     }
1574 
1575     /**
1576      * Returns the string representation of an event type. For example,
1577      * {@link #TYPE_VIEW_CLICKED} is represented by the string TYPE_VIEW_CLICKED.
1578      *
1579      * @param eventType The event type
1580      * @return The string representation.
1581      */
eventTypeToString(int eventType)1582     public static String eventTypeToString(int eventType) {
1583         if (eventType == TYPES_ALL_MASK) {
1584             return "TYPES_ALL_MASK";
1585         }
1586         StringBuilder builder = new StringBuilder();
1587         int eventTypeCount = 0;
1588         while (eventType != 0) {
1589             final int eventTypeFlag = 1 << Integer.numberOfTrailingZeros(eventType);
1590             eventType &= ~eventTypeFlag;
1591 
1592             if (eventTypeCount > 0) {
1593                 builder.append(", ");
1594             }
1595             builder.append(singleEventTypeToString(eventTypeFlag));
1596 
1597             eventTypeCount++;
1598         }
1599         if (eventTypeCount > 1) {
1600             builder.insert(0, '[');
1601             builder.append(']');
1602         }
1603         return builder.toString();
1604     }
1605 
singleEventTypeToString(int eventType)1606     private static String singleEventTypeToString(int eventType) {
1607         switch (eventType) {
1608             case TYPE_VIEW_CLICKED: return "TYPE_VIEW_CLICKED";
1609             case TYPE_VIEW_LONG_CLICKED: return "TYPE_VIEW_LONG_CLICKED";
1610             case TYPE_VIEW_SELECTED: return "TYPE_VIEW_SELECTED";
1611             case TYPE_VIEW_FOCUSED: return "TYPE_VIEW_FOCUSED";
1612             case TYPE_VIEW_TEXT_CHANGED: return "TYPE_VIEW_TEXT_CHANGED";
1613             case TYPE_WINDOW_STATE_CHANGED: return "TYPE_WINDOW_STATE_CHANGED";
1614             case TYPE_VIEW_HOVER_ENTER: return "TYPE_VIEW_HOVER_ENTER";
1615             case TYPE_VIEW_HOVER_EXIT: return "TYPE_VIEW_HOVER_EXIT";
1616             case TYPE_NOTIFICATION_STATE_CHANGED: return "TYPE_NOTIFICATION_STATE_CHANGED";
1617             case TYPE_TOUCH_EXPLORATION_GESTURE_START: {
1618                 return "TYPE_TOUCH_EXPLORATION_GESTURE_START";
1619             }
1620             case TYPE_TOUCH_EXPLORATION_GESTURE_END: return "TYPE_TOUCH_EXPLORATION_GESTURE_END";
1621             case TYPE_WINDOW_CONTENT_CHANGED: return "TYPE_WINDOW_CONTENT_CHANGED";
1622             case TYPE_VIEW_TEXT_SELECTION_CHANGED: return "TYPE_VIEW_TEXT_SELECTION_CHANGED";
1623             case TYPE_VIEW_SCROLLED: return "TYPE_VIEW_SCROLLED";
1624             case TYPE_ANNOUNCEMENT: return "TYPE_ANNOUNCEMENT";
1625             case TYPE_VIEW_ACCESSIBILITY_FOCUSED: return "TYPE_VIEW_ACCESSIBILITY_FOCUSED";
1626             case TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: {
1627                 return "TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED";
1628             }
1629             case TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY: {
1630                 return "TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY";
1631             }
1632             case TYPE_GESTURE_DETECTION_START: return "TYPE_GESTURE_DETECTION_START";
1633             case TYPE_GESTURE_DETECTION_END: return "TYPE_GESTURE_DETECTION_END";
1634             case TYPE_TOUCH_INTERACTION_START: return "TYPE_TOUCH_INTERACTION_START";
1635             case TYPE_TOUCH_INTERACTION_END: return "TYPE_TOUCH_INTERACTION_END";
1636             case TYPE_WINDOWS_CHANGED: return "TYPE_WINDOWS_CHANGED";
1637             case TYPE_VIEW_CONTEXT_CLICKED: return "TYPE_VIEW_CONTEXT_CLICKED";
1638             case TYPE_ASSIST_READING_CONTEXT: return "TYPE_ASSIST_READING_CONTEXT";
1639             case TYPE_SPEECH_STATE_CHANGE: return "TYPE_SPEECH_STATE_CHANGE";
1640             default: return Integer.toHexString(eventType);
1641         }
1642     }
1643 
1644     /**
1645      * @see Parcelable.Creator
1646      */
1647     public static final @android.annotation.NonNull Parcelable.Creator<AccessibilityEvent> CREATOR =
1648             new Parcelable.Creator<AccessibilityEvent>() {
1649         public AccessibilityEvent createFromParcel(Parcel parcel) {
1650             AccessibilityEvent event = new AccessibilityEvent();
1651             event.initFromParcel(parcel);
1652             return event;
1653         }
1654 
1655         public AccessibilityEvent[] newArray(int size) {
1656             return new AccessibilityEvent[size];
1657         }
1658     };
1659 }
1660