复制代码 代码如下:
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>
总结
以上是内存溢出为你收集整理的Android中打电话的数据流程分析全部内容,希望文章能够帮你解决Android中打电话的数据流程分析所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)