Android蓝牙介绍

1. 介绍

自从Android 4.2开始,Android开始使用自己的蓝牙协议栈BlueDroid,而不是bluez

BlueDroid可分为两层:

 - BTE: Bluetooth Embedded System, 实现了核心的蓝牙功能
 - BTA: Bluetooth Application Layer, 和框架的应用程序进行通信

2. 结构

下图显示了协议栈的基本结构

bluedroid 

2.1 Framework

framework代码主要位于 framework/base/core/java/android/bluetooth
通过Binder IPC机制使用蓝牙服务,提供我们所熟知的android.bluetooth APIs接口

2.2 APK

APK代码位于 packages/app/Bluetooth
APK通过JNI与蓝牙协议栈交互,它在Android框架层实现了蓝牙的服务和Profiles

2.3 JNI

JNI代码位于packages/apps/Bluetooth/jni; 当进行蓝牙操作时,JNI的代码会调用到HAL层以获取回调

2.4 HAL

HAL层定义了android.bluetooth和蓝牙协议栈的接口
其头文件位于hardware/libhardware/include/hardware

 - bluetooth.h: Contains the HAL for the Bluetooth hardware on the device 
 - bt_av.h:     Contains the HAL for the advanced audio profile. 
 - bt_hf.h:     Contains the HAL for the handsfree profile. 
 - bt_hh.h:     Contains the HAL for the HID host profile 
 - bt_hl.h:     Contains the HAL for the health profile 
 - bt_pan.h:    Contains the HAL for the pan profile 
 - bt_sock.h:   Contains the HAL for the socket profile

2.5 Bluetooth stack

蓝牙协议栈,代码位于external/bluetooth/bluedroid, 实现了通用的蓝牙HAL及可配置组件

2.6 Vendor extensions

厂商可通过创建libbt-vendor模块来自定义扩展接口和HCI层来方便调试

3. 代码

相关代码可在GitHub上进行查看

external_bluetooth_bluedroid
packages_apps_Bluetooth

android_hardware_libhardware

参考:
<AndroidXRef>
<Android Bluetooth>

原文地址:https://www.cnblogs.com/hzl6255/p/3887547.html