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

Commit 77db2843 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Don't allow Enterprise to override disallowed reason"

parents 9e80acc9 9f27bd8a
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -1610,8 +1610,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);
@@ -1873,9 +1873,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) {
@@ -1895,6 +1895,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.
     *
+56 −4
Original line number Diff line number Diff line
@@ -640,10 +640,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,
@@ -1204,8 +1204,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();
@@ -3082,6 +3086,17 @@ public class DataNetworkControllerTest extends TelephonyTest {
        processAllMessages();

        verifyConnectedNetworkHasCapabilities(NetworkCapabilities.NET_CAPABILITY_DUN);
    }

    @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(
@@ -3120,6 +3135,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(8, false, true, true,