From 686e7c02e0f14ac76f45bf66614ad1d978eb94a5 Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Tue, 27 Nov 2018 18:00:05 +0800 Subject: [PATCH] Data stall detection using DNS event If dns resolver on a network get consecutively timeout then it is a strong signal that the network is no longer usable. Reevaluate the network once it's data stall suspected Test: 1. runtest frameworks-net 2. SettingsBackupTest passes 2. Run on wifi w/o internet capability Bug: 112653893, 113916551 Change-Id: I74287b174d933f97a91fa1529b1809856ac3b38d --- .../android/server/ConnectivityService.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 74c80237d7..9dcade9445 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -1659,6 +1659,24 @@ public class ConnectivityService extends IConnectivityManager.Stub loge("Error parsing ip address in validation event"); } } + + @Override + public void onDnsEvent(int netId, int eventType, int returnCode, String hostname, + String[] ipAddresses, int ipAddressesCount, long timestamp, int uid) { + NetworkAgentInfo nai = getNetworkAgentInfoForNetId(netId); + // Netd event only allow registrants from system. Each NetworkMonitor thread is under + // the caller thread of registerNetworkAgent. Thus, it's not allowed to register netd + // event callback for certain nai. e.g. cellular. Register here to pass to + // NetworkMonitor instead. + // TODO: Move the Dns Event to NetworkMonitor. Use Binder.clearCallingIdentity() in + // registerNetworkAgent to have NetworkMonitor created with system process as design + // expectation. Also, NetdEventListenerService only allow one callback from each + // caller type. Need to re-factor NetdEventListenerService to allow multiple + // NetworkMonitor registrants. + if (nai != null && nai.satisfies(mDefaultRequest)) { + nai.networkMonitor.sendMessage(NetworkMonitor.EVENT_DNS_NOTIFICATION, returnCode); + } + } }; @VisibleForTesting