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 0fee10a7fb0c701551179ae6f057ce2729318053..e887d0305f31e541ad3a7b5ae56b1e0598f1801b 100644 |
--- a/build/android/pylib/device/device_utils.py |
+++ b/build/android/pylib/device/device_utils.py |
@@ -8,6 +8,7 @@ Eventually, this will be based on adb_wrapper. |
""" |
# pylint: disable=W0613 |
+import signal |
import time |
import pylib.android_commands |
@@ -298,6 +299,68 @@ class DeviceUtils(object): |
output = self.old_interface.RunShellCommand(cmd, timeout_time=timeout) |
return output |
+ @decorators.WithTimeoutAndRetriesFromInstance() |
+ def KillAll(self, process_name, signum=signal.SIGKILL, root=False, |
+ blocking=False, timeout=None, retries=None): |
+ """Kill all processes with the given name on the device. |
frankf
2014/06/19 17:54:05
A general note: if it's not too expensive these me
jbudorick
2014/06/20 00:36:44
KillAll now raises a CommandFailedError if no proc
|
+ |
+ Args: |
+ process_name: A string containing the name of the process to kill. |
+ signum: An integer containing the signal number to send to kill. Defaults |
+ to 9 (SIGKILL). |
+ root: A boolean indicating whether the kill should be executed with root |
frankf
2014/06/19 17:54:05
I'd rename "root" to "as_root" here and above
jbudorick
2014/06/20 00:36:44
Done.
|
+ priveleges. |
+ blocking: A boolean indicating whether we should wait until all processes |
+ with the given |process_name| are dead. |
+ timeout: Same as for |IsOnline|. |
+ retries: Same as for |IsOnline|. |
+ """ |
+ if blocking: |
+ self.old_interface.KillAllBlocking(process_name, signum=signum, |
+ with_su=root, timeout_sec=timeout) |
+ else: |
+ self.old_interface.KillAll(process_name, signum=signum, with_su=root) |
+ |
+ @decorators.WithTimeoutAndRetriesFromInstance() |
+ def StartActivity(self, intent, blocking=False, trace_file_name=None, |
+ force_stop=False, timeout=None, retries=None): |
+ """Start package's activity on the device. |
+ |
+ Args: |
+ intent: An Intent to send. |
+ blocking: A boolean indicating whether we should wait for the activity to |
+ finish launching. |
+ trace_file_name: If present, a string that both indicates that we want to |
+ profile the activity and contains the path to which the |
+ trace should be saved. |
+ force_stop: A boolean indicating whether we should stop the activity |
+ before starting it. |
+ timeout: Same as for |IsOnline|. |
+ retries: Same as for |IsOnline|. |
+ """ |
+ self.old_interface.StartActivity( |
frankf
2014/06/19 17:54:05
what happens if you fail to start an activity?
jbudorick
2014/06/20 00:36:44
It was doing the same thing as AndroidCommands.Sta
|
+ intent.package, intent.activity, wait_for_completion=blocking, |
+ action=intent.action, category=intent.category, data=intent.data, |
+ extras=intent.extras, trace_file_name=trace_file_name, |
+ force_stop=force_stop, flags=intent.flags) |
+ |
+ @decorators.WithTimeoutAndRetriesFromInstance() |
+ def BroadcastIntent(self, intent, timeout=None, retries=None): |
+ """Send a broadcast intent. |
+ |
+ Args: |
+ intent: An Intent to broadcast. |
+ timeout: Same as for |IsOnline|. |
+ retries: Same as for |IsOnline|. |
+ """ |
+ 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) |
+ |
def __str__(self): |
"""Returns the device serial.""" |
return self.old_interface.GetDevice() |