AccessibilityServiceInfoCompat

Added in 1.1.0

public final class AccessibilityServiceInfoCompat


Helper for accessing features in AccessibilityServiceInfo.

Summary

Constants

static final int

Capability: This accessibility service can filter the key event stream.

static final int

Capability: This accessibility service can request enhanced web accessibility enhancements.

static final int

Capability: This accessibility service can request touch exploration mode in which touched items are spoken aloud and the UI can be explored via gestures.

static final int

Capability: This accessibility service can retrieve the active window content.

static final int

Mask for all feedback types.

static final int

Denotes braille feedback.

static final int

If this flag is set the system will regard views that are not important for accessibility in addition to the ones that are important for accessibility.

static final int

This flag requests that the AccessibilityNodeInfos obtained by an AccessibilityService contain the id of the source view.

static final int

This flag requests from the system to enable web accessibility enhancing extensions.

static final int

This flag requests from the system to filter key events.

static final int

This flag requests that the system gets into touch exploration mode.

Public methods

static @NonNull String
capabilityToString(int capability)

Returns the string representation of a capability.

static @NonNull String
feedbackTypeToString(int feedbackType)

Returns the string representation of a feedback type.

static @Nullable String
flagToString(int flag)

Returns the string representation of a flag.

static int
@ReplaceWith(expression = "info.getCapabilities()")
getCapabilities(@NonNull AccessibilityServiceInfo info)

This method is deprecated.

Call getCapabilities directly.

static @Nullable String
@ReplaceWith(expression = "info.loadDescription(packageManager)")
loadDescription(
    @NonNull AccessibilityServiceInfo info,
    @NonNull PackageManager packageManager
)

This method is deprecated.

Call loadDescription directly.

Constants

CAPABILITY_CAN_FILTER_KEY_EVENTS

Added in 1.1.0
public static final int CAPABILITY_CAN_FILTER_KEY_EVENTS = 8

Capability: This accessibility service can filter the key event stream.

CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY

Added in 1.1.0
public static final int CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY = 4

Capability: This accessibility service can request enhanced web accessibility enhancements. For example, installing scripts to make app content more accessible.

CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION

Added in 1.1.0
public static final int CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION = 2

Capability: This accessibility service can request touch exploration mode in which touched items are spoken aloud and the UI can be explored via gestures.

CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT

Added in 1.1.0
public static final int CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT = 1

Capability: This accessibility service can retrieve the active window content.

FEEDBACK_ALL_MASK

Added in 1.1.0
public static final int FEEDBACK_ALL_MASK = -1

Mask for all feedback types.

FEEDBACK_BRAILLE

Added in 1.1.0
public static final int FEEDBACK_BRAILLE = 32

Denotes braille feedback.

FLAG_INCLUDE_NOT_IMPORTANT_VIEWS

Added in 1.1.0
public static final int FLAG_INCLUDE_NOT_IMPORTANT_VIEWS = 2

If this flag is set the system will regard views that are not important for accessibility in addition to the ones that are important for accessibility. That is, views that are marked as not important for accessibility via IMPORTANT_FOR_ACCESSIBILITY_NO or IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS and views that are marked as potentially important for accessibility via IMPORTANT_FOR_ACCESSIBILITY_AUTO for which the system has determined that are not important for accessibility, are both reported while querying the window content and also the accessibility service will receive accessibility events from them.

Note: For accessibility services targeting API version JELLY_BEAN or higher this flag has to be explicitly set for the system to regard views that are not important for accessibility. For accessibility services targeting API version lower than JELLY_BEAN this flag is ignored and all views are regarded for accessibility purposes.

Usually views not important for accessibility are layout managers that do not react to user actions, do not draw any content, and do not have any special semantics in the context of the screen content. For example, a three by three grid can be implemented as three horizontal linear layouts and one vertical, or three vertical linear layouts and one horizontal, or one grid layout, etc. In this context the actual layout mangers used to achieve the grid configuration are not important, rather it is important that there are nine evenly distributed elements.

FLAG_REPORT_VIEW_IDS

Added in 1.1.0
public static final int FLAG_REPORT_VIEW_IDS = 16

This flag requests that the AccessibilityNodeInfos obtained by an AccessibilityService contain the id of the source view. The source view id will be a fully qualified resource name of the form "package:id/name", for example "foo.bar:id/my_list", and it is useful for UI test automation. This flag is not set by default.

FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY

Added in 1.1.0
public static final int FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY = 8

This flag requests from the system to enable web accessibility enhancing extensions. Such extensions aim to provide improved accessibility support for content presented in a android.webkit.WebView. An example of such an extension is injecting JavaScript from a secure source. The system will enable enhanced web accessibility if there is at least one accessibility service that has this flag set. Hence, clearing this flag does not guarantee that the device will not have enhanced web accessibility enabled since there may be another enabled service that requested it.

Services that want to set this flag have to declare this capability in their meta-data by setting the attribute canRequestEnhancedWebAccessibility to true, otherwise this flag will be ignored. For how to declare the meta-data of a service refer to {@value AccessibilityService#SERVICE_META_DATA}.

FLAG_REQUEST_FILTER_KEY_EVENTS

Added in 1.1.0
public static final int FLAG_REQUEST_FILTER_KEY_EVENTS = 32

This flag requests from the system to filter key events. If this flag is set the accessibility service will receive the key events before applications allowing it implement global shortcuts. Setting this flag does not guarantee that this service will filter key events since only one service can do so at any given time. This avoids user confusion due to behavior change in case different key filtering services are enabled. If there is already another key filtering service enabled, this one will not receive key events.

Services that want to set this flag have to declare this capability in their meta-data by setting the attribute canRequestFilterKeyEvents to true, otherwise this flag will be ignored. For how to declare the meta -data of a service refer to {@value AccessibilityService#SERVICE_META_DATA}.

FLAG_REQUEST_TOUCH_EXPLORATION_MODE

Added in 1.1.0
public static final int FLAG_REQUEST_TOUCH_EXPLORATION_MODE = 4

This flag requests that the system gets into touch exploration mode. In this mode a single finger moving on the screen behaves as a mouse pointer hovering over the user interface. The system will also detect certain gestures performed on the touch screen and notify this service. The system will enable touch exploration mode if there is at least one accessibility service that has this flag set. Hence, clearing this flag does not guarantee that the device will not be in touch exploration mode since there may be another enabled service that requested it.

For accessibility services targeting API version higher than JELLY_BEAN_MR1 that want to set this flag have to declare this capability in their meta-data by setting the attribute canRequestTouchExplorationMode to true, otherwise this flag will be ignored. For how to declare the meta-data of a service refer to {@value AccessibilityService#SERVICE_META_DATA}.

Services targeting API version equal to or lower than JELLY_BEAN_MR1 will work normally, i.e. the first time they are run, if this flag is specified, a dialog is shown to the user to confirm enabling explore by touch.

Public methods

capabilityToString

Added in 1.1.0
public static @NonNull String capabilityToString(int capability)

Returns the string representation of a capability. For example, CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT is represented by the string CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT.

Parameters
int capability

The capability.

Returns
@NonNull String

The string representation.

feedbackTypeToString

Added in 1.1.0
public static @NonNull String feedbackTypeToString(int feedbackType)

Returns the string representation of a feedback type. For example, FEEDBACK_SPOKEN is represented by the string FEEDBACK_SPOKEN.

Parameters
int feedbackType

The feedback type.

Returns
@NonNull String

The string representation.

flagToString

Added in 1.1.0
public static @Nullable String flagToString(int flag)

Returns the string representation of a flag. For example, DEFAULT is represented by the string DEFAULT.

Parameters
int flag

The flag.

Returns
@Nullable String

The string representation.

getCapabilities

Added in 1.1.0
Deprecated in 1.15.0-rc01
@ReplaceWith(expression = "info.getCapabilities()")
public static int getCapabilities(@NonNull AccessibilityServiceInfo info)

Returns the bit mask of capabilities this accessibility service has such as being able to retrieve the active window content, etc.

Parameters
@NonNull AccessibilityServiceInfo info

The service info whose capabilities to get.

Returns
int

The capability bit mask.

loadDescription

Added in 1.1.0
Deprecated in 1.15.0-rc01
@ReplaceWith(expression = "info.loadDescription(packageManager)")
public static @Nullable String loadDescription(
    @NonNull AccessibilityServiceInfo info,
    @NonNull PackageManager packageManager
)

The localized description of the accessibility service.

Statically set from meta-data.

Parameters
@NonNull AccessibilityServiceInfo info

The service info of interest

@NonNull PackageManager packageManager

The current package manager

Returns
@Nullable String

The localized description.