AccessibilityService is Destroyed when uiautomator is run

2.1k views Asked by At

I am new to android and I am trying to explore the AccessibilityService. I have extended the AccessibilityService class, which gets the AccessibilityEvents and I am able to use the events.

I see a problem when I run "uiautomator dump". My AccessibilityService gets destroyed and I do not get any Accessibility Events. Is there a way to work around this problem?

Any help or suggestion appreciated. Thank you very much in advance.

The stack trace is attached below:

W/System.err( 3832):    at com.example.myservice.MyAccessibilityService.onUnbind(MyAccessibilityService.java:185)
W/System.err( 3832):    at android.app.ActivityThread.handleUnbindService(ActivityThread.java:2629)
W/System.err( 3832):    at android.app.ActivityThread.access$1800(ActivityThread.java:141)
W/System.err( 3832):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1348)
W/System.err( 3832):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 3832):    at android.os.Looper.loop(Looper.java:137)
W/System.err( 3832):    at android.app.ActivityThread.main(ActivityThread.java:5103)
W/System.err( 3832):    at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 3832):    at java.lang.reflect.Method.invoke(Method.java:525)
W/System.err( 3832):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
W/System.err( 3832):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
W/System.err( 3832):    at dalvik.system.NativeStart.main(Native Method)
4

There are 4 answers

1
Inês On

UiAutomator can't be used along with an AccessibilityService. When you turn on the service the uiAutomator will crash.

However, as UiAutomator 2.0 is based on instrumentation you will probably be able to access the information you need without the service.

1
Shailaja Parida On

Please try with uiautomator2 having version above 18 and make disable supress accessibility service flag as true, which ll run accessibility service as well as driver seamlessly without terminating.

0
Xiao On

You could switch to UiAutmator2 with following code from appium-uiautomator2-server:

    private void setAccessibilityServiceState() {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
            return;
        }
        Configurator.getInstance().setUiAutomationFlags(
            UiAutomation.FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES);
        } else {
            // We can disable UiAutomation.FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES
            // only when we set the value as zero
            Configurator.getInstance().setUiAutomationFlags(0);
        }
    }
0
programmer dreamer On

I faced the same problem & just found out the solution from here.

The answer was written in Kotlin so I modified mine here as I am writing in Java:

 int flags = UiAutomation.FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES;
 Configurator.getInstance().setUiAutomationFlags(flags);

 mDevice = UiDevice.getInstance(getInstrumentation());