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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 reboots_left -= 1 | 452 reboots_left -= 1 |
453 | 453 |
454 def MakeSystemFolderWritable(self): | 454 def MakeSystemFolderWritable(self): |
455 """Remounts the /system folder rw.""" | 455 """Remounts the /system folder rw.""" |
456 out = self._adb.SendCommand('remount') | 456 out = self._adb.SendCommand('remount') |
457 if out.strip() != 'remount succeeded': | 457 if out.strip() != 'remount succeeded': |
458 raise errors.MsgException('Remount failed: %s' % out) | 458 raise errors.MsgException('Remount failed: %s' % out) |
459 | 459 |
460 def RestartAdbServer(self): | 460 def RestartAdbServer(self): |
461 """Restart the adb server.""" | 461 """Restart the adb server.""" |
462 self.KillAdbServer() | 462 ret = self.KillAdbServer() |
463 self.StartAdbServer() | 463 if ret != 0: |
| 464 raise errors.MsgException('KillAdbServer: %d' % ret) |
| 465 |
| 466 ret = self.StartAdbServer() |
| 467 if ret != 0: |
| 468 raise errors.MsgException('StartAdbServer: %d' % ret) |
464 | 469 |
465 def KillAdbServer(self): | 470 def KillAdbServer(self): |
466 """Kill adb server.""" | 471 """Kill adb server.""" |
467 adb_cmd = [constants.ADB_PATH, 'kill-server'] | 472 adb_cmd = [constants.ADB_PATH, 'kill-server'] |
468 return cmd_helper.RunCmd(adb_cmd) | 473 ret = cmd_helper.RunCmd(adb_cmd) |
| 474 retry = 0 |
| 475 while retry < 3: |
| 476 ret = cmd_helper.RunCmd(['pgrep', 'adb']) |
| 477 if ret != 0: |
| 478 # pgrep didn't find adb, kill-server succeeded. |
| 479 return 0 |
| 480 retry += 1 |
| 481 time.sleep(retry) |
| 482 return ret |
469 | 483 |
470 def StartAdbServer(self): | 484 def StartAdbServer(self): |
471 """Start adb server.""" | 485 """Start adb server.""" |
472 adb_cmd = [constants.ADB_PATH, 'start-server'] | 486 adb_cmd = ['taskset', '-c', '0', constants.ADB_PATH, 'start-server'] |
473 return cmd_helper.RunCmd(adb_cmd) | 487 ret = cmd_helper.RunCmd(adb_cmd) |
| 488 retry = 0 |
| 489 while retry < 3: |
| 490 ret = cmd_helper.RunCmd(['pgrep', 'adb']) |
| 491 if ret == 0: |
| 492 # pgrep fonud adb, start-server succeeded. |
| 493 return 0 |
| 494 retry += 1 |
| 495 time.sleep(retry) |
| 496 return ret |
474 | 497 |
475 def WaitForSystemBootCompleted(self, wait_time): | 498 def WaitForSystemBootCompleted(self, wait_time): |
476 """Waits for targeted system's boot_completed flag to be set. | 499 """Waits for targeted system's boot_completed flag to be set. |
477 | 500 |
478 Args: | 501 Args: |
479 wait_time: time in seconds to wait | 502 wait_time: time in seconds to wait |
480 | 503 |
481 Raises: | 504 Raises: |
482 WaitForResponseTimedOutError if wait_time elapses and flag still not | 505 WaitForResponseTimedOutError if wait_time elapses and flag still not |
483 set. | 506 set. |
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1519 """ | 1542 """ |
1520 def __init__(self, output): | 1543 def __init__(self, output): |
1521 self._output = output | 1544 self._output = output |
1522 | 1545 |
1523 def write(self, data): | 1546 def write(self, data): |
1524 data = data.replace('\r\r\n', '\n') | 1547 data = data.replace('\r\r\n', '\n') |
1525 self._output.write(data) | 1548 self._output.write(data) |
1526 | 1549 |
1527 def flush(self): | 1550 def flush(self): |
1528 self._output.flush() | 1551 self._output.flush() |
OLD | NEW |