diff options
author | Roshan Pius <rpius@google.com> | 2019-03-01 10:33:38 -0800 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2019-03-06 10:11:24 -0800 |
commit | 308adb4a09f544bdc8260031286e400338ce892b (patch) | |
tree | 2cea668da2b750de905e567d57aacb1e31f0ec22 /tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java | |
parent | 1e06b4a69e237bb570fc925c60227de60598d4f3 (diff) | |
download | android_frameworks_opt_net_wifi-308adb4a09f544bdc8260031286e400338ce892b.tar.gz android_frameworks_opt_net_wifi-308adb4a09f544bdc8260031286e400338ce892b.tar.bz2 android_frameworks_opt_net_wifi-308adb4a09f544bdc8260031286e400338ce892b.zip |
WifiMetrics: Report metrics for new API surfaces
Changes to report metrics for the new API surface usage.
Also,
a) Added a new maxSize field in WifiNetworkSuggestionsManager to track
the maximum size of suggestion list ever for that app.
b) Record the nominator names in existing connection event metrics.
Bug: 123362619
Bug: 123362779
Test: adb shell dumpsys wifi wifiMetricsProto
Test: ./frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Change-Id: I801ce489941259be9185e3dbc1133ff04bae5c71
Diffstat (limited to 'tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java index 02a2dc096..eb09d239b 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java @@ -101,6 +101,7 @@ public class WifiNetworkSuggestionsManagerTest { private @Mock WifiConfigManager mWifiConfigManager; private @Mock NetworkSuggestionStoreData mNetworkSuggestionStoreData; private @Mock ClientModeImpl mClientModeImpl; + private @Mock WifiMetrics mWifiMetrics; private TestLooper mLooper; private ArgumentCaptor<AppOpsManager.OnOpChangedListener> mAppOpChangedListenerCaptor = ArgumentCaptor.forClass(AppOpsManager.OnOpChangedListener.class); @@ -157,7 +158,8 @@ public class WifiNetworkSuggestionsManagerTest { mWifiNetworkSuggestionsManager = new WifiNetworkSuggestionsManager(mContext, new Handler(mLooper.getLooper()), - mWifiInjector, mWifiPermissionsUtil, mWifiConfigManager, mWifiConfigStore); + mWifiInjector, mWifiPermissionsUtil, mWifiConfigManager, mWifiConfigStore, + mWifiMetrics); verify(mContext).getResources(); verify(mContext).getSystemService(Context.APP_OPS_SERVICE); verify(mContext).getSystemService(Context.NOTIFICATION_SERVICE); @@ -208,6 +210,13 @@ public class WifiNetworkSuggestionsManagerTest { add(networkSuggestion2); }}; assertEquals(expectedAllNetworkSuggestions, allNetworkSuggestions); + + verify(mWifiMetrics, times(2)).incrementNetworkSuggestionApiNumModification(); + ArgumentCaptor<List<Integer>> maxSizesCaptor = ArgumentCaptor.forClass(List.class); + verify(mWifiMetrics, times(2)).noteNetworkSuggestionApiListSizeHistogram( + maxSizesCaptor.capture()); + assertNotNull(maxSizesCaptor.getValue()); + assertEquals(maxSizesCaptor.getValue(), new ArrayList<Integer>() {{ add(1); add(1); }}); } /** @@ -243,6 +252,13 @@ public class WifiNetworkSuggestionsManagerTest { mWifiNetworkSuggestionsManager.remove(networkSuggestionList2, TEST_PACKAGE_2)); assertTrue(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions().isEmpty()); + + verify(mWifiMetrics, times(4)).incrementNetworkSuggestionApiNumModification(); + ArgumentCaptor<List<Integer>> maxSizesCaptor = ArgumentCaptor.forClass(List.class); + verify(mWifiMetrics, times(4)).noteNetworkSuggestionApiListSizeHistogram( + maxSizesCaptor.capture()); + assertNotNull(maxSizesCaptor.getValue()); + assertEquals(maxSizesCaptor.getValue(), new ArrayList<Integer>() {{ add(1); add(1); }}); } /** @@ -745,6 +761,8 @@ public class WifiNetworkSuggestionsManagerTest { WifiMetrics.ConnectionEvent.FAILURE_NONE, networkSuggestion.wifiConfiguration, TEST_BSSID); + verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectSuccess(); + // Verify that the correct broadcast was sent out. mInorder.verify(mWifiPermissionsUtil) .enforceCanAccessScanResults(TEST_PACKAGE_1, TEST_UID_1); @@ -755,6 +773,34 @@ public class WifiNetworkSuggestionsManagerTest { } /** + * Verify a successful lookup of a single network suggestion matching the current network + * connection failure. + */ + @Test + public void testOnNetworkConnectionFailureWithOneMatch() { + WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( + WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1, + TEST_PACKAGE_1); + List<WifiNetworkSuggestion> networkSuggestionList = + new ArrayList<WifiNetworkSuggestion>() {{ + add(networkSuggestion); + }}; + assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, + mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_PACKAGE_1)); + mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); + + // Simulate connecting to the network. + mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( + WifiMetrics.ConnectionEvent.FAILURE_DHCP, networkSuggestion.wifiConfiguration, + TEST_BSSID); + + verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectFailure(); + + // Verify no more broadcast were sent out. + verifyNoMoreInteractions(mContext); + } + + /** * Verify a successful lookup of multiple network suggestion matching the connected network. * a) The corresponding network suggestion has the * {@link WifiNetworkSuggestion#isAppInteractionRequired} flag set. @@ -788,6 +834,8 @@ public class WifiNetworkSuggestionsManagerTest { mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( WifiMetrics.ConnectionEvent.FAILURE_NONE, wifiConfiguration, TEST_BSSID); + verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectSuccess(); + // Verify that the correct broadcasts were sent out. for (int i = 0; i < 2; i++) { ArgumentCaptor<String> packageNameCaptor = ArgumentCaptor.forClass(String.class); @@ -844,6 +892,8 @@ public class WifiNetworkSuggestionsManagerTest { mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( WifiMetrics.ConnectionEvent.FAILURE_NONE, wifiConfiguration, TEST_BSSID); + verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectSuccess(); + // Verify that the correct broadcasts were sent out. for (int i = 0; i < 2; i++) { ArgumentCaptor<String> packageNameCaptor = ArgumentCaptor.forClass(String.class); @@ -901,6 +951,8 @@ public class WifiNetworkSuggestionsManagerTest { mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( WifiMetrics.ConnectionEvent.FAILURE_NONE, wifiConfiguration1, TEST_BSSID); + verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectSuccess(); + // Verify that the correct broadcasts were sent out. for (int i = 0; i < 2; i++) { ArgumentCaptor<String> packageNameCaptor = ArgumentCaptor.forClass(String.class); |