Loading services/core/java/com/android/server/location/gnss/NtpTimeHelper.java +25 −18 Original line number Diff line number Diff line Loading @@ -73,7 +73,6 @@ class NtpTimeHelper { private final WakeLock mWakeLock; private final Handler mHandler; @GuardedBy("this") private final InjectNtpTimeCallback mCallback; // flags to trigger NTP when network becomes available Loading Loading @@ -129,6 +128,8 @@ class NtpTimeHelper { return; } if (!isNetworkConnected()) { // try to inject the cached NTP time injectCachedNtpTime(); // try again when network is up mInjectNtpTimeState = STATE_PENDING_NETWORK; return; Loading Loading @@ -157,23 +158,7 @@ class NtpTimeHelper { // only update when NTP time is fresh // If refreshSuccess is false, cacheAge does not drop down. ntpResult = mNtpTime.getCachedTimeResult(); if (ntpResult != null && ntpResult.getAgeMillis() < NTP_INTERVAL) { long time = ntpResult.getTimeMillis(); long timeReference = ntpResult.getElapsedRealtimeMillis(); long certainty = ntpResult.getCertaintyMillis(); if (DEBUG) { long now = System.currentTimeMillis(); Log.d(TAG, "NTP server returned: " + time + " (" + new Date(time) + ")" + " ntpResult: " + ntpResult + " system time offset: " + (time - now)); } // Ok to cast to int, as can't rollover in practice mHandler.post(() -> mCallback.injectTime(time, timeReference, (int) certainty)); if (injectCachedNtpTime()) { delay = NTP_INTERVAL; mNtpBackOff.reset(); } else { Loading Loading @@ -201,4 +186,26 @@ class NtpTimeHelper { // release wake lock held by task mWakeLock.release(); } /** Returns true if successfully inject cached NTP time. */ private synchronized boolean injectCachedNtpTime() { NtpTrustedTime.TimeResult ntpResult = mNtpTime.getCachedTimeResult(); if (ntpResult == null || ntpResult.getAgeMillis() >= NTP_INTERVAL) { return false; } long time = ntpResult.getTimeMillis(); long timeReference = ntpResult.getElapsedRealtimeMillis(); long certainty = ntpResult.getCertaintyMillis(); if (DEBUG) { long now = System.currentTimeMillis(); Log.d(TAG, "NTP server returned: " + time + " (" + new Date(time) + ")" + " ntpResult: " + ntpResult + " system time offset: " + (time - now)); } // Ok to cast to int, as can't rollover in practice mHandler.post(() -> mCallback.injectTime(time, timeReference, (int) certainty)); return true; } } Loading
services/core/java/com/android/server/location/gnss/NtpTimeHelper.java +25 −18 Original line number Diff line number Diff line Loading @@ -73,7 +73,6 @@ class NtpTimeHelper { private final WakeLock mWakeLock; private final Handler mHandler; @GuardedBy("this") private final InjectNtpTimeCallback mCallback; // flags to trigger NTP when network becomes available Loading Loading @@ -129,6 +128,8 @@ class NtpTimeHelper { return; } if (!isNetworkConnected()) { // try to inject the cached NTP time injectCachedNtpTime(); // try again when network is up mInjectNtpTimeState = STATE_PENDING_NETWORK; return; Loading Loading @@ -157,23 +158,7 @@ class NtpTimeHelper { // only update when NTP time is fresh // If refreshSuccess is false, cacheAge does not drop down. ntpResult = mNtpTime.getCachedTimeResult(); if (ntpResult != null && ntpResult.getAgeMillis() < NTP_INTERVAL) { long time = ntpResult.getTimeMillis(); long timeReference = ntpResult.getElapsedRealtimeMillis(); long certainty = ntpResult.getCertaintyMillis(); if (DEBUG) { long now = System.currentTimeMillis(); Log.d(TAG, "NTP server returned: " + time + " (" + new Date(time) + ")" + " ntpResult: " + ntpResult + " system time offset: " + (time - now)); } // Ok to cast to int, as can't rollover in practice mHandler.post(() -> mCallback.injectTime(time, timeReference, (int) certainty)); if (injectCachedNtpTime()) { delay = NTP_INTERVAL; mNtpBackOff.reset(); } else { Loading Loading @@ -201,4 +186,26 @@ class NtpTimeHelper { // release wake lock held by task mWakeLock.release(); } /** Returns true if successfully inject cached NTP time. */ private synchronized boolean injectCachedNtpTime() { NtpTrustedTime.TimeResult ntpResult = mNtpTime.getCachedTimeResult(); if (ntpResult == null || ntpResult.getAgeMillis() >= NTP_INTERVAL) { return false; } long time = ntpResult.getTimeMillis(); long timeReference = ntpResult.getElapsedRealtimeMillis(); long certainty = ntpResult.getCertaintyMillis(); if (DEBUG) { long now = System.currentTimeMillis(); Log.d(TAG, "NTP server returned: " + time + " (" + new Date(time) + ")" + " ntpResult: " + ntpResult + " system time offset: " + (time - now)); } // Ok to cast to int, as can't rollover in practice mHandler.post(() -> mCallback.injectTime(time, timeReference, (int) certainty)); return true; } }