Bug: 328779485

Clone this repo:
  1. 6e33fc8 Upgrade accessibility-test-framework to c65cab02b2a845c29c3da100d6adefd345a144e3 am: 00e9b06337 by Sadaf Ebrahimi · 4 months ago main
  2. 00e9b06 Upgrade accessibility-test-framework to c65cab02b2a845c29c3da100d6adefd345a144e3 by Sadaf Ebrahimi · 4 months ago
  3. 2555c82 Empty merge ab/12770256 into aosp-main-future by Xin Li · 4 months ago
  4. a0ebd65 [automerger skipped] Merge 24Q4 into AOSP main am: 8f3789514e -s ours by Xin Li · 5 months ago
  5. 8f37895 Merge 24Q4 into AOSP main by Xin Li · 5 months ago simpleperf-release

Accessibility Test Framework for Android

To help people with disabilities access Android apps, developers of those apps need to consider how their apps will be presented to accessibility services. Some good practices can be checked by automated tools, such as if a View has a contentDescription. Other rules require human judgment, such as whether or not a contentDescription makes sense to all users.

For more information about Mobile Accessibility, see http://www.w3.org/WAI/mobile/.

This library collects various accessibility-related checks on View objects as well as AccessibilityNodeInfo objects (which the Android framework derives from Views and sends to AccessibilityServices).

Building the Library

The supplied gradle wrapper and build.gradle file can be used to build the Accessibility Test Framework or import the project into Android Studio.

$ ./gradlew build

Sample Usage

Given a view, the following code runs all accessibility checks on all views in the hierarchy rooted at that view and throws an exception if any errors are found:

ImmutableSet<AccessibilityHierarchyCheck> checks =
    AccessibilityCheckPreset.getAccessibilityHierarchyChecksForPreset(
        AccessibilityCheckPreset.LATEST);
AccessibilityHierarchyAndroid hierarchy = AccessibilityHierarchyAndroid.newBuilder(view).build();
List<AccessibilityHierarchyCheckResult> results = new ArrayList<>();
for (AccessibilityHierarchyCheck check : checks) {
  results.addAll(check.runCheckOnHierarchy(hierarchy));
}
List<AccessibilityHierarchyCheckResult> errors =
    AccessibilityCheckResultUtils.getResultsForType(
        results, AccessibilityCheckResultType.ERROR);
if (!errors.isEmpty()) {
  throw new RuntimeException(errors.get(0).getMessage().toString());
}