OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 a variety of device interactions based on adb. | 5 """Provides a variety of device interactions based on adb. |
6 | 6 |
7 Eventually, this will be based on adb_wrapper. | 7 Eventually, this will be based on adb_wrapper. |
8 """ | 8 """ |
9 # pylint: disable=unused-argument | 9 # pylint: disable=unused-argument |
10 | 10 |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 self.adb.Reboot() | 537 self.adb.Reboot() |
538 self._ClearCache() | 538 self._ClearCache() |
539 timeout_retry.WaitFor(device_offline, wait_period=1) | 539 timeout_retry.WaitFor(device_offline, wait_period=1) |
540 if block: | 540 if block: |
541 self.WaitUntilFullyBooted(wifi=wifi) | 541 self.WaitUntilFullyBooted(wifi=wifi) |
542 | 542 |
543 INSTALL_DEFAULT_TIMEOUT = 4 * _DEFAULT_TIMEOUT | 543 INSTALL_DEFAULT_TIMEOUT = 4 * _DEFAULT_TIMEOUT |
544 | 544 |
545 @decorators.WithTimeoutAndRetriesFromInstance( | 545 @decorators.WithTimeoutAndRetriesFromInstance( |
546 min_default_timeout=INSTALL_DEFAULT_TIMEOUT) | 546 min_default_timeout=INSTALL_DEFAULT_TIMEOUT) |
547 def Install(self, apk, reinstall=False, permissions=None, timeout=None, | 547 def Install(self, apk, allow_downgrade=False, reinstall=False, |
548 retries=None): | 548 permissions=None, timeout=None, retries=None): |
549 """Install an APK. | 549 """Install an APK. |
550 | 550 |
551 Noop if an identical APK is already installed. | 551 Noop if an identical APK is already installed. |
552 | 552 |
553 Args: | 553 Args: |
554 apk: An ApkHelper instance or string containing the path to the APK. | 554 apk: An ApkHelper instance or string containing the path to the APK. |
| 555 allow_downgrade: A boolean indicating if we should allow downgrades. |
| 556 reinstall: A boolean indicating if we should keep any existing app data. |
555 permissions: Set of permissions to set. If not set, finds permissions with | 557 permissions: Set of permissions to set. If not set, finds permissions with |
556 apk helper. To set no permissions, pass []. | 558 apk helper. To set no permissions, pass []. |
557 reinstall: A boolean indicating if we should keep any existing app data. | |
558 timeout: timeout in seconds | 559 timeout: timeout in seconds |
559 retries: number of retries | 560 retries: number of retries |
560 | 561 |
561 Raises: | 562 Raises: |
562 CommandFailedError if the installation fails. | 563 CommandFailedError if the installation fails. |
563 CommandTimeoutError if the installation times out. | 564 CommandTimeoutError if the installation times out. |
564 DeviceUnreachableError on missing device. | 565 DeviceUnreachableError on missing device. |
565 """ | 566 """ |
566 self._InstallInternal(apk, None, reinstall=reinstall, | 567 self._InstallInternal(apk, None, allow_downgrade=allow_downgrade, |
567 permissions=permissions) | 568 reinstall=reinstall, permissions=permissions) |
568 | 569 |
569 @decorators.WithTimeoutAndRetriesFromInstance( | 570 @decorators.WithTimeoutAndRetriesFromInstance( |
570 min_default_timeout=INSTALL_DEFAULT_TIMEOUT) | 571 min_default_timeout=INSTALL_DEFAULT_TIMEOUT) |
571 def InstallSplitApk(self, base_apk, split_apks, reinstall=False, | 572 def InstallSplitApk(self, base_apk, split_apks, allow_downgrade=False, |
572 allow_cached_props=False, permissions=None, timeout=None, | 573 reinstall=False, allow_cached_props=False, |
573 retries=None): | 574 permissions=None, timeout=None, retries=None): |
574 """Install a split APK. | 575 """Install a split APK. |
575 | 576 |
576 Noop if all of the APK splits are already installed. | 577 Noop if all of the APK splits are already installed. |
577 | 578 |
578 Args: | 579 Args: |
579 base_apk: An ApkHelper instance or string containing the path to the base | 580 base_apk: An ApkHelper instance or string containing the path to the base |
580 APK. | 581 APK. |
581 split_apks: A list of strings of paths of all of the APK splits. | 582 split_apks: A list of strings of paths of all of the APK splits. |
| 583 allow_downgrade: A boolean indicating if we should allow downgrades. |
582 reinstall: A boolean indicating if we should keep any existing app data. | 584 reinstall: A boolean indicating if we should keep any existing app data. |
583 allow_cached_props: Whether to use cached values for device properties. | 585 allow_cached_props: Whether to use cached values for device properties. |
584 permissions: Set of permissions to set. If not set, finds permissions with | 586 permissions: Set of permissions to set. If not set, finds permissions with |
585 apk helper. To set no permissions, pass []. | 587 apk helper. To set no permissions, pass []. |
586 timeout: timeout in seconds | 588 timeout: timeout in seconds |
587 retries: number of retries | 589 retries: number of retries |
588 | 590 |
589 Raises: | 591 Raises: |
590 CommandFailedError if the installation fails. | 592 CommandFailedError if the installation fails. |
591 CommandTimeoutError if the installation times out. | 593 CommandTimeoutError if the installation times out. |
592 DeviceUnreachableError on missing device. | 594 DeviceUnreachableError on missing device. |
593 DeviceVersionError if device SDK is less than Android L. | 595 DeviceVersionError if device SDK is less than Android L. |
594 """ | 596 """ |
595 self._InstallInternal(base_apk, split_apks, reinstall=reinstall, | 597 self._InstallInternal(base_apk, split_apks, reinstall=reinstall, |
596 allow_cached_props=allow_cached_props, | 598 allow_cached_props=allow_cached_props, |
597 permissions=permissions) | 599 permissions=permissions, |
| 600 allow_downgrade=allow_downgrade) |
598 | 601 |
599 def _InstallInternal(self, base_apk, split_apks, reinstall=False, | 602 def _InstallInternal(self, base_apk, split_apks, allow_downgrade=False, |
600 allow_cached_props=False, permissions=None): | 603 reinstall=False, allow_cached_props=False, |
| 604 permissions=None): |
601 if split_apks: | 605 if split_apks: |
602 self._CheckSdkLevel(version_codes.LOLLIPOP) | 606 self._CheckSdkLevel(version_codes.LOLLIPOP) |
603 | 607 |
604 base_apk = apk_helper.ToHelper(base_apk) | 608 base_apk = apk_helper.ToHelper(base_apk) |
605 | 609 |
606 all_apks = [base_apk.path] | 610 all_apks = [base_apk.path] |
607 if split_apks: | 611 if split_apks: |
608 all_apks += split_select.SelectSplits( | 612 all_apks += split_select.SelectSplits( |
609 self, base_apk.path, split_apks, allow_cached_props=allow_cached_props) | 613 self, base_apk.path, split_apks, allow_cached_props=allow_cached_props) |
610 if len(all_apks) == 1: | 614 if len(all_apks) == 1: |
(...skipping 25 matching lines...) Expand all Loading... |
636 self.Uninstall(package_name) | 640 self.Uninstall(package_name) |
637 apks_to_install = all_apks | 641 apks_to_install = all_apks |
638 | 642 |
639 if apks_to_install: | 643 if apks_to_install: |
640 # Assume that we won't know the resulting device state. | 644 # Assume that we won't know the resulting device state. |
641 self._cache['package_apk_paths'].pop(package_name, 0) | 645 self._cache['package_apk_paths'].pop(package_name, 0) |
642 self._cache['package_apk_checksums'].pop(package_name, 0) | 646 self._cache['package_apk_checksums'].pop(package_name, 0) |
643 if split_apks: | 647 if split_apks: |
644 partial = package_name if len(apks_to_install) < len(all_apks) else None | 648 partial = package_name if len(apks_to_install) < len(all_apks) else None |
645 self.adb.InstallMultiple( | 649 self.adb.InstallMultiple( |
646 apks_to_install, partial=partial, reinstall=reinstall) | 650 apks_to_install, partial=partial, reinstall=reinstall, |
| 651 allow_downgrade=allow_downgrade) |
647 else: | 652 else: |
648 self.adb.Install(base_apk.path, reinstall=reinstall) | 653 self.adb.Install( |
| 654 base_apk.path, reinstall=reinstall, allow_downgrade=allow_downgrade) |
649 if (permissions is None | 655 if (permissions is None |
650 and self.build_version_sdk >= version_codes.MARSHMALLOW): | 656 and self.build_version_sdk >= version_codes.MARSHMALLOW): |
651 permissions = base_apk.GetPermissions() | 657 permissions = base_apk.GetPermissions() |
652 self.GrantPermissions(package_name, permissions) | 658 self.GrantPermissions(package_name, permissions) |
653 # Upon success, we know the device checksums, but not their paths. | 659 # Upon success, we know the device checksums, but not their paths. |
654 if host_checksums is not None: | 660 if host_checksums is not None: |
655 self._cache['package_apk_checksums'][package_name] = host_checksums | 661 self._cache['package_apk_checksums'][package_name] = host_checksums |
656 else: | 662 else: |
657 # Running adb install terminates running instances of the app, so to be | 663 # Running adb install terminates running instances of the app, so to be |
658 # consistent, we explicitly terminate it when skipping the install. | 664 # consistent, we explicitly terminate it when skipping the install. |
(...skipping 1492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2151 on: bool to decide state to switch to. True = on False = off. | 2157 on: bool to decide state to switch to. True = on False = off. |
2152 """ | 2158 """ |
2153 def screen_test(): | 2159 def screen_test(): |
2154 return self.IsScreenOn() == on | 2160 return self.IsScreenOn() == on |
2155 | 2161 |
2156 if screen_test(): | 2162 if screen_test(): |
2157 logging.info('Screen already in expected state.') | 2163 logging.info('Screen already in expected state.') |
2158 return | 2164 return |
2159 self.RunShellCommand('input keyevent 26') | 2165 self.RunShellCommand('input keyevent 26') |
2160 timeout_retry.WaitFor(screen_test, wait_period=1) | 2166 timeout_retry.WaitFor(screen_test, wait_period=1) |
OLD | NEW |