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

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
« no previous file with comments | « build/android/pylib/device/decorators.py ('k') | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ea1019d3de996f44b6bcb95785541b7570ee4344 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,51 @@ 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
+ 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 privileges.
+
+ Args:
+ timeout: Same as for |IsOnline|.
+ retries: Same as for |IsOnline|.
+ Returns:
+ True if adbd has root privileges, False otherwise.
+ """
+ return self.old_interface.IsRootEnabled()
+
+ @decorators.WithTimeoutAndRetriesFromInstance(
+ '_default_timeout', '_default_retries')
+ def EnableRoot(self, timeout=None, retries=None):
+ """ Restarts adbd with root privileges.
+
+ Args:
+ timeout: Same as for |IsOnline|.
+ retries: Same as for |IsOnline|.
+ Raises:
+ CommandFailedError if root could not be enabled.
+ """
+ if not self.old_interface.EnableAdbRoot():
+ raise device_errors.CommandFailedError(
+ 'adb root', 'Could not enable root.')
« no previous file with comments | « build/android/pylib/device/decorators.py ('k') | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698