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

Commit 23ec1c9f authored by Jack Yu's avatar Jack Yu Committed by Gerrit Code Review
Browse files

Merge "Fixed the incorrect link address parsing"

parents 23f498b9 acc7e7a6
Loading
Loading
Loading
Loading
+36 −21
Original line number Diff line number Diff line
@@ -6540,6 +6540,38 @@ public class RIL extends BaseCommands implements CommandsInterface {
        return response;
    }

    private static LinkAddress createLinkAddressFromString(String addressString) {
        return createLinkAddressFromString(addressString, 0, LinkAddress.LIFETIME_UNKNOWN,
                LinkAddress.LIFETIME_UNKNOWN);
    }

    private static LinkAddress createLinkAddressFromString(String addressString, int properties,
            long deprecationTime, long expirationTime) {
        addressString = addressString.trim();
        InetAddress address = null;
        int prefixLength = -1;
        try {
            String[] pieces = addressString.split("/", 2);
            address = InetAddresses.parseNumericAddress(pieces[0]);
            if (pieces.length == 1) {
                prefixLength = (address instanceof Inet4Address) ? 32 : 128;
            } else if (pieces.length == 2) {
                prefixLength = Integer.parseInt(pieces[1]);
            }
        } catch (NullPointerException e) {            // Null string.
        } catch (ArrayIndexOutOfBoundsException e) {  // No prefix length.
        } catch (NumberFormatException e) {           // Non-numeric prefix.
        } catch (IllegalArgumentException e) {        // Invalid IP address.
        }

        if (address == null || prefixLength == -1) {
            throw new IllegalArgumentException("Invalid link address " + addressString);
        }

        return new LinkAddress(address, prefixLength, properties, 0,
                deprecationTime, expirationTime);
    }

    /**
     * Convert SetupDataCallResult defined in 1.0, 1.4, or 1.5 types.hal into DataCallResponse
     * @param dcResult setup data call result
@@ -6609,9 +6641,9 @@ public class RIL extends BaseCommands implements CommandsInterface {
            active = result.active;
            protocolType = result.type;
            ifname = result.ifname;
            laList = result.addresses.stream().map(a -> new LinkAddress(
                    InetAddresses.parseNumericAddress(a.address), 0, a.properties, 0,
                    a.deprecationTime, a.expirationTime)).collect(Collectors.toList());
            laList = result.addresses.stream().map(la -> createLinkAddressFromString(
                    la.address, la.properties, la.deprecationTime, la.expirationTime))
                    .collect(Collectors.toList());

            dnses = result.dnses.stream().toArray(String[]::new);
            gateways = result.gateways.stream().toArray(String[]::new);
@@ -6629,24 +6661,7 @@ public class RIL extends BaseCommands implements CommandsInterface {
            // Process address
            if (addresses != null) {
                for (String address : addresses) {
                    address = address.trim();
                    if (address.isEmpty()) continue;

                    try {
                        LinkAddress la;
                        // Check if the address contains prefix length. If yes, LinkAddress
                        // can parse that.
                        if (address.split("/").length == 2) {
                            la = new LinkAddress(address);
                        } else {
                            InetAddress ia = InetAddresses.parseNumericAddress(address);
                            la = new LinkAddress(ia, (ia instanceof Inet4Address) ? 32 : 128);
                        }

                        laList.add(la);
                    } catch (IllegalArgumentException e) {
                        Rlog.e(RILJ_LOG_TAG, "Unknown address: " + address, e);
                    }
                    laList.add(createLinkAddressFromString(address));
                }
            }
        }
+54 −0
Original line number Diff line number Diff line
@@ -1713,6 +1713,60 @@ public class RILTest extends TelephonyTest {
        result14.mtu = 1500;

        assertEquals(response, RIL.convertDataCallResult(result14));

        // Test V1.5 SetupDataCallResult
        android.hardware.radio.V1_5.SetupDataCallResult result15 =
                new android.hardware.radio.V1_5.SetupDataCallResult();
        result15.cause = android.hardware.radio.V1_4.DataCallFailCause.NONE;
        result15.suggestedRetryTime = -1;
        result15.cid = 0;
        result15.active = android.hardware.radio.V1_4.DataConnActiveStatus.ACTIVE;
        result15.type = android.hardware.radio.V1_4.PdpProtocolType.IPV4V6;
        result15.ifname = "ifname";

        android.hardware.radio.V1_5.LinkAddress la1 = new android.hardware.radio.V1_5.LinkAddress();
        la1.address = "10.0.2.15";
        la1.properties = 0;
        la1.deprecationTime = -1;
        la1.expirationTime = -1;

        android.hardware.radio.V1_5.LinkAddress la2 = new android.hardware.radio.V1_5.LinkAddress();
        la2.address = "2607:fb90:a620:651d:eabe:f8da:c107:44be/64";
        la2.properties = 0;
        la2.deprecationTime = -1;
        la2.expirationTime = -1;
        result15.addresses = new ArrayList<>(Arrays.asList(la1, la2));
        result15.dnses = new ArrayList<>(Arrays.asList("10.0.2.3", "fd00:976a::9"));
        result15.gateways = new ArrayList<>(Arrays.asList("10.0.2.15", "fe80::2"));
        result15.pcscf = new ArrayList<>(Arrays.asList(
                "fd00:976a:c206:20::6", "fd00:976a:c206:20::9", "fd00:976a:c202:1d::9"));
        result15.mtuV4 = 1500;
        result15.mtuV6 = 3000;

        response = new DataCallResponse.Builder()
                .setCause(0)
                .setSuggestedRetryTime(-1)
                .setId(0)
                .setLinkStatus(2)
                .setProtocolType(ApnSetting.PROTOCOL_IPV4V6)
                .setInterfaceName("ifname")
                .setAddresses(Arrays.asList(
                        new LinkAddress(InetAddresses.parseNumericAddress("10.0.2.15"), 32),
                        new LinkAddress("2607:fb90:a620:651d:eabe:f8da:c107:44be/64")))
                .setDnsAddresses(Arrays.asList(InetAddresses.parseNumericAddress("10.0.2.3"),
                        InetAddresses.parseNumericAddress("fd00:976a::9")))
                .setGatewayAddresses(Arrays.asList(InetAddresses.parseNumericAddress("10.0.2.15"),
                        InetAddresses.parseNumericAddress("fe80::2")))
                .setPcscfAddresses(Arrays.asList(
                        InetAddresses.parseNumericAddress("fd00:976a:c206:20::6"),
                        InetAddresses.parseNumericAddress("fd00:976a:c206:20::9"),
                        InetAddresses.parseNumericAddress("fd00:976a:c202:1d::9")))
                .setMtuV4(1500)
                .setMtuV6(3000)
                .setVersion(5)
                .build();

        assertEquals(response, RIL.convertDataCallResult(result15));
    }

    @Test