Allow enabling and disabling of visual voicemail through settings.
Add switch to enable and disable visual voicemail in voicemail settings.
Bug: 21126480
Change-Id: I878e1128a4a2fe1fbb389b1f93f79d30946815e0
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9b3dee9..e8dac11 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1217,6 +1217,9 @@
<!-- Dialog title for the vibration settings for voice mail notifications [CHAR LIMIT=40]-->
<string name="voicemail_notification_vibarte_when_dialog_title" msgid="8995274609647451109">Vibrate</string>
+ <!-- Visual voicemail on/off title [CHAR LIMIT=40] -->
+ <string name="voicemail_visual_voicemail_switch_title">Visual Voicemail</string>
+
<!-- Voicemail ringtone title. The user clicks on this preference to select
which sound to play when a voicemail notification is received.
[CHAR LIMIT=30] -->
@@ -1282,6 +1285,8 @@
<string name="voicemail_notification_ringtone_key">voicemail_notification_ringtone_key</string>
<!-- DO NOT TRANSLATE. Internal key for a voicemail notification preference. -->
<string name="voicemail_notification_vibrate_key">voicemail_notification_vibrate_key</string>
+ <!-- DO NOT TRANSLATE. Internal key for a visual voicemail preference. -->
+ <string name="voicemail_visual_voicemail_key">voicemail_visual_voicemail_key</string>
<!-- DO NOT TRANSLATE. Internal key for tty mode preference. -->
<string name="tty_mode_key">button_tty_mode_key</string>
<!-- DO NOT TRANSLATE. Internal key for a voicemail notification preference. -->
diff --git a/res/xml/voicemail_settings.xml b/res/xml/voicemail_settings.xml
index a7d5fb4..9334566 100644
--- a/res/xml/voicemail_settings.xml
+++ b/res/xml/voicemail_settings.xml
@@ -60,5 +60,8 @@
android:key="@string/voicemail_notification_vibrate_key"
android:title="@string/voicemail_notification_vibrate_when_title"
android:persistent="true" />
+ <SwitchPreference
+ android:key="@string/voicemail_visual_voicemail_key"
+ android:title="@string/voicemail_visual_voicemail_switch_title" />"
</PreferenceScreen>
diff --git a/src/com/android/phone/settings/VisualVoicemailSettingsUtil.java b/src/com/android/phone/settings/VisualVoicemailSettingsUtil.java
index e3a9307..5dd3166 100644
--- a/src/com/android/phone/settings/VisualVoicemailSettingsUtil.java
+++ b/src/com/android/phone/settings/VisualVoicemailSettingsUtil.java
@@ -20,11 +20,15 @@
import android.preference.PreferenceManager;
import android.telecom.PhoneAccountHandle;
+import com.android.internal.telephony.Phone;
+import com.android.phone.PhoneUtils;
import com.android.phone.vvm.omtp.OmtpConstants;
import com.android.phone.vvm.omtp.sms.StatusMessage;
/**
* Save visual voicemail login values in shared preferences to be retrieved later.
+ * Because a voicemail source is tied 1:1 to a phone account, the phone account handle is used in
+ * the key for each voicemail source and the associated data.
*/
public class VisualVoicemailSettingsUtil {
private static final String VISUAL_VOICEMAIL_SHARED_PREFS_KEY_PREFIX =
@@ -32,6 +36,11 @@
private static final String IS_ENABLED_KEY = "is_enabled";
+ public static void setVisualVoicemailEnabled(Phone phone, boolean isEnabled) {
+ setVisualVoicemailEnabled(phone.getContext(), PhoneUtils.makePstnPhoneAccountHandle(phone),
+ isEnabled);
+ }
+
public static void setVisualVoicemailEnabled(Context context, PhoneAccountHandle phoneAccount,
boolean isEnabled) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@@ -41,17 +50,22 @@
editor.commit();
}
- public static boolean getVisualVoicemailEnabled(Context context,
+ public static boolean isVisualVoicemailEnabled(Context context,
PhoneAccountHandle phoneAccount) {
if (phoneAccount == null) {
return false;
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean(getVisualVoicemailSharedPrefsKey(IS_ENABLED_KEY, phoneAccount),
- true);
+ false);
}
- public static void setSourceCredentialsFromStatusMessage(Context context,
+ public static boolean isVisualVoicemailEnabled(Phone phone) {
+ return isVisualVoicemailEnabled(phone.getContext(),
+ PhoneUtils.makePstnPhoneAccountHandle(phone));
+ }
+
+ public static void setVisualVoicemailCredentialsFromStatusMessage(Context context,
PhoneAccountHandle phoneAccount, StatusMessage message) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
@@ -71,7 +85,7 @@
editor.commit();
}
- public static String getCredentialForSource(Context context, String key,
+ public static String getVisualVoicemailCredentials(Context context, String key,
PhoneAccountHandle phoneAccount) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getString(getVisualVoicemailSharedPrefsKey(key, phoneAccount), null);
diff --git a/src/com/android/phone/settings/VoicemailSettingsActivity.java b/src/com/android/phone/settings/VoicemailSettingsActivity.java
index f017836..7df0c98 100644
--- a/src/com/android/phone/settings/VoicemailSettingsActivity.java
+++ b/src/com/android/phone/settings/VoicemailSettingsActivity.java
@@ -28,7 +28,9 @@
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
+import android.preference.SwitchPreference;
import android.provider.ContactsContract.CommonDataKinds;
+import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.MenuItem;
@@ -40,7 +42,10 @@
import com.android.phone.R;
import com.android.phone.EditPhoneNumberPreference;
import com.android.phone.PhoneGlobals;
+import com.android.phone.PhoneUtils;
import com.android.phone.SubscriptionInfoHelper;
+import com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper;
+import com.android.phone.vvm.omtp.sync.OmtpVvmSourceManager;
import java.util.Collection;
import java.util.HashMap;
@@ -187,12 +192,14 @@
private boolean mForeground;
private Phone mPhone;
private SubscriptionInfoHelper mSubscriptionInfoHelper;
+ private OmtpVvmCarrierConfigHelper mOmtpVvmCarrierConfigHelper;
private EditPhoneNumberPreference mSubMenuVoicemailSettings;
private VoicemailProviderListPreference mVoicemailProviders;
private PreferenceScreen mVoicemailSettings;
private VoicemailRingtonePreference mVoicemailNotificationRingtone;
private CheckBoxPreference mVoicemailNotificationVibrate;
+ private SwitchPreference mVoicemailVisualVoicemail;
//*********************************************************************************************
@@ -212,6 +219,8 @@
mSubscriptionInfoHelper.setActionBarTitle(
getActionBar(), getResources(), R.string.voicemail_settings_with_label);
mPhone = mSubscriptionInfoHelper.getPhone();
+ mOmtpVvmCarrierConfigHelper = new OmtpVvmCarrierConfigHelper(
+ mPhone.getContext(), mPhone.getSubId());
}
@Override
@@ -248,6 +257,18 @@
getResources().getString(R.string.voicemail_notification_vibrate_key));
mVoicemailNotificationVibrate.setOnPreferenceChangeListener(this);
+ mVoicemailVisualVoicemail = (SwitchPreference) findPreference(
+ getResources().getString(R.string.voicemail_visual_voicemail_key));
+ if (TelephonyManager.VVM_TYPE_OMTP.equals(mOmtpVvmCarrierConfigHelper.getVvmType()) ||
+ TelephonyManager.VVM_TYPE_CVVM.equals(mOmtpVvmCarrierConfigHelper.getVvmType())) {
+ mVoicemailVisualVoicemail.setOnPreferenceChangeListener(this);
+ mVoicemailVisualVoicemail.setChecked(
+ VisualVoicemailSettingsUtil.isVisualVoicemailEnabled(mPhone));
+ } else {
+ prefSet.removePreference(mVoicemailVisualVoicemail);
+ }
+
+
updateVMPreferenceWidgets(mVoicemailProviders.getValue());
// check the intent that started this activity and pop up the voicemail
@@ -366,6 +387,15 @@
// TODO: Revert to checking reference after migrating voicemail to its own activity.
VoicemailNotificationSettingsUtil.setVibrationEnabled(
mPhone, Boolean.TRUE.equals(objValue));
+ } else if (preference.getKey().equals(mVoicemailVisualVoicemail.getKey())) {
+ boolean isEnabled = (Boolean) objValue;
+ VisualVoicemailSettingsUtil.setVisualVoicemailEnabled(mPhone, isEnabled);
+ if (isEnabled) {
+ mOmtpVvmCarrierConfigHelper.startActivation();
+ } else {
+ OmtpVvmSourceManager.getInstance(mPhone.getContext()).removeSource(mPhone);
+ mOmtpVvmCarrierConfigHelper.startDeactivation();
+ }
}
// Always let the preference setting proceed.
diff --git a/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java b/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java
index f2df9b1..6fe2059 100644
--- a/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java
+++ b/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java
@@ -34,54 +34,73 @@
*/
public class OmtpVvmCarrierConfigHelper {
private static final String TAG = "OmtpVvmCarrierConfigHelper";
+ private Context mContext;
+ private int mSubId;
+ private PersistableBundle mCarrierConfig;
+ private String mVvmType;
- public static void startActivation(Context context, int subId) {
- OmtpMessageSender messageSender = getMessageSender(context, subId);
+ public OmtpVvmCarrierConfigHelper(Context context, int subId) {
+ mContext = context;
+ mSubId = subId;
+ mCarrierConfig = getCarrierConfig();
+ mVvmType = getVvmType();
+ }
+
+ public String getVvmType() {
+ if (mCarrierConfig == null) {
+ return null;
+ }
+
+ return mCarrierConfig.getString(
+ CarrierConfigManager.STRING_VVM_TYPE, null);
+ }
+
+ public boolean isOmtpVvmType() {
+ return (TelephonyManager.VVM_TYPE_OMTP.equals(mVvmType) ||
+ TelephonyManager.VVM_TYPE_CVVM.equals(mVvmType));
+ }
+
+ public void startActivation() {
+ OmtpMessageSender messageSender = getMessageSender();
if (messageSender != null) {
- Log.i(TAG, "Requesting VVM activation for subId: " + subId);
+ Log.i(TAG, "Requesting VVM activation for subId: " + mSubId);
messageSender.requestVvmActivation(null);
}
}
- public static void startDeactivation(Context context, int subId) {
- OmtpMessageSender messageSender = getMessageSender(context, subId);
+ public void startDeactivation() {
+ OmtpMessageSender messageSender = getMessageSender();
if (messageSender != null) {
- Log.i(TAG, "Requesting VVM deactivation for subId: " + subId);
+ Log.i(TAG, "Requesting VVM deactivation for subId: " + mSubId);
messageSender.requestVvmDeactivation(null);
}
}
- private static OmtpMessageSender getMessageSender(Context context, int subId) {
- if (!SubscriptionManager.isValidSubscriptionId(subId)) {
+ private PersistableBundle getCarrierConfig() {
+ if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
Log.w(TAG, "Invalid subscriptionId or subscriptionId not provided in intent.");
return null;
}
CarrierConfigManager carrierConfigManager = (CarrierConfigManager)
- context.getSystemService(Context.CARRIER_CONFIG_SERVICE);
+ mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
if (carrierConfigManager == null) {
Log.w(TAG, "No carrier config service found.");
return null;
}
- PersistableBundle carrierConfig = carrierConfigManager.getConfigForSubId(subId);
- if (carrierConfig == null) {
+ return carrierConfigManager.getConfigForSubId(mSubId);
+ }
+
+ private OmtpMessageSender getMessageSender() {
+ if (mCarrierConfig == null) {
Log.w(TAG, "Empty carrier config.");
return null;
}
- String vvmType = carrierConfig.getString(
- CarrierConfigManager.STRING_VVM_TYPE, null);
-
- if (!(TelephonyManager.VVM_TYPE_OMTP.equals(vvmType) ||
- TelephonyManager.VVM_TYPE_CVVM.equals(vvmType))) {
- // This is not an OMTP visual voicemail compatible carrier.
- return null;
- }
-
- int applicationPort = carrierConfig.getInt(
+ int applicationPort = mCarrierConfig.getInt(
CarrierConfigManager.INT_VVM_PORT_NUMBER, 0);
- String destinationNumber = carrierConfig.getString(
+ String destinationNumber = mCarrierConfig.getString(
CarrierConfigManager.STRING_VVM_DESTINATION_NUMBER);
if (TextUtils.isEmpty(destinationNumber)) {
Log.w(TAG, "No destination number for this carrier.");
@@ -89,8 +108,8 @@
}
OmtpMessageSender messageSender = null;
- SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
- switch (vvmType) {
+ SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(mSubId);
+ switch (mVvmType) {
case TelephonyManager.VVM_TYPE_OMTP:
messageSender = new OmtpStandardMessageSender(smsManager, (short) applicationPort,
destinationNumber, null, OmtpConstants.PROTOCOL_VERSION1_1, null);
@@ -100,7 +119,7 @@
destinationNumber);
break;
default:
- Log.w(TAG, "Unexpected visual voicemail type: "+vvmType);
+ Log.w(TAG, "Unexpected visual voicemail type: " + mVvmType);
}
return messageSender;
diff --git a/src/com/android/phone/vvm/omtp/SimChangeReceiver.java b/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
index 5284f0c..940f3a0 100644
--- a/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
+++ b/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
@@ -18,13 +18,17 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.telecom.PhoneAccountHandle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
import android.util.Log;
import com.android.internal.telephony.IccCardConstants;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyIntents;
+import com.android.phone.PhoneUtils;
+import com.android.phone.settings.VisualVoicemailSettingsUtil;
import com.android.phone.vvm.omtp.sync.OmtpVvmSourceManager;
/**
@@ -57,7 +61,22 @@
case CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED:
int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
- OmtpVvmCarrierConfigHelper.startActivation(context, subId);
+ OmtpVvmCarrierConfigHelper carrierConfigHelper =
+ new OmtpVvmCarrierConfigHelper(context, subId);
+
+ if (carrierConfigHelper.isOmtpVvmType()) {
+ PhoneAccountHandle phoneAccount = PhoneUtils.makePstnPhoneAccountHandle(
+ SubscriptionManager.getPhoneId(subId));
+
+ if (TelephonyManager.VVM_TYPE_OMTP.equals(carrierConfigHelper.getVvmType())) {
+ carrierConfigHelper.startActivation();
+ VisualVoicemailSettingsUtil.setVisualVoicemailEnabled(
+ context, phoneAccount, true);
+ } else {
+ VisualVoicemailSettingsUtil.setVisualVoicemailEnabled(
+ context, phoneAccount, false);
+ }
+ }
break;
}
}
diff --git a/src/com/android/phone/vvm/omtp/imap/ImapHelper.java b/src/com/android/phone/vvm/omtp/imap/ImapHelper.java
index 3a197fc..684e5f5 100644
--- a/src/com/android/phone/vvm/omtp/imap/ImapHelper.java
+++ b/src/com/android/phone/vvm/omtp/imap/ImapHelper.java
@@ -66,14 +66,14 @@
mPhoneAccount = phoneAccount;
TempDirectory.setTempDirectory(context);
- String username = VisualVoicemailSettingsUtil.getCredentialForSource(context,
+ String username = VisualVoicemailSettingsUtil.getVisualVoicemailCredentials(context,
OmtpConstants.IMAP_USER_NAME, phoneAccount);
- String password = VisualVoicemailSettingsUtil.getCredentialForSource(context,
+ String password = VisualVoicemailSettingsUtil.getVisualVoicemailCredentials(context,
OmtpConstants.IMAP_PASSWORD, phoneAccount);
- String serverName = VisualVoicemailSettingsUtil.getCredentialForSource(context,
+ String serverName = VisualVoicemailSettingsUtil.getVisualVoicemailCredentials(context,
OmtpConstants.SERVER_ADDRESS, phoneAccount);
int port = Integer.parseInt(
- VisualVoicemailSettingsUtil.getCredentialForSource(context,
+ VisualVoicemailSettingsUtil.getVisualVoicemailCredentials(context,
OmtpConstants.IMAP_PORT, phoneAccount));
// TODO: determine the security protocol (e.g. ssl, tls, none, etc.)
mImapStore = new ImapStore(
diff --git a/src/com/android/phone/vvm/omtp/sms/OmtpMessageReceiver.java b/src/com/android/phone/vvm/omtp/sms/OmtpMessageReceiver.java
index 1911f2a..867a14f 100644
--- a/src/com/android/phone/vvm/omtp/sms/OmtpMessageReceiver.java
+++ b/src/com/android/phone/vvm/omtp/sms/OmtpMessageReceiver.java
@@ -48,7 +48,7 @@
mPhoneAccount = PhoneUtils.makePstnPhoneAccountHandle(
intent.getExtras().getInt(PhoneConstants.PHONE_KEY));
- if (!VisualVoicemailSettingsUtil.getVisualVoicemailEnabled(mContext, mPhoneAccount)) {
+ if (!VisualVoicemailSettingsUtil.isVisualVoicemailEnabled(mContext, mPhoneAccount)) {
Log.v(TAG, "Received vvm message for disabled vvm source.");
return;
}
@@ -69,7 +69,7 @@
processSync(message);
} else if (messageData.getPrefix() == OmtpConstants.STATUS_SMS_PREFIX) {
StatusMessage message = new StatusMessage(messageData);
- updateAccount(message);
+ updateSource(message);
} else {
Log.e(TAG, "This should never have happened");
}
@@ -113,7 +113,7 @@
}
}
- private void updateAccount(StatusMessage message) {
+ private void updateSource(StatusMessage message) {
OmtpVvmSourceManager vvmSourceManager =
OmtpVvmSourceManager.getInstance(mContext);
VoicemailContract.Status.setStatus(mContext, mPhoneAccount,
@@ -123,7 +123,7 @@
// Save the IMAP credentials in the corresponding account object so they are
// persistent and can be retrieved.
- VisualVoicemailSettingsUtil.setSourceCredentialsFromStatusMessage(
+ VisualVoicemailSettingsUtil.setVisualVoicemailCredentialsFromStatusMessage(
mContext,
mPhoneAccount,
message);
diff --git a/src/com/android/phone/vvm/omtp/sync/OmtpVvmSourceManager.java b/src/com/android/phone/vvm/omtp/sync/OmtpVvmSourceManager.java
index 9f49c2a..e7a189d 100644
--- a/src/com/android/phone/vvm/omtp/sync/OmtpVvmSourceManager.java
+++ b/src/com/android/phone/vvm/omtp/sync/OmtpVvmSourceManager.java
@@ -22,6 +22,7 @@
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
+import com.android.internal.telephony.Phone;
import com.android.phone.PhoneUtils;
import com.android.phone.settings.VisualVoicemailSettingsUtil;
@@ -30,7 +31,9 @@
import java.util.Set;
/**
- * A singleton class designed to remember the active OMTP visual voicemail sources.
+ * A singleton class designed to remember the active OMTP visual voicemail sources. Because a
+ * voicemail source is tied 1:1 to a phone account, the phone account handle is used as the key
+ * for each voicemail source and the associated data.
*/
public class OmtpVvmSourceManager {
public static final String TAG = "OmtpVvmSourceManager";
@@ -71,22 +74,30 @@
/**
* When a voicemail source is removed, we don't always know which one was removed. Check the
* list of registered phone accounts against the active subscriptions list and remove the
- * inactive accounts.
+ * inactive sources.
*/
public void removeInactiveSources() {
- Set<PhoneAccountHandle> sources = getOmtpVvmSources();
- for (PhoneAccountHandle source : sources) {
- if (!PhoneUtils.isPhoneAccountActive(mSubscriptionManager, source)) {
- VoicemailContract.Status.setStatus(mContext, source,
- VoicemailContract.Status.CONFIGURATION_STATE_NOT_CONFIGURED,
- VoicemailContract.Status.DATA_CHANNEL_STATE_NO_CONNECTION,
- VoicemailContract.Status.NOTIFICATION_CHANNEL_STATE_NO_CONNECTION);
- removePhoneStateListener(source);
- VisualVoicemailSettingsUtil.setVisualVoicemailEnabled(mContext, source, false);
+ Set<PhoneAccountHandle> phoneAccounts = getOmtpVvmSources();
+ for (PhoneAccountHandle phoneAccount : phoneAccounts) {
+ if (!PhoneUtils.isPhoneAccountActive(mSubscriptionManager, phoneAccount)) {
+ removeSource(phoneAccount);
}
}
}
+ public void removeSource(Phone phone) {
+ removeSource(PhoneUtils.makePstnPhoneAccountHandle(phone));
+ }
+
+ public void removeSource(PhoneAccountHandle phoneAccount) {
+ VoicemailContract.Status.setStatus(mContext, phoneAccount,
+ VoicemailContract.Status.CONFIGURATION_STATE_NOT_CONFIGURED,
+ VoicemailContract.Status.DATA_CHANNEL_STATE_NO_CONNECTION,
+ VoicemailContract.Status.NOTIFICATION_CHANNEL_STATE_NO_CONNECTION);
+ removePhoneStateListener(phoneAccount);
+ VisualVoicemailSettingsUtil.setVisualVoicemailEnabled(mContext, phoneAccount, false);
+ }
+
public void addPhoneStateListener(PhoneAccountHandle phoneAccount) {
if (!mPhoneStateListenerMap.containsKey(phoneAccount)) {
VvmPhoneStateListener phoneStateListener = new VvmPhoneStateListener(mContext,
@@ -126,4 +137,4 @@
}
return false;
}
-}
+}
\ No newline at end of file
diff --git a/src/com/android/phone/vvm/omtp/sync/OmtpVvmSyncService.java b/src/com/android/phone/vvm/omtp/sync/OmtpVvmSyncService.java
index b5bd51f..59f5120 100644
--- a/src/com/android/phone/vvm/omtp/sync/OmtpVvmSyncService.java
+++ b/src/com/android/phone/vvm/omtp/sync/OmtpVvmSyncService.java
@@ -93,7 +93,7 @@
}
private void doSync(PhoneAccountHandle phoneAccount, String action) {
- if (!VisualVoicemailSettingsUtil.getVisualVoicemailEnabled(this, phoneAccount)) {
+ if (!VisualVoicemailSettingsUtil.isVisualVoicemailEnabled(this, phoneAccount)) {
Log.v(TAG, "Sync requested for disabled account");
return;
}