Merge "Removing STOPSHIP comment that is not needed (per bug)." into lmp-mr1-dev
diff --git a/src/com/android/server/telecom/Call.java b/src/com/android/server/telecom/Call.java
index 19b7fdb..3e66426 100644
--- a/src/com/android/server/telecom/Call.java
+++ b/src/com/android/server/telecom/Call.java
@@ -331,6 +331,13 @@
             boolean isIncoming,
             boolean isConference) {
         mState = isConference ? CallState.ACTIVE : CallState.NEW;
+
+        // Conference calls are considered connected upon adding to Telecom, so set the connect
+        // time now.
+        if (isConference) {
+            mConnectTimeMillis = System.currentTimeMillis();
+        }
+
         mContext = context;
         mRepository = repository;
         setHandle(handle);
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index 1697d38..be2e25b 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -412,13 +412,19 @@
     private Call getNewOutgoingCall(Uri handle) {
         // First check to see if we can reuse any of the calls that are waiting to disconnect.
         // See {@link Call#abort} and {@link #onCanceledViaNewOutgoingCall} for more information.
+        Call reusedCall = null;
         for (Call pendingCall : mPendingCallsToDisconnect) {
-            if (Objects.equals(pendingCall.getHandle(), handle)) {
+            if (reusedCall == null && Objects.equals(pendingCall.getHandle(), handle)) {
                 mPendingCallsToDisconnect.remove(pendingCall);
                 Log.i(this, "Reusing disconnected call %s", pendingCall);
-                return pendingCall;
+                reusedCall = pendingCall;
+            } else {
+                pendingCall.disconnect();
             }
         }
+        if (reusedCall != null) {
+            return reusedCall;
+        }
 
         // Create a call with original handle. The handle may be changed when the call is attached
         // to a connection service, but in most cases will remain the same.
@@ -484,6 +490,7 @@
         // a call, or cancel this call altogether.
         if (!isPotentialInCallMMICode && !makeRoomForOutgoingCall(call, isEmergencyCall)) {
             // just cancel at this point.
+            Log.i(this, "No remaining room for outgoing call: %s", call);
             if (mCalls.contains(call)) {
                 // This call can already exist if it is a reused call,
                 // See {@link #getNewOutgoingCall}.
diff --git a/src/com/android/server/telecom/InCallController.java b/src/com/android/server/telecom/InCallController.java
index bc0e315..4698c61 100644
--- a/src/com/android/server/telecom/InCallController.java
+++ b/src/com/android/server/telecom/InCallController.java
@@ -493,13 +493,18 @@
         List<Call> childCalls = call.getChildCalls();
         List<String> childCallIds = new ArrayList<>();
         if (!childCalls.isEmpty()) {
-            connectTimeMillis = Long.MAX_VALUE;
+            long childConnectTimeMillis = Long.MAX_VALUE;
             for (Call child : childCalls) {
                 if (child.getConnectTimeMillis() > 0) {
-                    connectTimeMillis = Math.min(child.getConnectTimeMillis(), connectTimeMillis);
+                    childConnectTimeMillis = Math.min(child.getConnectTimeMillis(),
+                            childConnectTimeMillis);
                 }
                 childCallIds.add(mCallIdMapper.getCallId(child));
             }
+
+            if (childConnectTimeMillis != Long.MAX_VALUE) {
+                connectTimeMillis = childConnectTimeMillis;
+            }
         }
 
         Uri handle = call.getHandlePresentation() == TelecomManager.PRESENTATION_ALLOWED ?
@@ -582,6 +587,9 @@
 
         Connection.CAPABILITY_DISCONNECT_FROM_CONFERENCE,
         android.telecom.Call.Details.CAPABILITY_DISCONNECT_FROM_CONFERENCE,
+
+        Connection.CAPABILITY_GENERIC_CONFERENCE,
+        android.telecom.Call.Details.CAPABILITY_GENERIC_CONFERENCE
     };
 
     private static int convertConnectionToCallCapabilities(int connectionCapabilities) {