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

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

Merge "Fixed tethering allowed when data disabled" am: 8e384586 am: c458c5ec

parents 47261a25 c458c5ec
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -3210,6 +3210,17 @@ public class DataNetwork extends StateMachine {
        return mVcnManager.applyVcnNetworkPolicy(networkCapabilities, getLinkProperties());
    }

    /**
     * Check if any of the attached request has the specified network capability.
     *
     * @param netCapability The network capability to check.
     * @return {@code true} if at least one network request has specified network capability.
     */
    public boolean hasNetworkCapabilityInNetworkRequests(@NetCapability int netCapability) {
        return mAttachedNetworkRequestList.stream().anyMatch(
                request -> request.hasCapability(netCapability));
    }

    /**
     * Convert the data tear down reason to string.
     *
+9 −4
Original line number Diff line number Diff line
@@ -1524,8 +1524,10 @@ 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)) {
                // Check if request is restricted.
                    NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED) && !networkRequest
                    .hasCapability(NetworkCapabilities.NET_CAPABILITY_DUN)) {
                // Check if request is restricted and not for tethering, which always comes with
                // a restricted network request.
                evaluation.addDataAllowedReason(DataAllowedReason.RESTRICTED_REQUEST);
            } else if (transport == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) {
                // Check if request is unmetered (WiFi or unmetered APN).
@@ -1766,8 +1768,11 @@ public class DataNetworkController extends Handler {
                // Check if it's SUPL during emergency call.
                evaluation.addDataAllowedReason(DataAllowedReason.EMERGENCY_SUPL);
            } else if (!dataNetwork.getNetworkCapabilities().hasCapability(
                    NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)) {
                // Check if request is restricted
                    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
                // the network.
                evaluation.addDataAllowedReason(DataAllowedReason.RESTRICTED_REQUEST);
            } else if (dataNetwork.getTransport() == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) {
                // Check if request is unmetered (WiFi or unmetered APN)
+58 −0
Original line number Diff line number Diff line
@@ -2461,6 +2461,64 @@ public class DataNetworkControllerTest extends TelephonyTest {
        assertThat(dataNetworkList.get(0).isConnected()).isTrue();
    }

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

        // Request the restricted tethering network.
        NetworkCapabilities netCaps = new NetworkCapabilities();
        netCaps.addCapability(NetworkCapabilities.NET_CAPABILITY_DUN);
        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();

        verifyConnectedNetworkHasCapabilities(NetworkCapabilities.NET_CAPABILITY_DUN);

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

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

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

        // Request the restricted tethering network.
        NetworkCapabilities netCaps = new NetworkCapabilities();
        netCaps.addCapability(NetworkCapabilities.NET_CAPABILITY_DUN);
        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 DUN.
        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,