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

Commit 0c3eeddd authored by Robert Greenwalt's avatar Robert Greenwalt Committed by android-build-merger
Browse files

Use preferred APN for IA if it'll work. am: 40b0e247

am: 49e2bbc3

Change-Id: I1679174b549b6a0fe595b312186ca509f0b36e7b
parents be1e1a57 49e2bbc3
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -352,10 +352,12 @@ public class ApnSetting {

    public boolean canHandleType(String type) {
        if (!carrierEnabled) return false;
        boolean wildcardable = true;
        if (PhoneConstants.APN_TYPE_IA.equalsIgnoreCase(type)) wildcardable = false;
        for (String t : types) {
            // DEFAULT handles all, and HIPRI is handled by DEFAULT
            if (t.equalsIgnoreCase(type) ||
                    t.equalsIgnoreCase(PhoneConstants.APN_TYPE_ALL) ||
                    (wildcardable && t.equalsIgnoreCase(PhoneConstants.APN_TYPE_ALL)) ||
                    (t.equalsIgnoreCase(PhoneConstants.APN_TYPE_DEFAULT) &&
                    type.equalsIgnoreCase(PhoneConstants.APN_TYPE_HIPRI))) {
                return true;
+4 −4
Original line number Diff line number Diff line
@@ -2126,15 +2126,15 @@ public class DcTracker extends Handler {

        log("setInitialApn: E mPreferredApn=" + mPreferredApn);

        if (mAllApnSettings != null && !mAllApnSettings.isEmpty()) {
        if (mPreferredApn != null && mPreferredApn.canHandleType(PhoneConstants.APN_TYPE_IA)) {
              iaApnSetting = mPreferredApn;
        } else if (mAllApnSettings != null && !mAllApnSettings.isEmpty()) {
            firstApnSetting = mAllApnSettings.get(0);
            log("setInitialApn: firstApnSetting=" + firstApnSetting);

            // Search for Initial APN setting and the first apn that can handle default
            for (ApnSetting apn : mAllApnSettings) {
                // Can't use apn.canHandleType(), as that returns true for APNs that have no type.
                if (ArrayUtils.contains(apn.types, PhoneConstants.APN_TYPE_IA) &&
                        apn.carrierEnabled) {
                if (apn.canHandleType(PhoneConstants.APN_TYPE_IA)) {
                    // The Initial Attach APN is highest priority so use it if there is one
                    log("setInitialApn: iaApnSetting=" + apn);
                    iaApnSetting = apn;
+77 −2
Original line number Diff line number Diff line
@@ -31,10 +31,17 @@ import org.junit.Test;
import java.util.ArrayList;
import java.util.List;

import static com.android.internal.telephony.PhoneConstants.APN_TYPE_ALL;
import static com.android.internal.telephony.PhoneConstants.APN_TYPE_DEFAULT;
import static com.android.internal.telephony.PhoneConstants.APN_TYPE_HIPRI;
import static com.android.internal.telephony.PhoneConstants.APN_TYPE_IA;
import static com.android.internal.telephony.PhoneConstants.APN_TYPE_MMS;
import static com.android.internal.telephony.PhoneConstants.APN_TYPE_SUPL;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;


public class ApnSettingTest extends TelephonyTest {

    private PersistableBundle mBundle;
@@ -52,6 +59,14 @@ public class ApnSettingTest extends TelephonyTest {
    }

    private ApnSetting createApnSetting(String[] apnTypes) {
        return createApnSettingInternal(apnTypes, true);
    }

    private ApnSetting createDisabledApnSetting(String[] apnTypes) {
        return createApnSettingInternal(apnTypes, false);
    }

    private ApnSetting createApnSettingInternal(String[] apnTypes, boolean carrierEnabled) {
        return new ApnSetting(
                2163,                   // id
                "44010",                // numeric
@@ -68,7 +83,7 @@ public class ApnSettingTest extends TelephonyTest {
                apnTypes,               // types
                "IP",                   // protocol
                "IP",                   // roaming_protocol
                true,                   // carrier_enabled
                carrierEnabled,         // carrier_enabled
                0,                      // bearer
                0,                      // bearer_bitmask
                0,                      // profile_id
@@ -495,4 +510,64 @@ public class ApnSettingTest extends TelephonyTest {
                isMetered(mContext, 4, isRoaming));

    }

    @Test
    @SmallTest
    public void testCanHandleType() throws Exception {
        String types[] = {"mms"};

        // empty string replaced with ALL ('*') when loaded to db
        assertFalse(createApnSetting(new String[]{}).
                canHandleType(APN_TYPE_MMS));

        assertTrue(createApnSetting(new String[]{APN_TYPE_ALL}).
                canHandleType(APN_TYPE_MMS));

        assertFalse(createApnSetting(new String[]{APN_TYPE_DEFAULT}).
                canHandleType(APN_TYPE_MMS));

        assertTrue(createApnSetting(new String[]{"DEfAULT"}).
                canHandleType("defAult"));

        // Hipri is asymmetric
        assertTrue(createApnSetting(new String[]{APN_TYPE_DEFAULT}).
                canHandleType(APN_TYPE_HIPRI));
        assertFalse(createApnSetting(new String[]{APN_TYPE_HIPRI}).
                canHandleType(APN_TYPE_DEFAULT));


        assertTrue(createApnSetting(new String[]{APN_TYPE_DEFAULT, APN_TYPE_MMS}).
                canHandleType(APN_TYPE_DEFAULT));

        assertTrue(createApnSetting(new String[]{APN_TYPE_DEFAULT, APN_TYPE_MMS}).
                canHandleType(APN_TYPE_MMS));

        assertFalse(createApnSetting(new String[]{APN_TYPE_DEFAULT, APN_TYPE_MMS}).
                canHandleType(APN_TYPE_SUPL));

        // special IA case - doesn't match wildcards
        assertFalse(createApnSetting(new String[]{APN_TYPE_DEFAULT, APN_TYPE_MMS}).
                canHandleType(APN_TYPE_IA));
        assertFalse(createApnSetting(new String[]{APN_TYPE_ALL}).
                canHandleType(APN_TYPE_IA));
        assertFalse(createApnSetting(new String[]{APN_TYPE_ALL}).
                canHandleType("iA"));
        assertTrue(createApnSetting(new String[]{APN_TYPE_DEFAULT, APN_TYPE_MMS, APN_TYPE_IA}).
                canHandleType(APN_TYPE_IA));

        // check carrier disabled
        assertFalse(createDisabledApnSetting(new String[]{APN_TYPE_ALL}).
                canHandleType(APN_TYPE_MMS));
        assertFalse(createDisabledApnSetting(new String[]{"DEfAULT"}).
                canHandleType("defAult"));
        assertFalse(createDisabledApnSetting(new String[]{APN_TYPE_DEFAULT}).
                canHandleType(APN_TYPE_HIPRI));
        assertFalse(createDisabledApnSetting(new String[]{APN_TYPE_DEFAULT, APN_TYPE_MMS}).
                canHandleType(APN_TYPE_DEFAULT));
        assertFalse(createDisabledApnSetting(new String[]{APN_TYPE_DEFAULT, APN_TYPE_MMS}).
                canHandleType(APN_TYPE_MMS));
        assertFalse(createDisabledApnSetting(new String[]
                {APN_TYPE_DEFAULT, APN_TYPE_MMS, APN_TYPE_IA}).
                canHandleType(APN_TYPE_IA));
    }
}