OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 """This module wraps Android's adb tool. | 5 """This module wraps Android's adb tool. |
6 | 6 |
7 This is a thin wrapper around the adb interface. Any additional complexity | 7 This is a thin wrapper around the adb interface. Any additional complexity |
8 should be delegated to a higher level (ex. DeviceUtils). | 8 should be delegated to a higher level (ex. DeviceUtils). |
9 """ | 9 """ |
10 | 10 |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 Args: | 457 Args: |
458 timeout: (optional) Timeout per try in seconds. | 458 timeout: (optional) Timeout per try in seconds. |
459 retries: (optional) Number of retries to attempt. | 459 retries: (optional) Number of retries to attempt. |
460 | 460 |
461 Returns: | 461 Returns: |
462 A list of PIDs as strings. | 462 A list of PIDs as strings. |
463 """ | 463 """ |
464 return [a.strip() for a in | 464 return [a.strip() for a in |
465 self._RunDeviceAdbCmd(['jdwp'], timeout, retries).split('\n')] | 465 self._RunDeviceAdbCmd(['jdwp'], timeout, retries).split('\n')] |
466 | 466 |
467 def Install(self, apk_path, forward_lock=False, reinstall=False, | 467 def Install(self, apk_path, forward_lock=False, allow_downgrade=False, |
468 sd_card=False, timeout=60*2, retries=_DEFAULT_RETRIES): | 468 reinstall=False, sd_card=False, timeout=60*2, |
| 469 retries=_DEFAULT_RETRIES): |
469 """Install an apk on the device. | 470 """Install an apk on the device. |
470 | 471 |
471 Args: | 472 Args: |
472 apk_path: Host path to the APK file. | 473 apk_path: Host path to the APK file. |
473 forward_lock: (optional) If set forward-locks the app. | 474 forward_lock: (optional) If set forward-locks the app. |
| 475 allow_downgrade: (optional) If set, allows for downgrades. |
474 reinstall: (optional) If set reinstalls the app, keeping its data. | 476 reinstall: (optional) If set reinstalls the app, keeping its data. |
475 sd_card: (optional) If set installs on the SD card. | 477 sd_card: (optional) If set installs on the SD card. |
476 timeout: (optional) Timeout per try in seconds. | 478 timeout: (optional) Timeout per try in seconds. |
477 retries: (optional) Number of retries to attempt. | 479 retries: (optional) Number of retries to attempt. |
478 """ | 480 """ |
479 VerifyLocalFileExists(apk_path) | 481 VerifyLocalFileExists(apk_path) |
480 cmd = ['install'] | 482 cmd = ['install'] |
481 if forward_lock: | 483 if forward_lock: |
482 cmd.append('-l') | 484 cmd.append('-l') |
483 if reinstall: | 485 if reinstall: |
484 cmd.append('-r') | 486 cmd.append('-r') |
485 if sd_card: | 487 if sd_card: |
486 cmd.append('-s') | 488 cmd.append('-s') |
| 489 if allow_downgrade: |
| 490 cmd.append('-d') |
487 cmd.append(apk_path) | 491 cmd.append(apk_path) |
488 output = self._RunDeviceAdbCmd(cmd, timeout, retries) | 492 output = self._RunDeviceAdbCmd(cmd, timeout, retries) |
489 if 'Success' not in output: | 493 if 'Success' not in output: |
490 raise device_errors.AdbCommandFailedError( | 494 raise device_errors.AdbCommandFailedError( |
491 cmd, output, device_serial=self._device_serial) | 495 cmd, output, device_serial=self._device_serial) |
492 | 496 |
493 def InstallMultiple(self, apk_paths, forward_lock=False, reinstall=False, | 497 def InstallMultiple(self, apk_paths, forward_lock=False, reinstall=False, |
494 sd_card=False, allow_downgrade=False, partial=False, | 498 sd_card=False, allow_downgrade=False, partial=False, |
495 timeout=60*2, retries=_DEFAULT_RETRIES): | 499 timeout=60*2, retries=_DEFAULT_RETRIES): |
496 """Install an apk with splits on the device. | 500 """Install an apk with splits on the device. |
497 | 501 |
498 Args: | 502 Args: |
499 apk_paths: Host path to the APK file. | 503 apk_paths: Host path to the APK file. |
500 forward_lock: (optional) If set forward-locks the app. | 504 forward_lock: (optional) If set forward-locks the app. |
501 reinstall: (optional) If set reinstalls the app, keeping its data. | 505 reinstall: (optional) If set reinstalls the app, keeping its data. |
502 sd_card: (optional) If set installs on the SD card. | 506 sd_card: (optional) If set installs on the SD card. |
| 507 allow_downgrade: (optional) Allow versionCode downgrade. |
| 508 partial: (optional) Package ID if apk_paths doesn't include all .apks. |
503 timeout: (optional) Timeout per try in seconds. | 509 timeout: (optional) Timeout per try in seconds. |
504 retries: (optional) Number of retries to attempt. | 510 retries: (optional) Number of retries to attempt. |
505 allow_downgrade: (optional) Allow versionCode downgrade. | |
506 partial: (optional) Package ID if apk_paths doesn't include all .apks. | |
507 """ | 511 """ |
508 for path in apk_paths: | 512 for path in apk_paths: |
509 VerifyLocalFileExists(path) | 513 VerifyLocalFileExists(path) |
510 cmd = ['install-multiple'] | 514 cmd = ['install-multiple'] |
511 if forward_lock: | 515 if forward_lock: |
512 cmd.append('-l') | 516 cmd.append('-l') |
513 if reinstall: | 517 if reinstall: |
514 cmd.append('-r') | 518 cmd.append('-r') |
515 if sd_card: | 519 if sd_card: |
516 cmd.append('-s') | 520 cmd.append('-s') |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 @property | 685 @property |
682 def is_emulator(self): | 686 def is_emulator(self): |
683 return _EMULATOR_RE.match(self._device_serial) | 687 return _EMULATOR_RE.match(self._device_serial) |
684 | 688 |
685 @property | 689 @property |
686 def is_ready(self): | 690 def is_ready(self): |
687 try: | 691 try: |
688 return self.GetState() == _READY_STATE | 692 return self.GetState() == _READY_STATE |
689 except device_errors.CommandFailedError: | 693 except device_errors.CommandFailedError: |
690 return False | 694 return False |
OLD | NEW |