Add test API to override carrier config

Modify CarrierConfigLoader to accept an override bundle for CTS testing
usage.

Change-Id: I6f6409c9631dd16397a1850b88853d9ad1dd1dcd
Fixes: 118184943
Test: manually call api through shell cmd
diff --git a/src/com/android/phone/CarrierConfigLoader.java b/src/com/android/phone/CarrierConfigLoader.java
index f20d1ec..0b9b2e7 100644
--- a/src/com/android/phone/CarrierConfigLoader.java
+++ b/src/com/android/phone/CarrierConfigLoader.java
@@ -93,6 +93,8 @@
     private PersistableBundle[] mConfigFromDefaultApp;
     // Carrier configs from privileged carrier config app, indexed by phoneID.
     private PersistableBundle[] mConfigFromCarrierApp;
+    // Carrier configs that are provided via the override test API, indexed by phone ID.
+    private PersistableBundle[] mOverrideConfigs;
     // Service connection for binding to config app.
     private CarrierServiceConnection[] mServiceConnection;
     // Whether we have sent config change bcast for each phone id.
@@ -494,6 +496,7 @@
         int numPhones = TelephonyManager.from(context).getPhoneCount();
         mConfigFromDefaultApp = new PersistableBundle[numPhones];
         mConfigFromCarrierApp = new PersistableBundle[numPhones];
+        mOverrideConfigs = new PersistableBundle[numPhones];
         mServiceConnection = new CarrierServiceConnection[numPhones];
         mHasSentConfigChange = new boolean[numPhones];
         // Make this service available through ServiceManager.
@@ -782,9 +785,8 @@
         mHandler.sendMessage(mHandler.obtainMessage(EVENT_DO_FETCH_DEFAULT, phoneId, -1));
     }
 
-    @Override public
-    @NonNull
-    PersistableBundle getConfigForSubId(int subId, String callingPackage) {
+    @Override
+    public @NonNull PersistableBundle getConfigForSubId(int subId, String callingPackage) {
         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
                 mContext, subId, callingPackage, "getCarrierConfig")) {
             return new PersistableBundle();
@@ -803,11 +805,39 @@
                 retConfig.putAll(config);
                 retConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, true);
             }
+            config = mOverrideConfigs[phoneId];
+            if (config != null) {
+                retConfig.putAll(config);
+                retConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, true);
+            }
         }
         return retConfig;
     }
 
     @Override
+    public void overrideConfig(int subscriptionId, PersistableBundle overrides) {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.MODIFY_PHONE_STATE, null);
+        int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
+        if (!SubscriptionManager.isValidPhoneId(phoneId)) {
+            log("Ignore invalid phoneId: " + phoneId + " for subId: " + subscriptionId);
+            return;
+        }
+
+        if (overrides == null) {
+            mOverrideConfigs[phoneId] = new PersistableBundle();
+            return;
+        }
+
+        if (mOverrideConfigs[phoneId] == null) {
+            mOverrideConfigs[phoneId] = overrides;
+        } else {
+            mOverrideConfigs[phoneId].putAll(overrides);
+        }
+        broadcastConfigChangedIntent(phoneId);
+    }
+
+    @Override
     public void notifyConfigChangedForSubId(int subId) {
         int phoneId = SubscriptionManager.getPhoneId(subId);
         if (!SubscriptionManager.isValidPhoneId(phoneId)) {
@@ -881,6 +911,8 @@
             pw.println("");
             // display ConfigFromCarrierApp
             printConfig(mConfigFromCarrierApp[i], pw, "mConfigFromCarrierApp");
+            pw.println("");
+            printConfig(mOverrideConfigs[i], pw, "mOverrideConfigs");
         }
     }