Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android中打電話的數據流程分析

Android中打電話的數據流程分析

編輯:關於Android編程

1.所有流程的起點是從撥號後按下撥號鍵開始,此步的代碼在/android sourcecode/packages/Contacts/src/com/android/contacts/目錄的TwelveKeyDialer.java文件中,相關代碼如下:
復制代碼 代碼如下:
dialButtonPressed() {
.........
final String number = mDigits.getText().toString();
startActivity(newDialNumberIntent(number));
mDigits.getText().clear();
finish();
}

代碼中newDialNumberIntent()方法定義如下
復制代碼 代碼如下:
private Intent newDialNumberIntent(String number) {
final Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, Uri.fromParts("tel", number, null));
.............
}

從newDialNumberIntent的定義可以看出,當撥號鍵按下以後,TwelveKeyDial會啟動一個特定的組件,該組件的ACTION為:ACTION_CALL_PRIVILEGED,經過查找,該ACTION啟動的組件是目下:/android sourcecode/packeges/Phone/的一個文件,在該文件下的AndroidMenifest.xml中可以查到:“ACTION_CALL_PRIVILEGED”啟動的Activity的名字是:PrivilegedOutgoingCallBroadcast,但是我們到/android sourcecode/packeges/Phone/src/....目下並找不到該文件,因為該文件在AndroidMenifest.xml中標記有點特殊
<activity-alias />,這個標簽的意思是這個Activity是另一個Activity的別名,真實的Activity在標簽中用“android:targetActivity = OutgoingCallBroadcast”標出,所以 “ACTION_CALL_PRIVILEGED”啟動的 PrivilegedOutgoingCallBroadcast 所對應的真實“身份”是 “OutgoingCallBroadcast”。

2.這個時候電話的數據已經流到OutgoingCallBroadcast.java中了。
在OutgoingCallBroadcast.java的onCreate()方法中有:
復制代碼 代碼如下:
<PRE class=java name="code">protected void onCreate(Bundle icicle) {
.......
Intent intent = getIntent();
........
String action = intent.getAction();
.......
final boolean emergencyNum = (number != null) && PhoneNumUtils.isEmergencyNumber(number);//判斷號碼是否是緊急號碼
.......
if (Intent.ACTION_CALL_PRIVILEGED.equals(action)) {
action = emergencyNum ? Intent.ACTION_CALL_EMERGENCY : Intent.ACTION_CALL;
intent.setAction(action);
}
.......
intent.setClass(this, InCallScreen.class);
startActivity(intent);
}</PRE><P></P>
<PRE></PRE>
在這個方法中,判斷如果所收到的ACTION是“ACTION_CALL_PRIVILEGED”,那麼根據所輸入的號碼是否是緊急號碼進行轉換,如果是緊急號碼,則ACTION = Intent.ACTION_CALL_EMERGENCY,否則ACTION = Intent.ACTION_CALL,並啟動轉換Activity :InCallScreen.java
<P></P>
<P>3. InCallScreen.java依然在目錄/packeges/Phone/src/com/android/phone下。</P>
<P>InCallScreen的onCreate中調用initInCallScreen初始化打電話界面,並調用registerForPhoneStates注冊電話狀態監聽.<BR>
</P>
<P>在onNewIntent()方法中有:</P>
<P><PRE class=java name="code">protected void onNewIntent(Intent intent) {
..........
String action = intent.getAction();
..........
else if (action.equals(Intent.ACTION_CALL) || action.equals(Intent.ACTION_CALL_EMERGENCY)) {
..........
InCallInitStatus status = placeCall(intent);
}
}
//placeCall
private InCallInitStatus placeCall(Intent intent) {
..............
int callStatus = PhoneUtils.placeCall(........);
}</PRE>InCallScreen.java中的placeCall方法調用PhoneUtils.java文件的placeCall方法。<BR>
<P></P>
<P>4. PhoneUtils.java依然在目錄/packeges/Phone/src/com/android/phone下。</P>
<P><PRE class=java name="code">public static int placeCall(...) {
Connection connection;
connection = PhoneApp.getInstance().mCM.dial(phone, numberToDial);
}</PRE>繼續追蹤,在PhoneApp.java中發現,mCM是CallManager.java類的一個對象,而CallManager.java是屬於frameworks層的,所以,這個時候數據流已經進入frameworks.<P></P>
<P>5. 進入/frameworks/base/telephony/java/com/android/internal/telephony目錄。</P>
<P>在CallManager.java的dial()方法中,有:</P>
<P><PRE class=java name="code"><SPAN ></SPAN><PRE class=java name="code">public Connection dial(Phone phone, String dialNumber) throws CallStateException {
Phone basePhone = getPhoneBase(phone);
Connection result;
<SPAN >result = basePhone.dial(dialString);</SPAN>
........
}
private static Phone getPhoneBase(Phone phone) {
if (phone instanceof PhoneProxy) {
<SPAN >return phone.getForegroundCall().getPhone();</SPAN>
}
return phone;
}</PRE><P></P>
<PRE></PRE>
<PRE class=java name="code"><SPAN >繼續追蹤會發現:</SPAN></PRE><PRE class=java name="code"><SPAN >PhoneBase.java抽象類實現了接口Phone.java,而GSMPhone.java又實現了抽象類PhoneBase,所以:</SPAN></PRE>
<P></P>
<P>上述代碼中:phone.getForegroundCall()實際相當於GSMPhone對象執行了getForegroundCall()方法。</P>
<P>6. 繼續追蹤GSMPhone.java,該類位於/frameworks/base/telephony/java/com/android/internal/telephony/gsm/下。</P>
<P><PRE class=java name="code">GSMPhone.java:
GsmCallTracker mCT;
public GsmCall getForegroundCall() {
return mCT.foregroundCall;
}</PRE>可以看出getForegroundCall()函數繼續調用GsmCallTracker.java的foregroundCall屬性。<P></P>
<P>7.GsmCallTracker.java位於/frameworks/base/telephony/java/com/android/internal/telephony/gsm/下.</P>
<P><PRE class=cpp name="code">GsmCallTracker.java:
GSMCall foregroundCall = new GSMCall(this);</PRE><P></P>
<P>打開GSMCall.java,找到getPhone()方法,發現:</P>
<P><PRE class=java name="code">GSMCallTracker owner;
public Phone getPhone() {
return owner.phone;
}</PRE><P></P>
<P>而在GSMCallTracker.java中有如下聲明:</P>
<P><PRE class=cpp name="code">GSMPhone phone;</PRE><P></P>
<P><SPAN >到此,我們得出一下結論:第5部分標記紅色的代碼所返回的就是GSMPhone的對象,</SPAN><SPAN >進一步可以得出,第5部分藍色標記的代碼即是調用了GSMPhone對象的dial方法。</SPAN></P>
<P>8. 在GSMPhone.java中:</P>
<P><PRE class=java name="code">GSMCallTracker mCT;
public Connection dial(String dialString) throws CallStateException {
return dial(dialString, null);
}
public Connection dial(String dialString, UUSInfo uusInfo) throws CallStateException {
.......
mCT.dial(.......);
}</PRE><P></P>
<P>繼續調用GSMCallTracker.java中的dial()方法:</P>
<P><PRE class=cpp name="code">GSMCallTracker.java:
GSMCallTracker(GSMPhone phone) {
cm = phone.mCM;
}
Connection dial(String dialString, int clirMode, UUSInfo uusInfo) {
<SPAN >cm.dial(........);</SPAN>
}</PRE>追蹤mCM,發現 :<P></P>
<P>public CommandsInterface mCM;</P>
<P>所以GSMCallTracker持有CommandsInterface對象,即RIL.Java類的對象,所以"cm.dial(....)"即是調用RIL類對象的dial()方法。</P>
<P>9. RIL.java</P>
<P>BOSS出現。</P>
<P>RIL對象負責把客戶端的通話請求按照一定的格式發送給"rild"socket,至此,請求過程完畢。</P>
</PRE>
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved