ãã¹ãã¯ãã¢ããªã±ãŒã·ã§ã³éçºããã»ã¹ã®éèŠãªéšåã§ãã Androidã®å Žåãããã€ã¹ã¯äºãã«éåžžã«ç°ãªãããããã¹ãã¯ç¹ã«éèŠã§ãã
- ç»é¢ã®ãµã€ãºãšè§£å床ã
- AndroidããŒãžã§ã³ã
- ãã©ãŒã ãã¡ã¯ã¿ã
- ããã»ããµåœä»€ã·ã¹ãã ã
- ããã³ãã«ã¡ã©ãNFCãå€éšããŒããŒããªã©ã®ååš
ãããã£ãŠãå€ãã®ããã€ã¹ã§ã¢ããªã±ãŒã·ã§ã³ããã¹ãããå¿ èŠããããŸãã
ãã¹ãããã»ã¹ã«ã¯ãããŸããŸãªã¿ã€ãã®ãã¹ããå«ãŸããŸãã ã¢ããªã±ãŒã·ã§ã³ã®æ©èœãã¹ãã®ããã»ã¹ãæåã§è¡ãããæ¹æ³ãæ€èšããŠãã ããã ãã¹ã¿ãŒã¯ãã¢ããªã±ãŒã·ã§ã³ãããã€ã¹ã«ã€ã³ã¹ããŒã«ãããã¹ãŠã®æ©èœãæ éã«ãã§ãã¯ããŠãããããã€ã¹ãå ã®ç¶æ ã«æ»ããŸãã ãããŠãåã¢ããªã±ãŒã·ã§ã³ãšåããã€ã¹ã«å¯ŸããŠã ãã®æ¹æ³ã®æãããªæ¬ ç¹ã¯ãå®æçãªãã¹ãã«æéããããããšã§ãã
èªåãã¹ãã®æãããªå©ç¹ã¯ãå€ãã®ã³ã¹ãããããã«å®æçã«å®è¡ã§ããããšã§ãã ããšãã°ãå©çšå¯èœãªããã€ã¹ã®ã»ããå šäœã§æ¯æ©ã¢ããªã±ãŒã·ã§ã³ã®ææ°ãã«ãããã¹ãããååäžã«çµæãåæããŠãšã©ãŒãä¿®æ£ããŸãã
ãã®èšäºã§ã¯ãèªåãã¹ããå®è£ ããæ¹æ³ã«ã€ããŠèª¬æããŸãã Android SDKã«å«ãŸããŠããããŒã«ããŸãã¯ãªãŒãã³ãœãŒã¹ã©ã€ã»ã³ã¹ã§é åžãããŠããããŒã«ã®ã¿ãèæ ®ãããŸãã
èªåãã¹ãã®ã³ã³ã»ãã
ã¿ã¹ã¯ã¯ããã¹ã¿ãŒã«ââãã£ãŠå®è¡ãããã¢ã¯ã·ã§ã³ãæãæ£ç¢ºã«èªååããããšã§ãã ããããèŠãŠã¿ãŸãããã ããã€ãã®ã¢ããªã±ãŒã·ã§ã³ãšããã€ãã®Androidããã€ã¹ããããŸãã åã¢ããªã±ãŒã·ã§ã³ããã³åããã€ã¹ã«å¯ŸããŠã次ã®æé ãå®è¡ãããŸãã
- ããã€ã¹ã«ã¢ããªã±ãŒã·ã§ã³ãã€ã³ã¹ããŒã«ãã
- ã¢ããªã±ãŒã·ã§ã³ã®èµ·å
- éžæããæ¹æ³ã§ã¢ããªã±ãŒã·ã§ã³ããã¹ããã
- ã¢ããªã±ãŒã·ã§ã³ãã¢ã³ã€ã³ã¹ããŒã«ãã
- ããã€ã¹ã®ç¶æ ããªã»ãã
åã¹ãããã§ããã°ãã¹ã¯ãªãŒã³ã·ã§ãããªã©ã®ããŒã¿ãåéããŠåæããå¿ èŠããããŸãã 次ã«ããããã®ããŒã¿ã«åºã¥ããŠããã¹ãçµæãçæããŸãã
以äžã¯ããããã®æé ãèªååããããŒã«ã§ãã
Androidããã€ã¹ç®¡ç
æåã«ãèªåãã¹ããèµ·åããã³ã³ãã¥ãŒã¿ãŒãéžæãããã®ã³ã³ãã¥ãŒã¿ãŒã§Android SDKãæ§æããå¿ èŠããããŸãã Linuxãã€ã³ã¹ããŒã«ãããŠããã³ã³ãã¥ãŒã¿ãŒã®äŸãæäŸãããŠããŸãã
ãã¹ãŠã®ãã¹ãæžã¿ããã€ã¹ã§ãããã¯ç»é¢ããªãã«ããŠåŸ æ©æéãæ倧åããå¿ èŠããããŸãã äžéšã®ãã¹ãæ¹æ³ã§ã¯ãç»é¢ã®åãã®å€æŽãç¡å¹ã«ããå¿ èŠããããŸãã
Android SDKã«ã¯ãadbãšMonkeyRunnerã®2ã€ã®ããã€ã¹ç®¡çãŠãŒãã£ãªãã£ããããŸãã
ãã¹ãã§äœ¿çšãããã¢ã¯ã·ã§ã³ã®èªååã«ã€ããŠè©³ãã説æããŸãã ADBãšMonkeyRunnerã«ç²ŸéããŠãã人ã«ãšã£ãŠã¯ãã èªååããããã¹ãæ¹æ³ ãã»ã¯ã·ã§ã³ã«çŽæ¥è¡ãããšã¯çã«ããªã£ãŠããŸãã
ADBãŠãŒãã£ãªãã£ã䜿çšãã管ç
ADBïŒAndroid Debug BridgeïŒ-ã³ãã³ãã©ã€ã³ããAndroidããã€ã¹ã管çããããã®ãŠãŒãã£ãªãã£ã ADBãã¯ã€ãããŒããŒïŒ developer.android.com/tools/help/adb.html
adbãŠãŒãã£ãªãã£ã¯ããã£ã¬ã¯ããª
<android_sdk>/platform-tools/
ãŸãã ãã®ãã£ã¬ã¯ããªãžã®ãã¹ã¯ãPATHç°å¢å€æ°ã«æžã蟌ãããšããå§ãããŸãã
ADBã®ãã¹ã
Android SDKãã€ã³ã¹ããŒã«ããŠæ§æããAndroidããã€ã¹ãã³ã³ãã¥ãŒã¿ãŒã«æ¥ç¶ããŠãã³ãã³ããå®è¡ããŸãã
adb devices
ãã®ã³ãã³ãã¯ãæ¥ç¶ãããŠãããã¹ãŠã®ããã€ã¹ããªã¹ãããŸãã ããã€ã¹ã®ãªã¹ãã空ã§ãªãå ŽåãADBã¯æ§æãããŠãããæ©èœããŠããŸãã
è€æ°ã®ããã€ã¹ã§äœæ¥ãã
äœæ¥ããããã€ã¹ã§ADBãæå®ããã«ã¯ã
-s
åŸã«ããã€ã¹ã®ã·ãªã¢ã«çªå·ãç»é²ããå¿ èŠããããŸãã
adb -s <serial_number> <command>
äŸïŒ
adb -s <serial_number> logcat
ããã€ã¹ã®ã·ãªã¢ã«çªå·ã¯ã
adb devices
ã³ãã³ãã§è¡šç€ºã§ããŸãã
-s
䜿çšãããšãæ¥ç¶ãããŠããè€æ°ã®ããã€ã¹ãåæã«
-s
ã§ããŸãã å°æ¥ãã³ãã³ãã§
-s
ãæå®ããŸããã
åºæ¬çãªADBã³ãã³ã
ããã€ã¹ã§ã³ã³ãœãŒã«ãéããŸãã
adb shell
ããã€ã¹ã§ã³ãã³ããå®è¡ããŸãã
adb shell <command>
Androidã«ã¯ãlsãcatãdmesgãªã©ãå€ãã®æšæºLinuxãŠãŒãã£ãªãã£ããããŸãã
apkãã¡ã€ã«ããã¢ããªã±ãŒã·ã§ã³ãã€ã³ã¹ããŒã«ããŸãã
adb install example.apk
ã¢ããªã±ãŒã·ã§ã³ãåé€ïŒ
adb uninstall <package>
ååããã±ãŒãžã¯ã次ã®ã³ãã³ãã䜿çšããŠapkãã¡ã€ã«ããååŸã§ããŸãã
aapt dump badging example.apk | grep "package"
ããã€ã¹ããã³ã³ãã¥ãŒã¿ãŒã«ãã¡ã€ã«ãããŠã³ããŒãããŸãã
adb pull <path-on-device> <file>
ã³ã³ãã¥ãŒã¿ãŒããããã€ã¹ã«ãã¡ã€ã«ãããŠã³ããŒãããŸãã
adb push <file> <path-on-device>
泚ïŒ
ããã€ã¹äžã®ã»ãšãã©ã®ãã£ã¬ã¯ããªã«ã¯èªã¿åãå°çšã¢ã¯ã»ã¹ããããŸãã
/sdcard
ãã£ã¬ã¯ããªïŒããããããã°ã©ã ãå®è¡ããããšã¯ã§ããŸããïŒããã³
/data/local/tmp/
ãžã®æžã蟌ã¿ã¢ã¯ã»ã¹ãèš±å¯ãããŸãã
ã¢ããªã±ãŒã·ã§ã³ã®èµ·åïŒ
adb shell am start -n <package>/<activity>
æå®ãããã¢ã¯ãã£ããã£ãéå§ããŸãã ã¡ãã¥ãŒã§ã¢ããªã±ãŒã·ã§ã³ãéžæãããšéå§ãããååã¢ã¯ãã£ããã£ã¯ã次ã®ã³ãã³ãã䜿çšããŠapkãã¡ã€ã«ããååŸã§ããŸãã
aapt dump badging example.apk | grep "launchable-activity"
ãã°ãèªã
Androidã§ã®ãã°ã®èªã¿åãã¯ãlogcatãŠãŒãã£ãªãã£ã«ãã£ãŠè¡ãããŸãã
LogcatãŠãŒãã£ãªãã£ã®ããŒã ããŒãžïŒ developer.android.com/tools/help/logcat.html
ããã€ã¹ãããã°ãèªã¿åããŸãïŒCtrl-CãæŒããããŸã§ãããã¯ãããŸãïŒïŒ
adb logcat
ããã€ã¹ã®ãã°ãããã¡ãã¯ãªã¢ããŸãã
adb logcat -c
ããã€ã¹ã®ãã°ãããã¡ãŒãèªã¿åããŸãïŒãããã¡ãŒã®çŸåšã®å 容ã衚瀺ããŸããããããã¯ãããŸããïŒã
adb logcat -d
äŸïŒ
adb logcat -c # # adb logcat -d > file.log # file.log
screencapãŠãŒãã£ãªãã£ã§ã¹ã¯ãªãŒã³ã·ã§ãããæ®ã
screencapãŠãŒãã£ãªãã£ã¯ãçŸåšã®ç»é¢ã®å 容ãç»åãã¡ã€ã«ã«ä¿åããŸãã
adb shell screencap /sdcard/screen.png adb pull /sdcard/screen.png screen.png adb shell rm /sdcard/screen.png
screencap
ãŠãŒãã£ãªãã£ã¯ãAndroid 4.x以éãæèŒããæºåž¯é»è©±ã§äœ¿çšã§ããŸãã Androidã®ä»¥åã®ããŒãžã§ã³ã§ã¯ãMonkeyRunnerã䜿çšããŠã¹ã¯ãªãŒã³ã·ã§ãããæ®åœ±ã§ããŸãã
ADBã䜿çšããŠã¢ããªã±ãŒã·ã§ã³ããã¹ãããããã®BASHã¹ã¯ãªããã®äŸ
ã¹ã¯ãªããïŒapp_test.sh
#!/bin/bash #------------------------------------------------------------------------------- # BASH c ADB # # : # 1. # 2. # 3. monkey # 4. # # log-. #------------------------------------------------------------------------------- APK="example.apk" PACKAGE="com.example.package" ACTIVITY="com.example.package.activity" rm -rf log mkdir log # 1. adb uninstall $PACKAGE # adb logcat -c # adb install $APK # adb logcat -d > log/install.log # # 2. adb logcat -c adb shell am start -n $PACKAGE/$ACTIVITY # sleep 10 # 10 adb logcat -d > log/start.log # 3. adb logcat -c # monkey adb shell monkey --pct-touch 70 -p $PACKAGE -v 1000 --throttle 500 adb logcat -d > log/test.log # 4. adb logcat -c adb uninstall $PACKAGE adb logcat -d > log/uninstall.log
MonkeyRunnerã«ãã管ç
MonkeyRunnerãŠãŒãã£ãªãã£ã¯ãAndroidããã€ã¹ãå¶åŸ¡ããã¹ã¯ãªãããèšè¿°ããããã®APIãæäŸããŸãã MonkeyRunnerã䜿çšãããšãAndroidã¢ããªã±ãŒã·ã§ã³ãã€ã³ã¹ããŒã«ããŠèµ·åãããŠãŒã¶ãŒã¢ã¯ã·ã§ã³ãã·ãã¥ã¬ãŒãããã¹ã¯ãªãŒã³ã·ã§ãããæ®ããã³ã³ãã¥ãŒã¿ãŒã«ä¿åããPythonã¹ã¯ãªãããäœæã§ããŸãã MonkeyRunnerãŠãŒãã£ãªãã£ã¯ã Jythonã䜿çšããŠã¹ã¯ãªãããå®è¡ããŸãã
MonkeyRunnerãŠãŒãã£ãªãã£ã®ããŒã ããŒãžãšAPIã®èª¬æïŒ developer.android.com/tools/help/monkeyrunner_concepts.html
MonkeyRunnerã§ãã°ãèªã
Log.pyãã¡ã€ã«ïŒ
# coding: utf-8 from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice def log(fn, device): msg = device.shell('logcat -d') f_log = open(fn, 'at') if msg is None: msg = 'None' f_log.write(msg.encode('utf-8')) f_log.close() device.shell('logcat -c') if __name__ == '__main__': device = MonkeyRunner.waitForConnection() device.shell('logcat -c') # # ... log('example.log', device) #
æã¡äžãïŒ
monkeyrunner log.py
ã¹ã¯ãªããã¯ãçŸåšã®ãã£ã¬ã¯ããªã®
example.log
ãã¡ã€ã«ã«ãã°ãæžã蟌ã¿
example.log
ã
ã¹ã¯ãªãŒã³ã·ã§ãããæ®ã
Screen.pyãã¡ã€ã«ïŒ
# coding: utf-8 from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice if __name__ == '__main__': device = MonkeyRunner.waitForConnection() image = device.takeSnapshot() image.writeToFile('screenshot.png','png')
æã¡äžãïŒ
monkeyrunner screen.py
ã¹ã¯ãªããã¯ã¹ã¯ãªãŒã³ã·ã§ãããååŸãããããçŸåšã®ãã£ã¬ã¯ããªã®
screenshot.png
ãã¡ã€ã«ã«ä¿åããŸãã
MonkeyRunnerã䜿çšããããã€ã¹å¶åŸ¡ã®äŸ
ã¹ã¯ãªããïŒmonkeyrunner_test.py
# coding: utf-8 import time from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice APK = "example.apk" PACKAGE = "com.example.package" ACTIVITY = "com.example.package.activity" def log(fn, device): msg = device.shell('logcat -d') f_log = open(fn, 'at') if msg is None: msg = 'None' f_log.write(msg.encode('utf-8')) f_log.close() device.shell('logcat -c') if __name__ == '__main__': device = MonkeyRunner.waitForConnection() device.removePackage(PACKAGE) # , device.shell('logcat -c') # device.installPackage(APK) # log('install.log', device) # run_component = PACKAGE + '/' + ACTIVITY device.startActivity(component=run_component) # activity time.sleep(10) # 10 log('start.log', device) # device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP) # screen = device.takeSnapshot() # screen.writeToFile('screenshot.png', 'png') # screenshot.png log('run.log', device) # device.removePackage(PACKAGE) # log('uninstall.log', device) #
æã¡äžãïŒ
monkeyrunner monkeyrunner_test.py
èªåãã¹ãããŒã«
ãµã«ã§ãã¹ããã
ããã€ã¹ãéåžžã«æŽ»çºã§åµé çãªãµã«ã®æã«èœã¡ããšæ³åããŠãã ããããµã«ãŠãŒãã£ãªãã£ã¯åæ§ã®ç¶æ³ãæš¡å£ããããã«èšèšãããŠããŸãã
monkeyãŠãŒãã£ãªãã£ã¯ãAndroid SDKã®äžéšã§ãã ãŠãŒãã£ãªãã£ã¯ãããã€ã¹ã«ç䌌ã©ã³ãã ãŠãŒã¶ãŒã¢ã¯ã·ã§ã³ã®ã¹ããªãŒã ãéä¿¡ããŸãã ã³ãã³ãã©ã€ã³ãã©ã¡ãŒã¿ãŒã¯ããŠãŒã¶ãŒã¢ã¯ã·ã§ã³ã®æ°ãã¿ã€ãã®æ¯çãããã³ãã¹ãããã±ãŒãžã®ååãæå®ããŸããããã«ãããããšãã°ããµã«ããã¹ã察象ã®ã¢ããªã±ãŒã·ã§ã³ã®å¶éãè¶ ãããã¢ãã¬ã¹åž³ãããã¹ãŠã®é£çµ¡å ãžã®SMSã®éä¿¡ãéå§ãããŸããã
䜿çšäŸãšãªãã·ã§ã³ã®ãªã¹ãã¯ããŒã ããŒãžã§æäŸãããŠããŸãïŒ developer.android.com/tools/help/monkey.html
ãµã«ã®äž»ãªå©ç¹ã¯ããµããŒãã³ã¹ãããªãããšã§ãã ããã«ãä»»æã®ã€ãã³ãã®ã¹ããªãŒã ã«ããã¢ããªã±ãŒã·ã§ã³ã®ã¹ãã¬ã¹ãã¹ãã§ã¯ãéèŠãªãšã©ãŒãæ€åºã§ããŸãã
ãµã«ãŠãŒãã£ãªãã£ã®ãã¹ãã®æ¬ ç¹ïŒ
- è€éãªäžé£ã®ã¢ã¯ã·ã§ã³ã«ãã£ãŠåŒãèµ·ããããæ©èœã®ãã¹ãã«ã¯ç¡å¹ã§ãã ããšãã°ããµã«ã¯èªèšŒã§ãããã¢ããªã±ãŒã·ã§ã³ã®äž»ãªæ©èœã¯ç¡èŠãããŸãã
- è¿ éãªåå¿ãšè€éãªãžã§ã¹ãã£ãŒãå¿ èŠãšããè€éãªã³ã³ãããŒã«ãåããã²ãŒã ã¯ãæåããçµäºãããããŸã£ããçµäºããŸããã
- ãµã«ã§èŠã€ãã£ããšã©ãŒã¯åçŸãéåžžã«å°é£ã§ãã
- ã¢ããªã±ãŒã·ã§ã³ã®ç¶æ ã®ç¢ºèªã¯ãããŸããã
monkeyãŠãŒãã£ãªãã£ã䜿çšãããšãã¢ããªã±ãŒã·ã§ã³ãç°¡åã«ãã¹ãã§ããŸããããã¯è¯ãåºçºç¹ã§ãã ãã®æ¹æ³ã¯ãç¹å®ã®ã¢ããªã±ãŒã·ã§ã³ã«å¯ŸããŠé©åãªçµæã瀺ãå¯èœæ§ããããŸãã ãã¹ãã®å質ãäžååãªå Žåã¯ãä»ã®ãã¹ãæ¹æ³ã䜿çšããå¿ èŠããããŸãã
MonkeyRunnerã䜿çšãããã¹ã
MonkeyRunner APIã䜿çšããã¹ã¯ãªããã䜿çšãããšããã¹ãã·ã¹ãã ã®åºç€ãéçºã§ããã ãã§ãªããç¹å®ã®ããã€ã¹ã§ç¹å®ã®ã¢ããªã±ãŒã·ã§ã³ããã¹ãããã¹ã¯ãªãããäœæããããšãã§ããŸãã
å©ç¹ïŒ
- æè»æ§-ã»ãšãã©äœã§ãå®è£ ã§ããŸãã
çæïŒ
- åçŽãªå Žåã§ããã¹ã¯ãªãããæžãããšã®é£ããã
ååãšããŠããã®æ¹æ³ã¯æ£åœåãããŸãã-ã¹ã¯ãªããã®èšè¿°ã«ã¯å€ãã®æéãããããŸãã ãã ããç¹å¥ãªå Žåã«ã¯ããã®æ¹æ³ãæ©èœããå ŽåããããŸãã
getevent / sendeventã䜿çšãããã¹ã
geteventããã³sendeventãŠãŒãã£ãªãã£ã䜿çšãããšãäžé£ã®ãŠãŒã¶ãŒã¢ã¯ã·ã§ã³ãèšé²ããŠããããã®ã·ãŒã±ã³ã¹ãåçã§ããŸãã ãŠãŒãã£ãªãã£ã¯Androidããã€ã¹èªäœã«ãããåäœããããã«ã«ãŒãã¢ã¯ã»ã¹ãå¿ èŠãšããŸããã
å©ç¹ïŒ
- ãã§ã«å®è¡ãããŠããå Žåãæåãã¹ãäžã«äžé£ã®ã¢ã¯ã·ã§ã³ãè¿œå è²»çšãªãã§èšé²ã§ããŸãã
- ã¹ã¯ãªããã£ã³ã°ã«ã¯ããã°ã©ãã³ã°ã¹ãã«ã¯å¿ èŠãããŸããã
çæïŒ
- ã¢ã¯ã·ã§ã³ã®ã·ãŒã±ã³ã¹ã¯ãã¢ããªã±ãŒã·ã§ã³ããšããã³ããã€ã¹ããšã«åå¥ã«èšé²ããå¿ èŠããããŸãã ã¢ããªã±ãŒã·ã§ã³ã€ã³ã¿ãŒãã§ã€ã¹ãå€æŽããå Žåãèšé²ããããã¹ãŠã®ã¢ã¯ã·ã§ã³ãç¹°ãè¿ãå¿ èŠããããŸãã
- ã¢ããªã±ãŒã·ã§ã³ã®ã¹ããŒã¿ã¹ãã§ãã¯ããããŸããã ããšãã°ããã©ãŠã¶ããã¹ããããšãããŒãžãéããŸãã èšé²æãããé·ãéããŠããå ŽåãããŒãžãå®å šã«ããŒãããããŸã§ããã«ã¢ã¯ã·ã§ã³ãå®è¡ãããçµæãäžæ£ç¢ºã«ãªããŸãã ãã®ãããªå Žåã¯ãã¹ãŠãäºæ³ãå¯èœãªæ倧å€ãè¶ ãããããªæ¹æ³ã§ã¹ã¯ãªãããäœæããããšãã§ããŸãã
- ã¢ã¯ã·ã§ã³ã®è¿ éã§è€éãªã·ãŒã±ã³ã¹ã¯èšé²ãããé·ãåçãããŸãããããã£ãŠããã®æ¹æ³ã¯ãã¢ã¯ã·ã§ã³ã®åå¿æéãšé©ææ§ãéèŠãªåçã²ãŒã ã®ãã¹ãã«å¿ ãããé©ããŠããŸããã
äžé£ã®ã¢ã¯ã·ã§ã³ã®èšé²ïŒ
# # , Ctrl-C adb shell getevent -t > events.txt # ./decode_events.py events.txt > events.sh # adb push events.sh /data/local/tmp/ # adb shell chmod 755 /data/local/tmp/events.sh # adb shell sh /data/local/tmp/events.sh
ã¹ã¯ãªããïŒdecode_events.py
#!/usr/bin/python # coding: utf-8 USAGE = """ getevent shell-, sendevent sleep. : ./decode_events.py input.txt > output.sh """ import re import sys # [ 43319.628481] /dev/input/event1: 0003 0039 ffffffff # 48470-342082: /dev/input/event1: 0000 0000 00000000 _re = re.compile(r'[^\d]*(?P<sec>\d+)[.-](?P<msec>\d+)[:\]] (?P<device>[^:]+):' ' (?P<class>[0-9a-f]+) (?P<event>[0-9a-f]+) (?P<params>[0-9a-f]+)') T_FIX = 0.1 last_time = None if __name__ == '__main__': if len(sys.argv) < 2: print USAGE sys.exit(1) print '#!/bin/sh' input_fn = sys.argv[1] for line in open(input_fn, 'rt'): m = _re.match(line) if m is not None: d = m.groupdict() cur_time = float(d['sec']) + float(d['msec'][:2])/100 if last_time is not None: diff_time = (cur_time - last_time) if diff_time > 0.2: print 'sleep %.2f' % (diff_time-T_FIX,) last_time = cur_time print 'sendevent', d['device'], int(d['class'], 16), \ int(d['event'], 16), int(d['params'], 16) else: print '#', line.strip('\n\r\t ')
èšé²ãããã¢ã¯ã·ã§ã³ã¯ãããã€ã¹ã§åçããå¿ èŠããããŸãã
Robotiumã䜿çšãããã¹ã
åè¿°ã®æ¹æ³ãšã¯ç°ãªããRobotiumã¯Android SDKã®äžéšã§ã¯ãããŸãããããªãŒãã³ãœãŒã¹ã©ã€ã»ã³ã¹ã§é åžãããŸãã
RobotiumããŒã ããŒãžïŒ code.google.com/p/robotium
Robotiumã®äž»ãªéãã¯ããã¹ãã¢ã¯ã·ã§ã³ãã¢ããªã±ãŒã·ã§ã³ã€ã³ã¿ãŒãã§ã€ã¹ã¬ãã«ã§èšè¿°ãããããšã§ãã åè¿°ã®æ¹æ³ã§ã¯ããã¹ãã¢ã¯ã·ã§ã³ã¯å ¥åããã€ã¹ã¬ãã«ã§æ瀺çãŸãã¯æé»çã«èšè¿°ãããŠããŸããã
ããšãã°ãã¢ããªã±ãŒã·ã§ã³ã§ãOKããã¿ã³ãã¯ãªãã¯ããå¿ èŠããããŸãã MonkeyRunnerã¹ã¯ãªããã䜿çšãããšããã¿ã³ãæŒãããšã¯ã座æšïŒx0ãy0ïŒã§ç»é¢äžã®ãã€ã³ãã«ã¿ããããããšããŠå®è£ ãããŸãã Robotiumã䜿çšããŠãããã¯ãããã¹ããOKãã®ãã¿ã³ãæŒããŠãã ããããšããŠå®è£ ãããŸãã
ã¢ããªã±ãŒã·ã§ã³ã€ã³ã¿ãŒãã§ã€ã¹ã¬ãã«ã§ã¢ã¯ã·ã§ã³ãèšè¿°ããå Žåãã€ã³ã¿ãŒãã§ã€ã¹èŠçŽ ã®å Žæãç»é¢è§£å床ãããã€ã¹ã®äœçœ®ã«é¢ä¿ãªãã¢ã¯ã·ã§ã³ãå®è¡ã§ããŸãã
ããã«ãRobotiumã§ã¯ãã¢ã¯ã·ã§ã³ã«å¯Ÿããã¢ããªã±ãŒã·ã§ã³ã®åå¿ã確èªã§ããŸãã
ããšãã°ãã¢ããªã±ãŒã·ã§ã³ã®ãOKããã¿ã³ãã¯ãªãã¯ãããšããItem 1ãèŠçŽ ãå«ããªã¹ãã衚瀺ãããŸãã Robotiumã䜿çšãããšããã®ãããªèŠçŽ ãå«ããªã¹ãã衚瀺ããããã©ããã確èªã§ããŸãã
åã¢ã¯ã·ã§ã³ã®åŸã«ãã§ãã¯ãå®è¡ãããšããšã©ãŒãçºçããã¹ããããç°¡åã«æ€åºã§ããŸãã
çæïŒ
- ã¢ããªã±ãŒã·ã§ã³ããšã«ãJavaãã¹ãã¹ã¯ãªãããéçºããå¿ èŠããããŸãã ããã«ã¯ããã°ã©ãã³ã°ã¹ãã«ãšæéãããããŸãã
- ã¢ããªã±ãŒã·ã§ã³ã€ã³ã¿ãŒãã§ã€ã¹ãå€æŽããå Žåããã¹ãã¹ã¯ãªãããå€æŽããå¿ èŠããããŸãã
- Robotiumã¹ã¯ãªããã®äœæã¯ãgetevent / sendeventã䜿çšããã¢ã¯ã·ã§ã³ã®äœæãããå°é£ã§ãã
äžè¬ã«ãRobotiumã§ã¯ãé©åãªã³ã¹ãã§æé«å質ã®ãã¹ãã·ããªãªãéçºã§ããŸãã
è©Šéšæ¹æ³ã®æ¯èŒ
è©Šéšæ¹æ³ | é·æ | æ¬ ç¹ |
---|---|---|
ã¢ã³ããŒ-ã©ã³ãã ãªãŠãŒã¶ãŒã¢ã¯ã·ã§ã³ã®ã¹ããªãŒã ã | è·è¡è²»çšã¯ãããŸããã
ããã€ã¹ã«äŸåããŸããã ã¹ãã¬ã¹ãã¹ãã§ã¯ãéèŠãªãšã©ãŒãæ€åºã§ããŸãã | ãã¹ãã®å質ã¯ã¢ããªã±ãŒã·ã§ã³ã«ãã£ãŠç°ãªããŸãã
èŠã€ãã£ããšã©ãŒã¯åçŸãå°é£ã§ãã ã¢ããªã±ãŒã·ã§ã³ã®ç¶æ ã®ç¢ºèªã¯ãããŸããã |
MonkeyRunner-ããã€ã¹ç®¡çã¹ã¯ãªããã | æè»æ§ã | åçŽãªã¢ããªã±ãŒã·ã§ã³ã§ãã£ãŠããã¹ã¯ãªããã®èšè¿°ãšä¿å®ã®è€éãã |
getevent / sendevent-ãŠãŒã¶ãŒã¢ã¯ã·ã§ã³ãèšé²/åçããŸãã | äžé£ã®ã¢ã¯ã·ã§ã³ãèšé²ããã®ã«ããã°ã©ãã³ã°ã¹ãã«ã¯å¿ èŠãããŸããã | èšé²ãããäžé£ã®ã¢ã¯ã·ã§ã³ã¯ãæ¹åãåºå®ããã1ã€ã®ããã€ã¹ã«ã®ã¿é©ããŠããŸãã
ã¢ããªã±ãŒã·ã§ã³ã€ã³ã¿ãŒãã§ã€ã¹ãå€æŽããå Žåãã¢ã¯ã·ã§ã³ã®ã·ãŒã±ã³ã¹ãåèšé²ããå¿ èŠããããŸãã ã¢ããªã±ãŒã·ã§ã³ã®ç¶æ ã®ç¢ºèªã¯ãããŸããã |
Robotiumã¯ãã¹ããŒããã«ã¢ããªã±ãŒã·ã§ã³ã®ã€ã³ã¿ãŒãã§ã€ã¹ããã¹ãããããã®ã¹ã¯ãªããã§ãã | ã¢ã¯ã·ã§ã³ã¯ãã¢ããªã±ãŒã·ã§ã³ã€ã³ã¿ãŒãã§ã€ã¹ã¬ãã«ã§èª¬æãããŸãã
ã¹ã¯ãªããã¯ãç»é¢ã®è§£å床ãããã€ã¹ã®åãã«äŸåããªãå ŽåããããŸãã ã¢ã¯ã·ã§ã³ã®å®äºåŸãã¢ããªã±ãŒã·ã§ã³ã®ã¹ããŒã¿ã¹ã確èªã§ããŸãã | Javaã¹ã¯ãªããã®äœæãå°é£ã ã¢ããªã±ãŒã·ã§ã³ã€ã³ã¿ãŒãã§ã€ã¹ãå€æŽããå Žåãã¹ã¯ãªãããå€æŽããå¿ èŠããããŸãã |
çµæåæ
äžèšã®æ¹æ³ã§ã¢ããªã±ãŒã·ã§ã³ããã¹ãããçµæããã°ãšã¹ã¯ãªãŒã³ã·ã§ãããåŸãããŸããã 次ã«ããšã©ãŒãåæããå¿ èŠããããŸãã
ãã°åæ
ãŸããéšåæååã§æ€çŽ¢ã§ããŸãã
- ç§/ãããã°
- èŽåœçãªäŸå€
- WIN DEATH
æåãã¹ãäžã«ãšã©ãŒãæ€åºããããšããªã¹ããè£è¶³ã§ããŸãã
ã¹ã¯ãªãŒã³ã·ã§ããåæ
æåã§ãã¹ãããããã»ã¹ã§ã¯ããã¹ãã®éèŠãªãã€ã³ãã§äžé£ã®ã¹ã¯ãªãŒã³ã·ã§ãããæºåããèªåãã¹ãäžã«ããããã¹ã¯ãªãŒã³ã®å 容ãšæ¯èŒã§ããŸãã ããã«ãããèªåãã¹ãããã»ã¹ãæ£ããè¡ãããŠãããã©ãããå€æããããšã©ãŒãç¹å®ãããŸãã
ãŸããã¢ããªã±ãŒã·ã§ã³ã®èµ·ååãšèµ·ååŸã®ã¹ã¯ãªãŒã³ã·ã§ãããæ¯èŒããããšã圹ç«ã¡ãŸããããã«ãããç»é¢ããã°ã«ã¡ãã»ãŒãžã衚瀺ãããã«ã¢ããªã±ãŒã·ã§ã³ãã¯ã©ãã·ã¥ããã±ãŒã¹ãç¹å®ã§ããŸãã
MonkeyRunnerã䜿çšãããšã2ã€ã®ã¹ã¯ãªãŒã³ã·ã§ãããç¹å®ã®èš±å®¹å€ãšããŒã»ã³ãã§æ¯èŒã§ããŸãã
image1 = device.takeSnapshot() # ... image2 = device.takeSnapshot() if image2.sameAs(image1, 0.1): print 'image1 and image2 are the same (10%)'
æ®å¿µãªãããMonkeyImage APIã¯ãã¡ã€ã«ããããŒãããæ©èœãæäŸããŸããã ãããã£ãŠãä¿åããã¹ã¯ãªãŒã³ã·ã§ãããæ¯èŒããã«ã¯ãããšãã°Python Imaging Libraryã䜿çšããŠãç¬èªã®é¢æ°ãäœæããå¿ èŠããããŸãã
ãã¹ãåŸã«ããã€ã¹ã®ç¶æ ããªã»ãããã
ã¢ããªã±ãŒã·ã§ã³ããã¹ãããåŸãããã€ã¹ãå ã®ç¶æ ã«æ»ãå¿ èŠããããŸãã
ããã¯ããã€ãã®æ¹æ³ã§å®çŸã§ããŸãã
- æ»ããã¿ã³ãç¹°ãè¿ãæŒããŸãã
- ããã€ã¹ãåèµ·åããŸãã
- zygoteããã»ã¹ãåèµ·åããŸãã
æãé©åãªæåã®ãªãã·ã§ã³ãæ€èšããŠãã ããã
æ»ããã¿ã³ãç¹°ãè¿ãæŒã
MonkeyRunnerã䜿çšããŠæ»ããã¿ã³ãæŒããŸãã
for i in xrange(0, 10): device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP) time.sleep(0.5)
å®éã«ã¯ããã®ãªãã·ã§ã³ã¯å®éã®ãŠãŒã¶ãŒã®åäœãã·ãã¥ã¬ãŒããããããæé©ã§ãã
ãããã«
ããŒãã§ã¯ãAndroidã¢ããªã±ãŒã·ã§ã³ãèªåçã«ãã¹ãããããã®ããã€ãã®æ¹æ³ããããã®å©ç¹ãšæ¬ ç¹ãæ€èšãããŸããã ããã«ãAndroid SDKã«å«ãŸããŠããããŒã«ããŸãã¯ãªãŒãã³ãœãŒã¹ã©ã€ã»ã³ã¹ã§é åžãããŠããããŒã«ã確èªããŸãã
èªåãã¹ãã¯äžèœè¬ã§ã¯ãªããä»ã®ã¿ã€ãã®ãã¹ãã«ä»£ãããã®ã§ã¯ãªãããšã«æ³šæããŠãã ããã ããŸããŸãªæ¹æ³ãçµã¿åããããé©åã«æ§ç¯ããããã¹ãããã»ã¹ã«ãããé«å質ã®è£œåãåŸãããŸãã