Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ccca8742 authored by fionaxu's avatar fionaxu
Browse files

support carrier specific initial value of data_roaming

1. new carrier config for default data roaming value
to support carrier specific feature: turn on data_roaming by default.
2. use a sharedpref to record if user has ever touch the setting
before.
3. on sim loaded, update data roaming setting: In the absence of
user-pref, override with the carrier default value. otherwise migrate
user-pref when swap to new SIM.

Bug: 63532986
Test: manual tests includes factory reset, hot sim swap and build
updates without factory reset.
Change-Id: I64619a0df27ad36595f4d063cd66f73595ad24f3
parent 69614c66
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1866,7 +1866,7 @@ public class GsmCdmaPhone extends Phone {

    @Override
    public void setDataRoamingEnabled(boolean enable) {
        mDcTracker.setDataRoamingEnabled(enable);
        mDcTracker.setDataRoamingEnabledByUser(enable);
    }

    @Override
+3 −0
Original line number Diff line number Diff line
@@ -140,6 +140,9 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    // Key used to read/write "disable data connection on boot" pref (used for testing)
    public static final String DATA_DISABLED_ON_BOOT_KEY = "disabled_on_boot_key";

    // Key used to read/write data_roaming_is_user_setting pref
    public static final String DATA_ROAMING_IS_USER_SETTING_KEY = "data_roaming_is_user_setting_key";

    /* Event Constants */
    protected static final int EVENT_RADIO_AVAILABLE             = 1;
    /** Supplementary Service Notification received. */
+74 −13
Original line number Diff line number Diff line
@@ -264,12 +264,8 @@ public class DcTracker extends Handler {
                            + " mIsWifiConnected=" + mIsWifiConnected);
                }
            } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
                CarrierConfigManager configMgr = (CarrierConfigManager)
                        mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
                if (configMgr != null) {
                    PersistableBundle cfg = configMgr.getConfigForSubId(mPhone.getSubId());
                    if (cfg != null) mAllowUserEditTetherApn =
                            cfg.getBoolean(CarrierConfigManager.KEY_EDITABLE_TETHER_APN_BOOL);
                if (mIccRecords.get() != null && mIccRecords.get().getRecordsLoaded()) {
                    setDefaultDataRoamingEnabled();
                }
            } else {
                if (DBG) log("onReceive: Unknown action=" + action);
@@ -2641,9 +2637,9 @@ public class DcTracker extends Handler {
    }

    /**
     * Modify {@link android.provider.Settings.Global#DATA_ROAMING} value.
     * Modify {@link android.provider.Settings.Global#DATA_ROAMING} value for user modification only
     */
    public void setDataRoamingEnabled(boolean enabled) {
    public void setDataRoamingEnabledByUser(boolean enabled) {
        final int phoneSubId = mPhone.getSubId();
        if (getDataRoamingEnabled() != enabled) {
            int roaming = enabled ? 1 : 0;
@@ -2651,6 +2647,7 @@ public class DcTracker extends Handler {
            // For single SIM phones, this is a per phone property.
            if (TelephonyManager.getDefault().getSimCount() == 1) {
                Settings.Global.putInt(mResolver, Settings.Global.DATA_ROAMING, roaming);
                setDataRoamingFromUserAction(true);
            } else {
                Settings.Global.putInt(mResolver, Settings.Global.DATA_ROAMING +
                         phoneSubId, roaming);
@@ -2659,12 +2656,12 @@ public class DcTracker extends Handler {
            mSubscriptionManager.setDataRoaming(roaming, phoneSubId);
            // will trigger handleDataOnRoamingChange() through observer
            if (DBG) {
                log("setDataRoamingEnabled: set phoneSubId=" + phoneSubId
                log("setDataRoamingEnabledByUser: set phoneSubId=" + phoneSubId
                        + " isRoaming=" + enabled);
            }
        } else {
            if (DBG) {
                log("setDataRoamingEnabled: unchanged phoneSubId=" + phoneSubId
                log("setDataRoamingEnabledByUser: unchanged phoneSubId=" + phoneSubId
                        + " isRoaming=" + enabled);
             }
        }
@@ -2674,21 +2671,21 @@ public class DcTracker extends Handler {
     * Return current {@link android.provider.Settings.Global#DATA_ROAMING} value.
     */
    public boolean getDataRoamingEnabled() {
        boolean isDataRoamingEnabled = "true".equalsIgnoreCase(SystemProperties.get(
                "ro.com.android.dataroaming", "false"));
        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, isDataRoamingEnabled ? 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();
        }
        if (VDBG) {
            log("getDataRoamingEnabled: phoneSubId=" + phoneSubId
@@ -2697,6 +2694,70 @@ public class DcTracker extends Handler {
        return isDataRoamingEnabled;
    }

    /**
     * get default values for {@link Settings.Global#DATA_ROAMING}
     * return {@code true} if either
     * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} or
     * system property ro.com.android.dataroaming is set to true. otherwise return {@code false}
     */
    private boolean getDefaultDataRoamingEnabled() {
        final CarrierConfigManager configMgr = (CarrierConfigManager)
                mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
        boolean isDataRoamingEnabled = "true".equalsIgnoreCase(SystemProperties.get(
                "ro.com.android.dataroaming", "false"));
        isDataRoamingEnabled |= configMgr.getConfigForSubId(mPhone.getSubId()).getBoolean(
                CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
        return isDataRoamingEnabled;
    }

    /**
     * Set default value for {@link android.provider.Settings.Global#DATA_ROAMING}
     * if the setting is not from user actions. default value is based on carrier config and system
     * properties.
     */
    private void setDefaultDataRoamingEnabled() {
        // For single SIM phones, this is a per phone property.
        String setting = Settings.Global.DATA_ROAMING;
        boolean useCarrierSpecificDefault = false;
        if (TelephonyManager.getDefault().getSimCount() != 1) {
            setting = setting + mPhone.getSubId();
            try {
                Settings.Global.getInt(mResolver, setting);
            } catch (SettingNotFoundException ex) {
                // For msim, update to carrier default if uninitialized.
                useCarrierSpecificDefault = true;
            }
        } else if (!isDataRoamingFromUserAction()) {
            // for single sim device, update to carrier default if user action is not set
            useCarrierSpecificDefault = true;
        }
        if (useCarrierSpecificDefault) {
            boolean defaultVal = getDefaultDataRoamingEnabled();
            log("setDefaultDataRoamingEnabled: " + setting + "default value: " + defaultVal);
            Settings.Global.putInt(mResolver, setting, defaultVal ? 1 : 0);
            mSubscriptionManager.setDataRoaming(defaultVal ? 1 : 0, mPhone.getSubId());
        }
    }

    private boolean isDataRoamingFromUserAction() {
        final SharedPreferences sp = PreferenceManager
                .getDefaultSharedPreferences(mPhone.getContext());
        // since we don't want to unset user preference from system update, pass true as the default
        // value if shared pref does not exist and set shared pref to false explicitly from factory
        // reset.
        if (!sp.contains(Phone.DATA_ROAMING_IS_USER_SETTING_KEY)
                && Settings.Global.getInt(mResolver, Settings.Global.DEVICE_PROVISIONED, 0) == 0) {
            sp.edit().putBoolean(Phone.DATA_ROAMING_IS_USER_SETTING_KEY, false).commit();
        }
        return sp.getBoolean(Phone.DATA_ROAMING_IS_USER_SETTING_KEY, true);
    }

    private void setDataRoamingFromUserAction(boolean isUserAction) {
        final SharedPreferences.Editor sp = PreferenceManager
                .getDefaultSharedPreferences(mPhone.getContext()).edit();
        sp.putBoolean(Phone.DATA_ROAMING_IS_USER_SETTING_KEY, isUserAction).commit();
    }

    // When the data roaming status changes from roaming to non-roaming.
    private void onDataRoamingOff() {
        if (DBG) log("onDataRoamingOff");
+8 −3
Original line number Diff line number Diff line
@@ -663,7 +663,7 @@ public class DcTrackerTest extends TelephonyTest {
        //user is in roaming
        doReturn(true).when(mServiceState).getDataRoaming();
        logd("Sending DISABLE_ROAMING_CMD");
        mDct.setDataRoamingEnabled(false);
        mDct.setDataRoamingEnabledByUser(false);
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_ROAMING_ON));
        waitForMs(200);

@@ -675,7 +675,7 @@ public class DcTrackerTest extends TelephonyTest {
        assertEquals(DctConstants.State.CONNECTED, mDct.getState(PhoneConstants.APN_TYPE_IMS));

        // reset roaming settings / data enabled settings at end of this test
        mDct.setDataRoamingEnabled(roamingEnabled);
        mDct.setDataRoamingEnabledByUser(roamingEnabled);
        mDct.setDataEnabled(dataEnabled);
        waitForMs(200);
    }
@@ -701,7 +701,7 @@ public class DcTrackerTest extends TelephonyTest {
        mDct.setDataEnabled(true);

        logd("Sending DISABLE_ROAMING_CMD");
        mDct.setDataRoamingEnabled(false);
        mDct.setDataRoamingEnabledByUser(false);

        logd("Sending EVENT_RECORDS_LOADED");
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_RECORDS_LOADED, null));
@@ -724,6 +724,11 @@ public class DcTrackerTest extends TelephonyTest {
        assertEquals(DctConstants.State.CONNECTED, mDct.getOverallState());
        assertEquals(DctConstants.State.IDLE, mDct.getState(PhoneConstants.APN_TYPE_DEFAULT));
        assertEquals(DctConstants.State.CONNECTED, mDct.getState(PhoneConstants.APN_TYPE_IMS));

        // reset roaming settings / data enabled settings at end of this test
        mDct.setDataRoamingEnabledByUser(roamingEnabled);
        mDct.setDataEnabled(dataEnabled);
        waitForMs(200);
    }

    // Test the default data switch scenario.
+1 −1
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ public class DcTrackerMock extends DcTracker {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public void setDataRoamingEnabled(boolean enabled) {
    public void setDataRoamingEnabledByUser(boolean enabled) {
        throw new RuntimeException("Not Implemented");
    }
    @Override