| 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 | 9 |
| 10 import collections | 10 import collections |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 logging.info('>>> $' + command) | 459 logging.info('>>> $' + command) |
| 460 if "'" in command: logging.warning(command + " contains ' quotes") | 460 if "'" in command: logging.warning(command + " contains ' quotes") |
| 461 result = self._adb.SendShellCommand( | 461 result = self._adb.SendShellCommand( |
| 462 "'%s'" % command, timeout_time).splitlines() | 462 "'%s'" % command, timeout_time).splitlines() |
| 463 if ['error: device not found'] == result: | 463 if ['error: device not found'] == result: |
| 464 raise errors.DeviceUnresponsiveError('device not found') | 464 raise errors.DeviceUnresponsiveError('device not found') |
| 465 if log_result: | 465 if log_result: |
| 466 logging.info('\n>>> '.join(result)) | 466 logging.info('\n>>> '.join(result)) |
| 467 return result | 467 return result |
| 468 | 468 |
| 469 def GetShellCommandStatusAndOutput(self, command, timeout_time=20, |
| 470 log_result=False): |
| 471 """See RunShellCommand() above. |
| 472 |
| 473 Returns: |
| 474 The tuple (exit code, list of output lines). |
| 475 """ |
| 476 lines = self.RunShellCommand( |
| 477 command + '; echo $?', timeout_time, log_result) |
| 478 return (int(lines[-1]), lines[:-1]) |
| 479 |
| 469 def KillAll(self, process): | 480 def KillAll(self, process): |
| 470 """Android version of killall, connected via adb. | 481 """Android version of killall, connected via adb. |
| 471 | 482 |
| 472 Args: | 483 Args: |
| 473 process: name of the process to kill off | 484 process: name of the process to kill off |
| 474 | 485 |
| 475 Returns: | 486 Returns: |
| 476 the number of processes killed | 487 the number of processes killed |
| 477 """ | 488 """ |
| 478 pids = self.ExtractPid(process) | 489 pids = self.ExtractPid(process) |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 """ | 1103 """ |
| 1093 def __init__(self, output): | 1104 def __init__(self, output): |
| 1094 self._output = output | 1105 self._output = output |
| 1095 | 1106 |
| 1096 def write(self, data): | 1107 def write(self, data): |
| 1097 data = data.replace('\r\r\n', '\n') | 1108 data = data.replace('\r\r\n', '\n') |
| 1098 self._output.write(data) | 1109 self._output.write(data) |
| 1099 | 1110 |
| 1100 def flush(self): | 1111 def flush(self): |
| 1101 self._output.flush() | 1112 self._output.flush() |
| OLD | NEW |