Chromium Code Reviews| Index: build/android/pylib/device/device_utils.py |
| diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py |
| index c8a5c3a48124107fe9142489c6cf999e4d143eb4..5d75f857192a148c6f78e499c98fd461dbf82b87 100644 |
| --- a/build/android/pylib/device/device_utils.py |
| +++ b/build/android/pylib/device/device_utils.py |
| @@ -7,15 +7,78 @@ Provides a variety of device interactions based on adb. |
| Eventually, this will be based on adb_wrapper. |
| """ |
| +# pylint: disable=W0613 |
| import pylib.android_commands |
| from pylib.device import adb_wrapper |
| +from pylib.utils import reraiser_thread |
| +from pylib.utils import timeout_retry |
| -def GetAVDs(): |
| +_DEFAULT_TIMEOUT = 30 |
| +_DEFAULT_RETRIES = 3 |
| + |
| + |
| +def RunWithTimeoutAndRetries(f, *args, **kwargs): |
|
frankf
2014/05/01 18:31:01
There's also something similar in AdbWrapper. Can
|
| + """ Handles the timeout and retry logic. |
| + Args: |
| + f: The callable object to run with timeout and retry support. |
| + """ |
| + assert('timeout' in kwargs and 'retries' in kwargs) |
| + timeout = kwargs['timeout'] |
| + retries = kwargs['retries'] |
| + |
| + def bound_f(): |
| + return f(*args, **kwargs) |
| + |
| + try: |
| + return timeout_retry.Run(bound_f, timeout, retries) |
| + except reraiser_thread.TimeoutError as e: |
| + raise adb_wrapper.CommandTimeoutError(str(e)) |
| + |
| + |
| +def GetAVDs(timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): |
| + """ Returns a list of Android Virtual Devices. |
| + |
| + Args: |
| + timeout: The length of time to wait before giving up on either killing or |
| + restarting the server. |
| + retries: The number of times to retry either killing or restarting the |
| + server. |
| + Returns: |
| + A list containing the configured AVDs. |
| + """ |
| + return RunWithTimeoutAndRetries(_GetAVDsImpl, timeout=timeout, |
| + retries=retries) |
| + |
| + |
| +def _GetAVDsImpl(): |
| + """ Implementation of GetAVDs. |
| + """ |
| return pylib.android_commands.GetAVDs() |
| +def RestartServer(timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): |
|
frankf
2014/05/01 18:31:01
RestartServer -> RestartAdbServer
|
| + """ Restarts the adb server. |
| + |
| + Args: |
| + timeout: The length of time to wait before giving up on either killing or |
| + restarting the server. |
| + retries: The number of times to retry either killing or restarting the |
| + server. |
| + Raises: |
| + CommandFailedError if we fail to kill or restart the server. |
| + """ |
| + RunWithTimeoutAndRetries(_RestartServerImpl, timeout=timeout, |
| + retries=retries) |
| + |
| + |
| +def _RestartServerImpl(): |
| + """ Implementation of RestartServer. |
| + """ |
| + pylib.android_commands.AndroidCommands().RestartAdbServer() |
|
frankf
2014/05/01 18:31:01
You should think of thread-safety for any method y
|
| + |
| + |
| class DeviceUtils(object): |
| def __init__(self, device): |