Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get WiFi security (NONE, WEP, WPA, WPA2) from Android WifiConfiguration entry?

I need to get security type from WifiConfiguration entry. Is it possible?

String getSecurityType(WifiConfiguration conf) {
}

returning values "NONE", "WEP", "WPA", "WPA2"

For those who think it's a duplicate question: I want to get information from WiFiConfiguration object and not from ScanResult object. It's not the same!

like image 718
Seraphim's Avatar asked Jan 19 '15 10:01

Seraphim's


People also ask

How do I know what security My Wi-Fi is on Android?

How to Check Your Wi-Fi Security Type in Android. To check on an Android phone, go into Settings, then open the Wi-Fi category. Select the router you're connected to and view its details. It will state what security type your connection is.

How do I connect my WPA2 Personal to Wi-Fi?

Using WPA2-Personal (PSK)Once you find the wireless security settings, select WPA2 security and AES encryption. Then enter a Pre-Shared Key or Passphrase of 8 to 63 alphanumeric characters. The longer and more complex the more secure. Try to upper and lower case letters and numbers.

How do I enable WPA3 on Android?

To enable WPA3-Personal, WPA3-Enterprise, and Wi-Fi Enhanced Open in the Android framework: WPA3-Personal: Include the CONFIG_SAE compilation option in the wpa_supplicant configuration file. WPA3-Enterprise: Include the CONFIG_SUITEB192 and CONFIG_SUITEB compilation options in the wpa_supplicant configuration file.


1 Answers

I can do it, simply:

import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
import android.net.wifi.WifiConfiguration.KeyMgmt;

public static final int SECURITY_NONE = 0;
public static final int SECURITY_WEP = 1;
public static final int SECURITY_PSK = 2;
public static final int SECURITY_EAP = 3;

public static int getSecurity(WifiConfiguration config) {
    if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) 
        return SECURITY_PSK;

    if (config.allowedKeyManagement.get(KeyMgmt.WPA_EAP) || config.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) 
        return SECURITY_EAP;

    return (config.wepKeys[0] != null) ? SECURITY_WEP : SECURITY_NONE;
}

so...

public static String getSecurityType(WifiConfiguration config) {
    switch (getSecurity(config)) {
        case SECURITY_WEP:
            return "WEP";
        case SECURITY_PSK:
            if (wifiConfiguration.allowedProtocols.get(WifiConfiguration.Protocol.RSN))
                return "WPA2";
            else
                return "WPA";
        default:
            return "NONE";
    }
}
like image 90
Seraphim's Avatar answered Oct 26 '22 22:10

Seraphim's