blob: 8386c34604182fa53790bc09d025115868d5f962 [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;
pkanwarb4aef112016-07-17 15:39:30 -070045import android.telephony.PhoneStateListener;
Andrew Lee93c345f2014-10-27 15:25:07 -070046import android.telephony.TelephonyManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.text.TextUtils;
48import android.util.Log;
49import android.view.MenuItem;
Jay Shraunerc2684732014-11-12 12:10:37 -080050import android.widget.Toast;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051
Andrew Leeeffef9c2015-02-19 16:02:37 -080052import com.android.ims.ImsConfig;
Andrew Lee312e8172014-10-23 17:01:36 -070053import com.android.ims.ImsManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import com.android.internal.telephony.CallForwardInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import com.android.internal.telephony.Phone;
56import com.android.internal.telephony.PhoneConstants;
Andrew Lee2170a972014-08-13 18:13:01 -070057import com.android.phone.common.util.SettingsUtil;
Andrew Leedb2fe562014-09-03 15:40:43 -070058import com.android.phone.settings.AccountSelectionPreference;
Santos Cordon499378a2015-06-25 18:51:39 -070059import com.android.phone.settings.PhoneAccountSettingsFragment;
Andrew Leebf07f762015-04-07 19:05:50 -070060import com.android.phone.settings.VoicemailSettingsActivity;
Andrew Lee5ed870c2014-10-29 11:47:49 -070061import com.android.phone.settings.fdn.FdnSetting;
Sailesh Nepal788959e2014-07-08 23:36:40 -070062import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063
Andrew Lee2170a972014-08-13 18:13:01 -070064import java.lang.String;
Andrew Leef1776d82014-11-04 14:45:02 -080065import java.util.ArrayList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import java.util.List;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067
68/**
69 * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
70 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070071 * This preference screen is the root of the "Call settings" hierarchy available from the Phone
72 * app; the settings here let you control various features related to phone calls (including
73 * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
74 * voice-capable phone devices.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075 *
76 * Note that this activity is part of the package com.android.phone, even
77 * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
78 * is from the package com.android.contacts.
79 *
80 * For the "Mobile network settings" screen under the main Settings app,
81 * See {@link MobileNetworkSettings}.
82 *
83 * @see com.android.phone.MobileNetworkSettings
84 */
85public class CallFeaturesSetting extends PreferenceActivity
Andrew Leebf07f762015-04-07 19:05:50 -070086 implements Preference.OnPreferenceChangeListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087 private static final String LOG_TAG = "CallFeaturesSetting";
88 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
89
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090 // String keys for preference lookup
91 // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
Andrew Lee8d66d812014-11-24 14:54:02 -080092 // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
93 // in the layout files. These strings need to be treated carefully; if the setting is
94 // persistent, they are used as the key to store shared preferences and the name should not be
95 // changed unless the settings are also migrated.
Andrew Lee97708a42014-09-25 12:39:07 -070096 private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097 private static final String BUTTON_FDN_KEY = "button_fdn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098 private static final String BUTTON_RETRY_KEY = "button_auto_retry_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099 private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
100 private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
101
Andrew Leece8ae2a2014-09-10 10:41:48 -0700102 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
103 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -0700104
Andrew Leedf14ead2014-10-17 14:22:52 -0700105 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
106
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107 private Phone mPhone;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700108 private SubscriptionInfoHelper mSubscriptionInfoHelper;
Yorke Lee0b8d2252015-06-10 16:31:20 -0700109 private TelecomManager mTelecomManager;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700110
fionaxue46e69f2017-04-27 14:32:46 -0700111 private SwitchPreference mButtonAutoRetry;
Andrew Lee97708a42014-09-25 12:39:07 -0700112 private PreferenceScreen mVoicemailSettingsScreen;
fionaxue46e69f2017-04-27 14:32:46 -0700113 private SwitchPreference mEnableVideoCalling;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115 /*
116 * Click Listeners, handle click based on objects attached to UI.
117 */
118
119 // Click listener for all toggle events
120 @Override
121 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Andrew Leebf07f762015-04-07 19:05:50 -0700122 if (preference == mButtonAutoRetry) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
124 android.provider.Settings.Global.CALL_AUTO_RETRY,
125 mButtonAutoRetry.isChecked() ? 1 : 0);
126 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127 }
128 return false;
129 }
130
131 /**
132 * Implemented to support onPreferenceChangeListener to look for preference
133 * changes.
134 *
135 * @param preference is the preference to be changed
136 * @param objValue should be the value of the selection, NOT its localized
137 * display value.
138 */
139 @Override
140 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800141 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700142
Andrew Leebf07f762015-04-07 19:05:50 -0700143 if (preference == mEnableVideoCalling) {
Andrew Lee312e8172014-10-23 17:01:36 -0700144 if (ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())) {
145 PhoneGlobals.getInstance().phoneMgr.enableVideoCalling((boolean) objValue);
146 } else {
147 AlertDialog.Builder builder = new AlertDialog.Builder(this);
148 DialogInterface.OnClickListener networkSettingsClickListener =
149 new Dialog.OnClickListener() {
150 @Override
151 public void onClick(DialogInterface dialog, int which) {
152 startActivity(new Intent(mPhone.getContext(),
153 com.android.phone.MobileNetworkSettings.class));
154 }
155 };
156 builder.setMessage(getResources().getString(
157 R.string.enable_video_calling_dialog_msg))
158 .setNeutralButton(getResources().getString(
159 R.string.enable_video_calling_dialog_settings),
160 networkSettingsClickListener)
161 .setPositiveButton(android.R.string.ok, null)
162 .show();
163 return false;
164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800166
167 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168 return true;
169 }
170
171 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172 protected void onCreate(Bundle icicle) {
173 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800174 if (DBG) log("onCreate: Intent is " + getIntent());
175
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -0700176 // Make sure we are running as an admin user.
177 if (!UserManager.get(this).isAdminUser()) {
178 Toast.makeText(this, R.string.call_settings_admin_user_only,
Jay Shraunerc2684732014-11-12 12:10:37 -0800179 Toast.LENGTH_SHORT).show();
180 finish();
181 return;
182 }
183
Andrew Leedd4f6df2014-12-09 19:13:51 -0800184 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5ed870c2014-10-29 11:47:49 -0700185 mSubscriptionInfoHelper.setActionBarTitle(
186 getActionBar(), getResources(), R.string.call_settings_with_label);
Andrew Lee1479dd12014-11-06 23:06:32 -0800187 mPhone = mSubscriptionInfoHelper.getPhone();
Yorke Lee0b8d2252015-06-10 16:31:20 -0700188 mTelecomManager = TelecomManager.from(this);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700189 }
190
pkanwarb4aef112016-07-17 15:39:30 -0700191 private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
192 @Override
193 public void onCallStateChanged(int state, String incomingNumber) {
194 if (DBG) log("PhoneStateListener onCallStateChanged: state is " + state);
195 if (mEnableVideoCalling != null) {
196 mEnableVideoCalling.setEnabled(state == TelephonyManager.CALL_STATE_IDLE);
197 }
198 }
199 };
200
201 @Override
202 protected void onPause() {
pkanwar0a663122016-07-19 12:26:44 -0700203 super.onPause();
pkanwarb4aef112016-07-17 15:39:30 -0700204 TelephonyManager telephonyManager =
205 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
206 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
207 }
208
Tyler Gunnbaee2952014-09-10 16:01:02 -0700209 @Override
210 protected void onResume() {
211 super.onResume();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700212
213 PreferenceScreen preferenceScreen = getPreferenceScreen();
214 if (preferenceScreen != null) {
215 preferenceScreen.removeAll();
216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217
218 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -0700219
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800220 TelephonyManager telephonyManager =
221 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
pkanwarb4aef112016-07-17 15:39:30 -0700222 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800223
224 Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
Santos Cordonc9c48432015-06-12 17:01:21 -0700225 if (telephonyManager.isMultiSimEnabled() || !SipUtil.isVoipSupported(mPhone.getContext())) {
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800226 getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
227 }
Andrew Leedb2fe562014-09-03 15:40:43 -0700228
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee2c027892014-10-29 11:29:54 -0700230 mVoicemailSettingsScreen =
231 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Leebf07f762015-04-07 19:05:50 -0700232 mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
233 VoicemailSettingsActivity.class));
Andrew Lee8d66d812014-11-24 14:54:02 -0800234
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800235 maybeHideVoicemailSettings();
236
fionaxue46e69f2017-04-27 14:32:46 -0700237 mButtonAutoRetry = (SwitchPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800238
fionaxue46e69f2017-04-27 14:32:46 -0700239 mEnableVideoCalling = (SwitchPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700241 PersistableBundle carrierConfig =
242 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700243
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700244 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL)) {
Andrew Lee64a7d792014-10-15 17:38:38 -0700245 mButtonAutoRetry.setOnPreferenceChangeListener(this);
246 int autoretry = Settings.Global.getInt(
247 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
248 mButtonAutoRetry.setChecked(autoretry != 0);
249 } else {
250 prefSet.removePreference(mButtonAutoRetry);
251 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252 }
253
Sanket Padawee09a6f62015-03-05 11:59:39 -0800254 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
255 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
Wileen Chiu98664e52015-07-29 14:10:01 +0530256 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
257 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700258 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
Sanket Padawee09a6f62015-03-05 11:59:39 -0800259 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
260 gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
261 } else {
Andrew Lee2b36ba22014-11-05 17:08:49 -0800262 prefSet.removePreference(cdmaOptions);
Andrew Lee2b36ba22014-11-05 17:08:49 -0800263 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700264
265 int phoneType = mPhone.getPhoneType();
Junda Liua9ba9d42015-06-01 01:26:52 -0700266 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
Andrew Lee5ed870c2014-10-29 11:47:49 -0700267 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268 } else {
Junda Liua09d6962014-11-12 13:39:02 -0800269 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
270 prefSet.removePreference(fdnButton);
271
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700272 if (!carrierConfig.getBoolean(
Jonathan Basseri38c58552015-06-09 15:14:06 -0700273 CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800274 addPreferencesFromResource(R.xml.cdma_call_privacy);
275 }
276 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Junda Liua09d6962014-11-12 13:39:02 -0800277
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700278 if (carrierConfig.getBoolean(
279 CarrierConfigManager.KEY_ADDITIONAL_CALL_SETTING_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800280 addPreferencesFromResource(R.xml.gsm_umts_call_options);
Sanket Padawee09a6f62015-03-05 11:59:39 -0800281 GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
Junda Liua09d6962014-11-12 13:39:02 -0800282 }
283 } else {
284 throw new IllegalStateException("Unexpected phone type: " + phoneType);
285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286 }
287 }
288
Jack Yu75ab2952016-07-08 14:29:33 -0700289 if (ImsManager.isVtEnabledByPlatform(mPhone.getContext()) &&
Amit Mahajan26b5b8e2016-07-21 14:41:38 -0700290 ImsManager.isVtProvisionedOnDevice(mPhone.getContext()) &&
Jack Yub7628322016-11-28 11:10:18 -0800291 (carrierConfig.getBoolean(
292 CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS)
Jack Yu14d2ec72017-04-11 10:39:53 -0700293 || mPhone.mDcTracker.isDataEnabled())) {
Andrew Lee312e8172014-10-23 17:01:36 -0700294 boolean currentValue =
295 ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Svet Ganovb320e182015-04-16 12:30:10 -0700296 ? PhoneGlobals.getInstance().phoneMgr.isVideoCallingEnabled(
297 getOpPackageName()) : false;
Andrew Lee312e8172014-10-23 17:01:36 -0700298 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -0700299 mEnableVideoCalling.setOnPreferenceChangeListener(this);
300 } else {
301 prefSet.removePreference(mEnableVideoCalling);
302 }
Etan Cohena51d4ef2014-12-15 10:44:42 -0800303
304 if (ImsManager.isVolteEnabledByPlatform(this) &&
Junda Liu08a208a2015-06-23 15:06:00 -0700305 !carrierConfig.getBoolean(
306 CarrierConfigManager.KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL)) {
Etan Cohena51d4ef2014-12-15 10:44:42 -0800307 TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Vinit Deshpande84cccac2015-03-16 00:08:19 -0700308 /* tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); */
Etan Cohena51d4ef2014-12-15 10:44:42 -0800309 }
Andrew Leeb97fad82015-01-27 15:31:39 -0800310
Andrew Leeeffef9c2015-02-19 16:02:37 -0800311 Preference wifiCallingSettings = findPreference(
312 getResources().getString(R.string.wifi_calling_settings_key));
Yorke Lee0b8d2252015-06-10 16:31:20 -0700313
314 final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManager();
Santos Cordon499378a2015-06-25 18:51:39 -0700315 if (simCallManager != null) {
316 Intent intent = PhoneAccountSettingsFragment.buildPhoneAccountConfigureIntent(
317 this, simCallManager);
318 if (intent != null) {
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700319 PackageManager pm = mPhone.getContext().getPackageManager();
320 List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
321 if (!resolutions.isEmpty()) {
322 wifiCallingSettings.setTitle(resolutions.get(0).loadLabel(pm));
323 wifiCallingSettings.setSummary(null);
324 wifiCallingSettings.setIntent(intent);
325 } else {
326 prefSet.removePreference(wifiCallingSettings);
327 }
Yorke Lee0b8d2252015-06-10 16:31:20 -0700328 } else {
329 prefSet.removePreference(wifiCallingSettings);
330 }
Pavel Zhamaitsiak87c43792016-06-20 14:06:02 -0700331 } else if (!ImsManager.isWfcEnabledByPlatform(mPhone.getContext()) ||
332 !ImsManager.isWfcProvisionedOnDevice(mPhone.getContext())) {
Andrew Leeb97fad82015-01-27 15:31:39 -0800333 prefSet.removePreference(wifiCallingSettings);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800334 } else {
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700335 int resId = com.android.internal.R.string.wifi_calling_off_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800336 if (ImsManager.isWfcEnabledByUser(mPhone.getContext())) {
Youhan Wang269606e2017-01-19 15:25:55 -0800337 boolean isRoaming = telephonyManager.isNetworkRoaming();
338 int wfcMode = ImsManager.getWfcMode(mPhone.getContext(), isRoaming);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800339 switch (wfcMode) {
340 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700341 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800342 break;
343 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700344 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800345 break;
346 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700347 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800348 break;
349 default:
350 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
351 }
352 }
353 wifiCallingSettings.setSummary(resId);
Andrew Leeb97fad82015-01-27 15:31:39 -0800354 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 }
356
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800357 /**
358 * Hides the top level voicemail settings entry point if the default dialer contains a
359 * particular manifest metadata key. This is required when the default dialer wants to display
360 * its own version of voicemail settings.
361 */
362 private void maybeHideVoicemailSettings() {
363 String defaultDialer = getSystemService(TelecomManager.class).getDefaultDialerPackage();
364 if (defaultDialer == null) {
365 return;
366 }
367 try {
368 Bundle metadata = getPackageManager()
369 .getApplicationInfo(defaultDialer, PackageManager.GET_META_DATA).metaData;
Tyler Gunn8b6aa682017-04-06 16:01:59 -0700370 if (metadata == null) {
371 return;
372 }
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800373 if (!metadata
374 .getBoolean(TelephonyManager.METADATA_HIDE_VOICEMAIL_SETTINGS_MENU, false)) {
375 if (DBG) {
376 log("maybeHideVoicemailSettings(): not disabled by default dialer");
377 }
378 return;
379 }
380 getPreferenceScreen().removePreference(mVoicemailSettingsScreen);
381 if (DBG) {
382 log("maybeHideVoicemailSettings(): disabled by default dialer");
383 }
384 } catch (NameNotFoundException e) {
385 // do nothing
386 if (DBG) {
387 log("maybeHideVoicemailSettings(): not controlled by default dialer");
388 }
389 }
390 }
391
Andrew Lee785ca2a2014-12-18 12:46:41 -0800392 @Override
393 protected void onNewIntent(Intent newIntent) {
394 setIntent(newIntent);
395
396 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
397 mSubscriptionInfoHelper.setActionBarTitle(
398 getActionBar(), getResources(), R.string.call_settings_with_label);
399 mPhone = mSubscriptionInfoHelper.getPhone();
400 }
401
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402 private static void log(String msg) {
403 Log.d(LOG_TAG, msg);
404 }
405
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 @Override
407 public boolean onOptionsItemSelected(MenuItem item) {
408 final int itemId = item.getItemId();
409 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -0700410 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411 return true;
412 }
413 return super.onOptionsItemSelected(item);
414 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800415
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 /**
417 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
418 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
419 */
Andrew Lee5efb1122014-12-05 04:20:42 -0800420 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800421 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
422 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 intent.setAction(Intent.ACTION_MAIN);
424 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
425 activity.startActivity(intent);
426 activity.finish();
427 }
428}