Debian Codegraph @

core/java/android/accessibilityservice/AccessibilityServiceInfo.java

raw symbols SCIP
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.accessibilityservice;
18
19 import static android.accessibilityservice.util.AccessibilityUtils.getFilteredHtmlText;
20 import static android.accessibilityservice.util.AccessibilityUtils.loadSafeAnimatedImage;
21 import static android.content.pm.PackageManager.FEATURE_FINGERPRINT;
22
23 import android.annotation.IntDef;
24 import android.annotation.IntRange;
25 import android.annotation.NonNull;
26 import android.annotation.Nullable;
27 import android.annotation.TestApi;
28 import android.compat.annotation.ChangeId;
29 import android.compat.annotation.EnabledAfter;
30 import android.compat.annotation.UnsupportedAppUsage;
31 import android.content.ComponentName;
32 import android.content.Context;
33 import android.content.pm.PackageManager;
34 import android.content.pm.PackageManager.NameNotFoundException;
35 import android.content.pm.ResolveInfo;
36 import android.content.pm.ServiceInfo;
37 import android.content.res.Resources;
38 import android.content.res.TypedArray;
39 import android.content.res.XmlResourceParser;
40 import android.graphics.drawable.Drawable;
41 import android.hardware.fingerprint.FingerprintManager;
42 import android.os.Build;
43 import android.os.Parcel;
44 import android.os.Parcelable;
45 import android.os.RemoteException;
46 import android.util.AttributeSet;
47 import android.util.SparseArray;
48 import android.util.TypedValue;
49 import android.util.Xml;
50 import android.view.View;
51 import android.view.accessibility.AccessibilityEvent;
52 import android.view.accessibility.AccessibilityNodeInfo;
53
54 import com.android.internal.R;
55 import com.android.internal.compat.IPlatformCompat;
56
57 import org.xmlpull.v1.XmlPullParser;
58 import org.xmlpull.v1.XmlPullParserException;
59
60 import java.io.IOException;
61 import java.lang.annotation.Retention;
62 import java.lang.annotation.RetentionPolicy;
63 import java.util.ArrayList;
64 import java.util.Collections;
65 import java.util.List;
66
67 /**
68 * This class describes an {@link AccessibilityService}. The system notifies an
69 * {@link AccessibilityService} for {@link android.view.accessibility.AccessibilityEvent}s
70 * according to the information encapsulated in this class.
71 *
72 * <div class="special reference">
73 * <h3>Developer Guides</h3>
74 * <p>For more information about creating AccessibilityServices, read the
75 * <a href="{@docRoot}guide/topics/ui/accessibility/index.html">Accessibility</a>
76 * developer guide.</p>
77 * </div>
78 *
79 * @attr ref android.R.styleable#AccessibilityService_accessibilityEventTypes
80 * @attr ref android.R.styleable#AccessibilityService_accessibilityFeedbackType
81 * @attr ref android.R.styleable#AccessibilityService_accessibilityFlags
82 * @attr ref android.R.styleable#AccessibilityService_canRequestEnhancedWebAccessibility
83 * @attr ref android.R.styleable#AccessibilityService_canRequestFilterKeyEvents
84 * @attr ref android.R.styleable#AccessibilityService_canRequestTouchExplorationMode
85 * @attr ref android.R.styleable#AccessibilityService_canRetrieveWindowContent
86 * @attr ref android.R.styleable#AccessibilityService_intro
87 * @attr ref android.R.styleable#AccessibilityService_description
88 * @attr ref android.R.styleable#AccessibilityService_summary
89 * @attr ref android.R.styleable#AccessibilityService_notificationTimeout
90 * @attr ref android.R.styleable#AccessibilityService_packageNames
91 * @attr ref android.R.styleable#AccessibilityService_settingsActivity
92 * @attr ref android.R.styleable#AccessibilityService_tileService
93 * @attr ref android.R.styleable#AccessibilityService_nonInteractiveUiTimeout
94 * @attr ref android.R.styleable#AccessibilityService_interactiveUiTimeout
95 * @attr ref android.R.styleable#AccessibilityService_canTakeScreenshot
96 * @see AccessibilityService
97 * @see android.view.accessibility.AccessibilityEvent
98 * @see android.view.accessibility.AccessibilityManager
99 */
100 public class AccessibilityServiceInfo implements Parcelable {
101
102 private static final String TAG_ACCESSIBILITY_SERVICE = "accessibility-service";
103
104 /**
105 * Capability: This accessibility service can retrieve the active window content.
106 * @see android.R.styleable#AccessibilityService_canRetrieveWindowContent
107 */
108 public static final int CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT = 0x00000001;
109
110 /**
111 * Capability: This accessibility service can request touch exploration mode in which
112 * touched items are spoken aloud and the UI can be explored via gestures.
113 * @see android.R.styleable#AccessibilityService_canRequestTouchExplorationMode
114 */
115 public static final int CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION = 0x00000002;
116
117 /**
118 * @deprecated No longer used
119 */
120 public static final int CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY = 0x00000004;
121
122 /**
123 * Capability: This accessibility service can request to filter the key event stream.
124 * @see android.R.styleable#AccessibilityService_canRequestFilterKeyEvents
125 */
126 public static final int CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS = 0x00000008;
127
128 /**
129 * Capability: This accessibility service can control display magnification.
130 * @see android.R.styleable#AccessibilityService_canControlMagnification
131 */
132 public static final int CAPABILITY_CAN_CONTROL_MAGNIFICATION = 0x00000010;
133
134 /**
135 * Capability: This accessibility service can perform gestures.
136 * @see android.R.styleable#AccessibilityService_canPerformGestures
137 */
138 public static final int CAPABILITY_CAN_PERFORM_GESTURES = 0x00000020;
139
140 /**
141 * Capability: This accessibility service can capture gestures from the fingerprint sensor
142 * @see android.R.styleable#AccessibilityService_canRequestFingerprintGestures
143 */
144 public static final int CAPABILITY_CAN_REQUEST_FINGERPRINT_GESTURES = 0x00000040;
145
146 /**
147 * Capability: This accessibility service can take screenshot.
148 * @see android.R.styleable#AccessibilityService_canTakeScreenshot
149 */
150 public static final int CAPABILITY_CAN_TAKE_SCREENSHOT = 0x00000080;
151
152 private static SparseArray<CapabilityInfo> sAvailableCapabilityInfos;
153
154 /**
155 * Denotes spoken feedback.
156 */
157 public static final int FEEDBACK_SPOKEN = 0x0000001;
158
159 /**
160 * Denotes haptic feedback.
161 */
162 public static final int FEEDBACK_HAPTIC = 0x0000002;
163
164 /**
165 * Denotes audible (not spoken) feedback.
166 */
167 public static final int FEEDBACK_AUDIBLE = 0x0000004;
168
169 /**
170 * Denotes visual feedback.
171 */
172 public static final int FEEDBACK_VISUAL = 0x0000008;
173
174 /**
175 * Denotes generic feedback.
176 */
177 public static final int FEEDBACK_GENERIC = 0x0000010;
178
179 /**
180 * Denotes braille feedback.
181 */
182 public static final int FEEDBACK_BRAILLE = 0x0000020;
183
184 /**
185 * Mask for all feedback types.
186 *
187 * @see #FEEDBACK_SPOKEN
188 * @see #FEEDBACK_HAPTIC
189 * @see #FEEDBACK_AUDIBLE
190 * @see #FEEDBACK_VISUAL
191 * @see #FEEDBACK_GENERIC
192 * @see #FEEDBACK_BRAILLE
193 */
194 public static final int FEEDBACK_ALL_MASK = 0xFFFFFFFF;
195
196 /**
197 * If an {@link AccessibilityService} is the default for a given type.
198 * Default service is invoked only if no package specific one exists. In case of
199 * more than one package specific service only the earlier registered is notified.
200 */
201 public static final int DEFAULT = 0x0000001;
202
203 /**
204 * If this flag is set the system will regard views that are not important
205 * for accessibility in addition to the ones that are important for accessibility.
206 * That is, views that are marked as not important for accessibility via
207 * {@link View#IMPORTANT_FOR_ACCESSIBILITY_NO} or
208 * {@link View#IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS} and views that are
209 * marked as potentially important for accessibility via
210 * {@link View#IMPORTANT_FOR_ACCESSIBILITY_AUTO} for which the system has determined
211 * that are not important for accessibility, are reported while querying the window
212 * content and also the accessibility service will receive accessibility events from
213 * them.
214 * <p>
215 * <strong>Note:</strong> For accessibility services targeting Android 4.1 (API level 16) or
216 * higher, this flag has to be explicitly set for the system to regard views that are not
217 * important for accessibility. For accessibility services targeting Android 4.0.4 (API level
218 * 15) or lower, this flag is ignored and all views are regarded for accessibility purposes.
219 * </p>
220 * <p>
221 * Usually views not important for accessibility are layout managers that do not
222 * react to user actions, do not draw any content, and do not have any special
223 * semantics in the context of the screen content. For example, a three by three
224 * grid can be implemented as three horizontal linear layouts and one vertical,
225 * or three vertical linear layouts and one horizontal, or one grid layout, etc.
226 * In this context, the actual layout managers used to achieve the grid configuration
227 * are not important; rather it is important that there are nine evenly distributed
228 * elements.
229 * </p>
230 */
231 public static final int FLAG_INCLUDE_NOT_IMPORTANT_VIEWS = 0x0000002;
232
233 /**
234 * This flag requests that the system gets into touch exploration mode.
235 * In this mode a single finger moving on the screen behaves as a mouse
236 * pointer hovering over the user interface. The system will also detect
237 * certain gestures performed on the touch screen and notify this service.
238 * The system will enable touch exploration mode if there is at least one
239 * accessibility service that has this flag set. Hence, clearing this
240 * flag does not guarantee that the device will not be in touch exploration
241 * mode since there may be another enabled service that requested it.
242 * <p>
243 * For accessibility services targeting Android 4.3 (API level 18) or higher
244 * that want to set this flag have to declare this capability in their
245 * meta-data by setting the attribute
246 * {@link android.R.attr#canRequestTouchExplorationMode
247 * canRequestTouchExplorationMode} to true. Otherwise, this flag will
248 * be ignored. For how to declare the meta-data of a service refer to
249 * {@value AccessibilityService#SERVICE_META_DATA}.
250 * </p>
251 * <p>
252 * Services targeting Android 4.2.2 (API level 17) or lower will work
253 * normally. In other words, the first time they are run, if this flag is
254 * specified, a dialog is shown to the user to confirm enabling explore by
255 * touch.
256 * </p>
257 * @see android.R.styleable#AccessibilityService_canRequestTouchExplorationMode
258 */
259 public static final int FLAG_REQUEST_TOUCH_EXPLORATION_MODE = 0x0000004;
260
261 /**
262 * @deprecated No longer used
263 */
264 public static final int FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY = 0x00000008;
265
266 /**
267 * This flag requests that the {@link AccessibilityNodeInfo}s obtained
268 * by an {@link AccessibilityService} contain the id of the source view.
269 * The source view id will be a fully qualified resource name of the
270 * form "package:id/name", for example "foo.bar:id/my_list", and it is
271 * useful for UI test automation. This flag is not set by default.
272 */
273 public static final int FLAG_REPORT_VIEW_IDS = 0x00000010;
274
275 /**
276 * This flag requests from the system to filter key events. If this flag
277 * is set the accessibility service will receive the key events before
278 * applications allowing it implement global shortcuts.
279 * <p>
280 * Services that want to set this flag have to declare this capability
281 * in their meta-data by setting the attribute {@link android.R.attr
282 * #canRequestFilterKeyEvents canRequestFilterKeyEvents} to true,
283 * otherwise this flag will be ignored. For how to declare the meta-data
284 * of a service refer to {@value AccessibilityService#SERVICE_META_DATA}.
285 * </p>
286 * @see android.R.styleable#AccessibilityService_canRequestFilterKeyEvents
287 */
288 public static final int FLAG_REQUEST_FILTER_KEY_EVENTS = 0x00000020;
289
290 /**
291 * This flag indicates to the system that the accessibility service wants
292 * to access content of all interactive windows. An interactive window is a
293 * window that has input focus or can be touched by a sighted user when explore
294 * by touch is not enabled. If this flag is not set your service will not receive
295 * {@link android.view.accessibility.AccessibilityEvent#TYPE_WINDOWS_CHANGED}
296 * events, calling AccessibilityService{@link AccessibilityService#getWindows()
297 * AccessibilityService.getWindows()} will return an empty list, and {@link
298 * AccessibilityNodeInfo#getWindow() AccessibilityNodeInfo.getWindow()} will
299 * return null.
300 * <p>
301 * Services that want to set this flag have to declare the capability
302 * to retrieve window content in their meta-data by setting the attribute
303 * {@link android.R.attr#canRetrieveWindowContent canRetrieveWindowContent} to
304 * true, otherwise this flag will be ignored. For how to declare the meta-data
305 * of a service refer to {@value AccessibilityService#SERVICE_META_DATA}.
306 * </p>
307 * @see android.R.styleable#AccessibilityService_canRetrieveWindowContent
308 */
309 public static final int FLAG_RETRIEVE_INTERACTIVE_WINDOWS = 0x00000040;
310
311 /**
312 * This flag requests that all audio tracks system-wide with
313 * {@link android.media.AudioAttributes#USAGE_ASSISTANCE_ACCESSIBILITY} be controlled by the
314 * {@link android.media.AudioManager#STREAM_ACCESSIBILITY} volume.
315 */
316 public static final int FLAG_ENABLE_ACCESSIBILITY_VOLUME = 0x00000080;
317
318 /**
319 * This flag indicates to the system that the accessibility service requests that an
320 * accessibility button be shown within the system's navigation area, if available.
321 * <p>
322 * <strong>Note:</strong> For accessibility services targeting APIs greater than
323 * {@link Build.VERSION_CODES#Q API 29}, this flag must be specified in the
324 * accessibility service metadata file. Otherwise, it will be ignored.
325 * </p>
326 */
327 public static final int FLAG_REQUEST_ACCESSIBILITY_BUTTON = 0x00000100;
328
329 /**
330 * This flag requests that all fingerprint gestures be sent to the accessibility service.
331 * <p>
332 * Services that want to set this flag have to declare the capability
333 * to retrieve window content in their meta-data by setting the attribute
334 * {@link android.R.attr#canRequestFingerprintGestures} to
335 * true, otherwise this flag will be ignored. For how to declare the meta-data
336 * of a service refer to {@value AccessibilityService#SERVICE_META_DATA}.
337 * </p>
338 *
339 * @see android.R.styleable#AccessibilityService_canRequestFingerprintGestures
340 * @see AccessibilityService#getFingerprintGestureController()
341 */
342 public static final int FLAG_REQUEST_FINGERPRINT_GESTURES = 0x00000200;
343
344 /**
345 * This flag requests that accessibility shortcut warning dialog has spoken feedback when
346 * dialog is shown.
347 */
348 public static final int FLAG_REQUEST_SHORTCUT_WARNING_DIALOG_SPOKEN_FEEDBACK = 0x00000400;
349
350 /**
351 * This flag requests that when {@link #FLAG_REQUEST_TOUCH_EXPLORATION_MODE} is enabled,
352 * double tap and double tap and hold gestures are dispatched to the service rather than being
353 * handled by the framework. If {@link #FLAG_REQUEST_TOUCH_EXPLORATION_MODE} is disabled this
354 * flag has no effect.
355 *
356 * @see #FLAG_REQUEST_TOUCH_EXPLORATION_MODE
357 */
358 public static final int FLAG_SERVICE_HANDLES_DOUBLE_TAP = 0x0000800;
359
360 /**
361 * This flag requests that when when {@link #FLAG_REQUEST_TOUCH_EXPLORATION_MODE} is enabled,
362 * multi-finger gestures are also enabled. As a consequence, two-finger bypass gestures will be
363 * disabled. If {@link #FLAG_REQUEST_TOUCH_EXPLORATION_MODE} is disabled this flag has no
364 * effect.
365 *
366 * @see #FLAG_REQUEST_TOUCH_EXPLORATION_MODE
367 */
368 public static final int FLAG_REQUEST_MULTI_FINGER_GESTURES = 0x0001000;
369
370 /**
371 * This flag requests that when when {@link #FLAG_REQUEST_MULTI_FINGER_GESTURES} is enabled,
372 * two-finger passthrough gestures are re-enabled. Two-finger swipe gestures are not detected,
373 * but instead passed through as one-finger gestures. In addition, three-finger swipes from the
374 * bottom of the screen are not detected, and instead are passed through unchanged. If {@link
375 * #FLAG_REQUEST_MULTI_FINGER_GESTURES} is disabled this flag has no effect.
376 *
377 * @see #FLAG_REQUEST_TOUCH_EXPLORATION_MODE
378 */
379 public static final int FLAG_REQUEST_2_FINGER_PASSTHROUGH = 0x0002000;
380
381 /**
382 * This flag requests that when when {@link #FLAG_REQUEST_TOUCH_EXPLORATION_MODE} is enabled, a
383 * service will receive the motion events for each successfully-detected gesture. The service
384 * will also receive an AccessibilityGestureEvent of type GESTURE_INVALID for each cancelled
385 * gesture along with its motion events. A service will receive a gesture of type
386 * GESTURE_PASSTHROUGH and accompanying motion events for every passthrough gesture that does
387 * not start gesture detection. This information can be used to collect instances of improper
388 * gesture detection behavior and relay that information to framework developers. If {@link
389 * #FLAG_REQUEST_TOUCH_EXPLORATION_MODE} is disabled this flag has no effect.
390 *
391 * @see #FLAG_REQUEST_TOUCH_EXPLORATION_MODE
392 */
393 public static final int FLAG_SEND_MOTION_EVENTS = 0x0004000;
394
395 /**
396 * This flag makes the AccessibilityService an input method editor with a subset of input
397 * method editor capabilities: get the {@link android.view.inputmethod.InputConnection} and get
398 * text selection change notifications.
399 *
400 * @see AccessibilityService#getInputMethod()
401 */
402 public static final int FLAG_INPUT_METHOD_EDITOR = 0x0008000;
403
404 /** {@hide} */
405 public static final int FLAG_FORCE_DIRECT_BOOT_AWARE = 0x00010000;
406
407 /**
408 * The event types an {@link AccessibilityService} is interested in.
409 * <p>
410 * <strong>Can be dynamically set at runtime.</strong>
411 * </p>
412 * @see android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED
413 * @see android.view.accessibility.AccessibilityEvent#TYPE_VIEW_LONG_CLICKED
414 * @see android.view.accessibility.AccessibilityEvent#TYPE_VIEW_FOCUSED
415 * @see android.view.accessibility.AccessibilityEvent#TYPE_VIEW_SELECTED
416 * @see android.view.accessibility.AccessibilityEvent#TYPE_VIEW_TEXT_CHANGED
417 * @see android.view.accessibility.AccessibilityEvent#TYPE_WINDOW_STATE_CHANGED
418 * @see android.view.accessibility.AccessibilityEvent#TYPE_NOTIFICATION_STATE_CHANGED
419 * @see android.view.accessibility.AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_START
420 * @see android.view.accessibility.AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_END
421 * @see android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_ENTER
422 * @see android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_EXIT
423 * @see android.view.accessibility.AccessibilityEvent#TYPE_VIEW_SCROLLED
424 * @see android.view.accessibility.AccessibilityEvent#TYPE_VIEW_TEXT_SELECTION_CHANGED
425 * @see android.view.accessibility.AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED
426 * @see android.view.accessibility.AccessibilityEvent#TYPE_TOUCH_INTERACTION_START
427 * @see android.view.accessibility.AccessibilityEvent#TYPE_TOUCH_INTERACTION_END
428 * @see android.view.accessibility.AccessibilityEvent#TYPE_ANNOUNCEMENT
429 * @see android.view.accessibility.AccessibilityEvent#TYPE_GESTURE_DETECTION_START
430 * @see android.view.accessibility.AccessibilityEvent#TYPE_GESTURE_DETECTION_END
431 * @see android.view.accessibility.AccessibilityEvent#TYPE_VIEW_ACCESSIBILITY_FOCUSED
432 * @see android.view.accessibility.AccessibilityEvent#TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED
433 * @see android.view.accessibility.AccessibilityEvent#TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY
434 * @see android.view.accessibility.AccessibilityEvent#TYPE_WINDOWS_CHANGED
435 */
436 public int eventTypes;
437
438 /**
439 * The package names an {@link AccessibilityService} is interested in. Setting
440 * to <code>null</code> is equivalent to all packages.
441 * <p>
442 * <strong>Can be dynamically set at runtime.</strong>
443 * </p>
444 */
445 public String[] packageNames;
446
447
448 /** @hide */
449 @IntDef(flag = true, prefix = { "FEEDBACK_" }, value = {
450 FEEDBACK_AUDIBLE,
451 FEEDBACK_GENERIC,
452 FEEDBACK_HAPTIC,
453 FEEDBACK_SPOKEN,
454 FEEDBACK_VISUAL,
455 FEEDBACK_BRAILLE
456 })
457 @Retention(RetentionPolicy.SOURCE)
458 public @interface FeedbackType {}
459
460 /**
461 * The feedback type an {@link AccessibilityService} provides.
462 * <p>
463 * <strong>Can be dynamically set at runtime.</strong>
464 * </p>
465 * @see #FEEDBACK_AUDIBLE
466 * @see #FEEDBACK_GENERIC
467 * @see #FEEDBACK_HAPTIC
468 * @see #FEEDBACK_SPOKEN
469 * @see #FEEDBACK_VISUAL
470 * @see #FEEDBACK_BRAILLE
471 */
472 @FeedbackType
473 public int feedbackType;
474
475 /**
476 * The timeout, in milliseconds, after the most recent event of a given type before an
477 * {@link AccessibilityService} is notified.
478 * <p>
479 * <strong>Can be dynamically set at runtime.</strong>
480 * </p>
481 * <p>
482 * <strong>Note:</strong> The event notification timeout is useful to avoid propagating
483 * events to the client too frequently since this is accomplished via an expensive
484 * interprocess call. One can think of the timeout as a criteria to determine when
485 * event generation has settled down.
486 */
487 public long notificationTimeout;
488
489 /**
490 * This field represents a set of flags used for configuring an
491 * {@link AccessibilityService}.
492 * <p>
493 * <strong>Can be dynamically set at runtime.</strong>
494 * </p>
495 * <p>
496 * <strong>Note:</strong> Accessibility services with targetSdkVersion greater than
497 * {@link Build.VERSION_CODES#Q API 29} cannot dynamically set the
498 * {@link #FLAG_REQUEST_ACCESSIBILITY_BUTTON} at runtime. It must be specified in the
499 * accessibility service metadata file.
500 * </p>
501 * @see #DEFAULT
502 * @see #FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
503 * @see #FLAG_REQUEST_TOUCH_EXPLORATION_MODE
504 * @see #FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY
505 * @see #FLAG_REQUEST_FILTER_KEY_EVENTS
506 * @see #FLAG_REPORT_VIEW_IDS
507 * @see #FLAG_RETRIEVE_INTERACTIVE_WINDOWS
508 * @see #FLAG_ENABLE_ACCESSIBILITY_VOLUME
509 * @see #FLAG_REQUEST_ACCESSIBILITY_BUTTON
510 * @see #FLAG_REQUEST_SHORTCUT_WARNING_DIALOG_SPOKEN_FEEDBACK
511 * @see #FLAG_INPUT_METHOD_EDITOR
512 */
513 public int flags;
514
515 /**
516 * Whether or not the service has crashed and is awaiting restart. Only valid from {@link
517 * android.view.accessibility.AccessibilityManager#getInstalledAccessibilityServiceList()},
518 * because that is populated from the internal list of running services.
519 *
520 * @hide
521 */
522 public boolean crashed;
523
524 /**
525 * A recommended timeout in milliseconds for non-interactive controls.
526 */
527 private int mNonInteractiveUiTimeout;
528
529 /**
530 * A recommended timeout in milliseconds for interactive controls.
531 */
532 private int mInteractiveUiTimeout;
533
534 /**
535 * The component name the accessibility service.
536 */
537 @NonNull
538 private ComponentName mComponentName;
539
540 /**
541 * The Service that implements this accessibility service component.
542 */
543 private ResolveInfo mResolveInfo;
544
545 /**
546 * The accessibility service setting activity's name, used by the system
547 * settings to launch the setting activity of this accessibility service.
548 */
549 private String mSettingsActivityName;
550
551 /**
552 * The name of {@link android.service.quicksettings.TileService} is associated with this
553 * accessibility service for one to one mapping. It is used by system settings to remind users
554 * this accessibility service has a {@link android.service.quicksettings.TileService}.
555 */
556 private String mTileServiceName;
557
558 /**
559 * Bit mask with capabilities of this service.
560 */
561 private int mCapabilities;
562
563 /**
564 * Resource id of the summary of the accessibility service.
565 */
566 private int mSummaryResId;
567
568 /**
569 * Non-localized summary of the accessibility service.
570 */
571 private String mNonLocalizedSummary;
572
573 /**
574 * Resource id of the intro of the accessibility service.
575 */
576 private int mIntroResId;
577
578 /**
579 * Resource id of the description of the accessibility service.
580 */
581 private int mDescriptionResId;
582
583 /**
584 * Non localized description of the accessibility service.
585 */
586 private String mNonLocalizedDescription;
587
588 /**
589 * For accessibility services targeting APIs greater than {@link Build.VERSION_CODES#Q API 29},
590 * {@link #FLAG_REQUEST_ACCESSIBILITY_BUTTON} must be specified in the accessibility service
591 * metadata file. Otherwise, it will be ignored.
592 */
593 @ChangeId
594 @EnabledAfter(targetSdkVersion = android.os.Build.VERSION_CODES.Q)
595 private static final long REQUEST_ACCESSIBILITY_BUTTON_CHANGE = 136293963L;
596
597 /**
598 * Resource id of the animated image of the accessibility service.
599 */
600 private int mAnimatedImageRes;
601
602 /**
603 * Resource id of the html description of the accessibility service.
604 */
605 private int mHtmlDescriptionRes;
606
607 /**
608 * Whether the service is for accessibility.
609 *
610 * @hide
611 */
612 private boolean mIsAccessibilityTool = false;
613
614 /**
615 * Creates a new instance.
616 */
617 public AccessibilityServiceInfo() {
618 /* do nothing */
619 }
620
621 /**
622 * Creates a new instance.
623 *
624 * @param resolveInfo The service resolve info.
625 * @param context Context for accessing resources.
626 * @throws XmlPullParserException If a XML parsing error occurs.
627 * @throws IOException If a XML parsing error occurs.
628 *
629 * @hide
630 */
631 public AccessibilityServiceInfo(ResolveInfo resolveInfo, Context context)
632 throws XmlPullParserException, IOException {
633 ServiceInfo serviceInfo = resolveInfo.serviceInfo;
634 mComponentName = new ComponentName(serviceInfo.packageName, serviceInfo.name);
635 mResolveInfo = resolveInfo;
636
637 XmlResourceParser parser = null;
638
639 try {
640 PackageManager packageManager = context.getPackageManager();
641 parser = serviceInfo.loadXmlMetaData(packageManager,
642 AccessibilityService.SERVICE_META_DATA);
643 if (parser == null) {
644 return;
645 }
646
647 int type = 0;
648 while (type != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
649 type = parser.next();
650 }
651
652 String nodeName = parser.getName();
653 if (!TAG_ACCESSIBILITY_SERVICE.equals(nodeName)) {
654 throw new XmlPullParserException( "Meta-data does not start with"
655 + TAG_ACCESSIBILITY_SERVICE + " tag");
656 }
657
658 AttributeSet allAttributes = Xml.asAttributeSet(parser);
659 Resources resources = packageManager.getResourcesForApplication(
660 serviceInfo.applicationInfo);
661 TypedArray asAttributes = resources.obtainAttributes(allAttributes,
662 com.android.internal.R.styleable.AccessibilityService);
663 eventTypes = asAttributes.getInt(
664 com.android.internal.R.styleable.AccessibilityService_accessibilityEventTypes,
665 0);
666 String packageNamez = asAttributes.getString(
667 com.android.internal.R.styleable.AccessibilityService_packageNames);
668 if (packageNamez != null) {
669 packageNames = packageNamez.split("(\\s)*,(\\s)*");
670 }
671 feedbackType = asAttributes.getInt(
672 com.android.internal.R.styleable.AccessibilityService_accessibilityFeedbackType,
673 0);
674 notificationTimeout = asAttributes.getInt(
675 com.android.internal.R.styleable.AccessibilityService_notificationTimeout,
676 0);
677 mNonInteractiveUiTimeout = asAttributes.getInt(
678 com.android.internal.R.styleable.AccessibilityService_nonInteractiveUiTimeout,
679 0);
680 mInteractiveUiTimeout = asAttributes.getInt(
681 com.android.internal.R.styleable.AccessibilityService_interactiveUiTimeout,
682 0);
683 flags = asAttributes.getInt(
684 com.android.internal.R.styleable.AccessibilityService_accessibilityFlags, 0);
685 mSettingsActivityName = asAttributes.getString(
686 com.android.internal.R.styleable.AccessibilityService_settingsActivity);
687 if (asAttributes.getBoolean(com.android.internal.R.styleable
688 .AccessibilityService_canRetrieveWindowContent, false)) {
689 mCapabilities |= CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT;
690 }
691 if (asAttributes.getBoolean(com.android.internal.R.styleable
692 .AccessibilityService_canRequestTouchExplorationMode, false)) {
693 mCapabilities |= CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION;
694 }
695 if (asAttributes.getBoolean(com.android.internal.R.styleable
696 .AccessibilityService_canRequestFilterKeyEvents, false)) {
697 mCapabilities |= CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS;
698 }
699 if (asAttributes.getBoolean(com.android.internal.R.styleable
700 .AccessibilityService_canControlMagnification, false)) {
701 mCapabilities |= CAPABILITY_CAN_CONTROL_MAGNIFICATION;
702 }
703 if (asAttributes.getBoolean(com.android.internal.R.styleable
704 .AccessibilityService_canPerformGestures, false)) {
705 mCapabilities |= CAPABILITY_CAN_PERFORM_GESTURES;
706 }
707 if (asAttributes.getBoolean(com.android.internal.R.styleable
708 .AccessibilityService_canRequestFingerprintGestures, false)) {
709 mCapabilities |= CAPABILITY_CAN_REQUEST_FINGERPRINT_GESTURES;
710 }
711 if (asAttributes.getBoolean(com.android.internal.R.styleable
712 .AccessibilityService_canTakeScreenshot, false)) {
713 mCapabilities |= CAPABILITY_CAN_TAKE_SCREENSHOT;
714 }
715 TypedValue peekedValue = asAttributes.peekValue(
716 com.android.internal.R.styleable.AccessibilityService_description);
717 if (peekedValue != null) {
718 mDescriptionResId = peekedValue.resourceId;
719 CharSequence nonLocalizedDescription = peekedValue.coerceToString();
720 if (nonLocalizedDescription != null) {
721 mNonLocalizedDescription = nonLocalizedDescription.toString().trim();
722 }
723 }
724 peekedValue = asAttributes.peekValue(
725 com.android.internal.R.styleable.AccessibilityService_summary);
726 if (peekedValue != null) {
727 mSummaryResId = peekedValue.resourceId;
728 CharSequence nonLocalizedSummary = peekedValue.coerceToString();
729 if (nonLocalizedSummary != null) {
730 mNonLocalizedSummary = nonLocalizedSummary.toString().trim();
731 }
732 }
733 peekedValue = asAttributes.peekValue(
734 com.android.internal.R.styleable.AccessibilityService_animatedImageDrawable);
735 if (peekedValue != null) {
736 mAnimatedImageRes = peekedValue.resourceId;
737 }
738 peekedValue = asAttributes.peekValue(
739 com.android.internal.R.styleable.AccessibilityService_htmlDescription);
740 if (peekedValue != null) {
741 mHtmlDescriptionRes = peekedValue.resourceId;
742 }
743 mIsAccessibilityTool = asAttributes.getBoolean(
744 R.styleable.AccessibilityService_isAccessibilityTool, false);
745 mTileServiceName = asAttributes.getString(
746 com.android.internal.R.styleable.AccessibilityService_tileService);
747 peekedValue = asAttributes.peekValue(
748 com.android.internal.R.styleable.AccessibilityService_intro);
749 if (peekedValue != null) {
750 mIntroResId = peekedValue.resourceId;
751 }
752 asAttributes.recycle();
753 } catch (NameNotFoundException e) {
754 throw new XmlPullParserException( "Unable to create context for: "
755 + serviceInfo.packageName);
756 } finally {
757 if (parser != null) {
758 parser.close();
759 }
760 }
761 }
762
763 /**
764 * Updates the properties that an AccessibilityService can change dynamically.
765 * <p>
766 * Note: A11y services targeting APIs > Q, it cannot update flagRequestAccessibilityButton
767 * dynamically.
768 * </p>
769 *
770 * @param platformCompat The platform compat service to check the compatibility change.
771 * @param other The info from which to update the properties.
772 *
773 * @hide
774 */
775 public void updateDynamicallyConfigurableProperties(IPlatformCompat platformCompat,
776 AccessibilityServiceInfo other) {
777 if (isRequestAccessibilityButtonChangeEnabled(platformCompat)) {
778 other.flags &= ~FLAG_REQUEST_ACCESSIBILITY_BUTTON;
779 other.flags |= (flags & FLAG_REQUEST_ACCESSIBILITY_BUTTON);
780 }
781 eventTypes = other.eventTypes;
782 packageNames = other.packageNames;
783 feedbackType = other.feedbackType;
784 notificationTimeout = other.notificationTimeout;
785 mNonInteractiveUiTimeout = other.mNonInteractiveUiTimeout;
786 mInteractiveUiTimeout = other.mInteractiveUiTimeout;
787 flags = other.flags;
788 }
789
790 private boolean isRequestAccessibilityButtonChangeEnabled(IPlatformCompat platformCompat) {
791 if (mResolveInfo == null) {
792 return true;
793 }
794 try {
795 if (platformCompat != null) {
796 return platformCompat.isChangeEnabled(REQUEST_ACCESSIBILITY_BUTTON_CHANGE,
797 mResolveInfo.serviceInfo.applicationInfo);
798 }
799 } catch (RemoteException ignore) {
800 }
801 return mResolveInfo.serviceInfo.applicationInfo.targetSdkVersion > Build.VERSION_CODES.Q;
802 }
803
804 /**
805 * @hide
806 */
807 public void setComponentName(@NonNull ComponentName component) {
808 mComponentName = component;
809 }
810
811 /**
812 * @hide
813 */
814 @TestApi
815 @NonNull
816 public ComponentName getComponentName() {
817 return mComponentName;
818 }
819
820 /**
821 * The accessibility service id.
822 * <p>
823 * <strong>Generated by the system.</strong>
824 * </p>
825 * @return The id.
826 */
827 public String getId() {
828 return mComponentName.flattenToShortString();
829 }
830
831 /**
832 * The service {@link ResolveInfo}.
833 * <p>
834 * <strong>Generated by the system.</strong>
835 * </p>
836 * @return The info.
837 */
838 public ResolveInfo getResolveInfo() {
839 return mResolveInfo;
840 }
841
842 /**
843 * The settings activity name.
844 * <p>
845 * <strong>Statically set from
846 * {@link AccessibilityService#SERVICE_META_DATA meta-data}.</strong>
847 * </p>
848 * @return The settings activity name.
849 */
850 public String getSettingsActivityName() {
851 return mSettingsActivityName;
852 }
853
854 /**
855 * Gets the name of {@link android.service.quicksettings.TileService} is associated with
856 * this accessibility service.
857 *
858 * @return The name of {@link android.service.quicksettings.TileService}.
859 */
860 @Nullable
861 public String getTileServiceName() {
862 return mTileServiceName;
863 }
864
865 /**
866 * Gets the animated image resource id.
867 *
868 * @return The animated image resource id.
869 *
870 * @hide
871 */
872 public int getAnimatedImageRes() {
873 return mAnimatedImageRes;
874 }
875
876 /**
877 * The animated image drawable.
878 * <p>
879 * Image can not exceed the screen size.
880 * <strong>Statically set from
881 * {@link AccessibilityService#SERVICE_META_DATA meta-data}.</strong>
882 * </p>
883 * @return The animated image drawable, or null if the resource is invalid or the image
884 * exceed the screen size.
885 *
886 * @hide
887 */
888 @Nullable
889 public Drawable loadAnimatedImage(@NonNull Context context) {
890 if (mAnimatedImageRes == /* invalid */ 0) {
891 return null;
892 }
893
894 return loadSafeAnimatedImage(context, mResolveInfo.serviceInfo.applicationInfo,
895 mAnimatedImageRes);
896 }
897
898 /**
899 * Whether this service can retrieve the current window's content.
900 * <p>
901 * <strong>Statically set from
902 * {@link AccessibilityService#SERVICE_META_DATA meta-data}.</strong>
903 * </p>
904 * @return True if window content can be retrieved.
905 *
906 * @deprecated Use {@link #getCapabilities()}.
907 */
908 public boolean getCanRetrieveWindowContent() {
909 return (mCapabilities & CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT) != 0;
910 }
911
912 /**
913 * Returns the bit mask of capabilities this accessibility service has such as
914 * being able to retrieve the active window content, etc.
915 *
916 * @return The capability bit mask.
917 *
918 * @see #CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT
919 * @see #CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION
920 * @see #CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS
921 * @see #CAPABILITY_CAN_CONTROL_MAGNIFICATION
922 * @see #CAPABILITY_CAN_PERFORM_GESTURES
923 * @see #CAPABILITY_CAN_TAKE_SCREENSHOT
924 */
925 public int getCapabilities() {
926 return mCapabilities;
927 }
928
929 /**
930 * Sets the bit mask of capabilities this accessibility service has such as
931 * being able to retrieve the active window content, etc.
932 *
933 * @param capabilities The capability bit mask.
934 *
935 * @see #CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT
936 * @see #CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION
937 * @see #CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS
938 * @see #CAPABILITY_CAN_CONTROL_MAGNIFICATION
939 * @see #CAPABILITY_CAN_PERFORM_GESTURES
940 * @see #CAPABILITY_CAN_TAKE_SCREENSHOT
941 *
942 * @hide
943 */
944 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
945 public void setCapabilities(int capabilities) {
946 mCapabilities = capabilities;
947 }
948
949 /**
950 * The localized summary of the accessibility service.
951 * <p>
952 * <strong>Statically set from
953 * {@link AccessibilityService#SERVICE_META_DATA meta-data}.</strong>
954 * </p>
955 * @return The localized summary if available, and {@code null} if a summary
956 * has not been provided.
957 */
958 public CharSequence loadSummary(PackageManager packageManager) {
959 if (mSummaryResId == 0) {
960 return mNonLocalizedSummary;
961 }
962 ServiceInfo serviceInfo = mResolveInfo.serviceInfo;
963 CharSequence summary = packageManager.getText(serviceInfo.packageName,
964 mSummaryResId, serviceInfo.applicationInfo);
965 if (summary != null) {
966 return summary.toString().trim();
967 }
968 return null;
969 }
970
971 /**
972 * The localized intro of the accessibility service.
973 * <p>
974 * <strong>Statically set from
975 * {@link AccessibilityService#SERVICE_META_DATA meta-data}.</strong>
976 * </p>
977 * @return The localized intro if available, and {@code null} if a intro
978 * has not been provided.
979 */
980 @Nullable
981 public CharSequence loadIntro(@NonNull PackageManager packageManager) {
982 if (mIntroResId == /* invalid */ 0) {
983 return null;
984 }
985 ServiceInfo serviceInfo = mResolveInfo.serviceInfo;
986 CharSequence intro = packageManager.getText(serviceInfo.packageName,
987 mIntroResId, serviceInfo.applicationInfo);
988 if (intro != null) {
989 return intro.toString().trim();
990 }
991 return null;
992 }
993
994 /**
995 * Gets the non-localized description of the accessibility service.
996 * <p>
997 * <strong>Statically set from
998 * {@link AccessibilityService#SERVICE_META_DATA meta-data}.</strong>
999 * </p>
1000 * @return The description.
1001 *
1002 * @deprecated Use {@link #loadDescription(PackageManager)}.
1003 */
1004 public String getDescription() {
1005 return mNonLocalizedDescription;
1006 }
1007
1008 /**
1009 * The localized description of the accessibility service.
1010 * <p>
1011 * <strong>Statically set from
1012 * {@link AccessibilityService#SERVICE_META_DATA meta-data}.</strong>
1013 * </p>
1014 * @return The localized description.
1015 */
1016 public String loadDescription(PackageManager packageManager) {
1017 if (mDescriptionResId == 0) {
1018 return mNonLocalizedDescription;
1019 }
1020 ServiceInfo serviceInfo = mResolveInfo.serviceInfo;
1021 CharSequence description = packageManager.getText(serviceInfo.packageName,
1022 mDescriptionResId, serviceInfo.applicationInfo);
1023 if (description != null) {
1024 return description.toString().trim();
1025 }
1026 return null;
1027 }
1028
1029 /**
1030 * The localized and restricted html description of the accessibility service.
1031 * <p>
1032 * Filters the <img> tag which do not meet the custom specification and the <a> tag.
1033 * <strong>Statically set from
1034 * {@link AccessibilityService#SERVICE_META_DATA meta-data}.</strong>
1035 * </p>
1036 * @return The localized and restricted html description.
1037 *
1038 * @hide
1039 */
1040 @Nullable
1041 public String loadHtmlDescription(@NonNull PackageManager packageManager) {
1042 if (mHtmlDescriptionRes == /* invalid */ 0) {
1043 return null;
1044 }
1045
1046 final ServiceInfo serviceInfo = mResolveInfo.serviceInfo;
1047 final CharSequence htmlDescription = packageManager.getText(serviceInfo.packageName,
1048 mHtmlDescriptionRes, serviceInfo.applicationInfo);
1049 if (htmlDescription != null) {
1050 return getFilteredHtmlText(htmlDescription.toString().trim());
1051 }
1052 return null;
1053 }
1054
1055 /**
1056 * Set the recommended time that non-interactive controls need to remain on the screen to
1057 * support the user.
1058 * <p>
1059 * <strong>This value can be dynamically set at runtime by
1060 * {@link AccessibilityService#setServiceInfo(AccessibilityServiceInfo)}.</strong>
1061 * </p>
1062 *
1063 * @param timeout The timeout in milliseconds.
1064 *
1065 * @see android.R.styleable#AccessibilityService_nonInteractiveUiTimeout
1066 */
1067 public void setNonInteractiveUiTimeoutMillis(@IntRange(from = 0) int timeout) {
1068 mNonInteractiveUiTimeout = timeout;
1069 }
1070
1071 /**
1072 * Get the recommended timeout for non-interactive controls.
1073 *
1074 * @return The timeout in milliseconds.
1075 *
1076 * @see #setNonInteractiveUiTimeoutMillis(int)
1077 */
1078 public int getNonInteractiveUiTimeoutMillis() {
1079 return mNonInteractiveUiTimeout;
1080 }
1081
1082 /**
1083 * Set the recommended time that interactive controls need to remain on the screen to
1084 * support the user.
1085 * <p>
1086 * <strong>This value can be dynamically set at runtime by
1087 * {@link AccessibilityService#setServiceInfo(AccessibilityServiceInfo)}.</strong>
1088 * </p>
1089 *
1090 * @param timeout The timeout in milliseconds.
1091 *
1092 * @see android.R.styleable#AccessibilityService_interactiveUiTimeout
1093 */
1094 public void setInteractiveUiTimeoutMillis(@IntRange(from = 0) int timeout) {
1095 mInteractiveUiTimeout = timeout;
1096 }
1097
1098 /**
1099 * Get the recommended timeout for interactive controls.
1100 *
1101 * @return The timeout in milliseconds.
1102 *
1103 * @see #setInteractiveUiTimeoutMillis(int)
1104 */
1105 public int getInteractiveUiTimeoutMillis() {
1106 return mInteractiveUiTimeout;
1107 }
1108
1109 /** {@hide} */
1110 public boolean isDirectBootAware() {
1111 return ((flags & FLAG_FORCE_DIRECT_BOOT_AWARE) != 0)
1112 || mResolveInfo.serviceInfo.directBootAware;
1113 }
1114
1115 /**
1116 * Indicates if the service is used to assist users with disabilities.
1117 *
1118 * @return {@code true} if the property is set to true.
1119 */
1120 public boolean isAccessibilityTool() {
1121 return mIsAccessibilityTool;
1122 }
1123
1124 /**
1125 * {@inheritDoc}
1126 */
1127 public int describeContents() {
1128 return 0;
1129 }
1130
1131 public void writeToParcel(Parcel parcel, int flagz) {
1132 parcel.writeInt(eventTypes);
1133 parcel.writeStringArray(packageNames);
1134 parcel.writeInt(feedbackType);
1135 parcel.writeLong(notificationTimeout);
1136 parcel.writeInt(mNonInteractiveUiTimeout);
1137 parcel.writeInt(mInteractiveUiTimeout);
1138 parcel.writeInt(flags);
1139 parcel.writeInt(crashed ? 1 : 0);
1140 parcel.writeParcelable(mComponentName, flagz);
1141 parcel.writeParcelable(mResolveInfo, 0);
1142 parcel.writeString(mSettingsActivityName);
1143 parcel.writeInt(mCapabilities);
1144 parcel.writeInt(mSummaryResId);
1145 parcel.writeString(mNonLocalizedSummary);
1146 parcel.writeInt(mDescriptionResId);
1147 parcel.writeInt(mAnimatedImageRes);
1148 parcel.writeInt(mHtmlDescriptionRes);
1149 parcel.writeString(mNonLocalizedDescription);
1150 parcel.writeBoolean(mIsAccessibilityTool);
1151 parcel.writeString(mTileServiceName);
1152 parcel.writeInt(mIntroResId);
1153 }
1154
1155 private void initFromParcel(Parcel parcel) {
1156 eventTypes = parcel.readInt();
1157 packageNames = parcel.readStringArray();
1158 feedbackType = parcel.readInt();
1159 notificationTimeout = parcel.readLong();
1160 mNonInteractiveUiTimeout = parcel.readInt();
1161 mInteractiveUiTimeout = parcel.readInt();
1162 flags = parcel.readInt();
1163 crashed = parcel.readInt() != 0;
1164 mComponentName = parcel.readParcelable(this.getClass().getClassLoader(), android.content.ComponentName.class);
1165 mResolveInfo = parcel.readParcelable(null, android.content.pm.ResolveInfo.class);
1166 mSettingsActivityName = parcel.readString();
1167 mCapabilities = parcel.readInt();
1168 mSummaryResId = parcel.readInt();
1169 mNonLocalizedSummary = parcel.readString();
1170 mDescriptionResId = parcel.readInt();
1171 mAnimatedImageRes = parcel.readInt();
1172 mHtmlDescriptionRes = parcel.readInt();
1173 mNonLocalizedDescription = parcel.readString();
1174 mIsAccessibilityTool = parcel.readBoolean();
1175 mTileServiceName = parcel.readString();
1176 mIntroResId = parcel.readInt();
1177 }
1178
1179 @Override
1180 public int hashCode() {
1181 return 31 * 1 + ((mComponentName == null) ? 0 : mComponentName.hashCode());
1182 }
1183
1184 @Override
1185 public boolean equals(@Nullable Object obj) {
1186 if (this == obj) {
1187 return true;
1188 }
1189 if (obj == null) {
1190 return false;
1191 }
1192 if (getClass() != obj.getClass()) {
1193 return false;
1194 }
1195 AccessibilityServiceInfo other = (AccessibilityServiceInfo) obj;
1196 if (mComponentName == null) {
1197 if (other.mComponentName != null) {
1198 return false;
1199 }
1200 } else if (!mComponentName.equals(other.mComponentName)) {
1201 return false;
1202 }
1203 return true;
1204 }
1205
1206 @Override
1207 public String toString() {
1208 StringBuilder stringBuilder = new StringBuilder();
1209 appendEventTypes(stringBuilder, eventTypes);
1210 stringBuilder.append(", ");
1211 appendPackageNames(stringBuilder, packageNames);
1212 stringBuilder.append(", ");
1213 appendFeedbackTypes(stringBuilder, feedbackType);
1214 stringBuilder.append(", ");
1215 stringBuilder.append("notificationTimeout: ").append(notificationTimeout);
1216 stringBuilder.append(", ");
1217 stringBuilder.append("nonInteractiveUiTimeout: ").append(mNonInteractiveUiTimeout);
1218 stringBuilder.append(", ");
1219 stringBuilder.append("interactiveUiTimeout: ").append(mInteractiveUiTimeout);
1220 stringBuilder.append(", ");
1221 appendFlags(stringBuilder, flags);
1222 stringBuilder.append(", ");
1223 stringBuilder.append("id: ").append(getId());
1224 stringBuilder.append(", ");
1225 stringBuilder.append("resolveInfo: ").append(mResolveInfo);
1226 stringBuilder.append(", ");
1227 stringBuilder.append("settingsActivityName: ").append(mSettingsActivityName);
1228 stringBuilder.append(", ");
1229 stringBuilder.append("tileServiceName: ").append(mTileServiceName);
1230 stringBuilder.append(", ");
1231 stringBuilder.append("summary: ").append(mNonLocalizedSummary);
1232 stringBuilder.append(", ");
1233 stringBuilder.append("isAccessibilityTool: ").append(mIsAccessibilityTool);
1234 stringBuilder.append(", ");
1235 appendCapabilities(stringBuilder, mCapabilities);
1236 return stringBuilder.toString();
1237 }
1238
1239 private static void appendFeedbackTypes(StringBuilder stringBuilder,
1240 @FeedbackType int feedbackTypes) {
1241 stringBuilder.append("feedbackTypes:");
1242 stringBuilder.append("[");
1243 while (feedbackTypes != 0) {
1244 final int feedbackTypeBit = (1 << Integer.numberOfTrailingZeros(feedbackTypes));
1245 stringBuilder.append(feedbackTypeToString(feedbackTypeBit));
1246 feedbackTypes &= ~feedbackTypeBit;
1247 if (feedbackTypes != 0) {
1248 stringBuilder.append(", ");
1249 }
1250 }
1251 stringBuilder.append("]");
1252 }
1253
1254 private static void appendPackageNames(StringBuilder stringBuilder, String[] packageNames) {
1255 stringBuilder.append("packageNames:");
1256 stringBuilder.append("[");
1257 if (packageNames != null) {
1258 final int packageNameCount = packageNames.length;
1259 for (int i = 0; i < packageNameCount; i++) {
1260 stringBuilder.append(packageNames[i]);
1261 if (i < packageNameCount - 1) {
1262 stringBuilder.append(", ");
1263 }
1264 }
1265 }
1266 stringBuilder.append("]");
1267 }
1268
1269 private static void appendEventTypes(StringBuilder stringBuilder, int eventTypes) {
1270 stringBuilder.append("eventTypes:");
1271 stringBuilder.append("[");
1272 while (eventTypes != 0) {
1273 final int eventTypeBit = (1 << Integer.numberOfTrailingZeros(eventTypes));
1274 stringBuilder.append(AccessibilityEvent.eventTypeToString(eventTypeBit));
1275 eventTypes &= ~eventTypeBit;
1276 if (eventTypes != 0) {
1277 stringBuilder.append(", ");
1278 }
1279 }
1280 stringBuilder.append("]");
1281 }
1282
1283 private static void appendFlags(StringBuilder stringBuilder, int flags) {
1284 stringBuilder.append("flags:");
1285 stringBuilder.append("[");
1286 while (flags != 0) {
1287 final int flagBit = (1 << Integer.numberOfTrailingZeros(flags));
1288 stringBuilder.append(flagToString(flagBit));
1289 flags &= ~flagBit;
1290 if (flags != 0) {
1291 stringBuilder.append(", ");
1292 }
1293 }
1294 stringBuilder.append("]");
1295 }
1296
1297 private static void appendCapabilities(StringBuilder stringBuilder, int capabilities) {
1298 stringBuilder.append("capabilities:");
1299 stringBuilder.append("[");
1300 while (capabilities != 0) {
1301 final int capabilityBit = (1 << Integer.numberOfTrailingZeros(capabilities));
1302 stringBuilder.append(capabilityToString(capabilityBit));
1303 capabilities &= ~capabilityBit;
1304 if (capabilities != 0) {
1305 stringBuilder.append(", ");
1306 }
1307 }
1308 stringBuilder.append("]");
1309 }
1310
1311 /**
1312 * Returns the string representation of a feedback type. For example,
1313 * {@link #FEEDBACK_SPOKEN} is represented by the string FEEDBACK_SPOKEN.
1314 *
1315 * @param feedbackType The feedback type.
1316 * @return The string representation.
1317 */
1318 public static String feedbackTypeToString(int feedbackType) {
1319 StringBuilder builder = new StringBuilder();
1320 builder.append("[");
1321 while (feedbackType != 0) {
1322 final int feedbackTypeFlag = 1 << Integer.numberOfTrailingZeros(feedbackType);
1323 feedbackType &= ~feedbackTypeFlag;
1324 switch (feedbackTypeFlag) {
1325 case FEEDBACK_AUDIBLE:
1326 if (builder.length() > 1) {
1327 builder.append(", ");
1328 }
1329 builder.append("FEEDBACK_AUDIBLE");
1330 break;
1331 case FEEDBACK_HAPTIC:
1332 if (builder.length() > 1) {
1333 builder.append(", ");
1334 }
1335 builder.append("FEEDBACK_HAPTIC");
1336 break;
1337 case FEEDBACK_GENERIC:
1338 if (builder.length() > 1) {
1339 builder.append(", ");
1340 }
1341 builder.append("FEEDBACK_GENERIC");
1342 break;
1343 case FEEDBACK_SPOKEN:
1344 if (builder.length() > 1) {
1345 builder.append(", ");
1346 }
1347 builder.append("FEEDBACK_SPOKEN");
1348 break;
1349 case FEEDBACK_VISUAL:
1350 if (builder.length() > 1) {
1351 builder.append(", ");
1352 }
1353 builder.append("FEEDBACK_VISUAL");
1354 break;
1355 case FEEDBACK_BRAILLE:
1356 if (builder.length() > 1) {
1357 builder.append(", ");
1358 }
1359 builder.append("FEEDBACK_BRAILLE");
1360 break;
1361 }
1362 }
1363 builder.append("]");
1364 return builder.toString();
1365 }
1366
1367 /**
1368 * Returns the string representation of a flag. For example,
1369 * {@link #DEFAULT} is represented by the string DEFAULT.
1370 *
1371 * @param flag The flag.
1372 * @return The string representation.
1373 */
1374 public static String flagToString(int flag) {
1375 switch (flag) {
1376 case DEFAULT:
1377 return "DEFAULT";
1378 case FLAG_INCLUDE_NOT_IMPORTANT_VIEWS:
1379 return "FLAG_INCLUDE_NOT_IMPORTANT_VIEWS";
1380 case FLAG_REQUEST_TOUCH_EXPLORATION_MODE:
1381 return "FLAG_REQUEST_TOUCH_EXPLORATION_MODE";
1382 case FLAG_SERVICE_HANDLES_DOUBLE_TAP:
1383 return "FLAG_SERVICE_HANDLES_DOUBLE_TAP";
1384 case FLAG_REQUEST_MULTI_FINGER_GESTURES:
1385 return "FLAG_REQUEST_MULTI_FINGER_GESTURES";
1386 case FLAG_REQUEST_2_FINGER_PASSTHROUGH:
1387 return "FLAG_REQUEST_2_FINGER_PASSTHROUGH";
1388 case FLAG_SEND_MOTION_EVENTS:
1389 return "FLAG_SEND_MOTION_EVENTS";
1390 case FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY:
1391 return "FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY";
1392 case FLAG_REPORT_VIEW_IDS:
1393 return "FLAG_REPORT_VIEW_IDS";
1394 case FLAG_REQUEST_FILTER_KEY_EVENTS:
1395 return "FLAG_REQUEST_FILTER_KEY_EVENTS";
1396 case FLAG_RETRIEVE_INTERACTIVE_WINDOWS:
1397 return "FLAG_RETRIEVE_INTERACTIVE_WINDOWS";
1398 case FLAG_ENABLE_ACCESSIBILITY_VOLUME:
1399 return "FLAG_ENABLE_ACCESSIBILITY_VOLUME";
1400 case FLAG_REQUEST_ACCESSIBILITY_BUTTON:
1401 return "FLAG_REQUEST_ACCESSIBILITY_BUTTON";
1402 case FLAG_REQUEST_FINGERPRINT_GESTURES:
1403 return "FLAG_REQUEST_FINGERPRINT_GESTURES";
1404 case FLAG_REQUEST_SHORTCUT_WARNING_DIALOG_SPOKEN_FEEDBACK:
1405 return "FLAG_REQUEST_SHORTCUT_WARNING_DIALOG_SPOKEN_FEEDBACK";
1406 case FLAG_INPUT_METHOD_EDITOR:
1407 return "FLAG_INPUT_METHOD_EDITOR";
1408 default:
1409 return null;
1410 }
1411 }
1412
1413 /**
1414 * Returns the string representation of a capability. For example,
1415 * {@link #CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT} is represented
1416 * by the string CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT.
1417 *
1418 * @param capability The capability.
1419 * @return The string representation.
1420 */
1421 public static String capabilityToString(int capability) {
1422 switch (capability) {
1423 case CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT:
1424 return "CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT";
1425 case CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION:
1426 return "CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION";
1427 case CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY:
1428 return "CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY";
1429 case CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS:
1430 return "CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS";
1431 case CAPABILITY_CAN_CONTROL_MAGNIFICATION:
1432 return "CAPABILITY_CAN_CONTROL_MAGNIFICATION";
1433 case CAPABILITY_CAN_PERFORM_GESTURES:
1434 return "CAPABILITY_CAN_PERFORM_GESTURES";
1435 case CAPABILITY_CAN_REQUEST_FINGERPRINT_GESTURES:
1436 return "CAPABILITY_CAN_REQUEST_FINGERPRINT_GESTURES";
1437 case CAPABILITY_CAN_TAKE_SCREENSHOT:
1438 return "CAPABILITY_CAN_TAKE_SCREENSHOT";
1439 default:
1440 return "UNKNOWN";
1441 }
1442 }
1443
1444 /**
1445 * @hide
1446 * @return The list of {@link CapabilityInfo} objects.
1447 * @deprecated The version that takes a context works better.
1448 */
1449 public List<CapabilityInfo> getCapabilityInfos() {
1450 return getCapabilityInfos(null);
1451 }
1452
1453 /**
1454 * @hide
1455 * @param context A valid context
1456 * @return The list of {@link CapabilityInfo} objects.
1457 */
1458 public List<CapabilityInfo> getCapabilityInfos(Context context) {
1459 if (mCapabilities == 0) {
1460 return Collections.emptyList();
1461 }
1462 int capabilities = mCapabilities;
1463 List<CapabilityInfo> capabilityInfos = new ArrayList<CapabilityInfo>();
1464 SparseArray<CapabilityInfo> capabilityInfoSparseArray =
1465 getCapabilityInfoSparseArray(context);
1466 while (capabilities != 0) {
1467 final int capabilityBit = 1 << Integer.numberOfTrailingZeros(capabilities);
1468 capabilities &= ~capabilityBit;
1469 CapabilityInfo capabilityInfo = capabilityInfoSparseArray.get(capabilityBit);
1470 if (capabilityInfo != null) {
1471 capabilityInfos.add(capabilityInfo);
1472 }
1473 }
1474 return capabilityInfos;
1475 }
1476
1477 private static SparseArray<CapabilityInfo> getCapabilityInfoSparseArray(Context context) {
1478 if (sAvailableCapabilityInfos == null) {
1479 sAvailableCapabilityInfos = new SparseArray<CapabilityInfo>();
1480 sAvailableCapabilityInfos.put(CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT,
1481 new CapabilityInfo(CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT,
1482 R.string.capability_title_canRetrieveWindowContent,
1483 R.string.capability_desc_canRetrieveWindowContent));
1484 sAvailableCapabilityInfos.put(CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION,
1485 new CapabilityInfo(CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION,
1486 R.string.capability_title_canRequestTouchExploration,
1487 R.string.capability_desc_canRequestTouchExploration));
1488 sAvailableCapabilityInfos.put(CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS,
1489 new CapabilityInfo(CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS,
1490 R.string.capability_title_canRequestFilterKeyEvents,
1491 R.string.capability_desc_canRequestFilterKeyEvents));
1492 sAvailableCapabilityInfos.put(CAPABILITY_CAN_CONTROL_MAGNIFICATION,
1493 new CapabilityInfo(CAPABILITY_CAN_CONTROL_MAGNIFICATION,
1494 R.string.capability_title_canControlMagnification,
1495 R.string.capability_desc_canControlMagnification));
1496 sAvailableCapabilityInfos.put(CAPABILITY_CAN_PERFORM_GESTURES,
1497 new CapabilityInfo(CAPABILITY_CAN_PERFORM_GESTURES,
1498 R.string.capability_title_canPerformGestures,
1499 R.string.capability_desc_canPerformGestures));
1500 sAvailableCapabilityInfos.put(CAPABILITY_CAN_TAKE_SCREENSHOT,
1501 new CapabilityInfo(CAPABILITY_CAN_TAKE_SCREENSHOT,
1502 R.string.capability_title_canTakeScreenshot,
1503 R.string.capability_desc_canTakeScreenshot));
1504 if ((context == null) || fingerprintAvailable(context)) {
1505 sAvailableCapabilityInfos.put(CAPABILITY_CAN_REQUEST_FINGERPRINT_GESTURES,
1506 new CapabilityInfo(CAPABILITY_CAN_REQUEST_FINGERPRINT_GESTURES,
1507 R.string.capability_title_canCaptureFingerprintGestures,
1508 R.string.capability_desc_canCaptureFingerprintGestures));
1509 }
1510 }
1511 return sAvailableCapabilityInfos;
1512 }
1513
1514 private static boolean fingerprintAvailable(Context context) {
1515 return context.getPackageManager().hasSystemFeature(FEATURE_FINGERPRINT)
1516 && context.getSystemService(FingerprintManager.class).isHardwareDetected();
1517 }
1518 /**
1519 * @hide
1520 */
1521 public static final class CapabilityInfo {
1522 public final int capability;
1523 public final int titleResId;
1524 public final int descResId;
1525
1526 public CapabilityInfo(int capability, int titleResId, int descResId) {
1527 this.capability = capability;
1528 this.titleResId = titleResId;
1529 this.descResId = descResId;
1530 }
1531 }
1532
1533 /**
1534 * @see Parcelable.Creator
1535 */
1536 public static final @android.annotation.NonNull Parcelable.Creator<AccessibilityServiceInfo> CREATOR =
1537 new Parcelable.Creator<AccessibilityServiceInfo>() {
1538 public AccessibilityServiceInfo createFromParcel(Parcel parcel) {
1539 AccessibilityServiceInfo info = new AccessibilityServiceInfo();
1540 info.initFromParcel(parcel);
1541 return info;
1542 }
1543
1544 public AccessibilityServiceInfo[] newArray(int size) {
1545 return new AccessibilityServiceInfo[size];
1546 }
1547 };
1548 }