UiAutomator 和 AccessibilityServices 不兼容吗?

Are UiAutomator and AccessibilityServices not compatible?

我有一个 AccessibilityService (AS) 运行 以编程方式获取有关屏幕上当前显示内容的信息。

现在我想设置一些UiAutomator 测试用例。但是,如果我有 AS 运行,UiAutomator 会给出以下错误:

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

我在网上搜索了一下,发现很多人都遇到过这个问题,但都没有解决办法。

这是缺乏兼容性的问题还是有办法解决(或至少有变通办法)?

注意:如果您对如何 read/access 没有 AS 的屏幕内容有其他想法,我洗耳恭听(在这种情况下更多的眼睛......)但我已经看了很多对于其他解决方案,这是我唯一得到的解决方案。

提前致谢。

如果您需要更多信息,请告诉我。

这是一个老问题,但我想我会回答自己说它们确实不兼容。

我在这方面取得了一些成功:

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

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

此处有更多关于配置器的详细信息:

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

以下 GitHub 问题帮助我找到了这个:

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

dazza500 的解决方案适用于 Kotlin.

就像我的情况一样,我在 Java:

中修改了我的
 int flags = UiAutomation.FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES;
 Configurator.getInstance().setUiAutomationFlags(flags);

 mDevice = UiDevice.getInstance(getInstrumentation());