blob: fb1e3e4f7c3a9f78b5908b0a701761913a3922dc [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;
Malcolm Chen995721f2017-12-12 18:19:27 -080042import android.telephony.ims.feature.ImsFeature;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.util.Log;
44import android.view.MenuItem;
Jay Shraunerc2684732014-11-12 12:10:37 -080045import android.widget.Toast;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046
Andrew Leeeffef9c2015-02-19 16:02:37 -080047import com.android.ims.ImsConfig;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +053048import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070049import com.android.ims.ImsManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import com.android.internal.telephony.Phone;
51import com.android.internal.telephony.PhoneConstants;
Santos Cordon499378a2015-06-25 18:51:39 -070052import com.android.phone.settings.PhoneAccountSettingsFragment;
SongFerngWangbed485e2018-07-09 21:15:29 +080053import com.android.phone.settings.SuppServicesUiUtil;
Andrew Leebf07f762015-04-07 19:05:50 -070054import com.android.phone.settings.VoicemailSettingsActivity;
Andrew Lee5ed870c2014-10-29 11:47:49 -070055import com.android.phone.settings.fdn.FdnSetting;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import java.util.List;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058
59/**
60 * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
61 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070062 * This preference screen is the root of the "Call settings" hierarchy available from the Phone
63 * app; the settings here let you control various features related to phone calls (including
64 * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
65 * voice-capable phone devices.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066 *
67 * Note that this activity is part of the package com.android.phone, even
68 * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
69 * is from the package com.android.contacts.
70 *
71 * For the "Mobile network settings" screen under the main Settings app,
72 * See {@link MobileNetworkSettings}.
73 *
74 * @see com.android.phone.MobileNetworkSettings
75 */
76public class CallFeaturesSetting extends PreferenceActivity
Andrew Leebf07f762015-04-07 19:05:50 -070077 implements Preference.OnPreferenceChangeListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070078 private static final String LOG_TAG = "CallFeaturesSetting";
79 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
80
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081 // String keys for preference lookup
82 // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
Andrew Lee8d66d812014-11-24 14:54:02 -080083 // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
84 // in the layout files. These strings need to be treated carefully; if the setting is
85 // persistent, they are used as the key to store shared preferences and the name should not be
86 // changed unless the settings are also migrated.
Andrew Lee97708a42014-09-25 12:39:07 -070087 private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088 private static final String BUTTON_FDN_KEY = "button_fdn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089 private static final String BUTTON_RETRY_KEY = "button_auto_retry_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090 private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
91 private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
92
Andrew Leece8ae2a2014-09-10 10:41:48 -070093 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
94 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -070095
Andrew Leedf14ead2014-10-17 14:22:52 -070096 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
97
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098 private Phone mPhone;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +053099 private ImsManager mImsMgr;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700100 private SubscriptionInfoHelper mSubscriptionInfoHelper;
Yorke Lee0b8d2252015-06-10 16:31:20 -0700101 private TelecomManager mTelecomManager;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700102
fionaxue46e69f2017-04-27 14:32:46 -0700103 private SwitchPreference mButtonAutoRetry;
Andrew Lee97708a42014-09-25 12:39:07 -0700104 private PreferenceScreen mVoicemailSettingsScreen;
fionaxue46e69f2017-04-27 14:32:46 -0700105 private SwitchPreference mEnableVideoCalling;
Malcolm Chen4042eb42018-02-26 15:58:44 -0800106 private Preference mButtonWifiCalling;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108 /*
109 * Click Listeners, handle click based on objects attached to UI.
110 */
111
112 // Click listener for all toggle events
113 @Override
114 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Andrew Leebf07f762015-04-07 19:05:50 -0700115 if (preference == mButtonAutoRetry) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
117 android.provider.Settings.Global.CALL_AUTO_RETRY,
118 mButtonAutoRetry.isChecked() ? 1 : 0);
119 return true;
SongFerngWangbed485e2018-07-09 21:15:29 +0800120 } else if (preference == preferenceScreen.findPreference(
121 GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
122 return doSsOverUtPrecautions(preference);
123 } else if (preference == preferenceScreen.findPreference(
124 GsmUmtsCallOptions.CALL_BARRING_KEY)) {
125 return doSsOverUtPrecautions(preference);
126 }
127 return false;
128 }
129
130 private boolean doSsOverUtPrecautions(Preference preference) {
131 PersistableBundle b = null;
132 if (mSubscriptionInfoHelper.hasSubId()) {
133 b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
134 mSubscriptionInfoHelper.getSubId());
135 } else {
136 b = PhoneGlobals.getInstance().getCarrierConfig();
137 }
138
139 String configKey;
140 if (preference.getKey().equals(GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
141 configKey = CarrierConfigManager.KEY_CALL_FORWARDING_OVER_UT_WARNING_BOOL;
142 } else {
143 configKey = CarrierConfigManager.KEY_CALL_BARRING_OVER_UT_WARNING_BOOL;
144 }
145 if (b != null && b.getBoolean(configKey)
146 && mPhone != null
147 && SuppServicesUiUtil.isSsOverUtPrecautions(this, mPhone)) {
148 SuppServicesUiUtil.showBlockingSuppServicesDialog(this, mPhone,
149 preference.getKey()).show();
150 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151 }
152 return false;
153 }
154
155 /**
156 * Implemented to support onPreferenceChangeListener to look for preference
157 * changes.
158 *
159 * @param preference is the preference to be changed
160 * @param objValue should be the value of the selection, NOT its localized
161 * display value.
162 */
163 @Override
164 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800165 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700166
Andrew Leebf07f762015-04-07 19:05:50 -0700167 if (preference == mEnableVideoCalling) {
Malcolm Chen995721f2017-12-12 18:19:27 -0800168 if (mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530169 mImsMgr.setVtSetting((boolean) objValue);
Andrew Lee312e8172014-10-23 17:01:36 -0700170 } else {
171 AlertDialog.Builder builder = new AlertDialog.Builder(this);
172 DialogInterface.OnClickListener networkSettingsClickListener =
173 new Dialog.OnClickListener() {
174 @Override
175 public void onClick(DialogInterface dialog, int which) {
176 startActivity(new Intent(mPhone.getContext(),
177 com.android.phone.MobileNetworkSettings.class));
178 }
179 };
180 builder.setMessage(getResources().getString(
181 R.string.enable_video_calling_dialog_msg))
182 .setNeutralButton(getResources().getString(
183 R.string.enable_video_calling_dialog_settings),
184 networkSettingsClickListener)
185 .setPositiveButton(android.R.string.ok, null)
186 .show();
187 return false;
188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800190
191 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 return true;
193 }
194
195 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196 protected void onCreate(Bundle icicle) {
197 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800198 if (DBG) log("onCreate: Intent is " + getIntent());
199
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -0700200 // Make sure we are running as an admin user.
201 if (!UserManager.get(this).isAdminUser()) {
202 Toast.makeText(this, R.string.call_settings_admin_user_only,
Jay Shraunerc2684732014-11-12 12:10:37 -0800203 Toast.LENGTH_SHORT).show();
204 finish();
205 return;
206 }
207
Andrew Leedd4f6df2014-12-09 19:13:51 -0800208 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5ed870c2014-10-29 11:47:49 -0700209 mSubscriptionInfoHelper.setActionBarTitle(
210 getActionBar(), getResources(), R.string.call_settings_with_label);
Andrew Lee1479dd12014-11-06 23:06:32 -0800211 mPhone = mSubscriptionInfoHelper.getPhone();
Yorke Lee0b8d2252015-06-10 16:31:20 -0700212 mTelecomManager = TelecomManager.from(this);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700213 }
214
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530215 private void updateImsManager(Phone phone) {
216 log("updateImsManager :: phone.getContext()=" + phone.getContext()
217 + " phone.getPhoneId()=" + phone.getPhoneId());
218 mImsMgr = ImsManager.getInstance(phone.getContext(), phone.getPhoneId());
219 if (mImsMgr == null) {
220 log("updateImsManager :: Could not get ImsManager instance!");
221 } else {
222 log("updateImsManager :: mImsMgr=" + mImsMgr);
223 }
224 }
225
Omata Shou81a0c8a2018-07-19 18:57:02 +0900226 private void listenPhoneState(boolean listen) {
227 TelephonyManager telephonyManager =
228 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
229 telephonyManager.listen(mPhoneStateListener, listen
230 ? PhoneStateListener.LISTEN_CALL_STATE : PhoneStateListener.LISTEN_NONE);
231 }
232
pkanwarb4aef112016-07-17 15:39:30 -0700233 private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
234 @Override
235 public void onCallStateChanged(int state, String incomingNumber) {
236 if (DBG) log("PhoneStateListener onCallStateChanged: state is " + state);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900237 // Use TelecomManager#getCallStete instead of 'state' parameter because it needs
238 // to check the current state of all phone calls.
239 boolean isCallStateIdle =
240 mTelecomManager.getCallState() == TelephonyManager.CALL_STATE_IDLE;
pkanwarb4aef112016-07-17 15:39:30 -0700241 if (mEnableVideoCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530242 mEnableVideoCalling.setEnabled(isCallStateIdle);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900243 }
244 if (mButtonWifiCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530245 mButtonWifiCalling.setEnabled(isCallStateIdle);
pkanwarb4aef112016-07-17 15:39:30 -0700246 }
247 }
248 };
249
250 @Override
251 protected void onPause() {
pkanwar0a663122016-07-19 12:26:44 -0700252 super.onPause();
Omata Shou81a0c8a2018-07-19 18:57:02 +0900253 listenPhoneState(false);
pkanwarb4aef112016-07-17 15:39:30 -0700254 }
255
Tyler Gunnbaee2952014-09-10 16:01:02 -0700256 @Override
257 protected void onResume() {
258 super.onResume();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700259
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530260 updateImsManager(mPhone);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900261 listenPhoneState(true);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700262 PreferenceScreen preferenceScreen = getPreferenceScreen();
263 if (preferenceScreen != null) {
264 preferenceScreen.removeAll();
265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700266
267 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -0700268
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530269 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
270 .createForSubscriptionId(mPhone.getSubId());
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800271
Yuling Liu7dc96de2018-06-11 14:14:23 +0800272 // Note: The PhoneAccountSettingsActivity accessible via the
273 // android.telecom.action.CHANGE_PHONE_ACCOUNTS intent is accessible directly from
274 // the AOSP Dialer settings page on multi-sim devices.
275 // Where a device does NOT make the PhoneAccountSettingsActivity directly accessible from
276 // its Dialer app, this check must be modified in the device's AOSP branch to ensure that
277 // the PhoneAccountSettingsActivity is always accessible.
278 if (telephonyManager.isMultiSimEnabled()) {
279 Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
280 getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
281 }
282
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700283 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee2c027892014-10-29 11:29:54 -0700284 mVoicemailSettingsScreen =
285 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Leebf07f762015-04-07 19:05:50 -0700286 mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
287 VoicemailSettingsActivity.class));
Andrew Lee8d66d812014-11-24 14:54:02 -0800288
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800289 maybeHideVoicemailSettings();
290
fionaxue46e69f2017-04-27 14:32:46 -0700291 mButtonAutoRetry = (SwitchPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800292
fionaxue46e69f2017-04-27 14:32:46 -0700293 mEnableVideoCalling = (SwitchPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Malcolm Chen4042eb42018-02-26 15:58:44 -0800294 mButtonWifiCalling = findPreference(getResources().getString(
295 R.string.wifi_calling_settings_key));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700297 PersistableBundle carrierConfig =
298 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700299
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700300 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL)) {
Andrew Lee64a7d792014-10-15 17:38:38 -0700301 mButtonAutoRetry.setOnPreferenceChangeListener(this);
302 int autoretry = Settings.Global.getInt(
303 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
304 mButtonAutoRetry.setChecked(autoretry != 0);
305 } else {
306 prefSet.removePreference(mButtonAutoRetry);
307 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700308 }
309
Sanket Padawee09a6f62015-03-05 11:59:39 -0800310 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
311 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
Wileen Chiu98664e52015-07-29 14:10:01 +0530312 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
313 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700314 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
Sanket Padawee09a6f62015-03-05 11:59:39 -0800315 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
316 gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
317 } else {
Andrew Lee2b36ba22014-11-05 17:08:49 -0800318 prefSet.removePreference(cdmaOptions);
Andrew Lee2b36ba22014-11-05 17:08:49 -0800319 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700320
321 int phoneType = mPhone.getPhoneType();
Junda Liua9ba9d42015-06-01 01:26:52 -0700322 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
Andrew Lee5ed870c2014-10-29 11:47:49 -0700323 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324 } else {
Junda Liua09d6962014-11-12 13:39:02 -0800325 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
326 prefSet.removePreference(fdnButton);
327
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700328 if (!carrierConfig.getBoolean(
Jonathan Basseri38c58552015-06-09 15:14:06 -0700329 CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800330 addPreferencesFromResource(R.xml.cdma_call_privacy);
331 }
332 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Xiangyu/Malcolm Chen2f810e82018-03-29 18:56:16 +0000333 if (mPhone.getIccCard() == null || !mPhone.getIccCard().getIccFdnAvailable()) {
334 prefSet.removePreference(fdnButton);
335 }
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700336 if (carrierConfig.getBoolean(
337 CarrierConfigManager.KEY_ADDITIONAL_CALL_SETTING_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800338 addPreferencesFromResource(R.xml.gsm_umts_call_options);
Sanket Padawee09a6f62015-03-05 11:59:39 -0800339 GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
Junda Liua09d6962014-11-12 13:39:02 -0800340 }
341 } else {
342 throw new IllegalStateException("Unexpected phone type: " + phoneType);
343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344 }
345 }
346
Malcolm Chen995721f2017-12-12 18:19:27 -0800347 if (mImsMgr.isVtEnabledByPlatform() && mImsMgr.isVtProvisionedOnDevice()
348 && (carrierConfig.getBoolean(
Jack Yub7628322016-11-28 11:10:18 -0800349 CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS)
Jack Yud79fba22018-12-13 11:51:28 -0800350 || mPhone.getDataEnabledSettings().isDataEnabled())) {
Andrew Lee312e8172014-10-23 17:01:36 -0700351 boolean currentValue =
Malcolm Chen995721f2017-12-12 18:19:27 -0800352 mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530353 ? mImsMgr.isVtEnabledByUser() : false;
Andrew Lee312e8172014-10-23 17:01:36 -0700354 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -0700355 mEnableVideoCalling.setOnPreferenceChangeListener(this);
356 } else {
357 prefSet.removePreference(mEnableVideoCalling);
358 }
Etan Cohena51d4ef2014-12-15 10:44:42 -0800359
Yorke Lee0b8d2252015-06-10 16:31:20 -0700360 final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManager();
Santos Cordon499378a2015-06-25 18:51:39 -0700361 if (simCallManager != null) {
362 Intent intent = PhoneAccountSettingsFragment.buildPhoneAccountConfigureIntent(
363 this, simCallManager);
364 if (intent != null) {
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700365 PackageManager pm = mPhone.getContext().getPackageManager();
366 List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
367 if (!resolutions.isEmpty()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800368 mButtonWifiCalling.setTitle(resolutions.get(0).loadLabel(pm));
369 mButtonWifiCalling.setSummary(null);
370 mButtonWifiCalling.setIntent(intent);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700371 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800372 prefSet.removePreference(mButtonWifiCalling);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700373 }
Yorke Lee0b8d2252015-06-10 16:31:20 -0700374 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800375 prefSet.removePreference(mButtonWifiCalling);
Yorke Lee0b8d2252015-06-10 16:31:20 -0700376 }
Malcolm Chen995721f2017-12-12 18:19:27 -0800377 } else if (!mImsMgr.isWfcEnabledByPlatform() || !mImsMgr.isWfcProvisionedOnDevice()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800378 prefSet.removePreference(mButtonWifiCalling);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800379 } else {
Wenting Xiong6fec4552018-08-04 17:56:50 +0800380 String title = SubscriptionManager.getResourcesForSubId(mPhone.getContext(),
381 mPhone.getSubId()).getString(R.string.wifi_calling);
382 mButtonWifiCalling.setTitle(title);
383
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700384 int resId = com.android.internal.R.string.wifi_calling_off_summary;
Malcolm Chen995721f2017-12-12 18:19:27 -0800385 if (mImsMgr.isWfcEnabledByUser()) {
Youhan Wang269606e2017-01-19 15:25:55 -0800386 boolean isRoaming = telephonyManager.isNetworkRoaming();
Malcolm Chen995721f2017-12-12 18:19:27 -0800387 int wfcMode = mImsMgr.getWfcMode(isRoaming);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800388 switch (wfcMode) {
389 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700390 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800391 break;
392 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700393 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800394 break;
395 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700396 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800397 break;
398 default:
399 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
400 }
401 }
Malcolm Chen4042eb42018-02-26 15:58:44 -0800402 mButtonWifiCalling.setSummary(resId);
Andrew Leeb97fad82015-01-27 15:31:39 -0800403 }
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530404
405 try {
Brad Ebingera12246d2018-01-16 09:39:35 -0800406 if (mImsMgr.getImsServiceState() != ImsFeature.STATE_READY) {
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530407 log("Feature state not ready so remove vt and wfc settings for "
408 + " phone =" + mPhone.getPhoneId());
Malcolm Chen4042eb42018-02-26 15:58:44 -0800409 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530410 prefSet.removePreference(mEnableVideoCalling);
411 }
412 } catch (ImsException ex) {
413 log("Exception when trying to get ImsServiceStatus: " + ex);
Malcolm Chen4042eb42018-02-26 15:58:44 -0800414 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530415 prefSet.removePreference(mEnableVideoCalling);
416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417 }
418
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800419 /**
420 * Hides the top level voicemail settings entry point if the default dialer contains a
421 * particular manifest metadata key. This is required when the default dialer wants to display
422 * its own version of voicemail settings.
423 */
424 private void maybeHideVoicemailSettings() {
425 String defaultDialer = getSystemService(TelecomManager.class).getDefaultDialerPackage();
426 if (defaultDialer == null) {
427 return;
428 }
429 try {
430 Bundle metadata = getPackageManager()
431 .getApplicationInfo(defaultDialer, PackageManager.GET_META_DATA).metaData;
Tyler Gunn8b6aa682017-04-06 16:01:59 -0700432 if (metadata == null) {
433 return;
434 }
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800435 if (!metadata
436 .getBoolean(TelephonyManager.METADATA_HIDE_VOICEMAIL_SETTINGS_MENU, false)) {
437 if (DBG) {
438 log("maybeHideVoicemailSettings(): not disabled by default dialer");
439 }
440 return;
441 }
442 getPreferenceScreen().removePreference(mVoicemailSettingsScreen);
443 if (DBG) {
444 log("maybeHideVoicemailSettings(): disabled by default dialer");
445 }
446 } catch (NameNotFoundException e) {
447 // do nothing
448 if (DBG) {
449 log("maybeHideVoicemailSettings(): not controlled by default dialer");
450 }
451 }
452 }
453
Andrew Lee785ca2a2014-12-18 12:46:41 -0800454 @Override
455 protected void onNewIntent(Intent newIntent) {
456 setIntent(newIntent);
457
458 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
459 mSubscriptionInfoHelper.setActionBarTitle(
460 getActionBar(), getResources(), R.string.call_settings_with_label);
461 mPhone = mSubscriptionInfoHelper.getPhone();
462 }
463
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700464 private static void log(String msg) {
465 Log.d(LOG_TAG, msg);
466 }
467
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 @Override
469 public boolean onOptionsItemSelected(MenuItem item) {
470 final int itemId = item.getItemId();
471 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -0700472 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 return true;
474 }
475 return super.onOptionsItemSelected(item);
476 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800477
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478 /**
479 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
480 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
481 */
Andrew Lee5efb1122014-12-05 04:20:42 -0800482 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800483 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
484 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485 intent.setAction(Intent.ACTION_MAIN);
486 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
487 activity.startActivity(intent);
488 activity.finish();
489 }
490}