• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3.4
2#
3#   Copyright 2022 - 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.utils import rand_ascii_str
27from acts.test_decorators import test_tracker_info
28from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
29from acts_contrib.test_utils.tel.tel_defines import DIRECTION_MOBILE_ORIGINATED
30from acts_contrib.test_utils.tel.tel_defines import DIRECTION_MOBILE_TERMINATED
31from acts_contrib.test_utils.tel.tel_defines import DATA_STATE_CONNECTED
32from acts_contrib.test_utils.tel.tel_defines import FAKE_DATE_TIME
33from acts_contrib.test_utils.tel.tel_defines import FAKE_YEAR
34from acts_contrib.test_utils.tel.tel_defines import GEN_2G
35from acts_contrib.test_utils.tel.tel_defines import GEN_3G
36from acts_contrib.test_utils.tel.tel_defines import GEN_4G
37from acts_contrib.test_utils.tel.tel_defines import NETWORK_SERVICE_DATA
38from acts_contrib.test_utils.tel.tel_defines import RAT_2G
39from acts_contrib.test_utils.tel.tel_defines import RAT_3G
40from acts_contrib.test_utils.tel.tel_defines import RAT_4G
41from acts_contrib.test_utils.tel.tel_defines import SIM1_SLOT_INDEX
42from acts_contrib.test_utils.tel.tel_defines import SIM2_SLOT_INDEX
43from acts_contrib.test_utils.tel.tel_defines import MAX_WAIT_TIME_NW_SELECTION
44from acts_contrib.test_utils.tel.tel_defines import MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK
45from acts_contrib.test_utils.tel.tel_defines import TETHERING_MODE_WIFI
46from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_ANDROID_STATE_SETTLING
47from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_DATA_STATUS_CHANGE_DURING_WIFI_TETHERING
48from acts_contrib.test_utils.tel.tel_defines import TETHERING_PASSWORD_HAS_ESCAPE
49from acts_contrib.test_utils.tel.tel_defines import TETHERING_SPECIAL_SSID_LIST
50from acts_contrib.test_utils.tel.tel_defines import TETHERING_SPECIAL_PASSWORD_LIST
51from acts_contrib.test_utils.tel.tel_bt_utils import verify_bluetooth_tethering_connection
52from acts_contrib.test_utils.tel.tel_data_utils import active_file_download_test
53from acts_contrib.test_utils.tel.tel_data_utils import airplane_mode_test
54from acts_contrib.test_utils.tel.tel_data_utils import browsing_test
55from acts_contrib.test_utils.tel.tel_data_utils import get_mobile_data_usage
56from acts_contrib.test_utils.tel.tel_data_utils import reboot_test
57from acts_contrib.test_utils.tel.tel_data_utils import change_data_sim_and_verify_data
58from acts_contrib.test_utils.tel.tel_data_utils import check_data_stall_detection
59from acts_contrib.test_utils.tel.tel_data_utils import check_data_stall_recovery
60from acts_contrib.test_utils.tel.tel_data_utils import check_network_validation_fail
61from acts_contrib.test_utils.tel.tel_data_utils import data_connectivity_single_bearer
62from acts_contrib.test_utils.tel.tel_data_utils import remove_mobile_data_usage_limit
63from acts_contrib.test_utils.tel.tel_data_utils import set_mobile_data_usage_limit
64from acts_contrib.test_utils.tel.tel_data_utils import tethering_check_internet_connection
65from acts_contrib.test_utils.tel.tel_data_utils import test_data_connectivity_multi_bearer
66from acts_contrib.test_utils.tel.tel_data_utils import test_setup_tethering
67from acts_contrib.test_utils.tel.tel_data_utils import test_tethering_wifi_and_voice_call
68from acts_contrib.test_utils.tel.tel_data_utils import test_wifi_connect_disconnect
69from acts_contrib.test_utils.tel.tel_data_utils import wait_for_wifi_data_connection
70from acts_contrib.test_utils.tel.tel_data_utils import wifi_cell_switching
71from acts_contrib.test_utils.tel.tel_data_utils import wifi_tethering_cleanup
72from acts_contrib.test_utils.tel.tel_data_utils import verify_toggle_apm_tethering_internet_connection
73from acts_contrib.test_utils.tel.tel_data_utils import verify_tethering_entitlement_check
74from acts_contrib.test_utils.tel.tel_data_utils import wifi_tethering_setup_teardown
75from acts_contrib.test_utils.tel.tel_data_utils import test_wifi_tethering
76from acts_contrib.test_utils.tel.tel_data_utils import test_start_wifi_tethering_connect_teardown
77from acts_contrib.test_utils.tel.tel_data_utils import run_stress_test
78from acts_contrib.test_utils.tel.tel_data_utils import verify_wifi_tethering_when_reboot
79from acts_contrib.test_utils.tel.tel_data_utils import wait_and_verify_device_internet_connection
80from acts_contrib.test_utils.tel.tel_data_utils import setup_device_internet_connection
81from acts_contrib.test_utils.tel.tel_data_utils import setup_device_internet_connection_then_reboot
82from acts_contrib.test_utils.tel.tel_data_utils import verify_internet_connection_in_doze_mode
83from acts_contrib.test_utils.tel.tel_data_utils import verify_toggle_data_during_wifi_tethering
84from acts_contrib.test_utils.tel.tel_subscription_utils import get_slot_index_from_subid
85from acts_contrib.test_utils.tel.tel_subscription_utils import get_subid_from_slot_index
86from acts_contrib.test_utils.tel.tel_subscription_utils import set_subid_for_data
87from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_3g
88from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_voice_3g
89from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_csfb
90from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_volte
91from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_4g
92from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_phones_default_state
93from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_network_generation
94from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_network_generation_for_subscription
95from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode_by_adb
96from acts_contrib.test_utils.tel.tel_test_utils import verify_internet_connection
97from acts_contrib.test_utils.tel.tel_test_utils import wait_for_data_attach_for_subscription
98from acts_contrib.test_utils.tel.tel_test_utils import break_internet_except_sl4a_port
99from acts_contrib.test_utils.tel.tel_test_utils import resume_internet_with_sl4a_port
100from acts_contrib.test_utils.tel.tel_test_utils import get_device_epoch_time
101from acts_contrib.test_utils.tel.tel_test_utils import test_data_browsing_success_using_sl4a
102from acts_contrib.test_utils.tel.tel_test_utils import test_data_browsing_failure_using_sl4a
103from acts_contrib.test_utils.tel.tel_test_utils import set_time_sync_from_network
104from acts_contrib.test_utils.tel.tel_test_utils import datetime_handle
105from acts_contrib.test_utils.tel.tel_voice_utils import call_setup_teardown
106from acts_contrib.test_utils.tel.tel_voice_utils import hangup_call
107from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_3g
108from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_csfb
109from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
110from acts_contrib.test_utils.tel.tel_wifi_utils import WIFI_CONFIG_APBAND_2G
111from acts_contrib.test_utils.tel.tel_wifi_utils import WIFI_CONFIG_APBAND_5G
112from acts_contrib.test_utils.tel.tel_wifi_utils import ensure_wifi_connected
113from acts_contrib.test_utils.tel.tel_wifi_utils import stop_wifi_tethering
114from acts_contrib.test_utils.tel.tel_wifi_utils import wifi_reset
115from acts_contrib.test_utils.tel.tel_wifi_utils import wifi_toggle_state
116
117
118class TelLiveDataTest(TelephonyBaseTest):
119    def setup_class(self):
120        super().setup_class()
121
122        self.stress_test_number = self.get_stress_test_number()
123        self.provider = self.android_devices[0]
124        self.clients = self.android_devices[1:]
125
126    def setup_test(self):
127        TelephonyBaseTest.setup_test(self)
128        self.number_of_devices = 2
129
130    def teardown_class(self):
131        TelephonyBaseTest.teardown_class(self)
132
133
134    """ Tests Begin """
135
136
137    @test_tracker_info(uuid="ba24f9a3-0126-436c-8a5c-9f88859c273c")
138    @TelephonyBaseTest.tel_test_wrap
139    def test_data_browsing_for_single_phone(self):
140        """ Browsing websites on cellular.
141
142        Ensure phone attach, data on, WiFi off
143        Verify 5 websites on cellular.
144
145        Returns:
146            True if pass; False if fail.
147        """
148        ad = self.android_devices[0]
149        wifi_toggle_state(ad.log, ad, False)
150        self.number_of_devices = 1
151
152        for iteration in range(3):
153            ad.log.info("Attempt %d", iteration + 1)
154            if test_data_browsing_success_using_sl4a(ad.log, ad):
155                ad.log.info("Data Browsing test PASS in iteration %d",
156                            iteration + 1)
157                return True
158            time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
159        ad.log.info("Data Browsing test FAIL for all 3 iterations")
160        return False
161
162
163    @test_tracker_info(uuid="0679214b-9002-476d-83a7-3532b3cca209")
164    @TelephonyBaseTest.tel_test_wrap
165    def test_wifi_browsing_for_single_phone(self):
166        """ Browsing websites on wifi.
167
168        Ensure phone attach, data on, WiFi On, WiFi Connected.
169        Verify 5 websites on WiFi.
170
171        Returns:
172            True if pass; False if fail.
173        """
174        ad = self.android_devices[0]
175        wifi_toggle_state(ad.log, ad, True)
176        self.number_of_devices = 1
177
178        if not ensure_wifi_connected(ad.log, ad, self.wifi_network_ssid,
179                                     self.wifi_network_pass):
180            ad.log.error("WiFi connect fail.")
181            return False
182        for iteration in range(3):
183            ad.log.info("Attempt %d", iteration + 1)
184            if test_data_browsing_success_using_sl4a(ad.log, ad):
185                ad.log.info("Data Browsing test PASS in iteration %d",
186                            iteration + 1)
187                wifi_toggle_state(ad.log, ad, False)
188                return True
189            time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
190        ad.log.info("Data Browsing test FAIL for all 3 iterations")
191        wifi_toggle_state(ad.log, ad, False)
192        return False
193
194
195    @test_tracker_info(uuid="1b0354f3-8668-4a28-90a5-3b3d2b2756d3")
196    @TelephonyBaseTest.tel_test_wrap
197    def test_airplane_mode(self):
198        """ Test airplane mode basic on Phone and Live SIM.
199
200        Ensure phone attach, data on, WiFi off and verify Internet.
201        Turn on airplane mode to make sure detach.
202        Turn off airplane mode to make sure attach.
203        Verify Internet connection.
204
205        Returns:
206            True if pass; False if fail.
207        """
208        self.number_of_devices = 1
209
210        return airplane_mode_test(self.log, self.android_devices[0])
211
212    @test_tracker_info(uuid="47430f01-583f-4efb-923a-285a51b75d50")
213    @TelephonyBaseTest.tel_test_wrap
214    def test_lte_wifi_switching(self):
215        """Test data connection network switching when phone camped on LTE.
216
217        Ensure phone is camped on LTE
218        Ensure WiFi can connect to live network,
219        Airplane mode is off, data connection is on, WiFi is on.
220        Turn off WiFi, verify data is on cell and browse to google.com is OK.
221        Turn on WiFi, verify data is on WiFi and browse to google.com is OK.
222        Turn off WiFi, verify data is on cell and browse to google.com is OK.
223
224        Returns:
225            True if pass.
226        """
227        self.number_of_devices = 1
228
229        return wifi_cell_switching(self.log, self.android_devices[0], GEN_4G,
230                                   self.wifi_network_ssid,
231                                   self.wifi_network_pass)
232
233    @test_tracker_info(uuid="98d9f8c9-0532-49b6-85a3-5246b8314755")
234    @TelephonyBaseTest.tel_test_wrap
235    def test_lte_wifi_switching_stress(self):
236        """LTE WiFi Switching Data Connection Check
237
238        Same steps as test_lte_wifi_switching with stress testing
239
240        Returns:
241            True if pass.
242        """
243        MINIMUM_SUCCESS_RATE = .95
244        success_count = 0
245        fail_count = 0
246        self.stress_test_number = 10
247        self.number_of_devices = 1
248
249        for i in range(1, self.stress_test_number + 1):
250            ensure_phones_default_state(
251                self.log, [self.android_devices[0]])
252
253            if wifi_cell_switching(self.log, self.android_devices[0], GEN_4G,
254                                   self.wifi_network_ssid,
255                                   self.wifi_network_pass):
256                success_count += 1
257                result_str = "Succeeded"
258            else:
259                fail_count += 1
260                result_str = "Failed"
261            self.log.info("Iteration {} {}. Current: {} / {} passed.".format(
262                i, result_str, success_count, self.stress_test_number))
263
264        self.log.info("Final Count - Success: {}, Failure: {} - {}%".format(
265            success_count, fail_count,
266            str(100 * success_count / (success_count + fail_count))))
267        if success_count / (
268                success_count + fail_count) >= MINIMUM_SUCCESS_RATE:
269            return True
270        else:
271            return False
272
273    @test_tracker_info(uuid="8a836cf1-600b-4cf3-abfe-2e3da5c11396")
274    @TelephonyBaseTest.tel_test_wrap
275    def test_wcdma_wifi_switching(self):
276        """Test data connection network switching when phone camped on WCDMA.
277
278        Ensure phone is camped on WCDMA
279        Ensure WiFi can connect to live network,
280        Airplane mode is off, data connection is on, WiFi is on.
281        Turn off WiFi, verify data is on cell and browse to google.com is OK.
282        Turn on WiFi, verify data is on WiFi and browse to google.com is OK.
283        Turn off WiFi, verify data is on cell and browse to google.com is OK.
284
285        Returns:
286            True if pass.
287        """
288        self.number_of_devices = 1
289
290        return wifi_cell_switching(self.log, self.android_devices[0], GEN_3G,
291                                   self.wifi_network_ssid,
292                                   self.wifi_network_pass)
293
294    @test_tracker_info(uuid="c016f2e8-0af6-42e4-a3cb-a2b7d8b564d0")
295    @TelephonyBaseTest.tel_test_wrap
296    def test_gsm_wifi_switching(self):
297        """Test data connection network switching when phone camped on GSM.
298
299        Ensure phone is camped on GSM
300        Ensure WiFi can connect to live network,,
301        Airplane mode is off, data connection is on, WiFi is on.
302        Turn off WiFi, verify data is on cell and browse to google.com is OK.
303        Turn on WiFi, verify data is on WiFi and browse to google.com is OK.
304        Turn off WiFi, verify data is on cell and browse to google.com is OK.
305
306        Returns:
307            True if pass.
308        """
309        self.number_of_devices = 1
310
311        return wifi_cell_switching(self.log, self.android_devices[0], GEN_2G,
312                                   self.wifi_network_ssid,
313                                   self.wifi_network_pass)
314
315    @test_tracker_info(uuid="78d6b258-82d4-47b4-8723-3b3a15412d2d")
316    @TelephonyBaseTest.tel_test_wrap
317    def test_lte_multi_bearer(self):
318        """Test LTE data connection before call and in call. (VoLTE call)
319
320
321        Turn off airplane mode, disable WiFi, enable Cellular Data.
322        Make sure phone in LTE, verify Internet.
323        Initiate a voice call. verify Internet.
324        Disable Cellular Data, verify Internet is inaccessible.
325        Enable Cellular Data, verify Internet.
326        Hangup Voice Call, verify Internet.
327
328        Returns:
329            True if success.
330            False if failed.
331        """
332        self.number_of_devices = 1
333
334        return test_data_connectivity_multi_bearer(
335            self.log, self.android_devices, 'volte')
336
337    @test_tracker_info(uuid="5c9cb076-0c26-4517-95dc-2ec4974e8ce3")
338    @TelephonyBaseTest.tel_test_wrap
339    def test_wcdma_multi_bearer(self):
340        """Test WCDMA data connection before call and in call.
341
342        Turn off airplane mode, disable WiFi, enable Cellular Data.
343        Make sure phone in WCDMA, verify Internet.
344        Initiate a voice call. verify Internet.
345        Disable Cellular Data, verify Internet is inaccessible.
346        Enable Cellular Data, verify Internet.
347        Hangup Voice Call, verify Internet.
348
349        Returns:
350            True if success.
351            False if failed.
352        """
353
354        return test_data_connectivity_multi_bearer(
355            self.log, self.android_devices, '3g')
356
357    @test_tracker_info(uuid="314bbf1c-073f-4d48-9817-a6e14f96f3c0")
358    @TelephonyBaseTest.tel_test_wrap
359    def test_gsm_multi_bearer_mo(self):
360        """Test gsm data connection before call and in call.
361
362        Turn off airplane mode, disable WiFi, enable Cellular Data.
363        Make sure phone in GSM, verify Internet.
364        Initiate a MO voice call. Verify there is no Internet during call.
365        Hangup Voice Call, verify Internet.
366
367        Returns:
368            True if success.
369            False if failed.
370        """
371
372        return test_data_connectivity_multi_bearer(self.log,
373            self.android_devices, '2g', False, DIRECTION_MOBILE_ORIGINATED)
374
375    @test_tracker_info(uuid="549271ff-1034-4d02-8d92-b9d1b2bb912e")
376    @TelephonyBaseTest.tel_test_wrap
377    def test_gsm_multi_bearer_mt(self):
378        """Test gsm data connection before call and in call.
379
380        Turn off airplane mode, disable WiFi, enable Cellular Data.
381        Make sure phone in GSM, verify Internet.
382        Initiate a MT voice call. Verify there is no Internet during call.
383        Hangup Voice Call, verify Internet.
384
385        Returns:
386            True if success.
387            False if failed.
388        """
389
390        return test_data_connectivity_multi_bearer(self.log,
391            self.android_devices, '2g', False, DIRECTION_MOBILE_TERMINATED)
392
393    @test_tracker_info(uuid="111de471-559a-4bc3-9d3e-de18f098c162")
394    @TelephonyBaseTest.tel_test_wrap
395    def test_wcdma_multi_bearer_stress(self):
396        """Stress Test WCDMA data connection before call and in call.
397
398        This is a stress test for "test_wcdma_multi_bearer".
399        Default MINIMUM_SUCCESS_RATE is set to 95%.
400
401        Returns:
402            True stress pass rate is higher than MINIMUM_SUCCESS_RATE.
403            False otherwise.
404        """
405        MINIMUM_SUCCESS_RATE = .95
406        success_count = 0
407        fail_count = 0
408
409        for i in range(1, self.stress_test_number + 1):
410
411            ensure_phones_default_state(
412                self.log, [self.android_devices[0], self.android_devices[1]])
413
414            if self.test_wcdma_multi_bearer():
415                success_count += 1
416                result_str = "Succeeded"
417            else:
418                fail_count += 1
419                result_str = "Failed"
420            self.log.info("Iteration {} {}. Current: {} / {} passed.".format(
421                i, result_str, success_count, self.stress_test_number))
422
423        self.log.info("Final Count - Success: {}, Failure: {} - {}%".format(
424            success_count, fail_count,
425            str(100 * success_count / (success_count + fail_count))))
426        if success_count / (
427                success_count + fail_count) >= MINIMUM_SUCCESS_RATE:
428            return True
429        else:
430            return False
431
432    @test_tracker_info(uuid="c7f14ba7-7ac3-45d2-b391-5ed5c4b0e70b")
433    @TelephonyBaseTest.tel_test_wrap
434    def test_lte_multi_bearer_stress(self):
435        """Stress Test LTE data connection before call and in call. (VoLTE call)
436
437        This is a stress test for "test_lte_multi_bearer".
438        Default MINIMUM_SUCCESS_RATE is set to 95%.
439
440        Returns:
441            True stress pass rate is higher than MINIMUM_SUCCESS_RATE.
442            False otherwise.
443        """
444        ads = self.android_devices
445        MINIMUM_SUCCESS_RATE = .95
446        success_count = 0
447        fail_count = 0
448
449        for i in range(1, self.stress_test_number + 1):
450
451            ensure_phones_default_state(
452                self.log, [self.android_devices[0], self.android_devices[1]])
453
454            if self.test_lte_multi_bearer():
455                success_count += 1
456                result_str = "Succeeded"
457            else:
458                fail_count += 1
459                result_str = "Failed"
460            self.log.info("Iteration {} {}. Current: {} / {} passed.".format(
461                i, result_str, success_count, self.stress_test_number))
462
463        self.log.info("Final Count - Success: {}, Failure: {} - {}%".format(
464            success_count, fail_count,
465            str(100 * success_count / (success_count + fail_count))))
466        if success_count / (
467                success_count + fail_count) >= MINIMUM_SUCCESS_RATE:
468            return True
469        else:
470            return False
471
472
473    @test_tracker_info(uuid="dcb9bdc6-dbe2-47e1-9c2d-6f37c529d366")
474    @TelephonyBaseTest.tel_test_wrap
475    def test_2g_data_connectivity(self):
476        """Test data connection in 2G.
477
478        Turn off airplane mode, disable WiFi, enable Cellular Data.
479        Ensure phone data generation is 2G.
480        Verify Internet.
481        Disable Cellular Data, verify Internet is inaccessible.
482        Enable Cellular Data, verify Internet.
483
484        Returns:
485            True if success.
486            False if failed.
487        """
488        self.number_of_devices = 1
489
490        wifi_reset(self.log, self.android_devices[0])
491        wifi_toggle_state(self.log, self.android_devices[0], False)
492        return data_connectivity_single_bearer(self.log,
493                                               self.android_devices[0], RAT_2G)
494
495    @test_tracker_info(uuid="84197a49-d73f-44ce-8b9e-9479e5c4dfdc")
496    @TelephonyBaseTest.tel_test_wrap
497    def test_2g_wifi_not_associated(self):
498        """Test data connection in 2G.
499
500        Turn off airplane mode, enable WiFi (but not connected), enable Cellular Data.
501        Ensure phone data generation is 2G.
502        Verify Internet.
503        Disable Cellular Data, verify Internet is inaccessible.
504        Enable Cellular Data, verify Internet.
505
506        Returns:
507            True if success.
508            False if failed.
509        """
510        self.number_of_devices = 1
511
512        wifi_reset(self.log, self.android_devices[0])
513        wifi_toggle_state(self.log, self.android_devices[0], False)
514        wifi_toggle_state(self.log, self.android_devices[0], True)
515        return data_connectivity_single_bearer(self.log,
516                                               self.android_devices[0], RAT_2G)
517
518    @test_tracker_info(uuid="97067ebb-130a-4fcb-8e6b-f4ec5874828f")
519    @TelephonyBaseTest.tel_test_wrap
520    def test_3g_data_connectivity(self):
521        """Test data connection in 3G.
522
523        Turn off airplane mode, disable WiFi, enable Cellular Data.
524        Ensure phone data generation is 3G.
525        Verify Internet.
526        Disable Cellular Data, verify Internet is inaccessible.
527        Enable Cellular Data, verify Internet.
528
529        Returns:
530            True if success.
531            False if failed.
532        """
533        self.number_of_devices = 1
534
535        wifi_reset(self.log, self.android_devices[0])
536        wifi_toggle_state(self.log, self.android_devices[0], False)
537        return data_connectivity_single_bearer(self.log,
538                                               self.android_devices[0], RAT_3G)
539
540    @test_tracker_info(uuid="ffe2a392-95b8-4a4d-8a6f-bfa846c3462f")
541    @TelephonyBaseTest.tel_test_wrap
542    def test_3g_wifi_not_associated(self):
543        """Test data connection in 3G.
544
545        Turn off airplane mode, enable WiFi (but not connected), enable Cellular Data.
546        Ensure phone data generation is 3G.
547        Verify Internet.
548        Disable Cellular Data, verify Internet is inaccessible.
549        Enable Cellular Data, verify Internet.
550
551        Returns:
552            True if success.
553            False if failed.
554        """
555        self.number_of_devices = 1
556
557        wifi_reset(self.log, self.android_devices[0])
558        wifi_toggle_state(self.log, self.android_devices[0], False)
559        wifi_toggle_state(self.log, self.android_devices[0], True)
560        return data_connectivity_single_bearer(self.log,
561                                               self.android_devices[0], RAT_3G)
562
563    @test_tracker_info(uuid="9c2f459f-1aac-4c68-818b-8698e8124c8b")
564    @TelephonyBaseTest.tel_test_wrap
565    def test_4g_data_connectivity(self):
566        """Test data connection in 4g.
567
568        Turn off airplane mode, disable WiFi, enable Cellular Data.
569        Ensure phone data generation is 4g.
570        Verify Internet.
571        Disable Cellular Data, verify Internet is inaccessible.
572        Enable Cellular Data, verify Internet.
573
574        Returns:
575            True if success.
576            False if failed.
577        """
578        self.number_of_devices = 1
579
580        wifi_reset(self.log, self.android_devices[0])
581        wifi_toggle_state(self.log, self.android_devices[0], False)
582        return data_connectivity_single_bearer(self.log,
583                                               self.android_devices[0], RAT_4G)
584
585    @test_tracker_info(uuid="015a39a1-15ac-4b76-962b-d7d82d52d425")
586    @TelephonyBaseTest.tel_test_wrap
587    def test_4g_wifi_not_associated(self):
588        """Test data connection in 4g.
589
590        Turn off airplane mode, enable WiFi (but not connected), enable Cellular Data.
591        Ensure phone data generation is 4g.
592        Verify Internet.
593        Disable Cellular Data, verify Internet is inaccessible.
594        Enable Cellular Data, verify Internet.
595
596        Returns:
597            True if success.
598            False if failed.
599        """
600        self.number_of_devices = 1
601
602        wifi_reset(self.log, self.android_devices[0])
603        wifi_toggle_state(self.log, self.android_devices[0], False)
604        wifi_toggle_state(self.log, self.android_devices[0], True)
605        return data_connectivity_single_bearer(self.log,
606                                               self.android_devices[0], RAT_4G)
607
608    @test_tracker_info(uuid="44f47b64-f8bc-4a17-9195-42dcca0806bb")
609    @TelephonyBaseTest.tel_test_wrap
610    def test_3g_data_connectivity_stress(self):
611        """Stress Test data connection in 3G.
612
613        This is a stress test for "test_3g".
614        Default MINIMUM_SUCCESS_RATE is set to 95%.
615
616        Returns:
617            True stress pass rate is higher than MINIMUM_SUCCESS_RATE.
618            False otherwise.
619        """
620        MINIMUM_SUCCESS_RATE = .95
621        success_count = 0
622        fail_count = 0
623        self.number_of_devices = 1
624
625        for i in range(1, self.stress_test_number + 1):
626
627            ensure_phones_default_state(self.log, [self.android_devices[0]])
628            wifi_reset(self.log, self.android_devices[0])
629            wifi_toggle_state(self.log, self.android_devices[0], False)
630
631            if data_connectivity_single_bearer(
632                    self.log, self.android_devices[0], RAT_3G):
633                success_count += 1
634                result_str = "Succeeded"
635            else:
636                fail_count += 1
637                result_str = "Failed"
638            self.log.info("Iteration {} {}. Current: {} / {} passed.".format(
639                i, result_str, success_count, self.stress_test_number))
640
641        self.log.info("Final Count - Success: {}, Failure: {} - {}%".format(
642            success_count, fail_count,
643            str(100 * success_count / (success_count + fail_count))))
644        if success_count / (
645                success_count + fail_count) >= MINIMUM_SUCCESS_RATE:
646            return True
647        else:
648            return False
649
650    @test_tracker_info(uuid="c8876388-0441-4a51-81e6-ac2cb358a531")
651    @TelephonyBaseTest.tel_test_wrap
652    def test_4g_data_connectivity_stress(self):
653        """Stress Test data connection in 4g.
654
655        This is a stress test for "test_4g".
656        Default MINIMUM_SUCCESS_RATE is set to 95%.
657
658        Returns:
659            True stress pass rate is higher than MINIMUM_SUCCESS_RATE.
660            False otherwise.
661        """
662        MINIMUM_SUCCESS_RATE = .95
663        success_count = 0
664        fail_count = 0
665        self.number_of_devices = 1
666
667        for i in range(1, self.stress_test_number + 1):
668
669            ensure_phones_default_state(self.log, [self.android_devices[0]])
670            wifi_reset(self.log, self.android_devices[0])
671            wifi_toggle_state(self.log, self.android_devices[0], False)
672
673            if data_connectivity_single_bearer(
674                    self.log, self.android_devices[0], RAT_4G):
675                success_count += 1
676                result_str = "Succeeded"
677            else:
678                fail_count += 1
679                result_str = "Failed"
680            self.log.info("Iteration {} {}. Current: {} / {} passed.".format(
681                i, result_str, success_count, self.stress_test_number))
682
683        self.log.info("Final Count - Success: {}, Failure: {} - {}%".format(
684            success_count, fail_count,
685            str(100 * success_count / (success_count + fail_count))))
686        if success_count / (
687                success_count + fail_count) >= MINIMUM_SUCCESS_RATE:
688            return True
689        else:
690            return False
691
692
693    @test_tracker_info(uuid="2d945656-22f7-4610-9a84-40ce04d603a4")
694    @TelephonyBaseTest.tel_test_wrap
695    def test_tethering_4g_to_bluetooth(self):
696        """Bluetooth Tethering test: LTE to Bluetooth Tethering
697
698        1. DUT in LTE mode, idle.
699        2. DUT start Bluetooth Tethering
700        3. PhoneB disable data, connect to DUT's softAP
701        4. Verify Internet access on DUT and PhoneB
702        5. Toggle provider bluetooth connection
703        6. Verify Internet access on DUT and PhoneB
704
705        Returns:
706            True if success.
707            False if failed.
708        """
709        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_4G):
710            self.log.error("Verify 4G Internet access failed.")
711            return False
712
713        return verify_bluetooth_tethering_connection(self.log, self.provider, self.clients)
714
715    @test_tracker_info(uuid="8d2ae56b-c2c1-4c32-9b8e-5044007b5b90")
716    @TelephonyBaseTest.tel_test_wrap
717    def test_tethering_4g_to_bluetooth_with_voice_call(self):
718        """Bluetooth Tethering test: LTE to Bluetooth Tethering
719
720        1. DUT in LTE mode, idle.
721        2. DUT start Bluetooth Tethering
722        3. PhoneB disable data, connect to DUT's softAP
723        4. Verify Internet access on DUT and PhoneB
724        5. Verify provider and client are able to make or receive phone call
725        6. Verify Internet access on DUT and PhoneB
726
727        Returns:
728            True if success.
729            False if failed.
730        """
731        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_4G):
732            self.log.error("Verify 4G Internet access failed.")
733            return False
734
735        return verify_bluetooth_tethering_connection(self.log, self.provider, self.clients,
736            toggle_tethering=False, toggle_bluetooth=False, voice_call=True)
737
738    @test_tracker_info(uuid="b4617727-fa83-4451-89d7-7e574c0a0938")
739    @TelephonyBaseTest.tel_test_wrap
740    def test_tethering_4g_to_bluetooth_toggle_data(self):
741        """Bluetooth Tethering test: LTE to Bluetooth Tethering
742
743        1. DUT in LTE mode, idle.
744        2. DUT start Bluetooth Tethering
745        3. PhoneB disable data, connect to DUT's softAP
746        4. Verify Internet access on DUT and PhoneB
747        5. Toggle provider data connection
748        6. Verify Internet access on DUT and PhoneB
749
750        Returns:
751            True if success.
752            False if failed.
753        """
754        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_4G):
755            self.log.error("Verify 4G Internet access failed.")
756            return False
757
758        return verify_bluetooth_tethering_connection(self.log, self.provider, self.clients,
759            toggle_tethering=False, toggle_bluetooth=False, toggle_data=True)
760
761    @test_tracker_info(uuid="6a0f6001-609d-41f2-ad09-c8ae19f73ac8")
762    @TelephonyBaseTest.tel_test_wrap
763    def test_tethering_4g_to_bluetooth_toggle_tethering(self):
764        """Bluetooth Tethering test: LTE to Bluetooth Tethering
765
766        1. DUT in LTE mode, idle.
767        2. DUT start Bluetooth Tethering
768        3. PhoneB disable data, connect to DUT's softAP
769        4. Verify Internet access on DUT and PhoneB
770        5. Toggle provider bluetooth tethering
771        6. Verify Internet access on DUT and PhoneB
772
773        Returns:
774            True if success.
775            False if failed.
776        """
777        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_4G):
778            self.log.error("Verify 4G Internet access failed.")
779            return False
780
781        return verify_bluetooth_tethering_connection(self.log, self.provider, self.clients,
782            toggle_tethering=True, toggle_bluetooth=False, toggle_data=False)
783
784    @test_tracker_info(uuid="b1abc1ac-8018-4956-a17e-bf2ceaf264ea")
785    @TelephonyBaseTest.tel_test_wrap
786    def test_tethering_3g_to_bluetooth(self):
787        """Bluetooth Tethering test: 3G to Bluetoothing Tethering
788
789        1. DUT in 3G mode, idle.
790        2. DUT start bluetooth Tethering
791        3. PhoneB disable data, connect to DUT's softAP
792        4. Verify Internet access on DUT and PhoneB
793        5. Toggle provider bluetooth connection
794        6. Verify Internet access on DUT and PhoneB
795
796        Returns:
797            True if success.
798            False if failed.
799        """
800        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_3G):
801            self.log.error("Verify 3G Internet access failed.")
802            return False
803
804        return verify_bluetooth_tethering_connection(self.log, self.provider, self.clients)
805
806    @test_tracker_info(uuid="69793745-0c49-4cef-9879-d372e3a3f4c7")
807    @TelephonyBaseTest.tel_test_wrap
808    def test_tethering_3g_to_bluetooth_with_voice_call(self):
809        """Bluetooth Tethering test: 3G to Bluetooth Tethering
810
811        1. DUT in 3G mode, idle.
812        2. DUT start Bluetooth Tethering
813        3. PhoneB disable data, connect to DUT's softAP
814        4. Verify Internet access on DUT and PhoneB
815        5. Verify provider and client are able to make or receive phone call
816        6. Verify Internet access on DUT and PhoneB
817
818        Returns:
819            True if success.
820            False if failed.
821        """
822        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_3G):
823            self.log.error("Verify 3G Internet access failed.")
824            return False
825
826        return verify_bluetooth_tethering_connection(self.log, self.provider, self.clients,
827            toggle_tethering=False, toggle_bluetooth=False, voice_call=True)
828
829    @test_tracker_info(uuid="4275ee69-dfdf-4f47-82c5-4224fceee761")
830    @TelephonyBaseTest.tel_test_wrap
831    def test_tethering_3g_to_bluetooth_toggle_data(self):
832        """Bluetooth Tethering test: 3G to Bluetoothing Tethering
833
834        1. DUT in 3G mode, idle.
835        2. DUT start bluetooth Tethering
836        3. PhoneB disable data, connect to DUT's softAP
837        4. Verify Internet access on DUT and PhoneB
838        5. Toggle provider data connection
839        6. Verify Internet access on DUT and PhoneB
840
841        Returns:
842            True if success.
843            False if failed.
844        """
845        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_3G):
846            self.log.error("Verify 3G Internet access failed.")
847            return False
848
849        return verify_bluetooth_tethering_connection(self.log, self.provider, self.clients,
850            toggle_tethering=False, toggle_bluetooth=False, toggle_data=True)
851
852    @test_tracker_info(uuid="db0e0f27-1a4f-4301-832d-b66415e289f3")
853    @TelephonyBaseTest.tel_test_wrap
854    def test_tethering_2g_to_bluetooth(self):
855        """Bluetooth Tethering test: 2G to Bluetooth Tethering
856
857        1. DUT in 2G mode, idle.
858        2. DUT start bluetooth Tethering
859        3. PhoneB disable data, connect to DUT's softAP
860        4. Verify Internet access on DUT and PhoneB
861        5. Toggle provider bluetooth connection
862        6. Verify Internet access on DUT and PhoneB
863
864        Returns:
865            True if success.
866            False if failed.
867        """
868        for a in self.android_devices:
869            a.adb.shell("setprop persist.bluetooth.btsnoopenable true")
870            if not toggle_airplane_mode_by_adb(self.log, a, True):
871                self.log.error("Failed to toggle airplane mode on")
872                return False
873            if not toggle_airplane_mode_by_adb(self.log, a, False):
874                self.log.error("Failed to toggle airplane mode off")
875                return False
876
877        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_2G):
878            self.log.error("Verify 3G Internet access failed.")
879            return False
880
881        return verify_bluetooth_tethering_connection(self.log, self.provider, self.clients)
882
883    @test_tracker_info(uuid="584e9fa5-a38e-47cd-aa33-fcf8d72c423e")
884    @TelephonyBaseTest.tel_test_wrap
885    def test_tethering_2g_to_bluetooth_with_voice_call(self):
886        """Bluetooth Tethering test: 2G to Bluetooth Tethering
887
888        1. DUT in 2G mode, idle.
889        2. DUT start Bluetooth Tethering
890        3. PhoneB disable data, connect to DUT's softAP
891        4. Verify Internet access on DUT and PhoneB
892        5. Verify provider and client are able to make or receive phone call
893        6. Verify Internet access on DUT and PhoneB
894
895        Returns:
896            True if success.
897            False if failed.
898        """
899        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_2G):
900            self.log.error("Verify 2G Internet access failed.")
901            return False
902
903        return verify_bluetooth_tethering_connection(self.log, self.provider, self.clients,
904            toggle_tethering=False, toggle_bluetooth=False, voice_call=True)
905
906    @test_tracker_info(uuid="be3e74f9-3dc8-4b72-8a33-32bff0868a44")
907    @TelephonyBaseTest.tel_test_wrap
908    def test_tethering_2g_to_bluetooth_toggle_data(self):
909        """Bluetooth Tethering test: 2G to Bluetooth Tethering
910
911        1. DUT in 2G mode, idle.
912        2. DUT start Bluetooth Tethering
913        3. PhoneB disable data, connect to DUT's softAP
914        4. Verify Internet access on DUT and PhoneB
915        5. Toggle provider data connection
916        6. Verify Internet access on DUT and PhoneB
917
918        Returns:
919            True if success.
920            False if failed.
921        """
922        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_2G):
923            self.log.error("Verify 4G Internet access failed.")
924            return False
925
926        return verify_bluetooth_tethering_connection(self.log, self.provider, self.clients,
927            toggle_tethering=False, toggle_bluetooth=False, toggle_data=True)
928
929    @test_tracker_info(uuid="4a106549-0bfa-4c8f-8e66-edec93fabadf")
930    @TelephonyBaseTest.tel_test_wrap
931    def test_tethering_rat_from_4g_to_3g_bluetooth(self):
932        """Bluetooth Tethering test: 2G to Bluetooth Tethering
933
934        1. DUT in 4G mode, idle.
935        2. DUT start bluetooth Tethering
936        3. PhoneB disable data, connect to DUT's softAP
937        4. Verify Internet access on DUT and PhoneB
938        5. Change provider RAT to 3G
939        6. Verify Internet access on DUT and PhoneB
940
941        Returns:
942            True if success.
943            False if failed.
944        """
945        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_4G):
946            self.log.error("Verify 3G Internet access failed.")
947            return False
948
949        return verify_bluetooth_tethering_connection(self.log, self.provider, self.clients,
950            toggle_tethering=False,
951            toggle_bluetooth=False,
952            toggle_data=False,
953            change_rat=RAT_3G)
954
955    @test_tracker_info(uuid="eaa5b61b-f054-437f-ae82-8d80f6487785")
956    @TelephonyBaseTest.tel_test_wrap
957    def test_tethering_rat_from_4g_to_2g_bluetooth(self):
958        """Bluetooth Tethering test: 2G to Bluetooth Tethering
959
960        1. DUT in 4G mode, idle.
961        2. DUT start bluetooth Tethering
962        3. PhoneB disable data, connect to DUT's softAP
963        4. Verify Internet access on DUT and PhoneB
964        5. Change provider RAT to 2G
965        6. Verify Internet access on DUT and PhoneB
966
967        Returns:
968            True if success.
969            False if failed.
970        """
971        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_4G):
972            self.log.error("Verify 3G Internet access failed.")
973            return False
974
975        return verify_bluetooth_tethering_connection(self.log, self.provider, self.clients,
976            toggle_tethering=False,
977            toggle_bluetooth=False,
978            toggle_data=False,
979            change_rat=RAT_2G)
980
981    @test_tracker_info(uuid="912a11a3-14b3-4928-885f-cea69f14a571")
982    @TelephonyBaseTest.tel_test_wrap
983    def test_tethering_4g_to_2gwifi(self):
984        """WiFi Tethering test: LTE to WiFI 2.4G Tethering
985
986        1. DUT in LTE mode, idle.
987        2. DUT start 2.4G WiFi Tethering
988        3. PhoneB disable data, connect to DUT's softAP
989        4. Verify Internet access on DUT and PhoneB
990
991        Returns:
992            True if success.
993            False if failed.
994        """
995        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_4G):
996            self.log.error("Verify 4G Internet access failed.")
997            return False
998
999        return wifi_tethering_setup_teardown(
1000            self.log,
1001            self.provider,
1002            self.clients,
1003            ap_band=WIFI_CONFIG_APBAND_2G,
1004            check_interval=10,
1005            check_iteration=10)
1006
1007    @test_tracker_info(uuid="743e3998-d39f-42b9-b11f-009dcee34f3f")
1008    @TelephonyBaseTest.tel_test_wrap
1009    def test_tethering_4g_to_5gwifi(self):
1010        """WiFi Tethering test: LTE to WiFI 5G Tethering
1011
1012        1. DUT in LTE mode, idle.
1013        2. DUT start 5G WiFi Tethering
1014        3. PhoneB disable data, connect to DUT's softAP
1015        4. Verify Internet access on DUT and PhoneB
1016
1017        Returns:
1018            True if success.
1019            False if failed.
1020        """
1021        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_4G):
1022            self.log.error("Verify 4G Internet access failed.")
1023            return False
1024
1025        return wifi_tethering_setup_teardown(
1026            self.log,
1027            self.provider,
1028            self.clients,
1029            ap_band=WIFI_CONFIG_APBAND_5G,
1030            check_interval=10,
1031            check_iteration=10)
1032
1033
1034    @test_tracker_info(uuid="c1a16464-3800-40d3-ba63-35db784e0383")
1035    @TelephonyBaseTest.tel_test_wrap
1036    def test_tethering_default_to_5gwifi(self):
1037        """WiFi Tethering test: Default to WiFI 5G Tethering
1038
1039        1. DUT in default mode, idle.
1040        2. DUT start 5G WiFi Tethering
1041        3. PhoneB disable data, connect to DUT's softAP
1042        4. Verify Internet access on DUT and PhoneB
1043        5. True: Stop
1044           False: Change DUT to next device and repeat until find the device
1045                  with tethering capability
1046
1047        Returns:
1048            True if success.
1049            False if no device has tethering capability.
1050        """
1051        num = len(self.android_devices)
1052        for idx, ad in enumerate(self.android_devices):
1053            self.provider = self.android_devices[idx]
1054            self.clients = self.android_devices[:
1055                                                idx] + self.android_devices[idx
1056                                                                            +
1057                                                                            1:]
1058            ensure_phones_default_state(self.log, self.android_devices)
1059            wifi_toggle_state(self.log, self.provider, False)
1060
1061            if not test_setup_tethering(self.log, self.provider, self.clients, None):
1062                self.provider.log.error("Data connection check failed.")
1063                continue
1064
1065            if not self.provider.droid.carrierConfigIsTetheringModeAllowed(
1066                    TETHERING_MODE_WIFI,
1067                    MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK):
1068                self.provider.log.info("Tethering is not entitled")
1069                continue
1070
1071            if wifi_tethering_setup_teardown(
1072                    self.log,
1073                    self.provider, [self.clients[0]],
1074                    ap_band=WIFI_CONFIG_APBAND_5G,
1075                    check_interval=10,
1076                    check_iteration=10):
1077                self.android_devices = [self.provider] + self.clients
1078                return True
1079            elif idx == num - 1:
1080                self.log.error("Tethering is not working on all devices")
1081                return False
1082        self.log.error(
1083            "Failed to enable tethering on any device in this testbed")
1084        raise signals.TestAbortClass(
1085            "Tethering is not available on all devices in this testbed")
1086
1087    @test_tracker_info(uuid="c9a570b0-838c-44ba-991c-f1ddeee21f3c")
1088    @TelephonyBaseTest.tel_test_wrap
1089    def test_tethering_default_to_2gwifi(self):
1090        """WiFi Tethering test: Default to WiFI 2G Tethering
1091
1092        1. DUT in default mode, idle.
1093        2. DUT start 2G WiFi Tethering
1094        3. PhoneB disable data, connect to DUT's softAP
1095        4. Verify Internet access on DUT and PhoneB
1096        5. True: Stop
1097           False: Change DUT to next device and repeat until find the device
1098                  with tethering capability
1099
1100        Returns:
1101            True if success.
1102            False if no device has tethering capability.
1103        """
1104        num = len(self.android_devices)
1105        for idx, ad in enumerate(self.android_devices):
1106            self.provider = self.android_devices[idx]
1107            self.clients = self.android_devices[:
1108                                                idx] + self.android_devices[idx
1109                                                                            +
1110                                                                            1:]
1111            ensure_phones_default_state(self.log, self.android_devices)
1112            wifi_toggle_state(self.log, self.provider, False)
1113
1114            if not test_setup_tethering(self.log, self.provider, self.clients, None):
1115                self.provider.log.error("Data connection check failed.")
1116                continue
1117
1118            if not self.provider.droid.carrierConfigIsTetheringModeAllowed(
1119                    TETHERING_MODE_WIFI,
1120                    MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK):
1121                self.provider.log.info("Tethering is not entitled")
1122                continue
1123
1124            if wifi_tethering_setup_teardown(
1125                    self.log,
1126                    self.provider, [self.clients[0]],
1127                    ap_band=WIFI_CONFIG_APBAND_2G,
1128                    check_interval=10,
1129                    check_iteration=10):
1130                self.android_devices = [self.provider] + self.clients
1131                return True
1132            elif idx == num - 1:
1133                self.log.error("Tethering is not working on all devices")
1134                return False
1135        self.log.error(
1136            "Failed to enable tethering on any device in this testbed")
1137        raise signals.TestAbortClass(
1138            "Tethering is not available on all devices in this testbed")
1139
1140    @test_tracker_info(uuid="59be8d68-f05b-4448-8584-de971174fd81")
1141    @TelephonyBaseTest.tel_test_wrap
1142    def test_tethering_3g_to_2gwifi(self):
1143        """WiFi Tethering test: 3G to WiFI 2.4G Tethering
1144
1145        1. DUT in 3G mode, idle.
1146        2. DUT start 2.4G WiFi Tethering
1147        3. PhoneB disable data, connect to DUT's softAP
1148        4. Verify Internet access on DUT and PhoneB
1149
1150        Returns:
1151            True if success.
1152            False if failed.
1153        """
1154        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_3G):
1155            self.log.error("Verify 3G Internet access failed.")
1156            return False
1157
1158        return wifi_tethering_setup_teardown(
1159            self.log,
1160            self.provider,
1161            self.clients,
1162            ap_band=WIFI_CONFIG_APBAND_2G,
1163            check_interval=10,
1164            check_iteration=10)
1165
1166    @test_tracker_info(uuid="1be6b741-92e8-4ee1-9f59-e7f9f369b065")
1167    @TelephonyBaseTest.tel_test_wrap
1168    def test_tethering_3g_to_5gwifi(self):
1169        """WiFi Tethering test: 3G to WiFI 5G Tethering
1170
1171        1. DUT in 3G mode, idle.
1172        2. DUT start 5G WiFi Tethering
1173        3. PhoneB disable data, connect to DUT's softAP
1174        4. Verify Internet access on DUT and PhoneB
1175
1176        Returns:
1177            True if success.
1178            False if failed.
1179        """
1180        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_3G):
1181            self.log.error("Verify 3G Internet access failed.")
1182            return False
1183
1184        return wifi_tethering_setup_teardown(
1185            self.log,
1186            self.provider,
1187            self.clients,
1188            ap_band=WIFI_CONFIG_APBAND_5G,
1189            check_interval=10,
1190            check_iteration=10)
1191
1192    @test_tracker_info(uuid="89fe6321-4c0d-40c0-89b2-54008ecca68f")
1193    @TelephonyBaseTest.tel_test_wrap
1194    def test_tethering_2g_to_2gwifi(self):
1195        """WiFi Tethering test: 2G to WiFI 2.4G Tethering
1196
1197        1. DUT in 2G mode, idle.
1198        2. DUT start 2.4G WiFi Tethering
1199        3. PhoneB disable data, connect to DUT's softAP
1200        4. Verify Internet access on DUT and PhoneB
1201
1202        Returns:
1203            True if success.
1204            False if failed.
1205        """
1206        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_2G):
1207            self.log.error("Verify 2G Internet access failed.")
1208            return False
1209
1210        return wifi_tethering_setup_teardown(
1211            self.log,
1212            self.provider, [self.clients[0]],
1213            ap_band=WIFI_CONFIG_APBAND_2G,
1214            check_interval=10,
1215            check_iteration=10)
1216
1217    @test_tracker_info(uuid="b8258d51-9581-4d52-80b6-501941ec1191")
1218    @TelephonyBaseTest.tel_test_wrap
1219    def test_tethering_2g_to_5gwifi(self):
1220        """WiFi Tethering test: 2G to WiFI 5G Tethering
1221
1222        1. DUT in 2G mode, idle.
1223        2. DUT start 5G WiFi Tethering
1224        3. PhoneB disable data, connect to DUT's softAP
1225        4. Verify Internet access on DUT and PhoneB
1226
1227        Returns:
1228            True if success.
1229            False if failed.
1230        """
1231        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_2G):
1232            self.log.error("Verify 2G Internet access failed.")
1233            return False
1234
1235        return wifi_tethering_setup_teardown(
1236            self.log,
1237            self.provider, [self.clients[0]],
1238            ap_band=WIFI_CONFIG_APBAND_5G,
1239            check_interval=10,
1240            check_iteration=10)
1241
1242    @test_tracker_info(uuid="8ed766a6-71c5-4b3b-8897-a4e796c75619")
1243    @TelephonyBaseTest.tel_test_wrap
1244    def test_disable_wifi_tethering_resume_connected_wifi(self):
1245        """WiFi Tethering test: WiFI connected to 2.4G network,
1246        start (LTE) 2.4G WiFi tethering, then stop tethering
1247
1248        1. DUT in data connected, idle. WiFi connected to 2.4G Network
1249        2. DUT start 2.4G WiFi Tethering
1250        3. PhoneB disable data, connect to DUT's softAP
1251        4. Verify Internet access on DUT and PhoneB
1252        5. Disable WiFi Tethering on DUT.
1253        6. Verify DUT automatically connect to previous WiFI network
1254
1255        Returns:
1256            True if success.
1257            False if failed.
1258        """
1259        # Ensure provider connecting to wifi network.
1260        def setup_provider_internet_connection():
1261            return setup_device_internet_connection(self.log,
1262                                                    self.provider,
1263                                                    self.wifi_network_ssid,
1264                                                    self.wifi_network_pass)
1265
1266        if not test_wifi_tethering(self.log,
1267                                   self.provider,
1268                                   self.clients,
1269                                   [self.clients[0]],
1270                                   None,
1271                                   WIFI_CONFIG_APBAND_2G,
1272                                   check_interval=10,
1273                                   check_iteration=2,
1274                                   pre_teardown_func=setup_provider_internet_connection):
1275            return False
1276
1277        if not wait_and_verify_device_internet_connection(self.log, self.provider):
1278            return False
1279        return True
1280
1281    @test_tracker_info(uuid="b879ceb2-1b80-4762-93f9-afef4d688c28")
1282    @TelephonyBaseTest.tel_test_wrap
1283    def test_toggle_data_during_active_wifi_tethering(self):
1284        """WiFi Tethering test: Toggle Data during active WiFi Tethering
1285
1286        1. DUT data connection is on and idle.
1287        2. DUT start 2.4G WiFi Tethering
1288        3. PhoneB disable data, connect to DUT's softAP
1289        4. Verify Internet access on DUT and PhoneB
1290        5. Disable Data on DUT, verify PhoneB still connected to WiFi, but no Internet access.
1291        6. Enable Data on DUT, verify PhoneB still connected to WiFi and have Internet access.
1292
1293        Returns:
1294            True if success.
1295            False if failed.
1296        """
1297        if not verify_toggle_data_during_wifi_tethering(self.log,
1298                                                        self.provider,
1299                                                        self.clients):
1300            return False
1301        return True
1302
1303    # Invalid Live Test. Can't rely on the result of this test with live network.
1304    # Network may decide not to change the RAT when data conenction is active.
1305    @test_tracker_info(uuid="c92a961b-e85d-435c-8988-052928add591")
1306    @TelephonyBaseTest.tel_test_wrap
1307    def test_change_rat_during_active_wifi_tethering_lte_to_3g(self):
1308        """WiFi Tethering test: Change Cellular Data RAT generation from LTE to 3G,
1309            during active WiFi Tethering.
1310
1311        1. DUT in LTE mode, idle.
1312        2. DUT start 2.4G WiFi Tethering
1313        3. PhoneB disable data, connect to DUT's softAP
1314        4. Verily Internet access on DUT and PhoneB
1315        5. Change DUT Cellular Data RAT generation from LTE to 3G.
1316        6. Verify both DUT and PhoneB have Internet access.
1317
1318        Returns:
1319            True if success.
1320            False if failed.
1321        """
1322        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_4G):
1323            self.log.error("Verify 4G Internet access failed.")
1324            return False
1325        try:
1326            if not wifi_tethering_setup_teardown(
1327                    self.log,
1328                    self.provider, [self.clients[0]],
1329                    ap_band=WIFI_CONFIG_APBAND_2G,
1330                    check_interval=10,
1331                    check_iteration=2,
1332                    do_cleanup=False):
1333                self.log.error("WiFi Tethering failed.")
1334                return False
1335
1336            if not self.provider.droid.wifiIsApEnabled():
1337                self.provider.log.error("Provider WiFi tethering stopped.")
1338                return False
1339
1340            self.log.info("Provider change RAT from LTE to 3G.")
1341            if not ensure_network_generation(
1342                    self.log,
1343                    self.provider,
1344                    RAT_3G,
1345                    voice_or_data=NETWORK_SERVICE_DATA,
1346                    toggle_apm_after_setting=False):
1347                self.provider.log.error("Provider failed to reselect to 3G.")
1348                return False
1349            time.sleep(WAIT_TIME_DATA_STATUS_CHANGE_DURING_WIFI_TETHERING)
1350            if not verify_internet_connection(self.log, self.provider):
1351                self.provider.log.error("Data not available on Provider.")
1352                return False
1353            if not self.provider.droid.wifiIsApEnabled():
1354                self.provider.log.error("Provider WiFi tethering stopped.")
1355                return False
1356            if not tethering_check_internet_connection(
1357                    self.log, self.provider, [self.clients[0]], 10, 5):
1358                return False
1359        finally:
1360            if not wifi_tethering_cleanup(self.log, self.provider,
1361                                          self.clients):
1362                return False
1363        return True
1364
1365    # Invalid Live Test. Can't rely on the result of this test with live network.
1366    # Network may decide not to change the RAT when data conenction is active.
1367    @test_tracker_info(uuid="eb5f0180-b70d-436f-8fcb-60c59307cc43")
1368    @TelephonyBaseTest.tel_test_wrap
1369    def test_change_rat_during_active_wifi_tethering_3g_to_lte(self):
1370        """WiFi Tethering test: Change Cellular Data RAT generation from 3G to LTE,
1371            during active WiFi Tethering.
1372
1373        1. DUT in 3G mode, idle.
1374        2. DUT start 2.4G WiFi Tethering
1375        3. PhoneB disable data, connect to DUT's softAP
1376        4. Verily Internet access on DUT and PhoneB
1377        5. Change DUT Cellular Data RAT generation from 3G to LTE.
1378        6. Verify both DUT and PhoneB have Internet access.
1379
1380        Returns:
1381            True if success.
1382            False if failed.
1383        """
1384        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_3G):
1385            self.log.error("Verify 3G Internet access failed.")
1386            return False
1387        try:
1388            if not wifi_tethering_setup_teardown(
1389                    self.log,
1390                    self.provider, [self.clients[0]],
1391                    ap_band=WIFI_CONFIG_APBAND_2G,
1392                    check_interval=10,
1393                    check_iteration=2,
1394                    do_cleanup=False):
1395                self.log.error("WiFi Tethering failed.")
1396                return False
1397
1398            if not self.provider.droid.wifiIsApEnabled():
1399                self.log.error("Provider WiFi tethering stopped.")
1400                return False
1401
1402            self.log.info("Provider change RAT from 3G to 4G.")
1403            if not ensure_network_generation(
1404                    self.log,
1405                    self.provider,
1406                    RAT_4G,
1407                    voice_or_data=NETWORK_SERVICE_DATA,
1408                    toggle_apm_after_setting=False):
1409                self.log.error("Provider failed to reselect to 4G.")
1410                return False
1411            time.sleep(WAIT_TIME_DATA_STATUS_CHANGE_DURING_WIFI_TETHERING)
1412            if not verify_internet_connection(self.log, self.provider):
1413                self.provider.log.error("Data not available on Provider.")
1414                return False
1415            if not self.provider.droid.wifiIsApEnabled():
1416                self.provider.log.error("Provider WiFi tethering stopped.")
1417                return False
1418            if not tethering_check_internet_connection(
1419                    self.log, self.provider, [self.clients[0]], 10, 5):
1420                return False
1421        finally:
1422            if not wifi_tethering_cleanup(self.log, self.provider, [self.clients[0]]):
1423                return False
1424        return True
1425
1426    @test_tracker_info(uuid="12a6c910-fa96-4d9b-99a5-8391fea33732")
1427    @TelephonyBaseTest.tel_test_wrap
1428    def test_toggle_apm_during_active_wifi_tethering(self):
1429        """WiFi Tethering test: Toggle APM during active WiFi Tethering
1430
1431        1. DUT in LTE mode, idle.
1432        2. DUT start 2.4G WiFi Tethering
1433        3. PhoneB disable data, connect to DUT's softAP
1434        4. Verify Internet access on DUT and PhoneB
1435        5. DUT toggle APM on, verify WiFi tethering stopped, PhoneB lost WiFi connection.
1436        6. DUT toggle APM off, verify PhoneA have cellular data and Internet connection.
1437
1438        Returns:
1439            True if success.
1440            False if failed.
1441        """
1442        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_4G):
1443            self.log.error("Verify 4G Internet access failed.")
1444            return False
1445        try:
1446            ssid = rand_ascii_str(10)
1447            if not wifi_tethering_setup_teardown(
1448                    self.log,
1449                    self.provider, [self.clients[0]],
1450                    ap_band=WIFI_CONFIG_APBAND_2G,
1451                    check_interval=10,
1452                    check_iteration=2,
1453                    do_cleanup=False,
1454                    ssid=ssid):
1455                self.log.error("WiFi Tethering failed.")
1456                return False
1457
1458            if not verify_toggle_apm_tethering_internet_connection(self.log,
1459                                                                   self.provider,
1460                                                                   self.clients,
1461                                                                   ssid):
1462                return False
1463        finally:
1464            self.clients[0].droid.telephonyToggleDataConnection(True)
1465            wifi_reset(self.log, self.clients[0])
1466        return True
1467
1468    @test_tracker_info(uuid="037e80fc-6eab-4cd1-846a-b9780a1d502d")
1469    @TelephonyBaseTest.tel_test_wrap
1470    def test_tethering_entitlement_check(self):
1471        """Tethering Entitlement Check Test
1472
1473        Get tethering entitlement check result.
1474
1475        Returns:
1476            True if entitlement check returns True.
1477        """
1478        self.number_of_devices = 1
1479
1480        return verify_tethering_entitlement_check(self.log,
1481                                                  self.provider)
1482
1483    @test_tracker_info(uuid="4972826e-39ea-42f7-aae0-06fe3aa9ecc6")
1484    @TelephonyBaseTest.tel_test_wrap
1485    def test_tethering_4g_to_2gwifi_stress(self):
1486        """Stress Test LTE to WiFI 2.4G Tethering
1487
1488        This is a stress test for "test_tethering_4g_to_2gwifi".
1489        Default MINIMUM_SUCCESS_RATE is set to 95%.
1490
1491        Returns:
1492            True stress pass rate is higher than MINIMUM_SUCCESS_RATE.
1493            False otherwise.
1494        """
1495        def precondition():
1496            return ensure_phones_default_state(self.log, self.android_devices)
1497
1498        def test_case():
1499            return test_wifi_tethering(self.log,
1500                                       self.provider,
1501                                       self.clients,
1502                                       self.clients,
1503                                       RAT_4G,
1504                                       WIFI_CONFIG_APBAND_2G,
1505                                       check_interval=10,
1506                                       check_iteration=10)
1507        return run_stress_test(self.log, self.stress_test_number, precondition, test_case)
1508
1509    @test_tracker_info(uuid="54e85aed-09e3-42e2-bb33-bca1005d93ab")
1510    @TelephonyBaseTest.tel_test_wrap
1511    def test_tethering_wifi_ssid_quotes(self):
1512        """WiFi Tethering test: SSID name have quotes.
1513        1. Set SSID name have double quotes.
1514        2. Start LTE to WiFi (2.4G) tethering.
1515        3. Verify tethering.
1516
1517        Returns:
1518            True if success.
1519            False if failed.
1520        """
1521        ssid = "\"" + rand_ascii_str(10) + "\""
1522        self.log.info(
1523            "Starting WiFi Tethering test with ssid: {}".format(ssid))
1524
1525        return test_wifi_tethering(self.log,
1526                                   self.provider,
1527                                   self.clients,
1528                                   self.clients,
1529                                   None,
1530                                   WIFI_CONFIG_APBAND_2G,
1531                                   check_interval=10,
1532                                   check_iteration=10,
1533                                   ssid=ssid)
1534
1535    @test_tracker_info(uuid="320326da-bf32-444d-81f9-f781c55dbc99")
1536    @TelephonyBaseTest.tel_test_wrap
1537    def test_tethering_wifi_password_escaping_characters(self):
1538        """WiFi Tethering test: password have escaping characters.
1539        1. Set password have escaping characters.
1540            e.g.: '"DQ=/{Yqq;M=(^_3HzRvhOiL8S%`]w&l<Qp8qH)bs<4E9v_q=HLr^)}w$blA0Kg'
1541        2. Start LTE to WiFi (2.4G) tethering.
1542        3. Verify tethering.
1543
1544        Returns:
1545            True if success.
1546            False if failed.
1547        """
1548        if not test_setup_tethering(self.log, self.provider, self.clients, None):
1549            self.log.error("Verify Internet access failed.")
1550            return False
1551
1552        password = TETHERING_PASSWORD_HAS_ESCAPE
1553        self.log.info(
1554            "Starting WiFi Tethering test with password: {}".format(password))
1555
1556        return wifi_tethering_setup_teardown(
1557            self.log,
1558            self.provider,
1559            self.clients,
1560            ap_band=WIFI_CONFIG_APBAND_2G,
1561            check_interval=10,
1562            check_iteration=10,
1563            password=password)
1564
1565    @test_tracker_info(uuid="617c7e71-f166-465f-bfd3-b5a3a40cc0d4")
1566    @TelephonyBaseTest.tel_test_wrap
1567    def test_tethering_wifi_ssid(self):
1568        """WiFi Tethering test: start WiFi tethering with all kinds of SSIDs.
1569
1570        For each listed SSID, start WiFi tethering on DUT, client connect WiFi,
1571        then tear down WiFi tethering.
1572
1573        Returns:
1574            True if WiFi tethering succeed on all SSIDs.
1575            False if failed.
1576        """
1577        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_4G):
1578            self.log.error("Setup Failed.")
1579            return False
1580        ssid_list = TETHERING_SPECIAL_SSID_LIST
1581        fail_list = {}
1582
1583        for ssid in ssid_list:
1584            password = rand_ascii_str(8)
1585            self.log.info("SSID: <{}>, Password: <{}>".format(ssid, password))
1586            if not test_start_wifi_tethering_connect_teardown(self.log,
1587                                                          self.provider,
1588                                                          self.clients[0],
1589                                                          ssid,
1590                                                          password):
1591                fail_list[ssid] = password
1592
1593        if len(fail_list) > 0:
1594            self.log.error("Failed cases: {}".format(fail_list))
1595            return False
1596        else:
1597            return True
1598
1599    @test_tracker_info(uuid="9a5b5a34-b5cf-451d-94c4-8a64d456dfe5")
1600    @TelephonyBaseTest.tel_test_wrap
1601    def test_tethering_wifi_password(self):
1602        """WiFi Tethering test: start WiFi tethering with all kinds of passwords.
1603
1604        For each listed password, start WiFi tethering on DUT, client connect WiFi,
1605        then tear down WiFi tethering.
1606
1607        Returns:
1608            True if WiFi tethering succeed on all passwords.
1609            False if failed.
1610        """
1611        if not test_setup_tethering(self.log, self.provider, self.clients, RAT_4G):
1612            self.log.error("Setup Failed.")
1613            return False
1614        password_list = TETHERING_SPECIAL_PASSWORD_LIST
1615        fail_list = {}
1616
1617        for password in password_list:
1618            ssid = rand_ascii_str(8)
1619            self.log.info("SSID: <{}>, Password: <{}>".format(ssid, password))
1620            if not test_start_wifi_tethering_connect_teardown(self.log,
1621                                                          self.provider,
1622                                                          self.clients[0],
1623                                                          ssid,
1624                                                          password):
1625                fail_list[ssid] = password
1626
1627        if len(fail_list) > 0:
1628            self.log.error("Failed cases: {}".format(fail_list))
1629            return False
1630        else:
1631            return True
1632
1633    @test_tracker_info(uuid="216bdb8c-edbf-4ff8-8750-a0861ab44df6")
1634    @TelephonyBaseTest.tel_test_wrap
1635    def test_tethering_wifi_volte_call(self):
1636        """WiFi Tethering test: VoLTE call during WiFi tethering
1637        1. Start LTE to WiFi (2.4G) tethering.
1638        2. Verify tethering.
1639        3. Make outgoing VoLTE call on tethering provider.
1640        4. Verify tethering still works.
1641        5. Make incoming VoLTE call on tethering provider.
1642        6. Verify tethering still works.
1643
1644        Returns:
1645            True if success.
1646            False if failed.
1647        """
1648        return test_tethering_wifi_and_voice_call(self.log, self.provider, self.clients,
1649            RAT_4G, phone_setup_volte, is_phone_in_call_volte)
1650
1651    @test_tracker_info(uuid="bcd430cc-6d33-47d1-825d-aae9f248addc")
1652    @TelephonyBaseTest.tel_test_wrap
1653    def test_tethering_wifi_csfb_call(self):
1654        """WiFi Tethering test: CSFB call during WiFi tethering
1655        1. Start LTE to WiFi (2.4G) tethering.
1656        2. Verify tethering.
1657        3. Make outgoing CSFB call on tethering provider.
1658        4. Verify tethering still works.
1659        5. Make incoming CSFB call on tethering provider.
1660        6. Verify tethering still works.
1661
1662        Returns:
1663            True if success.
1664            False if failed.
1665        """
1666        return test_tethering_wifi_and_voice_call(self.log, self.provider, self.clients,
1667            RAT_4G, phone_setup_csfb, is_phone_in_call_csfb)
1668
1669    @test_tracker_info(uuid="19e0df23-6819-4c69-bfda-eea9cce802d8")
1670    @TelephonyBaseTest.tel_test_wrap
1671    def test_tethering_wifi_3g_call(self):
1672        """WiFi Tethering test: 3G call during WiFi tethering
1673        1. Start 3G to WiFi (2.4G) tethering.
1674        2. Verify tethering.
1675        3. Make outgoing CS call on tethering provider.
1676        4. Verify tethering still works.
1677        5. Make incoming CS call on tethering provider.
1678        6. Verify tethering still works.
1679
1680        Returns:
1681            True if success.
1682            False if failed.
1683        """
1684        return test_tethering_wifi_and_voice_call(self.log, self.provider, self.clients,
1685            RAT_3G, phone_setup_voice_3g, is_phone_in_call_3g)
1686
1687    @test_tracker_info(uuid="4acd98b5-fdef-4736-969f-3fa953990a58")
1688    @TelephonyBaseTest.tel_test_wrap
1689    def test_tethering_wifi_no_password(self):
1690        """WiFi Tethering test: Start WiFi tethering with no password
1691
1692        1. DUT is idle.
1693        2. DUT start 2.4G WiFi Tethering, with no WiFi password.
1694        3. PhoneB disable data, connect to DUT's softAP
1695        4. Verify Internet access on DUT and PhoneB
1696
1697        Returns:
1698            True if success.
1699            False if failed.
1700        """
1701        if not test_setup_tethering(self.log, self.provider, self.clients, None):
1702            self.log.error("Verify Internet access failed.")
1703            return False
1704
1705        return wifi_tethering_setup_teardown(
1706            self.log,
1707            self.provider, [self.clients[0]],
1708            ap_band=WIFI_CONFIG_APBAND_2G,
1709            check_interval=10,
1710            check_iteration=10,
1711            password="")
1712
1713    @test_tracker_info(uuid="86ad1680-bfb8-457e-8b4d-23321cb3f223")
1714    @TelephonyBaseTest.tel_test_wrap
1715    def test_tethering_wifi_reboot(self):
1716        """WiFi Tethering test: Start WiFi tethering then Reboot device
1717
1718        1. DUT is idle.
1719        2. DUT start 2.4G WiFi Tethering.
1720        3. PhoneB disable data, connect to DUT's softAP
1721        4. Verify Internet access on DUT and PhoneB
1722        5. Reboot DUT
1723        6. After DUT reboot, verify tethering is stopped.
1724
1725        Returns:
1726            True if success.
1727            False if failed.
1728        """
1729        try:
1730            if not test_wifi_tethering(self.log,
1731                                       self.provider,
1732                                       self.clients,
1733                                       [self.clients[0]],
1734                                       None,
1735                                       WIFI_CONFIG_APBAND_2G,
1736                                       check_interval=10,
1737                                       check_iteration=2,
1738                                       do_cleanup=False):
1739                return False
1740
1741            if not verify_wifi_tethering_when_reboot(self.log,
1742                                                     self.provider):
1743                return False
1744
1745        finally:
1746            if not wifi_tethering_cleanup(self.log, self.provider,
1747                                          self.clients):
1748                return False
1749
1750        return True
1751
1752    @test_tracker_info(uuid="5cf04ca2-dfde-43d6-be74-78b9abdf6c26")
1753    @TelephonyBaseTest.tel_test_wrap
1754    def test_connect_wifi_start_tethering_wifi_reboot(self):
1755        """WiFi Tethering test: WiFI connected, then start WiFi tethering,
1756            then reboot device.
1757
1758        Initial Condition: DUT in 4G mode, idle, DUT connect to WiFi.
1759        1. DUT start 2.4G WiFi Tethering.
1760        2. PhoneB disable data, connect to DUT's softAP
1761        3. Verify Internet access on DUT and PhoneB
1762        4. Reboot DUT
1763        5. After DUT reboot, verify tethering is stopped. DUT is able to connect
1764            to previous WiFi AP.
1765
1766        Returns:
1767            True if success.
1768            False if failed.
1769        """
1770
1771        # Ensure provider connecting to wifi network.
1772        def setup_provider_internet_connection():
1773            return setup_device_internet_connection(self.log,
1774                                                    self.provider,
1775                                                    self.wifi_network_ssid,
1776                                                    self.wifi_network_pass)
1777
1778        # wait for provider connecting to wifi network and verify
1779        # internet connection is working.
1780        def wait_and_verify_internet_connection():
1781            return wait_and_verify_device_internet_connection(self.log,
1782                                                              self.provider)
1783
1784        try:
1785            if not test_wifi_tethering(self.log,
1786                                       self.provider,
1787                                       self.clients,
1788                                       [self.clients[0]],
1789                                       None,
1790                                       WIFI_CONFIG_APBAND_2G,
1791                                       check_interval=10,
1792                                       check_iteration=2,
1793                                       do_cleanup=False,
1794                                       pre_teardown_func=setup_provider_internet_connection):
1795                return False
1796
1797            if not verify_wifi_tethering_when_reboot(self.log,
1798                                                     self.provider,
1799                                                     post_reboot_func=wait_and_verify_internet_connection):
1800                return False
1801
1802        finally:
1803            if not wifi_tethering_cleanup(self.log,
1804                                          self.provider,
1805                                          self.clients):
1806                return False
1807        return True
1808
1809    @test_tracker_info(uuid="e0621997-c5bd-4137-afa6-b43406e9c713")
1810    @TelephonyBaseTest.tel_test_wrap
1811    def test_connect_wifi_reboot_start_tethering_wifi(self):
1812        """WiFi Tethering test: DUT connected to WiFi, then reboot,
1813        After reboot, start WiFi tethering, verify tethering actually works.
1814
1815        Initial Condition: Device set to 4G mode, idle, DUT connect to WiFi.
1816        1. Verify Internet is working on DUT (by WiFi).
1817        2. Reboot DUT.
1818        3. DUT start 2.4G WiFi Tethering.
1819        4. PhoneB disable data, connect to DUT's softAP
1820        5. Verify Internet access on DUT and PhoneB
1821
1822        Returns:
1823            True if success.
1824            False if failed.
1825        """
1826
1827        # Ensure provider connecting to wifi network and then reboot.
1828        def setup_provider_internet_connect_then_reboot():
1829            return setup_device_internet_connection_then_reboot(self.log,
1830                                                                self.provider,
1831                                                                self.wifi_network_ssid,
1832                                                                self.wifi_network_pass)
1833        return test_wifi_tethering(self.log,
1834                                   self.provider,
1835                                   self.clients,
1836                                   [self.clients[0]],
1837                                   None,
1838                                   WIFI_CONFIG_APBAND_2G,
1839                                   check_interval=10,
1840                                   check_iteration=2,
1841                                   pre_teardown_func=setup_provider_internet_connect_then_reboot)
1842
1843    @test_tracker_info(uuid="89a849ef-e2ed-4bf2-ac31-81d34aba672a")
1844    @TelephonyBaseTest.tel_test_wrap
1845    def test_tethering_wifi_screen_off_enable_doze_mode(self):
1846        """WiFi Tethering test: Start WiFi tethering, then turn off DUT's screen,
1847            then enable doze mode, verify internet connection.
1848
1849        1. Start WiFi tethering on DUT.
1850        2. PhoneB disable data, and connect to DUT's softAP
1851        3. Verify Internet access on DUT and PhoneB
1852        4. Turn off DUT's screen. Wait for 1 minute and
1853            verify Internet access on Client PhoneB.
1854        5. Enable doze mode on DUT. Wait for 1 minute and
1855            verify Internet access on Client PhoneB.
1856        6. Disable doze mode and turn off wifi tethering on DUT.
1857
1858        Returns:
1859            True if success.
1860            False if failed.
1861        """
1862        try:
1863            if not test_wifi_tethering(self.log,
1864                                       self.provider,
1865                                       self.clients,
1866                                       [self.clients[0]],
1867                                       None,
1868                                       WIFI_CONFIG_APBAND_2G,
1869                                       check_interval=10,
1870                                       check_iteration=2,
1871                                       do_cleanup=False):
1872                return False
1873            if not verify_internet_connection_in_doze_mode(self.log,
1874                                                           self.provider,
1875                                                           self.clients[0]):
1876                return False
1877
1878        finally:
1879            if not wifi_tethering_cleanup(self.log,
1880                                          self.provider,
1881                                          [self.clients[0]]):
1882                return False
1883        return True
1884
1885    @test_tracker_info(uuid="695eef18-f759-4b41-8ad3-1fb329ee4b1b")
1886    @TelephonyBaseTest.tel_test_wrap
1887    def test_msim_switch_data_sim_2g(self):
1888        """Switch Data SIM on 2G network.
1889
1890        Steps:
1891        1. Data on default Data SIM.
1892        2. Switch Data to another SIM. Make sure data is still available.
1893        3. Switch Data back to previous SIM. Make sure data is still available.
1894
1895        Expected Results:
1896        1. Verify Data on Cell
1897        2. Verify Data on Wifi
1898
1899        Returns:
1900            True if success.
1901            False if failed.
1902        """
1903        ad = self.android_devices[0]
1904        self.number_of_devices = 1
1905        current_data_sub_id = ad.droid.subscriptionGetDefaultDataSubId()
1906        current_sim_slot_index = get_slot_index_from_subid(
1907            ad, current_data_sub_id)
1908        if current_sim_slot_index == SIM1_SLOT_INDEX:
1909            next_sim_slot_index = SIM2_SLOT_INDEX
1910        else:
1911            next_sim_slot_index = SIM1_SLOT_INDEX
1912        next_data_sub_id = get_subid_from_slot_index(self.log, ad,
1913                                                     next_sim_slot_index)
1914        self.log.info("Current Data is on subId: {}, SIM slot: {}".format(
1915            current_data_sub_id, current_sim_slot_index))
1916        if not ensure_network_generation_for_subscription(
1917                self.log,
1918                ad,
1919                ad.droid.subscriptionGetDefaultDataSubId(),
1920                GEN_2G,
1921                voice_or_data=NETWORK_SERVICE_DATA):
1922            self.log.error("Device data does not attach to 2G.")
1923            return False
1924        if not verify_internet_connection(self.log, ad):
1925            self.log.error("No Internet access on default Data SIM.")
1926            return False
1927
1928        self.log.info("Change Data to subId: {}, SIM slot: {}".format(
1929            next_data_sub_id, next_sim_slot_index))
1930        if not change_data_sim_and_verify_data(self.log, ad,
1931                                               next_sim_slot_index):
1932            self.log.error("Failed to change data SIM.")
1933            return False
1934
1935        next_data_sub_id = current_data_sub_id
1936        next_sim_slot_index = current_sim_slot_index
1937        self.log.info("Change Data back to subId: {}, SIM slot: {}".format(
1938            next_data_sub_id, next_sim_slot_index))
1939        if not change_data_sim_and_verify_data(self.log, ad,
1940                                               next_sim_slot_index):
1941            self.log.error("Failed to change data SIM.")
1942            return False
1943
1944        return True
1945
1946
1947    @test_tracker_info(uuid="9b8e92da-0ae1-472c-a72a-f6427e5405ce")
1948    @TelephonyBaseTest.tel_test_wrap
1949    def test_wifi_connect_disconnect_4g(self):
1950        """Perform multiple connects and disconnects from WiFi and verify that
1951            data switches between WiFi and Cell.
1952
1953        Steps:
1954        1. DUT Cellular Data is on 4G. Reset Wifi on DUT
1955        2. Connect DUT to a WiFi AP
1956        3. Repeat steps 1-2, alternately disconnecting and disabling wifi
1957
1958        Expected Results:
1959        1. Verify Data on Cell
1960        2. Verify Data on Wifi
1961
1962        Returns:
1963            True if success.
1964            False if failed.
1965        """
1966
1967        ad = self.android_devices[0]
1968        self.number_of_devices = 1
1969
1970        if not ensure_network_generation_for_subscription(
1971                self.log, ad, ad.droid.subscriptionGetDefaultDataSubId(),
1972                GEN_4G, MAX_WAIT_TIME_NW_SELECTION, NETWORK_SERVICE_DATA):
1973            self.log.error("Device {} failed to reselect in {}s.".format(
1974                ad.serial, MAX_WAIT_TIME_NW_SELECTION))
1975            return False
1976        return test_wifi_connect_disconnect(self.log, ad, self.wifi_network_ssid, self.wifi_network_pass)
1977
1978    @test_tracker_info(uuid="09893b1f-a4a2-49d3-8027-c2c91cb8742e")
1979    @TelephonyBaseTest.tel_test_wrap
1980    def test_wifi_connect_disconnect_3g(self):
1981        """Perform multiple connects and disconnects from WiFi and verify that
1982            data switches between WiFi and Cell.
1983
1984        Steps:
1985        1. DUT Cellular Data is on 3G. Reset Wifi on DUT
1986        2. Connect DUT to a WiFi AP
1987        3. Repeat steps 1-2, alternately disconnecting and disabling wifi
1988
1989        Expected Results:
1990        1. Verify Data on Cell
1991        2. Verify Data on Wifi
1992
1993        Returns:
1994            True if success.
1995            False if failed.
1996        """
1997
1998        ad = self.android_devices[0]
1999        self.number_of_devices = 1
2000
2001        if not ensure_network_generation_for_subscription(
2002                self.log, ad, ad.droid.subscriptionGetDefaultDataSubId(),
2003                GEN_3G, MAX_WAIT_TIME_NW_SELECTION, NETWORK_SERVICE_DATA):
2004            self.log.error("Device {} failed to reselect in {}s.".format(
2005                ad.serial, MAX_WAIT_TIME_NW_SELECTION))
2006            return False
2007        return test_wifi_connect_disconnect(self.log, ad, self.wifi_network_ssid, self.wifi_network_pass)
2008
2009    @test_tracker_info(uuid="0f095ca4-ce05-458f-9670-49a69f8c8270")
2010    @TelephonyBaseTest.tel_test_wrap
2011    def test_wifi_connect_disconnect_2g(self):
2012        """Perform multiple connects and disconnects from WiFi and verify that
2013            data switches between WiFi and Cell.
2014
2015        Steps:
2016        1. DUT Cellular Data is on 2G. Reset Wifi on DUT
2017        2. Connect DUT to a WiFi AP
2018        3. Repeat steps 1-2, alternately disconnecting and disabling wifi
2019
2020        Expected Results:
2021        1. Verify Data on Cell
2022        2. Verify Data on Wifi
2023
2024        Returns:
2025            True if success.
2026            False if failed.
2027        """
2028        ad = self.android_devices[0]
2029        self.number_of_devices = 1
2030
2031        if not ensure_network_generation_for_subscription(
2032                self.log, ad, ad.droid.subscriptionGetDefaultDataSubId(),
2033                GEN_2G, MAX_WAIT_TIME_NW_SELECTION, NETWORK_SERVICE_DATA):
2034            self.log.error("Device {} failed to reselect in {}s.".format(
2035                ad.serial, MAX_WAIT_TIME_NW_SELECTION))
2036            return False
2037        return test_wifi_connect_disconnect(self.log, ad, self.wifi_network_ssid, self.wifi_network_pass)
2038
2039    def _test_wifi_tethering_enabled_add_voice_call(
2040            self, network_generation, voice_call_direction,
2041            is_data_available_during_call):
2042        """Tethering enabled + voice call.
2043
2044        Steps:
2045        1. DUT data is on <network_generation>. Start WiFi Tethering.
2046        2. PhoneB connect to DUT's softAP
2047        3. DUT make a MO/MT (<voice_call_direction>) phone call.
2048        4. DUT end phone call.
2049
2050        Expected Results:
2051        1. DUT is able to start WiFi tethering.
2052        2. PhoneB connected to DUT's softAP and able to browse Internet.
2053        3. DUT WiFi tethering is still on. Phone call works OK.
2054            If is_data_available_during_call is True, then PhoneB still has
2055            Internet access.
2056            Else, then Data is suspend, PhoneB has no Internet access.
2057        4. WiFi Tethering still on, voice call stopped, and PhoneB have Internet
2058            access.
2059
2060        Returns:
2061            True if success.
2062            False if failed.
2063        """
2064        if not test_setup_tethering(self.log, self.provider, self.clients, network_generation):
2065            self.log.error("Verify Internet access failed.")
2066            return False
2067        try:
2068            # Start WiFi Tethering
2069            if not wifi_tethering_setup_teardown(
2070                    self.log,
2071                    self.provider, [self.clients[0]],
2072                    ap_band=WIFI_CONFIG_APBAND_2G,
2073                    check_interval=10,
2074                    check_iteration=2,
2075                    do_cleanup=False):
2076                self.log.error("WiFi Tethering failed.")
2077                return False
2078
2079            if not self.provider.droid.wifiIsApEnabled():
2080                self.log.error("Provider WiFi tethering stopped.")
2081                return False
2082
2083            # Make a voice call
2084            if voice_call_direction == DIRECTION_MOBILE_ORIGINATED:
2085                ad_caller = self.provider
2086                ad_callee = self.clients[0]
2087            else:
2088                ad_caller = self.clients[0]
2089                ad_callee = self.provider
2090            if not call_setup_teardown(self.log, ad_caller, ad_callee, None,
2091                                       None, None):
2092                self.log.error("Failed to Establish {} Voice Call".format(
2093                    voice_call_direction))
2094                return False
2095
2096            # Tethering should still be on.
2097            if not self.provider.droid.wifiIsApEnabled():
2098                self.provider.log.error("Provider WiFi tethering stopped.")
2099                return False
2100            if not is_data_available_during_call:
2101                if verify_internet_connection(
2102                        self.log, self.clients[0], retry=0):
2103                    self.clients[0].log.error(
2104                        "Client should not have Internet Access.")
2105                    return False
2106            else:
2107                if not verify_internet_connection(self.log, self.clients[0]):
2108                    self.clients[0].error(
2109                        "Client should have Internet Access.")
2110                    return False
2111
2112            # Hangup call. Client should have data.
2113            if not hangup_call(self.log, self.provider):
2114                self.provider.log.error("Failed to hang up call")
2115                return False
2116            if not self.provider.droid.wifiIsApEnabled():
2117                self.provider.log.error("Provider WiFi tethering stopped.")
2118                return False
2119            if not verify_internet_connection(self.log, self.clients[0]):
2120                self.clients[0].log.error(
2121                    "Client should have Internet Access.")
2122                return False
2123        finally:
2124            self.clients[0].droid.telephonyToggleDataConnection(True)
2125            wifi_reset(self.log, self.clients[0])
2126            if self.provider.droid.wifiIsApEnabled():
2127                stop_wifi_tethering(self.log, self.provider)
2128        return True
2129
2130    @test_tracker_info(uuid="4d7a68c6-5eae-4242-a6e6-668f830caec3")
2131    @TelephonyBaseTest.tel_test_wrap
2132    def test_wifi_tethering_enabled_add_mo_voice_call_2g_dsds(self):
2133        """Tethering enabled + voice call
2134
2135        Steps:
2136        1. DUT is DSDS device, Data on 2G. Start WiFi Tethering on <Data SIM>
2137        2. PhoneB connect to DUT's softAP
2138        3. DUT make a mo phone call on <Voice SIM>
2139        4. DUT end phone call.
2140
2141        Expected Results:
2142        1. DUT is able to start WiFi tethering.
2143        2. PhoneB connected to DUT's softAP and able to browse Internet.
2144        3. DUT WiFi tethering is still on. Phone call works OK. Data is suspend,
2145            PhoneB still connected to DUT's softAP, but no data available.
2146        4. DUT data resumes, and PhoneB have Internet access.
2147
2148        Returns:
2149            True if success.
2150            False if failed.
2151        """
2152
2153        return self._test_wifi_tethering_enabled_add_voice_call(
2154            GEN_2G, DIRECTION_MOBILE_ORIGINATED, False)
2155
2156    @test_tracker_info(uuid="de720069-a46c-4a6f-ae80-60b9349c8528")
2157    @TelephonyBaseTest.tel_test_wrap
2158    def test_wifi_tethering_enabled_add_mt_voice_call_2g_dsds(self):
2159        """Tethering enabled + voice call
2160
2161        Steps:
2162        1. DUT is DSDS device, Data on 2G. Start WiFi Tethering on <Data SIM>
2163        2. PhoneB connect to DUT's softAP
2164        3. DUT make a mt phone call on <Voice SIM>
2165        4. DUT end phone call.
2166
2167        Expected Results:
2168        1. DUT is able to start WiFi tethering.
2169        2. PhoneB connected to DUT's softAP and able to browse Internet.
2170        3. DUT WiFi tethering is still on. Phone call works OK. Data is suspend,
2171            PhoneB still connected to DUT's softAP, but no data available.
2172        4. DUT data resumes, and PhoneB have Internet access.
2173
2174        Returns:
2175            True if success.
2176            False if failed.
2177        """
2178
2179        return self._test_wifi_tethering_enabled_add_voice_call(
2180            GEN_2G, DIRECTION_MOBILE_TERMINATED, False)
2181
2182    @test_tracker_info(uuid="fad169c0-8ae6-45d2-98ba-3fb60466ff0b")
2183    @TelephonyBaseTest.tel_test_wrap
2184    def test_wifi_tethering_msim_switch_data_sim(self):
2185        """Tethering enabled + switch data SIM.
2186
2187        Steps:
2188        1. Start WiFi Tethering on <Default Data SIM>
2189        2. PhoneB connect to DUT's softAP
2190        3. DUT change Default Data SIM.
2191
2192        Expected Results:
2193        1. DUT is able to start WiFi tethering.
2194        2. PhoneB connected to DUT's softAP and able to browse Internet.
2195        3. DUT Data changed to 2nd SIM, WiFi tethering should continues,
2196            PhoneB should have Internet access.
2197
2198        Returns:
2199            True if success.
2200            False if failed.
2201        """
2202        current_data_sub_id = self.provider.droid.subscriptionGetDefaultDataSubId(
2203        )
2204        current_sim_slot_index = get_slot_index_from_subid(
2205            self.provider, current_data_sub_id)
2206        self.provider.log.info("Current Data is on subId: %s, SIM slot: %s",
2207                               current_data_sub_id, current_sim_slot_index)
2208        if not test_setup_tethering(self.log, self.provider, self.clients, None):
2209            self.log.error("Verify Internet access failed.")
2210            return False
2211        try:
2212            # Start WiFi Tethering
2213            if not wifi_tethering_setup_teardown(
2214                    self.log,
2215                    self.provider, [self.clients[0]],
2216                    ap_band=WIFI_CONFIG_APBAND_2G,
2217                    check_interval=10,
2218                    check_iteration=2,
2219                    do_cleanup=False):
2220                self.log.error("WiFi Tethering failed.")
2221                return False
2222            for i in range(0, 2):
2223                next_sim_slot_index = \
2224                    {SIM1_SLOT_INDEX : SIM2_SLOT_INDEX,
2225                     SIM2_SLOT_INDEX : SIM1_SLOT_INDEX}[current_sim_slot_index]
2226                self.log.info(
2227                    "Change Data to SIM slot: {}".format(next_sim_slot_index))
2228                if not change_data_sim_and_verify_data(self.log, self.provider,
2229                                                       next_sim_slot_index):
2230                    self.provider.log.error("Failed to change data SIM.")
2231                    return False
2232                current_sim_slot_index = next_sim_slot_index
2233                if not verify_internet_connection(self.log, self.clients[0]):
2234                    self.clients[0].log.error(
2235                        "Client should have Internet Access.")
2236                    return False
2237        finally:
2238            self.clients[0].droid.telephonyToggleDataConnection(True)
2239            wifi_reset(self.log, self.clients[0])
2240            if self.provider.droid.wifiIsApEnabled():
2241                stop_wifi_tethering(self.log, self.provider)
2242        return True
2243
2244    @test_tracker_info(uuid="8bb9383f-ddf9-400c-a831-c9462bae6b47")
2245    @TelephonyBaseTest.tel_test_wrap
2246    def test_msim_cell_data_switch_to_wifi_switch_data_sim_2g(self):
2247        """Switch Data SIM on 2G network.
2248
2249        Steps:
2250        1. Data on default Data SIM.
2251        2. Turn on WiFi, then data should be on WiFi.
2252        3. Switch Data to another SIM. Disable WiFi.
2253
2254        Expected Results:
2255        1. Verify Data on Cell
2256        2. Verify Data on WiFi
2257        3. After WiFi disabled, Cell Data is available on 2nd SIM.
2258
2259        Returns:
2260            True if success.
2261            False if failed.
2262        """
2263        ad = self.android_devices[0]
2264        self.number_of_devices = 1
2265
2266        current_data_sub_id = ad.droid.subscriptionGetDefaultDataSubId()
2267        current_sim_slot_index = get_slot_index_from_subid(
2268            ad, current_data_sub_id)
2269        if current_sim_slot_index == SIM1_SLOT_INDEX:
2270            next_sim_slot_index = SIM2_SLOT_INDEX
2271        else:
2272            next_sim_slot_index = SIM1_SLOT_INDEX
2273        next_data_sub_id = get_subid_from_slot_index(self.log, ad,
2274                                                     next_sim_slot_index)
2275        self.log.info("Current Data is on subId: {}, SIM slot: {}".format(
2276            current_data_sub_id, current_sim_slot_index))
2277        if not ensure_network_generation_for_subscription(
2278                self.log,
2279                ad,
2280                ad.droid.subscriptionGetDefaultDataSubId(),
2281                GEN_2G,
2282                voice_or_data=NETWORK_SERVICE_DATA):
2283            self.log.error("Device data does not attach to 2G.")
2284            return False
2285        if not verify_internet_connection(self.log, ad):
2286            self.log.error("No Internet access on default Data SIM.")
2287            return False
2288
2289        self.log.info("Connect to WiFi and verify Internet access.")
2290        if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
2291                                     self.wifi_network_pass):
2292            self.log.error("WiFi connect fail.")
2293            return False
2294        if (not wait_for_wifi_data_connection(self.log, ad, True)
2295                or not verify_internet_connection(self.log, ad)):
2296            self.log.error("Data is not on WiFi")
2297            return False
2298
2299        try:
2300            self.log.info(
2301                "Change Data SIM, Disable WiFi and verify Internet access.")
2302            set_subid_for_data(ad, next_data_sub_id)
2303            wifi_toggle_state(self.log, ad, False)
2304            if not wait_for_data_attach_for_subscription(
2305                    self.log, ad, next_data_sub_id,
2306                    MAX_WAIT_TIME_NW_SELECTION):
2307                self.log.error("Failed to attach data on subId:{}".format(
2308                    next_data_sub_id))
2309                return False
2310            if not verify_internet_connection(self.log, ad):
2311                self.log.error("No Internet access after changing Data SIM.")
2312                return False
2313
2314        finally:
2315            self.log.info("Change Data SIM back.")
2316            set_subid_for_data(ad, current_data_sub_id)
2317
2318        return True
2319
2320    @test_tracker_info(uuid="ef03eff7-ddd3-48e9-8f67-5e271e14048b")
2321    @TelephonyBaseTest.tel_test_wrap
2322    def test_vzw_embms_services(self):
2323        ad = self.android_devices[0]
2324        self.number_of_devices = 1
2325
2326        # Install App and Push config
2327        self.log.info("Pushing embms config and apk to the Android device.")
2328        android_embms_path = "/sdcard/mobitv"
2329        embms_path = self.user_params.get("embms_path", "embms_path")
2330        if isinstance(embms_path, list):
2331            embms_path = embms_path[0]
2332        ad.adb.shell("mkdir /sdcard/mobitv")
2333        dcafile = os.path.join(embms_path, "dca.config")
2334        apkfile = os.path.join(embms_path, "VzwDCA.apk")
2335        ad.adb.push("%s %s" % (dcafile, android_embms_path))
2336        ad.adb.install("%s" % apkfile)
2337
2338        # Co-ordinates Mapping
2339        lcd_density = ad.adb.shell("getprop ro.sf.lcd_density")
2340        ad.log.debug("lcd_density %s" % lcd_density)
2341        if lcd_density in ["420", "440"]:
2342            agree_y_axis = 1000
2343        else:
2344            agree_y_axis = 1300
2345
2346        # Screen ON needed to open the VZW App
2347        if "ON" in \
2348        ad.adb.shell(
2349               "dumpsys power | grep 'Display Power: state' | cut -d '=' -f2"):
2350            ad.log.info("Screen already ON")
2351            ad.adb.shell("input keyevent 82")
2352        else:
2353            ad.log.info("Screen OFF, turning ON")
2354            ad.adb.shell("input keyevent 26")
2355            ad.adb.shell("input keyevent 82")
2356
2357        try:
2358            # Check if app is installed
2359            if ad.is_apk_installed("com.mobitv.vzwdca"):
2360                ad.log.info("VZWDCA App is successfully installed")
2361            else:
2362                ad.log.error("VZWDCA App is not installed")
2363                return False
2364
2365            # Grant Permissions, Start, Agree, Register
2366            for cmd in ("pm grant com.mobitv.vzwdca "
2367                        "android.permission.READ_EXTERNAL_STORAGE",
2368                        "pm grant com.mobitv.vzwdca "
2369                        "android.permission.WRITE_EXTERNAL_STORAGE",
2370                        "am start -a android.intent.action.VIEW -n "
2371                        "com.mobitv.vzwdca/.DcaActivity",
2372                        "input tap 500 %d" % agree_y_axis, "input keyevent 61",
2373                        "input keyevent 61", "input keyevent 61",
2374                        "input keyevent 61", "input keyevent 61",
2375                        "input keyevent 66"):
2376                time.sleep(1)
2377                ad.log.info(cmd)
2378                ad.adb.shell(cmd)
2379
2380            # Check Reg-DeReg
2381            time.sleep(5)
2382            if ad.is_apk_running("com.qualcomm.ltebc_vzw"):
2383                ad.log.info("EMBMS Registered successfully")
2384                ad.adb.shell("input keyevent 61")
2385                time.sleep(1)
2386                ad.adb.shell("input keyevent 66")
2387                time.sleep(1)
2388                if not ad.is_apk_running("com.qualcomm.ltebc_vzw"):
2389                    ad.log.info("EMBMS De-Registered successfully")
2390                    return True
2391                else:
2392                    ad.log.error("EMBMS De-Registeration Failed")
2393                    return False
2394            else:
2395                ad.log.error("EMBMS Registeration Failed")
2396                return False
2397        finally:
2398            ad.log.info("Force Close the VZW App")
2399            ad.adb.shell("am force-stop com.mobitv.vzwdca")
2400
2401    @test_tracker_info(uuid="8a8cd773-77f5-4802-85ac-1a654bb4743c")
2402    @TelephonyBaseTest.tel_test_wrap
2403    def test_disable_data_on_non_active_data_sim(self):
2404        """Switch Data SIM on 2G network.
2405
2406        Steps:
2407        1. Data on default Data SIM.
2408        2. Disable data on non-active Data SIM.
2409
2410        Expected Results:
2411        1. Verify Data Status on Default Data SIM and non-active Data SIM.
2412        1. Verify Data Status on Default Data SIM and non-active Data SIM.
2413
2414        Returns:
2415            True if success.
2416            False if failed.
2417        """
2418        ad = self.android_devices[0]
2419        self.number_of_devices = 1
2420        current_data_sub_id = ad.droid.subscriptionGetDefaultDataSubId()
2421        current_sim_slot_index = get_slot_index_from_subid(
2422            ad, current_data_sub_id)
2423        if current_sim_slot_index == SIM1_SLOT_INDEX:
2424            non_active_sim_slot_index = SIM2_SLOT_INDEX
2425        else:
2426            non_active_sim_slot_index = SIM1_SLOT_INDEX
2427        non_active_sub_id = get_subid_from_slot_index(
2428            self.log, ad, non_active_sim_slot_index)
2429        self.log.info("Current Data is on subId: {}, SIM slot: {}".format(
2430            current_data_sub_id, current_sim_slot_index))
2431
2432        if not ensure_network_generation_for_subscription(
2433                self.log,
2434                ad,
2435                ad.droid.subscriptionGetDefaultDataSubId(),
2436                GEN_2G,
2437                voice_or_data=NETWORK_SERVICE_DATA):
2438            self.log.error("Device data does not attach to 2G.")
2439            return False
2440        if not verify_internet_connection(self.log, ad):
2441            self.log.error("No Internet access on default Data SIM.")
2442            return False
2443
2444        if ad.droid.telephonyGetDataConnectionState() != DATA_STATE_CONNECTED:
2445            self.log.error("Data Connection State should be connected.")
2446            return False
2447        # TODO: Check Data state for non-active subId.
2448
2449        try:
2450            self.log.info("Disable Data on Non-Active Sub ID")
2451            ad.droid.telephonyToggleDataConnectionForSubscription(
2452                non_active_sub_id, False)
2453            # TODO: Check Data state for non-active subId.
2454            if ad.droid.telephonyGetDataConnectionState(
2455            ) != DATA_STATE_CONNECTED:
2456                self.log.error("Data Connection State should be connected.")
2457                return False
2458        finally:
2459            self.log.info("Enable Data on Non-Active Sub ID")
2460            ad.droid.telephonyToggleDataConnectionForSubscription(
2461                non_active_sub_id, True)
2462        return True
2463
2464    def file_download_stress(self):
2465        failure = 0
2466        total_count = 0
2467        self.result_info = collections.defaultdict(int)
2468        dut = self.android_devices[0]
2469        self.number_of_devices = 1
2470        self.max_sleep_time = int(self.user_params.get("max_sleep_time", 1200))
2471        #file_names = ["5MB", "10MB", "20MB", "50MB", "200MB", "512MB", "1GB"]
2472        file_names = ["5MB", "10MB", "20MB", "50MB", "200MB", "512MB"]
2473        while total_count < self.stress_test_number:
2474            total_count += 1
2475            try:
2476                dut.log.info(dict(self.result_info))
2477                selection = random.randrange(0, len(file_names))
2478                file_name = file_names[selection]
2479                self.result_info["Total %s file download" % file_name] += 1
2480                if not active_file_download_test(self.log, dut, file_name):
2481                    self.result_info["%s file download failure" %
2482                                     file_name] += 1
2483                    failure += 1
2484                    dut.take_bug_report("%s_failure_%s" % (self.test_name,
2485                                                           failure),
2486                                        time.strftime("%m-%d-%Y-%H-%M-%S"))
2487                    self.dut.droid.goToSleepNow()
2488                    time.sleep(random.randrange(0, self.max_sleep_time))
2489            except Exception as e:
2490                self.log.error("Exception error %s", str(e))
2491                self.result_info["Exception Errors"] += 1
2492            dut.log.info("File download test failure: %s/%s", failure,
2493                         total_count)
2494        if failure / total_count > 0.1:
2495            dut.log.error("File download test failure: %s/%s", failure,
2496                          total_count)
2497            return False
2498        return True
2499
2500    @test_tracker_info(uuid="5381a6fa-6771-4b00-a0d6-4a3891a6dba8")
2501    @TelephonyBaseTest.tel_test_wrap
2502    def test_file_download_stress_default(self):
2503        """File download stress test
2504
2505        Steps:
2506        1. Download a file random picked.
2507        2. Device sleep for sometime and Repeat 1.
2508
2509        Expected Results:
2510        Total download failure rate is less than 10%.
2511
2512        Returns:
2513            True if success.
2514            False if failed.
2515        """
2516        return self.file_download_stress()
2517
2518    @test_tracker_info(uuid="c9970955-123b-467c-afbb-95ec8f99e9b7")
2519    def test_file_download_with_mobile_data_usage_limit_set(self):
2520        """ Steps:
2521
2522        1. Set the data usage limit to current data usage + 9MB
2523        2. Download 5MB file from internet.
2524        3. The first file download should succeed
2525        4. The second file download should fail
2526
2527        """
2528        dut = self.android_devices[0]
2529        self.number_of_devices = 1
2530        ensure_phones_default_state(self.log, [dut])
2531        subscriber_id = dut.droid.telephonyGetSubscriberId()
2532        old_data_usage = get_mobile_data_usage(dut, subscriber_id)
2533
2534        # set data usage limit to current usage limit + 10MB
2535        data_limit = old_data_usage + 9 * 1000 * 1000
2536        set_mobile_data_usage_limit(dut, data_limit, subscriber_id)
2537
2538        # download file - size 5MB twice
2539        try:
2540            for _ in range(2):
2541                if not active_file_download_test(self.log, dut, "5MB", "curl"):
2542                    if get_mobile_data_usage(
2543                            dut, subscriber_id) + 5 * 1000 * 1000 < data_limit:
2544                        dut.log.error(
2545                            "Fail to download file when mobile data usage is"
2546                            " below data usage limit")
2547                        return False
2548                    else:
2549                        dut.log.info(
2550                            "Download fails as expected due to data limit reached"
2551                        )
2552                else:
2553                    if get_mobile_data_usage(dut, subscriber_id) < data_limit:
2554                        dut.log.info(
2555                            "Download file succeed when mobile data usage is"
2556                            " below data usage limit")
2557                    else:
2558                        dut.log.error(
2559                            "Download should fail due to data limit reached")
2560                        return False
2561            return True
2562        finally:
2563            remove_mobile_data_usage_limit(dut, subscriber_id)
2564
2565
2566    def _test_data_stall_detection_recovery(self, nw_type="cellular",
2567                                            validation_type="detection"):
2568        dut = self.android_devices[0]
2569        self.number_of_devices = 1
2570
2571        try:
2572            cmd = ('ss -l -p -n | grep "tcp.*droid_script" | tr -s " " '
2573                   '| cut -d " " -f 5 | sed s/.*://g')
2574            sl4a_port = dut.adb.shell(cmd)
2575            ensure_phones_default_state(self.log, [dut])
2576            if nw_type == "wifi":
2577                if not ensure_wifi_connected(self.log, dut,
2578                                self.wifi_network_ssid, self.wifi_network_pass):
2579                    return False
2580
2581            if not test_data_browsing_success_using_sl4a(self.log, dut):
2582                dut.log.error("Browsing failed before the test, aborting!")
2583                return False
2584
2585            begin_time = get_device_epoch_time(dut)
2586            break_internet_except_sl4a_port(dut, sl4a_port)
2587
2588            if not test_data_browsing_failure_using_sl4a(self.log, dut):
2589                dut.log.error("Browsing success even after breaking internet, "\
2590                              "aborting!")
2591                return False
2592
2593            if not check_data_stall_detection(dut):
2594                dut.log.error("NetworkMonitor unable to detect Data Stall")
2595
2596            if not check_network_validation_fail(dut, begin_time):
2597                dut.log.error("Unable to detect NW validation fail")
2598                return False
2599
2600            if validation_type == "recovery":
2601                if not check_data_stall_recovery(dut, begin_time):
2602                    dut.log.error("Recovery was not triggerred")
2603                    return False
2604
2605            resume_internet_with_sl4a_port(dut, sl4a_port)
2606            time.sleep(10)
2607
2608            if not test_data_browsing_success_using_sl4a(self.log, dut):
2609                dut.log.error("Browsing failed after resuming internet")
2610                return False
2611            return True
2612        finally:
2613            resume_internet_with_sl4a_port(dut, sl4a_port)
2614
2615
2616    def _test_airplane_mode_stress(self):
2617        ad = self.android_devices[0]
2618        self.number_of_devices = 1
2619        total_iteration = self.stress_test_number
2620        fail_count = collections.defaultdict(int)
2621        current_iteration = 1
2622        for i in range(1, total_iteration + 1):
2623            msg = "Airplane mode test Iteration: <%s> / <%s>" % (i, total_iteration)
2624            self.log.info(msg)
2625            if not airplane_mode_test(self.log, ad):
2626                fail_count["apm_run"] += 1
2627                ad.log.error(">----Iteration : %d/%d failed.----<",
2628                             i, total_iteration)
2629            ad.log.info(">----Iteration : %d/%d succeeded.----<",
2630                        i, total_iteration)
2631            current_iteration += 1
2632        test_result = True
2633        for failure, count in fail_count.items():
2634            if count:
2635                ad.log.error("%s: %s %s failures in %s iterations",
2636                             self.test_name, count, failure,
2637                             total_iteration)
2638                test_result = False
2639        return test_result
2640
2641
2642    @test_tracker_info(uuid="3a82728f-18b5-4a35-9eab-4e6cf55271d9")
2643    @TelephonyBaseTest.tel_test_wrap
2644    def test_apm_toggle_stress(self):
2645        """ Test airplane mode toggle
2646
2647        1. Start with airplane mode off
2648        2. Toggle airplane mode on
2649        3. Toggle airplane mode off
2650        4. Repeat above steps
2651
2652        Returns:
2653            True if pass; False if fail.
2654        """
2655        return self._test_airplane_mode_stress()
2656
2657
2658    @test_tracker_info(uuid="fda33416-698a-408f-8ddc-b5cde13b1f83")
2659    @TelephonyBaseTest.tel_test_wrap
2660    def test_data_stall_detection_cellular(self):
2661        """ Data Stall Detection Testing
2662
2663        1. Ensure device is camped, browsing working fine
2664        2. Break Internet access, browsing should fail
2665        3. Check for Data Stall Detection
2666
2667        """
2668        return self._test_data_stall_detection_recovery(nw_type="cellular")
2669
2670
2671    @test_tracker_info(uuid="a57891d6-7892-46c7-8bca-23cd2cca8552")
2672    @TelephonyBaseTest.tel_test_wrap
2673    def test_data_stall_detection_wifi(self):
2674        """ Data Stall Detection Testing
2675
2676        1. Ensure device is connected to WiFi, browsing working fine
2677        2. Break Internet access, browsing should fail
2678        3. Check for Data Stall Detection
2679
2680        """
2681        return self._test_data_stall_detection_recovery(nw_type="wifi")
2682
2683
2684    @test_tracker_info(uuid="16d3f123-cac3-45a9-a2e5-c01bab7044d4")
2685    @TelephonyBaseTest.tel_test_wrap
2686    def test_data_stall_recovery_cellular(self):
2687        """ Data Stall Recovery Testing
2688
2689        1. Ensure device is camped, browsing working fine
2690        2. Break Internet access, browsing should fail
2691        3. Check for Data Stall Detection
2692        4. Check for Data Stall Recovery
2693
2694        """
2695        return self._test_data_stall_detection_recovery(nw_type="cellular",
2696                                                validation_type="recovery")
2697
2698    @test_tracker_info(uuid="d705d653-c810-42eb-bd07-3313f99be2fa")
2699    @TelephonyBaseTest.tel_test_wrap
2700    def test_browsing_4g(self):
2701        ad = self.android_devices[0]
2702        self.number_of_devices = 1
2703
2704        self.log.info("Connect to LTE and verify internet connection.")
2705        if not phone_setup_4g(self.log, ad):
2706            return False
2707        if not verify_internet_connection(self.log, ad):
2708            return False
2709
2710        return browsing_test(self.log, self.android_devices[0])
2711
2712    @test_tracker_info(uuid="71088cb1-5ccb-4d3a-8e6a-03fac9bf31cc")
2713    @TelephonyBaseTest.tel_test_wrap
2714    def test_browsing_wifi(self):
2715        ad = self.android_devices[0]
2716        self.number_of_devices = 1
2717
2718        self.log.info("Connect to Wi-Fi and verify internet connection.")
2719        if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
2720                                     self.wifi_network_pass):
2721            return False
2722        if not wait_for_wifi_data_connection(self.log, ad, True):
2723            return False
2724        if not verify_internet_connection(self.log, ad):
2725            return False
2726
2727        return browsing_test(self.log, self.android_devices[0], wifi_ssid=self.wifi_network_ssid)
2728
2729    def _test_sync_time_from_network(self, ad, data_on=True):
2730        """ Verifies time recovered by nitz service
2731
2732        1. Toggle mobile data
2733        2. Toggle off network time synchronization
2734        3. Change device time to FAKE_DATE_TIME: Jan,2,2019 03:04:05
2735        4. Toggle on network time synchronization
2736        5. Verify the year is changed back.
2737        6. Recover mobile data
2738
2739        Args:
2740            ad: android device object
2741            data_on: conditional mobile data on or off
2742
2743        Returns:
2744            True if pass; False if fail.
2745        """
2746        if not(data_on):
2747            ad.log.info("Disable mobile data.")
2748            ad.droid.telephonyToggleDataConnection(False)
2749        set_time_sync_from_network(ad, "disable")
2750        ad.log.info("Set device time to Jan,2,2019 03:04:05")
2751        datetime_handle(ad, 'set', set_datetime_value = FAKE_DATE_TIME)
2752        datetime_before_sync = datetime_handle(ad, 'get')
2753        ad.log.info("Got before sync datetime from device: %s",
2754                        datetime_before_sync)
2755        device_year = datetime_handle(ad, 'get', get_year = True)
2756
2757        if (device_year != FAKE_YEAR):
2758            raise signals.TestSkip("Set device time failed, skip test.")
2759        set_time_sync_from_network(ad, "enable")
2760        datetime_after_sync = datetime_handle(ad, "get")
2761        ad.log.info("Got after sync datetime from device: %s",
2762                        datetime_after_sync)
2763        device_year = datetime_handle(ad, "get", get_year = True)
2764
2765        if not(data_on):
2766            ad.log.info("Enabling mobile data.")
2767            ad.droid.telephonyToggleDataConnection(True)
2768
2769        if (device_year != FAKE_YEAR):
2770            self.record_data({
2771                "Test Name": "test_sync_time_from_network",
2772                "sponge_properties": {
2773                    "result": "pass",
2774                },
2775            })
2776            return True
2777        else:
2778            return False
2779
2780    @test_tracker_info(uuid="1017b655-5d79-44d2-86ff-675c69aec26b")
2781    @TelephonyBaseTest.tel_test_wrap
2782    def test_sync_time_from_network(self):
2783        """ Test device time recovered by nitz service
2784
2785        1. Toggle off network time synchronization
2786        2. Change device time to FAKE_DATE_TIME.
2787        3. Toggle on network time synchronization
2788        4. Verify the year is changed back.
2789
2790        """
2791        ad = self.android_devices[0]
2792        self.number_of_devices = 1
2793
2794        wifi_toggle_state(ad.log, ad, False)
2795        return self._test_sync_time_from_network(ad)
2796
2797    @test_tracker_info(uuid="46d170c6-a632-4124-889b-96caa0e641da")
2798    @TelephonyBaseTest.tel_test_wrap
2799    def test_sync_time_from_network_data_off(self):
2800        """ Test device time recovered by nitz service
2801
2802        1. Toggle off mobile data
2803        2. Toggle off network time synchronization
2804        3. Change device time to FAKE_DATE_TIME.
2805        4. Toggle on network time synchronization
2806        5. Verify the year is changed back.
2807
2808        """
2809        ad = self.android_devices[0]
2810        self.number_of_devices = 1
2811
2812        wifi_toggle_state(ad.log, ad, False)
2813        return self._test_sync_time_from_network(ad, data_on=False)
2814
2815    @test_tracker_info(uuid="2d739779-3beb-4e6e-8396-84f28e626379")
2816    @TelephonyBaseTest.tel_test_wrap
2817    def test_reboot_4g(self):
2818        ad = self.android_devices[0]
2819        self.number_of_devices = 1
2820
2821        self.log.info("Connect to LTE and verify internet connection.")
2822        if not phone_setup_4g(self.log, ad):
2823            return False
2824        if not verify_internet_connection(self.log, ad):
2825            return False
2826
2827        return reboot_test(self.log, ad)
2828
2829    @test_tracker_info(uuid="5ce671f7-c2a4-46aa-a9f2-e5571c144fad")
2830    @TelephonyBaseTest.tel_test_wrap
2831    def test_reboot_3g(self):
2832        ad = self.android_devices[0]
2833        self.number_of_devices = 1
2834
2835        self.log.info("Connect to 3G and verify internet connection.")
2836        if not phone_setup_3g(self.log, ad):
2837            return False
2838        if not verify_internet_connection(self.log, ad):
2839            return False
2840
2841        return reboot_test(self.log, ad)
2842
2843    @test_tracker_info(uuid="9e094f0e-7bef-479e-a5fa-a6bfa95289a5")
2844    @TelephonyBaseTest.tel_test_wrap
2845    def test_reboot_wifi(self):
2846        ad = self.android_devices[0]
2847        self.number_of_devices = 1
2848
2849        self.log.info("Connect to Wi-Fi and verify internet connection.")
2850        if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
2851                                     self.wifi_network_pass):
2852            return False
2853        if not wait_for_wifi_data_connection(self.log, ad, True):
2854            return False
2855        if not verify_internet_connection(self.log, ad):
2856            return False
2857
2858        return reboot_test(self.log, ad, wifi_ssid=self.wifi_network_ssid)
2859
2860    """ Tests End """
2861