Merge "Set the value of KEY_CARRIER_CONFIG_OVERRIDE_BOOL"
diff --git a/res/values/config.xml b/res/values/config.xml
index 615d43f..b3fc30a 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -232,6 +232,9 @@
          disconnecting the ongoing Telephony call when the call goes active. -->
     <bool name="config_support_handover_from">false</bool>
 
+    <!-- Flag indicating whether the device supports RTT (real-time text) -->
+    <bool name="config_support_rtt">false</bool>
+
     <!-- Flag indicating whether a system app can use video calling fallback if carrier video
          calling is not available. -->
     <bool name="config_support_video_calling_fallback">false</bool>
diff --git a/src/com/android/phone/NotificationMgr.java b/src/com/android/phone/NotificationMgr.java
index 97daa34..d36c761 100644
--- a/src/com/android/phone/NotificationMgr.java
+++ b/src/com/android/phone/NotificationMgr.java
@@ -45,7 +45,6 @@
 import android.telephony.ServiceState;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
-import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.util.ArrayMap;
@@ -162,7 +161,7 @@
     /* package */ void refreshMwi(int subId) {
         // In a single-sim device, subId can be -1 which means "no sub id".  In this case we will
         // reference the single subid stored in the mMwiVisible map.
-        if (subId == SubscriptionInfoHelper.NO_SUB_ID) {
+        if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
             if (mMwiVisible.keySet().size() == 1) {
                 Set<Integer> keySet = mMwiVisible.keySet();
                 Iterator<Integer> keyIt = keySet.iterator();
diff --git a/src/com/android/phone/SubscriptionInfoHelper.java b/src/com/android/phone/SubscriptionInfoHelper.java
index 9f0ebd0..7c373e0 100644
--- a/src/com/android/phone/SubscriptionInfoHelper.java
+++ b/src/com/android/phone/SubscriptionInfoHelper.java
@@ -20,12 +20,12 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.res.Resources;
+import android.telecom.PhoneAccountHandle;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 
-import com.android.phone.PhoneGlobals;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneFactory;
 
@@ -37,7 +37,6 @@
  * helping extract this info and perform common operations using this info.
  */
 public class SubscriptionInfoHelper {
-    public static final int NO_SUB_ID = -1;
 
     // Extra on intent containing the id of a subscription.
     public static final String SUB_ID_EXTRA =
@@ -46,17 +45,24 @@
     private static final String SUB_LABEL_EXTRA =
             "com.android.phone.settings.SubscriptionInfoHelper.SubscriptionLabel";
 
-    private static Context mContext;
+    private Context mContext;
 
-    private static int mSubId = NO_SUB_ID;
-    private static String mSubLabel;
+    private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
+    private String mSubLabel;
 
     /**
      * Instantiates the helper, by extracting the subscription id and label from the intent.
      */
     public SubscriptionInfoHelper(Context context, Intent intent) {
         mContext = context;
-        mSubId = intent.getIntExtra(SUB_ID_EXTRA, NO_SUB_ID);
+        PhoneAccountHandle phoneAccountHandle =
+                intent.getParcelableExtra(TelephonyManager.EXTRA_PHONE_ACCOUNT_HANDLE);
+        if (phoneAccountHandle != null) {
+            mSubId = PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
+        }
+        if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+            mSubId = intent.getIntExtra(SUB_ID_EXTRA, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+        }
         mSubLabel = intent.getStringExtra(SUB_LABEL_EXTRA);
     }
 
@@ -118,7 +124,7 @@
     }
 
     public boolean hasSubId() {
-        return mSubId != NO_SUB_ID;
+        return mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID;
     }
 
     public int getSubId() {
diff --git a/src/com/android/services/telephony/TelecomAccountRegistry.java b/src/com/android/services/telephony/TelecomAccountRegistry.java
index 8963229..49a21c8 100644
--- a/src/com/android/services/telephony/TelecomAccountRegistry.java
+++ b/src/com/android/services/telephony/TelecomAccountRegistry.java
@@ -226,6 +226,12 @@
                         isHandoverFromSupported);
             }
 
+            boolean isDeviceRttSupported = mContext.getResources().getBoolean(
+                    R.bool.config_support_rtt);
+            if (isDeviceRttSupported && isCarrierRttSupported()) {
+                capabilities |= PhoneAccount.CAPABILITY_RTT;
+            }
+
             extras.putBoolean(PhoneAccount.EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK,
                     mContext.getResources()
                             .getBoolean(R.bool.config_support_video_calling_fallback));
@@ -390,6 +396,12 @@
                     b.getBoolean(CarrierConfigManager.KEY_SUPPORT_VIDEO_CONFERENCE_CALL_BOOL);
         }
 
+        private boolean isCarrierRttSupported() {
+            PersistableBundle b =
+                    PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
+            return b != null && b.getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
+        }
+
         /**
          * Determines from carrier config whether merging of wifi calls is allowed when VoWIFI is
          * turned off.
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index 26aeaba..e64e5a5 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -33,7 +33,6 @@
 import android.telecom.TelecomManager;
 import android.telecom.VideoProfile;
 import android.telephony.CarrierConfigManager;
-import android.telephony.DisconnectCause;
 import android.telephony.PhoneNumberUtils;
 import android.telephony.TelephonyManager;
 import android.util.Pair;
@@ -521,6 +520,11 @@
     protected final boolean mIsOutgoing;
 
     /**
+     * Indicates whether this call is using assisted dialing.
+     */
+    private boolean mIsUsingAssistedDialing;
+
+    /**
      * Listeners to our TelephonyConnection specific callbacks
      */
     private final Set<TelephonyConnectionListener> mTelephonyListeners = Collections.newSetFromMap(
@@ -823,6 +827,8 @@
                 isExternalConnection());
         newProperties = changeBitmask(newProperties, PROPERTY_HAS_CDMA_VOICE_PRIVACY,
                 mIsCdmaVoicePrivacyEnabled);
+        newProperties = changeBitmask(newProperties, PROPERTY_ASSISTED_DIALING_USED,
+                mIsUsingAssistedDialing);
 
         if (getConnectionProperties() != newProperties) {
             setConnectionProperties(newProperties);
@@ -1692,6 +1698,15 @@
         return mWasImsConnection;
     }
 
+    boolean getIsUsingAssistedDialing() {
+        return mIsUsingAssistedDialing;
+    }
+
+    void setIsUsingAssistedDialing(Boolean isUsingAssistedDialing) {
+        mIsUsingAssistedDialing = isUsingAssistedDialing;
+        updateConnectionProperties();
+    }
+
     private static Uri getAddressFromNumber(String number) {
         // Address can be null for blocked calls.
         if (number == null) {
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index f4ee745..ea460cf 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -421,7 +421,11 @@
                     isEmergencyNumber, handle, phone);
             // If there was a failure, the resulting connection will not be a TelephonyConnection,
             // so don't place the call!
-            if(resultConnection instanceof TelephonyConnection) {
+            if (resultConnection instanceof TelephonyConnection) {
+                if (request.getExtras() != null && request.getExtras().getBoolean(
+                        TelecomManager.EXTRA_USE_ASSISTED_DIALING, false)) {
+                    ((TelephonyConnection) resultConnection).setIsUsingAssistedDialing(true);
+                }
                 placeOutgoingConnection((TelephonyConnection) resultConnection, phone, request);
             }
             return resultConnection;