diff options
author | Kai Shi <kaishi@google.com> | 2020-04-14 15:03:27 -0700 |
---|---|---|
committer | Kai Shi <kaishi@google.com> | 2020-04-14 15:03:27 -0700 |
commit | 2693c3a8265476521c5dbb599cab444268769c5b (patch) | |
tree | b5c6fedcffa5fff924d6feeecc31b7d75211147b | |
parent | 82298418fe24c1d0d8f62ba1b79e55d168bf6351 (diff) |
Check internet status for pre-scan sufficiency check
If internet status is not acceptable, don't skip screen-on scan even if RSSI is
high and there is a recent network selection.
Test: atest com.android.server.wifi
Bug: 154040171
Change-Id: I4ffded56a7aae2740c625f25ca2158de39c79220
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 467abf32b..39603dd22 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -1080,17 +1080,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 d66f6ddb8..32e85f528 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -1755,6 +1755,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 */ @@ -1767,6 +1769,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); @@ -1802,6 +1805,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 @@ -1809,6 +1813,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()); } /** @@ -1824,6 +1841,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, @@ -1878,6 +1896,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, @@ -1931,6 +1950,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); |