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

Commit 00ed9996 authored by Jack Yu's avatar Jack Yu
Browse files

Handled IPv4 without prefix length correctly

LinkAddress always takes address with prefix length. We should
add a prefix length to those IPv4 addresses. This is a regression
from aosp/586706. Also fixed the incorrect regex used to split the
addresses from the modem.

Test: Telephony sanity tests
bug: 72039489
Merged-In: I31fa1a343036370b28ce44fd895802804342dadd
Change-Id: I31fa1a343036370b28ce44fd895802804342dadd
(cherry picked from commit bf307ac1)
parent 0facf3c0
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ import java.io.DataInputStream;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
@@ -1186,7 +1187,7 @@ public class RIL extends BaseCommands implements CommandsInterface {
        // Process address
        String[] addresses = null;
        if (!TextUtils.isEmpty(dcResult.addresses)) {
            addresses = dcResult.addresses.split(" ");
            addresses = dcResult.addresses.split("\\s+");
        }

        List<LinkAddress> laList = new ArrayList<>();
@@ -1196,10 +1197,19 @@ public class RIL extends BaseCommands implements CommandsInterface {
                if (address.isEmpty()) continue;

                try {
                    LinkAddress la = new LinkAddress(address);
                    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 = NetworkUtils.numericToInetAddress(address);
                        la = new LinkAddress(ia, (ia instanceof Inet4Address) ? 32 : 128);
                    }

                    laList.add(la);
                } catch (IllegalArgumentException e) {
                    Rlog.e(RILJ_LOG_TAG, "Unknown address: " + address + ", exception = " + e);
                    Rlog.e(RILJ_LOG_TAG, "Unknown address: " + address + ", " + e);
                }
            }
        }
@@ -1207,7 +1217,7 @@ public class RIL extends BaseCommands implements CommandsInterface {
        // Process dns
        String[] dnses = null;
        if (!TextUtils.isEmpty(dcResult.dnses)) {
            dnses = dcResult.dnses.split(" ");
            dnses = dcResult.dnses.split("\\s+");
        }

        List<InetAddress> dnsList = new ArrayList<>();
@@ -1227,7 +1237,7 @@ public class RIL extends BaseCommands implements CommandsInterface {
        // Process gateway
        String[] gateways = null;
        if (!TextUtils.isEmpty(dcResult.gateways)) {
            gateways = dcResult.gateways.split(" ");
            gateways = dcResult.gateways.split("\\s+");
        }

        List<InetAddress> gatewayList = new ArrayList<>();
@@ -1253,7 +1263,7 @@ public class RIL extends BaseCommands implements CommandsInterface {
                laList,
                dnsList,
                gatewayList,
                new ArrayList<>(Arrays.asList(dcResult.pcscf.trim().split("\\s*,\\s*"))),
                new ArrayList<>(Arrays.asList(dcResult.pcscf.trim().split("\\s+"))),
                dcResult.mtu
        );
    }
+3 −9
Original line number Diff line number Diff line
@@ -67,7 +67,6 @@ import com.android.internal.util.StateMachine;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
@@ -1069,15 +1068,10 @@ public class DataConnection extends StateMachine {
                if (response.getAddresses().size() > 0) {
                    for (LinkAddress la : response.getAddresses()) {
                        if (!la.getAddress().isAnyLocalAddress()) {
                            int addrPrefixLen = la.getNetworkPrefixLength();
                            if (addrPrefixLen == 0) {
                                // Assume point to point
                                addrPrefixLen = (la.getAddress() instanceof Inet4Address)
                                        ? 32 : 128;
                                la = new LinkAddress(la.getAddress(), addrPrefixLen);
                            if (DBG) {
                                log("addr/pl=" + la.getAddress() + "/"
                                        + la.getNetworkPrefixLength());
                            }
                            if (DBG) log("addr/pl=" + la.getAddress() + "/" + addrPrefixLen);

                            linkProperties.addLinkAddress(la);
                        }
                    }
+65 −2
Original line number Diff line number Diff line
@@ -93,17 +93,20 @@ import static org.mockito.Mockito.verify;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.hardware.radio.V1_0.DataProfileInfo;
import android.hardware.radio.V1_0.CdmaSmsMessage;
import android.hardware.radio.V1_0.DataProfileInfo;
import android.hardware.radio.V1_0.GsmSmsMessage;
import android.hardware.radio.V1_0.ImsSmsMessage;
import android.hardware.radio.V1_0.IRadio;
import android.hardware.radio.V1_0.ImsSmsMessage;
import android.hardware.radio.V1_0.NvWriteItem;
import android.hardware.radio.V1_0.RadioError;
import android.hardware.radio.V1_0.RadioResponseInfo;
import android.hardware.radio.V1_0.RadioResponseType;
import android.hardware.radio.V1_0.SetupDataCallResult;
import android.hardware.radio.V1_0.SmsWriteArgs;
import android.net.ConnectivityManager;
import android.net.LinkAddress;
import android.net.NetworkUtils;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IPowerManager;
@@ -126,6 +129,7 @@ import android.telephony.CellSignalStrengthLte;
import android.telephony.CellSignalStrengthWcdma;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
import android.telephony.data.DataCallResponse;
import android.telephony.data.DataProfile;

import com.android.internal.telephony.RIL.RilHandler;
@@ -142,6 +146,7 @@ import org.mockito.MockitoAnnotations;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;

public class RILTest extends TelephonyTest {

@@ -1542,4 +1547,62 @@ public class RILTest extends TelephonyTest {

        return RIL.convertHalCellInfoList_1_2(records);
    }

    @Test
    public void testConvertDataCallResult() throws Exception {

        SetupDataCallResult result = new SetupDataCallResult();
        result.status = 0;
        result.suggestedRetryTime = -1;
        result.cid = 1;
        result.active = 1;
        result.type = "IP";
        result.ifname = "eth0";
        result.addresses = "10.0.2.15";
        result.dnses = "10.0.2.3";
        result.gateways = "10.0.2.15 fe80::2";
        result.pcscf = "";
        result.mtu = 1500;

        DataCallResponse response = new DataCallResponse(0, -1, 1, 1, "IP",
                "eth0",
                Arrays.asList(new LinkAddress(NetworkUtils.numericToInetAddress("10.0.2.15"), 32)),
                Arrays.asList(NetworkUtils.numericToInetAddress("10.0.2.3")),
                Arrays.asList(NetworkUtils.numericToInetAddress("10.0.2.15"),
                        NetworkUtils.numericToInetAddress("fe80::2")),
                Arrays.asList(""),
                1500);

        assertEquals(response, invokeMethod(mRILInstance, "convertDataCallResult",
                new Class<?>[] {SetupDataCallResult.class},
                new Object[] {result}));


        result.status = 0;
        result.suggestedRetryTime = -1;
        result.cid = 0;
        result.active = 2;
        result.type = "IPV4V6";
        result.ifname = "ifname";
        result.addresses = "2607:fb90:a620:651d:eabe:f8da:c107:44be/64";
        result.dnses = "fd00:976a::9      fd00:976a::10";
        result.gateways = "fe80::4c61:1832:7b28:d36c    1.2.3.4";
        result.pcscf = "fd00:976a:c206:20::6   fd00:976a:c206:20::9    fd00:976a:c202:1d::9";
        result.mtu = 1500;

        response = new DataCallResponse(0, -1, 0, 2, "IPV4V6",
                "ifname",
                Arrays.asList(new LinkAddress("2607:fb90:a620:651d:eabe:f8da:c107:44be/64")),
                Arrays.asList(NetworkUtils.numericToInetAddress("fd00:976a::9"),
                        NetworkUtils.numericToInetAddress("fd00:976a::10")),
                Arrays.asList(NetworkUtils.numericToInetAddress("fe80::4c61:1832:7b28:d36c"),
                        NetworkUtils.numericToInetAddress("1.2.3.4")),
                Arrays.asList("fd00:976a:c206:20::6", "fd00:976a:c206:20::9",
                        "fd00:976a:c202:1d::9"),
                1500);

        assertEquals(response, invokeMethod(mRILInstance, "convertDataCallResult",
                new Class<?>[] {SetupDataCallResult.class},
                new Object[] {result}));
    }
}