Resolver: active network gets high priority

This commit is contained in:
Daniel Gultsch 2017-10-28 13:12:11 +02:00
parent 4d0986ee91
commit aeec76d68b
1 changed files with 11 additions and 10 deletions

View File

@ -44,18 +44,19 @@ public class AndroidUsingLinkProperties extends AbstractDNSServerLookupMechanism
int vpnOffset = 0; int vpnOffset = 0;
for(Network network : networks) { for(Network network : networks) {
LinkProperties linkProperties = connectivityManager.getLinkProperties(network); LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
if (linkProperties == null) {
continue;
}
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network); NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
final boolean isActiveNetwork = network.equals(activeNetwork); final boolean isActiveNetwork = network.equals(activeNetwork);
if (linkProperties != null) { if (networkInfo != null && isActiveNetwork && networkInfo.getType() == ConnectivityManager.TYPE_VPN) {
if (networkInfo != null && isActiveNetwork && networkInfo.getType() == ConnectivityManager.TYPE_VPN) { final List<String> tmp = getIPv4First(linkProperties.getDnsServers());
final List<String> tmp = getIPv4First(linkProperties.getDnsServers()); servers.addAll(0, tmp);
servers.addAll(0, tmp); vpnOffset += tmp.size();
vpnOffset += tmp.size(); } else if (hasDefaultRoute(linkProperties) || isActiveNetwork) {
} else if (hasDefaultRoute(linkProperties)) { servers.addAll(vpnOffset, getIPv4First(linkProperties.getDnsServers()));
servers.addAll(vpnOffset, getIPv4First(linkProperties.getDnsServers())); } else {
} else { servers.addAll(getIPv4First(linkProperties.getDnsServers()));
servers.addAll(getIPv4First(linkProperties.getDnsServers()));
}
} }
} }
return servers.toArray(new String[servers.size()]); return servers.toArray(new String[servers.size()]);