• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.phone;
18 
19 import android.app.Activity;
20 import android.app.AlertDialog;
21 import android.app.Dialog;
22 import android.content.BroadcastReceiver;
23 import android.content.ComponentName;
24 import android.content.Context;
25 import android.content.DialogInterface;
26 import android.content.Intent;
27 import android.content.IntentFilter;
28 import android.content.pm.PackageManager;
29 import android.content.pm.PackageManager.NameNotFoundException;
30 import android.content.pm.ResolveInfo;
31 import android.content.res.Resources;
32 import android.os.Bundle;
33 import android.os.Handler;
34 import android.os.HandlerExecutor;
35 import android.os.Looper;
36 import android.os.PersistableBundle;
37 import android.os.UserManager;
38 import android.preference.Preference;
39 import android.preference.PreferenceActivity;
40 import android.preference.PreferenceScreen;
41 import android.preference.SwitchPreference;
42 import android.provider.Settings;
43 import android.telecom.PhoneAccountHandle;
44 import android.telecom.TelecomManager;
45 import android.telephony.CarrierConfigManager;
46 import android.telephony.SubscriptionManager;
47 import android.telephony.TelephonyCallback;
48 import android.telephony.TelephonyManager;
49 import android.telephony.ims.ProvisioningManager;
50 import android.telephony.ims.feature.ImsFeature;
51 import android.util.Log;
52 import android.view.MenuItem;
53 import android.widget.Toast;
54 
55 import com.android.ims.ImsConfig;
56 import com.android.ims.ImsException;
57 import com.android.ims.ImsManager;
58 import com.android.internal.telephony.Phone;
59 import com.android.internal.telephony.PhoneConstants;
60 import com.android.phone.settings.PhoneAccountSettingsFragment;
61 import com.android.phone.settings.SuppServicesUiUtil;
62 import com.android.phone.settings.VoicemailSettingsActivity;
63 import com.android.phone.settings.fdn.FdnSetting;
64 
65 import java.util.List;
66 
67 /**
68  * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
69  *
70  * This preference screen is the root of the "Call settings" hierarchy available from the Phone
71  * app; the settings here let you control various features related to phone calls (including
72  * voicemail settings, the "Respond via SMS" feature, and others.)  It's used only on
73  * voice-capable phone devices.
74  *
75  * Note that this activity is part of the package com.android.phone, even
76  * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
77  * is from the package com.android.contacts.
78  *
79  * For the "Mobile network settings" screen under the main Settings app,
80  * See {@link com.android.settings.network.telephony.MobileNetworkActivity}.
81  */
82 public class CallFeaturesSetting extends PreferenceActivity
83         implements Preference.OnPreferenceChangeListener {
84     private static final String LOG_TAG = "CallFeaturesSetting";
85     private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
86 
87     // String keys for preference lookup
88     // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
89     // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
90     // in the layout files. These strings need to be treated carefully; if the setting is
91     // persistent, they are used as the key to store shared preferences and the name should not be
92     // changed unless the settings are also migrated.
93     private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
94     private static final String BUTTON_FDN_KEY   = "button_fdn_key";
95     private static final String BUTTON_RETRY_KEY       = "button_auto_retry_key";
96     private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
97     private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
98 
99     private static final String PHONE_ACCOUNT_SETTINGS_KEY =
100             "phone_account_settings_preference_screen";
101 
102     private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
103     private static final String BUTTON_VP_KEY = "button_voice_privacy_key";
104 
105     private Phone mPhone;
106     private ImsManager mImsMgr;
107     private SubscriptionInfoHelper mSubscriptionInfoHelper;
108     private TelecomManager mTelecomManager;
109     private TelephonyCallback mTelephonyCallback;
110 
111     private SwitchPreference mButtonAutoRetry;
112     private PreferenceScreen mVoicemailSettingsScreen;
113     private SwitchPreference mEnableVideoCalling;
114     private Preference mButtonWifiCalling;
115 
116     /*
117      * Click Listeners, handle click based on objects attached to UI.
118      */
119 
120     private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
121         @Override
122         public void onReceive(Context context, Intent intent) {
123             log("onReceive: " + intent.getAction());
124 
125             if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) {
126                 log("ACTION_AIRPLANE_MODE_CHANGED");
127 
128                 boolean isAirplaneModeOn = intent.getBooleanExtra("state", false);
129                 handleAirplaneModeChange(isAirplaneModeOn);
130             }
131         }
132     };
133 
handleAirplaneModeChange(boolean isAirplaneModeOn)134     private void handleAirplaneModeChange(boolean isAirplaneModeOn) {
135         PersistableBundle b = null;
136         if (mSubscriptionInfoHelper.hasSubId()) {
137             b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
138                     mSubscriptionInfoHelper.getSubId());
139         } else {
140             b = PhoneGlobals.getInstance().getCarrierConfig();
141         }
142 
143         if (b != null && b.getBoolean(
144                 CarrierConfigManager.KEY_DISABLE_SUPPLEMENTARY_SERVICES_IN_AIRPLANE_MODE_BOOL)) {
145             PreferenceScreen preferenceScreen = getPreferenceScreen();
146             Preference callForwarding = preferenceScreen.findPreference(
147                     GsmUmtsCallOptions.CALL_FORWARDING_KEY);
148             Preference callBarring = preferenceScreen.findPreference(
149                     GsmUmtsCallOptions.CALL_BARRING_KEY);
150             Preference additional = preferenceScreen.findPreference(
151                     GsmUmtsCallOptions.ADDITIONAL_GSM_SETTINGS_KEY);
152             if (callForwarding != null) {
153                 callForwarding.setEnabled(!isAirplaneModeOn);
154             }
155             if (callBarring != null) {
156                 callBarring.setEnabled(!isAirplaneModeOn);
157             }
158             if (additional != null) {
159                 additional.setEnabled(!isAirplaneModeOn);
160             }
161         }
162     }
163 
164     // Click listener for all toggle events
165     @Override
onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)166     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
167         if (preference == mButtonAutoRetry) {
168             android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
169                     android.provider.Settings.Global.CALL_AUTO_RETRY,
170                     mButtonAutoRetry.isChecked() ? 1 : 0);
171             return true;
172         } else if (preference == preferenceScreen.findPreference(
173                 GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
174             return doSsOverUtPrecautions(preference);
175         } else if (preference == preferenceScreen.findPreference(
176                 GsmUmtsCallOptions.CALL_BARRING_KEY)) {
177             return doSsOverUtPrecautions(preference);
178         }
179         return false;
180     }
181 
doSsOverUtPrecautions(Preference preference)182     private boolean doSsOverUtPrecautions(Preference preference) {
183         PersistableBundle b = null;
184         if (mSubscriptionInfoHelper.hasSubId()) {
185             b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
186                     mSubscriptionInfoHelper.getSubId());
187         } else {
188             b = PhoneGlobals.getInstance().getCarrierConfig();
189         }
190 
191         String configKey;
192         if (preference.getKey().equals(GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
193             configKey = CarrierConfigManager.KEY_CALL_FORWARDING_OVER_UT_WARNING_BOOL;
194         } else {
195             configKey = CarrierConfigManager.KEY_CALL_BARRING_OVER_UT_WARNING_BOOL;
196         }
197         if (b != null && b.getBoolean(configKey)
198                 && mPhone != null
199                 && SuppServicesUiUtil.isSsOverUtPrecautions(this, mPhone)) {
200             SuppServicesUiUtil.showBlockingSuppServicesDialog(this, mPhone,
201                     preference.getKey()).show();
202             return true;
203         }
204         return false;
205     }
206 
207     /**
208      * Implemented to support onPreferenceChangeListener to look for preference
209      * changes.
210      *
211      * @param preference is the preference to be changed
212      * @param objValue should be the value of the selection, NOT its localized
213      * display value.
214      */
215     @Override
onPreferenceChange(Preference preference, Object objValue)216     public boolean onPreferenceChange(Preference preference, Object objValue) {
217         if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
218 
219         if (preference == mEnableVideoCalling) {
220             if (mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()) {
221                 mImsMgr.setVtSetting((boolean) objValue);
222             } else {
223                 AlertDialog.Builder builder = new AlertDialog.Builder(this);
224                 DialogInterface.OnClickListener networkSettingsClickListener =
225                         new Dialog.OnClickListener() {
226                             @Override
227                             public void onClick(DialogInterface dialog, int which) {
228                                 Intent intent = new Intent(Intent.ACTION_MAIN);
229                                 ComponentName mobileNetworkSettingsComponent = new ComponentName(
230                                         getString(R.string.mobile_network_settings_package),
231                                         getString(R.string.mobile_network_settings_class));
232                                 intent.setComponent(mobileNetworkSettingsComponent);
233                                 startActivity(intent);
234                             }
235                         };
236                 builder.setMessage(getResourcesForSubId().getString(
237                                 R.string.enable_video_calling_dialog_msg))
238                         .setNeutralButton(getResourcesForSubId().getString(
239                                 R.string.enable_video_calling_dialog_settings),
240                                 networkSettingsClickListener)
241                         .setPositiveButton(android.R.string.ok, null)
242                         .show();
243                 return false;
244             }
245         }
246 
247         // Always let the preference setting proceed.
248         return true;
249     }
250 
251     @Override
onCreate(Bundle icicle)252     protected void onCreate(Bundle icicle) {
253         super.onCreate(icicle);
254         if (DBG) log("onCreate: Intent is " + getIntent());
255 
256         // Make sure we are running as an admin user.
257         UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
258         if (!userManager.isAdminUser()) {
259             Toast.makeText(this, R.string.call_settings_admin_user_only,
260                     Toast.LENGTH_SHORT).show();
261             finish();
262             return;
263         }
264 
265         mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
266         mPhone = mSubscriptionInfoHelper.getPhone();
267         mSubscriptionInfoHelper.setActionBarTitle(
268                 getActionBar(), getResourcesForSubId(), R.string.call_settings_with_label);
269         mTelecomManager = getSystemService(TelecomManager.class);
270         mTelephonyCallback = new CallFeaturesTelephonyCallback();
271     }
272 
updateImsManager(Phone phone)273     private void updateImsManager(Phone phone) {
274         log("updateImsManager :: phone.getContext()=" + phone.getContext()
275                 + " phone.getPhoneId()=" + phone.getPhoneId());
276         mImsMgr = ImsManager.getInstance(phone.getContext(), phone.getPhoneId());
277         if (mImsMgr == null) {
278             log("updateImsManager :: Could not get ImsManager instance!");
279         } else {
280             log("updateImsManager :: mImsMgr=" + mImsMgr);
281         }
282     }
283 
listenPhoneState(boolean listen)284     private void listenPhoneState(boolean listen) {
285         TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
286                 .createForSubscriptionId(mPhone.getSubId());
287         if (listen) {
288             telephonyManager.registerTelephonyCallback(
289                     new HandlerExecutor(new Handler(Looper.getMainLooper())), mTelephonyCallback);
290         } else {
291             telephonyManager.unregisterTelephonyCallback(mTelephonyCallback);
292         }
293     }
294 
295     private final class CallFeaturesTelephonyCallback extends TelephonyCallback implements
296             TelephonyCallback.CallStateListener {
297         @Override
onCallStateChanged(int state)298         public void onCallStateChanged(int state) {
299             if (DBG) log("PhoneStateListener onCallStateChanged: state is " + state);
300             boolean isCallStateIdle = state == TelephonyManager.CALL_STATE_IDLE;
301             if (mEnableVideoCalling != null) {
302                 mEnableVideoCalling.setEnabled(isCallStateIdle);
303             }
304             if (mButtonWifiCalling != null) {
305                 mButtonWifiCalling.setEnabled(isCallStateIdle);
306             }
307         }
308     }
309 
310     private final ProvisioningManager.Callback mProvisioningCallback =
311             new ProvisioningManager.Callback() {
312         @Override
313         public void onProvisioningIntChanged(int item, int value) {
314             if (item == ImsConfig.ConfigConstants.VOICE_OVER_WIFI_SETTING_ENABLED
315                     || item == ImsConfig.ConfigConstants.VLT_SETTING_ENABLED
316                     || item == ImsConfig.ConfigConstants.LVC_SETTING_ENABLED) {
317                 updateVtWfc();
318             }
319         }
320     };
321 
322     @Override
onPause()323     protected void onPause() {
324         super.onPause();
325         listenPhoneState(false);
326         unregisterReceiver(mReceiver);
327 
328         // Remove callback for provisioning changes.
329         try {
330             if (mImsMgr != null) {
331                 mImsMgr.getConfigInterface().removeConfigCallback(
332                         mProvisioningCallback.getBinder());
333             }
334         } catch (ImsException e) {
335             Log.w(LOG_TAG, "onPause: Unable to remove callback for provisioning changes");
336         }
337     }
338 
339     @Override
onResume()340     protected void onResume() {
341         super.onResume();
342 
343         updateImsManager(mPhone);
344         listenPhoneState(true);
345         PreferenceScreen preferenceScreen = getPreferenceScreen();
346         if (preferenceScreen != null) {
347             preferenceScreen.removeAll();
348         }
349 
350         addPreferencesFromResource(R.xml.call_feature_setting);
351 
352         TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
353                 .createForSubscriptionId(mPhone.getSubId());
354 
355         // Note: The PhoneAccountSettingsActivity accessible via the
356         // android.telecom.action.CHANGE_PHONE_ACCOUNTS intent is accessible directly from
357         // the AOSP Dialer settings page on multi-sim devices.
358         // Where a device does NOT make the PhoneAccountSettingsActivity directly accessible from
359         // its Dialer app, this check must be modified in the device's AOSP branch to ensure that
360         // the PhoneAccountSettingsActivity is always accessible.
361         if (telephonyManager.isMultiSimEnabled()) {
362             Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
363             getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
364         }
365 
366         PreferenceScreen prefSet = getPreferenceScreen();
367         mVoicemailSettingsScreen =
368                 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
369         mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
370                 VoicemailSettingsActivity.class));
371 
372         maybeHideVoicemailSettings();
373 
374         mButtonAutoRetry = (SwitchPreference) findPreference(BUTTON_RETRY_KEY);
375 
376         mEnableVideoCalling = (SwitchPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
377         mButtonWifiCalling = findPreference(getResourcesForSubId().getString(
378                 R.string.wifi_calling_settings_key));
379 
380         PersistableBundle carrierConfig =
381                 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
382 
383         if (carrierConfig.getBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL)) {
384             mButtonAutoRetry.setOnPreferenceChangeListener(this);
385             int autoretry = Settings.Global.getInt(
386                     getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
387             mButtonAutoRetry.setChecked(autoretry != 0);
388         } else {
389             prefSet.removePreference(mButtonAutoRetry);
390             mButtonAutoRetry = null;
391         }
392 
393         Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
394         Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
395         Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
396         fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
397         if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
398             cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
399             gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
400         } else {
401             // Remove GSM options and repopulate the preferences in this Activity if phone type is
402             // GSM.
403             prefSet.removePreference(gsmOptions);
404 
405             int phoneType = mPhone.getPhoneType();
406             if (carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
407                 prefSet.removePreference(fdnButton);
408             } else {
409                 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
410                     // For now, just keep CdmaCallOptions as one entity. Eventually CDMA should
411                     // follow the same pattern as GSM below, where VP and Call forwarding are
412                     // populated here and Call waiting is populated in another "Additional Settings"
413                     // submenu for CDMA.
414                     prefSet.removePreference(fdnButton);
415                     cdmaOptions.setSummary(null);
416                     cdmaOptions.setTitle(R.string.additional_gsm_call_settings);
417                     cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
418                 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
419                     prefSet.removePreference(cdmaOptions);
420                     if (mPhone.getIccCard() == null || !mPhone.getIccCard().getIccFdnAvailable()) {
421                         prefSet.removePreference(fdnButton);
422                     }
423                     if (carrierConfig.getBoolean(
424                             CarrierConfigManager.KEY_ADDITIONAL_CALL_SETTING_BOOL)) {
425                         addPreferencesFromResource(R.xml.gsm_umts_call_options);
426                         GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
427                     }
428                 } else {
429                     throw new IllegalStateException("Unexpected phone type: " + phoneType);
430                 }
431             }
432         }
433         updateVtWfc();
434 
435         // Register callback for provisioning changes.
436         try {
437             if (mImsMgr != null) {
438                 mImsMgr.getConfigInterface().addConfigCallback(mProvisioningCallback);
439             }
440         } catch (ImsException e) {
441             Log.w(LOG_TAG, "onResume: Unable to register callback for provisioning changes.");
442         }
443 
444         IntentFilter intentFilter =
445                 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
446         registerReceiver(mReceiver, intentFilter);
447     }
448 
updateVtWfc()449     private void updateVtWfc() {
450         PreferenceScreen prefSet = getPreferenceScreen();
451         TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
452                 .createForSubscriptionId(mPhone.getSubId());
453         PersistableBundle carrierConfig =
454                 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
455         boolean useWfcHomeModeForRoaming = carrierConfig.getBoolean(
456                     CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL,
457                     false);
458         if (mImsMgr.isVtEnabledByPlatform() && mImsMgr.isVtProvisionedOnDevice()
459                 && (carrierConfig.getBoolean(
460                         CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS)
461                 || mPhone.getDataEnabledSettings().isDataEnabled())) {
462             boolean currentValue =
463                     mImsMgr.isEnhanced4gLteModeSettingEnabledByUser()
464                     ? mImsMgr.isVtEnabledByUser() : false;
465             mEnableVideoCalling.setChecked(currentValue);
466             mEnableVideoCalling.setOnPreferenceChangeListener(this);
467             prefSet.addPreference(mEnableVideoCalling);
468         } else {
469             prefSet.removePreference(mEnableVideoCalling);
470         }
471 
472         final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManagerForSubscription(
473                 mPhone.getSubId());
474         if (simCallManager != null) {
475             Intent intent = PhoneAccountSettingsFragment.buildPhoneAccountConfigureIntent(
476                     this, simCallManager);
477             if (intent != null) {
478                 PackageManager pm = mPhone.getContext().getPackageManager();
479                 List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
480                 if (!resolutions.isEmpty()) {
481                     mButtonWifiCalling.setTitle(resolutions.get(0).loadLabel(pm));
482                     mButtonWifiCalling.setSummary(null);
483                     mButtonWifiCalling.setIntent(intent);
484                     prefSet.addPreference(mButtonWifiCalling);
485                 } else {
486                     prefSet.removePreference(mButtonWifiCalling);
487                 }
488             } else {
489                 prefSet.removePreference(mButtonWifiCalling);
490             }
491         } else if (!mImsMgr.isWfcEnabledByPlatform() || !mImsMgr.isWfcProvisionedOnDevice()) {
492             prefSet.removePreference(mButtonWifiCalling);
493         } else {
494             String title = getResourcesForSubId().getString(R.string.wifi_calling);
495             mButtonWifiCalling.setTitle(title);
496 
497             int resId = com.android.internal.R.string.wifi_calling_off_summary;
498             if (mImsMgr.isWfcEnabledByUser()) {
499                 boolean isRoaming = telephonyManager.isNetworkRoaming();
500                 // Also check carrier config for roaming mode
501                 int wfcMode = mImsMgr.getWfcMode(isRoaming && !useWfcHomeModeForRoaming);
502                 switch (wfcMode) {
503                     case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
504                         resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
505                         break;
506                     case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
507                         resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
508                         break;
509                     case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
510                         resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
511                         break;
512                     default:
513                         if (DBG) log("Unexpected WFC mode value: " + wfcMode);
514                 }
515             }
516             mButtonWifiCalling.setSummary(getResourcesForSubId().getString(resId));
517             Intent intent = mButtonWifiCalling.getIntent();
518             if (intent != null) {
519                 intent.putExtra(Settings.EXTRA_SUB_ID, mPhone.getSubId());
520             }
521             prefSet.addPreference(mButtonWifiCalling);
522         }
523 
524         try {
525             if (mImsMgr.getImsServiceState() != ImsFeature.STATE_READY) {
526                 log("Feature state not ready so remove vt and wfc settings for "
527                         + " phone =" + mPhone.getPhoneId());
528                 prefSet.removePreference(mButtonWifiCalling);
529                 prefSet.removePreference(mEnableVideoCalling);
530             }
531         } catch (ImsException ex) {
532             log("Exception when trying to get ImsServiceStatus: " + ex);
533             prefSet.removePreference(mButtonWifiCalling);
534             prefSet.removePreference(mEnableVideoCalling);
535         }
536     }
537 
538     /**
539      * Hides the top level voicemail settings entry point if the default dialer contains a
540      * particular manifest metadata key. This is required when the default dialer wants to display
541      * its own version of voicemail settings.
542      */
maybeHideVoicemailSettings()543     private void maybeHideVoicemailSettings() {
544         String defaultDialer = getSystemService(TelecomManager.class).getDefaultDialerPackage();
545         if (defaultDialer == null) {
546             return;
547         }
548         try {
549             Bundle metadata = getPackageManager()
550                     .getApplicationInfo(defaultDialer, PackageManager.GET_META_DATA).metaData;
551             if (metadata == null) {
552                 return;
553             }
554             if (!metadata
555                     .getBoolean(TelephonyManager.METADATA_HIDE_VOICEMAIL_SETTINGS_MENU, false)) {
556                 if (DBG) {
557                     log("maybeHideVoicemailSettings(): not disabled by default dialer");
558                 }
559                 return;
560             }
561             getPreferenceScreen().removePreference(mVoicemailSettingsScreen);
562             if (DBG) {
563                 log("maybeHideVoicemailSettings(): disabled by default dialer");
564             }
565         } catch (NameNotFoundException e) {
566             // do nothing
567             if (DBG) {
568                 log("maybeHideVoicemailSettings(): not controlled by default dialer");
569             }
570         }
571     }
572 
573     @Override
onNewIntent(Intent newIntent)574     protected void onNewIntent(Intent newIntent) {
575         setIntent(newIntent);
576 
577         mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
578         mPhone = mSubscriptionInfoHelper.getPhone();
579         mSubscriptionInfoHelper.setActionBarTitle(
580                 getActionBar(), getResourcesForSubId(), R.string.call_settings_with_label);
581     }
582 
log(String msg)583     private static void log(String msg) {
584         Log.d(LOG_TAG, msg);
585     }
586 
587     @Override
onOptionsItemSelected(MenuItem item)588     public boolean onOptionsItemSelected(MenuItem item) {
589         final int itemId = item.getItemId();
590         if (itemId == android.R.id.home) {  // See ActionBar#setDisplayHomeAsUpEnabled()
591             onBackPressed();
592             return true;
593         }
594         return super.onOptionsItemSelected(item);
595     }
596 
597     /**
598      * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
599      * This is useful for implementing "HomeAsUp" capability for second-level Settings.
600      */
goUpToTopLevelSetting( Activity activity, SubscriptionInfoHelper subscriptionInfoHelper)601     public static void goUpToTopLevelSetting(
602             Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
603         Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
604         intent.setAction(Intent.ACTION_MAIN);
605         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
606         activity.startActivity(intent);
607         activity.finish();
608     }
609 
getResourcesForSubId()610     private Resources getResourcesForSubId() {
611         if (mPhone != null) {
612             return SubscriptionManager.getResourcesForSubId(mPhone.getContext(), mPhone.getSubId());
613         } else {
614             return getResources();
615         }
616     }
617 }
618