Switching to PersistableBundle in carrier config API.

Part of this API involves persisting config bundles to avoid binding to
apps at critical moments (like boot). Regular bundles should not be
written to disk because they support object types that can lose their
meaning while the data is at rest.

In order to use PersistableBundle, we must either start with one or
filter unwanted types out of Bundle objects. Since the carrier config
API has no use for unsupported types, we chose to use PersistableBundle
everywhere.

Bug: 20268926
Change-Id: Ia85c1b2426907a5e6431095dbd3776213c7eb45d
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index a75bd3a..3178ae4 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -26,6 +26,7 @@
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.os.Bundle;
+import android.os.PersistableBundle;
 import android.os.UserHandle;
 import android.preference.CheckBoxPreference;
 import android.preference.ListPreference;
@@ -211,7 +212,8 @@
 
         mEnableVideoCalling = (CheckBoxPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
 
-        Bundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
+        PersistableBundle carrierConfig =
+                PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
 
         if (carrierConfig.getBoolean(CarrierConfigManager.BOOL_AUTO_RETRY_ENABLED)) {
             mButtonAutoRetry.setOnPreferenceChangeListener(this);
diff --git a/src/com/android/phone/CarrierConfigLoader.java b/src/com/android/phone/CarrierConfigLoader.java
index 53e67bd..75acefe 100644
--- a/src/com/android/phone/CarrierConfigLoader.java
+++ b/src/com/android/phone/CarrierConfigLoader.java
@@ -26,16 +26,16 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.pm.PackageManager;
 import android.content.ServiceConnection;
+import android.content.pm.PackageManager;
 import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteOpenHelper;
 import android.os.AsyncResult;
 import android.os.Binder;
-import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.Message;
+import android.os.PersistableBundle;
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.os.UserHandle;
@@ -75,9 +75,9 @@
     // The context for phone app, passed from PhoneGlobals.
     private Context mContext;
     // Carrier configs from default app, indexed by phoneID.
-    private Bundle[] mConfigFromDefaultApp;
+    private PersistableBundle[] mConfigFromDefaultApp;
     // Carrier configs from privileged carrier config app, indexed by phoneID.
-    private Bundle[] mConfigFromCarrierApp;
+    private PersistableBundle[] mConfigFromCarrierApp;
     // Service connection for binding to config app.
     private ConfigServiceConnection[] mServiceConnection;
 
@@ -117,7 +117,7 @@
             log("mHandler: " + msg.what + " phoneId: " + phoneId);
             CarrierIdentifier carrierId;
             ConfigServiceConnection conn;
-            Bundle config;
+            PersistableBundle config;
             switch (msg.what) {
                 case EVENT_CLEAR_CONFIG:
                     mConfigFromDefaultApp[phoneId] = null;
@@ -220,8 +220,8 @@
         mContext.registerReceiver(mReceiver, triggers);
 
         int numPhones = TelephonyManager.from(context).getPhoneCount();
-        mConfigFromDefaultApp = new Bundle[numPhones];
-        mConfigFromCarrierApp = new Bundle[numPhones];
+        mConfigFromDefaultApp = new PersistableBundle[numPhones];
+        mConfigFromCarrierApp = new PersistableBundle[numPhones];
         mServiceConnection = new ConfigServiceConnection[numPhones];
         // Make this service available through ServiceManager.
         ServiceManager.addService(Context.CARRIER_CONFIG_SERVICE, this);
@@ -291,11 +291,11 @@
     }
 
     @Override
-    public Bundle getConfigForSubId(int subId) {
+    public PersistableBundle getConfigForSubId(int subId) {
         int phoneId = SubscriptionManager.getPhoneId(subId);
-        Bundle retConfig = CarrierConfigManager.getDefaultConfig();
+        PersistableBundle retConfig = CarrierConfigManager.getDefaultConfig();
         if (SubscriptionManager.isValidPhoneId(phoneId)) {
-            Bundle config = mConfigFromDefaultApp[phoneId];
+            PersistableBundle config = mConfigFromDefaultApp[phoneId];
             if (config != null) retConfig.putAll(config);
             config = mConfigFromCarrierApp[phoneId];
             if (config != null) retConfig.putAll(config);
diff --git a/src/com/android/phone/CdmaCallOptions.java b/src/com/android/phone/CdmaCallOptions.java
index 9247173..7d8c991 100644
--- a/src/com/android/phone/CdmaCallOptions.java
+++ b/src/com/android/phone/CdmaCallOptions.java
@@ -24,6 +24,7 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
+import android.os.PersistableBundle;
 import android.preference.CheckBoxPreference;
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
@@ -50,7 +51,7 @@
                 getActionBar(), getResources(), R.string.labelCdmaMore_with_label);
 
         mButtonVoicePrivacy = (CheckBoxPreference) findPreference(BUTTON_VP_KEY);
-        Bundle carrierConfig;
+        PersistableBundle carrierConfig;
         if (subInfoHelper.hasSubId()) {
             carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(
                     subInfoHelper.getSubId());
diff --git a/src/com/android/phone/CdmaOptions.java b/src/com/android/phone/CdmaOptions.java
index fa3db13..76753fc 100644
--- a/src/com/android/phone/CdmaOptions.java
+++ b/src/com/android/phone/CdmaOptions.java
@@ -20,7 +20,7 @@
 import android.content.Intent;
 import android.content.res.Resources;
 import android.net.Uri;
-import android.os.Bundle;
+import android.os.PersistableBundle;
 import android.os.SystemProperties;
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
@@ -66,7 +66,7 @@
 
         mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
         boolean removedAPNExpand = false;
-        Bundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
+        PersistableBundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
         // Some CDMA carriers want the APN settings.
         if (!carrierConfig.getBoolean(CarrierConfigManager.BOOL_SHOW_APN_SETTING_CDMA) && mButtonAPNExpand != null) {
             mPrefScreen.removePreference(mButtonAPNExpand);
diff --git a/src/com/android/phone/EmergencyDialer.java b/src/com/android/phone/EmergencyDialer.java
index e25d91f..93760d2 100644
--- a/src/com/android/phone/EmergencyDialer.java
+++ b/src/com/android/phone/EmergencyDialer.java
@@ -29,6 +29,7 @@
 import android.media.ToneGenerator;
 import android.net.Uri;
 import android.os.Bundle;
+import android.os.PersistableBundle;
 import android.provider.Settings;
 import android.telecom.PhoneAccount;
 import android.telephony.CarrierConfigManager;
@@ -199,7 +200,7 @@
         mDialButton = findViewById(R.id.floating_action_button);
 
         // Check whether we should show the onscreen "Dial" button and co.
-        Bundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfig();
+        PersistableBundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfig();
         if (carrierConfig.getBoolean(CarrierConfigManager.BOOL_SHOW_ONSCREEN_DIAL_BUTTON)) {
             mDialButton.setOnClickListener(this);
         } else {
diff --git a/src/com/android/phone/GsmUmtsOptions.java b/src/com/android/phone/GsmUmtsOptions.java
index b8597f7..24dfb74 100644
--- a/src/com/android/phone/GsmUmtsOptions.java
+++ b/src/com/android/phone/GsmUmtsOptions.java
@@ -19,7 +19,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.res.Resources;
-import android.os.Bundle;
+import android.os.PersistableBundle;
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceScreen;
@@ -66,7 +66,7 @@
         } else {
             log("Not a CDMA phone");
             Resources res = mPrefActivity.getResources();
-            Bundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(mSubId);
+            PersistableBundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(mSubId);
 
             // Determine which options to display. For GSM these are defaulted to true in
             // CarrierConfigManager, but they maybe overriden by DefaultCarrierConfigService or a
diff --git a/src/com/android/phone/IccNetworkDepersonalizationPanel.java b/src/com/android/phone/IccNetworkDepersonalizationPanel.java
index 5f448a3..b241c3c 100644
--- a/src/com/android/phone/IccNetworkDepersonalizationPanel.java
+++ b/src/com/android/phone/IccNetworkDepersonalizationPanel.java
@@ -21,6 +21,7 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
+import android.os.PersistableBundle;
 import android.telephony.CarrierConfigManager;
 import android.text.Editable;
 import android.text.Spannable;
@@ -136,7 +137,7 @@
         // The "Dismiss" button is present in some (but not all) products,
         // based on the "sim_network_unlock_allow_dismiss" resource.
         mDismissButton = (Button) findViewById(R.id.ndp_dismiss);
-        Bundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfig();
+        PersistableBundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfig();
         if (carrierConfig.getBoolean(CarrierConfigManager.BOOL_SIM_NETWORK_UNLOCK_ALLOW_DISMISS)) {
             if (DBG) log("Enabling 'Dismiss' button...");
             mDismissButton.setVisibility(View.VISIBLE);
diff --git a/src/com/android/phone/InCallScreenShowActivation.java b/src/com/android/phone/InCallScreenShowActivation.java
index 3b5fe16..64d2aa6 100644
--- a/src/com/android/phone/InCallScreenShowActivation.java
+++ b/src/com/android/phone/InCallScreenShowActivation.java
@@ -23,6 +23,7 @@
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.os.Bundle;
+import android.os.PersistableBundle;
 import android.os.SystemProperties;
 import android.provider.Settings;
 import android.telephony.CarrierConfigManager;
@@ -72,7 +73,7 @@
 
         if (intent.getAction().equals(OtaUtils.ACTION_PERFORM_CDMA_PROVISIONING)) {
 
-            Bundle carrierConfig = app.getCarrierConfig();
+            PersistableBundle carrierConfig = app.getCarrierConfig();
             boolean usesHfa = carrierConfig.getBoolean(CarrierConfigManager.BOOL_USE_HFA_FOR_PROVISIONING);
             if (usesHfa) {
                 Log.i(LOG_TAG, "Starting Hfa from ACTION_PERFORM_CDMA_PROVISIONING");
diff --git a/src/com/android/phone/MobileNetworkSettings.java b/src/com/android/phone/MobileNetworkSettings.java
index 8d45002..73cc56d 100644
--- a/src/com/android/phone/MobileNetworkSettings.java
+++ b/src/com/android/phone/MobileNetworkSettings.java
@@ -40,6 +40,7 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
+import android.os.PersistableBundle;
 import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -57,10 +58,10 @@
 import android.util.Log;
 import android.view.MenuItem;
 import android.view.View;
-import android.widget.TabHost;
 import android.widget.TabHost.OnTabChangeListener;
 import android.widget.TabHost.TabContentFactory;
 import android.widget.TabHost.TabSpec;
+import android.widget.TabHost;
 
 /**
  * "Mobile network settings" screen.  This preference screen lets you
@@ -536,7 +537,8 @@
                 android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
                 preferredNetworkMode);
 
-        Bundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
+        PersistableBundle carrierConfig =
+                PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
         mIsGlobalCdma = isLteOnCdma
                 && carrierConfig.getBoolean(CarrierConfigManager.BOOL_SHOW_CDMA);
         int shouldHideCarrierSettings = android.provider.Settings.Global.getInt(
diff --git a/src/com/android/phone/NotificationMgr.java b/src/com/android/phone/NotificationMgr.java
index a6ccca9..54dfb75 100644
--- a/src/com/android/phone/NotificationMgr.java
+++ b/src/com/android/phone/NotificationMgr.java
@@ -27,7 +27,7 @@
 import android.content.pm.UserInfo;
 import android.content.res.Resources;
 import android.net.Uri;
-import android.os.Bundle;
+import android.os.PersistableBundle;
 import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -387,7 +387,7 @@
             }
 
             Resources res = mContext.getResources();
-            Bundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(
+            PersistableBundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(
                     mPhone.getSubId());
             Notification.Builder builder = new Notification.Builder(mContext);
             builder.setSmallIcon(resId)
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index fcef594..8b0b8a9 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -39,6 +39,7 @@
 import android.os.IBinder;
 import android.os.IPowerManager;
 import android.os.Message;
+import android.os.PersistableBundle;
 import android.os.PowerManager;
 import android.os.RemoteException;
 import android.os.ServiceManager;
@@ -511,11 +512,11 @@
         return mCM;
     }
 
-    /* package */ Bundle getCarrierConfig() {
+    /* package */ PersistableBundle getCarrierConfig() {
         return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubId());
     }
 
-    /* package */ Bundle getCarrierConfigForSubId(int subId) {
+    /* package */ PersistableBundle getCarrierConfigForSubId(int subId) {
         return configLoader.getConfigForSubId(subId);
     }
 
diff --git a/src/com/android/phone/vvm/omtp/SimChangeReceiver.java b/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
index df30ff0..917374c 100644
--- a/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
+++ b/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
@@ -18,7 +18,7 @@
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
-import android.os.Bundle;
+import android.os.PersistableBundle;
 import android.telephony.CarrierConfigManager;
 import android.telephony.SmsManager;
 import android.telephony.SubscriptionManager;
@@ -78,7 +78,7 @@
             return;
         }
 
-        Bundle carrierConfig = carrierConfigManager.getConfigForSubId(subId);
+        PersistableBundle carrierConfig = carrierConfigManager.getConfigForSubId(subId);
         if (carrierConfig == null) {
             Log.w(TAG, "Empty carrier config.");
             return;
@@ -107,4 +107,4 @@
                 OmtpConstants.PROTOCOL_VERSION1_1, null);
         messageSender.requestVvmActivation(null);
     }
-}
\ No newline at end of file
+}
diff --git a/src/com/android/services/telephony/CdmaConference.java b/src/com/android/services/telephony/CdmaConference.java
index 3423a3e..36eacea 100755
--- a/src/com/android/services/telephony/CdmaConference.java
+++ b/src/com/android/services/telephony/CdmaConference.java
@@ -18,7 +18,7 @@
 
 import android.content.Context;
 import android.content.res.Resources;
-import android.os.Bundle;
+import android.os.PersistableBundle;
 import android.telecom.Conference;
 import android.telecom.Connection;
 import android.telecom.PhoneAccountHandle;
@@ -169,7 +169,7 @@
         if (context != null) {
             CarrierConfigManager configManager = (CarrierConfigManager) context.getSystemService(
                     Context.CARRIER_CONFIG_SERVICE);
-            Bundle b = configManager.getConfig();
+            PersistableBundle b = configManager.getConfig();
             if (b != null) {
                 supportSwapAfterMerge = b.getBoolean(CarrierConfigManager.BOOL_SUPPORT_SWAP_AFTER_MERGE);
                 Log.d(this, "Current network support swap after call merged capability is "