我在我的service中集成Monkey来对其他APP进行Monkey测试,每次总是报如下错误:
10-13 09:16:24.682: INFO/System.out(274): :Monkey: seed=0 count=500...
10-13 09:16:24.682: INFO/System.out(274): :Monkey: seed=0 count=500...
10-13 09:16:24.704: INFO/System.out(274): :AllowPackage: org.example.tabdemo...
10-13 09:16:24.712: INFO/System.out(274): AllowPackage: org.example.tabdemo...
10-13 09:16:24.723: INFO/System.out(274): :IncludeCategory: android.intent.category.LAUNCHER...
10-13 09:16:24.762: INFO/System.out(274): IncludeCategory: android.intent.category.LAUNCHER...
10-13 09:16:24.773: INFO/System.out(274): :IncludeCategory: android.intent.category.MONKEYER...
10-13 09:16:24.783: INFO/System.out(274): IncludeCategory: android.intent.category.MONKEYER...
10-13 09:16:24.872: WARN/ActivityManager(58): Permission Denial: setActivityController() from pid=290, uid=10036 requires android.permission.SET_ACTIVITY_WATCHER
10-13 09:16:24.903: DEBUG/AndroidRuntime(290): Shutting down VM
10-13 09:16:24.912: WARN/dalvikvm(290): threadid=1: thread exiting with uncaught exception (group=0x4001d850)
10-13 09:16:25.112: ERROR/AndroidRuntime(290): *** FATAL EXCEPTION IN SYSTEM PROCESS: main
10-13 09:16:25.112: ERROR/AndroidRuntime(290): java.lang.SecurityException: Permission Denial: setActivityController() from pid=290, uid=10036 requires android.permission.SET_ACTIVITY_WATCHER
10-13 09:16:25.112: ERROR/AndroidRuntime(290): at android.os.Parcel.readException(Parcel.java:1247)
10-13 09:16:25.112: ERROR/AndroidRuntime(290): at android.os.Parcel.readException(Parcel.java:1235)
10-13 09:16:25.112: ERROR/AndroidRuntime(290): at android.app.ActivityManagerProxy.setActivityController(ActivityManagerNative.java:2450)
10-13 09:16:25.112: ERROR/AndroidRuntime(290): at com.android.commands.monkey.Monkey.getSystemInterfaces(Monkey.java:780)
10-13 09:16:25.112: ERROR/AndroidRuntime(290): at com.android.commands.monkey.Monkey.run(Monkey.java:433)
10-13 09:16:25.112: ERROR/AndroidRuntime(290): at com.android.commands.monkey.Monkey.main(Monkey.java:360)
10-13 09:16:25.112: ERROR/AndroidRuntime(290): at com.android.internal.os.RuntimeInit.finishInit(Native Method)
10-13 09:16:25.112: ERROR/AndroidRuntime(290): at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
10-13 09:16:25.112: ERROR/AndroidRuntime(290): at dalvik.system.NativeStart.main(Native Method)
10-13 09:16:25.133: ERROR/JavaBinder(290): Unknown binder error code. 0xfffffff7
10-13 09:16:25.133: INFO/Process(290): Sending signal. PID: 290 SIG: 9
10-13 09:16:25.252: DEBUG/dalvikvm(132): GC_EXPLICIT freed 315 objects / 15400 bytes in 160ms
测试方法如下:
public void startMonkeyTest(){
Monkey monkey = new Monkey();
String[] s = {"-p","com.android.music","-v","5"};
monkey.run(s);
}
需要导入系统jar包
方法:需要增加下面两个权限
requires android.permission.SET_ACTIVITY_WATCHER 观察者****monkey测试用
android.permission.INJECT_EVENTS:允许一个程序截获用户事件如按键、触摸、轨迹球...