blob: f2fcb4937bf0811a0978680e25da69202446a17c [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 Leeeffef9c2015-02-19 16:02:37 -080050import com.android.ims.ImsConfig;
Andrew Lee312e8172014-10-23 17:01:36 -070051import com.android.ims.ImsManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import com.android.internal.telephony.CallForwardInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import com.android.internal.telephony.Phone;
54import com.android.internal.telephony.PhoneConstants;
Andrew Lee2170a972014-08-13 18:13:01 -070055import com.android.phone.common.util.SettingsUtil;
Andrew Leedb2fe562014-09-03 15:40:43 -070056import com.android.phone.settings.AccountSelectionPreference;
Andrew Lee1af6cf72014-11-04 17:35:26 -080057import com.android.phone.settings.CallForwardInfoUtil;
Andrew Leefb7f92e2015-02-26 16:23:32 -080058import com.android.phone.settings.SettingsConstants;
Andrew Lee84024342014-11-06 23:37:09 -080059import com.android.phone.settings.VoicemailDialogUtil;
Andrew Lee1ec7c7e2014-12-03 15:33:21 -080060import com.android.phone.settings.VoicemailNotificationSettingsUtil;
Andrew Lee64e5c9d2014-11-26 12:00:10 -080061import com.android.phone.settings.VoicemailProviderListPreference;
62import com.android.phone.settings.VoicemailProviderListPreference.VoicemailProvider;
Andrew Leeb490d732014-10-27 15:00:41 -070063import com.android.phone.settings.VoicemailProviderSettings;
Andrew Lee88b51e22014-10-29 15:48:51 -070064import com.android.phone.settings.VoicemailProviderSettingsUtil;
Andrew Lee1ec7c7e2014-12-03 15:33:21 -080065import com.android.phone.settings.VoicemailRingtonePreference;
Andrew Lee5ed870c2014-10-29 11:47:49 -070066import com.android.phone.settings.fdn.FdnSetting;
Sailesh Nepal788959e2014-07-08 23:36:40 -070067import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068
Andrew Lee2170a972014-08-13 18:13:01 -070069import java.lang.String;
Andrew Leef1776d82014-11-04 14:45:02 -080070import java.util.ArrayList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import java.util.Collection;
72import java.util.HashMap;
73import java.util.HashSet;
74import java.util.Iterator;
75import java.util.List;
76import java.util.Map;
77
78/**
79 * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
80 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070081 * This preference screen is the root of the "Call settings" hierarchy available from the Phone
82 * app; the settings here let you control various features related to phone calls (including
83 * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
84 * voice-capable phone devices.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085 *
86 * Note that this activity is part of the package com.android.phone, even
87 * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
88 * is from the package com.android.contacts.
89 *
90 * For the "Mobile network settings" screen under the main Settings app,
91 * See {@link MobileNetworkSettings}.
92 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070093 * TODO: Settings should be split into PreferenceFragments where possible (ie. voicemail).
Andrew Lee2170a972014-08-13 18:13:01 -070094 *
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095 * @see com.android.phone.MobileNetworkSettings
96 */
97public class CallFeaturesSetting extends PreferenceActivity
98 implements DialogInterface.OnClickListener,
Andrew Lee2170a972014-08-13 18:13:01 -070099 Preference.OnPreferenceChangeListener,
Andrew Lee2170a972014-08-13 18:13:01 -0700100 EditPhoneNumberPreference.OnDialogClosedListener,
Andrew Leece8ae2a2014-09-10 10:41:48 -0700101 EditPhoneNumberPreference.GetDefaultNumberListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102 private static final String LOG_TAG = "CallFeaturesSetting";
103 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
Andrew Lee77527ac2014-10-21 16:57:39 -0700104 // STOPSHIP if true. Flag to override behavior default behavior to hide VT setting.
105 private static final boolean ENABLE_VT_FLAG = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106
107 /**
108 * Intent action to bring up Voicemail Provider settings.
109 *
110 * @see #IGNORE_PROVIDER_EXTRA
111 */
112 public static final String ACTION_ADD_VOICEMAIL =
113 "com.android.phone.CallFeaturesSetting.ADD_VOICEMAIL";
114 // intent action sent by this activity to a voice mail provider
115 // to trigger its configuration UI
116 public static final String ACTION_CONFIGURE_VOICEMAIL =
117 "com.android.phone.CallFeaturesSetting.CONFIGURE_VOICEMAIL";
118 // Extra put in the return from VM provider config containing voicemail number to set
119 public static final String VM_NUMBER_EXTRA = "com.android.phone.VoicemailNumber";
120 // Extra put in the return from VM provider config containing call forwarding number to set
121 public static final String FWD_NUMBER_EXTRA = "com.android.phone.ForwardingNumber";
122 // Extra put in the return from VM provider config containing call forwarding number to set
123 public static final String FWD_NUMBER_TIME_EXTRA = "com.android.phone.ForwardingNumberTime";
124 // If the VM provider returns non null value in this extra we will force the user to
125 // choose another VM provider
126 public static final String SIGNOUT_EXTRA = "com.android.phone.Signout";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128 /**
129 * String Extra put into ACTION_ADD_VOICEMAIL call to indicate which provider should be hidden
130 * in the list of providers presented to the user. This allows a provider which is being
131 * disabled (e.g. GV user logging out) to force the user to pick some other provider.
132 */
133 public static final String IGNORE_PROVIDER_EXTRA = "com.android.phone.ProviderToIgnore";
134
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800135 /**
136 * String Extra put into ACTION_ADD_VOICEMAIL to indicate that the voicemail setup screen should
137 * be opened.
138 */
139 public static final String SETUP_VOICEMAIL_EXTRA = "com.android.phone.SetupVoicemail";
140
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141 // string constants
142 private static final String NUM_PROJECTION[] = {CommonDataKinds.Phone.NUMBER};
143
144 // String keys for preference lookup
145 // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
Andrew Lee8d66d812014-11-24 14:54:02 -0800146 // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
147 // in the layout files. These strings need to be treated carefully; if the setting is
148 // persistent, they are used as the key to store shared preferences and the name should not be
149 // changed unless the settings are also migrated.
Andrew Lee97708a42014-09-25 12:39:07 -0700150 private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151 private static final String BUTTON_VOICEMAIL_KEY = "button_voicemail_key";
152 private static final String BUTTON_VOICEMAIL_PROVIDER_KEY = "button_voicemail_provider_key";
153 private static final String BUTTON_VOICEMAIL_SETTING_KEY = "button_voicemail_setting_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154 private static final String BUTTON_FDN_KEY = "button_fdn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156 private static final String BUTTON_RETRY_KEY = "button_auto_retry_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157
158 private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
159 private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
Andrew Lee2b36ba22014-11-05 17:08:49 -0800160 private static final String CALL_FORWARDING_KEY = "call_forwarding_key";
161 private static final String ADDITIONAL_GSM_SETTINGS_KEY = "additional_gsm_call_settings_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162
Andrew Leece8ae2a2014-09-10 10:41:48 -0700163 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
164 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -0700165
Andrew Leedf14ead2014-10-17 14:22:52 -0700166 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
167
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168 /** Event for Async voicemail change call */
169 private static final int EVENT_VOICEMAIL_CHANGED = 500;
170 private static final int EVENT_FORWARDING_CHANGED = 501;
171 private static final int EVENT_FORWARDING_GET_COMPLETED = 502;
172
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173 /** Handle to voicemail pref */
174 private static final int VOICEMAIL_PREF_ID = 1;
175 private static final int VOICEMAIL_PROVIDER_CFG_ID = 2;
176
177 private Phone mPhone;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178
Andrew Lee5ed870c2014-10-29 11:47:49 -0700179 private SubscriptionInfoHelper mSubscriptionInfoHelper;
180
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181 private EditPhoneNumberPreference mSubMenuVoicemailSettings;
182
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700183 private CheckBoxPreference mButtonAutoRetry;
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800184 private VoicemailProviderListPreference mVoicemailProviders;
Andrew Lee97708a42014-09-25 12:39:07 -0700185 private PreferenceScreen mVoicemailSettingsScreen;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186 private PreferenceScreen mVoicemailSettings;
Andrew Lee1ec7c7e2014-12-03 15:33:21 -0800187 private VoicemailRingtonePreference mVoicemailNotificationRingtone;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188 private CheckBoxPreference mVoicemailNotificationVibrate;
Andrew Leedf14ead2014-10-17 14:22:52 -0700189 private CheckBoxPreference mEnableVideoCalling;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191 /**
192 * Results of reading forwarding settings
193 */
194 private CallForwardInfo[] mForwardingReadResults = null;
195
196 /**
197 * Result of forwarding number change.
198 * Keys are reasons (eg. unconditional forwarding).
199 */
200 private Map<Integer, AsyncResult> mForwardingChangeResults = null;
201
202 /**
203 * Expected CF read result types.
204 * This set keeps track of the CF types for which we've issued change
205 * commands so we can tell when we've received all of the responses.
206 */
207 private Collection<Integer> mExpectedChangeResultReasons = null;
208
209 /**
210 * Result of vm number change
211 */
212 private AsyncResult mVoicemailChangeResult = null;
213
214 /**
215 * Previous VM provider setting so we can return to it in case of failure.
216 */
217 private String mPreviousVMProviderKey = null;
218
219 /**
220 * Id of the dialog being currently shown.
221 */
222 private int mCurrentDialogId = 0;
223
224 /**
225 * Flag indicating that we are invoking settings for the voicemail provider programmatically
226 * due to vm provider change.
227 */
228 private boolean mVMProviderSettingsForced = false;
229
230 /**
231 * Flag indicating that we are making changes to vm or fwd numbers
232 * due to vm provider change.
233 */
234 private boolean mChangingVMorFwdDueToProviderChange = false;
235
236 /**
237 * True if we are in the process of vm & fwd number change and vm has already been changed.
238 * This is used to decide what to do in case of rollback.
239 */
240 private boolean mVMChangeCompletedSuccessfully = false;
241
242 /**
243 * True if we had full or partial failure setting forwarding numbers and so need to roll them
244 * back.
245 */
246 private boolean mFwdChangesRequireRollback = false;
247
248 /**
249 * Id of error msg to display to user once we are done reverting the VM provider to the previous
250 * one.
251 */
252 private int mVMOrFwdSetError = 0;
253
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254 /** string to hold old voicemail number as it is being updated. */
255 private String mOldVmNumber;
256
257 // New call forwarding settings and vm number we will be setting
258 // Need to save these since before we get to saving we need to asynchronously
259 // query the existing forwarding settings.
260 private CallForwardInfo[] mNewFwdSettings;
261 private String mNewVMNumber;
262
263 private boolean mForeground;
264
265 @Override
266 public void onPause() {
267 super.onPause();
268 mForeground = false;
269 }
270
271 /**
272 * We have to pull current settings from the network for all kinds of
273 * voicemail providers so we can tell whether we have to update them,
274 * so use this bit to keep track of whether we're reading settings for the
275 * default provider and should therefore save them out when done.
276 */
277 private boolean mReadingSettingsForDefaultProvider = false;
278
Tyler Gunnbaee2952014-09-10 16:01:02 -0700279 /**
280 * Used to indicate that the voicemail preference should be shown.
281 */
282 private boolean mShowVoicemailPreference = false;
283
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800284 /**
285 * Used to indicate that the voicemail setup screen should be shown.
286 */
287 private boolean mSetupVoicemail = false;
288
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289 /*
290 * Click Listeners, handle click based on objects attached to UI.
291 */
292
293 // Click listener for all toggle events
294 @Override
295 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
296 if (preference == mSubMenuVoicemailSettings) {
297 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298 } else if (preference == mButtonAutoRetry) {
299 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
300 android.provider.Settings.Global.CALL_AUTO_RETRY,
301 mButtonAutoRetry.isChecked() ? 1 : 0);
302 return true;
Andrew Lee696bff52014-12-03 17:58:18 -0800303 } else if (preference.getKey().equals(mVoicemailSettings.getKey())) {
304 // Check key instead of comparing reference because closing the voicemail notification
305 // ringtone dialog invokes onResume(), but leaves the old preference screen up,
306 // TODO: Revert to checking reference after migrating voicemail to its own activity.
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800307 if (DBG) log("onPreferenceTreeClick: Voicemail Settings Preference is clicked.");
308
Andrew Lee696bff52014-12-03 17:58:18 -0800309 final Dialog dialog = ((PreferenceScreen) preference).getDialog();
Yorke Leea0f63bf2014-10-09 18:27:20 -0700310 if (dialog != null) {
311 dialog.getActionBar().setDisplayHomeAsUpEnabled(false);
312 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800313
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700314 if (preference.getIntent() != null) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800315 if (DBG) log("Invoking cfg intent " + preference.getIntent().getPackage());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316
317 // onActivityResult() will be responsible for resetting some of variables.
318 this.startActivityForResult(preference.getIntent(), VOICEMAIL_PROVIDER_CFG_ID);
319 return true;
320 } else {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800321 if (DBG) log("onPreferenceTreeClick(). No intent; use default behavior in xml.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800323 // onActivityResult() will not be called, so reset variables here.
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800324 mPreviousVMProviderKey = VoicemailProviderListPreference.DEFAULT_KEY;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325 mVMProviderSettingsForced = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326 return false;
327 }
Andrew Lee97708a42014-09-25 12:39:07 -0700328 } else if (preference == mVoicemailSettingsScreen) {
Yorke Leea0f63bf2014-10-09 18:27:20 -0700329 final Dialog dialog = mVoicemailSettingsScreen.getDialog();
330 if (dialog != null) {
331 dialog.getActionBar().setDisplayHomeAsUpEnabled(false);
332 }
Andrew Lee97708a42014-09-25 12:39:07 -0700333 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334 }
335 return false;
336 }
337
338 /**
339 * Implemented to support onPreferenceChangeListener to look for preference
340 * changes.
341 *
342 * @param preference is the preference to be changed
343 * @param objValue should be the value of the selection, NOT its localized
344 * display value.
345 */
346 @Override
347 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800348 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700349
Andrew Leea1239f22015-03-02 17:44:07 -0800350 if (preference == mVoicemailProviders) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 final String newProviderKey = (String) objValue;
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800352
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353 // If previous provider key and the new one is same, we don't need to handle it.
354 if (mPreviousVMProviderKey.equals(newProviderKey)) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800355 if (DBG) log("No change is made to the VM provider setting.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 return true;
357 }
358 updateVMPreferenceWidgets(newProviderKey);
359
Andrew Leeb490d732014-10-27 15:00:41 -0700360 final VoicemailProviderSettings newProviderSettings =
Andrew Lee6950c6c2014-11-26 12:05:42 -0800361 VoicemailProviderSettingsUtil.load(this, newProviderKey);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362
Andrew Lee88b51e22014-10-29 15:48:51 -0700363 // If the user switches to a voice mail provider and we have numbers stored for it we
364 // will automatically change the phone's voice mail and forwarding number to the stored
365 // ones. Otherwise we will bring up provider's configuration UI.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 if (newProviderSettings == null) {
367 // Force the user into a configuration of the chosen provider
368 Log.w(LOG_TAG, "Saved preferences not found - invoking config");
369 mVMProviderSettingsForced = true;
370 simulatePreferenceClick(mVoicemailSettings);
371 } else {
372 if (DBG) log("Saved preferences found - switching to them");
373 // Set this flag so if we get a failure we revert to previous provider
374 mChangingVMorFwdDueToProviderChange = true;
375 saveVoiceMailAndForwardingNumber(newProviderKey, newProviderSettings);
376 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800377 } else if (preference.getKey().equals(mVoicemailNotificationVibrate.getKey())) {
Andrew Lee696bff52014-12-03 17:58:18 -0800378 // Check key instead of comparing reference because closing the voicemail notification
379 // ringtone dialog invokes onResume(), but leaves the old preference screen up,
380 // TODO: Revert to checking reference after migrating voicemail to its own activity.
Andrew Lee8d66d812014-11-24 14:54:02 -0800381 VoicemailNotificationSettingsUtil.setVibrationEnabled(
Andrew Lee1ec7c7e2014-12-03 15:33:21 -0800382 mPhone, Boolean.TRUE.equals(objValue));
Andrew Leedf14ead2014-10-17 14:22:52 -0700383 } else if (preference == mEnableVideoCalling) {
Andrew Lee312e8172014-10-23 17:01:36 -0700384 if (ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())) {
385 PhoneGlobals.getInstance().phoneMgr.enableVideoCalling((boolean) objValue);
386 } else {
387 AlertDialog.Builder builder = new AlertDialog.Builder(this);
388 DialogInterface.OnClickListener networkSettingsClickListener =
389 new Dialog.OnClickListener() {
390 @Override
391 public void onClick(DialogInterface dialog, int which) {
392 startActivity(new Intent(mPhone.getContext(),
393 com.android.phone.MobileNetworkSettings.class));
394 }
395 };
396 builder.setMessage(getResources().getString(
397 R.string.enable_video_calling_dialog_msg))
398 .setNeutralButton(getResources().getString(
399 R.string.enable_video_calling_dialog_settings),
400 networkSettingsClickListener)
401 .setPositiveButton(android.R.string.ok, null)
402 .show();
403 return false;
404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800406
407 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 return true;
409 }
410
411 @Override
412 public void onDialogClosed(EditPhoneNumberPreference preference, int buttonClicked) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800413 if (DBG) log("onDialogClosed: Button clicked is " + buttonClicked);
414
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 if (buttonClicked == DialogInterface.BUTTON_NEGATIVE) {
416 return;
417 }
418
419 if (preference == mSubMenuVoicemailSettings) {
Andrew Leee438b312014-10-29 16:59:15 -0700420 VoicemailProviderSettings newSettings = new VoicemailProviderSettings(
421 mSubMenuVoicemailSettings.getPhoneNumber(),
422 VoicemailProviderSettings.NO_FORWARDING);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800423 saveVoiceMailAndForwardingNumber(mVoicemailProviders.getKey(), newSettings);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 }
425 }
426
427 /**
428 * Implemented for EditPhoneNumberPreference.GetDefaultNumberListener.
429 * This method set the default values for the various
430 * EditPhoneNumberPreference dialogs.
431 */
432 @Override
433 public String onGetDefaultNumber(EditPhoneNumberPreference preference) {
434 if (preference == mSubMenuVoicemailSettings) {
435 // update the voicemail number field, which takes care of the
436 // mSubMenuVoicemailSettings itself, so we should return null.
437 if (DBG) log("updating default for voicemail dialog");
438 updateVoiceNumberField();
439 return null;
440 }
441
442 String vmDisplay = mPhone.getVoiceMailNumber();
443 if (TextUtils.isEmpty(vmDisplay)) {
444 // if there is no voicemail number, we just return null to
445 // indicate no contribution.
446 return null;
447 }
448
449 // Return the voicemail number prepended with "VM: "
450 if (DBG) log("updating default for call forwarding dialogs");
451 return getString(R.string.voicemail_abbreviated) + " " + vmDisplay;
452 }
453
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454 private void switchToPreviousVoicemailProvider() {
455 if (DBG) log("switchToPreviousVoicemailProvider " + mPreviousVMProviderKey);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800457 if (mPreviousVMProviderKey == null) {
458 return;
459 }
460
461 if (mVMChangeCompletedSuccessfully || mFwdChangesRequireRollback) {
Andrew Lee84024342014-11-06 23:37:09 -0800462 showDialogIfForeground(VoicemailDialogUtil.VM_REVERTING_DIALOG);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800463 final VoicemailProviderSettings prevSettings =
Andrew Lee6950c6c2014-11-26 12:05:42 -0800464 VoicemailProviderSettingsUtil.load(this, mPreviousVMProviderKey);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800465 if (prevSettings == null) {
466 Log.e(LOG_TAG, "VoicemailProviderSettings for the key \""
467 + mPreviousVMProviderKey + "\" is null but should be loaded.");
468 }
469
470 if (mVMChangeCompletedSuccessfully) {
471 mNewVMNumber = prevSettings.getVoicemailNumber();
472 Log.i(LOG_TAG, "VM change is already completed successfully."
473 + "Have to revert VM back to " + mNewVMNumber + " again.");
474 mPhone.setVoiceMailNumber(
475 mPhone.getVoiceMailAlphaTag().toString(),
476 mNewVMNumber,
477 Message.obtain(mRevertOptionComplete, EVENT_VOICEMAIL_CHANGED));
478 }
479
480 if (mFwdChangesRequireRollback) {
481 Log.i(LOG_TAG, "Requested to rollback forwarding changes.");
482
483 final CallForwardInfo[] prevFwdSettings = prevSettings.getForwardingSettings();
484 if (prevFwdSettings != null) {
485 Map<Integer, AsyncResult> results = mForwardingChangeResults;
486 resetForwardingChangeState();
487 for (int i = 0; i < prevFwdSettings.length; i++) {
488 CallForwardInfo fi = prevFwdSettings[i];
489 if (DBG) log("Reverting fwd #: " + i + ": " + fi.toString());
490 // Only revert the settings for which the update succeeded.
491 AsyncResult result = results.get(fi.reason);
492 if (result != null && result.exception == null) {
493 mExpectedChangeResultReasons.add(fi.reason);
494 CallForwardInfoUtil.setCallForwardingOption(mPhone, fi,
495 mRevertOptionComplete.obtainMessage(
496 EVENT_FORWARDING_CHANGED, i, 0));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700497 }
498 }
499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700500 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800501 } else {
502 if (DBG) log("No need to revert");
503 onRevertDone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504 }
505 }
506
507 private void onRevertDone() {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800508 if (DBG) log("onRevertDone: Changing provider key back to " + mPreviousVMProviderKey);
509
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510 updateVMPreferenceWidgets(mPreviousVMProviderKey);
511 updateVoiceNumberField();
512 if (mVMOrFwdSetError != 0) {
Andrew Leeab082272014-11-04 15:50:42 -0800513 showDialogIfForeground(mVMOrFwdSetError);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700514 mVMOrFwdSetError = 0;
515 }
516 }
517
518 @Override
519 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
520 if (DBG) {
521 log("onActivityResult: requestCode: " + requestCode
522 + ", resultCode: " + resultCode
523 + ", data: " + data);
524 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800525
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700526 // there are cases where the contact picker may end up sending us more than one
527 // request. We want to ignore the request if we're not in the correct state.
528 if (requestCode == VOICEMAIL_PROVIDER_CFG_ID) {
529 boolean failure = false;
530
531 // No matter how the processing of result goes lets clear the flag
532 if (DBG) log("mVMProviderSettingsForced: " + mVMProviderSettingsForced);
533 final boolean isVMProviderSettingsForced = mVMProviderSettingsForced;
534 mVMProviderSettingsForced = false;
535
536 String vmNum = null;
537 if (resultCode != RESULT_OK) {
538 if (DBG) log("onActivityResult: vm provider cfg result not OK.");
539 failure = true;
540 } else {
541 if (data == null) {
542 if (DBG) log("onActivityResult: vm provider cfg result has no data");
543 failure = true;
544 } else {
545 if (data.getBooleanExtra(SIGNOUT_EXTRA, false)) {
546 if (DBG) log("Provider requested signout");
547 if (isVMProviderSettingsForced) {
548 if (DBG) log("Going back to previous provider on signout");
549 switchToPreviousVoicemailProvider();
550 } else {
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800551 final String victim = mVoicemailProviders.getKey();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552 if (DBG) log("Relaunching activity and ignoring " + victim);
553 Intent i = new Intent(ACTION_ADD_VOICEMAIL);
554 i.putExtra(IGNORE_PROVIDER_EXTRA, victim);
555 i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
556 this.startActivity(i);
557 }
558 return;
559 }
560 vmNum = data.getStringExtra(VM_NUMBER_EXTRA);
561 if (vmNum == null || vmNum.length() == 0) {
562 if (DBG) log("onActivityResult: vm provider cfg result has no vmnum");
563 failure = true;
564 }
565 }
566 }
567 if (failure) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800568 if (DBG) log("Failure in return from voicemail provider.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700569 if (isVMProviderSettingsForced) {
570 switchToPreviousVoicemailProvider();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800572
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700573 return;
574 }
575 mChangingVMorFwdDueToProviderChange = isVMProviderSettingsForced;
576 final String fwdNum = data.getStringExtra(FWD_NUMBER_EXTRA);
577
Santos Cordonda120f42014-08-06 04:44:34 -0700578 // TODO: It would be nice to load the current network setting for this and
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700579 // send it to the provider when it's config is invoked so it can use this as default
580 final int fwdNumTime = data.getIntExtra(FWD_NUMBER_TIME_EXTRA, 20);
581
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800582 if (DBG) log("onActivityResult: cfg result has forwarding number " + fwdNum);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800583 saveVoiceMailAndForwardingNumber(mVoicemailProviders.getKey(),
Andrew Leeb490d732014-10-27 15:00:41 -0700584 new VoicemailProviderSettings(vmNum, fwdNum, fwdNumTime));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700585 return;
586 }
587
588 if (requestCode == VOICEMAIL_PREF_ID) {
589 if (resultCode != RESULT_OK) {
590 if (DBG) log("onActivityResult: contact picker result not OK.");
591 return;
592 }
593
594 Cursor cursor = null;
595 try {
596 cursor = getContentResolver().query(data.getData(),
597 NUM_PROJECTION, null, null, null);
598 if ((cursor == null) || (!cursor.moveToFirst())) {
599 if (DBG) log("onActivityResult: bad contact data, no results found.");
600 return;
601 }
602 mSubMenuVoicemailSettings.onPickActivityResult(cursor.getString(0));
603 return;
604 } finally {
605 if (cursor != null) {
606 cursor.close();
607 }
608 }
609 }
610
611 super.onActivityResult(requestCode, resultCode, data);
612 }
613
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700614 /**
615 * Wrapper around showDialog() that will silently do nothing if we're
616 * not in the foreground.
617 *
618 * This is useful here because most of the dialogs we display from
619 * this class are triggered by asynchronous events (like
620 * success/failure messages from the telephony layer) and it's
621 * possible for those events to come in even after the user has gone
622 * to a different screen.
623 */
624 // TODO: this is too brittle: it's still easy to accidentally add new
625 // code here that calls showDialog() directly (which will result in a
626 // WindowManager$BadTokenException if called after the activity has
627 // been stopped.)
628 //
629 // It would be cleaner to do the "if (mForeground)" check in one
630 // central place, maybe by using a single Handler for all asynchronous
631 // events (and have *that* discard events if we're not in the
632 // foreground.)
633 //
634 // Unfortunately it's not that simple, since we sometimes need to do
635 // actual work to handle these events whether or not we're in the
636 // foreground (see the Handler code in mSetOptionComplete for
637 // example.)
Andrew Leeab082272014-11-04 15:50:42 -0800638 //
639 // TODO: It's a bit worrisome that we don't do anything in error cases when we're not in the
640 // foreground. Consider displaying a toast instead.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700641 private void showDialogIfForeground(int id) {
642 if (mForeground) {
643 showDialog(id);
644 }
645 }
646
647 private void dismissDialogSafely(int id) {
648 try {
649 dismissDialog(id);
650 } catch (IllegalArgumentException e) {
651 // This is expected in the case where we were in the background
652 // at the time we would normally have shown the dialog, so we didn't
653 // show it.
654 }
655 }
656
Andrew Lee299e4a72015-01-15 12:44:34 -0800657 /**
658 * TODO: Refactor to make it easier to understand what's done in the different stages.
659 */
Andrew Leeb490d732014-10-27 15:00:41 -0700660 private void saveVoiceMailAndForwardingNumber(
661 String key, VoicemailProviderSettings newSettings) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700662 if (DBG) log("saveVoiceMailAndForwardingNumber: " + newSettings.toString());
Andrew Leeb490d732014-10-27 15:00:41 -0700663 mNewVMNumber = newSettings.getVoicemailNumber();
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800664 mNewVMNumber = (mNewVMNumber == null) ? "" : mNewVMNumber;
Andrew Leeb490d732014-10-27 15:00:41 -0700665 mNewFwdSettings = newSettings.getForwardingSettings();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700666
Andrew Lee299e4a72015-01-15 12:44:34 -0800667 // No fwd settings on CDMA.
668 boolean isCdma = mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA;
669 if (isCdma) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700670 if (DBG) log("ignoring forwarding setting since this is CDMA phone");
Andrew Leeb490d732014-10-27 15:00:41 -0700671 mNewFwdSettings = VoicemailProviderSettings.NO_FORWARDING;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700672 }
673
Andrew Leee3c15212014-10-28 13:12:55 -0700674 // Throw a warning if the voicemail is the same and we did not change forwarding.
Andrew Leeb490d732014-10-27 15:00:41 -0700675 if (mNewVMNumber.equals(mOldVmNumber)
676 && mNewFwdSettings == VoicemailProviderSettings.NO_FORWARDING) {
Andrew Lee84024342014-11-06 23:37:09 -0800677 showDialogIfForeground(VoicemailDialogUtil.VM_NOCHANGE_ERROR_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700678 return;
679 }
680
Andrew Lee6950c6c2014-11-26 12:05:42 -0800681 VoicemailProviderSettingsUtil.save(this, key, newSettings);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700682 mVMChangeCompletedSuccessfully = false;
683 mFwdChangesRequireRollback = false;
684 mVMOrFwdSetError = 0;
Andrew Lee299e4a72015-01-15 12:44:34 -0800685
686 // Don't read call forwarding settings if CDMA. Call forwarding is not supported by CDMA.
Andrew Lee9c822312015-03-13 07:52:08 -0700687 if (isCdma || mNewFwdSettings == VoicemailProviderSettings.NO_FORWARDING) {
688 if (DBG) log("Not touching fwd #");
689 setVoicemailNumberWithCarrier();
690 } else {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700691 mReadingSettingsForDefaultProvider =
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800692 mPreviousVMProviderKey.equals(VoicemailProviderListPreference.DEFAULT_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700693 if (DBG) log("Reading current forwarding settings");
Andrew Leeb490d732014-10-27 15:00:41 -0700694 int numSettingsReasons = VoicemailProviderSettings.FORWARDING_SETTINGS_REASONS.length;
695 mForwardingReadResults = new CallForwardInfo[numSettingsReasons];
696 for (int i = 0; i < mForwardingReadResults.length; i++) {
697 mPhone.getCallForwardingOption(
698 VoicemailProviderSettings.FORWARDING_SETTINGS_REASONS[i],
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700699 mGetOptionComplete.obtainMessage(EVENT_FORWARDING_GET_COMPLETED, i, 0));
700 }
Andrew Lee84024342014-11-06 23:37:09 -0800701 showDialogIfForeground(VoicemailDialogUtil.VM_FWD_READING_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700702 }
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800703
704 // Refresh the MWI indicator if it is already showing.
705 PhoneGlobals.getInstance().refreshMwiIndicator(mSubscriptionInfoHelper.getSubId());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700706 }
707
708 private final Handler mGetOptionComplete = new Handler() {
709 @Override
710 public void handleMessage(Message msg) {
711 AsyncResult result = (AsyncResult) msg.obj;
712 switch (msg.what) {
713 case EVENT_FORWARDING_GET_COMPLETED:
714 handleForwardingSettingsReadResult(result, msg.arg1);
715 break;
716 }
717 }
718 };
719
720 private void handleForwardingSettingsReadResult(AsyncResult ar, int idx) {
721 if (DBG) Log.d(LOG_TAG, "handleForwardingSettingsReadResult: " + idx);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800722
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700723 Throwable error = null;
724 if (ar.exception != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700725 error = ar.exception;
Andrew Lee1af6cf72014-11-04 17:35:26 -0800726 if (DBG) Log.d(LOG_TAG, "FwdRead: ar.exception=" + error.getMessage());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700727 }
728 if (ar.userObj instanceof Throwable) {
Andrew Lee1af6cf72014-11-04 17:35:26 -0800729 error = (Throwable) ar.userObj;
730 if (DBG) Log.d(LOG_TAG, "FwdRead: userObj=" + error.getMessage());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700731 }
732
733 // We may have already gotten an error and decided to ignore the other results.
734 if (mForwardingReadResults == null) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800735 if (DBG) Log.d(LOG_TAG, "Ignoring fwd reading result: " + idx);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700736 return;
737 }
738
739 // In case of error ignore other results, show an error dialog
740 if (error != null) {
741 if (DBG) Log.d(LOG_TAG, "Error discovered for fwd read : " + idx);
742 mForwardingReadResults = null;
Andrew Lee84024342014-11-06 23:37:09 -0800743 dismissDialogSafely(VoicemailDialogUtil.VM_FWD_READING_DIALOG);
744 showDialogIfForeground(VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700745 return;
746 }
747
Andrew Lee1af6cf72014-11-04 17:35:26 -0800748 // Get the forwarding info.
749 mForwardingReadResults[idx] = CallForwardInfoUtil.getCallForwardInfo(
750 (CallForwardInfo[]) ar.result,
751 VoicemailProviderSettings.FORWARDING_SETTINGS_REASONS[idx]);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700752
753 // Check if we got all the results already
754 boolean done = true;
755 for (int i = 0; i < mForwardingReadResults.length; i++) {
756 if (mForwardingReadResults[i] == null) {
757 done = false;
758 break;
759 }
760 }
Andrew Lee1af6cf72014-11-04 17:35:26 -0800761
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700762 if (done) {
763 if (DBG) Log.d(LOG_TAG, "Done receiving fwd info");
Andrew Lee84024342014-11-06 23:37:09 -0800764 dismissDialogSafely(VoicemailDialogUtil.VM_FWD_READING_DIALOG);
Andrew Lee1af6cf72014-11-04 17:35:26 -0800765
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700766 if (mReadingSettingsForDefaultProvider) {
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800767 VoicemailProviderSettingsUtil.save(mPhone.getContext(),
768 VoicemailProviderListPreference.DEFAULT_KEY,
Andrew Lee299e4a72015-01-15 12:44:34 -0800769 new VoicemailProviderSettings(mOldVmNumber, mForwardingReadResults));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700770 mReadingSettingsForDefaultProvider = false;
771 }
772 saveVoiceMailAndForwardingNumberStage2();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700773 }
774 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800775
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700776 private void resetForwardingChangeState() {
777 mForwardingChangeResults = new HashMap<Integer, AsyncResult>();
778 mExpectedChangeResultReasons = new HashSet<Integer>();
779 }
780
Andrew Lee299e4a72015-01-15 12:44:34 -0800781 // Called after we are done saving the previous forwarding settings if we needed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700782 private void saveVoiceMailAndForwardingNumberStage2() {
783 mForwardingChangeResults = null;
784 mVoicemailChangeResult = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700785
Andrew Lee9c822312015-03-13 07:52:08 -0700786 resetForwardingChangeState();
787 for (int i = 0; i < mNewFwdSettings.length; i++) {
788 CallForwardInfo fi = mNewFwdSettings[i];
789 CallForwardInfo fiForReason =
790 CallForwardInfoUtil.infoForReason(mForwardingReadResults, fi.reason);
791 final boolean doUpdate = CallForwardInfoUtil.isUpdateRequired(fiForReason, fi);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700792
Andrew Lee9c822312015-03-13 07:52:08 -0700793 if (doUpdate) {
794 if (DBG) log("Setting fwd #: " + i + ": " + fi.toString());
795 mExpectedChangeResultReasons.add(i);
796
797 CallForwardInfoUtil.setCallForwardingOption(mPhone, fi,
798 mSetOptionComplete.obtainMessage(
799 EVENT_FORWARDING_CHANGED, fi.reason, 0));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700800 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700801 }
Andrew Lee9c822312015-03-13 07:52:08 -0700802 showDialogIfForeground(VoicemailDialogUtil.VM_FWD_SAVING_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700803 }
804
Andrew Lee9c822312015-03-13 07:52:08 -0700805 private void setVoicemailNumberWithCarrier() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700806 if (DBG) log("save voicemail #: " + mNewVMNumber);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800807
Andrew Lee9c822312015-03-13 07:52:08 -0700808 mVoicemailChangeResult = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700809 mPhone.setVoiceMailNumber(
810 mPhone.getVoiceMailAlphaTag().toString(),
811 mNewVMNumber,
812 Message.obtain(mSetOptionComplete, EVENT_VOICEMAIL_CHANGED));
813 }
814
815 /**
816 * Callback to handle option update completions
817 */
818 private final Handler mSetOptionComplete = new Handler() {
819 @Override
820 public void handleMessage(Message msg) {
821 AsyncResult result = (AsyncResult) msg.obj;
822 boolean done = false;
823 switch (msg.what) {
824 case EVENT_VOICEMAIL_CHANGED:
825 mVoicemailChangeResult = result;
Andrew Leee438b312014-10-29 16:59:15 -0700826 mVMChangeCompletedSuccessfully = isVmChangeSuccess();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700827 done = true;
828 break;
829 case EVENT_FORWARDING_CHANGED:
830 mForwardingChangeResults.put(msg.arg1, result);
831 if (result.exception != null) {
832 Log.w(LOG_TAG, "Error in setting fwd# " + msg.arg1 + ": " +
833 result.exception.getMessage());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700834 }
Andrew Leee438b312014-10-29 16:59:15 -0700835 if (isForwardingCompleted()) {
836 if (isFwdChangeSuccess()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700837 if (DBG) log("Overall fwd changes completed ok, starting vm change");
Andrew Lee9c822312015-03-13 07:52:08 -0700838 setVoicemailNumberWithCarrier();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700839 } else {
840 Log.w(LOG_TAG, "Overall fwd changes completed in failure. " +
841 "Check if we need to try rollback for some settings.");
842 mFwdChangesRequireRollback = false;
843 Iterator<Map.Entry<Integer,AsyncResult>> it =
844 mForwardingChangeResults.entrySet().iterator();
845 while (it.hasNext()) {
846 Map.Entry<Integer,AsyncResult> entry = it.next();
847 if (entry.getValue().exception == null) {
848 // If at least one succeeded we have to revert
849 Log.i(LOG_TAG, "Rollback will be required");
850 mFwdChangesRequireRollback = true;
851 break;
852 }
853 }
854 if (!mFwdChangesRequireRollback) {
855 Log.i(LOG_TAG, "No rollback needed.");
856 }
857 done = true;
858 }
859 }
860 break;
861 default:
862 // TODO: should never reach this, may want to throw exception
863 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800864
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700865 if (done) {
866 if (DBG) log("All VM provider related changes done");
867 if (mForwardingChangeResults != null) {
Andrew Lee84024342014-11-06 23:37:09 -0800868 dismissDialogSafely(VoicemailDialogUtil.VM_FWD_SAVING_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700869 }
Andrew Leee438b312014-10-29 16:59:15 -0700870 handleSetVmOrFwdMessage();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700871 }
872 }
873 };
874
875 /**
876 * Callback to handle option revert completions
877 */
878 private final Handler mRevertOptionComplete = new Handler() {
879 @Override
880 public void handleMessage(Message msg) {
881 AsyncResult result = (AsyncResult) msg.obj;
882 switch (msg.what) {
883 case EVENT_VOICEMAIL_CHANGED:
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700884 if (DBG) log("VM revert complete msg");
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800885 mVoicemailChangeResult = result;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700886 break;
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800887
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700888 case EVENT_FORWARDING_CHANGED:
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800889 if (DBG) log("FWD revert complete msg ");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700890 mForwardingChangeResults.put(msg.arg1, result);
891 if (result.exception != null) {
892 if (DBG) log("Error in reverting fwd# " + msg.arg1 + ": " +
893 result.exception.getMessage());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700895 break;
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800896
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700897 default:
898 // TODO: should never reach this, may want to throw exception
899 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800900
901 final boolean done = (!mVMChangeCompletedSuccessfully || mVoicemailChangeResult != null)
902 && (!mFwdChangesRequireRollback || isForwardingCompleted());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700903 if (done) {
904 if (DBG) log("All VM reverts done");
Andrew Lee84024342014-11-06 23:37:09 -0800905 dismissDialogSafely(VoicemailDialogUtil.VM_REVERTING_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700906 onRevertDone();
907 }
908 }
909 };
910
911 /**
Andrew Leee438b312014-10-29 16:59:15 -0700912 * Return true if there is a change result for every reason for which we expect a result.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700913 */
Andrew Leee438b312014-10-29 16:59:15 -0700914 private boolean isForwardingCompleted() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700915 if (mForwardingChangeResults == null) {
Andrew Leee438b312014-10-29 16:59:15 -0700916 return true;
917 }
918
919 for (Integer reason : mExpectedChangeResultReasons) {
920 if (mForwardingChangeResults.get(reason) == null) {
921 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700922 }
923 }
Andrew Leee438b312014-10-29 16:59:15 -0700924
925 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700926 }
Andrew Leee438b312014-10-29 16:59:15 -0700927
928 private boolean isFwdChangeSuccess() {
929 if (mForwardingChangeResults == null) {
930 return true;
931 }
932
933 for (AsyncResult result : mForwardingChangeResults.values()) {
934 Throwable exception = result.exception;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700935 if (exception != null) {
Andrew Leee438b312014-10-29 16:59:15 -0700936 String msg = exception.getMessage();
937 msg = (msg != null) ? msg : "";
938 Log.w(LOG_TAG, "Failed to change forwarding setting. Reason: " + msg);
939 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700940 }
941 }
Andrew Leee438b312014-10-29 16:59:15 -0700942 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700943 }
944
Andrew Leee438b312014-10-29 16:59:15 -0700945 private boolean isVmChangeSuccess() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700946 if (mVoicemailChangeResult.exception != null) {
Andrew Leee438b312014-10-29 16:59:15 -0700947 String msg = mVoicemailChangeResult.exception.getMessage();
948 msg = (msg != null) ? msg : "";
949 Log.w(LOG_TAG, "Failed to change voicemail. Reason: " + msg);
950 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700951 }
Andrew Leee438b312014-10-29 16:59:15 -0700952 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700953 }
954
Andrew Leee438b312014-10-29 16:59:15 -0700955 private void handleSetVmOrFwdMessage() {
956 if (DBG) log("handleSetVMMessage: set VM request complete");
957
958 if (!isFwdChangeSuccess()) {
Andrew Lee84024342014-11-06 23:37:09 -0800959 handleVmOrFwdSetError(VoicemailDialogUtil.FWD_SET_RESPONSE_ERROR_DIALOG);
Andrew Leee438b312014-10-29 16:59:15 -0700960 } else if (!isVmChangeSuccess()) {
Andrew Lee84024342014-11-06 23:37:09 -0800961 handleVmOrFwdSetError(VoicemailDialogUtil.VM_RESPONSE_ERROR_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700962 } else {
Andrew Lee84024342014-11-06 23:37:09 -0800963 handleVmAndFwdSetSuccess(VoicemailDialogUtil.VM_CONFIRM_DIALOG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700964 }
965 }
966
967 /**
968 * Called when Voicemail Provider or its forwarding settings failed. Rolls back partly made
969 * changes to those settings and show "failure" dialog.
970 *
Andrew Leeab082272014-11-04 15:50:42 -0800971 * @param dialogId ID of the dialog to show for the specific error case. Either
Andrew Lee84024342014-11-06 23:37:09 -0800972 * {@link #FWD_SET_RESPONSE_ERROR_DIALOG} or {@link #VM_RESPONSE_ERROR_DIALOG}
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700973 */
Andrew Leeab082272014-11-04 15:50:42 -0800974 private void handleVmOrFwdSetError(int dialogId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700975 if (mChangingVMorFwdDueToProviderChange) {
Andrew Leeab082272014-11-04 15:50:42 -0800976 mVMOrFwdSetError = dialogId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700977 mChangingVMorFwdDueToProviderChange = false;
978 switchToPreviousVoicemailProvider();
979 return;
980 }
981 mChangingVMorFwdDueToProviderChange = false;
Andrew Leeab082272014-11-04 15:50:42 -0800982 showDialogIfForeground(dialogId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700983 updateVoiceNumberField();
984 }
985
986 /**
987 * Called when Voicemail Provider and its forwarding settings were successfully finished.
988 * This updates a bunch of variables and show "success" dialog.
989 */
Andrew Leeab082272014-11-04 15:50:42 -0800990 private void handleVmAndFwdSetSuccess(int dialogId) {
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800991 if (DBG) log("handleVmAndFwdSetSuccess: key is " + mVoicemailProviders.getKey());
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800992
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800993 mPreviousVMProviderKey = mVoicemailProviders.getKey();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700994 mChangingVMorFwdDueToProviderChange = false;
Andrew Leeab082272014-11-04 15:50:42 -0800995 showDialogIfForeground(dialogId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700996 updateVoiceNumberField();
997 }
998
999 /**
1000 * Update the voicemail number from what we've recorded on the sim.
1001 */
1002 private void updateVoiceNumberField() {
Andrew Lee2d5d1a42014-11-05 12:34:14 -08001003 if (DBG) log("updateVoiceNumberField()");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001004
1005 mOldVmNumber = mPhone.getVoiceMailNumber();
Andrew Lee2d5d1a42014-11-05 12:34:14 -08001006 if (TextUtils.isEmpty(mOldVmNumber)) {
1007 mSubMenuVoicemailSettings.setPhoneNumber("");
1008 mSubMenuVoicemailSettings.setSummary(getString(R.string.voicemail_number_not_set));
1009 } else {
1010 mSubMenuVoicemailSettings.setPhoneNumber(mOldVmNumber);
1011 mSubMenuVoicemailSettings.setSummary(mOldVmNumber);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001013 }
1014
1015 /*
1016 * Helper Methods for Activity class.
1017 * The initial query commands are split into two pieces now
1018 * for individual expansion. This combined with the ability
1019 * to cancel queries allows for a much better user experience,
1020 * and also ensures that the user only waits to update the
1021 * data that is relevant.
1022 */
1023
1024 @Override
1025 protected void onPrepareDialog(int id, Dialog dialog) {
1026 super.onPrepareDialog(id, dialog);
1027 mCurrentDialogId = id;
1028 }
1029
1030 // dialog creation method, called by showDialog()
1031 @Override
Andrew Lee84024342014-11-06 23:37:09 -08001032 protected Dialog onCreateDialog(int dialogId) {
1033 return VoicemailDialogUtil.getDialog(this, dialogId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001034 }
1035
1036 // This is a method implemented for DialogInterface.OnClickListener.
1037 // Used with the error dialog to close the app, voicemail dialog to just dismiss.
1038 // Close button is mapped to BUTTON_POSITIVE for the errors that close the activity,
1039 // while those that are mapped to BUTTON_NEUTRAL only move the preference focus.
1040 public void onClick(DialogInterface dialog, int which) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -08001041 if (DBG) log("onClick: button clicked is " + which);
1042
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001043 dialog.dismiss();
1044 switch (which){
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001045 case DialogInterface.BUTTON_NEGATIVE:
Andrew Lee84024342014-11-06 23:37:09 -08001046 if (mCurrentDialogId == VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001047 // We failed to get current forwarding settings and the user
1048 // does not wish to continue.
1049 switchToPreviousVoicemailProvider();
1050 }
1051 break;
1052 case DialogInterface.BUTTON_POSITIVE:
Andrew Lee84024342014-11-06 23:37:09 -08001053 if (mCurrentDialogId == VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001054 // We failed to get current forwarding settings but the user
1055 // wishes to continue changing settings to the new vm provider
Andrew Lee9c822312015-03-13 07:52:08 -07001056 setVoicemailNumberWithCarrier();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001057 } else {
1058 finish();
1059 }
1060 return;
1061 default:
1062 // just let the dialog close and go back to the input
1063 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -08001064
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001065 // In all dialogs, all buttons except BUTTON_POSITIVE lead to the end of user interaction
1066 // with settings UI. If we were called to explicitly configure voice mail then
1067 // we finish the settings activity here to come back to whatever the user was doing.
1068 if (getIntent().getAction().equals(ACTION_ADD_VOICEMAIL)) {
1069 finish();
1070 }
1071 }
1072
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001073 /*
1074 * Activity class methods
1075 */
1076
1077 @Override
1078 protected void onCreate(Bundle icicle) {
1079 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -08001080 if (DBG) log("onCreate: Intent is " + getIntent());
1081
Jay Shraunerc2684732014-11-12 12:10:37 -08001082 // Make sure we are running as the primary user.
1083 if (UserHandle.myUserId() != UserHandle.USER_OWNER) {
1084 Toast.makeText(this, R.string.call_settings_primary_user_only,
1085 Toast.LENGTH_SHORT).show();
1086 finish();
1087 return;
1088 }
1089
Tyler Gunnbaee2952014-09-10 16:01:02 -07001090 // Show the voicemail preference in onResume if the calling intent specifies the
1091 // ACTION_ADD_VOICEMAIL action.
1092 mShowVoicemailPreference = (icicle == null) &&
Jay Shraunerbe2fb262014-11-11 15:19:58 -08001093 TextUtils.equals(getIntent().getAction(), ACTION_ADD_VOICEMAIL);
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001094 mSetupVoicemail = mShowVoicemailPreference &&
1095 getIntent().getBooleanExtra(SETUP_VOICEMAIL_EXTRA, false);
Andrew Lee5ed870c2014-10-29 11:47:49 -07001096
Andrew Leedd4f6df2014-12-09 19:13:51 -08001097 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5ed870c2014-10-29 11:47:49 -07001098 mSubscriptionInfoHelper.setActionBarTitle(
1099 getActionBar(), getResources(), R.string.call_settings_with_label);
Andrew Lee1479dd12014-11-06 23:06:32 -08001100 mPhone = mSubscriptionInfoHelper.getPhone();
Tyler Gunnbaee2952014-09-10 16:01:02 -07001101 }
1102
Tyler Gunnbaee2952014-09-10 16:01:02 -07001103 @Override
1104 protected void onResume() {
1105 super.onResume();
1106 mForeground = true;
1107
1108 PreferenceScreen preferenceScreen = getPreferenceScreen();
1109 if (preferenceScreen != null) {
1110 preferenceScreen.removeAll();
1111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001112
1113 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -07001114
Andrew Lee6fee2cb2014-12-09 16:42:18 -08001115 TelecomManager telecomManager = TelecomManager.from(this);
1116 TelephonyManager telephonyManager =
1117 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1118
1119 Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
1120 if (telephonyManager.isMultiSimEnabled() || (telecomManager.getSimCallManagers().isEmpty()
1121 && !SipUtil.isVoipSupported(mPhone.getContext()))) {
1122 getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
1123 }
Andrew Leedb2fe562014-09-03 15:40:43 -07001124
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001125 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee64a7d792014-10-15 17:38:38 -07001126 mSubMenuVoicemailSettings = (EditPhoneNumberPreference) findPreference(BUTTON_VOICEMAIL_KEY);
1127 mSubMenuVoicemailSettings.setParentActivity(this, VOICEMAIL_PREF_ID, this);
1128 mSubMenuVoicemailSettings.setDialogOnClosedListener(this);
1129 mSubMenuVoicemailSettings.setDialogTitle(R.string.voicemail_settings_number_label);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001130
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001131 mButtonAutoRetry = (CheckBoxPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee2170a972014-08-13 18:13:01 -07001132
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001133 mVoicemailProviders = (VoicemailProviderListPreference) findPreference(
1134 BUTTON_VOICEMAIL_PROVIDER_KEY);
1135 mVoicemailProviders.init(mPhone, getIntent());
Andrew Lee2c027892014-10-29 11:29:54 -07001136 mVoicemailProviders.setOnPreferenceChangeListener(this);
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001137 mPreviousVMProviderKey = mVoicemailProviders.getValue();
Andrew Lee8d66d812014-11-24 14:54:02 -08001138
Andrew Lee2c027892014-10-29 11:29:54 -07001139 mVoicemailSettingsScreen =
1140 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001141 mVoicemailSettings = (PreferenceScreen) findPreference(BUTTON_VOICEMAIL_SETTING_KEY);
Andrew Lee8d66d812014-11-24 14:54:02 -08001142
Andrew Lee1ec7c7e2014-12-03 15:33:21 -08001143 mVoicemailNotificationRingtone = (VoicemailRingtonePreference) findPreference(
1144 getResources().getString(R.string.voicemail_notification_ringtone_key));
1145 mVoicemailNotificationRingtone.init(mPhone);
1146
Andrew Lee8d66d812014-11-24 14:54:02 -08001147 mVoicemailNotificationVibrate = (CheckBoxPreference) findPreference(
1148 getResources().getString(R.string.voicemail_notification_vibrate_key));
1149 mVoicemailNotificationVibrate.setOnPreferenceChangeListener(this);
1150
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001151 updateVMPreferenceWidgets(mVoicemailProviders.getValue());
1152
1153 mEnableVideoCalling = (CheckBoxPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001154
Andrew Lee64a7d792014-10-15 17:38:38 -07001155 if (getResources().getBoolean(R.bool.auto_retry_enabled)) {
1156 mButtonAutoRetry.setOnPreferenceChangeListener(this);
1157 int autoretry = Settings.Global.getInt(
1158 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
1159 mButtonAutoRetry.setChecked(autoretry != 0);
1160 } else {
1161 prefSet.removePreference(mButtonAutoRetry);
1162 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001163 }
1164
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001165 if (!getResources().getBoolean(R.bool.world_phone)) {
Andrew Lee2b36ba22014-11-05 17:08:49 -08001166 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
1167 prefSet.removePreference(cdmaOptions);
1168
1169 // TODO: Support MSIM for this preference option.
1170 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
1171 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001172
1173 int phoneType = mPhone.getPhoneType();
Andrew Lee5ed870c2014-10-29 11:47:49 -07001174 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
Junda Liua09d6962014-11-12 13:39:02 -08001175 boolean shouldHideCarrierSettings = Settings.Global.getInt(
1176 getContentResolver(), Settings.Global.HIDE_CARRIER_NETWORK_SETTINGS, 0) == 1;
1177 if (shouldHideCarrierSettings) {
Andrew Lee5ed870c2014-10-29 11:47:49 -07001178 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001179 } else {
Junda Liua09d6962014-11-12 13:39:02 -08001180 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
1181 prefSet.removePreference(fdnButton);
1182
1183 if (!getResources().getBoolean(R.bool.config_voice_privacy_disable)) {
1184 addPreferencesFromResource(R.xml.cdma_call_privacy);
1185 }
1186 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Andrew Leedd4f6df2014-12-09 19:13:51 -08001187 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Junda Liua09d6962014-11-12 13:39:02 -08001188
1189 if (getResources().getBoolean(R.bool.config_additional_call_setting)) {
1190 addPreferencesFromResource(R.xml.gsm_umts_call_options);
1191
1192 Preference callForwardingPref = prefSet.findPreference(CALL_FORWARDING_KEY);
1193 callForwardingPref.setIntent(mSubscriptionInfoHelper.getIntent(
Andrew Leedd4f6df2014-12-09 19:13:51 -08001194 GsmUmtsCallForwardOptions.class));
Junda Liua09d6962014-11-12 13:39:02 -08001195
1196 Preference additionalGsmSettingsPref =
1197 prefSet.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
1198 additionalGsmSettingsPref.setIntent(mSubscriptionInfoHelper.getIntent(
Andrew Leedd4f6df2014-12-09 19:13:51 -08001199 GsmUmtsAdditionalCallOptions.class));
Junda Liua09d6962014-11-12 13:39:02 -08001200 }
1201 } else {
1202 throw new IllegalStateException("Unexpected phone type: " + phoneType);
1203 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001204 }
1205 }
1206
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001207 // check the intent that started this activity and pop up the voicemail
1208 // dialog if we've been asked to.
1209 // If we have at least one non default VM provider registered then bring up
1210 // the selection for the VM provider, otherwise bring up a VM number dialog.
1211 // We only bring up the dialog the first time we are called (not after orientation change)
Andrew Lee2c027892014-10-29 11:29:54 -07001212 if (mShowVoicemailPreference) {
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001213 if (DBG) log("ACTION_ADD_VOICEMAIL Intent is thrown");
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001214 if (mSetupVoicemail) {
1215 simulatePreferenceClick(mVoicemailSettingsScreen);
1216 mSetupVoicemail = false;
1217 } else if (mVoicemailProviders.hasMoreThanOneVoicemailProvider()) {
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001218 if (DBG) log("Voicemail data has more than one provider.");
Tyler Gunnbaee2952014-09-10 16:01:02 -07001219 simulatePreferenceClick(mVoicemailProviders);
1220 } else {
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001221 onPreferenceChange(mVoicemailProviders, VoicemailProviderListPreference.DEFAULT_KEY);
1222 mVoicemailProviders.setValue(VoicemailProviderListPreference.DEFAULT_KEY);
Tyler Gunnbaee2952014-09-10 16:01:02 -07001223 }
1224 mShowVoicemailPreference = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001225 }
Tyler Gunnbaee2952014-09-10 16:01:02 -07001226
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001227 updateVoiceNumberField();
1228 mVMProviderSettingsForced = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001229
Andrew Lee8d66d812014-11-24 14:54:02 -08001230 mVoicemailNotificationVibrate.setChecked(
Andrew Lee1ec7c7e2014-12-03 15:33:21 -08001231 VoicemailNotificationSettingsUtil.isVibrationEnabled(mPhone));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232
Andrew Lee312e8172014-10-23 17:01:36 -07001233 if (ImsManager.isVtEnabledByPlatform(mPhone.getContext()) && ENABLE_VT_FLAG) {
1234 boolean currentValue =
1235 ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
1236 ? PhoneGlobals.getInstance().phoneMgr.isVideoCallingEnabled() : false;
1237 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -07001238 mEnableVideoCalling.setOnPreferenceChangeListener(this);
1239 } else {
1240 prefSet.removePreference(mEnableVideoCalling);
1241 }
Etan Cohena51d4ef2014-12-15 10:44:42 -08001242
1243 if (ImsManager.isVolteEnabledByPlatform(this) &&
1244 !mPhone.getContext().getResources().getBoolean(
1245 com.android.internal.R.bool.config_carrier_volte_tty_supported)) {
1246 TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Vinit Deshpande84cccac2015-03-16 00:08:19 -07001247 /* tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); */
Etan Cohena51d4ef2014-12-15 10:44:42 -08001248 }
Andrew Leeb97fad82015-01-27 15:31:39 -08001249
Andrew Leeeffef9c2015-02-19 16:02:37 -08001250 Preference wifiCallingSettings = findPreference(
1251 getResources().getString(R.string.wifi_calling_settings_key));
Andrew Leeb97fad82015-01-27 15:31:39 -08001252 if (!ImsManager.isWfcEnabledByPlatform(mPhone.getContext())) {
Andrew Leeb97fad82015-01-27 15:31:39 -08001253 prefSet.removePreference(wifiCallingSettings);
Andrew Leeeffef9c2015-02-19 16:02:37 -08001254 } else {
1255 int resId = R.string.wifi_calling_off_summary;
1256 if (ImsManager.isWfcEnabledByUser(mPhone.getContext())) {
1257 int wfcMode = ImsManager.getWfcMode(mPhone.getContext());
1258 switch (wfcMode) {
1259 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
1260 resId = R.string.wfc_mode_wifi_only_summary;
1261 break;
1262 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
1263 resId = R.string.wfc_mode_cellular_preferred_summary;
1264 break;
1265 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
1266 resId = R.string.wfc_mode_wifi_preferred_summary;
1267 break;
1268 default:
1269 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
1270 }
1271 }
1272 wifiCallingSettings.setSummary(resId);
Andrew Leeb97fad82015-01-27 15:31:39 -08001273 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 }
1275
Andrew Lee785ca2a2014-12-18 12:46:41 -08001276 @Override
1277 protected void onNewIntent(Intent newIntent) {
1278 setIntent(newIntent);
1279
1280 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
1281 mSubscriptionInfoHelper.setActionBarTitle(
1282 getActionBar(), getResources(), R.string.call_settings_with_label);
1283 mPhone = mSubscriptionInfoHelper.getPhone();
1284 }
1285
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 private static void log(String msg) {
1287 Log.d(LOG_TAG, msg);
1288 }
1289
1290 /**
1291 * Updates the look of the VM preference widgets based on current VM provider settings.
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001292 * Note that the provider name is loaded fxrorm the found activity via loadLabel in
1293 * {@link VoicemailProviderListPreference#initVoiceMailProviders()} in order for it to be
1294 * localizable.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001295 */
1296 private void updateVMPreferenceWidgets(String currentProviderSetting) {
1297 final String key = currentProviderSetting;
Andrew Lee64e5c9d2014-11-26 12:00:10 -08001298 final VoicemailProvider provider = mVoicemailProviders.getVoicemailProvider(key);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001299
1300 /* This is the case when we are coming up on a freshly wiped phone and there is no
1301 persisted value for the list preference mVoicemailProviders.
1302 In this case we want to show the UI asking the user to select a voicemail provider as
1303 opposed to silently falling back to default one. */
1304 if (provider == null) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -08001305 if (DBG) log("updateVMPreferenceWidget: key: " + key + " -> null.");
1306
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307 mVoicemailProviders.setSummary(getString(R.string.sum_voicemail_choose_provider));
1308 mVoicemailSettings.setEnabled(false);
1309 mVoicemailSettings.setIntent(null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001310 mVoicemailNotificationVibrate.setEnabled(false);
1311 } else {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -08001312 if (DBG) log("updateVMPreferenceWidget: key: " + key + " -> " + provider.toString());
1313
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 final String providerName = provider.name;
1315 mVoicemailProviders.setSummary(providerName);
1316 mVoicemailSettings.setEnabled(true);
1317 mVoicemailSettings.setIntent(provider.intent);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 mVoicemailNotificationVibrate.setEnabled(true);
1319 }
1320 }
1321
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001322
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001323 /**
1324 * Simulates user clicking on a passed preference.
1325 * Usually needed when the preference is a dialog preference and we want to invoke
1326 * a dialog for this preference programmatically.
Santos Cordonda120f42014-08-06 04:44:34 -07001327 * TODO: figure out if there is a cleaner way to cause preference dlg to come up
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 */
1329 private void simulatePreferenceClick(Preference preference) {
1330 // Go through settings until we find our setting
1331 // and then simulate a click on it to bring up the dialog
1332 final ListAdapter adapter = getPreferenceScreen().getRootAdapter();
1333 for (int idx = 0; idx < adapter.getCount(); idx++) {
1334 if (adapter.getItem(idx) == preference) {
1335 getPreferenceScreen().onItemClick(this.getListView(),
1336 null, idx, adapter.getItemId(idx));
1337 break;
1338 }
1339 }
1340 }
1341
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 @Override
1343 public boolean onOptionsItemSelected(MenuItem item) {
1344 final int itemId = item.getItemId();
1345 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -07001346 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001347 return true;
1348 }
1349 return super.onOptionsItemSelected(item);
1350 }
Andrew Lee8d66d812014-11-24 14:54:02 -08001351
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001352 /**
1353 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
1354 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
1355 */
Andrew Lee5efb1122014-12-05 04:20:42 -08001356 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -08001357 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
1358 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359 intent.setAction(Intent.ACTION_MAIN);
1360 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
1361 activity.startActivity(intent);
1362 activity.finish();
1363 }
1364}