Are UiAutomator and AccessibilityServices not compatible?

早过忘川 提交于 2019-12-11 12:38:55

问题


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.


回答1:


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




回答2:


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());



回答3:


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



来源:https://stackoverflow.com/questions/29035320/are-uiautomator-and-accessibilityservices-not-compatible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!