Bug 1134821: Detect default Bluetooth backend, r=shuang

This patch adds code to select the default Bluetooth backend from a
list of supported ones, by detecting the backend's availability. Some
devices are missing bluetoothd support. With the patch, bluetoothd
can be the default backend, but unsupportive devices fall back to in-
Gecko Bluedroid.
This commit is contained in:
Thomas Zimmermann 2015-03-11 10:11:48 +01:00
parent b0c20457d4
commit 30b68c77dd

View File

@ -95,29 +95,43 @@ BluetoothInterface*
BluetoothInterface::GetInstance()
{
#if ANDROID_VERSION >= 17
/* We pick a default backend from the available ones. The branches
* are ordered by preference.
/* We pick a default backend from the available ones. The options are
* ordered by preference. If a backend is supported but not available
* on the current system, we pick the next one. The selected default
* can be overriden manually by storing the respective string in the
* system property 'ro.moz.bluetooth.backend'.
*/
#ifdef MOZ_B2G_BT_BLUEDROID
static const char sDefaultBackend[] = "bluedroid";
#else
#ifdef MOZ_B2G_BT_DAEMON
static const char sDefaultBackend[] = "bluetoothd";
#else
static const char* const sDefaultBackend = nullptr;
#endif
#endif
/* Here's where we decide which implementation to use. Currently
* there is only Bluedroid and the Bluetooth daemon, but others are
* possible. Having multiple interfaces built-in and selecting the
* correct one at runtime is also an option.
*/
static const char* const sDefaultBackend[] = {
#ifdef MOZ_B2G_BT_DAEMON
"bluetoothd",
#endif
#ifdef MOZ_B2G_BT_BLUEDROID
"bluedroid",
#endif
nullptr // no default backend; must be final element in array
};
const char* defaultBackend;
for (size_t i = 0; i < MOZ_ARRAY_LENGTH(sDefaultBackend); ++i) {
/* select current backend */
defaultBackend = sDefaultBackend[i];
if (defaultBackend) {
if (!strcmp(defaultBackend, "bluetoothd") &&
access("/init.bluetooth.rc", F_OK) == -1) {
continue; /* bluetoothd not available */
}
}
break;
}
char value[PROPERTY_VALUE_MAX];
int len;
len = property_get("ro.moz.bluetooth.backend", value, sDefaultBackend);
len = property_get("ro.moz.bluetooth.backend", value, defaultBackend);
if (len < 0) {
BT_WARNING("No Bluetooth backend available.");
return nullptr;
@ -125,6 +139,12 @@ BluetoothInterface::GetInstance()
const nsDependentCString backend(value, len);
/* Here's where we decide which implementation to use. Currently
* there is only Bluedroid and the Bluetooth daemon, but others are
* possible. Having multiple interfaces built-in and selecting the
* correct one at runtime is also an option.
*/
#ifdef MOZ_B2G_BT_BLUEDROID
if (backend.LowerCaseEqualsLiteral("bluedroid")) {
return BluetoothHALInterface::GetInstance();