Loading src/java/com/android/internal/telephony/dataconnection/DcTracker.java +17 −43 Original line number Diff line number Diff line Loading @@ -123,7 +123,6 @@ import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; Loading Loading @@ -1854,12 +1853,15 @@ public class DcTracker extends Handler { } for (ApnSetting dunSetting : dunCandidates) { if (!dunSetting.canSupportNetworkType( if (dunSetting.canSupportNetworkType( ServiceState.rilRadioTechnologyToNetworkType(bearer))) { continue; } int preferredApnSetId = getPreferredApnSetId(); if (preferredApnSetId == Telephony.Carriers.NO_APN_SET_ID || preferredApnSetId == dunSetting.getApnSetId()) { retDunSettings.add(dunSetting); } } } if (VDBG) log("fetchDunApns: dunSettings=" + retDunSettings); return retDunSettings; Loading Loading @@ -2385,7 +2387,7 @@ public class DcTracker extends Handler { ArrayList<ApnSetting> dunSettings = null; if (ApnSetting.TYPE_DUN == apnType) { dunSettings = sortApnListByPreferred(fetchDunApns()); dunSettings = fetchDunApns(); } if (DBG) { log("checkForCompatibleDataConnection: apnContext=" + apnContext); Loading Loading @@ -3360,7 +3362,7 @@ public class DcTracker extends Handler { apnList.add(dun); if (DBG) log("buildWaitingApns: X added APN_TYPE_DUN apnList=" + apnList); } return sortApnListByPreferred(apnList); return apnList; } } Loading Loading @@ -3399,7 +3401,6 @@ public class DcTracker extends Handler { if (mPreferredApn.canSupportNetworkType( ServiceState.rilRadioTechnologyToNetworkType(radioTech))) { apnList.add(mPreferredApn); apnList = sortApnListByPreferred(apnList); if (DBG) log("buildWaitingApns: X added preferred apnList=" + apnList); return apnList; } Loading @@ -3414,8 +3415,15 @@ public class DcTracker extends Handler { if (apn.canHandleType(requestedApnTypeBitmask)) { if (apn.canSupportNetworkType( ServiceState.rilRadioTechnologyToNetworkType(radioTech))) { int preferredApnSetId = getPreferredApnSetId(); if (preferredApnSetId == Telephony.Carriers.NO_APN_SET_ID || preferredApnSetId == apn.getApnSetId()) { if (VDBG) log("buildWaitingApns: adding apn=" + apn); apnList.add(apn); } else { log("buildWaitingApns: APN set id " + apn.getApnSetId() + " does not match the preferred set id " + preferredApnSetId); } } else { if (DBG) { log("buildWaitingApns: networkTypeBitmask:" Loading @@ -3430,44 +3438,10 @@ public class DcTracker extends Handler { } } apnList = sortApnListByPreferred(apnList); if (DBG) log("buildWaitingApns: " + apnList.size() + " APNs in the list: " + apnList); return apnList; } /** * Sort a list of ApnSetting objects, with the preferred APNs at the front of the list * * e.g. if the preferred APN set = 2 and we have * 1. APN with apn_set_id = 0 = Carriers.NO_SET_SET (no set is set) * 2. APN with apn_set_id = 1 (not preferred set) * 3. APN with apn_set_id = 2 (preferred set) * Then the return order should be (3, 1, 2) or (3, 2, 1) * * e.g. if the preferred APN set = Carriers.NO_SET_SET (no preferred set) then the * return order can be anything */ @VisibleForTesting public ArrayList<ApnSetting> sortApnListByPreferred(ArrayList<ApnSetting> list) { if (list == null || list.size() <= 1) return list; int preferredApnSetId = getPreferredApnSetId(); if (preferredApnSetId != Telephony.Carriers.NO_APN_SET_ID) { list.sort(new Comparator<ApnSetting>() { @Override public int compare(ApnSetting apn1, ApnSetting apn2) { if (apn1.getApnSetId() == preferredApnSetId) { return -1; } if (apn2.getApnSetId() == preferredApnSetId) { return 1; } return 0; } }); } return list; } private String apnListToString (ArrayList<ApnSetting> apns) { StringBuilder result = new StringBuilder(); for (int i = 0, size = apns.size(); i < size; i++) { Loading tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java +16 −3 Original line number Diff line number Diff line Loading @@ -1373,7 +1373,7 @@ public class DcTrackerTest extends TelephonyTest { + "0,,,,,,,,,,1"; // apnSetId=0 String dunApnString2 = "[ApnSettingV5]HOT mobile PC,pc.coldm,,,,,,,,,440,10,,DUN,,,true," + "0,,,,,,,,,,0"; + "0,,,,,,,,,,2"; ApnSetting dunApnExpected = ApnSetting.fromString(dunApnString1); Loading @@ -1387,8 +1387,21 @@ public class DcTrackerTest extends TelephonyTest { cr.update(PREFERAPN_URI, values, null, null); // return APN from Setting with apnSetId=1 ArrayList<ApnSetting> dunApns = mDct.sortApnListByPreferred(mDct.fetchDunApns()); assertEquals(2, dunApns.size()); ArrayList<ApnSetting> dunApns = mDct.fetchDunApns(); assertEquals(1, dunApns.size()); assertEquals(1, dunApns.get(0).getApnSetId()); assertTrue(dunApnExpected.equals(dunApns.get(0))); // set that we prefer apn set 2 values = new ContentValues(); values.put(Telephony.Carriers.APN_SET_ID, 2); cr.update(PREFERAPN_URI, values, null, null); // return APN from Setting with apnSetId=2 dunApns = mDct.fetchDunApns(); assertEquals(1, dunApns.size()); assertEquals(2, dunApns.get(0).getApnSetId()); dunApnExpected = ApnSetting.fromString(dunApnString2); assertTrue(dunApnExpected.equals(dunApns.get(0))); } Loading Loading
src/java/com/android/internal/telephony/dataconnection/DcTracker.java +17 −43 Original line number Diff line number Diff line Loading @@ -123,7 +123,6 @@ import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; Loading Loading @@ -1854,12 +1853,15 @@ public class DcTracker extends Handler { } for (ApnSetting dunSetting : dunCandidates) { if (!dunSetting.canSupportNetworkType( if (dunSetting.canSupportNetworkType( ServiceState.rilRadioTechnologyToNetworkType(bearer))) { continue; } int preferredApnSetId = getPreferredApnSetId(); if (preferredApnSetId == Telephony.Carriers.NO_APN_SET_ID || preferredApnSetId == dunSetting.getApnSetId()) { retDunSettings.add(dunSetting); } } } if (VDBG) log("fetchDunApns: dunSettings=" + retDunSettings); return retDunSettings; Loading Loading @@ -2385,7 +2387,7 @@ public class DcTracker extends Handler { ArrayList<ApnSetting> dunSettings = null; if (ApnSetting.TYPE_DUN == apnType) { dunSettings = sortApnListByPreferred(fetchDunApns()); dunSettings = fetchDunApns(); } if (DBG) { log("checkForCompatibleDataConnection: apnContext=" + apnContext); Loading Loading @@ -3360,7 +3362,7 @@ public class DcTracker extends Handler { apnList.add(dun); if (DBG) log("buildWaitingApns: X added APN_TYPE_DUN apnList=" + apnList); } return sortApnListByPreferred(apnList); return apnList; } } Loading Loading @@ -3399,7 +3401,6 @@ public class DcTracker extends Handler { if (mPreferredApn.canSupportNetworkType( ServiceState.rilRadioTechnologyToNetworkType(radioTech))) { apnList.add(mPreferredApn); apnList = sortApnListByPreferred(apnList); if (DBG) log("buildWaitingApns: X added preferred apnList=" + apnList); return apnList; } Loading @@ -3414,8 +3415,15 @@ public class DcTracker extends Handler { if (apn.canHandleType(requestedApnTypeBitmask)) { if (apn.canSupportNetworkType( ServiceState.rilRadioTechnologyToNetworkType(radioTech))) { int preferredApnSetId = getPreferredApnSetId(); if (preferredApnSetId == Telephony.Carriers.NO_APN_SET_ID || preferredApnSetId == apn.getApnSetId()) { if (VDBG) log("buildWaitingApns: adding apn=" + apn); apnList.add(apn); } else { log("buildWaitingApns: APN set id " + apn.getApnSetId() + " does not match the preferred set id " + preferredApnSetId); } } else { if (DBG) { log("buildWaitingApns: networkTypeBitmask:" Loading @@ -3430,44 +3438,10 @@ public class DcTracker extends Handler { } } apnList = sortApnListByPreferred(apnList); if (DBG) log("buildWaitingApns: " + apnList.size() + " APNs in the list: " + apnList); return apnList; } /** * Sort a list of ApnSetting objects, with the preferred APNs at the front of the list * * e.g. if the preferred APN set = 2 and we have * 1. APN with apn_set_id = 0 = Carriers.NO_SET_SET (no set is set) * 2. APN with apn_set_id = 1 (not preferred set) * 3. APN with apn_set_id = 2 (preferred set) * Then the return order should be (3, 1, 2) or (3, 2, 1) * * e.g. if the preferred APN set = Carriers.NO_SET_SET (no preferred set) then the * return order can be anything */ @VisibleForTesting public ArrayList<ApnSetting> sortApnListByPreferred(ArrayList<ApnSetting> list) { if (list == null || list.size() <= 1) return list; int preferredApnSetId = getPreferredApnSetId(); if (preferredApnSetId != Telephony.Carriers.NO_APN_SET_ID) { list.sort(new Comparator<ApnSetting>() { @Override public int compare(ApnSetting apn1, ApnSetting apn2) { if (apn1.getApnSetId() == preferredApnSetId) { return -1; } if (apn2.getApnSetId() == preferredApnSetId) { return 1; } return 0; } }); } return list; } private String apnListToString (ArrayList<ApnSetting> apns) { StringBuilder result = new StringBuilder(); for (int i = 0, size = apns.size(); i < size; i++) { Loading
tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java +16 −3 Original line number Diff line number Diff line Loading @@ -1373,7 +1373,7 @@ public class DcTrackerTest extends TelephonyTest { + "0,,,,,,,,,,1"; // apnSetId=0 String dunApnString2 = "[ApnSettingV5]HOT mobile PC,pc.coldm,,,,,,,,,440,10,,DUN,,,true," + "0,,,,,,,,,,0"; + "0,,,,,,,,,,2"; ApnSetting dunApnExpected = ApnSetting.fromString(dunApnString1); Loading @@ -1387,8 +1387,21 @@ public class DcTrackerTest extends TelephonyTest { cr.update(PREFERAPN_URI, values, null, null); // return APN from Setting with apnSetId=1 ArrayList<ApnSetting> dunApns = mDct.sortApnListByPreferred(mDct.fetchDunApns()); assertEquals(2, dunApns.size()); ArrayList<ApnSetting> dunApns = mDct.fetchDunApns(); assertEquals(1, dunApns.size()); assertEquals(1, dunApns.get(0).getApnSetId()); assertTrue(dunApnExpected.equals(dunApns.get(0))); // set that we prefer apn set 2 values = new ContentValues(); values.put(Telephony.Carriers.APN_SET_ID, 2); cr.update(PREFERAPN_URI, values, null, null); // return APN from Setting with apnSetId=2 dunApns = mDct.fetchDunApns(); assertEquals(1, dunApns.size()); assertEquals(2, dunApns.get(0).getApnSetId()); dunApnExpected = ApnSetting.fromString(dunApnString2); assertTrue(dunApnExpected.equals(dunApns.get(0))); } Loading