I recently read the network time synchronization and summarized it.
Overall description:
Android Network Time Synchronization uses the network identity and Time Zone (nitz) operator to select Services.
The RIL layer actively reports the notify message. The notification (notify Y) is sent to the notify and gsmservicestatetracker. The notify obtains the network synchronization time and determines whether to synchronize and send the notifications Based on the automatic synchronization settings in datetimesetting (action_network_set_time) broadcast.
Where
/** If time between nitz updates is less than mnitzupdatespacing the update may be ignored .*/
Private Static final int nitz_update_spacing_default = 1000*60*10;
Private int mnitzupdatespacing = systemproperties. getint ("Ro. nitz_update_spacing ",
Nitz_update_spacing_default );
Determines the synchronization interval. If the Active Reporting interval is less than this interval, the message is ignored.
/** If mnitzupdatespacing hasn't been exceeded but update is> mnitzupdate do the update */
Private Static final int nitz_update_diff_default = 2000;
Private int mnitzupdatediff = systemproperties. getint ("Ro. nitz_update_diff ",
Nitz_update_diff_default );
The default interval between the reported nitz synchronization time and the current processing time. If the actual interval is greater than this interval, this time is synchronized.
Synchronous judgment Condition
If (msavedattime = 0) | (timesincelastupdate> nitzupdatespacing)
| (Math. Abs (gained)> nitzupdatediff )){
Log. I (log_tag, "nitz: auto updating time of day to" + C. gettime ()
+ "Nitz receive delay =" + millissincenitzreceived
+ "Ms gained =" + gained + "MS from" + nitz );
Setandbroadcastnetworksettime (C. gettimeinmillis ());
} Else {
Log. I (log_tag, "nitz: Ignore, a previous update was"
+ Timesincelastupdate + "Ms ago and gained =" + gained + "Ms ");
Return;
}
In the upper-layer setting app, if datetimesetting sets autotime to true, then the cdmaservicestatetracker and gsmservicestatetracker listen based on the current
If (msavedtimezone! = NULL & msavedtime! = 0 & msavedattime! = 0 ){
Setandbroadcastnetworksettimezone (msavedtimezone );
Setandbroadcastnetworksettime (msavedtime
+ (Systemclock. elapsedrealtime ()-msavedattime ));
}
Broadcast time and time zone