blob: 1b8f96f08f9ac1568a0b5cdbac86270f34df4c36 [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";
94
Andrew Leece8ae2a2014-09-10 10:41:48 -070095 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
96 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -070097
Andrew Leedf14ead2014-10-17 14:22:52 -070098 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
99
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100 private Phone mPhone;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700101 private SubscriptionInfoHelper mSubscriptionInfoHelper;
102
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103 private CheckBoxPreference mButtonAutoRetry;
Andrew Lee97708a42014-09-25 12:39:07 -0700104 private PreferenceScreen mVoicemailSettingsScreen;
Andrew Leedf14ead2014-10-17 14:22:52 -0700105 private CheckBoxPreference mEnableVideoCalling;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107 /*
108 * Click Listeners, handle click based on objects attached to UI.
109 */
110
111 // Click listener for all toggle events
112 @Override
113 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Andrew Leebf07f762015-04-07 19:05:50 -0700114 if (preference == mButtonAutoRetry) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
116 android.provider.Settings.Global.CALL_AUTO_RETRY,
117 mButtonAutoRetry.isChecked() ? 1 : 0);
118 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119 }
120 return false;
121 }
122
123 /**
124 * Implemented to support onPreferenceChangeListener to look for preference
125 * changes.
126 *
127 * @param preference is the preference to be changed
128 * @param objValue should be the value of the selection, NOT its localized
129 * display value.
130 */
131 @Override
132 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800133 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700134
Andrew Leebf07f762015-04-07 19:05:50 -0700135 if (preference == mEnableVideoCalling) {
Andrew Lee312e8172014-10-23 17:01:36 -0700136 if (ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())) {
137 PhoneGlobals.getInstance().phoneMgr.enableVideoCalling((boolean) objValue);
138 } else {
139 AlertDialog.Builder builder = new AlertDialog.Builder(this);
140 DialogInterface.OnClickListener networkSettingsClickListener =
141 new Dialog.OnClickListener() {
142 @Override
143 public void onClick(DialogInterface dialog, int which) {
144 startActivity(new Intent(mPhone.getContext(),
145 com.android.phone.MobileNetworkSettings.class));
146 }
147 };
148 builder.setMessage(getResources().getString(
149 R.string.enable_video_calling_dialog_msg))
150 .setNeutralButton(getResources().getString(
151 R.string.enable_video_calling_dialog_settings),
152 networkSettingsClickListener)
153 .setPositiveButton(android.R.string.ok, null)
154 .show();
155 return false;
156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800158
159 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160 return true;
161 }
162
163 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164 protected void onCreate(Bundle icicle) {
165 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800166 if (DBG) log("onCreate: Intent is " + getIntent());
167
Jay Shraunerc2684732014-11-12 12:10:37 -0800168 // Make sure we are running as the primary user.
169 if (UserHandle.myUserId() != UserHandle.USER_OWNER) {
170 Toast.makeText(this, R.string.call_settings_primary_user_only,
171 Toast.LENGTH_SHORT).show();
172 finish();
173 return;
174 }
175
Andrew Leedd4f6df2014-12-09 19:13:51 -0800176 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5ed870c2014-10-29 11:47:49 -0700177 mSubscriptionInfoHelper.setActionBarTitle(
178 getActionBar(), getResources(), R.string.call_settings_with_label);
Andrew Lee1479dd12014-11-06 23:06:32 -0800179 mPhone = mSubscriptionInfoHelper.getPhone();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700180 }
181
Tyler Gunnbaee2952014-09-10 16:01:02 -0700182 @Override
183 protected void onResume() {
184 super.onResume();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700185
186 PreferenceScreen preferenceScreen = getPreferenceScreen();
187 if (preferenceScreen != null) {
188 preferenceScreen.removeAll();
189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190
191 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -0700192
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800193 TelecomManager telecomManager = TelecomManager.from(this);
194 TelephonyManager telephonyManager =
195 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
196
197 Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
198 if (telephonyManager.isMultiSimEnabled() || (telecomManager.getSimCallManagers().isEmpty()
199 && !SipUtil.isVoipSupported(mPhone.getContext()))) {
200 getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
201 }
Andrew Leedb2fe562014-09-03 15:40:43 -0700202
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700203 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee2c027892014-10-29 11:29:54 -0700204 mVoicemailSettingsScreen =
205 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Leebf07f762015-04-07 19:05:50 -0700206 mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
207 VoicemailSettingsActivity.class));
Andrew Lee8d66d812014-11-24 14:54:02 -0800208
Andrew Leebf07f762015-04-07 19:05:50 -0700209 mButtonAutoRetry = (CheckBoxPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800210
211 mEnableVideoCalling = (CheckBoxPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700212
Andrew Lee64a7d792014-10-15 17:38:38 -0700213 if (getResources().getBoolean(R.bool.auto_retry_enabled)) {
214 mButtonAutoRetry.setOnPreferenceChangeListener(this);
215 int autoretry = Settings.Global.getInt(
216 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
217 mButtonAutoRetry.setChecked(autoretry != 0);
218 } else {
219 prefSet.removePreference(mButtonAutoRetry);
220 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700221 }
222
Sanket Padawee09a6f62015-03-05 11:59:39 -0800223 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
224 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
225 if (getResources().getBoolean(R.bool.world_phone)) {
226 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
227 gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
228 } else {
Andrew Lee2b36ba22014-11-05 17:08:49 -0800229 prefSet.removePreference(cdmaOptions);
Andrew Lee2b36ba22014-11-05 17:08:49 -0800230 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231
232 int phoneType = mPhone.getPhoneType();
Andrew Lee5ed870c2014-10-29 11:47:49 -0700233 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
Junda Liua09d6962014-11-12 13:39:02 -0800234 boolean shouldHideCarrierSettings = Settings.Global.getInt(
235 getContentResolver(), Settings.Global.HIDE_CARRIER_NETWORK_SETTINGS, 0) == 1;
236 if (shouldHideCarrierSettings) {
Andrew Lee5ed870c2014-10-29 11:47:49 -0700237 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238 } else {
Junda Liua09d6962014-11-12 13:39:02 -0800239 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
240 prefSet.removePreference(fdnButton);
241
242 if (!getResources().getBoolean(R.bool.config_voice_privacy_disable)) {
243 addPreferencesFromResource(R.xml.cdma_call_privacy);
244 }
245 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Andrew Leedd4f6df2014-12-09 19:13:51 -0800246 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Junda Liua09d6962014-11-12 13:39:02 -0800247
248 if (getResources().getBoolean(R.bool.config_additional_call_setting)) {
249 addPreferencesFromResource(R.xml.gsm_umts_call_options);
Sanket Padawee09a6f62015-03-05 11:59:39 -0800250 GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
Junda Liua09d6962014-11-12 13:39:02 -0800251 }
252 } else {
253 throw new IllegalStateException("Unexpected phone type: " + phoneType);
254 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700255 }
256 }
257
Andrew Lee312e8172014-10-23 17:01:36 -0700258 if (ImsManager.isVtEnabledByPlatform(mPhone.getContext()) && ENABLE_VT_FLAG) {
259 boolean currentValue =
260 ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Svet Ganovb320e182015-04-16 12:30:10 -0700261 ? PhoneGlobals.getInstance().phoneMgr.isVideoCallingEnabled(
262 getOpPackageName()) : false;
Andrew Lee312e8172014-10-23 17:01:36 -0700263 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -0700264 mEnableVideoCalling.setOnPreferenceChangeListener(this);
265 } else {
266 prefSet.removePreference(mEnableVideoCalling);
267 }
Etan Cohena51d4ef2014-12-15 10:44:42 -0800268
269 if (ImsManager.isVolteEnabledByPlatform(this) &&
270 !mPhone.getContext().getResources().getBoolean(
271 com.android.internal.R.bool.config_carrier_volte_tty_supported)) {
272 TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Vinit Deshpande84cccac2015-03-16 00:08:19 -0700273 /* tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); */
Etan Cohena51d4ef2014-12-15 10:44:42 -0800274 }
Andrew Leeb97fad82015-01-27 15:31:39 -0800275
Andrew Leeeffef9c2015-02-19 16:02:37 -0800276 Preference wifiCallingSettings = findPreference(
277 getResources().getString(R.string.wifi_calling_settings_key));
Andrew Leeb97fad82015-01-27 15:31:39 -0800278 if (!ImsManager.isWfcEnabledByPlatform(mPhone.getContext())) {
Andrew Leeb97fad82015-01-27 15:31:39 -0800279 prefSet.removePreference(wifiCallingSettings);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800280 } else {
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700281 int resId = com.android.internal.R.string.wifi_calling_off_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800282 if (ImsManager.isWfcEnabledByUser(mPhone.getContext())) {
283 int wfcMode = ImsManager.getWfcMode(mPhone.getContext());
284 switch (wfcMode) {
285 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700286 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800287 break;
288 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700289 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800290 break;
291 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700292 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800293 break;
294 default:
295 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
296 }
297 }
298 wifiCallingSettings.setSummary(resId);
Andrew Leeb97fad82015-01-27 15:31:39 -0800299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300 }
301
Andrew Lee785ca2a2014-12-18 12:46:41 -0800302 @Override
303 protected void onNewIntent(Intent newIntent) {
304 setIntent(newIntent);
305
306 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
307 mSubscriptionInfoHelper.setActionBarTitle(
308 getActionBar(), getResources(), R.string.call_settings_with_label);
309 mPhone = mSubscriptionInfoHelper.getPhone();
310 }
311
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312 private static void log(String msg) {
313 Log.d(LOG_TAG, msg);
314 }
315
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316 @Override
317 public boolean onOptionsItemSelected(MenuItem item) {
318 final int itemId = item.getItemId();
319 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -0700320 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700321 return true;
322 }
323 return super.onOptionsItemSelected(item);
324 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800325
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326 /**
327 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
328 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
329 */
Andrew Lee5efb1122014-12-05 04:20:42 -0800330 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800331 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
332 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 intent.setAction(Intent.ACTION_MAIN);
334 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
335 activity.startActivity(intent);
336 activity.finish();
337 }
338}