tags | ||
---|---|---|
|
Just use this command to set a server address to automatically sync your device time. ( ͡° ͜ʖ ͡°)✧
$ adb shell settings put global ntp_server <new-ntp-server>
I have a Raspberry Pi 3 with Android Things installed on it. But the time is never synchronized...
After googling it, I found this piece of code in NtpTrustedTime.java
public class NtpTrustedTime implements TrustedTime {
...
public static synchronized NtpTrustedTime getInstance(Context context) {
if (sSingleton == null) {
final Resources res = context.getResources();
final ContentResolver resolver = context.getContentResolver();
final String defaultServer = res.getString(
com.android.internal.R.string.config_ntpServer);
final long defaultTimeout = res.getInteger(
com.android.internal.R.integer.config_ntpTimeout);
final String secureServer = Settings.Global.getString(
resolver, Settings.Global.NTP_SERVER);
final long timeout = Settings.Global.getLong(
resolver, Settings.Global.NTP_TIMEOUT, defaultTimeout);
final String server = secureServer != null ? secureServer : defaultServer;
sSingleton = new NtpTrustedTime(server, timeout);
sContext = context;
}
return sSingleton;
}
}
It shows that android tring to get NTP server from:
-
Settings.Global.NTP_SERVER first
-
Then com.android.internal.R.string.config_ntpServer
And the NTP server of my Android Things is time.android.com
, that's why it dose not work (I'm in China...).
Fortunately, it is easy to set settings via adb:
$ adb shell settings put global ntp_server asia.pool.ntp.org
# test
$ adb shell settings get global ntp_server
> asia.pool.ntp.org
🎉 CHEERS
adb shell settings get global --- instructs on getting that specific config only and it is the expected behavior
to see how ntp actually connects using the current configurations, you would need to see the sync in action
There are actually more ntp servers used on android. System uses time.android.com (defined normally by the global settings vars .. not 100% sure) while gps uses whatever is defined on gps.conf. For example i created magisk module to force gps to use pool.ntp.org or time.xtracloud.net.
Some things you can do:
running android 11. i think the behavior is different from phone to phone.