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

あなたのアプローチには多くの問題があります。インストルメンテーション以外の別のフレームワーク(例:monkey/ http://developer.android.com/tools/testing/testing_ui.html)を使用してボタンの押下を自動化できますが、私の投票エミュレーターにスナップショット/カスタム ディスク イメージを利用し、電話をルート化した独自のスナップショット/イメージを作成すると、エミュレーターを起動して、既にルート アクセス権を持つスナップショットを使用するように指示できるはずです。 .

于 2013-02-18T14:58:40.070 に答える