config files has matching carrier id which passed to carrier Services.

this is to fix a race condition triggered from a back-to-back
sim refresh events. scenario is when we passed carrier id to
carrierconfigservices, sim status change to absent and thus we
passed unknown carrier id. later carrierconfigservices returns the
empty result for unknown carrier id, sim status change to loaded
and we persist the empty config to a cache file with correct
carrier id. The fix is make sure config file always has matching
carrier id as what passed to carrierconfig services.

Bug: 137951167
Test: Manual
Change-Id: I9960d167005b3e23d30692074d877eca08606f7d
(cherry picked from commit 49b1de39662eda1dbd2f9c668de5a64cafb72950)
Merged-in: I9960d167005b3e23d30692074d877eca08606f7d
(cherry picked from commit eb8b3ba033e042c6e93c0e1ab6fb72f1f6898a67)
(cherry picked from commit cd4a6376e1e6033679ed56a7a6ed9ba9eeeeb38c)
diff --git a/src/com/android/phone/CarrierConfigLoader.java b/src/com/android/phone/CarrierConfigLoader.java
index ed95a2c..d7c1a59 100644
--- a/src/com/android/phone/CarrierConfigLoader.java
+++ b/src/com/android/phone/CarrierConfigLoader.java
@@ -285,8 +285,8 @@
                                     }
                                     PersistableBundle config =
                                             resultData.getParcelable(KEY_CONFIG_BUNDLE);
-                                    saveConfigToXml(
-                                            mPlatformCarrierConfigPackage, phoneId, config);
+                                    saveConfigToXml(mPlatformCarrierConfigPackage, phoneId,
+                                        carrierId, config);
                                     mConfigFromDefaultApp[phoneId] = config;
                                     sendMessage(
                                             obtainMessage(
@@ -416,8 +416,8 @@
                                     }
                                     PersistableBundle config =
                                             resultData.getParcelable(KEY_CONFIG_BUNDLE);
-                                    saveConfigToXml(
-                                            getCarrierPackageForPhoneId(phoneId), phoneId, config);
+                                    saveConfigToXml(getCarrierPackageForPhoneId(phoneId), phoneId,
+                                        carrierId, config);
                                     mConfigFromCarrierApp[phoneId] = config;
                                     sendMessage(
                                             obtainMessage(
@@ -705,9 +705,11 @@
      *
      * @param packageName the name of the package from which we fetched this bundle.
      * @param phoneId the phone ID.
+     * @param carrierId contains all carrier-identifying information.
      * @param config the bundle to be written. Null will be treated as an empty bundle.
      */
-    private void saveConfigToXml(String packageName, int phoneId, PersistableBundle config) {
+    private void saveConfigToXml(String packageName, int phoneId, CarrierIdentifier carrierId,
+        PersistableBundle config) {
         if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
                 != TelephonyManager.SIM_STATE_LOADED) {
             loge("Skip save config because SIM records are not loaded.");
@@ -715,7 +717,7 @@
         }
 
         final String iccid = getIccIdForPhoneId(phoneId);
-        final int cid = getSpecificCarrierIdForPhoneId(phoneId);
+        final int cid = carrierId.getSpecificCarrierId();
         if (packageName == null || iccid == null) {
             loge("Cannot save config with null packageName or iccid.");
             return;