blob: 8b3f4824d7cfb725acf4b9cf1a97ab11e23654a8 [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.
686 if (!key.equals(mPreviousVMProviderKey) && !isCdma) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700687 mReadingSettingsForDefaultProvider =
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800688 mPreviousVMProviderKey.equals(VoicemailProviderListPreference.DEFAULT_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700689 if (DBG) log("Reading current forwarding settings");
Andrew Leeb490d732014-10-27 15:00:41 -0700690 int numSettingsReasons = VoicemailProviderSettings.FORWARDING_SETTINGS_REASONS.length;
691 mForwardingReadResults = new CallForwardInfo[numSettingsReasons];
692 for (int i = 0; i < mForwardingReadResults.length; i++) {
693 mPhone.getCallForwardingOption(
694 VoicemailProviderSettings.FORWARDING_SETTINGS_REASONS[i],
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700695 mGetOptionComplete.obtainMessage(EVENT_FORWARDING_GET_COMPLETED, i, 0));
696 }
Andrew Lee84024342014-11-06 23:37:09 -0800697 showDialogIfForeground(VoicemailDialogUtil.VM_FWD_READING_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700698 } else {
699 saveVoiceMailAndForwardingNumberStage2();
700 }
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800701
702 // Refresh the MWI indicator if it is already showing.
703 PhoneGlobals.getInstance().refreshMwiIndicator(mSubscriptionInfoHelper.getSubId());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700704 }
705
706 private final Handler mGetOptionComplete = new Handler() {
707 @Override
708 public void handleMessage(Message msg) {
709 AsyncResult result = (AsyncResult) msg.obj;
710 switch (msg.what) {
711 case EVENT_FORWARDING_GET_COMPLETED:
712 handleForwardingSettingsReadResult(result, msg.arg1);
713 break;
714 }
715 }
716 };
717
718 private void handleForwardingSettingsReadResult(AsyncResult ar, int idx) {
719 if (DBG) Log.d(LOG_TAG, "handleForwardingSettingsReadResult: " + idx);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800720
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700721 Throwable error = null;
722 if (ar.exception != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700723 error = ar.exception;
Andrew Lee1af6cf72014-11-04 17:35:26 -0800724 if (DBG) Log.d(LOG_TAG, "FwdRead: ar.exception=" + error.getMessage());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700725 }
726 if (ar.userObj instanceof Throwable) {
Andrew Lee1af6cf72014-11-04 17:35:26 -0800727 error = (Throwable) ar.userObj;
728 if (DBG) Log.d(LOG_TAG, "FwdRead: userObj=" + error.getMessage());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700729 }
730
731 // We may have already gotten an error and decided to ignore the other results.
732 if (mForwardingReadResults == null) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800733 if (DBG) Log.d(LOG_TAG, "Ignoring fwd reading result: " + idx);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700734 return;
735 }
736
737 // In case of error ignore other results, show an error dialog
738 if (error != null) {
739 if (DBG) Log.d(LOG_TAG, "Error discovered for fwd read : " + idx);
740 mForwardingReadResults = null;
Andrew Lee84024342014-11-06 23:37:09 -0800741 dismissDialogSafely(VoicemailDialogUtil.VM_FWD_READING_DIALOG);
742 showDialogIfForeground(VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700743 return;
744 }
745
Andrew Lee1af6cf72014-11-04 17:35:26 -0800746 // Get the forwarding info.
747 mForwardingReadResults[idx] = CallForwardInfoUtil.getCallForwardInfo(
748 (CallForwardInfo[]) ar.result,
749 VoicemailProviderSettings.FORWARDING_SETTINGS_REASONS[idx]);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700750
751 // Check if we got all the results already
752 boolean done = true;
753 for (int i = 0; i < mForwardingReadResults.length; i++) {
754 if (mForwardingReadResults[i] == null) {
755 done = false;
756 break;
757 }
758 }
Andrew Lee1af6cf72014-11-04 17:35:26 -0800759
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700760 if (done) {
761 if (DBG) Log.d(LOG_TAG, "Done receiving fwd info");
Andrew Lee84024342014-11-06 23:37:09 -0800762 dismissDialogSafely(VoicemailDialogUtil.VM_FWD_READING_DIALOG);
Andrew Lee1af6cf72014-11-04 17:35:26 -0800763
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700764 if (mReadingSettingsForDefaultProvider) {
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800765 VoicemailProviderSettingsUtil.save(mPhone.getContext(),
766 VoicemailProviderListPreference.DEFAULT_KEY,
Andrew Lee299e4a72015-01-15 12:44:34 -0800767 new VoicemailProviderSettings(mOldVmNumber, mForwardingReadResults));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700768 mReadingSettingsForDefaultProvider = false;
769 }
770 saveVoiceMailAndForwardingNumberStage2();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700771 }
772 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800773
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700774 private void resetForwardingChangeState() {
775 mForwardingChangeResults = new HashMap<Integer, AsyncResult>();
776 mExpectedChangeResultReasons = new HashSet<Integer>();
777 }
778
Andrew Lee299e4a72015-01-15 12:44:34 -0800779 // Called after we are done saving the previous forwarding settings if we needed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700780 private void saveVoiceMailAndForwardingNumberStage2() {
781 mForwardingChangeResults = null;
782 mVoicemailChangeResult = null;
Andrew Leeb490d732014-10-27 15:00:41 -0700783 if (mNewFwdSettings != VoicemailProviderSettings.NO_FORWARDING) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700784 resetForwardingChangeState();
785 for (int i = 0; i < mNewFwdSettings.length; i++) {
786 CallForwardInfo fi = mNewFwdSettings[i];
Andrew Lee1af6cf72014-11-04 17:35:26 -0800787 CallForwardInfo fiForReason =
788 CallForwardInfoUtil.infoForReason(mForwardingReadResults, fi.reason);
789 final boolean doUpdate = CallForwardInfoUtil.isUpdateRequired(fiForReason, fi);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700790
791 if (doUpdate) {
792 if (DBG) log("Setting fwd #: " + i + ": " + fi.toString());
793 mExpectedChangeResultReasons.add(i);
794
Andrew Lee1af6cf72014-11-04 17:35:26 -0800795 CallForwardInfoUtil.setCallForwardingOption(mPhone, fi,
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700796 mSetOptionComplete.obtainMessage(
797 EVENT_FORWARDING_CHANGED, fi.reason, 0));
798 }
799 }
Andrew Lee84024342014-11-06 23:37:09 -0800800 showDialogIfForeground(VoicemailDialogUtil.VM_FWD_SAVING_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700801 } else {
802 if (DBG) log("Not touching fwd #");
803 setVMNumberWithCarrier();
804 }
805 }
806
807 private void setVMNumberWithCarrier() {
808 if (DBG) log("save voicemail #: " + mNewVMNumber);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800809
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700810 mPhone.setVoiceMailNumber(
811 mPhone.getVoiceMailAlphaTag().toString(),
812 mNewVMNumber,
813 Message.obtain(mSetOptionComplete, EVENT_VOICEMAIL_CHANGED));
814 }
815
816 /**
817 * Callback to handle option update completions
818 */
819 private final Handler mSetOptionComplete = new Handler() {
820 @Override
821 public void handleMessage(Message msg) {
822 AsyncResult result = (AsyncResult) msg.obj;
823 boolean done = false;
824 switch (msg.what) {
825 case EVENT_VOICEMAIL_CHANGED:
826 mVoicemailChangeResult = result;
Andrew Leee438b312014-10-29 16:59:15 -0700827 mVMChangeCompletedSuccessfully = isVmChangeSuccess();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700828 done = true;
829 break;
830 case EVENT_FORWARDING_CHANGED:
831 mForwardingChangeResults.put(msg.arg1, result);
832 if (result.exception != null) {
833 Log.w(LOG_TAG, "Error in setting fwd# " + msg.arg1 + ": " +
834 result.exception.getMessage());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700835 }
Andrew Leee438b312014-10-29 16:59:15 -0700836 if (isForwardingCompleted()) {
837 if (isFwdChangeSuccess()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700838 if (DBG) log("Overall fwd changes completed ok, starting vm change");
839 setVMNumberWithCarrier();
840 } else {
841 Log.w(LOG_TAG, "Overall fwd changes completed in failure. " +
842 "Check if we need to try rollback for some settings.");
843 mFwdChangesRequireRollback = false;
844 Iterator<Map.Entry<Integer,AsyncResult>> it =
845 mForwardingChangeResults.entrySet().iterator();
846 while (it.hasNext()) {
847 Map.Entry<Integer,AsyncResult> entry = it.next();
848 if (entry.getValue().exception == null) {
849 // If at least one succeeded we have to revert
850 Log.i(LOG_TAG, "Rollback will be required");
851 mFwdChangesRequireRollback = true;
852 break;
853 }
854 }
855 if (!mFwdChangesRequireRollback) {
856 Log.i(LOG_TAG, "No rollback needed.");
857 }
858 done = true;
859 }
860 }
861 break;
862 default:
863 // TODO: should never reach this, may want to throw exception
864 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800865
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700866 if (done) {
867 if (DBG) log("All VM provider related changes done");
868 if (mForwardingChangeResults != null) {
Andrew Lee84024342014-11-06 23:37:09 -0800869 dismissDialogSafely(VoicemailDialogUtil.VM_FWD_SAVING_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700870 }
Andrew Leee438b312014-10-29 16:59:15 -0700871 handleSetVmOrFwdMessage();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700872 }
873 }
874 };
875
876 /**
877 * Callback to handle option revert completions
878 */
879 private final Handler mRevertOptionComplete = new Handler() {
880 @Override
881 public void handleMessage(Message msg) {
882 AsyncResult result = (AsyncResult) msg.obj;
883 switch (msg.what) {
884 case EVENT_VOICEMAIL_CHANGED:
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700885 if (DBG) log("VM revert complete msg");
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800886 mVoicemailChangeResult = result;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700887 break;
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800888
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700889 case EVENT_FORWARDING_CHANGED:
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800890 if (DBG) log("FWD revert complete msg ");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700891 mForwardingChangeResults.put(msg.arg1, result);
892 if (result.exception != null) {
893 if (DBG) log("Error in reverting fwd# " + msg.arg1 + ": " +
894 result.exception.getMessage());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700896 break;
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800897
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700898 default:
899 // TODO: should never reach this, may want to throw exception
900 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800901
902 final boolean done = (!mVMChangeCompletedSuccessfully || mVoicemailChangeResult != null)
903 && (!mFwdChangesRequireRollback || isForwardingCompleted());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700904 if (done) {
905 if (DBG) log("All VM reverts done");
Andrew Lee84024342014-11-06 23:37:09 -0800906 dismissDialogSafely(VoicemailDialogUtil.VM_REVERTING_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700907 onRevertDone();
908 }
909 }
910 };
911
912 /**
Andrew Leee438b312014-10-29 16:59:15 -0700913 * Return true if there is a change result for every reason for which we expect a result.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700914 */
Andrew Leee438b312014-10-29 16:59:15 -0700915 private boolean isForwardingCompleted() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700916 if (mForwardingChangeResults == null) {
Andrew Leee438b312014-10-29 16:59:15 -0700917 return true;
918 }
919
920 for (Integer reason : mExpectedChangeResultReasons) {
921 if (mForwardingChangeResults.get(reason) == null) {
922 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700923 }
924 }
Andrew Leee438b312014-10-29 16:59:15 -0700925
926 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700927 }
Andrew Leee438b312014-10-29 16:59:15 -0700928
929 private boolean isFwdChangeSuccess() {
930 if (mForwardingChangeResults == null) {
931 return true;
932 }
933
934 for (AsyncResult result : mForwardingChangeResults.values()) {
935 Throwable exception = result.exception;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700936 if (exception != null) {
Andrew Leee438b312014-10-29 16:59:15 -0700937 String msg = exception.getMessage();
938 msg = (msg != null) ? msg : "";
939 Log.w(LOG_TAG, "Failed to change forwarding setting. Reason: " + msg);
940 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700941 }
942 }
Andrew Leee438b312014-10-29 16:59:15 -0700943 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700944 }
945
Andrew Leee438b312014-10-29 16:59:15 -0700946 private boolean isVmChangeSuccess() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700947 if (mVoicemailChangeResult.exception != null) {
Andrew Leee438b312014-10-29 16:59:15 -0700948 String msg = mVoicemailChangeResult.exception.getMessage();
949 msg = (msg != null) ? msg : "";
950 Log.w(LOG_TAG, "Failed to change voicemail. Reason: " + msg);
951 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700952 }
Andrew Leee438b312014-10-29 16:59:15 -0700953 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700954 }
955
Andrew Leee438b312014-10-29 16:59:15 -0700956 private void handleSetVmOrFwdMessage() {
957 if (DBG) log("handleSetVMMessage: set VM request complete");
958
959 if (!isFwdChangeSuccess()) {
Andrew Lee84024342014-11-06 23:37:09 -0800960 handleVmOrFwdSetError(VoicemailDialogUtil.FWD_SET_RESPONSE_ERROR_DIALOG);
Andrew Leee438b312014-10-29 16:59:15 -0700961 } else if (!isVmChangeSuccess()) {
Andrew Lee84024342014-11-06 23:37:09 -0800962 handleVmOrFwdSetError(VoicemailDialogUtil.VM_RESPONSE_ERROR_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700963 } else {
Andrew Lee84024342014-11-06 23:37:09 -0800964 handleVmAndFwdSetSuccess(VoicemailDialogUtil.VM_CONFIRM_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700965 }
966 }
967
968 /**
969 * Called when Voicemail Provider or its forwarding settings failed. Rolls back partly made
970 * changes to those settings and show "failure" dialog.
971 *
Andrew Leeab082272014-11-04 15:50:42 -0800972 * @param dialogId ID of the dialog to show for the specific error case. Either
Andrew Lee84024342014-11-06 23:37:09 -0800973 * {@link #FWD_SET_RESPONSE_ERROR_DIALOG} or {@link #VM_RESPONSE_ERROR_DIALOG}
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700974 */
Andrew Leeab082272014-11-04 15:50:42 -0800975 private void handleVmOrFwdSetError(int dialogId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700976 if (mChangingVMorFwdDueToProviderChange) {
Andrew Leeab082272014-11-04 15:50:42 -0800977 mVMOrFwdSetError = dialogId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700978 mChangingVMorFwdDueToProviderChange = false;
979 switchToPreviousVoicemailProvider();
980 return;
981 }
982 mChangingVMorFwdDueToProviderChange = false;
Andrew Leeab082272014-11-04 15:50:42 -0800983 showDialogIfForeground(dialogId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700984 updateVoiceNumberField();
985 }
986
987 /**
988 * Called when Voicemail Provider and its forwarding settings were successfully finished.
989 * This updates a bunch of variables and show "success" dialog.
990 */
Andrew Leeab082272014-11-04 15:50:42 -0800991 private void handleVmAndFwdSetSuccess(int dialogId) {
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800992 if (DBG) log("handleVmAndFwdSetSuccess: key is " + mVoicemailProviders.getKey());
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800993
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800994 mPreviousVMProviderKey = mVoicemailProviders.getKey();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700995 mChangingVMorFwdDueToProviderChange = false;
Andrew Leeab082272014-11-04 15:50:42 -0800996 showDialogIfForeground(dialogId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700997 updateVoiceNumberField();
998 }
999
1000 /**
1001 * Update the voicemail number from what we've recorded on the sim.
1002 */
1003 private void updateVoiceNumberField() {
Andrew Lee2d5d1a42014-11-05 12:34:14 -08001004 if (DBG) log("updateVoiceNumberField()");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001005
1006 mOldVmNumber = mPhone.getVoiceMailNumber();
Andrew Lee2d5d1a42014-11-05 12:34:14 -08001007 if (TextUtils.isEmpty(mOldVmNumber)) {
1008 mSubMenuVoicemailSettings.setPhoneNumber("");
1009 mSubMenuVoicemailSettings.setSummary(getString(R.string.voicemail_number_not_set));
1010 } else {
1011 mSubMenuVoicemailSettings.setPhoneNumber(mOldVmNumber);
1012 mSubMenuVoicemailSettings.setSummary(mOldVmNumber);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001013 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001014 }
1015
1016 /*
1017 * Helper Methods for Activity class.
1018 * The initial query commands are split into two pieces now
1019 * for individual expansion. This combined with the ability
1020 * to cancel queries allows for a much better user experience,
1021 * and also ensures that the user only waits to update the
1022 * data that is relevant.
1023 */
1024
1025 @Override
1026 protected void onPrepareDialog(int id, Dialog dialog) {
1027 super.onPrepareDialog(id, dialog);
1028 mCurrentDialogId = id;
1029 }
1030
1031 // dialog creation method, called by showDialog()
1032 @Override
Andrew Lee84024342014-11-06 23:37:09 -08001033 protected Dialog onCreateDialog(int dialogId) {
1034 return VoicemailDialogUtil.getDialog(this, dialogId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001035 }
1036
1037 // This is a method implemented for DialogInterface.OnClickListener.
1038 // Used with the error dialog to close the app, voicemail dialog to just dismiss.
1039 // Close button is mapped to BUTTON_POSITIVE for the errors that close the activity,
1040 // while those that are mapped to BUTTON_NEUTRAL only move the preference focus.
1041 public void onClick(DialogInterface dialog, int which) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -08001042 if (DBG) log("onClick: button clicked is " + which);
1043
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001044 dialog.dismiss();
1045 switch (which){
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001046 case DialogInterface.BUTTON_NEGATIVE:
Andrew Lee84024342014-11-06 23:37:09 -08001047 if (mCurrentDialogId == VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001048 // We failed to get current forwarding settings and the user
1049 // does not wish to continue.
1050 switchToPreviousVoicemailProvider();
1051 }
1052 break;
1053 case DialogInterface.BUTTON_POSITIVE:
Andrew Lee84024342014-11-06 23:37:09 -08001054 if (mCurrentDialogId == VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001055 // We failed to get current forwarding settings but the user
1056 // wishes to continue changing settings to the new vm provider
1057 saveVoiceMailAndForwardingNumberStage2();
1058 } else {
1059 finish();
1060 }
1061 return;
1062 default:
1063 // just let the dialog close and go back to the input
1064 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -08001065
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001066 // In all dialogs, all buttons except BUTTON_POSITIVE lead to the end of user interaction
1067 // with settings UI. If we were called to explicitly configure voice mail then
1068 // we finish the settings activity here to come back to whatever the user was doing.
1069 if (getIntent().getAction().equals(ACTION_ADD_VOICEMAIL)) {
1070 finish();
1071 }
1072 }
1073
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001074 /*
1075 * Activity class methods
1076 */
1077
1078 @Override
1079 protected void onCreate(Bundle icicle) {
1080 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -08001081 if (DBG) log("onCreate: Intent is " + getIntent());
1082
Jay Shraunerc2684732014-11-12 12:10:37 -08001083 // Make sure we are running as the primary user.
1084 if (UserHandle.myUserId() != UserHandle.USER_OWNER) {
1085 Toast.makeText(this, R.string.call_settings_primary_user_only,
1086 Toast.LENGTH_SHORT).show();
1087 finish();
1088 return;
1089 }
1090
Tyler Gunnbaee2952014-09-10 16:01:02 -07001091 // Show the voicemail preference in onResume if the calling intent specifies the
1092 // ACTION_ADD_VOICEMAIL action.
1093 mShowVoicemailPreference = (icicle == null) &&
Jay Shraunerbe2fb262014-11-11 15:19:58 -08001094 TextUtils.equals(getIntent().getAction(), ACTION_ADD_VOICEMAIL);
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001095 mSetupVoicemail = mShowVoicemailPreference &&
1096 getIntent().getBooleanExtra(SETUP_VOICEMAIL_EXTRA, false);
Andrew Lee5ed870c2014-10-29 11:47:49 -07001097
Andrew Leedd4f6df2014-12-09 19:13:51 -08001098 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5ed870c2014-10-29 11:47:49 -07001099 mSubscriptionInfoHelper.setActionBarTitle(
1100 getActionBar(), getResources(), R.string.call_settings_with_label);
Andrew Lee1479dd12014-11-06 23:06:32 -08001101 mPhone = mSubscriptionInfoHelper.getPhone();
Tyler Gunnbaee2952014-09-10 16:01:02 -07001102 }
1103
Tyler Gunnbaee2952014-09-10 16:01:02 -07001104 @Override
1105 protected void onResume() {
1106 super.onResume();
1107 mForeground = true;
1108
1109 PreferenceScreen preferenceScreen = getPreferenceScreen();
1110 if (preferenceScreen != null) {
1111 preferenceScreen.removeAll();
1112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001113
1114 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -07001115
Andrew Lee6fee2cb2014-12-09 16:42:18 -08001116 TelecomManager telecomManager = TelecomManager.from(this);
1117 TelephonyManager telephonyManager =
1118 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1119
1120 Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
1121 if (telephonyManager.isMultiSimEnabled() || (telecomManager.getSimCallManagers().isEmpty()
1122 && !SipUtil.isVoipSupported(mPhone.getContext()))) {
1123 getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
1124 }
Andrew Leedb2fe562014-09-03 15:40:43 -07001125
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001126 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee64a7d792014-10-15 17:38:38 -07001127 mSubMenuVoicemailSettings = (EditPhoneNumberPreference) findPreference(BUTTON_VOICEMAIL_KEY);
1128 mSubMenuVoicemailSettings.setParentActivity(this, VOICEMAIL_PREF_ID, this);
1129 mSubMenuVoicemailSettings.setDialogOnClosedListener(this);
1130 mSubMenuVoicemailSettings.setDialogTitle(R.string.voicemail_settings_number_label);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001131
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001132 mButtonAutoRetry = (CheckBoxPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee2170a972014-08-13 18:13:01 -07001133
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001134 mVoicemailProviders = (VoicemailProviderListPreference) findPreference(
1135 BUTTON_VOICEMAIL_PROVIDER_KEY);
1136 mVoicemailProviders.init(mPhone, getIntent());
Andrew Lee2c027892014-10-29 11:29:54 -07001137 mVoicemailProviders.setOnPreferenceChangeListener(this);
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001138 mPreviousVMProviderKey = mVoicemailProviders.getValue();
Andrew Lee8d66d812014-11-24 14:54:02 -08001139
Andrew Lee2c027892014-10-29 11:29:54 -07001140 mVoicemailSettingsScreen =
1141 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001142 mVoicemailSettings = (PreferenceScreen) findPreference(BUTTON_VOICEMAIL_SETTING_KEY);
Andrew Lee8d66d812014-11-24 14:54:02 -08001143
Andrew Lee1ec7c7e2014-12-03 15:33:21 -08001144 mVoicemailNotificationRingtone = (VoicemailRingtonePreference) findPreference(
1145 getResources().getString(R.string.voicemail_notification_ringtone_key));
1146 mVoicemailNotificationRingtone.init(mPhone);
1147
Andrew Lee8d66d812014-11-24 14:54:02 -08001148 mVoicemailNotificationVibrate = (CheckBoxPreference) findPreference(
1149 getResources().getString(R.string.voicemail_notification_vibrate_key));
1150 mVoicemailNotificationVibrate.setOnPreferenceChangeListener(this);
1151
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001152 updateVMPreferenceWidgets(mVoicemailProviders.getValue());
1153
1154 mEnableVideoCalling = (CheckBoxPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001155
Andrew Lee64a7d792014-10-15 17:38:38 -07001156 if (getResources().getBoolean(R.bool.auto_retry_enabled)) {
1157 mButtonAutoRetry.setOnPreferenceChangeListener(this);
1158 int autoretry = Settings.Global.getInt(
1159 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
1160 mButtonAutoRetry.setChecked(autoretry != 0);
1161 } else {
1162 prefSet.removePreference(mButtonAutoRetry);
1163 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001164 }
1165
Andrew Lee9431b832015-03-09 18:46:45 -07001166 if (!PhoneGlobals.getInstance().phoneMgr.isWorldPhone()) {
Andrew Lee2b36ba22014-11-05 17:08:49 -08001167 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
1168 prefSet.removePreference(cdmaOptions);
1169
1170 // TODO: Support MSIM for this preference option.
1171 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
1172 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001173
1174 int phoneType = mPhone.getPhoneType();
Andrew Lee5ed870c2014-10-29 11:47:49 -07001175 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
Junda Liua09d6962014-11-12 13:39:02 -08001176 boolean shouldHideCarrierSettings = Settings.Global.getInt(
1177 getContentResolver(), Settings.Global.HIDE_CARRIER_NETWORK_SETTINGS, 0) == 1;
1178 if (shouldHideCarrierSettings) {
Andrew Lee5ed870c2014-10-29 11:47:49 -07001179 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001180 } else {
Junda Liua09d6962014-11-12 13:39:02 -08001181 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
1182 prefSet.removePreference(fdnButton);
1183
1184 if (!getResources().getBoolean(R.bool.config_voice_privacy_disable)) {
1185 addPreferencesFromResource(R.xml.cdma_call_privacy);
1186 }
1187 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Andrew Leedd4f6df2014-12-09 19:13:51 -08001188 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Junda Liua09d6962014-11-12 13:39:02 -08001189
1190 if (getResources().getBoolean(R.bool.config_additional_call_setting)) {
1191 addPreferencesFromResource(R.xml.gsm_umts_call_options);
1192
1193 Preference callForwardingPref = prefSet.findPreference(CALL_FORWARDING_KEY);
1194 callForwardingPref.setIntent(mSubscriptionInfoHelper.getIntent(
Andrew Leedd4f6df2014-12-09 19:13:51 -08001195 GsmUmtsCallForwardOptions.class));
Junda Liua09d6962014-11-12 13:39:02 -08001196
1197 Preference additionalGsmSettingsPref =
1198 prefSet.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
1199 additionalGsmSettingsPref.setIntent(mSubscriptionInfoHelper.getIntent(
Andrew Leedd4f6df2014-12-09 19:13:51 -08001200 GsmUmtsAdditionalCallOptions.class));
Junda Liua09d6962014-11-12 13:39:02 -08001201 }
1202 } else {
1203 throw new IllegalStateException("Unexpected phone type: " + phoneType);
1204 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001205 }
1206 }
1207
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001208 // check the intent that started this activity and pop up the voicemail
1209 // dialog if we've been asked to.
1210 // If we have at least one non default VM provider registered then bring up
1211 // the selection for the VM provider, otherwise bring up a VM number dialog.
1212 // We only bring up the dialog the first time we are called (not after orientation change)
Andrew Lee2c027892014-10-29 11:29:54 -07001213 if (mShowVoicemailPreference) {
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001214 if (DBG) log("ACTION_ADD_VOICEMAIL Intent is thrown");
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001215 if (mSetupVoicemail) {
1216 simulatePreferenceClick(mVoicemailSettingsScreen);
1217 mSetupVoicemail = false;
1218 } else if (mVoicemailProviders.hasMoreThanOneVoicemailProvider()) {
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001219 if (DBG) log("Voicemail data has more than one provider.");
Tyler Gunnbaee2952014-09-10 16:01:02 -07001220 simulatePreferenceClick(mVoicemailProviders);
1221 } else {
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001222 onPreferenceChange(mVoicemailProviders, VoicemailProviderListPreference.DEFAULT_KEY);
1223 mVoicemailProviders.setValue(VoicemailProviderListPreference.DEFAULT_KEY);
Tyler Gunnbaee2952014-09-10 16:01:02 -07001224 }
1225 mShowVoicemailPreference = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001226 }
Tyler Gunnbaee2952014-09-10 16:01:02 -07001227
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228 updateVoiceNumberField();
1229 mVMProviderSettingsForced = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001230
Andrew Lee8d66d812014-11-24 14:54:02 -08001231 mVoicemailNotificationVibrate.setChecked(
Andrew Lee1ec7c7e2014-12-03 15:33:21 -08001232 VoicemailNotificationSettingsUtil.isVibrationEnabled(mPhone));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001233
Andrew Lee312e8172014-10-23 17:01:36 -07001234 if (ImsManager.isVtEnabledByPlatform(mPhone.getContext()) && ENABLE_VT_FLAG) {
1235 boolean currentValue =
1236 ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
1237 ? PhoneGlobals.getInstance().phoneMgr.isVideoCallingEnabled() : false;
1238 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -07001239 mEnableVideoCalling.setOnPreferenceChangeListener(this);
1240 } else {
1241 prefSet.removePreference(mEnableVideoCalling);
1242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001243 }
1244
Andrew Lee785ca2a2014-12-18 12:46:41 -08001245 @Override
1246 protected void onNewIntent(Intent newIntent) {
1247 setIntent(newIntent);
1248
1249 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
1250 mSubscriptionInfoHelper.setActionBarTitle(
1251 getActionBar(), getResources(), R.string.call_settings_with_label);
1252 mPhone = mSubscriptionInfoHelper.getPhone();
1253 }
1254
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001255 private static void log(String msg) {
1256 Log.d(LOG_TAG, msg);
1257 }
1258
1259 /**
1260 * Updates the look of the VM preference widgets based on current VM provider settings.
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001261 * Note that the provider name is loaded fxrorm the found activity via loadLabel in
1262 * {@link VoicemailProviderListPreference#initVoiceMailProviders()} in order for it to be
1263 * localizable.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 */
1265 private void updateVMPreferenceWidgets(String currentProviderSetting) {
1266 final String key = currentProviderSetting;
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001267 final VoicemailProvider provider = mVoicemailProviders.getVoicemailProvider(key);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001268
1269 /* This is the case when we are coming up on a freshly wiped phone and there is no
1270 persisted value for the list preference mVoicemailProviders.
1271 In this case we want to show the UI asking the user to select a voicemail provider as
1272 opposed to silently falling back to default one. */
1273 if (provider == null) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -08001274 if (DBG) log("updateVMPreferenceWidget: key: " + key + " -> null.");
1275
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276 mVoicemailProviders.setSummary(getString(R.string.sum_voicemail_choose_provider));
1277 mVoicemailSettings.setEnabled(false);
1278 mVoicemailSettings.setIntent(null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001279 mVoicemailNotificationVibrate.setEnabled(false);
1280 } else {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -08001281 if (DBG) log("updateVMPreferenceWidget: key: " + key + " -> " + provider.toString());
1282
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 final String providerName = provider.name;
1284 mVoicemailProviders.setSummary(providerName);
1285 mVoicemailSettings.setEnabled(true);
1286 mVoicemailSettings.setIntent(provider.intent);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001287 mVoicemailNotificationVibrate.setEnabled(true);
1288 }
1289 }
1290
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001291
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001292 /**
1293 * Simulates user clicking on a passed preference.
1294 * Usually needed when the preference is a dialog preference and we want to invoke
1295 * a dialog for this preference programmatically.
Santos Cordonda120f42014-08-06 04:44:34 -07001296 * TODO: figure out if there is a cleaner way to cause preference dlg to come up
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001297 */
1298 private void simulatePreferenceClick(Preference preference) {
1299 // Go through settings until we find our setting
1300 // and then simulate a click on it to bring up the dialog
1301 final ListAdapter adapter = getPreferenceScreen().getRootAdapter();
1302 for (int idx = 0; idx < adapter.getCount(); idx++) {
1303 if (adapter.getItem(idx) == preference) {
1304 getPreferenceScreen().onItemClick(this.getListView(),
1305 null, idx, adapter.getItemId(idx));
1306 break;
1307 }
1308 }
1309 }
1310
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 @Override
1312 public boolean onOptionsItemSelected(MenuItem item) {
1313 final int itemId = item.getItemId();
1314 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -07001315 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 return true;
1317 }
1318 return super.onOptionsItemSelected(item);
1319 }
Andrew Lee8d66d812014-11-24 14:54:02 -08001320
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001321 /**
1322 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
1323 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
1324 */
Andrew Lee5efb1122014-12-05 04:20:42 -08001325 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -08001326 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
1327 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 intent.setAction(Intent.ACTION_MAIN);
1329 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
1330 activity.startActivity(intent);
1331 activity.finish();
1332 }
1333}