【问题标题】:Calling from not trusted UID从不受信任的 UID 调用
【发布时间】:2018-07-16 11:30:45
【问题描述】:

当我在 Android Studio 中运行 UIAutomator 时,有时会出现崩溃。

 W/ActivityManager: Crash of app com.example.testsample running instrumentation ComponentInfo{com.example.testsample.test/android.support.test.runner.AndroidJUnitRunner}
07-16 19:19:34.191 7834-7850/? W/Binder: Binder call failed.
java.lang.SecurityException: Calling from not trusted UID!
    at android.app.UiAutomationConnection.throwIfCalledByNotTrustedUidLocked(UiAutomationConnection.java:427)
    at android.app.UiAutomationConnection.shutdown(UiAutomationConnection.java:324)
    at android.app.IUiAutomationConnection$Stub.onTransact(IUiAutomationConnection.java:209)
    at android.os.Binder.execTransact(Binder.java:570)

但它并不是每次都显示。当这没有显示时,我可以成功运行。 谁能帮我? 谢谢。

【问题讨论】:

  • 我在另一台设备(HUAWEI Mate9)上试过同样的代码,效果很好。从不显示此错误。所以它可能只在特定设备中引起(对我来说是美图 T8)。
  • 运行时显示此错误。测试未能完成。原因:“由于“进程崩溃”,仪器运行失败。”。检查设备 logcat 了解详细信息测试运行失败:由于“进程崩溃”,检测运行失败。

标签: java android testing android-uiautomator


【解决方案1】:
private void throwIfCalledByNotTrustedUidLocked() {
    final int callingUid = Binder.getCallingUid();
    if (callingUid != mOwningUid && mOwningUid != Process.SYSTEM_UID
            && callingUid != 0 /*root*/) {
        throw new SecurityException("Calling from not trusted UID!");
    }
}

这是引发错误的方法。也许uid 与进程uid 不同,或者该设备上的uid 不是root。也许你可以在你的应用中添加一些打印来找出答案。

【讨论】:

  • 我在每个 UIAutomator 函数调用之前和之后添加日志。这个崩溃是随机显示的。不在特定的地方。
猜你喜欢
  • 1970-01-01
  • 2012-07-05
  • 2019-05-07
  • 2018-10-22
  • 2012-08-19
  • 1970-01-01
  • 2019-02-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多