Starting March 27, 2025, we recommend using android-latest-release instead of aosp-main to build and contribute to AOSP. For more information, see Changes to AOSP.

Time source priority

The Android framework uses various time sources for time synchronization. This page focuses on the Network Time Protocol (NTP) and Network Identity and Time Zone (NITZ) automatic time sources. By default in Android 12 or higher, the framework prioritizes NTP as the time source over NITZ because NTP is more accurate and reliable than NITZ. In situations where NTP isn't available, the framework falls back on NITZ. This is a reversal of the default priority from earlier versions of the platform. By default in Android 11 and lower, the framework prioritizes NITZ over NTP.

For more details on this change, see the following AOSP patches: 1563678, 1513323.

Configure time source priority

To configure which time source takes priority by default for a specific Android version, configure the config_autoTimeSourcesPriority key in frameworks/base/core/res/res/values/config.xml at build time. Time suggestions from the time source that is higher in the list takes precedence over sources that are lower in the list.

Android time sources that can be configured are found in TimeDetectorStrategy.java. The following sources are configured for use by default:

  • Telephony (NITZ)
  • Network (NTP)

Testing

To verify that the device uses NITZ when NTP isn't available (when mobile data and Wi-Fi are disabled), do the following:

  1. Ensure there's a working SIM in the DUT
  2. Turn off mobile data and Wi-Fi
  3. Put the device into airplane mode to make sure the cell radio is turned off
  4. Turn off automatic time detection
  5. Set the clock manually to an incorrect time value in the future
  6. Reboot the device
  7. Turn on automatic time detection
  8. Take the device out of airplane mode

These steps trigger a change to the system clock as soon as a NITZ signal is received. To check how the device time is set, run the following command:

adbshelldumpsystime_detector

To verify that the system clock uses NITZ, confirm the following in the command output:

  • mEnvironment.isAutoTimeDetectionEnabled() is true.
  • mEnvironment.autoOriginPriorities() contains a list of time sources with sources higher on the list taking precedence over sources lower on the list.
  • The Time change log section shows that the system clock is set using a telephony suggestion.
  • The Telephony suggestion history section contains time suggestions.
  • The Network suggestion history section is empty.

The time suggestions in the Telephony suggestion history and Network suggestion history sections are considered the source of truth for time. If the device is connected to the internet and has a SIM card, suggestions are generated using both NTP (network) and NITZ (telephony). In this test case, only the Telephony suggestion history section contains suggestions because NTP is disabled.

The Time change log section records the changes made to the device's system clock and the suggestion used. The system clock is set based on the order of the time sources in the priority list in the config_autoTimeSourcesPriority key. However, suggestions from a higher priority source might be ignored if the suggestion is too old or invalid. Also, if the highest priority valid suggestion matches the device's current system clock time to within a couple of seconds the time won't be changed. In this test case, as long as the suggestions aren't outdated, the system clock is set using one of the suggestions from the Telephony suggestion history.

The following is an example of an output where the device falls back on using NITZ when NTP is unavailable.

TimeDetectorStrategy:
mLastAutoSystemClockTimeSet=TimestampedValue{mReferenceTimeMillis=66240,mValue=1614186761000}
mEnvironment.isAutoTimeDetectionEnabled()=true
mEnvironment.elapsedRealtimeMillis()=73059
mEnvironment.systemClockMillis()=1614186767818
mEnvironment.systemClockUpdateThresholdMillis()=2000
mEnvironment.autoTimeLowerBound()=2021年02月24日T15:44:15Z(1614181455000)
mEnvironment.autoOriginPriorities()=[network,telephony]
Timechangelog:
66261/2021年02月24日T17:12:41.020Z-Setsystemclockusingtime=TimestampedValue{mReferenceTimeMillis=66240,mValue=1614186761000}cause=Foundgoodtelephonysuggestion.,bestTelephonySuggestion=TelephonyTimeSuggestion{mSlotIndex='0',mUtcTime=TimestampedValue{mReferenceTimeMillis=66240,mValue=1614186761000},mDebugInfo=[SendingnewtimesuggestionnitzSignal=TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}},reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}})]},detectionReason=Newtelephonytimesuggested.timeSuggestion=TelephonyTimeSuggestion{mSlotIndex='0',mUtcTime=TimestampedValue{mReferenceTimeMillis=66240,mValue=1614186761000},mDebugInfo=[SendingnewtimesuggestionnitzSignal=TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}},reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}})]}elapsedRealtimeMillis=66259newSystemClockMillis=1614186761019
Telephonysuggestionhistory:
keyidx:0=0
validx:0=TelephonyTimeSuggestion{mSlotIndex='0',mUtcTime=TimestampedValue{mReferenceTimeMillis=66240,mValue=1614186761000},mDebugInfo=[SendingnewtimesuggestionnitzSignal=TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}},reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}})]}
Historicvalues=[
0@PT1M6.258S:TelephonyTimeSuggestion{mSlotIndex='0',mUtcTime=TimestampedValue{mReferenceTimeMillis=66240,mValue=1614186761000},mDebugInfo=[SendingnewtimesuggestionnitzSignal=TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}},reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}})]}
]
Networksuggestionhistory:
{Empty}
Gnsssuggestionhistory:
{Empty}
Externalsuggestionhistory:
{Empty}

For reference as a comparison to the output in the testing scenario, the following is an example of a typical output where the device receives time suggestions from both NTP and NITZ time sources.

TimeDetectorStrategy:
mLastAutoSystemClockTimeSet=TimestampedValue{mReferenceTimeMillis=66240,mValue=1614186761000}
mEnvironment.isAutoTimeDetectionEnabled()=true
mEnvironment.elapsedRealtimeMillis()=302926
mEnvironment.systemClockMillis()=1614186997685
mEnvironment.systemClockUpdateThresholdMillis()=2000
mEnvironment.autoTimeLowerBound()=2021年02月24日T15:44:15Z(1614181455000)
mEnvironment.autoOriginPriorities()=[network,telephony]
Timechangelog:
66261/2021年02月24日T17:12:41.020Z-Setsystemclockusingtime=TimestampedValue{mReferenceTimeMillis=66240,mValue=1614186761000}cause=Foundgoodtelephonysuggestion.,bestTelephonySuggestion=TelephonyTimeSuggestion{mSlotIndex='0',mUtcTime=TimestampedValue{mReferenceTimeMillis=66240,mValue=1614186761000},mDebugInfo=[SendingnewtimesuggestionnitzSignal=TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}},reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}})]},detectionReason=Newtelephonytimesuggested.timeSuggestion=TelephonyTimeSuggestion{mSlotIndex='0',mUtcTime=TimestampedValue{mReferenceTimeMillis=66240,mValue=1614186761000},mDebugInfo=[SendingnewtimesuggestionnitzSignal=TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}},reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}})]}elapsedRealtimeMillis=66259newSystemClockMillis=1614186761019
Telephonysuggestionhistory:
keyidx:0=0
validx:0=TelephonyTimeSuggestion{mSlotIndex='0',mUtcTime=TimestampedValue{mReferenceTimeMillis=66240,mValue=1614186761000},mDebugInfo=[SendingnewtimesuggestionnitzSignal=TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}},reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}})]}
Historicvalues=[
0@PT1M6.258S:TelephonyTimeSuggestion{mSlotIndex='0',mUtcTime=TimestampedValue{mReferenceTimeMillis=66240,mValue=1614186761000},mDebugInfo=[SendingnewtimesuggestionnitzSignal=TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}},reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240,mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00,mZoneOffset=0,mDstOffset=0,mCurrentTimeMillis=1614186761000,mEmulatorHostTimeZone=null}})]}
]
Networksuggestionhistory:
0@PT4M4.04S:NetworkTimeSuggestion{mUtcTime=TimestampedValue{mReferenceTimeMillis=244038,mValue=1614186939242},mDebugInfo=[Origin:NetworkTimeUpdateService.event=3]}
Gnsssuggestionhistory:
{Empty}
Externalsuggestionhistory:
{Empty}

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2025年12月02日 UTC.