Merge "Merge QQ3A.200605.002 into master"
diff --git a/src/com/android/phone/GsmUmtsCallForwardOptions.java b/src/com/android/phone/GsmUmtsCallForwardOptions.java
index 10bd8d7..fda0ea5 100644
--- a/src/com/android/phone/GsmUmtsCallForwardOptions.java
+++ b/src/com/android/phone/GsmUmtsCallForwardOptions.java
@@ -63,7 +63,9 @@
         mPhone = mSubscriptionInfoHelper.getPhone();
 
         PersistableBundle b = null;
+        boolean supportCFB = true;
         boolean supportCFNRc = true;
+        boolean supportCFNRy = true;
         if (mSubscriptionInfoHelper.hasSubId()) {
             b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
                     mSubscriptionInfoHelper.getSubId());
@@ -75,8 +77,12 @@
                     CarrierConfigManager.KEY_CALL_FORWARDING_MAP_NON_NUMBER_TO_VOICEMAIL_BOOL);
             mCallForwardByUssd = b.getBoolean(
                     CarrierConfigManager.KEY_USE_CALL_FORWARDING_USSD_BOOL);
+            supportCFB = b.getBoolean(
+                    CarrierConfigManager.KEY_CALL_FORWARDING_WHEN_BUSY_SUPPORTED_BOOL);
             supportCFNRc = b.getBoolean(
                     CarrierConfigManager.KEY_CALL_FORWARDING_WHEN_UNREACHABLE_SUPPORTED_BOOL);
+            supportCFNRy = b.getBoolean(
+                    CarrierConfigManager.KEY_CALL_FORWARDING_WHEN_UNANSWERED_SUPPORTED_BOOL);
         }
 
         PreferenceScreen prefSet = getPreferenceScreen();
@@ -91,18 +97,9 @@
         mButtonCFNRc.setParentActivity(this, mButtonCFNRc.reason);
 
         mPreferences.add(mButtonCFU);
-        mPreferences.add(mButtonCFB);
-        mPreferences.add(mButtonCFNRy);
-
-        if (supportCFNRc) {
-            mPreferences.add(mButtonCFNRc);
-        } else {
-            // When CFNRc is not supported, mButtonCFNRc is grayed out from the menu.
-            // Default state for the preferences in this PreferenceScreen is disabled.
-            // Only preferences listed in the ArrayList mPreferences will be enabled.
-            // By not adding mButtonCFNRc to mPreferences it will be kept disabled.
-            if (DBG) Log.d(LOG_TAG, "onCreate: CFNRc is not supported, grey out the item.");
-        }
+        layoutCallForwardItem(supportCFB, mButtonCFB, prefSet);
+        layoutCallForwardItem(supportCFNRy, mButtonCFNRy, prefSet);
+        layoutCallForwardItem(supportCFNRc, mButtonCFNRc, prefSet);
 
         if (mCallForwardByUssd) {
             //the call forwarding ussd command's behavior is similar to the call forwarding when
@@ -130,6 +127,15 @@
         }
     }
 
+    private void layoutCallForwardItem(boolean support, CallForwardEditPreference preference,
+            PreferenceScreen prefSet) {
+        if (support) {
+            mPreferences.add(preference);
+        } else {
+            prefSet.removePreference(preference);
+        }
+    }
+
     @Override
     public void onResume() {
         super.onResume();
diff --git a/src/com/android/phone/IccNetworkDepersonalizationPanel.java b/src/com/android/phone/IccNetworkDepersonalizationPanel.java
index 7d854cd..a26225e 100644
--- a/src/com/android/phone/IccNetworkDepersonalizationPanel.java
+++ b/src/com/android/phone/IccNetworkDepersonalizationPanel.java
@@ -22,8 +22,6 @@
 import android.os.Handler;
 import android.os.Message;
 import android.os.PersistableBundle;
-import android.os.RemoteException;
-import android.os.ServiceManager;
 import android.telephony.CarrierConfigManager;
 import android.telephony.TelephonyManager;
 import android.text.Editable;
@@ -40,7 +38,6 @@
 import android.widget.TextView;
 
 import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.uicc.IccCardApplicationStatus;
 import com.android.internal.telephony.uicc.IccCardApplicationStatus.PersoSubState;
 
 /**
@@ -58,7 +55,7 @@
      * Ensures only a single instance of the dialog is visible.
      */
     private static boolean [] sShowingDialog =
-            new boolean[TelephonyManager.getDefault().getSimCount()];
+            new boolean[TelephonyManager.getDefault().getSupportedModemCount()];
 
     //debug constants
     private static final boolean DBG = false;
@@ -69,7 +66,8 @@
     private Phone mPhone;
     private int mPersoSubtype;
     private static IccNetworkDepersonalizationPanel [] sNdpPanel =
-            new IccNetworkDepersonalizationPanel[TelephonyManager.getDefault().getSimCount()];
+            new IccNetworkDepersonalizationPanel[
+                    TelephonyManager.getDefault().getSupportedModemCount()];
 
     //UI elements
     private EditText     mPinEntry;
@@ -94,6 +92,10 @@
      */
     public static void showDialog(Phone phone, int subType) {
         int phoneId = phone == null ? 0: phone.getPhoneId();
+        if (phoneId >= sShowingDialog.length) {
+            Log.e(TAG, "[IccNetworkDepersonalizationPanel] showDialog; invalid phoneId" + phoneId);
+            return;
+        }
         if (sShowingDialog[phoneId]) {
             Log.i(TAG, "[IccNetworkDepersonalizationPanel] - showDialog; skipped already shown.");
             return;
@@ -106,6 +108,10 @@
     }
 
     public static void dialogDismiss(int phoneId) {
+        if (phoneId >= sShowingDialog.length) {
+            Log.e(TAG, "[IccNetworkDepersonalizationPanel] - dismiss; invalid phoneId " + phoneId);
+            return;
+        }
         if (sNdpPanel[phoneId] != null && sShowingDialog[phoneId]) {
             sNdpPanel[phoneId].dismiss();
         }
@@ -222,6 +228,10 @@
         super.onStop();
         Log.i(TAG, "[IccNetworkDepersonalizationPanel] - showDialog; hiding dialog.");
         int phoneId = mPhone == null ? 0 : mPhone.getPhoneId();
+        if (phoneId >= sShowingDialog.length) {
+            Log.e(TAG, "[IccNetworkDepersonalizationPanel] - onStop; invalid phoneId " + phoneId);
+            return;
+        }
         sShowingDialog[phoneId] = false;
     }