IMS: SRVCC related fixes.

1. SRVCC: Fix only one call seen on UI after multi-call SRVCC

    When SRVCC for more than one call happens, the original connection
    is overwritten by the last handover connection for all the
    connections before SRVCC. As a result the connection of second
    call overwrites all the connections after handover

    Change-Id: I449d3cea8d8e430db63ef2af21b3447d1b718e0e

2. Add support for using the state of connection before handover

    Pick the correct connection to replace the original connection
    using the state of handover connection before handover

    Change-Id: I22bf5f4e72dd835ae857ab65423d6601abe454c8

Bug: 18559588
Change-Id: Iac25e07a271cd157c7bf061f1329ff347b867727
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index 9877269..7f92c92 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -60,7 +60,14 @@
                     AsyncResult ar = (AsyncResult) msg.obj;
                     com.android.internal.telephony.Connection connection =
                          (com.android.internal.telephony.Connection) ar.result;
-                    setOriginalConnection(connection);
+                    if ((connection.getAddress() != null &&
+                                    mOriginalConnection.getAddress() != null &&
+                            mOriginalConnection.getAddress().contains(connection.getAddress())) ||
+                            connection.getStateBeforeHandover() == mOriginalConnection.getState()) {
+                        Log.d(TelephonyConnection.this, "SettingOriginalConnection " +
+                                mOriginalConnection.toString() + " with " + connection.toString());
+                        setOriginalConnection(connection);
+                    }
                     break;
                 case MSG_RINGBACK_TONE:
                     Log.v(TelephonyConnection.this, "MSG_RINGBACK_TONE");