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

Commit 0180988b authored by Aishwarya Mallampati's avatar Aishwarya Mallampati Committed by Aishwarya Mallamapti
Browse files

Block data call

If network is a non-terrestrial network, block data requests with
NET_CAPABILITY_INTERNET.

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

Change-Id: Icc2cb26d319433a74570c1bd1909599069e7fa7f
parent 867c8163
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -290,6 +290,8 @@ public class DataEvaluation {
        SIM_NOT_READY(true),
        /** Concurrent voice and data is not allowed. */
        CONCURRENT_VOICE_DATA_NOT_ALLOWED(true),
        /** Indicates that data is not allowed as device is connected to satellite. */
        SATELLITE_ENABLED(true),
        /** Carrier notified data should be restricted. */
        DATA_RESTRICTED_BY_NETWORK(true),
        /** Radio power is off (i.e. airplane mode on) */
+5 −1
Original line number Diff line number Diff line
@@ -279,6 +279,7 @@ public class DataNetwork extends StateMachine {
                    TEAR_DOWN_REASON_RAT_NOT_ALLOWED,
                    TEAR_DOWN_REASON_ROAMING_DISABLED,
                    TEAR_DOWN_REASON_CONCURRENT_VOICE_DATA_NOT_ALLOWED,
                    TEAR_DOWN_REASON_SATELLITE_ENABLED,
                    TEAR_DOWN_REASON_DATA_SERVICE_NOT_READY,
                    TEAR_DOWN_REASON_POWER_OFF_BY_CARRIER,
                    TEAR_DOWN_REASON_DATA_STALL,
@@ -330,7 +331,8 @@ public class DataNetwork extends StateMachine {
    /** Data network tear down due to concurrent voice/data not allowed. */
    public static final int TEAR_DOWN_REASON_CONCURRENT_VOICE_DATA_NOT_ALLOWED = 8;


    /** Data network tear down due to device is connected to satellite. */
    public static final int TEAR_DOWN_REASON_SATELLITE_ENABLED = 9;

    /** Data network tear down due to data service unbound. */
    public static final int TEAR_DOWN_REASON_DATA_SERVICE_NOT_READY = 10;
@@ -3489,6 +3491,8 @@ public class DataNetwork extends StateMachine {
                return "TEAR_DOWN_REASON_ROAMING_DISABLED";
            case TEAR_DOWN_REASON_CONCURRENT_VOICE_DATA_NOT_ALLOWED:
                return "TEAR_DOWN_REASON_CONCURRENT_VOICE_DATA_NOT_ALLOWED";
            case TEAR_DOWN_REASON_SATELLITE_ENABLED:
                return "TEAR_DOWN_REASON_SATELLITE_ENABLED";
            case TEAR_DOWN_REASON_DATA_SERVICE_NOT_READY:
                return "TEAR_DOWN_REASON_DATA_SERVICE_NOT_READY";
            case TEAR_DOWN_REASON_POWER_OFF_BY_CARRIER:
+40 −1
Original line number Diff line number Diff line
@@ -1552,6 +1552,12 @@ 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())) {
            evaluation.addDataDisallowedReason(DataDisallowedReason.SATELLITE_ENABLED);
        }

        // Check if only one data network is allowed.
        if (isOnlySingleDataNetworkAllowed(transport)
                && !hasCapabilityExemptsFromSinglePdnRule(networkRequest.getCapabilities())) {
@@ -1729,6 +1735,12 @@ 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())) {
            evaluation.addDataDisallowedReason(DataDisallowedReason.SATELLITE_ENABLED);
        }

        // Check if there are other network that has higher priority, and only single data network
        // is allowed.
        if (isOnlySingleDataNetworkAllowed(dataNetwork.getTransport())
@@ -2080,6 +2092,8 @@ public class DataNetworkController extends Handler {
                    return DataNetwork.TEAR_DOWN_REASON_SIM_REMOVAL;
                case CONCURRENT_VOICE_DATA_NOT_ALLOWED:
                    return DataNetwork.TEAR_DOWN_REASON_CONCURRENT_VOICE_DATA_NOT_ALLOWED;
                case SATELLITE_ENABLED:
                    return DataNetwork.TEAR_DOWN_REASON_SATELLITE_ENABLED;
                case RADIO_POWER_OFF:
                    return DataNetwork.TEAR_DOWN_REASON_AIRPLANE_MODE_ON;
                case PENDING_TEAR_DOWN_ALL:
@@ -3394,6 +3408,10 @@ public class DataNetworkController extends Handler {
            return true;
        }

        if (!oldNri.isNonTerrestrialNetwork() && newNri.isNonTerrestrialNetwork()) {
            return true;
        }

        DataSpecificRegistrationInfo oldDsri = oldNri.getDataSpecificInfo();
        DataSpecificRegistrationInfo newDsri = newNri.getDataSpecificInfo();

@@ -3446,6 +3464,10 @@ public class DataNetworkController extends Handler {
            return true;
        }

        if (oldSS.isUsingNonTerrestrialNetwork() && !newSS.isUsingNonTerrestrialNetwork()) {
            return true;
        }

        DataSpecificRegistrationInfo oldDsri = oldPsNri.getDataSpecificInfo();
        DataSpecificRegistrationInfo newDsri = newPsNri.getDataSpecificInfo();

@@ -3494,7 +3516,12 @@ public class DataNetworkController extends Handler {
                                oldNri.getRegistrationState()) : null);
                debugMessage.append("->").append(newNri != null
                        ? NetworkRegistrationInfo.registrationStateToString(
                        newNri.getRegistrationState()) : null).append("] ");
                        newNri.getRegistrationState()) : null).append(", ");
                debugMessage.append(oldNri != null ? NetworkRegistrationInfo
                        .isNonTerrestrialNetworkToString(oldNri.isNonTerrestrialNetwork()) : null);
                debugMessage.append("->").append(newNri != null ? NetworkRegistrationInfo
                        .isNonTerrestrialNetworkToString(newNri.isNonTerrestrialNetwork()) : null)
                        .append("] ");
                if (shouldReevaluateDataNetworks(oldNri, newNri)) {
                    if (!hasMessages(EVENT_REEVALUATE_EXISTING_DATA_NETWORKS)) {
                        sendMessage(obtainMessage(EVENT_REEVALUATE_EXISTING_DATA_NETWORKS,
@@ -3831,6 +3858,18 @@ public class DataNetworkController extends Handler {
        return packages;
    }

    /**
     * Check whether data is disallowed while using satellite
     * @param capabilities The Network Capabilities 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.
        Set<Integer> restrictedCapabilities = Set.of(NetworkCapabilities.NET_CAPABILITY_INTERNET);
        return Arrays.stream(capabilities).anyMatch(restrictedCapabilities::contains);
    }

    /**
     * Log debug messages.
     * @param s debug messages
+26 −0
Original line number Diff line number Diff line
@@ -178,6 +178,8 @@ public class DataNetworkControllerTest extends TelephonyTest {
    private AccessNetworksManagerCallback mAccessNetworksManagerCallback;
    private LinkBandwidthEstimatorCallback mLinkBandwidthEstimatorCallback;

    private boolean mIsNonTerrestrialNetwork = false;

    private final DataProfile mGeneralPurposeDataProfile = new DataProfile.Builder()
            .setApnSetting(new ApnSetting.Builder()
                    .setId(2163)
@@ -610,6 +612,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
                .setRegistrationState(dataRegState)
                .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
                .setDataSpecificInfo(dsri)
                .setIsNonTerrestrialNetwork(mIsNonTerrestrialNetwork)
                .build());

        ss.addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
@@ -617,6 +620,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_IWLAN)
                .setRegistrationState(iwlanRegState)
                .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
                .setIsNonTerrestrialNetwork(mIsNonTerrestrialNetwork)
                .build());

        ss.addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
@@ -1555,6 +1559,28 @@ public class DataNetworkControllerTest extends TelephonyTest {
        verifyInternetConnected();
    }

    @Test
    public void testNonTerrestrialNetworkChanged() throws Exception {
        mIsNonTerrestrialNetwork = true;
        serviceStateChanged(TelephonyManager.NETWORK_TYPE_LTE,
                NetworkRegistrationInfo.REGISTRATION_STATE_HOME);

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

        // Data with internet capability should not be allowed
        // when the device is using non-terrestrial network
        verifyNoConnectedNetworkHasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);

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

        // Verify data is restored.
        verifyInternetConnected();
    }

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