aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-01-26 22:46:00 +0100
committerDaniel Gultsch <daniel@gultsch.de>2016-01-26 22:46:00 +0100
commit5e6917c7d508c4e8f75989be520289ce42092854 (patch)
tree5bf2f6948add2725234d0f38fa4bdea5436884ee
parentd2c5a939ed2cf42374e0ddb528ee363b7fefee8c (diff)
prefer dns servers from networsk with the default routednsfixes
-rw-r--r--src/main/java/eu/siacs/conversations/utils/DNSHelper.java19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
index 87790d64..306d50c2 100644
--- a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
+++ b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
@@ -5,6 +5,7 @@ import android.content.Context;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
+import android.net.RouteInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
@@ -75,15 +76,29 @@ public class DNSHelper {
for(int i = 0; i < networks.length; ++i) {
LinkProperties linkProperties = connectivityManager.getLinkProperties(networks[i]);
if (linkProperties != null) {
- servers.addAll(linkProperties.getDnsServers());
+ if (hasDefaultRoute(linkProperties)) {
+ servers.addAll(0, linkProperties.getDnsServers());
+ } else {
+ servers.addAll(linkProperties.getDnsServers());
+ }
}
}
if (servers.size() > 0) {
- Log.d(Config.LOGTAG,"used lollipop variant to discover dns servers in "+networks.length+" networks");
+ Log.d(Config.LOGTAG, "used lollipop variant to discover dns servers in " + networks.length + " networks");
}
return servers.size() > 0 ? servers : getDnsServersPreLollipop();
}
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ private static boolean hasDefaultRoute(LinkProperties linkProperties) {
+ for(RouteInfo route: linkProperties.getRoutes()) {
+ if (route.isDefaultRoute()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private static List<InetAddress> getDnsServersPreLollipop() {
List<InetAddress> servers = new ArrayList<>();
String[] dns = client.findDNS();