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 19 import android.accessibilityservice.AccessibilityServiceInfo; 20 import android.accessibilityservice.AccessibilityServiceInfo.FeedbackType; 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.content.Context; 24 import android.content.pm.ServiceInfo; 25 import android.os.Handler; 26 import android.view.IWindow; 27 import android.view.View; 28 import android.view.accessibility.AccessibilityEvent.EventType; 29 30 import java.util.Collections; 31 import java.util.List; 32 33 /** 34 * System level service that serves as an event dispatch for {@link AccessibilityEvent}s. 35 * Such events are generated when something notable happens in the user interface, 36 * for example an {@link android.app.Activity} starts, the focus or selection of a 37 * {@link android.view.View} changes etc. Parties interested in handling accessibility 38 * events implement and register an accessibility service which extends 39 * {@code android.accessibilityservice.AccessibilityService}. 40 * 41 * @see AccessibilityEvent 42 * @see android.content.Context#getSystemService 43 */ 44 @SuppressWarnings("UnusedDeclaration") 45 public final class AccessibilityManager { 46 47 private static AccessibilityManager sInstance = new AccessibilityManager(null, null, 0); 48 49 50 /** 51 * Listener for the accessibility state. 52 */ 53 public interface AccessibilityStateChangeListener { 54 55 /** 56 * Called back on change in the accessibility state. 57 * 58 * @param enabled Whether accessibility is enabled. 59 */ onAccessibilityStateChanged(boolean enabled)60 public void onAccessibilityStateChanged(boolean enabled); 61 } 62 63 /** 64 * Listener for the system touch exploration state. To listen for changes to 65 * the touch exploration state on the device, implement this interface and 66 * register it with the system by calling 67 * {@link #addTouchExplorationStateChangeListener}. 68 */ 69 public interface TouchExplorationStateChangeListener { 70 71 /** 72 * Called when the touch exploration enabled state changes. 73 * 74 * @param enabled Whether touch exploration is enabled. 75 */ onTouchExplorationStateChanged(boolean enabled)76 public void onTouchExplorationStateChanged(boolean enabled); 77 } 78 79 /** 80 * Listener for the system high text contrast state. To listen for changes to 81 * the high text contrast state on the device, implement this interface and 82 * register it with the system by calling 83 * {@link #addHighTextContrastStateChangeListener}. 84 */ 85 public interface HighTextContrastChangeListener { 86 87 /** 88 * Called when the high text contrast enabled state changes. 89 * 90 * @param enabled Whether high text contrast is enabled. 91 */ onHighTextContrastStateChanged(boolean enabled)92 public void onHighTextContrastStateChanged(boolean enabled); 93 } 94 95 /** 96 * Policy to inject behavior into the accessibility manager. 97 * 98 * @hide 99 */ 100 public interface AccessibilityPolicy { 101 /** 102 * Checks whether accessibility is enabled. 103 * 104 * @param accessibilityEnabled Whether the accessibility layer is enabled. 105 * @return whether accessibility is enabled. 106 */ isEnabled(boolean accessibilityEnabled)107 boolean isEnabled(boolean accessibilityEnabled); 108 109 /** 110 * Notifies the policy for an accessibility event. 111 * 112 * @param event The event. 113 * @param accessibilityEnabled Whether the accessibility layer is enabled. 114 * @param relevantEventTypes The events relevant events. 115 * @return The event to dispatch or null. 116 */ onAccessibilityEvent(@onNull AccessibilityEvent event, boolean accessibilityEnabled, @EventType int relevantEventTypes)117 @Nullable AccessibilityEvent onAccessibilityEvent(@NonNull AccessibilityEvent event, 118 boolean accessibilityEnabled, @EventType int relevantEventTypes); 119 120 /** 121 * Gets the list of relevant events. 122 * 123 * @param relevantEventTypes The relevant events. 124 * @return The relevant events to report. 125 */ getRelevantEventTypes(@ventType int relevantEventTypes)126 @EventType int getRelevantEventTypes(@EventType int relevantEventTypes); 127 128 /** 129 * Gets the list of installed services to report. 130 * 131 * @param installedService The installed services. 132 * @return The services to report. 133 */ getInstalledAccessibilityServiceList( @ullable List<AccessibilityServiceInfo> installedService)134 @NonNull List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList( 135 @Nullable List<AccessibilityServiceInfo> installedService); 136 137 /** 138 * Gets the list of enabled accessibility services. 139 * 140 * @param feedbackTypeFlags The feedback type to query for. 141 * @param enabledService The enabled services. 142 * @return The services to report. 143 */ getEnabledAccessibilityServiceList( @eedbackType int feedbackTypeFlags, @Nullable List<AccessibilityServiceInfo> enabledService)144 @Nullable List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList( 145 @FeedbackType int feedbackTypeFlags, 146 @Nullable List<AccessibilityServiceInfo> enabledService); 147 } 148 149 private final IAccessibilityManagerClient.Stub mClient = 150 new IAccessibilityManagerClient.Stub() { 151 public void setState(int state) { 152 } 153 154 public void notifyServicesStateChanged(long updatedUiTimeout) { 155 } 156 157 public void setRelevantEventTypes(int eventTypes) { 158 } 159 }; 160 161 /** 162 * Get an AccessibilityManager instance (create one if necessary). 163 * 164 */ getInstance(Context context)165 public static AccessibilityManager getInstance(Context context) { 166 return sInstance; 167 } 168 169 /** 170 * Create an instance. 171 * 172 * @param context A {@link Context}. 173 */ AccessibilityManager(Context context, IAccessibilityManager service, int userId)174 public AccessibilityManager(Context context, IAccessibilityManager service, int userId) { 175 } 176 getClient()177 public IAccessibilityManagerClient getClient() { 178 return mClient; 179 } 180 181 /** 182 * Returns if the {@link AccessibilityManager} is enabled. 183 * 184 * @return True if this {@link AccessibilityManager} is enabled, false otherwise. 185 */ isEnabled()186 public boolean isEnabled() { 187 return false; 188 } 189 190 /** 191 * Returns if the touch exploration in the system is enabled. 192 * 193 * @return True if touch exploration is enabled, false otherwise. 194 */ isTouchExplorationEnabled()195 public boolean isTouchExplorationEnabled() { 196 return true; 197 } 198 199 /** 200 * Returns if the high text contrast in the system is enabled. 201 * <p> 202 * <strong>Note:</strong> You need to query this only if you application is 203 * doing its own rendering and does not rely on the platform rendering pipeline. 204 * </p> 205 * 206 */ isHighTextContrastEnabled()207 public boolean isHighTextContrastEnabled() { 208 return false; 209 } 210 211 /** 212 * Sends an {@link AccessibilityEvent}. 213 */ sendAccessibilityEvent(AccessibilityEvent event)214 public void sendAccessibilityEvent(AccessibilityEvent event) { 215 } 216 217 /** 218 * Returns whether there are observers registered for this event type. If 219 * this method returns false you shuold not generate events of this type 220 * to conserve resources. 221 * 222 * @param type The event type. 223 * @return Whether the event is being observed. 224 */ isObservedEventType(@ccessibilityEvent.EventType int type)225 public boolean isObservedEventType(@AccessibilityEvent.EventType int type) { 226 return false; 227 } 228 229 /** 230 * Requests interruption of the accessibility feedback from all accessibility services. 231 */ interrupt()232 public void interrupt() { 233 } 234 235 /** 236 * Returns the {@link ServiceInfo}s of the installed accessibility services. 237 * 238 * @return An unmodifiable list with {@link ServiceInfo}s. 239 */ 240 @Deprecated getAccessibilityServiceList()241 public List<ServiceInfo> getAccessibilityServiceList() { 242 return Collections.emptyList(); 243 } 244 getInstalledAccessibilityServiceList()245 public List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList() { 246 return Collections.emptyList(); 247 } 248 249 /** 250 * Returns the {@link AccessibilityServiceInfo}s of the enabled accessibility services 251 * for a given feedback type. 252 * 253 * @param feedbackTypeFlags The feedback type flags. 254 * @return An unmodifiable list with {@link AccessibilityServiceInfo}s. 255 * 256 * @see AccessibilityServiceInfo#FEEDBACK_AUDIBLE 257 * @see AccessibilityServiceInfo#FEEDBACK_GENERIC 258 * @see AccessibilityServiceInfo#FEEDBACK_HAPTIC 259 * @see AccessibilityServiceInfo#FEEDBACK_SPOKEN 260 * @see AccessibilityServiceInfo#FEEDBACK_VISUAL 261 */ getEnabledAccessibilityServiceList( int feedbackTypeFlags)262 public List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList( 263 int feedbackTypeFlags) { 264 return Collections.emptyList(); 265 } 266 267 /** 268 * Registers an {@link AccessibilityStateChangeListener} for changes in 269 * the global accessibility state of the system. 270 * 271 * @param listener The listener. 272 * @return True if successfully registered. 273 */ addAccessibilityStateChangeListener( AccessibilityStateChangeListener listener)274 public boolean addAccessibilityStateChangeListener( 275 AccessibilityStateChangeListener listener) { 276 return true; 277 } 278 279 /** 280 * Registers an {@link AccessibilityStateChangeListener} for changes in 281 * the global accessibility state of the system. If the listener has already been registered, 282 * the handler used to call it back is updated. 283 * 284 * @param listener The listener. 285 * @param handler The handler on which the listener should be called back, or {@code null} 286 * for a callback on the process's main handler. 287 */ addAccessibilityStateChangeListener( @onNull AccessibilityStateChangeListener listener, @Nullable Handler handler)288 public void addAccessibilityStateChangeListener( 289 @NonNull AccessibilityStateChangeListener listener, @Nullable Handler handler) {} 290 removeAccessibilityStateChangeListener( AccessibilityStateChangeListener listener)291 public boolean removeAccessibilityStateChangeListener( 292 AccessibilityStateChangeListener listener) { 293 return true; 294 } 295 296 /** 297 * Registers a {@link TouchExplorationStateChangeListener} for changes in 298 * the global touch exploration state of the system. 299 * 300 * @param listener The listener. 301 * @return True if successfully registered. 302 */ addTouchExplorationStateChangeListener( @onNull TouchExplorationStateChangeListener listener)303 public boolean addTouchExplorationStateChangeListener( 304 @NonNull TouchExplorationStateChangeListener listener) { 305 return true; 306 } 307 308 /** 309 * Registers an {@link TouchExplorationStateChangeListener} for changes in 310 * the global touch exploration state of the system. If the listener has already been 311 * registered, the handler used to call it back is updated. 312 * 313 * @param listener The listener. 314 * @param handler The handler on which the listener should be called back, or {@code null} 315 * for a callback on the process's main handler. 316 */ addTouchExplorationStateChangeListener( @onNull TouchExplorationStateChangeListener listener, @Nullable Handler handler)317 public void addTouchExplorationStateChangeListener( 318 @NonNull TouchExplorationStateChangeListener listener, @Nullable Handler handler) {} 319 320 /** 321 * Unregisters a {@link TouchExplorationStateChangeListener}. 322 * 323 * @param listener The listener. 324 * @return True if successfully unregistered. 325 */ removeTouchExplorationStateChangeListener( @onNull TouchExplorationStateChangeListener listener)326 public boolean removeTouchExplorationStateChangeListener( 327 @NonNull TouchExplorationStateChangeListener listener) { 328 return true; 329 } 330 331 /** 332 * Registers a {@link HighTextContrastChangeListener} for changes in 333 * the global high text contrast state of the system. 334 * 335 * @param listener The listener. 336 * 337 * @hide 338 */ addHighTextContrastStateChangeListener( @onNull HighTextContrastChangeListener listener, @Nullable Handler handler)339 public void addHighTextContrastStateChangeListener( 340 @NonNull HighTextContrastChangeListener listener, @Nullable Handler handler) {} 341 342 /** 343 * Unregisters a {@link HighTextContrastChangeListener}. 344 * 345 * @param listener The listener. 346 * 347 * @hide 348 */ removeHighTextContrastStateChangeListener( @onNull HighTextContrastChangeListener listener)349 public void removeHighTextContrastStateChangeListener( 350 @NonNull HighTextContrastChangeListener listener) {} 351 352 /** 353 * Sets the current state and notifies listeners, if necessary. 354 * 355 * @param stateFlags The state flags. 356 */ setStateLocked(int stateFlags)357 private void setStateLocked(int stateFlags) { 358 } 359 addAccessibilityInteractionConnection(IWindow windowToken, IAccessibilityInteractionConnection connection)360 public int addAccessibilityInteractionConnection(IWindow windowToken, 361 IAccessibilityInteractionConnection connection) { 362 return View.NO_ID; 363 } 364 removeAccessibilityInteractionConnection(IWindow windowToken)365 public void removeAccessibilityInteractionConnection(IWindow windowToken) { 366 } 367 368 } 369