sm7125-common: Fixup BT SCO phone calls

Partial revert of 9968055bb8.

Change-Id: I4c087f2130591b4bb4cbcfc6f323a2d2401211eb
fourteen-wip
Simon1511 1 year ago
parent 62f0858f85
commit 2e4f5d511c
  1. 33
      audio/SamsungAudio/src/android/hardware/media/SamsungAudioService.java
  2. 61
      audio/configs/audio_policy_configuration.xml
  3. 144
      audio/impl/ParametersUtil.cpp
  4. 2
      sepolicy/vendor/property_contexts

@ -26,19 +26,14 @@ import android.os.Handler;
import android.media.AudioManager;
import android.media.AudioDeviceInfo;
import android.media.AudioSystem;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
public class SamsungAudioService extends Service {
private static final String TAG = "SamsungAudioService";
private static final boolean DEBUG = false;
private boolean hasBTcallSet = false;
private Handler mHandler;
private static Runnable mRunnable;
private AudioManager mAudioManager;
private BluetoothManager mBluetoothManager;
private BluetoothAdapter mBluetoothAdapter;
@Override
public void onCreate() {
@ -46,39 +41,11 @@ public class SamsungAudioService extends Service {
mAudioManager = getSystemService(AudioManager.class);
mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = mBluetoothManager.getAdapter();
mHandler = new Handler();
mRunnable = new Runnable() {
public void run() {
if (DEBUG) Log.d(TAG, "onCreate: " + TAG + " is running");
if (!mBluetoothAdapter.isEnabled()) {
if (DEBUG) Log.d(TAG, "Bluetooth is not enabled");
SystemProperties.set("vendor.audio.a2dp.connected", "false");
}
if (mAudioManager.getMode() != AudioManager.MODE_IN_CALL && mAudioManager.getMode() != AudioManager.MODE_IN_COMMUNICATION && hasBTcallSet) {
if (DEBUG) Log.d(TAG, "Call ended, reset everything");
hasBTcallSet = false;
SystemProperties.set("vendor.audio.call.switched", "false");
AudioSystem.setParameters("reset_a2dp=1");
}
if (SystemProperties.get("vendor.audio.a2dp.connected").equals("true") && mAudioManager.getMode() == AudioManager.MODE_IN_CALL
&& mBluetoothAdapter.isEnabled()) {
if (hasBTcallSet) {
SystemProperties.set("vendor.audio.call.switched", "true");
}
if (!hasBTcallSet) {
if (DEBUG) Log.d(TAG, "Setting A2DP parameter");
AudioSystem.setParameters("a2dp_call=1");
hasBTcallSet = true;
SystemProperties.set("vendor.audio.call.switched", "false");
}
}
if (mAudioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) {
if (mAudioManager.getCommunicationDevice().getType() == AudioDeviceInfo.TYPE_BLUETOOTH_SCO

@ -8,10 +8,11 @@
<module name="primary" halVersion="3.0">
<attachedDevices>
<item>Earpiece</item>
<item>Telephony Tx</item>
<item>Speaker</item>
<item>Built-In Mic</item>
<item>Built-In Back Mic</item>
<item>Voice Call Mic</item>
<item>Telephony Rx</item>
</attachedDevices>
<defaultOutputDevice>Speaker</defaultOutputDevice>
@ -41,6 +42,25 @@
samplingRates="8000,11025,12000,16000,22050,24000,32000,44100,48000,88200,96000,176400,192000"
channelMasks="AUDIO_CHANNEL_IN_STEREO,AUDIO_CHANNEL_INDEX_MASK_2,AUDIO_CHANNEL_IN_5POINT1,AUDIO_CHANNEL_INDEX_MASK_6,AUDIO_CHANNEL_IN_7POINT1,AUDIO_CHANNEL_INDEX_MASK_8"/>
</mixPort>
<mixPort name="voice_tx" role="source">
<profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
samplingRates="8000,16000,48000" channelMasks="AUDIO_CHANNEL_OUT_MONO,AUDIO_CHANNEL_OUT_STEREO"/>
</mixPort>
<mixPort name="voip_rx" role="source"
flags="AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_VOIP_RX">
<profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
samplingRates="8000,16000,32000,48000" channelMasks="AUDIO_CHANNEL_OUT_MONO,AUDIO_CHANNEL_OUT_STEREO"/>
</mixPort>
<mixPort name="voip_tx" role="sink"
flags="AUDIO_INPUT_FLAG_VOIP_TX">
<profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
samplingRates="8000,16000,32000,48000" channelMasks="AUDIO_CHANNEL_IN_MONO"/>
</mixPort>
<mixPort name="voice_rx" role="sink">
<profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
samplingRates="8000,16000,48000" channelMasks="AUDIO_CHANNEL_IN_MONO,AUDIO_CHANNEL_IN_STEREO"/>
</mixPort>
<mixPort name="hifi_playback" role="source" />
<mixPort name="hifi_input" role="sink" />
</mixPorts>
@ -62,9 +82,21 @@
<profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
</devicePort>
<devicePort tagName="Bt Sco All" role="sink" type="AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET">
<profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
<devicePort tagName="BT SCO" type="AUDIO_DEVICE_OUT_BLUETOOTH_SCO" role="sink">
<profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
samplingRates="8000,16000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
</devicePort>
<devicePort tagName="BT SCO Headset" type="AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET" role="sink">
<profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
samplingRates="8000,16000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
</devicePort>
<devicePort tagName="BT SCO Car Kit" type="AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT" role="sink">
<profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
samplingRates="8000,16000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
</devicePort>
<devicePort tagName="Telephony Tx" type="AUDIO_DEVICE_OUT_TELEPHONY_TX" role="sink">
<profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
samplingRates="8000,16000" channelMasks="AUDIO_CHANNEL_OUT_MONO,AUDIO_CHANNEL_OUT_STEREO"/>
</devicePort>
<devicePort tagName="Aux Device Out" role="sink" type="AUDIO_DEVICE_OUT_AUX_DIGITAL">
<profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
@ -105,10 +137,9 @@
samplingRates="8000,11025,12000,16000,22050,24000,32000,44100,48000"
channelMasks="AUDIO_CHANNEL_IN_MONO,AUDIO_CHANNEL_IN_STEREO,AUDIO_CHANNEL_IN_FRONT_BACK"/>
</devicePort>
<devicePort tagName="Voice Call Mic" type="AUDIO_DEVICE_IN_VOICE_CALL" role="source">
<devicePort tagName="Telephony Rx" type="AUDIO_DEVICE_IN_TELEPHONY_RX" role="source">
<profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
samplingRates="8000,11025,12000,16000,22050,24000,32000,44100,48000"
channelMasks="AUDIO_CHANNEL_IN_MONO,AUDIO_CHANNEL_IN_STEREO,AUDIO_CHANNEL_IN_FRONT_BACK"/>
samplingRates="8000,16000,48000" channelMasks="AUDIO_CHANNEL_IN_MONO"/>
</devicePort>
<devicePort tagName="FM Mic" type="AUDIO_DEVICE_IN_FM_TUNER" role="source">
<profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
@ -138,10 +169,20 @@
sources="USB Device In,USB Headset In"/>
<route type="mix" sink="hifi_input"
sources="USB Device In,USB Headset In"/>
<route type="mix" sink="Bt Sco All"
sources="primary-out,fast"/>
<route type="mix" sink="BT SCO"
sources="primary-out,fast,voip_rx"/>
<route type="mix" sink="BT SCO Headset"
sources="primary-out,fast,voip_rx"/>
<route type="mix" sink="BT SCO Car Kit"
sources="primary-out,fast,voip_rx"/>
<route type="mix" sink="Telephony Tx"
sources="voice_tx"/>
<route type="mix" sink="voice_rx"
sources="Telephony Rx"/>
<route type="mix" sink="voip_tx"
sources="Built-In Mic,Built-In Back Mic,Bt Sco Headset Mic,USB Device In,USB Headset In,Wired Headset Mic"/>
<route type="mix" sink="primary-in"
sources="Built-In Mic,Built-In Back Mic,Wired Headset Mic,Bt Sco Headset Mic,Aux Device In,Voice Call Mic,FM Mic,USB Device In,USB Headset In"/>
sources="Built-In Mic,Built-In Back Mic,Wired Headset Mic,Bt Sco Headset Mic,Aux Device In,FM Mic,USB Device In,USB Headset In"/>
</routes>
</module>

@ -215,106 +215,6 @@ void setMixerValueByNameString(mixer *mixer, const char *name, const char *value
}
}
void setBTincall(bool enabled, char *slot) {
const auto mixer = mixer_open(0);
if (mixer == nullptr) {
ALOGE("Failed to open mixer");
return;
}
if (enabled) {
ALOGD("Fixing BT in-call mixers");
setMixerValueByName(mixer, "QUIN_MI2S_RX_Voice Mixer VoiceMMode1", 0);
setMixerValueByName(mixer, "QUIN_MI2S_RX_Voice Mixer VoiceMMode2", 0);
setMixerValueByName(mixer, "VoiceMMode1_Tx Mixer TX_CDC_DMA_TX_3_MMode1", 0);
setMixerValueByName(mixer, "VoiceMMode2_Tx Mixer TX_CDC_DMA_TX_3_MMode2", 0);
setMixerValueByNameString(mixer, "SLIM7_RX ADM Channels", "Two");
setMixerValueByName(mixer, "TAS256X IVSENSE ENABLE", 0);
setMixerValueByName(mixer, "BT SOC status", 1);
setMixerValueByName(mixer, "Voip_Tx Mixer TX_CDC_DMA_TX_3_Voip", 0);
setMixerValueByName(mixer, "QUIN_MI2S_RX_Voice Mixer Voip", 0);
setMixerValueByName(mixer, "TAS256X RECEIVER ENABLE LEFT", 0);
setMixerValueByName(mixer, "SmartPA Mute", 1);
setMixerValueByNameString(mixer, "TX_CDC_DMA_TX_3 Channels", "One");
setMixerValueByName(mixer, "TAS256X ASI Left Switch", 0);
setMixerValueByNameString(mixer, "TAS256X ASI1 SEL LEFT", "I2C offset");
setMixerValueByName(mixer, "TAS256X AMP OUTPUT LVL LEFT", 20);
setMixerValueByName(mixer, "Compress Gapless Playback", 1);
setMixerValueByName(mixer, "TX_AIF1_CAP Mixer DEC0", 0);
setMixerValueByName(mixer, "TX_AIF1_CAP Mixer DEC1", 0);
setMixerValueByNameString(mixer, "TX SMIC MUX0", "ZERO");
setMixerValueByNameString(mixer, "TX SMIC MUX1", "ZERO");
setMixerValueByNameString(mixer, "TX DEC0 MUX", "MSM_DMIC");
setMixerValueByNameString(mixer, "TX DEC1 MUX", "MSM_DMIC");
setMixerValueByNameString(mixer, "EC Reference Bit Format", "S16_LE");
setMixerValueByName(mixer, "ADC1 Volume", 12);
setMixerValueByName(mixer, "ADC3 Volume", 12);
setMixerValueByNameString(mixer, "BT SampleRate", "KHZ_16");
setMixerValueByNameString(mixer, "BT SampleRate RX", "KHZ_16");
setMixerValueByNameString(mixer, "BT SampleRate TX", "KHZ_16");
setMixerValueByName(mixer, "ADC3_MIXER Switch", 0);
if (strcmp(slot, "0") == 0) {
setMixerValueByName(mixer, "SLIM_7_RX_Voice Mixer VoiceMMode1", 1);
setMixerValueByName(mixer, "VoiceMMode1_Tx Mixer SLIM_7_TX_MMode1", 1);
setMixerValueByName(mixer, "SLIM_7_RX_Voice Mixer VoiceMMode1", 0);
setMixerValueByName(mixer, "VoiceMMode1_Tx Mixer SLIM_7_TX_MMode1", 0);
setMixerValueByName(mixer, "SLIM_7_RX_Voice Mixer VoiceMMode1", 1);
setMixerValueByName(mixer, "VoiceMMode1_Tx Mixer SLIM_7_TX_MMode1", 1);
} else if (strcmp(slot, "1") == 0) {
setMixerValueByName(mixer, "SLIM_7_RX_Voice Mixer VoiceMMode2", 1);
setMixerValueByName(mixer, "VoiceMMode2_Tx Mixer SLIM_7_TX_MMode2", 1);
setMixerValueByName(mixer, "SLIM_7_RX_Voice Mixer VoiceMMode2", 0);
setMixerValueByName(mixer, "VoiceMMode2_Tx Mixer SLIM_7_TX_MMode2", 0);
setMixerValueByName(mixer, "SLIM_7_RX_Voice Mixer VoiceMMode2", 1);
setMixerValueByName(mixer, "VoiceMMode2_Tx Mixer SLIM_7_TX_MMode2", 1);
}
} else {
ALOGD("Resetting BT in-call mixers");
setMixerValueByNameString(mixer, "SLIM7_RX ADM Channels", "Zero");
setMixerValueByName(mixer, "TAS256X IVSENSE ENABLE", 1);
setMixerValueByName(mixer, "TAS256X RECEIVER ENABLE LEFT", 1);
setMixerValueByName(mixer, "SmartPA Mute", 0);
setMixerValueByNameString(mixer, "TX_CDC_DMA_TX_3 Channels", "Two");
setMixerValueByName(mixer, "TAS256X ASI Left Switch", 1);
setMixerValueByNameString(mixer, "TAS256X ASI1 SEL LEFT", "LeftRightDiv2");
setMixerValueByName(mixer, "TAS256X AMP OUTPUT LVL LEFT", 0);
setMixerValueByName(mixer, "TX_AIF1_CAP Mixer DEC0", 1);
setMixerValueByName(mixer, "TX_AIF1_CAP Mixer DEC1", 1);
setMixerValueByNameString(mixer, "TX SMIC MUX0", "ADC0");
setMixerValueByNameString(mixer, "TX SMIC MUX1", "ADC2");
setMixerValueByNameString(mixer, "TX DEC0 MUX", "SWR_MIC");
setMixerValueByNameString(mixer, "TX DEC1 MUX", "SWR_MIC");
setMixerValueByName(mixer, "EC Reference Bit Format", 0);
setMixerValueByName(mixer, "ADC1 Volume", 0);
setMixerValueByName(mixer, "ADC3 Volume", 0);
setMixerValueByName(mixer, "ADC3_MIXER Switch", 1);
setMixerValueByName(mixer, "SLIM_7_RX_Voice Mixer VoiceMMode1", 0);
setMixerValueByName(mixer, "VoiceMMode1_Tx Mixer SLIM_7_TX_MMode1", 0);
setMixerValueByName(mixer, "SLIM_7_RX_Voice Mixer VoiceMMode2", 0);
setMixerValueByName(mixer, "VoiceMMode2_Tx Mixer SLIM_7_TX_MMode2", 0);
if (strcmp(slot, "0") == 0) {
setMixerValueByName(mixer, "QUIN_MI2S_RX_Voice Mixer VoiceMMode1", 1);
setMixerValueByName(mixer, "VoiceMMode1_Tx Mixer TX_CDC_DMA_TX_3_MMode1", 1);
setMixerValueByName(mixer, "QUIN_MI2S_RX_Voice Mixer VoiceMMode1", 0);
setMixerValueByName(mixer, "VoiceMMode1_Tx Mixer TX_CDC_DMA_TX_3_MMode1", 0);
setMixerValueByName(mixer, "QUIN_MI2S_RX_Voice Mixer VoiceMMode1", 1);
setMixerValueByName(mixer, "VoiceMMode1_Tx Mixer TX_CDC_DMA_TX_3_MMode1", 1);
} else if (strcmp(slot, "1") == 0) {
setMixerValueByName(mixer, "QUIN_MI2S_RX_Voice Mixer VoiceMMode2", 1);
setMixerValueByName(mixer, "VoiceMMode2_Tx Mixer TX_CDC_DMA_TX_3_MMode2", 1);
setMixerValueByName(mixer, "QUIN_MI2S_RX_Voice Mixer VoiceMMode2", 0);
setMixerValueByName(mixer, "VoiceMMode2_Tx Mixer TX_CDC_DMA_TX_3_MMode2", 0);
setMixerValueByName(mixer, "QUIN_MI2S_RX_Voice Mixer VoiceMMode2", 1);
setMixerValueByName(mixer, "VoiceMMode2_Tx Mixer TX_CDC_DMA_TX_3_MMode2", 1);
}
}
mixer_close(mixer);
}
void setEarpieceVoipMixers(bool enabled) {
const auto mixer = mixer_open(0);
@ -420,18 +320,14 @@ void setBTVoipMixers(bool enabled) {
mixer_close(mixer);
}
void fixupMixers(int state) {
char a2dpcall[92];
void fixupMixers() {
char simslot[92];
char voipdevice[92];
char callswitched[92];
const char *ampstatus;
int voipstatus, btvoipstatus;
property_get("vendor.audio.a2dp.connected", a2dpcall, "false");
property_get("vendor.calls.slotid", simslot, "-1");
property_get("vendor.audio.voip.device", voipdevice, "none");
property_get("vendor.audio.call.switched", callswitched, "false");
voipstatus = getMixerValueByName("QUIN_MI2S_RX_Voice Mixer Voip");
ampstatus = getMixerValueString("TAS256X RECEIVER ENABLE LEFT");
@ -441,19 +337,6 @@ void fixupMixers(int state) {
ALOGD("voipstatus is %d", voipstatus);
ALOGD("bluetooth VoIP status is %d", btvoipstatus);
// BT in-call
if (strcmp(simslot, "0") == 0 || strcmp(simslot, "1") == 0) {
ALOGD("In phone call");
if (strcmp(a2dpcall, "true") == 0 && state == 1) {
ALOGD("In BT phone call");
setBTincall(true, simslot);
} else if (strcmp(a2dpcall, "true") == 0 && state == 2 && strcmp(callswitched, "true") == 0) {
setBTincall(false, simslot);
}
} else if (state == 3) {
setBTincall(false, simslot);
}
// VoIP call
if (voipstatus == 1 || btvoipstatus == 1) {
ALOGD("In VoIP call");
@ -489,24 +372,9 @@ Result ParametersUtil::setParametersImpl(const hidl_vec<ParameterValue>& context
params.add(String8("g_sco_samplerate"),
String8(parameters[i].value == AudioParameter::valueOn ? "16000" : "8000"));
}
if (parameters[i].key == "a2dp_call" || parameters[i].key == "A2dpSuspended") {
if (parameters[i].value == "1" || parameters[i].value == "true") {
fixupMixers(1);
}
}
if (parameters[i].key == "voip_call") {
if (parameters[i].value == "1") {
fixupMixers(0);
}
}
if (parameters[i].key == "BT_SCO") {
if (parameters[i].value == "off") {
fixupMixers(2);
}
}
if (parameters[i].key == "reset_a2dp") {
if (parameters[i].value == "1") {
fixupMixers(3);
fixupMixers();
}
}
params.add(String8(parameters[i].key.c_str()), String8(parameters[i].value.c_str()));
@ -520,14 +388,6 @@ Result ParametersUtil::setParam(const char* name, const DeviceAddress& address)
if (CoreUtils::deviceAddressToHal(address, &halDeviceType, halDeviceAddress) != NO_ERROR) {
return Result::INVALID_ARGUMENTS;
}
if (halDeviceType == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP || halDeviceType == AUDIO_DEVICE_OUT_BLUETOOTH_SCO
|| halDeviceType == AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
if (strcmp(name, "connect") == 0) {
property_set("vendor.audio.a2dp.connected", "true");
} else if (strcmp(name, "disconnect") == 0) {
property_set("vendor.audio.a2dp.connected", "false");
}
}
AudioParameter params{String8(halDeviceAddress)};
params.addInt(String8(name), halDeviceType);
return setParams(params);

@ -1,8 +1,6 @@
# audio
vendor.audio_hal. u:object_r:vendor_audio_prop:s0
vendor.audio.voip.device u:object_r:vendor_samsung_audio_prop:s0
vendor.audio.a2dp.connected u:object_r:vendor_samsung_audio_prop:s0
vendor.audio.call.switched u:object_r:vendor_samsung_audio_prop:s0
# Bluetooth
vendor.bluetooth_fw_ver u:object_r:vendor_bluetooth_prop:s0

Loading…
Cancel
Save