def check_passpoint_connection(self, passpoint_network): """Verify the device is automatically able to connect to the Passpoint network. Args: passpoint_network: SSID of the Passpoint network. """ ad = self.dut ad.ed.clear_all_events() wutils.start_wifi_connection_scan(ad) scan_results = ad.droid.wifiGetScanResults() # Wait for scan to complete. time.sleep(5) ssid = passpoint_network wutils.assert_network_in_list({WifiEnums.SSID_KEY: ssid}, scan_results) # Passpoint network takes longer time to connect than normal networks. # Every try comes with a timeout of 30s. Setting total timeout to 120s. wutils.wifi_passpoint_connect(self.dut, passpoint_network, num_of_tries=4) # Re-verify we are connected to the correct network. network_info = self.dut.droid.wifiGetConnectionInfo() if network_info[WifiEnums.SSID_KEY] != passpoint_network: raise signals.TestFailure("Device did not connect to the passpoint" " network.")
def test_scan(self): """Test wifi connection scan can start and find expected networks.""" wutils.wifi_toggle_state(self.dut, True) self.log.debug("Start regular wifi scan.") wutils.start_wifi_connection_scan(self.dut) wifi_results = self.dut.droid.wifiGetScanResults() self.log.debug("Scan results: %s", wifi_results) ssid = self.open_network[WifiEnums.SSID_KEY] wutils.assert_network_in_list({WifiEnums.SSID_KEY: ssid}, wifi_results)
def test_add_network(self): """Test wifi connection scan.""" ssid = self.open_network[WifiEnums.SSID_KEY] nId = self.dut.droid.wifiAddNetwork(self.open_network) asserts.assert_true(nId > -1, "Failed to add network.") configured_networks = self.dut.droid.wifiGetConfiguredNetworks() self.log.debug( ("Configured networks after adding: %s" % configured_networks)) wutils.assert_network_in_list({WifiEnums.SSID_KEY: ssid}, configured_networks)
def connect_to_wifi_network(self, network): """Connection logic for open and psk wifi networks. Args: params: Dictionary with network info. """ SSID = network[WifiEnums.SSID_KEY] self.dut.ed.clear_all_events() wutils.start_wifi_connection_scan(self.dut) scan_results = self.dut.droid.wifiGetScanResults() wutils.assert_network_in_list({WifiEnums.SSID_KEY: SSID}, scan_results) wutils.wifi_connect(self.dut, network, num_of_tries=3)
def connect_to_wifi_network(self, params): """Connection logic for open and psk wifi networks. Args: params: A tuple of network info and AndroidDevice object. """ network, ad = params droid = ad.droid ed = ad.ed SSID = network[WifiEnums.SSID_KEY] ed.clear_all_events() wutils.start_wifi_connection_scan(ad) scan_results = droid.wifiGetScanResults() wutils.assert_network_in_list({WifiEnums.SSID_KEY: SSID}, scan_results) wutils.wifi_connect(ad, network, num_of_tries=3)
def test_forget_network(self): ssid = self.open_network[WifiEnums.SSID_KEY] nId = self.dut.droid.wifiAddNetwork(self.open_network) asserts.assert_true(nId > -1, "Failed to add network.") configured_networks = self.dut.droid.wifiGetConfiguredNetworks() self.log.debug( ("Configured networks after adding: %s" % configured_networks)) wutils.assert_network_in_list({WifiEnums.SSID_KEY: ssid}, configured_networks) wutils.wifi_forget_network(self.dut, ssid) configured_networks = self.dut.droid.wifiGetConfiguredNetworks() for nw in configured_networks: asserts.assert_true( nw[WifiEnums.BSSID_KEY] != ssid, "Found forgotten network %s in configured networks." % ssid)
def connect_to_wifi(self, ad, network): """Connection logic for open and psk wifi networks. Args: ad: Android device object. network: A JSON dict of the WiFi network configuration. """ ad.ed.clear_all_events() wifi_utils.start_wifi_connection_scan(ad) scan_results = ad.droid.wifiGetScanResults() wifi_utils.assert_network_in_list( {WifiEnums.SSID_KEY: self.wifi_network_ssid}, scan_results) wifi_utils.wifi_connect(ad, network) self.log.debug("Connected to %s network on %s device" % (network[WifiEnums.SSID_KEY], ad.serial))
def connect_to_wifi_network_with_id(self, network_id, network_ssid): """Connect to the given network using network id and verify SSID. Args: network_id: int Network Id of the network. network_ssid: string SSID of the network. Returns: True if connect using network id was successful; False otherwise. """ self.dut.ed.clear_all_events() wutils.start_wifi_connection_scan(self.dut) scan_results = self.dut.droid.wifiGetScanResults() wutils.assert_network_in_list({WifiEnums.SSID_KEY: network_ssid}, scan_results) wutils.wifi_connect_by_id(self.dut, network_id) connect_data = self.dut.droid.wifiGetConnectionInfo() connect_ssid = connect_data[WifiEnums.SSID_KEY] self.log.debug("Expected SSID = %s Connected SSID = %s" % (network_ssid, connect_ssid)) if connect_ssid != network_ssid: return False return True