Search in sources :

Example 1 with QualifiedNetworks

use of com.android.internal.telephony.dataconnection.AccessNetworksManager.QualifiedNetworks in project android_frameworks_opt_telephony by LineageOS.

the class TransportManager method updateAvailableNetworks.

private void updateAvailableNetworks() {
    if (isHandoverPending()) {
        log("There's ongoing handover. Will update networks once handover completed.");
        return;
    }
    if (mAvailableNetworksList.size() == 0) {
        log("Nothing in the available network list queue.");
        return;
    }
    List<QualifiedNetworks> networksList = mAvailableNetworksList.remove();
    logl("updateAvailableNetworks: " + networksList);
    for (QualifiedNetworks networks : networksList) {
        if (areNetworksValid(networks)) {
            if (isHandoverNeeded(networks)) {
                // If handover is needed, perform the handover works. For now we only pick the
                // first element because it's the most preferred. In the future we should also
                // consider the rest in the list, for example, the first one violates
                // carrier/user policy.
                int targetTransport = ACCESS_NETWORK_TRANSPORT_TYPE_MAP.get(networks.qualifiedNetworks[0]);
                logl("Handover needed for APN type: " + ApnSetting.getApnTypeString(networks.apnType) + ", target transport: " + AccessNetworkConstants.transportTypeToString(targetTransport));
                mPendingHandoverApns.put(networks.apnType, targetTransport);
                mHandoverNeededEventRegistrants.notifyResult(new HandoverParams(networks.apnType, targetTransport, (success, fallback) -> {
                    // The callback for handover completed.
                    if (success) {
                        logl("Handover succeeded.");
                    } else {
                        logl("APN type " + ApnSetting.getApnTypeString(networks.apnType) + " handover to " + AccessNetworkConstants.transportTypeToString(targetTransport) + " failed." + ", fallback=" + fallback);
                    }
                    if (success || !fallback) {
                        // If handover succeeds or failed without falling back
                        // to the original transport, we should move to the new
                        // transport (even if it is failed).
                        setCurrentTransport(networks.apnType, targetTransport);
                    }
                    mPendingHandoverApns.delete(networks.apnType);
                    // need to process the rest.
                    if (mAvailableNetworksList.size() > 0) {
                        sendEmptyMessage(EVENT_UPDATE_AVAILABLE_NETWORKS);
                    }
                }));
            }
            mCurrentAvailableNetworks.put(networks.apnType, networks.qualifiedNetworks);
        } else {
            loge("Invalid networks received: " + networks);
        }
    }
    // If there are still pending available network changes, we need to process the rest.
    if (mAvailableNetworksList.size() > 0) {
        sendEmptyMessage(EVENT_UPDATE_AVAILABLE_NETWORKS);
    }
}
Also used : AccessNetworkConstants(android.telephony.AccessNetworkConstants) ApnSetting(android.telephony.data.ApnSetting) Arrays(java.util.Arrays) SparseIntArray(android.util.SparseIntArray) AsyncResult(android.os.AsyncResult) HashMap(java.util.HashMap) ApnType(android.telephony.Annotation.ApnType) LocalLog(android.util.LocalLog) ArrayUtils(com.android.internal.telephony.util.ArrayUtils) Retention(java.lang.annotation.Retention) Rlog(com.android.telephony.Rlog) Handler(android.os.Handler) Map(java.util.Map) StringDef(android.annotation.StringDef) QualifiedNetworks(com.android.internal.telephony.dataconnection.AccessNetworksManager.QualifiedNetworks) CarrierConfigManager(android.telephony.CarrierConfigManager) LinkedList(java.util.LinkedList) PrintWriter(java.io.PrintWriter) Nullable(android.annotation.Nullable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Phone(com.android.internal.telephony.Phone) NonNull(android.annotation.NonNull) Collectors(java.util.stream.Collectors) RegistrantList(android.os.RegistrantList) AccessNetworkType(android.telephony.AccessNetworkConstants.AccessNetworkType) SystemProperties(android.os.SystemProperties) SparseArray(android.util.SparseArray) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) List(java.util.List) Message(android.os.Message) FileDescriptor(java.io.FileDescriptor) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter) RIL(com.android.internal.telephony.RIL) RetentionPolicy(java.lang.annotation.RetentionPolicy) QualifiedNetworks(com.android.internal.telephony.dataconnection.AccessNetworksManager.QualifiedNetworks)

Example 2 with QualifiedNetworks

use of com.android.internal.telephony.dataconnection.AccessNetworksManager.QualifiedNetworks in project android_frameworks_opt_telephony by LineageOS.

the class TransportManager method handleMessage.

@Override
public void handleMessage(Message msg) {
    switch(msg.what) {
        case EVENT_QUALIFIED_NETWORKS_CHANGED:
            AsyncResult ar = (AsyncResult) msg.obj;
            List<QualifiedNetworks> networks = (List<QualifiedNetworks>) ar.result;
            mAvailableNetworksList.add(networks);
            sendEmptyMessage(EVENT_UPDATE_AVAILABLE_NETWORKS);
            break;
        case EVENT_UPDATE_AVAILABLE_NETWORKS:
            updateAvailableNetworks();
            break;
        default:
            loge("Unexpected event " + msg.what);
            break;
    }
}
Also used : LinkedList(java.util.LinkedList) RegistrantList(android.os.RegistrantList) List(java.util.List) QualifiedNetworks(com.android.internal.telephony.dataconnection.AccessNetworksManager.QualifiedNetworks) AsyncResult(android.os.AsyncResult)

Example 3 with QualifiedNetworks

use of com.android.internal.telephony.dataconnection.AccessNetworksManager.QualifiedNetworks in project android_frameworks_opt_telephony by LineageOS.

the class TransportManagerTest method getAvailableNetworksList.

private LinkedList<List<QualifiedNetworks>> getAvailableNetworksList() throws Exception {
    Field f = TransportManager.class.getDeclaredField("mAvailableNetworksList");
    f.setAccessible(true);
    return (LinkedList<List<QualifiedNetworks>>) f.get(mTransportManager);
}
Also used : Field(java.lang.reflect.Field) QualifiedNetworks(com.android.internal.telephony.dataconnection.AccessNetworksManager.QualifiedNetworks) LinkedList(java.util.LinkedList)

Example 4 with QualifiedNetworks

use of com.android.internal.telephony.dataconnection.AccessNetworksManager.QualifiedNetworks in project android_frameworks_opt_telephony by LineageOS.

the class TransportManagerTest method testHandoverNotNeeded.

@Test
@SmallTest
public void testHandoverNotNeeded() 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());
    // Now change the order of qualified networks by swapping EUTRAN and UTRAN.
    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();
    // Verify handover needed event was not sent
    verify(mTestHandler, never()).sendMessageAtTime(any(Message.class), anyLong());
}
Also used : Message(android.os.Message) ArrayList(java.util.ArrayList) 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 5 with QualifiedNetworks

use of com.android.internal.telephony.dataconnection.AccessNetworksManager.QualifiedNetworks 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)

Aggregations

QualifiedNetworks (com.android.internal.telephony.dataconnection.AccessNetworksManager.QualifiedNetworks)6 AsyncResult (android.os.AsyncResult)5 Message (android.os.Message)4 LinkedList (java.util.LinkedList)4 SmallTest (android.test.suitebuilder.annotation.SmallTest)3 TelephonyTest (com.android.internal.telephony.TelephonyTest)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Test (org.junit.Test)3 RegistrantList (android.os.RegistrantList)2 HandoverParams (com.android.internal.telephony.dataconnection.TransportManager.HandoverParams)2 NonNull (android.annotation.NonNull)1 Nullable (android.annotation.Nullable)1 StringDef (android.annotation.StringDef)1 Handler (android.os.Handler)1 SystemProperties (android.os.SystemProperties)1 AccessNetworkConstants (android.telephony.AccessNetworkConstants)1 AccessNetworkType (android.telephony.AccessNetworkConstants.AccessNetworkType)1 ApnType (android.telephony.Annotation.ApnType)1 CarrierConfigManager (android.telephony.CarrierConfigManager)1