Merge "Don't call onStartRtt unless RTT property changes" into pi-dev
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index e4e5722..f61a8ee 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -1249,8 +1249,13 @@
                     CallState.CONNECTING,
                     phoneAccountHandle == null ? "no-handle" : phoneAccountHandle.toString());
 
-            if (isRttSettingOn() || (extras != null
-                    && extras.getBoolean(TelecomManager.EXTRA_START_CALL_WITH_RTT, false))) {
+            boolean isVoicemail = (call.getHandle() != null)
+                    && (PhoneAccount.SCHEME_VOICEMAIL.equals(call.getHandle().getScheme())
+                    || (accountToUse != null && mPhoneAccountRegistrar.isVoiceMailNumber(
+                    accountToUse.getAccountHandle(), call.getHandle().getSchemeSpecificPart())));
+
+            if (!isVoicemail && (isRttSettingOn() || (extras != null
+                    && extras.getBoolean(TelecomManager.EXTRA_START_CALL_WITH_RTT, false)))) {
                 Log.d(this, "Outgoing call requesting RTT, rtt setting is %b", isRttSettingOn());
                 if (accountToUse != null
                         && accountToUse.hasCapabilities(PhoneAccount.CAPABILITY_RTT)) {
@@ -1833,8 +1838,15 @@
                 Log.d("phoneAccountSelected: default to voip mode for call %s", call.getId());
                 call.setIsVoipAudioMode(true);
             }
-            if (isRttSettingOn() || call.getIntentExtras()
-                    .getBoolean(TelecomManager.EXTRA_START_CALL_WITH_RTT, false)) {
+
+            boolean isVoicemail = (call.getHandle() != null)
+                    && (PhoneAccount.SCHEME_VOICEMAIL.equals(call.getHandle().getScheme())
+                    || (realPhoneAccount != null && mPhoneAccountRegistrar.isVoiceMailNumber(
+                    realPhoneAccount.getAccountHandle(),
+                    call.getHandle().getSchemeSpecificPart())));
+
+            if (!isVoicemail && (isRttSettingOn() || call.getIntentExtras()
+                    .getBoolean(TelecomManager.EXTRA_START_CALL_WITH_RTT, false))) {
                 Log.d(this, "Outgoing call after account selection requesting RTT," +
                         " rtt setting is %b", isRttSettingOn());
                 if (realPhoneAccount != null
diff --git a/src/com/android/server/telecom/InCallAdapter.java b/src/com/android/server/telecom/InCallAdapter.java
index f3afc9a..8de27be 100644
--- a/src/com/android/server/telecom/InCallAdapter.java
+++ b/src/com/android/server/telecom/InCallAdapter.java
@@ -96,15 +96,19 @@
     public void rejectCall(String callId, boolean rejectWithMessage, String textMessage) {
         try {
             Log.startSession(LogUtils.Sessions.ICA_REJECT_CALL, mOwnerComponentName);
-            // Check to make sure the in-call app's user isn't restricted from sending SMS. If so,
-            // silently drop the outgoing message. Also drop message if the screen is locked.
-            if (!mCallsManager.isReplyWithSmsAllowed(Binder.getCallingUid())) {
-                rejectWithMessage = false;
-                textMessage = null;
-            }
+
+            int callingUid = Binder.getCallingUid();
             long token = Binder.clearCallingIdentity();
             try {
                 synchronized (mLock) {
+                    // Check to make sure the in-call app's user isn't restricted from sending SMS.
+                    // If so, silently drop the outgoing message. Also drop message if the screen is
+                    // locked.
+                    if (!mCallsManager.isReplyWithSmsAllowed(callingUid)) {
+                        rejectWithMessage = false;
+                        textMessage = null;
+                    }
+
                     Log.d(this, "rejectCall(%s,%b,%s)", callId, rejectWithMessage, textMessage);
                     Call call = mCallIdMapper.getCall(callId);
                     if (call != null) {