第一部分 Android電話功能概述
Android的Radio Interface Layer (RIL)提供了電話服務和的radio硬件之間的抽象層。
Radio Interface Layer RIL(Radio Interface Layer)負責數據的可靠傳輸、AT命令的發送以及response的解析。應用處理器通過AT命令集與帶GPRS功能的無線通訊模塊通信。
AT command由Hayes公司發明,是一個調制解調器製造商採用的一個調制解調器命令語言,每條命令以字母"AT"開頭。
JAVA Framework
代碼的路徑爲:
- frameworks/base/telephony/java/android/telephony
- android.telephony以及android.telephony.gsm
在hardware/ril目錄中,提供了對RIL支持的本地代碼,包括4個文件夾:
- hardware/ril/include
- hardware/ril/libril
- hardware/ril/reference-ril
- hardware/ril/rild kernel Driver
第二部分 Android電話功能各個部分
hardware/ril/include/telephony/目錄中的ril.h文件是ril部分的基礎頭文件。
其中定義的結構體RIL_RadioFunctions如下所示:
- typedef struct {
- int version;
- RIL_RequestFunc onRequest;
- RIL_RadioStateRequest onStateRequest;
- RIL_Supports supports;
- RIL_Cancel onCancel;
- RIL_GetVersion getVersion;
- } RIL_RadioFunctions;
幾個函數指針的原型爲:
- typedef void (*RIL_RequestFunc) (int request, void *data,
- size_t datalen, RIL_Token t);
- typedef RIL_RadioState (*RIL_RadioStateRequest)();
- typedef int (*RIL_Supports)(int requestCode);
- typedef void (*RIL_Cancel)(RIL_Token t);
- typedef const char * (*RIL_GetVersion) (void);
2.1 rild守護進程
rild 守護進程的文件包含在hardware/ril/rild目錄中,其中包含了rild.c和radiooptions.c兩個文件,這個目錄中的文件經過編譯後生成一個可執行程序,這個程序在系統的安裝路徑在:
- /system/bin/rild
RIL_Init符號是一個函數指針,執行這個函數後,返回的是一個RIL_RadioFunctions類型的指針。得到這個指針後,調用RIL_register()函數,將這個指針註冊到libril庫之中,然後進入循環。
事實上,這個守護進程提供了一個申請處理的框架,而具體的功能都是在libril.so和libreference-ril.so中完成的。
2.2 libreference-ril.so動態庫
libreference-ril.so動態庫的路徑是:
- hardware/ril/reference-ril
這個庫在執行的過程中需要創建一個線程來執行實際的功能。在執行的過程中,這個庫將打開一個/dev/ttySXXX的終端(終端的名字是從上層傳入的),然後利用這個終端控制硬件執行。
2.3 libril.so動態庫
libril.so庫的目錄是:
hardware/ril/libril 其中主要的文件爲ril.cpp,這個庫主要需要實現的以下幾個接口爲:
- RIL_startEventLoop(void);
- void RIL_setcallbacks (const RIL_RadioFunctions *callbacks);
- RIL_register (const RIL_RadioFunctions *callbacks);
- RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response,
- size_t responselen);
- void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
- size_t datalen);
- RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
- const struct timeval *relativeTime);