blob: a0c0510d3ca89693e67b375458724b597f805f54 [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;
Jonathan Basseri4b40ff42015-04-30 21:54:10 -070038import android.telephony.CarrierConfigManager;
Andrew Lee93c345f2014-10-27 15:25:07 -070039import android.telephony.TelephonyManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.text.TextUtils;
41import android.util.Log;
42import android.view.MenuItem;
Jay Shraunerc2684732014-11-12 12:10:37 -080043import android.widget.Toast;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044
Andrew Leeeffef9c2015-02-19 16:02:37 -080045import com.android.ims.ImsConfig;
Andrew Lee312e8172014-10-23 17:01:36 -070046import com.android.ims.ImsManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import com.android.internal.telephony.CallForwardInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import com.android.internal.telephony.Phone;
49import com.android.internal.telephony.PhoneConstants;
Andrew Lee2170a972014-08-13 18:13:01 -070050import com.android.phone.common.util.SettingsUtil;
Andrew Leedb2fe562014-09-03 15:40:43 -070051import com.android.phone.settings.AccountSelectionPreference;
Andrew Leebf07f762015-04-07 19:05:50 -070052import com.android.phone.settings.VoicemailSettingsActivity;
Andrew Lee5ed870c2014-10-29 11:47:49 -070053import com.android.phone.settings.fdn.FdnSetting;
Sailesh Nepal788959e2014-07-08 23:36:40 -070054import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055
Andrew Lee2170a972014-08-13 18:13:01 -070056import java.lang.String;
Andrew Leef1776d82014-11-04 14:45:02 -080057import java.util.ArrayList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import java.util.List;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059
60/**
61 * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
62 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070063 * This preference screen is the root of the "Call settings" hierarchy available from the Phone
64 * app; the settings here let you control various features related to phone calls (including
65 * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
66 * voice-capable phone devices.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067 *
68 * Note that this activity is part of the package com.android.phone, even
69 * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
70 * is from the package com.android.contacts.
71 *
72 * For the "Mobile network settings" screen under the main Settings app,
73 * See {@link MobileNetworkSettings}.
74 *
75 * @see com.android.phone.MobileNetworkSettings
76 */
77public class CallFeaturesSetting extends PreferenceActivity
Andrew Leebf07f762015-04-07 19:05:50 -070078 implements Preference.OnPreferenceChangeListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079 private static final String LOG_TAG = "CallFeaturesSetting";
80 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
Andrew Lee77527ac2014-10-21 16:57:39 -070081 // STOPSHIP if true. Flag to override behavior default behavior to hide VT setting.
82 private static final boolean ENABLE_VT_FLAG = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084 // String keys for preference lookup
85 // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
Andrew Lee8d66d812014-11-24 14:54:02 -080086 // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
87 // in the layout files. These strings need to be treated carefully; if the setting is
88 // persistent, they are used as the key to store shared preferences and the name should not be
89 // changed unless the settings are also migrated.
Andrew Lee97708a42014-09-25 12:39:07 -070090 private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091 private static final String BUTTON_FDN_KEY = "button_fdn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092 private static final String BUTTON_RETRY_KEY = "button_auto_retry_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093 private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
94 private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
95
Andrew Leece8ae2a2014-09-10 10:41:48 -070096 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
97 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -070098
Andrew Leedf14ead2014-10-17 14:22:52 -070099 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
100
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700101 private Phone mPhone;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700102 private SubscriptionInfoHelper mSubscriptionInfoHelper;
103
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104 private CheckBoxPreference mButtonAutoRetry;
Andrew Lee97708a42014-09-25 12:39:07 -0700105 private PreferenceScreen mVoicemailSettingsScreen;
Andrew Leedf14ead2014-10-17 14:22:52 -0700106 private CheckBoxPreference mEnableVideoCalling;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108 /*
109 * Click Listeners, handle click based on objects attached to UI.
110 */
111
112 // Click listener for all toggle events
113 @Override
114 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Andrew Leebf07f762015-04-07 19:05:50 -0700115 if (preference == mButtonAutoRetry) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
117 android.provider.Settings.Global.CALL_AUTO_RETRY,
118 mButtonAutoRetry.isChecked() ? 1 : 0);
119 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120 }
121 return false;
122 }
123
124 /**
125 * Implemented to support onPreferenceChangeListener to look for preference
126 * changes.
127 *
128 * @param preference is the preference to be changed
129 * @param objValue should be the value of the selection, NOT its localized
130 * display value.
131 */
132 @Override
133 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800134 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700135
Andrew Leebf07f762015-04-07 19:05:50 -0700136 if (preference == mEnableVideoCalling) {
Andrew Lee312e8172014-10-23 17:01:36 -0700137 if (ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())) {
138 PhoneGlobals.getInstance().phoneMgr.enableVideoCalling((boolean) objValue);
139 } else {
140 AlertDialog.Builder builder = new AlertDialog.Builder(this);
141 DialogInterface.OnClickListener networkSettingsClickListener =
142 new Dialog.OnClickListener() {
143 @Override
144 public void onClick(DialogInterface dialog, int which) {
145 startActivity(new Intent(mPhone.getContext(),
146 com.android.phone.MobileNetworkSettings.class));
147 }
148 };
149 builder.setMessage(getResources().getString(
150 R.string.enable_video_calling_dialog_msg))
151 .setNeutralButton(getResources().getString(
152 R.string.enable_video_calling_dialog_settings),
153 networkSettingsClickListener)
154 .setPositiveButton(android.R.string.ok, null)
155 .show();
156 return false;
157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800159
160 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161 return true;
162 }
163
164 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165 protected void onCreate(Bundle icicle) {
166 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800167 if (DBG) log("onCreate: Intent is " + getIntent());
168
Jay Shraunerc2684732014-11-12 12:10:37 -0800169 // Make sure we are running as the primary user.
170 if (UserHandle.myUserId() != UserHandle.USER_OWNER) {
171 Toast.makeText(this, R.string.call_settings_primary_user_only,
172 Toast.LENGTH_SHORT).show();
173 finish();
174 return;
175 }
176
Andrew Leedd4f6df2014-12-09 19:13:51 -0800177 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5ed870c2014-10-29 11:47:49 -0700178 mSubscriptionInfoHelper.setActionBarTitle(
179 getActionBar(), getResources(), R.string.call_settings_with_label);
Andrew Lee1479dd12014-11-06 23:06:32 -0800180 mPhone = mSubscriptionInfoHelper.getPhone();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700181 }
182
Tyler Gunnbaee2952014-09-10 16:01:02 -0700183 @Override
184 protected void onResume() {
185 super.onResume();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700186
187 PreferenceScreen preferenceScreen = getPreferenceScreen();
188 if (preferenceScreen != null) {
189 preferenceScreen.removeAll();
190 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191
192 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -0700193
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800194 TelecomManager telecomManager = TelecomManager.from(this);
195 TelephonyManager telephonyManager =
196 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
197
198 Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
199 if (telephonyManager.isMultiSimEnabled() || (telecomManager.getSimCallManagers().isEmpty()
200 && !SipUtil.isVoipSupported(mPhone.getContext()))) {
201 getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
202 }
Andrew Leedb2fe562014-09-03 15:40:43 -0700203
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee2c027892014-10-29 11:29:54 -0700205 mVoicemailSettingsScreen =
206 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Leebf07f762015-04-07 19:05:50 -0700207 mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
208 VoicemailSettingsActivity.class));
Andrew Lee8d66d812014-11-24 14:54:02 -0800209
Andrew Leebf07f762015-04-07 19:05:50 -0700210 mButtonAutoRetry = (CheckBoxPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800211
212 mEnableVideoCalling = (CheckBoxPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700214 Bundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
215
216 if (carrierConfig.getBoolean(CarrierConfigManager.BOOL_AUTO_RETRY_ENABLED)) {
Andrew Lee64a7d792014-10-15 17:38:38 -0700217 mButtonAutoRetry.setOnPreferenceChangeListener(this);
218 int autoretry = Settings.Global.getInt(
219 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
220 mButtonAutoRetry.setChecked(autoretry != 0);
221 } else {
222 prefSet.removePreference(mButtonAutoRetry);
223 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224 }
225
Sanket Padawee09a6f62015-03-05 11:59:39 -0800226 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
227 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700228 if (carrierConfig.getBoolean(CarrierConfigManager.BOOL_WORLD_PHONE)) {
Sanket Padawee09a6f62015-03-05 11:59:39 -0800229 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
230 gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
231 } else {
Andrew Lee2b36ba22014-11-05 17:08:49 -0800232 prefSet.removePreference(cdmaOptions);
Andrew Lee2b36ba22014-11-05 17:08:49 -0800233 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234
235 int phoneType = mPhone.getPhoneType();
Andrew Lee5ed870c2014-10-29 11:47:49 -0700236 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
Junda Liua09d6962014-11-12 13:39:02 -0800237 boolean shouldHideCarrierSettings = Settings.Global.getInt(
238 getContentResolver(), Settings.Global.HIDE_CARRIER_NETWORK_SETTINGS, 0) == 1;
239 if (shouldHideCarrierSettings) {
Andrew Lee5ed870c2014-10-29 11:47:49 -0700240 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241 } else {
Junda Liua09d6962014-11-12 13:39:02 -0800242 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
243 prefSet.removePreference(fdnButton);
244
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700245 if (!carrierConfig.getBoolean(CarrierConfigManager.BOOL_VOICE_PRIVACY_DISABLE)) {
Junda Liua09d6962014-11-12 13:39:02 -0800246 addPreferencesFromResource(R.xml.cdma_call_privacy);
247 }
248 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Andrew Leedd4f6df2014-12-09 19:13:51 -0800249 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Junda Liua09d6962014-11-12 13:39:02 -0800250
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700251 if (carrierConfig.getBoolean(CarrierConfigManager.BOOL_ADDITIONAL_CALL_SETTING)) {
Junda Liua09d6962014-11-12 13:39:02 -0800252 addPreferencesFromResource(R.xml.gsm_umts_call_options);
Sanket Padawee09a6f62015-03-05 11:59:39 -0800253 GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
Junda Liua09d6962014-11-12 13:39:02 -0800254 }
255 } else {
256 throw new IllegalStateException("Unexpected phone type: " + phoneType);
257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 }
259 }
260
Andrew Lee312e8172014-10-23 17:01:36 -0700261 if (ImsManager.isVtEnabledByPlatform(mPhone.getContext()) && ENABLE_VT_FLAG) {
262 boolean currentValue =
263 ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Svet Ganovb320e182015-04-16 12:30:10 -0700264 ? PhoneGlobals.getInstance().phoneMgr.isVideoCallingEnabled(
265 getOpPackageName()) : false;
Andrew Lee312e8172014-10-23 17:01:36 -0700266 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -0700267 mEnableVideoCalling.setOnPreferenceChangeListener(this);
268 } else {
269 prefSet.removePreference(mEnableVideoCalling);
270 }
Etan Cohena51d4ef2014-12-15 10:44:42 -0800271
272 if (ImsManager.isVolteEnabledByPlatform(this) &&
273 !mPhone.getContext().getResources().getBoolean(
274 com.android.internal.R.bool.config_carrier_volte_tty_supported)) {
275 TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Vinit Deshpande84cccac2015-03-16 00:08:19 -0700276 /* tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); */
Etan Cohena51d4ef2014-12-15 10:44:42 -0800277 }
Andrew Leeb97fad82015-01-27 15:31:39 -0800278
Andrew Leeeffef9c2015-02-19 16:02:37 -0800279 Preference wifiCallingSettings = findPreference(
280 getResources().getString(R.string.wifi_calling_settings_key));
Andrew Leeb97fad82015-01-27 15:31:39 -0800281 if (!ImsManager.isWfcEnabledByPlatform(mPhone.getContext())) {
Andrew Leeb97fad82015-01-27 15:31:39 -0800282 prefSet.removePreference(wifiCallingSettings);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800283 } else {
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700284 int resId = com.android.internal.R.string.wifi_calling_off_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800285 if (ImsManager.isWfcEnabledByUser(mPhone.getContext())) {
286 int wfcMode = ImsManager.getWfcMode(mPhone.getContext());
287 switch (wfcMode) {
288 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700289 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800290 break;
291 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700292 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800293 break;
294 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700295 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800296 break;
297 default:
298 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
299 }
300 }
301 wifiCallingSettings.setSummary(resId);
Andrew Leeb97fad82015-01-27 15:31:39 -0800302 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303 }
304
Andrew Lee785ca2a2014-12-18 12:46:41 -0800305 @Override
306 protected void onNewIntent(Intent newIntent) {
307 setIntent(newIntent);
308
309 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
310 mSubscriptionInfoHelper.setActionBarTitle(
311 getActionBar(), getResources(), R.string.call_settings_with_label);
312 mPhone = mSubscriptionInfoHelper.getPhone();
313 }
314
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315 private static void log(String msg) {
316 Log.d(LOG_TAG, msg);
317 }
318
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 @Override
320 public boolean onOptionsItemSelected(MenuItem item) {
321 final int itemId = item.getItemId();
322 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -0700323 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324 return true;
325 }
326 return super.onOptionsItemSelected(item);
327 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800328
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 /**
330 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
331 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
332 */
Andrew Lee5efb1122014-12-05 04:20:42 -0800333 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800334 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
335 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 intent.setAction(Intent.ACTION_MAIN);
337 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
338 activity.startActivity(intent);
339 activity.finish();
340 }
341}