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

Commit c6c89c80 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Don't allow Enterprise to override disallowed reason" am: 77db2843...

Merge "Don't allow Enterprise to override disallowed reason" am: 77db2843 am: a22a7688 am: a8d7dcc0

Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/2636715



Change-Id: I83870f5aaf56dc8de678fa9c65f9e82a48e8f80e
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 15357d2b a8d7dcc0
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -1588,8 +1588,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);
@@ -1856,9 +1856,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) {
@@ -1887,6 +1887,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
@@ -687,10 +687,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,
@@ -1247,8 +1247,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();
@@ -3204,6 +3208,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(
@@ -3309,6 +3324,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)