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