diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-10-29 20:02:14 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-10-29 20:02:14 +0100 |
commit | 44552010ed6bfb45d2adf2ba2b1d22bb3a9c1802 (patch) | |
tree | eb974dec83a5433c8574d915505e783c5f0e1623 /src/main/java/de/pixart | |
parent | e7592e5898c1da9e44d7af5a3e5ea0afb86bb018 (diff) |
Resolver: Only prefer VPN connections when network is active
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/AndroidUsingLinkProperties.java | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/AndroidUsingLinkProperties.java b/src/main/java/de/pixart/messenger/utils/AndroidUsingLinkProperties.java index a740188b8..64c144a1f 100644 --- a/src/main/java/de/pixart/messenger/utils/AndroidUsingLinkProperties.java +++ b/src/main/java/de/pixart/messenger/utils/AndroidUsingLinkProperties.java @@ -39,13 +39,15 @@ public class AndroidUsingLinkProperties extends AbstractDNSServerLookupMechanism if (networks == null) { return new String[0]; } + final Network activeNetwork = getActiveNetwork(connectivityManager); List<String> servers = new ArrayList<>(); int vpnOffset = 0; for (Network network : networks) { LinkProperties linkProperties = connectivityManager.getLinkProperties(network); NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network); + final boolean isActiveNetwork = network.equals(activeNetwork); if (linkProperties != null) { - if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_VPN) { + if (networkInfo != null && isActiveNetwork && networkInfo.getType() == ConnectivityManager.TYPE_VPN) { final List<String> tmp = getIPv4First(linkProperties.getDnsServers()); servers.addAll(0, tmp); vpnOffset += tmp.size(); @@ -59,6 +61,11 @@ public class AndroidUsingLinkProperties extends AbstractDNSServerLookupMechanism return servers.toArray(new String[servers.size()]); } + @TargetApi(23) + private static Network getActiveNetwork(ConnectivityManager cm) { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? cm.getActiveNetwork() : null; + } + private static List<String> getIPv4First(List<InetAddress> in) { List<String> out = new ArrayList<>(); for (InetAddress addr : in) { |