IMS: Add APIs to support RTT UI

- Added APIs to set/get RTT call type
- Added APIs to set/get RTT operating
  mode
- Added APIs to query if RTT merge is
  supported

Change-Id: Id8cb2d47467627cd686a8fdf8cdbd739bcff4b78
CRs-Fixed: 2828959
diff --git a/ims/ims-ext-common/src/org/codeaurora/ims/QtiCallConstants.java b/ims/ims-ext-common/src/org/codeaurora/ims/QtiCallConstants.java
index 80e119a..07bcbbb 100644
--- a/ims/ims-ext-common/src/org/codeaurora/ims/QtiCallConstants.java
+++ b/ims/ims-ext-common/src/org/codeaurora/ims/QtiCallConstants.java
@@ -1,4 +1,4 @@
-/* Copyright (c) 2015, 2019-2020 The Linux Foundation. All rights reserved.
+/* Copyright (c) 2015, 2019-2021 The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -255,9 +255,16 @@
      * For TMO - 0 : Upon Request Mode (Disabled)
      *           1 : Automatic Mode (Full)
      * For Vzw - 1 : Automatic Mode (Full)
-     *
      */
-    public static final String PROPERTY_RTT_OPERATING_MODE = "persist.vendor.radio.rtt.operval";
+    public static final String QTI_IMS_RTT_OPERATING_MODE = "qti.settings.rtt_operation";
+
+    /**
+     * Whether dialing normal call is ON or OFF
+     * The value 1 - enable (Voice call), 0 - disable (RTT call)
+     * This is set through ImsSettings UI
+     */
+    public static final String QTI_IMS_CAN_START_RTT_CALL =
+            "qti.settings.can_start_rtt_call";
 
     // RTT default phone id
     public static final int RTT_DEFAULT_PHONE_ID = 0;
@@ -274,39 +281,18 @@
     // RTT Visibility On
     public static final int RTT_VISIBILITY_ENABLED = 1;
 
-   /**
-     * Broadcast Action: Send RTT Text Message
-     */
-    public static final String ACTION_SEND_RTT_TEXT =
-            "org.codeaurora.intent.action.send.rtt.text";
+    // RTT Call Type Off
+    public static final int RTT_CALL_TYPE_RTT = 0;
 
-   /**
-     * RTT Text Value
-     */
-    public static final String RTT_TEXT_VALUE =
-            "org.codeaurora.intent.action.rtt.textvalue";
+    // RTT Call Type On
+    public static final int RTT_CALL_TYPE_VOICE = 1;
 
-   /**
-     * Broadcast Action: RTT Operation
-     */
-    public static final String ACTION_RTT_OPERATION =
-            "org.codeaurora.intent.action.send.rtt.operation";
-
-   /**
-     * RTT Operation Type
-     */
-    public static final String RTT_OPERATION_TYPE =
-            "org.codeaurora.intent.action.rtt.operation.type";
-
-    // RTT Operation Type can be one of the following
-    // To request upgrade of regular call to RTT call
-    public static final int RTT_UPGRADE_INITIATE = 1;
-    // To accept incoming RTT upgrade request
-    public static final int RTT_UPGRADE_CONFIRM = 2;
-    // To reject incoming RTT upgrade request
-    public static final int RTT_UPGRADE_REJECT = 3;
-    // To request downgrade of RTT call to regular call
-    public static final int RTT_DOWNGRADE_INITIATE = 4;
+    // RTT Operating mode
+    // Dials normal voice call by default and provides an option
+    // to upgrade call to RTT in InCallUi.
+    public static final int RTT_UPON_REQUEST_MODE = 0;
+    // All the calls dialed are RTT calls by default.
+    public static final int RTT_AUTOMATIC_MODE = 1;
 
     // Recorder Auto-Scaling Factor
     public static final int RECORDER_SCALING_FACTOR = 8;
diff --git a/ims/ims-ext-common/src/org/codeaurora/ims/utils/QtiImsExtUtils.java b/ims/ims-ext-common/src/org/codeaurora/ims/utils/QtiImsExtUtils.java
index 706d73a..b91df68 100644
--- a/ims/ims-ext-common/src/org/codeaurora/ims/utils/QtiImsExtUtils.java
+++ b/ims/ims-ext-common/src/org/codeaurora/ims/utils/QtiImsExtUtils.java
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2015-2017, 2020 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2015-2017, 2020-2021 The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -119,7 +119,6 @@
     //Value representing volte preference is NOT known
     public static final int QTI_IMS_VOLTE_PREF_UNKNOWN = 2;
 
-
     /* Incoming conference call extra key */
     public static final String QTI_IMS_INCOMING_CONF_EXTRA_KEY = "incomingConference";
 
@@ -548,6 +547,24 @@
                     Settings.Secure.RTT_CALLING_MODE + convertRttPhoneId(phoneId), value ? 1 : 0);
     }
 
+    // Sets global settings with call type preference
+    public static void setCanStartRttCall(boolean value, Context context, int phoneId) {
+        android.provider.Settings.Global.putInt(context.getContentResolver(),
+                    QtiCallConstants.QTI_IMS_CAN_START_RTT_CALL + convertRttPhoneId(phoneId),
+                    value ? QtiCallConstants.RTT_CALL_TYPE_VOICE
+                          : QtiCallConstants.RTT_CALL_TYPE_RTT);
+    }
+
+    // Returns true if can start RTT call
+    public static boolean canStartRttCall(Context context, int phoneId) {
+        if (!shallShowRttVisibilitySetting(phoneId, context)) {
+            return true;
+        }
+        return android.provider.Settings.Global.getInt(context.getContentResolver(),
+                QtiCallConstants.QTI_IMS_CAN_START_RTT_CALL + convertRttPhoneId(phoneId),
+                QtiCallConstants.RTT_CALL_TYPE_RTT) == QtiCallConstants.RTT_CALL_TYPE_RTT;
+    }
+
     // Returns value of RTT visibility
     public static int getRttVisibility(Context context) {
         return getRttVisibility(context, QtiCallConstants.RTT_DEFAULT_PHONE_ID);
@@ -595,16 +612,22 @@
             CarrierConfigManager.KEY_RTT_UPGRADE_SUPPORTED_BOOL);
     }
 
-    // Utility to get the RTT Mode that is set through adb property
-    // Mode can be either RTT_MODE_DISABLED or RTT_MODE_FULL
+    // Utility to get the RTT Mode that is set through ImsSettings
+    // Mode can be either RTT_UPON_REQUEST_MODE or RTT_AUTOMATIC_MODE
     public static int getRttOperatingMode(Context context) {
         return getRttOperatingMode(context, QtiCallConstants.RTT_DEFAULT_PHONE_ID);
     }
 
+    // Utility to get the RTT Operation Mode that is set through ImsSettings
+    // Mode can be either RTT_UPON_REQUEST_MODE or RTT_AUTOMATIC_MODE
+    // Takes a phoneId to support DSDS configuration.
     public static int getRttOperatingMode(Context context, int phoneId) {
-        int mode = SystemProperties.getInt(QtiCallConstants.PROPERTY_RTT_OPERATING_MODE +
-                convertRttPhoneId(phoneId), 0);
-        return mode;
+        if (shallShowRttVisibilitySetting(phoneId, context)) {
+            return QtiCallConstants.RTT_AUTOMATIC_MODE;
+        }
+        return android.provider.Settings.Global.getInt(context.getContentResolver(),
+                QtiCallConstants.QTI_IMS_RTT_OPERATING_MODE + convertRttPhoneId(phoneId),
+                QtiCallConstants.RTT_UPON_REQUEST_MODE);
     }
 
     // Returns true if Carrier supports RTT downgrade
@@ -621,6 +644,13 @@
                 QtiCarrierConfigs.KEY_SHOW_RTT_VISIBILITY_SETTING));
     }
 
+    // Returns true if Carrier supports merging RTT calls
+    // False otherwise
+    public static boolean isRttMergeSupported(int phoneId, Context context) {
+        return isCarrierConfigEnabled(phoneId, context,
+            CarrierConfigManager.KEY_ALLOW_MERGING_RTT_CALLS_BOOL);
+    }
+
     // Returns true if Carrier supports Cancel Modify Call
     public static boolean isCancelModifyCallSupported(int phoneId, Context context) {
         return (isCarrierConfigEnabled(phoneId, context,
@@ -668,4 +698,13 @@
                 QtiCallConstants.IMS_CALL_COMPOSER + phoneId,
                 QtiCallConstants.CALL_COMPOSER_DISABLED);
     }
+
+    // Sets RTT Operation Mode to global settings
+    // Takes a phoneId to support DSDS configuration.
+    public static void setRttOperatingMode(ContentResolver contentResolver, int phoneId,
+            int rttOpMode) {
+        android.provider.Settings.Global.putInt(contentResolver,
+                QtiCallConstants.QTI_IMS_RTT_OPERATING_MODE + convertRttPhoneId(phoneId),
+                rttOpMode);
+    }
 }