Merge tag 'android-security-10.0.0_r53' into int/10/fp2

Android security 10.0.0 release 53

* tag 'android-security-10.0.0_r53':

Change-Id: Ic44029b8e2ccbd19126b7c5b64a0418937572567
diff --git a/Common/src/com/googlecode/android_scripting/facade/ConnectivityManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/ConnectivityManagerFacade.java
index 437ada8..ce31b61 100644
--- a/Common/src/com/googlecode/android_scripting/facade/ConnectivityManagerFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/ConnectivityManagerFacade.java
@@ -670,6 +670,15 @@
         }
     }
 
+    @Rpc(description = "register a default network callback")
+    public String connectivityRegisterDefaultNetworkCallback() {
+        mNetworkCallback = new NetworkCallback(NetworkCallback.EVENT_AVAILABLE);
+        mManager.registerDefaultNetworkCallback(mNetworkCallback);
+        String key = mNetworkCallback.mId;
+        mNetworkCallbackMap.put(key, mNetworkCallback);
+        return key;
+    }
+
     @Rpc(description = "request a network")
     public String connectivityRequestNetwork(@RpcParameter(name = "configJson")
     JSONObject configJson) throws JSONException {
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/media/BluetoothSL4AAudioSrcMBS.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/media/BluetoothSL4AAudioSrcMBS.java
index fdc7ec9..4bdca3f 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/media/BluetoothSL4AAudioSrcMBS.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/media/BluetoothSL4AAudioSrcMBS.java
@@ -168,6 +168,15 @@
                 .build();
         mMediaSession.setPlaybackState(state);
         mMediaSession.setActive(true);
+
+        // Sets the PlaybackState to STOPPED now that we are able to receive MediaSession callbacks.
+        state = new PlaybackState.Builder()
+                .setActions(PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PAUSE
+                        | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS
+                        | PlaybackState.ACTION_STOP)
+                .setState(PlaybackState.STATE_STOPPED, PlaybackState.PLAYBACK_POSITION_UNKNOWN, 1)
+                .build();
+        mMediaSession.setPlaybackState(state);
     }
 
     @Override
diff --git a/Common/src/com/googlecode/android_scripting/facade/telephony/ImsMmTelManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/telephony/ImsMmTelManagerFacade.java
new file mode 100644
index 0000000..7853e4d
--- /dev/null
+++ b/Common/src/com/googlecode/android_scripting/facade/telephony/ImsMmTelManagerFacade.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.googlecode.android_scripting.facade.telephony;
+
+import android.telephony.ims.ImsMmTelManager;
+
+import com.googlecode.android_scripting.facade.FacadeManager;
+import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
+import com.googlecode.android_scripting.rpc.Rpc;
+import com.googlecode.android_scripting.rpc.RpcParameter;
+
+/**
+ * Exposes ImsMmManager functionality
+ */
+public class ImsMmTelManagerFacade extends RpcReceiver {
+
+    /**
+     * Exposes ImsMmTelManager functionality
+     */
+    public ImsMmTelManagerFacade(FacadeManager manager) {
+        super(manager);
+    }
+
+    /**
+     * Get whether Advanced Calling is enabled for a subId
+     *
+     * @param subId The subscription ID of the sim you want to check
+     */
+    @Rpc(description = "Return True if Enhanced 4g Lte mode is enabled.")
+    public boolean imsMmTelIsAdvancedCallingEnabled(@RpcParameter(name = "subId") Integer subId) {
+        return ImsMmTelManager.createForSubscriptionId(subId).isAdvancedCallingSettingEnabled();
+    }
+
+    /**
+     * Set whether Advanced Calling is enabled for a subId
+     *
+     * @param subId The subscription ID of the sim you want to check
+     * @param isEnabled Whether the sim should have Enhanced 4g Lte on or off
+     */
+    @Rpc(description = "Set Enhanced 4g Lte mode")
+    public void imsMmTelSetAdvancedCallingEnabled(
+                        @RpcParameter(name = "subId") Integer subId,
+                        @RpcParameter(name = "isEnabled") Boolean isEnabled) {
+        ImsMmTelManager.createForSubscriptionId(subId).setAdvancedCallingSettingEnabled(isEnabled);
+    }
+
+    @Override
+    public void shutdown() {
+
+    }
+}
diff --git a/Common/src/com/googlecode/android_scripting/facade/telephony/SubscriptionManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/telephony/SubscriptionManagerFacade.java
index 90ae1f5..5e0f256 100644
--- a/Common/src/com/googlecode/android_scripting/facade/telephony/SubscriptionManagerFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/telephony/SubscriptionManagerFacade.java
@@ -66,6 +66,11 @@
         return SubscriptionManager.getDefaultVoiceSubscriptionId();
     }
 
+    @Rpc(description = "Returns active data subscription ID")
+    public Integer subscriptionGetActiveDataSubscriptionId() {
+        return SubscriptionManager.getActiveDataSubscriptionId();
+    }
+
     @Rpc(description = "Set the default voice subscription ID")
     public void subscriptionSetDefaultVoiceSubId(
             @RpcParameter(name = "subId")
diff --git a/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyManagerFacade.java
index 2631e49..90026d5 100644
--- a/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyManagerFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyManagerFacade.java
@@ -35,6 +35,7 @@
 import android.telephony.SignalStrength;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
+import android.telephony.AvailableNetworkInfo;
 
 import com.android.internal.telephony.RILConstants;
 import com.android.internal.telephony.TelephonyProperties;
@@ -67,6 +68,7 @@
 import com.googlecode.android_scripting.rpc.RpcParameter;
 
 import java.util.Arrays;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.concurrent.Executor;
@@ -82,6 +84,7 @@
     private final EventFacade mEventFacade;
     private final TelephonyManager mTelephonyManager;
     private final SubscriptionManager mSubscriptionManager;
+    private List<AvailableNetworkInfo> availableNetworkList;
     private HashMap<Integer, StateChangeListener> mStateChangeListeners =
                              new HashMap<Integer, StateChangeListener>();
 
@@ -742,6 +745,32 @@
         return mTelephonyManager.getPreferredOpportunisticDataSubscription();
     }
 
+    @Rpc(description = "Sets preferred opportunistic data subscription Id")
+    public void telephonySetPreferredOpportunisticDataSubscription(
+            @RpcParameter(name = "subId") Integer subId,
+            @RpcParameter(name = "needValidation") Boolean needValidation) {
+        mTelephonyManager.setPreferredOpportunisticDataSubscription(
+                   subId, needValidation, null, null);
+    }
+
+    @Rpc(description = "Updates Available Networks")
+    public void telephonyUpdateAvailableNetworks(
+            @RpcParameter(name = "subId") Integer subId) {
+
+        availableNetworkList = new ArrayList<>();
+        List<String> mccmmc = new ArrayList<String>();
+        List<Integer> bands = new ArrayList<Integer>();
+
+        availableNetworkList.add(
+            new AvailableNetworkInfo(
+                subId,
+                AvailableNetworkInfo.PRIORITY_HIGH,
+                mccmmc,
+                bands));
+
+        mTelephonyManager.updateAvailableNetworks(availableNetworkList, null, null);
+    }
+
     /**
     * Get device phone type for a subscription.
     * @param subId the subscriber id
diff --git a/Common/src/com/googlecode/android_scripting/facade/wifi/HttpFacade.java b/Common/src/com/googlecode/android_scripting/facade/wifi/HttpFacade.java
index 6f173b5..0d3d887 100644
--- a/Common/src/com/googlecode/android_scripting/facade/wifi/HttpFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/wifi/HttpFacade.java
@@ -96,13 +96,19 @@
      * Send an http request and get the response.
      *
      * @param url The url to send request to.
+     * @param timeout Time to load the page
      * @return The HttpURLConnection object.
      */
-    private HttpURLConnection httpRequest(String url) throws IOException {
+    private HttpURLConnection httpRequest(String url, Integer timeout) throws IOException {
+        if (timeout == null) {
+            timeout = 50000;
+        }
         URL targetURL = new URL(url);
         HttpURLConnection urlConnection;
         try {
             urlConnection = (HttpURLConnection) targetURL.openConnection();
+            urlConnection.setConnectTimeout(9000);
+            urlConnection.setReadTimeout(timeout);
             urlConnection.connect();
             int respCode = urlConnection.getResponseCode();
             String respMsg = urlConnection.getResponseMessage();
@@ -132,7 +138,7 @@
     public void httpDownloadFile(@RpcParameter(name = "url") String url,
             @RpcParameter(name="outPath") @RpcOptional String outPath) throws IOException {
         // Create the input stream
-        HttpURLConnection urlConnection = httpRequest(url);
+        HttpURLConnection urlConnection = httpRequest(url, null);
         // Parse destination path and create the output stream. The function assumes that the path
         // is specified relative to the system default Download dir.
         File outFile = FileUtils.getExternalDownload();
@@ -179,10 +185,12 @@
     }
 
     @Rpc(description = "Make an http request and return the response message.")
-    public HttpURLConnection httpPing(@RpcParameter(name = "url") String url) throws IOException {
+    public HttpURLConnection httpPing(
+            @RpcParameter(name = "url") String url,
+            @RpcParameter(name = "timeout") @RpcOptional Integer timeout) throws IOException {
         try {
             HttpURLConnection urlConnection = null;
-            urlConnection = httpRequest(url);
+            urlConnection = httpRequest(url, timeout);
             urlConnection.disconnect();
             return urlConnection;
         } catch (UnknownHostException e) {
@@ -192,7 +200,7 @@
 
     @Rpc(description = "Make an http request and return the response content as a string.")
     public String httpRequestString(@RpcParameter(name = "url") String url) throws IOException {
-        HttpURLConnection urlConnection = httpRequest(url);
+        HttpURLConnection urlConnection = httpRequest(url, null);
         InputStream in = new BufferedInputStream(urlConnection.getInputStream());
         String result = inputStreamToString(in);
         Log.d("Fetched: " + result);
diff --git a/Common/src/com/googlecode/android_scripting/facade/wifi/WifiManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/wifi/WifiManagerFacade.java
index bfe176d..0183c69 100755
--- a/Common/src/com/googlecode/android_scripting/facade/wifi/WifiManagerFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/wifi/WifiManagerFacade.java
@@ -656,7 +656,7 @@
         if (j.has("isWpa3") && j.getBoolean("isWpa3")) {
             isWpa3 = true;
         }
-        if (j.has("password")) {
+        if (j.has("password") && !j.has(WifiEnterpriseConfig.EAP_KEY)) {
             if (!isWpa3) {
                 builder = builder.setWpa2Passphrase(j.getString("password"));
             } else {
@@ -695,7 +695,7 @@
         if (j.has("isWpa3") && j.getBoolean("isWpa3")) {
             isWpa3 = true;
         }
-        if (j.has("password")) {
+        if (j.has("password") && !j.has(WifiEnterpriseConfig.EAP_KEY)) {
             if (!isWpa3) {
                 builder = builder.setWpa2Passphrase(j.getString("password"));
             } else {
diff --git a/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java b/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
index f673f5a..5ee2718 100644
--- a/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
+++ b/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
@@ -995,6 +995,7 @@
         msg.put("dataRoaming", data.getDataRoaming());
         msg.put("mcc", data.getMcc());
         msg.put("mnc", data.getMnc());
+        msg.put("carrierId", data.getCarrierId());
         return msg;
     }
 
diff --git a/ScriptingLayer/src/com/googlecode/android_scripting/facade/FacadeConfiguration.java b/ScriptingLayer/src/com/googlecode/android_scripting/facade/FacadeConfiguration.java
index 7ca7a84..4dbc711 100644
--- a/ScriptingLayer/src/com/googlecode/android_scripting/facade/FacadeConfiguration.java
+++ b/ScriptingLayer/src/com/googlecode/android_scripting/facade/FacadeConfiguration.java
@@ -48,6 +48,7 @@
 import com.googlecode.android_scripting.facade.net.nsd.NsdManagerFacade;
 import com.googlecode.android_scripting.facade.telephony.CarrierConfigFacade;
 import com.googlecode.android_scripting.facade.telephony.ImsManagerFacade;
+import com.googlecode.android_scripting.facade.telephony.ImsMmTelManagerFacade;
 import com.googlecode.android_scripting.facade.telephony.SmsFacade;
 import com.googlecode.android_scripting.facade.telephony.SubscriptionManagerFacade;
 import com.googlecode.android_scripting.facade.telephony.TelecomCallFacade;
@@ -104,6 +105,7 @@
         sFacadeClassList.add(ContactsFacade.class);
         sFacadeClassList.add(EventFacade.class);
         sFacadeClassList.add(ImsManagerFacade.class);
+        sFacadeClassList.add(ImsMmTelManagerFacade.class);
         sFacadeClassList.add(LocationFacade.class);
         sFacadeClassList.add(TelephonyManagerFacade.class);
         sFacadeClassList.add(PreferencesFacade.class);