packages\services\Telephony\src\com\android\phone\Ringer.java
private void makeLooper() {
if (mRingThread == null) {mRingThread = new Worker("ringer");
if (mRingThread.getLooper() == null) {
return ;
}
mRingHandler = new Handler(mRingThread.getLooper()) {
@Override
public void handleMessage(Message msg) {
Ringtone r = null;
switch (msg.what) {
case PLAY_RING_ONCE:
if (DBG) log("mRingHandler: PLAY_RING_ONCE...");
if (mRingtone == null && !hasMessages(STOP_RING)) {
// create the ringtone with the uri
if (DBG) log("creating ringtone: " + mCustomRingtoneUri);
r = RingtoneManager.getRingtone(mContext, mCustomRingtoneUri);
synchronized (Ringer.this) {
if (!hasMessages(STOP_RING)) {
mRingtone = r;
}
}
}
r = mRingtone;
// add by xuxin20130906 to fix no ring for incoming call when first reboot +
boolean shouldRing = (!hasMessages(STOP_RING));
if(shouldRing){
shouldRing){
if (r != null && !r.isPlaying() && !isMpPlaying() ) {
if(begintoRing){
PhoneUtils.setAudioMode();
playRingbyForce();
synchronized (Ringer.this) {
if (mFirstRingStartTime < 0) {
mFirstRingStartTime = SystemClock.elapsedRealtime();
}
}
}else{
begintoRing = true;
PhoneUtils.setAudioMode();
r.play();
synchronized (Ringer.this) {
if (mFirstRingStartTime < 0) {
mFirstRingStartTime = SystemClock.elapsedRealtime();
}
}
}
}else if((r == null || (r!=null && !r.isPlaying())) && !isMpPlaying()){
PhoneUtils.setAudioMode();
playRingbyForce();
synchronized (Ringer.this) {
if (mFirstRingStartTime < 0) {
mFirstRingStartTime = SystemClock.elapsedRealtime();
}
}
}
// add by xuxin20130906 to fix no ring for incoming call when first reboot -
}
break;
case STOP_RING:
// add by xuxin20130906 to fix no ring for incoming call when first reboot
begintoRing = false;
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);
}
// add by xuxin20130906 to fix no ring for incoming call when first reboot
stopRingbyForce();
getLooper().quit();
break;
}
}
};
}
}