Android: Bluetooth Input 连接流程分析

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更新其中设备的连接状态。


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这些 SCPI 命令是用于控制和查询蓝牙测量相关参数的。下面是每个命令的作用: 1. `:CALCulate:BLUetooth:MEASurement{1..4}:MEValuation:MODulation:NMODe:LENergy:MINimum?`:查询蓝牙测量结果中最小的能量级别。 2. `:CALCulate:BLUetooth:MEASurement{1..4}:MEValuation:MODulation:NMODe:LENergy:SDEViation?`:查询蓝牙测量结果中能量级别的标准偏差。 3. `:CALCulate:BLUetooth:MEASurement{1..4}:MEValuation:MODulation:NMODe:LENergy:XMAXimum?`:查询蓝牙测量结果中最大的能量值。 4. `:CALCulate:BLUetooth:MEASurement{1..4}:MEValuation:MODulation:NMODe:LENergy:XMINimum?`:查询蓝牙测量结果中最小的能量值。 5. `:CALCulate:BLUetooth:MEASurement{1..4}:MEValuation:PENCoding:EDRate:CURRent?`:查询蓝牙测量结果中误码率的当前值。 6. `:CALCulate:BLUetooth:MEASurement{1..4}:MEValuation:PVTime:BRATe:AVERage?`:查询蓝牙测量结果中比特率的平均值。 7. `:CALCulate:BLUetooth:MEASurement{1..4}:MEValuation:PVTime:BRATe:CURRent?`:查询蓝牙测量结果中比特率的当前值。 8. `:CALCulate:BLUetooth:MEASurement{1..4}:MEValuation:PVTime:BRATe:MAXimum?`:查询蓝牙测量结果中比特率的最大值。 9. `:CALCulate:BLUetooth:MEASurement{1..4}:MEValuation:PVTime:BRATe:MINimum?`:查询蓝牙测量结果中比特率的最小值。 10. `:CALCulate:BLUetooth:MEASurement{1..4}:MEValuation:PVTime:EDRate:AVERage?`:查询蓝牙测量结果中误码率的平均值。 11. `:CALCulate:BLUetooth:MEASurement{1..4}:MEValuation:PVTime:EDRate:CURRent?`:查询蓝牙测量结果中误码率的当前值。 12. `:CALCulate:BLUetooth:MEASurement{1..4}:MEValuation:PVTime:EDRate:MAXimum?`:查询蓝牙测量结果中误码率的最大值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值