Bumping manifests a=b2g-bump
[gecko.git] / dom / bluetooth / BluetoothInterface.cpp
blob03ba3461d58c36771a5ae89b02d1626720f5748e
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>
10 #endif
11 #ifdef MOZ_B2G_BT_BLUEDROID
12 #include "BluetoothHALInterface.h"
13 #endif
14 #ifdef MOZ_B2G_BT_DAEMON
15 #include "BluetoothDaemonInterface.h"
16 #endif
18 BEGIN_BLUETOOTH_NAMESPACE
21 // Socket Interface
24 BluetoothSocketInterface::~BluetoothSocketInterface()
25 { }
28 // Handsfree Interface
31 // Notification handling
34 BluetoothHandsfreeNotificationHandler::
35 ~BluetoothHandsfreeNotificationHandler()
36 { }
38 // Interface
41 BluetoothHandsfreeInterface::BluetoothHandsfreeInterface()
42 { }
44 BluetoothHandsfreeInterface::~BluetoothHandsfreeInterface()
45 { }
48 // Bluetooth Advanced Audio Interface
51 // Notification handling
54 BluetoothA2dpNotificationHandler::~BluetoothA2dpNotificationHandler()
55 { }
57 // Interface
60 BluetoothA2dpInterface::BluetoothA2dpInterface()
61 { }
63 BluetoothA2dpInterface::~BluetoothA2dpInterface()
64 { }
67 // Bluetooth AVRCP Interface
70 // Notification handling
73 BluetoothAvrcpNotificationHandler::~BluetoothAvrcpNotificationHandler()
74 { }
76 // Interface
79 BluetoothAvrcpInterface::BluetoothAvrcpInterface()
80 { }
82 BluetoothAvrcpInterface::~BluetoothAvrcpInterface()
83 { }
85 // Notification handling
88 BluetoothNotificationHandler::~BluetoothNotificationHandler()
89 { }
91 // Interface
94 BluetoothInterface*
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
107 "bluetoothd",
108 #endif
109 #ifdef MOZ_B2G_BT_BLUEDROID
110 "bluedroid",
111 #endif
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 */
128 break;
131 char value[PROPERTY_VALUE_MAX];
132 int len;
134 len = property_get("ro.moz.bluetooth.backend", value, defaultBackend);
135 if (len < 0) {
136 BT_WARNING("No Bluetooth backend available.");
137 return nullptr;
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();
151 } else
152 #endif
153 #ifdef MOZ_B2G_BT_DAEMON
154 if (backend.LowerCaseEqualsLiteral("bluetoothd")) {
155 return BluetoothDaemonInterface::GetInstance();
156 } else
157 #endif
159 BT_WARNING("Bluetooth backend '%s' is unknown or not available.",
160 backend.get());
162 return nullptr;
164 #else
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.");
169 return nullptr;
170 #endif
173 BluetoothInterface::BluetoothInterface()
176 BluetoothInterface::~BluetoothInterface()
179 END_BLUETOOTH_NAMESPACE