Don't create conferences with invalid calls

When a remote conference was created
ConnectionServiceWrapper would actually create 2
conferences. One for the remote connection service with no
valid calls one for the real connection service with valid
calls.

When the conference was destroyed the remove call on the
remote connection serivce would trigger a unbind causing
android.telecom.ConnectionService to end call connections
for that service.

Fix was to ensure that we only create conferences with
valid calls.

Bug: 17632595
Change-Id: I3f339120dde8eb07ee7e40a26d3a37f1dbd1409e
diff --git a/src/com/android/server/telecom/ConnectionServiceWrapper.java b/src/com/android/server/telecom/ConnectionServiceWrapper.java
index efa01e9..ce93177 100644
--- a/src/com/android/server/telecom/ConnectionServiceWrapper.java
+++ b/src/com/android/server/telecom/ConnectionServiceWrapper.java
@@ -198,6 +198,21 @@
                         }
                         ParcelableConference parcelableConference =
                                 (ParcelableConference) args.arg2;
+
+                        // Make sure that there's at least one valid call. For remote connections
+                        // we'll get a add conference msg from both the remote connection service
+                        // and from the real connection service.
+                        boolean hasValidCalls = false;
+                        for (String callId : parcelableConference.getConnectionIds()) {
+                            if (mCallIdMapper.getCall(callId) != null) {
+                                hasValidCalls = true;
+                            }
+                        }
+                        if (!hasValidCalls) {
+                            Log.d(this, "Attempting to add a conference with no valid calls");
+                            break;
+                        }
+
                         // need to create a new Call
                         Call conferenceCall = mCallsManager.createConferenceCall(
                                 null, parcelableConference);
@@ -426,7 +441,6 @@
             logIncoming("removeCall %s", callId);
             if (mCallIdMapper.isValidCallId(callId) || mCallIdMapper.isValidConferenceId(callId)) {
                 mHandler.obtainMessage(MSG_REMOVE_CALL, callId).sendToTarget();
-                mHandler.obtainMessage(MSG_REMOVE_CALL, callId);
             }
         }