1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-18 12:06:08 +00:00

fw/ApkWorkload: Allow workloads to provide apk arguments

In some workloads it is beneficial to be able to provide arguments
when launching the required APK. Add a new `arpk_arguments` property
to allow a workload to provide a dict of parameter names and values
that should be used when launching the APK.

The python types of the parameters are used to determine the data
type provided to the APK. Currently supported types are string, bool,
int and float.
This commit is contained in:
Marc Bonnici 2023-03-31 15:26:10 +01:00
parent 3228a3187c
commit 36a909dda2
2 changed files with 37 additions and 8 deletions

View File

@ -23,7 +23,7 @@ except ImportError:
from pipes import quote from pipes import quote
from wa.utils.android import get_cacheable_apk_info from wa.utils.android import get_cacheable_apk_info, build_apk_launch_command
from wa.framework.plugin import TargetedPlugin, Parameter from wa.framework.plugin import TargetedPlugin, Parameter
from wa.framework.resource import (ApkFile, ReventFile, from wa.framework.resource import (ApkFile, ReventFile,
File, loose_version_matching, File, loose_version_matching,
@ -180,6 +180,7 @@ class ApkWorkload(Workload):
activity = None activity = None
view = None view = None
clear_data_on_reset = True clear_data_on_reset = True
apk_arguments = {}
# Set this to True to mark that this workload requires the target apk to be run # Set this to True to mark that this workload requires the target apk to be run
# for initialisation purposes before the main run is performed. # for initialisation purposes before the main run is performed.
@ -289,7 +290,8 @@ class ApkWorkload(Workload):
clear_data_on_reset=self.clear_data_on_reset, clear_data_on_reset=self.clear_data_on_reset,
activity=self.activity, activity=self.activity,
min_version=self.min_version, min_version=self.min_version,
max_version=self.max_version) max_version=self.max_version,
apk_arguments=self.apk_arguments)
def validate(self): def validate(self):
if self.min_version and self.max_version: if self.min_version and self.max_version:
@ -686,7 +688,7 @@ class PackageHandler(object):
def __init__(self, owner, install_timeout=300, version=None, variant=None, def __init__(self, owner, install_timeout=300, version=None, variant=None,
package_name=None, strict=False, force_install=False, uninstall=False, package_name=None, strict=False, force_install=False, uninstall=False,
exact_abi=False, prefer_host_package=True, clear_data_on_reset=True, exact_abi=False, prefer_host_package=True, clear_data_on_reset=True,
activity=None, min_version=None, max_version=None): activity=None, min_version=None, max_version=None, apk_arguments=None):
self.logger = logging.getLogger('apk') self.logger = logging.getLogger('apk')
self.owner = owner self.owner = owner
self.target = self.owner.target self.target = self.owner.target
@ -709,6 +711,7 @@ class PackageHandler(object):
self.apk_version = None self.apk_version = None
self.logcat_log = None self.logcat_log = None
self.error_msg = None self.error_msg = None
self.apk_arguments = apk_arguments
def initialize(self, context): def initialize(self, context):
self.resolve_package(context) self.resolve_package(context)
@ -853,11 +856,10 @@ class PackageHandler(object):
self.apk_version = host_version self.apk_version = host_version
def start_activity(self): def start_activity(self):
if not self.activity:
cmd = 'am start -W {}'.format(self.apk_info.package) cmd = build_apk_launch_command(self.apk_info.package, self.activity,
else: self.apk_arguments)
cmd = 'am start -W -n {}/{}'.format(self.apk_info.package,
self.activity)
output = self.target.execute(cmd) output = self.target.execute(cmd)
if 'Error:' in output: if 'Error:' in output:
# this will dismiss any error dialogs # this will dismiss any error dialogs

View File

@ -16,6 +16,7 @@
import logging import logging
import os import os
from datetime import datetime from datetime import datetime
from shlex import quote
from devlib.utils.android import ApkInfo as _ApkInfo from devlib.utils.android import ApkInfo as _ApkInfo
@ -196,3 +197,29 @@ def get_cacheable_apk_info(path):
apk_info_cache = ApkInfoCache() apk_info_cache = ApkInfoCache()
def build_apk_launch_command(package, activity=None, apk_args=None):
args_string = ''
if apk_args:
for k, v in apk_args.items():
if isinstance(v, str):
arg = '--es'
v = quote(v)
elif isinstance(v, float):
arg = '--ef'
elif isinstance(v, bool):
arg = '--ez'
elif isinstance(v, int):
arg = '--ei'
else:
raise ValueError('Unable to encode {} {}'.format(v, type(v)))
args_string = '{} {} {} {}'.format(args_string, arg, k, v)
if not activity:
cmd = 'am start -W {} {}'.format(package, args_string)
else:
cmd = 'am start -W -n {}/{} {}'.format(package, activity, args_string)
return cmd