Android HFP流程记录
来源:互联网 发布:繁体字转换简体字 mac 编辑:程序博客网 时间:2024/06/05 18:58
DP 完成后,btif_dm.c文件中,
btif_dm_search_services_evt函数,
bond_state_changed(BT_STATUS_SUCCESS,&bd_addr, BT_BOND_STATE_BONDED);
HAL_CBACK(bt_hal_cbacks,bond_state_changed_cb, status, bd_addr, state);
com_android_bluetooth_btservice_AdapterService.cpp,调用:
voidbond_state_changed_callback(bt_status_t status, bt_bdaddr_t *bd_addr, bt_bond_state_tstate)
JniCallbacks.java文件
void bondStateChangeCallback(int status,byte[] address, int newState)
BondStateMachine.java
void bondStateChangeCallback(int status,byte[] address, int newState)
sendIntent发送Bond状态。
mAdapterProperties.onBondStateChanged(device,newState);
Intent intent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
BluetoothEventManager中,注册了该Intentfilter。
addHandler(BluetoothDevice.ACTION_BOND_STATE_CHANGED,
new BondStateChangedHandler());
在BondStateChangedHandler中,通过CachedBluetoothDeviceManager找到对应设备CachedBluetoothDevice。
CachedBluetoothDevice cachedDevice =mDeviceManager.findDevice(device);
然后调用cachedDevice.onBondingStateChanged(bondState);
if (bondState ==BluetoothDevice.BOND_BONDED) {
if (mDevice.isBluetoothDock()) {
onBondingDockConnect();
} else if (mConnectAfterPairing) {
connect(false);
}
mConnectAfterPairing = false;
}
因为mConnectAfterPairing在startPairing中已经置为true,因此会调用connect(false)。
public boolean startPairing(){
// Pairing is unreliable while scanning, so cancel discovery
if (mLocalAdapter.isDiscovering()) {
mLocalAdapter.cancelDiscovery();
}
if (!mDevice.createBond()) {
return false;
}
mConnectAfterPairing = true; // auto-connect after pairing
return true;
}
在connectWithoutResettingTimer(boolean connectAllProfiles)方法中,
int preferredProfiles = 0;
for (LocalBluetoothProfile profile : mProfiles) {
if (connectAllProfiles ? profile.isConnectable() :profile.isAutoConnectable()) {
if(profile.isPreferred(mDevice)) {
++preferredProfiles;
connectInt(profile);
}
}
}
if (DEBUG) Log.d(TAG, "Preferred profiles = " +preferredProfiles);
测试输出Log为
06-19 20:54:24.341 1409 1974 D CachedBluetoothDevice: Command sent successfully:CONNECTAddress:00:0D:18:00:5E:D5 Profile:HEADSET
06-19 20:54:24.351 1409 1974 D BluetoothA2dp: connect(00:0D:18:00:5E:D5)
06-19 20:54:24.364 6478 6513 D A2dpStateMachine: Disconnected process message: 1
06-19 20:54:24.365 1409 1974 D CachedBluetoothDevice: Command sent successfully:CONNECTAddress:00:0D:18:00:5E:D5 Profile:A2DP
06-19 20:54:24.365 1409 1974 D CachedBluetoothDevice: Preferredprofiles = 2
connectInt(profile)最终调用profile的connect函数。
profile.connect(mDevice)调用到HeadsetProfile的connect,然后调用到BluetoothHeadset的connect方法。
最后通过Binder调用到HeadsetService的connect,然后通过向HeadsetStateMachine发送CONNECT MSG,在Disconnect State的processMessage 方法调用native函数connectHfpNative(getByteAddress(device)创建HFP连接,并广播连接状态,进入到Pending State。
broadcastConnectionState(device,BluetoothProfile.STATE_CONNECTING,
BluetoothProfile.STATE_DISCONNECTED);
连接Log输出如下:
06-19 20:54:24.322 1409 1974 D BluetoothHeadset: connect(00:0D:18:00:5E:D5)
06-19 20:54:24.327 6478 6490 D HeadsetStateMachine: currentState is Disconnected
06-19 20:54:24.327 6478 6490 D HeadsetService: connectionState = 0
06-19 20:54:24.328 6478 6511 D HeadsetStateMachine: Disconnected process message:1, size: 0
06-19 20:54:24.328 6478 6511 D HeadsetStateMachine: Connection state 00:0D:18:00:5E:D5: 0->1
06-19 20:54:24.329 6478 6478 D BluetoothAdapterService: handleMessage() - Message: 20
06-19 20:54:24.329 6478 6478 D BluetoothAdapterService: handleMessage() -MESSAGE_PROFILE_CONNECTION_STATE_CHANGED
06-19 20:54:24.333 6478 6511 I BluetoothHeadsetServiceJni: connectHfpNative:sBluetoothHfpInterface: 0xa594fa30
06-19 20:54:24.334 6478 6511 I bt_btif : BTHF: connect
06-19 20:54:24.335 6478 6495 I bt_btif : BTHF: connect_int
06-19 20:54:24.335 6478 6511 D HeadsetStateMachine: Exit Disconnected: 1 (transitionTo会调用打印)
06-19 20:54:24.335 6478 6506 I bt_btif : BTA got event 0x502
06-19 20:54:24.335 6478 6506 D bt_btif : bta_ag_hdl_event: Event 0x0502
06-19 20:54:24.335 6478 6511 D HeadsetStateMachine: Enter Pending:1
06-19 20:54:24.335 6478 6506 D bt_btif : bta_ag_hdl_event: p_scb 0xa5a3c6d0
06-19 20:54:24.335 6478 6506 I bt_btif : AG evt (hdl 0x0001): State 0, Event 0x0502
。。。。。
06-19 20:54:24.379 6478 6478 D BluetoothAdapterService: handleMessage() - Message: 20
06-19 20:54:24.379 6478 6478 D BluetoothAdapterService: handleMessage() -MESSAGE_PROFILE_CONNECTION_STATE_CHANGED
06-19 20:54:24.387 1409 1974 D CachedBluetoothDevice: onProfileStateChanged: profile HEADSETnewProfileState 1
。。。。。。
06-19 20:54:25.241 6478 6495 D bt_btif : btif_hf_upstreams_evt: event=BTA_AG_OPEN_EVT
06-19 20:54:25.241 6478 6495 I bt_btif : HAL bt_hf_callbacks->connection_state_cb
06-19 20:54:25.241 6478 6495 I BluetoothHeadsetServiceJni: connection_state_callback
。。。。。。
06-19 20:54:25.248 6478 6511 D HeadsetStateMachine: Pending processmessage: 101, size: 0
06-19 20:54:25.248 6478 6511 D HeadsetStateMachine: event type: 1
06-19 20:54:25.248 6478 6511 D HeadsetStateMachine: getDeviceForMessage:returning mTargetDevice for what=201
06-19 20:54:25.248 6478 6511 D HeadsetStateMachine: remove connect timeout for device =00:0D:18:00:5E:D5
。。。。。。
06-19 20:54:25.254 6478 6511 D HeadsetStateMachine: processConnectionEventstate = 2, device = 00:0D:18:00:5E:D5
06-19 20:54:25.254 6478 6511 D HeadsetStateMachine: device 00:0D:18:00:5E:D5 isadded in Pending state
06-19 20:54:25.254 6478 6511 D HeadsetStateMachine: Connection state 00:0D:18:00:5E:D5: 1->2
06-19 20:54:25.255 6478 6478 D BluetoothAdapterService: handleMessage() - Message: 20
06-19 20:54:25.255 6478 6478 D BluetoothAdapterService: handleMessage() - MESSAGE_PROFILE_CONNECTION_STATE_CHANGED
06-19 20:54:25.255 6478 6478 D BluetoothAdapterService: Profile connected. Schedule missingprofile connection if any
06-19 20:54:25.255 6478 6478 D BluetoothAdapterService: isQuetModeEnabled() - Enabled = false
06-19 20:54:25.261 1597 1597 D CachedBluetoothDevice: onProfileStateChanged: profile HEADSETnewProfileState 2
06-19 20:54:25.270 331 1302 I APM::AudioPolicyManager: setDeviceConnectionStateInt()device: 0xFFFFFFE0, state 1, address 00:0D:18:00:5E:D5 name CarBT 802
06-19 20:54:25.279 331 2115 I APM::AudioPolicyManager: setDeviceConnectionStateInt() device:0x7FFFFFF8, state 1, address 00:0D:18:00:5E:D5 name CarBT 802
06-19 20:54:25.283 331 2115 W audio_hw_primary: [TH], adev_open_input_stream,devices=0x80000008,sample_rate=48000,channel_count=2
06-19 20:54:25.284 331 2115 W audio_hw_primary: Successfully, adev_open_input_stream.
06-19 20:54:25.313 331 2070 W audio_hw_primary: adev_set_parameters, kvpairs :bt_headset_name=CarBT 802;bt_headset_nrec=on
06-19 20:54:25.314 6478 6511 D HeadsetStateMachine: configAudioParameters fordevice:00:0D:18:00:5E:D5 are: nrec = 1
06-19 20:54:25.320 6478 6511 D HeadsetStateMachine: Enter Connected: 101, size: 1
06-19 20:54:25.325 1409 1974 D CachedBluetoothDevice: onProfileStateChanged: profile HEADSETnewProfileState 2
在HFP连接建立成功后,调用HAL bt_hf_callbacks->connection_state_cb ,发送STACK_EVENT到HeadsetStateMachine,在Pending state调用processConnectionEvent(event.valueInt,event.device),传入的HeadsetHalConstants.CONNECTION_STATE_CONNECTED,进入到以下代码段,打印Log“added in Pending state”。广播profile状态。
else if (mTargetDevice != null &&mTargetDevice.equals(device)) {
synchronized(HeadsetStateMachine.this) {
mCurrentDevice =device;
mConnectedDevicesList.add(device);
Log.d(TAG,"device " + device.getAddress() +
"is added in Pending state");
mTargetDevice =null;
transitionTo(mConnected);
}
broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
BluetoothProfile.STATE_CONNECTING);
configAudioParameters(device);
}
然后调用configAudioParameters(BluetoothDevice device),通知AudioManager,打印Log” configAudioParameters for device:”
AudioParamConfig.put("NREC", 1);
mHeadsetAudioParam.put(device, AudioParamConfig);
mAudioManager.setParameters(HEADSET_NAME + "=" +getCurrentDeviceName(device) + ";" +HEADSET_NREC + "=on");
AT CMD接收和响应Log:
06-19 20:54:26.016 6478 6506 D bt_btif : HFP AT cmd:7 arg_type:4 arg:0 arg:?
06-19 20:54:26.016 6478 6495 D bt_btif : btif_hf_upstreams_evt:event=BTA_AG_AT_CIND_EVT
06-19 20:54:26.016 6478 6495 I bt_btif : HAL bt_hf_callbacks->cind_cmd_cb
06-19 20:54:26.017 6478 6511 D HeadsetStateMachine: Connectedprocess message: 101, size: 1
06-19 20:54:26.017 6478 6511 D HeadsetStateMachine: event type: 12event device :00:0D:18:00:5E:D5
06-19 20:54:26.017 6478 6511 I BluetoothHeadsetServiceJni: cindResponseNative:sBluetoothHfpInterface: 0xa594fa30
06-19 20:54:26.017 6478 6511 I bt_btif : BTHF: cind_response
06-19 20:54:26.017 6478 6506 I bt_btif : BTA got event 0x506
06-19 20:54:26.017 6478 6506 D bt_btif : bta_ag_hdl_event: Event 0x0506
06-19 20:54:26.017 6478 6506 D bt_btif : bta_ag_api_result: p_scb 0xa5a3c6d0
06-19 20:54:26.017 6478 6506 I bt_btif : AG evt (hdl 0x0001): State 2, Event 0x0506
06-19 20:54:26.017 6478 6506 D bt_btif : bta_ag_hfp_result : res = 3
06-19 20:54:26.017 6478 6506 D bt_btif : cind call:0 callsetup:0
Skype电话流程分析
06-19 20:54:53.289 1084 1105 D BluetoothHeadset: startScoUsingVirtualVoiceCall()
06-19 20:54:53.291 6478 6511 D HeadsetStateMachine: Connected process message: 14, size: 1
06-19 20:54:53.331 6478 6511 D HeadsetStateMachine: initiateScoUsingVirtualVoiceCall:Received
06-19 20:54:53.335 6478 6511 D HeadsetStateMachine: mNumActive: 0 mNumHeld: 0 mCallState: 2
06-19 20:54:53.335 6478 6511 D HeadsetStateMachine: mNumber: mType: 0
06-19 20:54:53.335 6478 6511 D bt_btif : phone_state_change: idx = 0
06-19 20:54:53.335 6478 6511 I bt_btif : BTHF: btif_hf_check_if_slc_connected: slc connected foridx = 0
06-19 20:54:53.335 6478 6511 D bt_btif : phone_state_change: num_active=0 [prev: 0] num_held=0[prev: 0]call_setup=BTHF_CALL_STATE_DIALING [prev: BTHF_CALL_STATE_IDLE]
06-19 20:54:53.335 6478 6511 D bt_btif : phone_state_change: Call setup states changed. old:BTHF_CALL_STATE_IDLE new: BTHF_CALL_STATE_DIALING
06-19 20:54:53.335 6478 6511 D bt_btif : phone_state_change: Call setup state changed. res=14,audio_handle=1
06-19 20:54:53.336 6478 6511 D HeadsetStateMachine: mNumActive: 0 mNumHeld: 0 mCallState: 3
06-19 20:54:53.336 6478 6511 D HeadsetStateMachine: mNumber: mType: 0
06-19 20:54:53.336 6478 6511 D bt_btif : phone_state_change: idx = 0
06-19 20:54:53.336 6478 6511 I bt_btif : BTHF:btif_hf_check_if_slc_connected: slc connected for idx = 0
06-19 20:54:53.336 6478 6506 I bt_btif : BTA got event 0x506
06-19 20:54:53.336 6478 6511 D bt_btif : phone_state_change:num_active=0 [prev: 0] num_held=0[prev:0] call_setup=BTHF_CALL_STATE_ALERTING [prev: BTHF_CALL_STATE_DIALING]
06-19 20:54:53.336 6478 6506 D bt_btif : bta_ag_hdl_event: Event0x0506
06-19 20:54:53.336 6478 6511 D bt_btif : phone_state_change: Callsetup states changed. old: BTHF_CALL_STATE_DIALING new:BTHF_CALL_STATE_ALERTING
06-19 20:54:53.336 6478 6506 D bt_btif : bta_ag_api_result p_scb0xa5a3c6d0
06-19 20:54:53.336 6478 6511 D bt_btif : phone_state_change: Callsetup state changed. res=15, audio_handle=0
06-19 20:54:53.336 6478 6506 I bt_btif : AG evt (hdl 0x0001): State2, Event 0x0506
06-19 20:54:53.336 6478 6511 D HeadsetStateMachine: mNumActive: 1mNumHeld: 0 mCallState: 6
。。。。。。
06-19 20:54:53.340 6478 6511 D HeadsetStateMachine: initiateScoUsingVirtualVoiceCall: Done
。。。。。
06-19 20:55:28.669 1084 3746 D BluetoothHeadset: stopScoUsingVirtualVoiceCall()
06-19 20:55:28.699 6478 6511 D HeadsetStateMachine: AudioOn processmessage: 15, size: 1
06-19 20:55:29.049 6478 6495 D bt_btif : btif_hf_upstreams_evt:event=BTA_AG_AUDIO_CLOSE_EVT
06-19 20:55:29.049 6478 6495 I bt_btif : HALbt_hf_callbacks->audio_state_cb
。。。。。。
06-19 20:55:28.708 6478 6511 D HeadsetStateMachine: terminateScoUsingVirtualVoiceCall: Received
06-19 20:55:28.709 6478 6511 D HeadsetStateMachine: mNumActive: 0mNumHeld: 0 mCallState: 6
06-19 20:55:28.709 6478 6511 D HeadsetStateMachine: mNumber: mType: 0
06-19 20:55:28.710 6478 6511 D bt_btif : phone_state_change: idx = 0
06-19 20:55:28.710 6478 6511 I bt_btif : BTHF:btif_hf_check_if_slc_connected: slc connected for idx = 0
06-19 20:55:28.712 6478 6511 D bt_btif : phone_state_change:num_active=0 [prev: 1] num_held=0[prev:0] call_setup=BTHF_CALL_STATE_IDLE [prev: BTHF_CALL_STATE_IDLE]
06-19 20:55:28.712 6478 6511 D bt_btif : phone_state_change: Phone onhook
06-19 20:55:28.712 6478 6511 D bt_btif : phone_state_change: Recordcall termination timestamp
06-19 20:55:28.718 6478 6511 D HeadsetStateMachine: terminateScoUsingVirtualVoiceCall: Done
- Android HFP流程记录
- android 蓝牙 HFP 总结
- 4.3 android bluetooth hfp分析
- android 4.0 bluetooth bt HFP/HSP分析
- android 蓝牙hfp client实现简介
- android 蓝牙hfp server实现简介
- android蓝牙hfp client使用例
- Android 蓝牙开发(六)hfp连接
- Android蓝牙开发【六】hfp连接
- Android蓝牙开发【七】hfp音频连接
- Android4.4蓝牙耳机HFP流程分析-1
- Android4.4蓝牙耳机HFP流程分析-2
- Android4.4蓝牙耳机HFP流程分析-3
- Android4.4蓝牙耳机HFP流程分析-3
- android蓝牙协议名词解释 OPP HFP HDP A2DP PAN
- A2DP Sink, AVRCP Controller and HFP Client in Android L
- A2DP Sink, AVRCP Controller and HFP Client in Android L
- Android 蓝牙开发(七)hfp音频连接
- SideBarEnhancements
- LinkedList原理及源码解析
- 24点游戏c++
- recovery 升级时间戳校验
- 游戏编程入门(14):创建子画面背景
- Android HFP流程记录
- String to Integer (atoi)
- 非常实用的Java文件操作类
- C++智能指针
- linux查看内存占用情况(简洁版)
- 如何有效防止SQL注入
- 动态规划:HDU1176-免费馅饼
- Python标准库--random,sys,time
- jdk 中常用的 xml 数据解析