OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 a variety of device interactions based on adb. | 5 """Provides a variety of device interactions based on adb. |
6 | 6 |
7 Eventually, this will be based on adb_wrapper. | 7 Eventually, this will be based on adb_wrapper. |
8 """ | 8 """ |
9 # pylint: disable=W0613 | 9 # pylint: disable=W0613 |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 | 63 |
64 @decorators.WithExplicitTimeoutAndRetries( | 64 @decorators.WithExplicitTimeoutAndRetries( |
65 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) | 65 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) |
66 def RestartServer(): | 66 def RestartServer(): |
67 """Restarts the adb server. | 67 """Restarts the adb server. |
68 | 68 |
69 Raises: | 69 Raises: |
70 CommandFailedError if we fail to kill or restart the server. | 70 CommandFailedError if we fail to kill or restart the server. |
71 """ | 71 """ |
72 pylib.android_commands.AndroidCommands().RestartAdbServer() | 72 def adb_killed(): |
| 73 status, _ = cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb']) |
| 74 return status != 0 # pgrep didn't find adb, kill-server succeeded |
| 75 |
| 76 def adb_started(): |
| 77 status, _ = cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb']) |
| 78 return status == 0 # pgrep found adb, start-server succeeded |
| 79 |
| 80 adb_wrapper.AdbWrapper.KillServer() |
| 81 if not timeout_retry.WaitFor(adb_killed, wait_period=1, max_tries=5): |
| 82 raise device_errors.CommandFailedError('Failed to kill adb server') |
| 83 adb_wrapper.AdbWrapper.StartServer() |
| 84 if not timeout_retry.WaitFor(adb_started, wait_period=1, max_tries=5): |
| 85 raise device_errors.CommandFailedError('Failed to start adb server') |
73 | 86 |
74 | 87 |
75 class DeviceUtils(object): | 88 class DeviceUtils(object): |
76 | 89 |
77 _VALID_SHELL_VARIABLE = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$') | 90 _VALID_SHELL_VARIABLE = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$') |
78 | 91 |
79 def __init__(self, device, default_timeout=_DEFAULT_TIMEOUT, | 92 def __init__(self, device, default_timeout=_DEFAULT_TIMEOUT, |
80 default_retries=_DEFAULT_RETRIES): | 93 default_retries=_DEFAULT_RETRIES): |
81 """DeviceUtils constructor. | 94 """DeviceUtils constructor. |
82 | 95 |
(...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 Returns: | 1282 Returns: |
1270 A Parallelizer operating over |devices|. | 1283 A Parallelizer operating over |devices|. |
1271 """ | 1284 """ |
1272 if not devices: | 1285 if not devices: |
1273 devices = adb_wrapper.AdbWrapper.GetDevices() | 1286 devices = adb_wrapper.AdbWrapper.GetDevices() |
1274 devices = [d if isinstance(d, cls) else cls(d) for d in devices] | 1287 devices = [d if isinstance(d, cls) else cls(d) for d in devices] |
1275 if async: | 1288 if async: |
1276 return parallelizer.Parallelizer(devices) | 1289 return parallelizer.Parallelizer(devices) |
1277 else: | 1290 else: |
1278 return parallelizer.SyncParallelizer(devices) | 1291 return parallelizer.SyncParallelizer(devices) |
OLD | NEW |