Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1066)

Unified Diff: build/android/pylib/device/device_utils.py

Issue 285143002: [Android] Convert to DeviceUtils versions of IsOnline, HasRoot, and EnableRoot. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..defd544db71b15aaa75d793d75c7f4e9d2aad90b 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 ValueError('Unsupported type passed for argument "device"')
+ self._default_timeout = default_timeout
+ self._default_retries = default_retries
+
+ @decorators.WithTimeoutAndRetriesFromInstance(
+ '_default_timeout', '_default_retries')
+ 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
frankf 2014/05/15 01:27:59 DRY applies to docstrings as well ;)
jbudorick 2014/05/15 05:03:54 "An integer containing the seconds to wait ...?" I
frankf 2014/05/15 17:40:08 To clarify, you've repeated the same Args section
+ 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.
frankf 2014/05/15 01:27:59 typo
+
+ 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():
frankf 2014/05/15 01:27:59 Why can't you inline EnableAdbRoot here?
jbudorick 2014/05/15 05:03:54 What exactly do you mean by "inline" in a python c
frankf 2014/05/15 17:40:08 Yes, otherwise you would to do another pass to mov
+ raise device_errors.CommandFailedError(
+ 'adb root', 'Could not enable root.')

Powered by Google App Engine
This is Rietveld 408576698