Android 修改ntp网络校时服务器

SystemService启动后创建NetworkTimeUpdateService网络校时服务,构造方法加载配置文件,默认配置文件位置在/frameworks/base/core/res/res/values/config.xml,定制部分放在/vendor方案商的定制目录。

XML 复制代码
    <!-- Remote server that can provide NTP responses. -->
    <string translatable="false" name="config_ntpServer">time.android.com</string>
    <!-- Normal polling frequency in milliseconds -->
    <integer name="config_ntpPollingInterval">64800000</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>
    <!-- Timeout to wait for NTP server response in milliseconds. -->
    <integer name="config_ntpTimeout">5000</integer>

config_ntpServer:默认NTP服务器,方案商定制可能换成2.android.pool.ntp.org

config_ntpPollingInterval:开机后的轮询间隔时间

NetworkTimeUpdateService在网络连接后,轮训校时。

打开frameworks/base/core/java/android/util/NtpTrustedTime.java,找到getNtpConnectionInfo方法:

java 复制代码
    private NtpConnectionInfo getNtpConnectionInfo() {
        .......................................
        final String hostname;
        if (mHostnameForTests != null) {
            hostname = mHostnameForTests;
        } else {
            String serverGlobalSetting =
                    Settings.Global.getString(resolver, Settings.Global.NTP_SERVER);
            if (serverGlobalSetting != null) {
                hostname = serverGlobalSetting;
            } else {
                hostname = res.getString(com.android.internal.R.string.config_ntpServer);
            }
        }
        ........................................
        return TextUtils.isEmpty(hostname) ? null :
            new NtpConnectionInfo(hostname, port, timeoutMillis);
    }

Settings.Global中NTP_SERVER的值:

public static final String NTP_SERVER = "ntp_server";

按照方法逻辑,当Settings.Global.NTP_SERVER的值为空时,系统取默认的ntp服务器。

修改ntp网络校时服务器就有两种选择:

1、不修改系统:

adb shell settings put global ntp_server xxx.xxx.xxx.xxx

xxx.xxx.xxx.xxx为服务器IP

adb shell settings get global ntp_server,查看修改后的值

2、修改系统

修改config_ntpServer的值

相关推荐
问心无愧05132 小时前
[GXYCTF2019]Ping Ping Ping
android·笔记
事圆则缓2 小时前
Kotlin 异步与并发:从一次搜索请求走到状态流
android·开发语言·kotlin
帅得不敢出门3 小时前
Android Framework定制卸载确认窗口
android
Android-Flutter4 小时前
Compose 什么叫重组?怎么样触发重组?
android·compose
硫酸锌014 小时前
安卓手机连接Windows电脑后通过DHCP服务为手机分配IP地址
android·windows·计算机网络
骑着蜗牛撵大象3274 小时前
设备监控数据存与查:Spring Boot 接入 TimescaleDB 超表的完整落地
android·spring boot·后端·springboot·时序数据库·es·设备监控
云贝贝贝5 小时前
MySQL 线上报 Lock wait timeout 别慌:6 招定位锁等待与死锁
android
mmsx5 小时前
Android 签名校验为什么能拦住二次打包:指纹与完整性校验
android·签名
jason.zeng@15022076 小时前
使用vscode+flutter开发android程序(入门)
android·vscode·flutter
事圆则缓6 小时前
Kotlin学习导航:从知识树走到项目与面试
android·开发语言·kotlin