Fields Summary |
---|
private static final boolean | DEBUG |
private static final String | LOG_TAG |
public static final int | STATE_FLAG_ACCESSIBILITY_ENABLED |
public static final int | STATE_FLAG_TOUCH_EXPLORATION_ENABLED |
public static final int | STATE_FLAG_HIGH_TEXT_CONTRAST_ENABLED |
public static final int | DALTONIZER_DISABLED |
public static final int | DALTONIZER_SIMULATE_MONOCHROMACY |
public static final int | DALTONIZER_CORRECT_DEUTERANOMALY |
static final Object | sInstanceSync |
private static AccessibilityManager | sInstance |
private final Object | mLock |
private IAccessibilityManager | mService |
final int | mUserId |
final android.os.Handler | mHandler |
boolean | mIsEnabled |
boolean | mIsTouchExplorationEnabled |
boolean | mIsHighTextContrastEnabled |
private final CopyOnWriteArrayList | mAccessibilityStateChangeListeners |
private final CopyOnWriteArrayList | mTouchExplorationStateChangeListeners |
private final CopyOnWriteArrayList | mHighTextContrastStateChangeListeners |
private final IAccessibilityManagerClient.Stub | mClient |
Methods Summary |
---|
public int | addAccessibilityInteractionConnection(android.view.IWindow windowToken, IAccessibilityInteractionConnection connection)Adds an accessibility interaction connection interface for a given window.
final IAccessibilityManager service;
final int userId;
synchronized (mLock) {
service = getServiceLocked();
if (service == null) {
return View.NO_ID;
}
userId = mUserId;
}
try {
return service.addAccessibilityInteractionConnection(windowToken, connection, userId);
} catch (RemoteException re) {
Log.e(LOG_TAG, "Error while adding an accessibility interaction connection. ", re);
}
return View.NO_ID;
|
public boolean | addAccessibilityStateChangeListener(android.view.accessibility.AccessibilityManager$AccessibilityStateChangeListener listener)Registers an {@link AccessibilityStateChangeListener} for changes in
the global accessibility state of the system.
// Final CopyOnWriteArrayList - no lock needed.
return mAccessibilityStateChangeListeners.add(listener);
|
public boolean | addHighTextContrastStateChangeListener(android.view.accessibility.AccessibilityManager$HighTextContrastChangeListener listener)Registers a {@link HighTextContrastChangeListener} for changes in
the global high text contrast state of the system.
// Final CopyOnWriteArrayList - no lock needed.
return mHighTextContrastStateChangeListeners.add(listener);
|
public boolean | addTouchExplorationStateChangeListener(android.view.accessibility.AccessibilityManager$TouchExplorationStateChangeListener listener)Registers a {@link TouchExplorationStateChangeListener} for changes in
the global touch exploration state of the system.
// Final CopyOnWriteArrayList - no lock needed.
return mTouchExplorationStateChangeListeners.add(listener);
|
public java.util.List | getAccessibilityServiceList()Returns the {@link ServiceInfo}s of the installed accessibility services.
List<AccessibilityServiceInfo> infos = getInstalledAccessibilityServiceList();
List<ServiceInfo> services = new ArrayList<>();
final int infoCount = infos.size();
for (int i = 0; i < infoCount; i++) {
AccessibilityServiceInfo info = infos.get(i);
services.add(info.getResolveInfo().serviceInfo);
}
return Collections.unmodifiableList(services);
|
public IAccessibilityManagerClient | getClient()
return mClient;
|
public java.util.List | getEnabledAccessibilityServiceList(int feedbackTypeFlags)Returns the {@link AccessibilityServiceInfo}s of the enabled accessibility services
for a given feedback type.
final IAccessibilityManager service;
final int userId;
synchronized (mLock) {
service = getServiceLocked();
if (service == null) {
return Collections.emptyList();
}
userId = mUserId;
}
List<AccessibilityServiceInfo> services = null;
try {
services = service.getEnabledAccessibilityServiceList(feedbackTypeFlags, userId);
if (DEBUG) {
Log.i(LOG_TAG, "Installed AccessibilityServices " + services);
}
} catch (RemoteException re) {
Log.e(LOG_TAG, "Error while obtaining the installed AccessibilityServices. ", re);
}
if (services != null) {
return Collections.unmodifiableList(services);
} else {
return Collections.emptyList();
}
|
public java.util.List | getInstalledAccessibilityServiceList()Returns the {@link AccessibilityServiceInfo}s of the installed accessibility services.
final IAccessibilityManager service;
final int userId;
synchronized (mLock) {
service = getServiceLocked();
if (service == null) {
return Collections.emptyList();
}
userId = mUserId;
}
List<AccessibilityServiceInfo> services = null;
try {
services = service.getInstalledAccessibilityServiceList(userId);
if (DEBUG) {
Log.i(LOG_TAG, "Installed AccessibilityServices " + services);
}
} catch (RemoteException re) {
Log.e(LOG_TAG, "Error while obtaining the installed AccessibilityServices. ", re);
}
if (services != null) {
return Collections.unmodifiableList(services);
} else {
return Collections.emptyList();
}
|
public static android.view.accessibility.AccessibilityManager | getInstance(android.content.Context context)Get an AccessibilityManager instance (create one if necessary).
synchronized (sInstanceSync) {
if (sInstance == null) {
final int userId;
if (Binder.getCallingUid() == Process.SYSTEM_UID
|| context.checkCallingOrSelfPermission(
Manifest.permission.INTERACT_ACROSS_USERS)
== PackageManager.PERMISSION_GRANTED
|| context.checkCallingOrSelfPermission(
Manifest.permission.INTERACT_ACROSS_USERS_FULL)
== PackageManager.PERMISSION_GRANTED) {
userId = UserHandle.USER_CURRENT;
} else {
userId = UserHandle.myUserId();
}
IBinder iBinder = ServiceManager.getService(Context.ACCESSIBILITY_SERVICE);
IAccessibilityManager service = iBinder == null
? null : IAccessibilityManager.Stub.asInterface(iBinder);
sInstance = new AccessibilityManager(context, service, userId);
}
}
return sInstance;
|
private IAccessibilityManager | getServiceLocked()
if (mService == null) {
tryConnectToServiceLocked();
}
return mService;
|
private void | handleNotifyAccessibilityStateChanged()Notifies the registered {@link AccessibilityStateChangeListener}s.
final boolean isEnabled;
synchronized (mLock) {
isEnabled = mIsEnabled;
}
// Listeners are a final CopyOnWriteArrayList, hence no lock needed.
for (AccessibilityStateChangeListener listener :mAccessibilityStateChangeListeners) {
listener.onAccessibilityStateChanged(isEnabled);
}
|
private void | handleNotifyHighTextContrastStateChanged()Notifies the registered {@link HighTextContrastChangeListener}s.
final boolean isHighTextContrastEnabled;
synchronized (mLock) {
isHighTextContrastEnabled = mIsHighTextContrastEnabled;
}
// Listeners are a final CopyOnWriteArrayList, hence no lock needed.
for (HighTextContrastChangeListener listener : mHighTextContrastStateChangeListeners) {
listener.onHighTextContrastStateChanged(isHighTextContrastEnabled);
}
|
private void | handleNotifyTouchExplorationStateChanged()Notifies the registered {@link TouchExplorationStateChangeListener}s.
final boolean isTouchExplorationEnabled;
synchronized (mLock) {
isTouchExplorationEnabled = mIsTouchExplorationEnabled;
}
// Listeners are a final CopyOnWriteArrayList, hence no lock needed.
for (TouchExplorationStateChangeListener listener :mTouchExplorationStateChangeListeners) {
listener.onTouchExplorationStateChanged(isTouchExplorationEnabled);
}
|
public void | interrupt()Requests feedback interruption from all accessibility services.
final IAccessibilityManager service;
final int userId;
synchronized (mLock) {
service = getServiceLocked();
if (service == null) {
return;
}
if (!mIsEnabled) {
throw new IllegalStateException("Accessibility off. Did you forget to check that?");
}
userId = mUserId;
}
try {
service.interrupt(userId);
if (DEBUG) {
Log.i(LOG_TAG, "Requested interrupt from all services");
}
} catch (RemoteException re) {
Log.e(LOG_TAG, "Error while requesting interrupt from all services. ", re);
}
|
public boolean | isEnabled()Returns if the accessibility in the system is enabled.
synchronized (mLock) {
IAccessibilityManager service = getServiceLocked();
if (service == null) {
return false;
}
return mIsEnabled;
}
|
public boolean | isHighTextContrastEnabled()Returns if the high text contrast in the system is enabled.
Note: You need to query this only if you application is
doing its own rendering and does not rely on the platform rendering pipeline.
synchronized (mLock) {
IAccessibilityManager service = getServiceLocked();
if (service == null) {
return false;
}
return mIsHighTextContrastEnabled;
}
|
public boolean | isTouchExplorationEnabled()Returns if the touch exploration in the system is enabled.
synchronized (mLock) {
IAccessibilityManager service = getServiceLocked();
if (service == null) {
return false;
}
return mIsTouchExplorationEnabled;
}
|
public void | removeAccessibilityInteractionConnection(android.view.IWindow windowToken)Removed an accessibility interaction connection interface for a given window.
final IAccessibilityManager service;
synchronized (mLock) {
service = getServiceLocked();
if (service == null) {
return;
}
}
try {
service.removeAccessibilityInteractionConnection(windowToken);
} catch (RemoteException re) {
Log.e(LOG_TAG, "Error while removing an accessibility interaction connection. ", re);
}
|
public boolean | removeAccessibilityStateChangeListener(android.view.accessibility.AccessibilityManager$AccessibilityStateChangeListener listener)Unregisters an {@link AccessibilityStateChangeListener}.
// Final CopyOnWriteArrayList - no lock needed.
return mAccessibilityStateChangeListeners.remove(listener);
|
public boolean | removeHighTextContrastStateChangeListener(android.view.accessibility.AccessibilityManager$HighTextContrastChangeListener listener)Unregisters a {@link HighTextContrastChangeListener}.
// Final CopyOnWriteArrayList - no lock needed.
return mHighTextContrastStateChangeListeners.remove(listener);
|
public boolean | removeTouchExplorationStateChangeListener(android.view.accessibility.AccessibilityManager$TouchExplorationStateChangeListener listener)Unregisters a {@link TouchExplorationStateChangeListener}.
// Final CopyOnWriteArrayList - no lock needed.
return mTouchExplorationStateChangeListeners.remove(listener);
|
public void | sendAccessibilityEvent(AccessibilityEvent event)Sends an {@link AccessibilityEvent}.
final IAccessibilityManager service;
final int userId;
synchronized (mLock) {
service = getServiceLocked();
if (service == null) {
return;
}
if (!mIsEnabled) {
throw new IllegalStateException("Accessibility off. Did you forget to check that?");
}
userId = mUserId;
}
boolean doRecycle = false;
try {
event.setEventTime(SystemClock.uptimeMillis());
// it is possible that this manager is in the same process as the service but
// client using it is called through Binder from another process. Example: MMS
// app adds a SMS notification and the NotificationManagerService calls this method
long identityToken = Binder.clearCallingIdentity();
doRecycle = service.sendAccessibilityEvent(event, userId);
Binder.restoreCallingIdentity(identityToken);
if (DEBUG) {
Log.i(LOG_TAG, event + " sent");
}
} catch (RemoteException re) {
Log.e(LOG_TAG, "Error during sending " + event + " ", re);
} finally {
if (doRecycle) {
event.recycle();
}
}
|
private void | setStateLocked(int stateFlags)Sets the current state and notifies listeners, if necessary.
final boolean enabled = (stateFlags & STATE_FLAG_ACCESSIBILITY_ENABLED) != 0;
final boolean touchExplorationEnabled =
(stateFlags & STATE_FLAG_TOUCH_EXPLORATION_ENABLED) != 0;
final boolean highTextContrastEnabled =
(stateFlags & STATE_FLAG_HIGH_TEXT_CONTRAST_ENABLED) != 0;
final boolean wasEnabled = mIsEnabled;
final boolean wasTouchExplorationEnabled = mIsTouchExplorationEnabled;
final boolean wasHighTextContrastEnabled = mIsHighTextContrastEnabled;
// Ensure listeners get current state from isZzzEnabled() calls.
mIsEnabled = enabled;
mIsTouchExplorationEnabled = touchExplorationEnabled;
mIsHighTextContrastEnabled = highTextContrastEnabled;
if (wasEnabled != enabled) {
mHandler.sendEmptyMessage(MyHandler.MSG_NOTIFY_ACCESSIBILITY_STATE_CHANGED);
}
if (wasTouchExplorationEnabled != touchExplorationEnabled) {
mHandler.sendEmptyMessage(MyHandler.MSG_NOTIFY_EXPLORATION_STATE_CHANGED);
}
if (wasHighTextContrastEnabled != highTextContrastEnabled) {
mHandler.sendEmptyMessage(MyHandler.MSG_NOTIFY_HIGH_TEXT_CONTRAST_STATE_CHANGED);
}
|
private void | tryConnectToServiceLocked()
IBinder iBinder = ServiceManager.getService(Context.ACCESSIBILITY_SERVICE);
if (iBinder == null) {
return;
}
IAccessibilityManager service = IAccessibilityManager.Stub.asInterface(iBinder);
try {
final int stateFlags = service.addClient(mClient, mUserId);
setStateLocked(stateFlags);
mService = service;
} catch (RemoteException re) {
Log.e(LOG_TAG, "AccessibilityManagerService is dead", re);
}
|