Merge "Fix parent call not being identified as a conference call" into klp-dev
diff --git a/src/com/android/phone/CallModeler.java b/src/com/android/phone/CallModeler.java
index 495a5ef..52a7ef8 100644
--- a/src/com/android/phone/CallModeler.java
+++ b/src/com/android/phone/CallModeler.java
@@ -345,9 +345,9 @@
      */
     private boolean updateForConferenceCalls(Connection connection, List<Call> updatedCalls) {
         // We consider this connection a conference connection if the call it
-        // belongs to is a multiparty call AND it is the first connection.
+        // belongs to is a multiparty call AND it is the first live connection.
         final boolean isConferenceCallConnection = isPartOfLiveConferenceCall(connection) &&
-                connection.getCall().getEarliestConnection() == connection;
+                getEarliestLiveConnection(connection.getCall()) == connection;
 
         boolean changed = false;
 
@@ -384,6 +384,23 @@
         return changed;
     }
 
+    private Connection getEarliestLiveConnection(com.android.internal.telephony.Call call) {
+        final List<Connection> connections = call.getConnections();
+        final int size = connections.size();
+        Connection earliestConn = null;
+        long earliestTime = Long.MAX_VALUE;
+        for (int i = 0; i < size; i++) {
+            final Connection connection = connections.get(i);
+            if (!connection.isAlive()) continue;
+            final long time = connection.getCreateTime();
+            if (time < earliestTime) {
+                earliestTime = time;
+                earliestConn = connection;
+            }
+        }
+        return earliestConn;
+    }
+
     /**
      * Sets the new call state onto the call and performs some additional logic
      * associated with setting the state.