Java 类android.net.wifi.WifiConfiguration.Protocol 实例源码
项目: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;
}
}
项目: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;
}
}
项目: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;
}