Wykrywanie czasu GNSS

Począwszy od systemu Android 12, system Android może opcjonalnie korzystać z globalnego systemu nawigacji satelitarnej (GNSS), aby sugerować czasy epok systemu Unix usłudze time_detector . Nie jest to domyślnie włączone w AOSP.

Gdy włączone jest wykrywanie czasu GNSS, gnss_time_update_service pasywnie nasłuchuje aktualizacji lokalizacji ze źródeł GNSS i przesyła sugestie GNSS do usługi time_detector . Usługa time_detector określa następnie, czy zaktualizować zegar systemowy, aby odpowiadał sugestii.

Wpływ na zużycie energii

Usługa AOSP gnss_time_update_service biernie nasłuchuje aktualizacji lokalizacji. Oznacza to, że nigdy aktywnie nie włącza GPS i nie zużywa dodatkowej energii. Oznacza to również, że jeśli inna aplikacja lub usługa w systemie aktywnie nie żąda aktualizacji lokalizacji, usługa gnss_time_update_service nie otrzyma aktualizacji lokalizacji i nie zasugeruje czasu GNSS.

Realizacja

Aby umożliwić wykrywanie czasu GNSS, producenci urządzeń muszą jawnie włączyć gnss_time_update_service na serwerze systemowym.

Aby włączyć tę funkcję, należy zaktualizować zarówno wartości config_enableGnssTimeUpdateService , jak i config_autoTimeSourcesPriority w pliku core/res/res/values/config.xml . Ustaw wartość config_enableGnssTimeUpdateService na true i dodaj gnss do listy elementów dla config_autoTimeSourcesPriority . Pozycja gnss na liście priorytetów określa priorytet nadawany sugestiom GNSS w stosunku do sugestii z innych źródeł.

Poniżej znajduje się przykładowy plik core/res/res/values/config.xml , w którym włączono wykrywanie czasu GNSS, a gnss zajmuje trzecie miejsce na liście priorytetów po network i 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>

Debugowanie i testowanie

Aby przetestować wykrywanie czasu GNSS, możesz użyć poleceń adb shell cmd location . Użyj tych poleceń, aby dodać dostawców lokalizacji testowych, w których możesz określić lokalizację i powiązany czas GNSS. Usługa gnss_time_update_service nasłuchuje aktualizacji lokalizacji i okresowo przedstawia sugestie.

Poniżej przedstawiono przykłady poleceń adb shell cmd location :

# Enable Master Location Switch in the foreground user (usually user 10 on automotive). If you just flashed, this can be done through setup wizard.
adb shell cmd location set-location-enabled true --user 10

# Add GPS test provider (This usually fails the first time. Will throw a SecurityException with "android from <SOME_UID> not allowed to perform MOCK_LOCATION".)
adb shell cmd location providers add-test-provider gps

# Enable mock location permissions for previous UID
adb shell appops set UID_PRINTED_IN_PREVIOUS_ERROR android:mock_location allow

# Add GPS test provider (Should work with no errors.)
adb shell cmd location providers add-test-provider gps

# Enable GPS test provider
adb shell cmd location providers set-test-provider-enabled gps true

# Set location with time (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