From 86f3066f5688705ea7f5cf706b580d025ab81b8a Mon Sep 17 00:00:00 2001 From: John Richardson Date: Thu, 4 Aug 2016 15:03:28 +0100 Subject: [PATCH] Add unsupported package check to AndroidUiAutoBenchmark Add method to automatically check against a dictionary of known package versions that don't work well with AndroidUiAutoBenchmark workloads. Raises an exception if found. --- wlauto/common/android/workload.py | 25 ++++++++++++++++++++++++- wlauto/utils/android.py | 10 ++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/wlauto/common/android/workload.py b/wlauto/common/android/workload.py index 71502ebf..21ce3d56 100644 --- a/wlauto/common/android/workload.py +++ b/wlauto/common/android/workload.py @@ -24,7 +24,7 @@ from wlauto.core.resource import NO_ONE from wlauto.common.android.resources import ApkFile from wlauto.common.resources import ExtensionAsset, Executable from wlauto.exceptions import WorkloadError, ResourceError, ConfigError, DeviceError -from wlauto.utils.android import ApkInfo, ANDROID_NORMAL_PERMISSIONS +from wlauto.utils.android import ApkInfo, ANDROID_NORMAL_PERMISSIONS, UNSUPPORTED_PACKAGES from wlauto.utils.types import boolean from wlauto.utils.revent import ReventParser from wlauto import File @@ -428,6 +428,11 @@ class AndroidUiAutoBenchmark(UiAutomatorWorkload, AndroidBenchmark): UiAutomatorWorkload.__init__(self, device, **kwargs) AndroidBenchmark.__init__(self, device, _call_super=False, **kwargs) + def initialize(self, context): + UiAutomatorWorkload.initialize(self, context) + AndroidBenchmark.initialize(self, context) + self._check_unsupported_packages() + def init_resources(self, context): UiAutomatorWorkload.init_resources(self, context) AndroidBenchmark.init_resources(self, context) @@ -444,6 +449,24 @@ class AndroidUiAutoBenchmark(UiAutomatorWorkload, AndroidBenchmark): UiAutomatorWorkload.teardown(self, context) AndroidBenchmark.teardown(self, context) + def _check_unsupported_packages(self): + """ + Check for any unsupported package versions and raise an + exception if detected. + + """ + for package in UNSUPPORTED_PACKAGES: + version = self.device.get_installed_package_version(package) + if version is None: + continue + + if '-' in version: + version = version.split('-')[0] # ignore abi version + + if version in UNSUPPORTED_PACKAGES[package]: + message = 'This workload does not support version "{}" of package "{}"' + raise WorkloadError(message.format(version, package)) + class GameWorkload(ApkWorkload, ReventWorkload): """ diff --git a/wlauto/utils/android.py b/wlauto/utils/android.py index b50b58b9..881c4da0 100644 --- a/wlauto/utils/android.py +++ b/wlauto/utils/android.py @@ -100,6 +100,16 @@ ANDROID_NORMAL_PERMISSIONS = [ 'UNINSTALL_SHORTCUT', ] +# Package versions that are known to have problems with AndroidUiAutoBenchmark workloads. +# NOTE: ABI versions are not included. +UNSUPPORTED_PACKAGES = { + # Google Keyboard: + # For some versions of the Google Keyboard package device key presses are + # not registered correctly when running UiAutomator Workloads. + 'com.google.android.inputmethod.latin': ['5.0.25.122319759'] +} + + # TODO: these are set to their actual values near the bottom of the file. There # is some HACKery involved to ensure that ANDROID_HOME does not need to be set # or adb added to path for root when installing as root, and the whole