Is Android using NTP to sync time?
Asked Answered
T

5

69

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

Tonicity answered 17/1, 2013 at 14:16 Comment(0)
M
57

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);
Meemeece answered 25/1, 2013 at 13:55 Comment(4)
Interestingly, it looks like they've hard-coded it to 2.android.pool.ntp.org. Line 820: android.googlesource.com/platform/frameworks/base/+/…Bedeck
Yes, but that is only for stock android. Some manufacturers change the server string.Meemeece
Notes: 1) If you want to change the ntp server, Android only looks at the config_ntpServer value on startup, so you'll need to reboot (or restart NetworkTimeUpdateService) to use the new value. 2) Since 2012, Android only checks the time every 10 days once booted. (There is a patch in gerrit to restore the original timeout of 1 day) 3) A trick to get Android to check the time is to toggle Settings.Global.AUTO_TIME off and then back on. This is equivalent to the check box in the Date & Time section of Settings.app. 4) Android doesn't use NTP, it polls very infrequently using SNTP.Neurocoele
So when you say: "1) If you want to change the ntp server, Android only looks at the config_ntpServer value on startup, so you'll need to reboot (or restart NetworkTimeUpdateService) to use the new value", exactly HOW should I be able to change the value?Bucharest
P
12

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.

Porscheporsena answered 17/1, 2013 at 14:22 Comment(0)
H
10

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.

Hurried answered 29/4, 2013 at 17:15 Comment(2)
Seems to be manual update only... Mine gains 1.5 minutes per 6 months.Fatigue
The Tab 2 has topped out with Android 4.2.2, and does not have the checkbox mentioned by @Neurocoele in his comment on the accepted answer. Mine drifts backward in time. I'll have to try GPS sync the next time I can't scrobble.Foehn
C
7

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.

Clubhaul answered 29/12, 2013 at 14:56 Comment(4)
Ok, the file is present on and complete on my Samsung Galaxy tab S. Do you know how I can enable the built-in NTP?Mehta
@Mehta I think some of the answers above will give you more better information than I could at this pointClubhaul
There is no gps.conf file inside the / folder. What could be the reason? My device is rooted.Georginegeorglana
@Georginegeorglana This question/answer is 6 years old, maybe Android has changed since then. Sorry but I'm not in a position to keep this answer up-to-date.Clubhaul
T
1

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.

Theotokos answered 6/11, 2021 at 14:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.