java.lang.SecurityException: Permission Denial: getIntentSender() when using UiAutomation in a test

浪尽此生 提交于 2019-12-21 03:42:15

问题


Whenever I try to use UiAutomation in any test through getInstrumentation().getUiAutomation(), the process crashes with this exception:

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)

Any idea why? I'm using Gradle through Android Studio, tried various versions, calling it directly through adb, even without any external dependency (and obviously with at least SDK 18)... Always crashing.

This is the only official example I've found: https://www.youtube.com/watch?v=_SlBHUW0ybM


回答1:


This isn't an answer for why UIAutomator isn't catching the error, but rather a possible workaround that I found. When accessibility services are on I am unable to get an UIAutomator dump because I receive the error you described. When I turn off TalkBack and/or Switch Access in the Accessibility settings I no longer get the Permission Denial error and UIAutomator dump works successfully. Not sure if this will help you, but I can reproduce your issue every time with accessibility services ON in Lollipop(Nexus 5).




回答2:


Use InstrumentationRegistry.getTargetContext() instead of InstrumentationRegistry.getContext()



来源:https://stackoverflow.com/questions/27132799/java-lang-securityexception-permission-denial-getintentsender-when-using-uia

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