| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2008 The Android Open Source Project | 
 | 3 |  * | 
 | 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 |  * you may not use this file except in compliance with the License. | 
 | 6 |  * You may obtain a copy of the License at | 
 | 7 |  * | 
 | 8 |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 |  * | 
 | 10 |  * Unless required by applicable law or agreed to in writing, software | 
 | 11 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 |  * See the License for the specific language governing permissions and | 
 | 14 |  * limitations under the License. | 
 | 15 |  */ | 
 | 16 |  | 
 | 17 | package com.android.phone; | 
 | 18 |  | 
 | 19 | import android.app.ActionBar; | 
 | 20 | import android.app.Activity; | 
| Evan Charlton | 1c69683 | 2014-04-15 14:24:23 -0700 | [diff] [blame] | 21 | import android.app.ActivityOptions; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 22 | import android.app.AlertDialog; | 
 | 23 | import android.app.Dialog; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 24 | import android.content.ContentResolver; | 
 | 25 | import android.content.Context; | 
 | 26 | import android.content.DialogInterface; | 
 | 27 | import android.content.Intent; | 
 | 28 | import android.content.SharedPreferences; | 
 | 29 | import android.content.SharedPreferences.Editor; | 
 | 30 | import android.content.pm.ActivityInfo; | 
 | 31 | import android.content.pm.PackageManager; | 
 | 32 | import android.content.pm.ResolveInfo; | 
 | 33 | import android.database.Cursor; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 34 | import android.media.AudioManager; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.os.AsyncResult; | 
 | 36 | import android.os.Bundle; | 
 | 37 | import android.os.Handler; | 
 | 38 | import android.os.Message; | 
 | 39 | import android.os.UserHandle; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 40 | import android.preference.CheckBoxPreference; | 
 | 41 | import android.preference.ListPreference; | 
 | 42 | import android.preference.Preference; | 
 | 43 | import android.preference.PreferenceActivity; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.preference.PreferenceManager; | 
 | 45 | import android.preference.PreferenceScreen; | 
 | 46 | import android.provider.ContactsContract.CommonDataKinds; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 47 | import android.provider.Settings; | 
| Tyler Gunn | 4d45d1c | 2014-09-12 22:17:53 -0700 | [diff] [blame] | 48 | import android.telecom.PhoneAccountHandle; | 
 | 49 | import android.telecom.TelecomManager; | 
| Andrew Lee | 93c345f | 2014-10-27 15:25:07 -0700 | [diff] [blame] | 50 | import android.telephony.TelephonyManager; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.text.TextUtils; | 
 | 52 | import android.util.Log; | 
 | 53 | import android.view.MenuItem; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.widget.ListAdapter; | 
 | 55 |  | 
| Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 56 | import com.android.ims.ImsManager; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import com.android.internal.telephony.CallForwardInfo; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | import com.android.internal.telephony.Phone; | 
 | 59 | import com.android.internal.telephony.PhoneConstants; | 
| Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 60 | import com.android.phone.common.util.SettingsUtil; | 
| Andrew Lee | db2fe56 | 2014-09-03 15:40:43 -0700 | [diff] [blame] | 61 | import com.android.phone.settings.AccountSelectionPreference; | 
| Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 62 | import com.android.phone.settings.CallForwardInfoUtil; | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 63 | import com.android.phone.settings.VoicemailDialogUtil; | 
| Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 64 | import com.android.phone.settings.VoicemailProviderSettings; | 
| Andrew Lee | 88b51e2 | 2014-10-29 15:48:51 -0700 | [diff] [blame] | 65 | import com.android.phone.settings.VoicemailProviderSettingsUtil; | 
| Andrew Lee | 5ed870c | 2014-10-29 11:47:49 -0700 | [diff] [blame] | 66 | import com.android.phone.settings.fdn.FdnSetting; | 
| Sailesh Nepal | 788959e | 2014-07-08 23:36:40 -0700 | [diff] [blame] | 67 | import com.android.services.telephony.sip.SipUtil; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 68 |  | 
| Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 69 | import java.lang.String; | 
| Andrew Lee | f1776d8 | 2014-11-04 14:45:02 -0800 | [diff] [blame] | 70 | import java.util.ArrayList; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 71 | import java.util.Collection; | 
 | 72 | import java.util.HashMap; | 
 | 73 | import java.util.HashSet; | 
 | 74 | import java.util.Iterator; | 
 | 75 | import java.util.List; | 
 | 76 | import java.util.Map; | 
 | 77 |  | 
 | 78 | /** | 
 | 79 |  * Top level "Call settings" UI; see res/xml/call_feature_setting.xml | 
 | 80 |  * | 
| Andrew Lee | ce8ae2a | 2014-09-10 10:41:48 -0700 | [diff] [blame] | 81 |  * This preference screen is the root of the "Call settings" hierarchy available from the Phone | 
 | 82 |  * app; the settings here let you control various features related to phone calls (including | 
 | 83 |  * voicemail settings, the "Respond via SMS" feature, and others.)  It's used only on | 
 | 84 |  * voice-capable phone devices. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 85 |  * | 
 | 86 |  * Note that this activity is part of the package com.android.phone, even | 
 | 87 |  * though you reach it from the "Phone" app (i.e. DialtactsActivity) which | 
 | 88 |  * is from the package com.android.contacts. | 
 | 89 |  * | 
 | 90 |  * For the "Mobile network settings" screen under the main Settings app, | 
 | 91 |  * See {@link MobileNetworkSettings}. | 
 | 92 |  * | 
| Andrew Lee | ce8ae2a | 2014-09-10 10:41:48 -0700 | [diff] [blame] | 93 |  * TODO: Settings should be split into PreferenceFragments where possible (ie. voicemail). | 
| Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 94 |  * | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 95 |  * @see com.android.phone.MobileNetworkSettings | 
 | 96 |  */ | 
 | 97 | public class CallFeaturesSetting extends PreferenceActivity | 
 | 98 |         implements DialogInterface.OnClickListener, | 
| Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 99 |                 Preference.OnPreferenceChangeListener, | 
| Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 100 |                 EditPhoneNumberPreference.OnDialogClosedListener, | 
| Andrew Lee | ce8ae2a | 2014-09-10 10:41:48 -0700 | [diff] [blame] | 101 |                 EditPhoneNumberPreference.GetDefaultNumberListener { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 102 |     private static final String LOG_TAG = "CallFeaturesSetting"; | 
 | 103 |     private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); | 
| Andrew Lee | 77527ac | 2014-10-21 16:57:39 -0700 | [diff] [blame] | 104 |     // STOPSHIP if true. Flag to override behavior default behavior to hide VT setting. | 
 | 105 |     private static final boolean ENABLE_VT_FLAG = false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 106 |  | 
 | 107 |     /** | 
 | 108 |      * Intent action to bring up Voicemail Provider settings. | 
 | 109 |      * | 
 | 110 |      * @see #IGNORE_PROVIDER_EXTRA | 
 | 111 |      */ | 
 | 112 |     public static final String ACTION_ADD_VOICEMAIL = | 
 | 113 |             "com.android.phone.CallFeaturesSetting.ADD_VOICEMAIL"; | 
 | 114 |     // intent action sent by this activity to a voice mail provider | 
 | 115 |     // to trigger its configuration UI | 
 | 116 |     public static final String ACTION_CONFIGURE_VOICEMAIL = | 
 | 117 |             "com.android.phone.CallFeaturesSetting.CONFIGURE_VOICEMAIL"; | 
 | 118 |     // Extra put in the return from VM provider config containing voicemail number to set | 
 | 119 |     public static final String VM_NUMBER_EXTRA = "com.android.phone.VoicemailNumber"; | 
 | 120 |     // Extra put in the return from VM provider config containing call forwarding number to set | 
 | 121 |     public static final String FWD_NUMBER_EXTRA = "com.android.phone.ForwardingNumber"; | 
 | 122 |     // Extra put in the return from VM provider config containing call forwarding number to set | 
 | 123 |     public static final String FWD_NUMBER_TIME_EXTRA = "com.android.phone.ForwardingNumberTime"; | 
 | 124 |     // If the VM provider returns non null value in this extra we will force the user to | 
 | 125 |     // choose another VM provider | 
 | 126 |     public static final String SIGNOUT_EXTRA = "com.android.phone.Signout"; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 127 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 128 |     // Key identifying the default vocie mail provider | 
 | 129 |     public static final String DEFAULT_VM_PROVIDER_KEY = ""; | 
 | 130 |  | 
 | 131 |     /** | 
 | 132 |      * String Extra put into ACTION_ADD_VOICEMAIL call to indicate which provider should be hidden | 
 | 133 |      * in the list of providers presented to the user. This allows a provider which is being | 
 | 134 |      * disabled (e.g. GV user logging out) to force the user to pick some other provider. | 
 | 135 |      */ | 
 | 136 |     public static final String IGNORE_PROVIDER_EXTRA = "com.android.phone.ProviderToIgnore"; | 
 | 137 |  | 
 | 138 |     // string constants | 
 | 139 |     private static final String NUM_PROJECTION[] = {CommonDataKinds.Phone.NUMBER}; | 
 | 140 |  | 
 | 141 |     // String keys for preference lookup | 
 | 142 |     // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!) | 
| Andrew Lee | 97708a4 | 2014-09-25 12:39:07 -0700 | [diff] [blame] | 143 |     private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key"; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 144 |     private static final String BUTTON_VOICEMAIL_KEY = "button_voicemail_key"; | 
 | 145 |     private static final String BUTTON_VOICEMAIL_PROVIDER_KEY = "button_voicemail_provider_key"; | 
 | 146 |     private static final String BUTTON_VOICEMAIL_SETTING_KEY = "button_voicemail_setting_key"; | 
 | 147 |     // New preference key for voicemail notification vibration | 
 | 148 |     /* package */ static final String BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY = | 
 | 149 |             "button_voicemail_notification_vibrate_key"; | 
 | 150 |     // Old preference key for voicemail notification vibration. Used for migration to the new | 
 | 151 |     // preference key only. | 
 | 152 |     /* package */ static final String BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_WHEN_KEY = | 
 | 153 |             "button_voicemail_notification_vibrate_when_key"; | 
 | 154 |     /* package */ static final String BUTTON_VOICEMAIL_NOTIFICATION_RINGTONE_KEY = | 
 | 155 |             "button_voicemail_notification_ringtone_key"; | 
 | 156 |     private static final String BUTTON_FDN_KEY   = "button_fdn_key"; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 157 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 158 |     private static final String BUTTON_DTMF_KEY        = "button_dtmf_settings"; | 
 | 159 |     private static final String BUTTON_RETRY_KEY       = "button_auto_retry_key"; | 
 | 160 |     private static final String BUTTON_TTY_KEY         = "button_tty_mode_key"; | 
 | 161 |     private static final String BUTTON_HAC_KEY         = "button_hac_key"; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 162 |  | 
 | 163 |     private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key"; | 
 | 164 |     private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key"; | 
| Andrew Lee | 2b36ba2 | 2014-11-05 17:08:49 -0800 | [diff] [blame] | 165 |     private static final String CALL_FORWARDING_KEY = "call_forwarding_key"; | 
 | 166 |     private static final String ADDITIONAL_GSM_SETTINGS_KEY = "additional_gsm_call_settings_key"; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 167 |  | 
| Andrew Lee | ce8ae2a | 2014-09-10 10:41:48 -0700 | [diff] [blame] | 168 |     private static final String PHONE_ACCOUNT_SETTINGS_KEY = | 
 | 169 |             "phone_account_settings_preference_screen"; | 
| Andrew Lee | db2fe56 | 2014-09-03 15:40:43 -0700 | [diff] [blame] | 170 |  | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 171 |     private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling"; | 
 | 172 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 173 |     /** Event for Async voicemail change call */ | 
 | 174 |     private static final int EVENT_VOICEMAIL_CHANGED        = 500; | 
 | 175 |     private static final int EVENT_FORWARDING_CHANGED       = 501; | 
 | 176 |     private static final int EVENT_FORWARDING_GET_COMPLETED = 502; | 
 | 177 |  | 
| Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 178 |     private static final int MSG_UPDATE_VOICEMAIL_RINGTONE_SUMMARY = 1; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 179 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 180 |     public static final String HAC_KEY = "HACSetting"; | 
 | 181 |     public static final String HAC_VAL_ON = "ON"; | 
 | 182 |     public static final String HAC_VAL_OFF = "OFF"; | 
 | 183 |  | 
 | 184 |     /** Handle to voicemail pref */ | 
 | 185 |     private static final int VOICEMAIL_PREF_ID = 1; | 
 | 186 |     private static final int VOICEMAIL_PROVIDER_CFG_ID = 2; | 
 | 187 |  | 
 | 188 |     private Phone mPhone; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 189 |     private AudioManager mAudioManager; | 
| Andrew Lee | 88b51e2 | 2014-10-29 15:48:51 -0700 | [diff] [blame] | 190 |     private VoicemailProviderSettingsUtil mVmProviderSettingsUtil; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 191 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 192 |     // voicemail notification vibration string constants | 
 | 193 |     private static final String VOICEMAIL_VIBRATION_ALWAYS = "always"; | 
 | 194 |     private static final String VOICEMAIL_VIBRATION_NEVER = "never"; | 
 | 195 |  | 
| Andrew Lee | 5ed870c | 2014-10-29 11:47:49 -0700 | [diff] [blame] | 196 |     private SubscriptionInfoHelper mSubscriptionInfoHelper; | 
 | 197 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 198 |     private EditPhoneNumberPreference mSubMenuVoicemailSettings; | 
 | 199 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 200 |     /** Whether dialpad plays DTMF tone or not. */ | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 201 |     private CheckBoxPreference mButtonAutoRetry; | 
 | 202 |     private CheckBoxPreference mButtonHAC; | 
 | 203 |     private ListPreference mButtonDTMF; | 
 | 204 |     private ListPreference mButtonTTY; | 
| Andrew Lee | ce8ae2a | 2014-09-10 10:41:48 -0700 | [diff] [blame] | 205 |     private Preference mPhoneAccountSettingsPreference; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 206 |     private ListPreference mVoicemailProviders; | 
| Andrew Lee | 97708a4 | 2014-09-25 12:39:07 -0700 | [diff] [blame] | 207 |     private PreferenceScreen mVoicemailSettingsScreen; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 208 |     private PreferenceScreen mVoicemailSettings; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 209 |     private CheckBoxPreference mVoicemailNotificationVibrate; | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 210 |     private CheckBoxPreference mEnableVideoCalling; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 211 |  | 
 | 212 |     private class VoiceMailProvider { | 
| Andrew Lee | f1776d8 | 2014-11-04 14:45:02 -0800 | [diff] [blame] | 213 |         public String name; | 
 | 214 |         public Intent intent; | 
 | 215 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 216 |         public VoiceMailProvider(String name, Intent intent) { | 
 | 217 |             this.name = name; | 
 | 218 |             this.intent = intent; | 
 | 219 |         } | 
| Andrew Lee | f1776d8 | 2014-11-04 14:45:02 -0800 | [diff] [blame] | 220 |  | 
 | 221 |         public String toString() { | 
 | 222 |             return "[ Name: " + name + ", Intent: " + intent + " ]"; | 
 | 223 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 224 |     } | 
 | 225 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 226 |     /** | 
 | 227 |      * Results of reading forwarding settings | 
 | 228 |      */ | 
 | 229 |     private CallForwardInfo[] mForwardingReadResults = null; | 
 | 230 |  | 
 | 231 |     /** | 
 | 232 |      * Result of forwarding number change. | 
 | 233 |      * Keys are reasons (eg. unconditional forwarding). | 
 | 234 |      */ | 
 | 235 |     private Map<Integer, AsyncResult> mForwardingChangeResults = null; | 
 | 236 |  | 
 | 237 |     /** | 
 | 238 |      * Expected CF read result types. | 
 | 239 |      * This set keeps track of the CF types for which we've issued change | 
 | 240 |      * commands so we can tell when we've received all of the responses. | 
 | 241 |      */ | 
 | 242 |     private Collection<Integer> mExpectedChangeResultReasons = null; | 
 | 243 |  | 
 | 244 |     /** | 
 | 245 |      * Result of vm number change | 
 | 246 |      */ | 
 | 247 |     private AsyncResult mVoicemailChangeResult = null; | 
 | 248 |  | 
 | 249 |     /** | 
 | 250 |      * Previous VM provider setting so we can return to it in case of failure. | 
 | 251 |      */ | 
 | 252 |     private String mPreviousVMProviderKey = null; | 
 | 253 |  | 
 | 254 |     /** | 
 | 255 |      * Id of the dialog being currently shown. | 
 | 256 |      */ | 
 | 257 |     private int mCurrentDialogId = 0; | 
 | 258 |  | 
 | 259 |     /** | 
 | 260 |      * Flag indicating that we are invoking settings for the voicemail provider programmatically | 
 | 261 |      * due to vm provider change. | 
 | 262 |      */ | 
 | 263 |     private boolean mVMProviderSettingsForced = false; | 
 | 264 |  | 
 | 265 |     /** | 
 | 266 |      * Flag indicating that we are making changes to vm or fwd numbers | 
 | 267 |      * due to vm provider change. | 
 | 268 |      */ | 
 | 269 |     private boolean mChangingVMorFwdDueToProviderChange = false; | 
 | 270 |  | 
 | 271 |     /** | 
 | 272 |      * True if we are in the process of vm & fwd number change and vm has already been changed. | 
 | 273 |      * This is used to decide what to do in case of rollback. | 
 | 274 |      */ | 
 | 275 |     private boolean mVMChangeCompletedSuccessfully = false; | 
 | 276 |  | 
 | 277 |     /** | 
 | 278 |      * True if we had full or partial failure setting forwarding numbers and so need to roll them | 
 | 279 |      * back. | 
 | 280 |      */ | 
 | 281 |     private boolean mFwdChangesRequireRollback = false; | 
 | 282 |  | 
 | 283 |     /** | 
 | 284 |      * Id of error msg to display to user once we are done reverting the VM provider to the previous | 
 | 285 |      * one. | 
 | 286 |      */ | 
 | 287 |     private int mVMOrFwdSetError = 0; | 
 | 288 |  | 
 | 289 |     /** | 
 | 290 |      * Data about discovered voice mail settings providers. | 
 | 291 |      * Is populated by querying which activities can handle ACTION_CONFIGURE_VOICEMAIL. | 
 | 292 |      * They key in this map is package name + activity name. | 
 | 293 |      * We always add an entry for the default provider with a key of empty | 
 | 294 |      * string and intent value of null. | 
 | 295 |      * @see #initVoiceMailProviders() | 
 | 296 |      */ | 
 | 297 |     private final Map<String, VoiceMailProvider> mVMProvidersData = | 
 | 298 |             new HashMap<String, VoiceMailProvider>(); | 
 | 299 |  | 
 | 300 |     /** string to hold old voicemail number as it is being updated. */ | 
 | 301 |     private String mOldVmNumber; | 
 | 302 |  | 
 | 303 |     // New call forwarding settings and vm number we will be setting | 
 | 304 |     // Need to save these since before we get to saving we need to asynchronously | 
 | 305 |     // query the existing forwarding settings. | 
 | 306 |     private CallForwardInfo[] mNewFwdSettings; | 
 | 307 |     private String mNewVMNumber; | 
 | 308 |  | 
 | 309 |     private boolean mForeground; | 
 | 310 |  | 
 | 311 |     @Override | 
 | 312 |     public void onPause() { | 
 | 313 |         super.onPause(); | 
 | 314 |         mForeground = false; | 
 | 315 |     } | 
 | 316 |  | 
 | 317 |     /** | 
 | 318 |      * We have to pull current settings from the network for all kinds of | 
 | 319 |      * voicemail providers so we can tell whether we have to update them, | 
 | 320 |      * so use this bit to keep track of whether we're reading settings for the | 
 | 321 |      * default provider and should therefore save them out when done. | 
 | 322 |      */ | 
 | 323 |     private boolean mReadingSettingsForDefaultProvider = false; | 
 | 324 |  | 
| Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 325 |     /** | 
 | 326 |      * Used to indicate that the voicemail preference should be shown. | 
 | 327 |      */ | 
 | 328 |     private boolean mShowVoicemailPreference = false; | 
 | 329 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 330 |     /* | 
 | 331 |      * Click Listeners, handle click based on objects attached to UI. | 
 | 332 |      */ | 
 | 333 |  | 
 | 334 |     // Click listener for all toggle events | 
 | 335 |     @Override | 
 | 336 |     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { | 
 | 337 |         if (preference == mSubMenuVoicemailSettings) { | 
 | 338 |             return true; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 339 |         } else if (preference == mButtonDTMF) { | 
 | 340 |             return true; | 
 | 341 |         } else if (preference == mButtonTTY) { | 
 | 342 |             return true; | 
 | 343 |         } else if (preference == mButtonAutoRetry) { | 
 | 344 |             android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), | 
 | 345 |                     android.provider.Settings.Global.CALL_AUTO_RETRY, | 
 | 346 |                     mButtonAutoRetry.isChecked() ? 1 : 0); | 
 | 347 |             return true; | 
 | 348 |         } else if (preference == mButtonHAC) { | 
 | 349 |             int hac = mButtonHAC.isChecked() ? 1 : 0; | 
 | 350 |             // Update HAC value in Settings database | 
 | 351 |             Settings.System.putInt(mPhone.getContext().getContentResolver(), | 
 | 352 |                     Settings.System.HEARING_AID, hac); | 
 | 353 |  | 
 | 354 |             // Update HAC Value in AudioManager | 
 | 355 |             mAudioManager.setParameter(HAC_KEY, hac != 0 ? HAC_VAL_ON : HAC_VAL_OFF); | 
 | 356 |             return true; | 
 | 357 |         } else if (preference == mVoicemailSettings) { | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 358 |             if (DBG) log("onPreferenceTreeClick: Voicemail Settings Preference is clicked."); | 
 | 359 |  | 
| Yorke Lee | a0f63bf | 2014-10-09 18:27:20 -0700 | [diff] [blame] | 360 |             final Dialog dialog = mVoicemailSettings.getDialog(); | 
 | 361 |             if (dialog != null) { | 
 | 362 |                 dialog.getActionBar().setDisplayHomeAsUpEnabled(false); | 
 | 363 |             } | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 364 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 365 |             if (preference.getIntent() != null) { | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 366 |                 if (DBG) log("Invoking cfg intent " + preference.getIntent().getPackage()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 367 |  | 
 | 368 |                 // onActivityResult() will be responsible for resetting some of variables. | 
 | 369 |                 this.startActivityForResult(preference.getIntent(), VOICEMAIL_PROVIDER_CFG_ID); | 
 | 370 |                 return true; | 
 | 371 |             } else { | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 372 |                 if (DBG) log("onPreferenceTreeClick(). No intent; use default behavior in xml."); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 373 |  | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 374 |                 // onActivityResult() will not be called, so reset variables here. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 375 |                 mPreviousVMProviderKey = DEFAULT_VM_PROVIDER_KEY; | 
 | 376 |                 mVMProviderSettingsForced = false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 377 |                 return false; | 
 | 378 |             } | 
| Andrew Lee | 97708a4 | 2014-09-25 12:39:07 -0700 | [diff] [blame] | 379 |         } else if (preference == mVoicemailSettingsScreen) { | 
| Yorke Lee | a0f63bf | 2014-10-09 18:27:20 -0700 | [diff] [blame] | 380 |             final Dialog dialog = mVoicemailSettingsScreen.getDialog(); | 
 | 381 |             if (dialog != null) { | 
 | 382 |                 dialog.getActionBar().setDisplayHomeAsUpEnabled(false); | 
 | 383 |             } | 
| Andrew Lee | 97708a4 | 2014-09-25 12:39:07 -0700 | [diff] [blame] | 384 |             return false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 385 |         } | 
 | 386 |         return false; | 
 | 387 |     } | 
 | 388 |  | 
 | 389 |     /** | 
 | 390 |      * Implemented to support onPreferenceChangeListener to look for preference | 
 | 391 |      * changes. | 
 | 392 |      * | 
 | 393 |      * @param preference is the preference to be changed | 
 | 394 |      * @param objValue should be the value of the selection, NOT its localized | 
 | 395 |      * display value. | 
 | 396 |      */ | 
 | 397 |     @Override | 
 | 398 |     public boolean onPreferenceChange(Preference preference, Object objValue) { | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 399 |         if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\""); | 
| Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 400 |  | 
 | 401 |         if (preference == mButtonDTMF) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 402 |             int index = mButtonDTMF.findIndexOfValue((String) objValue); | 
 | 403 |             Settings.System.putInt(mPhone.getContext().getContentResolver(), | 
 | 404 |                     Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, index); | 
 | 405 |         } else if (preference == mButtonTTY) { | 
 | 406 |             handleTTYChange(preference, objValue); | 
 | 407 |         } else if (preference == mVoicemailProviders) { | 
 | 408 |             final String newProviderKey = (String) objValue; | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 409 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 410 |             // If previous provider key and the new one is same, we don't need to handle it. | 
 | 411 |             if (mPreviousVMProviderKey.equals(newProviderKey)) { | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 412 |                 if (DBG) log("No change is made to the VM provider setting."); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 413 |                 return true; | 
 | 414 |             } | 
 | 415 |             updateVMPreferenceWidgets(newProviderKey); | 
 | 416 |  | 
| Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 417 |             final VoicemailProviderSettings newProviderSettings = | 
| Andrew Lee | 88b51e2 | 2014-10-29 15:48:51 -0700 | [diff] [blame] | 418 |                     mVmProviderSettingsUtil.load(newProviderKey); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 419 |  | 
| Andrew Lee | 88b51e2 | 2014-10-29 15:48:51 -0700 | [diff] [blame] | 420 |             // If the user switches to a voice mail provider and we have numbers stored for it we | 
 | 421 |             // will automatically change the phone's voice mail and forwarding number to the stored | 
 | 422 |             // ones. Otherwise we will bring up provider's configuration UI. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 423 |             if (newProviderSettings == null) { | 
 | 424 |                 // Force the user into a configuration of the chosen provider | 
 | 425 |                 Log.w(LOG_TAG, "Saved preferences not found - invoking config"); | 
 | 426 |                 mVMProviderSettingsForced = true; | 
 | 427 |                 simulatePreferenceClick(mVoicemailSettings); | 
 | 428 |             } else { | 
 | 429 |                 if (DBG) log("Saved preferences found - switching to them"); | 
 | 430 |                 // Set this flag so if we get a failure we revert to previous provider | 
 | 431 |                 mChangingVMorFwdDueToProviderChange = true; | 
 | 432 |                 saveVoiceMailAndForwardingNumber(newProviderKey, newProviderSettings); | 
 | 433 |             } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 434 |         } else if (preference == mEnableVideoCalling) { | 
| Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 435 |             if (ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())) { | 
 | 436 |                 PhoneGlobals.getInstance().phoneMgr.enableVideoCalling((boolean) objValue); | 
 | 437 |             } else { | 
 | 438 |                 AlertDialog.Builder builder = new AlertDialog.Builder(this); | 
 | 439 |                 DialogInterface.OnClickListener networkSettingsClickListener = | 
 | 440 |                         new Dialog.OnClickListener() { | 
 | 441 |                             @Override | 
 | 442 |                             public void onClick(DialogInterface dialog, int which) { | 
 | 443 |                                 startActivity(new Intent(mPhone.getContext(), | 
 | 444 |                                         com.android.phone.MobileNetworkSettings.class)); | 
 | 445 |                             } | 
 | 446 |                         }; | 
 | 447 |                 builder.setMessage(getResources().getString( | 
 | 448 |                                 R.string.enable_video_calling_dialog_msg)) | 
 | 449 |                         .setNeutralButton(getResources().getString( | 
 | 450 |                                 R.string.enable_video_calling_dialog_settings), | 
 | 451 |                                 networkSettingsClickListener) | 
 | 452 |                         .setPositiveButton(android.R.string.ok, null) | 
 | 453 |                         .show(); | 
 | 454 |                 return false; | 
 | 455 |             } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 456 |         } | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 457 |  | 
 | 458 |         // Always let the preference setting proceed. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 459 |         return true; | 
 | 460 |     } | 
 | 461 |  | 
 | 462 |     @Override | 
 | 463 |     public void onDialogClosed(EditPhoneNumberPreference preference, int buttonClicked) { | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 464 |         if (DBG) log("onDialogClosed: Button clicked is " + buttonClicked); | 
 | 465 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 466 |         if (buttonClicked == DialogInterface.BUTTON_NEGATIVE) { | 
 | 467 |             return; | 
 | 468 |         } | 
 | 469 |  | 
 | 470 |         if (preference == mSubMenuVoicemailSettings) { | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 471 |             VoicemailProviderSettings newSettings = new VoicemailProviderSettings( | 
 | 472 |                     mSubMenuVoicemailSettings.getPhoneNumber(), | 
 | 473 |                     VoicemailProviderSettings.NO_FORWARDING); | 
 | 474 |             saveVoiceMailAndForwardingNumber(getCurrentVoicemailProviderKey(), newSettings); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 475 |         } | 
 | 476 |     } | 
 | 477 |  | 
 | 478 |     /** | 
 | 479 |      * Implemented for EditPhoneNumberPreference.GetDefaultNumberListener. | 
 | 480 |      * This method set the default values for the various | 
 | 481 |      * EditPhoneNumberPreference dialogs. | 
 | 482 |      */ | 
 | 483 |     @Override | 
 | 484 |     public String onGetDefaultNumber(EditPhoneNumberPreference preference) { | 
 | 485 |         if (preference == mSubMenuVoicemailSettings) { | 
 | 486 |             // update the voicemail number field, which takes care of the | 
 | 487 |             // mSubMenuVoicemailSettings itself, so we should return null. | 
 | 488 |             if (DBG) log("updating default for voicemail dialog"); | 
 | 489 |             updateVoiceNumberField(); | 
 | 490 |             return null; | 
 | 491 |         } | 
 | 492 |  | 
 | 493 |         String vmDisplay = mPhone.getVoiceMailNumber(); | 
 | 494 |         if (TextUtils.isEmpty(vmDisplay)) { | 
 | 495 |             // if there is no voicemail number, we just return null to | 
 | 496 |             // indicate no contribution. | 
 | 497 |             return null; | 
 | 498 |         } | 
 | 499 |  | 
 | 500 |         // Return the voicemail number prepended with "VM: " | 
 | 501 |         if (DBG) log("updating default for call forwarding dialogs"); | 
 | 502 |         return getString(R.string.voicemail_abbreviated) + " " + vmDisplay; | 
 | 503 |     } | 
 | 504 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 505 |     private void switchToPreviousVoicemailProvider() { | 
 | 506 |         if (DBG) log("switchToPreviousVoicemailProvider " + mPreviousVMProviderKey); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 507 |  | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 508 |         if (mPreviousVMProviderKey == null) { | 
 | 509 |             return; | 
 | 510 |         } | 
 | 511 |  | 
 | 512 |         if (mVMChangeCompletedSuccessfully || mFwdChangesRequireRollback) { | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 513 |             showDialogIfForeground(VoicemailDialogUtil.VM_REVERTING_DIALOG); | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 514 |             final VoicemailProviderSettings prevSettings = | 
 | 515 |                     mVmProviderSettingsUtil.load(mPreviousVMProviderKey); | 
 | 516 |             if (prevSettings == null) { | 
 | 517 |                 Log.e(LOG_TAG, "VoicemailProviderSettings for the key \"" | 
 | 518 |                         + mPreviousVMProviderKey + "\" is null but should be loaded."); | 
 | 519 |             } | 
 | 520 |  | 
 | 521 |             if (mVMChangeCompletedSuccessfully) { | 
 | 522 |                 mNewVMNumber = prevSettings.getVoicemailNumber(); | 
 | 523 |                 Log.i(LOG_TAG, "VM change is already completed successfully." | 
 | 524 |                         + "Have to revert VM back to " + mNewVMNumber + " again."); | 
 | 525 |                 mPhone.setVoiceMailNumber( | 
 | 526 |                         mPhone.getVoiceMailAlphaTag().toString(), | 
 | 527 |                         mNewVMNumber, | 
 | 528 |                         Message.obtain(mRevertOptionComplete, EVENT_VOICEMAIL_CHANGED)); | 
 | 529 |             } | 
 | 530 |  | 
 | 531 |             if (mFwdChangesRequireRollback) { | 
 | 532 |                 Log.i(LOG_TAG, "Requested to rollback forwarding changes."); | 
 | 533 |  | 
 | 534 |                 final CallForwardInfo[] prevFwdSettings = prevSettings.getForwardingSettings(); | 
 | 535 |                 if (prevFwdSettings != null) { | 
 | 536 |                     Map<Integer, AsyncResult> results = mForwardingChangeResults; | 
 | 537 |                     resetForwardingChangeState(); | 
 | 538 |                     for (int i = 0; i < prevFwdSettings.length; i++) { | 
 | 539 |                         CallForwardInfo fi = prevFwdSettings[i]; | 
 | 540 |                         if (DBG) log("Reverting fwd #: " + i + ": " + fi.toString()); | 
 | 541 |                         // Only revert the settings for which the update succeeded. | 
 | 542 |                         AsyncResult result = results.get(fi.reason); | 
 | 543 |                         if (result != null && result.exception == null) { | 
 | 544 |                             mExpectedChangeResultReasons.add(fi.reason); | 
 | 545 |                             CallForwardInfoUtil.setCallForwardingOption(mPhone, fi, | 
 | 546 |                                     mRevertOptionComplete.obtainMessage( | 
 | 547 |                                             EVENT_FORWARDING_CHANGED, i, 0)); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 548 |                         } | 
 | 549 |                     } | 
 | 550 |                 } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 551 |             } | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 552 |         } else { | 
 | 553 |             if (DBG) log("No need to revert"); | 
 | 554 |             onRevertDone(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 555 |         } | 
 | 556 |     } | 
 | 557 |  | 
 | 558 |     private void onRevertDone() { | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 559 |         if (DBG) log("onRevertDone: Changing provider key back to " + mPreviousVMProviderKey); | 
 | 560 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 561 |         updateVMPreferenceWidgets(mPreviousVMProviderKey); | 
 | 562 |         updateVoiceNumberField(); | 
 | 563 |         if (mVMOrFwdSetError != 0) { | 
| Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 564 |             showDialogIfForeground(mVMOrFwdSetError); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 565 |             mVMOrFwdSetError = 0; | 
 | 566 |         } | 
 | 567 |     } | 
 | 568 |  | 
 | 569 |     @Override | 
 | 570 |     protected void onActivityResult(int requestCode, int resultCode, Intent data) { | 
 | 571 |         if (DBG) { | 
 | 572 |             log("onActivityResult: requestCode: " + requestCode | 
 | 573 |                     + ", resultCode: " + resultCode | 
 | 574 |                     + ", data: " + data); | 
 | 575 |         } | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 576 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 577 |         // there are cases where the contact picker may end up sending us more than one | 
 | 578 |         // request.  We want to ignore the request if we're not in the correct state. | 
 | 579 |         if (requestCode == VOICEMAIL_PROVIDER_CFG_ID) { | 
 | 580 |             boolean failure = false; | 
 | 581 |  | 
 | 582 |             // No matter how the processing of result goes lets clear the flag | 
 | 583 |             if (DBG) log("mVMProviderSettingsForced: " + mVMProviderSettingsForced); | 
 | 584 |             final boolean isVMProviderSettingsForced = mVMProviderSettingsForced; | 
 | 585 |             mVMProviderSettingsForced = false; | 
 | 586 |  | 
 | 587 |             String vmNum = null; | 
 | 588 |             if (resultCode != RESULT_OK) { | 
 | 589 |                 if (DBG) log("onActivityResult: vm provider cfg result not OK."); | 
 | 590 |                 failure = true; | 
 | 591 |             } else { | 
 | 592 |                 if (data == null) { | 
 | 593 |                     if (DBG) log("onActivityResult: vm provider cfg result has no data"); | 
 | 594 |                     failure = true; | 
 | 595 |                 } else { | 
 | 596 |                     if (data.getBooleanExtra(SIGNOUT_EXTRA, false)) { | 
 | 597 |                         if (DBG) log("Provider requested signout"); | 
 | 598 |                         if (isVMProviderSettingsForced) { | 
 | 599 |                             if (DBG) log("Going back to previous provider on signout"); | 
 | 600 |                             switchToPreviousVoicemailProvider(); | 
 | 601 |                         } else { | 
 | 602 |                             final String victim = getCurrentVoicemailProviderKey(); | 
 | 603 |                             if (DBG) log("Relaunching activity and ignoring " + victim); | 
 | 604 |                             Intent i = new Intent(ACTION_ADD_VOICEMAIL); | 
 | 605 |                             i.putExtra(IGNORE_PROVIDER_EXTRA, victim); | 
 | 606 |                             i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | 
 | 607 |                             this.startActivity(i); | 
 | 608 |                         } | 
 | 609 |                         return; | 
 | 610 |                     } | 
 | 611 |                     vmNum = data.getStringExtra(VM_NUMBER_EXTRA); | 
 | 612 |                     if (vmNum == null || vmNum.length() == 0) { | 
 | 613 |                         if (DBG) log("onActivityResult: vm provider cfg result has no vmnum"); | 
 | 614 |                         failure = true; | 
 | 615 |                     } | 
 | 616 |                 } | 
 | 617 |             } | 
 | 618 |             if (failure) { | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 619 |                 if (DBG) log("Failure in return from voicemail provider."); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 620 |                 if (isVMProviderSettingsForced) { | 
 | 621 |                     switchToPreviousVoicemailProvider(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 622 |                 } | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 623 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 624 |                 return; | 
 | 625 |             } | 
 | 626 |             mChangingVMorFwdDueToProviderChange = isVMProviderSettingsForced; | 
 | 627 |             final String fwdNum = data.getStringExtra(FWD_NUMBER_EXTRA); | 
 | 628 |  | 
| Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 629 |             // TODO: It would be nice to load the current network setting for this and | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 630 |             // send it to the provider when it's config is invoked so it can use this as default | 
 | 631 |             final int fwdNumTime = data.getIntExtra(FWD_NUMBER_TIME_EXTRA, 20); | 
 | 632 |  | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 633 |             if (DBG) log("onActivityResult: cfg result has forwarding number " + fwdNum); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 634 |             saveVoiceMailAndForwardingNumber(getCurrentVoicemailProviderKey(), | 
| Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 635 |                     new VoicemailProviderSettings(vmNum, fwdNum, fwdNumTime)); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 636 |             return; | 
 | 637 |         } | 
 | 638 |  | 
 | 639 |         if (requestCode == VOICEMAIL_PREF_ID) { | 
 | 640 |             if (resultCode != RESULT_OK) { | 
 | 641 |                 if (DBG) log("onActivityResult: contact picker result not OK."); | 
 | 642 |                 return; | 
 | 643 |             } | 
 | 644 |  | 
 | 645 |             Cursor cursor = null; | 
 | 646 |             try { | 
 | 647 |                 cursor = getContentResolver().query(data.getData(), | 
 | 648 |                     NUM_PROJECTION, null, null, null); | 
 | 649 |                 if ((cursor == null) || (!cursor.moveToFirst())) { | 
 | 650 |                     if (DBG) log("onActivityResult: bad contact data, no results found."); | 
 | 651 |                     return; | 
 | 652 |                 } | 
 | 653 |                 mSubMenuVoicemailSettings.onPickActivityResult(cursor.getString(0)); | 
 | 654 |                 return; | 
 | 655 |             } finally { | 
 | 656 |                 if (cursor != null) { | 
 | 657 |                     cursor.close(); | 
 | 658 |                 } | 
 | 659 |             } | 
 | 660 |         } | 
 | 661 |  | 
 | 662 |         super.onActivityResult(requestCode, resultCode, data); | 
 | 663 |     } | 
 | 664 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 665 |     /** | 
 | 666 |      * Wrapper around showDialog() that will silently do nothing if we're | 
 | 667 |      * not in the foreground. | 
 | 668 |      * | 
 | 669 |      * This is useful here because most of the dialogs we display from | 
 | 670 |      * this class are triggered by asynchronous events (like | 
 | 671 |      * success/failure messages from the telephony layer) and it's | 
 | 672 |      * possible for those events to come in even after the user has gone | 
 | 673 |      * to a different screen. | 
 | 674 |      */ | 
 | 675 |     // TODO: this is too brittle: it's still easy to accidentally add new | 
 | 676 |     // code here that calls showDialog() directly (which will result in a | 
 | 677 |     // WindowManager$BadTokenException if called after the activity has | 
 | 678 |     // been stopped.) | 
 | 679 |     // | 
 | 680 |     // It would be cleaner to do the "if (mForeground)" check in one | 
 | 681 |     // central place, maybe by using a single Handler for all asynchronous | 
 | 682 |     // events (and have *that* discard events if we're not in the | 
 | 683 |     // foreground.) | 
 | 684 |     // | 
 | 685 |     // Unfortunately it's not that simple, since we sometimes need to do | 
 | 686 |     // actual work to handle these events whether or not we're in the | 
 | 687 |     // foreground (see the Handler code in mSetOptionComplete for | 
 | 688 |     // example.) | 
| Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 689 |     // | 
 | 690 |     // TODO: It's a bit worrisome that we don't do anything in error cases when we're not in the | 
 | 691 |     // foreground. Consider displaying a toast instead. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 692 |     private void showDialogIfForeground(int id) { | 
 | 693 |         if (mForeground) { | 
 | 694 |             showDialog(id); | 
 | 695 |         } | 
 | 696 |     } | 
 | 697 |  | 
 | 698 |     private void dismissDialogSafely(int id) { | 
 | 699 |         try { | 
 | 700 |             dismissDialog(id); | 
 | 701 |         } catch (IllegalArgumentException e) { | 
 | 702 |             // This is expected in the case where we were in the background | 
 | 703 |             // at the time we would normally have shown the dialog, so we didn't | 
 | 704 |             // show it. | 
 | 705 |         } | 
 | 706 |     } | 
 | 707 |  | 
| Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 708 |     private void saveVoiceMailAndForwardingNumber( | 
 | 709 |             String key, VoicemailProviderSettings newSettings) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 710 |         if (DBG) log("saveVoiceMailAndForwardingNumber: " + newSettings.toString()); | 
| Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 711 |         mNewVMNumber = newSettings.getVoicemailNumber(); | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 712 |         mNewVMNumber = (mNewVMNumber == null) ? "" : mNewVMNumber; | 
| Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 713 |         mNewFwdSettings = newSettings.getForwardingSettings(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 714 |  | 
 | 715 |         // No fwd settings on CDMA | 
 | 716 |         if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { | 
 | 717 |             if (DBG) log("ignoring forwarding setting since this is CDMA phone"); | 
| Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 718 |             mNewFwdSettings = VoicemailProviderSettings.NO_FORWARDING; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 719 |         } | 
 | 720 |  | 
| Andrew Lee | e3c1521 | 2014-10-28 13:12:55 -0700 | [diff] [blame] | 721 |         // Throw a warning if the voicemail is the same and we did not change forwarding. | 
| Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 722 |         if (mNewVMNumber.equals(mOldVmNumber) | 
 | 723 |                 && mNewFwdSettings == VoicemailProviderSettings.NO_FORWARDING) { | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 724 |             showDialogIfForeground(VoicemailDialogUtil.VM_NOCHANGE_ERROR_DIALOG); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 725 |             return; | 
 | 726 |         } | 
 | 727 |  | 
| Andrew Lee | 88b51e2 | 2014-10-29 15:48:51 -0700 | [diff] [blame] | 728 |         mVmProviderSettingsUtil.save(key, newSettings); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 729 |         mVMChangeCompletedSuccessfully = false; | 
 | 730 |         mFwdChangesRequireRollback = false; | 
 | 731 |         mVMOrFwdSetError = 0; | 
 | 732 |         if (!key.equals(mPreviousVMProviderKey)) { | 
 | 733 |             mReadingSettingsForDefaultProvider = | 
 | 734 |                     mPreviousVMProviderKey.equals(DEFAULT_VM_PROVIDER_KEY); | 
 | 735 |             if (DBG) log("Reading current forwarding settings"); | 
| Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 736 |             int numSettingsReasons = VoicemailProviderSettings.FORWARDING_SETTINGS_REASONS.length; | 
 | 737 |             mForwardingReadResults = new CallForwardInfo[numSettingsReasons]; | 
 | 738 |             for (int i = 0; i < mForwardingReadResults.length; i++) { | 
 | 739 |                 mPhone.getCallForwardingOption( | 
 | 740 |                         VoicemailProviderSettings.FORWARDING_SETTINGS_REASONS[i], | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 741 |                         mGetOptionComplete.obtainMessage(EVENT_FORWARDING_GET_COMPLETED, i, 0)); | 
 | 742 |             } | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 743 |             showDialogIfForeground(VoicemailDialogUtil.VM_FWD_READING_DIALOG); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 744 |         } else { | 
 | 745 |             saveVoiceMailAndForwardingNumberStage2(); | 
 | 746 |         } | 
 | 747 |     } | 
 | 748 |  | 
 | 749 |     private final Handler mGetOptionComplete = new Handler() { | 
 | 750 |         @Override | 
 | 751 |         public void handleMessage(Message msg) { | 
 | 752 |             AsyncResult result = (AsyncResult) msg.obj; | 
 | 753 |             switch (msg.what) { | 
 | 754 |                 case EVENT_FORWARDING_GET_COMPLETED: | 
 | 755 |                     handleForwardingSettingsReadResult(result, msg.arg1); | 
 | 756 |                     break; | 
 | 757 |             } | 
 | 758 |         } | 
 | 759 |     }; | 
 | 760 |  | 
 | 761 |     private void handleForwardingSettingsReadResult(AsyncResult ar, int idx) { | 
 | 762 |         if (DBG) Log.d(LOG_TAG, "handleForwardingSettingsReadResult: " + idx); | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 763 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 764 |         Throwable error = null; | 
 | 765 |         if (ar.exception != null) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 766 |             error = ar.exception; | 
| Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 767 |             if (DBG) Log.d(LOG_TAG, "FwdRead: ar.exception=" + error.getMessage()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 768 |         } | 
 | 769 |         if (ar.userObj instanceof Throwable) { | 
| Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 770 |             error = (Throwable) ar.userObj; | 
 | 771 |             if (DBG) Log.d(LOG_TAG, "FwdRead: userObj=" + error.getMessage()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 772 |         } | 
 | 773 |  | 
 | 774 |         // We may have already gotten an error and decided to ignore the other results. | 
 | 775 |         if (mForwardingReadResults == null) { | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 776 |             if (DBG) Log.d(LOG_TAG, "Ignoring fwd reading result: " + idx); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 777 |             return; | 
 | 778 |         } | 
 | 779 |  | 
 | 780 |         // In case of error ignore other results, show an error dialog | 
 | 781 |         if (error != null) { | 
 | 782 |             if (DBG) Log.d(LOG_TAG, "Error discovered for fwd read : " + idx); | 
 | 783 |             mForwardingReadResults = null; | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 784 |             dismissDialogSafely(VoicemailDialogUtil.VM_FWD_READING_DIALOG); | 
 | 785 |             showDialogIfForeground(VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 786 |             return; | 
 | 787 |         } | 
 | 788 |  | 
| Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 789 |         // Get the forwarding info. | 
 | 790 |         mForwardingReadResults[idx] = CallForwardInfoUtil.getCallForwardInfo( | 
 | 791 |                 (CallForwardInfo[]) ar.result, | 
 | 792 |                 VoicemailProviderSettings.FORWARDING_SETTINGS_REASONS[idx]); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 793 |  | 
 | 794 |         // Check if we got all the results already | 
 | 795 |         boolean done = true; | 
 | 796 |         for (int i = 0; i < mForwardingReadResults.length; i++) { | 
 | 797 |             if (mForwardingReadResults[i] == null) { | 
 | 798 |                 done = false; | 
 | 799 |                 break; | 
 | 800 |             } | 
 | 801 |         } | 
| Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 802 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 803 |         if (done) { | 
 | 804 |             if (DBG) Log.d(LOG_TAG, "Done receiving fwd info"); | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 805 |             dismissDialogSafely(VoicemailDialogUtil.VM_FWD_READING_DIALOG); | 
| Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 806 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 807 |             if (mReadingSettingsForDefaultProvider) { | 
| Andrew Lee | 88b51e2 | 2014-10-29 15:48:51 -0700 | [diff] [blame] | 808 |                 mVmProviderSettingsUtil.save(DEFAULT_VM_PROVIDER_KEY, | 
 | 809 |                         new VoicemailProviderSettings(this.mOldVmNumber, mForwardingReadResults)); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 810 |                 mReadingSettingsForDefaultProvider = false; | 
 | 811 |             } | 
 | 812 |             saveVoiceMailAndForwardingNumberStage2(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 813 |         } | 
 | 814 |     } | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 815 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 816 |     private void resetForwardingChangeState() { | 
 | 817 |         mForwardingChangeResults = new HashMap<Integer, AsyncResult>(); | 
 | 818 |         mExpectedChangeResultReasons = new HashSet<Integer>(); | 
 | 819 |     } | 
 | 820 |  | 
 | 821 |     // Called after we are done saving the previous forwarding settings if | 
 | 822 |     // we needed. | 
 | 823 |     private void saveVoiceMailAndForwardingNumberStage2() { | 
 | 824 |         mForwardingChangeResults = null; | 
 | 825 |         mVoicemailChangeResult = null; | 
| Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 826 |         if (mNewFwdSettings != VoicemailProviderSettings.NO_FORWARDING) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 827 |             resetForwardingChangeState(); | 
 | 828 |             for (int i = 0; i < mNewFwdSettings.length; i++) { | 
 | 829 |                 CallForwardInfo fi = mNewFwdSettings[i]; | 
| Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 830 |                 CallForwardInfo fiForReason = | 
 | 831 |                         CallForwardInfoUtil.infoForReason(mForwardingReadResults, fi.reason); | 
 | 832 |                 final boolean doUpdate = CallForwardInfoUtil.isUpdateRequired(fiForReason, fi); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 833 |  | 
 | 834 |                 if (doUpdate) { | 
 | 835 |                     if (DBG) log("Setting fwd #: " + i + ": " + fi.toString()); | 
 | 836 |                     mExpectedChangeResultReasons.add(i); | 
 | 837 |  | 
| Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 838 |                     CallForwardInfoUtil.setCallForwardingOption(mPhone, fi, | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 839 |                             mSetOptionComplete.obtainMessage( | 
 | 840 |                                     EVENT_FORWARDING_CHANGED, fi.reason, 0)); | 
 | 841 |                 } | 
 | 842 |             } | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 843 |             showDialogIfForeground(VoicemailDialogUtil.VM_FWD_SAVING_DIALOG); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 844 |         } else { | 
 | 845 |             if (DBG) log("Not touching fwd #"); | 
 | 846 |             setVMNumberWithCarrier(); | 
 | 847 |         } | 
 | 848 |     } | 
 | 849 |  | 
 | 850 |     private void setVMNumberWithCarrier() { | 
 | 851 |         if (DBG) log("save voicemail #: " + mNewVMNumber); | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 852 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 853 |         mPhone.setVoiceMailNumber( | 
 | 854 |                 mPhone.getVoiceMailAlphaTag().toString(), | 
 | 855 |                 mNewVMNumber, | 
 | 856 |                 Message.obtain(mSetOptionComplete, EVENT_VOICEMAIL_CHANGED)); | 
 | 857 |     } | 
 | 858 |  | 
 | 859 |     /** | 
 | 860 |      * Callback to handle option update completions | 
 | 861 |      */ | 
 | 862 |     private final Handler mSetOptionComplete = new Handler() { | 
 | 863 |         @Override | 
 | 864 |         public void handleMessage(Message msg) { | 
 | 865 |             AsyncResult result = (AsyncResult) msg.obj; | 
 | 866 |             boolean done = false; | 
 | 867 |             switch (msg.what) { | 
 | 868 |                 case EVENT_VOICEMAIL_CHANGED: | 
 | 869 |                     mVoicemailChangeResult = result; | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 870 |                     mVMChangeCompletedSuccessfully = isVmChangeSuccess(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 871 |                     done = true; | 
 | 872 |                     break; | 
 | 873 |                 case EVENT_FORWARDING_CHANGED: | 
 | 874 |                     mForwardingChangeResults.put(msg.arg1, result); | 
 | 875 |                     if (result.exception != null) { | 
 | 876 |                         Log.w(LOG_TAG, "Error in setting fwd# " + msg.arg1 + ": " + | 
 | 877 |                                 result.exception.getMessage()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 878 |                     } | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 879 |                     if (isForwardingCompleted()) { | 
 | 880 |                         if (isFwdChangeSuccess()) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 881 |                             if (DBG) log("Overall fwd changes completed ok, starting vm change"); | 
 | 882 |                             setVMNumberWithCarrier(); | 
 | 883 |                         } else { | 
 | 884 |                             Log.w(LOG_TAG, "Overall fwd changes completed in failure. " + | 
 | 885 |                                     "Check if we need to try rollback for some settings."); | 
 | 886 |                             mFwdChangesRequireRollback = false; | 
 | 887 |                             Iterator<Map.Entry<Integer,AsyncResult>> it = | 
 | 888 |                                 mForwardingChangeResults.entrySet().iterator(); | 
 | 889 |                             while (it.hasNext()) { | 
 | 890 |                                 Map.Entry<Integer,AsyncResult> entry = it.next(); | 
 | 891 |                                 if (entry.getValue().exception == null) { | 
 | 892 |                                     // If at least one succeeded we have to revert | 
 | 893 |                                     Log.i(LOG_TAG, "Rollback will be required"); | 
 | 894 |                                     mFwdChangesRequireRollback = true; | 
 | 895 |                                     break; | 
 | 896 |                                 } | 
 | 897 |                             } | 
 | 898 |                             if (!mFwdChangesRequireRollback) { | 
 | 899 |                                 Log.i(LOG_TAG, "No rollback needed."); | 
 | 900 |                             } | 
 | 901 |                             done = true; | 
 | 902 |                         } | 
 | 903 |                     } | 
 | 904 |                     break; | 
 | 905 |                 default: | 
 | 906 |                     // TODO: should never reach this, may want to throw exception | 
 | 907 |             } | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 908 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 909 |             if (done) { | 
 | 910 |                 if (DBG) log("All VM provider related changes done"); | 
 | 911 |                 if (mForwardingChangeResults != null) { | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 912 |                     dismissDialogSafely(VoicemailDialogUtil.VM_FWD_SAVING_DIALOG); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 913 |                 } | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 914 |                 handleSetVmOrFwdMessage(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 915 |             } | 
 | 916 |         } | 
 | 917 |     }; | 
 | 918 |  | 
 | 919 |     /** | 
 | 920 |      * Callback to handle option revert completions | 
 | 921 |      */ | 
 | 922 |     private final Handler mRevertOptionComplete = new Handler() { | 
 | 923 |         @Override | 
 | 924 |         public void handleMessage(Message msg) { | 
 | 925 |             AsyncResult result = (AsyncResult) msg.obj; | 
 | 926 |             switch (msg.what) { | 
 | 927 |                 case EVENT_VOICEMAIL_CHANGED: | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 928 |                     if (DBG) log("VM revert complete msg"); | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 929 |                     mVoicemailChangeResult = result; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 930 |                     break; | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 931 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 932 |                 case EVENT_FORWARDING_CHANGED: | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 933 |                     if (DBG) log("FWD revert complete msg "); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 934 |                     mForwardingChangeResults.put(msg.arg1, result); | 
 | 935 |                     if (result.exception != null) { | 
 | 936 |                         if (DBG) log("Error in reverting fwd# " + msg.arg1 + ": " + | 
 | 937 |                                 result.exception.getMessage()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 938 |                     } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 939 |                     break; | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 940 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 941 |                 default: | 
 | 942 |                     // TODO: should never reach this, may want to throw exception | 
 | 943 |             } | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 944 |  | 
 | 945 |             final boolean done = (!mVMChangeCompletedSuccessfully || mVoicemailChangeResult != null) | 
 | 946 |                     && (!mFwdChangesRequireRollback || isForwardingCompleted()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 947 |             if (done) { | 
 | 948 |                 if (DBG) log("All VM reverts done"); | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 949 |                 dismissDialogSafely(VoicemailDialogUtil.VM_REVERTING_DIALOG); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 950 |                 onRevertDone(); | 
 | 951 |             } | 
 | 952 |         } | 
 | 953 |     }; | 
 | 954 |  | 
 | 955 |     /** | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 956 |      * Return true if there is a change result for every reason for which we expect a result. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 957 |      */ | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 958 |     private boolean isForwardingCompleted() { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 959 |         if (mForwardingChangeResults == null) { | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 960 |             return true; | 
 | 961 |         } | 
 | 962 |  | 
 | 963 |         for (Integer reason : mExpectedChangeResultReasons) { | 
 | 964 |             if (mForwardingChangeResults.get(reason) == null) { | 
 | 965 |                 return false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 966 |             } | 
 | 967 |         } | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 968 |  | 
 | 969 |         return true; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 970 |     } | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 971 |  | 
 | 972 |     private boolean isFwdChangeSuccess() { | 
 | 973 |         if (mForwardingChangeResults == null) { | 
 | 974 |             return true; | 
 | 975 |         } | 
 | 976 |  | 
 | 977 |         for (AsyncResult result : mForwardingChangeResults.values()) { | 
 | 978 |             Throwable exception = result.exception; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 979 |             if (exception != null) { | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 980 |                 String msg = exception.getMessage(); | 
 | 981 |                 msg = (msg != null) ? msg : ""; | 
 | 982 |                 Log.w(LOG_TAG, "Failed to change forwarding setting. Reason: " + msg); | 
 | 983 |                 return false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 984 |             } | 
 | 985 |         } | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 986 |         return true; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 987 |     } | 
 | 988 |  | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 989 |     private boolean isVmChangeSuccess() { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 990 |         if (mVoicemailChangeResult.exception != null) { | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 991 |             String msg = mVoicemailChangeResult.exception.getMessage(); | 
 | 992 |             msg = (msg != null) ? msg : ""; | 
 | 993 |             Log.w(LOG_TAG, "Failed to change voicemail. Reason: " + msg); | 
 | 994 |             return false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 995 |         } | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 996 |         return true; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 997 |     } | 
 | 998 |  | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 999 |     private void handleSetVmOrFwdMessage() { | 
 | 1000 |         if (DBG) log("handleSetVMMessage: set VM request complete"); | 
 | 1001 |  | 
 | 1002 |         if (!isFwdChangeSuccess()) { | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 1003 |             handleVmOrFwdSetError(VoicemailDialogUtil.FWD_SET_RESPONSE_ERROR_DIALOG); | 
| Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 1004 |         } else if (!isVmChangeSuccess()) { | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 1005 |             handleVmOrFwdSetError(VoicemailDialogUtil.VM_RESPONSE_ERROR_DIALOG); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1006 |         } else { | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 1007 |             handleVmAndFwdSetSuccess(VoicemailDialogUtil.VM_CONFIRM_DIALOG); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1008 |         } | 
 | 1009 |     } | 
 | 1010 |  | 
 | 1011 |     /** | 
 | 1012 |      * Called when Voicemail Provider or its forwarding settings failed. Rolls back partly made | 
 | 1013 |      * changes to those settings and show "failure" dialog. | 
 | 1014 |      * | 
| Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 1015 |      * @param dialogId ID of the dialog to show for the specific error case. Either | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 1016 |      *     {@link #FWD_SET_RESPONSE_ERROR_DIALOG} or {@link #VM_RESPONSE_ERROR_DIALOG} | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1017 |      */ | 
| Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 1018 |     private void handleVmOrFwdSetError(int dialogId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1019 |         if (mChangingVMorFwdDueToProviderChange) { | 
| Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 1020 |             mVMOrFwdSetError = dialogId; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1021 |             mChangingVMorFwdDueToProviderChange = false; | 
 | 1022 |             switchToPreviousVoicemailProvider(); | 
 | 1023 |             return; | 
 | 1024 |         } | 
 | 1025 |         mChangingVMorFwdDueToProviderChange = false; | 
| Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 1026 |         showDialogIfForeground(dialogId); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1027 |         updateVoiceNumberField(); | 
 | 1028 |     } | 
 | 1029 |  | 
 | 1030 |     /** | 
 | 1031 |      * Called when Voicemail Provider and its forwarding settings were successfully finished. | 
 | 1032 |      * This updates a bunch of variables and show "success" dialog. | 
 | 1033 |      */ | 
| Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 1034 |     private void handleVmAndFwdSetSuccess(int dialogId) { | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 1035 |         if (DBG) log("handleVmAndFwdSetSuccess: key is " + getCurrentVoicemailProviderKey()); | 
 | 1036 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1037 |         mPreviousVMProviderKey = getCurrentVoicemailProviderKey(); | 
 | 1038 |         mChangingVMorFwdDueToProviderChange = false; | 
| Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 1039 |         showDialogIfForeground(dialogId); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1040 |         updateVoiceNumberField(); | 
 | 1041 |     } | 
 | 1042 |  | 
 | 1043 |     /** | 
 | 1044 |      * Update the voicemail number from what we've recorded on the sim. | 
 | 1045 |      */ | 
 | 1046 |     private void updateVoiceNumberField() { | 
| Andrew Lee | 2d5d1a4 | 2014-11-05 12:34:14 -0800 | [diff] [blame] | 1047 |         if (DBG) log("updateVoiceNumberField()"); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1048 |  | 
 | 1049 |         mOldVmNumber = mPhone.getVoiceMailNumber(); | 
| Andrew Lee | 2d5d1a4 | 2014-11-05 12:34:14 -0800 | [diff] [blame] | 1050 |         if (TextUtils.isEmpty(mOldVmNumber)) { | 
 | 1051 |             mSubMenuVoicemailSettings.setPhoneNumber(""); | 
 | 1052 |             mSubMenuVoicemailSettings.setSummary(getString(R.string.voicemail_number_not_set)); | 
 | 1053 |         } else { | 
 | 1054 |             mSubMenuVoicemailSettings.setPhoneNumber(mOldVmNumber); | 
 | 1055 |             mSubMenuVoicemailSettings.setSummary(mOldVmNumber); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1056 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1057 |     } | 
 | 1058 |  | 
 | 1059 |     /* | 
 | 1060 |      * Helper Methods for Activity class. | 
 | 1061 |      * The initial query commands are split into two pieces now | 
 | 1062 |      * for individual expansion.  This combined with the ability | 
 | 1063 |      * to cancel queries allows for a much better user experience, | 
 | 1064 |      * and also ensures that the user only waits to update the | 
 | 1065 |      * data that is relevant. | 
 | 1066 |      */ | 
 | 1067 |  | 
 | 1068 |     @Override | 
 | 1069 |     protected void onPrepareDialog(int id, Dialog dialog) { | 
 | 1070 |         super.onPrepareDialog(id, dialog); | 
 | 1071 |         mCurrentDialogId = id; | 
 | 1072 |     } | 
 | 1073 |  | 
 | 1074 |     // dialog creation method, called by showDialog() | 
 | 1075 |     @Override | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 1076 |     protected Dialog onCreateDialog(int dialogId) { | 
 | 1077 |         return VoicemailDialogUtil.getDialog(this, dialogId); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1078 |     } | 
 | 1079 |  | 
 | 1080 |     // This is a method implemented for DialogInterface.OnClickListener. | 
 | 1081 |     // Used with the error dialog to close the app, voicemail dialog to just dismiss. | 
 | 1082 |     // Close button is mapped to BUTTON_POSITIVE for the errors that close the activity, | 
 | 1083 |     // while those that are mapped to BUTTON_NEUTRAL only move the preference focus. | 
 | 1084 |     public void onClick(DialogInterface dialog, int which) { | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 1085 |         if (DBG) log("onClick: button clicked is " + which); | 
 | 1086 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1087 |         dialog.dismiss(); | 
 | 1088 |         switch (which){ | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1089 |             case DialogInterface.BUTTON_NEGATIVE: | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 1090 |                 if (mCurrentDialogId == VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1091 |                     // We failed to get current forwarding settings and the user | 
 | 1092 |                     // does not wish to continue. | 
 | 1093 |                     switchToPreviousVoicemailProvider(); | 
 | 1094 |                 } | 
 | 1095 |                 break; | 
 | 1096 |             case DialogInterface.BUTTON_POSITIVE: | 
| Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 1097 |                 if (mCurrentDialogId == VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1098 |                     // We failed to get current forwarding settings but the user | 
 | 1099 |                     // wishes to continue changing settings to the new vm provider | 
 | 1100 |                     saveVoiceMailAndForwardingNumberStage2(); | 
 | 1101 |                 } else { | 
 | 1102 |                     finish(); | 
 | 1103 |                 } | 
 | 1104 |                 return; | 
 | 1105 |             default: | 
 | 1106 |                 // just let the dialog close and go back to the input | 
 | 1107 |         } | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 1108 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1109 |         // In all dialogs, all buttons except BUTTON_POSITIVE lead to the end of user interaction | 
 | 1110 |         // with settings UI. If we were called to explicitly configure voice mail then | 
 | 1111 |         // we finish the settings activity here to come back to whatever the user was doing. | 
 | 1112 |         if (getIntent().getAction().equals(ACTION_ADD_VOICEMAIL)) { | 
 | 1113 |             finish(); | 
 | 1114 |         } | 
 | 1115 |     } | 
 | 1116 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1117 |     /* | 
 | 1118 |      * Activity class methods | 
 | 1119 |      */ | 
 | 1120 |  | 
 | 1121 |     @Override | 
 | 1122 |     protected void onCreate(Bundle icicle) { | 
 | 1123 |         super.onCreate(icicle); | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 1124 |         if (DBG) log("onCreate: Intent is " + getIntent()); | 
 | 1125 |  | 
| Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1126 |         mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); | 
| Andrew Lee | 88b51e2 | 2014-10-29 15:48:51 -0700 | [diff] [blame] | 1127 |         mVmProviderSettingsUtil = new VoicemailProviderSettingsUtil(getApplicationContext()); | 
| Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1128 |  | 
| Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1129 |         // Show the voicemail preference in onResume if the calling intent specifies the | 
 | 1130 |         // ACTION_ADD_VOICEMAIL action. | 
 | 1131 |         mShowVoicemailPreference = (icicle == null) && | 
| Jay Shrauner | be2fb26 | 2014-11-11 15:19:58 -0800 | [diff] [blame] | 1132 |                 TextUtils.equals(getIntent().getAction(), ACTION_ADD_VOICEMAIL); | 
| Andrew Lee | 5ed870c | 2014-10-29 11:47:49 -0700 | [diff] [blame] | 1133 |  | 
 | 1134 |         mSubscriptionInfoHelper = new SubscriptionInfoHelper(getIntent()); | 
 | 1135 |         mSubscriptionInfoHelper.setActionBarTitle( | 
 | 1136 |                 getActionBar(), getResources(), R.string.call_settings_with_label); | 
| Andrew Lee | 1479dd1 | 2014-11-06 23:06:32 -0800 | [diff] [blame] | 1137 |         mPhone = mSubscriptionInfoHelper.getPhone(); | 
| Andrew Lee | 5ed870c | 2014-10-29 11:47:49 -0700 | [diff] [blame] | 1138 |    } | 
| Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1139 |  | 
 | 1140 |     private void initPhoneAccountPreferences() { | 
| Andrew Lee | ce8ae2a | 2014-09-10 10:41:48 -0700 | [diff] [blame] | 1141 |         mPhoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY); | 
| Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1142 |  | 
| Tyler Gunn | 4d45d1c | 2014-09-12 22:17:53 -0700 | [diff] [blame] | 1143 |         TelecomManager telecomManager = TelecomManager.from(this); | 
| Andrew Lee | 93c345f | 2014-10-27 15:25:07 -0700 | [diff] [blame] | 1144 |         TelephonyManager telephonyManager = | 
 | 1145 |                 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); | 
| Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1146 |  | 
| Andrew Lee | 93c345f | 2014-10-27 15:25:07 -0700 | [diff] [blame] | 1147 |         if ((telecomManager.getSimCallManagers().isEmpty() && !SipUtil.isVoipSupported(this)) | 
 | 1148 |                 || telephonyManager.getPhoneCount() > 1) { | 
| Andrew Lee | ce8ae2a | 2014-09-10 10:41:48 -0700 | [diff] [blame] | 1149 |             getPreferenceScreen().removePreference(mPhoneAccountSettingsPreference); | 
| Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1150 |         } | 
 | 1151 |     } | 
 | 1152 |  | 
| Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1153 |     @Override | 
 | 1154 |     protected void onResume() { | 
 | 1155 |         super.onResume(); | 
 | 1156 |         mForeground = true; | 
 | 1157 |  | 
 | 1158 |         PreferenceScreen preferenceScreen = getPreferenceScreen(); | 
 | 1159 |         if (preferenceScreen != null) { | 
 | 1160 |             preferenceScreen.removeAll(); | 
 | 1161 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1162 |  | 
 | 1163 |         addPreferencesFromResource(R.xml.call_feature_setting); | 
| Andrew Lee | 5ed870c | 2014-10-29 11:47:49 -0700 | [diff] [blame] | 1164 |  | 
| Andrew Lee | db2fe56 | 2014-09-03 15:40:43 -0700 | [diff] [blame] | 1165 |         initPhoneAccountPreferences(); | 
 | 1166 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1167 |         PreferenceScreen prefSet = getPreferenceScreen(); | 
| Andrew Lee | 64a7d79 | 2014-10-15 17:38:38 -0700 | [diff] [blame] | 1168 |         mSubMenuVoicemailSettings = (EditPhoneNumberPreference) findPreference(BUTTON_VOICEMAIL_KEY); | 
 | 1169 |         mSubMenuVoicemailSettings.setParentActivity(this, VOICEMAIL_PREF_ID, this); | 
 | 1170 |         mSubMenuVoicemailSettings.setDialogOnClosedListener(this); | 
 | 1171 |         mSubMenuVoicemailSettings.setDialogTitle(R.string.voicemail_settings_number_label); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1172 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1173 |         mButtonDTMF = (ListPreference) findPreference(BUTTON_DTMF_KEY); | 
 | 1174 |         mButtonAutoRetry = (CheckBoxPreference) findPreference(BUTTON_RETRY_KEY); | 
 | 1175 |         mButtonHAC = (CheckBoxPreference) findPreference(BUTTON_HAC_KEY); | 
 | 1176 |         mButtonTTY = (ListPreference) findPreference(BUTTON_TTY_KEY); | 
 | 1177 |         mVoicemailProviders = (ListPreference) findPreference(BUTTON_VOICEMAIL_PROVIDER_KEY); | 
| Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 1178 |         mEnableVideoCalling = (CheckBoxPreference) findPreference(ENABLE_VIDEO_CALLING_KEY); | 
| Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 1179 |  | 
| Andrew Lee | 2c02789 | 2014-10-29 11:29:54 -0700 | [diff] [blame] | 1180 |         mVoicemailProviders.setOnPreferenceChangeListener(this); | 
 | 1181 |         mVoicemailSettingsScreen = | 
 | 1182 |                 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY); | 
 | 1183 |         mVoicemailSettings = (PreferenceScreen)findPreference(BUTTON_VOICEMAIL_SETTING_KEY); | 
 | 1184 |         mVoicemailNotificationVibrate = | 
 | 1185 |                 (CheckBoxPreference) findPreference(BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY); | 
 | 1186 |         initVoiceMailProviders(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1187 |  | 
| Andrew Lee | 64a7d79 | 2014-10-15 17:38:38 -0700 | [diff] [blame] | 1188 |         if (getResources().getBoolean(R.bool.dtmf_type_enabled)) { | 
 | 1189 |             mButtonDTMF.setOnPreferenceChangeListener(this); | 
 | 1190 |             int dtmf = Settings.System.getInt(getContentResolver(), | 
 | 1191 |                     Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, Constants.DTMF_TONE_TYPE_NORMAL); | 
 | 1192 |             mButtonDTMF.setValueIndex(dtmf); | 
 | 1193 |         } else { | 
 | 1194 |             prefSet.removePreference(mButtonDTMF); | 
 | 1195 |             mButtonDTMF = null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1196 |         } | 
 | 1197 |  | 
| Andrew Lee | 64a7d79 | 2014-10-15 17:38:38 -0700 | [diff] [blame] | 1198 |         if (getResources().getBoolean(R.bool.auto_retry_enabled)) { | 
 | 1199 |             mButtonAutoRetry.setOnPreferenceChangeListener(this); | 
 | 1200 |             int autoretry = Settings.Global.getInt( | 
 | 1201 |                     getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0); | 
 | 1202 |             mButtonAutoRetry.setChecked(autoretry != 0); | 
 | 1203 |         } else { | 
 | 1204 |             prefSet.removePreference(mButtonAutoRetry); | 
 | 1205 |             mButtonAutoRetry = null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1206 |         } | 
 | 1207 |  | 
| Andrew Lee | 64a7d79 | 2014-10-15 17:38:38 -0700 | [diff] [blame] | 1208 |         if (getResources().getBoolean(R.bool.hac_enabled)) { | 
 | 1209 |             mButtonHAC.setOnPreferenceChangeListener(this); | 
 | 1210 |             int hac = Settings.System.getInt(getContentResolver(), Settings.System.HEARING_AID, 0); | 
 | 1211 |             mButtonHAC.setChecked(hac != 0); | 
 | 1212 |         } else { | 
 | 1213 |             prefSet.removePreference(mButtonHAC); | 
 | 1214 |             mButtonHAC = null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1215 |         } | 
 | 1216 |  | 
| Andrew Lee | 64a7d79 | 2014-10-15 17:38:38 -0700 | [diff] [blame] | 1217 |         TelecomManager telecomManager = TelecomManager.from(this); | 
 | 1218 |         if (telecomManager != null && telecomManager.isTtySupported()) { | 
 | 1219 |             mButtonTTY.setOnPreferenceChangeListener(this); | 
 | 1220 |             int settingsTtyMode = Settings.Secure.getInt(getContentResolver(), | 
 | 1221 |                     Settings.Secure.PREFERRED_TTY_MODE, | 
 | 1222 |                     TelecomManager.TTY_MODE_OFF); | 
 | 1223 |             mButtonTTY.setValue(Integer.toString(settingsTtyMode)); | 
 | 1224 |             updatePreferredTtyModeSummary(settingsTtyMode); | 
 | 1225 |         } else { | 
 | 1226 |             prefSet.removePreference(mButtonTTY); | 
 | 1227 |             mButtonTTY = null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1228 |         } | 
 | 1229 |  | 
 | 1230 |         if (!getResources().getBoolean(R.bool.world_phone)) { | 
| Andrew Lee | 2b36ba2 | 2014-11-05 17:08:49 -0800 | [diff] [blame] | 1231 |             Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS); | 
 | 1232 |             prefSet.removePreference(cdmaOptions); | 
 | 1233 |  | 
 | 1234 |             // TODO: Support MSIM for this preference option. | 
 | 1235 |             Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS); | 
 | 1236 |             prefSet.removePreference(gsmOptions); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1237 |  | 
 | 1238 |             int phoneType = mPhone.getPhoneType(); | 
| Andrew Lee | 5ed870c | 2014-10-29 11:47:49 -0700 | [diff] [blame] | 1239 |             Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1240 |             if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { | 
| Andrew Lee | 5ed870c | 2014-10-29 11:47:49 -0700 | [diff] [blame] | 1241 |                 prefSet.removePreference(fdnButton); | 
 | 1242 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1243 |                 if (!getResources().getBoolean(R.bool.config_voice_privacy_disable)) { | 
 | 1244 |                     addPreferencesFromResource(R.xml.cdma_call_privacy); | 
 | 1245 |                 } | 
 | 1246 |             } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { | 
| Andrew Lee | 5ed870c | 2014-10-29 11:47:49 -0700 | [diff] [blame] | 1247 |                 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(this, FdnSetting.class)); | 
 | 1248 |  | 
| Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 1249 |                 if (getResources().getBoolean(R.bool.config_additional_call_setting)) { | 
| Etan Cohen | 0ca1c80 | 2014-07-07 15:35:48 -0700 | [diff] [blame] | 1250 |                     addPreferencesFromResource(R.xml.gsm_umts_call_options); | 
| Andrew Lee | 2b36ba2 | 2014-11-05 17:08:49 -0800 | [diff] [blame] | 1251 |  | 
 | 1252 |                     Preference callForwardingPref = prefSet.findPreference(CALL_FORWARDING_KEY); | 
 | 1253 |                     callForwardingPref.setIntent(mSubscriptionInfoHelper.getIntent( | 
 | 1254 |                             this, GsmUmtsCallForwardOptions.class)); | 
 | 1255 |  | 
 | 1256 |                     Preference additionalGsmSettingsPref = | 
 | 1257 |                             prefSet.findPreference(ADDITIONAL_GSM_SETTINGS_KEY); | 
 | 1258 |                     additionalGsmSettingsPref.setIntent(mSubscriptionInfoHelper.getIntent( | 
 | 1259 |                             this, GsmUmtsAdditionalCallOptions.class)); | 
| Etan Cohen | 0ca1c80 | 2014-07-07 15:35:48 -0700 | [diff] [blame] | 1260 |                 } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1261 |             } else { | 
 | 1262 |                 throw new IllegalStateException("Unexpected phone type: " + phoneType); | 
 | 1263 |             } | 
 | 1264 |         } | 
 | 1265 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1266 |         // check the intent that started this activity and pop up the voicemail | 
 | 1267 |         // dialog if we've been asked to. | 
 | 1268 |         // If we have at least one non default VM provider registered then bring up | 
 | 1269 |         // the selection for the VM provider, otherwise bring up a VM number dialog. | 
 | 1270 |         // We only bring up the dialog the first time we are called (not after orientation change) | 
| Andrew Lee | 2c02789 | 2014-10-29 11:29:54 -0700 | [diff] [blame] | 1271 |         if (mShowVoicemailPreference) { | 
| Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1272 |             if (DBG) { | 
 | 1273 |                 log("ACTION_ADD_VOICEMAIL Intent is thrown. current VM data size: " | 
 | 1274 |                         + mVMProvidersData.size()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1275 |             } | 
| Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1276 |             if (mVMProvidersData.size() > 1) { | 
 | 1277 |                 simulatePreferenceClick(mVoicemailProviders); | 
 | 1278 |             } else { | 
 | 1279 |                 onPreferenceChange(mVoicemailProviders, DEFAULT_VM_PROVIDER_KEY); | 
 | 1280 |                 mVoicemailProviders.setValue(DEFAULT_VM_PROVIDER_KEY); | 
 | 1281 |             } | 
 | 1282 |             mShowVoicemailPreference = false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1283 |         } | 
| Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1284 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1285 |         updateVoiceNumberField(); | 
 | 1286 |         mVMProviderSettingsForced = false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1287 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1288 |         SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences( | 
 | 1289 |                 mPhone.getContext()); | 
 | 1290 |         if (migrateVoicemailVibrationSettingsIfNeeded(prefs)) { | 
 | 1291 |             mVoicemailNotificationVibrate.setChecked(prefs.getBoolean( | 
 | 1292 |                     BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY, false)); | 
 | 1293 |         } | 
 | 1294 |  | 
| Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 1295 |         if (ImsManager.isVtEnabledByPlatform(mPhone.getContext()) && ENABLE_VT_FLAG) { | 
 | 1296 |             boolean currentValue = | 
 | 1297 |                     ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext()) | 
 | 1298 |                     ? PhoneGlobals.getInstance().phoneMgr.isVideoCallingEnabled() : false; | 
 | 1299 |             mEnableVideoCalling.setChecked(currentValue); | 
| Andrew Lee | 77527ac | 2014-10-21 16:57:39 -0700 | [diff] [blame] | 1300 |             mEnableVideoCalling.setOnPreferenceChangeListener(this); | 
 | 1301 |         } else { | 
 | 1302 |             prefSet.removePreference(mEnableVideoCalling); | 
 | 1303 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1304 |     } | 
 | 1305 |  | 
 | 1306 |     // Migrate settings from BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_WHEN_KEY to | 
 | 1307 |     // BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY, if the latter does not exist. | 
 | 1308 |     // Returns true if migration was performed. | 
 | 1309 |     public static boolean migrateVoicemailVibrationSettingsIfNeeded(SharedPreferences prefs) { | 
 | 1310 |         if (!prefs.contains(BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY)) { | 
 | 1311 |             String vibrateWhen = prefs.getString( | 
 | 1312 |                     BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_WHEN_KEY, VOICEMAIL_VIBRATION_NEVER); | 
 | 1313 |             // If vibrateWhen is always, then voicemailVibrate should be True. | 
 | 1314 |             // otherwise if vibrateWhen is "only in silent mode", or "never", then | 
 | 1315 |             // voicemailVibrate = False. | 
 | 1316 |             boolean voicemailVibrate = vibrateWhen.equals(VOICEMAIL_VIBRATION_ALWAYS); | 
 | 1317 |             final SharedPreferences.Editor editor = prefs.edit(); | 
 | 1318 |             editor.putBoolean(BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY, voicemailVibrate); | 
 | 1319 |             editor.commit(); | 
 | 1320 |             return true; | 
 | 1321 |         } | 
 | 1322 |         return false; | 
 | 1323 |     } | 
 | 1324 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1325 |     private void handleTTYChange(Preference preference, Object objValue) { | 
 | 1326 |         int buttonTtyMode; | 
 | 1327 |         buttonTtyMode = Integer.valueOf((String) objValue).intValue(); | 
 | 1328 |         int settingsTtyMode = android.provider.Settings.Secure.getInt( | 
 | 1329 |                 getContentResolver(), | 
| Sailesh Nepal | bf90054 | 2014-07-15 16:18:32 -0700 | [diff] [blame] | 1330 |                 android.provider.Settings.Secure.PREFERRED_TTY_MODE, | 
| Tyler Gunn | 4d45d1c | 2014-09-12 22:17:53 -0700 | [diff] [blame] | 1331 |                 TelecomManager.TTY_MODE_OFF); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1332 |         if (DBG) log("handleTTYChange: requesting set TTY mode enable (TTY) to" + | 
 | 1333 |                 Integer.toString(buttonTtyMode)); | 
 | 1334 |  | 
 | 1335 |         if (buttonTtyMode != settingsTtyMode) { | 
 | 1336 |             switch(buttonTtyMode) { | 
| Tyler Gunn | 4d45d1c | 2014-09-12 22:17:53 -0700 | [diff] [blame] | 1337 |             case TelecomManager.TTY_MODE_OFF: | 
 | 1338 |             case TelecomManager.TTY_MODE_FULL: | 
 | 1339 |             case TelecomManager.TTY_MODE_HCO: | 
 | 1340 |             case TelecomManager.TTY_MODE_VCO: | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1341 |                 android.provider.Settings.Secure.putInt(getContentResolver(), | 
 | 1342 |                         android.provider.Settings.Secure.PREFERRED_TTY_MODE, buttonTtyMode); | 
 | 1343 |                 break; | 
 | 1344 |             default: | 
| Tyler Gunn | 4d45d1c | 2014-09-12 22:17:53 -0700 | [diff] [blame] | 1345 |                 buttonTtyMode = TelecomManager.TTY_MODE_OFF; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1346 |             } | 
 | 1347 |  | 
 | 1348 |             mButtonTTY.setValue(Integer.toString(buttonTtyMode)); | 
 | 1349 |             updatePreferredTtyModeSummary(buttonTtyMode); | 
| Tyler Gunn | 4d45d1c | 2014-09-12 22:17:53 -0700 | [diff] [blame] | 1350 |             Intent ttyModeChanged = new Intent(TelecomManager.ACTION_TTY_PREFERRED_MODE_CHANGED); | 
 | 1351 |             ttyModeChanged.putExtra(TelecomManager.EXTRA_TTY_PREFERRED_MODE, buttonTtyMode); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1352 |             sendBroadcastAsUser(ttyModeChanged, UserHandle.ALL); | 
 | 1353 |         } | 
 | 1354 |     } | 
 | 1355 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1356 |     private void updatePreferredTtyModeSummary(int TtyMode) { | 
 | 1357 |         String [] txts = getResources().getStringArray(R.array.tty_mode_entries); | 
 | 1358 |         switch(TtyMode) { | 
| Tyler Gunn | 4d45d1c | 2014-09-12 22:17:53 -0700 | [diff] [blame] | 1359 |             case TelecomManager.TTY_MODE_OFF: | 
 | 1360 |             case TelecomManager.TTY_MODE_HCO: | 
 | 1361 |             case TelecomManager.TTY_MODE_VCO: | 
 | 1362 |             case TelecomManager.TTY_MODE_FULL: | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1363 |                 mButtonTTY.setSummary(txts[TtyMode]); | 
 | 1364 |                 break; | 
 | 1365 |             default: | 
 | 1366 |                 mButtonTTY.setEnabled(false); | 
| Tyler Gunn | 4d45d1c | 2014-09-12 22:17:53 -0700 | [diff] [blame] | 1367 |                 mButtonTTY.setSummary(txts[TelecomManager.TTY_MODE_OFF]); | 
| Sailesh Nepal | bf90054 | 2014-07-15 16:18:32 -0700 | [diff] [blame] | 1368 |                 break; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1369 |         } | 
 | 1370 |     } | 
 | 1371 |  | 
 | 1372 |     private static void log(String msg) { | 
 | 1373 |         Log.d(LOG_TAG, msg); | 
 | 1374 |     } | 
 | 1375 |  | 
 | 1376 |     /** | 
 | 1377 |      * Updates the look of the VM preference widgets based on current VM provider settings. | 
 | 1378 |      * Note that the provider name is loaded form the found activity via loadLabel in | 
 | 1379 |      * {@link #initVoiceMailProviders()} in order for it to be localizable. | 
 | 1380 |      */ | 
 | 1381 |     private void updateVMPreferenceWidgets(String currentProviderSetting) { | 
 | 1382 |         final String key = currentProviderSetting; | 
 | 1383 |         final VoiceMailProvider provider = mVMProvidersData.get(key); | 
 | 1384 |  | 
 | 1385 |         /* This is the case when we are coming up on a freshly wiped phone and there is no | 
 | 1386 |          persisted value for the list preference mVoicemailProviders. | 
 | 1387 |          In this case we want to show the UI asking the user to select a voicemail provider as | 
 | 1388 |          opposed to silently falling back to default one. */ | 
 | 1389 |         if (provider == null) { | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 1390 |             if (DBG) log("updateVMPreferenceWidget: key: " + key + " -> null."); | 
 | 1391 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1392 |             mVoicemailProviders.setSummary(getString(R.string.sum_voicemail_choose_provider)); | 
 | 1393 |             mVoicemailSettings.setEnabled(false); | 
 | 1394 |             mVoicemailSettings.setIntent(null); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1395 |             mVoicemailNotificationVibrate.setEnabled(false); | 
 | 1396 |         } else { | 
| Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 1397 |             if (DBG) log("updateVMPreferenceWidget: key: " + key + " -> " + provider.toString()); | 
 | 1398 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1399 |             final String providerName = provider.name; | 
 | 1400 |             mVoicemailProviders.setSummary(providerName); | 
 | 1401 |             mVoicemailSettings.setEnabled(true); | 
 | 1402 |             mVoicemailSettings.setIntent(provider.intent); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1403 |             mVoicemailNotificationVibrate.setEnabled(true); | 
 | 1404 |         } | 
 | 1405 |     } | 
 | 1406 |  | 
 | 1407 |     /** | 
 | 1408 |      * Enumerates existing VM providers and puts their data into the list and populates | 
 | 1409 |      * the preference list objects with their names. | 
 | 1410 |      * In case we are called with ACTION_ADD_VOICEMAIL intent the intent may have | 
 | 1411 |      * an extra string called IGNORE_PROVIDER_EXTRA with "package.activityName" of the provider | 
 | 1412 |      * which should be hidden when we bring up the list of possible VM providers to choose. | 
 | 1413 |      */ | 
 | 1414 |     private void initVoiceMailProviders() { | 
 | 1415 |         if (DBG) log("initVoiceMailProviders()"); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1416 |  | 
 | 1417 |         String providerToIgnore = null; | 
| Andrew Lee | f1776d8 | 2014-11-04 14:45:02 -0800 | [diff] [blame] | 1418 |         if (getIntent().getAction().equals(ACTION_ADD_VOICEMAIL) | 
 | 1419 |                 && getIntent().hasExtra(IGNORE_PROVIDER_EXTRA)) { | 
 | 1420 |             providerToIgnore = getIntent().getStringExtra(IGNORE_PROVIDER_EXTRA); | 
 | 1421 |             // Remove this provider from the list. | 
 | 1422 |             if (!TextUtils.isEmpty(providerToIgnore)) { | 
 | 1423 |                 if (DBG) log("Found ACTION_ADD_VOICEMAIL. providerToIgnore= " + providerToIgnore); | 
| Andrew Lee | 88b51e2 | 2014-10-29 15:48:51 -0700 | [diff] [blame] | 1424 |                 mVmProviderSettingsUtil.delete(providerToIgnore); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1425 |             } | 
 | 1426 |         } | 
 | 1427 |  | 
 | 1428 |         mVMProvidersData.clear(); | 
 | 1429 |  | 
| Andrew Lee | f1776d8 | 2014-11-04 14:45:02 -0800 | [diff] [blame] | 1430 |         List<String> entries = new ArrayList<String>(); | 
 | 1431 |         List<String> values = new ArrayList<String>(); | 
 | 1432 |  | 
 | 1433 |         // Add default voicemail provider. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1434 |         final String myCarrier = getString(R.string.voicemail_default); | 
 | 1435 |         mVMProvidersData.put(DEFAULT_VM_PROVIDER_KEY, new VoiceMailProvider(myCarrier, null)); | 
| Andrew Lee | f1776d8 | 2014-11-04 14:45:02 -0800 | [diff] [blame] | 1436 |         entries.add(myCarrier); | 
 | 1437 |         values.add(DEFAULT_VM_PROVIDER_KEY); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1438 |  | 
| Andrew Lee | f1776d8 | 2014-11-04 14:45:02 -0800 | [diff] [blame] | 1439 |         // Add other voicemail providers. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1440 |         PackageManager pm = getPackageManager(); | 
| Andrew Lee | f1776d8 | 2014-11-04 14:45:02 -0800 | [diff] [blame] | 1441 |         Intent intent = new Intent(ACTION_CONFIGURE_VOICEMAIL); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1442 |         List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1443 |         for (int i = 0; i < resolveInfos.size(); i++) { | 
 | 1444 |             final ResolveInfo ri= resolveInfos.get(i); | 
 | 1445 |             final ActivityInfo currentActivityInfo = ri.activityInfo; | 
| Andrew Lee | 6214e2b | 2014-11-04 13:57:38 -0800 | [diff] [blame] | 1446 |             final String key = currentActivityInfo.name; | 
| Andrew Lee | f1776d8 | 2014-11-04 14:45:02 -0800 | [diff] [blame] | 1447 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1448 |             if (key.equals(providerToIgnore)) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1449 |                 continue; | 
 | 1450 |             } | 
| Andrew Lee | f1776d8 | 2014-11-04 14:45:02 -0800 | [diff] [blame] | 1451 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1452 |             if (DBG) log("Loading key: " + key); | 
 | 1453 |             final String nameForDisplay = ri.loadLabel(pm).toString(); | 
 | 1454 |             Intent providerIntent = new Intent(); | 
 | 1455 |             providerIntent.setAction(ACTION_CONFIGURE_VOICEMAIL); | 
| Andrew Lee | f1776d8 | 2014-11-04 14:45:02 -0800 | [diff] [blame] | 1456 |             providerIntent.setClassName(currentActivityInfo.packageName, currentActivityInfo.name); | 
 | 1457 |             VoiceMailProvider vmProvider = new VoiceMailProvider(nameForDisplay, providerIntent); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1458 |  | 
| Andrew Lee | f1776d8 | 2014-11-04 14:45:02 -0800 | [diff] [blame] | 1459 |             if (DBG) log("Store VoiceMailProvider. Key: " + key + " -> " + vmProvider.toString()); | 
 | 1460 |             mVMProvidersData.put(key, vmProvider); | 
 | 1461 |             entries.add(vmProvider.name); | 
 | 1462 |             values.add(key); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1463 |         } | 
 | 1464 |  | 
| Andrew Lee | f1776d8 | 2014-11-04 14:45:02 -0800 | [diff] [blame] | 1465 |         mVoicemailProviders.setEntries(entries.toArray(new String[0])); | 
 | 1466 |         mVoicemailProviders.setEntryValues(values.toArray(new String[0])); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1467 |  | 
| Andrew Lee | f1776d8 | 2014-11-04 14:45:02 -0800 | [diff] [blame] | 1468 |         // Remember the current Voicemail Provider key as a "previous" key. This will be used when | 
 | 1469 |         // we fail to update Voicemail Provider, which requires rollback. We will update this when | 
 | 1470 |         // the VM Provider setting is successfully updated. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1471 |         mPreviousVMProviderKey = getCurrentVoicemailProviderKey(); | 
 | 1472 |         if (DBG) log("Set up the first mPreviousVMProviderKey: " + mPreviousVMProviderKey); | 
 | 1473 |  | 
 | 1474 |         // Finally update the preference texts. | 
 | 1475 |         updateVMPreferenceWidgets(mPreviousVMProviderKey); | 
 | 1476 |     } | 
 | 1477 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1478 |     /** | 
 | 1479 |      * Simulates user clicking on a passed preference. | 
 | 1480 |      * Usually needed when the preference is a dialog preference and we want to invoke | 
 | 1481 |      * a dialog for this preference programmatically. | 
| Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 1482 |      * TODO: figure out if there is a cleaner way to cause preference dlg to come up | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1483 |      */ | 
 | 1484 |     private void simulatePreferenceClick(Preference preference) { | 
 | 1485 |         // Go through settings until we find our setting | 
 | 1486 |         // and then simulate a click on it to bring up the dialog | 
 | 1487 |         final ListAdapter adapter = getPreferenceScreen().getRootAdapter(); | 
 | 1488 |         for (int idx = 0; idx < adapter.getCount(); idx++) { | 
 | 1489 |             if (adapter.getItem(idx) == preference) { | 
 | 1490 |                 getPreferenceScreen().onItemClick(this.getListView(), | 
 | 1491 |                         null, idx, adapter.getItemId(idx)); | 
 | 1492 |                 break; | 
 | 1493 |             } | 
 | 1494 |         } | 
 | 1495 |     } | 
 | 1496 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1497 |     private String getCurrentVoicemailProviderKey() { | 
 | 1498 |         final String key = mVoicemailProviders.getValue(); | 
 | 1499 |         return (key != null) ? key : DEFAULT_VM_PROVIDER_KEY; | 
 | 1500 |     } | 
 | 1501 |  | 
 | 1502 |     @Override | 
 | 1503 |     public boolean onOptionsItemSelected(MenuItem item) { | 
 | 1504 |         final int itemId = item.getItemId(); | 
 | 1505 |         if (itemId == android.R.id.home) {  // See ActionBar#setDisplayHomeAsUpEnabled() | 
| Yorke Lee | f2d0cac | 2013-09-09 19:42:56 -0700 | [diff] [blame] | 1506 |             onBackPressed(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1507 |             return true; | 
 | 1508 |         } | 
 | 1509 |         return super.onOptionsItemSelected(item); | 
 | 1510 |     } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1511 |     /** | 
 | 1512 |      * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}). | 
 | 1513 |      * This is useful for implementing "HomeAsUp" capability for second-level Settings. | 
 | 1514 |      */ | 
 | 1515 |     public static void goUpToTopLevelSetting(Activity activity) { | 
 | 1516 |         Intent intent = new Intent(activity, CallFeaturesSetting.class); | 
 | 1517 |         intent.setAction(Intent.ACTION_MAIN); | 
 | 1518 |         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | 
 | 1519 |         activity.startActivity(intent); | 
 | 1520 |         activity.finish(); | 
 | 1521 |     } | 
 | 1522 | } |