[Settings] Use WifiConfiguration#setSecurityParams
Use WifiConfiguration#setSecurityParams instead of manually initializing security params. Bug: 150889755 Test: Created new connections and manually connected to open, WPA2, WPA3, EAP and SUITE-B networks. Change-Id: I42f4c21a37428ee87be14f6ba09dc54fa327054a
This commit is contained in:
@@ -28,8 +28,6 @@ import android.net.ProxyInfo;
|
|||||||
import android.net.StaticIpConfiguration;
|
import android.net.StaticIpConfiguration;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
|
|
||||||
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
|
||||||
import android.net.wifi.WifiEnterpriseConfig;
|
import android.net.wifi.WifiEnterpriseConfig;
|
||||||
import android.net.wifi.WifiEnterpriseConfig.Eap;
|
import android.net.wifi.WifiEnterpriseConfig.Eap;
|
||||||
import android.net.wifi.WifiEnterpriseConfig.Phase2;
|
import android.net.wifi.WifiEnterpriseConfig.Phase2;
|
||||||
@@ -638,13 +636,11 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
|
|
||||||
switch (mAccessPointSecurity) {
|
switch (mAccessPointSecurity) {
|
||||||
case AccessPoint.SECURITY_NONE:
|
case AccessPoint.SECURITY_NONE:
|
||||||
config.allowedKeyManagement.set(KeyMgmt.NONE);
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OPEN);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AccessPoint.SECURITY_WEP:
|
case AccessPoint.SECURITY_WEP:
|
||||||
config.allowedKeyManagement.set(KeyMgmt.NONE);
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_WEP);
|
||||||
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
|
|
||||||
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
|
|
||||||
if (mPasswordView.length() != 0) {
|
if (mPasswordView.length() != 0) {
|
||||||
int length = mPasswordView.length();
|
int length = mPasswordView.length();
|
||||||
String password = mPasswordView.getText().toString();
|
String password = mPasswordView.getText().toString();
|
||||||
@@ -659,7 +655,7 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case AccessPoint.SECURITY_PSK:
|
case AccessPoint.SECURITY_PSK:
|
||||||
config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_PSK);
|
||||||
if (mPasswordView.length() != 0) {
|
if (mPasswordView.length() != 0) {
|
||||||
String password = mPasswordView.getText().toString();
|
String password = mPasswordView.getText().toString();
|
||||||
if (password.matches("[0-9A-Fa-f]{64}")) {
|
if (password.matches("[0-9A-Fa-f]{64}")) {
|
||||||
@@ -672,16 +668,11 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
|
|
||||||
case AccessPoint.SECURITY_EAP:
|
case AccessPoint.SECURITY_EAP:
|
||||||
case AccessPoint.SECURITY_EAP_SUITE_B:
|
case AccessPoint.SECURITY_EAP_SUITE_B:
|
||||||
config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
|
|
||||||
config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
|
|
||||||
if (mAccessPointSecurity == AccessPoint.SECURITY_EAP_SUITE_B) {
|
if (mAccessPointSecurity == AccessPoint.SECURITY_EAP_SUITE_B) {
|
||||||
config.allowedKeyManagement.set(KeyMgmt.SUITE_B_192);
|
|
||||||
config.requirePmf = true;
|
|
||||||
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.GCMP_256);
|
|
||||||
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GCMP_256);
|
|
||||||
config.allowedGroupManagementCiphers.set(WifiConfiguration.GroupMgmtCipher
|
|
||||||
.BIP_GMAC_256);
|
|
||||||
// allowedSuiteBCiphers will be set according to certificate type
|
// allowedSuiteBCiphers will be set according to certificate type
|
||||||
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP_SUITE_B);
|
||||||
|
} else {
|
||||||
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP);
|
||||||
}
|
}
|
||||||
config.enterpriseConfig = new WifiEnterpriseConfig();
|
config.enterpriseConfig = new WifiEnterpriseConfig();
|
||||||
int eapMethod = mEapMethodSpinner.getSelectedItemPosition();
|
int eapMethod = mEapMethodSpinner.getSelectedItemPosition();
|
||||||
@@ -815,8 +806,7 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AccessPoint.SECURITY_SAE:
|
case AccessPoint.SECURITY_SAE:
|
||||||
config.allowedKeyManagement.set(KeyMgmt.SAE);
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_SAE);
|
||||||
config.requirePmf = true;
|
|
||||||
if (mPasswordView.length() != 0) {
|
if (mPasswordView.length() != 0) {
|
||||||
String password = mPasswordView.getText().toString();
|
String password = mPasswordView.getText().toString();
|
||||||
config.preSharedKey = '"' + password + '"';
|
config.preSharedKey = '"' + password + '"';
|
||||||
@@ -824,8 +814,7 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case AccessPoint.SECURITY_OWE:
|
case AccessPoint.SECURITY_OWE:
|
||||||
config.allowedKeyManagement.set(KeyMgmt.OWE);
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OWE);
|
||||||
config.requirePmf = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@@ -27,8 +27,6 @@ import android.net.ProxyInfo;
|
|||||||
import android.net.StaticIpConfiguration;
|
import android.net.StaticIpConfiguration;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
|
|
||||||
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
|
||||||
import android.net.wifi.WifiEnterpriseConfig;
|
import android.net.wifi.WifiEnterpriseConfig;
|
||||||
import android.net.wifi.WifiEnterpriseConfig.Eap;
|
import android.net.wifi.WifiEnterpriseConfig.Eap;
|
||||||
import android.net.wifi.WifiEnterpriseConfig.Phase2;
|
import android.net.wifi.WifiEnterpriseConfig.Phase2;
|
||||||
@@ -633,13 +631,11 @@ public class WifiConfigController2 implements TextWatcher,
|
|||||||
|
|
||||||
switch (mWifiEntrySecurity) {
|
switch (mWifiEntrySecurity) {
|
||||||
case WifiEntry.SECURITY_NONE:
|
case WifiEntry.SECURITY_NONE:
|
||||||
config.allowedKeyManagement.set(KeyMgmt.NONE);
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OPEN);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WifiEntry.SECURITY_WEP:
|
case WifiEntry.SECURITY_WEP:
|
||||||
config.allowedKeyManagement.set(KeyMgmt.NONE);
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_WEP);
|
||||||
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
|
|
||||||
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
|
|
||||||
if (mPasswordView.length() != 0) {
|
if (mPasswordView.length() != 0) {
|
||||||
int length = mPasswordView.length();
|
int length = mPasswordView.length();
|
||||||
String password = mPasswordView.getText().toString();
|
String password = mPasswordView.getText().toString();
|
||||||
@@ -654,7 +650,7 @@ public class WifiConfigController2 implements TextWatcher,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case WifiEntry.SECURITY_PSK:
|
case WifiEntry.SECURITY_PSK:
|
||||||
config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_PSK);
|
||||||
if (mPasswordView.length() != 0) {
|
if (mPasswordView.length() != 0) {
|
||||||
String password = mPasswordView.getText().toString();
|
String password = mPasswordView.getText().toString();
|
||||||
if (password.matches("[0-9A-Fa-f]{64}")) {
|
if (password.matches("[0-9A-Fa-f]{64}")) {
|
||||||
@@ -667,16 +663,11 @@ public class WifiConfigController2 implements TextWatcher,
|
|||||||
|
|
||||||
case WifiEntry.SECURITY_EAP:
|
case WifiEntry.SECURITY_EAP:
|
||||||
case WifiEntry.SECURITY_EAP_SUITE_B:
|
case WifiEntry.SECURITY_EAP_SUITE_B:
|
||||||
config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
|
|
||||||
config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
|
|
||||||
if (mWifiEntrySecurity == WifiEntry.SECURITY_EAP_SUITE_B) {
|
if (mWifiEntrySecurity == WifiEntry.SECURITY_EAP_SUITE_B) {
|
||||||
config.allowedKeyManagement.set(KeyMgmt.SUITE_B_192);
|
|
||||||
config.requirePmf = true;
|
|
||||||
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.GCMP_256);
|
|
||||||
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GCMP_256);
|
|
||||||
config.allowedGroupManagementCiphers.set(WifiConfiguration.GroupMgmtCipher
|
|
||||||
.BIP_GMAC_256);
|
|
||||||
// allowedSuiteBCiphers will be set according to certificate type
|
// allowedSuiteBCiphers will be set according to certificate type
|
||||||
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP_SUITE_B);
|
||||||
|
} else {
|
||||||
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP);
|
||||||
}
|
}
|
||||||
config.enterpriseConfig = new WifiEnterpriseConfig();
|
config.enterpriseConfig = new WifiEnterpriseConfig();
|
||||||
int eapMethod = mEapMethodSpinner.getSelectedItemPosition();
|
int eapMethod = mEapMethodSpinner.getSelectedItemPosition();
|
||||||
@@ -809,8 +800,7 @@ public class WifiConfigController2 implements TextWatcher,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WifiEntry.SECURITY_SAE:
|
case WifiEntry.SECURITY_SAE:
|
||||||
config.allowedKeyManagement.set(KeyMgmt.SAE);
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_SAE);
|
||||||
config.requirePmf = true;
|
|
||||||
if (mPasswordView.length() != 0) {
|
if (mPasswordView.length() != 0) {
|
||||||
String password = mPasswordView.getText().toString();
|
String password = mPasswordView.getText().toString();
|
||||||
config.preSharedKey = '"' + password + '"';
|
config.preSharedKey = '"' + password + '"';
|
||||||
@@ -818,8 +808,7 @@ public class WifiConfigController2 implements TextWatcher,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case WifiEntry.SECURITY_OWE:
|
case WifiEntry.SECURITY_OWE:
|
||||||
config.allowedKeyManagement.set(KeyMgmt.OWE);
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OWE);
|
||||||
config.requirePmf = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@@ -157,13 +157,11 @@ public class WifiUtils {
|
|||||||
|
|
||||||
switch (security) {
|
switch (security) {
|
||||||
case AccessPoint.SECURITY_NONE:
|
case AccessPoint.SECURITY_NONE:
|
||||||
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OPEN);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AccessPoint.SECURITY_WEP:
|
case AccessPoint.SECURITY_WEP:
|
||||||
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_WEP);
|
||||||
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
|
|
||||||
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
|
|
||||||
if (!TextUtils.isEmpty(password)) {
|
if (!TextUtils.isEmpty(password)) {
|
||||||
int length = password.length();
|
int length = password.length();
|
||||||
// WEP-40, WEP-104, and 256-bit WEP (WEP-232?)
|
// WEP-40, WEP-104, and 256-bit WEP (WEP-232?)
|
||||||
@@ -177,7 +175,7 @@ public class WifiUtils {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case AccessPoint.SECURITY_PSK:
|
case AccessPoint.SECURITY_PSK:
|
||||||
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_PSK);
|
||||||
if (!TextUtils.isEmpty(password)) {
|
if (!TextUtils.isEmpty(password)) {
|
||||||
if (password.matches("[0-9A-Fa-f]{64}")) {
|
if (password.matches("[0-9A-Fa-f]{64}")) {
|
||||||
config.preSharedKey = password;
|
config.preSharedKey = password;
|
||||||
@@ -189,16 +187,11 @@ public class WifiUtils {
|
|||||||
|
|
||||||
case AccessPoint.SECURITY_EAP:
|
case AccessPoint.SECURITY_EAP:
|
||||||
case AccessPoint.SECURITY_EAP_SUITE_B:
|
case AccessPoint.SECURITY_EAP_SUITE_B:
|
||||||
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
|
|
||||||
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
|
|
||||||
if (security == AccessPoint.SECURITY_EAP_SUITE_B) {
|
if (security == AccessPoint.SECURITY_EAP_SUITE_B) {
|
||||||
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.SUITE_B_192);
|
|
||||||
config.requirePmf = true;
|
|
||||||
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.GCMP_256);
|
|
||||||
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GCMP_256);
|
|
||||||
config.allowedGroupManagementCiphers.set(WifiConfiguration.GroupMgmtCipher
|
|
||||||
.BIP_GMAC_256);
|
|
||||||
// allowedSuiteBCiphers will be set according to certificate type
|
// allowedSuiteBCiphers will be set according to certificate type
|
||||||
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP_SUITE_B);
|
||||||
|
} else {
|
||||||
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(password)) {
|
if (!TextUtils.isEmpty(password)) {
|
||||||
@@ -206,16 +199,14 @@ public class WifiUtils {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AccessPoint.SECURITY_SAE:
|
case AccessPoint.SECURITY_SAE:
|
||||||
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.SAE);
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_SAE);
|
||||||
config.requirePmf = true;
|
|
||||||
if (!TextUtils.isEmpty(password)) {
|
if (!TextUtils.isEmpty(password)) {
|
||||||
config.preSharedKey = '"' + password + '"';
|
config.preSharedKey = '"' + password + '"';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AccessPoint.SECURITY_OWE:
|
case AccessPoint.SECURITY_OWE:
|
||||||
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.OWE);
|
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OWE);
|
||||||
config.requirePmf = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@@ -24,7 +24,6 @@ import static com.android.settings.wifi.dpp.WifiQrCode.SECURITY_WPA_PSK;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
|
|
||||||
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -252,17 +251,15 @@ public class WifiNetworkConfig {
|
|||||||
|
|
||||||
final WifiConfiguration enhancedOpenNetworkWifiConfiguration =
|
final WifiConfiguration enhancedOpenNetworkWifiConfiguration =
|
||||||
getBasicWifiConfiguration();
|
getBasicWifiConfiguration();
|
||||||
enhancedOpenNetworkWifiConfiguration.allowedKeyManagement.set(KeyMgmt.OWE);
|
enhancedOpenNetworkWifiConfiguration
|
||||||
enhancedOpenNetworkWifiConfiguration.requirePmf = true;
|
.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OWE);
|
||||||
wifiConfigurations.add(enhancedOpenNetworkWifiConfiguration);
|
wifiConfigurations.add(enhancedOpenNetworkWifiConfiguration);
|
||||||
return wifiConfigurations;
|
return wifiConfigurations;
|
||||||
}
|
}
|
||||||
|
|
||||||
final WifiConfiguration wifiConfiguration = getBasicWifiConfiguration();
|
final WifiConfiguration wifiConfiguration = getBasicWifiConfiguration();
|
||||||
if (mSecurity.startsWith(SECURITY_WEP)) {
|
if (mSecurity.startsWith(SECURITY_WEP)) {
|
||||||
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.NONE);
|
wifiConfiguration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_WEP);
|
||||||
wifiConfiguration.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
|
|
||||||
wifiConfiguration.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
|
|
||||||
|
|
||||||
// WEP-40, WEP-104, and 256-bit WEP (WEP-232?)
|
// WEP-40, WEP-104, and 256-bit WEP (WEP-232?)
|
||||||
final int length = mPreSharedKey.length();
|
final int length = mPreSharedKey.length();
|
||||||
@@ -273,7 +270,7 @@ public class WifiNetworkConfig {
|
|||||||
wifiConfiguration.wepKeys[0] = addQuotationIfNeeded(mPreSharedKey);
|
wifiConfiguration.wepKeys[0] = addQuotationIfNeeded(mPreSharedKey);
|
||||||
}
|
}
|
||||||
} else if (mSecurity.startsWith(SECURITY_WPA_PSK)) {
|
} else if (mSecurity.startsWith(SECURITY_WPA_PSK)) {
|
||||||
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
|
wifiConfiguration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_PSK);
|
||||||
|
|
||||||
if (mPreSharedKey.matches("[0-9A-Fa-f]{64}")) {
|
if (mPreSharedKey.matches("[0-9A-Fa-f]{64}")) {
|
||||||
wifiConfiguration.preSharedKey = mPreSharedKey;
|
wifiConfiguration.preSharedKey = mPreSharedKey;
|
||||||
@@ -281,8 +278,7 @@ public class WifiNetworkConfig {
|
|||||||
wifiConfiguration.preSharedKey = addQuotationIfNeeded(mPreSharedKey);
|
wifiConfiguration.preSharedKey = addQuotationIfNeeded(mPreSharedKey);
|
||||||
}
|
}
|
||||||
} else if (mSecurity.startsWith(SECURITY_SAE)) {
|
} else if (mSecurity.startsWith(SECURITY_SAE)) {
|
||||||
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.SAE);
|
wifiConfiguration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_SAE);
|
||||||
wifiConfiguration.requirePmf = true;
|
|
||||||
if (mPreSharedKey.length() != 0) {
|
if (mPreSharedKey.length() != 0) {
|
||||||
wifiConfiguration.preSharedKey = addQuotationIfNeeded(mPreSharedKey);
|
wifiConfiguration.preSharedKey = addQuotationIfNeeded(mPreSharedKey);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user