From 26b97ef6a6d8e755e7db541afa84aacd807599d7 Mon Sep 17 00:00:00 2001 From: Peter Qiu Date: Thu, 22 Jun 2017 14:49:02 -0700 Subject: WifiMetrics: add support for Passpoint related metrics The support for tracking number of Passpoint providers that provided successful network connection will be added in the upcoming CL. Bug: 36358031 Test: frameworks/wifi/tests/wifitests/runtests.sh Change-Id: Id0dc3bc6a3d30785c883b8a478be9b23911d3747 --- .../com/android/server/wifi/WifiMetricsTest.java | 29 +++++++++++++++++++ .../server/wifi/hotspot2/PasspointManagerTest.java | 33 +++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 1c89190dd..e58928bf5 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,7 @@ public class WifiMetricsTest { */ public void setAndIncrementMetrics() throws Exception { mWifiMetrics.updateSavedNetworks(buildSavedNetworkList()); + mWifiMetrics.updateSavedPasspointProfiles(NUM_PASSPOINT_PROVIDERS); mWifiMetrics.setIsLocationEnabled(TEST_VAL_IS_LOCATION_ENABLED); mWifiMetrics.setIsScanningAlwaysEnabled(IS_SCANNING_ALWAYS_ENABLED); @@ -421,6 +429,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 +583,15 @@ 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); } /** 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..a8dd831ed 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 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 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(); } /** -- cgit v1.2.3