From 3ec3e900e8f0eaf7c816672dac9e59c14b208cd1 Mon Sep 17 00:00:00 2001 From: Hai Shalom Date: Tue, 18 Feb 2020 14:01:31 -0800 Subject: [Passpoint] Fix provider removal for factory reset and multiple providers with same FQDN Fix Passpoint provider removal for factory reset and multiple providers with same FQDN. Bug: 149776782 Test: atest PasspointManagerTest WifiServiceImplTest Test: Manually run Wi-Fi factory reset from Settings Change-Id: I4518bf2c9f7af6790a223d06126e1ed7d9063096 --- .../android/server/wifi/WifiServiceImplTest.java | 4 +- .../server/wifi/hotspot2/PasspointManagerTest.java | 133 ++++++++++++++------- 2 files changed, 95 insertions(+), 42 deletions(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index a289171b4..5cd51be30 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -4008,8 +4008,8 @@ public class WifiServiceImplTest extends WifiBaseTest { verify(mWifiConfigManager).removeNetwork( network.networkId, Binder.getCallingUid(), TEST_PACKAGE_NAME); - verify(mPasspointManager).removeProvider(anyInt(), anyBoolean(), isNull(), - eq(config.getUniqueId())); + verify(mPasspointManager).removeProvider(anyInt(), anyBoolean(), eq(config.getUniqueId()), + isNull()); verify(mWifiConfigManager).clearDeletedEphemeralNetworks(); verify(mClientModeImpl).clearNetworkRequestUserApprovedAccessPoints(); verify(mWifiNetworkSuggestionsManager).clear(); diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java index ea1ef1782..98dbcb97a 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java @@ -141,6 +141,8 @@ public class PasspointManagerTest extends WifiBaseTest { private static final String TEST_FRIENDLY_NAME = "friendly name"; private static final String TEST_FRIENDLY_NAME2 = "second friendly name"; private static final String TEST_REALM = "realm.test.com"; + private static final String TEST_REALM2 = "realm.test2.com"; + private static final String TEST_REALM3 = "realm.test3.com"; private static final String TEST_IMSI = "123456*"; private static final String FULL_IMSI = "123456789123456"; private static final int TEST_CARRIER_ID = 10; @@ -316,6 +318,17 @@ public class PasspointManagerTest extends WifiBaseTest { */ private PasspointConfiguration createTestConfigWithUserCredential(String fqdn, String friendlyName) { + return createTestConfigWithUserCredentialAndRealm(fqdn, friendlyName, TEST_REALM); + } + + /** + * Helper function for creating a test configuration with user credential + * and a unique realm. + * + * @return {@link PasspointConfiguration} + */ + private PasspointConfiguration createTestConfigWithUserCredentialAndRealm(String fqdn, + String friendlyName, String realm) { PasspointConfiguration config = new PasspointConfiguration(); HomeSp homeSp = new HomeSp(); homeSp.setFqdn(fqdn); @@ -327,7 +340,7 @@ public class PasspointManagerTest extends WifiBaseTest { friendlyNames.put("jp", friendlyName + 2); config.setServiceFriendlyNames(friendlyNames); Credential credential = new Credential(); - credential.setRealm(TEST_REALM); + credential.setRealm(realm != null ? realm : TEST_REALM); credential.setCaCertificate(FakeKeys.CA_CERT0); Credential.UserCredential userCredential = new Credential.UserCredential(); userCredential.setUsername("username"); @@ -362,12 +375,12 @@ public class PasspointManagerTest extends WifiBaseTest { } private PasspointProvider addTestProvider(String fqdn, String friendlyName, - String packageName, boolean isSuggestion) { + String packageName, boolean isSuggestion, String realm) { WifiConfiguration wifiConfig = WifiConfigurationTestUtil.generateWifiConfig(-1, TEST_UID, "\"PasspointTestSSID\"", true, true, fqdn, friendlyName, SECURITY_EAP); - return addTestProvider(fqdn, friendlyName, packageName, wifiConfig, isSuggestion); + return addTestProvider(fqdn, friendlyName, packageName, wifiConfig, isSuggestion, realm); } /** @@ -377,8 +390,9 @@ public class PasspointManagerTest extends WifiBaseTest { * @return {@link PasspointProvider} */ private PasspointProvider addTestProvider(String fqdn, String friendlyName, - String packageName, WifiConfiguration wifiConfig, boolean isSuggestion) { - PasspointConfiguration config = createTestConfigWithUserCredential(fqdn, friendlyName); + String packageName, WifiConfiguration wifiConfig, boolean isSuggestion, String realm) { + PasspointConfiguration config = + createTestConfigWithUserCredentialAndRealm(fqdn, friendlyName, realm); wifiConfig.setPasspointUniqueId(config.getUniqueId()); PasspointProvider provider = createMockProvider(config, wifiConfig, isSuggestion); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), @@ -999,7 +1013,7 @@ public class PasspointManagerTest extends WifiBaseTest { com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession().mockStatic( InformationElementUtil.class).startMocking(); try { - addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false); + addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false, null); when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(null); InformationElementUtil.Vsa vsa = new InformationElementUtil.Vsa(); @@ -1028,7 +1042,7 @@ public class PasspointManagerTest extends WifiBaseTest { @Test public void matchProviderAsHomeProvider() throws Exception { PasspointProvider provider = - addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false); + addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false, null); ANQPData entry = new ANQPData(mClock, null); when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); @@ -1049,7 +1063,7 @@ public class PasspointManagerTest extends WifiBaseTest { @Test public void matchProviderAsRoamingProvider() throws Exception { PasspointProvider provider = - addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false); + addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false, null); ANQPData entry = new ANQPData(mClock, null); when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); @@ -1070,9 +1084,9 @@ public class PasspointManagerTest extends WifiBaseTest { public void matchScanResultWithMultipleProviderAsHomeAndRoaming() { // Only add roaming providers. PasspointProvider roamingProvider1 = - addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false); + addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false, null); PasspointProvider roamingProvider2 = - addTestProvider(TEST_FQDN2, TEST_FRIENDLY_NAME2, TEST_PACKAGE1, false); + addTestProvider(TEST_FQDN2, TEST_FRIENDLY_NAME2, TEST_PACKAGE1, false, null); ANQPData entry = new ANQPData(mClock, null); when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); when(roamingProvider1.match(anyMap(), any(RoamingConsortium.class))) @@ -1088,9 +1102,9 @@ public class PasspointManagerTest extends WifiBaseTest { } // Add home providers. PasspointProvider homeProvider1 = - addTestProvider(TEST_FQDN + "home", TEST_FRIENDLY_NAME, TEST_PACKAGE, false); - PasspointProvider homeProvider2 = - addTestProvider(TEST_FQDN2 + "home", TEST_FRIENDLY_NAME2, TEST_PACKAGE1, false); + addTestProvider(TEST_FQDN + "home", TEST_FRIENDLY_NAME, TEST_PACKAGE, false, null); + PasspointProvider homeProvider2 = addTestProvider(TEST_FQDN2 + "home", TEST_FRIENDLY_NAME2, + TEST_PACKAGE1, false, null); when(homeProvider1.match(anyMap(), any(RoamingConsortium.class))) .thenReturn(PasspointMatch.HomeProvider); when(homeProvider2.match(anyMap(), any(RoamingConsortium.class))) @@ -1111,7 +1125,7 @@ public class PasspointManagerTest extends WifiBaseTest { @Test public void matchProviderWithNoMatch() throws Exception { PasspointProvider provider = - addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false); + addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false, null); ANQPData entry = new ANQPData(mClock, null); when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); @@ -1170,7 +1184,7 @@ public class PasspointManagerTest extends WifiBaseTest { InformationElementUtil.class).startMocking(); try { PasspointProvider provider = addTestProvider(TEST_FQDN + 0, TEST_FRIENDLY_NAME, - TEST_PACKAGE, false); + TEST_PACKAGE, false, null); when(provider.tryUpdateCarrierId()).thenReturn(true); reset(mWifiConfigManager); @@ -1204,15 +1218,15 @@ public class PasspointManagerTest extends WifiBaseTest { InformationElementUtil.class).startMocking(); try { PasspointProvider providerHome = addTestProvider(TEST_FQDN + 0, TEST_FRIENDLY_NAME, - TEST_PACKAGE, false); + TEST_PACKAGE, false, null); providerHome.getWifiConfig().isHomeProviderNetwork = true; PasspointProvider providerRoaming = addTestProvider(TEST_FQDN + 1, TEST_FRIENDLY_NAME, - TEST_PACKAGE, false); + TEST_PACKAGE, false, null); WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.generateWifiConfig(-1, TEST_UID, "\"PasspointTestSSID\"", true, true, TEST_FQDN + 2, TEST_FRIENDLY_NAME, SECURITY_EAP); PasspointProvider providerNone = addTestProvider(TEST_FQDN + 2, TEST_FRIENDLY_NAME, - TEST_PACKAGE, wifiConfiguration, false); + TEST_PACKAGE, wifiConfiguration, false, null); ANQPData entry = new ANQPData(mClock, null); InformationElementUtil.Vsa vsa = new InformationElementUtil.Vsa(); vsa.anqpDomainID = TEST_ANQP_DOMAIN_ID2; @@ -1255,18 +1269,18 @@ public class PasspointManagerTest extends WifiBaseTest { @Test public void getWifiConfigsForPasspointProfiles() { PasspointProvider provider1 = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, - TEST_PACKAGE, false); + TEST_PACKAGE, false, null); PasspointProvider provider2 = addTestProvider(TEST_FQDN + 1, TEST_FRIENDLY_NAME, - TEST_PACKAGE, false); + TEST_PACKAGE, false, null); PasspointProvider provider3 = addTestProvider(TEST_FQDN + 2, TEST_FRIENDLY_NAME, - TEST_PACKAGE, false); + TEST_PACKAGE, false, null); assertEquals(3, mManager.getWifiConfigsForPasspointProfiles( Arrays.asList(provider1.getConfig().getUniqueId(), provider2.getConfig().getUniqueId(), provider3.getConfig().getUniqueId(), TEST_FQDN + "_353ab8c93", TEST_FQDN + "_83765319aca")).size()); PasspointProvider provider4 = addTestProvider(TEST_FQDN + 3, TEST_FRIENDLY_NAME, - TEST_PACKAGE, true); + TEST_PACKAGE, true, null); when(mWifiNetworkSuggestionsManager .isPasspointSuggestionSharedWithUser(provider4.getWifiConfig())).thenReturn(false); assertEquals(3, mManager.getWifiConfigsForPasspointProfiles( @@ -1274,7 +1288,7 @@ public class PasspointManagerTest extends WifiBaseTest { provider2.getConfig().getUniqueId(), provider3.getConfig().getUniqueId(), provider4.getConfig().getUniqueId(), TEST_FQDN + "_83765319aca")).size()); PasspointProvider provider5 = addTestProvider(TEST_FQDN + 4, TEST_FRIENDLY_NAME, - TEST_PACKAGE, true); + TEST_PACKAGE, true, null); when(mWifiNetworkSuggestionsManager .isPasspointSuggestionSharedWithUser(provider5.getWifiConfig())).thenReturn(true); assertEquals(4, mManager.getWifiConfigsForPasspointProfiles( @@ -1478,9 +1492,9 @@ public class PasspointManagerTest extends WifiBaseTest { @Test public void getMatchingPasspointConfigsForOsuProvidersWithMatch() { PasspointProvider provider1 = - addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false); + addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false, null); PasspointProvider provider2 = - addTestProvider(TEST_FQDN2, TEST_FRIENDLY_NAME2, TEST_PACKAGE, false); + addTestProvider(TEST_FQDN2, TEST_FRIENDLY_NAME2, TEST_PACKAGE, false, null); List osuProviders = new ArrayList<>(); Map friendlyNames = new HashMap<>(); @@ -1507,8 +1521,8 @@ public class PasspointManagerTest extends WifiBaseTest { */ @Test public void getMatchingPasspointConfigsForOsuProvidersWitNoMatch() { - addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false); - addTestProvider(TEST_FQDN2, TEST_FRIENDLY_NAME2, TEST_PACKAGE, false); + addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false, null); + addTestProvider(TEST_FQDN2, TEST_FRIENDLY_NAME2, TEST_PACKAGE, false, null); List osuProviders = new ArrayList<>(); @@ -1809,7 +1823,7 @@ public class PasspointManagerTest extends WifiBaseTest { @Test public void providerNetworkConnectedFirstTime() throws Exception { PasspointProvider provider = - addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false); + addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false, null); when(provider.getHasEverConnected()).thenReturn(false); mManager.onPasspointNetworkConnected(provider.getConfig().getUniqueId()); verify(provider).setHasEverConnected(eq(true)); @@ -1825,7 +1839,7 @@ public class PasspointManagerTest extends WifiBaseTest { @Test public void providerNetworkConnectedNotFirstTime() throws Exception { PasspointProvider provider = - addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false); + addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false, null); when(provider.getHasEverConnected()).thenReturn(true); mManager.onPasspointNetworkConnected(TEST_FQDN); verify(provider, never()).setHasEverConnected(anyBoolean()); @@ -1840,7 +1854,7 @@ public class PasspointManagerTest extends WifiBaseTest { @Test public void updateMetrics() { PasspointProvider provider = - addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false); + addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false, null); ArgumentCaptor> argCaptor = ArgumentCaptor.forClass( Map.class); // Provider have not provided a successful network connection. @@ -1888,7 +1902,7 @@ public class PasspointManagerTest extends WifiBaseTest { currentConfiguration.FQDN = TEST_FQDN; when(mClientModeImpl.getCurrentWifiConfiguration()).thenReturn(currentConfiguration); PasspointProvider passpointProvider = - addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false); + addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE, false, null); currentConfiguration.setPasspointUniqueId(passpointProvider.getConfig().getUniqueId()); verify(mAppOpsManager).startWatchingMode(eq(OPSTR_CHANGE_WIFI_STATE), eq(TEST_PACKAGE), mAppOpChangedListenerCaptor.capture()); @@ -2211,17 +2225,17 @@ public class PasspointManagerTest extends WifiBaseTest { InformationElementUtil.class).startMocking(); try { PasspointProvider providerHome = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, - TEST_PACKAGE, false); + TEST_PACKAGE, false, null); providerHome.getConfig().setSubscriptionExpirationTimeInMillis( System.currentTimeMillis() + 100000); providerHome.getWifiConfig().isHomeProviderNetwork = true; PasspointProvider providerRoaming = addTestProvider(TEST_FQDN2, TEST_FRIENDLY_NAME, - TEST_PACKAGE, false); + TEST_PACKAGE, false, null); WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.generateWifiConfig(-1, TEST_UID, "\"PasspointTestSSID\"", true, true, TEST_FQDN + 2, TEST_FRIENDLY_NAME, SECURITY_EAP); PasspointProvider providerNone = addTestProvider(TEST_FQDN + 2, TEST_FRIENDLY_NAME, - TEST_PACKAGE, wifiConfiguration, false); + TEST_PACKAGE, wifiConfiguration, false, null); ANQPData entry = new ANQPData(mClock, null); InformationElementUtil.Vsa vsa = new InformationElementUtil.Vsa(); vsa.anqpDomainID = TEST_ANQP_DOMAIN_ID; @@ -2261,17 +2275,17 @@ public class PasspointManagerTest extends WifiBaseTest { InformationElementUtil.class).startMocking(); try { PasspointProvider providerHome = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, - TEST_PACKAGE, false); + TEST_PACKAGE, false, null); providerHome.getConfig().setSubscriptionExpirationTimeInMillis( System.currentTimeMillis() - 10000); providerHome.getWifiConfig().isHomeProviderNetwork = true; PasspointProvider providerRoaming = addTestProvider(TEST_FQDN2, TEST_FRIENDLY_NAME, - TEST_PACKAGE, false); + TEST_PACKAGE, false, null); WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.generateWifiConfig(-1, TEST_UID, "\"PasspointTestSSID\"", true, true, TEST_FQDN + 2, TEST_FRIENDLY_NAME, SECURITY_EAP); PasspointProvider providerNone = addTestProvider(TEST_FQDN + 2, TEST_FRIENDLY_NAME, - TEST_PACKAGE, wifiConfiguration, false); + TEST_PACKAGE, wifiConfiguration, false, null); ANQPData entry = new ANQPData(mClock, null); InformationElementUtil.Vsa vsa = new InformationElementUtil.Vsa(); vsa.anqpDomainID = TEST_ANQP_DOMAIN_ID; @@ -2311,19 +2325,19 @@ public class PasspointManagerTest extends WifiBaseTest { InformationElementUtil.class).startMocking(); try { PasspointProvider providerHome = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, - TEST_PACKAGE, false); + TEST_PACKAGE, false, null); providerHome.getConfig().setSubscriptionExpirationTimeInMillis( System.currentTimeMillis() - 10000); providerHome.getWifiConfig().isHomeProviderNetwork = true; PasspointProvider providerRoaming = addTestProvider(TEST_FQDN2, TEST_FRIENDLY_NAME, - TEST_PACKAGE, false); + TEST_PACKAGE, false, null); providerRoaming.getConfig().setSubscriptionExpirationTimeInMillis( System.currentTimeMillis() + 100000); WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.generateWifiConfig(-1, TEST_UID, "\"PasspointTestSSID\"", true, true, TEST_FQDN + 2, TEST_FRIENDLY_NAME, SECURITY_EAP); PasspointProvider providerNone = addTestProvider(TEST_FQDN + 2, TEST_FRIENDLY_NAME, - TEST_PACKAGE, wifiConfiguration, false); + TEST_PACKAGE, wifiConfiguration, false, null); ANQPData entry = new ANQPData(mClock, null); InformationElementUtil.Vsa vsa = new InformationElementUtil.Vsa(); vsa.anqpDomainID = TEST_ANQP_DOMAIN_ID; @@ -2467,4 +2481,43 @@ public class PasspointManagerTest extends WifiBaseTest { verify(mAnqpRequestManager, never()).requestANQPElements(any(long.class), any(ANQPNetworkKey.class), any(boolean.class), any(NetworkDetail.HSRelease.class)); } + + /** + * Verify that removing of multiple providers with the same FQDN is done correctly. + */ + @Test + public void removeAllProvidersWithSameFqdn() { + PasspointProvider provider1 = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, + TEST_PACKAGE, false, TEST_REALM); + PasspointProvider provider2 = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, + TEST_PACKAGE, false, TEST_REALM2); + PasspointProvider provider3 = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, + TEST_PACKAGE, false, TEST_REALM3); + + List providers = mUserDataSource.getProviders(); + assertEquals(3, providers.size()); + verify(mWifiMetrics, times(3)).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics, times(3)).incrementNumPasspointProviderInstallSuccess(); + + // Remove the provider as the creator app. + assertTrue(mManager.removeProvider(TEST_CREATOR_UID, false, null, TEST_FQDN)); + + verify(provider1).uninstallCertsAndKeys(); + verify(mWifiConfigManager, times(1)).removePasspointConfiguredNetwork( + provider1.getWifiConfig().getKey()); + verify(provider2).uninstallCertsAndKeys(); + verify(mWifiConfigManager, times(1)).removePasspointConfiguredNetwork( + provider2.getWifiConfig().getKey()); + verify(provider3).uninstallCertsAndKeys(); + verify(mWifiConfigManager, times(1)).removePasspointConfiguredNetwork( + provider3.getWifiConfig().getKey()); + + verify(mWifiMetrics, times(3)).incrementNumPasspointProviderUninstallation(); + verify(mWifiMetrics, times(3)).incrementNumPasspointProviderUninstallSuccess(); + verify(mAppOpsManager).stopWatchingMode(any(AppOpsManager.OnOpChangedListener.class)); + assertTrue(mManager.getProviderConfigs(TEST_CREATOR_UID, false).isEmpty()); + + // Verify content in the data source. + assertTrue(mUserDataSource.getProviders().isEmpty()); + } } -- cgit v1.2.3