Android devices automatically attempt to obtain the correct Unix epoch time from a network source. Android uses the SNTP protocol, which uses the UDP protocol, to obtain time information.
The components described on this page are part of the automatic time detection
system referred to as the network time origin. A time signal from
a network time server can be used to set the Android device's system clock when
automatic time detection is supported on the device and the
service is configured to use it.
By default, Android uses the network time origin as the primary automatic time detection origin.
Network time detection system
network_time_update_service service that runs in the Android system server
implements the network time detection system. The service periodically uses
SNTP to obtain a time signal from a server. The service also monitors network
connectivity and triggers a time refresh when no recent time signal is available
after extended periods of poor connectivity.
network_time_update_service service attempts to obtain a time signal
after boot and when network connectivity is first established. The
service then tries to keep the latest signal it holds fresh. It balances the
needs of individual Android devices with the substantial load that could be
generated by many Android devices worldwide refreshing their time.
Using internal APIs,
network_time_update_service submits network time
suggestions to the
time_detector service. Other Android platform
components then use these network time suggestions.
After receiving suggestions from the network time origin, the
service determines whether to update the system clock according to the
configured prioritization rules.
To configure the automatic time detection system to use the network origin
suggestions to set the system clock automatically, use the
core/res/res/values/config.xml system server configuration file. Ensure the
network is contained in
config_autoTimeSourcesPriority in the desired
position. For details, see
Time Source Priority.
This section describes how device manufacturers can configure the network time detection system.
The base AOSP configuration is at
|Configuration key||AOSP value||Description|
||After failing to refresh, this is the number of times the system tries
network time polling with a shorter NTP polling interval
||The normal network time polling interval in milliseconds.|
||The retry network time polling interval in milliseconds. Used when a time refresh fails.|
||A single entry:
||NTP servers to use to obtain an accurate time. Items must be in the form:
This isn't a registered IANA URI scheme.
||5000||Time to wait for an NTP server response in milliseconds before timeout.|
Multiple server support
For Android 14 and higher, the framework supports
multiple NTP servers. This supports situations where devices are
distributed globally with a single configuration, but where access to servers
time.android.com is restricted in certain places.
The algorithm tries each server specified in the
configuration key. When it finds one that responds, the system continues using
that server until it fails to refresh or the device reboots.
Android's default network time sync uses SNTP with a single time query approximately once a day to try to ensure it always has a recent time signal.
Network latency effects are the biggest contributor to time inaccuracy with Android's SNTP implementation. SNTP assumes symmetric network delays, that is, the network latency for the request is the same as the network latency for the response, and the correct time lies exactly in the middle of that network round trip. Often, network round trip time is in the order of a few hundred milliseconds and on a wired network the latency is close to symmetric, leading to levels of inaccuracy that are near imperceptible to users. However, with mobile or radio telephony there are several stages where relatively long, asymmetric delays can be inserted into a network transaction leading to greater inaccuracy.
With the AOSP default setting for
config_ntpTimeout set to
and if all network latency is solely concentrated on the inbound or outbound
leg, the maximum theoretical error is approximately 2.5 seconds.
Overall system clock accuracy is also affected by the Android device's ability
to track elapsed time accurately after a time signal is obtained. This is a
concern with all timekeeping on Android, not just network time detection, and is
time_detector service disregards old time suggestions. The
network_time_update_service service refreshes regularly using the
config_ntpPollingInterval interval to keep the
supplied with fresh time suggestions and to ensure that the
service doesn't fall back to lower-priority and often lower-accuracy or
occasionally incorrect time origins such as
When automatic time detection is used, device system clock accuracy can be
affected by other configurations of the
time_detector service, such as the
constants and flags that affect how different a time suggestion has to be from
the current system clock time before the clock is adjusted
Device manufacturers can modify accuracy using the preceding configuration options and constants. But it's important to be aware of the limitations of the platform's SNTP implementation, and the potential impact on power consumption from more frequent network operations, impact to apps running on the device from more frequent but smaller clock adjustments, and the effect on server load.
Other uses of network time
If automatic time detection using the
network origin isn't configured or if
the user has disabled automatic time detection, the time obtained by the
network_time_update_service service is still used by the following components:
- Internal platform functions. For example, A-GPS can locate a GNSS (location) first fix faster when it has network time information.
Debugging and testing
The following section describes shell commands for debugging and testing the network time detection feature.
Interact with the network_time_update_service service
To dump the current state of
adb shell cmd network_time_update_service dump
To see a set of command line options that can assist with testing, use:
adb shell cmd network_time_update_service help