blob: 5a4026d51db4e6683a53469735dfb8b4fb5038fb [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 Xiong73045392018-08-04 17:56:50 +080040import android.telephony.SubscriptionManager;
Andrew Lee93c345f2014-10-27 15:25:07 -070041import android.telephony.TelephonyManager;
Torbjorn Eklund13971a22018-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;
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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120 }
121 return false;
122 }
123
124 /**
125 * Implemented to support onPreferenceChangeListener to look for preference
126 * changes.
127 *
128 * @param preference is the preference to be changed
129 * @param objValue should be the value of the selection, NOT its localized
130 * display value.
131 */
132 @Override
133 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800134 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700135
Andrew Leebf07f762015-04-07 19:05:50 -0700136 if (preference == mEnableVideoCalling) {
Malcolm Chen995721f2017-12-12 18:19:27 -0800137 if (mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530138 mImsMgr.setVtSetting((boolean) objValue);
Andrew Lee312e8172014-10-23 17:01:36 -0700139 } else {
140 AlertDialog.Builder builder = new AlertDialog.Builder(this);
141 DialogInterface.OnClickListener networkSettingsClickListener =
142 new Dialog.OnClickListener() {
143 @Override
144 public void onClick(DialogInterface dialog, int which) {
145 startActivity(new Intent(mPhone.getContext(),
146 com.android.phone.MobileNetworkSettings.class));
147 }
148 };
149 builder.setMessage(getResources().getString(
150 R.string.enable_video_calling_dialog_msg))
151 .setNeutralButton(getResources().getString(
152 R.string.enable_video_calling_dialog_settings),
153 networkSettingsClickListener)
154 .setPositiveButton(android.R.string.ok, null)
155 .show();
156 return false;
157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800159
160 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161 return true;
162 }
163
164 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165 protected void onCreate(Bundle icicle) {
166 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800167 if (DBG) log("onCreate: Intent is " + getIntent());
168
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -0700169 // Make sure we are running as an admin user.
170 if (!UserManager.get(this).isAdminUser()) {
171 Toast.makeText(this, R.string.call_settings_admin_user_only,
Jay Shraunerc2684732014-11-12 12:10:37 -0800172 Toast.LENGTH_SHORT).show();
173 finish();
174 return;
175 }
176
Andrew Leedd4f6df2014-12-09 19:13:51 -0800177 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5ed870c2014-10-29 11:47:49 -0700178 mSubscriptionInfoHelper.setActionBarTitle(
179 getActionBar(), getResources(), R.string.call_settings_with_label);
Andrew Lee1479dd12014-11-06 23:06:32 -0800180 mPhone = mSubscriptionInfoHelper.getPhone();
Yorke Lee0b8d2252015-06-10 16:31:20 -0700181 mTelecomManager = TelecomManager.from(this);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700182 }
183
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530184 private void updateImsManager(Phone phone) {
185 log("updateImsManager :: phone.getContext()=" + phone.getContext()
186 + " phone.getPhoneId()=" + phone.getPhoneId());
187 mImsMgr = ImsManager.getInstance(phone.getContext(), phone.getPhoneId());
188 if (mImsMgr == null) {
189 log("updateImsManager :: Could not get ImsManager instance!");
190 } else {
191 log("updateImsManager :: mImsMgr=" + mImsMgr);
192 }
193 }
194
Omata Shou81a0c8a2018-07-19 18:57:02 +0900195 private void listenPhoneState(boolean listen) {
196 TelephonyManager telephonyManager =
197 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
198 telephonyManager.listen(mPhoneStateListener, listen
199 ? PhoneStateListener.LISTEN_CALL_STATE : PhoneStateListener.LISTEN_NONE);
200 }
201
pkanwarb4aef112016-07-17 15:39:30 -0700202 private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
203 @Override
204 public void onCallStateChanged(int state, String incomingNumber) {
205 if (DBG) log("PhoneStateListener onCallStateChanged: state is " + state);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900206 // Use TelecomManager#getCallStete instead of 'state' parameter because it needs
207 // to check the current state of all phone calls.
208 boolean isCallStateIdle =
209 mTelecomManager.getCallState() == TelephonyManager.CALL_STATE_IDLE;
pkanwarb4aef112016-07-17 15:39:30 -0700210 if (mEnableVideoCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530211 mEnableVideoCalling.setEnabled(isCallStateIdle);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900212 }
213 if (mButtonWifiCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530214 mButtonWifiCalling.setEnabled(isCallStateIdle);
pkanwarb4aef112016-07-17 15:39:30 -0700215 }
216 }
217 };
218
Torbjorn Eklund13971a22018-11-29 15:32:13 +0100219 private final ProvisioningManager.Callback mProvisioningCallback =
220 new ProvisioningManager.Callback() {
221 @Override
222 public void onProvisioningIntChanged(int item, int value) {
223 if (item == ImsConfig.ConfigConstants.VOICE_OVER_WIFI_SETTING_ENABLED
224 || item == ImsConfig.ConfigConstants.VLT_SETTING_ENABLED
225 || item == ImsConfig.ConfigConstants.LVC_SETTING_ENABLED) {
226 updateVtWfc();
227 }
228 }
229 };
230
pkanwarb4aef112016-07-17 15:39:30 -0700231 @Override
232 protected void onPause() {
pkanwar0a663122016-07-19 12:26:44 -0700233 super.onPause();
Omata Shou81a0c8a2018-07-19 18:57:02 +0900234 listenPhoneState(false);
Torbjorn Eklund13971a22018-11-29 15:32:13 +0100235
236 // Remove callback for provisioning changes.
237 try {
238 if (mImsMgr != null) {
239 mImsMgr.getConfigInterface().removeConfigCallback(
240 mProvisioningCallback.getBinder());
241 }
242 } catch (ImsException e) {
243 Log.w(LOG_TAG, "onPause: Unable to remove callback for provisioning changes");
244 }
pkanwarb4aef112016-07-17 15:39:30 -0700245 }
246
Tyler Gunnbaee2952014-09-10 16:01:02 -0700247 @Override
248 protected void onResume() {
249 super.onResume();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700250
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530251 updateImsManager(mPhone);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900252 listenPhoneState(true);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700253 PreferenceScreen preferenceScreen = getPreferenceScreen();
254 if (preferenceScreen != null) {
255 preferenceScreen.removeAll();
256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257
258 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -0700259
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530260 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
261 .createForSubscriptionId(mPhone.getSubId());
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800262
Yuling Liu7dc96de2018-06-11 14:14:23 +0800263 // Note: The PhoneAccountSettingsActivity accessible via the
264 // android.telecom.action.CHANGE_PHONE_ACCOUNTS intent is accessible directly from
265 // the AOSP Dialer settings page on multi-sim devices.
266 // Where a device does NOT make the PhoneAccountSettingsActivity directly accessible from
267 // its Dialer app, this check must be modified in the device's AOSP branch to ensure that
268 // the PhoneAccountSettingsActivity is always accessible.
269 if (telephonyManager.isMultiSimEnabled()) {
270 Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
271 getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
272 }
273
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee2c027892014-10-29 11:29:54 -0700275 mVoicemailSettingsScreen =
276 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Leebf07f762015-04-07 19:05:50 -0700277 mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
278 VoicemailSettingsActivity.class));
Andrew Lee8d66d812014-11-24 14:54:02 -0800279
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800280 maybeHideVoicemailSettings();
281
fionaxue46e69f2017-04-27 14:32:46 -0700282 mButtonAutoRetry = (SwitchPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800283
fionaxue46e69f2017-04-27 14:32:46 -0700284 mEnableVideoCalling = (SwitchPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Malcolm Chen4042eb42018-02-26 15:58:44 -0800285 mButtonWifiCalling = findPreference(getResources().getString(
286 R.string.wifi_calling_settings_key));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700288 PersistableBundle carrierConfig =
289 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700290
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700291 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL)) {
Andrew Lee64a7d792014-10-15 17:38:38 -0700292 mButtonAutoRetry.setOnPreferenceChangeListener(this);
293 int autoretry = Settings.Global.getInt(
294 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
295 mButtonAutoRetry.setChecked(autoretry != 0);
296 } else {
297 prefSet.removePreference(mButtonAutoRetry);
298 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 }
300
Sanket Padawee09a6f62015-03-05 11:59:39 -0800301 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
302 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
Wileen Chiu98664e52015-07-29 14:10:01 +0530303 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
304 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700305 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
Sanket Padawee09a6f62015-03-05 11:59:39 -0800306 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
307 gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
308 } else {
Andrew Lee2b36ba22014-11-05 17:08:49 -0800309 prefSet.removePreference(cdmaOptions);
Andrew Lee2b36ba22014-11-05 17:08:49 -0800310 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311
312 int phoneType = mPhone.getPhoneType();
Junda Liua9ba9d42015-06-01 01:26:52 -0700313 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
Andrew Lee5ed870c2014-10-29 11:47:49 -0700314 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315 } else {
Junda Liua09d6962014-11-12 13:39:02 -0800316 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
317 prefSet.removePreference(fdnButton);
318
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700319 if (!carrierConfig.getBoolean(
Jonathan Basseri38c58552015-06-09 15:14:06 -0700320 CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800321 addPreferencesFromResource(R.xml.cdma_call_privacy);
322 }
323 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Xiangyu/Malcolm Chen2f810e82018-03-29 18:56:16 +0000324 if (mPhone.getIccCard() == null || !mPhone.getIccCard().getIccFdnAvailable()) {
325 prefSet.removePreference(fdnButton);
326 }
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700327 if (carrierConfig.getBoolean(
328 CarrierConfigManager.KEY_ADDITIONAL_CALL_SETTING_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800329 addPreferencesFromResource(R.xml.gsm_umts_call_options);
Sanket Padawee09a6f62015-03-05 11:59:39 -0800330 GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
Junda Liua09d6962014-11-12 13:39:02 -0800331 }
332 } else {
333 throw new IllegalStateException("Unexpected phone type: " + phoneType);
334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335 }
336 }
Torbjorn Eklund13971a22018-11-29 15:32:13 +0100337 updateVtWfc();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338
Torbjorn Eklund13971a22018-11-29 15:32:13 +0100339 // Register callback for provisioning changes.
340 try {
341 if (mImsMgr != null) {
342 mImsMgr.getConfigInterface().addConfigCallback(mProvisioningCallback);
343 }
344 } catch (ImsException e) {
345 Log.w(LOG_TAG, "onResume: Unable to register callback for provisioning changes.");
346 }
347 }
348
349 private void updateVtWfc() {
350 PreferenceScreen prefSet = getPreferenceScreen();
351 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
352 .createForSubscriptionId(mPhone.getSubId());
353 PersistableBundle carrierConfig =
354 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Youming Ye482a2672019-05-07 15:27:35 -0700355 boolean editableWfcRoamingMode = true;
356 boolean useWfcHomeModeForRoaming = false;
357 if (carrierConfig != null) {
358 editableWfcRoamingMode = carrierConfig.getBoolean(
359 CarrierConfigManager.KEY_EDITABLE_WFC_ROAMING_MODE_BOOL);
360 useWfcHomeModeForRoaming = carrierConfig.getBoolean(
361 CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL,
362 false);
363 }
Malcolm Chen995721f2017-12-12 18:19:27 -0800364 if (mImsMgr.isVtEnabledByPlatform() && mImsMgr.isVtProvisionedOnDevice()
365 && (carrierConfig.getBoolean(
Jack Yub7628322016-11-28 11:10:18 -0800366 CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS)
Jack Yu7a030e52018-12-13 11:51:28 -0800367 || mPhone.getDataEnabledSettings().isDataEnabled())) {
Andrew Lee312e8172014-10-23 17:01:36 -0700368 boolean currentValue =
Malcolm Chen995721f2017-12-12 18:19:27 -0800369 mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530370 ? mImsMgr.isVtEnabledByUser() : false;
Andrew Lee312e8172014-10-23 17:01:36 -0700371 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -0700372 mEnableVideoCalling.setOnPreferenceChangeListener(this);
Torbjorn Eklund13971a22018-11-29 15:32:13 +0100373 prefSet.addPreference(mEnableVideoCalling);
Andrew Lee77527ac2014-10-21 16:57:39 -0700374 } else {
375 prefSet.removePreference(mEnableVideoCalling);
376 }
Etan Cohena51d4ef2014-12-15 10:44:42 -0800377
Brad Ebinger860bbb42019-05-07 11:02:08 -0700378 final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManagerForSubscription(
379 mPhone.getSubId());
Santos Cordon499378a2015-06-25 18:51:39 -0700380 if (simCallManager != null) {
381 Intent intent = PhoneAccountSettingsFragment.buildPhoneAccountConfigureIntent(
382 this, simCallManager);
383 if (intent != null) {
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700384 PackageManager pm = mPhone.getContext().getPackageManager();
385 List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
386 if (!resolutions.isEmpty()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800387 mButtonWifiCalling.setTitle(resolutions.get(0).loadLabel(pm));
388 mButtonWifiCalling.setSummary(null);
389 mButtonWifiCalling.setIntent(intent);
Torbjorn Eklund13971a22018-11-29 15:32:13 +0100390 prefSet.addPreference(mButtonWifiCalling);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700391 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800392 prefSet.removePreference(mButtonWifiCalling);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700393 }
Yorke Lee0b8d2252015-06-10 16:31:20 -0700394 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800395 prefSet.removePreference(mButtonWifiCalling);
Yorke Lee0b8d2252015-06-10 16:31:20 -0700396 }
Malcolm Chen995721f2017-12-12 18:19:27 -0800397 } else if (!mImsMgr.isWfcEnabledByPlatform() || !mImsMgr.isWfcProvisionedOnDevice()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800398 prefSet.removePreference(mButtonWifiCalling);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800399 } else {
Wenting Xiong73045392018-08-04 17:56:50 +0800400 String title = SubscriptionManager.getResourcesForSubId(mPhone.getContext(),
401 mPhone.getSubId()).getString(R.string.wifi_calling);
402 mButtonWifiCalling.setTitle(title);
403
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700404 int resId = com.android.internal.R.string.wifi_calling_off_summary;
Malcolm Chen995721f2017-12-12 18:19:27 -0800405 if (mImsMgr.isWfcEnabledByUser()) {
Youhan Wang269606e2017-01-19 15:25:55 -0800406 boolean isRoaming = telephonyManager.isNetworkRoaming();
Youming Ye482a2672019-05-07 15:27:35 -0700407 boolean wfcRoamingEnabled = editableWfcRoamingMode && !useWfcHomeModeForRoaming;
408 int wfcMode = mImsMgr.getWfcMode(isRoaming && wfcRoamingEnabled);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800409 switch (wfcMode) {
410 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700411 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800412 break;
413 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700414 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800415 break;
416 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700417 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800418 break;
419 default:
420 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
421 }
422 }
Malcolm Chen4042eb42018-02-26 15:58:44 -0800423 mButtonWifiCalling.setSummary(resId);
Brad Ebinger02c51962019-04-29 15:55:40 -0700424 Intent intent = mButtonWifiCalling.getIntent();
425 if (intent != null) {
426 intent.putExtra(Settings.EXTRA_SUB_ID, mPhone.getSubId());
427 }
Torbjorn Eklund13971a22018-11-29 15:32:13 +0100428 prefSet.addPreference(mButtonWifiCalling);
Andrew Leeb97fad82015-01-27 15:31:39 -0800429 }
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530430
431 try {
Brad Ebingera12246d2018-01-16 09:39:35 -0800432 if (mImsMgr.getImsServiceState() != ImsFeature.STATE_READY) {
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530433 log("Feature state not ready so remove vt and wfc settings for "
434 + " phone =" + mPhone.getPhoneId());
Malcolm Chen4042eb42018-02-26 15:58:44 -0800435 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530436 prefSet.removePreference(mEnableVideoCalling);
437 }
438 } catch (ImsException ex) {
439 log("Exception when trying to get ImsServiceStatus: " + ex);
Malcolm Chen4042eb42018-02-26 15:58:44 -0800440 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530441 prefSet.removePreference(mEnableVideoCalling);
442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 }
444
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800445 /**
446 * Hides the top level voicemail settings entry point if the default dialer contains a
447 * particular manifest metadata key. This is required when the default dialer wants to display
448 * its own version of voicemail settings.
449 */
450 private void maybeHideVoicemailSettings() {
451 String defaultDialer = getSystemService(TelecomManager.class).getDefaultDialerPackage();
452 if (defaultDialer == null) {
453 return;
454 }
455 try {
456 Bundle metadata = getPackageManager()
457 .getApplicationInfo(defaultDialer, PackageManager.GET_META_DATA).metaData;
Tyler Gunn8b6aa682017-04-06 16:01:59 -0700458 if (metadata == null) {
459 return;
460 }
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800461 if (!metadata
462 .getBoolean(TelephonyManager.METADATA_HIDE_VOICEMAIL_SETTINGS_MENU, false)) {
463 if (DBG) {
464 log("maybeHideVoicemailSettings(): not disabled by default dialer");
465 }
466 return;
467 }
468 getPreferenceScreen().removePreference(mVoicemailSettingsScreen);
469 if (DBG) {
470 log("maybeHideVoicemailSettings(): disabled by default dialer");
471 }
472 } catch (NameNotFoundException e) {
473 // do nothing
474 if (DBG) {
475 log("maybeHideVoicemailSettings(): not controlled by default dialer");
476 }
477 }
478 }
479
Andrew Lee785ca2a2014-12-18 12:46:41 -0800480 @Override
481 protected void onNewIntent(Intent newIntent) {
482 setIntent(newIntent);
483
484 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
485 mSubscriptionInfoHelper.setActionBarTitle(
486 getActionBar(), getResources(), R.string.call_settings_with_label);
487 mPhone = mSubscriptionInfoHelper.getPhone();
488 }
489
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490 private static void log(String msg) {
491 Log.d(LOG_TAG, msg);
492 }
493
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494 @Override
495 public boolean onOptionsItemSelected(MenuItem item) {
496 final int itemId = item.getItemId();
497 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -0700498 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700499 return true;
500 }
501 return super.onOptionsItemSelected(item);
502 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800503
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504 /**
505 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
506 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
507 */
Andrew Lee5efb1122014-12-05 04:20:42 -0800508 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800509 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
510 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511 intent.setAction(Intent.ACTION_MAIN);
512 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
513 activity.startActivity(intent);
514 activity.finish();
515 }
516}