diff options
author | Peter Qiu <zqiu@google.com> | 2017-07-12 18:01:38 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-07-12 18:01:38 +0000 |
commit | fcbfa80a8deed21b2c7e6f43f9b1305f73b89132 (patch) | |
tree | d988db630de962ec2a782246078fb2f09ac34cc7 | |
parent | d983cadcacb9270f08d9b3fa064e20fe2eca0d47 (diff) | |
parent | 61a44929dc78c8bfc85816c31d0608ab9469457b (diff) |
Merge changes from topic 'passpoint_metrics' into oc-dr1-dev am: 209007db2b
am: 61a44929dc
Change-Id: I9ab6f20a65e3620b2bf50e39afaad1ea98909c2e
10 files changed, 285 insertions, 8 deletions
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index c4be62570..0b0c38002 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -216,7 +216,8 @@ public class WifiInjector { mWifiNetworkScoreCache); mSimAccessor = new SIMAccessor(mContext); mPasspointManager = new PasspointManager(mContext, mWifiNative, mWifiKeyStore, mClock, - mSimAccessor, new PasspointObjectFactory(), mWifiConfigManager, mWifiConfigStore); + mSimAccessor, new PasspointObjectFactory(), mWifiConfigManager, mWifiConfigStore, + mWifiMetrics); mPasspointNetworkEvaluator = new PasspointNetworkEvaluator( mPasspointManager, mWifiConfigManager, mConnectivityLocalLog); // mWifiStateMachine has an implicit dependency on mJavaRuntime due to WifiDiagnostics. diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 0caf79e79..d317f8386 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -1025,6 +1025,41 @@ public class WifiMetrics { } } + /** + * Increment number of times Passpoint provider being installed. + */ + public void incrementNumPasspointProviderInstallation() { + synchronized (mLock) { + mWifiLogProto.numPasspointProviderInstallation++; + } + } + + /** + * Increment number of times Passpoint provider is installed successfully. + */ + public void incrementNumPasspointProviderInstallSuccess() { + synchronized (mLock) { + mWifiLogProto.numPasspointProviderInstallSuccess++; + } + } + + /** + * Increment number of times Passpoint provider being uninstalled. + */ + public void incrementNumPasspointProviderUninstallation() { + synchronized (mLock) { + mWifiLogProto.numPasspointProviderUninstallation++; + } + } + + /** + * Increment number of times Passpoint provider is uninstalled successfully. + */ + public void incrementNumPasspointProviderUninstallSuccess() { + synchronized (mLock) { + mWifiLogProto.numPasspointProviderUninstallSuccess++; + } + } public static final String PROTO_DUMP_ARG = "wifiMetricsProto"; public static final String CLEAN_DUMP_ARG = "clean"; @@ -1228,6 +1263,19 @@ public class WifiMetrics { pw.println(staEventToString(event)); } + pw.println("mWifiLogProto.numPasspointProviders=" + + mWifiLogProto.numPasspointProviders); + pw.println("mWifiLogProto.numPasspointProviderInstallation=" + + mWifiLogProto.numPasspointProviderInstallation); + pw.println("mWifiLogProto.numPasspointProviderInstallSuccess=" + + mWifiLogProto.numPasspointProviderInstallSuccess); + pw.println("mWifiLogProto.numPasspointProviderUninstallation=" + + mWifiLogProto.numPasspointProviderUninstallation); + pw.println("mWifiLogProto.numPasspointProviderUninstallSuccess=" + + mWifiLogProto.numPasspointProviderUninstallSuccess); + pw.println("mWifiLogProto.numPasspointProvidersSuccessfullyConnected=" + + mWifiLogProto.numPasspointProvidersSuccessfullyConnected); + pw.println("mWifiAwareMetrics:"); mWifiAwareMetrics.dump(fd, pw, args); } @@ -1273,6 +1321,20 @@ public class WifiMetrics { } /** + * Update metrics for saved Passpoint profiles. + * + * @param numSavedProfiles The number of saved Passpoint profiles + * @param numConnectedProfiles The number of saved Passpoint profiles that have ever resulted + * in a successful network connection + */ + public void updateSavedPasspointProfiles(int numSavedProfiles, int numConnectedProfiles) { + synchronized (mLock) { + mWifiLogProto.numPasspointProviders = numSavedProfiles; + mWifiLogProto.numPasspointProvidersSuccessfullyConnected = numConnectedProfiles; + } + } + + /** * append the separate ConnectionEvent, SystemStateEntry and ScanReturnCode collections to their * respective lists within mWifiLogProto * diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 3b6ff817c..c58f83b74 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -4727,6 +4727,12 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss mWifiConfigManager.updateNetworkAfterConnect(mLastNetworkId); // On connect, reset wifiScoreReport mWifiScoreReport.reset(); + + // Notify PasspointManager of Passpoint network connected event. + WifiConfiguration currentNetwork = getCurrentWifiConfiguration(); + if (currentNetwork.isPasspoint()) { + mPasspointManager.onPasspointNetworkConnected(currentNetwork.FQDN); + } } } @@ -7009,6 +7015,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss */ public void updateWifiMetrics() { mWifiMetrics.updateSavedNetworks(mWifiConfigManager.getSavedNetworks()); + mPasspointManager.updateMetrics(); } /** diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointConfigStoreData.java b/service/java/com/android/server/wifi/hotspot2/PasspointConfigStoreData.java index 74a4760b4..38401d2ca 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointConfigStoreData.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointConfigStoreData.java @@ -66,6 +66,7 @@ public class PasspointConfigStoreData implements WifiConfigStore.StoreData { private static final String XML_TAG_CLIENT_PRIVATE_KEY_ALIAS = "ClientPrivateKeyAlias"; private static final String XML_TAG_PROVIDER_INDEX = "ProviderIndex"; + private static final String XML_TAG_HAS_EVER_CONNECTED = "HasEverConnected"; private final WifiKeyStore mKeyStore; private final SIMAccessor mSimAccessor; @@ -211,6 +212,7 @@ public class PasspointConfigStoreData implements WifiConfigStore.StoreData { provider.getClientCertificateAlias()); XmlUtil.writeNextValue(out, XML_TAG_CLIENT_PRIVATE_KEY_ALIAS, provider.getClientPrivateKeyAlias()); + XmlUtil.writeNextValue(out, XML_TAG_HAS_EVER_CONNECTED, provider.getHasEverConnected()); if (provider.getConfig() != null) { XmlUtil.writeNextSectionStart(out, XML_TAG_SECTION_HEADER_PASSPOINT_CONFIGURATION); PasspointXmlUtils.serializePasspointConfiguration(out, provider.getConfig()); @@ -304,6 +306,7 @@ public class PasspointConfigStoreData implements WifiConfigStore.StoreData { String caCertificateAlias = null; String clientCertificateAlias = null; String clientPrivateKeyAlias = null; + boolean hasEverConnected = false; PasspointConfiguration config = null; while (XmlUtils.nextElementWithin(in, outerTagDepth)) { if (in.getAttributeValue(null, "name") != null) { @@ -326,6 +329,9 @@ public class PasspointConfigStoreData implements WifiConfigStore.StoreData { case XML_TAG_CLIENT_PRIVATE_KEY_ALIAS: clientPrivateKeyAlias = (String) value; break; + case XML_TAG_HAS_EVER_CONNECTED: + hasEverConnected = (boolean) value; + break; } } else { if (!TextUtils.equals(in.getName(), @@ -344,7 +350,8 @@ public class PasspointConfigStoreData implements WifiConfigStore.StoreData { throw new XmlPullParserException("Missing Passpoint configuration"); } return new PasspointProvider(config, mKeyStore, mSimAccessor, providerId, creatorUid, - caCertificateAlias, clientCertificateAlias, clientPrivateKeyAlias); + caCertificateAlias, clientCertificateAlias, clientPrivateKeyAlias, + hasEverConnected); } /** diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java index 3695ba35f..5d79ba40a 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java @@ -45,6 +45,7 @@ import com.android.server.wifi.SIMAccessor; import com.android.server.wifi.WifiConfigManager; import com.android.server.wifi.WifiConfigStore; import com.android.server.wifi.WifiKeyStore; +import com.android.server.wifi.WifiMetrics; import com.android.server.wifi.WifiNative; import com.android.server.wifi.hotspot2.anqp.ANQPElement; import com.android.server.wifi.hotspot2.anqp.Constants; @@ -97,6 +98,7 @@ public class PasspointManager { private final ANQPRequestManager mAnqpRequestManager; private final WifiConfigManager mWifiConfigManager; private final CertificateVerifier mCertVerifier; + private final WifiMetrics mWifiMetrics; // Counter used for assigning unique identifier to each provider. private long mProviderIndex; @@ -194,7 +196,8 @@ public class PasspointManager { public PasspointManager(Context context, WifiNative wifiNative, WifiKeyStore keyStore, Clock clock, SIMAccessor simAccessor, PasspointObjectFactory objectFactory, - WifiConfigManager wifiConfigManager, WifiConfigStore wifiConfigStore) { + WifiConfigManager wifiConfigManager, WifiConfigStore wifiConfigStore, + WifiMetrics wifiMetrics) { mHandler = objectFactory.makePasspointEventHandler(wifiNative, new CallbackHandler(context)); mKeyStore = keyStore; @@ -205,6 +208,7 @@ public class PasspointManager { mAnqpRequestManager = objectFactory.makeANQPRequestManager(mHandler, clock); mCertVerifier = objectFactory.makeCertificateVerifier(); mWifiConfigManager = wifiConfigManager; + mWifiMetrics = wifiMetrics; mProviderIndex = 0; wifiConfigStore.registerStoreData(objectFactory.makePasspointConfigStoreData( mKeyStore, mSimAccessor, new DataSourceHandler())); @@ -222,6 +226,7 @@ public class PasspointManager { * @return true if provider is added, false otherwise */ public boolean addOrUpdateProvider(PasspointConfiguration config, int uid) { + mWifiMetrics.incrementNumPasspointProviderInstallation(); if (config == null) { Log.e(TAG, "Configuration not provided"); return false; @@ -266,6 +271,7 @@ public class PasspointManager { mWifiConfigManager.saveToStore(true /* forceWrite */); Log.d(TAG, "Added/updated Passpoint configuration: " + config.getHomeSp().getFqdn() + " by " + uid); + mWifiMetrics.incrementNumPasspointProviderInstallSuccess(); return true; } @@ -276,6 +282,7 @@ public class PasspointManager { * @return true if a provider is removed, false otherwise */ public boolean removeProvider(String fqdn) { + mWifiMetrics.incrementNumPasspointProviderUninstallation(); if (!mProviders.containsKey(fqdn)) { Log.e(TAG, "Config doesn't exist"); return false; @@ -285,6 +292,7 @@ public class PasspointManager { mProviders.remove(fqdn); mWifiConfigManager.saveToStore(true /* forceWrite */); Log.d(TAG, "Removed Passpoint configuration: " + fqdn); + mWifiMetrics.incrementNumPasspointProviderUninstallSuccess(); return true; } @@ -528,6 +536,41 @@ public class PasspointManager { } /** + * Invoked when a Passpoint network was successfully connected based on the credentials + * provided by the given Passpoint provider (specified by its FQDN). + * + * @param fqdn The FQDN of the Passpoint provider + */ + public void onPasspointNetworkConnected(String fqdn) { + PasspointProvider provider = mProviders.get(fqdn); + if (provider == null) { + Log.e(TAG, "Passpoint network connected without provider: " + fqdn); + return; + } + + if (!provider.getHasEverConnected()) { + // First successful connection using this provider. + provider.setHasEverConnected(true); + } + } + + /** + * Update metrics related to installed Passpoint providers, this includes the number of + * installed providers and the number of those providers that results in a successful network + * connection. + */ + public void updateMetrics() { + int numProviders = mProviders.size(); + int numConnectedProviders = 0; + for (Map.Entry<String, PasspointProvider> entry : mProviders.entrySet()) { + if (entry.getValue().getHasEverConnected()) { + numConnectedProviders++; + } + } + mWifiMetrics.updateSavedPasspointProfiles(numProviders, numConnectedProviders); + } + + /** * Dump the current state of PasspointManager to the provided output stream. * * @param pw The output stream to write to @@ -587,7 +630,7 @@ public class PasspointManager { mSimAccessor, mProviderIndex++, wifiConfig.creatorUid, enterpriseConfig.getCaCertificateAlias(), enterpriseConfig.getClientCertificateAlias(), - enterpriseConfig.getClientCertificateAlias()); + enterpriseConfig.getClientCertificateAlias(), false); mProviders.put(passpointConfig.getHomeSp().getFqdn(), provider); return true; } diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java b/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java index c38098dac..c7943ed81 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java @@ -87,14 +87,17 @@ public class PasspointProvider { private final int mEAPMethodID; private final AuthParam mAuthParam; + private boolean mHasEverConnected; + public PasspointProvider(PasspointConfiguration config, WifiKeyStore keyStore, SIMAccessor simAccessor, long providerId, int creatorUid) { - this(config, keyStore, simAccessor, providerId, creatorUid, null, null, null); + this(config, keyStore, simAccessor, providerId, creatorUid, null, null, null, false); } public PasspointProvider(PasspointConfiguration config, WifiKeyStore keyStore, SIMAccessor simAccessor, long providerId, int creatorUid, String caCertificateAlias, - String clientCertificateAlias, String clientPrivateKeyAlias) { + String clientCertificateAlias, String clientPrivateKeyAlias, + boolean hasEverConnected) { // Maintain a copy of the configuration to avoid it being updated by others. mConfig = new PasspointConfiguration(config); mKeyStore = keyStore; @@ -103,6 +106,7 @@ public class PasspointProvider { mCaCertificateAlias = caCertificateAlias; mClientCertificateAlias = clientCertificateAlias; mClientPrivateKeyAlias = clientPrivateKeyAlias; + mHasEverConnected = hasEverConnected; // Setup EAP method and authentication parameter based on the credential. if (mConfig.getCredential().getUserCredential() != null) { @@ -150,6 +154,14 @@ public class PasspointProvider { return mCreatorUid; } + public boolean getHasEverConnected() { + return mHasEverConnected; + } + + public void setHasEverConnected(boolean hasEverConnected) { + mHasEverConnected = hasEverConnected; + } + /** * Install certificates and key based on current configuration. * Note: the certificates and keys in the configuration will get cleared once diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 1c89190dd..e7216ce4a 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -237,6 +237,13 @@ public class WifiMetricsTest { private static final int NUM_WIFICOND_CRASHES = 12; private static final int NUM_WIFI_ON_FAILURE_DUE_TO_HAL = 13; private static final int NUM_WIFI_ON_FAILURE_DUE_TO_WIFICOND = 14; + private static final int NUM_PASSPOINT_PROVIDERS = 4; + private static final int NUM_PASSPOINT_PROVIDER_INSTALLATION = 5; + private static final int NUM_PASSPOINT_PROVIDER_INSTALL_SUCCESS = 4; + private static final int NUM_PASSPOINT_PROVIDER_UNINSTALLATION = 3; + private static final int NUM_PASSPOINT_PROVIDER_UNINSTALL_SUCCESS = 2; + private static final int NUM_PASSPOINT_PROVIDERS_SUCCESSFULLY_CONNECTED = 1; + private ScanDetail buildMockScanDetail(boolean hidden, NetworkDetail.HSRelease hSRelease, String capabilities) { @@ -288,6 +295,8 @@ public class WifiMetricsTest { */ public void setAndIncrementMetrics() throws Exception { mWifiMetrics.updateSavedNetworks(buildSavedNetworkList()); + mWifiMetrics.updateSavedPasspointProfiles(NUM_PASSPOINT_PROVIDERS, + NUM_PASSPOINT_PROVIDERS_SUCCESSFULLY_CONNECTED); mWifiMetrics.setIsLocationEnabled(TEST_VAL_IS_LOCATION_ENABLED); mWifiMetrics.setIsScanningAlwaysEnabled(IS_SCANNING_ALWAYS_ENABLED); @@ -421,6 +430,18 @@ public class WifiMetricsTest { for (int i = 0; i < NUM_WIFI_ON_FAILURE_DUE_TO_WIFICOND; i++) { mWifiMetrics.incrementNumWifiOnFailureDueToWificond(); } + for (int i = 0; i < NUM_PASSPOINT_PROVIDER_INSTALLATION; i++) { + mWifiMetrics.incrementNumPasspointProviderInstallation(); + } + for (int i = 0; i < NUM_PASSPOINT_PROVIDER_INSTALL_SUCCESS; i++) { + mWifiMetrics.incrementNumPasspointProviderInstallSuccess(); + } + for (int i = 0; i < NUM_PASSPOINT_PROVIDER_UNINSTALLATION; i++) { + mWifiMetrics.incrementNumPasspointProviderUninstallation(); + } + for (int i = 0; i < NUM_PASSPOINT_PROVIDER_UNINSTALL_SUCCESS; i++) { + mWifiMetrics.incrementNumPasspointProviderUninstallSuccess(); + } } /** @@ -563,6 +584,17 @@ public class WifiMetricsTest { mDeserializedWifiMetrics.numWifiOnFailureDueToHal); assertEquals(NUM_WIFI_ON_FAILURE_DUE_TO_WIFICOND, mDeserializedWifiMetrics.numWifiOnFailureDueToWificond); + assertEquals(NUM_PASSPOINT_PROVIDERS, mDeserializedWifiMetrics.numPasspointProviders); + assertEquals(NUM_PASSPOINT_PROVIDER_INSTALLATION, + mDeserializedWifiMetrics.numPasspointProviderInstallation); + assertEquals(NUM_PASSPOINT_PROVIDER_INSTALL_SUCCESS, + mDeserializedWifiMetrics.numPasspointProviderInstallSuccess); + assertEquals(NUM_PASSPOINT_PROVIDER_UNINSTALLATION, + 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 d2762d022..01566c203 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java @@ -69,6 +69,7 @@ import com.android.server.wifi.SIMAccessor; import com.android.server.wifi.WifiConfigManager; import com.android.server.wifi.WifiConfigStore; import com.android.server.wifi.WifiKeyStore; +import com.android.server.wifi.WifiMetrics; import com.android.server.wifi.WifiNative; import com.android.server.wifi.hotspot2.anqp.ANQPElement; import com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType; @@ -128,6 +129,7 @@ public class PasspointManagerTest { @Mock WifiConfigManager mWifiConfigManager; @Mock WifiConfigStore mWifiConfigStore; @Mock PasspointConfigStoreData.DataSource mDataSource; + @Mock WifiMetrics mWifiMetrics; PasspointManager mManager; /** Sets up test. */ @@ -139,7 +141,7 @@ public class PasspointManagerTest { .thenReturn(mAnqpRequestManager); when(mObjectFactory.makeCertificateVerifier()).thenReturn(mCertVerifier); mManager = new PasspointManager(mContext, mWifiNative, mWifiKeyStore, mClock, - mSimAccessor, mObjectFactory, mWifiConfigManager, mWifiConfigStore); + mSimAccessor, mObjectFactory, mWifiConfigManager, mWifiConfigStore, mWifiMetrics); ArgumentCaptor<PasspointEventHandler.Callbacks> callbacks = ArgumentCaptor.forClass(PasspointEventHandler.Callbacks.class); verify(mObjectFactory).makePasspointEventHandler(any(WifiNative.class), @@ -411,6 +413,8 @@ public class PasspointManagerTest { @Test public void addProviderWithNullConfig() throws Exception { assertFalse(mManager.addOrUpdateProvider(null, TEST_CREATOR_UID)); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); } /** @@ -421,6 +425,8 @@ public class PasspointManagerTest { @Test public void addProviderWithEmptyConfig() throws Exception { assertFalse(mManager.addOrUpdateProvider(new PasspointConfiguration(), TEST_CREATOR_UID)); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); } /** @@ -435,6 +441,8 @@ public class PasspointManagerTest { // EAP-TLS not allowed for user credential. config.getCredential().getUserCredential().setEapType(EAPConstants.EAP_TLS); assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); } /** @@ -451,6 +459,9 @@ public class PasspointManagerTest { assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); verifyInstalledConfig(config); verify(mWifiConfigManager).saveToStore(true); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); + reset(mWifiMetrics); reset(mWifiConfigManager); // Verify content in the data source. @@ -464,6 +475,8 @@ public class PasspointManagerTest { assertTrue(mManager.removeProvider(TEST_FQDN)); verify(provider).uninstallCertsAndKeys(); verify(mWifiConfigManager).saveToStore(true); + verify(mWifiMetrics).incrementNumPasspointProviderUninstallation(); + verify(mWifiMetrics).incrementNumPasspointProviderUninstallSuccess(); assertTrue(mManager.getProviderConfigs().isEmpty()); // Verify content in the data source. @@ -486,6 +499,9 @@ public class PasspointManagerTest { assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); verifyInstalledConfig(config); verify(mWifiConfigManager).saveToStore(true); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); + reset(mWifiMetrics); reset(mWifiConfigManager); // Verify content in the data source. @@ -499,6 +515,8 @@ public class PasspointManagerTest { assertTrue(mManager.removeProvider(TEST_FQDN)); verify(provider).uninstallCertsAndKeys(); verify(mWifiConfigManager).saveToStore(true); + verify(mWifiMetrics).incrementNumPasspointProviderUninstallation(); + verify(mWifiMetrics).incrementNumPasspointProviderUninstallSuccess(); assertTrue(mManager.getProviderConfigs().isEmpty()); // Verify content in the data source. @@ -524,6 +542,9 @@ public class PasspointManagerTest { assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID)); verifyInstalledConfig(origConfig); verify(mWifiConfigManager).saveToStore(true); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); + reset(mWifiMetrics); reset(mWifiConfigManager); // Verify data source content. @@ -541,6 +562,8 @@ public class PasspointManagerTest { assertTrue(mManager.addOrUpdateProvider(newConfig, TEST_CREATOR_UID)); verifyInstalledConfig(newConfig); verify(mWifiConfigManager).saveToStore(true); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); // Verify data source content. List<PasspointProvider> newProviders = mDataSource.getProviders(); @@ -563,6 +586,8 @@ public class PasspointManagerTest { when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(provider); assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); } /** @@ -576,6 +601,8 @@ public class PasspointManagerTest { doThrow(new GeneralSecurityException()) .when(mCertVerifier).verifyCaCert(any(X509Certificate.class)); assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); } /** @@ -594,6 +621,8 @@ public class PasspointManagerTest { assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); verify(mCertVerifier, never()).verifyCaCert(any(X509Certificate.class)); verifyInstalledConfig(config); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); } /** @@ -604,6 +633,8 @@ public class PasspointManagerTest { @Test public void removeNonExistingProvider() throws Exception { assertFalse(mManager.removeProvider(TEST_FQDN)); + verify(mWifiMetrics).incrementNumPasspointProviderUninstallation(); + verify(mWifiMetrics, never()).incrementNumPasspointProviderUninstallSuccess(); } /** @@ -1184,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()); + } } |