List of Bluetooth profiles
https://en.wikipedia.org/wiki/List_of_Bluetooth_profiles
A2dp : Advanced Audio Distribution Profile 蓝牙 音频传输模型协定
蓝牙立体声,和蓝牙耳机听歌有关那些,另还有个AVRCP--( Audio/Video Remote Control Profile) 音频/视频远程控制配置文件, 是用来听歌时暂停,上下歌曲选择的
GATT: Generic Attribute Profile 通用属性配置文件
GATT是基于ATT Protocol的, ATT针对BLE设备做了专门的优化,具体就是在传输过程中使用尽量少的数据。每个属性都有一个唯一的UUID,属性将以characteristics and services的形式传输
https://developer.bluetooth.org/TechnologyOverview/Pages/GATT.aspx
HDP : Bluetooth Health Device Profile 蓝牙关于医疗方面的应用
HFP : Hands-free Profile 和电话相关,蓝牙接听、挂断电话
HID : Human Interface Device
定义了蓝牙在人机接口设备中的协议、特征和使用规程。典型的应用包括蓝牙鼠标、蓝牙键盘、蓝牙游戏手柄等。该协议改编自USB HID Protocol
MAP : Message Access Profile
OPP : Object Push Profile
PAN : Personal Area Network Profile
描述了两个或更多个 Bluetooth 设备如何构成一个即时网络,和网络有关的还有串行端口功能(SPP),拨号网络功能(DUN)
PBAP : Phonebook Access Profile 电话号码簿访问协议
在setting界面点击连接,会调到CachedBluetoothDevice类的connect方法,调用 updateProfiles(),根据搜索到的device的uuid来向ProfilesList里添加profile,然后遍历 ProfileList,根据不同的profile来获得profileManager。
然后判断当前的device的Priority,如果Priority=100,则去调用queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile)),去发送连接的命令。如果Priority=1,则不去自动连接。Priority=-1,代表当前的device没有配对。
在queueCommand()函数里,有一个消息队列来处理命令,在这里生成了一个BluetoothJob的实例,来代表要执行的命令。
最终调到processCommand(BluetoothJob job)函数,由它来通过job.command来调用CONNECT: DISCONNECT:REMOVE_BOND:
以A2DP为例,在connectInt里,根据不同的profile来获得profilemanger,然后调用 profilemanger.connect()函数,在这个函数里调用了BluetoothA2dpService的connectSink()函数,最后调到Native方法connectSinkNative()去建立连接。
1. 当用户在setting的bluetooth device list中选择了input设备后会触发起所有profile的connect操作,input设备在Setting中叫做HidProfile.java.
值得我们注意的是Android的BluetoothInputDevice是通过getProfileProxy的方法取得的,这点并不同于HFP或HSP.
2. HidProfile通过调用BluetoothInputDevice的connect,如果是有效的设备则BluetoothInputDevice会直接调用bluetoothservice的connectInputDevice函式。
3. 其中bluetoothservice也就是简单的调用了BluetoothInputProfileHandler的connectInputDevice函式。connectInputDevice会向BluetoothDeviceProfileState发送CONNECT_HID_OUTGOING消息。
Framework中包含了很多profilehandler, 这些Handler有个共同的特点是都包含了一个此profile的设备列表。
4. BluetoothDeviceProfileState会切至OutgoingHidstate.此时OutgoingHid将deferMessageCONNECT_HID_OUTGOING消息并且交由BluetoothDeviceProfileState类的processCommand处理,在些它调用了BluetoothService的connectInputDeviceInternal.
5. 在些BluetoothService又去调用了mBluetoothInputProfileHandler的connectInputDeviceInternal,在其中其调用了jni方法BluetoothService的connectInputDeviceNative方法。此时的DBUS调用为异步调用。
6. 当Bluez在Input接口上连接成功后,会调用之前注册的onInputDeviceConnectionResult函数,(onInputDeviceConnectionResult是EventLoop中的函数)。
7. onInputDeviceConnectionResult将解析bluez返回的path,其格式中包含了address,所以androide有替换”_”到”:”. 后呼叫了BluetoothService的handleInputDevicePropertyChange去通过mBluetoothInputProfileHandler更新其中设备的连接状态。