blob: 1c5525689f77a181be8cec26e9dd6e7cad06bfc9 [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
Pranav Madapurmath4c830832022-10-14 21:44:05 +000019import android.app.ActionBar;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070020import android.app.Activity;
21import android.app.AlertDialog;
22import android.app.Dialog;
SongFerngWang09ba5d92019-11-25 22:52:03 +080023import android.content.BroadcastReceiver;
Pengquan Mengdb6b87e2019-06-18 17:42:16 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.DialogInterface;
27import android.content.Intent;
SongFerngWang09ba5d92019-11-25 22:52:03 +080028import android.content.IntentFilter;
Yorke Lee0b8d2252015-06-10 16:31:20 -070029import android.content.pm.PackageManager;
Ta-wei Yenb8e770c2017-01-24 17:49:58 -080030import android.content.pm.PackageManager.NameNotFoundException;
Yorke Lee0b8d2252015-06-10 16:31:20 -070031import android.content.pm.ResolveInfo;
Torbjorn Eklund209ed792019-03-06 15:15:30 +010032import android.content.res.Resources;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.os.Bundle;
Zoey Chen5719bac2021-01-28 15:05:49 +080034import android.os.Handler;
35import android.os.HandlerExecutor;
36import android.os.Looper;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070037import android.os.PersistableBundle;
Jack Yu58d04bd2024-09-10 17:32:39 -070038import android.os.UserHandle;
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -070039import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.preference.Preference;
41import android.preference.PreferenceActivity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.preference.PreferenceScreen;
fionaxue46e69f2017-04-27 14:32:46 -070043import android.preference.SwitchPreference;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.provider.Settings;
Tyler Gunn4d45d1c2014-09-12 22:17:53 -070045import android.telecom.PhoneAccountHandle;
46import android.telecom.TelecomManager;
Jonathan Basseri4b40ff42015-04-30 21:54:10 -070047import android.telephony.CarrierConfigManager;
Wenting Xiong6fec4552018-08-04 17:56:50 +080048import android.telephony.SubscriptionManager;
Zoey Chen5ec326b2021-02-22 21:21:28 +080049import android.telephony.TelephonyCallback;
Andrew Lee93c345f2014-10-27 15:25:07 -070050import android.telephony.TelephonyManager;
Torbjorn Eklund82d5d742018-11-29 15:32:13 +010051import android.telephony.ims.ProvisioningManager;
Malcolm Chen995721f2017-12-12 18:19:27 -080052import android.telephony.ims.feature.ImsFeature;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.util.Log;
54import android.view.MenuItem;
Jay Shraunerc2684732014-11-12 12:10:37 -080055import android.widget.Toast;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056
Andrew Leeeffef9c2015-02-19 16:02:37 -080057import com.android.ims.ImsConfig;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +053058import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070059import com.android.ims.ImsManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import com.android.internal.telephony.Phone;
61import com.android.internal.telephony.PhoneConstants;
Grant Menke616af982024-06-12 11:47:52 -070062import com.android.internal.telephony.flags.Flags;
Santos Cordon499378a2015-06-25 18:51:39 -070063import com.android.phone.settings.PhoneAccountSettingsFragment;
SongFerngWangbed485e2018-07-09 21:15:29 +080064import com.android.phone.settings.SuppServicesUiUtil;
Andrew Leebf07f762015-04-07 19:05:50 -070065import com.android.phone.settings.VoicemailSettingsActivity;
Andrew Lee5ed870c2014-10-29 11:47:49 -070066import com.android.phone.settings.fdn.FdnSetting;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import java.util.List;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069
70/**
71 * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
72 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070073 * This preference screen is the root of the "Call settings" hierarchy available from the Phone
74 * app; the settings here let you control various features related to phone calls (including
75 * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
76 * voice-capable phone devices.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077 *
78 * Note that this activity is part of the package com.android.phone, even
79 * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
80 * is from the package com.android.contacts.
81 *
82 * For the "Mobile network settings" screen under the main Settings app,
Pengquan Mengdb6b87e2019-06-18 17:42:16 -070083 * See {@link com.android.settings.network.telephony.MobileNetworkActivity}.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084 */
85public class CallFeaturesSetting extends PreferenceActivity
Andrew Leebf07f762015-04-07 19:05:50 -070086 implements Preference.OnPreferenceChangeListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087 private static final String LOG_TAG = "CallFeaturesSetting";
88 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
89
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090 // String keys for preference lookup
91 // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
Andrew Lee8d66d812014-11-24 14:54:02 -080092 // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
93 // in the layout files. These strings need to be treated carefully; if the setting is
94 // persistent, they are used as the key to store shared preferences and the name should not be
95 // changed unless the settings are also migrated.
Andrew Lee97708a42014-09-25 12:39:07 -070096 private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097 private static final String BUTTON_FDN_KEY = "button_fdn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098 private static final String BUTTON_RETRY_KEY = "button_auto_retry_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099 private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
100 private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
101
Andrew Leece8ae2a2014-09-10 10:41:48 -0700102 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
103 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -0700104
Andrew Leedf14ead2014-10-17 14:22:52 -0700105 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
Grace Jiad0ba6312020-03-23 15:12:55 -0700106 private static final String BUTTON_VP_KEY = "button_voice_privacy_key";
Andrew Leedf14ead2014-10-17 14:22:52 -0700107
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108 private Phone mPhone;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530109 private ImsManager mImsMgr;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700110 private SubscriptionInfoHelper mSubscriptionInfoHelper;
Yorke Lee0b8d2252015-06-10 16:31:20 -0700111 private TelecomManager mTelecomManager;
Zoey Chen5ec326b2021-02-22 21:21:28 +0800112 private TelephonyCallback mTelephonyCallback;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700113
fionaxue46e69f2017-04-27 14:32:46 -0700114 private SwitchPreference mButtonAutoRetry;
Andrew Lee97708a42014-09-25 12:39:07 -0700115 private PreferenceScreen mVoicemailSettingsScreen;
fionaxue46e69f2017-04-27 14:32:46 -0700116 private SwitchPreference mEnableVideoCalling;
Malcolm Chen4042eb42018-02-26 15:58:44 -0800117 private Preference mButtonWifiCalling;
Grant Menke616af982024-06-12 11:47:52 -0700118 private boolean mDisallowedConfig = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120 /*
121 * Click Listeners, handle click based on objects attached to UI.
122 */
123
SongFerngWang09ba5d92019-11-25 22:52:03 +0800124 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
125 @Override
126 public void onReceive(Context context, Intent intent) {
127 log("onReceive: " + intent.getAction());
128
129 if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) {
130 log("ACTION_AIRPLANE_MODE_CHANGED");
131
132 boolean isAirplaneModeOn = intent.getBooleanExtra("state", false);
133 handleAirplaneModeChange(isAirplaneModeOn);
134 }
135 }
136 };
137
138 private void handleAirplaneModeChange(boolean isAirplaneModeOn) {
139 PersistableBundle b = null;
140 if (mSubscriptionInfoHelper.hasSubId()) {
141 b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
142 mSubscriptionInfoHelper.getSubId());
143 } else {
144 b = PhoneGlobals.getInstance().getCarrierConfig();
145 }
146
147 if (b != null && b.getBoolean(
148 CarrierConfigManager.KEY_DISABLE_SUPPLEMENTARY_SERVICES_IN_AIRPLANE_MODE_BOOL)) {
149 PreferenceScreen preferenceScreen = getPreferenceScreen();
150 Preference callForwarding = preferenceScreen.findPreference(
151 GsmUmtsCallOptions.CALL_FORWARDING_KEY);
152 Preference callBarring = preferenceScreen.findPreference(
153 GsmUmtsCallOptions.CALL_BARRING_KEY);
154 Preference additional = preferenceScreen.findPreference(
155 GsmUmtsCallOptions.ADDITIONAL_GSM_SETTINGS_KEY);
156 if (callForwarding != null) {
157 callForwarding.setEnabled(!isAirplaneModeOn);
158 }
159 if (callBarring != null) {
160 callBarring.setEnabled(!isAirplaneModeOn);
161 }
162 if (additional != null) {
163 additional.setEnabled(!isAirplaneModeOn);
164 }
165 }
166 }
167
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168 // Click listener for all toggle events
169 @Override
170 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Andrew Leebf07f762015-04-07 19:05:50 -0700171 if (preference == mButtonAutoRetry) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
173 android.provider.Settings.Global.CALL_AUTO_RETRY,
174 mButtonAutoRetry.isChecked() ? 1 : 0);
175 return true;
SongFerngWangbed485e2018-07-09 21:15:29 +0800176 } else if (preference == preferenceScreen.findPreference(
177 GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
178 return doSsOverUtPrecautions(preference);
179 } else if (preference == preferenceScreen.findPreference(
180 GsmUmtsCallOptions.CALL_BARRING_KEY)) {
181 return doSsOverUtPrecautions(preference);
182 }
183 return false;
184 }
185
186 private boolean doSsOverUtPrecautions(Preference preference) {
187 PersistableBundle b = null;
188 if (mSubscriptionInfoHelper.hasSubId()) {
189 b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
190 mSubscriptionInfoHelper.getSubId());
191 } else {
192 b = PhoneGlobals.getInstance().getCarrierConfig();
193 }
194
195 String configKey;
196 if (preference.getKey().equals(GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
197 configKey = CarrierConfigManager.KEY_CALL_FORWARDING_OVER_UT_WARNING_BOOL;
198 } else {
199 configKey = CarrierConfigManager.KEY_CALL_BARRING_OVER_UT_WARNING_BOOL;
200 }
201 if (b != null && b.getBoolean(configKey)
202 && mPhone != null
203 && SuppServicesUiUtil.isSsOverUtPrecautions(this, mPhone)) {
204 SuppServicesUiUtil.showBlockingSuppServicesDialog(this, mPhone,
205 preference.getKey()).show();
206 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207 }
208 return false;
209 }
210
211 /**
212 * Implemented to support onPreferenceChangeListener to look for preference
213 * changes.
214 *
215 * @param preference is the preference to be changed
216 * @param objValue should be the value of the selection, NOT its localized
217 * display value.
218 */
219 @Override
220 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800221 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700222
Andrew Leebf07f762015-04-07 19:05:50 -0700223 if (preference == mEnableVideoCalling) {
Malcolm Chen995721f2017-12-12 18:19:27 -0800224 if (mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530225 mImsMgr.setVtSetting((boolean) objValue);
Andrew Lee312e8172014-10-23 17:01:36 -0700226 } else {
Sooraj Sasindran9dbb2882021-10-19 11:40:34 -0700227 AlertDialog.Builder builder = FrameworksUtils.makeAlertDialogBuilder(this);
Andrew Lee312e8172014-10-23 17:01:36 -0700228 DialogInterface.OnClickListener networkSettingsClickListener =
229 new Dialog.OnClickListener() {
230 @Override
231 public void onClick(DialogInterface dialog, int which) {
Zoey Chenc9e19902022-05-23 15:24:13 +0800232 Intent intent = new Intent();
Pengquan Mengdb6b87e2019-06-18 17:42:16 -0700233 ComponentName mobileNetworkSettingsComponent = new ComponentName(
234 getString(R.string.mobile_network_settings_package),
235 getString(R.string.mobile_network_settings_class));
236 intent.setComponent(mobileNetworkSettingsComponent);
Jack Yu58d04bd2024-09-10 17:32:39 -0700237 startActivityAsUser(intent, UserHandle.CURRENT);
Andrew Lee312e8172014-10-23 17:01:36 -0700238 }
239 };
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100240 builder.setMessage(getResourcesForSubId().getString(
Andrew Lee312e8172014-10-23 17:01:36 -0700241 R.string.enable_video_calling_dialog_msg))
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100242 .setNeutralButton(getResourcesForSubId().getString(
Andrew Lee312e8172014-10-23 17:01:36 -0700243 R.string.enable_video_calling_dialog_settings),
244 networkSettingsClickListener)
245 .setPositiveButton(android.R.string.ok, null)
246 .show();
247 return false;
248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800250
251 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252 return true;
253 }
254
255 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256 protected void onCreate(Bundle icicle) {
257 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800258 if (DBG) log("onCreate: Intent is " + getIntent());
259
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -0700260 // Make sure we are running as an admin user.
Meng Wangc04cd2d2019-10-04 12:00:06 -0700261 UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
262 if (!userManager.isAdminUser()) {
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -0700263 Toast.makeText(this, R.string.call_settings_admin_user_only,
Jay Shraunerc2684732014-11-12 12:10:37 -0800264 Toast.LENGTH_SHORT).show();
265 finish();
266 return;
267 }
268
Grant Menke616af982024-06-12 11:47:52 -0700269 // Check if mobile network configs are restricted.
270 if (Flags.ensureAccessToCallSettingsIsRestricted() &&
271 userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
272 mDisallowedConfig = true;
273 Log.i(LOG_TAG, "Mobile network configs are restricted, disabling mobile network "
274 + "settings");
275 }
276
Andrew Leedd4f6df2014-12-09 19:13:51 -0800277 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee1479dd12014-11-06 23:06:32 -0800278 mPhone = mSubscriptionInfoHelper.getPhone();
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100279 mSubscriptionInfoHelper.setActionBarTitle(
280 getActionBar(), getResourcesForSubId(), R.string.call_settings_with_label);
Tyler Gunn77ee9382019-10-31 13:08:23 -0700281 mTelecomManager = getSystemService(TelecomManager.class);
Zoey Chen5ec326b2021-02-22 21:21:28 +0800282 mTelephonyCallback = new CallFeaturesTelephonyCallback();
Pranav Madapurmath4c830832022-10-14 21:44:05 +0000283
284 ActionBar actionBar = getActionBar();
285 if (actionBar != null) {
286 // sets the talkback voice prompt to say "Back" instead of "Navigate Up"
287 actionBar.setHomeActionContentDescription(R.string.ota_call_end);
288 }
Tyler Gunnbaee2952014-09-10 16:01:02 -0700289 }
290
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530291 private void updateImsManager(Phone phone) {
292 log("updateImsManager :: phone.getContext()=" + phone.getContext()
293 + " phone.getPhoneId()=" + phone.getPhoneId());
294 mImsMgr = ImsManager.getInstance(phone.getContext(), phone.getPhoneId());
295 if (mImsMgr == null) {
296 log("updateImsManager :: Could not get ImsManager instance!");
297 } else {
298 log("updateImsManager :: mImsMgr=" + mImsMgr);
299 }
300 }
301
Omata Shou81a0c8a2018-07-19 18:57:02 +0900302 private void listenPhoneState(boolean listen) {
Kazuki Iwami940af4d2019-02-25 18:07:38 +0900303 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
304 .createForSubscriptionId(mPhone.getSubId());
Zoey Chen5719bac2021-01-28 15:05:49 +0800305 if (listen) {
Zoey Chen5ec326b2021-02-22 21:21:28 +0800306 telephonyManager.registerTelephonyCallback(
307 new HandlerExecutor(new Handler(Looper.getMainLooper())), mTelephonyCallback);
Zoey Chen5719bac2021-01-28 15:05:49 +0800308 } else {
Zoey Chen5ec326b2021-02-22 21:21:28 +0800309 telephonyManager.unregisterTelephonyCallback(mTelephonyCallback);
Zoey Chen5719bac2021-01-28 15:05:49 +0800310 }
Omata Shou81a0c8a2018-07-19 18:57:02 +0900311 }
312
Zoey Chen5ec326b2021-02-22 21:21:28 +0800313 private final class CallFeaturesTelephonyCallback extends TelephonyCallback implements
314 TelephonyCallback.CallStateListener {
pkanwarb4aef112016-07-17 15:39:30 -0700315 @Override
Tyler Gunncca49da2021-03-08 15:58:26 -0800316 public void onCallStateChanged(int state) {
pkanwarb4aef112016-07-17 15:39:30 -0700317 if (DBG) log("PhoneStateListener onCallStateChanged: state is " + state);
Kazuki Iwami940af4d2019-02-25 18:07:38 +0900318 boolean isCallStateIdle = state == TelephonyManager.CALL_STATE_IDLE;
pkanwarb4aef112016-07-17 15:39:30 -0700319 if (mEnableVideoCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530320 mEnableVideoCalling.setEnabled(isCallStateIdle);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900321 }
322 if (mButtonWifiCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530323 mButtonWifiCalling.setEnabled(isCallStateIdle);
pkanwarb4aef112016-07-17 15:39:30 -0700324 }
325 }
Zoey Chen5719bac2021-01-28 15:05:49 +0800326 }
pkanwarb4aef112016-07-17 15:39:30 -0700327
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100328 private final ProvisioningManager.Callback mProvisioningCallback =
329 new ProvisioningManager.Callback() {
330 @Override
331 public void onProvisioningIntChanged(int item, int value) {
332 if (item == ImsConfig.ConfigConstants.VOICE_OVER_WIFI_SETTING_ENABLED
333 || item == ImsConfig.ConfigConstants.VLT_SETTING_ENABLED
334 || item == ImsConfig.ConfigConstants.LVC_SETTING_ENABLED) {
335 updateVtWfc();
336 }
337 }
338 };
339
pkanwarb4aef112016-07-17 15:39:30 -0700340 @Override
341 protected void onPause() {
pkanwar0a663122016-07-19 12:26:44 -0700342 super.onPause();
Omata Shou81a0c8a2018-07-19 18:57:02 +0900343 listenPhoneState(false);
SongFerngWang09ba5d92019-11-25 22:52:03 +0800344 unregisterReceiver(mReceiver);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100345
346 // Remove callback for provisioning changes.
347 try {
348 if (mImsMgr != null) {
349 mImsMgr.getConfigInterface().removeConfigCallback(
350 mProvisioningCallback.getBinder());
351 }
352 } catch (ImsException e) {
353 Log.w(LOG_TAG, "onPause: Unable to remove callback for provisioning changes");
354 }
pkanwarb4aef112016-07-17 15:39:30 -0700355 }
356
Tyler Gunnbaee2952014-09-10 16:01:02 -0700357 @Override
358 protected void onResume() {
359 super.onResume();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700360
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530361 updateImsManager(mPhone);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900362 listenPhoneState(true);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700363 PreferenceScreen preferenceScreen = getPreferenceScreen();
364 if (preferenceScreen != null) {
365 preferenceScreen.removeAll();
366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367
368 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -0700369
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530370 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
371 .createForSubscriptionId(mPhone.getSubId());
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800372
Yuling Liu7dc96de2018-06-11 14:14:23 +0800373 // Note: The PhoneAccountSettingsActivity accessible via the
374 // android.telecom.action.CHANGE_PHONE_ACCOUNTS intent is accessible directly from
375 // the AOSP Dialer settings page on multi-sim devices.
376 // Where a device does NOT make the PhoneAccountSettingsActivity directly accessible from
377 // its Dialer app, this check must be modified in the device's AOSP branch to ensure that
378 // the PhoneAccountSettingsActivity is always accessible.
379 if (telephonyManager.isMultiSimEnabled()) {
380 Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
381 getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
382 }
383
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee2c027892014-10-29 11:29:54 -0700385 mVoicemailSettingsScreen =
386 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Leebf07f762015-04-07 19:05:50 -0700387 mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
388 VoicemailSettingsActivity.class));
Andrew Lee8d66d812014-11-24 14:54:02 -0800389
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800390 maybeHideVoicemailSettings();
391
fionaxue46e69f2017-04-27 14:32:46 -0700392 mButtonAutoRetry = (SwitchPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800393
fionaxue46e69f2017-04-27 14:32:46 -0700394 mEnableVideoCalling = (SwitchPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100395 mButtonWifiCalling = findPreference(getResourcesForSubId().getString(
Malcolm Chen4042eb42018-02-26 15:58:44 -0800396 R.string.wifi_calling_settings_key));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700398 PersistableBundle carrierConfig =
399 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700400
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700401 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL)) {
Andrew Lee64a7d792014-10-15 17:38:38 -0700402 mButtonAutoRetry.setOnPreferenceChangeListener(this);
403 int autoretry = Settings.Global.getInt(
404 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
405 mButtonAutoRetry.setChecked(autoretry != 0);
406 } else {
407 prefSet.removePreference(mButtonAutoRetry);
408 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 }
410
Sanket Padawee09a6f62015-03-05 11:59:39 -0800411 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
412 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
Wileen Chiu98664e52015-07-29 14:10:01 +0530413 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
414 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700415 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
Sanket Padawee09a6f62015-03-05 11:59:39 -0800416 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
417 gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
418 } else {
Brad Ebinger931ab212021-06-14 11:50:39 -0700419 // Remove GSM options and repopulate the preferences in this Activity if phone type is
420 // GSM.
Andrew Lee2b36ba22014-11-05 17:08:49 -0800421 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422
423 int phoneType = mPhone.getPhoneType();
Junda Liua9ba9d42015-06-01 01:26:52 -0700424 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
Andrew Lee5ed870c2014-10-29 11:47:49 -0700425 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700426 } else {
Junda Liua09d6962014-11-12 13:39:02 -0800427 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
Brad Ebinger931ab212021-06-14 11:50:39 -0700428 // For now, just keep CdmaCallOptions as one entity. Eventually CDMA should
429 // follow the same pattern as GSM below, where VP and Call forwarding are
430 // populated here and Call waiting is populated in another "Additional Settings"
431 // submenu for CDMA.
Junda Liua09d6962014-11-12 13:39:02 -0800432 prefSet.removePreference(fdnButton);
Brad Ebinger931ab212021-06-14 11:50:39 -0700433 cdmaOptions.setSummary(null);
434 cdmaOptions.setTitle(R.string.additional_gsm_call_settings);
435 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
Junda Liua09d6962014-11-12 13:39:02 -0800436 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Brad Ebinger931ab212021-06-14 11:50:39 -0700437 prefSet.removePreference(cdmaOptions);
Xiangyu/Malcolm Chen2f810e82018-03-29 18:56:16 +0000438 if (mPhone.getIccCard() == null || !mPhone.getIccCard().getIccFdnAvailable()) {
439 prefSet.removePreference(fdnButton);
440 }
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700441 if (carrierConfig.getBoolean(
442 CarrierConfigManager.KEY_ADDITIONAL_CALL_SETTING_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800443 addPreferencesFromResource(R.xml.gsm_umts_call_options);
Sanket Padawee09a6f62015-03-05 11:59:39 -0800444 GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
Junda Liua09d6962014-11-12 13:39:02 -0800445 }
446 } else {
447 throw new IllegalStateException("Unexpected phone type: " + phoneType);
448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 }
450 }
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100451 updateVtWfc();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100453 // Register callback for provisioning changes.
454 try {
455 if (mImsMgr != null) {
456 mImsMgr.getConfigInterface().addConfigCallback(mProvisioningCallback);
457 }
458 } catch (ImsException e) {
459 Log.w(LOG_TAG, "onResume: Unable to register callback for provisioning changes.");
460 }
SongFerngWang09ba5d92019-11-25 22:52:03 +0800461
462 IntentFilter intentFilter =
463 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
464 registerReceiver(mReceiver, intentFilter);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100465 }
466
467 private void updateVtWfc() {
468 PreferenceScreen prefSet = getPreferenceScreen();
469 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
470 .createForSubscriptionId(mPhone.getSubId());
471 PersistableBundle carrierConfig =
472 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Youming Ye91040ec2019-06-05 14:04:14 -0700473 boolean useWfcHomeModeForRoaming = carrierConfig.getBoolean(
Youming Ye8958ed52019-05-07 15:27:35 -0700474 CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL,
475 false);
Jack Yu99e87332021-12-17 23:14:15 -0800476 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -0700477 isDataEnabled = mPhone.getDataSettingsManager().isDataEnabled();
Malcolm Chen995721f2017-12-12 18:19:27 -0800478 if (mImsMgr.isVtEnabledByPlatform() && mImsMgr.isVtProvisionedOnDevice()
479 && (carrierConfig.getBoolean(
Jack Yub7628322016-11-28 11:10:18 -0800480 CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS)
Grant Menke616af982024-06-12 11:47:52 -0700481 || isDataEnabled) && !mDisallowedConfig) {
Andrew Lee312e8172014-10-23 17:01:36 -0700482 boolean currentValue =
Malcolm Chen995721f2017-12-12 18:19:27 -0800483 mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530484 ? mImsMgr.isVtEnabledByUser() : false;
Andrew Lee312e8172014-10-23 17:01:36 -0700485 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -0700486 mEnableVideoCalling.setOnPreferenceChangeListener(this);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100487 prefSet.addPreference(mEnableVideoCalling);
Andrew Lee77527ac2014-10-21 16:57:39 -0700488 } else {
489 prefSet.removePreference(mEnableVideoCalling);
490 }
Etan Cohena51d4ef2014-12-15 10:44:42 -0800491
Brad Ebinger85ff1822019-05-07 11:02:08 -0700492 final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManagerForSubscription(
493 mPhone.getSubId());
Santos Cordon499378a2015-06-25 18:51:39 -0700494 if (simCallManager != null) {
495 Intent intent = PhoneAccountSettingsFragment.buildPhoneAccountConfigureIntent(
496 this, simCallManager);
497 if (intent != null) {
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700498 PackageManager pm = mPhone.getContext().getPackageManager();
499 List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
500 if (!resolutions.isEmpty()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800501 mButtonWifiCalling.setTitle(resolutions.get(0).loadLabel(pm));
502 mButtonWifiCalling.setSummary(null);
503 mButtonWifiCalling.setIntent(intent);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100504 prefSet.addPreference(mButtonWifiCalling);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700505 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800506 prefSet.removePreference(mButtonWifiCalling);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700507 }
Yorke Lee0b8d2252015-06-10 16:31:20 -0700508 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800509 prefSet.removePreference(mButtonWifiCalling);
Yorke Lee0b8d2252015-06-10 16:31:20 -0700510 }
Malcolm Chen995721f2017-12-12 18:19:27 -0800511 } else if (!mImsMgr.isWfcEnabledByPlatform() || !mImsMgr.isWfcProvisionedOnDevice()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800512 prefSet.removePreference(mButtonWifiCalling);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800513 } else {
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100514 String title = getResourcesForSubId().getString(R.string.wifi_calling);
Wenting Xiong6fec4552018-08-04 17:56:50 +0800515 mButtonWifiCalling.setTitle(title);
516
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700517 int resId = com.android.internal.R.string.wifi_calling_off_summary;
Malcolm Chen995721f2017-12-12 18:19:27 -0800518 if (mImsMgr.isWfcEnabledByUser()) {
Youhan Wang269606e2017-01-19 15:25:55 -0800519 boolean isRoaming = telephonyManager.isNetworkRoaming();
Youming Ye91040ec2019-06-05 14:04:14 -0700520 // Also check carrier config for roaming mode
521 int wfcMode = mImsMgr.getWfcMode(isRoaming && !useWfcHomeModeForRoaming);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800522 switch (wfcMode) {
523 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700524 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800525 break;
526 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700527 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800528 break;
529 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700530 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800531 break;
532 default:
533 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
534 }
535 }
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100536 mButtonWifiCalling.setSummary(getResourcesForSubId().getString(resId));
Brad Ebinger1a1caf72019-04-29 15:55:40 -0700537 Intent intent = mButtonWifiCalling.getIntent();
538 if (intent != null) {
539 intent.putExtra(Settings.EXTRA_SUB_ID, mPhone.getSubId());
540 }
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100541 prefSet.addPreference(mButtonWifiCalling);
Andrew Leeb97fad82015-01-27 15:31:39 -0800542 }
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530543
544 try {
Brad Ebingera12246d2018-01-16 09:39:35 -0800545 if (mImsMgr.getImsServiceState() != ImsFeature.STATE_READY) {
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530546 log("Feature state not ready so remove vt and wfc settings for "
547 + " phone =" + mPhone.getPhoneId());
Malcolm Chen4042eb42018-02-26 15:58:44 -0800548 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530549 prefSet.removePreference(mEnableVideoCalling);
550 }
551 } catch (ImsException ex) {
552 log("Exception when trying to get ImsServiceStatus: " + ex);
Malcolm Chen4042eb42018-02-26 15:58:44 -0800553 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530554 prefSet.removePreference(mEnableVideoCalling);
555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700556 }
557
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800558 /**
559 * Hides the top level voicemail settings entry point if the default dialer contains a
560 * particular manifest metadata key. This is required when the default dialer wants to display
561 * its own version of voicemail settings.
562 */
563 private void maybeHideVoicemailSettings() {
564 String defaultDialer = getSystemService(TelecomManager.class).getDefaultDialerPackage();
565 if (defaultDialer == null) {
566 return;
567 }
568 try {
569 Bundle metadata = getPackageManager()
570 .getApplicationInfo(defaultDialer, PackageManager.GET_META_DATA).metaData;
Tyler Gunn8b6aa682017-04-06 16:01:59 -0700571 if (metadata == null) {
572 return;
573 }
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800574 if (!metadata
575 .getBoolean(TelephonyManager.METADATA_HIDE_VOICEMAIL_SETTINGS_MENU, false)) {
576 if (DBG) {
577 log("maybeHideVoicemailSettings(): not disabled by default dialer");
578 }
579 return;
580 }
581 getPreferenceScreen().removePreference(mVoicemailSettingsScreen);
582 if (DBG) {
583 log("maybeHideVoicemailSettings(): disabled by default dialer");
584 }
585 } catch (NameNotFoundException e) {
586 // do nothing
587 if (DBG) {
588 log("maybeHideVoicemailSettings(): not controlled by default dialer");
589 }
590 }
591 }
592
Andrew Lee785ca2a2014-12-18 12:46:41 -0800593 @Override
594 protected void onNewIntent(Intent newIntent) {
595 setIntent(newIntent);
596
597 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee785ca2a2014-12-18 12:46:41 -0800598 mPhone = mSubscriptionInfoHelper.getPhone();
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100599 mSubscriptionInfoHelper.setActionBarTitle(
600 getActionBar(), getResourcesForSubId(), R.string.call_settings_with_label);
Andrew Lee785ca2a2014-12-18 12:46:41 -0800601 }
602
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700603 private static void log(String msg) {
604 Log.d(LOG_TAG, msg);
605 }
606
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700607 @Override
608 public boolean onOptionsItemSelected(MenuItem item) {
609 final int itemId = item.getItemId();
610 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -0700611 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700612 return true;
613 }
614 return super.onOptionsItemSelected(item);
615 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800616
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700617 /**
618 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
619 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
620 */
Andrew Lee5efb1122014-12-05 04:20:42 -0800621 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800622 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
623 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700624 intent.setAction(Intent.ACTION_MAIN);
625 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Jack Yu58d04bd2024-09-10 17:32:39 -0700626 activity.startActivityAsUser(intent, UserHandle.CURRENT);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700627 activity.finish();
628 }
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100629
630 private Resources getResourcesForSubId() {
631 if (mPhone != null) {
632 return SubscriptionManager.getResourcesForSubId(mPhone.getContext(), mPhone.getSubId());
633 } else {
634 return getResources();
635 }
636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700637}