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

Commit 3c4aab4e authored by d34d's avatar d34d Committed by Abhisek Devkota
Browse files

APN: Clean up mvno filtering of apn list

The current implementation was filtering out the mvnos correctly
but those apns ended up getting added to the end of the list rather
than alphabetically.  This patch keeps the sorting even for matching
mvno entries.

Change-Id: I4636a9be230834f093f9b21d69197fbf2449229c
TICKET: CYNGNOS-670
(cherry picked from commit acdfc53f)
parent 9d26227f
Loading
Loading
Loading
Loading
+27 −38
Original line number Diff line number Diff line
@@ -241,9 +241,9 @@ public class ApnSettings extends SettingsPreferenceFragment implements

            ArrayList<Preference> mmsApnList = new ArrayList<Preference>();

            ArrayList<ApnInfo> mvnoSpnList = new ArrayList<ApnInfo>();
            ArrayList<ApnInfo> mvnoGid1List = new ArrayList<ApnInfo>();
            ArrayList<ApnInfo> mvnoImsiList = new ArrayList<ApnInfo>();
            ArrayList<Preference> mvnoSpnList = new ArrayList<Preference>();
            ArrayList<Preference> mvnoGid1List = new ArrayList<Preference>();
            ArrayList<Preference> mvnoImsiList = new ArrayList<Preference>();

            mSelectedKey = getSelectedApnKey();
            while (cursor.moveToNext()) {
@@ -256,21 +256,6 @@ public class ApnSettings extends SettingsPreferenceFragment implements
                String mvnoData = cursor.getString(MVNODATA_INDEX);
                boolean isMvno = !TextUtils.isEmpty(mvnoType) && !TextUtils.isEmpty(mvnoData);

                if (isMvno) {
                    if (!mvnoMatches(mvnoType, mvnoData, simOperatorName, imsiSIM, gid1)) {
                    } else {
                        ApnInfo apnInfo = new ApnInfo(name, apn, key, type, mvnoType, readOnly);
                        if ("spn".equals(mvnoType)) {
                            mvnoSpnList.add(apnInfo);
                        } else if ("gid".equals(mvnoType)) {
                            mvnoGid1List.add(apnInfo);
                        } else if ("imsi".equals(mvnoType)) {
                            mvnoImsiList.add(apnInfo);
                        }
                    }
                    continue;
                }

                ApnPreference pref = createApnPreference(name, key, apn, type, readOnly);

                if (pref.getSelectable()) {
@@ -282,30 +267,34 @@ public class ApnSettings extends SettingsPreferenceFragment implements
                } else {
                    mmsApnList.add(pref);
                }

                if (isMvno) {
                    if (!mvnoMatches(mvnoType, mvnoData, simOperatorName, imsiSIM, gid1)) {
                        apnList.removePreference(pref);
                    } else {
                        ApnInfo apnInfo = new ApnInfo(name, apn, key, type, mvnoType, readOnly);
                        if ("spn".equals(mvnoType)) {
                            mvnoSpnList.add(pref);
                        } else if ("gid".equals(mvnoType)) {
                            mvnoGid1List.add(pref);
                        } else if ("imsi".equals(mvnoType)) {
                            mvnoImsiList.add(pref);
                        }
                    }
                }

            }
            cursor.close();

            ArrayList<ApnInfo> mvnoList = null;
            // remove preferences for mvnos that should not be shown
            if (mvnoImsiList.size() > 0 || mvnoGid1List.size() > 0) {
                if (mvnoImsiList.size() > 0) {
                mvnoList = mvnoImsiList;
            } else if (mvnoGid1List.size() > 0) {
                mvnoList = mvnoGid1List;
            } else if (mvnoSpnList.size() > 0) {
                mvnoList = mvnoSpnList;
            }
            if (mvnoList != null) {
                for (ApnInfo apnInfo : mvnoList) {
                    ApnPreference pref = createApnPreference(apnInfo.name, apnInfo.key, apnInfo.apn,
                            apnInfo.type, apnInfo.readOnly);
                    if (apnInfo.selectable) {
                        if ((mSelectedKey != null) && mSelectedKey.equals(apnInfo.key)) {
                            pref.setChecked();
                            Log.d(TAG, "find select key = " + mSelectedKey);
                    for (Preference pref : mvnoGid1List) {
                        apnList.removePreference(pref);
                    }
                        apnList.addPreference(pref);
                    } else {
                        mmsApnList.add(pref);
                }
                for (Preference pref : mvnoSpnList) {
                    apnList.removePreference(pref);
                }
            }