Adding newer APIs for MmTel functionality am: 67bc630356 am: 53a7ee64bc

Change-Id: I1baf1f69412e47a458c52e94809a5d09fc0aebc4
diff --git a/Common/src/com/googlecode/android_scripting/facade/telephony/ImsMmTelManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/telephony/ImsMmTelManagerFacade.java
index 7853e4d..9ad4e38 100644
--- a/Common/src/com/googlecode/android_scripting/facade/telephony/ImsMmTelManagerFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/telephony/ImsMmTelManagerFacade.java
@@ -16,13 +16,20 @@
 
 package com.googlecode.android_scripting.facade.telephony;
 
+import android.telephony.AccessNetworkConstants;
+import android.telephony.ims.ImsException;
 import android.telephony.ims.ImsMmTelManager;
+import android.telephony.ims.feature.MmTelFeature;
 
+import com.googlecode.android_scripting.Log;
 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;
 
+import java.util.concurrent.Executor;
+import java.util.concurrent.LinkedBlockingQueue;
+
 /**
  * Exposes ImsMmManager functionality
  */
@@ -41,12 +48,13 @@
      * @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) {
+    public boolean imsMmTelIsAdvancedCallingEnabled(
+                        @RpcParameter(name = "subId") Integer subId) {
         return ImsMmTelManager.createForSubscriptionId(subId).isAdvancedCallingSettingEnabled();
     }
 
     /**
-     * Set whether Advanced Calling is enabled for a subId
+     * Set Advanced Calling 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
@@ -58,6 +66,191 @@
         ImsMmTelManager.createForSubscriptionId(subId).setAdvancedCallingSettingEnabled(isEnabled);
     }
 
+    /**
+     * Get whether VoWiFi Roaming setting is enabled for a subId
+     *
+     * @param subId The subscription ID of the sim you want to check
+     */
+    @Rpc(description = "Return True if VoWiFi Roaming is enabled.")
+    public boolean imsMmTelIsVoWiFiRoamingSettingEnabled(
+                        @RpcParameter(name = "subId") Integer subId) {
+        return ImsMmTelManager.createForSubscriptionId(subId).isVoWiFiRoamingSettingEnabled();
+    }
+
+    /**
+     * Set VoWiFi Roaming setting for a subId
+     *
+     * @param subId The subscription ID of the sim you want to check
+     * @param isEnabled Whether the sim should have VoWiFi Roaming on or off
+     */
+    @Rpc(description = "Set VoWiFi Roaming setting")
+    public void imsMmTelSetVoWiFiRoamingSettingEnabled(
+                        @RpcParameter(name = "subId") Integer subId,
+                        @RpcParameter(name = "isEnabled") Boolean isEnabled) {
+        ImsMmTelManager.createForSubscriptionId(subId).setVoWiFiRoamingSettingEnabled(isEnabled);
+    }
+
+    /**
+     * Get whether VoWiFi setting is enabled for a subId
+     *
+     * @param subId The subscription ID of the sim you want to check
+     */
+    @Rpc(description = "Return True if VoWiFi is enabled.")
+    public boolean imsMmTelIsVoWiFiSettingEnabled(@RpcParameter(name = "subId") Integer subId) {
+        return ImsMmTelManager.createForSubscriptionId(subId).isVoWiFiSettingEnabled();
+    }
+
+    /**
+     * Set VoWiFi setting for a subId
+     *
+     * @param subId The subscription ID of the sim you want to check
+     * @param isEnabled Whether the sim should have VoWiFi on or off
+     */
+    @Rpc(description = "Set VoWiFi setting")
+    public void imsMmTelSetVoWiFiSettingEnabled(
+                        @RpcParameter(name = "subId") Integer subId,
+                        @RpcParameter(name = "isEnabled") Boolean isEnabled) {
+        ImsMmTelManager.createForSubscriptionId(subId).setVoWiFiSettingEnabled(isEnabled);
+    }
+
+    /**
+     * Get whether Video Telephony setting is enabled for a subId
+     *
+     * @param subId The subscription ID of the sim you want to check
+     */
+    @Rpc(description = "Return True if VT is enabled.")
+    public boolean imsMmTelIsVtSettingEnabled(
+                        @RpcParameter(name = "subId") Integer subId) {
+        return ImsMmTelManager.createForSubscriptionId(subId).isVtSettingEnabled();
+    }
+
+    /**
+     * Set Video Telephony setting for a subId
+     *
+     * @param subId The subscription ID of the sim you want to check
+     * @param isEnabled Whether the sim should have VT on or off
+     */
+    @Rpc(description = "Set VT setting")
+    public void imsMmTelSetVtSettingEnabled(
+                        @RpcParameter(name = "subId") Integer subId,
+                        @RpcParameter(name = "isEnabled") Boolean isEnabled) {
+        ImsMmTelManager.createForSubscriptionId(subId).setVtSettingEnabled(isEnabled);
+    }
+
+    /**
+     * Get current VoWiFi Mode Pref for a subId
+     *
+     * @param subId The subscription ID of the sim you want to check
+     */
+    @Rpc(description = "Return Preferred WFC Mode if Enabled.")
+    public String imsMmTelGetVoWiFiModeSetting(
+                        @RpcParameter(name = "subId") Integer subId) {
+        return TelephonyUtils.getWfcModeString(
+            ImsMmTelManager.createForSubscriptionId(subId).getVoWiFiModeSetting());
+    }
+
+    /**
+     * Set VoWiFi Mode Pref for a subId
+     *
+     * @param subId The subscription ID of the sim you want to check
+     * @mode mode pref can be one of the following
+     * - WIFI_ONLY
+     * - WIFI_PREFERRED
+     * - CELLULAR_PREFERRED
+     */
+    @Rpc(description = "Set the Preferred WFC Mode")
+    public void imsMmTelSetVoWiFiModeSetting(
+                        @RpcParameter(name = "subId") Integer subId,
+                        @RpcParameter(name = "mode") String mode)
+            throws IllegalArgumentException {
+
+        int mode_val;
+
+        switch (mode.toUpperCase()) {
+            case TelephonyConstants.WFC_MODE_WIFI_ONLY:
+                mode_val = ImsMmTelManager.WIFI_MODE_WIFI_ONLY;
+                break;
+            case TelephonyConstants.WFC_MODE_CELLULAR_PREFERRED:
+                mode_val = ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED;
+                break;
+            case TelephonyConstants.WFC_MODE_WIFI_PREFERRED:
+                mode_val = ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED;
+                break;
+            default:
+                throw new IllegalArgumentException("Invalid WfcMode");
+        }
+
+        ImsMmTelManager.createForSubscriptionId(subId).setVoWiFiModeSetting(mode_val);
+        return;
+    }
+
+    /**
+     * Check MmTel capability is supported by the carrier
+     *
+     * @param subId The subscription ID of the sim you want to check
+     * @param capability includes voice, video, sms
+     * @param transportType includes wlan, wwan
+     */
+    @Rpc(description = "Return Preferred WFC Mode if Enabled.")
+    public Boolean imsMmTelIsSupported(
+                        @RpcParameter(name = "subId") Integer subId,
+                        @RpcParameter(name = "capability") String capability,
+                        @RpcParameter(name = "transportType") String transportType)
+            throws IllegalArgumentException {
+
+        int capability_val;
+        int transport_val;
+
+        LinkedBlockingQueue<Boolean> resultQueue = new LinkedBlockingQueue<>(1);
+
+        Executor executor = new Executor() {
+            public void execute(Runnable r) {
+                Log.d("Running MmTel Executor");
+                r.run();
+                }
+            };
+
+        switch (capability.toUpperCase()) {
+            case TelephonyConstants.CAPABILITY_TYPE_VOICE:
+                capability_val = MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE;
+                break;
+            case TelephonyConstants.CAPABILITY_TYPE_VIDEO:
+                capability_val = MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO;
+                break;
+            case TelephonyConstants.CAPABILITY_TYPE_UT:
+                capability_val = MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT;
+                break;
+            case TelephonyConstants.CAPABILITY_TYPE_SMS:
+                capability_val = MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_SMS;
+                break;
+            default:
+                throw new IllegalArgumentException("Invalid Capability");
+        }
+
+        switch (transportType.toUpperCase()) {
+            case TelephonyConstants.TRANSPORT_TYPE_INVALID:
+                transport_val = AccessNetworkConstants.TRANSPORT_TYPE_INVALID;
+                break;
+            case TelephonyConstants.TRANSPORT_TYPE_WWAN:
+                transport_val = AccessNetworkConstants.TRANSPORT_TYPE_WWAN;
+                break;
+            case TelephonyConstants.TRANSPORT_TYPE_WLAN:
+                transport_val = AccessNetworkConstants.TRANSPORT_TYPE_WLAN;
+                break;
+            default:
+                throw new IllegalArgumentException("Invalid transportType");
+        }
+
+        try {
+            ImsMmTelManager.createForSubscriptionId(subId)
+                .isSupported(capability_val, transport_val, executor, resultQueue::offer);
+        } catch (ImsException e) {
+            Log.d("ImsException " + e);
+            return false;
+        }
+        return true;
+    }
+
     @Override
     public void shutdown() {
 
diff --git a/Common/src/com/googlecode/android_scripting/facade/telephony/ProvisioningManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/telephony/ProvisioningManagerFacade.java
new file mode 100644
index 0000000..069f71b
--- /dev/null
+++ b/Common/src/com/googlecode/android_scripting/facade/telephony/ProvisioningManagerFacade.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2020 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.ProvisioningManager;
+import android.telephony.ims.feature.MmTelFeature;
+import android.telephony.ims.stub.ImsRegistrationImplBase;
+
+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 ProvisioningManager functionality
+ */
+public class ProvisioningManagerFacade extends RpcReceiver {
+
+    public ProvisioningManagerFacade(FacadeManager manager) {
+        super(manager);
+    }
+
+    /**
+     * Get whether VoLTE, WFC, VT is provisioned on device
+     *
+     * @param subId The subscription ID of the sim you want to check
+     * @param capability includes voice, video, sms
+     * @param tech includes lte, iwlan
+     */
+    @Rpc(description = "Return True if Capability is provisioned on device.")
+    public boolean provisioningGetProvisioningStatusForCapability(
+                @RpcParameter(name = "subId") Integer subId,
+                @RpcParameter(name = "capability") String capability,
+                @RpcParameter(name = "tech") String tech)
+            throws IllegalArgumentException {
+
+        int capability_val;
+        int tech_val;
+
+        switch (capability.toUpperCase()) {
+            case TelephonyConstants.CAPABILITY_TYPE_VOICE:
+                capability_val = MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE;
+                break;
+            case TelephonyConstants.CAPABILITY_TYPE_VIDEO:
+                capability_val = MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO;
+                break;
+            case TelephonyConstants.CAPABILITY_TYPE_UT:
+                capability_val = MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT;
+                break;
+            case TelephonyConstants.CAPABILITY_TYPE_SMS:
+                capability_val = MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_SMS;
+                break;
+            default:
+                throw new IllegalArgumentException("Invalid CapabilityType");
+        }
+
+        switch (tech.toUpperCase()) {
+            case TelephonyConstants.REGISTRATION_TECH_LTE:
+                tech_val = ImsRegistrationImplBase.REGISTRATION_TECH_LTE;
+                break;
+            case TelephonyConstants.REGISTRATION_TECH_IWLAN:
+                tech_val = ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN;
+                break;
+            case TelephonyConstants.REGISTRATION_TECH_NONE:
+                tech_val = ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
+                break;
+            default:
+                throw new IllegalArgumentException("Invalid TechType");
+        }
+
+        return ProvisioningManager.createForSubscriptionId(subId)
+            .getProvisioningStatusForCapability(capability_val, tech_val);
+    }
+
+    /**
+     * Sets provisioned value for VoLTE, WFC, VT on device
+     *
+     * @param subId The subscription ID of the sim you want to set
+     * @param key includes volte, vt
+     * @param value includes enable, disable
+     */
+    @Rpc(description = "Returns CapabilityValue after setting on device.")
+    public int provisioningSetProvisioningIntValue(
+                @RpcParameter(name = "subId") Integer subId,
+                @RpcParameter(name = "key") String key,
+                @RpcParameter(name = "value") String value)
+            throws IllegalArgumentException {
+
+        int capability_key;
+        int capability_val;
+
+        switch (key.toUpperCase()) {
+            case TelephonyConstants.KEY_VOLTE_PROVISIONING_STATUS:
+                capability_key = ProvisioningManager.KEY_VOLTE_PROVISIONING_STATUS;
+                break;
+            case TelephonyConstants.KEY_VT_PROVISIONING_STATUS:
+                capability_key = ProvisioningManager.KEY_VT_PROVISIONING_STATUS;
+                break;
+            default:
+                throw new IllegalArgumentException("Invalid Key");
+        }
+
+        switch (value.toUpperCase()) {
+            case TelephonyConstants.PROVISIONING_VALUE_ENABLED:
+                capability_val = ProvisioningManager.PROVISIONING_VALUE_ENABLED;
+                break;
+            case TelephonyConstants.PROVISIONING_VALUE_DISABLED:
+                capability_val = ProvisioningManager.PROVISIONING_VALUE_DISABLED;
+                break;
+            default:
+                throw new IllegalArgumentException("Invalid Value");
+        }
+
+        return ProvisioningManager.createForSubscriptionId(subId)
+                    .setProvisioningIntValue(capability_key, capability_val);
+    }
+
+    @Override
+    public void shutdown() {
+
+    }
+}
diff --git a/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyConstants.java b/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyConstants.java
index 9cd6aaa..ecbec0d 100644
--- a/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyConstants.java
+++ b/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyConstants.java
@@ -120,6 +120,29 @@
     public static final String CALL_CAPABILITY_UNKOWN = "UNKOWN";
 
     /**
+     * Constant for MmTel Capability
+     * **/
+    public static final String CAPABILITY_TYPE_VOICE = "VOICE";
+    public static final String CAPABILITY_TYPE_VIDEO = "VIDEO";
+    public static final String CAPABILITY_TYPE_UT = "UT";
+    public static final String CAPABILITY_TYPE_SMS = "SMS";
+
+    /**
+     * Constant for ProvisioningManager Key and Values
+     * **/
+    public static final String KEY_VOLTE_PROVISIONING_STATUS = "VOICE";
+    public static final String KEY_VT_PROVISIONING_STATUS = "VIDEO";
+    public static final String PROVISIONING_VALUE_ENABLED = "ENABLE";
+    public static final String PROVISIONING_VALUE_DISABLED = "DISABLE";
+
+    /**
+     * Constant for AccessNetwork Transport Type
+     * **/
+    public static final String TRANSPORT_TYPE_INVALID = "INVALID";
+    public static final String TRANSPORT_TYPE_WWAN = "WWAN";
+    public static final String TRANSPORT_TYPE_WLAN = "WLAN";
+
+    /**
      * Constant for Call Property
      * **/
     public static final String CALL_PROPERTY_HIGH_DEF_AUDIO = "HIGH_DEF_AUDIO";
@@ -168,6 +191,13 @@
     public static final String RAT_UNKNOWN = "UNKNOWN";
 
     /**
+     * Constant for Ims Registration RAT
+     * **/
+    public static final String REGISTRATION_TECH_NONE = "NONE";
+    public static final String REGISTRATION_TECH_LTE = "LTE";
+    public static final String REGISTRATION_TECH_IWLAN = "IWLAN";
+
+    /**
      * Constant for Phone Type
      * **/
     public static final String PHONE_TYPE_GSM = "GSM";
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 90026d5..8f1db85 100644
--- a/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyManagerFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyManagerFacade.java
@@ -136,6 +136,19 @@
         mTelephonyManager.factoryReset(subId);
     }
 
+    /**
+    * Reset TelephonyManager settings to factory default.
+    * @param subId the subriber id to be reset, use default id if not provided.
+    */
+    @Rpc(description = "Resets Telephony and IMS settings to factory default.")
+    public void telephonyResetSettings(
+            @RpcOptional @RpcParameter(name = "subId") Integer subId) {
+        if (subId == null) {
+            subId = SubscriptionManager.getDefaultVoiceSubscriptionId();
+        }
+        mTelephonyManager.createForSubscriptionId(subId).resetSettings();
+    }
+
     @Rpc(description = "Set network preference.")
     public boolean telephonySetPreferredNetworkTypes(
         @RpcParameter(name = "nwPreference") String nwPreference) {
diff --git a/ScriptingLayer/src/com/googlecode/android_scripting/facade/FacadeConfiguration.java b/ScriptingLayer/src/com/googlecode/android_scripting/facade/FacadeConfiguration.java
index a8a2487..ba18919 100644
--- a/ScriptingLayer/src/com/googlecode/android_scripting/facade/FacadeConfiguration.java
+++ b/ScriptingLayer/src/com/googlecode/android_scripting/facade/FacadeConfiguration.java
@@ -50,6 +50,7 @@
 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.ProvisioningManagerFacade;
 import com.googlecode.android_scripting.facade.telephony.SmsFacade;
 import com.googlecode.android_scripting.facade.telephony.SubscriptionManagerFacade;
 import com.googlecode.android_scripting.facade.telephony.TelecomCallFacade;
@@ -109,6 +110,7 @@
         sFacadeClassList.add(ImsMmTelManagerFacade.class);
         sFacadeClassList.add(LocationFacade.class);
         sFacadeClassList.add(TelephonyManagerFacade.class);
+        sFacadeClassList.add(ProvisioningManagerFacade.class);
         sFacadeClassList.add(PreferencesFacade.class);
         sFacadeClassList.add(MediaPlayerFacade.class);
         sFacadeClassList.add(MediaRecorderFacade.class);