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; |
| 24 | import android.app.ProgressDialog; |
| 25 | import android.content.ContentResolver; |
| 26 | import android.content.Context; |
| 27 | import android.content.DialogInterface; |
| 28 | import android.content.Intent; |
| 29 | import android.content.SharedPreferences; |
| 30 | import android.content.SharedPreferences.Editor; |
| 31 | import android.content.pm.ActivityInfo; |
| 32 | import android.content.pm.PackageManager; |
| 33 | import android.content.pm.ResolveInfo; |
| 34 | import android.database.Cursor; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.media.AudioManager; |
| 36 | import android.media.RingtoneManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.net.sip.SipManager; |
| 38 | import android.os.AsyncResult; |
| 39 | import android.os.Bundle; |
| 40 | import android.os.Handler; |
| 41 | import android.os.Message; |
| 42 | import android.os.UserHandle; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 43 | import android.preference.CheckBoxPreference; |
| 44 | import android.preference.ListPreference; |
| 45 | import android.preference.Preference; |
| 46 | import android.preference.PreferenceActivity; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 47 | import android.preference.PreferenceManager; |
| 48 | import android.preference.PreferenceScreen; |
| 49 | import android.provider.ContactsContract.CommonDataKinds; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.provider.Settings; |
Andrew Lee | db2fe56 | 2014-09-03 15:40:43 -0700 | [diff] [blame] | 51 | import android.telecomm.PhoneAccountHandle; |
Sailesh Nepal | bf90054 | 2014-07-15 16:18:32 -0700 | [diff] [blame] | 52 | import android.telecomm.TelecommManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.telephony.PhoneNumberUtils; |
| 54 | import android.text.TextUtils; |
| 55 | import android.util.Log; |
| 56 | import android.view.MenuItem; |
| 57 | import android.view.WindowManager; |
| 58 | import android.widget.ListAdapter; |
| 59 | |
| 60 | import com.android.internal.telephony.CallForwardInfo; |
| 61 | import com.android.internal.telephony.CommandsInterface; |
| 62 | import com.android.internal.telephony.Phone; |
| 63 | import com.android.internal.telephony.PhoneConstants; |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 64 | import com.android.phone.common.util.SettingsUtil; |
Andrew Lee | db2fe56 | 2014-09-03 15:40:43 -0700 | [diff] [blame] | 65 | import com.android.phone.settings.AccountSelectionPreference; |
Sailesh Nepal | 788959e | 2014-07-08 23:36:40 -0700 | [diff] [blame] | 66 | import com.android.services.telephony.sip.SipSharedPreferences; |
| 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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 70 | import java.util.Collection; |
| 71 | import java.util.HashMap; |
| 72 | import java.util.HashSet; |
| 73 | import java.util.Iterator; |
| 74 | import java.util.List; |
| 75 | import java.util.Map; |
| 76 | |
| 77 | /** |
| 78 | * Top level "Call settings" UI; see res/xml/call_feature_setting.xml |
| 79 | * |
| 80 | * This preference screen is the root of the "Call settings" hierarchy |
| 81 | * available from the Phone app; the settings here let you control various |
| 82 | * features related to phone calls (including voicemail settings, SIP |
| 83 | * settings, the "Respond via SMS" feature, and others.) It's used only |
| 84 | * on voice-capable phone devices. |
| 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 | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 93 | * TODO: Settings should be split into PreferenceFragments where possible (ie. voicemail, SIP). |
| 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, |
| 100 | Preference.OnPreferenceClickListener, |
| 101 | EditPhoneNumberPreference.OnDialogClosedListener, |
Andrew Lee | db2fe56 | 2014-09-03 15:40:43 -0700 | [diff] [blame] | 102 | EditPhoneNumberPreference.GetDefaultNumberListener, |
| 103 | AccountSelectionPreference.AccountSelectionListener { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | private static final String LOG_TAG = "CallFeaturesSetting"; |
| 105 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 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"; |
| 127 | //Information about logical "up" Activity |
| 128 | private static final String UP_ACTIVITY_PACKAGE = "com.android.dialer"; |
| 129 | private static final String UP_ACTIVITY_CLASS = |
| 130 | "com.android.dialer.DialtactsActivity"; |
| 131 | |
| 132 | // Used to tell the saving logic to leave forwarding number as is |
| 133 | public static final CallForwardInfo[] FWD_SETTINGS_DONT_TOUCH = null; |
| 134 | // Suffix appended to provider key for storing vm number |
| 135 | public static final String VM_NUMBER_TAG = "#VMNumber"; |
| 136 | // Suffix appended to provider key for storing forwarding settings |
| 137 | public static final String FWD_SETTINGS_TAG = "#FWDSettings"; |
| 138 | // Suffix appended to forward settings key for storing length of settings array |
| 139 | public static final String FWD_SETTINGS_LENGTH_TAG = "#Length"; |
| 140 | // Suffix appended to forward settings key for storing an individual setting |
| 141 | public static final String FWD_SETTING_TAG = "#Setting"; |
| 142 | // Suffixes appended to forward setting key for storing an individual setting properties |
| 143 | public static final String FWD_SETTING_STATUS = "#Status"; |
| 144 | public static final String FWD_SETTING_REASON = "#Reason"; |
| 145 | public static final String FWD_SETTING_NUMBER = "#Number"; |
| 146 | public static final String FWD_SETTING_TIME = "#Time"; |
| 147 | |
| 148 | // Key identifying the default vocie mail provider |
| 149 | public static final String DEFAULT_VM_PROVIDER_KEY = ""; |
| 150 | |
| 151 | /** |
| 152 | * String Extra put into ACTION_ADD_VOICEMAIL call to indicate which provider should be hidden |
| 153 | * in the list of providers presented to the user. This allows a provider which is being |
| 154 | * disabled (e.g. GV user logging out) to force the user to pick some other provider. |
| 155 | */ |
| 156 | public static final String IGNORE_PROVIDER_EXTRA = "com.android.phone.ProviderToIgnore"; |
| 157 | |
| 158 | // string constants |
| 159 | private static final String NUM_PROJECTION[] = {CommonDataKinds.Phone.NUMBER}; |
| 160 | |
| 161 | // String keys for preference lookup |
| 162 | // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!) |
| 163 | private static final String BUTTON_VOICEMAIL_KEY = "button_voicemail_key"; |
| 164 | private static final String BUTTON_VOICEMAIL_PROVIDER_KEY = "button_voicemail_provider_key"; |
| 165 | private static final String BUTTON_VOICEMAIL_SETTING_KEY = "button_voicemail_setting_key"; |
| 166 | // New preference key for voicemail notification vibration |
| 167 | /* package */ static final String BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY = |
| 168 | "button_voicemail_notification_vibrate_key"; |
| 169 | // Old preference key for voicemail notification vibration. Used for migration to the new |
| 170 | // preference key only. |
| 171 | /* package */ static final String BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_WHEN_KEY = |
| 172 | "button_voicemail_notification_vibrate_when_key"; |
| 173 | /* package */ static final String BUTTON_VOICEMAIL_NOTIFICATION_RINGTONE_KEY = |
| 174 | "button_voicemail_notification_ringtone_key"; |
| 175 | private static final String BUTTON_FDN_KEY = "button_fdn_key"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 176 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 177 | private static final String BUTTON_DTMF_KEY = "button_dtmf_settings"; |
| 178 | private static final String BUTTON_RETRY_KEY = "button_auto_retry_key"; |
| 179 | private static final String BUTTON_TTY_KEY = "button_tty_mode_key"; |
| 180 | private static final String BUTTON_HAC_KEY = "button_hac_key"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 181 | |
| 182 | private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key"; |
| 183 | private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key"; |
| 184 | |
| 185 | private static final String VM_NUMBERS_SHARED_PREFERENCES_NAME = "vm_numbers"; |
| 186 | |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 187 | private static final String BUTTON_SIP_CALL_OPTIONS = "sip_call_options_key"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 188 | private static final String BUTTON_SIP_CALL_OPTIONS_WIFI_ONLY = |
| 189 | "sip_call_options_wifi_only_key"; |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 190 | private static final String SIP_SETTINGS_PREFERENCE_SCREEN_KEY = |
| 191 | "sip_settings_preference_screen_key"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 192 | |
Andrew Lee | db2fe56 | 2014-09-03 15:40:43 -0700 | [diff] [blame] | 193 | private static final String DEFAULT_OUTGOING_ACCOUNT_KEY = "default_outgoing_account"; |
| 194 | private static final String WIFI_CALL_MANAGER_ACCOUNT_KEY = "wifi_call_manager_account"; |
| 195 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 196 | private Intent mContactListIntent; |
| 197 | |
| 198 | /** Event for Async voicemail change call */ |
| 199 | private static final int EVENT_VOICEMAIL_CHANGED = 500; |
| 200 | private static final int EVENT_FORWARDING_CHANGED = 501; |
| 201 | private static final int EVENT_FORWARDING_GET_COMPLETED = 502; |
| 202 | |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 203 | private static final int MSG_UPDATE_VOICEMAIL_RINGTONE_SUMMARY = 1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 204 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 205 | public static final String HAC_KEY = "HACSetting"; |
| 206 | public static final String HAC_VAL_ON = "ON"; |
| 207 | public static final String HAC_VAL_OFF = "OFF"; |
| 208 | |
| 209 | /** Handle to voicemail pref */ |
| 210 | private static final int VOICEMAIL_PREF_ID = 1; |
| 211 | private static final int VOICEMAIL_PROVIDER_CFG_ID = 2; |
| 212 | |
| 213 | private Phone mPhone; |
| 214 | |
| 215 | private AudioManager mAudioManager; |
| 216 | private SipManager mSipManager; |
| 217 | |
| 218 | private static final int VM_NOCHANGE_ERROR = 400; |
| 219 | private static final int VM_RESPONSE_ERROR = 500; |
| 220 | private static final int FW_SET_RESPONSE_ERROR = 501; |
| 221 | private static final int FW_GET_RESPONSE_ERROR = 502; |
| 222 | |
| 223 | |
| 224 | // dialog identifiers for voicemail |
| 225 | private static final int VOICEMAIL_DIALOG_CONFIRM = 600; |
| 226 | private static final int VOICEMAIL_FWD_SAVING_DIALOG = 601; |
| 227 | private static final int VOICEMAIL_FWD_READING_DIALOG = 602; |
| 228 | private static final int VOICEMAIL_REVERTING_DIALOG = 603; |
| 229 | |
| 230 | // status message sent back from handlers |
| 231 | private static final int MSG_OK = 100; |
| 232 | |
| 233 | // special statuses for voicemail controls. |
| 234 | private static final int MSG_VM_EXCEPTION = 400; |
| 235 | private static final int MSG_FW_SET_EXCEPTION = 401; |
| 236 | private static final int MSG_FW_GET_EXCEPTION = 402; |
| 237 | private static final int MSG_VM_OK = 600; |
| 238 | private static final int MSG_VM_NOCHANGE = 700; |
| 239 | |
| 240 | // voicemail notification vibration string constants |
| 241 | private static final String VOICEMAIL_VIBRATION_ALWAYS = "always"; |
| 242 | private static final String VOICEMAIL_VIBRATION_NEVER = "never"; |
| 243 | |
| 244 | private EditPhoneNumberPreference mSubMenuVoicemailSettings; |
| 245 | |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 246 | private Runnable mVoicemailRingtoneLookupRunnable; |
| 247 | private final Handler mVoicemailRingtoneLookupComplete = new Handler() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 248 | @Override |
| 249 | public void handleMessage(Message msg) { |
| 250 | switch (msg.what) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 251 | case MSG_UPDATE_VOICEMAIL_RINGTONE_SUMMARY: |
| 252 | mVoicemailNotificationRingtone.setSummary((CharSequence) msg.obj); |
| 253 | break; |
| 254 | } |
| 255 | } |
| 256 | }; |
| 257 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 258 | /** Whether dialpad plays DTMF tone or not. */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 259 | private CheckBoxPreference mButtonAutoRetry; |
| 260 | private CheckBoxPreference mButtonHAC; |
| 261 | private ListPreference mButtonDTMF; |
| 262 | private ListPreference mButtonTTY; |
| 263 | private ListPreference mButtonSipCallOptions; |
Evan Charlton | 1c69683 | 2014-04-15 14:24:23 -0700 | [diff] [blame] | 264 | private Preference mWifiCallOptionsPreference; |
| 265 | private Preference mWifiCallAccountPreference; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 266 | private ListPreference mVoicemailProviders; |
| 267 | private PreferenceScreen mVoicemailSettings; |
| 268 | private Preference mVoicemailNotificationRingtone; |
| 269 | private CheckBoxPreference mVoicemailNotificationVibrate; |
| 270 | private SipSharedPreferences mSipSharedPreferences; |
Andrew Lee | db2fe56 | 2014-09-03 15:40:43 -0700 | [diff] [blame] | 271 | private AccountSelectionPreference mDefaultOutgoingAccount; |
| 272 | private AccountSelectionPreference mSimCallManagerAccount; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 273 | |
| 274 | private class VoiceMailProvider { |
| 275 | public VoiceMailProvider(String name, Intent intent) { |
| 276 | this.name = name; |
| 277 | this.intent = intent; |
| 278 | } |
| 279 | public String name; |
| 280 | public Intent intent; |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Forwarding settings we are going to save. |
| 285 | */ |
| 286 | private static final int [] FORWARDING_SETTINGS_REASONS = new int[] { |
| 287 | CommandsInterface.CF_REASON_UNCONDITIONAL, |
| 288 | CommandsInterface.CF_REASON_BUSY, |
| 289 | CommandsInterface.CF_REASON_NO_REPLY, |
| 290 | CommandsInterface.CF_REASON_NOT_REACHABLE |
| 291 | }; |
| 292 | |
| 293 | private class VoiceMailProviderSettings { |
| 294 | /** |
| 295 | * Constructs settings object, setting all conditional forwarding to the specified number |
| 296 | */ |
| 297 | public VoiceMailProviderSettings(String voicemailNumber, String forwardingNumber, |
| 298 | int timeSeconds) { |
| 299 | this.voicemailNumber = voicemailNumber; |
| 300 | if (forwardingNumber == null || forwardingNumber.length() == 0) { |
| 301 | this.forwardingSettings = FWD_SETTINGS_DONT_TOUCH; |
| 302 | } else { |
| 303 | this.forwardingSettings = new CallForwardInfo[FORWARDING_SETTINGS_REASONS.length]; |
| 304 | for (int i = 0; i < this.forwardingSettings.length; i++) { |
| 305 | CallForwardInfo fi = new CallForwardInfo(); |
| 306 | this.forwardingSettings[i] = fi; |
| 307 | fi.reason = FORWARDING_SETTINGS_REASONS[i]; |
| 308 | fi.status = (fi.reason == CommandsInterface.CF_REASON_UNCONDITIONAL) ? 0 : 1; |
| 309 | fi.serviceClass = CommandsInterface.SERVICE_CLASS_VOICE; |
| 310 | fi.toa = PhoneNumberUtils.TOA_International; |
| 311 | fi.number = forwardingNumber; |
| 312 | fi.timeSeconds = timeSeconds; |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | public VoiceMailProviderSettings(String voicemailNumber, CallForwardInfo[] infos) { |
| 318 | this.voicemailNumber = voicemailNumber; |
| 319 | this.forwardingSettings = infos; |
| 320 | } |
| 321 | |
| 322 | @Override |
| 323 | public boolean equals(Object o) { |
| 324 | if (o == null) return false; |
| 325 | if (!(o instanceof VoiceMailProviderSettings)) return false; |
| 326 | final VoiceMailProviderSettings v = (VoiceMailProviderSettings)o; |
| 327 | |
| 328 | return ((this.voicemailNumber == null && |
| 329 | v.voicemailNumber == null) || |
| 330 | this.voicemailNumber != null && |
| 331 | this.voicemailNumber.equals(v.voicemailNumber)) |
| 332 | && |
| 333 | forwardingSettingsEqual(this.forwardingSettings, |
| 334 | v.forwardingSettings); |
| 335 | } |
| 336 | |
| 337 | private boolean forwardingSettingsEqual(CallForwardInfo[] infos1, |
| 338 | CallForwardInfo[] infos2) { |
| 339 | if (infos1 == infos2) return true; |
| 340 | if (infos1 == null || infos2 == null) return false; |
| 341 | if (infos1.length != infos2.length) return false; |
| 342 | for (int i = 0; i < infos1.length; i++) { |
| 343 | CallForwardInfo i1 = infos1[i]; |
| 344 | CallForwardInfo i2 = infos2[i]; |
| 345 | if (i1.status != i2.status || |
| 346 | i1.reason != i2.reason || |
| 347 | i1.serviceClass != i2.serviceClass || |
| 348 | i1.toa != i2.toa || |
| 349 | i1.number != i2.number || |
| 350 | i1.timeSeconds != i2.timeSeconds) { |
| 351 | return false; |
| 352 | } |
| 353 | } |
| 354 | return true; |
| 355 | } |
| 356 | |
| 357 | @Override |
| 358 | public String toString() { |
| 359 | return voicemailNumber + ((forwardingSettings != null ) ? (", " + |
| 360 | forwardingSettings.toString()) : ""); |
| 361 | } |
| 362 | |
| 363 | public String voicemailNumber; |
| 364 | public CallForwardInfo[] forwardingSettings; |
| 365 | } |
| 366 | |
| 367 | private SharedPreferences mPerProviderSavedVMNumbers; |
| 368 | |
| 369 | /** |
| 370 | * Results of reading forwarding settings |
| 371 | */ |
| 372 | private CallForwardInfo[] mForwardingReadResults = null; |
| 373 | |
| 374 | /** |
| 375 | * Result of forwarding number change. |
| 376 | * Keys are reasons (eg. unconditional forwarding). |
| 377 | */ |
| 378 | private Map<Integer, AsyncResult> mForwardingChangeResults = null; |
| 379 | |
| 380 | /** |
| 381 | * Expected CF read result types. |
| 382 | * This set keeps track of the CF types for which we've issued change |
| 383 | * commands so we can tell when we've received all of the responses. |
| 384 | */ |
| 385 | private Collection<Integer> mExpectedChangeResultReasons = null; |
| 386 | |
| 387 | /** |
| 388 | * Result of vm number change |
| 389 | */ |
| 390 | private AsyncResult mVoicemailChangeResult = null; |
| 391 | |
| 392 | /** |
| 393 | * Previous VM provider setting so we can return to it in case of failure. |
| 394 | */ |
| 395 | private String mPreviousVMProviderKey = null; |
| 396 | |
| 397 | /** |
| 398 | * Id of the dialog being currently shown. |
| 399 | */ |
| 400 | private int mCurrentDialogId = 0; |
| 401 | |
| 402 | /** |
| 403 | * Flag indicating that we are invoking settings for the voicemail provider programmatically |
| 404 | * due to vm provider change. |
| 405 | */ |
| 406 | private boolean mVMProviderSettingsForced = false; |
| 407 | |
| 408 | /** |
| 409 | * Flag indicating that we are making changes to vm or fwd numbers |
| 410 | * due to vm provider change. |
| 411 | */ |
| 412 | private boolean mChangingVMorFwdDueToProviderChange = false; |
| 413 | |
| 414 | /** |
| 415 | * True if we are in the process of vm & fwd number change and vm has already been changed. |
| 416 | * This is used to decide what to do in case of rollback. |
| 417 | */ |
| 418 | private boolean mVMChangeCompletedSuccessfully = false; |
| 419 | |
| 420 | /** |
| 421 | * True if we had full or partial failure setting forwarding numbers and so need to roll them |
| 422 | * back. |
| 423 | */ |
| 424 | private boolean mFwdChangesRequireRollback = false; |
| 425 | |
| 426 | /** |
| 427 | * Id of error msg to display to user once we are done reverting the VM provider to the previous |
| 428 | * one. |
| 429 | */ |
| 430 | private int mVMOrFwdSetError = 0; |
| 431 | |
| 432 | /** |
| 433 | * Data about discovered voice mail settings providers. |
| 434 | * Is populated by querying which activities can handle ACTION_CONFIGURE_VOICEMAIL. |
| 435 | * They key in this map is package name + activity name. |
| 436 | * We always add an entry for the default provider with a key of empty |
| 437 | * string and intent value of null. |
| 438 | * @see #initVoiceMailProviders() |
| 439 | */ |
| 440 | private final Map<String, VoiceMailProvider> mVMProvidersData = |
| 441 | new HashMap<String, VoiceMailProvider>(); |
| 442 | |
| 443 | /** string to hold old voicemail number as it is being updated. */ |
| 444 | private String mOldVmNumber; |
| 445 | |
| 446 | // New call forwarding settings and vm number we will be setting |
| 447 | // Need to save these since before we get to saving we need to asynchronously |
| 448 | // query the existing forwarding settings. |
| 449 | private CallForwardInfo[] mNewFwdSettings; |
| 450 | private String mNewVMNumber; |
| 451 | |
| 452 | private boolean mForeground; |
| 453 | |
| 454 | @Override |
| 455 | public void onPause() { |
| 456 | super.onPause(); |
| 457 | mForeground = false; |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * We have to pull current settings from the network for all kinds of |
| 462 | * voicemail providers so we can tell whether we have to update them, |
| 463 | * so use this bit to keep track of whether we're reading settings for the |
| 464 | * default provider and should therefore save them out when done. |
| 465 | */ |
| 466 | private boolean mReadingSettingsForDefaultProvider = false; |
| 467 | |
Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame^] | 468 | /** |
| 469 | * Used to indicate that the voicemail preference should be shown. |
| 470 | */ |
| 471 | private boolean mShowVoicemailPreference = false; |
| 472 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 473 | /* |
| 474 | * Click Listeners, handle click based on objects attached to UI. |
| 475 | */ |
| 476 | |
| 477 | // Click listener for all toggle events |
| 478 | @Override |
| 479 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
| 480 | if (preference == mSubMenuVoicemailSettings) { |
| 481 | return true; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 482 | } else if (preference == mButtonDTMF) { |
| 483 | return true; |
| 484 | } else if (preference == mButtonTTY) { |
| 485 | return true; |
| 486 | } else if (preference == mButtonAutoRetry) { |
| 487 | android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
| 488 | android.provider.Settings.Global.CALL_AUTO_RETRY, |
| 489 | mButtonAutoRetry.isChecked() ? 1 : 0); |
| 490 | return true; |
| 491 | } else if (preference == mButtonHAC) { |
| 492 | int hac = mButtonHAC.isChecked() ? 1 : 0; |
| 493 | // Update HAC value in Settings database |
| 494 | Settings.System.putInt(mPhone.getContext().getContentResolver(), |
| 495 | Settings.System.HEARING_AID, hac); |
| 496 | |
| 497 | // Update HAC Value in AudioManager |
| 498 | mAudioManager.setParameter(HAC_KEY, hac != 0 ? HAC_VAL_ON : HAC_VAL_OFF); |
| 499 | return true; |
| 500 | } else if (preference == mVoicemailSettings) { |
| 501 | if (DBG) log("onPreferenceTreeClick: Voicemail Settings Preference is clicked."); |
| 502 | if (preference.getIntent() != null) { |
| 503 | if (DBG) { |
| 504 | log("onPreferenceTreeClick: Invoking cfg intent " |
| 505 | + preference.getIntent().getPackage()); |
| 506 | } |
| 507 | |
| 508 | // onActivityResult() will be responsible for resetting some of variables. |
| 509 | this.startActivityForResult(preference.getIntent(), VOICEMAIL_PROVIDER_CFG_ID); |
| 510 | return true; |
| 511 | } else { |
| 512 | if (DBG) { |
| 513 | log("onPreferenceTreeClick:" |
| 514 | + " No Intent is available. Use default behavior defined in xml."); |
| 515 | } |
| 516 | |
| 517 | // There's no onActivityResult(), so we need to take care of some of variables |
| 518 | // which should be reset here. |
| 519 | mPreviousVMProviderKey = DEFAULT_VM_PROVIDER_KEY; |
| 520 | mVMProviderSettingsForced = false; |
| 521 | |
| 522 | // This should let the preference use default behavior in the xml. |
| 523 | return false; |
| 524 | } |
| 525 | } |
| 526 | return false; |
| 527 | } |
| 528 | |
| 529 | /** |
| 530 | * Implemented to support onPreferenceChangeListener to look for preference |
| 531 | * changes. |
| 532 | * |
| 533 | * @param preference is the preference to be changed |
| 534 | * @param objValue should be the value of the selection, NOT its localized |
| 535 | * display value. |
| 536 | */ |
| 537 | @Override |
| 538 | public boolean onPreferenceChange(Preference preference, Object objValue) { |
| 539 | if (DBG) { |
| 540 | log("onPreferenceChange(). preferenece: \"" + preference + "\"" |
| 541 | + ", value: \"" + objValue + "\""); |
| 542 | } |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 543 | |
| 544 | if (preference == mButtonDTMF) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 545 | int index = mButtonDTMF.findIndexOfValue((String) objValue); |
| 546 | Settings.System.putInt(mPhone.getContext().getContentResolver(), |
| 547 | Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, index); |
| 548 | } else if (preference == mButtonTTY) { |
| 549 | handleTTYChange(preference, objValue); |
| 550 | } else if (preference == mVoicemailProviders) { |
| 551 | final String newProviderKey = (String) objValue; |
| 552 | if (DBG) { |
| 553 | log("Voicemail Provider changes from \"" + mPreviousVMProviderKey |
| 554 | + "\" to \"" + newProviderKey + "\"."); |
| 555 | } |
| 556 | // If previous provider key and the new one is same, we don't need to handle it. |
| 557 | if (mPreviousVMProviderKey.equals(newProviderKey)) { |
| 558 | if (DBG) log("No change is made toward VM provider setting."); |
| 559 | return true; |
| 560 | } |
| 561 | updateVMPreferenceWidgets(newProviderKey); |
| 562 | |
| 563 | final VoiceMailProviderSettings newProviderSettings = |
| 564 | loadSettingsForVoiceMailProvider(newProviderKey); |
| 565 | |
| 566 | // If the user switches to a voice mail provider and we have a |
| 567 | // numbers stored for it we will automatically change the |
| 568 | // phone's |
| 569 | // voice mail and forwarding number to the stored ones. |
| 570 | // Otherwise we will bring up provider's configuration UI. |
| 571 | |
| 572 | if (newProviderSettings == null) { |
| 573 | // Force the user into a configuration of the chosen provider |
| 574 | Log.w(LOG_TAG, "Saved preferences not found - invoking config"); |
| 575 | mVMProviderSettingsForced = true; |
| 576 | simulatePreferenceClick(mVoicemailSettings); |
| 577 | } else { |
| 578 | if (DBG) log("Saved preferences found - switching to them"); |
| 579 | // Set this flag so if we get a failure we revert to previous provider |
| 580 | mChangingVMorFwdDueToProviderChange = true; |
| 581 | saveVoiceMailAndForwardingNumber(newProviderKey, newProviderSettings); |
| 582 | } |
| 583 | } else if (preference == mButtonSipCallOptions) { |
| 584 | handleSipCallOptionsChange(objValue); |
| 585 | } |
| 586 | // always let the preference setting proceed. |
| 587 | return true; |
| 588 | } |
| 589 | |
| 590 | @Override |
Evan Charlton | 1c69683 | 2014-04-15 14:24:23 -0700 | [diff] [blame] | 591 | public boolean onPreferenceClick(Preference preference) { |
| 592 | if (preference == mWifiCallOptionsPreference || preference == mWifiCallAccountPreference) { |
| 593 | handleWifiCallSettingsClick(preference); |
| 594 | } |
| 595 | return true; |
| 596 | } |
| 597 | |
| 598 | @Override |
Andrew Lee | db2fe56 | 2014-09-03 15:40:43 -0700 | [diff] [blame] | 599 | public boolean onAccountSelected(AccountSelectionPreference pref, PhoneAccountHandle account) { |
| 600 | TelecommManager telecommManager = TelecommManager.from(this); |
| 601 | if (pref == mDefaultOutgoingAccount) { |
| 602 | telecommManager.setUserSelectedOutgoingPhoneAccount(account); |
| 603 | return true; |
| 604 | } else if (pref == mSimCallManagerAccount) { |
| 605 | telecommManager.setSimCallManager(account); |
| 606 | return true; |
| 607 | } |
| 608 | return false; |
| 609 | } |
| 610 | |
Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame^] | 611 | /** |
| 612 | * Called just prior to showing an AccountSelection dialog to re-populate the model of the |
| 613 | * AccountSelection dialog. Important to ensure changes to the enabled state of |
| 614 | * {@code PhoneAccount}s are reflected in the dialog. |
| 615 | * |
| 616 | * @param pref The account selection preference dialog being shown. |
| 617 | */ |
| 618 | @Override |
| 619 | public void onAccountSelectionDialogShow(AccountSelectionPreference pref) { |
| 620 | if (pref == mDefaultOutgoingAccount) { |
| 621 | populateDefaultOutgoingAccountsModel(); |
| 622 | } else if (pref == mSimCallManagerAccount) { |
| 623 | populateSimCallManagerAccountsModel(); |
| 624 | } |
| 625 | } |
| 626 | |
Andrew Lee | db2fe56 | 2014-09-03 15:40:43 -0700 | [diff] [blame] | 627 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 628 | public void onDialogClosed(EditPhoneNumberPreference preference, int buttonClicked) { |
| 629 | if (DBG) log("onPreferenceClick: request preference click on dialog close: " + |
| 630 | buttonClicked); |
| 631 | if (buttonClicked == DialogInterface.BUTTON_NEGATIVE) { |
| 632 | return; |
| 633 | } |
| 634 | |
| 635 | if (preference == mSubMenuVoicemailSettings) { |
| 636 | handleVMBtnClickRequest(); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * Implemented for EditPhoneNumberPreference.GetDefaultNumberListener. |
| 642 | * This method set the default values for the various |
| 643 | * EditPhoneNumberPreference dialogs. |
| 644 | */ |
| 645 | @Override |
| 646 | public String onGetDefaultNumber(EditPhoneNumberPreference preference) { |
| 647 | if (preference == mSubMenuVoicemailSettings) { |
| 648 | // update the voicemail number field, which takes care of the |
| 649 | // mSubMenuVoicemailSettings itself, so we should return null. |
| 650 | if (DBG) log("updating default for voicemail dialog"); |
| 651 | updateVoiceNumberField(); |
| 652 | return null; |
| 653 | } |
| 654 | |
| 655 | String vmDisplay = mPhone.getVoiceMailNumber(); |
| 656 | if (TextUtils.isEmpty(vmDisplay)) { |
| 657 | // if there is no voicemail number, we just return null to |
| 658 | // indicate no contribution. |
| 659 | return null; |
| 660 | } |
| 661 | |
| 662 | // Return the voicemail number prepended with "VM: " |
| 663 | if (DBG) log("updating default for call forwarding dialogs"); |
| 664 | return getString(R.string.voicemail_abbreviated) + " " + vmDisplay; |
| 665 | } |
| 666 | |
| 667 | |
| 668 | // override the startsubactivity call to make changes in state consistent. |
| 669 | @Override |
| 670 | public void startActivityForResult(Intent intent, int requestCode) { |
| 671 | if (requestCode == -1) { |
| 672 | // this is an intent requested from the preference framework. |
| 673 | super.startActivityForResult(intent, requestCode); |
| 674 | return; |
| 675 | } |
| 676 | |
| 677 | if (DBG) log("startSubActivity: starting requested subactivity"); |
| 678 | super.startActivityForResult(intent, requestCode); |
| 679 | } |
| 680 | |
| 681 | private void switchToPreviousVoicemailProvider() { |
| 682 | if (DBG) log("switchToPreviousVoicemailProvider " + mPreviousVMProviderKey); |
| 683 | if (mPreviousVMProviderKey != null) { |
| 684 | if (mVMChangeCompletedSuccessfully || mFwdChangesRequireRollback) { |
| 685 | // we have to revert with carrier |
| 686 | if (DBG) { |
| 687 | log("Needs to rollback." |
| 688 | + " mVMChangeCompletedSuccessfully=" + mVMChangeCompletedSuccessfully |
| 689 | + ", mFwdChangesRequireRollback=" + mFwdChangesRequireRollback); |
| 690 | } |
| 691 | |
| 692 | showDialogIfForeground(VOICEMAIL_REVERTING_DIALOG); |
| 693 | final VoiceMailProviderSettings prevSettings = |
| 694 | loadSettingsForVoiceMailProvider(mPreviousVMProviderKey); |
| 695 | if (prevSettings == null) { |
| 696 | // prevSettings never becomes null since it should be already loaded! |
| 697 | Log.e(LOG_TAG, "VoiceMailProviderSettings for the key \"" |
| 698 | + mPreviousVMProviderKey + "\" becomes null, which is unexpected."); |
| 699 | if (DBG) { |
| 700 | Log.e(LOG_TAG, |
| 701 | "mVMChangeCompletedSuccessfully: " + mVMChangeCompletedSuccessfully |
| 702 | + ", mFwdChangesRequireRollback: " + mFwdChangesRequireRollback); |
| 703 | } |
| 704 | } |
| 705 | if (mVMChangeCompletedSuccessfully) { |
| 706 | mNewVMNumber = prevSettings.voicemailNumber; |
| 707 | Log.i(LOG_TAG, "VM change is already completed successfully." |
| 708 | + "Have to revert VM back to " + mNewVMNumber + " again."); |
| 709 | mPhone.setVoiceMailNumber( |
| 710 | mPhone.getVoiceMailAlphaTag().toString(), |
| 711 | mNewVMNumber, |
| 712 | Message.obtain(mRevertOptionComplete, EVENT_VOICEMAIL_CHANGED)); |
| 713 | } |
| 714 | if (mFwdChangesRequireRollback) { |
| 715 | Log.i(LOG_TAG, "Requested to rollback Fwd changes."); |
| 716 | final CallForwardInfo[] prevFwdSettings = |
| 717 | prevSettings.forwardingSettings; |
| 718 | if (prevFwdSettings != null) { |
| 719 | Map<Integer, AsyncResult> results = |
| 720 | mForwardingChangeResults; |
| 721 | resetForwardingChangeState(); |
| 722 | for (int i = 0; i < prevFwdSettings.length; i++) { |
| 723 | CallForwardInfo fi = prevFwdSettings[i]; |
| 724 | if (DBG) log("Reverting fwd #: " + i + ": " + fi.toString()); |
| 725 | // Only revert the settings for which the update |
| 726 | // succeeded |
| 727 | AsyncResult result = results.get(fi.reason); |
| 728 | if (result != null && result.exception == null) { |
| 729 | mExpectedChangeResultReasons.add(fi.reason); |
| 730 | mPhone.setCallForwardingOption( |
| 731 | (fi.status == 1 ? |
| 732 | CommandsInterface.CF_ACTION_REGISTRATION : |
| 733 | CommandsInterface.CF_ACTION_DISABLE), |
| 734 | fi.reason, |
| 735 | fi.number, |
| 736 | fi.timeSeconds, |
| 737 | mRevertOptionComplete.obtainMessage( |
| 738 | EVENT_FORWARDING_CHANGED, i, 0)); |
| 739 | } |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | } else { |
| 744 | if (DBG) log("No need to revert"); |
| 745 | onRevertDone(); |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | private void onRevertDone() { |
| 751 | if (DBG) log("Flipping provider key back to " + mPreviousVMProviderKey); |
| 752 | mVoicemailProviders.setValue(mPreviousVMProviderKey); |
| 753 | updateVMPreferenceWidgets(mPreviousVMProviderKey); |
| 754 | updateVoiceNumberField(); |
| 755 | if (mVMOrFwdSetError != 0) { |
| 756 | showVMDialog(mVMOrFwdSetError); |
| 757 | mVMOrFwdSetError = 0; |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | @Override |
| 762 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 763 | if (DBG) { |
| 764 | log("onActivityResult: requestCode: " + requestCode |
| 765 | + ", resultCode: " + resultCode |
| 766 | + ", data: " + data); |
| 767 | } |
| 768 | // there are cases where the contact picker may end up sending us more than one |
| 769 | // request. We want to ignore the request if we're not in the correct state. |
| 770 | if (requestCode == VOICEMAIL_PROVIDER_CFG_ID) { |
| 771 | boolean failure = false; |
| 772 | |
| 773 | // No matter how the processing of result goes lets clear the flag |
| 774 | if (DBG) log("mVMProviderSettingsForced: " + mVMProviderSettingsForced); |
| 775 | final boolean isVMProviderSettingsForced = mVMProviderSettingsForced; |
| 776 | mVMProviderSettingsForced = false; |
| 777 | |
| 778 | String vmNum = null; |
| 779 | if (resultCode != RESULT_OK) { |
| 780 | if (DBG) log("onActivityResult: vm provider cfg result not OK."); |
| 781 | failure = true; |
| 782 | } else { |
| 783 | if (data == null) { |
| 784 | if (DBG) log("onActivityResult: vm provider cfg result has no data"); |
| 785 | failure = true; |
| 786 | } else { |
| 787 | if (data.getBooleanExtra(SIGNOUT_EXTRA, false)) { |
| 788 | if (DBG) log("Provider requested signout"); |
| 789 | if (isVMProviderSettingsForced) { |
| 790 | if (DBG) log("Going back to previous provider on signout"); |
| 791 | switchToPreviousVoicemailProvider(); |
| 792 | } else { |
| 793 | final String victim = getCurrentVoicemailProviderKey(); |
| 794 | if (DBG) log("Relaunching activity and ignoring " + victim); |
| 795 | Intent i = new Intent(ACTION_ADD_VOICEMAIL); |
| 796 | i.putExtra(IGNORE_PROVIDER_EXTRA, victim); |
| 797 | i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 798 | this.startActivity(i); |
| 799 | } |
| 800 | return; |
| 801 | } |
| 802 | vmNum = data.getStringExtra(VM_NUMBER_EXTRA); |
| 803 | if (vmNum == null || vmNum.length() == 0) { |
| 804 | if (DBG) log("onActivityResult: vm provider cfg result has no vmnum"); |
| 805 | failure = true; |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | if (failure) { |
| 810 | if (DBG) log("Failure in return from voicemail provider"); |
| 811 | if (isVMProviderSettingsForced) { |
| 812 | switchToPreviousVoicemailProvider(); |
| 813 | } else { |
| 814 | if (DBG) log("Not switching back the provider since this is not forced config"); |
| 815 | } |
| 816 | return; |
| 817 | } |
| 818 | mChangingVMorFwdDueToProviderChange = isVMProviderSettingsForced; |
| 819 | final String fwdNum = data.getStringExtra(FWD_NUMBER_EXTRA); |
| 820 | |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 821 | // 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] | 822 | // send it to the provider when it's config is invoked so it can use this as default |
| 823 | final int fwdNumTime = data.getIntExtra(FWD_NUMBER_TIME_EXTRA, 20); |
| 824 | |
| 825 | if (DBG) log("onActivityResult: vm provider cfg result " + |
| 826 | (fwdNum != null ? "has" : " does not have") + " forwarding number"); |
| 827 | saveVoiceMailAndForwardingNumber(getCurrentVoicemailProviderKey(), |
| 828 | new VoiceMailProviderSettings(vmNum, fwdNum, fwdNumTime)); |
| 829 | return; |
| 830 | } |
| 831 | |
| 832 | if (requestCode == VOICEMAIL_PREF_ID) { |
| 833 | if (resultCode != RESULT_OK) { |
| 834 | if (DBG) log("onActivityResult: contact picker result not OK."); |
| 835 | return; |
| 836 | } |
| 837 | |
| 838 | Cursor cursor = null; |
| 839 | try { |
| 840 | cursor = getContentResolver().query(data.getData(), |
| 841 | NUM_PROJECTION, null, null, null); |
| 842 | if ((cursor == null) || (!cursor.moveToFirst())) { |
| 843 | if (DBG) log("onActivityResult: bad contact data, no results found."); |
| 844 | return; |
| 845 | } |
| 846 | mSubMenuVoicemailSettings.onPickActivityResult(cursor.getString(0)); |
| 847 | return; |
| 848 | } finally { |
| 849 | if (cursor != null) { |
| 850 | cursor.close(); |
| 851 | } |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | super.onActivityResult(requestCode, resultCode, data); |
| 856 | } |
| 857 | |
| 858 | // Voicemail button logic |
| 859 | private void handleVMBtnClickRequest() { |
| 860 | // normally called on the dialog close. |
| 861 | |
| 862 | // Since we're stripping the formatting out on the getPhoneNumber() |
| 863 | // call now, we won't need to do so here anymore. |
| 864 | |
| 865 | saveVoiceMailAndForwardingNumber( |
| 866 | getCurrentVoicemailProviderKey(), |
| 867 | new VoiceMailProviderSettings(mSubMenuVoicemailSettings.getPhoneNumber(), |
| 868 | FWD_SETTINGS_DONT_TOUCH)); |
| 869 | } |
| 870 | |
| 871 | |
| 872 | /** |
| 873 | * Wrapper around showDialog() that will silently do nothing if we're |
| 874 | * not in the foreground. |
| 875 | * |
| 876 | * This is useful here because most of the dialogs we display from |
| 877 | * this class are triggered by asynchronous events (like |
| 878 | * success/failure messages from the telephony layer) and it's |
| 879 | * possible for those events to come in even after the user has gone |
| 880 | * to a different screen. |
| 881 | */ |
| 882 | // TODO: this is too brittle: it's still easy to accidentally add new |
| 883 | // code here that calls showDialog() directly (which will result in a |
| 884 | // WindowManager$BadTokenException if called after the activity has |
| 885 | // been stopped.) |
| 886 | // |
| 887 | // It would be cleaner to do the "if (mForeground)" check in one |
| 888 | // central place, maybe by using a single Handler for all asynchronous |
| 889 | // events (and have *that* discard events if we're not in the |
| 890 | // foreground.) |
| 891 | // |
| 892 | // Unfortunately it's not that simple, since we sometimes need to do |
| 893 | // actual work to handle these events whether or not we're in the |
| 894 | // foreground (see the Handler code in mSetOptionComplete for |
| 895 | // example.) |
| 896 | private void showDialogIfForeground(int id) { |
| 897 | if (mForeground) { |
| 898 | showDialog(id); |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | private void dismissDialogSafely(int id) { |
| 903 | try { |
| 904 | dismissDialog(id); |
| 905 | } catch (IllegalArgumentException e) { |
| 906 | // This is expected in the case where we were in the background |
| 907 | // at the time we would normally have shown the dialog, so we didn't |
| 908 | // show it. |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | private void saveVoiceMailAndForwardingNumber(String key, |
| 913 | VoiceMailProviderSettings newSettings) { |
| 914 | if (DBG) log("saveVoiceMailAndForwardingNumber: " + newSettings.toString()); |
| 915 | mNewVMNumber = newSettings.voicemailNumber; |
| 916 | // empty vm number == clearing the vm number ? |
| 917 | if (mNewVMNumber == null) { |
| 918 | mNewVMNumber = ""; |
| 919 | } |
| 920 | |
| 921 | mNewFwdSettings = newSettings.forwardingSettings; |
| 922 | if (DBG) log("newFwdNumber " + |
| 923 | String.valueOf((mNewFwdSettings != null ? mNewFwdSettings.length : 0)) |
| 924 | + " settings"); |
| 925 | |
| 926 | // No fwd settings on CDMA |
| 927 | if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 928 | if (DBG) log("ignoring forwarding setting since this is CDMA phone"); |
| 929 | mNewFwdSettings = FWD_SETTINGS_DONT_TOUCH; |
| 930 | } |
| 931 | |
| 932 | //throw a warning if the vm is the same and we do not touch forwarding. |
| 933 | if (mNewVMNumber.equals(mOldVmNumber) && mNewFwdSettings == FWD_SETTINGS_DONT_TOUCH) { |
| 934 | showVMDialog(MSG_VM_NOCHANGE); |
| 935 | return; |
| 936 | } |
| 937 | |
| 938 | maybeSaveSettingsForVoicemailProvider(key, newSettings); |
| 939 | mVMChangeCompletedSuccessfully = false; |
| 940 | mFwdChangesRequireRollback = false; |
| 941 | mVMOrFwdSetError = 0; |
| 942 | if (!key.equals(mPreviousVMProviderKey)) { |
| 943 | mReadingSettingsForDefaultProvider = |
| 944 | mPreviousVMProviderKey.equals(DEFAULT_VM_PROVIDER_KEY); |
| 945 | if (DBG) log("Reading current forwarding settings"); |
| 946 | mForwardingReadResults = new CallForwardInfo[FORWARDING_SETTINGS_REASONS.length]; |
| 947 | for (int i = 0; i < FORWARDING_SETTINGS_REASONS.length; i++) { |
| 948 | mForwardingReadResults[i] = null; |
| 949 | mPhone.getCallForwardingOption(FORWARDING_SETTINGS_REASONS[i], |
| 950 | mGetOptionComplete.obtainMessage(EVENT_FORWARDING_GET_COMPLETED, i, 0)); |
| 951 | } |
| 952 | showDialogIfForeground(VOICEMAIL_FWD_READING_DIALOG); |
| 953 | } else { |
| 954 | saveVoiceMailAndForwardingNumberStage2(); |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | private final Handler mGetOptionComplete = new Handler() { |
| 959 | @Override |
| 960 | public void handleMessage(Message msg) { |
| 961 | AsyncResult result = (AsyncResult) msg.obj; |
| 962 | switch (msg.what) { |
| 963 | case EVENT_FORWARDING_GET_COMPLETED: |
| 964 | handleForwardingSettingsReadResult(result, msg.arg1); |
| 965 | break; |
| 966 | } |
| 967 | } |
| 968 | }; |
| 969 | |
| 970 | private void handleForwardingSettingsReadResult(AsyncResult ar, int idx) { |
| 971 | if (DBG) Log.d(LOG_TAG, "handleForwardingSettingsReadResult: " + idx); |
| 972 | Throwable error = null; |
| 973 | if (ar.exception != null) { |
| 974 | if (DBG) Log.d(LOG_TAG, "FwdRead: ar.exception=" + |
| 975 | ar.exception.getMessage()); |
| 976 | error = ar.exception; |
| 977 | } |
| 978 | if (ar.userObj instanceof Throwable) { |
| 979 | if (DBG) Log.d(LOG_TAG, "FwdRead: userObj=" + |
| 980 | ((Throwable)ar.userObj).getMessage()); |
| 981 | error = (Throwable)ar.userObj; |
| 982 | } |
| 983 | |
| 984 | // We may have already gotten an error and decided to ignore the other results. |
| 985 | if (mForwardingReadResults == null) { |
| 986 | if (DBG) Log.d(LOG_TAG, "ignoring fwd reading result: " + idx); |
| 987 | return; |
| 988 | } |
| 989 | |
| 990 | // In case of error ignore other results, show an error dialog |
| 991 | if (error != null) { |
| 992 | if (DBG) Log.d(LOG_TAG, "Error discovered for fwd read : " + idx); |
| 993 | mForwardingReadResults = null; |
| 994 | dismissDialogSafely(VOICEMAIL_FWD_READING_DIALOG); |
| 995 | showVMDialog(MSG_FW_GET_EXCEPTION); |
| 996 | return; |
| 997 | } |
| 998 | |
| 999 | // Get the forwarding info |
| 1000 | final CallForwardInfo cfInfoArray[] = (CallForwardInfo[]) ar.result; |
| 1001 | CallForwardInfo fi = null; |
| 1002 | for (int i = 0 ; i < cfInfoArray.length; i++) { |
| 1003 | if ((cfInfoArray[i].serviceClass & CommandsInterface.SERVICE_CLASS_VOICE) != 0) { |
| 1004 | fi = cfInfoArray[i]; |
| 1005 | break; |
| 1006 | } |
| 1007 | } |
| 1008 | if (fi == null) { |
| 1009 | |
| 1010 | // In case we go nothing it means we need this reason disabled |
| 1011 | // so create a CallForwardInfo for capturing this |
| 1012 | if (DBG) Log.d(LOG_TAG, "Creating default info for " + idx); |
| 1013 | fi = new CallForwardInfo(); |
| 1014 | fi.status = 0; |
| 1015 | fi.reason = FORWARDING_SETTINGS_REASONS[idx]; |
| 1016 | fi.serviceClass = CommandsInterface.SERVICE_CLASS_VOICE; |
| 1017 | } else { |
| 1018 | // if there is not a forwarding number, ensure the entry is set to "not active." |
| 1019 | if (fi.number == null || fi.number.length() == 0) { |
| 1020 | fi.status = 0; |
| 1021 | } |
| 1022 | |
| 1023 | if (DBG) Log.d(LOG_TAG, "Got " + fi.toString() + " for " + idx); |
| 1024 | } |
| 1025 | mForwardingReadResults[idx] = fi; |
| 1026 | |
| 1027 | // Check if we got all the results already |
| 1028 | boolean done = true; |
| 1029 | for (int i = 0; i < mForwardingReadResults.length; i++) { |
| 1030 | if (mForwardingReadResults[i] == null) { |
| 1031 | done = false; |
| 1032 | break; |
| 1033 | } |
| 1034 | } |
| 1035 | if (done) { |
| 1036 | if (DBG) Log.d(LOG_TAG, "Done receiving fwd info"); |
| 1037 | dismissDialogSafely(VOICEMAIL_FWD_READING_DIALOG); |
| 1038 | if (mReadingSettingsForDefaultProvider) { |
| 1039 | maybeSaveSettingsForVoicemailProvider(DEFAULT_VM_PROVIDER_KEY, |
| 1040 | new VoiceMailProviderSettings(this.mOldVmNumber, |
| 1041 | mForwardingReadResults)); |
| 1042 | mReadingSettingsForDefaultProvider = false; |
| 1043 | } |
| 1044 | saveVoiceMailAndForwardingNumberStage2(); |
| 1045 | } else { |
| 1046 | if (DBG) Log.d(LOG_TAG, "Not done receiving fwd info"); |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | private CallForwardInfo infoForReason(CallForwardInfo[] infos, int reason) { |
| 1051 | CallForwardInfo result = null; |
| 1052 | if (null != infos) { |
| 1053 | for (CallForwardInfo info : infos) { |
| 1054 | if (info.reason == reason) { |
| 1055 | result = info; |
| 1056 | break; |
| 1057 | } |
| 1058 | } |
| 1059 | } |
| 1060 | return result; |
| 1061 | } |
| 1062 | |
| 1063 | private boolean isUpdateRequired(CallForwardInfo oldInfo, |
| 1064 | CallForwardInfo newInfo) { |
| 1065 | boolean result = true; |
| 1066 | if (0 == newInfo.status) { |
| 1067 | // If we're disabling a type of forwarding, and it's already |
| 1068 | // disabled for the account, don't make any change |
| 1069 | if (oldInfo != null && oldInfo.status == 0) { |
| 1070 | result = false; |
| 1071 | } |
| 1072 | } |
| 1073 | return result; |
| 1074 | } |
| 1075 | |
| 1076 | private void resetForwardingChangeState() { |
| 1077 | mForwardingChangeResults = new HashMap<Integer, AsyncResult>(); |
| 1078 | mExpectedChangeResultReasons = new HashSet<Integer>(); |
| 1079 | } |
| 1080 | |
| 1081 | // Called after we are done saving the previous forwarding settings if |
| 1082 | // we needed. |
| 1083 | private void saveVoiceMailAndForwardingNumberStage2() { |
| 1084 | mForwardingChangeResults = null; |
| 1085 | mVoicemailChangeResult = null; |
| 1086 | if (mNewFwdSettings != FWD_SETTINGS_DONT_TOUCH) { |
| 1087 | resetForwardingChangeState(); |
| 1088 | for (int i = 0; i < mNewFwdSettings.length; i++) { |
| 1089 | CallForwardInfo fi = mNewFwdSettings[i]; |
| 1090 | |
| 1091 | final boolean doUpdate = isUpdateRequired(infoForReason( |
| 1092 | mForwardingReadResults, fi.reason), fi); |
| 1093 | |
| 1094 | if (doUpdate) { |
| 1095 | if (DBG) log("Setting fwd #: " + i + ": " + fi.toString()); |
| 1096 | mExpectedChangeResultReasons.add(i); |
| 1097 | |
| 1098 | mPhone.setCallForwardingOption( |
| 1099 | fi.status == 1 ? |
| 1100 | CommandsInterface.CF_ACTION_REGISTRATION : |
| 1101 | CommandsInterface.CF_ACTION_DISABLE, |
| 1102 | fi.reason, |
| 1103 | fi.number, |
| 1104 | fi.timeSeconds, |
| 1105 | mSetOptionComplete.obtainMessage( |
| 1106 | EVENT_FORWARDING_CHANGED, fi.reason, 0)); |
| 1107 | } |
| 1108 | } |
| 1109 | showDialogIfForeground(VOICEMAIL_FWD_SAVING_DIALOG); |
| 1110 | } else { |
| 1111 | if (DBG) log("Not touching fwd #"); |
| 1112 | setVMNumberWithCarrier(); |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | private void setVMNumberWithCarrier() { |
| 1117 | if (DBG) log("save voicemail #: " + mNewVMNumber); |
| 1118 | mPhone.setVoiceMailNumber( |
| 1119 | mPhone.getVoiceMailAlphaTag().toString(), |
| 1120 | mNewVMNumber, |
| 1121 | Message.obtain(mSetOptionComplete, EVENT_VOICEMAIL_CHANGED)); |
| 1122 | } |
| 1123 | |
| 1124 | /** |
| 1125 | * Callback to handle option update completions |
| 1126 | */ |
| 1127 | private final Handler mSetOptionComplete = new Handler() { |
| 1128 | @Override |
| 1129 | public void handleMessage(Message msg) { |
| 1130 | AsyncResult result = (AsyncResult) msg.obj; |
| 1131 | boolean done = false; |
| 1132 | switch (msg.what) { |
| 1133 | case EVENT_VOICEMAIL_CHANGED: |
| 1134 | mVoicemailChangeResult = result; |
| 1135 | mVMChangeCompletedSuccessfully = checkVMChangeSuccess() == null; |
| 1136 | if (DBG) log("VM change complete msg, VM change done = " + |
| 1137 | String.valueOf(mVMChangeCompletedSuccessfully)); |
| 1138 | done = true; |
| 1139 | break; |
| 1140 | case EVENT_FORWARDING_CHANGED: |
| 1141 | mForwardingChangeResults.put(msg.arg1, result); |
| 1142 | if (result.exception != null) { |
| 1143 | Log.w(LOG_TAG, "Error in setting fwd# " + msg.arg1 + ": " + |
| 1144 | result.exception.getMessage()); |
| 1145 | } else { |
| 1146 | if (DBG) log("Success in setting fwd# " + msg.arg1); |
| 1147 | } |
| 1148 | final boolean completed = checkForwardingCompleted(); |
| 1149 | if (completed) { |
| 1150 | if (checkFwdChangeSuccess() == null) { |
| 1151 | if (DBG) log("Overall fwd changes completed ok, starting vm change"); |
| 1152 | setVMNumberWithCarrier(); |
| 1153 | } else { |
| 1154 | Log.w(LOG_TAG, "Overall fwd changes completed in failure. " + |
| 1155 | "Check if we need to try rollback for some settings."); |
| 1156 | mFwdChangesRequireRollback = false; |
| 1157 | Iterator<Map.Entry<Integer,AsyncResult>> it = |
| 1158 | mForwardingChangeResults.entrySet().iterator(); |
| 1159 | while (it.hasNext()) { |
| 1160 | Map.Entry<Integer,AsyncResult> entry = it.next(); |
| 1161 | if (entry.getValue().exception == null) { |
| 1162 | // If at least one succeeded we have to revert |
| 1163 | Log.i(LOG_TAG, "Rollback will be required"); |
| 1164 | mFwdChangesRequireRollback = true; |
| 1165 | break; |
| 1166 | } |
| 1167 | } |
| 1168 | if (!mFwdChangesRequireRollback) { |
| 1169 | Log.i(LOG_TAG, "No rollback needed."); |
| 1170 | } |
| 1171 | done = true; |
| 1172 | } |
| 1173 | } |
| 1174 | break; |
| 1175 | default: |
| 1176 | // TODO: should never reach this, may want to throw exception |
| 1177 | } |
| 1178 | if (done) { |
| 1179 | if (DBG) log("All VM provider related changes done"); |
| 1180 | if (mForwardingChangeResults != null) { |
| 1181 | dismissDialogSafely(VOICEMAIL_FWD_SAVING_DIALOG); |
| 1182 | } |
| 1183 | handleSetVMOrFwdMessage(); |
| 1184 | } |
| 1185 | } |
| 1186 | }; |
| 1187 | |
| 1188 | /** |
| 1189 | * Callback to handle option revert completions |
| 1190 | */ |
| 1191 | private final Handler mRevertOptionComplete = new Handler() { |
| 1192 | @Override |
| 1193 | public void handleMessage(Message msg) { |
| 1194 | AsyncResult result = (AsyncResult) msg.obj; |
| 1195 | switch (msg.what) { |
| 1196 | case EVENT_VOICEMAIL_CHANGED: |
| 1197 | mVoicemailChangeResult = result; |
| 1198 | if (DBG) log("VM revert complete msg"); |
| 1199 | break; |
| 1200 | case EVENT_FORWARDING_CHANGED: |
| 1201 | mForwardingChangeResults.put(msg.arg1, result); |
| 1202 | if (result.exception != null) { |
| 1203 | if (DBG) log("Error in reverting fwd# " + msg.arg1 + ": " + |
| 1204 | result.exception.getMessage()); |
| 1205 | } else { |
| 1206 | if (DBG) log("Success in reverting fwd# " + msg.arg1); |
| 1207 | } |
| 1208 | if (DBG) log("FWD revert complete msg "); |
| 1209 | break; |
| 1210 | default: |
| 1211 | // TODO: should never reach this, may want to throw exception |
| 1212 | } |
| 1213 | final boolean done = |
| 1214 | (!mVMChangeCompletedSuccessfully || mVoicemailChangeResult != null) && |
| 1215 | (!mFwdChangesRequireRollback || checkForwardingCompleted()); |
| 1216 | if (done) { |
| 1217 | if (DBG) log("All VM reverts done"); |
| 1218 | dismissDialogSafely(VOICEMAIL_REVERTING_DIALOG); |
| 1219 | onRevertDone(); |
| 1220 | } |
| 1221 | } |
| 1222 | }; |
| 1223 | |
| 1224 | /** |
| 1225 | * @return true if forwarding change has completed |
| 1226 | */ |
| 1227 | private boolean checkForwardingCompleted() { |
| 1228 | boolean result; |
| 1229 | if (mForwardingChangeResults == null) { |
| 1230 | result = true; |
| 1231 | } else { |
| 1232 | // return true iff there is a change result for every reason for |
| 1233 | // which we expected a result |
| 1234 | result = true; |
| 1235 | for (Integer reason : mExpectedChangeResultReasons) { |
| 1236 | if (mForwardingChangeResults.get(reason) == null) { |
| 1237 | result = false; |
| 1238 | break; |
| 1239 | } |
| 1240 | } |
| 1241 | } |
| 1242 | return result; |
| 1243 | } |
| 1244 | /** |
| 1245 | * @return error string or null if successful |
| 1246 | */ |
| 1247 | private String checkFwdChangeSuccess() { |
| 1248 | String result = null; |
| 1249 | Iterator<Map.Entry<Integer,AsyncResult>> it = |
| 1250 | mForwardingChangeResults.entrySet().iterator(); |
| 1251 | while (it.hasNext()) { |
| 1252 | Map.Entry<Integer,AsyncResult> entry = it.next(); |
| 1253 | Throwable exception = entry.getValue().exception; |
| 1254 | if (exception != null) { |
| 1255 | result = exception.getMessage(); |
| 1256 | if (result == null) { |
| 1257 | result = ""; |
| 1258 | } |
| 1259 | break; |
| 1260 | } |
| 1261 | } |
| 1262 | return result; |
| 1263 | } |
| 1264 | |
| 1265 | /** |
| 1266 | * @return error string or null if successful |
| 1267 | */ |
| 1268 | private String checkVMChangeSuccess() { |
| 1269 | if (mVoicemailChangeResult.exception != null) { |
| 1270 | final String msg = mVoicemailChangeResult.exception.getMessage(); |
| 1271 | if (msg == null) { |
| 1272 | return ""; |
| 1273 | } |
| 1274 | return msg; |
| 1275 | } |
| 1276 | return null; |
| 1277 | } |
| 1278 | |
| 1279 | private void handleSetVMOrFwdMessage() { |
| 1280 | if (DBG) { |
| 1281 | log("handleSetVMMessage: set VM request complete"); |
| 1282 | } |
| 1283 | boolean success = true; |
| 1284 | boolean fwdFailure = false; |
| 1285 | String exceptionMessage = ""; |
| 1286 | if (mForwardingChangeResults != null) { |
| 1287 | exceptionMessage = checkFwdChangeSuccess(); |
| 1288 | if (exceptionMessage != null) { |
| 1289 | success = false; |
| 1290 | fwdFailure = true; |
| 1291 | } |
| 1292 | } |
| 1293 | if (success) { |
| 1294 | exceptionMessage = checkVMChangeSuccess(); |
| 1295 | if (exceptionMessage != null) { |
| 1296 | success = false; |
| 1297 | } |
| 1298 | } |
| 1299 | if (success) { |
| 1300 | if (DBG) log("change VM success!"); |
| 1301 | handleVMAndFwdSetSuccess(MSG_VM_OK); |
| 1302 | } else { |
| 1303 | if (fwdFailure) { |
| 1304 | Log.w(LOG_TAG, "Failed to change fowarding setting. Reason: " + exceptionMessage); |
| 1305 | handleVMOrFwdSetError(MSG_FW_SET_EXCEPTION); |
| 1306 | } else { |
| 1307 | Log.w(LOG_TAG, "Failed to change voicemail. Reason: " + exceptionMessage); |
| 1308 | handleVMOrFwdSetError(MSG_VM_EXCEPTION); |
| 1309 | } |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | /** |
| 1314 | * Called when Voicemail Provider or its forwarding settings failed. Rolls back partly made |
| 1315 | * changes to those settings and show "failure" dialog. |
| 1316 | * |
| 1317 | * @param msgId Message ID used for the specific error case. {@link #MSG_FW_SET_EXCEPTION} or |
| 1318 | * {@link #MSG_VM_EXCEPTION} |
| 1319 | */ |
| 1320 | private void handleVMOrFwdSetError(int msgId) { |
| 1321 | if (mChangingVMorFwdDueToProviderChange) { |
| 1322 | mVMOrFwdSetError = msgId; |
| 1323 | mChangingVMorFwdDueToProviderChange = false; |
| 1324 | switchToPreviousVoicemailProvider(); |
| 1325 | return; |
| 1326 | } |
| 1327 | mChangingVMorFwdDueToProviderChange = false; |
| 1328 | showVMDialog(msgId); |
| 1329 | updateVoiceNumberField(); |
| 1330 | } |
| 1331 | |
| 1332 | /** |
| 1333 | * Called when Voicemail Provider and its forwarding settings were successfully finished. |
| 1334 | * This updates a bunch of variables and show "success" dialog. |
| 1335 | */ |
| 1336 | private void handleVMAndFwdSetSuccess(int msg) { |
| 1337 | if (DBG) { |
| 1338 | log("handleVMAndFwdSetSuccess(). current voicemail provider key: " |
| 1339 | + getCurrentVoicemailProviderKey()); |
| 1340 | } |
| 1341 | mPreviousVMProviderKey = getCurrentVoicemailProviderKey(); |
| 1342 | mChangingVMorFwdDueToProviderChange = false; |
| 1343 | showVMDialog(msg); |
| 1344 | updateVoiceNumberField(); |
| 1345 | } |
| 1346 | |
| 1347 | /** |
| 1348 | * Update the voicemail number from what we've recorded on the sim. |
| 1349 | */ |
| 1350 | private void updateVoiceNumberField() { |
| 1351 | if (DBG) { |
| 1352 | log("updateVoiceNumberField(). mSubMenuVoicemailSettings=" + mSubMenuVoicemailSettings); |
| 1353 | } |
| 1354 | if (mSubMenuVoicemailSettings == null) { |
| 1355 | return; |
| 1356 | } |
| 1357 | |
| 1358 | mOldVmNumber = mPhone.getVoiceMailNumber(); |
| 1359 | if (mOldVmNumber == null) { |
| 1360 | mOldVmNumber = ""; |
| 1361 | } |
| 1362 | mSubMenuVoicemailSettings.setPhoneNumber(mOldVmNumber); |
| 1363 | final String summary = (mOldVmNumber.length() > 0) ? mOldVmNumber : |
| 1364 | getString(R.string.voicemail_number_not_set); |
| 1365 | mSubMenuVoicemailSettings.setSummary(summary); |
| 1366 | } |
| 1367 | |
| 1368 | /* |
| 1369 | * Helper Methods for Activity class. |
| 1370 | * The initial query commands are split into two pieces now |
| 1371 | * for individual expansion. This combined with the ability |
| 1372 | * to cancel queries allows for a much better user experience, |
| 1373 | * and also ensures that the user only waits to update the |
| 1374 | * data that is relevant. |
| 1375 | */ |
| 1376 | |
| 1377 | @Override |
| 1378 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 1379 | super.onPrepareDialog(id, dialog); |
| 1380 | mCurrentDialogId = id; |
| 1381 | } |
| 1382 | |
| 1383 | // dialog creation method, called by showDialog() |
| 1384 | @Override |
| 1385 | protected Dialog onCreateDialog(int id) { |
| 1386 | if ((id == VM_RESPONSE_ERROR) || (id == VM_NOCHANGE_ERROR) || |
| 1387 | (id == FW_SET_RESPONSE_ERROR) || (id == FW_GET_RESPONSE_ERROR) || |
| 1388 | (id == VOICEMAIL_DIALOG_CONFIRM)) { |
| 1389 | |
| 1390 | AlertDialog.Builder b = new AlertDialog.Builder(this); |
| 1391 | |
| 1392 | int msgId; |
| 1393 | int titleId = R.string.error_updating_title; |
| 1394 | switch (id) { |
| 1395 | case VOICEMAIL_DIALOG_CONFIRM: |
| 1396 | msgId = R.string.vm_changed; |
| 1397 | titleId = R.string.voicemail; |
| 1398 | // Set Button 2 |
| 1399 | b.setNegativeButton(R.string.close_dialog, this); |
| 1400 | break; |
| 1401 | case VM_NOCHANGE_ERROR: |
| 1402 | // even though this is technically an error, |
| 1403 | // keep the title friendly. |
| 1404 | msgId = R.string.no_change; |
| 1405 | titleId = R.string.voicemail; |
| 1406 | // Set Button 2 |
| 1407 | b.setNegativeButton(R.string.close_dialog, this); |
| 1408 | break; |
| 1409 | case VM_RESPONSE_ERROR: |
| 1410 | msgId = R.string.vm_change_failed; |
| 1411 | // Set Button 1 |
| 1412 | b.setPositiveButton(R.string.close_dialog, this); |
| 1413 | break; |
| 1414 | case FW_SET_RESPONSE_ERROR: |
| 1415 | msgId = R.string.fw_change_failed; |
| 1416 | // Set Button 1 |
| 1417 | b.setPositiveButton(R.string.close_dialog, this); |
| 1418 | break; |
| 1419 | case FW_GET_RESPONSE_ERROR: |
| 1420 | msgId = R.string.fw_get_in_vm_failed; |
| 1421 | b.setPositiveButton(R.string.alert_dialog_yes, this); |
| 1422 | b.setNegativeButton(R.string.alert_dialog_no, this); |
| 1423 | break; |
| 1424 | default: |
| 1425 | msgId = R.string.exception_error; |
| 1426 | // Set Button 3, tells the activity that the error is |
| 1427 | // not recoverable on dialog exit. |
| 1428 | b.setNeutralButton(R.string.close_dialog, this); |
| 1429 | break; |
| 1430 | } |
| 1431 | |
| 1432 | b.setTitle(getText(titleId)); |
| 1433 | String message = getText(msgId).toString(); |
| 1434 | b.setMessage(message); |
| 1435 | b.setCancelable(false); |
| 1436 | AlertDialog dialog = b.create(); |
| 1437 | |
| 1438 | // make the dialog more obvious by bluring the background. |
| 1439 | dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
| 1440 | |
| 1441 | return dialog; |
| 1442 | } else if (id == VOICEMAIL_FWD_SAVING_DIALOG || id == VOICEMAIL_FWD_READING_DIALOG || |
| 1443 | id == VOICEMAIL_REVERTING_DIALOG) { |
| 1444 | ProgressDialog dialog = new ProgressDialog(this); |
| 1445 | dialog.setTitle(getText(R.string.updating_title)); |
| 1446 | dialog.setIndeterminate(true); |
| 1447 | dialog.setCancelable(false); |
| 1448 | dialog.setMessage(getText( |
| 1449 | id == VOICEMAIL_FWD_SAVING_DIALOG ? R.string.updating_settings : |
| 1450 | (id == VOICEMAIL_REVERTING_DIALOG ? R.string.reverting_settings : |
| 1451 | R.string.reading_settings))); |
| 1452 | return dialog; |
| 1453 | } |
| 1454 | |
| 1455 | |
| 1456 | return null; |
| 1457 | } |
| 1458 | |
| 1459 | // This is a method implemented for DialogInterface.OnClickListener. |
| 1460 | // Used with the error dialog to close the app, voicemail dialog to just dismiss. |
| 1461 | // Close button is mapped to BUTTON_POSITIVE for the errors that close the activity, |
| 1462 | // while those that are mapped to BUTTON_NEUTRAL only move the preference focus. |
| 1463 | public void onClick(DialogInterface dialog, int which) { |
| 1464 | dialog.dismiss(); |
| 1465 | switch (which){ |
| 1466 | case DialogInterface.BUTTON_NEUTRAL: |
| 1467 | if (DBG) log("Neutral button"); |
| 1468 | break; |
| 1469 | case DialogInterface.BUTTON_NEGATIVE: |
| 1470 | if (DBG) log("Negative button"); |
| 1471 | if (mCurrentDialogId == FW_GET_RESPONSE_ERROR) { |
| 1472 | // We failed to get current forwarding settings and the user |
| 1473 | // does not wish to continue. |
| 1474 | switchToPreviousVoicemailProvider(); |
| 1475 | } |
| 1476 | break; |
| 1477 | case DialogInterface.BUTTON_POSITIVE: |
| 1478 | if (DBG) log("Positive button"); |
| 1479 | if (mCurrentDialogId == FW_GET_RESPONSE_ERROR) { |
| 1480 | // We failed to get current forwarding settings but the user |
| 1481 | // wishes to continue changing settings to the new vm provider |
| 1482 | saveVoiceMailAndForwardingNumberStage2(); |
| 1483 | } else { |
| 1484 | finish(); |
| 1485 | } |
| 1486 | return; |
| 1487 | default: |
| 1488 | // just let the dialog close and go back to the input |
| 1489 | } |
| 1490 | // In all dialogs, all buttons except BUTTON_POSITIVE lead to the end of user interaction |
| 1491 | // with settings UI. If we were called to explicitly configure voice mail then |
| 1492 | // we finish the settings activity here to come back to whatever the user was doing. |
| 1493 | if (getIntent().getAction().equals(ACTION_ADD_VOICEMAIL)) { |
| 1494 | finish(); |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | // set the app state with optional status. |
| 1499 | private void showVMDialog(int msgStatus) { |
| 1500 | switch (msgStatus) { |
| 1501 | // It's a bit worrisome to punt in the error cases here when we're |
| 1502 | // not in the foreground; maybe toast instead? |
| 1503 | case MSG_VM_EXCEPTION: |
| 1504 | showDialogIfForeground(VM_RESPONSE_ERROR); |
| 1505 | break; |
| 1506 | case MSG_FW_SET_EXCEPTION: |
| 1507 | showDialogIfForeground(FW_SET_RESPONSE_ERROR); |
| 1508 | break; |
| 1509 | case MSG_FW_GET_EXCEPTION: |
| 1510 | showDialogIfForeground(FW_GET_RESPONSE_ERROR); |
| 1511 | break; |
| 1512 | case MSG_VM_NOCHANGE: |
| 1513 | showDialogIfForeground(VM_NOCHANGE_ERROR); |
| 1514 | break; |
| 1515 | case MSG_VM_OK: |
| 1516 | showDialogIfForeground(VOICEMAIL_DIALOG_CONFIRM); |
| 1517 | break; |
| 1518 | case MSG_OK: |
| 1519 | default: |
| 1520 | // This should never happen. |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | /* |
| 1525 | * Activity class methods |
| 1526 | */ |
| 1527 | |
| 1528 | @Override |
| 1529 | protected void onCreate(Bundle icicle) { |
| 1530 | super.onCreate(icicle); |
| 1531 | if (DBG) log("onCreate(). Intent: " + getIntent()); |
| 1532 | mPhone = PhoneGlobals.getPhone(); |
Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame^] | 1533 | mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
| 1534 | |
| 1535 | // create intent to bring up contact list |
| 1536 | mContactListIntent = new Intent(Intent.ACTION_GET_CONTENT); |
| 1537 | mContactListIntent.setType(android.provider.Contacts.Phones.CONTENT_ITEM_TYPE); |
| 1538 | |
| 1539 | mVoicemailRingtoneLookupRunnable = new Runnable() { |
| 1540 | @Override |
| 1541 | public void run() { |
| 1542 | if (mVoicemailNotificationRingtone != null) { |
| 1543 | SettingsUtil.updateRingtoneName( |
| 1544 | mPhone.getContext(), |
| 1545 | mVoicemailRingtoneLookupComplete, |
| 1546 | RingtoneManager.TYPE_NOTIFICATION, |
| 1547 | mVoicemailNotificationRingtone, |
| 1548 | MSG_UPDATE_VOICEMAIL_RINGTONE_SUMMARY); |
| 1549 | } |
| 1550 | } |
| 1551 | }; |
| 1552 | |
| 1553 | ActionBar actionBar = getActionBar(); |
| 1554 | if (actionBar != null) { |
| 1555 | // android.R.id.home will be triggered in onOptionsItemSelected() |
| 1556 | actionBar.setDisplayShowHomeEnabled(true); |
| 1557 | actionBar.setDisplayHomeAsUpEnabled(true); |
| 1558 | actionBar.setDisplayShowTitleEnabled(true); |
| 1559 | } |
| 1560 | |
| 1561 | // Show the voicemail preference in onResume if the calling intent specifies the |
| 1562 | // ACTION_ADD_VOICEMAIL action. |
| 1563 | mShowVoicemailPreference = (icicle == null) && |
| 1564 | getIntent().getAction().equals(ACTION_ADD_VOICEMAIL); |
| 1565 | } |
| 1566 | |
| 1567 | private void initPhoneAccountPreferences() { |
| 1568 | mDefaultOutgoingAccount = (AccountSelectionPreference) |
| 1569 | findPreference(DEFAULT_OUTGOING_ACCOUNT_KEY); |
| 1570 | mSimCallManagerAccount = (AccountSelectionPreference) |
| 1571 | findPreference(WIFI_CALL_MANAGER_ACCOUNT_KEY); |
| 1572 | |
| 1573 | TelecommManager telecommManager = TelecommManager.from(this); |
| 1574 | |
| 1575 | int allPhoneAccountsCount = telecommManager.getAllPhoneAccountsCount(); |
| 1576 | // Show the phone accounts preference if there are is more than one phone account (this |
| 1577 | // includes disabled phone accounts). The default selection, however, only includes those |
| 1578 | // PhoneAccounts which are enabled. |
| 1579 | if (allPhoneAccountsCount > 1) { |
| 1580 | populateDefaultOutgoingAccountsModel(); |
| 1581 | |
| 1582 | mDefaultOutgoingAccount.setListener(this); |
| 1583 | } else { |
| 1584 | getPreferenceScreen().removePreference(mDefaultOutgoingAccount); |
| 1585 | } |
| 1586 | |
| 1587 | List<PhoneAccountHandle> simCallManagers = telecommManager.getSimCallManagers(); |
| 1588 | if (!simCallManagers.isEmpty()) { |
| 1589 | populateSimCallManagerAccountsModel(); |
| 1590 | mSimCallManagerAccount.setListener(this); |
| 1591 | } else { |
| 1592 | getPreferenceScreen().removePreference(mSimCallManagerAccount); |
| 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | private void createSipCallSettings() { |
| 1597 | // Add Internet call settings. |
| 1598 | if (SipUtil.isVoipSupported(this)) { |
| 1599 | mSipManager = SipManager.newInstance(this); |
| 1600 | mSipSharedPreferences = new SipSharedPreferences(this); |
| 1601 | addPreferencesFromResource( |
| 1602 | com.android.services.telephony.sip.R.xml.sip_settings_category); |
| 1603 | mButtonSipCallOptions = getSipCallOptionPreference(); |
| 1604 | mButtonSipCallOptions.setOnPreferenceChangeListener(this); |
| 1605 | mButtonSipCallOptions.setValueIndex( |
| 1606 | mButtonSipCallOptions.findIndexOfValue( |
| 1607 | mSipSharedPreferences.getSipCallOption())); |
| 1608 | mButtonSipCallOptions.setSummary(mButtonSipCallOptions.getEntry()); |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | private boolean canLaunchIntent(Intent intent) { |
| 1613 | PackageManager pm = getPackageManager(); |
| 1614 | return pm.resolveActivity(intent, PackageManager.GET_ACTIVITIES) != null; |
| 1615 | } |
| 1616 | |
| 1617 | // Gets the call options for SIP depending on whether SIP is allowed only |
| 1618 | // on Wi-Fi only; also make the other options preference invisible. |
| 1619 | private ListPreference getSipCallOptionPreference() { |
| 1620 | ListPreference wifiAnd3G = (ListPreference) |
| 1621 | findPreference(BUTTON_SIP_CALL_OPTIONS); |
| 1622 | ListPreference wifiOnly = (ListPreference) |
| 1623 | findPreference(BUTTON_SIP_CALL_OPTIONS_WIFI_ONLY); |
| 1624 | PreferenceScreen sipSettings = (PreferenceScreen) |
| 1625 | getPreferenceScreen().findPreference(SIP_SETTINGS_PREFERENCE_SCREEN_KEY); |
| 1626 | if (SipManager.isSipWifiOnly(this)) { |
| 1627 | sipSettings.removePreference(wifiAnd3G); |
| 1628 | return wifiOnly; |
| 1629 | } else { |
| 1630 | sipSettings.removePreference(wifiOnly); |
| 1631 | return wifiAnd3G; |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | @Override |
| 1636 | protected void onResume() { |
| 1637 | super.onResume(); |
| 1638 | mForeground = true; |
| 1639 | |
| 1640 | PreferenceScreen preferenceScreen = getPreferenceScreen(); |
| 1641 | if (preferenceScreen != null) { |
| 1642 | preferenceScreen.removeAll(); |
| 1643 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1644 | |
| 1645 | addPreferencesFromResource(R.xml.call_feature_setting); |
Andrew Lee | db2fe56 | 2014-09-03 15:40:43 -0700 | [diff] [blame] | 1646 | initPhoneAccountPreferences(); |
| 1647 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1648 | // get buttons |
| 1649 | PreferenceScreen prefSet = getPreferenceScreen(); |
| 1650 | mSubMenuVoicemailSettings = (EditPhoneNumberPreference)findPreference(BUTTON_VOICEMAIL_KEY); |
| 1651 | if (mSubMenuVoicemailSettings != null) { |
| 1652 | mSubMenuVoicemailSettings.setParentActivity(this, VOICEMAIL_PREF_ID, this); |
| 1653 | mSubMenuVoicemailSettings.setDialogOnClosedListener(this); |
| 1654 | mSubMenuVoicemailSettings.setDialogTitle(R.string.voicemail_settings_number_label); |
| 1655 | } |
| 1656 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1657 | mButtonDTMF = (ListPreference) findPreference(BUTTON_DTMF_KEY); |
| 1658 | mButtonAutoRetry = (CheckBoxPreference) findPreference(BUTTON_RETRY_KEY); |
| 1659 | mButtonHAC = (CheckBoxPreference) findPreference(BUTTON_HAC_KEY); |
| 1660 | mButtonTTY = (ListPreference) findPreference(BUTTON_TTY_KEY); |
| 1661 | mVoicemailProviders = (ListPreference) findPreference(BUTTON_VOICEMAIL_PROVIDER_KEY); |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 1662 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1663 | if (mVoicemailProviders != null) { |
| 1664 | mVoicemailProviders.setOnPreferenceChangeListener(this); |
| 1665 | mVoicemailSettings = (PreferenceScreen)findPreference(BUTTON_VOICEMAIL_SETTING_KEY); |
| 1666 | mVoicemailNotificationRingtone = |
| 1667 | findPreference(BUTTON_VOICEMAIL_NOTIFICATION_RINGTONE_KEY); |
| 1668 | mVoicemailNotificationVibrate = |
| 1669 | (CheckBoxPreference) findPreference(BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY); |
| 1670 | initVoiceMailProviders(); |
| 1671 | } |
| 1672 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1673 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1674 | if (mButtonDTMF != null) { |
| 1675 | if (getResources().getBoolean(R.bool.dtmf_type_enabled)) { |
| 1676 | mButtonDTMF.setOnPreferenceChangeListener(this); |
| 1677 | } else { |
| 1678 | prefSet.removePreference(mButtonDTMF); |
| 1679 | mButtonDTMF = null; |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | if (mButtonAutoRetry != null) { |
| 1684 | if (getResources().getBoolean(R.bool.auto_retry_enabled)) { |
| 1685 | mButtonAutoRetry.setOnPreferenceChangeListener(this); |
| 1686 | } else { |
| 1687 | prefSet.removePreference(mButtonAutoRetry); |
| 1688 | mButtonAutoRetry = null; |
| 1689 | } |
| 1690 | } |
| 1691 | |
| 1692 | if (mButtonHAC != null) { |
| 1693 | if (getResources().getBoolean(R.bool.hac_enabled)) { |
| 1694 | |
| 1695 | mButtonHAC.setOnPreferenceChangeListener(this); |
| 1696 | } else { |
| 1697 | prefSet.removePreference(mButtonHAC); |
| 1698 | mButtonHAC = null; |
| 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | if (mButtonTTY != null) { |
Sailesh Nepal | bf90054 | 2014-07-15 16:18:32 -0700 | [diff] [blame] | 1703 | TelecommManager telecommManager = TelecommManager.from(this); |
| 1704 | if (telecommManager != null && telecommManager.isTtySupported()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1705 | mButtonTTY.setOnPreferenceChangeListener(this); |
| 1706 | } else { |
| 1707 | prefSet.removePreference(mButtonTTY); |
| 1708 | mButtonTTY = null; |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | if (!getResources().getBoolean(R.bool.world_phone)) { |
| 1713 | Preference options = prefSet.findPreference(BUTTON_CDMA_OPTIONS); |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 1714 | if (options != null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1715 | prefSet.removePreference(options); |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 1716 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1717 | options = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS); |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 1718 | if (options != null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1719 | prefSet.removePreference(options); |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 1720 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1721 | |
| 1722 | int phoneType = mPhone.getPhoneType(); |
| 1723 | if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { |
| 1724 | Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY); |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 1725 | if (fdnButton != null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1726 | prefSet.removePreference(fdnButton); |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 1727 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1728 | if (!getResources().getBoolean(R.bool.config_voice_privacy_disable)) { |
| 1729 | addPreferencesFromResource(R.xml.cdma_call_privacy); |
| 1730 | } |
| 1731 | } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 1732 | if (getResources().getBoolean(R.bool.config_additional_call_setting)) { |
Etan Cohen | 0ca1c80 | 2014-07-07 15:35:48 -0700 | [diff] [blame] | 1733 | addPreferencesFromResource(R.xml.gsm_umts_call_options); |
| 1734 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1735 | } else { |
| 1736 | throw new IllegalStateException("Unexpected phone type: " + phoneType); |
| 1737 | } |
| 1738 | } |
| 1739 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1740 | // check the intent that started this activity and pop up the voicemail |
| 1741 | // dialog if we've been asked to. |
| 1742 | // If we have at least one non default VM provider registered then bring up |
| 1743 | // the selection for the VM provider, otherwise bring up a VM number dialog. |
| 1744 | // We only bring up the dialog the first time we are called (not after orientation change) |
Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame^] | 1745 | if (mShowVoicemailPreference && mVoicemailProviders != null) { |
| 1746 | if (DBG) { |
| 1747 | log("ACTION_ADD_VOICEMAIL Intent is thrown. current VM data size: " |
| 1748 | + mVMProvidersData.size()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1749 | } |
Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame^] | 1750 | if (mVMProvidersData.size() > 1) { |
| 1751 | simulatePreferenceClick(mVoicemailProviders); |
| 1752 | } else { |
| 1753 | onPreferenceChange(mVoicemailProviders, DEFAULT_VM_PROVIDER_KEY); |
| 1754 | mVoicemailProviders.setValue(DEFAULT_VM_PROVIDER_KEY); |
| 1755 | } |
| 1756 | mShowVoicemailPreference = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1757 | } |
Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame^] | 1758 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1759 | updateVoiceNumberField(); |
| 1760 | mVMProviderSettingsForced = false; |
| 1761 | createSipCallSettings(); |
| 1762 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1763 | if (isAirplaneModeOn()) { |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 1764 | Preference sipSettings = findPreference(SIP_SETTINGS_PREFERENCE_SCREEN_KEY); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1765 | PreferenceScreen screen = getPreferenceScreen(); |
| 1766 | int count = screen.getPreferenceCount(); |
| 1767 | for (int i = 0 ; i < count ; ++i) { |
| 1768 | Preference pref = screen.getPreference(i); |
| 1769 | if (pref != sipSettings) pref.setEnabled(false); |
| 1770 | } |
| 1771 | return; |
| 1772 | } |
| 1773 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1774 | if (mButtonDTMF != null) { |
| 1775 | int dtmf = Settings.System.getInt(getContentResolver(), |
| 1776 | Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, Constants.DTMF_TONE_TYPE_NORMAL); |
| 1777 | mButtonDTMF.setValueIndex(dtmf); |
| 1778 | } |
| 1779 | |
| 1780 | if (mButtonAutoRetry != null) { |
| 1781 | int autoretry = Settings.Global.getInt(getContentResolver(), |
| 1782 | Settings.Global.CALL_AUTO_RETRY, 0); |
| 1783 | mButtonAutoRetry.setChecked(autoretry != 0); |
| 1784 | } |
| 1785 | |
| 1786 | if (mButtonHAC != null) { |
| 1787 | int hac = Settings.System.getInt(getContentResolver(), Settings.System.HEARING_AID, 0); |
| 1788 | mButtonHAC.setChecked(hac != 0); |
| 1789 | } |
| 1790 | |
| 1791 | if (mButtonTTY != null) { |
| 1792 | int settingsTtyMode = Settings.Secure.getInt(getContentResolver(), |
| 1793 | Settings.Secure.PREFERRED_TTY_MODE, |
Evan Charlton | 6abba88 | 2014-07-19 15:02:56 -0700 | [diff] [blame] | 1794 | TelecommManager.TTY_MODE_OFF); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1795 | mButtonTTY.setValue(Integer.toString(settingsTtyMode)); |
| 1796 | updatePreferredTtyModeSummary(settingsTtyMode); |
| 1797 | } |
| 1798 | |
| 1799 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences( |
| 1800 | mPhone.getContext()); |
| 1801 | if (migrateVoicemailVibrationSettingsIfNeeded(prefs)) { |
| 1802 | mVoicemailNotificationVibrate.setChecked(prefs.getBoolean( |
| 1803 | BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY, false)); |
| 1804 | } |
| 1805 | |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 1806 | // Look up the voicemail ringtone name asynchronously and update its preference. |
| 1807 | new Thread(mVoicemailRingtoneLookupRunnable).start(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | // Migrate settings from BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_WHEN_KEY to |
| 1811 | // BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY, if the latter does not exist. |
| 1812 | // Returns true if migration was performed. |
| 1813 | public static boolean migrateVoicemailVibrationSettingsIfNeeded(SharedPreferences prefs) { |
| 1814 | if (!prefs.contains(BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY)) { |
| 1815 | String vibrateWhen = prefs.getString( |
| 1816 | BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_WHEN_KEY, VOICEMAIL_VIBRATION_NEVER); |
| 1817 | // If vibrateWhen is always, then voicemailVibrate should be True. |
| 1818 | // otherwise if vibrateWhen is "only in silent mode", or "never", then |
| 1819 | // voicemailVibrate = False. |
| 1820 | boolean voicemailVibrate = vibrateWhen.equals(VOICEMAIL_VIBRATION_ALWAYS); |
| 1821 | final SharedPreferences.Editor editor = prefs.edit(); |
| 1822 | editor.putBoolean(BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY, voicemailVibrate); |
| 1823 | editor.commit(); |
| 1824 | return true; |
| 1825 | } |
| 1826 | return false; |
| 1827 | } |
| 1828 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1829 | private boolean isAirplaneModeOn() { |
| 1830 | return Settings.System.getInt(getContentResolver(), |
| 1831 | Settings.System.AIRPLANE_MODE_ON, 0) != 0; |
| 1832 | } |
| 1833 | |
| 1834 | private void handleTTYChange(Preference preference, Object objValue) { |
| 1835 | int buttonTtyMode; |
| 1836 | buttonTtyMode = Integer.valueOf((String) objValue).intValue(); |
| 1837 | int settingsTtyMode = android.provider.Settings.Secure.getInt( |
| 1838 | getContentResolver(), |
Sailesh Nepal | bf90054 | 2014-07-15 16:18:32 -0700 | [diff] [blame] | 1839 | android.provider.Settings.Secure.PREFERRED_TTY_MODE, |
Evan Charlton | 6abba88 | 2014-07-19 15:02:56 -0700 | [diff] [blame] | 1840 | TelecommManager.TTY_MODE_OFF); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1841 | if (DBG) log("handleTTYChange: requesting set TTY mode enable (TTY) to" + |
| 1842 | Integer.toString(buttonTtyMode)); |
| 1843 | |
| 1844 | if (buttonTtyMode != settingsTtyMode) { |
| 1845 | switch(buttonTtyMode) { |
Evan Charlton | 1561976 | 2014-07-19 15:52:48 -0700 | [diff] [blame] | 1846 | case TelecommManager.TTY_MODE_OFF: |
| 1847 | case TelecommManager.TTY_MODE_FULL: |
| 1848 | case TelecommManager.TTY_MODE_HCO: |
| 1849 | case TelecommManager.TTY_MODE_VCO: |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1850 | android.provider.Settings.Secure.putInt(getContentResolver(), |
| 1851 | android.provider.Settings.Secure.PREFERRED_TTY_MODE, buttonTtyMode); |
| 1852 | break; |
| 1853 | default: |
Evan Charlton | 6abba88 | 2014-07-19 15:02:56 -0700 | [diff] [blame] | 1854 | buttonTtyMode = TelecommManager.TTY_MODE_OFF; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | mButtonTTY.setValue(Integer.toString(buttonTtyMode)); |
| 1858 | updatePreferredTtyModeSummary(buttonTtyMode); |
Evan Charlton | 6abba88 | 2014-07-19 15:02:56 -0700 | [diff] [blame] | 1859 | Intent ttyModeChanged = new Intent(TelecommManager.ACTION_TTY_PREFERRED_MODE_CHANGED); |
| 1860 | ttyModeChanged.putExtra(TelecommManager.EXTRA_TTY_PREFERRED_MODE, buttonTtyMode); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1861 | sendBroadcastAsUser(ttyModeChanged, UserHandle.ALL); |
| 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | private void handleSipCallOptionsChange(Object objValue) { |
| 1866 | String option = objValue.toString(); |
| 1867 | mSipSharedPreferences.setSipCallOption(option); |
| 1868 | mButtonSipCallOptions.setValueIndex( |
| 1869 | mButtonSipCallOptions.findIndexOfValue(option)); |
| 1870 | mButtonSipCallOptions.setSummary(mButtonSipCallOptions.getEntry()); |
| 1871 | } |
| 1872 | |
Evan Charlton | 1c69683 | 2014-04-15 14:24:23 -0700 | [diff] [blame] | 1873 | private void handleWifiCallSettingsClick(Preference preference) { |
| 1874 | Intent intent = preference.getIntent(); |
| 1875 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
| 1876 | // TODO - Restrict to a (the?) blessed Wi-Fi calling app. |
| 1877 | |
| 1878 | Bundle noAnimations = ActivityOptions.makeCustomAnimation(this, 0, 0).toBundle(); |
| 1879 | startActivity(intent, noAnimations); |
Ihab Awad | ca8ee7d | 2013-12-05 12:13:16 -0800 | [diff] [blame] | 1880 | } |
| 1881 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1882 | private void updatePreferredTtyModeSummary(int TtyMode) { |
| 1883 | String [] txts = getResources().getStringArray(R.array.tty_mode_entries); |
| 1884 | switch(TtyMode) { |
Evan Charlton | 1561976 | 2014-07-19 15:52:48 -0700 | [diff] [blame] | 1885 | case TelecommManager.TTY_MODE_OFF: |
| 1886 | case TelecommManager.TTY_MODE_HCO: |
| 1887 | case TelecommManager.TTY_MODE_VCO: |
| 1888 | case TelecommManager.TTY_MODE_FULL: |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1889 | mButtonTTY.setSummary(txts[TtyMode]); |
| 1890 | break; |
| 1891 | default: |
| 1892 | mButtonTTY.setEnabled(false); |
Evan Charlton | 6abba88 | 2014-07-19 15:02:56 -0700 | [diff] [blame] | 1893 | mButtonTTY.setSummary(txts[TelecommManager.TTY_MODE_OFF]); |
Sailesh Nepal | bf90054 | 2014-07-15 16:18:32 -0700 | [diff] [blame] | 1894 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | private static void log(String msg) { |
| 1899 | Log.d(LOG_TAG, msg); |
| 1900 | } |
| 1901 | |
| 1902 | /** |
| 1903 | * Updates the look of the VM preference widgets based on current VM provider settings. |
| 1904 | * Note that the provider name is loaded form the found activity via loadLabel in |
| 1905 | * {@link #initVoiceMailProviders()} in order for it to be localizable. |
| 1906 | */ |
| 1907 | private void updateVMPreferenceWidgets(String currentProviderSetting) { |
| 1908 | final String key = currentProviderSetting; |
| 1909 | final VoiceMailProvider provider = mVMProvidersData.get(key); |
| 1910 | |
| 1911 | /* This is the case when we are coming up on a freshly wiped phone and there is no |
| 1912 | persisted value for the list preference mVoicemailProviders. |
| 1913 | In this case we want to show the UI asking the user to select a voicemail provider as |
| 1914 | opposed to silently falling back to default one. */ |
| 1915 | if (provider == null) { |
| 1916 | if (DBG) { |
| 1917 | log("updateVMPreferenceWidget: provider for the key \"" + key + "\" is null."); |
| 1918 | } |
| 1919 | mVoicemailProviders.setSummary(getString(R.string.sum_voicemail_choose_provider)); |
| 1920 | mVoicemailSettings.setEnabled(false); |
| 1921 | mVoicemailSettings.setIntent(null); |
| 1922 | |
| 1923 | mVoicemailNotificationVibrate.setEnabled(false); |
| 1924 | } else { |
| 1925 | if (DBG) { |
| 1926 | log("updateVMPreferenceWidget: provider for the key \"" + key + "\".." |
| 1927 | + "name: " + provider.name |
| 1928 | + ", intent: " + provider.intent); |
| 1929 | } |
| 1930 | final String providerName = provider.name; |
| 1931 | mVoicemailProviders.setSummary(providerName); |
| 1932 | mVoicemailSettings.setEnabled(true); |
| 1933 | mVoicemailSettings.setIntent(provider.intent); |
| 1934 | |
| 1935 | mVoicemailNotificationVibrate.setEnabled(true); |
| 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | /** |
| 1940 | * Enumerates existing VM providers and puts their data into the list and populates |
| 1941 | * the preference list objects with their names. |
| 1942 | * In case we are called with ACTION_ADD_VOICEMAIL intent the intent may have |
| 1943 | * an extra string called IGNORE_PROVIDER_EXTRA with "package.activityName" of the provider |
| 1944 | * which should be hidden when we bring up the list of possible VM providers to choose. |
| 1945 | */ |
| 1946 | private void initVoiceMailProviders() { |
| 1947 | if (DBG) log("initVoiceMailProviders()"); |
| 1948 | mPerProviderSavedVMNumbers = |
| 1949 | this.getApplicationContext().getSharedPreferences( |
| 1950 | VM_NUMBERS_SHARED_PREFERENCES_NAME, MODE_PRIVATE); |
| 1951 | |
| 1952 | String providerToIgnore = null; |
| 1953 | if (getIntent().getAction().equals(ACTION_ADD_VOICEMAIL)) { |
| 1954 | if (getIntent().hasExtra(IGNORE_PROVIDER_EXTRA)) { |
| 1955 | providerToIgnore = getIntent().getStringExtra(IGNORE_PROVIDER_EXTRA); |
| 1956 | } |
| 1957 | if (DBG) log("Found ACTION_ADD_VOICEMAIL. providerToIgnore=" + providerToIgnore); |
| 1958 | if (providerToIgnore != null) { |
| 1959 | // IGNORE_PROVIDER_EXTRA implies we want to remove the choice from the list. |
| 1960 | deleteSettingsForVoicemailProvider(providerToIgnore); |
| 1961 | } |
| 1962 | } |
| 1963 | |
| 1964 | mVMProvidersData.clear(); |
| 1965 | |
| 1966 | // Stick the default element which is always there |
| 1967 | final String myCarrier = getString(R.string.voicemail_default); |
| 1968 | mVMProvidersData.put(DEFAULT_VM_PROVIDER_KEY, new VoiceMailProvider(myCarrier, null)); |
| 1969 | |
| 1970 | // Enumerate providers |
| 1971 | PackageManager pm = getPackageManager(); |
| 1972 | Intent intent = new Intent(); |
| 1973 | intent.setAction(ACTION_CONFIGURE_VOICEMAIL); |
| 1974 | List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0); |
| 1975 | int len = resolveInfos.size() + 1; // +1 for the default choice we will insert. |
| 1976 | |
| 1977 | // Go through the list of discovered providers populating the data map |
| 1978 | // skip the provider we were instructed to ignore if there was one |
| 1979 | for (int i = 0; i < resolveInfos.size(); i++) { |
| 1980 | final ResolveInfo ri= resolveInfos.get(i); |
| 1981 | final ActivityInfo currentActivityInfo = ri.activityInfo; |
| 1982 | final String key = makeKeyForActivity(currentActivityInfo); |
| 1983 | if (key.equals(providerToIgnore)) { |
| 1984 | if (DBG) log("Ignoring key: " + key); |
| 1985 | len--; |
| 1986 | continue; |
| 1987 | } |
| 1988 | if (DBG) log("Loading key: " + key); |
| 1989 | final String nameForDisplay = ri.loadLabel(pm).toString(); |
| 1990 | Intent providerIntent = new Intent(); |
| 1991 | providerIntent.setAction(ACTION_CONFIGURE_VOICEMAIL); |
| 1992 | providerIntent.setClassName(currentActivityInfo.packageName, |
| 1993 | currentActivityInfo.name); |
| 1994 | if (DBG) { |
| 1995 | log("Store loaded VoiceMailProvider. key: " + key |
| 1996 | + " -> name: " + nameForDisplay + ", intent: " + providerIntent); |
| 1997 | } |
| 1998 | mVMProvidersData.put( |
| 1999 | key, |
| 2000 | new VoiceMailProvider(nameForDisplay, providerIntent)); |
| 2001 | |
| 2002 | } |
| 2003 | |
| 2004 | // Now we know which providers to display - create entries and values array for |
| 2005 | // the list preference |
| 2006 | String [] entries = new String [len]; |
| 2007 | String [] values = new String [len]; |
| 2008 | entries[0] = myCarrier; |
| 2009 | values[0] = DEFAULT_VM_PROVIDER_KEY; |
| 2010 | int entryIdx = 1; |
| 2011 | for (int i = 0; i < resolveInfos.size(); i++) { |
| 2012 | final String key = makeKeyForActivity(resolveInfos.get(i).activityInfo); |
| 2013 | if (!mVMProvidersData.containsKey(key)) { |
| 2014 | continue; |
| 2015 | } |
| 2016 | entries[entryIdx] = mVMProvidersData.get(key).name; |
| 2017 | values[entryIdx] = key; |
| 2018 | entryIdx++; |
| 2019 | } |
| 2020 | |
| 2021 | // ListPreference is now updated. |
| 2022 | mVoicemailProviders.setEntries(entries); |
| 2023 | mVoicemailProviders.setEntryValues(values); |
| 2024 | |
| 2025 | // Remember the current Voicemail Provider key as a "previous" key. This will be used |
| 2026 | // when we fail to update Voicemail Provider, which requires rollback. |
| 2027 | // We will update this when the VM Provider setting is successfully updated. |
| 2028 | mPreviousVMProviderKey = getCurrentVoicemailProviderKey(); |
| 2029 | if (DBG) log("Set up the first mPreviousVMProviderKey: " + mPreviousVMProviderKey); |
| 2030 | |
| 2031 | // Finally update the preference texts. |
| 2032 | updateVMPreferenceWidgets(mPreviousVMProviderKey); |
| 2033 | } |
| 2034 | |
| 2035 | private String makeKeyForActivity(ActivityInfo ai) { |
| 2036 | return ai.name; |
| 2037 | } |
| 2038 | |
| 2039 | /** |
| 2040 | * Simulates user clicking on a passed preference. |
| 2041 | * Usually needed when the preference is a dialog preference and we want to invoke |
| 2042 | * a dialog for this preference programmatically. |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 2043 | * 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] | 2044 | */ |
| 2045 | private void simulatePreferenceClick(Preference preference) { |
| 2046 | // Go through settings until we find our setting |
| 2047 | // and then simulate a click on it to bring up the dialog |
| 2048 | final ListAdapter adapter = getPreferenceScreen().getRootAdapter(); |
| 2049 | for (int idx = 0; idx < adapter.getCount(); idx++) { |
| 2050 | if (adapter.getItem(idx) == preference) { |
| 2051 | getPreferenceScreen().onItemClick(this.getListView(), |
| 2052 | null, idx, adapter.getItemId(idx)); |
| 2053 | break; |
| 2054 | } |
| 2055 | } |
| 2056 | } |
| 2057 | |
| 2058 | /** |
| 2059 | * Saves new VM provider settings associating them with the currently selected |
| 2060 | * provider if settings are different than the ones already stored for this |
| 2061 | * provider. |
| 2062 | * Later on these will be used when the user switches a provider. |
| 2063 | */ |
| 2064 | private void maybeSaveSettingsForVoicemailProvider(String key, |
| 2065 | VoiceMailProviderSettings newSettings) { |
| 2066 | if (mVoicemailProviders == null) { |
| 2067 | return; |
| 2068 | } |
| 2069 | final VoiceMailProviderSettings curSettings = loadSettingsForVoiceMailProvider(key); |
| 2070 | if (newSettings.equals(curSettings)) { |
| 2071 | if (DBG) { |
| 2072 | log("maybeSaveSettingsForVoicemailProvider:" |
| 2073 | + " Not saving setting for " + key + " since they have not changed"); |
| 2074 | } |
| 2075 | return; |
| 2076 | } |
| 2077 | if (DBG) log("Saving settings for " + key + ": " + newSettings.toString()); |
| 2078 | Editor editor = mPerProviderSavedVMNumbers.edit(); |
| 2079 | editor.putString(key + VM_NUMBER_TAG, newSettings.voicemailNumber); |
| 2080 | String fwdKey = key + FWD_SETTINGS_TAG; |
| 2081 | CallForwardInfo[] s = newSettings.forwardingSettings; |
| 2082 | if (s != FWD_SETTINGS_DONT_TOUCH) { |
| 2083 | editor.putInt(fwdKey + FWD_SETTINGS_LENGTH_TAG, s.length); |
| 2084 | for (int i = 0; i < s.length; i++) { |
| 2085 | final String settingKey = fwdKey + FWD_SETTING_TAG + String.valueOf(i); |
| 2086 | final CallForwardInfo fi = s[i]; |
| 2087 | editor.putInt(settingKey + FWD_SETTING_STATUS, fi.status); |
| 2088 | editor.putInt(settingKey + FWD_SETTING_REASON, fi.reason); |
| 2089 | editor.putString(settingKey + FWD_SETTING_NUMBER, fi.number); |
| 2090 | editor.putInt(settingKey + FWD_SETTING_TIME, fi.timeSeconds); |
| 2091 | } |
| 2092 | } else { |
| 2093 | editor.putInt(fwdKey + FWD_SETTINGS_LENGTH_TAG, 0); |
| 2094 | } |
| 2095 | editor.apply(); |
| 2096 | } |
| 2097 | |
| 2098 | /** |
| 2099 | * Returns settings previously stored for the currently selected |
| 2100 | * voice mail provider. If none is stored returns null. |
| 2101 | * If the user switches to a voice mail provider and we have settings |
| 2102 | * stored for it we will automatically change the phone's voice mail number |
| 2103 | * and forwarding number to the stored one. Otherwise we will bring up provider's configuration |
| 2104 | * UI. |
| 2105 | */ |
| 2106 | private VoiceMailProviderSettings loadSettingsForVoiceMailProvider(String key) { |
| 2107 | final String vmNumberSetting = mPerProviderSavedVMNumbers.getString(key + VM_NUMBER_TAG, |
| 2108 | null); |
| 2109 | if (vmNumberSetting == null) { |
| 2110 | Log.w(LOG_TAG, "VoiceMailProvider settings for the key \"" + key + "\"" |
| 2111 | + " was not found. Returning null."); |
| 2112 | return null; |
| 2113 | } |
| 2114 | |
| 2115 | CallForwardInfo[] cfi = FWD_SETTINGS_DONT_TOUCH; |
| 2116 | String fwdKey = key + FWD_SETTINGS_TAG; |
| 2117 | final int fwdLen = mPerProviderSavedVMNumbers.getInt(fwdKey + FWD_SETTINGS_LENGTH_TAG, 0); |
| 2118 | if (fwdLen > 0) { |
| 2119 | cfi = new CallForwardInfo[fwdLen]; |
| 2120 | for (int i = 0; i < cfi.length; i++) { |
| 2121 | final String settingKey = fwdKey + FWD_SETTING_TAG + String.valueOf(i); |
| 2122 | cfi[i] = new CallForwardInfo(); |
| 2123 | cfi[i].status = mPerProviderSavedVMNumbers.getInt( |
| 2124 | settingKey + FWD_SETTING_STATUS, 0); |
| 2125 | cfi[i].reason = mPerProviderSavedVMNumbers.getInt( |
| 2126 | settingKey + FWD_SETTING_REASON, |
| 2127 | CommandsInterface.CF_REASON_ALL_CONDITIONAL); |
| 2128 | cfi[i].serviceClass = CommandsInterface.SERVICE_CLASS_VOICE; |
| 2129 | cfi[i].toa = PhoneNumberUtils.TOA_International; |
| 2130 | cfi[i].number = mPerProviderSavedVMNumbers.getString( |
| 2131 | settingKey + FWD_SETTING_NUMBER, ""); |
| 2132 | cfi[i].timeSeconds = mPerProviderSavedVMNumbers.getInt( |
| 2133 | settingKey + FWD_SETTING_TIME, 20); |
| 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | VoiceMailProviderSettings settings = new VoiceMailProviderSettings(vmNumberSetting, cfi); |
| 2138 | if (DBG) log("Loaded settings for " + key + ": " + settings.toString()); |
| 2139 | return settings; |
| 2140 | } |
| 2141 | |
| 2142 | /** |
Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame^] | 2143 | * Populates the phone accounts which could potentially be selected as the default. |
| 2144 | */ |
| 2145 | private void populateDefaultOutgoingAccountsModel() { |
| 2146 | if (mDefaultOutgoingAccount == null ) { |
| 2147 | return; |
| 2148 | } |
| 2149 | |
| 2150 | TelecommManager telecommManager = TelecommManager.from(this); |
| 2151 | List<PhoneAccountHandle> enabledPhoneAccounts = telecommManager.getEnabledPhoneAccounts(); |
| 2152 | mDefaultOutgoingAccount.setModel( |
| 2153 | telecommManager, |
| 2154 | enabledPhoneAccounts, |
| 2155 | telecommManager.getUserSelectedOutgoingPhoneAccount(), |
| 2156 | getString(R.string.phone_accounts_ask_every_time)); |
| 2157 | } |
| 2158 | |
| 2159 | /** |
| 2160 | * Populates the phone accounts which could potentially be selected as the default sim call |
| 2161 | * manager. |
| 2162 | */ |
| 2163 | private void populateSimCallManagerAccountsModel() { |
| 2164 | if (mSimCallManagerAccount == null) { |
| 2165 | return; |
| 2166 | } |
| 2167 | |
| 2168 | TelecommManager telecommManager = TelecommManager.from(this); |
| 2169 | List<PhoneAccountHandle> simCallManagers = telecommManager.getSimCallManagers(); |
| 2170 | mSimCallManagerAccount.setModel( |
| 2171 | telecommManager, |
| 2172 | simCallManagers, |
| 2173 | telecommManager.getSimCallManager(), |
| 2174 | getString(R.string.wifi_calling_do_not_use)); |
| 2175 | } |
| 2176 | |
| 2177 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2178 | * Deletes settings for the specified provider. |
| 2179 | */ |
| 2180 | private void deleteSettingsForVoicemailProvider(String key) { |
| 2181 | if (DBG) log("Deleting settings for" + key); |
| 2182 | if (mVoicemailProviders == null) { |
| 2183 | return; |
| 2184 | } |
| 2185 | mPerProviderSavedVMNumbers.edit() |
| 2186 | .putString(key + VM_NUMBER_TAG, null) |
| 2187 | .putInt(key + FWD_SETTINGS_TAG + FWD_SETTINGS_LENGTH_TAG, 0) |
| 2188 | .commit(); |
| 2189 | } |
| 2190 | |
| 2191 | private String getCurrentVoicemailProviderKey() { |
| 2192 | final String key = mVoicemailProviders.getValue(); |
| 2193 | return (key != null) ? key : DEFAULT_VM_PROVIDER_KEY; |
| 2194 | } |
| 2195 | |
| 2196 | @Override |
| 2197 | public boolean onOptionsItemSelected(MenuItem item) { |
| 2198 | final int itemId = item.getItemId(); |
| 2199 | if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled() |
Yorke Lee | f2d0cac | 2013-09-09 19:42:56 -0700 | [diff] [blame] | 2200 | onBackPressed(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2201 | return true; |
| 2202 | } |
| 2203 | return super.onOptionsItemSelected(item); |
| 2204 | } |
| 2205 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2206 | /** |
| 2207 | * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}). |
| 2208 | * This is useful for implementing "HomeAsUp" capability for second-level Settings. |
| 2209 | */ |
| 2210 | public static void goUpToTopLevelSetting(Activity activity) { |
| 2211 | Intent intent = new Intent(activity, CallFeaturesSetting.class); |
| 2212 | intent.setAction(Intent.ACTION_MAIN); |
| 2213 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 2214 | activity.startActivity(intent); |
| 2215 | activity.finish(); |
| 2216 | } |
| 2217 | } |