@UnstableApi
class SntpClient


Static utility to retrieve the device time offset using SNTP.

Based on the Android framework SntpClient.

Summary

Nested types

Callback for calls to initialize.

Constants

const String!
DEFAULT_NTP_HOST = "time.android.com"

The default NTP host address used to retrieve getElapsedRealtimeOffsetMs.

const Int

The default maximum time, in milliseconds, to wait for the SNTP request to complete.

Public functions

java-static Unit

Starts loading the device time offset.

Public properties

java-static Long
@GuardedBy(value = "valueLock")
elapsedRealtimeOffsetMs

Returns the offset between elapsedRealtime and the NTP server time in milliseconds, or TIME_UNSET if isInitialized returns false.

java-static Boolean
@GuardedBy(value = "valueLock")
isInitialized

Returns whether the device time offset has already been loaded.

java-static Long
@GuardedBy(value = "valueLock")
maxElapsedTimeUntilUpdateMs

Returns the maximum time to elapse until the client is re-initialized, in milliseconds.

java-static String!
@GuardedBy(value = "valueLock")
ntpHost

Returns the NTP host address used to retrieve getElapsedRealtimeOffsetMs.

java-static Int
@GuardedBy(value = "valueLock")
timeoutMs

Returns the maximum time to wait for the SNTP request to complete, in milliseconds.

Constants

DEFAULT_NTP_HOST

const val DEFAULT_NTP_HOST = "time.android.com": String!

The default NTP host address used to retrieve getElapsedRealtimeOffsetMs.

DEFAULT_TIMEOUT_MS

const val DEFAULT_TIMEOUT_MS = 1000: Int

The default maximum time, in milliseconds, to wait for the SNTP request to complete.

Public functions

initialize

java-static fun initialize(loader: Loader?, callback: SntpClient.InitializationCallback?): Unit

Starts loading the device time offset.

Parameters
loader: Loader?

A Loader to use for loading the time offset, or null to create a new one.

callback: SntpClient.InitializationCallback?

An optional InitializationCallback to be notified when the time offset has been initialized or initialization failed.

Public properties

elapsedRealtimeOffsetMs

@GuardedBy(value = "valueLock")
java-static val elapsedRealtimeOffsetMs: Long

Returns the offset between elapsedRealtime and the NTP server time in milliseconds, or TIME_UNSET if isInitialized returns false.

The offset is calculated as ntpServerTime - deviceElapsedRealTime.

isInitialized

@GuardedBy(value = "valueLock")
java-static val isInitialized: Boolean

Returns whether the device time offset has already been loaded.

If false, use initialize to start the initialization.

maxElapsedTimeUntilUpdateMs

@GuardedBy(value = "valueLock")
java-static var maxElapsedTimeUntilUpdateMs: Long

Returns the maximum time to elapse until the client is re-initialized, in milliseconds.

ntpHost

@GuardedBy(value = "valueLock")
java-static var ntpHost: String!

Returns the NTP host address used to retrieve getElapsedRealtimeOffsetMs.

timeoutMs

@GuardedBy(value = "valueLock")
java-static var timeoutMs: Int

Returns the maximum time to wait for the SNTP request to complete, in milliseconds.