README 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. BlueZ for Android
  2. *****************
  3. Since Android 4.2 there exists a well standardized HAL interface that the
  4. Bluetooth stack is expected to provide and which enables the easy replacement
  5. of the stack of choice on Android. Android BlueZ is intended as a drop-in
  6. replacement to Android provided Bluetooth stack.
  7. More details about BlueZ for Android architecture and components can be found
  8. in android/hal-ipc-api.txt file.
  9. Supported Android version: 4.4 KitKat and 5.0, 5.1 Lollipop
  10. Building and running on Android
  11. ===============================
  12. Steps needed to build and run Android Open Source Project with integrated BlueZ.
  13. Build requirements
  14. ------------------
  15. - GLib - Android 4.2 or later don't provide GLib and one must provide it in
  16. 'external/bluetooth/glib' folder of Android tree. Sample Android GLib port
  17. is available at https://github.com/bluez-android/glib
  18. - SBC - A2DP code requires SBC library (version 1.2 or higher) present in
  19. 'external/bluetooth/sbc' directory. Library is build from Android.mk provided
  20. by BlueZ. SBC code is available at git://git.kernel.org/pub/scm/bluetooth/sbc
  21. - Bionic support - Android 5.0 provides all required functionality. Running
  22. BlueZ on Android 4.4 requires backporting missing features (epoll_create1 and
  23. ppoll calls). Sample Bionic for Android 4.4 with all required features
  24. backported is available at
  25. https://github.com/bluez-android/aosp_platform_bionic
  26. Runtime requirements
  27. --------------------
  28. BlueZ HAL library requires 'bluetoothd' and 'bluetoothd-snoop' services to be
  29. available on Android system. Some permissions settings are also required.
  30. This can be done by importing init.bluetooth.rc file in init.rc file of targeted
  31. board:
  32. import init.bluetooth.rc
  33. For convenience examples are provided at:
  34. https://github.com/bluez-android/aosp_device_lge_mako (Nexus 4)
  35. https://github.com/bluez-android/aosp_device_lge_hammerhead (Nexus 5)
  36. https://github.com/bluez-android/aosp_device_asus_flo (Nexus 7 2013)
  37. Security-Enhanced Linux in Android
  38. ----------------------------------
  39. Since 5.0 release Android moved to full enforcement of SELinux. This requires
  40. proper policy to be provided for all BlueZ for Android services (and services
  41. interacting with BlueZ). Policies should be placed in external/selinux/ path.
  42. Required policy files are provided at:
  43. bluetoothd.te
  44. bluetoothd_snoop.te
  45. For convenience sepolicy.git with all required policies is available at:
  46. https://github.com/bluez-android/aosp_platform_external_sepolicy
  47. Downloading and building
  48. ------------------------
  49. Building for Android requires full Android AOSP source tree. Sample Android tree
  50. with all required components present is available at
  51. https://github.com/bluez-android
  52. This tree provides support for Nexus4 (mako), Nexus 5 (hammerhead) and
  53. Nexus 7 2013 (flo, deb). Tree does not provide binary blobs needed to run
  54. Android on supported devices. Those can be obtained from
  55. https://developers.google.com/android/nexus/drivers. Binary blobs needs to be
  56. unpacked (EULA acceptance required) into 'vendor' directory of Android tree.
  57. Downloading:
  58. Android 5.0 - 'lollipop' branch
  59. Android 4.4 - 'kitkat' branch
  60. repo init -u https://github.com/bluez-android/aosp_platform_manifest \
  61. -b lollipop
  62. repo sync
  63. Building:
  64. source build/envsetup.sh
  65. lunch aosp_<target>-userdebug
  66. make -j8
  67. Flashing:
  68. adb reboot bootloader
  69. fastboot flashall -w
  70. After full build is done it is possible to rebuild only BlueZ:
  71. 'cd external/bluetooth/bluez/android/'
  72. 'mm' (or 'mm -B' to force rebuilding of all files)
  73. 'adb sync' to update target device.
  74. Downloading and building for Intel devices
  75. ------------------------------------------
  76. Sample Android tree with all required components for Intel devices based on
  77. Intel reference image (https://01.org/android-ia) can be reconstructed following
  78. instructions below.
  79. This tree provides support for Dell XPS12, Minnowboard MAX, Intel NUC,
  80. Acer Iconia W700 and other devices mentioned in:
  81. https://01.org/android-ia/guides/devices
  82. Downloading:
  83. repo init -u https://github.com/01org/android-bluez-manifest.git -b android-ia \
  84. -m topic/bluez
  85. repo sync
  86. Building:
  87. source build/envsetup.sh
  88. lunch haswell_generic-eng
  89. make -j8
  90. Installing:
  91. Live and Install image is $OUT/live.img
  92. Flash live.img to USB flash and boot from it. More instructions here:
  93. https://01.org/android-ia/guides/developers/build-and-install
  94. Linux Kernel requirements
  95. -------------------------
  96. BlueZ for Android uses Linux Bluetooth subsystem and it must be enabled in
  97. kernel. Minimal required version of management interface is 1.3. This
  98. corresponds to Linux 3.9 but latest available version is recommended. Other
  99. requirements include UHID and network bridge support.
  100. Following kernel options should be enabled:
  101. CONFIG_BT
  102. CONFIG_BT_RFCOMM
  103. CONFIG_BT_RFCOMM_TTY
  104. CONFIG_BT_BNEP
  105. CONFIG_BT_BNEP_MC_FILTER
  106. CONFIG_BT_BNEP_PROTO_FILTER
  107. CONFIG_BRIDGE
  108. CONFIG_UHID
  109. CONFIG_CRYPTO_CMAC
  110. CONFIG_CRYPTO_USER_API
  111. CONFIG_CRYPTO_USER_API_HASH
  112. CONFIG_CRYPTO_USER_API_SKCIPHER
  113. Also BT chip driver needs to be enabled e.g:
  114. CONFIG_BT_HCIBTUSB
  115. If it is not possible to use new enough Linux kernel one can use updated
  116. bluetooth subsystem from Backports project. More information about Backports can
  117. be found at https://backports.wiki.kernel.org. Sample kernels using backports
  118. for running BlueZ on Android are available at https://github.com/bluez-android.
  119. Running with Valgrind
  120. ---------------------
  121. BlueZ for Android is preconfigured to be easily run under Valgrind memcheck.
  122. Appropriate configuration and required modules are automatically included when
  123. building either userdebug or eng variant of Android platform.
  124. Valgrind can be enabled in runtime by setting "persist.sys.bluetooth.valgrind"
  125. property to either literal "true" or any numeric value >0. For example:
  126. adb root
  127. adb shell setprop persist.sys.bluetooth.valgrind true
  128. After changing property value Bluetooth need to be restarted to apply changes
  129. (this can be done using UI, just disable and enable it again). Property is
  130. persistent, i.e. there's no need to enable Valgrind again after reboot.
  131. It's recommended to have unstripped libglib.so installed which will enable
  132. complete backtraces in Valgrind output. Otherwise, in many cases backtrace
  133. will break at e.g. g_free() function without prior callers. It's possible to
  134. have proper library installed automatically by appropriate entry in Android.mk,
  135. see https://github.com/bluez-android/glib for an example.
  136. When running with valgrind SElinux needs to be set into permissive mode. This
  137. can be done by executing 'setenforce 0' from root shell.
  138. Enabling BlueZ debugs
  139. ---------------------
  140. BlueZ debug logs can be enabled in runtime by setting
  141. "persist.sys.bluetooth.debug" property to either literal "true" or any
  142. numeric value >0. For example:
  143. adb root
  144. adb shell setprop persist.sys.bluetooth.debug 1
  145. After changing property value Bluetooth needs to be restarted to apply changes.
  146. There is also a possibility to enable mgmt debug logs which also enables debugs
  147. as above. To enable it proceed in the same way as described above but use
  148. system properties called: persist.sys.bluetooth.mgmtdbg
  149. Note: Debugs are only available on NON USER build variants
  150. Customization
  151. -------------
  152. It is possible to customize BlueZ for Android through Android system properties.
  153. This may include enabling extra profiles or features inside HALs implementation
  154. These properties are read on Bluetooth stack startup only and require stack
  155. restart if changed. All customization properties names start with
  156. "persist.sys.bluetooth." or "ro.bluetooth." followed by specific HAL name e.g.
  157. "persist.sys.bluetooth.handsfree". If both are present "persist.sys.bluetooth."
  158. takes precedence. This allows for read only properties to be set during build
  159. leaving enough flexibility for developing or debugging purposes.
  160. This section list available customization options.
  161. Property Value Description
  162. -------------------------------------------
  163. mode bredr Enable BlueZ in BR/EDR mode
  164. le Enable BlueZ in LE mode
  165. <none> Enable BlueZ in default mode - enable BR/EDR/LE
  166. if available.
  167. handsfree hfp Enable Handsfree Profile (HFP) with narrowband
  168. speech only
  169. hfp_wbs Enable Handsfree Profile (HFP) with narrowband
  170. and wideband speech support
  171. <none> Don't enable Handsfree Profile (HFP)
  172. vendor <any> Set vendor name in DIS. If not set fallback to
  173. "ro.product.manufacturer".
  174. model <any> Set model name used as default adapter name.
  175. If not set fallback to "ro.product.model".
  176. name <any> Set model number in DIS. If not set fallback to
  177. "ro.product.name".
  178. serialno <any> Set serial number in DIS. If not set fallback to
  179. "ro.serialno".
  180. systemid <uint64> Set system ID in DIS. Hex string encoded uint64.
  181. pnpid <any> PnP information used in DIS and DID profiles.
  182. Required format: "Source:VID:PID:Version".
  183. Source must be either "bluetooth" or "usb".
  184. VID, PID and Version are uint16. Version is
  185. optional.
  186. fwrev <any> Firmware revision in DIS. If not set fallback to
  187. "ro.build.version.release".
  188. hwrew <any> Hardware revision in DIS. If not set fallback to
  189. "ro.board.platform".
  190. Building and running on Linux
  191. -----------------------------
  192. It is possible to build and test BlueZ for Android daemon on Linux (eg. PC).
  193. Simply follow instructions available at README file in BlueZ top directory.
  194. Android daemon binary is located at android/bluetoothd. See next section on
  195. how to test Android daemon on Linux.
  196. Testing tool
  197. ------------
  198. BT HAL test tools located in android/haltest is provided for HAL level testing
  199. of both Android daemon and HAL library. Start it with '-n' parameter and type
  200. 'bluetooth init' in prompt to initialize HAL library. Running without parameter
  201. will make haltest try to initialize all services after start. On Android
  202. required bluetoothd service will be started automatically. On Linux it is
  203. required to start android/bluetoothd manually before init command timeout or
  204. use provided android/system-emulator, which takes care of launching daemon
  205. automatically on HAL library initialization. To deinitialize HAL library and
  206. stop daemon type 'bluetooth cleanup'. Type 'help' for more information. Tab
  207. completion is also supported.
  208. Implementation status
  209. =====================
  210. Summary of HALs implementation status.
  211. complete - implementation is feature complete and Android Framework is able
  212. to use it normally
  213. partial - implementation is in progress and not all required features are
  214. present, Android Framework is able to use some of features
  215. initial - only initial implementations is present, Android Framework is
  216. able to initialize but most likely not able to use it
  217. not started - no implementation, Android Framework is not able to initialize it
  218. Profile ID HAL header 4.4 Status 5.0 status
  219. -------------------------------------------------------------
  220. core bluetooth.h complete partial
  221. a2dp bt_av.h complete complete
  222. gatt bt_gatt.h complete partial
  223. bt_gatt_client.h complete partial
  224. bt_gatt_server.h complete partial
  225. handsfree bt_hf.h complete complete
  226. hidhost bt_hh.h complete complete
  227. health bt_hl.h complete complete
  228. pan bt_pan.h complete complete
  229. avrcp bt_rc.h complete complete
  230. socket bt_sock.h complete partial
  231. handsfree_client bt_hf_client.h N/A complete
  232. map_client bt_mce.h N/A complete
  233. a2dp_sink bt_av.h N/A partial
  234. avrcp_ctrl bt_rc.h N/A partial
  235. Implementation shortcomings
  236. ===========================
  237. It is possible that some of HAL functionality (although being marked as
  238. complete) is missing implementation due to reasons like feature feasibility or
  239. necessity for latest Android Framework. This sections provides list of such
  240. deficiencies. Note that HAL library is always expected to fully implement HAL
  241. API so missing implementation might happen only in daemon.
  242. HAL Bluetooth
  243. -------------
  244. methods:
  245. dut_mode_send never called from Android Framework
  246. le_test_mode never called from Android Framework
  247. callbacks:
  248. dut_mode_recv_cb empty JNI implementation
  249. le_test_mode_cb empty JNI implementation
  250. properties:
  251. BT_PROPERTY_SERVICE_RECORD not supported for adapter, for device this
  252. property is returned as a response to
  253. get_remote_service_record call
  254. BT_PROPERTY_REMOTE_VERSION_INFO information required by this property (LMP
  255. information) are not accessible from mgmt
  256. interface, also marking this property as
  257. settable is probably a typo in HAL header
  258. HAL Socket
  259. ----------
  260. Support only for BTSOCK_RFCOMM socket type.
  261. HAL AVRCP
  262. ---------
  263. methods:
  264. list_player_app_attr_rsp never called from Android Framework
  265. list_player_app_value_rsp never called from Android Framework
  266. get_player_app_value_rsp never called from Android Framework
  267. get_player_app_attr_text_rsp never called from Android Framework
  268. get_player_app_value_text_rsp never called from Android Framework
  269. set_player_app_value_rsp never called from Android Framework
  270. callbacks:
  271. list_player_app_attr_cb NULL JNI implementation
  272. list_player_app_values_cb NULL JNI implementation
  273. get_player_app_value_cb NULL JNI implementation
  274. get_player_app_attrs_text_cb NULL JNI implementation
  275. get_player_app_values_text_cb NULL JNI implementation
  276. set_player_app_value_cb NULL JNI implementation
  277. HAL GATT
  278. --------
  279. methods:
  280. client->set_adv_data missing kernel support for vendor data
  281. client->connect is_direct parameter is ignored
  282. Audio SCO HAL
  283. =============
  284. When Bluetooth chip's audio is not wired directly to device audio, Audio SCO
  285. HAL is used to enable SCO support. It needs to be loaded by AudioFlinger
  286. following audio_policy.conf configuration. Example of configuration is shown
  287. below:
  288. ...
  289. sco {
  290. outputs {
  291. sco {
  292. sampling_rates 8000|44100
  293. channel_masks AUDIO_CHANNEL_OUT_STEREO
  294. formats AUDIO_FORMAT_PCM_16_BIT
  295. devices AUDIO_DEVICE_OUT_ALL_SCO
  296. }
  297. }
  298. inputs {
  299. sco {
  300. sampling_rates 8000|44100
  301. channel_masks AUDIO_CHANNEL_IN_MONO
  302. formats AUDIO_FORMAT_PCM_16_BIT
  303. devices AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET
  304. }
  305. }
  306. }
  307. ...
  308. Known Android issues
  309. ====================
  310. It is possible that BlueZ is triggering bugs on Android Framework that could
  311. affect qualification or user experience. This section provides list of
  312. recommended Android fixes that are not part of latest AOSP release supported by
  313. BlueZ.
  314. For Android 5.1 Lollipop:
  315. https://android-review.googlesource.com/177314
  316. For Android 5.0 Lollipop:
  317. https://android-review.googlesource.com/99761
  318. https://android-review.googlesource.com/100297
  319. https://android-review.googlesource.com/102882
  320. https://android-review.googlesource.com/132733
  321. https://android-review.googlesource.com/132763
  322. https://android-review.googlesource.com/177314
  323. For Android 4.4 KitKat:
  324. https://android-review.googlesource.com/82757
  325. https://android-review.googlesource.com/87670
  326. https://android-review.googlesource.com/88384
  327. https://android-review.googlesource.com/99761
  328. https://android-review.googlesource.com/99850
  329. https://android-review.googlesource.com/100297
  330. https://android-review.googlesource.com/102882
  331. https://android-review.googlesource.com/177314
  332. Unimplemented Bluetooth features
  333. ================================
  334. Some Bluetooth functionality require support from outside of BT stack
  335. eg. telephony stack. This sections describes profiles optional features not
  336. implemented due to lack of support in other Android subsystems or missing API
  337. in respective BT HALs.
  338. Profile Feature Comments
  339. --------------------------------------------------------
  340. HFP Attach a phone number to AT+BINP=1
  341. a voice tag
  342. HFP Enhanced Call Control AT+CHLD={1x,2x}
  343. HFP Explicit Call Transfer AT+CHLD=4
  344. HFP Response and Hold AT+BTRH, +BTRH
  345. HFP In-band Ring Tone +BSIR
  346. AVRCP Player Settings HAL API present but not used
  347. AVRCP Browsing No HAL API
  348. GATT Read multiple characteristics No HAL API
  349. Reporting Bugs
  350. ==============
  351. Bugs should be reported at https://01.org/jira/browse/BA. When reporting
  352. a bug please attach logs from logcat (logcat -v time) and HCI trace. Daemon
  353. debug logs should be enabled. When reporting daemon crash please run it under
  354. valgrind if possible. For details on how to enabled debug logs and valgrind see
  355. "Enabling BlueZ debugs" section.