Merge "Create different KeyId for saved and suggestion network" into qt-dev
This commit is contained in:
@@ -2113,15 +2113,23 @@ public class WifiConfiguration implements Parcelable {
|
|||||||
throw new IllegalStateException("Not an EAP network");
|
throw new IllegalStateException("Not an EAP network");
|
||||||
}
|
}
|
||||||
|
|
||||||
return trimStringForKeyId(SSID) + "_" + keyMgmt + "_" +
|
String keyId = trimStringForKeyId(SSID) + "_" + keyMgmt + "_"
|
||||||
trimStringForKeyId(enterpriseConfig.getKeyId(current != null ?
|
+ trimStringForKeyId(enterpriseConfig.getKeyId(current != null
|
||||||
current.enterpriseConfig : null));
|
? current.enterpriseConfig : null));
|
||||||
|
|
||||||
|
if (!fromWifiNetworkSuggestion) {
|
||||||
|
return keyId;
|
||||||
|
}
|
||||||
|
return keyId + "_" + trimStringForKeyId(BSSID) + "_" + trimStringForKeyId(creatorName);
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
throw new IllegalStateException("Invalid config details");
|
throw new IllegalStateException("Invalid config details");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String trimStringForKeyId(String string) {
|
private String trimStringForKeyId(String string) {
|
||||||
|
if (string == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
// Remove quotes and spaces
|
// Remove quotes and spaces
|
||||||
return string.replace("\"", "").replace(" ", "");
|
return string.replace("\"", "").replace(" ", "");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -349,6 +349,67 @@ public class WifiConfigurationTest {
|
|||||||
assertTrue(exceptionThrown);
|
assertTrue(exceptionThrown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies that getKeyIdForCredentials returns the expected string for Suggestion Enterprise
|
||||||
|
* networks
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetKeyIdForCredentialsForSuggestion() throws Exception {
|
||||||
|
WifiConfiguration config = new WifiConfiguration();
|
||||||
|
final String mSsid = "TestAP";
|
||||||
|
final String packageName = "TestApp";
|
||||||
|
final String bSsid = MacAddress.createRandomUnicastAddress().toString();
|
||||||
|
String suggestionSuffix = "_" + bSsid + "_" + packageName;
|
||||||
|
config.SSID = mSsid;
|
||||||
|
config.fromWifiNetworkSuggestion = true;
|
||||||
|
config.creatorName = packageName;
|
||||||
|
config.BSSID = bSsid;
|
||||||
|
|
||||||
|
// Test various combinations
|
||||||
|
// EAP with TLS
|
||||||
|
config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
|
||||||
|
config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TLS);
|
||||||
|
config.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.NONE);
|
||||||
|
String keyId = config.getKeyIdForCredentials(config);
|
||||||
|
assertEquals(keyId, mSsid + "_WPA_EAP_TLS_NULL" + suggestionSuffix);
|
||||||
|
|
||||||
|
// EAP with TTLS & MSCHAPv2
|
||||||
|
config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
|
||||||
|
config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TTLS);
|
||||||
|
config.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.MSCHAPV2);
|
||||||
|
keyId = config.getKeyIdForCredentials(config);
|
||||||
|
assertEquals(keyId, mSsid + "_WPA_EAP_TTLS_MSCHAPV2" + suggestionSuffix);
|
||||||
|
|
||||||
|
// Suite-B 192 with PWD & GTC
|
||||||
|
config.allowedKeyManagement.clear();
|
||||||
|
config.allowedKeyManagement.set(KeyMgmt.SUITE_B_192);
|
||||||
|
config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.PWD);
|
||||||
|
config.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.GTC);
|
||||||
|
keyId = config.getKeyIdForCredentials(config);
|
||||||
|
assertEquals(keyId, mSsid + "_SUITE_B_192_PWD_GTC" + suggestionSuffix);
|
||||||
|
|
||||||
|
// IEEE8021X with SIM
|
||||||
|
config.allowedKeyManagement.clear();
|
||||||
|
config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
|
||||||
|
config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.SIM);
|
||||||
|
config.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.NONE);
|
||||||
|
keyId = config.getKeyIdForCredentials(config);
|
||||||
|
assertEquals(keyId, mSsid + "_IEEE8021X_SIM_NULL" + suggestionSuffix);
|
||||||
|
|
||||||
|
// Try calling this method with non-Enterprise network, expect an exception
|
||||||
|
boolean exceptionThrown = false;
|
||||||
|
try {
|
||||||
|
config.allowedKeyManagement.clear();
|
||||||
|
config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);
|
||||||
|
config.preSharedKey = "TestPsk";
|
||||||
|
keyId = config.getKeyIdForCredentials(config);
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
exceptionThrown = true;
|
||||||
|
}
|
||||||
|
assertTrue(exceptionThrown);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies that getSsidAndSecurityTypeString returns the correct String for networks of
|
* Verifies that getSsidAndSecurityTypeString returns the correct String for networks of
|
||||||
* various different security types
|
* various different security types
|
||||||
|
|||||||
Reference in New Issue
Block a user