1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-09-03 03:42:35 +01:00

Properly replace APK during adb install

Issue: For certain installation errors, it is possible for WA to
 incorrectly report that an APK was reinstalled while it actually
 wasn't, leading to bugs later on in the run.

Fix:
 - Add the '-r' flag to adb install when reinstalling, to make sure
   APK is replaced.
 - Add '-g' flag for API 23 and higher, to grant all permissions that
   would otherwise be requested at runtime (similar to pre-API 23)
This commit is contained in:
muendelezaji
2016-06-21 14:21:03 +01:00
parent 25dd6b71f3
commit fab6a977aa
2 changed files with 18 additions and 11 deletions

View File

@@ -349,18 +349,24 @@ class AndroidDevice(BaseLinuxDevice): # pylint: disable=W0223
timeout=self.default_timeout)
return bool(int(output))
def install(self, filepath, timeout=default_timeout, with_name=None): # pylint: disable=W0221
def install(self, filepath, timeout=default_timeout, with_name=None, replace=False): # pylint: disable=W0221
ext = os.path.splitext(filepath)[1].lower()
if ext == '.apk':
return self.install_apk(filepath, timeout)
return self.install_apk(filepath, timeout, replace)
else:
return self.install_executable(filepath, with_name)
def install_apk(self, filepath, timeout=default_timeout): # pylint: disable=W0221
def install_apk(self, filepath, timeout=default_timeout, replace=False): # pylint: disable=W0221
self._check_ready()
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 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 DeviceError('Can\'t install {}: unsupported format.'.format(filepath))