| 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 ff99fccdc83729d0b3c88199cba46e116401875e..4adde1d47b273da180277eb0fcb8906c94e92fb6 100644
|
| --- a/build/android/pylib/device/device_utils.py
|
| +++ b/build/android/pylib/device/device_utils.py
|
| @@ -9,6 +9,8 @@ Eventually, this will be based on adb_wrapper.
|
| """
|
| # pylint: disable=W0613
|
|
|
| +import time
|
| +
|
| import pylib.android_commands
|
| from pylib.device import adb_wrapper
|
| from pylib.device import decorators
|
| @@ -70,9 +72,10 @@ class DeviceUtils(object):
|
| raise ValueError('Unsupported type passed for argument "device"')
|
| self._default_timeout = default_timeout
|
| self._default_retries = default_retries
|
| + assert(hasattr(self, decorators.DEFAULT_TIMEOUT_ATTR))
|
| + assert(hasattr(self, decorators.DEFAULT_RETRIES_ATTR))
|
|
|
| - @decorators.WithTimeoutAndRetriesFromInstance(
|
| - '_default_timeout', '_default_retries')
|
| + @decorators.WithTimeoutAndRetriesFromInstance()
|
| def IsOnline(self, timeout=None, retries=None):
|
| """ Checks whether the device is online.
|
|
|
| @@ -86,8 +89,7 @@ class DeviceUtils(object):
|
| """
|
| return self.old_interface.IsOnline()
|
|
|
| - @decorators.WithTimeoutAndRetriesFromInstance(
|
| - '_default_timeout', '_default_retries')
|
| + @decorators.WithTimeoutAndRetriesFromInstance()
|
| def HasRoot(self, timeout=None, retries=None):
|
| """ Checks whether or not adbd has root privileges.
|
|
|
| @@ -99,8 +101,7 @@ class DeviceUtils(object):
|
| """
|
| return self.old_interface.IsRootEnabled()
|
|
|
| - @decorators.WithTimeoutAndRetriesFromInstance(
|
| - '_default_timeout', '_default_retries')
|
| + @decorators.WithTimeoutAndRetriesFromInstance()
|
| def EnableRoot(self, timeout=None, retries=None):
|
| """ Restarts adbd with root privileges.
|
|
|
| @@ -114,12 +115,51 @@ class DeviceUtils(object):
|
| raise device_errors.CommandFailedError(
|
| 'adb root', 'Could not enable root.')
|
|
|
| + @decorators.WithTimeoutAndRetriesFromInstance()
|
| + def GetExternalStoragePath(self, timeout=None, retries=None):
|
| + """ Get the device's path to its SD card.
|
| +
|
| + Args:
|
| + timeout: Same as for |IsOnline|.
|
| + retries: Same as for |IsOnline|.
|
| + Returns:
|
| + The device's path to its SD card.
|
| + """
|
| + try:
|
| + return self.old_interface.GetExternalStorage()
|
| + except AssertionError as e:
|
| + raise device_errors.CommandFailedError(str(e))
|
| +
|
| + @decorators.WithTimeoutAndRetriesFromInstance()
|
| + def WaitUntilFullyBooted(self, wifi=False, timeout=None, retries=None):
|
| + """ Wait for the device to fully boot.
|
| +
|
| + This means waiting for the device to boot, the package manager to be
|
| + available, and the SD card to be ready. It can optionally mean waiting
|
| + for wifi to come up, too.
|
| +
|
| + Args:
|
| + wifi: A boolean indicating if we should wait for wifi to come up or not.
|
| + timeout: Same as for |IsOnline|.
|
| + retries: Same as for |IsOnline|.
|
| + Raises:
|
| + CommandTimeoutError if one of the component waits times out.
|
| + DeviceUnreachableError if the device becomes unresponsive.
|
| + """
|
| + self.old_interface.WaitForSystemBootCompleted(timeout)
|
| + self.old_interface.WaitForDevicePm()
|
| + self.old_interface.WaitForSdCardReady(timeout)
|
| + if wifi:
|
| + while not 'Wi-Fi is enabled' in (
|
| + self.old_interface.RunShellCommand('dumpsys wifi')):
|
| + time.sleep(0.1)
|
| +
|
| def __str__(self):
|
| """Returns the device serial."""
|
| return self.old_interface.GetDevice()
|
|
|
| @staticmethod
|
| - def parallel(devices):
|
| + def parallel(devices=None, async=False):
|
| """ Creates a Parallelizer to operate over the provided list of devices.
|
|
|
| If |devices| is either |None| or an empty list, the Parallelizer will
|
| @@ -127,13 +167,18 @@ class DeviceUtils(object):
|
|
|
| Args:
|
| devices: A list of either DeviceUtils instances or objects from
|
| - from which DeviceUtils instances can be constructed.
|
| + from which DeviceUtils instances can be constructed. If None,
|
| + all attached devices will be used.
|
| + async: If true, returns a Parallelizer that runs operations
|
| + asynchronously.
|
| Returns:
|
| A Parallelizer operating over |devices|.
|
| """
|
| if not devices or len(devices) == 0:
|
| - devices = pylib.android_commands.AndroidCommands.GetAttachedDevices()
|
| - return parallelizer.Parallelizer([
|
| + devices = pylib.android_commands.GetAttachedDevices()
|
| + parallelizer_type = (parallelizer.Parallelizer if async
|
| + else parallelizer.SyncParallelizer)
|
| + return parallelizer_type([
|
| d if isinstance(d, DeviceUtils) else DeviceUtils(d)
|
| for d in devices])
|
|
|
|
|