В Android 12 и более поздних версиях Android может опционально использовать глобальную навигационную спутниковую систему (GNSS) для предоставления службе time_detector времени в формате Unix epoch. В AOSP эта функция по умолчанию отключена.
Когда включено определение времени по GNSS, gnss_time_update_service пассивно отслеживает обновления местоположения от источников GNSS и отправляет предложения по GNSS в службу time_detector . Затем служба time_detector определяет, следует ли обновить системные часы в соответствии с предложением.
Влияние на потребление электроэнергии
Сервис AOSP gnss_time_update_service пассивно отслеживает обновления местоположения. Это означает, что сервис никогда активно не включает GPS и не потребляет дополнительную энергию. Это также означает, что если другое приложение или сервис в системе не запрашивает обновления местоположения, gnss_time_update_service не получит обновление местоположения и не предложит время GNSS.
Выполнение
To enable GNSS time detection, device manufacturers must explicitly enable gnss_time_update_service in the system server.
Для включения этой функции необходимо обновить значения параметров config_enableGnssTimeUpdateService и config_autoTimeSourcesPriority в файле core/res/res/values/config.xml . Установите значение параметра config_enableGnssTimeUpdateService равным true и добавьте gnss в список элементов для config_autoTimeSourcesPriority . Позиция gnss в списке приоритетов определяет приоритет, присваиваемый предложениям GNSS по отношению к предложениям из других источников.
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>
Отладка и тестирование
Для проверки определения времени по GNSS используйте команды adb shell cmd location . Эти команды позволяют добавить тестовые поставщики местоположения, указав местоположение и соответствующее время GNSS. gnss_time_update_service отслеживает эти обновления местоположения и периодически предлагает варианты.
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 trueВключить поставщика тестирования GPS
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