Servicestatetracker
As an important tracker for phone: calltracker, dataconnectiontracker, servicestatetracker
Servicestatetracker:Process and maintain various statuses of mobile phones
Cell location celllocation, network status servicestate, signal strength signalstrength,
Business restriction status restrictedstate, user identification card information iccrecords ......
Take a look at the structure of the servicestatetracker class:
There are some differences between CDMA and GSM network communication technologies. Let's take a look at the cdmaservicestatetracker workflow.
Cdmaservicestatetracker is a handler used to process many messages. You can understand the process and role of cdmaservicestatetracker from the message it processes.
Construct cdmaservicestatetracker 1 cdmaservicestatetracker Construction
Public Cdmaservicestatetracker (cdmaphone phone ){ // Related object initialization This . Phone = Phone; SS = New Servicestate (); newss = New Servicestate (); cellloc = New Cdmacelllocation (); msignalstrength = New Signalstrength (); // CDMA sub‑source management host/card separation or integration Mcdmassm = cdmasubscriptionsourcemanager. getinstance (phone. getcontext (), CM, This , Event_cdma _subscription_source_changed, Null ); // Register related events with RIL // Register a radio status change listener event Cm. registerforradiostatechanged ( This , Event_radio_state_changed, Null );
// Voice service status changes Cm. registerforvoicenetworkstatechanged ( This , Event_network_state_changed_cdma, Null );
// Time update Cm. setonnitztime ( This , Event_nitz_time, Null );
// Signal strength update Cm. setonsignalstrengthupdate ( This , Event_signal_strength_update, Null );
// Roaming list Cm. registerforcdmaprlchanged ( This , Event_cdma _prl_version_changed, Null );
// OTA Problems Cm. registerforcdma otaprovision ( This , Event_ota_provision_status_change, Null );
// Obtain the CDMA Standard Cm. getcdmasubmessage (obtainmessage (event_poll_state_cdma _submessage )); // System Setting property airplane_mode_on is set in settings. Int Airplanemode = settings. system. getint (Cr, settings. system. airplane_mode_on, 0 ); Mdesiredpowerstate =! (Airplanemode> 0 );}
2 event processing
When RIL receives such an event, it will notify Y to the registered handler for processing;
Public Void Handlemessage (Message MSG ){ Switch (Msg. What ){...... Case Event_ruim_ready: // Parse roaming-related ERI data Phone. prepareeri (); Break ; Case Event_nv_ready: // The device-card-integrated subcategory information is stored in NV on the mobile phone. Getsubscriptioninfoandstartpollingthreads (); Break ; Case Event_radio_state_changed: // Radio open status to obtain signal strength If (CM. getradiostate () = Radiostate. radio_on) {handlecdmasubscriptionsource (mcdmassm. getcdmasubscriptionsource ()); // Signal strength polling stops when radio is off. Queuenextsignalstrengthpoll ();} // Start radio Setpowerstatetodesired (); // Network status change update Pollstate (); Break ; Case Event_network_state_changed_cdma: // Network status change update Pollstate (); Break ; Case Event_get_signal_strength: // Obtain RF signal strength Onsignalstrengthresult (AR, phone, False ); Queuenextsignalstrengthpoll (); Break ; Case Event_poll_signal_strength: cm. getsignalstrength (obtainmessage (event_get_signal_strength )); Break ; Case Event_nitz_time: // Update Time Settimefromnitzstring (nitzstring, nitzreceivetime ); Break ; Case Event_signal_strength_update: // Update signal strength Onsignalstrengthresult (AR, phone, False ); Break ; Case Event_ruim_records_loaded: // Update mobile phone SPNs Updatespndisplay (); Break ;...... }}
3. event handling process
Create a cdmaservicestatetracker object and register the listener when the phone is created.
Handle several boot events:
After establishing the connection between ril cpp and qcril in the rild process, ensure that the RIL and native RIL socket connections at the framework layer are established.
After a socket connection is established, ril_cpp sends the ril_unsol_ril_connected message to ril_java to inform ril_java that the connection has been established;
Otherwise, ril_java constantly tries to establish a connection, and ril_cpp will continue to listen for the connection.
Based on the sequence diagram process:
1) ril_cpp sends the establish connection message ril_unsol_ril_connected to ril_java
2) After ril_java receives the ril_unsol_ril_connected of the established connection, it sends the ril_request_radio_power message to rild and sets radio to off.
3) the modem sends the radio status change event. After ril_java receives the event, it switches the status and notifies the radio status change.
4) cdmaservicestatetracker receives the event_radio_state_changed notification, and sets radio to on.
5)Ril_java sends the ril_request_radio_power message to rild to start radio.
6) Send the event_radio_state_changed notification to change the radio status. The cdmaservicestatetracker updates the status and obtains the signal strength ......
4. Status settings
InCodeThe status changes are handled in pollstate.
CaseEvent_radio_state_changed: setpowerstatetodesired (); pollstate ();Break;CaseEvent_network_state_changed_cdma: pollstate ();Break;
The final state is through calling the FunctionPollstatedoneCompleted:
Protected Void Pollstatedone (){ // Maintain two servicestate statuses to determine status changes If (DBG) log ("pollstatedone: oldss = [" + SS + "] newss = [" + newss + "]" ); // Mobile Network Status Boolean Hasregistered = SS. getstate () ! = Servicestate. state_in_service & Amp; newss. getstate () = Servicestate. state_in_service; Boolean Hasderegistered = SS. getstate () =Servicestate. state_in_service & Newss. getstate ()! = Servicestate. state_in_service; // Data Network Status Boolean Hascdma dataconnectionattached = Mdataconnectionstate ! = Servicestate. state_in_service & Mnewdataconnectionstate = Servicestate. state_in_service; Boolean Hascdma dataconnectiondetached = Mdataconnectionstate =Servicestate. state_in_service & Mnewdataconnectionstate! = Servicestate. state_in_service; // Determination of various data connection status changes Boolean Hascdma dataconnectionchanged = Mdataconnectionstate ! = Mnewdataconnectionstate; Boolean Hasradiotechnologychanged = mrilradiotechnology! = Mnewrilradiotechnology; Boolean Haschanged =!Newss. Equals (SS ); Boolean Hasroamingon =! SS. getroaming ()&& Newss. getroaming (); Boolean Hasroamingoff = ss. getroaming ()&&! Newss. getroaming (); Boolean Haslocationchanged =! Newcellloc. Equals (cellloc ); // Update Status Servicestate TSS; TSS = SS; SS =Newss; newss = Tss; // Clean slate for next time Newss. setstateoutofservice (); cdmacelllocation TCL = Cellloc; cellloc = Newcellloc; newcellloc = TCL; mdataconnectionstate = Mnewdataconnectionstate; mrilradiotechnology = Mnewrilradiotechnology; // This new State has been applied-forget it until we get a new state Mnewrilradiotechnology = 0 ; Newss. setstateoutofservice (); // Clean slate for next time // Network registration status notification If (Hasregistered) {mnetworkattachedregistrants. policyregistrants ();} // Data Connection notification If (Hascdma dataconnectionattached) {mattachedregistrants. policyregistrants ();} // Data disconnection notification If (Hascdma dataconnectiondetached) {mdetachedregistrants. policyregistrants ();} // Enable roaming notification If (Hasroamingon) {mroamingonregistrants. policyregistrants ();}...... }