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();
- }
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));
- .............
- }
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">protectedvoid 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">protectedvoid 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">publicstatic 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 style="font-family: Arial, Verdana, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"></span><pre class="java" name="code">public Connection dial(Phone phone, String dialNumber) throws CallStateException {
- Phone basePhone = getPhoneBase(phone);
- Connection result;
- <span style="color: rgb(51, 51, 255);">result = basePhone.dial(dialString);</span>
- ........
- }
- private static Phone getPhoneBase(Phone phone) {
- if (phone instanceof PhoneProxy) {
- <span style="color: rgb(255, 0, 0);">return phone.getForegroundCall().getPhone();</span>
- }
- return phone;
- }</pre><p></p>
- <pre></pre>
- <pre class="java" name="code"><span style="font-family: Arial, Verdana, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">继续追踪会发现:</span></pre><preclass="java" name="code"><span style="font-family: Arial, Verdana, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">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 style="color: rgb(255, 0, 0);">到此,我们得出一下结论:第5部分标记红色的代码所返回的就是GSMPhone的对象,</span><span style="color: rgb(51, 51, 255);">进一步可以得出,第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 style="color: rgb(255, 0, 0);">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>
- <p><br>
- </p>
- <p><br>
- </p>
- <p><br>
- </p>
- <p><br>
- </p>
- <p><br>
- </p>
- <p><br>
- </p>
- </pre>