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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 logging.info('\n>>> '.join(result)) | 462 logging.info('\n>>> '.join(result)) |
463 return result | 463 return result |
464 | 464 |
465 def KillAll(self, process): | 465 def KillAll(self, process): |
466 """Android version of killall, connected via adb. | 466 """Android version of killall, connected via adb. |
467 | 467 |
468 Args: | 468 Args: |
469 process: name of the process to kill off | 469 process: name of the process to kill off |
470 | 470 |
471 Returns: | 471 Returns: |
472 the number of processess killed | 472 the number of processes killed |
473 """ | 473 """ |
474 pids = self.ExtractPid(process) | 474 pids = self.ExtractPid(process) |
475 if pids: | 475 if pids: |
476 self.RunShellCommand('kill ' + ' '.join(pids)) | 476 self.RunShellCommand('kill ' + ' '.join(pids)) |
477 return len(pids) | 477 return len(pids) |
478 | 478 |
| 479 def KillAllBlocking(self, process, timeout_sec): |
| 480 """Blocking version of killall, connected via adb. |
| 481 |
| 482 This waits until no process matching the corresponding name appears in ps' |
| 483 output anymore. |
| 484 |
| 485 Args: |
| 486 process: name of the process to kill off |
| 487 timeout_sec: the timeout in seconds |
| 488 |
| 489 Returns: |
| 490 the number of processes killed |
| 491 """ |
| 492 processes_killed = self.KillAll(process) |
| 493 if processes_killed: |
| 494 elapsed = 0 |
| 495 wait_period = 0.1 |
| 496 # Note that this doesn't take into account the time spent in ExtractPid(). |
| 497 while self.ExtractPid(process) and elapsed < timeout_sec: |
| 498 time.sleep(wait_period) |
| 499 elapsed += wait_period |
| 500 if elapsed >= timeout_sec: |
| 501 return 0 |
| 502 return processes_killed |
| 503 |
479 def StartActivity(self, package, activity, wait_for_completion=False, | 504 def StartActivity(self, package, activity, wait_for_completion=False, |
480 action='android.intent.action.VIEW', | 505 action='android.intent.action.VIEW', |
481 category=None, data=None, | 506 category=None, data=None, |
482 extras=None, trace_file_name=None): | 507 extras=None, trace_file_name=None): |
483 """Starts |package|'s activity on the device. | 508 """Starts |package|'s activity on the device. |
484 | 509 |
485 Args: | 510 Args: |
486 package: Name of package to start (e.g. 'com.google.android.apps.chrome'). | 511 package: Name of package to start (e.g. 'com.google.android.apps.chrome'). |
487 activity: Name of activity (e.g. '.Main' or | 512 activity: Name of activity (e.g. '.Main' or |
488 'com.google.android.apps.chrome.Main'). | 513 'com.google.android.apps.chrome.Main'). |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 """ | 1035 """ |
1011 def __init__(self, output): | 1036 def __init__(self, output): |
1012 self._output = output | 1037 self._output = output |
1013 | 1038 |
1014 def write(self, data): | 1039 def write(self, data): |
1015 data = data.replace('\r\r\n', '\n') | 1040 data = data.replace('\r\r\n', '\n') |
1016 self._output.write(data) | 1041 self._output.write(data) |
1017 | 1042 |
1018 def flush(self): | 1043 def flush(self): |
1019 self._output.flush() | 1044 self._output.flush() |
OLD | NEW |