| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view.accessibility; |
| 18 |
|
| 19 |
import static android.accessibilityservice.AccessibilityServiceInfo.FLAG_ENABLE_ACCESSIBILITY_VOLUME; |
| 20 |
|
| 21 |
import android.Manifest; |
| 22 |
import android.accessibilityservice.AccessibilityService; |
| 23 |
import android.accessibilityservice.AccessibilityServiceInfo; |
| 24 |
import android.accessibilityservice.AccessibilityServiceInfo.FeedbackType; |
| 25 |
import android.accessibilityservice.AccessibilityShortcutInfo; |
| 26 |
import android.annotation.CallbackExecutor; |
| 27 |
import android.annotation.ColorInt; |
| 28 |
import android.annotation.IntDef; |
| 29 |
import android.annotation.NonNull; |
| 30 |
import android.annotation.Nullable; |
| 31 |
import android.annotation.RequiresPermission; |
| 32 |
import android.annotation.SdkConstant; |
| 33 |
import android.annotation.SystemApi; |
| 34 |
import android.annotation.SystemService; |
| 35 |
import android.annotation.TestApi; |
| 36 |
import android.annotation.UserIdInt; |
| 37 |
import android.app.RemoteAction; |
| 38 |
import android.compat.annotation.UnsupportedAppUsage; |
| 39 |
import android.content.ComponentName; |
| 40 |
import android.content.Context; |
| 41 |
import android.content.Intent; |
| 42 |
import android.content.pm.ActivityInfo; |
| 43 |
import android.content.pm.PackageManager; |
| 44 |
import android.content.pm.ResolveInfo; |
| 45 |
import android.content.pm.ServiceInfo; |
| 46 |
import android.content.res.Resources; |
| 47 |
import android.os.Binder; |
| 48 |
import android.os.Build; |
| 49 |
import android.os.Handler; |
| 50 |
import android.os.HandlerExecutor; |
| 51 |
import android.os.IBinder; |
| 52 |
import android.os.Looper; |
| 53 |
import android.os.Message; |
| 54 |
import android.os.Process; |
| 55 |
import android.os.RemoteException; |
| 56 |
import android.os.ServiceManager; |
| 57 |
import android.os.SystemClock; |
| 58 |
import android.os.UserHandle; |
| 59 |
import android.util.ArrayMap; |
| 60 |
import android.util.Log; |
| 61 |
import android.util.SparseArray; |
| 62 |
import android.view.IWindow; |
| 63 |
import android.view.View; |
| 64 |
import android.view.accessibility.AccessibilityEvent.EventType; |
| 65 |
|
| 66 |
import com.android.internal.R; |
| 67 |
import com.android.internal.annotations.VisibleForTesting; |
| 68 |
import com.android.internal.util.IntPair; |
| 69 |
|
| 70 |
import org.xmlpull.v1.XmlPullParserException; |
| 71 |
|
| 72 |
import java.io.IOException; |
| 73 |
import java.lang.annotation.Retention; |
| 74 |
import java.lang.annotation.RetentionPolicy; |
| 75 |
import java.util.ArrayList; |
| 76 |
import java.util.Collections; |
| 77 |
import java.util.List; |
| 78 |
import java.util.concurrent.Executor; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
@SystemService(Context.ACCESSIBILITY_SERVICE) |
| 96 |
public final class AccessibilityManager { |
| 97 |
private static final boolean DEBUG = false; |
| 98 |
|
| 99 |
private static final String LOG_TAG = "AccessibilityManager"; |
| 100 |
|
| 101 |
|
| 102 |
public static final int STATE_FLAG_ACCESSIBILITY_ENABLED = 0x00000001; |
| 103 |
|
| 104 |
|
| 105 |
public static final int STATE_FLAG_TOUCH_EXPLORATION_ENABLED = 0x00000002; |
| 106 |
|
| 107 |
|
| 108 |
public static final int STATE_FLAG_HIGH_TEXT_CONTRAST_ENABLED = 0x00000004; |
| 109 |
|
| 110 |
|
| 111 |
public static final int STATE_FLAG_DISPATCH_DOUBLE_TAP = 0x00000008; |
| 112 |
|
| 113 |
|
| 114 |
public static final int STATE_FLAG_REQUEST_MULTI_FINGER_GESTURES = 0x00000010; |
| 115 |
|
| 116 |
|
| 117 |
public static final int STATE_FLAG_TRACE_A11Y_INTERACTION_CONNECTION_ENABLED = 0x00000100; |
| 118 |
|
| 119 |
public static final int STATE_FLAG_TRACE_A11Y_INTERACTION_CONNECTION_CB_ENABLED = 0x00000200; |
| 120 |
|
| 121 |
public static final int STATE_FLAG_TRACE_A11Y_INTERACTION_CLIENT_ENABLED = 0x00000400; |
| 122 |
|
| 123 |
public static final int STATE_FLAG_TRACE_A11Y_SERVICE_ENABLED = 0x00000800; |
| 124 |
|
| 125 |
public static final int STATE_FLAG_AUDIO_DESCRIPTION_BY_DEFAULT_ENABLED = 0x00001000; |
| 126 |
|
| 127 |
|
| 128 |
public static final int DALTONIZER_DISABLED = -1; |
| 129 |
|
| 130 |
|
| 131 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 132 |
public static final int DALTONIZER_SIMULATE_MONOCHROMACY = 0; |
| 133 |
|
| 134 |
|
| 135 |
public static final int DALTONIZER_CORRECT_DEUTERANOMALY = 12; |
| 136 |
|
| 137 |
|
| 138 |
public static final int AUTOCLICK_DELAY_DEFAULT = 600; |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
@SdkConstant(SdkConstant.SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 153 |
public static final String ACTION_CHOOSE_ACCESSIBILITY_BUTTON = |
| 154 |
"com.android.internal.intent.action.CHOOSE_ACCESSIBILITY_BUTTON"; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
public static final int ACCESSIBILITY_BUTTON = 0; |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
public static final int ACCESSIBILITY_SHORTCUT_KEY = 1; |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
@Retention(RetentionPolicy.SOURCE) |
| 177 |
@IntDef(value = { |
| 178 |
ACCESSIBILITY_BUTTON, |
| 179 |
ACCESSIBILITY_SHORTCUT_KEY |
| 180 |
}) |
| 181 |
public @interface ShortcutType {} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
@Retention(RetentionPolicy.SOURCE) |
| 188 |
@IntDef(flag = true, prefix = { "FLAG_CONTENT_" }, value = { |
| 189 |
FLAG_CONTENT_ICONS, |
| 190 |
FLAG_CONTENT_TEXT, |
| 191 |
FLAG_CONTENT_CONTROLS |
| 192 |
}) |
| 193 |
public @interface ContentFlag {} |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
public static final int FLAG_CONTENT_ICONS = 1; |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
public static final int FLAG_CONTENT_TEXT = 2; |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
public static final int FLAG_CONTENT_CONTROLS = 4; |
| 215 |
|
| 216 |
@UnsupportedAppUsage |
| 217 |
static final Object sInstanceSync = new Object(); |
| 218 |
|
| 219 |
@UnsupportedAppUsage |
| 220 |
private static AccessibilityManager sInstance; |
| 221 |
|
| 222 |
@UnsupportedAppUsage |
| 223 |
private final Object mLock = new Object(); |
| 224 |
|
| 225 |
@UnsupportedAppUsage |
| 226 |
private IAccessibilityManager mService; |
| 227 |
|
| 228 |
@UnsupportedAppUsage |
| 229 |
final int mUserId; |
| 230 |
|
| 231 |
@UnsupportedAppUsage |
| 232 |
final Handler mHandler; |
| 233 |
|
| 234 |
final Handler.Callback mCallback; |
| 235 |
|
| 236 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
| 237 |
boolean mIsEnabled; |
| 238 |
|
| 239 |
int mRelevantEventTypes = AccessibilityEvent.TYPES_ALL_MASK; |
| 240 |
|
| 241 |
int mInteractiveUiTimeout; |
| 242 |
int mNonInteractiveUiTimeout; |
| 243 |
|
| 244 |
boolean mIsTouchExplorationEnabled; |
| 245 |
|
| 246 |
@UnsupportedAppUsage(trackingBug = 123768939L) |
| 247 |
boolean mIsHighTextContrastEnabled; |
| 248 |
|
| 249 |
boolean mIsAudioDescriptionByDefaultRequested; |
| 250 |
|
| 251 |
|
| 252 |
int mAccessibilityTracingState = 0; |
| 253 |
|
| 254 |
AccessibilityPolicy mAccessibilityPolicy; |
| 255 |
|
| 256 |
private int mPerformingAction = 0; |
| 257 |
|
| 258 |
|
| 259 |
private int mFocusStrokeWidth; |
| 260 |
|
| 261 |
private int mFocusColor; |
| 262 |
|
| 263 |
@UnsupportedAppUsage |
| 264 |
private final ArrayMap<AccessibilityStateChangeListener, Handler> |
| 265 |
mAccessibilityStateChangeListeners = new ArrayMap<>(); |
| 266 |
|
| 267 |
private final ArrayMap<TouchExplorationStateChangeListener, Handler> |
| 268 |
mTouchExplorationStateChangeListeners = new ArrayMap<>(); |
| 269 |
|
| 270 |
private final ArrayMap<HighTextContrastChangeListener, Handler> |
| 271 |
mHighTextContrastStateChangeListeners = new ArrayMap<>(); |
| 272 |
|
| 273 |
private final ArrayMap<AccessibilityServicesStateChangeListener, Executor> |
| 274 |
mServicesStateChangeListeners = new ArrayMap<>(); |
| 275 |
|
| 276 |
private final ArrayMap<AudioDescriptionRequestedChangeListener, Executor> |
| 277 |
mAudioDescriptionRequestedChangeListeners = new ArrayMap<>(); |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
private SparseArray<List<AccessibilityRequestPreparer>> mRequestPreparerLists; |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
public interface AccessibilityStateChangeListener { |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
void onAccessibilityStateChanged(boolean enabled); |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
public interface TouchExplorationStateChangeListener { |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
void onTouchExplorationStateChanged(boolean enabled); |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
public interface AccessibilityServicesStateChangeListener { |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
void onAccessibilityServicesStateChanged(@NonNull AccessibilityManager manager); |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
public interface HighTextContrastChangeListener { |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
void onHighTextContrastStateChanged(boolean enabled); |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
public interface AudioDescriptionRequestedChangeListener { |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
void onAudioDescriptionRequestedChanged(boolean enabled); |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
public interface AccessibilityPolicy { |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
boolean isEnabled(boolean accessibilityEnabled); |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
@Nullable AccessibilityEvent onAccessibilityEvent(@NonNull AccessibilityEvent event, |
| 396 |
boolean accessibilityEnabled, @EventType int relevantEventTypes); |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
@EventType int getRelevantEventTypes(@EventType int relevantEventTypes); |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
@NonNull List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList( |
| 413 |
@Nullable List<AccessibilityServiceInfo> installedService); |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
@Nullable List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList( |
| 423 |
@FeedbackType int feedbackTypeFlags, |
| 424 |
@Nullable List<AccessibilityServiceInfo> enabledService); |
| 425 |
} |
| 426 |
|
| 427 |
private final IAccessibilityManagerClient.Stub mClient = |
| 428 |
new IAccessibilityManagerClient.Stub() { |
| 429 |
@Override |
| 430 |
public void setState(int state) { |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
mHandler.obtainMessage(MyCallback.MSG_SET_STATE, state, 0).sendToTarget(); |
| 438 |
} |
| 439 |
|
| 440 |
@Override |
| 441 |
public void notifyServicesStateChanged(long updatedUiTimeout) { |
| 442 |
updateUiTimeout(updatedUiTimeout); |
| 443 |
|
| 444 |
final ArrayMap<AccessibilityServicesStateChangeListener, Executor> listeners; |
| 445 |
synchronized (mLock) { |
| 446 |
if (mServicesStateChangeListeners.isEmpty()) { |
| 447 |
return; |
| 448 |
} |
| 449 |
listeners = new ArrayMap<>(mServicesStateChangeListeners); |
| 450 |
} |
| 451 |
|
| 452 |
int numListeners = listeners.size(); |
| 453 |
for (int i = 0; i < numListeners; i++) { |
| 454 |
final AccessibilityServicesStateChangeListener listener = |
| 455 |
mServicesStateChangeListeners.keyAt(i); |
| 456 |
mServicesStateChangeListeners.valueAt(i).execute(() -> listener |
| 457 |
.onAccessibilityServicesStateChanged(AccessibilityManager.this)); |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
@Override |
| 462 |
public void setRelevantEventTypes(int eventTypes) { |
| 463 |
mRelevantEventTypes = eventTypes; |
| 464 |
} |
| 465 |
|
| 466 |
@Override |
| 467 |
public void setFocusAppearance(int strokeWidth, int color) { |
| 468 |
synchronized (mLock) { |
| 469 |
updateFocusAppearanceLocked(strokeWidth, color); |
| 470 |
} |
| 471 |
} |
| 472 |
}; |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
@UnsupportedAppUsage |
| 482 |
public static AccessibilityManager getInstance(Context context) { |
| 483 |
synchronized (sInstanceSync) { |
| 484 |
if (sInstance == null) { |
| 485 |
final int userId; |
| 486 |
if (Binder.getCallingUid() == Process.SYSTEM_UID |
| 487 |
|| context.checkCallingOrSelfPermission( |
| 488 |
Manifest.permission.INTERACT_ACROSS_USERS) |
| 489 |
== PackageManager.PERMISSION_GRANTED |
| 490 |
|| context.checkCallingOrSelfPermission( |
| 491 |
Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
| 492 |
== PackageManager.PERMISSION_GRANTED) { |
| 493 |
userId = UserHandle.USER_CURRENT; |
| 494 |
} else { |
| 495 |
userId = context.getUserId(); |
| 496 |
} |
| 497 |
sInstance = new AccessibilityManager(context, null, userId); |
| 498 |
} |
| 499 |
} |
| 500 |
return sInstance; |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
public AccessibilityManager(Context context, IAccessibilityManager service, int userId) { |
| 513 |
|
| 514 |
|
| 515 |
mCallback = new MyCallback(); |
| 516 |
mHandler = new Handler(context.getMainLooper(), mCallback); |
| 517 |
mUserId = userId; |
| 518 |
synchronized (mLock) { |
| 519 |
initialFocusAppearanceLocked(context.getResources()); |
| 520 |
tryConnectToServiceLocked(service); |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
@VisibleForTesting |
| 537 |
public AccessibilityManager(Context context, Handler handler, IAccessibilityManager service, |
| 538 |
int userId, boolean serviceConnect) { |
| 539 |
mCallback = new MyCallback(); |
| 540 |
mHandler = handler; |
| 541 |
mUserId = userId; |
| 542 |
synchronized (mLock) { |
| 543 |
initialFocusAppearanceLocked(context.getResources()); |
| 544 |
if (serviceConnect) { |
| 545 |
tryConnectToServiceLocked(service); |
| 546 |
} |
| 547 |
} |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
public IAccessibilityManagerClient getClient() { |
| 554 |
return mClient; |
| 555 |
} |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
public boolean removeClient() { |
| 562 |
synchronized (mLock) { |
| 563 |
IAccessibilityManager service = getServiceLocked(); |
| 564 |
if (service == null) { |
| 565 |
return false; |
| 566 |
} |
| 567 |
try { |
| 568 |
return service.removeClient(mClient, mUserId); |
| 569 |
} catch (RemoteException re) { |
| 570 |
Log.e(LOG_TAG, "AccessibilityManagerService is dead", re); |
| 571 |
} |
| 572 |
} |
| 573 |
return false; |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
@VisibleForTesting |
| 580 |
public Handler.Callback getCallback() { |
| 581 |
return mCallback; |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
public boolean isEnabled() { |
| 590 |
synchronized (mLock) { |
| 591 |
return mIsEnabled || (mAccessibilityPolicy != null |
| 592 |
&& mAccessibilityPolicy.isEnabled(mIsEnabled)); |
| 593 |
} |
| 594 |
} |
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
public boolean isTouchExplorationEnabled() { |
| 602 |
synchronized (mLock) { |
| 603 |
IAccessibilityManager service = getServiceLocked(); |
| 604 |
if (service == null) { |
| 605 |
return false; |
| 606 |
} |
| 607 |
return mIsTouchExplorationEnabled; |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
@UnsupportedAppUsage |
| 623 |
public boolean isHighTextContrastEnabled() { |
| 624 |
synchronized (mLock) { |
| 625 |
IAccessibilityManager service = getServiceLocked(); |
| 626 |
if (service == null) { |
| 627 |
return false; |
| 628 |
} |
| 629 |
return mIsHighTextContrastEnabled; |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
public void sendAccessibilityEvent(AccessibilityEvent event) { |
| 647 |
final IAccessibilityManager service; |
| 648 |
final int userId; |
| 649 |
final AccessibilityEvent dispatchedEvent; |
| 650 |
synchronized (mLock) { |
| 651 |
service = getServiceLocked(); |
| 652 |
if (service == null) { |
| 653 |
return; |
| 654 |
} |
| 655 |
event.setEventTime(SystemClock.uptimeMillis()); |
| 656 |
if (event.getAction() == 0) { |
| 657 |
event.setAction(mPerformingAction); |
| 658 |
} |
| 659 |
if (mAccessibilityPolicy != null) { |
| 660 |
dispatchedEvent = mAccessibilityPolicy.onAccessibilityEvent(event, |
| 661 |
mIsEnabled, mRelevantEventTypes); |
| 662 |
if (dispatchedEvent == null) { |
| 663 |
return; |
| 664 |
} |
| 665 |
} else { |
| 666 |
dispatchedEvent = event; |
| 667 |
} |
| 668 |
if (!isEnabled()) { |
| 669 |
Looper myLooper = Looper.myLooper(); |
| 670 |
if (myLooper == Looper.getMainLooper()) { |
| 671 |
throw new IllegalStateException( |
| 672 |
"Accessibility off. Did you forget to check that?"); |
| 673 |
} else { |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
Log.e(LOG_TAG, "AccessibilityEvent sent with accessibility disabled"); |
| 679 |
return; |
| 680 |
} |
| 681 |
} |
| 682 |
if ((dispatchedEvent.getEventType() & mRelevantEventTypes) == 0) { |
| 683 |
if (DEBUG) { |
| 684 |
Log.i(LOG_TAG, "Not dispatching irrelevant event: " + dispatchedEvent |
| 685 |
+ " that is not among " |
| 686 |
+ AccessibilityEvent.eventTypeToString(mRelevantEventTypes)); |
| 687 |
} |
| 688 |
return; |
| 689 |
} |
| 690 |
userId = mUserId; |
| 691 |
} |
| 692 |
try { |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
final long identityToken = Binder.clearCallingIdentity(); |
| 697 |
try { |
| 698 |
service.sendAccessibilityEvent(dispatchedEvent, userId); |
| 699 |
} finally { |
| 700 |
Binder.restoreCallingIdentity(identityToken); |
| 701 |
} |
| 702 |
if (DEBUG) { |
| 703 |
Log.i(LOG_TAG, dispatchedEvent + " sent"); |
| 704 |
} |
| 705 |
} catch (RemoteException re) { |
| 706 |
Log.e(LOG_TAG, "Error during sending " + dispatchedEvent + " ", re); |
| 707 |
} finally { |
| 708 |
if (event != dispatchedEvent) { |
| 709 |
event.recycle(); |
| 710 |
} |
| 711 |
dispatchedEvent.recycle(); |
| 712 |
} |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
public void interrupt() { |
| 719 |
final IAccessibilityManager service; |
| 720 |
final int userId; |
| 721 |
synchronized (mLock) { |
| 722 |
service = getServiceLocked(); |
| 723 |
if (service == null) { |
| 724 |
return; |
| 725 |
} |
| 726 |
if (!isEnabled()) { |
| 727 |
Looper myLooper = Looper.myLooper(); |
| 728 |
if (myLooper == Looper.getMainLooper()) { |
| 729 |
throw new IllegalStateException( |
| 730 |
"Accessibility off. Did you forget to check that?"); |
| 731 |
} else { |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
Log.e(LOG_TAG, "Interrupt called with accessibility disabled"); |
| 737 |
return; |
| 738 |
} |
| 739 |
} |
| 740 |
userId = mUserId; |
| 741 |
} |
| 742 |
try { |
| 743 |
service.interrupt(userId); |
| 744 |
if (DEBUG) { |
| 745 |
Log.i(LOG_TAG, "Requested interrupt from all services"); |
| 746 |
} |
| 747 |
} catch (RemoteException re) { |
| 748 |
Log.e(LOG_TAG, "Error while requesting interrupt from all services. ", re); |
| 749 |
} |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
@Deprecated |
| 760 |
public List<ServiceInfo> getAccessibilityServiceList() { |
| 761 |
List<AccessibilityServiceInfo> infos = getInstalledAccessibilityServiceList(); |
| 762 |
List<ServiceInfo> services = new ArrayList<>(); |
| 763 |
final int infoCount = infos.size(); |
| 764 |
for (int i = 0; i < infoCount; i++) { |
| 765 |
AccessibilityServiceInfo info = infos.get(i); |
| 766 |
services.add(info.getResolveInfo().serviceInfo); |
| 767 |
} |
| 768 |
return Collections.unmodifiableList(services); |
| 769 |
} |
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
public List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList() { |
| 777 |
final IAccessibilityManager service; |
| 778 |
final int userId; |
| 779 |
synchronized (mLock) { |
| 780 |
service = getServiceLocked(); |
| 781 |
if (service == null) { |
| 782 |
return Collections.emptyList(); |
| 783 |
} |
| 784 |
userId = mUserId; |
| 785 |
} |
| 786 |
|
| 787 |
List<AccessibilityServiceInfo> services = null; |
| 788 |
try { |
| 789 |
services = service.getInstalledAccessibilityServiceList(userId); |
| 790 |
if (DEBUG) { |
| 791 |
Log.i(LOG_TAG, "Installed AccessibilityServices " + services); |
| 792 |
} |
| 793 |
} catch (RemoteException re) { |
| 794 |
Log.e(LOG_TAG, "Error while obtaining the installed AccessibilityServices. ", re); |
| 795 |
} |
| 796 |
if (mAccessibilityPolicy != null) { |
| 797 |
services = mAccessibilityPolicy.getInstalledAccessibilityServiceList(services); |
| 798 |
} |
| 799 |
if (services != null) { |
| 800 |
return Collections.unmodifiableList(services); |
| 801 |
} else { |
| 802 |
return Collections.emptyList(); |
| 803 |
} |
| 804 |
} |
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
public List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList( |
| 821 |
int feedbackTypeFlags) { |
| 822 |
final IAccessibilityManager service; |
| 823 |
final int userId; |
| 824 |
synchronized (mLock) { |
| 825 |
service = getServiceLocked(); |
| 826 |
if (service == null) { |
| 827 |
return Collections.emptyList(); |
| 828 |
} |
| 829 |
userId = mUserId; |
| 830 |
} |
| 831 |
|
| 832 |
List<AccessibilityServiceInfo> services = null; |
| 833 |
try { |
| 834 |
services = service.getEnabledAccessibilityServiceList(feedbackTypeFlags, userId); |
| 835 |
if (DEBUG) { |
| 836 |
Log.i(LOG_TAG, "Enabled AccessibilityServices " + services); |
| 837 |
} |
| 838 |
} catch (RemoteException re) { |
| 839 |
Log.e(LOG_TAG, "Error while obtaining the enabled AccessibilityServices. ", re); |
| 840 |
} |
| 841 |
if (mAccessibilityPolicy != null) { |
| 842 |
services = mAccessibilityPolicy.getEnabledAccessibilityServiceList( |
| 843 |
feedbackTypeFlags, services); |
| 844 |
} |
| 845 |
if (services != null) { |
| 846 |
return Collections.unmodifiableList(services); |
| 847 |
} else { |
| 848 |
return Collections.emptyList(); |
| 849 |
} |
| 850 |
} |
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
public boolean addAccessibilityStateChangeListener( |
| 862 |
@NonNull AccessibilityStateChangeListener listener) { |
| 863 |
addAccessibilityStateChangeListener(listener, null); |
| 864 |
return true; |
| 865 |
} |
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
public void addAccessibilityStateChangeListener( |
| 877 |
@NonNull AccessibilityStateChangeListener listener, @Nullable Handler handler) { |
| 878 |
synchronized (mLock) { |
| 879 |
mAccessibilityStateChangeListeners |
| 880 |
.put(listener, (handler == null) ? mHandler : handler); |
| 881 |
} |
| 882 |
} |
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
public boolean removeAccessibilityStateChangeListener( |
| 891 |
@NonNull AccessibilityStateChangeListener listener) { |
| 892 |
synchronized (mLock) { |
| 893 |
int index = mAccessibilityStateChangeListeners.indexOfKey(listener); |
| 894 |
mAccessibilityStateChangeListeners.remove(listener); |
| 895 |
return (index >= 0); |
| 896 |
} |
| 897 |
} |
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
public boolean addTouchExplorationStateChangeListener( |
| 909 |
@NonNull TouchExplorationStateChangeListener listener) { |
| 910 |
addTouchExplorationStateChangeListener(listener, null); |
| 911 |
return true; |
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
public void addTouchExplorationStateChangeListener( |
| 924 |
@NonNull TouchExplorationStateChangeListener listener, @Nullable Handler handler) { |
| 925 |
synchronized (mLock) { |
| 926 |
mTouchExplorationStateChangeListeners |
| 927 |
.put(listener, (handler == null) ? mHandler : handler); |
| 928 |
} |
| 929 |
} |
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
public boolean removeTouchExplorationStateChangeListener( |
| 938 |
@NonNull TouchExplorationStateChangeListener listener) { |
| 939 |
synchronized (mLock) { |
| 940 |
int index = mTouchExplorationStateChangeListeners.indexOfKey(listener); |
| 941 |
mTouchExplorationStateChangeListeners.remove(listener); |
| 942 |
return (index >= 0); |
| 943 |
} |
| 944 |
} |
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
public void addAccessibilityServicesStateChangeListener( |
| 953 |
@NonNull @CallbackExecutor Executor executor, |
| 954 |
@NonNull AccessibilityServicesStateChangeListener listener) { |
| 955 |
synchronized (mLock) { |
| 956 |
mServicesStateChangeListeners.put(listener, executor); |
| 957 |
} |
| 958 |
} |
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
public void addAccessibilityServicesStateChangeListener( |
| 968 |
@NonNull AccessibilityServicesStateChangeListener listener) { |
| 969 |
addAccessibilityServicesStateChangeListener(new HandlerExecutor(mHandler), listener); |
| 970 |
} |
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
public boolean removeAccessibilityServicesStateChangeListener( |
| 979 |
@NonNull AccessibilityServicesStateChangeListener listener) { |
| 980 |
synchronized (mLock) { |
| 981 |
return mServicesStateChangeListeners.remove(listener) != null; |
| 982 |
} |
| 983 |
} |
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
public void addAccessibilityRequestPreparer(AccessibilityRequestPreparer preparer) { |
| 989 |
if (mRequestPreparerLists == null) { |
| 990 |
mRequestPreparerLists = new SparseArray<>(1); |
| 991 |
} |
| 992 |
int id = preparer.getAccessibilityViewId(); |
| 993 |
List<AccessibilityRequestPreparer> requestPreparerList = mRequestPreparerLists.get(id); |
| 994 |
if (requestPreparerList == null) { |
| 995 |
requestPreparerList = new ArrayList<>(1); |
| 996 |
mRequestPreparerLists.put(id, requestPreparerList); |
| 997 |
} |
| 998 |
requestPreparerList.add(preparer); |
| 999 |
} |
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
public void removeAccessibilityRequestPreparer(AccessibilityRequestPreparer preparer) { |
| 1005 |
if (mRequestPreparerLists == null) { |
| 1006 |
return; |
| 1007 |
} |
| 1008 |
int viewId = preparer.getAccessibilityViewId(); |
| 1009 |
List<AccessibilityRequestPreparer> requestPreparerList = mRequestPreparerLists.get(viewId); |
| 1010 |
if (requestPreparerList != null) { |
| 1011 |
requestPreparerList.remove(preparer); |
| 1012 |
if (requestPreparerList.isEmpty()) { |
| 1013 |
mRequestPreparerLists.remove(viewId); |
| 1014 |
} |
| 1015 |
} |
| 1016 |
} |
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
public int getRecommendedTimeoutMillis(int originalTimeout, @ContentFlag int uiContentFlags) { |
| 1037 |
boolean hasControls = (uiContentFlags & FLAG_CONTENT_CONTROLS) != 0; |
| 1038 |
boolean hasIconsOrText = (uiContentFlags & FLAG_CONTENT_ICONS) != 0 |
| 1039 |
|| (uiContentFlags & FLAG_CONTENT_TEXT) != 0; |
| 1040 |
int recommendedTimeout = originalTimeout; |
| 1041 |
if (hasControls) { |
| 1042 |
recommendedTimeout = Math.max(recommendedTimeout, mInteractiveUiTimeout); |
| 1043 |
} |
| 1044 |
if (hasIconsOrText) { |
| 1045 |
recommendedTimeout = Math.max(recommendedTimeout, mNonInteractiveUiTimeout); |
| 1046 |
} |
| 1047 |
return recommendedTimeout; |
| 1048 |
} |
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
public int getAccessibilityFocusStrokeWidth() { |
| 1058 |
synchronized (mLock) { |
| 1059 |
return mFocusStrokeWidth; |
| 1060 |
} |
| 1061 |
} |
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
public @ColorInt int getAccessibilityFocusColor() { |
| 1071 |
synchronized (mLock) { |
| 1072 |
return mFocusColor; |
| 1073 |
} |
| 1074 |
} |
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
public boolean isA11yInteractionConnectionTraceEnabled() { |
| 1082 |
synchronized (mLock) { |
| 1083 |
return ((mAccessibilityTracingState |
| 1084 |
& STATE_FLAG_TRACE_A11Y_INTERACTION_CONNECTION_ENABLED) != 0); |
| 1085 |
} |
| 1086 |
} |
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
public boolean isA11yInteractionConnectionCBTraceEnabled() { |
| 1094 |
synchronized (mLock) { |
| 1095 |
return ((mAccessibilityTracingState |
| 1096 |
& STATE_FLAG_TRACE_A11Y_INTERACTION_CONNECTION_CB_ENABLED) != 0); |
| 1097 |
} |
| 1098 |
} |
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
public boolean isA11yInteractionClientTraceEnabled() { |
| 1106 |
synchronized (mLock) { |
| 1107 |
return ((mAccessibilityTracingState |
| 1108 |
& STATE_FLAG_TRACE_A11Y_INTERACTION_CLIENT_ENABLED) != 0); |
| 1109 |
} |
| 1110 |
} |
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
public boolean isA11yServiceTraceEnabled() { |
| 1118 |
synchronized (mLock) { |
| 1119 |
return ((mAccessibilityTracingState |
| 1120 |
& STATE_FLAG_TRACE_A11Y_SERVICE_ENABLED) != 0); |
| 1121 |
} |
| 1122 |
} |
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
public List<AccessibilityRequestPreparer> getRequestPreparersForAccessibilityId(int id) { |
| 1133 |
if (mRequestPreparerLists == null) { |
| 1134 |
return null; |
| 1135 |
} |
| 1136 |
return mRequestPreparerLists.get(id); |
| 1137 |
} |
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
public void notifyPerformingAction(int actionId) { |
| 1146 |
mPerformingAction = actionId; |
| 1147 |
} |
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
public void addHighTextContrastStateChangeListener( |
| 1158 |
@NonNull HighTextContrastChangeListener listener, @Nullable Handler handler) { |
| 1159 |
synchronized (mLock) { |
| 1160 |
mHighTextContrastStateChangeListeners |
| 1161 |
.put(listener, (handler == null) ? mHandler : handler); |
| 1162 |
} |
| 1163 |
} |
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
public void removeHighTextContrastStateChangeListener( |
| 1173 |
@NonNull HighTextContrastChangeListener listener) { |
| 1174 |
synchronized (mLock) { |
| 1175 |
mHighTextContrastStateChangeListeners.remove(listener); |
| 1176 |
} |
| 1177 |
} |
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
public void addAudioDescriptionRequestedChangeListener( |
| 1188 |
@NonNull Executor executor, |
| 1189 |
@NonNull AudioDescriptionRequestedChangeListener listener) { |
| 1190 |
synchronized (mLock) { |
| 1191 |
mAudioDescriptionRequestedChangeListeners.put(listener, executor); |
| 1192 |
} |
| 1193 |
} |
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
public boolean removeAudioDescriptionRequestedChangeListener( |
| 1202 |
@NonNull AudioDescriptionRequestedChangeListener listener) { |
| 1203 |
synchronized (mLock) { |
| 1204 |
return (mAudioDescriptionRequestedChangeListeners.remove(listener) != null); |
| 1205 |
} |
| 1206 |
} |
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
public void setAccessibilityPolicy(@Nullable AccessibilityPolicy policy) { |
| 1216 |
synchronized (mLock) { |
| 1217 |
mAccessibilityPolicy = policy; |
| 1218 |
} |
| 1219 |
} |
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
public boolean isAccessibilityVolumeStreamActive() { |
| 1229 |
List<AccessibilityServiceInfo> serviceInfos = |
| 1230 |
getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_ALL_MASK); |
| 1231 |
for (int i = 0; i < serviceInfos.size(); i++) { |
| 1232 |
if ((serviceInfos.get(i).flags & FLAG_ENABLE_ACCESSIBILITY_VOLUME) != 0) { |
| 1233 |
return true; |
| 1234 |
} |
| 1235 |
} |
| 1236 |
return false; |
| 1237 |
} |
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
public boolean sendFingerprintGesture(int keyCode) { |
| 1247 |
final IAccessibilityManager service; |
| 1248 |
synchronized (mLock) { |
| 1249 |
service = getServiceLocked(); |
| 1250 |
if (service == null) { |
| 1251 |
return false; |
| 1252 |
} |
| 1253 |
} |
| 1254 |
try { |
| 1255 |
return service.sendFingerprintGesture(keyCode); |
| 1256 |
} catch (RemoteException e) { |
| 1257 |
return false; |
| 1258 |
} |
| 1259 |
} |
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
@SystemApi |
| 1272 |
public int getAccessibilityWindowId(@Nullable IBinder windowToken) { |
| 1273 |
if (windowToken == null) { |
| 1274 |
return AccessibilityWindowInfo.UNDEFINED_WINDOW_ID; |
| 1275 |
} |
| 1276 |
|
| 1277 |
final IAccessibilityManager service; |
| 1278 |
synchronized (mLock) { |
| 1279 |
service = getServiceLocked(); |
| 1280 |
if (service == null) { |
| 1281 |
return AccessibilityWindowInfo.UNDEFINED_WINDOW_ID; |
| 1282 |
} |
| 1283 |
} |
| 1284 |
try { |
| 1285 |
return service.getAccessibilityWindowId(windowToken); |
| 1286 |
} catch (RemoteException e) { |
| 1287 |
return AccessibilityWindowInfo.UNDEFINED_WINDOW_ID; |
| 1288 |
} |
| 1289 |
} |
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
public void associateEmbeddedHierarchy(@NonNull IBinder host, @NonNull IBinder embedded) { |
| 1297 |
final IAccessibilityManager service; |
| 1298 |
synchronized (mLock) { |
| 1299 |
service = getServiceLocked(); |
| 1300 |
if (service == null) { |
| 1301 |
return; |
| 1302 |
} |
| 1303 |
} |
| 1304 |
try { |
| 1305 |
service.associateEmbeddedHierarchy(host, embedded); |
| 1306 |
} catch (RemoteException e) { |
| 1307 |
return; |
| 1308 |
} |
| 1309 |
} |
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
public void disassociateEmbeddedHierarchy(@NonNull IBinder token) { |
| 1318 |
if (token == null) { |
| 1319 |
return; |
| 1320 |
} |
| 1321 |
final IAccessibilityManager service; |
| 1322 |
synchronized (mLock) { |
| 1323 |
service = getServiceLocked(); |
| 1324 |
if (service == null) { |
| 1325 |
return; |
| 1326 |
} |
| 1327 |
} |
| 1328 |
try { |
| 1329 |
service.disassociateEmbeddedHierarchy(token); |
| 1330 |
} catch (RemoteException e) { |
| 1331 |
return; |
| 1332 |
} |
| 1333 |
} |
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
@UnsupportedAppUsage |
| 1341 |
private void setStateLocked(int stateFlags) { |
| 1342 |
final boolean enabled = (stateFlags & STATE_FLAG_ACCESSIBILITY_ENABLED) != 0; |
| 1343 |
final boolean touchExplorationEnabled = |
| 1344 |
(stateFlags & STATE_FLAG_TOUCH_EXPLORATION_ENABLED) != 0; |
| 1345 |
final boolean highTextContrastEnabled = |
| 1346 |
(stateFlags & STATE_FLAG_HIGH_TEXT_CONTRAST_ENABLED) != 0; |
| 1347 |
final boolean audioDescriptionEnabled = |
| 1348 |
(stateFlags & STATE_FLAG_AUDIO_DESCRIPTION_BY_DEFAULT_ENABLED) != 0; |
| 1349 |
|
| 1350 |
final boolean wasEnabled = isEnabled(); |
| 1351 |
final boolean wasTouchExplorationEnabled = mIsTouchExplorationEnabled; |
| 1352 |
final boolean wasHighTextContrastEnabled = mIsHighTextContrastEnabled; |
| 1353 |
final boolean wasAudioDescriptionByDefaultRequested = mIsAudioDescriptionByDefaultRequested; |
| 1354 |
|
| 1355 |
|
| 1356 |
mIsEnabled = enabled; |
| 1357 |
mIsTouchExplorationEnabled = touchExplorationEnabled; |
| 1358 |
mIsHighTextContrastEnabled = highTextContrastEnabled; |
| 1359 |
mIsAudioDescriptionByDefaultRequested = audioDescriptionEnabled; |
| 1360 |
|
| 1361 |
if (wasEnabled != isEnabled()) { |
| 1362 |
notifyAccessibilityStateChanged(); |
| 1363 |
} |
| 1364 |
|
| 1365 |
if (wasTouchExplorationEnabled != touchExplorationEnabled) { |
| 1366 |
notifyTouchExplorationStateChanged(); |
| 1367 |
} |
| 1368 |
|
| 1369 |
if (wasHighTextContrastEnabled != highTextContrastEnabled) { |
| 1370 |
notifyHighTextContrastStateChanged(); |
| 1371 |
} |
| 1372 |
|
| 1373 |
if (wasAudioDescriptionByDefaultRequested |
| 1374 |
!= audioDescriptionEnabled) { |
| 1375 |
notifyAudioDescriptionbyDefaultStateChanged(); |
| 1376 |
} |
| 1377 |
|
| 1378 |
updateAccessibilityTracingState(stateFlags); |
| 1379 |
} |
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
public AccessibilityServiceInfo getInstalledServiceInfoWithComponentName( |
| 1391 |
ComponentName componentName) { |
| 1392 |
final List<AccessibilityServiceInfo> installedServiceInfos = |
| 1393 |
getInstalledAccessibilityServiceList(); |
| 1394 |
if ((installedServiceInfos == null) || (componentName == null)) { |
| 1395 |
return null; |
| 1396 |
} |
| 1397 |
for (int i = 0; i < installedServiceInfos.size(); i++) { |
| 1398 |
if (componentName.equals(installedServiceInfos.get(i).getComponentName())) { |
| 1399 |
return installedServiceInfos.get(i); |
| 1400 |
} |
| 1401 |
} |
| 1402 |
return null; |
| 1403 |
} |
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
public int addAccessibilityInteractionConnection(IWindow windowToken, IBinder leashToken, |
| 1414 |
String packageName, IAccessibilityInteractionConnection connection) { |
| 1415 |
final IAccessibilityManager service; |
| 1416 |
final int userId; |
| 1417 |
synchronized (mLock) { |
| 1418 |
service = getServiceLocked(); |
| 1419 |
if (service == null) { |
| 1420 |
return View.NO_ID; |
| 1421 |
} |
| 1422 |
userId = mUserId; |
| 1423 |
} |
| 1424 |
try { |
| 1425 |
return service.addAccessibilityInteractionConnection(windowToken, leashToken, |
| 1426 |
connection, packageName, userId); |
| 1427 |
} catch (RemoteException re) { |
| 1428 |
Log.e(LOG_TAG, "Error while adding an accessibility interaction connection. ", re); |
| 1429 |
} |
| 1430 |
return View.NO_ID; |
| 1431 |
} |
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
public void removeAccessibilityInteractionConnection(IWindow windowToken) { |
| 1440 |
final IAccessibilityManager service; |
| 1441 |
synchronized (mLock) { |
| 1442 |
service = getServiceLocked(); |
| 1443 |
if (service == null) { |
| 1444 |
return; |
| 1445 |
} |
| 1446 |
} |
| 1447 |
try { |
| 1448 |
service.removeAccessibilityInteractionConnection(windowToken); |
| 1449 |
} catch (RemoteException re) { |
| 1450 |
Log.e(LOG_TAG, "Error while removing an accessibility interaction connection. ", re); |
| 1451 |
} |
| 1452 |
} |
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
@SystemApi |
| 1460 |
@RequiresPermission(Manifest.permission.MANAGE_ACCESSIBILITY) |
| 1461 |
public void performAccessibilityShortcut() { |
| 1462 |
performAccessibilityShortcut(null); |
| 1463 |
} |
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
@RequiresPermission(Manifest.permission.MANAGE_ACCESSIBILITY) |
| 1474 |
public void performAccessibilityShortcut(@Nullable String targetName) { |
| 1475 |
final IAccessibilityManager service; |
| 1476 |
synchronized (mLock) { |
| 1477 |
service = getServiceLocked(); |
| 1478 |
if (service == null) { |
| 1479 |
return; |
| 1480 |
} |
| 1481 |
} |
| 1482 |
try { |
| 1483 |
service.performAccessibilityShortcut(targetName); |
| 1484 |
} catch (RemoteException re) { |
| 1485 |
Log.e(LOG_TAG, "Error performing accessibility shortcut. ", re); |
| 1486 |
} |
| 1487 |
} |
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
@SystemApi |
| 1504 |
@RequiresPermission(Manifest.permission.MANAGE_ACCESSIBILITY) |
| 1505 |
public void registerSystemAction(@NonNull RemoteAction action, int actionId) { |
| 1506 |
final IAccessibilityManager service; |
| 1507 |
synchronized (mLock) { |
| 1508 |
service = getServiceLocked(); |
| 1509 |
if (service == null) { |
| 1510 |
return; |
| 1511 |
} |
| 1512 |
} |
| 1513 |
try { |
| 1514 |
service.registerSystemAction(action, actionId); |
| 1515 |
|
| 1516 |
if (DEBUG) { |
| 1517 |
Log.i(LOG_TAG, "System action " + action.getTitle() + " is registered."); |
| 1518 |
} |
| 1519 |
} catch (RemoteException re) { |
| 1520 |
Log.e(LOG_TAG, "Error registering system action " + action.getTitle() + " ", re); |
| 1521 |
} |
| 1522 |
} |
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
@SystemApi |
| 1531 |
@RequiresPermission(Manifest.permission.MANAGE_ACCESSIBILITY) |
| 1532 |
public void unregisterSystemAction(int actionId) { |
| 1533 |
final IAccessibilityManager service; |
| 1534 |
synchronized (mLock) { |
| 1535 |
service = getServiceLocked(); |
| 1536 |
if (service == null) { |
| 1537 |
return; |
| 1538 |
} |
| 1539 |
} |
| 1540 |
try { |
| 1541 |
service.unregisterSystemAction(actionId); |
| 1542 |
|
| 1543 |
if (DEBUG) { |
| 1544 |
Log.i(LOG_TAG, "System action with actionId " + actionId + " is unregistered."); |
| 1545 |
} |
| 1546 |
} catch (RemoteException re) { |
| 1547 |
Log.e(LOG_TAG, "Error unregistering system action with actionId " + actionId + " ", re); |
| 1548 |
} |
| 1549 |
} |
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
@RequiresPermission(android.Manifest.permission.STATUS_BAR_SERVICE) |
| 1558 |
public void notifyAccessibilityButtonClicked(int displayId) { |
| 1559 |
notifyAccessibilityButtonClicked(displayId, null); |
| 1560 |
} |
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
@RequiresPermission(android.Manifest.permission.STATUS_BAR_SERVICE) |
| 1572 |
public void notifyAccessibilityButtonClicked(int displayId, @Nullable String targetName) { |
| 1573 |
final IAccessibilityManager service; |
| 1574 |
synchronized (mLock) { |
| 1575 |
service = getServiceLocked(); |
| 1576 |
if (service == null) { |
| 1577 |
return; |
| 1578 |
} |
| 1579 |
} |
| 1580 |
try { |
| 1581 |
service.notifyAccessibilityButtonClicked(displayId, targetName); |
| 1582 |
} catch (RemoteException re) { |
| 1583 |
Log.e(LOG_TAG, "Error while dispatching accessibility button click", re); |
| 1584 |
} |
| 1585 |
} |
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
public void notifyAccessibilityButtonVisibilityChanged(boolean shown) { |
| 1596 |
final IAccessibilityManager service; |
| 1597 |
synchronized (mLock) { |
| 1598 |
service = getServiceLocked(); |
| 1599 |
if (service == null) { |
| 1600 |
return; |
| 1601 |
} |
| 1602 |
} |
| 1603 |
try { |
| 1604 |
service.notifyAccessibilityButtonVisibilityChanged(shown); |
| 1605 |
} catch (RemoteException re) { |
| 1606 |
Log.e(LOG_TAG, "Error while dispatching accessibility button visibility change", re); |
| 1607 |
} |
| 1608 |
} |
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
public void setPictureInPictureActionReplacingConnection( |
| 1620 |
@Nullable IAccessibilityInteractionConnection connection) { |
| 1621 |
final IAccessibilityManager service; |
| 1622 |
synchronized (mLock) { |
| 1623 |
service = getServiceLocked(); |
| 1624 |
if (service == null) { |
| 1625 |
return; |
| 1626 |
} |
| 1627 |
} |
| 1628 |
try { |
| 1629 |
service.setPictureInPictureActionReplacingConnection(connection); |
| 1630 |
} catch (RemoteException re) { |
| 1631 |
Log.e(LOG_TAG, "Error setting picture in picture action replacement", re); |
| 1632 |
} |
| 1633 |
} |
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
@TestApi |
| 1643 |
@RequiresPermission(Manifest.permission.MANAGE_ACCESSIBILITY) |
| 1644 |
@NonNull |
| 1645 |
public List<String> getAccessibilityShortcutTargets(@ShortcutType int shortcutType) { |
| 1646 |
final IAccessibilityManager service; |
| 1647 |
synchronized (mLock) { |
| 1648 |
service = getServiceLocked(); |
| 1649 |
} |
| 1650 |
if (service != null) { |
| 1651 |
try { |
| 1652 |
return service.getAccessibilityShortcutTargets(shortcutType); |
| 1653 |
} catch (RemoteException re) { |
| 1654 |
re.rethrowFromSystemServer(); |
| 1655 |
} |
| 1656 |
} |
| 1657 |
return Collections.emptyList(); |
| 1658 |
} |
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
@NonNull |
| 1670 |
public List<AccessibilityShortcutInfo> getInstalledAccessibilityShortcutListAsUser( |
| 1671 |
@NonNull Context context, @UserIdInt int userId) { |
| 1672 |
final List<AccessibilityShortcutInfo> shortcutInfos = new ArrayList<>(); |
| 1673 |
final int flags = PackageManager.GET_ACTIVITIES |
| 1674 |
| PackageManager.GET_META_DATA |
| 1675 |
| PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 1676 |
| PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 1677 |
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE; |
| 1678 |
final Intent actionMain = new Intent(Intent.ACTION_MAIN); |
| 1679 |
actionMain.addCategory(Intent.CATEGORY_ACCESSIBILITY_SHORTCUT_TARGET); |
| 1680 |
|
| 1681 |
final PackageManager packageManager = context.getPackageManager(); |
| 1682 |
final List<ResolveInfo> installedShortcutList = |
| 1683 |
packageManager.queryIntentActivitiesAsUser(actionMain, flags, userId); |
| 1684 |
for (int i = 0; i < installedShortcutList.size(); i++) { |
| 1685 |
final AccessibilityShortcutInfo shortcutInfo = |
| 1686 |
getShortcutInfo(context, installedShortcutList.get(i)); |
| 1687 |
if (shortcutInfo != null) { |
| 1688 |
shortcutInfos.add(shortcutInfo); |
| 1689 |
} |
| 1690 |
} |
| 1691 |
return shortcutInfos; |
| 1692 |
} |
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
@Nullable |
| 1703 |
private AccessibilityShortcutInfo getShortcutInfo(@NonNull Context context, |
| 1704 |
@NonNull ResolveInfo resolveInfo) { |
| 1705 |
final ActivityInfo activityInfo = resolveInfo.activityInfo; |
| 1706 |
if (activityInfo == null || activityInfo.metaData == null |
| 1707 |
|| activityInfo.metaData.getInt(AccessibilityShortcutInfo.META_DATA) == 0) { |
| 1708 |
return null; |
| 1709 |
} |
| 1710 |
try { |
| 1711 |
return new AccessibilityShortcutInfo(context, activityInfo); |
| 1712 |
} catch (XmlPullParserException | IOException exp) { |
| 1713 |
Log.e(LOG_TAG, "Error while initializing AccessibilityShortcutInfo", exp); |
| 1714 |
} |
| 1715 |
return null; |
| 1716 |
} |
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
public void setWindowMagnificationConnection(@Nullable |
| 1726 |
IWindowMagnificationConnection connection) { |
| 1727 |
final IAccessibilityManager service; |
| 1728 |
synchronized (mLock) { |
| 1729 |
service = getServiceLocked(); |
| 1730 |
if (service == null) { |
| 1731 |
return; |
| 1732 |
} |
| 1733 |
} |
| 1734 |
try { |
| 1735 |
service.setWindowMagnificationConnection(connection); |
| 1736 |
} catch (RemoteException re) { |
| 1737 |
Log.e(LOG_TAG, "Error setting window magnfication connection", re); |
| 1738 |
} |
| 1739 |
} |
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
public boolean isAudioDescriptionRequested() { |
| 1760 |
synchronized (mLock) { |
| 1761 |
IAccessibilityManager service = getServiceLocked(); |
| 1762 |
if (service == null) { |
| 1763 |
return false; |
| 1764 |
} |
| 1765 |
return mIsAudioDescriptionByDefaultRequested; |
| 1766 |
} |
| 1767 |
} |
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
public void setSystemAudioCaptioningEnabled(boolean isEnabled, int userId) { |
| 1777 |
final IAccessibilityManager service; |
| 1778 |
synchronized (mLock) { |
| 1779 |
service = getServiceLocked(); |
| 1780 |
if (service == null) { |
| 1781 |
return; |
| 1782 |
} |
| 1783 |
} |
| 1784 |
try { |
| 1785 |
service.setSystemAudioCaptioningEnabled(isEnabled, userId); |
| 1786 |
} catch (RemoteException re) { |
| 1787 |
throw re.rethrowFromSystemServer(); |
| 1788 |
} |
| 1789 |
} |
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
public boolean isSystemAudioCaptioningUiEnabled(int userId) { |
| 1799 |
final IAccessibilityManager service; |
| 1800 |
synchronized (mLock) { |
| 1801 |
service = getServiceLocked(); |
| 1802 |
if (service == null) { |
| 1803 |
return false; |
| 1804 |
} |
| 1805 |
} |
| 1806 |
try { |
| 1807 |
return service.isSystemAudioCaptioningUiEnabled(userId); |
| 1808 |
} catch (RemoteException re) { |
| 1809 |
throw re.rethrowFromSystemServer(); |
| 1810 |
} |
| 1811 |
} |
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
public void setSystemAudioCaptioningUiEnabled(boolean isEnabled, int userId) { |
| 1821 |
final IAccessibilityManager service; |
| 1822 |
synchronized (mLock) { |
| 1823 |
service = getServiceLocked(); |
| 1824 |
if (service == null) { |
| 1825 |
return; |
| 1826 |
} |
| 1827 |
} |
| 1828 |
try { |
| 1829 |
service.setSystemAudioCaptioningUiEnabled(isEnabled, userId); |
| 1830 |
} catch (RemoteException re) { |
| 1831 |
throw re.rethrowFromSystemServer(); |
| 1832 |
} |
| 1833 |
} |
| 1834 |
|
| 1835 |
private IAccessibilityManager getServiceLocked() { |
| 1836 |
if (mService == null) { |
| 1837 |
tryConnectToServiceLocked(null); |
| 1838 |
} |
| 1839 |
return mService; |
| 1840 |
} |
| 1841 |
|
| 1842 |
private void tryConnectToServiceLocked(IAccessibilityManager service) { |
| 1843 |
if (service == null) { |
| 1844 |
IBinder iBinder = ServiceManager.getService(Context.ACCESSIBILITY_SERVICE); |
| 1845 |
if (iBinder == null) { |
| 1846 |
return; |
| 1847 |
} |
| 1848 |
service = IAccessibilityManager.Stub.asInterface(iBinder); |
| 1849 |
} |
| 1850 |
|
| 1851 |
try { |
| 1852 |
final long userStateAndRelevantEvents = service.addClient(mClient, mUserId); |
| 1853 |
setStateLocked(IntPair.first(userStateAndRelevantEvents)); |
| 1854 |
mRelevantEventTypes = IntPair.second(userStateAndRelevantEvents); |
| 1855 |
updateUiTimeout(service.getRecommendedTimeoutMillis()); |
| 1856 |
updateFocusAppearanceLocked(service.getFocusStrokeWidth(), service.getFocusColor()); |
| 1857 |
mService = service; |
| 1858 |
} catch (RemoteException re) { |
| 1859 |
Log.e(LOG_TAG, "AccessibilityManagerService is dead", re); |
| 1860 |
} |
| 1861 |
} |
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
private void notifyAccessibilityStateChanged() { |
| 1867 |
final boolean isEnabled; |
| 1868 |
final ArrayMap<AccessibilityStateChangeListener, Handler> listeners; |
| 1869 |
synchronized (mLock) { |
| 1870 |
if (mAccessibilityStateChangeListeners.isEmpty()) { |
| 1871 |
return; |
| 1872 |
} |
| 1873 |
isEnabled = isEnabled(); |
| 1874 |
listeners = new ArrayMap<>(mAccessibilityStateChangeListeners); |
| 1875 |
} |
| 1876 |
|
| 1877 |
final int numListeners = listeners.size(); |
| 1878 |
for (int i = 0; i < numListeners; i++) { |
| 1879 |
final AccessibilityStateChangeListener listener = listeners.keyAt(i); |
| 1880 |
listeners.valueAt(i).post(() -> |
| 1881 |
listener.onAccessibilityStateChanged(isEnabled)); |
| 1882 |
} |
| 1883 |
} |
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
private void notifyTouchExplorationStateChanged() { |
| 1889 |
final boolean isTouchExplorationEnabled; |
| 1890 |
final ArrayMap<TouchExplorationStateChangeListener, Handler> listeners; |
| 1891 |
synchronized (mLock) { |
| 1892 |
if (mTouchExplorationStateChangeListeners.isEmpty()) { |
| 1893 |
return; |
| 1894 |
} |
| 1895 |
isTouchExplorationEnabled = mIsTouchExplorationEnabled; |
| 1896 |
listeners = new ArrayMap<>(mTouchExplorationStateChangeListeners); |
| 1897 |
} |
| 1898 |
|
| 1899 |
final int numListeners = listeners.size(); |
| 1900 |
for (int i = 0; i < numListeners; i++) { |
| 1901 |
final TouchExplorationStateChangeListener listener = listeners.keyAt(i); |
| 1902 |
listeners.valueAt(i).post(() -> |
| 1903 |
listener.onTouchExplorationStateChanged(isTouchExplorationEnabled)); |
| 1904 |
} |
| 1905 |
} |
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
private void notifyHighTextContrastStateChanged() { |
| 1911 |
final boolean isHighTextContrastEnabled; |
| 1912 |
final ArrayMap<HighTextContrastChangeListener, Handler> listeners; |
| 1913 |
synchronized (mLock) { |
| 1914 |
if (mHighTextContrastStateChangeListeners.isEmpty()) { |
| 1915 |
return; |
| 1916 |
} |
| 1917 |
isHighTextContrastEnabled = mIsHighTextContrastEnabled; |
| 1918 |
listeners = new ArrayMap<>(mHighTextContrastStateChangeListeners); |
| 1919 |
} |
| 1920 |
|
| 1921 |
final int numListeners = listeners.size(); |
| 1922 |
for (int i = 0; i < numListeners; i++) { |
| 1923 |
final HighTextContrastChangeListener listener = listeners.keyAt(i); |
| 1924 |
listeners.valueAt(i).post(() -> |
| 1925 |
listener.onHighTextContrastStateChanged(isHighTextContrastEnabled)); |
| 1926 |
} |
| 1927 |
} |
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
private void notifyAudioDescriptionbyDefaultStateChanged() { |
| 1933 |
final boolean isAudioDescriptionByDefaultRequested; |
| 1934 |
final ArrayMap<AudioDescriptionRequestedChangeListener, Executor> listeners; |
| 1935 |
synchronized (mLock) { |
| 1936 |
if (mAudioDescriptionRequestedChangeListeners.isEmpty()) { |
| 1937 |
return; |
| 1938 |
} |
| 1939 |
isAudioDescriptionByDefaultRequested = mIsAudioDescriptionByDefaultRequested; |
| 1940 |
listeners = new ArrayMap<>(mAudioDescriptionRequestedChangeListeners); |
| 1941 |
} |
| 1942 |
|
| 1943 |
final int numListeners = listeners.size(); |
| 1944 |
for (int i = 0; i < numListeners; i++) { |
| 1945 |
final AudioDescriptionRequestedChangeListener listener = listeners.keyAt(i); |
| 1946 |
listeners.valueAt(i).execute(() -> |
| 1947 |
listener.onAudioDescriptionRequestedChanged( |
| 1948 |
isAudioDescriptionByDefaultRequested)); |
| 1949 |
} |
| 1950 |
} |
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
private void updateAccessibilityTracingState(int stateFlag) { |
| 1956 |
synchronized (mLock) { |
| 1957 |
mAccessibilityTracingState = stateFlag; |
| 1958 |
} |
| 1959 |
} |
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
private void updateUiTimeout(long uiTimeout) { |
| 1968 |
mInteractiveUiTimeout = IntPair.first(uiTimeout); |
| 1969 |
mNonInteractiveUiTimeout = IntPair.second(uiTimeout); |
| 1970 |
} |
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
|
| 1978 |
private void updateFocusAppearanceLocked(int strokeWidth, int color) { |
| 1979 |
if (mFocusStrokeWidth == strokeWidth && mFocusColor == color) { |
| 1980 |
return; |
| 1981 |
} |
| 1982 |
mFocusStrokeWidth = strokeWidth; |
| 1983 |
mFocusColor = color; |
| 1984 |
} |
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
private void initialFocusAppearanceLocked(Resources resource) { |
| 1992 |
try { |
| 1993 |
mFocusStrokeWidth = resource.getDimensionPixelSize( |
| 1994 |
R.dimen.accessibility_focus_highlight_stroke_width); |
| 1995 |
mFocusColor = resource.getColor(R.color.accessibility_focus_highlight_color); |
| 1996 |
} catch (Resources.NotFoundException re) { |
| 1997 |
|
| 1998 |
|
| 1999 |
mFocusStrokeWidth = (int) (4 * resource.getDisplayMetrics().density); |
| 2000 |
mFocusColor = 0xbf39b500; |
| 2001 |
Log.e(LOG_TAG, "Error while initialing the focus appearance data then setting to" |
| 2002 |
+ " default value by hardcoded", re); |
| 2003 |
} |
| 2004 |
} |
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
public static boolean isAccessibilityButtonSupported() { |
| 2013 |
final Resources res = Resources.getSystem(); |
| 2014 |
return res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
| 2015 |
} |
| 2016 |
|
| 2017 |
private final class MyCallback implements Handler.Callback { |
| 2018 |
public static final int MSG_SET_STATE = 1; |
| 2019 |
|
| 2020 |
@Override |
| 2021 |
public boolean handleMessage(Message message) { |
| 2022 |
switch (message.what) { |
| 2023 |
case MSG_SET_STATE: { |
| 2024 |
|
| 2025 |
final int state = message.arg1; |
| 2026 |
synchronized (mLock) { |
| 2027 |
setStateLocked(state); |
| 2028 |
} |
| 2029 |
} break; |
| 2030 |
} |
| 2031 |
return true; |
| 2032 |
} |
| 2033 |
} |
| 2034 |
} |