1# Copyright 2017 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"""An adapter to remotely access the CFM facade on DUT.""" 6 7import os 8import tempfile 9import time 10 11 12class CFMFacadeRemoteAdapter(object): 13 """CFMFacadeRemoteAdapter is an adapter to remotely control CFM on DUT. 14 15 The Autotest host object representing the remote DUT, passed to this 16 class on initialization, can be accessed from its _client property. 17 """ 18 _RESTART_UI_DELAY = 10 19 20 def __init__(self, host, remote_facade_proxy): 21 """Construct a CFMFacadeRemoteAdapter. 22 23 @param host: Host object representing a remote host. 24 @param remote_facade_proxy: RemoteFacadeProxy object. 25 """ 26 self._client = host 27 self._proxy = remote_facade_proxy 28 29 30 @property 31 def _cfm_proxy(self): 32 return self._proxy.cfm_main_screen 33 34 35 @property 36 def main_screen(self): 37 """CFM main screen API.""" 38 return self._proxy.cfm_main_screen 39 40 41 @property 42 def mimo_screen(self): 43 """CFM mimo screen API.""" 44 return self._proxy.cfm_mimo_screen 45 46 47 def enroll_device(self): 48 """Enroll device into CFM.""" 49 self._cfm_proxy.enroll_device() 50 51 52 def restart_chrome_for_cfm(self): 53 """Restart chrome for CFM.""" 54 self._cfm_proxy.restart_chrome_for_cfm() 55 56 def reboot_device_with_chrome_api(self): 57 """Reboot device using Chrome runtime API.""" 58 self._cfm_proxy.reboot_device_with_chrome_api() 59 60 def skip_oobe_after_enrollment(self): 61 """Skips oobe and goes to the app landing page after enrollment.""" 62 self._client.run('restart ui', ignore_status=True) 63 time.sleep(self._RESTART_UI_DELAY) 64 self._cfm_proxy.skip_oobe_after_enrollment() 65 66 67 def wait_for_telemetry_commands(self): 68 """Wait for telemetry commands.""" 69 self._cfm_proxy.wait_for_telemetry_commands() 70 71 72 def wait_for_hangouts_telemetry_commands(self): 73 """Wait for Hangouts App telemetry commands.""" 74 self._cfm_proxy.wait_for_hangouts_telemetry_commands() 75 76 77 def wait_for_meetings_telemetry_commands(self): 78 """Waits for Meet App telemetry commands.""" 79 self._cfm_proxy.wait_for_meetings_telemetry_commands() 80 81 82 def wait_for_meetings_in_call_page(self): 83 """Waits for the in-call page to launch.""" 84 self._cfm_proxy.wait_for_meetings_in_call_page() 85 86 87 def wait_for_meetings_landing_page(self): 88 """Waits for the landing page screen.""" 89 self._cfm_proxy.wait_for_meetings_landing_page() 90 91 92 # UI commands/functions 93 def wait_for_oobe_start_page(self): 94 """Wait for oobe start screen to launch.""" 95 self._cfm_proxy.wait_for_oobe_start_page() 96 97 98 def skip_oobe_screen(self): 99 """Skip Chromebox for Meetings oobe screen.""" 100 self._cfm_proxy.skip_oobe_screen() 101 102 103 def is_oobe_start_page(self): 104 """Check if device is on CFM oobe start screen. 105 106 @return a boolean, based on oobe start page status. 107 """ 108 return self._cfm_proxy.is_oobe_start_page() 109 110 111 # Hangouts commands/functions 112 def start_new_hangout_session(self, session_name): 113 """Start a new hangout session. 114 115 @param session_name: Name of the hangout session. 116 """ 117 self._cfm_proxy.start_new_hangout_session(session_name) 118 119 120 def end_hangout_session(self): 121 """End current hangout session.""" 122 self._cfm_proxy.end_hangout_session() 123 124 125 def take_screenshot(self): 126 """ 127 Takes a screenshot on the DUT. 128 129 @return The file path to the screenshot on the DUT or None. 130 """ 131 # No suffix since cfm_proxy.take_screenshot() automactially appends one. 132 with tempfile.NamedTemporaryFile() as f: 133 basename = os.path.basename(f.name) 134 return self._cfm_proxy.take_screenshot(basename) 135 136 def get_latest_callgrok_file_path(self): 137 """ 138 @return The path to the lastest callgrok log file, if any. 139 """ 140 return self._cfm_proxy.get_latest_callgrok_file_path() 141 142 143 def get_latest_pa_logs_file_path(self): 144 """ 145 @return The path to the lastest packaged app log file, if any. 146 """ 147 return self._cfm_proxy.get_latest_pa_logs_file_path() 148 149 150 def is_in_hangout_session(self): 151 """Check if device is in hangout session. 152 153 @return a boolean, for hangout session state. 154 """ 155 return self._cfm_proxy.is_in_hangout_session() 156 157 158 def is_ready_to_start_hangout_session(self): 159 """Check if device is ready to start a new hangout session. 160 161 @return a boolean for hangout session ready state. 162 """ 163 return self._cfm_proxy.is_ready_to_start_hangout_session() 164 165 166 def join_meeting_session(self, session_name): 167 """Join a meeting. 168 169 @param session_name: Name of the meeting session. 170 """ 171 self._cfm_proxy.join_meeting_session(session_name) 172 173 174 def start_meeting_session(self): 175 """Start a meeting.""" 176 self._cfm_proxy.start_meeting_session() 177 178 179 def end_meeting_session(self): 180 """End current meeting session.""" 181 self._cfm_proxy.end_meeting_session() 182 183 184 def get_participant_count(self): 185 """Gets the total participant count in a call.""" 186 return self._cfm_proxy.get_participant_count() 187 188 189 # Diagnostics commands/functions 190 def is_diagnostic_run_in_progress(self): 191 """Check if hotrod diagnostics is running. 192 193 @return a boolean for diagnostic run state. 194 """ 195 return self._cfm_proxy.is_diagnostic_run_in_progress() 196 197 198 def wait_for_diagnostic_run_to_complete(self): 199 """Wait for hotrod diagnostics to complete.""" 200 self._cfm_proxy.wait_for_diagnostic_run_to_complete() 201 202 203 def run_diagnostics(self): 204 """Run hotrod diagnostics.""" 205 self._cfm_proxy.run_diagnostics() 206 207 208 def get_last_diagnostics_results(self): 209 """Get latest hotrod diagnostics results. 210 211 @return a dict with diagnostic test results. 212 """ 213 return self._cfm_proxy.get_last_diagnostics_results() 214 215 216 # Mic audio commands/functions 217 def is_mic_muted(self): 218 """Check if mic is muted. 219 220 @return a boolean for mic mute state. 221 """ 222 return self._cfm_proxy.is_mic_muted() 223 224 225 def mute_mic(self): 226 """Local mic mute from toolbar.""" 227 self._cfm_proxy.mute_mic() 228 229 230 def unmute_mic(self): 231 """Local mic unmute from toolbar.""" 232 self._cfm_proxy.unmute_mic() 233 234 235 def remote_mute_mic(self): 236 """Remote mic mute request from cPanel.""" 237 self._cfm_proxy.remote_mute_mic() 238 239 240 def remote_unmute_mic(self): 241 """Remote mic unmute request from cPanel.""" 242 self._cfm_proxy.remote_unmute_mic() 243 244 245 def get_mic_devices(self): 246 """Get all mic devices detected by hotrod.""" 247 return self._cfm_proxy.get_mic_devices() 248 249 250 def get_preferred_mic(self): 251 """Get mic preferred for hotrod. 252 253 @return a str with preferred mic name. 254 """ 255 return self._cfm_proxy.get_preferred_mic() 256 257 258 def set_preferred_mic(self, mic): 259 """Set preferred mic for hotrod. 260 261 @param mic: String with mic name. 262 """ 263 self._cfm_proxy.set_preferred_mic(mic) 264 265 266 # Speaker commands/functions 267 def get_speaker_devices(self): 268 """Get all speaker devices detected by hotrod. 269 270 @return a list of speaker devices. 271 """ 272 return self._cfm_proxy.get_speaker_devices() 273 274 275 def get_preferred_speaker(self): 276 """Get speaker preferred for hotrod. 277 278 @return a str with preferred speaker name. 279 """ 280 return self._cfm_proxy.get_preferred_speaker() 281 282 283 def set_preferred_speaker(self, speaker): 284 """Set preferred speaker for hotrod. 285 286 @param speaker: String with speaker name. 287 """ 288 self._cfm_proxy.set_preferred_speaker(speaker) 289 290 291 def set_speaker_volume(self, volume_level): 292 """Set speaker volume. 293 294 @param volume_level: String value ranging from 0-100 to set volume to. 295 """ 296 self._cfm_proxy.set_speaker_volume(volume_level) 297 298 299 def get_speaker_volume(self): 300 """Get current speaker volume. 301 302 @return a str value with speaker volume level 0-100. 303 """ 304 return self._cfm_proxy.get_speaker_volume() 305 306 307 def play_test_sound(self): 308 """Play test sound.""" 309 self._cfm_proxy.play_test_sound() 310 311 312 # Camera commands/functions 313 def get_camera_devices(self): 314 """Get all camera devices detected by hotrod. 315 316 @return a list of camera devices. 317 """ 318 return self._cfm_proxy.get_camera_devices() 319 320 321 def get_preferred_camera(self): 322 """Get camera preferred for hotrod. 323 324 @return a str with preferred camera name. 325 """ 326 return self._cfm_proxy.get_preferred_camera() 327 328 329 def set_preferred_camera(self, camera): 330 """Set preferred camera for hotrod. 331 332 @param camera: String with camera name. 333 """ 334 self._cfm_proxy.set_preferred_camera(camera) 335 336 337 def is_camera_muted(self): 338 """Check if camera is muted (turned off). 339 340 @return a boolean for camera muted state. 341 """ 342 return self._cfm_proxy.is_camera_muted() 343 344 345 def mute_camera(self): 346 """Turned camera off.""" 347 self._cfm_proxy.mute_camera() 348 349 350 def unmute_camera(self): 351 """Turned camera on.""" 352 self._cfm_proxy.unmute_camera() 353 354 355 def move_camera(self, camera_motion): 356 """ 357 Move camera(PTZ commands). 358 359 @param camera_motion: Set of allowed commands 360 defined in cfmApi.move_camera. 361 """ 362 self._cfm_proxy.move_camera(camera_motion) 363 364 def get_media_info_data_points(self): 365 """ 366 Gets media info data points containing media stats. 367 368 These are exported on the window object when the 369 ExportMediaInfo mod is enabled. 370 371 @returns A list with dictionaries of media info data points. 372 @raises RuntimeError if the data point API is not available. 373 """ 374 return self._cfm_proxy.get_media_info_data_points() 375 376