From b54f07e01c9daef8883c85e09f61436f2c06cc72 Mon Sep 17 00:00:00 2001 From: Peter Qiu Date: Tue, 7 Mar 2017 14:56:15 -0800 Subject: hotspot2: update semantics for PasspointManager#matchProvider Instead of returning a list of matched providers, it will now return the best provider for the given AP (based on ScanResult). It will return null if no match is found. So PasspointManager is responsible for ranking providers for a given AP (based on ScanResult), while PasspointNetworkEvalutor is responsible for ranking Passpoint networks with matched provider. Bug: 35888100 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Test: Manual test with Global Reach Passpoint AP Change-Id: I9e2a76aaf319f6180d7767fe8f713547221feb6c --- .../server/wifi/hotspot2/PasspointManagerTest.java | 38 ++++++++------------ .../hotspot2/PasspointNetworkEvaluatorTest.java | 42 ++++++++-------------- 2 files changed, 29 insertions(+), 51 deletions(-) (limited to 'tests') 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 a86d961ba..887e6354f 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java @@ -28,6 +28,7 @@ import static android.net.wifi.WifiManager.EXTRA_URL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyBoolean; @@ -552,19 +553,17 @@ public class PasspointManagerTest { } /** - * Verify that an empty list will be returned when no providers are installed. + * Verify that a {code null} will be returned when no providers are installed. * * @throws Exception */ @Test public void matchProviderWithNoProvidersInstalled() throws Exception { - List> result = - mManager.matchProvider(createTestScanResult()); - assertTrue(result.isEmpty()); + assertNull(mManager.matchProvider(createTestScanResult())); } /** - * Verify that an empty list will be returned when ANQP entry doesn't exist in the cache. + * Verify that a {code null} be returned when ANQP entry doesn't exist in the cache. * * @throws Exception */ @@ -573,17 +572,14 @@ public class PasspointManagerTest { addTestProvider(); when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(null); - List> result = - mManager.matchProvider(createTestScanResult()); + assertNull(mManager.matchProvider(createTestScanResult())); // Verify that a request for ANQP elements is initiated. verify(mAnqpRequestManager).requestANQPElements(eq(TEST_BSSID), any(ANQPNetworkKey.class), anyBoolean(), anyBoolean()); - assertTrue(result.isEmpty()); } /** - * Verify that the returned list will contained an expected provider when a HomeProvider - * is matched. + * Verify that the expected provider will be returned when a HomeProvider is matched. * * @throws Exception */ @@ -594,15 +590,14 @@ public class PasspointManagerTest { when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); when(provider.match(anyMap())).thenReturn(PasspointMatch.HomeProvider); - List> result = + Pair result = mManager.matchProvider(createTestScanResult()); - assertEquals(1, result.size()); - assertEquals(PasspointMatch.HomeProvider, result.get(0).second); + assertEquals(PasspointMatch.HomeProvider, result.second); + assertEquals(TEST_FQDN, result.first.getConfig().getHomeSp().getFqdn()); } /** - * Verify that the returned list will contained an expected provider when a RoamingProvider - * is matched. + * Verify that the expected provider will be returned when a RoamingProvider is matched. * * @throws Exception */ @@ -613,15 +608,14 @@ public class PasspointManagerTest { when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); when(provider.match(anyMap())).thenReturn(PasspointMatch.RoamingProvider); - List> result = + Pair result = mManager.matchProvider(createTestScanResult()); - assertEquals(1, result.size()); - assertEquals(PasspointMatch.RoamingProvider, result.get(0).second); - assertEquals(TEST_FQDN, provider.getConfig().getHomeSp().getFqdn()); + assertEquals(PasspointMatch.RoamingProvider, result.second); + assertEquals(TEST_FQDN, result.first.getConfig().getHomeSp().getFqdn()); } /** - * Verify that an empty list will be returned when there is no matching provider. + * Verify that a {code null} will be returned when there is no matching provider. * * @throws Exception */ @@ -632,9 +626,7 @@ public class PasspointManagerTest { when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); when(provider.match(anyMap())).thenReturn(PasspointMatch.None); - List> result = - mManager.matchProvider(createTestScanResult()); - assertEquals(0, result.size()); + assertNull(mManager.matchProvider(createTestScanResult())); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java index 05d9ea225..c4527adc4 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java @@ -128,8 +128,7 @@ public class PasspointNetworkEvaluatorTest { List scanDetails = Arrays.asList(new ScanDetail[] { generateScanDetail(TEST_SSID1), generateScanDetail(TEST_SSID2)}); List> connectableNetworks = new ArrayList<>(); - List> matchedProviders = new ArrayList<>(); - when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(matchedProviders); + when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(null); assertEquals(null, mEvaluator.evaluateNetworks( scanDetails, null, null, false, false, connectableNetworks)); assertTrue(connectableNetworks.isEmpty()); @@ -158,31 +157,26 @@ public class PasspointNetworkEvaluatorTest { } /** - * Verify that when both home provider and roaming provider is found for the same network, - * home provider is preferred. + * Verify that when a network matches a home provider is found, the correct network + * information (WifiConfiguration) is setup and returned. * * @throws Exception */ @Test - public void evaluateScansWithNetworkMatchingHomeAndRoamingProvider() throws Exception { + public void evaluateScansWithNetworkMatchingHomeProvider() throws Exception { List scanDetails = Arrays.asList(new ScanDetail[] { generateScanDetail(TEST_SSID1), generateScanDetail(TEST_SSID2)}); // Setup matching providers for ScanDetail with TEST_SSID1. Pair homeProvider = Pair.create( TEST_PROVIDER1, PasspointMatch.HomeProvider); - Pair roamingProvider = Pair.create( - TEST_PROVIDER2, PasspointMatch.RoamingProvider); - List> matchedProviders = new ArrayList<>(); - matchedProviders.add(homeProvider); - matchedProviders.add(roamingProvider); List> connectableNetworks = new ArrayList<>(); - // Return matchedProviders for the first ScanDetail (TEST_SSID1) and an empty list for + // Return homeProvider for the first ScanDetail (TEST_SSID1) and a null (no match) for // for the second (TEST_SSID2); - when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(matchedProviders) - .thenReturn(new ArrayList>()); + when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(homeProvider) + .thenReturn(null); when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt())) .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID)); when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1); @@ -217,15 +211,13 @@ public class PasspointNetworkEvaluatorTest { // Setup matching providers for ScanDetail with TEST_SSID1. Pair roamingProvider = Pair.create( TEST_PROVIDER1, PasspointMatch.RoamingProvider); - List> matchedProviders = new ArrayList<>(); - matchedProviders.add(roamingProvider); List> connectableNetworks = new ArrayList<>(); - // Return matchedProviders for the first ScanDetail (TEST_SSID1) and an empty list for + // Return roamingProvider for the first ScanDetail (TEST_SSID1) and a null (no match) for // for the second (TEST_SSID2); - when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(matchedProviders) - .thenReturn(new ArrayList>()); + when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(roamingProvider) + .thenReturn(null); when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt())) .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID)); when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1); @@ -262,17 +254,13 @@ public class PasspointNetworkEvaluatorTest { TEST_PROVIDER1, PasspointMatch.HomeProvider); Pair roamingProvider = Pair.create( TEST_PROVIDER2, PasspointMatch.RoamingProvider); - List> providerForScanDetail1 = new ArrayList<>(); - providerForScanDetail1.add(homeProvider); - List> providerForScanDetail2 = new ArrayList<>(); - providerForScanDetail2.add(roamingProvider); List> connectableNetworks = new ArrayList<>(); - // Return providerForScanDetail1 for the first ScanDetail (TEST_SSID1) and - // providerForScanDetail2 for the second (TEST_SSID2); + // Return homeProvider for the first ScanDetail (TEST_SSID1) and + // roamingProvider for the second (TEST_SSID2); when(mPasspointManager.matchProvider(any(ScanResult.class))) - .thenReturn(providerForScanDetail1).thenReturn(providerForScanDetail2); + .thenReturn(homeProvider).thenReturn(roamingProvider); when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt())) .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID)); when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1); @@ -307,8 +295,6 @@ public class PasspointNetworkEvaluatorTest { // Setup matching providers for both ScanDetail. Pair homeProvider = Pair.create( TEST_PROVIDER1, PasspointMatch.HomeProvider); - List> matchedProviders = new ArrayList<>(); - matchedProviders.add(homeProvider); // Setup currently connected network WifiConfiguration currentNetwork = new WifiConfiguration(); @@ -319,7 +305,7 @@ public class PasspointNetworkEvaluatorTest { // Returning the same matching provider for both ScanDetail. List> connectableNetworks = new ArrayList<>(); when(mPasspointManager.matchProvider(any(ScanResult.class))) - .thenReturn(matchedProviders).thenReturn(matchedProviders); + .thenReturn(homeProvider).thenReturn(homeProvider); WifiConfiguration config = mEvaluator.evaluateNetworks(scanDetails, currentNetwork, currentBssid, true, false, connectableNetworks); assertEquals(1, connectableNetworks.size()); -- cgit v1.2.3