In this document
Android provides a default Bluetooth stack, BlueDroid, that is divided into two layers: The Bluetooth Embedded System (BTE), which implements the core Bluetooth functionality and the Bluetooth Application Layer (BTA), which communicates with Android framework applications.
A Bluetooth system service communicates with the Bluetooth stack through JNI and with applications through Binder IPC. The system service provides developers access to various Bluetooth profiles. The following diagram shows the general structure of the Bluetooth stack:
- Application framework
- At the application framework level is the app's code, which utilizes the android.bluetooth APIs to interact with the Bluetooth hardware. Internally, this code calls the Bluetooth process through the Binder IPC mechanism.
- Bluetooth system service
- The Bluetooth system service, located in
packages/apps/Bluetooth, is packaged as an Android app and implements the Bluetooth service and profiles at the Android framework layer. This app calls into the HAL layer via JNI.
- The JNI code associated with android.bluetooth is located in
packages/apps/Bluetooth/jni. The JNI code calls into the HAL layer and receives callbacks from the HAL when certain Bluetooth operations occur, such as when devices are discovered.
- The hardware abstraction layer defines the standard interface that the android.bluetooth APIs
and Bluetooth process calls into and that you must implement to have your Bluetooth hardware
function correctly. The header files for the Bluetooth HAL is located
- Bluetooth stack
- The default Bluetooth stack is provided for you and is located in
external/bluetooth/bluedroid. The stack implements the generic Bluetooth HAL as well as customizes it with extensions and configuration changes.
- Vendor extensions
- To add custom extensions and an HCI layer for tracing, you can create a libbt-vendor module and specify these components.
Implementing the HAL
The Bluetooth HAL is located in the
hardware/libhardware/include/hardware/ directory. Please see that directory for the complete set of files, which include but are not limited to the following:
bluetooth.h: Includes the interface definition for the Bluetooth hardware on the device.
bt_av.h: Includes the interface definition for the A2DP profile.
bt_gatt_server.h: These include the interface definition for the GATT profile.
bt_hf.h: Includes the interface definition for the HFP profile.
bt_hh.h: Includes the interface definition for the HID host profile.
bt_hl.h: Includes the interface definition for the HDP profile.
bt_mce.h: Includes the interface definition for the MAP profile.
bt_pan.h: Includes the interface definition for the PAN profile.
bt_rc.h: Includes the interface definition for the AVRCP profile.
bt_sock.h: Includes the interface definition for RFCOMM sockets.
Keep in mind that your Bluetooth implementation is not constrained to the features
and profiles exposed in the HAL. You can find the default implementation located
in the BlueDroid Bluetooth stack in the
which implements the default HAL and also extra features and customizations.
Customizing the BlueDroid Stack
If you are using the default BlueDroid stack, but want to make a few customizations, you can do the following things:
- Custom Bluetooth profiles - If you want to add Bluetooth profiles that do not have
HAL interfaces provided by Android, you must supply an SDK add-on download to make the profile available to app developers,
make the APIs available in the Bluetooth system process app (
packages/apps/Bluetooth), and add them to the BlueDroid stack (
- Custom vendor extensions and configuration changes - You can add things such as extra AT commands or device-specific configuration changes
by creating a
libbt-vendormodule. See the
vendor/broadcom/libbt-vendordirectory for an example.
- Host Controller Interface (HCI) - You can provide your own HCI by creating a
libbt-hcimodule, which is mainly used for debug tracing. See the
external/bluetooth/hcidirectory for an example.