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

Commit acb75d0e authored by Sarah Chin's avatar Sarah Chin Committed by Automerger Merge Worker
Browse files

Merge changes from topic "carrier_name_api" am: 3994f51d am: 5691ce56

Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/1661996

Change-Id: Icb5cf6c23899be11af31e0e94e71d1340bb60f67
parents edd0034a 5691ce56
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -2052,8 +2052,10 @@ public class DcTracker extends Handler {
        // a dun-profiled connection so we can't share an existing one
        // On GSM/LTE we can share existing apn connections provided they support
        // this type.
        if (!apnContext.getApnType().equals(ApnSetting.TYPE_DUN_STRING)
                || ServiceState.isGsm(getDataRat())) {
        // If asking for ENTERPRISE, there are no compatible data connections, so skip this check
        if ((apnContext.getApnTypeBitmask() != ApnSetting.TYPE_DUN
                || ServiceState.isGsm(getDataRat()))
                && apnContext.getApnTypeBitmask() != ApnSetting.TYPE_ENTERPRISE) {
            dataConnection = checkForCompatibleDataConnection(apnContext, apnSetting);
            if (dataConnection != null) {
                // Get the apn setting used by the data connection
@@ -2478,7 +2480,7 @@ public class DcTracker extends Handler {
                            }
                        }
                    }
                } else if (apnSetting != null && apnSetting.canHandleType(apnType)) {
                } else if (isApnSettingCompatible(curDc, apnType)) {
                    if (curDc.isActive()) {
                        if (DBG) {
                            log("checkForCompatibleDataConnection:"
@@ -2498,6 +2500,20 @@ public class DcTracker extends Handler {
        return potentialDc;
    }

    private boolean isApnSettingCompatible(DataConnection dc, int apnType) {
        ApnSetting apnSetting = dc.getApnSetting();
        if (apnSetting == null) return false;

        // Nothing can be compatible with type ENTERPRISE
        for (ApnContext apnContext : dc.getApnContexts()) {
            if (apnContext.getApnTypeBitmask() == ApnSetting.TYPE_ENTERPRISE) {
                return false;
            }
        }

        return apnSetting.canHandleType(apnType);
    }

    private void addRequestNetworkCompleteMsg(Message onCompleteMsg,
                                              @ApnType int apnType) {
        if (onCompleteMsg != null) {
+70 −2
Original line number Diff line number Diff line
@@ -209,12 +209,18 @@ public class DcTrackerTest extends TelephonyTest {

        private String mFakeApn1Types = "default,supl";

        private int mNetworkTypeBitmask = NETWORK_TYPE_LTE_BITMASK;

        private int mRowIdOffset = 0;

        public void setFakeApn1Types(String apnTypes) {
            mFakeApn1Types = apnTypes;
        }

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

        public void setRowIdOffset(int rowIdOffset) {
            mRowIdOffset = rowIdOffset;
        }
@@ -289,7 +295,7 @@ public class DcTrackerTest extends TelephonyTest {
                            0,                      // mtu
                            "",                     // mvno_type
                            "",                     // mnvo_match_data
                            NETWORK_TYPE_LTE_BITMASK, // network_type_bitmask
                            mNetworkTypeBitmask,    // network_type_bitmask
                            0,                      // apn_set_id
                            -1,                     // carrier_id
                            -1                      // skip_464xlat
@@ -1219,7 +1225,7 @@ public class DcTrackerTest extends TelephonyTest {
                eq(DataService.REQUEST_REASON_NORMAL), any(), anyInt(), any(), tdCaptor.capture(),
                anyBoolean(), any(Message.class));
        assertEquals(null, tdCaptor.getValue().getDnn());
        assertTrue(tdCaptor.getValue().getOsAppId().equals("ENTERPRISE"));
        assertEquals(tdCaptor.getValue().getOsAppId(), "ENTERPRISE");
    }

    @Test
@@ -1631,6 +1637,68 @@ public class DcTrackerTest extends TelephonyTest {
                apnContextsAfterRowIdsChanged.get(ApnSetting.TYPE_DUN).getDataConnection());
    }

    @Test
    @SmallTest
    public void testCheckForCompatibleDataConnectionWithEnterprise() {
        // Allow both DEFAULT and ENTERPRISE to use APN 1
        mApnSettingContentProvider.setFakeApn1NetworkTypeBitmask(
                NETWORK_TYPE_LTE_BITMASK | NETWORK_TYPE_NR_BITMASK);

        // Enable the DEFAULT APN
        mDct.enableApn(ApnSetting.TYPE_DEFAULT, DcTracker.REQUEST_TYPE_NORMAL, null);
        waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
        sendInitializationEvents();

        ArgumentCaptor<TrafficDescriptor> tdCaptor =
                ArgumentCaptor.forClass(TrafficDescriptor.class);
        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 APN 1", tdCaptor.getValue().getDnn());
        assertEquals(null, tdCaptor.getValue().getOsAppId());

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

        // Enable the ENTERPRISE APN
        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);
        waitForMs(200);

        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().getDnn());
        assertEquals(tdCaptor.getValue().getOsAppId(), "ENTERPRISE");

        // Check APN contexts after ENTERPRISE is set up
        Map<Integer, ApnContext> apnContextsAfterRowIdsChanged = mDct.getApnContexts()
                .stream().collect(Collectors.toMap(ApnContext::getApnTypeBitmask, x -> x));

        // Make sure that the data connection used earlier wasn't cleaned up and still in use.
        assertEquals(apnContexts.get(ApnSetting.TYPE_DEFAULT).getDataConnection(),
                apnContextsAfterRowIdsChanged.get(ApnSetting.TYPE_DEFAULT).getDataConnection());

        // Check that ENTERPRISE isn't using the same data connection as DEFAULT
        assertNotEquals(apnContexts.get(ApnSetting.TYPE_DEFAULT).getDataConnection(),
                apnContextsAfterRowIdsChanged.get(ApnSetting.TYPE_ENTERPRISE).getDataConnection());
    }

    // Test for Data setup with APN Set ID
    @Test
    @SmallTest