blob: 0c42d18e27044382b055c0acac94d0f8f019c5ac [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
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
17package com.android.phone;
18
19import android.app.ActionBar;
20import android.app.Activity;
Evan Charlton1c696832014-04-15 14:24:23 -070021import android.app.ActivityOptions;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AlertDialog;
23import android.app.Dialog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.content.ContentResolver;
25import android.content.Context;
26import android.content.DialogInterface;
27import android.content.Intent;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.os.Bundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.os.UserHandle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.preference.CheckBoxPreference;
31import android.preference.ListPreference;
32import android.preference.Preference;
33import android.preference.PreferenceActivity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.preference.PreferenceScreen;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.provider.Settings;
Tyler Gunn4d45d1c2014-09-12 22:17:53 -070036import android.telecom.PhoneAccountHandle;
37import android.telecom.TelecomManager;
Andrew Lee93c345f2014-10-27 15:25:07 -070038import android.telephony.TelephonyManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.text.TextUtils;
40import android.util.Log;
41import android.view.MenuItem;
Jay Shraunerc2684732014-11-12 12:10:37 -080042import android.widget.Toast;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043
Andrew Leeeffef9c2015-02-19 16:02:37 -080044import com.android.ims.ImsConfig;
Andrew Lee312e8172014-10-23 17:01:36 -070045import com.android.ims.ImsManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import com.android.internal.telephony.CallForwardInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import com.android.internal.telephony.Phone;
48import com.android.internal.telephony.PhoneConstants;
Andrew Lee2170a972014-08-13 18:13:01 -070049import com.android.phone.common.util.SettingsUtil;
Andrew Leedb2fe562014-09-03 15:40:43 -070050import com.android.phone.settings.AccountSelectionPreference;
Andrew Leebf07f762015-04-07 19:05:50 -070051import com.android.phone.settings.VoicemailSettingsActivity;
Andrew Lee5ed870c2014-10-29 11:47:49 -070052import com.android.phone.settings.fdn.FdnSetting;
Sailesh Nepal788959e2014-07-08 23:36:40 -070053import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054
Andrew Lee2170a972014-08-13 18:13:01 -070055import java.lang.String;
Andrew Leef1776d82014-11-04 14:45:02 -080056import java.util.ArrayList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import java.util.List;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058
59/**
60 * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
61 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070062 * This preference screen is the root of the "Call settings" hierarchy available from the Phone
63 * app; the settings here let you control various features related to phone calls (including
64 * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
65 * voice-capable phone devices.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066 *
67 * Note that this activity is part of the package com.android.phone, even
68 * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
69 * is from the package com.android.contacts.
70 *
71 * For the "Mobile network settings" screen under the main Settings app,
72 * See {@link MobileNetworkSettings}.
73 *
74 * @see com.android.phone.MobileNetworkSettings
75 */
76public class CallFeaturesSetting extends PreferenceActivity
Andrew Leebf07f762015-04-07 19:05:50 -070077 implements Preference.OnPreferenceChangeListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070078 private static final String LOG_TAG = "CallFeaturesSetting";
79 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
Andrew Lee77527ac2014-10-21 16:57:39 -070080 // STOPSHIP if true. Flag to override behavior default behavior to hide VT setting.
81 private static final boolean ENABLE_VT_FLAG = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083 // String keys for preference lookup
84 // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
Andrew Lee8d66d812014-11-24 14:54:02 -080085 // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
86 // in the layout files. These strings need to be treated carefully; if the setting is
87 // persistent, they are used as the key to store shared preferences and the name should not be
88 // changed unless the settings are also migrated.
Andrew Lee97708a42014-09-25 12:39:07 -070089 private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090 private static final String BUTTON_FDN_KEY = "button_fdn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091 private static final String BUTTON_RETRY_KEY = "button_auto_retry_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092 private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
93 private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
Andrew Lee2b36ba22014-11-05 17:08:49 -080094 private static final String CALL_FORWARDING_KEY = "call_forwarding_key";
95 private static final String ADDITIONAL_GSM_SETTINGS_KEY = "additional_gsm_call_settings_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096
Andrew Leece8ae2a2014-09-10 10:41:48 -070097 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
98 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -070099
Andrew Leedf14ead2014-10-17 14:22:52 -0700100 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
101
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102 private Phone mPhone;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700103 private SubscriptionInfoHelper mSubscriptionInfoHelper;
104
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105 private CheckBoxPreference mButtonAutoRetry;
Andrew Lee97708a42014-09-25 12:39:07 -0700106 private PreferenceScreen mVoicemailSettingsScreen;
Andrew Leedf14ead2014-10-17 14:22:52 -0700107 private CheckBoxPreference mEnableVideoCalling;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109 /*
110 * Click Listeners, handle click based on objects attached to UI.
111 */
112
113 // Click listener for all toggle events
114 @Override
115 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Andrew Leebf07f762015-04-07 19:05:50 -0700116 if (preference == mButtonAutoRetry) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
118 android.provider.Settings.Global.CALL_AUTO_RETRY,
119 mButtonAutoRetry.isChecked() ? 1 : 0);
120 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121 }
122 return false;
123 }
124
125 /**
126 * Implemented to support onPreferenceChangeListener to look for preference
127 * changes.
128 *
129 * @param preference is the preference to be changed
130 * @param objValue should be the value of the selection, NOT its localized
131 * display value.
132 */
133 @Override
134 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800135 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700136
Andrew Leebf07f762015-04-07 19:05:50 -0700137 if (preference == mEnableVideoCalling) {
Andrew Lee312e8172014-10-23 17:01:36 -0700138 if (ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())) {
139 PhoneGlobals.getInstance().phoneMgr.enableVideoCalling((boolean) objValue);
140 } else {
141 AlertDialog.Builder builder = new AlertDialog.Builder(this);
142 DialogInterface.OnClickListener networkSettingsClickListener =
143 new Dialog.OnClickListener() {
144 @Override
145 public void onClick(DialogInterface dialog, int which) {
146 startActivity(new Intent(mPhone.getContext(),
147 com.android.phone.MobileNetworkSettings.class));
148 }
149 };
150 builder.setMessage(getResources().getString(
151 R.string.enable_video_calling_dialog_msg))
152 .setNeutralButton(getResources().getString(
153 R.string.enable_video_calling_dialog_settings),
154 networkSettingsClickListener)
155 .setPositiveButton(android.R.string.ok, null)
156 .show();
157 return false;
158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800160
161 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162 return true;
163 }
164
165 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166 protected void onCreate(Bundle icicle) {
167 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800168 if (DBG) log("onCreate: Intent is " + getIntent());
169
Jay Shraunerc2684732014-11-12 12:10:37 -0800170 // Make sure we are running as the primary user.
171 if (UserHandle.myUserId() != UserHandle.USER_OWNER) {
172 Toast.makeText(this, R.string.call_settings_primary_user_only,
173 Toast.LENGTH_SHORT).show();
174 finish();
175 return;
176 }
177
Andrew Leedd4f6df2014-12-09 19:13:51 -0800178 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5ed870c2014-10-29 11:47:49 -0700179 mSubscriptionInfoHelper.setActionBarTitle(
180 getActionBar(), getResources(), R.string.call_settings_with_label);
Andrew Lee1479dd12014-11-06 23:06:32 -0800181 mPhone = mSubscriptionInfoHelper.getPhone();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700182 }
183
Tyler Gunnbaee2952014-09-10 16:01:02 -0700184 @Override
185 protected void onResume() {
186 super.onResume();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700187
188 PreferenceScreen preferenceScreen = getPreferenceScreen();
189 if (preferenceScreen != null) {
190 preferenceScreen.removeAll();
191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192
193 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -0700194
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800195 TelecomManager telecomManager = TelecomManager.from(this);
196 TelephonyManager telephonyManager =
197 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
198
199 Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
200 if (telephonyManager.isMultiSimEnabled() || (telecomManager.getSimCallManagers().isEmpty()
201 && !SipUtil.isVoipSupported(mPhone.getContext()))) {
202 getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
203 }
Andrew Leedb2fe562014-09-03 15:40:43 -0700204
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee2c027892014-10-29 11:29:54 -0700206 mVoicemailSettingsScreen =
207 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Leebf07f762015-04-07 19:05:50 -0700208 mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
209 VoicemailSettingsActivity.class));
Andrew Lee8d66d812014-11-24 14:54:02 -0800210
Andrew Leebf07f762015-04-07 19:05:50 -0700211 mButtonAutoRetry = (CheckBoxPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800212
213 mEnableVideoCalling = (CheckBoxPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700214
Andrew Lee64a7d792014-10-15 17:38:38 -0700215 if (getResources().getBoolean(R.bool.auto_retry_enabled)) {
216 mButtonAutoRetry.setOnPreferenceChangeListener(this);
217 int autoretry = Settings.Global.getInt(
218 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
219 mButtonAutoRetry.setChecked(autoretry != 0);
220 } else {
221 prefSet.removePreference(mButtonAutoRetry);
222 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223 }
224
Andrew Lee9431b832015-03-09 18:46:45 -0700225 if (!PhoneGlobals.getInstance().phoneMgr.isWorldPhone()) {
Andrew Lee2b36ba22014-11-05 17:08:49 -0800226 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
227 prefSet.removePreference(cdmaOptions);
228
229 // TODO: Support MSIM for this preference option.
230 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
231 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232
233 int phoneType = mPhone.getPhoneType();
Andrew Lee5ed870c2014-10-29 11:47:49 -0700234 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
Junda Liua09d6962014-11-12 13:39:02 -0800235 boolean shouldHideCarrierSettings = Settings.Global.getInt(
236 getContentResolver(), Settings.Global.HIDE_CARRIER_NETWORK_SETTINGS, 0) == 1;
237 if (shouldHideCarrierSettings) {
Andrew Lee5ed870c2014-10-29 11:47:49 -0700238 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239 } else {
Junda Liua09d6962014-11-12 13:39:02 -0800240 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
241 prefSet.removePreference(fdnButton);
242
243 if (!getResources().getBoolean(R.bool.config_voice_privacy_disable)) {
244 addPreferencesFromResource(R.xml.cdma_call_privacy);
245 }
246 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Andrew Leedd4f6df2014-12-09 19:13:51 -0800247 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Junda Liua09d6962014-11-12 13:39:02 -0800248
249 if (getResources().getBoolean(R.bool.config_additional_call_setting)) {
250 addPreferencesFromResource(R.xml.gsm_umts_call_options);
251
252 Preference callForwardingPref = prefSet.findPreference(CALL_FORWARDING_KEY);
253 callForwardingPref.setIntent(mSubscriptionInfoHelper.getIntent(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800254 GsmUmtsCallForwardOptions.class));
Junda Liua09d6962014-11-12 13:39:02 -0800255
256 Preference additionalGsmSettingsPref =
257 prefSet.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
258 additionalGsmSettingsPref.setIntent(mSubscriptionInfoHelper.getIntent(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800259 GsmUmtsAdditionalCallOptions.class));
Junda Liua09d6962014-11-12 13:39:02 -0800260 }
261 } else {
262 throw new IllegalStateException("Unexpected phone type: " + phoneType);
263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700264 }
265 }
266
Andrew Lee312e8172014-10-23 17:01:36 -0700267 if (ImsManager.isVtEnabledByPlatform(mPhone.getContext()) && ENABLE_VT_FLAG) {
268 boolean currentValue =
269 ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Svet Ganovb320e182015-04-16 12:30:10 -0700270 ? PhoneGlobals.getInstance().phoneMgr.isVideoCallingEnabled(
271 getOpPackageName()) : false;
Andrew Lee312e8172014-10-23 17:01:36 -0700272 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -0700273 mEnableVideoCalling.setOnPreferenceChangeListener(this);
274 } else {
275 prefSet.removePreference(mEnableVideoCalling);
276 }
Etan Cohena51d4ef2014-12-15 10:44:42 -0800277
278 if (ImsManager.isVolteEnabledByPlatform(this) &&
279 !mPhone.getContext().getResources().getBoolean(
280 com.android.internal.R.bool.config_carrier_volte_tty_supported)) {
281 TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Vinit Deshpande84cccac2015-03-16 00:08:19 -0700282 /* tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); */
Etan Cohena51d4ef2014-12-15 10:44:42 -0800283 }
Andrew Leeb97fad82015-01-27 15:31:39 -0800284
Andrew Leeeffef9c2015-02-19 16:02:37 -0800285 Preference wifiCallingSettings = findPreference(
286 getResources().getString(R.string.wifi_calling_settings_key));
Andrew Leeb97fad82015-01-27 15:31:39 -0800287 if (!ImsManager.isWfcEnabledByPlatform(mPhone.getContext())) {
Andrew Leeb97fad82015-01-27 15:31:39 -0800288 prefSet.removePreference(wifiCallingSettings);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800289 } else {
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700290 int resId = com.android.internal.R.string.wifi_calling_off_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800291 if (ImsManager.isWfcEnabledByUser(mPhone.getContext())) {
292 int wfcMode = ImsManager.getWfcMode(mPhone.getContext());
293 switch (wfcMode) {
294 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700295 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800296 break;
297 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700298 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800299 break;
300 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700301 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800302 break;
303 default:
304 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
305 }
306 }
307 wifiCallingSettings.setSummary(resId);
Andrew Leeb97fad82015-01-27 15:31:39 -0800308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700309 }
310
Andrew Lee785ca2a2014-12-18 12:46:41 -0800311 @Override
312 protected void onNewIntent(Intent newIntent) {
313 setIntent(newIntent);
314
315 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
316 mSubscriptionInfoHelper.setActionBarTitle(
317 getActionBar(), getResources(), R.string.call_settings_with_label);
318 mPhone = mSubscriptionInfoHelper.getPhone();
319 }
320
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700321 private static void log(String msg) {
322 Log.d(LOG_TAG, msg);
323 }
324
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325 @Override
326 public boolean onOptionsItemSelected(MenuItem item) {
327 final int itemId = item.getItemId();
328 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -0700329 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 return true;
331 }
332 return super.onOptionsItemSelected(item);
333 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800334
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335 /**
336 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
337 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
338 */
Andrew Lee5efb1122014-12-05 04:20:42 -0800339 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800340 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
341 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 intent.setAction(Intent.ACTION_MAIN);
343 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
344 activity.startActivity(intent);
345 activity.finish();
346 }
347}