blob: 5c744a7eb9eba8487d19aadef8d63fda72782695 [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;
Andrew Lee93c345f2014-10-27 15:25:07 -070040import android.telephony.TelephonyManager;
Malcolm Chen995721f2017-12-12 18:19:27 -080041import android.telephony.ims.feature.ImsFeature;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.util.Log;
43import android.view.MenuItem;
Jay Shraunerc2684732014-11-12 12:10:37 -080044import android.widget.Toast;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045
Andrew Leeeffef9c2015-02-19 16:02:37 -080046import com.android.ims.ImsConfig;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +053047import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070048import com.android.ims.ImsManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import com.android.internal.telephony.Phone;
50import com.android.internal.telephony.PhoneConstants;
Santos Cordon499378a2015-06-25 18:51:39 -070051import com.android.phone.settings.PhoneAccountSettingsFragment;
SongFerngWangbed485e2018-07-09 21:15:29 +080052import com.android.phone.settings.SuppServicesUiUtil;
Andrew Leebf07f762015-04-07 19:05:50 -070053import com.android.phone.settings.VoicemailSettingsActivity;
Andrew Lee5ed870c2014-10-29 11:47:49 -070054import com.android.phone.settings.fdn.FdnSetting;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import java.util.List;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057
58/**
59 * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
60 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070061 * This preference screen is the root of the "Call settings" hierarchy available from the Phone
62 * app; the settings here let you control various features related to phone calls (including
63 * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
64 * voice-capable phone devices.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065 *
66 * Note that this activity is part of the package com.android.phone, even
67 * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
68 * is from the package com.android.contacts.
69 *
70 * For the "Mobile network settings" screen under the main Settings app,
71 * See {@link MobileNetworkSettings}.
72 *
73 * @see com.android.phone.MobileNetworkSettings
74 */
75public class CallFeaturesSetting extends PreferenceActivity
Andrew Leebf07f762015-04-07 19:05:50 -070076 implements Preference.OnPreferenceChangeListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077 private static final String LOG_TAG = "CallFeaturesSetting";
78 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
79
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080 // String keys for preference lookup
81 // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
Andrew Lee8d66d812014-11-24 14:54:02 -080082 // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
83 // in the layout files. These strings need to be treated carefully; if the setting is
84 // persistent, they are used as the key to store shared preferences and the name should not be
85 // changed unless the settings are also migrated.
Andrew Lee97708a42014-09-25 12:39:07 -070086 private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087 private static final String BUTTON_FDN_KEY = "button_fdn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088 private static final String BUTTON_RETRY_KEY = "button_auto_retry_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089 private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
90 private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
91
Andrew Leece8ae2a2014-09-10 10:41:48 -070092 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
93 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -070094
Andrew Leedf14ead2014-10-17 14:22:52 -070095 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
96
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097 private Phone mPhone;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +053098 private ImsManager mImsMgr;
Andrew Lee5ed870c2014-10-29 11:47:49 -070099 private SubscriptionInfoHelper mSubscriptionInfoHelper;
Yorke Lee0b8d2252015-06-10 16:31:20 -0700100 private TelecomManager mTelecomManager;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700101
fionaxue46e69f2017-04-27 14:32:46 -0700102 private SwitchPreference mButtonAutoRetry;
Andrew Lee97708a42014-09-25 12:39:07 -0700103 private PreferenceScreen mVoicemailSettingsScreen;
fionaxue46e69f2017-04-27 14:32:46 -0700104 private SwitchPreference mEnableVideoCalling;
Malcolm Chen4042eb42018-02-26 15:58:44 -0800105 private Preference mButtonWifiCalling;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107 /*
108 * Click Listeners, handle click based on objects attached to UI.
109 */
110
111 // Click listener for all toggle events
112 @Override
113 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Andrew Leebf07f762015-04-07 19:05:50 -0700114 if (preference == mButtonAutoRetry) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
116 android.provider.Settings.Global.CALL_AUTO_RETRY,
117 mButtonAutoRetry.isChecked() ? 1 : 0);
118 return true;
SongFerngWangbed485e2018-07-09 21:15:29 +0800119 } else if (preference == preferenceScreen.findPreference(
120 GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
121 return doSsOverUtPrecautions(preference);
122 } else if (preference == preferenceScreen.findPreference(
123 GsmUmtsCallOptions.CALL_BARRING_KEY)) {
124 return doSsOverUtPrecautions(preference);
125 }
126 return false;
127 }
128
129 private boolean doSsOverUtPrecautions(Preference preference) {
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 String configKey;
139 if (preference.getKey().equals(GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
140 configKey = CarrierConfigManager.KEY_CALL_FORWARDING_OVER_UT_WARNING_BOOL;
141 } else {
142 configKey = CarrierConfigManager.KEY_CALL_BARRING_OVER_UT_WARNING_BOOL;
143 }
144 if (b != null && b.getBoolean(configKey)
145 && mPhone != null
146 && SuppServicesUiUtil.isSsOverUtPrecautions(this, mPhone)) {
147 SuppServicesUiUtil.showBlockingSuppServicesDialog(this, mPhone,
148 preference.getKey()).show();
149 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150 }
151 return false;
152 }
153
154 /**
155 * Implemented to support onPreferenceChangeListener to look for preference
156 * changes.
157 *
158 * @param preference is the preference to be changed
159 * @param objValue should be the value of the selection, NOT its localized
160 * display value.
161 */
162 @Override
163 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800164 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700165
Andrew Leebf07f762015-04-07 19:05:50 -0700166 if (preference == mEnableVideoCalling) {
Malcolm Chen995721f2017-12-12 18:19:27 -0800167 if (mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530168 mImsMgr.setVtSetting((boolean) objValue);
Andrew Lee312e8172014-10-23 17:01:36 -0700169 } else {
170 AlertDialog.Builder builder = new AlertDialog.Builder(this);
171 DialogInterface.OnClickListener networkSettingsClickListener =
172 new Dialog.OnClickListener() {
173 @Override
174 public void onClick(DialogInterface dialog, int which) {
175 startActivity(new Intent(mPhone.getContext(),
176 com.android.phone.MobileNetworkSettings.class));
177 }
178 };
179 builder.setMessage(getResources().getString(
180 R.string.enable_video_calling_dialog_msg))
181 .setNeutralButton(getResources().getString(
182 R.string.enable_video_calling_dialog_settings),
183 networkSettingsClickListener)
184 .setPositiveButton(android.R.string.ok, null)
185 .show();
186 return false;
187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800189
190 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191 return true;
192 }
193
194 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195 protected void onCreate(Bundle icicle) {
196 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800197 if (DBG) log("onCreate: Intent is " + getIntent());
198
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -0700199 // Make sure we are running as an admin user.
200 if (!UserManager.get(this).isAdminUser()) {
201 Toast.makeText(this, R.string.call_settings_admin_user_only,
Jay Shraunerc2684732014-11-12 12:10:37 -0800202 Toast.LENGTH_SHORT).show();
203 finish();
204 return;
205 }
206
Andrew Leedd4f6df2014-12-09 19:13:51 -0800207 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5ed870c2014-10-29 11:47:49 -0700208 mSubscriptionInfoHelper.setActionBarTitle(
209 getActionBar(), getResources(), R.string.call_settings_with_label);
Andrew Lee1479dd12014-11-06 23:06:32 -0800210 mPhone = mSubscriptionInfoHelper.getPhone();
Yorke Lee0b8d2252015-06-10 16:31:20 -0700211 mTelecomManager = TelecomManager.from(this);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700212 }
213
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530214 private void updateImsManager(Phone phone) {
215 log("updateImsManager :: phone.getContext()=" + phone.getContext()
216 + " phone.getPhoneId()=" + phone.getPhoneId());
217 mImsMgr = ImsManager.getInstance(phone.getContext(), phone.getPhoneId());
218 if (mImsMgr == null) {
219 log("updateImsManager :: Could not get ImsManager instance!");
220 } else {
221 log("updateImsManager :: mImsMgr=" + mImsMgr);
222 }
223 }
224
Omata Shou81a0c8a2018-07-19 18:57:02 +0900225 private void listenPhoneState(boolean listen) {
226 TelephonyManager telephonyManager =
227 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
228 telephonyManager.listen(mPhoneStateListener, listen
229 ? PhoneStateListener.LISTEN_CALL_STATE : PhoneStateListener.LISTEN_NONE);
230 }
231
pkanwarb4aef112016-07-17 15:39:30 -0700232 private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
233 @Override
234 public void onCallStateChanged(int state, String incomingNumber) {
235 if (DBG) log("PhoneStateListener onCallStateChanged: state is " + state);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900236 // Use TelecomManager#getCallStete instead of 'state' parameter because it needs
237 // to check the current state of all phone calls.
238 boolean isCallStateIdle =
239 mTelecomManager.getCallState() == TelephonyManager.CALL_STATE_IDLE;
pkanwarb4aef112016-07-17 15:39:30 -0700240 if (mEnableVideoCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530241 mEnableVideoCalling.setEnabled(isCallStateIdle);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900242 }
243 if (mButtonWifiCalling != null) {
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530244 mButtonWifiCalling.setEnabled(isCallStateIdle);
pkanwarb4aef112016-07-17 15:39:30 -0700245 }
246 }
247 };
248
249 @Override
250 protected void onPause() {
pkanwar0a663122016-07-19 12:26:44 -0700251 super.onPause();
Omata Shou81a0c8a2018-07-19 18:57:02 +0900252 listenPhoneState(false);
pkanwarb4aef112016-07-17 15:39:30 -0700253 }
254
Tyler Gunnbaee2952014-09-10 16:01:02 -0700255 @Override
256 protected void onResume() {
257 super.onResume();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700258
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530259 updateImsManager(mPhone);
Omata Shou81a0c8a2018-07-19 18:57:02 +0900260 listenPhoneState(true);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700261 PreferenceScreen preferenceScreen = getPreferenceScreen();
262 if (preferenceScreen != null) {
263 preferenceScreen.removeAll();
264 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265
266 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -0700267
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530268 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
269 .createForSubscriptionId(mPhone.getSubId());
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800270
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee2c027892014-10-29 11:29:54 -0700272 mVoicemailSettingsScreen =
273 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Leebf07f762015-04-07 19:05:50 -0700274 mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
275 VoicemailSettingsActivity.class));
Andrew Lee8d66d812014-11-24 14:54:02 -0800276
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800277 maybeHideVoicemailSettings();
278
fionaxue46e69f2017-04-27 14:32:46 -0700279 mButtonAutoRetry = (SwitchPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800280
fionaxue46e69f2017-04-27 14:32:46 -0700281 mEnableVideoCalling = (SwitchPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Malcolm Chen4042eb42018-02-26 15:58:44 -0800282 mButtonWifiCalling = findPreference(getResources().getString(
283 R.string.wifi_calling_settings_key));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700285 PersistableBundle carrierConfig =
286 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700287
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700288 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL)) {
Andrew Lee64a7d792014-10-15 17:38:38 -0700289 mButtonAutoRetry.setOnPreferenceChangeListener(this);
290 int autoretry = Settings.Global.getInt(
291 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
292 mButtonAutoRetry.setChecked(autoretry != 0);
293 } else {
294 prefSet.removePreference(mButtonAutoRetry);
295 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296 }
297
Sanket Padawee09a6f62015-03-05 11:59:39 -0800298 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
299 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
Wileen Chiu98664e52015-07-29 14:10:01 +0530300 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
301 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700302 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
Sanket Padawee09a6f62015-03-05 11:59:39 -0800303 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
304 gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
305 } else {
Andrew Lee2b36ba22014-11-05 17:08:49 -0800306 prefSet.removePreference(cdmaOptions);
Andrew Lee2b36ba22014-11-05 17:08:49 -0800307 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700308
309 int phoneType = mPhone.getPhoneType();
Junda Liua9ba9d42015-06-01 01:26:52 -0700310 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
Andrew Lee5ed870c2014-10-29 11:47:49 -0700311 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312 } else {
Junda Liua09d6962014-11-12 13:39:02 -0800313 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
314 prefSet.removePreference(fdnButton);
315
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700316 if (!carrierConfig.getBoolean(
Jonathan Basseri38c58552015-06-09 15:14:06 -0700317 CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800318 addPreferencesFromResource(R.xml.cdma_call_privacy);
319 }
320 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Xiangyu/Malcolm Chen2f810e82018-03-29 18:56:16 +0000321 if (mPhone.getIccCard() == null || !mPhone.getIccCard().getIccFdnAvailable()) {
322 prefSet.removePreference(fdnButton);
323 }
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700324 if (carrierConfig.getBoolean(
325 CarrierConfigManager.KEY_ADDITIONAL_CALL_SETTING_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800326 addPreferencesFromResource(R.xml.gsm_umts_call_options);
Sanket Padawee09a6f62015-03-05 11:59:39 -0800327 GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
Junda Liua09d6962014-11-12 13:39:02 -0800328 }
329 } else {
330 throw new IllegalStateException("Unexpected phone type: " + phoneType);
331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 }
333 }
334
Malcolm Chen995721f2017-12-12 18:19:27 -0800335 if (mImsMgr.isVtEnabledByPlatform() && mImsMgr.isVtProvisionedOnDevice()
336 && (carrierConfig.getBoolean(
Jack Yub7628322016-11-28 11:10:18 -0800337 CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS)
Malcolm Chen995721f2017-12-12 18:19:27 -0800338 || mPhone.mDcTracker.isDataEnabled())) {
Andrew Lee312e8172014-10-23 17:01:36 -0700339 boolean currentValue =
Malcolm Chen995721f2017-12-12 18:19:27 -0800340 mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()
Suresh Koleti7963bfe2018-03-08 17:57:53 +0530341 ? mImsMgr.isVtEnabledByUser() : false;
Andrew Lee312e8172014-10-23 17:01:36 -0700342 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -0700343 mEnableVideoCalling.setOnPreferenceChangeListener(this);
344 } else {
345 prefSet.removePreference(mEnableVideoCalling);
346 }
Etan Cohena51d4ef2014-12-15 10:44:42 -0800347
Yorke Lee0b8d2252015-06-10 16:31:20 -0700348 final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManager();
Santos Cordon499378a2015-06-25 18:51:39 -0700349 if (simCallManager != null) {
350 Intent intent = PhoneAccountSettingsFragment.buildPhoneAccountConfigureIntent(
351 this, simCallManager);
352 if (intent != null) {
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700353 PackageManager pm = mPhone.getContext().getPackageManager();
354 List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
355 if (!resolutions.isEmpty()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800356 mButtonWifiCalling.setTitle(resolutions.get(0).loadLabel(pm));
357 mButtonWifiCalling.setSummary(null);
358 mButtonWifiCalling.setIntent(intent);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700359 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800360 prefSet.removePreference(mButtonWifiCalling);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700361 }
Yorke Lee0b8d2252015-06-10 16:31:20 -0700362 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800363 prefSet.removePreference(mButtonWifiCalling);
Yorke Lee0b8d2252015-06-10 16:31:20 -0700364 }
Malcolm Chen995721f2017-12-12 18:19:27 -0800365 } else if (!mImsMgr.isWfcEnabledByPlatform() || !mImsMgr.isWfcProvisionedOnDevice()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800366 prefSet.removePreference(mButtonWifiCalling);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800367 } else {
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700368 int resId = com.android.internal.R.string.wifi_calling_off_summary;
Malcolm Chen995721f2017-12-12 18:19:27 -0800369 if (mImsMgr.isWfcEnabledByUser()) {
Youhan Wang269606e2017-01-19 15:25:55 -0800370 boolean isRoaming = telephonyManager.isNetworkRoaming();
Malcolm Chen995721f2017-12-12 18:19:27 -0800371 int wfcMode = mImsMgr.getWfcMode(isRoaming);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800372 switch (wfcMode) {
373 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700374 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800375 break;
376 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700377 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800378 break;
379 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700380 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800381 break;
382 default:
383 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
384 }
385 }
Malcolm Chen4042eb42018-02-26 15:58:44 -0800386 mButtonWifiCalling.setSummary(resId);
Andrew Leeb97fad82015-01-27 15:31:39 -0800387 }
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530388
389 try {
Brad Ebingera12246d2018-01-16 09:39:35 -0800390 if (mImsMgr.getImsServiceState() != ImsFeature.STATE_READY) {
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530391 log("Feature state not ready so remove vt and wfc settings for "
392 + " phone =" + mPhone.getPhoneId());
Malcolm Chen4042eb42018-02-26 15:58:44 -0800393 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530394 prefSet.removePreference(mEnableVideoCalling);
395 }
396 } catch (ImsException ex) {
397 log("Exception when trying to get ImsServiceStatus: " + ex);
Malcolm Chen4042eb42018-02-26 15:58:44 -0800398 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530399 prefSet.removePreference(mEnableVideoCalling);
400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 }
402
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800403 /**
404 * Hides the top level voicemail settings entry point if the default dialer contains a
405 * particular manifest metadata key. This is required when the default dialer wants to display
406 * its own version of voicemail settings.
407 */
408 private void maybeHideVoicemailSettings() {
409 String defaultDialer = getSystemService(TelecomManager.class).getDefaultDialerPackage();
410 if (defaultDialer == null) {
411 return;
412 }
413 try {
414 Bundle metadata = getPackageManager()
415 .getApplicationInfo(defaultDialer, PackageManager.GET_META_DATA).metaData;
Tyler Gunn8b6aa682017-04-06 16:01:59 -0700416 if (metadata == null) {
417 return;
418 }
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800419 if (!metadata
420 .getBoolean(TelephonyManager.METADATA_HIDE_VOICEMAIL_SETTINGS_MENU, false)) {
421 if (DBG) {
422 log("maybeHideVoicemailSettings(): not disabled by default dialer");
423 }
424 return;
425 }
426 getPreferenceScreen().removePreference(mVoicemailSettingsScreen);
427 if (DBG) {
428 log("maybeHideVoicemailSettings(): disabled by default dialer");
429 }
430 } catch (NameNotFoundException e) {
431 // do nothing
432 if (DBG) {
433 log("maybeHideVoicemailSettings(): not controlled by default dialer");
434 }
435 }
436 }
437
Andrew Lee785ca2a2014-12-18 12:46:41 -0800438 @Override
439 protected void onNewIntent(Intent newIntent) {
440 setIntent(newIntent);
441
442 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
443 mSubscriptionInfoHelper.setActionBarTitle(
444 getActionBar(), getResources(), R.string.call_settings_with_label);
445 mPhone = mSubscriptionInfoHelper.getPhone();
446 }
447
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 private static void log(String msg) {
449 Log.d(LOG_TAG, msg);
450 }
451
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452 @Override
453 public boolean onOptionsItemSelected(MenuItem item) {
454 final int itemId = item.getItemId();
455 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -0700456 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 return true;
458 }
459 return super.onOptionsItemSelected(item);
460 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800461
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700462 /**
463 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
464 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
465 */
Andrew Lee5efb1122014-12-05 04:20:42 -0800466 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800467 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
468 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 intent.setAction(Intent.ACTION_MAIN);
470 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
471 activity.startActivity(intent);
472 activity.finish();
473 }
474}