• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5'''Login with test account and display chart file using telemetry.'''
6
7# This sets up import paths for autotest.
8import common
9
10import argparse
11import contextlib
12import logging
13import os
14import signal
15import time
16
17from autotest_lib.client.bin import utils
18from autotest_lib.client.common_lib.cros import chrome
19from autotest_lib.client.cros.input_playback import keyboard
20
21DISPLAY_LEVEL = 96.0
22
23
24@contextlib.contextmanager
25def set_display_brightness(display_level):
26    SET_BRIGHTNESS_CMD = 'backlight_tool --set_brightness_percent=%s'
27
28    original_display_level = utils.system_output(
29            'backlight_tool --get_brightness_percent')
30    logging.info('Save original display brightness %r '
31                 'and fix display brightness to %r', original_display_level,
32                 display_level)
33    utils.system(SET_BRIGHTNESS_CMD % display_level)
34    utils.system('stop powerd', ignore_status=True)
35    yield
36    logging.info('Restore display brightness %r', original_display_level)
37    utils.system('start powerd', ignore_status=True)
38    utils.system(SET_BRIGHTNESS_CMD % original_display_level)
39
40
41def display(filepath):
42    """Display chart with filepath on device by using telemetry."""
43    assert os.path.isfile(filepath), 'filepath %r not found.' % filepath
44    filepath = os.path.abspath(filepath)
45
46    logging.info('Setup SIGINT listener for stop displaying.')
47    displaying = [True]
48
49    def handler(signum, frame):
50        """Wait signal to clear running flag."""
51        if signum == signal.SIGINT:
52            displaying.pop()
53
54    signal.signal(signal.SIGINT, handler)
55
56    with chrome.Chrome() as cr, set_display_brightness(DISPLAY_LEVEL):
57        logging.info('Display chart file of path %r.', filepath)
58        tab = cr.browser.tabs[0]
59        tab.Navigate('file://' + filepath)
60
61        logging.info('Set chart tab fullscreen.')
62        kb = keyboard.Keyboard()
63        kb.press_key('f4')
64        kb.close()
65
66        while displaying:
67            time.sleep(1)
68
69
70if __name__ == '__main__':
71    argparser = argparse.ArgumentParser(
72            description='Display chart file on chrome by using telemetry.'
73            ' Send SIGINT or keyboard interrupt to stop displaying.')
74    argparser.add_argument('filepath', help='Path of displayed chart file.')
75
76    args = argparser.parse_args()
77    display(args.filepath)
78