| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 an interface to communicate with the device via the adb command. | 5 """Provides an interface to communicate with the device via the adb command. |
| 6 | 6 |
| 7 Assumes adb binary is currently on system path. | 7 Assumes adb binary is currently on system path. |
| 8 """ | 8 """ |
| 9 # pylint: disable-all | 9 # pylint: disable-all |
| 10 | 10 |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 last_line = lines[-1] | 751 last_line = lines[-1] |
| 752 status_pos = last_line.rfind('%') | 752 status_pos = last_line.rfind('%') |
| 753 assert status_pos >= 0 | 753 assert status_pos >= 0 |
| 754 status = int(last_line[status_pos + 1:]) | 754 status = int(last_line[status_pos + 1:]) |
| 755 if status_pos == 0: | 755 if status_pos == 0: |
| 756 lines = lines[:-1] | 756 lines = lines[:-1] |
| 757 else: | 757 else: |
| 758 lines = lines[:-1] + [last_line[:status_pos]] | 758 lines = lines[:-1] + [last_line[:status_pos]] |
| 759 return (status, lines) | 759 return (status, lines) |
| 760 | 760 |
| 761 def KillAll(self, process, signum=9, with_su=False): | 761 def KillAll(self, process, signum=signal.SIGKILL, with_su=False): |
| 762 """Android version of killall, connected via adb. | 762 """Android version of killall, connected via adb. |
| 763 | 763 |
| 764 Args: | 764 Args: |
| 765 process: name of the process to kill off. | 765 process: name of the process to kill off. |
| 766 signum: signal to use, 9 (SIGKILL) by default. | 766 signum: signal to use, 9 (SIGKILL) by default. |
| 767 with_su: wether or not to use su to kill the processes. | 767 with_su: wether or not to use su to kill the processes. |
| 768 | 768 |
| 769 Returns: | 769 Returns: |
| 770 the number of processes killed | 770 the number of processes killed |
| 771 """ | 771 """ |
| 772 pids = self.ExtractPid(process) | 772 pids = self.ExtractPid(process) |
| 773 if pids: | 773 if pids: |
| 774 cmd = 'kill -%d %s' % (signum, ' '.join(pids)) | 774 cmd = 'kill -%d %s' % (signum, ' '.join(pids)) |
| 775 if with_su: | 775 if with_su: |
| 776 self.RunShellCommandWithSU(cmd) | 776 self.RunShellCommandWithSU(cmd) |
| 777 else: | 777 else: |
| 778 self.RunShellCommand(cmd) | 778 self.RunShellCommand(cmd) |
| 779 return len(pids) | 779 return len(pids) |
| 780 | 780 |
| 781 def KillAllBlocking(self, process, timeout_sec): | 781 def KillAllBlocking(self, process, timeout_sec, signum=signal.SIGKILL, |
| 782 with_su=False): |
| 782 """Blocking version of killall, connected via adb. | 783 """Blocking version of killall, connected via adb. |
| 783 | 784 |
| 784 This waits until no process matching the corresponding name appears in ps' | 785 This waits until no process matching the corresponding name appears in ps' |
| 785 output anymore. | 786 output anymore. |
| 786 | 787 |
| 787 Args: | 788 Args: |
| 788 process: name of the process to kill off | 789 process: name of the process to kill off |
| 789 timeout_sec: the timeout in seconds | 790 timeout_sec: the timeout in seconds |
| 790 | 791 signum: same as |KillAll| |
| 792 with_su: same as |KillAll| |
| 791 Returns: | 793 Returns: |
| 792 the number of processes killed | 794 the number of processes killed |
| 793 """ | 795 """ |
| 794 processes_killed = self.KillAll(process) | 796 processes_killed = self.KillAll(process, signum=signum, with_su=with_su) |
| 795 if processes_killed: | 797 if processes_killed: |
| 796 elapsed = 0 | 798 elapsed = 0 |
| 797 wait_period = 0.1 | 799 wait_period = 0.1 |
| 798 # Note that this doesn't take into account the time spent in ExtractPid(). | 800 # Note that this doesn't take into account the time spent in ExtractPid(). |
| 799 while self.ExtractPid(process) and elapsed < timeout_sec: | 801 while self.ExtractPid(process) and elapsed < timeout_sec: |
| 800 time.sleep(wait_period) | 802 time.sleep(wait_period) |
| 801 elapsed += wait_period | 803 elapsed += wait_period |
| 802 if elapsed >= timeout_sec: | 804 if elapsed >= timeout_sec: |
| 803 return 0 | 805 return 0 |
| 804 return processes_killed | 806 return processes_killed |
| (...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1983 """ | 1985 """ |
| 1984 def __init__(self, output): | 1986 def __init__(self, output): |
| 1985 self._output = output | 1987 self._output = output |
| 1986 | 1988 |
| 1987 def write(self, data): | 1989 def write(self, data): |
| 1988 data = data.replace('\r\r\n', '\n') | 1990 data = data.replace('\r\r\n', '\n') |
| 1989 self._output.write(data) | 1991 self._output.write(data) |
| 1990 | 1992 |
| 1991 def flush(self): | 1993 def flush(self): |
| 1992 self._output.flush() | 1994 self._output.flush() |
| OLD | NEW |