Fix crash issue when dismiss MMI dialog

Dialing an MMI code will start MMIDialogActivity to show MMI
running dialog. After MMI code is completed, the activity will receive
MMI completed event and dismiss the MMI running dialog. But before
receiving this event, the MMIDialogActivity is already finished. So if
we dismiss the dialog in this case, illegalArgumentException will
happen and phone process crashes.

Change-Id: Icfcb6473e202e2e851fa28d389a8a9a41dd2e396
diff --git a/src/com/android/phone/MMIDialogActivity.java b/src/com/android/phone/MMIDialogActivity.java
index 24179b8..10ec6a3 100644
--- a/src/com/android/phone/MMIDialogActivity.java
+++ b/src/com/android/phone/MMIDialogActivity.java
@@ -69,6 +69,20 @@
         showMMIDialog();
     }
 
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+
+        if (mMMIDialog != null) {
+            mMMIDialog.dismiss();
+            mMMIDialog = null;
+        }
+        if (mHandler != null) {
+            mCM.unregisterForMmiComplete(mHandler);
+            mHandler = null;
+        }
+    }
+
     private void showMMIDialog() {
         final List<? extends MmiCode> codes = mPhone.getPendingMmiCodes();
         if (codes.size() > 0) {
@@ -127,9 +141,11 @@
     private void dismissDialogsAndFinish() {
         if (mMMIDialog != null) {
             mMMIDialog.dismiss();
+            mMMIDialog = null;
         }
         if (mHandler != null) {
             mCM.unregisterForMmiComplete(mHandler);
+            mHandler = null;
         }
         finish();
     }