Java 类android.net.wifi.WifiConfiguration.KeyMgmt 实例源码
项目:wifi-password-android
文件:Patch.java
private String getWiFiPassword(Context context, int networkId) {
final WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
@SuppressWarnings("unchecked")
final List<WifiConfiguration> list = (List<WifiConfiguration>) XposedHelpers.callMethod(wifiManager, "getPrivilegedConfiguredNetworks");
String pwd;
for (WifiConfiguration config : list) {
if (config.networkId == networkId) {
if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
pwd = config.preSharedKey;
} else {
pwd = config.wepKeys[config.wepTxKeyIndex];
}
if (pwd != null) {
return pwd.replaceAll("^\"|\"$", "");
}
}
}
return null;
}
项目:wifiglue
文件:WifiApManager.java
public boolean setWifiApEnabled(boolean enabled) {
boolean ok = false;
if (enabled) {
savedApConfig_ = getWifiApConfiguration();
ok = setWifiApEnabled(wifiConfig, enabled);
}
else {
// return to previous settings
if (savedApConfig_.SSID.isEmpty() || savedApConfig_.SSID.equals(wifiConfig.SSID)) {
// in case of no previous settings or error where
// previous settings are the same as current settings AndroidAP with no
// password
savedApConfig_.SSID = "AndroidAP";
savedApConfig_.allowedKeyManagement.set(KeyMgmt.NONE);
}
restoreSavedAp_ = true;
// disabling
ok = setWifiApEnabled(wifiConfig, enabled);
}
return ok;
}
项目:wifiglue
文件:WifiApManager.java
public boolean setWifiApEnabled(String ssid, String pwd, boolean enabled) {
wifiConfig.SSID = ssid;
Wifi.setupSecurity(wifiConfig, Wifi.WPA, pwd);
boolean ok = false;
if (enabled) {
savedApConfig_ = getWifiApConfiguration();
ok = setWifiApEnabled(wifiConfig, enabled);
}
else {
// return to previous settings
if (savedApConfig_.SSID.isEmpty() || savedApConfig_.SSID.equals(wifiConfig.SSID)) {
// in case of no previous settings or error where
// previous settings are the same as current settings AndroidAP with no
// password
savedApConfig_.SSID = "AndroidAP";
savedApConfig_.allowedKeyManagement.set(KeyMgmt.NONE);
}
restoreSavedAp_ = true;
// disabling
ok = setWifiApEnabled(wifiConfig, enabled);
}
return ok;
}
项目:YiZhi
文件:NetworkConnectionUtils.java
/**
* 连接指定
*
* @param manager
* @param wifiSSID
* @return
*/
public static boolean connectToSocketWifi(WifiManager manager, String wifiSSID) {
LogUtils.i("要连接的socket wifi====>" + wifiSSID);
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = "\"" + wifiSSID + "\"";
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.NONE);
wifiConfiguration.wepKeys[0] = "\"" + "\""; //小米手机MIUI7/华为EMUI4.1 需要webKey
int networkId = manager.addNetwork(wifiConfiguration);
if (networkId != -1) {
manager.enableNetwork(networkId, true);
e("连接设备成功");
return true;
} else {
e("第一次连接失败,尝试第二次。");
WifiConfiguration wifiConfiguration2 = new WifiConfiguration();
wifiConfiguration2.SSID = "\"" + wifiSSID + "\"";
//wifiConfiguration.wepKeys[0] = "\"" + "\"";//去掉webKey //小米手机MIUI8不能有webKey
wifiConfiguration2.allowedKeyManagement.set(KeyMgmt.NONE);
networkId = manager.addNetwork(wifiConfiguration2);
if (networkId != -1) {
manager.enableNetwork(networkId, true);
e("连接设备成功");
return true;
}
e("连接设备失败");
}
return false;
}
项目:YiZhi
文件:NetworkConnectionUtils.java
/**
* 获取要连接的wifi节点各个配置选项的加密类型
*
* @param ssid
* @return wifiConfiguration
*/
public static WifiConfiguration getWifiConfiguration(WifiManager manager, String ssid, String
password) {
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = "\"" + ssid + "\"";
List<ScanResult> list = manager.getScanResults();
for (ScanResult scResult : list) {
if (ssid.equals(scResult.SSID)) {
String capabilities = scResult.capabilities;
LogUtils.i("capabilities=" + capabilities);
if (capabilities.contains("WEP") || capabilities.contains("wep")) {
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
wifiConfiguration.preSharedKey = "\"" + password + "\"";
LogUtils.i("wep");
} else if (capabilities.contains("WPA") || capabilities.contains("wpa")) {
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
wifiConfiguration.preSharedKey = "\"" + password + "\"";
LogUtils.i("wpa");
} else {
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.NONE);
LogUtils.i("none");
}
}
}
return wifiConfiguration;
}
项目:IMKBaseFrameworkLibrary
文件:WifiOpenHelper.java
public static int getSecurity(WifiConfiguration config) {
if (config.wepKeys[0] != null) {
return SECURITY_WEP;
}
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_OR_IEEE8021X;
}
return SECURITY_NONE;
}
项目:AndroidSettingDemoAP
文件:AccessPoint.java
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;
}
项目:AndroidSettingDemoAP
文件:AccessPoint.java
/**
* Generate and save a default wifiConfiguration with common values. Can
* only be called for unsecured networks.
*
* @hide
*/
protected void generateOpenNetworkConfig() {
if (security != SECURITY_NONE)
throw new IllegalStateException();
if (mConfig != null)
return;
mConfig = new WifiConfiguration();
mConfig.SSID = AccessPoint.convertToQuotedString(ssid);
mConfig.allowedKeyManagement.set(KeyMgmt.NONE);
}
项目:Fon
文件:FonManService.java
private static boolean isInsecure(final WifiConfiguration wc) {
for (final String s : wc.wepKeys) {
if (s != null) {
return false;
}
}
return wc.allowedKeyManagement.get(KeyMgmt.NONE);
}
项目:SmartLockScreen
文件:WiFiEnvironmentVariable.java
/**
* Gets the security type of a WifiConfiguration
* @param config WifiConfiguration whose security is to be found out
* @return security of the given WifiConfiguration
*/
public static String 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;
}
项目:WifiConnecter
文件:WiFi.java
/**
* @return The security of a given {@link WifiConfiguration}.
*/
static public String getWifiConfigurationSecurity(WifiConfiguration wifiConfig) {
if (wifiConfig.allowedKeyManagement.get(KeyMgmt.NONE)) {
// If we never set group ciphers, wpa_supplicant puts all of them.
// For open, we don't set group ciphers.
// For WEP, we specifically only set WEP40 and WEP104, so CCMP
// and TKIP should not be there.
if (!wifiConfig.allowedGroupCiphers.get(GroupCipher.CCMP)
&& (wifiConfig.allowedGroupCiphers.get(GroupCipher.WEP40)
|| wifiConfig.allowedGroupCiphers.get(GroupCipher.WEP104))) {
return WEP;
} else {
return OPEN;
}
} else if (wifiConfig.allowedProtocols.get(Protocol.RSN)) {
return WPA2;
} else if (wifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_EAP)) {
return WPA_EAP;
} else if (wifiConfig.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
return IEEE8021X;
} else if (wifiConfig.allowedProtocols.get(Protocol.WPA)) {
return WPA;
} else {
Log.w(TAG, "Unknown security type from WifiConfiguration, falling back on open.");
return OPEN;
}
}
项目:nthu-cis
文件:WifiHelper.java
@Override
public void onReceive(Context context, Intent intent) {
WifiManager wfm = (WifiManager) who
.getSystemService(Context.WIFI_SERVICE);
if (wfm == null)
return;
List<ScanResult> results = wfm.getScanResults();
if (results == null)
return;
if (onWifiScanResultListener != null)
onWifiScanResultListener.run();
for (ScanResult result : results) {
if (wifiAPName.equals(result.SSID)) {
WifiConfiguration wfc = new WifiConfiguration();
wfc.SSID = "\"" + result.SSID + "\"";
wfc.allowedKeyManagement.set(KeyMgmt.NONE);
wfc.status = WifiConfiguration.Status.ENABLED;
int netId = wfm.addNetwork(wfc);
wfm.saveConfiguration();
wfm.enableNetwork(netId, true);
wfm.reconnect();
safeConnectivityReceiverRegister();
break;
}
}
}
项目:AlternateWifiMeshMessaging
文件:HostManager.java
private void createAccessPoint() {
wifiManager.setWifiEnabled(false);
wifiConfig = new WifiConfiguration();
wifiConfig.SSID = AP_NAME;
wifiConfig.allowedKeyManagement.set(KeyMgmt.NONE);
Method method;
try {
method = wifiManager.getClass().getMethod("setWifiApEnabled",
WifiConfiguration.class, boolean.class);
method.invoke(wifiManager, wifiConfig, true);
} catch (Exception e) {
Log.e(TAG, "", e);
}
}
项目:AlternateWifiMeshMessaging
文件:HostManager.java
private void closeAccessPoint() {
wifiManager.setWifiEnabled(false);
wifiConfig = new WifiConfiguration();
wifiConfig.SSID = AP_NAME;
wifiConfig.allowedKeyManagement.set(KeyMgmt.NONE);
Method method;
try {
method = wifiManager.getClass().getMethod("setWifiApEnabled",
WifiConfiguration.class, boolean.class);
method.invoke(wifiManager, wifiConfig, false);
} catch (Exception e) {
Log.e(TAG, "", e);
}
}
项目:AlternateWifiMeshMessaging
文件:HostManager.java
private void configureNetwork(ScanResult scanResult) {
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "\"" + scanResult.SSID + "\"";
wc.BSSID = scanResult.BSSID;
wc.status = WifiConfiguration.Status.DISABLED;
wc.priority = 40;
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wc.status = WifiConfiguration.Status.ENABLED;
wifiManager.addNetwork(wc);
wifiManager.saveConfiguration();
}
项目:wifiglue
文件:Wifi.java
/**
* @return The security of a given {@link WifiConfiguration}.
*/
static public String getWifiConfigurationSecurity(WifiConfiguration wifiConfig) {
if (wifiConfig.allowedKeyManagement.get(KeyMgmt.NONE)) {
// If we never set group ciphers, wpa_supplicant puts all of them.
// For open, we don't set group ciphers.
// For WEP, we specifically only set WEP40 and WEP104, so CCMP
// and TKIP should not be there.
if (!wifiConfig.allowedGroupCiphers.get(GroupCipher.CCMP)
&& (wifiConfig.allowedGroupCiphers.get(GroupCipher.WEP40) || wifiConfig.allowedGroupCiphers.get(GroupCipher.WEP104))) {
return WEP;
}
else {
return OPEN;
}
}
else if (wifiConfig.allowedProtocols.get(Protocol.RSN)) {
return WPA2;
}
else if (wifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_EAP)) {
return WPA_EAP;
}
else if (wifiConfig.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
return IEEE8021X;
}
else if (wifiConfig.allowedProtocols.get(Protocol.WPA)) {
return WPA;
}
else {
Log.w(TAG, "Unknown security type from WifiConfiguration, falling back on open.");
return OPEN;
}
}
项目:IMKBaseFrameworkLibrary
文件:WifiOpenHelper.java
public WifiConfiguration createWifiConfiguration(String SSID, String password, int type) {
WifiConfiguration config = new WifiConfiguration();
config.allowedAuthAlgorithms.clear();
config.allowedGroupCiphers.clear();
config.allowedKeyManagement.clear();
config.allowedPairwiseCiphers.clear();
config.allowedProtocols.clear();
config.SSID = "\"" + SSID + "\"";
WifiConfiguration tempConfig = this.isExsits(SSID);
if (tempConfig != null) {
mWifiManager.removeNetwork(tempConfig.networkId);
}
if (type == SECURITY_NONE) {
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
} else if (type == SECURITY_WEP) {
config.hiddenSSID = true;
config.wepKeys[0] = "\"" + password + "\"";
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
config.wepTxKeyIndex = 0;
} else if (type == SECURITY_PSK) {
config.preSharedKey = "\"" + password + "\"";
config.hiddenSSID = true;
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
config.status = WifiConfiguration.Status.ENABLED;
}
return config;
}
项目:GOpenSource_AppKit_Android_AS
文件:WifiAutoConnectManager.java
private WifiConfiguration createWifiInfo(String SSID, String Password,
WifiCipherType Type) {
WifiConfiguration config = new WifiConfiguration();
config.allowedAuthAlgorithms.clear();
config.allowedGroupCiphers.clear();
config.allowedKeyManagement.clear();
config.allowedPairwiseCiphers.clear();
config.allowedProtocols.clear();
config.SSID = "\"" + SSID + "\"";
// config.SSID = SSID;
// nopass
if (Type == WifiCipherType.WIFICIPHER_NOPASS) {
// config.wepKeys[0] = "";
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
// config.wepTxKeyIndex = 0;
}
// wep
if (Type == WifiCipherType.WIFICIPHER_WEP) {
if (!TextUtils.isEmpty(Password)) {
if (isHexWepKey(Password)) {
config.wepKeys[0] = Password;
} else {
config.wepKeys[0] = "\"" + Password + "\"";
}
}
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
config.allowedKeyManagement.set(KeyMgmt.NONE);
config.wepTxKeyIndex = 0;
}
// wpa
if (Type == WifiCipherType.WIFICIPHER_WPA) {
config.preSharedKey = "\"" + Password + "\"";
config.hiddenSSID = true;
config.allowedAuthAlgorithms
.set(WifiConfiguration.AuthAlgorithm.OPEN);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
config.allowedPairwiseCiphers
.set(WifiConfiguration.PairwiseCipher.TKIP);
// 此处需要修改否则不能自动重联
// config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedPairwiseCiphers
.set(WifiConfiguration.PairwiseCipher.CCMP);
config.status = WifiConfiguration.Status.ENABLED;
}
return config;
}
项目:GizOpenSource_AppKit_Android
文件:WifiAutoConnectManager.java
private WifiConfiguration createWifiInfo(String SSID, String Password,
WifiCipherType Type) {
WifiConfiguration config = new WifiConfiguration();
config.allowedAuthAlgorithms.clear();
config.allowedGroupCiphers.clear();
config.allowedKeyManagement.clear();
config.allowedPairwiseCiphers.clear();
config.allowedProtocols.clear();
config.SSID = "\"" + SSID + "\"";
// config.SSID = SSID;
// nopass
if (Type == WifiCipherType.WIFICIPHER_NOPASS) {
// config.wepKeys[0] = "";
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
// config.wepTxKeyIndex = 0;
}
// wep
if (Type == WifiCipherType.WIFICIPHER_WEP) {
if (!TextUtils.isEmpty(Password)) {
if (isHexWepKey(Password)) {
config.wepKeys[0] = Password;
} else {
config.wepKeys[0] = "\"" + Password + "\"";
}
}
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
config.allowedKeyManagement.set(KeyMgmt.NONE);
config.wepTxKeyIndex = 0;
}
// wpa
if (Type == WifiCipherType.WIFICIPHER_WPA) {
config.preSharedKey = "\"" + Password + "\"";
config.hiddenSSID = true;
config.allowedAuthAlgorithms
.set(WifiConfiguration.AuthAlgorithm.OPEN);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
config.allowedPairwiseCiphers
.set(WifiConfiguration.PairwiseCipher.TKIP);
// 此处需要修改否则不能自动重联
// config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedPairwiseCiphers
.set(WifiConfiguration.PairwiseCipher.CCMP);
config.status = WifiConfiguration.Status.ENABLED;
}
return config;
}
项目:Gizwits-SmartBuld_Android
文件:WifiAutoConnectManager.java
private WifiConfiguration createWifiInfo(String SSID, String Password, WifiCipherType Type) {
WifiConfiguration config = new WifiConfiguration();
config.allowedAuthAlgorithms.clear();
config.allowedGroupCiphers.clear();
config.allowedKeyManagement.clear();
config.allowedPairwiseCiphers.clear();
config.allowedProtocols.clear();
config.SSID = "\"" + SSID + "\"";
// nopass
if (Type == WifiCipherType.WIFICIPHER_NOPASS) {
// config.wepKeys[0] = "";
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
// config.wepTxKeyIndex = 0;
}
// wep
if (Type == WifiCipherType.WIFICIPHER_WEP) {
if (!TextUtils.isEmpty(Password)) {
if (isHexWepKey(Password)) {
config.wepKeys[0] = Password;
} else {
config.wepKeys[0] = "\"" + Password + "\"";
}
}
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
config.allowedKeyManagement.set(KeyMgmt.NONE);
config.wepTxKeyIndex = 0;
}
// wpa
if (Type == WifiCipherType.WIFICIPHER_WPA) {
config.preSharedKey = "\"" + Password + "\"";
config.hiddenSSID = true;
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
// 此处需要修改否则不能自动重联
// config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
config.status = WifiConfiguration.Status.ENABLED;
}
return config;
}
项目:gokit-android
文件:WifiAutoConnectManager.java
private WifiConfiguration createWifiInfo(String SSID, String Password,
WifiCipherType Type) {
WifiConfiguration config = new WifiConfiguration();
config.allowedAuthAlgorithms.clear();
config.allowedGroupCiphers.clear();
config.allowedKeyManagement.clear();
config.allowedPairwiseCiphers.clear();
config.allowedProtocols.clear();
config.SSID = "\"" + SSID + "\"";
// config.SSID = SSID;
// nopass
if (Type == WifiCipherType.WIFICIPHER_NOPASS) {
// config.wepKeys[0] = "";
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
// config.wepTxKeyIndex = 0;
}
// wep
if (Type == WifiCipherType.WIFICIPHER_WEP) {
if (!TextUtils.isEmpty(Password)) {
if (isHexWepKey(Password)) {
config.wepKeys[0] = Password;
} else {
config.wepKeys[0] = "\"" + Password + "\"";
}
}
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
config.allowedKeyManagement.set(KeyMgmt.NONE);
config.wepTxKeyIndex = 0;
}
// wpa
if (Type == WifiCipherType.WIFICIPHER_WPA) {
config.preSharedKey = "\"" + Password + "\"";
config.hiddenSSID = true;
config.allowedAuthAlgorithms
.set(WifiConfiguration.AuthAlgorithm.OPEN);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
config.allowedPairwiseCiphers
.set(WifiConfiguration.PairwiseCipher.TKIP);
// 此处需要修改否则不能自动重联
// config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedPairwiseCiphers
.set(WifiConfiguration.PairwiseCipher.CCMP);
config.status = WifiConfiguration.Status.ENABLED;
}
return config;
}
项目:TumCampusApp
文件:EduroamManager.java
/**
* Configures eduroam wifi connection
*
* @param lrzId User's LRZ-ID
* @param networkPass User's lrz password
* @return Returns true if configuration was successful, false otherwise
*/
public boolean configureEduroam(String lrzId, String networkPass) {
// Configure Wifi
boolean update = true;
WifiConfiguration conf = getEduroamConfig(mContext);
if (conf == null) {
update = false;
conf = new WifiConfiguration();
}
conf.SSID = "\"" + NETWORK_SSID + "\"";
conf.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
conf.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
conf.allowedGroupCiphers.set(GroupCipher.TKIP);
conf.allowedGroupCiphers.set(GroupCipher.CCMP);
conf.allowedGroupCiphers.set(GroupCipher.WEP40);
conf.allowedGroupCiphers.set(GroupCipher.WEP104);
conf.allowedPairwiseCiphers.set(PairwiseCipher.CCMP);
conf.allowedPairwiseCiphers.set(PairwiseCipher.TKIP);
conf.allowedProtocols.set(Protocol.RSN);
conf.status = WifiConfiguration.Status.ENABLED;
if (Build.VERSION.SDK_INT >= 18) {
setupEnterpriseConfigAPI18(conf, lrzId, networkPass);
} else {
if (!setupEnterpriseConfigOld(conf, lrzId, networkPass)) {
return false;
}
}
// Add eduroam to wifi networks
WifiManager wifiManager = (WifiManager) mContext.getApplicationContext()
.getSystemService(Context.WIFI_SERVICE);
int networkId;
if (update) {
networkId = wifiManager.updateNetwork(conf);
Utils.log("deleted " + conf.networkId);
} else {
networkId = wifiManager.addNetwork(conf);
}
Utils.log("added " + networkId);
//Check if update successful
if (networkId == -1) {
return false;
}
//Enable and exit
wifiManager.enableNetwork(networkId, true);
return true;
}