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 1440961aa5ec8f31b0a8dc88aab4a945a5dec3a5..cdcb7803f8c653e5d71f91572752db8774f17bee 100644 |
| --- a/build/android/pylib/device/device_utils.py |
| +++ b/build/android/pylib/device/device_utils.py |
| @@ -16,6 +16,7 @@ import sys |
| import pylib.android_commands |
| from pylib.device import adb_wrapper |
| from pylib.device import decorators |
| +from pylib.device import device_errors |
| CHROME_SRC_DIR = os.path.abspath( |
| os.path.join(os.path.dirname(__file__), '..', '..', '..', '..')) |
| @@ -78,7 +79,20 @@ def RestartServer(): |
| class DeviceUtils(object): |
| - def __init__(self, device): |
| + def __init__(self, device, default_timeout=_DEFAULT_TIMEOUT, |
| + default_retries=_DEFAULT_RETRIES): |
| + """ DeviceUtils constructor. |
| + |
| + Args: |
| + device: Either a device serial, an existing AdbWrapper instance, an |
| + an existing AndroidCommands instance, or nothing. |
| + default_timeout: An integer containing the default number of seconds to |
| + wait for an operation to complete if no explicit value |
| + is provided. |
| + default_retries: An integer containing the default number or times an |
| + operation should be retried on failure if no explicit |
| + value is provided. |
| + """ |
| self.old_interface = None |
| if isinstance(device, basestring): |
| self.old_interface = pylib.android_commands.AndroidCommands(device) |
| @@ -88,4 +102,55 @@ class DeviceUtils(object): |
| self.old_interface = device |
| elif not device: |
| self.old_interface = pylib.android_commands.AndroidCommands() |
| + else: |
| + raise device_errors.DeviceUnreachableError('Unexpected device type?') |
|
craigdh
2014/05/14 20:33:08
This error message is confusing (is my physical de
jbudorick
2014/05/14 21:02:01
Done.
|
| + self._default_timeout = default_timeout |
| + self._default_retries = default_retries |
| + |
| + @decorators.WithTimeoutAndRetriesFromInstance( |
| + '_default_timeout', '_default_retries') |
|
craigdh
2014/05/14 20:33:08
I think it would be fine to default to these value
jbudorick
2014/05/14 21:02:01
Holding for now, but I'm interested to hear what t
|
| + def IsOnline(self, timeout=None, retries=None): |
| + """ Checks whether the device is online. |
| + |
| + Args: |
| + timeout: An integer containing the number of seconds to wait for the |
| + operation to complete. |
| + retries: An integer containing the number of times the operation should |
| + be retried if it fails. |
| + Returns: |
| + True if the device is online, False otherwise. |
| + """ |
| + return self.old_interface.IsOnline() |
| + |
| + @decorators.WithTimeoutAndRetriesFromInstance( |
| + '_default_timeout', '_default_retries') |
| + def HasRoot(self, timeout=None, retries=None): |
| + """ Checks whether or not adbd has root priveleges. |
| + |
| + Args: |
| + timeout: An integer containing the number of seconds to wait for the |
| + operation to complete. |
| + retries: An integer containing the number of times the operation should |
| + be retried if it fails. |
| + Returns: |
| + True if adbd has root priveleges, False otherwise. |
| + """ |
| + return self.old_interface.IsRootEnabled() |
| + |
| + @decorators.WithTimeoutAndRetriesFromInstance( |
| + '_default_timeout', '_default_retries') |
| + def EnableRoot(self, timeout=None, retries=None): |
| + """ Restarts adbd with root priveleges. |
| + |
| + Args: |
| + timeout: An integer containing the number of seconds to wait for the |
| + operation to complete. |
| + retries: An integer containing the number of times the operation should |
| + be retried if it fails. |
| + Raises: |
| + CommandFailedError if root could not be enabled. |
| + """ |
| + if not self.old_interface.EnableAdbRoot(): |
| + raise device_errors.CommandFailedError( |
| + 'adb root', 'Could not enable root.') |