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

กรอบงาน Android ใช้แหล่งเวลาที่หลากหลายสำหรับการซิงโครไนซ์เวลา หน้านี้เน้นที่แหล่งเวลาอัตโนมัติ Network Time Protocol (NTP) และ Network Identity and Time Zone (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 ณ เวลา build ข้อเสนอแนะเวลาจากแหล่งเวลาที่สูงกว่าในรายการจะมีความสำคัญมากกว่าแหล่งที่มาที่อยู่ต่ำกว่าในรายการ

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