In Android 12 and higher, Android can optionally use a
Global Navigation Satellite System (GNSS) to suggest Unix epoch times to the
time_detector service.
This isn't enabled by default in AOSP.
When GNSS time detection is enabled, gnss_time_update_service passively
listens to location updates from GNSS sources and submits GNSS suggestions to
the time_detector service. The time_detector service then determines whether
to update the system clock to match the suggestion.
Impact on power usage
AOSP gnss_time_update_service passively listens to location updates. This
means that the service never actively turns on the GPS or consumes additional
power. This also means that unless another app or service in the system is
actively requesting location updates, gnss_time_update_service won't get a
location update and suggest a GNSS time.
Implementation
To enable GNSS time detection, device manufacturers must explicitly enable
gnss_time_update_service in the system server.
Both the config_enableGnssTimeUpdateService and
config_autoTimeSourcesPriority values in the core/res/res/values/config.xml
file must be updated to enable this feature. Set the value for
config_enableGnssTimeUpdateService to true and add gnss to the item list
for config_autoTimeSourcesPriority. The position of gnss in the priority
list determines the priority given to GNSS suggestions with respect to those
from other sources.
The following is an example core/res/res/values/config.xml file where GNSS
time detection is enabled and gnss is third in the priority list after
network and telephony:
<!-- Specifies priority of automatic time sources. Suggestions from higher entries in the list
take precedence over lower ones.
See com.android.server.timedetector.TimeDetectorStrategy for available sources. -->
<string-array name="config_autoTimeSourcesPriority">
<item>network</item>
<item>telephony</item>
<item>gnss</item>
</string-array>
<!-- Enables the GnssTimeUpdate service. This is the global switch for enabling Gnss time based
suggestions to TimeDetector service. See also config_autoTimeSourcesPriority. -->
<bool name="config_enableGnssTimeUpdateService">true</bool>
Debug and test
To test GNSS time detection, use adb shell cmd location commands.
Use these commands to add test location providers where you can specify a
location and the associated GNSS time. gnss_time_update_service listens to
these location updates, and makes suggestions periodically.
The following shows examples of adb shell cmd location commands:
Enable the master location switch for the foreground user (usually user
10on automotive). If you just flashed, this can be done through the setup wizard.adb shell cmd location set-location-enabled true --user 10Add GPS test provider (usually fails the first time and throws a security exception with
android from <SOME_UID> not allowed to perform MOCK_LOCATION)adb shell cmd location providers add-test-provider gpsEnable mock location permissions for previous UID
adb shell appops set UID_PRINTED_IN_PREVIOUS_ERROR android:mock_location allowAdd GPS test provider (should work with no errors)
adb shell cmd location providers set-test-provider-enabled gps trueEnable GPS test provider
adb shell cmd location providers set-test-provider-enabled gps trueSet location with time (the time can't be lower than the limit set by the lower bound)
adb shell cmd location providers set-test-provider-location gps --location LATITUDE,LONGITUDE --time TIME