Only use mDefaultDns if the network claims to offer Internet

Currently, if a network does not specify DNS servers, we default
it to using 8.8.8.8. This was done because the emulator did not
specify DNS servers. However, it causes queries to fail slowly,
instead of failing fast, on networks that do not have
connectivity to 8.8.8.8.

Bug: 18327075
Change-Id: I0df13ff4a17ee65e640be96695a3af31b020963a
This commit is contained in:
Lorenzo Colitti
2014-11-28 20:07:46 +09:00
parent 1d27e7d678
commit 20068c2d12

View File

@@ -3593,8 +3593,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
// updateMtu(lp, null); // updateMtu(lp, null);
// } // }
updateTcpBufferSizes(networkAgent); updateTcpBufferSizes(networkAgent);
// TODO: deprecate and remove mDefaultDns when we can do so safely.
// For now, use it only when the network has Internet access. http://b/18327075
final boolean useDefaultDns = networkAgent.networkCapabilities.hasCapability(
NetworkCapabilities.NET_CAPABILITY_INTERNET);
final boolean flushDns = updateRoutes(newLp, oldLp, netId); final boolean flushDns = updateRoutes(newLp, oldLp, netId);
updateDnses(newLp, oldLp, netId, flushDns); updateDnses(newLp, oldLp, netId, flushDns, useDefaultDns);
updateClat(newLp, oldLp, networkAgent); updateClat(newLp, oldLp, networkAgent);
if (isDefaultNetwork(networkAgent)) handleApplyDefaultProxy(newLp.getHttpProxy()); if (isDefaultNetwork(networkAgent)) handleApplyDefaultProxy(newLp.getHttpProxy());
// TODO - move this check to cover the whole function // TODO - move this check to cover the whole function
@@ -3688,10 +3694,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
return !routeDiff.added.isEmpty() || !routeDiff.removed.isEmpty(); return !routeDiff.added.isEmpty() || !routeDiff.removed.isEmpty();
} }
private void updateDnses(LinkProperties newLp, LinkProperties oldLp, int netId, boolean flush) { private void updateDnses(LinkProperties newLp, LinkProperties oldLp, int netId,
boolean flush, boolean useDefaultDns) {
if (oldLp == null || (newLp.isIdenticalDnses(oldLp) == false)) { if (oldLp == null || (newLp.isIdenticalDnses(oldLp) == false)) {
Collection<InetAddress> dnses = newLp.getDnsServers(); Collection<InetAddress> dnses = newLp.getDnsServers();
if (dnses.size() == 0 && mDefaultDns != null) { if (dnses.size() == 0 && mDefaultDns != null && useDefaultDns) {
dnses = new ArrayList(); dnses = new ArrayList();
dnses.add(mDefaultDns); dnses.add(mDefaultDns);
if (DBG) { if (DBG) {