Merge "Flush DNS cache when routes change." into lmp-dev
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index cb8d688..f8d8db5 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -4236,8 +4236,8 @@
// for (LinkProperties lp : newLp.getStackedLinks()) {
// updateMtu(lp, null);
// }
- updateRoutes(newLp, oldLp, netId);
- updateDnses(newLp, oldLp, netId);
+ final boolean flushDns = updateRoutes(newLp, oldLp, netId);
+ updateDnses(newLp, oldLp, netId, flushDns);
updateClat(newLp, oldLp, networkAgent);
}
@@ -4285,7 +4285,11 @@
}
}
- private void updateRoutes(LinkProperties newLp, LinkProperties oldLp, int netId) {
+ /**
+ * Have netd update routes from oldLp to newLp.
+ * @return true if routes changed between oldLp and newLp
+ */
+ private boolean updateRoutes(LinkProperties newLp, LinkProperties oldLp, int netId) {
CompareResult<RouteInfo> routeDiff = new CompareResult<RouteInfo>();
if (oldLp != null) {
routeDiff = oldLp.compareAllRoutes(newLp);
@@ -4320,8 +4324,9 @@
loge("Exception in removeRoute: " + e);
}
}
+ return !routeDiff.added.isEmpty() || !routeDiff.removed.isEmpty();
}
- private void updateDnses(LinkProperties newLp, LinkProperties oldLp, int netId) {
+ private void updateDnses(LinkProperties newLp, LinkProperties oldLp, int netId, boolean flush) {
if (oldLp == null || (newLp.isIdenticalDnses(oldLp) == false)) {
Collection<InetAddress> dnses = newLp.getDnsServers();
if (dnses.size() == 0 && mDefaultDns != null) {
@@ -4342,6 +4347,13 @@
setDefaultDnsSystemProperties(dnses);
}
flushVmDnsCache();
+ } else if (flush) {
+ try {
+ mNetd.flushNetworkDnsCache(netId);
+ } catch (Exception e) {
+ loge("Exception in flushNetworkDnsCache: " + e);
+ }
+ flushVmDnsCache();
}
}