diff options
author | Peter Qiu <zqiu@google.com> | 2017-03-27 09:26:34 -0700 |
---|---|---|
committer | Peter Qiu <zqiu@google.com> | 2017-03-31 10:45:29 -0700 |
commit | d6ba42b153a41a19c9ce4fb8e63abbe859ad67e9 (patch) | |
tree | e4877bccd269f210b773095a9bb4b0355c82e1bf | |
parent | 3108e4b84d64353b6a055655af92271c98ad267e (diff) |
hotspot2: set WifiConfiguration#isHomeProviderNetwork for Passpoint networks
When creating a WifiConfiguration for a Passpoint network, set
isHomeProviderNetwork based on the matching status, set to true
when matching a home Passpoint provider.
Bug: 36592220
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Change-Id: Ibe0d9b2f19f9d563547788dba45cee9bcde6a233
4 files changed, 57 insertions, 36 deletions
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java index f472d86db..6103b494e 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java @@ -450,6 +450,9 @@ public class PasspointManager { } WifiConfiguration config = matchedProvider.first.getWifiConfig(); config.SSID = ScanResultUtil.createQuotedSSID(scanResult.SSID); + if (matchedProvider.second == PasspointMatch.HomeProvider) { + config.isHomeProviderNetwork = true; + } return config; } diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java index 1bade6c52..132a2f22c 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java @@ -42,6 +42,21 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva private final WifiConfigManager mWifiConfigManager; private final LocalLog mLocalLog; + /** + * Contained information for a Passpoint network candidate. + */ + private class PasspointNetworkCandidate { + PasspointNetworkCandidate(PasspointProvider provider, PasspointMatch matchStatus, + ScanDetail scanDetail) { + mProvider = provider; + mMatchStatus = matchStatus; + mScanDetail = scanDetail; + } + PasspointProvider mProvider; + PasspointMatch mMatchStatus; + ScanDetail mScanDetail; + } + public PasspointNetworkEvaluator(PasspointManager passpointManager, WifiConfigManager wifiConfigManager, LocalLog localLog) { mPasspointManager = passpointManager; @@ -66,8 +81,7 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva mPasspointManager.sweepCache(); // Go through each ScanDetail and find the best provider for each ScanDetail. - List<Pair<ScanDetail, Pair<PasspointProvider, PasspointMatch>>> providerList = - new ArrayList<>(); + List<PasspointNetworkCandidate> candidateList = new ArrayList<>(); for (ScanDetail scanDetail : scanDetails) { // Skip non-Passpoint APs. if (!scanDetail.getNetworkDetail().isInterworking()) { @@ -78,31 +92,31 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva Pair<PasspointProvider, PasspointMatch> bestProvider = mPasspointManager.matchProvider(scanDetail.getScanResult()); if (bestProvider != null) { - providerList.add(Pair.create(scanDetail, bestProvider)); + candidateList.add(new PasspointNetworkCandidate( + bestProvider.first, bestProvider.second, scanDetail)); } } - // Done if no matching provider is found. - if (providerList.isEmpty()) { + // Done if no candidate is found. + if (candidateList.isEmpty()) { localLog("No suitable Passpoint network found"); return null; } - // Find the best Passpoint network among all matches. - Pair<PasspointProvider, ScanDetail> bestNetwork = findBestNetwork(providerList, - currentNetwork == null ? null : currentNetwork.SSID); + // Find the best Passpoint network among all candidates. + PasspointNetworkCandidate bestNetwork = + findBestNetwork(candidateList, currentNetwork == null ? null : currentNetwork.SSID); // Return the configuration for the current connected network if it is the best network. if (currentNetwork != null && TextUtils.equals(currentNetwork.SSID, - ScanResultUtil.createQuotedSSID(bestNetwork.second.getSSID()))) { + ScanResultUtil.createQuotedSSID(bestNetwork.mScanDetail.getSSID()))) { localLog("Staying with current Passpoint network " + currentNetwork.SSID); - connectableNetworks.add(Pair.create(bestNetwork.second, currentNetwork)); + connectableNetworks.add(Pair.create(bestNetwork.mScanDetail, currentNetwork)); return currentNetwork; } - WifiConfiguration config = - createWifiConfigForProvider(bestNetwork.first, bestNetwork.second); - connectableNetworks.add(Pair.create(bestNetwork.second, config)); + WifiConfiguration config = createWifiConfigForProvider(bestNetwork); + connectableNetworks.add(Pair.create(bestNetwork.mScanDetail, config)); localLog("Passpoint network to connect to: " + config.SSID); return config; } @@ -111,14 +125,15 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva * Create and return a WifiConfiguration for the given ScanDetail and PasspointProvider. * The newly created WifiConfiguration will also be added to WifiConfigManager. * - * @param provider The provider to create WifiConfiguration from - * @param scanDetail The ScanDetail to create WifiConfiguration from + * @param networkInfo Contained information for the Passpoint network to connect to * @return {@link WifiConfiguration} */ - private WifiConfiguration createWifiConfigForProvider(PasspointProvider provider, - ScanDetail scanDetail) { - WifiConfiguration config = provider.getWifiConfig(); - config.SSID = ScanResultUtil.createQuotedSSID(scanDetail.getSSID()); + private WifiConfiguration createWifiConfigForProvider(PasspointNetworkCandidate networkInfo) { + WifiConfiguration config = networkInfo.mProvider.getWifiConfig(); + config.SSID = ScanResultUtil.createQuotedSSID(networkInfo.mScanDetail.getSSID()); + if (networkInfo.mMatchStatus == PasspointMatch.HomeProvider) { + config.isHomeProviderNetwork = true; + } // Add the newly created WifiConfiguration to WifiConfigManager. NetworkUpdateResult result = @@ -129,8 +144,9 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva } mWifiConfigManager.enableNetwork(result.getNetworkId(), false, Process.WIFI_UID); mWifiConfigManager.setNetworkCandidateScanResult(result.getNetworkId(), - scanDetail.getScanResult(), 0); - mWifiConfigManager.updateScanDetailForNetwork(result.getNetworkId(), scanDetail); + networkInfo.mScanDetail.getScanResult(), 0); + mWifiConfigManager.updateScanDetailForNetwork( + result.getNetworkId(), networkInfo.mScanDetail); return mWifiConfigManager.getConfiguredNetwork(result.getNetworkId()); } @@ -141,18 +157,15 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva * * @param networkList List of Passpoint networks * @param currentNetworkSsid The SSID of the currently connected network, null if not connected - * @return {@link PasspointProvider} and {@link ScanDetail} associated with the network + * @return {@link PasspointNetworkCandidate} */ - private Pair<PasspointProvider, ScanDetail> findBestNetwork( - List<Pair<ScanDetail, Pair<PasspointProvider, PasspointMatch>>> networkList, - String currentNetworkSsid) { - ScanDetail bestScanDetail = null; - PasspointProvider bestProvider = null; + private PasspointNetworkCandidate findBestNetwork( + List<PasspointNetworkCandidate> networkList, String currentNetworkSsid) { + PasspointNetworkCandidate bestCandidate = null; int bestScore = Integer.MIN_VALUE; - for (Pair<ScanDetail, Pair<PasspointProvider, PasspointMatch>> candidate : networkList) { - ScanDetail scanDetail = candidate.first; - PasspointProvider provider = candidate.second.first; - PasspointMatch match = candidate.second.second; + for (PasspointNetworkCandidate candidate : networkList) { + ScanDetail scanDetail = candidate.mScanDetail; + PasspointMatch match = candidate.mMatchStatus; boolean isActiveNetwork = TextUtils.equals(currentNetworkSsid, ScanResultUtil.createQuotedSSID(scanDetail.getSSID())); @@ -161,14 +174,13 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva isActiveNetwork); if (score > bestScore) { - bestScanDetail = scanDetail; - bestProvider = provider; + bestCandidate = candidate; bestScore = score; } } - localLog("Best Passpoint network " + bestScanDetail.getSSID() + " provided by " - + bestProvider.getConfig().getHomeSp().getFqdn()); - return Pair.create(bestProvider, bestScanDetail); + localLog("Best Passpoint network " + bestCandidate.mScanDetail.getSSID() + " provided by " + + bestCandidate.mProvider.getConfig().getHomeSp().getFqdn()); + return bestCandidate; } private void localLog(String log) { 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 8008bf68e..5ac94ec78 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java @@ -691,6 +691,7 @@ public class PasspointManagerTest { when(provider.getWifiConfig()).thenReturn(new WifiConfiguration()); WifiConfiguration config = mManager.getMatchingWifiConfig(createTestScanResult()); assertEquals(ScanResultUtil.createQuotedSSID(TEST_SSID), config.SSID); + assertTrue(config.isHomeProviderNetwork); } /** @@ -709,6 +710,7 @@ public class PasspointManagerTest { when(provider.getWifiConfig()).thenReturn(new WifiConfiguration()); WifiConfiguration config = mManager.getMatchingWifiConfig(createTestScanResult()); assertEquals(ScanResultUtil.createQuotedSSID(TEST_SSID), config.SSID); + assertFalse(config.isHomeProviderNetwork); } /** 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 cb20d0ccd..2224486ba 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java @@ -17,6 +17,7 @@ package com.android.server.wifi.hotspot2; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.any; @@ -201,6 +202,7 @@ public class PasspointNetworkEvaluatorTest { verify(mWifiConfigManager).addOrUpdateNetwork(addedConfig.capture(), anyInt()); assertEquals(ScanResultUtil.createQuotedSSID(TEST_SSID1), addedConfig.getValue().SSID); assertEquals(TEST_FQDN1, addedConfig.getValue().FQDN); + assertTrue(addedConfig.getValue().isHomeProviderNetwork); verify(mWifiConfigManager).enableNetwork(eq(TEST_NETWORK_ID), eq(false), anyInt()); verify(mWifiConfigManager).setNetworkCandidateScanResult( eq(TEST_NETWORK_ID), any(ScanResult.class), anyInt()); @@ -242,6 +244,7 @@ public class PasspointNetworkEvaluatorTest { verify(mWifiConfigManager).addOrUpdateNetwork(addedConfig.capture(), anyInt()); assertEquals(ScanResultUtil.createQuotedSSID(TEST_SSID1), addedConfig.getValue().SSID); assertEquals(TEST_FQDN1, addedConfig.getValue().FQDN); + assertFalse(addedConfig.getValue().isHomeProviderNetwork); verify(mWifiConfigManager).enableNetwork(eq(TEST_NETWORK_ID), eq(false), anyInt()); verify(mWifiConfigManager).setNetworkCandidateScanResult( eq(TEST_NETWORK_ID), any(ScanResult.class), anyInt()); @@ -285,6 +288,7 @@ public class PasspointNetworkEvaluatorTest { verify(mWifiConfigManager).addOrUpdateNetwork(addedConfig.capture(), anyInt()); assertEquals(ScanResultUtil.createQuotedSSID(TEST_SSID1), addedConfig.getValue().SSID); assertEquals(TEST_FQDN1, addedConfig.getValue().FQDN); + assertTrue(addedConfig.getValue().isHomeProviderNetwork); verify(mWifiConfigManager).enableNetwork(eq(TEST_NETWORK_ID), eq(false), anyInt()); verify(mWifiConfigManager).setNetworkCandidateScanResult( eq(TEST_NETWORK_ID), any(ScanResult.class), anyInt()); |