From Android 4.2, the Bluetooth Stack has undergone a major change: From bluez to bluedroid jointly developed by Google and Broadcom (of course, the core part is still Broadcom, google is mainly engaged in the upper-layer framework ). You can use http://source.android.com/devices/javasth.htmlto obtain a new Bluetooth
Stack architecture. In general, there are few relevant documents, mainly by reading the code for in-depth understanding.
Compared with bluez, bluedroid has the following advantages:
- The hierarchy is clear. Each profile is unified to the upper-layer interface to facilitate the addition of a new profile; the Hal layer is added to facilitate migration.
- With the release removed, the Java code of the framework directly calls the native code of bluedroid.
However, bluedroid in Android 4.2 has fewer functions than bluez in Android 4.1. For example, it does not support avrcp 1.3 and has many bugs. For example, some Bluetooth headsets cannot redial the last phone. Most importantly, bluedroid 4.2 does not support ble. However, there have been many improvements in the just-released Android 4.3, and avrcp 1.3 and ble are supported.
Currently, some Android 4.1 or 4.2 devices support Ble, but they all adopt their own vendor solutions. For example, Bluetooth Stack uses bluez 5.x, and then provides vendor ble Android SDK. now Android 4.3 has been released. From the future development trend, if someone wants to learn Bluetooth in Android, It is recommended not to study bluez any more. It is best to switch to bluedroid.
The distribution of Bluetooth-related codes in Android 4.2 is as follows:
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: callinto Hal and calls es 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 |
Taking Pan profile as an example, we can look at the distribution of code and the naming of classes and files:
Android. Bluetooth |
Frameworks |
Public class implements thpan implements thprofile |
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) |