Commit 75964d2b authored by Romain Hunault's avatar Romain Hunault

[DNS] Global DNS switch

parent 3cba4ac2
/*
* Copyright (C) 2008 The Android Open Source Project
* Copyright (C) 2019 e.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -184,8 +185,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
implements PendingIntent.OnFinished {
private static final String TAG = ConnectivityService.class.getSimpleName();
private static final boolean DBG = true;
private static final boolean VDBG = false;
private static final boolean VDBG = true;
private static final boolean LOGD_RULES = false;
private static final boolean LOGD_BLOCKED_NETWORKINFO = true;
......@@ -4661,7 +4663,27 @@ public class ConnectivityService extends IConnectivityManager.Stub
return; // no updating necessary
}
Collection<InetAddress> dnses = newLp.getDnsServers();
Collection<InetAddress> dnses = null;//newLp.getDnsServers();
int useNwDNS = android.provider.Settings.System.getInt(mContext.getContentResolver(), "USE_NETWORK_DNS", 1);
if (DBG) log("useNwDNS>"+useNwDNS+"<");
if ( 0 != useNwDNS ) {
dnses = newLp.getDnsServers();
} else {
dnses = new ArrayList<InetAddress>();
try {
String s = android.provider.Settings.System.getString(mContext.getContentResolver(), "OVERRIDE_DNS_IP_V4");
if (s == null) s = "9.9.9.9";
if (DBG) log("Override dnses>"+s+"<");
InetAddress addr = InetAddress.getByName(s);
dnses.add(addr);
} catch (Exception e) {
loge("Cannot set custom DNS: " + e);
}
}
if (DBG) log("Setting DNS servers for network " + netId + " to " + dnses);
try {
mNetd.setDnsConfigurationForNetwork(
......@@ -4669,6 +4691,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
} catch (Exception e) {
loge("Exception in setDnsConfigurationForNetwork: " + e);
}
if (DBG) log("Setting DNS servers for network (2)" + netId + " to " + dnses);
final NetworkAgentInfo defaultNai = getDefaultNetwork();
if (defaultNai != null && defaultNai.network.netId == netId) {
setDefaultDnsSystemProperties(dnses);
......@@ -4908,7 +4931,28 @@ public class ConnectivityService extends IConnectivityManager.Stub
handleApplyDefaultProxy(newNetwork.linkProperties.getHttpProxy());
updateTcpBufferSizes(newNetwork);
updateTcpDelayedAck(newNetwork);
setDefaultDnsSystemProperties(newNetwork.linkProperties.getDnsServers());
Collection<InetAddress> dnses = null;
int useNwDNS = android.provider.Settings.System.getInt(mContext.getContentResolver(), "USE_NETWORK_DNS", 1);
if (DBG) log("useNwDNS>"+useNwDNS+"<");
if ( 0 != useNwDNS ) {
dnses = newNetwork.linkProperties.getDnsServers();
} else {
dnses = new ArrayList<InetAddress>();
try {
String s = android.provider.Settings.System.getString(mContext.getContentResolver(), "OVERRIDE_DNS_IP_V4");
if (s == null) s = "9.9.9.9";
if (DBG) log("Override dnses>"+s+"<");
InetAddress addr = InetAddress.getByName(s);
dnses.add(addr);
} catch (Exception e) {
loge("Cannot set custom DNS: " + e);
}
}
setDefaultDnsSystemProperties(dnses);
}
private void processListenRequests(NetworkAgentInfo nai, boolean capabilitiesChanged) {
......
/*
* Copyright (C) 2007 The Android Open Source Project
* Copyright (C) 2019 e.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -777,18 +778,33 @@ public class NetworkManagementService extends INetworkManagementService.Stub
* Notify our observers of DNS server information received.
*/
private void notifyInterfaceDnsServerInfo(String iface, long lifetime, String[] addresses) {
final int length = mObservers.beginBroadcast();
try {
for (int i = 0; i < length; i++) {
try {
mObservers.getBroadcastItem(i).interfaceDnsServerInfo(iface, lifetime,
addresses);
} catch (RemoteException | RuntimeException e) {
}
}
} finally {
mObservers.finishBroadcast();
}
int useNwDNS = android.provider.Settings.System.getInt(mContext.getContentResolver(), "USE_NETWORK_DNS", 1);
if ( 0 != useNwDNS ) {
final int length = mObservers.beginBroadcast();
try {
for (int i = 0; i < length; i++) {
try {
mObservers.getBroadcastItem(i).interfaceDnsServerInfo(iface, lifetime,
addresses);
} catch (RemoteException | RuntimeException e) {
}
}
} finally {
mObservers.finishBroadcast();
}
} else {
final String[] xaddresses = new String[1];
String s = android.provider.Settings.System.getString(mContext.getContentResolver(), "OVERRIDE_DNS_IP_V4");
xaddresses[0] = s;
try {
mObservers.getBroadcastItem(0).interfaceDnsServerInfo(iface, lifetime, xaddresses);
} catch (RemoteException | RuntimeException e) {}
finally {
mObservers.finishBroadcast();
}
}
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment