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

Commit ed242725 authored by Jack Yu's avatar Jack Yu Committed by Automerger Merge Worker
Browse files

Fixed tethering allowed when data disabled am: 514a4731

parents 7e4a1b33 514a4731
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
@@ -3314,6 +3314,17 @@ public class DataNetwork extends StateMachine {
        return mVcnManager.applyVcnNetworkPolicy(networkCapabilities, getLinkProperties());
        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.
     * Convert the data tear down reason to string.
     *
     *
+9 −4
Original line number Original line Diff line number Diff line
@@ -1540,8 +1540,10 @@ public class DataNetworkController extends Handler {
                // Check if it's SUPL during emergency call.
                // Check if it's SUPL during emergency call.
                evaluation.addDataAllowedReason(DataAllowedReason.EMERGENCY_SUPL);
                evaluation.addDataAllowedReason(DataAllowedReason.EMERGENCY_SUPL);
            } else if (!networkRequest.hasCapability(
            } else if (!networkRequest.hasCapability(
                    NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)) {
                    NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED) && !networkRequest
                // Check if request is restricted.
                    .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);
                evaluation.addDataAllowedReason(DataAllowedReason.RESTRICTED_REQUEST);
            } else if (transport == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) {
            } else if (transport == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) {
                // Check if request is unmetered (WiFi or unmetered APN).
                // Check if request is unmetered (WiFi or unmetered APN).
@@ -1782,8 +1784,11 @@ public class DataNetworkController extends Handler {
                // Check if it's SUPL during emergency call.
                // Check if it's SUPL during emergency call.
                evaluation.addDataAllowedReason(DataAllowedReason.EMERGENCY_SUPL);
                evaluation.addDataAllowedReason(DataAllowedReason.EMERGENCY_SUPL);
            } else if (!dataNetwork.getNetworkCapabilities().hasCapability(
            } else if (!dataNetwork.getNetworkCapabilities().hasCapability(
                    NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)) {
                    NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
                // Check if request is 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);
                evaluation.addDataAllowedReason(DataAllowedReason.RESTRICTED_REQUEST);
            } else if (dataNetwork.getTransport() == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) {
            } else if (dataNetwork.getTransport() == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) {
                // Check if request is unmetered (WiFi or unmetered APN)
                // Check if request is unmetered (WiFi or unmetered APN)
+58 −0
Original line number Original line Diff line number Diff line
@@ -2632,6 +2632,64 @@ public class DataNetworkControllerTest extends TelephonyTest {
        assertThat(dataNetworkList.get(0).isConnected()).isTrue();
        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
    @Test
    public void testNonVoPSNoIMSSetup() throws Exception {
    public void testNonVoPSNoIMSSetup() throws Exception {
        DataSpecificRegistrationInfo dsri = new DataSpecificRegistrationInfo(8, false, true, true,
        DataSpecificRegistrationInfo dsri = new DataSpecificRegistrationInfo(8, false, true, true,