Android telephony--mobile phone signal real-time change source analysis process record

Source: Internet
Author: User

SOURCE Version: 4.4

Skipping UI implementations such as Incallactivity. First look at the service and the bottom.

1, a list of the following files will be found below frameworks/opt:

./telephony/src/java/com/android/Internal/telephony/cdma/Cdmaservicestatetracker.java. /telephony/src/java/com/android/Internal/telephony/cdma/Cdmalteservicestatetracker.java. /telephony/src/java/com/android/Internal/telephony/gsm/Gsmservicestatetracker.java. /telephony/src/java/com/android/Internal/telephony/gsm/Gsmlteservicestatetracker.java. /telephony/src/java/com/android/Internal/telephony/servicestatetracker.java

2, can be directly into the./telephony/src/java/com/android/internal/telephony/servicestatetracker.java analysis, it is easy to find code similar to the following:

619/**620 * Send signal-strength-changed notification if changed called both for621 * solicited and unsolicited Si Gnal Strength updates622 *623 *@returntrue if the signal strength changed and a notification was sent.624*/625protected BooleanOnsignalstrengthresult (AsyncResult ar,Booleanisgsm) {626 Signalstrength oldsignalstrength =msignalstrength;627 628//This signal was used for both voice and data radio signal so parse629// all fields630 631if(Ar.exception = =NULL) && (Ar.result! =NULL)) {632 Msignalstrength =(signalstrength) Ar.result;633msignalstrength.validateinput ();634msignalstrength.setgsm (isgsm);635}Else {636 Log ("Onsignalstrengthresult () Exception from RIL:" +ar.exception);637 Msignalstrength =Newsignalstrength (isgsm);638         }639 640returnnotifysignalstrength ();641}

This is mainly the initialization of the structure and the simple judgment of the context. We continue to track notifysignalstrength ()

229PrivateSignalstrength mlastsignalstrength =NULL;230protected Booleannotifysignalstrength () {231Booleannotified =false;232synchronized(mcellinfo) {233if(!msignalstrength.equals (mlastsignalstrength)) {234Try {235mphonebase.notifysignalstrength ();236 notified =true;237}Catch(NullPointerException ex) {238 Loge ("Updatesignalstrength () Phone already destroyed:" +ex239 + "Signalstrength not notified");240                 }241             }242         }243returnnotified;244}

There are two msignalstrength and mlastsignalstrength, and the amount of signal strength associated with it. is to find the point of entry, signal strength update the middle point is here.

3, let's go down to see what we can learn. Onsignalstrengthresult is being frameworks/opt/telephony/src/java/com/android/internal/telephony/gsm/. The handlemessage in Gsmservicestatetracker.java is called when the message type is event_get_signal_strength:

424 Caseevent_get_signal_strength:425//This callback was called when signal strength was polled426//All by itself427 428if(!(Mci.getradiostate (). IsOn ())) { 429//Polling would continue when radio turns back on430return; 431                 } 432 AR =(AsyncResult) msg.obj;433 Onsignalstrengthresult (AR,true); 434Queuenextsignalstrengthpoll ();435 436 Break;

4, to here need to have a certain understanding of RIL to continue to chase down. Ril's event was passed on to the upper layer and was distributed mainly through a mechanism called registrant.

We jumped into the Frameworks/opt/telephony/src/java/com/android/internal/telephony/ril.java.

Here are the ways to get Signalstrength:

1127     getsignalstrength (Message result) {1128         rilrequest rr1129                 =  Rilrequest.obtain (ril_request_signal_strength, result, mis2ndril); 1130 1131         if (RILJ_LOGD) Riljlog (rr.serialstring () + ">" + requesttostring (rr.mrequest)); 1132 1133         Send (RR); 1134     }

Continue to look down and accept the data from the bottom to the registrant Notification:

2811 Caseril_unsol_signal_strength:2812//Note This is the set to "verbose" because it happens2813//frequently2814if(RILJ_LOGV) Unsljlogvret (response, ret);2815 2816if(Msignalstrengthregistrant! =NULL) {2817Msignalstrengthregistrant.notifyregistrant (2818NewAsyncResult (NULLRetNULL));2819                 }2820 Break;

5, continue to chase down, we see the initiative through the ril_request_signal_strength to REQUEST SIGNAL strength.

So search the keyword directly under Hardware/ril: Ril_request_signal_strength get the result as follows:

./include/telephony/ril.h:1388: * ril_request_signal_strength./include/telephony/ril.h:1402: #define RIL_REQUEST_ Signal_strength 19./libril/ril.cpp:3758: Case        Ril_request_signal_strength:return "Signal_strength";. /libril/ril_commands.h:36:    {ril_request_signal_strength, dispatchvoid, responserilsignalstrength},./ reference-ril/reference-ril.c:2093: Case        ril_request_signal_strength:./reference-ril/ril.h:1388: * RIL_ request_signal_strength./reference-ril/ril.h:1402: #define RIL_REQUEST_SIGNAL_STRENGTH 19

It is obvious that the following function is called to query the signal strength in HARDWARE/RIL/REFERENCE-RIL/REFERENCE-RIL.C, call at command and so on to know:

 839 Static voidRequestsignalstrength (void*data, size_t datalen, Ril_token t)840 { 841Atresponse *p_response =NULL;842     interr;843     Char*Line ;844     intCount =0; 845     intnumofelements=sizeof(RIL_SIGNALSTRENGTH_V6)/sizeof(int); 846     intresponse[numofelements];847  848Err = At_send_command_singleline ("AT+CSQ","+CSQ:", &p_response); 849  850     if(Err <0|| P_response->success = =0) { 851Ril_onrequestcomplete (t, Ril_e_generic_failure, NULL,0); 852         Gotoerror;853     } 854  855line = p_response->p_intermediates->Line ;856  857Err = At_tok_start (&Line ); 858     if(Err <0)Gotoerror;859  860      for(Count =0; Count < numofelements; Count + +) { 861Err = At_tok_nextint (&line, &(Response[count])); 862         if(Err <0)Gotoerror;863     } 864  865Ril_onrequestcomplete (t, ril_e_success, response,sizeof(response)); 866  867At_response_free (p_response);868     return;

From the upper level to the bottom of the basic,telephony other functions of the implementation of the same structure, can also be traced through the above ideas.

The source path involved is basically:

Frameworks/av

Frameworks/base

Frameworks/opt

Packages/apps

Hardware/ril

such as

Android telephony--mobile phone signal real-time change source analysis process record

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.