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

เฟรมเวิร์ก 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 ในเวลาบิลด์ คำแนะนำเกี่ยวกับเวลา จากแหล่งที่มาของเวลาที่อยู่สูงกว่าในรายการจะมีความสำคัญเหนือกว่า แหล่งที่มาที่อยู่ต่ำกว่าในรายการ

แหล่งเวลาของ 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}