• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Tethering scenarios
18"""
19
20import time
21
22from acts.utils import rand_ascii_str
23from acts.test_decorators import test_tracker_info
24from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
25from acts_contrib.test_utils.tel.tel_defines import NETWORK_SERVICE_DATA
26from acts_contrib.test_utils.tel.tel_defines import RAT_2G
27from acts_contrib.test_utils.tel.tel_defines import RAT_3G
28from acts_contrib.test_utils.tel.tel_defines import RAT_4G
29from acts_contrib.test_utils.tel.tel_defines import RAT_5G
30from acts_contrib.test_utils.tel.tel_defines import TETHERING_PASSWORD_HAS_ESCAPE
31from acts_contrib.test_utils.tel.tel_defines import TETHERING_SPECIAL_SSID_LIST
32from acts_contrib.test_utils.tel.tel_defines import TETHERING_SPECIAL_PASSWORD_LIST
33from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_DATA_STATUS_CHANGE_DURING_WIFI_TETHERING
34from acts_contrib.test_utils.tel.tel_5g_test_utils import provision_device_for_5g
35from acts_contrib.test_utils.tel.tel_bt_utils import verify_bluetooth_tethering_connection
36from acts_contrib.test_utils.tel.tel_data_utils import run_stress_test
37from acts_contrib.test_utils.tel.tel_data_utils import test_wifi_tethering
38from acts_contrib.test_utils.tel.tel_data_utils import test_setup_tethering
39from acts_contrib.test_utils.tel.tel_data_utils import test_start_wifi_tethering_connect_teardown
40from acts_contrib.test_utils.tel.tel_data_utils import test_tethering_wifi_and_voice_call
41from acts_contrib.test_utils.tel.tel_data_utils import tethering_check_internet_connection
42from acts_contrib.test_utils.tel.tel_data_utils import verify_toggle_apm_tethering_internet_connection
43from acts_contrib.test_utils.tel.tel_data_utils import verify_tethering_entitlement_check
44from acts_contrib.test_utils.tel.tel_data_utils import wifi_tethering_cleanup
45from acts_contrib.test_utils.tel.tel_data_utils import wifi_tethering_setup_teardown
46from acts_contrib.test_utils.tel.tel_data_utils import wait_and_verify_device_internet_connection
47from acts_contrib.test_utils.tel.tel_data_utils import setup_device_internet_connection
48from acts_contrib.test_utils.tel.tel_data_utils import verify_wifi_tethering_when_reboot
49from acts_contrib.test_utils.tel.tel_data_utils import setup_device_internet_connection_then_reboot
50from acts_contrib.test_utils.tel.tel_data_utils import verify_internet_connection_in_doze_mode
51from acts_contrib.test_utils.tel.tel_data_utils import verify_toggle_data_during_wifi_tethering
52from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_volte
53from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_csfb
54from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_voice_3g
55from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_network_generation
56from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_phones_default_state
57from acts_contrib.test_utils.tel.tel_test_utils import verify_internet_connection
58from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
59from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_csfb
60from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_3g
61from acts_contrib.test_utils.tel.tel_wifi_utils import WIFI_CONFIG_APBAND_5G
62from acts_contrib.test_utils.tel.tel_wifi_utils import WIFI_CONFIG_APBAND_2G
63from acts_contrib.test_utils.tel.tel_wifi_utils import wifi_reset
64
65
66class Nsa5gTetheringTest(TelephonyBaseTest):
67    def setup_class(self):
68        super().setup_class()
69        self.stress_test_number = self.get_stress_test_number()
70        self.provider = self.android_devices[0]
71        self.clients = self.android_devices[1:]
72
73    def setup_test(self):
74        TelephonyBaseTest.setup_test(self)
75        self.number_of_devices = 1
76
77    def teardown_class(self):
78        TelephonyBaseTest.teardown_class(self)
79
80    """ Tests Begin """
81
82
83    @test_tracker_info(uuid="c7957e52-d5e5-499b-b387-fced88fda237")
84    @TelephonyBaseTest.tel_test_wrap
85    def test_5g_nsa_wifi_tethering_to_5gwifi(self):
86        """WiFi Tethering test: 5G NSA to WiFI 5G Tethering
87
88        1. DUT in 5G NSA mode, attached.
89        2. DUT start 5G WiFi Tethering
90        3. PhoneB disable data, connect to DUT's softAP
91        4. Verify Internet access on DUT and PhoneB
92
93        Returns:
94            True if success.
95            False if failed.
96        """
97        return test_wifi_tethering(self.log,
98                                   self.provider,
99                                   self.clients,
100                                   self.clients,
101                                   RAT_5G,
102                                   WIFI_CONFIG_APBAND_5G,
103                                   check_interval=10,
104                                   check_iteration=10,
105                                   nr_type= 'nsa')
106
107
108    @test_tracker_info(uuid="0af10a6b-7c01-41fd-95ce-d839a787aa98")
109    @TelephonyBaseTest.tel_test_wrap
110    def test_5g_nsa_wifi_tethering_to_2gwifi(self):
111        """WiFi Tethering test: 5G NSA to WiFI 2G Tethering
112
113        1. DUT in 5G NSA mode, attached.
114        2. DUT start 2.4G WiFi Tethering
115        3. PhoneB disable data, connect to DUT's softAP
116        4. Verify Internet access on DUT and PhoneB
117
118        Returns:
119            True if success.
120            False if failed.
121        """
122        return test_wifi_tethering(self.log,
123                                   self.provider,
124                                   self.clients,
125                                   self.clients,
126                                   RAT_5G,
127                                   WIFI_CONFIG_APBAND_2G,
128                                   check_interval=10,
129                                   check_iteration=10,
130                                   nr_type= 'nsa')
131
132
133    @test_tracker_info(uuid="d7ab31d5-5f96-4b48-aa92-810e6cfcf845")
134    @TelephonyBaseTest.tel_test_wrap
135    def test_5g_nsa_wifi_tethering_toggle_apm(self):
136        """WiFi Tethering test: Toggle APM during active WiFi 2.4G Tethering from 5G NSA
137
138        1. DUT in 5G NSA mode, idle.
139        2. DUT start 2.4G WiFi Tethering
140        3. PhoneB disable data, connect to DUT's softAP
141        4. Verify Internet access on DUT and PhoneB
142        5. DUT toggle APM on, verify WiFi tethering stopped, PhoneB lost WiFi connection.
143        6. DUT toggle APM off, verify PhoneA have cellular data and Internet connection.
144
145        Returns:
146            True if success.
147            False if failed.
148        """
149        try:
150            ssid = rand_ascii_str(10)
151            if not test_wifi_tethering(self.log,
152                                       self.provider,
153                                       self.clients,
154                                       [self.clients[0]],
155                                       RAT_5G,
156                                       WIFI_CONFIG_APBAND_2G,
157                                       check_interval=10,
158                                       check_iteration=2,
159                                       do_cleanup=False,
160                                       ssid=ssid,
161                                       nr_type= 'nsa'):
162                self.log.error("WiFi Tethering failed.")
163                return False
164
165            if not verify_toggle_apm_tethering_internet_connection(self.log,
166                                                                   self.provider,
167                                                                   self.clients,
168                                                                   ssid):
169                return False
170        finally:
171            self.clients[0].droid.telephonyToggleDataConnection(True)
172            wifi_reset(self.log, self.clients[0])
173        return True
174
175    @test_tracker_info(uuid="3fa61282-eb08-469e-8d7a-1c790556e09c")
176    @TelephonyBaseTest.tel_test_wrap
177    def test_5g_nsa_wifi_tethering_toggle_data(self):
178        """WiFi Tethering test: Toggle Data during active WiFi Tethering from 5G NSA
179
180        1. DUT is on 5G NSA, DUT data connection is on and idle.
181        2. DUT start 2.4G WiFi Tethering
182        3. PhoneB disable data, connect to DUT's softAP
183        4. Verify Internet access on DUT and PhoneB
184        5. Disable Data on DUT, verify PhoneB still connected to WiFi, but no Internet access.
185        6. Enable Data on DUT, verify PhoneB still connected to WiFi and have Internet access.
186
187        Returns:
188            True if success.
189            False if failed.
190        """
191        if not verify_toggle_data_during_wifi_tethering(self.log,
192                                                        self.provider,
193                                                        self.clients,
194                                                        new_gen=RAT_5G,
195                                                        nr_type= 'nsa'):
196            return False
197        return True
198
199    @test_tracker_info(uuid="2be31ba7-f69c-410b-86d1-daaeda892533")
200    @TelephonyBaseTest.tel_test_wrap
201    def test_5g_nsa_wifi_tethering_entitlement_check(self):
202        """5G NSA Tethering Entitlement Check Test
203
204        Get tethering entitlement check result.
205
206        Returns:
207            True if entitlement check returns True.
208        """
209
210        if not provision_device_for_5g(self.log, self.provider, nr_type= 'nsa'):
211            return False
212        return verify_tethering_entitlement_check(self.log,
213                                                  self.provider)
214
215
216    @test_tracker_info(uuid="f07c316c-dbab-4c95-8bec-2a2fc029d5cd")
217    @TelephonyBaseTest.tel_test_wrap
218    def test_5g_nsa_wifi_tethering_to_2gwifi_stress(self):
219        """Stress Test 5G NSA to WiFI 2.4G Tethering
220
221        This is a stress test for "test_5g_nsa_wifi_tethering_to_2gwifi".
222        Default MINIMUM_SUCCESS_RATE is set to 95%.
223
224        Returns:
225            True stress pass rate is higher than MINIMUM_SUCCESS_RATE.
226            False otherwise.
227        """
228        def precondition():
229            return ensure_phones_default_state(self.log, self.android_devices)
230
231        def test_case():
232            return test_wifi_tethering(self.log,
233                                       self.provider,
234                                       self.clients,
235                                       self.clients,
236                                       RAT_5G,
237                                       WIFI_CONFIG_APBAND_2G,
238                                       check_interval=10,
239                                       check_iteration=10,
240                                       nr_type= 'nsa')
241        return run_stress_test(self.log, self.stress_test_number, precondition, test_case)
242
243
244    @test_tracker_info(uuid="bbe9175d-8781-4b31-9962-21abb9441022")
245    @TelephonyBaseTest.tel_test_wrap
246    def test_5g_nsa_wifi_tethering_ssid_quotes(self):
247        """WiFi Tethering test: 5G NSA wifi tethering SSID name have quotes.
248        1. Set SSID name have double quotes.
249        2. Start LTE to WiFi (2.4G) tethering.
250        3. Verify tethering.
251
252        Returns:
253            True if success.
254            False if failed.
255        """
256        ssid = "\"" + rand_ascii_str(10) + "\""
257        self.log.info(
258            "Starting WiFi Tethering test with ssid: {}".format(ssid))
259
260        return test_wifi_tethering(self.log,
261                                   self.provider,
262                                   self.clients,
263                                   self.clients,
264                                   RAT_5G,
265                                   WIFI_CONFIG_APBAND_2G,
266                                   check_interval=10,
267                                   check_iteration=10,
268                                   ssid=ssid,
269                                   nr_type= 'nsa')
270
271
272    @test_tracker_info(uuid="678c6b04-6733-41e1-bb0c-af8c9d1183cb")
273    @TelephonyBaseTest.tel_test_wrap
274    def test_5g_nsa_wifi_tethering_password_escaping_characters(self):
275        """WiFi Tethering test: 5G NSA wifi tethering password have escaping characters.
276        1. Set password have escaping characters.
277            e.g.: '"DQ=/{Yqq;M=(^_3HzRvhOiL8S%`]w&l<Qp8qH)bs<4E9v_q=HLr^)}w$blA0Kg'
278        2. Start LTE to WiFi (2.4G) tethering.
279        3. Verify tethering.
280
281        Returns:
282            True if success.
283            False if failed.
284        """
285
286        password = TETHERING_PASSWORD_HAS_ESCAPE
287        self.log.info(
288            "Starting WiFi Tethering test with password: {}".format(password))
289
290        return test_wifi_tethering(self.log,
291                                   self.provider,
292                                   self.clients,
293                                   self.clients,
294                                   RAT_5G,
295                                   WIFI_CONFIG_APBAND_2G,
296                                   check_interval=10,
297                                   check_iteration=10,
298                                   password=password,
299                                   nr_type= 'nsa')
300
301
302    @test_tracker_info(uuid="eacc5412-fe75-400b-aba9-c0c38bdfff71")
303    @TelephonyBaseTest.tel_test_wrap
304    def test_5g_nsa_wifi_tethering_ssid(self):
305        """WiFi Tethering test: start 5G NSA WiFi tethering with all kinds of SSIDs.
306
307        For each listed SSID, start WiFi tethering on DUT, client connect WiFi,
308        then tear down WiFi tethering.
309
310        Returns:
311            True if WiFi tethering succeed on all SSIDs.
312            False if failed.
313        """
314        if not test_setup_tethering(self.log,
315                                    self.provider,
316                                    self.clients,
317                                    RAT_5G,
318                                    nr_type='nsa'):
319            self.log.error("Setup Failed.")
320            return False
321        ssid_list = TETHERING_SPECIAL_SSID_LIST
322        fail_list = {}
323        self.number_of_devices = 2
324        for ssid in ssid_list:
325            password = rand_ascii_str(8)
326            self.log.info("SSID: <{}>, Password: <{}>".format(ssid, password))
327            if not test_start_wifi_tethering_connect_teardown(self.log,
328                                                              self.provider,
329                                                              self.clients[0],
330                                                              ssid,
331                                                              password):
332                fail_list[ssid] = password
333
334        if len(fail_list) > 0:
335            self.log.error("Failed cases: {}".format(fail_list))
336            return False
337        else:
338            return True
339
340
341    @test_tracker_info(uuid="249cfa53-edb2-4d9c-8f4f-8291bf22fb36")
342    @TelephonyBaseTest.tel_test_wrap
343    def test_5g_nsa_wifi_tethering_password(self):
344        """WiFi Tethering test: start 5G NSA WiFi tethering with all kinds of passwords.
345
346        For each listed password, start WiFi tethering on DUT, client connect WiFi,
347        then tear down WiFi tethering.
348
349        Returns:
350            True if WiFi tethering succeed on all passwords.
351            False if failed.
352        """
353        if not test_setup_tethering(self.log,
354                                    self.provider,
355                                    self.clients,
356                                    RAT_5G,
357                                    nr_type='nsa'):
358            self.log.error("Setup Failed.")
359            return False
360        password_list = TETHERING_SPECIAL_PASSWORD_LIST
361        fail_list = {}
362        self.number_of_devices = 2
363        for password in password_list:
364            ssid = rand_ascii_str(8)
365            self.log.info("SSID: <{}>, Password: <{}>".format(ssid, password))
366            if not test_start_wifi_tethering_connect_teardown(self.log,
367                                                              self.provider,
368                                                              self.clients[0],
369                                                              ssid,
370                                                              password):
371                fail_list[ssid] = password
372
373        if len(fail_list) > 0:
374            self.log.error("Failed cases: {}".format(fail_list))
375            return False
376        else:
377            return True
378
379
380    @test_tracker_info(uuid="9feb4c81-17c6-46ed-9cf7-7aa3d5ae2da0")
381    @TelephonyBaseTest.tel_test_wrap
382    def test_5g_nsa_bluetooth_tethering(self):
383        """Bluetooth Tethering test: nsa 5G to Bluetooth Tethering
384
385        1. DUT in nsa 5G mode, idle.
386        2. DUT start Bluetooth Tethering
387        3. PhoneB disable data, connect to DUT's softAP
388        4. Verify Internet access on DUT and PhoneB
389        5. Toggle provider bluetooth connection
390        6. Verify Internet access on DUT and PhoneB
391
392        Returns:
393            True if success.
394            False if failed.
395        """
396        if not test_setup_tethering(self.log,
397                                    self.provider,
398                                    self.clients,
399                                    RAT_5G,
400                                    nr_type='nsa'):
401            self.log.error("Verify 5G Internet access failed.")
402            return False
403
404        return verify_bluetooth_tethering_connection(self.log,
405                                                    self.provider,
406                                                    self.clients)
407
408
409    @test_tracker_info(uuid="db70c6ec-5edc-44c2-b61b-1c39516a7475")
410    @TelephonyBaseTest.tel_test_wrap
411    def test_5g_nsa_bluetooth_tethering_with_voice_call(self):
412        """Bluetooth Tethering test: nsa 5G to Bluetooth Tethering
413
414        1. DUT in nsa 5G mode, idle.
415        2. DUT start Bluetooth Tethering
416        3. PhoneB disable data, connect to DUT's softAP
417        4. Verify Internet access on DUT and PhoneB
418        5. Verify provider and client are able to make or receive phone call
419        6. Verify Internet access on DUT and PhoneB
420
421        Returns:
422            True if success.
423            False if failed.
424        """
425        if not test_setup_tethering(self.log,
426                                    self.provider,
427                                    self.clients,
428                                    RAT_5G,
429                                    nr_type='nsa'):
430            self.log.error("Verify 5G Internet access failed.")
431            return False
432
433        return verify_bluetooth_tethering_connection(self.log,
434                                                    self.provider,
435                                                    self.clients,
436                                                    toggle_tethering=False,
437                                                    toggle_bluetooth=False,
438                                                    voice_call=True)
439
440
441    @test_tracker_info(uuid="12efb94f-7466-40e9-9a79-59b4074ab4dd")
442    @TelephonyBaseTest.tel_test_wrap
443    def test_5g_nsa_bluetooth_tethering_toggle_data(self):
444        """Bluetooth Tethering test: nsa 5G to Bluetooth Tethering
445
446        1. DUT in nsa 5G mode, idle.
447        2. DUT start Bluetooth Tethering
448        3. PhoneB disable data, connect to DUT's softAP
449        4. Verify Internet access on DUT and PhoneB
450        5. Toggle provider data connection
451        6. Verify Internet access on DUT and PhoneB
452
453        Returns:
454            True if success.
455            False if failed.
456        """
457        if not test_setup_tethering(self.log,
458                                    self.provider,
459                                    self.clients,
460                                    RAT_5G,
461                                    nr_type='nsa'):
462            self.log.error("Verify 5G Internet access failed.")
463            return False
464
465        return verify_bluetooth_tethering_connection(self.log,
466                                                    self.provider,
467                                                    self.clients,
468                                                    toggle_tethering=False,
469                                                    toggle_bluetooth=False,
470                                                    toggle_data=True)
471
472
473    @test_tracker_info(uuid="475b485a-1228-4f18-b9f2-593f96850165")
474    @TelephonyBaseTest.tel_test_wrap
475    def test_5g_nsa_bluetooth_tethering_toggle_tethering(self):
476        """Bluetooth Tethering test: nsa 5G to Bluetooth Tethering
477
478        1. DUT in nsa 5G mode, idle.
479        2. DUT start Bluetooth Tethering
480        3. PhoneB disable data, connect to DUT's softAP
481        4. Verify Internet access on DUT and PhoneB
482        5. Toggle provider bluetooth tethering
483        6. Verify Internet access on DUT and PhoneB
484
485        Returns:
486            True if success.
487            False if failed.
488        """
489        if not test_setup_tethering(self.log,
490                                    self.provider,
491                                    self.clients,
492                                    RAT_5G,
493                                    nr_type='nsa'):
494            self.log.error("Verify 5G Internet access failed.")
495            return False
496
497        return verify_bluetooth_tethering_connection(self.log,
498                                                    self.provider,
499                                                    self.clients,
500                                                    toggle_tethering=True,
501                                                    toggle_bluetooth=False,
502                                                    toggle_data=False)
503
504
505    @test_tracker_info(uuid="07f8e523-b471-4156-b057-558123973a5b")
506    @TelephonyBaseTest.tel_test_wrap
507    def test_5g_nsa_bluetooth_tethering_rat_from_5g_nsa_to_4g(self):
508        """Bluetooth Tethering test: nsa 5G to 4G Bluetooth Tethering
509
510        1. DUT in nsa 5G mode, idle.
511        2. DUT start bluetooth Tethering
512        3. PhoneB disable data, connect to DUT's softAP
513        4. Verify Internet access on DUT and PhoneB
514        5. Change provider RAT to 4G
515        6. Verify Internet access on DUT and PhoneB
516
517        Returns:
518            True if success.
519            False if failed.
520        """
521        if not test_setup_tethering(self.log,
522                                    self.provider,
523                                    self.clients,
524                                    RAT_5G,
525                                    nr_type='nsa'):
526            self.log.error("Verify 5G Internet access failed.")
527            return False
528
529        return verify_bluetooth_tethering_connection(self.log,
530                                                    self.provider,
531                                                    self.clients,
532                                                    toggle_tethering=False,
533                                                    toggle_bluetooth=False,
534                                                    toggle_data=False,
535                                                    change_rat=RAT_4G)
536
537
538    @test_tracker_info(uuid="93040a69-fa85-431f-ac9d-80091c6c8223")
539    @TelephonyBaseTest.tel_test_wrap
540    def test_5g_nsa_bluetooth_tethering_rat_from_5g_nsa_to_3g(self):
541        """Bluetooth Tethering test: nsa5G to 3G Bluetooth Tethering
542
543        1. DUT in nsa 5G mode, idle.
544        2. DUT start bluetooth Tethering
545        3. PhoneB disable data, connect to DUT's softAP
546        4. Verify Internet access on DUT and PhoneB
547        5. Change provider RAT to 3G
548        6. Verify Internet access on DUT and PhoneB
549
550        Returns:
551            True if success.
552            False if failed.
553        """
554        if not test_setup_tethering(self.log,
555                                    self.provider,
556                                    self.clients,
557                                    RAT_5G,
558                                    nr_type='nsa'):
559            self.log.error("Verify 5G Internet access failed.")
560            return False
561
562        return verify_bluetooth_tethering_connection(self.log,
563                                                    self.provider,
564                                                    self.clients,
565                                                    toggle_tethering=False,
566                                                    toggle_bluetooth=False,
567                                                    toggle_data=False,
568                                                    change_rat=RAT_3G)
569
570
571    @test_tracker_info(uuid="6cc17fc7-13a0-4493-9673-920952a16fcc")
572    @TelephonyBaseTest.tel_test_wrap
573    def test_5g_nsa_bluetooth_tethering_rat_from_5g_nsa_to_2g(self):
574        """Bluetooth Tethering test: nsa5G to 2G Bluetooth Tethering
575
576        1. DUT in nsa 5G mode, idle.
577        2. DUT start bluetooth Tethering
578        3. PhoneB disable data, connect to DUT's softAP
579        4. Verify Internet access on DUT and PhoneB
580        5. Change provider RAT to 2G
581        6. Verify Internet access on DUT and PhoneB
582
583        Returns:
584            True if success.
585            False if failed.
586        """
587        if not test_setup_tethering(self.log,
588                                    self.provider,
589                                    self.clients,
590                                    RAT_5G,
591                                    nr_type='nsa'):
592            self.log.error("Verify 5G Internet access failed.")
593            return False
594
595        return verify_bluetooth_tethering_connection(self.log,
596                                                    self.provider,
597                                                    self.clients,
598                                                    toggle_tethering=False,
599                                                    toggle_bluetooth=False,
600                                                    toggle_data=False,
601                                                    change_rat=RAT_2G)
602
603
604    # Invalid Live Test. Can't rely on the result of this test with live network.
605    # Network may decide not to change the RAT when data connection is active.
606    @test_tracker_info(uuid="8bef3215-8218-4f7f-9a5f-954fa36ac5d8")
607    @TelephonyBaseTest.tel_test_wrap
608    def test_5g_nsa_wifi_tethering_from_5g_nsa_to_3g(self):
609        """WiFi Tethering test: Change Cellular Data RAT generation from nsa 5G to 3G,
610            during active WiFi Tethering.
611
612        1. DUT in nsa 5G mode, idle.
613        2. DUT start 2.4G WiFi Tethering
614        3. PhoneB disable data, connect to DUT's softAP
615        4. Verily Internet access on DUT and PhoneB
616        5. Change DUT Cellular Data RAT generation from nsa5G to 3G.
617        6. Verify both DUT and PhoneB have Internet access.
618
619        Returns:
620            True if success.
621            False if failed.
622        """
623        if not test_setup_tethering(self.log,
624                                    self.provider,
625                                    self.clients,
626                                    RAT_5G,
627                                    nr_type='nsa'):
628            self.log.error("Verify 5G Internet access failed.")
629            return False
630        try:
631            if not wifi_tethering_setup_teardown(
632                    self.log,
633                    self.provider, [self.clients[0]],
634                    ap_band=WIFI_CONFIG_APBAND_2G,
635                    check_interval=10,
636                    check_iteration=2,
637                    do_cleanup=False):
638                self.log.error("WiFi Tethering failed.")
639                return False
640
641            if not self.provider.droid.wifiIsApEnabled():
642                self.provider.log.error("Provider WiFi tethering stopped.")
643                return False
644
645            self.log.info("Provider change RAT from nsa 5G to 3G.")
646            if not ensure_network_generation(
647                    self.log,
648                    self.provider,
649                    RAT_3G,
650                    voice_or_data=NETWORK_SERVICE_DATA,
651                    toggle_apm_after_setting=False):
652                self.provider.log.error("Provider failed to reselect to 3G.")
653                return False
654            time.sleep(WAIT_TIME_DATA_STATUS_CHANGE_DURING_WIFI_TETHERING)
655            if not verify_internet_connection(self.log, self.provider):
656                self.provider.log.error("Data not available on Provider.")
657                return False
658            if not self.provider.droid.wifiIsApEnabled():
659                self.provider.log.error("Provider WiFi tethering stopped.")
660                return False
661            if not tethering_check_internet_connection(
662                    self.log, self.provider, [self.clients[0]], 10, 5):
663                return False
664        finally:
665            if not wifi_tethering_cleanup(self.log, self.provider,
666                                          self.clients):
667                return False
668        return True
669
670
671    # Invalid Live Test. Can't rely on the result of this test with live network.
672    # Network may decide not to change the RAT when data connection is active.
673    @test_tracker_info(uuid="633f187d-3a8f-46dc-86de-f87b733a83ba")
674    @TelephonyBaseTest.tel_test_wrap
675    def test_5g_nsa_wifi_tethering_from_3g_to_5g_nsa(self):
676        """WiFi Tethering test: Change Cellular Data RAT generation from 3G to nsa5G,
677            during active WiFi Tethering.
678
679        1. DUT in 3G mode, idle.
680        2. DUT start 2.4G WiFi Tethering
681        3. PhoneB disable data, connect to DUT's softAP
682        4. Verily Internet access on DUT and PhoneB
683        5. Change DUT Cellular Data RAT generation from 3G to nsa5G.
684        6. Verify both DUT and PhoneB have Internet access.
685
686        Returns:
687            True if success.
688            False if failed.
689        """
690        if not test_setup_tethering(self.log,
691                                    self.provider,
692                                    self.clients,
693                                    RAT_3G):
694            self.log.error("Verify 3G Internet access failed.")
695            return False
696        try:
697            if not wifi_tethering_setup_teardown(
698                    self.log,
699                    self.provider, [self.clients[0]],
700                    ap_band=WIFI_CONFIG_APBAND_2G,
701                    check_interval=10,
702                    check_iteration=2,
703                    do_cleanup=False):
704                self.log.error("WiFi Tethering failed.")
705                return False
706
707            if not self.provider.droid.wifiIsApEnabled():
708                self.log.error("Provider WiFi tethering stopped.")
709                return False
710
711            self.log.info("Provider change RAT from 3G to 5G.")
712            if not ensure_network_generation(
713                    self.log,
714                    self.provider,
715                    RAT_4G,
716                    voice_or_data=NETWORK_SERVICE_DATA,
717                    toggle_apm_after_setting=False):
718                self.log.error("Provider failed to reselect to LTE")
719                return False
720            if not provision_device_for_5g(self.log,
721                                            self.provider,
722                                            nr_type='nsa'):
723                self.log.error("Provider failed to reselect to nsa 5G")
724                return False
725            time.sleep(WAIT_TIME_DATA_STATUS_CHANGE_DURING_WIFI_TETHERING)
726            if not verify_internet_connection(self.log, self.provider):
727                self.provider.log.error("Data not available on Provider.")
728                return False
729            if not self.provider.droid.wifiIsApEnabled():
730                self.provider.log.error("Provider WiFi tethering stopped.")
731                return False
732            if not tethering_check_internet_connection(
733                    self.log, self.provider, [self.clients[0]], 10, 5):
734                return False
735        finally:
736            if not wifi_tethering_cleanup(self.log, self.provider, [self.clients[0]]):
737                return False
738        return True
739
740
741    # Invalid Live Test. Can't rely on the result of this test with live network.
742    # Network may decide not to change the RAT when data connection is active.
743    @test_tracker_info(uuid="28e654a6-2318-4f36-a4f0-16214d8e004d")
744    @TelephonyBaseTest.tel_test_wrap
745    def test_5g_nsa_wifi_tethering_from_5g_nsa_to_4g(self):
746        """WiFi Tethering test: Change Cellular Data RAT generation from nsa 5G to 4G,
747            during active WiFi Tethering.
748
749        1. DUT in nsa 5G mode, idle.
750        2. DUT start 2.4G WiFi Tethering
751        3. PhoneB disable data, connect to DUT's softAP
752        4. Verily Internet access on DUT and PhoneB
753        5. Change DUT Cellular Data RAT generation from nsa5G to LTE.
754        6. Verify both DUT and PhoneB have Internet access.
755
756        Returns:
757            True if success.
758            False if failed.
759        """
760        if not test_setup_tethering(self.log,
761                                    self.provider,
762                                    self.clients,
763                                    RAT_5G,
764                                    nr_type='nsa'):
765            self.log.error("Verify 5G Internet access failed.")
766            return False
767        try:
768            if not wifi_tethering_setup_teardown(
769                    self.log,
770                    self.provider, [self.clients[0]],
771                    ap_band=WIFI_CONFIG_APBAND_2G,
772                    check_interval=10,
773                    check_iteration=2,
774                    do_cleanup=False):
775                self.log.error("WiFi Tethering failed.")
776                return False
777
778            if not self.provider.droid.wifiIsApEnabled():
779                self.provider.log.error("Provider WiFi tethering stopped.")
780                return False
781
782            self.log.info("Provider change RAT from 5G to LTE.")
783            if not ensure_network_generation(
784                    self.log,
785                    self.provider,
786                    RAT_4G,
787                    voice_or_data=NETWORK_SERVICE_DATA,
788                    toggle_apm_after_setting=False):
789                self.provider.log.error("Provider failed to reselect to 4G.")
790                return False
791            time.sleep(WAIT_TIME_DATA_STATUS_CHANGE_DURING_WIFI_TETHERING)
792            if not verify_internet_connection(self.log, self.provider):
793                self.provider.log.error("Data not available on Provider.")
794                return False
795            if not self.provider.droid.wifiIsApEnabled():
796                self.provider.log.error("Provider WiFi tethering stopped.")
797                return False
798            if not tethering_check_internet_connection(
799                    self.log, self.provider, [self.clients[0]], 10, 5):
800                return False
801        finally:
802            if not wifi_tethering_cleanup(self.log, self.provider,
803                                          self.clients):
804                return False
805        return True
806
807
808    # Invalid Live Test. Can't rely on the result of this test with live network.
809    # Network may decide not to change the RAT when data connection is active.
810    @test_tracker_info(uuid="a8190c2a-a9ee-4673-b003-769691d1a575")
811    @TelephonyBaseTest.tel_test_wrap
812    def test_5g_nsa_wifi_tethering_from_4g_to_5g_nsa(self):
813        """WiFi Tethering test: Change Cellular Data RAT generation from 4G to nsa5G,
814            during active WiFi Tethering.
815
816        1. DUT in 4G mode, idle.
817        2. DUT start 2.4G WiFi Tethering
818        3. PhoneB disable data, connect to DUT's softAP
819        4. Verily Internet access on DUT and PhoneB
820        5. Change DUT Cellular Data RAT generation from 4G to nsa5G.
821        6. Verify both DUT and PhoneB have Internet access.
822
823        Returns:
824            True if success.
825            False if failed.
826        """
827        if not test_setup_tethering(self.log,
828                                    self.provider,
829                                    self.clients,
830                                    RAT_4G):
831            self.log.error("Verify 4G Internet access failed.")
832            return False
833        try:
834            if not wifi_tethering_setup_teardown(
835                    self.log,
836                    self.provider, [self.clients[0]],
837                    ap_band=WIFI_CONFIG_APBAND_2G,
838                    check_interval=10,
839                    check_iteration=2,
840                    do_cleanup=False):
841                self.log.error("WiFi Tethering failed.")
842                return False
843
844            if not self.provider.droid.wifiIsApEnabled():
845                self.log.error("Provider WiFi tethering stopped.")
846                return False
847
848            self.log.info("Provider change RAT from 4G to 5G.")
849            if not ensure_network_generation(
850                    self.log,
851                    self.provider,
852                    RAT_4G,
853                    voice_or_data=NETWORK_SERVICE_DATA,
854                    toggle_apm_after_setting=False):
855                self.log.error("Provider failed to reselect to LTE")
856                return False
857            if not provision_device_for_5g(self.log,
858                                            self.provider,
859                                            nr_type='nsa'):
860                self.log.error("Provider failed to reselect to nsa 5G")
861                return False
862            time.sleep(WAIT_TIME_DATA_STATUS_CHANGE_DURING_WIFI_TETHERING)
863            if not verify_internet_connection(self.log, self.provider):
864                self.provider.log.error("Data not available on Provider.")
865                return False
866            if not self.provider.droid.wifiIsApEnabled():
867                self.provider.log.error("Provider WiFi tethering stopped.")
868                return False
869            if not tethering_check_internet_connection(
870                    self.log, self.provider, [self.clients[0]], 10, 5):
871                return False
872        finally:
873            if not wifi_tethering_cleanup(self.log, self.provider, [self.clients[0]]):
874                return False
875        return True
876
877
878    @test_tracker_info(uuid="ac3ff18a-69e0-4a8a-bbfa-41fad7f05200")
879    @TelephonyBaseTest.tel_test_wrap
880    def test_5g_nsa_wifi_tethering_volte_call(self):
881        """WiFi Tethering test: VoLTE call during WiFi tethering
882        1. Start LTE to WiFi (2.4G) tethering.
883        2. Verify tethering.
884        3. Make outgoing VoLTE call on tethering provider.
885        4. Verify tethering still works.
886        5. Make incoming VoLTE call on tethering provider.
887        6. Verify tethering still works.
888
889        Returns:
890            True if success.
891            False if failed.
892        """
893        return test_tethering_wifi_and_voice_call(self.log,
894                                                self.provider,
895                                                self.clients,
896                                                RAT_5G,
897                                                phone_setup_volte,
898                                                is_phone_in_call_volte,
899                                                nr_type='nsa')
900
901    @test_tracker_info(uuid="f4b96666-ac71-49f2-89db-a792da7bb88c")
902    @TelephonyBaseTest.tel_test_wrap
903    def test_5g_nsa_wifi_tethering_csfb_call(self):
904        """WiFi Tethering test: CSFB call during WiFi tethering
905        1. Start 5G NSA to WiFi (2.4G) tethering.
906        2. Verify tethering.
907        3. Make outgoing CSFB call on tethering provider.
908        4. Verify tethering still works.
909        5. Make incoming CSFB call on tethering provider.
910        6. Verify tethering still works.
911
912        Returns:
913            True if success.
914            False if failed.
915        """
916        return test_tethering_wifi_and_voice_call(self.log,
917                                                    self.provider,
918                                                    self.clients,
919                                                    RAT_5G,
920                                                    phone_setup_csfb,
921                                                    is_phone_in_call_csfb,
922                                                    nr_type='nsa')
923
924    @test_tracker_info(uuid="8cfa6ab6-6dcd-4ee5-97f2-db3b0f52ae17")
925    @TelephonyBaseTest.tel_test_wrap
926    def test_5g_nsa_wifi_tethering_3g_call(self):
927        """WiFi Tethering test: 3G call during WiFi tethering
928        1. Start 5G NSA to WiFi (2.4G) tethering.
929        2. Verify tethering.
930        3. Make outgoing CS call on tethering provider.
931        4. Verify tethering still works.
932        5. Make incoming CS call on tethering provider.
933        6. Verify tethering still works.
934
935        Returns:
936            True if success.
937            False if failed.
938        """
939        return test_tethering_wifi_and_voice_call(self.log,
940                                                    self.provider,
941                                                    self.clients,
942                                                    RAT_5G,
943                                                    phone_setup_voice_3g,
944                                                    is_phone_in_call_3g,
945                                                    nr_type='nsa')
946
947    @test_tracker_info(uuid="ff1f71d7-142c-4e0d-94be-cadbc30828fd")
948    @TelephonyBaseTest.tel_test_wrap
949    def test_5g_nsa_wifi_tethering_no_password(self):
950        """WiFi Tethering test: Start 5g NSA WiFi tethering with no password
951
952        1. DUT is idle.
953        2. DUT start 2.4G WiFi Tethering, with no WiFi password.
954        3. PhoneB disable data, connect to DUT's softAP
955        4. Verify Internet access on DUT and PhoneB
956
957        Returns:
958            True if success.
959            False if failed.
960        """
961        return test_wifi_tethering(self.log,
962                                   self.provider,
963                                   self.clients,
964                                   [self.clients[0]],
965                                   RAT_5G,
966                                   WIFI_CONFIG_APBAND_2G,
967                                   check_interval=10,
968                                   check_iteration=10,
969                                   password="",
970                                   nr_type='nsa')
971
972    @test_tracker_info(uuid="fd6daa93-2ecb-4a23-8f29-6d2db3b940c4")
973    @TelephonyBaseTest.tel_test_wrap
974    def test_5g_nsa_wifi_tethering_reboot(self):
975        """WiFi Tethering test: Start 5G NSA to WiFi tethering then Reboot device
976
977        1. DUT is in idle.
978        2. DUT start 2.4G WiFi Tethering.
979        3. PhoneB disable data, connect to DUT's softAP
980        4. Verify Internet access on DUT and PhoneB
981        5. Reboot DUT
982        6. After DUT reboot, verify tethering is stopped.
983
984        Returns:
985            True if success.
986            False if failed.
987        """
988        try:
989            if not test_wifi_tethering(self.log,
990                                       self.provider,
991                                       self.clients,
992                                       [self.clients[0]],
993                                       RAT_5G,
994                                       WIFI_CONFIG_APBAND_2G,
995                                       check_interval=10,
996                                       check_iteration=2,
997                                       do_cleanup=False,
998                                       nr_type='nsa'):
999                return False
1000
1001            if not verify_wifi_tethering_when_reboot(self.log,
1002                                                     self.provider):
1003                return False
1004        finally:
1005            if not wifi_tethering_cleanup(self.log,
1006                                          self.provider,
1007                                          self.clients):
1008                return False
1009        return True
1010
1011    @test_tracker_info(uuid="b37b5fec-0fef-4206-aa86-1994b89c9369")
1012    @TelephonyBaseTest.tel_test_wrap
1013    def test_5g_nsa_wifi_tethering_connect_wifi_reboot(self):
1014        """WiFi Tethering test: WiFI connected, then start 5G NSA to WiFi tethering,
1015            then reboot device.
1016
1017        Initial Condition: DUT in 5G NSA mode, idle, DUT connect to WiFi.
1018        1. DUT start 2.4G WiFi Tethering.
1019        2. PhoneB disable data, connect to DUT's softAP
1020        3. Verify Internet access on DUT and PhoneB
1021        4. Reboot DUT
1022        5. After DUT reboot, verify tethering is stopped. DUT is able to connect
1023            to previous WiFi AP.
1024
1025        Returns:
1026            True if success.
1027            False if failed.
1028        """
1029
1030        # Ensure provider connecting to wifi network.
1031        def setup_provider_internet_connection():
1032            return setup_device_internet_connection(self.log,
1033                                                    self.provider,
1034                                                    self.wifi_network_ssid,
1035                                                    self.wifi_network_pass)
1036
1037        # wait for provider connecting to wifi network and verify
1038        # internet connection is working.
1039        def wait_and_verify_internet_connection():
1040            return wait_and_verify_device_internet_connection(self.log,
1041                                                              self.provider)
1042
1043        try:
1044            if not test_wifi_tethering(self.log,
1045                                       self.provider,
1046                                       self.clients,
1047                                       [self.clients[0]],
1048                                       RAT_5G,
1049                                       WIFI_CONFIG_APBAND_2G,
1050                                       check_interval=10,
1051                                       check_iteration=2,
1052                                       do_cleanup=False,
1053                                       pre_teardown_func=setup_provider_internet_connection,
1054                                       nr_type='nsa'):
1055                return False
1056
1057            if not verify_wifi_tethering_when_reboot(self.log,
1058                                                     self.provider,
1059                                                     post_reboot_func=wait_and_verify_internet_connection):
1060                return False
1061
1062        finally:
1063            if not wifi_tethering_cleanup(self.log,
1064                                          self.provider,
1065                                          self.clients):
1066                return False
1067        return True
1068
1069    @test_tracker_info(uuid="30050de6-4483-4533-b6ac-17625dd743c2")
1070    @TelephonyBaseTest.tel_test_wrap
1071    def test_5g_nsa_wifi_tethering_connect_reboot_tethering(self):
1072        """WiFi Tethering test: DUT connected to WiFi, then reboot,
1073        After reboot, start 5G NSA to WiFi tethering, verify tethering actually works.
1074
1075        Initial Condition: Device set to 5G NSA mode, idle, DUT connect to WiFi.
1076        1. Verify Internet is working on DUT (by WiFi).
1077        2. Reboot DUT.
1078        3. DUT start 2.4G WiFi Tethering.
1079        4. PhoneB disable data, connect to DUT's softAP
1080        5. Verify Internet access on DUT and PhoneB
1081
1082        Returns:
1083            True if success.
1084            False if failed.
1085        """
1086
1087        # Ensure provider connecting to wifi network and then reboot.
1088        def setup_provider_internet_connect_then_reboot():
1089            return setup_device_internet_connection_then_reboot(self.log,
1090                                                                self.provider,
1091                                                                self.wifi_network_ssid,
1092                                                                self.wifi_network_pass)
1093        return test_wifi_tethering(self.log,
1094                                   self.provider,
1095                                   self.clients,
1096                                   [self.clients[0]],
1097                                   RAT_5G,
1098                                   WIFI_CONFIG_APBAND_2G,
1099                                   check_interval=10,
1100                                   check_iteration=2,
1101                                   pre_teardown_func=setup_provider_internet_connect_then_reboot,
1102                                   nr_type='nsa')
1103
1104    @test_tracker_info(uuid="70f20bcf-8064-49e3-a3f0-ff151374d1ac")
1105    @TelephonyBaseTest.tel_test_wrap
1106    def test_5g_nsa_wifi_tethering_screen_off_enable_doze_mode(self):
1107        """WiFi Tethering test: Start 5G NSA WiFi tethering, then turn off DUT's screen,
1108            then enable doze mode, verify internet connection.
1109
1110        1. Start 5G NSA WiFi tethering on DUT.
1111        2. PhoneB disable data, and connect to DUT's softAP
1112        3. Verify Internet access on DUT and PhoneB
1113        4. Turn off DUT's screen. Wait for 1 minute and
1114            verify Internet access on Client PhoneB.
1115        5. Enable doze mode on DUT. Wait for 1 minute and
1116            verify Internet access on Client PhoneB.
1117        6. Disable doze mode and turn off wifi tethering on DUT.
1118
1119        Returns:
1120            True if success.
1121            False if failed.
1122        """
1123        try:
1124            if not test_wifi_tethering(self.log,
1125                                       self.provider,
1126                                       self.clients,
1127                                       [self.clients[0]],
1128                                       RAT_5G,
1129                                       WIFI_CONFIG_APBAND_2G,
1130                                       check_interval=10,
1131                                       check_iteration=2,
1132                                       do_cleanup=False,
1133                                       nr_type='nsa'):
1134                return False
1135            if not verify_internet_connection_in_doze_mode(self.log,
1136                                                           self.provider,
1137                                                           self.clients[0]):
1138                return False
1139
1140        finally:
1141            if not wifi_tethering_cleanup(self.log,
1142                                          self.provider,
1143                                          [self.clients[0]]):
1144                return False
1145        return True
1146
1147    @test_tracker_info(uuid="260c63d0-4398-4794-bb3e-1ff3db542ab5")
1148    @TelephonyBaseTest.tel_test_wrap
1149    def test_5g_nsa_wifi_tethering_disable_resume_wifi(self):
1150        """WiFi Tethering test: WiFI connected to 2.4G network,
1151        start (LTE) 2.4G WiFi tethering, then stop tethering over 5G NSA
1152
1153        1. DUT in data connected, idle. WiFi connected to 2.4G Network
1154        2. DUT start 2.4G WiFi Tethering
1155        3. PhoneB disable data, connect to DUT's softAP
1156        4. Verify Internet access on DUT and PhoneB
1157        5. Disable WiFi Tethering on DUT.
1158        6. Verify DUT automatically connect to previous WiFI network
1159
1160        Returns:
1161            True if success.
1162            False if failed.
1163        """
1164        # Ensure provider connecting to wifi network.
1165        def setup_provider_internet_connection():
1166            return setup_device_internet_connection(self.log,
1167                                                    self.provider,
1168                                                    self.wifi_network_ssid,
1169                                                    self.wifi_network_pass)
1170
1171        if not test_wifi_tethering(self.log,
1172                                   self.provider,
1173                                   self.clients,
1174                                   [self.clients[0]],
1175                                   RAT_5G,
1176                                   WIFI_CONFIG_APBAND_2G,
1177                                   check_interval=10,
1178                                   check_iteration=2,
1179                                   pre_teardown_func=setup_provider_internet_connection,
1180                                   nr_type='nsa'):
1181            return False
1182
1183        if not wait_and_verify_device_internet_connection(self.log, self.provider):
1184            return False
1185        return True
1186
1187    """ Tests End """
1188