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

يستخدم إطار عمل Android مصادر زمنية متنوعة لمزامنة الوقت. تركز هذه الصفحة على بروتوكول وقت الشبكة (NTP) مصادر الوقت التلقائية لهوية الشبكة والمنطقة الزمنية (NITZ). في نظام التشغيل Android 12 أو الإصدارات الأحدث، يتم تلقائيًا يعطي NTP الأولوية كمصدر للوقت على NITZ لأن NTP أكثر دقة وموثوقية من NITZ. في الحالات التي لا يتوفّر فيها NTP، يعود إطار العمل إلى NITZ. وهذا يمثل عكسًا للأولوية الافتراضية من الإصدارات السابقة من بدون خادم. يمنح إطار العمل الأولوية لنظام NITZ في Android 11 والإصدارات الأقدم تلقائيًا. عبر 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 فقط على اقتراحات لأنّ بروتوكول وقت الشبكة غير مفعَّل.

يسجِّل القسم "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}