IMS conference merge improvements.

1. When adding a new child call in an ims conference, use new CS method
to add it and set the parent property at the same time.  This helps
prevent jank in the InCall UI when unparented children are added.
2. When the original call get disconnected, setting the reason code to
IMS_MERGED_SUCCESSFULLY so that dialer will have a notion that the call
is being disconnected due to merging; this will allow better filtering.

Test: Manual
Bug: 37581781
Change-Id: I75e560837c258c1fa9c0fae71c73c2e29bceb1a6
diff --git a/src/com/android/services/telephony/ImsConference.java b/src/com/android/services/telephony/ImsConference.java
index eb1fccf..c5a0896 100644
--- a/src/com/android/services/telephony/ImsConference.java
+++ b/src/com/android/services/telephony/ImsConference.java
@@ -131,17 +131,6 @@
         }
 
         /**
-         * Handles destruction of the host connection; once the host connection has been
-         * destroyed, cleans up the conference participant connection.
-         *
-         * @param connection The host connection.
-         */
-        @Override
-        public void onDestroyed(android.telecom.Connection connection) {
-            disconnectConferenceParticipants();
-        }
-
-        /**
          * Handles changes to conference participant data as reported by the conference host
          * connection.
          *
@@ -416,6 +405,8 @@
             return;
         }
 
+        disconnectConferenceParticipants();
+
         Call call = mConferenceHost.getCall();
         if (call != null) {
             try {
@@ -743,8 +734,9 @@
             mConferenceParticipantConnections.put(new Pair<>(participant.getHandle(),
                     participant.getEndpoint()), connection);
         }
+
         mTelephonyConnectionService.addExistingConnection(mConferenceHostPhoneAccountHandle,
-                connection);
+                connection, this);
         addConnection(connection);
     }
 
diff --git a/src/com/android/services/telephony/ImsConferenceController.java b/src/com/android/services/telephony/ImsConferenceController.java
index c2319a7..501808f 100644
--- a/src/com/android/services/telephony/ImsConferenceController.java
+++ b/src/com/android/services/telephony/ImsConferenceController.java
@@ -16,6 +16,7 @@
 
 package com.android.services.telephony;
 
+import com.android.ims.ImsReasonInfo;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
 import com.android.phone.PhoneUtils;
@@ -382,7 +383,9 @@
         // disconnect tone is not played.
         connection.removeConnectionListener(mConnectionListener);
         connection.clearOriginalConnection();
-        connection.setDisconnected(new DisconnectCause(DisconnectCause.OTHER));
+        connection.setDisconnected(new DisconnectCause(DisconnectCause.OTHER,
+                android.telephony.DisconnectCause.toString(
+                        android.telephony.DisconnectCause.IMS_MERGED_SUCCESSFULLY)));
         connection.destroy();
         mImsConferences.add(conference);
     }
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index b9be502..ccc5f1e 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -98,6 +98,12 @@
                     .addExistingConnection(phoneAccountHandle, connection);
         }
         @Override
+        public void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
+                Connection connection, Conference conference) {
+            TelephonyConnectionService.this
+                    .addExistingConnection(phoneAccountHandle, connection, conference);
+        }
+        @Override
         public void addConnectionToConferenceController(TelephonyConnection connection) {
             TelephonyConnectionService.this.addConnectionToConferenceController(connection);
         }
diff --git a/src/com/android/services/telephony/TelephonyConnectionServiceProxy.java b/src/com/android/services/telephony/TelephonyConnectionServiceProxy.java
index ee77b08..1ced34a 100644
--- a/src/com/android/services/telephony/TelephonyConnectionServiceProxy.java
+++ b/src/com/android/services/telephony/TelephonyConnectionServiceProxy.java
@@ -16,6 +16,7 @@
 
 package com.android.services.telephony;
 
+import android.telecom.Conference;
 import android.telecom.Connection;
 import android.telecom.PhoneAccountHandle;
 
@@ -31,6 +32,8 @@
     void addConference(ImsConference mImsConference);
     void removeConnection(Connection connection);
     void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
-                               Connection connection);
+            Connection connection);
+    void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
+                               Connection connection, Conference conference);
     void addConnectionToConferenceController(TelephonyConnection connection);
 }