blob: ffb729288432e56a55778457b5fd7bcb9ac1489e [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.content.Context;
23import android.content.DialogInterface;
24import android.content.Intent;
Yorke Lee0b8d2252015-06-10 16:31:20 -070025import android.content.pm.PackageManager;
Ta-wei Yenb8e770c2017-01-24 17:49:58 -080026import android.content.pm.PackageManager.NameNotFoundException;
Yorke Lee0b8d2252015-06-10 16:31:20 -070027import android.content.pm.ResolveInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.os.Bundle;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070029import android.os.PersistableBundle;
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -070030import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.preference.Preference;
32import android.preference.PreferenceActivity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.preference.PreferenceScreen;
fionaxue46e69f2017-04-27 14:32:46 -070034import android.preference.SwitchPreference;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.provider.Settings;
Tyler Gunn4d45d1c2014-09-12 22:17:53 -070036import android.telecom.PhoneAccountHandle;
37import android.telecom.TelecomManager;
Jonathan Basseri4b40ff42015-04-30 21:54:10 -070038import android.telephony.CarrierConfigManager;
pkanwarb4aef112016-07-17 15:39:30 -070039import android.telephony.PhoneStateListener;
Wenting Xiong6fec4552018-08-04 17:56:50 +080040import android.telephony.SubscriptionManager;
Andrew Lee93c345f2014-10-27 15:25:07 -070041import android.telephony.TelephonyManager;
Torbjorn Eklund82d5d742018-11-29 15:32:13 +010042import android.telephony.ims.ProvisioningManager;
Malcolm Chen995721f2017-12-12 18:19:27 -080043import android.telephony.ims.feature.ImsFeature;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.util.Log;
45import android.view.MenuItem;
Jay Shraunerc2684732014-11-12 12:10:37 -080046import android.widget.Toast;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047
Andrew Leeeffef9c2015-02-19 16:02:37 -080048import com.android.ims.ImsConfig;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +053049import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070050import com.android.ims.ImsManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import com.android.internal.telephony.Phone;
52import com.android.internal.telephony.PhoneConstants;
Santos Cordon499378a2015-06-25 18:51:39 -070053import com.android.phone.settings.PhoneAccountSettingsFragment;
SongFerngWangbed485e2018-07-09 21:15:29 +080054import com.android.phone.settings.SuppServicesUiUtil;
Andrew Leebf07f762015-04-07 19:05:50 -070055import com.android.phone.settings.VoicemailSettingsActivity;
Andrew Lee5ed870c2014-10-29 11:47:49 -070056import com.android.phone.settings.fdn.FdnSetting;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import java.util.List;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059
60/**
61 * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
62 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070063 * This preference screen is the root of the "Call settings" hierarchy available from the Phone
64 * app; the settings here let you control various features related to phone calls (including
65 * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
66 * voice-capable phone devices.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067 *
68 * Note that this activity is part of the package com.android.phone, even
69 * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
70 * is from the package com.android.contacts.
71 *
72 * For the "Mobile network settings" screen under the main Settings app,
73 * See {@link MobileNetworkSettings}.
74 *
75 * @see com.android.phone.MobileNetworkSettings
76 */
77public class CallFeaturesSetting extends PreferenceActivity
Andrew Leebf07f762015-04-07 19:05:50 -070078 implements Preference.OnPreferenceChangeListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079 private static final String LOG_TAG = "CallFeaturesSetting";
80 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
81
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082 // String keys for preference lookup
83 // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
Andrew Lee8d66d812014-11-24 14:54:02 -080084 // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
85 // in the layout files. These strings need to be treated carefully; if the setting is
86 // persistent, they are used as the key to store shared preferences and the name should not be
87 // changed unless the settings are also migrated.
Andrew Lee97708a42014-09-25 12:39:07 -070088 private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089 private static final String BUTTON_FDN_KEY = "button_fdn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090 private static final String BUTTON_RETRY_KEY = "button_auto_retry_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091 private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
92 private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
93
Andrew Leece8ae2a2014-09-10 10:41:48 -070094 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
95 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -070096
Andrew Leedf14ead2014-10-17 14:22:52 -070097 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
98
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099 private Phone mPhone;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530100 private ImsManager mImsMgr;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700101 private SubscriptionInfoHelper mSubscriptionInfoHelper;
Yorke Lee0b8d2252015-06-10 16:31:20 -0700102 private TelecomManager mTelecomManager;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700103
fionaxue46e69f2017-04-27 14:32:46 -0700104 private SwitchPreference mButtonAutoRetry;
Andrew Lee97708a42014-09-25 12:39:07 -0700105 private PreferenceScreen mVoicemailSettingsScreen;
fionaxue46e69f2017-04-27 14:32:46 -0700106 private SwitchPreference mEnableVideoCalling;
Malcolm Chen4042eb42018-02-26 15:58:44 -0800107 private Preference mButtonWifiCalling;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109 /*
110 * Click Listeners, handle click based on objects attached to UI.
111 */
112
113 // Click listener for all toggle events
114 @Override
115 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Andrew Leebf07f762015-04-07 19:05:50 -0700116 if (preference == mButtonAutoRetry) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
118 android.provider.Settings.Global.CALL_AUTO_RETRY,
119 mButtonAutoRetry.isChecked() ? 1 : 0);
120 return true;
SongFerngWangbed485e2018-07-09 21:15:29 +0800121 } else if (preference == preferenceScreen.findPreference(
122 GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
123 return doSsOverUtPrecautions(preference);
124 } else if (preference == preferenceScreen.findPreference(
125 GsmUmtsCallOptions.CALL_BARRING_KEY)) {
126 return doSsOverUtPrecautions(preference);
127 }
128 return false;
129 }
130
131 private boolean doSsOverUtPrecautions(Preference preference) {
132 PersistableBundle b = null;
133 if (mSubscriptionInfoHelper.hasSubId()) {
134 b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
135 mSubscriptionInfoHelper.getSubId());
136 } else {
137 b = PhoneGlobals.getInstance().getCarrierConfig();
138 }
139
140 String configKey;
141 if (preference.getKey().equals(GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
142 configKey = CarrierConfigManager.KEY_CALL_FORWARDING_OVER_UT_WARNING_BOOL;
143 } else {
144 configKey = CarrierConfigManager.KEY_CALL_BARRING_OVER_UT_WARNING_BOOL;
145 }
146 if (b != null && b.getBoolean(configKey)
147 && mPhone != null
148 && SuppServicesUiUtil.isSsOverUtPrecautions(this, mPhone)) {
149 SuppServicesUiUtil.showBlockingSuppServicesDialog(this, mPhone,
150 preference.getKey()).show();
151 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152 }
153 return false;
154 }
155
156 /**
157 * Implemented to support onPreferenceChangeListener to look for preference
158 * changes.
159 *
160 * @param preference is the preference to be changed
161 * @param objValue should be the value of the selection, NOT its localized
162 * display value.
163 */
164 @Override
165 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800166 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700167
Andrew Leebf07f762015-04-07 19:05:50 -0700168 if (preference == mEnableVideoCalling) {
Malcolm Chen995721f2017-12-12 18:19:27 -0800169 if (mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530170 mImsMgr.setVtSetting((boolean) objValue);
Andrew Lee312e8172014-10-23 17:01:36 -0700171 } else {
172 AlertDialog.Builder builder = new AlertDialog.Builder(this);
173 DialogInterface.OnClickListener networkSettingsClickListener =
174 new Dialog.OnClickListener() {
175 @Override
176 public void onClick(DialogInterface dialog, int which) {
177 startActivity(new Intent(mPhone.getContext(),
178 com.android.phone.MobileNetworkSettings.class));
179 }
180 };
181 builder.setMessage(getResources().getString(
182 R.string.enable_video_calling_dialog_msg))
183 .setNeutralButton(getResources().getString(
184 R.string.enable_video_calling_dialog_settings),
185 networkSettingsClickListener)
186 .setPositiveButton(android.R.string.ok, null)
187 .show();
188 return false;
189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800191
192 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 return true;
194 }
195
196 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197 protected void onCreate(Bundle icicle) {
198 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800199 if (DBG) log("onCreate: Intent is " + getIntent());
200
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -0700201 // Make sure we are running as an admin user.
202 if (!UserManager.get(this).isAdminUser()) {
203 Toast.makeText(this, R.string.call_settings_admin_user_only,
Jay Shraunerc2684732014-11-12 12:10:37 -0800204 Toast.LENGTH_SHORT).show();
205 finish();
206 return;
207 }
208
Andrew Leedd4f6df2014-12-09 19:13:51 -0800209 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5ed870c2014-10-29 11:47:49 -0700210 mSubscriptionInfoHelper.setActionBarTitle(
211 getActionBar(), getResources(), R.string.call_settings_with_label);
Andrew Lee1479dd12014-11-06 23:06:32 -0800212 mPhone = mSubscriptionInfoHelper.getPhone();
Yorke Lee0b8d2252015-06-10 16:31:20 -0700213 mTelecomManager = TelecomManager.from(this);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700214 }
215
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530216 private void updateImsManager(Phone phone) {
217 log("updateImsManager :: phone.getContext()=" + phone.getContext()
218 + " phone.getPhoneId()=" + phone.getPhoneId());
219 mImsMgr = ImsManager.getInstance(phone.getContext(), phone.getPhoneId());
220 if (mImsMgr == null) {
221 log("updateImsManager :: Could not get ImsManager instance!");
222 } else {
223 log("updateImsManager :: mImsMgr=" + mImsMgr);
224 }
225 }
226
Omata Shou81a0c8a2018-07-19 18:57:02 +0900227 private void listenPhoneState(boolean listen) {
228 TelephonyManager telephonyManager =
229 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
230 telephonyManager.listen(mPhoneStateListener, listen
231 ? PhoneStateListener.LISTEN_CALL_STATE : PhoneStateListener.LISTEN_NONE);
232 }
233
pkanwarb4aef112016-07-17 15:39:30 -0700234 private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
235 @Override
236 public void onCallStateChanged(int state, String incomingNumber) {
237 if (DBG) log("PhoneStateListener onCallStateChanged: state is " + state);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900238 // Use TelecomManager#getCallStete instead of 'state' parameter because it needs
239 // to check the current state of all phone calls.
240 boolean isCallStateIdle =
241 mTelecomManager.getCallState() == TelephonyManager.CALL_STATE_IDLE;
pkanwarb4aef112016-07-17 15:39:30 -0700242 if (mEnableVideoCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530243 mEnableVideoCalling.setEnabled(isCallStateIdle);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900244 }
245 if (mButtonWifiCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530246 mButtonWifiCalling.setEnabled(isCallStateIdle);
pkanwarb4aef112016-07-17 15:39:30 -0700247 }
248 }
249 };
250
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100251 private final ProvisioningManager.Callback mProvisioningCallback =
252 new ProvisioningManager.Callback() {
253 @Override
254 public void onProvisioningIntChanged(int item, int value) {
255 if (item == ImsConfig.ConfigConstants.VOICE_OVER_WIFI_SETTING_ENABLED
256 || item == ImsConfig.ConfigConstants.VLT_SETTING_ENABLED
257 || item == ImsConfig.ConfigConstants.LVC_SETTING_ENABLED) {
258 updateVtWfc();
259 }
260 }
261 };
262
pkanwarb4aef112016-07-17 15:39:30 -0700263 @Override
264 protected void onPause() {
pkanwar0a663122016-07-19 12:26:44 -0700265 super.onPause();
Omata Shou81a0c8a2018-07-19 18:57:02 +0900266 listenPhoneState(false);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100267
268 // Remove callback for provisioning changes.
269 try {
270 if (mImsMgr != null) {
271 mImsMgr.getConfigInterface().removeConfigCallback(
272 mProvisioningCallback.getBinder());
273 }
274 } catch (ImsException e) {
275 Log.w(LOG_TAG, "onPause: Unable to remove callback for provisioning changes");
276 }
pkanwarb4aef112016-07-17 15:39:30 -0700277 }
278
Tyler Gunnbaee2952014-09-10 16:01:02 -0700279 @Override
280 protected void onResume() {
281 super.onResume();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700282
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530283 updateImsManager(mPhone);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900284 listenPhoneState(true);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700285 PreferenceScreen preferenceScreen = getPreferenceScreen();
286 if (preferenceScreen != null) {
287 preferenceScreen.removeAll();
288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289
290 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -0700291
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530292 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
293 .createForSubscriptionId(mPhone.getSubId());
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800294
Yuling Liu7dc96de2018-06-11 14:14:23 +0800295 // Note: The PhoneAccountSettingsActivity accessible via the
296 // android.telecom.action.CHANGE_PHONE_ACCOUNTS intent is accessible directly from
297 // the AOSP Dialer settings page on multi-sim devices.
298 // Where a device does NOT make the PhoneAccountSettingsActivity directly accessible from
299 // its Dialer app, this check must be modified in the device's AOSP branch to ensure that
300 // the PhoneAccountSettingsActivity is always accessible.
301 if (telephonyManager.isMultiSimEnabled()) {
302 Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
303 getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
304 }
305
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee2c027892014-10-29 11:29:54 -0700307 mVoicemailSettingsScreen =
308 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Leebf07f762015-04-07 19:05:50 -0700309 mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
310 VoicemailSettingsActivity.class));
Andrew Lee8d66d812014-11-24 14:54:02 -0800311
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800312 maybeHideVoicemailSettings();
313
fionaxue46e69f2017-04-27 14:32:46 -0700314 mButtonAutoRetry = (SwitchPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800315
fionaxue46e69f2017-04-27 14:32:46 -0700316 mEnableVideoCalling = (SwitchPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Malcolm Chen4042eb42018-02-26 15:58:44 -0800317 mButtonWifiCalling = findPreference(getResources().getString(
318 R.string.wifi_calling_settings_key));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700320 PersistableBundle carrierConfig =
321 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700322
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700323 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL)) {
Andrew Lee64a7d792014-10-15 17:38:38 -0700324 mButtonAutoRetry.setOnPreferenceChangeListener(this);
325 int autoretry = Settings.Global.getInt(
326 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
327 mButtonAutoRetry.setChecked(autoretry != 0);
328 } else {
329 prefSet.removePreference(mButtonAutoRetry);
330 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331 }
332
Sanket Padawee09a6f62015-03-05 11:59:39 -0800333 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
334 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
Wileen Chiu98664e52015-07-29 14:10:01 +0530335 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
336 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700337 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
Sanket Padawee09a6f62015-03-05 11:59:39 -0800338 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
339 gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
340 } else {
Andrew Lee2b36ba22014-11-05 17:08:49 -0800341 prefSet.removePreference(cdmaOptions);
Andrew Lee2b36ba22014-11-05 17:08:49 -0800342 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343
344 int phoneType = mPhone.getPhoneType();
Junda Liua9ba9d42015-06-01 01:26:52 -0700345 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
Andrew Lee5ed870c2014-10-29 11:47:49 -0700346 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347 } else {
Junda Liua09d6962014-11-12 13:39:02 -0800348 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
349 prefSet.removePreference(fdnButton);
350
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700351 if (!carrierConfig.getBoolean(
Jonathan Basseri38c58552015-06-09 15:14:06 -0700352 CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800353 addPreferencesFromResource(R.xml.cdma_call_privacy);
354 }
355 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Xiangyu/Malcolm Chen2f810e82018-03-29 18:56:16 +0000356 if (mPhone.getIccCard() == null || !mPhone.getIccCard().getIccFdnAvailable()) {
357 prefSet.removePreference(fdnButton);
358 }
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700359 if (carrierConfig.getBoolean(
360 CarrierConfigManager.KEY_ADDITIONAL_CALL_SETTING_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800361 addPreferencesFromResource(R.xml.gsm_umts_call_options);
Sanket Padawee09a6f62015-03-05 11:59:39 -0800362 GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
Junda Liua09d6962014-11-12 13:39:02 -0800363 }
364 } else {
365 throw new IllegalStateException("Unexpected phone type: " + phoneType);
366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 }
368 }
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100369 updateVtWfc();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100371 // Register callback for provisioning changes.
372 try {
373 if (mImsMgr != null) {
374 mImsMgr.getConfigInterface().addConfigCallback(mProvisioningCallback);
375 }
376 } catch (ImsException e) {
377 Log.w(LOG_TAG, "onResume: Unable to register callback for provisioning changes.");
378 }
379 }
380
381 private void updateVtWfc() {
382 PreferenceScreen prefSet = getPreferenceScreen();
383 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
384 .createForSubscriptionId(mPhone.getSubId());
385 PersistableBundle carrierConfig =
386 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Malcolm Chen995721f2017-12-12 18:19:27 -0800387 if (mImsMgr.isVtEnabledByPlatform() && mImsMgr.isVtProvisionedOnDevice()
388 && (carrierConfig.getBoolean(
Jack Yub7628322016-11-28 11:10:18 -0800389 CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS)
Jack Yud79fba22018-12-13 11:51:28 -0800390 || mPhone.getDataEnabledSettings().isDataEnabled())) {
Andrew Lee312e8172014-10-23 17:01:36 -0700391 boolean currentValue =
Malcolm Chen995721f2017-12-12 18:19:27 -0800392 mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530393 ? mImsMgr.isVtEnabledByUser() : false;
Andrew Lee312e8172014-10-23 17:01:36 -0700394 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -0700395 mEnableVideoCalling.setOnPreferenceChangeListener(this);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100396 prefSet.addPreference(mEnableVideoCalling);
Andrew Lee77527ac2014-10-21 16:57:39 -0700397 } else {
398 prefSet.removePreference(mEnableVideoCalling);
399 }
Etan Cohena51d4ef2014-12-15 10:44:42 -0800400
Yorke Lee0b8d2252015-06-10 16:31:20 -0700401 final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManager();
Santos Cordon499378a2015-06-25 18:51:39 -0700402 if (simCallManager != null) {
403 Intent intent = PhoneAccountSettingsFragment.buildPhoneAccountConfigureIntent(
404 this, simCallManager);
405 if (intent != null) {
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700406 PackageManager pm = mPhone.getContext().getPackageManager();
407 List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
408 if (!resolutions.isEmpty()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800409 mButtonWifiCalling.setTitle(resolutions.get(0).loadLabel(pm));
410 mButtonWifiCalling.setSummary(null);
411 mButtonWifiCalling.setIntent(intent);
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100412 prefSet.addPreference(mButtonWifiCalling);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700413 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800414 prefSet.removePreference(mButtonWifiCalling);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700415 }
Yorke Lee0b8d2252015-06-10 16:31:20 -0700416 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800417 prefSet.removePreference(mButtonWifiCalling);
Yorke Lee0b8d2252015-06-10 16:31:20 -0700418 }
Malcolm Chen995721f2017-12-12 18:19:27 -0800419 } else if (!mImsMgr.isWfcEnabledByPlatform() || !mImsMgr.isWfcProvisionedOnDevice()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800420 prefSet.removePreference(mButtonWifiCalling);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800421 } else {
Wenting Xiong6fec4552018-08-04 17:56:50 +0800422 String title = SubscriptionManager.getResourcesForSubId(mPhone.getContext(),
423 mPhone.getSubId()).getString(R.string.wifi_calling);
424 mButtonWifiCalling.setTitle(title);
425
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700426 int resId = com.android.internal.R.string.wifi_calling_off_summary;
Malcolm Chen995721f2017-12-12 18:19:27 -0800427 if (mImsMgr.isWfcEnabledByUser()) {
Youhan Wang269606e2017-01-19 15:25:55 -0800428 boolean isRoaming = telephonyManager.isNetworkRoaming();
Malcolm Chen995721f2017-12-12 18:19:27 -0800429 int wfcMode = mImsMgr.getWfcMode(isRoaming);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800430 switch (wfcMode) {
431 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700432 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800433 break;
434 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700435 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800436 break;
437 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700438 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800439 break;
440 default:
441 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
442 }
443 }
Malcolm Chen4042eb42018-02-26 15:58:44 -0800444 mButtonWifiCalling.setSummary(resId);
Brad Ebinger1a1caf72019-04-29 15:55:40 -0700445 Intent intent = mButtonWifiCalling.getIntent();
446 if (intent != null) {
447 intent.putExtra(Settings.EXTRA_SUB_ID, mPhone.getSubId());
448 }
Torbjorn Eklund82d5d742018-11-29 15:32:13 +0100449 prefSet.addPreference(mButtonWifiCalling);
Andrew Leeb97fad82015-01-27 15:31:39 -0800450 }
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530451
452 try {
Brad Ebingera12246d2018-01-16 09:39:35 -0800453 if (mImsMgr.getImsServiceState() != ImsFeature.STATE_READY) {
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530454 log("Feature state not ready so remove vt and wfc settings for "
455 + " phone =" + mPhone.getPhoneId());
Malcolm Chen4042eb42018-02-26 15:58:44 -0800456 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530457 prefSet.removePreference(mEnableVideoCalling);
458 }
459 } catch (ImsException ex) {
460 log("Exception when trying to get ImsServiceStatus: " + ex);
Malcolm Chen4042eb42018-02-26 15:58:44 -0800461 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530462 prefSet.removePreference(mEnableVideoCalling);
463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700464 }
465
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800466 /**
467 * Hides the top level voicemail settings entry point if the default dialer contains a
468 * particular manifest metadata key. This is required when the default dialer wants to display
469 * its own version of voicemail settings.
470 */
471 private void maybeHideVoicemailSettings() {
472 String defaultDialer = getSystemService(TelecomManager.class).getDefaultDialerPackage();
473 if (defaultDialer == null) {
474 return;
475 }
476 try {
477 Bundle metadata = getPackageManager()
478 .getApplicationInfo(defaultDialer, PackageManager.GET_META_DATA).metaData;
Tyler Gunn8b6aa682017-04-06 16:01:59 -0700479 if (metadata == null) {
480 return;
481 }
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800482 if (!metadata
483 .getBoolean(TelephonyManager.METADATA_HIDE_VOICEMAIL_SETTINGS_MENU, false)) {
484 if (DBG) {
485 log("maybeHideVoicemailSettings(): not disabled by default dialer");
486 }
487 return;
488 }
489 getPreferenceScreen().removePreference(mVoicemailSettingsScreen);
490 if (DBG) {
491 log("maybeHideVoicemailSettings(): disabled by default dialer");
492 }
493 } catch (NameNotFoundException e) {
494 // do nothing
495 if (DBG) {
496 log("maybeHideVoicemailSettings(): not controlled by default dialer");
497 }
498 }
499 }
500
Andrew Lee785ca2a2014-12-18 12:46:41 -0800501 @Override
502 protected void onNewIntent(Intent newIntent) {
503 setIntent(newIntent);
504
505 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
506 mSubscriptionInfoHelper.setActionBarTitle(
507 getActionBar(), getResources(), R.string.call_settings_with_label);
508 mPhone = mSubscriptionInfoHelper.getPhone();
509 }
510
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511 private static void log(String msg) {
512 Log.d(LOG_TAG, msg);
513 }
514
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700515 @Override
516 public boolean onOptionsItemSelected(MenuItem item) {
517 final int itemId = item.getItemId();
518 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -0700519 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 return true;
521 }
522 return super.onOptionsItemSelected(item);
523 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800524
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 /**
526 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
527 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
528 */
Andrew Lee5efb1122014-12-05 04:20:42 -0800529 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800530 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
531 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700532 intent.setAction(Intent.ACTION_MAIN);
533 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
534 activity.startActivity(intent);
535 activity.finish();
536 }
537}