Skip to content

Commit c793d62

Browse files
Amith YamasaniAndroid (Google) Code Review
authored andcommitted
Merge "On first boot and NTP lookup, set the time even if it's not off by 5+ secs." into jb-dev
2 parents eaca069 + 708d5d4 commit c793d62

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

services/java/com/android/server/NetworkTimeUpdateService.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,15 @@ private void onPollNetworkTime(int event) {
165165
if (mTime.getCacheAge() < POLLING_INTERVAL_MS) {
166166
final long ntp = mTime.currentTimeMillis();
167167
mTryAgainCounter = 0;
168-
mLastNtpFetchTime = SystemClock.elapsedRealtime();
169-
if (Math.abs(ntp - currentTime) > TIME_ERROR_THRESHOLD_MS) {
168+
// If the clock is more than N seconds off or this is the first time it's been
169+
// fetched since boot, set the current time.
170+
if (Math.abs(ntp - currentTime) > TIME_ERROR_THRESHOLD_MS
171+
|| mLastNtpFetchTime == NOT_SET) {
170172
// Set the system time
173+
if (DBG && mLastNtpFetchTime == NOT_SET
174+
&& Math.abs(ntp - currentTime) <= TIME_ERROR_THRESHOLD_MS) {
175+
Log.d(TAG, "For initial setup, rtc = " + currentTime);
176+
}
171177
if (DBG) Log.d(TAG, "Ntp time to be set = " + ntp);
172178
// Make sure we don't overflow, since it's going to be converted to an int
173179
if (ntp / 1000 < Integer.MAX_VALUE) {
@@ -176,6 +182,7 @@ private void onPollNetworkTime(int event) {
176182
} else {
177183
if (DBG) Log.d(TAG, "Ntp time is close enough = " + ntp);
178184
}
185+
mLastNtpFetchTime = SystemClock.elapsedRealtime();
179186
} else {
180187
// Try again shortly
181188
mTryAgainCounter++;

0 commit comments

Comments
 (0)