OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Provides an interface to communicate with the device via the adb command. | 5 """Provides an interface to communicate with the device via the adb command. |
6 | 6 |
7 Assumes adb binary is currently on system path. | 7 Assumes adb binary is currently on system path. |
8 """ | 8 """ |
9 | 9 |
10 import collections | 10 import collections |
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 | 1059 |
1060 status = self._adb.SendShellCommand( | 1060 status = self._adb.SendShellCommand( |
1061 '\'ls "%s" >/dev/null 2>&1; echo $?\'' % (file_name)) | 1061 '\'ls "%s" >/dev/null 2>&1; echo $?\'' % (file_name)) |
1062 return int(status) == 0 | 1062 return int(status) == 0 |
1063 except ValueError: | 1063 except ValueError: |
1064 if IsDeviceAttached(self._device): | 1064 if IsDeviceAttached(self._device): |
1065 raise errors.DeviceUnresponsiveError('Device may be offline.') | 1065 raise errors.DeviceUnresponsiveError('Device may be offline.') |
1066 | 1066 |
1067 return False | 1067 return False |
1068 | 1068 |
| 1069 def TakeScreenshot(self, host_file): |
| 1070 """Saves a screenshot image to |host_file| on the host. |
| 1071 |
| 1072 Args: |
| 1073 host_file: Absolute path to the image file to store on the host. |
| 1074 """ |
| 1075 host_dir = os.path.dirname(host_file) |
| 1076 if not os.path.exists(host_dir): |
| 1077 os.mkdir(host_dir) |
| 1078 device_file = '%s/screenshot.png' % self.GetExternalStorage() |
| 1079 self.RunShellCommand('/system/bin/screencap -p %s' % device_file) |
| 1080 assert self._adb.Pull(device_file, host_file) |
| 1081 assert os.path.exists(host_file) |
| 1082 |
1069 | 1083 |
1070 class NewLineNormalizer(object): | 1084 class NewLineNormalizer(object): |
1071 """A file-like object to normalize EOLs to '\n'. | 1085 """A file-like object to normalize EOLs to '\n'. |
1072 | 1086 |
1073 Pexpect runs adb within a pseudo-tty device (see | 1087 Pexpect runs adb within a pseudo-tty device (see |
1074 http://www.noah.org/wiki/pexpect), so any '\n' printed by adb is written | 1088 http://www.noah.org/wiki/pexpect), so any '\n' printed by adb is written |
1075 as '\r\n' to the logfile. Since adb already uses '\r\n' to terminate | 1089 as '\r\n' to the logfile. Since adb already uses '\r\n' to terminate |
1076 lines, the log ends up having '\r\r\n' at the end of each line. This | 1090 lines, the log ends up having '\r\r\n' at the end of each line. This |
1077 filter replaces the above with a single '\n' in the data stream. | 1091 filter replaces the above with a single '\n' in the data stream. |
1078 """ | 1092 """ |
1079 def __init__(self, output): | 1093 def __init__(self, output): |
1080 self._output = output | 1094 self._output = output |
1081 | 1095 |
1082 def write(self, data): | 1096 def write(self, data): |
1083 data = data.replace('\r\r\n', '\n') | 1097 data = data.replace('\r\r\n', '\n') |
1084 self._output.write(data) | 1098 self._output.write(data) |
1085 | 1099 |
1086 def flush(self): | 1100 def flush(self): |
1087 self._output.flush() | 1101 self._output.flush() |
OLD | NEW |