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

Commit 08fac289 authored by fionaxu's avatar fionaxu
Browse files

resolve merge conflicts of eef3bbab to stage-aosp-master

Test: I solemnly swear I tested this conflict resolution.

Change-Id: I7e9bbede8165ea67be4bac08ee21f05ba76cd6e4
parents c237b672 eef3bbab
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -1898,7 +1898,7 @@ public class GsmCdmaPhone extends Phone {


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


    @Override
    @Override
+3 −0
Original line number Original line Diff line number Diff line
@@ -143,6 +143,9 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    // Key used to read/write "disable data connection on boot" pref (used for testing)
    // 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";
    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 */
    /* Event Constants */
    protected static final int EVENT_RADIO_AVAILABLE             = 1;
    protected static final int EVENT_RADIO_AVAILABLE             = 1;
    /** Supplementary Service Notification received. */
    /** Supplementary Service Notification received. */
+74 −13
Original line number Original line Diff line number Diff line
@@ -264,12 +264,8 @@ public class DcTracker extends Handler {
                            + " mIsWifiConnected=" + mIsWifiConnected);
                            + " mIsWifiConnected=" + mIsWifiConnected);
                }
                }
            } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
            } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
                CarrierConfigManager configMgr = (CarrierConfigManager)
                if (mIccRecords.get() != null && mIccRecords.get().getRecordsLoaded()) {
                        mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
                    setDefaultDataRoamingEnabled();
                if (configMgr != null) {
                    PersistableBundle cfg = configMgr.getConfigForSubId(mPhone.getSubId());
                    if (cfg != null) mAllowUserEditTetherApn =
                            cfg.getBoolean(CarrierConfigManager.KEY_EDITABLE_TETHER_APN_BOOL);
                }
                }
            } else {
            } else {
                if (DBG) log("onReceive: Unknown action=" + action);
                if (DBG) log("onReceive: Unknown action=" + action);
@@ -2651,9 +2647,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();
        final int phoneSubId = mPhone.getSubId();
        if (getDataRoamingEnabled() != enabled) {
        if (getDataRoamingEnabled() != enabled) {
            int roaming = enabled ? 1 : 0;
            int roaming = enabled ? 1 : 0;
@@ -2661,6 +2657,7 @@ public class DcTracker extends Handler {
            // For single SIM phones, this is a per phone property.
            // For single SIM phones, this is a per phone property.
            if (TelephonyManager.getDefault().getSimCount() == 1) {
            if (TelephonyManager.getDefault().getSimCount() == 1) {
                Settings.Global.putInt(mResolver, Settings.Global.DATA_ROAMING, roaming);
                Settings.Global.putInt(mResolver, Settings.Global.DATA_ROAMING, roaming);
                setDataRoamingFromUserAction(true);
            } else {
            } else {
                Settings.Global.putInt(mResolver, Settings.Global.DATA_ROAMING +
                Settings.Global.putInt(mResolver, Settings.Global.DATA_ROAMING +
                         phoneSubId, roaming);
                         phoneSubId, roaming);
@@ -2669,12 +2666,12 @@ public class DcTracker extends Handler {
            mSubscriptionManager.setDataRoaming(roaming, phoneSubId);
            mSubscriptionManager.setDataRoaming(roaming, phoneSubId);
            // will trigger handleDataOnRoamingChange() through observer
            // will trigger handleDataOnRoamingChange() through observer
            if (DBG) {
            if (DBG) {
                log("setDataRoamingEnabled: set phoneSubId=" + phoneSubId
                log("setDataRoamingEnabledByUser: set phoneSubId=" + phoneSubId
                        + " isRoaming=" + enabled);
                        + " isRoaming=" + enabled);
            }
            }
        } else {
        } else {
            if (DBG) {
            if (DBG) {
                log("setDataRoamingEnabled: unchanged phoneSubId=" + phoneSubId
                log("setDataRoamingEnabledByUser: unchanged phoneSubId=" + phoneSubId
                        + " isRoaming=" + enabled);
                        + " isRoaming=" + enabled);
             }
             }
        }
        }
@@ -2684,21 +2681,21 @@ public class DcTracker extends Handler {
     * Return current {@link android.provider.Settings.Global#DATA_ROAMING} value.
     * Return current {@link android.provider.Settings.Global#DATA_ROAMING} value.
     */
     */
    public boolean getDataRoamingEnabled() {
    public boolean getDataRoamingEnabled() {
        boolean isDataRoamingEnabled = "true".equalsIgnoreCase(SystemProperties.get(
        boolean isDataRoamingEnabled;
                "ro.com.android.dataroaming", "false"));
        final int phoneSubId = mPhone.getSubId();
        final int phoneSubId = mPhone.getSubId();


        try {
        try {
            // For single SIM phones, this is a per phone property.
            // For single SIM phones, this is a per phone property.
            if (TelephonyManager.getDefault().getSimCount() == 1) {
            if (TelephonyManager.getDefault().getSimCount() == 1) {
                isDataRoamingEnabled = Settings.Global.getInt(mResolver,
                isDataRoamingEnabled = Settings.Global.getInt(mResolver,
                        Settings.Global.DATA_ROAMING, isDataRoamingEnabled ? 1 : 0) != 0;
                        Settings.Global.DATA_ROAMING, getDefaultDataRoamingEnabled() ? 1 : 0) != 0;
            } else {
            } else {
                isDataRoamingEnabled = TelephonyManager.getIntWithSubId(mResolver,
                isDataRoamingEnabled = TelephonyManager.getIntWithSubId(mResolver,
                        Settings.Global.DATA_ROAMING, phoneSubId) != 0;
                        Settings.Global.DATA_ROAMING, phoneSubId) != 0;
            }
            }
        } catch (SettingNotFoundException snfe) {
        } catch (SettingNotFoundException snfe) {
            if (DBG) log("getDataRoamingEnabled: SettingNofFoundException snfe=" + snfe);
            if (DBG) log("getDataRoamingEnabled: SettingNofFoundException snfe=" + snfe);
            isDataRoamingEnabled = getDefaultDataRoamingEnabled();
        }
        }
        if (VDBG) {
        if (VDBG) {
            log("getDataRoamingEnabled: phoneSubId=" + phoneSubId
            log("getDataRoamingEnabled: phoneSubId=" + phoneSubId
@@ -2707,6 +2704,70 @@ public class DcTracker extends Handler {
        return isDataRoamingEnabled;
        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.
    // When the data roaming status changes from roaming to non-roaming.
    private void onDataRoamingOff() {
    private void onDataRoamingOff() {
        if (DBG) log("onDataRoamingOff");
        if (DBG) log("onDataRoamingOff");
+4 −4
Original line number Original line Diff line number Diff line
@@ -661,7 +661,7 @@ public class DcTrackerTest extends TelephonyTest {
        //user is in roaming
        //user is in roaming
        doReturn(true).when(mServiceState).getDataRoaming();
        doReturn(true).when(mServiceState).getDataRoaming();
        logd("Sending DISABLE_ROAMING_CMD");
        logd("Sending DISABLE_ROAMING_CMD");
        mDct.setDataRoamingEnabled(false);
        mDct.setDataRoamingEnabledByUser(false);
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_ROAMING_ON));
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_ROAMING_ON));
        waitForMs(200);
        waitForMs(200);


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


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


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


        logd("Sending EVENT_RECORDS_LOADED");
        logd("Sending EVENT_RECORDS_LOADED");
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_RECORDS_LOADED, null));
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_RECORDS_LOADED, null));
@@ -721,7 +721,7 @@ public class DcTrackerTest extends TelephonyTest {
        assertEquals(DctConstants.State.CONNECTED, mDct.getState(PhoneConstants.APN_TYPE_IMS));
        assertEquals(DctConstants.State.CONNECTED, mDct.getState(PhoneConstants.APN_TYPE_IMS));


        // reset roaming settings / data enabled settings at end of this test
        // reset roaming settings / data enabled settings at end of this test
        mDct.setDataRoamingEnabled(roamingEnabled);
        mDct.setDataRoamingEnabledByUser(roamingEnabled);
        mDct.setDataEnabled(dataEnabled);
        mDct.setDataEnabled(dataEnabled);
        waitForMs(200);
        waitForMs(200);
    }
    }
+1 −1
Original line number Original line Diff line number Diff line
@@ -97,7 +97,7 @@ public class DcTrackerMock extends DcTracker {
        throw new RuntimeException("Not Implemented");
        throw new RuntimeException("Not Implemented");
    }
    }
    @Override
    @Override
    public void setDataRoamingEnabled(boolean enabled) {
    public void setDataRoamingEnabledByUser(boolean enabled) {
        throw new RuntimeException("Not Implemented");
        throw new RuntimeException("Not Implemented");
    }
    }
    @Override
    @Override