Android provides a default Bluetooth stack 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.
To fully leverage the Bluetooth Low Energy APIs added in Android 5.0, you should implement the Android 6.0 Bluetooth HCI Requirements. That document initially was provided as the Android 5.0 Bluetooth HCI Requirements.
A Bluetooth system service communicates with the Bluetooth stack through JNI and with applications through Binder IPC. The system service provides developers with access to various Bluetooth profiles. The following diagram shows the general structure of the Bluetooth stack:
Figure 1. Bluetooth architecture
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.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.hardware/libhardware/include/hardware/bluetooth.h
. Additionally, please review all of the
hardware/libhardware/include/hardware/bt_*.h
files.
system/bt
. The stack implements the generic Bluetooth HAL and
customizes it with extensions and configuration changes.
The Bluetooth HAL is located in /hardware/libhardware/include/hardware/bluetooth.h
.
Thus, the bluetooth.h
file contains the basic interface for the Bluetooth stack, and you must implement its functions.
Profile-specific files are located in the same directory. For details, see the HAL File Reference.
The following is a partial list of the profile-related
files. For the complete set, see the /hardware/libhardware/include/hardware/
directory:
bt_av.h
: Includes the interface definition for the A2DP profile.bt_gatt.h
, bt_gatt_client.h
, and 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 Bluetooth stack in the system/bt
directory,
which implements the default HAL and also extra features and customizations.
If you are using the default Bluetooth stack, but want to make a few customizations, you can do the following:
packages/apps/Bluetooth
), and add them to the default stack (system/bt
).libbt-vendor
module. See the /hardware/broadcom/libbt
directory
for an example.libbt-hci
module, which
is mainly used for debug tracing. See the external/bluetooth/hci
directory for an example.