Kuo Jen Wei | 7f00bb3 | 2018-11-01 15:35:24 +0800 | [diff] [blame] | 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. |
| 8 | import common |
| 9 | |
| 10 | import argparse |
| 11 | import contextlib |
| 12 | import logging |
| 13 | import os |
| 14 | import signal |
| 15 | import time |
| 16 | |
| 17 | from autotest_lib.client.bin import utils |
| 18 | from autotest_lib.client.common_lib.cros import chrome |
| 19 | from autotest_lib.client.cros.input_playback import keyboard |
| 20 | |
| 21 | DISPLAY_LEVEL = 96.0 |
| 22 | |
| 23 | |
| 24 | @contextlib.contextmanager |
| 25 | def 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 | |
| 41 | def 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 | |
Kuo Jen Wei | 377e99b | 2020-02-25 16:39:42 +0800 | [diff] [blame] | 56 | with chrome.Chrome(init_network_controller=True |
| 57 | ) as cr, set_display_brightness(DISPLAY_LEVEL): |
Kuo Jen Wei | 7f00bb3 | 2018-11-01 15:35:24 +0800 | [diff] [blame] | 58 | logging.info('Display chart file of path %r.', filepath) |
Kuo Jen Wei | 377e99b | 2020-02-25 16:39:42 +0800 | [diff] [blame] | 59 | cr.browser.platform.SetHTTPServerDirectories(os.path.dirname(filepath)) |
Kuo Jen Wei | 7f00bb3 | 2018-11-01 15:35:24 +0800 | [diff] [blame] | 60 | tab = cr.browser.tabs[0] |
Kuo Jen Wei | 377e99b | 2020-02-25 16:39:42 +0800 | [diff] [blame] | 61 | tab.Navigate(cr.browser.platform.http_server.UrlOf(filepath)) |
Kuo Jen Wei | 7f00bb3 | 2018-11-01 15:35:24 +0800 | [diff] [blame] | 62 | |
| 63 | logging.info('Set chart tab fullscreen.') |
| 64 | kb = keyboard.Keyboard() |
| 65 | kb.press_key('f4') |
| 66 | kb.close() |
| 67 | |
| 68 | while displaying: |
| 69 | time.sleep(1) |
| 70 | |
| 71 | |
| 72 | if __name__ == '__main__': |
| 73 | argparser = argparse.ArgumentParser( |
| 74 | description='Display chart file on chrome by using telemetry.' |
| 75 | ' Send SIGINT or keyboard interrupt to stop displaying.') |
| 76 | argparser.add_argument('filepath', help='Path of displayed chart file.') |
| 77 | |
| 78 | args = argparser.parse_args() |
| 79 | display(args.filepath) |