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 def adb_killed(): | 72 pylib.android_commands.AndroidCommands().RestartAdbServer() |
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') | |
86 | 73 |
87 | 74 |
88 class DeviceUtils(object): | 75 class DeviceUtils(object): |
89 | 76 |
90 _VALID_SHELL_VARIABLE = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$') | 77 _VALID_SHELL_VARIABLE = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$') |
91 | 78 |
92 def __init__(self, device, default_timeout=_DEFAULT_TIMEOUT, | 79 def __init__(self, device, default_timeout=_DEFAULT_TIMEOUT, |
93 default_retries=_DEFAULT_RETRIES): | 80 default_retries=_DEFAULT_RETRIES): |
94 """DeviceUtils constructor. | 81 """DeviceUtils constructor. |
95 | 82 |
(...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 Returns: | 1269 Returns: |
1283 A Parallelizer operating over |devices|. | 1270 A Parallelizer operating over |devices|. |
1284 """ | 1271 """ |
1285 if not devices: | 1272 if not devices: |
1286 devices = adb_wrapper.AdbWrapper.GetDevices() | 1273 devices = adb_wrapper.AdbWrapper.GetDevices() |
1287 devices = [d if isinstance(d, cls) else cls(d) for d in devices] | 1274 devices = [d if isinstance(d, cls) else cls(d) for d in devices] |
1288 if async: | 1275 if async: |
1289 return parallelizer.Parallelizer(devices) | 1276 return parallelizer.Parallelizer(devices) |
1290 else: | 1277 else: |
1291 return parallelizer.SyncParallelizer(devices) | 1278 return parallelizer.SyncParallelizer(devices) |
OLD | NEW |