0

I have developed an Android app that requires root access, and it works fine. I am trying to test the app using instrumentation tests with ActivityInstrumentationTestCase2 and cover the parts of the app that utilize root access. The tests should be fully automated as they will run on our CI. The CI build creates a fresh emulator, and then it roots the emulator using the following commands:

adb -e install superuser.apk
adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system 
adb push su /system/xbin/su 
adb shell chmod 06755 /system 
adb shell chmod 06755 /system/xbin/su

It works OK, but at some point I have to click "Allow" button on the Superuser's root access prompt when the test requires it. My problem is how to execute those tests without manual clicking the "Allow" button and gain the root access.

If I try to click this button from instrumentation test using the following code

instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);

I get

java.lang.SecurityException: 
Injecting to another application requires INJECT_EVENTS permission

Apparently, this privilege is used only by system apps, and I cannot authorize my apps with this permission. Maybe I am doing something wrong here?

Another idea is to pre-authorize the app during the emulator boot from command line, but I haven't found the way for this.

4

1 回答 1

1

您的方法会遇到很多问题,您可以使用除仪器以外的其他框架(例如猴子/ http://developer.android.com/tools/testing/testing_ui.html)自动按下按钮,但我的投票因为你会为你的模拟器使用快照/自定义磁盘映像,创建你自己的具有手机根的快照/映像,然后你可能应该能够启动模拟器并告诉它使用已经具有 root 访问权限的快照.

于 2013-02-18T14:58:40.070 回答