Framework fixes to support VoLTE conf calls via RemoteConnectionServices.

Fixing some issues with the addExistingConnection and addConference APIs
on ConnectionService.  When a connection manager relays the addition of
an existing connection or a conference to Telecom, it will assign a new
ID to the new connection/conference.  Due to how RemoteCSes work, the
Connection/Conf will be added directly via TelephonyConnectionService and
also via the connection manager's connection service.  Because the ID
changes, we ended up adding these twice. Conferences weren't a problem in
the GSM conference case because the TElephonyConnectionService's
ConnectionServiceWrapper didn't know of the IDs for the children of the
conference.  However, due to how the existing connections work its not the
case for VoLTE conferences.  To mitigate this, I'm passing the original
connection/conference ID to the connection manager via extras (ugh) and
using this to ensure that when the new existing connection/conference is
added to telecom that the same ID is used.  This ensures that we can
properly de-dupe the requests from TelephonyConnectionService and the
connection manager.

Also, there was some missing code in RemoteConnectionService which would
cause it to not properly track existing connections.

Bug: 31464792
Change-Id: I436f4438fd000ea48ebea7ceb75105bd3f456e46
diff --git a/telecomm/java/android/telecom/RemoteConnectionService.java b/telecomm/java/android/telecom/RemoteConnectionService.java
index fe14003..c65d5ef 100644
--- a/telecomm/java/android/telecom/RemoteConnectionService.java
+++ b/telecomm/java/android/telecom/RemoteConnectionService.java
@@ -219,18 +219,27 @@
                     conference.addConnection(c);
                 }
             }
-
             if (conference.getConnections().size() == 0) {
                 // A conference was created, but none of its connections are ones that have been
                 // created by, and therefore being tracked by, this remote connection service. It
                 // is of no interest to us.
+                Log.d(this, "addConferenceCall - skipping");
                 return;
             }
 
             conference.setState(parcel.getState());
             conference.setConnectionCapabilities(parcel.getConnectionCapabilities());
             conference.setConnectionProperties(parcel.getConnectionProperties());
+            conference.putExtras(parcel.getExtras());
             mConferenceById.put(callId, conference);
+
+            // Stash the original connection ID as it exists in the source ConnectionService.
+            // Telecom will use this to avoid adding duplicates later.
+            // See comments on Connection.EXTRA_ORIGINAL_CONNECTION_ID for more information.
+            Bundle newExtras = new Bundle();
+            newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId);
+            conference.putExtras(newExtras);
+
             conference.registerCallback(new RemoteConference.Callback() {
                 @Override
                 public void onDestroyed(RemoteConference c) {
@@ -342,11 +351,17 @@
         @Override
         public void addExistingConnection(String callId, ParcelableConnection connection,
                 Session.Info sessionInfo) {
-            // TODO: add contents of this method
-            RemoteConnection remoteConnction = new RemoteConnection(callId,
+            RemoteConnection remoteConnection = new RemoteConnection(callId,
                     mOutgoingConnectionServiceRpc, connection);
-
-            mOurConnectionServiceImpl.addRemoteExistingConnection(remoteConnction);
+            mConnectionById.put(callId, remoteConnection);
+            remoteConnection.registerCallback(new RemoteConnection.Callback() {
+                @Override
+                public void onDestroyed(RemoteConnection connection) {
+                    mConnectionById.remove(callId);
+                    maybeDisconnectAdapter();
+                }
+            });
+            mOurConnectionServiceImpl.addRemoteExistingConnection(remoteConnection);
         }
 
         @Override