1#!/usr/bin/env python3.4
2#
3#   Copyright 2020 - 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 5G Voice scenarios
18"""
19
20import time
21
22from acts import signals
23from acts.utils import adb_shell_ping
24from acts.test_decorators import test_tracker_info
25from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
26from acts_contrib.test_utils.tel.loggers.telephony_metric_logger import TelephonyMetricLogger
27from acts_contrib.test_utils.tel.loggers.protos.telephony_metric_pb2 import TelephonyVoiceTestResult
28from acts_contrib.test_utils.tel.tel_defines import DIRECTION_MOBILE_ORIGINATED
29from acts_contrib.test_utils.tel.tel_defines import DIRECTION_MOBILE_TERMINATED
30from acts_contrib.test_utils.tel.tel_defines import GEN_5G
31from acts_contrib.test_utils.tel.tel_defines import TOTAL_LONG_CALL_DURATION
32from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_ANDROID_STATE_SETTLING
33from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_IN_CALL_FOR_IMS
34from acts_contrib.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED
35from acts_contrib.test_utils.tel.tel_defines import WFC_MODE_WIFI_ONLY
36from acts_contrib.test_utils.tel.tel_test_utils import call_setup_teardown
37from acts_contrib.test_utils.tel.tel_test_utils import \
38    call_voicemail_erase_all_pending_voicemail
39from acts_contrib.test_utils.tel.tel_test_utils import ensure_phones_idle
40from acts_contrib.test_utils.tel.tel_test_utils import get_mobile_data_usage
41from acts_contrib.test_utils.tel.tel_test_utils import hangup_call
42from acts_contrib.test_utils.tel.tel_test_utils import is_phone_in_call_active
43from acts_contrib.test_utils.tel.tel_test_utils import multithread_func
44from acts_contrib.test_utils.tel.tel_test_utils import remove_mobile_data_usage_limit
45from acts_contrib.test_utils.tel.tel_test_utils import set_mobile_data_usage_limit
46from acts_contrib.test_utils.tel.tel_voice_utils import _test_call_long_duration
47from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_2g
48from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_3g
49from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_csfb
50from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_iwlan
51from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
52from acts_contrib.test_utils.tel.tel_voice_utils import phone_idle_2g
53from acts_contrib.test_utils.tel.tel_voice_utils import phone_idle_csfb
54from acts_contrib.test_utils.tel.tel_voice_utils import phone_idle_iwlan
55from acts_contrib.test_utils.tel.tel_voice_utils import phone_idle_volte
56from acts_contrib.test_utils.tel.tel_voice_utils import phone_setup_call_hold_unhold_test
57from acts_contrib.test_utils.tel.tel_voice_utils import phone_setup_csfb
58from acts_contrib.test_utils.tel.tel_voice_utils import phone_setup_iwlan
59from acts_contrib.test_utils.tel.tel_voice_utils import phone_setup_voice_2g
60from acts_contrib.test_utils.tel.tel_voice_utils import phone_setup_voice_3g
61from acts_contrib.test_utils.tel.tel_voice_utils import phone_setup_voice_general
62from acts_contrib.test_utils.tel.tel_voice_utils import phone_setup_volte
63from acts_contrib.test_utils.tel.tel_voice_utils import two_phone_call_leave_voice_mail
64from acts_contrib.test_utils.tel.tel_voice_utils import two_phone_call_long_seq
65from acts_contrib.test_utils.tel.tel_voice_utils import two_phone_call_short_seq
66from acts_contrib.test_utils.tel.tel_5g_utils import is_current_network_5g_nsa
67from acts_contrib.test_utils.tel.tel_5g_test_utils import provision_both_devices_for_volte
68from acts_contrib.test_utils.tel.tel_5g_test_utils import provision_device_for_5g
69from acts_contrib.test_utils.tel.tel_5g_test_utils import set_preferred_mode_for_5g
70from acts_contrib.test_utils.tel.tel_5g_test_utils import verify_5g_attach_for_both_devices
71from acts_contrib.test_utils.tel.tel_5g_test_utils import disable_apm_mode_both_devices
72from acts_contrib.test_utils.tel.tel_data_utils import call_epdg_to_epdg_wfc
73from acts_contrib.test_utils.tel.tel_data_utils import test_call_setup_in_active_data_transfer
74from acts_contrib.test_utils.tel.tel_data_utils import test_call_setup_in_active_youtube_video
75from acts_contrib.test_utils.tel.tel_data_utils import wifi_cell_switching
76from acts_contrib.test_utils.tel.tel_data_utils import test_wifi_cell_switching_in_call
77CallResult = TelephonyVoiceTestResult.CallResult.Value
78
79
80class Nsa5gVoiceTest(TelephonyBaseTest):
81    def setup_class(self):
82        super().setup_class()
83        self.number_of_devices = 2
84        self.message_lengths = (50, 160, 180)
85        self.tel_logger = TelephonyMetricLogger.for_test_case()
86        self.stress_test_number = self.get_stress_test_number()
87        self.long_call_duration = self.user_params.get(
88            "long_call_duration",
89            TOTAL_LONG_CALL_DURATION)
90
91    def setup_test(self):
92        TelephonyBaseTest.setup_test(self)
93
94    def teardown_test(self):
95        ensure_phones_idle(self.log, self.android_devices)
96
97    """ Tests Begin """
98
99    @test_tracker_info(uuid="1bef3da1-4608-4b0e-8b78-f3f7be0115d5")
100    @TelephonyBaseTest.tel_test_wrap
101    def test_5g_nsa_call_volte_to_volte(self):
102        """ 5g nsa volte to volte call test
103
104        1. Make sure PhoneA is in nsa5g mode (with volte).
105        2. Make sure PhoneB is in nsa5g mode (with volte).
106        3. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneA.
107        4. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneB.
108        5. Verify both PhoneA and PhoneB gets attached back to nsa5g
109
110        Raises:
111            TestFailure if not success.
112        """
113        ads = self.android_devices
114        if not provision_both_devices_for_volte(self.log, ads):
115            return False
116
117        if not provision_device_for_5g(self.log, ads):
118            return False
119
120        # VoLTE calls
121        result = two_phone_call_short_seq(
122            self.log, ads[0], None, is_phone_in_call_volte, ads[1],
123            None, is_phone_in_call_volte, None,
124            WAIT_TIME_IN_CALL_FOR_IMS)
125        if not result:
126            self.log.error("Failure is volte call during 5g nsa")
127            return False
128
129        if not verify_5g_attach_for_both_devices(self.log, ads):
130            return False
131
132        self.log.info("PASS - volte test over 5g nsa validated")
133        return True
134
135    @test_tracker_info(uuid="3df252a4-308a-49c3-8e37-08e9c4e8efef")
136    @TelephonyBaseTest.tel_test_wrap
137    def test_5g_nsa_call_volte_to_3g(self):
138        """ 5g nsa volte to 3g call test
139
140        1. Make sure PhoneA is in nsa5g mode (with volte).
141        2. Make sure PhoneB is in 3g mode.
142        3. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneA.
143        4. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneB.
144        5. Verify both PhoneA and PhoneB gets attached back to nsa5g
145
146        Raises:
147            TestFailure if not success.
148        """
149        ads = self.android_devices
150
151        # LTE attach
152        tasks = [(phone_setup_volte, (self.log, ads[0])),
153                 (phone_setup_voice_3g, (self.log, ads[1]))]
154        if not multithread_func(self.log, tasks):
155            self.log.error("Phone failed to set up in volte/3g")
156            return False
157
158        if not provision_device_for_5g(self.log, ads[0]):
159            return False
160
161        # VoLTE to 3G
162        result = two_phone_call_short_seq(
163            self.log, ads[0], None, is_phone_in_call_volte, ads[1],
164            None, is_phone_in_call_3g, None,
165            WAIT_TIME_IN_CALL_FOR_IMS)
166        if not result:
167            self.log.error("Failure is volte to 3g call during 5g nsa")
168            return False
169
170        # Attach nsa5g
171        if not is_current_network_5g_nsa(ads[0]):
172            ads[0].log.error("Phone not attached on 5g nsa after call end.")
173            return False
174
175        self.log.info("PASS - VoLTE to 3g over 5g nsa validated")
176        return True
177
178
179    @test_tracker_info(uuid="3a8147d6-c136-42cb-92ca-2023b8eed85e")
180    @TelephonyBaseTest.tel_test_wrap
181    def test_5g_nsa_call_volte_mo_hold_unhold(self):
182        """ 5g nsa volte mo hold unhold test
183
184        1. Make sure PhoneA is in nsa 5g (with volte)
185        2. Make sure PhoneB is in nsa 5g (with volte)
186        3. Call from PhoneA to PhoneB, accept on PhoneB
187        4. Make sure PhoneA/B are in call
188        5. Hold and unhold on PhoneA
189        6. Verify both PhoneA and PhoneB gets attached back to nsa5g
190
191        Raises:
192            TestFailure if not success.
193        """
194        ads = self.android_devices
195        if not provision_both_devices_for_volte(self.log, ads):
196            return False
197
198        if not provision_device_for_5g(self.log, ads):
199            return False
200
201        if not phone_setup_call_hold_unhold_test(self.log,
202                                                 ads,
203                                                 DIRECTION_MOBILE_ORIGINATED,
204                                                 caller_func=is_phone_in_call_volte):
205            return False
206
207        if not verify_5g_attach_for_both_devices(self.log, ads):
208            return False
209        return True
210
211    @test_tracker_info(uuid="1825f9d9-dcf1-4407-922d-3f218d5b8932")
212    @TelephonyBaseTest.tel_test_wrap
213    def test_5g_nsa_call_volte_mt_hold_unhold(self):
214        """ 5g nsa volte mt hold unhold test
215
216        1. Make sure PhoneA is in nsa 5g (with volte)
217        2. Make sure PhoneB is in nsa 5g (with volte)
218        3. Call from PhoneB to PhoneA, accept on PhoneA
219        4. Make sure PhoneA/B are in call
220        5. Hold and unhold on PhoneA
221        6. Verify both PhoneA and PhoneB gets attached back to nsa5g
222
223        Raises:
224            TestFailure if not success.
225        """
226        ads = self.android_devices
227        if not provision_both_devices_for_volte(self.log, ads):
228            return False
229
230        if not provision_device_for_5g(self.log, ads):
231            return False
232
233        if not phone_setup_call_hold_unhold_test(self.log,
234                                                 ads,
235                                                 DIRECTION_MOBILE_TERMINATED,
236                                                 callee_func=is_phone_in_call_volte):
237            return False
238
239        if not verify_5g_attach_for_both_devices(self.log, ads):
240            return False
241        return True
242
243
244    @test_tracker_info(uuid="c082a9b0-fb66-4d3a-9fdd-1ce5710624be")
245    @TelephonyBaseTest.tel_test_wrap
246    def test_5g_nsa_call_mo_volte_in_active_data_transfer(self):
247        """Test call can be established during active data connection in 5G NSA.
248
249        Turn off airplane mode, disable WiFi, enable Cellular Data.
250        Make sure phone in 5G NSA.
251        Starting downloading file from Internet.
252        Initiate a MO voice call. Verify call can be established.
253        Hangup Voice Call, verify file is downloaded successfully.
254        Note: file download will be suspended when call is initiated if voice
255              is using voice channel and voice channel and data channel are
256              on different RATs.
257
258        Returns:
259            True if success.
260            False if failed.
261        """
262        ads = self.android_devices
263        if not phone_setup_volte(self.log, ads[0]):
264            ads[0].log.error("failed to setup volte")
265            return False
266        return test_call_setup_in_active_data_transfer(self.log,
267                                                       ads,
268                                                       GEN_5G,
269                                                       DIRECTION_MOBILE_ORIGINATED)
270
271
272    @test_tracker_info(uuid="aaa98e51-0bde-472a-abc3-5dc180f56a08")
273    @TelephonyBaseTest.tel_test_wrap
274    def test_5g_nsa_call_mt_volte_in_active_data_transfer(self):
275        """Test call can be established during active data connection in 5G NSA.
276
277        Turn off airplane mode, disable WiFi, enable Cellular Data.
278        Make sure phone in 5G NSA.
279        Starting downloading file from Internet.
280        Initiate a MT voice call. Verify call can be established.
281        Hangup Voice Call, verify file is downloaded successfully.
282        Note: file download will be suspended when call is initiated if voice
283              is using voice channel and voice channel and data channel are
284              on different RATs.
285
286        Returns:
287            True if success.
288            False if failed.
289        """
290        ads = self.android_devices
291        if not phone_setup_volte(self.log, ads[0]):
292            ads[0].log.error("failed to setup volte")
293            return False
294        return test_call_setup_in_active_data_transfer(self.log,
295                                                       ads,
296                                                       GEN_5G,
297                                                       DIRECTION_MOBILE_TERMINATED)
298
299
300    @test_tracker_info(uuid="3a607dee-7e92-4567-8ca0-05099590b773")
301    @TelephonyBaseTest.tel_test_wrap
302    def test_5g_nsa_volte_in_call_wifi_toggling(self):
303        """ Test data connection network switching during VoLTE call in 5G NSA.
304
305        1. Make Sure PhoneA in VoLTE.
306        2. Make Sure PhoneB in VoLTE.
307        3. Make sure Phones are in 5G NSA
308        4. Call from PhoneA to PhoneB.
309        5. Toggling Wifi connection in call.
310        6. Verify call is active.
311        7. Hung up the call on PhoneA
312        8. Make sure Phones are in 5G NSA
313
314        Returns:
315            True if pass; False if fail.
316        """
317        ads = self.android_devices
318        result = True
319        if not provision_both_devices_for_volte(self.log, ads):
320            return False
321
322        time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
323
324        if not provision_device_for_5g(self.log, ads):
325            return False
326
327        if not verify_5g_attach_for_both_devices(self.log, ads):
328            self.log.error("Phone not attached on 5G NSA before call.")
329            return False
330
331        if not call_setup_teardown(self.log, ads[0], ads[1], None, None, None,
332                                   5):
333            self.log.error("Call setup failed")
334            return False
335        else:
336            self.log.info("Call setup succeed")
337
338        if not wifi_cell_switching(self.log, ads[0], None, self.wifi_network_ssid,
339                                   self.wifi_network_pass):
340            ads[0].log.error("Failed to do WIFI and Cell switch in call")
341            result = False
342
343        if not is_phone_in_call_active(ads[0]):
344            return False
345        else:
346            if not ads[0].droid.telecomCallGetAudioState():
347                ads[0].log.error("Audio is not on call")
348                result = False
349            else:
350                ads[0].log.info("Audio is on call")
351            hangup_call(self.log, ads[0])
352
353            time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
354
355            if not verify_5g_attach_for_both_devices(self.log, ads):
356                self.log.error("Phone not attached on 5G NSA after call.")
357                return False
358            return result
359
360
361    @test_tracker_info(uuid="96b7d8c9-d32a-4abf-8326-6b060d116ac2")
362    @TelephonyBaseTest.tel_test_wrap
363    def test_5g_nsa_call_epdg_to_epdg_wfc_wifi_preferred(self):
364        """ WiFi Preferred, WiFi calling to WiFi Calling test on 5G NSA
365
366        1. Setup PhoneA WFC mode: WIFI_PREFERRED, APM off.
367        2. Setup PhoneB WFC mode: WIFI_PREFERRED, APM off .
368        3. Set PhoneA/PhoneB on 5G NSA
369        4. Make sure PhoneA/PhoneB on 5G NSA before testing
370        5. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneA.
371        6. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneB.
372        7. Make sure PhoneA/PhoneB on 5G NSA after testing
373
374        Returns:
375            True if pass; False if fail.
376        """
377        return call_epdg_to_epdg_wfc(self.log,
378                                     self.android_devices,
379                                     False,
380                                     WFC_MODE_WIFI_PREFERRED,
381                                     self.wifi_network_ssid,
382                                     self.wifi_network_pass,
383                                     GEN_5G)
384
385
386    @test_tracker_info(uuid="29fa7f44-8d6a-4948-8178-33c9a9aab334")
387    @TelephonyBaseTest.tel_test_wrap
388    def test_5g_nsa_call_mo_volte_in_active_youtube(self):
389        """Test call can be established during active youtube video on 5G NSA.
390
391        1. Enable VoLTE on PhoneA.
392        2. Set up PhoneA on 5G NSA.
393        3. Make sure phoneA is on 5G NSA.
394        4. Starting an youtube video.
395        5. Initiate a MO voice call. Verify call can be established.
396        6. Make sure phoneA is on 5G NSA.
397
398        Returns:
399            True if success.
400            False if failed.
401        """
402        ads = self.android_devices
403        if not phone_setup_volte(self.log, ads[0]):
404            ads[0].log.error("Failed to setup VoLTE")
405            return False
406        return test_call_setup_in_active_youtube_video(self.log,
407                                                       ads,
408                                                       GEN_5G,
409                                                       DIRECTION_MOBILE_ORIGINATED)
410
411    @test_tracker_info(uuid="4e138477-3536-48bd-ab8a-7fb7c228b3e6")
412    @TelephonyBaseTest.tel_test_wrap
413    def test_5g_nsa_call_mt_volte_in_active_youtube(self):
414        """Test call can be established during active youtube video on 5G NSA.
415
416        1. Enable VoLTE on PhoneA.
417        2. Set up PhoneA on 5G NSA.
418        3. Make sure phoneA is on 5G NSA.
419        4. Starting an youtube video.
420        5. Initiate a MT voice call. Verify call can be established.
421        6. Make sure phoneA is on 5G NSA.
422
423        Returns:
424            True if success.
425            False if failed.
426        """
427        ads = self.android_devices
428        if not phone_setup_volte(self.log, ads[0]):
429            ads[0].log.error("Failed to setup VoLTE")
430            return False
431        return test_call_setup_in_active_youtube_video(self.log,
432                                                       ads,
433                                                       GEN_5G,
434                                                       DIRECTION_MOBILE_TERMINATED)
435
436
437    @test_tracker_info(uuid="0d477f6f-3464-4b32-a5e5-0fd134f2753d")
438    @TelephonyBaseTest.tel_test_wrap
439    def test_5g_nsa_call_mo_vowifi_in_active_data_transfer(self):
440        """Test MO voice wifi call can be established during active data connection on 5G NSA.
441
442        1. Turn off airplane mode, turn on wfc and wifi on phoneA.
443        2. Set PhoneA on 5G NSA
444        3. Make sure PhoneA on 5G NSA before testing
445        4. Starting downloading file from Internet.
446        5. Initiate a MO voice call. Verify call can be established.
447        6. Hangup Voice Call, verify file is downloaded successfully.
448        7. Make sure PhoneA on 5G NSA after testing
449
450        Returns:
451            True if success.
452            False if failed.
453        """
454        ads = self.android_devices
455        if not phone_setup_iwlan(self.log, ads[0], False,
456                                 WFC_MODE_WIFI_PREFERRED,
457                                 self.wifi_network_ssid,
458                                 self.wifi_network_pass):
459            ads[0].log.error(
460                "Failed to setup iwlan with APM off and WIFI and WFC on")
461            return False
462
463        return test_call_setup_in_active_data_transfer(self.log,
464                                                       ads,
465                                                       GEN_5G,
466                                                       DIRECTION_MOBILE_ORIGINATED)
467
468
469    @test_tracker_info(uuid="4d1d7dd9-b373-4361-8301-8517ef77b57b")
470    @TelephonyBaseTest.tel_test_wrap
471    def test_5g_nsa_call_mt_vowifi_in_active_data_transfer(self):
472        """Test MT voice wifi call can be established during active data connection on 5G NSA.
473
474        1. Turn off airplane mode, turn on wfc and wifi on phoneA.
475        2. Set PhoneA on 5G NSA
476        3. Make sure PhoneA on 5G NSA before testing
477        4. Starting downloading file from Internet.
478        5. Initiate a MT voice call. Verify call can be established.
479        6. Hangup Voice Call, verify file is downloaded successfully.
480        7. Make sure PhoneA on 5G NSA after testing
481
482        Returns:
483            True if success.
484            False if failed.
485        """
486        ads = self.android_devices
487        if not phone_setup_iwlan(self.log, ads[0], False,
488                                 WFC_MODE_WIFI_PREFERRED,
489                                 self.wifi_network_ssid,
490                                 self.wifi_network_pass):
491            ads[0].log.error(
492                "Failed to setup iwlan with APM off and WIFI and WFC on")
493            return False
494
495        return test_call_setup_in_active_data_transfer(self.log,
496                                                       ads,
497                                                       GEN_5G,
498                                                       DIRECTION_MOBILE_TERMINATED)
499
500
501    @test_tracker_info(uuid="e360bc3a-96b3-4fdf-9bf3-fe3aa08b1af5")
502    @TelephonyBaseTest.tel_test_wrap
503    def test_5g_nsa_call_epdg_mo_hold_unhold_wfc_wifi_preferred(self):
504        """ WiFi Preferred, WiFi calling MO call hold/unhold test on 5G NSA
505
506        1. Setup PhoneA WFC mode: WIFI_PREFERRED.
507        2. Set preferred network of phoneA on 5G NSA
508        3. Verify phoneA is on 5G NSA.
509        4. Call from PhoneA to PhoneB, accept on PhoneB.
510        5. Hold and unhold on PhoneA.
511        6. Verify phoneA is on 5G NSA.
512
513        Returns:
514            True if pass; False if fail.
515        """
516        ads = self.android_devices
517        if not phone_setup_iwlan(self.log, ads[0], False,
518                                 WFC_MODE_WIFI_PREFERRED,
519                                 self.wifi_network_ssid,
520                                 self.wifi_network_pass):
521            ads[0].log.error(
522                "Failed to setup iwlan with APM off and WIFI and WFC on")
523            return False
524
525        if not provision_device_for_5g(self.log, ads[0]):
526            return False
527
528        if not phone_setup_call_hold_unhold_test(self.log,
529                                                 ads,
530                                                 DIRECTION_MOBILE_ORIGINATED,
531                                                 caller_func=is_phone_in_call_iwlan):
532            return False
533
534        if not is_current_network_5g_nsa(ads[0]):
535            ads[0].log.error("Phone not attached on 5G NSA after call.")
536            return False
537        return True
538
539
540    @test_tracker_info(uuid="d2335c83-87ec-4a0e-97a8-b53f769b0d21")
541    @TelephonyBaseTest.tel_test_wrap
542    def test_5g_nsa_call_epdg_mt_hold_unhold_wfc_wifi_preferred(self):
543        """ WiFi Preferred, WiFi calling MT call hold/unhold test on 5G NSA
544
545        1. Setup PhoneA WFC mode: WIFI_PREFERRED.
546        2. Set preferred network of phoneA on 5G NSA
547        3. Verify if phoneA is on 5G NSA.
548        4. Call from PhoneB to PhoneA, accept on PhoneA.
549        5. Hold and unhold on PhoneA.
550        6. Verify if phoneA is on 5G NSA.
551
552        Returns:
553            True if pass; False if fail.
554        """
555        ads = self.android_devices
556        if not phone_setup_iwlan(self.log, ads[0], False,
557                                 WFC_MODE_WIFI_PREFERRED,
558                                 self.wifi_network_ssid,
559                                 self.wifi_network_pass):
560            ads[0].log.error(
561                "Failed to setup iwlan with APM off and WIFI and WFC on")
562            return False
563
564        if not provision_device_for_5g(self.log, ads[0]):
565            return False
566
567        if not phone_setup_call_hold_unhold_test(self.log,
568                                                 ads,
569                                                 DIRECTION_MOBILE_TERMINATED,
570                                                 callee_func=is_phone_in_call_iwlan):
571            return False
572
573        if not is_current_network_5g_nsa(ads[0]):
574            ads[0].log.error("Phone not attached on 5G NSA after call.")
575            return False
576        return True
577
578
579    @test_tracker_info(uuid="03dc3296-5f2f-4141-b2e5-bb0d8ea6ffec")
580    @TelephonyBaseTest.tel_test_wrap
581    def test_5g_nsa_call_volte_to_csfb_3g(self):
582        """ VoLTE nsa 5G to CSFB 3G call test
583
584        1. Make Sure PhoneA is in nsa 5G mode (with VoLTE).
585        2. Make Sure PhoneB is in CSFB mode (without VoLTE).
586        3. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneA.
587        4. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneB.
588
589        Raises:
590            TestFailure if not success.
591        """
592        ads = self.android_devices
593
594        tasks = [(phone_setup_volte, (self.log, ads[0])), (phone_setup_csfb,
595                                                           (self.log, ads[1]))]
596        if not multithread_func(self.log, tasks):
597            self.log.error("Phone failed to set up in VoLTE/CSFB")
598            return False
599
600        if not provision_device_for_5g(self.log, ads[0]):
601            return False
602
603        result = two_phone_call_short_seq(
604            self.log, ads[0], None, is_phone_in_call_volte, ads[1],
605            phone_idle_csfb, is_phone_in_call_csfb, None)
606        self.tel_logger.set_result(result.result_value)
607        if not result:
608            raise signals.TestFailure("Failed",
609                extras={"fail_reason": str(result.result_value)})
610
611
612    @test_tracker_info(uuid="1955604b-5b81-4b06-b846-ba55b46ea997")
613    @TelephonyBaseTest.tel_test_wrap
614    def test_5g_nsa_call_volte_to_2g(self):
615        """ nsa 5G to 2G call test (with VoLTE)
616
617        1. Make Sure PhoneA is in nsa 5G mode (with VoLTE).
618        2. Make Sure PhoneB is in 2G mode.
619        3. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneA.
620        4. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneB.
621
622        Raises:
623            TestFailure if not success.
624        """
625        ads = self.android_devices
626
627        tasks = [(phone_setup_volte, (self.log, ads[0])),
628                 (phone_setup_voice_2g, (self.log, ads[1]))]
629        if not multithread_func(self.log, tasks):
630            self.log.error("Phone failed to set up in VoLTE/2G")
631            return False
632
633        if not provision_device_for_5g(self.log, ads[0]):
634            return False
635
636        result = two_phone_call_short_seq(
637            self.log, ads[0], None, is_phone_in_call_volte, ads[1],
638            phone_idle_2g, is_phone_in_call_2g, None)
639        self.tel_logger.set_result(result.result_value)
640        if not result:
641            raise signals.TestFailure("Failed",
642                extras={"fail_reason": str(result.result_value)})
643
644
645    @test_tracker_info(uuid="547d0b7e-8130-4166-bd57-af8257d5d0c4")
646    @TelephonyBaseTest.tel_test_wrap
647    def test_5g_nsa_call_epdg_to_volte_wfc_wifi_preferred(self):
648        """ WiFi Preferred, WiFi calling to nsa5g VoLTE test
649
650        1. Setup PhoneA WFC mode: WIFI_PREFERRED.
651        2. Make Sure PhoneB is in nsa5G mode (with VoLTE enabled).
652        3. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneA.
653        4. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneB.
654
655        Raises:
656            TestFailure if not success.
657        """
658        ads = self.android_devices
659        tasks = [(phone_setup_iwlan,
660                  (self.log, ads[0], False, WFC_MODE_WIFI_PREFERRED,
661                   self.wifi_network_ssid, self.wifi_network_pass)),
662                 (phone_setup_volte, (self.log, ads[1]))]
663
664        if not multithread_func(self.log, tasks):
665            self.log.error("Phone failed to set up in VoLTE")
666            return False
667
668        if not provision_device_for_5g(self.log, ads[1]):
669            return False
670
671        result = two_phone_call_short_seq(
672            self.log, ads[0], phone_idle_iwlan, is_phone_in_call_iwlan, ads[1],
673            None, is_phone_in_call_volte, None,
674            WAIT_TIME_IN_CALL_FOR_IMS)
675        self.tel_logger.set_result(result.result_value)
676        if not result:
677            raise signals.TestFailure("Failed",
678                extras={"fail_reason": str(result.result_value)})
679
680
681    @test_tracker_info(uuid="119b54f8-fe4f-4158-baa3-c869a7ce12b9")
682    @TelephonyBaseTest.tel_test_wrap
683    def test_5g_nsa_call_epdg_to_volte_apm_wfc_wifi_only(self):
684        """ Airplane + WiFi Only, WiFi calling to nsa5g VoLTE test
685
686        1. Setup PhoneA in airplane mode, WFC mode: WIFI_ONLY.
687        2. Make Sure PhoneB is in nsa 5G mode (with VoLTE enabled).
688        3. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneA.
689        4. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneB.
690
691        Raises:
692            TestFailure if not success.
693        """
694        ads = self.android_devices
695        tasks = [(phone_setup_iwlan,
696                  (self.log, ads[0], True, WFC_MODE_WIFI_ONLY,
697                   self.wifi_network_ssid, self.wifi_network_pass)),
698                 (phone_setup_volte, (self.log, ads[1]))]
699
700        if not multithread_func(self.log, tasks):
701            self.log.error("Phone failed to set up in VoLTE")
702            return False
703
704        if not provision_device_for_5g(self.log, ads[1]):
705            return False
706
707        result = two_phone_call_short_seq(
708            self.log, ads[0], phone_idle_iwlan, is_phone_in_call_iwlan, ads[1],
709            None, is_phone_in_call_volte, None,
710            WAIT_TIME_IN_CALL_FOR_IMS)
711        self.tel_logger.set_result(result.result_value)
712        if not result:
713            raise signals.TestFailure("Failed",
714                extras={"fail_reason": str(result.result_value)})
715
716
717    @test_tracker_info(uuid="cb2eac2b-fc48-409d-bff2-a06849d6cd1a")
718    @TelephonyBaseTest.tel_test_wrap
719    def test_5g_nsa_call_epdg_to_volte_apm_wfc_wifi_preferred(self):
720        """ Airplane + WiFi Preferred, WiFi calling to nsa5g VoLTE test
721
722        1. Setup PhoneA in airplane mode, WFC mode: WIFI_PREFERRED.
723        2. Make Sure PhoneB is in nsa 5G mode (with VoLTE enabled).
724        3. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneA.
725        4. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneB.
726
727        Raises:
728            TestFailure if not success.
729        """
730        ads = self.android_devices
731        tasks = [(phone_setup_iwlan,
732                  (self.log, ads[0], True, WFC_MODE_WIFI_PREFERRED,
733                   self.wifi_network_ssid, self.wifi_network_pass)),
734                 (phone_setup_volte, (self.log, ads[1]))]
735
736        if not multithread_func(self.log, tasks):
737            self.log.error("Phone failed to set up in VoLTE")
738            return False
739
740        if not provision_device_for_5g(self.log, ads[1]):
741            return False
742
743        result = two_phone_call_short_seq(
744            self.log, ads[0], phone_idle_iwlan, is_phone_in_call_iwlan, ads[1],
745            None, is_phone_in_call_volte, None,
746            WAIT_TIME_IN_CALL_FOR_IMS)
747        self.tel_logger.set_result(result.result_value)
748        if not result:
749            raise signals.TestFailure("Failed",
750                extras={"fail_reason": str(result.result_value)})
751
752
753    @test_tracker_info(uuid="c06d6c81-ce26-474d-b41e-fcfe1ec6e761")
754    @TelephonyBaseTest.tel_test_wrap
755    def test_5g_nsa_call_volte_to_volte_long(self):
756        """ VoLTE to nsa 5G VoLTE call test
757
758        1. Make Sure PhoneA is in LTE mode (with VoLTE).
759        2. Make Sure PhoneB is in nsa 5G mode (with VoLTE).
760        3. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneA.
761        4. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneB.
762        5. Call from PhoneB to PhoneA, accept on PhoneA, hang up on PhoneB.
763        6. Call from PhoneB to PhoneA, accept on PhoneA, hang up on PhoneA.
764
765        Raises:
766            TestFailure if not success.
767        """
768        ads = self.android_devices
769        if not provision_both_devices_for_volte(self.log, ads):
770            return False
771
772        if not provision_device_for_5g(self.log, ads[1]):
773            return False
774
775        result = two_phone_call_long_seq(
776            self.log, ads[0], phone_idle_volte, is_phone_in_call_volte, ads[1],
777            None, is_phone_in_call_volte, None,
778            WAIT_TIME_IN_CALL_FOR_IMS)
779        self.tel_logger.set_result(result.result_value)
780        if not result:
781            raise signals.TestFailure("Failed",
782                extras={"fail_reason": str(result.result_value)})
783
784
785    @test_tracker_info(uuid="3c45ab10-9e8c-4804-9f32-c775baa3d5e7")
786    @TelephonyBaseTest.tel_test_wrap
787    def test_5g_nsa_call_volte_to_volte_loop(self):
788        """ Stress test: VoLTE to nsa 5g VoLTE call test
789
790        1. Make Sure PhoneA is in LTE mode (with VoLTE).
791        2. Make Sure PhoneB is in nsa 5G mode (with VoLTE).
792        3. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneA.
793        4. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneB.
794        5. Call from PhoneB to PhoneA, accept on PhoneA, hang up on PhoneB.
795        6. Call from PhoneB to PhoneA, accept on PhoneA, hang up on PhoneA.
796        7. Repeat step 3~6.
797
798        Returns:
799            True if pass; False if fail.
800        """
801
802        MINIMUM_SUCCESS_RATE = .95
803        ads = self.android_devices
804
805        if not provision_both_devices_for_volte(self.log, ads):
806            return False
807
808        if not provision_device_for_5g(self.log, ads[1]):
809            return False
810
811        success_count = 0
812        fail_count = 0
813
814        for i in range(1, self.stress_test_number + 1):
815
816            if two_phone_call_long_seq(
817                    self.log, ads[0], phone_idle_volte, is_phone_in_call_volte,
818                    ads[1], None, is_phone_in_call_volte, None,
819                    WAIT_TIME_IN_CALL_FOR_IMS):
820                success_count += 1
821                result_str = "Succeeded"
822
823            else:
824                fail_count += 1
825                result_str = "Failed"
826
827            self.log.info("Iteration %s %s. Current: %s / %s passed.", i,
828                          result_str, success_count, self.stress_test_number)
829
830        self.log.info("Final Count - Success: %s, Failure: %s - %s%",
831                      success_count, fail_count,
832                      str(100 * success_count / (success_count + fail_count)))
833        if success_count / (
834                success_count + fail_count) >= MINIMUM_SUCCESS_RATE:
835            return True
836        else:
837            return False
838
839
840    @test_tracker_info(uuid="875292c8-14f8-43aa-8770-3d0099da9c53")
841    @TelephonyBaseTest.tel_test_wrap
842    def test_5g_nsa_call_voicemail_indicator_volte(self):
843        """Test Voice Mail notification in nsa 5G (VoLTE enabled).
844        This script currently only works for TMO now.
845
846        1. Make sure DUT (ads[0]) in nsa 5g VoLTE mode. Both PhoneB and DUT idle.
847        2. Make call from PhoneB to DUT, reject on DUT.
848        3. On PhoneB, leave a voice mail to DUT.
849        4. Verify DUT receive voice mail notification.
850
851        Returns:
852            True if pass; False if fail.
853        """
854        ads = self.android_devices
855
856        tasks = [(phone_setup_voice_general, (self.log, ads[1])),
857                 (phone_setup_volte, (self.log, ads[0]))]
858        if not multithread_func(self.log, tasks):
859            self.log.error("Phone Failed to Set Up Properly.")
860            return False
861
862        if not provision_device_for_5g(self.log, ads[0]):
863            return False
864
865        if not call_voicemail_erase_all_pending_voicemail(self.log, ads[0]):
866            self.log.error("Failed to clear voice mail.")
867            return False
868
869        return two_phone_call_leave_voice_mail(self.log, ads[1], None, None,
870                                               ads[0], phone_idle_volte)
871
872
873    @test_tracker_info(uuid="b866dcfa-f133-424d-bb5d-f381a1f63602")
874    @TelephonyBaseTest.tel_test_wrap
875    def test_5g_nsa_call_long_duration_volte(self):
876        """ Test call drop rate for nsa 5g VoLTE long duration call.
877
878        Steps:
879        1. Setup nsa 5g VoLTE for DUT.
880        2. Make nsa 5g VoLTE call from DUT to PhoneB.
881        3. For <total_duration> time, check if DUT drop call or not.
882
883        Expected Results:
884        DUT should not drop call.
885
886        Returns:
887        False if DUT call dropped during test.
888        Otherwise True.
889        """
890        ads = self.android_devices
891
892        tasks = [(phone_setup_volte, (self.log, ads[0])),
893                 (phone_setup_voice_general, (self.log, ads[1]))]
894        if not multithread_func(self.log, tasks):
895            self.log.error("Phone Failed to Set Up Properly.")
896            return False
897
898        if not provision_device_for_5g(self.log, ads[0]):
899            return False
900
901        return _test_call_long_duration(self.log, ads,
902            is_phone_in_call_volte, self.long_call_duration)
903
904
905    @test_tracker_info(uuid="527e6676-25c7-4adc-94e7-bb6d3b8f6c24")
906    @TelephonyBaseTest.tel_test_wrap
907    def test_5g_nsa_call_volte_after_mobile_data_usage_limit_reached(self):
908        """ VoLTE to VoLTE call test after mobile data usage limit reached
909
910        1. Set the data limit to the current usage
911        2. Make Sure PhoneA is in nsa 5G mode (with VoLTE).
912        3. Make Sure PhoneB is in nsa 5G mode (with VoLTE).
913        4. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneA.
914        5. Call from PhoneA to PhoneB, accept on PhoneB, hang up on PhoneB.
915
916        Raises:
917            TestFailure if not success.
918        """
919        ads = self.android_devices
920        try:
921            subscriber_id = ads[0].droid.telephonyGetSubscriberId()
922            data_usage = get_mobile_data_usage(ads[0], subscriber_id)
923            set_mobile_data_usage_limit(ads[0], data_usage, subscriber_id)
924
925            if not provision_device_for_5g(self.log, ads):
926                self.log.error("Phone Failed to Set Up Properly.")
927                self.tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
928                raise signals.TestFailure("Failed",
929                    extras={"fail_reason": "Phone Failed to Set Up Properly."})
930
931            result = two_phone_call_short_seq(
932                self.log, ads[0], None, is_phone_in_call_volte,
933                ads[1], None, is_phone_in_call_volte, None,
934                WAIT_TIME_IN_CALL_FOR_IMS)
935            self.tel_logger.set_result(result.result_value)
936
937            if not result:
938                raise signals.TestFailure("Failed",
939                    extras={"fail_reason": str(result.result_value)})
940        finally:
941            remove_mobile_data_usage_limit(ads[0], subscriber_id)
942
943
944    @test_tracker_info(uuid="2c28a974-dc31-4f01-b555-d3e0a8374f37")
945    @TelephonyBaseTest.tel_test_wrap
946    def test_5g_nsa_call_volte_in_call_wifi_toggling(self):
947        """ General voice to voice call.
948
949        1. Make Sure PhoneA in nsa5G.
950        2. Make Sure PhoneB in nsa5G.
951        3. Call from PhoneA to PhoneB.
952        4. Toggling Wifi connnection in call.
953        5. Verify call is active.
954        6. Hung up the call on PhoneA
955
956        Returns:
957            True if pass; False if fail.
958        """
959        ads = self.android_devices
960        result = True
961
962        if not provision_device_for_5g(self.log, ads):
963                self.log.error("Phone Failed to Set Up Properly.")
964                self.tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
965                raise signals.TestFailure("Failed",
966                    extras={"fail_reason": "Phone Failed to Set Up Properly."})
967
968        if not call_setup_teardown(self.log, ads[0], ads[1], None, None, None,
969                                   5):
970            self.log.error("Call setup failed")
971            return False
972        else:
973            self.log.info("Call setup succeed")
974
975        if not wifi_cell_switching(self.log, ads[0], GEN_5G, self.wifi_network_ssid,
976                                   self.wifi_network_pass):
977            ads[0].log.error("Failed to do WIFI and Cell switch in call")
978            result = False
979
980        if not is_phone_in_call_active(ads[0]):
981            return False
982        else:
983            if not ads[0].droid.telecomCallGetAudioState():
984                ads[0].log.error("Audio is not on call")
985                result = False
986            else:
987                ads[0].log.info("Audio is on call")
988            hangup_call(self.log, ads[0])
989            return result
990
991    @test_tracker_info(uuid="95802175-06d5-4774-8ce8-fdf7922eca20")
992    @TelephonyBaseTest.tel_test_wrap
993    def test_5g_nsa_call_mo_vowifi_in_active_youtube(self):
994        """Test call can be established during active youtube video on 5G NSA.
995
996        Turn off airplane mode, turn on wfc and wifi.
997        Starting youtube video.
998        Initiate a MO voice call. Verify call can be established.
999
1000        Returns:
1001            True if success.
1002            False if failed.
1003        """
1004        if not phone_setup_iwlan(self.log, self.android_devices[0], False,
1005                                 WFC_MODE_WIFI_PREFERRED,
1006                                 self.wifi_network_ssid,
1007                                 self.wifi_network_pass):
1008            self.android_devices[0].log.error(
1009                "Failed to setup IWLAN with NON-APM WIFI WFC on")
1010            return False
1011        return test_call_setup_in_active_youtube_video(self.log,
1012                                                       self.android_devices,
1013                                                       GEN_5G,
1014                                                       DIRECTION_MOBILE_ORIGINATED)
1015
1016    @test_tracker_info(uuid="f827a8b5-039c-4cc1-b030-78a09119acfc")
1017    @TelephonyBaseTest.tel_test_wrap
1018    def test_5g_nsa_call_mt_vowifi_in_active_youtube(self):
1019        """Test call can be established during active youtube_video on 5G NSA.
1020
1021        Turn off airplane mode, turn on wfc and wifi.
1022        Starting an youtube video.
1023        Initiate a MT voice call. Verify call can be established.
1024
1025        Returns:
1026            True if success.
1027            False if failed.
1028        """
1029        if not phone_setup_iwlan(self.log, self.android_devices[0], False,
1030                                 WFC_MODE_WIFI_PREFERRED,
1031                                 self.wifi_network_ssid,
1032                                 self.wifi_network_pass):
1033            self.android_devices[0].log.error(
1034                "Failed to setup iwlan with APM off and WIFI and WFC on")
1035            return False
1036        return test_call_setup_in_active_youtube_video(self.log,
1037                                                       self.android_devices,
1038                                                       GEN_5G,
1039                                                       DIRECTION_MOBILE_TERMINATED)
1040
1041    @test_tracker_info(uuid="af3254d0-a84a-47c8-8ebc-11517b7b4944")
1042    @TelephonyBaseTest.tel_test_wrap
1043    def test_5g_nsa_call_mo_vowifi_apm_in_active_data_transfer(self):
1044        """Test call can be established during active data connection on 5G NSA.
1045
1046        Turn on wifi-calling, airplane mode and wifi.
1047        Starting downloading file from Internet.
1048        Initiate a MO voice call. Verify call can be established.
1049        Hangup Voice Call, verify file is downloaded successfully.
1050
1051        Returns:
1052            True if success.
1053            False if failed.
1054        """
1055        if not provision_device_for_5g(self.log, self.android_devices[0]):
1056            self.android_devices[0].log.error("Phone not attached on 5G NSA before call.")
1057            return False
1058
1059        if not phone_setup_iwlan(self.log, self.android_devices[0], True,
1060                                 WFC_MODE_WIFI_PREFERRED,
1061                                 self.wifi_network_ssid,
1062                                 self.wifi_network_pass):
1063            self.android_devices[0].log.error(
1064                "Failed to setup iwlan with APM, WIFI and WFC on")
1065            return False
1066        return test_call_setup_in_active_data_transfer(self.log,
1067                                                       self.android_devices,
1068                                                       None,
1069                                                       DIRECTION_MOBILE_ORIGINATED)
1070
1071    @test_tracker_info(uuid="5c58af94-8c24-481b-a555-bdbf36db5f6e")
1072    @TelephonyBaseTest.tel_test_wrap
1073    def test_5g_nsa_call_mt_vowifi_apm_in_active_data_transfer(self):
1074        """Test call can be established during active data connection on 5G NSA.
1075
1076        Turn on wifi-calling, airplane mode and wifi.
1077        Starting downloading file from Internet.
1078        Initiate a MT voice call. Verify call can be established.
1079        Hangup Voice Call, verify file is downloaded successfully.
1080
1081        Returns:
1082            True if success.
1083            False if failed.
1084        """
1085        if not provision_device_for_5g(self.log, self.android_devices[0]):
1086            self.android_devices[0].log.error("Phone not attached on 5G NSA before call.")
1087            return False
1088
1089        if not phone_setup_iwlan(self.log, self.android_devices[0], True,
1090                                 WFC_MODE_WIFI_PREFERRED,
1091                                 self.wifi_network_ssid,
1092                                 self.wifi_network_pass):
1093            self.android_devices[0].log.error(
1094                "Failed to setup iwlan with APM, WIFI and WFC on")
1095            return False
1096        return test_call_setup_in_active_data_transfer(self.log,
1097                                                       self.android_devices,
1098                                                       None,
1099                                                       DIRECTION_MOBILE_TERMINATED)
1100
1101    @test_tracker_info(uuid="bcd874ae-58e1-4954-88af-bb3dd54d4abf")
1102    @TelephonyBaseTest.tel_test_wrap
1103    def test_5g_nsa_call_mo_vowifi_apm_in_active_youtube(self):
1104        """Test call can be established during active youtube video on 5G NSA.
1105
1106        Turn on wifi-calling, airplane mode and wifi.
1107        Starting an youtube video.
1108        Initiate a MO voice call. Verify call can be established.
1109
1110        Returns:
1111            True if success.
1112            False if failed.
1113        """
1114        if not provision_device_for_5g(self.log, self.android_devices[0]):
1115            self.android_devices[0].log.error("Phone not attached on 5G NSA before call.")
1116            return False
1117
1118        if not phone_setup_iwlan(self.log, self.android_devices[0], True,
1119                                 WFC_MODE_WIFI_PREFERRED,
1120                                 self.wifi_network_ssid,
1121                                 self.wifi_network_pass):
1122            self.android_devices[0].log.error(
1123                "Failed to setup iwlan with APM, WIFI and WFC on")
1124            return False
1125        return test_call_setup_in_active_youtube_video(self.log,
1126                                                       self.android_devices,
1127                                                       None,
1128                                                       DIRECTION_MOBILE_ORIGINATED)
1129
1130    @test_tracker_info(uuid="ad96f1cf-0d17-4a39-86cf-cacb5f4cc81c")
1131    @TelephonyBaseTest.tel_test_wrap
1132    def test_5g_nsa_call_mt_vowifi_apm_in_active_youtube(self):
1133        """Test call can be established during active youtube video on 5G NSA.
1134
1135        Turn on wifi-calling, airplane mode and wifi.
1136        Starting youtube video.
1137        Initiate a MT voice call. Verify call can be established.
1138
1139        Returns:
1140            True if success.
1141            False if failed.
1142        """
1143        if not provision_device_for_5g(self.log, self.android_devices[0]):
1144            self.android_devices[0].log.error("Phone not attached on 5G NSA before call.")
1145            return False
1146
1147        if not phone_setup_iwlan(self.log, self.android_devices[0], True,
1148                                 WFC_MODE_WIFI_PREFERRED,
1149                                 self.wifi_network_ssid,
1150                                 self.wifi_network_pass):
1151            self.android_devices[0].log.error(
1152                "Failed to setup iwlan with APM, WIFI and WFC on")
1153            return False
1154        return test_call_setup_in_active_youtube_video(self.log,
1155                                                       self.android_devices,
1156                                                       None,
1157                                                       DIRECTION_MOBILE_TERMINATED)
1158
1159    @test_tracker_info(uuid="9d1121c1-aae4-428b-9167-09d4efdb7e37")
1160    @TelephonyBaseTest.tel_test_wrap
1161    def test_5g_nsa_call_wfc_in_call_wifi_toggling(self):
1162        """ General voice to voice call on 5G NSA. TMO Only Test
1163
1164        1. Make Sure PhoneA in wfc with APM off.
1165        2. Make Sure PhoneB in Voice Capable.
1166        3. Call from PhoneA to PhoneB.
1167        4. Toggling Wifi connection in call.
1168        5. Verify call is active.
1169        6. Hung up the call on PhoneA
1170
1171        Returns:
1172            True if pass; False if fail.
1173        """
1174
1175        ads = self.android_devices
1176
1177        if not provision_device_for_5g(self.log, ads):
1178            return False
1179        tasks = [(phone_setup_iwlan,
1180                  (self.log, ads[0], False, WFC_MODE_WIFI_PREFERRED,
1181                   self.wifi_network_ssid, self.wifi_network_pass)),
1182                 (phone_setup_voice_general, (self.log, ads[1]))]
1183
1184        if not multithread_func(self.log, tasks):
1185            self.log.error("Phone Failed to Set Up Properly.")
1186            return False
1187        return test_wifi_cell_switching_in_call(self.log,
1188                                                ads,
1189                                                self.wifi_network_ssid,
1190                                                self.wifi_network_pass)
1191
1192    """ Tests End """
1193