Are UiAutomator and AccessibilityServices not comp

2019-09-05 15:46发布

I have an AccessibilityService (AS) running to programatically get information about what's currently displayed on the screen.

Now I want to set some UiAutomator test cases. However, if I have the AS running the UiAutomator gives the following error:

INSTRUMENTATION_RESULT: shortMsg=java.lang.SecurityException

INSTRUMENTATION_RESULT: longMsg=Permission Denial: getIntentSender() from pid=9700, uid=2000, (need uid=1000) is not allowed to send as package android

I've searched the web and I've found that lots of people have encountered this problem but no solution for it.

So is this a lack of compatibility issue or is there a way to solve it (or at least a work-around)?

Note: If you have other thoughts in how to read/access the contents of the screen without the AS I'm all ears (more eyes in this case...) but I've looked a lot for other solutions and this is the only one I got.

Thanks in advance.

If you need more information please tell me.

3条回答
看我几分像从前
2楼-- · 2019-09-05 15:58

This is an old question but I've figured I'd answer myself saying that they are indeed incompatible.

查看更多
甜甜的少女心
3楼-- · 2019-09-05 16:17

I had some success with this:

    val flags = UiAutomation.FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES
    Configurator.getInstance().uiAutomationFlags = flags

    mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

There are some more details on Configurator here:

https://developer.android.com/reference/androidx/test/uiautomator/Configurator.html

The following GitHub issue helped me find this:

https://github.com/appium/appium/issues/4910

查看更多
等我变得足够好
4楼-- · 2019-09-05 16:18

dazza500's solution works in Kotlin.

As in my case, 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());
查看更多
登录 后发表回答