Telephony: Voice mail notification related changes
Sukanya Rajkhowa [Fri, 3 Jan 2014 22:00:58 +0000 (14:00 -0800)]
* Separate voice mail notify from SIM/RUIM card

* For GSM store voice mail count in phone memory
irrespective of SIM write result.

* Display voice mail count for GSM

Bug: 17299884

Change-Id: I368bfb98c8798ed1f43bcc330e6d97e8f95f0f54

src/java/com/android/internal/telephony/InboundSmsHandler.java
src/java/com/android/internal/telephony/PhoneBase.java
src/java/com/android/internal/telephony/TelephonyCapabilities.java
src/java/com/android/internal/telephony/cdma/CDMAPhone.java
src/java/com/android/internal/telephony/cdma/CdmaInboundSmsHandler.java
src/java/com/android/internal/telephony/gsm/GSMPhone.java
src/java/com/android/internal/telephony/gsm/GsmInboundSmsHandler.java
src/java/com/android/internal/telephony/uicc/IccRecords.java
src/java/com/android/internal/telephony/uicc/IsimUiccRecords.java
src/java/com/android/internal/telephony/uicc/RuimRecords.java
src/java/com/android/internal/telephony/uicc/SIMRecords.java

index 328780f..525f875 100644 (file)
@@ -29,6 +29,7 @@ import android.content.ContentValues;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.UserInfo;
+import android.content.SharedPreferences;
 import android.database.Cursor;
 import android.database.SQLException;
 import android.net.Uri;
@@ -42,6 +43,7 @@ import android.os.RemoteException;
 import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.os.UserManager;
+import android.preference.PreferenceManager;
 import android.provider.Telephony;
 import android.provider.Telephony.Sms.Intents;
 import android.telephony.Rlog;
@@ -939,6 +941,23 @@ public abstract class InboundSmsHandler extends StateMachine {
         return (PHONE_TYPE_CDMA == activePhone);
     }
 
+    protected void storeVoiceMailCount() {
+        // Store the voice mail count in persistent memory.
+        String imsi = mPhone.getSubscriberId();
+        int mwi = mPhone.getVoiceMessageCount();
+
+        log("Storing Voice Mail Count = " + mwi
+                    + " for mVmCountKey = " + ((PhoneBase)mPhone).VM_COUNT
+                    + " vmId = " + ((PhoneBase)mPhone).VM_ID
+                    + " in preferences.");
+
+        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
+        SharedPreferences.Editor editor = sp.edit();
+        editor.putInt(mPhone.VM_COUNT, mwi);
+        editor.putString(mPhone.VM_ID, imsi);
+        editor.commit();
+    }
+
     /**
      * Handler for an {@link InboundSmsTracker} broadcast. Deletes PDUs from the raw table and
      * logs the broadcast duration (as an error if the other receivers were especially slow).
index 3c7c9af..e0753a4 100644 (file)
@@ -157,6 +157,11 @@ public abstract class PhoneBase extends Handler implements Phone {
     // Key used to read/write current CLIR setting
     public static final String CLIR_KEY = "clir_key";
 
+    // Key used for storing voice mail count
+    public static final String VM_COUNT = "vm_count_key";
+    // Key used to read/write the ID for storing the voice mail
+    public static final String VM_ID = "vm_id_key";
+
     // Key used to read/write "disable DNS server check" pref (used for testing)
     public static final String DNS_SERVER_CHECK_DISABLED_KEY = "dns_server_check_disabled_key";
 
@@ -174,6 +179,7 @@ public abstract class PhoneBase extends Handler implements Phone {
 
     /* Instance Variables */
     public CommandsInterface mCi;
+    private int mVmCount = 0;
     boolean mDnsCheckDisabled;
     public DcTrackerBase mDcTracker;
     boolean mDoesRilSendMultipleCallRing;
@@ -1169,9 +1175,9 @@ public abstract class PhoneBase extends Handler implements Phone {
     }
 
     @Override
+    /** @return true if there are messages waiting, false otherwise. */
     public boolean getMessageWaitingIndicator() {
-        IccRecords r = mIccRecords.get();
-        return (r != null) ? r.getVoiceMessageWaiting() : false;
+        return mVmCount != 0;
     }
 
     @Override
@@ -1372,9 +1378,36 @@ public abstract class PhoneBase extends Handler implements Phone {
     public abstract int getPhoneType();
 
     /** @hide */
+    /** @return number of voicemails */
     @Override
     public int getVoiceMessageCount(){
-        return 0;
+        return mVmCount;
+    }
+
+    /** sets the voice mail count of the phone and notifies listeners. */
+    public void setVoiceMessageCount(int countWaiting) {
+        mVmCount = countWaiting;
+        // notify listeners of voice mail
+        notifyMessageWaitingIndicator();
+    }
+
+    /** gets the voice mail count from preferences */
+    protected int getStoredVoiceMessageCount() {
+        int countVoiceMessages = 0;
+        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
+        String subscriberId = sp.getString(VM_ID, null);
+        String currentSubscriberId = getSubscriberId();
+
+        Rlog.d(LOG_TAG, "Voicemail count retrieval for subscriberId = " + subscriberId +
+                " current subscriberId = " + currentSubscriberId);
+
+        if ((subscriberId != null) && (currentSubscriberId != null)
+                && (currentSubscriberId.equals(subscriberId))) {
+            // get voice mail count from preferences
+            countVoiceMessages = sp.getInt(VM_COUNT, 0);
+            Rlog.d(LOG_TAG, "Voice Mail Count from preference = " + countVoiceMessages);
+        }
+        return countVoiceMessages;
     }
 
     /**
@@ -1724,19 +1757,9 @@ public abstract class PhoneBase extends Handler implements Phone {
         return mCi.getLteOnCdmaMode();
     }
 
-    /**
-     * Sets the SIM voice message waiting indicator records.
-     * @param line GSM Subscriber Profile Number, one-based. Only '1' is supported
-     * @param countWaiting The number of messages waiting, if known. Use
-     *                     -1 to indicate that an unknown number of
-     *                      messages are waiting
-     */
-    @Override
     public void setVoiceMessageWaiting(int line, int countWaiting) {
-        IccRecords r = mIccRecords.get();
-        if (r != null) {
-            r.setVoiceMessageWaiting(line, countWaiting);
-        }
+        // This function should be overridden by class GSMPhone and CDMAPhone.
+        Rlog.e(LOG_TAG, "Error! This function should never be executed, inactive Phone.");
     }
 
     /**
index 2494b2e..b7c68a3 100644 (file)
@@ -73,12 +73,12 @@ public class TelephonyCapabilities {
     }
 
     /**
-     * Return true if the current phone can retrieve the voice message count.
-     *
-     * Currently this is assumed to be true on CDMA phones and false otherwise.
+     * Return true if the current phone supports voice message count.
+     * and the count is available
+     * Both CDMA and GSM phones support voice message count
      */
     public static boolean supportsVoiceMessageCount(Phone phone) {
-        return (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA);
+        return (phone.getVoiceMessageCount() != -1);
     }
 
     /**
index 2a4e694..7e7574e 100644 (file)
@@ -94,7 +94,6 @@ public class CDMAPhone extends PhoneBase {
     // Default Emergency Callback Mode exit timer
     private static final int DEFAULT_ECM_EXIT_TIMER_VALUE = 300000;
 
-    static final String VM_COUNT_CDMA = "vm_count_key_cdma";
     private static final String VM_NUMBER_CDMA = "vm_number_key_cdma";
     private String mVmNumber = null;
 
@@ -457,12 +456,6 @@ public class CDMAPhone extends PhoneBase {
     }
 
     @Override
-    public boolean
-    getMessageWaitingIndicator() {
-        return (getVoiceMessageCount() > 0);
-    }
-
-    @Override
     public List<? extends MmiCode>
     getPendingMmiCodes() {
         return mPendingMmis;
@@ -940,21 +933,9 @@ public class CDMAPhone extends PhoneBase {
         return number;
     }
 
-    /* Returns Number of Voicemails
-     * @hide
-     */
-    @Override
-    public int getVoiceMessageCount() {
-        IccRecords r = mIccRecords.get();
-        int voicemailCount =  (r != null) ? r.getVoiceMessageCount() : 0;
-        // If mRuimRecords.getVoiceMessageCount returns zero, then there is possibility
-        // that phone was power cycled and would have lost the voicemail count.
-        // So get the count from preferences.
-        if (voicemailCount == 0) {
-            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
-            voicemailCount = sp.getInt(VM_COUNT_CDMA + getPhoneId(), 0);
-        }
-        return voicemailCount;
+    // pending voice mail count updated after phone creation
+    private void updateVoiceMail() {
+        setVoiceMessageCount(getStoredVoiceMessageCount());
     }
 
     @Override
@@ -1216,11 +1197,6 @@ public class CDMAPhone extends PhoneBase {
             }
             break;
 
-            case EVENT_ICC_RECORD_EVENTS:
-                ar = (AsyncResult)msg.obj;
-                processIccRecordEvents((Integer)ar.result);
-                break;
-
             case  EVENT_EXIT_EMERGENCY_CALLBACK_RESPONSE:{
                 handleExitEmergencyCallbackMode(msg);
             }
@@ -1232,6 +1208,7 @@ public class CDMAPhone extends PhoneBase {
                 // Notify voicemails.
                 log("notifyMessageWaitingChanged");
                 mNotifier.notifyMessageWaitingChanged(this);
+                updateVoiceMail();
             }
             break;
 
@@ -1272,6 +1249,7 @@ public class CDMAPhone extends PhoneBase {
                 // Notify voicemails.
                 log("notifyMessageWaitingChanged");
                 mNotifier.notifyMessageWaitingChanged(this);
+                updateVoiceMail();
             }
             break;
 
@@ -1332,18 +1310,6 @@ public class CDMAPhone extends PhoneBase {
         }
     }
 
-    private void processIccRecordEvents(int eventCode) {
-        switch (eventCode) {
-            case RuimRecords.EVENT_MWI:
-                notifyMessageWaitingIndicator();
-                break;
-
-            default:
-                Rlog.e(LOG_TAG,"Unknown icc records event code " + eventCode);
-                break;
-        }
-    }
-
     /**
      * Handles the call to get the subscription source
      *
@@ -1751,7 +1717,6 @@ public class CDMAPhone extends PhoneBase {
         if (r == null) {
             return;
         }
-        r.registerForRecordsEvents(this, EVENT_ICC_RECORD_EVENTS, null);
         r.registerForRecordsLoaded(this, EVENT_RUIM_RECORDS_LOADED, null);
     }
 
@@ -1760,10 +1725,22 @@ public class CDMAPhone extends PhoneBase {
         if (r == null) {
             return;
         }
-        r.unregisterForRecordsEvents(this);
         r.unregisterForRecordsLoaded(this);
     }
 
+     /**
+     * Sets the SIM voice message count
+     * @param line Subscriber Profile Number, one-based. Only '1' is supported
+     * @param countWaiting The number of messages waiting, if known. Use
+     *                     -1 to indicate that an unknown number of
+     *                      messages are waiting
+     * This is a wrapper function for setVoiceMessageCount
+     */
+    @Override
+    public void setVoiceMessageWaiting(int line, int countWaiting) {
+        setVoiceMessageCount(countWaiting);
+    }
+
     protected void log(String s) {
         if (DBG)
             Rlog.d(LOG_TAG, s);
index c20e2ac..37db94e 100644 (file)
@@ -18,11 +18,9 @@ package com.android.internal.telephony.cdma;
 
 import android.app.Activity;
 import android.content.Context;
-import android.content.SharedPreferences;
 import android.content.res.Resources;
 import android.os.Message;
 import android.os.SystemProperties;
-import android.preference.PreferenceManager;
 import android.provider.Telephony.Sms.Intents;
 import android.telephony.SmsCbMessage;
 
@@ -252,12 +250,18 @@ public class CdmaInboundSmsHandler extends InboundSmsHandler {
         int voicemailCount = sms.getNumOfVoicemails();
         if (DBG) log("Voicemail count=" + voicemailCount);
 
-        // Store the voicemail count in preferences.
-        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
-        SharedPreferences.Editor editor = sp.edit();
-        editor.putInt(CDMAPhone.VM_COUNT_CDMA + mPhone.getPhoneId(), voicemailCount);
-        editor.apply();
-        mPhone.setVoiceMessageWaiting(1, voicemailCount);
+        // range check
+        if (voicemailCount < 0) {
+            voicemailCount = -1;
+        } else if (voicemailCount > 99) {
+            // C.S0015-B v2, 4.5.12
+            // range: 0-99
+            voicemailCount = 99;
+        }
+        // update voice mail count in phone
+        mPhone.setVoiceMessageCount(voicemailCount);
+        // store voice mail count in preferences
+        storeVoiceMailCount();
     }
 
     /**
index 211d397..8bdfb0a 100644 (file)
@@ -33,6 +33,7 @@ import android.telecom.VideoProfile;
 import android.telephony.CellLocation;
 import android.telephony.PhoneNumberUtils;
 import android.telephony.ServiceState;
+import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
 
 import com.android.ims.ImsManager;
@@ -68,7 +69,6 @@ import com.android.internal.telephony.PhoneNotifier;
 import com.android.internal.telephony.PhoneProxy;
 import com.android.internal.telephony.PhoneSubInfo;
 
-import android.telephony.SubscriptionManager;
 import com.android.internal.telephony.TelephonyProperties;
 import com.android.internal.telephony.UUSInfo;
 import com.android.internal.telephony.imsphone.ImsPhone;
@@ -330,6 +330,23 @@ public class GSMPhone extends PhoneBase {
         return mCT;
     }
 
+    // pending voice mail count updated after phone creation
+    private void updateVoiceMail() {
+        int countVoiceMessages = 0;
+        IccRecords r = mIccRecords.get();
+        if (r != null) {
+            // get voice mail count from SIM
+            countVoiceMessages = r.getVoiceMessageCount();
+        }
+        int countVoiceMessagesStored = getStoredVoiceMessageCount();
+        if (countVoiceMessages == -1 && countVoiceMessagesStored != 0) {
+            countVoiceMessages = countVoiceMessagesStored;
+        }
+        Rlog.d(LOG_TAG, "updateVoiceMail countVoiceMessages = " + countVoiceMessages
+                +" subId "+getSubId());
+        setVoiceMessageCount(countVoiceMessages);
+    }
+
     @Override
     public List<? extends MmiCode>
     getPendingMmiCodes() {
@@ -1415,6 +1432,7 @@ public class GSMPhone extends PhoneBase {
                 }
 
                 mSimRecordsLoadedRegistrants.notifyRegistrants();
+                updateVoiceMail();
             break;
 
             case EVENT_GET_BASEBAND_VERSION_DONE:
@@ -1618,13 +1636,10 @@ public class GSMPhone extends PhoneBase {
             case IccRecords.EVENT_CFI:
                 notifyCallForwardingIndicator();
                 break;
-            case IccRecords.EVENT_MWI:
-                notifyMessageWaitingIndicator();
-                break;
         }
     }
 
-   /**
+    /**
      * Sets the "current" field in the telephony provider according to the SIM's operator
      *
      * @return true for success; false otherwise.
@@ -1865,6 +1880,23 @@ public class GSMPhone extends PhoneBase {
     public void resetSubSpecifics() {
     }
 
+    /**
+     * Sets the SIM voice message waiting indicator records.
+     * @param line GSM Subscriber Profile Number, one-based. Only '1' is supported
+     * @param countWaiting The number of messages waiting, if known. Use
+     *                     -1 to indicate that an unknown number of
+     *                      messages are waiting
+     */
+    @Override
+    public void setVoiceMessageWaiting(int line, int countWaiting) {
+        IccRecords r = mIccRecords.get();
+        if (r != null) {
+            r.setVoiceMessageWaiting(line, countWaiting);
+        } else {
+            log("SIM Records not found, MWI not updated");
+        }
+    }
+
     protected void log(String s) {
         Rlog.d(LOG_TAG, "[GSMPhone] " + s);
     }
index a22b0aa..0db251d 100644 (file)
@@ -27,6 +27,8 @@ import com.android.internal.telephony.PhoneBase;
 import com.android.internal.telephony.SmsConstants;
 import com.android.internal.telephony.SmsMessageBase;
 import com.android.internal.telephony.SmsStorageMonitor;
+import com.android.internal.telephony.uicc.IccRecords;
+import com.android.internal.telephony.uicc.UiccController;
 import com.android.internal.telephony.uicc.UsimServiceTable;
 
 /**
@@ -107,11 +109,11 @@ public class GsmInboundSmsHandler extends InboundSmsHandler {
 
         boolean handled = false;
         if (sms.isMWISetMessage()) {
-            mPhone.setVoiceMessageWaiting(1, sms.getNumOfVoicemails());
+            updateMessageWaitingIndicator(sms.getNumOfVoicemails());
             handled = sms.isMwiDontStore();
             if (DBG) log("Received voice mail indicator set SMS shouldStore=" + !handled);
         } else if (sms.isMWIClearMessage()) {
-            mPhone.setVoiceMessageWaiting(1, 0);   // line 1: no msgs waiting
+            updateMessageWaitingIndicator(0);
             handled = sms.isMwiDontStore();
             if (DBG) log("Received voice mail indicator clear SMS shouldStore=" + !handled);
         }
@@ -129,6 +131,29 @@ public class GsmInboundSmsHandler extends InboundSmsHandler {
         return dispatchNormalMessage(smsb);
     }
 
+    /* package */ void updateMessageWaitingIndicator(int voicemailCount) {
+        // range check
+        if (voicemailCount < 0) {
+            voicemailCount = -1;
+        } else if (voicemailCount > 0xff) {
+            // TS 23.040 9.2.3.24.2
+            // "The value 255 shall be taken to mean 255 or greater"
+            voicemailCount = 0xff;
+        }
+        // update voice mail count in GsmPhone
+        mPhone.setVoiceMessageCount(voicemailCount);
+        // store voice mail count in SIM & shared preferences
+        IccRecords records = UiccController.getInstance().getIccRecords(
+                mPhone.getPhoneId(), UiccController.APP_FAM_3GPP);
+        if (records != null) {
+            log("updateMessageWaitingIndicator: updating SIM Records");
+            records.setVoiceMessageWaiting(1, voicemailCount);
+        } else {
+            log("updateMessageWaitingIndicator: SIM Records not found");
+        }
+        storeVoiceMailCount();
+    }
+
     /**
      * Send an acknowledge message.
      * @param success indicates that last message was successfully received.
index 3697430..1831f4e 100644 (file)
@@ -65,7 +65,6 @@ public abstract class IccRecords extends Handler implements IccConstants {
     protected String mNewVoiceMailNum = null;
     protected String mNewVoiceMailTag = null;
     protected boolean mIsVoiceMailFixed = false;
-    protected int mCountVoiceMessages = 0;
     protected String mImsi;
     private IccIoResult auth_rsp;
 
@@ -122,7 +121,6 @@ public abstract class IccRecords extends Handler implements IccConstants {
                 + " newVoiceMailNum=" + mNewVoiceMailNum
                 + " newVoiceMailTag=" + mNewVoiceMailTag
                 + " isVoiceMailFixed=" + mIsVoiceMailFixed
-                + " countVoiceMessages=" + mCountVoiceMessages
                 + " mImsi=" + mImsi
                 + " mncLength=" + mMncLength
                 + " mailboxIndex=" + mMailboxIndex
@@ -383,19 +381,10 @@ public abstract class IccRecords extends Handler implements IccConstants {
      */
     public abstract void setVoiceMessageWaiting(int line, int countWaiting);
 
-    /** @return  true if there are messages waiting, false otherwise. */
-    public boolean getVoiceMessageWaiting() {
-        return mCountVoiceMessages != 0;
-    }
-
     /**
-     * Returns number of voice messages waiting, if available
-     * If not available (eg, on an older CPHS SIM) -1 is returned if
-     * getVoiceMessageWaiting() is true
+     * Called by GsmPhone to update VoiceMail count
      */
-    public int getVoiceMessageCount() {
-        return mCountVoiceMessages;
-    }
+    public abstract int getVoiceMessageCount();
 
     /**
      * Called by STK Service when REFRESH is received.
@@ -658,7 +647,6 @@ public abstract class IccRecords extends Handler implements IccConstants {
         pw.println(" mNewVoiceMailNum=" + mNewVoiceMailNum);
         pw.println(" mNewVoiceMailTag=" + mNewVoiceMailTag);
         pw.println(" mIsVoiceMailFixed=" + mIsVoiceMailFixed);
-        pw.println(" mCountVoiceMessages=" + mCountVoiceMessages);
         pw.println(" mImsi=" + mImsi);
         pw.println(" mMncLength=" + mMncLength);
         pw.println(" mMailboxIndex=" + mMailboxIndex);
index 9bf4587..c7c1c8f 100644 (file)
@@ -517,4 +517,10 @@ public final class IsimUiccRecords extends IccRecords implements IsimRecords {
         pw.println(" mIsimPcscf"+mIsimPcscf);
         pw.flush();
     }
+
+    @Override
+    public int getVoiceMessageCount() {
+        return 0; // Not applicable to Isim
+    }
+
 }
index 1a591c6..d296f78 100644 (file)
@@ -134,7 +134,6 @@ public final class RuimRecords extends IccRecords {
     }
 
     protected void resetRecords() {
-        mCountVoiceMessages = 0;
         mMncLength = UNINITIALIZED;
         log("setting0 mMncLength" + mMncLength);
         mIccId = null;
@@ -795,22 +794,17 @@ public final class RuimRecords extends IccRecords {
 
     @Override
     public void setVoiceMessageWaiting(int line, int countWaiting) {
-        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;
-        }
-        mCountVoiceMessages = countWaiting;
+        // Will be used in future to store voice mail count in UIM
+        // C.S0023-D_v1.0 does not have a file id in UIM for MWI
+        log("RuimRecords:setVoiceMessageWaiting - NOP for CDMA");
+    }
 
-        mRecordsEventsRegistrants.notifyResult(EVENT_MWI);
+    @Override
+    public int getVoiceMessageCount() {
+        // Will be used in future to retrieve voice mail count for UIM
+        // C.S0023-D_v1.0 does not have a file id in UIM for MWI
+        log("RuimRecords:getVoiceMessageCount - NOP for CDMA");
+        return 0;
     }
 
     private void handleRuimRefresh(IccRefreshResponse refreshResponse) {
index f3cf197..4ca8f08 100644 (file)
@@ -236,7 +236,6 @@ public class SIMRecords extends IccRecords {
         mImsi = null;
         mMsisdn = null;
         mVoiceMailNum = null;
-        mCountVoiceMessages = 0;
         mMncLength = UNINITIALIZED;
         log("setting0 mMncLength" + mMncLength);
         mIccId = null;
@@ -408,26 +407,13 @@ public class SIMRecords extends IccRecords {
             return;
         }
 
-        // range check
-        if (countWaiting < 0) {
-            countWaiting = -1;
-        } else if (countWaiting > 0xff) {
-            // TS 23.040 9.2.3.24.2
-            // "The value 255 shall be taken to mean 255 or greater"
-            countWaiting = 0xff;
-        }
-
-        mCountVoiceMessages = countWaiting;
-
-        mRecordsEventsRegistrants.notifyResult(EVENT_MWI);
-
         try {
             if (mEfMWIS != null) {
                 // TS 51.011 10.3.45
 
                 // lsb of byte 0 is 'voicemail' status
                 mEfMWIS[0] = (byte)((mEfMWIS[0] & 0xfe)
-                                    | (mCountVoiceMessages == 0 ? 0 : 1));
+                                    | (countWaiting == 0 ? 0 : 1));
 
                 // byte 1 is the number of voice messages waiting
                 if (countWaiting < 0) {
@@ -440,14 +426,13 @@ public class SIMRecords extends IccRecords {
 
                 mFh.updateEFLinearFixed(
                     EF_MWIS, 1, mEfMWIS, null,
-                    obtainMessage (EVENT_UPDATE_DONE, EF_MWIS));
+                    obtainMessage (EVENT_UPDATE_DONE, EF_MWIS, 0));
             }
 
             if (mEfCPHS_MWI != null) {
                     // Refer CPHS4_2.WW6 B4.2.3
                 mEfCPHS_MWI[0] = (byte)((mEfCPHS_MWI[0] & 0xf0)
-                            | (mCountVoiceMessages == 0 ? 0x5 : 0xa));
-
+                            | (countWaiting == 0 ? 0x5 : 0xa));
                 mFh.updateEFTransparent(
                     EF_VOICE_MAIL_INDICATOR_CPHS, mEfCPHS_MWI,
                     obtainMessage (EVENT_UPDATE_DONE, EF_VOICE_MAIL_INDICATOR_CPHS));
@@ -463,6 +448,37 @@ public class SIMRecords extends IccRecords {
         return ((data != null) && (data[0] >= 1) && (data[0] <= 4));
     }
 
+    public int getVoiceMessageCount() {
+        boolean voiceMailWaiting = false;
+        int countVoiceMessages = -1;
+        if (mEfMWIS != null) {
+            // Use this data if the EF[MWIS] exists and
+            // has been loaded
+            // Refer TS 51.011 Section 10.3.45 for the content description
+            voiceMailWaiting = ((mEfMWIS[0] & 0x01) != 0);
+            countVoiceMessages = mEfMWIS[1] & 0xff;
+
+            if (voiceMailWaiting && countVoiceMessages == 0) {
+                // Unknown count = -1
+                countVoiceMessages = -1;
+            }
+            if(DBG) log(" VoiceMessageCount from SIM MWIS = " + countVoiceMessages);
+        } else if (mEfCPHS_MWI != null) {
+            // use voice mail count from CPHS
+            int indicator = (int) (mEfCPHS_MWI[0] & 0xf);
+
+            // Refer CPHS4_2.WW6 B4.2.3
+            if (indicator == 0xA) {
+                // Unknown count = -1
+                countVoiceMessages = -1;
+            } else if (indicator == 0x5) {
+                countVoiceMessages = 0;
+            }
+            if(DBG) log(" VoiceMessageCount from SIM CPHS = " + countVoiceMessages);
+        }
+        return countVoiceMessages;
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -779,30 +795,21 @@ public class SIMRecords extends IccRecords {
                 ar = (AsyncResult)msg.obj;
                 data = (byte[])ar.result;
 
+                if(DBG) log("EF_MWIS : " + IccUtils.bytesToHexString(data));
+
                 if (ar.exception != null) {
+                    if(DBG) log("EVENT_GET_MWIS_DONE exception = "
+                            + ar.exception);
                     break;
                 }
 
-                log("EF_MWIS: " + IccUtils.bytesToHexString(data));
-
-                mEfMWIS = data;
-
                 if ((data[0] & 0xff) == 0xff) {
-                    log("Uninitialized record MWIS");
+                    if(DBG) log("SIMRecords: Uninitialized record MWIS");
                     break;
                 }
 
-                // Refer TS 51.011 Section 10.3.45 for the content description
-                boolean voiceMailWaiting = ((data[0] & 0x01) != 0);
-                mCountVoiceMessages = data[1] & 0xff;
-
-                if (voiceMailWaiting && mCountVoiceMessages == 0) {
-                    // Unknown count = -1
-                    mCountVoiceMessages = -1;
-                }
-
-                mRecordsEventsRegistrants.notifyResult(EVENT_MWI);
-            break;
+                mEfMWIS = data;
+                break;
 
             case EVENT_GET_VOICE_MAIL_INDICATOR_CPHS_DONE:
                 isRecordLoadResponse = true;
@@ -810,29 +817,16 @@ public class SIMRecords extends IccRecords {
                 ar = (AsyncResult)msg.obj;
                 data = (byte[])ar.result;
 
+                if(DBG) log("EF_CPHS_MWI: " + IccUtils.bytesToHexString(data));
+
                 if (ar.exception != null) {
+                    if(DBG) log("EVENT_GET_VOICE_MAIL_INDICATOR_CPHS_DONE exception = "
+                            + ar.exception);
                     break;
                 }
 
                 mEfCPHS_MWI = data;
-
-                // Use this data if the EF[MWIS] exists and
-                // has been loaded
-
-                if (mEfMWIS == null) {
-                    int indicator = data[0] & 0xf;
-
-                    // Refer CPHS4_2.WW6 B4.2.3
-                    if (indicator == 0xA) {
-                        // Unknown count = -1
-                        mCountVoiceMessages = -1;
-                    } else if (indicator == 0x5) {
-                        mCountVoiceMessages = 0;
-                    }
-
-                    mRecordsEventsRegistrants.notifyResult(EVENT_MWI);
-                }
-            break;
+                break;
 
             case EVENT_GET_ICCID_DONE:
                 isRecordLoadResponse = true;