diff --git a/wa/framework/target/runtime_config.py b/wa/framework/target/runtime_config.py index 7aadc3e2..973f845f 100644 --- a/wa/framework/target/runtime_config.py +++ b/wa/framework/target/runtime_config.py @@ -1,4 +1,5 @@ import logging +import time from collections import defaultdict, OrderedDict from copy import copy @@ -893,7 +894,18 @@ class AndroidRuntimeConfig(RuntimeConfig): def commit(self): if 'airplane_mode' in self.config: - self.target.set_airplane_mode(self.config['airplane_mode']) + new_airplane_mode = self.config['airplane_mode'] + old_airplane_mode = self.target.get_airplane_mode() + self.target.set_airplane_mode(new_airplane_mode) + + # If we've just switched airplane mode off, wait a few seconds to + # enable the network state to stabilise. That's helpful if we're + # about to run a workload that is going to check for network + # connectivity. + if old_airplane_mode and not new_airplane_mode: + self.logger.info('Disabled airplane mode, waiting 5 seconds for network setup') + time.sleep(5) + if 'brightness' in self.config: self.target.set_brightness(self.config['brightness']) if 'rotation' in self.config: diff --git a/wa/framework/workload.py b/wa/framework/workload.py index 7638b376..bb002e8e 100644 --- a/wa/framework/workload.py +++ b/wa/framework/workload.py @@ -50,6 +50,12 @@ class Workload(TargetedPlugin): prevent this workload from being run accidentally. """ + requires_network = False + """ + Set this to ``True`` to mark the the workload will fail without a network + connection, this enables it to fail early with a clear message. + """ + def init_resources(self, context): """ This method may be used to perform early resource discovery and @@ -77,7 +83,11 @@ class Workload(TargetedPlugin): This is also the place to perform any on-device checks prior to attempting to execute the workload. """ - pass + if self.requires_network and not self.target.is_network_connected(): + raise WorkloadError( + 'Workload "{}" requires internet. Target does not appear ' + 'to be connected to the internet.'.format(self.name)) + def run(self, context): """ @@ -193,6 +203,7 @@ class ApkWorkload(Workload): self.apk.activity) def setup(self, context): + super(ApkWorkload, self).setup(context) self.apk.setup(context) time.sleep(self.loading_time) diff --git a/wa/workloads/geekbench/__init__.py b/wa/workloads/geekbench/__init__.py index c0b24da1..cdf8128a 100644 --- a/wa/workloads/geekbench/__init__.py +++ b/wa/workloads/geekbench/__init__.py @@ -100,6 +100,8 @@ class Geekbench(ApkUiautoWorkload): phones_home = True + requires_network = True + @property def activity(self): return self.versions[self.version]['activity'] @@ -402,6 +404,7 @@ class GBScoreCalculator(object): class GeekbenchCorproate(Geekbench): name = "geekbench-corporate" is_corporate = True + requires_network = False versions = ['4.1.0']