diff options
author | Peter Qiu <zqiu@google.com> | 2017-06-22 15:48:19 -0700 |
---|---|---|
committer | Peter Qiu <zqiu@google.com> | 2017-07-11 13:57:53 -0700 |
commit | 49357a30edf5786c8db4bad6f5dbe62545751cc6 (patch) | |
tree | 201d9fef949592bac0af6bdaa47c6b509daabc5b /tests | |
parent | 26b97ef6a6d8e755e7db541afa84aacd807599d7 (diff) |
hotspot2: track number of providers that connected successfully
Add boolean field "hasEverConnected" to PasspointProvider to indicate
if the given provider had ever provided a successful network connection.
The added field is persisted to the config file.
Update the associated metric for the given provider after it was used
to successfully connect for the first time.
Note that PasspointManager#onPasspointNetworkConnected can be expanded
in the future to keep track of connected SSIDs for a given Passpoint
provider, as an additional input to the network selection algorithm.
Bug: 36358031
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Test: manually verify the provider's "hasEverConnected" is set to true
in the config file after a success connection
Change-Id: I6ef4ec801f78f34ff2ca9df97ab06188e1cc0324
Diffstat (limited to 'tests')
4 files changed, 87 insertions, 2 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index e58928bf5..e7216ce4a 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -295,7 +295,8 @@ public class WifiMetricsTest { */ public void setAndIncrementMetrics() throws Exception { mWifiMetrics.updateSavedNetworks(buildSavedNetworkList()); - mWifiMetrics.updateSavedPasspointProfiles(NUM_PASSPOINT_PROVIDERS); + mWifiMetrics.updateSavedPasspointProfiles(NUM_PASSPOINT_PROVIDERS, + NUM_PASSPOINT_PROVIDERS_SUCCESSFULLY_CONNECTED); mWifiMetrics.setIsLocationEnabled(TEST_VAL_IS_LOCATION_ENABLED); mWifiMetrics.setIsScanningAlwaysEnabled(IS_SCANNING_ALWAYS_ENABLED); @@ -592,6 +593,8 @@ public class WifiMetricsTest { mDeserializedWifiMetrics.numPasspointProviderUninstallation); assertEquals(NUM_PASSPOINT_PROVIDER_UNINSTALL_SUCCESS, mDeserializedWifiMetrics.numPasspointProviderUninstallSuccess); + assertEquals(NUM_PASSPOINT_PROVIDERS_SUCCESSFULLY_CONNECTED, + mDeserializedWifiMetrics.numPasspointProvidersSuccessfullyConnected); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigStoreDataTest.java index 8e808efcf..7e05c3d09 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigStoreDataTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigStoreDataTest.java @@ -60,6 +60,7 @@ public class PasspointConfigStoreDataTest { private static final String TEST_CLIENT_PRIVATE_KEY_ALIAS = "ClientPrivateKey"; private static final long TEST_PROVIDER_ID = 1; private static final int TEST_CREATOR_UID = 1234; + private static final boolean TEST_HAS_EVER_CONNECTED = true; @Mock WifiKeyStore mKeyStore; @Mock SIMAccessor mSimAccessor; @@ -238,7 +239,7 @@ public class PasspointConfigStoreDataTest { providerList.add(new PasspointProvider(createFullPasspointConfiguration(), mKeyStore, mSimAccessor, TEST_PROVIDER_ID, TEST_CREATOR_UID, TEST_CA_CERTIFICATE_ALIAS, TEST_CLIENT_CERTIFICATE_ALIAS, - TEST_CLIENT_PRIVATE_KEY_ALIAS)); + TEST_CLIENT_PRIVATE_KEY_ALIAS, TEST_HAS_EVER_CONNECTED)); // Serialize data for user store. when(mDataSource.getProviders()).thenReturn(providerList); 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 a8dd831ed..01566c203 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java @@ -1215,4 +1215,62 @@ public class PasspointManagerTest { assertFalse(PasspointManager.addLegacyPasspointConfig(wifiConfig)); } + + /** + * Verify that the provider's "hasEverConnected" flag will be set to true and the associated + * metric is updated after the provider was used to successfully connect to a Passpoint + * network for the first time. + * + * @throws Exception + */ + @Test + public void providerNetworkConnectedFirstTime() throws Exception { + PasspointProvider provider = addTestProvider(); + when(provider.getHasEverConnected()).thenReturn(false); + mManager.onPasspointNetworkConnected(TEST_FQDN); + verify(provider).setHasEverConnected(eq(true)); + } + + /** + * Verify that the provider's "hasEverConnected" flag the associated metric is not updated + * after the provider was used to successfully connect to a Passpoint network for non-first + * time. + * + * @throws Exception + */ + @Test + public void providerNetworkConnectedNotFirstTime() throws Exception { + PasspointProvider provider = addTestProvider(); + when(provider.getHasEverConnected()).thenReturn(true); + mManager.onPasspointNetworkConnected(TEST_FQDN); + verify(provider, never()).setHasEverConnected(anyBoolean()); + } + + /** + * Verify that the expected Passpoint metrics are updated when + * {@link PasspointManager#updateMetrics} is invoked. + * + * @throws Exception + */ + @Test + public void updateMetrics() throws Exception { + PasspointProvider provider = addTestProvider(); + + // Provider have not provided a successful network connection. + int expectedInstalledProviders = 1; + int expectedConnectedProviders = 0; + when(provider.getHasEverConnected()).thenReturn(false); + mManager.updateMetrics(); + verify(mWifiMetrics).updateSavedPasspointProfiles( + eq(expectedInstalledProviders), eq(expectedConnectedProviders)); + reset(provider); + reset(mWifiMetrics); + + // Provider have provided a successful network connection. + expectedConnectedProviders = 1; + when(provider.getHasEverConnected()).thenReturn(true); + mManager.updateMetrics(); + verify(mWifiMetrics).updateSavedPasspointProfiles( + eq(expectedInstalledProviders), eq(expectedConnectedProviders)); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java index 15f8471e0..9ee9fc6d5 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java @@ -963,4 +963,27 @@ public class PasspointProviderTest { assertFalse(mProvider.isSimCredential()); } + + /** + * Verify that hasEverConnected flag is set correctly using + * {@link PasspointProvider#setHasEverConnected}. + * + * @throws Exception + */ + @Test + public void setHasEverConnected() throws Exception { + PasspointConfiguration config = new PasspointConfiguration(); + HomeSp homeSp = new HomeSp(); + homeSp.setFqdn("test1"); + config.setHomeSp(homeSp); + Credential credential = new Credential(); + credential.setUserCredential(new Credential.UserCredential()); + config.setCredential(credential); + mProvider = createProvider(config); + verifyInstalledConfig(config, true); + + assertFalse(mProvider.getHasEverConnected()); + mProvider.setHasEverConnected(true); + assertTrue(mProvider.getHasEverConnected()); + } } |