رصد وقت GNSS

بدءًا من نظام التشغيل Android 12، يمكن لنظام التشغيل Android أن يستخدم اختياريًا نظام القمر الصناعي العالمي للتنقل (GNSS) لاقتراح أوقات حقبة يونكس إلى 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 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