From ce099c3226b33b43e0dd5d1f24347b14a2223ee1 Mon Sep 17 00:00:00 2001 From: David Krause Date: Mon, 1 Jun 2009 06:51:43 -0500 Subject: frameworks/base: CDMA voicemail support --- .../java/android/telephony/TelephonyManager.java | 15 +++++ .../com/android/internal/telephony/ITelephony.aidl | 2 +- .../com/android/internal/telephony/IccRecords.java | 2 +- .../java/com/android/internal/telephony/Phone.java | 2 +- .../com/android/internal/telephony/PhoneBase.java | 7 ++- .../com/android/internal/telephony/PhoneProxy.java | 4 +- .../android/internal/telephony/cdma/CDMAPhone.java | 70 ++++++++++++++++++---- .../internal/telephony/cdma/CdmaSMSDispatcher.java | 35 +++++------ .../internal/telephony/cdma/SmsMessage.java | 6 ++ .../android/internal/telephony/gsm/GSMPhone.java | 5 -- 10 files changed, 104 insertions(+), 44 deletions(-) diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index a79eb3a..bf5df88 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -612,6 +612,21 @@ public class TelephonyManager { } /** + * Returns the voice mail count. + *

+ * Requires Permission: + * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} + * @hide + */ + public int getVoiceMessageCount() { + try { + return getITelephony().getVoiceMessageCount(); + } catch (RemoteException ex) { + } + return 0; + } + + /** * Retrieves the alphabetic identifier associated with the voice * mail number. *

diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 6e6f64c..d83b135 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -241,7 +241,7 @@ interface ITelephony { /** * Returns the unread count of voicemails */ - int getCountVoiceMessages(); + int getVoiceMessageCount(); } diff --git a/telephony/java/com/android/internal/telephony/IccRecords.java b/telephony/java/com/android/internal/telephony/IccRecords.java index 114094b..ea24c25 100644 --- a/telephony/java/com/android/internal/telephony/IccRecords.java +++ b/telephony/java/com/android/internal/telephony/IccRecords.java @@ -196,7 +196,7 @@ public abstract class IccRecords extends Handler implements IccConstants { * If not available (eg, on an older CPHS SIM) -1 is returned if * getVoiceMessageWaiting() is true */ - public int getCountVoiceMessages() { + public int getVoiceMessageCount() { return countVoiceMessages; } diff --git a/telephony/java/com/android/internal/telephony/Phone.java b/telephony/java/com/android/internal/telephony/Phone.java index cdbfd61..c8d384d 100644 --- a/telephony/java/com/android/internal/telephony/Phone.java +++ b/telephony/java/com/android/internal/telephony/Phone.java @@ -831,7 +831,7 @@ public interface Phone { * Returns unread voicemail count. This count is shown when the voicemail * notification is expanded.

*/ - int getCountVoiceMessages(); + int getVoiceMessageCount(); /** * Returns the alpha tag associated with the voice mail number. diff --git a/telephony/java/com/android/internal/telephony/PhoneBase.java b/telephony/java/com/android/internal/telephony/PhoneBase.java index 0783fe0..a26e729 100644 --- a/telephony/java/com/android/internal/telephony/PhoneBase.java +++ b/telephony/java/com/android/internal/telephony/PhoneBase.java @@ -631,6 +631,11 @@ public abstract class PhoneBase implements Phone { mNotifier.notifyDataActivity(this); } + public void notifyMessageWaitingIndicator() { + // This function is added to send the notification to DefaultPhoneNotifier. + mNotifier.notifyMessageWaitingChanged(this); + } + public void notifyDataConnection(String reason) { mNotifier.notifyDataConnection(this, reason); } @@ -638,7 +643,7 @@ public abstract class PhoneBase implements Phone { public abstract String getPhoneName(); /** @hide */ - public int getCountVoiceMessages(){ + public int getVoiceMessageCount(){ return 0; } diff --git a/telephony/java/com/android/internal/telephony/PhoneProxy.java b/telephony/java/com/android/internal/telephony/PhoneProxy.java index 4bb24dc..5b3c8dd 100644 --- a/telephony/java/com/android/internal/telephony/PhoneProxy.java +++ b/telephony/java/com/android/internal/telephony/PhoneProxy.java @@ -435,8 +435,8 @@ public class PhoneProxy extends Handler implements Phone { } /** @hide */ - public int getCountVoiceMessages(){ - return mActivePhone.getCountVoiceMessages(); + public int getVoiceMessageCount(){ + return mActivePhone.getVoiceMessageCount(); } public String getVoiceMailAlphaTag() { diff --git a/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java b/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java index 9aa7eab..3362de8 100755 --- a/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java +++ b/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java @@ -19,6 +19,7 @@ package com.android.internal.telephony.cdma; import android.app.ActivityManagerNative; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.AsyncResult; import android.os.Handler; import android.os.Looper; @@ -26,6 +27,7 @@ import android.os.Message; import android.os.Registrant; import android.os.RegistrantList; import android.os.SystemProperties; +import android.preference.PreferenceManager; import android.provider.Settings; import android.telephony.CellLocation; import android.telephony.PhoneNumberUtils; @@ -40,6 +42,7 @@ import com.android.internal.telephony.CommandsInterface; import com.android.internal.telephony.Connection; import com.android.internal.telephony.DataConnection; import com.android.internal.telephony.IccCard; +import com.android.internal.telephony.IccException; import com.android.internal.telephony.IccFileHandler; import com.android.internal.telephony.IccPhoneBookInterfaceManager; import com.android.internal.telephony.IccSmsInterfaceManager; @@ -65,6 +68,9 @@ public class CDMAPhone extends PhoneBase { // Default Emergency Callback Mode exit timer private static final int DEFAULT_ECM_EXIT_TIMER_VALUE = 30000; + 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; //***** Instance Variables CdmaCallTracker mCT; @@ -147,6 +153,9 @@ public class CDMAPhone extends PhoneBase { // This is needed to handle phone process crashes String inEcm=SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE, "false"); mIsPhoneInECMState = inEcm.equals("true"); + + // Notify voicemails. + notifier.notifyMessageWaitingChanged(this); } public void dispose() { @@ -300,7 +309,7 @@ public class CDMAPhone extends PhoneBase { public boolean getMessageWaitingIndicator() { - return mRuimRecords.getVoiceMessageWaiting(); + return (getVoiceMessageCount() > 0); } public List @@ -678,22 +687,33 @@ public class CDMAPhone extends PhoneBase { public void setVoiceMailNumber(String alphaTag, String voiceMailNumber, Message onComplete) { - //mSIMRecords.setVoiceMailNumber(alphaTag, voiceMailNumber, onComplete); - //TODO: Where do we have to store this value has to be clarified with QC + Message resp; + mVmNumber = voiceMailNumber; + resp = h.obtainMessage(EVENT_SET_VM_NUMBER_DONE, 0, 0, onComplete); + mRuimRecords.setVoiceMailNumber(alphaTag, mVmNumber, resp); } public String getVoiceMailNumber() { - //TODO: Where can we get this value has to be clarified with QC - //return mSIMRecords.getVoiceMailNumber(); -// throw new RuntimeException(); - return "*86"; + String number = null; + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); + // TODO(Moto): The default value of voicemail number should be read from a system property + number = sp.getString(VM_NUMBER_CDMA, "*86"); + return number; } /* Returns Number of Voicemails * @hide */ - public int getCountVoiceMessages() { - return mRuimRecords.getCountVoiceMessages(); + public int getVoiceMessageCount() { + int voicemailCount = mRuimRecords.getVoiceMessageCount(); + // 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, 0); + } + return voicemailCount; } public String getVoiceMailAlphaTag() { @@ -820,9 +840,10 @@ public class CDMAPhone extends PhoneBase { mRuimRecords.setVoiceMessageWaiting(1, mwi ? -1 : 0); } - public void - notifyMessageWaitingIndicator() { - mNotifier.notifyMessageWaitingChanged(this); + /* This function is overloaded to send number of voicemails instead of sending true/false */ + /*package*/ void + updateMessageWaitingIndicator(int mwi) { + mRuimRecords.setVoiceMessageWaiting(1, mwi); } /** @@ -984,6 +1005,19 @@ public class CDMAPhone extends PhoneBase { } break; + case EVENT_SET_VM_NUMBER_DONE:{ + ar = (AsyncResult)msg.obj; + if (IccException.class.isInstance(ar.exception)) { + storeVoiceMailNumber(mVmNumber); + ar.exception = null; + } + onComplete = (Message) ar.userObj; + if (onComplete != null) { + AsyncResult.forMessage(onComplete, ar.result, ar.exception); + onComplete.sendToTarget(); + } + } + default:{ throw new RuntimeException("unexpected event not handled"); } @@ -1198,4 +1232,16 @@ public class CDMAPhone extends PhoneBase { int defRoamInd = getServiceState().getCdmaDefaultRoamingIndicator(); return mEriManager.getCdmaEriText(roamInd, defRoamInd); } + + /** + * Store the voicemail number in preferences + */ + private void storeVoiceMailNumber(String number) { + // Update the preference value of voicemail number + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); + SharedPreferences.Editor editor = sp.edit(); + editor.putString(VM_NUMBER_CDMA, number); + editor.commit(); + } + } diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java b/telephony/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java index 2b4a700..8a0070d 100644 --- a/telephony/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java +++ b/telephony/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java @@ -20,11 +20,13 @@ package com.android.internal.telephony.cdma; import android.app.Activity; import android.app.PendingIntent; import android.content.ContentValues; +import android.content.SharedPreferences; import android.database.Cursor; import android.database.SQLException; import android.os.AsyncResult; import android.os.Message; import android.provider.Telephony.Sms.Intents; +import android.preference.PreferenceManager; import android.util.Config; import android.util.Log; @@ -83,27 +85,6 @@ final class CdmaSMSDispatcher extends SMSDispatcher { int teleService = sms.getTeleService(); boolean handled = false; - // Teleservices W(E)MT and VMN are handled together: - if ((teleService == SmsEnvelope.TELESERVICE_WMT) - || (teleService == SmsEnvelope.TELESERVICE_WEMT) - || (teleService == SmsEnvelope.TELESERVICE_VMN)) { - // From here on we need decoded BD. - // Special case the message waiting indicator messages - if (sms.isMWISetMessage()) { - mCdmaPhone.updateMessageWaitingIndicator(true); - handled |= sms.isMwiDontStore(); - if (Config.LOGD) { - Log.d(TAG, "Received voice mail indicator set SMS shouldStore=" + !handled); - } - } else if (sms.isMWIClearMessage()) { - mCdmaPhone.updateMessageWaitingIndicator(false); - handled |= sms.isMwiDontStore(); - if (Config.LOGD) { - Log.d(TAG, "Received voice mail indicator clear SMS shouldStore=" + !handled); - } - } - } - if (sms.getUserData() == null) { if (Config.LOGD) { Log.d(TAG, "Received SMS without user data"); @@ -116,6 +97,18 @@ final class CdmaSMSDispatcher extends SMSDispatcher { if (SmsEnvelope.TELESERVICE_WAP == teleService){ processCdmaWapPdu(sms.getUserData(), sms.messageRef, sms.getOriginatingAddress()); return; + } else if (SmsEnvelope.TELESERVICE_VMN == teleService) { + // handling Voicemail + int voicemailCount = sms.getNumOfVoicemails(); + Log.d(TAG, "Voicemail count=" + voicemailCount); + // Store the voicemail count in preferences. + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences( + ((CDMAPhone) mPhone).getContext()); + SharedPreferences.Editor editor = sp.edit(); + editor.putInt(CDMAPhone.VM_COUNT_CDMA, voicemailCount); + editor.commit(); + ((CDMAPhone) mPhone).updateMessageWaitingIndicator(voicemailCount); + return; } /** diff --git a/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java b/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java index 63d2c47..3a92064 100644 --- a/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java +++ b/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java @@ -773,6 +773,12 @@ public class SmsMessage extends SmsMessageBase { return asciiDigit; } + /** This function shall be called to get the number of voicemails. + * @hide + */ + /*package*/ int getNumOfVoicemails() { + return mBearerData.numberOfMessages; + } } diff --git a/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java b/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java index 70d71fc..d1e4b4f 100755 --- a/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java +++ b/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java @@ -448,11 +448,6 @@ public class GSMPhone extends PhoneBase { } public void - notifyMessageWaitingIndicator() { - mNotifier.notifyMessageWaitingChanged(this); - } - - public void notifyCallForwardingIndicator() { mNotifier.notifyCallForwardingChanged(this); } -- cgit v1.1