修改功能的方案为MTK的源码,其他方案源码仅供参考。
1.在mtk源码当中有专门的宏控进行开关一些功能,就像这次的打电话面提功能。在device.mk文件当中可以搜到这个MTK_TB_APP_CALL_FORCE_SPEAKER_ON,当它为yes的时候通话免提只是拨打的时候免提,接听的时候并不是免提状态。
--- a/alps/device/mediateksample/xx/ProjectConfig.mk +++ b/alps/device/mediateksample/xx/ProjectConfig.mk @@ -539,6 +539,7 @@ MTK_SMART_CHARGING = no MTK_ADSP_VA_SUPPORT = no MTK_CAM_BSS_SUPPORT = 0 MTK_LK_VERSION = lk +MTK_TB_APP_CALL_FORCE_SPEAKER_ON=yes
2.因接听的时候并不是免提状态,所以有以下修改。
第一种方法:
--- a/alps/frameworks/base/telecomm/java/android/telecom/InCallService.java +++ b/alps/frameworks/base/telecomm/java/android/telecom/InCallService.java @@ -40,6 +40,10 @@ import com.android.internal.telecom.IInCallService; import java.util.Collections; import java.util.List; +import android.telecom.CallAudioState; +import android.telephony.PhoneStateListener; +import android.telephony.TelephonyManager; +import android.content.Context; /** * This service is implemented by an app that wishes to provide functionality for managing * phone calls. @@ -230,6 +234,40 @@ public abstract class InCallService extends Service { private static final int MSG_ON_HANDOVER_FAILED = 12; private static final int MSG_ON_HANDOVER_COMPLETE = 13; + //Added by lwz start + @Override + public void onCreate() { + super.onCreate(); + MyPhoneStateListener phonehoneStateListener=new MyPhoneStateListener(); + TelephonyManager mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); + mTelephonyManager.listen(phonehoneStateListener,PhoneStateListener.LISTEN_CALL_STATE); + } + + @Override + public void onDestroy() { + super.onDestroy(); + } + + private class MyPhoneStateListener 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); + } + } + //Added by lwz end + /** Default Handler used to consolidate binder method calls onto a single thread. */ private final Handler mHandler = new Handler(Looper.getMainLooper()) { @Override
第二种方法:
index fe2a32b..101b15c 100644 --- a/alps/frameworks/av/services/audiopolicy/enginedefault/src/Engine.cpp +++ b/alps/frameworks/av/services/audiopolicy/enginedefault/src/Engine.cpp @@ -295,7 +295,8 @@ DeviceVector Engine::getDevicesForStrategyInt(legacy_strategy strategy, AUDIO_DEVICE_OUT_AUX_DIGITAL, AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET}); if (!devices.isEmpty()) break; } - devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_EARPIECE); + //devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_EARPIECE); + devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_SPEAKER); break; case AUDIO_POLICY_FORCE_SPEAKER: