From c33dd6524941ec4db872e7f05237fa7d7c062d07 Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Wed, 31 May 2017 15:51:31 +0100 Subject: [PATCH] Target: Updated install_apk to version from WA2 This version of the method adds support for both replacing and downgrading of APKS. --- devlib/target.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/devlib/target.py b/devlib/target.py index 35473b4..8798ad4 100644 --- a/devlib/target.py +++ b/devlib/target.py @@ -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))