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

Commit e310a116 authored by Josh Hou's avatar Josh Hou Committed by android-build-merger
Browse files

Merge "Refine APN fetching logic"

am: 477570a1

Change-Id: I7f66eedce09e255dd554f6c6d6fbb8e19dea95b3
parents ed714576 477570a1
Loading
Loading
Loading
Loading
+21 −76
Original line number Diff line number Diff line
@@ -511,10 +511,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);

@@ -1709,8 +1705,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>();

@@ -1738,17 +1732,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;
@@ -1820,41 +1805,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;
@@ -3232,34 +3182,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/subId/"
                            + mPhone.getSubId()), null, selection, null, Telephony.Carriers._ID);
                        + mPhone.getSubId()), 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();
@@ -3267,8 +3211,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.toString().startsWith(Uri.withAppendedPath(
                            Telephony.Carriers.CONTENT_URI, "filtered").toString())) {
                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,
@@ -248,7 +238,7 @@ public class DcTrackerTest extends TelephonyTest {

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

                    mc.addRow(new Object[]{
                            2164,                   // id
                            plmn,                   // numeric
                            FAKE_PLMN,              // numeric
                            "mopera U",             // name
                            FAKE_APN2,              // apn
                            "",                     // proxy
@@ -312,7 +302,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
@@ -344,7 +334,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
@@ -376,7 +366,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
@@ -437,7 +427,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);