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