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

Commit 5c1f8fd7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Don't allow Enterprise to override disallowed reason" into udc-qpr-dev am: 82c397bf

parents f0b2c7d0 82c397bf
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -1592,8 +1592,8 @@ public class DataNetworkController extends Handler {
                // Check if it's SUPL during emergency call.
                evaluation.addDataAllowedReason(DataAllowedReason.EMERGENCY_SUPL);
            } else if (!networkRequest.hasCapability(
                    NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED) && !networkRequest
                    .hasCapability(NetworkCapabilities.NET_CAPABILITY_DUN)) {
                    NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
                    && isValidRestrictedRequest(networkRequest)) {
                // Check if request is restricted and not for tethering, which always comes with
                // a restricted network request.
                evaluation.addDataAllowedReason(DataAllowedReason.RESTRICTED_REQUEST);
@@ -1869,9 +1869,9 @@ public class DataNetworkController extends Handler {
                evaluation.addDataAllowedReason(DataAllowedReason.EMERGENCY_SUPL);
            } else if (!dataNetwork.getNetworkCapabilities().hasCapability(
                    NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
                    && !dataNetwork.hasNetworkCapabilityInNetworkRequests(
                            NetworkCapabilities.NET_CAPABILITY_DUN)) {
                // Check if request is restricted and there are no DUN network requests attached to
                    && dataNetwork.getAttachedNetworkRequestList().stream()
                            .allMatch(this::isValidRestrictedRequest)) {
                // Check if request is restricted and there are no exceptional requests attached to
                // the network.
                evaluation.addDataAllowedReason(DataAllowedReason.RESTRICTED_REQUEST);
            } else if (dataNetwork.getTransport() == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) {
@@ -1900,6 +1900,18 @@ public class DataNetworkController extends Handler {
        return evaluation;
    }

    /**
     * tethering and enterprise capabilities are not respected as restricted requests. For a request
     * with these capabilities, any soft disallowed reasons are honored.
     * @param networkRequest The network request to evaluate.
     * @return {@code true} if the request doesn't contain any exceptional capabilities, its
     * restricted capability, if any, is respected.
     */
    private boolean isValidRestrictedRequest(@NonNull TelephonyNetworkRequest networkRequest) {
        return !(networkRequest.hasCapability(NetworkCapabilities.NET_CAPABILITY_DUN)
                || networkRequest.hasCapability(NetworkCapabilities.NET_CAPABILITY_ENTERPRISE));
    }

    /**
     * Called when needed to re-evaluate existing data networks and tear down networks if needed.
     *
+64 −4
Original line number Diff line number Diff line
@@ -689,10 +689,10 @@ public class DataNetworkControllerTest extends TelephonyTest {
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, true);
        mCarrierConfig.putStringArray(
                CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS,
                new String[]{"default", "mms", "dun", "supl"});
                new String[]{"default", "mms", "dun", "supl", "enterprise"});
        mCarrierConfig.putStringArray(
                CarrierConfigManager.KEY_CARRIER_METERED_ROAMING_APN_TYPES_STRINGS,
                new String[]{"default", "mms", "dun", "supl"});
                new String[]{"default", "mms", "dun", "supl", "enterprise"});

        mCarrierConfig.putStringArray(
                CarrierConfigManager.KEY_TELEPHONY_DATA_SETUP_RETRY_RULES_STRING_ARRAY,
@@ -1249,8 +1249,12 @@ public class DataNetworkControllerTest extends TelephonyTest {
                .getDataProfileForNetworkRequest(any(TelephonyNetworkRequest.class), anyInt(),
                        anyBoolean());

        mDataNetworkControllerUT.addNetworkRequest(
                createNetworkRequest(NetworkCapabilities.NET_CAPABILITY_ENTERPRISE));
        NetworkCapabilities netCaps = new NetworkCapabilities();
        netCaps.addCapability(NetworkCapabilities.NET_CAPABILITY_ENTERPRISE);
        netCaps.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED);
        mDataNetworkControllerUT.addNetworkRequest(new TelephonyNetworkRequest(
                new NetworkRequest(netCaps, ConnectivityManager.TYPE_MOBILE, ++mNetworkRequestId,
                        NetworkRequest.Type.REQUEST), mPhone));
        processAllMessages();
        verifyConnectedNetworkHasCapabilities(NetworkCapabilities.NET_CAPABILITY_ENTERPRISE);
        List<DataNetwork> dataNetworkList = getDataNetworks();
@@ -3221,6 +3225,25 @@ public class DataNetworkControllerTest extends TelephonyTest {
        verifyAllDataDisconnected();
    }

    @Test
    public void testDataDisableTearingDownEnterpriseNetwork() throws Exception {
        // User data enabled
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, true, mContext.getOpPackageName());
        processAllMessages();

        // Request the restricted enterprise network.
        testSetupEnterpriseDataNetwork();

        // User data disabled
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName());
        processAllMessages();

        // Everything should be disconnected.
        verifyAllDataDisconnected();
    }

    @Test
    public void testSetPreferredDataProfileMultiInternetDataProfile() throws Exception {
        // No preferred data profile in the beginning
@@ -3316,6 +3339,43 @@ public class DataNetworkControllerTest extends TelephonyTest {
                any(), any(), anyBoolean(), any(Message.class));
    }

    @Test
    public void testDataDisableNotAllowingBringingUpEnterpriseNetwork() throws Exception {
        // User data disabled
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName());
        processAllMessages();

        // Request the restricted tethering network.
        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(),
                        anyBoolean());

        NetworkCapabilities netCaps = new NetworkCapabilities();
        netCaps.addCapability(NetworkCapabilities.NET_CAPABILITY_ENTERPRISE);
        netCaps.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED);

        NetworkRequest nativeNetworkRequest = new NetworkRequest(netCaps,
                ConnectivityManager.TYPE_MOBILE, ++mNetworkRequestId, NetworkRequest.Type.REQUEST);

        mDataNetworkControllerUT.addNetworkRequest(
                new TelephonyNetworkRequest(nativeNetworkRequest, mPhone));
        processAllMessages();

        // Everything should be disconnected.
        verifyAllDataDisconnected();

        // Telephony should not try to setup a data call for Enterprise.
        verify(mMockedWwanDataServiceManager, never()).setupDataCall(anyInt(),
                any(DataProfile.class), anyBoolean(), anyBoolean(), anyInt(), any(), anyInt(),
                any(), any(), anyBoolean(), any(Message.class));
    }
    @Test
    public void testNonVoPSNoIMSSetup() throws Exception {
        DataSpecificRegistrationInfo dsri = new DataSpecificRegistrationInfo.Builder(8)