In Android, the hardware/ril directory contains the telephony source code of Android. I will introduce these directories to you, including three subdirectories, the following is a detailed analysis of the three subdirectories.
I. Directory hardware/ril/include analysis:
Only one header file, ril. h, is included in this directory. Ril. h defines 76 macros of the following types: these macros represent the commands that a customer process can send to telephony, Android source code, including SIM card-related functions, phone calls, text messages, network signal query. Does the address book function seem to be unavailable?
Ii. Directory hardware/ril/libril analysis. The code in this directory is responsible for interacting with the customer process. After receiving the client process command, call the corresponding function for processing, and then return the command response result to the client process. After receiving an event from the network side, it is also sent to the customer process.
File ril_commands.h: lists the commands that telephony can receive, the corresponding processing functions of each command, and the processing functions of the command response. File ril_unsol_commands.h: lists the types of events that telephony can receive and the processing functions for each event;
And WAKE Type ??? File ril_event.h/cpp: processing functions related to the event source (port, modem, etc. Ril_event_loop monitors all registered event sources. When an event source has data, the callback function of the corresponding event source is triggered by firePending-> ev-> func ())
ListenCallback function: This function is called when a connection is established with a client process. This function then calls processCommandsCallback to process the command request processCommandsCallback function from the customer process: process the command request from the customer process.
For each command, ril_commands.h specifies the corresponding command processing function dispatchXXX). processCommandsCallback calls this command processing function for processing. Dispatch functions: This function receives the corresponding parameters of commands from the customer Process and calls onRequest for processing.
RIL_onUnsolicitedResponse function: encapsulate events from the network side by calling responseXXX) and send the events to the customer process. RIL_onRequestComplete function: encapsulate the final response structure of the command by calling responseXXX) and then send the events to the customer process.
Response series functions: Each Command requires a corresponding response function to process the final response of the command; for each network-side event, it also specifies a corresponding response function to handle this event. The response function can be called by onUnsolicitedResponse or onRequestComplete.
Iii. Directory hardware/ril/reference-ril analysis. The code in this directory is mainly responsible for interacting with modem. File reference-ril.c: the core of this file is two functions: onRequest and onUnsolicited.
OnRequest function: in this function, each RIL_REQUEST_XXX request is converted into an AT command, sent to the modem, and then sleep. After receiving the final response from this AT command, the thread is awakened and the response is sent to the client process RIL_onRequestComplete-> sendResponse ).
OnUnsolicited function: This function handles various events received by the modem from the network, such as network signal changes, incoming calls, and text messages. Then pass the time to the client process RIL_onUnsolicitedResponse-> sendResponse) file atchannel. c: reads and writes data to the modem. The write data (mainly AT command) function runs in the main thread, and the read data function runs in a separate read thread.
Android source code at_send_command_full_nolock: runs in the main thread. Write an AT command to the modem and enter the sleep state using pthread_cond_wait or similar functions) until the modem read thread wakes it up. After waking up, this function obtains the final response of the AT command and returns it.
The readerLoop function runs in a separate read thread and reads data from the modem. Data read can be divided into three types: Incoming events on the network side, partial responses from the modem to the current AT command, and full responses from the modem to the current AT command. For all responses to the third type of data AT command), The read thread wakes up pthread_cond_signal) the main thread in sleep state.