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