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

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