1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-03-04 01:07:51 +00:00

Target: Updated install_apk to version from WA2

This version of the method adds support for both replacing and downgrading of
APKS.
This commit is contained in:
Marc Bonnici 2017-05-31 15:51:31 +01:00
parent 48d717b301
commit c33dd65249

View File

@ -1037,10 +1037,18 @@ class AndroidTarget(Target):
return line.split('=', 1)[1]
return None
def install_apk(self, filepath, timeout=None): # pylint: disable=W0221
def install_apk(self, filepath, timeout=None, replace=False, allow_downgrade=False): # pylint: disable=W0221
ext = os.path.splitext(filepath)[1].lower()
if ext == '.apk':
return adb_command(self.adb_name, "install '{}'".format(filepath), timeout=timeout)
flags = []
if replace:
flags.append('-r') # Replace existing APK
if allow_downgrade:
flags.append('-d') # Install the APK even if a newer version is already installed
if self.get_sdk_version() >= 23:
flags.append('-g') # Grant all runtime permissions
self.logger.debug("Replace APK = {}, ADB flags = '{}'".format(replace, ' '.join(flags)))
return adb_command(self.adb_name, "install {} '{}'".format(' '.join(flags), filepath), timeout=timeout)
else:
raise TargetError('Can\'t install {}: unsupported format.'.format(filepath))