Bug 1102703 - Porting bluetooth interface of bluez 5.26 (core). r=btian, f=tzimmermann
☠☠ backed out by b4926227268f ☠ ☠
authorBruce Sun <brsun@mozilla.com>
Thu, 08 Jan 2015 11:49:17 +0800
changeset 222673 f62155e4fb9c32f91e21395bab8b870b992f0388
parent 222672 ff47d1b9e86cd3cb2e56c5ab36011161e65de5b3
child 222674 b61bf281e9910a32f2084e99aabf1f7f45438d74
push id28071
push userkwierso@gmail.com
push dateFri, 09 Jan 2015 00:54:55 +0000
treeherdermozilla-central@ccfafae7330f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbtian
bugs1102703
milestone37.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 1102703 - Porting bluetooth interface of bluez 5.26 (core). r=btian, f=tzimmermann
dom/bluetooth/bluedroid/BluetoothDaemonA2dpInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonA2dpInterface.h
dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.h
dom/bluetooth/bluedroid/BluetoothDaemonHelpers.cpp
dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.h
--- a/dom/bluetooth/bluedroid/BluetoothDaemonA2dpInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonA2dpInterface.cpp
@@ -9,16 +9,18 @@
 #include "mozilla/unused.h"
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 //
 // A2DP module
 //
 
+const int BluetoothDaemonA2dpModule::MAX_NUM_CLIENTS = 1;
+
 BluetoothA2dpNotificationHandler*
   BluetoothDaemonA2dpModule::sNotificationHandler;
 
 void
 BluetoothDaemonA2dpModule::SetNotificationHandler(
   BluetoothA2dpNotificationHandler* aNotificationHandler)
 {
   sNotificationHandler = aNotificationHandler;
@@ -337,17 +339,17 @@ BluetoothDaemonA2dpInterface::Init(
   if (aRes) {
     res = new InitResultHandler(aRes);
   } else {
     // We don't need a result handler if the caller is not interested.
     res = nullptr;
   }
 
   nsresult rv = mModule->RegisterModule(BluetoothDaemonA2dpModule::SERVICE_ID,
-                                        0x00, res);
+    0x00, BluetoothDaemonA2dpModule::MAX_NUM_CLIENTS, res);
   if (NS_FAILED(rv) && aRes) {
     DispatchError(aRes, STATUS_FAIL);
   }
 }
 
 class BluetoothDaemonA2dpInterface::CleanupResultHandler MOZ_FINAL
   : public BluetoothSetupResultHandler
 {
--- a/dom/bluetooth/bluedroid/BluetoothDaemonA2dpInterface.h
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonA2dpInterface.h
@@ -23,19 +23,22 @@ public:
   };
 
   enum {
     OPCODE_ERROR = 0x00,
     OPCODE_CONNECT = 0x01,
     OPCODE_DISCONNECT = 0x02
   };
 
+  static const int MAX_NUM_CLIENTS;
+
   virtual nsresult Send(BluetoothDaemonPDU* aPDU, void* aUserData) = 0;
 
   virtual nsresult RegisterModule(uint8_t aId, uint8_t aMode,
+                                  uint32_t aMaxNumClients,
                                   BluetoothSetupResultHandler* aRes) = 0;
 
   virtual nsresult UnregisterModule(uint8_t aId,
                                     BluetoothSetupResultHandler* aRes) = 0;
 
   void SetNotificationHandler(
     BluetoothA2dpNotificationHandler* aNotificationHandler);
 
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.cpp
@@ -1313,17 +1313,18 @@ BluetoothDaemonHandsfreeInterface::Init(
   if (aRes) {
     res = new InitResultHandler(aRes);
   } else {
     // We don't need a result handler if the caller is not interested.
     res = nullptr;
   }
 
   nsresult rv = mModule->RegisterModule(
-    BluetoothDaemonHandsfreeModule::SERVICE_ID, MODE_NARROWBAND_SPEECH, res);
+    BluetoothDaemonHandsfreeModule::SERVICE_ID, MODE_NARROWBAND_SPEECH,
+    aMaxNumClients, res);
 
   if (NS_FAILED(rv) && aRes) {
     DispatchError(aRes, STATUS_FAIL);
   }
 }
 
 class BluetoothDaemonHandsfreeInterface::CleanupResultHandler MOZ_FINAL
   : public BluetoothSetupResultHandler
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.h
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.h
@@ -38,16 +38,17 @@ public:
     OPCODE_AT_RESPONSE = 0x0c,
     OPCODE_CLCC_RESPONSE = 0x0d,
     OPCODE_PHONE_STATE_CHANGE = 0x0e
   };
 
   virtual nsresult Send(BluetoothDaemonPDU* aPDU, void* aUserData) = 0;
 
   virtual nsresult RegisterModule(uint8_t aId, uint8_t aMode,
+                                  uint32_t aMaxNumClients,
                                   BluetoothSetupResultHandler* aRes) = 0;
 
   virtual nsresult UnregisterModule(uint8_t aId,
                                     BluetoothSetupResultHandler* aRes) = 0;
 
   void SetNotificationHandler(
     BluetoothHandsfreeNotificationHandler* aNotificationHandler);
 
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.cpp
@@ -1255,16 +1255,22 @@ PackPDU(const BluetoothServiceName& aIn,
 
 nsresult
 PackPDU(BluetoothSocketType aIn, BluetoothDaemonPDU& aPDU)
 {
   return PackPDU(PackConversion<BluetoothSocketType, uint8_t>(aIn), aPDU);
 }
 
 nsresult
+PackPDU(BluetoothTransport aIn, BluetoothDaemonPDU& aPDU)
+{
+  return PackPDU(PackConversion<BluetoothTransport, uint8_t>(aIn), aPDU);
+}
+
+nsresult
 PackPDU(ControlPlayStatus aIn, BluetoothDaemonPDU& aPDU)
 {
   return PackPDU(PackConversion<ControlPlayStatus, uint8_t>(aIn), aPDU);
 }
 
 //
 // Unpacking
 //
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
@@ -414,16 +414,19 @@ PackPDU(BluetoothSocketType aIn, Bluetoo
 
 nsresult
 PackPDU(BluetoothSspPairingVariant aIn, BluetoothDaemonPDU& aPDU);
 
 nsresult
 PackPDU(BluetoothScanMode aIn, BluetoothDaemonPDU& aPDU);
 
 nsresult
+PackPDU(BluetoothTransport aIn, BluetoothDaemonPDU& aPDU);
+
+nsresult
 PackPDU(ControlPlayStatus aIn, BluetoothDaemonPDU& aPDU);
 
 /* |PackConversion| is a helper for packing converted values. Pass
  * an instance of this structure to |PackPDU| to convert a value from
  * the input type to the output type and and write it to the PDU.
  */
 template<typename Tin, typename Tout>
 struct PackConversion {
--- a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
@@ -26,23 +26,28 @@ class BluetoothDaemonSetupModule
 {
 public:
   virtual nsresult Send(BluetoothDaemonPDU* aPDU, void* aUserData) = 0;
 
   // Commands
   //
 
   nsresult RegisterModuleCmd(uint8_t aId, uint8_t aMode,
+                             uint32_t aMaxNumClients,
                              BluetoothSetupResultHandler* aRes)
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     nsAutoPtr<BluetoothDaemonPDU> pdu(new BluetoothDaemonPDU(0x00, 0x01, 0));
 
+#if ANDROID_VERSION >= 21
+    nsresult rv = PackPDU(aId, aMode, aMaxNumClients, *pdu);
+#else
     nsresult rv = PackPDU(aId, aMode, *pdu);
+#endif
     if (NS_FAILED(rv)) {
       return rv;
     }
     rv = Send(pdu, aRes);
     if (NS_FAILED(rv)) {
       return rv;
     }
     unused << pdu.forget();
@@ -183,16 +188,19 @@ private:
 // Core module
 //
 
 static BluetoothNotificationHandler* sNotificationHandler;
 
 class BluetoothDaemonCoreModule
 {
 public:
+
+  static const int MAX_NUM_CLIENTS;
+
   virtual nsresult Send(BluetoothDaemonPDU* aPDU, void* aUserData) = 0;
 
   nsresult EnableCmd(BluetoothResultHandler* aRes)
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     nsAutoPtr<BluetoothDaemonPDU> pdu(new BluetoothDaemonPDU(0x01, 0x01, 0));
 
@@ -408,18 +416,23 @@ public:
   nsresult CreateBondCmd(const nsAString& aBdAddr,
                          BluetoothTransport aTransport,
                          BluetoothResultHandler* aRes)
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     nsAutoPtr<BluetoothDaemonPDU> pdu(new BluetoothDaemonPDU(0x01, 0x0d, 0));
 
+#if ANDROID_VERSION >= 21
+    nsresult rv = PackPDU(
+      PackConversion<nsAString, BluetoothAddress>(aBdAddr), aTransport, *pdu);
+#else
     nsresult rv = PackPDU(
       PackConversion<nsAString, BluetoothAddress>(aBdAddr), *pdu);
+#endif
     if (NS_FAILED(rv)) {
       return rv;
     }
     rv = Send(pdu, aRes);
     if (NS_FAILED(rv)) {
       return rv;
     }
     unused << pdu.forget();
@@ -1349,16 +1362,18 @@ private:
       return;
     }
 
     (this->*(HandleNtf[index]))(aHeader, aPDU);
   }
 
 };
 
+const int BluetoothDaemonCoreModule::MAX_NUM_CLIENTS = 1;
+
 //
 // Protocol handling
 //
 
 // |BluetoothDaemonProtocol| is the central class for communicating
 // with the Bluetooth daemon. It maintains both socket connections
 // to the external daemon and implements the complete HAL protocol
 // by inheriting from base-class modules.
@@ -1413,17 +1428,17 @@ class BluetoothDaemonProtocol MOZ_FINAL
   , public BluetoothDaemonSocketModule
   , public BluetoothDaemonHandsfreeModule
   , public BluetoothDaemonA2dpModule
   , public BluetoothDaemonAvrcpModule
 {
 public:
   BluetoothDaemonProtocol(BluetoothDaemonConnection* aConnection);
 
-  nsresult RegisterModule(uint8_t aId, uint8_t aMode,
+  nsresult RegisterModule(uint8_t aId, uint8_t aMode, uint32_t aMaxNumClients,
                           BluetoothSetupResultHandler* aRes) MOZ_OVERRIDE;
 
   nsresult UnregisterModule(uint8_t aId,
                             BluetoothSetupResultHandler* aRes) MOZ_OVERRIDE;
 
   // Outgoing PDUs
   //
 
@@ -1460,19 +1475,21 @@ BluetoothDaemonProtocol::BluetoothDaemon
   BluetoothDaemonConnection* aConnection)
   : mConnection(aConnection)
 {
   MOZ_ASSERT(mConnection);
 }
 
 nsresult
 BluetoothDaemonProtocol::RegisterModule(uint8_t aId, uint8_t aMode,
+                                        uint32_t aMaxNumClients,
                                         BluetoothSetupResultHandler* aRes)
 {
-  return BluetoothDaemonSetupModule::RegisterModuleCmd(aId, aMode, aRes);
+  return BluetoothDaemonSetupModule::RegisterModuleCmd(aId, aMode,
+                                                       aMaxNumClients, aRes);
 }
 
 nsresult
 BluetoothDaemonProtocol::UnregisterModule(uint8_t aId,
                                           BluetoothSetupResultHandler* aRes)
 {
   return BluetoothDaemonSetupModule::UnregisterModuleCmd(aId, aRes);
 }
@@ -1742,17 +1759,18 @@ public:
   void RegisterModule() MOZ_OVERRIDE
   {
     MOZ_ASSERT(NS_IsMainThread());
     MOZ_ASSERT(mInterface->mProtocol);
 
     if (!mRegisteredSocketModule) {
       mRegisteredSocketModule = true;
       // Init, step 4: Register Socket module
-      mInterface->mProtocol->RegisterModuleCmd(0x02, 0x00, this);
+      mInterface->mProtocol->RegisterModuleCmd(0x02, 0x00,
+        BluetoothDaemonSocketModule::MAX_NUM_CLIENTS, this);
     } else if (mRes) {
       // Init, step 5: Signal success to caller
       mRes->Init();
     }
   }
 
 private:
   BluetoothDaemonInterface* mInterface;
@@ -1781,17 +1799,18 @@ BluetoothDaemonInterface::OnConnectSucce
       break;
 
     case NTF_CHANNEL: {
         nsRefPtr<BluetoothResultHandler> res = mResultHandlerQ.ElementAt(0);
         mResultHandlerQ.RemoveElementAt(0);
 
         // Init, step 3: Register Core module
         nsresult rv = mProtocol->RegisterModuleCmd(
-          0x01, 0x00, new InitResultHandler(this, res));
+          0x01, 0x00, BluetoothDaemonCoreModule::MAX_NUM_CLIENTS,
+          new InitResultHandler(this, res));
         if (NS_FAILED(rv) && res) {
           DispatchError(res, STATUS_FAIL);
         }
       }
       break;
   }
 }
 
--- a/dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.cpp
@@ -10,16 +10,18 @@
 #include "mozilla/unused.h"
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 //
 // Socket module
 //
 
+const int BluetoothDaemonSocketModule::MAX_NUM_CLIENTS = 1;
+
 // Commands
 //
 
 nsresult
 BluetoothDaemonSocketModule::ListenCmd(BluetoothSocketType aType,
                                        const nsAString& aServiceName,
                                        const uint8_t aServiceUuid[16],
                                        int aChannel, bool aEncrypt,
--- a/dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.h
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.h
@@ -15,16 +15,18 @@ BEGIN_BLUETOOTH_NAMESPACE
 
 using namespace mozilla::ipc;
 
 class BlutoothDaemonInterface;
 
 class BluetoothDaemonSocketModule
 {
 public:
+  static const int MAX_NUM_CLIENTS;
+
   virtual nsresult Send(BluetoothDaemonPDU* aPDU, void* aUserData) = 0;
 
   // Commands
   //
 
   nsresult ListenCmd(BluetoothSocketType aType,
                      const nsAString& aServiceName,
                      const uint8_t aServiceUuid[16],