Revert "Revert "Extention API: Change Wifi score reporting behaviors bas...""

This reverts commit 44d6353d4f36a4c7c1848d721e03d568ad158fcf.

Reason for revert: Fix is going in with ag/14627135 which needs to be submitted with this original change

Bug: 171571687

Test: atest com.android.server.wifi

Change-Id: I2e7d36c71d66393582b2cc8587870fe762b662b3
diff --git a/service/java/com/android/server/wifi/WifiScoreReport.java b/service/java/com/android/server/wifi/WifiScoreReport.java
index 3356183..37623cf 100644
--- a/service/java/com/android/server/wifi/WifiScoreReport.java
+++ b/service/java/com/android/server/wifi/WifiScoreReport.java
@@ -129,8 +129,11 @@
                 return;
             }
             long millis = mClock.getWallClockMillis();
-            // TODO(b/171571687): Check the Sdk level and score is used for metric collection only
-            // in S.
+            if (SdkLevel.isAtLeastS()) {
+                mLegacyIntScore = score;
+                updateWifiMetrics(millis, -1);
+                return;
+            }
             if (score < ConnectedScore.WIFI_TRANSITION_SCORE) {
                 if (mLegacyIntScore >= ConnectedScore.WIFI_TRANSITION_SCORE) {
                     mLastScoreBreachLowTimeMillis = millis;
@@ -220,6 +223,9 @@
             if (mNetworkAgent == null) {
                 return;
             }
+            if (mShouldReduceNetworkScore) {
+                return;
+            }
             int score = isUsable ? ConnectedScore.WIFI_TRANSITION_SCORE + 1 :
                     ConnectedScore.WIFI_TRANSITION_SCORE - 1;
             // Stay a notch above the transition score if adaptive connectivity is disabled.
@@ -675,9 +681,8 @@
         if (deltaMillis < NUD_THROTTLE_MILLIS) {
             return false;
         }
-        if (SdkLevel.isAtLeastS() && mWifiConnectedNetworkScorerHolder != null
-                && mWifiConnectedNetworkScorerHolder.getShouldCheckIpLayerOnce()) {
-            return true;
+        if (SdkLevel.isAtLeastS() && mWifiConnectedNetworkScorerHolder != null) {
+            return mWifiConnectedNetworkScorerHolder.getShouldCheckIpLayerOnce();
         }
         int nud = mScoringParams.getNudKnob();
         if (nud == 0) {
diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
index a78a63b..98c1398 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
@@ -20,6 +20,7 @@
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeFalse;
 import static org.junit.Assume.assumeTrue;
 import static org.mockito.AdditionalAnswers.answerVoid;
 import static org.mockito.ArgumentMatchers.anyString;
@@ -414,10 +415,16 @@
         verify(mWifiConnectedNetworkScorer).onStop(TEST_SESSION_ID);
 
         // send score after session has ended
-        mExternalScoreUpdateObserverCbCaptor.getValue().notifyScoreUpdate(TEST_SESSION_ID, 49);
+        mExternalScoreUpdateObserverCbCaptor.getValue().notifyStatusUpdate(TEST_SESSION_ID, false);
         mLooper.dispatchAll();
         // score not sent since session ended
-        verify(mNetworkAgent).sendNetworkScore(any());
+        verify(mNetworkAgent, never()).sendNetworkScore(argThat(
+                new ArgumentMatcher<NetworkScore>() {
+                    @Override
+                    public boolean matches(NetworkScore ns) {
+                        return ns.getLegacyInt() == 49 && ns.isExiting() && ns.isTransportPrimary();
+                    }
+                }));
     }
 
     /**
@@ -913,6 +920,7 @@
      */
     @Test
     public void testFrameworkGetsUpdatesScore() throws Exception {
+        assumeFalse(SdkLevel.isAtLeastS());
         // initially called once
         verifySentNetworkScore(60);
         WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
@@ -1000,6 +1008,7 @@
      */
     @Test
     public void askForNudCheckWhenExternalScoreBreaches() throws Exception {
+        assumeFalse(SdkLevel.isAtLeastS());
         WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
         // Register Client for verification.
         mWifiScoreReport.setWifiConnectedNetworkScorer(mAppBinder, scorerImpl);
@@ -1064,6 +1073,7 @@
      */
     @Test
     public void bssidBlockListHappensWhenExitingIsLongerThanMinDuration() throws Exception {
+        assumeFalse(SdkLevel.isAtLeastS());
         WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
         // Register Client for verification.
         mWifiScoreReport.setWifiConnectedNetworkScorer(mAppBinder, scorerImpl);
@@ -1135,6 +1145,7 @@
      */
     @Test
     public void confirmationDurationIsNotAddedWhenItIsNotEnabledInConfigOverlay() throws Exception {
+        assumeFalse(SdkLevel.isAtLeastS());
         verifySentAnyNetworkScore();
         WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
         // Register Client for verification.
@@ -1154,10 +1165,11 @@
     }
 
     /**
-     * Verify confirmation duration is not added when there is no score breacht
+     * Verify confirmation duration is not added when there is no score breach
      */
     @Test
     public void confirmationDurationIsNotAddedWhenThereIsNoScoreBreach() throws Exception {
+        assumeFalse(SdkLevel.isAtLeastS());
         // initially sent score = 60
         verifySentNetworkScore(60);
         WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
@@ -1196,6 +1208,7 @@
      */
     @Test
     public void confirmationDurationAndRssiCheckIsAddedForSendingLowScore() throws Exception {
+        assumeFalse(SdkLevel.isAtLeastS());
         // initially called once
         verifySentAnyNetworkScore();
         WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
@@ -1243,6 +1256,7 @@
      */
     @Test
     public void confirmationDurationIsNotAddedForSendingHighScore() throws Exception {
+        assumeFalse(SdkLevel.isAtLeastS());
         // initially called once
         verifySentAnyNetworkScore();
         WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
@@ -1281,6 +1295,7 @@
      */
     @Test
     public void confirmationDurationIsAddedForSendingHighScore() throws Exception {
+        assumeFalse(SdkLevel.isAtLeastS());
         // initially called once
         verifySentAnyNetworkScore();
         WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
@@ -1379,6 +1394,7 @@
      */
     @Test
     public void verifyNudCheckAndScoreIfToggleOffForExternalScorer() throws Exception {
+        assumeFalse(SdkLevel.isAtLeastS());
         // initially called once
         verifySentAnyNetworkScore();
         WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
@@ -1424,6 +1440,7 @@
      */
     @Test
     public void verifyNudCheckAndScoreIfScoringDisabledForExternalScorer() throws Exception {
+        assumeFalse(SdkLevel.isAtLeastS());
         WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
         // Register Client for verification.
         mWifiScoreReport.setWifiConnectedNetworkScorer(mAppBinder, scorerImpl);