OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Provides a variety of device interactions based on adb. | 5 """Provides a variety of device interactions based on adb. |
6 | 6 |
7 Eventually, this will be based on adb_wrapper. | 7 Eventually, this will be based on adb_wrapper. |
8 """ | 8 """ |
9 # pylint: disable=unused-argument | 9 # pylint: disable=unused-argument |
10 | 10 |
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1174 | 1174 |
1175 Args: | 1175 Args: |
1176 package: A string containing the name of the package to stop. | 1176 package: A string containing the name of the package to stop. |
1177 timeout: timeout in seconds | 1177 timeout: timeout in seconds |
1178 retries: number of retries | 1178 retries: number of retries |
1179 | 1179 |
1180 Raises: | 1180 Raises: |
1181 CommandTimeoutError on timeout. | 1181 CommandTimeoutError on timeout. |
1182 DeviceUnreachableError on missing device. | 1182 DeviceUnreachableError on missing device. |
1183 """ | 1183 """ |
1184 cmd = 'p=%s;if [[ "$(ps)" = *$p* ]]; then am force-stop $p; fi' | 1184 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
| |
1185 self.RunShellCommand(cmd % package, shell=True, check_return=True) | 1185 (package, self._GetPsCommand())) |
1186 self.RunShellCommand(cmd, shell=True, check_return=True) | |
1186 | 1187 |
1187 @decorators.WithTimeoutAndRetriesFromInstance() | 1188 @decorators.WithTimeoutAndRetriesFromInstance() |
1188 def ClearApplicationState( | 1189 def ClearApplicationState( |
1189 self, package, permissions=None, timeout=None, retries=None): | 1190 self, package, permissions=None, timeout=None, retries=None): |
1190 """Clear all state for the given package. | 1191 """Clear all state for the given package. |
1191 | 1192 |
1192 Args: | 1193 Args: |
1193 package: A string containing the name of the package to stop. | 1194 package: A string containing the name of the package to stop. |
1194 permissions: List of permissions to set after clearing data. | 1195 permissions: List of permissions to set after clearing data. |
1195 timeout: timeout in seconds | 1196 timeout: timeout in seconds |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2146 Returns: | 2147 Returns: |
2147 A dict mapping process name to a list of PIDs for each process that | 2148 A dict mapping process name to a list of PIDs for each process that |
2148 contained the provided |process_name|. | 2149 contained the provided |process_name|. |
2149 | 2150 |
2150 Raises: | 2151 Raises: |
2151 CommandTimeoutError on timeout. | 2152 CommandTimeoutError on timeout. |
2152 DeviceUnreachableError on missing device. | 2153 DeviceUnreachableError on missing device. |
2153 """ | 2154 """ |
2154 procs_pids = collections.defaultdict(list) | 2155 procs_pids = collections.defaultdict(list) |
2155 try: | 2156 try: |
2156 ps_cmd = 'ps' | 2157 ps_cmd = self._GetPsCommand() |
2157 # ps behavior was changed in Android above N, http://crbug.com/686716 | |
2158 if (self.build_version_sdk >= version_codes.NOUGAT_MR1 | |
2159 and self.build_id[0] > 'N'): | |
2160 ps_cmd = 'ps -e' | |
2161 if process_name: | 2158 if process_name: |
2162 ps_output = self._RunPipedShellCommand( | 2159 ps_output = self._RunPipedShellCommand( |
2163 '%s | grep -F %s' % (ps_cmd, cmd_helper.SingleQuote(process_name))) | 2160 '%s | grep -F %s' % (ps_cmd, cmd_helper.SingleQuote(process_name))) |
2164 else: | 2161 else: |
2165 ps_output = self.RunShellCommand( | 2162 ps_output = self.RunShellCommand( |
2166 ps_cmd.split(), check_return=True, large_output=True) | 2163 ps_cmd.split(), check_return=True, large_output=True) |
2167 except device_errors.AdbShellCommandFailedError as e: | 2164 except device_errors.AdbShellCommandFailedError as e: |
2168 if e.status and isinstance(e.status, list) and not e.status[0]: | 2165 if e.status and isinstance(e.status, list) and not e.status[0]: |
2169 # If ps succeeded but grep failed, there were no processes with the | 2166 # If ps succeeded but grep failed, there were no processes with the |
2170 # given name. | 2167 # given name. |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2631 on: bool to decide state to switch to. True = on False = off. | 2628 on: bool to decide state to switch to. True = on False = off. |
2632 """ | 2629 """ |
2633 def screen_test(): | 2630 def screen_test(): |
2634 return self.IsScreenOn() == on | 2631 return self.IsScreenOn() == on |
2635 | 2632 |
2636 if screen_test(): | 2633 if screen_test(): |
2637 logger.info('Screen already in expected state.') | 2634 logger.info('Screen already in expected state.') |
2638 return | 2635 return |
2639 self.SendKeyEvent(keyevent.KEYCODE_POWER) | 2636 self.SendKeyEvent(keyevent.KEYCODE_POWER) |
2640 timeout_retry.WaitFor(screen_test, wait_period=1) | 2637 timeout_retry.WaitFor(screen_test, wait_period=1) |
2638 | |
2639 def _GetPsCommand(self): | |
2640 """Returns command to get list of processes. | |
2641 | |
2642 Command to get list of processes is different for differnet Android | |
2643 versions. | |
2644 """ | |
2645 ps_cmd = 'ps' | |
2646 # ps behavior was changed in Android above N, http://crbug.com/686716 | |
2647 if (self.build_version_sdk >= version_codes.NOUGAT_MR1 | |
2648 and self.build_id[0] > 'N'): | |
2649 ps_cmd = 'ps -e' | |
2650 return ps_cmd | |
OLD | NEW |