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

Commit aa5cf5f7 authored by Yuuki Habu's avatar Yuuki Habu
Browse files

Add the logic for check skip 464xlat

Add process to determine that whether the current NetworkCapability
should skip the 464xlat with ApnSetting

Bug: 69949375
Test: following manual test and Unit Test
 - skipped 464xlat on the ims network and no internet
 - skipped 464xlat on network if flag is set as 1
 - NOT skipped 464xlat on network if flag is set as 0
 - run ApnSettingTest, DataConnectionTest and DcTrackerTest

Change-Id: I676a02cb92530d64f29f34e89482a934f3ec4553
parent af64bf9d
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.provider.Telephony;
import android.telephony.AccessNetworkConstants.TransportType;
import android.telephony.DataFailCause;
import android.telephony.Rlog;
@@ -1194,6 +1195,27 @@ public class DataConnection extends StateMachine {
        return result;
    }

    /**
     * @return {@code True} if 464xlat should be skipped.
     */
    @VisibleForTesting
    public boolean shouldSkip464Xlat() {
        switch (mApnSetting.getSkip464Xlat()) {
            case Telephony.Carriers.SKIP_464XLAT_ENABLE:
                return true;
            case Telephony.Carriers.SKIP_464XLAT_DISABLE:
                return false;
            case Telephony.Carriers.SKIP_464XLAT_DEFAULT:
            default:
                break;
        }

        // As default, return true if ims and no internet
        final NetworkCapabilities nc = getNetworkCapabilities();
        return nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_IMS)
                && !nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
    }

    /**
     * @return {@code} true iff. {@code address} is a literal IPv4 or IPv6 address.
     */
@@ -1807,6 +1829,9 @@ public class DataConnection extends StateMachine {
            }
            misc.subscriberId = mPhone.getSubscriberId();

            // set skip464xlat if it is not default otherwise
            misc.skip464xlat = shouldSkip464Xlat();

            mRestrictedNetworkOverride = shouldRestrictNetwork();
            mUnmeteredUseOnly = isUnmeteredUseOnly();

+2 −1
Original line number Diff line number Diff line
@@ -3179,7 +3179,8 @@ public class DcTracker extends Handler {
            dest.isEnabled(), networkTypeBitmask, dest.getProfileId(),
            (dest.isPersistent() || src.isPersistent()), dest.getMaxConns(),
            dest.getWaitTime(), dest.getMaxConnsTime(), dest.getMtu(), dest.getMvnoType(),
            dest.getMvnoMatchData(), dest.getApnSetId(), dest.getCarrierId());
            dest.getMvnoMatchData(), dest.getApnSetId(), dest.getCarrierId(),
            dest.getSkip464Xlat());
    }

    private DataConnection createDataConnection() {
+19 −8
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ public class ApnSettingTest extends TelephonyTest {
        assertEquals(a1.getMvnoMatchData(), a2.getMvnoMatchData());
        assertEquals(a1.getNetworkTypeBitmask(), a2.getNetworkTypeBitmask());
        assertEquals(a1.getApnSetId(), a2.getApnSetId());
        assertEquals(a1.getSkip464Xlat(), a2.getSkip464Xlat());
    }

    @Test
@@ -229,7 +230,7 @@ public class ApnSettingTest extends TelephonyTest {
        expectedApn = ApnSetting.makeApnSetting(
                -1, "12345", "Name", "apn", "", -1, null, "", -1, "", "", 0,
                mmsTypesBitmask, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true,
                0, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "testspn", 3, -1);
                0, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "testspn", 3, -1, -1);
        assertApnSettingEqual(expectedApn, ApnSetting.fromString(testString));

        // A v6 string with carrierId=100
@@ -239,7 +240,17 @@ public class ApnSettingTest extends TelephonyTest {
        expectedApn = ApnSetting.makeApnSetting(
            -1, "12345", "Name", "apn", "", -1, null, "", -1, "", "", 0,
            mmsTypesBitmask, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true,
            0, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "testspn", 3, 100);
            0, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "testspn", 3, 100, -1);
        assertApnSettingEqual(expectedApn, ApnSetting.fromString(testString));

        // A v7 string with skip_464xlat=1
        testString =
            "[ApnSettingV7] Name,apn,,,,,,,,,123,45,,mms|*,IPV6,IP,true,0,,,,,,,spn,testspn,0,3,"
                + "-1, 1";
        expectedApn = ApnSetting.makeApnSetting(
            -1, "12345", "Name", "apn", "", -1, null, "", -1, "", "", 0,
            mmsTypesBitmask, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true,
            0, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "testspn", 3, -1, 1);
        assertApnSettingEqual(expectedApn, ApnSetting.fromString(testString));

        // Return no apn if insufficient fields given.
@@ -279,7 +290,7 @@ public class ApnSettingTest extends TelephonyTest {
        expectedApns.add(ApnSetting.makeApnSetting(
                -1, "12346", "Name1", "apn2", "", -1, null, "", -1, "", "", 0,
                mmsTypesBitmask, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true,
                0, 0, false, 0, 0, 0, 0, -1, "", 3, -1));
                0, 0, false, 0, 0, 0, 0, -1, "", 3, -1, -1));
        assertApnSettingsEqual(expectedApns, ApnSetting.arrayFromString(testString));
    }

@@ -292,9 +303,9 @@ public class ApnSettingTest extends TelephonyTest {
                null, null, -1, "user", "password", 0,
                ApnSetting.TYPE_DEFAULT, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true,
                4096, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "");
        String expected = "[ApnSettingV6] Name, 99, 12345, apn, null, "
        String expected = "[ApnSettingV7] Name, 99, 12345, apn, null, "
                + "null, null, null, 10, 0, hipri | default, "
                + "IPV6, IP, true, 0, false, 0, 0, 0, 0, spn, , false, 4096, 0, -1";
                + "IPV6, IP, true, 0, false, 0, 0, 0, 0, spn, , false, 4096, 0, -1, -1";
        assertEquals(expected, apn.toString());

        final int networkTypeBitmask = 1 << (14 - 1);
@@ -302,10 +313,10 @@ public class ApnSettingTest extends TelephonyTest {
                99, "12345", "Name", "apn", null, 10,
                null, null, -1, "user", "password", 0,
                ApnSetting.TYPE_DEFAULT, ApnSetting.PROTOCOL_IPV6, ApnSetting.PROTOCOL_IP, true,
                networkTypeBitmask, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "", 3, -1);
        expected = "[ApnSettingV6] Name, 99, 12345, apn, null, "
                networkTypeBitmask, 0, false, 0, 0, 0, 0, ApnSetting.MVNO_TYPE_SPN, "", 3, -1, 1);
        expected = "[ApnSettingV7] Name, 99, 12345, apn, null, "
                + "null, null, null, 10, 0, hipri | default, "
                + "IPV6, IP, true, 0, false, 0, 0, 0, 0, spn, , false, 8192, 3, -1";
                + "IPV6, IP, true, 0, false, 0, 0, 0, 0, spn, , false, 8192, 3, -1, 1";
        assertEquals(expected, apn.toString());
    }

+125 −0
Original line number Diff line number Diff line
@@ -157,6 +157,93 @@ public class DataConnectionTest extends TelephonyTest {
            -1,                     // mvno_type
            "");                    // mnvo_match_data

    private ApnSetting mApn3 = ApnSetting.makeApnSetting(
            2164,                   // id
            "44010",                // numeric
            "sp-mode",              // name
            "spmode.ne.jp",         // apn
            null,                   // proxy
            -1,                     // port
            null,                   // mmsc
            null,                   // mmsproxy
            -1,                     // mmsport
            "",                     // user
            "",                     // password
            -1,                     // authtype
            ApnSetting.TYPE_DEFAULT, // types
            ApnSetting.PROTOCOL_IPV6, // protocol
            ApnSetting.PROTOCOL_IP, // roaming_protocol
            true,                   // carrier_enabled
            0,                      // networktype_bitmask
            0,                      // profile_id
            false,                  // modem_cognitive
            0,                      // max_conns
            0,                      // wait_time
            0,                      // max_conns_time
            0,                      // mtu
            -1,                     // mvno_type
            "",                     // mnvo_match_data
            0,                      // apn_set_id
            -1,                     // carrier_id
            1);                     // skip_464xlat

    private ApnSetting mApn4 = ApnSetting.makeApnSetting(
            2164,                   // id
            "44010",                // numeric
            "sp-mode",              // name
            "spmode.ne.jp",         // apn
            null,                   // proxy
            -1,                     // port
            null,                   // mmsc
            null,                   // mmsproxy
            -1,                     // mmsport
            "",                     // user
            "",                     // password
            -1,                     // authtype
            ApnSetting.TYPE_IMS,    // types
            ApnSetting.PROTOCOL_IPV6, // protocol
            ApnSetting.PROTOCOL_IP, // roaming_protocol
            true,                   // carrier_enabled
            0,                      // networktype_bitmask
            0,                      // profile_id
            false,                  // modem_cognitive
            0,                      // max_conns
            0,                      // wait_time
            0,                      // max_conns_time
            0,                      // mtu
            -1,                     // mvno_type
            "");                    // mnvo_match_data

    private ApnSetting mApn5 = ApnSetting.makeApnSetting(
            2164,                   // id
            "44010",                // numeric
            "sp-mode",              // name
            "spmode.ne.jp",         // apn
            null,                   // proxy
            -1,                     // port
            null,                   // mmsc
            null,                   // mmsproxy
            -1,                     // mmsport
            "",                     // user
            "",                     // password
            -1,                     // authtype
            ApnSetting.TYPE_IMS,    // types
            ApnSetting.PROTOCOL_IPV6, // protocol
            ApnSetting.PROTOCOL_IP, // roaming_protocol
            true,                   // carrier_enabled
            0,                      // networktype_bitmask
            0,                      // profile_id
            false,                  // modem_cognitive
            0,                      // max_conns
            0,                      // wait_time
            0,                      // max_conns_time
            0,                      // mtu
            -1,                     // mvno_type
            "",                     // mnvo_match_data
            0,                      // apn_set_id
            -1,                     // carrier_id
            0);                     // skip_464xlat

    private class DataConnectionTestHandler extends HandlerThread {

        private DataConnectionTestHandler(String name) {
@@ -509,6 +596,44 @@ public class DataConnectionTest extends TelephonyTest {
        assertTrue(getNetworkCapabilities().hasCapability(NET_CAPABILITY_NOT_CONGESTED));
    }

    @Test
    public void testShouldSkip464Xlat() throws Exception {
        assertFalse(testShouldSkip464XlatEvent(mApn1));
        disconnectEvent();

        assertTrue(testShouldSkip464XlatEvent(mApn3));
        disconnectEvent();

        assertTrue(testShouldSkip464XlatEvent(mApn4));
        disconnectEvent();

        assertFalse(testShouldSkip464XlatEvent(mApn5));
        disconnectEvent();
    }

    private boolean testShouldSkip464XlatEvent(ApnSetting apn) throws Exception {
        Method method = DataConnection.class.getDeclaredMethod("shouldSkip464Xlat");
        method.setAccessible(true);

        doReturn(apn).when(mApnContext).getApnSetting();
        connectEvent();
        logd(getNetworkCapabilities().toString());

        return (Boolean) method.invoke(mDc);
    }

    private void connectEvent() throws Exception {
        mDc.sendMessage(DataConnection.EVENT_CONNECT, mCp);
        waitForMs(200);
        assertEquals("DcActiveState", getCurrentState().getName());
    }

    private void disconnectEvent() throws Exception {
        mDc.sendMessage(DataConnection.EVENT_DISCONNECT, mDcp);
        waitForMs(100);
        assertEquals("DcInactiveState", getCurrentState().getName());
    }

    @Test
    @SmallTest
    public void testIsIpAddress() throws Exception {
+12 −6
Original line number Diff line number Diff line
@@ -229,7 +229,8 @@ public class DcTrackerTest extends TelephonyTest {
                                    Telephony.Carriers.MVNO_MATCH_DATA,
                                    Telephony.Carriers.NETWORK_TYPE_BITMASK,
                                    Telephony.Carriers.APN_SET_ID,
                                    Telephony.Carriers.CARRIER_ID});
                                    Telephony.Carriers.CARRIER_ID,
                                    Telephony.Carriers.SKIP_464XLAT});

                    mc.addRow(new Object[]{
                            2163,                   // id
@@ -260,7 +261,8 @@ public class DcTrackerTest extends TelephonyTest {
                            "",                     // mnvo_match_data
                            NETWORK_TYPE_LTE_BITMASK, // network_type_bitmask
                            0,                      // apn_set_id
                            -1                      // carrier_id
                            -1,                     // carrier_id
                            -1                      // skip_464xlat
                    });

                    mc.addRow(new Object[]{
@@ -292,7 +294,8 @@ public class DcTrackerTest extends TelephonyTest {
                            "",                     // mnvo_match_data
                            NETWORK_TYPE_LTE_BITMASK, // network_type_bitmask
                            0,                      // apn_set_id
                            -1                      // carrier_id
                            -1,                     // carrier_id
                            -1                      // skip_464xlat
                    });

                    mc.addRow(new Object[]{
@@ -324,7 +327,8 @@ public class DcTrackerTest extends TelephonyTest {
                            "",                     // mnvo_match_data
                            0,                      // network_type_bitmask
                            0,                      // apn_set_id
                            -1                      // carrier_id
                            -1,                     // carrier_id
                            -1                      // skip_464xlat
                    });

                    mc.addRow(new Object[]{
@@ -356,7 +360,8 @@ public class DcTrackerTest extends TelephonyTest {
                            "",                     // mnvo_match_data
                            NETWORK_TYPE_EHRPD_BITMASK, // network_type_bitmask
                            0,                      // apn_set_id
                            -1                      // carrier_id
                            -1,                     // carrier_id
                            -1                      // skip_464xlat
                    });

                    mc.addRow(new Object[]{
@@ -388,7 +393,8 @@ public class DcTrackerTest extends TelephonyTest {
                            "",                     // mnvo_match_data
                            0,                      // network_type_bitmask
                            0,                      // apn_set_id
                            -1                      // carrier_id
                            -1,                     // carrier_id
                            -1                      // skip_464xlat
                    });

                    return mc;