每当我尝试使用 UiAutomation
在通过 getInstrumentation().getUiAutomation()
进行的任何测试中,进程崩溃并出现以下异常:
java.lang.SecurityException: Permission Denial: getIntentSender() from pid=30334, uid=2000, (need uid=1000) is not allowed to send as package android
at android.os.Parcel.readException(Parcel.java:1540)
at android.os.Parcel.readException(Parcel.java:1493)
at android.app.IUiAutomationConnection$Stub$Proxy.disconnect(IUiAutomationConnection.java:225)
at android.app.UiAutomation.disconnect(UiAutomation.java:240)
at android.app.Instrumentation.finish(Instrumentation.java:197)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:575)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1837)
知道为什么吗?我通过 Android Studio 使用 Gradle,尝试了各种版本,直接通过 adb
调用它,即使没有任何外部依赖(显然至少有 SDK 18)......总是崩溃。
这是我找到的唯一官方示例:https://www.youtube.com/watch?v=_SlBHUW0ybM
最佳答案
这不是 UIAutomator 为何未捕获错误的答案,而是我发现的一种可能的解决方法。当可访问性服务打开时,我无法获取 UIAutomator 转储,因为我收到了您描述的错误。当我在辅助功能设置中关闭 TalkBack 和/或切换访问时,我不再收到权限拒绝错误并且 UIAutomator 转储成功运行。不确定这是否对您有帮助,但我每次都可以在 Lollipop (Nexus 5) 中启用无障碍服务来重现您的问题。
关于android - java.lang.SecurityException : Permission Denial: getIntentSender() when using UiAutomation in a test 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27132799/