| 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 last_line = lines[-1] |
| 479 status_pos = last_line.rfind('%') |
| 480 assert status_pos >= 0 |
| 481 status = int(last_line[status_pos + 1:]) |
| 482 if status_pos == 0: |
| 483 lines = lines[:-1] |
| 484 else: |
| 485 lines = lines[:-1] + last_line[:status_pos] |
| 486 return (status, lines) |
| 487 |
| 469 def KillAll(self, process): | 488 def KillAll(self, process): |
| 470 """Android version of killall, connected via adb. | 489 """Android version of killall, connected via adb. |
| 471 | 490 |
| 472 Args: | 491 Args: |
| 473 process: name of the process to kill off | 492 process: name of the process to kill off |
| 474 | 493 |
| 475 Returns: | 494 Returns: |
| 476 the number of processes killed | 495 the number of processes killed |
| 477 """ | 496 """ |
| 478 pids = self.ExtractPid(process) | 497 pids = self.ExtractPid(process) |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 """ | 1112 """ |
| 1094 def __init__(self, output): | 1113 def __init__(self, output): |
| 1095 self._output = output | 1114 self._output = output |
| 1096 | 1115 |
| 1097 def write(self, data): | 1116 def write(self, data): |
| 1098 data = data.replace('\r\r\n', '\n') | 1117 data = data.replace('\r\r\n', '\n') |
| 1099 self._output.write(data) | 1118 self._output.write(data) |
| 1100 | 1119 |
| 1101 def flush(self): | 1120 def flush(self): |
| 1102 self._output.flush() | 1121 self._output.flush() |
| OLD | NEW |