1. 介紹
自從Android 4.2開始,Android開始使用自己的藍牙協議棧BlueDroid,而不是bluez
BlueDroid可分為兩層:
- BTE: Bluetooth Embedded System, 實現了核心的藍牙功能
- BTA: Bluetooth Application Layer, 和框架的應用程序進行通信
2. 結構
下圖顯示了協議棧的基本結構
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>