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 401 if (!carrierConfig.getBoolean( 402 CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) { 403 addPreferencesFromResource(R.xml.cdma_call_privacy); 404 CdmaVoicePrivacySwitchPreference buttonVoicePrivacy = 405 (CdmaVoicePrivacySwitchPreference) findPreference(BUTTON_VP_KEY); 406 buttonVoicePrivacy.setPhone(mPhone); 407 } 408 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { 409 if (mPhone.getIccCard() == null || !mPhone.getIccCard().getIccFdnAvailable()) { 410 prefSet.removePreference(fdnButton); 411 } 412 if (carrierConfig.getBoolean( 413 CarrierConfigManager.KEY_ADDITIONAL_CALL_SETTING_BOOL)) { 414 addPreferencesFromResource(R.xml.gsm_umts_call_options); 415 GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper); 416 } 417 } else { 418 throw new IllegalStateException("Unexpected phone type: " + phoneType); 419 } 420 } 421 } 422 updateVtWfc(); 423 424 // Register callback for provisioning changes. 425 try { 426 if (mImsMgr != null) { 427 mImsMgr.getConfigInterface().addConfigCallback(mProvisioningCallback); 428 } 429 } catch (ImsException e) { 430 Log.w(LOG_TAG, "onResume: Unable to register callback for provisioning changes."); 431 } 432 433 IntentFilter intentFilter = 434 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED); 435 registerReceiver(mReceiver, intentFilter); 436 } 437 updateVtWfc()438 private void updateVtWfc() { 439 PreferenceScreen prefSet = getPreferenceScreen(); 440 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class) 441 .createForSubscriptionId(mPhone.getSubId()); 442 PersistableBundle carrierConfig = 443 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId()); 444 boolean useWfcHomeModeForRoaming = carrierConfig.getBoolean( 445 CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL, 446 false); 447 if (mImsMgr.isVtEnabledByPlatform() && mImsMgr.isVtProvisionedOnDevice() 448 && (carrierConfig.getBoolean( 449 CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS) 450 || mPhone.getDataEnabledSettings().isDataEnabled())) { 451 boolean currentValue = 452 mImsMgr.isEnhanced4gLteModeSettingEnabledByUser() 453 ? mImsMgr.isVtEnabledByUser() : false; 454 mEnableVideoCalling.setChecked(currentValue); 455 mEnableVideoCalling.setOnPreferenceChangeListener(this); 456 prefSet.addPreference(mEnableVideoCalling); 457 } else { 458 prefSet.removePreference(mEnableVideoCalling); 459 } 460 461 final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManagerForSubscription( 462 mPhone.getSubId()); 463 if (simCallManager != null) { 464 Intent intent = PhoneAccountSettingsFragment.buildPhoneAccountConfigureIntent( 465 this, simCallManager); 466 if (intent != null) { 467 PackageManager pm = mPhone.getContext().getPackageManager(); 468 List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0); 469 if (!resolutions.isEmpty()) { 470 mButtonWifiCalling.setTitle(resolutions.get(0).loadLabel(pm)); 471 mButtonWifiCalling.setSummary(null); 472 mButtonWifiCalling.setIntent(intent); 473 prefSet.addPreference(mButtonWifiCalling); 474 } else { 475 prefSet.removePreference(mButtonWifiCalling); 476 } 477 } else { 478 prefSet.removePreference(mButtonWifiCalling); 479 } 480 } else if (!mImsMgr.isWfcEnabledByPlatform() || !mImsMgr.isWfcProvisionedOnDevice()) { 481 prefSet.removePreference(mButtonWifiCalling); 482 } else { 483 String title = getResourcesForSubId().getString(R.string.wifi_calling); 484 mButtonWifiCalling.setTitle(title); 485 486 int resId = com.android.internal.R.string.wifi_calling_off_summary; 487 if (mImsMgr.isWfcEnabledByUser()) { 488 boolean isRoaming = telephonyManager.isNetworkRoaming(); 489 // Also check carrier config for roaming mode 490 int wfcMode = mImsMgr.getWfcMode(isRoaming && !useWfcHomeModeForRoaming); 491 switch (wfcMode) { 492 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY: 493 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary; 494 break; 495 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED: 496 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary; 497 break; 498 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED: 499 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary; 500 break; 501 default: 502 if (DBG) log("Unexpected WFC mode value: " + wfcMode); 503 } 504 } 505 mButtonWifiCalling.setSummary(getResourcesForSubId().getString(resId)); 506 Intent intent = mButtonWifiCalling.getIntent(); 507 if (intent != null) { 508 intent.putExtra(Settings.EXTRA_SUB_ID, mPhone.getSubId()); 509 } 510 prefSet.addPreference(mButtonWifiCalling); 511 } 512 513 try { 514 if (mImsMgr.getImsServiceState() != ImsFeature.STATE_READY) { 515 log("Feature state not ready so remove vt and wfc settings for " 516 + " phone =" + mPhone.getPhoneId()); 517 prefSet.removePreference(mButtonWifiCalling); 518 prefSet.removePreference(mEnableVideoCalling); 519 } 520 } catch (ImsException ex) { 521 log("Exception when trying to get ImsServiceStatus: " + ex); 522 prefSet.removePreference(mButtonWifiCalling); 523 prefSet.removePreference(mEnableVideoCalling); 524 } 525 } 526 527 /** 528 * Hides the top level voicemail settings entry point if the default dialer contains a 529 * particular manifest metadata key. This is required when the default dialer wants to display 530 * its own version of voicemail settings. 531 */ maybeHideVoicemailSettings()532 private void maybeHideVoicemailSettings() { 533 String defaultDialer = getSystemService(TelecomManager.class).getDefaultDialerPackage(); 534 if (defaultDialer == null) { 535 return; 536 } 537 try { 538 Bundle metadata = getPackageManager() 539 .getApplicationInfo(defaultDialer, PackageManager.GET_META_DATA).metaData; 540 if (metadata == null) { 541 return; 542 } 543 if (!metadata 544 .getBoolean(TelephonyManager.METADATA_HIDE_VOICEMAIL_SETTINGS_MENU, false)) { 545 if (DBG) { 546 log("maybeHideVoicemailSettings(): not disabled by default dialer"); 547 } 548 return; 549 } 550 getPreferenceScreen().removePreference(mVoicemailSettingsScreen); 551 if (DBG) { 552 log("maybeHideVoicemailSettings(): disabled by default dialer"); 553 } 554 } catch (NameNotFoundException e) { 555 // do nothing 556 if (DBG) { 557 log("maybeHideVoicemailSettings(): not controlled by default dialer"); 558 } 559 } 560 } 561 562 @Override onNewIntent(Intent newIntent)563 protected void onNewIntent(Intent newIntent) { 564 setIntent(newIntent); 565 566 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent()); 567 mPhone = mSubscriptionInfoHelper.getPhone(); 568 mSubscriptionInfoHelper.setActionBarTitle( 569 getActionBar(), getResourcesForSubId(), R.string.call_settings_with_label); 570 } 571 log(String msg)572 private static void log(String msg) { 573 Log.d(LOG_TAG, msg); 574 } 575 576 @Override onOptionsItemSelected(MenuItem item)577 public boolean onOptionsItemSelected(MenuItem item) { 578 final int itemId = item.getItemId(); 579 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled() 580 onBackPressed(); 581 return true; 582 } 583 return super.onOptionsItemSelected(item); 584 } 585 586 /** 587 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}). 588 * This is useful for implementing "HomeAsUp" capability for second-level Settings. 589 */ goUpToTopLevelSetting( Activity activity, SubscriptionInfoHelper subscriptionInfoHelper)590 public static void goUpToTopLevelSetting( 591 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) { 592 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class); 593 intent.setAction(Intent.ACTION_MAIN); 594 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 595 activity.startActivity(intent); 596 activity.finish(); 597 } 598 getResourcesForSubId()599 private Resources getResourcesForSubId() { 600 if (mPhone != null) { 601 return SubscriptionManager.getResourcesForSubId(mPhone.getContext(), mPhone.getSubId()); 602 } else { 603 return getResources(); 604 } 605 } 606 } 607