DO NOT MERGE - Fix MSIM for CDMA and GSM Call Options.

This scenario was just... pretty broken before. Update, to pass
the right subscription ids to the right menus, display the right
strings, and obtain the correct phone reference for the sub id.

In particular, moved some initialization code into
GsmUmtsCallOptions so that initialization of its layout can be
shared between it and CallFeatureSettings.

Bug: 19301753
Change-Id: Ib233ad859aefd97abf742334f2636590644eb374
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0b8bcef..3095db0 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -116,10 +116,16 @@
 
     <!-- Error message for users that aren't allowed to modify Mobile Network settings [CHAR LIMIT=none] -->
     <string name="mobile_network_settings_not_available">Cellular network settings are not available for this user</string>
-    <!-- GSM Call settings screen, setting option name -->
+    <!-- GSM Call settings screen, setting option name. [CHAR LIMIT=40] -->
     <string name="labelGSMMore">GSM call settings</string>
-    <!-- CDM Call settings screen, setting option name -->
+    <!-- GSM Call settings screen, setting option name with label indicating the SIM the settings
+         are applied to. [CHAR LIMIT=40] -->
+    <string name="labelGsmMore_with_label">GSM call settings (<xliff:g id="subscriptionlabel" example="T-Mobile">%s</xliff:g>)</string>
+    <!-- CDMA Call settings screen, setting option name -->
     <string name="labelCDMAMore">CDMA call settings</string>
+    <!-- CDMA Call settings screen, setting option name with label indicating the SIM the settings
+         are applied to. [CHAR LIMIT=40] -->
+    <string name="labelCdmaMore_with_label">CDMA call settings (<xliff:g id="subscriptionlabel" example="Verizon">%s</xliff:g>)</string>
     <!-- Mobile network settings screen, setting option name -->
     <string name="apn_settings">Access Point Names</string>
     <!-- Label for the "Network settings" screen in the Settings UI -->
diff --git a/res/xml/call_feature_setting.xml b/res/xml/call_feature_setting.xml
index a6e78e4..6dde59d 100644
--- a/res/xml/call_feature_setting.xml
+++ b/res/xml/call_feature_setting.xml
@@ -129,23 +129,12 @@
         android:key="button_gsm_more_expand_key"
         android:title="@string/labelGSMMore"
         android:summary="@string/sum_gsm_call_settings"
-        android:persistent="false">
-
-        <intent android:action="android.intent.action.MAIN"
-            android:targetPackage="com.android.phone"
-            android:targetClass="com.android.phone.GsmUmtsCallOptions"/>
-
-    </PreferenceScreen>
+        android:persistent="false" />
 
     <PreferenceScreen
         android:key="button_cdma_more_expand_key"
         android:title="@string/labelCDMAMore"
         android:summary="@string/sum_cdma_call_settings"
-        android:persistent="false">
+        android:persistent="false" />
 
-        <intent android:action="android.intent.action.MAIN"
-            android:targetPackage="com.android.phone"
-            android:targetClass="com.android.phone.CdmaCallOptions"/>
-
-    </PreferenceScreen>
 </PreferenceScreen>
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index 4fa28ab..b23a14b 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -162,8 +162,6 @@
 
     private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
     private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
-    private static final String CALL_FORWARDING_KEY = "call_forwarding_key";
-    private static final String ADDITIONAL_GSM_SETTINGS_KEY = "additional_gsm_call_settings_key";
 
     private static final String PHONE_ACCOUNT_SETTINGS_KEY =
             "phone_account_settings_preference_screen";
@@ -1255,12 +1253,13 @@
             mButtonTTY = null;
         }
 
-        if (!getResources().getBoolean(R.bool.world_phone)) {
-            Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
+        Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
+        Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
+        if (getResources().getBoolean(R.bool.world_phone)) {
+            cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
+            gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
+        } else {
             prefSet.removePreference(cdmaOptions);
-
-            // TODO: Support MSIM for this preference option.
-            Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
             prefSet.removePreference(gsmOptions);
 
             int phoneType = mPhone.getPhoneType();
@@ -1284,15 +1283,7 @@
 
                     if (getResources().getBoolean(R.bool.config_additional_call_setting)) {
                         addPreferencesFromResource(R.xml.gsm_umts_call_options);
-
-                        Preference callForwardingPref = prefSet.findPreference(CALL_FORWARDING_KEY);
-                        callForwardingPref.setIntent(mSubscriptionInfoHelper.getIntent(
-                                GsmUmtsCallForwardOptions.class));
-
-                        Preference additionalGsmSettingsPref =
-                                prefSet.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
-                        additionalGsmSettingsPref.setIntent(mSubscriptionInfoHelper.getIntent(
-                                GsmUmtsAdditionalCallOptions.class));
+                        GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
                     }
                 } else {
                     throw new IllegalStateException("Unexpected phone type: " + phoneType);
diff --git a/src/com/android/phone/CdmaCallOptions.java b/src/com/android/phone/CdmaCallOptions.java
index 8eecd27..8f7b1b1 100644
--- a/src/com/android/phone/CdmaCallOptions.java
+++ b/src/com/android/phone/CdmaCallOptions.java
@@ -29,6 +29,7 @@
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceScreen;
 import android.util.Log;
+import android.view.MenuItem;
 
 public class CdmaCallOptions extends PreferenceActivity {
     private static final String LOG_TAG = "CdmaCallOptions";
@@ -43,8 +44,12 @@
 
         addPreferencesFromResource(R.xml.cdma_call_privacy);
 
+        SubscriptionInfoHelper subInfoHelper = new SubscriptionInfoHelper(this, getIntent());
+        subInfoHelper.setActionBarTitle(
+                getActionBar(), getResources(), R.string.labelCdmaMore_with_label);
+
         mButtonVoicePrivacy = (CheckBoxPreference) findPreference(BUTTON_VP_KEY);
-        if (PhoneGlobals.getPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_CDMA
+        if (subInfoHelper.getPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_CDMA
                 || getResources().getBoolean(R.bool.config_voice_privacy_disable)) {
             //disable the entire screen
             getPreferenceScreen().setEnabled(false);
@@ -52,6 +57,16 @@
     }
 
     @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        final int itemId = item.getItemId();
+        if (itemId == android.R.id.home) {
+            onBackPressed();
+            return true;
+        }
+        return super.onOptionsItemSelected(item);
+    }
+
+    @Override
     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
         if (preference.getKey().equals(BUTTON_VP_KEY)) {
             return true;
diff --git a/src/com/android/phone/GsmUmtsCallOptions.java b/src/com/android/phone/GsmUmtsCallOptions.java
index a9a1940..419e72c 100644
--- a/src/com/android/phone/GsmUmtsCallOptions.java
+++ b/src/com/android/phone/GsmUmtsCallOptions.java
@@ -21,6 +21,7 @@
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceScreen;
+import android.view.MenuItem;
 
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
@@ -29,15 +30,43 @@
     private static final String LOG_TAG = "GsmUmtsCallOptions";
     private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
 
+    private static final String CALL_FORWARDING_KEY = "call_forwarding_key";
+    private static final String ADDITIONAL_GSM_SETTINGS_KEY = "additional_gsm_call_settings_key";
+
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
 
         addPreferencesFromResource(R.xml.gsm_umts_call_options);
 
-        if (PhoneGlobals.getPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
+        SubscriptionInfoHelper subInfoHelper = new SubscriptionInfoHelper(this, getIntent());
+        subInfoHelper.setActionBarTitle(
+                getActionBar(), getResources(), R.string.labelGsmMore_with_label);
+        init(getPreferenceScreen(), subInfoHelper);
+
+        if (subInfoHelper.getPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
             //disable the entire screen
             getPreferenceScreen().setEnabled(false);
         }
     }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        final int itemId = item.getItemId();
+        if (itemId == android.R.id.home) {
+            onBackPressed();
+            return true;
+        }
+        return super.onOptionsItemSelected(item);
+    }
+
+    public static void init(PreferenceScreen prefScreen, SubscriptionInfoHelper subInfoHelper) {
+        Preference callForwardingPref = prefScreen.findPreference(CALL_FORWARDING_KEY);
+        callForwardingPref.setIntent(subInfoHelper.getIntent(GsmUmtsCallForwardOptions.class));
+
+        Preference additionalGsmSettingsPref =
+                prefScreen.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
+        additionalGsmSettingsPref.setIntent(
+                subInfoHelper.getIntent(GsmUmtsAdditionalCallOptions.class));
+    }
 }