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 |
11 import errno | 11 import errno |
12 import os | 12 import os |
13 | 13 |
14 from pylib import cmd_helper | 14 from pylib import cmd_helper |
15 from pylib.device import decorators | 15 from pylib.device import decorators |
16 from pylib.device import device_errors | 16 from pylib.device import device_errors |
| 17 from pylib.utils import timeout_retry |
17 | 18 |
18 | 19 |
19 _DEFAULT_TIMEOUT = 30 | 20 _DEFAULT_TIMEOUT = 30 |
20 _DEFAULT_RETRIES = 2 | 21 _DEFAULT_RETRIES = 2 |
21 | 22 |
22 | 23 |
23 def _VerifyLocalFileExists(path): | 24 def _VerifyLocalFileExists(path): |
24 """Verifies a local file exists. | 25 """Verifies a local file exists. |
25 | 26 |
26 Args: | 27 Args: |
(...skipping 15 matching lines...) Expand all Loading... |
42 Args: | 43 Args: |
43 device_serial: The device serial number as a string. | 44 device_serial: The device serial number as a string. |
44 """ | 45 """ |
45 self._device_serial = str(device_serial) | 46 self._device_serial = str(device_serial) |
46 | 47 |
47 # pylint: disable=W0613 | 48 # pylint: disable=W0613 |
48 @classmethod | 49 @classmethod |
49 @decorators.WithTimeoutAndRetries | 50 @decorators.WithTimeoutAndRetries |
50 def _RunAdbCmd(cls, arg_list, timeout=None, retries=None, check_error=True): | 51 def _RunAdbCmd(cls, arg_list, timeout=None, retries=None, check_error=True): |
51 cmd = ['adb'] + arg_list | 52 cmd = ['adb'] + arg_list |
52 exit_code, output = cmd_helper.GetCmdStatusAndOutput(cmd) | 53 exit_code, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( |
| 54 cmd, timeout_retry.CurrentTimeoutThread().GetRemainingTime()) |
53 if exit_code != 0: | 55 if exit_code != 0: |
54 raise device_errors.AdbCommandFailedError( | 56 raise device_errors.AdbCommandFailedError( |
55 cmd, 'returned non-zero exit code %s, output: %s' % | 57 cmd, 'returned non-zero exit code %d and output %r' % |
56 (exit_code, output)) | 58 (exit_code, output)) |
57 # This catches some errors, including when the device drops offline; | 59 # This catches some errors, including when the device drops offline; |
58 # unfortunately adb is very inconsistent with error reporting so many | 60 # unfortunately adb is very inconsistent with error reporting so many |
59 # command failures present differently. | 61 # command failures present differently. |
60 if check_error and output[:len('error:')] == 'error:': | 62 if check_error and output[:len('error:')] == 'error:': |
61 raise device_errors.AdbCommandFailedError(arg_list, output) | 63 raise device_errors.AdbCommandFailedError(arg_list, output) |
62 return output | 64 return output |
63 # pylint: enable=W0613 | 65 # pylint: enable=W0613 |
64 | 66 |
65 def _DeviceAdbCmd(self, arg_list, timeout, retries, check_error=True): | 67 def _DeviceAdbCmd(self, arg_list, timeout, retries, check_error=True): |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 """Restarts the adbd daemon with root permissions, if possible. | 389 """Restarts the adbd daemon with root permissions, if possible. |
388 | 390 |
389 Args: | 391 Args: |
390 timeout: (optional) Timeout per try in seconds. | 392 timeout: (optional) Timeout per try in seconds. |
391 retries: (optional) Number of retries to attempt. | 393 retries: (optional) Number of retries to attempt. |
392 """ | 394 """ |
393 output = self._DeviceAdbCmd(['root'], timeout, retries) | 395 output = self._DeviceAdbCmd(['root'], timeout, retries) |
394 if 'cannot' in output: | 396 if 'cannot' in output: |
395 raise device_errors.AdbCommandFailedError(['root'], output) | 397 raise device_errors.AdbCommandFailedError(['root'], output) |
396 | 398 |
OLD | NEW |