1 /* -*- Mode: c++; c-basic-offset: 3; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "BluetoothInterface.h"
8 #if ANDROID_VERSION >= 17
9 #include <cutils/properties.h>
11 #ifdef MOZ_B2G_BT_BLUEDROID
12 #include "BluetoothHALInterface.h"
14 #ifdef MOZ_B2G_BT_DAEMON
15 #include "BluetoothDaemonInterface.h"
18 BEGIN_BLUETOOTH_NAMESPACE
24 BluetoothSocketInterface::~BluetoothSocketInterface()
28 // Handsfree Interface
31 // Notification handling
34 BluetoothHandsfreeNotificationHandler::
35 ~BluetoothHandsfreeNotificationHandler()
41 BluetoothHandsfreeInterface::BluetoothHandsfreeInterface()
44 BluetoothHandsfreeInterface::~BluetoothHandsfreeInterface()
48 // Bluetooth Advanced Audio Interface
51 // Notification handling
54 BluetoothA2dpNotificationHandler::~BluetoothA2dpNotificationHandler()
60 BluetoothA2dpInterface::BluetoothA2dpInterface()
63 BluetoothA2dpInterface::~BluetoothA2dpInterface()
67 // Bluetooth AVRCP Interface
70 // Notification handling
73 BluetoothAvrcpNotificationHandler::~BluetoothAvrcpNotificationHandler()
79 BluetoothAvrcpInterface::BluetoothAvrcpInterface()
82 BluetoothAvrcpInterface::~BluetoothAvrcpInterface()
85 // Notification handling
88 BluetoothNotificationHandler::~BluetoothNotificationHandler()
95 BluetoothInterface::GetInstance()
97 #if ANDROID_VERSION >= 17
98 /* We pick a default backend from the available ones. The options are
99 * ordered by preference. If a backend is supported but not available
100 * on the current system, we pick the next one. The selected default
101 * can be overriden manually by storing the respective string in the
102 * system property 'ro.moz.bluetooth.backend'.
105 static const char* const sDefaultBackend
[] = {
106 #ifdef MOZ_B2G_BT_DAEMON
109 #ifdef MOZ_B2G_BT_BLUEDROID
112 nullptr // no default backend; must be final element in array
115 const char* defaultBackend
;
117 for (size_t i
= 0; i
< MOZ_ARRAY_LENGTH(sDefaultBackend
); ++i
) {
119 /* select current backend */
120 defaultBackend
= sDefaultBackend
[i
];
122 if (defaultBackend
) {
123 if (!strcmp(defaultBackend
, "bluetoothd") &&
124 access("/init.bluetooth.rc", F_OK
) == -1) {
125 continue; /* bluetoothd not available */
131 char value
[PROPERTY_VALUE_MAX
];
134 len
= property_get("ro.moz.bluetooth.backend", value
, defaultBackend
);
136 BT_WARNING("No Bluetooth backend available.");
140 const nsDependentCString
backend(value
, len
);
142 /* Here's where we decide which implementation to use. Currently
143 * there is only Bluedroid and the Bluetooth daemon, but others are
144 * possible. Having multiple interfaces built-in and selecting the
145 * correct one at runtime is also an option.
148 #ifdef MOZ_B2G_BT_BLUEDROID
149 if (backend
.LowerCaseEqualsLiteral("bluedroid")) {
150 return BluetoothHALInterface::GetInstance();
153 #ifdef MOZ_B2G_BT_DAEMON
154 if (backend
.LowerCaseEqualsLiteral("bluetoothd")) {
155 return BluetoothDaemonInterface::GetInstance();
159 BT_WARNING("Bluetooth backend '%s' is unknown or not available.",
165 /* Anything that's not Android 4.2 or later uses BlueZ instead. The
166 * code should actually never reach this point.
168 BT_WARNING("No Bluetooth backend available for your system.");
173 BluetoothInterface::BluetoothInterface()
176 BluetoothInterface::~BluetoothInterface()
179 END_BLUETOOTH_NAMESPACE