summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNate Jiang <qiangjiang@google.com>2020-04-01 16:54:48 -0700
committerNate Jiang <qiangjiang@google.com>2020-04-02 17:02:55 -0700
commit02c42a3e85f8098e8f1a762623699a8ed8ea3f64 (patch)
tree8b051f909e66268e30a83e44f70935c17255f658 /tests
parent48a31819c11d3ee7508f3fb364617925684c362b (diff)
Add suggestion network into partial scan list
Add suggestion non-passpoint networks into partial scan list, and get channel info from ScoreCard. Bug: 148172745 Bug: 148216622 Test: atest com.android.server.wifi Change-Id: Id18d6f776a40fdf29bd8815657531d905351da24
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java325
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java183
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java7
3 files changed, 160 insertions, 355 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index a8928313a..89b069894 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -2612,331 +2612,6 @@ public class WifiConfigManagerTest extends WifiBaseTest {
}
/**
- * Verifies the creation of channel list using
- * {@link WifiConfigManager#fetchChannelSetForPartialScan(long, int)}.
- */
- @Test
- public void testFetchChannelSetForPartialScan() {
- WifiConfiguration network1 = WifiConfigurationTestUtil.createPskNetwork();
- NetworkUpdateResult result = verifyAddNetworkToWifiConfigManager(network1);
-
- // Set it to enabled.
- verifyUpdateNetworkSelectionStatus(
- result.getNetworkId(), NetworkSelectionStatus.DISABLED_NONE, 0);
-
- WifiConfiguration network2 = WifiConfigurationTestUtil.createOpenNetwork();
- result = verifyAddNetworkToWifiConfigManager(network2);
- // Set it to enabled.
- verifyUpdateNetworkSelectionStatus(
- result.getNetworkId(), NetworkSelectionStatus.DISABLED_NONE, 0);
-
- // Create 3 scan results with different bssid's & frequencies to network1
- String test_bssid_base = "af:89:56:34:56:6";
- for (int i = 0; i < 3; i++) {
- ScanDetail networkScanDetail =
- createScanDetailForNetwork(
- network1, test_bssid_base + Integer.toString(i), 0, TEST_FREQ_LIST[i]);
- assertNotNull(
- mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(
- networkScanDetail));
- }
-
- // Create 2 scan results with different bssid's & frequencies to network2
- for (int i = 3; i < TEST_FREQ_LIST.length; i++) {
- ScanDetail networkScanDetail =
- createScanDetailForNetwork(
- network2, test_bssid_base + Integer.toString(i), 0, TEST_FREQ_LIST[i]);
- assertNotNull(
- mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(
- networkScanDetail));
- }
-
- assertEquals(new HashSet<Integer>(Arrays.asList(TEST_FREQ_LIST)),
- mWifiConfigManager.fetchChannelSetForPartialScan(100, 5));
- }
-
- /**
- * Verify that the length of frequency set will not exceed the provided max value
- */
- @Test
- public void testFetchChannelSetForPartialScanMaxCount() {
- WifiConfiguration network1 = WifiConfigurationTestUtil.createPskNetwork();
- NetworkUpdateResult result = verifyAddNetworkToWifiConfigManager(network1);
-
- // Set it to enabled.
- verifyUpdateNetworkSelectionStatus(
- result.getNetworkId(), NetworkSelectionStatus.DISABLED_NONE, 0);
-
- WifiConfiguration network2 = WifiConfigurationTestUtil.createOpenNetwork();
- result = verifyAddNetworkToWifiConfigManager(network2);
- // Set it to enabled.
- verifyUpdateNetworkSelectionStatus(
- result.getNetworkId(), NetworkSelectionStatus.DISABLED_NONE, 0);
-
- // Create 3 scan results with different bssid's & frequencies to network1
- String test_bssid_base = "af:89:56:34:56:6";
- for (int i = 0; i < 3; i++) {
- ScanDetail networkScanDetail =
- createScanDetailForNetwork(
- network1, test_bssid_base + Integer.toString(i), 0, TEST_FREQ_LIST[i]);
- assertNotNull(
- mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(
- networkScanDetail));
- }
-
- // Create 2 scan results with different bssid's & frequencies to network2
- for (int i = 3; i < TEST_FREQ_LIST.length; i++) {
- ScanDetail networkScanDetail =
- createScanDetailForNetwork(
- network2, test_bssid_base + Integer.toString(i), 0, TEST_FREQ_LIST[i]);
- assertNotNull(
- mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(
- networkScanDetail));
- }
-
- assertEquals(3, mWifiConfigManager.fetchChannelSetForPartialScan(100, 3).size());
- }
-
- /**
- * Verifies the creation of channel list using
- * {@link WifiConfigManager#fetchChannelSetForNetworkForPartialScan(int, long, int)}.
- */
- @Test
- public void testFetchChannelSetForNetwork() {
- 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.getConfiguredNetworkForScanDetailAndCache(
- networkScanDetail));
-
- }
- assertEquals(new HashSet<Integer>(Arrays.asList(TEST_FREQ_LIST)),
- 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.getConfiguredNetworkForScanDetailAndCache(
- 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, 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() {
- WifiConfiguration network = WifiConfigurationTestUtil.createPskNetwork();
- verifyAddNetworkToWifiConfigManager(network);
-
- long wallClockBase = 0;
- // 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++) {
- // Increment the seen value in the scan results for each of them.
- when(mClock.getWallClockMillis()).thenReturn(wallClockBase + i);
- ScanDetail networkScanDetail =
- createScanDetailForNetwork(
- network, test_bssid_base + Integer.toString(i), 0, TEST_FREQ_LIST[i]);
- assertNotNull(
- mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(
- networkScanDetail));
-
- }
- int ageInMillis = 4;
- // Now fetch only scan results which are 4 millis stale. This should ignore the first
- // scan result.
- assertEquals(
- new HashSet<>(Arrays.asList(
- Arrays.copyOfRange(
- TEST_FREQ_LIST,
- TEST_FREQ_LIST.length - ageInMillis, TEST_FREQ_LIST.length))),
- mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(
- network.networkId, ageInMillis, TEST_FREQ_LIST[4]));
- }
-
- /**
- * Verifies the creation of channel list using
- * {@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() {
- // Need to recreate the WifiConfigManager instance for this test to modify the config
- // value which is read only in the constructor.
- int maxListSize = 3;
- mResources.setInteger(
- R.integer.config_wifi_framework_associated_partial_scan_max_num_active_channels,
- maxListSize);
- createWifiConfigManager();
-
- 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.getConfiguredNetworkForScanDetailAndCache(
- networkScanDetail));
- verify(mPerNetwork).addFrequency(TEST_FREQ_LIST[i]);
-
- }
- // Ensure that the fetched list size is limited.
- assertEquals(maxListSize,
- mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(
- network.networkId, 1, TEST_FREQ_LIST[4]).size());
- }
-
- /**
- * Verifies the creation of channel list using
- * {@link WifiConfigManager#fetchChannelSetForNetworkForPartialScan(int, long, int)} and
- * ensures that scan results from linked networks are used in the channel list.
- */
- @Test
- public void testFetchChannelSetForNetworkIncludesLinkedNetworks() {
- WifiConfiguration network1 = WifiConfigurationTestUtil.createPskNetwork();
- WifiConfiguration network2 = WifiConfigurationTestUtil.createPskNetwork();
- verifyAddNetworkToWifiConfigManager(network1);
- verifyAddNetworkToWifiConfigManager(network2);
-
- String test_bssid_base = "af:89:56:34:56:6";
- int TEST_FREQ_LISTIdx = 0;
- // Create 3 scan results with different bssid's & frequencies for network 1.
- for (; TEST_FREQ_LISTIdx < TEST_FREQ_LIST.length / 2; TEST_FREQ_LISTIdx++) {
- ScanDetail networkScanDetail =
- createScanDetailForNetwork(
- network1, test_bssid_base + Integer.toString(TEST_FREQ_LISTIdx), 0,
- TEST_FREQ_LIST[TEST_FREQ_LISTIdx]);
- assertNotNull(
- mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(
- networkScanDetail));
-
- }
- // Create 3 scan results with different bssid's & frequencies for network 2.
- for (; TEST_FREQ_LISTIdx < TEST_FREQ_LIST.length; TEST_FREQ_LISTIdx++) {
- ScanDetail networkScanDetail =
- createScanDetailForNetwork(
- network2, test_bssid_base + Integer.toString(TEST_FREQ_LISTIdx), 0,
- TEST_FREQ_LIST[TEST_FREQ_LISTIdx]);
- assertNotNull(
- mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(
- networkScanDetail));
- }
-
- // Link the 2 configurations together using the GwMacAddress.
- assertTrue(mWifiConfigManager.setNetworkDefaultGwMacAddress(
- network1.networkId, TEST_DEFAULT_GW_MAC_ADDRESS));
- assertTrue(mWifiConfigManager.setNetworkDefaultGwMacAddress(
- network2.networkId, TEST_DEFAULT_GW_MAC_ADDRESS));
-
- // 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,
- TEST_FREQ_LIST[0]));
- assertEquals(new HashSet<Integer>(Arrays.asList(TEST_FREQ_LIST)),
- mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(network2.networkId, 1,
- TEST_FREQ_LIST[0]));
- }
-
- /**
- * Verifies the creation of channel list using
- * {@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() {
- // Need to recreate the WifiConfigManager instance for this test to modify the config
- // value which is read only in the constructor.
- int maxListSize = 3;
- mResources.setInteger(
- R.integer.config_wifi_framework_associated_partial_scan_max_num_active_channels,
- maxListSize);
-
- createWifiConfigManager();
- WifiConfiguration network1 = WifiConfigurationTestUtil.createPskNetwork();
- WifiConfiguration network2 = WifiConfigurationTestUtil.createPskNetwork();
- verifyAddNetworkToWifiConfigManager(network1);
- verifyAddNetworkToWifiConfigManager(network2);
-
- String test_bssid_base = "af:89:56:34:56:6";
- int TEST_FREQ_LISTIdx = 0;
- // Create 3 scan results with different bssid's & frequencies for network 1.
- for (; TEST_FREQ_LISTIdx < TEST_FREQ_LIST.length / 2; TEST_FREQ_LISTIdx++) {
- ScanDetail networkScanDetail =
- createScanDetailForNetwork(
- network1, test_bssid_base + Integer.toString(TEST_FREQ_LISTIdx), 0,
- TEST_FREQ_LIST[TEST_FREQ_LISTIdx]);
- assertNotNull(
- mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(
- networkScanDetail));
-
- }
- // Create 3 scan results with different bssid's & frequencies for network 2.
- for (; TEST_FREQ_LISTIdx < TEST_FREQ_LIST.length; TEST_FREQ_LISTIdx++) {
- ScanDetail networkScanDetail =
- createScanDetailForNetwork(
- network2, test_bssid_base + Integer.toString(TEST_FREQ_LISTIdx), 0,
- TEST_FREQ_LIST[TEST_FREQ_LISTIdx]);
- assertNotNull(
- mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(
- networkScanDetail));
- }
-
- // Link the 2 configurations together using the GwMacAddress.
- assertTrue(mWifiConfigManager.setNetworkDefaultGwMacAddress(
- network1.networkId, TEST_DEFAULT_GW_MAC_ADDRESS));
- assertTrue(mWifiConfigManager.setNetworkDefaultGwMacAddress(
- network2.networkId, TEST_DEFAULT_GW_MAC_ADDRESS));
-
- // Ensure that the fetched list size is limited.
- assertEquals(maxListSize,
- mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(
- network1.networkId, 1, TEST_FREQ_LIST[0]).size());
- assertEquals(maxListSize,
- mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(
- network2.networkId, 1, TEST_FREQ_LIST[0]).size());
- }
-
- /**
* Verifies the foreground user switch using {@link WifiConfigManager#handleUserSwitch(int)}
* and ensures that any shared private networks networkId is not changed.
* Test scenario:
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
index ede5c8b7a..d66f6ddb8 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
@@ -231,6 +231,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
private static final int TEST_FREQUENCY_1 = 2412;
private static final int TEST_FREQUENCY_2 = 5180;
private static final int TEST_FREQUENCY_3 = 5240;
+ private static final int TEST_CURRENT_CONNECTED_FREQUENCY = 2427;
private static final int HIGH_MVMT_SCAN_DELAY_MS = 10000;
private static final int HIGH_MVMT_RSSI_DELTA = 10;
private static final String TEST_FQDN = "FQDN";
@@ -397,7 +398,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
mWifiConfigManager, mWifiInfo, mWifiNS, mWifiConnectivityHelper,
mWifiLastResortWatchdog, mOpenNetworkNotifier,
mWifiMetrics, new Handler(mLooper.getLooper()), mClock,
- mLocalLog);
+ mLocalLog, mWifiScoreCard);
}
void setWifiStateConnected() {
@@ -1767,15 +1768,18 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
when(mWifiNS.hasActiveStream(eq(mWifiInfo))).thenReturn(false);
when(mWifiNS.hasSufficientLinkQuality(eq(mWifiInfo))).thenReturn(false);
- final HashSet<Integer> channelList = new HashSet<>();
- channelList.add(1);
- channelList.add(2);
- channelList.add(3);
-
+ final List<Integer> channelList = new ArrayList<>();
+ channelList.add(TEST_FREQUENCY_1);
+ channelList.add(TEST_FREQUENCY_2);
+ channelList.add(TEST_FREQUENCY_3);
+ WifiConfiguration configuration = WifiConfigurationTestUtil.createOpenNetwork();
+ configuration.networkId = TEST_CONNECTED_NETWORK_ID;
+ when(mWifiConfigManager.getConfiguredNetwork(TEST_CONNECTED_NETWORK_ID))
+ .thenReturn(configuration);
when(mClientModeImpl.getCurrentWifiConfiguration())
- .thenReturn(new WifiConfiguration());
- when(mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(anyInt(), anyLong(),
- anyInt())).thenReturn(channelList);
+ .thenReturn(configuration);
+ when(mWifiScoreCard.lookupNetwork(configuration.SSID)).thenReturn(mPerNetwork);
+ when(mPerNetwork.getFrequencies()).thenReturn(channelList);
doAnswer(new AnswerWithArguments() {
public void answer(ScanSettings settings, ScanListener listener,
@@ -1821,15 +1825,24 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
when(mWifiNS.hasActiveStream(eq(mWifiInfo))).thenReturn(true);
when(mWifiNS.hasSufficientLinkQuality(eq(mWifiInfo))).thenReturn(false);
- final HashSet<Integer> channelList = new HashSet<>();
- channelList.add(1);
- channelList.add(2);
- channelList.add(3);
+ mResources.setInteger(
+ R.integer.config_wifi_framework_associated_partial_scan_max_num_active_channels,
+ 10);
+
+ final List<Integer> channelList = new ArrayList<>();
+ channelList.add(TEST_FREQUENCY_1);
+ channelList.add(TEST_FREQUENCY_2);
+ channelList.add(TEST_FREQUENCY_3);
+ WifiConfiguration configuration = WifiConfigurationTestUtil.createOpenNetwork();
+ configuration.networkId = TEST_CONNECTED_NETWORK_ID;
+ when(mWifiConfigManager.getConfiguredNetwork(TEST_CONNECTED_NETWORK_ID))
+ .thenReturn(configuration);
+ when(mWifiScoreCard.lookupNetwork(configuration.SSID)).thenReturn(mPerNetwork);
+ when(mPerNetwork.getFrequencies()).thenReturn(channelList);
when(mClientModeImpl.getCurrentWifiConfiguration())
- .thenReturn(new WifiConfiguration());
- when(mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(anyInt(), anyLong(),
- anyInt())).thenReturn(channelList);
+ .thenReturn(configuration);
+
when(mWifiConnectivityHelper.isFirmwareRoamingSupported()).thenReturn(false);
doAnswer(new AnswerWithArguments() {
@@ -1866,15 +1879,23 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
when(mWifiNS.hasActiveStream(eq(mWifiInfo))).thenReturn(false);
when(mWifiNS.hasSufficientLinkQuality(eq(mWifiInfo))).thenReturn(true);
- final HashSet<Integer> channelList = new HashSet<>();
- channelList.add(1);
- channelList.add(2);
- channelList.add(3);
+ mResources.setInteger(
+ R.integer.config_wifi_framework_associated_partial_scan_max_num_active_channels,
+ 10);
+
+ final List<Integer> channelList = new ArrayList<>();
+ channelList.add(TEST_FREQUENCY_1);
+ channelList.add(TEST_FREQUENCY_2);
+ channelList.add(TEST_FREQUENCY_3);
+ WifiConfiguration configuration = WifiConfigurationTestUtil.createOpenNetwork();
+ configuration.networkId = TEST_CONNECTED_NETWORK_ID;
+ when(mWifiConfigManager.getConfiguredNetwork(TEST_CONNECTED_NETWORK_ID))
+ .thenReturn(configuration);
+ when(mWifiScoreCard.lookupNetwork(configuration.SSID)).thenReturn(mPerNetwork);
+ when(mPerNetwork.getFrequencies()).thenReturn(channelList);
when(mClientModeImpl.getCurrentWifiConfiguration())
- .thenReturn(new WifiConfiguration());
- when(mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(anyInt(), anyLong(),
- anyInt())).thenReturn(channelList);
+ .thenReturn(configuration);
when(mWifiConnectivityHelper.isFirmwareRoamingSupported()).thenReturn(false);
doAnswer(new AnswerWithArguments() {
@@ -1911,12 +1932,19 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
when(mWifiNS.isNetworkSufficient(eq(mWifiInfo))).thenReturn(true);
when(mWifiNS.hasActiveStream(eq(mWifiInfo))).thenReturn(true);
- final HashSet<Integer> channelList = new HashSet<>();
+ final List<Integer> channelList = new ArrayList<>();
+ channelList.add(TEST_FREQUENCY_1);
+ channelList.add(TEST_FREQUENCY_2);
+ channelList.add(TEST_FREQUENCY_3);
+ WifiConfiguration configuration = WifiConfigurationTestUtil.createOpenNetwork();
+ configuration.networkId = TEST_CONNECTED_NETWORK_ID;
+ when(mWifiConfigManager.getConfiguredNetwork(TEST_CONNECTED_NETWORK_ID))
+ .thenReturn(configuration);
+ when(mWifiScoreCard.lookupNetwork(configuration.SSID)).thenReturn(mPerNetwork);
+ when(mPerNetwork.getFrequencies()).thenReturn(channelList);
when(mClientModeImpl.getCurrentWifiConfiguration())
.thenReturn(new WifiConfiguration());
- when(mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(anyInt(), anyLong(),
- anyInt())).thenReturn(channelList);
doAnswer(new AnswerWithArguments() {
public void answer(ScanSettings settings, Executor executor, ScanListener listener,
@@ -2924,7 +2952,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
// Retrieve the Pno network list & verify.
List<WifiScanner.PnoSettings.PnoNetwork> pnoNetworks =
mWifiConnectivityManager.retrievePnoNetworkList();
- verify(mWifiNetworkSuggestionsManager).getAllPnoAvailableSuggestionNetworks();
+ verify(mWifiNetworkSuggestionsManager).getAllScanOptimizationSuggestionNetworks();
assertEquals(3, pnoNetworks.size());
assertEquals(network1.SSID, pnoNetworks.get(0).ssid);
assertEquals(network2.SSID, pnoNetworks.get(1).ssid);
@@ -3032,4 +3060,105 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
assertEquals(network2.SSID, pnoNetworks.get(1).ssid);
assertEquals(network1.SSID, pnoNetworks.get(2).ssid);
}
+
+ private List<List<Integer>> linkScoreCardFreqsToNetwork(WifiConfiguration... configs) {
+ List<List<Integer>> results = new ArrayList<>();
+ int i = 0;
+ for (WifiConfiguration config : configs) {
+ List<Integer> channelList = new ArrayList<>();
+ channelList.add(TEST_FREQUENCY_1 + i);
+ channelList.add(TEST_FREQUENCY_2 + i);
+ channelList.add(TEST_FREQUENCY_3 + i);
+ WifiScoreCard.PerNetwork perNetwork = mock(WifiScoreCard.PerNetwork.class);
+ when(mWifiScoreCard.lookupNetwork(config.SSID)).thenReturn(perNetwork);
+ when(perNetwork.getFrequencies()).thenReturn(channelList);
+ results.add(channelList);
+ i++;
+ }
+ return results;
+ }
+
+ /**
+ * Verify that the length of frequency set will not exceed the provided max value
+ */
+ @Test
+ public void testFetchChannelSetForPartialScanMaxCount() {
+ WifiConfiguration configuration1 = WifiConfigurationTestUtil.createOpenNetwork();
+ WifiConfiguration configuration2 = WifiConfigurationTestUtil.createOpenNetwork();
+ when(mWifiConfigManager.getSavedNetworks(anyInt()))
+ .thenReturn(Arrays.asList(configuration1, configuration2));
+
+ List<List<Integer>> freqs = linkScoreCardFreqsToNetwork(configuration1, configuration2);
+
+ mLruConnectionTracker.addNetwork(configuration2);
+ mLruConnectionTracker.addNetwork(configuration1);
+
+ assertEquals(new HashSet<>(freqs.get(0)),
+ mWifiConnectivityManager.fetchChannelSetForPartialScan(3));
+ }
+
+ /**
+ * Verifies the creation of channel list using
+ * {@link WifiConnectivityManager#fetchChannelSetForNetworkForPartialScan(int)}.
+ */
+ @Test
+ public void testFetchChannelSetForNetwork() {
+ WifiConfiguration configuration = WifiConfigurationTestUtil.createOpenNetwork();
+ configuration.networkId = TEST_CONNECTED_NETWORK_ID;
+ when(mWifiConfigManager.getConfiguredNetwork(TEST_CONNECTED_NETWORK_ID))
+ .thenReturn(configuration);
+ List<List<Integer>> freqs = linkScoreCardFreqsToNetwork(configuration);
+
+ assertEquals(new HashSet<>(freqs.get(0)), mWifiConnectivityManager
+ .fetchChannelSetForNetworkForPartialScan(configuration.networkId));
+ }
+
+ /**
+ * Verifies the creation of channel list using
+ * {@link WifiConnectivityManager#fetchChannelSetForNetworkForPartialScan(int)} and
+ * ensures that the frequenecy of the currently connected network is in the returned
+ * channel set.
+ */
+ @Test
+ public void testFetchChannelSetForNetworkIncludeCurrentNetwork() {
+ WifiConfiguration configuration = WifiConfigurationTestUtil.createOpenNetwork();
+ configuration.networkId = TEST_CONNECTED_NETWORK_ID;
+ when(mWifiConfigManager.getConfiguredNetwork(TEST_CONNECTED_NETWORK_ID))
+ .thenReturn(configuration);
+ linkScoreCardFreqsToNetwork(configuration);
+
+ mWifiInfo.setFrequency(TEST_CURRENT_CONNECTED_FREQUENCY);
+
+ // Currently connected network frequency 2427 is not in the TEST_FREQ_LIST
+ Set<Integer> freqs = mWifiConnectivityManager.fetchChannelSetForNetworkForPartialScan(
+ configuration.networkId);
+
+ assertTrue(freqs.contains(2427));
+ }
+
+ /**
+ * Verifies the creation of channel list using
+ * {@link WifiConnectivityManager#fetchChannelSetForNetworkForPartialScan(int)} and
+ * ensures that the list size does not exceed the max configured for the device.
+ */
+ @Test
+ public void testFetchChannelSetForNetworkIsLimitedToConfiguredSize() {
+ // Need to recreate the WifiConfigManager instance for this test to modify the config
+ // value which is read only in the constructor.
+ int maxListSize = 2;
+ mResources.setInteger(
+ R.integer.config_wifi_framework_associated_partial_scan_max_num_active_channels,
+ maxListSize);
+
+ WifiConfiguration configuration = WifiConfigurationTestUtil.createOpenNetwork();
+ configuration.networkId = TEST_CONNECTED_NETWORK_ID;
+ when(mWifiConfigManager.getConfiguredNetwork(TEST_CONNECTED_NETWORK_ID))
+ .thenReturn(configuration);
+ List<List<Integer>> freqs = linkScoreCardFreqsToNetwork(configuration);
+ // Ensure that the fetched list size is limited.
+ Set<Integer> results = mWifiConnectivityManager.fetchChannelSetForNetworkForPartialScan(
+ configuration.networkId);
+ assertEquals(maxListSize, results.size());
+ assertFalse(results.contains(freqs.get(0).get(2)));
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
index bb090cae5..f53b4c41e 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -3582,7 +3582,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
}
/**
- * Verify getAllPnoAvailableSuggestionNetworks will only return user approved,
+ * Verify getAllScanOptimizationSuggestionNetworks will only return user approved,
* non-passpoint network.
*/
@Test
@@ -3605,10 +3605,11 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
mWifiNetworkSuggestionsManager
.add(networkSuggestionList, TEST_UID_1, TEST_PACKAGE_1, TEST_FEATURE));
- assertTrue(mWifiNetworkSuggestionsManager.getAllPnoAvailableSuggestionNetworks().isEmpty());
+ assertTrue(mWifiNetworkSuggestionsManager
+ .getAllScanOptimizationSuggestionNetworks().isEmpty());
mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1);
List<WifiConfiguration> pnoNetwork =
- mWifiNetworkSuggestionsManager.getAllPnoAvailableSuggestionNetworks();
+ mWifiNetworkSuggestionsManager.getAllScanOptimizationSuggestionNetworks();
assertEquals(1, pnoNetwork.size());
assertEquals(network1.SSID, pnoNetwork.get(0).SSID);
}