blob: 6324eae0fdaec8c6d1db4246872ab08e225851f9 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
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
17package com.android.phone;
18
19import android.app.ActionBar;
20import android.app.Activity;
Evan Charlton1c696832014-04-15 14:24:23 -070021import android.app.ActivityOptions;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AlertDialog;
23import android.app.Dialog;
24import android.app.ProgressDialog;
25import android.content.ContentResolver;
26import android.content.Context;
27import android.content.DialogInterface;
28import android.content.Intent;
29import android.content.SharedPreferences;
30import android.content.SharedPreferences.Editor;
31import android.content.pm.ActivityInfo;
32import android.content.pm.PackageManager;
33import android.content.pm.ResolveInfo;
34import android.database.Cursor;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.media.AudioManager;
36import android.media.RingtoneManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.sip.SipManager;
38import android.os.AsyncResult;
39import android.os.Bundle;
40import android.os.Handler;
41import android.os.Message;
42import android.os.UserHandle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.preference.CheckBoxPreference;
44import android.preference.ListPreference;
45import android.preference.Preference;
46import android.preference.PreferenceActivity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.preference.PreferenceManager;
48import android.preference.PreferenceScreen;
49import android.provider.ContactsContract.CommonDataKinds;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.provider.Settings;
Andrew Leedb2fe562014-09-03 15:40:43 -070051import android.telecomm.PhoneAccountHandle;
Sailesh Nepalbf900542014-07-15 16:18:32 -070052import android.telecomm.TelecommManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.telephony.PhoneNumberUtils;
54import android.text.TextUtils;
55import android.util.Log;
56import android.view.MenuItem;
57import android.view.WindowManager;
58import android.widget.ListAdapter;
59
60import com.android.internal.telephony.CallForwardInfo;
61import com.android.internal.telephony.CommandsInterface;
62import com.android.internal.telephony.Phone;
63import com.android.internal.telephony.PhoneConstants;
Andrew Lee2170a972014-08-13 18:13:01 -070064import com.android.phone.common.util.SettingsUtil;
Andrew Leedb2fe562014-09-03 15:40:43 -070065import com.android.phone.settings.AccountSelectionPreference;
Sailesh Nepal788959e2014-07-08 23:36:40 -070066import com.android.services.telephony.sip.SipSharedPreferences;
67import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068
Andrew Lee2170a972014-08-13 18:13:01 -070069import java.lang.String;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import java.util.Collection;
71import java.util.HashMap;
72import java.util.HashSet;
73import java.util.Iterator;
74import java.util.List;
75import 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 Lee2170a972014-08-13 18:13:01 -070093 * TODO: Settings should be split into PreferenceFragments where possible (ie. voicemail, SIP).
94 *
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095 * @see com.android.phone.MobileNetworkSettings
96 */
97public class CallFeaturesSetting extends PreferenceActivity
98 implements DialogInterface.OnClickListener,
Andrew Lee2170a972014-08-13 18:13:01 -070099 Preference.OnPreferenceChangeListener,
100 Preference.OnPreferenceClickListener,
101 EditPhoneNumberPreference.OnDialogClosedListener,
Andrew Leedb2fe562014-09-03 15:40:43 -0700102 EditPhoneNumberPreference.GetDefaultNumberListener,
103 AccountSelectionPreference.AccountSelectionListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104 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 Cordon7d4ddf62013-07-10 11:58:08 -0700176
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177 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 Cordon7d4ddf62013-07-10 11:58:08 -0700181
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 Lee2170a972014-08-13 18:13:01 -0700187 private static final String BUTTON_SIP_CALL_OPTIONS = "sip_call_options_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188 private static final String BUTTON_SIP_CALL_OPTIONS_WIFI_ONLY =
189 "sip_call_options_wifi_only_key";
Andrew Lee2170a972014-08-13 18:13:01 -0700190 private static final String SIP_SETTINGS_PREFERENCE_SCREEN_KEY =
191 "sip_settings_preference_screen_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192
Andrew Leedb2fe562014-09-03 15:40:43 -0700193 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 Cordon7d4ddf62013-07-10 11:58:08 -0700196 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 Lee2170a972014-08-13 18:13:01 -0700203 private static final int MSG_UPDATE_VOICEMAIL_RINGTONE_SUMMARY = 1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205 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 Lee2170a972014-08-13 18:13:01 -0700246 private Runnable mVoicemailRingtoneLookupRunnable;
247 private final Handler mVoicemailRingtoneLookupComplete = new Handler() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248 @Override
249 public void handleMessage(Message msg) {
250 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251 case MSG_UPDATE_VOICEMAIL_RINGTONE_SUMMARY:
252 mVoicemailNotificationRingtone.setSummary((CharSequence) msg.obj);
253 break;
254 }
255 }
256 };
257
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 /** Whether dialpad plays DTMF tone or not. */
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700259 private CheckBoxPreference mButtonAutoRetry;
260 private CheckBoxPreference mButtonHAC;
261 private ListPreference mButtonDTMF;
262 private ListPreference mButtonTTY;
263 private ListPreference mButtonSipCallOptions;
Evan Charlton1c696832014-04-15 14:24:23 -0700264 private Preference mWifiCallOptionsPreference;
265 private Preference mWifiCallAccountPreference;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700266 private ListPreference mVoicemailProviders;
267 private PreferenceScreen mVoicemailSettings;
268 private Preference mVoicemailNotificationRingtone;
269 private CheckBoxPreference mVoicemailNotificationVibrate;
270 private SipSharedPreferences mSipSharedPreferences;
Andrew Leedb2fe562014-09-03 15:40:43 -0700271 private AccountSelectionPreference mDefaultOutgoingAccount;
272 private AccountSelectionPreference mSimCallManagerAccount;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273
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
468 /*
469 * Click Listeners, handle click based on objects attached to UI.
470 */
471
472 // Click listener for all toggle events
473 @Override
474 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
475 if (preference == mSubMenuVoicemailSettings) {
476 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 } else if (preference == mButtonDTMF) {
478 return true;
479 } else if (preference == mButtonTTY) {
480 return true;
481 } else if (preference == mButtonAutoRetry) {
482 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
483 android.provider.Settings.Global.CALL_AUTO_RETRY,
484 mButtonAutoRetry.isChecked() ? 1 : 0);
485 return true;
486 } else if (preference == mButtonHAC) {
487 int hac = mButtonHAC.isChecked() ? 1 : 0;
488 // Update HAC value in Settings database
489 Settings.System.putInt(mPhone.getContext().getContentResolver(),
490 Settings.System.HEARING_AID, hac);
491
492 // Update HAC Value in AudioManager
493 mAudioManager.setParameter(HAC_KEY, hac != 0 ? HAC_VAL_ON : HAC_VAL_OFF);
494 return true;
495 } else if (preference == mVoicemailSettings) {
496 if (DBG) log("onPreferenceTreeClick: Voicemail Settings Preference is clicked.");
497 if (preference.getIntent() != null) {
498 if (DBG) {
499 log("onPreferenceTreeClick: Invoking cfg intent "
500 + preference.getIntent().getPackage());
501 }
502
503 // onActivityResult() will be responsible for resetting some of variables.
504 this.startActivityForResult(preference.getIntent(), VOICEMAIL_PROVIDER_CFG_ID);
505 return true;
506 } else {
507 if (DBG) {
508 log("onPreferenceTreeClick:"
509 + " No Intent is available. Use default behavior defined in xml.");
510 }
511
512 // There's no onActivityResult(), so we need to take care of some of variables
513 // which should be reset here.
514 mPreviousVMProviderKey = DEFAULT_VM_PROVIDER_KEY;
515 mVMProviderSettingsForced = false;
516
517 // This should let the preference use default behavior in the xml.
518 return false;
519 }
520 }
521 return false;
522 }
523
524 /**
525 * Implemented to support onPreferenceChangeListener to look for preference
526 * changes.
527 *
528 * @param preference is the preference to be changed
529 * @param objValue should be the value of the selection, NOT its localized
530 * display value.
531 */
532 @Override
533 public boolean onPreferenceChange(Preference preference, Object objValue) {
534 if (DBG) {
535 log("onPreferenceChange(). preferenece: \"" + preference + "\""
536 + ", value: \"" + objValue + "\"");
537 }
Andrew Lee2170a972014-08-13 18:13:01 -0700538
539 if (preference == mButtonDTMF) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 int index = mButtonDTMF.findIndexOfValue((String) objValue);
541 Settings.System.putInt(mPhone.getContext().getContentResolver(),
542 Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, index);
543 } else if (preference == mButtonTTY) {
544 handleTTYChange(preference, objValue);
545 } else if (preference == mVoicemailProviders) {
546 final String newProviderKey = (String) objValue;
547 if (DBG) {
548 log("Voicemail Provider changes from \"" + mPreviousVMProviderKey
549 + "\" to \"" + newProviderKey + "\".");
550 }
551 // If previous provider key and the new one is same, we don't need to handle it.
552 if (mPreviousVMProviderKey.equals(newProviderKey)) {
553 if (DBG) log("No change is made toward VM provider setting.");
554 return true;
555 }
556 updateVMPreferenceWidgets(newProviderKey);
557
558 final VoiceMailProviderSettings newProviderSettings =
559 loadSettingsForVoiceMailProvider(newProviderKey);
560
561 // If the user switches to a voice mail provider and we have a
562 // numbers stored for it we will automatically change the
563 // phone's
564 // voice mail and forwarding number to the stored ones.
565 // Otherwise we will bring up provider's configuration UI.
566
567 if (newProviderSettings == null) {
568 // Force the user into a configuration of the chosen provider
569 Log.w(LOG_TAG, "Saved preferences not found - invoking config");
570 mVMProviderSettingsForced = true;
571 simulatePreferenceClick(mVoicemailSettings);
572 } else {
573 if (DBG) log("Saved preferences found - switching to them");
574 // Set this flag so if we get a failure we revert to previous provider
575 mChangingVMorFwdDueToProviderChange = true;
576 saveVoiceMailAndForwardingNumber(newProviderKey, newProviderSettings);
577 }
578 } else if (preference == mButtonSipCallOptions) {
579 handleSipCallOptionsChange(objValue);
580 }
581 // always let the preference setting proceed.
582 return true;
583 }
584
585 @Override
Evan Charlton1c696832014-04-15 14:24:23 -0700586 public boolean onPreferenceClick(Preference preference) {
587 if (preference == mWifiCallOptionsPreference || preference == mWifiCallAccountPreference) {
588 handleWifiCallSettingsClick(preference);
589 }
590 return true;
591 }
592
593 @Override
Andrew Leedb2fe562014-09-03 15:40:43 -0700594 public boolean onAccountSelected(AccountSelectionPreference pref, PhoneAccountHandle account) {
595 TelecommManager telecommManager = TelecommManager.from(this);
596 if (pref == mDefaultOutgoingAccount) {
597 telecommManager.setUserSelectedOutgoingPhoneAccount(account);
598 return true;
599 } else if (pref == mSimCallManagerAccount) {
600 telecommManager.setSimCallManager(account);
601 return true;
602 }
603 return false;
604 }
605
606 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700607 public void onDialogClosed(EditPhoneNumberPreference preference, int buttonClicked) {
608 if (DBG) log("onPreferenceClick: request preference click on dialog close: " +
609 buttonClicked);
610 if (buttonClicked == DialogInterface.BUTTON_NEGATIVE) {
611 return;
612 }
613
614 if (preference == mSubMenuVoicemailSettings) {
615 handleVMBtnClickRequest();
616 }
617 }
618
619 /**
620 * Implemented for EditPhoneNumberPreference.GetDefaultNumberListener.
621 * This method set the default values for the various
622 * EditPhoneNumberPreference dialogs.
623 */
624 @Override
625 public String onGetDefaultNumber(EditPhoneNumberPreference preference) {
626 if (preference == mSubMenuVoicemailSettings) {
627 // update the voicemail number field, which takes care of the
628 // mSubMenuVoicemailSettings itself, so we should return null.
629 if (DBG) log("updating default for voicemail dialog");
630 updateVoiceNumberField();
631 return null;
632 }
633
634 String vmDisplay = mPhone.getVoiceMailNumber();
635 if (TextUtils.isEmpty(vmDisplay)) {
636 // if there is no voicemail number, we just return null to
637 // indicate no contribution.
638 return null;
639 }
640
641 // Return the voicemail number prepended with "VM: "
642 if (DBG) log("updating default for call forwarding dialogs");
643 return getString(R.string.voicemail_abbreviated) + " " + vmDisplay;
644 }
645
646
647 // override the startsubactivity call to make changes in state consistent.
648 @Override
649 public void startActivityForResult(Intent intent, int requestCode) {
650 if (requestCode == -1) {
651 // this is an intent requested from the preference framework.
652 super.startActivityForResult(intent, requestCode);
653 return;
654 }
655
656 if (DBG) log("startSubActivity: starting requested subactivity");
657 super.startActivityForResult(intent, requestCode);
658 }
659
660 private void switchToPreviousVoicemailProvider() {
661 if (DBG) log("switchToPreviousVoicemailProvider " + mPreviousVMProviderKey);
662 if (mPreviousVMProviderKey != null) {
663 if (mVMChangeCompletedSuccessfully || mFwdChangesRequireRollback) {
664 // we have to revert with carrier
665 if (DBG) {
666 log("Needs to rollback."
667 + " mVMChangeCompletedSuccessfully=" + mVMChangeCompletedSuccessfully
668 + ", mFwdChangesRequireRollback=" + mFwdChangesRequireRollback);
669 }
670
671 showDialogIfForeground(VOICEMAIL_REVERTING_DIALOG);
672 final VoiceMailProviderSettings prevSettings =
673 loadSettingsForVoiceMailProvider(mPreviousVMProviderKey);
674 if (prevSettings == null) {
675 // prevSettings never becomes null since it should be already loaded!
676 Log.e(LOG_TAG, "VoiceMailProviderSettings for the key \""
677 + mPreviousVMProviderKey + "\" becomes null, which is unexpected.");
678 if (DBG) {
679 Log.e(LOG_TAG,
680 "mVMChangeCompletedSuccessfully: " + mVMChangeCompletedSuccessfully
681 + ", mFwdChangesRequireRollback: " + mFwdChangesRequireRollback);
682 }
683 }
684 if (mVMChangeCompletedSuccessfully) {
685 mNewVMNumber = prevSettings.voicemailNumber;
686 Log.i(LOG_TAG, "VM change is already completed successfully."
687 + "Have to revert VM back to " + mNewVMNumber + " again.");
688 mPhone.setVoiceMailNumber(
689 mPhone.getVoiceMailAlphaTag().toString(),
690 mNewVMNumber,
691 Message.obtain(mRevertOptionComplete, EVENT_VOICEMAIL_CHANGED));
692 }
693 if (mFwdChangesRequireRollback) {
694 Log.i(LOG_TAG, "Requested to rollback Fwd changes.");
695 final CallForwardInfo[] prevFwdSettings =
696 prevSettings.forwardingSettings;
697 if (prevFwdSettings != null) {
698 Map<Integer, AsyncResult> results =
699 mForwardingChangeResults;
700 resetForwardingChangeState();
701 for (int i = 0; i < prevFwdSettings.length; i++) {
702 CallForwardInfo fi = prevFwdSettings[i];
703 if (DBG) log("Reverting fwd #: " + i + ": " + fi.toString());
704 // Only revert the settings for which the update
705 // succeeded
706 AsyncResult result = results.get(fi.reason);
707 if (result != null && result.exception == null) {
708 mExpectedChangeResultReasons.add(fi.reason);
709 mPhone.setCallForwardingOption(
710 (fi.status == 1 ?
711 CommandsInterface.CF_ACTION_REGISTRATION :
712 CommandsInterface.CF_ACTION_DISABLE),
713 fi.reason,
714 fi.number,
715 fi.timeSeconds,
716 mRevertOptionComplete.obtainMessage(
717 EVENT_FORWARDING_CHANGED, i, 0));
718 }
719 }
720 }
721 }
722 } else {
723 if (DBG) log("No need to revert");
724 onRevertDone();
725 }
726 }
727 }
728
729 private void onRevertDone() {
730 if (DBG) log("Flipping provider key back to " + mPreviousVMProviderKey);
731 mVoicemailProviders.setValue(mPreviousVMProviderKey);
732 updateVMPreferenceWidgets(mPreviousVMProviderKey);
733 updateVoiceNumberField();
734 if (mVMOrFwdSetError != 0) {
735 showVMDialog(mVMOrFwdSetError);
736 mVMOrFwdSetError = 0;
737 }
738 }
739
740 @Override
741 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
742 if (DBG) {
743 log("onActivityResult: requestCode: " + requestCode
744 + ", resultCode: " + resultCode
745 + ", data: " + data);
746 }
747 // there are cases where the contact picker may end up sending us more than one
748 // request. We want to ignore the request if we're not in the correct state.
749 if (requestCode == VOICEMAIL_PROVIDER_CFG_ID) {
750 boolean failure = false;
751
752 // No matter how the processing of result goes lets clear the flag
753 if (DBG) log("mVMProviderSettingsForced: " + mVMProviderSettingsForced);
754 final boolean isVMProviderSettingsForced = mVMProviderSettingsForced;
755 mVMProviderSettingsForced = false;
756
757 String vmNum = null;
758 if (resultCode != RESULT_OK) {
759 if (DBG) log("onActivityResult: vm provider cfg result not OK.");
760 failure = true;
761 } else {
762 if (data == null) {
763 if (DBG) log("onActivityResult: vm provider cfg result has no data");
764 failure = true;
765 } else {
766 if (data.getBooleanExtra(SIGNOUT_EXTRA, false)) {
767 if (DBG) log("Provider requested signout");
768 if (isVMProviderSettingsForced) {
769 if (DBG) log("Going back to previous provider on signout");
770 switchToPreviousVoicemailProvider();
771 } else {
772 final String victim = getCurrentVoicemailProviderKey();
773 if (DBG) log("Relaunching activity and ignoring " + victim);
774 Intent i = new Intent(ACTION_ADD_VOICEMAIL);
775 i.putExtra(IGNORE_PROVIDER_EXTRA, victim);
776 i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
777 this.startActivity(i);
778 }
779 return;
780 }
781 vmNum = data.getStringExtra(VM_NUMBER_EXTRA);
782 if (vmNum == null || vmNum.length() == 0) {
783 if (DBG) log("onActivityResult: vm provider cfg result has no vmnum");
784 failure = true;
785 }
786 }
787 }
788 if (failure) {
789 if (DBG) log("Failure in return from voicemail provider");
790 if (isVMProviderSettingsForced) {
791 switchToPreviousVoicemailProvider();
792 } else {
793 if (DBG) log("Not switching back the provider since this is not forced config");
794 }
795 return;
796 }
797 mChangingVMorFwdDueToProviderChange = isVMProviderSettingsForced;
798 final String fwdNum = data.getStringExtra(FWD_NUMBER_EXTRA);
799
Santos Cordonda120f42014-08-06 04:44:34 -0700800 // TODO: It would be nice to load the current network setting for this and
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700801 // send it to the provider when it's config is invoked so it can use this as default
802 final int fwdNumTime = data.getIntExtra(FWD_NUMBER_TIME_EXTRA, 20);
803
804 if (DBG) log("onActivityResult: vm provider cfg result " +
805 (fwdNum != null ? "has" : " does not have") + " forwarding number");
806 saveVoiceMailAndForwardingNumber(getCurrentVoicemailProviderKey(),
807 new VoiceMailProviderSettings(vmNum, fwdNum, fwdNumTime));
808 return;
809 }
810
811 if (requestCode == VOICEMAIL_PREF_ID) {
812 if (resultCode != RESULT_OK) {
813 if (DBG) log("onActivityResult: contact picker result not OK.");
814 return;
815 }
816
817 Cursor cursor = null;
818 try {
819 cursor = getContentResolver().query(data.getData(),
820 NUM_PROJECTION, null, null, null);
821 if ((cursor == null) || (!cursor.moveToFirst())) {
822 if (DBG) log("onActivityResult: bad contact data, no results found.");
823 return;
824 }
825 mSubMenuVoicemailSettings.onPickActivityResult(cursor.getString(0));
826 return;
827 } finally {
828 if (cursor != null) {
829 cursor.close();
830 }
831 }
832 }
833
834 super.onActivityResult(requestCode, resultCode, data);
835 }
836
837 // Voicemail button logic
838 private void handleVMBtnClickRequest() {
839 // normally called on the dialog close.
840
841 // Since we're stripping the formatting out on the getPhoneNumber()
842 // call now, we won't need to do so here anymore.
843
844 saveVoiceMailAndForwardingNumber(
845 getCurrentVoicemailProviderKey(),
846 new VoiceMailProviderSettings(mSubMenuVoicemailSettings.getPhoneNumber(),
847 FWD_SETTINGS_DONT_TOUCH));
848 }
849
850
851 /**
852 * Wrapper around showDialog() that will silently do nothing if we're
853 * not in the foreground.
854 *
855 * This is useful here because most of the dialogs we display from
856 * this class are triggered by asynchronous events (like
857 * success/failure messages from the telephony layer) and it's
858 * possible for those events to come in even after the user has gone
859 * to a different screen.
860 */
861 // TODO: this is too brittle: it's still easy to accidentally add new
862 // code here that calls showDialog() directly (which will result in a
863 // WindowManager$BadTokenException if called after the activity has
864 // been stopped.)
865 //
866 // It would be cleaner to do the "if (mForeground)" check in one
867 // central place, maybe by using a single Handler for all asynchronous
868 // events (and have *that* discard events if we're not in the
869 // foreground.)
870 //
871 // Unfortunately it's not that simple, since we sometimes need to do
872 // actual work to handle these events whether or not we're in the
873 // foreground (see the Handler code in mSetOptionComplete for
874 // example.)
875 private void showDialogIfForeground(int id) {
876 if (mForeground) {
877 showDialog(id);
878 }
879 }
880
881 private void dismissDialogSafely(int id) {
882 try {
883 dismissDialog(id);
884 } catch (IllegalArgumentException e) {
885 // This is expected in the case where we were in the background
886 // at the time we would normally have shown the dialog, so we didn't
887 // show it.
888 }
889 }
890
891 private void saveVoiceMailAndForwardingNumber(String key,
892 VoiceMailProviderSettings newSettings) {
893 if (DBG) log("saveVoiceMailAndForwardingNumber: " + newSettings.toString());
894 mNewVMNumber = newSettings.voicemailNumber;
895 // empty vm number == clearing the vm number ?
896 if (mNewVMNumber == null) {
897 mNewVMNumber = "";
898 }
899
900 mNewFwdSettings = newSettings.forwardingSettings;
901 if (DBG) log("newFwdNumber " +
902 String.valueOf((mNewFwdSettings != null ? mNewFwdSettings.length : 0))
903 + " settings");
904
905 // No fwd settings on CDMA
906 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
907 if (DBG) log("ignoring forwarding setting since this is CDMA phone");
908 mNewFwdSettings = FWD_SETTINGS_DONT_TOUCH;
909 }
910
911 //throw a warning if the vm is the same and we do not touch forwarding.
912 if (mNewVMNumber.equals(mOldVmNumber) && mNewFwdSettings == FWD_SETTINGS_DONT_TOUCH) {
913 showVMDialog(MSG_VM_NOCHANGE);
914 return;
915 }
916
917 maybeSaveSettingsForVoicemailProvider(key, newSettings);
918 mVMChangeCompletedSuccessfully = false;
919 mFwdChangesRequireRollback = false;
920 mVMOrFwdSetError = 0;
921 if (!key.equals(mPreviousVMProviderKey)) {
922 mReadingSettingsForDefaultProvider =
923 mPreviousVMProviderKey.equals(DEFAULT_VM_PROVIDER_KEY);
924 if (DBG) log("Reading current forwarding settings");
925 mForwardingReadResults = new CallForwardInfo[FORWARDING_SETTINGS_REASONS.length];
926 for (int i = 0; i < FORWARDING_SETTINGS_REASONS.length; i++) {
927 mForwardingReadResults[i] = null;
928 mPhone.getCallForwardingOption(FORWARDING_SETTINGS_REASONS[i],
929 mGetOptionComplete.obtainMessage(EVENT_FORWARDING_GET_COMPLETED, i, 0));
930 }
931 showDialogIfForeground(VOICEMAIL_FWD_READING_DIALOG);
932 } else {
933 saveVoiceMailAndForwardingNumberStage2();
934 }
935 }
936
937 private final Handler mGetOptionComplete = new Handler() {
938 @Override
939 public void handleMessage(Message msg) {
940 AsyncResult result = (AsyncResult) msg.obj;
941 switch (msg.what) {
942 case EVENT_FORWARDING_GET_COMPLETED:
943 handleForwardingSettingsReadResult(result, msg.arg1);
944 break;
945 }
946 }
947 };
948
949 private void handleForwardingSettingsReadResult(AsyncResult ar, int idx) {
950 if (DBG) Log.d(LOG_TAG, "handleForwardingSettingsReadResult: " + idx);
951 Throwable error = null;
952 if (ar.exception != null) {
953 if (DBG) Log.d(LOG_TAG, "FwdRead: ar.exception=" +
954 ar.exception.getMessage());
955 error = ar.exception;
956 }
957 if (ar.userObj instanceof Throwable) {
958 if (DBG) Log.d(LOG_TAG, "FwdRead: userObj=" +
959 ((Throwable)ar.userObj).getMessage());
960 error = (Throwable)ar.userObj;
961 }
962
963 // We may have already gotten an error and decided to ignore the other results.
964 if (mForwardingReadResults == null) {
965 if (DBG) Log.d(LOG_TAG, "ignoring fwd reading result: " + idx);
966 return;
967 }
968
969 // In case of error ignore other results, show an error dialog
970 if (error != null) {
971 if (DBG) Log.d(LOG_TAG, "Error discovered for fwd read : " + idx);
972 mForwardingReadResults = null;
973 dismissDialogSafely(VOICEMAIL_FWD_READING_DIALOG);
974 showVMDialog(MSG_FW_GET_EXCEPTION);
975 return;
976 }
977
978 // Get the forwarding info
979 final CallForwardInfo cfInfoArray[] = (CallForwardInfo[]) ar.result;
980 CallForwardInfo fi = null;
981 for (int i = 0 ; i < cfInfoArray.length; i++) {
982 if ((cfInfoArray[i].serviceClass & CommandsInterface.SERVICE_CLASS_VOICE) != 0) {
983 fi = cfInfoArray[i];
984 break;
985 }
986 }
987 if (fi == null) {
988
989 // In case we go nothing it means we need this reason disabled
990 // so create a CallForwardInfo for capturing this
991 if (DBG) Log.d(LOG_TAG, "Creating default info for " + idx);
992 fi = new CallForwardInfo();
993 fi.status = 0;
994 fi.reason = FORWARDING_SETTINGS_REASONS[idx];
995 fi.serviceClass = CommandsInterface.SERVICE_CLASS_VOICE;
996 } else {
997 // if there is not a forwarding number, ensure the entry is set to "not active."
998 if (fi.number == null || fi.number.length() == 0) {
999 fi.status = 0;
1000 }
1001
1002 if (DBG) Log.d(LOG_TAG, "Got " + fi.toString() + " for " + idx);
1003 }
1004 mForwardingReadResults[idx] = fi;
1005
1006 // Check if we got all the results already
1007 boolean done = true;
1008 for (int i = 0; i < mForwardingReadResults.length; i++) {
1009 if (mForwardingReadResults[i] == null) {
1010 done = false;
1011 break;
1012 }
1013 }
1014 if (done) {
1015 if (DBG) Log.d(LOG_TAG, "Done receiving fwd info");
1016 dismissDialogSafely(VOICEMAIL_FWD_READING_DIALOG);
1017 if (mReadingSettingsForDefaultProvider) {
1018 maybeSaveSettingsForVoicemailProvider(DEFAULT_VM_PROVIDER_KEY,
1019 new VoiceMailProviderSettings(this.mOldVmNumber,
1020 mForwardingReadResults));
1021 mReadingSettingsForDefaultProvider = false;
1022 }
1023 saveVoiceMailAndForwardingNumberStage2();
1024 } else {
1025 if (DBG) Log.d(LOG_TAG, "Not done receiving fwd info");
1026 }
1027 }
1028
1029 private CallForwardInfo infoForReason(CallForwardInfo[] infos, int reason) {
1030 CallForwardInfo result = null;
1031 if (null != infos) {
1032 for (CallForwardInfo info : infos) {
1033 if (info.reason == reason) {
1034 result = info;
1035 break;
1036 }
1037 }
1038 }
1039 return result;
1040 }
1041
1042 private boolean isUpdateRequired(CallForwardInfo oldInfo,
1043 CallForwardInfo newInfo) {
1044 boolean result = true;
1045 if (0 == newInfo.status) {
1046 // If we're disabling a type of forwarding, and it's already
1047 // disabled for the account, don't make any change
1048 if (oldInfo != null && oldInfo.status == 0) {
1049 result = false;
1050 }
1051 }
1052 return result;
1053 }
1054
1055 private void resetForwardingChangeState() {
1056 mForwardingChangeResults = new HashMap<Integer, AsyncResult>();
1057 mExpectedChangeResultReasons = new HashSet<Integer>();
1058 }
1059
1060 // Called after we are done saving the previous forwarding settings if
1061 // we needed.
1062 private void saveVoiceMailAndForwardingNumberStage2() {
1063 mForwardingChangeResults = null;
1064 mVoicemailChangeResult = null;
1065 if (mNewFwdSettings != FWD_SETTINGS_DONT_TOUCH) {
1066 resetForwardingChangeState();
1067 for (int i = 0; i < mNewFwdSettings.length; i++) {
1068 CallForwardInfo fi = mNewFwdSettings[i];
1069
1070 final boolean doUpdate = isUpdateRequired(infoForReason(
1071 mForwardingReadResults, fi.reason), fi);
1072
1073 if (doUpdate) {
1074 if (DBG) log("Setting fwd #: " + i + ": " + fi.toString());
1075 mExpectedChangeResultReasons.add(i);
1076
1077 mPhone.setCallForwardingOption(
1078 fi.status == 1 ?
1079 CommandsInterface.CF_ACTION_REGISTRATION :
1080 CommandsInterface.CF_ACTION_DISABLE,
1081 fi.reason,
1082 fi.number,
1083 fi.timeSeconds,
1084 mSetOptionComplete.obtainMessage(
1085 EVENT_FORWARDING_CHANGED, fi.reason, 0));
1086 }
1087 }
1088 showDialogIfForeground(VOICEMAIL_FWD_SAVING_DIALOG);
1089 } else {
1090 if (DBG) log("Not touching fwd #");
1091 setVMNumberWithCarrier();
1092 }
1093 }
1094
1095 private void setVMNumberWithCarrier() {
1096 if (DBG) log("save voicemail #: " + mNewVMNumber);
1097 mPhone.setVoiceMailNumber(
1098 mPhone.getVoiceMailAlphaTag().toString(),
1099 mNewVMNumber,
1100 Message.obtain(mSetOptionComplete, EVENT_VOICEMAIL_CHANGED));
1101 }
1102
1103 /**
1104 * Callback to handle option update completions
1105 */
1106 private final Handler mSetOptionComplete = new Handler() {
1107 @Override
1108 public void handleMessage(Message msg) {
1109 AsyncResult result = (AsyncResult) msg.obj;
1110 boolean done = false;
1111 switch (msg.what) {
1112 case EVENT_VOICEMAIL_CHANGED:
1113 mVoicemailChangeResult = result;
1114 mVMChangeCompletedSuccessfully = checkVMChangeSuccess() == null;
1115 if (DBG) log("VM change complete msg, VM change done = " +
1116 String.valueOf(mVMChangeCompletedSuccessfully));
1117 done = true;
1118 break;
1119 case EVENT_FORWARDING_CHANGED:
1120 mForwardingChangeResults.put(msg.arg1, result);
1121 if (result.exception != null) {
1122 Log.w(LOG_TAG, "Error in setting fwd# " + msg.arg1 + ": " +
1123 result.exception.getMessage());
1124 } else {
1125 if (DBG) log("Success in setting fwd# " + msg.arg1);
1126 }
1127 final boolean completed = checkForwardingCompleted();
1128 if (completed) {
1129 if (checkFwdChangeSuccess() == null) {
1130 if (DBG) log("Overall fwd changes completed ok, starting vm change");
1131 setVMNumberWithCarrier();
1132 } else {
1133 Log.w(LOG_TAG, "Overall fwd changes completed in failure. " +
1134 "Check if we need to try rollback for some settings.");
1135 mFwdChangesRequireRollback = false;
1136 Iterator<Map.Entry<Integer,AsyncResult>> it =
1137 mForwardingChangeResults.entrySet().iterator();
1138 while (it.hasNext()) {
1139 Map.Entry<Integer,AsyncResult> entry = it.next();
1140 if (entry.getValue().exception == null) {
1141 // If at least one succeeded we have to revert
1142 Log.i(LOG_TAG, "Rollback will be required");
1143 mFwdChangesRequireRollback = true;
1144 break;
1145 }
1146 }
1147 if (!mFwdChangesRequireRollback) {
1148 Log.i(LOG_TAG, "No rollback needed.");
1149 }
1150 done = true;
1151 }
1152 }
1153 break;
1154 default:
1155 // TODO: should never reach this, may want to throw exception
1156 }
1157 if (done) {
1158 if (DBG) log("All VM provider related changes done");
1159 if (mForwardingChangeResults != null) {
1160 dismissDialogSafely(VOICEMAIL_FWD_SAVING_DIALOG);
1161 }
1162 handleSetVMOrFwdMessage();
1163 }
1164 }
1165 };
1166
1167 /**
1168 * Callback to handle option revert completions
1169 */
1170 private final Handler mRevertOptionComplete = new Handler() {
1171 @Override
1172 public void handleMessage(Message msg) {
1173 AsyncResult result = (AsyncResult) msg.obj;
1174 switch (msg.what) {
1175 case EVENT_VOICEMAIL_CHANGED:
1176 mVoicemailChangeResult = result;
1177 if (DBG) log("VM revert complete msg");
1178 break;
1179 case EVENT_FORWARDING_CHANGED:
1180 mForwardingChangeResults.put(msg.arg1, result);
1181 if (result.exception != null) {
1182 if (DBG) log("Error in reverting fwd# " + msg.arg1 + ": " +
1183 result.exception.getMessage());
1184 } else {
1185 if (DBG) log("Success in reverting fwd# " + msg.arg1);
1186 }
1187 if (DBG) log("FWD revert complete msg ");
1188 break;
1189 default:
1190 // TODO: should never reach this, may want to throw exception
1191 }
1192 final boolean done =
1193 (!mVMChangeCompletedSuccessfully || mVoicemailChangeResult != null) &&
1194 (!mFwdChangesRequireRollback || checkForwardingCompleted());
1195 if (done) {
1196 if (DBG) log("All VM reverts done");
1197 dismissDialogSafely(VOICEMAIL_REVERTING_DIALOG);
1198 onRevertDone();
1199 }
1200 }
1201 };
1202
1203 /**
1204 * @return true if forwarding change has completed
1205 */
1206 private boolean checkForwardingCompleted() {
1207 boolean result;
1208 if (mForwardingChangeResults == null) {
1209 result = true;
1210 } else {
1211 // return true iff there is a change result for every reason for
1212 // which we expected a result
1213 result = true;
1214 for (Integer reason : mExpectedChangeResultReasons) {
1215 if (mForwardingChangeResults.get(reason) == null) {
1216 result = false;
1217 break;
1218 }
1219 }
1220 }
1221 return result;
1222 }
1223 /**
1224 * @return error string or null if successful
1225 */
1226 private String checkFwdChangeSuccess() {
1227 String result = null;
1228 Iterator<Map.Entry<Integer,AsyncResult>> it =
1229 mForwardingChangeResults.entrySet().iterator();
1230 while (it.hasNext()) {
1231 Map.Entry<Integer,AsyncResult> entry = it.next();
1232 Throwable exception = entry.getValue().exception;
1233 if (exception != null) {
1234 result = exception.getMessage();
1235 if (result == null) {
1236 result = "";
1237 }
1238 break;
1239 }
1240 }
1241 return result;
1242 }
1243
1244 /**
1245 * @return error string or null if successful
1246 */
1247 private String checkVMChangeSuccess() {
1248 if (mVoicemailChangeResult.exception != null) {
1249 final String msg = mVoicemailChangeResult.exception.getMessage();
1250 if (msg == null) {
1251 return "";
1252 }
1253 return msg;
1254 }
1255 return null;
1256 }
1257
1258 private void handleSetVMOrFwdMessage() {
1259 if (DBG) {
1260 log("handleSetVMMessage: set VM request complete");
1261 }
1262 boolean success = true;
1263 boolean fwdFailure = false;
1264 String exceptionMessage = "";
1265 if (mForwardingChangeResults != null) {
1266 exceptionMessage = checkFwdChangeSuccess();
1267 if (exceptionMessage != null) {
1268 success = false;
1269 fwdFailure = true;
1270 }
1271 }
1272 if (success) {
1273 exceptionMessage = checkVMChangeSuccess();
1274 if (exceptionMessage != null) {
1275 success = false;
1276 }
1277 }
1278 if (success) {
1279 if (DBG) log("change VM success!");
1280 handleVMAndFwdSetSuccess(MSG_VM_OK);
1281 } else {
1282 if (fwdFailure) {
1283 Log.w(LOG_TAG, "Failed to change fowarding setting. Reason: " + exceptionMessage);
1284 handleVMOrFwdSetError(MSG_FW_SET_EXCEPTION);
1285 } else {
1286 Log.w(LOG_TAG, "Failed to change voicemail. Reason: " + exceptionMessage);
1287 handleVMOrFwdSetError(MSG_VM_EXCEPTION);
1288 }
1289 }
1290 }
1291
1292 /**
1293 * Called when Voicemail Provider or its forwarding settings failed. Rolls back partly made
1294 * changes to those settings and show "failure" dialog.
1295 *
1296 * @param msgId Message ID used for the specific error case. {@link #MSG_FW_SET_EXCEPTION} or
1297 * {@link #MSG_VM_EXCEPTION}
1298 */
1299 private void handleVMOrFwdSetError(int msgId) {
1300 if (mChangingVMorFwdDueToProviderChange) {
1301 mVMOrFwdSetError = msgId;
1302 mChangingVMorFwdDueToProviderChange = false;
1303 switchToPreviousVoicemailProvider();
1304 return;
1305 }
1306 mChangingVMorFwdDueToProviderChange = false;
1307 showVMDialog(msgId);
1308 updateVoiceNumberField();
1309 }
1310
1311 /**
1312 * Called when Voicemail Provider and its forwarding settings were successfully finished.
1313 * This updates a bunch of variables and show "success" dialog.
1314 */
1315 private void handleVMAndFwdSetSuccess(int msg) {
1316 if (DBG) {
1317 log("handleVMAndFwdSetSuccess(). current voicemail provider key: "
1318 + getCurrentVoicemailProviderKey());
1319 }
1320 mPreviousVMProviderKey = getCurrentVoicemailProviderKey();
1321 mChangingVMorFwdDueToProviderChange = false;
1322 showVMDialog(msg);
1323 updateVoiceNumberField();
1324 }
1325
1326 /**
1327 * Update the voicemail number from what we've recorded on the sim.
1328 */
1329 private void updateVoiceNumberField() {
1330 if (DBG) {
1331 log("updateVoiceNumberField(). mSubMenuVoicemailSettings=" + mSubMenuVoicemailSettings);
1332 }
1333 if (mSubMenuVoicemailSettings == null) {
1334 return;
1335 }
1336
1337 mOldVmNumber = mPhone.getVoiceMailNumber();
1338 if (mOldVmNumber == null) {
1339 mOldVmNumber = "";
1340 }
1341 mSubMenuVoicemailSettings.setPhoneNumber(mOldVmNumber);
1342 final String summary = (mOldVmNumber.length() > 0) ? mOldVmNumber :
1343 getString(R.string.voicemail_number_not_set);
1344 mSubMenuVoicemailSettings.setSummary(summary);
1345 }
1346
1347 /*
1348 * Helper Methods for Activity class.
1349 * The initial query commands are split into two pieces now
1350 * for individual expansion. This combined with the ability
1351 * to cancel queries allows for a much better user experience,
1352 * and also ensures that the user only waits to update the
1353 * data that is relevant.
1354 */
1355
1356 @Override
1357 protected void onPrepareDialog(int id, Dialog dialog) {
1358 super.onPrepareDialog(id, dialog);
1359 mCurrentDialogId = id;
1360 }
1361
1362 // dialog creation method, called by showDialog()
1363 @Override
1364 protected Dialog onCreateDialog(int id) {
1365 if ((id == VM_RESPONSE_ERROR) || (id == VM_NOCHANGE_ERROR) ||
1366 (id == FW_SET_RESPONSE_ERROR) || (id == FW_GET_RESPONSE_ERROR) ||
1367 (id == VOICEMAIL_DIALOG_CONFIRM)) {
1368
1369 AlertDialog.Builder b = new AlertDialog.Builder(this);
1370
1371 int msgId;
1372 int titleId = R.string.error_updating_title;
1373 switch (id) {
1374 case VOICEMAIL_DIALOG_CONFIRM:
1375 msgId = R.string.vm_changed;
1376 titleId = R.string.voicemail;
1377 // Set Button 2
1378 b.setNegativeButton(R.string.close_dialog, this);
1379 break;
1380 case VM_NOCHANGE_ERROR:
1381 // even though this is technically an error,
1382 // keep the title friendly.
1383 msgId = R.string.no_change;
1384 titleId = R.string.voicemail;
1385 // Set Button 2
1386 b.setNegativeButton(R.string.close_dialog, this);
1387 break;
1388 case VM_RESPONSE_ERROR:
1389 msgId = R.string.vm_change_failed;
1390 // Set Button 1
1391 b.setPositiveButton(R.string.close_dialog, this);
1392 break;
1393 case FW_SET_RESPONSE_ERROR:
1394 msgId = R.string.fw_change_failed;
1395 // Set Button 1
1396 b.setPositiveButton(R.string.close_dialog, this);
1397 break;
1398 case FW_GET_RESPONSE_ERROR:
1399 msgId = R.string.fw_get_in_vm_failed;
1400 b.setPositiveButton(R.string.alert_dialog_yes, this);
1401 b.setNegativeButton(R.string.alert_dialog_no, this);
1402 break;
1403 default:
1404 msgId = R.string.exception_error;
1405 // Set Button 3, tells the activity that the error is
1406 // not recoverable on dialog exit.
1407 b.setNeutralButton(R.string.close_dialog, this);
1408 break;
1409 }
1410
1411 b.setTitle(getText(titleId));
1412 String message = getText(msgId).toString();
1413 b.setMessage(message);
1414 b.setCancelable(false);
1415 AlertDialog dialog = b.create();
1416
1417 // make the dialog more obvious by bluring the background.
1418 dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
1419
1420 return dialog;
1421 } else if (id == VOICEMAIL_FWD_SAVING_DIALOG || id == VOICEMAIL_FWD_READING_DIALOG ||
1422 id == VOICEMAIL_REVERTING_DIALOG) {
1423 ProgressDialog dialog = new ProgressDialog(this);
1424 dialog.setTitle(getText(R.string.updating_title));
1425 dialog.setIndeterminate(true);
1426 dialog.setCancelable(false);
1427 dialog.setMessage(getText(
1428 id == VOICEMAIL_FWD_SAVING_DIALOG ? R.string.updating_settings :
1429 (id == VOICEMAIL_REVERTING_DIALOG ? R.string.reverting_settings :
1430 R.string.reading_settings)));
1431 return dialog;
1432 }
1433
1434
1435 return null;
1436 }
1437
1438 // This is a method implemented for DialogInterface.OnClickListener.
1439 // Used with the error dialog to close the app, voicemail dialog to just dismiss.
1440 // Close button is mapped to BUTTON_POSITIVE for the errors that close the activity,
1441 // while those that are mapped to BUTTON_NEUTRAL only move the preference focus.
1442 public void onClick(DialogInterface dialog, int which) {
1443 dialog.dismiss();
1444 switch (which){
1445 case DialogInterface.BUTTON_NEUTRAL:
1446 if (DBG) log("Neutral button");
1447 break;
1448 case DialogInterface.BUTTON_NEGATIVE:
1449 if (DBG) log("Negative button");
1450 if (mCurrentDialogId == FW_GET_RESPONSE_ERROR) {
1451 // We failed to get current forwarding settings and the user
1452 // does not wish to continue.
1453 switchToPreviousVoicemailProvider();
1454 }
1455 break;
1456 case DialogInterface.BUTTON_POSITIVE:
1457 if (DBG) log("Positive button");
1458 if (mCurrentDialogId == FW_GET_RESPONSE_ERROR) {
1459 // We failed to get current forwarding settings but the user
1460 // wishes to continue changing settings to the new vm provider
1461 saveVoiceMailAndForwardingNumberStage2();
1462 } else {
1463 finish();
1464 }
1465 return;
1466 default:
1467 // just let the dialog close and go back to the input
1468 }
1469 // In all dialogs, all buttons except BUTTON_POSITIVE lead to the end of user interaction
1470 // with settings UI. If we were called to explicitly configure voice mail then
1471 // we finish the settings activity here to come back to whatever the user was doing.
1472 if (getIntent().getAction().equals(ACTION_ADD_VOICEMAIL)) {
1473 finish();
1474 }
1475 }
1476
1477 // set the app state with optional status.
1478 private void showVMDialog(int msgStatus) {
1479 switch (msgStatus) {
1480 // It's a bit worrisome to punt in the error cases here when we're
1481 // not in the foreground; maybe toast instead?
1482 case MSG_VM_EXCEPTION:
1483 showDialogIfForeground(VM_RESPONSE_ERROR);
1484 break;
1485 case MSG_FW_SET_EXCEPTION:
1486 showDialogIfForeground(FW_SET_RESPONSE_ERROR);
1487 break;
1488 case MSG_FW_GET_EXCEPTION:
1489 showDialogIfForeground(FW_GET_RESPONSE_ERROR);
1490 break;
1491 case MSG_VM_NOCHANGE:
1492 showDialogIfForeground(VM_NOCHANGE_ERROR);
1493 break;
1494 case MSG_VM_OK:
1495 showDialogIfForeground(VOICEMAIL_DIALOG_CONFIRM);
1496 break;
1497 case MSG_OK:
1498 default:
1499 // This should never happen.
1500 }
1501 }
1502
1503 /*
1504 * Activity class methods
1505 */
1506
1507 @Override
1508 protected void onCreate(Bundle icicle) {
1509 super.onCreate(icicle);
1510 if (DBG) log("onCreate(). Intent: " + getIntent());
1511 mPhone = PhoneGlobals.getPhone();
1512
1513 addPreferencesFromResource(R.xml.call_feature_setting);
1514
Andrew Leedb2fe562014-09-03 15:40:43 -07001515 initPhoneAccountPreferences();
1516
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001517 mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
1518
1519 // get buttons
1520 PreferenceScreen prefSet = getPreferenceScreen();
1521 mSubMenuVoicemailSettings = (EditPhoneNumberPreference)findPreference(BUTTON_VOICEMAIL_KEY);
1522 if (mSubMenuVoicemailSettings != null) {
1523 mSubMenuVoicemailSettings.setParentActivity(this, VOICEMAIL_PREF_ID, this);
1524 mSubMenuVoicemailSettings.setDialogOnClosedListener(this);
1525 mSubMenuVoicemailSettings.setDialogTitle(R.string.voicemail_settings_number_label);
1526 }
1527
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 mButtonDTMF = (ListPreference) findPreference(BUTTON_DTMF_KEY);
1529 mButtonAutoRetry = (CheckBoxPreference) findPreference(BUTTON_RETRY_KEY);
1530 mButtonHAC = (CheckBoxPreference) findPreference(BUTTON_HAC_KEY);
1531 mButtonTTY = (ListPreference) findPreference(BUTTON_TTY_KEY);
1532 mVoicemailProviders = (ListPreference) findPreference(BUTTON_VOICEMAIL_PROVIDER_KEY);
Andrew Lee2170a972014-08-13 18:13:01 -07001533
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534 if (mVoicemailProviders != null) {
1535 mVoicemailProviders.setOnPreferenceChangeListener(this);
1536 mVoicemailSettings = (PreferenceScreen)findPreference(BUTTON_VOICEMAIL_SETTING_KEY);
1537 mVoicemailNotificationRingtone =
1538 findPreference(BUTTON_VOICEMAIL_NOTIFICATION_RINGTONE_KEY);
1539 mVoicemailNotificationVibrate =
1540 (CheckBoxPreference) findPreference(BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY);
1541 initVoiceMailProviders();
1542 }
1543
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 final ContentResolver contentResolver = getContentResolver();
1545
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001546 if (mButtonDTMF != null) {
1547 if (getResources().getBoolean(R.bool.dtmf_type_enabled)) {
1548 mButtonDTMF.setOnPreferenceChangeListener(this);
1549 } else {
1550 prefSet.removePreference(mButtonDTMF);
1551 mButtonDTMF = null;
1552 }
1553 }
1554
1555 if (mButtonAutoRetry != null) {
1556 if (getResources().getBoolean(R.bool.auto_retry_enabled)) {
1557 mButtonAutoRetry.setOnPreferenceChangeListener(this);
1558 } else {
1559 prefSet.removePreference(mButtonAutoRetry);
1560 mButtonAutoRetry = null;
1561 }
1562 }
1563
1564 if (mButtonHAC != null) {
1565 if (getResources().getBoolean(R.bool.hac_enabled)) {
1566
1567 mButtonHAC.setOnPreferenceChangeListener(this);
1568 } else {
1569 prefSet.removePreference(mButtonHAC);
1570 mButtonHAC = null;
1571 }
1572 }
1573
1574 if (mButtonTTY != null) {
Sailesh Nepalbf900542014-07-15 16:18:32 -07001575 TelecommManager telecommManager = TelecommManager.from(this);
1576 if (telecommManager != null && telecommManager.isTtySupported()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 mButtonTTY.setOnPreferenceChangeListener(this);
1578 } else {
1579 prefSet.removePreference(mButtonTTY);
1580 mButtonTTY = null;
1581 }
1582 }
1583
1584 if (!getResources().getBoolean(R.bool.world_phone)) {
1585 Preference options = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
Andrew Lee2170a972014-08-13 18:13:01 -07001586 if (options != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 prefSet.removePreference(options);
Andrew Lee2170a972014-08-13 18:13:01 -07001588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 options = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
Andrew Lee2170a972014-08-13 18:13:01 -07001590 if (options != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 prefSet.removePreference(options);
Andrew Lee2170a972014-08-13 18:13:01 -07001592 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593
1594 int phoneType = mPhone.getPhoneType();
1595 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
1596 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
Andrew Lee2170a972014-08-13 18:13:01 -07001597 if (fdnButton != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 prefSet.removePreference(fdnButton);
Andrew Lee2170a972014-08-13 18:13:01 -07001599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 if (!getResources().getBoolean(R.bool.config_voice_privacy_disable)) {
1601 addPreferencesFromResource(R.xml.cdma_call_privacy);
1602 }
1603 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Andrew Lee2170a972014-08-13 18:13:01 -07001604 if (getResources().getBoolean(R.bool.config_additional_call_setting)) {
Etan Cohen0ca1c802014-07-07 15:35:48 -07001605 addPreferencesFromResource(R.xml.gsm_umts_call_options);
1606 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001607 } else {
1608 throw new IllegalStateException("Unexpected phone type: " + phoneType);
1609 }
1610 }
1611
1612 // create intent to bring up contact list
1613 mContactListIntent = new Intent(Intent.ACTION_GET_CONTENT);
1614 mContactListIntent.setType(android.provider.Contacts.Phones.CONTENT_ITEM_TYPE);
1615
1616 // check the intent that started this activity and pop up the voicemail
1617 // dialog if we've been asked to.
1618 // If we have at least one non default VM provider registered then bring up
1619 // the selection for the VM provider, otherwise bring up a VM number dialog.
1620 // We only bring up the dialog the first time we are called (not after orientation change)
1621 if (icicle == null) {
1622 if (getIntent().getAction().equals(ACTION_ADD_VOICEMAIL) &&
1623 mVoicemailProviders != null) {
1624 if (DBG) {
1625 log("ACTION_ADD_VOICEMAIL Intent is thrown. current VM data size: "
1626 + mVMProvidersData.size());
1627 }
1628 if (mVMProvidersData.size() > 1) {
1629 simulatePreferenceClick(mVoicemailProviders);
1630 } else {
1631 onPreferenceChange(mVoicemailProviders, DEFAULT_VM_PROVIDER_KEY);
1632 mVoicemailProviders.setValue(DEFAULT_VM_PROVIDER_KEY);
1633 }
1634 }
1635 }
1636 updateVoiceNumberField();
1637 mVMProviderSettingsForced = false;
1638 createSipCallSettings();
1639
Andrew Lee2170a972014-08-13 18:13:01 -07001640 mVoicemailRingtoneLookupRunnable = new Runnable() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 @Override
1642 public void run() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 if (mVoicemailNotificationRingtone != null) {
Andrew Lee2170a972014-08-13 18:13:01 -07001644 SettingsUtil.updateRingtoneName(
1645 mPhone.getContext(),
1646 mVoicemailRingtoneLookupComplete,
1647 RingtoneManager.TYPE_NOTIFICATION,
1648 mVoicemailNotificationRingtone,
1649 MSG_UPDATE_VOICEMAIL_RINGTONE_SUMMARY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 }
1651 }
1652 };
1653
1654 ActionBar actionBar = getActionBar();
1655 if (actionBar != null) {
1656 // android.R.id.home will be triggered in onOptionsItemSelected()
Yorke Lee88bf3cc2013-09-10 18:45:12 -07001657 actionBar.setDisplayShowHomeEnabled(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 actionBar.setDisplayHomeAsUpEnabled(true);
Yorke Lee88bf3cc2013-09-10 18:45:12 -07001659 actionBar.setDisplayShowTitleEnabled(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 }
1661 }
1662
Andrew Leedb2fe562014-09-03 15:40:43 -07001663 private void initPhoneAccountPreferences() {
1664 mDefaultOutgoingAccount = (AccountSelectionPreference)
1665 findPreference(DEFAULT_OUTGOING_ACCOUNT_KEY);
1666 mSimCallManagerAccount = (AccountSelectionPreference)
1667 findPreference(WIFI_CALL_MANAGER_ACCOUNT_KEY);
1668
1669 TelecommManager telecommManager = TelecommManager.from(this);
1670
1671 List<PhoneAccountHandle> enabledPhoneAccounts = telecommManager.getEnabledPhoneAccounts();
1672 if (enabledPhoneAccounts.size() > 1) {
1673 mDefaultOutgoingAccount.setModel(
1674 telecommManager,
1675 enabledPhoneAccounts,
1676 telecommManager.getUserSelectedOutgoingPhoneAccount(),
1677 getString(R.string.phone_accounts_ask_every_time));
1678 mDefaultOutgoingAccount.setListener(this);
1679 } else {
1680 getPreferenceScreen().removePreference(mDefaultOutgoingAccount);
1681 }
1682
1683 List<PhoneAccountHandle> simCallManagers = telecommManager.getSimCallManagers();
1684 if (simCallManagers.size() > 1) {
1685 mSimCallManagerAccount.setModel(
1686 telecommManager,
1687 simCallManagers,
1688 telecommManager.getSimCallManager(),
1689 getString(R.string.wifi_calling_do_not_use));
1690 mSimCallManagerAccount.setListener(this);
1691 } else {
1692 getPreferenceScreen().removePreference(mSimCallManagerAccount);
1693 }
1694 }
1695
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001696 private void createSipCallSettings() {
1697 // Add Internet call settings.
Sailesh Nepal788959e2014-07-08 23:36:40 -07001698 if (SipUtil.isVoipSupported(this)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 mSipManager = SipManager.newInstance(this);
1700 mSipSharedPreferences = new SipSharedPreferences(this);
Sailesh Nepal788959e2014-07-08 23:36:40 -07001701 addPreferencesFromResource(
1702 com.android.services.telephony.sip.R.xml.sip_settings_category);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 mButtonSipCallOptions = getSipCallOptionPreference();
1704 mButtonSipCallOptions.setOnPreferenceChangeListener(this);
1705 mButtonSipCallOptions.setValueIndex(
1706 mButtonSipCallOptions.findIndexOfValue(
1707 mSipSharedPreferences.getSipCallOption()));
1708 mButtonSipCallOptions.setSummary(mButtonSipCallOptions.getEntry());
1709 }
1710 }
1711
Evan Charlton1c696832014-04-15 14:24:23 -07001712 private boolean canLaunchIntent(Intent intent) {
1713 PackageManager pm = getPackageManager();
1714 return pm.resolveActivity(intent, PackageManager.GET_ACTIVITIES) != null;
Ihab Awadca8ee7d2013-12-05 12:13:16 -08001715 }
1716
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717 // Gets the call options for SIP depending on whether SIP is allowed only
1718 // on Wi-Fi only; also make the other options preference invisible.
1719 private ListPreference getSipCallOptionPreference() {
1720 ListPreference wifiAnd3G = (ListPreference)
1721 findPreference(BUTTON_SIP_CALL_OPTIONS);
1722 ListPreference wifiOnly = (ListPreference)
1723 findPreference(BUTTON_SIP_CALL_OPTIONS_WIFI_ONLY);
Andrew Lee2170a972014-08-13 18:13:01 -07001724 PreferenceScreen sipSettings = (PreferenceScreen)
1725 getPreferenceScreen().findPreference(SIP_SETTINGS_PREFERENCE_SCREEN_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 if (SipManager.isSipWifiOnly(this)) {
1727 sipSettings.removePreference(wifiAnd3G);
1728 return wifiOnly;
1729 } else {
1730 sipSettings.removePreference(wifiOnly);
1731 return wifiAnd3G;
1732 }
1733 }
1734
1735 @Override
1736 protected void onResume() {
1737 super.onResume();
1738 mForeground = true;
1739
1740 if (isAirplaneModeOn()) {
Andrew Lee2170a972014-08-13 18:13:01 -07001741 Preference sipSettings = findPreference(SIP_SETTINGS_PREFERENCE_SCREEN_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 PreferenceScreen screen = getPreferenceScreen();
1743 int count = screen.getPreferenceCount();
1744 for (int i = 0 ; i < count ; ++i) {
1745 Preference pref = screen.getPreference(i);
1746 if (pref != sipSettings) pref.setEnabled(false);
1747 }
1748 return;
1749 }
1750
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 if (mButtonDTMF != null) {
1752 int dtmf = Settings.System.getInt(getContentResolver(),
1753 Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, Constants.DTMF_TONE_TYPE_NORMAL);
1754 mButtonDTMF.setValueIndex(dtmf);
1755 }
1756
1757 if (mButtonAutoRetry != null) {
1758 int autoretry = Settings.Global.getInt(getContentResolver(),
1759 Settings.Global.CALL_AUTO_RETRY, 0);
1760 mButtonAutoRetry.setChecked(autoretry != 0);
1761 }
1762
1763 if (mButtonHAC != null) {
1764 int hac = Settings.System.getInt(getContentResolver(), Settings.System.HEARING_AID, 0);
1765 mButtonHAC.setChecked(hac != 0);
1766 }
1767
1768 if (mButtonTTY != null) {
1769 int settingsTtyMode = Settings.Secure.getInt(getContentResolver(),
1770 Settings.Secure.PREFERRED_TTY_MODE,
Evan Charlton6abba882014-07-19 15:02:56 -07001771 TelecommManager.TTY_MODE_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 mButtonTTY.setValue(Integer.toString(settingsTtyMode));
1773 updatePreferredTtyModeSummary(settingsTtyMode);
1774 }
1775
1776 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(
1777 mPhone.getContext());
1778 if (migrateVoicemailVibrationSettingsIfNeeded(prefs)) {
1779 mVoicemailNotificationVibrate.setChecked(prefs.getBoolean(
1780 BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY, false));
1781 }
1782
Andrew Lee2170a972014-08-13 18:13:01 -07001783 // Look up the voicemail ringtone name asynchronously and update its preference.
1784 new Thread(mVoicemailRingtoneLookupRunnable).start();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
1786
1787 // Migrate settings from BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_WHEN_KEY to
1788 // BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY, if the latter does not exist.
1789 // Returns true if migration was performed.
1790 public static boolean migrateVoicemailVibrationSettingsIfNeeded(SharedPreferences prefs) {
1791 if (!prefs.contains(BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY)) {
1792 String vibrateWhen = prefs.getString(
1793 BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_WHEN_KEY, VOICEMAIL_VIBRATION_NEVER);
1794 // If vibrateWhen is always, then voicemailVibrate should be True.
1795 // otherwise if vibrateWhen is "only in silent mode", or "never", then
1796 // voicemailVibrate = False.
1797 boolean voicemailVibrate = vibrateWhen.equals(VOICEMAIL_VIBRATION_ALWAYS);
1798 final SharedPreferences.Editor editor = prefs.edit();
1799 editor.putBoolean(BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY, voicemailVibrate);
1800 editor.commit();
1801 return true;
1802 }
1803 return false;
1804 }
1805
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 private boolean isAirplaneModeOn() {
1807 return Settings.System.getInt(getContentResolver(),
1808 Settings.System.AIRPLANE_MODE_ON, 0) != 0;
1809 }
1810
1811 private void handleTTYChange(Preference preference, Object objValue) {
1812 int buttonTtyMode;
1813 buttonTtyMode = Integer.valueOf((String) objValue).intValue();
1814 int settingsTtyMode = android.provider.Settings.Secure.getInt(
1815 getContentResolver(),
Sailesh Nepalbf900542014-07-15 16:18:32 -07001816 android.provider.Settings.Secure.PREFERRED_TTY_MODE,
Evan Charlton6abba882014-07-19 15:02:56 -07001817 TelecommManager.TTY_MODE_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 if (DBG) log("handleTTYChange: requesting set TTY mode enable (TTY) to" +
1819 Integer.toString(buttonTtyMode));
1820
1821 if (buttonTtyMode != settingsTtyMode) {
1822 switch(buttonTtyMode) {
Evan Charlton15619762014-07-19 15:52:48 -07001823 case TelecommManager.TTY_MODE_OFF:
1824 case TelecommManager.TTY_MODE_FULL:
1825 case TelecommManager.TTY_MODE_HCO:
1826 case TelecommManager.TTY_MODE_VCO:
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 android.provider.Settings.Secure.putInt(getContentResolver(),
1828 android.provider.Settings.Secure.PREFERRED_TTY_MODE, buttonTtyMode);
1829 break;
1830 default:
Evan Charlton6abba882014-07-19 15:02:56 -07001831 buttonTtyMode = TelecommManager.TTY_MODE_OFF;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 }
1833
1834 mButtonTTY.setValue(Integer.toString(buttonTtyMode));
1835 updatePreferredTtyModeSummary(buttonTtyMode);
Evan Charlton6abba882014-07-19 15:02:56 -07001836 Intent ttyModeChanged = new Intent(TelecommManager.ACTION_TTY_PREFERRED_MODE_CHANGED);
1837 ttyModeChanged.putExtra(TelecommManager.EXTRA_TTY_PREFERRED_MODE, buttonTtyMode);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 sendBroadcastAsUser(ttyModeChanged, UserHandle.ALL);
1839 }
1840 }
1841
1842 private void handleSipCallOptionsChange(Object objValue) {
1843 String option = objValue.toString();
1844 mSipSharedPreferences.setSipCallOption(option);
1845 mButtonSipCallOptions.setValueIndex(
1846 mButtonSipCallOptions.findIndexOfValue(option));
1847 mButtonSipCallOptions.setSummary(mButtonSipCallOptions.getEntry());
1848 }
1849
Evan Charlton1c696832014-04-15 14:24:23 -07001850 private void handleWifiCallSettingsClick(Preference preference) {
1851 Intent intent = preference.getIntent();
1852 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
1853 // TODO - Restrict to a (the?) blessed Wi-Fi calling app.
1854
1855 Bundle noAnimations = ActivityOptions.makeCustomAnimation(this, 0, 0).toBundle();
1856 startActivity(intent, noAnimations);
Ihab Awadca8ee7d2013-12-05 12:13:16 -08001857 }
1858
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 private void updatePreferredTtyModeSummary(int TtyMode) {
1860 String [] txts = getResources().getStringArray(R.array.tty_mode_entries);
1861 switch(TtyMode) {
Evan Charlton15619762014-07-19 15:52:48 -07001862 case TelecommManager.TTY_MODE_OFF:
1863 case TelecommManager.TTY_MODE_HCO:
1864 case TelecommManager.TTY_MODE_VCO:
1865 case TelecommManager.TTY_MODE_FULL:
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001866 mButtonTTY.setSummary(txts[TtyMode]);
1867 break;
1868 default:
1869 mButtonTTY.setEnabled(false);
Evan Charlton6abba882014-07-19 15:02:56 -07001870 mButtonTTY.setSummary(txts[TelecommManager.TTY_MODE_OFF]);
Sailesh Nepalbf900542014-07-15 16:18:32 -07001871 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 }
1873 }
1874
1875 private static void log(String msg) {
1876 Log.d(LOG_TAG, msg);
1877 }
1878
1879 /**
1880 * Updates the look of the VM preference widgets based on current VM provider settings.
1881 * Note that the provider name is loaded form the found activity via loadLabel in
1882 * {@link #initVoiceMailProviders()} in order for it to be localizable.
1883 */
1884 private void updateVMPreferenceWidgets(String currentProviderSetting) {
1885 final String key = currentProviderSetting;
1886 final VoiceMailProvider provider = mVMProvidersData.get(key);
1887
1888 /* This is the case when we are coming up on a freshly wiped phone and there is no
1889 persisted value for the list preference mVoicemailProviders.
1890 In this case we want to show the UI asking the user to select a voicemail provider as
1891 opposed to silently falling back to default one. */
1892 if (provider == null) {
1893 if (DBG) {
1894 log("updateVMPreferenceWidget: provider for the key \"" + key + "\" is null.");
1895 }
1896 mVoicemailProviders.setSummary(getString(R.string.sum_voicemail_choose_provider));
1897 mVoicemailSettings.setEnabled(false);
1898 mVoicemailSettings.setIntent(null);
1899
1900 mVoicemailNotificationVibrate.setEnabled(false);
1901 } else {
1902 if (DBG) {
1903 log("updateVMPreferenceWidget: provider for the key \"" + key + "\".."
1904 + "name: " + provider.name
1905 + ", intent: " + provider.intent);
1906 }
1907 final String providerName = provider.name;
1908 mVoicemailProviders.setSummary(providerName);
1909 mVoicemailSettings.setEnabled(true);
1910 mVoicemailSettings.setIntent(provider.intent);
1911
1912 mVoicemailNotificationVibrate.setEnabled(true);
1913 }
1914 }
1915
1916 /**
1917 * Enumerates existing VM providers and puts their data into the list and populates
1918 * the preference list objects with their names.
1919 * In case we are called with ACTION_ADD_VOICEMAIL intent the intent may have
1920 * an extra string called IGNORE_PROVIDER_EXTRA with "package.activityName" of the provider
1921 * which should be hidden when we bring up the list of possible VM providers to choose.
1922 */
1923 private void initVoiceMailProviders() {
1924 if (DBG) log("initVoiceMailProviders()");
1925 mPerProviderSavedVMNumbers =
1926 this.getApplicationContext().getSharedPreferences(
1927 VM_NUMBERS_SHARED_PREFERENCES_NAME, MODE_PRIVATE);
1928
1929 String providerToIgnore = null;
1930 if (getIntent().getAction().equals(ACTION_ADD_VOICEMAIL)) {
1931 if (getIntent().hasExtra(IGNORE_PROVIDER_EXTRA)) {
1932 providerToIgnore = getIntent().getStringExtra(IGNORE_PROVIDER_EXTRA);
1933 }
1934 if (DBG) log("Found ACTION_ADD_VOICEMAIL. providerToIgnore=" + providerToIgnore);
1935 if (providerToIgnore != null) {
1936 // IGNORE_PROVIDER_EXTRA implies we want to remove the choice from the list.
1937 deleteSettingsForVoicemailProvider(providerToIgnore);
1938 }
1939 }
1940
1941 mVMProvidersData.clear();
1942
1943 // Stick the default element which is always there
1944 final String myCarrier = getString(R.string.voicemail_default);
1945 mVMProvidersData.put(DEFAULT_VM_PROVIDER_KEY, new VoiceMailProvider(myCarrier, null));
1946
1947 // Enumerate providers
1948 PackageManager pm = getPackageManager();
1949 Intent intent = new Intent();
1950 intent.setAction(ACTION_CONFIGURE_VOICEMAIL);
1951 List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
1952 int len = resolveInfos.size() + 1; // +1 for the default choice we will insert.
1953
1954 // Go through the list of discovered providers populating the data map
1955 // skip the provider we were instructed to ignore if there was one
1956 for (int i = 0; i < resolveInfos.size(); i++) {
1957 final ResolveInfo ri= resolveInfos.get(i);
1958 final ActivityInfo currentActivityInfo = ri.activityInfo;
1959 final String key = makeKeyForActivity(currentActivityInfo);
1960 if (key.equals(providerToIgnore)) {
1961 if (DBG) log("Ignoring key: " + key);
1962 len--;
1963 continue;
1964 }
1965 if (DBG) log("Loading key: " + key);
1966 final String nameForDisplay = ri.loadLabel(pm).toString();
1967 Intent providerIntent = new Intent();
1968 providerIntent.setAction(ACTION_CONFIGURE_VOICEMAIL);
1969 providerIntent.setClassName(currentActivityInfo.packageName,
1970 currentActivityInfo.name);
1971 if (DBG) {
1972 log("Store loaded VoiceMailProvider. key: " + key
1973 + " -> name: " + nameForDisplay + ", intent: " + providerIntent);
1974 }
1975 mVMProvidersData.put(
1976 key,
1977 new VoiceMailProvider(nameForDisplay, providerIntent));
1978
1979 }
1980
1981 // Now we know which providers to display - create entries and values array for
1982 // the list preference
1983 String [] entries = new String [len];
1984 String [] values = new String [len];
1985 entries[0] = myCarrier;
1986 values[0] = DEFAULT_VM_PROVIDER_KEY;
1987 int entryIdx = 1;
1988 for (int i = 0; i < resolveInfos.size(); i++) {
1989 final String key = makeKeyForActivity(resolveInfos.get(i).activityInfo);
1990 if (!mVMProvidersData.containsKey(key)) {
1991 continue;
1992 }
1993 entries[entryIdx] = mVMProvidersData.get(key).name;
1994 values[entryIdx] = key;
1995 entryIdx++;
1996 }
1997
1998 // ListPreference is now updated.
1999 mVoicemailProviders.setEntries(entries);
2000 mVoicemailProviders.setEntryValues(values);
2001
2002 // Remember the current Voicemail Provider key as a "previous" key. This will be used
2003 // when we fail to update Voicemail Provider, which requires rollback.
2004 // We will update this when the VM Provider setting is successfully updated.
2005 mPreviousVMProviderKey = getCurrentVoicemailProviderKey();
2006 if (DBG) log("Set up the first mPreviousVMProviderKey: " + mPreviousVMProviderKey);
2007
2008 // Finally update the preference texts.
2009 updateVMPreferenceWidgets(mPreviousVMProviderKey);
2010 }
2011
2012 private String makeKeyForActivity(ActivityInfo ai) {
2013 return ai.name;
2014 }
2015
2016 /**
2017 * Simulates user clicking on a passed preference.
2018 * Usually needed when the preference is a dialog preference and we want to invoke
2019 * a dialog for this preference programmatically.
Santos Cordonda120f42014-08-06 04:44:34 -07002020 * TODO: figure out if there is a cleaner way to cause preference dlg to come up
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021 */
2022 private void simulatePreferenceClick(Preference preference) {
2023 // Go through settings until we find our setting
2024 // and then simulate a click on it to bring up the dialog
2025 final ListAdapter adapter = getPreferenceScreen().getRootAdapter();
2026 for (int idx = 0; idx < adapter.getCount(); idx++) {
2027 if (adapter.getItem(idx) == preference) {
2028 getPreferenceScreen().onItemClick(this.getListView(),
2029 null, idx, adapter.getItemId(idx));
2030 break;
2031 }
2032 }
2033 }
2034
2035 /**
2036 * Saves new VM provider settings associating them with the currently selected
2037 * provider if settings are different than the ones already stored for this
2038 * provider.
2039 * Later on these will be used when the user switches a provider.
2040 */
2041 private void maybeSaveSettingsForVoicemailProvider(String key,
2042 VoiceMailProviderSettings newSettings) {
2043 if (mVoicemailProviders == null) {
2044 return;
2045 }
2046 final VoiceMailProviderSettings curSettings = loadSettingsForVoiceMailProvider(key);
2047 if (newSettings.equals(curSettings)) {
2048 if (DBG) {
2049 log("maybeSaveSettingsForVoicemailProvider:"
2050 + " Not saving setting for " + key + " since they have not changed");
2051 }
2052 return;
2053 }
2054 if (DBG) log("Saving settings for " + key + ": " + newSettings.toString());
2055 Editor editor = mPerProviderSavedVMNumbers.edit();
2056 editor.putString(key + VM_NUMBER_TAG, newSettings.voicemailNumber);
2057 String fwdKey = key + FWD_SETTINGS_TAG;
2058 CallForwardInfo[] s = newSettings.forwardingSettings;
2059 if (s != FWD_SETTINGS_DONT_TOUCH) {
2060 editor.putInt(fwdKey + FWD_SETTINGS_LENGTH_TAG, s.length);
2061 for (int i = 0; i < s.length; i++) {
2062 final String settingKey = fwdKey + FWD_SETTING_TAG + String.valueOf(i);
2063 final CallForwardInfo fi = s[i];
2064 editor.putInt(settingKey + FWD_SETTING_STATUS, fi.status);
2065 editor.putInt(settingKey + FWD_SETTING_REASON, fi.reason);
2066 editor.putString(settingKey + FWD_SETTING_NUMBER, fi.number);
2067 editor.putInt(settingKey + FWD_SETTING_TIME, fi.timeSeconds);
2068 }
2069 } else {
2070 editor.putInt(fwdKey + FWD_SETTINGS_LENGTH_TAG, 0);
2071 }
2072 editor.apply();
2073 }
2074
2075 /**
2076 * Returns settings previously stored for the currently selected
2077 * voice mail provider. If none is stored returns null.
2078 * If the user switches to a voice mail provider and we have settings
2079 * stored for it we will automatically change the phone's voice mail number
2080 * and forwarding number to the stored one. Otherwise we will bring up provider's configuration
2081 * UI.
2082 */
2083 private VoiceMailProviderSettings loadSettingsForVoiceMailProvider(String key) {
2084 final String vmNumberSetting = mPerProviderSavedVMNumbers.getString(key + VM_NUMBER_TAG,
2085 null);
2086 if (vmNumberSetting == null) {
2087 Log.w(LOG_TAG, "VoiceMailProvider settings for the key \"" + key + "\""
2088 + " was not found. Returning null.");
2089 return null;
2090 }
2091
2092 CallForwardInfo[] cfi = FWD_SETTINGS_DONT_TOUCH;
2093 String fwdKey = key + FWD_SETTINGS_TAG;
2094 final int fwdLen = mPerProviderSavedVMNumbers.getInt(fwdKey + FWD_SETTINGS_LENGTH_TAG, 0);
2095 if (fwdLen > 0) {
2096 cfi = new CallForwardInfo[fwdLen];
2097 for (int i = 0; i < cfi.length; i++) {
2098 final String settingKey = fwdKey + FWD_SETTING_TAG + String.valueOf(i);
2099 cfi[i] = new CallForwardInfo();
2100 cfi[i].status = mPerProviderSavedVMNumbers.getInt(
2101 settingKey + FWD_SETTING_STATUS, 0);
2102 cfi[i].reason = mPerProviderSavedVMNumbers.getInt(
2103 settingKey + FWD_SETTING_REASON,
2104 CommandsInterface.CF_REASON_ALL_CONDITIONAL);
2105 cfi[i].serviceClass = CommandsInterface.SERVICE_CLASS_VOICE;
2106 cfi[i].toa = PhoneNumberUtils.TOA_International;
2107 cfi[i].number = mPerProviderSavedVMNumbers.getString(
2108 settingKey + FWD_SETTING_NUMBER, "");
2109 cfi[i].timeSeconds = mPerProviderSavedVMNumbers.getInt(
2110 settingKey + FWD_SETTING_TIME, 20);
2111 }
2112 }
2113
2114 VoiceMailProviderSettings settings = new VoiceMailProviderSettings(vmNumberSetting, cfi);
2115 if (DBG) log("Loaded settings for " + key + ": " + settings.toString());
2116 return settings;
2117 }
2118
2119 /**
2120 * Deletes settings for the specified provider.
2121 */
2122 private void deleteSettingsForVoicemailProvider(String key) {
2123 if (DBG) log("Deleting settings for" + key);
2124 if (mVoicemailProviders == null) {
2125 return;
2126 }
2127 mPerProviderSavedVMNumbers.edit()
2128 .putString(key + VM_NUMBER_TAG, null)
2129 .putInt(key + FWD_SETTINGS_TAG + FWD_SETTINGS_LENGTH_TAG, 0)
2130 .commit();
2131 }
2132
2133 private String getCurrentVoicemailProviderKey() {
2134 final String key = mVoicemailProviders.getValue();
2135 return (key != null) ? key : DEFAULT_VM_PROVIDER_KEY;
2136 }
2137
2138 @Override
2139 public boolean onOptionsItemSelected(MenuItem item) {
2140 final int itemId = item.getItemId();
2141 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -07002142 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 return true;
2144 }
2145 return super.onOptionsItemSelected(item);
2146 }
2147
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002148 /**
2149 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
2150 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
2151 */
2152 public static void goUpToTopLevelSetting(Activity activity) {
2153 Intent intent = new Intent(activity, CallFeaturesSetting.class);
2154 intent.setAction(Intent.ACTION_MAIN);
2155 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
2156 activity.startActivity(intent);
2157 activity.finish();
2158 }
2159}