From c722a6a73c2e5852569548f4568183cceb32fbb5 Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Fri, 14 Jul 2017 18:11:05 +0100 Subject: [PATCH] ApkResolution: Now takes into account apk abi when resolving. Previously any apk found would be selected even if the abi did not match the device, now an apk is only selected if it is compatible with the device. Additionally the 'exact_abi' parameter has been added to allow only selecting an apk if a devices primary abi's native code is present in the apk, or there is no native code. --- wa/framework/resource.py | 29 ++++++++++++++++++++++++++--- wa/framework/workload.py | 18 +++++++++++++++--- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/wa/framework/resource.py b/wa/framework/resource.py index 3db8ad57..8cec1c17 100644 --- a/wa/framework/resource.py +++ b/wa/framework/resource.py @@ -29,7 +29,7 @@ from wa.framework.exception import ResourceError from wa.framework.configuration import settings from wa.utils import log from wa.utils.misc import ensure_directory_exists as _d, get_object_name -from wa.utils.types import boolean, prioritylist, enum +from wa.utils.types import boolean, prioritylist, enum, list_or_string @@ -144,17 +144,21 @@ class ApkFile(Resource): kind = 'apk' def __init__(self, owner, variant=None, version=None, - package=None, uiauto=False): + package=None, uiauto=False, exact_abi=False, + supported_abi=None): super(ApkFile, self).__init__(owner) self.variant = variant self.version = version self.package = package self.uiauto = uiauto + self.exact_abi = exact_abi + self.supported_abi = supported_abi def match(self, path): name_matches = True version_matches = True package_matches = True + abi_matches = True uiauto_matches = uiauto_test_matches(path, self.uiauto) if self.version is not None: version_matches = apk_version_matches(path, self.version) @@ -162,8 +166,12 @@ class ApkFile(Resource): name_matches = file_name_matches(path, self.variant) if self.package is not None: package_matches = package_name_matches(path, self.package) + if self.supported_abi is not None: + abi_matches = apk_abi_matches(path, self.supported_abi, + self.exact_abi) return name_matches and version_matches and \ - uiauto_matches and package_matches + uiauto_matches and package_matches and \ + abi_matches def __str__(self): @@ -289,3 +297,18 @@ def uiauto_test_matches(path, uiauto): def package_name_matches(path, package): info = ApkInfo(path) return info.package == package + +def apk_abi_matches(path, supported_abi, exact_abi=False): + supported_abi = list_or_string(supported_abi) + info = ApkInfo(path) + # If no native code present, suitable for all devices. + if not info.native_code: + return True + + if exact_abi: # Only check primary + return supported_abi[0] in info.native_code + else: + for abi in supported_abi: + if abi in info.native_code: + return True + return False diff --git a/wa/framework/workload.py b/wa/framework/workload.py index cd1fd92f..b2a9a434 100644 --- a/wa/framework/workload.py +++ b/wa/framework/workload.py @@ -145,6 +145,12 @@ class ApkWorkload(Workload): description=""" If ``True``, will uninstall workload\'s APK as part of teardown.' """), + Parameter('exact_abi', kind=bool, + default=False, + description=""" + If ``True``, workload will check that the APK matches the target + device ABI, otherwise any suitable APK found will be used. + """) ] def __init__(self, target, **kwargs): @@ -156,7 +162,8 @@ class ApkWorkload(Workload): version=self.version, force_install=self.force_install, install_timeout=self.install_timeout, - uninstall=self.uninstall) + uninstall=self.uninstall, + exact_abi=self.exact_abi) def init_resources(self, context): pass @@ -423,7 +430,8 @@ class ReventGUI(object): class PackageHandler(object): def __init__(self, owner, install_timeout=300, version=None, variant=None, - package=None, strict=False, force_install=False, uninstall=False): + package=None, strict=False, force_install=False, uninstall=False, + exact_abi=False): self.logger = logging.getLogger('apk') self.owner = owner self.target = self.owner.target @@ -434,10 +442,12 @@ class PackageHandler(object): self.strict = strict self.force_install = force_install self.uninstall = uninstall + self.exact_abi = exact_abi self.apk_file = None self.apk_info = None self.apk_version = None self.logcat_log = None + self.supported_abi = self.target.supported_abi def initialize(self, context): self.resolve_package(context) @@ -452,7 +462,9 @@ class PackageHandler(object): self.apk_file = context.resolver.get(ApkFile(self.owner, variant=self.variant, version=self.version, - package=self.package), + package=self.package, + exact_abi=self.exact_abi, + supported_abi=self.supported_abi), strict=self.strict) if self.apk_file: self.apk_info = ApkInfo(self.apk_file)