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

เฟรมเวิร์กของ 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}