كشف وقت GNSS

بدءًا من Android 12، يمكن لنظام Android اختياريًا استخدام النظام العالمي للملاحة عبر الأقمار الصناعية (GNSS) لاقتراح أوقات عصر Unix لخدمة time_detector . لا يتم تمكين هذا افتراضيًا في AOSP.

عند تمكين اكتشاف وقت GNSS، تستمع gnss_time_update_service بشكل سلبي إلى تحديثات الموقع من مصادر GNSS وترسل اقتراحات GNSS إلى خدمة time_detector . تحدد خدمة time_detector بعد ذلك ما إذا كان سيتم تحديث ساعة النظام لتتوافق مع الاقتراح.

التأثير على استخدام الطاقة

تستمع خدمة AOSP gnss_time_update_service بشكل سلبي إلى تحديثات الموقع. وهذا يعني أنه لا يقوم أبدًا بتشغيل نظام تحديد المواقع العالمي (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. 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