Use system property for mobile network reset

This changed set default value based on system properties instead of
hard coding when reset network settings.

Test: manual test
Bug: 63145658
Change-Id: Ic49d5ad46e378f97f2579eebf12ccedb31af8454
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 16996c0..4fb2c9b 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -42,6 +42,7 @@
 import android.os.RemoteException;
 import android.os.ResultReceiver;
 import android.os.ServiceManager;
+import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.os.WorkSource;
@@ -196,6 +197,10 @@
     private static final int SELECT_P2 = 0;
     private static final int SELECT_P3 = 0x10;
 
+    private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
+    private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
+    private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
+
     /** The singleton instance. */
     private static PhoneInterfaceManager sInstance;
 
@@ -3461,21 +3466,10 @@
         try {
             if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
                     UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
-                // Enable data
-                setUserDataEnabled(subId, true);
-                // Set network selection mode to automatic
+                setUserDataEnabled(subId, getDefaultDataEnabled());
                 setNetworkSelectionModeAutomatic(subId);
-                // Set preferred mobile network type to the best available
-                String defaultNetwork = TelephonyManager.getTelephonyProperty(
-                        mSubscriptionController.getPhoneId(subId),
-                        "ro.telephony.default_network",
-                        null);
-                int networkType = !TextUtils.isEmpty(defaultNetwork)
-                        ? Integer.parseInt(defaultNetwork) : Phone.PREFERRED_NT_MODE;
-                setPreferredNetworkType(subId, networkType);
-                // Turn off roaming
-                mPhone.setDataRoamingEnabled(false);
-                // Remove IMSI encryption keys from Carrier DB.
+                setPreferredNetworkType(subId, getDefaultNetworkType(subId));
+                mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
                 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
             }
         } finally {
@@ -4149,4 +4143,39 @@
 
         phone.setRadioIndicationUpdateMode(filters, mode);
     }
+
+    /**
+     * Returns false if the mobile data is disabled by default, otherwise return true.
+     */
+    private boolean getDefaultDataEnabled() {
+        return "true".equalsIgnoreCase(
+                SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
+    }
+
+    /**
+     * Returns true if the data roaming is enabled by default, i.e the system property
+     * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
+     * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
+     */
+    private boolean getDefaultDataRoamingEnabled(int subId) {
+        final CarrierConfigManager configMgr = (CarrierConfigManager)
+                mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
+        boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
+                SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
+        isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
+                CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
+        return isDataRoamingEnabled;
+    }
+
+    /**
+     * Returns the default network type for the given {@code subId}, if the default network type is
+     * not set, return {@link Phone#PREFERRED_NT_MODE}.
+     */
+    private int getDefaultNetworkType(int subId) {
+        return Integer.parseInt(
+                TelephonyManager.getTelephonyProperty(
+                        mSubscriptionController.getPhoneId(subId),
+                        DEFAULT_NETWORK_MODE_PROPERTY_NAME,
+                        String.valueOf(Phone.PREFERRED_NT_MODE)));
+    }
 }