AI 144706: am: CL 144705 Teleca patch from 03/27/2009, fixes some CDMA issues.
  Original author: wink

Automated import of CL 144706
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 4cd0168..8150a96 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -168,6 +168,11 @@
     <string name="cfTemplateRegisteredTime"><xliff:g id="bearer_service_code">{0}</xliff:g>: Not forwarded</string>
 
     <!-- android.net.http Error strings --> <skip />
+    <!-- Displayed when a feature code (non-phone number) is dialed and completes successfully. -->
+    <string name="fcComplete">Feature code complete.</string>
+    <!-- Displayed when a feature code (non-phone number) is dialed and completes unsuccessfully. -->
+    <string name="fcError">Connection problem or invalid feature code.</string>
+    <!-- android.net.http Error strings --> <skip />
     <!-- Displayed when a web request was successful. -->
     <string name="httpErrorOk">OK</string>
     <!-- Displayed when a web request failed because we don't know the exact reason. -->
diff --git a/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java b/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java
index ef2f548..c139619 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java
@@ -68,7 +68,6 @@
     RuimRecords mRuimRecords;
     RuimCard mRuimCard;
     MyHandler h;
-    ArrayList <FeatureCode> mPendingMMIs = new ArrayList<FeatureCode>();
     RuimPhoneBookInterfaceManager mRuimPhoneBookInterfaceManager;
     RuimSmsInterfaceManager mRuimSmsInterfaceManager;
     PhoneSubInfo mSubInfo;
@@ -245,41 +244,31 @@
         // Need to make sure dialString gets parsed properly
         String newDialString = PhoneNumberUtils.stripSeparators(dialString);
 
-        FeatureCode fc = FeatureCode.newFromDialString(newDialString, this);
-        if (LOCAL_DEBUG) Log.d(LOG_TAG,
-                "dialing w/ fc '" + fc + "'...");
-        // check for feature code
-        if (fc == null) {
-            // check if call in progress
-            if (!mCT.foregroundCall.isIdle()) {
+        if (!mCT.foregroundCall.isIdle()) {
+            FeatureCode fc = FeatureCode.newFromDialString(newDialString, this);
+            if (fc != null) {
+                //mMmiRegistrants.notifyRegistrants(new AsyncResult(null, fc, null));
+                fc.processCode();
+            } else {
                 FeatureCode digits = new FeatureCode(this);
                 // use dial number as poundString
                 digits.poundString = newDialString;
-                mPendingMMIs.add(fc);
-                mMmiRegistrants.notifyRegistrants(new AsyncResult(null, fc, null));
                 digits.processCode();
-                return null;
-            } else {
-                return mCT.dial(newDialString);
             }
-        } else {
-            mPendingMMIs.add(fc);
-            mMmiRegistrants.notifyRegistrants(new AsyncResult(null, fc, null));
-            fc.processCode();
-
-            // FIXME should this return null or something else?
             return null;
+        } else {
+            return mCT.dial(newDialString);
         }
     }
 
+
     public int getSignalStrengthASU() {
         return mSST.rssi == 99 ? -1 : mSST.rssi;
     }
 
     public boolean
     getMessageWaitingIndicator() {
-        Log.e(LOG_TAG, "method getMessageWaitingIndicator is NOT supported in CDMA!");
-        return false;
+        return mRuimRecords.getVoiceMessageWaiting();
     }
 
     public List<? extends MmiCode>
@@ -709,22 +698,23 @@
         mRuimRecords.setVoiceMessageWaiting(1, mwi ? -1 : 0);
     }
 
+    public void
+    notifyMessageWaitingIndicator() {
+        mNotifier.notifyMessageWaitingChanged(this);
+    }
 
     /**
      * Removes the given FC from the pending list and notifies
      * registrants that it is complete.
      * @param fc FC that is done
      */
-    /*package*/ void onMMIDone(FeatureCode fc) {
+    /*package*/ void onFeatureCodeDone(FeatureCode fc) {
         /* Only notify complete if it's on the pending list.
          * Otherwise, it's already been handled (eg, previously canceled).
          * The exception is cancellation of an incoming USSD-REQUEST, which is
          * not on the list.
          */
-        if (mPendingMMIs.remove(fc)) {
-            mMmiCompleteRegistrants.notifyRegistrants(
-                    new AsyncResult(null, fc, null));
-        }
+         mMmiCompleteRegistrants.notifyRegistrants(new AsyncResult(null, fc, null));
     }
 
     //***** Inner Classes
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java
index 84febf3b..ed617ef 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java
@@ -304,7 +304,8 @@
             return trySetupData(Phone.REASON_DATA_ENABLED);
         } else if (!enable) {
             setEnabled(EXTERNAL_NETWORK_DEFAULT_ID, false);
-            return false;
+            cleanUpConnection(true, Phone.REASON_DATA_DISABLED);
+            return true;
         } else // isEnabled && enable
 
         return true;
diff --git a/telephony/java/com/android/internal/telephony/cdma/FeatureCode.java b/telephony/java/com/android/internal/telephony/cdma/FeatureCode.java
index 65b7336..c226b62e 100644
--- a/telephony/java/com/android/internal/telephony/cdma/FeatureCode.java
+++ b/telephony/java/com/android/internal/telephony/cdma/FeatureCode.java
@@ -257,12 +257,12 @@
 
             if (ar.exception != null) {
                 state = State.FAILED;
-                message = context.getText(com.android.internal.R.string.mmiError);
+                message = context.getText(com.android.internal.R.string.fcError);
             } else {
                 state = State.COMPLETE;
-                message = context.getText(com.android.internal.R.string.mmiComplete);
+                message = context.getText(com.android.internal.R.string.fcComplete);
             }
-            phone.onMMIDone(this);
+            phone.onFeatureCodeDone(this);
             break;
         }
     }
@@ -307,6 +307,6 @@
         }
 
         message = sb;
-        phone.onMMIDone(this);
+        phone.onFeatureCodeDone(this);
     }
 }
diff --git a/telephony/java/com/android/internal/telephony/cdma/RuimRecords.java b/telephony/java/com/android/internal/telephony/cdma/RuimRecords.java
index 7776f8b..13408cf 100644
--- a/telephony/java/com/android/internal/telephony/cdma/RuimRecords.java
+++ b/telephony/java/com/android/internal/telephony/cdma/RuimRecords.java
@@ -334,12 +334,27 @@
 
     @Override
     public void setVoiceMessageWaiting(int line, int countWaiting) {
-        Log.i(LOG_TAG, "RuimRecords: setVoiceMessageWaiting not supported.");
+        if (line != 1) {
+            // only profile 1 is supported
+            return;
+        }
+
+        // range check
+        if (countWaiting < 0) {
+            countWaiting = -1;
+        } else if (countWaiting > 0xff) {
+            // C.S0015-B v2, 4.5.12
+            // range: 0-99
+            countWaiting = 0xff;
+        }
+        countVoiceMessages = countWaiting;
+
+        ((CDMAPhone) phone).notifyMessageWaitingIndicator();
     }
 
     private void handleRuimRefresh(int[] result) {
         if (result == null || result.length == 0) {
-	        if (DBG) log("handleRuimRefresh without input");
+            if (DBG) log("handleRuimRefresh without input");
             return;
         }