| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public class AccessibilityServiceInfo implements Parcelable { |
| 101 |
|
| 102 |
private static final String TAG_ACCESSIBILITY_SERVICE = "accessibility-service"; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public static final int CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT = 0x00000001; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
public static final int CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION = 0x00000002; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public static final int CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY = 0x00000004; |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public static final int CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS = 0x00000008; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
public static final int CAPABILITY_CAN_CONTROL_MAGNIFICATION = 0x00000010; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
public static final int CAPABILITY_CAN_PERFORM_GESTURES = 0x00000020; |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
public static final int CAPABILITY_CAN_REQUEST_FINGERPRINT_GESTURES = 0x00000040; |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
public static final int CAPABILITY_CAN_TAKE_SCREENSHOT = 0x00000080; |
| 151 |
|
| 152 |
private static SparseArray<CapabilityInfo> sAvailableCapabilityInfos; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
public static final int FEEDBACK_SPOKEN = 0x0000001; |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
public static final int FEEDBACK_HAPTIC = 0x0000002; |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
public static final int FEEDBACK_AUDIBLE = 0x0000004; |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
public static final int FEEDBACK_VISUAL = 0x0000008; |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
public static final int FEEDBACK_GENERIC = 0x0000010; |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
public static final int FEEDBACK_BRAILLE = 0x0000020; |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
public static final int FEEDBACK_ALL_MASK = 0xFFFFFFFF; |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
public static final int DEFAULT = 0x0000001; |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
public static final int FLAG_INCLUDE_NOT_IMPORTANT_VIEWS = 0x0000002; |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
public static final int FLAG_REQUEST_TOUCH_EXPLORATION_MODE = 0x0000004; |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
public static final int FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY = 0x00000008; |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
public static final int FLAG_REPORT_VIEW_IDS = 0x00000010; |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
public static final int FLAG_REQUEST_FILTER_KEY_EVENTS = 0x00000020; |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
public static final int FLAG_RETRIEVE_INTERACTIVE_WINDOWS = 0x00000040; |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
public static final int FLAG_ENABLE_ACCESSIBILITY_VOLUME = 0x00000080; |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
public static final int FLAG_REQUEST_ACCESSIBILITY_BUTTON = 0x00000100; |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
public static final int FLAG_REQUEST_FINGERPRINT_GESTURES = 0x00000200; |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
public static final int FLAG_REQUEST_SHORTCUT_WARNING_DIALOG_SPOKEN_FEEDBACK = 0x00000400; |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
public static final int FLAG_SERVICE_HANDLES_DOUBLE_TAP = 0x0000800; |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
public static final int FLAG_REQUEST_MULTI_FINGER_GESTURES = 0x0001000; |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
public static final int FLAG_REQUEST_2_FINGER_PASSTHROUGH = 0x0002000; |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
public static final int FLAG_SEND_MOTION_EVENTS = 0x0004000; |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
public static final int FLAG_INPUT_METHOD_EDITOR = 0x0008000; |
| 403 |
|
| 404 |
|
| 405 |
public static final int FLAG_FORCE_DIRECT_BOOT_AWARE = 0x00010000; |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
public int eventTypes; |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
public String[] packageNames; |
| 446 |
|
| 447 |
|
| 448 |
|
| 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 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
@FeedbackType |
| 473 |
public int feedbackType; |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
public long notificationTimeout; |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
public int flags; |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
public boolean crashed; |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
private int mNonInteractiveUiTimeout; |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
private int mInteractiveUiTimeout; |
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
@NonNull |
| 538 |
private ComponentName mComponentName; |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
private ResolveInfo mResolveInfo; |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
private String mSettingsActivityName; |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
private String mTileServiceName; |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
private int mCapabilities; |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
private int mSummaryResId; |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
private String mNonLocalizedSummary; |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
private int mIntroResId; |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
private int mDescriptionResId; |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
private String mNonLocalizedDescription; |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 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 |
|
| 599 |
|
| 600 |
private int mAnimatedImageRes; |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
private int mHtmlDescriptionRes; |
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
private boolean mIsAccessibilityTool = false; |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
public AccessibilityServiceInfo() { |
| 618 |
|
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 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 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 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 |
|
| 806 |
|
| 807 |
public void setComponentName(@NonNull ComponentName component) { |
| 808 |
mComponentName = component; |
| 809 |
} |
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
@TestApi |
| 815 |
@NonNull |
| 816 |
public ComponentName getComponentName() { |
| 817 |
return mComponentName; |
| 818 |
} |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
public String getId() { |
| 828 |
return mComponentName.flattenToShortString(); |
| 829 |
} |
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
public ResolveInfo getResolveInfo() { |
| 839 |
return mResolveInfo; |
| 840 |
} |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
public String getSettingsActivityName() { |
| 851 |
return mSettingsActivityName; |
| 852 |
} |
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
@Nullable |
| 861 |
public String getTileServiceName() { |
| 862 |
return mTileServiceName; |
| 863 |
} |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
public int getAnimatedImageRes() { |
| 873 |
return mAnimatedImageRes; |
| 874 |
} |
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
@Nullable |
| 889 |
public Drawable loadAnimatedImage(@NonNull Context context) { |
| 890 |
if (mAnimatedImageRes == 0) { |
| 891 |
return null; |
| 892 |
} |
| 893 |
|
| 894 |
return loadSafeAnimatedImage(context, mResolveInfo.serviceInfo.applicationInfo, |
| 895 |
mAnimatedImageRes); |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
public boolean getCanRetrieveWindowContent() { |
| 909 |
return (mCapabilities & CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT) != 0; |
| 910 |
} |
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
public int getCapabilities() { |
| 926 |
return mCapabilities; |
| 927 |
} |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 945 |
public void setCapabilities(int capabilities) { |
| 946 |
mCapabilities = capabilities; |
| 947 |
} |
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 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 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
@Nullable |
| 981 |
public CharSequence loadIntro(@NonNull PackageManager packageManager) { |
| 982 |
if (mIntroResId == 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 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
public String getDescription() { |
| 1005 |
return mNonLocalizedDescription; |
| 1006 |
} |
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 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 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
@Nullable |
| 1041 |
public String loadHtmlDescription(@NonNull PackageManager packageManager) { |
| 1042 |
if (mHtmlDescriptionRes == 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 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
public void setNonInteractiveUiTimeoutMillis(@IntRange(from = 0) int timeout) { |
| 1068 |
mNonInteractiveUiTimeout = timeout; |
| 1069 |
} |
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
public int getNonInteractiveUiTimeoutMillis() { |
| 1079 |
return mNonInteractiveUiTimeout; |
| 1080 |
} |
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
public void setInteractiveUiTimeoutMillis(@IntRange(from = 0) int timeout) { |
| 1095 |
mInteractiveUiTimeout = timeout; |
| 1096 |
} |
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
public int getInteractiveUiTimeoutMillis() { |
| 1106 |
return mInteractiveUiTimeout; |
| 1107 |
} |
| 1108 |
|
| 1109 |
|
| 1110 |
public boolean isDirectBootAware() { |
| 1111 |
return ((flags & FLAG_FORCE_DIRECT_BOOT_AWARE) != 0) |
| 1112 |
|| mResolveInfo.serviceInfo.directBootAware; |
| 1113 |
} |
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
public boolean isAccessibilityTool() { |
| 1121 |
return mIsAccessibilityTool; |
| 1122 |
} |
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 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 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 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 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 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 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 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 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
public List<CapabilityInfo> getCapabilityInfos() { |
| 1450 |
return getCapabilityInfos(null); |
| 1451 |
} |
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 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 |
|
| 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 |
|
| 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 |
} |