Snap for 7132927 from e9af524b6a6bc0af23ac834738a309be979442ac to mainline-conscrypt-release

Change-Id: I1401dcfd4052fd010c29db86c3cf86ef11817b5f
diff --git a/apex/Android.bp b/apex/Android.bp
index 8a2f834..819734a 100644
--- a/apex/Android.bp
+++ b/apex/Android.bp
@@ -34,6 +34,7 @@
         "ServiceWifiResources",
     ],
     min_sdk_version: "30",
+    updatable: true,
 }
 
 filegroup {
diff --git a/service/ServiceWifiResources/res/values-mn/strings.xml b/service/ServiceWifiResources/res/values-mn/strings.xml
index ef7e116..c168472 100644
--- a/service/ServiceWifiResources/res/values-mn/strings.xml
+++ b/service/ServiceWifiResources/res/values-mn/strings.xml
@@ -36,7 +36,7 @@
     <string name="wifi_suggestion_action_allow_imsi_privacy_exemption_carrier" msgid="3888538126440442636">"Холбогдох"</string>
     <string name="wifi_suggestion_action_disallow_imsi_privacy_exemption_carrier" msgid="3225397664735676024">"Битгий холбогд"</string>
     <string name="wifi_suggestion_imsi_privacy_exemption_confirmation_title" msgid="4407415300707014525">"Холболтыг баталгаажуулах уу?"</string>
-    <string name="wifi_suggestion_imsi_privacy_exemption_confirmation_content" msgid="9211241189147807136">"Хэрэв та холбогдвол <xliff:g id="CARRIERNAME">%s</xliff:g>-н Wi‑Fi сүлжээ нь таны СИМ-тэй холбоотой цор ганц дугаарт хандаж эсвэл түүнийг хуваалцаж болзошгүй. Энэ нь таны төхөөрөмжийн байршлыг тандахыг зөвшөөрч болзошгүй."</string>
+    <string name="wifi_suggestion_imsi_privacy_exemption_confirmation_content" msgid="9211241189147807136">"Хэрэв та холбогдвол <xliff:g id="CARRIERNAME">%s</xliff:g>-н Wi‑Fi сүлжээ нь таны SIM-тэй холбоотой цор ганц дугаарт хандаж эсвэл түүнийг хуваалцаж болзошгүй. Энэ нь таны төхөөрөмжийн байршлыг тандахыг зөвшөөрч болзошгүй."</string>
     <string name="wifi_suggestion_action_allow_imsi_privacy_exemption_confirmation" msgid="2168947026413431603">"Холбогдох"</string>
     <string name="wifi_suggestion_action_disallow_imsi_privacy_exemption_confirmation" msgid="5156881939985876066">"Битгий холбогд"</string>
     <string name="wifi_wakeup_onboarding_title" msgid="3868826648004934540">"Wi‑Fi автоматаар асна"</string>
@@ -80,5 +80,5 @@
     <string name="wifi_softap_auto_shutdown_timeout_expired_title" msgid="4896534374569504484">"Сүлжээний цэгийг унтраасан"</string>
     <string name="wifi_softap_auto_shutdown_timeout_expired_summary" msgid="7975476698140267728">"Ямар ч төхөөрөмж холбогдоогүй байна. Өөрчлөхийн тулд товшино уу."</string>
     <string name="wifi_sim_required_title" msgid="2262227800991155459">"Wifi-г салгалаа"</string>
-    <string name="wifi_sim_required_message" msgid="284812212346125745">"<xliff:g id="SSID">%1$s</xliff:g>-д холбогдохын тулд <xliff:g id="CARRIER_NAME">%2$s</xliff:g> СИМ-г хийнэ үү"</string>
+    <string name="wifi_sim_required_message" msgid="284812212346125745">"<xliff:g id="SSID">%1$s</xliff:g>-д холбогдохын тулд <xliff:g id="CARRIER_NAME">%2$s</xliff:g> SIM-г хийнэ үү"</string>
 </resources>
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/proto/Android.bp b/service/proto/Android.bp
index cb061d3..84ddfdc 100644
--- a/service/proto/Android.bp
+++ b/service/proto/Android.bp
@@ -18,6 +18,7 @@
         type: "lite",
     },
     sdk_version: "system_current",
+    min_sdk_version: "30",
     srcs: ["src/scorecard.proto"],
 }
 
@@ -32,6 +33,7 @@
         ":system-messages-proto-src",
     ],
     sdk_version: "system_current",
+    min_sdk_version: "30",
     // Pin java_version until jarjar is certified to support later versions. http://b/72703434
     java_version: "1.8",
     target: {
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());
+    }
 }