Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 195f896d authored by Jack Yu's avatar Jack Yu Committed by Sarah Chin
Browse files

Adjusted APN type capability and priority

Adjusted APN type capability and priority based on
latest attached network requests.

If a network supports both internet and MMS, but only
internet requests are attached, then this network
is more considered as an internet network.

Fix: 230519858
Test: Sanity + atest DataNetworkTest

Change-Id: Id7b20d4a3f1d2467bd20ec40e25c7bac357accce
Merged-In: Id7b20d4a3f1d2467bd20ec40e25c7bac357accce
parent 01adfe2b
Loading
Loading
Loading
Loading
+37 −12
Original line number Diff line number Diff line
@@ -1595,7 +1595,7 @@ public class DataNetwork extends StateMachine {
        for (TelephonyNetworkRequest networkRequest : requestList) {
            if (!mDataNetworkController.isNetworkRequestExisting(networkRequest)) {
                failedList.add(networkRequest);
                log("Attached failed. Network request was already removed.");
                log("Attached failed. Network request was already removed. " + networkRequest);
            } else if (!networkRequest.canBeSatisfiedBy(getNetworkCapabilities())) {
                failedList.add(networkRequest);
                log("Attached failed. Cannot satisfy the network request "
@@ -2698,26 +2698,51 @@ public class DataNetwork extends StateMachine {

    /**
     * Get the APN type network capability. If there are more than one capabilities that are
     * APN-types, then return the highest priority one.
     * APN types, then return the highest priority one which also has associated network request.
     * For example, if the network supports both MMS and internet, but only internet request
     * attached at this time, then the capability would be internet. Later on if MMS network request
     * attached to this network, then the APN type capability would be MMS.
     *
     * @return The APN type network capability from this network.
     *
     * @see #getPriority()
     */
    public @NetCapability int getApnTypeNetworkCapability() {
        if (!mAttachedNetworkRequestList.isEmpty()) {
            // The highest priority network request is always at the top of list.
            return mAttachedNetworkRequestList.get(0).getApnTypeNetworkCapability();
        } else {
            return Arrays.stream(getNetworkCapabilities().getCapabilities()).boxed()
                .filter(cap -> DataUtils.networkCapabilityToApnType(cap) != ApnSetting.TYPE_NONE)
                    .filter(cap -> DataUtils.networkCapabilityToApnType(cap)
                            != ApnSetting.TYPE_NONE)
                    .max(Comparator.comparingInt(mDataConfigManager::getNetworkCapabilityPriority))
                    .orElse(-1);
        }
    }

    /**
     * @return The priority of the network. The priority is derived from the highest priority
     * capability of the network.
     * Get the priority of the network. The priority is derived from the highest priority capability
     * which also has such associated network request. For example, if the network supports both
     * MMS and internet, but only has internet request attached, then this network has internet's
     * priority. Later on when the MMS request attached to this network, the network's priority will
     * be updated to MMS's priority.
     *
     * @return The priority of the network.
     *
     * @see #getApnTypeNetworkCapability()
     */
    public int getPriority() {
        if (!mAttachedNetworkRequestList.isEmpty()) {
            // The highest priority network request is always at the top of list.
            return mAttachedNetworkRequestList.get(0).getPriority();
        } else {
            // If all network requests are already detached, then just pick the highest priority
            // capability's priority.
            return Arrays.stream(getNetworkCapabilities().getCapabilities()).boxed()
                    .map(mDataConfigManager::getNetworkCapabilityPriority)
                    .max(Integer::compare)
                .orElse(-1);
                    .orElse(0);
        }
    }

    /**
+58 −20
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.data.DataEvaluation.DataAllowedReason;
import com.android.internal.telephony.data.DataNetwork.DataNetworkCallback;
import com.android.internal.telephony.data.DataNetworkController.NetworkRequestList;
import com.android.internal.telephony.data.LinkBandwidthEstimator.LinkBandwidthEstimatorCallback;
import com.android.internal.telephony.metrics.DataCallSessionStats;

@@ -313,6 +314,8 @@ public class DataNetworkTest extends TelephonyTest {
        doReturn(true).when(mDataConfigManager).isTempNotMeteredSupportedByCarrier();
        doReturn(true).when(mDataConfigManager).isImsDelayTearDownEnabled();
        doReturn(FAKE_IMSI).when(mPhone).getSubscriberId();
        doReturn(true).when(mDataNetworkController)
                .isNetworkRequestExisting(any(TelephonyNetworkRequest.class));

        serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE,
                NetworkRegistrationInfo.REGISTRATION_STATE_HOME);
@@ -347,8 +350,7 @@ public class DataNetworkTest extends TelephonyTest {
    // expected, and make sure it is always sorted.
    @Test
    public void testCreateDataNetwork() throws Exception {
        DataNetworkController.NetworkRequestList
                networkRequestList = new DataNetworkController.NetworkRequestList();
        NetworkRequestList networkRequestList = new NetworkRequestList();
        networkRequestList.add(new TelephonyNetworkRequest(new NetworkRequest.Builder()
                .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                .build(), mPhone));
@@ -442,8 +444,7 @@ public class DataNetworkTest extends TelephonyTest {

    @Test
    public void testCreateImsDataNetwork() throws Exception {
        DataNetworkController.NetworkRequestList
                networkRequestList = new DataNetworkController.NetworkRequestList();
        NetworkRequestList networkRequestList = new NetworkRequestList();
        networkRequestList.add(new TelephonyNetworkRequest(new NetworkRequest.Builder()
                .addCapability(NetworkCapabilities.NET_CAPABILITY_IMS)
                .build(), mPhone));
@@ -520,8 +521,7 @@ public class DataNetworkTest extends TelephonyTest {

    @Test
    public void testCreateDataNetworkOnEnterpriseSlice() throws Exception {
        DataNetworkController.NetworkRequestList
                networkRequestList = new DataNetworkController.NetworkRequestList();
        NetworkRequestList networkRequestList = new NetworkRequestList();
        networkRequestList.add(new TelephonyNetworkRequest(new NetworkRequest.Builder()
                .addCapability(NetworkCapabilities.NET_CAPABILITY_ENTERPRISE)
                .build(), mPhone));
@@ -556,8 +556,7 @@ public class DataNetworkTest extends TelephonyTest {

    @Test
    public void testCreateDataNetworkOnUrllcSlice() throws Exception {
        DataNetworkController.NetworkRequestList
                networkRequestList = new DataNetworkController.NetworkRequestList();
        NetworkRequestList networkRequestList = new NetworkRequestList();
        networkRequestList.add(new TelephonyNetworkRequest(new NetworkRequest.Builder()
                .addCapability(NetworkCapabilities.NET_CAPABILITY_PRIORITIZE_LATENCY)
                .build(), mPhone));
@@ -590,8 +589,7 @@ public class DataNetworkTest extends TelephonyTest {

    @Test
    public void testCreateDataNetworkOnEmbbSlice() throws Exception {
        DataNetworkController.NetworkRequestList
                networkRequestList = new DataNetworkController.NetworkRequestList();
        NetworkRequestList networkRequestList = new NetworkRequestList();
        networkRequestList.add(new TelephonyNetworkRequest(new NetworkRequest.Builder()
                .addCapability(NetworkCapabilities.NET_CAPABILITY_PRIORITIZE_BANDWIDTH)
                .build(), mPhone));
@@ -624,8 +622,7 @@ public class DataNetworkTest extends TelephonyTest {

    @Test
    public void testCreateDataNetworkOnCbsSlice() throws Exception {
        DataNetworkController.NetworkRequestList
                networkRequestList = new DataNetworkController.NetworkRequestList();
        NetworkRequestList networkRequestList = new NetworkRequestList();
        networkRequestList.add(new TelephonyNetworkRequest(new NetworkRequest.Builder()
                .addCapability(NetworkCapabilities.NET_CAPABILITY_CBS)
                .build(), mPhone));
@@ -659,8 +656,7 @@ public class DataNetworkTest extends TelephonyTest {

    @Test
    public void testSlicingDataNetworkHasSlicingCapabilitiesBeforeConnected() throws Exception {
        DataNetworkController.NetworkRequestList
                networkRequestList = new DataNetworkController.NetworkRequestList();
        NetworkRequestList networkRequestList = new NetworkRequestList();
        networkRequestList.add(new TelephonyNetworkRequest(new NetworkRequest.Builder()
                .addCapability(NetworkCapabilities.NET_CAPABILITY_CBS)
                .build(), mPhone));
@@ -745,8 +741,7 @@ public class DataNetworkTest extends TelephonyTest {
        doReturn(AccessNetworkConstants.TRANSPORT_TYPE_WLAN).when(mAccessNetworksManager)
                .getPreferredTransportByNetworkCapability(NetworkCapabilities.NET_CAPABILITY_IMS);

        DataNetworkController.NetworkRequestList
                networkRequestList = new DataNetworkController.NetworkRequestList();
        NetworkRequestList networkRequestList = new NetworkRequestList();
        networkRequestList.add(new TelephonyNetworkRequest(new NetworkRequest.Builder()
                .addCapability(NetworkCapabilities.NET_CAPABILITY_IMS)
                .build(), mPhone));
@@ -925,8 +920,7 @@ public class DataNetworkTest extends TelephonyTest {
    }

    private void setupDataNetwork() throws Exception {
        DataNetworkController.NetworkRequestList
                networkRequestList = new DataNetworkController.NetworkRequestList();
        NetworkRequestList networkRequestList = new NetworkRequestList();
        networkRequestList.add(new TelephonyNetworkRequest(new NetworkRequest.Builder()
                .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                .build(), mPhone));
@@ -1103,8 +1097,7 @@ public class DataNetworkTest extends TelephonyTest {

    @Test
    public void testDataNetworkHasCapabilitiesAtBeginning() {
        DataNetworkController.NetworkRequestList
                networkRequestList = new DataNetworkController.NetworkRequestList();
        NetworkRequestList networkRequestList = new NetworkRequestList();
        networkRequestList.add(new TelephonyNetworkRequest(new NetworkRequest.Builder()
                .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                .build(), mPhone));
@@ -1302,4 +1295,49 @@ public class DataNetworkTest extends TelephonyTest {
        assertThat(mDataNetworkUT.getNetworkCapabilities().hasCapability(
                NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED)).isTrue();
    }

    @Test
    public void testGetApnTypeCapability() throws Exception {
        testCreateDataNetwork();
        assertThat(mDataNetworkUT.getApnTypeNetworkCapability())
                .isEqualTo(NetworkCapabilities.NET_CAPABILITY_INTERNET);

        TelephonyNetworkRequest networkRequest = new TelephonyNetworkRequest(
                new NetworkRequest.Builder().addCapability(
                        NetworkCapabilities.NET_CAPABILITY_SUPL).build(), mPhone);
        mDataNetworkUT.attachNetworkRequests(new NetworkRequestList(networkRequest));
        processAllMessages();

        assertThat(mDataNetworkUT.getApnTypeNetworkCapability())
                .isEqualTo(NetworkCapabilities.NET_CAPABILITY_SUPL);

        mDataNetworkUT.detachNetworkRequest(networkRequest);
        processAllMessages();

        assertThat(mDataNetworkUT.getApnTypeNetworkCapability())
                .isEqualTo(NetworkCapabilities.NET_CAPABILITY_INTERNET);
    }

    @Test
    public void testGetPriority() throws Exception {
        testCreateDataNetwork();

        // Internet priority is 20
        assertThat(mDataNetworkUT.getPriority()).isEqualTo(20);

        TelephonyNetworkRequest networkRequest = new TelephonyNetworkRequest(
                new NetworkRequest.Builder().addCapability(
                        NetworkCapabilities.NET_CAPABILITY_SUPL).build(), mPhone);
        mDataNetworkUT.attachNetworkRequests(new NetworkRequestList(networkRequest));
        processAllMessages();

        // SUPL priority is 80
        assertThat(mDataNetworkUT.getPriority()).isEqualTo(80);

        mDataNetworkUT.detachNetworkRequest(networkRequest);
        processAllMessages();

        // Internet priority is 20
        assertThat(mDataNetworkUT.getPriority()).isEqualTo(20);
    }
}