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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 while self.ExtractPid(process) and elapsed < timeout_sec: | 501 while self.ExtractPid(process) and elapsed < timeout_sec: |
502 time.sleep(wait_period) | 502 time.sleep(wait_period) |
503 elapsed += wait_period | 503 elapsed += wait_period |
504 if elapsed >= timeout_sec: | 504 if elapsed >= timeout_sec: |
505 return 0 | 505 return 0 |
506 return processes_killed | 506 return processes_killed |
507 | 507 |
508 def StartActivity(self, package, activity, wait_for_completion=False, | 508 def StartActivity(self, package, activity, wait_for_completion=False, |
509 action='android.intent.action.VIEW', | 509 action='android.intent.action.VIEW', |
510 category=None, data=None, | 510 category=None, data=None, |
511 extras=None, trace_file_name=None): | 511 extras=None, trace_file_name=None, |
| 512 force_stop=False): |
512 """Starts |package|'s activity on the device. | 513 """Starts |package|'s activity on the device. |
513 | 514 |
514 Args: | 515 Args: |
515 package: Name of package to start (e.g. 'com.google.android.apps.chrome'). | 516 package: Name of package to start (e.g. 'com.google.android.apps.chrome'). |
516 activity: Name of activity (e.g. '.Main' or | 517 activity: Name of activity (e.g. '.Main' or |
517 'com.google.android.apps.chrome.Main'). | 518 'com.google.android.apps.chrome.Main'). |
518 wait_for_completion: wait for the activity to finish launching (-W flag). | 519 wait_for_completion: wait for the activity to finish launching (-W flag). |
519 action: string (e.g. "android.intent.action.MAIN"). Default is VIEW. | 520 action: string (e.g. "android.intent.action.MAIN"). Default is VIEW. |
520 category: string (e.g. "android.intent.category.HOME") | 521 category: string (e.g. "android.intent.category.HOME") |
521 data: Data string to pass to activity (e.g. 'http://www.example.com/'). | 522 data: Data string to pass to activity (e.g. 'http://www.example.com/'). |
522 extras: Dict of extras to pass to activity. Values are significant. | 523 extras: Dict of extras to pass to activity. Values are significant. |
523 trace_file_name: If used, turns on and saves the trace to this file name. | 524 trace_file_name: If used, turns on and saves the trace to this file name. |
| 525 force_stop: force stop the target app before starting the activity (-S |
| 526 flag). |
524 """ | 527 """ |
525 cmd = 'am start -a %s' % action | 528 cmd = 'am start -a %s' % action |
| 529 if force_stop: |
| 530 cmd += ' -S' |
526 if wait_for_completion: | 531 if wait_for_completion: |
527 cmd += ' -W' | 532 cmd += ' -W' |
528 if category: | 533 if category: |
529 cmd += ' -c %s' % category | 534 cmd += ' -c %s' % category |
530 if package and activity: | 535 if package and activity: |
531 cmd += ' -n %s/%s' % (package, activity) | 536 cmd += ' -n %s/%s' % (package, activity) |
532 if data: | 537 if data: |
533 cmd += ' -d "%s"' % data | 538 cmd += ' -d "%s"' % data |
534 if extras: | 539 if extras: |
535 for key in extras: | 540 for key in extras: |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 """ | 1078 """ |
1074 def __init__(self, output): | 1079 def __init__(self, output): |
1075 self._output = output | 1080 self._output = output |
1076 | 1081 |
1077 def write(self, data): | 1082 def write(self, data): |
1078 data = data.replace('\r\r\n', '\n') | 1083 data = data.replace('\r\r\n', '\n') |
1079 self._output.write(data) | 1084 self._output.write(data) |
1080 | 1085 |
1081 def flush(self): | 1086 def flush(self): |
1082 self._output.flush() | 1087 self._output.flush() |
1083 | |
OLD | NEW |