blob: e5527bc7d44eec9c3d214599225dee314200589b [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
19import android.app.ActionBar;
20import android.app.Activity;
Evan Charlton1c696832014-04-15 14:24:23 -070021import android.app.ActivityOptions;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AlertDialog;
23import android.app.Dialog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.content.ContentResolver;
25import android.content.Context;
26import android.content.DialogInterface;
27import android.content.Intent;
Ta-wei Yenb8e770c2017-01-24 17:49:58 -080028import android.content.pm.ApplicationInfo;
Yorke Lee0b8d2252015-06-10 16:31:20 -070029import android.content.pm.PackageManager;
Ta-wei Yenb8e770c2017-01-24 17:49:58 -080030import android.content.pm.PackageManager.NameNotFoundException;
Yorke Lee0b8d2252015-06-10 16:31:20 -070031import android.content.pm.ResolveInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.os.Bundle;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070033import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.os.UserHandle;
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -070035import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.preference.ListPreference;
37import android.preference.Preference;
38import android.preference.PreferenceActivity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.preference.PreferenceScreen;
fionaxue46e69f2017-04-27 14:32:46 -070040import android.preference.SwitchPreference;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.provider.Settings;
Tyler Gunn4d45d1c2014-09-12 22:17:53 -070042import android.telecom.PhoneAccountHandle;
43import android.telecom.TelecomManager;
Jonathan Basseri4b40ff42015-04-30 21:54:10 -070044import android.telephony.CarrierConfigManager;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +053045import android.telephony.ims.feature.ImsFeature;
pkanwarb4aef112016-07-17 15:39:30 -070046import android.telephony.PhoneStateListener;
Andrew Lee93c345f2014-10-27 15:25:07 -070047import android.telephony.TelephonyManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.text.TextUtils;
49import android.util.Log;
50import android.view.MenuItem;
Jay Shraunerc2684732014-11-12 12:10:37 -080051import android.widget.Toast;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052
Andrew Leeeffef9c2015-02-19 16:02:37 -080053import com.android.ims.ImsConfig;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +053054import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070055import com.android.ims.ImsManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import com.android.internal.telephony.CallForwardInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import com.android.internal.telephony.Phone;
58import com.android.internal.telephony.PhoneConstants;
Andrew Lee2170a972014-08-13 18:13:01 -070059import com.android.phone.common.util.SettingsUtil;
Andrew Leedb2fe562014-09-03 15:40:43 -070060import com.android.phone.settings.AccountSelectionPreference;
Santos Cordon499378a2015-06-25 18:51:39 -070061import com.android.phone.settings.PhoneAccountSettingsFragment;
Andrew Leebf07f762015-04-07 19:05:50 -070062import com.android.phone.settings.VoicemailSettingsActivity;
Andrew Lee5ed870c2014-10-29 11:47:49 -070063import com.android.phone.settings.fdn.FdnSetting;
Sailesh Nepal788959e2014-07-08 23:36:40 -070064import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065
Andrew Lee2170a972014-08-13 18:13:01 -070066import java.lang.String;
Andrew Leef1776d82014-11-04 14:45:02 -080067import java.util.ArrayList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import java.util.List;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069
70/**
71 * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
72 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070073 * This preference screen is the root of the "Call settings" hierarchy available from the Phone
74 * app; the settings here let you control various features related to phone calls (including
75 * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
76 * voice-capable phone devices.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077 *
78 * Note that this activity is part of the package com.android.phone, even
79 * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
80 * is from the package com.android.contacts.
81 *
82 * For the "Mobile network settings" screen under the main Settings app,
83 * See {@link MobileNetworkSettings}.
84 *
85 * @see com.android.phone.MobileNetworkSettings
86 */
87public class CallFeaturesSetting extends PreferenceActivity
Andrew Leebf07f762015-04-07 19:05:50 -070088 implements Preference.OnPreferenceChangeListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089 private static final String LOG_TAG = "CallFeaturesSetting";
90 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
91
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092 // String keys for preference lookup
93 // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
Andrew Lee8d66d812014-11-24 14:54:02 -080094 // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
95 // in the layout files. These strings need to be treated carefully; if the setting is
96 // persistent, they are used as the key to store shared preferences and the name should not be
97 // changed unless the settings are also migrated.
Andrew Lee97708a42014-09-25 12:39:07 -070098 private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099 private static final String BUTTON_FDN_KEY = "button_fdn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100 private static final String BUTTON_RETRY_KEY = "button_auto_retry_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700101 private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
102 private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
103
Andrew Leece8ae2a2014-09-10 10:41:48 -0700104 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
105 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -0700106
Andrew Leedf14ead2014-10-17 14:22:52 -0700107 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
108
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109 private Phone mPhone;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530110 private ImsManager mImsMgr;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700111 private SubscriptionInfoHelper mSubscriptionInfoHelper;
Yorke Lee0b8d2252015-06-10 16:31:20 -0700112 private TelecomManager mTelecomManager;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700113
fionaxue46e69f2017-04-27 14:32:46 -0700114 private SwitchPreference mButtonAutoRetry;
Andrew Lee97708a42014-09-25 12:39:07 -0700115 private PreferenceScreen mVoicemailSettingsScreen;
fionaxue46e69f2017-04-27 14:32:46 -0700116 private SwitchPreference mEnableVideoCalling;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118 /*
119 * Click Listeners, handle click based on objects attached to UI.
120 */
121
122 // Click listener for all toggle events
123 @Override
124 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Andrew Leebf07f762015-04-07 19:05:50 -0700125 if (preference == mButtonAutoRetry) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
127 android.provider.Settings.Global.CALL_AUTO_RETRY,
128 mButtonAutoRetry.isChecked() ? 1 : 0);
129 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130 }
131 return false;
132 }
133
134 /**
135 * Implemented to support onPreferenceChangeListener to look for preference
136 * changes.
137 *
138 * @param preference is the preference to be changed
139 * @param objValue should be the value of the selection, NOT its localized
140 * display value.
141 */
142 @Override
143 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800144 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700145
Andrew Leebf07f762015-04-07 19:05:50 -0700146 if (preference == mEnableVideoCalling) {
Andrew Lee312e8172014-10-23 17:01:36 -0700147 if (ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())) {
148 PhoneGlobals.getInstance().phoneMgr.enableVideoCalling((boolean) objValue);
149 } else {
150 AlertDialog.Builder builder = new AlertDialog.Builder(this);
151 DialogInterface.OnClickListener networkSettingsClickListener =
152 new Dialog.OnClickListener() {
153 @Override
154 public void onClick(DialogInterface dialog, int which) {
155 startActivity(new Intent(mPhone.getContext(),
156 com.android.phone.MobileNetworkSettings.class));
157 }
158 };
159 builder.setMessage(getResources().getString(
160 R.string.enable_video_calling_dialog_msg))
161 .setNeutralButton(getResources().getString(
162 R.string.enable_video_calling_dialog_settings),
163 networkSettingsClickListener)
164 .setPositiveButton(android.R.string.ok, null)
165 .show();
166 return false;
167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800169
170 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171 return true;
172 }
173
174 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175 protected void onCreate(Bundle icicle) {
176 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800177 if (DBG) log("onCreate: Intent is " + getIntent());
178
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -0700179 // Make sure we are running as an admin user.
180 if (!UserManager.get(this).isAdminUser()) {
181 Toast.makeText(this, R.string.call_settings_admin_user_only,
Jay Shraunerc2684732014-11-12 12:10:37 -0800182 Toast.LENGTH_SHORT).show();
183 finish();
184 return;
185 }
186
Andrew Leedd4f6df2014-12-09 19:13:51 -0800187 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5ed870c2014-10-29 11:47:49 -0700188 mSubscriptionInfoHelper.setActionBarTitle(
189 getActionBar(), getResources(), R.string.call_settings_with_label);
Andrew Lee1479dd12014-11-06 23:06:32 -0800190 mPhone = mSubscriptionInfoHelper.getPhone();
Yorke Lee0b8d2252015-06-10 16:31:20 -0700191 mTelecomManager = TelecomManager.from(this);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700192 }
193
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530194 private void updateImsManager(Phone phone) {
195 log("updateImsManager :: phone.getContext()=" + phone.getContext()
196 + " phone.getPhoneId()=" + phone.getPhoneId());
197 mImsMgr = ImsManager.getInstance(phone.getContext(), phone.getPhoneId());
198 if (mImsMgr == null) {
199 log("updateImsManager :: Could not get ImsManager instance!");
200 } else {
201 log("updateImsManager :: mImsMgr=" + mImsMgr);
202 }
203 }
204
pkanwarb4aef112016-07-17 15:39:30 -0700205 private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
206 @Override
207 public void onCallStateChanged(int state, String incomingNumber) {
208 if (DBG) log("PhoneStateListener onCallStateChanged: state is " + state);
209 if (mEnableVideoCalling != null) {
210 mEnableVideoCalling.setEnabled(state == TelephonyManager.CALL_STATE_IDLE);
211 }
212 }
213 };
214
215 @Override
216 protected void onPause() {
pkanwar0a663122016-07-19 12:26:44 -0700217 super.onPause();
pkanwarb4aef112016-07-17 15:39:30 -0700218 TelephonyManager telephonyManager =
219 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
220 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
221 }
222
Tyler Gunnbaee2952014-09-10 16:01:02 -0700223 @Override
224 protected void onResume() {
225 super.onResume();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700226
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530227 updateImsManager(mPhone);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700228 PreferenceScreen preferenceScreen = getPreferenceScreen();
229 if (preferenceScreen != null) {
230 preferenceScreen.removeAll();
231 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232
233 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -0700234
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800235 TelephonyManager telephonyManager =
236 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
pkanwarb4aef112016-07-17 15:39:30 -0700237 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800238
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee2c027892014-10-29 11:29:54 -0700240 mVoicemailSettingsScreen =
241 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Leebf07f762015-04-07 19:05:50 -0700242 mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
243 VoicemailSettingsActivity.class));
Andrew Lee8d66d812014-11-24 14:54:02 -0800244
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800245 maybeHideVoicemailSettings();
246
fionaxue46e69f2017-04-27 14:32:46 -0700247 mButtonAutoRetry = (SwitchPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800248
fionaxue46e69f2017-04-27 14:32:46 -0700249 mEnableVideoCalling = (SwitchPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700251 PersistableBundle carrierConfig =
252 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700253
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700254 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL)) {
Andrew Lee64a7d792014-10-15 17:38:38 -0700255 mButtonAutoRetry.setOnPreferenceChangeListener(this);
256 int autoretry = Settings.Global.getInt(
257 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
258 mButtonAutoRetry.setChecked(autoretry != 0);
259 } else {
260 prefSet.removePreference(mButtonAutoRetry);
261 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262 }
263
Sanket Padawee09a6f62015-03-05 11:59:39 -0800264 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
265 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
Wileen Chiu98664e52015-07-29 14:10:01 +0530266 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
267 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700268 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
Sanket Padawee09a6f62015-03-05 11:59:39 -0800269 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
270 gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
271 } else {
Andrew Lee2b36ba22014-11-05 17:08:49 -0800272 prefSet.removePreference(cdmaOptions);
Andrew Lee2b36ba22014-11-05 17:08:49 -0800273 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274
275 int phoneType = mPhone.getPhoneType();
Junda Liua9ba9d42015-06-01 01:26:52 -0700276 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
Andrew Lee5ed870c2014-10-29 11:47:49 -0700277 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278 } else {
Junda Liua09d6962014-11-12 13:39:02 -0800279 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
280 prefSet.removePreference(fdnButton);
281
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700282 if (!carrierConfig.getBoolean(
Jonathan Basseri38c58552015-06-09 15:14:06 -0700283 CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800284 addPreferencesFromResource(R.xml.cdma_call_privacy);
285 }
286 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Junda Liua09d6962014-11-12 13:39:02 -0800287
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700288 if (carrierConfig.getBoolean(
289 CarrierConfigManager.KEY_ADDITIONAL_CALL_SETTING_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800290 addPreferencesFromResource(R.xml.gsm_umts_call_options);
Sanket Padawee09a6f62015-03-05 11:59:39 -0800291 GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
Junda Liua09d6962014-11-12 13:39:02 -0800292 }
293 } else {
294 throw new IllegalStateException("Unexpected phone type: " + phoneType);
295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296 }
297 }
298
Jack Yu75ab2952016-07-08 14:29:33 -0700299 if (ImsManager.isVtEnabledByPlatform(mPhone.getContext()) &&
Amit Mahajan26b5b8e2016-07-21 14:41:38 -0700300 ImsManager.isVtProvisionedOnDevice(mPhone.getContext()) &&
Jack Yub7628322016-11-28 11:10:18 -0800301 (carrierConfig.getBoolean(
302 CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS)
Jack Yu14d2ec72017-04-11 10:39:53 -0700303 || mPhone.mDcTracker.isDataEnabled())) {
Andrew Lee312e8172014-10-23 17:01:36 -0700304 boolean currentValue =
305 ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Svet Ganovb320e182015-04-16 12:30:10 -0700306 ? PhoneGlobals.getInstance().phoneMgr.isVideoCallingEnabled(
307 getOpPackageName()) : false;
Andrew Lee312e8172014-10-23 17:01:36 -0700308 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -0700309 mEnableVideoCalling.setOnPreferenceChangeListener(this);
310 } else {
311 prefSet.removePreference(mEnableVideoCalling);
312 }
Etan Cohena51d4ef2014-12-15 10:44:42 -0800313
314 if (ImsManager.isVolteEnabledByPlatform(this) &&
Junda Liu08a208a2015-06-23 15:06:00 -0700315 !carrierConfig.getBoolean(
316 CarrierConfigManager.KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL)) {
Etan Cohena51d4ef2014-12-15 10:44:42 -0800317 TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Vinit Deshpande84cccac2015-03-16 00:08:19 -0700318 /* tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); */
Etan Cohena51d4ef2014-12-15 10:44:42 -0800319 }
Andrew Leeb97fad82015-01-27 15:31:39 -0800320
Andrew Leeeffef9c2015-02-19 16:02:37 -0800321 Preference wifiCallingSettings = findPreference(
322 getResources().getString(R.string.wifi_calling_settings_key));
Yorke Lee0b8d2252015-06-10 16:31:20 -0700323
324 final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManager();
Santos Cordon499378a2015-06-25 18:51:39 -0700325 if (simCallManager != null) {
326 Intent intent = PhoneAccountSettingsFragment.buildPhoneAccountConfigureIntent(
327 this, simCallManager);
328 if (intent != null) {
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700329 PackageManager pm = mPhone.getContext().getPackageManager();
330 List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
331 if (!resolutions.isEmpty()) {
332 wifiCallingSettings.setTitle(resolutions.get(0).loadLabel(pm));
333 wifiCallingSettings.setSummary(null);
334 wifiCallingSettings.setIntent(intent);
335 } else {
336 prefSet.removePreference(wifiCallingSettings);
337 }
Yorke Lee0b8d2252015-06-10 16:31:20 -0700338 } else {
339 prefSet.removePreference(wifiCallingSettings);
340 }
Pavel Zhamaitsiak87c43792016-06-20 14:06:02 -0700341 } else if (!ImsManager.isWfcEnabledByPlatform(mPhone.getContext()) ||
342 !ImsManager.isWfcProvisionedOnDevice(mPhone.getContext())) {
Andrew Leeb97fad82015-01-27 15:31:39 -0800343 prefSet.removePreference(wifiCallingSettings);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800344 } else {
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700345 int resId = com.android.internal.R.string.wifi_calling_off_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800346 if (ImsManager.isWfcEnabledByUser(mPhone.getContext())) {
Youhan Wang269606e2017-01-19 15:25:55 -0800347 boolean isRoaming = telephonyManager.isNetworkRoaming();
348 int wfcMode = ImsManager.getWfcMode(mPhone.getContext(), isRoaming);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800349 switch (wfcMode) {
350 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700351 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800352 break;
353 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700354 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800355 break;
356 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700357 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800358 break;
359 default:
360 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
361 }
362 }
363 wifiCallingSettings.setSummary(resId);
Andrew Leeb97fad82015-01-27 15:31:39 -0800364 }
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530365
366 try {
367 if (mImsMgr.getImsServiceStatus() != ImsFeature.STATE_READY) {
368 log("Feature state not ready so remove vt and wfc settings for "
369 + " phone =" + mPhone.getPhoneId());
370 prefSet.removePreference(wifiCallingSettings);
371 prefSet.removePreference(mEnableVideoCalling);
372 }
373 } catch (ImsException ex) {
374 log("Exception when trying to get ImsServiceStatus: " + ex);
375 prefSet.removePreference(wifiCallingSettings);
376 prefSet.removePreference(mEnableVideoCalling);
377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 }
379
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800380 /**
381 * Hides the top level voicemail settings entry point if the default dialer contains a
382 * particular manifest metadata key. This is required when the default dialer wants to display
383 * its own version of voicemail settings.
384 */
385 private void maybeHideVoicemailSettings() {
386 String defaultDialer = getSystemService(TelecomManager.class).getDefaultDialerPackage();
387 if (defaultDialer == null) {
388 return;
389 }
390 try {
391 Bundle metadata = getPackageManager()
392 .getApplicationInfo(defaultDialer, PackageManager.GET_META_DATA).metaData;
Tyler Gunn8b6aa682017-04-06 16:01:59 -0700393 if (metadata == null) {
394 return;
395 }
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800396 if (!metadata
397 .getBoolean(TelephonyManager.METADATA_HIDE_VOICEMAIL_SETTINGS_MENU, false)) {
398 if (DBG) {
399 log("maybeHideVoicemailSettings(): not disabled by default dialer");
400 }
401 return;
402 }
403 getPreferenceScreen().removePreference(mVoicemailSettingsScreen);
404 if (DBG) {
405 log("maybeHideVoicemailSettings(): disabled by default dialer");
406 }
407 } catch (NameNotFoundException e) {
408 // do nothing
409 if (DBG) {
410 log("maybeHideVoicemailSettings(): not controlled by default dialer");
411 }
412 }
413 }
414
Andrew Lee785ca2a2014-12-18 12:46:41 -0800415 @Override
416 protected void onNewIntent(Intent newIntent) {
417 setIntent(newIntent);
418
419 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
420 mSubscriptionInfoHelper.setActionBarTitle(
421 getActionBar(), getResources(), R.string.call_settings_with_label);
422 mPhone = mSubscriptionInfoHelper.getPhone();
423 }
424
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 private static void log(String msg) {
426 Log.d(LOG_TAG, msg);
427 }
428
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 @Override
430 public boolean onOptionsItemSelected(MenuItem item) {
431 final int itemId = item.getItemId();
432 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -0700433 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 return true;
435 }
436 return super.onOptionsItemSelected(item);
437 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800438
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 /**
440 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
441 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
442 */
Andrew Lee5efb1122014-12-05 04:20:42 -0800443 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800444 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
445 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 intent.setAction(Intent.ACTION_MAIN);
447 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
448 activity.startActivity(intent);
449 activity.finish();
450 }
451}