diff options
author | Kai Shi <kaishi@google.com> | 2020-04-16 19:57:04 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-04-16 19:57:04 +0000 |
commit | 656f7b75dcb6c972378235683d5653d8fd086c89 (patch) | |
tree | 61b122d1d70fdda550d3e021e6484b2983f31ba1 | |
parent | bfe73b182d85930ea04d0c2cdce2c73674fc3b6f (diff) | |
parent | 2693c3a8265476521c5dbb599cab444268769c5b (diff) |
Merge "Check internet status for pre-scan sufficiency check" into rvc-dev
3 files changed, 38 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index 030121efd..bf774688e 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -1115,17 +1115,19 @@ public class WifiConnectivityManager { <= 1000 * mContext.getResources().getInteger( R.integer.config_wifiConnectedHighRssiScanMinimumWindowSizeSec)); - boolean isGoodLinkAndShortTimeSinceLastNetworkSelection = + boolean isGoodLinkAndAcceptableInternetAndShortTimeSinceLastNetworkSelection = mNetworkSelector.hasSufficientLinkQuality(mWifiInfo) + && mNetworkSelector.hasInternetOrExpectNoInternet(mWifiInfo) && isShortTimeSinceLastNetworkSelection; // Check it is one of following conditions to skip scan (with firmware roaming) // or do partial scan only (without firmware roaming). // 1) Network is sufficient - // 2) link is good and it is a short time since last network selection + // 2) link is good, internet status is acceptable + // and it is a short time since last network selection // 3) There is active stream such that scan will be likely disruptive if (mWifiState == WIFI_STATE_CONNECTED && (mNetworkSelector.isNetworkSufficient(mWifiInfo) - || isGoodLinkAndShortTimeSinceLastNetworkSelection + || isGoodLinkAndAcceptableInternetAndShortTimeSinceLastNetworkSelection || mNetworkSelector.hasActiveStream(mWifiInfo))) { // If only partial scan is proposed and firmware roaming control is supported, // we will not issue any scan because firmware roaming will take care of diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java index f6178f24c..20544282f 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSelector.java +++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java @@ -218,6 +218,17 @@ public class WifiNetworkSelector { } /** + * Check if current network has internet or is expected to not have internet + */ + public boolean hasInternetOrExpectNoInternet(WifiInfo wifiInfo) { + WifiConfiguration network = + mWifiConfigManager.getConfiguredNetwork(wifiInfo.getNetworkId()); + if (network == null) { + return false; + } + return !network.hasNoInternetAccess() || network.isNoInternetAccessExpected(); + } + /** * Determines whether the currently connected network is sufficient. * * If the network is good enough, or if switching to a new network is likely to @@ -262,7 +273,7 @@ public class WifiNetworkSelector { } // Network without internet access is not sufficient, unless expected - if (network.hasNoInternetAccess() && !network.isNoInternetAccessExpected()) { + if (!hasInternetOrExpectNoInternet(wifiInfo)) { localLog("Current network has [" + network.numNoInternetAccessReports + "] no-internet access reports"); return false; diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index f03c5360d..be6ee2622 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -1756,6 +1756,8 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { * Verify that we perform full band scan in the following two cases * 1) Current RSSI is low, no active stream, network is insufficient * 2) Current RSSI is high, no active stream, and a long time since last network selection + * 3) Current RSSI is high, no active stream, and a short time since last network selection, + * internet status is not acceptable * * Expected behavior: WifiConnectivityManager does full band scan in both cases */ @@ -1768,6 +1770,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { when(mWifiNS.isNetworkSufficient(eq(mWifiInfo))).thenReturn(false); when(mWifiNS.hasActiveStream(eq(mWifiInfo))).thenReturn(false); when(mWifiNS.hasSufficientLinkQuality(eq(mWifiInfo))).thenReturn(false); + when(mWifiNS.hasInternetOrExpectNoInternet(eq(mWifiInfo))).thenReturn(true); final List<Integer> channelList = new ArrayList<>(); channelList.add(TEST_FREQUENCY_1); @@ -1803,6 +1806,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { when(mWifiNS.isNetworkSufficient(eq(mWifiInfo))).thenReturn(true); when(mWifiNS.hasActiveStream(eq(mWifiInfo))).thenReturn(false); when(mWifiNS.hasSufficientLinkQuality(eq(mWifiInfo))).thenReturn(true); + when(mWifiNS.hasInternetOrExpectNoInternet(eq(mWifiInfo))).thenReturn(true); when(mClock.getElapsedSinceBootMillis()).thenReturn(600_000L + 1L); mWifiConnectivityManager.handleScreenStateChanged(true); // Set WiFi to connected state to trigger periodic scan @@ -1810,6 +1814,19 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { WifiConnectivityManager.WIFI_STATE_CONNECTED); verify(mWifiScanner, times(2)).startScan(anyObject(), anyObject(), anyObject(), anyObject()); + + // Verify case 3 + when(mWifiNS.isNetworkSufficient(eq(mWifiInfo))).thenReturn(false); + when(mWifiNS.hasActiveStream(eq(mWifiInfo))).thenReturn(false); + when(mWifiNS.hasSufficientLinkQuality(eq(mWifiInfo))).thenReturn(true); + when(mWifiNS.hasInternetOrExpectNoInternet(eq(mWifiInfo))).thenReturn(false); + when(mClock.getElapsedSinceBootMillis()).thenReturn(0L); + mWifiConnectivityManager.handleScreenStateChanged(true); + // Set WiFi to connected state to trigger periodic scan + mWifiConnectivityManager.handleConnectionStateChanged( + WifiConnectivityManager.WIFI_STATE_CONNECTED); + verify(mWifiScanner, times(2)).startScan(anyObject(), anyObject(), anyObject(), + anyObject()); } /** @@ -1825,6 +1842,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { when(mWifiNS.isNetworkSufficient(eq(mWifiInfo))).thenReturn(false); when(mWifiNS.hasActiveStream(eq(mWifiInfo))).thenReturn(true); when(mWifiNS.hasSufficientLinkQuality(eq(mWifiInfo))).thenReturn(false); + when(mWifiNS.hasInternetOrExpectNoInternet(eq(mWifiInfo))).thenReturn(true); mResources.setInteger( R.integer.config_wifi_framework_associated_partial_scan_max_num_active_channels, @@ -1879,6 +1897,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { when(mWifiNS.isNetworkSufficient(eq(mWifiInfo))).thenReturn(false); when(mWifiNS.hasActiveStream(eq(mWifiInfo))).thenReturn(false); when(mWifiNS.hasSufficientLinkQuality(eq(mWifiInfo))).thenReturn(true); + when(mWifiNS.hasInternetOrExpectNoInternet(eq(mWifiInfo))).thenReturn(true); mResources.setInteger( R.integer.config_wifi_framework_associated_partial_scan_max_num_active_channels, @@ -1932,6 +1951,8 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { public void checkSingleScanSettingsWhenConnectedWithHighDataRateNotInCache() { when(mWifiNS.isNetworkSufficient(eq(mWifiInfo))).thenReturn(true); when(mWifiNS.hasActiveStream(eq(mWifiInfo))).thenReturn(true); + when(mWifiNS.hasSufficientLinkQuality(eq(mWifiInfo))).thenReturn(true); + when(mWifiNS.hasInternetOrExpectNoInternet(eq(mWifiInfo))).thenReturn(true); final List<Integer> channelList = new ArrayList<>(); channelList.add(TEST_FREQUENCY_1); |