use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.
the class ApnSettingTest method testEquals.
@Test
@SmallTest
public void testEquals() throws Exception {
final int dummyInt = 1;
final String dummyString = "dummy";
final String[] dummyStringArr = new String[] { "dummy" };
final InetAddress dummyProxyAddress = InetAddress.getByAddress(new byte[] { 0, 0, 0, 0 });
final Uri dummyUri = Uri.parse("www.google.com");
// base apn
ApnSetting baseApn = createApnSetting(ApnSetting.TYPE_MMS | ApnSetting.TYPE_DEFAULT);
Field[] fields = ApnSetting.class.getDeclaredFields();
for (Field f : fields) {
int modifiers = f.getModifiers();
if (Modifier.isStatic(modifiers) || !Modifier.isFinal(modifiers)) {
continue;
}
f.setAccessible(true);
ApnSetting testApn = null;
if (int.class.equals(f.getType())) {
testApn = ApnSetting.makeApnSetting(baseApn);
f.setInt(testApn, dummyInt + f.getInt(testApn));
} else if (boolean.class.equals(f.getType())) {
testApn = ApnSetting.makeApnSetting(baseApn);
f.setBoolean(testApn, !f.getBoolean(testApn));
} else if (String.class.equals(f.getType())) {
testApn = ApnSetting.makeApnSetting(baseApn);
f.set(testApn, dummyString);
} else if (String[].class.equals(f.getType())) {
testApn = ApnSetting.makeApnSetting(baseApn);
f.set(testApn, dummyStringArr);
} else if (InetAddress.class.equals(f.getType())) {
testApn = ApnSetting.makeApnSetting(baseApn);
f.set(testApn, dummyProxyAddress);
} else if (Uri.class.equals(f.getType())) {
testApn = ApnSetting.makeApnSetting(baseApn);
f.set(testApn, dummyUri);
} else {
fail("Unsupported field:" + f.getName());
}
if (testApn != null) {
assertFalse(f.getName() + " is NOT checked", testApn.equals(baseApn));
}
}
}
use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.
the class ApnSettingTest method testToString.
@Test
@SmallTest
public void testToString() throws Exception {
// Use default apn_set_id constructor.
ApnSetting apn = ApnSetting.makeApnSetting(99, "12345", "Name", "apn", null, 10, null, null, -1, "user", "password", 0, ApnSetting.TYPE_DEFAULT, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true, 4096, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "");
String expected = "[ApnSettingV7] Name, 99, 12345, apn, null, " + "null, null, null, 10, 0, hipri | default, " + "IPV6, IP, true, 0, false, 0, 0, 0, 0, spn, , false, 4096, 0, -1, -1";
assertEquals(expected, apn.toString());
final int networkTypeBitmask = 1 << (14 - 1);
apn = ApnSetting.makeApnSetting(99, "12345", "Name", "apn", null, 10, null, null, -1, "user", "password", 0, ApnSetting.TYPE_DEFAULT, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true, networkTypeBitmask, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "", 3, -1, 1);
expected = "[ApnSettingV7] Name, 99, 12345, apn, null, " + "null, null, null, 10, 0, hipri | default, " + "IPV6, IP, true, 0, false, 0, 0, 0, 0, spn, , false, 8192, 3, -1, 1";
assertEquals(expected, apn.toString());
}
use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.
the class DcTrackerTest method initApns.
private void initApns(String targetApn, String[] canHandleTypes) {
doReturn(targetApn).when(mApnContext).getApnType();
doReturn(ApnSetting.getApnTypesBitmaskFromString(mApnContext.getApnType())).when(mApnContext).getApnTypeBitmask();
doReturn(true).when(mApnContext).isConnectable();
ApnSetting apnSetting = createApnSetting(ApnSetting.getApnTypesBitmaskFromString(TextUtils.join(",", canHandleTypes)));
doReturn(apnSetting).when(mApnContext).getNextApnSetting();
doReturn(apnSetting).when(mApnContext).getApnSetting();
doReturn(mDataConnection).when(mApnContext).getDataConnection();
doReturn(true).when(mApnContext).isEnabled();
doReturn(true).when(mApnContext).isDependencyMet();
doReturn(true).when(mApnContext).isReady();
doReturn(false).when(mApnContext).hasRestrictedRequests(eq(true));
}
use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.
the class RetryManagerTest method testRetryManagerTwoApnsTwoRetries.
/**
* Test the basic retry scenario where two waiting APNs with two retries configured.
*/
@Test
@SmallTest
public void testRetryManagerTwoApnsTwoRetries() throws Exception {
mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_DATA_CALL_RETRY_CONFIG_STRINGS, new String[] { "dun:2000,5000" });
ArrayList<ApnSetting> waitingApns = new ArrayList<ApnSetting>();
waitingApns.add(ApnSetting.makeApnSetting(mApn1));
waitingApns.add(ApnSetting.makeApnSetting(mApn2));
RetryManager rm = new RetryManager(mPhone, "dun");
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(2000, delay);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn1));
delay = rm.getDelayForNextApn(false);
assertEquals(20000, delay);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn2));
delay = rm.getDelayForNextApn(false);
assertEquals(5000, delay);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn1));
delay = rm.getDelayForNextApn(false);
assertEquals(20000, 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 testRetryManagerOneApnTwoRetries.
/**
* Test the basic retry scenario where only one APN with two retries configured.
*/
@Test
@SmallTest
public void testRetryManagerOneApnTwoRetries() throws Exception {
mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_DATA_CALL_RETRY_CONFIG_STRINGS, new String[] { "supl:2000,3000" });
ArrayList<ApnSetting> waitingApns = new ArrayList<ApnSetting>();
waitingApns.add(ApnSetting.makeApnSetting(mApn1));
RetryManager rm = new RetryManager(mPhone, "supl");
rm.setWaitingApns(waitingApns);
ApnSetting nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn1));
long delay = rm.getDelayForNextApn(false);
assertEquals(2000, delay);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn1));
delay = rm.getDelayForNextApn(false);
assertEquals(3000, delay);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn1));
delay = rm.getDelayForNextApn(false);
assertEquals(RetryManager.NO_RETRY, delay);
// No matter how many times we call getNextApnSetting, it should always return the next APN
// with NO_RETRY because we've already reached the maximum retry count.
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn1));
delay = rm.getDelayForNextApn(false);
assertEquals(RetryManager.NO_RETRY, delay);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn1));
delay = rm.getDelayForNextApn(false);
assertEquals(RetryManager.NO_RETRY, delay);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn1));
delay = rm.getDelayForNextApn(false);
assertEquals(RetryManager.NO_RETRY, delay);
nextApn = rm.getNextApnSetting();
assertTrue(nextApn.equals(mApn1));
delay = rm.getDelayForNextApn(false);
assertEquals(RetryManager.NO_RETRY, delay);
}
Aggregations