如何解决更新android NTP配置,要求从NTP服务器时间起约1秒内的时钟精度
在一个对时间敏感的应用程序上工作,该应用程序需要时间精确,即关闭时间不到1秒。 设备通过wifi连接到互联网,并且我将NTP轮询频率设置为30分钟。
设备每30分钟从NTP服务器成功获取一次准确的时间,但不会更新本地系统时间。
根据android code NetworkTimeUpdateService仅在时间漂移大于5000ms时才同步本地系统时间。如果少于5000毫秒,它将忽略并记录“ Ntp时间足够接近”。
// If the clock is more than N seconds off or this is the first time it's been
// fetched since boot,set the current time.
if (Math.abs(ntp - currentTime) > mTimeErrorThresholdMs
|| mLastNtpFetchTime == NOT_SET) {
// Set the system time
if (DBG && mLastNtpFetchTime == NOT_SET
&& Math.abs(ntp - currentTime) <= mTimeErrorThresholdMs) {
Log.d(TAG,"For initial setup,rtc = " + currentTime);
}
if (DBG) Log.d(TAG,"Ntp time to be set = " + ntp);
// Make sure we don't overflow,since it's going to be converted to an int
if (ntp / 1000 < Integer.MAX_VALUE) {
SystemClock.setCurrentTimeMillis(ntp);
}
} else {
if (DBG) Log.d(TAG,"Ntp time is close enough = " + ntp);
}
这是android中的默认NTP配置settings。此处config_ntpThreshold设置为5000ms。
<!-- If the time difference is greater than this threshold in milliseconds,then update the time. -->
<integer name="config_ntpThreshold">5000</integer>
我想将阈值更改为小于1秒。如何通过配置更改或其他解决方法更改它?
任何线索或建议将不胜感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。