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 pids = self.ExtractPid(process) | |
493 if pids: | |
494 self.RunShellCommand('kill ' + ' '.join(pids)) | |
bulach
2012/10/08 13:57:56
how about replacing 492-494 with:
if self.KillAll(
Philippe
2012/10/08 14:07:52
Good point.
| |
495 elapsed = 0 | |
496 wait_period = 0.1 | |
497 # Note that this doesn't take into account the time spent in ExtractPid(). | |
498 while self.ExtractPid(process) and elapsed < timeout: | |
499 time.sleep(wait_period) | |
500 elapsed += wait_period | |
501 if elapsed >= timeout: | |
502 return 0 | |
503 return len(pids) | |
504 | |
479 def StartActivity(self, package, activity, wait_for_completion=False, | 505 def StartActivity(self, package, activity, wait_for_completion=False, |
480 action='android.intent.action.VIEW', | 506 action='android.intent.action.VIEW', |
481 category=None, data=None, | 507 category=None, data=None, |
482 extras=None, trace_file_name=None): | 508 extras=None, trace_file_name=None): |
483 """Starts |package|'s activity on the device. | 509 """Starts |package|'s activity on the device. |
484 | 510 |
485 Args: | 511 Args: |
486 package: Name of package to start (e.g. 'com.google.android.apps.chrome'). | 512 package: Name of package to start (e.g. 'com.google.android.apps.chrome'). |
487 activity: Name of activity (e.g. '.Main' or | 513 activity: Name of activity (e.g. '.Main' or |
488 'com.google.android.apps.chrome.Main'). | 514 'com.google.android.apps.chrome.Main'). |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1010 """ | 1036 """ |
1011 def __init__(self, output): | 1037 def __init__(self, output): |
1012 self._output = output | 1038 self._output = output |
1013 | 1039 |
1014 def write(self, data): | 1040 def write(self, data): |
1015 data = data.replace('\r\r\n', '\n') | 1041 data = data.replace('\r\r\n', '\n') |
1016 self._output.write(data) | 1042 self._output.write(data) |
1017 | 1043 |
1018 def flush(self): | 1044 def flush(self): |
1019 self._output.flush() | 1045 self._output.flush() |
OLD | NEW |