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