Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
| 19 | import android.app.ActionBar; |
| 20 | import android.app.Activity; |
Evan Charlton | 1c69683 | 2014-04-15 14:24:23 -0700 | [diff] [blame] | 21 | import android.app.ActivityOptions; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 22 | import android.app.AlertDialog; |
| 23 | import android.app.Dialog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 24 | import android.content.ContentResolver; |
| 25 | import android.content.Context; |
| 26 | import android.content.DialogInterface; |
| 27 | import android.content.Intent; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 28 | import android.database.Cursor; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 29 | import android.media.AudioManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.os.AsyncResult; |
| 31 | import android.os.Bundle; |
| 32 | import android.os.Handler; |
| 33 | import android.os.Message; |
| 34 | import android.os.UserHandle; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.preference.CheckBoxPreference; |
| 36 | import android.preference.ListPreference; |
| 37 | import android.preference.Preference; |
| 38 | import android.preference.PreferenceActivity; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 39 | import android.preference.PreferenceScreen; |
| 40 | import android.provider.ContactsContract.CommonDataKinds; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.provider.Settings; |
Tyler Gunn | 4d45d1c | 2014-09-12 22:17:53 -0700 | [diff] [blame] | 42 | import android.telecom.PhoneAccountHandle; |
| 43 | import android.telecom.TelecomManager; |
Andrew Lee | 93c345f | 2014-10-27 15:25:07 -0700 | [diff] [blame] | 44 | import android.telephony.TelephonyManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.text.TextUtils; |
| 46 | import android.util.Log; |
| 47 | import android.view.MenuItem; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | import android.widget.ListAdapter; |
Jay Shrauner | c268473 | 2014-11-12 12:10:37 -0800 | [diff] [blame] | 49 | import android.widget.Toast; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 51 | import com.android.ims.ImsManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import com.android.internal.telephony.CallForwardInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import com.android.internal.telephony.Phone; |
| 54 | import com.android.internal.telephony.PhoneConstants; |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 55 | import com.android.phone.common.util.SettingsUtil; |
Andrew Lee | db2fe56 | 2014-09-03 15:40:43 -0700 | [diff] [blame] | 56 | import com.android.phone.settings.AccountSelectionPreference; |
Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 57 | import com.android.phone.settings.CallForwardInfoUtil; |
Andrew Lee | 6fee2cb | 2014-12-09 16:42:18 -0800 | [diff] [blame] | 58 | import com.android.phone.settings.TtyModeListPreference; |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 59 | import com.android.phone.settings.VoicemailDialogUtil; |
Andrew Lee | 1ec7c7e | 2014-12-03 15:33:21 -0800 | [diff] [blame] | 60 | import com.android.phone.settings.VoicemailNotificationSettingsUtil; |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 61 | import com.android.phone.settings.VoicemailProviderListPreference; |
| 62 | import com.android.phone.settings.VoicemailProviderListPreference.VoicemailProvider; |
Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 63 | import com.android.phone.settings.VoicemailProviderSettings; |
Andrew Lee | 88b51e2 | 2014-10-29 15:48:51 -0700 | [diff] [blame] | 64 | import com.android.phone.settings.VoicemailProviderSettingsUtil; |
Andrew Lee | 1ec7c7e | 2014-12-03 15:33:21 -0800 | [diff] [blame] | 65 | import com.android.phone.settings.VoicemailRingtonePreference; |
Andrew Lee | 5ed870c | 2014-10-29 11:47:49 -0700 | [diff] [blame] | 66 | import com.android.phone.settings.fdn.FdnSetting; |
Sailesh Nepal | 788959e | 2014-07-08 23:36:40 -0700 | [diff] [blame] | 67 | import com.android.services.telephony.sip.SipUtil; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 68 | |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 69 | import java.lang.String; |
Andrew Lee | f1776d8 | 2014-11-04 14:45:02 -0800 | [diff] [blame] | 70 | import java.util.ArrayList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 71 | import java.util.Collection; |
| 72 | import java.util.HashMap; |
| 73 | import java.util.HashSet; |
| 74 | import java.util.Iterator; |
| 75 | import java.util.List; |
| 76 | import java.util.Map; |
| 77 | |
| 78 | /** |
| 79 | * Top level "Call settings" UI; see res/xml/call_feature_setting.xml |
| 80 | * |
Andrew Lee | ce8ae2a | 2014-09-10 10:41:48 -0700 | [diff] [blame] | 81 | * 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 Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 85 | * |
| 86 | * Note that this activity is part of the package com.android.phone, even |
| 87 | * though you reach it from the "Phone" app (i.e. DialtactsActivity) which |
| 88 | * is from the package com.android.contacts. |
| 89 | * |
| 90 | * For the "Mobile network settings" screen under the main Settings app, |
| 91 | * See {@link MobileNetworkSettings}. |
| 92 | * |
Andrew Lee | ce8ae2a | 2014-09-10 10:41:48 -0700 | [diff] [blame] | 93 | * TODO: Settings should be split into PreferenceFragments where possible (ie. voicemail). |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 94 | * |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 95 | * @see com.android.phone.MobileNetworkSettings |
| 96 | */ |
| 97 | public class CallFeaturesSetting extends PreferenceActivity |
| 98 | implements DialogInterface.OnClickListener, |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 99 | Preference.OnPreferenceChangeListener, |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 100 | EditPhoneNumberPreference.OnDialogClosedListener, |
Andrew Lee | ce8ae2a | 2014-09-10 10:41:48 -0700 | [diff] [blame] | 101 | EditPhoneNumberPreference.GetDefaultNumberListener { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 102 | private static final String LOG_TAG = "CallFeaturesSetting"; |
| 103 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
Andrew Lee | 77527ac | 2014-10-21 16:57:39 -0700 | [diff] [blame] | 104 | // STOPSHIP if true. Flag to override behavior default behavior to hide VT setting. |
| 105 | private static final boolean ENABLE_VT_FLAG = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * Intent action to bring up Voicemail Provider settings. |
| 109 | * |
| 110 | * @see #IGNORE_PROVIDER_EXTRA |
| 111 | */ |
| 112 | public static final String ACTION_ADD_VOICEMAIL = |
| 113 | "com.android.phone.CallFeaturesSetting.ADD_VOICEMAIL"; |
| 114 | // intent action sent by this activity to a voice mail provider |
| 115 | // to trigger its configuration UI |
| 116 | public static final String ACTION_CONFIGURE_VOICEMAIL = |
| 117 | "com.android.phone.CallFeaturesSetting.CONFIGURE_VOICEMAIL"; |
| 118 | // Extra put in the return from VM provider config containing voicemail number to set |
| 119 | public static final String VM_NUMBER_EXTRA = "com.android.phone.VoicemailNumber"; |
| 120 | // Extra put in the return from VM provider config containing call forwarding number to set |
| 121 | public static final String FWD_NUMBER_EXTRA = "com.android.phone.ForwardingNumber"; |
| 122 | // Extra put in the return from VM provider config containing call forwarding number to set |
| 123 | public static final String FWD_NUMBER_TIME_EXTRA = "com.android.phone.ForwardingNumberTime"; |
| 124 | // If the VM provider returns non null value in this extra we will force the user to |
| 125 | // choose another VM provider |
| 126 | public static final String SIGNOUT_EXTRA = "com.android.phone.Signout"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 127 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 128 | /** |
| 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 Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 135 | /** |
| 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 Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 141 | // 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 Lee | 8d66d81 | 2014-11-24 14:54:02 -0800 | [diff] [blame] | 146 | // 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 Lee | 97708a4 | 2014-09-25 12:39:07 -0700 | [diff] [blame] | 150 | private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 151 | 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 Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 154 | private static final String BUTTON_FDN_KEY = "button_fdn_key"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 155 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 156 | private static final String BUTTON_DTMF_KEY = "button_dtmf_settings"; |
| 157 | private static final String BUTTON_RETRY_KEY = "button_auto_retry_key"; |
| 158 | private static final String BUTTON_TTY_KEY = "button_tty_mode_key"; |
| 159 | private static final String BUTTON_HAC_KEY = "button_hac_key"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 160 | |
| 161 | private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key"; |
| 162 | private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key"; |
Andrew Lee | 2b36ba2 | 2014-11-05 17:08:49 -0800 | [diff] [blame] | 163 | private static final String CALL_FORWARDING_KEY = "call_forwarding_key"; |
| 164 | private static final String ADDITIONAL_GSM_SETTINGS_KEY = "additional_gsm_call_settings_key"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 165 | |
Andrew Lee | ce8ae2a | 2014-09-10 10:41:48 -0700 | [diff] [blame] | 166 | private static final String PHONE_ACCOUNT_SETTINGS_KEY = |
| 167 | "phone_account_settings_preference_screen"; |
Andrew Lee | db2fe56 | 2014-09-03 15:40:43 -0700 | [diff] [blame] | 168 | |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 169 | private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling"; |
| 170 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 171 | /** Event for Async voicemail change call */ |
| 172 | private static final int EVENT_VOICEMAIL_CHANGED = 500; |
| 173 | private static final int EVENT_FORWARDING_CHANGED = 501; |
| 174 | private static final int EVENT_FORWARDING_GET_COMPLETED = 502; |
| 175 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 176 | public static final String HAC_KEY = "HACSetting"; |
| 177 | public static final String HAC_VAL_ON = "ON"; |
| 178 | public static final String HAC_VAL_OFF = "OFF"; |
| 179 | |
| 180 | /** Handle to voicemail pref */ |
| 181 | private static final int VOICEMAIL_PREF_ID = 1; |
| 182 | private static final int VOICEMAIL_PROVIDER_CFG_ID = 2; |
| 183 | |
| 184 | private Phone mPhone; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 185 | private AudioManager mAudioManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 186 | |
Andrew Lee | 5ed870c | 2014-10-29 11:47:49 -0700 | [diff] [blame] | 187 | private SubscriptionInfoHelper mSubscriptionInfoHelper; |
| 188 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 189 | private EditPhoneNumberPreference mSubMenuVoicemailSettings; |
| 190 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 191 | /** Whether dialpad plays DTMF tone or not. */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 192 | private CheckBoxPreference mButtonAutoRetry; |
| 193 | private CheckBoxPreference mButtonHAC; |
| 194 | private ListPreference mButtonDTMF; |
Andrew Lee | 6fee2cb | 2014-12-09 16:42:18 -0800 | [diff] [blame] | 195 | private TtyModeListPreference mButtonTTY; |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 196 | private VoicemailProviderListPreference mVoicemailProviders; |
Andrew Lee | 97708a4 | 2014-09-25 12:39:07 -0700 | [diff] [blame] | 197 | private PreferenceScreen mVoicemailSettingsScreen; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 198 | private PreferenceScreen mVoicemailSettings; |
Andrew Lee | 1ec7c7e | 2014-12-03 15:33:21 -0800 | [diff] [blame] | 199 | private VoicemailRingtonePreference mVoicemailNotificationRingtone; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 200 | private CheckBoxPreference mVoicemailNotificationVibrate; |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 201 | private CheckBoxPreference mEnableVideoCalling; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 202 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 203 | /** |
| 204 | * Results of reading forwarding settings |
| 205 | */ |
| 206 | private CallForwardInfo[] mForwardingReadResults = null; |
| 207 | |
| 208 | /** |
| 209 | * Result of forwarding number change. |
| 210 | * Keys are reasons (eg. unconditional forwarding). |
| 211 | */ |
| 212 | private Map<Integer, AsyncResult> mForwardingChangeResults = null; |
| 213 | |
| 214 | /** |
| 215 | * Expected CF read result types. |
| 216 | * This set keeps track of the CF types for which we've issued change |
| 217 | * commands so we can tell when we've received all of the responses. |
| 218 | */ |
| 219 | private Collection<Integer> mExpectedChangeResultReasons = null; |
| 220 | |
| 221 | /** |
| 222 | * Result of vm number change |
| 223 | */ |
| 224 | private AsyncResult mVoicemailChangeResult = null; |
| 225 | |
| 226 | /** |
| 227 | * Previous VM provider setting so we can return to it in case of failure. |
| 228 | */ |
| 229 | private String mPreviousVMProviderKey = null; |
| 230 | |
| 231 | /** |
| 232 | * Id of the dialog being currently shown. |
| 233 | */ |
| 234 | private int mCurrentDialogId = 0; |
| 235 | |
| 236 | /** |
| 237 | * Flag indicating that we are invoking settings for the voicemail provider programmatically |
| 238 | * due to vm provider change. |
| 239 | */ |
| 240 | private boolean mVMProviderSettingsForced = false; |
| 241 | |
| 242 | /** |
| 243 | * Flag indicating that we are making changes to vm or fwd numbers |
| 244 | * due to vm provider change. |
| 245 | */ |
| 246 | private boolean mChangingVMorFwdDueToProviderChange = false; |
| 247 | |
| 248 | /** |
| 249 | * True if we are in the process of vm & fwd number change and vm has already been changed. |
| 250 | * This is used to decide what to do in case of rollback. |
| 251 | */ |
| 252 | private boolean mVMChangeCompletedSuccessfully = false; |
| 253 | |
| 254 | /** |
| 255 | * True if we had full or partial failure setting forwarding numbers and so need to roll them |
| 256 | * back. |
| 257 | */ |
| 258 | private boolean mFwdChangesRequireRollback = false; |
| 259 | |
| 260 | /** |
| 261 | * Id of error msg to display to user once we are done reverting the VM provider to the previous |
| 262 | * one. |
| 263 | */ |
| 264 | private int mVMOrFwdSetError = 0; |
| 265 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 266 | /** string to hold old voicemail number as it is being updated. */ |
| 267 | private String mOldVmNumber; |
| 268 | |
| 269 | // New call forwarding settings and vm number we will be setting |
| 270 | // Need to save these since before we get to saving we need to asynchronously |
| 271 | // query the existing forwarding settings. |
| 272 | private CallForwardInfo[] mNewFwdSettings; |
| 273 | private String mNewVMNumber; |
| 274 | |
| 275 | private boolean mForeground; |
| 276 | |
| 277 | @Override |
| 278 | public void onPause() { |
| 279 | super.onPause(); |
| 280 | mForeground = false; |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * We have to pull current settings from the network for all kinds of |
| 285 | * voicemail providers so we can tell whether we have to update them, |
| 286 | * so use this bit to keep track of whether we're reading settings for the |
| 287 | * default provider and should therefore save them out when done. |
| 288 | */ |
| 289 | private boolean mReadingSettingsForDefaultProvider = false; |
| 290 | |
Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 291 | /** |
| 292 | * Used to indicate that the voicemail preference should be shown. |
| 293 | */ |
| 294 | private boolean mShowVoicemailPreference = false; |
| 295 | |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 296 | /** |
| 297 | * Used to indicate that the voicemail setup screen should be shown. |
| 298 | */ |
| 299 | private boolean mSetupVoicemail = false; |
| 300 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 301 | /* |
| 302 | * Click Listeners, handle click based on objects attached to UI. |
| 303 | */ |
| 304 | |
| 305 | // Click listener for all toggle events |
| 306 | @Override |
| 307 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
| 308 | if (preference == mSubMenuVoicemailSettings) { |
| 309 | return true; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 310 | } else if (preference == mButtonDTMF) { |
| 311 | return true; |
| 312 | } else if (preference == mButtonTTY) { |
| 313 | return true; |
| 314 | } else if (preference == mButtonAutoRetry) { |
| 315 | android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
| 316 | android.provider.Settings.Global.CALL_AUTO_RETRY, |
| 317 | mButtonAutoRetry.isChecked() ? 1 : 0); |
| 318 | return true; |
| 319 | } else if (preference == mButtonHAC) { |
| 320 | int hac = mButtonHAC.isChecked() ? 1 : 0; |
| 321 | // Update HAC value in Settings database |
| 322 | Settings.System.putInt(mPhone.getContext().getContentResolver(), |
| 323 | Settings.System.HEARING_AID, hac); |
| 324 | |
| 325 | // Update HAC Value in AudioManager |
| 326 | mAudioManager.setParameter(HAC_KEY, hac != 0 ? HAC_VAL_ON : HAC_VAL_OFF); |
| 327 | return true; |
Andrew Lee | 696bff5 | 2014-12-03 17:58:18 -0800 | [diff] [blame] | 328 | } else if (preference.getKey().equals(mVoicemailSettings.getKey())) { |
| 329 | // Check key instead of comparing reference because closing the voicemail notification |
| 330 | // ringtone dialog invokes onResume(), but leaves the old preference screen up, |
| 331 | // TODO: Revert to checking reference after migrating voicemail to its own activity. |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 332 | if (DBG) log("onPreferenceTreeClick: Voicemail Settings Preference is clicked."); |
| 333 | |
Andrew Lee | 696bff5 | 2014-12-03 17:58:18 -0800 | [diff] [blame] | 334 | final Dialog dialog = ((PreferenceScreen) preference).getDialog(); |
Yorke Lee | a0f63bf | 2014-10-09 18:27:20 -0700 | [diff] [blame] | 335 | if (dialog != null) { |
| 336 | dialog.getActionBar().setDisplayHomeAsUpEnabled(false); |
| 337 | } |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 338 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 339 | if (preference.getIntent() != null) { |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 340 | if (DBG) log("Invoking cfg intent " + preference.getIntent().getPackage()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 341 | |
| 342 | // onActivityResult() will be responsible for resetting some of variables. |
| 343 | this.startActivityForResult(preference.getIntent(), VOICEMAIL_PROVIDER_CFG_ID); |
| 344 | return true; |
| 345 | } else { |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 346 | if (DBG) log("onPreferenceTreeClick(). No intent; use default behavior in xml."); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 347 | |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 348 | // onActivityResult() will not be called, so reset variables here. |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 349 | mPreviousVMProviderKey = VoicemailProviderListPreference.DEFAULT_KEY; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 350 | mVMProviderSettingsForced = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 351 | return false; |
| 352 | } |
Andrew Lee | 97708a4 | 2014-09-25 12:39:07 -0700 | [diff] [blame] | 353 | } else if (preference == mVoicemailSettingsScreen) { |
Yorke Lee | a0f63bf | 2014-10-09 18:27:20 -0700 | [diff] [blame] | 354 | final Dialog dialog = mVoicemailSettingsScreen.getDialog(); |
| 355 | if (dialog != null) { |
| 356 | dialog.getActionBar().setDisplayHomeAsUpEnabled(false); |
| 357 | } |
Andrew Lee | 97708a4 | 2014-09-25 12:39:07 -0700 | [diff] [blame] | 358 | return false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 359 | } |
| 360 | return false; |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Implemented to support onPreferenceChangeListener to look for preference |
| 365 | * changes. |
| 366 | * |
| 367 | * @param preference is the preference to be changed |
| 368 | * @param objValue should be the value of the selection, NOT its localized |
| 369 | * display value. |
| 370 | */ |
| 371 | @Override |
| 372 | public boolean onPreferenceChange(Preference preference, Object objValue) { |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 373 | if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\""); |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 374 | |
| 375 | if (preference == mButtonDTMF) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 376 | int index = mButtonDTMF.findIndexOfValue((String) objValue); |
| 377 | Settings.System.putInt(mPhone.getContext().getContentResolver(), |
| 378 | Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, index); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 379 | } else if (preference == mVoicemailProviders) { |
| 380 | final String newProviderKey = (String) objValue; |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 381 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 382 | // If previous provider key and the new one is same, we don't need to handle it. |
| 383 | if (mPreviousVMProviderKey.equals(newProviderKey)) { |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 384 | if (DBG) log("No change is made to the VM provider setting."); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 385 | return true; |
| 386 | } |
| 387 | updateVMPreferenceWidgets(newProviderKey); |
| 388 | |
Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 389 | final VoicemailProviderSettings newProviderSettings = |
Andrew Lee | 6950c6c | 2014-11-26 12:05:42 -0800 | [diff] [blame] | 390 | VoicemailProviderSettingsUtil.load(this, newProviderKey); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 391 | |
Andrew Lee | 88b51e2 | 2014-10-29 15:48:51 -0700 | [diff] [blame] | 392 | // If the user switches to a voice mail provider and we have numbers stored for it we |
| 393 | // will automatically change the phone's voice mail and forwarding number to the stored |
| 394 | // ones. Otherwise we will bring up provider's configuration UI. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 395 | if (newProviderSettings == null) { |
| 396 | // Force the user into a configuration of the chosen provider |
| 397 | Log.w(LOG_TAG, "Saved preferences not found - invoking config"); |
| 398 | mVMProviderSettingsForced = true; |
| 399 | simulatePreferenceClick(mVoicemailSettings); |
| 400 | } else { |
| 401 | if (DBG) log("Saved preferences found - switching to them"); |
| 402 | // Set this flag so if we get a failure we revert to previous provider |
| 403 | mChangingVMorFwdDueToProviderChange = true; |
| 404 | saveVoiceMailAndForwardingNumber(newProviderKey, newProviderSettings); |
| 405 | } |
Andrew Lee | 8d66d81 | 2014-11-24 14:54:02 -0800 | [diff] [blame] | 406 | } else if (preference.getKey().equals(mVoicemailNotificationVibrate.getKey())) { |
Andrew Lee | 696bff5 | 2014-12-03 17:58:18 -0800 | [diff] [blame] | 407 | // Check key instead of comparing reference because closing the voicemail notification |
| 408 | // ringtone dialog invokes onResume(), but leaves the old preference screen up, |
| 409 | // TODO: Revert to checking reference after migrating voicemail to its own activity. |
Andrew Lee | 8d66d81 | 2014-11-24 14:54:02 -0800 | [diff] [blame] | 410 | VoicemailNotificationSettingsUtil.setVibrationEnabled( |
Andrew Lee | 1ec7c7e | 2014-12-03 15:33:21 -0800 | [diff] [blame] | 411 | mPhone, Boolean.TRUE.equals(objValue)); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 412 | } else if (preference == mEnableVideoCalling) { |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 413 | if (ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())) { |
| 414 | PhoneGlobals.getInstance().phoneMgr.enableVideoCalling((boolean) objValue); |
| 415 | } else { |
| 416 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
| 417 | DialogInterface.OnClickListener networkSettingsClickListener = |
| 418 | new Dialog.OnClickListener() { |
| 419 | @Override |
| 420 | public void onClick(DialogInterface dialog, int which) { |
| 421 | startActivity(new Intent(mPhone.getContext(), |
| 422 | com.android.phone.MobileNetworkSettings.class)); |
| 423 | } |
| 424 | }; |
| 425 | builder.setMessage(getResources().getString( |
| 426 | R.string.enable_video_calling_dialog_msg)) |
| 427 | .setNeutralButton(getResources().getString( |
| 428 | R.string.enable_video_calling_dialog_settings), |
| 429 | networkSettingsClickListener) |
| 430 | .setPositiveButton(android.R.string.ok, null) |
| 431 | .show(); |
| 432 | return false; |
| 433 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 434 | } |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 435 | |
| 436 | // Always let the preference setting proceed. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 437 | return true; |
| 438 | } |
| 439 | |
| 440 | @Override |
| 441 | public void onDialogClosed(EditPhoneNumberPreference preference, int buttonClicked) { |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 442 | if (DBG) log("onDialogClosed: Button clicked is " + buttonClicked); |
| 443 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 444 | if (buttonClicked == DialogInterface.BUTTON_NEGATIVE) { |
| 445 | return; |
| 446 | } |
| 447 | |
| 448 | if (preference == mSubMenuVoicemailSettings) { |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 449 | VoicemailProviderSettings newSettings = new VoicemailProviderSettings( |
| 450 | mSubMenuVoicemailSettings.getPhoneNumber(), |
| 451 | VoicemailProviderSettings.NO_FORWARDING); |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 452 | saveVoiceMailAndForwardingNumber(mVoicemailProviders.getKey(), newSettings); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Implemented for EditPhoneNumberPreference.GetDefaultNumberListener. |
| 458 | * This method set the default values for the various |
| 459 | * EditPhoneNumberPreference dialogs. |
| 460 | */ |
| 461 | @Override |
| 462 | public String onGetDefaultNumber(EditPhoneNumberPreference preference) { |
| 463 | if (preference == mSubMenuVoicemailSettings) { |
| 464 | // update the voicemail number field, which takes care of the |
| 465 | // mSubMenuVoicemailSettings itself, so we should return null. |
| 466 | if (DBG) log("updating default for voicemail dialog"); |
| 467 | updateVoiceNumberField(); |
| 468 | return null; |
| 469 | } |
| 470 | |
| 471 | String vmDisplay = mPhone.getVoiceMailNumber(); |
| 472 | if (TextUtils.isEmpty(vmDisplay)) { |
| 473 | // if there is no voicemail number, we just return null to |
| 474 | // indicate no contribution. |
| 475 | return null; |
| 476 | } |
| 477 | |
| 478 | // Return the voicemail number prepended with "VM: " |
| 479 | if (DBG) log("updating default for call forwarding dialogs"); |
| 480 | return getString(R.string.voicemail_abbreviated) + " " + vmDisplay; |
| 481 | } |
| 482 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 483 | private void switchToPreviousVoicemailProvider() { |
| 484 | if (DBG) log("switchToPreviousVoicemailProvider " + mPreviousVMProviderKey); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 485 | |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 486 | if (mPreviousVMProviderKey == null) { |
| 487 | return; |
| 488 | } |
| 489 | |
| 490 | if (mVMChangeCompletedSuccessfully || mFwdChangesRequireRollback) { |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 491 | showDialogIfForeground(VoicemailDialogUtil.VM_REVERTING_DIALOG); |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 492 | final VoicemailProviderSettings prevSettings = |
Andrew Lee | 6950c6c | 2014-11-26 12:05:42 -0800 | [diff] [blame] | 493 | VoicemailProviderSettingsUtil.load(this, mPreviousVMProviderKey); |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 494 | if (prevSettings == null) { |
| 495 | Log.e(LOG_TAG, "VoicemailProviderSettings for the key \"" |
| 496 | + mPreviousVMProviderKey + "\" is null but should be loaded."); |
| 497 | } |
| 498 | |
| 499 | if (mVMChangeCompletedSuccessfully) { |
| 500 | mNewVMNumber = prevSettings.getVoicemailNumber(); |
| 501 | Log.i(LOG_TAG, "VM change is already completed successfully." |
| 502 | + "Have to revert VM back to " + mNewVMNumber + " again."); |
| 503 | mPhone.setVoiceMailNumber( |
| 504 | mPhone.getVoiceMailAlphaTag().toString(), |
| 505 | mNewVMNumber, |
| 506 | Message.obtain(mRevertOptionComplete, EVENT_VOICEMAIL_CHANGED)); |
| 507 | } |
| 508 | |
| 509 | if (mFwdChangesRequireRollback) { |
| 510 | Log.i(LOG_TAG, "Requested to rollback forwarding changes."); |
| 511 | |
| 512 | final CallForwardInfo[] prevFwdSettings = prevSettings.getForwardingSettings(); |
| 513 | if (prevFwdSettings != null) { |
| 514 | Map<Integer, AsyncResult> results = mForwardingChangeResults; |
| 515 | resetForwardingChangeState(); |
| 516 | for (int i = 0; i < prevFwdSettings.length; i++) { |
| 517 | CallForwardInfo fi = prevFwdSettings[i]; |
| 518 | if (DBG) log("Reverting fwd #: " + i + ": " + fi.toString()); |
| 519 | // Only revert the settings for which the update succeeded. |
| 520 | AsyncResult result = results.get(fi.reason); |
| 521 | if (result != null && result.exception == null) { |
| 522 | mExpectedChangeResultReasons.add(fi.reason); |
| 523 | CallForwardInfoUtil.setCallForwardingOption(mPhone, fi, |
| 524 | mRevertOptionComplete.obtainMessage( |
| 525 | EVENT_FORWARDING_CHANGED, i, 0)); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 529 | } |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 530 | } else { |
| 531 | if (DBG) log("No need to revert"); |
| 532 | onRevertDone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
| 536 | private void onRevertDone() { |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 537 | if (DBG) log("onRevertDone: Changing provider key back to " + mPreviousVMProviderKey); |
| 538 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 539 | updateVMPreferenceWidgets(mPreviousVMProviderKey); |
| 540 | updateVoiceNumberField(); |
| 541 | if (mVMOrFwdSetError != 0) { |
Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 542 | showDialogIfForeground(mVMOrFwdSetError); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 543 | mVMOrFwdSetError = 0; |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | @Override |
| 548 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 549 | if (DBG) { |
| 550 | log("onActivityResult: requestCode: " + requestCode |
| 551 | + ", resultCode: " + resultCode |
| 552 | + ", data: " + data); |
| 553 | } |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 554 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 555 | // there are cases where the contact picker may end up sending us more than one |
| 556 | // request. We want to ignore the request if we're not in the correct state. |
| 557 | if (requestCode == VOICEMAIL_PROVIDER_CFG_ID) { |
| 558 | boolean failure = false; |
| 559 | |
| 560 | // No matter how the processing of result goes lets clear the flag |
| 561 | if (DBG) log("mVMProviderSettingsForced: " + mVMProviderSettingsForced); |
| 562 | final boolean isVMProviderSettingsForced = mVMProviderSettingsForced; |
| 563 | mVMProviderSettingsForced = false; |
| 564 | |
| 565 | String vmNum = null; |
| 566 | if (resultCode != RESULT_OK) { |
| 567 | if (DBG) log("onActivityResult: vm provider cfg result not OK."); |
| 568 | failure = true; |
| 569 | } else { |
| 570 | if (data == null) { |
| 571 | if (DBG) log("onActivityResult: vm provider cfg result has no data"); |
| 572 | failure = true; |
| 573 | } else { |
| 574 | if (data.getBooleanExtra(SIGNOUT_EXTRA, false)) { |
| 575 | if (DBG) log("Provider requested signout"); |
| 576 | if (isVMProviderSettingsForced) { |
| 577 | if (DBG) log("Going back to previous provider on signout"); |
| 578 | switchToPreviousVoicemailProvider(); |
| 579 | } else { |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 580 | final String victim = mVoicemailProviders.getKey(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 581 | if (DBG) log("Relaunching activity and ignoring " + victim); |
| 582 | Intent i = new Intent(ACTION_ADD_VOICEMAIL); |
| 583 | i.putExtra(IGNORE_PROVIDER_EXTRA, victim); |
| 584 | i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 585 | this.startActivity(i); |
| 586 | } |
| 587 | return; |
| 588 | } |
| 589 | vmNum = data.getStringExtra(VM_NUMBER_EXTRA); |
| 590 | if (vmNum == null || vmNum.length() == 0) { |
| 591 | if (DBG) log("onActivityResult: vm provider cfg result has no vmnum"); |
| 592 | failure = true; |
| 593 | } |
| 594 | } |
| 595 | } |
| 596 | if (failure) { |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 597 | if (DBG) log("Failure in return from voicemail provider."); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 598 | if (isVMProviderSettingsForced) { |
| 599 | switchToPreviousVoicemailProvider(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 600 | } |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 601 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 602 | return; |
| 603 | } |
| 604 | mChangingVMorFwdDueToProviderChange = isVMProviderSettingsForced; |
| 605 | final String fwdNum = data.getStringExtra(FWD_NUMBER_EXTRA); |
| 606 | |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 607 | // TODO: It would be nice to load the current network setting for this and |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 608 | // send it to the provider when it's config is invoked so it can use this as default |
| 609 | final int fwdNumTime = data.getIntExtra(FWD_NUMBER_TIME_EXTRA, 20); |
| 610 | |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 611 | if (DBG) log("onActivityResult: cfg result has forwarding number " + fwdNum); |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 612 | saveVoiceMailAndForwardingNumber(mVoicemailProviders.getKey(), |
Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 613 | new VoicemailProviderSettings(vmNum, fwdNum, fwdNumTime)); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 614 | return; |
| 615 | } |
| 616 | |
| 617 | if (requestCode == VOICEMAIL_PREF_ID) { |
| 618 | if (resultCode != RESULT_OK) { |
| 619 | if (DBG) log("onActivityResult: contact picker result not OK."); |
| 620 | return; |
| 621 | } |
| 622 | |
| 623 | Cursor cursor = null; |
| 624 | try { |
| 625 | cursor = getContentResolver().query(data.getData(), |
| 626 | NUM_PROJECTION, null, null, null); |
| 627 | if ((cursor == null) || (!cursor.moveToFirst())) { |
| 628 | if (DBG) log("onActivityResult: bad contact data, no results found."); |
| 629 | return; |
| 630 | } |
| 631 | mSubMenuVoicemailSettings.onPickActivityResult(cursor.getString(0)); |
| 632 | return; |
| 633 | } finally { |
| 634 | if (cursor != null) { |
| 635 | cursor.close(); |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | super.onActivityResult(requestCode, resultCode, data); |
| 641 | } |
| 642 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 643 | /** |
| 644 | * Wrapper around showDialog() that will silently do nothing if we're |
| 645 | * not in the foreground. |
| 646 | * |
| 647 | * This is useful here because most of the dialogs we display from |
| 648 | * this class are triggered by asynchronous events (like |
| 649 | * success/failure messages from the telephony layer) and it's |
| 650 | * possible for those events to come in even after the user has gone |
| 651 | * to a different screen. |
| 652 | */ |
| 653 | // TODO: this is too brittle: it's still easy to accidentally add new |
| 654 | // code here that calls showDialog() directly (which will result in a |
| 655 | // WindowManager$BadTokenException if called after the activity has |
| 656 | // been stopped.) |
| 657 | // |
| 658 | // It would be cleaner to do the "if (mForeground)" check in one |
| 659 | // central place, maybe by using a single Handler for all asynchronous |
| 660 | // events (and have *that* discard events if we're not in the |
| 661 | // foreground.) |
| 662 | // |
| 663 | // Unfortunately it's not that simple, since we sometimes need to do |
| 664 | // actual work to handle these events whether or not we're in the |
| 665 | // foreground (see the Handler code in mSetOptionComplete for |
| 666 | // example.) |
Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 667 | // |
| 668 | // TODO: It's a bit worrisome that we don't do anything in error cases when we're not in the |
| 669 | // foreground. Consider displaying a toast instead. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 670 | private void showDialogIfForeground(int id) { |
| 671 | if (mForeground) { |
| 672 | showDialog(id); |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | private void dismissDialogSafely(int id) { |
| 677 | try { |
| 678 | dismissDialog(id); |
| 679 | } catch (IllegalArgumentException e) { |
| 680 | // This is expected in the case where we were in the background |
| 681 | // at the time we would normally have shown the dialog, so we didn't |
| 682 | // show it. |
| 683 | } |
| 684 | } |
| 685 | |
Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 686 | private void saveVoiceMailAndForwardingNumber( |
| 687 | String key, VoicemailProviderSettings newSettings) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 688 | if (DBG) log("saveVoiceMailAndForwardingNumber: " + newSettings.toString()); |
Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 689 | mNewVMNumber = newSettings.getVoicemailNumber(); |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 690 | mNewVMNumber = (mNewVMNumber == null) ? "" : mNewVMNumber; |
Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 691 | mNewFwdSettings = newSettings.getForwardingSettings(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 692 | |
| 693 | // No fwd settings on CDMA |
| 694 | if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 695 | if (DBG) log("ignoring forwarding setting since this is CDMA phone"); |
Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 696 | mNewFwdSettings = VoicemailProviderSettings.NO_FORWARDING; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Andrew Lee | e3c1521 | 2014-10-28 13:12:55 -0700 | [diff] [blame] | 699 | // Throw a warning if the voicemail is the same and we did not change forwarding. |
Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 700 | if (mNewVMNumber.equals(mOldVmNumber) |
| 701 | && mNewFwdSettings == VoicemailProviderSettings.NO_FORWARDING) { |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 702 | showDialogIfForeground(VoicemailDialogUtil.VM_NOCHANGE_ERROR_DIALOG); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 703 | return; |
| 704 | } |
| 705 | |
Andrew Lee | 6950c6c | 2014-11-26 12:05:42 -0800 | [diff] [blame] | 706 | VoicemailProviderSettingsUtil.save(this, key, newSettings); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 707 | mVMChangeCompletedSuccessfully = false; |
| 708 | mFwdChangesRequireRollback = false; |
| 709 | mVMOrFwdSetError = 0; |
| 710 | if (!key.equals(mPreviousVMProviderKey)) { |
| 711 | mReadingSettingsForDefaultProvider = |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 712 | mPreviousVMProviderKey.equals(VoicemailProviderListPreference.DEFAULT_KEY); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 713 | if (DBG) log("Reading current forwarding settings"); |
Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 714 | int numSettingsReasons = VoicemailProviderSettings.FORWARDING_SETTINGS_REASONS.length; |
| 715 | mForwardingReadResults = new CallForwardInfo[numSettingsReasons]; |
| 716 | for (int i = 0; i < mForwardingReadResults.length; i++) { |
| 717 | mPhone.getCallForwardingOption( |
| 718 | VoicemailProviderSettings.FORWARDING_SETTINGS_REASONS[i], |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 719 | mGetOptionComplete.obtainMessage(EVENT_FORWARDING_GET_COMPLETED, i, 0)); |
| 720 | } |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 721 | showDialogIfForeground(VoicemailDialogUtil.VM_FWD_READING_DIALOG); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 722 | } else { |
| 723 | saveVoiceMailAndForwardingNumberStage2(); |
| 724 | } |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 725 | |
| 726 | // Refresh the MWI indicator if it is already showing. |
| 727 | PhoneGlobals.getInstance().refreshMwiIndicator(mSubscriptionInfoHelper.getSubId()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | private final Handler mGetOptionComplete = new Handler() { |
| 731 | @Override |
| 732 | public void handleMessage(Message msg) { |
| 733 | AsyncResult result = (AsyncResult) msg.obj; |
| 734 | switch (msg.what) { |
| 735 | case EVENT_FORWARDING_GET_COMPLETED: |
| 736 | handleForwardingSettingsReadResult(result, msg.arg1); |
| 737 | break; |
| 738 | } |
| 739 | } |
| 740 | }; |
| 741 | |
| 742 | private void handleForwardingSettingsReadResult(AsyncResult ar, int idx) { |
| 743 | if (DBG) Log.d(LOG_TAG, "handleForwardingSettingsReadResult: " + idx); |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 744 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 745 | Throwable error = null; |
| 746 | if (ar.exception != null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 747 | error = ar.exception; |
Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 748 | if (DBG) Log.d(LOG_TAG, "FwdRead: ar.exception=" + error.getMessage()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 749 | } |
| 750 | if (ar.userObj instanceof Throwable) { |
Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 751 | error = (Throwable) ar.userObj; |
| 752 | if (DBG) Log.d(LOG_TAG, "FwdRead: userObj=" + error.getMessage()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | // We may have already gotten an error and decided to ignore the other results. |
| 756 | if (mForwardingReadResults == null) { |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 757 | if (DBG) Log.d(LOG_TAG, "Ignoring fwd reading result: " + idx); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 758 | return; |
| 759 | } |
| 760 | |
| 761 | // In case of error ignore other results, show an error dialog |
| 762 | if (error != null) { |
| 763 | if (DBG) Log.d(LOG_TAG, "Error discovered for fwd read : " + idx); |
| 764 | mForwardingReadResults = null; |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 765 | dismissDialogSafely(VoicemailDialogUtil.VM_FWD_READING_DIALOG); |
| 766 | showDialogIfForeground(VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 767 | return; |
| 768 | } |
| 769 | |
Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 770 | // Get the forwarding info. |
| 771 | mForwardingReadResults[idx] = CallForwardInfoUtil.getCallForwardInfo( |
| 772 | (CallForwardInfo[]) ar.result, |
| 773 | VoicemailProviderSettings.FORWARDING_SETTINGS_REASONS[idx]); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 774 | |
| 775 | // Check if we got all the results already |
| 776 | boolean done = true; |
| 777 | for (int i = 0; i < mForwardingReadResults.length; i++) { |
| 778 | if (mForwardingReadResults[i] == null) { |
| 779 | done = false; |
| 780 | break; |
| 781 | } |
| 782 | } |
Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 783 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 784 | if (done) { |
| 785 | if (DBG) Log.d(LOG_TAG, "Done receiving fwd info"); |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 786 | dismissDialogSafely(VoicemailDialogUtil.VM_FWD_READING_DIALOG); |
Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 787 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 788 | if (mReadingSettingsForDefaultProvider) { |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 789 | VoicemailProviderSettingsUtil.save(mPhone.getContext(), |
| 790 | VoicemailProviderListPreference.DEFAULT_KEY, |
Andrew Lee | 88b51e2 | 2014-10-29 15:48:51 -0700 | [diff] [blame] | 791 | new VoicemailProviderSettings(this.mOldVmNumber, mForwardingReadResults)); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 792 | mReadingSettingsForDefaultProvider = false; |
| 793 | } |
| 794 | saveVoiceMailAndForwardingNumberStage2(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 795 | } |
| 796 | } |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 797 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 798 | private void resetForwardingChangeState() { |
| 799 | mForwardingChangeResults = new HashMap<Integer, AsyncResult>(); |
| 800 | mExpectedChangeResultReasons = new HashSet<Integer>(); |
| 801 | } |
| 802 | |
| 803 | // Called after we are done saving the previous forwarding settings if |
| 804 | // we needed. |
| 805 | private void saveVoiceMailAndForwardingNumberStage2() { |
| 806 | mForwardingChangeResults = null; |
| 807 | mVoicemailChangeResult = null; |
Andrew Lee | b490d73 | 2014-10-27 15:00:41 -0700 | [diff] [blame] | 808 | if (mNewFwdSettings != VoicemailProviderSettings.NO_FORWARDING) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 809 | resetForwardingChangeState(); |
| 810 | for (int i = 0; i < mNewFwdSettings.length; i++) { |
| 811 | CallForwardInfo fi = mNewFwdSettings[i]; |
Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 812 | CallForwardInfo fiForReason = |
| 813 | CallForwardInfoUtil.infoForReason(mForwardingReadResults, fi.reason); |
| 814 | final boolean doUpdate = CallForwardInfoUtil.isUpdateRequired(fiForReason, fi); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 815 | |
| 816 | if (doUpdate) { |
| 817 | if (DBG) log("Setting fwd #: " + i + ": " + fi.toString()); |
| 818 | mExpectedChangeResultReasons.add(i); |
| 819 | |
Andrew Lee | 1af6cf7 | 2014-11-04 17:35:26 -0800 | [diff] [blame] | 820 | CallForwardInfoUtil.setCallForwardingOption(mPhone, fi, |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 821 | mSetOptionComplete.obtainMessage( |
| 822 | EVENT_FORWARDING_CHANGED, fi.reason, 0)); |
| 823 | } |
| 824 | } |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 825 | showDialogIfForeground(VoicemailDialogUtil.VM_FWD_SAVING_DIALOG); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 826 | } else { |
| 827 | if (DBG) log("Not touching fwd #"); |
| 828 | setVMNumberWithCarrier(); |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | private void setVMNumberWithCarrier() { |
| 833 | if (DBG) log("save voicemail #: " + mNewVMNumber); |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 834 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 835 | mPhone.setVoiceMailNumber( |
| 836 | mPhone.getVoiceMailAlphaTag().toString(), |
| 837 | mNewVMNumber, |
| 838 | Message.obtain(mSetOptionComplete, EVENT_VOICEMAIL_CHANGED)); |
| 839 | } |
| 840 | |
| 841 | /** |
| 842 | * Callback to handle option update completions |
| 843 | */ |
| 844 | private final Handler mSetOptionComplete = new Handler() { |
| 845 | @Override |
| 846 | public void handleMessage(Message msg) { |
| 847 | AsyncResult result = (AsyncResult) msg.obj; |
| 848 | boolean done = false; |
| 849 | switch (msg.what) { |
| 850 | case EVENT_VOICEMAIL_CHANGED: |
| 851 | mVoicemailChangeResult = result; |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 852 | mVMChangeCompletedSuccessfully = isVmChangeSuccess(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 853 | done = true; |
| 854 | break; |
| 855 | case EVENT_FORWARDING_CHANGED: |
| 856 | mForwardingChangeResults.put(msg.arg1, result); |
| 857 | if (result.exception != null) { |
| 858 | Log.w(LOG_TAG, "Error in setting fwd# " + msg.arg1 + ": " + |
| 859 | result.exception.getMessage()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 860 | } |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 861 | if (isForwardingCompleted()) { |
| 862 | if (isFwdChangeSuccess()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 863 | if (DBG) log("Overall fwd changes completed ok, starting vm change"); |
| 864 | setVMNumberWithCarrier(); |
| 865 | } else { |
| 866 | Log.w(LOG_TAG, "Overall fwd changes completed in failure. " + |
| 867 | "Check if we need to try rollback for some settings."); |
| 868 | mFwdChangesRequireRollback = false; |
| 869 | Iterator<Map.Entry<Integer,AsyncResult>> it = |
| 870 | mForwardingChangeResults.entrySet().iterator(); |
| 871 | while (it.hasNext()) { |
| 872 | Map.Entry<Integer,AsyncResult> entry = it.next(); |
| 873 | if (entry.getValue().exception == null) { |
| 874 | // If at least one succeeded we have to revert |
| 875 | Log.i(LOG_TAG, "Rollback will be required"); |
| 876 | mFwdChangesRequireRollback = true; |
| 877 | break; |
| 878 | } |
| 879 | } |
| 880 | if (!mFwdChangesRequireRollback) { |
| 881 | Log.i(LOG_TAG, "No rollback needed."); |
| 882 | } |
| 883 | done = true; |
| 884 | } |
| 885 | } |
| 886 | break; |
| 887 | default: |
| 888 | // TODO: should never reach this, may want to throw exception |
| 889 | } |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 890 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 891 | if (done) { |
| 892 | if (DBG) log("All VM provider related changes done"); |
| 893 | if (mForwardingChangeResults != null) { |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 894 | dismissDialogSafely(VoicemailDialogUtil.VM_FWD_SAVING_DIALOG); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 895 | } |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 896 | handleSetVmOrFwdMessage(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 897 | } |
| 898 | } |
| 899 | }; |
| 900 | |
| 901 | /** |
| 902 | * Callback to handle option revert completions |
| 903 | */ |
| 904 | private final Handler mRevertOptionComplete = new Handler() { |
| 905 | @Override |
| 906 | public void handleMessage(Message msg) { |
| 907 | AsyncResult result = (AsyncResult) msg.obj; |
| 908 | switch (msg.what) { |
| 909 | case EVENT_VOICEMAIL_CHANGED: |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 910 | if (DBG) log("VM revert complete msg"); |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 911 | mVoicemailChangeResult = result; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 912 | break; |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 913 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 914 | case EVENT_FORWARDING_CHANGED: |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 915 | if (DBG) log("FWD revert complete msg "); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 916 | mForwardingChangeResults.put(msg.arg1, result); |
| 917 | if (result.exception != null) { |
| 918 | if (DBG) log("Error in reverting fwd# " + msg.arg1 + ": " + |
| 919 | result.exception.getMessage()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 920 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 921 | break; |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 922 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 923 | default: |
| 924 | // TODO: should never reach this, may want to throw exception |
| 925 | } |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 926 | |
| 927 | final boolean done = (!mVMChangeCompletedSuccessfully || mVoicemailChangeResult != null) |
| 928 | && (!mFwdChangesRequireRollback || isForwardingCompleted()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 929 | if (done) { |
| 930 | if (DBG) log("All VM reverts done"); |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 931 | dismissDialogSafely(VoicemailDialogUtil.VM_REVERTING_DIALOG); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 932 | onRevertDone(); |
| 933 | } |
| 934 | } |
| 935 | }; |
| 936 | |
| 937 | /** |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 938 | * Return true if there is a change result for every reason for which we expect a result. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 939 | */ |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 940 | private boolean isForwardingCompleted() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 941 | if (mForwardingChangeResults == null) { |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 942 | return true; |
| 943 | } |
| 944 | |
| 945 | for (Integer reason : mExpectedChangeResultReasons) { |
| 946 | if (mForwardingChangeResults.get(reason) == null) { |
| 947 | return false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 948 | } |
| 949 | } |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 950 | |
| 951 | return true; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 952 | } |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 953 | |
| 954 | private boolean isFwdChangeSuccess() { |
| 955 | if (mForwardingChangeResults == null) { |
| 956 | return true; |
| 957 | } |
| 958 | |
| 959 | for (AsyncResult result : mForwardingChangeResults.values()) { |
| 960 | Throwable exception = result.exception; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 961 | if (exception != null) { |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 962 | String msg = exception.getMessage(); |
| 963 | msg = (msg != null) ? msg : ""; |
| 964 | Log.w(LOG_TAG, "Failed to change forwarding setting. Reason: " + msg); |
| 965 | return false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 966 | } |
| 967 | } |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 968 | return true; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 969 | } |
| 970 | |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 971 | private boolean isVmChangeSuccess() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 972 | if (mVoicemailChangeResult.exception != null) { |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 973 | String msg = mVoicemailChangeResult.exception.getMessage(); |
| 974 | msg = (msg != null) ? msg : ""; |
| 975 | Log.w(LOG_TAG, "Failed to change voicemail. Reason: " + msg); |
| 976 | return false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 977 | } |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 978 | return true; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 981 | private void handleSetVmOrFwdMessage() { |
| 982 | if (DBG) log("handleSetVMMessage: set VM request complete"); |
| 983 | |
| 984 | if (!isFwdChangeSuccess()) { |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 985 | handleVmOrFwdSetError(VoicemailDialogUtil.FWD_SET_RESPONSE_ERROR_DIALOG); |
Andrew Lee | e438b31 | 2014-10-29 16:59:15 -0700 | [diff] [blame] | 986 | } else if (!isVmChangeSuccess()) { |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 987 | handleVmOrFwdSetError(VoicemailDialogUtil.VM_RESPONSE_ERROR_DIALOG); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 988 | } else { |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 989 | handleVmAndFwdSetSuccess(VoicemailDialogUtil.VM_CONFIRM_DIALOG); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
| 993 | /** |
| 994 | * Called when Voicemail Provider or its forwarding settings failed. Rolls back partly made |
| 995 | * changes to those settings and show "failure" dialog. |
| 996 | * |
Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 997 | * @param dialogId ID of the dialog to show for the specific error case. Either |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 998 | * {@link #FWD_SET_RESPONSE_ERROR_DIALOG} or {@link #VM_RESPONSE_ERROR_DIALOG} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 999 | */ |
Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 1000 | private void handleVmOrFwdSetError(int dialogId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1001 | if (mChangingVMorFwdDueToProviderChange) { |
Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 1002 | mVMOrFwdSetError = dialogId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1003 | mChangingVMorFwdDueToProviderChange = false; |
| 1004 | switchToPreviousVoicemailProvider(); |
| 1005 | return; |
| 1006 | } |
| 1007 | mChangingVMorFwdDueToProviderChange = false; |
Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 1008 | showDialogIfForeground(dialogId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1009 | updateVoiceNumberField(); |
| 1010 | } |
| 1011 | |
| 1012 | /** |
| 1013 | * Called when Voicemail Provider and its forwarding settings were successfully finished. |
| 1014 | * This updates a bunch of variables and show "success" dialog. |
| 1015 | */ |
Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 1016 | private void handleVmAndFwdSetSuccess(int dialogId) { |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 1017 | if (DBG) log("handleVmAndFwdSetSuccess: key is " + mVoicemailProviders.getKey()); |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 1018 | |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 1019 | mPreviousVMProviderKey = mVoicemailProviders.getKey(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1020 | mChangingVMorFwdDueToProviderChange = false; |
Andrew Lee | ab08227 | 2014-11-04 15:50:42 -0800 | [diff] [blame] | 1021 | showDialogIfForeground(dialogId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1022 | updateVoiceNumberField(); |
| 1023 | } |
| 1024 | |
| 1025 | /** |
| 1026 | * Update the voicemail number from what we've recorded on the sim. |
| 1027 | */ |
| 1028 | private void updateVoiceNumberField() { |
Andrew Lee | 2d5d1a4 | 2014-11-05 12:34:14 -0800 | [diff] [blame] | 1029 | if (DBG) log("updateVoiceNumberField()"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1030 | |
| 1031 | mOldVmNumber = mPhone.getVoiceMailNumber(); |
Andrew Lee | 2d5d1a4 | 2014-11-05 12:34:14 -0800 | [diff] [blame] | 1032 | if (TextUtils.isEmpty(mOldVmNumber)) { |
| 1033 | mSubMenuVoicemailSettings.setPhoneNumber(""); |
| 1034 | mSubMenuVoicemailSettings.setSummary(getString(R.string.voicemail_number_not_set)); |
| 1035 | } else { |
| 1036 | mSubMenuVoicemailSettings.setPhoneNumber(mOldVmNumber); |
| 1037 | mSubMenuVoicemailSettings.setSummary(mOldVmNumber); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1038 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | /* |
| 1042 | * Helper Methods for Activity class. |
| 1043 | * The initial query commands are split into two pieces now |
| 1044 | * for individual expansion. This combined with the ability |
| 1045 | * to cancel queries allows for a much better user experience, |
| 1046 | * and also ensures that the user only waits to update the |
| 1047 | * data that is relevant. |
| 1048 | */ |
| 1049 | |
| 1050 | @Override |
| 1051 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 1052 | super.onPrepareDialog(id, dialog); |
| 1053 | mCurrentDialogId = id; |
| 1054 | } |
| 1055 | |
| 1056 | // dialog creation method, called by showDialog() |
| 1057 | @Override |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 1058 | protected Dialog onCreateDialog(int dialogId) { |
| 1059 | return VoicemailDialogUtil.getDialog(this, dialogId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | // This is a method implemented for DialogInterface.OnClickListener. |
| 1063 | // Used with the error dialog to close the app, voicemail dialog to just dismiss. |
| 1064 | // Close button is mapped to BUTTON_POSITIVE for the errors that close the activity, |
| 1065 | // while those that are mapped to BUTTON_NEUTRAL only move the preference focus. |
| 1066 | public void onClick(DialogInterface dialog, int which) { |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 1067 | if (DBG) log("onClick: button clicked is " + which); |
| 1068 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1069 | dialog.dismiss(); |
| 1070 | switch (which){ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1071 | case DialogInterface.BUTTON_NEGATIVE: |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 1072 | if (mCurrentDialogId == VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1073 | // We failed to get current forwarding settings and the user |
| 1074 | // does not wish to continue. |
| 1075 | switchToPreviousVoicemailProvider(); |
| 1076 | } |
| 1077 | break; |
| 1078 | case DialogInterface.BUTTON_POSITIVE: |
Andrew Lee | 8402434 | 2014-11-06 23:37:09 -0800 | [diff] [blame] | 1079 | if (mCurrentDialogId == VoicemailDialogUtil.FWD_GET_RESPONSE_ERROR_DIALOG) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1080 | // We failed to get current forwarding settings but the user |
| 1081 | // wishes to continue changing settings to the new vm provider |
| 1082 | saveVoiceMailAndForwardingNumberStage2(); |
| 1083 | } else { |
| 1084 | finish(); |
| 1085 | } |
| 1086 | return; |
| 1087 | default: |
| 1088 | // just let the dialog close and go back to the input |
| 1089 | } |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 1090 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1091 | // In all dialogs, all buttons except BUTTON_POSITIVE lead to the end of user interaction |
| 1092 | // with settings UI. If we were called to explicitly configure voice mail then |
| 1093 | // we finish the settings activity here to come back to whatever the user was doing. |
| 1094 | if (getIntent().getAction().equals(ACTION_ADD_VOICEMAIL)) { |
| 1095 | finish(); |
| 1096 | } |
| 1097 | } |
| 1098 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1099 | /* |
| 1100 | * Activity class methods |
| 1101 | */ |
| 1102 | |
| 1103 | @Override |
| 1104 | protected void onCreate(Bundle icicle) { |
| 1105 | super.onCreate(icicle); |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 1106 | if (DBG) log("onCreate: Intent is " + getIntent()); |
| 1107 | |
Jay Shrauner | c268473 | 2014-11-12 12:10:37 -0800 | [diff] [blame] | 1108 | // Make sure we are running as the primary user. |
| 1109 | if (UserHandle.myUserId() != UserHandle.USER_OWNER) { |
| 1110 | Toast.makeText(this, R.string.call_settings_primary_user_only, |
| 1111 | Toast.LENGTH_SHORT).show(); |
| 1112 | finish(); |
| 1113 | return; |
| 1114 | } |
| 1115 | |
Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1116 | mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
| 1117 | |
Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1118 | // Show the voicemail preference in onResume if the calling intent specifies the |
| 1119 | // ACTION_ADD_VOICEMAIL action. |
| 1120 | mShowVoicemailPreference = (icicle == null) && |
Jay Shrauner | be2fb26 | 2014-11-11 15:19:58 -0800 | [diff] [blame] | 1121 | TextUtils.equals(getIntent().getAction(), ACTION_ADD_VOICEMAIL); |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 1122 | mSetupVoicemail = mShowVoicemailPreference && |
| 1123 | getIntent().getBooleanExtra(SETUP_VOICEMAIL_EXTRA, false); |
Andrew Lee | 5ed870c | 2014-10-29 11:47:49 -0700 | [diff] [blame] | 1124 | |
Andrew Lee | dd4f6df | 2014-12-09 19:13:51 -0800 | [diff] [blame] | 1125 | mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent()); |
Andrew Lee | 5ed870c | 2014-10-29 11:47:49 -0700 | [diff] [blame] | 1126 | mSubscriptionInfoHelper.setActionBarTitle( |
| 1127 | getActionBar(), getResources(), R.string.call_settings_with_label); |
Andrew Lee | 1479dd1 | 2014-11-06 23:06:32 -0800 | [diff] [blame] | 1128 | mPhone = mSubscriptionInfoHelper.getPhone(); |
Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1131 | @Override |
| 1132 | protected void onResume() { |
| 1133 | super.onResume(); |
| 1134 | mForeground = true; |
| 1135 | |
| 1136 | PreferenceScreen preferenceScreen = getPreferenceScreen(); |
| 1137 | if (preferenceScreen != null) { |
| 1138 | preferenceScreen.removeAll(); |
| 1139 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1140 | |
| 1141 | addPreferencesFromResource(R.xml.call_feature_setting); |
Andrew Lee | 5ed870c | 2014-10-29 11:47:49 -0700 | [diff] [blame] | 1142 | |
Andrew Lee | 6fee2cb | 2014-12-09 16:42:18 -0800 | [diff] [blame] | 1143 | TelecomManager telecomManager = TelecomManager.from(this); |
| 1144 | TelephonyManager telephonyManager = |
| 1145 | (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
| 1146 | |
| 1147 | Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY); |
| 1148 | if (telephonyManager.isMultiSimEnabled() || (telecomManager.getSimCallManagers().isEmpty() |
| 1149 | && !SipUtil.isVoipSupported(mPhone.getContext()))) { |
| 1150 | getPreferenceScreen().removePreference(phoneAccountSettingsPreference); |
| 1151 | } |
Andrew Lee | db2fe56 | 2014-09-03 15:40:43 -0700 | [diff] [blame] | 1152 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1153 | PreferenceScreen prefSet = getPreferenceScreen(); |
Andrew Lee | 64a7d79 | 2014-10-15 17:38:38 -0700 | [diff] [blame] | 1154 | mSubMenuVoicemailSettings = (EditPhoneNumberPreference) findPreference(BUTTON_VOICEMAIL_KEY); |
| 1155 | mSubMenuVoicemailSettings.setParentActivity(this, VOICEMAIL_PREF_ID, this); |
| 1156 | mSubMenuVoicemailSettings.setDialogOnClosedListener(this); |
| 1157 | mSubMenuVoicemailSettings.setDialogTitle(R.string.voicemail_settings_number_label); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1158 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1159 | mButtonDTMF = (ListPreference) findPreference(BUTTON_DTMF_KEY); |
| 1160 | mButtonAutoRetry = (CheckBoxPreference) findPreference(BUTTON_RETRY_KEY); |
| 1161 | mButtonHAC = (CheckBoxPreference) findPreference(BUTTON_HAC_KEY); |
Andrew Lee | 6fee2cb | 2014-12-09 16:42:18 -0800 | [diff] [blame] | 1162 | mButtonTTY = (TtyModeListPreference) findPreference( |
| 1163 | getResources().getString(R.string.tty_mode_key)); |
Andrew Lee | 2170a97 | 2014-08-13 18:13:01 -0700 | [diff] [blame] | 1164 | |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 1165 | mVoicemailProviders = (VoicemailProviderListPreference) findPreference( |
| 1166 | BUTTON_VOICEMAIL_PROVIDER_KEY); |
| 1167 | mVoicemailProviders.init(mPhone, getIntent()); |
Andrew Lee | 2c02789 | 2014-10-29 11:29:54 -0700 | [diff] [blame] | 1168 | mVoicemailProviders.setOnPreferenceChangeListener(this); |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 1169 | mPreviousVMProviderKey = mVoicemailProviders.getValue(); |
Andrew Lee | 8d66d81 | 2014-11-24 14:54:02 -0800 | [diff] [blame] | 1170 | |
Andrew Lee | 2c02789 | 2014-10-29 11:29:54 -0700 | [diff] [blame] | 1171 | mVoicemailSettingsScreen = |
| 1172 | (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY); |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 1173 | mVoicemailSettings = (PreferenceScreen) findPreference(BUTTON_VOICEMAIL_SETTING_KEY); |
Andrew Lee | 8d66d81 | 2014-11-24 14:54:02 -0800 | [diff] [blame] | 1174 | |
Andrew Lee | 1ec7c7e | 2014-12-03 15:33:21 -0800 | [diff] [blame] | 1175 | mVoicemailNotificationRingtone = (VoicemailRingtonePreference) findPreference( |
| 1176 | getResources().getString(R.string.voicemail_notification_ringtone_key)); |
| 1177 | mVoicemailNotificationRingtone.init(mPhone); |
| 1178 | |
Andrew Lee | 8d66d81 | 2014-11-24 14:54:02 -0800 | [diff] [blame] | 1179 | mVoicemailNotificationVibrate = (CheckBoxPreference) findPreference( |
| 1180 | getResources().getString(R.string.voicemail_notification_vibrate_key)); |
| 1181 | mVoicemailNotificationVibrate.setOnPreferenceChangeListener(this); |
| 1182 | |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 1183 | updateVMPreferenceWidgets(mVoicemailProviders.getValue()); |
| 1184 | |
| 1185 | mEnableVideoCalling = (CheckBoxPreference) findPreference(ENABLE_VIDEO_CALLING_KEY); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1186 | |
Andrew Lee | 64a7d79 | 2014-10-15 17:38:38 -0700 | [diff] [blame] | 1187 | if (getResources().getBoolean(R.bool.dtmf_type_enabled)) { |
| 1188 | mButtonDTMF.setOnPreferenceChangeListener(this); |
| 1189 | int dtmf = Settings.System.getInt(getContentResolver(), |
| 1190 | Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, Constants.DTMF_TONE_TYPE_NORMAL); |
| 1191 | mButtonDTMF.setValueIndex(dtmf); |
| 1192 | } else { |
| 1193 | prefSet.removePreference(mButtonDTMF); |
| 1194 | mButtonDTMF = null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
Andrew Lee | 64a7d79 | 2014-10-15 17:38:38 -0700 | [diff] [blame] | 1197 | if (getResources().getBoolean(R.bool.auto_retry_enabled)) { |
| 1198 | mButtonAutoRetry.setOnPreferenceChangeListener(this); |
| 1199 | int autoretry = Settings.Global.getInt( |
| 1200 | getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0); |
| 1201 | mButtonAutoRetry.setChecked(autoretry != 0); |
| 1202 | } else { |
| 1203 | prefSet.removePreference(mButtonAutoRetry); |
| 1204 | mButtonAutoRetry = null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
Andrew Lee | 64a7d79 | 2014-10-15 17:38:38 -0700 | [diff] [blame] | 1207 | if (getResources().getBoolean(R.bool.hac_enabled)) { |
| 1208 | mButtonHAC.setOnPreferenceChangeListener(this); |
| 1209 | int hac = Settings.System.getInt(getContentResolver(), Settings.System.HEARING_AID, 0); |
| 1210 | mButtonHAC.setChecked(hac != 0); |
| 1211 | } else { |
| 1212 | prefSet.removePreference(mButtonHAC); |
| 1213 | mButtonHAC = null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
Andrew Lee | 6fee2cb | 2014-12-09 16:42:18 -0800 | [diff] [blame] | 1216 | if (!telephonyManager.isMultiSimEnabled() && telecomManager.isTtySupported()) { |
| 1217 | mButtonTTY.init(); |
Andrew Lee | 64a7d79 | 2014-10-15 17:38:38 -0700 | [diff] [blame] | 1218 | } else { |
| 1219 | prefSet.removePreference(mButtonTTY); |
| 1220 | mButtonTTY = null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | if (!getResources().getBoolean(R.bool.world_phone)) { |
Andrew Lee | 2b36ba2 | 2014-11-05 17:08:49 -0800 | [diff] [blame] | 1224 | Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS); |
| 1225 | prefSet.removePreference(cdmaOptions); |
| 1226 | |
| 1227 | // TODO: Support MSIM for this preference option. |
| 1228 | Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS); |
| 1229 | prefSet.removePreference(gsmOptions); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1230 | |
| 1231 | int phoneType = mPhone.getPhoneType(); |
Andrew Lee | 5ed870c | 2014-10-29 11:47:49 -0700 | [diff] [blame] | 1232 | Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY); |
Junda Liu | a09d696 | 2014-11-12 13:39:02 -0800 | [diff] [blame] | 1233 | boolean shouldHideCarrierSettings = Settings.Global.getInt( |
| 1234 | getContentResolver(), Settings.Global.HIDE_CARRIER_NETWORK_SETTINGS, 0) == 1; |
| 1235 | if (shouldHideCarrierSettings) { |
Andrew Lee | 5ed870c | 2014-10-29 11:47:49 -0700 | [diff] [blame] | 1236 | prefSet.removePreference(fdnButton); |
Junda Liu | a09d696 | 2014-11-12 13:39:02 -0800 | [diff] [blame] | 1237 | if (mButtonDTMF != null) { |
| 1238 | prefSet.removePreference(mButtonDTMF); |
Etan Cohen | 0ca1c80 | 2014-07-07 15:35:48 -0700 | [diff] [blame] | 1239 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1240 | } else { |
Junda Liu | a09d696 | 2014-11-12 13:39:02 -0800 | [diff] [blame] | 1241 | if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { |
| 1242 | prefSet.removePreference(fdnButton); |
| 1243 | |
| 1244 | if (!getResources().getBoolean(R.bool.config_voice_privacy_disable)) { |
| 1245 | addPreferencesFromResource(R.xml.cdma_call_privacy); |
| 1246 | } |
| 1247 | } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { |
Andrew Lee | dd4f6df | 2014-12-09 19:13:51 -0800 | [diff] [blame] | 1248 | fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class)); |
Junda Liu | a09d696 | 2014-11-12 13:39:02 -0800 | [diff] [blame] | 1249 | |
| 1250 | if (getResources().getBoolean(R.bool.config_additional_call_setting)) { |
| 1251 | addPreferencesFromResource(R.xml.gsm_umts_call_options); |
| 1252 | |
| 1253 | Preference callForwardingPref = prefSet.findPreference(CALL_FORWARDING_KEY); |
| 1254 | callForwardingPref.setIntent(mSubscriptionInfoHelper.getIntent( |
Andrew Lee | dd4f6df | 2014-12-09 19:13:51 -0800 | [diff] [blame] | 1255 | GsmUmtsCallForwardOptions.class)); |
Junda Liu | a09d696 | 2014-11-12 13:39:02 -0800 | [diff] [blame] | 1256 | |
| 1257 | Preference additionalGsmSettingsPref = |
| 1258 | prefSet.findPreference(ADDITIONAL_GSM_SETTINGS_KEY); |
| 1259 | additionalGsmSettingsPref.setIntent(mSubscriptionInfoHelper.getIntent( |
Andrew Lee | dd4f6df | 2014-12-09 19:13:51 -0800 | [diff] [blame] | 1260 | GsmUmtsAdditionalCallOptions.class)); |
Junda Liu | a09d696 | 2014-11-12 13:39:02 -0800 | [diff] [blame] | 1261 | } |
| 1262 | } else { |
| 1263 | throw new IllegalStateException("Unexpected phone type: " + phoneType); |
| 1264 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1265 | } |
| 1266 | } |
| 1267 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1268 | // check the intent that started this activity and pop up the voicemail |
| 1269 | // dialog if we've been asked to. |
| 1270 | // If we have at least one non default VM provider registered then bring up |
| 1271 | // the selection for the VM provider, otherwise bring up a VM number dialog. |
| 1272 | // We only bring up the dialog the first time we are called (not after orientation change) |
Andrew Lee | 2c02789 | 2014-10-29 11:29:54 -0700 | [diff] [blame] | 1273 | if (mShowVoicemailPreference) { |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 1274 | if (DBG) log("ACTION_ADD_VOICEMAIL Intent is thrown"); |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 1275 | if (mSetupVoicemail) { |
| 1276 | simulatePreferenceClick(mVoicemailSettingsScreen); |
| 1277 | mSetupVoicemail = false; |
| 1278 | } else if (mVoicemailProviders.hasMoreThanOneVoicemailProvider()) { |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 1279 | if (DBG) log("Voicemail data has more than one provider."); |
Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1280 | simulatePreferenceClick(mVoicemailProviders); |
| 1281 | } else { |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 1282 | onPreferenceChange(mVoicemailProviders, VoicemailProviderListPreference.DEFAULT_KEY); |
| 1283 | mVoicemailProviders.setValue(VoicemailProviderListPreference.DEFAULT_KEY); |
Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1284 | } |
| 1285 | mShowVoicemailPreference = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1286 | } |
Tyler Gunn | baee295 | 2014-09-10 16:01:02 -0700 | [diff] [blame] | 1287 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1288 | updateVoiceNumberField(); |
| 1289 | mVMProviderSettingsForced = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1290 | |
Andrew Lee | 8d66d81 | 2014-11-24 14:54:02 -0800 | [diff] [blame] | 1291 | mVoicemailNotificationVibrate.setChecked( |
Andrew Lee | 1ec7c7e | 2014-12-03 15:33:21 -0800 | [diff] [blame] | 1292 | VoicemailNotificationSettingsUtil.isVibrationEnabled(mPhone)); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1293 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 1294 | if (ImsManager.isVtEnabledByPlatform(mPhone.getContext()) && ENABLE_VT_FLAG) { |
| 1295 | boolean currentValue = |
| 1296 | ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext()) |
| 1297 | ? PhoneGlobals.getInstance().phoneMgr.isVideoCallingEnabled() : false; |
| 1298 | mEnableVideoCalling.setChecked(currentValue); |
Andrew Lee | 77527ac | 2014-10-21 16:57:39 -0700 | [diff] [blame] | 1299 | mEnableVideoCalling.setOnPreferenceChangeListener(this); |
| 1300 | } else { |
| 1301 | prefSet.removePreference(mEnableVideoCalling); |
| 1302 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1303 | } |
| 1304 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1305 | private static void log(String msg) { |
| 1306 | Log.d(LOG_TAG, msg); |
| 1307 | } |
| 1308 | |
| 1309 | /** |
| 1310 | * Updates the look of the VM preference widgets based on current VM provider settings. |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 1311 | * Note that the provider name is loaded fxrorm the found activity via loadLabel in |
| 1312 | * {@link VoicemailProviderListPreference#initVoiceMailProviders()} in order for it to be |
| 1313 | * localizable. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1314 | */ |
| 1315 | private void updateVMPreferenceWidgets(String currentProviderSetting) { |
| 1316 | final String key = currentProviderSetting; |
Andrew Lee | 64e5c9d | 2014-11-26 12:00:10 -0800 | [diff] [blame] | 1317 | final VoicemailProvider provider = mVoicemailProviders.getVoicemailProvider(key); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1318 | |
| 1319 | /* This is the case when we are coming up on a freshly wiped phone and there is no |
| 1320 | persisted value for the list preference mVoicemailProviders. |
| 1321 | In this case we want to show the UI asking the user to select a voicemail provider as |
| 1322 | opposed to silently falling back to default one. */ |
| 1323 | if (provider == null) { |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 1324 | if (DBG) log("updateVMPreferenceWidget: key: " + key + " -> null."); |
| 1325 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1326 | mVoicemailProviders.setSummary(getString(R.string.sum_voicemail_choose_provider)); |
| 1327 | mVoicemailSettings.setEnabled(false); |
| 1328 | mVoicemailSettings.setIntent(null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1329 | mVoicemailNotificationVibrate.setEnabled(false); |
| 1330 | } else { |
Andrew Lee | 4ddb9bb | 2014-11-05 15:03:20 -0800 | [diff] [blame] | 1331 | if (DBG) log("updateVMPreferenceWidget: key: " + key + " -> " + provider.toString()); |
| 1332 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1333 | final String providerName = provider.name; |
| 1334 | mVoicemailProviders.setSummary(providerName); |
| 1335 | mVoicemailSettings.setEnabled(true); |
| 1336 | mVoicemailSettings.setIntent(provider.intent); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1337 | mVoicemailNotificationVibrate.setEnabled(true); |
| 1338 | } |
| 1339 | } |
| 1340 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1341 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1342 | /** |
| 1343 | * Simulates user clicking on a passed preference. |
| 1344 | * Usually needed when the preference is a dialog preference and we want to invoke |
| 1345 | * a dialog for this preference programmatically. |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 1346 | * TODO: figure out if there is a cleaner way to cause preference dlg to come up |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1347 | */ |
| 1348 | private void simulatePreferenceClick(Preference preference) { |
| 1349 | // Go through settings until we find our setting |
| 1350 | // and then simulate a click on it to bring up the dialog |
| 1351 | final ListAdapter adapter = getPreferenceScreen().getRootAdapter(); |
| 1352 | for (int idx = 0; idx < adapter.getCount(); idx++) { |
| 1353 | if (adapter.getItem(idx) == preference) { |
| 1354 | getPreferenceScreen().onItemClick(this.getListView(), |
| 1355 | null, idx, adapter.getItemId(idx)); |
| 1356 | break; |
| 1357 | } |
| 1358 | } |
| 1359 | } |
| 1360 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1361 | @Override |
| 1362 | public boolean onOptionsItemSelected(MenuItem item) { |
| 1363 | final int itemId = item.getItemId(); |
| 1364 | if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled() |
Yorke Lee | f2d0cac | 2013-09-09 19:42:56 -0700 | [diff] [blame] | 1365 | onBackPressed(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1366 | return true; |
| 1367 | } |
| 1368 | return super.onOptionsItemSelected(item); |
| 1369 | } |
Andrew Lee | 8d66d81 | 2014-11-24 14:54:02 -0800 | [diff] [blame] | 1370 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1371 | /** |
| 1372 | * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}). |
| 1373 | * This is useful for implementing "HomeAsUp" capability for second-level Settings. |
| 1374 | */ |
Andrew Lee | 5efb112 | 2014-12-05 04:20:42 -0800 | [diff] [blame] | 1375 | public static void goUpToTopLevelSetting( |
Andrew Lee | dd4f6df | 2014-12-09 19:13:51 -0800 | [diff] [blame] | 1376 | Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) { |
| 1377 | Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1378 | intent.setAction(Intent.ACTION_MAIN); |
| 1379 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 1380 | activity.startActivity(intent); |
| 1381 | activity.finish(); |
| 1382 | } |
| 1383 | } |