从 Android 5.0.0_r1-5.1.0_r1 开始,可接受的字段为“NONE”、“WPA”和“WEP”。似乎 null 或空值将解析为“NONE”,但我尚未确认。
这些字段直接映射到 ManagedProvisioning 项目 (AOSP) 中的 WifiConfig 类。
https://android.googlesource.com/platform/packages/apps/ManagedProvisioning/+/android-5.0.0_r7/src/com/android/managedprovisioning/WifiConfig.java
注意:安全类型直接在此类中定义,而不是使用 WifiConfiguration 类中的常量。
enum SecurityType {
NONE,
WPA,
WEP;
}
这是 WifiConfig 函数 (AOSP) 的 sn-p,显示了如何使用安全类型:
/**
* Adds a new WiFi network.
*/
public int addNetwork(String ssid, boolean hidden, String type, String password,
String proxyHost, int proxyPort, String proxyBypassHosts, String pacUrl) {
if (!mWifiManager.isWifiEnabled()) {
mWifiManager.setWifiEnabled(true);
}
WifiConfiguration wifiConf = new WifiConfiguration();
SecurityType securityType;
if (type == null || TextUtils.isEmpty(type)) {
securityType = SecurityType.NONE;
} else {
securityType = Enum.valueOf(SecurityType.class, type.toUpperCase());
}
// If we have a password, and no security type, assume WPA.
// TODO: Remove this when the programmer supports it.
if (securityType.equals(SecurityType.NONE) && !TextUtils.isEmpty(password)) {
securityType = SecurityType.WPA;
}
wifiConf.SSID = ssid;
wifiConf.status = WifiConfiguration.Status.ENABLED;
wifiConf.hiddenSSID = hidden;
switch (securityType) {
case NONE:
wifiConf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wifiConf.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
break;
case WPA:
updateForWPAConfiguration(wifiConf, password);
break;
case WEP:
updateForWEPConfiguration(wifiConf, password);
break;
}
updateForProxy(wifiConf, proxyHost, proxyPort, proxyBypassHosts, pacUrl);
int netId = mWifiManager.addNetwork(wifiConf);
if (netId != -1) {
// Setting disableOthers to 'true' should trigger a connection attempt.
mWifiManager.enableNetwork(netId, true);
mWifiManager.saveConfiguration();
}
return netId;
}
如果我们需要企业网络的凭据,我们似乎不走运。这让我有点莫名其妙,因为设备所有者功能是为 MDM 设计的。有时需要连接到企业网络!