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