此文描述的是 AOSP11(Android R) 版本的藍(lán)牙內(nèi)容。
1. AOSP11 Bluetooth Relative Repos
| Repos | Documents | Installed Product |
|---|---|---|
| packages/apps/Settings/ | src/com/android/settings/bluetooth/ | Settings.apk |
| src/com/android/settings/development/bluetooth/ | Settings.apk | |
| frameworks/base/ | packages/SettingsLib/src/com/android/settingslib/bluetooth/ | ?? |
| core/java/android/bluetooth/ | framework.jar | |
| services/core/java/com/android/server/ | services.jar | |
| packages/apps/Bluetooth/ | * (exclude jni/) | Bluetooth.apk |
| jni/ | libbluetooth_jni.so | |
| system/bt/ | * | libbluetooth.so |
| hardware/interfaces/ | bluetooth/ | ?? |
- packages/apps/Settings/ 包含藍(lán)牙的設(shè)置和開發(fā)者選項;
- frameworks/base/ 包含藍(lán)牙的 API封裝(供設(shè)置等系統(tǒng)應(yīng)用使用)、標(biāo)準(zhǔn)API、system_server中運(yùn)行的常駐藍(lán)牙服務(wù);
- packages/apps/Bluetooth/ 包含藍(lán)牙的核心服務(wù)和各種profile服務(wù)等;
- system/bt/ 包含藍(lán)牙的協(xié)議棧實現(xiàn)、apex、binder接口定義(AIDL);
- hardware/interfaces/ 包含藍(lán)牙的 HAL 層接口定義(AIDL/HIDL)。
2. AOSP11 Bluetooth Architecture

AOSP11 Bluetooth Architecture
- 紫色框是進(jìn)程;
- 黑色框是模塊(Android 上可獨(dú)立修改安裝的包)。
- 由于藍(lán)牙進(jìn)程(com.android.bluetooth)僅在藍(lán)牙開啟時運(yùn)行,因此,在藍(lán)牙進(jìn)程未啟動時,在系統(tǒng)中需要有一個常駐模塊接收并處理 enable bluetooth 操作,該模塊即為 system_server 進(jìn)程中的 BluetoothManagerService。
2.1 AOSP11 Bluetooth Stack Architecture

AOSP11 Bluetooth Stack Architecture
注意:以上名稱主要來自AOSP的目錄名稱,不確保具備通用性。
- BTIF:Bluetooth Interface,表示 JNI 與 BTA 之間的接口;
- BTA:Bluetooth Application,表示藍(lán)牙應(yīng)用(如 profile或 與profile相關(guān))的實現(xiàn);
- STACK:Bluetooth Stack,表示藍(lán)牙核心協(xié)議棧的 Protocol 的實現(xiàn)(可能包含部分 Profile 的實現(xiàn));
- BTU:Bluetooth Upper,表示 HCI 的上層,是 HCI 與 Stack 之間的接口,主要是對 HCI 操作的封裝;
- HCI:Host Controller Interface,表示藍(lán)牙 Core Spec 描述的 HCI 在AOSP中的實現(xiàn)。
3. AOSP11 Bluetooth Code Description
3.1 system/bt/

Part of Bluetooth Code Description
4 AOSP11 Bluetooth Initialization Arch
Bluetooth initialization - enable in Settings & System_server process
?? Bluetooth initialization - Bluetooth process Initialization - Framework(Java)
?? Bluetooth initialization - Bluetooth process Initialization - Native(Cpp)
Bluetooth initialization - enable in Bluetooth process