Fix potential call crashes in Telephony.

There is a timing issue in the ImsPhoneCallTracker#dial method.  Basically
we assign the new outgoing call to mPendingMO, but it is possible for the
dial to go out and the modem to signal onCallProgressing for that call.
onCallProgressing will set mPendingMO to null, which means by the time we
end the dial method, the return value we send back is null.  This in turn
causes TelephonyConnectionService to think that the dialed number was an
MMI code and to bring up the MMI code dialog which itself crashes because
_surprise_ the call wasn't actually an MMI code.

Changing the dial method to cache the pending MO call as a local variable
so we can still pass it back and allow the call to set up as expected.

Test: Run telephony unit tests.
Test: Manual phone call regression testing for normal numbers.
Test: Manual phone call regression testing for test emergency numbers.
Bug: 149005037
Change-Id: I959196ffbaf3843ba15369029fc640ee47df9d3a
(cherry picked from commit c808925d6f16180da40b16bb4a46e13a26b7ef40)
diff --git a/src/java/com/android/internal/telephony/imsphone/ImsPhoneCallTracker.java b/src/java/com/android/internal/telephony/imsphone/ImsPhoneCallTracker.java
index db8defb..ac91475 100644
--- a/src/java/com/android/internal/telephony/imsphone/ImsPhoneCallTracker.java
+++ b/src/java/com/android/internal/telephony/imsphone/ImsPhoneCallTracker.java
@@ -871,28 +871,33 @@
         boolean holdBeforeDial = prepareForDialing(dialArgs);
 
         mClirMode = clirMode;
-
+        ImsPhoneConnection pendingConnection;
         synchronized (mSyncHold) {
             mLastDialArgs = dialArgs;
-            mPendingMO = new ImsPhoneConnection(mPhone,
+            pendingConnection = new ImsPhoneConnection(mPhone,
                     participantsToDial, this, mForegroundCall,
                     false);
-            mPendingMO.setVideoState(videoState);
+            // Don't rely on the mPendingMO in this method; if the modem calls back through
+            // onCallProgressing, we'll end up nulling out mPendingMO, which means that
+            // TelephonyConnectionService would treat this call as an MMI code, which it is not,
+            // which would mean that the MMI code dialog would crash.
+            mPendingMO = pendingConnection;
+            pendingConnection.setVideoState(videoState);
             if (dialArgs.rttTextStream != null) {
                 log("startConference: setting RTT stream on mPendingMO");
-                mPendingMO.setCurrentRttTextStream(dialArgs.rttTextStream);
+                pendingConnection.setCurrentRttTextStream(dialArgs.rttTextStream);
             }
         }
-        addConnection(mPendingMO);
+        addConnection(pendingConnection);
 
         if (!holdBeforeDial) {
-            dialInternal(mPendingMO, clirMode, videoState, dialArgs.intentExtras);
+            dialInternal(pendingConnection, clirMode, videoState, dialArgs.intentExtras);
         }
 
         updatePhoneState();
         mPhone.notifyPreciseCallStateChanged();
 
-        return mPendingMO;
+        return pendingConnection;
     }
 
     @UnsupportedAppUsage