prefer DNS servers from VPNs
This commit is contained in:
parent
35a4b848a5
commit
7623accfd5
|
@ -5,6 +5,7 @@ import android.content.Context;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.LinkProperties;
|
import android.net.LinkProperties;
|
||||||
import android.net.Network;
|
import android.net.Network;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
import android.net.RouteInfo;
|
import android.net.RouteInfo;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
|
@ -39,11 +40,17 @@ public class AndroidUsingLinkProperties extends AbstractDNSServerLookupMechanism
|
||||||
return new String[0];
|
return new String[0];
|
||||||
}
|
}
|
||||||
List<String> servers = new ArrayList<>();
|
List<String> servers = new ArrayList<>();
|
||||||
|
int vpnOffset = 0;
|
||||||
for(Network network : networks) {
|
for(Network network : networks) {
|
||||||
LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
|
LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
|
||||||
|
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
|
||||||
if (linkProperties != null) {
|
if (linkProperties != null) {
|
||||||
if (hasDefaultRoute(linkProperties)) {
|
if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_VPN) {
|
||||||
servers.addAll(0, getIPv4First(linkProperties.getDnsServers()));
|
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 {
|
} else {
|
||||||
servers.addAll(getIPv4First(linkProperties.getDnsServers()));
|
servers.addAll(getIPv4First(linkProperties.getDnsServers()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,9 +119,7 @@ public class Resolver {
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + "error resolving fallback records",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;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue