OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2017 The Chromium 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 import webvr_latency_test | |
6 | |
7 import logging | |
8 import os | |
9 import time | |
10 | |
11 | |
12 DEFAULT_SCREEN_WIDTH = 720 | |
13 DEFAULT_SCREEN_HEIGHT = 1280 | |
14 NUM_VR_ENTRY_ATTEMPTS = 5 | |
15 | |
Nico
2017/04/20 17:51:21
nit: two blank lines between toplevel things
bsheedy
2017/04/20 20:05:00
Done.
| |
16 class AndroidWebVrLatencyTest(webvr_latency_test.WebVrLatencyTest): | |
17 """Android implementation of the WebVR latency test.""" | |
18 def __init__(self, args): | |
19 super(AndroidWebVrLatencyTest, self).__init__(args) | |
20 self._device_name = self._Adb(['shell', 'getprop', | |
21 'ro.product.name']).strip() | |
22 | |
23 def _Setup(self): | |
24 self._Adb(['root']) | |
25 | |
26 # Install the latest VrCore and Chrome APKs | |
27 self._Adb(['install', '-r', '-d', | |
28 '../../third_party/gvr-android-sdk/test-apks/vr_services' | |
29 '/vr_services_current.apk']) | |
30 self._SaveInstalledVrCoreVersion() | |
31 # TODO(bsheedy): Make APK path configurable so usable with other channels | |
32 self._Adb(['install', '-r', 'apks/ChromePublic.apk']) | |
33 | |
34 # Force WebVR support, remove open tabs, and don't have first run | |
35 # experience. | |
36 self._SetChromeCommandLineFlags(['--enable-webvr', '--no-restore-state', | |
37 '--disable-fre']) | |
38 # Wake up the device and sleep, otherwise WebGL can crash on startup. | |
39 self._Adb(['shell', 'input', 'keyevent', 'KEYCODE_WAKEUP']) | |
40 time.sleep(1) | |
41 | |
42 # Start Chrome | |
43 self._Adb(['shell', 'am', 'start', | |
44 '-a', 'android.intent.action.MAIN', | |
45 '-n', 'org.chromium.chrome/com.google.android.apps.chrome.Main', | |
46 self._flicker_app_url]) | |
47 time.sleep(10) | |
48 | |
49 # Tap the center of the screen to start presenting. | |
50 # It's technically possible that the screen tap won't enter VR on the first | |
51 # time, so try several times by checking for the logcat output from | |
52 # entering VR | |
53 (width, height) = self._GetScreenResolution() | |
54 entered_vr = False | |
55 for _ in xrange(NUM_VR_ENTRY_ATTEMPTS): | |
56 self._Adb(['logcat', '-c']) | |
57 self._Adb(['shell', 'input', 'touchscreen', 'tap', str(width/2), | |
58 str(height/2)]) | |
59 time.sleep(5) | |
60 output = self._Adb(['logcat', '-d']) | |
61 if 'Initialized GVR version' in output: | |
62 entered_vr = True | |
63 break | |
64 logging.warning('Failed to enter VR, retrying') | |
65 if not entered_vr: | |
66 raise RuntimeError('Failed to enter VR after %d attempts' | |
67 % NUM_VR_ENTRY_ATTEMPTS) | |
68 | |
69 def _Teardown(self): | |
70 # Exit VR and close Chrome | |
71 self._Adb(['shell', 'input', 'keyevent', 'KEYCODE_BACK']) | |
72 self._Adb(['shell', 'am', 'force-stop', 'org.chromium.chrome']) | |
73 # Turn off the screen | |
74 self._Adb(['shell', 'input', 'keyevent', 'KEYCODE_POWER']) | |
75 | |
76 def _Adb(self, cmd): | |
77 """Runs the given command via adb. | |
78 | |
79 Returns: | |
80 A string containing the stdout and stderr of the adb command. | |
81 """ | |
82 # TODO(bsheedy): Maybe migrate to use Devil (overkill?) | |
83 return self._RunCommand([self.args.adb_path] + cmd) | |
84 | |
85 def _SaveInstalledVrCoreVersion(self): | |
86 """Retrieves the VrCore version and saves it for dashboard uploading.""" | |
87 output = self._Adb(['shell', 'dumpsys', 'package', 'com.google.vr.vrcore']) | |
88 version = None | |
89 for line in output.split('\n'): | |
90 if 'versionName' in line: | |
91 version = line.split('=')[1] | |
92 break | |
93 if version: | |
94 logging.info('VrCore version is %s', version) | |
95 else: | |
96 logging.info('VrCore version not retrieved') | |
97 version = '0' | |
98 if not (self.args.output_dir and os.path.isdir(self.args.output_dir)): | |
99 logging.warning('No output directory, not saving VrCore version') | |
100 return | |
101 with file(os.path.join(self.args.output_dir, | |
102 self.args.vrcore_version_file), 'w') as outfile: | |
103 outfile.write(version) | |
104 | |
105 def _SetChromeCommandLineFlags(self, flags): | |
106 """Sets the Chrome command line flags to the given list.""" | |
107 self._Adb(['shell', "echo 'chrome " + ' '.join(flags) + "' > " | |
108 + '/data/local/tmp/chrome-command-line']) | |
109 | |
110 def _GetScreenResolution(self): | |
111 """Retrieves the device's screen resolution, or a default if not found. | |
112 | |
113 Returns: | |
114 A tuple (width, height). | |
115 """ | |
116 output = self._Adb(['shell', 'dumpsys', 'display']) | |
117 width = None | |
118 height = None | |
119 for line in output.split('\n'): | |
120 if 'mDisplayWidth' in line: | |
121 width = int(line.split('=')[1]) | |
122 elif 'mDisplayHeight' in line: | |
123 height = int(line.split('=')[1]) | |
124 if width and height: | |
125 break | |
126 if not width: | |
127 logging.warning('Could not get actual screen width, defaulting to %d', | |
128 DEFAULT_SCREEN_WIDTH) | |
129 width = DEFAULT_SCREEN_WIDTH | |
130 if not height: | |
131 logging.warning('Could not get actual screen height, defaulting to %d', | |
132 DEFAULT_SCREEN_HEIGHT) | |
133 height = DEFAULT_SCREEN_HEIGHT | |
134 return (width, height) | |
OLD | NEW |