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

Commit 4c6ae560 authored by Sarah Chin's avatar Sarah Chin Committed by Android (Google) Code Review
Browse files

Merge "Fix ENTERPRISE failures for duplicate CID and no default data" into sc-dev

parents 4539a085 5b27b121
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -1372,10 +1372,12 @@ public class DataConnection extends StateMachine {
                && mDcController.getActiveDcByCid(response.getId()) != null) {
            if (DBG) log("DataConnection already exists for cid: " + response.getId());
            result = SetupResult.ERROR_DUPLICATE_CID;
            result.mFailCause = DataFailCause.DUPLICATE_CID;
        } else if (cp.mApnContext.getApnTypeBitmask() == ApnSetting.TYPE_ENTERPRISE
                && !mDcController.isDefaultDataActive()) {
            if (DBG) log("No default data connection currently active");
            result = SetupResult.ERROR_NO_DEFAULT_CONNECTION;
            result.mFailCause = DataFailCause.NO_DEFAULT_DATA;
        } else {
            if (DBG) log("onSetupConnectionCompleted received successful DataCallResponse");
            mCid = response.getId();
@@ -2619,9 +2621,27 @@ public class DataConnection extends StateMachine {
                        case ERROR_DUPLICATE_CID:
                            // TODO (b/180988471): Properly handle the case when an existing cid is
                            // returned by tearing down the network agent if enterprise changed.
                            long retry = RetryManager.NO_SUGGESTED_RETRY_DELAY;
                            if (cp.mApnContext != null) {
                                retry = RetryManager.NO_RETRY;
                                mDct.getDataThrottler().setRetryTime(
                                        cp.mApnContext.getApnTypeBitmask(),
                                        retry, DcTracker.REQUEST_TYPE_NORMAL);
                            }
                            String logStr = "DcActivatingState: "
                                    + DataFailCause.toString(result.mFailCause)
                                    + " retry=" + retry;
                            if (DBG) log(logStr);
                            if (cp.mApnContext != null) cp.mApnContext.requestLog(logStr);
                            mInactiveState.setEnterNotificationParams(cp, result.mFailCause,
                                    DataCallResponse.HANDOVER_FAILURE_MODE_UNKNOWN);
                            transitionTo(mInactiveState);
                            break;
                        case ERROR_NO_DEFAULT_CONNECTION:
                            // TODO (b/180988471): Properly handle the case when a default data
                            // connection doesn't exist.
                            // connection doesn't exist (tear down connection and retry).
                            // Currently, this just tears down the connection without retry.
                            if (DBG) log("DcActivatingState: NO_DEFAULT_DATA");
                        case ERROR_INVALID_ARG:
                            // The addresses given from the RIL are bad
                            tearDownData(cp);
+8 −0
Original line number Diff line number Diff line
@@ -64,6 +64,8 @@ import android.provider.DeviceConfig;
import android.provider.Settings;
import android.telephony.AccessNetworkConstants;
import android.telephony.CarrierConfigManager;
import android.telephony.CellIdentity;
import android.telephony.CellLocation;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
@@ -329,6 +331,10 @@ public abstract class TelephonyTest {
    protected PinStorage mPinStorage;
    @Mock
    protected LocationManager mLocationManager;
    @Mock
    protected CellIdentity mCellIdentity;
    @Mock
    protected CellLocation mCellLocation;

    protected ActivityManager mActivityManager;
    protected ImsCallProfile mImsCallProfile;
@@ -573,6 +579,8 @@ public abstract class TelephonyTest {
        doReturn(mImsStats).when(mImsPhone).getImsStats();
        mIccSmsInterfaceManager.mDispatchersController = mSmsDispatchersController;
        doReturn(mLinkBandwidthEstimator).when(mPhone).getLinkBandwidthEstimator();
        doReturn(mCellIdentity).when(mPhone).getCurrentCellIdentity();
        doReturn(mCellLocation).when(mCellIdentity).asCellLocation();

        //mUiccController
        doReturn(mUiccCardApplication3gpp).when(mUiccController).getUiccCardApplication(anyInt(),
+128 −7
Original line number Diff line number Diff line
@@ -239,7 +239,7 @@ public class DcTrackerTest extends TelephonyTest {

        private String mFakeApn5Types = "dun";

        private int mNetworkTypeBitmask = NETWORK_TYPE_LTE_BITMASK;
        private int mFakeApn1Bitmask = NETWORK_TYPE_LTE_BITMASK;

        private int mRowIdOffset = 0;

@@ -252,7 +252,7 @@ public class DcTrackerTest extends TelephonyTest {
        }

        public void setFakeApn1NetworkTypeBitmask(int bitmask) {
            mNetworkTypeBitmask = bitmask;
            mFakeApn1Bitmask = bitmask;
        }

        public void setRowIdOffset(int rowIdOffset) {
@@ -291,7 +291,7 @@ public class DcTrackerTest extends TelephonyTest {
                    0,                      // mtu
                    "",                     // mvno_type
                    "",                     // mnvo_match_data
                    mNetworkTypeBitmask,    // network_type_bitmask
                    mFakeApn1Bitmask,       // network_type_bitmask
                    0,                      // apn_set_id
                    -1,                     // carrier_id
                    -1                      // skip_464xlat
@@ -1256,7 +1256,7 @@ public class DcTrackerTest extends TelephonyTest {
                eq(AccessNetworkType.EUTRAN), any(DataProfile.class), eq(false), eq(false),
                eq(DataService.REQUEST_REASON_NORMAL), any(), anyInt(), any(), tdCaptor.capture(),
                anyBoolean(), any(Message.class));
        assertEquals("FAKE APN 1", tdCaptor.getValue().getDataNetworkName());
        assertEquals(FAKE_APN1, tdCaptor.getValue().getDataNetworkName());
        assertEquals(null, tdCaptor.getValue().getOsAppId());

        mNetworkRegistrationInfo = new NetworkRegistrationInfo.Builder()
@@ -1276,7 +1276,128 @@ public class DcTrackerTest extends TelephonyTest {
                eq(DataService.REQUEST_REASON_NORMAL), any(), anyInt(), any(), tdCaptor.capture(),
                anyBoolean(), any(Message.class));
        assertEquals(null, tdCaptor.getValue().getDataNetworkName());
        assertEquals(tdCaptor.getValue().getOsAppId(), "ENTERPRISE");
        assertEquals("ENTERPRISE", tdCaptor.getValue().getOsAppId());
    }

    // Test the ENTERPRISE APN setup when default data is not set up yet.
    @Test
    public void testTrySetupDataEnterpriseApnNoDefaultData() {
        mNetworkRegistrationInfo = new NetworkRegistrationInfo.Builder()
                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_NR)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .build();
        doReturn(mNetworkRegistrationInfo).when(mServiceState).getNetworkRegistrationInfo(
                anyInt(), anyInt());
        mDct.enableApn(ApnSetting.TYPE_ENTERPRISE, DcTracker.REQUEST_TYPE_NORMAL, null);
        sendInitializationEvents();

        ArgumentCaptor<TrafficDescriptor> tdCaptor =
                ArgumentCaptor.forClass(TrafficDescriptor.class);
        verify(mSimulatedCommandsVerifier, times(1)).setupDataCall(
                eq(AccessNetworkType.NGRAN), any(DataProfile.class), eq(false), eq(false),
                eq(DataService.REQUEST_REASON_NORMAL), any(), anyInt(), any(), tdCaptor.capture(),
                anyBoolean(), any(Message.class));
        assertEquals(null, tdCaptor.getValue().getDataNetworkName());
        assertEquals("ENTERPRISE", tdCaptor.getValue().getOsAppId());

        // Check APN contexts with no DEFAULT set up
        Map<Integer, ApnContext> apnContexts = mDct.getApnContexts()
                .stream().collect(Collectors.toMap(ApnContext::getApnTypeBitmask, x -> x));
        assertEquals(DctConstants.State.IDLE, apnContexts.get(ApnSetting.TYPE_DEFAULT).getState());
        assertEquals(DctConstants.State.FAILED,
                apnContexts.get(ApnSetting.TYPE_ENTERPRISE).getState());

        mNetworkRegistrationInfo = new NetworkRegistrationInfo.Builder()
                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_LTE)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .build();
        doReturn(mNetworkRegistrationInfo).when(mServiceState).getNetworkRegistrationInfo(
                anyInt(), anyInt());
        mDct.enableApn(ApnSetting.TYPE_DEFAULT, DcTracker.REQUEST_TYPE_NORMAL, null);
        waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
        waitForMs(200);

        verify(mSimulatedCommandsVerifier, times(1)).setupDataCall(
                eq(AccessNetworkType.EUTRAN), any(DataProfile.class), eq(false), eq(false),
                eq(DataService.REQUEST_REASON_NORMAL), any(), anyInt(), any(), tdCaptor.capture(),
                anyBoolean(), any(Message.class));
        assertEquals(FAKE_APN1, tdCaptor.getValue().getDataNetworkName());
        assertEquals(null, tdCaptor.getValue().getOsAppId());

        // Check APN contexts after DEFAULT is set up (and ENTERPRISE failure)
        apnContexts = mDct.getApnContexts()
                .stream().collect(Collectors.toMap(ApnContext::getApnTypeBitmask, x -> x));
        assertEquals(DctConstants.State.CONNECTED,
                apnContexts.get(ApnSetting.TYPE_DEFAULT).getState());
        assertEquals(DctConstants.State.FAILED,
                apnContexts.get(ApnSetting.TYPE_ENTERPRISE).getState());

        mNetworkRegistrationInfo = new NetworkRegistrationInfo.Builder()
                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_NR)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .build();
        doReturn(mNetworkRegistrationInfo).when(mServiceState).getNetworkRegistrationInfo(
                anyInt(), anyInt());
        SetupDataCallResult result = createSetupDataCallResult();
        result.cid = 10;
        mSimulatedCommands.setDataCallResult(true, result);
        mDct.enableApn(ApnSetting.TYPE_ENTERPRISE, DcTracker.REQUEST_TYPE_NORMAL, null);
        waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
        waitForMs(200);

        verify(mSimulatedCommandsVerifier, times(2)).setupDataCall(
                eq(AccessNetworkType.NGRAN), any(DataProfile.class), eq(false), eq(false),
                eq(DataService.REQUEST_REASON_NORMAL), any(), anyInt(), any(), tdCaptor.capture(),
                anyBoolean(), any(Message.class));
        assertEquals(null, tdCaptor.getValue().getDataNetworkName());
        assertEquals("ENTERPRISE", tdCaptor.getValue().getOsAppId());

        // Check APN contexts after DEFAULT is set up (and ENTERPRISE reenabled)
        apnContexts = mDct.getApnContexts()
                .stream().collect(Collectors.toMap(ApnContext::getApnTypeBitmask, x -> x));
        assertEquals(DctConstants.State.CONNECTED,
                apnContexts.get(ApnSetting.TYPE_DEFAULT).getState());
        assertEquals(DctConstants.State.CONNECTED,
                apnContexts.get(ApnSetting.TYPE_ENTERPRISE).getState());
    }

    // Test the ENTERPRISE APN setup when the same CID is returned.
    @Test
    public void testTrySetupDataEnterpriseApnDuplicateCid() {
        mApnSettingContentProvider.setFakeApn1NetworkTypeBitmask(
                NETWORK_TYPE_LTE_BITMASK | NETWORK_TYPE_NR_BITMASK);
        mNetworkRegistrationInfo = new NetworkRegistrationInfo.Builder()
                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_NR)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .build();
        doReturn(mNetworkRegistrationInfo).when(mServiceState).getNetworkRegistrationInfo(
                anyInt(), anyInt());
        // mSimulatedCommandsVerifier will return the same CID in SetupDataCallResult
        mDct.enableApn(ApnSetting.TYPE_DEFAULT, DcTracker.REQUEST_TYPE_NORMAL, null);
        mDct.enableApn(ApnSetting.TYPE_ENTERPRISE, DcTracker.REQUEST_TYPE_NORMAL, null);
        sendInitializationEvents();
        waitForMs(200);

        ArgumentCaptor<TrafficDescriptor> tdCaptor =
                ArgumentCaptor.forClass(TrafficDescriptor.class);
        verify(mSimulatedCommandsVerifier, times(2)).setupDataCall(
                eq(AccessNetworkType.NGRAN), any(DataProfile.class), eq(false), eq(false),
                eq(DataService.REQUEST_REASON_NORMAL), any(), anyInt(), any(), tdCaptor.capture(),
                anyBoolean(), any(Message.class));
        List<TrafficDescriptor> tds = tdCaptor.getAllValues();
        // [0] is default and [1] is enterprise, since default should be set up first
        assertEquals(FAKE_APN1, tds.get(0).getDataNetworkName());
        assertEquals(null, tds.get(0).getOsAppId());
        assertEquals(null, tds.get(1).getDataNetworkName());
        assertEquals("ENTERPRISE", tds.get(1).getOsAppId());

        // Check APN contexts after DEFAULT and ENTERPRISE set up
        Map<Integer, ApnContext> apnContexts = mDct.getApnContexts()
                .stream().collect(Collectors.toMap(ApnContext::getApnTypeBitmask, x -> x));
        assertEquals(DctConstants.State.CONNECTED,
                apnContexts.get(ApnSetting.TYPE_DEFAULT).getState());
        assertEquals(DctConstants.State.FAILED,
                apnContexts.get(ApnSetting.TYPE_ENTERPRISE).getState());
    }

    @Test
@@ -1733,7 +1854,7 @@ public class DcTrackerTest extends TelephonyTest {
                eq(AccessNetworkType.EUTRAN), any(DataProfile.class), eq(false), eq(false),
                eq(DataService.REQUEST_REASON_NORMAL), any(), anyInt(), any(), tdCaptor.capture(),
                anyBoolean(), any(Message.class));
        assertEquals("FAKE APN 1", tdCaptor.getValue().getDataNetworkName());
        assertEquals(FAKE_APN1, tdCaptor.getValue().getDataNetworkName());
        assertEquals(null, tdCaptor.getValue().getOsAppId());

        // Check APN contexts after DEFAULT is set up
@@ -1762,7 +1883,7 @@ public class DcTrackerTest extends TelephonyTest {
                eq(DataService.REQUEST_REASON_NORMAL), any(), anyInt(), any(), tdCaptor.capture(),
                anyBoolean(), any(Message.class));
        assertEquals(null, tdCaptor.getValue().getDataNetworkName());
        assertEquals(tdCaptor.getValue().getOsAppId(), "ENTERPRISE");
        assertEquals("ENTERPRISE", tdCaptor.getValue().getOsAppId());

        // Check APN contexts after ENTERPRISE is set up
        Map<Integer, ApnContext> apnContextsAfterRowIdsChanged = mDct.getApnContexts()