Clean up calls in GsmCdmaCallTracker on GSM<->CDMA transitions.

Bug: 29972199
Change-Id: I2df4264a97239d6c87378ebae8e30abd8de6af0f
diff --git a/src/java/com/android/internal/telephony/GsmCdmaCallTracker.java b/src/java/com/android/internal/telephony/GsmCdmaCallTracker.java
index 37a4ae5..d918362 100755
--- a/src/java/com/android/internal/telephony/GsmCdmaCallTracker.java
+++ b/src/java/com/android/internal/telephony/GsmCdmaCallTracker.java
@@ -189,6 +189,10 @@
                 gsmCdmaConnection.dispose();
             }
         }
+
+        mConnections = null;
+        mPendingMO = null;
+        mState = PhoneConstants.State.IDLE;
     }
 
     @Override
diff --git a/src/java/com/android/internal/telephony/GsmCdmaConnection.java b/src/java/com/android/internal/telephony/GsmCdmaConnection.java
index aa92a18..a195bd1 100644
--- a/src/java/com/android/internal/telephony/GsmCdmaConnection.java
+++ b/src/java/com/android/internal/telephony/GsmCdmaConnection.java
@@ -215,6 +215,9 @@
 
     public void dispose() {
         clearPostDialListeners();
+        if (mParent != null) {
+            mParent.detach(this);
+        }
         releaseAllWakeLocks();
     }
 
diff --git a/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaCallTrackerTest.java b/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaCallTrackerTest.java
index 29a56d1..fb4ab24 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaCallTrackerTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaCallTrackerTest.java
@@ -358,6 +358,18 @@
 
         // verify getCurrentCalls is called on updating phone type
         verify(mSimulatedCommandsVerifier, times(2)).getCurrentCalls(any(Message.class));
+
+        // verify that if phone type is updated, calls and callTracker go to idle
+        testMOCallPickUp();
+
+        // update phone type
+        mCTUT.updatePhoneType();
+
+        // verify CT and calls go to idle
+        assertEquals(PhoneConstants.State.IDLE, mCTUT.getState());
+        assertEquals(GsmCdmaCall.State.IDLE, mCTUT.mForegroundCall.getState());
+        assertEquals(GsmCdmaCall.State.IDLE, mCTUT.mBackgroundCall.getState());
+        assertEquals(GsmCdmaCall.State.IDLE, mCTUT.mRingingCall.getState());
     }
 }