def test_connect_failure_user_rejected(self):
        """
        Initiates a connection to network via network request with specific SSID
        which the user rejected.

        Steps:
        1. Send a network specifier with the specific SSID/credentials of
           WPA-PSK 5G network.
        2. Wait for platform to scan and find matching networks.
        3. Simulate user rejecting the network.
        4. Ensure that we get an instant onUnavailable callback.
        5. Simulate user fogetting the network from the UI.
        """
        network = self.wpa_psk_5g
        expected_ssid = network[WifiEnums.SSID_KEY]

        self.dut.droid.wifiStartTrackingStateChange()

        self.dut.droid.wifiRequestNetworkWithSpecifierWithTimeout(
            network, NETWORK_REQUEST_TIMEOUT_MS)
        self.dut.log.info("Sent network request with specifier %s", network)
        time.sleep(wifi_constants.NETWORK_REQUEST_CB_REGISTER_DELAY_SEC)
        self.dut.droid.wifiRegisterNetworkRequestMatchCallback()

        # Wait for the platform to scan and return a list of networks
        # matching the request
        try:
            matched_network = None
            for _ in [0, 3]:
                on_match_event = self.dut.ed.pop_event(
                    wifi_constants.WIFI_NETWORK_REQUEST_MATCH_CB_ON_MATCH, 30)
                asserts.assert_true(on_match_event,
                                    "Network request on match not received.")
                matched_scan_results = on_match_event["data"]
                self.dut.log.debug("Network request on match results %s",
                                   matched_scan_results)
                matched_network = wutils.match_networks(
                    {WifiEnums.SSID_KEY: network[WifiEnums.SSID_KEY]},
                    matched_scan_results)
                if matched_network:
                    break
            asserts.assert_true(matched_network,
                                "Target network %s not found" % network)

            # Send user rejection.
            self.dut.droid.wifiSendUserRejectionForNetworkRequestMatch()
            self.dut.log.info("Sent user rejection for network request %s",
                              expected_ssid)

            # Wait for the platform to raise unavailable callback
            # instantaneously.
            on_unavailable_event = self.dut.ed.pop_event(
                wifi_constants.WIFI_NETWORK_CB_ON_UNAVAILABLE,
                NETWORK_REQUEST_INSTANT_FAILURE_TIMEOUT_SEC)
            asserts.assert_true(on_unavailable_event,
                                "Network request on available not received.")
        except queue.Empty:
            asserts.fail("Expected events not returned")
        finally:
            self.dut.droid.wifiStopTrackingStateChange()
    def _find_reference_networks_no_attn(self):
        """ Verify that when ATTN set to 0, all reference networks
            show up in the scanned results

            Args:
            1. List of reference networks

            Returns:
            1. List of networks not found. Empty if all reference
               networks are found
        """
        found_networks = copy.deepcopy(self.target_networks)
        start_time = time.time()
        while (time.time() < start_time + SCAN_TIME):
            if not found_networks:
                break
            time.sleep(WAIT_TIME)
            scanned_networks = self.dut.droid.wifiGetScanResults()
            for net in self.target_networks:
                if net in found_networks:
                    result = wutils.match_networks(net, scanned_networks)
                    if result and result[0]['level'] > self.MIN_SIGNAL_LEVEL:
                        found_networks.remove(net)
                    elif result:
                        self.log.warn("Signal strength for %s is low: %sdBm" %
                                      (net, result[0]['level']))
        return found_networks
    def check_networks_after_autoupdate(self, networks):
        """Verify that all previously configured networks are presistent after
           reboot.

        Args:
            networks: List of network dicts.

        Return:
            None. Raises TestFailure.

        """
        network_info = self.dut.droid.wifiGetConfiguredNetworks()
        if len(network_info) != len(networks):
            msg = (
                "Number of configured networks before and after Auto-update "
                "don't match. \nBefore reboot = %s \n After reboot = %s" %
                (networks, network_info))
            raise signals.TestFailure(msg)
        current_count = 0
        # For each network, check if it exists in configured list after Auto-
        # update.
        for network in networks:
            exists = wutils.match_networks(
                {WifiEnums.SSID_KEY: network[WifiEnums.SSID_KEY]},
                network_info)
            if not len(exists):
                raise signals.TestFailure(
                    "%s network is not present in the"
                    " configured list after Auto-update" %
                    network[WifiEnums.SSID_KEY])
            # Get the new network id for each network after reboot.
            network[WifiEnums.NETID_KEY] = exists[0]['networkId']
Esempio n. 4
0
 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]
     condition = {WifiEnums.SSID_KEY: ssid}
     asserts.assert_true(wutils.match_networks(condition, wifi_results),
                         "Can not find expected network %s" % ssid)
Esempio n. 5
0
 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))
     condition = {WifiEnums.SSID_KEY: ssid}
     asserts.assert_true(
         wutils.match_networks(condition, configured_networks),
         ("Could not find expected network %s in configured "
          "networks.") % ssid)
    def add_network(self, ad, networks):
        """Add Wi-Fi networks to an Android device and verify the networks were
        added correctly

        Args:
            ad: the AndroidDevice object to add networks to.
            networks: a list of dicts, each dict represents a Wi-Fi network.
        """
        for network in networks:
            ret = ad.droid.wifiAddNetwork(network)
            asserts.assert_true(ret != 1, "Failed to add network %s" % network)
            configured_networks = ad.droid.wifiGetConfiguredNetworks()
            is_configured = wutils.match_networks(network, configured_networks)
            asserts.assert_true(
                is_configured,
                "Network %s was added but it's not in the configured list.")
    def confirm_softap_in_scan_results(self, ap_ssid):
        """Confirm the ap started by wifi tethering is seen in scan results.

        Args:
            ap_ssid: SSID of the ap we are looking for.
        """
        #TODO(silberst): debug and remove the extra scan before submitting this test
        wutils.start_wifi_connection_scan(self.dut_client)
        client_scan_results = self.dut_client.droid.wifiGetScanResults()
        wutils.start_wifi_connection_scan(self.dut_client)
        client_scan_results = self.dut_client.droid.wifiGetScanResults()
        for result in client_scan_results:
            self.log.debug("scan found: %s", result[wutils.WifiEnums.SSID_KEY])

        asserts.assert_true(wutils.match_networks(
                {wutils.WifiEnums.SSID_KEY: ap_ssid}, client_scan_results),
                "Did not find SSID in scan results")
    def test_connect_to_wpa_psk_2g_which_is_already_approved(self):
        """
        Initiates a connection to network via network request with specific SSID
        bypassing user approval.

        Steps:
        1. Send a network specifier with the specific SSID/credentials of
           WPA-PSK 2G network.
        2. Wait for platform to scan and find matching networks.
        3. Simulate user selecting the network.
        4. Ensure that the device connects to the network.
        5. Ensure we disconnect from the previous network.
        6. Send another network specifier with the specific
           SSID/BSSID/credentials of WPA-PSK 2G network.
        7. Ensure that the device bypasses user approval & connects to the
           same network.
        """
        # Complete flow for the first request.
        wutils.wifi_connect_using_network_request(self.dut, self.wpa_psk_2g,
                                                  self.wpa_psk_2g)
        # Release the request.
        self.dut.droid.wifiReleaseNetwork(self.wpa_psk_2g)
        # Ensure we disconnected from the network.
        wutils.wait_for_disconnect(self.dut)
        self.dut.log.info("Disconnected from network %s", self.wpa_psk_2g)
        self.dut.ed.clear_all_events()

        # Find bssid for the WPA-PSK 2G network.
        scan_results = self.dut.droid.wifiGetScanResults()
        match_results = wutils.match_networks(
            {WifiEnums.SSID_KEY: self.wpa_psk_2g[WifiEnums.SSID_KEY]},
            scan_results)
        asserts.assert_equal(len(match_results), 1,
                             "Cannot find bssid for WPA-PSK 2G network")
        bssid = match_results[0][WifiEnums.BSSID_KEY]
        # Send the second request with bssid.
        network_specifier_with_bssid = self.wpa_psk_2g.copy()
        network_specifier_with_bssid[WifiEnums.BSSID_KEY] = bssid
        self.dut.droid.wifiRequestNetworkWithSpecifier(
            network_specifier_with_bssid)
        self.dut.log.info("Sent network request with %r",
                          network_specifier_with_bssid)

        # Ensure we connected to second request without user approval.
        wutils.wait_for_connect(self.dut, self.wpa_psk_2g[WifiEnums.SSID_KEY])
    def check_hiddenSSID_in_scan(self, ap_ssid, max_tries=2):
        """Check if the ap started by wifi tethering is seen in scan results.

        Args:
            ap_ssid: SSID of the ap we are looking for.
            max_tries: Number of scans to try.
        Returns:
            True: if ap_ssid is found in scan results.
            False: if ap_ssid is not found in scan results.
        """
        for num_tries in range(max_tries):
            wutils.start_wifi_connection_scan(self.dut)
            scan_results = self.dut.droid.wifiGetScanResults()
            match_results = wutils.match_networks(
                {wutils.WifiEnums.SSID_KEY: ap_ssid}, scan_results)
            if len(match_results) > 0:
                return True
        return False
    def _find_network_after_setting_attn(self, target_network):
        """ Find network after setting attenuation

            Args:
            1. target_network to find in the scanned_results

            Returns:
            1. True if
               a. if max_attn is set and target_network not found
            2. False if not
        """
        start_time = time.time()
        while (time.time() < start_time + SCAN_TIME):
            time.sleep(WAIT_TIME)
            scanned_networks = self.dut.droid.wifiGetScanResults()
            result = wutils.match_networks(target_network, scanned_networks)
            if not result:
                return True
        return False
    def test_discovery(self):
        """Make sure all the expected 11mc BSSIDs are discovered properly, and
        they are all reported as 802.11mc Rtt Responder.

        Procedures:
            1. Scan for wifi networks.

        Expect:
            All the RTT networks show up in scan results and their
            "is80211McRTTResponder" is True.
            All the non-RTT networks show up in scan results and their
            "is80211McRTTResponder" is False.
        """
        wutils.start_wifi_connection_scan(self.dut)
        scan_results = self.dut.droid.wifiGetScanResults()
        self.log.debug(scan_results)
        for n in visible_networks:
            asserts.assert_true(wutils.match_networks(n, scan_results),
                                "Network %s was not discovered properly." % n)
        return True
Esempio n. 12
0
    def check_configstore_networks(self, networks):
        """Verify that all previously configured networks are presistent after
           reboot.

        Args:
            networks: List of network dicts.

        Return:
            None. Raises TestFailure.

        """
        network_info = self.dut.droid.wifiGetConfiguredNetworks()
        if len(network_info) != len(networks):
            msg = (
                "Length of configured networks before and after reboot don't"
                " match. \nBefore reboot = %s \n After reboot = %s" %
                (networks, network_info))
            raise signals.TestFailure(msg)
        current_count = 0
        # For each network, check if it exists in configured list after reboot
        for network in networks:
            exists = wutils.match_networks(
                {WifiEnums.SSID_KEY: network[WifiEnums.SSID_KEY]},
                network_info)
            if not len(exists):
                raise signals.TestFailure("%s network is not present in the"
                                          " configured list after reboot" %
                                          network[WifiEnums.SSID_KEY])
            # Get the new network id for each network after reboot.
            network[WifiEnums.NETID_KEY] = exists[0]['networkId']
            if exists[0]['status'] == 'CURRENT':
                current_count += 1
                # At any given point, there can only be one currently active
                # network, defined with 'status':'CURRENT'
                if current_count > 1:
                    raise signals.TestFailure("More than one network showing"
                                              "as 'CURRENT' after reboot")
    def test_connect_to_wpa_psk_2g_which_is_already_approved_but_then_forgot(
            self):
        """
        Initiates a connection to network via network request with specific SSID
        with user approval.

        Steps:
        1. Send a network specifier with the specific SSID/credentials of
           WPA-PSK 2G network.
        2. Wait for platform to scan and find matching networks.
        3. Simulate user selecting the network.
        4. Ensure that the device connects to the network.
        4. Simulate user fogetting the network from the UI.
        6. Ensure we disconnect from the previous network.
        7. Send another network specifier with the specific
           SSID/BSSID/credentials of WPA-PSK 2G network.
        8. Ensure that the device does not bypass user approval & connects to the
           same network with user approval. (This should also clear the blacklist)
        9. Send the same network specifier with the specific
           SSID/BSSID/credentials of WPA-PSK 2G network.
        10.Ensure that the device bypasses user approval now & connects to the
           same network.
        """
        # Complete flow for the first request.
        wutils.wifi_connect_using_network_request(self.dut, self.wpa_psk_2g,
                                                  self.wpa_psk_2g)

        # Simulate user forgeting the ephemeral network.
        self.dut.droid.wifiDisableEphemeralNetwork(
            self.wpa_psk_2g[WifiEnums.SSID_KEY])
        # Ensure we disconnected from the network.
        wutils.wait_for_disconnect(self.dut)
        self.dut.log.info("Disconnected from network %s", self.wpa_psk_2g)
        self.dut.ed.clear_all_events()
        # Release the first request.
        self.dut.droid.wifiReleaseNetwork(self.wpa_psk_2g)

        # Find bssid for the WPA-PSK 2G network.
        scan_results = self.dut.droid.wifiGetScanResults()
        match_results = wutils.match_networks(
            {WifiEnums.SSID_KEY: self.wpa_psk_2g[WifiEnums.SSID_KEY]},
            scan_results)
        asserts.assert_equal(len(match_results), 1,
                             "Cannot find bssid for WPA-PSK 2G network")
        bssid = match_results[0][WifiEnums.BSSID_KEY]
        # Send the second request with bssid.
        network_specifier_with_bssid = self.wpa_psk_2g.copy()
        network_specifier_with_bssid[WifiEnums.BSSID_KEY] = bssid
        self.dut.droid.wifiRequestNetworkWithSpecifier(
            network_specifier_with_bssid)
        self.dut.log.info("Sent network request with %r",
                          network_specifier_with_bssid)

        # Ensure that we did not connect bypassing user approval.
        assert_msg = "Device should not connect without user approval"
        asserts.assert_false(
            wutils.wait_for_connect(self.dut,
                                    self.wpa_psk_2g[WifiEnums.SSID_KEY],
                                    assert_on_fail=False), assert_msg)

        # Now complete the flow and ensure we connected to second request.
        wutils.wait_for_wifi_connect_after_network_request(
            self.dut, self.wpa_psk_2g)

        # Now make the same request again & ensure that we connect without user
        # approval.
        self.dut.droid.wifiRequestNetworkWithSpecifier(
            network_specifier_with_bssid)
        self.dut.log.info("Sent network request with %r",
                          network_specifier_with_bssid)
        wutils.wait_for_connect(self.dut, self.wpa_psk_2g[WifiEnums.SSID_KEY])