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

Commit d78faac2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Change data profile base on transport for MMS" into main

parents b29ec94b 07975ae7
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -1030,9 +1030,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
@@ -1290,6 +1290,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()
@@ -1307,6 +1308,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
@@ -388,6 +388,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<>();

@@ -4637,4 +4648,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);
    }
}