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