| Did you know...? LWN.net is a subscriber-supported publication; we rely on subscribers to keep the entire operation going. Please help out by buying a subscription and keeping LWN on the net. |
Toward the end of 2012, Google switched the Bluetooth stack in Android—for reasons unknown, though there has always been speculation about licensing—from the GPL-licensed BlueZ to the Apache-licensed BlueDroid. That switch was for the release of Android 4.2 (one of the Jelly Bean releases). Since the switch, though, Intel and the BlueZ project have been working to restore the option of running Android with BlueZ, which provides a whole raft of additional features lacking in BlueDroid. Marcel Holtmann of the Intel Open Source Technology Center reported on the BlueZ option at the Android Builders Summit (ABS) held in San Jose, CA, April 29–May 1.
After the October 2012 Android release with BlueDroid, the initial reviews of the new stack were "not that good", Holtmann said, which is not a huge surprise for a completely new Bluetooth stack. As it turns out, based on Google's February 2014 numbers, 73% of Android devices are actually still running BlueZ because they are running earlier releases. The initial release of Google Glass ran BlueZ as well.
From the perspective of the BlueZ developers, one good thing that came out of the BlueDroid switch was the addition of a Bluetooth hardware abstraction layer (HAL). That meant that Google engineers had to think about and define what features to expose and how to expose them. In the end, Google added a Bluetooth Core HAL and a Profile HAL, he said.
When it was added, BlueDroid was said to be "tiny", but it turns out to be 286K lines of C and C++ code. There are a number of limitations to BlueDroid, Holtmann said. For example, the entire stack, which includes the Bluetooth service, HAL layers, and BlueDroid itself, all runs in a single process.
But there is much more to be concerned about with BlueDroid, according to Holtmann. He had a list of more than a dozen items that are missing or sub-par in BlueDroid. To start with, every new hardware device that will be supported needs to fork the source of BlueDroid. There is build-time configuration for the stack, including which profiles are included and what hardware features are enabled. So there is no single BlueDroid tree with support for multiple hardware platforms. The Android open source project (AOSP) only provides trees for three Nexus devices (4, 5, and 7) which are based on either Broadcom or Qualcomm hardware.
Anything more complicated than supporting the serial (UART) interface to the hardware requires that a kernel shim driver be written, which means that devices connected via USB, PCI, SPI, etc. will require drivers to be written. In addition, the bus power management is done in user space, which we have learned is "not a good idea".
BlueDroid is a lot of new code being introduced into devices, without any kind of known security audit. The Git history for the repository starts in December 2012 and has a grand total of 140 commits. Worse yet, those commits are often huge and don't have commit messages that explain what is being done or why. There is little documentation provided, essentially just the examples, and there are no unit tests.
The stack itself suffers from audio latency problems. Part of that is due to the large number of context switches required for handling every audio frame, host controller interface (HCI) packet, network packet, and other communications. The initial release of BlueDroid had no support for debugging; recompiling was required to get debugging output. Things are a bit better with the Android 4.4 (KitKat) release of BlueDroid, though, he said.
There is no Intel architecture (IA) optimization for the required SBC audio codec, nor support for other Intel-only features, which is obviously a problem for Intel and its customers, he said. The 64-bit support for BlueDroid is unclear as well. Much of it has only been compile-tested on ARM, Holtmann said.
Beyond all of that, BlueDroid is not Bluetooth-certified except for the proprietary Broadcom AirForceBT stack that also uses the Bluetooth HALs. Support for Bluetooth 4.1 is left up to the device makers; BlueDroid only provides code for Bluetooth 4.0.
Given all of that, one might ask why Google switched away from BlueZ (which doesn't have most of the problems identified), as one audience member did. Holtmann said that he has heard rumors about why the switch was made, but that he didn't want to spread them. He is, however, interested in finding out, and suggested that someone from Google should explain the choice. Google attendees were in short supply at ABS; if any were present at the talk, they didn't seem willing (or able) to answer that particular question.
There are now two different ways to support BlueZ features on Android devices. The first is a port of BlueDroid to use the existing Linux kernel drivers for Bluetooth. That allows devices to use all of the existing drivers, so Bluetooth is not limited to just the UART interface, as USB, SDIO, PCMCIA (if you can still find such devices), and others are available. There is a "tiny shim layer" of around 100 lines of kernel code that the upper layers of BlueDroid talk to.
That alternative is called "BlueDroid with HCI user channel" and "it works pretty well", Holtmann said. It allows a few of the problems identified with BlueDroid to be crossed off the list (user-space power management, only a few reference devices, new drivers required, limited debugging capabilities), but most of the rest remain. Fixing those problem is the goal of the second alternative: "BlueZ for Android".
BlueZ for Android (BfA) provides a "drop-in replacement" for BlueDroid, which means that apps do not need to change. That is also true for the HCI user channel alternative since it sits below BlueDroid. The D-Bus APIs that BlueZ normally uses have been replaced by integration with the Android Bluetooth HALs. BfA brings Bluetooth 4.1 support, as well as documentation and a wide of range of tests. It supports an even dozen profiles, with the Health Device Profile (HDP) currently being worked on.
It is a low-latency stack that also supports lower-power audio. BlueZ has had 64-bit support for some time now, as well as codecs optimized for the Intel architecture. It also supports Intel's hardware advanced encryption standard (AES) processing and hardware random number generation (RDRAND instruction). The code has been used and tested in a variety of different desktop and mobile platforms over many years, including Android.
The laundry list of BlueDroid deficiencies also dropped to near zero by swapping BlueZ in. There are still too many context switches for human interface device (HID) reports and radio frequency communication (RFCOMM) streams, but the project is working on eliminating those as well. Other than that, everything on the list has been addressed.
In addition, BfA has been developed as part of the open-source BlueZ project. Its Git repository stretches back much further, with many more, well-documented commits. It is also notable that BlueZ is on its way toward switching to the LGPL. Roughly 80% of the code is already licensed that way, with more coming, though it was not clear when that job would be finished.
While it was never said in the presentation, the clear implication of Holtmann's talk was that Google made a poor choice in switching to BlueDroid. The addition of the Bluetooth HALs was good, but BlueDroid itself simply did not have the right architecture or feature set. Unless Google puts a lot of effort into BlueDroid development, it will likely fall further behind, as things like Bluetooth 4.2 are on the horizon. But it would seem that device makers already have an alternative—it will be interesting to see if (and how much) it gets used.
Thanks
Posted May 6, 2014 19:34 UTC (Tue) by ncm (subscriber, #165) [Link]
Returning BlueZ to Android
Posted May 6, 2014 20:31 UTC (Tue) by javispedro (subscriber, #83660) [Link]
One might argue that such a flurry of Android-only activity is also indirectly helping the normal BlueZ, but this doesn't seem to be the case. In fact, the quality of the Bluetooth stack in the desktop GNU/Linux environments seems to be dropping rapidly:
- Hands-free / Headset support has been broken in Fedora and all distros using BlueZ 5
https://lists.fedoraproject.org/pipermail/devel/2014-Janu...
There seems to be no fix in the horizon. Suggestions are to install ofono, but ofono conflicts with ModemManager, which is a requirement of NetworkManager...
- Similarly, Dial-up Networking is also broken:
https://bugzilla.redhat.com/show_bug.cgi?id=1055628
No fix in the horizon either because (AIUI) Network/ModemManager expects to use /dev/rfcomm* nodes which are now a deprecated API...
- Still no D-Bus API for GATT (a requirement for Bluetooth Smart peripherals).
The fun/ironic thing is that these features are working nicely in Android. Part of the reason is that, in Android, Google is mandating the Bluetooth API (the HAL), keeping it stable between releases, and thus avoiding the periodic API breakage that causes issues like the above everytime there is a major Bluez release.
This may be an example of a benefit of the Google-cathedral development style... even if I don't like Google nor the cathedral style.
Returning BlueZ to Android
Posted May 7, 2014 3:24 UTC (Wed) by mathstuf (subscriber, #69389) [Link]
I think this is because there was some interface supported in BlueZ 4 which wasn't implemented in 5. IIRC, there was no intention to reimplement it.
Returning BlueZ to Android
Posted May 7, 2014 10:22 UTC (Wed) by vudentz (guest, #57202) [Link]
- Regarding ModemManager conflicting with oFono that is distro's choice, there are other options including replacing ModemManager with oFono as Ubuntu touch did, or use connman instead of NetworkManager as jolla did.
- GATT API is in progress
Btw, Bluetooth on Android does not work nicely, Android HAL has been broken already and considering its current state it will probably be broken again when 4.1/4.2 support is finally added.
The difference is that we don't glue things together, and perhaps the mistake was not to keep backward compatibility but nowadays we have version number on interfaces so this should no longer happen.
Returning BlueZ to Android
Posted May 7, 2014 13:29 UTC (Wed) by tcourbon (subscriber, #60669) [Link]
As far I understand your statement, you prove his point.
There is indeed a regression between BlueZ4 and 5. The fact some other software package may or may not solve this regression is irrelevant. In part because it depends on the other package's developer and the availability/version of said package in your distribution of choice's repositories.
I do not know whether the decision taken by the BlueZ team is right or wrong (maybe it relieve the team of a huge maintenance burden, I dunno), but the fact holds.
Returning BlueZ to Android
Posted May 7, 2014 15:12 UTC (Wed) by javispedro (subscriber, #83660) [Link]
No, there will not be Headset Profile for PulseAudio _without_ ofono. I've already based my observations on reading ML and asking questions around (how else could I?).
In fact, after asking around, I've already forward-ported org.bluez.Serial support to Bluez5 (without much difficulty, TBH) and was starting doing the same with HFP support.
Ubuntu did not replace ModemManager, they just made a ModemManager->Ofono bridge. I suppose it works very well for their use case (phones) but not at all for us desktop users (I tried on my desktop -- it doesn't even know what to do with Bluetooth devices).
While, personally, as a Jolla user, I would be accepting of using connman instead of NetworkManager, do you really want Gnome, etc. to start another NM vs connman flame war? Gnome-shell is currently NM-only, and while I was notified of extensions for connman, they are not upstreamed, and I'm not sure if they ever will... (note this last assertion is a unsourced prediction based on previous flamewars).
But the following is what I really dislike most, since I've read it in several places already:
we have version number on interfaces so this should no longer happen.
I don't believe that. It will happen again. And again and again.
Does anyone really believe for a second that what prevents Bluez from offering stable interfaces was the lack of version numbers? A numerical suffix on the D-Bus interface names?
If anyone actually cared about providing backwards compatibility they'd have just kept providing the old interfaces with the version-less names. Instead, they were removed -- for what appears to me as no apparent reason, specially after checking how easy it was to put the Serial interface back in Bluez5.
Again, no criticism intended, because I suspect and accept there's just not enough manpower to keep all the old interfaces "up to date" in BlueZ, specially with all the changes coming in from BluezAndroid, and so they're readily removed when they slow "progress". And that if we us "old dinasours" really care about support for basic Bluetooth profiles in non-Android platforms, we should be the ones sending in the patches.
Returning BlueZ to Android
Posted May 8, 2014 8:50 UTC (Thu) by vudentz (guest, #57202) [Link]
Im actually a bit surprised you choose to discuss this here and not in the mailing list, serial port is also supported you just need to register via org.bluez.ProfileManager1, which is how Handsfree and Headset profile can be supported as well.
I will not comment about NM vs connman or MM vs oFono, as I said this is a distro's choice.
No comments about backward compatibility, this really does not belong here, if you want to contribute then do it.
Returning BlueZ to Android
Posted May 8, 2014 19:55 UTC (Thu) by deepfire (guest, #26138) [Link]
So, you broke support for a large group of users AND are cavalier about it?
Returning BlueZ to Android
Posted May 8, 2014 22:46 UTC (Thu) by javispedro (subscriber, #83660) [Link]
And ProfileManager1 basically seems to only replace SDP. Abilities like, creating /dev/rfcomm* device nodes, or well, actually get audio channels are not exported via it. Without the ability to create /dev/rfcomm* nodes, ModemManager (and the API it offers) would need a heavy redesign -- and that's much harder than just forwardporting org.bluez.Serial back to 5.0 .
Returning BlueZ to Android
Posted May 7, 2014 15:20 UTC (Wed) by javispedro (subscriber, #83660) [Link]
In fact, it seems to me, by following progress, that the Android HAL API "frontend" is by now more featureful than the D-Bus API.
Either coding for the Android HAL is just easier or the sad truth is there's just much more free software developer interest in Android than on the Linux desktop these days.
Returning BlueZ to Android
Posted May 8, 2014 15:37 UTC (Thu) by drag (subscriber, #31333) [Link]
This.
People will tend to want to stick with what they know and use. If people don't use Linux at home or on their laptop they are not going to give a crap.
This is why many people struggle to get 'AMP' stack working well on Windows and then shove that into 'the cloud' despite the fact that Linux would offer significant advantages in performance and reduction is costs.
Returning BlueZ to Android
Posted May 9, 2014 17:25 UTC (Fri) by dashesy (guest, #74652) [Link]
My first thought when I first heard about the switch was exactly that, Android 4.3 finally has a fully reliable BLE support. Android wants to compete with iOS, or users will switch on the next wave of wearables.
Returning BlueZ to Android
Posted May 7, 2014 16:04 UTC (Wed) by fandingo (subscriber, #67019) [Link]
Connman is an unacceptable replacement. It's DBus API is incompatible with NetworkManager's and is rather incomplete and featureless. Most interaction that users (or their applications) have with their connection manager is via DBus.
Returning BlueZ to Android
Posted May 9, 2014 7:06 UTC (Fri) by pflykt (subscriber, #2757) [Link]
There is always the upstream mailing list where one can point out which of the features are missing. Maybe it is something that was just overlooked and can be easily fixed, maybe it is something else that is way more difficult to achieve. Unless someone points out the missing features, they will unfortunately stay missing.
Returning BlueZ to Android
Posted May 10, 2014 7:35 UTC (Sat) by marcH (subscriber, #57642) [Link]
Future tense = argument lost.
Returning BlueZ to Android
Posted May 7, 2014 4:19 UTC (Wed) by dashesy (guest, #74652) [Link]
Returning BlueZ to Android
Posted May 7, 2014 7:04 UTC (Wed) by pbonzini (subscriber, #60935) [Link]
In the case of Qt, there seems to be a way to do the opposite, namely let the GLib main loop dispatch Qt events.
Returning BlueZ to Android
Posted May 7, 2014 7:18 UTC (Wed) by ovitters (subscriber, #27950) [Link]
Returning BlueZ to Android
Posted May 7, 2014 15:14 UTC (Wed) by javispedro (subscriber, #83660) [Link]
Returning BlueZ to Android
Posted May 8, 2014 0:33 UTC (Thu) by ppisa (subscriber, #67307) [Link]
Problem is g_source_add_poll() function. It seems that later Glib versions add and suggest to use g_source_add_unix_fd() function instead. But I have not analyzed if there is chance, that next ABI change allows to switch to flexible backends - i.e allows poll, epoll or kevent selection.
So there is fundamental problem with Glib in actual version and requirement for Glib and other frameworks (i.e. Qt) libraries coexistence in same process/on same even distribution mechanism can be resolved only by bending even better API (i.e. Qt signal slot based event notifiers) to use Glib as base implementation.
So there is fundamental problem to solve one day (in next 20 years). I have resolved that problem for myself projects by yet another layer which can live above glib, libevent or directly on poll/epoll and even cascade main loop mechanism (own epoll events based) inserted into glib events base. But ul_evpoll is small project without real manpower for maintenance. It cannot compete with libevent2 which has later provided quite nice API. But libevent2 cannot live above Glib and Glib cannot live above libevent2. And when Glib targets for GNU/Linux common C low level framework (which it already is in the fact) then this performance problem has to be resolved and it would mean to break Glib actual ABI.
Returning BlueZ to Android
Posted May 8, 2014 7:24 UTC (Thu) by nzjrs (guest, #35911) [Link]
Returning BlueZ to Android
Posted May 8, 2014 9:39 UTC (Thu) by ppisa (subscriber, #67307) [Link]
I have not analyzed latest pollers branch enough to be sure about epoll mechanism implementation. But N:M mapping between GSources and underlaying epoll_ctl registered struct epoll_event-s is required and I hope that it is included in proposed implementation.
Returning BlueZ to Android
Posted May 8, 2014 11:33 UTC (Thu) by nzjrs (guest, #35911) [Link]
https://bugzilla.gnome.org/show_bug.cgi?id=704374#c18
The problem with an old project with a public bug tracker is that one can choose trends over arbitrary time spans to make whatever point one wishes.
I prefer an interpretation where recent glib development is healthy and accelerating, rather than the opposite as one might get by integrating over >10 years.
Returning BlueZ to Android
Posted May 8, 2014 4:04 UTC (Thu) by jackb (subscriber, #41909) [Link]
Given all of that, one might ask why Google switched away from BlueZ (which doesn't have most of the problems identified), as one audience member did. Holtmann said that he has heard rumors about why the switch was made, but that he didn't want to spread them. He is, however, interested in finding out, and suggested that someone from Google should explain the choice. Google attendees were in short supply at ABS; if any were present at the talk, they didn't seem willing (or able) to answer that particular question.It's always good to keep in mind that what constitutes a "feature" vs a "bug" is a matter of perspective, and also that Google's customers are not the people who use Android devices.
BlueDroid is a lot of new code being introduced into devices, without any kind of known security audit. The Git history for the repository starts in December 2012 and has a grand total of 140 commits. Worse yet, those commits are often huge and don't have commit messages that explain what is being done or why. There is little documentation provided, essentially just the examples, and there are no unit tests.Unless Google offers an alternate explanation, I'm going to assume this is the reason they switched. BlueDroid offers the features their customers were demanding.
Returning BlueZ to Android
Posted May 10, 2014 7:48 UTC (Sat) by marcH (subscriber, #57642) [Link]
Interesting... can anyone with some understanding of the code prove that BlueDroid actually makes any kind of difference here? On the surface it's hard to see why you would need a special stack to achieve this type of surveillance; any would do.
More rumours about the switch please! If rumours are not posted in comments sections, where would they be? It should be quick enough to open a throw-away LWN account ;-)
Returning BlueZ to Android
Posted May 10, 2014 14:48 UTC (Sat) by raven667 (subscriber, #5198) [Link]
Returning BlueZ to Android
Posted May 12, 2014 20:10 UTC (Mon) by lmb (subscriber, #39048) [Link]
That'd make audio on Android a lot more usable.
Returning BlueZ to Android
Posted Dec 2, 2014 9:14 UTC (Tue) by JerryzKeys (guest, #100063) [Link]
Returning BlueZ to Android
Posted Dec 2, 2014 13:04 UTC (Tue) by tao (subscriber, #17563) [Link]
Copyright © 2014, Eklektix, Inc.
This article may be redistributed under the terms of the
Creative
Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds