Index: devil/devil/android/device_utils.py |
diff --git a/devil/devil/android/device_utils.py b/devil/devil/android/device_utils.py |
index 50f362c3839974e7d296ff08c6cc7669b63b3a85..de7cc5cc87e06f4d1014e3f06323394388cbf380 100644 |
--- a/devil/devil/android/device_utils.py |
+++ b/devil/devil/android/device_utils.py |
@@ -1181,8 +1181,9 @@ class DeviceUtils(object): |
CommandTimeoutError on timeout. |
DeviceUnreachableError on missing device. |
""" |
- cmd = 'p=%s;if [[ "$(ps)" = *$p* ]]; then am force-stop $p; fi' |
- self.RunShellCommand(cmd % package, shell=True, check_return=True) |
+ cmd = ('p=%s;if [[ "$(%s)" = *$p* ]]; then am force-stop $p; fi' % |
jbudorick
2017/04/11 23:47:24
I'm wondering if maintaining the hotrolled script
perezju
2017/04/12 09:13:20
+1
|
+ (package, self._GetPsCommand())) |
+ self.RunShellCommand(cmd, shell=True, check_return=True) |
@decorators.WithTimeoutAndRetriesFromInstance() |
def ClearApplicationState( |
@@ -2153,11 +2154,7 @@ class DeviceUtils(object): |
""" |
procs_pids = collections.defaultdict(list) |
try: |
- ps_cmd = 'ps' |
- # ps behavior was changed in Android above N, http://crbug.com/686716 |
- if (self.build_version_sdk >= version_codes.NOUGAT_MR1 |
- and self.build_id[0] > 'N'): |
- ps_cmd = 'ps -e' |
+ ps_cmd = self._GetPsCommand() |
if process_name: |
ps_output = self._RunPipedShellCommand( |
'%s | grep -F %s' % (ps_cmd, cmd_helper.SingleQuote(process_name))) |
@@ -2638,3 +2635,16 @@ class DeviceUtils(object): |
return |
self.SendKeyEvent(keyevent.KEYCODE_POWER) |
timeout_retry.WaitFor(screen_test, wait_period=1) |
+ |
+ def _GetPsCommand(self): |
+ """Returns command to get list of processes. |
+ |
+ Command to get list of processes is different for differnet Android |
+ versions. |
+ """ |
+ ps_cmd = 'ps' |
+ # ps behavior was changed in Android above N, http://crbug.com/686716 |
+ if (self.build_version_sdk >= version_codes.NOUGAT_MR1 |
+ and self.build_id[0] > 'N'): |
+ ps_cmd = 'ps -e' |
+ return ps_cmd |