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