Search in sources :

Example 1 with HandoverParams

use of com.android.internal.telephony.dataconnection.TransportManager.HandoverParams in project android_frameworks_opt_telephony by LineageOS.

the class TelephonyNetworkFactoryTest method testHandoverNoLiveData.

/**
 * Test handover when there is no live data connection
 */
@Test
@SmallTest
public void testHandoverNoLiveData() throws Exception {
    createMockedTelephonyComponents();
    doReturn(0).when(mSubscriptionController).getSubIdUsingPhoneId(0);
    mTelephonyNetworkFactoryUT.mInternalHandler.sendEmptyMessage(TelephonyNetworkFactory.EVENT_SUBSCRIPTION_CHANGED);
    activatePhoneInPhoneSwitcher(0, true);
    makeDefaultInternetRequest();
    makeSubSpecificMmsRequest(0);
    processAllMessages();
    Field f = TelephonyNetworkFactory.class.getDeclaredField("mInternalHandler");
    f.setAccessible(true);
    Handler h = (Handler) f.get(mTelephonyNetworkFactoryUT);
    HandoverCallback handoverCallback = mock(HandoverCallback.class);
    HandoverParams hp = new HandoverParams(ApnSetting.TYPE_MMS, AccessNetworkConstants.TRANSPORT_TYPE_WLAN, handoverCallback);
    AsyncResult ar = new AsyncResult(null, hp, null);
    h.sendMessage(h.obtainMessage(5, ar));
    processAllMessages();
    doReturn(AccessNetworkConstants.TRANSPORT_TYPE_WLAN).when(mTransportManager).getCurrentTransport(anyInt());
    hp = new HandoverParams(ApnSetting.TYPE_MMS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN, handoverCallback);
    ar = new AsyncResult(null, hp, null);
    h.sendMessage(h.obtainMessage(5, ar));
    processAllMessages();
}
Also used : Field(java.lang.reflect.Field) HandoverCallback(com.android.internal.telephony.dataconnection.TransportManager.HandoverParams.HandoverCallback) HandoverParams(com.android.internal.telephony.dataconnection.TransportManager.HandoverParams) Handler(android.os.Handler) AsyncResult(android.os.AsyncResult) FlakyTest(androidx.test.filters.FlakyTest) SmallTest(android.test.suitebuilder.annotation.SmallTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 2 with HandoverParams

use of com.android.internal.telephony.dataconnection.TransportManager.HandoverParams in project android_frameworks_opt_telephony by LineageOS.

the class TelephonyNetworkFactoryTest method testHandoverActivatingData.

/**
 * Test handover when the data connection is being connected.
 */
@Test
@SmallTest
public void testHandoverActivatingData() throws Exception {
    createMockedTelephonyComponents();
    doReturn(0).when(mSubscriptionController).getSubIdUsingPhoneId(0);
    mTelephonyNetworkFactoryUT.mInternalHandler.sendEmptyMessage(TelephonyNetworkFactory.EVENT_SUBSCRIPTION_CHANGED);
    activatePhoneInPhoneSwitcher(0, true);
    makeDefaultInternetRequest();
    makeSubSpecificMmsRequest(0);
    processAllMessages();
    Field f = TelephonyNetworkFactory.class.getDeclaredField("mInternalHandler");
    f.setAccessible(true);
    Handler h = (Handler) f.get(mTelephonyNetworkFactoryUT);
    HandoverCallback handoverCallback = mock(HandoverCallback.class);
    Mockito.reset(mDcTracker);
    doReturn(mDataConnection).when(mDcTracker).getDataConnectionByApnType(anyString());
    doReturn(false).when(mDataConnection).isActive();
    HandoverParams hp = new HandoverParams(ApnSetting.TYPE_MMS, AccessNetworkConstants.TRANSPORT_TYPE_WLAN, handoverCallback);
    AsyncResult ar = new AsyncResult(null, hp, null);
    h.sendMessage(h.obtainMessage(5, ar));
    processAllMessages();
    verify(mDcTracker, times(1)).releaseNetwork(any(), eq(1));
    verify(mDcTracker, times(1)).requestNetwork(any(), eq(1), any());
}
Also used : Field(java.lang.reflect.Field) HandoverCallback(com.android.internal.telephony.dataconnection.TransportManager.HandoverParams.HandoverCallback) HandoverParams(com.android.internal.telephony.dataconnection.TransportManager.HandoverParams) Handler(android.os.Handler) AsyncResult(android.os.AsyncResult) FlakyTest(androidx.test.filters.FlakyTest) SmallTest(android.test.suitebuilder.annotation.SmallTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 3 with HandoverParams

use of com.android.internal.telephony.dataconnection.TransportManager.HandoverParams in project android_frameworks_opt_telephony by LineageOS.

the class TransportManagerTest method testHandoverNeeded.

@Test
@SmallTest
public void testHandoverNeeded() throws Exception {
    mTransportManager.registerForHandoverNeededEvent(mTestHandler, EVENT_HANDOVER_NEEDED);
    // Initial qualified networks
    List<QualifiedNetworks> networkList = new ArrayList<>(Arrays.asList(new QualifiedNetworks(ApnSetting.TYPE_IMS, new int[] { AccessNetworkType.EUTRAN, AccessNetworkType.UTRAN, AccessNetworkType.IWLAN })));
    mTransportManager.obtainMessage(1, /* EVENT_QUALIFIED_NETWORKS_CHANGED */
    new AsyncResult(null, networkList, null)).sendToTarget();
    processAllMessages();
    // Verify handover needed event was not sent
    verify(mTestHandler, never()).sendMessageAtTime(any(Message.class), anyLong());
    assertEquals(AccessNetworkConstants.TRANSPORT_TYPE_WWAN, mTransportManager.getCurrentTransport(ApnSetting.TYPE_IMS));
    // Now change the order of qualified networks by putting IWLAN first
    networkList = new ArrayList<>(Arrays.asList(new QualifiedNetworks(ApnSetting.TYPE_IMS, new int[] { AccessNetworkType.IWLAN, AccessNetworkType.UTRAN, AccessNetworkType.EUTRAN })));
    mTransportManager.obtainMessage(1, /* EVENT_QUALIFIED_NETWORKS_CHANGED */
    new AsyncResult(null, networkList, null)).sendToTarget();
    processAllMessages();
    ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
    // Verify handover needed event was sent and the the target transport is WLAN.
    verify(mTestHandler, times(1)).sendMessageAtTime(messageArgumentCaptor.capture(), anyLong());
    Message message = messageArgumentCaptor.getValue();
    assertEquals(EVENT_HANDOVER_NEEDED, message.what);
    AsyncResult ar = (AsyncResult) message.obj;
    HandoverParams params = (HandoverParams) ar.result;
    assertEquals(ApnSetting.TYPE_IMS, params.apnType);
    assertEquals(AccessNetworkConstants.TRANSPORT_TYPE_WLAN, params.targetTransport);
    // Notify handover succeeded.
    params.callback.onCompleted(true, false);
    assertEquals(AccessNetworkConstants.TRANSPORT_TYPE_WLAN, mTransportManager.getCurrentTransport(ApnSetting.TYPE_IMS));
    // Now change the order of qualified networks by putting UTRAN first
    networkList = new ArrayList<>(Arrays.asList(new QualifiedNetworks(ApnSetting.TYPE_IMS, new int[] { AccessNetworkType.UTRAN, AccessNetworkType.EUTRAN, AccessNetworkType.IWLAN })));
    mTransportManager.obtainMessage(1, /* EVENT_QUALIFIED_NETWORKS_CHANGED */
    new AsyncResult(null, networkList, null)).sendToTarget();
    processAllMessages();
    messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
    // Verify handover needed event was sent and the the target transport is WWAN.
    verify(mTestHandler, times(2)).sendMessageAtTime(messageArgumentCaptor.capture(), anyLong());
    message = messageArgumentCaptor.getValue();
    assertEquals(EVENT_HANDOVER_NEEDED, message.what);
    ar = (AsyncResult) message.obj;
    params = (HandoverParams) ar.result;
    assertEquals(ApnSetting.TYPE_IMS, params.apnType);
    assertEquals(AccessNetworkConstants.TRANSPORT_TYPE_WWAN, params.targetTransport);
    // The transport should not change before handover complete callback is called.
    assertEquals(AccessNetworkConstants.TRANSPORT_TYPE_WLAN, mTransportManager.getCurrentTransport(ApnSetting.TYPE_IMS));
    // Notify handover succeeded.
    params.callback.onCompleted(true, false);
    assertEquals(AccessNetworkConstants.TRANSPORT_TYPE_WWAN, mTransportManager.getCurrentTransport(ApnSetting.TYPE_IMS));
}
Also used : Message(android.os.Message) ArrayList(java.util.ArrayList) HandoverParams(com.android.internal.telephony.dataconnection.TransportManager.HandoverParams) QualifiedNetworks(com.android.internal.telephony.dataconnection.AccessNetworksManager.QualifiedNetworks) AsyncResult(android.os.AsyncResult) SmallTest(android.test.suitebuilder.annotation.SmallTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 4 with HandoverParams

use of com.android.internal.telephony.dataconnection.TransportManager.HandoverParams in project android_frameworks_opt_telephony by LineageOS.

the class TransportManagerTest method testBackToBackHandoverNeeded.

@Test
@SmallTest
public void testBackToBackHandoverNeeded() throws Exception {
    mTransportManager.registerForHandoverNeededEvent(mTestHandler, EVENT_HANDOVER_NEEDED);
    // Initial qualified networks
    List<QualifiedNetworks> networkList = new ArrayList<>(Arrays.asList(new QualifiedNetworks(ApnSetting.TYPE_IMS, new int[] { AccessNetworkType.EUTRAN, AccessNetworkType.UTRAN, AccessNetworkType.IWLAN })));
    mTransportManager.obtainMessage(1, /* EVENT_QUALIFIED_NETWORKS_CHANGED */
    new AsyncResult(null, networkList, null)).sendToTarget();
    processAllMessages();
    // Verify handover needed event was not sent
    verify(mTestHandler, never()).sendMessageAtTime(any(Message.class), anyLong());
    assertEquals(AccessNetworkConstants.TRANSPORT_TYPE_WWAN, mTransportManager.getCurrentTransport(ApnSetting.TYPE_IMS));
    // Now change the order of qualified networks by putting IWLAN first
    networkList = new ArrayList<>(Arrays.asList(new QualifiedNetworks(ApnSetting.TYPE_IMS, new int[] { AccessNetworkType.IWLAN, AccessNetworkType.UTRAN, AccessNetworkType.EUTRAN })));
    mTransportManager.obtainMessage(1, /* EVENT_QUALIFIED_NETWORKS_CHANGED */
    new AsyncResult(null, networkList, null)).sendToTarget();
    processAllMessages();
    ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
    // Verify handover needed event was sent and the the target transport is WLAN.
    verify(mTestHandler, times(1)).sendMessageAtTime(messageArgumentCaptor.capture(), anyLong());
    Message message = messageArgumentCaptor.getValue();
    assertEquals(EVENT_HANDOVER_NEEDED, message.what);
    AsyncResult ar = (AsyncResult) message.obj;
    HandoverParams params = (HandoverParams) ar.result;
    assertEquals(ApnSetting.TYPE_IMS, params.apnType);
    assertEquals(AccessNetworkConstants.TRANSPORT_TYPE_WLAN, params.targetTransport);
    // Before handover is completed, update the available networks again.
    // This time change the order of qualified networks by putting EUTRAN first
    networkList = new ArrayList<>(Arrays.asList(new QualifiedNetworks(ApnSetting.TYPE_IMS, new int[] { AccessNetworkType.EUTRAN, AccessNetworkType.UTRAN, AccessNetworkType.IWLAN })));
    mTransportManager.obtainMessage(1, /* EVENT_QUALIFIED_NETWORKS_CHANGED */
    new AsyncResult(null, networkList, null)).sendToTarget();
    processAllMessages();
    // Verify handover needed event was sent only once (for the previous change)
    verify(mTestHandler, times(1)).sendMessageAtTime(messageArgumentCaptor.capture(), anyLong());
    LinkedList<List<QualifiedNetworks>> listQueue = getAvailableNetworksList();
    // Verify the list has been queued.
    assertEquals(1, listQueue.size());
    // Notify handover succeeded.
    params.callback.onCompleted(true, false);
    assertEquals(AccessNetworkConstants.TRANSPORT_TYPE_WLAN, mTransportManager.getCurrentTransport(ApnSetting.TYPE_IMS));
    processAllMessages();
    listQueue = getAvailableNetworksList();
    // Verify the queue is empty.
    assertEquals(0, listQueue.size());
    // Verify handover 2nd needed event was sent
    verify(mTestHandler, times(2)).sendMessageAtTime(messageArgumentCaptor.capture(), anyLong());
}
Also used : Message(android.os.Message) ArrayList(java.util.ArrayList) HandoverParams(com.android.internal.telephony.dataconnection.TransportManager.HandoverParams) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) QualifiedNetworks(com.android.internal.telephony.dataconnection.AccessNetworksManager.QualifiedNetworks) AsyncResult(android.os.AsyncResult) SmallTest(android.test.suitebuilder.annotation.SmallTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

AsyncResult (android.os.AsyncResult)4 SmallTest (android.test.suitebuilder.annotation.SmallTest)4 TelephonyTest (com.android.internal.telephony.TelephonyTest)4 HandoverParams (com.android.internal.telephony.dataconnection.TransportManager.HandoverParams)4 Test (org.junit.Test)4 Handler (android.os.Handler)2 Message (android.os.Message)2 FlakyTest (androidx.test.filters.FlakyTest)2 QualifiedNetworks (com.android.internal.telephony.dataconnection.AccessNetworksManager.QualifiedNetworks)2 HandoverCallback (com.android.internal.telephony.dataconnection.TransportManager.HandoverParams.HandoverCallback)2 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1