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

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

Issue 783543003: Update from https://crrev.com/306901 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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/adb_wrapper_test.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 0ff3a8454799eccc160b4aaf357b1f1bb34dc2d3..66a62fd4b847f32f48bd8fb1b8ccec1eb5717caa 100644
--- a/build/android/pylib/device/device_utils.py
+++ b/build/android/pylib/device/device_utils.py
@@ -557,13 +557,14 @@ class DeviceUtils(object):
CommandTimeoutError on timeout.
DeviceUnreachableError on missing device.
"""
- package, old_intent = intent.action.rsplit('.', 1)
- if intent.extras is None:
- args = []
- else:
- args = ['-e %s%s' % (k, ' "%s"' % v if v else '')
- for k, v in intent.extras.items() if len(k) > 0]
- self.old_interface.BroadcastIntent(package, old_intent, *args)
+ cmd = ['am', 'broadcast', '-a', intent.action]
+ if intent.extras:
+ for key, value in intent.extras.iteritems():
+ if key:
+ cmd.extend(['-e', key])
+ if value:
+ cmd.append(str(value))
+ self.RunShellCommand(cmd, check_return=True)
@decorators.WithTimeoutAndRetriesFromInstance()
def GoHome(self, timeout=None, retries=None):
@@ -592,7 +593,7 @@ class DeviceUtils(object):
CommandTimeoutError on timeout.
DeviceUnreachableError on missing device.
"""
- self.old_interface.CloseApplication(package)
+ self.RunShellCommand(['am', 'force-stop', package], check_return=True)
@decorators.WithTimeoutAndRetriesFromInstance()
def ClearApplicationState(self, package, timeout=None, retries=None):
@@ -607,7 +608,10 @@ class DeviceUtils(object):
CommandTimeoutError on timeout.
DeviceUnreachableError on missing device.
"""
- self.old_interface.ClearApplicationState(package)
+ # Check that the package exists before clearing it. Necessary because
+ # calling pm clear on a package that doesn't exist may never return.
+ if self.GetApplicationPath(package):
+ self.RunShellCommand(['pm', 'clear', package], check_return=True)
@decorators.WithTimeoutAndRetriesFromInstance()
def SendKeyEvent(self, keycode, timeout=None, retries=None):
@@ -624,7 +628,8 @@ class DeviceUtils(object):
CommandTimeoutError on timeout.
DeviceUnreachableError on missing device.
"""
- self.old_interface.SendKeyEvent(keycode)
+ self.RunShellCommand(['input', 'keyevent', format(keycode, 'd')],
+ check_return=True)
PUSH_CHANGED_FILES_DEFAULT_TIMEOUT = 10 * _DEFAULT_TIMEOUT
PUSH_CHANGED_FILES_DEFAULT_RETRIES = _DEFAULT_RETRIES
@@ -938,13 +943,41 @@ class DeviceUtils(object):
retries: number of retries
Returns:
- The contents of the directory specified by |device_path|.
+ A list of pairs (filename, stat) for each file found in the directory,
+ where the stat object has the properties: st_mode, st_size, and st_time.
+
+ Raises:
+ AdbCommandFailedError if |device_path| does not specify a valid and
+ accessible directory in the device.
+ CommandTimeoutError on timeout.
+ DeviceUnreachableError on missing device.
+ """
+ return self.adb.Ls(device_path)
+
+ @decorators.WithTimeoutAndRetriesFromInstance()
+ def Stat(self, device_path, timeout=None, retries=None):
+ """Get the stat attributes of a file or directory on the device.
+
+ Args:
+ device_path: A string containing the path of from which to get attributes
+ on the device.
+ timeout: timeout in seconds
+ retries: number of retries
+
+ Returns:
+ A stat object with the properties: st_mode, st_size, and st_time
Raises:
+ CommandFailedError if device_path cannot be found on the device.
CommandTimeoutError on timeout.
DeviceUnreachableError on missing device.
"""
- return self.old_interface.ListPathContents(device_path)
+ dirname, target = device_path.rsplit('/', 1)
+ for filename, stat in self.adb.Ls(dirname):
+ if filename == target:
+ return stat
+ raise device_errors.CommandFailedError(
+ 'Cannot find file or directory: %r' % device_path, str(self))
@decorators.WithTimeoutAndRetriesFromInstance()
def SetJavaAsserts(self, enabled, timeout=None, retries=None):
« no previous file with comments | « build/android/pylib/device/adb_wrapper_test.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