summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChiachang Wang <chiachangwang@google.com>2019-10-24 00:48:27 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-10-24 00:48:27 -0700
commit0ec9d5bb84e8394ca2c2ead47646aa2d431a87af (patch)
tree1dfb10b345581fca32b443b43f5c12dac98e29f1
parent3a0cd647c7d03465c36aa330468bc6dd91e4dd59 (diff)
parented5f519883cd4257881ca8f46961e8d4189feed8 (diff)
Keep only one CMD_EVALUATE_PRIVATE_DNS in the queue
am: ed5f519883 Change-Id: I91aaddb89b5439269af121c8c8d51e496abbaf0a
-rw-r--r--src/com/android/server/connectivity/NetworkMonitor.java11
-rw-r--r--tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java12
2 files changed, 11 insertions, 12 deletions
diff --git a/src/com/android/server/connectivity/NetworkMonitor.java b/src/com/android/server/connectivity/NetworkMonitor.java
index 7cabb1e..e08170a 100644
--- a/src/com/android/server/connectivity/NetworkMonitor.java
+++ b/src/com/android/server/connectivity/NetworkMonitor.java
@@ -681,6 +681,8 @@ public class NetworkMonitor extends StateMachine {
// no resolved IP addresses, IPs unreachable,
// port 853 unreachable, port 853 is not running a
// DNS-over-TLS server, et cetera).
+ // Cancel any outstanding CMD_EVALUATE_PRIVATE_DNS.
+ removeMessages(CMD_EVALUATE_PRIVATE_DNS);
sendMessage(CMD_EVALUATE_PRIVATE_DNS);
break;
}
@@ -1042,6 +1044,11 @@ public class NetworkMonitor extends StateMachine {
// All good!
transitionTo(mValidatedState);
break;
+ case CMD_PRIVATE_DNS_SETTINGS_CHANGED:
+ // When settings change the reevaluation timer must be reset.
+ mPrivateDnsReevalDelayMs = INITIAL_REEVALUATE_DELAY_MS;
+ // Let the message bubble up and be handled by parent states as usual.
+ return NOT_HANDLED;
default:
return NOT_HANDLED;
}
@@ -1094,10 +1101,6 @@ public class NetworkMonitor extends StateMachine {
// transitioning back to EvaluatingState, to perhaps give ourselves
// the opportunity to (re)detect a captive portal or something.
//
- // TODO: distinguish between CMD_EVALUATE_PRIVATE_DNS messages that are caused by server
- // lookup failures (which should continue to do exponential backoff) and
- // CMD_EVALUATE_PRIVATE_DNS messages that are caused by user reconfiguration (which
- // should be processed immediately.
sendMessageDelayed(CMD_EVALUATE_PRIVATE_DNS, mPrivateDnsReevalDelayMs);
mPrivateDnsReevalDelayMs *= 2;
if (mPrivateDnsReevalDelayMs > MAX_REEVALUATE_DELAY_MS) {
diff --git a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
index 6eeadf5..49a2ce3 100644
--- a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
+++ b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
@@ -868,10 +868,8 @@ public class NetworkMonitorTest {
WrappedNetworkMonitor wnm = makeNotMeteredNetworkMonitor();
wnm.notifyPrivateDnsSettingsChanged(new PrivateDnsConfig("dns.google", new InetAddress[0]));
wnm.notifyNetworkConnected(TEST_LINK_PROPERTIES, NOT_METERED_CAPABILITIES);
- verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).atLeastOnce())
- .notifyNetworkTested(
- eq(NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS),
- eq(null));
+ verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS)).notifyNetworkTested(
+ eq(NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS), eq(null));
verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1)).notifyProbeStatusChanged(
eq(VALIDATION_RESULT_PRIVDNS_VALID), eq(NETWORK_VALIDATION_PROBE_DNS
| NETWORK_VALIDATION_PROBE_HTTPS));
@@ -907,10 +905,8 @@ public class NetworkMonitorTest {
mFakeDns.setNonBypassPrivateDnsWorking(false);
wnm.notifyPrivateDnsSettingsChanged(new PrivateDnsConfig("dns.google",
new InetAddress[0]));
- verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).atLeastOnce())
- .notifyNetworkTested(
- eq(NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS),
- eq(null));
+ verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS)).notifyNetworkTested(
+ eq(NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS), eq(null));
// NetworkMonitor will check if the probes has changed or not, if the probes has not
// changed, the callback won't be fired.
verify(mCallbacks, never()).notifyProbeStatusChanged(