Merge "Switch to using TelephonyConnection#hangup instead of onDisconnect." into sc-dev
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index 64c008a..2383981 100755
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -2097,7 +2097,8 @@
         phone.unregisterForInCallVoicePrivacyOff(mHandler);
     }
 
-    protected void hangup(int telephonyDisconnectCode) {
+    @VisibleForTesting
+    public void hangup(int telephonyDisconnectCode) {
         if (mOriginalConnection != null) {
             mHangupDisconnectCause = telephonyDisconnectCode;
             try {
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index b3b50ee..d872316 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -2628,7 +2628,10 @@
                         if (!tc.shouldTreatAsEmergencyCall()) {
                             Log.i(LOG_TAG, "maybeDisconnectCallsOnOtherSubs: disconnect %s due to "
                                     + "incoming call on other sub.", tc.getTelecomCallId());
-                            tc.onDisconnect();
+                            // Note: intentionally calling hangup instead of onDisconnect.
+                            // onDisconnect posts the disconnection to a handle which means that the
+                            // disconnection will take place AFTER we answer the incoming call.
+                            tc.hangup(android.telephony.DisconnectCause.LOCAL);
                         }
                     }
                 });
diff --git a/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java b/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java
index 2a79247..50386f1 100644
--- a/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java
+++ b/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java
@@ -96,9 +96,8 @@
             return null;
         }
 
-
         @Override
-        public void onDisconnect() {
+        public void hangup(int telephonyDisconnectCode) {
             wasDisconnected = true;
         }
     }