blob: d6bb03075aeff507bb665bf27c321ac8d7b6b520 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.content.ContentResolver;
25import android.content.Context;
26import android.content.DialogInterface;
27import android.content.Intent;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.database.Cursor;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.os.AsyncResult;
30import android.os.Bundle;
31import android.os.Handler;
32import android.os.Message;
33import android.os.UserHandle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.preference.CheckBoxPreference;
35import android.preference.ListPreference;
36import android.preference.Preference;
37import android.preference.PreferenceActivity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.preference.PreferenceScreen;
39import android.provider.ContactsContract.CommonDataKinds;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.provider.Settings;
Tyler Gunn4d45d1c2014-09-12 22:17:53 -070041import android.telecom.PhoneAccountHandle;
42import android.telecom.TelecomManager;
Andrew Lee93c345f2014-10-27 15:25:07 -070043import android.telephony.TelephonyManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.text.TextUtils;
45import android.util.Log;
46import android.view.MenuItem;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.widget.ListAdapter;
Jay Shraunerc2684732014-11-12 12:10:37 -080048import android.widget.Toast;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049
Andrew Lee312e8172014-10-23 17:01:36 -070050import com.android.ims.ImsManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import com.android.internal.telephony.CallForwardInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import com.android.internal.telephony.Phone;
53import com.android.internal.telephony.PhoneConstants;
Andrew Lee2170a972014-08-13 18:13:01 -070054import com.android.phone.common.util.SettingsUtil;
Andrew Leedb2fe562014-09-03 15:40:43 -070055import com.android.phone.settings.AccountSelectionPreference;
Andrew Lee1af6cf72014-11-04 17:35:26 -080056import com.android.phone.settings.CallForwardInfoUtil;
Andrew Leefb7f92e2015-02-26 16:23:32 -080057import com.android.phone.settings.SettingsConstants;
Andrew Lee84024342014-11-06 23:37:09 -080058import com.android.phone.settings.VoicemailDialogUtil;
Andrew Lee1ec7c7e2014-12-03 15:33:21 -080059import com.android.phone.settings.VoicemailNotificationSettingsUtil;
Andrew Lee64e5c9d2014-11-26 12:00:10 -080060import com.android.phone.settings.VoicemailProviderListPreference;
61import com.android.phone.settings.VoicemailProviderListPreference.VoicemailProvider;
Andrew Leeb490d732014-10-27 15:00:41 -070062import com.android.phone.settings.VoicemailProviderSettings;
Andrew Lee88b51e22014-10-29 15:48:51 -070063import com.android.phone.settings.VoicemailProviderSettingsUtil;
Andrew Lee1ec7c7e2014-12-03 15:33:21 -080064import com.android.phone.settings.VoicemailRingtonePreference;
Andrew Lee5ed870c2014-10-29 11:47:49 -070065import com.android.phone.settings.fdn.FdnSetting;
Sailesh Nepal788959e2014-07-08 23:36:40 -070066import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067
Andrew Lee2170a972014-08-13 18:13:01 -070068import java.lang.String;
Andrew Leef1776d82014-11-04 14:45:02 -080069import java.util.ArrayList;
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 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070080 * This preference screen is the root of the "Call settings" hierarchy available from the Phone
81 * app; the settings here let you control various features related to phone calls (including
82 * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
83 * voice-capable phone devices.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084 *
85 * Note that this activity is part of the package com.android.phone, even
86 * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
87 * is from the package com.android.contacts.
88 *
89 * For the "Mobile network settings" screen under the main Settings app,
90 * See {@link MobileNetworkSettings}.
91 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070092 * TODO: Settings should be split into PreferenceFragments where possible (ie. voicemail).
Andrew Lee2170a972014-08-13 18:13:01 -070093 *
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094 * @see com.android.phone.MobileNetworkSettings
95 */
96public class CallFeaturesSetting extends PreferenceActivity
97 implements DialogInterface.OnClickListener,
Andrew Lee2170a972014-08-13 18:13:01 -070098 Preference.OnPreferenceChangeListener,
Andrew Lee2170a972014-08-13 18:13:01 -070099 EditPhoneNumberPreference.OnDialogClosedListener,
Andrew Leece8ae2a2014-09-10 10:41:48 -0700100 EditPhoneNumberPreference.GetDefaultNumberListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700101 private static final String LOG_TAG = "CallFeaturesSetting";
102 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
Andrew Lee77527ac2014-10-21 16:57:39 -0700103 // STOPSHIP if true. Flag to override behavior default behavior to hide VT setting.
104 private static final boolean ENABLE_VT_FLAG = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105
106 /**
107 * Intent action to bring up Voicemail Provider settings.
108 *
109 * @see #IGNORE_PROVIDER_EXTRA
110 */
111 public static final String ACTION_ADD_VOICEMAIL =
112 "com.android.phone.CallFeaturesSetting.ADD_VOICEMAIL";
113 // intent action sent by this activity to a voice mail provider
114 // to trigger its configuration UI
115 public static final String ACTION_CONFIGURE_VOICEMAIL =
116 "com.android.phone.CallFeaturesSetting.CONFIGURE_VOICEMAIL";
117 // Extra put in the return from VM provider config containing voicemail number to set
118 public static final String VM_NUMBER_EXTRA = "com.android.phone.VoicemailNumber";
119 // Extra put in the return from VM provider config containing call forwarding number to set
120 public static final String FWD_NUMBER_EXTRA = "com.android.phone.ForwardingNumber";
121 // Extra put in the return from VM provider config containing call forwarding number to set
122 public static final String FWD_NUMBER_TIME_EXTRA = "com.android.phone.ForwardingNumberTime";
123 // If the VM provider returns non null value in this extra we will force the user to
124 // choose another VM provider
125 public static final String SIGNOUT_EXTRA = "com.android.phone.Signout";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127 /**
128 * String Extra put into ACTION_ADD_VOICEMAIL call to indicate which provider should be hidden
129 * in the list of providers presented to the user. This allows a provider which is being
130 * disabled (e.g. GV user logging out) to force the user to pick some other provider.
131 */
132 public static final String IGNORE_PROVIDER_EXTRA = "com.android.phone.ProviderToIgnore";
133
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800134 /**
135 * String Extra put into ACTION_ADD_VOICEMAIL to indicate that the voicemail setup screen should
136 * be opened.
137 */
138 public static final String SETUP_VOICEMAIL_EXTRA = "com.android.phone.SetupVoicemail";
139
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140 // string constants
141 private static final String NUM_PROJECTION[] = {CommonDataKinds.Phone.NUMBER};
142
143 // String keys for preference lookup
144 // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
Andrew Lee8d66d812014-11-24 14:54:02 -0800145 // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
146 // in the layout files. These strings need to be treated carefully; if the setting is
147 // persistent, they are used as the key to store shared preferences and the name should not be
148 // changed unless the settings are also migrated.
Andrew Lee97708a42014-09-25 12:39:07 -0700149 private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150 private static final String BUTTON_VOICEMAIL_KEY = "button_voicemail_key";
151 private static final String BUTTON_VOICEMAIL_PROVIDER_KEY = "button_voicemail_provider_key";
152 private static final String BUTTON_VOICEMAIL_SETTING_KEY = "button_voicemail_setting_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153 private static final String BUTTON_FDN_KEY = "button_fdn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155 private static final String BUTTON_RETRY_KEY = "button_auto_retry_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156
157 private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
158 private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
Andrew Lee2b36ba22014-11-05 17:08:49 -0800159 private static final String CALL_FORWARDING_KEY = "call_forwarding_key";
160 private static final String ADDITIONAL_GSM_SETTINGS_KEY = "additional_gsm_call_settings_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161
Andrew Leece8ae2a2014-09-10 10:41:48 -0700162 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
163 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -0700164
Andrew Leedf14ead2014-10-17 14:22:52 -0700165 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
166
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167 /** Event for Async voicemail change call */
168 private static final int EVENT_VOICEMAIL_CHANGED = 500;
169 private static final int EVENT_FORWARDING_CHANGED = 501;
170 private static final int EVENT_FORWARDING_GET_COMPLETED = 502;
171
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172 /** Handle to voicemail pref */
173 private static final int VOICEMAIL_PREF_ID = 1;
174 private static final int VOICEMAIL_PROVIDER_CFG_ID = 2;
175
176 private Phone mPhone;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177
Andrew Lee5ed870c2014-10-29 11:47:49 -0700178 private SubscriptionInfoHelper mSubscriptionInfoHelper;
179
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180 private EditPhoneNumberPreference mSubMenuVoicemailSettings;
181
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182 private CheckBoxPreference mButtonAutoRetry;
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800183 private VoicemailProviderListPreference mVoicemailProviders;
Andrew Lee97708a42014-09-25 12:39:07 -0700184 private PreferenceScreen mVoicemailSettingsScreen;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185 private PreferenceScreen mVoicemailSettings;
Andrew Lee1ec7c7e2014-12-03 15:33:21 -0800186 private VoicemailRingtonePreference mVoicemailNotificationRingtone;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187 private CheckBoxPreference mVoicemailNotificationVibrate;
Andrew Leedf14ead2014-10-17 14:22:52 -0700188 private CheckBoxPreference mEnableVideoCalling;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190 /**
191 * Results of reading forwarding settings
192 */
193 private CallForwardInfo[] mForwardingReadResults = null;
194
195 /**
196 * Result of forwarding number change.
197 * Keys are reasons (eg. unconditional forwarding).
198 */
199 private Map<Integer, AsyncResult> mForwardingChangeResults = null;
200
201 /**
202 * Expected CF read result types.
203 * This set keeps track of the CF types for which we've issued change
204 * commands so we can tell when we've received all of the responses.
205 */
206 private Collection<Integer> mExpectedChangeResultReasons = null;
207
208 /**
209 * Result of vm number change
210 */
211 private AsyncResult mVoicemailChangeResult = null;
212
213 /**
214 * Previous VM provider setting so we can return to it in case of failure.
215 */
216 private String mPreviousVMProviderKey = null;
217
218 /**
219 * Id of the dialog being currently shown.
220 */
221 private int mCurrentDialogId = 0;
222
223 /**
224 * Flag indicating that we are invoking settings for the voicemail provider programmatically
225 * due to vm provider change.
226 */
227 private boolean mVMProviderSettingsForced = false;
228
229 /**
230 * Flag indicating that we are making changes to vm or fwd numbers
231 * due to vm provider change.
232 */
233 private boolean mChangingVMorFwdDueToProviderChange = false;
234
235 /**
236 * True if we are in the process of vm & fwd number change and vm has already been changed.
237 * This is used to decide what to do in case of rollback.
238 */
239 private boolean mVMChangeCompletedSuccessfully = false;
240
241 /**
242 * True if we had full or partial failure setting forwarding numbers and so need to roll them
243 * back.
244 */
245 private boolean mFwdChangesRequireRollback = false;
246
247 /**
248 * Id of error msg to display to user once we are done reverting the VM provider to the previous
249 * one.
250 */
251 private int mVMOrFwdSetError = 0;
252
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253 /** string to hold old voicemail number as it is being updated. */
254 private String mOldVmNumber;
255
256 // New call forwarding settings and vm number we will be setting
257 // Need to save these since before we get to saving we need to asynchronously
258 // query the existing forwarding settings.
259 private CallForwardInfo[] mNewFwdSettings;
260 private String mNewVMNumber;
261
262 private boolean mForeground;
263
264 @Override
265 public void onPause() {
266 super.onPause();
267 mForeground = false;
268 }
269
270 /**
271 * We have to pull current settings from the network for all kinds of
272 * voicemail providers so we can tell whether we have to update them,
273 * so use this bit to keep track of whether we're reading settings for the
274 * default provider and should therefore save them out when done.
275 */
276 private boolean mReadingSettingsForDefaultProvider = false;
277
Tyler Gunnbaee2952014-09-10 16:01:02 -0700278 /**
279 * Used to indicate that the voicemail preference should be shown.
280 */
281 private boolean mShowVoicemailPreference = false;
282
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800283 /**
284 * Used to indicate that the voicemail setup screen should be shown.
285 */
286 private boolean mSetupVoicemail = false;
287
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288 /*
289 * Click Listeners, handle click based on objects attached to UI.
290 */
291
292 // Click listener for all toggle events
293 @Override
294 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
295 if (preference == mSubMenuVoicemailSettings) {
296 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297 } else if (preference == mButtonAutoRetry) {
298 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
299 android.provider.Settings.Global.CALL_AUTO_RETRY,
300 mButtonAutoRetry.isChecked() ? 1 : 0);
301 return true;
Andrew Lee696bff52014-12-03 17:58:18 -0800302 } else if (preference.getKey().equals(mVoicemailSettings.getKey())) {
303 // Check key instead of comparing reference because closing the voicemail notification
304 // ringtone dialog invokes onResume(), but leaves the old preference screen up,
305 // TODO: Revert to checking reference after migrating voicemail to its own activity.
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800306 if (DBG) log("onPreferenceTreeClick: Voicemail Settings Preference is clicked.");
307
Andrew Lee696bff52014-12-03 17:58:18 -0800308 final Dialog dialog = ((PreferenceScreen) preference).getDialog();
Yorke Leea0f63bf2014-10-09 18:27:20 -0700309 if (dialog != null) {
310 dialog.getActionBar().setDisplayHomeAsUpEnabled(false);
311 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800312
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700313 if (preference.getIntent() != null) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800314 if (DBG) log("Invoking cfg intent " + preference.getIntent().getPackage());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315
316 // onActivityResult() will be responsible for resetting some of variables.
317 this.startActivityForResult(preference.getIntent(), VOICEMAIL_PROVIDER_CFG_ID);
318 return true;
319 } else {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800320 if (DBG) log("onPreferenceTreeClick(). No intent; use default behavior in xml.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700321
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800322 // onActivityResult() will not be called, so reset variables here.
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800323 mPreviousVMProviderKey = VoicemailProviderListPreference.DEFAULT_KEY;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324 mVMProviderSettingsForced = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325 return false;
326 }
Andrew Lee97708a42014-09-25 12:39:07 -0700327 } else if (preference == mVoicemailSettingsScreen) {
Yorke Leea0f63bf2014-10-09 18:27:20 -0700328 final Dialog dialog = mVoicemailSettingsScreen.getDialog();
329 if (dialog != null) {
330 dialog.getActionBar().setDisplayHomeAsUpEnabled(false);
331 }
Andrew Lee97708a42014-09-25 12:39:07 -0700332 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 }
334 return false;
335 }
336
337 /**
338 * Implemented to support onPreferenceChangeListener to look for preference
339 * changes.
340 *
341 * @param preference is the preference to be changed
342 * @param objValue should be the value of the selection, NOT its localized
343 * display value.
344 */
345 @Override
346 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800347 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700348
Andrew Leea1239f22015-03-02 17:44:07 -0800349 if (preference == mVoicemailProviders) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 final String newProviderKey = (String) objValue;
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800351
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352 // If previous provider key and the new one is same, we don't need to handle it.
353 if (mPreviousVMProviderKey.equals(newProviderKey)) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800354 if (DBG) log("No change is made to the VM provider setting.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 return true;
356 }
357 updateVMPreferenceWidgets(newProviderKey);
358
Andrew Leeb490d732014-10-27 15:00:41 -0700359 final VoicemailProviderSettings newProviderSettings =
Andrew Lee6950c6c2014-11-26 12:05:42 -0800360 VoicemailProviderSettingsUtil.load(this, newProviderKey);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361
Andrew Lee88b51e22014-10-29 15:48:51 -0700362 // If the user switches to a voice mail provider and we have numbers stored for it we
363 // will automatically change the phone's voice mail and forwarding number to the stored
364 // ones. Otherwise we will bring up provider's configuration UI.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 if (newProviderSettings == null) {
366 // Force the user into a configuration of the chosen provider
367 Log.w(LOG_TAG, "Saved preferences not found - invoking config");
368 mVMProviderSettingsForced = true;
369 simulatePreferenceClick(mVoicemailSettings);
370 } else {
371 if (DBG) log("Saved preferences found - switching to them");
372 // Set this flag so if we get a failure we revert to previous provider
373 mChangingVMorFwdDueToProviderChange = true;
374 saveVoiceMailAndForwardingNumber(newProviderKey, newProviderSettings);
375 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800376 } else if (preference.getKey().equals(mVoicemailNotificationVibrate.getKey())) {
Andrew Lee696bff52014-12-03 17:58:18 -0800377 // Check key instead of comparing reference because closing the voicemail notification
378 // ringtone dialog invokes onResume(), but leaves the old preference screen up,
379 // TODO: Revert to checking reference after migrating voicemail to its own activity.
Andrew Lee8d66d812014-11-24 14:54:02 -0800380 VoicemailNotificationSettingsUtil.setVibrationEnabled(
Andrew Lee1ec7c7e2014-12-03 15:33:21 -0800381 mPhone, Boolean.TRUE.equals(objValue));
Andrew Leedf14ead2014-10-17 14:22:52 -0700382 } else if (preference == mEnableVideoCalling) {
Andrew Lee312e8172014-10-23 17:01:36 -0700383 if (ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())) {
384 PhoneGlobals.getInstance().phoneMgr.enableVideoCalling((boolean) objValue);
385 } else {
386 AlertDialog.Builder builder = new AlertDialog.Builder(this);
387 DialogInterface.OnClickListener networkSettingsClickListener =
388 new Dialog.OnClickListener() {
389 @Override
390 public void onClick(DialogInterface dialog, int which) {
391 startActivity(new Intent(mPhone.getContext(),
392 com.android.phone.MobileNetworkSettings.class));
393 }
394 };
395 builder.setMessage(getResources().getString(
396 R.string.enable_video_calling_dialog_msg))
397 .setNeutralButton(getResources().getString(
398 R.string.enable_video_calling_dialog_settings),
399 networkSettingsClickListener)
400 .setPositiveButton(android.R.string.ok, null)
401 .show();
402 return false;
403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800405
406 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 return true;
408 }
409
410 @Override
411 public void onDialogClosed(EditPhoneNumberPreference preference, int buttonClicked) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800412 if (DBG) log("onDialogClosed: Button clicked is " + buttonClicked);
413
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 if (buttonClicked == DialogInterface.BUTTON_NEGATIVE) {
415 return;
416 }
417
418 if (preference == mSubMenuVoicemailSettings) {
Andrew Leee438b312014-10-29 16:59:15 -0700419 VoicemailProviderSettings newSettings = new VoicemailProviderSettings(
420 mSubMenuVoicemailSettings.getPhoneNumber(),
421 VoicemailProviderSettings.NO_FORWARDING);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800422 saveVoiceMailAndForwardingNumber(mVoicemailProviders.getKey(), newSettings);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 }
424 }
425
426 /**
427 * Implemented for EditPhoneNumberPreference.GetDefaultNumberListener.
428 * This method set the default values for the various
429 * EditPhoneNumberPreference dialogs.
430 */
431 @Override
432 public String onGetDefaultNumber(EditPhoneNumberPreference preference) {
433 if (preference == mSubMenuVoicemailSettings) {
434 // update the voicemail number field, which takes care of the
435 // mSubMenuVoicemailSettings itself, so we should return null.
436 if (DBG) log("updating default for voicemail dialog");
437 updateVoiceNumberField();
438 return null;
439 }
440
441 String vmDisplay = mPhone.getVoiceMailNumber();
442 if (TextUtils.isEmpty(vmDisplay)) {
443 // if there is no voicemail number, we just return null to
444 // indicate no contribution.
445 return null;
446 }
447
448 // Return the voicemail number prepended with "VM: "
449 if (DBG) log("updating default for call forwarding dialogs");
450 return getString(R.string.voicemail_abbreviated) + " " + vmDisplay;
451 }
452
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700453 private void switchToPreviousVoicemailProvider() {
454 if (DBG) log("switchToPreviousVoicemailProvider " + mPreviousVMProviderKey);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800456 if (mPreviousVMProviderKey == null) {
457 return;
458 }
459
460 if (mVMChangeCompletedSuccessfully || mFwdChangesRequireRollback) {
Andrew Lee84024342014-11-06 23:37:09 -0800461 showDialogIfForeground(VoicemailDialogUtil.VM_REVERTING_DIALOG);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800462 final VoicemailProviderSettings prevSettings =
Andrew Lee6950c6c2014-11-26 12:05:42 -0800463 VoicemailProviderSettingsUtil.load(this, mPreviousVMProviderKey);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800464 if (prevSettings == null) {
465 Log.e(LOG_TAG, "VoicemailProviderSettings for the key \""
466 + mPreviousVMProviderKey + "\" is null but should be loaded.");
467 }
468
469 if (mVMChangeCompletedSuccessfully) {
470 mNewVMNumber = prevSettings.getVoicemailNumber();
471 Log.i(LOG_TAG, "VM change is already completed successfully."
472 + "Have to revert VM back to " + mNewVMNumber + " again.");
473 mPhone.setVoiceMailNumber(
474 mPhone.getVoiceMailAlphaTag().toString(),
475 mNewVMNumber,
476 Message.obtain(mRevertOptionComplete, EVENT_VOICEMAIL_CHANGED));
477 }
478
479 if (mFwdChangesRequireRollback) {
480 Log.i(LOG_TAG, "Requested to rollback forwarding changes.");
481
482 final CallForwardInfo[] prevFwdSettings = prevSettings.getForwardingSettings();
483 if (prevFwdSettings != null) {
484 Map<Integer, AsyncResult> results = mForwardingChangeResults;
485 resetForwardingChangeState();
486 for (int i = 0; i < prevFwdSettings.length; i++) {
487 CallForwardInfo fi = prevFwdSettings[i];
488 if (DBG) log("Reverting fwd #: " + i + ": " + fi.toString());
489 // Only revert the settings for which the update succeeded.
490 AsyncResult result = results.get(fi.reason);
491 if (result != null && result.exception == null) {
492 mExpectedChangeResultReasons.add(fi.reason);
493 CallForwardInfoUtil.setCallForwardingOption(mPhone, fi,
494 mRevertOptionComplete.obtainMessage(
495 EVENT_FORWARDING_CHANGED, i, 0));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700496 }
497 }
498 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700499 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800500 } else {
501 if (DBG) log("No need to revert");
502 onRevertDone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700503 }
504 }
505
506 private void onRevertDone() {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800507 if (DBG) log("onRevertDone: Changing provider key back to " + mPreviousVMProviderKey);
508
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 updateVMPreferenceWidgets(mPreviousVMProviderKey);
510 updateVoiceNumberField();
511 if (mVMOrFwdSetError != 0) {
Andrew Leeab082272014-11-04 15:50:42 -0800512 showDialogIfForeground(mVMOrFwdSetError);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700513 mVMOrFwdSetError = 0;
514 }
515 }
516
517 @Override
518 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
519 if (DBG) {
520 log("onActivityResult: requestCode: " + requestCode
521 + ", resultCode: " + resultCode
522 + ", data: " + data);
523 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800524
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 // there are cases where the contact picker may end up sending us more than one
526 // request. We want to ignore the request if we're not in the correct state.
527 if (requestCode == VOICEMAIL_PROVIDER_CFG_ID) {
528 boolean failure = false;
529
530 // No matter how the processing of result goes lets clear the flag
531 if (DBG) log("mVMProviderSettingsForced: " + mVMProviderSettingsForced);
532 final boolean isVMProviderSettingsForced = mVMProviderSettingsForced;
533 mVMProviderSettingsForced = false;
534
535 String vmNum = null;
536 if (resultCode != RESULT_OK) {
537 if (DBG) log("onActivityResult: vm provider cfg result not OK.");
538 failure = true;
539 } else {
540 if (data == null) {
541 if (DBG) log("onActivityResult: vm provider cfg result has no data");
542 failure = true;
543 } else {
544 if (data.getBooleanExtra(SIGNOUT_EXTRA, false)) {
545 if (DBG) log("Provider requested signout");
546 if (isVMProviderSettingsForced) {
547 if (DBG) log("Going back to previous provider on signout");
548 switchToPreviousVoicemailProvider();
549 } else {
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800550 final String victim = mVoicemailProviders.getKey();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551 if (DBG) log("Relaunching activity and ignoring " + victim);
552 Intent i = new Intent(ACTION_ADD_VOICEMAIL);
553 i.putExtra(IGNORE_PROVIDER_EXTRA, victim);
554 i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
555 this.startActivity(i);
556 }
557 return;
558 }
559 vmNum = data.getStringExtra(VM_NUMBER_EXTRA);
560 if (vmNum == null || vmNum.length() == 0) {
561 if (DBG) log("onActivityResult: vm provider cfg result has no vmnum");
562 failure = true;
563 }
564 }
565 }
566 if (failure) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800567 if (DBG) log("Failure in return from voicemail provider.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700568 if (isVMProviderSettingsForced) {
569 switchToPreviousVoicemailProvider();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700570 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800571
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700572 return;
573 }
574 mChangingVMorFwdDueToProviderChange = isVMProviderSettingsForced;
575 final String fwdNum = data.getStringExtra(FWD_NUMBER_EXTRA);
576
Santos Cordonda120f42014-08-06 04:44:34 -0700577 // TODO: It would be nice to load the current network setting for this and
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700578 // send it to the provider when it's config is invoked so it can use this as default
579 final int fwdNumTime = data.getIntExtra(FWD_NUMBER_TIME_EXTRA, 20);
580
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800581 if (DBG) log("onActivityResult: cfg result has forwarding number " + fwdNum);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800582 saveVoiceMailAndForwardingNumber(mVoicemailProviders.getKey(),
Andrew Leeb490d732014-10-27 15:00:41 -0700583 new VoicemailProviderSettings(vmNum, fwdNum, fwdNumTime));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700584 return;
585 }
586
587 if (requestCode == VOICEMAIL_PREF_ID) {
588 if (resultCode != RESULT_OK) {
589 if (DBG) log("onActivityResult: contact picker result not OK.");
590 return;
591 }
592
593 Cursor cursor = null;
594 try {
595 cursor = getContentResolver().query(data.getData(),
596 NUM_PROJECTION, null, null, null);
597 if ((cursor == null) || (!cursor.moveToFirst())) {
598 if (DBG) log("onActivityResult: bad contact data, no results found.");
599 return;
600 }
601 mSubMenuVoicemailSettings.onPickActivityResult(cursor.getString(0));
602 return;
603 } finally {
604 if (cursor != null) {
605 cursor.close();
606 }
607 }
608 }
609
610 super.onActivityResult(requestCode, resultCode, data);
611 }
612
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700613 /**
614 * Wrapper around showDialog() that will silently do nothing if we're
615 * not in the foreground.
616 *
617 * This is useful here because most of the dialogs we display from
618 * this class are triggered by asynchronous events (like
619 * success/failure messages from the telephony layer) and it's
620 * possible for those events to come in even after the user has gone
621 * to a different screen.
622 */
623 // TODO: this is too brittle: it's still easy to accidentally add new
624 // code here that calls showDialog() directly (which will result in a
625 // WindowManager$BadTokenException if called after the activity has
626 // been stopped.)
627 //
628 // It would be cleaner to do the "if (mForeground)" check in one
629 // central place, maybe by using a single Handler for all asynchronous
630 // events (and have *that* discard events if we're not in the
631 // foreground.)
632 //
633 // Unfortunately it's not that simple, since we sometimes need to do
634 // actual work to handle these events whether or not we're in the
635 // foreground (see the Handler code in mSetOptionComplete for
636 // example.)
Andrew Leeab082272014-11-04 15:50:42 -0800637 //
638 // TODO: It's a bit worrisome that we don't do anything in error cases when we're not in the
639 // foreground. Consider displaying a toast instead.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700640 private void showDialogIfForeground(int id) {
641 if (mForeground) {
642 showDialog(id);
643 }
644 }
645
646 private void dismissDialogSafely(int id) {
647 try {
648 dismissDialog(id);
649 } catch (IllegalArgumentException e) {
650 // This is expected in the case where we were in the background
651 // at the time we would normally have shown the dialog, so we didn't
652 // show it.
653 }
654 }
655
Andrew Lee299e4a72015-01-15 12:44:34 -0800656 /**
657 * TODO: Refactor to make it easier to understand what's done in the different stages.
658 */
Andrew Leeb490d732014-10-27 15:00:41 -0700659 private void saveVoiceMailAndForwardingNumber(
660 String key, VoicemailProviderSettings newSettings) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700661 if (DBG) log("saveVoiceMailAndForwardingNumber: " + newSettings.toString());
Andrew Leeb490d732014-10-27 15:00:41 -0700662 mNewVMNumber = newSettings.getVoicemailNumber();
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800663 mNewVMNumber = (mNewVMNumber == null) ? "" : mNewVMNumber;
Andrew Leeb490d732014-10-27 15:00:41 -0700664 mNewFwdSettings = newSettings.getForwardingSettings();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700665
Andrew Lee299e4a72015-01-15 12:44:34 -0800666 // No fwd settings on CDMA.
667 boolean isCdma = mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA;
668 if (isCdma) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700669 if (DBG) log("ignoring forwarding setting since this is CDMA phone");
Andrew Leeb490d732014-10-27 15:00:41 -0700670 mNewFwdSettings = VoicemailProviderSettings.NO_FORWARDING;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700671 }
672
Andrew Leee3c15212014-10-28 13:12:55 -0700673 // Throw a warning if the voicemail is the same and we did not change forwarding.
Andrew Leeb490d732014-10-27 15:00:41 -0700674 if (mNewVMNumber.equals(mOldVmNumber)
675 && mNewFwdSettings == VoicemailProviderSettings.NO_FORWARDING) {
Andrew Lee84024342014-11-06 23:37:09 -0800676 showDialogIfForeground(VoicemailDialogUtil.VM_NOCHANGE_ERROR_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700677 return;
678 }
679
Andrew Lee6950c6c2014-11-26 12:05:42 -0800680 VoicemailProviderSettingsUtil.save(this, key, newSettings);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700681 mVMChangeCompletedSuccessfully = false;
682 mFwdChangesRequireRollback = false;
683 mVMOrFwdSetError = 0;
Andrew Lee299e4a72015-01-15 12:44:34 -0800684
685 // Don't read call forwarding settings if CDMA. Call forwarding is not supported by CDMA.
Andrew Lee9c822312015-03-13 07:52:08 -0700686 if (isCdma || mNewFwdSettings == VoicemailProviderSettings.NO_FORWARDING) {
687 if (DBG) log("Not touching fwd #");
688 setVoicemailNumberWithCarrier();
689 } else {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700690 mReadingSettingsForDefaultProvider =
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800691 mPreviousVMProviderKey.equals(VoicemailProviderListPreference.DEFAULT_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700692 if (DBG) log("Reading current forwarding settings");
Andrew Leeb490d732014-10-27 15:00:41 -0700693 int numSettingsReasons = VoicemailProviderSettings.FORWARDING_SETTINGS_REASONS.length;
694 mForwardingReadResults = new CallForwardInfo[numSettingsReasons];
695 for (int i = 0; i < mForwardingReadResults.length; i++) {
696 mPhone.getCallForwardingOption(
697 VoicemailProviderSettings.FORWARDING_SETTINGS_REASONS[i],
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700698 mGetOptionComplete.obtainMessage(EVENT_FORWARDING_GET_COMPLETED, i, 0));
699 }
Andrew Lee84024342014-11-06 23:37:09 -0800700 showDialogIfForeground(VoicemailDialogUtil.VM_FWD_READING_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700701 }
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800702
703 // Refresh the MWI indicator if it is already showing.
704 PhoneGlobals.getInstance().refreshMwiIndicator(mSubscriptionInfoHelper.getSubId());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700705 }
706
707 private final Handler mGetOptionComplete = new Handler() {
708 @Override
709 public void handleMessage(Message msg) {
710 AsyncResult result = (AsyncResult) msg.obj;
711 switch (msg.what) {
712 case EVENT_FORWARDING_GET_COMPLETED:
713 handleForwardingSettingsReadResult(result, msg.arg1);
714 break;
715 }
716 }
717 };
718
719 private void handleForwardingSettingsReadResult(AsyncResult ar, int idx) {
720 if (DBG) Log.d(LOG_TAG, "handleForwardingSettingsReadResult: " + idx);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800721
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700722 Throwable error = null;
723 if (ar.exception != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700724 error = ar.exception;
Andrew Lee1af6cf72014-11-04 17:35:26 -0800725 if (DBG) Log.d(LOG_TAG, "FwdRead: ar.exception=" + error.getMessage());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700726 }
727 if (ar.userObj instanceof Throwable) {
Andrew Lee1af6cf72014-11-04 17:35:26 -0800728 error = (Throwable) ar.userObj;
729 if (DBG) Log.d(LOG_TAG, "FwdRead: userObj=" + error.getMessage());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700730 }
731
732 // We may have already gotten an error and decided to ignore the other results.
733 if (mForwardingReadResults == null) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800734 if (DBG) Log.d(LOG_TAG, "Ignoring fwd reading result: " + idx);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700735 return;
736 }
737
738 // In case of error ignore other results, show an error dialog
739 if (error != null) {
740 if (DBG) Log.d(LOG_TAG, "Error discovered for fwd read : " + idx);
741 mForwardingReadResults = null;
Andrew Lee84024342014-11-06 23:37:09 -0800742 dismissDialogSafely(VoicemailDialogUtil.VM_FWD_READING_DIALOG);
743 showDialogIfForeground(VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700744 return;
745 }
746
Andrew Lee1af6cf72014-11-04 17:35:26 -0800747 // Get the forwarding info.
748 mForwardingReadResults[idx] = CallForwardInfoUtil.getCallForwardInfo(
749 (CallForwardInfo[]) ar.result,
750 VoicemailProviderSettings.FORWARDING_SETTINGS_REASONS[idx]);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700751
752 // Check if we got all the results already
753 boolean done = true;
754 for (int i = 0; i < mForwardingReadResults.length; i++) {
755 if (mForwardingReadResults[i] == null) {
756 done = false;
757 break;
758 }
759 }
Andrew Lee1af6cf72014-11-04 17:35:26 -0800760
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700761 if (done) {
762 if (DBG) Log.d(LOG_TAG, "Done receiving fwd info");
Andrew Lee84024342014-11-06 23:37:09 -0800763 dismissDialogSafely(VoicemailDialogUtil.VM_FWD_READING_DIALOG);
Andrew Lee1af6cf72014-11-04 17:35:26 -0800764
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700765 if (mReadingSettingsForDefaultProvider) {
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800766 VoicemailProviderSettingsUtil.save(mPhone.getContext(),
767 VoicemailProviderListPreference.DEFAULT_KEY,
Andrew Lee299e4a72015-01-15 12:44:34 -0800768 new VoicemailProviderSettings(mOldVmNumber, mForwardingReadResults));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700769 mReadingSettingsForDefaultProvider = false;
770 }
771 saveVoiceMailAndForwardingNumberStage2();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700772 }
773 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800774
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700775 private void resetForwardingChangeState() {
776 mForwardingChangeResults = new HashMap<Integer, AsyncResult>();
777 mExpectedChangeResultReasons = new HashSet<Integer>();
778 }
779
Andrew Lee299e4a72015-01-15 12:44:34 -0800780 // Called after we are done saving the previous forwarding settings if we needed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700781 private void saveVoiceMailAndForwardingNumberStage2() {
782 mForwardingChangeResults = null;
783 mVoicemailChangeResult = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700784
Andrew Lee9c822312015-03-13 07:52:08 -0700785 resetForwardingChangeState();
786 for (int i = 0; i < mNewFwdSettings.length; i++) {
787 CallForwardInfo fi = mNewFwdSettings[i];
788 CallForwardInfo fiForReason =
789 CallForwardInfoUtil.infoForReason(mForwardingReadResults, fi.reason);
790 final boolean doUpdate = CallForwardInfoUtil.isUpdateRequired(fiForReason, fi);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700791
Andrew Lee9c822312015-03-13 07:52:08 -0700792 if (doUpdate) {
793 if (DBG) log("Setting fwd #: " + i + ": " + fi.toString());
794 mExpectedChangeResultReasons.add(i);
795
796 CallForwardInfoUtil.setCallForwardingOption(mPhone, fi,
797 mSetOptionComplete.obtainMessage(
798 EVENT_FORWARDING_CHANGED, fi.reason, 0));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700799 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700800 }
Andrew Lee9c822312015-03-13 07:52:08 -0700801 showDialogIfForeground(VoicemailDialogUtil.VM_FWD_SAVING_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700802 }
803
Andrew Lee9c822312015-03-13 07:52:08 -0700804 private void setVoicemailNumberWithCarrier() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700805 if (DBG) log("save voicemail #: " + mNewVMNumber);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800806
Andrew Lee9c822312015-03-13 07:52:08 -0700807 mVoicemailChangeResult = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700808 mPhone.setVoiceMailNumber(
809 mPhone.getVoiceMailAlphaTag().toString(),
810 mNewVMNumber,
811 Message.obtain(mSetOptionComplete, EVENT_VOICEMAIL_CHANGED));
812 }
813
814 /**
815 * Callback to handle option update completions
816 */
817 private final Handler mSetOptionComplete = new Handler() {
818 @Override
819 public void handleMessage(Message msg) {
820 AsyncResult result = (AsyncResult) msg.obj;
821 boolean done = false;
822 switch (msg.what) {
823 case EVENT_VOICEMAIL_CHANGED:
824 mVoicemailChangeResult = result;
Andrew Leee438b312014-10-29 16:59:15 -0700825 mVMChangeCompletedSuccessfully = isVmChangeSuccess();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700826 done = true;
827 break;
828 case EVENT_FORWARDING_CHANGED:
829 mForwardingChangeResults.put(msg.arg1, result);
830 if (result.exception != null) {
831 Log.w(LOG_TAG, "Error in setting fwd# " + msg.arg1 + ": " +
832 result.exception.getMessage());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700833 }
Andrew Leee438b312014-10-29 16:59:15 -0700834 if (isForwardingCompleted()) {
835 if (isFwdChangeSuccess()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700836 if (DBG) log("Overall fwd changes completed ok, starting vm change");
Andrew Lee9c822312015-03-13 07:52:08 -0700837 setVoicemailNumberWithCarrier();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700838 } else {
839 Log.w(LOG_TAG, "Overall fwd changes completed in failure. " +
840 "Check if we need to try rollback for some settings.");
841 mFwdChangesRequireRollback = false;
842 Iterator<Map.Entry<Integer,AsyncResult>> it =
843 mForwardingChangeResults.entrySet().iterator();
844 while (it.hasNext()) {
845 Map.Entry<Integer,AsyncResult> entry = it.next();
846 if (entry.getValue().exception == null) {
847 // If at least one succeeded we have to revert
848 Log.i(LOG_TAG, "Rollback will be required");
849 mFwdChangesRequireRollback = true;
850 break;
851 }
852 }
853 if (!mFwdChangesRequireRollback) {
854 Log.i(LOG_TAG, "No rollback needed.");
855 }
856 done = true;
857 }
858 }
859 break;
860 default:
861 // TODO: should never reach this, may want to throw exception
862 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800863
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700864 if (done) {
865 if (DBG) log("All VM provider related changes done");
866 if (mForwardingChangeResults != null) {
Andrew Lee84024342014-11-06 23:37:09 -0800867 dismissDialogSafely(VoicemailDialogUtil.VM_FWD_SAVING_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700868 }
Andrew Leee438b312014-10-29 16:59:15 -0700869 handleSetVmOrFwdMessage();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700870 }
871 }
872 };
873
874 /**
875 * Callback to handle option revert completions
876 */
877 private final Handler mRevertOptionComplete = new Handler() {
878 @Override
879 public void handleMessage(Message msg) {
880 AsyncResult result = (AsyncResult) msg.obj;
881 switch (msg.what) {
882 case EVENT_VOICEMAIL_CHANGED:
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700883 if (DBG) log("VM revert complete msg");
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800884 mVoicemailChangeResult = result;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700885 break;
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800886
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700887 case EVENT_FORWARDING_CHANGED:
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800888 if (DBG) log("FWD revert complete msg ");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700889 mForwardingChangeResults.put(msg.arg1, result);
890 if (result.exception != null) {
891 if (DBG) log("Error in reverting fwd# " + msg.arg1 + ": " +
892 result.exception.getMessage());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700893 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700894 break;
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800895
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700896 default:
897 // TODO: should never reach this, may want to throw exception
898 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800899
900 final boolean done = (!mVMChangeCompletedSuccessfully || mVoicemailChangeResult != null)
901 && (!mFwdChangesRequireRollback || isForwardingCompleted());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700902 if (done) {
903 if (DBG) log("All VM reverts done");
Andrew Lee84024342014-11-06 23:37:09 -0800904 dismissDialogSafely(VoicemailDialogUtil.VM_REVERTING_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700905 onRevertDone();
906 }
907 }
908 };
909
910 /**
Andrew Leee438b312014-10-29 16:59:15 -0700911 * Return true if there is a change result for every reason for which we expect a result.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700912 */
Andrew Leee438b312014-10-29 16:59:15 -0700913 private boolean isForwardingCompleted() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700914 if (mForwardingChangeResults == null) {
Andrew Leee438b312014-10-29 16:59:15 -0700915 return true;
916 }
917
918 for (Integer reason : mExpectedChangeResultReasons) {
919 if (mForwardingChangeResults.get(reason) == null) {
920 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700921 }
922 }
Andrew Leee438b312014-10-29 16:59:15 -0700923
924 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700925 }
Andrew Leee438b312014-10-29 16:59:15 -0700926
927 private boolean isFwdChangeSuccess() {
928 if (mForwardingChangeResults == null) {
929 return true;
930 }
931
932 for (AsyncResult result : mForwardingChangeResults.values()) {
933 Throwable exception = result.exception;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700934 if (exception != null) {
Andrew Leee438b312014-10-29 16:59:15 -0700935 String msg = exception.getMessage();
936 msg = (msg != null) ? msg : "";
937 Log.w(LOG_TAG, "Failed to change forwarding setting. Reason: " + msg);
938 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700939 }
940 }
Andrew Leee438b312014-10-29 16:59:15 -0700941 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700942 }
943
Andrew Leee438b312014-10-29 16:59:15 -0700944 private boolean isVmChangeSuccess() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700945 if (mVoicemailChangeResult.exception != null) {
Andrew Leee438b312014-10-29 16:59:15 -0700946 String msg = mVoicemailChangeResult.exception.getMessage();
947 msg = (msg != null) ? msg : "";
948 Log.w(LOG_TAG, "Failed to change voicemail. Reason: " + msg);
949 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700950 }
Andrew Leee438b312014-10-29 16:59:15 -0700951 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700952 }
953
Andrew Leee438b312014-10-29 16:59:15 -0700954 private void handleSetVmOrFwdMessage() {
955 if (DBG) log("handleSetVMMessage: set VM request complete");
956
957 if (!isFwdChangeSuccess()) {
Andrew Lee84024342014-11-06 23:37:09 -0800958 handleVmOrFwdSetError(VoicemailDialogUtil.FWD_SET_RESPONSE_ERROR_DIALOG);
Andrew Leee438b312014-10-29 16:59:15 -0700959 } else if (!isVmChangeSuccess()) {
Andrew Lee84024342014-11-06 23:37:09 -0800960 handleVmOrFwdSetError(VoicemailDialogUtil.VM_RESPONSE_ERROR_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700961 } else {
Andrew Lee84024342014-11-06 23:37:09 -0800962 handleVmAndFwdSetSuccess(VoicemailDialogUtil.VM_CONFIRM_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700963 }
964 }
965
966 /**
967 * Called when Voicemail Provider or its forwarding settings failed. Rolls back partly made
968 * changes to those settings and show "failure" dialog.
969 *
Andrew Leeab082272014-11-04 15:50:42 -0800970 * @param dialogId ID of the dialog to show for the specific error case. Either
Andrew Lee84024342014-11-06 23:37:09 -0800971 * {@link #FWD_SET_RESPONSE_ERROR_DIALOG} or {@link #VM_RESPONSE_ERROR_DIALOG}
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700972 */
Andrew Leeab082272014-11-04 15:50:42 -0800973 private void handleVmOrFwdSetError(int dialogId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700974 if (mChangingVMorFwdDueToProviderChange) {
Andrew Leeab082272014-11-04 15:50:42 -0800975 mVMOrFwdSetError = dialogId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700976 mChangingVMorFwdDueToProviderChange = false;
977 switchToPreviousVoicemailProvider();
978 return;
979 }
980 mChangingVMorFwdDueToProviderChange = false;
Andrew Leeab082272014-11-04 15:50:42 -0800981 showDialogIfForeground(dialogId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700982 updateVoiceNumberField();
983 }
984
985 /**
986 * Called when Voicemail Provider and its forwarding settings were successfully finished.
987 * This updates a bunch of variables and show "success" dialog.
988 */
Andrew Leeab082272014-11-04 15:50:42 -0800989 private void handleVmAndFwdSetSuccess(int dialogId) {
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800990 if (DBG) log("handleVmAndFwdSetSuccess: key is " + mVoicemailProviders.getKey());
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800991
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800992 mPreviousVMProviderKey = mVoicemailProviders.getKey();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700993 mChangingVMorFwdDueToProviderChange = false;
Andrew Leeab082272014-11-04 15:50:42 -0800994 showDialogIfForeground(dialogId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700995 updateVoiceNumberField();
996 }
997
998 /**
999 * Update the voicemail number from what we've recorded on the sim.
1000 */
1001 private void updateVoiceNumberField() {
Andrew Lee2d5d1a42014-11-05 12:34:14 -08001002 if (DBG) log("updateVoiceNumberField()");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001003
1004 mOldVmNumber = mPhone.getVoiceMailNumber();
Andrew Lee2d5d1a42014-11-05 12:34:14 -08001005 if (TextUtils.isEmpty(mOldVmNumber)) {
1006 mSubMenuVoicemailSettings.setPhoneNumber("");
1007 mSubMenuVoicemailSettings.setSummary(getString(R.string.voicemail_number_not_set));
1008 } else {
1009 mSubMenuVoicemailSettings.setPhoneNumber(mOldVmNumber);
1010 mSubMenuVoicemailSettings.setSummary(mOldVmNumber);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001011 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001012 }
1013
1014 /*
1015 * Helper Methods for Activity class.
1016 * The initial query commands are split into two pieces now
1017 * for individual expansion. This combined with the ability
1018 * to cancel queries allows for a much better user experience,
1019 * and also ensures that the user only waits to update the
1020 * data that is relevant.
1021 */
1022
1023 @Override
1024 protected void onPrepareDialog(int id, Dialog dialog) {
1025 super.onPrepareDialog(id, dialog);
1026 mCurrentDialogId = id;
1027 }
1028
1029 // dialog creation method, called by showDialog()
1030 @Override
Andrew Lee84024342014-11-06 23:37:09 -08001031 protected Dialog onCreateDialog(int dialogId) {
1032 return VoicemailDialogUtil.getDialog(this, dialogId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001033 }
1034
1035 // This is a method implemented for DialogInterface.OnClickListener.
1036 // Used with the error dialog to close the app, voicemail dialog to just dismiss.
1037 // Close button is mapped to BUTTON_POSITIVE for the errors that close the activity,
1038 // while those that are mapped to BUTTON_NEUTRAL only move the preference focus.
1039 public void onClick(DialogInterface dialog, int which) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -08001040 if (DBG) log("onClick: button clicked is " + which);
1041
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001042 dialog.dismiss();
1043 switch (which){
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001044 case DialogInterface.BUTTON_NEGATIVE:
Andrew Lee84024342014-11-06 23:37:09 -08001045 if (mCurrentDialogId == VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001046 // We failed to get current forwarding settings and the user
1047 // does not wish to continue.
1048 switchToPreviousVoicemailProvider();
1049 }
1050 break;
1051 case DialogInterface.BUTTON_POSITIVE:
Andrew Lee84024342014-11-06 23:37:09 -08001052 if (mCurrentDialogId == VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001053 // We failed to get current forwarding settings but the user
1054 // wishes to continue changing settings to the new vm provider
Andrew Lee9c822312015-03-13 07:52:08 -07001055 setVoicemailNumberWithCarrier();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001056 } else {
1057 finish();
1058 }
1059 return;
1060 default:
1061 // just let the dialog close and go back to the input
1062 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -08001063
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001064 // In all dialogs, all buttons except BUTTON_POSITIVE lead to the end of user interaction
1065 // with settings UI. If we were called to explicitly configure voice mail then
1066 // we finish the settings activity here to come back to whatever the user was doing.
1067 if (getIntent().getAction().equals(ACTION_ADD_VOICEMAIL)) {
1068 finish();
1069 }
1070 }
1071
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001072 /*
1073 * Activity class methods
1074 */
1075
1076 @Override
1077 protected void onCreate(Bundle icicle) {
1078 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -08001079 if (DBG) log("onCreate: Intent is " + getIntent());
1080
Jay Shraunerc2684732014-11-12 12:10:37 -08001081 // Make sure we are running as the primary user.
1082 if (UserHandle.myUserId() != UserHandle.USER_OWNER) {
1083 Toast.makeText(this, R.string.call_settings_primary_user_only,
1084 Toast.LENGTH_SHORT).show();
1085 finish();
1086 return;
1087 }
1088
Tyler Gunnbaee2952014-09-10 16:01:02 -07001089 // Show the voicemail preference in onResume if the calling intent specifies the
1090 // ACTION_ADD_VOICEMAIL action.
1091 mShowVoicemailPreference = (icicle == null) &&
Jay Shraunerbe2fb262014-11-11 15:19:58 -08001092 TextUtils.equals(getIntent().getAction(), ACTION_ADD_VOICEMAIL);
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001093 mSetupVoicemail = mShowVoicemailPreference &&
1094 getIntent().getBooleanExtra(SETUP_VOICEMAIL_EXTRA, false);
Andrew Lee5ed870c2014-10-29 11:47:49 -07001095
Andrew Leedd4f6df2014-12-09 19:13:51 -08001096 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5ed870c2014-10-29 11:47:49 -07001097 mSubscriptionInfoHelper.setActionBarTitle(
1098 getActionBar(), getResources(), R.string.call_settings_with_label);
Andrew Lee1479dd12014-11-06 23:06:32 -08001099 mPhone = mSubscriptionInfoHelper.getPhone();
Tyler Gunnbaee2952014-09-10 16:01:02 -07001100 }
1101
Tyler Gunnbaee2952014-09-10 16:01:02 -07001102 @Override
1103 protected void onResume() {
1104 super.onResume();
1105 mForeground = true;
1106
1107 PreferenceScreen preferenceScreen = getPreferenceScreen();
1108 if (preferenceScreen != null) {
1109 preferenceScreen.removeAll();
1110 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001111
1112 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -07001113
Andrew Lee6fee2cb2014-12-09 16:42:18 -08001114 TelecomManager telecomManager = TelecomManager.from(this);
1115 TelephonyManager telephonyManager =
1116 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1117
1118 Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
1119 if (telephonyManager.isMultiSimEnabled() || (telecomManager.getSimCallManagers().isEmpty()
1120 && !SipUtil.isVoipSupported(mPhone.getContext()))) {
1121 getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
1122 }
Andrew Leedb2fe562014-09-03 15:40:43 -07001123
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001124 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee64a7d792014-10-15 17:38:38 -07001125 mSubMenuVoicemailSettings = (EditPhoneNumberPreference) findPreference(BUTTON_VOICEMAIL_KEY);
1126 mSubMenuVoicemailSettings.setParentActivity(this, VOICEMAIL_PREF_ID, this);
1127 mSubMenuVoicemailSettings.setDialogOnClosedListener(this);
1128 mSubMenuVoicemailSettings.setDialogTitle(R.string.voicemail_settings_number_label);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001129
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001130 mButtonAutoRetry = (CheckBoxPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee2170a972014-08-13 18:13:01 -07001131
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001132 mVoicemailProviders = (VoicemailProviderListPreference) findPreference(
1133 BUTTON_VOICEMAIL_PROVIDER_KEY);
1134 mVoicemailProviders.init(mPhone, getIntent());
Andrew Lee2c027892014-10-29 11:29:54 -07001135 mVoicemailProviders.setOnPreferenceChangeListener(this);
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001136 mPreviousVMProviderKey = mVoicemailProviders.getValue();
Andrew Lee8d66d812014-11-24 14:54:02 -08001137
Andrew Lee2c027892014-10-29 11:29:54 -07001138 mVoicemailSettingsScreen =
1139 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001140 mVoicemailSettings = (PreferenceScreen) findPreference(BUTTON_VOICEMAIL_SETTING_KEY);
Andrew Lee8d66d812014-11-24 14:54:02 -08001141
Andrew Lee1ec7c7e2014-12-03 15:33:21 -08001142 mVoicemailNotificationRingtone = (VoicemailRingtonePreference) findPreference(
1143 getResources().getString(R.string.voicemail_notification_ringtone_key));
1144 mVoicemailNotificationRingtone.init(mPhone);
1145
Andrew Lee8d66d812014-11-24 14:54:02 -08001146 mVoicemailNotificationVibrate = (CheckBoxPreference) findPreference(
1147 getResources().getString(R.string.voicemail_notification_vibrate_key));
1148 mVoicemailNotificationVibrate.setOnPreferenceChangeListener(this);
1149
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001150 updateVMPreferenceWidgets(mVoicemailProviders.getValue());
1151
1152 mEnableVideoCalling = (CheckBoxPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001153
Andrew Lee64a7d792014-10-15 17:38:38 -07001154 if (getResources().getBoolean(R.bool.auto_retry_enabled)) {
1155 mButtonAutoRetry.setOnPreferenceChangeListener(this);
1156 int autoretry = Settings.Global.getInt(
1157 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
1158 mButtonAutoRetry.setChecked(autoretry != 0);
1159 } else {
1160 prefSet.removePreference(mButtonAutoRetry);
1161 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001162 }
1163
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001164 if (!getResources().getBoolean(R.bool.world_phone)) {
Andrew Lee2b36ba22014-11-05 17:08:49 -08001165 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
1166 prefSet.removePreference(cdmaOptions);
1167
1168 // TODO: Support MSIM for this preference option.
1169 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
1170 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171
1172 int phoneType = mPhone.getPhoneType();
Andrew Lee5ed870c2014-10-29 11:47:49 -07001173 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
Junda Liua09d6962014-11-12 13:39:02 -08001174 boolean shouldHideCarrierSettings = Settings.Global.getInt(
1175 getContentResolver(), Settings.Global.HIDE_CARRIER_NETWORK_SETTINGS, 0) == 1;
1176 if (shouldHideCarrierSettings) {
Andrew Lee5ed870c2014-10-29 11:47:49 -07001177 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001178 } else {
Junda Liua09d6962014-11-12 13:39:02 -08001179 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
1180 prefSet.removePreference(fdnButton);
1181
1182 if (!getResources().getBoolean(R.bool.config_voice_privacy_disable)) {
1183 addPreferencesFromResource(R.xml.cdma_call_privacy);
1184 }
1185 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Andrew Leedd4f6df2014-12-09 19:13:51 -08001186 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Junda Liua09d6962014-11-12 13:39:02 -08001187
1188 if (getResources().getBoolean(R.bool.config_additional_call_setting)) {
1189 addPreferencesFromResource(R.xml.gsm_umts_call_options);
1190
1191 Preference callForwardingPref = prefSet.findPreference(CALL_FORWARDING_KEY);
1192 callForwardingPref.setIntent(mSubscriptionInfoHelper.getIntent(
Andrew Leedd4f6df2014-12-09 19:13:51 -08001193 GsmUmtsCallForwardOptions.class));
Junda Liua09d6962014-11-12 13:39:02 -08001194
1195 Preference additionalGsmSettingsPref =
1196 prefSet.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
1197 additionalGsmSettingsPref.setIntent(mSubscriptionInfoHelper.getIntent(
Andrew Leedd4f6df2014-12-09 19:13:51 -08001198 GsmUmtsAdditionalCallOptions.class));
Junda Liua09d6962014-11-12 13:39:02 -08001199 }
1200 } else {
1201 throw new IllegalStateException("Unexpected phone type: " + phoneType);
1202 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001203 }
1204 }
1205
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001206 // check the intent that started this activity and pop up the voicemail
1207 // dialog if we've been asked to.
1208 // If we have at least one non default VM provider registered then bring up
1209 // the selection for the VM provider, otherwise bring up a VM number dialog.
1210 // We only bring up the dialog the first time we are called (not after orientation change)
Andrew Lee2c027892014-10-29 11:29:54 -07001211 if (mShowVoicemailPreference) {
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001212 if (DBG) log("ACTION_ADD_VOICEMAIL Intent is thrown");
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001213 if (mSetupVoicemail) {
1214 simulatePreferenceClick(mVoicemailSettingsScreen);
1215 mSetupVoicemail = false;
1216 } else if (mVoicemailProviders.hasMoreThanOneVoicemailProvider()) {
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001217 if (DBG) log("Voicemail data has more than one provider.");
Tyler Gunnbaee2952014-09-10 16:01:02 -07001218 simulatePreferenceClick(mVoicemailProviders);
1219 } else {
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001220 onPreferenceChange(mVoicemailProviders, VoicemailProviderListPreference.DEFAULT_KEY);
1221 mVoicemailProviders.setValue(VoicemailProviderListPreference.DEFAULT_KEY);
Tyler Gunnbaee2952014-09-10 16:01:02 -07001222 }
1223 mShowVoicemailPreference = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001224 }
Tyler Gunnbaee2952014-09-10 16:01:02 -07001225
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001226 updateVoiceNumberField();
1227 mVMProviderSettingsForced = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228
Andrew Lee8d66d812014-11-24 14:54:02 -08001229 mVoicemailNotificationVibrate.setChecked(
Andrew Lee1ec7c7e2014-12-03 15:33:21 -08001230 VoicemailNotificationSettingsUtil.isVibrationEnabled(mPhone));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231
Andrew Lee312e8172014-10-23 17:01:36 -07001232 if (ImsManager.isVtEnabledByPlatform(mPhone.getContext()) && ENABLE_VT_FLAG) {
1233 boolean currentValue =
1234 ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
1235 ? PhoneGlobals.getInstance().phoneMgr.isVideoCallingEnabled() : false;
1236 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -07001237 mEnableVideoCalling.setOnPreferenceChangeListener(this);
1238 } else {
1239 prefSet.removePreference(mEnableVideoCalling);
1240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001241 }
1242
Andrew Lee785ca2a2014-12-18 12:46:41 -08001243 @Override
1244 protected void onNewIntent(Intent newIntent) {
1245 setIntent(newIntent);
1246
1247 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
1248 mSubscriptionInfoHelper.setActionBarTitle(
1249 getActionBar(), getResources(), R.string.call_settings_with_label);
1250 mPhone = mSubscriptionInfoHelper.getPhone();
1251 }
1252
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001253 private static void log(String msg) {
1254 Log.d(LOG_TAG, msg);
1255 }
1256
1257 /**
1258 * Updates the look of the VM preference widgets based on current VM provider settings.
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001259 * Note that the provider name is loaded fxrorm the found activity via loadLabel in
1260 * {@link VoicemailProviderListPreference#initVoiceMailProviders()} in order for it to be
1261 * localizable.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 */
1263 private void updateVMPreferenceWidgets(String currentProviderSetting) {
1264 final String key = currentProviderSetting;
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001265 final VoicemailProvider provider = mVoicemailProviders.getVoicemailProvider(key);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001266
1267 /* This is the case when we are coming up on a freshly wiped phone and there is no
1268 persisted value for the list preference mVoicemailProviders.
1269 In this case we want to show the UI asking the user to select a voicemail provider as
1270 opposed to silently falling back to default one. */
1271 if (provider == null) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -08001272 if (DBG) log("updateVMPreferenceWidget: key: " + key + " -> null.");
1273
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 mVoicemailProviders.setSummary(getString(R.string.sum_voicemail_choose_provider));
1275 mVoicemailSettings.setEnabled(false);
1276 mVoicemailSettings.setIntent(null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 mVoicemailNotificationVibrate.setEnabled(false);
1278 } else {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -08001279 if (DBG) log("updateVMPreferenceWidget: key: " + key + " -> " + provider.toString());
1280
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 final String providerName = provider.name;
1282 mVoicemailProviders.setSummary(providerName);
1283 mVoicemailSettings.setEnabled(true);
1284 mVoicemailSettings.setIntent(provider.intent);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001285 mVoicemailNotificationVibrate.setEnabled(true);
1286 }
1287 }
1288
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001289
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290 /**
1291 * Simulates user clicking on a passed preference.
1292 * Usually needed when the preference is a dialog preference and we want to invoke
1293 * a dialog for this preference programmatically.
Santos Cordonda120f42014-08-06 04:44:34 -07001294 * TODO: figure out if there is a cleaner way to cause preference dlg to come up
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001295 */
1296 private void simulatePreferenceClick(Preference preference) {
1297 // Go through settings until we find our setting
1298 // and then simulate a click on it to bring up the dialog
1299 final ListAdapter adapter = getPreferenceScreen().getRootAdapter();
1300 for (int idx = 0; idx < adapter.getCount(); idx++) {
1301 if (adapter.getItem(idx) == preference) {
1302 getPreferenceScreen().onItemClick(this.getListView(),
1303 null, idx, adapter.getItemId(idx));
1304 break;
1305 }
1306 }
1307 }
1308
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001309 @Override
1310 public boolean onOptionsItemSelected(MenuItem item) {
1311 final int itemId = item.getItemId();
1312 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -07001313 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 return true;
1315 }
1316 return super.onOptionsItemSelected(item);
1317 }
Andrew Lee8d66d812014-11-24 14:54:02 -08001318
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 /**
1320 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
1321 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
1322 */
Andrew Lee5efb1122014-12-05 04:20:42 -08001323 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -08001324 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
1325 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326 intent.setAction(Intent.ACTION_MAIN);
1327 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
1328 activity.startActivity(intent);
1329 activity.finish();
1330 }
1331}