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

Commit 07975ae7 authored by Ling Ma's avatar Ling Ma
Browse files

Change data profile base on transport for MMS

The change is to address the issue where some capability uses different
APN depending on the preferred transport. The change address the issue
by allowing new network to be brought up if exists anther data profile
that's more suitable than the existing connected network.

The existing network shouldn't be torn down because it's the default
backup if the new network failed to connect.

Bug: 231972603
Test: Sent MMS under WFC available/WFC disabled/cellular with diff SIMs
Test: tester at b/294076938
Change-Id: I294479afa9a4474f6df8ef188e676a0c6523ce63
parent c0c30941
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -1036,9 +1036,16 @@ public class DataNetwork extends StateMachine {
                mPhone.getPhoneId());
        final NetworkProvider provider = (null == factory) ? null : factory.getProvider();

        mNetworkScore = new NetworkScore.Builder().setKeepConnectedReason(
                        isHandoverInProgress() ? NetworkScore.KEEP_CONNECTED_FOR_HANDOVER
        // Always prefer IWLAN network for MMS designated network.
        // TODO(b/293656884) Proper use of primary transport to avoid conflicting with DSDA.
        boolean isPreferred = mTransport == AccessNetworkConstants.TRANSPORT_TYPE_WLAN
                && getApnTypeNetworkCapability() == NetworkCapabilities.NET_CAPABILITY_MMS;

        mNetworkScore = new NetworkScore.Builder().setTransportPrimary(isPreferred)
                .setKeepConnectedReason(isHandoverInProgress()
                        ? NetworkScore.KEEP_CONNECTED_FOR_HANDOVER
                        : NetworkScore.KEEP_CONNECTED_NONE).build();

        return new TelephonyNetworkAgent(mPhone, getHandler().getLooper(), this,
                mNetworkScore, configBuilder.build(), provider,
                new TelephonyNetworkAgentCallback(getHandler()::post) {
+21 −0
Original line number Diff line number Diff line
@@ -1293,6 +1293,7 @@ public class DataNetworkController extends Handler {
     * {@link #onAttachNetworkRequestsFailed(DataNetwork, NetworkRequestList)} will be invoked.
     */
    private boolean findCompatibleDataNetworkAndAttach(@NonNull NetworkRequestList requestList) {
        if (requestList.isEmpty()) return false;
        // Try to find a data network that can satisfy all the network requests.
        for (DataNetwork dataNetwork : mDataNetworkList) {
            TelephonyNetworkRequest networkRequest = requestList.stream()
@@ -1310,6 +1311,26 @@ public class DataNetworkController extends Handler {
            // When reaching here, it means this data network can satisfy all the network requests.
            logv("Found a compatible data network " + dataNetwork + ". Attaching "
                    + requestList);

            // If WLAN preferred, see whether a more suitable data profile shall be used to satisfy
            // a short-lived request that doesn't perform handover.
            int capability = requestList.getFirst().getApnTypeNetworkCapability();
            int preferredTransport = mAccessNetworksManager
                    .getPreferredTransportByNetworkCapability(capability);
            if (capability == NetworkCapabilities.NET_CAPABILITY_MMS
                    && preferredTransport != dataNetwork.getTransport()
                    && preferredTransport == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) {
                DataProfile candidate = mDataProfileManager
                        .getDataProfileForNetworkRequest(requestList.getFirst(),
                                TelephonyManager.NETWORK_TYPE_IWLAN,
                                false/*ignorePermanentFailure*/);
                if (candidate != null && !dataNetwork.getDataProfile().equals(candidate)) {
                    logv("But skipped because found better data profile " + candidate
                            + DataUtils.networkCapabilityToString(capability) + " preferred on "
                            + AccessNetworkConstants.transportTypeToString(preferredTransport));
                    continue;
                }
            }
            return dataNetwork.attachNetworkRequests(requestList);
        }
        return false;
+40 −0
Original line number Diff line number Diff line
@@ -387,6 +387,17 @@ public class DataNetworkControllerTest extends TelephonyTest {
                            "PRIORITIZE_LATENCY", 1).getBytes()))
            .build();

    private final DataProfile mMmsOnWlanDataProfile = new DataProfile.Builder()
            .setApnSetting(new ApnSetting.Builder()
                    .setEntryName("mms_wlan")
                    .setApnName("mms_wlan")
                    .setApnTypeBitmask(ApnSetting.TYPE_MMS)
                    .setCarrierEnabled(true)
                    .setNetworkTypeBitmask((int) TelephonyManager.NETWORK_TYPE_BITMASK_IWLAN)
                    .build())
            .setPreferred(false)
            .build();

    /** Data call response map. The first key is the transport type, the second key is the cid. */
    private final Map<Integer, Map<Integer, DataCallResponse>> mDataCallResponses = new HashMap<>();

@@ -4786,4 +4797,33 @@ public class DataNetworkControllerTest extends TelephonyTest {
        assertThat(dataNetworkList.get(1).getNetworkCapabilities().hasCapability(
                NetworkCapabilities.NET_CAPABILITY_PRIORITIZE_LATENCY)).isTrue();
    }

    @Test
    public void testAllowBringUpWithDifferentDataProfileForWlan() throws Exception {
        // Mock MMS preferred on WLAN
        doReturn(AccessNetworkConstants.TRANSPORT_TYPE_WLAN).when(mAccessNetworksManager)
                .getPreferredTransportByNetworkCapability(NetworkCapabilities.NET_CAPABILITY_MMS);

        // Setup a default cellular network that's capable of MMS
        mDataNetworkControllerUT.addNetworkRequest(
                createNetworkRequest(NetworkCapabilities.NET_CAPABILITY_INTERNET));
        mDataNetworkControllerUT.addNetworkRequest(
                createNetworkRequest(NetworkCapabilities.NET_CAPABILITY_IMS));
        processAllMessages();
        verifyConnectedNetworkHasDataProfile(mGeneralPurposeDataProfile);
        verifyConnectedNetworkHasDataProfile(mGeneralPurposeDataProfile);

        // Mock the designated MMS profile when WLAN is preferred
        doReturn(mMmsOnWlanDataProfile).when(mDataProfileManager).getDataProfileForNetworkRequest(
                any(TelephonyNetworkRequest.class), eq(TelephonyManager.NETWORK_TYPE_IWLAN),
                anyBoolean());
        setSuccessfulSetupDataResponse(mMockedWlanDataServiceManager,
                createDataCallResponse(2, DataCallResponse.LINK_STATUS_ACTIVE));

        // Verify the designated MMS profile is used to satisfy MMS request
        mDataNetworkControllerUT.addNetworkRequest(
                createNetworkRequest(NetworkCapabilities.NET_CAPABILITY_MMS));
        processAllMessages();
        verifyConnectedNetworkHasDataProfile(mMmsOnWlanDataProfile);
    }
}