连接蓝牙耳机过程

来源:互联网 发布:湘北vs爱和学院数据 编辑:程序博客网 时间:2024/05/01 22:57

      首先BluetoothAudioGateway 会在一个线程中收到来自蓝牙耳机的RFCOMM 连接(MSG_INCOMING_HEADSET_CONNECTION),然后发送消息给BluetoothHeadsetService。如果一个设备支持headset和handfree,先发送了headset的消息,再发送handfree。

手机主动连接过程处理:
在配对上蓝牙耳机之后,收到BOND_STATE_CHANGED和Property Changed,调用onPropertyChanged()在bluetootheventloop类中,获取UUID:  adapterProperties.setProperty(name, value);
            if (name.equals("UUIDs")) {
                mBluetoothService.updateBluetoothState(value);
            }
更新之后收到ACTION_UUID;
在bluetoothheadsetservice这个类中,处理ACTION_UUID:
else if (action.equals(BluetoothDevice.ACTION_UUID)) {
                if (device.equals(mDeviceSdpQuery) && device.equals(currDevice)) {
                    // We have got SDP records for the device we are interested in.
                    getSdpRecordsAndConnect(device);
                }
            }
SDP查询过后,启动RfcommConnectThread线程,建立RFCOMM连接。在收到RFCOMM_CONNECTED这个消息后去调用connectheadset,如果在通话等过程中调用audioOn中,connectScoThread。

 

原创粉丝点击