Dari Android 12, Android secara opsional dapat menggunakan Sistem Satelit Navigasi Global (GNSS) untuk menyarankan waktu Unix epoch ke time_detector. Ini tidak diaktifkan secara default di AOSP.
Saat deteksi waktu GNSS diaktifkan, gnss_time_update_service
secara pasif
mendengarkan pembaruan lokasi dari sumber GNSS dan mengirim saran GNSS ke
layanan time_detector
. Layanan time_detector
kemudian menentukan apakah
untuk memperbarui jam sistem agar
sesuai dengan saran.
Dampak pada penggunaan daya
gnss_time_update_service
AOSP secara pasif memproses update lokasi. Ini
berarti perangkat tidak mengaktifkan GPS secara aktif atau menggunakan daya tambahan. Ini
juga berarti bahwa kecuali aplikasi atau layanan
lain dalam sistem secara aktif
meminta pembaruan lokasi, gnss_time_update_service
tidak akan mendapatkan lokasi
memperbarui dan menyarankan waktu GNSS.
Implementasi
Untuk mengaktifkan deteksi waktu GNSS, produsen perangkat harus secara eksplisit mengaktifkan
gnss_time_update_service
di server sistem.
config_enableGnssTimeUpdateService
dan
Nilai config_autoTimeSourcesPriority
di core/res/res/values/config.xml
file harus diperbarui untuk mengaktifkan fitur ini. Tetapkan nilai untuk
config_enableGnssTimeUpdateService
ke true
dan tambahkan gnss
ke daftar item
untuk config_autoTimeSourcesPriority
. Posisi gnss
dalam prioritas
menentukan prioritas yang diberikan untuk saran GNSS dalam kaitannya dengan
dari sumber lain.
Berikut adalah contoh file core/res/res/values/config.xml
dengan GNSS
deteksi waktu diaktifkan dan gnss
berada di urutan ketiga dalam daftar prioritas setelah
network
dan 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>
Proses debug dan pengujian
Untuk menguji deteksi waktu GNSS, Anda dapat menggunakan perintah adb shell cmd location
.
Gunakan perintah berikut untuk menambahkan penyedia lokasi pengujian tempat Anda dapat menentukan
dan waktu GNSS yang terkait. gnss_time_update_service
mendengarkan
lokasi tersebut diperbarui, dan memberikan saran secara berkala.
Berikut ini contoh perintah 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. Throws 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 UIDadb 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 provideradb 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