Bug 1054242: Use Bluetooth Core notifications (under bluetooth2/), r=btian
authorThomas Zimmermann <tdz@users.sourceforge.net>
Tue, 02 Sep 2014 12:38:46 +0200
changeset 226215 d057f561350c70317643ca101f1ce7987aff134f
parent 226214 a9d8bf297d25c93e6ac7db3adad2a9b2d8b2d575
child 226216 57ba95fb155569446e4a3266b0e4d083c7b64ac4
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbtian
bugs1054242
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1054242: Use Bluetooth Core notifications (under bluetooth2/), r=btian This patch connects backend and Gecko side of the notification code. Gecko will now receive notifications instead of Bluedroid callbacks.
dom/bluetooth2/bluedroid/BluetoothInterface.cpp
dom/bluetooth2/bluedroid/BluetoothInterface.h
dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.cpp
--- a/dom/bluetooth2/bluedroid/BluetoothInterface.cpp
+++ b/dom/bluetooth2/bluedroid/BluetoothInterface.cpp
@@ -2943,23 +2943,25 @@ struct BluetoothCallback
   static void
   DutModeRecv(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen)
   {
     DutModeRecvNotification::Dispatch(
       &BluetoothNotificationHandler::DutModeRecvNotification,
       aOpcode, ConvertArray<uint8_t>(aBuf, aLen), aLen);
   }
 
+#if ANDROID_VERSION >= 18
   static void
   LeTestMode(bt_status_t aStatus, uint16_t aNumPackets)
   {
     LeTestModeNotification::Dispatch(
       &BluetoothNotificationHandler::LeTestModeNotification,
       aStatus, aNumPackets);
   }
+#endif // ANDROID_VERSION >= 18
 };
 
 // Interface
 //
 
 /* returns the container structure of a variable; _t is the container's
  * type, _v the name of the variable, and _m is _v's field within _t
  */
@@ -3027,36 +3029,59 @@ BluetoothInterface::BluetoothInterface(c
 {
   MOZ_ASSERT(mInterface);
 }
 
 BluetoothInterface::~BluetoothInterface()
 { }
 
 void
-BluetoothInterface::Init(bt_callbacks_t* aCallbacks,
+BluetoothInterface::Init(BluetoothNotificationHandler* aNotificationHandler,
                          BluetoothResultHandler* aRes)
 {
-  int status = mInterface->init(aCallbacks);
+  static bt_callbacks_t sBluetoothCallbacks = {
+    sizeof(sBluetoothCallbacks),
+    BluetoothCallback::AdapterStateChanged,
+    BluetoothCallback::AdapterProperties,
+    BluetoothCallback::RemoteDeviceProperties,
+    BluetoothCallback::DeviceFound,
+    BluetoothCallback::DiscoveryStateChanged,
+    BluetoothCallback::PinRequest,
+    BluetoothCallback::SspRequest,
+    BluetoothCallback::BondStateChanged,
+    BluetoothCallback::AclStateChanged,
+    BluetoothCallback::ThreadEvt,
+    BluetoothCallback::DutModeRecv
+#if ANDROID_VERSION >= 18
+    ,
+    BluetoothCallback::LeTestMode
+#endif
+  };
+
+  sNotificationHandler = aNotificationHandler;
+
+  int status = mInterface->init(&sBluetoothCallbacks);
 
   if (aRes) {
     DispatchBluetoothResult(aRes, &BluetoothResultHandler::Init,
                             ConvertDefault(status, STATUS_FAIL));
   }
 }
 
 void
 BluetoothInterface::Cleanup(BluetoothResultHandler* aRes)
 {
   mInterface->cleanup();
 
   if (aRes) {
     DispatchBluetoothResult(aRes, &BluetoothResultHandler::Cleanup,
                             STATUS_SUCCESS);
   }
+
+  sNotificationHandler = nullptr;
 }
 
 void
 BluetoothInterface::Enable(BluetoothResultHandler* aRes)
 {
   int status = mInterface->enable();
 
   if (aRes) {
--- a/dom/bluetooth2/bluedroid/BluetoothInterface.h
+++ b/dom/bluetooth2/bluedroid/BluetoothInterface.h
@@ -414,17 +414,18 @@ public:
   virtual void LeTestMode() { }
 };
 
 class BluetoothInterface
 {
 public:
   static BluetoothInterface* GetInstance();
 
-  void Init(bt_callbacks_t* aCallbacks, BluetoothResultHandler* aRes);
+  void Init(BluetoothNotificationHandler* aNotificationHandler,
+            BluetoothResultHandler* aRes);
   void Cleanup(BluetoothResultHandler* aRes);
 
   void Enable(BluetoothResultHandler* aRes);
   void Disable(BluetoothResultHandler* aRes);
 
 
   /* Adapter Properties */
 
--- a/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.cpp
+++ b/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.cpp
@@ -917,17 +917,18 @@ StartGonkBluetooth()
     // Keep current enable status
     nsRefPtr<nsRunnable> runnable = new BluetoothService::ToggleBtAck(true);
     if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
       BT_WARNING("Failed to dispatch to main thread!");
     }
     return NS_OK;
   }
 
-  sBtInterface->Init(&sBluetoothCallbacks, new InitResultHandler());
+  sBtInterface->Init(reinterpret_cast<BluetoothServiceBluedroid*>(bs),
+                     new InitResultHandler());
 
   return NS_OK;
 }
 
 class DisableResultHandler MOZ_FINAL : public BluetoothResultHandler
 {
 public:
   void OnError(BluetoothStatus aStatus) MOZ_OVERRIDE