Search in sources :

Example 41 with ApnSetting

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));
        }
    }
}
Also used : Field(java.lang.reflect.Field) InetAddress(java.net.InetAddress) Uri(android.net.Uri) ApnSetting(android.telephony.data.ApnSetting) SmallTest(android.test.suitebuilder.annotation.SmallTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 42 with ApnSetting

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());
}
Also used : ApnSetting(android.telephony.data.ApnSetting) SmallTest(android.test.suitebuilder.annotation.SmallTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 43 with ApnSetting

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));
}
Also used : ApnSetting(android.telephony.data.ApnSetting) ApnSettingTest.createApnSetting(com.android.internal.telephony.dataconnection.ApnSettingTest.createApnSetting)

Example 44 with ApnSetting

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);
}
Also used : RetryManager(com.android.internal.telephony.RetryManager) ArrayList(java.util.ArrayList) ApnSetting(android.telephony.data.ApnSetting) SmallTest(android.test.suitebuilder.annotation.SmallTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 45 with ApnSetting

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);
}
Also used : RetryManager(com.android.internal.telephony.RetryManager) ArrayList(java.util.ArrayList) ApnSetting(android.telephony.data.ApnSetting) SmallTest(android.test.suitebuilder.annotation.SmallTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

ApnSetting (android.telephony.data.ApnSetting)50 Test (org.junit.Test)30 SmallTest (android.test.suitebuilder.annotation.SmallTest)28 TelephonyTest (com.android.internal.telephony.TelephonyTest)28 ArrayList (java.util.ArrayList)23 RetryManager (com.android.internal.telephony.RetryManager)19 Cursor (android.database.Cursor)5 FlakyTest (androidx.test.filters.FlakyTest)4 ApnSettingTest.createApnSetting (com.android.internal.telephony.dataconnection.ApnSettingTest.createApnSetting)4 ContentResolver (android.content.ContentResolver)3 Uri (android.net.Uri)3 Message (android.os.Message)3 DataProfile (android.telephony.data.DataProfile)3 MediumTest (android.test.suitebuilder.annotation.MediumTest)3 Matchers.anyString (org.mockito.Matchers.anyString)3 NonNull (android.annotation.NonNull)2 PendingIntent (android.app.PendingIntent)2 ContentValues (android.content.ContentValues)2 Intent (android.content.Intent)2 IntentFilter (android.content.IntentFilter)2