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

Commit 61982956 authored by Ling Ma's avatar Ling Ma
Browse files

Allow data setup when oos if voice is registered

For non DDS subscription, if data is OOS and CS is registered for voice on 2G / 3G networks, then allow data setup as PS attach is possible

The original issue the non DDS check is trying to fix is b 123267897.

Fix: 233293665
Test: cts + atest, setup DSDS and confirm a MMS request is sent to
modem.

Change-Id: I4b3d13d5c7050d07a3e3fcb6de38c4effc77a296
parent e4e6b563
Loading
Loading
Loading
Loading
+59 −32
Original line number Original line Diff line number Diff line
@@ -1285,21 +1285,37 @@ public class DataNetworkController extends Handler {
    }
    }


    /**
    /**
     * @return {@code true} if checking registration state is needed before setup data network.
     * @param ss The service state to be checked
     * {@code false} indicates regardless in-service or out-of-service, setup data request will
     * @param transport The transport is used to determine the data registration state
     * be sent down to the data service.
     *
     * @return {@code true} if data is in service or if voice is in service on legacy CS
     * connections (2G/3G) on the non-DDS. In those cases we attempt to attach PS. We don't try for
     * newer RAT because for those PS attach already occurred.
     */
     */
    private boolean shouldCheckRegistrationState() {
    private boolean serviceStateAllowsPSAttach(@NonNull ServiceState ss,
        // Always don't check registration state on non-DDS sub.
            @TransportType int transport) {
        if (mPhone.getPhoneId() != PhoneSwitcher.getInstance().getPreferredDataPhoneId()) {
        // Use the data registration state from the modem instead of the current data registration
            return false;
        // state, which can be overridden.
        int nriRegState = getDataRegistrationState(ss, transport);
        if (nriRegState == NetworkRegistrationInfo.REGISTRATION_STATE_HOME
                || nriRegState == NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING) return true;

        // If data is OOS on the non-DDS,
        // attempt to attach PS on 2G/3G if CS connection is available.
        return ss.getVoiceRegState() == ServiceState.STATE_IN_SERVICE
                && mPhone.getPhoneId() != PhoneSwitcher.getInstance().getPreferredDataPhoneId()
                && isLegacyCs(ss.getVoiceNetworkType());
    }
    }


        // TODO: Expand this method to support more scenarios if needed. On Android 12 or older
    /**
        //  Android, auto attach is enabled by default. We dropped that support in Android 13 since
     * @param voiceNetworkType The voice network type to be checked.
        //  it's for the old 2G network. If there are other scenarios that we need to support
     * @return {@code true} if the network type is on legacy CS connection.
        //  auto-attach, can implement the logic in this method.
     */
        return true;
    private boolean isLegacyCs(@NetworkType int voiceNetworkType) {
        int voiceAccessNetworkType = DataUtils.networkTypeToAccessNetworkType(voiceNetworkType);
        return voiceAccessNetworkType == AccessNetworkType.GERAN
                || voiceAccessNetworkType == AccessNetworkType.UTRAN
                || voiceAccessNetworkType == AccessNetworkType.CDMA2000;
    }
    }


    /**
    /**
@@ -1384,10 +1400,7 @@ public class DataNetworkController extends Handler {
            return evaluation;
            return evaluation;
        }
        }


        int regState = getDataRegistrationState(transport);
        if (!serviceStateAllowsPSAttach(mServiceState, transport)) {
        if (shouldCheckRegistrationState()
                && regState != NetworkRegistrationInfo.REGISTRATION_STATE_HOME
                && regState != NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING) {
            evaluation.addDataDisallowedReason(DataDisallowedReason.NOT_IN_SERVICE);
            evaluation.addDataDisallowedReason(DataDisallowedReason.NOT_IN_SERVICE);
        }
        }


@@ -1548,7 +1561,7 @@ public class DataNetworkController extends Handler {
                    + TelephonyManager.getNetworkTypeName(getDataNetworkType(transport))
                    + TelephonyManager.getNetworkTypeName(getDataNetworkType(transport))
                    + ", reg state="
                    + ", reg state="
                    + NetworkRegistrationInfo.registrationStateToString(
                    + NetworkRegistrationInfo.registrationStateToString(
                    getDataRegistrationState(transport))
                    getDataRegistrationState(mServiceState, transport))
                    + ", " + networkRequest);
                    + ", " + networkRequest);
        }
        }
        return evaluation;
        return evaluation;
@@ -3064,27 +3077,39 @@ public class DataNetworkController extends Handler {
    /**
    /**
     * Check if needed to re-evaluate the unsatisfied network requests.
     * Check if needed to re-evaluate the unsatisfied network requests.
     *
     *
     * @param oldNri Previous network registration info.
     * @param oldSS Previous raw service state.
     * @param newNri Current network registration info.
     * @param newSS Current raw service state.
     * @param transport The network transport to be checked.
     * @return {@code true} if needed to re-evaluate the unsatisfied network requests.
     * @return {@code true} if needed to re-evaluate the unsatisfied network requests.
     */
     */
    private boolean shouldReevaluateNetworkRequests(@Nullable NetworkRegistrationInfo oldNri,
    private boolean shouldReevaluateNetworkRequests(@NonNull ServiceState oldSS,
            @Nullable NetworkRegistrationInfo newNri) {
            @NonNull ServiceState newSS, @TransportType int transport)  {
        if (newNri == null) return false;
        NetworkRegistrationInfo oldPsNri = oldSS.getNetworkRegistrationInfo(
        if (newNri.getAccessNetworkTechnology() == TelephonyManager.NETWORK_TYPE_UNKNOWN) {
                NetworkRegistrationInfo.DOMAIN_PS, transport);
        NetworkRegistrationInfo newPsNri = newSS.getNetworkRegistrationInfo(
                NetworkRegistrationInfo.DOMAIN_PS, transport);

        if (newPsNri == null) return false;
        if (newPsNri.getAccessNetworkTechnology() == TelephonyManager.NETWORK_TYPE_UNKNOWN) {
            // Sometimes devices temporarily lose signal and RAT becomes unknown. We don't setup
            // Sometimes devices temporarily lose signal and RAT becomes unknown. We don't setup
            // data in this case.
            // data in this case.
            return false;
            return false;
        }
        }


        if (oldNri == null
        if (oldPsNri == null
                || oldNri.getAccessNetworkTechnology() != newNri.getAccessNetworkTechnology()
                || oldPsNri.getAccessNetworkTechnology() != newPsNri.getAccessNetworkTechnology()
                || (!oldNri.isInService() && newNri.isInService())) {
                || (!oldPsNri.isInService() && newPsNri.isInService())) {
            return true;
            return true;
        }
        }


        DataSpecificRegistrationInfo oldDsri = oldNri.getDataSpecificInfo();
        // If CS connection is back to service on non-DDS, reevaluate for potential PS
        DataSpecificRegistrationInfo newDsri = newNri.getDataSpecificInfo();
        if (!serviceStateAllowsPSAttach(oldSS, transport)
                && serviceStateAllowsPSAttach(newSS, transport)) {
            return true;
        }

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


        if (oldDsri == null) return false;
        if (oldDsri == null) return false;
        if ((newDsri == null || newDsri.getVopsSupportInfo() == null
        if ((newDsri == null || newDsri.getVopsSupportInfo() == null
@@ -3139,7 +3164,7 @@ public class DataNetworkController extends Handler {
                        evaluateDataNetworks = true;
                        evaluateDataNetworks = true;
                    }
                    }
                }
                }
                if (shouldReevaluateNetworkRequests(oldNri, newNri)) {
                if (shouldReevaluateNetworkRequests(mServiceState, newServiceState, transport)) {
                    if (!hasMessages(EVENT_REEVALUATE_UNSATISFIED_NETWORK_REQUESTS)) {
                    if (!hasMessages(EVENT_REEVALUATE_UNSATISFIED_NETWORK_REQUESTS)) {
                        sendMessage(obtainMessage(EVENT_REEVALUATE_UNSATISFIED_NETWORK_REQUESTS,
                        sendMessage(obtainMessage(EVENT_REEVALUATE_UNSATISFIED_NETWORK_REQUESTS,
                                DataEvaluationReason.DATA_SERVICE_STATE_CHANGED));
                                DataEvaluationReason.DATA_SERVICE_STATE_CHANGED));
@@ -3276,11 +3301,13 @@ public class DataNetworkController extends Handler {
    /**
    /**
     * Get data registration state based on transport.
     * Get data registration state based on transport.
     *
     *
     * @param ss The service state from which to extract the data registration state.
     * @param transport The transport.
     * @param transport The transport.
     * @return The registration state.
     * @return The registration state.
     */
     */
    private @RegistrationState int getDataRegistrationState(@TransportType int transport) {
    private @RegistrationState int getDataRegistrationState(@NonNull ServiceState ss,
        NetworkRegistrationInfo nri = mServiceState.getNetworkRegistrationInfo(
            @TransportType int transport) {
        NetworkRegistrationInfo nri = ss.getNetworkRegistrationInfo(
                NetworkRegistrationInfo.DOMAIN_PS, transport);
                NetworkRegistrationInfo.DOMAIN_PS, transport);
        if (nri != null) {
        if (nri != null) {
            return nri.getRegistrationState();
            return nri.getRegistrationState();
+84 −5
Original line number Original line Diff line number Diff line
@@ -75,6 +75,7 @@ import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionPlan;
import android.telephony.SubscriptionPlan;
import android.telephony.TelephonyDisplayInfo;
import android.telephony.TelephonyDisplayInfo;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyProtoEnums;
import android.telephony.data.ApnSetting;
import android.telephony.data.ApnSetting;
import android.telephony.data.DataCallResponse;
import android.telephony.data.DataCallResponse;
import android.telephony.data.DataCallResponse.LinkStatus;
import android.telephony.data.DataCallResponse.LinkStatus;
@@ -478,17 +479,31 @@ public class DataNetworkControllerTest extends TelephonyTest {
                new LteVopsSupportInfo(LteVopsSupportInfo.LTE_STATUS_SUPPORTED,
                new LteVopsSupportInfo(LteVopsSupportInfo.LTE_STATUS_SUPPORTED,
                        LteVopsSupportInfo.LTE_STATUS_SUPPORTED));
                        LteVopsSupportInfo.LTE_STATUS_SUPPORTED));


        serviceStateChanged(networkType, regState, dsri);
        serviceStateChanged(networkType, regState, regState,
                NetworkRegistrationInfo.REGISTRATION_STATE_HOME, dsri);
    }
    }


    private void serviceStateChanged(@NetworkType int networkType,
    private void serviceStateChanged(@NetworkType int networkType,
            @RegistrationState int regState, DataSpecificRegistrationInfo dsri) {
            @RegistrationState int regState, DataSpecificRegistrationInfo dsri) {
        serviceStateChanged(networkType, regState, regState,
                NetworkRegistrationInfo.REGISTRATION_STATE_HOME, dsri);
    }

    private void serviceStateChanged(@NetworkType int networkType,
            @RegistrationState int dataRegState, @RegistrationState int voiceRegState,
            @RegistrationState int iwlanRegState, DataSpecificRegistrationInfo dsri) {
        if (dsri == null) {
            dsri = new DataSpecificRegistrationInfo(8, false, true, true,
                    new LteVopsSupportInfo(LteVopsSupportInfo.LTE_STATUS_SUPPORTED,
                            LteVopsSupportInfo.LTE_STATUS_SUPPORTED));
        }

        ServiceState ss = new ServiceState();
        ServiceState ss = new ServiceState();


        ss.addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
        ss.addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
                .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                .setAccessNetworkTechnology(networkType)
                .setAccessNetworkTechnology(networkType)
                .setRegistrationState(regState)
                .setRegistrationState(dataRegState)
                .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
                .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
                .setDataSpecificInfo(dsri)
                .setDataSpecificInfo(dsri)
                .build());
                .build());
@@ -496,18 +511,20 @@ public class DataNetworkControllerTest extends TelephonyTest {
        ss.addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
        ss.addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
                .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WLAN)
                .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WLAN)
                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_IWLAN)
                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_IWLAN)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .setRegistrationState(iwlanRegState)
                .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
                .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
                .build());
                .build());


        ss.addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
        ss.addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
                .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                .setAccessNetworkTechnology(networkType)
                .setAccessNetworkTechnology(networkType)
                .setRegistrationState(regState)
                .setRegistrationState(voiceRegState)
                .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
                .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
                .build());
                .build());
        ss.setDataRoamingFromRegistration(regState
        ss.setDataRoamingFromRegistration(dataRegState
                == NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING);
                == NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING);
        processServiceStateRegStateForTest(ss);

        doReturn(ss).when(mSST).getServiceState();
        doReturn(ss).when(mSST).getServiceState();
        doReturn(ss).when(mPhone).getServiceState();
        doReturn(ss).when(mPhone).getServiceState();


@@ -515,6 +532,28 @@ public class DataNetworkControllerTest extends TelephonyTest {
        processAllMessages();
        processAllMessages();
    }
    }


    // set SS reg state base on SST impl, where WLAN overrides WWAN's data reg.
    private void processServiceStateRegStateForTest(ServiceState ss) {
        int wlanRegState = ss.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS,
                AccessNetworkConstants.TRANSPORT_TYPE_WLAN).getRegistrationState();
        if (wlanRegState == NetworkRegistrationInfo.REGISTRATION_STATE_HOME) {
            ss.setDataRegState(ServiceState.STATE_IN_SERVICE);
        } else {
            int cellularRegState = ss.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS,
                    AccessNetworkConstants.TRANSPORT_TYPE_WWAN).getRegistrationState();
            int dataState = (cellularRegState == NetworkRegistrationInfo.REGISTRATION_STATE_HOME
                    || cellularRegState == NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING)
                    ? ServiceState.STATE_IN_SERVICE : ServiceState.STATE_OUT_OF_SERVICE;
            ss.setDataRegState(dataState);
        }
        int voiceRegState = ss.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_CS,
                AccessNetworkConstants.TRANSPORT_TYPE_WWAN).getRegistrationState();
        int voiceState = (voiceRegState == NetworkRegistrationInfo.REGISTRATION_STATE_HOME
                || voiceRegState == NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING)
                ? ServiceState.STATE_IN_SERVICE : ServiceState.STATE_OUT_OF_SERVICE;
        ss.setVoiceRegState(voiceState);
    }

    private void updateTransport(@NetCapability int capability, @TransportType int transport) {
    private void updateTransport(@NetCapability int capability, @TransportType int transport) {
        doReturn(transport).when(mAccessNetworksManager)
        doReturn(transport).when(mAccessNetworksManager)
                .getPreferredTransportByNetworkCapability(capability);
                .getPreferredTransportByNetworkCapability(capability);
@@ -2778,6 +2817,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
                .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
                .build());
                .build());
        processServiceStateRegStateForTest(ss);
        doReturn(ss).when(mSST).getServiceState();
        doReturn(ss).when(mSST).getServiceState();
        doReturn(ss).when(mPhone).getServiceState();
        doReturn(ss).when(mPhone).getServiceState();


@@ -2827,6 +2867,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
                .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
                .build());
                .build());
        processServiceStateRegStateForTest(ss);
        doReturn(ss).when(mSST).getServiceState();
        doReturn(ss).when(mSST).getServiceState();
        doReturn(ss).when(mPhone).getServiceState();
        doReturn(ss).when(mPhone).getServiceState();


@@ -2885,6 +2926,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
                .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
                .build());
                .build());
        processServiceStateRegStateForTest(ss);
        doReturn(ss).when(mSST).getServiceState();
        doReturn(ss).when(mSST).getServiceState();
        doReturn(ss).when(mPhone).getServiceState();
        doReturn(ss).when(mPhone).getServiceState();


@@ -2948,6 +2990,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
                .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
                .build());
                .build());
        processServiceStateRegStateForTest(ss);
        doReturn(ss).when(mSST).getServiceState();
        doReturn(ss).when(mSST).getServiceState();
        doReturn(ss).when(mPhone).getServiceState();
        doReturn(ss).when(mPhone).getServiceState();


@@ -2994,6 +3037,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
                .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
                .build());
                .build());
        processServiceStateRegStateForTest(ss);
        doReturn(ss).when(mSST).getServiceState();
        doReturn(ss).when(mSST).getServiceState();
        doReturn(ss).when(mPhone).getServiceState();
        doReturn(ss).when(mPhone).getServiceState();


@@ -3146,4 +3190,39 @@ public class DataNetworkControllerTest extends TelephonyTest {
        // Data should be torn down on this non-preferred sub.
        // Data should be torn down on this non-preferred sub.
        verifyAllDataDisconnected();
        verifyAllDataDisconnected();
    }
    }

    @Test
    public void testSetupDataOnNonDds() throws Exception {
        // Now DDS switched to phone 1
        doReturn(1).when(mMockedPhoneSwitcher).getPreferredDataPhoneId();
        TelephonyNetworkRequest request = createNetworkRequest(
                NetworkCapabilities.NET_CAPABILITY_MMS);

        // Test Don't allow setup if both data and voice OOS
        serviceStateChanged(TelephonyProtoEnums.NETWORK_TYPE_1XRTT,
                // data, voice, Iwlan reg state
                NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING,
                NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING,
                NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING, null);
        mDataNetworkControllerUT.addNetworkRequest(request);
        processAllMessages();

        verifyAllDataDisconnected();

        // Test Don't allow setup if CS is in service, but current RAT is already PS(e.g. LTE)
        serviceStateChanged(TelephonyProtoEnums.NETWORK_TYPE_LTE,
                NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING,
                NetworkRegistrationInfo.REGISTRATION_STATE_HOME,
                NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING, null);

        verifyAllDataDisconnected();

        // Test Allow if voice is in service if RAT is 2g/3g
        serviceStateChanged(TelephonyProtoEnums.NETWORK_TYPE_1XRTT,
                NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING,
                NetworkRegistrationInfo.REGISTRATION_STATE_HOME,
                NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING, null);

        verifyConnectedNetworkHasCapabilities(NetworkCapabilities.NET_CAPABILITY_MMS);
    }
}
}