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

Commit 3b28d713 authored by Jack Yu's avatar Jack Yu Committed by android-build-merger
Browse files

Merge "Add the logic for check skip 464xlat" am: 8e20a825 am: f41f1053

am: 1791048d

Change-Id: I55f3d9cedc17626048d7a59b2a69f778f9e9bfbc
parents e690300e 1791048d
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;
@@ -1195,6 +1196,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.
     */
@@ -1810,6 +1832,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
@@ -3186,7 +3186,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
@@ -230,7 +230,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
@@ -261,7 +262,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[]{
@@ -293,7 +295,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[]{
@@ -325,7 +328,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[]{
@@ -357,7 +361,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[]{
@@ -389,7 +394,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;