xref: /aosp_15_r20/external/accessibility-test-framework/README.md (revision 24652f07b1b5a5b18a8d655a3a5543bcf39b475e)
1# Accessibility Test Framework for Android
2
3To help people with disabilities access Android apps, developers of those apps
4need to consider how their apps will be presented to accessibility services.
5Some good practices can be checked by automated tools, such as if a View has a
6contentDescription. Other rules require human judgment, such as whether or not a
7contentDescription makes sense to all users.
8
9For more information about Mobile Accessibility, see
10http://www.w3.org/WAI/mobile/.
11
12This library collects various accessibility-related checks on View objects as
13well as AccessibilityNodeInfo objects (which the Android framework derives from
14Views and sends to AccessibilityServices).
15
16## Building the Library
17
18The supplied gradle wrapper and build.gradle file can be used to build the
19Accessibility Test Framework or import the project into Android Studio.
20
21```shell
22$ ./gradlew build
23```
24
25## Sample Usage
26
27Given a view, the following code runs all accessibility checks on all views in
28the hierarchy rooted at that view and throws an exception if any errors are
29found:
30
31```java
32ImmutableSet<AccessibilityHierarchyCheck> checks =
33    AccessibilityCheckPreset.getAccessibilityHierarchyChecksForPreset(
34        AccessibilityCheckPreset.LATEST);
35AccessibilityHierarchyAndroid hierarchy = AccessibilityHierarchyAndroid.newBuilder(view).build();
36List<AccessibilityHierarchyCheckResult> results = new ArrayList<>();
37for (AccessibilityHierarchyCheck check : checks) {
38  results.addAll(check.runCheckOnHierarchy(hierarchy));
39}
40List<AccessibilityHierarchyCheckResult> errors =
41    AccessibilityCheckResultUtils.getResultsForType(
42        results, AccessibilityCheckResultType.ERROR);
43if (!errors.isEmpty()) {
44  throw new RuntimeException(errors.get(0).getMessage().toString());
45}
46```
47