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