Android Bluetooth Stack: Bluedroid(一):綜述
阿新 • • 發佈:2019-02-07
從Android 4.2開始,Bluetooth stack發生了重大改變:從Bluez換成了由Google和Broadcom聯合開發的Bluedroid(當然,核心的部分還是Broadcom的,Google主要是做了和上層Framework相關的部分)。通過http://source.android.com/devices/bluetooth.html可以大概瞭解新的Bluetooth stack的架構,總的來說相關文件很少,主要靠閱讀程式碼進行深入瞭解。
Bluedroid和Bluez相比,有如下優點:
- 層次結構清晰。各個profile對上層介面統一,便於增加新的profile;增加了HAL層,便於移植。
- 去掉了DBus,Framework的Java程式碼直接呼叫到Bluedroid的Native程式碼。
目前有一些Android 4.1或4.2的裝置是支援BLE的,但是都是採用的Vendor自己的解決方案,比如Bluetooth stack採用Bluez 5.x,再提供Vendor BLE Android SDK. 現在Android 4.3已經發布,從未來發展趨勢來看,如果有人要學習Bluetooth in Android,建議不要再研究Bluez,最好轉向Bluedroid。
以下是Android 4.2中Bluetooth相關程式碼之分佈:
android.bluetooth | frameworks/base/core/java/android/bluetooth | implements public API for the Bluetooth adapter and profiles |
Bluetooth system service | packages/apps/Bluetooth/src | implements service and profiles at the Android fraework layer |
Bluetooth JNI | packages/apps/Bluetooth/jni | defines Bluetooth adapter and profiles service JNI: calls into HAL and receives callback from HAL |
Bluetooth HAL | hardware/libhardware/include/hardware/bt_*.h files | defines the standard interface that the android.bluetooth adapter and profiles APIs |
Bluetooth stack | external/bluetooth/bluedroid | implement bluetooth stack: core and profiles |
以Pan profile為例,我們可以看看程式碼的具體分佈和類及檔案的命名方式:
android.bluetooth | frameworks | public class BluetoothPan implements BluetoothProfile |
Bluetooth System Service | packages/apps | public class PanService extends ProfileService |
Bluetooth JNI | packages/apps | com_android_bluetooth_pan.cpp |
Bluetooth HAL | hardware/libhardware | include/hardware/bt_pan.h |
Bluetooth stack | external/bluetooth | bluedroid/btif/src/btif_pan.c(implements bt_pan.h) |
bluedroid/bta/pan (Broadcom BTA) | ||
bluedroid/stack/pan (Broadcom BTE) |