一、设备到ntp服务器的网络是否正常
130|test:/ # ping 2.android.pool.ntp.org
PING 2.android.pool.ntp.org (202.112.29.82) 56(84) bytes of data.
64 bytes from dns1.synet.edu.cn (202.112.29.82): icmp_seq=1 ttl=47 time=94.5 ms
出现如上日志说明是可以ping通的,可以正常访问网络 二、域名和IP查询网址
https://site.ip138.com/2.android.pool.ntp.org/
域名查询 IP查询 总结: 1、如果该卡不能ping通域名,换一张卡可以ping通,则说明是该卡运营商那边有问题,运营商那边是否有做限制 2、从上面可以ping通域名的设备看,每次ping域名的时候,IP是随机分配的 解决方法: 代码路径: frameworks/base/core/res/res/values/config.xml frameworks/base/core/java/android/util/NtpTrustedTime.java frameworks/base/services/core/java/com/android/server/NetworkTimeUpdateService.java NetworkTimeUpdateService.java文件是网络更新时间处理,在config.xml资源文件中可以对其它参数可以配置,比如重连次数,超时时间的、域名
<!-- Remote server that can provide NTP responses. -->
<string translatable="false" name="config_ntpServer">2.android.pool.ntp.org</string>
<!-- Normal polling frequency in milliseconds -->
<integer name="config_ntpPollingInterval">86400000</integer>
<!-- Try-again polling interval in milliseconds, in case the network request failed -->
<integer name="config_ntpPollingIntervalShorter">60000</integer>
<!-- Number of times to try again with the shorter interval, before backing
off until the normal polling interval. A value < 0 indicates infinite. -->
<integer name="config_ntpRetry">3</integer>
<!-- If the time difference is greater than this threshold in milliseconds,
then update the time. -->
<integer name="config_ntpThreshold">5000</integer>
<!-- Timeout to wait for NTP server response in milliseconds. -->
<integer name="config_ntpTimeout">5000</integer>
<!-- Default network policy warning threshold, in megabytes. -->
<integer name="config_networkPolicyDefaultWarning">2048</integer>
在NtpTrustedTime.java文件中forceRefresh()方法中可以动态添加NTP服务器域名
@Override
public boolean forceRefresh() {
if (TextUtils.isEmpty(mServer)) {
// missing server, so no trusted time available
return false;
}
// We can't do this at initialization time: ConnectivityService might not be running yet.
synchronized (this) {
if (mCM == null) {
mCM = (ConnectivityManager) sContext.getSystemService(Context.CONNECTIVITY_SERVICE);
}
}
final NetworkInfo ni = mCM == null ? null : mCM.getActiveNetworkInfo();
if (ni == null || !ni.isConnected()) {
if (LOGD) Log.d(TAG, "forceRefresh: no connectivity");
return false;
}
if (LOGD) Log.d(TAG, "forceRefresh() from cache miss");
final SntpClient client = new SntpClient();
if (client.requestTime(mServer, (int) mTimeout)) {
mHasCache = true;
mCachedNtpTime = client.getNtpTime();
mCachedNtpElapsedRealtime = client.getNtpTimeReference();
mCachedNtpCertainty = client.getRoundTripTime() / 2;
return true;
} else {
return false;
}
}
|