أولوية مصدر الوقت

يستخدم إطار عمل Android مصادر زمنية مختلفة لمزامنة الوقت. تركّز هذه الصفحة على بروتوكول Network Time Protocol ‏(NTP) ومصدرَي الوقت التلقائيَين Network Identity and Time Zone ‏(NITZ). في الإصدار 12 من Android أو الإصدارات الأحدث، يمنح الإطار العمل NTP الأولوية كمصدر للوقت على NITZ تلقائيًا لأنّ NTP هو أكثر دقة وموثوقية من NITZ. في الحالات التي لا يتوفّر فيها NTP، يعود إطار العمل إلى NITZ. وهذا يمثل عكسًا للأولوية الافتراضية من الإصدارات السابقة من بدون خادم. في الإصدار 11 من Android والإصدارات الأقدم، يمنح إطار العمل الأولوية لبروتوكول NITZ على بروتوكول NTP.

لمزيد من التفاصيل حول هذا التغيير، يُرجى الاطّلاع على الرموز البرمجية التالية في إطار مشروع AOSP: 1563678، 1513323.

ضبط أولوية مصدر الوقت

لضبط مصدر الوقت الذي يحظى بالأولوية تلقائيًا لإصدار Android معيّن، اضبط المفتاح config_autoTimeSourcesPriority في frameworks/base/core/res/res/values/config.xml في وقت الإنشاء. مدة تكون الأولوية للاقتراحات من مصدر الوقت الأعلى في القائمة على المصادر الأقل في القائمة.

يمكن العثور على مصادر الوقت في Android التي يمكن ضبطها في TimeDetectorStrategy.java. تم ضبط المصادر التالية للاستخدام بشكل تلقائي:

  • الاتصالات الهاتفية (NITZ)
  • الشبكة (بروتوكول NTP)

الاختبار

للتأكّد من أنّ الجهاز يستخدم بروتوكول NITZ عندما لا يكون بروتوكول NTP متاحًا (عندما تكون بيانات الجوّال وشبكة Wi-Fi غير مفعَّلَين)، اتّبِع الخطوات التالية:

  1. التأكّد من توفُّر شريحة SIM صالحة في جهاز DUT
  2. إيقاف بيانات الجوّال وشبكة Wi-Fi
  3. اضبط الجهاز على وضع الطيران للتأكّد من إيقاف الراديو الخلوي.
  4. إيقاف ميزة "الرصد التلقائي للوقت"
  5. ضبط الساعة يدويًا على قيمة وقت غير صحيحة في المستقبل
  6. إعادة تشغيل الجهاز
  7. تفعيل ميزة "التعرّف التلقائي على الوقت"
  8. إخراج الجهاز من وضع الطيران

تؤدي هذه الخطوات إلى حدوث تغيير في ساعة النظام عند بدء تشغيل NITZ. استلام الإشارة. للتحقّق من كيفية ضبط وقت الجهاز، يمكنك تشغيل ما يلي :

adb shell dumpsys time_detector

للتحقّق من أنّ ساعة النظام تستخدم NITZ، يجب تأكيد ما يلي في الأمر: الناتج:

  • mEnvironment.isAutoTimeDetectionEnabled() true.
  • يحتوي الحقل mEnvironment.autoOriginPriorities() على قائمة بمصادر الوقت، ويُمنَح الأولوية للمصادر التي تظهر في أعلى القائمة على المصادر التي تظهر في أسفل القائمة.
  • يشير القسم Time change log إلى أنّه تم ضبط ساعة النظام باستخدام أحد اقتراحات ميزة "الهاتف".
  • يحتوي قسم Telephony suggestion history على اقتراحات بشأن الوقت.
  • قسم Network suggestion history فارغ.

تُعدّ اقتراحات الوقت في قسمَي Telephony suggestion history و Network suggestion history مصدرًا دقيقًا لتحديد الوقت. إذا كان الجهاز متصلاً بالإنترنت وكان يحتوي على شريحة SIM، يتم إنشاء الاقتراحات باستخدام بروتوكول NTP (الشبكة) وNitz (الهاتف). وفي حالة الاختبار هذه، يحتوي القسم Telephony suggestion history فقط على اقتراحات لأنّ بروتوكول NTP غير مفعّل.

يسجِّل القسم "Time change log" التغييرات التي تمّ إجراؤها على بيانات ساعة النظام والاقتراح المستخدم. يتم ضبط ساعة النظام بناءً على ترتيب مصادر الوقت في قائمة الأولوية المفتاح config_autoTimeSourcesPriority. ومع ذلك، فإن الاقتراحات من قد يتم تجاهل المصدر ذو الأولوية الأعلى إذا كان الاقتراح قديمًا جدًا أو غير صالح. بالإضافة إلى ذلك، إذا كان الاقتراح الصالح ذو الأولوية الأعلى يتطابق مع الاقتراح الحالي للجهاز ساعة النظام إلى بضع ثوانٍ، لن يتم تغيير الوقت. وفي حالة الاختبار هذه، طالما أن الاقتراحات ليست قديمة، فإن ساعة النظام تم الضبط باستخدام أحد الاقتراحات من Telephony suggestion history.

في ما يلي مثال على إخراج يتوقّف فيه الجهاز عن استخدام التنسيق NITZ عندما لا يكون التنسيق NTP متاحًا.

TimeDetectorStrategy:
  mLastAutoSystemClockTimeSet=TimestampedValue{mReferenceTimeMillis=66240, mValue=1614186761000}
  mEnvironment.isAutoTimeDetectionEnabled()=true
  mEnvironment.elapsedRealtimeMillis()=73059
  mEnvironment.systemClockMillis()=1614186767818
  mEnvironment.systemClockUpdateThresholdMillis()=2000
  mEnvironment.autoTimeLowerBound()=2021-02-24T15:44:15Z(1614181455000)
  mEnvironment.autoOriginPriorities()=[network,telephony]
  Time change log:
    66261 / 2021-02-24T17:12:41.020Z - Set system clock using time=TimestampedValue{mReferenceTimeMillis=66240, mValue=1614186761000} cause=Found good telephony suggestion., bestTelephonySuggestion=TelephonyTimeSuggestion{mSlotIndex='0', mUtcTime=TimestampedValue{mReferenceTimeMillis=66240, mValue=1614186761000}, mDebugInfo=[Sending new time suggestion nitzSignal=TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}}, reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}})]}, detectionReason=New telephony time suggested. timeSuggestion=TelephonyTimeSuggestion{mSlotIndex='0', mUtcTime=TimestampedValue{mReferenceTimeMillis=66240, mValue=1614186761000}, mDebugInfo=[Sending new time suggestion nitzSignal=TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}}, reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}})]} elapsedRealtimeMillis=66259 newSystemClockMillis=1614186761019
  Telephony suggestion history:
    key idx: 0=0
    val idx: 0=TelephonyTimeSuggestion{mSlotIndex='0', mUtcTime=TimestampedValue{mReferenceTimeMillis=66240, mValue=1614186761000}, mDebugInfo=[Sending new time suggestion nitzSignal=TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}}, reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}})]}
      Historic values=[
        0@PT1M6.258S: TelephonyTimeSuggestion{mSlotIndex='0', mUtcTime=TimestampedValue{mReferenceTimeMillis=66240, mValue=1614186761000}, mDebugInfo=[Sending new time suggestion nitzSignal=TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}}, reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}})]}
      ]
  Network suggestion history:
    {Empty}
  Gnss suggestion history:
    {Empty}
  External suggestion history:
    {Empty}

للاطّلاع على مثال على الإخراج المعتاد الذي يتلقّى فيه الجهاز اقتراحات بشأن الوقت من مصدرَي الوقت NTP وNITZ، يُرجى الاطّلاع على الجدول التالي.

TimeDetectorStrategy:
  mLastAutoSystemClockTimeSet=TimestampedValue{mReferenceTimeMillis=66240, mValue=1614186761000}
  mEnvironment.isAutoTimeDetectionEnabled()=true
  mEnvironment.elapsedRealtimeMillis()=302926
  mEnvironment.systemClockMillis()=1614186997685
  mEnvironment.systemClockUpdateThresholdMillis()=2000
  mEnvironment.autoTimeLowerBound()=2021-02-24T15:44:15Z(1614181455000)
  mEnvironment.autoOriginPriorities()=[network,telephony]
  Time change log:
    66261 / 2021-02-24T17:12:41.020Z - Set system clock using time=TimestampedValue{mReferenceTimeMillis=66240, mValue=1614186761000} cause=Found good telephony suggestion., bestTelephonySuggestion=TelephonyTimeSuggestion{mSlotIndex='0', mUtcTime=TimestampedValue{mReferenceTimeMillis=66240, mValue=1614186761000}, mDebugInfo=[Sending new time suggestion nitzSignal=TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}}, reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}})]}, detectionReason=New telephony time suggested. timeSuggestion=TelephonyTimeSuggestion{mSlotIndex='0', mUtcTime=TimestampedValue{mReferenceTimeMillis=66240, mValue=1614186761000}, mDebugInfo=[Sending new time suggestion nitzSignal=TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}}, reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}})]} elapsedRealtimeMillis=66259 newSystemClockMillis=1614186761019
  Telephony suggestion history:
    key idx: 0=0
    val idx: 0=TelephonyTimeSuggestion{mSlotIndex='0', mUtcTime=TimestampedValue{mReferenceTimeMillis=66240, mValue=1614186761000}, mDebugInfo=[Sending new time suggestion nitzSignal=TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}}, reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}})]}
      Historic values=[
        0@PT1M6.258S: TelephonyTimeSuggestion{mSlotIndex='0', mUtcTime=TimestampedValue{mReferenceTimeMillis=66240, mValue=1614186761000}, mDebugInfo=[Sending new time suggestion nitzSignal=TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}}, reason=handleNitzReceived(TimestampedValue{mReferenceTimeMillis=66240, mValue=NitzData{mOriginalString=21/02/24,17:12:41+00,00, mZoneOffset=0, mDstOffset=0, mCurrentTimeMillis=1614186761000, mEmulatorHostTimeZone=null}})]}
      ]
  Network suggestion history:
    0@PT4M4.04S: NetworkTimeSuggestion{mUtcTime=TimestampedValue{mReferenceTimeMillis=244038, mValue=1614186939242}, mDebugInfo=[Origin: NetworkTimeUpdateService. event=3]}
  Gnss suggestion history:
    {Empty}
  External suggestion history:
    {Empty}