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

Commit 462b16f0 authored by Aishwarya Mallamapti's avatar Aishwarya Mallamapti
Browse files

Block data call based on carrier config.

If network is a non-terrestrial network and supports SERVICE_TYPE_DATA,
then do not block data requests with NET_CAPABILITY_INTERNET.

Bug: 287114765
Test: Flashed build on raven-userdebug and performed basic functionality
tests,
atest DataNetworkControllerTest

Change-Id: I7e92a12c5f3572705339d12767102056c49c33ad
parent 0180988b
Loading
Loading
Loading
Loading
+27 −9
Original line number Original line Diff line number Diff line
@@ -1552,9 +1552,8 @@ public class DataNetworkController extends Handler {
            evaluation.addDataDisallowedReason(DataDisallowedReason.CDMA_EMERGENCY_CALLBACK_MODE);
            evaluation.addDataDisallowedReason(DataDisallowedReason.CDMA_EMERGENCY_CALLBACK_MODE);
        }
        }


        // Check if device is connected to satellite
        // Check whether data is disallowed while using satellite
        if (mServiceState.isUsingNonTerrestrialNetwork()
        if (isDataDisallowedDueToSatellite(networkRequest.getCapabilities())) {
                && isDataDisallowedDueToSatellite(networkRequest.getCapabilities())) {
            evaluation.addDataDisallowedReason(DataDisallowedReason.SATELLITE_ENABLED);
            evaluation.addDataDisallowedReason(DataDisallowedReason.SATELLITE_ENABLED);
        }
        }


@@ -1735,9 +1734,9 @@ public class DataNetworkController extends Handler {
            evaluation.addDataDisallowedReason(DataDisallowedReason.CDMA_EMERGENCY_CALLBACK_MODE);
            evaluation.addDataDisallowedReason(DataDisallowedReason.CDMA_EMERGENCY_CALLBACK_MODE);
        }
        }


        // Check if device is connected to satellite
        // Check whether data is disallowed while using satellite
        if (mServiceState.isUsingNonTerrestrialNetwork() && isDataDisallowedDueToSatellite(
        if (isDataDisallowedDueToSatellite(dataNetwork.getNetworkCapabilities()
                dataNetwork.getNetworkCapabilities().getCapabilities())) {
                .getCapabilities())) {
            evaluation.addDataDisallowedReason(DataDisallowedReason.SATELLITE_ENABLED);
            evaluation.addDataDisallowedReason(DataDisallowedReason.SATELLITE_ENABLED);
        }
        }


@@ -3860,14 +3859,33 @@ public class DataNetworkController extends Handler {


    /**
    /**
     * Check whether data is disallowed while using satellite
     * Check whether data is disallowed while using satellite
     * @param capabilities The Network Capabilities to be checked
     * @param capabilities An array of the NetworkCapabilities to be checked
     * @return {@code true} if the capabilities contain any capability that are restricted
     * @return {@code true} if the capabilities contain any capability that are restricted
     * while using satellite else {@code false}
     * while using satellite else {@code false}
     */
     */
    private boolean isDataDisallowedDueToSatellite(@NetCapability int[] capabilities) {
    private boolean isDataDisallowedDueToSatellite(@NetCapability int[] capabilities) {
        // TODO: Disallow data when connected to satellite based on device config or carrier config.
        if (!mServiceState.isUsingNonTerrestrialNetwork()) {
            // Device is not connected to satellite
            return false;
        }

        Set<Integer> restrictedCapabilities = Set.of(NetworkCapabilities.NET_CAPABILITY_INTERNET);
        Set<Integer> restrictedCapabilities = Set.of(NetworkCapabilities.NET_CAPABILITY_INTERNET);
        return Arrays.stream(capabilities).anyMatch(restrictedCapabilities::contains);
        if (Arrays.stream(capabilities).noneMatch(restrictedCapabilities::contains)) {
            // Only internet data disallowed while using satellite
            return false;
        }

        for (NetworkRegistrationInfo nri : mServiceState.getNetworkRegistrationInfoList()) {
            if (nri.isNonTerrestrialNetwork()
                    && nri.getAvailableServices().contains(
                            NetworkRegistrationInfo.SERVICE_TYPE_DATA)) {
                // Data is supported while using satellite
                return false;
            }
        }

        // Data is disallowed while using satellite
        return true;
    }
    }


    /**
    /**
+26 −1
Original line number Original line Diff line number Diff line
@@ -179,6 +179,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
    private LinkBandwidthEstimatorCallback mLinkBandwidthEstimatorCallback;
    private LinkBandwidthEstimatorCallback mLinkBandwidthEstimatorCallback;


    private boolean mIsNonTerrestrialNetwork = false;
    private boolean mIsNonTerrestrialNetwork = false;
    private ArrayList<Integer> mCarrierSupportedSatelliteServices = new ArrayList<>();


    private final DataProfile mGeneralPurposeDataProfile = new DataProfile.Builder()
    private final DataProfile mGeneralPurposeDataProfile = new DataProfile.Builder()
            .setApnSetting(new ApnSetting.Builder()
            .setApnSetting(new ApnSetting.Builder()
@@ -613,6 +614,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
                .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
                .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
                .setDataSpecificInfo(dsri)
                .setDataSpecificInfo(dsri)
                .setIsNonTerrestrialNetwork(mIsNonTerrestrialNetwork)
                .setIsNonTerrestrialNetwork(mIsNonTerrestrialNetwork)
                .setAvailableServices(mCarrierSupportedSatelliteServices)
                .build());
                .build());


        ss.addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
        ss.addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
@@ -621,6 +623,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
                .setRegistrationState(iwlanRegState)
                .setRegistrationState(iwlanRegState)
                .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
                .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
                .setIsNonTerrestrialNetwork(mIsNonTerrestrialNetwork)
                .setIsNonTerrestrialNetwork(mIsNonTerrestrialNetwork)
                .setAvailableServices(mCarrierSupportedSatelliteServices)
                .build());
                .build());


        ss.addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
        ss.addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
@@ -1560,8 +1563,10 @@ public class DataNetworkControllerTest extends TelephonyTest {
    }
    }


    @Test
    @Test
    public void testNonTerrestrialNetworkChanged() throws Exception {
    public void testNonTerrestrialNetworkChangedWithoutDataSupport() throws Exception {
        mIsNonTerrestrialNetwork = true;
        mIsNonTerrestrialNetwork = true;
        // Data is not supported while using satellite
        mCarrierSupportedSatelliteServices.add(NetworkRegistrationInfo.SERVICE_TYPE_VOICE);
        serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE,
        serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE,
                NetworkRegistrationInfo.REGISTRATION_STATE_HOME);
                NetworkRegistrationInfo.REGISTRATION_STATE_HOME);


@@ -1574,6 +1579,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
        verifyNoConnectedNetworkHasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
        verifyNoConnectedNetworkHasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);


        mIsNonTerrestrialNetwork = false;
        mIsNonTerrestrialNetwork = false;
        mCarrierSupportedSatelliteServices.clear();
        serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE,
        serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE,
                NetworkRegistrationInfo.REGISTRATION_STATE_HOME);
                NetworkRegistrationInfo.REGISTRATION_STATE_HOME);


@@ -1581,6 +1587,25 @@ public class DataNetworkControllerTest extends TelephonyTest {
        verifyInternetConnected();
        verifyInternetConnected();
    }
    }


    @Test
    public void testNonTerrestrialNetworkWithDataSupport() throws Exception {
        mIsNonTerrestrialNetwork = true;
        // Data is supported while using satellite
        mCarrierSupportedSatelliteServices.add(NetworkRegistrationInfo.SERVICE_TYPE_DATA);
        serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE,
                NetworkRegistrationInfo.REGISTRATION_STATE_HOME);

        mDataNetworkControllerUT.addNetworkRequest(
                createNetworkRequest(NetworkCapabilities.NET_CAPABILITY_INTERNET));
        processAllMessages();

        // Verify data is connected.
        verifyInternetConnected();

        mIsNonTerrestrialNetwork = false;
        mCarrierSupportedSatelliteServices.clear();
    }

    @Test
    @Test
    public void testRoamingDataChanged() throws Exception {
    public void testRoamingDataChanged() throws Exception {
        doReturn(true).when(mServiceState).getDataRoaming();
        doReturn(true).when(mServiceState).getDataRoaming();