diff options
Diffstat (limited to 'java/com/android/voicemail/impl/settings')
-rw-r--r-- | java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java | 5 | ||||
-rw-r--r-- | java/com/android/voicemail/impl/settings/VoicemailSettingsFragment.java | 104 |
2 files changed, 63 insertions, 46 deletions
diff --git a/java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java b/java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java index 7e4a6a7dc..4c95e7783 100644 --- a/java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java +++ b/java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java @@ -18,6 +18,7 @@ package com.android.voicemail.impl.settings; import android.content.Context; import android.telecom.PhoneAccountHandle; import com.android.dialer.common.Assert; +import com.android.voicemail.VoicemailComponent; import com.android.voicemail.impl.OmtpVvmCarrierConfigHelper; import com.android.voicemail.impl.R; import com.android.voicemail.impl.VisualVoicemailPreferences; @@ -27,8 +28,6 @@ import com.android.voicemail.impl.sync.VvmAccountManager; public class VisualVoicemailSettingsUtil { private static final String IS_ENABLED_KEY = "is_enabled"; - // Flag name used for configuration - public static final String ALLOW_VOICEMAIL_ARCHIVE = "allow_voicemail_archive"; public static void setEnabled( Context context, PhoneAccountHandle phoneAccount, boolean isEnabled) { @@ -47,6 +46,8 @@ public class VisualVoicemailSettingsUtil { public static void setArchiveEnabled( Context context, PhoneAccountHandle phoneAccount, boolean isEnabled) { + Assert.checkArgument( + VoicemailComponent.get(context).getVoicemailClient().isVoicemailArchiveAvailable(context)); new VisualVoicemailPreferences(context, phoneAccount) .edit() .putBoolean(context.getString(R.string.voicemail_visual_voicemail_archive_key), isEnabled) diff --git a/java/com/android/voicemail/impl/settings/VoicemailSettingsFragment.java b/java/com/android/voicemail/impl/settings/VoicemailSettingsFragment.java index 2fc08f0ae..716f503ff 100644 --- a/java/com/android/voicemail/impl/settings/VoicemailSettingsFragment.java +++ b/java/com/android/voicemail/impl/settings/VoicemailSettingsFragment.java @@ -23,27 +23,32 @@ import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; import android.preference.SwitchPreference; -import android.telecom.PhoneAccount; +import android.support.annotation.Nullable; import android.telecom.PhoneAccountHandle; -import android.telecom.TelecomManager; import android.telephony.TelephonyManager; -import com.android.dialer.common.ConfigProviderBindings; +import com.android.dialer.common.Assert; import com.android.dialer.logging.Logger; import com.android.dialer.logging.nano.DialerImpression; +import com.android.voicemail.VoicemailClient; +import com.android.voicemail.VoicemailComponent; import com.android.voicemail.impl.OmtpVvmCarrierConfigHelper; import com.android.voicemail.impl.R; import com.android.voicemail.impl.VvmLog; import com.android.voicemail.impl.sync.VvmAccountManager; -/** Fragment for voicemail settings. */ +/** + * Fragment for voicemail settings. Requires {@link VoicemailClient#PARAM_PHONE_ACCOUNT_HANDLE} set + * in arguments. + */ @TargetApi(VERSION_CODES.O) public class VoicemailSettingsFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener, - VoicemailRingtonePreference.VoicemailRingtoneNameChangeListener { + VoicemailRingtonePreference.VoicemailRingtoneNameChangeListener, + VvmAccountManager.Listener { private static final String TAG = "VmSettingsActivity"; - private PhoneAccountHandle phoneAccountHandle; + @Nullable private PhoneAccountHandle phoneAccountHandle; private OmtpVvmCarrierConfigHelper omtpVvmCarrierConfigHelper; private VoicemailRingtonePreference voicemailRingtonePreference; @@ -62,9 +67,7 @@ public class VoicemailSettingsFragment extends PreferenceFragment super.onCreate(icicle); phoneAccountHandle = - getContext() - .getSystemService(TelecomManager.class) - .getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL); + Assert.isNotNull(getArguments().getParcelable(VoicemailClient.PARAM_PHONE_ACCOUNT_HANDLE)); omtpVvmCarrierConfigHelper = new OmtpVvmCarrierConfigHelper(getContext(), phoneAccountHandle); } @@ -73,6 +76,7 @@ public class VoicemailSettingsFragment extends PreferenceFragment public void onResume() { super.onResume(); Logger.get(getContext()).logImpression(DialerImpression.Type.VVM_SETTINGS_VIEWED); + VvmAccountManager.addListener(this); PreferenceScreen preferenceScreen = getPreferenceScreen(); if (preferenceScreen != null) { preferenceScreen.removeAll(); @@ -123,33 +127,38 @@ public class VoicemailSettingsFragment extends PreferenceFragment (SwitchPreference) findPreference(getString(R.string.voicemail_visual_voicemail_archive_key)); - if (!ConfigProviderBindings.get(getContext()) - .getBoolean(VisualVoicemailSettingsUtil.ALLOW_VOICEMAIL_ARCHIVE, true)) { + if (!VoicemailComponent.get(getContext()) + .getVoicemailClient() + .isVoicemailArchiveAvailable(getContext())) { getPreferenceScreen().removePreference(autoArchiveSwitchPreference); } voicemailChangePinPreference = findPreference(getString(R.string.voicemail_change_pin_key)); - Intent changePinIntent = new Intent(new Intent(getContext(), VoicemailChangePinActivity.class)); - changePinIntent.putExtra( - VoicemailChangePinActivity.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle); - - voicemailChangePinPreference.setIntent(changePinIntent); - voicemailChangePinPreference.setOnPreferenceClickListener( - new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - Logger.get(getContext()).logImpression(DialerImpression.Type.VVM_CHANGE_PIN_CLICKED); - // Let the preference handle the click. - return false; - } - }); - if (VoicemailChangePinActivity.isDefaultOldPinSet(getContext(), phoneAccountHandle)) { - voicemailChangePinPreference.setTitle(R.string.voicemail_set_pin_dialog_title); - } else { - voicemailChangePinPreference.setTitle(R.string.voicemail_change_pin_dialog_title); - } if (omtpVvmCarrierConfigHelper.isValid()) { + Assert.isNotNull(phoneAccountHandle); + Intent changePinIntent = + new Intent(new Intent(getContext(), VoicemailChangePinActivity.class)); + changePinIntent.putExtra( + VoicemailChangePinActivity.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle); + + voicemailChangePinPreference.setIntent(changePinIntent); + voicemailChangePinPreference.setOnPreferenceClickListener( + new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Logger.get(getContext()).logImpression(DialerImpression.Type.VVM_CHANGE_PIN_CLICKED); + // Let the preference handle the click. + return false; + } + }); + if (VoicemailChangePinActivity.isDefaultOldPinSet(getContext(), phoneAccountHandle)) { + voicemailChangePinPreference.setTitle(R.string.voicemail_set_pin_preference_title); + } else { + voicemailChangePinPreference.setTitle(R.string.voicemail_change_pin_preference_title); + } + updateChangePin(); + voicemailVisualVoicemail.setOnPreferenceChangeListener(this); voicemailVisualVoicemail.setChecked( VisualVoicemailSettingsUtil.isEnabled(getContext(), phoneAccountHandle)); @@ -159,10 +168,6 @@ public class VoicemailSettingsFragment extends PreferenceFragment getText(R.string.voicemail_visual_voicemail_auto_archive_temporary_disclaimer)); autoArchiveSwitchPreference.setChecked( VisualVoicemailSettingsUtil.isArchiveEnabled(getContext(), phoneAccountHandle)); - - if (!isVisualVoicemailActivated()) { - prefSet.removePreference(voicemailChangePinPreference); - } } else { prefSet.removePreference(voicemailVisualVoicemail); prefSet.removePreference(autoArchiveSwitchPreference); @@ -188,6 +193,7 @@ public class VoicemailSettingsFragment extends PreferenceFragment @Override public void onPause() { + VvmAccountManager.removeListener(this); super.onPause(); } @@ -210,12 +216,7 @@ public class VoicemailSettingsFragment extends PreferenceFragment Logger.get(getContext()).logImpression(DialerImpression.Type.VVM_USER_DISABLED_IN_SETTINGS); } - PreferenceScreen prefSet = getPreferenceScreen(); - if (isVisualVoicemailActivated()) { - prefSet.addPreference(voicemailChangePinPreference); - } else { - prefSet.removePreference(voicemailChangePinPreference); - } + updateChangePin(); } else if (preference.getKey().equals(autoArchiveSwitchPreference.getKey())) { logArchiveToggle((boolean) objValue); VisualVoicemailSettingsUtil.setArchiveEnabled( @@ -230,6 +231,21 @@ public class VoicemailSettingsFragment extends PreferenceFragment return true; } + private void updateChangePin() { + if (!VisualVoicemailSettingsUtil.isEnabled(getContext(), phoneAccountHandle)) { + voicemailChangePinPreference.setSummary( + R.string.voicemail_change_pin_preference_summary_disable); + voicemailChangePinPreference.setEnabled(false); + } else if (!VvmAccountManager.isAccountActivated(getContext(), phoneAccountHandle)) { + voicemailChangePinPreference.setSummary( + R.string.voicemail_change_pin_preference_summary_not_activated); + voicemailChangePinPreference.setEnabled(false); + } else { + voicemailChangePinPreference.setSummary(null); + voicemailChangePinPreference.setEnabled(true); + } + } + private void logArchiveToggle(boolean userTurnedOn) { if (userTurnedOn) { Logger.get(getContext()) @@ -245,10 +261,10 @@ public class VoicemailSettingsFragment extends PreferenceFragment oldRingtoneName = name; } - private boolean isVisualVoicemailActivated() { - if (!VisualVoicemailSettingsUtil.isEnabled(getContext(), phoneAccountHandle)) { - return false; + @Override + public void onActivationStateChanged(PhoneAccountHandle phoneAccountHandle, boolean isActivated) { + if (this.phoneAccountHandle.equals(phoneAccountHandle)) { + updateChangePin(); } - return VvmAccountManager.isAccountActivated(getContext(), phoneAccountHandle); } } |