Is Android using NTP to sync time?

AndroidTimeGpsNtp

Android Problem Overview


Do Android Devices use the network time protocol (NTP) to synchronize the time?

In my Device-Settings I see a checkbox with the following text "synchronize with network", but I don't know if they are using NTP.

I need this for my Bachelor Thesis for which I use GPS. To get an accurate GPS-signal the receiver should have an exact clock.

I have found this blog-entry on the web, but I'm not sure if he tells the truth: Speeding up NTP, GPS Lock in Android

Android Solutions


Solution 1 - Android

I know about Android ICS that it uses a custom service called: NetworkTimeUpdateService. This service also implements a NTP time synchronization via the NtpTrustedTime singleton.

In NtpTrustedTime the default NTP server is requested from the Android system string source:

final Resources res = context.getResources();

final String defaultServer = res.getString(
                                com.android.internal.R.string.config_ntpServer);

If the automatic time sync option in the system settings is checked and no NITZ time service is available then the time will be synchronized with the NTP server from com.android.internal.R.string.config_ntpServer.

To get the value of com.android.internal.R.string.config_ntpServer you can use the following method:

    final Resources res = this.getResources();
    final int id = Resources.getSystem().getIdentifier(
                       "config_ntpServer", "string","android");
    final String defaultServer = res.getString(id);

Solution 2 - Android

> i wanted to ask if Android Devices uses the network time protocol (ntp) to synchronize the time.

For general time synchronization, devices with telephony capability, where the wireless provider provides NITZ information, will use NITZ. My understanding is that NTP is used in other circumstances: NITZ-free wireless providers, WiFi-only, etc.

Your cited blog post suggests another circumstance: on-demand time synchronization in support of GPS. That is certainly conceivable, though I do not know whether it is used or not.

Solution 3 - Android

I have a Samsung Galaxy Tab 2 7.0 with Android 4.1.1. Apparently it does NOT sync to ntp. I loaded an app that says my tablet is 20 seconds off of ntp, but it can't set it unless I root the device.

Solution 4 - Android

Not an exact answer to your question, but a bit of information: if your device does use NTP for time (eg. if it is a tablet with no 3G or GPS capabilities), the server can be configured in /system/etc/gps.conf - obviously this file can only be edited with root access, but is viewable on non-rooted devices.

Solution 5 - Android

you can override ntp with a global variable NTP_SERVER, the property ro.NTP_SERVER, or by creating a file named ntp.conf under /etc as explained in:
https://developers.google.com/time/guides#linux_ntpd_or_chrony

the Linux instructions works well with Android.

you can always redirect the traffic from your device through proxy into a burp packet listener running on another computer on the same network to easily inspect all tratfic. SIM in your device will sync up regardless of NTP settings, and your router by default may also act as a NTP server for the network.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioniTampView Question on Stackoverflow
Solution 1 - AndroidDyonisosView Answer on Stackoverflow
Solution 2 - AndroidCommonsWareView Answer on Stackoverflow
Solution 3 - AndroidMishkaView Answer on Stackoverflow
Solution 4 - AndroidtoryanView Answer on Stackoverflow
Solution 5 - AndroidmmmmmburgermmmmView Answer on Stackoverflow