blob: fd8558539b69f044b4cc339abb0f5a8942709f61 [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;
Andrew Leebf07f762015-04-07 19:05:50 -070052import com.android.phone.settings.VoicemailSettingsActivity;
Andrew Lee5ed870c2014-10-29 11:47:49 -070053import com.android.phone.settings.fdn.FdnSetting;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import java.util.List;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056
57/**
58 * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
59 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070060 * This preference screen is the root of the "Call settings" hierarchy available from the Phone
61 * app; the settings here let you control various features related to phone calls (including
62 * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
63 * voice-capable phone devices.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064 *
65 * Note that this activity is part of the package com.android.phone, even
66 * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
67 * is from the package com.android.contacts.
68 *
69 * For the "Mobile network settings" screen under the main Settings app,
70 * See {@link MobileNetworkSettings}.
71 *
72 * @see com.android.phone.MobileNetworkSettings
73 */
74public class CallFeaturesSetting extends PreferenceActivity
Andrew Leebf07f762015-04-07 19:05:50 -070075 implements Preference.OnPreferenceChangeListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076 private static final String LOG_TAG = "CallFeaturesSetting";
77 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
78
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079 // String keys for preference lookup
80 // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
Andrew Lee8d66d812014-11-24 14:54:02 -080081 // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
82 // in the layout files. These strings need to be treated carefully; if the setting is
83 // persistent, they are used as the key to store shared preferences and the name should not be
84 // changed unless the settings are also migrated.
Andrew Lee97708a42014-09-25 12:39:07 -070085 private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086 private static final String BUTTON_FDN_KEY = "button_fdn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087 private static final String BUTTON_RETRY_KEY = "button_auto_retry_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088 private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
89 private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
90
Andrew Leece8ae2a2014-09-10 10:41:48 -070091 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
92 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -070093
Andrew Leedf14ead2014-10-17 14:22:52 -070094 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
95
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096 private Phone mPhone;
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +053097 private ImsManager mImsMgr;
Andrew Lee5ed870c2014-10-29 11:47:49 -070098 private SubscriptionInfoHelper mSubscriptionInfoHelper;
Yorke Lee0b8d2252015-06-10 16:31:20 -070099 private TelecomManager mTelecomManager;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700100
fionaxue46e69f2017-04-27 14:32:46 -0700101 private SwitchPreference mButtonAutoRetry;
Andrew Lee97708a42014-09-25 12:39:07 -0700102 private PreferenceScreen mVoicemailSettingsScreen;
fionaxue46e69f2017-04-27 14:32:46 -0700103 private SwitchPreference mEnableVideoCalling;
Malcolm Chen4042eb42018-02-26 15:58:44 -0800104 private Preference mButtonWifiCalling;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106 /*
107 * Click Listeners, handle click based on objects attached to UI.
108 */
109
110 // Click listener for all toggle events
111 @Override
112 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Andrew Leebf07f762015-04-07 19:05:50 -0700113 if (preference == mButtonAutoRetry) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
115 android.provider.Settings.Global.CALL_AUTO_RETRY,
116 mButtonAutoRetry.isChecked() ? 1 : 0);
117 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118 }
119 return false;
120 }
121
122 /**
123 * Implemented to support onPreferenceChangeListener to look for preference
124 * changes.
125 *
126 * @param preference is the preference to be changed
127 * @param objValue should be the value of the selection, NOT its localized
128 * display value.
129 */
130 @Override
131 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800132 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700133
Andrew Leebf07f762015-04-07 19:05:50 -0700134 if (preference == mEnableVideoCalling) {
Malcolm Chen995721f2017-12-12 18:19:27 -0800135 if (mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()) {
Andrew Lee312e8172014-10-23 17:01:36 -0700136 PhoneGlobals.getInstance().phoneMgr.enableVideoCalling((boolean) objValue);
137 } else {
138 AlertDialog.Builder builder = new AlertDialog.Builder(this);
139 DialogInterface.OnClickListener networkSettingsClickListener =
140 new Dialog.OnClickListener() {
141 @Override
142 public void onClick(DialogInterface dialog, int which) {
143 startActivity(new Intent(mPhone.getContext(),
144 com.android.phone.MobileNetworkSettings.class));
145 }
146 };
147 builder.setMessage(getResources().getString(
148 R.string.enable_video_calling_dialog_msg))
149 .setNeutralButton(getResources().getString(
150 R.string.enable_video_calling_dialog_settings),
151 networkSettingsClickListener)
152 .setPositiveButton(android.R.string.ok, null)
153 .show();
154 return false;
155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800157
158 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159 return true;
160 }
161
162 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163 protected void onCreate(Bundle icicle) {
164 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800165 if (DBG) log("onCreate: Intent is " + getIntent());
166
Xiaohui Chen9dc2bea2015-10-14 11:42:04 -0700167 // Make sure we are running as an admin user.
168 if (!UserManager.get(this).isAdminUser()) {
169 Toast.makeText(this, R.string.call_settings_admin_user_only,
Jay Shraunerc2684732014-11-12 12:10:37 -0800170 Toast.LENGTH_SHORT).show();
171 finish();
172 return;
173 }
174
Andrew Leedd4f6df2014-12-09 19:13:51 -0800175 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5ed870c2014-10-29 11:47:49 -0700176 mSubscriptionInfoHelper.setActionBarTitle(
177 getActionBar(), getResources(), R.string.call_settings_with_label);
Andrew Lee1479dd12014-11-06 23:06:32 -0800178 mPhone = mSubscriptionInfoHelper.getPhone();
Yorke Lee0b8d2252015-06-10 16:31:20 -0700179 mTelecomManager = TelecomManager.from(this);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700180 }
181
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530182 private void updateImsManager(Phone phone) {
183 log("updateImsManager :: phone.getContext()=" + phone.getContext()
184 + " phone.getPhoneId()=" + phone.getPhoneId());
185 mImsMgr = ImsManager.getInstance(phone.getContext(), phone.getPhoneId());
186 if (mImsMgr == null) {
187 log("updateImsManager :: Could not get ImsManager instance!");
188 } else {
189 log("updateImsManager :: mImsMgr=" + mImsMgr);
190 }
191 }
192
pkanwarb4aef112016-07-17 15:39:30 -0700193 private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
194 @Override
195 public void onCallStateChanged(int state, String incomingNumber) {
196 if (DBG) log("PhoneStateListener onCallStateChanged: state is " + state);
197 if (mEnableVideoCalling != null) {
Minoru Sakuma7a2643b2017-08-25 20:46:34 +0900198 // Use TelephonyManager#getCallStete instead of 'state' parameter because it needs
199 // to check the current state of all phone calls.
200 TelephonyManager telephonyManager =
201 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
202 mEnableVideoCalling.setEnabled(
203 telephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE);
Malcolm Chen4042eb42018-02-26 15:58:44 -0800204 mButtonWifiCalling.setEnabled(
205 telephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE);
pkanwarb4aef112016-07-17 15:39:30 -0700206 }
207 }
208 };
209
210 @Override
211 protected void onPause() {
pkanwar0a663122016-07-19 12:26:44 -0700212 super.onPause();
pkanwarb4aef112016-07-17 15:39:30 -0700213 TelephonyManager telephonyManager =
214 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
215 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
216 }
217
Tyler Gunnbaee2952014-09-10 16:01:02 -0700218 @Override
219 protected void onResume() {
220 super.onResume();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700221
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530222 updateImsManager(mPhone);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700223 PreferenceScreen preferenceScreen = getPreferenceScreen();
224 if (preferenceScreen != null) {
225 preferenceScreen.removeAll();
226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227
228 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -0700229
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800230 TelephonyManager telephonyManager =
231 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
pkanwarb4aef112016-07-17 15:39:30 -0700232 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800233
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee2c027892014-10-29 11:29:54 -0700235 mVoicemailSettingsScreen =
236 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Leebf07f762015-04-07 19:05:50 -0700237 mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
238 VoicemailSettingsActivity.class));
Andrew Lee8d66d812014-11-24 14:54:02 -0800239
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800240 maybeHideVoicemailSettings();
241
fionaxue46e69f2017-04-27 14:32:46 -0700242 mButtonAutoRetry = (SwitchPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800243
fionaxue46e69f2017-04-27 14:32:46 -0700244 mEnableVideoCalling = (SwitchPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Malcolm Chen4042eb42018-02-26 15:58:44 -0800245 mButtonWifiCalling = findPreference(getResources().getString(
246 R.string.wifi_calling_settings_key));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700248 PersistableBundle carrierConfig =
249 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700250
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700251 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL)) {
Andrew Lee64a7d792014-10-15 17:38:38 -0700252 mButtonAutoRetry.setOnPreferenceChangeListener(this);
253 int autoretry = Settings.Global.getInt(
254 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
255 mButtonAutoRetry.setChecked(autoretry != 0);
256 } else {
257 prefSet.removePreference(mButtonAutoRetry);
258 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700259 }
260
Sanket Padawee09a6f62015-03-05 11:59:39 -0800261 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
262 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
Wileen Chiu98664e52015-07-29 14:10:01 +0530263 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
264 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700265 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
Sanket Padawee09a6f62015-03-05 11:59:39 -0800266 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
267 gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
268 } else {
Andrew Lee2b36ba22014-11-05 17:08:49 -0800269 prefSet.removePreference(cdmaOptions);
Andrew Lee2b36ba22014-11-05 17:08:49 -0800270 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271
272 int phoneType = mPhone.getPhoneType();
Junda Liua9ba9d42015-06-01 01:26:52 -0700273 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
Andrew Lee5ed870c2014-10-29 11:47:49 -0700274 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 } else {
Junda Liua09d6962014-11-12 13:39:02 -0800276 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
277 prefSet.removePreference(fdnButton);
278
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700279 if (!carrierConfig.getBoolean(
Jonathan Basseri38c58552015-06-09 15:14:06 -0700280 CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800281 addPreferencesFromResource(R.xml.cdma_call_privacy);
282 }
283 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Xiangyu/Malcolm Chen2f810e82018-03-29 18:56:16 +0000284 if (mPhone.getIccCard() == null || !mPhone.getIccCard().getIccFdnAvailable()) {
285 prefSet.removePreference(fdnButton);
286 }
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700287 if (carrierConfig.getBoolean(
288 CarrierConfigManager.KEY_ADDITIONAL_CALL_SETTING_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800289 addPreferencesFromResource(R.xml.gsm_umts_call_options);
Sanket Padawee09a6f62015-03-05 11:59:39 -0800290 GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
Junda Liua09d6962014-11-12 13:39:02 -0800291 }
292 } else {
293 throw new IllegalStateException("Unexpected phone type: " + phoneType);
294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 }
296 }
297
Malcolm Chen995721f2017-12-12 18:19:27 -0800298 if (mImsMgr.isVtEnabledByPlatform() && mImsMgr.isVtProvisionedOnDevice()
299 && (carrierConfig.getBoolean(
Jack Yub7628322016-11-28 11:10:18 -0800300 CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS)
Malcolm Chen995721f2017-12-12 18:19:27 -0800301 || mPhone.mDcTracker.isDataEnabled())) {
Andrew Lee312e8172014-10-23 17:01:36 -0700302 boolean currentValue =
Malcolm Chen995721f2017-12-12 18:19:27 -0800303 mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()
Svet Ganovb320e182015-04-16 12:30:10 -0700304 ? PhoneGlobals.getInstance().phoneMgr.isVideoCallingEnabled(
305 getOpPackageName()) : false;
Andrew Lee312e8172014-10-23 17:01:36 -0700306 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -0700307 mEnableVideoCalling.setOnPreferenceChangeListener(this);
308 } else {
309 prefSet.removePreference(mEnableVideoCalling);
310 }
Etan Cohena51d4ef2014-12-15 10:44:42 -0800311
Malcolm Chen995721f2017-12-12 18:19:27 -0800312 if (mImsMgr.isVolteEnabledByPlatform()
313 && !carrierConfig.getBoolean(
Junda Liu08a208a2015-06-23 15:06:00 -0700314 CarrierConfigManager.KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL)) {
Etan Cohena51d4ef2014-12-15 10:44:42 -0800315 TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Vinit Deshpande84cccac2015-03-16 00:08:19 -0700316 /* tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); */
Etan Cohena51d4ef2014-12-15 10:44:42 -0800317 }
Andrew Leeb97fad82015-01-27 15:31:39 -0800318
Yorke Lee0b8d2252015-06-10 16:31:20 -0700319 final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManager();
Santos Cordon499378a2015-06-25 18:51:39 -0700320 if (simCallManager != null) {
321 Intent intent = PhoneAccountSettingsFragment.buildPhoneAccountConfigureIntent(
322 this, simCallManager);
323 if (intent != null) {
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700324 PackageManager pm = mPhone.getContext().getPackageManager();
325 List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
326 if (!resolutions.isEmpty()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800327 mButtonWifiCalling.setTitle(resolutions.get(0).loadLabel(pm));
328 mButtonWifiCalling.setSummary(null);
329 mButtonWifiCalling.setIntent(intent);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700330 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800331 prefSet.removePreference(mButtonWifiCalling);
Abhishek Guptaa134adb2016-04-14 18:57:31 -0700332 }
Yorke Lee0b8d2252015-06-10 16:31:20 -0700333 } else {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800334 prefSet.removePreference(mButtonWifiCalling);
Yorke Lee0b8d2252015-06-10 16:31:20 -0700335 }
Malcolm Chen995721f2017-12-12 18:19:27 -0800336 } else if (!mImsMgr.isWfcEnabledByPlatform() || !mImsMgr.isWfcProvisionedOnDevice()) {
Malcolm Chen4042eb42018-02-26 15:58:44 -0800337 prefSet.removePreference(mButtonWifiCalling);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800338 } else {
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700339 int resId = com.android.internal.R.string.wifi_calling_off_summary;
Malcolm Chen995721f2017-12-12 18:19:27 -0800340 if (mImsMgr.isWfcEnabledByUser()) {
Youhan Wang269606e2017-01-19 15:25:55 -0800341 boolean isRoaming = telephonyManager.isNetworkRoaming();
Malcolm Chen995721f2017-12-12 18:19:27 -0800342 int wfcMode = mImsMgr.getWfcMode(isRoaming);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800343 switch (wfcMode) {
344 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700345 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800346 break;
347 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700348 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800349 break;
350 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700351 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800352 break;
353 default:
354 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
355 }
356 }
Malcolm Chen4042eb42018-02-26 15:58:44 -0800357 mButtonWifiCalling.setSummary(resId);
Andrew Leeb97fad82015-01-27 15:31:39 -0800358 }
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530359
360 try {
Brad Ebingera12246d2018-01-16 09:39:35 -0800361 if (mImsMgr.getImsServiceState() != ImsFeature.STATE_READY) {
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530362 log("Feature state not ready so remove vt and wfc settings for "
363 + " phone =" + mPhone.getPhoneId());
Malcolm Chen4042eb42018-02-26 15:58:44 -0800364 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530365 prefSet.removePreference(mEnableVideoCalling);
366 }
367 } catch (ImsException ex) {
368 log("Exception when trying to get ImsServiceStatus: " + ex);
Malcolm Chen4042eb42018-02-26 15:58:44 -0800369 prefSet.removePreference(mButtonWifiCalling);
Benergy Meenan Ravuri57f18992017-07-20 18:03:33 +0530370 prefSet.removePreference(mEnableVideoCalling);
371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 }
373
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800374 /**
375 * Hides the top level voicemail settings entry point if the default dialer contains a
376 * particular manifest metadata key. This is required when the default dialer wants to display
377 * its own version of voicemail settings.
378 */
379 private void maybeHideVoicemailSettings() {
380 String defaultDialer = getSystemService(TelecomManager.class).getDefaultDialerPackage();
381 if (defaultDialer == null) {
382 return;
383 }
384 try {
385 Bundle metadata = getPackageManager()
386 .getApplicationInfo(defaultDialer, PackageManager.GET_META_DATA).metaData;
Tyler Gunn8b6aa682017-04-06 16:01:59 -0700387 if (metadata == null) {
388 return;
389 }
Ta-wei Yenb8e770c2017-01-24 17:49:58 -0800390 if (!metadata
391 .getBoolean(TelephonyManager.METADATA_HIDE_VOICEMAIL_SETTINGS_MENU, false)) {
392 if (DBG) {
393 log("maybeHideVoicemailSettings(): not disabled by default dialer");
394 }
395 return;
396 }
397 getPreferenceScreen().removePreference(mVoicemailSettingsScreen);
398 if (DBG) {
399 log("maybeHideVoicemailSettings(): disabled by default dialer");
400 }
401 } catch (NameNotFoundException e) {
402 // do nothing
403 if (DBG) {
404 log("maybeHideVoicemailSettings(): not controlled by default dialer");
405 }
406 }
407 }
408
Andrew Lee785ca2a2014-12-18 12:46:41 -0800409 @Override
410 protected void onNewIntent(Intent newIntent) {
411 setIntent(newIntent);
412
413 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
414 mSubscriptionInfoHelper.setActionBarTitle(
415 getActionBar(), getResources(), R.string.call_settings_with_label);
416 mPhone = mSubscriptionInfoHelper.getPhone();
417 }
418
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700419 private static void log(String msg) {
420 Log.d(LOG_TAG, msg);
421 }
422
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 @Override
424 public boolean onOptionsItemSelected(MenuItem item) {
425 final int itemId = item.getItemId();
426 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -0700427 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428 return true;
429 }
430 return super.onOptionsItemSelected(item);
431 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800432
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 /**
434 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
435 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
436 */
Andrew Lee5efb1122014-12-05 04:20:42 -0800437 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800438 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
439 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440 intent.setAction(Intent.ACTION_MAIN);
441 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
442 activity.startActivity(intent);
443 activity.finish();
444 }
445}