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