Merge "Document a section of code" am: 7c37904142 am: 5859be6c51

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2055047

Change-Id: I1a4345554c80510e0256e75dda13f69ae3f8ef16
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Neil Fuller
2022-04-05 16:10:48 +00:00
committed by Automerger Merge Worker

View File

@@ -193,6 +193,16 @@ public class NtpTrustedTime implements TrustedTime {
}
final Network network = connectivityManager.getActiveNetwork();
final NetworkInfo ni = connectivityManager.getNetworkInfo(network);
// This connectivity check is to avoid performing a DNS lookup for the time server on a
// unconnected network. There are races to obtain time in Android when connectivity
// changes, which means that forceRefresh() can be called by various components before
// the network is actually available. This led in the past to DNS lookup failures being
// cached (~2 seconds) thereby preventing the device successfully making an NTP request
// when connectivity had actually been established.
// A side effect of check is that tests that run a fake NTP server on the device itself
// will only be able to use it if the active network is connected, even though loopback
// addresses are actually reachable.
if (ni == null || !ni.isConnected()) {
if (LOGD) Log.d(TAG, "forceRefresh: no connectivity");
return false;