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 com.android.annotations.NonNull; 20 21 import android.accessibilityservice.AccessibilityServiceInfo; 22 import android.content.Context; 23 import android.content.pm.ServiceInfo; 24 import android.view.IWindow; 25 import android.view.View; 26 27 import java.util.Collections; 28 import java.util.List; 29 30 /** 31 * System level service that serves as an event dispatch for {@link AccessibilityEvent}s. 32 * Such events are generated when something notable happens in the user interface, 33 * for example an {@link android.app.Activity} starts, the focus or selection of a 34 * {@link android.view.View} changes etc. Parties interested in handling accessibility 35 * events implement and register an accessibility service which extends 36 * {@code android.accessibilityservice.AccessibilityService}. 37 * 38 * @see AccessibilityEvent 39 * @see android.content.Context#getSystemService 40 */ 41 @SuppressWarnings("UnusedDeclaration") 42 public final class AccessibilityManager { 43 44 private static AccessibilityManager sInstance = new AccessibilityManager(null, null, 0); 45 46 47 /** 48 * Listener for the accessibility state. 49 */ 50 public interface AccessibilityStateChangeListener { 51 52 /** 53 * Called back on change in the accessibility state. 54 * 55 * @param enabled Whether accessibility is enabled. 56 */ onAccessibilityStateChanged(boolean enabled)57 public void onAccessibilityStateChanged(boolean enabled); 58 } 59 60 /** 61 * Listener for the system touch exploration state. To listen for changes to 62 * the touch exploration state on the device, implement this interface and 63 * register it with the system by calling 64 * {@link #addTouchExplorationStateChangeListener}. 65 */ 66 public interface TouchExplorationStateChangeListener { 67 68 /** 69 * Called when the touch exploration enabled state changes. 70 * 71 * @param enabled Whether touch exploration is enabled. 72 */ onTouchExplorationStateChanged(boolean enabled)73 public void onTouchExplorationStateChanged(boolean enabled); 74 } 75 76 /** 77 * Listener for the system high text contrast state. To listen for changes to 78 * the high text contrast state on the device, implement this interface and 79 * register it with the system by calling 80 * {@link #addHighTextContrastStateChangeListener}. 81 */ 82 public interface HighTextContrastChangeListener { 83 84 /** 85 * Called when the high text contrast enabled state changes. 86 * 87 * @param enabled Whether high text contrast is enabled. 88 */ onHighTextContrastStateChanged(boolean enabled)89 public void onHighTextContrastStateChanged(boolean enabled); 90 } 91 92 private final IAccessibilityManagerClient.Stub mClient = 93 new IAccessibilityManagerClient.Stub() { 94 public void setState(int state) { 95 } 96 }; 97 98 /** 99 * Get an AccessibilityManager instance (create one if necessary). 100 * 101 */ getInstance(Context context)102 public static AccessibilityManager getInstance(Context context) { 103 return sInstance; 104 } 105 106 /** 107 * Create an instance. 108 * 109 * @param context A {@link Context}. 110 */ AccessibilityManager(Context context, IAccessibilityManager service, int userId)111 public AccessibilityManager(Context context, IAccessibilityManager service, int userId) { 112 } 113 getClient()114 public IAccessibilityManagerClient getClient() { 115 return mClient; 116 } 117 118 /** 119 * Returns if the {@link AccessibilityManager} is enabled. 120 * 121 * @return True if this {@link AccessibilityManager} is enabled, false otherwise. 122 */ isEnabled()123 public boolean isEnabled() { 124 return false; 125 } 126 127 /** 128 * Returns if the touch exploration in the system is enabled. 129 * 130 * @return True if touch exploration is enabled, false otherwise. 131 */ isTouchExplorationEnabled()132 public boolean isTouchExplorationEnabled() { 133 return true; 134 } 135 136 /** 137 * Returns if the high text contrast in the system is enabled. 138 * <p> 139 * <strong>Note:</strong> You need to query this only if you application is 140 * doing its own rendering and does not rely on the platform rendering pipeline. 141 * </p> 142 * 143 */ isHighTextContrastEnabled()144 public boolean isHighTextContrastEnabled() { 145 return false; 146 } 147 148 /** 149 * Sends an {@link AccessibilityEvent}. 150 */ sendAccessibilityEvent(AccessibilityEvent event)151 public void sendAccessibilityEvent(AccessibilityEvent event) { 152 } 153 154 /** 155 * Requests interruption of the accessibility feedback from all accessibility services. 156 */ interrupt()157 public void interrupt() { 158 } 159 160 /** 161 * Returns the {@link ServiceInfo}s of the installed accessibility services. 162 * 163 * @return An unmodifiable list with {@link ServiceInfo}s. 164 */ 165 @Deprecated getAccessibilityServiceList()166 public List<ServiceInfo> getAccessibilityServiceList() { 167 return Collections.emptyList(); 168 } 169 getInstalledAccessibilityServiceList()170 public List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList() { 171 return Collections.emptyList(); 172 } 173 174 /** 175 * Returns the {@link AccessibilityServiceInfo}s of the enabled accessibility services 176 * for a given feedback type. 177 * 178 * @param feedbackTypeFlags The feedback type flags. 179 * @return An unmodifiable list with {@link AccessibilityServiceInfo}s. 180 * 181 * @see AccessibilityServiceInfo#FEEDBACK_AUDIBLE 182 * @see AccessibilityServiceInfo#FEEDBACK_GENERIC 183 * @see AccessibilityServiceInfo#FEEDBACK_HAPTIC 184 * @see AccessibilityServiceInfo#FEEDBACK_SPOKEN 185 * @see AccessibilityServiceInfo#FEEDBACK_VISUAL 186 */ getEnabledAccessibilityServiceList( int feedbackTypeFlags)187 public List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList( 188 int feedbackTypeFlags) { 189 return Collections.emptyList(); 190 } 191 192 /** 193 * Registers an {@link AccessibilityStateChangeListener} for changes in 194 * the global accessibility state of the system. 195 * 196 * @param listener The listener. 197 * @return True if successfully registered. 198 */ addAccessibilityStateChangeListener( AccessibilityStateChangeListener listener)199 public boolean addAccessibilityStateChangeListener( 200 AccessibilityStateChangeListener listener) { 201 return true; 202 } 203 removeAccessibilityStateChangeListener( AccessibilityStateChangeListener listener)204 public boolean removeAccessibilityStateChangeListener( 205 AccessibilityStateChangeListener listener) { 206 return true; 207 } 208 209 /** 210 * Registers a {@link TouchExplorationStateChangeListener} for changes in 211 * the global touch exploration state of the system. 212 * 213 * @param listener The listener. 214 * @return True if successfully registered. 215 */ addTouchExplorationStateChangeListener( @onNull TouchExplorationStateChangeListener listener)216 public boolean addTouchExplorationStateChangeListener( 217 @NonNull TouchExplorationStateChangeListener listener) { 218 return true; 219 } 220 221 /** 222 * Unregisters a {@link TouchExplorationStateChangeListener}. 223 * 224 * @param listener The listener. 225 * @return True if successfully unregistered. 226 */ removeTouchExplorationStateChangeListener( @onNull TouchExplorationStateChangeListener listener)227 public boolean removeTouchExplorationStateChangeListener( 228 @NonNull TouchExplorationStateChangeListener listener) { 229 return true; 230 } 231 232 /** 233 * Registers a {@link HighTextContrastChangeListener} for changes in 234 * the global high text contrast state of the system. 235 * 236 * @param listener The listener. 237 * @return True if successfully registered. 238 * 239 */ addHighTextContrastStateChangeListener( @onNull HighTextContrastChangeListener listener)240 public boolean addHighTextContrastStateChangeListener( 241 @NonNull HighTextContrastChangeListener listener) { 242 return true; 243 } 244 245 /** 246 * Unregisters a {@link HighTextContrastChangeListener}. 247 * 248 * @param listener The listener. 249 * @return True if successfully unregistered. 250 * 251 */ removeHighTextContrastStateChangeListener( @onNull HighTextContrastChangeListener listener)252 public boolean removeHighTextContrastStateChangeListener( 253 @NonNull HighTextContrastChangeListener listener) { 254 return true; 255 } 256 257 /** 258 * Sets the current state and notifies listeners, if necessary. 259 * 260 * @param stateFlags The state flags. 261 */ setStateLocked(int stateFlags)262 private void setStateLocked(int stateFlags) { 263 } 264 addAccessibilityInteractionConnection(IWindow windowToken, IAccessibilityInteractionConnection connection)265 public int addAccessibilityInteractionConnection(IWindow windowToken, 266 IAccessibilityInteractionConnection connection) { 267 return View.NO_ID; 268 } 269 removeAccessibilityInteractionConnection(IWindow windowToken)270 public void removeAccessibilityInteractionConnection(IWindow windowToken) { 271 } 272 273 } 274