diff options
author | Randy Pan <zpan@google.com> | 2016-11-15 18:02:15 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-11-15 18:02:15 +0000 |
commit | 7fc06081539bbfdc51aee58698e73bf8cb933a5a (patch) | |
tree | 64e11edfb4ef5dd44d4014410a45b242bcb8bd00 | |
parent | b98623f8491bc0690f8f7ea723b8df78e50dc499 (diff) | |
parent | 2c698ca1d1b0460f61c84373a5a1f96e07e6a28b (diff) |
Merge "WifiConfigManager: partial scan channel list"
am: 2c698ca1d1
Change-Id: I895d5a9bdf013122d1f4e750067b58672c86a20d
5 files changed, 73 insertions, 30 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java index 812a3031d..0cad31f87 100644 --- a/service/java/com/android/server/wifi/WifiConfigManager.java +++ b/service/java/com/android/server/wifi/WifiConfigManager.java @@ -2066,10 +2066,12 @@ public class WifiConfigManager { * * @param networkId network ID corresponding to the network. * @param ageInMillis only consider scan details whose timestamps are earlier than this value. + * @param homeChannelFreq frequency of the currently connected network. * @return Set containing the frequencies on which this network was found, null if the network * was not found or there are no associated scan details in the cache. */ - public Set<Integer> fetchChannelSetForNetworkForPartialScan(int networkId, long ageInMillis) { + public Set<Integer> fetchChannelSetForNetworkForPartialScan(int networkId, long ageInMillis, + int homeChannelFreq) { WifiConfiguration config = getInternalConfiguredNetwork(networkId); if (config == null) { return null; @@ -2096,16 +2098,25 @@ public class WifiConfigManager { Log.v(TAG, dbg.toString()); } Set<Integer> channelSet = new HashSet<>(); + + // First add the currently connected network channel. + if (homeChannelFreq > 0) { + channelSet.add(homeChannelFreq); + if (channelSet.size() >= mMaxNumActiveChannelsForPartialScans) { + return channelSet; + } + } + long nowInMillis = mClock.getWallClockMillis(); - // First get channels for the network. + // Then get channels for the network. if (!addToChannelSetForNetworkFromScanDetailCache( channelSet, scanDetailCache, nowInMillis, ageInMillis, mMaxNumActiveChannelsForPartialScans)) { return channelSet; } - // Now get channels for linked networks. + // Lastly get channels for linked networks. if (config.linkedConfigurations != null) { for (String configKey : config.linkedConfigurations.keySet()) { WifiConfiguration linkedConfig = getInternalConfiguredNetwork(configKey); diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index 1fce14051..357fa32ed 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -650,7 +650,7 @@ public class WifiConnectivityManager { Set<Integer> freqs = mConfigManager.fetchChannelSetForNetworkForPartialScan( - config.networkId, CHANNEL_LIST_AGE_MS); + config.networkId, CHANNEL_LIST_AGE_MS, mWifiInfo.getFrequency()); if (freqs != null && freqs.size() != 0) { int index = 0; diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 38989ad3b..00b8648e4 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -5491,7 +5491,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss } Set<Integer> freqs = mWifiConfigManager.fetchChannelSetForNetworkForPartialScan( - config.networkId, ONE_HOUR_MILLI); + config.networkId, ONE_HOUR_MILLI, mWifiInfo.getFrequency()); if (freqs != null && freqs.size() != 0) { //if (mVerboseLoggingEnabled) { logd("starting scan for " + config.configKey() + " with " + freqs); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index b96d4e954..e7364b36d 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -1459,9 +1459,9 @@ public class WifiConfigManagerTest { } } - /* + /** * Verifies the creation of channel list using - * {@link WifiConfigManager#fetchChannelSetForNetworkForPartialScan(int, long)}. + * {@link WifiConfigManager#fetchChannelSetForNetworkForPartialScan(int, long, int)}. */ @Test public void testFetchChannelSetForNetwork() { @@ -1479,14 +1479,44 @@ public class WifiConfigManagerTest { } assertEquals(new HashSet<Integer>(Arrays.asList(TEST_FREQ_LIST)), - mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(network.networkId, 1)); + mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(network.networkId, 1, + TEST_FREQ_LIST[4])); + } + + /** + * Verifies the creation of channel list using + * {@link WifiConfigManager#fetchChannelSetForNetworkForPartialScan(int, long, int)} and + * ensures that the frequenecy of the currently connected network is in the returned + * channel set. + */ + @Test + public void testFetchChannelSetForNetworkIncludeCurrentNetwork() { + WifiConfiguration network = WifiConfigurationTestUtil.createPskNetwork(); + verifyAddNetworkToWifiConfigManager(network); + + // Create 5 scan results with different bssid's & frequencies. + String test_bssid_base = "af:89:56:34:56:6"; + for (int i = 0; i < TEST_FREQ_LIST.length; i++) { + ScanDetail networkScanDetail = + createScanDetailForNetwork( + network, test_bssid_base + Integer.toString(i), 0, TEST_FREQ_LIST[i]); + assertNotNull( + mWifiConfigManager.getSavedNetworkForScanDetailAndCache(networkScanDetail)); + + } + + // Currently connected network frequency 2427 is not in the TEST_FREQ_LIST + Set<Integer> freqs = mWifiConfigManager.fetchChannelSetForNetworkForPartialScan( + network.networkId, 1, 2427); + + assertEquals(true, freqs.contains(2427)); } /** * Verifies the creation of channel list using - * {@link WifiConfigManager#fetchChannelSetForNetworkForPartialScan(int, long)} and ensures - * that scan results which have a timestamp beyond the provided age are not used in the - * channel list. + * {@link WifiConfigManager#fetchChannelSetForNetworkForPartialScan(int, long, int)} and + * ensures that scan results which have a timestamp beyond the provided age are not used + * in the channel list. */ @Test public void testFetchChannelSetForNetworkIgnoresStaleScanResults() { @@ -1515,13 +1545,13 @@ public class WifiConfigManagerTest { TEST_FREQ_LIST, TEST_FREQ_LIST.length - ageInMillis, TEST_FREQ_LIST.length))), mWifiConfigManager.fetchChannelSetForNetworkForPartialScan( - network.networkId, ageInMillis)); + network.networkId, ageInMillis, TEST_FREQ_LIST[4])); } /** * Verifies the creation of channel list using - * {@link WifiConfigManager#fetchChannelSetForNetworkForPartialScan(int, long)} and ensures - * that the list size does not exceed the max configured for the device. + * {@link WifiConfigManager#fetchChannelSetForNetworkForPartialScan(int, long, int)} and + * ensures that the list size does not exceed the max configured for the device. */ @Test public void testFetchChannelSetForNetworkIsLimitedToConfiguredSize() { @@ -1549,13 +1579,13 @@ public class WifiConfigManagerTest { // Ensure that the fetched list size is limited. assertEquals(maxListSize, mWifiConfigManager.fetchChannelSetForNetworkForPartialScan( - network.networkId, 1).size()); + network.networkId, 1, TEST_FREQ_LIST[4]).size()); } /** * Verifies the creation of channel list using - * {@link WifiConfigManager#fetchChannelSetForNetworkForPartialScan(int, long)} and ensures - * that scan results from linked networks are used in the channel list. + * {@link WifiConfigManager#fetchChannelSetForNetworkForPartialScan(int, long, int)} and + * ensures that scan results from linked networks are used in the channel list. */ @Test public void testFetchChannelSetForNetworkIncludesLinkedNetworks() { @@ -1594,16 +1624,18 @@ public class WifiConfigManagerTest { // The channel list fetched should include scan results from both the linked networks. assertEquals(new HashSet<Integer>(Arrays.asList(TEST_FREQ_LIST)), - mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(network1.networkId, 1)); + mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(network1.networkId, 1, + TEST_FREQ_LIST[0])); assertEquals(new HashSet<Integer>(Arrays.asList(TEST_FREQ_LIST)), - mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(network2.networkId, 1)); + mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(network2.networkId, 1, + TEST_FREQ_LIST[0])); } /** * Verifies the creation of channel list using - * {@link WifiConfigManager#fetchChannelSetForNetworkForPartialScan(int, long)} and ensures - * that scan results from linked networks are used in the channel list and that the list size - * does not exceed the max configured for the device. + * {@link WifiConfigManager#fetchChannelSetForNetworkForPartialScan(int, long, int)} and + * ensures that scan results from linked networks are used in the channel list and that the + * list size does not exceed the max configured for the device. */ @Test public void testFetchChannelSetForNetworkIncludesLinkedNetworksIsLimitedToConfiguredSize() { @@ -1651,10 +1683,10 @@ public class WifiConfigManagerTest { // Ensure that the fetched list size is limited. assertEquals(maxListSize, mWifiConfigManager.fetchChannelSetForNetworkForPartialScan( - network1.networkId, 1).size()); + network1.networkId, 1, TEST_FREQ_LIST[0]).size()); assertEquals(maxListSize, mWifiConfigManager.fetchChannelSetForNetworkForPartialScan( - network2.networkId, 1).size()); + network2.networkId, 1, TEST_FREQ_LIST[0]).size()); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index 887895c71..9e52eb229 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -804,8 +804,8 @@ public class WifiConnectivityManagerTest { when(mWifiStateMachine.getCurrentWifiConfiguration()) .thenReturn(new WifiConfiguration()); - when(mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(anyInt(), anyInt())) - .thenReturn(channelList); + when(mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(anyInt(), anyInt(), + anyInt())).thenReturn(channelList); doAnswer(new AnswerWithArguments() { public void answer(ScanSettings settings, ScanListener listener, @@ -843,8 +843,8 @@ public class WifiConnectivityManagerTest { when(mWifiStateMachine.getCurrentWifiConfiguration()) .thenReturn(new WifiConfiguration()); - when(mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(anyInt(), anyInt())) - .thenReturn(channelList); + when(mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(anyInt(), anyInt(), + anyInt())).thenReturn(channelList); doAnswer(new AnswerWithArguments() { public void answer(ScanSettings settings, ScanListener listener, @@ -882,8 +882,8 @@ public class WifiConnectivityManagerTest { when(mWifiStateMachine.getCurrentWifiConfiguration()) .thenReturn(new WifiConfiguration()); - when(mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(anyInt(), anyInt())) - .thenReturn(channelList); + when(mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(anyInt(), anyInt(), + anyInt())).thenReturn(channelList); doAnswer(new AnswerWithArguments() { public void answer(ScanSettings settings, ScanListener listener, |