am 4039488e: am 70f3528c: am 8b0a1bbd: Merge "DO NOT MERGE Double-check SIP state before issuing a swap-calls command." into mnc-dr-dev

* commit '4039488ef1de5be6a63b9111839f61d8b4d509e7':
  DO NOT MERGE Double-check SIP state before issuing a swap-calls command.
diff --git a/sip/src/com/android/services/telephony/sip/SipConnection.java b/sip/src/com/android/services/telephony/sip/SipConnection.java
index e9f8e05..173bc99 100644
--- a/sip/src/com/android/services/telephony/sip/SipConnection.java
+++ b/sip/src/com/android/services/telephony/sip/SipConnection.java
@@ -134,7 +134,14 @@
         try {
             if (getPhone() != null && getState() == STATE_ACTIVE
                     && getPhone().getRingingCall().getState() != Call.State.WAITING) {
-                getPhone().switchHoldingAndActive();
+                // Double check with the internal state since a discrepancy in states could mean
+                // that the transactions is already in progress from a previous request.
+                if (mOriginalConnection != null &&
+                        mOriginalConnection.getState() == Call.State.ACTIVE) {
+                    getPhone().switchHoldingAndActive();
+                } else {
+                    log("skipping switch from onHold due to internal state:");
+                }
             }
         } catch (CallStateException e) {
             log("onHold, exception: " + e);
@@ -146,7 +153,14 @@
         if (VERBOSE) log("onUnhold");
         try {
             if (getPhone() != null && getState() == STATE_HOLDING) {
-                getPhone().switchHoldingAndActive();
+                // Double check with the internal state since a discrepancy in states could mean
+                // that the transaction is already in progress from a previous request.
+                if (mOriginalConnection != null &&
+                        mOriginalConnection.getState() == Call.State.HOLDING) {
+                    getPhone().switchHoldingAndActive();
+                } else {
+                    log("skipping switch from onUnHold due to internal state.");
+                }
             }
         } catch (CallStateException e) {
             log("onUnhold, exception: " + e);