Android phone call code analysis, android phone code

Source: Internet
Author: User

Android phone call code analysis, android phone code

The call function of a smartphone is implemented by the RIL part. For details, see:

Start to analyze the RIL part of the Android source code.

I also learned that there is a rild daemon in Android. I guess this process has a great relationship with the call answering process.

In addition, such an rild executable file exists in the Android system. The "hardware/ril/rild" directory in the source code contains rild. c file, and in rild. in c, we find the main function, that is, we have found the rild daemon program portal ~

Like a first ~

Start to analyze the code of the rild daemon.

At the beginning of the Code, there are some fragments about Parameter Parsing. For the moment, let's start with some important ril processes of the rild daemon:

Main ()

{// N rows are omitted

RIL_startEventLoop ();

// N rows are omitted.

}

From the name, we should think this should be a starting point -- "startEventLoop" -- a point that begins to enter the time loop. Let's track it and see ^_^.

There is such a line in "rild. c": extern void RIL_startEventLoop ();

It indicates that the code of the RIL_startEventLoop function is still elsewhere. It is found here:

In the ril. cpp file under the "hardware \ Ril \ libril" directory.

Get it ~

In Ril. cpp, RIL_startEventLoop contains the following line:

Ret = pthread_create (& s_tid_dispatch, & attr, eventLoop, NULL );

It seems that Android is here to open up a thread to execute the eventLoop loop,

This eventLoop function is also in this file (Ril. cpp ).

In eventLoop, the main execution is:

Ril_event_init ();

Ril_event_set (& s_wakeupfd_event, s_fdWakeupRead, true,

ProcessWakeupCallback, NULL );

Ril_event_add (& s_wakeupfd_event );

Ril_event_loop ();

You can guess by function name:

Ril_event_set used to create a ril event,

Ril_event_add adds the new event to an execution queue.

Finally, perform a round robin in the loop ril_event_loop to capture the event and complete event processing.

After reading the code of ril_event_set and ril_event_add, we confirmed the previous two points of speculation,

(The Code of the ril_event_set, ril_event_add, and ril_event_loop functions is in ril_event.cpp under the "hardware \ ril \ libril" directory)

The new event is added to an array named watch_table.

Ril_event_loop calls a select function, which is still being analyzed ~~ (This is a system call for unix-type systems, so we will release it for the time being)

Start analyzing the eventloop process again:

First, it is the ril_event_init function. The ril_event_init function has a ril_event struct of timer_list in Ril_event.cpp ("hardware \ ril \ libril") and Ril_event.cpp, which acts as the event queue to be processed (I guest)

Ril_event_init is used to initialize the event queue (through init_list (& timer_list). Of course, pending_list is also initialized)

Then, ril_event_set is an event structure s_wakeupfd_event.

Then, add the s_wakeupfd_event struct of ril_event_add to the watch_table array of Ril_event.cpp.

Finally, the ril_event_loop loop is executed.

Please note that the above steps do not add events to the timer_list part, but the operation of ril_event_loop is based on timer_list. Isn't the event queue empty? How can this happen?

After checking the relevant code, I found that a function named ril_timer_add executed the addToList function. I guess a function called ril_timer_add? What is a function? By using Source Insight to find the caller of the function, we found that the internalRequestTimedCallback function calls ril_timer_add. I think of the key point from the name: the current process is only used to "handle" telephone events, not to generate a telephone event by myself, A call event is generated by an object outside the process (for example, an incoming call or a call is required), and an event in the event queue is added by means of interruption.

So far, we have confirmed that the main listening function of rild is in ril_event_loop:

In the for (;) loop of ril_event_loop, we can see if (-1 = calcNextTimeout (& TV). Here we are trying to handle the call event.


Phone call code written by android cannot be used

In addition, a virtual machine can only call a virtual machine and cannot call a real phone!
 
Create an Android mobile phone call Software

I think the landlord can download a code reading software on app Bao.
Perform code parsing and transformation on the software that has already been done, and then you can compile a similar one.
There are a wide range of software resources on app Bao, and relevant tutorials are also provided.
Supports retrieval and free download of Various Application Software
You only need one-click search.



 

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.