ลำดับความสำคัญของแหล่งที่มาของเวลา

เฟรมเวิร์กของ 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. ตรวจสอบว่ามีซิมที่ใช้งานได้ใน 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 ส่วนถือเป็นแหล่งข้อมูลที่เชื่อถือได้สำหรับ หากอุปกรณ์เชื่อมต่ออินเทอร์เน็ตและมีซิมการ์ด คำแนะนำ สร้างขึ้นโดยใช้ทั้ง NTP (เครือข่าย) และ NITZ (โทรศัพท์) ในกรอบทดสอบนี้ มีเพียงส่วน Telephony suggestion history เท่านั้นที่มีคำแนะนำเนื่องจาก NTP ถูกปิดการใช้งาน

ส่วนTime change logจะบันทึกการเปลี่ยนแปลงที่เกิดขึ้นกับอุปกรณ์ นาฬิการะบบและคำแนะนำที่ใช้ นาฬิการะบบตั้งค่าไว้ตาม ลำดับของเวลาในรายการลำดับความสำคัญใน คีย์ config_autoTimeSourcesPriority อย่างไรก็ตาม คำแนะนำจาก ระบบอาจละเว้นแหล่งที่มาที่มีลําดับความสําคัญสูงกว่าหากคําแนะนํานั้นเก่าเกินไปหรือไม่ถูกต้อง นอกจากนี้ หากคำแนะนำที่ถูกต้องที่มีลำดับความสำคัญสูงสุดตรงกับคำแนะนำปัจจุบันของอุปกรณ์ เวลาของนาฬิกาของระบบเป็นภายใน 2-3 วินาที เวลาจะไม่เปลี่ยนแปลง ในกรอบการทดสอบนี้ ตราบใดที่คำแนะนำยังไม่ล้าสมัย นาฬิกาของระบบ ตั้งค่าโดยใช้คำแนะนำหนึ่งจาก 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}