Merge "[Wi-Fi] Change constant security type definition to Wificonfig value"

This commit is contained in:
Goven Liu
2020-01-08 06:00:48 +00:00
committed by Android (Google) Code Review

View File

@@ -62,12 +62,6 @@ import java.util.List;
public class AddAppNetworksFragment extends InstrumentedFragment { public class AddAppNetworksFragment extends InstrumentedFragment {
public static final String TAG = "AddAppNetworksFragment"; public static final String TAG = "AddAppNetworksFragment";
// Security types of a requested or saved network.
private static final String SECURITY_NO_PASSWORD = "nopass";
private static final String SECURITY_WEP = "wep";
private static final String SECURITY_WPA_PSK = "wpa";
private static final String SECURITY_SAE = "sae";
// Possible result values in each item of the returned result list, which is used // Possible result values in each item of the returned result list, which is used
// to inform the caller APP the processed result of each specified network. // to inform the caller APP the processed result of each specified network.
@VisibleForTesting @VisibleForTesting
@@ -269,25 +263,9 @@ public class AddAppNetworksFragment extends InstrumentedFragment {
} }
} }
/** private String getWepKey(WifiConfiguration config) {
* Classify security type into following types: return (config.wepTxKeyIndex >= 0 && config.wepTxKeyIndex < config.wepKeys.length)
* 1. {@Code SECURITY_NO_PASSWORD}: No password network or OWE network. ? config.wepKeys[config.wepTxKeyIndex] : null;
* 2. {@Code SECURITY_WEP}: Traditional WEP encryption network.
* 3. {@Code SECURITY_WPA_PSK}: WPA/WPA2 preshare key type.
* 4. {@Code SECURITY_SAE}: SAE type network.
*/
private String getSecurityType(WifiConfiguration config) {
if (config.allowedKeyManagement.get(KeyMgmt.SAE)) {
return SECURITY_SAE;
}
if (config.allowedKeyManagement.get(KeyMgmt.OWE)) {
return SECURITY_NO_PASSWORD;
}
if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK) || config.allowedKeyManagement.get(
KeyMgmt.WPA2_PSK)) {
return SECURITY_WPA_PSK;
}
return (config.wepKeys[0] == null) ? SECURITY_NO_PASSWORD : SECURITY_WEP;
} }
/** /**
@@ -306,41 +284,40 @@ public class AddAppNetworksFragment extends InstrumentedFragment {
boolean foundInSavedList; boolean foundInSavedList;
int networkPositionInBundle = 0; int networkPositionInBundle = 0;
for (WifiConfiguration specifiecConfig : mAllSpecifiedNetworksList) { for (WifiConfiguration specifiedConfig : mAllSpecifiedNetworksList) {
foundInSavedList = false; foundInSavedList = false;
final String displayedSsid = removeDoubleQuotes(specifiecConfig.SSID); final String displayedSsid = removeDoubleQuotes(specifiedConfig.SSID);
final String ssidWithQuotation = addQuotationIfNeeded(specifiecConfig.SSID); final String ssidWithQuotation = addQuotationIfNeeded(specifiedConfig.SSID);
final String securityType = getSecurityType(specifiecConfig); final int authType = specifiedConfig.getAuthType();
for (WifiConfiguration privilegedWifiConfiguration : savedWifiConfigurations) { for (WifiConfiguration privilegedWifiConfiguration : savedWifiConfigurations) {
final String savedSecurityType = getSecurityType(privilegedWifiConfiguration);
// If SSID or security type is different, should be new network or need to be // If SSID or security type is different, should be new network or need to be
// updated network. // updated network.
if (!ssidWithQuotation.equals(privilegedWifiConfiguration.SSID) if (!ssidWithQuotation.equals(privilegedWifiConfiguration.SSID)
|| !securityType.equals(savedSecurityType)) { || authType != privilegedWifiConfiguration.getAuthType()) {
continue; continue;
} }
// If specified network and saved network have same security types, we'll check // If specified network and saved network have same security types, we'll check
// more information according to their security type to judge if they are same. // more information according to their security type to judge if they are same.
switch (securityType) { switch (authType) {
case SECURITY_NO_PASSWORD: case KeyMgmt.NONE:
final String wep = getWepKey(specifiedConfig);
final String savedWep = getWepKey(privilegedWifiConfiguration);
foundInSavedList = TextUtils.equals(wep, savedWep);
break;
case KeyMgmt.OWE:
foundInSavedList = true; foundInSavedList = true;
break; break;
case SECURITY_WEP: case KeyMgmt.WPA_PSK:
if (specifiecConfig.wepKeys[0].equals( case KeyMgmt.WPA2_PSK:
privilegedWifiConfiguration.wepKeys[0])) { case KeyMgmt.SAE:
foundInSavedList = true; if (specifiedConfig.preSharedKey.equals(
}
break;
case SECURITY_WPA_PSK:
case SECURITY_SAE:
if (specifiecConfig.preSharedKey.equals(
privilegedWifiConfiguration.preSharedKey)) { privilegedWifiConfiguration.preSharedKey)) {
foundInSavedList = true; foundInSavedList = true;
} }
break; break;
// TODO: Check how to judge enterprise type.
default: default:
break; break;
} }
@@ -353,7 +330,7 @@ public class AddAppNetworksFragment extends InstrumentedFragment {
} else { } else {
// Prepare to add to UI list to show to user // Prepare to add to UI list to show to user
UiConfigurationItem uiConfigurationIcon = new UiConfigurationItem(displayedSsid, UiConfigurationItem uiConfigurationIcon = new UiConfigurationItem(displayedSsid,
specifiecConfig, networkPositionInBundle); specifiedConfig, networkPositionInBundle);
mUiToRequestedList.add(uiConfigurationIcon); mUiToRequestedList.add(uiConfigurationIcon);
} }
networkPositionInBundle++; networkPositionInBundle++;