RK3568 Android 11 增加NTP列表

上补丁:

commit 737086059c493b7ccda914f80763468ec65524dd (HEAD -> master, origin/master, origin/HEAD)
Author: rockemd <rockemd2020@163.com>
Date:   Thu Oct 27 16:29:35 2022 +0800

    add NtpServers
    QQ Group:790137629
    


diff --git a/frameworks/base/core/java/android/util/NtpTrustedTime.java b/frameworks/base/core/java/android/util/NtpTrustedTime.java
old mode 100644
new mode 100755
index 0892c94d5b..bb8f894cb3
--- a/frameworks/base/core/java/android/util/NtpTrustedTime.java
+++ b/frameworks/base/core/java/android/util/NtpTrustedTime.java
@@ -98,6 +98,27 @@ public class NtpTrustedTime implements TrustedTime {
 
     private static NtpTrustedTime sSingleton;
 
+       String[] backupNtpServers = new String[]{
+               "time.nist.gov",
+               "time-a.nist.gov",
+               "ntp1.aliyun.com",
+               "ntp2.aliyun.com",
+               "ntp3.aliyun.com",
+               "ntp-sz.chl.la",
+               "3.cn.pool.ntp.org",
+               "asia.pool.ntp.org",
+               "cn.pool.ntp.org",
+               "sg.pool.ntp.org",
+               "jp.pool.ntp.org",
+               "hk.pool.ntp.org",
+               "s2g.time.edu.cn",
+               "oceania.pool.ntp.org",
+               "south-america.pool.ntp.org",
+               "north-america.pool.ntp.org",
+               "tw.pool.ntp.org",
+       };
+       int index = -1;
+
     @NonNull
     private final Context mContext;
 
@@ -162,12 +183,18 @@ public class NtpTrustedTime implements TrustedTime {
 
             if (LOGD) Log.d(TAG, "forceRefresh() from cache miss");
             final SntpClient client = new SntpClient();
-            final String serverName = connectionInfo.getServer();
+            boolean result = false;
+            String serverName = connectionInfo.getServer();
+            if (LOGD) Log.d(TAG, "----------rockemd-add-20221027-serverName--1------"+serverName);
             final int timeoutMillis = connectionInfo.getTimeoutMillis();
-            if (client.requestTime(serverName, timeoutMillis, network)) {
+            while (!(result = client.requestTime(serverName, timeoutMillis, network)) && index < (backupNtpServers.length-1) ) {
+                index++;
+                serverName = backupNtpServers[index];
+                if (LOGD) Log.d(TAG, "----------rockemd-add-20221027-serverName--------"+serverName);
+            }
+            if(result){
                 long ntpCertainty = client.getRoundTripTime() / 2;
-                mTimeResult = new TimeResult(
-                        client.getNtpTime(), client.getNtpTimeReference(), ntpCertainty);
+                mTimeResult = new TimeResult(client.getNtpTime(), client.getNtpTimeReference(), ntpCertainty);
                 return true;
             } else {
                 return false;

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值