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