blob: 879e58f494c0e9192a9da0b3ff482e34ff53d06b [file] [log] [blame]
svetoslavganov75986cf2009-05-14 22:28:01 -07001/*
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.view.accessibility;
18
Svetoslav6b25e722013-02-28 16:55:54 -080019import android.Manifest;
Svetoslav Ganov736c2752011-04-22 18:30:36 -070020import android.accessibilityservice.AccessibilityServiceInfo;
svetoslavganov75986cf2009-05-14 22:28:01 -070021import android.content.Context;
Svetoslav6b25e722013-02-28 16:55:54 -080022import android.content.pm.PackageManager;
svetoslavganov75986cf2009-05-14 22:28:01 -070023import android.content.pm.ServiceInfo;
24import android.os.Binder;
25import android.os.Handler;
26import android.os.IBinder;
27import android.os.Looper;
28import android.os.Message;
Svetoslav6b25e722013-02-28 16:55:54 -080029import android.os.Process;
svetoslavganov75986cf2009-05-14 22:28:01 -070030import android.os.RemoteException;
31import android.os.ServiceManager;
32import android.os.SystemClock;
Svetoslav Ganov58d37b52012-09-18 12:04:19 -070033import android.os.UserHandle;
svetoslavganov75986cf2009-05-14 22:28:01 -070034import android.util.Log;
Svetoslav Ganov8643aa02011-04-20 12:12:33 -070035import android.view.IWindow;
36import android.view.View;
svetoslavganov75986cf2009-05-14 22:28:01 -070037
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -070038import java.util.ArrayList;
svetoslavganov75986cf2009-05-14 22:28:01 -070039import java.util.Collections;
40import java.util.List;
Svetoslav Ganov8643aa02011-04-20 12:12:33 -070041import java.util.concurrent.CopyOnWriteArrayList;
svetoslavganov75986cf2009-05-14 22:28:01 -070042
43/**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070044 * System level service that serves as an event dispatch for {@link AccessibilityEvent}s,
45 * and provides facilities for querying the accessibility state of the system.
46 * Accessibility events are generated when something notable happens in the user interface,
svetoslavganov75986cf2009-05-14 22:28:01 -070047 * for example an {@link android.app.Activity} starts, the focus or selection of a
48 * {@link android.view.View} changes etc. Parties interested in handling accessibility
49 * events implement and register an accessibility service which extends
50 * {@link android.accessibilityservice.AccessibilityService}.
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070051 * <p>
52 * To obtain a handle to the accessibility manager do the following:
53 * </p>
54 * <p>
55 * <code>
Scott Mainb303d832011-10-12 16:45:18 -070056 * <pre>AccessibilityManager accessibilityManager =
57 * (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);</pre>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070058 * </code>
59 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -070060 *
61 * @see AccessibilityEvent
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070062 * @see AccessibilityNodeInfo
svetoslavganov75986cf2009-05-14 22:28:01 -070063 * @see android.accessibilityservice.AccessibilityService
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070064 * @see Context#getSystemService
65 * @see Context#ACCESSIBILITY_SERVICE
svetoslavganov75986cf2009-05-14 22:28:01 -070066 */
67public final class AccessibilityManager {
Svetoslav Ganov736c2752011-04-22 18:30:36 -070068 private static final boolean DEBUG = false;
69
svetoslavganov75986cf2009-05-14 22:28:01 -070070 private static final String LOG_TAG = "AccessibilityManager";
71
Svetoslav Ganov00aabf72011-07-21 11:35:03 -070072 /** @hide */
73 public static final int STATE_FLAG_ACCESSIBILITY_ENABLED = 0x00000001;
74
75 /** @hide */
76 public static final int STATE_FLAG_TOUCH_EXPLORATION_ENABLED = 0x00000002;
77
svetoslavganov75986cf2009-05-14 22:28:01 -070078 static final Object sInstanceSync = new Object();
79
80 private static AccessibilityManager sInstance;
81
Svetoslav Ganov00aabf72011-07-21 11:35:03 -070082 private static final int DO_SET_STATE = 10;
svetoslavganov75986cf2009-05-14 22:28:01 -070083
84 final IAccessibilityManager mService;
85
Svetoslav Ganov58d37b52012-09-18 12:04:19 -070086 final int mUserId;
87
svetoslavganov75986cf2009-05-14 22:28:01 -070088 final Handler mHandler;
89
90 boolean mIsEnabled;
91
Svetoslav Ganov35bfede2011-07-14 17:57:06 -070092 boolean mIsTouchExplorationEnabled;
93
Alan Viverette5baeb9a2013-10-09 14:42:05 -070094 private final CopyOnWriteArrayList<AccessibilityStateChangeListener>
95 mAccessibilityStateChangeListeners = new CopyOnWriteArrayList<
96 AccessibilityStateChangeListener>();
97
98 private final CopyOnWriteArrayList<TouchExplorationStateChangeListener>
99 mTouchExplorationStateChangeListeners = new CopyOnWriteArrayList<
100 TouchExplorationStateChangeListener>();
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700101
102 /**
Alan Viverette5baeb9a2013-10-09 14:42:05 -0700103 * Listener for the system accessibility state. To listen for changes to the
104 * accessibility state on the device, implement this interface and register
105 * it with the system by calling {@link #addAccessibilityStateChangeListener}.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700106 */
107 public interface AccessibilityStateChangeListener {
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700108
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700109 /**
Alan Viverette5baeb9a2013-10-09 14:42:05 -0700110 * Called when the accessibility enabled state changes.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700111 *
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700112 * @param enabled Whether accessibility is enabled.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700113 */
114 public void onAccessibilityStateChanged(boolean enabled);
115 }
116
Alan Viverette5baeb9a2013-10-09 14:42:05 -0700117 /**
118 * Listener for the system touch exploration state. To listen for changes to
119 * the touch exploration state on the device, implement this interface and
120 * register it with the system by calling
121 * {@link #addTouchExplorationStateChangeListener}.
122 */
123 public interface TouchExplorationStateChangeListener {
124
125 /**
126 * Called when the touch exploration enabled state changes.
127 *
128 * @param enabled Whether touch exploration is enabled.
129 */
130 public void onTouchExplorationStateChanged(boolean enabled);
131 }
132
svetoslavganov75986cf2009-05-14 22:28:01 -0700133 final IAccessibilityManagerClient.Stub mClient = new IAccessibilityManagerClient.Stub() {
Svetoslav Ganov00aabf72011-07-21 11:35:03 -0700134 public void setState(int state) {
135 mHandler.obtainMessage(DO_SET_STATE, state, 0).sendToTarget();
svetoslavganov75986cf2009-05-14 22:28:01 -0700136 }
137 };
138
139 class MyHandler extends Handler {
140
141 MyHandler(Looper mainLooper) {
142 super(mainLooper);
143 }
144
145 @Override
146 public void handleMessage(Message message) {
147 switch (message.what) {
Svetoslav Ganov00aabf72011-07-21 11:35:03 -0700148 case DO_SET_STATE :
149 setState(message.arg1);
svetoslavganov75986cf2009-05-14 22:28:01 -0700150 return;
151 default :
152 Log.w(LOG_TAG, "Unknown message type: " + message.what);
153 }
154 }
155 }
156
157 /**
158 * Get an AccessibilityManager instance (create one if necessary).
159 *
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700160 * @param context Context in which this manager operates.
161 *
svetoslavganov75986cf2009-05-14 22:28:01 -0700162 * @hide
163 */
164 public static AccessibilityManager getInstance(Context context) {
165 synchronized (sInstanceSync) {
166 if (sInstance == null) {
Svetoslav6b25e722013-02-28 16:55:54 -0800167 final int userId;
168 if (Binder.getCallingUid() == Process.SYSTEM_UID
169 || context.checkCallingOrSelfPermission(
170 Manifest.permission.INTERACT_ACROSS_USERS)
171 == PackageManager.PERMISSION_GRANTED
172 || context.checkCallingOrSelfPermission(
173 Manifest.permission.INTERACT_ACROSS_USERS_FULL)
174 == PackageManager.PERMISSION_GRANTED) {
175 userId = UserHandle.USER_CURRENT;
176 } else {
177 userId = UserHandle.myUserId();
178 }
179 IBinder iBinder = ServiceManager.getService(Context.ACCESSIBILITY_SERVICE);
Amith Yamasani91588252013-11-22 08:25:26 -0800180 IAccessibilityManager service = iBinder == null
181 ? null : IAccessibilityManager.Stub.asInterface(iBinder);
Svetoslav6b25e722013-02-28 16:55:54 -0800182 sInstance = new AccessibilityManager(context, service, userId);
svetoslavganov75986cf2009-05-14 22:28:01 -0700183 }
184 }
185 return sInstance;
186 }
187
188 /**
189 * Create an instance.
190 *
191 * @param context A {@link Context}.
Svetoslav Ganovaf7adab2010-04-16 18:07:48 -0700192 * @param service An interface to the backing service.
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700193 * @param userId User id under which to run.
Svetoslav Ganovaf7adab2010-04-16 18:07:48 -0700194 *
195 * @hide
svetoslavganov75986cf2009-05-14 22:28:01 -0700196 */
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700197 public AccessibilityManager(Context context, IAccessibilityManager service, int userId) {
svetoslavganov75986cf2009-05-14 22:28:01 -0700198 mHandler = new MyHandler(context.getMainLooper());
Svetoslav Ganovaf7adab2010-04-16 18:07:48 -0700199 mService = service;
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700200 mUserId = userId;
Amith Yamasani91588252013-11-22 08:25:26 -0800201 if (mService == null) {
202 mIsEnabled = false;
203 }
svetoslavganov75986cf2009-05-14 22:28:01 -0700204 try {
Amith Yamasani91588252013-11-22 08:25:26 -0800205 if (mService != null) {
206 final int stateFlags = mService.addClient(mClient, userId);
207 setState(stateFlags);
208 }
svetoslavganov75986cf2009-05-14 22:28:01 -0700209 } catch (RemoteException re) {
210 Log.e(LOG_TAG, "AccessibilityManagerService is dead", re);
211 }
212 }
213
214 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700215 * Returns if the accessibility in the system is enabled.
svetoslavganov75986cf2009-05-14 22:28:01 -0700216 *
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700217 * @return True if accessibility is enabled, false otherwise.
svetoslavganov75986cf2009-05-14 22:28:01 -0700218 */
219 public boolean isEnabled() {
220 synchronized (mHandler) {
221 return mIsEnabled;
222 }
223 }
224
225 /**
Svetoslav Ganov35bfede2011-07-14 17:57:06 -0700226 * Returns if the touch exploration in the system is enabled.
227 *
228 * @return True if touch exploration is enabled, false otherwise.
229 */
230 public boolean isTouchExplorationEnabled() {
231 synchronized (mHandler) {
232 return mIsTouchExplorationEnabled;
233 }
234 }
235
236 /**
Svetoslav Ganovaf7adab2010-04-16 18:07:48 -0700237 * Returns the client interface this instance registers in
238 * the centralized accessibility manager service.
239 *
240 * @return The client.
241 *
242 * @hide
243 */
244 public IAccessibilityManagerClient getClient() {
Jim Miller4dfecf52011-06-30 15:45:35 -0700245 return (IAccessibilityManagerClient) mClient.asBinder();
Svetoslav Ganovaf7adab2010-04-16 18:07:48 -0700246 }
247
248 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700249 * Sends an {@link AccessibilityEvent}.
svetoslavganov75986cf2009-05-14 22:28:01 -0700250 *
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700251 * @param event The event to send.
svetoslavganov75986cf2009-05-14 22:28:01 -0700252 *
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700253 * @throws IllegalStateException if accessibility is not enabled.
Svetoslav Ganov42138042012-03-20 11:51:39 -0700254 *
255 * <strong>Note:</strong> The preferred mechanism for sending custom accessibility
256 * events is through calling
257 * {@link android.view.ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)}
258 * instead of this method to allow predecessors to augment/filter events sent by
259 * their descendants.
svetoslavganov75986cf2009-05-14 22:28:01 -0700260 */
261 public void sendAccessibilityEvent(AccessibilityEvent event) {
262 if (!mIsEnabled) {
263 throw new IllegalStateException("Accessibility off. Did you forget to check that?");
264 }
265 boolean doRecycle = false;
266 try {
267 event.setEventTime(SystemClock.uptimeMillis());
268 // it is possible that this manager is in the same process as the service but
269 // client using it is called through Binder from another process. Example: MMS
270 // app adds a SMS notification and the NotificationManagerService calls this method
271 long identityToken = Binder.clearCallingIdentity();
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700272 doRecycle = mService.sendAccessibilityEvent(event, mUserId);
svetoslavganov75986cf2009-05-14 22:28:01 -0700273 Binder.restoreCallingIdentity(identityToken);
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700274 if (DEBUG) {
svetoslavganov75986cf2009-05-14 22:28:01 -0700275 Log.i(LOG_TAG, event + " sent");
276 }
277 } catch (RemoteException re) {
278 Log.e(LOG_TAG, "Error during sending " + event + " ", re);
279 } finally {
280 if (doRecycle) {
281 event.recycle();
282 }
283 }
284 }
285
286 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700287 * Requests feedback interruption from all accessibility services.
svetoslavganov75986cf2009-05-14 22:28:01 -0700288 */
289 public void interrupt() {
290 if (!mIsEnabled) {
291 throw new IllegalStateException("Accessibility off. Did you forget to check that?");
292 }
293 try {
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700294 mService.interrupt(mUserId);
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700295 if (DEBUG) {
svetoslavganov75986cf2009-05-14 22:28:01 -0700296 Log.i(LOG_TAG, "Requested interrupt from all services");
297 }
298 } catch (RemoteException re) {
299 Log.e(LOG_TAG, "Error while requesting interrupt from all services. ", re);
300 }
301 }
302
303 /**
304 * Returns the {@link ServiceInfo}s of the installed accessibility services.
305 *
306 * @return An unmodifiable list with {@link ServiceInfo}s.
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -0700307 *
308 * @deprecated Use {@link #getInstalledAccessibilityServiceList()}
svetoslavganov75986cf2009-05-14 22:28:01 -0700309 */
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -0700310 @Deprecated
svetoslavganov75986cf2009-05-14 22:28:01 -0700311 public List<ServiceInfo> getAccessibilityServiceList() {
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -0700312 List<AccessibilityServiceInfo> infos = getInstalledAccessibilityServiceList();
313 List<ServiceInfo> services = new ArrayList<ServiceInfo>();
314 final int infoCount = infos.size();
315 for (int i = 0; i < infoCount; i++) {
316 AccessibilityServiceInfo info = infos.get(i);
317 services.add(info.getResolveInfo().serviceInfo);
318 }
319 return Collections.unmodifiableList(services);
320 }
321
322 /**
323 * Returns the {@link AccessibilityServiceInfo}s of the installed accessibility services.
324 *
325 * @return An unmodifiable list with {@link AccessibilityServiceInfo}s.
326 */
327 public List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList() {
328 List<AccessibilityServiceInfo> services = null;
svetoslavganov75986cf2009-05-14 22:28:01 -0700329 try {
Amith Yamasani91588252013-11-22 08:25:26 -0800330 if (mService != null) {
331 services = mService.getInstalledAccessibilityServiceList(mUserId);
332 if (DEBUG) {
333 Log.i(LOG_TAG, "Installed AccessibilityServices " + services);
334 }
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700335 }
336 } catch (RemoteException re) {
337 Log.e(LOG_TAG, "Error while obtaining the installed AccessibilityServices. ", re);
338 }
Amith Yamasani91588252013-11-22 08:25:26 -0800339 return services != null ? Collections.unmodifiableList(services) : Collections.EMPTY_LIST;
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700340 }
341
342 /**
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -0700343 * Returns the {@link AccessibilityServiceInfo}s of the enabled accessibility services
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700344 * for a given feedback type.
345 *
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700346 * @param feedbackTypeFlags The feedback type flags.
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -0700347 * @return An unmodifiable list with {@link AccessibilityServiceInfo}s.
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700348 *
349 * @see AccessibilityServiceInfo#FEEDBACK_AUDIBLE
350 * @see AccessibilityServiceInfo#FEEDBACK_GENERIC
351 * @see AccessibilityServiceInfo#FEEDBACK_HAPTIC
352 * @see AccessibilityServiceInfo#FEEDBACK_SPOKEN
353 * @see AccessibilityServiceInfo#FEEDBACK_VISUAL
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700354 */
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700355 public List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList(
356 int feedbackTypeFlags) {
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -0700357 List<AccessibilityServiceInfo> services = null;
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700358 try {
Amith Yamasani91588252013-11-22 08:25:26 -0800359 if (mService != null) {
360 services = mService.getEnabledAccessibilityServiceList(feedbackTypeFlags, mUserId);
361 if (DEBUG) {
362 Log.i(LOG_TAG, "Installed AccessibilityServices " + services);
363 }
svetoslavganov75986cf2009-05-14 22:28:01 -0700364 }
365 } catch (RemoteException re) {
366 Log.e(LOG_TAG, "Error while obtaining the installed AccessibilityServices. ", re);
367 }
Amith Yamasani91588252013-11-22 08:25:26 -0800368 return services != null ? Collections.unmodifiableList(services) : Collections.EMPTY_LIST;
svetoslavganov75986cf2009-05-14 22:28:01 -0700369 }
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700370
371 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700372 * Registers an {@link AccessibilityStateChangeListener} for changes in
373 * the global accessibility state of the system.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700374 *
375 * @param listener The listener.
376 * @return True if successfully registered.
377 */
378 public boolean addAccessibilityStateChangeListener(
379 AccessibilityStateChangeListener listener) {
380 return mAccessibilityStateChangeListeners.add(listener);
381 }
382
383 /**
384 * Unregisters an {@link AccessibilityStateChangeListener}.
385 *
386 * @param listener The listener.
387 * @return True if successfully unregistered.
388 */
389 public boolean removeAccessibilityStateChangeListener(
390 AccessibilityStateChangeListener listener) {
391 return mAccessibilityStateChangeListeners.remove(listener);
392 }
393
394 /**
Alan Viverette5baeb9a2013-10-09 14:42:05 -0700395 * Registers a {@link TouchExplorationStateChangeListener} for changes in
396 * the global touch exploration state of the system.
397 *
398 * @param listener The listener.
399 * @return True if successfully registered.
400 */
401 public boolean addTouchExplorationStateChangeListener(
402 TouchExplorationStateChangeListener listener) {
403 return mTouchExplorationStateChangeListeners.add(listener);
404 }
405
406 /**
407 * Unregisters a {@link TouchExplorationStateChangeListener}.
408 *
409 * @param listener The listener.
410 * @return True if successfully unregistered.
411 */
412 public boolean removeTouchExplorationStateChangeListener(
413 TouchExplorationStateChangeListener listener) {
414 return mTouchExplorationStateChangeListeners.remove(listener);
415 }
416
417 /**
418 * Sets the current state and notifies listeners, if necessary.
Svetoslav Ganov00aabf72011-07-21 11:35:03 -0700419 *
420 * @param stateFlags The state flags.
421 */
422 private void setState(int stateFlags) {
Alan Viverette5baeb9a2013-10-09 14:42:05 -0700423 final boolean enabled = (stateFlags & STATE_FLAG_ACCESSIBILITY_ENABLED) != 0;
424 final boolean touchExplorationEnabled =
425 (stateFlags & STATE_FLAG_TOUCH_EXPLORATION_ENABLED) != 0;
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700426 synchronized (mHandler) {
Alan Viverette7e361d22013-10-09 17:20:43 -0700427 final boolean wasEnabled = mIsEnabled;
428 final boolean wasTouchExplorationEnabled = mIsTouchExplorationEnabled;
429
430 // Ensure listeners get current state from isZzzEnabled() calls.
Alan Viverette5baeb9a2013-10-09 14:42:05 -0700431 mIsEnabled = enabled;
432 mIsTouchExplorationEnabled = touchExplorationEnabled;
433
Alan Viverette7e361d22013-10-09 17:20:43 -0700434 if (wasEnabled != enabled) {
Alan Viverette5baeb9a2013-10-09 14:42:05 -0700435 notifyAccessibilityStateChangedLh();
436 }
437
Alan Viverette7e361d22013-10-09 17:20:43 -0700438 if (wasTouchExplorationEnabled != touchExplorationEnabled) {
Alan Viverette5baeb9a2013-10-09 14:42:05 -0700439 notifyTouchExplorationStateChangedLh();
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700440 }
441 }
442 }
443
444 /**
445 * Notifies the registered {@link AccessibilityStateChangeListener}s.
Alan Viverette5baeb9a2013-10-09 14:42:05 -0700446 * <p>
447 * The caller must be locked on {@link #mHandler}.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700448 */
Alan Viverette5baeb9a2013-10-09 14:42:05 -0700449 private void notifyAccessibilityStateChangedLh() {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700450 final int listenerCount = mAccessibilityStateChangeListeners.size();
451 for (int i = 0; i < listenerCount; i++) {
452 mAccessibilityStateChangeListeners.get(i).onAccessibilityStateChanged(mIsEnabled);
453 }
454 }
455
456 /**
Alan Viverette5baeb9a2013-10-09 14:42:05 -0700457 * Notifies the registered {@link TouchExplorationStateChangeListener}s.
458 * <p>
459 * The caller must be locked on {@link #mHandler}.
460 */
461 private void notifyTouchExplorationStateChangedLh() {
462 final int listenerCount = mTouchExplorationStateChangeListeners.size();
463 for (int i = 0; i < listenerCount; i++) {
464 mTouchExplorationStateChangeListeners.get(i)
465 .onTouchExplorationStateChanged(mIsTouchExplorationEnabled);
466 }
467 }
468
469 /**
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700470 * Adds an accessibility interaction connection interface for a given window.
471 * @param windowToken The window token to which a connection is added.
472 * @param connection The connection.
473 *
474 * @hide
475 */
476 public int addAccessibilityInteractionConnection(IWindow windowToken,
477 IAccessibilityInteractionConnection connection) {
Amith Yamasani91588252013-11-22 08:25:26 -0800478 if (mService == null) {
479 return View.NO_ID;
480 }
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700481 try {
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700482 return mService.addAccessibilityInteractionConnection(windowToken, connection, mUserId);
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700483 } catch (RemoteException re) {
484 Log.e(LOG_TAG, "Error while adding an accessibility interaction connection. ", re);
485 }
486 return View.NO_ID;
487 }
488
489 /**
490 * Removed an accessibility interaction connection interface for a given window.
491 * @param windowToken The window token to which a connection is removed.
492 *
493 * @hide
494 */
495 public void removeAccessibilityInteractionConnection(IWindow windowToken) {
496 try {
Amith Yamasani91588252013-11-22 08:25:26 -0800497 if (mService != null) {
498 mService.removeAccessibilityInteractionConnection(windowToken);
499 }
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700500 } catch (RemoteException re) {
501 Log.e(LOG_TAG, "Error while removing an accessibility interaction connection. ", re);
502 }
503 }
svetoslavganov75986cf2009-05-14 22:28:01 -0700504}