OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 """This module wraps Android's adb tool. | 5 """This module wraps Android's adb tool. |
6 | 6 |
7 This is a thin wrapper around the adb interface. Any additional complexity | 7 This is a thin wrapper around the adb interface. Any additional complexity |
8 should be delegated to a higher level (ex. DeviceUtils). | 8 should be delegated to a higher level (ex. DeviceUtils). |
9 """ | 9 """ |
10 | 10 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 |expect_rc|. | 169 |expect_rc|. |
170 """ | 170 """ |
171 if expect_rc is None: | 171 if expect_rc is None: |
172 actual_command = command | 172 actual_command = command |
173 else: | 173 else: |
174 actual_command = '%s; echo $?;' % command | 174 actual_command = '%s; echo $?;' % command |
175 output = self._DeviceAdbCmd( | 175 output = self._DeviceAdbCmd( |
176 ['shell', actual_command], timeout, retries, check_error=False) | 176 ['shell', actual_command], timeout, retries, check_error=False) |
177 if expect_rc is not None: | 177 if expect_rc is not None: |
178 output_end = output.rstrip().rfind('\n') + 1 | 178 output_end = output.rstrip().rfind('\n') + 1 |
179 rc = output[output_end:].strip() | 179 rc = int(output[output_end:].strip()) |
180 output = output[:output_end] | 180 output = output[:output_end] |
181 if int(rc) != expect_rc: | 181 if rc != expect_rc: |
182 raise device_errors.AdbCommandFailedError( | 182 raise device_errors.AdbShellCommandFailedError( |
183 ['shell', command], | 183 command, rc, output, self._device_serial) |
184 'shell command exited with code: %s' % rc, | |
185 self._device_serial) | |
186 return output | 184 return output |
187 | 185 |
188 def Logcat(self, filter_spec=None, timeout=_DEFAULT_TIMEOUT, | 186 def Logcat(self, filter_spec=None, timeout=_DEFAULT_TIMEOUT, |
189 retries=_DEFAULT_RETRIES): | 187 retries=_DEFAULT_RETRIES): |
190 """Get the logcat output. | 188 """Get the logcat output. |
191 | 189 |
192 Args: | 190 Args: |
193 filter_spec: (optional) Spec to filter the logcat. | 191 filter_spec: (optional) Spec to filter the logcat. |
194 timeout: (optional) Timeout per try in seconds. | 192 timeout: (optional) Timeout per try in seconds. |
195 retries: (optional) Number of retries to attempt. | 193 retries: (optional) Number of retries to attempt. |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 """Restarts the adbd daemon with root permissions, if possible. | 376 """Restarts the adbd daemon with root permissions, if possible. |
379 | 377 |
380 Args: | 378 Args: |
381 timeout: (optional) Timeout per try in seconds. | 379 timeout: (optional) Timeout per try in seconds. |
382 retries: (optional) Number of retries to attempt. | 380 retries: (optional) Number of retries to attempt. |
383 """ | 381 """ |
384 output = self._DeviceAdbCmd(['root'], timeout, retries) | 382 output = self._DeviceAdbCmd(['root'], timeout, retries) |
385 if 'cannot' in output: | 383 if 'cannot' in output: |
386 raise device_errors.AdbCommandFailedError(['root'], output) | 384 raise device_errors.AdbCommandFailedError(['root'], output) |
387 | 385 |
OLD | NEW |