9from __future__
import print_function
10from __future__
import with_statement
13from com.android.monkeyrunner
import MonkeyRunner, MonkeyDevice
22WAIT_FOR_SKP_CAPTURE = 1
26 """Action describing a touch drag."""
27 def __init__(self, start, end, duration, points):
33 def run(self, device):
34 """Perform the action."""
39 """Action describing a button press."""
44 def run(self, device):
45 """Perform the action."""
50 """Parse a dict describing an action and return an Action object."""
51 if action_dict[
'type'] ==
'drag':
53 tuple(action_dict[
'end']),
54 action_dict[
'duration'],
55 action_dict[
'points'])
56 elif action_dict[
'type'] ==
'press':
57 return PressAction(action_dict[
'button'], action_dict[
'press_type'])
59 raise TypeError(
'Unsupported action type: %s' % action_dict[
'type'])
63 """Class which describes an app to launch and actions to run."""
64 def __init__(self, name, package, activity, app_launch_delay, actions):
73 """Launch the app on the device."""
83 """Convenience implementation of subprocess.check_output."""
84 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
86 raise Exception(
'Command failed: %s' %
' '.
join(cmd))
87 return proc.communicate()[0]
91 """Run the given ADB shell command and emulate the exit code."""
92 output =
check_output([
'adb',
'shell', cmd +
'; echo $?']).strip()
93 lines = output.splitlines()
95 raise Exception(
'ADB command failed: %s\n\nOutput:\n%s' % (cmd, output))
96 return '\n'.
join(lines[:-1])
100 """Return True if the given file exists on the device and False otherwise."""
109 """Capture an SKP."""
110 remote_path =
'/data/data/%s/cache/%s' % (package, os.path.basename(skp_file))
117 adb_shell(
'setprop debug.hwui.capture_frame_as_skp %s' % remote_path)
122 device.drag((300, 300), (300, 350), 1, 10)
124 if time.time() - start > timeout:
125 raise Exception(
'Timed out waiting for SKP capture.')
129 cmd = [
'adb',
'pull', remote_path, skp_file]
133 adb_shell(
'setprop debug.hwui.capture_frame_as_skp ""')
137 """Load the JSON file describing an app and return an App instance."""
138 with open(filename)
as f:
139 app_dict = ast.literal_eval(f.read())
140 return App(app_dict[
'name'],
142 app_dict[
'activity'],
143 app_dict[
'app_launch_delay'],
148 """Capture SKPs for all apps."""
149 device = MonkeyRunner.waitForConnection()
153 device.drag((600, 600), (10, 10), 0.2, 10)
155 apps_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'apps')
156 app_files = [os.path.join(apps_dir, app)
for app
in os.listdir(apps_dir)]
158 for app_file
in app_files:
161 print(
' Package %s' % app.package)
163 print(
' Launched activity %s' % app.activity)
165 for action
in app.actions:
166 print(
' %s' % action.__class__.__name__)
169 time.sleep(WAIT_FOR_SKP_CAPTURE)
170 print(
' Capturing SKP.')
171 skp_file =
'%s.skp' % app.name
173 print(
' Wrote SKP to %s' % skp_file)
178if __name__ ==
'__main__':
def __init__(self, name, package, activity, app_launch_delay, actions)
def __init__(self, start, end, duration, points)
def __init__(self, button, press_type)
def remote_file_exists(filename)
def capture_skp(skp_file, package, device)
def parse_action(action_dict)
def print(*args, **kwargs)
static SkString join(const CommandLineFlags::StringArray &)