Chromium Code Reviews| 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 import threading | |
| 14 import time | |
| 13 | 15 |
| 14 from pylib import cmd_helper | 16 from pylib import cmd_helper |
| 15 from pylib.device import decorators | 17 from pylib.device import decorators |
| 16 from pylib.device import device_errors | 18 from pylib.device import device_errors |
| 19 from pylib.utils import timeout_retry | |
| 17 | 20 |
| 18 | 21 |
| 19 _DEFAULT_TIMEOUT = 30 | 22 _DEFAULT_TIMEOUT = 30 |
| 20 _DEFAULT_RETRIES = 2 | 23 _DEFAULT_RETRIES = 2 |
| 21 | 24 |
| 22 | 25 |
| 23 def _VerifyLocalFileExists(path): | 26 def _VerifyLocalFileExists(path): |
| 24 """Verifies a local file exists. | 27 """Verifies a local file exists. |
| 25 | 28 |
| 26 Args: | 29 Args: |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 37 """A wrapper around a local Android Debug Bridge executable.""" | 40 """A wrapper around a local Android Debug Bridge executable.""" |
| 38 | 41 |
| 39 def __init__(self, device_serial): | 42 def __init__(self, device_serial): |
| 40 """Initializes the AdbWrapper. | 43 """Initializes the AdbWrapper. |
| 41 | 44 |
| 42 Args: | 45 Args: |
| 43 device_serial: The device serial number as a string. | 46 device_serial: The device serial number as a string. |
| 44 """ | 47 """ |
| 45 self._device_serial = str(device_serial) | 48 self._device_serial = str(device_serial) |
| 46 | 49 |
| 50 @classmethod | |
| 51 def Wait(cls, secs): | |
| 52 """Wait for the specified ammount of seconds. | |
| 53 | |
| 54 A drop-in replacement for time.sleep, which just waits for a number of | |
| 55 seconds. After the wait is over, however, the method checks to see whether | |
| 56 we're running under a timed-out thread and raises an exception if needed. | |
| 57 | |
| 58 Args: | |
| 59 secs: the number of seconds to sleep | |
| 60 """ | |
| 61 time.sleep(secs) | |
| 62 current_thread = threading.current_thread() | |
| 63 if isinstance(current_thread, timeout_retry.TimeoutRetryThread): | |
| 64 current_thread.CheckTimeout() | |
| 65 | |
| 47 # pylint: disable=W0613 | 66 # pylint: disable=W0613 |
| 48 @classmethod | 67 @classmethod |
| 49 @decorators.WithTimeoutAndRetries | 68 @decorators.WithTimeoutAndRetries |
| 50 def _RunAdbCmd(cls, arg_list, timeout=None, retries=None, check_error=True): | 69 def _RunAdbCmd(cls, arg_list, timeout=None, retries=None, check_error=True): |
| 51 cmd = ['adb'] + arg_list | 70 cmd = ['adb'] + arg_list |
| 52 exit_code, output = cmd_helper.GetCmdStatusAndOutput(cmd) | 71 try: |
| 72 exit_code, output = cmd_helper.GetCmdStatusAndOutput(cmd) | |
| 73 finally: | |
| 74 threading.current_thread().CheckTimeout() | |
|
perezju
2014/10/28 14:31:18
doing the check here at least we: (1) make sure th
| |
| 53 if exit_code != 0: | 75 if exit_code != 0: |
| 54 raise device_errors.AdbCommandFailedError( | 76 raise device_errors.AdbCommandFailedError( |
| 55 cmd, 'returned non-zero exit code %s, output: %s' % | 77 cmd, 'returned non-zero exit code %d and output %r' % |
| 56 (exit_code, output)) | 78 (exit_code, output)) |
| 57 # This catches some errors, including when the device drops offline; | 79 # This catches some errors, including when the device drops offline; |
| 58 # unfortunately adb is very inconsistent with error reporting so many | 80 # unfortunately adb is very inconsistent with error reporting so many |
| 59 # command failures present differently. | 81 # command failures present differently. |
| 60 if check_error and output[:len('error:')] == 'error:': | 82 if check_error and output[:len('error:')] == 'error:': |
| 61 raise device_errors.AdbCommandFailedError(arg_list, output) | 83 raise device_errors.AdbCommandFailedError(arg_list, output) |
| 62 return output | 84 return output |
| 63 # pylint: enable=W0613 | 85 # pylint: enable=W0613 |
| 64 | 86 |
| 65 def _DeviceAdbCmd(self, arg_list, timeout, retries, check_error=True): | 87 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. | 409 """Restarts the adbd daemon with root permissions, if possible. |
| 388 | 410 |
| 389 Args: | 411 Args: |
| 390 timeout: (optional) Timeout per try in seconds. | 412 timeout: (optional) Timeout per try in seconds. |
| 391 retries: (optional) Number of retries to attempt. | 413 retries: (optional) Number of retries to attempt. |
| 392 """ | 414 """ |
| 393 output = self._DeviceAdbCmd(['root'], timeout, retries) | 415 output = self._DeviceAdbCmd(['root'], timeout, retries) |
| 394 if 'cannot' in output: | 416 if 'cannot' in output: |
| 395 raise device_errors.AdbCommandFailedError(['root'], output) | 417 raise device_errors.AdbCommandFailedError(['root'], output) |
| 396 | 418 |
| OLD | NEW |