diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-08-01 12:13:24 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-08-01 12:13:24 +0200 |
commit | b08e5e7a00487e706bf2c54716b30191cdfea388 (patch) | |
tree | 4d60d703dd529f34be0656f71596f6207dc427c3 /src/main/java/de | |
parent | a3d536b8d642e6259a56349ec644bf4ea55b6f64 (diff) |
prefer DNS servers from VPNs
Diffstat (limited to 'src/main/java/de')
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/AndroidUsingLinkProperties.java | 11 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/Resolver.java | 4 |
2 files changed, 10 insertions, 5 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/AndroidUsingLinkProperties.java b/src/main/java/de/pixart/messenger/utils/AndroidUsingLinkProperties.java index d844824cf..a740188b8 100644 --- a/src/main/java/de/pixart/messenger/utils/AndroidUsingLinkProperties.java +++ b/src/main/java/de/pixart/messenger/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<String> 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<String> 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/de/pixart/messenger/utils/Resolver.java b/src/main/java/de/pixart/messenger/utils/Resolver.java index 5a90cb30c..42324daed 100644 --- a/src/main/java/de/pixart/messenger/utils/Resolver.java +++ b/src/main/java/de/pixart/messenger/utils/Resolver.java @@ -118,9 +118,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; } |