From fecef5b1be05409a5ac666611b8bfdefe7d34a27 Mon Sep 17 00:00:00 2001 From: Nate Jiang Date: Thu, 2 Apr 2020 20:18:36 -0700 Subject: Add in memory timestamp for channel inside score card Use the timestamp to age out channel for initial partial scan and PNO scan. The timestamp is elapsed time since boot. Bug: 153115968 Test: atest com.android.servre.wifi Change-Id: Icd1c84ae1c3518f501466377a8f6e4e532f83332 --- .../server/wifi/WifiConnectivityManagerTest.java | 51 ++++++++-------------- .../com/android/server/wifi/WifiScoreCardTest.java | 22 ++++++++-- 2 files changed, 36 insertions(+), 37 deletions(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index be6ee2622..093abfe50 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -158,6 +158,8 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { resources.setInteger( R.integer.config_wifiHighMovementNetworkSelectionOptimizationRssiDelta, HIGH_MVMT_RSSI_DELTA); + resources.setInteger(R.integer.config_wifiInitialPartialScanChannelCacheAgeMins, + CHANNEL_CACHE_AGE_MINS); } /** @@ -241,6 +243,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { private static final String TEST_SSID = "SSID"; private static final int TEMP_BSSID_BLOCK_DURATION_MS = 10 * 1000; // 10 seconds private static final int TEST_CONNECTED_NETWORK_ID = 55; + private static final int CHANNEL_CACHE_AGE_MINS = 14400; Context mockContext() { Context context = mock(Context.class); @@ -1783,7 +1786,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { when(mClientModeImpl.getCurrentWifiConfiguration()) .thenReturn(configuration); when(mWifiScoreCard.lookupNetwork(configuration.SSID)).thenReturn(mPerNetwork); - when(mPerNetwork.getFrequencies()).thenReturn(channelList); + when(mPerNetwork.getFrequencies(anyLong())).thenReturn(new ArrayList<>()); doAnswer(new AnswerWithArguments() { public void answer(ScanSettings settings, ScanListener listener, @@ -1848,17 +1851,11 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { R.integer.config_wifi_framework_associated_partial_scan_max_num_active_channels, 10); - final List 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); - + List channelList = linkScoreCardFreqsToNetwork(configuration).get(0); when(mClientModeImpl.getCurrentWifiConfiguration()) .thenReturn(configuration); @@ -1903,16 +1900,11 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { R.integer.config_wifi_framework_associated_partial_scan_max_num_active_channels, 10); - final List 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); + List channelList = linkScoreCardFreqsToNetwork(configuration).get(0); when(mClientModeImpl.getCurrentWifiConfiguration()) .thenReturn(configuration); @@ -1954,16 +1946,11 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { when(mWifiNS.hasSufficientLinkQuality(eq(mWifiInfo))).thenReturn(true); when(mWifiNS.hasInternetOrExpectNoInternet(eq(mWifiInfo))).thenReturn(true); - final List 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); + List channelList = linkScoreCardFreqsToNetwork(configuration).get(0); when(mClientModeImpl.getCurrentWifiConfiguration()) .thenReturn(new WifiConfiguration()); @@ -3024,14 +3011,12 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { assertEquals("frequencies should be empty", 0, pnoNetworks.get(1).frequencies.length); //Set up wifiScoreCard to get frequency. - List channelList = new ArrayList<>(); - channelList.add(TEST_FREQUENCY_1); - channelList.add(TEST_FREQUENCY_2); - channelList.add(TEST_FREQUENCY_3); + List channelList = Arrays + .asList(TEST_FREQUENCY_1, TEST_FREQUENCY_2, TEST_FREQUENCY_3); when(mWifiScoreCard.lookupNetwork(network1.SSID)).thenReturn(mPerNetwork); when(mWifiScoreCard.lookupNetwork(network2.SSID)).thenReturn(mPerNetwork1); - when(mPerNetwork.getFrequencies()).thenReturn(channelList); - when(mPerNetwork1.getFrequencies()).thenReturn(new ArrayList<>()); + when(mPerNetwork.getFrequencies(anyLong())).thenReturn(channelList); + when(mPerNetwork1.getFrequencies(anyLong())).thenReturn(new ArrayList<>()); //Set config_wifiPnoFrequencyCullingEnabled false, should ignore get frequency. mResources.setBoolean(R.bool.config_wifiPnoFrequencyCullingEnabled, false); @@ -3042,7 +3027,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { assertEquals("frequencies should be empty", 0, pnoNetworks.get(0).frequencies.length); assertEquals("frequencies should be empty", 0, pnoNetworks.get(1).frequencies.length); - ////Set config_wifiPnoFrequencyCullingEnabled false, should get the right frequency. + // Set config_wifiPnoFrequencyCullingEnabled false, should get the right frequency. mResources.setBoolean(R.bool.config_wifiPnoFrequencyCullingEnabled, true); pnoNetworks = mWifiConnectivityManager.retrievePnoNetworkList(); assertEquals(2, pnoNetworks.size()); @@ -3087,13 +3072,11 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { List> results = new ArrayList<>(); int i = 0; for (WifiConfiguration config : configs) { - List channelList = new ArrayList<>(); - channelList.add(TEST_FREQUENCY_1 + i); - channelList.add(TEST_FREQUENCY_2 + i); - channelList.add(TEST_FREQUENCY_3 + i); + List channelList = Arrays.asList(TEST_FREQUENCY_1 + i, TEST_FREQUENCY_2 + i, + TEST_FREQUENCY_3 + i); WifiScoreCard.PerNetwork perNetwork = mock(WifiScoreCard.PerNetwork.class); when(mWifiScoreCard.lookupNetwork(config.SSID)).thenReturn(perNetwork); - when(perNetwork.getFrequencies()).thenReturn(channelList); + when(perNetwork.getFrequencies(anyLong())).thenReturn(channelList); results.add(channelList); i++; } @@ -3115,8 +3098,8 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { mLruConnectionTracker.addNetwork(configuration2); mLruConnectionTracker.addNetwork(configuration1); - assertEquals(new HashSet<>(freqs.get(0)), - mWifiConnectivityManager.fetchChannelSetForPartialScan(3)); + assertEquals(new HashSet<>(freqs.get(0)), mWifiConnectivityManager + .fetchChannelSetForPartialScan(3, CHANNEL_CACHE_AGE_MINS)); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java index 498b18d53..3fc62609a 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java @@ -66,6 +66,7 @@ import org.mockito.MockitoAnnotations; import java.util.ArrayList; import java.util.Arrays; import java.util.List; + /** * Unit tests for {@link com.android.server.wifi.WifiScoreCard}. */ @@ -472,10 +473,9 @@ public class WifiScoreCardTest extends WifiBaseTest { assertEquals(diag, 0, dailyStats.getCount(CNT_ASSOCIATION_REJECTION)); assertEquals(diag, 0, dailyStats.getCount(CNT_ASSOCIATION_TIMEOUT)); assertEquals(diag, 0, dailyStats.getCount(CNT_AUTHENTICATION_FAILURE)); - List frequencies = perNetwork.getFrequencies(); + List frequencies = perNetwork.getFrequencies(Long.MAX_VALUE); assertEquals(diag, 2, frequencies.size()); - List expectedFrequencies = - new ArrayList<>(Arrays.asList(new Integer[] {2432, 5805})); + List expectedFrequencies = new ArrayList<>(Arrays.asList(2432, 5805)); assertEquals(diag, expectedFrequencies, frequencies); } @@ -1253,4 +1253,20 @@ public class WifiScoreCardTest extends WifiBaseTest { assertEquals(WifiHealthMonitor.REASON_AUTH_FAILURE, mWifiScoreCard.detectAbnormalConnectionFailure(mWifiInfo.getSSID())); } + + @Test + public void testAddGetFrequencies() { + mWifiScoreCard.noteConnectionAttempt(mWifiInfo, -53, mWifiInfo.getSSID()); + PerNetwork perNetwork = mWifiScoreCard.lookupNetwork(mWifiInfo.getSSID()); + millisecondsPass(100); + perNetwork.addFrequency(5805); + millisecondsPass(1000); + perNetwork.addFrequency(2432); + assertEquals(2, perNetwork.getFrequencies(Long.MAX_VALUE).size()); + assertEquals(2432, (int) perNetwork.getFrequencies(Long.MAX_VALUE).get(0)); + assertEquals(5805, (int) perNetwork.getFrequencies(Long.MAX_VALUE).get(1)); + // Check over aged channel will not return. + assertEquals(1, perNetwork.getFrequencies(900L).size()); + assertEquals(2432, (int) perNetwork.getFrequencies(Long.MAX_VALUE).get(0)); + } } -- cgit v1.2.3