החל מ-Android 12, ב-Android אפשר להשתמש מערכת ניווט לוויינית גלובלית (GNSS) כדי להציע זמנים של יוניקס (Unix epoch) time_detector. האפשרות הזו לא מופעלת כברירת מחדל ב-AOSP.
כשזיהוי הזמן של GNSS מופעל, gnss_time_update_service
באופן פסיבי
מקשיבה לעדכוני מיקום ממקורות של GNSS ושולחת הצעות ל-GNSS אל
השירות time_detector
. שירות time_detector
יקבע אם
כדי לעדכן את שעון המערכת בהתאם להצעה.
ההשפעה על השימוש בחשמל
gnss_time_update_service
של AOSP מאזין באופן פסיבי לעדכוני מיקום. הזה
כלומר, אף פעם לא מפעילה את ה-GPS באופן פעיל או צורכת חשמל נוסף. הזה
כלומר, אלא אם אפליקציה או שירות אחרים במערכת פועלים
נשלחת בקשה לעדכוני מיקום, ל-gnss_time_update_service
לא תהיה גישה למיקום
מעדכנים ומציעים זמן של GNSS.
הטמעה
כדי להפעיל את זיהוי הזמן של GNSS, יצרני המכשירים חייבים להפעיל באופן מפורש
gnss_time_update_service
בשרת המערכת.
גם config_enableGnssTimeUpdateService
וגם
config_autoTimeSourcesPriority
ערכים ברכיב core/res/res/values/config.xml
יש לעדכן את הקובץ כדי להפעיל את התכונה הזו. הגדרת הערך של
config_enableGnssTimeUpdateService
אל true
והוספת gnss
לרשימת הפריטים
למשך config_autoTimeSourcesPriority
. המיקום של gnss
בעדיפות
קובעת את העדיפות שתינתן להצעות GNSS ביחס
ממקורות אחרים.
הדוגמה הבאה היא קובץ core/res/res/values/config.xml
שבו GNSS
זיהוי הזמן מופעל ו-gnss
נמצא במקום השלישי ברשימת העדיפויות של האפליקציות אחרי
network
וגם 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
מאזין ל
ומדי פעם את עדכוני המיקום האלה.
בדוגמה הבאה מוצגות דוגמאות לפקודות 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