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 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 | 34 |
| 35 DEFAULT_TIMEOUT = 30 | 35 DEFAULT_TIMEOUT = 30 |
| 36 DEFAULT_RETRIES = 2 | 36 DEFAULT_RETRIES = 2 |
| 37 | 37 |
| 38 _ADB_VERSION_RE = re.compile(r'Android Debug Bridge version (\d+\.\d+\.\d+)') | 38 _ADB_VERSION_RE = re.compile(r'Android Debug Bridge version (\d+\.\d+\.\d+)') |
| 39 _EMULATOR_RE = re.compile(r'^emulator-[0-9]+$') | 39 _EMULATOR_RE = re.compile(r'^emulator-[0-9]+$') |
| 40 _DEVICE_NOT_FOUND_RE = re.compile(r"error: device '(?P<serial>.+)' not found") | 40 _DEVICE_NOT_FOUND_RE = re.compile(r"error: device '(?P<serial>.+)' not found") |
| 41 _READY_STATE = 'device' | 41 _READY_STATE = 'device' |
| 42 _VERITY_DISABLE_RE = re.compile(r'Verity (already )?disabled') | 42 _VERITY_DISABLE_RE = re.compile(r'Verity (already )?disabled') |
| 43 _VERITY_ENABLE_RE = re.compile(r'Verity (already )?enabled') | 43 _VERITY_ENABLE_RE = re.compile(r'Verity (already )?enabled') |
| 44 _WAITING_FOR_DEVICE_RE = re.compile(r'- waiting for device -') | |
| 44 | 45 |
| 45 | 46 |
| 46 def VerifyLocalFileExists(path): | 47 def VerifyLocalFileExists(path): |
| 47 """Verifies a local file exists. | 48 """Verifies a local file exists. |
| 48 | 49 |
| 49 Args: | 50 Args: |
| 50 path: Path to the local file. | 51 path: Path to the local file. |
| 51 | 52 |
| 52 Raises: | 53 Raises: |
| 53 IOError: If the file doesn't exist. | 54 IOError: If the file doesn't exist. |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 except OSError as e: | 263 except OSError as e: |
| 263 if e.errno in (errno.ENOENT, errno.ENOEXEC): | 264 if e.errno in (errno.ENOENT, errno.ENOEXEC): |
| 264 raise device_errors.NoAdbError(msg=str(e)) | 265 raise device_errors.NoAdbError(msg=str(e)) |
| 265 else: | 266 else: |
| 266 raise | 267 raise |
| 267 | 268 |
| 268 # Best effort to catch errors from adb; unfortunately adb is very | 269 # Best effort to catch errors from adb; unfortunately adb is very |
| 269 # inconsistent with error reporting so many command failures present | 270 # inconsistent with error reporting so many command failures present |
| 270 # differently. | 271 # differently. |
| 271 if status != 0 or (check_error and output.startswith('error:')): | 272 if status != 0 or (check_error and output.startswith('error:')): |
| 272 m = _DEVICE_NOT_FOUND_RE.match(output) | 273 not_found_m = _DEVICE_NOT_FOUND_RE.match(output) |
| 273 if m is not None and m.group('serial') == device_serial: | 274 device_waiting_m = _WAITING_FOR_DEVICE_RE.match(output) |
| 275 if device_waiting_m is not None or (not_found_m is not None and | |
|
jbudorick
2017/08/19 00:22:13
nit: this would be a bit easier to read w/ the lin
bpastene
2017/08/19 00:50:31
Done.
| |
| 276 not_found_m.group('serial') == device_serial): | |
| 274 raise device_errors.DeviceUnreachableError(device_serial) | 277 raise device_errors.DeviceUnreachableError(device_serial) |
| 275 else: | 278 else: |
| 276 raise device_errors.AdbCommandFailedError( | 279 raise device_errors.AdbCommandFailedError( |
| 277 args, output, status, device_serial) | 280 args, output, status, device_serial) |
| 278 | 281 |
| 279 return output | 282 return output |
| 280 # pylint: enable=unused-argument | 283 # pylint: enable=unused-argument |
| 281 | 284 |
| 282 def _RunDeviceAdbCmd(self, args, timeout, retries, check_error=True): | 285 def _RunDeviceAdbCmd(self, args, timeout, retries, check_error=True): |
| 283 """Runs an adb command on the device associated with this object. | 286 """Runs an adb command on the device associated with this object. |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 927 @property | 930 @property |
| 928 def is_emulator(self): | 931 def is_emulator(self): |
| 929 return _EMULATOR_RE.match(self._device_serial) | 932 return _EMULATOR_RE.match(self._device_serial) |
| 930 | 933 |
| 931 @property | 934 @property |
| 932 def is_ready(self): | 935 def is_ready(self): |
| 933 try: | 936 try: |
| 934 return self.GetState() == _READY_STATE | 937 return self.GetState() == _READY_STATE |
| 935 except device_errors.CommandFailedError: | 938 except device_errors.CommandFailedError: |
| 936 return False | 939 return False |
| OLD | NEW |