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

Commit d9cb7ebe authored by Jack Yu's avatar Jack Yu Committed by Automerger Merge Worker
Browse files

Merge "Added internet capability for enterprise slice" into tm-dev am: 8056fb99

parents 438bc673 8056fb99
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1677,6 +1677,8 @@ public class DataNetwork extends StateMachine {
                switch (networkCapability) {
                    case NetworkCapabilities.NET_CAPABILITY_ENTERPRISE:
                        builder.addCapability(networkCapability);
                        // Always add internet if TD contains enterprise.
                        builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
                        builder.addEnterpriseId(osAppId.getDifferentiator());
                        break;
                    case NetworkCapabilities.NET_CAPABILITY_PRIORITIZE_LATENCY:
@@ -1790,6 +1792,7 @@ public class DataNetwork extends StateMachine {
            // This is the first time when network capabilities is created. The agent is not created
            // at this time. Just return here. The network capabilities will be used when network
            // agent is created.
            log("Initial capabilities " + mNetworkCapabilities);
            mNetworkCapabilities = nc;
            return;
        }
@@ -1818,6 +1821,7 @@ public class DataNetwork extends StateMachine {
                // Now we need to inform connectivity service and data network controller
                // about the capabilities changed.
                mNetworkCapabilities = nc;
                log("Capabilities changed to " + mNetworkCapabilities);
                mNetworkAgent.sendNetworkCapabilities(mNetworkCapabilities);
            }

+1 −0
Original line number Diff line number Diff line
@@ -577,6 +577,7 @@ public class DataProfileManager extends Handler {
            @NonNull TelephonyNetworkRequest networkRequest, @NetworkType int networkType) {
        if (!networkRequest.hasAttribute(
                TelephonyNetworkRequest.CAPABILITY_ATTRIBUTE_APN_SETTING)) {
            loge("Network request does not have APN setting attribute.");
            return null;
        }

+1 −0
Original line number Diff line number Diff line
@@ -280,6 +280,7 @@ public class TelephonyNetworkRequest {
            // Fallback to the legacy APN type matching.
            List<Integer> apnTypes = Arrays.stream(getCapabilities()).boxed()
                    .map(DataUtils::networkCapabilityToApnType)
                    .filter(apnType -> apnType != ApnSetting.TYPE_NONE)
                    .collect(Collectors.toList());
            return apnTypes.stream().allMatch(dataProfile.getApnSetting()::canHandleType);
        }
+60 −1
Original line number Diff line number Diff line
@@ -79,6 +79,8 @@ import android.telephony.data.DataProfile;
import android.telephony.data.DataService;
import android.telephony.data.DataServiceCallback;
import android.telephony.data.ThrottleStatus;
import android.telephony.data.TrafficDescriptor;
import android.telephony.data.TrafficDescriptor.OsAppId;
import android.telephony.ims.ImsManager;
import android.telephony.ims.ImsMmTelManager;
import android.telephony.ims.ImsRcsManager;
@@ -115,6 +117,7 @@ import java.time.Period;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -265,11 +268,21 @@ public class DataNetworkControllerTest extends TelephonyTest {
            .setPreferred(false)
            .build();

    private final DataProfile mEnterpriseDataProfile = new DataProfile.Builder()
            .setTrafficDescriptor(new TrafficDescriptor(null,
                    new TrafficDescriptor.OsAppId(TrafficDescriptor.OsAppId.ANDROID_OS_ID,
                            "ENTERPRISE", 1).getBytes()))
            .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<>();

    private @NonNull DataCallResponse createDataCallResponse(int cid, @LinkStatus int linkStatus) {
        return createDataCallResponse(cid, linkStatus, Collections.emptyList());
    }

    private @NonNull DataCallResponse createDataCallResponse(int cid, @LinkStatus int linkStatus,
            @NonNull List<TrafficDescriptor> tdList) {
        return new DataCallResponse.Builder()
                .setCause(0)
                .setRetryDurationMillis(-1L)
@@ -294,7 +307,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
                .setMtuV6(1500)
                .setPduSessionId(1)
                .setQosBearerSessions(new ArrayList<>())
                .setTrafficDescriptors(new ArrayList<>())
                .setTrafficDescriptors(tdList)
                .build();
    }

@@ -316,6 +329,31 @@ public class DataNetworkControllerTest extends TelephonyTest {
                any(Message.class));
    }

    private void setSuccessfulSetupDataResponse(DataServiceManager dsm, DataCallResponse response) {
        doAnswer(invocation -> {
            final Message msg = (Message) invocation.getArguments()[10];

            int transport = AccessNetworkConstants.TRANSPORT_TYPE_INVALID;
            if (dsm == mMockedWwanDataServiceManager) {
                transport = AccessNetworkConstants.TRANSPORT_TYPE_WWAN;
            } else if (dsm == mMockedWlanDataServiceManager) {
                transport = AccessNetworkConstants.TRANSPORT_TYPE_WLAN;
            }
            mDataCallResponses.computeIfAbsent(transport, v -> new HashMap<>());
            mDataCallResponses.get(transport).put(response.getId(), response);
            msg.getData().putParcelable("data_call_response", response);
            msg.arg1 = DataServiceCallback.RESULT_SUCCESS;
            msg.sendToTarget();

            mDataCallListChangedRegistrants.get(transport).notifyRegistrants(
                    new AsyncResult(transport, new ArrayList<>(mDataCallResponses.get(
                            transport).values()), null));
            return null;
        }).when(dsm).setupDataCall(anyInt(), any(DataProfile.class), anyBoolean(),
                anyBoolean(), anyInt(), any(), anyInt(), any(), any(), anyBoolean(),
                any(Message.class));
    }

    private void setSuccessfulSetupDataResponse(DataServiceManager dsm, int cid) {
        doAnswer(invocation -> {
            final Message msg = (Message) invocation.getArguments()[10];
@@ -850,6 +888,27 @@ public class DataNetworkControllerTest extends TelephonyTest {
                InetAddresses.parseNumericAddress(IPV6_ADDRESS));
    }

    @Test
    public void testSetupEnterpriseDataNetwork() throws Exception {
        List<TrafficDescriptor> tdList = new ArrayList<>();
        tdList.add(new TrafficDescriptor.Builder()
                .setOsAppId(new OsAppId(OsAppId.ANDROID_OS_ID, "ENTERPRISE", 1).getBytes())
                .build());
        setSuccessfulSetupDataResponse(mMockedWwanDataServiceManager,
                createDataCallResponse(1, DataCallResponse.LINK_STATUS_ACTIVE, tdList));
        doReturn(mEnterpriseDataProfile).when(mDataProfileManager)
                .getDataProfileForNetworkRequest(any(TelephonyNetworkRequest.class), anyInt());

        mDataNetworkControllerUT.addNetworkRequest(
                createNetworkRequest(NetworkCapabilities.NET_CAPABILITY_ENTERPRISE));
        processAllMessages();
        verifyConnectedNetworkHasCapabilities(NetworkCapabilities.NET_CAPABILITY_ENTERPRISE);
        List<DataNetwork> dataNetworkList = getDataNetworks();
        assertThat(dataNetworkList.get(0).getLinkProperties().getAddresses()).containsExactly(
                InetAddresses.parseNumericAddress(IPV4_ADDRESS),
                InetAddresses.parseNumericAddress(IPV6_ADDRESS));
    }

    @Test
    public void testDataNetworkControllerCallback() throws Exception {
        mDataNetworkControllerUT.registerDataNetworkControllerCallback(
+1 −0
Original line number Diff line number Diff line
@@ -466,6 +466,7 @@ public class DataNetworkTest extends TelephonyTest {
        NetworkCapabilities nc = mDataNetworkUT.getNetworkCapabilities();
        assertThat(nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_ENTERPRISE)).isTrue();
        assertThat(nc.getEnterpriseIds()).asList().containsExactly(1, 5);
        assertThat(nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)).isTrue();
    }

    @Test