I'm seeing exceptions when ActivityManager.isUserAMonkey()
is run on older Android devices:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.AndroidApp}: java.lang.RuntimeException: Unknown exception code: 1 msg null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4914)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Unknown exception code: 1 msg null
at android.os.Parcel.readException(Parcel.java:1257)
at android.os.Parcel.readException(Parcel.java:1235)
at android.app.ActivityManagerProxy.isUserAMonkey(ActivityManagerNative.java:2762)
at android.app.ActivityManager.isUserAMonkey(ActivityManager.java:990)
at <com.myapp....> ...
There is a bit of discussion of the bug here (including a classic thats-not-possible response from one of the developers: "In the standard platform implementation this is pretty much not possible.")
https://groups.google.com/forum/?fromgroups=#!topic/android-developers/tQJcM4O4WxM
Its not clear to me if this always happens, or only happens when running under a test monkey, or only on some devices or what. (I'm running into this problem using Apkudo's device testing service, where the user is always a monkey.) Its not clear when this was fixed, either (it doesn't happen on most (all?) newer devices).