import os,sys,time from subprocess import call from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice COUNT = 0; def gen_png_no(): global COUNT COUNT = COUNT + 1 return str(COUNT) def take_snapshot(device): result = device.takeSnapshot() result.writeToFile(os.path.realpath(os.path.dirname(__file__))+"/quadrant_" + gen_png_no() +".png","png") def init(): os.system("rm" + os.path.realpath(os.path.dirname(__file__)) + "/*.png 2> /dev/null") def main(): if len(sys.argv) < 2: print "please input the device id" sys.exit(0) #connect the device timeout_val = 5 for dev_id in sys.argv[1:]: device = MonkeyRunner.waitForConnection( timeout = timeout_val,deviceId = dev_id ) if not device: print "connect to the device timeout" sys.exit(0) else: print "connect to the device: " + dev_id device.shell("echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor") device.shell("echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor") srcfile = os.path.realpath(os.path.dirname(__file__))+'/com.aurorasoftworks.quadrant.ui.standard-1.apk' device.installPackage(srcfile) #clean the enviroment init() device.startActivity(component='com.aurorasoftworks.quadrant.ui.standard/.QuadrantStandardLauncherActivity') MonkeyRunner.sleep(2) device.shell("am kill-all") MonkeyRunner.sleep(2) device.press("KEYCODE_DPAD_DOWN",MonkeyDevice.DOWN_AND_UP) device.press("KEYCODE_DPAD_DOWN",MonkeyDevice.DOWN_AND_UP) device.press("KEYCODE_DPAD_CENTER",MonkeyDevice.DOWN_AND_UP) MonkeyRunner.sleep(5) device.press("KEYCODE_DPAD_UP",MonkeyDevice.DOWN_AND_UP) device.press("KEYCODE_DPAD_UP",MonkeyDevice.DOWN_AND_UP) device.press("KEYCODE_DPAD_UP",MonkeyDevice.DOWN_AND_UP) device.press("KEYCODE_DPAD_UP",MonkeyDevice.DOWN_AND_UP) device.press("KEYCODE_DPAD_DOWN",MonkeyDevice.DOWN_AND_UP) device.press("KEYCODE_DPAD_CENTER",MonkeyDevice.DOWN_AND_UP) print "Running Quadrant" MonkeyRunner.sleep(120) device.press("KEYCODE_DPAD_DOWN",MonkeyDevice.DOWN_AND_UP) device.press("KEYCODE_DPAD_RIGHT",MonkeyDevice.DOWN_AND_UP) device.press("KEYCODE_DPAD_CENTER",MonkeyDevice.DOWN_AND_UP) MonkeyRunner.sleep(30) take_snapshot(device) device.removePackage("com.aurorasoftworks.quadrant.ui.standard") if __name__ == '__main__': main()