File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
services/java/com/android/server Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff 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 ++;
You can’t perform that action at this time.
0 commit comments