External Time Detection

From Android 12, Android can optionally use an external source of time to suggest UTC times to the time_detector service. This isn't enabled by default in AOSP.

The external time origin allows device manufacturers to provide completely custom time suggestions to Android. After receiving suggestions from the external time origin, the time_detector service determines whether to update the system clock using the configured prioritization rules.

Implementation

To support external time detection, device manufacturers must implement a component that submits external time suggestions to the time_detector service through a system API call.

To configure the external origin, use the the core/res/res/values/config.xml system server configuration file. Add the value external to config_autoTimeSourcesPriority.

The following example tells Android to give external time suggestions the highest priority when setting the system clock. If there is no valid external time suggestion available then the next origin, gnss in this case, is used.

<string-array name="config_autoTimeSourcesPriority">
        <item>external</item>
        <item>gnss</item>
</string-array>

To provide the system with an external time suggestion, use the suggestExternalTime() method in TimeManager. If the external origin is configured using config_autoTimeSourcesPriority in the configuration file and no higher priority time suggestions are available, Android uses the timestamp passed to this method to set the current UTC time.