Loading src/java/com/android/internal/telephony/data/DataSettingsManager.java +51 −4 Original line number Diff line number Diff line Loading @@ -20,10 +20,12 @@ import android.annotation.CallbackExecutor; import android.annotation.NonNull; import android.content.ContentResolver; import android.content.Context; import android.content.SharedPreferences; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.SystemProperties; import android.preference.PreferenceManager; import android.provider.Settings; import android.sysprop.TelephonyProperties; import android.telephony.CarrierConfigManager; Loading Loading @@ -185,7 +187,9 @@ public class DataSettingsManager extends Handler { public void handleMessage(Message msg) { switch (msg.what) { case EVENT_DATA_CONFIG_UPDATED: { // TODO: Add config changed logic if any settings are related to carrier configs if (mDataConfigManager.isConfigCarrierSpecific()) { setDefaultDataRoamingEnabled(); } break; } case EVENT_CALL_STATE_CHANGED: { Loading Loading @@ -515,9 +519,9 @@ public class DataSettingsManager extends Handler { } /** * Check whether data roaming is enabled by default, if either the * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} value and * system property "ro.com.android.dataroaming" are true. * Check whether data roaming is enabled by default. * This is true if {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} * or the system property "ro.com.android.dataroaming" are true. * @return {@code true} if data roaming is enabled by default and {@code false} otherwise. */ public boolean isDefaultDataRoamingEnabled() { Loading @@ -526,6 +530,49 @@ public class DataSettingsManager extends Handler { .isDataRoamingEnabledByDefault(); } /** * Set default value for {@link android.provider.Settings.Global#DATA_ROAMING} if the user * has not manually set the value. The default value is {@link #isDefaultDataRoamingEnabled()}. */ public void setDefaultDataRoamingEnabled() { // For SSSS, this is a per-phone property from DATA_ROAMING_IS_USER_SETTING_KEY. // For DSDS, this is a per-sub property from Settings.Global.DATA_ROAMING + subId. // If the user has not manually set the value, use the default from carrier configurations. boolean useCarrierSpecificDefault = false; if (mPhone.getContext().getSystemService(TelephonyManager.class).getSimCount() != 1) { String setting = Settings.Global.DATA_ROAMING + mPhone.getSubId(); try { Settings.Global.getInt(mResolver, setting); } catch (Settings.SettingNotFoundException ex) { // For multi-SIM phones, use the default value if uninitialized. useCarrierSpecificDefault = true; } } else if (!isDataRoamingFromUserAction()) { // For single-SIM phones, use the default value if user action is not set. useCarrierSpecificDefault = true; } log("setDefaultDataRoamingEnabled: useCarrierSpecificDefault=" + useCarrierSpecificDefault); if (useCarrierSpecificDefault) { boolean defaultVal = isDefaultDataRoamingEnabled(); setDataRoamingEnabled(defaultVal); } } /** * Get whether the user has manually enabled or disabled data roaming from settings. * @return {@code true} if the user has enabled data roaming and {@code false} if they have not. */ private boolean isDataRoamingFromUserAction() { final SharedPreferences sp = PreferenceManager .getDefaultSharedPreferences(mPhone.getContext()); // Since we don't want to unset user preferences after a system update, default to true if // the preference does not exist and set it to false explicitly from factory reset. if (!sp.contains(Phone.DATA_ROAMING_IS_USER_SETTING_KEY)) { sp.edit().putBoolean(Phone.DATA_ROAMING_IS_USER_SETTING_KEY, false).commit(); } return sp.getBoolean(Phone.DATA_ROAMING_IS_USER_SETTING_KEY, true); } private @NonNull DataEnabledOverride getDataEnabledOverride() { return new DataEnabledOverride(SubscriptionController.getInstance() .getDataEnabledOverrideRules(mSubId)); Loading tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -1436,6 +1436,9 @@ public class DataNetworkControllerTest extends TelephonyTest { CarrierConfigManager.KEY_CARRIER_METERED_ROAMING_APN_TYPES_STRINGS, new String[]{"default", "dun", "supl"}); carrierConfigChanged(); // Manually set data roaming to false in case ro.com.android.dataroaming is true. // TODO(b/232575718): Figure out a way to mock ro.com.android.dataroaming for tests. mDataNetworkControllerUT.getDataSettingsManager().setDataRoamingEnabled(false); // Device is roaming serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING); Loading Loading
src/java/com/android/internal/telephony/data/DataSettingsManager.java +51 −4 Original line number Diff line number Diff line Loading @@ -20,10 +20,12 @@ import android.annotation.CallbackExecutor; import android.annotation.NonNull; import android.content.ContentResolver; import android.content.Context; import android.content.SharedPreferences; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.SystemProperties; import android.preference.PreferenceManager; import android.provider.Settings; import android.sysprop.TelephonyProperties; import android.telephony.CarrierConfigManager; Loading Loading @@ -185,7 +187,9 @@ public class DataSettingsManager extends Handler { public void handleMessage(Message msg) { switch (msg.what) { case EVENT_DATA_CONFIG_UPDATED: { // TODO: Add config changed logic if any settings are related to carrier configs if (mDataConfigManager.isConfigCarrierSpecific()) { setDefaultDataRoamingEnabled(); } break; } case EVENT_CALL_STATE_CHANGED: { Loading Loading @@ -515,9 +519,9 @@ public class DataSettingsManager extends Handler { } /** * Check whether data roaming is enabled by default, if either the * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} value and * system property "ro.com.android.dataroaming" are true. * Check whether data roaming is enabled by default. * This is true if {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} * or the system property "ro.com.android.dataroaming" are true. * @return {@code true} if data roaming is enabled by default and {@code false} otherwise. */ public boolean isDefaultDataRoamingEnabled() { Loading @@ -526,6 +530,49 @@ public class DataSettingsManager extends Handler { .isDataRoamingEnabledByDefault(); } /** * Set default value for {@link android.provider.Settings.Global#DATA_ROAMING} if the user * has not manually set the value. The default value is {@link #isDefaultDataRoamingEnabled()}. */ public void setDefaultDataRoamingEnabled() { // For SSSS, this is a per-phone property from DATA_ROAMING_IS_USER_SETTING_KEY. // For DSDS, this is a per-sub property from Settings.Global.DATA_ROAMING + subId. // If the user has not manually set the value, use the default from carrier configurations. boolean useCarrierSpecificDefault = false; if (mPhone.getContext().getSystemService(TelephonyManager.class).getSimCount() != 1) { String setting = Settings.Global.DATA_ROAMING + mPhone.getSubId(); try { Settings.Global.getInt(mResolver, setting); } catch (Settings.SettingNotFoundException ex) { // For multi-SIM phones, use the default value if uninitialized. useCarrierSpecificDefault = true; } } else if (!isDataRoamingFromUserAction()) { // For single-SIM phones, use the default value if user action is not set. useCarrierSpecificDefault = true; } log("setDefaultDataRoamingEnabled: useCarrierSpecificDefault=" + useCarrierSpecificDefault); if (useCarrierSpecificDefault) { boolean defaultVal = isDefaultDataRoamingEnabled(); setDataRoamingEnabled(defaultVal); } } /** * Get whether the user has manually enabled or disabled data roaming from settings. * @return {@code true} if the user has enabled data roaming and {@code false} if they have not. */ private boolean isDataRoamingFromUserAction() { final SharedPreferences sp = PreferenceManager .getDefaultSharedPreferences(mPhone.getContext()); // Since we don't want to unset user preferences after a system update, default to true if // the preference does not exist and set it to false explicitly from factory reset. if (!sp.contains(Phone.DATA_ROAMING_IS_USER_SETTING_KEY)) { sp.edit().putBoolean(Phone.DATA_ROAMING_IS_USER_SETTING_KEY, false).commit(); } return sp.getBoolean(Phone.DATA_ROAMING_IS_USER_SETTING_KEY, true); } private @NonNull DataEnabledOverride getDataEnabledOverride() { return new DataEnabledOverride(SubscriptionController.getInstance() .getDataEnabledOverrideRules(mSubId)); Loading
tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -1436,6 +1436,9 @@ public class DataNetworkControllerTest extends TelephonyTest { CarrierConfigManager.KEY_CARRIER_METERED_ROAMING_APN_TYPES_STRINGS, new String[]{"default", "dun", "supl"}); carrierConfigChanged(); // Manually set data roaming to false in case ro.com.android.dataroaming is true. // TODO(b/232575718): Figure out a way to mock ro.com.android.dataroaming for tests. mDataNetworkControllerUT.getDataSettingsManager().setDataRoamingEnabled(false); // Device is roaming serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE, NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING); Loading