| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 import logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import psutil | 7 import psutil |
| 8 | 8 |
| 9 from pylib import android_commands | 9 from pylib import android_commands |
| 10 | 10 |
| 11 def _KillWebServers(): | 11 def _KillWebServers(): |
| 12 for retry in xrange(5): | 12 for retry in xrange(5): |
| 13 for server in ['lighttpd', 'web-page-replay']: | 13 for server in ['lighttpd', 'web-page-replay']: |
| 14 pids = [p.pid for p in psutil.process_iter() if server in p.name] | 14 pids = [p.pid for p in psutil.process_iter() if server in p.name] |
| 15 for pid in pids: | 15 for pid in pids: |
| 16 try: | 16 try: |
| 17 logging.warning('Killing %s %s', server, pid) | 17 logging.warning('Killing %s %s', server, pid) |
| 18 os.kill(pid, signal.SIGQUIT) | 18 os.kill(pid, signal.SIGQUIT) |
| 19 except Exception as e: | 19 except Exception as e: |
| 20 logging.warning('Failed killing %s %s %s', server, pid, e) | 20 logging.warning('Failed killing %s %s %s', server, pid, e) |
| 21 | 21 |
| 22 | 22 |
| 23 def CleanupLeftoverProcesses(): | 23 def CleanupLeftoverProcesses(): |
| 24 """Clean up the test environment, restarting fresh adb and HTTP daemons.""" | 24 """Clean up the test environment, restarting fresh adb and HTTP daemons.""" |
| 25 _KillWebServers() | 25 _KillWebServers() |
| 26 did_restart_host_adb = False | 26 did_restart_host_adb = False |
| 27 for device in android_commands.GetAttachedDevices(): | 27 for device in android_commands.GetAttachedDevices(): |
| 28 adb = android_commands.AndroidCommands(device) | 28 adb = android_commands.AndroidCommands(device, api_strict_mode=True) |
| 29 # Make sure we restart the host adb server only once. | 29 # Make sure we restart the host adb server only once. |
| 30 if not did_restart_host_adb: | 30 if not did_restart_host_adb: |
| 31 adb.RestartAdbServer() | 31 adb.RestartAdbServer() |
| 32 did_restart_host_adb = True | 32 did_restart_host_adb = True |
| 33 adb.RestartAdbdOnDevice() | 33 adb.RestartAdbdOnDevice() |
| 34 adb.EnableAdbRoot() | 34 adb.EnableAdbRoot() |
| 35 adb.WaitForDevicePm() | 35 adb.WaitForDevicePm() |
| OLD | NEW |