使用android.bluetooth相关的API和蓝牙硬件进行交互,内部是通过Binder IPC机制来调用bluetooth进程。
- 蓝牙系统服务
该层实际上被打包成一个system APP(Bluetooth.apk),其在Android框架层实现了蓝牙的service和profiles,并通过JNI调用HAL层。
代码目录为packages/apps/Bluetooth。
- JNI
代码目录为packages/apps/Bluetooth/jni。
JNI层代码调用到HAL层,并在蓝牙底层发生某些动作(如发现设备)的时候,接受HAL层的回调。
- 硬件抽象层
该层定义了android.bluetooth API和蓝牙进程需要使用的标准接口,只有实现这些接口才能确保蓝牙硬件正常工作。
代码目录为hardware/libhardware/include/hardware。
- 蓝牙协议栈
该层实现了通用的蓝牙HAL接口,并且可以进行客制化的扩展和配置。
代码目录为system/bt。
- 供应商扩展
该层专为蓝牙芯片供应商设计。供应商可以通过创建libbt-vendor.so并指定这些模块,来添加自定义扩展和HCI层调试。
-
+--------------------------------------+
-
| Application Framework |
-
| +-----------------------------+ |
-
| | BT Apps API
| |
-
| | android.bluetooth
| |
-
| +-----------------------------+ |
-
+-----------------^--------------------+
-
|
-
|Binder
-
|
-
+-----------------v--------------------+
-
| Bluetooth
process: Packages/apps/
|
-
| Bluetooth
|
-
|
|
-
| +------------------------------+
|
-
|
| Bluetooth Service |
|
-
| +------------------------------+
|
-
|
| Bluetooth Profiles |
|
-
| +------------------------------+
|
-
+-----------------^--------------------+
-
|
-
|JNI
-
|
-
+-----------------v--------------------+
-
| HAL hardware/libhardware/include/ |
-
| hardware/ |
-
| |
-
| +--------------------------------+ |
-
| | Bluetooth HAL Interfaces
| |
-
| +--------------------------------+ |
-
| |Bluetooth Profile HAL Interfaces
| |
-
| +--------------------------------+ |
-
+----------------^---------------------+
-
|
-
|
-
+----------------v---------------------+
-
| BlueDroid Stack /external/bluetooth/|
-
| bluedroid |
-
| |
-
| +---------------------------------+ |
-
| | Bluetooth App Layer
| |
-
| +---------------------------------+ |
-
| | Bluetooth Embedded System
| |
-
| +---------------------------------+ |
-
| +---------------------------------+ |
-
| | Vendor Extensions
| |
-
| | /vendor/company/libbt-vendor
| |
-
| +---------------------------------+ |
-
+--------------------------------------+
源码分析可以参考
https://blog.youkuaiyun.com/column/details/fang1021.html