diff options
author | Michael Plass <mplass@google.com> | 2019-06-03 18:23:29 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-06-03 18:23:29 +0000 |
commit | 782f16649ce3e8f95fea3c701b046842bca35c18 (patch) | |
tree | b9938ec92b800f52de124079c3b842e07b597952 | |
parent | aa697357cdf78fa41e7fb6a52803e5d2f9bcc5ae (diff) | |
parent | 13d755aca12a1e9b252fbfb8f36670dc0fb7ed71 (diff) |
Merge "[WifiNetworkSelector] User-selected network is sufficient for a while" into qt-dev
-rw-r--r-- | service/java/com/android/server/wifi/WifiNetworkSelector.java | 18 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java | 33 |
2 files changed, 51 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java index 4b7e3f02b..85bd9174a 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSelector.java +++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java @@ -56,6 +56,7 @@ public class WifiNetworkSelector { private static final String TAG = "WifiNetworkSelector"; private static final long INVALID_TIME_STAMP = Long.MIN_VALUE; + /** * Minimum time gap between last successful network selection and a * new selection attempt. @@ -64,6 +65,15 @@ public class WifiNetworkSelector { public static final int MINIMUM_NETWORK_SELECTION_INTERVAL_MS = 10 * 1000; /** + * For this duration after user selected it, consider the current network as sufficient. + * + * This delays network selection during the time that connectivity service may be posting + * a dialog about a no-internet network. + */ + @VisibleForTesting + public static final int LAST_USER_SELECTION_SUFFICIENT_MS = 30_000; + + /** * Time that it takes for the boost given to the most recently user-selected * network to decay to zero. * @@ -235,6 +245,14 @@ public class WifiNetworkSelector { return false; } + if (mWifiConfigManager.getLastSelectedNetwork() == network.networkId + && (mClock.getElapsedSinceBootMillis() + - mWifiConfigManager.getLastSelectedTimeStamp()) + <= LAST_USER_SELECTION_SUFFICIENT_MS) { + localLog("Current network is recently user-selected."); + return true; + } + // OSU (Online Sign Up) network for Passpoint Release 2 is sufficient network. if (network.osu) { return true; diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java index 53dae5229..bd7256a76 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java @@ -960,6 +960,39 @@ public class WifiNetworkSelectorTest { } /** + * 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 + - WifiNetworkSelector.LAST_USER_SELECTION_SUFFICIENT_MS + + 1000); + setupWifiConfigManager(0); // testStayOrTryToSwitch first connects to network 0 + // Rssi after connected. + when(mWifiInfo.getRssi()).thenReturn(mThresholdQualifiedRssi2G + 1); + // No streaming traffic. + mWifiInfo.txSuccessRate = 0.0; + mWifiInfo.rxSuccessRate = 0.0; + + testStayOrTryToSwitch( + // Parameters for network1: + mThresholdQualifiedRssi2G + 1 /* rssi before connected */, + false /* not a 5G network */, + false /* not open network */, + // Parameters for network2: + mThresholdQualifiedRssi5G + 1 /* rssi */, + true /* a 5G network */, + false /* not open network */, + // Should not try to switch. + false); + } + + /** * New network selection is performed if the currently connected network * band is 2G with bad rssi. * |