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

Commit cca1e256 authored by Sooraj Sasindran's avatar Sooraj Sasindran
Browse files

Add enterprise apn to data profile

Add enterprise APN to data profile if DPC has
configured the same.

Bug: 231360296
Test: system test to verify that enterprise data call is requested
with APN

Change-Id: I4c8a575b45f19e89eb07ce567a7e1571722494ba
parent c54fadb9
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1737,6 +1737,9 @@ public class DataNetwork extends StateMachine {
                    .map(DataUtils::apnTypeToNetworkCapability)
                    .filter(cap -> cap >= 0)
                    .forEach(builder::addCapability);
            if (apnSetting.getApnTypes().contains(ApnSetting.TYPE_ENTERPRISE)) {
                builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
            }
        }

        // If voice call is on-going, do not change MMTEL capability, which is an immutable
+45 −2
Original line number Diff line number Diff line
@@ -198,6 +198,36 @@ public class DataProfileManager extends Handler {
        //TODO: more works needed to be done here.
    }

    /**
     * Check if there are any Enterprise APN configured by DPC and return a data profile
     * with the same.
     * @return data profile with enterprise ApnSetting if available, else null
     */
    @Nullable private DataProfile getEnterpriseDataProfile() {
        Cursor cursor = mPhone.getContext().getContentResolver().query(
                Telephony.Carriers.DPC_URI, null, null, null, null);
        if (cursor == null) {
            loge("Cannot access APN database through telephony provider.");
            return null;
        }

        DataProfile dataProfile = null;
        while (cursor.moveToNext()) {
            ApnSetting apn = ApnSetting.makeApnSetting(cursor);
            if (apn != null) {
                dataProfile = new DataProfile.Builder()
                        .setApnSetting(apn)
                        .setTrafficDescriptor(new TrafficDescriptor(apn.getApnName(), null))
                        .setPreferred(false)
                        .build();
                if (dataProfile.canSatisfy(NetworkCapabilities.NET_CAPABILITY_ENTERPRISE)) {
                    break;
                }
            }
        }
        cursor.close();
        return dataProfile;
    }
    /**
     * Update all data profiles, including preferred data profile, and initial attach data profile.
     * Also send those profiles down to the modem if needed.
@@ -228,6 +258,20 @@ public class DataProfileManager extends Handler {
            cursor.close();
        }

        // Check if any of the profile already supports ENTERPRISE, if not, check if DPC has
        // configured one and retrieve the same.
        DataProfile dataProfile = profiles.stream()
                .filter(dp -> dp.canSatisfy(NetworkCapabilities.NET_CAPABILITY_ENTERPRISE))
                .findFirst()
                .orElse(null);
        if (dataProfile == null) {
            dataProfile = getEnterpriseDataProfile();
            if (dataProfile != null) {
                profiles.add(dataProfile);
                log("Added enterprise profile " + dataProfile);
            }
        }

        // Check if any of the profile already supports IMS, if not, add the default one.
        DataProfile dataProfile = profiles.stream()
                .filter(dp -> dp.canSatisfy(NetworkCapabilities.NET_CAPABILITY_IMS))
@@ -565,8 +609,7 @@ public class DataProfileManager extends Handler {
        profileBuilder.setTrafficDescriptor(trafficDescriptor);

        DataProfile dataProfile = profileBuilder.build();
        log("Added a new data profile " + dataProfile + " for " + networkRequest);
        mAllDataProfiles.add(dataProfile);
        log("Created data profile " + dataProfile + " for " + networkRequest);
        return dataProfile;
    }

+12 −0
Original line number Diff line number Diff line
@@ -282,6 +282,18 @@ public class TelephonyNetworkRequest {
                    .map(DataUtils::networkCapabilityToApnType)
                    .filter(apnType -> apnType != ApnSetting.TYPE_NONE)
                    .collect(Collectors.toList());
            // In case of enterprise network request, the network request will have internet,
            // but APN type will not have default type as the enterprise apn should not be used
            // as default network. Ignore default type of the network request if it
            // has enterprise type as well. This will make sure the network request with
            // internet and enterprise will be satisfied with data profile with enterprise at the
            // same time default network request will not get satisfied with enterprise data
            // profile.
            // TODO b/232264746
            if (apnTypes.contains(ApnSetting.TYPE_ENTERPRISE)) {
                apnTypes.remove((Integer) ApnSetting.TYPE_DEFAULT);
            }

            return apnTypes.stream().allMatch(dataProfile.getApnSetting()::canHandleType);
        }
        return false;
+51 −0
Original line number Diff line number Diff line
@@ -69,6 +69,23 @@ public class TelephonyNetworkRequestTest extends TelephonyTest {
            .setWaitTime(456)
            .setMaxConnsTime(789)
            .build();
    private static final ApnSetting ENTERPRISE_APN_SETTING = new ApnSetting.Builder()
            .setId(2164)
            .setOperatorNumeric("12345")
            .setEntryName("enterprise")
            .setApnName("enterprise")
            .setUser("user")
            .setPassword("passwd")
            .setApnTypeBitmask(ApnSetting.TYPE_ENTERPRISE)
            .setProtocol(ApnSetting.PROTOCOL_IPV6)
            .setRoamingProtocol(ApnSetting.PROTOCOL_IP)
            .setCarrierEnabled(true)
            .setNetworkTypeBitmask(0)
            .setProfileId(1234)
            .setMaxConns(321)
            .setWaitTime(456)
            .setMaxConnsTime(789)
            .build();

    @Before
    public void setUp() throws Exception {
@@ -246,6 +263,40 @@ public class TelephonyNetworkRequestTest extends TelephonyTest {
        assertThat(enterpriseRequest2.canBeSatisfiedBy(enterpriseDataProfile2)).isTrue();
    }

    @Test
    public void testCanBeSatisfiedByEnterpriseApnDataProfile() {
        TelephonyNetworkRequest enterpriseRequest1 = new TelephonyNetworkRequest(
                new NetworkRequest.Builder()
                        .addCapability(NetworkCapabilities.NET_CAPABILITY_ENTERPRISE)
                        .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                        .build(), mPhone);
        TelephonyNetworkRequest enterpriseRequest2 = new TelephonyNetworkRequest(
                new NetworkRequest(new NetworkCapabilities()
                        .addCapability(NetworkCapabilities.NET_CAPABILITY_ENTERPRISE)
                        .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                        .addEnterpriseId(2), ConnectivityManager.TYPE_NONE,
                        0, NetworkRequest.Type.REQUEST), mPhone);
        TelephonyNetworkRequest internetRequest = new TelephonyNetworkRequest(
                new NetworkRequest(new NetworkCapabilities()
                        .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET),
                        ConnectivityManager.TYPE_NONE,
                        0, NetworkRequest.Type.REQUEST), mPhone);

        DataProfile enterpriseDataProfile = new DataProfile.Builder()
                .setApnSetting(ENTERPRISE_APN_SETTING)
                .build();
        DataProfile internetDataProfile = new DataProfile.Builder()
                .setApnSetting(INTERNET_APN_SETTING)
                .build();

        assertThat(enterpriseRequest1.canBeSatisfiedBy(enterpriseDataProfile)).isTrue();
        assertThat(enterpriseRequest1.canBeSatisfiedBy(internetDataProfile)).isFalse();
        assertThat(enterpriseRequest2.canBeSatisfiedBy(enterpriseDataProfile)).isTrue();
        assertThat(enterpriseRequest2.canBeSatisfiedBy(internetDataProfile)).isFalse();
        assertThat(internetRequest.canBeSatisfiedBy(enterpriseDataProfile)).isFalse();
        assertThat(internetRequest.canBeSatisfiedBy(internetDataProfile)).isTrue();
    }

    @Test
    public void testCanBeSatisfiedByUrllcDataProfile() {
        TelephonyNetworkRequest urllcRequest = new TelephonyNetworkRequest(