The program for modifying functions is the source code of MTK, and the source codes for other programs are for reference only.
1. In the mtk source code, there is a special macro control to switch some functions, just like the call function this time. You can find this MTK_TB_APP_CALL_FORCE_SPEAKER_ON in the device.mk file. When it is yes, the hands-free call is only hands-free when dialing, and it is not hands-free when answering.
--- 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. Since it is not in the hands-free state when answering, the following modifications are made.
the first method:
--- 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
The second method:
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: