Get security type from configured network?

820 views Asked by At

I'm looking for a way to get the security type from networks which are configured but not currently in range. That is, from a WifiConfiguration returned by WifiManager#getConfiguredNetworks() as opposed to WifiManager#getScanResults(). Naturally, this could only tell what security type was in use when the network was last in range. That is good enough for my purposes.

The docs for getConfiguredNetworks() state:

Only the following fields are filled in: networkId, SSID, BSSID, priority, allowedProtocols, allowedKeyManagement, allowedAuthAlgorithms, allowedPairwiseCiphers, allowedGroupCiphers

Therefore, the accepted answer to this question and others like it will not work because it depends on the wepKeys field. (It also doesn't have a switch case for its own SECURITY_EAP result.)

Is this possible using the limited information available from getConfiguredNetworks()?

2

There are 2 answers

0
Kevin Krumwiede On

This is my naïve solution. From what little I know of wifi security, I have a hunch that these conditions are necessary but insufficient to determine the security type. Maybe someone who knows more can elaborate.

private static String getSecurity(final WifiConfiguration network) {
    if(network.allowedGroupCiphers.get(GroupCipher.CCMP)) {
        return "WPA2";
    }
    else if(network.allowedGroupCiphers.get(GroupCipher.TKIP)) {
        return "WPA";
    }
    else if(network.allowedGroupCiphers.get(GroupCipher.WEP40)
            || network.allowedGroupCiphers.get(GroupCipher.WEP104)) {
        return "WEP";
    }
    else return "NONE";
}
0
pjc On

The configuration would only be in your Configuration list if you had added it. You are correct, the other methods won't work in this case. The only way I can figure you got here is that you had added the configuration when it was in range, but had used the Forget function later. Now that you are out of range, you can't use the ScanResult, but neither do you have the information in your configuration to determine what the security was anymore.