diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-05-12 21:39:47 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-05-12 21:39:47 +0200 |
commit | cbdb4136136726d572b8bc521fc910f4dc31f00f (patch) | |
tree | ad28fa1a332b9f081c8ffe5c042d3be5721c90f7 /src/main/java/eu | |
parent | f4369b29ae0d4d3ad562ce6695af6aca8f7416ea (diff) |
prefer IPv4 DNS servers
some devices might have problems contacting the IPv6 DNS server while in sleep mode
Diffstat (limited to 'src/main/java/eu')
-rw-r--r-- | src/main/java/eu/siacs/conversations/utils/DNSHelper.java | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java index 306d50c2..b96d3c25 100644 --- a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java @@ -12,6 +12,7 @@ import android.os.Parcelable; import android.util.Log; import java.io.IOException; +import java.net.Inet4Address; import java.net.InetAddress; import java.net.SocketTimeoutException; import java.net.UnknownHostException; @@ -77,9 +78,9 @@ public class DNSHelper { LinkProperties linkProperties = connectivityManager.getLinkProperties(networks[i]); if (linkProperties != null) { if (hasDefaultRoute(linkProperties)) { - servers.addAll(0, linkProperties.getDnsServers()); + servers.addAll(0, getIPv4First(linkProperties.getDnsServers())); } else { - servers.addAll(linkProperties.getDnsServers()); + servers.addAll(getIPv4First(linkProperties.getDnsServers())); } } } @@ -89,6 +90,18 @@ public class DNSHelper { return servers.size() > 0 ? servers : getDnsServersPreLollipop(); } + private static List<InetAddress> getIPv4First(List<InetAddress> in) { + List<InetAddress> out = new ArrayList<>(); + for(InetAddress addr : in) { + if (addr instanceof Inet4Address) { + out.add(0, addr); + } else { + out.add(addr); + } + } + return out; + } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) private static boolean hasDefaultRoute(LinkProperties linkProperties) { for(RouteInfo route: linkProperties.getRoutes()) { @@ -155,7 +168,7 @@ public class DNSHelper { public static Bundle queryDNS(String host, InetAddress dnsServer) { Bundle bundle = new Bundle(); try { - client.setTimeout(Config.PING_TIMEOUT * 1000); + client.setTimeout(Config.SOCKET_TIMEOUT * 1000); final String qname = "_xmpp-client._tcp." + host; final String tlsQname = "_xmpps-client._tcp." + host; Log.d(Config.LOGTAG, "using dns server: " + dnsServer.getHostAddress() + " to look up " + host); |