Merge "Fix the ECBM dialog is not shown issue" into rvc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 0f316ea..425440a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -445,6 +445,9 @@
             Handler for EuiccManager's resolution intents. These are locked down so that only
             privileged processes can start them, which means we can trust the Intent used to start
             it (which contains a description of the next step to perform after resolution).
+
+            If modified, also change EuiccController#RESOLUTION_ACTIVITY_PACKAGE_NAME and
+            EuiccController#RESOLUTION_ACTIVITY_CLASS_NAME
         -->
         <activity android:name=".euicc.EuiccResolutionUiDispatcherActivity"
             android:permission="android.permission.CALL_PRIVILEGED">
diff --git a/res/xml/carrier_ss_string.xml b/res/xml/carrier_ss_string.xml
index 826f0ea..29de13a 100644
--- a/res/xml/carrier_ss_string.xml
+++ b/res/xml/carrier_ss_string.xml
@@ -21,7 +21,7 @@
 
      If developer need to define ussd command by specific carrier, developer can add new xml and
      xml is named carrier_ss_string_carrierId.xml. The carrierId is a number and is defined in
-     <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/carrier_list.textpb">here</a>
+     <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/latest_carrier_id/carrier_list.textpb">here</a>
      For example: carrier_ss_string_850.xml
 
      The tags define as below:
diff --git a/res/xml/carrier_ss_string_850.xml b/res/xml/carrier_ss_string_850.xml
index 86d5743..01eeee5 100644
--- a/res/xml/carrier_ss_string_850.xml
+++ b/res/xml/carrier_ss_string_850.xml
@@ -15,7 +15,7 @@
 -->
 <!-- This xml is the command's structure about supplementary service by ussd command for
      carrier id 850.
-     <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/carrier_list.textpb">here</a>
+     <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/latest_carrier_id/carrier_list.textpb">here</a>
      The introduction is same as carrier_ss_string.xml. @see carrier_ss_string_carrierId.xml
 -->
 
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;
     }
 
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index d265e6b..b045c0f 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -5015,6 +5015,22 @@
     }
 
     /**
+     * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
+     */
+    public void unregisterImsFeatureCallback(int slotId, int featureType,
+            IImsServiceFeatureCallback callback) {
+        enforceModifyPermission();
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (mImsResolver == null) return;
+            mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    /**
      * Returns the {@link IImsRegistration} structure associated with the slotId and feature
      * specified or null if IMS is not supported on the slot specified.
      */