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