Search in sources :

Example 36 with ApnSetting

use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.

the class DcTracker method getPreciseDataConnectionState.

/**
 * Return the Precise Data Connection State information
 */
@NonNull
public PreciseDataConnectionState getPreciseDataConnectionState(String apnType, boolean isSuspended, int networkType) {
    int telState = convertDctStateToTelephonyDataState(getState(apnType));
    // voice call state and device + rat capability
    if ((telState == TelephonyManager.DATA_CONNECTED || telState == TelephonyManager.DATA_DISCONNECTING) && isSuspended) {
        telState = TelephonyManager.DATA_SUSPENDED;
    }
    ApnSetting apnSetting = getActiveApnSetting(apnType);
    int apnTypesBitmask = ApnSetting.getApnTypesBitmaskFromString(apnType);
    // TODO: should the data fail cause be populated?
    return new PreciseDataConnectionState(telState, networkType, apnTypesBitmask, apnType, getLinkProperties(apnType), DataFailCause.NONE, apnSetting);
}
Also used : ApnSetting(android.telephony.data.ApnSetting) PreciseDataConnectionState(android.telephony.PreciseDataConnectionState) NonNull(android.annotation.NonNull)

Example 37 with ApnSetting

use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.

the class ApnContextTest method testProvisionApn.

@Test
@SmallTest
public void testProvisionApn() throws Exception {
    mContextFixture.putResource(R.string.mobile_provisioning_apn, "fake_apn");
    ApnSetting myApn = ApnSetting.makeApnSetting(// id
    2163, // numeric
    "44010", // name
    "sp-mode", // apn
    "fake_apn", // proxy
    null, // port
    -1, // mmsc
    null, // mmsproxy
    null, // mmsport
    -1, // user
    "", // password
    "", // authtype
    -1, // types
    ApnSetting.TYPE_DEFAULT | ApnSetting.TYPE_SUPL, // protocol
    ApnSetting.PROTOCOL_IP, // roaming_protocol
    ApnSetting.PROTOCOL_IP, // carrier_enabled
    true, // networktype_bismask
    0, // profile_id
    0, // modem_cognitive
    false, // max_conns
    0, // wait_time
    0, // max_conns_time
    0, // mtu
    0, // mvno_type
    -1, // mnvo_match_data
    "");
    mApnContext.setApnSetting(myApn);
    assertTrue(mApnContext.isProvisioningApn());
    mApnContext.setApnSetting(mApnSetting);
    assertFalse(mApnContext.isProvisioningApn());
}
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 38 with ApnSetting

use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.

the class RILTest method testSetInitialAttachApn.

@FlakyTest
@Test
public void testSetInitialAttachApn() throws Exception {
    ApnSetting apnSetting = ApnSetting.makeApnSetting(-1, "22210", "Vodafone IT", "web.omnitel.it", null, -1, null, null, -1, "", "", 0, ApnSetting.TYPE_DUN, ApnSetting.PROTOCOL_IP, ApnSetting.PROTOCOL_IP, true, 0, 0, false, 0, 0, 0, 0, -1, "");
    DataProfile dataProfile = DcTracker.createDataProfile(apnSetting, apnSetting.getProfileId(), false);
    boolean isRoaming = false;
    mRILUnderTest.setInitialAttachApn(dataProfile, isRoaming, obtainMessage());
    verify(mRadioProxy).setInitialAttachApn(mSerialNumberCaptor.capture(), eq((DataProfileInfo) invokeMethod(mRILInstance, "convertToHalDataProfile10", new Class<?>[] { DataProfile.class }, new Object[] { dataProfile })), eq(dataProfile.isPersistent()), eq(isRoaming));
    verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SET_INITIAL_ATTACH_APN);
}
Also used : DataProfile(android.telephony.data.DataProfile) DataProfileInfo(android.hardware.radio.V1_0.DataProfileInfo) ApnSetting(android.telephony.data.ApnSetting) FlakyTest(androidx.test.filters.FlakyTest) FlakyTest(androidx.test.filters.FlakyTest) Test(org.junit.Test)

Example 39 with ApnSetting

use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.

the class DcTrackerTest method testFetchDunApn.

// Test for fetchDunApns()
@Test
@SmallTest
public void testFetchDunApn() {
    sendInitializationEvents();
    String dunApnString = "[ApnSettingV3]HOT mobile PC,pc.hotm,,,,,,,,,440,10,,DUN,,,true," + "0,,,,,,,,";
    ApnSetting dunApnExpected = ApnSetting.fromString(dunApnString);
    Settings.Global.putString(mContext.getContentResolver(), Settings.Global.TETHER_DUN_APN, dunApnString);
    // should return APN from Setting
    ApnSetting dunApn = mDct.fetchDunApns().get(0);
    assertTrue(dunApnExpected.equals(dunApn));
    Settings.Global.putString(mContext.getContentResolver(), Settings.Global.TETHER_DUN_APN, null);
    // should return APN from db
    dunApn = mDct.fetchDunApns().get(0);
    assertEquals(FAKE_APN5, dunApn.getApnName());
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) ApnSetting(android.telephony.data.ApnSetting) ApnSettingTest.createApnSetting(com.android.internal.telephony.dataconnection.ApnSettingTest.createApnSetting) FlakyTest(androidx.test.filters.FlakyTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) MediumTest(android.test.suitebuilder.annotation.MediumTest) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 40 with ApnSetting

use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.

the class DcTrackerTest method testCheckForCompatibleDataConnectionWithDunWhenIdsChange.

// This tests simulates the race case where the sim status change event is triggered, the
// default data connection is attached, and then the carrier config gets changed which bumps
// the database id which we want to ignore when cleaning up connections and matching against
// the dun APN.  Tests b/158908392.
@Test
@SmallTest
public void testCheckForCompatibleDataConnectionWithDunWhenIdsChange() throws Exception {
    // Set dun as a support apn type of FAKE_APN1
    mApnSettingContentProvider.setFakeApn1Types("default,supl,dun");
    // Enable the default apn
    mSimulatedCommands.setDataCallResult(true, createSetupDataCallResult());
    mDct.enableApn(ApnSetting.TYPE_DEFAULT, DcTracker.REQUEST_TYPE_NORMAL, null);
    waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
    // Load the sim and attach the data connection without firing the carrier changed event
    final String logMsgPrefix = "testCheckForCompatibleDataConnectionWithDunWhenIdsChange: ";
    sendSimStateUpdated(logMsgPrefix);
    sendEventDataConnectionAttached(logMsgPrefix);
    waitForMs(200);
    // Confirm that FAKE_APN1 comes up as a dun candidate
    ApnSetting dunApn = mDct.fetchDunApns().get(0);
    assertEquals(dunApn.getApnName(), FAKE_APN1);
    Map<Integer, ApnContext> apnContexts = mDct.getApnContexts().stream().collect(Collectors.toMap(ApnContext::getApnTypeBitmask, x -> x));
    // Double check that the default apn content is connected while the dun apn context is not
    assertEquals(apnContexts.get(ApnSetting.TYPE_DEFAULT).getState(), DctConstants.State.CONNECTED);
    assertNotEquals(apnContexts.get(ApnSetting.TYPE_DUN).getState(), DctConstants.State.CONNECTED);
    // Change the row ids the same way as what happens when we have old apn values in the
    // carrier table
    mApnSettingContentProvider.setRowIdOffset(100);
    sendCarrierConfigChanged(logMsgPrefix);
    waitForMs(200);
    mDct.enableApn(ApnSetting.TYPE_DUN, DcTracker.REQUEST_TYPE_NORMAL, null);
    waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
    Map<Integer, ApnContext> apnContextsAfterRowIdsChanged = mDct.getApnContexts().stream().collect(Collectors.toMap(ApnContext::getApnTypeBitmask, x -> x));
    // Make sure that the data connection used earlier wasn't cleaned up and still in use.
    assertEquals(apnContexts.get(ApnSetting.TYPE_DEFAULT).getDataConnection(), apnContextsAfterRowIdsChanged.get(ApnSetting.TYPE_DEFAULT).getDataConnection());
    // Check that the DUN is using the same active data connection
    assertEquals(apnContexts.get(ApnSetting.TYPE_DEFAULT).getDataConnection(), apnContextsAfterRowIdsChanged.get(ApnSetting.TYPE_DUN).getDataConnection());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Telephony(android.provider.Telephony) FlakyTest(androidx.test.filters.FlakyTest) Arrays(java.util.Arrays) ZonedDateTime(java.time.ZonedDateTime) Uri(android.net.Uri) TelephonyTest(com.android.internal.telephony.TelephonyTest) DataProfile(android.telephony.data.DataProfile) PendingIntent(android.app.PendingIntent) NetworkCapabilities(android.net.NetworkCapabilities) LinkProperties(android.net.LinkProperties) IBinder(android.os.IBinder) ContentResolver(android.content.ContentResolver) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TelephonyTestUtils.waitForMs(com.android.internal.telephony.TelephonyTestUtils.waitForMs) Matchers.eq(org.mockito.Matchers.eq) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Handler(android.os.Handler) After(org.junit.After) Map(java.util.Map) PersistableBundle(android.os.PersistableBundle) Matchers.anyInt(org.mockito.Matchers.anyInt) MockContentResolver(android.test.mock.MockContentResolver) Assert.fail(org.junit.Assert.fail) SubscriptionPlan(android.telephony.SubscriptionPlan) CarrierConfigManager(android.telephony.CarrierConfigManager) Mockito.doReturn(org.mockito.Mockito.doReturn) Method(java.lang.reflect.Method) MediumTest(android.test.suitebuilder.annotation.MediumTest) Mockito.clearInvocations(org.mockito.Mockito.clearInvocations) ServiceState(android.telephony.ServiceState) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) IntentFilter(android.content.IntentFilter) NetworkPolicyManager(android.net.NetworkPolicyManager) ISub(com.android.internal.telephony.ISub) Collectors(java.util.stream.Collectors) AccessNetworkType(android.telephony.AccessNetworkConstants.AccessNetworkType) Matchers.any(org.mockito.Matchers.any) Objects(java.util.Objects) NetworkRegistrationInfo(android.telephony.NetworkRegistrationInfo) List(java.util.List) Message(android.os.Message) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) ContentValues(android.content.ContentValues) Context(android.content.Context) AccessNetworkConstants(android.telephony.AccessNetworkConstants) ApnSetting(android.telephony.data.ApnSetting) DctConstants(com.android.internal.telephony.DctConstants) SmallTest(android.test.suitebuilder.annotation.SmallTest) Mock(org.mockito.Mock) Pair(android.util.Pair) AsyncResult(android.os.AsyncResult) Intent(android.content.Intent) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) PhoneConstants(com.android.internal.telephony.PhoneConstants) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Mockito.timeout(org.mockito.Mockito.timeout) Answer(org.mockito.stubbing.Answer) DataService(android.telephony.data.DataService) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentCaptor(org.mockito.ArgumentCaptor) TelephonyDisplayInfo(android.telephony.TelephonyDisplayInfo) SubscriptionManager(android.telephony.SubscriptionManager) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) TelephonyManager(android.telephony.TelephonyManager) Matchers.anyLong(org.mockito.Matchers.anyLong) Settings(android.provider.Settings) R(com.android.internal.R) SubscriptionInfo(android.telephony.SubscriptionInfo) Cursor(android.database.Cursor) Before(org.junit.Before) Period(java.time.Period) AlarmManager(android.app.AlarmManager) NetworkAgent(android.net.NetworkAgent) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) TextUtils(android.text.TextUtils) Test(org.junit.Test) Field(java.lang.reflect.Field) NetworkRequest(android.net.NetworkRequest) MockContentProvider(android.test.mock.MockContentProvider) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) SignalStrength(android.telephony.SignalStrength) ApnSettingTest.createApnSetting(com.android.internal.telephony.dataconnection.ApnSettingTest.createApnSetting) Ignore(org.junit.Ignore) HandlerThread(android.os.HandlerThread) MatrixCursor(android.database.MatrixCursor) ServiceInfo(android.content.pm.ServiceInfo) Assert.assertEquals(org.junit.Assert.assertEquals) SetupDataCallResult(android.hardware.radio.V1_0.SetupDataCallResult) Matchers.anyString(org.mockito.Matchers.anyString) ApnSetting(android.telephony.data.ApnSetting) ApnSettingTest.createApnSetting(com.android.internal.telephony.dataconnection.ApnSettingTest.createApnSetting) FlakyTest(androidx.test.filters.FlakyTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) MediumTest(android.test.suitebuilder.annotation.MediumTest) SmallTest(android.test.suitebuilder.annotation.SmallTest) 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