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

Commit 100de66a authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Fixed empty dns not properly handled issue"

parents 822d1fd0 f894832e
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.net.NetworkAgent;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkMisc;
import android.net.NetworkUtils;
import android.net.ProxyInfo;
import android.net.RouteInfo;
import android.net.StringNetworkSpecifier;
@@ -1078,6 +1079,20 @@ public class DataConnection extends StateMachine {
                            linkProperties.addDnsServer(dns);
                        }
                    }
                } else if (okToUseSystemPropertyDns) {
                    for (String dnsAddr : dnsServers) {
                        dnsAddr = dnsAddr.trim();
                        if (dnsAddr.isEmpty()) continue;
                        InetAddress ia;
                        try {
                            ia = NetworkUtils.numericToInetAddress(dnsAddr);
                        } catch (IllegalArgumentException e) {
                            throw new UnknownHostException("Non-numeric dns addr=" + dnsAddr);
                        }
                        if (!ia.isAnyLocalAddress()) {
                            linkProperties.addDnsServer(ia);
                        }
                    }
                } else {
                    throw new UnknownHostException("Empty dns response and no system default dns");
                }
@@ -1095,7 +1110,6 @@ public class DataConnection extends StateMachine {
                result = SetupResult.SUCCESS;
            } catch (UnknownHostException e) {
                log("setLinkProperties: UnknownHostException " + e);
                e.printStackTrace();
                result = SetupResult.ERR_UnacceptableParameter;
            }
        } else {
+17 −0
Original line number Diff line number Diff line
@@ -427,4 +427,21 @@ public class DataConnectionTest extends TelephonyTest {
        assertEquals(SetupResult.ERR_UnacceptableParameter,
                setLinkProperties(response, linkProperties));
    }

    @Test
    @SmallTest
    public void testSetLinkPropertiesEmptyDns() throws Exception {

        // Empty dns entry.
        DataCallResponse response = new DataCallResponse(0, -1, 1, 2, "IP", FAKE_IFNAME,
                Arrays.asList(new InterfaceAddress(FAKE_ADDRESS, 0)),
                null,
                Arrays.asList(NetworkUtils.numericToInetAddress(FAKE_GATEWAY)),
                Arrays.asList(FAKE_PCSCF_ADDRESS),
                1440);

        // Make sure no exception was thrown
        LinkProperties linkProperties = new LinkProperties();
        assertEquals(SetupResult.SUCCESS, setLinkProperties(response, linkProperties));
    }
}