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

Commit 67262fc5 authored by Aishwarya Mallampati's avatar Aishwarya Mallampati Committed by Android (Google) Code Review
Browse files

Merge "Block data call based on carrier config." into main

parents de74504f 462b16f0
Loading
Loading
Loading
Loading
+27 −9
Original line number Diff line number Diff line
@@ -1552,9 +1552,8 @@ public class DataNetworkController extends Handler {
            evaluation.addDataDisallowedReason(DataDisallowedReason.CDMA_EMERGENCY_CALLBACK_MODE);
        }

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

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

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

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

    /**
     * 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
     * while using satellite else {@code false}
     */
    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);
        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 Diff line number Diff line
@@ -179,6 +179,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
    private LinkBandwidthEstimatorCallback mLinkBandwidthEstimatorCallback;

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

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

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

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

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

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

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

@@ -1581,6 +1587,25 @@ public class DataNetworkControllerTest extends TelephonyTest {
        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
    public void testRoamingDataChanged() throws Exception {
        doReturn(true).when(mServiceState).getDataRoaming();