AccessibilityService.java revision fefd20e927b7252d63acb7bb1852c5188e3c1b2e
1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.accessibilityservice; 18 19import android.app.Service; 20import android.content.Context; 21import android.content.Intent; 22import android.os.IBinder; 23import android.os.Looper; 24import android.os.Message; 25import android.os.RemoteException; 26import android.util.Log; 27import android.view.accessibility.AccessibilityEvent; 28import android.view.accessibility.AccessibilityInteractionClient; 29import android.view.accessibility.AccessibilityNodeInfo; 30 31import com.android.internal.os.HandlerCaller; 32 33/** 34 * An accessibility service runs in the background and receives callbacks by the system 35 * when {@link AccessibilityEvent}s are fired. Such events denote some state transition 36 * in the user interface, for example, the focus has changed, a button has been clicked, 37 * etc. Such a service can optionally request the capability for querying the content 38 * of the active window. Development of an accessibility service requires extending this 39 * class and implementing its abstract methods. 40 * 41 * <div class="special reference"> 42 * <h3>Developer Guides</h3> 43 * <p>For more information about creating AccessibilityServices, read the 44 * <a href="{@docRoot}guide/topics/ui/accessibility/index.html">Accessibility</a> 45 * developer guide.</p> 46 * </div> 47 * 48 * <h3>Lifecycle</h3> 49 * <p> 50 * The lifecycle of an accessibility service is managed exclusively by the system and 51 * follows the established service life cycle. Additionally, starting or stopping an 52 * accessibility service is triggered exclusively by an explicit user action through 53 * enabling or disabling it in the device settings. After the system binds to a service it 54 * calls {@link AccessibilityService#onServiceConnected()}. This method can be 55 * overriden by clients that want to perform post binding setup. 56 * </p> 57 * <h3>Declaration</h3> 58 * <p> 59 * An accessibility is declared as any other service in an AndroidManifest.xml but it 60 * must also specify that it handles the "android.accessibilityservice.AccessibilityService" 61 * {@link android.content.Intent}. Failure to declare this intent will cause the system to 62 * ignore the accessibility service. Following is an example declaration: 63 * </p> 64 * <pre> <service android:name=".MyAccessibilityService"> 65 * <intent-filter> 66 * <action android:name="android.accessibilityservice.AccessibilityService" /> 67 * </intent-filter> 68 * . . . 69 * </service></pre> 70 * <h3>Configuration</h3> 71 * <p> 72 * An accessibility service can be configured to receive specific types of accessibility events, 73 * listen only to specific packages, get events from each type only once in a given time frame, 74 * retrieve window content, specify a settings activity, etc. 75 * </p> 76 * <p> 77 * There are two approaches for configuring an accessibility service: 78 * </p> 79 * <ul> 80 * <li> 81 * Providing a {@link #SERVICE_META_DATA meta-data} entry in the manifest when declaring 82 * the service. A service declaration with a meta-data tag is presented below: 83 * <pre> <service android:name=".MyAccessibilityService"> 84 * <intent-filter> 85 * <action android:name="android.accessibilityservice.AccessibilityService" /> 86 * </intent-filter> 87 * <meta-data android:name="android.accessibilityservice" android:resource="@xml/accessibilityservice" /> 88 * </service></pre> 89 * <p class="note"> 90 * <strong>Note:</strong> This approach enables setting all properties. 91 * </p> 92 * <p> 93 * For more details refer to {@link #SERVICE_META_DATA} and 94 * <code><{@link android.R.styleable#AccessibilityService accessibility-service}></code>. 95 * </p> 96 * </li> 97 * <li> 98 * Calling {@link AccessibilityService#setServiceInfo(AccessibilityServiceInfo)}. Note 99 * that this method can be called any time to dynamically change the service configuration. 100 * <p class="note"> 101 * <strong>Note:</strong> This approach enables setting only dynamically configurable properties: 102 * {@link AccessibilityServiceInfo#eventTypes}, 103 * {@link AccessibilityServiceInfo#feedbackType}, 104 * {@link AccessibilityServiceInfo#flags}, 105 * {@link AccessibilityServiceInfo#notificationTimeout}, 106 * {@link AccessibilityServiceInfo#packageNames} 107 * </p> 108 * <p> 109 * For more details refer to {@link AccessibilityServiceInfo}. 110 * </p> 111 * </li> 112 * </ul> 113 * <h3>Retrieving window content</h3> 114 * <p> 115 * A service can specify in its declaration that it can retrieve the active window 116 * content which is represented as a tree of {@link AccessibilityNodeInfo}. Note that 117 * declaring this capability requires that the service declares its configuration via 118 * an XML resource referenced by {@link #SERVICE_META_DATA}. 119 * </p> 120 * <p> 121 * For security purposes an accessibility service can retrieve only the content of the 122 * currently active window. The currently active window is defined as the window from 123 * which was fired the last event of the following types: 124 * {@link AccessibilityEvent#TYPE_WINDOW_STATE_CHANGED}, 125 * {@link AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}, 126 * {@link AccessibilityEvent#TYPE_VIEW_HOVER_EXIT}, 127 * In other words, the last window that was shown or the last window that the user has touched 128 * during touch exploration. 129 * </p> 130 * <p> 131 * The entry point for retrieving window content is through calling 132 * {@link AccessibilityEvent#getSource() AccessibilityEvent.getSource()} of the last received 133 * event of the above types or a previous event from the same window 134 * (see {@link AccessibilityEvent#getWindowId() AccessibilityEvent.getWindowId()}). Invoking 135 * this method will return an {@link AccessibilityNodeInfo} that can be used to traverse the 136 * window content which represented as a tree of such objects. 137 * </p> 138 * <p class="note"> 139 * <strong>Note</strong> An accessibility service may have requested to be notified for 140 * a subset of the event types, thus be unaware that the active window has changed. Therefore 141 * accessibility service that would like to retrieve window content should: 142 * <ul> 143 * <li> 144 * Register for all event types with no notification timeout and keep track for the active 145 * window by calling {@link AccessibilityEvent#getWindowId()} of the last received event and 146 * compare this with the {@link AccessibilityNodeInfo#getWindowId()} before calling retrieval 147 * methods on the latter. 148 * </li> 149 * <li> 150 * Prepare that a retrieval method on {@link AccessibilityNodeInfo} may fail since the 151 * active window has changed and the service did not get the accessibility event yet. Note 152 * that it is possible to have a retrieval method failing even adopting the strategy 153 * specified in the previous bullet because the accessibility event dispatch is asynchronous 154 * and crosses process boundaries. 155 * </li> 156 * </ul> 157 * </p> 158 * <h3>Notification strategy</h3> 159 * <p> 160 * For each feedback type only one accessibility service is notified. Services are notified 161 * in the order of registration. Hence, if two services are registered for the same 162 * feedback type in the same package the first one wins. It is possible however, to 163 * register a service as the default one for a given feedback type. In such a case this 164 * service is invoked if no other service was interested in the event. In other words, default 165 * services do not compete with other services and are notified last regardless of the 166 * registration order. This enables "generic" accessibility services that work reasonably 167 * well with most applications to coexist with "polished" ones that are targeted for 168 * specific applications. 169 * </p> 170 * <p class="note"> 171 * <strong>Note:</strong> The event notification timeout is useful to avoid propagating 172 * events to the client too frequently since this is accomplished via an expensive 173 * interprocess call. One can think of the timeout as a criteria to determine when 174 * event generation has settled down.</p> 175 * <h3>Event types</h3> 176 * <ul> 177 * <li>{@link AccessibilityEvent#TYPE_VIEW_CLICKED} 178 * <li>{@link AccessibilityEvent#TYPE_VIEW_LONG_CLICKED} 179 * <li>{@link AccessibilityEvent#TYPE_VIEW_FOCUSED} 180 * <li>{@link AccessibilityEvent#TYPE_VIEW_SELECTED} 181 * <li>{@link AccessibilityEvent#TYPE_VIEW_TEXT_CHANGED} 182 * <li>{@link AccessibilityEvent#TYPE_WINDOW_STATE_CHANGED} 183 * <li>{@link AccessibilityEvent#TYPE_NOTIFICATION_STATE_CHANGED} 184 * <li>{@link AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_START} 185 * <li>{@link AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_END} 186 * <li>{@link AccessibilityEvent#TYPE_VIEW_HOVER_ENTER} 187 * <li>{@link AccessibilityEvent#TYPE_VIEW_HOVER_EXIT} 188 * <li>{@link AccessibilityEvent#TYPE_VIEW_SCROLLED} 189 * <li>{@link AccessibilityEvent#TYPE_VIEW_TEXT_SELECTION_CHANGED} 190 * <li>{@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} 191 * </ul> 192 * <h3>Feedback types</h3> 193 * <ul> 194 * <li>{@link AccessibilityServiceInfo#FEEDBACK_AUDIBLE} 195 * <li>{@link AccessibilityServiceInfo#FEEDBACK_HAPTIC} 196 * <li>{@link AccessibilityServiceInfo#FEEDBACK_AUDIBLE} 197 * <li>{@link AccessibilityServiceInfo#FEEDBACK_VISUAL} 198 * <li>{@link AccessibilityServiceInfo#FEEDBACK_GENERIC} 199 * </ul> 200 * @see AccessibilityEvent 201 * @see AccessibilityServiceInfo 202 * @see android.view.accessibility.AccessibilityManager 203 */ 204public abstract class AccessibilityService extends Service { 205 206 /** 207 * The user has performed a swipe up gesture on the touch screen. 208 */ 209 public static final int GESTURE_SWIPE_UP = 1; 210 211 /** 212 * The user has performed a swipe down gesture on the touch screen. 213 */ 214 public static final int GESTURE_SWIPE_DOWN = 2; 215 216 /** 217 * The user has performed a swipe left gesture on the touch screen. 218 */ 219 public static final int GESTURE_SWIPE_LEFT = 3; 220 221 /** 222 * The user has performed a swipe right gesture on the touch screen. 223 */ 224 public static final int GESTURE_SWIPE_RIGHT = 4; 225 226 /** 227 * The user has performed a swipe left and right gesture on the touch screen. 228 */ 229 public static final int GESTURE_SWIPE_LEFT_AND_RIGHT = 5; 230 231 /** 232 * The user has performed a swipe right and left gesture on the touch screen. 233 */ 234 public static final int GESTURE_SWIPE_RIGHT_AND_LEFT = 6; 235 236 /** 237 * The user has performed a swipe up and down gesture on the touch screen. 238 */ 239 public static final int GESTURE_SWIPE_UP_AND_DOWN = 7; 240 241 /** 242 * The user has performed a swipe down and up gesture on the touch screen. 243 */ 244 public static final int GESTURE_SWIPE_DOWN_AND_UP = 8; 245 246 /** 247 * The user has performed a clockwise circle gesture on the touch screen. 248 */ 249 public static final int GESTURE_CLOCKWISE_CIRCLE = 9; 250 251 /** 252 * The user has performed a counter clockwise circle gesture on the touch screen. 253 */ 254 public static final int GESTURE_COUNTER_CLOCKWISE_CIRCLE = 10; 255 256 /** 257 * The user has performed a left and up gesture on the touch screen. 258 */ 259 public static final int GESTURE_SWIPE_LEFT_AND_UP = 11; 260 261 /** 262 * The user has performed a left and down gesture on the touch screen. 263 */ 264 public static final int GESTURE_SWIPE_LEFT_AND_DOWN = 12; 265 266 /** 267 * The user has performed a right and up gesture on the touch screen. 268 */ 269 public static final int GESTURE_SWIPE_RIGHT_AND_UP = 13; 270 271 /** 272 * The user has performed a right and down gesture on the touch screen. 273 */ 274 public static final int GESTURE_SWIPE_RIGHT_AND_DOWN = 14; 275 276 /** 277 * The user has performed an up and left gesture on the touch screen. 278 */ 279 public static final int GESTURE_SWIPE_UP_AND_LEFT = 15; 280 281 /** 282 * The user has performed an up and right gesture on the touch screen. 283 */ 284 public static final int GESTURE_SWIPE_UP_AND_RIGHT = 16; 285 286 /** 287 * The user has performed an down and left gesture on the touch screen. 288 */ 289 public static final int GESTURE_SWIPE_DOWN_AND_LEFT = 17; 290 291 /** 292 * The user has performed an down and right gesture on the touch screen. 293 */ 294 public static final int GESTURE_SWIPE_DOWN_AND_RIGHT = 18; 295 296 /** 297 * The user has performed a two finger tap gesture on the touch screen. 298 */ 299 public static final int GESTURE_TWO_FINGER_TAP = 19; 300 301 /** 302 * The user has performed a two finger long press gesture on the touch screen. 303 */ 304 public static final int GESTURE_TWO_FINGER_LONG_PRESS = 20; 305 306 /** 307 * The {@link Intent} that must be declared as handled by the service. 308 */ 309 public static final String SERVICE_INTERFACE = 310 "android.accessibilityservice.AccessibilityService"; 311 312 /** 313 * Name under which an AccessibilityService component publishes information 314 * about itself. This meta-data must reference an XML resource containing an 315 * <code><{@link android.R.styleable#AccessibilityService accessibility-service}></code> 316 * tag. This is a a sample XML file configuring an accessibility service: 317 * <pre> <accessibility-service 318 * android:accessibilityEventTypes="typeViewClicked|typeViewFocused" 319 * android:packageNames="foo.bar, foo.baz" 320 * android:accessibilityFeedbackType="feedbackSpoken" 321 * android:notificationTimeout="100" 322 * android:accessibilityFlags="flagDefault" 323 * android:settingsActivity="foo.bar.TestBackActivity" 324 * android:canRetrieveWindowContent="true" 325 * . . . 326 * /></pre> 327 */ 328 public static final String SERVICE_META_DATA = "android.accessibilityservice"; 329 330 /** 331 * Action to go back. 332 */ 333 public static final int GLOBAL_ACTION_BACK = 1; 334 335 /** 336 * Action to go home. 337 */ 338 public static final int GLOBAL_ACTION_HOME = 2; 339 340 /** 341 * Action to open the recents. 342 */ 343 public static final int GLOBAL_ACTION_RECENTS = 3; 344 345 /** 346 * Action to open the notifications. 347 */ 348 public static final int GLOBAL_ACTION_NOTIFICATIONS = 4; 349 350 private static final String LOG_TAG = "AccessibilityService"; 351 352 interface Callbacks { 353 public void onAccessibilityEvent(AccessibilityEvent event); 354 public void onInterrupt(); 355 public void onServiceConnected(); 356 public void onSetConnectionId(int connectionId); 357 public boolean onGesture(int gestureId); 358 } 359 360 private int mConnectionId; 361 362 private AccessibilityServiceInfo mInfo; 363 364 /** 365 * Callback for {@link android.view.accessibility.AccessibilityEvent}s. 366 * 367 * @param event An event. 368 */ 369 public abstract void onAccessibilityEvent(AccessibilityEvent event); 370 371 /** 372 * Callback for interrupting the accessibility feedback. 373 */ 374 public abstract void onInterrupt(); 375 376 /** 377 * This method is a part of the {@link AccessibilityService} lifecycle and is 378 * called after the system has successfully bound to the service. If is 379 * convenient to use this method for setting the {@link AccessibilityServiceInfo}. 380 * 381 * @see AccessibilityServiceInfo 382 * @see #setServiceInfo(AccessibilityServiceInfo) 383 */ 384 protected void onServiceConnected() { 385 386 } 387 388 /** 389 * Called by the system when the user performs a specific gesture on the 390 * touch screen. If the gesture is not handled in this callback the system 391 * may provide default handing. Therefore, one should return true from this 392 * function if overriding of default behavior is desired. 393 * 394 * <strong>Note:</strong> To receive gestures an accessibility service 395 * must declare that it can handle such by specifying the 396 * <code><{@link android.R.styleable#AccessibilityService_canHandleGestures 397 * canHandleGestures}></code> attribute. 398 * 399 * @param gestureId The unique id of the performed gesture. 400 * 401 * @return Whether the gesture was handled. 402 * 403 * @see #GESTURE_SWIPE_UP 404 * @see #GESTURE_SWIPE_UP_AND_LEFT 405 * @see #GESTURE_SWIPE_UP_AND_DOWN 406 * @see #GESTURE_SWIPE_UP_AND_RIGHT 407 * @see #GESTURE_SWIPE_DOWN 408 * @see #GESTURE_SWIPE_DOWN_AND_LEFT 409 * @see #GESTURE_SWIPE_DOWN_AND_UP 410 * @see #GESTURE_SWIPE_DOWN_AND_RIGHT 411 * @see #GESTURE_SWIPE_LEFT 412 * @see #GESTURE_SWIPE_LEFT_AND_UP 413 * @see #GESTURE_SWIPE_LEFT_AND_RIGHT 414 * @see #GESTURE_SWIPE_LEFT_AND_DOWN 415 * @see #GESTURE_SWIPE_RIGHT 416 * @see #GESTURE_SWIPE_RIGHT_AND_UP 417 * @see #GESTURE_SWIPE_RIGHT_AND_LEFT 418 * @see #GESTURE_SWIPE_RIGHT_AND_DOWN 419 * @see #GESTURE_CLOCKWISE_CIRCLE 420 * @see #GESTURE_COUNTER_CLOCKWISE_CIRCLE 421 * @see #GESTURE_TWO_FINGER_TAP 422 * @see #GESTURE_TWO_FINGER_LONG_PRESS 423 */ 424 protected boolean onGesture(int gestureId) { 425 // TODO: Describe the default gesture processing in the javaDoc once it is finalized. 426 return false; 427 } 428 429 /** 430 * Gets the root node in the currently active window if this service 431 * can retrieve window content. 432 * 433 * @return The root node if this service can retrieve window content. 434 */ 435 public AccessibilityNodeInfo getRootInActiveWindow() { 436 return AccessibilityInteractionClient.getInstance().getRootInActiveWindow(mConnectionId); 437 } 438 439 /** 440 * Performs a global action. Such an action can be performed 441 * at any moment regardless of the current application or user 442 * location in that application. For example going back, going 443 * home, opening recents, etc. 444 * 445 * @param action The action to perform. 446 * @return Whether the action was successfully performed. 447 * 448 * @see #GLOBAL_ACTION_BACK 449 * @see #GLOBAL_ACTION_HOME 450 * @see #GLOBAL_ACTION_NOTIFICATIONS 451 * @see #GLOBAL_ACTION_RECENTS 452 */ 453 public final boolean performGlobalAction(int action) { 454 IAccessibilityServiceConnection connection = 455 AccessibilityInteractionClient.getInstance().getConnection(mConnectionId); 456 if (connection != null) { 457 try { 458 return connection.performGlobalAction(action); 459 } catch (RemoteException re) { 460 Log.w(LOG_TAG, "Error while calling performGlobalAction", re); 461 } 462 } 463 return false; 464 } 465 466 /** 467 * Gets the an {@link AccessibilityServiceInfo} describing this 468 * {@link AccessibilityService}. This method is useful if one wants 469 * to change some of the dynamically configurable properties at 470 * runtime. 471 * 472 * @return The accessibility service info. 473 * 474 * @see AccessibilityNodeInfo 475 */ 476 public final AccessibilityServiceInfo getServiceInfo() { 477 IAccessibilityServiceConnection connection = 478 AccessibilityInteractionClient.getInstance().getConnection(mConnectionId); 479 if (connection != null) { 480 try { 481 return connection.getServiceInfo(); 482 } catch (RemoteException re) { 483 Log.w(LOG_TAG, "Error while getting AccessibilityServiceInfo", re); 484 } 485 } 486 return null; 487 } 488 489 /** 490 * Sets the {@link AccessibilityServiceInfo} that describes this service. 491 * <p> 492 * Note: You can call this method any time but the info will be picked up after 493 * the system has bound to this service and when this method is called thereafter. 494 * 495 * @param info The info. 496 */ 497 public final void setServiceInfo(AccessibilityServiceInfo info) { 498 mInfo = info; 499 sendServiceInfo(); 500 } 501 502 /** 503 * Sets the {@link AccessibilityServiceInfo} for this service if the latter is 504 * properly set and there is an {@link IAccessibilityServiceConnection} to the 505 * AccessibilityManagerService. 506 */ 507 private void sendServiceInfo() { 508 IAccessibilityServiceConnection connection = 509 AccessibilityInteractionClient.getInstance().getConnection(mConnectionId); 510 if (mInfo != null && connection != null) { 511 try { 512 connection.setServiceInfo(mInfo); 513 mInfo = null; 514 AccessibilityInteractionClient.getInstance().clearCache(); 515 } catch (RemoteException re) { 516 Log.w(LOG_TAG, "Error while setting AccessibilityServiceInfo", re); 517 } 518 } 519 } 520 521 /** 522 * Implement to return the implementation of the internal accessibility 523 * service interface. 524 */ 525 @Override 526 public final IBinder onBind(Intent intent) { 527 return new IAccessibilityServiceClientWrapper(this, getMainLooper(), new Callbacks() { 528 @Override 529 public void onServiceConnected() { 530 AccessibilityService.this.onServiceConnected(); 531 } 532 533 @Override 534 public void onInterrupt() { 535 AccessibilityService.this.onInterrupt(); 536 } 537 538 @Override 539 public void onAccessibilityEvent(AccessibilityEvent event) { 540 AccessibilityService.this.onAccessibilityEvent(event); 541 } 542 543 @Override 544 public void onSetConnectionId( int connectionId) { 545 mConnectionId = connectionId; 546 } 547 548 @Override 549 public boolean onGesture(int gestureId) { 550 return AccessibilityService.this.onGesture(gestureId); 551 } 552 }); 553 } 554 555 /** 556 * Implements the internal {@link IAccessibilityServiceClient} interface to convert 557 * incoming calls to it back to calls on an {@link AccessibilityService}. 558 */ 559 static class IAccessibilityServiceClientWrapper extends IAccessibilityServiceClient.Stub 560 implements HandlerCaller.Callback { 561 562 static final int NO_ID = -1; 563 564 private static final int DO_SET_SET_CONNECTION = 10; 565 private static final int DO_ON_INTERRUPT = 20; 566 private static final int DO_ON_ACCESSIBILITY_EVENT = 30; 567 private static final int DO_ON_GESTURE = 40; 568 569 private final HandlerCaller mCaller; 570 571 private final Callbacks mCallback; 572 573 public IAccessibilityServiceClientWrapper(Context context, Looper looper, 574 Callbacks callback) { 575 mCallback = callback; 576 mCaller = new HandlerCaller(context, looper, this); 577 } 578 579 public void setConnection(IAccessibilityServiceConnection connection, int connectionId) { 580 Message message = mCaller.obtainMessageIO(DO_SET_SET_CONNECTION, connectionId, 581 connection); 582 mCaller.sendMessage(message); 583 } 584 585 public void onInterrupt() { 586 Message message = mCaller.obtainMessage(DO_ON_INTERRUPT); 587 mCaller.sendMessage(message); 588 } 589 590 public void onAccessibilityEvent(AccessibilityEvent event) { 591 Message message = mCaller.obtainMessageO(DO_ON_ACCESSIBILITY_EVENT, event); 592 mCaller.sendMessage(message); 593 } 594 595 public void onGesture(int gestureId, IAccessibilityServiceClientCallback callback, 596 int interactionId) { 597 Message message = mCaller.obtainMessageIIO(DO_ON_GESTURE, gestureId, interactionId, 598 callback); 599 mCaller.sendMessage(message); 600 } 601 602 public void executeMessage(Message message) { 603 switch (message.what) { 604 case DO_ON_ACCESSIBILITY_EVENT : 605 AccessibilityEvent event = (AccessibilityEvent) message.obj; 606 if (event != null) { 607 AccessibilityInteractionClient.getInstance().onAccessibilityEvent(event); 608 mCallback.onAccessibilityEvent(event); 609 event.recycle(); 610 } 611 return; 612 case DO_ON_INTERRUPT : 613 mCallback.onInterrupt(); 614 return; 615 case DO_SET_SET_CONNECTION : 616 final int connectionId = message.arg1; 617 IAccessibilityServiceConnection connection = 618 (IAccessibilityServiceConnection) message.obj; 619 if (connection != null) { 620 AccessibilityInteractionClient.getInstance().addConnection(connectionId, 621 connection); 622 mCallback.onSetConnectionId(connectionId); 623 mCallback.onServiceConnected(); 624 } else { 625 AccessibilityInteractionClient.getInstance().removeConnection(connectionId); 626 mCallback.onSetConnectionId(AccessibilityInteractionClient.NO_ID); 627 } 628 return; 629 case DO_ON_GESTURE : 630 final int gestureId = message.arg1; 631 final int interactionId = message.arg2; 632 IAccessibilityServiceClientCallback callback = 633 (IAccessibilityServiceClientCallback) message.obj; 634 final boolean handled = mCallback.onGesture(gestureId); 635 try { 636 callback.setGestureResult(gestureId, handled, interactionId); 637 } catch (RemoteException re) { 638 Log.e(LOG_TAG, "Error calling back with the gesture resut.", re); 639 } 640 return; 641 default : 642 Log.w(LOG_TAG, "Unknown message type " + message.what); 643 } 644 } 645 } 646} 647