1、系统网络同步慢
一般同步慢都是因为默认服务器未修改,将NTP默认服务器修改成ping较好的即可。
frameworks\base\core\res\res\values\config.xml
<!-- Remote server that can provide NTP responses. --> <string translatable="false" name="config_ntpServer">cn.pool.ntp.org</string> <!-- Normal polling frequency in milliseconds --> <integer name="config_ntpPollingInterval">86400000</integer> <!-- Try-again polling interval in milliseconds, in case the network request failed --> <integer name="config_ntpPollingIntervalShorter">1000</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">5</integer> <!-- If the time difference is greater than this threshold in milliseconds, then update the time. --> <integer name="config_ntpThreshold">5000</integer> <!-- Timeout to wait for NTP server response in milliseconds. --> <integer name="config_ntpTimeout">5000</integer> <!-- Default network policy warning threshold, in megabytes. --> <integer name="config_networkPolicyDefaultWarning">2048</integer>config_ntpServer 是默认的ntp服务器,平台默认是 time.android.com 内地无法访问,修改成 cn.pool.ntp.org
config_ntpPollingIntervalShorter 是更新时间的频率,可以适当调整一些
2、动态加载系统的默认时间,相关修改有两处
frameworks/base/services/java/com/android/server/SystemServer.java
//private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000; private static final long EARLIEST_SUPPORTED_TIME = 86400; private void run() { try { traceBeginAndSlog("InitBeforeStartServices"); // If a device's clock is before 1970 (before 0), a lot of // APIs crash dealing with negative numbers, notably // java.io.File#setLastModified, so instead we fake it and // hope that time from cell towers or NTP fixes it shortly. /*if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) { Slog.w(TAG, "System clock is before 1970; setting to 1970."); SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);*/ final long BUILD_TIME = SystemProperties.getLong("ro.build.date.utc", EARLIEST_SUPPORTED_TIME) * 1000; if (System.currentTimeMillis() < BUILD_TIME) { Slog.w(TAG, "System clock is before BUILD_TIME; setting to BUILD_TIME."); SystemClock.setCurrentTimeMillis(BUILD_TIME); } ... ... }如上直接在run方法中添加时无效的, 因为时间太早了。SystemClock.setCurrentTimeMillis(BUILD_TIME);这个动作需要在AlarmManagerService启动之后设置才可以。可以将这个动作往后移动一些。
另外也可以直接修改AlarmManagerService,在onStart()中修改 setKernelTime
//frameworks/base/services/core/java/com/android/server/AlarmManagerService.java @Override public void onStart() { mNativeData = init(); mNextWakeup = mNextNonWakeup = 0; // We have to set current TimeZone info to kernel // because kernel doesn't keep this after reboot setTimeZoneImpl(SystemProperties.get(TIMEZONE_PROPERTY)); /// M:add for PPL feature ,@{ initPpl(); ///@} /// M: For handling non-wakeup alarms while WFD is connected registerWFDStatusChangeReciever(); ///@} /// M: added for BG powerSaving feature @{ initAlarmGrouping(); ///@} // Also sure that we're booting with a halfway sensible current time if (mNativeData != 0) { //if (System.currentTimeMillis() < systemBuildTime) { // 获取build time final long BUILD_TIME = SystemProperties.getLong("ro.build.date.utc", systemBuildTime) * 1000; if (System.currentTimeMillis() < BUILD_TIME) { Slog.i(TAG, "Current time only " + System.currentTimeMillis() // + ", advancing to build time " + systemBuildTime); + ", advancing to build time " + BUILD_TIME); //setKernelTime(mNativeData, systemBuildTime); // 修改默认时间为build time setKernelTime(mNativeData, BUILD_TIME); } } ... ... )
