blob: 3f57cae1bc964c951256c48c7e6637c83abaf81c [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;
SongFerngWang09ba5d92019-11-25 22:52:03 +080022import android.content.BroadcastReceiver;
Pengquan Mengdb6b87e2019-06-18 17:42:16 -070023import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.content.Context;
25import android.content.DialogInterface;
26import android.content.Intent;
SongFerngWang09ba5d92019-11-25 22:52:03 +080027import android.content.IntentFilter;
Yorke Lee0b8d2252015-06-10 16:31:20 -070028import android.content.pm.PackageManager;
Ta-wei Yenb8e770c2017-01-24 17:49:58 -080029import android.content.pm.PackageManager.NameNotFoundException;
Yorke Lee0b8d2252015-06-10 16:31:20 -070030import android.content.pm.ResolveInfo;
Torbjorn Eklund209ed792019-03-06 15:15:30 +010031import android.content.res.Resources;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.os.Bundle;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070033import android.os.PersistableBundle;
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -070034import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.preference.Preference;
36import android.preference.PreferenceActivity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.preference.PreferenceScreen;
fionaxue46e69f2017-04-27 14:32:46 -070038import android.preference.SwitchPreference;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.provider.Settings;
Tyler Gunn4d45d1c2014-09-12 22:17:53 -070040import android.telecom.PhoneAccountHandle;
41import android.telecom.TelecomManager;
Jonathan Basseri4b40ff42015-04-30 21:54:10 -070042import android.telephony.CarrierConfigManager;
pkanwarb4aef112016-07-17 15:39:30 -070043import android.telephony.PhoneStateListener;
Wenting Xiong6fec4552018-08-04 17:56:50 +080044import android.telephony.SubscriptionManager;
Andrew Lee93c345f2014-10-27 15:25:07 -070045import android.telephony.TelephonyManager;
Torbjorn Eklund82d5d742018-11-29 15:32:13 +010046import android.telephony.ims.ProvisioningManager;
Malcolm Chen995721f2017-12-12 18:19:27 -080047import android.telephony.ims.feature.ImsFeature;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.util.Log;
49import android.view.MenuItem;
Jay Shraunerc2684732014-11-12 12:10:37 -080050import android.widget.Toast;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051
Andrew Leeeffef9c2015-02-19 16:02:37 -080052import com.android.ims.ImsConfig;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +053053import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070054import com.android.ims.ImsManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import com.android.internal.telephony.Phone;
56import com.android.internal.telephony.PhoneConstants;
Santos Cordon499378a2015-06-25 18:51:39 -070057import com.android.phone.settings.PhoneAccountSettingsFragment;
SongFerngWangbed485e2018-07-09 21:15:29 +080058import com.android.phone.settings.SuppServicesUiUtil;
Andrew Leebf07f762015-04-07 19:05:50 -070059import com.android.phone.settings.VoicemailSettingsActivity;
Andrew Lee5ed870c2014-10-29 11:47:49 -070060import com.android.phone.settings.fdn.FdnSetting;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import java.util.List;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063
64/**
65 * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
66 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070067 * This preference screen is the root of the "Call settings" hierarchy available from the Phone
68 * app; the settings here let you control various features related to phone calls (including
69 * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
70 * voice-capable phone devices.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071 *
72 * Note that this activity is part of the package com.android.phone, even
73 * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
74 * is from the package com.android.contacts.
75 *
76 * For the "Mobile network settings" screen under the main Settings app,
Pengquan Mengdb6b87e2019-06-18 17:42:16 -070077 * See {@link com.android.settings.network.telephony.MobileNetworkActivity}.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070078 */
79public class CallFeaturesSetting extends PreferenceActivity
Andrew Leebf07f762015-04-07 19:05:50 -070080 implements Preference.OnPreferenceChangeListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081 private static final String LOG_TAG = "CallFeaturesSetting";
82 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
83
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084 // String keys for preference lookup
85 // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
Andrew Lee8d66d812014-11-24 14:54:02 -080086 // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
87 // in the layout files. These strings need to be treated carefully; if the setting is
88 // persistent, they are used as the key to store shared preferences and the name should not be
89 // changed unless the settings are also migrated.
Andrew Lee97708a42014-09-25 12:39:07 -070090 private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091 private static final String BUTTON_FDN_KEY = "button_fdn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092 private static final String BUTTON_RETRY_KEY = "button_auto_retry_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093 private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
94 private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
95
Andrew Leece8ae2a2014-09-10 10:41:48 -070096 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
97 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -070098
Andrew Leedf14ead2014-10-17 14:22:52 -070099 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
100
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700101 private Phone mPhone;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530102 private ImsManager mImsMgr;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700103 private SubscriptionInfoHelper mSubscriptionInfoHelper;
Yorke Lee0b8d2252015-06-10 16:31:20 -0700104 private TelecomManager mTelecomManager;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700105
fionaxue46e69f2017-04-27 14:32:46 -0700106 private SwitchPreference mButtonAutoRetry;
Andrew Lee97708a42014-09-25 12:39:07 -0700107 private PreferenceScreen mVoicemailSettingsScreen;
fionaxue46e69f2017-04-27 14:32:46 -0700108 private SwitchPreference mEnableVideoCalling;
Malcolm Chen4042eb42018-02-26 15:58:44 -0800109 private Preference mButtonWifiCalling;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111 /*
112 * Click Listeners, handle click based on objects attached to UI.
113 */
114
SongFerngWang09ba5d92019-11-25 22:52:03 +0800115 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
116 @Override
117 public void onReceive(Context context, Intent intent) {
118 log("onReceive: " + intent.getAction());
119
120 if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) {
121 log("ACTION_AIRPLANE_MODE_CHANGED");
122
123 boolean isAirplaneModeOn = intent.getBooleanExtra("state", false);
124 handleAirplaneModeChange(isAirplaneModeOn);
125 }
126 }
127 };
128
129 private void handleAirplaneModeChange(boolean isAirplaneModeOn) {
130 PersistableBundle b = null;
131 if (mSubscriptionInfoHelper.hasSubId()) {
132 b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
133 mSubscriptionInfoHelper.getSubId());
134 } else {
135 b = PhoneGlobals.getInstance().getCarrierConfig();
136 }
137
138 if (b != null && b.getBoolean(
139 CarrierConfigManager.KEY_DISABLE_SUPPLEMENTARY_SERVICES_IN_AIRPLANE_MODE_BOOL)) {
140 PreferenceScreen preferenceScreen = getPreferenceScreen();
141 Preference callForwarding = preferenceScreen.findPreference(
142 GsmUmtsCallOptions.CALL_FORWARDING_KEY);
143 Preference callBarring = preferenceScreen.findPreference(
144 GsmUmtsCallOptions.CALL_BARRING_KEY);
145 Preference additional = preferenceScreen.findPreference(
146 GsmUmtsCallOptions.ADDITIONAL_GSM_SETTINGS_KEY);
147 if (callForwarding != null) {
148 callForwarding.setEnabled(!isAirplaneModeOn);
149 }
150 if (callBarring != null) {
151 callBarring.setEnabled(!isAirplaneModeOn);
152 }
153 if (additional != null) {
154 additional.setEnabled(!isAirplaneModeOn);
155 }
156 }
157 }
158
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159 // Click listener for all toggle events
160 @Override
161 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Andrew Leebf07f762015-04-07 19:05:50 -0700162 if (preference == mButtonAutoRetry) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
164 android.provider.Settings.Global.CALL_AUTO_RETRY,
165 mButtonAutoRetry.isChecked() ? 1 : 0);
166 return true;
SongFerngWangbed485e2018-07-09 21:15:29 +0800167 } else if (preference == preferenceScreen.findPreference(
168 GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
169 return doSsOverUtPrecautions(preference);
170 } else if (preference == preferenceScreen.findPreference(
171 GsmUmtsCallOptions.CALL_BARRING_KEY)) {
172 return doSsOverUtPrecautions(preference);
173 }
174 return false;
175 }
176
177 private boolean doSsOverUtPrecautions(Preference preference) {
178 PersistableBundle b = null;
179 if (mSubscriptionInfoHelper.hasSubId()) {
180 b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
181 mSubscriptionInfoHelper.getSubId());
182 } else {
183 b = PhoneGlobals.getInstance().getCarrierConfig();
184 }
185
186 String configKey;
187 if (preference.getKey().equals(GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
188 configKey = CarrierConfigManager.KEY_CALL_FORWARDING_OVER_UT_WARNING_BOOL;
189 } else {
190 configKey = CarrierConfigManager.KEY_CALL_BARRING_OVER_UT_WARNING_BOOL;
191 }
192 if (b != null && b.getBoolean(configKey)
193 && mPhone != null
194 && SuppServicesUiUtil.isSsOverUtPrecautions(this, mPhone)) {
195 SuppServicesUiUtil.showBlockingSuppServicesDialog(this, mPhone,
196 preference.getKey()).show();
197 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198 }
199 return false;
200 }
201
202 /**
203 * Implemented to support onPreferenceChangeListener to look for preference
204 * changes.
205 *
206 * @param preference is the preference to be changed
207 * @param objValue should be the value of the selection, NOT its localized
208 * display value.
209 */
210 @Override
211 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800212 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700213
Andrew Leebf07f762015-04-07 19:05:50 -0700214 if (preference == mEnableVideoCalling) {
Malcolm Chen995721f2017-12-12 18:19:27 -0800215 if (mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530216 mImsMgr.setVtSetting((boolean) objValue);
Andrew Lee312e8172014-10-23 17:01:36 -0700217 } else {
218 AlertDialog.Builder builder = new AlertDialog.Builder(this);
219 DialogInterface.OnClickListener networkSettingsClickListener =
220 new Dialog.OnClickListener() {
221 @Override
222 public void onClick(DialogInterface dialog, int which) {
Pengquan Mengdb6b87e2019-06-18 17:42:16 -0700223 Intent intent = new Intent(Intent.ACTION_MAIN);
224 ComponentName mobileNetworkSettingsComponent = new ComponentName(
225 getString(R.string.mobile_network_settings_package),
226 getString(R.string.mobile_network_settings_class));
227 intent.setComponent(mobileNetworkSettingsComponent);
228 startActivity(intent);
Andrew Lee312e8172014-10-23 17:01:36 -0700229 }
230 };
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100231 builder.setMessage(getResourcesForSubId().getString(
Andrew Lee312e8172014-10-23 17:01:36 -0700232 R.string.enable_video_calling_dialog_msg))
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100233 .setNeutralButton(getResourcesForSubId().getString(
Andrew Lee312e8172014-10-23 17:01:36 -0700234 R.string.enable_video_calling_dialog_settings),
235 networkSettingsClickListener)
236 .setPositiveButton(android.R.string.ok, null)
237 .show();
238 return false;
239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800241
242 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243 return true;
244 }
245
246 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247 protected void onCreate(Bundle icicle) {
248 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800249 if (DBG) log("onCreate: Intent is " + getIntent());
250
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -0700251 // Make sure we are running as an admin user.
Meng Wangc04cd2d2019-10-04 12:00:06 -0700252 UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
253 if (!userManager.isAdminUser()) {
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -0700254 Toast.makeText(this, R.string.call_settings_admin_user_only,
Jay Shraunerc2684732014-11-12 12:10:37 -0800255 Toast.LENGTH_SHORT).show();
256 finish();
257 return;
258 }
259
Andrew Leedd4f6df2014-12-09 19:13:51 -0800260 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee1479dd12014-11-06 23:06:32 -0800261 mPhone = mSubscriptionInfoHelper.getPhone();
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100262 mSubscriptionInfoHelper.setActionBarTitle(
263 getActionBar(), getResourcesForSubId(), R.string.call_settings_with_label);
Tyler Gunn77ee9382019-10-31 13:08:23 -0700264 mTelecomManager = getSystemService(TelecomManager.class);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700265 }
266
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530267 private void updateImsManager(Phone phone) {
268 log("updateImsManager :: phone.getContext()=" + phone.getContext()
269 + " phone.getPhoneId()=" + phone.getPhoneId());
270 mImsMgr = ImsManager.getInstance(phone.getContext(), phone.getPhoneId());
271 if (mImsMgr == null) {
272 log("updateImsManager :: Could not get ImsManager instance!");
273 } else {
274 log("updateImsManager :: mImsMgr=" + mImsMgr);
275 }
276 }
277
Omata Shou81a0c8a2018-07-19 18:57:02 +0900278 private void listenPhoneState(boolean listen) {
Kazuki Iwami940af4d2019-02-25 18:07:38 +0900279 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
280 .createForSubscriptionId(mPhone.getSubId());
Omata Shou81a0c8a2018-07-19 18:57:02 +0900281 telephonyManager.listen(mPhoneStateListener, listen
282 ? PhoneStateListener.LISTEN_CALL_STATE : PhoneStateListener.LISTEN_NONE);
283 }
284
pkanwarb4aef112016-07-17 15:39:30 -0700285 private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
286 @Override
287 public void onCallStateChanged(int state, String incomingNumber) {
288 if (DBG) log("PhoneStateListener onCallStateChanged: state is " + state);
Kazuki Iwami940af4d2019-02-25 18:07:38 +0900289 boolean isCallStateIdle = state == TelephonyManager.CALL_STATE_IDLE;
pkanwarb4aef112016-07-17 15:39:30 -0700290 if (mEnableVideoCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530291 mEnableVideoCalling.setEnabled(isCallStateIdle);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900292 }
293 if (mButtonWifiCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530294 mButtonWifiCalling.setEnabled(isCallStateIdle);
pkanwarb4aef112016-07-17 15:39:30 -0700295 }
296 }
297 };
298
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100299 private final ProvisioningManager.Callback mProvisioningCallback =
300 new ProvisioningManager.Callback() {
301 @Override
302 public void onProvisioningIntChanged(int item, int value) {
303 if (item == ImsConfig.ConfigConstants.VOICE_OVER_WIFI_SETTING_ENABLED
304 || item == ImsConfig.ConfigConstants.VLT_SETTING_ENABLED
305 || item == ImsConfig.ConfigConstants.LVC_SETTING_ENABLED) {
306 updateVtWfc();
307 }
308 }
309 };
310
pkanwarb4aef112016-07-17 15:39:30 -0700311 @Override
312 protected void onPause() {
pkanwar0a663122016-07-19 12:26:44 -0700313 super.onPause();
Omata Shou81a0c8a2018-07-19 18:57:02 +0900314 listenPhoneState(false);
SongFerngWang09ba5d92019-11-25 22:52:03 +0800315 unregisterReceiver(mReceiver);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100316
317 // Remove callback for provisioning changes.
318 try {
319 if (mImsMgr != null) {
320 mImsMgr.getConfigInterface().removeConfigCallback(
321 mProvisioningCallback.getBinder());
322 }
323 } catch (ImsException e) {
324 Log.w(LOG_TAG, "onPause: Unable to remove callback for provisioning changes");
325 }
pkanwarb4aef112016-07-17 15:39:30 -0700326 }
327
Tyler Gunnbaee2952014-09-10 16:01:02 -0700328 @Override
329 protected void onResume() {
330 super.onResume();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700331
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530332 updateImsManager(mPhone);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900333 listenPhoneState(true);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700334 PreferenceScreen preferenceScreen = getPreferenceScreen();
335 if (preferenceScreen != null) {
336 preferenceScreen.removeAll();
337 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338
339 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -0700340
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530341 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
342 .createForSubscriptionId(mPhone.getSubId());
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800343
Yuling Liu7dc96de2018-06-11 14:14:23 +0800344 // Note: The PhoneAccountSettingsActivity accessible via the
345 // android.telecom.action.CHANGE_PHONE_ACCOUNTS intent is accessible directly from
346 // the AOSP Dialer settings page on multi-sim devices.
347 // Where a device does NOT make the PhoneAccountSettingsActivity directly accessible from
348 // its Dialer app, this check must be modified in the device's AOSP branch to ensure that
349 // the PhoneAccountSettingsActivity is always accessible.
350 if (telephonyManager.isMultiSimEnabled()) {
351 Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
352 getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
353 }
354
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee2c027892014-10-29 11:29:54 -0700356 mVoicemailSettingsScreen =
357 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Leebf07f762015-04-07 19:05:50 -0700358 mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
359 VoicemailSettingsActivity.class));
Andrew Lee8d66d812014-11-24 14:54:02 -0800360
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800361 maybeHideVoicemailSettings();
362
fionaxue46e69f2017-04-27 14:32:46 -0700363 mButtonAutoRetry = (SwitchPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800364
fionaxue46e69f2017-04-27 14:32:46 -0700365 mEnableVideoCalling = (SwitchPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100366 mButtonWifiCalling = findPreference(getResourcesForSubId().getString(
Malcolm Chen4042eb42018-02-26 15:58:44 -0800367 R.string.wifi_calling_settings_key));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700369 PersistableBundle carrierConfig =
370 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700371
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700372 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL)) {
Andrew Lee64a7d792014-10-15 17:38:38 -0700373 mButtonAutoRetry.setOnPreferenceChangeListener(this);
374 int autoretry = Settings.Global.getInt(
375 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
376 mButtonAutoRetry.setChecked(autoretry != 0);
377 } else {
378 prefSet.removePreference(mButtonAutoRetry);
379 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 }
381
Sanket Padawee09a6f62015-03-05 11:59:39 -0800382 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
383 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
Wileen Chiu98664e52015-07-29 14:10:01 +0530384 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
385 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700386 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
Sanket Padawee09a6f62015-03-05 11:59:39 -0800387 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
388 gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
389 } else {
Andrew Lee2b36ba22014-11-05 17:08:49 -0800390 prefSet.removePreference(cdmaOptions);
Andrew Lee2b36ba22014-11-05 17:08:49 -0800391 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392
393 int phoneType = mPhone.getPhoneType();
Junda Liua9ba9d42015-06-01 01:26:52 -0700394 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
Andrew Lee5ed870c2014-10-29 11:47:49 -0700395 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 } else {
Junda Liua09d6962014-11-12 13:39:02 -0800397 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
398 prefSet.removePreference(fdnButton);
399
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700400 if (!carrierConfig.getBoolean(
Jonathan Basseri38c58552015-06-09 15:14:06 -0700401 CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800402 addPreferencesFromResource(R.xml.cdma_call_privacy);
403 }
404 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Xiangyu/Malcolm Chen2f810e82018-03-29 18:56:16 +0000405 if (mPhone.getIccCard() == null || !mPhone.getIccCard().getIccFdnAvailable()) {
406 prefSet.removePreference(fdnButton);
407 }
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700408 if (carrierConfig.getBoolean(
409 CarrierConfigManager.KEY_ADDITIONAL_CALL_SETTING_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800410 addPreferencesFromResource(R.xml.gsm_umts_call_options);
Sanket Padawee09a6f62015-03-05 11:59:39 -0800411 GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
Junda Liua09d6962014-11-12 13:39:02 -0800412 }
413 } else {
414 throw new IllegalStateException("Unexpected phone type: " + phoneType);
415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 }
417 }
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100418 updateVtWfc();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700419
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100420 // Register callback for provisioning changes.
421 try {
422 if (mImsMgr != null) {
423 mImsMgr.getConfigInterface().addConfigCallback(mProvisioningCallback);
424 }
425 } catch (ImsException e) {
426 Log.w(LOG_TAG, "onResume: Unable to register callback for provisioning changes.");
427 }
SongFerngWang09ba5d92019-11-25 22:52:03 +0800428
429 IntentFilter intentFilter =
430 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
431 registerReceiver(mReceiver, intentFilter);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100432 }
433
434 private void updateVtWfc() {
435 PreferenceScreen prefSet = getPreferenceScreen();
436 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
437 .createForSubscriptionId(mPhone.getSubId());
438 PersistableBundle carrierConfig =
439 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Youming Ye91040ec2019-06-05 14:04:14 -0700440 boolean useWfcHomeModeForRoaming = carrierConfig.getBoolean(
Youming Ye8958ed52019-05-07 15:27:35 -0700441 CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL,
442 false);
Malcolm Chen995721f2017-12-12 18:19:27 -0800443 if (mImsMgr.isVtEnabledByPlatform() && mImsMgr.isVtProvisionedOnDevice()
444 && (carrierConfig.getBoolean(
Jack Yub7628322016-11-28 11:10:18 -0800445 CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS)
Jack Yud79fba22018-12-13 11:51:28 -0800446 || mPhone.getDataEnabledSettings().isDataEnabled())) {
Andrew Lee312e8172014-10-23 17:01:36 -0700447 boolean currentValue =
Malcolm Chen995721f2017-12-12 18:19:27 -0800448 mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530449 ? mImsMgr.isVtEnabledByUser() : false;
Andrew Lee312e8172014-10-23 17:01:36 -0700450 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -0700451 mEnableVideoCalling.setOnPreferenceChangeListener(this);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100452 prefSet.addPreference(mEnableVideoCalling);
Andrew Lee77527ac2014-10-21 16:57:39 -0700453 } else {
454 prefSet.removePreference(mEnableVideoCalling);
455 }
Etan Cohena51d4ef2014-12-15 10:44:42 -0800456
Brad Ebinger85ff1822019-05-07 11:02:08 -0700457 final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManagerForSubscription(
458 mPhone.getSubId());
Santos Cordon499378a2015-06-25 18:51:39 -0700459 if (simCallManager != null) {
460 Intent intent = PhoneAccountSettingsFragment.buildPhoneAccountConfigureIntent(
461 this, simCallManager);
462 if (intent != null) {
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700463 PackageManager pm = mPhone.getContext().getPackageManager();
464 List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
465 if (!resolutions.isEmpty()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800466 mButtonWifiCalling.setTitle(resolutions.get(0).loadLabel(pm));
467 mButtonWifiCalling.setSummary(null);
468 mButtonWifiCalling.setIntent(intent);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100469 prefSet.addPreference(mButtonWifiCalling);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700470 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800471 prefSet.removePreference(mButtonWifiCalling);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700472 }
Yorke Lee0b8d2252015-06-10 16:31:20 -0700473 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800474 prefSet.removePreference(mButtonWifiCalling);
Yorke Lee0b8d2252015-06-10 16:31:20 -0700475 }
Malcolm Chen995721f2017-12-12 18:19:27 -0800476 } else if (!mImsMgr.isWfcEnabledByPlatform() || !mImsMgr.isWfcProvisionedOnDevice()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800477 prefSet.removePreference(mButtonWifiCalling);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800478 } else {
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100479 String title = getResourcesForSubId().getString(R.string.wifi_calling);
Wenting Xiong6fec4552018-08-04 17:56:50 +0800480 mButtonWifiCalling.setTitle(title);
481
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700482 int resId = com.android.internal.R.string.wifi_calling_off_summary;
Malcolm Chen995721f2017-12-12 18:19:27 -0800483 if (mImsMgr.isWfcEnabledByUser()) {
Youhan Wang269606e2017-01-19 15:25:55 -0800484 boolean isRoaming = telephonyManager.isNetworkRoaming();
Youming Ye91040ec2019-06-05 14:04:14 -0700485 // Also check carrier config for roaming mode
486 int wfcMode = mImsMgr.getWfcMode(isRoaming && !useWfcHomeModeForRoaming);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800487 switch (wfcMode) {
488 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700489 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800490 break;
491 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700492 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800493 break;
494 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700495 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800496 break;
497 default:
498 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
499 }
500 }
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100501 mButtonWifiCalling.setSummary(getResourcesForSubId().getString(resId));
Brad Ebinger1a1caf72019-04-29 15:55:40 -0700502 Intent intent = mButtonWifiCalling.getIntent();
503 if (intent != null) {
504 intent.putExtra(Settings.EXTRA_SUB_ID, mPhone.getSubId());
505 }
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100506 prefSet.addPreference(mButtonWifiCalling);
Andrew Leeb97fad82015-01-27 15:31:39 -0800507 }
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530508
509 try {
Brad Ebingera12246d2018-01-16 09:39:35 -0800510 if (mImsMgr.getImsServiceState() != ImsFeature.STATE_READY) {
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530511 log("Feature state not ready so remove vt and wfc settings for "
512 + " phone =" + mPhone.getPhoneId());
Malcolm Chen4042eb42018-02-26 15:58:44 -0800513 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530514 prefSet.removePreference(mEnableVideoCalling);
515 }
516 } catch (ImsException ex) {
517 log("Exception when trying to get ImsServiceStatus: " + ex);
Malcolm Chen4042eb42018-02-26 15:58:44 -0800518 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530519 prefSet.removePreference(mEnableVideoCalling);
520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 }
522
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800523 /**
524 * Hides the top level voicemail settings entry point if the default dialer contains a
525 * particular manifest metadata key. This is required when the default dialer wants to display
526 * its own version of voicemail settings.
527 */
528 private void maybeHideVoicemailSettings() {
529 String defaultDialer = getSystemService(TelecomManager.class).getDefaultDialerPackage();
530 if (defaultDialer == null) {
531 return;
532 }
533 try {
534 Bundle metadata = getPackageManager()
535 .getApplicationInfo(defaultDialer, PackageManager.GET_META_DATA).metaData;
Tyler Gunn8b6aa682017-04-06 16:01:59 -0700536 if (metadata == null) {
537 return;
538 }
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800539 if (!metadata
540 .getBoolean(TelephonyManager.METADATA_HIDE_VOICEMAIL_SETTINGS_MENU, false)) {
541 if (DBG) {
542 log("maybeHideVoicemailSettings(): not disabled by default dialer");
543 }
544 return;
545 }
546 getPreferenceScreen().removePreference(mVoicemailSettingsScreen);
547 if (DBG) {
548 log("maybeHideVoicemailSettings(): disabled by default dialer");
549 }
550 } catch (NameNotFoundException e) {
551 // do nothing
552 if (DBG) {
553 log("maybeHideVoicemailSettings(): not controlled by default dialer");
554 }
555 }
556 }
557
Andrew Lee785ca2a2014-12-18 12:46:41 -0800558 @Override
559 protected void onNewIntent(Intent newIntent) {
560 setIntent(newIntent);
561
562 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee785ca2a2014-12-18 12:46:41 -0800563 mPhone = mSubscriptionInfoHelper.getPhone();
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100564 mSubscriptionInfoHelper.setActionBarTitle(
565 getActionBar(), getResourcesForSubId(), R.string.call_settings_with_label);
Andrew Lee785ca2a2014-12-18 12:46:41 -0800566 }
567
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700568 private static void log(String msg) {
569 Log.d(LOG_TAG, msg);
570 }
571
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700572 @Override
573 public boolean onOptionsItemSelected(MenuItem item) {
574 final int itemId = item.getItemId();
575 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -0700576 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700577 return true;
578 }
579 return super.onOptionsItemSelected(item);
580 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800581
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700582 /**
583 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
584 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
585 */
Andrew Lee5efb1122014-12-05 04:20:42 -0800586 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800587 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
588 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700589 intent.setAction(Intent.ACTION_MAIN);
590 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
591 activity.startActivity(intent);
592 activity.finish();
593 }
Torbjorn Eklund209ed792019-03-06 15:15:30 +0100594
595 private Resources getResourcesForSubId() {
596 if (mPhone != null) {
597 return SubscriptionManager.getResourcesForSubId(mPhone.getContext(), mPhone.getSubId());
598 } else {
599 return getResources();
600 }
601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700602}