AccessibilityService.java revision 87bd0dccf7f2558ea1a5e0fce523aea022709834
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> &lt;service android:name=".MyAccessibilityService"&gt;
65 *     &lt;intent-filter&gt;
66 *         &lt;action android:name="android.accessibilityservice.AccessibilityService" /&gt;
67 *     &lt;/intent-filter&gt;
68 *     . . .
69 * &lt;/service&gt;</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> &lt;service android:name=".MyAccessibilityService"&gt;
84 *     &lt;intent-filter&gt;
85 *         &lt;action android:name="android.accessibilityservice.AccessibilityService" /&gt;
86 *     &lt;/intent-filter&gt;
87 *     &lt;meta-data android:name="android.accessibilityservice" android:resource="@xml/accessibilityservice" /&gt;
88 * &lt;/service&gt;</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>&lt;{@link android.R.styleable#AccessibilityService accessibility-service}&gt;</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 left and up gesture on the touch screen.
248     */
249    public static final int GESTURE_SWIPE_LEFT_AND_UP = 9;
250
251    /**
252     * The user has performed a left and down gesture on the touch screen.
253     */
254    public static final int GESTURE_SWIPE_LEFT_AND_DOWN = 10;
255
256    /**
257     * The user has performed a right and up gesture on the touch screen.
258     */
259    public static final int GESTURE_SWIPE_RIGHT_AND_UP = 11;
260
261    /**
262     * The user has performed a right and down gesture on the touch screen.
263     */
264    public static final int GESTURE_SWIPE_RIGHT_AND_DOWN = 12;
265
266    /**
267     * The user has performed an up and left gesture on the touch screen.
268     */
269    public static final int GESTURE_SWIPE_UP_AND_LEFT = 13;
270
271    /**
272     * The user has performed an up and right gesture on the touch screen.
273     */
274    public static final int GESTURE_SWIPE_UP_AND_RIGHT = 14;
275
276    /**
277     * The user has performed an down and left gesture on the touch screen.
278     */
279    public static final int GESTURE_SWIPE_DOWN_AND_LEFT = 15;
280
281    /**
282     * The user has performed an down and right gesture on the touch screen.
283     */
284    public static final int GESTURE_SWIPE_DOWN_AND_RIGHT = 16;
285
286    /**
287     * The user has performed a double tap gesture on the touch screen.
288     */
289    public static final int GESTURE_DOUBLE_TAP = 17;
290
291    /**
292     * The user has performed a tap and hold gesture on the touch screen.
293     */
294    public static final int GESTURE_TAP_AND_HOLD = 18;
295
296    /**
297     * The {@link Intent} that must be declared as handled by the service.
298     */
299    public static final String SERVICE_INTERFACE =
300        "android.accessibilityservice.AccessibilityService";
301
302    /**
303     * Name under which an AccessibilityService component publishes information
304     * about itself. This meta-data must reference an XML resource containing an
305     * <code>&lt;{@link android.R.styleable#AccessibilityService accessibility-service}&gt;</code>
306     * tag. This is a a sample XML file configuring an accessibility service:
307     * <pre> &lt;accessibility-service
308     *     android:accessibilityEventTypes="typeViewClicked|typeViewFocused"
309     *     android:packageNames="foo.bar, foo.baz"
310     *     android:accessibilityFeedbackType="feedbackSpoken"
311     *     android:notificationTimeout="100"
312     *     android:accessibilityFlags="flagDefault"
313     *     android:settingsActivity="foo.bar.TestBackActivity"
314     *     android:canRetrieveWindowContent="true"
315     *     . . .
316     * /&gt;</pre>
317     */
318    public static final String SERVICE_META_DATA = "android.accessibilityservice";
319
320    /**
321     * Action to go back.
322     */
323    public static final int GLOBAL_ACTION_BACK = 1;
324
325    /**
326     * Action to go home.
327     */
328    public static final int GLOBAL_ACTION_HOME = 2;
329
330    /**
331     * Action to open the recents.
332     */
333    public static final int GLOBAL_ACTION_RECENTS = 3;
334
335    /**
336     * Action to open the notifications.
337     */
338    public static final int GLOBAL_ACTION_NOTIFICATIONS = 4;
339
340    private static final String LOG_TAG = "AccessibilityService";
341
342    interface Callbacks {
343        public void onAccessibilityEvent(AccessibilityEvent event);
344        public void onInterrupt();
345        public void onServiceConnected();
346        public void onSetConnectionId(int connectionId);
347        public boolean onGesture(int gestureId);
348    }
349
350    private int mConnectionId;
351
352    private AccessibilityServiceInfo mInfo;
353
354    /**
355     * Callback for {@link android.view.accessibility.AccessibilityEvent}s.
356     *
357     * @param event An event.
358     */
359    public abstract void onAccessibilityEvent(AccessibilityEvent event);
360
361    /**
362     * Callback for interrupting the accessibility feedback.
363     */
364    public abstract void onInterrupt();
365
366    /**
367     * This method is a part of the {@link AccessibilityService} lifecycle and is
368     * called after the system has successfully bound to the service. If is
369     * convenient to use this method for setting the {@link AccessibilityServiceInfo}.
370     *
371     * @see AccessibilityServiceInfo
372     * @see #setServiceInfo(AccessibilityServiceInfo)
373     */
374    protected void onServiceConnected() {
375
376    }
377
378    /**
379     * Called by the system when the user performs a specific gesture on the
380     * touch screen. If the gesture is not handled in this callback the system
381     * may provide default handing. Therefore, one should return true from this
382     * function if overriding of default behavior is desired.
383     *
384     * <strong>Note:</strong> To receive gestures an accessibility service
385     *         must declare that it can handle such by specifying the
386     *         <code>&lt;{@link android.R.styleable#AccessibilityService_canHandleGestures
387     *         canHandleGestures}&gt;</code> attribute.
388     *
389     * @param gestureId The unique id of the performed gesture.
390     *
391     * @return Whether the gesture was handled.
392     *
393     * @see #GESTURE_SWIPE_UP
394     * @see #GESTURE_SWIPE_UP_AND_LEFT
395     * @see #GESTURE_SWIPE_UP_AND_DOWN
396     * @see #GESTURE_SWIPE_UP_AND_RIGHT
397     * @see #GESTURE_SWIPE_DOWN
398     * @see #GESTURE_SWIPE_DOWN_AND_LEFT
399     * @see #GESTURE_SWIPE_DOWN_AND_UP
400     * @see #GESTURE_SWIPE_DOWN_AND_RIGHT
401     * @see #GESTURE_SWIPE_LEFT
402     * @see #GESTURE_SWIPE_LEFT_AND_UP
403     * @see #GESTURE_SWIPE_LEFT_AND_RIGHT
404     * @see #GESTURE_SWIPE_LEFT_AND_DOWN
405     * @see #GESTURE_SWIPE_RIGHT
406     * @see #GESTURE_SWIPE_RIGHT_AND_UP
407     * @see #GESTURE_SWIPE_RIGHT_AND_LEFT
408     * @see #GESTURE_SWIPE_RIGHT_AND_DOWN
409     * @see #GESTURE_CLOCKWISE_CIRCLE
410     * @see #GESTURE_COUNTER_CLOCKWISE_CIRCLE
411     * @see #GESTURE_DOUBLE_TAP
412     * @see #GESTURE_TAP_AND_HOLD
413     */
414    protected boolean onGesture(int gestureId) {
415        // TODO: Describe the default gesture processing in the javaDoc once it is finalized.
416        return false;
417    }
418
419    /**
420     * Gets the root node in the currently active window if this service
421     * can retrieve window content.
422     *
423     * @return The root node if this service can retrieve window content.
424     */
425    public AccessibilityNodeInfo getRootInActiveWindow() {
426        return AccessibilityInteractionClient.getInstance().getRootInActiveWindow(mConnectionId);
427    }
428
429    /**
430     * Performs a global action. Such an action can be performed
431     * at any moment regardless of the current application or user
432     * location in that application. For example going back, going
433     * home, opening recents, etc.
434     *
435     * @param action The action to perform.
436     * @return Whether the action was successfully performed.
437     *
438     * @see #GLOBAL_ACTION_BACK
439     * @see #GLOBAL_ACTION_HOME
440     * @see #GLOBAL_ACTION_NOTIFICATIONS
441     * @see #GLOBAL_ACTION_RECENTS
442     */
443    public final boolean performGlobalAction(int action) {
444        IAccessibilityServiceConnection connection =
445            AccessibilityInteractionClient.getInstance().getConnection(mConnectionId);
446        if (connection != null) {
447            try {
448                return connection.performGlobalAction(action);
449            } catch (RemoteException re) {
450                Log.w(LOG_TAG, "Error while calling performGlobalAction", re);
451            }
452        }
453        return false;
454    }
455
456    /**
457     * Gets the an {@link AccessibilityServiceInfo} describing this
458     * {@link AccessibilityService}. This method is useful if one wants
459     * to change some of the dynamically configurable properties at
460     * runtime.
461     *
462     * @return The accessibility service info.
463     *
464     * @see AccessibilityNodeInfo
465     */
466    public final AccessibilityServiceInfo getServiceInfo() {
467        IAccessibilityServiceConnection connection =
468            AccessibilityInteractionClient.getInstance().getConnection(mConnectionId);
469        if (connection != null) {
470            try {
471                return connection.getServiceInfo();
472            } catch (RemoteException re) {
473                Log.w(LOG_TAG, "Error while getting AccessibilityServiceInfo", re);
474            }
475        }
476        return null;
477    }
478
479    /**
480     * Sets the {@link AccessibilityServiceInfo} that describes this service.
481     * <p>
482     * Note: You can call this method any time but the info will be picked up after
483     *       the system has bound to this service and when this method is called thereafter.
484     *
485     * @param info The info.
486     */
487    public final void setServiceInfo(AccessibilityServiceInfo info) {
488        mInfo = info;
489        sendServiceInfo();
490    }
491
492    /**
493     * Sets the {@link AccessibilityServiceInfo} for this service if the latter is
494     * properly set and there is an {@link IAccessibilityServiceConnection} to the
495     * AccessibilityManagerService.
496     */
497    private void sendServiceInfo() {
498        IAccessibilityServiceConnection connection =
499            AccessibilityInteractionClient.getInstance().getConnection(mConnectionId);
500        if (mInfo != null && connection != null) {
501            try {
502                connection.setServiceInfo(mInfo);
503                mInfo = null;
504                AccessibilityInteractionClient.getInstance().clearCache();
505            } catch (RemoteException re) {
506                Log.w(LOG_TAG, "Error while setting AccessibilityServiceInfo", re);
507            }
508        }
509    }
510
511    /**
512     * Implement to return the implementation of the internal accessibility
513     * service interface.
514     */
515    @Override
516    public final IBinder onBind(Intent intent) {
517        return new IAccessibilityServiceClientWrapper(this, getMainLooper(), new Callbacks() {
518            @Override
519            public void onServiceConnected() {
520                AccessibilityService.this.onServiceConnected();
521            }
522
523            @Override
524            public void onInterrupt() {
525                AccessibilityService.this.onInterrupt();
526            }
527
528            @Override
529            public void onAccessibilityEvent(AccessibilityEvent event) {
530                AccessibilityService.this.onAccessibilityEvent(event);
531            }
532
533            @Override
534            public void onSetConnectionId( int connectionId) {
535                mConnectionId = connectionId;
536            }
537
538            @Override
539            public boolean onGesture(int gestureId) {
540                return AccessibilityService.this.onGesture(gestureId);
541            }
542        });
543    }
544
545    /**
546     * Implements the internal {@link IAccessibilityServiceClient} interface to convert
547     * incoming calls to it back to calls on an {@link AccessibilityService}.
548     */
549    static class IAccessibilityServiceClientWrapper extends IAccessibilityServiceClient.Stub
550            implements HandlerCaller.Callback {
551
552        static final int NO_ID = -1;
553
554        private static final int DO_SET_SET_CONNECTION = 10;
555        private static final int DO_ON_INTERRUPT = 20;
556        private static final int DO_ON_ACCESSIBILITY_EVENT = 30;
557        private static final int DO_ON_GESTURE = 40;
558
559        private final HandlerCaller mCaller;
560
561        private final Callbacks mCallback;
562
563        public IAccessibilityServiceClientWrapper(Context context, Looper looper,
564                Callbacks callback) {
565            mCallback = callback;
566            mCaller = new HandlerCaller(context, looper, this);
567        }
568
569        public void setConnection(IAccessibilityServiceConnection connection, int connectionId) {
570            Message message = mCaller.obtainMessageIO(DO_SET_SET_CONNECTION, connectionId,
571                    connection);
572            mCaller.sendMessage(message);
573        }
574
575        public void onInterrupt() {
576            Message message = mCaller.obtainMessage(DO_ON_INTERRUPT);
577            mCaller.sendMessage(message);
578        }
579
580        public void onAccessibilityEvent(AccessibilityEvent event) {
581            Message message = mCaller.obtainMessageO(DO_ON_ACCESSIBILITY_EVENT, event);
582            mCaller.sendMessage(message);
583        }
584
585        public void onGesture(int gestureId, IAccessibilityServiceClientCallback callback,
586                int interactionId) {
587            Message message = mCaller.obtainMessageIIO(DO_ON_GESTURE, gestureId, interactionId,
588                    callback);
589            mCaller.sendMessage(message);
590        }
591
592        public void executeMessage(Message message) {
593            switch (message.what) {
594                case DO_ON_ACCESSIBILITY_EVENT :
595                    AccessibilityEvent event = (AccessibilityEvent) message.obj;
596                    if (event != null) {
597                        AccessibilityInteractionClient.getInstance().onAccessibilityEvent(event);
598                        mCallback.onAccessibilityEvent(event);
599                        event.recycle();
600                    }
601                    return;
602                case DO_ON_INTERRUPT :
603                    mCallback.onInterrupt();
604                    return;
605                case DO_SET_SET_CONNECTION :
606                    final int connectionId = message.arg1;
607                    IAccessibilityServiceConnection connection =
608                        (IAccessibilityServiceConnection) message.obj;
609                    if (connection != null) {
610                        AccessibilityInteractionClient.getInstance().addConnection(connectionId,
611                                connection);
612                        mCallback.onSetConnectionId(connectionId);
613                        mCallback.onServiceConnected();
614                    } else {
615                        AccessibilityInteractionClient.getInstance().removeConnection(connectionId);
616                        mCallback.onSetConnectionId(AccessibilityInteractionClient.NO_ID);
617                    }
618                    return;
619                case DO_ON_GESTURE :
620                    final int gestureId = message.arg1;
621                    final int interactionId = message.arg2;
622                    IAccessibilityServiceClientCallback callback =
623                        (IAccessibilityServiceClientCallback) message.obj;
624                    final boolean handled = mCallback.onGesture(gestureId);
625                    try {
626                        callback.setGestureResult(gestureId, handled, interactionId);
627                    } catch (RemoteException re) {
628                        Log.e(LOG_TAG, "Error calling back with the gesture resut.", re);
629                    }
630                    return;
631                default :
632                    Log.w(LOG_TAG, "Unknown message type " + message.what);
633            }
634        }
635    }
636}
637