1#!/usr/bin/env python3.4
2#
3#   Copyright 2016 - Google
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16"""
17    Test Script for Telephony Pre Check In Sanity
18"""
19
20import collections
21import random
22import time
23import os
24
25from acts import signals
26from acts.test_decorators import test_tracker_info
27from acts.test_utils.tel.tel_subscription_utils import \
28    get_subid_from_slot_index
29from acts.test_utils.bt.bt_test_utils import bluetooth_enabled_check
30from acts.test_utils.bt.bt_test_utils import disable_bluetooth
31from acts.test_utils.bt.bt_test_utils import pair_pri_to_sec
32from acts.test_utils.tel.tel_subscription_utils import set_subid_for_data
33from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
34from acts.test_utils.tel.tel_defines import DIRECTION_MOBILE_ORIGINATED
35from acts.test_utils.tel.tel_defines import DIRECTION_MOBILE_TERMINATED
36from acts.test_utils.tel.tel_defines import DATA_STATE_CONNECTED
37from acts.test_utils.tel.tel_defines import GEN_2G
38from acts.test_utils.tel.tel_defines import GEN_3G
39from acts.test_utils.tel.tel_defines import GEN_4G
40from acts.test_utils.tel.tel_defines import NETWORK_SERVICE_DATA
41from acts.test_utils.tel.tel_defines import NETWORK_SERVICE_VOICE
42from acts.test_utils.tel.tel_defines import RAT_2G
43from acts.test_utils.tel.tel_defines import RAT_3G
44from acts.test_utils.tel.tel_defines import RAT_4G
45from acts.test_utils.tel.tel_defines import RAT_5G
46from acts.test_utils.tel.tel_defines import NETWORK_MODE_WCDMA_ONLY
47from acts.test_utils.tel.tel_defines import NETWORK_MODE_NR_LTE_GSM_WCDMA
48from acts.test_utils.tel.tel_defines import RAT_FAMILY_LTE
49from acts.test_utils.tel.tel_defines import SIM1_SLOT_INDEX
50from acts.test_utils.tel.tel_defines import SIM2_SLOT_INDEX
51from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_NW_SELECTION
52from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK
53from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_WIFI_CONNECTION
54from acts.test_utils.tel.tel_defines import TETHERING_MODE_WIFI
55from acts.test_utils.tel.tel_defines import WAIT_TIME_AFTER_REBOOT
56from acts.test_utils.tel.tel_defines import WAIT_TIME_AFTER_MODE_CHANGE
57from acts.test_utils.tel.tel_defines import WAIT_TIME_ANDROID_STATE_SETTLING
58from acts.test_utils.tel.tel_defines import WAIT_TIME_BETWEEN_REG_AND_CALL
59from acts.test_utils.tel.tel_defines import \
60    WAIT_TIME_DATA_STATUS_CHANGE_DURING_WIFI_TETHERING
61from acts.test_utils.tel.tel_defines import WAIT_TIME_TETHERING_AFTER_REBOOT
62from acts.test_utils.tel.tel_data_utils import airplane_mode_test
63from acts.test_utils.tel.tel_data_utils import browsing_test
64from acts.test_utils.tel.tel_data_utils import change_data_sim_and_verify_data
65from acts.test_utils.tel.tel_data_utils import data_connectivity_single_bearer
66from acts.test_utils.tel.tel_data_utils import tethering_check_internet_connection
67from acts.test_utils.tel.tel_data_utils import wifi_cell_switching
68from acts.test_utils.tel.tel_data_utils import wifi_tethering_cleanup
69from acts.test_utils.tel.tel_data_utils import wifi_tethering_setup_teardown
70from acts.test_utils.tel.tel_test_utils import active_file_download_test
71from acts.test_utils.tel.tel_test_utils import call_setup_teardown
72from acts.test_utils.tel.tel_test_utils import check_is_wifi_connected
73from acts.test_utils.tel.tel_test_utils import ensure_phones_default_state
74from acts.test_utils.tel.tel_test_utils import ensure_phones_idle
75from acts.test_utils.tel.tel_test_utils import ensure_network_generation
76from acts.test_utils.tel.tel_test_utils import \
77    ensure_network_generation_for_subscription
78from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
79from acts.test_utils.tel.tel_test_utils import get_mobile_data_usage
80from acts.test_utils.tel.tel_test_utils import get_slot_index_from_subid
81from acts.test_utils.tel.tel_test_utils import get_network_rat_for_subscription
82from acts.test_utils.tel.tel_test_utils import hangup_call
83from acts.test_utils.tel.tel_test_utils import multithread_func
84from acts.test_utils.tel.tel_test_utils import reboot_device
85from acts.test_utils.tel.tel_test_utils import remove_mobile_data_usage_limit
86from acts.test_utils.tel.tel_test_utils import set_call_state_listen_level
87from acts.test_utils.tel.tel_test_utils import set_mobile_data_usage_limit
88from acts.test_utils.tel.tel_test_utils import setup_sim
89from acts.test_utils.tel.tel_test_utils import stop_wifi_tethering
90from acts.test_utils.tel.tel_test_utils import start_wifi_tethering
91from acts.test_utils.tel.tel_test_utils import is_current_network_5g_nsa
92from acts.test_utils.tel.tel_test_utils import set_preferred_mode_for_5g
93from acts.test_utils.tel.tel_test_utils import get_current_override_network_type
94from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
95from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode_by_adb
96from acts.test_utils.tel.tel_test_utils import toggle_volte
97from acts.test_utils.tel.tel_test_utils import verify_internet_connection
98from acts.test_utils.tel.tel_test_utils import verify_http_connection
99from acts.test_utils.tel.tel_test_utils import verify_incall_state
100from acts.test_utils.tel.tel_test_utils import wait_for_network_generation
101from acts.test_utils.tel.tel_test_utils import wait_for_cell_data_connection
102from acts.test_utils.tel.tel_test_utils import wait_for_network_rat
103from acts.test_utils.tel.tel_test_utils import \
104    wait_for_voice_attach_for_subscription
105from acts.test_utils.tel.tel_test_utils import \
106    wait_for_data_attach_for_subscription
107from acts.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection
108from acts.test_utils.tel.tel_test_utils import wifi_reset
109from acts.test_utils.tel.tel_test_utils import wait_for_state
110from acts.test_utils.tel.tel_test_utils import wifi_toggle_state
111from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_2G
112from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_5G
113from acts.test_utils.tel.tel_test_utils import WIFI_SSID_KEY
114from acts.test_utils.tel.tel_test_utils import bring_up_sl4a
115from acts.test_utils.tel.tel_test_utils import check_data_stall_detection
116from acts.test_utils.tel.tel_test_utils import check_network_validation_fail
117from acts.test_utils.tel.tel_test_utils import break_internet_except_sl4a_port
118from acts.test_utils.tel.tel_test_utils import resume_internet_with_sl4a_port
119from acts.test_utils.tel.tel_test_utils import set_preferred_network_mode_pref
120from acts.test_utils.tel.tel_test_utils import get_device_epoch_time
121from acts.test_utils.tel.tel_test_utils import check_data_stall_recovery
122from acts.test_utils.tel.tel_test_utils import \
123    test_data_browsing_success_using_sl4a
124from acts.test_utils.tel.tel_test_utils import \
125    test_data_browsing_failure_using_sl4a
126from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_3g
127from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_csfb
128from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
129from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_3g
130from acts.test_utils.tel.tel_voice_utils import phone_setup_csfb
131from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_general
132from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
133from acts.test_utils.tel.tel_voice_utils import phone_setup_4g
134from acts.test_utils.tel.tel_voice_utils import phone_setup_5g
135from acts.utils import disable_doze
136from acts.utils import enable_doze
137from acts.utils import rand_ascii_str
138from acts.utils import adb_shell_ping
139
140
141class TelLiveDataTest(TelephonyBaseTest):
142    def setup_class(self):
143        super().setup_class()
144
145        self.stress_test_number = self.get_stress_test_number()
146        self.provider = self.android_devices[0]
147        self.clients = self.android_devices[1:]
148
149    def setup_test(self):
150        TelephonyBaseTest.setup_test(self)
151        self.number_of_devices = 1
152
153    def teardown_class(self):
154        TelephonyBaseTest.teardown_class(self)
155
156
157    """ Tests Begin """
158
159
160    @test_tracker_info(uuid="ba24f9a3-0126-436c-8a5c-9f88859c273c")
161    @TelephonyBaseTest.tel_test_wrap
162    def test_data_browsing_for_single_phone(self):
163        """ Browsing websites on cellular.
164
165        Ensure phone attach, data on, WiFi off
166        Verify 5 websites on cellular.
167
168        Returns:
169            True if pass; False if fail.
170        """
171        ad = self.android_devices[0]
172        wifi_toggle_state(ad.log, ad, False)
173        for iteration in range(3):
174            ad.log.info("Attempt %d", iteration + 1)
175            if test_data_browsing_success_using_sl4a(ad.log, ad):
176                ad.log.info("Call test PASS in iteration %d", iteration + 1)
177                return True
178            time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
179        ad.log.info("Data Browsing test FAIL for all 3 iterations")
180        return False
181
182
183    @test_tracker_info(uuid="0679214b-9002-476d-83a7-3532b3cca209")
184    @TelephonyBaseTest.tel_test_wrap
185    def test_wifi_browsing_for_single_phone(self):
186        """ Browsing websites on wifi.
187
188        Ensure phone attach, data on, WiFi On, WiFi Connected.
189        Verify 5 websites on WiFi.
190
191        Returns:
192            True if pass; False if fail.
193        """
194        ad = self.android_devices[0]
195        wifi_toggle_state(ad.log, ad, True)
196        if not ensure_wifi_connected(ad.log, ad, self.wifi_network_ssid,
197                                     self.wifi_network_pass):
198            ad.log.error("WiFi connect fail.")
199            return False
200        for iteration in range(3):
201            ad.log.info("Attempt %d", iteration + 1)
202            if test_data_browsing_success_using_sl4a(ad.log, ad):
203                ad.log.info("Call test PASS in iteration %d", iteration + 1)
204                wifi_toggle_state(ad.log, ad, False)
205                return True
206            time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
207        ad.log.info("Data Browsing test FAIL for all 3 iterations")
208        wifi_toggle_state(ad.log, ad, False)
209        return False
210
211
212    @test_tracker_info(uuid="769efc9b-d9a3-4b96-b830-351435895b62")
213    @TelephonyBaseTest.tel_test_wrap
214    def test_5g_nsa_activation_from_apm(self):
215        """ Verifies 5G NSA activation from Airplane Mode
216
217        Toggle Airplane mode on and off
218        Ensure phone attach, data on, LTE attach
219        Wait for 120 secs for ENDC attach
220        Verify is data network type is NR_NSA
221
222        Returns:
223            True if pass; False if fail.
224        """
225        ad = self.android_devices[0]
226        wifi_toggle_state(ad.log, ad, False)
227        for iteration in range(3):
228            ad.log.info("Attempt %d", iteration + 1)
229            # APM toggle
230            toggle_airplane_mode(ad.log, ad, True)
231            toggle_airplane_mode(ad.log, ad, False)
232            # LTE attach
233            if not wait_for_network_generation(
234                    ad.log, ad, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA):
235                ad.log.error("Fail to ensure initial data in 4G")
236            # 5G attach
237            ad.log.info("Waiting for 5g NSA attach for 60 secs")
238            if is_current_network_5g_nsa(ad, timeout=60):
239                ad.log.info("Success! attached on 5g NSA")
240                return True
241            else:
242                ad.log.error("Failure - expected NR_NSA, current %s",
243                             get_current_override_network_type(ad))
244            time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
245        ad.log.info("5g attach test FAIL for all 3 iterations")
246        return False
247
248
249    @test_tracker_info(uuid="0c2a407a-6d8f-4c94-9a9d-b16e5f884b0b")
250    @TelephonyBaseTest.tel_test_wrap
251    def test_5g_nsa_activation_from_reboot(self):
252        """ Verifies 5G NSA activation from Reboot
253
254        Reboot device
255        Ensure phone attach, data on, LTE attach
256        Wait for 120 secs for ENDC attach
257        Verify is data network type is NR_NSA
258
259        Returns:
260            True if pass; False if fail.
261        """
262        ad = self.android_devices[0]
263        wifi_toggle_state(ad.log, ad, False)
264        toggle_airplane_mode(ad.log, ad, False)
265        for iteration in range(3):
266            ad.log.info("Attempt %d", iteration + 1)
267            # Reboot phone
268            reboot_device(ad)
269            # LTE attach
270            if not wait_for_network_generation(
271                    ad.log, ad, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA):
272                ad.log.error("Fail to ensure initial data in 4G")
273            # 5G attach
274            ad.log.info("Waiting for 5g NSA attach for 60 secs")
275            if is_current_network_5g_nsa(ad, timeout=60):
276                ad.log.info("Success! attached on 5g NSA")
277                return True
278            else:
279                ad.log.error("Failure - expected NR_NSA, current %s",
280                             get_current_override_network_type(ad))
281            time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
282        ad.log.info("5g reboot test FAIL for all 3 iterations")
283        return False
284
285
286    @test_tracker_info(uuid="09893a9f-72eb-4718-aaf0-772155b7b104")
287    @TelephonyBaseTest.tel_test_wrap
288    def test_5g_nsa_activation_from_3g_mode(self):
289        """ Verifies 5G NSA activation from 3G Mode Pref
290
291        Change Mode to 3G and wait for 15 secs
292        Change Mode back to 5G
293        Ensure phone attach, data on, LTE attach
294        Wait for 120 secs for ENDC attach
295        Verify is data network type is NR_NSA
296
297        Returns:
298            True if pass; False if fail.
299        """
300        ad = self.android_devices[0]
301        sub_id = ad.droid.subscriptionGetDefaultSubId()
302        wifi_toggle_state(ad.log, ad, False)
303        toggle_airplane_mode(ad.log, ad, False)
304        for iteration in range(3):
305            ad.log.info("Attempt %d", iteration + 1)
306            # Set mode pref to 3G
307            set_preferred_network_mode_pref(ad.log, ad, sub_id,
308                                            NETWORK_MODE_WCDMA_ONLY)
309            time.sleep(15)
310            # Set mode pref to 5G
311            set_preferred_network_mode_pref(ad.log, ad, sub_id,
312                                            NETWORK_MODE_NR_LTE_GSM_WCDMA)
313            # LTE attach
314            if not wait_for_network_generation(
315                    ad.log, ad, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA):
316                ad.log.error("Fail to ensure initial data in 4G")
317            # 5G attach
318            ad.log.info("Waiting for 5g NSA attach for 60 secs")
319            if is_current_network_5g_nsa(ad, timeout=60):
320                ad.log.info("Success! attached on 5g NSA")
321                return True
322            else:
323                ad.log.error("Failure - expected NR_NSA, current %s",
324                             get_current_override_network_type(ad))
325            time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
326        ad.log.info("5g mode pref from 3G test FAIL for all 3 iterations")
327        return False
328
329
330    @test_tracker_info(uuid="1b0354f3-8668-4a28-90a5-3b3d2b2756d3")
331    @TelephonyBaseTest.tel_test_wrap
332    def test_airplane_mode(self):
333        """ Test airplane mode basic on Phone and Live SIM.
334
335        Ensure phone attach, data on, WiFi off and verify Internet.
336        Turn on airplane mode to make sure detach.
337        Turn off airplane mode to make sure attach.
338        Verify Internet connection.
339
340        Returns:
341            True if pass; False if fail.
342        """
343        return airplane_mode_test(self.log, self.android_devices[0])
344
345    @test_tracker_info(uuid="47430f01-583f-4efb-923a-285a51b75d50")
346    @TelephonyBaseTest.tel_test_wrap
347    def test_lte_wifi_switching(self):
348        """Test data connection network switching when phone camped on LTE.
349
350        Ensure phone is camped on LTE
351        Ensure WiFi can connect to live network,
352        Airplane mode is off, data connection is on, WiFi is on.
353        Turn off WiFi, verify data is on cell and browse to google.com is OK.
354        Turn on WiFi, verify data is on WiFi and browse to google.com is OK.
355        Turn off WiFi, verify data is on cell and browse to google.com is OK.
356
357        Returns:
358            True if pass.
359        """
360        return wifi_cell_switching(self.log, self.android_devices[0],
361                                   self.wifi_network_ssid,
362                                   self.wifi_network_pass, GEN_4G)
363
364    @test_tracker_info(uuid="98d9f8c9-0532-49b6-85a3-5246b8314755")
365    @TelephonyBaseTest.tel_test_wrap
366    def test_lte_wifi_switching_stress(self):
367        """LTE WiFi Switching Data Connection Check
368
369        Same steps as test_lte_wifi_switching with stress testing
370
371        Returns:
372            True if pass.
373        """
374        MINIMUM_SUCCESS_RATE = .95
375        success_count = 0
376        fail_count = 0
377        self.stress_test_number = 10
378
379        for i in range(1, self.stress_test_number + 1):
380            ensure_phones_default_state(
381                self.log, [self.android_devices[0]])
382
383            if wifi_cell_switching(self.log, self.android_devices[0],
384                                   self.wifi_network_ssid,
385                                   self.wifi_network_pass, GEN_4G):
386                success_count += 1
387                result_str = "Succeeded"
388            else:
389                fail_count += 1
390                result_str = "Failed"
391            self.log.info("Iteration {} {}. Current: {} / {} passed.".format(
392                i, result_str, success_count, self.stress_test_number))
393
394        self.log.info("Final Count - Success: {}, Failure: {} - {}%".format(
395            success_count, fail_count,
396            str(100 * success_count / (success_count + fail_count))))
397        if success_count / (
398                success_count + fail_count) >= MINIMUM_SUCCESS_RATE:
399            return True
400        else:
401            return False
402
403    @test_tracker_info(uuid="8a836cf1-600b-4cf3-abfe-2e3da5c11396")
404    @TelephonyBaseTest.tel_test_wrap
405    def test_wcdma_wifi_switching(self):
406        """Test data connection network switching when phone camped on WCDMA.
407
408        Ensure phone is camped on WCDMA
409        Ensure WiFi can connect to live network,
410        Airplane mode is off, data connection is on, WiFi is on.
411        Turn off WiFi, verify data is on cell and browse to google.com is OK.
412        Turn on WiFi, verify data is on WiFi and browse to google.com is OK.
413        Turn off WiFi, verify data is on cell and browse to google.com is OK.
414
415        Returns:
416            True if pass.
417        """
418        return wifi_cell_switching(self.log, self.android_devices[0],
419                                   self.wifi_network_ssid,
420                                   self.wifi_network_pass, GEN_3G)
421
422    @test_tracker_info(uuid="c016f2e8-0af6-42e4-a3cb-a2b7d8b564d0")
423    @TelephonyBaseTest.tel_test_wrap
424    def test_gsm_wifi_switching(self):
425        """Test data connection network switching when phone camped on GSM.
426
427        Ensure phone is camped on GSM
428        Ensure WiFi can connect to live network,,
429        Airplane mode is off, data connection is on, WiFi is on.
430        Turn off WiFi, verify data is on cell and browse to google.com is OK.
431        Turn on WiFi, verify data is on WiFi and browse to google.com is OK.
432        Turn off WiFi, verify data is on cell and browse to google.com is OK.
433
434        Returns:
435            True if pass.
436        """
437        return wifi_cell_switching(self.log, self.android_devices[0],
438                                   self.wifi_network_ssid,
439                                   self.wifi_network_pass, GEN_2G)
440
441    @test_tracker_info(uuid="78d6b258-82d4-47b4-8723-3b3a15412d2d")
442    @TelephonyBaseTest.tel_test_wrap
443    def test_lte_multi_bearer(self):
444        """Test LTE data connection before call and in call. (VoLTE call)
445
446
447        Turn off airplane mode, disable WiFi, enable Cellular Data.
448        Make sure phone in LTE, verify Internet.
449        Initiate a voice call. verify Internet.
450        Disable Cellular Data, verify Internet is inaccessible.
451        Enable Cellular Data, verify Internet.
452        Hangup Voice Call, verify Internet.
453
454        Returns:
455            True if success.
456            False if failed.
457        """
458        if not phone_setup_volte(self.log, self.android_devices[0]):
459            self.log.error("Failed to setup VoLTE")
460            return False
461        return self._test_data_connectivity_multi_bearer(GEN_4G)
462
463    @test_tracker_info(uuid="5c9cb076-0c26-4517-95dc-2ec4974e8ce3")
464    @TelephonyBaseTest.tel_test_wrap
465    def test_wcdma_multi_bearer(self):
466        """Test WCDMA data connection before call and in call.
467
468        Turn off airplane mode, disable WiFi, enable Cellular Data.
469        Make sure phone in WCDMA, verify Internet.
470        Initiate a voice call. verify Internet.
471        Disable Cellular Data, verify Internet is inaccessible.
472        Enable Cellular Data, verify Internet.
473        Hangup Voice Call, verify Internet.
474
475        Returns:
476            True if success.
477            False if failed.
478        """
479
480        return self._test_data_connectivity_multi_bearer(GEN_3G)
481
482    @test_tracker_info(uuid="314bbf1c-073f-4d48-9817-a6e14f96f3c0")
483    @TelephonyBaseTest.tel_test_wrap
484    def test_gsm_multi_bearer_mo(self):
485        """Test gsm data connection before call and in call.
486
487        Turn off airplane mode, disable WiFi, enable Cellular Data.
488        Make sure phone in GSM, verify Internet.
489        Initiate a MO voice call. Verify there is no Internet during call.
490        Hangup Voice Call, verify Internet.
491
492        Returns:
493            True if success.
494            False if failed.
495        """
496
497        return self._test_data_connectivity_multi_bearer(
498            GEN_2G, False, DIRECTION_MOBILE_ORIGINATED)
499
500    @test_tracker_info(uuid="549271ff-1034-4d02-8d92-b9d1b2bb912e")
501    @TelephonyBaseTest.tel_test_wrap
502    def test_gsm_multi_bearer_mt(self):
503        """Test gsm data connection before call and in call.
504
505        Turn off airplane mode, disable WiFi, enable Cellular Data.
506        Make sure phone in GSM, verify Internet.
507        Initiate a MT voice call. Verify there is no Internet during call.
508        Hangup Voice Call, verify Internet.
509
510        Returns:
511            True if success.
512            False if failed.
513        """
514
515        return self._test_data_connectivity_multi_bearer(
516            GEN_2G, False, DIRECTION_MOBILE_TERMINATED)
517
518    @test_tracker_info(uuid="111de471-559a-4bc3-9d3e-de18f098c162")
519    @TelephonyBaseTest.tel_test_wrap
520    def test_wcdma_multi_bearer_stress(self):
521        """Stress Test WCDMA data connection before call and in call.
522
523        This is a stress test for "test_wcdma_multi_bearer".
524        Default MINIMUM_SUCCESS_RATE is set to 95%.
525
526        Returns:
527            True stress pass rate is higher than MINIMUM_SUCCESS_RATE.
528            False otherwise.
529        """
530        MINIMUM_SUCCESS_RATE = .95
531        success_count = 0
532        fail_count = 0
533        self.number_of_devices = 2
534
535        for i in range(1, self.stress_test_number + 1):
536
537            ensure_phones_default_state(
538                self.log, [self.android_devices[0], self.android_devices[1]])
539
540            if self.test_wcdma_multi_bearer():
541                success_count += 1
542                result_str = "Succeeded"
543            else:
544                fail_count += 1
545                result_str = "Failed"
546            self.log.info("Iteration {} {}. Current: {} / {} passed.".format(
547                i, result_str, success_count, self.stress_test_number))
548
549        self.log.info("Final Count - Success: {}, Failure: {} - {}%".format(
550            success_count, fail_count,
551            str(100 * success_count / (success_count + fail_count))))
552        if success_count / (
553                success_count + fail_count) >= MINIMUM_SUCCESS_RATE:
554            return True
555        else:
556            return False
557
558    @test_tracker_info(uuid="c7f14ba7-7ac3-45d2-b391-5ed5c4b0e70b")
559    @TelephonyBaseTest.tel_test_wrap
560    def test_lte_multi_bearer_stress(self):
561        """Stress Test LTE data connection before call and in call. (VoLTE call)
562
563        This is a stress test for "test_lte_multi_bearer".
564        Default MINIMUM_SUCCESS_RATE is set to 95%.
565
566        Returns:
567            True stress pass rate is higher than MINIMUM_SUCCESS_RATE.
568            False otherwise.
569        """
570        ads = self.android_devices
571        MINIMUM_SUCCESS_RATE = .95
572        success_count = 0
573        fail_count = 0
574
575        for i in range(1, self.stress_test_number + 1):
576
577            ensure_phones_default_state(
578                self.log, [self.android_devices[0], self.android_devices[1]])
579
580            if self.test_lte_multi_bearer():
581                success_count += 1
582                result_str = "Succeeded"
583            else:
584                fail_count += 1
585                result_str = "Failed"
586            self.log.info("Iteration {} {}. Current: {} / {} passed.".format(
587                i, result_str, success_count, self.stress_test_number))
588
589        self.log.info("Final Count - Success: {}, Failure: {} - {}%".format(
590            success_count, fail_count,
591            str(100 * success_count / (success_count + fail_count))))
592        if success_count / (
593                success_count + fail_count) >= MINIMUM_SUCCESS_RATE:
594            return True
595        else:
596            return False
597
598    def _test_data_connectivity_multi_bearer(
599            self,
600            nw_gen,
601            simultaneous_voice_data=True,
602            call_direction=DIRECTION_MOBILE_ORIGINATED):
603        """Test data connection before call and in call.
604
605        Turn off airplane mode, disable WiFi, enable Cellular Data.
606        Make sure phone in <nw_gen>, verify Internet.
607        Initiate a voice call.
608        if simultaneous_voice_data is True, then:
609            Verify Internet.
610            Disable Cellular Data, verify Internet is inaccessible.
611            Enable Cellular Data, verify Internet.
612        if simultaneous_voice_data is False, then:
613            Verify Internet is not available during voice call.
614        Hangup Voice Call, verify Internet.
615
616        Returns:
617            True if success.
618            False if failed.
619        """
620
621        class _LocalException(Exception):
622            pass
623
624        self.number_of_devices = 2
625        ad_list = [self.android_devices[0], self.android_devices[1]]
626        ensure_phones_idle(self.log, ad_list)
627
628        if not ensure_network_generation_for_subscription(
629                self.log, self.android_devices[0], self.android_devices[0]
630                .droid.subscriptionGetDefaultDataSubId(), nw_gen,
631                MAX_WAIT_TIME_NW_SELECTION, NETWORK_SERVICE_DATA):
632            self.log.error("Device failed to reselect in {}s.".format(
633                MAX_WAIT_TIME_NW_SELECTION))
634            return False
635
636        if not wait_for_voice_attach_for_subscription(
637                self.log, self.android_devices[0], self.android_devices[0]
638                .droid.subscriptionGetDefaultVoiceSubId(),
639                MAX_WAIT_TIME_NW_SELECTION):
640            return False
641
642        self.log.info("Step1 WiFi is Off, Data is on Cell.")
643        toggle_airplane_mode(self.log, self.android_devices[0], False)
644        wifi_toggle_state(self.log, self.android_devices[0], False)
645        self.android_devices[0].droid.telephonyToggleDataConnection(True)
646        if (not wait_for_cell_data_connection(self.log,
647                                              self.android_devices[0], True)
648                or not verify_internet_connection(self.log,
649                                                  self.android_devices[0])):
650            self.log.error("Data not available on cell")
651            return False
652
653        self.log.info(
654            "b/69431819, sending data to increase NW threshold limit")
655        adb_shell_ping(
656            self.android_devices[0], count=30, timeout=60, loss_tolerance=100)
657
658        try:
659            self.log.info("Step2 Initiate call and accept.")
660            if call_direction == DIRECTION_MOBILE_ORIGINATED:
661                ad_caller = self.android_devices[0]
662                ad_callee = self.android_devices[1]
663            else:
664                ad_caller = self.android_devices[1]
665                ad_callee = self.android_devices[0]
666            if not call_setup_teardown(self.log, ad_caller, ad_callee, None,
667                                       None, None):
668                self.log.error(
669                    "Failed to Establish {} Voice Call".format(call_direction))
670                return False
671            if simultaneous_voice_data:
672                self.log.info("Step3 Verify internet.")
673                time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
674                if not verify_internet_connection(
675                        self.log, self.android_devices[0], retries=3):
676                    raise _LocalException("Internet Inaccessible when Enabled")
677
678                self.log.info("Step4 Turn off data and verify not connected.")
679                self.android_devices[0].droid.telephonyToggleDataConnection(
680                    False)
681                if not wait_for_cell_data_connection(
682                        self.log, self.android_devices[0], False):
683                    raise _LocalException("Failed to Disable Cellular Data")
684
685                if not verify_internet_connection(self.log,
686                                              self.android_devices[0], expected_state=False):
687                    raise _LocalException("Internet Accessible when Disabled")
688
689                self.log.info("Step5 Re-enable data.")
690                self.android_devices[0].droid.telephonyToggleDataConnection(
691                    True)
692                if not wait_for_cell_data_connection(
693                        self.log, self.android_devices[0], True):
694                    raise _LocalException("Failed to Re-Enable Cellular Data")
695                if not verify_internet_connection(
696                        self.log, self.android_devices[0], retries=3):
697                    raise _LocalException("Internet Inaccessible when Enabled")
698            else:
699                self.log.info("Step3 Verify no Internet and skip step 4-5.")
700                if verify_internet_connection(
701                        self.log, self.android_devices[0], retries=0):
702                    raise _LocalException("Internet Accessible.")
703
704            self.log.info("Step6 Verify phones still in call and Hang up.")
705            if not verify_incall_state(
706                    self.log,
707                [self.android_devices[0], self.android_devices[1]], True):
708                return False
709            if not hangup_call(self.log, self.android_devices[0]):
710                self.log.error("Failed to hang up call")
711                return False
712            if not verify_internet_connection(
713                    self.log, self.android_devices[0], retries=3):
714                raise _LocalException("Internet Inaccessible when Enabled")
715
716        except _LocalException as e:
717            self.log.error(str(e))
718            try:
719                hangup_call(self.log, self.android_devices[0])
720                self.android_devices[0].droid.telephonyToggleDataConnection(
721                    True)
722            except Exception:
723                pass
724            return False
725
726        return True
727
728    @test_tracker_info(uuid="dcb9bdc6-dbe2-47e1-9c2d-6f37c529d366")
729    @TelephonyBaseTest.tel_test_wrap
730    def test_2g(self):
731        """Test data connection in 2G.
732
733        Turn off airplane mode, disable WiFi, enable Cellular Data.
734        Ensure phone data generation is 2G.
735        Verify Internet.
736        Disable Cellular Data, verify Internet is inaccessible.
737        Enable Cellular Data, verify Internet.
738
739        Returns:
740            True if success.
741            False if failed.
742        """
743        wifi_reset(self.log, self.android_devices[0])
744        wifi_toggle_state(self.log, self.android_devices[0], False)
745        return data_connectivity_single_bearer(self.log,
746                                               self.android_devices[0], RAT_2G)
747
748    @test_tracker_info(uuid="84197a49-d73f-44ce-8b9e-9479e5c4dfdc")
749    @TelephonyBaseTest.tel_test_wrap
750    def test_2g_wifi_not_associated(self):
751        """Test data connection in 2G.
752
753        Turn off airplane mode, enable WiFi (but not connected), enable Cellular Data.
754        Ensure phone data generation is 2G.
755        Verify Internet.
756        Disable Cellular Data, verify Internet is inaccessible.
757        Enable Cellular Data, verify Internet.
758
759        Returns:
760            True if success.
761            False if failed.
762        """
763        wifi_reset(self.log, self.android_devices[0])
764        wifi_toggle_state(self.log, self.android_devices[0], False)
765        wifi_toggle_state(self.log, self.android_devices[0], True)
766        return data_connectivity_single_bearer(self.log,
767                                               self.android_devices[0], RAT_2G)
768
769    @test_tracker_info(uuid="97067ebb-130a-4fcb-8e6b-f4ec5874828f")
770    @TelephonyBaseTest.tel_test_wrap
771    def test_3g(self):
772        """Test data connection in 3G.
773
774        Turn off airplane mode, disable WiFi, enable Cellular Data.
775        Ensure phone data generation is 3G.
776        Verify Internet.
777        Disable Cellular Data, verify Internet is inaccessible.
778        Enable Cellular Data, verify Internet.
779
780        Returns:
781            True if success.
782            False if failed.
783        """
784        wifi_reset(self.log, self.android_devices[0])
785        wifi_toggle_state(self.log, self.android_devices[0], False)
786        return data_connectivity_single_bearer(self.log,
787                                               self.android_devices[0], RAT_3G)
788
789    @test_tracker_info(uuid="ffe2a392-95b8-4a4d-8a6f-bfa846c3462f")
790    @TelephonyBaseTest.tel_test_wrap
791    def test_3g_wifi_not_associated(self):
792        """Test data connection in 3G.
793
794        Turn off airplane mode, enable WiFi (but not connected), enable Cellular Data.
795        Ensure phone data generation is 3G.
796        Verify Internet.
797        Disable Cellular Data, verify Internet is inaccessible.
798        Enable Cellular Data, verify Internet.
799
800        Returns:
801            True if success.
802            False if failed.
803        """
804        wifi_reset(self.log, self.android_devices[0])
805        wifi_toggle_state(self.log, self.android_devices[0], False)
806        wifi_toggle_state(self.log, self.android_devices[0], True)
807        return data_connectivity_single_bearer(self.log,
808                                               self.android_devices[0], RAT_3G)
809
810    @test_tracker_info(uuid="9c2f459f-1aac-4c68-818b-8698e8124c8b")
811    @TelephonyBaseTest.tel_test_wrap
812    def test_4g(self):
813        """Test data connection in 4g.
814
815        Turn off airplane mode, disable WiFi, enable Cellular Data.
816        Ensure phone data generation is 4g.
817        Verify Internet.
818        Disable Cellular Data, verify Internet is inaccessible.
819        Enable Cellular Data, verify Internet.
820
821        Returns:
822            True if success.
823            False if failed.
824        """
825        wifi_reset(self.log, self.android_devices[0])
826        wifi_toggle_state(self.log, self.android_devices[0], False)
827        return data_connectivity_single_bearer(self.log,
828                                               self.android_devices[0], RAT_4G)
829
830    @test_tracker_info(uuid="015a39a1-15ac-4b76-962b-d7d82d52d425")
831    @TelephonyBaseTest.tel_test_wrap
832    def test_4g_wifi_not_associated(self):
833        """Test data connection in 4g.
834
835        Turn off airplane mode, enable WiFi (but not connected), enable Cellular Data.
836        Ensure phone data generation is 4g.
837        Verify Internet.
838        Disable Cellular Data, verify Internet is inaccessible.
839        Enable Cellular Data, verify Internet.
840
841        Returns:
842            True if success.
843            False if failed.
844        """
845        wifi_reset(self.log, self.android_devices[0])
846        wifi_toggle_state(self.log, self.android_devices[0], False)
847        wifi_toggle_state(self.log, self.android_devices[0], True)
848        return data_connectivity_single_bearer(self.log,
849                                               self.android_devices[0], RAT_4G)
850
851    @test_tracker_info(uuid="44f47b64-f8bc-4a17-9195-42dcca0806bb")
852    @TelephonyBaseTest.tel_test_wrap
853    def test_3g_stress(self):
854        """Stress Test data connection in 3G.
855
856        This is a stress test for "test_3g".
857        Default MINIMUM_SUCCESS_RATE is set to 95%.
858
859        Returns:
860            True stress pass rate is higher than MINIMUM_SUCCESS_RATE.
861            False otherwise.
862        """
863        MINIMUM_SUCCESS_RATE = .95
864        success_count = 0
865        fail_count = 0
866
867        for i in range(1, self.stress_test_number + 1):
868
869            ensure_phones_default_state(self.log, [self.android_devices[0]])
870            wifi_reset(self.log, self.android_devices[0])
871            wifi_toggle_state(self.log, self.android_devices[0], False)
872
873            if data_connectivity_single_bearer(
874                    self.log, self.android_devices[0], RAT_3G):
875                success_count += 1
876                result_str = "Succeeded"
877            else:
878                fail_count += 1
879                result_str = "Failed"
880            self.log.info("Iteration {} {}. Current: {} / {} passed.".format(
881                i, result_str, success_count, self.stress_test_number))
882
883        self.log.info("Final Count - Success: {}, Failure: {} - {}%".format(
884            success_count, fail_count,
885            str(100 * success_count / (success_count + fail_count))))
886        if success_count / (
887                success_count + fail_count) >= MINIMUM_SUCCESS_RATE:
888            return True
889        else:
890            return False
891
892    @test_tracker_info(uuid="c8876388-0441-4a51-81e6-ac2cb358a531")
893    @TelephonyBaseTest.tel_test_wrap
894    def test_4g_stress(self):
895        """Stress Test data connection in 4g.
896
897        This is a stress test for "test_4g".
898        Default MINIMUM_SUCCESS_RATE is set to 95%.
899
900        Returns:
901            True stress pass rate is higher than MINIMUM_SUCCESS_RATE.
902            False otherwise.
903        """
904        MINIMUM_SUCCESS_RATE = .95
905        success_count = 0
906        fail_count = 0
907        self.number_of_devices = 1
908
909        for i in range(1, self.stress_test_number + 1):
910
911            ensure_phones_default_state(self.log, [self.android_devices[0]])
912            wifi_reset(self.log, self.android_devices[0])
913            wifi_toggle_state(self.log, self.android_devices[0], False)
914
915            if data_connectivity_single_bearer(
916                    self.log, self.android_devices[0], RAT_4G):
917                success_count += 1
918                result_str = "Succeeded"
919            else:
920                fail_count += 1
921                result_str = "Failed"
922            self.log.info("Iteration {} {}. Current: {} / {} passed.".format(
923                i, result_str, success_count, self.stress_test_number))
924
925        self.log.info("Final Count - Success: {}, Failure: {} - {}%".format(
926            success_count, fail_count,
927            str(100 * success_count / (success_count + fail_count))))
928        if success_count / (
929                success_count + fail_count) >= MINIMUM_SUCCESS_RATE:
930            return True
931        else:
932            return False
933
934    def _test_setup_tethering(self, network_generation=None):
935        """Pre setup steps for WiFi tethering test.
936
937        Ensure all ads are idle.
938        Ensure tethering provider:
939            turn off APM, turn off WiFI, turn on Data.
940            have Internet connection, no active ongoing WiFi tethering.
941
942        Returns:
943            True if success.
944            False if failed.
945        """
946        self.number_of_devices = None
947        ensure_phones_idle(self.log, self.android_devices)
948        wifi_toggle_state(self.log, self.provider, False)
949        if network_generation == RAT_5G:
950            # Attach 5g
951            set_preferred_mode_for_5g(self.provider)
952            if not is_current_network_5g_nsa(self.provider):
953                self.provider.log.error("Provider not attached on 5G NSA")
954                return False
955        elif network_generation:
956            if not ensure_network_generation(
957                    self.log, self.provider, network_generation,
958                    MAX_WAIT_TIME_NW_SELECTION, NETWORK_SERVICE_DATA):
959                self.provider.log.error("Provider failed to connect to %s.",
960                                        network_generation)
961                return False
962        else:
963            self.log.debug("Skipping network generation since it is None")
964
965        self.provider.log.info(
966            "Set provider Airplane Off, Wifi Off, Bluetooth Off, Data On.")
967        toggle_airplane_mode(self.log, self.provider, False)
968        self.provider.droid.telephonyToggleDataConnection(True)
969        self.provider.log.info("Provider disable wifi")
970        wifi_toggle_state(self.log, self.provider, False)
971        # Turn off active SoftAP if any.
972        if self.provider.droid.wifiIsApEnabled():
973            self.provider.log.info("Disable provider wifi tethering")
974            stop_wifi_tethering(self.log, self.provider)
975        self.provider.log.info("Provider disable bluetooth")
976        disable_bluetooth(self.provider.droid)
977        time.sleep(10)
978
979        for ad in self.clients:
980            ad.log.info(
981                "Set client Airplane Off, Wifi Off, Bluetooth Off, Data Off.")
982            toggle_airplane_mode(self.log, ad, False)
983            ad.log.info("Client disable data")
984            ad.droid.telephonyToggleDataConnection(False)
985            ad.log.info("Client disable bluetooth")
986            disable_bluetooth(ad.droid)
987            ad.log.info("Client disable wifi")
988            wifi_toggle_state(self.log, ad, False)
989        if not wait_for_cell_data_connection(self.log, self.provider, True):
990            self.provider.log.error(
991                "Provider failed to enable data connection.")
992            return False
993
994        time.sleep(10)
995        self.log.info("Verify internet")
996        if not self._test_internet_connection(
997                client_status=False, provider_status=True):
998            self.log.error("Internet connection check failed before tethering")
999            return False
1000
1001        return True
1002
1003    def _enable_bluetooth_tethering_connection(self, provider, clients):
1004        for ad in [self.provider] + self.clients:
1005            if not bluetooth_enabled_check(ad):
1006                ad.log.info("Bluetooth is not enabled")
1007                return False
1008            else:
1009                ad.log.info("Bluetooth is enabled")
1010        time.sleep(5)
1011        self.provider.log.info("Provider enabling bluetooth tethering")
1012        try:
1013            provider.droid.bluetoothPanSetBluetoothTethering(True)
1014        except Exception as e:
1015            provider.log.warning(
1016                "Failed to enable provider Bluetooth tethering with %s", e)
1017            provider.droid.bluetoothPanSetBluetoothTethering(True)
1018
1019        if wait_for_state(provider.droid.bluetoothPanIsTetheringOn, True):
1020            provider.log.info("Provider Bluetooth tethering is enabled.")
1021        else:
1022            provider.log.error(
1023                "Failed to enable provider Bluetooth tethering.")
1024            provider.log.error("bluetoothPanIsTetheringOn = %s",
1025                               provider.droid.bluetoothPanIsTetheringOn())
1026            return False
1027        for client in self.clients:
1028            if not (pair_pri_to_sec(self.provider, client)):
1029                client.log.error("Client failed to pair with provider")
1030                return False
1031            else:
1032                client.log.info("Client paired with provider")
1033        time.sleep(5)
1034        for client in clients:
1035            client.droid.bluetoothConnectBonded(
1036                provider.droid.bluetoothGetLocalAddress())
1037        time.sleep(20)
1038        return True
1039
1040    def _test_internet_connection(self,
1041                                  client_status=True,
1042                                  provider_status=True):
1043        client_retry = 10 if client_status else 1
1044        for client in self.clients:
1045            if not verify_internet_connection(
1046                    self.log,
1047                    client,
1048                    retries=client_retry,
1049                    expected_state=client_status):
1050                client.log.error("client internet connection state is not %s",
1051                                 client_status)
1052                return False
1053            else:
1054                client.log.info("client internet connection state is %s",
1055                                client_status)
1056        if not verify_internet_connection(
1057                self.log, self.provider, retries=3,
1058                expected_state=provider_status):
1059            self.provider.log.error(
1060                "provider internet connection is not %s" % provider_status)
1061            return False
1062        else:
1063            self.provider.log.info(
1064                "provider internet connection is %s" % provider_status)
1065        return True
1066
1067    def _verify_bluetooth_tethering_connection(self,
1068                                               change_rat=None,
1069                                               toggle_data=False,
1070                                               toggle_tethering=False,
1071                                               voice_call=False,
1072                                               toggle_bluetooth=True):
1073        """Setups up a bluetooth tethering conenction between two android devices.
1074
1075        Returns:
1076            True if PAN connection and verification is successful,
1077            false if unsuccessful.
1078        """
1079        if not self._enable_bluetooth_tethering_connection(
1080                self.provider, self.clients):
1081            return False
1082        if not self._test_internet_connection():
1083            self.log.error("Internet connection check failed")
1084            return False
1085        if voice_call:
1086            self.log.info("====== Voice call test =====")
1087            for caller, callee in [(self.provider, self.clients[0]),
1088                                   (self.clients[0], self.provider)]:
1089                if not call_setup_teardown(
1090                        self.log, caller, callee, ad_hangup=None):
1091                    self.log.error("Setup Call Failed.")
1092                    hangup_call(self.log, caller)
1093                    return False
1094                self.log.info("Verify data.")
1095                if not verify_internet_connection(
1096                        self.log, self.clients[0], retries=1):
1097                    self.clients[0].log.warning(
1098                        "client internet connection state is not on")
1099                else:
1100                    self.clients[0].log.info(
1101                        "client internet connection state is on")
1102                hangup_call(self.log, caller)
1103                if not verify_internet_connection(
1104                        self.log, self.clients[0], retries=1):
1105                    self.clients[0].log.warning(
1106                        "client internet connection state is not on")
1107                    return False
1108                else:
1109                    self.clients[0].log.info(
1110                        "client internet connection state is on")
1111        if toggle_tethering:
1112            self.log.info("====== Toggling provider bluetooth tethering =====")
1113            self.provider.log.info("Disable bluetooth tethering")
1114            self.provider.droid.bluetoothPanSetBluetoothTethering(False)
1115            if not self._test_internet_connection(False, True):
1116                self.log.error(
1117                    "Internet connection check failed after disable tethering")
1118                return False
1119            self.provider.log.info("Enable bluetooth tethering")
1120            if not self._enable_bluetooth_tethering_connection(
1121                    self.provider, self.clients):
1122                self.provider.log.error(
1123                    "Fail to re-enable bluetooth tethering")
1124                return False
1125            if not self._test_internet_connection(True, True):
1126                self.log.error(
1127                    "Internet connection check failed after enable tethering")
1128                return False
1129        if toggle_bluetooth:
1130            self.log.info("====== Toggling provider bluetooth =====")
1131            self.provider.log.info("Disable provider bluetooth")
1132            disable_bluetooth(self.provider.droid)
1133            time.sleep(10)
1134            if not self._test_internet_connection(False, True):
1135                self.log.error(
1136                    "Internet connection check failed after disable bluetooth")
1137                return False
1138            if not self._enable_bluetooth_tethering_connection(
1139                    self.provider, self.clients):
1140                self.provider.log.error(
1141                    "Fail to re-enable bluetooth tethering")
1142                return False
1143            if not self._test_internet_connection(True, True):
1144                self.log.error(
1145                    "Internet connection check failed after enable bluetooth")
1146                return False
1147        if toggle_data:
1148            self.log.info("===== Toggling provider data connection =====")
1149            self.provider.log.info("Disable provider data connection")
1150            self.provider.droid.telephonyToggleDataConnection(False)
1151            time.sleep(10)
1152            if not self._test_internet_connection(False, False):
1153                return False
1154            self.provider.log.info("Enable provider data connection")
1155            self.provider.droid.telephonyToggleDataConnection(True)
1156            if not wait_for_cell_data_connection(self.log, self.provider,
1157                                                 True):
1158                self.provider.log.error(
1159                    "Provider failed to enable data connection.")
1160                return False
1161            if not self._test_internet_connection(True, True):
1162                self.log.error(
1163                    "Internet connection check failed after enable data")
1164                return False
1165        if change_rat:
1166            self.log.info("===== Change provider RAT to %s =====", change_rat)
1167            if not ensure_network_generation(
1168                    self.log,
1169                    self.provider,
1170                    change_rat,
1171                    voice_or_data=NETWORK_SERVICE_DATA,
1172                    toggle_apm_after_setting=False):
1173                self.provider.log.error("Provider failed to reselect to %s.",
1174                                        change_rat)
1175                return False
1176            if not self._test_internet_connection(True, True):
1177                self.log.error(
1178                    "Internet connection check failed after RAT change to %s",
1179                    change_rat)
1180                return False
1181        return True
1182
1183    @test_tracker_info(uuid="2d945656-22f7-4610-9a84-40ce04d603a4")
1184    @TelephonyBaseTest.tel_test_wrap
1185    def test_tethering_4g_to_bluetooth(self):
1186        """Bluetooth Tethering test: LTE to Bluetooth Tethering
1187
1188        1. DUT in LTE mode, idle.
1189        2. DUT start Bluetooth Tethering
1190        3. PhoneB disable data, connect to DUT's softAP
1191        4. Verify Internet access on DUT and PhoneB
1192        5. Toggle provider bluetooth connection
1193        6. Verify Internet access on DUT and PhoneB
1194
1195        Returns:
1196            True if success.
1197            False if failed.
1198        """
1199        if not self._test_setup_tethering(RAT_4G):
1200            self.log.error("Verify 4G Internet access failed.")
1201            return False
1202
1203        return self._verify_bluetooth_tethering_connection()
1204
1205    @test_tracker_info(uuid="8d2ae56b-c2c1-4c32-9b8e-5044007b5b90")
1206    @TelephonyBaseTest.tel_test_wrap
1207    def test_tethering_4g_to_bluetooth_with_voice_call(self):
1208        """Bluetooth Tethering test: LTE to Bluetooth Tethering
1209
1210        1. DUT in LTE mode, idle.
1211        2. DUT start Bluetooth Tethering
1212        3. PhoneB disable data, connect to DUT's softAP
1213        4. Verify Internet access on DUT and PhoneB
1214        5. Verify provider and client are able to make or receive phone call
1215        6. Verify Internet access on DUT and PhoneB
1216
1217        Returns:
1218            True if success.
1219            False if failed.
1220        """
1221        if not self._test_setup_tethering(RAT_4G):
1222            self.log.error("Verify 4G Internet access failed.")
1223            return False
1224
1225        return self._verify_bluetooth_tethering_connection(
1226            toggle_tethering=False, toggle_bluetooth=False, voice_call=True)
1227
1228    @test_tracker_info(uuid="b4617727-fa83-4451-89d7-7e574c0a0938")
1229    @TelephonyBaseTest.tel_test_wrap
1230    def test_tethering_4g_to_bluetooth_toggle_data(self):
1231        """Bluetooth Tethering test: LTE to Bluetooth Tethering
1232
1233        1. DUT in LTE mode, idle.
1234        2. DUT start Bluetooth Tethering
1235        3. PhoneB disable data, connect to DUT's softAP
1236        4. Verify Internet access on DUT and PhoneB
1237        5. Toggle provider data connection
1238        6. Verify Internet access on DUT and PhoneB
1239
1240        Returns:
1241            True if success.
1242            False if failed.
1243        """
1244        if not self._test_setup_tethering(RAT_4G):
1245            self.log.error("Verify 4G Internet access failed.")
1246            return False
1247
1248        return self._verify_bluetooth_tethering_connection(
1249            toggle_tethering=False, toggle_bluetooth=False, toggle_data=True)
1250
1251    @test_tracker_info(uuid="6a0f6001-609d-41f2-ad09-c8ae19f73ac8")
1252    @TelephonyBaseTest.tel_test_wrap
1253    def test_tethering_4g_to_bluetooth_toggle_tethering(self):
1254        """Bluetooth Tethering test: LTE to Bluetooth Tethering
1255
1256        1. DUT in LTE mode, idle.
1257        2. DUT start Bluetooth Tethering
1258        3. PhoneB disable data, connect to DUT's softAP
1259        4. Verify Internet access on DUT and PhoneB
1260        5. Toggle provider bluetooth tethering
1261        6. Verify Internet access on DUT and PhoneB
1262
1263        Returns:
1264            True if success.
1265            False if failed.
1266        """
1267        if not self._test_setup_tethering(RAT_4G):
1268            self.log.error("Verify 4G Internet access failed.")
1269            return False
1270
1271        return self._verify_bluetooth_tethering_connection(
1272            toggle_tethering=True, toggle_bluetooth=False, toggle_data=False)
1273
1274    @test_tracker_info(uuid="b1abc1ac-8018-4956-a17e-bf2ceaf264ea")
1275    @TelephonyBaseTest.tel_test_wrap
1276    def test_tethering_3g_to_bluetooth(self):
1277        """Bluetooth Tethering test: 3G to Bluetoothing Tethering
1278
1279        1. DUT in 3G mode, idle.
1280        2. DUT start bluetooth Tethering
1281        3. PhoneB disable data, connect to DUT's softAP
1282        4. Verify Internet access on DUT and PhoneB
1283        5. Toggle provider bluetooth connection
1284        6. Verify Internet access on DUT and PhoneB
1285
1286        Returns:
1287            True if success.
1288            False if failed.
1289        """
1290        if not self._test_setup_tethering(RAT_3G):
1291            self.log.error("Verify 3G Internet access failed.")
1292            return False
1293
1294        return self._verify_bluetooth_tethering_connection()
1295
1296    @test_tracker_info(uuid="69793745-0c49-4cef-9879-d372e3a3f4c7")
1297    @TelephonyBaseTest.tel_test_wrap
1298    def test_tethering_3g_to_bluetooth_with_voice_call(self):
1299        """Bluetooth Tethering test: 3G to Bluetooth Tethering
1300
1301        1. DUT in 3G mode, idle.
1302        2. DUT start Bluetooth Tethering
1303        3. PhoneB disable data, connect to DUT's softAP
1304        4. Verify Internet access on DUT and PhoneB
1305        5. Verify provider and client are able to make or receive phone call
1306        6. Verify Internet access on DUT and PhoneB
1307
1308        Returns:
1309            True if success.
1310            False if failed.
1311        """
1312        if not self._test_setup_tethering(RAT_3G):
1313            self.log.error("Verify 3G Internet access failed.")
1314            return False
1315
1316        return self._verify_bluetooth_tethering_connection(
1317            toggle_tethering=False, toggle_bluetooth=False, voice_call=True)
1318
1319    @test_tracker_info(uuid="4275ee69-dfdf-4f47-82c5-4224fceee761")
1320    @TelephonyBaseTest.tel_test_wrap
1321    def test_tethering_3g_to_bluetooth_toggle_data(self):
1322        """Bluetooth Tethering test: 3G to Bluetoothing Tethering
1323
1324        1. DUT in 3G mode, idle.
1325        2. DUT start bluetooth Tethering
1326        3. PhoneB disable data, connect to DUT's softAP
1327        4. Verify Internet access on DUT and PhoneB
1328        5. Toggle provider data connection
1329        6. Verify Internet access on DUT and PhoneB
1330
1331        Returns:
1332            True if success.
1333            False if failed.
1334        """
1335        if not self._test_setup_tethering(RAT_3G):
1336            self.log.error("Verify 3G Internet access failed.")
1337            return False
1338
1339        return self._verify_bluetooth_tethering_connection(
1340            toggle_tethering=False, toggle_bluetooth=False, toggle_data=True)
1341
1342    @test_tracker_info(uuid="db0e0f27-1a4f-4301-832d-b66415e289f3")
1343    @TelephonyBaseTest.tel_test_wrap
1344    def test_tethering_2g_to_bluetooth(self):
1345        """Bluetooth Tethering test: 2G to Bluetooth Tethering
1346
1347        1. DUT in 2G mode, idle.
1348        2. DUT start bluetooth Tethering
1349        3. PhoneB disable data, connect to DUT's softAP
1350        4. Verify Internet access on DUT and PhoneB
1351        5. Toggle provider bluetooth connection
1352        6. Verify Internet access on DUT and PhoneB
1353
1354        Returns:
1355            True if success.
1356            False if failed.
1357        """
1358        for a in self.android_devices:
1359            a.adb.shell("setprop persist.bluetooth.btsnoopenable true")
1360            if not toggle_airplane_mode_by_adb(self.log, a, True):
1361                self.log.error("Failed to toggle airplane mode on")
1362                return False
1363            if not toggle_airplane_mode_by_adb(self.log, a, False):
1364                self.log.error("Failed to toggle airplane mode off")
1365                return False
1366
1367        if not self._test_setup_tethering(RAT_2G):
1368            self.log.error("Verify 3G Internet access failed.")
1369            return False
1370
1371        return self._verify_bluetooth_tethering_connection()
1372
1373    @test_tracker_info(uuid="584e9fa5-a38e-47cd-aa33-fcf8d72c423e")
1374    @TelephonyBaseTest.tel_test_wrap
1375    def test_tethering_2g_to_bluetooth_with_voice_call(self):
1376        """Bluetooth Tethering test: 2G to Bluetooth Tethering
1377
1378        1. DUT in 2G mode, idle.
1379        2. DUT start Bluetooth Tethering
1380        3. PhoneB disable data, connect to DUT's softAP
1381        4. Verify Internet access on DUT and PhoneB
1382        5. Verify provider and client are able to make or receive phone call
1383        6. Verify Internet access on DUT and PhoneB
1384
1385        Returns:
1386            True if success.
1387            False if failed.
1388        """
1389        if not self._test_setup_tethering(RAT_2G):
1390            self.log.error("Verify 2G Internet access failed.")
1391            return False
1392
1393        return self._verify_bluetooth_tethering_connection(
1394            toggle_tethering=False, toggle_bluetooth=False, voice_call=True)
1395
1396    @test_tracker_info(uuid="be3e74f9-3dc8-4b72-8a33-32bff0868a44")
1397    @TelephonyBaseTest.tel_test_wrap
1398    def test_tethering_2g_to_bluetooth_toggle_data(self):
1399        """Bluetooth Tethering test: 2G to Bluetooth Tethering
1400
1401        1. DUT in 2G mode, idle.
1402        2. DUT start Bluetooth Tethering
1403        3. PhoneB disable data, connect to DUT's softAP
1404        4. Verify Internet access on DUT and PhoneB
1405        5. Toggle provider data connection
1406        6. Verify Internet access on DUT and PhoneB
1407
1408        Returns:
1409            True if success.
1410            False if failed.
1411        """
1412        if not self._test_setup_tethering(RAT_2G):
1413            self.log.error("Verify 4G Internet access failed.")
1414            return False
1415
1416        return self._verify_bluetooth_tethering_connection(
1417            toggle_tethering=False, toggle_bluetooth=False, toggle_data=True)
1418
1419    @test_tracker_info(uuid="4a106549-0bfa-4c8f-8e66-edec93fabadf")
1420    @TelephonyBaseTest.tel_test_wrap
1421    def test_tethering_rat_from_4g_to_3g_bluetooth(self):
1422        """Bluetooth Tethering test: 2G to Bluetooth Tethering
1423
1424        1. DUT in 4G mode, idle.
1425        2. DUT start bluetooth Tethering
1426        3. PhoneB disable data, connect to DUT's softAP
1427        4. Verify Internet access on DUT and PhoneB
1428        5. Change provider RAT to 3G
1429        6. Verify Internet access on DUT and PhoneB
1430
1431        Returns:
1432            True if success.
1433            False if failed.
1434        """
1435        if not self._test_setup_tethering(RAT_4G):
1436            self.log.error("Verify 3G Internet access failed.")
1437            return False
1438
1439        return self._verify_bluetooth_tethering_connection(
1440            toggle_tethering=False,
1441            toggle_bluetooth=False,
1442            toggle_data=False,
1443            change_rat=RAT_3G)
1444
1445    @test_tracker_info(uuid="eaa5b61b-f054-437f-ae82-8d80f6487785")
1446    @TelephonyBaseTest.tel_test_wrap
1447    def test_tethering_rat_from_4g_to_2g_bluetooth(self):
1448        """Bluetooth Tethering test: 2G to Bluetooth Tethering
1449
1450        1. DUT in 4G mode, idle.
1451        2. DUT start bluetooth Tethering
1452        3. PhoneB disable data, connect to DUT's softAP
1453        4. Verify Internet access on DUT and PhoneB
1454        5. Change provider RAT to 2G
1455        6. Verify Internet access on DUT and PhoneB
1456
1457        Returns:
1458            True if success.
1459            False if failed.
1460        """
1461        if not self._test_setup_tethering(RAT_4G):
1462            self.log.error("Verify 3G Internet access failed.")
1463            return False
1464
1465        return self._verify_bluetooth_tethering_connection(
1466            toggle_tethering=False,
1467            toggle_bluetooth=False,
1468            toggle_data=False,
1469            change_rat=RAT_2G)
1470
1471    @test_tracker_info(uuid="912a11a3-14b3-4928-885f-cea69f14a571")
1472    @TelephonyBaseTest.tel_test_wrap
1473    def test_tethering_4g_to_2gwifi(self):
1474        """WiFi Tethering test: LTE to WiFI 2.4G Tethering
1475
1476        1. DUT in LTE mode, idle.
1477        2. DUT start 2.4G WiFi Tethering
1478        3. PhoneB disable data, connect to DUT's softAP
1479        4. Verify Internet access on DUT and PhoneB
1480
1481        Returns:
1482            True if success.
1483            False if failed.
1484        """
1485        if not self._test_setup_tethering(RAT_4G):
1486            self.log.error("Verify 4G Internet access failed.")
1487            return False
1488
1489        return wifi_tethering_setup_teardown(
1490            self.log,
1491            self.provider,
1492            self.clients,
1493            ap_band=WIFI_CONFIG_APBAND_2G,
1494            check_interval=10,
1495            check_iteration=10)
1496
1497    @test_tracker_info(uuid="743e3998-d39f-42b9-b11f-009dcee34f3f")
1498    @TelephonyBaseTest.tel_test_wrap
1499    def test_tethering_4g_to_5gwifi(self):
1500        """WiFi Tethering test: LTE to WiFI 5G Tethering
1501
1502        1. DUT in LTE mode, idle.
1503        2. DUT start 5G WiFi Tethering
1504        3. PhoneB disable data, connect to DUT's softAP
1505        4. Verify Internet access on DUT and PhoneB
1506
1507        Returns:
1508            True if success.
1509            False if failed.
1510        """
1511        if not self._test_setup_tethering(RAT_4G):
1512            self.log.error("Verify 4G Internet access failed.")
1513            return False
1514
1515        return wifi_tethering_setup_teardown(
1516            self.log,
1517            self.provider,
1518            self.clients,
1519            ap_band=WIFI_CONFIG_APBAND_5G,
1520            check_interval=10,
1521            check_iteration=10)
1522
1523
1524    @test_tracker_info(uuid="5f2c6cb3-c32c-4f96-a2f4-7b901bb9a328")
1525    @TelephonyBaseTest.tel_test_wrap
1526    def test_tethering_5g_nsa_to_5gwifi(self):
1527        """WiFi Tethering test: 5G NSA to WiFI 5G Tethering
1528
1529        1. DUT in 5G NSA mode, attached.
1530        2. DUT start 5G WiFi Tethering
1531        3. PhoneB disable data, connect to DUT's softAP
1532        4. Verify Internet access on DUT and PhoneB
1533
1534        Returns:
1535            True if success.
1536            False if failed.
1537        """
1538        if not self._test_setup_tethering(RAT_5G):
1539            self.log.error("Verify 5G NSA Internet access failed.")
1540            return False
1541
1542        return wifi_tethering_setup_teardown(
1543            self.log,
1544            self.provider,
1545            self.clients,
1546            ap_band=WIFI_CONFIG_APBAND_5G,
1547            check_interval=10,
1548            check_iteration=10)
1549
1550
1551    @test_tracker_info(uuid="0e38f30e-08f3-4be1-af61-c07c37c93b70")
1552    @TelephonyBaseTest.tel_test_wrap
1553    def test_tethering_5g_nsa_to_2gwifi(self):
1554        """WiFi Tethering test: 5G NSA to WiFI 2G Tethering
1555
1556        1. DUT in 5G NSA mode, attached.
1557        2. DUT start 5G WiFi Tethering
1558        3. PhoneB disable data, connect to DUT's softAP
1559        4. Verify Internet access on DUT and PhoneB
1560
1561        Returns:
1562            True if success.
1563            False if failed.
1564        """
1565        if not self._test_setup_tethering(RAT_5G):
1566            self.log.error("Verify 5G NSA Internet access failed.")
1567            return False
1568
1569        return wifi_tethering_setup_teardown(
1570            self.log,
1571            self.provider,
1572            self.clients,
1573            ap_band=WIFI_CONFIG_APBAND_2G,
1574            check_interval=10,
1575            check_iteration=10)
1576
1577
1578    @test_tracker_info(uuid="c1a16464-3800-40d3-ba63-35db784e0383")
1579    @TelephonyBaseTest.tel_test_wrap
1580    def test_tethering_default_to_5gwifi(self):
1581        """WiFi Tethering test: Default to WiFI 5G Tethering
1582
1583        1. DUT in default mode, idle.
1584        2. DUT start 5G WiFi Tethering
1585        3. PhoneB disable data, connect to DUT's softAP
1586        4. Verify Internet access on DUT and PhoneB
1587        5. True: Stop
1588           False: Change DUT to next device and repeat until find the device
1589                  with tethering capability
1590
1591        Returns:
1592            True if success.
1593            False if no device has tethering capability.
1594        """
1595        num = len(self.android_devices)
1596        for idx, ad in enumerate(self.android_devices):
1597            self.provider = self.android_devices[idx]
1598            self.clients = self.android_devices[:
1599                                                idx] + self.android_devices[idx
1600                                                                            +
1601                                                                            1:]
1602            ensure_phones_default_state(self.log, self.android_devices)
1603            wifi_toggle_state(self.log, self.provider, False)
1604
1605            if not self._test_setup_tethering(None):
1606                self.provider.log.error("Data connection check failed.")
1607                continue
1608
1609            if not self.provider.droid.carrierConfigIsTetheringModeAllowed(
1610                    TETHERING_MODE_WIFI,
1611                    MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK):
1612                self.provider.log.info("Tethering is not entitled")
1613                continue
1614
1615            if wifi_tethering_setup_teardown(
1616                    self.log,
1617                    self.provider, [self.clients[0]],
1618                    ap_band=WIFI_CONFIG_APBAND_5G,
1619                    check_interval=10,
1620                    check_iteration=10):
1621                self.android_devices = [self.provider] + self.clients
1622                return True
1623            elif idx == num - 1:
1624                self.log.error("Tethering is not working on all devices")
1625                return False
1626        self.log.error(
1627            "Failed to enable tethering on any device in this testbed")
1628        raise signals.TestAbortClass(
1629            "Tethering is not available on all devices in this testbed")
1630
1631    @test_tracker_info(uuid="c9a570b0-838c-44ba-991c-f1ddeee21f3c")
1632    @TelephonyBaseTest.tel_test_wrap
1633    def test_tethering_default_to_2gwifi(self):
1634        """WiFi Tethering test: Default to WiFI 2G Tethering
1635
1636        1. DUT in default mode, idle.
1637        2. DUT start 2G WiFi Tethering
1638        3. PhoneB disable data, connect to DUT's softAP
1639        4. Verify Internet access on DUT and PhoneB
1640        5. True: Stop
1641           False: Change DUT to next device and repeat until find the device
1642                  with tethering capability
1643
1644        Returns:
1645            True if success.
1646            False if no device has tethering capability.
1647        """
1648        num = len(self.android_devices)
1649        for idx, ad in enumerate(self.android_devices):
1650            self.provider = self.android_devices[idx]
1651            self.clients = self.android_devices[:
1652                                                idx] + self.android_devices[idx
1653                                                                            +
1654                                                                            1:]
1655            ensure_phones_default_state(self.log, self.android_devices)
1656            wifi_toggle_state(self.log, self.provider, False)
1657
1658            if not self._test_setup_tethering(None):
1659                self.provider.log.error("Data connection check failed.")
1660                continue
1661
1662            if not self.provider.droid.carrierConfigIsTetheringModeAllowed(
1663                    TETHERING_MODE_WIFI,
1664                    MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK):
1665                self.provider.log.info("Tethering is not entitled")
1666                continue
1667
1668            if wifi_tethering_setup_teardown(
1669                    self.log,
1670                    self.provider, [self.clients[0]],
1671                    ap_band=WIFI_CONFIG_APBAND_2G,
1672                    check_interval=10,
1673                    check_iteration=10):
1674                self.android_devices = [self.provider] + self.clients
1675                return True
1676            elif idx == num - 1:
1677                self.log.error("Tethering is not working on all devices")
1678                return False
1679        self.log.error(
1680            "Failed to enable tethering on any device in this testbed")
1681        raise signals.TestAbortClass(
1682            "Tethering is not available on all devices in this testbed")
1683
1684    @test_tracker_info(uuid="59be8d68-f05b-4448-8584-de971174fd81")
1685    @TelephonyBaseTest.tel_test_wrap
1686    def test_tethering_3g_to_2gwifi(self):
1687        """WiFi Tethering test: 3G to WiFI 2.4G Tethering
1688
1689        1. DUT in 3G mode, idle.
1690        2. DUT start 2.4G WiFi Tethering
1691        3. PhoneB disable data, connect to DUT's softAP
1692        4. Verify Internet access on DUT and PhoneB
1693
1694        Returns:
1695            True if success.
1696            False if failed.
1697        """
1698        if not self._test_setup_tethering(RAT_3G):
1699            self.log.error("Verify 3G Internet access failed.")
1700            return False
1701
1702        return wifi_tethering_setup_teardown(
1703            self.log,
1704            self.provider,
1705            self.clients,
1706            ap_band=WIFI_CONFIG_APBAND_2G,
1707            check_interval=10,
1708            check_iteration=10)
1709
1710    @test_tracker_info(uuid="1be6b741-92e8-4ee1-9f59-e7f9f369b065")
1711    @TelephonyBaseTest.tel_test_wrap
1712    def test_tethering_3g_to_5gwifi(self):
1713        """WiFi Tethering test: 3G to WiFI 5G Tethering
1714
1715        1. DUT in 3G mode, idle.
1716        2. DUT start 5G WiFi Tethering
1717        3. PhoneB disable data, connect to DUT's softAP
1718        4. Verify Internet access on DUT and PhoneB
1719
1720        Returns:
1721            True if success.
1722            False if failed.
1723        """
1724        if not self._test_setup_tethering(RAT_3G):
1725            self.log.error("Verify 3G Internet access failed.")
1726            return False
1727
1728        return wifi_tethering_setup_teardown(
1729            self.log,
1730            self.provider,
1731            self.clients,
1732            ap_band=WIFI_CONFIG_APBAND_5G,
1733            check_interval=10,
1734            check_iteration=10)
1735
1736    @test_tracker_info(uuid="89fe6321-4c0d-40c0-89b2-54008ecca68f")
1737    @TelephonyBaseTest.tel_test_wrap
1738    def test_tethering_2g_to_2gwifi(self):
1739        """WiFi Tethering test: 2G to WiFI 2.4G Tethering
1740
1741        1. DUT in 2G mode, idle.
1742        2. DUT start 2.4G WiFi Tethering
1743        3. PhoneB disable data, connect to DUT's softAP
1744        4. Verify Internet access on DUT and PhoneB
1745
1746        Returns:
1747            True if success.
1748            False if failed.
1749        """
1750        if not self._test_setup_tethering(RAT_2G):
1751            self.log.error("Verify 2G Internet access failed.")
1752            return False
1753
1754        return wifi_tethering_setup_teardown(
1755            self.log,
1756            self.provider, [self.clients[0]],
1757            ap_band=WIFI_CONFIG_APBAND_2G,
1758            check_interval=10,
1759            check_iteration=10)
1760
1761    @test_tracker_info(uuid="b8258d51-9581-4d52-80b6-501941ec1191")
1762    @TelephonyBaseTest.tel_test_wrap
1763    def test_tethering_2g_to_5gwifi(self):
1764        """WiFi Tethering test: 2G to WiFI 5G Tethering
1765
1766        1. DUT in 2G mode, idle.
1767        2. DUT start 5G WiFi Tethering
1768        3. PhoneB disable data, connect to DUT's softAP
1769        4. Verify Internet access on DUT and PhoneB
1770
1771        Returns:
1772            True if success.
1773            False if failed.
1774        """
1775        if not self._test_setup_tethering(RAT_2G):
1776            self.log.error("Verify 2G Internet access failed.")
1777            return False
1778
1779        return wifi_tethering_setup_teardown(
1780            self.log,
1781            self.provider, [self.clients[0]],
1782            ap_band=WIFI_CONFIG_APBAND_5G,
1783            check_interval=10,
1784            check_iteration=10)
1785
1786    @test_tracker_info(uuid="8ed766a6-71c5-4b3b-8897-a4e796c75619")
1787    @TelephonyBaseTest.tel_test_wrap
1788    def test_disable_wifi_tethering_resume_connected_wifi(self):
1789        """WiFi Tethering test: WiFI connected to 2.4G network,
1790        start (LTE) 2.4G WiFi tethering, then stop tethering
1791
1792        1. DUT in data connected, idle. WiFi connected to 2.4G Network
1793        2. DUT start 2.4G WiFi Tethering
1794        3. PhoneB disable data, connect to DUT's softAP
1795        4. Verify Internet access on DUT and PhoneB
1796        5. Disable WiFi Tethering on DUT.
1797        6. Verify DUT automatically connect to previous WiFI network
1798
1799        Returns:
1800            True if success.
1801            False if failed.
1802        """
1803        if not self._test_setup_tethering():
1804            self.log.error("Verify provider Internet access failed.")
1805            return False
1806        self.log.info("Connect WiFi.")
1807        if not ensure_wifi_connected(self.log, self.provider,
1808                                     self.wifi_network_ssid,
1809                                     self.wifi_network_pass):
1810            self.log.error("WiFi connect fail.")
1811            return False
1812        self.log.info("Start WiFi Tethering.")
1813        if not wifi_tethering_setup_teardown(
1814                self.log,
1815                self.provider, [self.clients[0]],
1816                check_interval=10,
1817                check_iteration=2):
1818            self.log.error("WiFi Tethering failed.")
1819            return False
1820
1821        if (not wait_for_wifi_data_connection(self.log, self.provider, True)
1822                or not verify_internet_connection(self.log, self.provider)):
1823            self.log.error("Provider data did not return to Wifi")
1824            return False
1825        return True
1826
1827    @test_tracker_info(uuid="b879ceb2-1b80-4762-93f9-afef4d688c28")
1828    @TelephonyBaseTest.tel_test_wrap
1829    def test_toggle_data_during_active_wifi_tethering(self):
1830        """WiFi Tethering test: Toggle Data during active WiFi Tethering
1831
1832        1. DUT data connection is on and idle.
1833        2. DUT start 2.4G WiFi Tethering
1834        3. PhoneB disable data, connect to DUT's softAP
1835        4. Verify Internet access on DUT and PhoneB
1836        5. Disable Data on DUT, verify PhoneB still connected to WiFi, but no Internet access.
1837        6. Enable Data on DUT, verify PhoneB still connected to WiFi and have Internet access.
1838
1839        Returns:
1840            True if success.
1841            False if failed.
1842        """
1843        if not self._test_setup_tethering():
1844            self.log.error("Provider Internet access check failed.")
1845            return False
1846        try:
1847            ssid = rand_ascii_str(10)
1848            if not wifi_tethering_setup_teardown(
1849                    self.log,
1850                    self.provider, [self.clients[0]],
1851                    ap_band=WIFI_CONFIG_APBAND_2G,
1852                    check_interval=10,
1853                    check_iteration=2,
1854                    do_cleanup=False,
1855                    ssid=ssid):
1856                self.log.error("WiFi Tethering failed.")
1857                return False
1858
1859            if not self.provider.droid.wifiIsApEnabled():
1860                self.provider.log.error("Provider WiFi tethering stopped.")
1861                return False
1862
1863            self.provider.log.info(
1864                "Disable Data on Provider, verify no data on Client.")
1865            self.provider.droid.telephonyToggleDataConnection(False)
1866            time.sleep(WAIT_TIME_DATA_STATUS_CHANGE_DURING_WIFI_TETHERING)
1867            if not verify_internet_connection(self.log, self.provider, expected_state=False):
1868                self.provider.log.error("Disable data on provider failed.")
1869                return False
1870            if not self.provider.droid.wifiIsApEnabled():
1871                self.provider.log.error("Provider WiFi tethering stopped.")
1872                return False
1873            if not check_is_wifi_connected(self.log, self.clients[0], ssid):
1874                self.clients[0].log.error("Client WiFi is not connected")
1875                return False
1876
1877            self.log.info(
1878                "Enable Data on Provider, verify data available on Client.")
1879            self.provider.droid.telephonyToggleDataConnection(True)
1880            if not wait_for_cell_data_connection(self.log, self.provider,
1881                                                 True):
1882                self.provider.log.error(
1883                    "Provider failed to enable data connection.")
1884                return False
1885            if not verify_internet_connection(self.log, self.provider):
1886                self.provider.log.error(
1887                    "Provider internet connection check failed.")
1888                return False
1889            if not self.provider.droid.wifiIsApEnabled():
1890                self.provider.log.error("Provider WiFi tethering stopped.")
1891                return False
1892
1893            if not check_is_wifi_connected(
1894                    self.log, self.clients[0],
1895                    ssid) or (not verify_internet_connection(
1896                        self.log, self.clients[0])):
1897                self.clients[0].log.error(
1898                    "Client wifi connection check failed!")
1899                return False
1900        finally:
1901            if not wifi_tethering_cleanup(self.log, self.provider,
1902                                          self.clients):
1903                return False
1904        return True
1905
1906    # Invalid Live Test. Can't rely on the result of this test with live network.
1907    # Network may decide not to change the RAT when data conenction is active.
1908    @test_tracker_info(uuid="c92a961b-e85d-435c-8988-052928add591")
1909    @TelephonyBaseTest.tel_test_wrap
1910    def test_change_rat_during_active_wifi_tethering_lte_to_3g(self):
1911        """WiFi Tethering test: Change Cellular Data RAT generation from LTE to 3G,
1912            during active WiFi Tethering.
1913
1914        1. DUT in LTE mode, idle.
1915        2. DUT start 2.4G WiFi Tethering
1916        3. PhoneB disable data, connect to DUT's softAP
1917        4. Verily Internet access on DUT and PhoneB
1918        5. Change DUT Cellular Data RAT generation from LTE to 3G.
1919        6. Verify both DUT and PhoneB have Internet access.
1920
1921        Returns:
1922            True if success.
1923            False if failed.
1924        """
1925        if not self._test_setup_tethering(RAT_4G):
1926            self.log.error("Verify 4G Internet access failed.")
1927            return False
1928        try:
1929            if not wifi_tethering_setup_teardown(
1930                    self.log,
1931                    self.provider, [self.clients[0]],
1932                    ap_band=WIFI_CONFIG_APBAND_2G,
1933                    check_interval=10,
1934                    check_iteration=2,
1935                    do_cleanup=False):
1936                self.log.error("WiFi Tethering failed.")
1937                return False
1938
1939            if not self.provider.droid.wifiIsApEnabled():
1940                self.provider.log.error("Provider WiFi tethering stopped.")
1941                return False
1942
1943            self.log.info("Provider change RAT from LTE to 3G.")
1944            if not ensure_network_generation(
1945                    self.log,
1946                    self.provider,
1947                    RAT_3G,
1948                    voice_or_data=NETWORK_SERVICE_DATA,
1949                    toggle_apm_after_setting=False):
1950                self.provider.log.error("Provider failed to reselect to 3G.")
1951                return False
1952            time.sleep(WAIT_TIME_DATA_STATUS_CHANGE_DURING_WIFI_TETHERING)
1953            if not verify_internet_connection(self.log, self.provider):
1954                self.provider.log.error("Data not available on Provider.")
1955                return False
1956            if not self.provider.droid.wifiIsApEnabled():
1957                self.provider.log.error("Provider WiFi tethering stopped.")
1958                return False
1959            if not tethering_check_internet_connection(
1960                    self.log, self.provider, [self.clients[0]], 10, 5):
1961                return False
1962        finally:
1963            if not wifi_tethering_cleanup(self.log, self.provider,
1964                                          self.clients):
1965                return False
1966        return True
1967
1968    # Invalid Live Test. Can't rely on the result of this test with live network.
1969    # Network may decide not to change the RAT when data conenction is active.
1970    @test_tracker_info(uuid="eb5f0180-b70d-436f-8fcb-60c59307cc43")
1971    @TelephonyBaseTest.tel_test_wrap
1972    def test_change_rat_during_active_wifi_tethering_3g_to_lte(self):
1973        """WiFi Tethering test: Change Cellular Data RAT generation from 3G to LTE,
1974            during active WiFi Tethering.
1975
1976        1. DUT in 3G mode, idle.
1977        2. DUT start 2.4G WiFi Tethering
1978        3. PhoneB disable data, connect to DUT's softAP
1979        4. Verily Internet access on DUT and PhoneB
1980        5. Change DUT Cellular Data RAT generation from 3G to LTE.
1981        6. Verify both DUT and PhoneB have Internet access.
1982
1983        Returns:
1984            True if success.
1985            False if failed.
1986        """
1987        if not self._test_setup_tethering(RAT_3G):
1988            self.log.error("Verify 3G Internet access failed.")
1989            return False
1990        try:
1991            if not wifi_tethering_setup_teardown(
1992                    self.log,
1993                    self.provider, [self.clients[0]],
1994                    ap_band=WIFI_CONFIG_APBAND_2G,
1995                    check_interval=10,
1996                    check_iteration=2,
1997                    do_cleanup=False):
1998                self.log.error("WiFi Tethering failed.")
1999                return False
2000
2001            if not self.provider.droid.wifiIsApEnabled():
2002                self.log.error("Provider WiFi tethering stopped.")
2003                return False
2004
2005            self.log.info("Provider change RAT from 3G to 4G.")
2006            if not ensure_network_generation(
2007                    self.log,
2008                    self.provider,
2009                    RAT_4G,
2010                    voice_or_data=NETWORK_SERVICE_DATA,
2011                    toggle_apm_after_setting=False):
2012                self.log.error("Provider failed to reselect to 4G.")
2013                return False
2014            time.sleep(WAIT_TIME_DATA_STATUS_CHANGE_DURING_WIFI_TETHERING)
2015            if not verify_internet_connection(self.log, self.provider):
2016                self.provider.log.error("Data not available on Provider.")
2017                return False
2018            if not self.provider.droid.wifiIsApEnabled():
2019                self.provider.log.error("Provider WiFi tethering stopped.")
2020                return False
2021            if not tethering_check_internet_connection(
2022                    self.log, self.provider, [self.clients[0]], 10, 5):
2023                return False
2024        finally:
2025            if not wifi_tethering_cleanup(self.log, self.provider, [self.clients[0]]):
2026                return False
2027        return True
2028
2029    @test_tracker_info(uuid="12a6c910-fa96-4d9b-99a5-8391fea33732")
2030    @TelephonyBaseTest.tel_test_wrap
2031    def test_toggle_apm_during_active_wifi_tethering(self):
2032        """WiFi Tethering test: Toggle APM during active WiFi Tethering
2033
2034        1. DUT in LTE mode, idle.
2035        2. DUT start 2.4G WiFi Tethering
2036        3. PhoneB disable data, connect to DUT's softAP
2037        4. Verify Internet access on DUT and PhoneB
2038        5. DUT toggle APM on, verify WiFi tethering stopped, PhoneB lost WiFi connection.
2039        6. DUT toggle APM off, verify PhoneA have cellular data and Internet connection.
2040
2041        Returns:
2042            True if success.
2043            False if failed.
2044        """
2045        if not self._test_setup_tethering(RAT_4G):
2046            self.log.error("Verify 4G Internet access failed.")
2047            return False
2048        try:
2049            ssid = rand_ascii_str(10)
2050            if not wifi_tethering_setup_teardown(
2051                    self.log,
2052                    self.provider, [self.clients[0]],
2053                    ap_band=WIFI_CONFIG_APBAND_2G,
2054                    check_interval=10,
2055                    check_iteration=2,
2056                    do_cleanup=False,
2057                    ssid=ssid):
2058                self.log.error("WiFi Tethering failed.")
2059                return False
2060
2061            if not self.provider.droid.wifiIsApEnabled():
2062                self.log.error("Provider WiFi tethering stopped.")
2063                return False
2064
2065            self.log.info(
2066                "Provider turn on APM, verify no wifi/data on Client.")
2067            if not toggle_airplane_mode(self.log, self.provider, True):
2068                self.log.error("Provider turn on APM failed.")
2069                return False
2070            time.sleep(WAIT_TIME_DATA_STATUS_CHANGE_DURING_WIFI_TETHERING)
2071            if self.provider.droid.wifiIsApEnabled():
2072                self.provider.log.error("Provider WiFi tethering not stopped.")
2073                return False
2074            if not verify_internet_connection(self.log, self.clients[0], expected_state=False):
2075                self.clients[0].log.error(
2076                    "Client should not have Internet connection.")
2077                return False
2078            wifi_info = self.clients[0].droid.wifiGetConnectionInfo()
2079            self.clients[0].log.info("WiFi Info: {}".format(wifi_info))
2080            if wifi_info[WIFI_SSID_KEY] == ssid:
2081                self.clients[0].log.error(
2082                    "WiFi error. WiFi should not be connected.".format(
2083                        wifi_info))
2084                return False
2085
2086            self.log.info("Provider turn off APM.")
2087            if not toggle_airplane_mode(self.log, self.provider, False):
2088                self.provider.log.error("Provider turn on APM failed.")
2089                return False
2090            time.sleep(WAIT_TIME_DATA_STATUS_CHANGE_DURING_WIFI_TETHERING)
2091            if self.provider.droid.wifiIsApEnabled():
2092                self.provider.log.error(
2093                    "Provider WiFi tethering should not on.")
2094                return False
2095            if not verify_internet_connection(self.log, self.provider):
2096                self.provider.log.error(
2097                    "Provider should have Internet connection.")
2098                return False
2099        finally:
2100            self.clients[0].droid.telephonyToggleDataConnection(True)
2101            wifi_reset(self.log, self.clients[0])
2102        return True
2103
2104    @test_tracker_info(uuid="037e80fc-6eab-4cd1-846a-b9780a1d502d")
2105    @TelephonyBaseTest.tel_test_wrap
2106    def test_tethering_entitlement_check(self):
2107        """Tethering Entitlement Check Test
2108
2109        Get tethering entitlement check result.
2110
2111        Returns:
2112            True if entitlement check returns True.
2113        """
2114        if (not wait_for_cell_data_connection(self.log, self.provider, True)
2115                or not verify_internet_connection(self.log, self.provider)):
2116            self.log.error("Failed cell data call for entitlement check.")
2117            return False
2118
2119        result = self.provider.droid.carrierConfigIsTetheringModeAllowed(
2120            TETHERING_MODE_WIFI, MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK)
2121        self.provider.log.info("Tethering entitlement check result: %s",
2122                               result)
2123        return result
2124
2125    @test_tracker_info(uuid="4972826e-39ea-42f7-aae0-06fe3aa9ecc6")
2126    @TelephonyBaseTest.tel_test_wrap
2127    def test_tethering_4g_to_2gwifi_stress(self):
2128        """Stress Test LTE to WiFI 2.4G Tethering
2129
2130        This is a stress test for "test_tethering_4g_to_2gwifi".
2131        Default MINIMUM_SUCCESS_RATE is set to 95%.
2132
2133        Returns:
2134            True stress pass rate is higher than MINIMUM_SUCCESS_RATE.
2135            False otherwise.
2136        """
2137        MINIMUM_SUCCESS_RATE = .95
2138        success_count = 0
2139        fail_count = 0
2140
2141        for i in range(1, self.stress_test_number + 1):
2142
2143            ensure_phones_default_state(self.log, self.android_devices)
2144
2145            if self.test_tethering_4g_to_2gwifi():
2146                success_count += 1
2147                result_str = "Succeeded"
2148            else:
2149                fail_count += 1
2150                result_str = "Failed"
2151            self.log.info("Iteration {} {}. Current: {} / {} passed.".format(
2152                i, result_str, success_count, self.stress_test_number))
2153
2154        self.log.info("Final Count - Success: {}, Failure: {} - {}%".format(
2155            success_count, fail_count,
2156            str(100 * success_count / (success_count + fail_count))))
2157        if success_count / (
2158                success_count + fail_count) >= MINIMUM_SUCCESS_RATE:
2159            return True
2160        else:
2161            return False
2162
2163    @test_tracker_info(uuid="54e85aed-09e3-42e2-bb33-bca1005d93ab")
2164    @TelephonyBaseTest.tel_test_wrap
2165    def test_tethering_wifi_ssid_quotes(self):
2166        """WiFi Tethering test: SSID name have quotes.
2167        1. Set SSID name have double quotes.
2168        2. Start LTE to WiFi (2.4G) tethering.
2169        3. Verify tethering.
2170
2171        Returns:
2172            True if success.
2173            False if failed.
2174        """
2175        if not self._test_setup_tethering():
2176            self.log.error("Verify Internet access failed.")
2177            return False
2178        ssid = "\"" + rand_ascii_str(10) + "\""
2179        self.log.info(
2180            "Starting WiFi Tethering test with ssid: {}".format(ssid))
2181
2182        return wifi_tethering_setup_teardown(
2183            self.log,
2184            self.provider,
2185            self.clients,
2186            ap_band=WIFI_CONFIG_APBAND_2G,
2187            check_interval=10,
2188            check_iteration=10,
2189            ssid=ssid)
2190
2191    @test_tracker_info(uuid="320326da-bf32-444d-81f9-f781c55dbc99")
2192    @TelephonyBaseTest.tel_test_wrap
2193    def test_tethering_wifi_password_escaping_characters(self):
2194        """WiFi Tethering test: password have escaping characters.
2195        1. Set password have escaping characters.
2196            e.g.: '"DQ=/{Yqq;M=(^_3HzRvhOiL8S%`]w&l<Qp8qH)bs<4E9v_q=HLr^)}w$blA0Kg'
2197        2. Start LTE to WiFi (2.4G) tethering.
2198        3. Verify tethering.
2199
2200        Returns:
2201            True if success.
2202            False if failed.
2203        """
2204        if not self._test_setup_tethering():
2205            self.log.error("Verify Internet access failed.")
2206            return False
2207
2208        password = '"DQ=/{Yqq;M=(^_3HzRvhOiL8S%`]w&l<Qp8qH)bs<4E9v_q=HLr^)}w$blA0Kg'
2209        self.log.info(
2210            "Starting WiFi Tethering test with password: {}".format(password))
2211
2212        return wifi_tethering_setup_teardown(
2213            self.log,
2214            self.provider,
2215            self.clients,
2216            ap_band=WIFI_CONFIG_APBAND_2G,
2217            check_interval=10,
2218            check_iteration=10,
2219            password=password)
2220
2221    def _test_start_wifi_tethering_connect_teardown(self, ad_host, ad_client,
2222                                                    ssid, password):
2223        """Private test util for WiFi Tethering.
2224
2225        1. Host start WiFi tethering.
2226        2. Client connect to tethered WiFi.
2227        3. Host tear down WiFi tethering.
2228
2229        Args:
2230            ad_host: android device object for host
2231            ad_client: android device object for client
2232            ssid: WiFi tethering ssid
2233            password: WiFi tethering password
2234
2235        Returns:
2236            True if no error happen, otherwise False.
2237        """
2238        result = True
2239        self.number_of_devices = 2
2240        # Turn off active SoftAP if any.
2241        if ad_host.droid.wifiIsApEnabled():
2242            stop_wifi_tethering(self.log, ad_host)
2243
2244        time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
2245        if not start_wifi_tethering(self.log, ad_host, ssid, password,
2246                                    WIFI_CONFIG_APBAND_2G):
2247            self.log.error("Start WiFi tethering failed.")
2248            result = False
2249        time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
2250        if not ensure_wifi_connected(self.log, ad_client, ssid, password):
2251            self.log.error("Client connect to WiFi failed.")
2252            result = False
2253        if not wifi_reset(self.log, ad_client):
2254            self.log.error("Reset client WiFi failed. {}".format(
2255                ad_client.serial))
2256            result = False
2257        if not stop_wifi_tethering(self.log, ad_host):
2258            self.log.error("Stop WiFi tethering failed.")
2259            result = False
2260        return result
2261
2262    @test_tracker_info(uuid="617c7e71-f166-465f-bfd3-b5a3a40cc0d4")
2263    @TelephonyBaseTest.tel_test_wrap
2264    def test_tethering_wifi_ssid(self):
2265        """WiFi Tethering test: start WiFi tethering with all kinds of SSIDs.
2266
2267        For each listed SSID, start WiFi tethering on DUT, client connect WiFi,
2268        then tear down WiFi tethering.
2269
2270        Returns:
2271            True if WiFi tethering succeed on all SSIDs.
2272            False if failed.
2273        """
2274        if not self._test_setup_tethering(RAT_4G):
2275            self.log.error("Setup Failed.")
2276            return False
2277        ssid_list = [
2278            " !\"#$%&'()*+,-./0123456789:;<=>?",
2279            "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_",
2280            "`abcdefghijklmnopqrstuvwxyz{|}~", " a ", "!b!", "#c#", "$d$",
2281            "%e%", "&f&", "'g'", "(h(", ")i)", "*j*", "+k+", "-l-", ".m.",
2282            "/n/", "_", " !\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}",
2283            "\u0644\u062c\u0648\u062c", "\u8c37\u6b4c", "\uad6c\uae00"
2284            "\u30b0\u30fc\u30eb",
2285            "\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0443\u0439"
2286        ]
2287        fail_list = {}
2288
2289        for ssid in ssid_list:
2290            password = rand_ascii_str(8)
2291            self.log.info("SSID: <{}>, Password: <{}>".format(ssid, password))
2292            if not self._test_start_wifi_tethering_connect_teardown(
2293                    self.provider, self.clients[0], ssid, password):
2294                fail_list[ssid] = password
2295
2296        if (len(fail_list) > 0):
2297            self.log.error("Failed cases: {}".format(fail_list))
2298            return False
2299        else:
2300            return True
2301
2302    @test_tracker_info(uuid="9a5b5a34-b5cf-451d-94c4-8a64d456dfe5")
2303    @TelephonyBaseTest.tel_test_wrap
2304    def test_tethering_wifi_password(self):
2305        """WiFi Tethering test: start WiFi tethering with all kinds of passwords.
2306
2307        For each listed password, start WiFi tethering on DUT, client connect WiFi,
2308        then tear down WiFi tethering.
2309
2310        Returns:
2311            True if WiFi tethering succeed on all passwords.
2312            False if failed.
2313        """
2314        if not self._test_setup_tethering(RAT_4G):
2315            self.log.error("Setup Failed.")
2316            return False
2317        password_list = [
2318            " !\"#$%&'()*+,-./0123456789:;<=>?",
2319            "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_",
2320            "`abcdefghijklmnopqrstuvwxyz{|}~",
2321            " !\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}", "abcdefgh",
2322            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!",
2323            " a12345 ", "!b12345!", "#c12345#", "$d12345$", "%e12345%",
2324            "&f12345&", "'g12345'", "(h12345(", ")i12345)", "*j12345*",
2325            "+k12345+", "-l12345-", ".m12345.", "/n12345/"
2326        ]
2327        fail_list = {}
2328
2329        for password in password_list:
2330            ssid = rand_ascii_str(8)
2331            self.log.info("SSID: <{}>, Password: <{}>".format(ssid, password))
2332            if not self._test_start_wifi_tethering_connect_teardown(
2333                    self.provider, self.clients[0], ssid, password):
2334                fail_list[ssid] = password
2335
2336        if (len(fail_list) > 0):
2337            self.log.error("Failed cases: {}".format(fail_list))
2338            return False
2339        else:
2340            return True
2341
2342    def _test_tethering_wifi_and_voice_call(self, provider_data_rat,
2343                                            provider_setup_func,
2344                                            provider_in_call_check_func):
2345        self.number_of_devices = 2
2346        if not self._test_setup_tethering(provider_data_rat):
2347            self.log.error("Verify 4G Internet access failed.")
2348            return False
2349
2350        tasks = [(provider_setup_func, (self.log, self.provider)),
2351                 (phone_setup_voice_general, (self.log, self.clients[0]))]
2352        if not multithread_func(self.log, tasks):
2353            self.log.error("Phone Failed to Set Up VoLTE.")
2354            return False
2355
2356        try:
2357            self.log.info("1. Setup WiFi Tethering.")
2358            if not wifi_tethering_setup_teardown(
2359                    self.log,
2360                    self.provider, [self.clients[0]],
2361                    ap_band=WIFI_CONFIG_APBAND_2G,
2362                    check_interval=10,
2363                    check_iteration=2,
2364                    do_cleanup=False):
2365                self.log.error("WiFi Tethering failed.")
2366                return False
2367            self.log.info("2. Make outgoing call.")
2368            if not call_setup_teardown(
2369                    self.log,
2370                    self.provider,
2371                    self.clients[0],
2372                    ad_hangup=None,
2373                    verify_caller_func=provider_in_call_check_func):
2374                self.log.error("Setup Call Failed.")
2375                return False
2376            self.log.info("3. Verify data.")
2377            if not verify_internet_connection(self.log, self.provider):
2378                self.provider.log.error("Provider have no Internet access.")
2379            if not verify_internet_connection(self.log, self.clients[0]):
2380                self.clients[0].log.error("Client have no Internet access.")
2381            hangup_call(self.log, self.provider)
2382
2383            time.sleep(WAIT_TIME_BETWEEN_REG_AND_CALL)
2384
2385            self.log.info("4. Make incoming call.")
2386            if not call_setup_teardown(
2387                    self.log,
2388                    self.clients[0],
2389                    self.provider,
2390                    ad_hangup=None,
2391                    verify_callee_func=provider_in_call_check_func):
2392                self.log.error("Setup Call Failed.")
2393                return False
2394            self.log.info("5. Verify data.")
2395            if not verify_internet_connection(self.log, self.provider):
2396                self.provider.log.error("Provider have no Internet access.")
2397            if not verify_internet_connection(self.log, self.clients[0]):
2398                self.clients[0].log.error("Client have no Internet access.")
2399            hangup_call(self.log, self.provider)
2400
2401        finally:
2402            if not wifi_tethering_cleanup(self.log, self.provider,
2403                                          self.clients):
2404                return False
2405        return True
2406
2407    @test_tracker_info(uuid="216bdb8c-edbf-4ff8-8750-a0861ab44df6")
2408    @TelephonyBaseTest.tel_test_wrap
2409    def test_tethering_wifi_volte_call(self):
2410        """WiFi Tethering test: VoLTE call during WiFi tethering
2411        1. Start LTE to WiFi (2.4G) tethering.
2412        2. Verify tethering.
2413        3. Make outgoing VoLTE call on tethering provider.
2414        4. Verify tethering still works.
2415        5. Make incoming VoLTE call on tethering provider.
2416        6. Verify tethering still works.
2417
2418        Returns:
2419            True if success.
2420            False if failed.
2421        """
2422        return self._test_tethering_wifi_and_voice_call(
2423            RAT_4G, phone_setup_volte, is_phone_in_call_volte)
2424
2425    @test_tracker_info(uuid="bcd430cc-6d33-47d1-825d-aae9f248addc")
2426    @TelephonyBaseTest.tel_test_wrap
2427    def test_tethering_wifi_csfb_call(self):
2428        """WiFi Tethering test: CSFB call during WiFi tethering
2429        1. Start LTE to WiFi (2.4G) tethering.
2430        2. Verify tethering.
2431        3. Make outgoing CSFB call on tethering provider.
2432        4. Verify tethering still works.
2433        5. Make incoming CSFB call on tethering provider.
2434        6. Verify tethering still works.
2435
2436        Returns:
2437            True if success.
2438            False if failed.
2439        """
2440        return self._test_tethering_wifi_and_voice_call(
2441            RAT_4G, phone_setup_csfb, is_phone_in_call_csfb)
2442
2443    @test_tracker_info(uuid="19e0df23-6819-4c69-bfda-eea9cce802d8")
2444    @TelephonyBaseTest.tel_test_wrap
2445    def test_tethering_wifi_3g_call(self):
2446        """WiFi Tethering test: 3G call during WiFi tethering
2447        1. Start 3G to WiFi (2.4G) tethering.
2448        2. Verify tethering.
2449        3. Make outgoing CS call on tethering provider.
2450        4. Verify tethering still works.
2451        5. Make incoming CS call on tethering provider.
2452        6. Verify tethering still works.
2453
2454        Returns:
2455            True if success.
2456            False if failed.
2457        """
2458        return self._test_tethering_wifi_and_voice_call(
2459            RAT_3G, phone_setup_voice_3g, is_phone_in_call_3g)
2460
2461    @test_tracker_info(uuid="4acd98b5-fdef-4736-969f-3fa953990a58")
2462    @TelephonyBaseTest.tel_test_wrap
2463    def test_tethering_wifi_no_password(self):
2464        """WiFi Tethering test: Start WiFi tethering with no password
2465
2466        1. DUT is idle.
2467        2. DUT start 2.4G WiFi Tethering, with no WiFi password.
2468        3. PhoneB disable data, connect to DUT's softAP
2469        4. Verify Internet access on DUT and PhoneB
2470
2471        Returns:
2472            True if success.
2473            False if failed.
2474        """
2475        if not self._test_setup_tethering():
2476            self.log.error("Verify Internet access failed.")
2477            return False
2478
2479        return wifi_tethering_setup_teardown(
2480            self.log,
2481            self.provider, [self.clients[0]],
2482            ap_band=WIFI_CONFIG_APBAND_2G,
2483            check_interval=10,
2484            check_iteration=10,
2485            password="")
2486
2487    @test_tracker_info(uuid="86ad1680-bfb8-457e-8b4d-23321cb3f223")
2488    @TelephonyBaseTest.tel_test_wrap
2489    def test_tethering_wifi_reboot(self):
2490        """WiFi Tethering test: Start WiFi tethering then Reboot device
2491
2492        1. DUT is idle.
2493        2. DUT start 2.4G WiFi Tethering.
2494        3. PhoneB disable data, connect to DUT's softAP
2495        4. Verify Internet access on DUT and PhoneB
2496        5. Reboot DUT
2497        6. After DUT reboot, verify tethering is stopped.
2498
2499        Returns:
2500            True if success.
2501            False if failed.
2502        """
2503        if not self._test_setup_tethering():
2504            self.log.error("Verify Internet access failed.")
2505            return False
2506        try:
2507            if not wifi_tethering_setup_teardown(
2508                    self.log,
2509                    self.provider, [self.clients[0]],
2510                    ap_band=WIFI_CONFIG_APBAND_2G,
2511                    check_interval=10,
2512                    check_iteration=2,
2513                    do_cleanup=False):
2514                self.log.error("WiFi Tethering failed.")
2515                return False
2516
2517            if not self.provider.droid.wifiIsApEnabled():
2518                self.log.error("Provider WiFi tethering stopped.")
2519                return False
2520
2521            self.provider.log.info("Reboot provider")
2522            self.provider.reboot()
2523            time.sleep(
2524                WAIT_TIME_AFTER_REBOOT + WAIT_TIME_TETHERING_AFTER_REBOOT)
2525
2526            self.log.info("After reboot check if tethering stopped.")
2527            if self.provider.droid.wifiIsApEnabled():
2528                self.log.error("Provider WiFi tethering did NOT stopped.")
2529                return False
2530        finally:
2531            self.clients[0].droid.telephonyToggleDataConnection(True)
2532            wifi_reset(self.log, self.clients[0])
2533            if self.provider.droid.wifiIsApEnabled():
2534                stop_wifi_tethering(self.log, self.provider)
2535        return True
2536
2537    @test_tracker_info(uuid="5cf04ca2-dfde-43d6-be74-78b9abdf6c26")
2538    @TelephonyBaseTest.tel_test_wrap
2539    def test_connect_wifi_start_tethering_wifi_reboot(self):
2540        """WiFi Tethering test: WiFI connected, then start WiFi tethering,
2541            then reboot device.
2542
2543        Initial Condition: DUT in 4G mode, idle, DUT connect to WiFi.
2544        1. DUT start 2.4G WiFi Tethering.
2545        2. PhoneB disable data, connect to DUT's softAP
2546        3. Verify Internet access on DUT and PhoneB
2547        4. Reboot DUT
2548        5. After DUT reboot, verify tethering is stopped. DUT is able to connect
2549            to previous WiFi AP.
2550
2551        Returns:
2552            True if success.
2553            False if failed.
2554        """
2555        if not self._test_setup_tethering():
2556            self.log.error("Verify Internet access failed.")
2557            return False
2558
2559        self.log.info("Make sure DUT can connect to live network by WIFI")
2560        if ((not ensure_wifi_connected(self.log, self.provider,
2561                                       self.wifi_network_ssid,
2562                                       self.wifi_network_pass))
2563                or (not verify_internet_connection(self.log, self.provider))):
2564            self.log.error("WiFi connect fail.")
2565            return False
2566
2567        try:
2568            if not wifi_tethering_setup_teardown(
2569                    self.log,
2570                    self.provider, [self.clients[0]],
2571                    ap_band=WIFI_CONFIG_APBAND_2G,
2572                    check_interval=10,
2573                    check_iteration=2,
2574                    do_cleanup=False):
2575                self.log.error("WiFi Tethering failed.")
2576                return False
2577
2578            if not self.provider.droid.wifiIsApEnabled():
2579                self.log.error("Provider WiFi tethering stopped.")
2580                return False
2581
2582            self.provider.log.info("Reboot Provider")
2583            self.provider.reboot()
2584            time.sleep(WAIT_TIME_AFTER_REBOOT)
2585            time.sleep(WAIT_TIME_TETHERING_AFTER_REBOOT)
2586
2587            self.log.info("After reboot check if tethering stopped.")
2588            if self.provider.droid.wifiIsApEnabled():
2589                self.provider.log.error(
2590                    "Provider WiFi tethering did NOT stopped.")
2591                return False
2592
2593            self.log.info("Make sure WiFi can connect automatically.")
2594            if (not wait_for_wifi_data_connection(self.log, self.provider,
2595                                                  True) or
2596                    not verify_internet_connection(self.log, self.provider)):
2597                self.log.error("Data did not return to WiFi")
2598                return False
2599
2600        finally:
2601            self.clients[0].droid.telephonyToggleDataConnection(True)
2602            wifi_reset(self.log, self.clients[0])
2603            if self.provider.droid.wifiIsApEnabled():
2604                stop_wifi_tethering(self.log, self.provider)
2605        return True
2606
2607    @test_tracker_info(uuid="e0621997-c5bd-4137-afa6-b43406e9c713")
2608    @TelephonyBaseTest.tel_test_wrap
2609    def test_connect_wifi_reboot_start_tethering_wifi(self):
2610        """WiFi Tethering test: DUT connected to WiFi, then reboot,
2611        After reboot, start WiFi tethering, verify tethering actually works.
2612
2613        Initial Condition: Device set to 4G mode, idle, DUT connect to WiFi.
2614        1. Verify Internet is working on DUT (by WiFi).
2615        2. Reboot DUT.
2616        3. DUT start 2.4G WiFi Tethering.
2617        4. PhoneB disable data, connect to DUT's softAP
2618        5. Verify Internet access on DUT and PhoneB
2619
2620        Returns:
2621            True if success.
2622            False if failed.
2623        """
2624        if not self._test_setup_tethering():
2625            self.log.error("Verify Internet access failed.")
2626            return False
2627
2628        self.log.info("Make sure DUT can connect to live network by WIFI")
2629        if ((not ensure_wifi_connected(self.log, self.provider,
2630                                       self.wifi_network_ssid,
2631                                       self.wifi_network_pass))
2632                or (not verify_internet_connection(self.log, self.provider))):
2633            self.log.error("WiFi connect fail.")
2634            return False
2635
2636        self.provider.log.info("Reboot provider")
2637        self.provider.reboot()
2638        time.sleep(WAIT_TIME_AFTER_REBOOT)
2639        time.sleep(WAIT_TIME_TETHERING_AFTER_REBOOT)
2640
2641        return wifi_tethering_setup_teardown(
2642            self.log,
2643            self.provider, [self.clients[0]],
2644            ap_band=WIFI_CONFIG_APBAND_2G,
2645            check_interval=10,
2646            check_iteration=10)
2647
2648    @test_tracker_info(uuid="89a849ef-e2ed-4bf2-ac31-81d34aba672a")
2649    @TelephonyBaseTest.tel_test_wrap
2650    def test_tethering_wifi_screen_off_enable_doze_mode(self):
2651        """WiFi Tethering test: Start WiFi tethering, then turn off DUT's screen,
2652            then enable doze mode.
2653
2654        1. Start WiFi tethering on DUT.
2655        2. PhoneB disable data, and connect to DUT's softAP
2656        3. Verify Internet access on DUT and PhoneB
2657        4. Turn off DUT's screen. Wait for 1 minute and
2658            verify Internet access on Client PhoneB.
2659        5. Enable doze mode on DUT. Wait for 1 minute and
2660            verify Internet access on Client PhoneB.
2661
2662        Returns:
2663            True if success.
2664            False if failed.
2665        """
2666        if not self._test_setup_tethering():
2667            self.log.error("Verify Internet access failed.")
2668            return False
2669        try:
2670            if not wifi_tethering_setup_teardown(
2671                    self.log,
2672                    self.provider, [self.clients[0]],
2673                    ap_band=WIFI_CONFIG_APBAND_2G,
2674                    check_interval=10,
2675                    check_iteration=2,
2676                    do_cleanup=False):
2677                self.log.error("WiFi Tethering failed.")
2678                return False
2679
2680            if not self.provider.droid.wifiIsApEnabled():
2681                self.provider.log.error("Provider WiFi tethering stopped.")
2682                return False
2683
2684            self.provider.log.info("Turn off screen on provider")
2685            self.provider.droid.goToSleepNow()
2686            time.sleep(60)
2687            if not verify_internet_connection(self.log, self.clients[0]):
2688                self.client.log.error("Client have no Internet access.")
2689                return False
2690
2691            self.provider.log.info("Enable doze mode on provider")
2692            if not enable_doze(self.provider):
2693                self.provider.log.error("Failed to enable doze mode.")
2694                return False
2695            time.sleep(60)
2696            if not verify_internet_connection(self.log, self.clients[0]):
2697                self.clients[0].log.error("Client have no Internet access.")
2698                return False
2699        finally:
2700            self.log.info("Disable doze mode.")
2701            if not disable_doze(self.provider):
2702                self.log.error("Failed to disable doze mode.")
2703                return False
2704            if not wifi_tethering_cleanup(self.log, self.provider,
2705                                          [self.clients[0]]):
2706                return False
2707        return True
2708
2709    @test_tracker_info(uuid="695eef18-f759-4b41-8ad3-1fb329ee4b1b")
2710    @TelephonyBaseTest.tel_test_wrap
2711    def test_msim_switch_data_sim_2g(self):
2712        """Switch Data SIM on 2G network.
2713
2714        Steps:
2715        1. Data on default Data SIM.
2716        2. Switch Data to another SIM. Make sure data is still available.
2717        3. Switch Data back to previous SIM. Make sure data is still available.
2718
2719        Expected Results:
2720        1. Verify Data on Cell
2721        2. Verify Data on Wifi
2722
2723        Returns:
2724            True if success.
2725            False if failed.
2726        """
2727        ad = self.android_devices[0]
2728        current_data_sub_id = ad.droid.subscriptionGetDefaultDataSubId()
2729        current_sim_slot_index = get_slot_index_from_subid(
2730            self.log, ad, current_data_sub_id)
2731        if current_sim_slot_index == SIM1_SLOT_INDEX:
2732            next_sim_slot_index = SIM2_SLOT_INDEX
2733        else:
2734            next_sim_slot_index = SIM1_SLOT_INDEX
2735        next_data_sub_id = get_subid_from_slot_index(self.log, ad,
2736                                                     next_sim_slot_index)
2737        self.log.info("Current Data is on subId: {}, SIM slot: {}".format(
2738            current_data_sub_id, current_sim_slot_index))
2739        if not ensure_network_generation_for_subscription(
2740                self.log,
2741                ad,
2742                ad.droid.subscriptionGetDefaultDataSubId(),
2743                GEN_2G,
2744                voice_or_data=NETWORK_SERVICE_DATA):
2745            self.log.error("Device data does not attach to 2G.")
2746            return False
2747        if not verify_internet_connection(self.log, ad):
2748            self.log.error("No Internet access on default Data SIM.")
2749            return False
2750
2751        self.log.info("Change Data to subId: {}, SIM slot: {}".format(
2752            next_data_sub_id, next_sim_slot_index))
2753        if not change_data_sim_and_verify_data(self.log, ad,
2754                                               next_sim_slot_index):
2755            self.log.error("Failed to change data SIM.")
2756            return False
2757
2758        next_data_sub_id = current_data_sub_id
2759        next_sim_slot_index = current_sim_slot_index
2760        self.log.info("Change Data back to subId: {}, SIM slot: {}".format(
2761            next_data_sub_id, next_sim_slot_index))
2762        if not change_data_sim_and_verify_data(self.log, ad,
2763                                               next_sim_slot_index):
2764            self.log.error("Failed to change data SIM.")
2765            return False
2766
2767        return True
2768
2769    def _test_wifi_connect_disconnect(self):
2770        """Perform multiple connects and disconnects from WiFi and verify that
2771            data switches between WiFi and Cell.
2772
2773        Steps:
2774        1. Reset Wifi on DUT
2775        2. Connect DUT to a WiFi AP
2776        3. Repeat steps 1-2, alternately disconnecting and disabling wifi
2777
2778        Expected Results:
2779        1. Verify Data on Cell
2780        2. Verify Data on Wifi
2781
2782        Returns:
2783            True if success.
2784            False if failed.
2785        """
2786        ad = self.android_devices[0]
2787
2788        wifi_toggles = [
2789            True, False, True, False, False, True, False, False, False, False,
2790            True, False, False, False, False, False, False, False, False
2791        ]
2792
2793        for toggle in wifi_toggles:
2794
2795            wifi_reset(self.log, ad, toggle)
2796
2797            if not wait_for_cell_data_connection(
2798                    self.log, ad, True, MAX_WAIT_TIME_WIFI_CONNECTION):
2799                self.log.error("Failed wifi connection, aborting!")
2800                return False
2801
2802            if not verify_internet_connection(self.log, ad):
2803                self.log.error("Failed to get user-plane traffic, aborting!")
2804                return False
2805
2806            if toggle:
2807                wifi_toggle_state(self.log, ad, True)
2808
2809            ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
2810                         self.wifi_network_pass)
2811
2812            if not wait_for_wifi_data_connection(
2813                    self.log, ad, True, MAX_WAIT_TIME_WIFI_CONNECTION):
2814                self.log.error("Failed wifi connection, aborting!")
2815                return False
2816
2817            if not verify_http_connection(
2818                    self.log, ad, 'http://www.google.com', 100, .1):
2819                self.log.error("Failed to get user-plane traffic, aborting!")
2820                return False
2821        return True
2822
2823    @test_tracker_info(uuid="9b8e92da-0ae1-472c-a72a-f6427e5405ce")
2824    @TelephonyBaseTest.tel_test_wrap
2825    def test_wifi_connect_disconnect_4g(self):
2826        """Perform multiple connects and disconnects from WiFi and verify that
2827            data switches between WiFi and Cell.
2828
2829        Steps:
2830        1. DUT Cellular Data is on 4G. Reset Wifi on DUT
2831        2. Connect DUT to a WiFi AP
2832        3. Repeat steps 1-2, alternately disconnecting and disabling wifi
2833
2834        Expected Results:
2835        1. Verify Data on Cell
2836        2. Verify Data on Wifi
2837
2838        Returns:
2839            True if success.
2840            False if failed.
2841        """
2842
2843        ad = self.android_devices[0]
2844        if not ensure_network_generation_for_subscription(
2845                self.log, ad, ad.droid.subscriptionGetDefaultDataSubId(),
2846                GEN_4G, MAX_WAIT_TIME_NW_SELECTION, NETWORK_SERVICE_DATA):
2847            self.log.error("Device {} failed to reselect in {}s.".format(
2848                ad.serial, MAX_WAIT_TIME_NW_SELECTION))
2849            return False
2850        return self._test_wifi_connect_disconnect()
2851
2852    @test_tracker_info(uuid="09893b1f-a4a2-49d3-8027-c2c91cb8742e")
2853    @TelephonyBaseTest.tel_test_wrap
2854    def test_wifi_connect_disconnect_3g(self):
2855        """Perform multiple connects and disconnects from WiFi and verify that
2856            data switches between WiFi and Cell.
2857
2858        Steps:
2859        1. DUT Cellular Data is on 3G. Reset Wifi on DUT
2860        2. Connect DUT to a WiFi AP
2861        3. Repeat steps 1-2, alternately disconnecting and disabling wifi
2862
2863        Expected Results:
2864        1. Verify Data on Cell
2865        2. Verify Data on Wifi
2866
2867        Returns:
2868            True if success.
2869            False if failed.
2870        """
2871
2872        ad = self.android_devices[0]
2873        if not ensure_network_generation_for_subscription(
2874                self.log, ad, ad.droid.subscriptionGetDefaultDataSubId(),
2875                GEN_3G, MAX_WAIT_TIME_NW_SELECTION, NETWORK_SERVICE_DATA):
2876            self.log.error("Device {} failed to reselect in {}s.".format(
2877                ad.serial, MAX_WAIT_TIME_NW_SELECTION))
2878            return False
2879        return self._test_wifi_connect_disconnect()
2880
2881    @test_tracker_info(uuid="0f095ca4-ce05-458f-9670-49a69f8c8270")
2882    @TelephonyBaseTest.tel_test_wrap
2883    def test_wifi_connect_disconnect_2g(self):
2884        """Perform multiple connects and disconnects from WiFi and verify that
2885            data switches between WiFi and Cell.
2886
2887        Steps:
2888        1. DUT Cellular Data is on 2G. Reset Wifi on DUT
2889        2. Connect DUT to a WiFi AP
2890        3. Repeat steps 1-2, alternately disconnecting and disabling wifi
2891
2892        Expected Results:
2893        1. Verify Data on Cell
2894        2. Verify Data on Wifi
2895
2896        Returns:
2897            True if success.
2898            False if failed.
2899        """
2900        ad = self.android_devices[0]
2901        if not ensure_network_generation_for_subscription(
2902                self.log, ad, ad.droid.subscriptionGetDefaultDataSubId(),
2903                GEN_2G, MAX_WAIT_TIME_NW_SELECTION, NETWORK_SERVICE_DATA):
2904            self.log.error("Device {} failed to reselect in {}s.".format(
2905                ad.serial, MAX_WAIT_TIME_NW_SELECTION))
2906            return False
2907        return self._test_wifi_connect_disconnect()
2908
2909    def _test_wifi_tethering_enabled_add_voice_call(
2910            self, network_generation, voice_call_direction,
2911            is_data_available_during_call):
2912        """Tethering enabled + voice call.
2913
2914        Steps:
2915        1. DUT data is on <network_generation>. Start WiFi Tethering.
2916        2. PhoneB connect to DUT's softAP
2917        3. DUT make a MO/MT (<voice_call_direction>) phone call.
2918        4. DUT end phone call.
2919
2920        Expected Results:
2921        1. DUT is able to start WiFi tethering.
2922        2. PhoneB connected to DUT's softAP and able to browse Internet.
2923        3. DUT WiFi tethering is still on. Phone call works OK.
2924            If is_data_available_during_call is True, then PhoneB still has
2925            Internet access.
2926            Else, then Data is suspend, PhoneB has no Internet access.
2927        4. WiFi Tethering still on, voice call stopped, and PhoneB have Internet
2928            access.
2929
2930        Returns:
2931            True if success.
2932            False if failed.
2933        """
2934        if not self._test_setup_tethering(network_generation):
2935            self.log.error("Verify Internet access failed.")
2936            return False
2937        try:
2938            # Start WiFi Tethering
2939            if not wifi_tethering_setup_teardown(
2940                    self.log,
2941                    self.provider, [self.clients[0]],
2942                    ap_band=WIFI_CONFIG_APBAND_2G,
2943                    check_interval=10,
2944                    check_iteration=2,
2945                    do_cleanup=False):
2946                self.log.error("WiFi Tethering failed.")
2947                return False
2948
2949            if not self.provider.droid.wifiIsApEnabled():
2950                self.log.error("Provider WiFi tethering stopped.")
2951                return False
2952
2953            # Make a voice call
2954            if voice_call_direction == DIRECTION_MOBILE_ORIGINATED:
2955                ad_caller = self.provider
2956                ad_callee = self.clients[0]
2957            else:
2958                ad_caller = self.clients[0]
2959                ad_callee = self.provider
2960            if not call_setup_teardown(self.log, ad_caller, ad_callee, None,
2961                                       None, None):
2962                self.log.error("Failed to Establish {} Voice Call".format(
2963                    voice_call_direction))
2964                return False
2965
2966            # Tethering should still be on.
2967            if not self.provider.droid.wifiIsApEnabled():
2968                self.provider.log.error("Provider WiFi tethering stopped.")
2969                return False
2970            if not is_data_available_during_call:
2971                if verify_internet_connection(
2972                        self.log, self.clients[0], retry=0):
2973                    self.clients[0].log.error(
2974                        "Client should not have Internet Access.")
2975                    return False
2976            else:
2977                if not verify_internet_connection(self.log, self.clients[0]):
2978                    self.clients[0].error(
2979                        "Client should have Internet Access.")
2980                    return False
2981
2982            # Hangup call. Client should have data.
2983            if not hangup_call(self.log, self.provider):
2984                self.provider.log.error("Failed to hang up call")
2985                return False
2986            if not self.provider.droid.wifiIsApEnabled():
2987                self.provider.log.error("Provider WiFi tethering stopped.")
2988                return False
2989            if not verify_internet_connection(self.log, self.clients[0]):
2990                self.clients[0].log.error(
2991                    "Client should have Internet Access.")
2992                return False
2993        finally:
2994            self.clients[0].droid.telephonyToggleDataConnection(True)
2995            wifi_reset(self.log, self.clients[0])
2996            if self.provider.droid.wifiIsApEnabled():
2997                stop_wifi_tethering(self.log, self.provider)
2998        return True
2999
3000    @test_tracker_info(uuid="4d7a68c6-5eae-4242-a6e6-668f830caec3")
3001    @TelephonyBaseTest.tel_test_wrap
3002    def test_wifi_tethering_enabled_add_mo_voice_call_2g_dsds(self):
3003        """Tethering enabled + voice call
3004
3005        Steps:
3006        1. DUT is DSDS device, Data on 2G. Start WiFi Tethering on <Data SIM>
3007        2. PhoneB connect to DUT's softAP
3008        3. DUT make a mo phone call on <Voice SIM>
3009        4. DUT end phone call.
3010
3011        Expected Results:
3012        1. DUT is able to start WiFi tethering.
3013        2. PhoneB connected to DUT's softAP and able to browse Internet.
3014        3. DUT WiFi tethering is still on. Phone call works OK. Data is suspend,
3015            PhoneB still connected to DUT's softAP, but no data available.
3016        4. DUT data resumes, and PhoneB have Internet access.
3017
3018        Returns:
3019            True if success.
3020            False if failed.
3021        """
3022
3023        return self._test_wifi_tethering_enabled_add_voice_call(
3024            GEN_2G, DIRECTION_MOBILE_ORIGINATED, False)
3025
3026    @test_tracker_info(uuid="de720069-a46c-4a6f-ae80-60b9349c8528")
3027    @TelephonyBaseTest.tel_test_wrap
3028    def test_wifi_tethering_enabled_add_mt_voice_call_2g_dsds(self):
3029        """Tethering enabled + voice call
3030
3031        Steps:
3032        1. DUT is DSDS device, Data on 2G. Start WiFi Tethering on <Data SIM>
3033        2. PhoneB connect to DUT's softAP
3034        3. DUT make a mt phone call on <Voice SIM>
3035        4. DUT end phone call.
3036
3037        Expected Results:
3038        1. DUT is able to start WiFi tethering.
3039        2. PhoneB connected to DUT's softAP and able to browse Internet.
3040        3. DUT WiFi tethering is still on. Phone call works OK. Data is suspend,
3041            PhoneB still connected to DUT's softAP, but no data available.
3042        4. DUT data resumes, and PhoneB have Internet access.
3043
3044        Returns:
3045            True if success.
3046            False if failed.
3047        """
3048
3049        return self._test_wifi_tethering_enabled_add_voice_call(
3050            GEN_2G, DIRECTION_MOBILE_TERMINATED, False)
3051
3052    @test_tracker_info(uuid="fad169c0-8ae6-45d2-98ba-3fb60466ff0b")
3053    @TelephonyBaseTest.tel_test_wrap
3054    def test_wifi_tethering_msim_switch_data_sim(self):
3055        """Tethering enabled + switch data SIM.
3056
3057        Steps:
3058        1. Start WiFi Tethering on <Default Data SIM>
3059        2. PhoneB connect to DUT's softAP
3060        3. DUT change Default Data SIM.
3061
3062        Expected Results:
3063        1. DUT is able to start WiFi tethering.
3064        2. PhoneB connected to DUT's softAP and able to browse Internet.
3065        3. DUT Data changed to 2nd SIM, WiFi tethering should continues,
3066            PhoneB should have Internet access.
3067
3068        Returns:
3069            True if success.
3070            False if failed.
3071        """
3072        current_data_sub_id = self.provider.droid.subscriptionGetDefaultDataSubId(
3073        )
3074        current_sim_slot_index = get_slot_index_from_subid(
3075            self.log, self.provider, current_data_sub_id)
3076        self.provider.log.info("Current Data is on subId: %s, SIM slot: %s",
3077                               current_data_sub_id, current_sim_slot_index)
3078        if not self._test_setup_tethering():
3079            self.log.error("Verify Internet access failed.")
3080            return False
3081        try:
3082            # Start WiFi Tethering
3083            if not wifi_tethering_setup_teardown(
3084                    self.log,
3085                    self.provider, [self.clients[0]],
3086                    ap_band=WIFI_CONFIG_APBAND_2G,
3087                    check_interval=10,
3088                    check_iteration=2,
3089                    do_cleanup=False):
3090                self.log.error("WiFi Tethering failed.")
3091                return False
3092            for i in range(0, 2):
3093                next_sim_slot_index = \
3094                    {SIM1_SLOT_INDEX : SIM2_SLOT_INDEX,
3095                     SIM2_SLOT_INDEX : SIM1_SLOT_INDEX}[current_sim_slot_index]
3096                self.log.info(
3097                    "Change Data to SIM slot: {}".format(next_sim_slot_index))
3098                if not change_data_sim_and_verify_data(self.log, self.provider,
3099                                                       next_sim_slot_index):
3100                    self.provider.log.error("Failed to change data SIM.")
3101                    return False
3102                current_sim_slot_index = next_sim_slot_index
3103                if not verify_internet_connection(self.log, self.clients[0]):
3104                    self.clients[0].log.error(
3105                        "Client should have Internet Access.")
3106                    return False
3107        finally:
3108            self.clients[0].droid.telephonyToggleDataConnection(True)
3109            wifi_reset(self.log, self.clients[0])
3110            if self.provider.droid.wifiIsApEnabled():
3111                stop_wifi_tethering(self.log, self.provider)
3112        return True
3113
3114    @test_tracker_info(uuid="8bb9383f-ddf9-400c-a831-c9462bae6b47")
3115    @TelephonyBaseTest.tel_test_wrap
3116    def test_msim_cell_data_switch_to_wifi_switch_data_sim_2g(self):
3117        """Switch Data SIM on 2G network.
3118
3119        Steps:
3120        1. Data on default Data SIM.
3121        2. Turn on WiFi, then data should be on WiFi.
3122        3. Switch Data to another SIM. Disable WiFi.
3123
3124        Expected Results:
3125        1. Verify Data on Cell
3126        2. Verify Data on WiFi
3127        3. After WiFi disabled, Cell Data is available on 2nd SIM.
3128
3129        Returns:
3130            True if success.
3131            False if failed.
3132        """
3133        ad = self.android_devices[0]
3134        current_data_sub_id = ad.droid.subscriptionGetDefaultDataSubId()
3135        current_sim_slot_index = get_slot_index_from_subid(
3136            self.log, ad, current_data_sub_id)
3137        if current_sim_slot_index == SIM1_SLOT_INDEX:
3138            next_sim_slot_index = SIM2_SLOT_INDEX
3139        else:
3140            next_sim_slot_index = SIM1_SLOT_INDEX
3141        next_data_sub_id = get_subid_from_slot_index(self.log, ad,
3142                                                     next_sim_slot_index)
3143        self.log.info("Current Data is on subId: {}, SIM slot: {}".format(
3144            current_data_sub_id, current_sim_slot_index))
3145        if not ensure_network_generation_for_subscription(
3146                self.log,
3147                ad,
3148                ad.droid.subscriptionGetDefaultDataSubId(),
3149                GEN_2G,
3150                voice_or_data=NETWORK_SERVICE_DATA):
3151            self.log.error("Device data does not attach to 2G.")
3152            return False
3153        if not verify_internet_connection(self.log, ad):
3154            self.log.error("No Internet access on default Data SIM.")
3155            return False
3156
3157        self.log.info("Connect to WiFi and verify Internet access.")
3158        if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
3159                                     self.wifi_network_pass):
3160            self.log.error("WiFi connect fail.")
3161            return False
3162        if (not wait_for_wifi_data_connection(self.log, ad, True)
3163                or not verify_internet_connection(self.log, ad)):
3164            self.log.error("Data is not on WiFi")
3165            return False
3166
3167        try:
3168            self.log.info(
3169                "Change Data SIM, Disable WiFi and verify Internet access.")
3170            set_subid_for_data(ad, next_data_sub_id)
3171            wifi_toggle_state(self.log, ad, False)
3172            if not wait_for_data_attach_for_subscription(
3173                    self.log, ad, next_data_sub_id,
3174                    MAX_WAIT_TIME_NW_SELECTION):
3175                self.log.error("Failed to attach data on subId:{}".format(
3176                    next_data_sub_id))
3177                return False
3178            if not verify_internet_connection(self.log, ad):
3179                self.log.error("No Internet access after changing Data SIM.")
3180                return False
3181
3182        finally:
3183            self.log.info("Change Data SIM back.")
3184            set_subid_for_data(ad, current_data_sub_id)
3185
3186        return True
3187
3188    @test_tracker_info(uuid="ef03eff7-ddd3-48e9-8f67-5e271e14048b")
3189    @TelephonyBaseTest.tel_test_wrap
3190    def test_vzw_embms_services(self):
3191        ad = self.android_devices[0]
3192        # Install App and Push config
3193        self.log.info("Pushing embms config and apk to the Android device.")
3194        android_embms_path = "/sdcard/mobitv"
3195        embms_path = self.user_params.get("embms_path", "embms_path")
3196        if isinstance(embms_path, list):
3197            embms_path = embms_path[0]
3198        ad.adb.shell("mkdir /sdcard/mobitv")
3199        dcafile = os.path.join(embms_path, "dca.config")
3200        apkfile = os.path.join(embms_path, "VzwDCA.apk")
3201        ad.adb.push("%s %s" % (dcafile, android_embms_path))
3202        ad.adb.install("%s" % apkfile)
3203
3204        # Co-ordinates Mapping
3205        lcd_density = ad.adb.shell("getprop ro.sf.lcd_density")
3206        ad.log.debug("lcd_density %s" % lcd_density)
3207        if lcd_density in ["420", "440"]:
3208            agree_y_axis = 1000
3209        else:
3210            agree_y_axis = 1300
3211
3212        # Screen ON needed to open the VZW App
3213        if "ON" in \
3214        ad.adb.shell(
3215               "dumpsys power | grep 'Display Power: state' | cut -d '=' -f2"):
3216            ad.log.info("Screen already ON")
3217            ad.adb.shell("input keyevent 82")
3218        else:
3219            ad.log.info("Screen OFF, turning ON")
3220            ad.adb.shell("input keyevent 26")
3221            ad.adb.shell("input keyevent 82")
3222
3223        try:
3224            # Check if app is installed
3225            if ad.is_apk_installed("com.mobitv.vzwdca"):
3226                ad.log.info("VZWDCA App is successfully installed")
3227            else:
3228                ad.log.error("VZWDCA App is not installed")
3229                return False
3230
3231            # Grant Permissions, Start, Agree, Register
3232            for cmd in ("pm grant com.mobitv.vzwdca "
3233                        "android.permission.READ_EXTERNAL_STORAGE",
3234                        "pm grant com.mobitv.vzwdca "
3235                        "android.permission.WRITE_EXTERNAL_STORAGE",
3236                        "am start -a android.intent.action.VIEW -n "
3237                        "com.mobitv.vzwdca/.DcaActivity",
3238                        "input tap 500 %d" % agree_y_axis, "input keyevent 61",
3239                        "input keyevent 61", "input keyevent 61",
3240                        "input keyevent 61", "input keyevent 61",
3241                        "input keyevent 66"):
3242                time.sleep(1)
3243                ad.log.info(cmd)
3244                ad.adb.shell(cmd)
3245
3246            # Check Reg-DeReg
3247            time.sleep(5)
3248            if ad.is_apk_running("com.qualcomm.ltebc_vzw"):
3249                ad.log.info("EMBMS Registered successfully")
3250                ad.adb.shell("input keyevent 61")
3251                time.sleep(1)
3252                ad.adb.shell("input keyevent 66")
3253                time.sleep(1)
3254                if not ad.is_apk_running("com.qualcomm.ltebc_vzw"):
3255                    ad.log.info("EMBMS De-Registered successfully")
3256                    return True
3257                else:
3258                    ad.log.error("EMBMS De-Registeration Failed")
3259                    return False
3260            else:
3261                ad.log.error("EMBMS Registeration Failed")
3262                return False
3263        finally:
3264            ad.log.info("Force Close the VZW App")
3265            ad.adb.shell("am force-stop com.mobitv.vzwdca")
3266
3267    @test_tracker_info(uuid="8a8cd773-77f5-4802-85ac-1a654bb4743c")
3268    @TelephonyBaseTest.tel_test_wrap
3269    def test_disable_data_on_non_active_data_sim(self):
3270        """Switch Data SIM on 2G network.
3271
3272        Steps:
3273        1. Data on default Data SIM.
3274        2. Disable data on non-active Data SIM.
3275
3276        Expected Results:
3277        1. Verify Data Status on Default Data SIM and non-active Data SIM.
3278        1. Verify Data Status on Default Data SIM and non-active Data SIM.
3279
3280        Returns:
3281            True if success.
3282            False if failed.
3283        """
3284        ad = self.android_devices[0]
3285        current_data_sub_id = ad.droid.subscriptionGetDefaultDataSubId()
3286        current_sim_slot_index = get_slot_index_from_subid(
3287            self.log, ad, current_data_sub_id)
3288        if current_sim_slot_index == SIM1_SLOT_INDEX:
3289            non_active_sim_slot_index = SIM2_SLOT_INDEX
3290        else:
3291            non_active_sim_slot_index = SIM1_SLOT_INDEX
3292        non_active_sub_id = get_subid_from_slot_index(
3293            self.log, ad, non_active_sim_slot_index)
3294        self.log.info("Current Data is on subId: {}, SIM slot: {}".format(
3295            current_data_sub_id, current_sim_slot_index))
3296
3297        if not ensure_network_generation_for_subscription(
3298                self.log,
3299                ad,
3300                ad.droid.subscriptionGetDefaultDataSubId(),
3301                GEN_2G,
3302                voice_or_data=NETWORK_SERVICE_DATA):
3303            self.log.error("Device data does not attach to 2G.")
3304            return False
3305        if not verify_internet_connection(self.log, ad):
3306            self.log.error("No Internet access on default Data SIM.")
3307            return False
3308
3309        if ad.droid.telephonyGetDataConnectionState() != DATA_STATE_CONNECTED:
3310            self.log.error("Data Connection State should be connected.")
3311            return False
3312        # TODO: Check Data state for non-active subId.
3313
3314        try:
3315            self.log.info("Disable Data on Non-Active Sub ID")
3316            ad.droid.telephonyToggleDataConnectionForSubscription(
3317                non_active_sub_id, False)
3318            # TODO: Check Data state for non-active subId.
3319            if ad.droid.telephonyGetDataConnectionState(
3320            ) != DATA_STATE_CONNECTED:
3321                self.log.error("Data Connection State should be connected.")
3322                return False
3323        finally:
3324            self.log.info("Enable Data on Non-Active Sub ID")
3325            ad.droid.telephonyToggleDataConnectionForSubscription(
3326                non_active_sub_id, True)
3327        return True
3328
3329    def file_download_stress(self):
3330        failure = 0
3331        total_count = 0
3332        self.result_info = collections.defaultdict(int)
3333        dut = self.android_devices[0]
3334        self.max_sleep_time = int(self.user_params.get("max_sleep_time", 1200))
3335        #file_names = ["5MB", "10MB", "20MB", "50MB", "200MB", "512MB", "1GB"]
3336        file_names = ["5MB", "10MB", "20MB", "50MB", "200MB", "512MB"]
3337        while total_count < self.stress_test_number:
3338            total_count += 1
3339            try:
3340                dut.log.info(dict(self.result_info))
3341                selection = random.randrange(0, len(file_names))
3342                file_name = file_names[selection]
3343                self.result_info["Total %s file download" % file_name] += 1
3344                if not active_file_download_test(self.log, dut, file_name):
3345                    self.result_info["%s file download failure" %
3346                                     file_name] += 1
3347                    failure += 1
3348                    dut.take_bug_report("%s_failure_%s" % (self.test_name,
3349                                                           failure),
3350                                        time.strftime("%m-%d-%Y-%H-%M-%S"))
3351                    self.dut.droid.goToSleepNow()
3352                    time.sleep(random.randrange(0, self.max_sleep_time))
3353            except Exception as e:
3354                self.log.error("Exception error %s", str(e))
3355                self.result_info["Exception Errors"] += 1
3356            dut.log.info("File download test failure: %s/%s", failure,
3357                         total_count)
3358        if failure / total_count > 0.1:
3359            dut.log.error("File download test failure: %s/%s", failure,
3360                          total_count)
3361            return False
3362        return True
3363
3364    @test_tracker_info(uuid="5381a6fa-6771-4b00-a0d6-4a3891a6dba8")
3365    @TelephonyBaseTest.tel_test_wrap
3366    def test_file_download_stress_default(self):
3367        """File download stress test
3368
3369        Steps:
3370        1. Download a file random picked.
3371        2. Device sleep for sometime and Repeat 1.
3372
3373        Expected Results:
3374        Total download failure rate is less than 10%.
3375
3376        Returns:
3377            True if success.
3378            False if failed.
3379        """
3380        return self.file_download_stress()
3381
3382    @test_tracker_info(uuid="c9970955-123b-467c-afbb-95ec8f99e9b7")
3383    def test_file_download_with_mobile_data_usage_limit_set(self):
3384        """ Steps:
3385
3386        1. Set the data usage limit to current data usage + 9MB
3387        2. Download 5MB file from internet.
3388        3. The first file download should succeed
3389        4. The second file download should fail
3390
3391        """
3392        dut = self.android_devices[0]
3393        ensure_phones_default_state(self.log, [dut])
3394        subscriber_id = dut.droid.telephonyGetSubscriberId()
3395        old_data_usage = get_mobile_data_usage(dut, subscriber_id)
3396
3397        # set data usage limit to current usage limit + 10MB
3398        data_limit = old_data_usage + 9 * 1000 * 1000
3399        set_mobile_data_usage_limit(dut, data_limit, subscriber_id)
3400
3401        # download file - size 5MB twice
3402        try:
3403            for _ in range(2):
3404                if not active_file_download_test(self.log, dut, "5MB", "curl"):
3405                    if get_mobile_data_usage(
3406                            dut, subscriber_id) + 5 * 1000 * 1000 < data_limit:
3407                        dut.log.error(
3408                            "Fail to download file when mobile data usage is"
3409                            " below data usage limit")
3410                        return False
3411                    else:
3412                        dut.log.info(
3413                            "Download fails as expected due to data limit reached"
3414                        )
3415                else:
3416                    if get_mobile_data_usage(dut, subscriber_id) < data_limit:
3417                        dut.log.info(
3418                            "Download file succeed when mobile data usage is"
3419                            " below data usage limit")
3420                    else:
3421                        dut.log.error(
3422                            "Download should fail due to data limit reached")
3423                        return False
3424            return True
3425        finally:
3426            remove_mobile_data_usage_limit(dut, subscriber_id)
3427
3428
3429    def _test_data_stall_detection_recovery(self, nw_type="cellular",
3430                                            validation_type="detection"):
3431        dut = self.android_devices[0]
3432        try:
3433            cmd = ('ss -l -p -n | grep "tcp.*droid_script" | tr -s " " '
3434                   '| cut -d " " -f 5 | sed s/.*://g')
3435            sl4a_port = dut.adb.shell(cmd)
3436            ensure_phones_default_state(self.log, [dut])
3437            if nw_type == "wifi":
3438                if not ensure_wifi_connected(self.log, dut,
3439                                self.wifi_network_ssid, self.wifi_network_pass):
3440                    return False
3441
3442            if not test_data_browsing_success_using_sl4a(self.log, dut):
3443                dut.log.error("Browsing failed before the test, aborting!")
3444                return False
3445
3446            begin_time = get_device_epoch_time(dut)
3447            break_internet_except_sl4a_port(dut, sl4a_port)
3448
3449            if not test_data_browsing_failure_using_sl4a(self.log, dut):
3450                dut.log.error("Browsing success even after breaking internet, "\
3451                              "aborting!")
3452                return False
3453
3454            if not check_data_stall_detection(dut):
3455                dut.log.error("NetworkMonitor unable to detect Data Stall")
3456
3457            if not check_network_validation_fail(dut, begin_time):
3458                dut.log.error("Unable to detect NW validation fail")
3459                return False
3460
3461            if validation_type == "recovery":
3462                if not check_data_stall_recovery(dut, begin_time):
3463                    dut.log.error("Recovery was not triggerred")
3464                    return False
3465
3466            resume_internet_with_sl4a_port(dut, sl4a_port)
3467            time.sleep(10)
3468
3469            if not test_data_browsing_success_using_sl4a(self.log, dut):
3470                dut.log.error("Browsing failed after resuming internet")
3471                return False
3472            return True
3473        finally:
3474            resume_internet_with_sl4a_port(dut, sl4a_port)
3475
3476
3477    def _test_airplane_mode_stress(self):
3478        ad = self.android_devices[0]
3479        total_iteration = self.stress_test_number
3480        fail_count = collections.defaultdict(int)
3481        current_iteration = 1
3482        for i in range(1, total_iteration + 1):
3483            msg = "Airplane mode test Iteration: <%s> / <%s>" % (i, total_iteration)
3484            self.log.info(msg)
3485            if not airplane_mode_test(self.log, ad):
3486                fail_count["apm_run"] += 1
3487                ad.log.error(">----Iteration : %d/%d failed.----<",
3488                             i, total_iteration)
3489            ad.log.info(">----Iteration : %d/%d succeeded.----<",
3490                        i, total_iteration)
3491            current_iteration += 1
3492        test_result = True
3493        for failure, count in fail_count.items():
3494            if count:
3495                ad.log.error("%s: %s %s failures in %s iterations",
3496                             self.test_name, count, failure,
3497                             total_iteration)
3498                test_result = False
3499        return test_result
3500
3501
3502    @test_tracker_info(uuid="3a82728f-18b5-4a35-9eab-4e6cf55271d9")
3503    @TelephonyBaseTest.tel_test_wrap
3504    def test_apm_toggle_stress(self):
3505        """ Test airplane mode toggle
3506
3507        1. Start with airplane mode off
3508        2. Toggle airplane mode on
3509        3. Toggle airplane mode off
3510        4. Repeat above steps
3511
3512        Returns:
3513            True if pass; False if fail.
3514        """
3515        return self._test_airplane_mode_stress()
3516
3517
3518    @test_tracker_info(uuid="fda33416-698a-408f-8ddc-b5cde13b1f83")
3519    @TelephonyBaseTest.tel_test_wrap
3520    def test_data_stall_detection_cellular(self):
3521        """ Data Stall Detection Testing
3522
3523        1. Ensure device is camped, browsing working fine
3524        2. Break Internet access, browsing should fail
3525        3. Check for Data Stall Detection
3526
3527        """
3528        return self._test_data_stall_detection_recovery(nw_type="cellular")
3529
3530
3531    @test_tracker_info(uuid="a57891d6-7892-46c7-8bca-23cd2cca8552")
3532    @TelephonyBaseTest.tel_test_wrap
3533    def test_data_stall_detection_wifi(self):
3534        """ Data Stall Detection Testing
3535
3536        1. Ensure device is connected to WiFi, browsing working fine
3537        2. Break Internet access, browsing should fail
3538        3. Check for Data Stall Detection
3539
3540        """
3541        return self._test_data_stall_detection_recovery(nw_type="wifi")
3542
3543
3544    @test_tracker_info(uuid="16d3f123-cac3-45a9-a2e5-c01bab7044d4")
3545    @TelephonyBaseTest.tel_test_wrap
3546    def test_data_stall_recovery_cellular(self):
3547        """ Data Stall Recovery Testing
3548
3549        1. Ensure device is camped, browsing working fine
3550        2. Break Internet access, browsing should fail
3551        3. Check for Data Stall Detection
3552        4. Check for Data Stall Recovery
3553
3554        """
3555        return self._test_data_stall_detection_recovery(nw_type="cellular",
3556                                                validation_type="recovery")
3557
3558    @test_tracker_info(uuid="cd1429e8-94d7-44de-ae48-68cf42f3246b")
3559    @TelephonyBaseTest.tel_test_wrap
3560    def test_browsing_5g(self):
3561        ad = self.android_devices[0]
3562        ad.log.info("Connect to NR and verify internet connection.")
3563        if not phone_setup_5g(self.log, ad):
3564            return False
3565        if not verify_internet_connection(self.log, ad):
3566            return False
3567
3568        return browsing_test(self.log, self.android_devices[0])
3569
3570    @test_tracker_info(uuid="d705d653-c810-42eb-bd07-3313f99be2fa")
3571    @TelephonyBaseTest.tel_test_wrap
3572    def test_browsing_4g(self):
3573        ad = self.android_devices[0]
3574        self.log.info("Connect to LTE and verify internet connection.")
3575        if not phone_setup_4g(self.log, ad):
3576            return False
3577        if not verify_internet_connection(self.log, ad):
3578            return False
3579
3580        return browsing_test(self.log, self.android_devices[0])
3581
3582    @test_tracker_info(uuid="71088cb1-5ccb-4d3a-8e6a-03fac9bf31cc")
3583    @TelephonyBaseTest.tel_test_wrap
3584    def test_browsing_wifi(self):
3585        ad = self.android_devices[0]
3586        self.log.info("Connect to Wi-Fi and verify internet connection.")
3587        if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
3588                                     self.wifi_network_pass):
3589            return False
3590        if not wait_for_wifi_data_connection(self.log, ad, True):
3591            return False
3592        if not verify_internet_connection(self.log, ad):
3593            return False
3594
3595        return browsing_test(self.log, self.android_devices[0], wifi_ssid=self.wifi_network_ssid)
3596
3597    """ Tests End """
3598