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);
}
}
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;
}
}
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);
}
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());
}
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));
}
Aggregations