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

Commit 91ff91fb authored by Jack Yu's avatar Jack Yu Committed by android-build-merger
Browse files

Merge "Fixed empty dns not properly handled issue"

am: 100de66a

Change-Id: I23849c62b3d1ceb5d51205f1fd8f9c94a9f07ac1
parents 42f363a7 100de66a
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));
    }
}