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

Commit a71c90d8 authored by Jack Yu's avatar Jack Yu
Browse files

Fixed the incorrect APN dedupling

Fixed that APN settings can't be merged when one APN
entry has MTU set, but the other doesn't. Also default
MTU unset value to 0 for backwards compatability.

Test: atest DataProfileManagerTest & Manual testing
Fix: 226563054
Change-Id: Ie03959e317d11e906e2f72833255a29c96920890
parent 96d114be
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -762,8 +762,10 @@ public class DataProfileManager extends Handler {
        apnBuilder.setAuthType(apn2.getAuthType() == -1
                ? apn1.getAuthType() : apn2.getAuthType());
        apnBuilder.setApnTypeBitmask(apn1.getApnTypeBitmask() | apn2.getApnTypeBitmask());
        apnBuilder.setMtuV4(apn2.getMtuV4() == -1 ? apn1.getMtuV4() : apn2.getMtuV4());
        apnBuilder.setMtuV6(apn2.getMtuV6() == -1 ? apn1.getMtuV6() : apn2.getMtuV6());
        apnBuilder.setMtuV4(apn2.getMtuV4() <= ApnSetting.UNSET_MTU
                ? apn1.getMtuV4() : apn2.getMtuV4());
        apnBuilder.setMtuV6(apn2.getMtuV6() <= ApnSetting.UNSET_MTU
                ? apn1.getMtuV6() : apn2.getMtuV6());

        // The following fields in apn1 and apn2 should be the same, otherwise ApnSetting.similar()
        // should fail earlier.
+56 −4
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ public class DataProfileManagerTest extends TelephonyTest {
                        0,                      // max_conns
                        0,                      // wait_time
                        0,                      // max_conns_time
                        -1,                     // mtu
                        0,                      // mtu
                        1280,                   // mtu_v4
                        1280,                   // mtu_v6
                        "",                     // mvno_type
@@ -280,9 +280,9 @@ public class DataProfileManagerTest extends TelephonyTest {
                        0,                      // max_conns
                        0,                      // wait_time
                        0,                      // max_conns_time
                        -1,                     // mtu
                        -1,                     // mtu_v4
                        -1,                     // mtu_v6
                        0,                      // mtu
                        0,                      // mtu_v4
                        0,                      // mtu_v6
                        "",                     // mvno_type
                        "",                     // mnvo_match_data
                        TelephonyManager.NETWORK_TYPE_BITMASK_LTE
@@ -757,6 +757,58 @@ public class DataProfileManagerTest extends TelephonyTest {
                .isEqualTo(ApnSetting.PROTOCOL_IPV4V6);
    }

    @Test
    public void testDedupeDataProfiles3() throws Exception {
        DataProfile dataProfile1 = new DataProfile.Builder()
                .setApnSetting(new ApnSetting.Builder()
                        .setEntryName("BTT Lastgenphone")
                        .setId(1)
                        .setOperatorNumeric("123456")
                        .setApnName("lastgenphone")
                        .setApnTypeBitmask(ApnSetting.TYPE_DEFAULT | ApnSetting.TYPE_MMS
                                | ApnSetting.TYPE_SUPL | ApnSetting.TYPE_FOTA)
                        .setMmsc(Uri.parse("http://mmsc.mobile.btt.net"))
                        .setMmsProxyAddress("proxy.mobile.btt.net")
                        .setMmsProxyPort(80)
                        .setMtuV4(1410)
                        .setProtocol(ApnSetting.PROTOCOL_IPV4V6)
                        .setRoamingProtocol(ApnSetting.PROTOCOL_IPV4V6)
                        .setCarrierEnabled(true)
                        .build())
                .build();

        DataProfile dataProfile2 = new DataProfile.Builder()
                .setApnSetting(new ApnSetting.Builder()
                        .setEntryName("BTT XCAP")
                        .setId(5)
                        .setOperatorNumeric("123456")
                        .setApnName("lastgenphone")
                        .setApnTypeBitmask(ApnSetting.TYPE_XCAP)
                        .setProtocol(ApnSetting.PROTOCOL_IPV4V6)
                        .setRoamingProtocol(ApnSetting.PROTOCOL_IPV4V6)
                        .setCarrierEnabled(true)
                        .build())
                .build();

        List<DataProfile> dataProfiles = new ArrayList<>(Arrays.asList(dataProfile2, dataProfile1));

        logd("dp1.apnSetting, dp2.apnSetting similar="
                + dataProfile1.getApnSetting().similar(dataProfile2.getApnSetting()));

        dedupeDataProfiles(dataProfiles);
        // After deduping, there should be only one.
        assertThat(dataProfiles).hasSize(1);

        DataProfile dataProfile = dataProfiles.get(0);
        assertThat(dataProfile.getApnSetting()).isNotNull();


        logd("After merged: " + dataProfile);
        assertThat(dataProfile.getApnSetting().getApnTypeBitmask()).isEqualTo(
                ApnSetting.TYPE_DEFAULT | ApnSetting.TYPE_MMS | ApnSetting.TYPE_SUPL
                        | ApnSetting.TYPE_FOTA | ApnSetting.TYPE_XCAP);
    }

    @Test
    public void testIsDataProfileValid() {
        TelephonyNetworkRequest tnr = new TelephonyNetworkRequest(new NetworkRequest.Builder()