blob: e5e02fa9ddfc199e2d75dd18ec0f8a38bbfa090d [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
Santos Cordon7d4ddf62013-07-10 11:58:08 -070019import android.app.Activity;
20import android.app.AlertDialog;
21import android.app.Dialog;
Pengquan Mengdb6b87e2019-06-18 17:42:16 -070022import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.content.Context;
24import android.content.DialogInterface;
25import android.content.Intent;
Yorke Lee0b8d2252015-06-10 16:31:20 -070026import android.content.pm.PackageManager;
Ta-wei Yenb8e770c2017-01-24 17:49:58 -080027import android.content.pm.PackageManager.NameNotFoundException;
Yorke Lee0b8d2252015-06-10 16:31:20 -070028import android.content.pm.ResolveInfo;
Torbjorn Eklund209ed792019-03-06 15:15:30 +010029import android.content.res.Resources;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.os.Bundle;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070031import android.os.PersistableBundle;
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -070032import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.preference.Preference;
34import android.preference.PreferenceActivity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.preference.PreferenceScreen;
fionaxue46e69f2017-04-27 14:32:46 -070036import android.preference.SwitchPreference;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.provider.Settings;
Tyler Gunn4d45d1c2014-09-12 22:17:53 -070038import android.telecom.PhoneAccountHandle;
39import android.telecom.TelecomManager;
Jonathan Basseri4b40ff42015-04-30 21:54:10 -070040import android.telephony.CarrierConfigManager;
pkanwarb4aef112016-07-17 15:39:30 -070041import android.telephony.PhoneStateListener;
Wenting Xiong6fec4552018-08-04 17:56:50 +080042import android.telephony.SubscriptionManager;
Andrew Lee93c345f2014-10-27 15:25:07 -070043import android.telephony.TelephonyManager;
Torbjorn Eklund82d5d742018-11-29 15:32:13 +010044import android.telephony.ims.ProvisioningManager;
Malcolm Chen995721f2017-12-12 18:19:27 -080045import android.telephony.ims.feature.ImsFeature;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.util.Log;
47import android.view.MenuItem;
Jay Shraunerc2684732014-11-12 12:10:37 -080048import android.widget.Toast;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049
Andrew Leeeffef9c2015-02-19 16:02:37 -080050import com.android.ims.ImsConfig;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +053051import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070052import com.android.ims.ImsManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import com.android.internal.telephony.Phone;
54import com.android.internal.telephony.PhoneConstants;
Santos Cordon499378a2015-06-25 18:51:39 -070055import com.android.phone.settings.PhoneAccountSettingsFragment;
SongFerngWangbed485e2018-07-09 21:15:29 +080056import com.android.phone.settings.SuppServicesUiUtil;
Andrew Leebf07f762015-04-07 19:05:50 -070057import com.android.phone.settings.VoicemailSettingsActivity;
Andrew Lee5ed870c2014-10-29 11:47:49 -070058import com.android.phone.settings.fdn.FdnSetting;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import java.util.List;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061
62/**
63 * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
64 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070065 * This preference screen is the root of the "Call settings" hierarchy available from the Phone
66 * app; the settings here let you control various features related to phone calls (including
67 * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
68 * voice-capable phone devices.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069 *
70 * Note that this activity is part of the package com.android.phone, even
71 * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
72 * is from the package com.android.contacts.
73 *
74 * For the "Mobile network settings" screen under the main Settings app,
Pengquan Mengdb6b87e2019-06-18 17:42:16 -070075 * See {@link com.android.settings.network.telephony.MobileNetworkActivity}.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076 */
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);
81
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082 // String keys for preference lookup
83 // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
Andrew Lee8d66d812014-11-24 14:54:02 -080084 // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
85 // in the layout files. These strings need to be treated carefully; if the setting is
86 // persistent, they are used as the key to store shared preferences and the name should not be
87 // changed unless the settings are also migrated.
Andrew Lee97708a42014-09-25 12:39:07 -070088 private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089 private static final String BUTTON_FDN_KEY = "button_fdn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090 private static final String BUTTON_RETRY_KEY = "button_auto_retry_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091 private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
92 private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
93
Andrew Leece8ae2a2014-09-10 10:41:48 -070094 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
95 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -070096
Andrew Leedf14ead2014-10-17 14:22:52 -070097 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
98
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099 private Phone mPhone;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530100 private ImsManager mImsMgr;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700101 private SubscriptionInfoHelper mSubscriptionInfoHelper;
Yorke Lee0b8d2252015-06-10 16:31:20 -0700102 private TelecomManager mTelecomManager;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700103
fionaxue46e69f2017-04-27 14:32:46 -0700104 private SwitchPreference mButtonAutoRetry;
Andrew Lee97708a42014-09-25 12:39:07 -0700105 private PreferenceScreen mVoicemailSettingsScreen;
fionaxue46e69f2017-04-27 14:32:46 -0700106 private SwitchPreference mEnableVideoCalling;
Malcolm Chen4042eb42018-02-26 15:58:44 -0800107 private Preference mButtonWifiCalling;
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;
SongFerngWangbed485e2018-07-09 21:15:29 +0800121 } else if (preference == preferenceScreen.findPreference(
122 GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
123 return doSsOverUtPrecautions(preference);
124 } else if (preference == preferenceScreen.findPreference(
125 GsmUmtsCallOptions.CALL_BARRING_KEY)) {
126 return doSsOverUtPrecautions(preference);
127 }
128 return false;
129 }
130
131 private boolean doSsOverUtPrecautions(Preference preference) {
132 PersistableBundle b = null;
133 if (mSubscriptionInfoHelper.hasSubId()) {
134 b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
135 mSubscriptionInfoHelper.getSubId());
136 } else {
137 b = PhoneGlobals.getInstance().getCarrierConfig();
138 }
139
140 String configKey;
141 if (preference.getKey().equals(GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
142 configKey = CarrierConfigManager.KEY_CALL_FORWARDING_OVER_UT_WARNING_BOOL;
143 } else {
144 configKey = CarrierConfigManager.KEY_CALL_BARRING_OVER_UT_WARNING_BOOL;
145 }
146 if (b != null && b.getBoolean(configKey)
147 && mPhone != null
148 && SuppServicesUiUtil.isSsOverUtPrecautions(this, mPhone)) {
149 SuppServicesUiUtil.showBlockingSuppServicesDialog(this, mPhone,
150 preference.getKey()).show();
151 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152 }
153 return false;
154 }
155
156 /**
157 * Implemented to support onPreferenceChangeListener to look for preference
158 * changes.
159 *
160 * @param preference is the preference to be changed
161 * @param objValue should be the value of the selection, NOT its localized
162 * display value.
163 */
164 @Override
165 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800166 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700167
Andrew Leebf07f762015-04-07 19:05:50 -0700168 if (preference == mEnableVideoCalling) {
Malcolm Chen995721f2017-12-12 18:19:27 -0800169 if (mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530170 mImsMgr.setVtSetting((boolean) objValue);
Andrew Lee312e8172014-10-23 17:01:36 -0700171 } else {
172 AlertDialog.Builder builder = new AlertDialog.Builder(this);
173 DialogInterface.OnClickListener networkSettingsClickListener =
174 new Dialog.OnClickListener() {
175 @Override
176 public void onClick(DialogInterface dialog, int which) {
Pengquan Mengdb6b87e2019-06-18 17:42:16 -0700177 Intent intent = new Intent(Intent.ACTION_MAIN);
178 ComponentName mobileNetworkSettingsComponent = new ComponentName(
179 getString(R.string.mobile_network_settings_package),
180 getString(R.string.mobile_network_settings_class));
181 intent.setComponent(mobileNetworkSettingsComponent);
182 startActivity(intent);
Andrew Lee312e8172014-10-23 17:01:36 -0700183 }
184 };
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100185 builder.setMessage(getResourcesForSubId().getString(
Andrew Lee312e8172014-10-23 17:01:36 -0700186 R.string.enable_video_calling_dialog_msg))
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100187 .setNeutralButton(getResourcesForSubId().getString(
Andrew Lee312e8172014-10-23 17:01:36 -0700188 R.string.enable_video_calling_dialog_settings),
189 networkSettingsClickListener)
190 .setPositiveButton(android.R.string.ok, null)
191 .show();
192 return false;
193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800195
196 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197 return true;
198 }
199
200 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 protected void onCreate(Bundle icicle) {
202 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800203 if (DBG) log("onCreate: Intent is " + getIntent());
204
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -0700205 // Make sure we are running as an admin user.
Meng Wangc04cd2d2019-10-04 12:00:06 -0700206 UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
207 if (!userManager.isAdminUser()) {
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -0700208 Toast.makeText(this, R.string.call_settings_admin_user_only,
Jay Shraunerc2684732014-11-12 12:10:37 -0800209 Toast.LENGTH_SHORT).show();
210 finish();
211 return;
212 }
213
Andrew Leedd4f6df2014-12-09 19:13:51 -0800214 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee1479dd12014-11-06 23:06:32 -0800215 mPhone = mSubscriptionInfoHelper.getPhone();
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100216 mSubscriptionInfoHelper.setActionBarTitle(
217 getActionBar(), getResourcesForSubId(), R.string.call_settings_with_label);
Tyler Gunn77ee9382019-10-31 13:08:23 -0700218 mTelecomManager = getSystemService(TelecomManager.class);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700219 }
220
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530221 private void updateImsManager(Phone phone) {
222 log("updateImsManager :: phone.getContext()=" + phone.getContext()
223 + " phone.getPhoneId()=" + phone.getPhoneId());
224 mImsMgr = ImsManager.getInstance(phone.getContext(), phone.getPhoneId());
225 if (mImsMgr == null) {
226 log("updateImsManager :: Could not get ImsManager instance!");
227 } else {
228 log("updateImsManager :: mImsMgr=" + mImsMgr);
229 }
230 }
231
Omata Shou81a0c8a2018-07-19 18:57:02 +0900232 private void listenPhoneState(boolean listen) {
Kazuki Iwami940af4d2019-02-25 18:07:38 +0900233 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
234 .createForSubscriptionId(mPhone.getSubId());
Omata Shou81a0c8a2018-07-19 18:57:02 +0900235 telephonyManager.listen(mPhoneStateListener, listen
236 ? PhoneStateListener.LISTEN_CALL_STATE : PhoneStateListener.LISTEN_NONE);
237 }
238
pkanwarb4aef112016-07-17 15:39:30 -0700239 private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
240 @Override
241 public void onCallStateChanged(int state, String incomingNumber) {
242 if (DBG) log("PhoneStateListener onCallStateChanged: state is " + state);
Kazuki Iwami940af4d2019-02-25 18:07:38 +0900243 boolean isCallStateIdle = state == TelephonyManager.CALL_STATE_IDLE;
pkanwarb4aef112016-07-17 15:39:30 -0700244 if (mEnableVideoCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530245 mEnableVideoCalling.setEnabled(isCallStateIdle);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900246 }
247 if (mButtonWifiCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530248 mButtonWifiCalling.setEnabled(isCallStateIdle);
pkanwarb4aef112016-07-17 15:39:30 -0700249 }
250 }
251 };
252
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100253 private final ProvisioningManager.Callback mProvisioningCallback =
254 new ProvisioningManager.Callback() {
255 @Override
256 public void onProvisioningIntChanged(int item, int value) {
257 if (item == ImsConfig.ConfigConstants.VOICE_OVER_WIFI_SETTING_ENABLED
258 || item == ImsConfig.ConfigConstants.VLT_SETTING_ENABLED
259 || item == ImsConfig.ConfigConstants.LVC_SETTING_ENABLED) {
260 updateVtWfc();
261 }
262 }
263 };
264
pkanwarb4aef112016-07-17 15:39:30 -0700265 @Override
266 protected void onPause() {
pkanwar0a663122016-07-19 12:26:44 -0700267 super.onPause();
Omata Shou81a0c8a2018-07-19 18:57:02 +0900268 listenPhoneState(false);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100269
270 // Remove callback for provisioning changes.
271 try {
272 if (mImsMgr != null) {
273 mImsMgr.getConfigInterface().removeConfigCallback(
274 mProvisioningCallback.getBinder());
275 }
276 } catch (ImsException e) {
277 Log.w(LOG_TAG, "onPause: Unable to remove callback for provisioning changes");
278 }
pkanwarb4aef112016-07-17 15:39:30 -0700279 }
280
Tyler Gunnbaee2952014-09-10 16:01:02 -0700281 @Override
282 protected void onResume() {
283 super.onResume();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700284
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530285 updateImsManager(mPhone);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900286 listenPhoneState(true);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700287 PreferenceScreen preferenceScreen = getPreferenceScreen();
288 if (preferenceScreen != null) {
289 preferenceScreen.removeAll();
290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291
292 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -0700293
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530294 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
295 .createForSubscriptionId(mPhone.getSubId());
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800296
Yuling Liu7dc96de2018-06-11 14:14:23 +0800297 // Note: The PhoneAccountSettingsActivity accessible via the
298 // android.telecom.action.CHANGE_PHONE_ACCOUNTS intent is accessible directly from
299 // the AOSP Dialer settings page on multi-sim devices.
300 // Where a device does NOT make the PhoneAccountSettingsActivity directly accessible from
301 // its Dialer app, this check must be modified in the device's AOSP branch to ensure that
302 // the PhoneAccountSettingsActivity is always accessible.
303 if (telephonyManager.isMultiSimEnabled()) {
304 Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
305 getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
306 }
307
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700308 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee2c027892014-10-29 11:29:54 -0700309 mVoicemailSettingsScreen =
310 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Leebf07f762015-04-07 19:05:50 -0700311 mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
312 VoicemailSettingsActivity.class));
Andrew Lee8d66d812014-11-24 14:54:02 -0800313
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800314 maybeHideVoicemailSettings();
315
fionaxue46e69f2017-04-27 14:32:46 -0700316 mButtonAutoRetry = (SwitchPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800317
fionaxue46e69f2017-04-27 14:32:46 -0700318 mEnableVideoCalling = (SwitchPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100319 mButtonWifiCalling = findPreference(getResourcesForSubId().getString(
Malcolm Chen4042eb42018-02-26 15:58:44 -0800320 R.string.wifi_calling_settings_key));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700321
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700322 PersistableBundle carrierConfig =
323 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700324
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700325 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL)) {
Andrew Lee64a7d792014-10-15 17:38:38 -0700326 mButtonAutoRetry.setOnPreferenceChangeListener(this);
327 int autoretry = Settings.Global.getInt(
328 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
329 mButtonAutoRetry.setChecked(autoretry != 0);
330 } else {
331 prefSet.removePreference(mButtonAutoRetry);
332 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 }
334
Sanket Padawee09a6f62015-03-05 11:59:39 -0800335 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
336 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
Wileen Chiu98664e52015-07-29 14:10:01 +0530337 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
338 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700339 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
Sanket Padawee09a6f62015-03-05 11:59:39 -0800340 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
341 gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
342 } else {
Andrew Lee2b36ba22014-11-05 17:08:49 -0800343 prefSet.removePreference(cdmaOptions);
Andrew Lee2b36ba22014-11-05 17:08:49 -0800344 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345
346 int phoneType = mPhone.getPhoneType();
Junda Liua9ba9d42015-06-01 01:26:52 -0700347 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
Andrew Lee5ed870c2014-10-29 11:47:49 -0700348 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 } else {
Junda Liua09d6962014-11-12 13:39:02 -0800350 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
351 prefSet.removePreference(fdnButton);
352
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700353 if (!carrierConfig.getBoolean(
Jonathan Basseri38c58552015-06-09 15:14:06 -0700354 CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800355 addPreferencesFromResource(R.xml.cdma_call_privacy);
356 }
357 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Xiangyu/Malcolm Chen2f810e82018-03-29 18:56:16 +0000358 if (mPhone.getIccCard() == null || !mPhone.getIccCard().getIccFdnAvailable()) {
359 prefSet.removePreference(fdnButton);
360 }
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700361 if (carrierConfig.getBoolean(
362 CarrierConfigManager.KEY_ADDITIONAL_CALL_SETTING_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800363 addPreferencesFromResource(R.xml.gsm_umts_call_options);
Sanket Padawee09a6f62015-03-05 11:59:39 -0800364 GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
Junda Liua09d6962014-11-12 13:39:02 -0800365 }
366 } else {
367 throw new IllegalStateException("Unexpected phone type: " + phoneType);
368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 }
370 }
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100371 updateVtWfc();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100373 // Register callback for provisioning changes.
374 try {
375 if (mImsMgr != null) {
376 mImsMgr.getConfigInterface().addConfigCallback(mProvisioningCallback);
377 }
378 } catch (ImsException e) {
379 Log.w(LOG_TAG, "onResume: Unable to register callback for provisioning changes.");
380 }
381 }
382
383 private void updateVtWfc() {
384 PreferenceScreen prefSet = getPreferenceScreen();
385 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
386 .createForSubscriptionId(mPhone.getSubId());
387 PersistableBundle carrierConfig =
388 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Youming Ye91040ec2019-06-05 14:04:14 -0700389 boolean useWfcHomeModeForRoaming = carrierConfig.getBoolean(
Youming Ye8958ed52019-05-07 15:27:35 -0700390 CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL,
391 false);
Malcolm Chen995721f2017-12-12 18:19:27 -0800392 if (mImsMgr.isVtEnabledByPlatform() && mImsMgr.isVtProvisionedOnDevice()
393 && (carrierConfig.getBoolean(
Jack Yub7628322016-11-28 11:10:18 -0800394 CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS)
Jack Yud79fba22018-12-13 11:51:28 -0800395 || mPhone.getDataEnabledSettings().isDataEnabled())) {
Andrew Lee312e8172014-10-23 17:01:36 -0700396 boolean currentValue =
Malcolm Chen995721f2017-12-12 18:19:27 -0800397 mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530398 ? mImsMgr.isVtEnabledByUser() : false;
Andrew Lee312e8172014-10-23 17:01:36 -0700399 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -0700400 mEnableVideoCalling.setOnPreferenceChangeListener(this);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100401 prefSet.addPreference(mEnableVideoCalling);
Andrew Lee77527ac2014-10-21 16:57:39 -0700402 } else {
403 prefSet.removePreference(mEnableVideoCalling);
404 }
Etan Cohena51d4ef2014-12-15 10:44:42 -0800405
Brad Ebinger85ff1822019-05-07 11:02:08 -0700406 final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManagerForSubscription(
407 mPhone.getSubId());
Santos Cordon499378a2015-06-25 18:51:39 -0700408 if (simCallManager != null) {
409 Intent intent = PhoneAccountSettingsFragment.buildPhoneAccountConfigureIntent(
410 this, simCallManager);
411 if (intent != null) {
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700412 PackageManager pm = mPhone.getContext().getPackageManager();
413 List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
414 if (!resolutions.isEmpty()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800415 mButtonWifiCalling.setTitle(resolutions.get(0).loadLabel(pm));
416 mButtonWifiCalling.setSummary(null);
417 mButtonWifiCalling.setIntent(intent);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100418 prefSet.addPreference(mButtonWifiCalling);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700419 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800420 prefSet.removePreference(mButtonWifiCalling);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700421 }
Yorke Lee0b8d2252015-06-10 16:31:20 -0700422 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800423 prefSet.removePreference(mButtonWifiCalling);
Yorke Lee0b8d2252015-06-10 16:31:20 -0700424 }
Malcolm Chen995721f2017-12-12 18:19:27 -0800425 } else if (!mImsMgr.isWfcEnabledByPlatform() || !mImsMgr.isWfcProvisionedOnDevice()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800426 prefSet.removePreference(mButtonWifiCalling);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800427 } else {
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100428 String title = getResourcesForSubId().getString(R.string.wifi_calling);
Wenting Xiong6fec4552018-08-04 17:56:50 +0800429 mButtonWifiCalling.setTitle(title);
430
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700431 int resId = com.android.internal.R.string.wifi_calling_off_summary;
Malcolm Chen995721f2017-12-12 18:19:27 -0800432 if (mImsMgr.isWfcEnabledByUser()) {
Youhan Wang269606e2017-01-19 15:25:55 -0800433 boolean isRoaming = telephonyManager.isNetworkRoaming();
Youming Ye91040ec2019-06-05 14:04:14 -0700434 // Also check carrier config for roaming mode
435 int wfcMode = mImsMgr.getWfcMode(isRoaming && !useWfcHomeModeForRoaming);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800436 switch (wfcMode) {
437 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700438 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800439 break;
440 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700441 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800442 break;
443 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700444 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800445 break;
446 default:
447 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
448 }
449 }
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100450 mButtonWifiCalling.setSummary(getResourcesForSubId().getString(resId));
Brad Ebinger1a1caf72019-04-29 15:55:40 -0700451 Intent intent = mButtonWifiCalling.getIntent();
452 if (intent != null) {
453 intent.putExtra(Settings.EXTRA_SUB_ID, mPhone.getSubId());
454 }
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100455 prefSet.addPreference(mButtonWifiCalling);
Andrew Leeb97fad82015-01-27 15:31:39 -0800456 }
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530457
458 try {
Brad Ebingera12246d2018-01-16 09:39:35 -0800459 if (mImsMgr.getImsServiceState() != ImsFeature.STATE_READY) {
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530460 log("Feature state not ready so remove vt and wfc settings for "
461 + " phone =" + mPhone.getPhoneId());
Malcolm Chen4042eb42018-02-26 15:58:44 -0800462 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530463 prefSet.removePreference(mEnableVideoCalling);
464 }
465 } catch (ImsException ex) {
466 log("Exception when trying to get ImsServiceStatus: " + ex);
Malcolm Chen4042eb42018-02-26 15:58:44 -0800467 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530468 prefSet.removePreference(mEnableVideoCalling);
469 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 }
471
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800472 /**
473 * Hides the top level voicemail settings entry point if the default dialer contains a
474 * particular manifest metadata key. This is required when the default dialer wants to display
475 * its own version of voicemail settings.
476 */
477 private void maybeHideVoicemailSettings() {
478 String defaultDialer = getSystemService(TelecomManager.class).getDefaultDialerPackage();
479 if (defaultDialer == null) {
480 return;
481 }
482 try {
483 Bundle metadata = getPackageManager()
484 .getApplicationInfo(defaultDialer, PackageManager.GET_META_DATA).metaData;
Tyler Gunn8b6aa682017-04-06 16:01:59 -0700485 if (metadata == null) {
486 return;
487 }
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800488 if (!metadata
489 .getBoolean(TelephonyManager.METADATA_HIDE_VOICEMAIL_SETTINGS_MENU, false)) {
490 if (DBG) {
491 log("maybeHideVoicemailSettings(): not disabled by default dialer");
492 }
493 return;
494 }
495 getPreferenceScreen().removePreference(mVoicemailSettingsScreen);
496 if (DBG) {
497 log("maybeHideVoicemailSettings(): disabled by default dialer");
498 }
499 } catch (NameNotFoundException e) {
500 // do nothing
501 if (DBG) {
502 log("maybeHideVoicemailSettings(): not controlled by default dialer");
503 }
504 }
505 }
506
Andrew Lee785ca2a2014-12-18 12:46:41 -0800507 @Override
508 protected void onNewIntent(Intent newIntent) {
509 setIntent(newIntent);
510
511 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee785ca2a2014-12-18 12:46:41 -0800512 mPhone = mSubscriptionInfoHelper.getPhone();
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100513 mSubscriptionInfoHelper.setActionBarTitle(
514 getActionBar(), getResourcesForSubId(), R.string.call_settings_with_label);
Andrew Lee785ca2a2014-12-18 12:46:41 -0800515 }
516
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700517 private static void log(String msg) {
518 Log.d(LOG_TAG, msg);
519 }
520
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 @Override
522 public boolean onOptionsItemSelected(MenuItem item) {
523 final int itemId = item.getItemId();
524 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -0700525 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700526 return true;
527 }
528 return super.onOptionsItemSelected(item);
529 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800530
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700531 /**
532 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
533 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
534 */
Andrew Lee5efb1122014-12-05 04:20:42 -0800535 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800536 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
537 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700538 intent.setAction(Intent.ACTION_MAIN);
539 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
540 activity.startActivity(intent);
541 activity.finish();
542 }
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100543
544 private Resources getResourcesForSubId() {
545 if (mPhone != null) {
546 return SubscriptionManager.getResourcesForSubId(mPhone.getContext(), mPhone.getSubId());
547 } else {
548 return getResources();
549 }
550 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551}