Merge "Disable emergency dialer shortcuts feature"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c2f88c5..ac8d18a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -90,6 +90,7 @@
     <protected-broadcast android:name= "android.telephony.action.SIM_APPLICATION_STATE_CHANGED" />
     <protected-broadcast android:name= "android.telephony.action.SIM_SLOT_STATUS_CHANGED" />
     <protected-broadcast android:name= "android.telephony.action.SUBSCRIPTION_CARRIER_IDENTITY_CHANGED" />
+    <protected-broadcast android:name= "android.telephony.action.SUBSCRIPTION_PRECISE_CARRIER_IDENTITY_CHANGED" />
 
     <uses-permission android:name="android.permission.BROADCAST_STICKY" />
     <uses-permission android:name="android.permission.CALL_PHONE" />
diff --git a/src/com/android/phone/CarrierConfigLoader.java b/src/com/android/phone/CarrierConfigLoader.java
index bddfd5f..8194c60 100644
--- a/src/com/android/phone/CarrierConfigLoader.java
+++ b/src/com/android/phone/CarrierConfigLoader.java
@@ -70,7 +70,6 @@
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.PrintWriter;
-import java.lang.Math;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -221,10 +220,8 @@
 
                 case EVENT_DO_FETCH_DEFAULT:
                 {
-                    final String iccid = getIccIdForPhoneId(phoneId);
-                    final String gid1 = getGid1ForPhoneId(phoneId);
                     final PersistableBundle config =
-                            restoreConfigFromXml(mPlatformCarrierConfigPackage, iccid, gid1);
+                            restoreConfigFromXml(mPlatformCarrierConfigPackage, phoneId);
                     if (config != null) {
                         log(
                                 "Loaded config from XML. package="
@@ -264,8 +261,6 @@
                         break;
                     }
                     final CarrierIdentifier carrierId = getCarrierIdForPhoneId(phoneId);
-                    final String iccid = getIccIdForPhoneId(phoneId);
-                    final String gid1 = getGid1ForPhoneId(phoneId);
                     // ResultReceiver callback will execute in this Handler's thread.
                     final ResultReceiver resultReceiver =
                             new ResultReceiver(this) {
@@ -286,8 +281,8 @@
                                     }
                                     PersistableBundle config =
                                             resultData.getParcelable(KEY_CONFIG_BUNDLE);
-                                    saveConfigToXml(mPlatformCarrierConfigPackage,
-                                            iccid, gid1, config);
+                                    saveConfigToXml(
+                                            mPlatformCarrierConfigPackage, phoneId, config);
                                     mConfigFromDefaultApp[phoneId] = config;
                                     sendMessage(
                                             obtainMessage(
@@ -342,10 +337,8 @@
                 case EVENT_DO_FETCH_CARRIER:
                 {
                     final String carrierPackageName = getCarrierPackageForPhoneId(phoneId);
-                    final String iccid = getIccIdForPhoneId(phoneId);
-                    final String gid1 = getGid1ForPhoneId(phoneId);
                     final PersistableBundle config =
-                            restoreConfigFromXml(carrierPackageName, iccid, gid1);
+                            restoreConfigFromXml(carrierPackageName, phoneId);
                     if (config != null) {
                         log(
                                 "Loaded config from XML. package="
@@ -384,8 +377,6 @@
                         break;
                     }
                     final CarrierIdentifier carrierId = getCarrierIdForPhoneId(phoneId);
-                    final String iccid = getIccIdForPhoneId(phoneId);
-                    final String gid1 = getGid1ForPhoneId(phoneId);
                     // ResultReceiver callback will execute in this Handler's thread.
                     final ResultReceiver resultReceiver =
                             new ResultReceiver(this) {
@@ -406,8 +397,8 @@
                                     }
                                     PersistableBundle config =
                                             resultData.getParcelable(KEY_CONFIG_BUNDLE);
-                                    saveConfigToXml(getCarrierPackageForPhoneId(phoneId),
-                                            iccid, gid1, config);
+                                    saveConfigToXml(
+                                            getCarrierPackageForPhoneId(phoneId), phoneId, config);
                                     mConfigFromCarrierApp[phoneId] = config;
                                     sendMessage(
                                             obtainMessage(
@@ -635,13 +626,19 @@
      * In case of errors or invalid input, no file will be written.
      *
      * @param packageName the name of the package from which we fetched this bundle.
-     * @param iccid the ICCID of the subscription for which this bundle was fetched.
-     * @param extras First 20 characters of gid1 of the subscription for which the bundle
-     *               was fetched.
+     * @param phoneId the phone ID.
      * @param config the bundle to be written. Null will be treated as an empty bundle.
      */
-    private void saveConfigToXml(String packageName, String iccid, String extras,
-            PersistableBundle config) {
+    private void saveConfigToXml(String packageName, int phoneId, PersistableBundle config) {
+        if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
+                != TelephonyManager.SIM_STATE_LOADED) {
+            log("Skip save config because SIM records are not loaded.");
+            return;
+        }
+
+        final String iccid = getIccIdForPhoneId(phoneId);
+        // extras is the first 20 characters of gid1
+        final String extras = getGid1ForPhoneId(phoneId);
         if (packageName == null || iccid == null) {
             loge("Cannot save config with null packageName or iccid.");
             return;
@@ -693,25 +690,31 @@
      * Reads a bundle from an XML file.
      *
      * This restores a bundle that was written with {@link #saveConfigToXml}. This returns the saved
-     * config bundle for the given package and ICCID.
+     * config bundle for the given package and phone ID.
      *
      * In case of errors, or if the saved config is from a different package version than the
      * current version, then null will be returned.
      *
      * @param packageName the name of the package from which we fetched this bundle.
-     * @param iccid the ICCID of the subscription for which this bundle was fetched.
-     * @param extras First 20 characters of gid1 of the subscription for which the bundle
-     *               was fetched.
+     * @param phoneId the phone ID.
      * @return the bundle from the XML file. Returns null if there is no saved config, the saved
      *         version does not match, or reading config fails.
      */
-    private PersistableBundle restoreConfigFromXml(String packageName, String iccid,
-            String extras) {
+    private PersistableBundle restoreConfigFromXml(String packageName, int phoneId) {
         final String version = getPackageVersion(packageName);
         if (version == null) {
             loge("Failed to get package version for: " + packageName);
             return null;
         }
+        if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
+                != TelephonyManager.SIM_STATE_LOADED) {
+            log("Skip restoring config because SIM records are not yet loaded.");
+            return null;
+        }
+
+        final String iccid = getIccIdForPhoneId(phoneId);
+        // extras is the first 20 characters of gid1
+        final String extras = getGid1ForPhoneId(phoneId);
         if (packageName == null || iccid == null) {
             loge("Cannot restore config with null packageName or iccid.");
             return null;
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index c44f7db..5401ddc 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -54,7 +54,6 @@
 import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
 import android.telecom.TelecomManager;
-import android.telephony.emergency.EmergencyNumber;
 import android.telephony.CarrierConfigManager;
 import android.telephony.CellInfo;
 import android.telephony.CellInfoGsm;
@@ -79,6 +78,7 @@
 import android.telephony.UssdResponse;
 import android.telephony.VisualVoicemailSmsFilterSettings;
 import android.telephony.cdma.CdmaCellLocation;
+import android.telephony.emergency.EmergencyNumber;
 import android.telephony.gsm.GsmCellLocation;
 import android.telephony.ims.aidl.IImsCapabilityCallback;
 import android.telephony.ims.aidl.IImsConfig;
@@ -2058,6 +2058,40 @@
         }
     }
 
+    @Override
+    public int getSubscriptionMNOCarrierId(int subId) {
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    @Override
+    public int getSubscriptionPreciseCarrierId(int subId) {
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
+                    : phone.getPreciseCarrierId();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    @Override
+    public String getSubscriptionPreciseCarrierName(int subId) {
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            return phone == null ? null : phone.getPreciseCarrierName();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
     //
     // Internal helper methods.
     //