Android Telephony-real-time mobile phone signal change source code analysis process record, androidtelephony

Source: Internet
Author: User
Tags how to use git

Android Telephony-real-time mobile phone signal change source code analysis process record, androidtelephony

Source code: 4.4

Skip UI implementations such as InCallActivity. First look at the service and the underlying layer.

 

1. the following file list is found under 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. You can directly go to./telephony/src/java/com/android/internal/telephony/ServiceStateTracker. java for analysis and easily find code similar to the following:

619     /**620      * send signal-strength-changed notification if changed Called both for621      * solicited and unsolicited signal strength updates622      *623      * @return true if the signal strength changed and a notification was sent.624      */625     protected boolean onSignalStrengthResult(AsyncResult ar, boolean isGsm) {626         SignalStrength oldSignalStrength = mSignalStrength;627 628         // This signal is used for both voice and data radio signal so parse629         // all fields630 631         if ((ar.exception == null) && (ar.result != null)) {632             mSignalStrength = (SignalStrength) ar.result;633             mSignalStrength.validateInput();634             mSignalStrength.setGsm(isGsm);635         } else {636             log("onSignalStrengthResult() Exception from RIL : " + ar.exception);637             mSignalStrength = new SignalStrength(isGsm);638         }639 640         return notifySignalStrength();641     }

The initialization of the struct and the simple judgment of the context. We continue to track policysignalstrength ()

229     private SignalStrength mLastSignalStrength = null;230     protected boolean notifySignalStrength() {231         boolean notified = false;232         synchronized(mCellInfo) {233             if (!mSignalStrength.equals(mLastSignalStrength)) {234                 try {235                     mPhoneBase.notifySignalStrength();236                     notified = true;237                 } catch (NullPointerException ex) {238                     loge("updateSignalStrength() Phone already destroyed: " + ex239                             + "SignalStrength not notified");240                 }241             }242         }243         return notified;244     }

Here there are two quantities related to signal strength: mSignalStrength and mLastSignalStrength. The starting point is found, and the intermediate point of signal strength update is here.

 

3. Let's analyze down to see what we can learn. OnSignalStrengthResult is called by frameworks/opt/telephony/src/java/com/android/internal/telephony/gsm/GsmServiceStateTracker. java when the handleMessage Type is EVENT_GET_SIGNAL_STRENGTH:

 424             case EVENT_GET_SIGNAL_STRENGTH: 425                 // This callback is called when signal strength is polled 426                 // all by itself 427  428                 if (!(mCi.getRadioState().isOn())) { 429                     // Polling will continue when radio turns back on 430                     return; 431                 } 432                 ar = (AsyncResult) msg.obj; 433                 onSignalStrengthResult(ar, true); 434                 queueNextSignalStrengthPoll(); 435  436                 break;

4. here we need to have a certain understanding of RIL to continue. After the RIL event is uploaded to the upper layer, it is mainly distributed through a mechanism called Registrant.

Go to frameworks/opt/telephony/src/java/com/android/internal/telephony/RIL. java.

Here is a method 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. After receiving the data from the bottom layer, use Registrant Notification:

2811             case RIL_UNSOL_SIGNAL_STRENGTH:2812                 // Note this is set to "verbose" because it happens2813                 // frequently2814                 if (RILJ_LOGV) unsljLogvRet(response, ret);2815 2816                 if (mSignalStrengthRegistrant != null) {2817                     mSignalStrengthRegistrant.notifyRegistrant(2818                                         new AsyncResult (null, ret, null));2819                 }2820             break;

 

5. Continue to catch up. We can see that there is an active request for signal strength through RIL_REQUEST_SIGNAL_STRENGTH.

Therefore, search for the keyword RIL_REQUEST_SIGNAL_STRENGTH directly under hardware/ril. The result is 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

Obviously hardware/ril/reference-ril/The following function in the reference-ril.c is called to query the signal strength, call AT command and so on a look to know:

 839 static void requestSignalStrength(void *data, size_t datalen, RIL_Token t) 840 { 841     ATResponse *p_response = NULL; 842     int err; 843     char *line; 844     int count =0; 845     int numofElements=sizeof(RIL_SignalStrength_v6)/sizeof(int); 846     int response[numofElements]; 847  848     err = at_send_command_singleline("AT+CSQ", "+CSQ:", &p_response); 849  850     if (err < 0 || p_response->success == 0) { 851         RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); 852         goto error; 853     } 854  855     line = p_response->p_intermediates->line; 856  857     err = at_tok_start(&line); 858     if (err < 0) goto error; 859  860     for (count =0; count < numofElements; count ++) { 861         err = at_tok_nextint(&line, &(response[count])); 862         if (err < 0) goto error; 863     } 864  865     RIL_onRequestComplete(t, RIL_E_SUCCESS, response, sizeof(response)); 866  867     at_response_free(p_response); 868     return;

 

From the upper layer to the lower layer,Other functions of Telephony have the same implementation structure and can also be tracked through the above ideas.

The source code paths involved include:

Frameworks/av

Frameworks/base

Frameworks/opt

Packages/apps

Hardware/ril

And so on

 


How to analyze the android source code

To view its structure, you need to look at a structural diagram provided by google. Let's take a look at the analysis and analysis. The project in the source code cannot be imported into Eclipse as an Android project separately. You need to import all the Android source code. For how to use git to download the source code, search for it on the Internet and try it on your own. This is not a question, but it is only a matter of your own!

How can I analyze the source code of android?

If you have a high level, you can start from which module, but if you are still at a general level and not very familiar with the code, I personally suggest you buy a related book so that it is better to take the book with you for analysis!

Related Article

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.