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

Commit b6e59754 authored by Josh Hou's avatar Josh Hou
Browse files

Refine APN fetching logic

APN fetching logic has been encapsulated in URL_FILTERED API in
TelephonyProvider

Bug: 115709816
Test: 1. Run DcTrackerTest 2.Live network test
Change-Id: Idc49945ab280090ab5b5d3508deae535023d2735
parent 58881942
Loading
Loading
Loading
Loading
+21 −76
Original line number Diff line number Diff line
@@ -516,10 +516,6 @@ public class DcTracker extends Handler {
    //        really a lower power mode")
    private boolean mIsScreenOn = true;

    // Indicates if we found mvno-specific APNs in the full APN list.
    // used to determine if we can accept mno-specific APN for tethering.
    private boolean mMvnoMatched = false;

    /** Allows the generation of unique Id's for DataConnection objects */
    private AtomicInteger mUniqueIdGenerator = new AtomicInteger(0);

@@ -1699,8 +1695,6 @@ public class DcTracker extends Handler {
            return new ArrayList<ApnSetting>(0);
        }
        int bearer = mPhone.getServiceState().getRilDataRadioTechnology();
        IccRecords r = mIccRecords.get();
        String operator = (r != null) ? r.getOperatorNumeric() : "";
        ArrayList<ApnSetting> dunCandidates = new ArrayList<ApnSetting>();
        ArrayList<ApnSetting> retDunSettings = new ArrayList<ApnSetting>();

@@ -1728,17 +1722,8 @@ public class DcTracker extends Handler {
                    ServiceState.rilRadioTechnologyToNetworkType(bearer))) {
                continue;
            }
            if (dunSetting.getOperatorNumeric().equals(operator)) {
                if (dunSetting.hasMvnoParams()) {
                    if (r != null && ApnSettingUtils.mvnoMatches(r, dunSetting.getMvnoType(),
                            dunSetting.getMvnoMatchData())) {
                        retDunSettings.add(dunSetting);
                    }
                } else if (mMvnoMatched == false) {
            retDunSettings.add(dunSetting);
        }
            }
        }

        if (VDBG) log("fetchDunApns: dunSettings=" + retDunSettings);
        return retDunSettings;
@@ -1810,41 +1795,6 @@ public class DcTracker extends Handler {
                (mAttached.get() == false || dcFailCause != DcFailCause.SIGNAL_LOST));
    }

    private ArrayList<ApnSetting> createApnList(Cursor cursor) {
        ArrayList<ApnSetting> mnoApns = new ArrayList<ApnSetting>();
        ArrayList<ApnSetting> mvnoApns = new ArrayList<ApnSetting>();
        IccRecords r = mIccRecords.get();

        if (cursor.moveToFirst()) {
            do {
                ApnSetting apn = ApnSetting.makeApnSetting(cursor);
                if (apn == null) {
                    continue;
                }

                if (apn.hasMvnoParams()) {
                    if (r != null && ApnSettingUtils.mvnoMatches(r, apn.getMvnoType(),
                            apn.getMvnoMatchData())) {
                        mvnoApns.add(apn);
                    }
                } else {
                    mnoApns.add(apn);
                }
            } while (cursor.moveToNext());
        }

        ArrayList<ApnSetting> result;
        if (mvnoApns.isEmpty()) {
            result = mnoApns;
            mMvnoMatched = false;
        } else {
            result = mvnoApns;
            mMvnoMatched = true;
        }
        if (DBG) log("createApnList: X result=" + result);
        return result;
    }

    private DataConnection findFreeDataConnection() {
        for (DataConnection dataConnection : mDataConnections.values()) {
            boolean inUse = false;
@@ -3223,34 +3173,28 @@ public class DcTracker extends Handler {
     * Data Connections and setup the preferredApn.
     */
    private void createAllApnList() {
        mMvnoMatched = false;
        mAllApnSettings.clear();
        IccRecords r = mIccRecords.get();
        String operator = (r != null) ? r.getOperatorNumeric() : "";
        if (operator != null) {
            String selection = Telephony.Carriers.NUMERIC + " = '" + operator + "'";
            // query only enabled apn.
            // carrier_enabled : 1 means enabled apn, 0 disabled apn.
            // selection += " and carrier_enabled = 1";
            if (DBG) log("createAllApnList: selection=" + selection);

        // ORDER BY Telephony.Carriers._ID ("_id")
        Cursor cursor = mPhone.getContext().getContentResolver().query(
                Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "filtered"),
                    null, selection, null, Telephony.Carriers._ID);
                null, null, null, Telephony.Carriers._ID);

        if (cursor != null) {
                if (cursor.getCount() > 0) {
                    mAllApnSettings = createApnList(cursor);
                } else {
                    if (DBG) log("createAllApnList: cursor count is 0");
                    mApnSettingsInitializationLog.log("no APN in db for carrier: " + operator);
            while (cursor.moveToNext()) {
                ApnSetting apn = ApnSetting.makeApnSetting(cursor);
                if (apn == null) {
                    continue;
                }
                mAllApnSettings.add(apn);
            }
            cursor.close();
        } else {
            if (DBG) log("createAllApnList: cursor is null");
                mApnSettingsInitializationLog.log("cursor is null for carrier: " + operator);
            }
            mApnSettingsInitializationLog.log("cursor is null for carrier, operator: "
                    + operator);
        }

        addEmergencyApnSetting();
@@ -3258,8 +3202,9 @@ public class DcTracker extends Handler {
        dedupeApnSettings();

        if (mAllApnSettings.isEmpty()) {
            if (DBG) log("createAllApnList: No APN found for carrier: " + operator);
            mApnSettingsInitializationLog.log("no APN found for carrier: " + operator);
            log("createAllApnList: No APN found for carrier, operator: " + operator);
            mApnSettingsInitializationLog.log("no APN found for carrier, operator: "
                    + operator);
            mPreferredApn = null;
            // TODO: What is the right behavior?
            //notifyNoData(DataConnection.FailCause.MISSING_UNKNOWN_APN);
+8 −19
Original line number Diff line number Diff line
@@ -98,8 +98,6 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DcTrackerTest extends TelephonyTest {

@@ -132,6 +130,7 @@ public class DcTrackerTest extends TelephonyTest {
    private static final Uri PREFERAPN_URI = Uri.parse(
            Telephony.Carriers.CONTENT_URI + "/preferapn");
    private static final int DATA_ENABLED_CHANGED = 0;
    private static final String FAKE_PLMN = "44010";

    @Mock
    ISub mIsub;
@@ -210,18 +209,9 @@ public class DcTrackerTest extends TelephonyTest {
            if (uri.compareTo(Telephony.Carriers.CONTENT_URI) == 0
                    || uri.compareTo(Uri.withAppendedPath(
                            Telephony.Carriers.CONTENT_URI, "filtered")) == 0) {
                if (projection == null && selectionArgs == null && selection != null) {
                if (projection == null) {

                    Pattern pattern = Pattern.compile("^numeric = '([0-9]*)'");
                    Matcher matcher = pattern.matcher(selection);
                    if (!matcher.find()) {
                        logd("Cannot find MCC/MNC from " + selection);
                        return null;
                    }

                    String plmn = matcher.group(1);

                    logd("Query '" + plmn + "' APN settings");
                    logd("Query '" + FAKE_PLMN + "' APN settings");
                    MatrixCursor mc = new MatrixCursor(
                            new String[]{Telephony.Carriers._ID, Telephony.Carriers.NUMERIC,
                                    Telephony.Carriers.NAME, Telephony.Carriers.APN,
@@ -246,7 +236,7 @@ public class DcTrackerTest extends TelephonyTest {

                    mc.addRow(new Object[]{
                            2163,                   // id
                            plmn,                   // numeric
                            FAKE_PLMN,              // numeric
                            "sp-mode",              // name
                            FAKE_APN1,              // apn
                            "",                     // proxy
@@ -278,7 +268,7 @@ public class DcTrackerTest extends TelephonyTest {

                    mc.addRow(new Object[]{
                            2164,                   // id
                            plmn,                   // numeric
                            FAKE_PLMN,              // numeric
                            "mopera U",             // name
                            FAKE_APN2,              // apn
                            "",                     // proxy
@@ -310,7 +300,7 @@ public class DcTrackerTest extends TelephonyTest {

                    mc.addRow(new Object[]{
                            2165,                   // id
                            plmn,                   // numeric
                            FAKE_PLMN,              // numeric
                            "b-mobile for Nexus",   // name
                            FAKE_APN3,              // apn
                            "",                     // proxy
@@ -342,7 +332,7 @@ public class DcTrackerTest extends TelephonyTest {

                    mc.addRow(new Object[]{
                            2166,                   // id
                            plmn,                   // numeric
                            FAKE_PLMN,              // numeric
                            "sp-mode ehrpd",        // name
                            FAKE_APN4,              // apn
                            "",                     // proxy
@@ -374,7 +364,7 @@ public class DcTrackerTest extends TelephonyTest {

                    mc.addRow(new Object[]{
                            2166,                   // id
                            plmn,                   // numeric
                            FAKE_PLMN,              // numeric
                            "b-mobile for Nexus",   // name
                            FAKE_APN5,              // apn
                            "",                     // proxy
@@ -435,7 +425,6 @@ public class DcTrackerTest extends TelephonyTest {
        doReturn("fake.action_attached").when(mPhone).getActionAttached();
        doReturn(ServiceState.RIL_RADIO_TECHNOLOGY_LTE).when(mServiceState)
                .getRilDataRadioTechnology();
        doReturn("44010").when(mSimRecords).getOperatorNumeric();

        mContextFixture.putStringArrayResource(com.android.internal.R.array.networkAttributes,
                sNetworkAttributes);