1.来电流程分析
PhoneApp在初始化时会实例CallNotifier对象,Callnotifier主要是对电话状态的监听,通知事件
PhoneApp创建一个CallNotifier
// Create the CallNotifer singleton, which handles
// asynchronous events from the telephony layer (like
// launching the incoming-call UI when an incoming call comes
// in.)
notifier = CallNotifier.init(this, phone, ringer, mBtHandsfree, new CallLogAsync());
PhoneApp创建一个CallNotifier
// Create the CallNotifer singleton, which handles
// asynchronous events from the telephony layer (like
// launching the incoming-call UI when an incoming call comes
// in.)
notifier = CallNotifier.init(this, phone, ringer, mBtHandsfree, new CallLogAsync());
Callnotifier实现对电话状态的监听
/** Private constructor; @see init() */
private CallNotifier(PhoneApp app, Phone phone, Ringer ringer,
BluetoothHandsfree btMgr, CallLogAsync callLog) {
mApplication = app;
mCM = app.mCM;
mCallLog = callLog;
mAudioManager = (AudioManager) mApplication.getSystemService(Context.AUDIO_SERVICE);
<SPAN style="FONT-SIZE: 18px; COLOR: #cc0000"><STRONG>registerForNotifications();//状态监听</STRONG></SPAN>
/** Private constructor; @see init() */
private CallNotifier(PhoneApp app, Phone phone, Ringer ringer,
BluetoothHandsfree btMgr, CallLogAsync callLog) {
mApplication = app;
mCM = app.mCM;
mCallLog = callLog;
mAudioManager = (AudioManager) mApplication.getSystemService(Context.AUDIO_SERVICE);
registerForNotifications();//状态监听
registerForNotifications方法注册电话状态监听
private void registerForNotifications() {
private void registerForNotifications() {
view plaincopyprint?mCM.registerForNewRingingConnection(this, PHONE_NEW_RINGING_CONNECTION, null);
mCM.registerForNewRingingConnection(this, PHONE_NEW_RINGING_CONNECTION, null);[java] view plaincopyprint? mCM.registerForPreciseCallStateChanged(this, PHONE_STATE_CHANGED, null);
mCM.registerForDisconnect(this, PHONE_DISCONNECT, null);
mCM.registerForUnknownConnection(this, PHONE_UNKNOWN_CONNECTION_APPEARED, null);
mCM.registerForIncomingRing(this, PHONE_INCOMING_RING, null);
mCM.registerForCdmaOtaStatusChange(this, EVENT_OTA_PROVISION_CHANGE, null);
mCM.registerForCallWaiting(this, PHONE_CDMA_CALL_WAITING, null);
mCM.registerForDisplayInfo(this, PHONE_STATE_DISPLAYINFO, null);
mCM.registerForSignalInfo(this, PHONE_STATE_SIGNALINFO, null);
mCM.registerForInCallVoicePrivacyOn(this, PHONE_ENHANCED_VP_ON, null);
mCM.registerForInCallVoicePrivacyOff(this, PHONE_ENHANCED_VP_OFF, null);
mCM.registerForRingbackTone(this, PHONE_RINGBACK_TONE, null);
mCM.registerForResendIncallMute(this, PHONE_RESEND_MUTE, null);
}
mCM.registerForPreciseCallStateChanged(this, PHONE_STATE_CHANGED, null);
mCM.registerForDisconnect(this, PHONE_DISCONNECT, null);
mCM.registerForUnknownConnection(this, PHONE_UNKNOWN_CONNECTION_APPEARED, null);
mCM.registerForIncomingRing(this, PHONE_INCOMING_RING, null);
mCM.registerForCdmaOtaStatusChange(this, EVENT_OTA_PROVISION_CHANGE, null);
mCM.registerForCallWaiting(this, PHONE_CDMA_CALL_WAITING, null);
mCM.registerForDisplayInfo(this, PHONE_STATE_DISPLAYINFO, null);
mCM.registerForSignalInfo(this, PHONE_STATE_SIGNALINFO, null);
mCM.registerForInCallVoicePrivacyOn(this, PHONE_ENHANCED_VP_ON, null);
mCM.registerForInCallVoicePrivacyOff(this, PHONE_ENHANCED_VP_OFF, null);
mCM.registerForRingbackTone(this, PHONE_RINGBACK_TONE, null);
mCM.registerForResendIncallMute(this, PHONE_RESEND_MUTE, null);
}
mCM.registerForNewRingingConnection(this, PHONE_NEW_RINGING_CONNECTION, null); 监听来电,在handleMessage函数内处理
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case PHONE_NEW_RINGING_CONNECTION:
log("RINGING... (new)");
onNewRingingConnection((AsyncResult) msg.obj);
mSilentRingerRequested = false;
break;
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case PHONE_NEW_RINGING_CONNECTION:
log("RINGING... (new)");
onNewRingingConnection((AsyncResult) msg.obj);
mSilentRingerRequested = false;
break;转到onNewRingingConnection处理来电,最后转到showIncomingCall函数启动InCallScreen界面,当然还有处理一些状态更新,响铃之类的
2.拨号流程分析
拨号主要是从拨号盘按下call按键开始,进入OutgoingCallBroadcaster处理,
3.电话状态判断
private boolean isIdle(){
boolean isIdle = false;
TelephonyManager tm = (TelephonyManager) getSystemService("phone");
if(tm != null){
isIdle = (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE);
}
return isIdle;
}