From f9434f2a0d7d12b168ebd6d5b19663a0092c8477 Mon Sep 17 00:00:00 2001 From: Michele Di Giorgio Date: Tue, 20 Sep 2016 17:37:24 +0100 Subject: [PATCH] libs/utils/android/workloads: add video preview workload for Android targets Signed-off-by: Michele Di Giorgio --- libs/utils/android/workloads/videopreview.py | 103 +++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 libs/utils/android/workloads/videopreview.py diff --git a/libs/utils/android/workloads/videopreview.py b/libs/utils/android/workloads/videopreview.py new file mode 100644 index 000000000..35f578b9d --- /dev/null +++ b/libs/utils/android/workloads/videopreview.py @@ -0,0 +1,103 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (C) 2015, ARM Limited and contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import logging +import os +import re + +from time import sleep +from android import Screen, System +from android.workload import Workload + +class VideoPreview(Workload): + """ + Android VideoPreview workload + """ + + # Package required by this workload + package = 'com.google.android.GoogleCamera' + action = 'android.media.action.VIDEO_CAPTURE' + + def __init__(self, test_env): + super(VideoPreview, self).__init__(test_env) + self._log = logging.getLogger('VideoPreview') + self._log.debug('Workload created') + + def run(self, out_dir, duration_s=30, collect='systrace'): + """ + Run a video preview workload + + :param out_dir: Path to experiment directory where to store results. + :type out_dir: str + + :param duration_s: Duration of test + :type duration_s: int + + :param collect: Specifies what to collect. Possible values: + - 'energy' + - 'systrace' + - 'ftrace' + - any combination of the above + :type collect: list(str) + """ + self._log.info("Running VideoPreview for {}s and collecting {}".format(duration_s, collect)) + + # Keep track of mandatory parameters + self.out_dir = out_dir + self.collect = collect + + # Unlock device screen (assume no password required) + Screen.unlock(self._target) + + # Set airplane mode + System.set_airplane_mode(self._target, on=True) + + # Set min brightness + Screen.set_brightness(self._target, auto=False, percent=0) + + # Start video capture + System.start_action(self._target, self.action) + + # Force screen in LANDSCAPE mode + Screen.set_orientation(self._target, portrait=False) + + # Allow the activity to start + sleep(3) + + self.tracingStart() + + sleep(duration_s) + + self.tracingStop() + + # Close the app without clearing the local data to + # avoid the dialog to select the account at next start + System.force_stop(self._target, self.package, clear=False) + + # Go back to home screen + System.home(self._target) + + # Set brightness back to auto + Screen.set_brightness(self._target, auto=True) + + # Switch back to screen auto rotation + Screen.set_orientation(self._target, auto=True) + + # Switch off airplane mode + System.set_airplane_mode(self._target, on=False) + +# vim :set tabstop=4 shiftwidth=4 expandtab -- GitLab