use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.
the class ApnSettingTest method testFromString.
@Test
@SmallTest
public void testFromString() throws Exception {
final int dunTypesBitmask = ApnSetting.TYPE_DUN;
final int mmsTypesBitmask = ApnSetting.TYPE_MMS | ApnSetting.TYPE_ALL;
ApnSetting expectedApn;
String testString;
// A real-world v1 example string.
testString = "Vodafone IT,web.omnitel.it,,,,,,,,,222,10,,DUN";
expectedApn = ApnSetting.makeApnSetting(-1, "22210", "Vodafone IT", "web.omnitel.it", "", -1, null, "", -1, "", "", 0, dunTypesBitmask, ApnSetting.PROTOCOL_IP, ApnSetting.PROTOCOL_IP, true, 0, 0, false, 0, 0, 0, 0, -1, "");
assertApnSettingEqual(expectedApn, ApnSetting.fromString(testString));
// A v2 string.
testString = "[ApnSettingV2] Name,apn,,,,,,,,,123,45,,mms|*,IPV6,IP,true,14";
int networkTypeBitmask = 1 << (13 - 1);
expectedApn = ApnSetting.makeApnSetting(-1, "12345", "Name", "apn", "", -1, null, "", -1, "", "", 0, mmsTypesBitmask, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true, networkTypeBitmask, 0, false, 0, 0, 0, 0, -1, "");
assertApnSettingEqual(expectedApn, ApnSetting.fromString(testString));
// A v2 string with spaces.
testString = "[ApnSettingV2] Name,apn, ,,,,,,,,123,45,,mms|*,IPV6, IP,true,14";
expectedApn = ApnSetting.makeApnSetting(-1, "12345", "Name", "apn", "", -1, null, "", -1, "", "", 0, mmsTypesBitmask, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true, networkTypeBitmask, 0, false, 0, 0, 0, 0, -1, "");
assertApnSettingEqual(expectedApn, ApnSetting.fromString(testString));
// A v3 string.
testString = "[ApnSettingV3] Name,apn,,,,,,,,,123,45,,mms|*,IPV6,IP,true,14,,,,,,,spn,testspn";
expectedApn = ApnSetting.makeApnSetting(-1, "12345", "Name", "apn", "", -1, null, "", -1, "", "", 0, mmsTypesBitmask, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true, networkTypeBitmask, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "testspn");
assertApnSettingEqual(expectedApn, ApnSetting.fromString(testString));
// A v4 string with network type bitmask.
testString = "[ApnSettingV4] Name,apn,,,,,,,,,123,45,,mms|*,IPV6,IP,true,0,,,,,,,spn,testspn,6";
networkTypeBitmask = 1 << (6 - 1);
expectedApn = ApnSetting.makeApnSetting(-1, "12345", "Name", "apn", "", -1, null, "", -1, "", "", 0, mmsTypesBitmask, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true, networkTypeBitmask, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "testspn");
assertApnSettingEqual(expectedApn, ApnSetting.fromString(testString));
testString = "[ApnSettingV4] Name,apn,,,,,,,,,123,45,,mms|*,IPV6,IP,true,0,,,,,,,spn,testspn," + "4|5|6|7|8|12|13|14|19";
// The value was calculated by adding "4|5|6|7|8|12|13|14|19".
networkTypeBitmask = 276728;
expectedApn = ApnSetting.makeApnSetting(-1, "12345", "Name", "apn", "", -1, null, "", -1, "", "", 0, mmsTypesBitmask, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true, networkTypeBitmask, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "testspn");
assertApnSettingEqual(expectedApn, ApnSetting.fromString(testString));
// A v4 string with network type bitmask and compatible bearer bitmask.
testString = "[ApnSettingV4] Name,apn,,,,,,,,,123,45,,mms|*,IPV6,IP,true,8,,,,,,,spn,testspn, 6";
networkTypeBitmask = 1 << (6 - 1);
expectedApn = ApnSetting.makeApnSetting(-1, "12345", "Name", "apn", "", -1, null, "", -1, "", "", 0, mmsTypesBitmask, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true, networkTypeBitmask, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "testspn");
assertApnSettingEqual(expectedApn, ApnSetting.fromString(testString));
// A v4 string with network type bitmask and incompatible bearer bitmask.
testString = "[ApnSettingV4] Name,apn,,,,,,,,,123,45,,mms|*,IPV6,IP,true,9,,,,,,,spn,testspn, 6";
expectedApn = ApnSetting.makeApnSetting(-1, "12345", "Name", "apn", "", -1, null, "", -1, "", "", 0, mmsTypesBitmask, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true, networkTypeBitmask, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "testspn");
assertApnSettingEqual(expectedApn, ApnSetting.fromString(testString));
// A v5 string with apnSetId=0
testString = "[ApnSettingV5] Name,apn,,,,,,,,,123,45,,mms|*,IPV6,IP,true,0,,,,,,,spn,testspn,0,0";
expectedApn = ApnSetting.makeApnSetting(-1, "12345", "Name", "apn", "", -1, null, "", -1, "", "", 0, mmsTypesBitmask, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true, 0, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "testspn");
assertApnSettingEqual(expectedApn, ApnSetting.fromString(testString));
// A v5 string with apnSetId=3
testString = "[ApnSettingV5] Name,apn,,,,,,,,,123,45,,mms|*,IPV6,IP,true,0,,,,,,,spn,testspn,0,3";
expectedApn = ApnSetting.makeApnSetting(-1, "12345", "Name", "apn", "", -1, null, "", -1, "", "", 0, mmsTypesBitmask, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true, 0, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "testspn", 3, -1, -1);
assertApnSettingEqual(expectedApn, ApnSetting.fromString(testString));
// A v6 string with carrierId=100
testString = "[ApnSettingV5] Name,apn,,,,,,,,,123,45,,mms|*,IPV6,IP,true,0,,,,,,,spn,testspn,0,3," + "100";
expectedApn = ApnSetting.makeApnSetting(-1, "12345", "Name", "apn", "", -1, null, "", -1, "", "", 0, mmsTypesBitmask, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true, 0, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "testspn", 3, 100, -1);
assertApnSettingEqual(expectedApn, ApnSetting.fromString(testString));
// A v7 string with skip_464xlat=1
testString = "[ApnSettingV7] Name,apn,,,,,,,,,123,45,,mms|*,IPV6,IP,true,0,,,,,,,spn,testspn,0,3," + "-1, 1";
expectedApn = ApnSetting.makeApnSetting(-1, "12345", "Name", "apn", "", -1, null, "", -1, "", "", 0, mmsTypesBitmask, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true, 0, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "testspn", 3, -1, 1);
assertApnSettingEqual(expectedApn, ApnSetting.fromString(testString));
// Return no apn if insufficient fields given.
testString = "[ApnSettingV3] Name,apn,,,,,,,,,123, 45,,mms|*";
assertEquals(null, ApnSetting.fromString(testString));
testString = "Name,apn,,,,,,,,,123, 45,";
assertEquals(null, ApnSetting.fromString(testString));
}
use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.
the class ApnSettingTest method testCanHandleNetwork.
@Test
@SmallTest
public void testCanHandleNetwork() throws Exception {
ApnSetting apn1 = ApnSetting.makeApnSetting(1234, "310260", "", "ims", null, -1, null, null, -1, "", "", -1, ApnSetting.TYPE_IMS, ApnSetting.PROTOCOL_IPV6, -1, true, (int) (TelephonyManager.NETWORK_TYPE_BITMASK_LTE | TelephonyManager.NETWORK_TYPE_BITMASK_UMTS), 0, false, 0, 0, 0, 1440, -1, "");
ApnSetting apn2 = ApnSetting.makeApnSetting(1235, "310260", "", "ims", null, -1, null, null, -1, "", "", -1, ApnSetting.TYPE_IMS, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IPV6, true, (int) (TelephonyManager.NETWORK_TYPE_BITMASK_EDGE | TelephonyManager.NETWORK_TYPE_BITMASK_GPRS), 0, false, 0, 0, 0, 1440, -1, "");
assertFalse(apn1.canSupportNetworkType(TelephonyManager.NETWORK_TYPE_1xRTT));
assertTrue(apn1.canSupportNetworkType(TelephonyManager.NETWORK_TYPE_LTE));
assertTrue(apn1.canSupportNetworkType(TelephonyManager.NETWORK_TYPE_UMTS));
assertFalse(apn2.canSupportNetworkType(TelephonyManager.NETWORK_TYPE_1xRTT));
assertFalse(apn2.canSupportNetworkType(TelephonyManager.NETWORK_TYPE_LTE));
assertTrue(apn2.canSupportNetworkType(TelephonyManager.NETWORK_TYPE_GPRS));
assertTrue(apn2.canSupportNetworkType(TelephonyManager.NETWORK_TYPE_EDGE));
assertTrue(apn2.canSupportNetworkType(TelephonyManager.NETWORK_TYPE_GSM));
}
use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.
the class RetryManagerTest method testRetryManagerEmpty.
/**
* Test the behavior of a retry manager with no waiting APNs set.
*/
@Test
@SmallTest
public void testRetryManagerEmpty() throws Exception {
mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_DATA_CALL_RETRY_CONFIG_STRINGS, new String[] { "default:2000" });
RetryManager rm = new RetryManager(mPhone, "default");
long delay = rm.getDelayForNextApn(false);
assertEquals(RetryManager.NO_RETRY, delay);
ApnSetting nextApn = rm.getNextApnSetting();
assertTrue(nextApn == null);
delay = rm.getDelayForNextApn(false);
assertEquals(RetryManager.NO_RETRY, delay);
}
use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.
the class RetryManagerTest method testRetryManagerApnPermanentFailedWithTwoApns.
/**
* Test the permanent fail scenario with two APNs configured.
*/
@Test
@SmallTest
public void testRetryManagerApnPermanentFailedWithTwoApns() throws Exception {
mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_DATA_CALL_RETRY_CONFIG_STRINGS, new String[] { "xyz : 1000,4000,7000" });
ArrayList<ApnSetting> waitingApns = new ArrayList<ApnSetting>();
ApnSetting myApn1 = ApnSetting.makeApnSetting(mApn1);
ApnSetting myApn2 = ApnSetting.makeApnSetting(mApn2);
waitingApns.add(myApn1);
waitingApns.add(myApn2);
RetryManager rm = new RetryManager(mPhone, "xyz");
rm.setWaitingApns(waitingApns);
ApnSetting nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn1));
long delay = rm.getDelayForNextApn(false);
assertEquals(20000, delay);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn2));
delay = rm.getDelayForNextApn(false);
assertEquals(1000, delay);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn1));
delay = rm.getDelayForNextApn(false);
assertEquals(20000, delay);
rm.markApnPermanentFailed(myApn1);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn2));
delay = rm.getDelayForNextApn(false);
assertEquals(4000, delay);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn2));
delay = rm.getDelayForNextApn(false);
assertEquals(7000, delay);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn2));
delay = rm.getDelayForNextApn(false);
assertEquals(RetryManager.NO_RETRY, delay);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn2));
delay = rm.getDelayForNextApn(false);
assertEquals(RetryManager.NO_RETRY, delay);
}
use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.
the class RetryManagerTest method testRetryManagerDelayWithRandomization.
/**
* Test the randomized delay scenario.
*/
@Test
@SmallTest
public void testRetryManagerDelayWithRandomization() throws Exception {
mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_DATA_CALL_RETRY_CONFIG_STRINGS, new String[] { "default:default_randomization=1000,3000:2000,6000:3000,10000" });
ArrayList<ApnSetting> waitingApns = new ArrayList<ApnSetting>();
waitingApns.add(ApnSetting.makeApnSetting(mApn1));
RetryManager rm = new RetryManager(mPhone, "default");
rm.setWaitingApns(waitingApns);
ApnSetting nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn1));
long delay = rm.getDelayForNextApn(false);
// 3s + 2s rand
assertTrue(delay >= 3000 && delay < 5000);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn1));
delay = rm.getDelayForNextApn(false);
// 6s + 3s rand
assertTrue(delay >= 6000 && delay < 9000);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn1));
delay = rm.getDelayForNextApn(false);
// 10s + 1s default rand
assertTrue(delay >= 10000 && delay < 11000);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn1));
delay = rm.getDelayForNextApn(false);
assertEquals(RetryManager.NO_RETRY, delay);
}
Aggregations