Wifi: enhance pre-scan check and simplify network selection sufficiency check.

1) Skip single scan scheduled by periodic scan alarm if current RSSI ssufficient
2) Simplify pre-network-selection sufficiency check. Skip selection only if
 +) Current network has internet access, active traffic and sufficient RSSI.
 +) or current network is in OSU process.
3) Move to rely on network selection scorer to stick with user selected network.

Bug: 141714375
Test: unit test with atest com.android.server.wifi
Test: manual test with phone.
Change-Id: Id232b59a546271d7f0798bc6a85ca6ccd65621e9
diff --git a/service/java/com/android/server/wifi/ScoringParams.java b/service/java/com/android/server/wifi/ScoringParams.java
index 94efde1..2168487 100644
--- a/service/java/com/android/server/wifi/ScoringParams.java
+++ b/service/java/com/android/server/wifi/ScoringParams.java
@@ -48,6 +48,8 @@
     private static final int SUFFICIENT = 2;
     private static final int GOOD = 3;
 
+    private static final int ACTIVE_TRAFFIC = 1;
+    private static final int HIGH_TRAFFIC = 2;
     /**
      * Parameter values are stored in a separate container so that a new collection of values can
      * be checked for consistency before activating them.
@@ -284,7 +286,10 @@
                 R.integer.config_wifiFrameworkSecureNetworkBonus);
         mVal.lastSelectionBonus = context.getResources().getInteger(
                 R.integer.config_wifiFrameworkLastSelectionBonus);
-
+        mVal.pps[ACTIVE_TRAFFIC] = context.getResources().getInteger(
+                R.integer.config_wifiFrameworkMinPacketPerSecondActiveTraffic);
+        mVal.pps[HIGH_TRAFFIC] = context.getResources().getInteger(
+                R.integer.config_wifiFrameworkMinPacketPerSecondHighTraffic);
         try {
             mVal.validate();
         } catch (IllegalArgumentException e) {
@@ -409,7 +414,15 @@
      */
     public int getYippeeSkippyPacketsPerSecond() {
         loadResources(mContext);
-        return mVal.pps[2];
+        return mVal.pps[HIGH_TRAFFIC];
+    }
+
+    /**
+     * Returns a packet rate that should be considered acceptable to skip scan or network selection
+     */
+    public int getActiveTrafficPacketsPerSecond() {
+        loadResources(mContext);
+        return mVal.pps[ACTIVE_TRAFFIC];
     }
 
     /**
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java
index 5c67fa5..53261d3 100644
--- a/service/java/com/android/server/wifi/WifiConnectivityManager.java
+++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java
@@ -268,8 +268,8 @@
     /**
      * Set whether bluetooth is in the connected state
      */
-    public void setBluetoothConnected(boolean isBlueToothConnected) {
-        mNetworkSelector.setBluetoothConnected(isBlueToothConnected);
+    public void setBluetoothConnected(boolean isBluetoothConnected) {
+        mNetworkSelector.setBluetoothConnected(isBluetoothConnected);
     }
 
     // All single scan results listener.
@@ -574,7 +574,6 @@
         mClock = clock;
         mScoringParams = scoringParams;
         mConnectionAttemptTimeStamps = new LinkedList<>();
-
         mPnoScanIntervalMs = MOVING_PNO_SCAN_INTERVAL_MS;
 
         // Listen to WifiConfigManager network update events
@@ -815,15 +814,12 @@
 
         boolean isScanNeeded = true;
         boolean isFullBandScan = true;
-        boolean isTrafficOverThreshold = mWifiInfo.getTxSuccessRate()
-                > mContext.getResources().getInteger(
-                        R.integer.config_wifi_framework_max_tx_rate_for_full_scan)
-                || mWifiInfo.getRxSuccessRate()
-                > mContext.getResources().getInteger(
-                        R.integer.config_wifi_framework_max_rx_rate_for_full_scan);
 
-        // If the WiFi traffic is heavy, only partial scan is proposed.
-        if (mWifiState == WIFI_STATE_CONNECTED && isTrafficOverThreshold) {
+        // 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 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.
@@ -831,7 +827,7 @@
                 localLog("No partial scan because firmware roaming is supported.");
                 isScanNeeded = false;
             } else {
-                localLog("No full band scan due to ongoing traffic");
+                localLog("No full band scan because current network is sufficient");
                 isFullBandScan = false;
             }
         }
diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java
index 426a814..fec8e0d 100644
--- a/service/java/com/android/server/wifi/WifiNetworkSelector.java
+++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java
@@ -214,7 +214,34 @@
         mLocalLog.log(log);
     }
 
-    private boolean isCurrentNetworkSufficient(WifiInfo wifiInfo, List<ScanDetail> scanDetails) {
+    /**
+     * 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) {
+        int currentRssi = wifiInfo.getRssi();
+        return  currentRssi >= scoringParams.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.getTxSuccessRate() > scoringParams.getActiveTrafficPacketsPerSecond())
+                || (wifiInfo.getRxSuccessRate() > scoringParams.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
+     */
+    private boolean isCurrentNetworkSufficient(WifiInfo wifiInfo) {
         // Currently connected?
         if (wifiInfo.getSupplicantState() != SupplicantState.COMPLETED) {
             localLog("No current connected network.");
@@ -224,19 +251,6 @@
                     + " , ID: " + wifiInfo.getNetworkId());
         }
 
-        final int stayOnNetworkMinimumTxRate = mContext.getResources().getInteger(
-                R.integer.config_wifi_framework_min_tx_rate_for_staying_on_network);
-        final int stayOnNetworkMinimumRxRate = mContext.getResources().getInteger(
-                R.integer.config_wifi_framework_min_rx_rate_for_staying_on_network);
-        int currentRssi = wifiInfo.getRssi();
-        boolean hasQualifiedRssi = currentRssi
-                > mScoringParams.getSufficientRssi(wifiInfo.getFrequency());
-        boolean hasActiveStream = (wifiInfo.getTxSuccessRate() > stayOnNetworkMinimumTxRate)
-                || (wifiInfo.getRxSuccessRate() > stayOnNetworkMinimumRxRate);
-        if (hasQualifiedRssi && hasActiveStream) {
-            localLog("Stay on current network because of good RSSI and ongoing traffic");
-            return true;
-        }
         WifiConfiguration network =
                 mWifiConfigManager.getConfiguredNetwork(wifiInfo.getNetworkId());
 
@@ -245,58 +259,25 @@
             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.
+        // 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) {
             return true;
         }
 
-        // Ephemeral network is not qualified.
-        if (wifiInfo.isEphemeral()) {
-            localLog("Current network is an ephemeral one.");
-            return false;
-        }
-
-        if (wifiInfo.is24GHz()) {
-            // 2.4GHz networks is not qualified whenever 5GHz is available
-            if (is5GHzNetworkAvailable(scanDetails)) {
-                localLog("Current network is 2.4GHz. 5GHz networks available.");
-                return false;
-            }
-        }
-        if (!hasQualifiedRssi) {
-            localLog("Current network RSSI[" + currentRssi + "]-acceptable but not qualified.");
-            return false;
-        }
-
-        // Open network is not qualified.
-        if (WifiConfigurationUtil.isConfigForOpenNetwork(network)) {
-            localLog("Current network is a open one.");
-            return false;
-        }
-
-        // Network with no internet access reports is not qualified.
+        // Network with no internet access reports is not sufficient
         if (network.numNoInternetAccessReports > 0 && !network.noInternetAccessExpected) {
             localLog("Current network has [" + network.numNoInternetAccessReports
                     + "] no-internet access reports.");
             return false;
         }
-        return true;
-    }
 
-    // Determine whether there are any 5GHz networks in the scan result
-    private boolean is5GHzNetworkAvailable(List<ScanDetail> scanDetails) {
-        for (ScanDetail detail : scanDetails) {
-            ScanResult result = detail.getScanResult();
-            if (result.is5GHz()) return true;
+        if ((hasSufficientLinkQuality(wifiInfo, mScoringParams))
+                && hasActiveStream(wifiInfo, mScoringParams)) {
+            localLog("Stay on current network due to sufficient link quality and ongoing traffic");
+            return true;
         }
+
         return false;
     }
 
@@ -326,8 +307,10 @@
                     return false;
                 }
             }
-
-            if (isCurrentNetworkSufficient(wifiInfo, scanDetails)) {
+            // 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)) {
                 localLog("Current connected network already sufficient. Skip network selection.");
                 return false;
             } else {
@@ -828,6 +811,7 @@
         // Get a fresh copy of WifiConfiguration reflecting any scan result updates
         WifiConfiguration selectedNetwork =
                 mWifiConfigManager.getConfiguredNetwork(selectedNetworkId);
+        // TODO (b/136675430): the legacyOverrideWanted check seems unnecessary
         if (selectedNetwork != null && legacyOverrideWanted) {
             selectedNetwork = overrideCandidateWithUserConnectChoice(selectedNetwork);
             mLastNetworkSelectionTimeStamp = mClock.getElapsedSinceBootMillis();
diff --git a/service/res/values/config.xml b/service/res/values/config.xml
index ec8da0e..29cd634 100644
--- a/service/res/values/config.xml
+++ b/service/res/values/config.xml
@@ -98,12 +98,12 @@
          boundaries. -->
     <integer translatable="false" name="config_wifiFrameworkLastSelectionBonus">1999</integer>
 
-    <!-- Integers specifying the max packet Tx/Rx rates for full scan -->
-    <integer translatable="false" name="config_wifi_framework_max_tx_rate_for_full_scan">8</integer>
-    <integer translatable="false" name="config_wifi_framework_max_rx_rate_for_full_scan">16</integer>
-    <!-- Integers specifying the min packet Tx/Rx rates in packets per second for staying on the same network -->
-    <integer translatable="false" name="config_wifi_framework_min_tx_rate_for_staying_on_network">16</integer>
-    <integer translatable="false" name="config_wifi_framework_min_rx_rate_for_staying_on_network">16</integer>
+    <!-- Integer specifying the min packet Tx/Rx rates in packets per second to be considered
+         active traffic so that network selection and scan could be skipped-->
+    <integer translatable="false" name="config_wifiFrameworkMinPacketPerSecondActiveTraffic">16</integer>
+    <!-- Integer specifying the min packet Tx/Rx rates in packets per second to be considered
+         high traffic so that the device should stay on WiFi even if RSSI is very low -->
+    <integer translatable="false" name="config_wifiFrameworkMinPacketPerSecondHighTraffic">100</integer>
     <!-- Integer parameters of the wifi to cellular handover feature
          wifi should not stick to bad networks -->
     <!-- Integer threshold for low network score, should be somewhat less than the entry threshhold -->
diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml
index e7b82ce..a60e04d 100644
--- a/service/res/values/overlayable.xml
+++ b/service/res/values/overlayable.xml
@@ -40,10 +40,8 @@
           <item type="integer" name="config_wifiFrameworkCurrentNetworkBonus" />
           <item type="integer" name="config_wifiFrameworkSecureNetworkBonus" />
           <item type="integer" name="config_wifiFrameworkLastSelectionBonus" />
-          <item type="integer" name="config_wifi_framework_max_tx_rate_for_full_scan" />
-          <item type="integer" name="config_wifi_framework_max_rx_rate_for_full_scan" />
-          <item type="integer" name="config_wifi_framework_min_tx_rate_for_staying_on_network" />
-          <item type="integer" name="config_wifi_framework_min_rx_rate_for_staying_on_network" />
+          <item type="integer" name="config_wifiFrameworkMinPacketPerSecondActiveTraffic" />
+          <item type="integer" name="config_wifiFrameworkMinPacketPerSecondHighTraffic" />
           <item type="integer" name="config_wifi_framework_wifi_score_bad_rssi_threshold_5GHz" />
           <item type="integer" name="config_wifi_framework_wifi_score_entry_rssi_threshold_5GHz" />
           <item type="integer" name="config_wifi_framework_wifi_score_low_rssi_threshold_5GHz" />
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
index 306a95b..223af75 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
@@ -93,6 +93,7 @@
         mWifiScanner = mockWifiScanner();
         mWifiConnectivityHelper = mockWifiConnectivityHelper();
         mWifiNS = mockWifiNetworkSelector();
+        when(mScoringParams.getSufficientRssi(anyInt())).thenReturn(SUFFICIENT_RSSI_THRESHOLD);
         when(mWifiInjector.getWifiScanner()).thenReturn(mWifiScanner);
         when(mWifiInjector.getWifiNetworkSuggestionsManager())
                 .thenReturn(mWifiNetworkSuggestionsManager);
@@ -105,10 +106,8 @@
         mWifiConnectivityManager.setTrustedConnectionAllowed(true);
         mWifiConnectivityManager.setWifiEnabled(true);
         when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime());
-        mFullScanMaxTxPacketRate = mResource.getInteger(
-                R.integer.config_wifi_framework_max_tx_rate_for_full_scan);
-        mFullScanMaxRxPacketRate = mResource.getInteger(
-                R.integer.config_wifi_framework_max_rx_rate_for_full_scan);
+        mMinPacketRateActiveTraffic = mResource.getInteger(
+                R.integer.config_wifiFrameworkMinPacketPerSecondActiveTraffic);
         when(mWifiLastResortWatchdog.shouldIgnoreBssidUpdate(anyString())).thenReturn(false);
     }
 
@@ -144,14 +143,14 @@
     @Mock private WifiNetworkSuggestionsManager mWifiNetworkSuggestionsManager;
     @Mock private BssidBlocklistMonitor mBssidBlocklistMonitor;
     @Mock private WifiChannelUtilization mWifiChannelUtilization;
+    @Mock private ScoringParams mScoringParams;
     @Captor ArgumentCaptor<ScanResult> mCandidateScanResultCaptor;
     @Captor ArgumentCaptor<ArrayList<String>> mBssidBlacklistCaptor;
     @Captor ArgumentCaptor<ArrayList<String>> mSsidWhitelistCaptor;
     @Captor ArgumentCaptor<WifiConfigManager.OnNetworkUpdateListener>
             mNetworkUpdateListenerCaptor;
     private MockResources mResources;
-    private int mFullScanMaxTxPacketRate;
-    private int mFullScanMaxRxPacketRate;
+    private int mMinPacketRateActiveTraffic;
 
     private static final int CANDIDATE_NETWORK_ID = 0;
     private static final String CANDIDATE_SSID = "\"AnSsid\"";
@@ -167,6 +166,8 @@
     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);
@@ -177,16 +178,13 @@
                 R.integer.config_wifi_framework_wifi_score_good_rssi_threshold_24GHz))
                 .thenReturn(-60);
         when(resource.getInteger(
-                R.integer.config_wifi_framework_max_tx_rate_for_full_scan)).thenReturn(8);
-        when(resource.getInteger(
-                R.integer.config_wifi_framework_max_rx_rate_for_full_scan)).thenReturn(16);
+                R.integer.config_wifiFrameworkMinPacketPerSecondActiveTraffic)).thenReturn(16);
         when(resource.getIntArray(
                 R.array.config_wifiConnectedScanIntervalScheduleSec))
                 .thenReturn(VALID_CONNECTED_SINGLE_SCAN_SCHEDULE);
         when(resource.getIntArray(
                 R.array.config_wifiDisconnectedScanIntervalScheduleSec))
                 .thenReturn(VALID_DISCONNECTED_SINGLE_SCAN_SCHEDULE);
-
         return resource;
     }
 
@@ -333,7 +331,7 @@
 
     WifiConnectivityManager createConnectivityManager() {
         return new WifiConnectivityManager(mContext,
-                new ScoringParams(mContext),
+                mScoringParams,
                 mClientModeImpl, mWifiInjector,
                 mWifiConfigManager, mWifiInfo, mWifiNS, mWifiConnectivityHelper,
                 mWifiLastResortWatchdog, mOpenNetworkNotifier,
@@ -1129,7 +1127,7 @@
 
     /**
      * Verify that we perform full band scan when the currently connected network's tx/rx success
-     * rate is low.
+     * rate is low and current RSSI is also low.
      *
      * Expected behavior: WifiConnectivityManager does full band scan.
      */
@@ -1137,6 +1135,7 @@
     public void checkSingleScanSettingsWhenConnectedWithLowDataRate() {
         mWifiInfo.setTxSuccessRate(0);
         mWifiInfo.setRxSuccessRate(0);
+        mWifiInfo.setRssi(SUFFICIENT_RSSI_THRESHOLD - 1);
 
         final HashSet<Integer> channelList = new HashSet<>();
         channelList.add(1);
@@ -1167,16 +1166,17 @@
 
     /**
      * Verify that we perform partial scan when the currently connected network's tx/rx success
-     * rate is high and when the currently connected network is present in scan
-     * cache in WifiConfigManager.
+     * 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.setTxSuccessRate(mFullScanMaxTxPacketRate * 2);
-        mWifiInfo.setRxSuccessRate(mFullScanMaxRxPacketRate * 2);
+        mWifiInfo.setTxSuccessRate(mMinPacketRateActiveTraffic + 1);
+        mWifiInfo.setRxSuccessRate(mMinPacketRateActiveTraffic + 1);
+        mWifiInfo.setRssi(SUFFICIENT_RSSI_THRESHOLD - 1);
 
         final HashSet<Integer> channelList = new HashSet<>();
         channelList.add(1);
@@ -1210,21 +1210,18 @@
     }
 
     /**
-     * Verify that we skip the partial scan when:
-     * 1. The currently connected network's tx/rx success rate is high.
-     * 2. When the currently connected network is present in scan
-     * cache in WifiConfigManager.
-     * 3. When firmware roaming is supported.
-     * Expected behavior: WifiConnectivityManager does no scan, but periodic scans
-     * are still scheduled.
+     * 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
+     * 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 checkPartialScanSkippedWithHighDataRateWithFwRoaming() {
-        mWifiInfo.setTxSuccessRate(mFullScanMaxTxPacketRate * 2);
-        mWifiInfo.setRxSuccessRate(mFullScanMaxRxPacketRate * 2);
-
-        long currentTimeStamp = CURRENT_SYSTEM_TIME_MS;
-        when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp);
+    public void checkPartialScanRequestedWithHighRssiTxSpeedWithoutFwRoaming() {
+        mWifiInfo.setTxSuccessRate(0.0);
+        mWifiInfo.setTxSuccessRate(0.0);
+        mWifiInfo.setRssi(SUFFICIENT_RSSI_THRESHOLD + 1);
 
         final HashSet<Integer> channelList = new HashSet<>();
         channelList.add(1);
@@ -1235,8 +1232,17 @@
                 .thenReturn(new WifiConfiguration());
         when(mWifiConfigManager.fetchChannelSetForNetworkForPartialScan(anyInt(), anyLong(),
                 anyInt())).thenReturn(channelList);
-        // No scan will be requested when firmware roaming control is not supported.
-        when(mWifiConnectivityHelper.isFirmwareRoamingSupported()).thenReturn(true);
+        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);
@@ -1245,27 +1251,23 @@
         mWifiConnectivityManager.handleConnectionStateChanged(
                 WifiConnectivityManager.WIFI_STATE_CONNECTED);
 
-        verify(mWifiScanner, never()).startScan(anyObject(), anyObject(), anyObject());
-
-        // Get the first periodic scan interval to check that we are still scheduling
-        // periodic scans.
-        long firstIntervalMs = mAlarmManager
-                .getTriggerTimeMillis(WifiConnectivityManager.PERIODIC_SCAN_TIMER_TAG)
-                - currentTimeStamp;
-        assertEquals(VALID_CONNECTED_SINGLE_SCAN_SCHEDULE[0] * 1000, firstIntervalMs);
+        verify(mWifiScanner).startScan(anyObject(), anyObject(), anyObject());
     }
 
+
     /**
      * Verify that we fall back to full band scan when the currently connected network's tx/rx
-     * success rate is high and the currently connected network is not present in scan cache in
-     * WifiConfigManager. This is simulated by returning an empty hashset in |makeChannelList|.
+     * success rate is high, RSSI is also high but the currently connected network
+     * is not present in scan cache in WifiConfigManager.
+     * This is simulated by returning an empty hashset in |makeChannelList|.
      *
      * Expected behavior: WifiConnectivityManager does full band scan.
      */
     @Test
     public void checkSingleScanSettingsWhenConnectedWithHighDataRateNotInCache() {
-        mWifiInfo.setTxSuccessRate(mFullScanMaxTxPacketRate * 2);
-        mWifiInfo.setRxSuccessRate(mFullScanMaxRxPacketRate * 2);
+        mWifiInfo.setTxSuccessRate(mMinPacketRateActiveTraffic + 1);
+        mWifiInfo.setRxSuccessRate(mMinPacketRateActiveTraffic + 1);
+        mWifiInfo.setRssi(SUFFICIENT_RSSI_THRESHOLD + 1);
 
         final HashSet<Integer> channelList = new HashSet<>();
 
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java
index db914ea..a8d94d7 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java
@@ -216,8 +216,7 @@
     private int mThresholdMinimumRssi5G;
     private int mThresholdQualifiedRssi2G;
     private int mThresholdQualifiedRssi5G;
-    private int mStayOnNetworkMinimumTxRate;
-    private int mStayOnNetworkMinimumRxRate;
+    private int mMinPacketRateActiveTraffic;
     private CompatibilityScorer mCompatibilityScorer;
     private ScoreCardBasedScorer mScoreCardBasedScorer;
     private ThroughputScorer mThroughputScorer;
@@ -235,11 +234,8 @@
     private void setupResources() {
         doReturn(true).when(mResource).getBoolean(
                 R.bool.config_wifi_framework_enable_associated_network_selection);
-
-        mStayOnNetworkMinimumTxRate = setupIntegerResource(
-                R.integer.config_wifi_framework_min_tx_rate_for_staying_on_network, 16);
-        mStayOnNetworkMinimumRxRate = setupIntegerResource(
-                R.integer.config_wifi_framework_min_rx_rate_for_staying_on_network, 16);
+        mMinPacketRateActiveTraffic = setupIntegerResource(
+                R.integer.config_wifiFrameworkMinPacketPerSecondActiveTraffic, 16);
         doReturn(false).when(mResource).getBoolean(R.bool.config_wifi_11ax_supported);
         doReturn(false).when(mResource).getBoolean(
                 R.bool.config_wifi_contiguous_160mhz_supported);
@@ -339,7 +335,7 @@
      *
      * ClientModeImpl is in connected state.
      * scanDetails contains two valid networks.
-     * Perform a network seletion right after the first one.
+     * Perform a network selection right after the first one.
      *
      * Expected behavior: no network recommended by Network Selector
      */
@@ -355,7 +351,7 @@
         // Make a network selection.
         ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
                 WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
-                    freqs, caps, levels, securities, mWifiConfigManager, mClock);
+                        freqs, caps, levels, securities, mWifiConfigManager, mClock);
         List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
         HashSet<String> blacklist = new HashSet<String>();
         WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails,
@@ -417,59 +413,11 @@
 
     /**
      * New network selection is performed if the currently connected network
-     * is a open one.
-     *
-     * ClientModeImpl is connected to a open network.
-     * scanDetails contains a valid networks.
-     * Perform a network seletion after the first one.
-     *
-     * Expected behavior: the first network is recommended by Network Selector
-     */
-    @Test
-    public void openNetworkIsNotSufficient() {
-        String[] ssids = {"\"test1\""};
-        String[] bssids = {"6c:f3:7f:ae:8c:f3"};
-        int[] freqs = {5180};
-        String[] caps = {"[ESS]"};
-        int[] levels = {mThresholdQualifiedRssi5G + 8};
-        int[] securities = {SECURITY_NONE};
-
-        ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
-                WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
-                    freqs, caps, levels, securities, mWifiConfigManager, mClock);
-        List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
-        HashSet<String> blacklist = new HashSet<String>();
-        WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
-
-        // connect to test1
-        mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false);
-        when(mWifiInfo.getSupplicantState()).thenReturn(SupplicantState.COMPLETED);
-        when(mWifiInfo.getNetworkId()).thenReturn(0);
-        when(mWifiInfo.getBSSID()).thenReturn(bssids[0]);
-        when(mWifiInfo.is24GHz()).thenReturn(false);
-        when(mWifiInfo.is5GHz()).thenReturn(true);
-        when(mWifiInfo.getFrequency()).thenReturn(5000);
-
-        when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime()
-                + WifiNetworkSelector.MINIMUM_NETWORK_SELECTION_INTERVAL_MS + 2000);
-
-        // Do another network selection.
-        WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails,
-                blacklist, mWifiInfo, true, false, false);
-
-        ScanResult chosenScanResult = scanDetails.get(0).getScanResult();
-        WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate);
-        WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
-                chosenScanResult, candidate);
-    }
-
-    /**
-     * New network selection is performed if the currently connected network
      * has low RSSI value.
      *
      * ClientModeImpl is connected to a low RSSI 5GHz network.
      * scanDetails contains a valid networks.
-     * Perform a network seletion after the first one.
+     * Perform a network selection after the first one.
      *
      * Expected behavior: the first network is recommended by Network Selector
      */
@@ -513,7 +461,7 @@
 
     /**
      * New network selection is performed if the currently connected network
-     * has no internet access and the user did not explicitly choose to stay connected.
+     * has no internet access although it has active traffic and high RSSI
      *
      * ClientModeImpl is connected to a network with no internet connectivity.
      * scanDetails contains a valid networks.
@@ -546,6 +494,8 @@
         when(mWifiInfo.is5GHz()).thenReturn(true);
         when(mWifiInfo.getFrequency()).thenReturn(5000);
         when(mWifiInfo.getRssi()).thenReturn(levels[0]);
+        when(mWifiInfo.getTxSuccessRate()).thenReturn(mMinPacketRateActiveTraffic - 1.0);
+        when(mWifiInfo.getRxSuccessRate()).thenReturn(mMinPacketRateActiveTraffic + 1.0);
 
         when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime()
                 + WifiNetworkSelector.MINIMUM_NETWORK_SELECTION_INTERVAL_MS + 2000);
@@ -561,7 +511,6 @@
         WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
                 chosenScanResult, candidate);
     }
-
     /**
      * Ensure that network selector update's network selection status for all configured
      * networks before performing network selection.
@@ -656,6 +605,7 @@
         when(mWifiInfo.getNetworkId()).thenReturn(0);
         when(mWifiInfo.getBSSID()).thenReturn(bssids[0]);
         when(mWifiInfo.is24GHz()).thenReturn(true);
+        when(mWifiInfo.getScore()).thenReturn(ConnectedScore.WIFI_TRANSITION_SCORE);
         when(mWifiInfo.is5GHz()).thenReturn(false);
         when(mWifiInfo.getFrequency()).thenReturn(2400);
         when(mWifiInfo.getRssi()).thenReturn(levels[0]);
@@ -842,54 +792,24 @@
     }
 
     /**
-     * Wifi network selector doesn't recommend any network if the currently connected 2.4Ghz
-     * network is high quality and no 5GHz networks are available
-     *
-     * ClientModeImpl is under connected state and 2.4GHz test1 is connected.
-     *
-     * Expected behavior: no network selection is performed
-     */
-    @Test
-    public void test2GhzQualifiedNo5GhzAvailable() {
-        // Rssi after connected.
-        when(mWifiInfo.getRssi()).thenReturn(mThresholdQualifiedRssi2G + 1);
-        // No streaming traffic.
-        mWifiInfo.setTxSuccessRate(0.0);
-        mWifiInfo.setRxSuccessRate(0.0);
-
-        // Do not perform selection on 2GHz if current network is good and no 5GHz available
-        testStayOrTryToSwitch(
-                mThresholdQualifiedRssi2G + 1 /* rssi before connected */,
-                false /* not a 5G network */,
-                false /* not open network */,
-                // Should not try to switch.
-                false);
-    }
-
-    /**
-     * Wifi network selector performs network selection even when the 2Ghz network is high
-     * quality whenever 5Ghz networks are available.
-     *
-     * ClientModeImpl is under connected state and 2.4GHz test1 is connected.
-     * The scan results contain a 5Ghz network, which forces network selection.
-     * Test1 is not in the second scan results.
+     * Wifi network selector performs network selection when current network has high
+     * quality but no active stream
      *
      * Expected behavior: network selection is performed
      */
     @Test
-    public void test2GhzHighQuality5GhzAvailable() {
+    public void testNoActiveStream() {
         // Rssi after connected.
         when(mWifiInfo.getRssi()).thenReturn(mThresholdQualifiedRssi2G + 1);
-        // No streaming traffic.
-        mWifiInfo.setTxSuccessRate(0.0);
-        mWifiInfo.setRxSuccessRate(0.0);
+        when(mWifiInfo.getTxSuccessRate()).thenReturn(0.0);
+        when(mWifiInfo.getRxSuccessRate()).thenReturn(0.0);
 
-        // When on 2GHz, even with "good" signal strength, run selection if 5GHz available
         testStayOrTryToSwitch(
                 // Parameters for network1:
                 mThresholdQualifiedRssi2G + 1 /* rssi before connected */,
                 false /* not a 5G network */,
                 false /* not open network */,
+                false /* not a osu */,
                 // Parameters for network2:
                 mThresholdQualifiedRssi5G + 1 /* rssi */,
                 true /* a 5G network */,
@@ -899,47 +819,45 @@
     }
 
     /**
-     * Wifi network selector performs network selection when connected to a 5Ghz network that
-     * has an insufficient RSSI.
+     * Wifi network selector skips network selection when current network is osu and has low RSSI
      *
-     * ClientModeImpl is under connected state and 5GHz test1 is connected.
-     *
-     * Expected behavior: network selection is performed
+     * Expected behavior: network selection is skipped
      */
     @Test
-    public void test5GhzNotQualifiedLowRssi() {
+    public void testOsuIsSufficient() {
         // Rssi after connected.
         when(mWifiInfo.getRssi()).thenReturn(mThresholdQualifiedRssi5G - 1);
-        // No streaming traffic.
-        mWifiInfo.setTxSuccessRate(0.0);
-        mWifiInfo.setRxSuccessRate(0.0);
+        when(mWifiInfo.getTxSuccessRate()).thenReturn(0.0);
+        when(mWifiInfo.getRxSuccessRate()).thenReturn(0.0);
 
-        // Run Selection when the current 5Ghz network has low RSSI.
         testStayOrTryToSwitch(
-                mThresholdQualifiedRssi5G + 1 /* rssi before connected */,
+                // Parameters for network1:
+                mThresholdQualifiedRssi5G - 1 /* rssi before connected */,
+                false /* not a 5G network */,
+                false /* not open network */,
+                true /* osu */,
+                // Parameters for network2:
+                mThresholdQualifiedRssi5G + 1 /* rssi */,
                 true /* a 5G network */,
                 false /* not open network */,
-                // Should try to switch.
-                true);
+                // Should not try to switch.
+                false);
     }
 
     /**
-     * Wifi network selector will not run selection when on a 5Ghz network that is of sufficent
-     * Quality (high-enough RSSI).
+     * Wifi network selector will not perform network selection when current network has high
+     * quality and active stream
      *
-     * ClientModeImpl is under connected state and 5GHz test1 is connected.
      *
      * Expected behavior: network selection is not performed
      */
     @Test
-    public void test5GhzQualified() {
+    public void testSufficientLinkQualityActiveStream() {
         // Rssi after connected.
         when(mWifiInfo.getRssi()).thenReturn(mThresholdQualifiedRssi5G + 1);
-        // No streaming traffic.
-        mWifiInfo.setTxSuccessRate(0.0);
-        mWifiInfo.setRxSuccessRate(0.0);
+        when(mWifiInfo.getTxSuccessRate()).thenReturn(mMinPacketRateActiveTraffic - 1.0);
+        when(mWifiInfo.getRxSuccessRate()).thenReturn(mMinPacketRateActiveTraffic * 2.0);
 
-        // Connected to a high quality 5Ghz network, so the other result is irrelevant
         testStayOrTryToSwitch(
                 mThresholdQualifiedRssi5G + 1 /* rssi before connected */,
                 true /* a 5G network */,
@@ -948,81 +866,19 @@
                 false);
     }
 
+
     /**
-     * New network selection is performed if the currently connected network
-     * band is 2G and there is no sign of streaming traffic.
+     * New network selection is performed if the currently connected network has bad rssi.
      *
      * Expected behavior: Network Selector perform network selection after connected
      * to the first one.
      */
     @Test
-    public void band2GNetworkIsNotSufficientWhenNoOngoingTrafficAnd5GhzAvailable() {
-        // Rssi after connected.
-        when(mWifiInfo.getRssi()).thenReturn(mThresholdQualifiedRssi2G + 1);
-        // No streaming traffic.
-        mWifiInfo.setTxSuccessRate(0.0);
-        mWifiInfo.setRxSuccessRate(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 try to switch.
-                true);
-    }
-
-    /**
-     * 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.setTxSuccessRate(0.0);
-        mWifiInfo.setRxSuccessRate(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.
-     *
-     * Expected behavior: Network Selector perform network selection after connected
-     * to the first one.
-     */
-    @Test
-    public void band2GNetworkIsNotSufficientWithBadRssi() {
+    public void testBadRssi() {
         // Rssi after connected.
         when(mWifiInfo.getRssi()).thenReturn(mThresholdQualifiedRssi2G - 1);
-        // No streaming traffic.
-        mWifiInfo.setTxSuccessRate(0.0);
-        mWifiInfo.setRxSuccessRate(0.0);
+        when(mWifiInfo.getTxSuccessRate()).thenReturn(mMinPacketRateActiveTraffic + 1.0);
+        when(mWifiInfo.getRxSuccessRate()).thenReturn(mMinPacketRateActiveTraffic - 1.0);
 
         testStayOrTryToSwitch(
                 mThresholdQualifiedRssi2G + 1 /* rssi before connected */,
@@ -1033,94 +889,6 @@
     }
 
     /**
-     * New network selection is not performed if the currently connected 2G network
-     * has good Rssi and sign of streaming tx traffic.
-     *
-     * Expected behavior: Network selector does not perform network selection.
-     */
-    @Test
-    public void band2GNetworkIsSufficientWhenOnGoingTxTrafficCombinedWithGoodRssi() {
-        // Rssi after connected.
-        when(mWifiInfo.getRssi()).thenReturn(mThresholdQualifiedRssi2G + 1);
-        // Streaming traffic
-        when(mWifiInfo.getTxSuccessRate()).thenReturn(mStayOnNetworkMinimumTxRate + 1.0);
-        when(mWifiInfo.getRxSuccessRate()).thenReturn(0.0);
-
-        testStayOrTryToSwitch(
-                mThresholdQualifiedRssi2G + 1 /* rssi before connected */,
-                false /* not a 5G network */,
-                true /* open network */,
-                // Should not try to switch.
-                false);
-    }
-
-    /**
-     * New network selection is not performed if the currently connected 2G network
-     * has good Rssi and sign of streaming rx traffic.
-     *
-     * Expected behavior: Network selector does not perform network selection.
-     */
-    @Test
-    public void band2GNetworkIsSufficientWhenOnGoingRxTrafficCombinedWithGoodRssi() {
-        // Rssi after connected.
-        when(mWifiInfo.getRssi()).thenReturn(mThresholdQualifiedRssi2G + 1);
-        // Streaming traffic
-        when(mWifiInfo.getTxSuccessRate()).thenReturn(0.0);
-        when(mWifiInfo.getRxSuccessRate()).thenReturn(mStayOnNetworkMinimumRxRate + 1.0);
-
-        testStayOrTryToSwitch(
-                mThresholdQualifiedRssi2G + 1 /* rssi before connected */,
-                false /* not a 5G network */,
-                true /* open network */,
-                // Should not try to switch.
-                false);
-    }
-
-    /**
-     * New network selection is not performed if the currently connected 5G network
-     * has good Rssi and sign of streaming tx traffic.
-     *
-     * Expected behavior: Network selector does not perform network selection.
-     */
-    @Test
-    public void band5GNetworkIsSufficientWhenOnGoingTxTrafficCombinedWithGoodRssi() {
-        // Rssi after connected.
-        when(mWifiInfo.getRssi()).thenReturn(mThresholdQualifiedRssi5G + 1);
-        // Streaming traffic
-        when(mWifiInfo.getTxSuccessRate()).thenReturn(mStayOnNetworkMinimumTxRate + 1.0);
-        when(mWifiInfo.getRxSuccessRate()).thenReturn(0.0);
-
-        testStayOrTryToSwitch(
-                mThresholdQualifiedRssi5G + 1 /* rssi before connected */,
-                true /* a 5G network */,
-                true /* open network */,
-                // Should not try to switch.
-                false);
-    }
-
-    /**
-     * New network selection is not performed if the currently connected 5G network
-     * has good Rssi and sign of streaming rx traffic.
-     *
-     * Expected behavior: Network selector does not perform network selection.
-     */
-    @Test
-    public void band5GNetworkIsSufficientWhenOnGoingRxTrafficCombinedWithGoodRssi() {
-        // Rssi after connected.
-        when(mWifiInfo.getRssi()).thenReturn(mThresholdQualifiedRssi5G + 1);
-        // Streaming traffic
-        when(mWifiInfo.getTxSuccessRate()).thenReturn(0.0);
-        when(mWifiInfo.getRxSuccessRate()).thenReturn(mStayOnNetworkMinimumRxRate + 1.0);
-
-        testStayOrTryToSwitch(
-                mThresholdQualifiedRssi5G + 1 /* rssi before connected */,
-                true /* a 5G network */,
-                true /* open network */,
-                // Should not try to switch.
-                false);
-    }
-
-    /**
      * This is a meta-test that given two scan results of various types, will
      * determine whether or not network selection should be performed.
      *
@@ -1129,6 +897,7 @@
      */
     private void testStayOrTryToSwitch(
             int rssiNetwork1, boolean is5GHzNetwork1, boolean isOpenNetwork1,
+            boolean isFirstNetworkOsu,
             int rssiNetwork2, boolean is5GHzNetwork2, boolean isOpenNetwork2,
             boolean shouldSelect) {
         String[] ssids = {"\"test1\"", "\"test2\""};
@@ -1139,14 +908,15 @@
         int[] levels = {rssiNetwork1, rssiNetwork2};
         int[] securities = {isOpenNetwork1 ? SECURITY_NONE : SECURITY_PSK,
                             isOpenNetwork2 ? SECURITY_NONE : SECURITY_PSK};
-        testStayOrTryToSwitchImpl(ssids, bssids, freqs, caps, levels, securities, shouldSelect);
+        testStayOrTryToSwitchImpl(ssids, bssids, freqs, caps, levels, securities, isFirstNetworkOsu,
+                shouldSelect);
     }
 
     /**
      * This is a meta-test that given one scan results, will
      * determine whether or not network selection should be performed.
      *
-     * It sets up two networks, connects to the first, and then ensures that
+     * It sets up one network, connects to it, and then ensures that it is in
      * the scan results for the NetworkSelector.
      */
     private void testStayOrTryToSwitch(
@@ -1158,11 +928,12 @@
         String[] caps = {isOpenNetwork ? "[ESS]" : "[WPA2-PSK][ESS]"};
         int[] levels = {rssi};
         int[] securities = {isOpenNetwork ? SECURITY_NONE : SECURITY_PSK};
-        testStayOrTryToSwitchImpl(ssids, bssids, freqs, caps, levels, securities, shouldSelect);
+        testStayOrTryToSwitchImpl(ssids, bssids, freqs, caps, levels, securities, false,
+                shouldSelect);
     }
 
     private void testStayOrTryToSwitchImpl(String[] ssids, String[] bssids, int[] freqs,
-            String[] caps, int[] levels, int[] securities,
+            String[] caps, int[] levels, int[] securities, boolean isFirstNetworkOsu,
             boolean shouldSelect) {
         // Make a network selection to connect to test1.
         ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
@@ -1184,6 +955,13 @@
         when(mWifiInfo.is24GHz()).thenReturn(!ScanResult.is5GHz(freqs[0]));
         when(mWifiInfo.is5GHz()).thenReturn(ScanResult.is5GHz(freqs[0]));
         when(mWifiInfo.getFrequency()).thenReturn(freqs[0]);
+        if (isFirstNetworkOsu) {
+            WifiConfiguration[] configs = scanDetailsAndConfigs.getWifiConfigs();
+            // Force 1st network to OSU
+            configs[0].osu = true;
+            when(mWifiConfigManager.getConfiguredNetwork(mWifiInfo.getNetworkId()))
+                    .thenReturn(configs[0]);
+        }
 
         when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime()
                 + WifiNetworkSelector.MINIMUM_NETWORK_SELECTION_INTERVAL_MS + 2000);
@@ -1192,7 +970,7 @@
                 true, false, false);
 
         // DummyNetworkEvaluator always return the first network in the scan results
-        // for connection, so if nework selection is performed, the first network should
+        // for connection, so if network selection is performed, the first network should
         // be returned as candidate.
         if (shouldSelect) {
             assertNotNull("Result should be not null", candidate);
@@ -1423,7 +1201,7 @@
      */
     @Test
     public void testCandidateScorerMetrics_onlyOneScorer() {
-        test2GhzHighQuality5GhzAvailable();
+        testNoActiveStream();
 
         verify(mWifiMetrics, never()).logNetworkSelectionDecision(
                 anyInt(), anyInt(), anyBoolean(), anyInt());
@@ -1472,11 +1250,11 @@
         mScoringParams.update("expid=" + compatibilityExpId);
         assertEquals(compatibilityExpId, mScoringParams.getExperimentIdentifier());
 
-        test2GhzHighQuality5GhzAvailable();
+        testNoActiveStream();
 
         int nullScorerId = experimentIdFromIdentifier(NULL_SCORER.getIdentifier());
 
-        // Wanted 2 times since test2GhzHighQuality5GhzAvailable() calls
+        // Wanted 2 times since testNoActiveStream() calls
         // WifiNetworkSelector.selectNetwork() twice
         verify(mWifiMetrics, times(2)).logNetworkSelectionDecision(nullScorerId,
                 compatibilityExpId, false, 2);
@@ -1502,12 +1280,12 @@
         mWifiNetworkSelector.registerNetworkNominator(
                 new DummyNetworkNominator(1, DUMMY_EVALUATOR_ID_2));
 
-        test2GhzHighQuality5GhzAvailable();
+        testNoActiveStream();
 
         int throughputExpId = experimentIdFromIdentifier(mThroughputScorer.getIdentifier());
         int compatibilityExpId = experimentIdFromIdentifier(mCompatibilityScorer.getIdentifier());
 
-        // Wanted 2 times since test2GhzHighQuality5GhzAvailable() calls
+        // Wanted 2 times since testNoActiveStream() calls
         // WifiNetworkSelector.selectNetwork() twice
         if (WifiNetworkSelector.PRESET_CANDIDATE_SCORER_NAME.equals(
                 mThroughputScorer.getIdentifier())) {
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
index caa0d66..c2e1d0b 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
@@ -120,6 +120,9 @@
         when(resources.getInteger(
                 R.integer.config_wifiFrameworkScoreGoodRssiThreshold6ghz))
             .thenReturn(-57);
+        when(resources.getInteger(
+                R.integer.config_wifiFrameworkMinPacketPerSecondHighTraffic))
+                .thenReturn(100);
     }
 
     /**