Merge "Fix CDMA Call Forwarding/Call Waiting UI" into sc-dev
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index 09f1072..ec6ea2b 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -398,7 +398,8 @@
             cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
             gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
         } else {
-            prefSet.removePreference(cdmaOptions);
+            // Remove GSM options and repopulate the preferences in this Activity if phone type is
+            // GSM.
             prefSet.removePreference(gsmOptions);
 
             int phoneType = mPhone.getPhoneType();
@@ -406,12 +407,16 @@
                 prefSet.removePreference(fdnButton);
             } else {
                 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
+                    // For now, just keep CdmaCallOptions as one entity. Eventually CDMA should
+                    // follow the same pattern as GSM below, where VP and Call forwarding are
+                    // populated here and Call waiting is populated in another "Additional Settings"
+                    // submenu for CDMA.
                     prefSet.removePreference(fdnButton);
-                    addPreferencesFromResource(R.xml.cdma_call_privacy);
-                    CdmaVoicePrivacySwitchPreference buttonVoicePrivacy =
-                            (CdmaVoicePrivacySwitchPreference) findPreference(BUTTON_VP_KEY);
-                    buttonVoicePrivacy.setPhone(mPhone);
+                    cdmaOptions.setSummary(null);
+                    cdmaOptions.setTitle(R.string.additional_gsm_call_settings);
+                    cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
                 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
+                    prefSet.removePreference(cdmaOptions);
                     if (mPhone.getIccCard() == null || !mPhone.getIccCard().getIccFdnAvailable()) {
                         prefSet.removePreference(fdnButton);
                     }
diff --git a/src/com/android/phone/CdmaCallOptions.java b/src/com/android/phone/CdmaCallOptions.java
index 2e310aa..40e3517 100644
--- a/src/com/android/phone/CdmaCallOptions.java
+++ b/src/com/android/phone/CdmaCallOptions.java
@@ -32,7 +32,6 @@
     private static final String BUTTON_VP_KEY = "button_voice_privacy_key";
     private static final String CALL_FORWARDING_KEY = "call_forwarding_key";
     private static final String CALL_WAITING_KEY = "call_waiting_key";
-    private CdmaVoicePrivacySwitchPreference mButtonVoicePrivacy;
 
     @Override
     protected void onCreate(Bundle icicle) {
@@ -44,8 +43,9 @@
         subInfoHelper.setActionBarTitle(
                 getActionBar(), getResources(), R.string.labelCdmaMore_with_label);
 
-        mButtonVoicePrivacy = (CdmaVoicePrivacySwitchPreference) findPreference(BUTTON_VP_KEY);
-        mButtonVoicePrivacy.setPhone(subInfoHelper.getPhone());
+        CdmaVoicePrivacySwitchPreference buttonVoicePrivacy =
+                (CdmaVoicePrivacySwitchPreference) findPreference(BUTTON_VP_KEY);
+        buttonVoicePrivacy.setPhone(subInfoHelper.getPhone());
         PersistableBundle carrierConfig;
         if (subInfoHelper.hasSubId()) {
             carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(
@@ -55,16 +55,26 @@
         }
         if (subInfoHelper.getPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_CDMA
                 || carrierConfig.getBoolean(CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
-            // disable the entire screen
-            mButtonVoicePrivacy.setEnabled(false);
+            buttonVoicePrivacy.setEnabled(false);
         }
 
         Preference callForwardingPref = getPreferenceScreen().findPreference(CALL_FORWARDING_KEY);
-        callForwardingPref.setIntent(subInfoHelper.getIntent(CdmaCallForwardOptions.class));
+        if (carrierConfig != null && carrierConfig.getBoolean(
+                CarrierConfigManager.KEY_CALL_FORWARDING_VISIBILITY_BOOL)) {
+            callForwardingPref.setIntent(
+                    subInfoHelper.getIntent(CdmaCallForwardOptions.class));
+        } else {
+            getPreferenceScreen().removePreference(callForwardingPref);
+        }
 
         CdmaCallWaitingPreference callWaitingPref = (CdmaCallWaitingPreference)getPreferenceScreen()
                                                      .findPreference(CALL_WAITING_KEY);
-        callWaitingPref.init(this, subInfoHelper.getPhone());
+        if (carrierConfig != null && carrierConfig.getBoolean(
+                CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL)) {
+            callWaitingPref.init(this, subInfoHelper.getPhone());
+        } else {
+            getPreferenceScreen().removePreference(callWaitingPref);
+        }
     }
 
     @Override