diff options
-rw-r--r-- | service/java/com/android/server/wifi/WifiNetworkSelector.java | 19 | ||||
-rw-r--r-- | service/res/values/config.xml | 3 | ||||
-rw-r--r-- | service/res/values/overlayable.xml | 1 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java | 32 |
4 files changed, 52 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java index 1e5b6c12d..59bc6dce8 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSelector.java +++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java @@ -224,9 +224,10 @@ public class WifiNetworkSelector { } /** - * Check if one of following conditions is met to avoid a new network selection - * 1) current network is in OSU process - * 2) current network has internet access, sufficient link quality and active traffic + * Determines whether the currently connected network is sufficient. + * + * If the network is good enough, or if switching to a new network is likely to + * be disruptive, we should avoid doing a network selection. * * @param wifiInfo info of currently connected network * @return true if the network is sufficient @@ -247,6 +248,18 @@ public class WifiNetworkSelector { return false; } + // Skip autojoin for the first few seconds of a user-initiated connection. + // This delays network selection during the time that connectivity service may be posting + // a dialog about a no-internet network. + if (mWifiConfigManager.getLastSelectedNetwork() == network.networkId + && (mClock.getElapsedSinceBootMillis() + - mWifiConfigManager.getLastSelectedTimeStamp()) + <= mContext.getResources().getInteger( + R.integer.config_wifiSufficientDurationAfterUserSelectionMilliseconds)) { + localLog("Current network is recently user-selected"); + return true; + } + // Set OSU (Online Sign Up) network for Passpoint Release 2 to sufficient // so that network select selection is skipped and OSU process can complete. if (network.osu) { diff --git a/service/res/values/config.xml b/service/res/values/config.xml index 3a7c11479..fbab4df31 100644 --- a/service/res/values/config.xml +++ b/service/res/values/config.xml @@ -154,6 +154,9 @@ <!-- Boolean indicating associated network selection is allowed --> <bool translatable="false" name="config_wifi_framework_enable_associated_network_selection">true</bool> + <!-- Integer duration after connection that a user-selected network is considered sufficient (milliseconds) --> + <integer translatable="false" name="config_wifiSufficientDurationAfterUserSelectionMilliseconds">60000</integer> + <!-- Boolean indicating performing a partial initial scan is enabled --> <bool translatable="false" name="config_wifiEnablePartialInitialScan">false</bool> diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml index c9e4866cb..1aa8f12bc 100644 --- a/service/res/values/overlayable.xml +++ b/service/res/values/overlayable.xml @@ -61,6 +61,7 @@ <item type="integer" name="config_wifi_framework_associated_partial_scan_max_num_active_channels" /> <item type="integer" name="config_wifi_framework_recovery_timeout_delay" /> <item type="bool" name="config_wifi_framework_enable_associated_network_selection" /> + <item type="integer" name="config_wifiSufficientDurationAfterUserSelectionMilliseconds" /> <item type="bool" name="config_wifiEnablePartialInitialScan" /> <item type="integer" name="config_wifiInitialPartialScanChannelMaxCount" /> <item type="integer" name="config_wifiInitialPartialScanChannelCacheAgeMins" /> diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java index 1e72cb758..0b91ea675 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java @@ -65,6 +65,7 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { private static final int RSSI_BUMP = 1; private static final int DUMMY_NOMINATOR_ID_1 = -2; // lowest index private static final int DUMMY_NOMINATOR_ID_2 = -1; + private static final int WAIT_JUST_A_MINUTE = 60_000; private static final HashSet<String> EMPTY_BLACKLIST = new HashSet<>(); /** Sets up test. */ @@ -216,6 +217,7 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { private int mThresholdQualifiedRssi2G; private int mThresholdQualifiedRssi5G; private int mMinPacketRateActiveTraffic; + private int mSufficientDurationAfterUserSelection; private CompatibilityScorer mCompatibilityScorer; private ScoreCardBasedScorer mScoreCardBasedScorer; private ThroughputScorer mThroughputScorer; @@ -234,6 +236,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { R.bool.config_wifi_framework_enable_associated_network_selection); mMinPacketRateActiveTraffic = setupIntegerResource( R.integer.config_wifiFrameworkMinPacketPerSecondActiveTraffic, 16); + mSufficientDurationAfterUserSelection = setupIntegerResource( + R.integer.config_wifiSufficientDurationAfterUserSelectionMilliseconds, + WAIT_JUST_A_MINUTE); doReturn(false).when(mResource).getBoolean(R.bool.config_wifi11axSupportOverride); } @@ -868,6 +873,33 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { false); } + /** + * New network selection is not performed if the currently connected network + * was recently selected. + */ + @Test + public void networkIsSufficientWhenRecentlyUserSelected() { + // Approximate mClock.getElapsedSinceBootMillis value mocked by testStayOrTryToSwitch + long millisSinceBoot = SystemClock.elapsedRealtime() + + WifiNetworkSelector.MINIMUM_NETWORK_SELECTION_INTERVAL_MS + 2000; + when(mWifiConfigManager.getLastSelectedTimeStamp()) + .thenReturn(millisSinceBoot + - WAIT_JUST_A_MINUTE + + 1000); + setupWifiConfigManager(0); // testStayOrTryToSwitch first connects to network 0 + // Rssi after connected. + when(mWifiInfo.getRssi()).thenReturn(mThresholdQualifiedRssi2G + 1); + // No streaming traffic. + when(mWifiInfo.getSuccessfulTxPacketsPerSecond()).thenReturn(0.0); + when(mWifiInfo.getSuccessfulRxPacketsPerSecond()).thenReturn(0.0); + + testStayOrTryToSwitch( + mThresholdQualifiedRssi2G + 1 /* rssi before connected */, + false /* not a 5G network */, + false /* not open network */, + // Should not try to switch. + false); + } /** * New network selection is performed if the currently connected network has bad rssi. |