修改文件:
frameworks-base/telecomm/java/android/telecom/InCallService.java
在此处的onCreate方法中添加一个PhoneStateListener用以监听Phone状态并进而控制AudioRoute。
FYI:
@Override
public void onCreate() {
super.onCreate();
SpeakerPhoneStateListener speakerPhoneStateListener=new SpeakerPhoneStateListener();
TelephonyManager mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
mTelephonyManager.listen(speakerPhoneStateListener,PhoneStateListener.LISTEN_CALL_STATE);
}
private class SpeakerPhoneStateListener extends PhoneStateListener{
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
setAudioRoute(CallAudioState.ROUTE_EARPIECE);
break;
case TelephonyManager.CALL_STATE_RINGING:
setAudioRoute(CallAudioState.ROUTE_SPEAKER);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
setAudioRoute(CallAudioState.ROUTE_SPEAKER);
default:
break;
}
super.onCallStateChanged(state, incomingNumber);
}
}
MTK平台修改ro也能达到同样效果,将MTK_TB_APP_CALL_FORCE_SPEAKER_ON配置为yes即可。 PS:这种方案MO的时候生效,MT的时候不生效。根据实际需求修改即可。
ifeq ($(strip $(MTK_TB_APP_CALL_FORCE_SPEAKER_ON)), yes)
PRODUCT_PROPERTY_OVERRIDES += ro.vendor.mtk_tb_call_speaker_on=1
endif
|