blob: 145df4143faac63bce5bdebcbd32336b263f5380 [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;
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -070038import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.preference.Preference;
40import android.preference.PreferenceActivity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.preference.PreferenceScreen;
fionaxue46e69f2017-04-27 14:32:46 -070042import android.preference.SwitchPreference;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.provider.Settings;
Tyler Gunn4d45d1c2014-09-12 22:17:53 -070044import android.telecom.PhoneAccountHandle;
45import android.telecom.TelecomManager;
Jonathan Basseri4b40ff42015-04-30 21:54:10 -070046import android.telephony.CarrierConfigManager;
Wenting Xiong6fec4552018-08-04 17:56:50 +080047import android.telephony.SubscriptionManager;
Zoey Chen5ec326b2021-02-22 21:21:28 +080048import android.telephony.TelephonyCallback;
Andrew Lee93c345f2014-10-27 15:25:07 -070049import android.telephony.TelephonyManager;
Torbjorn Eklund82d5d742018-11-29 15:32:13 +010050import android.telephony.ims.ProvisioningManager;
Malcolm Chen995721f2017-12-12 18:19:27 -080051import android.telephony.ims.feature.ImsFeature;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.util.Log;
53import android.view.MenuItem;
Jay Shraunerc2684732014-11-12 12:10:37 -080054import android.widget.Toast;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055
Andrew Leeeffef9c2015-02-19 16:02:37 -080056import com.android.ims.ImsConfig;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +053057import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070058import com.android.ims.ImsManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import com.android.internal.telephony.Phone;
60import com.android.internal.telephony.PhoneConstants;
Santos Cordon499378a2015-06-25 18:51:39 -070061import com.android.phone.settings.PhoneAccountSettingsFragment;
SongFerngWangbed485e2018-07-09 21:15:29 +080062import com.android.phone.settings.SuppServicesUiUtil;
Andrew Leebf07f762015-04-07 19:05:50 -070063import com.android.phone.settings.VoicemailSettingsActivity;
Andrew Lee5ed870c2014-10-29 11:47:49 -070064import com.android.phone.settings.fdn.FdnSetting;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import java.util.List;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067
68/**
69 * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
70 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070071 * This preference screen is the root of the "Call settings" hierarchy available from the Phone
72 * app; the settings here let you control various features related to phone calls (including
73 * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
74 * voice-capable phone devices.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075 *
76 * Note that this activity is part of the package com.android.phone, even
77 * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
78 * is from the package com.android.contacts.
79 *
80 * For the "Mobile network settings" screen under the main Settings app,
Pengquan Mengdb6b87e2019-06-18 17:42:16 -070081 * See {@link com.android.settings.network.telephony.MobileNetworkActivity}.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082 */
83public class CallFeaturesSetting extends PreferenceActivity
Andrew Leebf07f762015-04-07 19:05:50 -070084 implements Preference.OnPreferenceChangeListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085 private static final String LOG_TAG = "CallFeaturesSetting";
86 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
87
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088 // String keys for preference lookup
89 // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
Andrew Lee8d66d812014-11-24 14:54:02 -080090 // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
91 // in the layout files. These strings need to be treated carefully; if the setting is
92 // persistent, they are used as the key to store shared preferences and the name should not be
93 // changed unless the settings are also migrated.
Andrew Lee97708a42014-09-25 12:39:07 -070094 private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095 private static final String BUTTON_FDN_KEY = "button_fdn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096 private static final String BUTTON_RETRY_KEY = "button_auto_retry_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097 private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
98 private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
99
Andrew Leece8ae2a2014-09-10 10:41:48 -0700100 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
101 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -0700102
Andrew Leedf14ead2014-10-17 14:22:52 -0700103 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
Grace Jiad0ba6312020-03-23 15:12:55 -0700104 private static final String BUTTON_VP_KEY = "button_voice_privacy_key";
Andrew Leedf14ead2014-10-17 14:22:52 -0700105
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106 private Phone mPhone;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530107 private ImsManager mImsMgr;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700108 private SubscriptionInfoHelper mSubscriptionInfoHelper;
Yorke Lee0b8d2252015-06-10 16:31:20 -0700109 private TelecomManager mTelecomManager;
Zoey Chen5ec326b2021-02-22 21:21:28 +0800110 private TelephonyCallback mTelephonyCallback;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700111
fionaxue46e69f2017-04-27 14:32:46 -0700112 private SwitchPreference mButtonAutoRetry;
Andrew Lee97708a42014-09-25 12:39:07 -0700113 private PreferenceScreen mVoicemailSettingsScreen;
fionaxue46e69f2017-04-27 14:32:46 -0700114 private SwitchPreference mEnableVideoCalling;
Malcolm Chen4042eb42018-02-26 15:58:44 -0800115 private Preference mButtonWifiCalling;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117 /*
118 * Click Listeners, handle click based on objects attached to UI.
119 */
120
SongFerngWang09ba5d92019-11-25 22:52:03 +0800121 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
122 @Override
123 public void onReceive(Context context, Intent intent) {
124 log("onReceive: " + intent.getAction());
125
126 if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) {
127 log("ACTION_AIRPLANE_MODE_CHANGED");
128
129 boolean isAirplaneModeOn = intent.getBooleanExtra("state", false);
130 handleAirplaneModeChange(isAirplaneModeOn);
131 }
132 }
133 };
134
135 private void handleAirplaneModeChange(boolean isAirplaneModeOn) {
136 PersistableBundle b = null;
137 if (mSubscriptionInfoHelper.hasSubId()) {
138 b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
139 mSubscriptionInfoHelper.getSubId());
140 } else {
141 b = PhoneGlobals.getInstance().getCarrierConfig();
142 }
143
144 if (b != null && b.getBoolean(
145 CarrierConfigManager.KEY_DISABLE_SUPPLEMENTARY_SERVICES_IN_AIRPLANE_MODE_BOOL)) {
146 PreferenceScreen preferenceScreen = getPreferenceScreen();
147 Preference callForwarding = preferenceScreen.findPreference(
148 GsmUmtsCallOptions.CALL_FORWARDING_KEY);
149 Preference callBarring = preferenceScreen.findPreference(
150 GsmUmtsCallOptions.CALL_BARRING_KEY);
151 Preference additional = preferenceScreen.findPreference(
152 GsmUmtsCallOptions.ADDITIONAL_GSM_SETTINGS_KEY);
153 if (callForwarding != null) {
154 callForwarding.setEnabled(!isAirplaneModeOn);
155 }
156 if (callBarring != null) {
157 callBarring.setEnabled(!isAirplaneModeOn);
158 }
159 if (additional != null) {
160 additional.setEnabled(!isAirplaneModeOn);
161 }
162 }
163 }
164
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165 // Click listener for all toggle events
166 @Override
167 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Andrew Leebf07f762015-04-07 19:05:50 -0700168 if (preference == mButtonAutoRetry) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
170 android.provider.Settings.Global.CALL_AUTO_RETRY,
171 mButtonAutoRetry.isChecked() ? 1 : 0);
172 return true;
SongFerngWangbed485e2018-07-09 21:15:29 +0800173 } else if (preference == preferenceScreen.findPreference(
174 GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
175 return doSsOverUtPrecautions(preference);
176 } else if (preference == preferenceScreen.findPreference(
177 GsmUmtsCallOptions.CALL_BARRING_KEY)) {
178 return doSsOverUtPrecautions(preference);
179 }
180 return false;
181 }
182
183 private boolean doSsOverUtPrecautions(Preference preference) {
184 PersistableBundle b = null;
185 if (mSubscriptionInfoHelper.hasSubId()) {
186 b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
187 mSubscriptionInfoHelper.getSubId());
188 } else {
189 b = PhoneGlobals.getInstance().getCarrierConfig();
190 }
191
192 String configKey;
193 if (preference.getKey().equals(GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
194 configKey = CarrierConfigManager.KEY_CALL_FORWARDING_OVER_UT_WARNING_BOOL;
195 } else {
196 configKey = CarrierConfigManager.KEY_CALL_BARRING_OVER_UT_WARNING_BOOL;
197 }
198 if (b != null && b.getBoolean(configKey)
199 && mPhone != null
200 && SuppServicesUiUtil.isSsOverUtPrecautions(this, mPhone)) {
201 SuppServicesUiUtil.showBlockingSuppServicesDialog(this, mPhone,
202 preference.getKey()).show();
203 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204 }
205 return false;
206 }
207
208 /**
209 * Implemented to support onPreferenceChangeListener to look for preference
210 * changes.
211 *
212 * @param preference is the preference to be changed
213 * @param objValue should be the value of the selection, NOT its localized
214 * display value.
215 */
216 @Override
217 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800218 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700219
Andrew Leebf07f762015-04-07 19:05:50 -0700220 if (preference == mEnableVideoCalling) {
Malcolm Chen995721f2017-12-12 18:19:27 -0800221 if (mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530222 mImsMgr.setVtSetting((boolean) objValue);
Andrew Lee312e8172014-10-23 17:01:36 -0700223 } else {
Sooraj Sasindran9dbb2882021-10-19 11:40:34 -0700224 AlertDialog.Builder builder = FrameworksUtils.makeAlertDialogBuilder(this);
Andrew Lee312e8172014-10-23 17:01:36 -0700225 DialogInterface.OnClickListener networkSettingsClickListener =
226 new Dialog.OnClickListener() {
227 @Override
228 public void onClick(DialogInterface dialog, int which) {
Zoey Chenc9e19902022-05-23 15:24:13 +0800229 Intent intent = new Intent();
Pengquan Mengdb6b87e2019-06-18 17:42:16 -0700230 ComponentName mobileNetworkSettingsComponent = new ComponentName(
231 getString(R.string.mobile_network_settings_package),
232 getString(R.string.mobile_network_settings_class));
233 intent.setComponent(mobileNetworkSettingsComponent);
234 startActivity(intent);
Andrew Lee312e8172014-10-23 17:01:36 -0700235 }
236 };
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100237 builder.setMessage(getResourcesForSubId().getString(
Andrew Lee312e8172014-10-23 17:01:36 -0700238 R.string.enable_video_calling_dialog_msg))
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100239 .setNeutralButton(getResourcesForSubId().getString(
Andrew Lee312e8172014-10-23 17:01:36 -0700240 R.string.enable_video_calling_dialog_settings),
241 networkSettingsClickListener)
242 .setPositiveButton(android.R.string.ok, null)
243 .show();
244 return false;
245 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800247
248 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249 return true;
250 }
251
252 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253 protected void onCreate(Bundle icicle) {
254 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800255 if (DBG) log("onCreate: Intent is " + getIntent());
256
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -0700257 // Make sure we are running as an admin user.
Meng Wangc04cd2d2019-10-04 12:00:06 -0700258 UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
259 if (!userManager.isAdminUser()) {
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -0700260 Toast.makeText(this, R.string.call_settings_admin_user_only,
Jay Shraunerc2684732014-11-12 12:10:37 -0800261 Toast.LENGTH_SHORT).show();
262 finish();
263 return;
264 }
265
Andrew Leedd4f6df2014-12-09 19:13:51 -0800266 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee1479dd12014-11-06 23:06:32 -0800267 mPhone = mSubscriptionInfoHelper.getPhone();
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100268 mSubscriptionInfoHelper.setActionBarTitle(
269 getActionBar(), getResourcesForSubId(), R.string.call_settings_with_label);
Tyler Gunn77ee9382019-10-31 13:08:23 -0700270 mTelecomManager = getSystemService(TelecomManager.class);
Zoey Chen5ec326b2021-02-22 21:21:28 +0800271 mTelephonyCallback = new CallFeaturesTelephonyCallback();
Pranav Madapurmath4c830832022-10-14 21:44:05 +0000272
273 ActionBar actionBar = getActionBar();
274 if (actionBar != null) {
275 // sets the talkback voice prompt to say "Back" instead of "Navigate Up"
276 actionBar.setHomeActionContentDescription(R.string.ota_call_end);
277 }
Tyler Gunnbaee2952014-09-10 16:01:02 -0700278 }
279
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530280 private void updateImsManager(Phone phone) {
281 log("updateImsManager :: phone.getContext()=" + phone.getContext()
282 + " phone.getPhoneId()=" + phone.getPhoneId());
283 mImsMgr = ImsManager.getInstance(phone.getContext(), phone.getPhoneId());
284 if (mImsMgr == null) {
285 log("updateImsManager :: Could not get ImsManager instance!");
286 } else {
287 log("updateImsManager :: mImsMgr=" + mImsMgr);
288 }
289 }
290
Omata Shou81a0c8a2018-07-19 18:57:02 +0900291 private void listenPhoneState(boolean listen) {
Kazuki Iwami940af4d2019-02-25 18:07:38 +0900292 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
293 .createForSubscriptionId(mPhone.getSubId());
Zoey Chen5719bac2021-01-28 15:05:49 +0800294 if (listen) {
Zoey Chen5ec326b2021-02-22 21:21:28 +0800295 telephonyManager.registerTelephonyCallback(
296 new HandlerExecutor(new Handler(Looper.getMainLooper())), mTelephonyCallback);
Zoey Chen5719bac2021-01-28 15:05:49 +0800297 } else {
Zoey Chen5ec326b2021-02-22 21:21:28 +0800298 telephonyManager.unregisterTelephonyCallback(mTelephonyCallback);
Zoey Chen5719bac2021-01-28 15:05:49 +0800299 }
Omata Shou81a0c8a2018-07-19 18:57:02 +0900300 }
301
Zoey Chen5ec326b2021-02-22 21:21:28 +0800302 private final class CallFeaturesTelephonyCallback extends TelephonyCallback implements
303 TelephonyCallback.CallStateListener {
pkanwarb4aef112016-07-17 15:39:30 -0700304 @Override
Tyler Gunncca49da2021-03-08 15:58:26 -0800305 public void onCallStateChanged(int state) {
pkanwarb4aef112016-07-17 15:39:30 -0700306 if (DBG) log("PhoneStateListener onCallStateChanged: state is " + state);
Kazuki Iwami940af4d2019-02-25 18:07:38 +0900307 boolean isCallStateIdle = state == TelephonyManager.CALL_STATE_IDLE;
pkanwarb4aef112016-07-17 15:39:30 -0700308 if (mEnableVideoCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530309 mEnableVideoCalling.setEnabled(isCallStateIdle);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900310 }
311 if (mButtonWifiCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530312 mButtonWifiCalling.setEnabled(isCallStateIdle);
pkanwarb4aef112016-07-17 15:39:30 -0700313 }
314 }
Zoey Chen5719bac2021-01-28 15:05:49 +0800315 }
pkanwarb4aef112016-07-17 15:39:30 -0700316
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100317 private final ProvisioningManager.Callback mProvisioningCallback =
318 new ProvisioningManager.Callback() {
319 @Override
320 public void onProvisioningIntChanged(int item, int value) {
321 if (item == ImsConfig.ConfigConstants.VOICE_OVER_WIFI_SETTING_ENABLED
322 || item == ImsConfig.ConfigConstants.VLT_SETTING_ENABLED
323 || item == ImsConfig.ConfigConstants.LVC_SETTING_ENABLED) {
324 updateVtWfc();
325 }
326 }
327 };
328
pkanwarb4aef112016-07-17 15:39:30 -0700329 @Override
330 protected void onPause() {
pkanwar0a663122016-07-19 12:26:44 -0700331 super.onPause();
Omata Shou81a0c8a2018-07-19 18:57:02 +0900332 listenPhoneState(false);
SongFerngWang09ba5d92019-11-25 22:52:03 +0800333 unregisterReceiver(mReceiver);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100334
335 // Remove callback for provisioning changes.
336 try {
337 if (mImsMgr != null) {
338 mImsMgr.getConfigInterface().removeConfigCallback(
339 mProvisioningCallback.getBinder());
340 }
341 } catch (ImsException e) {
342 Log.w(LOG_TAG, "onPause: Unable to remove callback for provisioning changes");
343 }
pkanwarb4aef112016-07-17 15:39:30 -0700344 }
345
Tyler Gunnbaee2952014-09-10 16:01:02 -0700346 @Override
347 protected void onResume() {
348 super.onResume();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700349
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530350 updateImsManager(mPhone);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900351 listenPhoneState(true);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700352 PreferenceScreen preferenceScreen = getPreferenceScreen();
353 if (preferenceScreen != null) {
354 preferenceScreen.removeAll();
355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356
357 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -0700358
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530359 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
360 .createForSubscriptionId(mPhone.getSubId());
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800361
Yuling Liu7dc96de2018-06-11 14:14:23 +0800362 // Note: The PhoneAccountSettingsActivity accessible via the
363 // android.telecom.action.CHANGE_PHONE_ACCOUNTS intent is accessible directly from
364 // the AOSP Dialer settings page on multi-sim devices.
365 // Where a device does NOT make the PhoneAccountSettingsActivity directly accessible from
366 // its Dialer app, this check must be modified in the device's AOSP branch to ensure that
367 // the PhoneAccountSettingsActivity is always accessible.
368 if (telephonyManager.isMultiSimEnabled()) {
369 Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
370 getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
371 }
372
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee2c027892014-10-29 11:29:54 -0700374 mVoicemailSettingsScreen =
375 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Leebf07f762015-04-07 19:05:50 -0700376 mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
377 VoicemailSettingsActivity.class));
Andrew Lee8d66d812014-11-24 14:54:02 -0800378
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800379 maybeHideVoicemailSettings();
380
fionaxue46e69f2017-04-27 14:32:46 -0700381 mButtonAutoRetry = (SwitchPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800382
fionaxue46e69f2017-04-27 14:32:46 -0700383 mEnableVideoCalling = (SwitchPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100384 mButtonWifiCalling = findPreference(getResourcesForSubId().getString(
Malcolm Chen4042eb42018-02-26 15:58:44 -0800385 R.string.wifi_calling_settings_key));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700387 PersistableBundle carrierConfig =
388 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700389
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700390 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL)) {
Andrew Lee64a7d792014-10-15 17:38:38 -0700391 mButtonAutoRetry.setOnPreferenceChangeListener(this);
392 int autoretry = Settings.Global.getInt(
393 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
394 mButtonAutoRetry.setChecked(autoretry != 0);
395 } else {
396 prefSet.removePreference(mButtonAutoRetry);
397 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 }
399
Sanket Padawee09a6f62015-03-05 11:59:39 -0800400 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
401 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
Wileen Chiu98664e52015-07-29 14:10:01 +0530402 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
403 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700404 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
Sanket Padawee09a6f62015-03-05 11:59:39 -0800405 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
406 gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
407 } else {
Brad Ebinger931ab212021-06-14 11:50:39 -0700408 // Remove GSM options and repopulate the preferences in this Activity if phone type is
409 // GSM.
Andrew Lee2b36ba22014-11-05 17:08:49 -0800410 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411
412 int phoneType = mPhone.getPhoneType();
Junda Liua9ba9d42015-06-01 01:26:52 -0700413 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
Andrew Lee5ed870c2014-10-29 11:47:49 -0700414 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 } else {
Junda Liua09d6962014-11-12 13:39:02 -0800416 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
Brad Ebinger931ab212021-06-14 11:50:39 -0700417 // For now, just keep CdmaCallOptions as one entity. Eventually CDMA should
418 // follow the same pattern as GSM below, where VP and Call forwarding are
419 // populated here and Call waiting is populated in another "Additional Settings"
420 // submenu for CDMA.
Junda Liua09d6962014-11-12 13:39:02 -0800421 prefSet.removePreference(fdnButton);
Brad Ebinger931ab212021-06-14 11:50:39 -0700422 cdmaOptions.setSummary(null);
423 cdmaOptions.setTitle(R.string.additional_gsm_call_settings);
424 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
Junda Liua09d6962014-11-12 13:39:02 -0800425 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Brad Ebinger931ab212021-06-14 11:50:39 -0700426 prefSet.removePreference(cdmaOptions);
Xiangyu/Malcolm Chen2f810e82018-03-29 18:56:16 +0000427 if (mPhone.getIccCard() == null || !mPhone.getIccCard().getIccFdnAvailable()) {
428 prefSet.removePreference(fdnButton);
429 }
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700430 if (carrierConfig.getBoolean(
431 CarrierConfigManager.KEY_ADDITIONAL_CALL_SETTING_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800432 addPreferencesFromResource(R.xml.gsm_umts_call_options);
Sanket Padawee09a6f62015-03-05 11:59:39 -0800433 GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
Junda Liua09d6962014-11-12 13:39:02 -0800434 }
435 } else {
436 throw new IllegalStateException("Unexpected phone type: " + phoneType);
437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438 }
439 }
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100440 updateVtWfc();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100442 // Register callback for provisioning changes.
443 try {
444 if (mImsMgr != null) {
445 mImsMgr.getConfigInterface().addConfigCallback(mProvisioningCallback);
446 }
447 } catch (ImsException e) {
448 Log.w(LOG_TAG, "onResume: Unable to register callback for provisioning changes.");
449 }
SongFerngWang09ba5d92019-11-25 22:52:03 +0800450
451 IntentFilter intentFilter =
452 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
453 registerReceiver(mReceiver, intentFilter);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100454 }
455
456 private void updateVtWfc() {
457 PreferenceScreen prefSet = getPreferenceScreen();
458 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
459 .createForSubscriptionId(mPhone.getSubId());
460 PersistableBundle carrierConfig =
461 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Youming Ye91040ec2019-06-05 14:04:14 -0700462 boolean useWfcHomeModeForRoaming = carrierConfig.getBoolean(
Youming Ye8958ed52019-05-07 15:27:35 -0700463 CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL,
464 false);
Jack Yu99e87332021-12-17 23:14:15 -0800465 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -0700466 isDataEnabled = mPhone.getDataSettingsManager().isDataEnabled();
Malcolm Chen995721f2017-12-12 18:19:27 -0800467 if (mImsMgr.isVtEnabledByPlatform() && mImsMgr.isVtProvisionedOnDevice()
468 && (carrierConfig.getBoolean(
Jack Yub7628322016-11-28 11:10:18 -0800469 CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS)
Jack Yu99e87332021-12-17 23:14:15 -0800470 || isDataEnabled)) {
Andrew Lee312e8172014-10-23 17:01:36 -0700471 boolean currentValue =
Malcolm Chen995721f2017-12-12 18:19:27 -0800472 mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530473 ? mImsMgr.isVtEnabledByUser() : false;
Andrew Lee312e8172014-10-23 17:01:36 -0700474 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -0700475 mEnableVideoCalling.setOnPreferenceChangeListener(this);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100476 prefSet.addPreference(mEnableVideoCalling);
Andrew Lee77527ac2014-10-21 16:57:39 -0700477 } else {
478 prefSet.removePreference(mEnableVideoCalling);
479 }
Etan Cohena51d4ef2014-12-15 10:44:42 -0800480
Brad Ebinger85ff1822019-05-07 11:02:08 -0700481 final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManagerForSubscription(
482 mPhone.getSubId());
Santos Cordon499378a2015-06-25 18:51:39 -0700483 if (simCallManager != null) {
484 Intent intent = PhoneAccountSettingsFragment.buildPhoneAccountConfigureIntent(
485 this, simCallManager);
486 if (intent != null) {
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700487 PackageManager pm = mPhone.getContext().getPackageManager();
488 List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
489 if (!resolutions.isEmpty()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800490 mButtonWifiCalling.setTitle(resolutions.get(0).loadLabel(pm));
491 mButtonWifiCalling.setSummary(null);
492 mButtonWifiCalling.setIntent(intent);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100493 prefSet.addPreference(mButtonWifiCalling);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700494 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800495 prefSet.removePreference(mButtonWifiCalling);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700496 }
Yorke Lee0b8d2252015-06-10 16:31:20 -0700497 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800498 prefSet.removePreference(mButtonWifiCalling);
Yorke Lee0b8d2252015-06-10 16:31:20 -0700499 }
Malcolm Chen995721f2017-12-12 18:19:27 -0800500 } else if (!mImsMgr.isWfcEnabledByPlatform() || !mImsMgr.isWfcProvisionedOnDevice()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800501 prefSet.removePreference(mButtonWifiCalling);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800502 } else {
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100503 String title = getResourcesForSubId().getString(R.string.wifi_calling);
Wenting Xiong6fec4552018-08-04 17:56:50 +0800504 mButtonWifiCalling.setTitle(title);
505
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700506 int resId = com.android.internal.R.string.wifi_calling_off_summary;
Malcolm Chen995721f2017-12-12 18:19:27 -0800507 if (mImsMgr.isWfcEnabledByUser()) {
Youhan Wang269606e2017-01-19 15:25:55 -0800508 boolean isRoaming = telephonyManager.isNetworkRoaming();
Youming Ye91040ec2019-06-05 14:04:14 -0700509 // Also check carrier config for roaming mode
510 int wfcMode = mImsMgr.getWfcMode(isRoaming && !useWfcHomeModeForRoaming);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800511 switch (wfcMode) {
512 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700513 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800514 break;
515 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700516 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800517 break;
518 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700519 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800520 break;
521 default:
522 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
523 }
524 }
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100525 mButtonWifiCalling.setSummary(getResourcesForSubId().getString(resId));
Brad Ebinger1a1caf72019-04-29 15:55:40 -0700526 Intent intent = mButtonWifiCalling.getIntent();
527 if (intent != null) {
528 intent.putExtra(Settings.EXTRA_SUB_ID, mPhone.getSubId());
529 }
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100530 prefSet.addPreference(mButtonWifiCalling);
Andrew Leeb97fad82015-01-27 15:31:39 -0800531 }
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530532
533 try {
Brad Ebingera12246d2018-01-16 09:39:35 -0800534 if (mImsMgr.getImsServiceState() != ImsFeature.STATE_READY) {
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530535 log("Feature state not ready so remove vt and wfc settings for "
536 + " phone =" + mPhone.getPhoneId());
Malcolm Chen4042eb42018-02-26 15:58:44 -0800537 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530538 prefSet.removePreference(mEnableVideoCalling);
539 }
540 } catch (ImsException ex) {
541 log("Exception when trying to get ImsServiceStatus: " + ex);
Malcolm Chen4042eb42018-02-26 15:58:44 -0800542 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530543 prefSet.removePreference(mEnableVideoCalling);
544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 }
546
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800547 /**
548 * Hides the top level voicemail settings entry point if the default dialer contains a
549 * particular manifest metadata key. This is required when the default dialer wants to display
550 * its own version of voicemail settings.
551 */
552 private void maybeHideVoicemailSettings() {
553 String defaultDialer = getSystemService(TelecomManager.class).getDefaultDialerPackage();
554 if (defaultDialer == null) {
555 return;
556 }
557 try {
558 Bundle metadata = getPackageManager()
559 .getApplicationInfo(defaultDialer, PackageManager.GET_META_DATA).metaData;
Tyler Gunn8b6aa682017-04-06 16:01:59 -0700560 if (metadata == null) {
561 return;
562 }
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800563 if (!metadata
564 .getBoolean(TelephonyManager.METADATA_HIDE_VOICEMAIL_SETTINGS_MENU, false)) {
565 if (DBG) {
566 log("maybeHideVoicemailSettings(): not disabled by default dialer");
567 }
568 return;
569 }
570 getPreferenceScreen().removePreference(mVoicemailSettingsScreen);
571 if (DBG) {
572 log("maybeHideVoicemailSettings(): disabled by default dialer");
573 }
574 } catch (NameNotFoundException e) {
575 // do nothing
576 if (DBG) {
577 log("maybeHideVoicemailSettings(): not controlled by default dialer");
578 }
579 }
580 }
581
Andrew Lee785ca2a2014-12-18 12:46:41 -0800582 @Override
583 protected void onNewIntent(Intent newIntent) {
584 setIntent(newIntent);
585
586 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee785ca2a2014-12-18 12:46:41 -0800587 mPhone = mSubscriptionInfoHelper.getPhone();
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100588 mSubscriptionInfoHelper.setActionBarTitle(
589 getActionBar(), getResourcesForSubId(), R.string.call_settings_with_label);
Andrew Lee785ca2a2014-12-18 12:46:41 -0800590 }
591
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700592 private static void log(String msg) {
593 Log.d(LOG_TAG, msg);
594 }
595
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700596 @Override
597 public boolean onOptionsItemSelected(MenuItem item) {
598 final int itemId = item.getItemId();
599 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -0700600 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700601 return true;
602 }
603 return super.onOptionsItemSelected(item);
604 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800605
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700606 /**
607 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
608 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
609 */
Andrew Lee5efb1122014-12-05 04:20:42 -0800610 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800611 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
612 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700613 intent.setAction(Intent.ACTION_MAIN);
614 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
615 activity.startActivity(intent);
616 activity.finish();
617 }
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100618
619 private Resources getResourcesForSubId() {
620 if (mPhone != null) {
621 return SubscriptionManager.getResourcesForSubId(mPhone.getContext(), mPhone.getSubId());
622 } else {
623 return getResources();
624 }
625 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700626}