svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 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 | |
| 17 | package android.view.accessibility; |
| 18 | |
Svetoslav | 6b25e72 | 2013-02-28 16:55:54 -0800 | [diff] [blame] | 19 | import android.Manifest; |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 20 | import android.accessibilityservice.AccessibilityServiceInfo; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 21 | import android.content.Context; |
Svetoslav | 6b25e72 | 2013-02-28 16:55:54 -0800 | [diff] [blame] | 22 | import android.content.pm.PackageManager; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 23 | import android.content.pm.ServiceInfo; |
| 24 | import android.os.Binder; |
| 25 | import android.os.Handler; |
| 26 | import android.os.IBinder; |
| 27 | import android.os.Looper; |
| 28 | import android.os.Message; |
Svetoslav | 6b25e72 | 2013-02-28 16:55:54 -0800 | [diff] [blame] | 29 | import android.os.Process; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 30 | import android.os.RemoteException; |
| 31 | import android.os.ServiceManager; |
| 32 | import android.os.SystemClock; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 33 | import android.os.UserHandle; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 34 | import android.util.Log; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 35 | import android.view.IWindow; |
| 36 | import android.view.View; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 37 | |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 38 | import java.util.ArrayList; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 39 | import java.util.Collections; |
| 40 | import java.util.List; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 41 | import java.util.concurrent.CopyOnWriteArrayList; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 44 | * 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, |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 47 | * 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 Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 51 | * <p> |
| 52 | * To obtain a handle to the accessibility manager do the following: |
| 53 | * </p> |
| 54 | * <p> |
| 55 | * <code> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 56 | * <pre>AccessibilityManager accessibilityManager = |
| 57 | * (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);</pre> |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 58 | * </code> |
| 59 | * </p> |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 60 | * |
| 61 | * @see AccessibilityEvent |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 62 | * @see AccessibilityNodeInfo |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 63 | * @see android.accessibilityservice.AccessibilityService |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 64 | * @see Context#getSystemService |
| 65 | * @see Context#ACCESSIBILITY_SERVICE |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 66 | */ |
| 67 | public final class AccessibilityManager { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 68 | private static final boolean DEBUG = false; |
| 69 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 70 | private static final String LOG_TAG = "AccessibilityManager"; |
| 71 | |
Svetoslav Ganov | 00aabf7 | 2011-07-21 11:35:03 -0700 | [diff] [blame] | 72 | /** @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 | |
Alan Viverette | 410d4e3 | 2013-09-30 15:37:38 -0700 | [diff] [blame] | 78 | /** @hide */ |
| 79 | public static final int INVERSION_DISABLED = -1; |
| 80 | |
| 81 | /** @hide */ |
| 82 | public static final int INVERSION_STANDARD = 0; |
| 83 | |
| 84 | /** @hide */ |
| 85 | public static final int INVERSION_HUE_ONLY = 1; |
| 86 | |
| 87 | /** @hide */ |
| 88 | public static final int INVERSION_VALUE_ONLY = 2; |
| 89 | |
| 90 | /** @hide */ |
| 91 | public static final int DALTONIZER_DISABLED = -1; |
| 92 | |
| 93 | /** @hide */ |
| 94 | public static final int DALTONIZER_SIMULATE_MONOCHROMACY = 0; |
| 95 | |
| 96 | /** @hide */ |
| 97 | public static final int DALTONIZER_SIMULATE_PROTANOMALY = 1; |
| 98 | |
| 99 | /** @hide */ |
| 100 | public static final int DALTONIZER_SIMULATE_DEUTERANOMALY = 2; |
| 101 | |
| 102 | /** @hide */ |
| 103 | public static final int DALTONIZER_SIMULATE_TRITANOMALY = 3; |
| 104 | |
| 105 | /** @hide */ |
| 106 | public static final int DALTONIZER_CORRECT_PROTANOMALY = 11; |
| 107 | |
| 108 | /** @hide */ |
| 109 | public static final int DALTONIZER_CORRECT_DEUTERANOMALY = 12; |
| 110 | |
| 111 | /** @hide */ |
| 112 | public static final int DALTONIZER_CORRECT_TRITANOMALY = 13; |
| 113 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 114 | static final Object sInstanceSync = new Object(); |
| 115 | |
| 116 | private static AccessibilityManager sInstance; |
| 117 | |
Svetoslav Ganov | 00aabf7 | 2011-07-21 11:35:03 -0700 | [diff] [blame] | 118 | private static final int DO_SET_STATE = 10; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 119 | |
| 120 | final IAccessibilityManager mService; |
| 121 | |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 122 | final int mUserId; |
| 123 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 124 | final Handler mHandler; |
| 125 | |
| 126 | boolean mIsEnabled; |
| 127 | |
Svetoslav Ganov | 35bfede | 2011-07-14 17:57:06 -0700 | [diff] [blame] | 128 | boolean mIsTouchExplorationEnabled; |
| 129 | |
Alan Viverette | 5baeb9a | 2013-10-09 14:42:05 -0700 | [diff] [blame] | 130 | private final CopyOnWriteArrayList<AccessibilityStateChangeListener> |
| 131 | mAccessibilityStateChangeListeners = new CopyOnWriteArrayList< |
| 132 | AccessibilityStateChangeListener>(); |
| 133 | |
| 134 | private final CopyOnWriteArrayList<TouchExplorationStateChangeListener> |
| 135 | mTouchExplorationStateChangeListeners = new CopyOnWriteArrayList< |
| 136 | TouchExplorationStateChangeListener>(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 137 | |
| 138 | /** |
Alan Viverette | 5baeb9a | 2013-10-09 14:42:05 -0700 | [diff] [blame] | 139 | * Listener for the system accessibility state. To listen for changes to the |
| 140 | * accessibility state on the device, implement this interface and register |
| 141 | * it with the system by calling {@link #addAccessibilityStateChangeListener}. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 142 | */ |
| 143 | public interface AccessibilityStateChangeListener { |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 144 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 145 | /** |
Alan Viverette | 5baeb9a | 2013-10-09 14:42:05 -0700 | [diff] [blame] | 146 | * Called when the accessibility enabled state changes. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 147 | * |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 148 | * @param enabled Whether accessibility is enabled. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 149 | */ |
| 150 | public void onAccessibilityStateChanged(boolean enabled); |
| 151 | } |
| 152 | |
Alan Viverette | 5baeb9a | 2013-10-09 14:42:05 -0700 | [diff] [blame] | 153 | /** |
| 154 | * Listener for the system touch exploration state. To listen for changes to |
| 155 | * the touch exploration state on the device, implement this interface and |
| 156 | * register it with the system by calling |
| 157 | * {@link #addTouchExplorationStateChangeListener}. |
| 158 | */ |
| 159 | public interface TouchExplorationStateChangeListener { |
| 160 | |
| 161 | /** |
| 162 | * Called when the touch exploration enabled state changes. |
| 163 | * |
| 164 | * @param enabled Whether touch exploration is enabled. |
| 165 | */ |
| 166 | public void onTouchExplorationStateChanged(boolean enabled); |
| 167 | } |
| 168 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 169 | final IAccessibilityManagerClient.Stub mClient = new IAccessibilityManagerClient.Stub() { |
Svetoslav Ganov | 00aabf7 | 2011-07-21 11:35:03 -0700 | [diff] [blame] | 170 | public void setState(int state) { |
| 171 | mHandler.obtainMessage(DO_SET_STATE, state, 0).sendToTarget(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 172 | } |
| 173 | }; |
| 174 | |
| 175 | class MyHandler extends Handler { |
| 176 | |
| 177 | MyHandler(Looper mainLooper) { |
| 178 | super(mainLooper); |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public void handleMessage(Message message) { |
| 183 | switch (message.what) { |
Svetoslav Ganov | 00aabf7 | 2011-07-21 11:35:03 -0700 | [diff] [blame] | 184 | case DO_SET_STATE : |
| 185 | setState(message.arg1); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 186 | return; |
| 187 | default : |
| 188 | Log.w(LOG_TAG, "Unknown message type: " + message.what); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Get an AccessibilityManager instance (create one if necessary). |
| 195 | * |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 196 | * @param context Context in which this manager operates. |
| 197 | * |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 198 | * @hide |
| 199 | */ |
| 200 | public static AccessibilityManager getInstance(Context context) { |
| 201 | synchronized (sInstanceSync) { |
| 202 | if (sInstance == null) { |
Svetoslav | 6b25e72 | 2013-02-28 16:55:54 -0800 | [diff] [blame] | 203 | final int userId; |
| 204 | if (Binder.getCallingUid() == Process.SYSTEM_UID |
| 205 | || context.checkCallingOrSelfPermission( |
| 206 | Manifest.permission.INTERACT_ACROSS_USERS) |
| 207 | == PackageManager.PERMISSION_GRANTED |
| 208 | || context.checkCallingOrSelfPermission( |
| 209 | Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
| 210 | == PackageManager.PERMISSION_GRANTED) { |
| 211 | userId = UserHandle.USER_CURRENT; |
| 212 | } else { |
| 213 | userId = UserHandle.myUserId(); |
| 214 | } |
| 215 | IBinder iBinder = ServiceManager.getService(Context.ACCESSIBILITY_SERVICE); |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 216 | IAccessibilityManager service = iBinder == null |
| 217 | ? null : IAccessibilityManager.Stub.asInterface(iBinder); |
Svetoslav | 6b25e72 | 2013-02-28 16:55:54 -0800 | [diff] [blame] | 218 | sInstance = new AccessibilityManager(context, service, userId); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | return sInstance; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Create an instance. |
| 226 | * |
| 227 | * @param context A {@link Context}. |
Svetoslav Ganov | af7adab | 2010-04-16 18:07:48 -0700 | [diff] [blame] | 228 | * @param service An interface to the backing service. |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 229 | * @param userId User id under which to run. |
Svetoslav Ganov | af7adab | 2010-04-16 18:07:48 -0700 | [diff] [blame] | 230 | * |
| 231 | * @hide |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 232 | */ |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 233 | public AccessibilityManager(Context context, IAccessibilityManager service, int userId) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 234 | mHandler = new MyHandler(context.getMainLooper()); |
Svetoslav Ganov | af7adab | 2010-04-16 18:07:48 -0700 | [diff] [blame] | 235 | mService = service; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 236 | mUserId = userId; |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 237 | if (mService == null) { |
| 238 | mIsEnabled = false; |
| 239 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 240 | try { |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 241 | if (mService != null) { |
| 242 | final int stateFlags = mService.addClient(mClient, userId); |
| 243 | setState(stateFlags); |
| 244 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 245 | } catch (RemoteException re) { |
| 246 | Log.e(LOG_TAG, "AccessibilityManagerService is dead", re); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | /** |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 251 | * Returns if the accessibility in the system is enabled. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 252 | * |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 253 | * @return True if accessibility is enabled, false otherwise. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 254 | */ |
| 255 | public boolean isEnabled() { |
| 256 | synchronized (mHandler) { |
| 257 | return mIsEnabled; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | /** |
Svetoslav Ganov | 35bfede | 2011-07-14 17:57:06 -0700 | [diff] [blame] | 262 | * Returns if the touch exploration in the system is enabled. |
| 263 | * |
| 264 | * @return True if touch exploration is enabled, false otherwise. |
| 265 | */ |
| 266 | public boolean isTouchExplorationEnabled() { |
| 267 | synchronized (mHandler) { |
| 268 | return mIsTouchExplorationEnabled; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | /** |
Svetoslav Ganov | af7adab | 2010-04-16 18:07:48 -0700 | [diff] [blame] | 273 | * Returns the client interface this instance registers in |
| 274 | * the centralized accessibility manager service. |
| 275 | * |
| 276 | * @return The client. |
| 277 | * |
| 278 | * @hide |
| 279 | */ |
| 280 | public IAccessibilityManagerClient getClient() { |
Jim Miller | 4dfecf5 | 2011-06-30 15:45:35 -0700 | [diff] [blame] | 281 | return (IAccessibilityManagerClient) mClient.asBinder(); |
Svetoslav Ganov | af7adab | 2010-04-16 18:07:48 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /** |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 285 | * Sends an {@link AccessibilityEvent}. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 286 | * |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 287 | * @param event The event to send. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 288 | * |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 289 | * @throws IllegalStateException if accessibility is not enabled. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 290 | * |
| 291 | * <strong>Note:</strong> The preferred mechanism for sending custom accessibility |
| 292 | * events is through calling |
| 293 | * {@link android.view.ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)} |
| 294 | * instead of this method to allow predecessors to augment/filter events sent by |
| 295 | * their descendants. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 296 | */ |
| 297 | public void sendAccessibilityEvent(AccessibilityEvent event) { |
| 298 | if (!mIsEnabled) { |
| 299 | throw new IllegalStateException("Accessibility off. Did you forget to check that?"); |
| 300 | } |
| 301 | boolean doRecycle = false; |
| 302 | try { |
| 303 | event.setEventTime(SystemClock.uptimeMillis()); |
| 304 | // it is possible that this manager is in the same process as the service but |
| 305 | // client using it is called through Binder from another process. Example: MMS |
| 306 | // app adds a SMS notification and the NotificationManagerService calls this method |
| 307 | long identityToken = Binder.clearCallingIdentity(); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 308 | doRecycle = mService.sendAccessibilityEvent(event, mUserId); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 309 | Binder.restoreCallingIdentity(identityToken); |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 310 | if (DEBUG) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 311 | Log.i(LOG_TAG, event + " sent"); |
| 312 | } |
| 313 | } catch (RemoteException re) { |
| 314 | Log.e(LOG_TAG, "Error during sending " + event + " ", re); |
| 315 | } finally { |
| 316 | if (doRecycle) { |
| 317 | event.recycle(); |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | /** |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 323 | * Requests feedback interruption from all accessibility services. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 324 | */ |
| 325 | public void interrupt() { |
| 326 | if (!mIsEnabled) { |
| 327 | throw new IllegalStateException("Accessibility off. Did you forget to check that?"); |
| 328 | } |
| 329 | try { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 330 | mService.interrupt(mUserId); |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 331 | if (DEBUG) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 332 | Log.i(LOG_TAG, "Requested interrupt from all services"); |
| 333 | } |
| 334 | } catch (RemoteException re) { |
| 335 | Log.e(LOG_TAG, "Error while requesting interrupt from all services. ", re); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Returns the {@link ServiceInfo}s of the installed accessibility services. |
| 341 | * |
| 342 | * @return An unmodifiable list with {@link ServiceInfo}s. |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 343 | * |
| 344 | * @deprecated Use {@link #getInstalledAccessibilityServiceList()} |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 345 | */ |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 346 | @Deprecated |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 347 | public List<ServiceInfo> getAccessibilityServiceList() { |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 348 | List<AccessibilityServiceInfo> infos = getInstalledAccessibilityServiceList(); |
| 349 | List<ServiceInfo> services = new ArrayList<ServiceInfo>(); |
| 350 | final int infoCount = infos.size(); |
| 351 | for (int i = 0; i < infoCount; i++) { |
| 352 | AccessibilityServiceInfo info = infos.get(i); |
| 353 | services.add(info.getResolveInfo().serviceInfo); |
| 354 | } |
| 355 | return Collections.unmodifiableList(services); |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * Returns the {@link AccessibilityServiceInfo}s of the installed accessibility services. |
| 360 | * |
| 361 | * @return An unmodifiable list with {@link AccessibilityServiceInfo}s. |
| 362 | */ |
| 363 | public List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList() { |
| 364 | List<AccessibilityServiceInfo> services = null; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 365 | try { |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 366 | if (mService != null) { |
| 367 | services = mService.getInstalledAccessibilityServiceList(mUserId); |
| 368 | if (DEBUG) { |
| 369 | Log.i(LOG_TAG, "Installed AccessibilityServices " + services); |
| 370 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 371 | } |
| 372 | } catch (RemoteException re) { |
| 373 | Log.e(LOG_TAG, "Error while obtaining the installed AccessibilityServices. ", re); |
| 374 | } |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 375 | return services != null ? Collections.unmodifiableList(services) : Collections.EMPTY_LIST; |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /** |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 379 | * Returns the {@link AccessibilityServiceInfo}s of the enabled accessibility services |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 380 | * for a given feedback type. |
| 381 | * |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 382 | * @param feedbackTypeFlags The feedback type flags. |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 383 | * @return An unmodifiable list with {@link AccessibilityServiceInfo}s. |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 384 | * |
| 385 | * @see AccessibilityServiceInfo#FEEDBACK_AUDIBLE |
| 386 | * @see AccessibilityServiceInfo#FEEDBACK_GENERIC |
| 387 | * @see AccessibilityServiceInfo#FEEDBACK_HAPTIC |
| 388 | * @see AccessibilityServiceInfo#FEEDBACK_SPOKEN |
| 389 | * @see AccessibilityServiceInfo#FEEDBACK_VISUAL |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 390 | */ |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 391 | public List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList( |
| 392 | int feedbackTypeFlags) { |
Svetoslav Ganov | cc4053e | 2011-05-23 13:37:44 -0700 | [diff] [blame] | 393 | List<AccessibilityServiceInfo> services = null; |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 394 | try { |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 395 | if (mService != null) { |
| 396 | services = mService.getEnabledAccessibilityServiceList(feedbackTypeFlags, mUserId); |
| 397 | if (DEBUG) { |
| 398 | Log.i(LOG_TAG, "Installed AccessibilityServices " + services); |
| 399 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 400 | } |
| 401 | } catch (RemoteException re) { |
| 402 | Log.e(LOG_TAG, "Error while obtaining the installed AccessibilityServices. ", re); |
| 403 | } |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 404 | return services != null ? Collections.unmodifiableList(services) : Collections.EMPTY_LIST; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 405 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 406 | |
| 407 | /** |
Svetoslav Ganov | 38e8b4e | 2011-06-29 20:00:53 -0700 | [diff] [blame] | 408 | * Registers an {@link AccessibilityStateChangeListener} for changes in |
| 409 | * the global accessibility state of the system. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 410 | * |
| 411 | * @param listener The listener. |
| 412 | * @return True if successfully registered. |
| 413 | */ |
| 414 | public boolean addAccessibilityStateChangeListener( |
| 415 | AccessibilityStateChangeListener listener) { |
| 416 | return mAccessibilityStateChangeListeners.add(listener); |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * Unregisters an {@link AccessibilityStateChangeListener}. |
| 421 | * |
| 422 | * @param listener The listener. |
| 423 | * @return True if successfully unregistered. |
| 424 | */ |
| 425 | public boolean removeAccessibilityStateChangeListener( |
| 426 | AccessibilityStateChangeListener listener) { |
| 427 | return mAccessibilityStateChangeListeners.remove(listener); |
| 428 | } |
| 429 | |
| 430 | /** |
Alan Viverette | 5baeb9a | 2013-10-09 14:42:05 -0700 | [diff] [blame] | 431 | * Registers a {@link TouchExplorationStateChangeListener} for changes in |
| 432 | * the global touch exploration state of the system. |
| 433 | * |
| 434 | * @param listener The listener. |
| 435 | * @return True if successfully registered. |
| 436 | */ |
| 437 | public boolean addTouchExplorationStateChangeListener( |
| 438 | TouchExplorationStateChangeListener listener) { |
| 439 | return mTouchExplorationStateChangeListeners.add(listener); |
| 440 | } |
| 441 | |
| 442 | /** |
| 443 | * Unregisters a {@link TouchExplorationStateChangeListener}. |
| 444 | * |
| 445 | * @param listener The listener. |
| 446 | * @return True if successfully unregistered. |
| 447 | */ |
| 448 | public boolean removeTouchExplorationStateChangeListener( |
| 449 | TouchExplorationStateChangeListener listener) { |
| 450 | return mTouchExplorationStateChangeListeners.remove(listener); |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * Sets the current state and notifies listeners, if necessary. |
Svetoslav Ganov | 00aabf7 | 2011-07-21 11:35:03 -0700 | [diff] [blame] | 455 | * |
| 456 | * @param stateFlags The state flags. |
| 457 | */ |
| 458 | private void setState(int stateFlags) { |
Alan Viverette | 5baeb9a | 2013-10-09 14:42:05 -0700 | [diff] [blame] | 459 | final boolean enabled = (stateFlags & STATE_FLAG_ACCESSIBILITY_ENABLED) != 0; |
| 460 | final boolean touchExplorationEnabled = |
| 461 | (stateFlags & STATE_FLAG_TOUCH_EXPLORATION_ENABLED) != 0; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 462 | synchronized (mHandler) { |
Alan Viverette | 7e361d2 | 2013-10-09 17:20:43 -0700 | [diff] [blame] | 463 | final boolean wasEnabled = mIsEnabled; |
| 464 | final boolean wasTouchExplorationEnabled = mIsTouchExplorationEnabled; |
| 465 | |
| 466 | // Ensure listeners get current state from isZzzEnabled() calls. |
Alan Viverette | 5baeb9a | 2013-10-09 14:42:05 -0700 | [diff] [blame] | 467 | mIsEnabled = enabled; |
| 468 | mIsTouchExplorationEnabled = touchExplorationEnabled; |
| 469 | |
Alan Viverette | 7e361d2 | 2013-10-09 17:20:43 -0700 | [diff] [blame] | 470 | if (wasEnabled != enabled) { |
Alan Viverette | 5baeb9a | 2013-10-09 14:42:05 -0700 | [diff] [blame] | 471 | notifyAccessibilityStateChangedLh(); |
| 472 | } |
| 473 | |
Alan Viverette | 7e361d2 | 2013-10-09 17:20:43 -0700 | [diff] [blame] | 474 | if (wasTouchExplorationEnabled != touchExplorationEnabled) { |
Alan Viverette | 5baeb9a | 2013-10-09 14:42:05 -0700 | [diff] [blame] | 475 | notifyTouchExplorationStateChangedLh(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * Notifies the registered {@link AccessibilityStateChangeListener}s. |
Alan Viverette | 5baeb9a | 2013-10-09 14:42:05 -0700 | [diff] [blame] | 482 | * <p> |
| 483 | * The caller must be locked on {@link #mHandler}. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 484 | */ |
Alan Viverette | 5baeb9a | 2013-10-09 14:42:05 -0700 | [diff] [blame] | 485 | private void notifyAccessibilityStateChangedLh() { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 486 | final int listenerCount = mAccessibilityStateChangeListeners.size(); |
| 487 | for (int i = 0; i < listenerCount; i++) { |
| 488 | mAccessibilityStateChangeListeners.get(i).onAccessibilityStateChanged(mIsEnabled); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | /** |
Alan Viverette | 5baeb9a | 2013-10-09 14:42:05 -0700 | [diff] [blame] | 493 | * Notifies the registered {@link TouchExplorationStateChangeListener}s. |
| 494 | * <p> |
| 495 | * The caller must be locked on {@link #mHandler}. |
| 496 | */ |
| 497 | private void notifyTouchExplorationStateChangedLh() { |
| 498 | final int listenerCount = mTouchExplorationStateChangeListeners.size(); |
| 499 | for (int i = 0; i < listenerCount; i++) { |
| 500 | mTouchExplorationStateChangeListeners.get(i) |
| 501 | .onTouchExplorationStateChanged(mIsTouchExplorationEnabled); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 506 | * Adds an accessibility interaction connection interface for a given window. |
| 507 | * @param windowToken The window token to which a connection is added. |
| 508 | * @param connection The connection. |
| 509 | * |
| 510 | * @hide |
| 511 | */ |
| 512 | public int addAccessibilityInteractionConnection(IWindow windowToken, |
| 513 | IAccessibilityInteractionConnection connection) { |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 514 | if (mService == null) { |
| 515 | return View.NO_ID; |
| 516 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 517 | try { |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 518 | return mService.addAccessibilityInteractionConnection(windowToken, connection, mUserId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 519 | } catch (RemoteException re) { |
| 520 | Log.e(LOG_TAG, "Error while adding an accessibility interaction connection. ", re); |
| 521 | } |
| 522 | return View.NO_ID; |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * Removed an accessibility interaction connection interface for a given window. |
| 527 | * @param windowToken The window token to which a connection is removed. |
| 528 | * |
| 529 | * @hide |
| 530 | */ |
| 531 | public void removeAccessibilityInteractionConnection(IWindow windowToken) { |
| 532 | try { |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 533 | if (mService != null) { |
| 534 | mService.removeAccessibilityInteractionConnection(windowToken); |
| 535 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 536 | } catch (RemoteException re) { |
| 537 | Log.e(LOG_TAG, "Error while removing an accessibility interaction connection. ", re); |
| 538 | } |
| 539 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 540 | } |