2018年2月8日星期四

Android 8.0 自定义ntp服务器

Android 8.0开始默认的ntp服务器变为 time.android.com,导致了一部分用户由于众所周知的原因无法同步网络时间,解决办法是将其修改为可以访问的服务器。

修改方法:

adb shell "settings put global ntp_server time.asia.apple.com"
AOSP相关代码:

    public static synchronized NtpTrustedTime getInstance(Context context) {

        if (sSingleton == null) {

            final Resources res = context.getResources();

            final ContentResolver resolver = context.getContentResolver();

 

            final String defaultServer = res.getString(

                    com.android.internal.R.string.config_ntpServer);

            final long defaultTimeout = res.getInteger(

                    com.android.internal.R.integer.config_ntpTimeout);

 

            final String secureServer = Settings.Global.getString(

                    resolver, Settings.Global.NTP_SERVER);

            final long timeout = Settings.Global.getLong(

                    resolver, Settings.Global.NTP_TIMEOUT, defaultTimeout);

 

            final String server = secureServer != null ? secureServer : defaultServer;

            sSingleton = new NtpTrustedTime(server, timeout);

            sContext = context;

        }

 

        return sSingleton;

    }

参考:

https://android.googlesource.com/platform/frameworks/base/+/oreo-release/core/res/res/values/config.xml#1719

https://android.googlesource.com/platform/frameworks/base/+/oreo-release/core/java/android/util/NtpTrustedTime.java#58

没有评论:

发表评论