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)
(cherry picked from commit e0d33cd4021d7c28602018b605f881610e75974a)
diff --git a/src/com/android/phone/ b/src/com/android/phone/
index ed95a2c..d7c1a59 100644
--- a/src/com/android/phone/
+++ b/src/com/android/phone/
@@ -285,8 +285,8 @@
                                     PersistableBundle config =
-                                    saveConfigToXml(
-                                            mPlatformCarrierConfigPackage, phoneId, config);
+                                    saveConfigToXml(mPlatformCarrierConfigPackage, phoneId,
+                                        carrierId, config);
                                     mConfigFromDefaultApp[phoneId] = config;
@@ -416,8 +416,8 @@
                                     PersistableBundle config =
-                                    saveConfigToXml(
-                                            getCarrierPackageForPhoneId(phoneId), phoneId, config);
+                                    saveConfigToXml(getCarrierPackageForPhoneId(phoneId), phoneId,
+                                        carrierId, config);
                                     mConfigFromCarrierApp[phoneId] = config;
@@ -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.");