टाइम सोर्स की प्राथमिकता

Android फ़्रेमवर्क, समय सिंक करने के लिए अलग-अलग टाइम सोर्स का इस्तेमाल करता है. इस पेज पर, नेटवर्क टाइम प्रोटोकॉल (NTP) और नेटवर्क आइडेंटिटी और टाइम ज़ोन (NITZ) के अपने-आप समय सेट करने वाले सोर्स के बारे में बताया गया है. Android 12 या इसके बाद के वर्शन में, फ़्रेमवर्क डिफ़ॉल्ट रूप से, समय के सोर्स के तौर पर NITZ के बजाय NTP को प्राथमिकता देता है. ऐसा इसलिए, क्योंकि NTP, NITZ के मुकाबले ज़्यादा सटीक और भरोसेमंद है. अगर NTP उपलब्ध नहीं है, तो फ़्रेमवर्क NITZ का इस्तेमाल करता है. यह प्लैटफ़ॉर्म के पिछले वर्शन की डिफ़ॉल्ट प्राथमिकता के उलट है. Android 11 और उससे पहले के वर्शन में, फ़्रेमवर्क डिफ़ॉल्ट रूप से NTP के बजाय NITZ को प्राथमिकता देता है.

इस बदलाव के बारे में ज़्यादा जानकारी के लिए, AOSP के ये पैच देखें: 1563678, 1513323.

टाइम सोर्स की प्राथमिकता कॉन्फ़िगर करना

किसी खास Android वर्शन के लिए, डिफ़ॉल्ट रूप से किस टाइम सोर्स को प्राथमिकता दी जाए, यह कॉन्फ़िगर करने के लिए, बिल्ड के समय frameworks/base/core/res/res/values/config.xml में config_autoTimeSourcesPriority बटन को कॉन्फ़िगर करें. सूची में सबसे ऊपर मौजूद टाइम सोर्स के सुझावों को, सूची में सबसे नीचे मौजूद सोर्स के सुझावों के मुकाबले प्राथमिकता दी जाती है.

Android के समय के ऐसे सोर्स जिन्हें कॉन्फ़िगर किया जा सकता है, वे TimeDetectorStrategy.java में मिलते हैं. यहां दिए गए सोर्स, डिफ़ॉल्ट रूप से इस्तेमाल के लिए कॉन्फ़िगर होते हैं:

  • टेलीफ़ोनी (NITZ)
  • नेटवर्क (एनटीपी)

टेस्ट करना

यह पुष्टि करने के लिए कि NTP उपलब्ध न होने पर डिवाइस, NITZ का इस्तेमाल करता है (जब मोबाइल डेटा और वाई-फ़ाई बंद हों), यह तरीका अपनाएं:

  1. पक्का करें कि डीयूटी में काम करने वाला सिम कार्ड हो
  2. मोबाइल डेटा और वाई-फ़ाई बंद करना
  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 सेक्शन में सुझाव दिखते हैं, क्योंकि एनटीपी बंद है.

Time change log सेक्शन, डिवाइस की सिस्टम घड़ी में किए गए बदलावों और इस्तेमाल किए गए सुझाव को रिकॉर्ड करता है. सिस्टम घड़ी, config_autoTimeSourcesPriority कुंजी में प्राथमिकता सूची में समय सोर्स के क्रम के आधार पर सेट की जाती है. हालांकि, अगर सुझाव बहुत पुराना या अमान्य है, तो ज़्यादा प्राथमिकता वाले सोर्स के सुझावों को अनदेखा किया जा सकता है. साथ ही, अगर सबसे ज़्यादा प्राथमिकता वाला मान्य सुझाव, डिवाइस की मौजूदा सिस्टम घड़ी के समय से कुछ सेकंड के अंदर मैच होता है, तो समय नहीं बदलेगा. इस टेस्ट केस में, जब तक सुझाव पुराने नहीं हो जाते, तब तक सिस्टम घड़ी को Telephony suggestion history के किसी सुझाव का इस्तेमाल करके सेट किया जाता है.

यहां ऐसे आउटपुट का उदाहरण दिया गया है जिसमें NTP उपलब्ध न होने पर, डिवाइस टाइम सिंक करने के लिए, NITZ का इस्तेमाल करता है.

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}