1from acts import asserts 2from acts import base_test 3from acts.test_decorators import test_tracker_info 4from acts.test_utils.net import net_test_utils as nutils 5from acts.test_utils.wifi import wifi_test_utils as wutils 6from scapy.all import get_if_list 7from scapy.all import get_if_raw_hwaddr 8 9DUMSYS_CMD = "dumpsys connectivity tethering" 10UPSTREAM_WANTED_STRING = "Upstream wanted" 11CURRENT_UPSTREAM_STRING = "Current upstream interface" 12SSID = wutils.WifiEnums.SSID_KEY 13 14 15class UsbTetheringTest(base_test.BaseTestClass): 16 """Tests for tethering.""" 17 18 def setup_class(self): 19 self.dut = self.android_devices[0] 20 self.USB_TETHERED = False 21 22 nutils.verify_lte_data_and_tethering_supported(self.dut) 23 req_params = ("wifi_network",) 24 self.unpack_userparams(req_params) 25 26 def teardown_class(self): 27 nutils.stop_usb_tethering(self.dut) 28 self.USB_TETHERED = False 29 wutils.reset_wifi(self.dut) 30 31 def on_fail(self, test_name, begin_time): 32 self.dut.take_bug_report(test_name, begin_time) 33 34 @test_tracker_info(uuid="140a064b-1ab0-4a92-8bdb-e52dde03d5b8") 35 def test_usb_tethering_over_wifi(self): 36 """Tests USB tethering over wifi. 37 38 Steps: 39 1. Connects to a wifi network 40 2. Enables USB tethering 41 3. Verifies wifi is preferred upstream over data connection 42 """ 43 44 wutils.start_wifi_connection_scan_and_ensure_network_found( 45 self.dut, self.wifi_network[SSID]) 46 wutils.wifi_connect(self.dut, self.wifi_network) 47 wifi_network = self.dut.droid.connectivityGetActiveNetwork() 48 self.log.info("wifi network %s" % wifi_network) 49 50 iflist_before = get_if_list() 51 nutils.start_usb_tethering(self.dut) 52 self.USB_TETHERED = True 53 self.iface = nutils.wait_for_new_iface(iflist_before) 54 self.real_hwaddr = get_if_raw_hwaddr(self.iface) 55 56 output = self.dut.adb.shell(DUMSYS_CMD) 57 for line in output.split("\n"): 58 if UPSTREAM_WANTED_STRING in line: 59 asserts.assert_true("true" in line, "Upstream interface is not active") 60 self.log.info("Upstream interface is active") 61 if CURRENT_UPSTREAM_STRING in line: 62 asserts.assert_true("wlan" in line, "WiFi is not the upstream " 63 "interface") 64 self.log.info("WiFi is the upstream interface") 65 66