am b2bdf2f3: am bddc129f: Merge "Add MSIM support for Call Forwarding." into lmp-mr1-dev

* commit 'b2bdf2f3128b5781fc69e6827ce7bd67960884a0':
  Add MSIM support for Call Forwarding.
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5701dfb..a97d7c4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -183,6 +183,8 @@
     <string name="call_settings">Call settings</string>
     <!-- GSM Call settings screen, setting option name -->
     <string name="additional_gsm_call_settings">Additional settings</string>
+    <!-- GSM Call settings screen, setting option name, with label identifying the SIM the settings are for. -->
+    <string name="additional_gsm_call_settings_with_label">Additional settings (<xliff:g id="subscriptionlabel" example="Verizon">%s</xliff:g>)</string>
     <!-- GSM-only Call settings screen, setting option name-->
     <string name="sum_gsm_call_settings">Additional GSM only call settings</string>
     <!-- CDMA Call settings screen, setting option name -->
@@ -209,6 +211,8 @@
     <string name="sum_cw_disabled">During a call, notify me of incoming calls</string>
     <!-- Call forwarding settings screen, section heading -->
     <string name="call_forwarding_settings">Call forwarding settings</string>
+    <!-- Call forwarding settings screen, section heading, with a label identifying the SIM the settings are for. -->
+    <string name="call_forwarding_settings_with_label">Call forwarding settings (<xliff:g id="subscriptionlabel" example="Verizon">%s</xliff:g>)</string>
     <!-- Call settings screen, setting option name -->
     <string name="labelCF">Call forwarding</string>
 
diff --git a/res/xml/gsm_umts_additional_options.xml b/res/xml/gsm_umts_additional_options.xml
index 19ec56b..f2234e3 100644
--- a/res/xml/gsm_umts_additional_options.xml
+++ b/res/xml/gsm_umts_additional_options.xml
@@ -21,4 +21,5 @@
         android:summaryOn="@string/sum_cw_enabled"
         android:summaryOff="@string/sum_cw_disabled"
         android:enabled="false"/>
+
 </PreferenceScreen>
diff --git a/res/xml/gsm_umts_call_options.xml b/res/xml/gsm_umts_call_options.xml
index 2f3c235..5f3dfe4 100644
--- a/res/xml/gsm_umts_call_options.xml
+++ b/res/xml/gsm_umts_call_options.xml
@@ -1,25 +1,17 @@
 <?xml version="1.0" encoding="utf-8"?>
+
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:phone="http://schemas.android.com/apk/res/com.android.phone"
      android:title="@string/labelGSMMore">
 
     <PreferenceScreen
-        android:key="button_cf_expand_key"
+        android:key="call_forwarding_key"
         android:title="@string/labelCF"
-        android:persistent="false">
-
-        <intent android:action="android.intent.action.MAIN"
-            android:targetPackage="com.android.phone"
-            android:targetClass="com.android.phone.GsmUmtsCallForwardOptions"/>
-    </PreferenceScreen>
+        android:persistent="false" />
 
     <PreferenceScreen
-        android:key="button_more_expand_key"
+        android:key="additional_gsm_call_settings_key"
         android:title="@string/additional_gsm_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.GsmUmtsAdditionalCallOptions"/>
-    </PreferenceScreen>
 </PreferenceScreen>
diff --git a/src/com/android/phone/CLIRListPreference.java b/src/com/android/phone/CLIRListPreference.java
index 198bdb0..939caf0 100644
--- a/src/com/android/phone/CLIRListPreference.java
+++ b/src/com/android/phone/CLIRListPreference.java
@@ -23,15 +23,13 @@
     private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
 
     private final MyHandler mHandler = new MyHandler();
-    private final Phone mPhone;
+    private Phone mPhone;
     private TimeConsumingPreferenceListener mTcpListener;
 
     int clirArray[];
 
     public CLIRListPreference(Context context, AttributeSet attrs) {
         super(context, attrs);
-
-        mPhone = PhoneGlobals.getPhone();
     }
 
     public CLIRListPreference(Context context) {
@@ -49,7 +47,9 @@
         }
     }
 
-    /* package */ void init(TimeConsumingPreferenceListener listener, boolean skipReading) {
+    /* package */ void init(
+            TimeConsumingPreferenceListener listener, boolean skipReading, Phone phone) {
+        mPhone = phone;
         mTcpListener = listener;
         if (!skipReading) {
             mPhone.getOutgoingCallerIdDisplay(mHandler.obtainMessage(MyHandler.MESSAGE_GET_CLIR,
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index 65ca3e5..c99e432 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -163,6 +163,8 @@
 
     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 DEFAULT_OUTGOING_ACCOUNT_KEY = "default_outgoing_account";
     private static final String PHONE_ACCOUNT_SETTINGS_KEY =
@@ -1316,14 +1318,12 @@
         }
 
         if (!getResources().getBoolean(R.bool.world_phone)) {
-            Preference options = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
-            if (options != null) {
-                prefSet.removePreference(options);
-            }
-            options = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
-            if (options != null) {
-                prefSet.removePreference(options);
-            }
+            Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
+            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();
             Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
@@ -1338,6 +1338,15 @@
 
                 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(
+                            this, GsmUmtsCallForwardOptions.class));
+
+                    Preference additionalGsmSettingsPref =
+                            prefSet.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
+                    additionalGsmSettingsPref.setIntent(mSubscriptionInfoHelper.getIntent(
+                            this, GsmUmtsAdditionalCallOptions.class));
                 }
             } else {
                 throw new IllegalStateException("Unexpected phone type: " + phoneType);
diff --git a/src/com/android/phone/CallForwardEditPreference.java b/src/com/android/phone/CallForwardEditPreference.java
index f925022..b176c27 100644
--- a/src/com/android/phone/CallForwardEditPreference.java
+++ b/src/com/android/phone/CallForwardEditPreference.java
@@ -36,14 +36,13 @@
     private int mServiceClass;
     private MyHandler mHandler = new MyHandler();
     int reason;
-    Phone phone;
+    private Phone mPhone;
     CallForwardInfo callForwardInfo;
-    TimeConsumingPreferenceListener tcpListener;
+    private TimeConsumingPreferenceListener mTcpListener;
 
     public CallForwardEditPreference(Context context, AttributeSet attrs) {
         super(context, attrs);
 
-        phone = PhoneGlobals.getPhone();
         mSummaryOnTemplate = this.getSummaryOn();
 
         TypedArray a = context.obtainStyledAttributes(attrs,
@@ -61,16 +60,18 @@
         this(context, null);
     }
 
-    void init(TimeConsumingPreferenceListener listener, boolean skipReading) {
-        tcpListener = listener;
+    void init(TimeConsumingPreferenceListener listener, boolean skipReading, Phone phone) {
+        mPhone = phone;
+        mTcpListener = listener;
+
         if (!skipReading) {
-            phone.getCallForwardingOption(reason,
+            mPhone.getCallForwardingOption(reason,
                     mHandler.obtainMessage(MyHandler.MESSAGE_GET_CF,
                             // unused in this case
                             CommandsInterface.CF_ACTION_DISABLE,
                             MyHandler.MESSAGE_GET_CF, null));
-            if (tcpListener != null) {
-                tcpListener.onStarted(this, true);
+            if (mTcpListener != null) {
+                mTcpListener.onStarted(this, true);
             }
         }
     }
@@ -122,7 +123,7 @@
 
                 // the interface of Phone.setCallForwardingOption has error:
                 // should be action, reason...
-                phone.setCallForwardingOption(action,
+                mPhone.setCallForwardingOption(action,
                         reason,
                         number,
                         time,
@@ -130,8 +131,8 @@
                                 action,
                                 MyHandler.MESSAGE_SET_CF));
 
-                if (tcpListener != null) {
-                    tcpListener.onStarted(this, false);
+                if (mTcpListener != null) {
+                    mTcpListener.onStarted(this, false);
                 }
             }
         }
@@ -183,28 +184,24 @@
         private void handleGetCFResponse(Message msg) {
             if (DBG) Log.d(LOG_TAG, "handleGetCFResponse: done");
 
-            if (msg.arg2 == MESSAGE_SET_CF) {
-                tcpListener.onFinished(CallForwardEditPreference.this, false);
-            } else {
-                tcpListener.onFinished(CallForwardEditPreference.this, true);
-            }
+            mTcpListener.onFinished(CallForwardEditPreference.this, msg.arg2 != MESSAGE_SET_CF);
 
             AsyncResult ar = (AsyncResult) msg.obj;
 
             callForwardInfo = null;
             if (ar.exception != null) {
                 if (DBG) Log.d(LOG_TAG, "handleGetCFResponse: ar.exception=" + ar.exception);
-                tcpListener.onException(CallForwardEditPreference.this,
+                mTcpListener.onException(CallForwardEditPreference.this,
                         (CommandException) ar.exception);
             } else {
                 if (ar.userObj instanceof Throwable) {
-                    tcpListener.onError(CallForwardEditPreference.this, RESPONSE_ERROR);
+                    mTcpListener.onError(CallForwardEditPreference.this, RESPONSE_ERROR);
                 }
                 CallForwardInfo cfInfoArray[] = (CallForwardInfo[]) ar.result;
                 if (cfInfoArray.length == 0) {
                     if (DBG) Log.d(LOG_TAG, "handleGetCFResponse: cfInfoArray.length==0");
                     setEnabled(false);
-                    tcpListener.onError(CallForwardEditPreference.this, RESPONSE_ERROR);
+                    mTcpListener.onError(CallForwardEditPreference.this, RESPONSE_ERROR);
                 } else {
                     for (int i = 0, length = cfInfoArray.length; i < length; i++) {
                         if (DBG) Log.d(LOG_TAG, "handleGetCFResponse, cfInfoArray[" + i + "]="
@@ -258,7 +255,7 @@
                 // setEnabled(false);
             }
             if (DBG) Log.d(LOG_TAG, "handleSetCFResponse: re get");
-            phone.getCallForwardingOption(reason,
+            mPhone.getCallForwardingOption(reason,
                     obtainMessage(MESSAGE_GET_CF, msg.arg1, MESSAGE_SET_CF, ar.exception));
         }
     }
diff --git a/src/com/android/phone/CallWaitingCheckBoxPreference.java b/src/com/android/phone/CallWaitingCheckBoxPreference.java
index a2f5c70..ce2a420 100644
--- a/src/com/android/phone/CallWaitingCheckBoxPreference.java
+++ b/src/com/android/phone/CallWaitingCheckBoxPreference.java
@@ -20,13 +20,11 @@
     private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
 
     private final MyHandler mHandler = new MyHandler();
-    private final Phone mPhone;
+    private Phone mPhone;
     private TimeConsumingPreferenceListener mTcpListener;
 
     public CallWaitingCheckBoxPreference(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
-
-        mPhone = PhoneGlobals.getPhone();
     }
 
     public CallWaitingCheckBoxPreference(Context context, AttributeSet attrs) {
@@ -37,7 +35,9 @@
         this(context, null);
     }
 
-    /* package */ void init(TimeConsumingPreferenceListener listener, boolean skipReading) {
+    /* package */ void init(
+            TimeConsumingPreferenceListener listener, boolean skipReading, Phone phone) {
+        mPhone = phone;
         mTcpListener = listener;
 
         if (!skipReading) {
diff --git a/src/com/android/phone/GsmUmtsAdditionalCallOptions.java b/src/com/android/phone/GsmUmtsAdditionalCallOptions.java
index cd400f9..0540547 100644
--- a/src/com/android/phone/GsmUmtsAdditionalCallOptions.java
+++ b/src/com/android/phone/GsmUmtsAdditionalCallOptions.java
@@ -8,10 +8,11 @@
 import android.util.Log;
 import android.view.MenuItem;
 
+import com.android.internal.telephony.Phone;
+
 import java.util.ArrayList;
 
-public class GsmUmtsAdditionalCallOptions extends
-        TimeConsumingPreferenceActivity {
+public class GsmUmtsAdditionalCallOptions extends TimeConsumingPreferenceActivity {
     private static final String LOG_TAG = "GsmUmtsAdditionalCallOptions";
     private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
 
@@ -22,7 +23,8 @@
     private CallWaitingCheckBoxPreference mCWButton;
 
     private final ArrayList<Preference> mPreferences = new ArrayList<Preference>();
-    private int mInitIndex= 0;
+    private int mInitIndex = 0;
+    private Phone mPhone;
 
     @Override
     protected void onCreate(Bundle icicle) {
@@ -30,6 +32,11 @@
 
         addPreferencesFromResource(R.xml.gsm_umts_additional_options);
 
+        SubscriptionInfoHelper subscriptionInfoHelper = new SubscriptionInfoHelper(getIntent());
+        subscriptionInfoHelper.setActionBarTitle(
+                getActionBar(), getResources(), R.string.additional_gsm_call_settings_with_label);
+        mPhone = subscriptionInfoHelper.getPhone();
+
         PreferenceScreen prefSet = getPreferenceScreen();
         mCLIRButton = (CLIRListPreference) prefSet.findPreference(BUTTON_CLIR_KEY);
         mCWButton = (CallWaitingCheckBoxPreference) prefSet.findPreference(BUTTON_CW_KEY);
@@ -39,19 +46,19 @@
 
         if (icicle == null) {
             if (DBG) Log.d(LOG_TAG, "start to init ");
-            mCLIRButton.init(this, false);
+            mCLIRButton.init(this, false, mPhone);
         } else {
             if (DBG) Log.d(LOG_TAG, "restore stored states");
             mInitIndex = mPreferences.size();
-            mCLIRButton.init(this, true);
-            mCWButton.init(this, true);
+            mCLIRButton.init(this, true, mPhone);
+            mCWButton.init(this, true, mPhone);
             int[] clirArray = icicle.getIntArray(mCLIRButton.getKey());
             if (clirArray != null) {
                 if (DBG) Log.d(LOG_TAG, "onCreate:  clirArray[0]="
                         + clirArray[0] + ", clirArray[1]=" + clirArray[1]);
                 mCLIRButton.handleGetCLIRResult(clirArray);
             } else {
-                mCLIRButton.init(this, false);
+                mCLIRButton.init(this, false, mPhone);
             }
         }
 
@@ -77,7 +84,7 @@
             mInitIndex++;
             Preference pref = mPreferences.get(mInitIndex);
             if (pref instanceof CallWaitingCheckBoxPreference) {
-                ((CallWaitingCheckBoxPreference) pref).init(this, false);
+                ((CallWaitingCheckBoxPreference) pref).init(this, false, mPhone);
             }
         }
         super.onFinished(preference, reading);
diff --git a/src/com/android/phone/GsmUmtsCallForwardOptions.java b/src/com/android/phone/GsmUmtsCallForwardOptions.java
index 8ecb1bf..3c4bebe 100644
--- a/src/com/android/phone/GsmUmtsCallForwardOptions.java
+++ b/src/com/android/phone/GsmUmtsCallForwardOptions.java
@@ -2,6 +2,7 @@
 
 import com.android.internal.telephony.CallForwardInfo;
 import com.android.internal.telephony.CommandsInterface;
+import com.android.internal.telephony.Phone;
 
 import android.app.ActionBar;
 import android.content.Intent;
@@ -9,7 +10,6 @@
 import android.os.Bundle;
 import android.preference.Preference;
 import android.preference.PreferenceScreen;
-import android.provider.ContactsContract.CommonDataKinds.Phone;
 import android.util.Log;
 import android.view.MenuItem;
 
@@ -20,7 +20,9 @@
     private static final String LOG_TAG = "GsmUmtsCallForwardOptions";
     private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
 
-    private static final String NUM_PROJECTION[] = {Phone.NUMBER};
+    private static final String NUM_PROJECTION[] = {
+        android.provider.ContactsContract.CommonDataKinds.Phone.NUMBER
+    };
 
     private static final String BUTTON_CFU_KEY   = "button_cfu_key";
     private static final String BUTTON_CFB_KEY   = "button_cfb_key";
@@ -42,6 +44,7 @@
 
     private boolean mFirstResume;
     private Bundle mIcicle;
+    private Phone mPhone;
 
     @Override
     protected void onCreate(Bundle icicle) {
@@ -49,9 +52,14 @@
 
         addPreferencesFromResource(R.xml.callforward_options);
 
+        SubscriptionInfoHelper subscriptionInfoHelper = new SubscriptionInfoHelper(getIntent());
+        subscriptionInfoHelper.setActionBarTitle(
+                getActionBar(), getResources(), R.string.call_forwarding_settings_with_label);
+        mPhone = subscriptionInfoHelper.getPhone();
+
         PreferenceScreen prefSet = getPreferenceScreen();
-        mButtonCFU   = (CallForwardEditPreference) prefSet.findPreference(BUTTON_CFU_KEY);
-        mButtonCFB   = (CallForwardEditPreference) prefSet.findPreference(BUTTON_CFB_KEY);
+        mButtonCFU = (CallForwardEditPreference) prefSet.findPreference(BUTTON_CFU_KEY);
+        mButtonCFB = (CallForwardEditPreference) prefSet.findPreference(BUTTON_CFB_KEY);
         mButtonCFNRy = (CallForwardEditPreference) prefSet.findPreference(BUTTON_CFNRY_KEY);
         mButtonCFNRc = (CallForwardEditPreference) prefSet.findPreference(BUTTON_CFNRC_KEY);
 
@@ -86,7 +94,7 @@
         if (mFirstResume) {
             if (mIcicle == null) {
                 if (DBG) Log.d(LOG_TAG, "start to init ");
-                mPreferences.get(mInitIndex).init(this, false);
+                mPreferences.get(mInitIndex).init(this, false, mPhone);
             } else {
                 mInitIndex = mPreferences.size();
 
@@ -97,11 +105,11 @@
                     cf.number = bundle.getString(KEY_NUMBER);
                     cf.status = bundle.getInt(KEY_STATUS);
                     pref.handleCallForwardResult(cf);
-                    pref.init(this, true);
+                    pref.init(this, true, mPhone);
                 }
             }
             mFirstResume = false;
-            mIcicle=null;
+            mIcicle = null;
         }
     }
 
@@ -124,7 +132,7 @@
     public void onFinished(Preference preference, boolean reading) {
         if (mInitIndex < mPreferences.size()-1 && !isFinishing()) {
             mInitIndex++;
-            mPreferences.get(mInitIndex).init(this, false);
+            mPreferences.get(mInitIndex).init(this, false, mPhone);
         }
 
         super.onFinished(preference, reading);