Merge "Import translations. DO NOT MERGE ANYWHERE" into mainline-prod
diff --git a/service/java/com/android/server/wifi/WifiScoreReport.java b/service/java/com/android/server/wifi/WifiScoreReport.java
index 5d7545c..3902933 100644
--- a/service/java/com/android/server/wifi/WifiScoreReport.java
+++ b/service/java/com/android/server/wifi/WifiScoreReport.java
@@ -61,6 +61,7 @@
     private static final int INVALID_SESSION_ID = -1;
     private static final long MIN_TIME_TO_WAIT_BEFORE_BLOCKLIST_BSSID_MILLIS = 29000;
     private static final long INVALID_WALL_CLOCK_MILLIS = -1;
+    private static final int WIFI_SCORE_TO_TERMINATE_CONNECTION_BLOCKLIST_BSSID = -2;
 
     /**
      * Copy of the settings string. Can't directly use the constant because it is @hide.
@@ -111,6 +112,21 @@
                              + " score=" + score);
                     return;
                 }
+                // Disconnect WiFi and blocklist current BSSID. This is an intermediate solution
+                // and will be removed when the extension API is extended to include more inputs
+                // tracked by b/171571687.
+                if (score == WIFI_SCORE_TO_TERMINATE_CONNECTION_BLOCKLIST_BSSID) {
+                    mBssidBlocklistMonitor.handleBssidConnectionFailure(mWifiInfo.getBSSID(),
+                            mWifiInfo.getSSID(),
+                            BssidBlocklistMonitor.REASON_FRAMEWORK_DISCONNECT_CONNECTED_SCORE,
+                            mWifiInfo.getRssi());
+                    return;
+                }
+                if (score > ConnectedScore.WIFI_MAX_SCORE
+                        || score < ConnectedScore.WIFI_MIN_SCORE) {
+                    Log.e(TAG, "Invalid score value from external scorer: " + score);
+                    return;
+                }
                 long millis = mClock.getWallClockMillis();
                 if (score < ConnectedScore.WIFI_TRANSITION_SCORE) {
                     if (mScore >= ConnectedScore.WIFI_TRANSITION_SCORE) {
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 bd15f62..e9a6f8b 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
@@ -1078,4 +1078,50 @@
         mLooper.dispatchAll();
         verify(mNetworkAgent).sendNetworkScore(51);
     }
+
+    /**
+     * Verify BSSID is added onto blocklist when the score value of -2 is sent from external Wi-Fi
+     * scorer.
+     */
+    @Test
+    public void verifyBssidBlocklistWithScoreValueOfMinus2() throws Exception {
+        WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
+        // Register Client for verification.
+        mWifiScoreReport.setWifiConnectedNetworkScorer(mAppBinder, scorerImpl);
+        when(mNetwork.getNetId()).thenReturn(TEST_NETWORK_ID);
+        mWifiScoreReport.startConnectedNetworkScorer(TEST_NETWORK_ID);
+        mClock.mStepMillis = 0;
+        mClock.mWallClockMillis = 10;
+        mWifiInfo.setRssi(-65);
+
+        scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, -2);
+        mLooper.dispatchAll();
+        verify(mBssidBlocklistMonitor).handleBssidConnectionFailure(any(), any(), anyInt(),
+                anyInt());
+    }
+
+    /**
+     * Verify BSSID is not added onto blocklist when positive score values are sent from external
+     * Wi-Fi scorer.
+     */
+    @Test
+    public void verifyNoBssidBlocklistWithPositiveScoreValues() throws Exception {
+        WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
+        // Register Client for verification.
+        mWifiScoreReport.setWifiConnectedNetworkScorer(mAppBinder, scorerImpl);
+        when(mNetwork.getNetId()).thenReturn(TEST_NETWORK_ID);
+        mWifiScoreReport.startConnectedNetworkScorer(TEST_NETWORK_ID);
+        mClock.mStepMillis = 0;
+        mClock.mWallClockMillis = 10;
+        mWifiInfo.setRssi(-65);
+
+        scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 49);
+        mLooper.dispatchAll();
+        verify(mBssidBlocklistMonitor, never()).handleBssidConnectionFailure(any(), any(), anyInt(),
+                anyInt());
+        scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 51);
+        mLooper.dispatchAll();
+        verify(mBssidBlocklistMonitor, never()).handleBssidConnectionFailure(any(), any(), anyInt(),
+                anyInt());
+    }
 }