question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Testing Android Accessibility Services

See original GitHub issue

I’m trying to find a way to test Accessibility Services on Android (4.4) but I don’t get it working.

As a proof-of-concept I’m trying to test a simple accessiblity service that logs notifications.

I have been able to narrow down the issue to the UiAutomator. Everything works fine as long as I’m not using the UiAutomator, but as soon as the UiAutomator is involved the Accessibility Services are destroyed (see dumpsys and uiautomator outputs below). The Service are not disabled but simply destroyed i.e. they are still “on” according to the “Settings / Accessibility” i.e. to re-enable them I need to disable them first and then enable them.

The same happens if I’m starting an App via Appium, except that the dumpsys accessiblity fails when executed when the Appium Session is open.

Is this something that could/should be managed by the Appium Bootstrap i.e. keep the accessibility services enabled (or re-enable them)?

outputs with appium before opening the session

> adb shell dumpsys accessibility
ACCESSIBILITY MANAGER (dumpsys accessibility)

User state[attributes:{id=0, currentUser=true, accessibilityEnabled=true, touchExplorationEnabled=false, displayMagnificationEnabled=false}
           services:{Service[label=Toaster, feedbackType[FEEDBACK_GENERIC], capabilities=0, eventTypes=TYPE_NOTIFICATION_STATE_CHANGED, notificationTimeout=0]}]


[14.04.2015 16:09:29 C:\\]

during open session

> adb shell dumpsys accessibility
ACCESSIBILITY MANAGER (dumpsys accessibility)

User state[attributes:{id=0, currentUser=true, accessibilityEnabled=true, touchExplorationEnabled=false, displayMagnificationEnabled=false,
Exception occurred while dumping:
java.lang.NullPointerException
        at com.android.server.accessibility.AccessibilityManagerService$Service.dump(AccessibilityManagerService.java:2216)
        at com.android.server.accessibility.AccessibilityManagerService.dump(AccessibilityManagerService.java:1510)
        at android.os.Binder.dump(Binder.java:300)
        at android.os.Binder.onTransact(Binder.java:266)
        at android.view.accessibility.IAccessibilityManager$Stub.onTransact(IAccessibilityManager.java:178)
        at android.os.Binder.execTransact(Binder.java:404)
        at dalvik.system.NativeStart.run(Native Method)

[14.04.2015 16:09:47 C:\\]

after closing the session

> adb shell dumpsys accessibility
ACCESSIBILITY MANAGER (dumpsys accessibility)

User state[attributes:{id=0, currentUser=true, accessibilityEnabled=true, touchExplorationEnabled=false, displayMagnificationEnabled=false}
           services:{}]


[14.04.2015 16:10:00 C:\\]

outputs without appium

[14.04.2015 15:52:15 C:\\]
> adb shell dumpsys accessibility
ACCESSIBILITY MANAGER (dumpsys accessibility)

User state[attributes:{id=0, currentUser=true, accessibilityEnabled=true, touchExplorationEnabled=false, displayMagnificationEnabled=false}
           services:{Service[label=Toaster, feedbackType[FEEDBACK_GENERIC], capabilities=0, eventTypes=TYPE_NOTIFICATION_STATE_CHANGED, notificationTimeout=0]}]


[14.04.2015 15:53:11 C:\\]
> adb shell uiautomator dump --compressed
UI hierchary dumped to: /storage/emulated/0/window_dump.xml

[14.04.2015 15:53:35 C:\\]
> adb shell dumpsys accessibility
ACCESSIBILITY MANAGER (dumpsys accessibility)

User state[attributes:{id=0, currentUser=true, accessibilityEnabled=true, touchExplorationEnabled=false, displayMagnificationEnabled=false}
           services:{}]


[14.04.2015 15:53:37 C:\\]
> adb shell dumpsys accessibility
ACCESSIBILITY MANAGER (dumpsys accessibility)

User state[attributes:{id=0, currentUser=true, accessibilityEnabled=true, touchExplorationEnabled=false, displayMagnificationEnabled=false}
           services:{Service[label=Toaster, feedbackType[FEEDBACK_GENERIC], capabilities=0, eventTypes=TYPE_NOTIFICATION_STATE_CHANGED, notificationTimeout=0]}]


[14.04.2015 15:54:17 C:\\]
> adb shell uiautomator dump
UI hierchary dumped to: /storage/emulated/0/window_dump.xml

[14.04.2015 15:54:27 C:\\]
> adb shell dumpsys accessibility
ACCESSIBILITY MANAGER (dumpsys accessibility)

User state[attributes:{id=0, currentUser=true, accessibilityEnabled=true, touchExplorationEnabled=false, displayMagnificationEnabled=false}
           services:{}]

[14.04.2015 15:54:31 C:\\]

If this a Android Platform thing (= UiAutomator bug or “feature”) any other ideas how this could be done?

PS. The same issue seems to be on Android 4.3 (no workarounds in these threads either) https://groups.google.com/forum/#!msg/adt-dev/-9cyoNlRTh4/vzN0QyUwTVoJ http://stackoverflow.com/questions/20341440/accessibilityservice-is-destroyed-when-uiautomator-is-run

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:32 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
maxblumentalcommented, Jul 19, 2018

@sravanmedarapu Could you please provide a little bit more details about the held resources in terms of code? I am confused. We can run simultaneously several AccessibilityServices but running just one UiAutomation in the system causes all AccessibilityServices to suspend.

By the way, I found out that you can run UiAutomation along with AccessibilityServices if you uses a special flag:

int flags = UiAutomation.FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES;
UiAutomation mUiAutomation = 
    InstrumentationRegistry.getInstrumentation().getUiAutomation(flags);

If you obtain UiAutomation in this way, you’ll be able to run your tests without suspending AccessibilityServices.

2reactions
vivek978commented, Mar 11, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

Automated Accessibility Testing using Espresso
Manual testing using Android's built-in accessibility services to ensure that your app works end-to-end for users with accessibility needs ...
Read more >
Create your own accessibility service - Android Developers
An accessibility service is an application that provides user interface enhancements to assist users with disabilities, or who may temporarily ...
Read more >
How to Perform Accessibility Testing on Android Devices
In part 1 of this series, we will explore accessibility testing for mobile applications and websites using Android devices.
Read more >
3 accessibility testing tools for Android - Medium
Google, Deque Systems, and Microsoft provide tools for testing accessibility in your Android app. Here's an opinionated look.
Read more >
Accessibility Testing Checklist | Android Developers
Audible accessibility feedback features on Android devices provide audio prompts that speaks the screen content as you move around an application. By enabling ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found