Skip network selection score sufficiency check on secondary

The AOSP score for secondary LONG_LIVED STA is always set to be lower
so that it does not become the default network. This is however
triggering unneccesary network selection attempts. Ignore the AOSP score
when checking secondary sufficiency.

Bug: 261663526
Test: atest com.android.server.wifi

Change-Id: I8dbb8a5104967935bc2506ad4b2e209502835522
diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java
index 36cae2e..068c642 100644
--- a/service/java/com/android/server/wifi/WifiNetworkSelector.java
+++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java
@@ -308,10 +308,18 @@
 
         // External scorer is not being used, and the current network's score is below the
         // sufficient score threshold configured for the AOSP scorer.
-        if (!mWifiGlobals.isUsingExternalScorer()
-                && wifiInfo.getScore()
+        if (!mWifiGlobals.isUsingExternalScorer() && wifiInfo.getScore()
                 < mWifiGlobals.getWifiLowConnectedScoreThresholdToTriggerScanForMbb()) {
-            return false;
+            if (!SdkLevel.isAtLeastS()) {
+                // Return false to prevent build issues since WifiInfo#isPrimary is only supported
+                // on S and above.
+                return false;
+            }
+            // Only return false to trigger network selection on the primary, since the secondary
+            // STA is not scored.
+            if (wifiInfo.isPrimary()) {
+                return false;
+            }
         }
 
         // OEM paid/private networks are only available to system apps, so this is never sufficient.
diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java
index 4626de8..2392b81 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java
@@ -435,6 +435,10 @@
         when(mWifiConfigManager.getConfiguredNetwork(anyInt()))
                 .thenReturn(testConfig);
         when(mWifiInfo.getScore()).thenReturn(ConnectedScore.WIFI_TRANSITION_SCORE);
+        if (SdkLevel.isAtLeastS()) {
+            when(mWifiInfo.isPrimary()).thenReturn(true);
+        }
+        when(mActiveModeWarden.canRequestSecondaryTransientClientModeManager()).thenReturn(true);
 
         // verify the current network is sufficient
         assertTrue(mWifiNetworkSelector.isNetworkSufficient(mWifiInfo));
@@ -444,10 +448,17 @@
         when(mWifiInfo.getScore()).thenReturn(ConnectedScore.WIFI_TRANSITION_SCORE - 1);
         assertFalse(mWifiNetworkSelector.isNetworkSufficient(mWifiInfo));
 
-        // verify that when the external scorer is used, aosp score no longer affect network
-        // selection.
-        when(mWifiGlobals.isUsingExternalScorer()).thenReturn(true);
-        assertTrue(mWifiNetworkSelector.isNetworkSufficient(mWifiInfo));
+        if (SdkLevel.isAtLeastS()) {
+            // verify the aosp scorer does not affect selection on secondary
+            when(mWifiInfo.isPrimary()).thenReturn(false);
+            assertTrue(mWifiNetworkSelector.isNetworkSufficient(mWifiInfo));
+
+            // verify that when the external scorer is used, aosp score no longer affect network
+            // selection.
+            when(mWifiInfo.isPrimary()).thenReturn(true);
+            when(mWifiGlobals.isUsingExternalScorer()).thenReturn(true);
+            assertTrue(mWifiNetworkSelector.isNetworkSufficient(mWifiInfo));
+        }
     }
 
     /**