2

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()?

Community
  • 1
  • 1
Kevin Krumwiede
  • 9,868
  • 4
  • 34
  • 82
  • Possible duplicate of http://stackoverflow.com/questions/6866153/android-determine-security-type-of-wifi-networks-in-range-without-connecting-t – Kristy Welsh Jun 15 '15 at 19:27
  • @KristyWelsh Not a duplicate. That question deals with `WifiManager#getScanResults()`, not `WifiManager#getConfiguredNetworks()`. – Kevin Krumwiede Jun 15 '15 at 20:32
  • Do you wish to check keyManagement ? – Sahil Bahl Jun 18 '15 at 06:27
  • @SahilBahl I don't know. Hence my question. – Kevin Krumwiede Jun 29 '15 at 14:03
  • What was the problem with http://stackoverflow.com/questions/6866153/android-determine-security-type-of-wifi-networks-in-range-without-connecting-t – Sahil Bahl Jun 29 '15 at 17:18
  • @SahilBahl If you're referring to [this answer](http://stackoverflow.com/a/19567423/1953590), the first method is similar to the code in the Q&A I linked. It won't work because the `wepKeys` field will not be populated. The other answers deal with `ScanResult`, not `WifiConfiguration`. – Kevin Krumwiede Jun 29 '15 at 17:49

2 Answers2

0

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";
}
Kevin Krumwiede
  • 9,868
  • 4
  • 34
  • 82
0

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.

pjc
  • 240
  • 5
  • 14