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