From 72ca252ebfb5d91b13627a5f95b89db7b6adc1e5 Mon Sep 17 00:00:00 2001 From: Etan Cohen Date: Mon, 9 Oct 2017 10:30:50 -0700 Subject: [PASSPOINT] Add metrics to determine deployment/avail of Passpoint Add metrics which will help determine Passpoint availability in the wild. The metrics measure the percentage of time a Passpoint network is visible to user - by collecting historgrams of observations per scan result. (cherry-pick of commit 9831c1a04929d8d2cadbebbc1e6843895653bd4c) Bug: 66951771 Test: unit test Change-Id: I80af113f120515d86b2b6adb3e44ce37e97d5441 Merged-In: I51e05e9a075259544008107810c4489e8111cfcd --- .../com/android/server/wifi/WifiMetricsTest.java | 88 +++++++++++++++++++++- 1 file changed, 87 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 65427beb2..6e0b7759c 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -18,7 +18,9 @@ package com.android.server.wifi; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import android.net.NetworkAgent; import android.net.wifi.ScanResult; @@ -311,6 +313,23 @@ public class WifiMetricsTest { return mockScanDetail; } + private ScanDetail buildMockScanDetailPasspoint(String ssid, String bssid, long hessid, + int anqpDomainId, NetworkDetail.HSRelease hsRelease) { + ScanDetail mockScanDetail = mock(ScanDetail.class); + NetworkDetail mockNetworkDetail = mock(NetworkDetail.class); + ScanResult scanResult = new ScanResult(); + scanResult.SSID = ssid; + scanResult.BSSID = bssid; + scanResult.hessid = hessid; + scanResult.capabilities = "PSK"; + when(mockScanDetail.getNetworkDetail()).thenReturn(mockNetworkDetail); + when(mockScanDetail.getScanResult()).thenReturn(scanResult); + when(mockNetworkDetail.getHSRelease()).thenReturn(hsRelease); + when(mockNetworkDetail.getAnqpDomainID()).thenReturn(anqpDomainId); + when(mockNetworkDetail.isInterworking()).thenReturn(true); + return mockScanDetail; + } + private List buildMockScanDetailList() { List mockScanDetails = new ArrayList(); mockScanDetails.add(buildMockScanDetail(true, null, "[ESS]")); @@ -1270,6 +1289,73 @@ public class WifiMetricsTest { a(WifiMetrics.MAX_CONNECTABLE_BSSID_NETWORK_BUCKET), a(1)); } + /** + * Test that Hotspot 2.0 (Passpoint) scan results are collected correctly and that relevant + * bounds are observed. + */ + @Test + public void testObservedHotspotAps() throws Exception { + List scan = new ArrayList(); + // 2 R1 (Unknown AP isn't counted) passpoint APs belonging to a single provider: hessid1 + long hessid1 = 10; + int anqpDomainId1 = 5; + scan.add(buildMockScanDetailPasspoint("PASSPOINT_XX", "00:02:03:04:05:06", hessid1, + anqpDomainId1, NetworkDetail.HSRelease.R1)); + scan.add(buildMockScanDetailPasspoint("PASSPOINT_XY", "01:02:03:04:05:06", hessid1, + anqpDomainId1, NetworkDetail.HSRelease.R1)); + scan.add(buildMockScanDetailPasspoint("PASSPOINT_XYZ", "02:02:03:04:05:06", hessid1, + anqpDomainId1, NetworkDetail.HSRelease.Unknown)); + // 2 R2 passpoint APs belonging to a single provider: hessid2 + long hessid2 = 12; + int anqpDomainId2 = 6; + scan.add(buildMockScanDetailPasspoint("PASSPOINT_Y", "AA:02:03:04:05:06", hessid2, + anqpDomainId2, NetworkDetail.HSRelease.R2)); + scan.add(buildMockScanDetailPasspoint("PASSPOINT_Z", "AB:02:03:04:05:06", hessid2, + anqpDomainId2, NetworkDetail.HSRelease.R2)); + mWifiMetrics.incrementAvailableNetworksHistograms(scan, true); + scan = new ArrayList(); + // 3 R2 passpoint APs belonging to a single provider: hessid3 (in next scan) + long hessid3 = 15; + int anqpDomainId3 = 8; + scan.add(buildMockScanDetailPasspoint("PASSPOINT_Y", "AA:02:03:04:05:06", hessid3, + anqpDomainId3, NetworkDetail.HSRelease.R2)); + scan.add(buildMockScanDetailPasspoint("PASSPOINT_Y", "AA:02:03:04:05:06", hessid3, + anqpDomainId3, NetworkDetail.HSRelease.R2)); + scan.add(buildMockScanDetailPasspoint("PASSPOINT_Z", "AB:02:03:04:05:06", hessid3, + anqpDomainId3, NetworkDetail.HSRelease.R2)); + mWifiMetrics.incrementAvailableNetworksHistograms(scan, true); + dumpProtoAndDeserialize(); + + verifyHist(mDecodedProto.observedHotspotR1ApsInScanHistogram, 2, a(0, 2), a(1, 1)); + verifyHist(mDecodedProto.observedHotspotR2ApsInScanHistogram, 2, a(2, 3), a(1, 1)); + verifyHist(mDecodedProto.observedHotspotR1EssInScanHistogram, 2, a(0, 1), a(1, 1)); + verifyHist(mDecodedProto.observedHotspotR2EssInScanHistogram, 1, a(1), a(2)); + verifyHist(mDecodedProto.observedHotspotR1ApsPerEssInScanHistogram, 1, a(2), a(1)); + verifyHist(mDecodedProto.observedHotspotR2ApsPerEssInScanHistogram, 2, a(2, 3), a(1, 1)); + + // check bounds + scan.clear(); + int lotsOfSSids = Math.max(WifiMetrics.MAX_TOTAL_PASSPOINT_APS_BUCKET, + WifiMetrics.MAX_TOTAL_PASSPOINT_UNIQUE_ESS_BUCKET) + 5; + for (int i = 0; i < lotsOfSSids; i++) { + scan.add(buildMockScanDetailPasspoint("PASSPOINT_XX" + i, "00:02:03:04:05:06", i, + i + 10, NetworkDetail.HSRelease.R1)); + scan.add(buildMockScanDetailPasspoint("PASSPOINT_XY" + i, "AA:02:03:04:05:06", 1000 * i, + i + 10, NetworkDetail.HSRelease.R2)); + } + mWifiMetrics.incrementAvailableNetworksHistograms(scan, true); + dumpProtoAndDeserialize(); + verifyHist(mDecodedProto.observedHotspotR1ApsInScanHistogram, 1, + a(WifiMetrics.MAX_TOTAL_PASSPOINT_APS_BUCKET), a(1)); + verifyHist(mDecodedProto.observedHotspotR2ApsInScanHistogram, 1, + a(WifiMetrics.MAX_TOTAL_PASSPOINT_APS_BUCKET), a(1)); + verifyHist(mDecodedProto.observedHotspotR1EssInScanHistogram, 1, + a(WifiMetrics.MAX_TOTAL_PASSPOINT_UNIQUE_ESS_BUCKET), a(1)); + verifyHist(mDecodedProto.observedHotspotR2EssInScanHistogram, 1, + a(WifiMetrics.MAX_TOTAL_PASSPOINT_UNIQUE_ESS_BUCKET), a(1)); + + } + /** * Test Open Network Notification blacklist size and feature state are not cleared when proto * is dumped. -- cgit v1.2.3