aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-08-31 14:57:23 +0200
committerChristian Schneppe <christian@pix-art.de>2019-08-31 14:57:23 +0200
commit4210498d3cee8922a2bec699e74f342e2dcfc648 (patch)
treee79cdd61d2242f61a0f32d171d55a87f60992c6a /src
parent58b464cf268e156fa4295a8a5c58dddc0a467394 (diff)
do not include DNS servers from networks know to be inactive
* we still include DNS servers from VPNs because of edge cases where the XMPP server is hosted in the VPN * on older Android versions we don’t know if a network is active or not (activeNetwork == null)
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/pixart/messenger/utils/AndroidUsingLinkProperties.java35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/AndroidUsingLinkProperties.java b/src/main/java/de/pixart/messenger/utils/AndroidUsingLinkProperties.java
index 1c0fca8bb..f2f33dc1b 100644
--- a/src/main/java/de/pixart/messenger/utils/AndroidUsingLinkProperties.java
+++ b/src/main/java/de/pixart/messenger/utils/AndroidUsingLinkProperties.java
@@ -21,7 +21,7 @@ public class AndroidUsingLinkProperties extends AbstractDNSServerLookupMechanism
private final Context context;
- protected AndroidUsingLinkProperties(Context context) {
+ AndroidUsingLinkProperties(Context context) {
super(AndroidUsingLinkProperties.class.getSimpleName(), AndroidUsingExec.PRIORITY - 1);
this.context = context;
}
@@ -34,32 +34,31 @@ public class AndroidUsingLinkProperties extends AbstractDNSServerLookupMechanism
@Override
@TargetApi(21)
public String[] getDnsServerAddresses() {
- ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- Network[] networks = connectivityManager == null ? null : connectivityManager.getAllNetworks();
+ final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ final Network[] networks = connectivityManager == null ? null : connectivityManager.getAllNetworks();
if (networks == null) {
return new String[0];
}
final Network activeNetwork = getActiveNetwork(connectivityManager);
- List<String> servers = new ArrayList<>();
+ final List<String> servers = new ArrayList<>();
int vpnOffset = 0;
for (Network network : networks) {
LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
if (linkProperties == null) {
continue;
}
- NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
+ final NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
final boolean isActiveNetwork = network.equals(activeNetwork);
- if (isActiveNetwork) {
- if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_VPN) {
- final List<String> tmp = getIPv4First(linkProperties.getDnsServers());
- servers.addAll(0, tmp);
- vpnOffset += tmp.size();
- } else {
- servers.addAll(vpnOffset, getIPv4First(linkProperties.getDnsServers()));
- }
+ final boolean isVpn = networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_VPN;
+ if (isActiveNetwork && isVpn) {
+ final List<String> tmp = getIPv4First(linkProperties.getDnsServers());
+ servers.addAll(0, tmp);
+ vpnOffset += tmp.size();
+ } else if (hasDefaultRoute(linkProperties) || isActiveNetwork || activeNetwork == null || isVpn) {
+ servers.addAll(vpnOffset, getIPv4First(linkProperties.getDnsServers()));
}
}
- return servers.toArray(new String[servers.size()]);
+ return servers.toArray(new String[0]);
}
@TargetApi(23)
@@ -69,11 +68,11 @@ public class AndroidUsingLinkProperties extends AbstractDNSServerLookupMechanism
private static List<String> getIPv4First(List<InetAddress> in) {
List<String> out = new ArrayList<>();
- for (InetAddress addr : in) {
- if (addr instanceof Inet4Address) {
- out.add(0, addr.getHostAddress());
+ for (InetAddress address : in) {
+ if (address instanceof Inet4Address) {
+ out.add(0, address.getHostAddress());
} else {
- out.add(addr.getHostAddress());
+ out.add(address.getHostAddress());
}
}
return out;