Play music in the background of the android mobile phone, set an alarm clock, make a call, and after the phone is hung up, the alarm and music will sound at the same time.
Modify:
Frameworks \ base \ media \ java \ android \ media \ MediaFocusControl. java:
1. import packages:
Import com. android. internal. telephony. ITelephony;
Import android. OS. ServiceManager;
2. added the getPhoneCallState () method for obtaining the current Phone Call State ():
Private int getPhoneCallState (){
Int phoneCallState = TelephonyManager. CALL_STATE_IDLE;
TelephonyManager telephonyManager = (TelephonyManager) mContext. getSystemService (Context. TELEPHONY_SERVICE );
ITelephony telephonyService = ITelephony. Stub. asInterface (ServiceManager. getService (Context. TELEPHONY_SERVICE ));
If (telephonyService! = Null ){
Log. w (TAG, "getPhoneCallState: mTelephonyService! = Null ");
Try {
PhoneCallState = telephonyService. getPreciseCallState ();
Log. w (TAG, "getPhoneCallState: telephonyService. getPreciseCallState () =" + phoneCallState );
} Catch (RemoteException ex ){
If (telephonyManager! = Null ){
PhoneCallState = telephonyManager. getCallState ();
Log. w (TAG, "getPhoneCallState: telephonyManager. getCallState () =" + phoneCallState );
}
Log. w (TAG, "Catch exception when getPreciseCallState: ex ="
+ Ex. getMessage ());
}
} Else {
Log. w (TAG, "getPhoneCallState: telephonyService = null ");
If (telephonyManager! = Null ){
PhoneCallState = telephonyManager. getCallState ();
Log. w (TAG, "getPhoneCallState: telephonyManager. getCallState () =" + phoneCallState );
}
}
Log. w (TAG, "getPhoneCallState: phoneCallState =" + phoneCallState );
Return phoneCallState;
}
3. Modify
Private boolean canReassignAudioFocus (){
// Focus requests are rejected during a phone call or when the phone is ringing
// This is equivalent to IN_VOICE_COMM_FOCUS_ID having the focus
If (! MFocusStack. isEmpty () & mFocusStack. peek (). hasSameClient (IN_VOICE_COMM_FOCUS_ID )){
Return false;
}
Return true;
}
Is
Private boolean canReassignAudioFocus (){
// Focus requests are rejected during a phone call or when the phone is ringing
// This is equivalent to IN_VOICE_COMM_FOCUS_ID having the focus
If (! MFocusStack. isEmpty () & mFocusStack. peek (). hasSameClient (IN_VOICE_COMM_FOCUS_ID) & (getPhoneCallState ()! = TelephonyManager. CALL_STATE_IDLE )){
Log. w (TAG, "canReassignAudioFocus: return false ");
Return false;
}
Log. w (TAG, "canReassignAudioFocus: return true ");
Return true;
}