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.
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.
HAL
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 in the hardware/libhardware/include/hardware/bluetooth.h and hardware/libhardware/include/hardware/bt_*.h files.
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 and consists of the following header files:

  • bluetooth.h: Contains the HAL for the Bluetooth hardware on the device
  • bt_av.h: Contains the HAL for the advanced audio profile.
  • bt_hf.h: Contains the HAL for the handsfree profile.
  • bt_hh.h: Contains the HAL for the HID host profile
  • bt_hl.h: Contains the HAL for the health profile
  • bt_pan.h: Contains the HAL for the pan profile
  • bt_sock.h: Contains the HAL for the socket profile.

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 external/bluetooth/bluedroid directory, 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 (external/bluetooth/bluedroid).
  • Custom vendor extensions and configuration changes - You can add things such as extra AT commands or device-specific configuration changes by creating a libbt-vendor module. See the vendor/broadcom/libbt-vendor directory for an example.
  • Host Controller Interface (HCI) - You can provide your own HCI by creating a libbt-hci module, which is mainly used for debug tracing. See the external/bluetooth/hci directory for an example.

最新文章

  1. grunt自动化构建工具
  2. javascript 的事件--阻止冒泡
  3. Python开发包推荐系列之xml、html解析器PyQuery
  4. 夺命雷公狗---DEDECMS----32dedecms电影网评价星星功能的实现
  5. 指定IE浏览器渲染方式
  6. form不提交问题
  7. Android开发学习总结——Android开发的一些相关概念(转)
  8. ios 中在容器中移除单个控件的两个方法Subview
  9. 学习MVC之租房网站(九)-房源显示和搜索
  10. JDBCTemplate
  11. 我的three.js学习记录(二)
  12. Windows Server 2016-部署第一台域控制器
  13. Eclipse代码块折叠插件,安装使用
  14. Spock - Document -04- Interaction Based Testing
  15. 【kindle笔记】之 《犬夜叉》-2017-12-26
  16. FFT的一种迭代实现
  17. 020_nginx禁止ip默认参数是$remote_addr无法禁止真实ip的问题
  18. tidb集群某个节点报错之:node_exporter-9100.service failed
  19. Sql_索引分析
  20. 小心踩雷,一次Java内存泄漏排查实战

热门文章

  1. springboot部署在云服务器上
  2. 编程之美——求1~N的整数中1的个数
  3. AVL模板
  4. eclipse中把多个项目放在一个文件夹里
  5. Codeforces Round #365 (Div. 2) B - Mishka and trip
  6. C# 自动触发鼠标、键盘事件
  7. chengdongyue的笔记
  8. HTML 参考手册- (HTML5 标准)
  9. flask学习(四):debug模式
  10. Hibernate入门_增删改查