From 7623accfd59ceec8043062c1e7e60081c4443770 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 12 Jul 2017 22:19:45 +0200 Subject: [PATCH] prefer DNS servers from VPNs --- .../utils/AndroidUsingLinkProperties.java | 11 +++++++++-- .../java/eu/siacs/conversations/utils/Resolver.java | 4 +--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/utils/AndroidUsingLinkProperties.java b/src/main/java/eu/siacs/conversations/utils/AndroidUsingLinkProperties.java index 4e137a7ed..36fec0a47 100644 --- a/src/main/java/eu/siacs/conversations/utils/AndroidUsingLinkProperties.java +++ b/src/main/java/eu/siacs/conversations/utils/AndroidUsingLinkProperties.java @@ -5,6 +5,7 @@ import android.content.Context; import android.net.ConnectivityManager; import android.net.LinkProperties; import android.net.Network; +import android.net.NetworkInfo; import android.net.RouteInfo; import android.os.Build; @@ -39,11 +40,17 @@ public class AndroidUsingLinkProperties extends AbstractDNSServerLookupMechanism return new String[0]; } List servers = new ArrayList<>(); + int vpnOffset = 0; for(Network network : networks) { LinkProperties linkProperties = connectivityManager.getLinkProperties(network); + NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network); if (linkProperties != null) { - if (hasDefaultRoute(linkProperties)) { - servers.addAll(0, getIPv4First(linkProperties.getDnsServers())); + if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_VPN) { + final List tmp = getIPv4First(linkProperties.getDnsServers()); + servers.addAll(0, tmp); + vpnOffset += tmp.size(); + } else if (hasDefaultRoute(linkProperties)) { + servers.addAll(vpnOffset, getIPv4First(linkProperties.getDnsServers())); } else { servers.addAll(getIPv4First(linkProperties.getDnsServers())); } diff --git a/src/main/java/eu/siacs/conversations/utils/Resolver.java b/src/main/java/eu/siacs/conversations/utils/Resolver.java index c8c20e7e5..5adfba50e 100644 --- a/src/main/java/eu/siacs/conversations/utils/Resolver.java +++ b/src/main/java/eu/siacs/conversations/utils/Resolver.java @@ -119,9 +119,7 @@ public class Resolver { } catch (Throwable throwable) { Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + "error resolving fallback records",throwable); } - if (results.size() == 0) { - results.add(Result.createDefault(dnsName)); - } + results.add(Result.createDefault(dnsName)); return results; }