通话的时候,需要打开音频通路,音频设备(上下行都要)
我们从这里开始:
packages/apps/Bluetooth/src/com/android/bluetooth/hfpclient
// in Connected state
private void processAudioEvent(int state, BluetoothDevice device) {
...
switch (state) {
...
case HeadsetClientHalConstants.AUDIO_STATE_CONNECTED:
routeHfpAudio(true);
}
}
private void acceptCall(int flag) {
...
if (flag == BluetoothHeadsetClient.CALL_ACCEPT_HOLD) {
// When unholding a call over Bluetooth make sure to route audio.
routeHfpAudio(true);
}
...
}
两种场景,一个是接通电话,一个是电话hold之后,unhold的时候。都需要去调用routeHfpAudio(true).我们简化问题,只分析打开的情况。
static synchronized void routeHfpAudio(boolean enable) {
...
if (enable && !sAudioIsRouted) {
sAudioManager.setParameters("hfp_enable=true");
} else if (!enable) {
sAudioManager.setParameters("hfp_enable=false");
}
...
}
直接跳过中间繁琐的调用分析,欢迎查看我之前的博客。我们直接来到这里(路径都懒得贴了,搞audio的都知道):
audio_hw.c
static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
{
...
struct str_parms *parms;
...
//一猜就是通过等号把上面传下来的参数分割成对:hfp_enable,true
parms = str_parms_create_s