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