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

Commit 13ff2eb1 authored by Xiangyu/Malcolm Chen's avatar Xiangyu/Malcolm Chen Committed by Android (Google) Code Review
Browse files

Merge "Accept restricted network request on non default data SIM." into qt-dev

parents b9d1f776 6ccdd6b1
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -758,11 +758,15 @@ public class PhoneSwitcher extends Handler {

        int preferredDataSubId = SubscriptionManager.isValidPhoneId(mPreferredDataPhoneId)
                ? mPhoneSubscriptions[mPreferredDataPhoneId] : INVALID_SUBSCRIPTION_ID;

        // Currently we assume multi-SIM devices will only support one Internet PDN connection. So
        // if Internet PDN is established on the non-preferred phone, it will interrupt
        // Internet connection on the preferred phone. So we only accept Internet request with
        // preferred data subscription or no specified subscription.
        // One exception is, if it's restricted request (doesn't have NET_CAPABILITY_NOT_RESTRICTED)
        // it will be accepted, which is used temporary data usage from system.
        if (netRequest.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                && netRequest.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
                && subId != preferredDataSubId && subId != mValidator.getSubIdInValidation()) {
            // Returning INVALID_PHONE_INDEX will result in netRequest not being handled.
            return INVALID_PHONE_INDEX;
+38 −1
Original line number Diff line number Diff line
@@ -574,6 +574,35 @@ public class PhoneSwitcherTest extends TelephonyTest {
        mHandlerThread.quit();
    }


    @Test
    @SmallTest
    public void testNetworkRequestOnNonDefaultData() throws Exception {
        final int numPhones = 2;
        final int maxActivePhones = 1;
        doReturn(true).when(mMockRadioConfig).isSetPreferredDataCommandSupported();
        initialize(numPhones, maxActivePhones);
        // Phone 0 has sub 1, phone 1 has sub 2.
        // Sub 1 is default data sub.
        // Both are active subscriptions are active sub, as they are in both active slots.
        setSlotIndexToSubId(0, 1);
        setSlotIndexToSubId(1, 2);
        setDefaultDataSubId(1);
        waitABit();
        NetworkRequest internetRequest = addInternetNetworkRequest(2, 50);
        waitABit();
        assertFalse(mPhoneSwitcher.shouldApplyNetworkRequest(internetRequest, 0));
        assertFalse(mPhoneSwitcher.shouldApplyNetworkRequest(internetRequest, 1));

        // Restricted network request will should be applied.
        internetRequest = addInternetNetworkRequest(2, 50, true);
        waitABit();
        assertFalse(mPhoneSwitcher.shouldApplyNetworkRequest(internetRequest, 0));
        assertTrue(mPhoneSwitcher.shouldApplyNetworkRequest(internetRequest, 1));

        mHandlerThread.quit();
    }

    /* Private utility methods start here */

    private void sendDefaultDataSubChanged() {
@@ -728,10 +757,18 @@ public class PhoneSwitcherTest extends TelephonyTest {
     * Create an internet PDN network request and send it to PhoneSwitcher.
     */
    private NetworkRequest addInternetNetworkRequest(Integer subId, int score) throws Exception {
        return addInternetNetworkRequest(subId, score, false);
    }

    private NetworkRequest addInternetNetworkRequest(Integer subId, int score, boolean restricted)
            throws Exception {
        NetworkCapabilities netCap = (new NetworkCapabilities())
                .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
                .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
        if (restricted) {
            netCap.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED);
        }

        if (subId != null) {
            netCap.setNetworkSpecifier(new StringNetworkSpecifier(Integer.toString(subId)));
        }
+0 −3
Original line number Diff line number Diff line
@@ -296,9 +296,6 @@ public class TelephonyNetworkFactoryTest extends TelephonyTest {
        mSubscriptionControllerMock.setSlotSubId(phoneId, subId);
        mSubscriptionMonitorMock.notifySubscriptionChanged(phoneId);
        waitForMs(250);
        // Although specified a subId, Internet request is only handled by
        // preferred data phone.
        assertEquals(1, mNetworkRequestList.size());

        mSubscriptionControllerMock.setDefaultDataSubId(subId);
        mPhoneSwitcherMock.setPreferredDataPhoneId(phoneId);