<span style="font-size:14px;">case STOP_RING:
if (DBG) log("mRingHandler: STOP_RING...");
r = (Ringtone) msg.obj;
if (r != null) {
r.stop();
} else {
if (DBG) log("- STOP_RING with null ringtone! msg = " + msg);
}
getLooper().quit();
break;</span>
这边是当对方接听前挂电话或者对方没有能力接电话后,本机的提示音会随之变化,关键在与这个stop——ring这个消息的来源是
<span style="font-size:14px;"> public void handleMessage(Message msg) {
Ringtone r = null;
switch (msg.what) {
case PLAY_RING_ONCE:</span>
关键的问题在与找到这个message是在哪里被发的,看起来所有的message在发送的时候都会带上特定的handle。
void stopRing() {
synchronized (this) {
if (DBG) log("stopRing()...");
try {
mPowerManager.setAttentionLight(false, 0x00000000);
} catch (RemoteException ex) {
// the other end of this binder call is in the system process.
}
if (mRingHandler != null) {
mRingHandler.removeCallbacksAndMessages(null);
Message msg = mRingHandler.obtainMessage(STOP_RING);
msg.obj = mRingtone;
<span style="color:#66FF99;"> <span style="color:#FF6666;"> mRingHandler.sendMessage(msg);</span></span>
PhoneUtils.setAudioMode();
mRingThread = null;
mRingHandler = null;
mRingtone = null;
mFirstRingEventTime = -1;
mFirstRingStartTime = -1;
} else {
if (DBG) log("- stopRing: null mRingHandler!");
}
if (mVibratorThread != null) {
if (DBG) log("- stopRing: cleaning up vibrator thread...");
mContinueVibrating = false;
mVibratorThread = null;
}
// Also immediately cancel any vibration in progress.
mVibrator.cancel();
}
}
看msg
public void handleMessage(Message msg) {
switch(msg.what) {
case CallStateMonitor.PHONE_NEW_RINGING_CONNECTION:
Log.i(TAG, "[CORE][MODELER] PHONE_NEW_RINGING_CONNECTION");
// We let the CallNotifier handle the new ringing connection first. When the custom
// ringtone and send_to_voicemail settings are retrieved, CallNotifier will directly
// call CallModeler's onNewRingingConnection.
break;
case CallStateMonitor.PHONE_DISCONNECT:
Log.i(TAG, "[CORE][MODELER] PHONE_DISCONNECT");
onDisconnect((Connection) ((AsyncResult) msg.obj).result);
break;
case CallStateMonitor.PHONE_UNKNOWN_CONNECTION_APPEARED:
// fall through
case CallStateMonitor.PHONE_STATE_CHANGED:
Log.i(TAG, "[CORE][MODELER] PHONE_STATE_CHANGED/PHONE_UNKNOWN_CONNECTION_APPEARED");
onPhoneStateChanged((AsyncResult) msg.obj);
break;
case CallStateMonitor.PHONE_ON_DIAL_CHARS:
Log.i(TAG, "[CORE][MODELER] PHONE_ON_DIAL_CHARS");
onPostDialChars((AsyncResult) msg.obj, (char) msg.arg1);
break;
case CallStateMonitor.PHONE_SUPP_SERVICE_NOTIFY:
Log.i(TAG, "[CORE][MODELER] PHONE_SUPP_SERVICE_NOTIFY");
if (msg.obj != null && ((AsyncResult) msg.obj).result != null) {
mSuppSvcNotification =
(SuppServiceNotification) (((AsyncResult) msg.obj).result);
if (mSuppSvcNotification.code == SuppServiceNotification.MT_CODE_CALL_ON_HOLD
|| mSuppSvcNotification.code
== SuppServiceNotification.MT_CODE_CALL_RETRIEVED) {
onPhoneStateChanged(null);
}
}
break;
case CallStateMonitor.PHONE_ACTIVE_SUBSCRIPTION_CHANGE:
Log.i(TAG, "[CORE][MODELER] PHONE_ACTIVE_SUBSCRIPTION_CHANGE");
onActiveSubChanged((AsyncResult) msg.obj);
break;
default:
break;
}
}
关于
public void onCreate() {
super.onCreate();
mCM = CallManager.getInstance();
if (TelephonyConstants.IS_DSDS) {
mCM1 = CallManager.getInstance();
mCM2 = CallManager.getInstance2();
}
mCM.getDefaultPhone().registerForServiceStateChanged(mHandler,
SERVICE_STATE_CHANGED, null);
mCM.registerForPreciseCallStateChanged(mHandler,
PRECISE_CALL_STATE_CHANGED, null);