• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPDX-License-Identifier: Apache-2.0
2#
3# Copyright (C) 2015, ARM Limited, Google and contributors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18import re
19import os
20import logging
21
22from time import sleep
23
24from target_script import TargetScript
25from android import Screen, System
26from android.workload import Workload
27
28
29class CameraStartup(Workload):
30    """
31    Android CameraStartup workload
32    """
33
34    # Package required by this workload
35    package = 'com.google.android.GoogleCamera'
36    action = 'android.intent.action.MAIN'
37
38    def __init__(self, test_env):
39        super(CameraStartup, self).__init__(test_env)
40        self._log = logging.getLogger('CameraStartup')
41        self._log.debug('Workload created')
42
43    def run(self, out_dir, duration_s=10, collect='surfaceflinger'):
44        """
45        Run a camera startup workload
46
47        :param out_dir: Path to experiment directory where to store results.
48        :type out_dir: str
49
50        :param duration_s: Duration of test
51        :type duration_s: int
52
53        :param collect: Specifies what to collect. Possible values:
54            - 'energy'
55            - 'systrace'
56            - 'ftrace'
57            - any combination of the above
58        :type collect: list(str)
59        """
60
61        self._log.info("Running CameraStartup for {}s and collecting {}".format(duration_s, collect))
62
63        # Keep track of mandatory parameters
64        self.out_dir = out_dir
65        self.collect = collect
66
67        # Unlock device screen (assume no password required)
68        Screen.unlock(self._target)
69
70        # Set airplane mode
71        System.set_airplane_mode(self._target, on=True)
72
73        # Set min brightness
74        Screen.set_brightness(self._target, auto=False, percent=0)
75
76        # Force screen in PORTRAIT  mode
77        Screen.set_orientation(self._target, portrait=True)
78
79        sleep(1)
80
81        self.tracingStart()
82        # Wait for a few seconds so that you can clear see start of trace and start of camera app
83        sleep(3)
84
85        # Use the monkey tool to start CameraStartup
86        System.monkey(self._target, self.package)
87
88        sleep(duration_s)
89
90        self.tracingStop()
91
92        # Close the app without clearing the local data to
93        # avoid the dialog to select the account at next start
94        System.force_stop(self._target, self.package, clear=False)
95
96        # Go back to home screen
97        System.home(self._target)
98
99        # Set brightness back to auto
100        Screen.set_brightness(self._target, auto=True)
101
102        # Switch back to screen auto rotation
103        Screen.set_orientation(self._target, auto=True)
104
105        # Switch off airplane mode
106        System.set_airplane_mode(self._target, on=False)
107