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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 | 47 |
48 @decorators.WithExplicitTimeoutAndRetries( | 48 @decorators.WithExplicitTimeoutAndRetries( |
49 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) | 49 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) |
50 def RestartServer(): | 50 def RestartServer(): |
51 """Restarts the adb server. | 51 """Restarts the adb server. |
52 | 52 |
53 Raises: | 53 Raises: |
54 CommandFailedError if we fail to kill or restart the server. | 54 CommandFailedError if we fail to kill or restart the server. |
55 """ | 55 """ |
56 pylib.android_commands.AndroidCommands().RestartAdbServer() | 56 def adb_killed(): |
| 57 status, _ = cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb']) |
| 58 return status != 0 # pgrep didn't find adb, kill-server succeeded |
| 59 |
| 60 def adb_started(): |
| 61 status, _ = cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb']) |
| 62 return status == 0 # pgrep found adb, start-server succeeded |
| 63 |
| 64 adb_wrapper.AdbWrapper.KillServer() |
| 65 if not timeout_retry.WaitFor(adb_killed, wait_period=1, max_tries=5): |
| 66 raise device_errors.CommandFailedError('Failed to kill adb server') |
| 67 adb_wrapper.AdbWrapper.StartServer() |
| 68 if not timeout_retry.WaitFor(adb_started, wait_period=1, max_tries=5): |
| 69 raise device_errors.CommandFailedError('Failed to start adb server') |
57 | 70 |
58 | 71 |
59 class DeviceUtils(object): | 72 class DeviceUtils(object): |
60 | 73 |
61 _VALID_SHELL_VARIABLE = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$') | 74 _VALID_SHELL_VARIABLE = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$') |
62 | 75 |
63 def __init__(self, device, default_timeout=_DEFAULT_TIMEOUT, | 76 def __init__(self, device, default_timeout=_DEFAULT_TIMEOUT, |
64 default_retries=_DEFAULT_RETRIES): | 77 default_retries=_DEFAULT_RETRIES): |
65 """DeviceUtils constructor. | 78 """DeviceUtils constructor. |
66 | 79 |
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 Returns: | 1207 Returns: |
1195 A Parallelizer operating over |devices|. | 1208 A Parallelizer operating over |devices|. |
1196 """ | 1209 """ |
1197 if not devices or len(devices) == 0: | 1210 if not devices or len(devices) == 0: |
1198 devices = pylib.android_commands.GetAttachedDevices() | 1211 devices = pylib.android_commands.GetAttachedDevices() |
1199 parallelizer_type = (parallelizer.Parallelizer if async | 1212 parallelizer_type = (parallelizer.Parallelizer if async |
1200 else parallelizer.SyncParallelizer) | 1213 else parallelizer.SyncParallelizer) |
1201 return parallelizer_type([ | 1214 return parallelizer_type([ |
1202 d if isinstance(d, DeviceUtils) else DeviceUtils(d) | 1215 d if isinstance(d, DeviceUtils) else DeviceUtils(d) |
1203 for d in devices]) | 1216 for d in devices]) |
OLD | NEW |