108def capture_skp(skp_file, package, device):
109 """Capture an SKP."""
110 remote_path = '/data/data/%s/cache/%s' % (package, os.path.basename(skp_file))
111 try:
112 adb_shell('rm %s' % remote_path)
113 except Exception:
114 if remote_file_exists(remote_path):
115 raise
116
117 adb_shell('setprop debug.hwui.capture_frame_as_skp %s' % remote_path)
118 try:
119
120 timeout = 10
121 start = time.time()
122 device.drag((300, 300), (300, 350), 1, 10)
123 while not remote_file_exists(remote_path):
124 if time.time() - start > timeout:
125 raise Exception('Timed out waiting for SKP capture.')
126 time.sleep(1)
127
128
129 cmd = ['adb', 'pull', remote_path, skp_file]
130 check_output(cmd)
131
132 finally:
133 adb_shell('setprop debug.hwui.capture_frame_as_skp ""')
134
135