summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Plass <mplass@google.com>2020-02-05 01:03:20 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-02-05 01:03:20 +0000
commit542b6e90991b710ac664cc7fe613ca7fe4d2dd8a (patch)
treec6d33ba4fade0b9cefcd6670ee103026fe9173b6
parente73c2b4c6166577b38c2147147b4433f45e833dc (diff)
parent677116a9705fe1a99587278db2414beba8b25d96 (diff)
Merge "[WifiNetworkSelector] Consistency of Pre/Post-scan sufficiency"
-rw-r--r--service/java/com/android/server/wifi/WifiConnectivityManager.java6
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkSelector.java60
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java74
3 files changed, 44 insertions, 96 deletions
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java
index bbec2f355..0667793bb 100644
--- a/service/java/com/android/server/wifi/WifiConnectivityManager.java
+++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java
@@ -854,9 +854,9 @@ public class WifiConnectivityManager {
// If current network link quality is sufficient or has active stream,
// skip scan (with firmware roaming) or do partial scan only (without firmware roaming).
- if (mWifiState == WIFI_STATE_CONNECTED
- && (mNetworkSelector.hasSufficientLinkQuality(mWifiInfo, mScoringParams)
- || mNetworkSelector.hasActiveStream(mWifiInfo, mScoringParams))) {
+ if (mWifiState == WIFI_STATE_CONNECTED && (
+ mNetworkSelector.isNetworkSufficient(mWifiInfo)
+ || 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
// intra-SSID roam.
diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java
index 791ea41a3..2194dad2b 100644
--- a/service/java/com/android/server/wifi/WifiNetworkSelector.java
+++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java
@@ -66,15 +66,6 @@ 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.
*
@@ -217,70 +208,73 @@ public class WifiNetworkSelector {
/**
* Check if current network has sufficient RSSI
* @param wifiInfo info of currently connected network
- * @param scoringParams scoring parameter set including RSSI sufficiency check threshold
* @return true if current link quality is sufficient, false otherwise.
*/
- public static boolean hasSufficientLinkQuality(WifiInfo wifiInfo, ScoringParams scoringParams) {
+ private boolean hasSufficientLinkQuality(WifiInfo wifiInfo) {
int currentRssi = wifiInfo.getRssi();
- return currentRssi >= scoringParams.getSufficientRssi(wifiInfo.getFrequency());
+ return currentRssi >= mScoringParams.getSufficientRssi(wifiInfo.getFrequency());
}
/**
* Check if current network has active Tx or Rx traffic
* @param wifiInfo info of currently connected network
- * @param scoringParams scoring parameter set including active traffic check threshold
* @return true if it has active Tx or Rx traffic, false otherwise.
*/
- public static boolean hasActiveStream(WifiInfo wifiInfo, ScoringParams scoringParams) {
- return (wifiInfo.getSuccessfulTxPacketsPerSecond()
- > scoringParams.getActiveTrafficPacketsPerSecond())
- || (wifiInfo.getSuccessfulRxPacketsPerSecond()
- > scoringParams.getActiveTrafficPacketsPerSecond());
+ public boolean hasActiveStream(WifiInfo wifiInfo) {
+ return wifiInfo.getSuccessfulTxPacketsPerSecond()
+ > mScoringParams.getActiveTrafficPacketsPerSecond()
+ || wifiInfo.getSuccessfulRxPacketsPerSecond()
+ > mScoringParams.getActiveTrafficPacketsPerSecond();
}
/**
* 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
+ * @param wifiInfo info of currently connected network
+ * @return true if the network is sufficient
*/
- private boolean isCurrentNetworkSufficient(WifiInfo wifiInfo) {
+ public boolean isNetworkSufficient(WifiInfo wifiInfo) {
// Currently connected?
if (wifiInfo.getSupplicantState() != SupplicantState.COMPLETED) {
- localLog("No current connected network.");
return false;
- } else {
- localLog("Current connected network: " + wifiInfo.getSSID()
- + " , ID: " + wifiInfo.getNetworkId());
}
+ localLog("Current connected network: " + wifiInfo.getNetworkId());
+
WifiConfiguration network =
mWifiConfigManager.getConfiguredNetwork(wifiInfo.getNetworkId());
if (network == null) {
- localLog("Current network was removed.");
+ localLog("Current network was removed");
return false;
}
// 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) {
+ localLog("Current connection is OSU");
return true;
}
- // Network with no internet access reports is not sufficient
- if (network.numNoInternetAccessReports > 0 && !network.noInternetAccessExpected) {
+ // Network without internet access is not sufficient, unless expected
+ if (network.hasNoInternetAccess() && !network.isNoInternetAccessExpected()) {
localLog("Current network has [" + network.numNoInternetAccessReports
- + "] no-internet access reports.");
+ + "] no-internet access reports");
return false;
}
- if ((hasSufficientLinkQuality(wifiInfo, mScoringParams))
- && hasActiveStream(wifiInfo, mScoringParams)) {
- localLog("Stay on current network due to sufficient link quality and ongoing traffic");
- return true;
+ if (!hasSufficientLinkQuality(wifiInfo)) {
+ localLog("Current network link quality is not sufficient");
+ return false;
+ }
+
+ if (!hasActiveStream(wifiInfo)) {
+ localLog("Current network has low ongoing traffic");
+ return false;
}
- return false;
+ return true;
}
private boolean isNetworkSelectionNeeded(List<ScanDetail> scanDetails, WifiInfo wifiInfo,
@@ -312,7 +306,7 @@ public class WifiNetworkSelector {
// Please note other scans (e.g., location scan or app scan) may also trigger network
// selection and these scans may or may not run sufficiency check.
// So it is better to run sufficiency check here before network selection.
- if (isCurrentNetworkSufficient(wifiInfo)) {
+ if (isNetworkSufficient(wifiInfo)) {
localLog("Current connected network already sufficient. Skip network selection.");
return false;
} else {
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
index 3e72c14b2..0ec4849eb 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
@@ -94,7 +94,6 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
mWifiScanner = mockWifiScanner();
mWifiConnectivityHelper = mockWifiConnectivityHelper();
mWifiNS = mockWifiNetworkSelector();
- when(mScoringParams.getSufficientRssi(anyInt())).thenReturn(SUFFICIENT_RSSI_THRESHOLD);
when(mWifiInjector.getWifiScanner()).thenReturn(mWifiScanner);
when(mWifiInjector.getWifiNetworkSuggestionsManager())
.thenReturn(mWifiNetworkSuggestionsManager);
@@ -117,6 +116,8 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
*/
@After
public void cleanup() {
+ verify(mScoringParams, atLeast(0)).getEntryRssi(anyInt());
+ verifyNoMoreInteractions(mScoringParams);
validateMockitoUsage();
}
@@ -168,8 +169,6 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
private static final int MAX_SCAN_INTERVAL_IN_SCHEDULE = 60;
private static final int[] DEFAULT_SINGLE_SCAN_SCHEDULE = {20, 40, 80, 160};
private static final int MAX_SCAN_INTERVAL_IN_DEFAULT_SCHEDULE = 160;
- private static final int SUFFICIENT_RSSI_THRESHOLD = -60;
- private static final int SUFFICIENT_TX_SPEED_THRESHOLD = 24;
Resources mockResource() {
Resources resource = mock(Resources.class);
@@ -1264,9 +1263,8 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
*/
@Test
public void checkSingleScanSettingsWhenConnectedWithLowDataRate() {
- mWifiInfo.setSuccessfulTxPacketsPerSecond(0);
- mWifiInfo.setSuccessfulRxPacketsPerSecond(0);
- mWifiInfo.setRssi(SUFFICIENT_RSSI_THRESHOLD - 1);
+ when(mWifiNS.isNetworkSufficient(eq(mWifiInfo))).thenReturn(false);
+ when(mWifiNS.hasActiveStream(eq(mWifiInfo))).thenReturn(false);
final HashSet<Integer> channelList = new HashSet<>();
channelList.add(1);
@@ -1296,63 +1294,17 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
}
/**
- * Verify that we perform partial scan when the currently connected network's tx/rx success
- * rate is high, current RSSI is low and currently connected network is
- * present in scan cache in WifiConfigManager.
- * WifiConnectivityManager does partial scan only when firmware roaming is not supported.
- *
- * Expected behavior: WifiConnectivityManager does partial scan.
- */
- @Test
- public void checkPartialScanRequestedWithHighDataRateWithoutFwRoaming() {
- mWifiInfo.setSuccessfulTxPacketsPerSecond(mMinPacketRateActiveTraffic + 1);
- mWifiInfo.setSuccessfulRxPacketsPerSecond(mMinPacketRateActiveTraffic + 1);
- mWifiInfo.setRssi(SUFFICIENT_RSSI_THRESHOLD - 1);
-
- final HashSet<Integer> channelList = new HashSet<>();
- channelList.add(1);
- channelList.add(2);
- channelList.add(3);
-
- when(mClientModeImpl.getCurrentWifiConfiguration())
- .thenReturn(new WifiConfiguration());
- when(mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(anyInt(), anyLong(),
- anyInt())).thenReturn(channelList);
- when(mWifiConnectivityHelper.isFirmwareRoamingSupported()).thenReturn(false);
-
- doAnswer(new AnswerWithArguments() {
- public void answer(ScanSettings settings, ScanListener listener,
- WorkSource workSource) throws Exception {
- assertEquals(settings.band, WifiScanner.WIFI_BAND_UNSPECIFIED);
- assertEquals(settings.channels.length, channelList.size());
- for (int chanIdx = 0; chanIdx < settings.channels.length; chanIdx++) {
- assertTrue(channelList.contains(settings.channels[chanIdx].frequency));
- }
- }}).when(mWifiScanner).startScan(anyObject(), anyObject(), anyObject());
-
- // Set screen to ON
- mWifiConnectivityManager.handleScreenStateChanged(true);
-
- // Set WiFi to connected state to trigger periodic scan
- mWifiConnectivityManager.handleConnectionStateChanged(
- WifiConnectivityManager.WIFI_STATE_CONNECTED);
-
- verify(mWifiScanner).startScan(anyObject(), anyObject(), anyObject(), anyObject());
- }
-
- /**
- * Verify that we perform partial scan when the currently connected network's RSSI is high,
- * Tx/Rx success rates are low, and when the currently connected network is present
+ * Verify that we perform partial scan when the current network is not sufficient,
+ * Tx/Rx success rates are high, and when the currently connected network is present
* in scan cache in WifiConfigManager.
* WifiConnectivityManager does partial scan only when firmware roaming is not supported.
*
* Expected behavior: WifiConnectivityManager does partial scan.
*/
@Test
- public void checkPartialScanRequestedWithHighRssiTxSpeedWithoutFwRoaming() {
- mWifiInfo.setSuccessfulTxPacketsPerSecond(0.0);
- mWifiInfo.setSuccessfulTxPacketsPerSecond(0.0);
- mWifiInfo.setRssi(SUFFICIENT_RSSI_THRESHOLD + 1);
+ public void checkPartialScanRequestedWithLowRssiAndActiveStreamWithoutFwRoaming() {
+ when(mWifiNS.isNetworkSufficient(eq(mWifiInfo))).thenReturn(false);
+ when(mWifiNS.hasActiveStream(eq(mWifiInfo))).thenReturn(true);
final HashSet<Integer> channelList = new HashSet<>();
channelList.add(1);
@@ -1396,9 +1348,8 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
*/
@Test
public void checkSingleScanSettingsWhenConnectedWithHighDataRateNotInCache() {
- mWifiInfo.setSuccessfulTxPacketsPerSecond(mMinPacketRateActiveTraffic + 1);
- mWifiInfo.setSuccessfulRxPacketsPerSecond(mMinPacketRateActiveTraffic + 1);
- mWifiInfo.setRssi(SUFFICIENT_RSSI_THRESHOLD + 1);
+ when(mWifiNS.isNetworkSufficient(eq(mWifiInfo))).thenReturn(true);
+ when(mWifiNS.hasActiveStream(eq(mWifiInfo))).thenReturn(true);
final HashSet<Integer> channelList = new HashSet<>();
@@ -2175,6 +2126,9 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
scanSettingsCaptor.capture(), any(), any(), any());
assertEquals(scanSettingsCaptor.getValue().periodInMs,
WifiConnectivityManager.STATIONARY_PNO_SCAN_INTERVAL_MS);
+ verify(mScoringParams, times(2)).getEntryRssi(ScoringParams.BAND6);
+ verify(mScoringParams, times(2)).getEntryRssi(ScoringParams.BAND5);
+ verify(mScoringParams, times(2)).getEntryRssi(ScoringParams.BAND2);
}
/**