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