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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 if apks_to_install: | 618 if apks_to_install: |
619 # Assume that we won't know the resulting device state. | 619 # Assume that we won't know the resulting device state. |
620 self._cache['package_apk_paths'].pop(package_name, 0) | 620 self._cache['package_apk_paths'].pop(package_name, 0) |
621 self._cache['package_apk_checksums'].pop(package_name, 0) | 621 self._cache['package_apk_checksums'].pop(package_name, 0) |
622 if split_apks: | 622 if split_apks: |
623 partial = package_name if len(apks_to_install) < len(all_apks) else None | 623 partial = package_name if len(apks_to_install) < len(all_apks) else None |
624 self.adb.InstallMultiple( | 624 self.adb.InstallMultiple( |
625 apks_to_install, partial=partial, reinstall=reinstall) | 625 apks_to_install, partial=partial, reinstall=reinstall) |
626 else: | 626 else: |
627 self.adb.Install(base_apk, reinstall=reinstall) | 627 self.adb.Install(base_apk, reinstall=reinstall) |
| 628 if (permissions is None |
| 629 and self.build_version_sdk >= version_codes.MARSHMALLOW): |
| 630 permissions = apk_helper.ApkHelper(base_apk).GetPermissions() |
| 631 self.GrantPermissions(package_name, permissions) |
628 # Upon success, we know the device checksums, but not their paths. | 632 # Upon success, we know the device checksums, but not their paths. |
629 if host_checksums is not None: | 633 if host_checksums is not None: |
630 self._cache['package_apk_checksums'][package_name] = host_checksums | 634 self._cache['package_apk_checksums'][package_name] = host_checksums |
631 else: | 635 else: |
632 # Running adb install terminates running instances of the app, so to be | 636 # Running adb install terminates running instances of the app, so to be |
633 # consistent, we explicitly terminate it when skipping the install. | 637 # consistent, we explicitly terminate it when skipping the install. |
634 self.ForceStop(package_name) | 638 self.ForceStop(package_name) |
635 | 639 |
636 if (permissions is None | |
637 and self.build_version_sdk >= version_codes.MARSHMALLOW): | |
638 permissions = apk_helper.ApkHelper(base_apk).GetPermissions() | |
639 self.GrantPermissions(package_name, permissions) | |
640 | |
641 @decorators.WithTimeoutAndRetriesFromInstance() | 640 @decorators.WithTimeoutAndRetriesFromInstance() |
642 def Uninstall(self, package_name, keep_data=False, timeout=None, | 641 def Uninstall(self, package_name, keep_data=False, timeout=None, |
643 retries=None): | 642 retries=None): |
644 """Remove the app |package_name| from the device. | 643 """Remove the app |package_name| from the device. |
645 | 644 |
646 This is a no-op if the app is not already installed. | 645 This is a no-op if the app is not already installed. |
647 | 646 |
648 Args: | 647 Args: |
649 package_name: The package to uninstall. | 648 package_name: The package to uninstall. |
650 keep_data: (optional) Whether to keep the data and cache directories. | 649 keep_data: (optional) Whether to keep the data and cache directories. |
(...skipping 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2056 if ('android.permission.WRITE_EXTERNAL_STORAGE' in permissions | 2055 if ('android.permission.WRITE_EXTERNAL_STORAGE' in permissions |
2057 and 'android.permission.READ_EXTERNAL_STORAGE' not in permissions): | 2056 and 'android.permission.READ_EXTERNAL_STORAGE' not in permissions): |
2058 permissions.append('android.permission.READ_EXTERNAL_STORAGE') | 2057 permissions.append('android.permission.READ_EXTERNAL_STORAGE') |
2059 cmd = ';'.join('pm grant %s %s' %(package, p) for p in permissions) | 2058 cmd = ';'.join('pm grant %s %s' %(package, p) for p in permissions) |
2060 if cmd: | 2059 if cmd: |
2061 output = self.RunShellCommand(cmd) | 2060 output = self.RunShellCommand(cmd) |
2062 if output: | 2061 if output: |
2063 logging.warning('Possible problem when granting permissions. Blacklist ' | 2062 logging.warning('Possible problem when granting permissions. Blacklist ' |
2064 'may need to be updated.') | 2063 'may need to be updated.') |
2065 logging.warning(output) | 2064 logging.warning(output) |
OLD | NEW |