Loading wifi/java/android/net/wifi/WifiConfiguration.java +10 −3 Original line number Diff line number Diff line Loading @@ -2442,16 +2442,23 @@ public class WifiConfiguration implements Parcelable { if (TextUtils.isEmpty(keyMgmt)) { throw new IllegalStateException("Not an EAP network"); } String keyId = trimStringForKeyId(SSID) + "_" + keyMgmt + "_" + trimStringForKeyId(enterpriseConfig.getKeyId(current != null ? current.enterpriseConfig : null)); return trimStringForKeyId(SSID) + "_" + keyMgmt + "_" + trimStringForKeyId(enterpriseConfig.getKeyId(current != null ? current.enterpriseConfig : null)); if (!fromWifiNetworkSuggestion) { return keyId; } return keyId + "_" + trimStringForKeyId(BSSID) + "_" + trimStringForKeyId(creatorName); } catch (NullPointerException e) { throw new IllegalStateException("Invalid config details"); } } private String trimStringForKeyId(String string) { if (string == null) { return ""; } // Remove quotes and spaces return string.replace("\"", "").replace(" ", ""); } Loading wifi/tests/src/android/net/wifi/WifiConfigurationTest.java +61 −0 Original line number Diff line number Diff line Loading @@ -252,6 +252,67 @@ public class WifiConfigurationTest { 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 = MacAddressUtils.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 * various different security types Loading Loading
wifi/java/android/net/wifi/WifiConfiguration.java +10 −3 Original line number Diff line number Diff line Loading @@ -2442,16 +2442,23 @@ public class WifiConfiguration implements Parcelable { if (TextUtils.isEmpty(keyMgmt)) { throw new IllegalStateException("Not an EAP network"); } String keyId = trimStringForKeyId(SSID) + "_" + keyMgmt + "_" + trimStringForKeyId(enterpriseConfig.getKeyId(current != null ? current.enterpriseConfig : null)); return trimStringForKeyId(SSID) + "_" + keyMgmt + "_" + trimStringForKeyId(enterpriseConfig.getKeyId(current != null ? current.enterpriseConfig : null)); if (!fromWifiNetworkSuggestion) { return keyId; } return keyId + "_" + trimStringForKeyId(BSSID) + "_" + trimStringForKeyId(creatorName); } catch (NullPointerException e) { throw new IllegalStateException("Invalid config details"); } } private String trimStringForKeyId(String string) { if (string == null) { return ""; } // Remove quotes and spaces return string.replace("\"", "").replace(" ", ""); } Loading
wifi/tests/src/android/net/wifi/WifiConfigurationTest.java +61 −0 Original line number Diff line number Diff line Loading @@ -252,6 +252,67 @@ public class WifiConfigurationTest { 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 = MacAddressUtils.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 * various different security types Loading