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

Commit 4b17d6f8 authored by Junda Liu's avatar Junda Liu
Browse files

DO NOT MERGE If set data profile with roaming protocol, set back to home when roaming off.

Data profile will be updated in O to support both home and roaming protocol.
This is a MR2 only fix to minimize behavior change and fix data error when
device move from roaming to home without airplane mode or power cycle.

The sequence of events can be tricky, eg. set data profile may be called before
device registers on network and will set home protocol even device is indeed roaming.
It is intentional this behavior is unchanged. Same for not set roaming protocol in
onRoamingOn.

Test: manual, https://paste.googleplex.com/4566715396521984
Bug: b/32240817
Change-Id: I70598bb14c7cb499552b1b725cf5b464f8ec3b2c
parent 243f76a2
Loading
Loading
Loading
Loading
+27 −11
Original line number Diff line number Diff line
@@ -611,6 +611,15 @@ public class DcTracker extends Handler {
     *  undesired network load */
    private boolean mMeteredApnDisabled = false;

    /**
     * int to remember whether has setDataProfiles and with roaming or not.
     * 0: default, has never set data profile
     * 1: has set data profile with home protocol
     * 2: has set data profile with roaming protocol
     * This is not needed once RIL command is updated to support both home and roaming protocol.
     */
    private int mSetDataProfileStatus = 0;

    /**
     * Handles changes to the APN db.
     */
@@ -2752,6 +2761,10 @@ public class DcTracker extends Handler {

        if (!mDataEnabledSettings.isUserDataEnabled()) return;

        // Note onRoamingOff will be called immediately when DcTracker registerForDataRoamingOff,
        // and will be called again if SST calls mDataRoamingOffRegistrants.notify().
        setDataProfilesAsNeeded();

        if (getDataOnRoamingEnabled() == false) {
            notifyOffApnsOfAvailability(Phone.REASON_ROAMING_OFF);
            setupDataOnConnectableApns(Phone.REASON_ROAMING_OFF);
@@ -3284,27 +3297,29 @@ public class DcTracker extends Handler {
    }

    private void setDataProfilesAsNeeded() {
        if (DBG) log("setDataProfilesAsNeeded");
        if (DBG) log("setDataProfilesAsNeeded mSetDataProfileStatus: " + mSetDataProfileStatus);
        if (mAllApnSettings != null && !mAllApnSettings.isEmpty()) {
            ArrayList<DataProfile> dps = new ArrayList<DataProfile>();
            // Note getDataRoaming is also false if data not registered
            boolean isRoaming = mPhone.getServiceState().getDataRoaming();
            // If has set profile with home, and isRoaming is also false, no need to resend
            // Also skip if has set profile with roaming and isRoaming is true.
            if ((mSetDataProfileStatus == 1 && !isRoaming) ||
                (mSetDataProfileStatus == 2 && isRoaming)) {
                return;
            }
            for (ApnSetting apn : mAllApnSettings) {
                if (apn.modemCognitive) {
                    DataProfile dp = new DataProfile(apn,
                            mPhone.getServiceState().getDataRoaming());
                    boolean isDup = false;
                    for(DataProfile dpIn : dps) {
                        if (dp.equals(dpIn)) {
                            isDup = true;
                            break;
                        }
                    }
                    if (!isDup) {
                    DataProfile dp = new DataProfile(apn, isRoaming);
                    // ArrayList.contains will call object.equals
                    if (!dps.contains(dp)) {
                        dps.add(dp);
                    }
                }
            }
            if(dps.size() > 0) {
                mPhone.mCi.setDataProfile(dps.toArray(new DataProfile[0]), null);
                mSetDataProfileStatus = isRoaming ? 2 : 1;
            }
        }
    }
@@ -4219,6 +4234,7 @@ public class DcTracker extends Handler {
        pw.println(" mAutoAttachOnCreation=" + mAutoAttachOnCreation.get());
        pw.println(" mIsScreenOn=" + mIsScreenOn);
        pw.println(" mUniqueIdGenerator=" + mUniqueIdGenerator);
        pw.println(" mSetDataProfileStatus=" + mSetDataProfileStatus);
        pw.flush();
        pw.println(" ***************************************");
        DcController dcc = mDcc;