Android फ़्रेमवर्क, समय को सिंक करने के लिए अलग-अलग टाइम सोर्स का इस्तेमाल करता है. इस पेज पर, नेटवर्क टाइम प्रोटोकॉल (एनटीपी) और नेटवर्क आइडेंटिटी ऐंड टाइम ज़ोन (एनआईटीज़) के बारे में बताया गया है. ये दोनों, समय की जानकारी अपने-आप देने वाले सोर्स हैं. Android 12 या इसके बाद के वर्शन में, फ़्रेमवर्क डिफ़ॉल्ट रूप से समय के सोर्स के तौर पर NITZ के बजाय NTP को प्राथमिकता देता है. ऐसा इसलिए, क्योंकि NTP, NITZ से ज़्यादा सटीक और भरोसेमंद है. जिन स्थितियों में एनटीपी उपलब्ध नहीं होता है उनमें फ़्रेमवर्क, एनटीआईजेड का इस्तेमाल करता है. यह प्लैटफ़ॉर्म के पिछले वर्शन में, डिफ़ॉल्ट प्राथमिकता के उलट है. Android 11 और इससे पहले के वर्शन में, फ़्रेमवर्क डिफ़ॉल्ट रूप से NTP के बजाय NITZ को प्राथमिकता देता है.
इस बदलाव के बारे में ज़्यादा जानने के लिए, यहां दिए गए AOSP पैच देखें: 1563678, 1513323.
टाइम सोर्स की प्राथमिकता कॉन्फ़िगर करना
यह कॉन्फ़िगर करने के लिए कि किसी खास Android वर्शन के लिए, डिफ़ॉल्ट रूप से कौनसे टाइम सोर्स को प्राथमिकता दी जाए, बिल्ड टाइम पर frameworks/base/core/res/res/values/config.xml
में config_autoTimeSourcesPriority
कुंजी को कॉन्फ़िगर करें. सूची में ऊपर मौजूद टाइम सोर्स से मिले समय के सुझावों को, सूची में नीचे मौजूद सोर्स से मिले सुझावों के मुकाबले ज़्यादा प्राथमिकता दी जाती है.
कॉन्फ़िगर किए जा सकने वाले Android टाइम सोर्स, TimeDetectorStrategy.java
में मौजूद होते हैं.
यहां दिए गए सोर्स, डिफ़ॉल्ट रूप से इस्तेमाल करने के लिए कॉन्फ़िगर किए जाते हैं:
- टेलीफ़ोनी (एनआईटी्ज़)
- नेटवर्क (एनटीपी)
टेस्ट करना
यह पुष्टि करने के लिए कि जब एनटीपी उपलब्ध न हो, तब डिवाइस NITZ का इस्तेमाल करता है (जब मोबाइल डेटा और वाई-फ़ाई बंद हों), तो यह तरीका अपनाएं:
- पक्का करें कि DUT में काम करने वाला सिम कार्ड हो
- मोबाइल डेटा और वाई-फ़ाई बंद करना
- डिवाइस को हवाई जहाज़ मोड पर रखें, ताकि यह पक्का किया जा सके कि सेल रेडियो बंद है
- समय का अपने-आप पता लगने की सुविधा बंद करना
- घड़ी को मैन्युअल तरीके से, आने वाले समय के लिए गलत समय पर सेट करना
- डिवाइस को रीबूट करें
- समय का अपने-आप पता लगने की सुविधा चालू करना
- डिवाइस पर फ़्लाइट मोड बंद करें
इन चरणों को पूरा करने पर, 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
सेक्शन में दिए गए समय के सुझावों को, समय के लिए भरोसेमंद सोर्स माना जाता है. अगर डिवाइस इंटरनेट से कनेक्ट है और उसमें सिम कार्ड है, तो सुझाव जनरेट करने के लिए, एनटीपी (नेटवर्क) और एनआईटीज़ (टेलीफ़ोनी), दोनों का इस्तेमाल किया जाता है. इस टेस्ट केस में, सिर्फ़ Telephony suggestion history
सेक्शन में सुझाव दिख रहे हैं, क्योंकि
एनटीपी बंद है.
Time change log
सेक्शन में, डिवाइस की सिस्टम क्लॉक में किए गए बदलाव और इस्तेमाल किए गए सुझाव को रिकॉर्ड किया जाता है. सिस्टम क्लॉक, config_autoTimeSourcesPriority
कुंजी में प्राथमिकता सूची में मौजूद समय के सोर्स के क्रम के आधार पर सेट की जाती है. हालांकि, अगर सुझाव बहुत पुराना है या अमान्य है, तो ज़्यादा प्राथमिकता वाले सोर्स से मिले सुझावों को अनदेखा किया जा सकता है.
इसके अलावा, अगर सबसे ज़्यादा प्राथमिकता वाला मान्य सुझाव, डिवाइस की मौजूदा सिस्टम क्लॉक के समय से कुछ सेकंड के अंदर मेल खाता है, तो समय में बदलाव नहीं किया जाएगा.
इस टेस्ट केस में, जब तक सुझाव पुराने नहीं हो जाते, तब तक सिस्टम क्लॉक को Telephony suggestion history
से मिले किसी एक सुझाव का इस्तेमाल करके सेट किया जाता है.
यहां एक ऐसे आउटपुट का उदाहरण दिया गया है जिसमें डिवाइस, एनटीपी के उपलब्ध न होने पर 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}