Loading src/java/com/android/internal/telephony/dataconnection/DataEnabledSettings.java +95 −12 Original line number Diff line number Diff line Loading @@ -17,10 +17,22 @@ package com.android.internal.telephony.dataconnection; import android.content.ContentResolver; import android.os.Handler; import android.os.RegistrantList; import android.os.SystemProperties; import android.provider.Settings; import android.telephony.Rlog; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.util.LocalLog; import android.util.Pair; import com.android.internal.telephony.Phone; import java.io.FileDescriptor; import java.io.PrintWriter; /** * The class to hold different data enabled/disabled settings. Also it allows clients to register * for overall data enabled setting changed event. Loading @@ -28,6 +40,8 @@ import android.util.Pair; */ public class DataEnabledSettings { private static final String LOG_TAG = "DataEnabledSettings"; public static final int REASON_REGISTERED = 0; public static final int REASON_INTERNAL_DATA_ENABLED = 1; Loading @@ -44,12 +58,6 @@ public class DataEnabledSettings { */ private boolean mInternalDataEnabled = true; /** * responds to public (user) API to enable/disable data use independent of * mInternalDataEnabled and requests for APN access persisted */ private boolean mUserDataEnabled = true; /** * Flag indicating data allowed by network policy manager or not. */ Loading @@ -61,16 +69,29 @@ public class DataEnabledSettings { */ private boolean mCarrierDataEnabled = true; private Phone mPhone = null; private ContentResolver mResolver = null; private final RegistrantList mDataEnabledChangedRegistrants = new RegistrantList(); private final LocalLog mSettingChangeLocalLog = new LocalLog(50); @Override public String toString() { return "[mInternalDataEnabled=" + mInternalDataEnabled + ", mUserDataEnabled=" + mUserDataEnabled + ", mPolicyDataEnabled=" + mPolicyDataEnabled return "[mInternalDataEnabled=" + mInternalDataEnabled + ", isUserDataEnabled=" + isUserDataEnabled() + ", isProvisioningDataEnabled=" + isProvisioningDataEnabled() + ", mPolicyDataEnabled=" + mPolicyDataEnabled + ", mCarrierDataEnabled=" + mCarrierDataEnabled + "]"; } public DataEnabledSettings(Phone phone) { mPhone = phone; mResolver = mPhone.getContext().getContentResolver(); } public synchronized void setInternalDataEnabled(boolean enabled) { localLog("InternalDataEnabled", enabled); boolean prevDataEnabled = isDataEnabled(); mInternalDataEnabled = enabled; if (prevDataEnabled != isDataEnabled()) { Loading @@ -82,17 +103,37 @@ public class DataEnabledSettings { } public synchronized void setUserDataEnabled(boolean enabled) { localLog("UserDataEnabled", enabled); boolean prevDataEnabled = isDataEnabled(); mUserDataEnabled = enabled; Settings.Global.putInt(mResolver, getMobileDataSettingName(), enabled ? 1 : 0); if (prevDataEnabled != isDataEnabled()) { notifyDataEnabledChanged(!prevDataEnabled, REASON_USER_DATA_ENABLED); } } public synchronized boolean isUserDataEnabled() { return mUserDataEnabled; boolean defaultVal = "true".equalsIgnoreCase(SystemProperties.get( "ro.com.android.mobiledata", "true")); return (Settings.Global.getInt(mResolver, getMobileDataSettingName(), defaultVal ? 1 : 0) != 0); } private String getMobileDataSettingName() { // For single SIM phones, this is a per phone property. Or if it's invalid subId, we // read default setting. int subId = mPhone.getSubId(); if (TelephonyManager.getDefault().getSimCount() == 1 || !SubscriptionManager.isValidSubscriptionId(subId)) { return Settings.Global.MOBILE_DATA; } else { return Settings.Global.MOBILE_DATA + mPhone.getSubId(); } } public synchronized void setPolicyDataEnabled(boolean enabled) { localLog("PolicyDataEnabled", enabled); boolean prevDataEnabled = isDataEnabled(); mPolicyDataEnabled = enabled; if (prevDataEnabled != isDataEnabled()) { Loading @@ -104,6 +145,7 @@ public class DataEnabledSettings { } public synchronized void setCarrierDataEnabled(boolean enabled) { localLog("CarrierDataEnabled", enabled); boolean prevDataEnabled = isDataEnabled(); mCarrierDataEnabled = enabled; if (prevDataEnabled != isDataEnabled()) { Loading @@ -115,8 +157,36 @@ public class DataEnabledSettings { } public synchronized boolean isDataEnabled() { return (mInternalDataEnabled && mUserDataEnabled && mPolicyDataEnabled && mCarrierDataEnabled); if (isProvisioning()) { return isProvisioningDataEnabled(); } else { return mInternalDataEnabled && isUserDataEnabled() && mPolicyDataEnabled && mCarrierDataEnabled; } } public boolean isProvisioning() { return Settings.Global.getInt(mResolver, Settings.Global.DEVICE_PROVISIONED, 0) == 0; } /** * In provisioning, we might want to have enable mobile data during provisioning. It depends * on value of Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED which is set by * setupwizard. It only matters if it's in provisioning stage. * @return whether we are enabling userData during provisioning stage. */ public boolean isProvisioningDataEnabled() { final String prov_property = SystemProperties.get("ro.com.android.prov_mobiledata", "false"); boolean retVal = "true".equalsIgnoreCase(prov_property); final int prov_mobile_data = Settings.Global.getInt(mResolver, Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED, retVal ? 1 : 0); retVal = prov_mobile_data != 0; log("getDataEnabled during provisioning retVal=" + retVal + " - (" + prov_property + ", " + prov_mobile_data + ")"); return retVal; } private void notifyDataEnabledChanged(boolean enabled, int reason) { Loading @@ -131,4 +201,17 @@ public class DataEnabledSettings { public void unregisterForDataEnabledChanged(Handler h) { mDataEnabledChangedRegistrants.remove(h); } private void log(String s) { Rlog.d(LOG_TAG, "[" + mPhone.getPhoneId() + "]" + s); } private void localLog(String name, boolean value) { mSettingChangeLocalLog.log(name + " change to " + value); } protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println(" DataEnabledSettings="); mSettingChangeLocalLog.dump(fd, pw, args); } } src/java/com/android/internal/telephony/dataconnection/DcTracker.java +19 −65 Original line number Diff line number Diff line Loading @@ -126,7 +126,7 @@ public class DcTracker extends Handler { private String mRequestedApnType = PhoneConstants.APN_TYPE_DEFAULT; // All data enabling/disabling related settings private final DataEnabledSettings mDataEnabledSettings = new DataEnabledSettings(); private final DataEnabledSettings mDataEnabledSettings; /** Loading Loading @@ -612,8 +612,8 @@ public class DcTracker extends Handler { filter.addAction(INTENT_DATA_STALL_ALARM); filter.addAction(INTENT_PROVISIONING_APN_ALARM); filter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); // TODO - redundent with update call below? mDataEnabledSettings.setUserDataEnabled(getDataEnabled()); mDataEnabledSettings = new DataEnabledSettings(phone); mPhone.getContext().registerReceiver(mIntentReceiver, filter, null, mPhone); Loading Loading @@ -664,6 +664,7 @@ public class DcTracker extends Handler { mDataConnectionTracker = null; mProvisionActionName = null; mSettingsObserver = new SettingsObserver(null, this); mDataEnabledSettings = null; } public void registerServiceStateTrackerEvents() { Loading Loading @@ -803,16 +804,6 @@ public class DcTracker extends Handler { synchronized (mDataEnabledSettings) { if (mDataEnabledSettings.isUserDataEnabled() != enabled) { mDataEnabledSettings.setUserDataEnabled(enabled); //TODO: We should move the followings into DataEnabledSettings class. // For single SIM phones, this is a per phone property. if (TelephonyManager.getDefault().getSimCount() == 1) { Settings.Global.putInt(mResolver, Settings.Global.MOBILE_DATA, enabled ? 1 : 0); } else { int phoneSubId = mPhone.getSubId(); Settings.Global.putInt(mResolver, Settings.Global.MOBILE_DATA + phoneSubId, enabled ? 1 : 0); } if (!getDataRoamingEnabled() && mPhone.getServiceState().getDataRoaming()) { if (enabled) { notifyOffApnsOfAvailability(Phone.REASON_ROAMING_ON); Loading Loading @@ -883,12 +874,10 @@ public class DcTracker extends Handler { } private void onDeviceProvisionedChange() { if (getDataEnabled()) { mDataEnabledSettings.setUserDataEnabled(true); if (isDataEnabled()) { reevaluateDataConnections(); onTrySetupData(Phone.REASON_DATA_ENABLED); } else { mDataEnabledSettings.setUserDataEnabled(false); onCleanUpAllConnections(Phone.REASON_DATA_SPECIFIC_DISABLED); } } Loading Loading @@ -2587,45 +2576,12 @@ public class DcTracker extends Handler { /** * Return current {@link android.provider.Settings.Global#MOBILE_DATA} value. */ //TODO: Merge this into DataSettings. And probably should rename to getUserDataEnabled(). public boolean getDataEnabled() { final int device_provisioned = Settings.Global.getInt(mResolver, Settings.Global.DEVICE_PROVISIONED, 0); boolean retVal = "true".equalsIgnoreCase(SystemProperties.get( "ro.com.android.mobiledata", "true")); if (TelephonyManager.getDefault().getSimCount() == 1) { retVal = Settings.Global.getInt(mResolver, Settings.Global.MOBILE_DATA, retVal ? 1 : 0) != 0; if (mDataEnabledSettings.isProvisioning()) { return mDataEnabledSettings.isProvisioningDataEnabled(); } else { int phoneSubId = mPhone.getSubId(); try { retVal = TelephonyManager.getIntWithSubId(mResolver, Settings.Global.MOBILE_DATA, phoneSubId) != 0; } catch (SettingNotFoundException e) { // use existing retVal } } if (VDBG) log("getDataEnabled: retVal=" + retVal); if (device_provisioned == 0) { // device is still getting provisioned - use whatever setting they // want during this process // // use the normal data_enabled setting (retVal, determined above) // as the default if nothing else is set final String prov_property = SystemProperties.get("ro.com.android.prov_mobiledata", retVal ? "true" : "false"); retVal = "true".equalsIgnoreCase(prov_property); final int prov_mobile_data = Settings.Global.getInt(mResolver, Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED, retVal ? 1 : 0); retVal = prov_mobile_data != 0; log("getDataEnabled during provisioning retVal=" + retVal + " - (" + prov_property + ", " + prov_mobile_data + ")"); return mDataEnabledSettings.isUserDataEnabled(); } return retVal; } /** Loading Loading @@ -2666,19 +2622,17 @@ public class DcTracker extends Handler { boolean isDataRoamingEnabled; final int phoneSubId = mPhone.getSubId(); try { // For single SIM phones, this is a per phone property. if (TelephonyManager.getDefault().getSimCount() == 1) { isDataRoamingEnabled = Settings.Global.getInt(mResolver, Settings.Global.DATA_ROAMING, getDefaultDataRoamingEnabled() ? 1 : 0) != 0; Settings.Global.DATA_ROAMING, getDefaultDataRoamingEnabled() ? 1 : 0) != 0; } else { isDataRoamingEnabled = TelephonyManager.getIntWithSubId(mResolver, Settings.Global.DATA_ROAMING, phoneSubId) != 0; } } catch (SettingNotFoundException snfe) { if (DBG) log("getDataRoamingEnabled: SettingNofFoundException snfe=" + snfe); isDataRoamingEnabled = getDefaultDataRoamingEnabled(); isDataRoamingEnabled = Settings.Global.getInt(mResolver, Settings.Global.DATA_ROAMING + phoneSubId, getDefaultDataRoamingEnabled() ? 1 : 0) != 0; } if (VDBG) { log("getDataRoamingEnabled: phoneSubId=" + phoneSubId + " isDataRoamingEnabled=" + isDataRoamingEnabled); Loading Loading @@ -4070,7 +4024,6 @@ public class DcTracker extends Handler { log("update(): Active DDS, register for all events now!"); onUpdateIcc(); mDataEnabledSettings.setUserDataEnabled(getDataEnabled()); mAutoAttachOnCreation.set(false); ((GsmCdmaPhone)mPhone).updateCurrentCarrierInProvider(); Loading Loading @@ -4268,6 +4221,7 @@ public class DcTracker extends Handler { pw.println(" getOverallState=" + getOverallState()); pw.println(" mDataConnectionAsyncChannels=%s\n" + mDataConnectionAcHashMap); pw.println(" mAttached=" + mAttached.get()); mDataEnabledSettings.dump(fd, pw, args); pw.flush(); } Loading tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -461,6 +461,9 @@ public abstract class TelephonyTest { mSST.mSS = mServiceState; mServiceManagerMockedServices.put("connectivity_metrics_logger", mConnMetLoggerBinder); //SIM doReturn(1).when(mTelephonyManager).getSimCount(); setReady(false); } Loading tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java +47 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import static org.mockito.Mockito.verify; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.database.Cursor; Loading Loading @@ -805,6 +806,9 @@ public class DcTrackerTest extends TelephonyTest { @MediumTest public void testDDSResetAutoAttach() throws Exception { ContentResolver resolver = mContext.getContentResolver(); Settings.Global.putInt(resolver, Settings.Global.DEVICE_PROVISIONED, 1); mDct.setDataEnabled(true); mContextFixture.putBooleanResource( Loading Loading @@ -1225,4 +1229,47 @@ public class DcTrackerTest extends TelephonyTest { assertEquals(FAKE_APN4, mDct.getActiveApnString(PhoneConstants.APN_TYPE_DEFAULT)); assertEquals(DctConstants.State.CONNECTED, mDct.getOverallState()); } // Test provisioning @Test @SmallTest public void testDataEnableInProvisioning() throws Exception { // Initial state is: userData enabled, provisioned. ContentResolver resolver = mContext.getContentResolver(); Settings.Global.putInt(resolver, Settings.Global.MOBILE_DATA, 1); Settings.Global.putInt(resolver, Settings.Global.DEVICE_PROVISIONED, 1); Settings.Global.putInt(resolver, Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED, 1); assertEquals(1, Settings.Global.getInt(resolver, Settings.Global.MOBILE_DATA)); assertTrue(mDct.isDataEnabled()); // The api should rename to getUserDataEnabled(); assertTrue(mDct.getDataEnabled()); mDct.setDataEnabled(false); waitForMs(200); assertEquals(0, Settings.Global.getInt(resolver, Settings.Global.MOBILE_DATA)); assertFalse(mDct.isDataEnabled()); // The api should rename to getUserDataEnabled(); assertFalse(mDct.getDataEnabled()); // Changing provisioned to 0. Settings.Global.putInt(resolver, Settings.Global.DEVICE_PROVISIONED, 0); assertTrue(mDct.isDataEnabled()); // The api should rename to getUserDataEnabled(); assertTrue(mDct.getDataEnabled()); // Enable user data during provisioning. It should write to // Settings.Global.MOBILE_DATA and keep data enabled when provisioned. mDct.setDataEnabled(true); Settings.Global.putInt(resolver, Settings.Global.DEVICE_PROVISIONED, 1); waitForMs(200); assertTrue(mDct.isDataEnabled()); assertTrue(mDct.getDataEnabled()); assertEquals(1, Settings.Global.getInt(resolver, Settings.Global.MOBILE_DATA)); } } Loading
src/java/com/android/internal/telephony/dataconnection/DataEnabledSettings.java +95 −12 Original line number Diff line number Diff line Loading @@ -17,10 +17,22 @@ package com.android.internal.telephony.dataconnection; import android.content.ContentResolver; import android.os.Handler; import android.os.RegistrantList; import android.os.SystemProperties; import android.provider.Settings; import android.telephony.Rlog; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.util.LocalLog; import android.util.Pair; import com.android.internal.telephony.Phone; import java.io.FileDescriptor; import java.io.PrintWriter; /** * The class to hold different data enabled/disabled settings. Also it allows clients to register * for overall data enabled setting changed event. Loading @@ -28,6 +40,8 @@ import android.util.Pair; */ public class DataEnabledSettings { private static final String LOG_TAG = "DataEnabledSettings"; public static final int REASON_REGISTERED = 0; public static final int REASON_INTERNAL_DATA_ENABLED = 1; Loading @@ -44,12 +58,6 @@ public class DataEnabledSettings { */ private boolean mInternalDataEnabled = true; /** * responds to public (user) API to enable/disable data use independent of * mInternalDataEnabled and requests for APN access persisted */ private boolean mUserDataEnabled = true; /** * Flag indicating data allowed by network policy manager or not. */ Loading @@ -61,16 +69,29 @@ public class DataEnabledSettings { */ private boolean mCarrierDataEnabled = true; private Phone mPhone = null; private ContentResolver mResolver = null; private final RegistrantList mDataEnabledChangedRegistrants = new RegistrantList(); private final LocalLog mSettingChangeLocalLog = new LocalLog(50); @Override public String toString() { return "[mInternalDataEnabled=" + mInternalDataEnabled + ", mUserDataEnabled=" + mUserDataEnabled + ", mPolicyDataEnabled=" + mPolicyDataEnabled return "[mInternalDataEnabled=" + mInternalDataEnabled + ", isUserDataEnabled=" + isUserDataEnabled() + ", isProvisioningDataEnabled=" + isProvisioningDataEnabled() + ", mPolicyDataEnabled=" + mPolicyDataEnabled + ", mCarrierDataEnabled=" + mCarrierDataEnabled + "]"; } public DataEnabledSettings(Phone phone) { mPhone = phone; mResolver = mPhone.getContext().getContentResolver(); } public synchronized void setInternalDataEnabled(boolean enabled) { localLog("InternalDataEnabled", enabled); boolean prevDataEnabled = isDataEnabled(); mInternalDataEnabled = enabled; if (prevDataEnabled != isDataEnabled()) { Loading @@ -82,17 +103,37 @@ public class DataEnabledSettings { } public synchronized void setUserDataEnabled(boolean enabled) { localLog("UserDataEnabled", enabled); boolean prevDataEnabled = isDataEnabled(); mUserDataEnabled = enabled; Settings.Global.putInt(mResolver, getMobileDataSettingName(), enabled ? 1 : 0); if (prevDataEnabled != isDataEnabled()) { notifyDataEnabledChanged(!prevDataEnabled, REASON_USER_DATA_ENABLED); } } public synchronized boolean isUserDataEnabled() { return mUserDataEnabled; boolean defaultVal = "true".equalsIgnoreCase(SystemProperties.get( "ro.com.android.mobiledata", "true")); return (Settings.Global.getInt(mResolver, getMobileDataSettingName(), defaultVal ? 1 : 0) != 0); } private String getMobileDataSettingName() { // For single SIM phones, this is a per phone property. Or if it's invalid subId, we // read default setting. int subId = mPhone.getSubId(); if (TelephonyManager.getDefault().getSimCount() == 1 || !SubscriptionManager.isValidSubscriptionId(subId)) { return Settings.Global.MOBILE_DATA; } else { return Settings.Global.MOBILE_DATA + mPhone.getSubId(); } } public synchronized void setPolicyDataEnabled(boolean enabled) { localLog("PolicyDataEnabled", enabled); boolean prevDataEnabled = isDataEnabled(); mPolicyDataEnabled = enabled; if (prevDataEnabled != isDataEnabled()) { Loading @@ -104,6 +145,7 @@ public class DataEnabledSettings { } public synchronized void setCarrierDataEnabled(boolean enabled) { localLog("CarrierDataEnabled", enabled); boolean prevDataEnabled = isDataEnabled(); mCarrierDataEnabled = enabled; if (prevDataEnabled != isDataEnabled()) { Loading @@ -115,8 +157,36 @@ public class DataEnabledSettings { } public synchronized boolean isDataEnabled() { return (mInternalDataEnabled && mUserDataEnabled && mPolicyDataEnabled && mCarrierDataEnabled); if (isProvisioning()) { return isProvisioningDataEnabled(); } else { return mInternalDataEnabled && isUserDataEnabled() && mPolicyDataEnabled && mCarrierDataEnabled; } } public boolean isProvisioning() { return Settings.Global.getInt(mResolver, Settings.Global.DEVICE_PROVISIONED, 0) == 0; } /** * In provisioning, we might want to have enable mobile data during provisioning. It depends * on value of Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED which is set by * setupwizard. It only matters if it's in provisioning stage. * @return whether we are enabling userData during provisioning stage. */ public boolean isProvisioningDataEnabled() { final String prov_property = SystemProperties.get("ro.com.android.prov_mobiledata", "false"); boolean retVal = "true".equalsIgnoreCase(prov_property); final int prov_mobile_data = Settings.Global.getInt(mResolver, Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED, retVal ? 1 : 0); retVal = prov_mobile_data != 0; log("getDataEnabled during provisioning retVal=" + retVal + " - (" + prov_property + ", " + prov_mobile_data + ")"); return retVal; } private void notifyDataEnabledChanged(boolean enabled, int reason) { Loading @@ -131,4 +201,17 @@ public class DataEnabledSettings { public void unregisterForDataEnabledChanged(Handler h) { mDataEnabledChangedRegistrants.remove(h); } private void log(String s) { Rlog.d(LOG_TAG, "[" + mPhone.getPhoneId() + "]" + s); } private void localLog(String name, boolean value) { mSettingChangeLocalLog.log(name + " change to " + value); } protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println(" DataEnabledSettings="); mSettingChangeLocalLog.dump(fd, pw, args); } }
src/java/com/android/internal/telephony/dataconnection/DcTracker.java +19 −65 Original line number Diff line number Diff line Loading @@ -126,7 +126,7 @@ public class DcTracker extends Handler { private String mRequestedApnType = PhoneConstants.APN_TYPE_DEFAULT; // All data enabling/disabling related settings private final DataEnabledSettings mDataEnabledSettings = new DataEnabledSettings(); private final DataEnabledSettings mDataEnabledSettings; /** Loading Loading @@ -612,8 +612,8 @@ public class DcTracker extends Handler { filter.addAction(INTENT_DATA_STALL_ALARM); filter.addAction(INTENT_PROVISIONING_APN_ALARM); filter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); // TODO - redundent with update call below? mDataEnabledSettings.setUserDataEnabled(getDataEnabled()); mDataEnabledSettings = new DataEnabledSettings(phone); mPhone.getContext().registerReceiver(mIntentReceiver, filter, null, mPhone); Loading Loading @@ -664,6 +664,7 @@ public class DcTracker extends Handler { mDataConnectionTracker = null; mProvisionActionName = null; mSettingsObserver = new SettingsObserver(null, this); mDataEnabledSettings = null; } public void registerServiceStateTrackerEvents() { Loading Loading @@ -803,16 +804,6 @@ public class DcTracker extends Handler { synchronized (mDataEnabledSettings) { if (mDataEnabledSettings.isUserDataEnabled() != enabled) { mDataEnabledSettings.setUserDataEnabled(enabled); //TODO: We should move the followings into DataEnabledSettings class. // For single SIM phones, this is a per phone property. if (TelephonyManager.getDefault().getSimCount() == 1) { Settings.Global.putInt(mResolver, Settings.Global.MOBILE_DATA, enabled ? 1 : 0); } else { int phoneSubId = mPhone.getSubId(); Settings.Global.putInt(mResolver, Settings.Global.MOBILE_DATA + phoneSubId, enabled ? 1 : 0); } if (!getDataRoamingEnabled() && mPhone.getServiceState().getDataRoaming()) { if (enabled) { notifyOffApnsOfAvailability(Phone.REASON_ROAMING_ON); Loading Loading @@ -883,12 +874,10 @@ public class DcTracker extends Handler { } private void onDeviceProvisionedChange() { if (getDataEnabled()) { mDataEnabledSettings.setUserDataEnabled(true); if (isDataEnabled()) { reevaluateDataConnections(); onTrySetupData(Phone.REASON_DATA_ENABLED); } else { mDataEnabledSettings.setUserDataEnabled(false); onCleanUpAllConnections(Phone.REASON_DATA_SPECIFIC_DISABLED); } } Loading Loading @@ -2587,45 +2576,12 @@ public class DcTracker extends Handler { /** * Return current {@link android.provider.Settings.Global#MOBILE_DATA} value. */ //TODO: Merge this into DataSettings. And probably should rename to getUserDataEnabled(). public boolean getDataEnabled() { final int device_provisioned = Settings.Global.getInt(mResolver, Settings.Global.DEVICE_PROVISIONED, 0); boolean retVal = "true".equalsIgnoreCase(SystemProperties.get( "ro.com.android.mobiledata", "true")); if (TelephonyManager.getDefault().getSimCount() == 1) { retVal = Settings.Global.getInt(mResolver, Settings.Global.MOBILE_DATA, retVal ? 1 : 0) != 0; if (mDataEnabledSettings.isProvisioning()) { return mDataEnabledSettings.isProvisioningDataEnabled(); } else { int phoneSubId = mPhone.getSubId(); try { retVal = TelephonyManager.getIntWithSubId(mResolver, Settings.Global.MOBILE_DATA, phoneSubId) != 0; } catch (SettingNotFoundException e) { // use existing retVal } } if (VDBG) log("getDataEnabled: retVal=" + retVal); if (device_provisioned == 0) { // device is still getting provisioned - use whatever setting they // want during this process // // use the normal data_enabled setting (retVal, determined above) // as the default if nothing else is set final String prov_property = SystemProperties.get("ro.com.android.prov_mobiledata", retVal ? "true" : "false"); retVal = "true".equalsIgnoreCase(prov_property); final int prov_mobile_data = Settings.Global.getInt(mResolver, Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED, retVal ? 1 : 0); retVal = prov_mobile_data != 0; log("getDataEnabled during provisioning retVal=" + retVal + " - (" + prov_property + ", " + prov_mobile_data + ")"); return mDataEnabledSettings.isUserDataEnabled(); } return retVal; } /** Loading Loading @@ -2666,19 +2622,17 @@ public class DcTracker extends Handler { boolean isDataRoamingEnabled; final int phoneSubId = mPhone.getSubId(); try { // For single SIM phones, this is a per phone property. if (TelephonyManager.getDefault().getSimCount() == 1) { isDataRoamingEnabled = Settings.Global.getInt(mResolver, Settings.Global.DATA_ROAMING, getDefaultDataRoamingEnabled() ? 1 : 0) != 0; Settings.Global.DATA_ROAMING, getDefaultDataRoamingEnabled() ? 1 : 0) != 0; } else { isDataRoamingEnabled = TelephonyManager.getIntWithSubId(mResolver, Settings.Global.DATA_ROAMING, phoneSubId) != 0; } } catch (SettingNotFoundException snfe) { if (DBG) log("getDataRoamingEnabled: SettingNofFoundException snfe=" + snfe); isDataRoamingEnabled = getDefaultDataRoamingEnabled(); isDataRoamingEnabled = Settings.Global.getInt(mResolver, Settings.Global.DATA_ROAMING + phoneSubId, getDefaultDataRoamingEnabled() ? 1 : 0) != 0; } if (VDBG) { log("getDataRoamingEnabled: phoneSubId=" + phoneSubId + " isDataRoamingEnabled=" + isDataRoamingEnabled); Loading Loading @@ -4070,7 +4024,6 @@ public class DcTracker extends Handler { log("update(): Active DDS, register for all events now!"); onUpdateIcc(); mDataEnabledSettings.setUserDataEnabled(getDataEnabled()); mAutoAttachOnCreation.set(false); ((GsmCdmaPhone)mPhone).updateCurrentCarrierInProvider(); Loading Loading @@ -4268,6 +4221,7 @@ public class DcTracker extends Handler { pw.println(" getOverallState=" + getOverallState()); pw.println(" mDataConnectionAsyncChannels=%s\n" + mDataConnectionAcHashMap); pw.println(" mAttached=" + mAttached.get()); mDataEnabledSettings.dump(fd, pw, args); pw.flush(); } Loading
tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -461,6 +461,9 @@ public abstract class TelephonyTest { mSST.mSS = mServiceState; mServiceManagerMockedServices.put("connectivity_metrics_logger", mConnMetLoggerBinder); //SIM doReturn(1).when(mTelephonyManager).getSimCount(); setReady(false); } Loading
tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java +47 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import static org.mockito.Mockito.verify; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.database.Cursor; Loading Loading @@ -805,6 +806,9 @@ public class DcTrackerTest extends TelephonyTest { @MediumTest public void testDDSResetAutoAttach() throws Exception { ContentResolver resolver = mContext.getContentResolver(); Settings.Global.putInt(resolver, Settings.Global.DEVICE_PROVISIONED, 1); mDct.setDataEnabled(true); mContextFixture.putBooleanResource( Loading Loading @@ -1225,4 +1229,47 @@ public class DcTrackerTest extends TelephonyTest { assertEquals(FAKE_APN4, mDct.getActiveApnString(PhoneConstants.APN_TYPE_DEFAULT)); assertEquals(DctConstants.State.CONNECTED, mDct.getOverallState()); } // Test provisioning @Test @SmallTest public void testDataEnableInProvisioning() throws Exception { // Initial state is: userData enabled, provisioned. ContentResolver resolver = mContext.getContentResolver(); Settings.Global.putInt(resolver, Settings.Global.MOBILE_DATA, 1); Settings.Global.putInt(resolver, Settings.Global.DEVICE_PROVISIONED, 1); Settings.Global.putInt(resolver, Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED, 1); assertEquals(1, Settings.Global.getInt(resolver, Settings.Global.MOBILE_DATA)); assertTrue(mDct.isDataEnabled()); // The api should rename to getUserDataEnabled(); assertTrue(mDct.getDataEnabled()); mDct.setDataEnabled(false); waitForMs(200); assertEquals(0, Settings.Global.getInt(resolver, Settings.Global.MOBILE_DATA)); assertFalse(mDct.isDataEnabled()); // The api should rename to getUserDataEnabled(); assertFalse(mDct.getDataEnabled()); // Changing provisioned to 0. Settings.Global.putInt(resolver, Settings.Global.DEVICE_PROVISIONED, 0); assertTrue(mDct.isDataEnabled()); // The api should rename to getUserDataEnabled(); assertTrue(mDct.getDataEnabled()); // Enable user data during provisioning. It should write to // Settings.Global.MOBILE_DATA and keep data enabled when provisioned. mDct.setDataEnabled(true); Settings.Global.putInt(resolver, Settings.Global.DEVICE_PROVISIONED, 1); waitForMs(200); assertTrue(mDct.isDataEnabled()); assertTrue(mDct.getDataEnabled()); assertEquals(1, Settings.Global.getInt(resolver, Settings.Global.MOBILE_DATA)); } }