IMS: Support IMS Data Channel

- Add API to check if IMS service data channel capability
is enabled/disabled from modem.
- Add carrier config to control DC for carriers.
- Add extra to provide CallId and isDcCall to upper layer.
- Add API to store/retrieve user setting for data channel.

Change-Id: I07f5f13d4d917538a718fcc9287bc112e63e5ec8
CRs-Fixed: 3137374
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 c52986f..1e3d5cd 100755
--- a/ims/ims-ext-common/src/org/codeaurora/ims/QtiCallConstants.java
+++ b/ims/ims-ext-common/src/org/codeaurora/ims/QtiCallConstants.java
@@ -362,6 +362,7 @@
     public static final int QTI_CONFIG_VOWIFI_ROAMING_MODE_PREFERENCE = 1003;
     public static final int CALL_COMPOSER_MODE = 1004;
     public static final int B2C_ENRICHED_CALLING_MODE = 1005;
+    public static final int DATA_CHANNEL_MODE = 1006;
 
     /**
      * Key values for the pre alerting call elements
@@ -455,6 +456,14 @@
     public static final int B2C_ENRICHED_CALLING_ENABLED = 1;
 
     /**
+     * User setting to control whether ims data channel is allowed
+     * Type: int (0 for disable, 1 for enabled);
+     */
+    public static final String DATA_CHANNEL = "qti.settings.data_channel";
+    public static final int DATA_CHANNEL_DISABLED = 0;
+    public static final int DATA_CHANNEL_ENABLED = 1;
+
+    /**
      * Constants used by clients as part of registration status change indication.
      * Below constants will be notified when modem is unable to get the geo location information.
      */
@@ -522,4 +531,7 @@
      *  - activate CFx before register operation
      *  - query CFNL while network does not support CFNL feature */
     public static final int CODE_UT_CF_SERVICE_NOT_REGISTERED = 850;
+    // Data Channel call information
+    public static final String EXTRA_DATA_CHANNEL_MODEM_CALL_ID = "modemCallId";
+    public static final String EXTRA_IS_DATA_CHANNEL_CALL = "isDcCall";
 }
diff --git a/ims/ims-ext-common/src/org/codeaurora/ims/QtiCarrierConfigs.java b/ims/ims-ext-common/src/org/codeaurora/ims/QtiCarrierConfigs.java
index 477cabd..ebdc1b6 100755
--- a/ims/ims-ext-common/src/org/codeaurora/ims/QtiCarrierConfigs.java
+++ b/ims/ims-ext-common/src/org/codeaurora/ims/QtiCarrierConfigs.java
@@ -197,4 +197,10 @@
      */
     public static final String KEY_IS_PRIVATE_NETWORK =
         "is_private_network";
+
+    /* Config to determine if Carrier supports ims data channel
+     * true - if data channel is support else false
+     */
+     public static final String KEY_CARRIER_DATA_CHANNEL_SUPPORTED =
+         "carrier_data_channel_supported_bool";
 }
diff --git a/ims/ims-ext-common/src/org/codeaurora/ims/QtiImsExtBase.java b/ims/ims-ext-common/src/org/codeaurora/ims/QtiImsExtBase.java
index 2755507..c63c29d 100644
--- a/ims/ims-ext-common/src/org/codeaurora/ims/QtiImsExtBase.java
+++ b/ims/ims-ext-common/src/org/codeaurora/ims/QtiImsExtBase.java
@@ -118,6 +118,12 @@
         }
 
         @Override
+        public void setDataChannelCapabilityListener(int phoneId,
+                IQtiImsExtListener listener) {
+           onSetDataChannelCapabilityListener(phoneId, listener);
+        }
+
+        @Override
         public int getRcsAppConfig(int phoneId) {
             return onGetRcsAppConfig(phoneId);
 
@@ -185,6 +191,11 @@
         public boolean isExitScbmFeatureSupported(int phoneId) {
             return onIsExitScbmFeatureSupported(phoneId);
         }
+
+        @Override
+        public boolean isDataChannelEnabled(int phoneId) {
+            return onIsDataChannelEnabled(phoneId);
+        }
     };
 
     private QtiImsExtBinder mQtiImsExtBinder;
@@ -298,4 +309,14 @@
         // no-op
         return false;
     }
+
+    protected void onSetDataChannelCapabilityListener(int phoneId,
+            IQtiImsExtListener listener) {
+        // no-op
+    }
+
+    protected boolean onIsDataChannelEnabled(int phoneId) {
+        // no-op
+        return false;
+    }
 }
diff --git a/ims/ims-ext-common/src/org/codeaurora/ims/QtiImsExtListenerBaseImpl.java b/ims/ims-ext-common/src/org/codeaurora/ims/QtiImsExtListenerBaseImpl.java
index d98f119..0dac915 100644
--- a/ims/ims-ext-common/src/org/codeaurora/ims/QtiImsExtListenerBaseImpl.java
+++ b/ims/ims-ext-common/src/org/codeaurora/ims/QtiImsExtListenerBaseImpl.java
@@ -106,5 +106,9 @@
     @Override
     public void onScbmExited(boolean status) {
     }
+
+    @Override
+    public void notifyDataChannelCapability(int phoneId, boolean dcCapability) {
+    }
 }
 
diff --git a/ims/ims-ext-common/src/org/codeaurora/ims/QtiImsExtManager.java b/ims/ims-ext-common/src/org/codeaurora/ims/QtiImsExtManager.java
index 97a8297..42eae0d 100644
--- a/ims/ims-ext-common/src/org/codeaurora/ims/QtiImsExtManager.java
+++ b/ims/ims-ext-common/src/org/codeaurora/ims/QtiImsExtManager.java
@@ -423,4 +423,32 @@
         }
     }
 
+    /**
+     * Used by client to register call back listener with vendor for
+     * UNSOL indication when data channel capability updated.
+     */
+    public void setDataChannelCapabilityListener(int phoneId, IQtiImsExtListener listener)
+            throws QtiImsException {
+        validateInvariants(phoneId);
+        try {
+            mQtiImsExt.setDataChannelCapabilityListener(phoneId, listener);
+        } catch(RemoteException e) {
+            throw new QtiImsException("Remote ImsService setDataChannelCapabilityListener : "
+                    + e);
+        }
+    }
+    /**
+     * Used by clients to check if IMS service data channel is enabled/disabled
+     * @param phoneId indicates the phone instance which triggered the request
+     * @return boolean
+     */
+    public boolean isDataChannelEnabled(int phoneId)
+            throws QtiImsException {
+        validateInvariants(phoneId);
+        try {
+            return mQtiImsExt.isDataChannelEnabled(phoneId);
+        } catch (RemoteException e) {
+            throw new QtiImsException("Remote ImsService isDataChannelEnabled: " + e);
+        }
+    }
 }
diff --git a/ims/ims-ext-common/src/org/codeaurora/ims/internal/IQtiImsExt.aidl b/ims/ims-ext-common/src/org/codeaurora/ims/internal/IQtiImsExt.aidl
index 153db12..8e960a2 100644
--- a/ims/ims-ext-common/src/org/codeaurora/ims/internal/IQtiImsExt.aidl
+++ b/ims/ims-ext-common/src/org/codeaurora/ims/internal/IQtiImsExt.aidl
@@ -341,4 +341,25 @@
       * @throws RemoteException if calling the IMS service results in an error.
       */
      boolean isExitScbmFeatureSupported(int phoneId);
+
+   /**
+     * setDataChannelCapabilityListener
+     * Set data channel capability listener.
+     *
+     * @param phoneId indicates the phone instance which triggered the request
+     * @param listener an IQtiImsExtListener instance to indicate the response
+     * @return void
+     */
+    oneway void setDataChannelCapabilityListener(int phoneId, IQtiImsExtListener listener);
+
+    /**
+     * isDataChannelEnabled
+     * Retrieves whether IMS service data channel is enabled/disabled
+     *
+     * @param phoneId indicates the phone instance which triggered the request
+     * @return boolean
+     *
+     *@throws RemoteException if calling the IMS service results in an error.
+     */
+    boolean isDataChannelEnabled(int phoneId);
 }
diff --git a/ims/ims-ext-common/src/org/codeaurora/ims/internal/IQtiImsExtListener.aidl b/ims/ims-ext-common/src/org/codeaurora/ims/internal/IQtiImsExtListener.aidl
index 8d5db4f..3d3c73c 100644
--- a/ims/ims-ext-common/src/org/codeaurora/ims/internal/IQtiImsExtListener.aidl
+++ b/ims/ims-ext-common/src/org/codeaurora/ims/internal/IQtiImsExtListener.aidl
@@ -197,4 +197,12 @@
      */
    void onScbmExited(boolean status);
 
+   /** Notifies client on data channel capability
+     * @param phoneId indicates the phone instance which triggered the request
+     * @param dcCapability
+     *        if true  : has data channel capability
+     *        if false : no data channel capability
+     * @return void.
+     */
+   void notifyDataChannelCapability(int phoneId, boolean dcCapability);
 }
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 0a26676..6f482ee 100755
--- a/ims/ims-ext-common/src/org/codeaurora/ims/utils/QtiImsExtUtils.java
+++ b/ims/ims-ext-common/src/org/codeaurora/ims/utils/QtiImsExtUtils.java
@@ -823,4 +823,27 @@
         return isCarrierConfigEnabled(phoneId, context,
                 QtiCarrierConfigs.KEY_CARRIER_SEND_MEDIA_CONFIG_SUPPORTED);
     }
+
+    // Returns true if Carrier supports data channel
+    public static boolean isDataChannelSupported(int phoneId, Context context) {
+        return isCarrierConfigEnabled(phoneId, context,
+                QtiCarrierConfigs.KEY_CARRIER_DATA_CHANNEL_SUPPORTED);
+    }
+
+    // Stores user setting for data channel
+    public static void setDataChannelUserPreference(ContentResolver contentResolver,
+            int phoneId, boolean turnOn) {
+        final int value = turnOn ? QtiCallConstants.DATA_CHANNEL_ENABLED :
+                QtiCallConstants.DATA_CHANNEL_DISABLED;
+        android.provider.Settings.Global.putInt(contentResolver,
+                QtiCallConstants.DATA_CHANNEL + phoneId, value);
+    }
+
+    // retrieves the stored user setting from the database per phone id
+    public static int getDataChannelUserPreference(ContentResolver contentResolver,
+            int phoneId) {
+        return android.provider.Settings.Global.getInt(contentResolver,
+                QtiCallConstants.DATA_CHANNEL + phoneId,
+                QtiCallConstants.DATA_CHANNEL_DISABLED);
+    }
 }