• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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                 public void setFocusAppearance(int strokeWidth, int color) {
161                 }
162             };
163 
164     /**
165      * Get an AccessibilityManager instance (create one if necessary).
166      *
167      */
getInstance(Context context)168     public static AccessibilityManager getInstance(Context context) {
169         return sInstance;
170     }
171 
172     /**
173      * Create an instance.
174      *
175      * @param context A {@link Context}.
176      */
AccessibilityManager(Context context, IAccessibilityManager service, int userId)177     public AccessibilityManager(Context context, IAccessibilityManager service, int userId) {
178     }
179 
getClient()180     public IAccessibilityManagerClient getClient() {
181         return mClient;
182     }
183 
184     /**
185      * Returns if the {@link AccessibilityManager} is enabled.
186      *
187      * @return True if this {@link AccessibilityManager} is enabled, false otherwise.
188      */
isEnabled()189     public boolean isEnabled() {
190         return false;
191     }
192 
193     /**
194      * Returns if the touch exploration in the system is enabled.
195      *
196      * @return True if touch exploration is enabled, false otherwise.
197      */
isTouchExplorationEnabled()198     public boolean isTouchExplorationEnabled() {
199         return true;
200     }
201 
202     /**
203      * Returns if the high text contrast in the system is enabled.
204      * <p>
205      * <strong>Note:</strong> You need to query this only if you application is
206      * doing its own rendering and does not rely on the platform rendering pipeline.
207      * </p>
208      *
209      */
isHighTextContrastEnabled()210     public boolean isHighTextContrastEnabled() {
211         return false;
212     }
213 
214     /**
215      * Sends an {@link AccessibilityEvent}.
216      */
sendAccessibilityEvent(AccessibilityEvent event)217     public void sendAccessibilityEvent(AccessibilityEvent event) {
218     }
219 
220     /**
221      * Returns whether there are observers registered for this event type. If
222      * this method returns false you shuold not generate events of this type
223      * to conserve resources.
224      *
225      * @param type The event type.
226      * @return Whether the event is being observed.
227      */
isObservedEventType(@ccessibilityEvent.EventType int type)228     public boolean isObservedEventType(@AccessibilityEvent.EventType int type) {
229         return false;
230     }
231 
232     /**
233      * Requests interruption of the accessibility feedback from all accessibility services.
234      */
interrupt()235     public void interrupt() {
236     }
237 
238     /**
239      * Returns the {@link ServiceInfo}s of the installed accessibility services.
240      *
241      * @return An unmodifiable list with {@link ServiceInfo}s.
242      */
243     @Deprecated
getAccessibilityServiceList()244     public List<ServiceInfo> getAccessibilityServiceList() {
245         return Collections.emptyList();
246     }
247 
getInstalledAccessibilityServiceList()248     public List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList() {
249         return Collections.emptyList();
250     }
251 
252     /**
253      * Returns the {@link AccessibilityServiceInfo}s of the enabled accessibility services
254      * for a given feedback type.
255      *
256      * @param feedbackTypeFlags The feedback type flags.
257      * @return An unmodifiable list with {@link AccessibilityServiceInfo}s.
258      *
259      * @see AccessibilityServiceInfo#FEEDBACK_AUDIBLE
260      * @see AccessibilityServiceInfo#FEEDBACK_GENERIC
261      * @see AccessibilityServiceInfo#FEEDBACK_HAPTIC
262      * @see AccessibilityServiceInfo#FEEDBACK_SPOKEN
263      * @see AccessibilityServiceInfo#FEEDBACK_VISUAL
264      */
getEnabledAccessibilityServiceList( int feedbackTypeFlags)265     public List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList(
266             int feedbackTypeFlags) {
267         return Collections.emptyList();
268     }
269 
270     /**
271      * Registers an {@link AccessibilityStateChangeListener} for changes in
272      * the global accessibility state of the system.
273      *
274      * @param listener The listener.
275      * @return True if successfully registered.
276      */
addAccessibilityStateChangeListener( AccessibilityStateChangeListener listener)277     public boolean addAccessibilityStateChangeListener(
278             AccessibilityStateChangeListener listener) {
279         return true;
280     }
281 
282     /**
283      * Registers an {@link AccessibilityStateChangeListener} for changes in
284      * the global accessibility state of the system. If the listener has already been registered,
285      * the handler used to call it back is updated.
286      *
287      * @param listener The listener.
288      * @param handler The handler on which the listener should be called back, or {@code null}
289      *                for a callback on the process's main handler.
290      */
addAccessibilityStateChangeListener( @onNull AccessibilityStateChangeListener listener, @Nullable Handler handler)291     public void addAccessibilityStateChangeListener(
292             @NonNull AccessibilityStateChangeListener listener, @Nullable Handler handler) {}
293 
removeAccessibilityStateChangeListener( AccessibilityStateChangeListener listener)294     public boolean removeAccessibilityStateChangeListener(
295             AccessibilityStateChangeListener listener) {
296         return true;
297     }
298 
299     /**
300      * Registers a {@link TouchExplorationStateChangeListener} for changes in
301      * the global touch exploration state of the system.
302      *
303      * @param listener The listener.
304      * @return True if successfully registered.
305      */
addTouchExplorationStateChangeListener( @onNull TouchExplorationStateChangeListener listener)306     public boolean addTouchExplorationStateChangeListener(
307             @NonNull TouchExplorationStateChangeListener listener) {
308         return true;
309     }
310 
311     /**
312      * Registers an {@link TouchExplorationStateChangeListener} for changes in
313      * the global touch exploration state of the system. If the listener has already been
314      * registered, the handler used to call it back is updated.
315      *
316      * @param listener The listener.
317      * @param handler The handler on which the listener should be called back, or {@code null}
318      *                for a callback on the process's main handler.
319      */
addTouchExplorationStateChangeListener( @onNull TouchExplorationStateChangeListener listener, @Nullable Handler handler)320     public void addTouchExplorationStateChangeListener(
321             @NonNull TouchExplorationStateChangeListener listener, @Nullable Handler handler) {}
322 
323     /**
324      * Unregisters a {@link TouchExplorationStateChangeListener}.
325      *
326      * @param listener The listener.
327      * @return True if successfully unregistered.
328      */
removeTouchExplorationStateChangeListener( @onNull TouchExplorationStateChangeListener listener)329     public boolean removeTouchExplorationStateChangeListener(
330             @NonNull TouchExplorationStateChangeListener listener) {
331         return true;
332     }
333 
334     /**
335      * Registers a {@link HighTextContrastChangeListener} for changes in
336      * the global high text contrast state of the system.
337      *
338      * @param listener The listener.
339      *
340      * @hide
341      */
addHighTextContrastStateChangeListener( @onNull HighTextContrastChangeListener listener, @Nullable Handler handler)342     public void addHighTextContrastStateChangeListener(
343             @NonNull HighTextContrastChangeListener listener, @Nullable Handler handler) {}
344 
345     /**
346      * Unregisters a {@link HighTextContrastChangeListener}.
347      *
348      * @param listener The listener.
349      *
350      * @hide
351      */
removeHighTextContrastStateChangeListener( @onNull HighTextContrastChangeListener listener)352     public void removeHighTextContrastStateChangeListener(
353             @NonNull HighTextContrastChangeListener listener) {}
354 
355     /**
356      * Sets the current state and notifies listeners, if necessary.
357      *
358      * @param stateFlags The state flags.
359      */
setStateLocked(int stateFlags)360     private void setStateLocked(int stateFlags) {
361     }
362 
addAccessibilityInteractionConnection(IWindow windowToken, IAccessibilityInteractionConnection connection)363     public int addAccessibilityInteractionConnection(IWindow windowToken,
364             IAccessibilityInteractionConnection connection) {
365         return View.NO_ID;
366     }
367 
removeAccessibilityInteractionConnection(IWindow windowToken)368     public void removeAccessibilityInteractionConnection(IWindow windowToken) {
369     }
370 
371 }
372