• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3.4
2#
3#   Copyright 2016 - Google
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16"""
17    Test Script for VT live call test
18"""
19
20import time
21from queue import Empty
22from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
23from acts.test_utils.tel.tel_defines import AUDIO_ROUTE_EARPIECE
24from acts.test_utils.tel.tel_defines import AUDIO_ROUTE_SPEAKER
25from acts.test_utils.tel.tel_defines import CALL_STATE_ACTIVE
26from acts.test_utils.tel.tel_defines import CALL_STATE_HOLDING
27from acts.test_utils.tel.tel_defines import CALL_CAPABILITY_MANAGE_CONFERENCE
28from acts.test_utils.tel.tel_defines import CALL_CAPABILITY_MERGE_CONFERENCE
29from acts.test_utils.tel.tel_defines import CALL_CAPABILITY_SWAP_CONFERENCE
30from acts.test_utils.tel.tel_defines import CALL_PROPERTY_CONFERENCE
31from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_VIDEO_SESSION_EVENT
32from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_VOLTE_ENABLED
33from acts.test_utils.tel.tel_defines import VT_STATE_AUDIO_ONLY
34from acts.test_utils.tel.tel_defines import VT_STATE_BIDIRECTIONAL
35from acts.test_utils.tel.tel_defines import VT_STATE_BIDIRECTIONAL_PAUSED
36from acts.test_utils.tel.tel_defines import VT_VIDEO_QUALITY_DEFAULT
37from acts.test_utils.tel.tel_defines import VT_STATE_RX_ENABLED
38from acts.test_utils.tel.tel_defines import VT_STATE_TX_ENABLED
39from acts.test_utils.tel.tel_defines import WAIT_TIME_ANDROID_STATE_SETTLING
40from acts.test_utils.tel.tel_defines import WAIT_TIME_IN_CALL
41from acts.test_utils.tel.tel_defines import EVENT_VIDEO_SESSION_EVENT
42from acts.test_utils.tel.tel_defines import EventTelecomVideoCallSessionEvent
43from acts.test_utils.tel.tel_defines import SESSION_EVENT_RX_PAUSE
44from acts.test_utils.tel.tel_defines import SESSION_EVENT_RX_RESUME
45from acts.test_utils.tel.tel_test_utils import call_setup_teardown
46from acts.test_utils.tel.tel_test_utils import disconnect_call_by_id
47from acts.test_utils.tel.tel_test_utils import hangup_call
48from acts.test_utils.tel.tel_test_utils import multithread_func
49from acts.test_utils.tel.tel_test_utils import num_active_calls
50from acts.test_utils.tel.tel_test_utils import verify_http_connection
51from acts.test_utils.tel.tel_test_utils import verify_incall_state
52from acts.test_utils.tel.tel_test_utils import wait_for_video_enabled
53from acts.test_utils.tel.tel_video_utils import get_call_id_in_video_state
54from acts.test_utils.tel.tel_video_utils import \
55    is_phone_in_call_video_bidirectional
56from acts.test_utils.tel.tel_video_utils import is_phone_in_call_voice_hd
57from acts.test_utils.tel.tel_video_utils import phone_setup_video
58from acts.test_utils.tel.tel_video_utils import \
59    verify_video_call_in_expected_state
60from acts.test_utils.tel.tel_video_utils import video_call_downgrade
61from acts.test_utils.tel.tel_video_utils import video_call_modify_video
62from acts.test_utils.tel.tel_video_utils import video_call_setup_teardown
63from acts.test_utils.tel.tel_voice_utils import get_audio_route
64from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
65from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
66from acts.test_utils.tel.tel_voice_utils import set_audio_route
67from acts.test_utils.tel.tel_voice_utils import get_cep_conference_call_id
68
69
70class TelLiveVideoTest(TelephonyBaseTest):
71    def __init__(self, controllers):
72        TelephonyBaseTest.__init__(self, controllers)
73        self.tests = (
74            "test_call_video_to_video",
75            "test_call_video_accept_as_voice",
76            "test_call_video_to_video_mo_disable_camera",
77            "test_call_video_to_video_mt_disable_camera",
78            "test_call_video_to_video_mo_mt_disable_camera",
79            "test_call_video_to_video_mt_mo_disable_camera",
80            "test_call_volte_to_volte_mo_upgrade_bidirectional",
81            "test_call_video_accept_as_voice_mo_upgrade_bidirectional",
82            "test_call_volte_to_volte_mo_upgrade_reject",
83            "test_call_video_accept_as_voice_mo_upgrade_reject",
84            "test_call_video_to_video_mo_to_backgroundpause_foregroundresume",
85            "test_call_video_to_video_mt_to_backgroundpause_foregroundresume",
86
87            # Video Call + Voice Call
88            "test_call_video_add_mo_voice",
89            "test_call_video_add_mt_voice",
90            "test_call_volte_add_mo_video",
91            "test_call_volte_add_mt_video",
92            "test_call_video_add_mt_voice_swap_once_local_drop",
93            "test_call_video_add_mt_voice_swap_twice_remote_drop_voice_unhold_video",
94
95            # Video + Video
96            "test_call_video_add_mo_video",
97            "test_call_video_add_mt_video",
98            "test_call_mt_video_add_mt_video",
99            "test_call_mt_video_add_mo_video",
100
101            # VT conference
102            "test_call_volte_add_mo_video_accept_as_voice_merge_drop",
103            "test_call_volte_add_mt_video_accept_as_voice_merge_drop",
104            "test_call_video_add_mo_voice_swap_downgrade_merge_drop",
105            "test_call_video_add_mt_voice_swap_downgrade_merge_drop",
106            "test_call_volte_add_mo_video_downgrade_merge_drop",
107            "test_call_volte_add_mt_video_downgrade_merge_drop",
108
109            # VT conference - Conference Event Package
110            "test_call_volte_add_mo_video_accept_as_voice_merge_drop_cep",
111            "test_call_volte_add_mt_video_accept_as_voice_merge_drop_cep",
112            "test_call_video_add_mo_voice_swap_downgrade_merge_drop_cep",
113            "test_call_video_add_mt_voice_swap_downgrade_merge_drop_cep",
114            "test_call_volte_add_mo_video_downgrade_merge_drop_cep",
115            "test_call_volte_add_mt_video_downgrade_merge_drop_cep",
116
117            # Disable Data, VT not available
118            "test_disable_data_vt_unavailable", )
119
120        self.stress_test_number = int(self.user_params["stress_test_number"])
121        self.wifi_network_ssid = self.user_params["wifi_network_ssid"]
122
123        try:
124            self.wifi_network_pass = self.user_params["wifi_network_pass"]
125        except KeyError:
126            self.wifi_network_pass = None
127
128    """ Tests Begin """
129
130    @TelephonyBaseTest.tel_test_wrap
131    def test_call_video_to_video(self):
132        """ Test VT<->VT call functionality.
133
134        Make Sure PhoneA is in LTE mode (with Video Calling).
135        Make Sure PhoneB is in LTE mode (with Video Calling).
136        Call from PhoneA to PhoneB as Bi-Directional Video,
137        Accept on PhoneB as video call, hang up on PhoneA.
138
139        Returns:
140            True if pass; False if fail.
141        """
142        ads = self.android_devices
143        tasks = [(phone_setup_video, (self.log, ads[0])), (phone_setup_video,
144                                                           (self.log, ads[1]))]
145        if not multithread_func(self.log, tasks):
146            self.log.error("Phone Failed to Set Up Properly.")
147            return False
148
149        if not video_call_setup_teardown(
150                self.log,
151                ads[0],
152                ads[1],
153                ads[0],
154                video_state=VT_STATE_BIDIRECTIONAL,
155                verify_caller_func=is_phone_in_call_video_bidirectional,
156                verify_callee_func=is_phone_in_call_video_bidirectional):
157            self.log.error("Failed to setup+teardown a call")
158            return False
159
160        return True
161
162    @TelephonyBaseTest.tel_test_wrap
163    def test_call_video_accept_as_voice(self):
164        """ Test VT<->VT call functionality.
165
166        Make Sure PhoneA is in LTE mode (with Video Calling).
167        Make Sure PhoneB is in LTE mode (with Video Calling).
168        Call from PhoneA to PhoneB as Bi-Directional Video,
169        Accept on PhoneB as audio only, hang up on PhoneA.
170
171        Returns:
172            True if pass; False if fail.
173        """
174        ads = self.android_devices
175        tasks = [(phone_setup_video, (self.log, ads[0])), (phone_setup_video,
176                                                           (self.log, ads[1]))]
177        if not multithread_func(self.log, tasks):
178            self.log.error("Phone Failed to Set Up Properly.")
179            return False
180
181        if not video_call_setup_teardown(
182                self.log,
183                ads[0],
184                ads[1],
185                ads[0],
186                video_state=VT_STATE_AUDIO_ONLY,
187                verify_caller_func=is_phone_in_call_voice_hd,
188                verify_callee_func=is_phone_in_call_voice_hd):
189            self.log.error("Failed to setup+teardown a call")
190            return False
191        return True
192
193    @TelephonyBaseTest.tel_test_wrap
194    def test_call_video_to_video_mo_disable_camera(self):
195        """ Test VT<->VT call functionality.
196
197        Make Sure PhoneA is in LTE mode (with Video Calling).
198        Make Sure PhoneB is in LTE mode (with Video Calling).
199        Call from PhoneA to PhoneB as Bi-Directional Video,
200        Accept on PhoneB as video call.
201        On PhoneA disabled video transmission.
202        Verify PhoneA as RX_ENABLED and PhoneB as TX_ENABLED.
203        Hangup on PhoneA.
204
205        Returns:
206            True if pass; False if fail.
207        """
208        ads = self.android_devices
209        tasks = [(phone_setup_video, (self.log, ads[0])), (phone_setup_video,
210                                                           (self.log, ads[1]))]
211        if not multithread_func(self.log, tasks):
212            self.log.error("Phone Failed to Set Up Properly.")
213            return False
214
215        if not video_call_setup_teardown(
216                self.log,
217                ads[0],
218                ads[1],
219                None,
220                video_state=VT_STATE_BIDIRECTIONAL,
221                verify_caller_func=is_phone_in_call_video_bidirectional,
222                verify_callee_func=is_phone_in_call_video_bidirectional):
223            self.log.error("Failed to setup a call")
224            return False
225
226        self.log.info("Disable video on PhoneA:{}".format(ads[0].serial))
227        if not video_call_downgrade(
228                self.log, ads[0], get_call_id_in_video_state(
229                    self.log, ads[0], VT_STATE_BIDIRECTIONAL), ads[1],
230                get_call_id_in_video_state(self.log, ads[1],
231                                           VT_STATE_BIDIRECTIONAL)):
232            self.log.error("Failed to disable video on PhoneA.")
233            return False
234        return hangup_call(self.log, ads[0])
235
236    @TelephonyBaseTest.tel_test_wrap
237    def test_call_video_to_video_mt_disable_camera(self):
238        """ Test VT<->VT call functionality.
239
240        Make Sure PhoneA is in LTE mode (with Video Calling).
241        Make Sure PhoneB is in LTE mode (with Video Calling).
242        Call from PhoneA to PhoneB as Bi-Directional Video,
243        Accept on PhoneB as video call.
244        On PhoneB disabled video transmission.
245        Verify PhoneB as RX_ENABLED and PhoneA as TX_ENABLED.
246        Hangup on PhoneA.
247
248        Returns:
249            True if pass; False if fail.
250        """
251        ads = self.android_devices
252        tasks = [(phone_setup_video, (self.log, ads[0])), (phone_setup_video,
253                                                           (self.log, ads[1]))]
254        if not multithread_func(self.log, tasks):
255            self.log.error("Phone Failed to Set Up Properly.")
256            return False
257
258        if not video_call_setup_teardown(
259                self.log,
260                ads[0],
261                ads[1],
262                None,
263                video_state=VT_STATE_BIDIRECTIONAL,
264                verify_caller_func=is_phone_in_call_video_bidirectional,
265                verify_callee_func=is_phone_in_call_video_bidirectional):
266            self.log.error("Failed to setup a call")
267            return False
268
269        self.log.info("Disable video on PhoneB:{}".format(ads[1].serial))
270        if not video_call_downgrade(
271                self.log, ads[1], get_call_id_in_video_state(
272                    self.log, ads[1], VT_STATE_BIDIRECTIONAL), ads[0],
273                get_call_id_in_video_state(self.log, ads[0],
274                                           VT_STATE_BIDIRECTIONAL)):
275            self.log.error("Failed to disable video on PhoneB.")
276            return False
277        return hangup_call(self.log, ads[0])
278
279    @TelephonyBaseTest.tel_test_wrap
280    def test_call_video_to_video_mo_mt_disable_camera(self):
281        """ Test VT<->VT call functionality.
282
283        Make Sure PhoneA is in LTE mode (with Video Calling).
284        Make Sure PhoneB is in LTE mode (with Video Calling).
285        Call from PhoneA to PhoneB as Bi-Directional Video,
286        Accept on PhoneB as video call.
287        On PhoneA disabled video transmission.
288        Verify PhoneA as RX_ENABLED and PhoneB as TX_ENABLED.
289        On PhoneB disabled video transmission.
290        Verify PhoneA as AUDIO_ONLY and PhoneB as AUDIO_ONLY.
291        Hangup on PhoneA.
292
293        Returns:
294            True if pass; False if fail.
295        """
296        ads = self.android_devices
297        tasks = [(phone_setup_video, (self.log, ads[0])), (phone_setup_video,
298                                                           (self.log, ads[1]))]
299        if not multithread_func(self.log, tasks):
300            self.log.error("Phone Failed to Set Up Properly.")
301            return False
302
303        if not video_call_setup_teardown(
304                self.log,
305                ads[0],
306                ads[1],
307                None,
308                video_state=VT_STATE_BIDIRECTIONAL,
309                verify_caller_func=is_phone_in_call_video_bidirectional,
310                verify_callee_func=is_phone_in_call_video_bidirectional):
311            self.log.error("Failed to setup a call")
312            return False
313
314        self.log.info("Disable video on PhoneA:{}".format(ads[0].serial))
315        if not video_call_downgrade(
316                self.log, ads[0], get_call_id_in_video_state(
317                    self.log, ads[0], VT_STATE_BIDIRECTIONAL), ads[1],
318                get_call_id_in_video_state(self.log, ads[1],
319                                           VT_STATE_BIDIRECTIONAL)):
320            self.log.error("Failed to disable video on PhoneA.")
321            return False
322
323        self.log.info("Disable video on PhoneB:{}".format(ads[1].serial))
324        if not video_call_downgrade(
325                self.log, ads[1], get_call_id_in_video_state(
326                    self.log, ads[1], VT_STATE_TX_ENABLED), ads[0],
327                get_call_id_in_video_state(self.log, ads[0],
328                                           VT_STATE_RX_ENABLED)):
329            self.log.error("Failed to disable video on PhoneB.")
330            return False
331        return hangup_call(self.log, ads[0])
332
333    @TelephonyBaseTest.tel_test_wrap
334    def test_call_video_to_video_mt_mo_disable_camera(self):
335        """ Test VT<->VT call functionality.
336
337        Make Sure PhoneA is in LTE mode (with Video Calling).
338        Make Sure PhoneB is in LTE mode (with Video Calling).
339        Call from PhoneA to PhoneB as Bi-Directional Video,
340        Accept on PhoneB as video call.
341        On PhoneB disabled video transmission.
342        Verify PhoneB as RX_ENABLED and PhoneA as TX_ENABLED.
343        On PhoneA disabled video transmission.
344        Verify PhoneA as AUDIO_ONLY and PhoneB as AUDIO_ONLY.
345        Hangup on PhoneA.
346
347        Returns:
348            True if pass; False if fail.
349        """
350        ads = self.android_devices
351        tasks = [(phone_setup_video, (self.log, ads[0])), (phone_setup_video,
352                                                           (self.log, ads[1]))]
353        if not multithread_func(self.log, tasks):
354            self.log.error("Phone Failed to Set Up Properly.")
355            return False
356
357        if not video_call_setup_teardown(
358                self.log,
359                ads[0],
360                ads[1],
361                None,
362                video_state=VT_STATE_BIDIRECTIONAL,
363                verify_caller_func=is_phone_in_call_video_bidirectional,
364                verify_callee_func=is_phone_in_call_video_bidirectional):
365            self.log.error("Failed to setup a call")
366            return False
367
368        self.log.info("Disable video on PhoneB:{}".format(ads[1].serial))
369        if not video_call_downgrade(
370                self.log, ads[1], get_call_id_in_video_state(
371                    self.log, ads[1], VT_STATE_BIDIRECTIONAL), ads[0],
372                get_call_id_in_video_state(self.log, ads[0],
373                                           VT_STATE_BIDIRECTIONAL)):
374            self.log.error("Failed to disable video on PhoneB.")
375            return False
376
377        self.log.info("Disable video on PhoneA:{}".format(ads[0].serial))
378        if not video_call_downgrade(
379                self.log, ads[0], get_call_id_in_video_state(
380                    self.log, ads[0], VT_STATE_TX_ENABLED), ads[1],
381                get_call_id_in_video_state(self.log, ads[1],
382                                           VT_STATE_RX_ENABLED)):
383            self.log.error("Failed to disable video on PhoneB.")
384            return False
385        return hangup_call(self.log, ads[0])
386
387    def _mo_upgrade_bidirectional(self, ads):
388        """Send + accept an upgrade request from Phone A to B.
389
390        Returns:
391            True if pass; False if fail.
392        """
393        call_id_requester = get_call_id_in_video_state(self.log, ads[0],
394                                                       VT_STATE_AUDIO_ONLY)
395
396        call_id_responder = get_call_id_in_video_state(self.log, ads[1],
397                                                       VT_STATE_AUDIO_ONLY)
398
399        if not call_id_requester or not call_id_responder:
400            self.log.error("Couldn't find a candidate call id {}:{}, {}:{}"
401                           .format(ads[0].serial, call_id_requester, ads[
402                               1].serial, call_id_responder))
403            return False
404
405        if not video_call_modify_video(self.log, ads[0], call_id_requester,
406                                       ads[1], call_id_responder,
407                                       VT_STATE_BIDIRECTIONAL):
408            self.log.error("Failed to upgrade video call!")
409            return False
410
411        #Wait for a completed upgrade and ensure the call is stable
412        time.sleep(WAIT_TIME_IN_CALL)
413
414        if not verify_incall_state(self.log, [ads[0], ads[1]], True):
415            self.log.error("_mo_upgrade_bidirectional: Call Drop!")
416            return False
417
418        if (get_call_id_in_video_state(self.log, ads[0],
419                                       VT_STATE_BIDIRECTIONAL) !=
420                call_id_requester):
421            self.log.error("Caller not in correct state: {}".format(
422                VT_STATE_BIDIRECTIONAL))
423            return False
424
425        if (get_call_id_in_video_state(self.log, ads[1],
426                                       VT_STATE_BIDIRECTIONAL) !=
427                call_id_responder):
428            self.log.error("Callee not in correct state: {}".format(
429                VT_STATE_BIDIRECTIONAL))
430            return False
431
432        return hangup_call(self.log, ads[0])
433
434    @TelephonyBaseTest.tel_test_wrap
435    def test_call_video_accept_as_voice_mo_upgrade_bidirectional(self):
436        """ Test Upgrading from VoLTE to Bi-Directional VT.
437
438        Make Sure PhoneA is in LTE mode (with Video Calling).
439        Make Sure PhoneB is in LTE mode (with Video Calling).
440        Call from PhoneA to PhoneB as Video, accept on PhoneB as audio only.
441        Send + accept an upgrade request from Phone A to B.
442
443        Returns:
444            True if pass; False if fail.
445        """
446
447        ads = self.android_devices
448        tasks = [(phone_setup_video, (self.log, ads[0])), (phone_setup_video,
449                                                           (self.log, ads[1]))]
450        if not multithread_func(self.log, tasks):
451            self.log.error("Phone Failed to Set Up Properly.")
452            return False
453        if not video_call_setup_teardown(
454                self.log,
455                ads[0],
456                ads[1],
457                None,
458                video_state=VT_STATE_AUDIO_ONLY,
459                verify_caller_func=is_phone_in_call_volte,
460                verify_callee_func=is_phone_in_call_volte):
461            self.log.error("Failed to setup a call")
462            return False
463
464        return self._mo_upgrade_bidirectional(ads)
465
466    @TelephonyBaseTest.tel_test_wrap
467    def test_call_volte_to_volte_mo_upgrade_bidirectional(self):
468        """ Test Upgrading from VoLTE to Bi-Directional VT.
469
470        Make Sure PhoneA is in LTE mode (with Video Calling).
471        Make Sure PhoneB is in LTE mode (with Video Calling).
472        Call from PhoneA to PhoneB as VoLTE, accept on PhoneB.
473        Send + accept an upgrade request from Phone A to B.
474
475        Returns:
476            True if pass; False if fail.
477        """
478
479        ads = self.android_devices
480        tasks = [(phone_setup_video, (self.log, ads[0])), (phone_setup_video,
481                                                           (self.log, ads[1]))]
482        if not multithread_func(self.log, tasks):
483            self.log.error("Phone Failed to Set Up Properly.")
484            return False
485        if not call_setup_teardown(self.log, ads[0], ads[1], None,
486                                   is_phone_in_call_volte,
487                                   is_phone_in_call_volte):
488            self.log.error("Failed to setup a call")
489            return False
490
491        return self._mo_upgrade_bidirectional(ads)
492
493    def _mo_upgrade_reject(self, ads):
494        """Send + reject an upgrade request from Phone A to B.
495
496        Returns:
497            True if pass; False if fail.
498        """
499        call_id_requester = get_call_id_in_video_state(self.log, ads[0],
500                                                       VT_STATE_AUDIO_ONLY)
501
502        call_id_responder = get_call_id_in_video_state(self.log, ads[1],
503                                                       VT_STATE_AUDIO_ONLY)
504
505        if not call_id_requester or not call_id_responder:
506            self.log.error("Couldn't find a candidate call id {}:{}, {}:{}"
507                           .format(ads[0].serial, call_id_requester, ads[
508                               1].serial, call_id_responder))
509            return False
510
511        if not video_call_modify_video(
512                self.log, ads[0], call_id_requester, ads[1], call_id_responder,
513                VT_STATE_BIDIRECTIONAL, VT_VIDEO_QUALITY_DEFAULT,
514                VT_STATE_AUDIO_ONLY, VT_VIDEO_QUALITY_DEFAULT):
515            self.log.error("Failed to upgrade video call!")
516            return False
517
518        time.sleep(WAIT_TIME_IN_CALL)
519
520        if not is_phone_in_call_voice_hd(self.log, ads[0]):
521            self.log.error("PhoneA not in correct state.")
522            return False
523        if not is_phone_in_call_voice_hd(self.log, ads[1]):
524            self.log.error("PhoneB not in correct state.")
525            return False
526
527        return hangup_call(self.log, ads[0])
528
529    @TelephonyBaseTest.tel_test_wrap
530    def test_call_volte_to_volte_mo_upgrade_reject(self):
531        """ Test Upgrading from VoLTE to Bi-Directional VT and reject.
532
533        Make Sure PhoneA is in LTE mode (with Video Calling).
534        Make Sure PhoneB is in LTE mode (with Video Calling).
535        Call from PhoneA to PhoneB as VoLTE, accept on PhoneB.
536        Send an upgrade request from Phone A to PhoneB.
537        Reject on PhoneB. Verify PhoneA and PhoneB ad AUDIO_ONLY.
538        Verify call continues.
539        Hangup on PhoneA.
540
541        Returns:
542            True if pass; False if fail.
543        """
544        ads = self.android_devices
545        tasks = [(phone_setup_video, (self.log, ads[0])), (phone_setup_video,
546                                                           (self.log, ads[1]))]
547        if not multithread_func(self.log, tasks):
548            self.log.error("Phone Failed to Set Up Properly.")
549            return False
550        if not call_setup_teardown(self.log, ads[0], ads[1], None,
551                                   is_phone_in_call_volte,
552                                   is_phone_in_call_volte):
553            self.log.error("Failed to setup a call")
554            return False
555
556        return self._mo_upgrade_reject(ads)
557
558    @TelephonyBaseTest.tel_test_wrap
559    def test_call_video_accept_as_voice_mo_upgrade_reject(self):
560        """ Test Upgrading from VoLTE to Bi-Directional VT and reject.
561
562        Make Sure PhoneA is in LTE mode (with Video Calling).
563        Make Sure PhoneB is in LTE mode (with Video Calling).
564        Call from PhoneA to PhoneB as Video, accept on PhoneB as audio only.
565        Send an upgrade request from Phone A to PhoneB.
566        Reject on PhoneB. Verify PhoneA and PhoneB ad AUDIO_ONLY.
567        Verify call continues.
568        Hangup on PhoneA.
569
570        Returns:
571            True if pass; False if fail.
572        """
573        ads = self.android_devices
574        tasks = [(phone_setup_video, (self.log, ads[0])), (phone_setup_video,
575                                                           (self.log, ads[1]))]
576        if not multithread_func(self.log, tasks):
577            self.log.error("Phone Failed to Set Up Properly.")
578            return False
579        if not video_call_setup_teardown(
580                self.log,
581                ads[0],
582                ads[1],
583                None,
584                video_state=VT_STATE_AUDIO_ONLY,
585                verify_caller_func=is_phone_in_call_volte,
586                verify_callee_func=is_phone_in_call_volte):
587            self.log.error("Failed to setup a call")
588            return False
589
590        return self._mo_upgrade_reject(ads)
591
592    def _test_put_call_to_backgroundpause_and_foregroundresume(
593            self, ad_requester, ad_responder):
594        call_id_requester = get_call_id_in_video_state(self.log, ad_requester,
595                                                       VT_STATE_BIDIRECTIONAL)
596        call_id_responder = get_call_id_in_video_state(self.log, ad_responder,
597                                                       VT_STATE_BIDIRECTIONAL)
598        ad_requester.droid.telecomCallVideoStartListeningForEvent(
599            call_id_requester, EVENT_VIDEO_SESSION_EVENT)
600        ad_responder.droid.telecomCallVideoStartListeningForEvent(
601            call_id_responder, EVENT_VIDEO_SESSION_EVENT)
602        self.log.info("Put In-Call UI on {} to background.".format(
603            ad_requester.serial))
604        ad_requester.droid.showHomeScreen()
605        try:
606            event_on_responder = ad_responder.ed.pop_event(
607                EventTelecomVideoCallSessionEvent,
608                MAX_WAIT_TIME_VIDEO_SESSION_EVENT)
609            event_on_requester = ad_requester.ed.pop_event(
610                EventTelecomVideoCallSessionEvent,
611                MAX_WAIT_TIME_VIDEO_SESSION_EVENT)
612            if event_on_responder['data']['Event'] != SESSION_EVENT_RX_PAUSE:
613                self.log.error(
614                    "Event not correct. event_on_responder: {}. Expected :{}".format(
615                        event_on_responder, SESSION_EVENT_RX_PAUSE))
616                return False
617            if event_on_requester['data']['Event'] != SESSION_EVENT_RX_PAUSE:
618                self.log.error(
619                    "Event not correct. event_on_requester: {}. Expected :{}".format(
620                        event_on_requester, SESSION_EVENT_RX_PAUSE))
621                return False
622        except Empty:
623            self.log.error("Expected event not received.")
624            return False
625        finally:
626            ad_requester.droid.telecomCallVideoStopListeningForEvent(
627                call_id_requester, EVENT_VIDEO_SESSION_EVENT)
628            ad_responder.droid.telecomCallVideoStopListeningForEvent(
629                call_id_responder, EVENT_VIDEO_SESSION_EVENT)
630        time.sleep(WAIT_TIME_IN_CALL)
631
632        if not verify_video_call_in_expected_state(
633                self.log, ad_requester, call_id_requester,
634                VT_STATE_BIDIRECTIONAL_PAUSED, CALL_STATE_ACTIVE):
635            return False
636        if not verify_video_call_in_expected_state(
637                self.log, ad_responder, call_id_responder,
638                VT_STATE_BIDIRECTIONAL_PAUSED, CALL_STATE_ACTIVE):
639            return False
640
641        self.log.info("Put In-Call UI on {} to foreground.".format(
642            ad_requester.serial))
643        ad_requester.droid.telecomCallVideoStartListeningForEvent(
644            call_id_requester, EVENT_VIDEO_SESSION_EVENT)
645        ad_responder.droid.telecomCallVideoStartListeningForEvent(
646            call_id_responder, EVENT_VIDEO_SESSION_EVENT)
647        ad_requester.droid.telecomShowInCallScreen()
648        try:
649            event_on_responder = ad_responder.ed.pop_event(
650                EventTelecomVideoCallSessionEvent,
651                MAX_WAIT_TIME_VIDEO_SESSION_EVENT)
652            event_on_requester = ad_requester.ed.pop_event(
653                EventTelecomVideoCallSessionEvent,
654                MAX_WAIT_TIME_VIDEO_SESSION_EVENT)
655            if event_on_responder['data']['Event'] != SESSION_EVENT_RX_RESUME:
656                self.log.error(
657                    "Event not correct. event_on_responder: {}. Expected :{}".format(
658                        event_on_responder, SESSION_EVENT_RX_RESUME))
659                return False
660            if event_on_requester['data']['Event'] != SESSION_EVENT_RX_RESUME:
661                self.log.error(
662                    "Event not correct. event_on_requester: {}. Expected :{}".format(
663                        event_on_requester, SESSION_EVENT_RX_RESUME))
664                return False
665        except Empty:
666            self.log.error("Expected event not received.")
667            return False
668        finally:
669            ad_requester.droid.telecomCallVideoStopListeningForEvent(
670                call_id_requester, EVENT_VIDEO_SESSION_EVENT)
671            ad_responder.droid.telecomCallVideoStopListeningForEvent(
672                call_id_responder, EVENT_VIDEO_SESSION_EVENT)
673        time.sleep(WAIT_TIME_IN_CALL)
674        self.log.info("Verify both calls are in bi-directional/active state.")
675        if not verify_video_call_in_expected_state(
676                self.log, ad_requester, call_id_requester,
677                VT_STATE_BIDIRECTIONAL, CALL_STATE_ACTIVE):
678            return False
679        if not verify_video_call_in_expected_state(
680                self.log, ad_responder, call_id_responder,
681                VT_STATE_BIDIRECTIONAL, CALL_STATE_ACTIVE):
682            return False
683
684        return True
685
686    @TelephonyBaseTest.tel_test_wrap
687    def test_call_video_to_video_mo_to_backgroundpause_foregroundresume(self):
688        ads = self.android_devices
689        tasks = [(phone_setup_video, (self.log, ads[0])), (phone_setup_video,
690                                                           (self.log, ads[1]))]
691        if not multithread_func(self.log, tasks):
692            self.log.error("Phone Failed to Set Up Properly.")
693            return False
694
695        if not video_call_setup_teardown(
696                self.log,
697                ads[0],
698                ads[1],
699                None,
700                video_state=VT_STATE_BIDIRECTIONAL,
701                verify_caller_func=is_phone_in_call_video_bidirectional,
702                verify_callee_func=is_phone_in_call_video_bidirectional):
703            self.log.error("Failed to setup a call")
704            return False
705
706        time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
707
708        return self._test_put_call_to_backgroundpause_and_foregroundresume(
709            ads[0], ads[1])
710
711    @TelephonyBaseTest.tel_test_wrap
712    def test_call_video_to_video_mt_to_backgroundpause_foregroundresume(self):
713        ads = self.android_devices
714        tasks = [(phone_setup_video, (self.log, ads[0])), (phone_setup_video,
715                                                           (self.log, ads[1]))]
716        if not multithread_func(self.log, tasks):
717            self.log.error("Phone Failed to Set Up Properly.")
718            return False
719
720        if not video_call_setup_teardown(
721                self.log,
722                ads[0],
723                ads[1],
724                None,
725                video_state=VT_STATE_BIDIRECTIONAL,
726                verify_caller_func=is_phone_in_call_video_bidirectional,
727                verify_callee_func=is_phone_in_call_video_bidirectional):
728            self.log.error("Failed to setup a call")
729            return False
730
731        time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
732
733        return self._test_put_call_to_backgroundpause_and_foregroundresume(
734            ads[1], ads[0])
735
736    def _vt_test_multi_call_hangup(self, ads):
737        """private function to hangup calls for VT tests.
738
739        Hangup on PhoneB.
740        Verify PhoneA and PhoneC still in call.
741        Hangup on PhoneC.
742        Verify all phones not in call.
743        """
744        if not hangup_call(self.log, ads[1]):
745            return False
746        time.sleep(WAIT_TIME_IN_CALL)
747        if not verify_incall_state(self.log, [ads[0], ads[2]], True):
748            return False
749        if not hangup_call(self.log, ads[2]):
750            return False
751        time.sleep(WAIT_TIME_IN_CALL)
752        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], False):
753            return False
754        return True
755
756    @TelephonyBaseTest.tel_test_wrap
757    def test_call_video_add_mo_voice(self):
758        """
759        From Phone_A, Initiate a Bi-Directional Video Call to Phone_B
760        Accept the call on Phone_B as Bi-Directional Video
761        From Phone_A, add a voice call to Phone_C
762        Accept the call on Phone_C
763        Verify both calls remain active.
764        """
765        # This test case is not supported by VZW.
766        ads = self.android_devices
767        tasks = [(phone_setup_video, (self.log, ads[0])),
768                 (phone_setup_video, (self.log, ads[1])), (phone_setup_volte,
769                                                           (self.log, ads[2]))]
770        if not multithread_func(self.log, tasks):
771            self.log.error("Phone Failed to Set Up Properly.")
772            return False
773
774        self.log.info("Step1: Initiate Video Call PhoneA->PhoneB.")
775        if not video_call_setup_teardown(
776                self.log,
777                ads[0],
778                ads[1],
779                None,
780                video_state=VT_STATE_BIDIRECTIONAL,
781                verify_caller_func=is_phone_in_call_video_bidirectional,
782                verify_callee_func=is_phone_in_call_video_bidirectional):
783            self.log.error("Failed to setup a call")
784            return False
785        call_id_video = get_call_id_in_video_state(self.log, ads[0],
786                                                   VT_STATE_BIDIRECTIONAL)
787        if call_id_video is None:
788            self.log.error("No active video call in PhoneA.")
789            return False
790
791        self.log.info("Step2: Initiate Voice Call PhoneA->PhoneC.")
792        if not call_setup_teardown(self.log,
793                                   ads[0],
794                                   ads[2],
795                                   None,
796                                   verify_caller_func=None,
797                                   verify_callee_func=is_phone_in_call_volte):
798            self.log.error("Failed to setup a call")
799            return False
800
801        self.log.info(
802            "Step3: Verify PhoneA's video/voice call in correct state.")
803        calls = ads[0].droid.telecomCallGetCallIds()
804        self.log.info("Calls in PhoneA{}".format(calls))
805        if num_active_calls(self.log, ads[0]) != 2:
806            self.log.error("Active call numbers in PhoneA is not 2.")
807            return False
808        for call in calls:
809            if call != call_id_video:
810                call_id_voice = call
811
812        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
813            return False
814        if not verify_video_call_in_expected_state(
815                self.log, ads[0], call_id_video, VT_STATE_BIDIRECTIONAL,
816                CALL_STATE_HOLDING):
817            return False
818        if not verify_video_call_in_expected_state(
819                self.log, ads[0], call_id_voice, VT_STATE_AUDIO_ONLY,
820                CALL_STATE_ACTIVE):
821            return False
822
823        return self._vt_test_multi_call_hangup(ads)
824
825    @TelephonyBaseTest.tel_test_wrap
826    def test_call_video_add_mt_voice(self):
827        """
828        From Phone_A, Initiate a Bi-Directional Video Call to Phone_B
829        Accept the call on Phone_B as Bi-Directional Video
830        From Phone_C, add a voice call to Phone_A
831        Accept the call on Phone_A
832        Verify both calls remain active.
833        """
834        ads = self.android_devices
835        tasks = [(phone_setup_video, (self.log, ads[0])),
836                 (phone_setup_video, (self.log, ads[1])), (phone_setup_volte,
837                                                           (self.log, ads[2]))]
838        if not multithread_func(self.log, tasks):
839            self.log.error("Phone Failed to Set Up Properly.")
840            return False
841
842        self.log.info("Step1: Initiate Video Call PhoneA->PhoneB.")
843        if not video_call_setup_teardown(
844                self.log,
845                ads[0],
846                ads[1],
847                None,
848                video_state=VT_STATE_BIDIRECTIONAL,
849                verify_caller_func=is_phone_in_call_video_bidirectional,
850                verify_callee_func=is_phone_in_call_video_bidirectional):
851            self.log.error("Failed to setup a call")
852            return False
853        call_id_video = get_call_id_in_video_state(self.log, ads[0],
854                                                   VT_STATE_BIDIRECTIONAL)
855        if call_id_video is None:
856            self.log.error("No active video call in PhoneA.")
857            return False
858
859        self.log.info("Step2: Initiate Voice Call PhoneC->PhoneA.")
860        if not call_setup_teardown(self.log,
861                                   ads[2],
862                                   ads[0],
863                                   None,
864                                   verify_caller_func=is_phone_in_call_volte,
865                                   verify_callee_func=None):
866            self.log.error("Failed to setup a call")
867            return False
868
869        self.log.info(
870            "Step3: Verify PhoneA's video/voice call in correct state.")
871        calls = ads[0].droid.telecomCallGetCallIds()
872        self.log.info("Calls in PhoneA{}".format(calls))
873        if num_active_calls(self.log, ads[0]) != 2:
874            self.log.error("Active call numbers in PhoneA is not 2.")
875            return False
876        for call in calls:
877            if call != call_id_video:
878                call_id_voice = call
879
880        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
881            return False
882        if not verify_video_call_in_expected_state(
883                self.log, ads[0], call_id_video, VT_STATE_BIDIRECTIONAL_PAUSED,
884                CALL_STATE_HOLDING):
885            return False
886
887        if not verify_video_call_in_expected_state(
888                self.log, ads[0], call_id_voice, VT_STATE_AUDIO_ONLY,
889                CALL_STATE_ACTIVE):
890            return False
891
892        return self._vt_test_multi_call_hangup(ads)
893
894    @TelephonyBaseTest.tel_test_wrap
895    def test_call_volte_add_mo_video(self):
896        """
897        From Phone_A, Initiate a VoLTE Call to Phone_B
898        Accept the call on Phone_B
899        From Phone_A, add a Video call to Phone_C
900        Accept the call on Phone_C as Video
901        Verify both calls remain active.
902        """
903        # This test case is not supported by VZW.
904        ads = self.android_devices
905        tasks = [(phone_setup_video, (self.log, ads[0])),
906                 (phone_setup_volte, (self.log, ads[1])), (phone_setup_video,
907                                                           (self.log, ads[2]))]
908        if not multithread_func(self.log, tasks):
909            self.log.error("Phone Failed to Set Up Properly.")
910            return False
911
912        self.log.info("Step1: Initiate VoLTE Call PhoneA->PhoneB.")
913        if not call_setup_teardown(self.log,
914                                   ads[0],
915                                   ads[1],
916                                   None,
917                                   verify_caller_func=is_phone_in_call_volte,
918                                   verify_callee_func=is_phone_in_call_volte):
919            self.log.error("Failed to setup a call")
920            return False
921        calls = ads[0].droid.telecomCallGetCallIds()
922        self.log.info("Calls in PhoneA{}".format(calls))
923        if num_active_calls(self.log, ads[0]) != 1:
924            self.log.error("Active call numbers in PhoneA is not 1.")
925            return False
926        call_id_voice = calls[0]
927
928        self.log.info("Step2: Initiate Video Call PhoneA->PhoneC.")
929        if not video_call_setup_teardown(
930                self.log,
931                ads[0],
932                ads[2],
933                None,
934                video_state=VT_STATE_BIDIRECTIONAL,
935                verify_caller_func=is_phone_in_call_video_bidirectional,
936                verify_callee_func=is_phone_in_call_video_bidirectional):
937            self.log.error("Failed to setup a call")
938            return False
939        call_id_video = get_call_id_in_video_state(self.log, ads[0],
940                                                   VT_STATE_BIDIRECTIONAL)
941        if call_id_video is None:
942            self.log.error("No active video call in PhoneA.")
943            return False
944
945        self.log.info(
946            "Step3: Verify PhoneA's video/voice call in correct state.")
947        calls = ads[0].droid.telecomCallGetCallIds()
948        self.log.info("Calls in PhoneA{}".format(calls))
949        if num_active_calls(self.log, ads[0]) != 2:
950            self.log.error("Active call numbers in PhoneA is not 2.")
951            return False
952
953        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
954            return False
955        if not verify_video_call_in_expected_state(
956                self.log, ads[0], call_id_video, VT_STATE_BIDIRECTIONAL,
957                CALL_STATE_ACTIVE):
958            return False
959        if not verify_video_call_in_expected_state(
960                self.log, ads[0], call_id_voice, VT_STATE_AUDIO_ONLY,
961                CALL_STATE_HOLDING):
962            return False
963
964        return self._vt_test_multi_call_hangup(ads)
965
966    @TelephonyBaseTest.tel_test_wrap
967    def test_call_volte_add_mt_video(self):
968        """
969        From Phone_A, Initiate a VoLTE Call to Phone_B
970        Accept the call on Phone_B
971        From Phone_C, add a Video call to Phone_A
972        Accept the call on Phone_A as Video
973        Verify both calls remain active.
974        """
975        # TODO (b/21437650):
976        # Test will fail. After established 2nd call ~15s, Phone C will drop call.
977        ads = self.android_devices
978        tasks = [(phone_setup_video, (self.log, ads[0])),
979                 (phone_setup_volte, (self.log, ads[1])), (phone_setup_video,
980                                                           (self.log, ads[2]))]
981        if not multithread_func(self.log, tasks):
982            self.log.error("Phone Failed to Set Up Properly.")
983            return False
984
985        self.log.info("Step1: Initiate VoLTE Call PhoneA->PhoneB.")
986        if not call_setup_teardown(self.log,
987                                   ads[0],
988                                   ads[1],
989                                   None,
990                                   verify_caller_func=is_phone_in_call_volte,
991                                   verify_callee_func=is_phone_in_call_volte):
992            self.log.error("Failed to setup a call")
993            return False
994        calls = ads[0].droid.telecomCallGetCallIds()
995        self.log.info("Calls in PhoneA{}".format(calls))
996        if num_active_calls(self.log, ads[0]) != 1:
997            self.log.error("Active call numbers in PhoneA is not 1.")
998            return False
999        call_id_voice = calls[0]
1000
1001        self.log.info("Step2: Initiate Video Call PhoneC->PhoneA.")
1002        if not video_call_setup_teardown(
1003                self.log,
1004                ads[2],
1005                ads[0],
1006                None,
1007                video_state=VT_STATE_BIDIRECTIONAL,
1008                verify_caller_func=is_phone_in_call_video_bidirectional,
1009                verify_callee_func=is_phone_in_call_video_bidirectional):
1010            self.log.error("Failed to setup a call")
1011            return False
1012
1013        call_id_video = get_call_id_in_video_state(self.log, ads[0],
1014                                                   VT_STATE_BIDIRECTIONAL)
1015        if call_id_video is None:
1016            self.log.error("No active video call in PhoneA.")
1017            return False
1018
1019        self.log.info(
1020            "Step3: Verify PhoneA's video/voice call in correct state.")
1021        calls = ads[0].droid.telecomCallGetCallIds()
1022        self.log.info("Calls in PhoneA{}".format(calls))
1023        if num_active_calls(self.log, ads[0]) != 2:
1024            self.log.error("Active call numbers in PhoneA is not 2.")
1025            return False
1026
1027        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
1028            return False
1029        if not verify_video_call_in_expected_state(
1030                self.log, ads[0], call_id_video, VT_STATE_BIDIRECTIONAL,
1031                CALL_STATE_ACTIVE):
1032            return False
1033        if not verify_video_call_in_expected_state(
1034                self.log, ads[0], call_id_voice, VT_STATE_AUDIO_ONLY,
1035                CALL_STATE_HOLDING):
1036            return False
1037
1038        return self._vt_test_multi_call_hangup(ads)
1039
1040    @TelephonyBaseTest.tel_test_wrap
1041    def test_call_video_add_mt_voice_swap_once_local_drop(self):
1042        """
1043        From Phone_A, Initiate a Bi-Directional Video Call to Phone_B
1044        Accept the call on Phone_B as Bi-Directional Video
1045        From Phone_C, add a voice call to Phone_A
1046        Accept the call on Phone_A
1047        Verify both calls remain active.
1048        Swap calls on PhoneA.
1049        End Video call on PhoneA.
1050        End Voice call on PhoneA.
1051        """
1052        ads = self.android_devices
1053        tasks = [(phone_setup_video, (self.log, ads[0])),
1054                 (phone_setup_video, (self.log, ads[1])), (phone_setup_volte,
1055                                                           (self.log, ads[2]))]
1056        if not multithread_func(self.log, tasks):
1057            self.log.error("Phone Failed to Set Up Properly.")
1058            return False
1059
1060        self.log.info("Step1: Initiate Video Call PhoneA->PhoneB.")
1061        if not video_call_setup_teardown(
1062                self.log,
1063                ads[0],
1064                ads[1],
1065                None,
1066                video_state=VT_STATE_BIDIRECTIONAL,
1067                verify_caller_func=is_phone_in_call_video_bidirectional,
1068                verify_callee_func=is_phone_in_call_video_bidirectional):
1069            self.log.error("Failed to setup a call")
1070            return False
1071        call_id_video = get_call_id_in_video_state(self.log, ads[0],
1072                                                   VT_STATE_BIDIRECTIONAL)
1073        if call_id_video is None:
1074            self.log.error("No active video call in PhoneA.")
1075            return False
1076
1077        self.log.info("Step2: Initiate Voice Call PhoneC->PhoneA.")
1078        if not call_setup_teardown(self.log,
1079                                   ads[2],
1080                                   ads[0],
1081                                   None,
1082                                   verify_caller_func=is_phone_in_call_volte,
1083                                   verify_callee_func=None):
1084            self.log.error("Failed to setup a call")
1085            return False
1086
1087        self.log.info(
1088            "Step3: Verify PhoneA's video/voice call in correct state.")
1089        calls = ads[0].droid.telecomCallGetCallIds()
1090        self.log.info("Calls in PhoneA{}".format(calls))
1091        if num_active_calls(self.log, ads[0]) != 2:
1092            self.log.error("Active call numbers in PhoneA is not 2.")
1093            return False
1094        for call in calls:
1095            if call != call_id_video:
1096                call_id_voice = call
1097
1098        if not verify_video_call_in_expected_state(
1099                self.log, ads[0], call_id_video, VT_STATE_BIDIRECTIONAL_PAUSED,
1100                CALL_STATE_HOLDING):
1101            return False
1102
1103        if not verify_video_call_in_expected_state(
1104                self.log, ads[0], call_id_voice, VT_STATE_AUDIO_ONLY,
1105                CALL_STATE_ACTIVE):
1106            return False
1107        self.log.info("Step4: Verify all phones remain in-call.")
1108        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
1109            return False
1110
1111        self.log.info(
1112            "Step5: Swap calls on PhoneA and verify call state correct.")
1113        ads[0].droid.telecomCallHold(call_id_voice)
1114        time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
1115        for ad in [ads[0], ads[1]]:
1116            if get_audio_route(self.log, ad) != AUDIO_ROUTE_SPEAKER:
1117                self.log.error("{} Audio is not on speaker.".format(ad.serial))
1118                # TODO: b/26337892 Define expected audio route behavior.
1119
1120            set_audio_route(self.log, ad, AUDIO_ROUTE_EARPIECE)
1121
1122        time.sleep(WAIT_TIME_IN_CALL)
1123        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
1124            return False
1125        if not verify_video_call_in_expected_state(
1126                self.log, ads[0], call_id_video, VT_STATE_BIDIRECTIONAL,
1127                CALL_STATE_ACTIVE):
1128            return False
1129        if not verify_video_call_in_expected_state(
1130                self.log, ads[0], call_id_voice, VT_STATE_AUDIO_ONLY,
1131                CALL_STATE_HOLDING):
1132            return False
1133
1134        self.log.info("Step6: Drop Video Call on PhoneA.")
1135        disconnect_call_by_id(self.log, ads[0], call_id_video)
1136        time.sleep(WAIT_TIME_IN_CALL)
1137        if not verify_incall_state(self.log, [ads[0], ads[2]], True):
1138            return False
1139        disconnect_call_by_id(self.log, ads[0], call_id_voice)
1140        time.sleep(WAIT_TIME_IN_CALL)
1141        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], False):
1142            return False
1143        return True
1144
1145    @TelephonyBaseTest.tel_test_wrap
1146    def test_call_video_add_mt_voice_swap_twice_remote_drop_voice_unhold_video(
1147            self):
1148        """
1149        From Phone_A, Initiate a Bi-Directional Video Call to Phone_B
1150        Accept the call on Phone_B as Bi-Directional Video
1151        From Phone_C, add a voice call to Phone_A
1152        Accept the call on Phone_A
1153        Verify both calls remain active.
1154        Swap calls on PhoneA.
1155        Swap calls on PhoneA.
1156        End Voice call on PhoneC.
1157        Unhold Video call on PhoneA.
1158        End Video call on PhoneA.
1159        """
1160
1161        ads = self.android_devices
1162        tasks = [(phone_setup_video, (self.log, ads[0])),
1163                 (phone_setup_video, (self.log, ads[1])), (phone_setup_volte,
1164                                                           (self.log, ads[2]))]
1165        if not multithread_func(self.log, tasks):
1166            self.log.error("Phone Failed to Set Up Properly.")
1167            return False
1168
1169        self.log.info("Step1: Initiate Video Call PhoneA->PhoneB.")
1170        if not video_call_setup_teardown(
1171                self.log,
1172                ads[0],
1173                ads[1],
1174                None,
1175                video_state=VT_STATE_BIDIRECTIONAL,
1176                verify_caller_func=is_phone_in_call_video_bidirectional,
1177                verify_callee_func=is_phone_in_call_video_bidirectional):
1178            self.log.error("Failed to setup a call")
1179            return False
1180        call_id_video = get_call_id_in_video_state(self.log, ads[0],
1181                                                   VT_STATE_BIDIRECTIONAL)
1182        if call_id_video is None:
1183            self.log.error("No active video call in PhoneA.")
1184            return False
1185
1186        self.log.info("Step2: Initiate Voice Call PhoneC->PhoneA.")
1187        if not call_setup_teardown(self.log,
1188                                   ads[2],
1189                                   ads[0],
1190                                   None,
1191                                   verify_caller_func=is_phone_in_call_volte,
1192                                   verify_callee_func=None):
1193            self.log.error("Failed to setup a call")
1194            return False
1195
1196        self.log.info(
1197            "Step3: Verify PhoneA's video/voice call in correct state.")
1198        calls = ads[0].droid.telecomCallGetCallIds()
1199        self.log.info("Calls in PhoneA{}".format(calls))
1200        if num_active_calls(self.log, ads[0]) != 2:
1201            self.log.error("Active call numbers in PhoneA is not 2.")
1202            return False
1203        for call in calls:
1204            if call != call_id_video:
1205                call_id_voice = call
1206
1207        if not verify_video_call_in_expected_state(
1208                self.log, ads[0], call_id_video, VT_STATE_BIDIRECTIONAL_PAUSED,
1209                CALL_STATE_HOLDING):
1210            return False
1211
1212        if not verify_video_call_in_expected_state(
1213                self.log, ads[0], call_id_voice, VT_STATE_AUDIO_ONLY,
1214                CALL_STATE_ACTIVE):
1215            return False
1216        self.log.info("Step4: Verify all phones remain in-call.")
1217        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
1218            return False
1219
1220        self.log.info(
1221            "Step5: Swap calls on PhoneA and verify call state correct.")
1222        ads[0].droid.telecomCallHold(call_id_voice)
1223        time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
1224        for ad in [ads[0], ads[1]]:
1225            if get_audio_route(self.log, ad) != AUDIO_ROUTE_SPEAKER:
1226                self.log.error("{} Audio is not on speaker.".format(ad.serial))
1227                # TODO: b/26337892 Define expected audio route behavior.
1228            set_audio_route(self.log, ad, AUDIO_ROUTE_EARPIECE)
1229
1230        time.sleep(WAIT_TIME_IN_CALL)
1231        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
1232            return False
1233        if not verify_video_call_in_expected_state(
1234                self.log, ads[0], call_id_video, VT_STATE_BIDIRECTIONAL,
1235                CALL_STATE_ACTIVE):
1236            return False
1237        if not verify_video_call_in_expected_state(
1238                self.log, ads[0], call_id_voice, VT_STATE_AUDIO_ONLY,
1239                CALL_STATE_HOLDING):
1240            return False
1241
1242        self.log.info(
1243            "Step6: Swap calls on PhoneA and verify call state correct.")
1244        ads[0].droid.telecomCallHold(call_id_video)
1245        time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
1246        # Audio will goto earpiece in here
1247        for ad in [ads[0], ads[1]]:
1248            if get_audio_route(self.log, ad) != AUDIO_ROUTE_EARPIECE:
1249                self.log.error("{} Audio is not on EARPIECE.".format(
1250                    ad.serial))
1251                # TODO: b/26337892 Define expected audio route behavior.
1252
1253        time.sleep(WAIT_TIME_IN_CALL)
1254        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
1255            return False
1256        if not verify_video_call_in_expected_state(
1257                self.log, ads[0], call_id_video, VT_STATE_BIDIRECTIONAL,
1258                CALL_STATE_HOLDING):
1259            return False
1260        if not verify_video_call_in_expected_state(
1261                self.log, ads[0], call_id_voice, VT_STATE_AUDIO_ONLY,
1262                CALL_STATE_ACTIVE):
1263            return False
1264
1265        self.log.info("Step7: Drop Voice Call on PhoneC.")
1266        hangup_call(self.log, ads[2])
1267        time.sleep(WAIT_TIME_IN_CALL)
1268        if not verify_incall_state(self.log, [ads[0], ads[1]], True):
1269            return False
1270
1271        self.log.info(
1272            "Step8: Unhold Video call on PhoneA and verify call state.")
1273        ads[0].droid.telecomCallUnhold(call_id_video)
1274        time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
1275        # Audio will goto earpiece in here
1276        for ad in [ads[0], ads[1]]:
1277            if get_audio_route(self.log, ad) != AUDIO_ROUTE_EARPIECE:
1278                self.log.error("{} Audio is not on EARPIECE.".format(
1279                    ad.serial))
1280                # TODO: b/26337892 Define expected audio route behavior.
1281
1282        time.sleep(WAIT_TIME_IN_CALL)
1283        if not verify_video_call_in_expected_state(
1284                self.log, ads[0], call_id_video, VT_STATE_BIDIRECTIONAL,
1285                CALL_STATE_ACTIVE):
1286            return False
1287
1288        self.log.info("Step9: Drop Video Call on PhoneA.")
1289        disconnect_call_by_id(self.log, ads[0], call_id_video)
1290        time.sleep(WAIT_TIME_IN_CALL)
1291        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], False):
1292            return False
1293        return True
1294
1295    @TelephonyBaseTest.tel_test_wrap
1296    def test_call_video_add_mo_video(self):
1297        """
1298        From Phone_A, Initiate a Bi-Directional Video Call to Phone_B
1299        Accept the call on Phone_B as Bi-Directional Video
1300        From Phone_A, add a Bi-Directional Video Call to Phone_C
1301        Accept the call on Phone_C
1302        Verify both calls remain active.
1303        """
1304        # This test case is not supported by VZW.
1305        ads = self.android_devices
1306        tasks = [(phone_setup_video, (self.log, ads[0])),
1307                 (phone_setup_video, (self.log, ads[1])), (phone_setup_video,
1308                                                           (self.log, ads[2]))]
1309        if not multithread_func(self.log, tasks):
1310            self.log.error("Phone Failed to Set Up Properly.")
1311            return False
1312
1313        self.log.info("Step1: Initiate Video Call PhoneA->PhoneB.")
1314        if not video_call_setup_teardown(
1315                self.log,
1316                ads[0],
1317                ads[1],
1318                None,
1319                video_state=VT_STATE_BIDIRECTIONAL,
1320                verify_caller_func=is_phone_in_call_video_bidirectional,
1321                verify_callee_func=is_phone_in_call_video_bidirectional):
1322            self.log.error("Failed to setup a call")
1323            return False
1324        call_id_video_ab = get_call_id_in_video_state(self.log, ads[0],
1325                                                      VT_STATE_BIDIRECTIONAL)
1326        if call_id_video_ab is None:
1327            self.log.error("No active video call in PhoneA.")
1328            return False
1329
1330        self.log.info("Step2: Initiate Video Call PhoneA->PhoneC.")
1331        if not video_call_setup_teardown(
1332                self.log,
1333                ads[0],
1334                ads[2],
1335                None,
1336                video_state=VT_STATE_BIDIRECTIONAL,
1337                verify_caller_func=is_phone_in_call_video_bidirectional,
1338                verify_callee_func=is_phone_in_call_video_bidirectional):
1339            self.log.error("Failed to setup a call")
1340            return False
1341
1342        self.log.info("Step3: Verify PhoneA's video calls in correct state.")
1343        calls = ads[0].droid.telecomCallGetCallIds()
1344        self.log.info("Calls in PhoneA{}".format(calls))
1345        if num_active_calls(self.log, ads[0]) != 2:
1346            self.log.error("Active call numbers in PhoneA is not 2.")
1347            return False
1348        for call in calls:
1349            if call != call_id_video_ab:
1350                call_id_video_ac = call
1351
1352        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
1353            return False
1354        if not verify_video_call_in_expected_state(
1355                self.log, ads[0], call_id_video_ab, VT_STATE_BIDIRECTIONAL,
1356                CALL_STATE_HOLDING):
1357            return False
1358        if not verify_video_call_in_expected_state(
1359                self.log, ads[0], call_id_video_ac, VT_STATE_BIDIRECTIONAL,
1360                CALL_STATE_ACTIVE):
1361            return False
1362
1363        return self._vt_test_multi_call_hangup(ads)
1364
1365    @TelephonyBaseTest.tel_test_wrap
1366    def test_call_video_add_mt_video(self):
1367        """
1368        From Phone_A, Initiate a Bi-Directional Video Call to Phone_B
1369        Accept the call on Phone_B as Bi-Directional Video
1370        From Phone_C, add a Bi-Directional Video Call to Phone_A
1371        Accept the call on Phone_A
1372        Verify both calls remain active.
1373        Hang up on PhoneC.
1374        Hang up on PhoneA.
1375        """
1376        # TODO: b/21437650 Test will fail. After established 2nd call ~15s,
1377        # Phone C will drop call.
1378        ads = self.android_devices
1379        tasks = [(phone_setup_video, (self.log, ads[0])),
1380                 (phone_setup_video, (self.log, ads[1])), (phone_setup_video,
1381                                                           (self.log, ads[2]))]
1382        if not multithread_func(self.log, tasks):
1383            self.log.error("Phone Failed to Set Up Properly.")
1384            return False
1385
1386        self.log.info("Step1: Initiate Video Call PhoneA->PhoneB.")
1387        if not video_call_setup_teardown(
1388                self.log,
1389                ads[0],
1390                ads[1],
1391                None,
1392                video_state=VT_STATE_BIDIRECTIONAL,
1393                verify_caller_func=is_phone_in_call_video_bidirectional,
1394                verify_callee_func=is_phone_in_call_video_bidirectional):
1395            self.log.error("Failed to setup a call")
1396            return False
1397        call_id_video_ab = get_call_id_in_video_state(self.log, ads[0],
1398                                                      VT_STATE_BIDIRECTIONAL)
1399        if call_id_video_ab is None:
1400            self.log.error("No active video call in PhoneA.")
1401            return False
1402
1403        self.log.info("Step2: Initiate Video Call PhoneC->PhoneA.")
1404        if not video_call_setup_teardown(
1405                self.log,
1406                ads[2],
1407                ads[0],
1408                None,
1409                video_state=VT_STATE_BIDIRECTIONAL,
1410                verify_caller_func=is_phone_in_call_video_bidirectional,
1411                verify_callee_func=is_phone_in_call_video_bidirectional):
1412            self.log.error("Failed to setup a call")
1413            return False
1414
1415        self.log.info("Step3: Verify PhoneA's video calls in correct state.")
1416        calls = ads[0].droid.telecomCallGetCallIds()
1417        self.log.info("Calls in PhoneA{}".format(calls))
1418        if num_active_calls(self.log, ads[0]) != 2:
1419            self.log.error("Active call numbers in PhoneA is not 2.")
1420            return False
1421        for call in calls:
1422            if call != call_id_video_ab:
1423                call_id_video_ac = call
1424
1425        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
1426            return False
1427        if not verify_video_call_in_expected_state(
1428                self.log, ads[0], call_id_video_ab,
1429                VT_STATE_BIDIRECTIONAL_PAUSED, CALL_STATE_HOLDING):
1430            return False
1431        if not verify_video_call_in_expected_state(
1432                self.log, ads[0], call_id_video_ac, VT_STATE_BIDIRECTIONAL,
1433                CALL_STATE_ACTIVE):
1434            return False
1435
1436        self.log.info("Step4: Hangup on PhoneC.")
1437        if not hangup_call(self.log, ads[2]):
1438            return False
1439        time.sleep(WAIT_TIME_IN_CALL)
1440        if not verify_incall_state(self.log, [ads[0], ads[1]], True):
1441            return False
1442        self.log.info("Step4: Hangup on PhoneA.")
1443        if not hangup_call(self.log, ads[0]):
1444            return False
1445        time.sleep(WAIT_TIME_IN_CALL)
1446        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], False):
1447            return False
1448        return True
1449
1450    @TelephonyBaseTest.tel_test_wrap
1451    def test_call_mt_video_add_mt_video(self):
1452        """
1453        From Phone_B, Initiate a Bi-Directional Video Call to Phone_A
1454        Accept the call on Phone_A as Bi-Directional Video
1455        From Phone_C, add a Bi-Directional Video Call to Phone_A
1456        Accept the call on Phone_A
1457        Verify both calls remain active.
1458        Hang up on PhoneC.
1459        Hang up on PhoneA.
1460        """
1461        # TODO: b/21437650 Test will fail. After established 2nd call ~15s,
1462        # Phone C will drop call.
1463        ads = self.android_devices
1464        tasks = [(phone_setup_video, (self.log, ads[0])),
1465                 (phone_setup_video, (self.log, ads[1])), (phone_setup_video,
1466                                                           (self.log, ads[2]))]
1467        if not multithread_func(self.log, tasks):
1468            self.log.error("Phone Failed to Set Up Properly.")
1469            return False
1470
1471        self.log.info("Step1: Initiate Video Call PhoneB->PhoneA.")
1472        if not video_call_setup_teardown(
1473                self.log,
1474                ads[1],
1475                ads[0],
1476                None,
1477                video_state=VT_STATE_BIDIRECTIONAL,
1478                verify_caller_func=is_phone_in_call_video_bidirectional,
1479                verify_callee_func=is_phone_in_call_video_bidirectional):
1480            self.log.error("Failed to setup a call")
1481            return False
1482        call_id_video_ab = get_call_id_in_video_state(self.log, ads[0],
1483                                                      VT_STATE_BIDIRECTIONAL)
1484        if call_id_video_ab is None:
1485            self.log.error("No active video call in PhoneA.")
1486            return False
1487
1488        self.log.info("Step2: Initiate Video Call PhoneC->PhoneA.")
1489        if not video_call_setup_teardown(
1490                self.log,
1491                ads[2],
1492                ads[0],
1493                None,
1494                video_state=VT_STATE_BIDIRECTIONAL,
1495                verify_caller_func=is_phone_in_call_video_bidirectional,
1496                verify_callee_func=is_phone_in_call_video_bidirectional):
1497            self.log.error("Failed to setup a call")
1498            return False
1499
1500        self.log.info("Step3: Verify PhoneA's video calls in correct state.")
1501        calls = ads[0].droid.telecomCallGetCallIds()
1502        self.log.info("Calls in PhoneA{}".format(calls))
1503        if num_active_calls(self.log, ads[0]) != 2:
1504            self.log.error("Active call numbers in PhoneA is not 2.")
1505            return False
1506        for call in calls:
1507            if call != call_id_video_ab:
1508                call_id_video_ac = call
1509
1510        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
1511            return False
1512        if not verify_video_call_in_expected_state(
1513                self.log, ads[0], call_id_video_ab,
1514                VT_STATE_BIDIRECTIONAL_PAUSED, CALL_STATE_HOLDING):
1515            return False
1516        if not verify_video_call_in_expected_state(
1517                self.log, ads[0], call_id_video_ac, VT_STATE_BIDIRECTIONAL,
1518                CALL_STATE_ACTIVE):
1519            return False
1520
1521        self.log.info("Step4: Hangup on PhoneC.")
1522        if not hangup_call(self.log, ads[2]):
1523            return False
1524        time.sleep(WAIT_TIME_IN_CALL)
1525        if not verify_incall_state(self.log, [ads[0], ads[1]], True):
1526            return False
1527        self.log.info("Step4: Hangup on PhoneA.")
1528        if not hangup_call(self.log, ads[0]):
1529            return False
1530        time.sleep(WAIT_TIME_IN_CALL)
1531        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], False):
1532            return False
1533        return True
1534
1535    @TelephonyBaseTest.tel_test_wrap
1536    def test_call_mt_video_add_mo_video(self):
1537        """
1538        From Phone_B, Initiate a Bi-Directional Video Call to Phone_A
1539        Accept the call on Phone_A as Bi-Directional Video
1540        From Phone_A, add a Bi-Directional Video Call to Phone_C
1541        Accept the call on Phone_C
1542        Verify both calls remain active.
1543        """
1544        # This test case is not supported by VZW.
1545        ads = self.android_devices
1546        tasks = [(phone_setup_video, (self.log, ads[0])),
1547                 (phone_setup_video, (self.log, ads[1])), (phone_setup_video,
1548                                                           (self.log, ads[2]))]
1549        if not multithread_func(self.log, tasks):
1550            self.log.error("Phone Failed to Set Up Properly.")
1551            return False
1552
1553        self.log.info("Step1: Initiate Video Call PhoneB->PhoneA.")
1554        if not video_call_setup_teardown(
1555                self.log,
1556                ads[1],
1557                ads[0],
1558                None,
1559                video_state=VT_STATE_BIDIRECTIONAL,
1560                verify_caller_func=is_phone_in_call_video_bidirectional,
1561                verify_callee_func=is_phone_in_call_video_bidirectional):
1562            self.log.error("Failed to setup a call")
1563            return False
1564        call_id_video_ab = get_call_id_in_video_state(self.log, ads[0],
1565                                                      VT_STATE_BIDIRECTIONAL)
1566        if call_id_video_ab is None:
1567            self.log.error("No active video call in PhoneA.")
1568            return False
1569
1570        self.log.info("Step2: Initiate Video Call PhoneA->PhoneC.")
1571        if not video_call_setup_teardown(
1572                self.log,
1573                ads[0],
1574                ads[2],
1575                None,
1576                video_state=VT_STATE_BIDIRECTIONAL,
1577                verify_caller_func=is_phone_in_call_video_bidirectional,
1578                verify_callee_func=is_phone_in_call_video_bidirectional):
1579            self.log.error("Failed to setup a call")
1580            return False
1581
1582        self.log.info("Step3: Verify PhoneA's video calls in correct state.")
1583        calls = ads[0].droid.telecomCallGetCallIds()
1584        self.log.info("Calls in PhoneA{}".format(calls))
1585        if num_active_calls(self.log, ads[0]) != 2:
1586            self.log.error("Active call numbers in PhoneA is not 2.")
1587            return False
1588        for call in calls:
1589            if call != call_id_video_ab:
1590                call_id_video_ac = call
1591
1592        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
1593            return False
1594        if not verify_video_call_in_expected_state(
1595                self.log, ads[0], call_id_video_ab, VT_STATE_BIDIRECTIONAL,
1596                CALL_STATE_HOLDING):
1597            return False
1598        if not verify_video_call_in_expected_state(
1599                self.log, ads[0], call_id_video_ac, VT_STATE_BIDIRECTIONAL,
1600                CALL_STATE_ACTIVE):
1601            return False
1602
1603        return self._vt_test_multi_call_hangup(ads)
1604
1605    def _test_vt_conference_merge_drop(self, ads, call_ab_id, call_ac_id):
1606        """Test conference merge and drop for VT call test.
1607
1608        PhoneA in call with PhoneB.
1609        PhoneA in call with PhoneC.
1610        Merge calls to conference on PhoneA.
1611        Hangup on PhoneB, check call continues between AC.
1612        Hangup on PhoneC.
1613        Hangup on PhoneA.
1614
1615        Args:
1616            call_ab_id: call id for call_AB on PhoneA.
1617            call_ac_id: call id for call_AC on PhoneA.
1618
1619        Returns:
1620            True if succeed;
1621            False if failed.
1622        """
1623        self.log.info(
1624            "Merge - Step1: Merge to Conf Call and verify Conf Call.")
1625        ads[0].droid.telecomCallJoinCallsInConf(call_ab_id, call_ac_id)
1626        time.sleep(WAIT_TIME_IN_CALL)
1627        calls = ads[0].droid.telecomCallGetCallIds()
1628        self.log.info("Calls in PhoneA{}".format(calls))
1629        if num_active_calls(self.log, ads[0]) != 1:
1630            self.log.error("Total number of call ids in {} is not 1.".format(
1631                ads[0].serial))
1632            return False
1633        call_conf_id = None
1634        for call_id in calls:
1635            if call_id != call_ab_id and call_id != call_ac_id:
1636                call_conf_id = call_id
1637        if not call_conf_id:
1638            self.log.error("Merge call fail, no new conference call id.")
1639            return False
1640        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
1641            return False
1642
1643        # Check if Conf Call is currently active
1644        if ads[0].droid.telecomCallGetCallState(
1645                call_conf_id) != CALL_STATE_ACTIVE:
1646            self.log.error(
1647                "Call_id:{}, state:{}, expected: STATE_ACTIVE".format(
1648                    call_conf_id, ads[0].droid.telecomCallGetCallState(
1649                        call_conf_id)))
1650            return False
1651
1652        self.log.info(
1653            "Merge - Step2: End call on PhoneB and verify call continues.")
1654        ads[1].droid.telecomEndCall()
1655        time.sleep(WAIT_TIME_IN_CALL)
1656        calls = ads[0].droid.telecomCallGetCallIds()
1657        self.log.info("Calls in PhoneA{}".format(calls))
1658        if not verify_incall_state(self.log, [ads[0], ads[2]], True):
1659            return False
1660        if not verify_incall_state(self.log, [ads[1]], False):
1661            return False
1662
1663        ads[1].droid.telecomEndCall()
1664        ads[0].droid.telecomEndCall()
1665        return True
1666
1667    def _test_vt_conference_merge_drop_cep(self, ads, call_ab_id, call_ac_id):
1668        """Merge CEP conference call.
1669
1670        PhoneA in IMS (VoLTE or WiFi Calling) call with PhoneB.
1671        PhoneA in IMS (VoLTE or WiFi Calling) call with PhoneC.
1672        Merge calls to conference on PhoneA (CEP enabled IMS conference).
1673
1674        Args:
1675            call_ab_id: call id for call_AB on PhoneA.
1676            call_ac_id: call id for call_AC on PhoneA.
1677
1678        Returns:
1679            call_id for conference
1680        """
1681
1682        self.log.info("Step4: Merge to Conf Call and verify Conf Call.")
1683        ads[0].droid.telecomCallJoinCallsInConf(call_ab_id, call_ac_id)
1684        time.sleep(WAIT_TIME_IN_CALL)
1685        calls = ads[0].droid.telecomCallGetCallIds()
1686        self.log.info("Calls in PhoneA{}".format(calls))
1687
1688        call_conf_id = get_cep_conference_call_id(ads[0])
1689        if call_conf_id is None:
1690            self.log.error(
1691                "No call with children. Probably CEP not enabled or merge failed.")
1692            return False
1693        calls.remove(call_conf_id)
1694        if (set(ads[0].droid.telecomCallGetCallChildren(call_conf_id)) !=
1695                set(calls)):
1696            self.log.error(
1697                "Children list<{}> for conference call is not correct.".format(
1698                    ads[0].droid.telecomCallGetCallChildren(call_conf_id)))
1699            return False
1700
1701        if (CALL_PROPERTY_CONFERENCE not in
1702                ads[0].droid.telecomCallGetProperties(call_conf_id)):
1703            self.log.error("Conf call id properties wrong: {}".format(ads[
1704                0].droid.telecomCallGetProperties(call_conf_id)))
1705            return False
1706
1707        if (CALL_CAPABILITY_MANAGE_CONFERENCE not in
1708                ads[0].droid.telecomCallGetCapabilities(call_conf_id)):
1709            self.log.error("Conf call id capabilities wrong: {}".format(ads[
1710                0].droid.telecomCallGetCapabilities(call_conf_id)))
1711            return False
1712
1713        if (call_ab_id in calls) or (call_ac_id in calls):
1714            self.log.error(
1715                "Previous call ids should not in new call list after merge.")
1716            return False
1717
1718        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
1719            return False
1720
1721        # Check if Conf Call is currently active
1722        if ads[0].droid.telecomCallGetCallState(
1723                call_conf_id) != CALL_STATE_ACTIVE:
1724            self.log.error(
1725                "Call_id:{}, state:{}, expected: STATE_ACTIVE".format(
1726                    call_conf_id, ads[0].droid.telecomCallGetCallState(
1727                        call_conf_id)))
1728            return False
1729
1730        self.log.info(
1731            "End call on PhoneB and verify call continues.")
1732        ads[1].droid.telecomEndCall()
1733        time.sleep(WAIT_TIME_IN_CALL)
1734        calls = ads[0].droid.telecomCallGetCallIds()
1735        self.log.info("Calls in PhoneA{}".format(calls))
1736        if not verify_incall_state(self.log, [ads[0], ads[2]], True):
1737            return False
1738        if not verify_incall_state(self.log, [ads[1]], False):
1739            return False
1740
1741        ads[1].droid.telecomEndCall()
1742        ads[0].droid.telecomEndCall()
1743
1744        return True
1745
1746    @TelephonyBaseTest.tel_test_wrap
1747    def test_call_volte_add_mo_video_accept_as_voice_merge_drop(self):
1748        """Conference call
1749
1750        Make Sure PhoneA is in LTE mode (with Video Calling).
1751        Make Sure PhoneB is in LTE mode (with VoLTE).
1752        Make Sure PhoneC is in LTE mode (with Video Calling).
1753        PhoneA VoLTE call to PhoneB. Accept on PhoneB.
1754        PhoneA add a Bi-Directional Video call to PhoneC.
1755        PhoneC accept as voice.
1756        Merge call on PhoneA.
1757        Hang up on PhoneB.
1758        Hang up on PhoneC.
1759        """
1760        return self._test_call_volte_add_mo_video_accept_as_voice_merge_drop(
1761            False)
1762
1763    @TelephonyBaseTest.tel_test_wrap
1764    def test_call_volte_add_mo_video_accept_as_voice_merge_drop_cep(self):
1765        """Conference call
1766
1767        Make Sure PhoneA is in LTE mode (with Video Calling).
1768        Make Sure PhoneB is in LTE mode (with VoLTE).
1769        Make Sure PhoneC is in LTE mode (with Video Calling).
1770        PhoneA VoLTE call to PhoneB. Accept on PhoneB.
1771        PhoneA add a Bi-Directional Video call to PhoneC.
1772        PhoneC accept as voice.
1773        Merge call on PhoneA.
1774        Hang up on PhoneB.
1775        Hang up on PhoneC.
1776        """
1777        return self._test_call_volte_add_mo_video_accept_as_voice_merge_drop(
1778            True)
1779
1780    def _test_call_volte_add_mo_video_accept_as_voice_merge_drop(
1781            self,
1782            use_cep=False):
1783        # This test case is not supported by VZW.
1784        ads = self.android_devices
1785        tasks = [(phone_setup_video, (self.log, ads[0])),
1786                 (phone_setup_volte, (self.log, ads[1])), (phone_setup_video,
1787                                                           (self.log, ads[2]))]
1788        if not multithread_func(self.log, tasks):
1789            self.log.error("Phone Failed to Set Up Properly.")
1790            return False
1791        self.log.info("Step1: Initiate VoLTE Call PhoneA->PhoneB.")
1792        if not call_setup_teardown(self.log, ads[0], ads[1], None,
1793                                   is_phone_in_call_volte,
1794                                   is_phone_in_call_volte):
1795            self.log.error("Failed to setup a call")
1796            return False
1797        calls = ads[0].droid.telecomCallGetCallIds()
1798        self.log.info("Calls in PhoneA{}".format(calls))
1799        if num_active_calls(self.log, ads[0]) != 1:
1800            self.log.error("Active call numbers in PhoneA is not 1.")
1801            return False
1802        call_ab_id = calls[0]
1803
1804        self.log.info(
1805            "Step2: Initiate Video Call PhoneA->PhoneC and accept as voice.")
1806        if not video_call_setup_teardown(
1807                self.log,
1808                ads[0],
1809                ads[2],
1810                None,
1811                video_state=VT_STATE_AUDIO_ONLY,
1812                verify_caller_func=is_phone_in_call_voice_hd,
1813                verify_callee_func=is_phone_in_call_voice_hd):
1814            self.log.error("Failed to setup a call")
1815            return False
1816        calls = ads[0].droid.telecomCallGetCallIds()
1817        self.log.info("Calls in PhoneA{}".format(calls))
1818        if num_active_calls(self.log, ads[0]) != 2:
1819            self.log.error("Active call numbers in PhoneA is not 2.")
1820            return False
1821        for call in calls:
1822            if call != call_ab_id:
1823                call_ac_id = call
1824
1825        self.log.info("Step3: Verify calls in correct state.")
1826        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
1827            return False
1828        if not verify_video_call_in_expected_state(
1829                self.log, ads[0], call_ab_id, VT_STATE_AUDIO_ONLY,
1830                CALL_STATE_HOLDING):
1831            return False
1832        if not verify_video_call_in_expected_state(
1833                self.log, ads[0], call_ac_id, VT_STATE_AUDIO_ONLY,
1834                CALL_STATE_ACTIVE):
1835            return False
1836
1837        return {False: self._test_vt_conference_merge_drop,
1838                True: self._test_vt_conference_merge_drop_cep}[use_cep](
1839                    ads, call_ab_id, call_ac_id)
1840
1841    @TelephonyBaseTest.tel_test_wrap
1842    def test_call_volte_add_mt_video_accept_as_voice_merge_drop(self):
1843        """Conference call
1844
1845        Make Sure PhoneA is in LTE mode (with Video Calling).
1846        Make Sure PhoneB is in LTE mode (with VoLTE).
1847        Make Sure PhoneC is in LTE mode (with Video Calling).
1848        PhoneA VoLTE call to PhoneB. Accept on PhoneB.
1849        PhoneC add a Bi-Directional Video call to PhoneA.
1850        PhoneA accept as voice.
1851        Merge call on PhoneA.
1852        Hang up on PhoneB.
1853        Hang up on PhoneC.
1854        """
1855        return self._test_call_volte_add_mt_video_accept_as_voice_merge_drop(
1856            False)
1857
1858    @TelephonyBaseTest.tel_test_wrap
1859    def test_call_volte_add_mt_video_accept_as_voice_merge_drop_cep(self):
1860        """Conference call
1861
1862        Make Sure PhoneA is in LTE mode (with Video Calling).
1863        Make Sure PhoneB is in LTE mode (with VoLTE).
1864        Make Sure PhoneC is in LTE mode (with Video Calling).
1865        PhoneA VoLTE call to PhoneB. Accept on PhoneB.
1866        PhoneC add a Bi-Directional Video call to PhoneA.
1867        PhoneA accept as voice.
1868        Merge call on PhoneA.
1869        Hang up on PhoneB.
1870        Hang up on PhoneC.
1871        """
1872        return self._test_call_volte_add_mt_video_accept_as_voice_merge_drop(
1873            True)
1874
1875    def _test_call_volte_add_mt_video_accept_as_voice_merge_drop(
1876            self,
1877            use_cep=False):
1878        ads = self.android_devices
1879        tasks = [(phone_setup_video, (self.log, ads[0])),
1880                 (phone_setup_volte, (self.log, ads[1])), (phone_setup_video,
1881                                                           (self.log, ads[2]))]
1882        if not multithread_func(self.log, tasks):
1883            self.log.error("Phone Failed to Set Up Properly.")
1884            return False
1885        self.log.info("Step1: Initiate VoLTE Call PhoneA->PhoneB.")
1886        if not call_setup_teardown(self.log, ads[0], ads[1], None,
1887                                   is_phone_in_call_volte,
1888                                   is_phone_in_call_volte):
1889            self.log.error("Failed to setup a call")
1890            return False
1891        calls = ads[0].droid.telecomCallGetCallIds()
1892        self.log.info("Calls in PhoneA{}".format(calls))
1893        if num_active_calls(self.log, ads[0]) != 1:
1894            self.log.error("Active call numbers in PhoneA is not 1.")
1895            return False
1896        call_ab_id = calls[0]
1897
1898        self.log.info(
1899            "Step2: Initiate Video Call PhoneC->PhoneA and accept as voice.")
1900        if not video_call_setup_teardown(
1901                self.log,
1902                ads[2],
1903                ads[0],
1904                None,
1905                video_state=VT_STATE_AUDIO_ONLY,
1906                verify_caller_func=is_phone_in_call_voice_hd,
1907                verify_callee_func=is_phone_in_call_voice_hd):
1908            self.log.error("Failed to setup a call")
1909            return False
1910        calls = ads[0].droid.telecomCallGetCallIds()
1911        self.log.info("Calls in PhoneA{}".format(calls))
1912        if num_active_calls(self.log, ads[0]) != 2:
1913            self.log.error("Active call numbers in PhoneA is not 2.")
1914            return False
1915        for call in calls:
1916            if call != call_ab_id:
1917                call_ac_id = call
1918
1919        self.log.info("Step3: Verify calls in correct state.")
1920        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
1921            return False
1922        if not verify_video_call_in_expected_state(
1923                self.log, ads[0], call_ab_id, VT_STATE_AUDIO_ONLY,
1924                CALL_STATE_HOLDING):
1925            return False
1926        if not verify_video_call_in_expected_state(
1927                self.log, ads[0], call_ac_id, VT_STATE_AUDIO_ONLY,
1928                CALL_STATE_ACTIVE):
1929            return False
1930
1931        return {False: self._test_vt_conference_merge_drop,
1932                True: self._test_vt_conference_merge_drop_cep}[use_cep](
1933                    ads, call_ab_id, call_ac_id)
1934
1935    @TelephonyBaseTest.tel_test_wrap
1936    def test_call_video_add_mo_voice_swap_downgrade_merge_drop(self):
1937        """Conference call
1938
1939        Make Sure PhoneA is in LTE mode (with Video Calling).
1940        Make Sure PhoneB is in LTE mode (with Video Calling).
1941        Make Sure PhoneC is in LTE mode (with VoLTE).
1942        PhoneA add a Bi-Directional Video call to PhoneB.
1943        PhoneB accept as Video.
1944        PhoneA VoLTE call to PhoneC. Accept on PhoneC.
1945        Swap Active call on PhoneA.
1946        Downgrade Video call on PhoneA and PhoneB to audio only.
1947        Merge call on PhoneA.
1948        Hang up on PhoneB.
1949        Hang up on PhoneC.
1950        """
1951        return self._test_call_video_add_mo_voice_swap_downgrade_merge_drop(
1952            False)
1953
1954    @TelephonyBaseTest.tel_test_wrap
1955    def test_call_video_add_mo_voice_swap_downgrade_merge_drop_cep(self):
1956        """Conference call
1957
1958        Make Sure PhoneA is in LTE mode (with Video Calling).
1959        Make Sure PhoneB is in LTE mode (with Video Calling).
1960        Make Sure PhoneC is in LTE mode (with VoLTE).
1961        PhoneA add a Bi-Directional Video call to PhoneB.
1962        PhoneB accept as Video.
1963        PhoneA VoLTE call to PhoneC. Accept on PhoneC.
1964        Swap Active call on PhoneA.
1965        Downgrade Video call on PhoneA and PhoneB to audio only.
1966        Merge call on PhoneA.
1967        Hang up on PhoneB.
1968        Hang up on PhoneC.
1969        """
1970        return self._test_call_video_add_mo_voice_swap_downgrade_merge_drop(
1971            True)
1972
1973    def _test_call_video_add_mo_voice_swap_downgrade_merge_drop(self, use_cep):
1974        ads = self.android_devices
1975        tasks = [(phone_setup_video, (self.log, ads[0])),
1976                 (phone_setup_video, (self.log, ads[1])), (phone_setup_volte,
1977                                                           (self.log, ads[2]))]
1978        if not multithread_func(self.log, tasks):
1979            self.log.error("Phone Failed to Set Up Properly.")
1980            return False
1981
1982        self.log.info("Step1: Initiate Video Call PhoneA->PhoneB.")
1983        if not video_call_setup_teardown(
1984                self.log,
1985                ads[0],
1986                ads[1],
1987                None,
1988                video_state=VT_STATE_BIDIRECTIONAL,
1989                verify_caller_func=is_phone_in_call_video_bidirectional,
1990                verify_callee_func=is_phone_in_call_video_bidirectional):
1991            self.log.error("Failed to setup a call")
1992            return False
1993        call_id_video_ab = get_call_id_in_video_state(self.log, ads[0],
1994                                                      VT_STATE_BIDIRECTIONAL)
1995        if call_id_video_ab is None:
1996            self.log.error("No active video call in PhoneA.")
1997            return False
1998
1999        self.log.info("Step2: Initiate Voice Call PhoneA->PhoneC.")
2000        if not call_setup_teardown(self.log,
2001                                   ads[0],
2002                                   ads[2],
2003                                   None,
2004                                   verify_caller_func=None,
2005                                   verify_callee_func=is_phone_in_call_volte):
2006            self.log.error("Failed to setup a call")
2007            return False
2008
2009        self.log.info(
2010            "Step3: Verify PhoneA's video/voice call in correct state.")
2011        calls = ads[0].droid.telecomCallGetCallIds()
2012        self.log.info("Calls in PhoneA{}".format(calls))
2013        if num_active_calls(self.log, ads[0]) != 2:
2014            self.log.error("Active call numbers in PhoneA is not 2.")
2015            return False
2016        for call in calls:
2017            if call != call_id_video_ab:
2018                call_id_voice_ac = call
2019
2020        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
2021            return False
2022        if not verify_video_call_in_expected_state(
2023                self.log, ads[0], call_id_video_ab, VT_STATE_BIDIRECTIONAL,
2024                CALL_STATE_HOLDING):
2025            return False
2026        if not verify_video_call_in_expected_state(
2027                self.log, ads[0], call_id_voice_ac, VT_STATE_AUDIO_ONLY,
2028                CALL_STATE_ACTIVE):
2029            return False
2030
2031        self.log.info(
2032            "Step4: Swap calls on PhoneA and verify call state correct.")
2033        ads[0].droid.telecomCallHold(call_id_voice_ac)
2034        time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
2035        for ad in [ads[0], ads[1]]:
2036            self.log.info("{} audio: {}".format(ad.serial, get_audio_route(
2037                self.log, ad)))
2038            set_audio_route(self.log, ad, AUDIO_ROUTE_EARPIECE)
2039
2040        time.sleep(WAIT_TIME_IN_CALL)
2041        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
2042            return False
2043        if not verify_video_call_in_expected_state(
2044                self.log, ads[0], call_id_video_ab, VT_STATE_BIDIRECTIONAL,
2045                CALL_STATE_ACTIVE):
2046            return False
2047        if not verify_video_call_in_expected_state(
2048                self.log, ads[0], call_id_voice_ac, VT_STATE_AUDIO_ONLY,
2049                CALL_STATE_HOLDING):
2050            return False
2051
2052        self.log.info("Step5: Disable camera on PhoneA and PhoneB.")
2053        if not video_call_downgrade(self.log, ads[0], call_id_video_ab, ads[1],
2054                                    get_call_id_in_video_state(
2055                                        self.log, ads[1],
2056                                        VT_STATE_BIDIRECTIONAL)):
2057            self.log.error("Failed to disable video on PhoneA.")
2058            return False
2059        if not video_call_downgrade(
2060                self.log, ads[1], get_call_id_in_video_state(
2061                    self.log, ads[1], VT_STATE_TX_ENABLED), ads[0],
2062                call_id_video_ab):
2063            self.log.error("Failed to disable video on PhoneB.")
2064            return False
2065
2066        self.log.info("Step6: Verify calls in correct state.")
2067        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
2068            return False
2069        if not verify_video_call_in_expected_state(
2070                self.log, ads[0], call_id_video_ab, VT_STATE_AUDIO_ONLY,
2071                CALL_STATE_ACTIVE):
2072            return False
2073        if not verify_video_call_in_expected_state(
2074                self.log, ads[0], call_id_voice_ac, VT_STATE_AUDIO_ONLY,
2075                CALL_STATE_HOLDING):
2076            return False
2077
2078        return {False: self._test_vt_conference_merge_drop,
2079                True: self._test_vt_conference_merge_drop_cep}[use_cep](
2080                    ads, call_id_video_ab, call_id_voice_ac)
2081
2082    @TelephonyBaseTest.tel_test_wrap
2083    def test_call_video_add_mt_voice_swap_downgrade_merge_drop(self):
2084        """Conference call
2085
2086        Make Sure PhoneA is in LTE mode (with Video Calling).
2087        Make Sure PhoneB is in LTE mode (with Video Calling).
2088        Make Sure PhoneC is in LTE mode (with VoLTE).
2089        PhoneA add a Bi-Directional Video call to PhoneB.
2090        PhoneB accept as Video.
2091        PhoneC VoLTE call to PhoneA. Accept on PhoneA.
2092        Swap Active call on PhoneA.
2093        Downgrade Video call on PhoneA and PhoneB to audio only.
2094        Merge call on PhoneA.
2095        Hang up on PhoneB.
2096        Hang up on PhoneC.
2097        """
2098        return self._test_call_video_add_mt_voice_swap_downgrade_merge_drop(
2099            False)
2100
2101    @TelephonyBaseTest.tel_test_wrap
2102    def test_call_video_add_mt_voice_swap_downgrade_merge_drop_cep(self):
2103        """Conference call
2104
2105        Make Sure PhoneA is in LTE mode (with Video Calling).
2106        Make Sure PhoneB is in LTE mode (with Video Calling).
2107        Make Sure PhoneC is in LTE mode (with VoLTE).
2108        PhoneA add a Bi-Directional Video call to PhoneB.
2109        PhoneB accept as Video.
2110        PhoneC VoLTE call to PhoneA. Accept on PhoneA.
2111        Swap Active call on PhoneA.
2112        Downgrade Video call on PhoneA and PhoneB to audio only.
2113        Merge call on PhoneA.
2114        Hang up on PhoneB.
2115        Hang up on PhoneC.
2116        """
2117        return self._test_call_video_add_mt_voice_swap_downgrade_merge_drop(
2118            True)
2119
2120    def _test_call_video_add_mt_voice_swap_downgrade_merge_drop(self,
2121                                                                use_cep=False):
2122        ads = self.android_devices
2123        tasks = [(phone_setup_video, (self.log, ads[0])),
2124                 (phone_setup_video, (self.log, ads[1])), (phone_setup_volte,
2125                                                           (self.log, ads[2]))]
2126        if not multithread_func(self.log, tasks):
2127            self.log.error("Phone Failed to Set Up Properly.")
2128            return False
2129
2130        self.log.info("Step1: Initiate Video Call PhoneA->PhoneB.")
2131        if not video_call_setup_teardown(
2132                self.log,
2133                ads[0],
2134                ads[1],
2135                None,
2136                video_state=VT_STATE_BIDIRECTIONAL,
2137                verify_caller_func=is_phone_in_call_video_bidirectional,
2138                verify_callee_func=is_phone_in_call_video_bidirectional):
2139            self.log.error("Failed to setup a call")
2140            return False
2141        call_id_video_ab = get_call_id_in_video_state(self.log, ads[0],
2142                                                      VT_STATE_BIDIRECTIONAL)
2143        if call_id_video_ab is None:
2144            self.log.error("No active video call in PhoneA.")
2145            return False
2146
2147        self.log.info("Step2: Initiate Voice Call PhoneC->PhoneA.")
2148        if not call_setup_teardown(self.log,
2149                                   ads[2],
2150                                   ads[0],
2151                                   None,
2152                                   verify_caller_func=is_phone_in_call_volte,
2153                                   verify_callee_func=None):
2154            self.log.error("Failed to setup a call")
2155            return False
2156
2157        self.log.info(
2158            "Step3: Verify PhoneA's video/voice call in correct state.")
2159        calls = ads[0].droid.telecomCallGetCallIds()
2160        self.log.info("Calls in PhoneA{}".format(calls))
2161        if num_active_calls(self.log, ads[0]) != 2:
2162            self.log.error("Active call numbers in PhoneA is not 2.")
2163            return False
2164        for call in calls:
2165            if call != call_id_video_ab:
2166                call_id_voice_ac = call
2167
2168        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
2169            return False
2170        if not verify_video_call_in_expected_state(
2171                self.log, ads[0], call_id_video_ab,
2172                VT_STATE_BIDIRECTIONAL_PAUSED, CALL_STATE_HOLDING):
2173            return False
2174        if not verify_video_call_in_expected_state(
2175                self.log, ads[0], call_id_voice_ac, VT_STATE_AUDIO_ONLY,
2176                CALL_STATE_ACTIVE):
2177            return False
2178
2179        self.log.info(
2180            "Step4: Swap calls on PhoneA and verify call state correct.")
2181        ads[0].droid.telecomCallHold(call_id_voice_ac)
2182        time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
2183        for ad in [ads[0], ads[1]]:
2184            if get_audio_route(self.log, ad) != AUDIO_ROUTE_SPEAKER:
2185                self.log.error("{} Audio is not on speaker.".format(ad.serial))
2186                # TODO: b/26337892 Define expected audio route behavior.
2187            set_audio_route(self.log, ad, AUDIO_ROUTE_EARPIECE)
2188
2189        time.sleep(WAIT_TIME_IN_CALL)
2190        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
2191            return False
2192        if not verify_video_call_in_expected_state(
2193                self.log, ads[0], call_id_video_ab, VT_STATE_BIDIRECTIONAL,
2194                CALL_STATE_ACTIVE):
2195            return False
2196        if not verify_video_call_in_expected_state(
2197                self.log, ads[0], call_id_voice_ac, VT_STATE_AUDIO_ONLY,
2198                CALL_STATE_HOLDING):
2199            return False
2200
2201        self.log.info("Step5: Disable camera on PhoneA and PhoneB.")
2202        if not video_call_downgrade(self.log, ads[0], call_id_video_ab, ads[1],
2203                                    get_call_id_in_video_state(
2204                                        self.log, ads[1],
2205                                        VT_STATE_BIDIRECTIONAL)):
2206            self.log.error("Failed to disable video on PhoneA.")
2207            return False
2208        if not video_call_downgrade(
2209                self.log, ads[1], get_call_id_in_video_state(
2210                    self.log, ads[1], VT_STATE_TX_ENABLED), ads[0],
2211                call_id_video_ab):
2212            self.log.error("Failed to disable video on PhoneB.")
2213            return False
2214
2215        self.log.info("Step6: Verify calls in correct state.")
2216        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
2217            return False
2218        if not verify_video_call_in_expected_state(
2219                self.log, ads[0], call_id_video_ab, VT_STATE_AUDIO_ONLY,
2220                CALL_STATE_ACTIVE):
2221            return False
2222        if not verify_video_call_in_expected_state(
2223                self.log, ads[0], call_id_voice_ac, VT_STATE_AUDIO_ONLY,
2224                CALL_STATE_HOLDING):
2225            return False
2226
2227        return {False: self._test_vt_conference_merge_drop,
2228                True: self._test_vt_conference_merge_drop_cep}[use_cep](
2229                    ads, call_id_video_ab, call_id_voice_ac)
2230
2231    @TelephonyBaseTest.tel_test_wrap
2232    def test_call_volte_add_mo_video_downgrade_merge_drop(self):
2233        """Conference call
2234
2235        Make Sure PhoneA is in LTE mode (with Video Calling).
2236        Make Sure PhoneB is in LTE mode (with VoLTE).
2237        Make Sure PhoneC is in LTE mode (with Video Calling).
2238        PhoneA VoLTE call to PhoneB. Accept on PhoneB.
2239        PhoneA add a Bi-Directional Video call to PhoneC.
2240        PhoneC accept as Video.
2241        Downgrade Video call on PhoneA and PhoneC to audio only.
2242        Merge call on PhoneA.
2243        Hang up on PhoneB.
2244        Hang up on PhoneC.
2245        """
2246        return self._test_call_volte_add_mo_video_downgrade_merge_drop(False)
2247
2248    @TelephonyBaseTest.tel_test_wrap
2249    def test_call_volte_add_mo_video_downgrade_merge_drop_cep(self):
2250        """Conference call
2251
2252        Make Sure PhoneA is in LTE mode (with Video Calling).
2253        Make Sure PhoneB is in LTE mode (with VoLTE).
2254        Make Sure PhoneC is in LTE mode (with Video Calling).
2255        PhoneA VoLTE call to PhoneB. Accept on PhoneB.
2256        PhoneA add a Bi-Directional Video call to PhoneC.
2257        PhoneC accept as Video.
2258        Downgrade Video call on PhoneA and PhoneC to audio only.
2259        Merge call on PhoneA.
2260        Hang up on PhoneB.
2261        Hang up on PhoneC.
2262        """
2263        return self._test_call_volte_add_mo_video_downgrade_merge_drop(True)
2264
2265    def _test_call_volte_add_mo_video_downgrade_merge_drop(self, use_cep):
2266        ads = self.android_devices
2267        tasks = [(phone_setup_video, (self.log, ads[0])),
2268                 (phone_setup_volte, (self.log, ads[1])), (phone_setup_video,
2269                                                           (self.log, ads[2]))]
2270        if not multithread_func(self.log, tasks):
2271            self.log.error("Phone Failed to Set Up Properly.")
2272            return False
2273
2274        self.log.info("Step1: Initiate VoLTE Call PhoneA->PhoneB.")
2275        if not call_setup_teardown(self.log,
2276                                   ads[0],
2277                                   ads[1],
2278                                   None,
2279                                   verify_caller_func=is_phone_in_call_volte,
2280                                   verify_callee_func=is_phone_in_call_volte):
2281            self.log.error("Failed to setup a call")
2282            return False
2283        calls = ads[0].droid.telecomCallGetCallIds()
2284        self.log.info("Calls in PhoneA{}".format(calls))
2285        if num_active_calls(self.log, ads[0]) != 1:
2286            self.log.error("Active call numbers in PhoneA is not 1.")
2287            return False
2288        call_id_voice_ab = calls[0]
2289
2290        self.log.info("Step2: Initiate Video Call PhoneA->PhoneC.")
2291        if not video_call_setup_teardown(
2292                self.log,
2293                ads[0],
2294                ads[2],
2295                None,
2296                video_state=VT_STATE_BIDIRECTIONAL,
2297                verify_caller_func=is_phone_in_call_video_bidirectional,
2298                verify_callee_func=is_phone_in_call_video_bidirectional):
2299            self.log.error("Failed to setup a call")
2300            return False
2301        call_id_video_ac = get_call_id_in_video_state(self.log, ads[0],
2302                                                      VT_STATE_BIDIRECTIONAL)
2303        if call_id_video_ac is None:
2304            self.log.error("No active video call in PhoneA.")
2305            return False
2306
2307        self.log.info(
2308            "Step3: Verify PhoneA's video/voice call in correct state.")
2309        calls = ads[0].droid.telecomCallGetCallIds()
2310        self.log.info("Calls in PhoneA{}".format(calls))
2311        if num_active_calls(self.log, ads[0]) != 2:
2312            self.log.error("Active call numbers in PhoneA is not 2.")
2313            return False
2314
2315        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
2316            return False
2317        if not verify_video_call_in_expected_state(
2318                self.log, ads[0], call_id_video_ac, VT_STATE_BIDIRECTIONAL,
2319                CALL_STATE_ACTIVE):
2320            return False
2321        if not verify_video_call_in_expected_state(
2322                self.log, ads[0], call_id_voice_ab, VT_STATE_AUDIO_ONLY,
2323                CALL_STATE_HOLDING):
2324            return False
2325
2326        self.log.info("Step4: Disable camera on PhoneA and PhoneC.")
2327        if not video_call_downgrade(self.log, ads[0], call_id_video_ac, ads[2],
2328                                    get_call_id_in_video_state(
2329                                        self.log, ads[2],
2330                                        VT_STATE_BIDIRECTIONAL)):
2331            self.log.error("Failed to disable video on PhoneA.")
2332            return False
2333        if not video_call_downgrade(
2334                self.log, ads[2], get_call_id_in_video_state(
2335                    self.log, ads[2], VT_STATE_TX_ENABLED), ads[0],
2336                call_id_video_ac):
2337            self.log.error("Failed to disable video on PhoneB.")
2338            return False
2339
2340        self.log.info("Step6: Verify calls in correct state.")
2341        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
2342            return False
2343        if not verify_video_call_in_expected_state(
2344                self.log, ads[0], call_id_video_ac, VT_STATE_AUDIO_ONLY,
2345                CALL_STATE_ACTIVE):
2346            return False
2347        if not verify_video_call_in_expected_state(
2348                self.log, ads[0], call_id_voice_ab, VT_STATE_AUDIO_ONLY,
2349                CALL_STATE_HOLDING):
2350            return False
2351
2352        return {False: self._test_vt_conference_merge_drop,
2353                True: self._test_vt_conference_merge_drop_cep}[use_cep](
2354                    ads, call_id_video_ac, call_id_voice_ab)
2355
2356    @TelephonyBaseTest.tel_test_wrap
2357    def test_call_volte_add_mt_video_downgrade_merge_drop(self):
2358        """Conference call
2359
2360        Make Sure PhoneA is in LTE mode (with Video Calling).
2361        Make Sure PhoneB is in LTE mode (with VoLTE).
2362        Make Sure PhoneC is in LTE mode (with Video Calling).
2363        PhoneA VoLTE call to PhoneB. Accept on PhoneB.
2364        PhoneC add a Bi-Directional Video call to PhoneA.
2365        PhoneA accept as Video.
2366        Downgrade Video call on PhoneA and PhoneC to audio only.
2367        Merge call on PhoneA.
2368        Hang up on PhoneB.
2369        Hang up on PhoneC.
2370        """
2371        return self._test_call_volte_add_mt_video_downgrade_merge_drop(False)
2372
2373    @TelephonyBaseTest.tel_test_wrap
2374    def test_call_volte_add_mt_video_downgrade_merge_drop_cep(self):
2375        """Conference call
2376
2377        Make Sure PhoneA is in LTE mode (with Video Calling).
2378        Make Sure PhoneB is in LTE mode (with VoLTE).
2379        Make Sure PhoneC is in LTE mode (with Video Calling).
2380        PhoneA VoLTE call to PhoneB. Accept on PhoneB.
2381        PhoneC add a Bi-Directional Video call to PhoneA.
2382        PhoneA accept as Video.
2383        Downgrade Video call on PhoneA and PhoneC to audio only.
2384        Merge call on PhoneA.
2385        Hang up on PhoneB.
2386        Hang up on PhoneC.
2387        """
2388        return self._test_call_volte_add_mt_video_downgrade_merge_drop(True)
2389
2390    def _test_call_volte_add_mt_video_downgrade_merge_drop(self, use_cep):
2391        # TODO: b/21437650 Test will fail. After established 2nd call ~15s,
2392        # Phone C will drop call.
2393        ads = self.android_devices
2394        tasks = [(phone_setup_video, (self.log, ads[0])),
2395                 (phone_setup_volte, (self.log, ads[1])), (phone_setup_video,
2396                                                           (self.log, ads[2]))]
2397        if not multithread_func(self.log, tasks):
2398            self.log.error("Phone Failed to Set Up Properly.")
2399            return False
2400
2401        self.log.info("Step1: Initiate VoLTE Call PhoneA->PhoneB.")
2402        if not call_setup_teardown(self.log,
2403                                   ads[0],
2404                                   ads[1],
2405                                   None,
2406                                   verify_caller_func=is_phone_in_call_volte,
2407                                   verify_callee_func=is_phone_in_call_volte):
2408            self.log.error("Failed to setup a call")
2409            return False
2410        calls = ads[0].droid.telecomCallGetCallIds()
2411        self.log.info("Calls in PhoneA{}".format(calls))
2412        if num_active_calls(self.log, ads[0]) != 1:
2413            self.log.error("Active call numbers in PhoneA is not 1.")
2414            return False
2415        call_id_voice_ab = calls[0]
2416
2417        self.log.info("Step2: Initiate Video Call PhoneC->PhoneA.")
2418        if not video_call_setup_teardown(
2419                self.log,
2420                ads[2],
2421                ads[0],
2422                None,
2423                video_state=VT_STATE_BIDIRECTIONAL,
2424                verify_caller_func=is_phone_in_call_video_bidirectional,
2425                verify_callee_func=is_phone_in_call_video_bidirectional):
2426            self.log.error("Failed to setup a call")
2427            return False
2428        call_id_video_ac = get_call_id_in_video_state(self.log, ads[0],
2429                                                      VT_STATE_BIDIRECTIONAL)
2430        if call_id_video_ac is None:
2431            self.log.error("No active video call in PhoneA.")
2432            return False
2433
2434        self.log.info(
2435            "Step3: Verify PhoneA's video/voice call in correct state.")
2436        calls = ads[0].droid.telecomCallGetCallIds()
2437        self.log.info("Calls in PhoneA{}".format(calls))
2438        if num_active_calls(self.log, ads[0]) != 2:
2439            self.log.error("Active call numbers in PhoneA is not 2.")
2440            return False
2441
2442        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
2443            return False
2444        if not verify_video_call_in_expected_state(
2445                self.log, ads[0], call_id_video_ac, VT_STATE_BIDIRECTIONAL,
2446                CALL_STATE_ACTIVE):
2447            return False
2448        if not verify_video_call_in_expected_state(
2449                self.log, ads[0], call_id_voice_ab, VT_STATE_AUDIO_ONLY,
2450                CALL_STATE_HOLDING):
2451            return False
2452
2453        self.log.info("Step4: Disable camera on PhoneA and PhoneC.")
2454        if not video_call_downgrade(self.log, ads[0], call_id_video_ac, ads[2],
2455                                    get_call_id_in_video_state(
2456                                        self.log, ads[2],
2457                                        VT_STATE_BIDIRECTIONAL)):
2458            self.log.error("Failed to disable video on PhoneA.")
2459            return False
2460        if not video_call_downgrade(
2461                self.log, ads[2], get_call_id_in_video_state(
2462                    self.log, ads[2], VT_STATE_TX_ENABLED), ads[0],
2463                call_id_video_ac):
2464            self.log.error("Failed to disable video on PhoneB.")
2465            return False
2466
2467        self.log.info("Step6: Verify calls in correct state.")
2468        if not verify_incall_state(self.log, [ads[0], ads[1], ads[2]], True):
2469            return False
2470        if not verify_video_call_in_expected_state(
2471                self.log, ads[0], call_id_video_ac, VT_STATE_AUDIO_ONLY,
2472                CALL_STATE_ACTIVE):
2473            return False
2474        if not verify_video_call_in_expected_state(
2475                self.log, ads[0], call_id_voice_ab, VT_STATE_AUDIO_ONLY,
2476                CALL_STATE_HOLDING):
2477            return False
2478
2479        return {False: self._test_vt_conference_merge_drop,
2480                True: self._test_vt_conference_merge_drop_cep}[use_cep](
2481                    ads, call_id_video_ac, call_id_voice_ab)
2482
2483    @TelephonyBaseTest.tel_test_wrap
2484    def test_disable_data_vt_unavailable(self):
2485        """Disable Data, phone should no be able to make VT call.
2486
2487        Make sure PhoneA and PhoneB can make VT call.
2488        Disable Data on PhoneA.
2489        Make sure phoneA report vt_enabled as false.
2490        Attempt to make a VT call from PhoneA to PhoneB,
2491        Verify the call succeed as Voice call.
2492        """
2493
2494        self.log.info("Step1 Make sure Phones are able make VT call")
2495        ads = self.android_devices
2496        ads[0], ads[1] = ads[1], ads[0]
2497        tasks = [(phone_setup_video, (self.log, ads[0])), (phone_setup_video,
2498                                                           (self.log, ads[1]))]
2499        if not multithread_func(self.log, tasks):
2500            self.log.error("Phone Failed to Set Up Properly.")
2501            return False
2502
2503        try:
2504            self.log.info("Step2 Turn off data and verify not connected.")
2505            ads[0].droid.telephonyToggleDataConnection(False)
2506            if verify_http_connection(self.log, ads[0]):
2507                self.log.error("Internet Accessible when Disabled")
2508                return False
2509
2510            self.log.info("Step3 Verify vt_enabled return false.")
2511            if wait_for_video_enabled(self.log, ads[0],
2512                                      MAX_WAIT_TIME_VOLTE_ENABLED):
2513                self.log.error(
2514                    "{} failed to <report vt enabled false> for {}s."
2515                    .format(ads[0].serial, MAX_WAIT_TIME_VOLTE_ENABLED))
2516                return False
2517            self.log.info(
2518                "Step4 Attempt to make VT call, verify call is AUDIO_ONLY.")
2519            if not video_call_setup_teardown(
2520                    self.log,
2521                    ads[0],
2522                    ads[1],
2523                    ads[0],
2524                    video_state=VT_STATE_BIDIRECTIONAL,
2525                    verify_caller_func=is_phone_in_call_voice_hd,
2526                    verify_callee_func=is_phone_in_call_voice_hd):
2527                self.log.error("Call failed or is not AUDIO_ONLY")
2528                return False
2529
2530        finally:
2531            ads[0].droid.telephonyToggleDataConnection(True)
2532
2533        return True
2534
2535
2536""" Tests End """
2537