AccessibilityServiceInfopublic class AccessibilityServiceInfo extends Object implements android.os.ParcelableThis class describes an {@link AccessibilityService}. The system notifies an
{@link AccessibilityService} for {@link android.view.accessibility.AccessibilityEvent}s
according to the information encapsulated in this class.
Developer Guides
For more information about creating AccessibilityServices, read the
Accessibility
developer guide.
|
Fields Summary |
---|
private static final String | TAG_ACCESSIBILITY_SERVICE | public static final int | CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENTCapability: This accessibility service can retrieve the active window content. | public static final int | CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATIONCapability: This accessibility service can request touch exploration mode in which
touched items are spoken aloud and the UI can be explored via gestures. | public static final int | CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITYCapability: This accessibility service can request enhanced web accessibility
enhancements. For example, installing scripts to make app content more accessible. | public static final int | CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTSCapability: This accessibility service can request to filter the key event stream. | private static final android.util.SparseArray | sAvailableCapabilityInfos | public static final int | FEEDBACK_SPOKENDenotes spoken feedback. | public static final int | FEEDBACK_HAPTICDenotes haptic feedback. | public static final int | FEEDBACK_AUDIBLEDenotes audible (not spoken) feedback. | public static final int | FEEDBACK_VISUALDenotes visual feedback. | public static final int | FEEDBACK_GENERICDenotes generic feedback. | public static final int | FEEDBACK_BRAILLEDenotes braille feedback. | public static final int | FEEDBACK_ALL_MASKMask for all feedback types. | public static final int | DEFAULTIf an {@link AccessibilityService} is the default for a given type.
Default service is invoked only if no package specific one exists. In case of
more than one package specific service only the earlier registered is notified. | public static final int | FLAG_INCLUDE_NOT_IMPORTANT_VIEWSIf 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
{@link View#IMPORTANT_FOR_ACCESSIBILITY_NO} or
{@link View#IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS} and views that are
marked as potentially important for accessibility via
{@link View#IMPORTANT_FOR_ACCESSIBILITY_AUTO} for which the system has determined
that are not important for accessibility, are reported while querying the window
content and also the accessibility service will receive accessibility events from
them.
Note: For accessibility services targeting API version
{@link Build.VERSION_CODES#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
{@link Build.VERSION_CODES#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.
| public static final int | FLAG_REQUEST_TOUCH_EXPLORATION_MODEThis 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
{@link Build.VERSION_CODES#JELLY_BEAN_MR1} that want to set
this flag have to declare this capability in their meta-data by setting
the attribute {@link android.R.attr#canRequestTouchExplorationMode
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
{@link Build.VERSION_CODES#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 static final int | FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITYThis flag requests from the system to enable web accessibility enhancing
extensions. Such extensions aim to provide improved accessibility support
for content presented in a {@link 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 {@link android.R.attr
#canRequestEnhancedWebAccessibility 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}.
| public static final int | FLAG_REPORT_VIEW_IDSThis flag requests that the {@link AccessibilityNodeInfo}s obtained
by an {@link 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. | public static final int | FLAG_REQUEST_FILTER_KEY_EVENTSThis 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 {@link android.R.attr
#canRequestFilterKeyEvents 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}.
| public static final int | FLAG_RETRIEVE_INTERACTIVE_WINDOWSThis flag indicates to the system that the accessibility service wants
to access content of all interactive windows. An interactive window is a
window that has input focus or can be touched by a sighted user when explore
by touch is not enabled. If this flag is not set your service will not receive
{@link android.view.accessibility.AccessibilityEvent#TYPE_WINDOWS_CHANGED}
events, calling AccessibilityService{@link AccessibilityService#getWindows()
AccessibilityService.getWindows()} will return an empty list, and {@link
AccessibilityNodeInfo#getWindow() AccessibilityNodeInfo.getWindow()} will
return null.
Services that want to set this flag have to declare the capability
to retrieve window content in their meta-data by setting the attribute
{@link android.R.attr#canRetrieveWindowContent canRetrieveWindowContent} 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}.
| public int | eventTypesThe event types an {@link AccessibilityService} is interested in.
Can be dynamically set at runtime.
| public String[] | packageNamesThe package names an {@link AccessibilityService} is interested in. Setting
to null is equivalent to all packages.
Can be dynamically set at runtime.
| public int | feedbackTypeThe feedback type an {@link AccessibilityService} provides.
Can be dynamically set at runtime.
| public long | notificationTimeoutThe timeout after the most recent event of a given type before an
{@link AccessibilityService} is notified.
Can be dynamically set at runtime..
Note: The event notification timeout is useful to avoid propagating
events to the client too frequently since this is accomplished via an expensive
interprocess call. One can think of the timeout as a criteria to determine when
event generation has settled down. | public int | flagsThis field represents a set of flags used for configuring an
{@link AccessibilityService}.
Can be dynamically set at runtime.
| private String | mIdThe unique string Id to identify the accessibility service. | private android.content.pm.ResolveInfo | mResolveInfoThe Service that implements this accessibility service component. | private String | mSettingsActivityNameThe accessibility service setting activity's name, used by the system
settings to launch the setting activity of this accessibility service. | private int | mCapabilitiesBit mask with capabilities of this service. | private int | mDescriptionResIdResource id of the description of the accessibility service. | private String | mNonLocalizedDescriptionNon localized description of the accessibility service. | public static final Parcelable.Creator | CREATOR |
Constructors Summary |
---|
public AccessibilityServiceInfo()Creates a new instance.
/* do nothing */
| public AccessibilityServiceInfo(android.content.pm.ResolveInfo resolveInfo, android.content.Context context)Creates a new instance.
ServiceInfo serviceInfo = resolveInfo.serviceInfo;
mId = new ComponentName(serviceInfo.packageName, serviceInfo.name).flattenToShortString();
mResolveInfo = resolveInfo;
XmlResourceParser parser = null;
try {
PackageManager packageManager = context.getPackageManager();
parser = serviceInfo.loadXmlMetaData(packageManager,
AccessibilityService.SERVICE_META_DATA);
if (parser == null) {
return;
}
int type = 0;
while (type != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
type = parser.next();
}
String nodeName = parser.getName();
if (!TAG_ACCESSIBILITY_SERVICE.equals(nodeName)) {
throw new XmlPullParserException( "Meta-data does not start with"
+ TAG_ACCESSIBILITY_SERVICE + " tag");
}
AttributeSet allAttributes = Xml.asAttributeSet(parser);
Resources resources = packageManager.getResourcesForApplication(
serviceInfo.applicationInfo);
TypedArray asAttributes = resources.obtainAttributes(allAttributes,
com.android.internal.R.styleable.AccessibilityService);
eventTypes = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_accessibilityEventTypes,
0);
String packageNamez = asAttributes.getString(
com.android.internal.R.styleable.AccessibilityService_packageNames);
if (packageNamez != null) {
packageNames = packageNamez.split("(\\s)*,(\\s)*");
}
feedbackType = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_accessibilityFeedbackType,
0);
notificationTimeout = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_notificationTimeout,
0);
flags = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_accessibilityFlags, 0);
mSettingsActivityName = asAttributes.getString(
com.android.internal.R.styleable.AccessibilityService_settingsActivity);
if (asAttributes.getBoolean(com.android.internal.R.styleable
.AccessibilityService_canRetrieveWindowContent, false)) {
mCapabilities |= CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT;
}
if (asAttributes.getBoolean(com.android.internal.R.styleable
.AccessibilityService_canRequestTouchExplorationMode, false)) {
mCapabilities |= CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION;
}
if (asAttributes.getBoolean(com.android.internal.R.styleable
.AccessibilityService_canRequestEnhancedWebAccessibility, false)) {
mCapabilities |= CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY;
}
if (asAttributes.getBoolean(com.android.internal.R.styleable
.AccessibilityService_canRequestFilterKeyEvents, false)) {
mCapabilities |= CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS;
}
TypedValue peekedValue = asAttributes.peekValue(
com.android.internal.R.styleable.AccessibilityService_description);
if (peekedValue != null) {
mDescriptionResId = peekedValue.resourceId;
CharSequence nonLocalizedDescription = peekedValue.coerceToString();
if (nonLocalizedDescription != null) {
mNonLocalizedDescription = nonLocalizedDescription.toString().trim();
}
}
asAttributes.recycle();
} catch (NameNotFoundException e) {
throw new XmlPullParserException( "Unable to create context for: "
+ serviceInfo.packageName);
} finally {
if (parser != null) {
parser.close();
}
}
|
Methods Summary |
---|
private static void | appendCapabilities(java.lang.StringBuilder stringBuilder, int capabilities)
stringBuilder.append("capabilities:");
stringBuilder.append("[");
while (capabilities != 0) {
final int capabilityBit = (1 << Integer.numberOfTrailingZeros(capabilities));
stringBuilder.append(capabilityToString(capabilityBit));
capabilities &= ~capabilityBit;
if (capabilities != 0) {
stringBuilder.append(", ");
}
}
stringBuilder.append("]");
| private static void | appendEventTypes(java.lang.StringBuilder stringBuilder, int eventTypes)
stringBuilder.append("eventTypes:");
stringBuilder.append("[");
while (eventTypes != 0) {
final int eventTypeBit = (1 << Integer.numberOfTrailingZeros(eventTypes));
stringBuilder.append(AccessibilityEvent.eventTypeToString(eventTypeBit));
eventTypes &= ~eventTypeBit;
if (eventTypes != 0) {
stringBuilder.append(", ");
}
}
stringBuilder.append("]");
| private static void | appendFeedbackTypes(java.lang.StringBuilder stringBuilder, int feedbackTypes)
stringBuilder.append("feedbackTypes:");
stringBuilder.append("[");
while (feedbackTypes != 0) {
final int feedbackTypeBit = (1 << Integer.numberOfTrailingZeros(feedbackTypes));
stringBuilder.append(feedbackTypeToString(feedbackTypeBit));
feedbackTypes &= ~feedbackTypeBit;
if (feedbackTypes != 0) {
stringBuilder.append(", ");
}
}
stringBuilder.append("]");
| private static void | appendFlags(java.lang.StringBuilder stringBuilder, int flags)
stringBuilder.append("flags:");
stringBuilder.append("[");
while (flags != 0) {
final int flagBit = (1 << Integer.numberOfTrailingZeros(flags));
stringBuilder.append(flagToString(flagBit));
flags &= ~flagBit;
if (flags != 0) {
stringBuilder.append(", ");
}
}
stringBuilder.append("]");
| private static void | appendPackageNames(java.lang.StringBuilder stringBuilder, java.lang.String[] packageNames)
stringBuilder.append("packageNames:");
stringBuilder.append("[");
if (packageNames != null) {
final int packageNameCount = packageNames.length;
for (int i = 0; i < packageNameCount; i++) {
stringBuilder.append(packageNames[i]);
if (i < packageNameCount - 1) {
stringBuilder.append(", ");
}
}
}
stringBuilder.append("]");
| public static java.lang.String | capabilityToString(int capability)Returns the string representation of a capability. For example,
{@link #CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT} is represented
by the string CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT.
switch (capability) {
case CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT:
return "CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT";
case CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION:
return "CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION";
case CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY:
return "CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY";
case CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS:
return "CAPABILITY_CAN_FILTER_KEY_EVENTS";
default:
return "UNKNOWN";
}
| public int | describeContents(){@inheritDoc}
return 0;
| public boolean | equals(java.lang.Object obj)
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
AccessibilityServiceInfo other = (AccessibilityServiceInfo) obj;
if (mId == null) {
if (other.mId != null) {
return false;
}
} else if (!mId.equals(other.mId)) {
return false;
}
return true;
| public static java.lang.String | feedbackTypeToString(int feedbackType)Returns the string representation of a feedback type. For example,
{@link #FEEDBACK_SPOKEN} is represented by the string FEEDBACK_SPOKEN.
StringBuilder builder = new StringBuilder();
builder.append("[");
while (feedbackType != 0) {
final int feedbackTypeFlag = 1 << Integer.numberOfTrailingZeros(feedbackType);
feedbackType &= ~feedbackTypeFlag;
switch (feedbackTypeFlag) {
case FEEDBACK_AUDIBLE:
if (builder.length() > 1) {
builder.append(", ");
}
builder.append("FEEDBACK_AUDIBLE");
break;
case FEEDBACK_HAPTIC:
if (builder.length() > 1) {
builder.append(", ");
}
builder.append("FEEDBACK_HAPTIC");
break;
case FEEDBACK_GENERIC:
if (builder.length() > 1) {
builder.append(", ");
}
builder.append("FEEDBACK_GENERIC");
break;
case FEEDBACK_SPOKEN:
if (builder.length() > 1) {
builder.append(", ");
}
builder.append("FEEDBACK_SPOKEN");
break;
case FEEDBACK_VISUAL:
if (builder.length() > 1) {
builder.append(", ");
}
builder.append("FEEDBACK_VISUAL");
break;
case FEEDBACK_BRAILLE:
if (builder.length() > 1) {
builder.append(", ");
}
builder.append("FEEDBACK_BRAILLE");
break;
}
}
builder.append("]");
return builder.toString();
| public static java.lang.String | flagToString(int flag)Returns the string representation of a flag. For example,
{@link #DEFAULT} is represented by the string DEFAULT.
switch (flag) {
case DEFAULT:
return "DEFAULT";
case FLAG_INCLUDE_NOT_IMPORTANT_VIEWS:
return "FLAG_INCLUDE_NOT_IMPORTANT_VIEWS";
case FLAG_REQUEST_TOUCH_EXPLORATION_MODE:
return "FLAG_REQUEST_TOUCH_EXPLORATION_MODE";
case FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY:
return "FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY";
case FLAG_REPORT_VIEW_IDS:
return "FLAG_REPORT_VIEW_IDS";
case FLAG_REQUEST_FILTER_KEY_EVENTS:
return "FLAG_REQUEST_FILTER_KEY_EVENTS";
case FLAG_RETRIEVE_INTERACTIVE_WINDOWS:
return "FLAG_RETRIEVE_INTERACTIVE_WINDOWS";
default:
return null;
}
| public boolean | getCanRetrieveWindowContent()Whether this service can retrieve the current window's content.
Statically set from
{@link AccessibilityService#SERVICE_META_DATA meta-data}.
return (mCapabilities & CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT) != 0;
| public int | getCapabilities()Returns the bit mask of capabilities this accessibility service has such as
being able to retrieve the active window content, etc.
return mCapabilities;
| public java.util.List | getCapabilityInfos()
if (mCapabilities == 0) {
return Collections.emptyList();
}
int capabilities = mCapabilities;
List<CapabilityInfo> capabilityInfos = new ArrayList<CapabilityInfo>();
while (capabilities != 0) {
final int capabilityBit = 1 << Integer.numberOfTrailingZeros(capabilities);
capabilities &= ~capabilityBit;
CapabilityInfo capabilityInfo = sAvailableCapabilityInfos.get(capabilityBit);
if (capabilityInfo != null) {
capabilityInfos.add(capabilityInfo);
}
}
return capabilityInfos;
| public java.lang.String | getDescription()Gets the non-localized description of the accessibility service.
Statically set from
{@link AccessibilityService#SERVICE_META_DATA meta-data}.
return mNonLocalizedDescription;
| public java.lang.String | getId()The accessibility service id.
Generated by the system.
return mId;
| public android.content.pm.ResolveInfo | getResolveInfo()The service {@link ResolveInfo}.
Generated by the system.
return mResolveInfo;
| public java.lang.String | getSettingsActivityName()The settings activity name.
Statically set from
{@link AccessibilityService#SERVICE_META_DATA meta-data}.
return mSettingsActivityName;
| public int | hashCode()
return 31 * 1 + ((mId == null) ? 0 : mId.hashCode());
| private void | initFromParcel(android.os.Parcel parcel)
eventTypes = parcel.readInt();
packageNames = parcel.readStringArray();
feedbackType = parcel.readInt();
notificationTimeout = parcel.readLong();
flags = parcel.readInt();
mId = parcel.readString();
mResolveInfo = parcel.readParcelable(null);
mSettingsActivityName = parcel.readString();
mCapabilities = parcel.readInt();
mDescriptionResId = parcel.readInt();
mNonLocalizedDescription = parcel.readString();
| public java.lang.String | loadDescription(android.content.pm.PackageManager packageManager)The localized description of the accessibility service.
Statically set from
{@link AccessibilityService#SERVICE_META_DATA meta-data}.
if (mDescriptionResId == 0) {
return mNonLocalizedDescription;
}
ServiceInfo serviceInfo = mResolveInfo.serviceInfo;
CharSequence description = packageManager.getText(serviceInfo.packageName,
mDescriptionResId, serviceInfo.applicationInfo);
if (description != null) {
return description.toString().trim();
}
return null;
| public void | setCapabilities(int capabilities)Sets the bit mask of capabilities this accessibility service has such as
being able to retrieve the active window content, etc.
mCapabilities = capabilities;
| public void | setComponentName(android.content.ComponentName component)
mId = component.flattenToShortString();
| public java.lang.String | toString()
StringBuilder stringBuilder = new StringBuilder();
appendEventTypes(stringBuilder, eventTypes);
stringBuilder.append(", ");
appendPackageNames(stringBuilder, packageNames);
stringBuilder.append(", ");
appendFeedbackTypes(stringBuilder, feedbackType);
stringBuilder.append(", ");
stringBuilder.append("notificationTimeout: ").append(notificationTimeout);
stringBuilder.append(", ");
appendFlags(stringBuilder, flags);
stringBuilder.append(", ");
stringBuilder.append("id: ").append(mId);
stringBuilder.append(", ");
stringBuilder.append("resolveInfo: ").append(mResolveInfo);
stringBuilder.append(", ");
stringBuilder.append("settingsActivityName: ").append(mSettingsActivityName);
stringBuilder.append(", ");
appendCapabilities(stringBuilder, mCapabilities);
return stringBuilder.toString();
| public void | updateDynamicallyConfigurableProperties(android.accessibilityservice.AccessibilityServiceInfo other)Updates the properties that an AccessibilitySerivice can change dynamically.
eventTypes = other.eventTypes;
packageNames = other.packageNames;
feedbackType = other.feedbackType;
notificationTimeout = other.notificationTimeout;
flags = other.flags;
| public void | writeToParcel(android.os.Parcel parcel, int flagz)
parcel.writeInt(eventTypes);
parcel.writeStringArray(packageNames);
parcel.writeInt(feedbackType);
parcel.writeLong(notificationTimeout);
parcel.writeInt(flags);
parcel.writeString(mId);
parcel.writeParcelable(mResolveInfo, 0);
parcel.writeString(mSettingsActivityName);
parcel.writeInt(mCapabilities);
parcel.writeInt(mDescriptionResId);
parcel.writeString(mNonLocalizedDescription);
|
|