Update ImsManager to use carrier configs.
Junda Liu [Tue, 23 Jun 2015 18:16:26 +0000 (11:16 -0700)]
Various carrier settings have been migrated to carrier config manager, so we update the call sites in ImsManager.

Bug: b/21878236
Change-Id: I20dcfba6e71f7db4961ff17f059e1a139c9958d7

src/java/com/android/ims/ImsManager.java

index 6183828..f8f2bf6 100644 (file)
@@ -27,6 +27,7 @@ import android.os.ServiceManager;
 import android.os.SystemProperties;
 import android.provider.Settings;
 import android.telecom.TelecomManager;
+import android.telephony.CarrierConfigManager;
 import android.telephony.Rlog;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
@@ -212,8 +213,8 @@ public class ImsManager {
      * supported.
      */
     public static boolean isNonTtyOrTtyOnVolteEnabled(Context context) {
-        if (context.getResources().getBoolean(
-                com.android.internal.R.bool.config_carrier_volte_tty_supported)) {
+        if (getBooleanCarrierConfig(context,
+                    CarrierConfigManager.KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL)) {
             return true;
         }
 
@@ -236,8 +237,9 @@ public class ImsManager {
                 android.provider.Settings.Global.VOLTE_FEATURE_DISABLED, 0) == 1;
 
         return context.getResources().getBoolean(
-                com.android.internal.R.bool.config_device_volte_available) && context.getResources()
-                .getBoolean(com.android.internal.R.bool.config_carrier_volte_available)
+                com.android.internal.R.bool.config_device_volte_available)
+                && getBooleanCarrierConfig(context,
+                        CarrierConfigManager.KEY_CARRIER_VOLTE_AVAILABLE_BOOL)
                 && !disabledByGlobalSetting;
     }
 
@@ -246,8 +248,8 @@ public class ImsManager {
      */
     public static boolean isVolteProvisionedOnDevice(Context context) {
         boolean isProvisioned = true;
-        if (context.getResources().getBoolean(
-                        com.android.internal.R.bool.config_carrier_volte_provisioned)) {
+        if (getBooleanCarrierConfig(context,
+                    CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL)) {
             isProvisioned = false; // disable on any error
             ImsManager mgr = ImsManager.getInstance(context,
                     SubscriptionManager.getDefaultVoicePhoneId());
@@ -281,8 +283,8 @@ public class ImsManager {
         return
                 context.getResources().getBoolean(
                         com.android.internal.R.bool.config_device_vt_available) &&
-                context.getResources().getBoolean(
-                        com.android.internal.R.bool.config_carrier_vt_available);
+                getBooleanCarrierConfig(context,
+                        CarrierConfigManager.KEY_CARRIER_VT_AVAILABLE_BOOL);
     }
 
     /**
@@ -317,8 +319,8 @@ public class ImsManager {
 
                 if (enabled) {
                     imsManager.turnOnIms();
-                } else if (context.getResources().getBoolean(
-                        com.android.internal.R.bool.imsServiceAllowTurnOff)
+                } else if (getBooleanCarrierConfig(context,
+                        CarrierConfigManager.KEY_CARRIER_ALLOW_TURNOFF_IMS_BOOL)
                         && (!isVolteEnabledByPlatform(context)
                         || !isEnhanced4gLteModeSettingEnabledByUser(context))) {
                     log("setWfcSetting() : imsServiceAllowTurnOff -> turnOffIms");
@@ -427,8 +429,8 @@ public class ImsManager {
         return
                context.getResources().getBoolean(
                        com.android.internal.R.bool.config_device_wfc_ims_available) &&
-               context.getResources().getBoolean(
-                       com.android.internal.R.bool.config_carrier_wfc_ims_available);
+               getBooleanCarrierConfig(context,
+                       CarrierConfigManager.KEY_CARRIER_WFC_IMS_AVAILABLE_BOOL);
     }
 
     private ImsManager(Context context, int phoneId) {
@@ -769,14 +771,32 @@ public class ImsManager {
                     ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
         }
 
-        if (!context.getResources().getBoolean(
-                com.android.internal.R.bool.config_carrier_volte_tty_supported)) {
+        if (!getBooleanCarrierConfig(context,
+                CarrierConfigManager.KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL)) {
             setAdvanced4GMode((uiTtyMode == TelecomManager.TTY_MODE_OFF) &&
                     isEnhanced4gLteModeSettingEnabledByUser(context));
         }
     }
 
     /**
+     * Get the boolean config from carrier config manager.
+     *
+     * @param context the context to get carrier service
+     * @param key config key defined in CarrierConfigManager
+     * @return boolean value of corresponding key.
+     */
+    private static boolean getBooleanCarrierConfig(Context context, String key) {
+        CarrierConfigManager configManager = (CarrierConfigManager) context.getSystemService(
+                Context.CARRIER_CONFIG_SERVICE);
+        if (configManager != null) {
+            return configManager.getConfig().getBoolean(key);
+        } else {
+            // Return static default defined in CarrierConfigManager.
+            return CarrierConfigManager.getDefaultConfig().getBoolean(key);
+        }
+    }
+
+    /**
      * Gets the call ID from the specified incoming call broadcast intent.
      *
      * @param incomingCallIntent the incoming call broadcast intent
@@ -914,8 +934,8 @@ public class ImsManager {
 
         if (turnOn) {
             turnOnIms();
-        } else if (mContext.getResources().getBoolean(
-                com.android.internal.R.bool.imsServiceAllowTurnOff)
+        } else if (getBooleanCarrierConfig(mContext,
+                CarrierConfigManager.KEY_CARRIER_ALLOW_TURNOFF_IMS_BOOL)
                 && (!isWfcEnabledByPlatform(mContext)
                 || !isWfcEnabledByUser(mContext))) {
             log("setAdvanced4GMode() : imsServiceAllowTurnOff -> turnOffIms");