diff --git a/libs/utils/android/system.py b/libs/utils/android/system.py index c26b0dd0830691c15e74b3892634f117662a7adc..3708d959495325e61ba97a8aeb3f7c9062390c63 100644 --- a/libs/utils/android/system.py +++ b/libs/utils/android/system.py @@ -47,8 +47,11 @@ class System(object): return None # Format the command according to the specified arguments - systrace_pattern = "{} -e {} -o {} {}" - trace_cmd = systrace_pattern.format(systrace_path, target.conf['device'], + device = target.conf.get('device', '') + if device: + device = "-e {}".format(device) + systrace_pattern = "{} {} -o {} {}" + trace_cmd = systrace_pattern.format(systrace_path, device, trace_file, " ".join(events)) if time is not None: trace_cmd += " -t {}".format(time) @@ -81,6 +84,37 @@ class System(object): log = logging.getLogger('System') log.warning('Failed to toggle airplane mode, permission denied.') + @staticmethod + def _set_svc(target, cmd, on=True): + mode = 'enable' if on else 'disable' + try: + target.execute('svc {} {}'.format(cmd, mode), as_root=True) + except TargetError: + log = logging.getLogger('System') + log.warning('Failed to toggle {} mode, permission denied.'\ + .format(cmd)) + + @staticmethod + def set_mobile_data(target, on=True): + """ + Set mobile data connectivity + """ + System._set_svc(target, 'data', on) + + @staticmethod + def set_wifi(target, on=True): + """ + Set mobile data connectivity + """ + System._set_svc(target, 'wifi', on) + + @staticmethod + def set_nfc(target, on=True): + """ + Set mobile data connectivity + """ + System._set_svc(target, 'nfc', on) + @staticmethod def start_app(target, apk_name): """ diff --git a/libs/utils/android/workload.py b/libs/utils/android/workload.py index 626b65d501df675cf85f668540eb26a570539430..b7ef3af16a7ba176a63881df8cca8c413111141d 100644 --- a/libs/utils/android/workload.py +++ b/libs/utils/android/workload.py @@ -18,6 +18,7 @@ import logging import os import re +import webbrowser from . import System @@ -134,4 +135,26 @@ class Workload(object): # Dump a platform description self._te.platform_dump(self.out_dir) + def traceShow(self): + """ + Open the collected trace using the most appropriate native viewer. + + The native viewer depends on the specified trace format: + - ftrace: open using kernelshark + - systrace: open using a browser + + In both cases the native viewer is assumed to be available in the host + machine. + """ + + if 'ftrace' in self.collect: + os.popen("kernelshark {}".format(self.trace_file)) + return + + if 'systrace' in self.collect: + webbrowser.open(self.trace_file) + return + + self._log.warning('No trace collected since last run') + # vim :set tabstop=4 shiftwidth=4 expandtab