Android 11.0修改原生ntp服务器 |
您所在的位置:网站首页 › 原生安卓11怎么样 › Android 11.0修改原生ntp服务器 |
基于高通平台、Android11.0源码,在项目开发中遇到开机启动后,联网无法自动同步时间问题,主要修改源码frameworks配置,代码修改位置主要有两处: 1、frameworks/base/core/java/android/util/NtpTrustedTime.java 2、frameworks/base/core/res/res/values/config.xm 一、目前Android 11源码中配的原生ntp服务器是time.android.com,访问成功率低或者直接请求失败,所以将config_ntpServer 改为国内ali的ntp1.aliyun.com(还有其他可选),请求时间间隔改短(value < 0 代表一直请求),retry次数增加。 --- a/frameworks/base/core/res/res/values/config.xml +++ b/frameworks/base/core/res/res/values/config.xml @@ -2040,14 +2040,14 @@ true - time.android.com + ntp1.aliyun.com 86400000 - 60000 + 30000 + "ntp2.aliyun.com", + "ntp3.aliyun.com", + "ntp4.aliyun.com", + "ntp5.aliyun.com", + "ntp6.aliyun.com", + }; + int index = -1; + @NonNull private final Context mContext; @@ -194,18 +203,27 @@ public class NtpTrustedTime implements TrustedTime { if (LOGD) Log.d(TAG, "forceRefresh() from cache miss"); final SntpClient client = new SntpClient(); + //String serverName = connectionInfo.getServer(); + boolean result = false; String serverName = connectionInfo.getServer(); final int timeoutMillis = connectionInfo.getTimeoutMillis(); - if (getBackupmode()) { - setBackupmode(false); - serverName = mBackupServer; - } + //if (getBackupmode()) { + // setBackupmode(false); + // serverName = mBackupServer; + //} if (LOGD) Log.d(TAG, "Ntp Server to access at:" + serverName); - if (client.requestTime(serverName, timeoutMillis, network)) { + //if (client.requestTime(serverName, timeoutMillis, network)) { + while (!(result = client.requestTime(serverName, timeoutMillis, network)) && index long ntpCertainty = client.getRoundTripTime() / 2; - mTimeResult = new TimeResult( - client.getNtpTime(), client.getNtpTimeReference(), ntpCertainty); + //mTimeResult = new TimeResult( + // client.getNtpTime(), client.getNtpTimeReference(), ntpCertainty); + mTimeResult = new TimeResult(client.getNtpTime(), client.getNtpTimeReference(), ntpCertainty); return true; } else { countInBackupmode();系统编译烧录后,时间可以更新成功。 |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |