@@ -178,6 +178,7 @@ class ApkWorkload(Workload):
178178 package_names = []
179179 supported_versions = []
180180 activity = None
181+ duration = None
181182 view = None
182183 clear_data_on_reset = True
183184
@@ -271,10 +272,16 @@ def __init__(self, target, **kwargs):
271272
272273 super (ApkWorkload , self ).__init__ (target , ** kwargs )
273274
274- if self .activity is not None and '.' not in self .activity :
275- # If we're receiving just the activity name, it's taken relative to
276- # the package namespace:
277- self .activity = '.' + self .activity
275+ if self .activity is not None :
276+ activities = self .activity .split ()
277+ self .activity = ''
278+ for activity in activities :
279+ if '.' not in activity :
280+ # If we're receiving just the activity name, it's taken relative to
281+ # the package namespace:
282+ self .activity += ' .' + activity
283+ else :
284+ self .activity += ' ' + activity
278285
279286 self .apk = PackageHandler (self ,
280287 package_name = self .package_name ,
@@ -288,6 +295,7 @@ def __init__(self, target, **kwargs):
288295 prefer_host_package = self .prefer_host_package ,
289296 clear_data_on_reset = self .clear_data_on_reset ,
290297 activity = self .activity ,
298+ duration = self .duration ,
291299 min_version = self .min_version ,
292300 max_version = self .max_version )
293301
@@ -686,7 +694,7 @@ def activity(self):
686694 def __init__ (self , owner , install_timeout = 300 , version = None , variant = None ,
687695 package_name = None , strict = False , force_install = False , uninstall = False ,
688696 exact_abi = False , prefer_host_package = True , clear_data_on_reset = True ,
689- activity = None , min_version = None , max_version = None ):
697+ activity = None , duration = None , min_version = None , max_version = None ):
690698 self .logger = logging .getLogger ('apk' )
691699 self .owner = owner
692700 self .target = self .owner .target
@@ -703,6 +711,7 @@ def __init__(self, owner, install_timeout=300, version=None, variant=None,
703711 self .prefer_host_package = prefer_host_package
704712 self .clear_data_on_reset = clear_data_on_reset
705713 self ._activity = activity
714+ self .duration = duration
706715 self .supported_abi = self .target .supported_abi
707716 self .apk_file = None
708717 self .apk_info = None
@@ -852,18 +861,27 @@ def initialize_package(self, context):
852861 self .target .grant_package_permission (self .apk_info .package , permission )
853862 self .apk_version = host_version
854863
855- def start_activity (self ):
856- if not self .activity :
857- cmd = 'am start -W {}' .format (self .apk_info .package )
858- else :
859- cmd = 'am start -W -n {}/{}' .format (self .apk_info .package ,
860- self .activity )
864+ def _start_activity (self , cmd ):
861865 output = self .target .execute (cmd )
862866 if 'Error:' in output :
863867 # this will dismiss any error dialogs
864868 self .target .execute ('am force-stop {}' .format (self .apk_info .package ))
865869 raise WorkloadError (output )
866870 self .logger .debug (output )
871+ if self .duration :
872+ self .target .sleep (self .duration )
873+ self .target .execute ('am force-stop {}' .format (self .apk_info .package ))
874+
875+ def start_activity (self ):
876+ if not self .activity :
877+ cmd = 'am start -W {}' .format (self .apk_info .package )
878+ self ._start_activity (cmd )
879+ else :
880+ for activity in self .activity .split ():
881+ self .logger .info ("Launching {} activity for {} seconds" .format (activity , self .duration ))
882+ cmd = 'am start -W -n {}/{}' .format (self .apk_info .package ,
883+ activity )
884+ self ._start_activity (cmd )
867885
868886 def restart_activity (self ):
869887 self .target .execute ('am force-stop {}' .format (self .apk_info .package ))
0 commit comments