Bug 1153796: Unify variants of |BluetoothInterface::SspReply|, r=btian
authorThomas Zimmermann <tdz@users.sourceforge.net>
Wed, 15 Apr 2015 11:46:33 +0200
changeset 269107 08499ede9432299b3904473e0b19d4e4aa5510a0
parent 269106 4fefcef6eb37cb1676de37a965a0ef75a3d3d175
child 269108 e7ad039bd0f16a33a135bb5b84778e77d28f2833
push id4830
push userjlund@mozilla.com
push dateMon, 29 Jun 2015 20:18:48 +0000
treeherdermozilla-beta@4c2175bb0420 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbtian
bugs1153796
milestone40.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 1153796: Unify variants of |BluetoothInterface::SspReply|, r=btian Bluetooth use different types for the second argument of their variant of |BluetoothInterface::SspReply|. This patch standardizes them on the v2 version.
dom/bluetooth/bluedroid/BluetoothDaemonHelpers.cpp
dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonInterface.h
dom/bluetooth/bluedroid/BluetoothHALHelpers.cpp
dom/bluetooth/bluedroid/BluetoothHALHelpers.h
dom/bluetooth/bluedroid/BluetoothHALInterface.cpp
dom/bluetooth/bluedroid/BluetoothHALInterface.h
dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
dom/bluetooth/bluetooth1/BluetoothInterface.h
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.cpp
@@ -593,39 +593,16 @@ Convert(const nsAString& aIn, BluetoothS
   }
 
   memcpy(aOut.mName, str, len);
   memset(aOut.mName + len, 0, sizeof(aOut.mName) - len);
 
   return NS_OK;
 }
 
-#ifdef MOZ_B2G_BT_API_V2
-// Removed in bluetooth2
-#else
-nsresult
-Convert(const nsAString& aIn, BluetoothSspVariant& aOut)
-{
-  if (aIn.EqualsLiteral("PasskeyConfirmation")) {
-    aOut = SSP_VARIANT_PASSKEY_CONFIRMATION;
-  } else if (aIn.EqualsLiteral("PasskeyEntry")) {
-    aOut = SSP_VARIANT_PASSKEY_ENTRY;
-  } else if (aIn.EqualsLiteral("Consent")) {
-    aOut = SSP_VARIANT_CONSENT;
-  } else if (aIn.EqualsLiteral("PasskeyNotification")) {
-    aOut = SSP_VARIANT_PASSKEY_NOTIFICATION;
-  } else {
-    BT_LOGR("Invalid SSP variant name: %s", NS_ConvertUTF16toUTF8(aIn).get());
-    aOut = SSP_VARIANT_PASSKEY_CONFIRMATION; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  return NS_OK;
-}
-#endif
-
 nsresult
 Convert(BluetoothAclState aIn, bool& aOut)
 {
   static const bool sBool[] = {
     CONVERT(ACL_STATE_CONNECTED, true),
     CONVERT(ACL_STATE_DISCONNECTED, false)
   };
   if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sBool))) {
@@ -958,32 +935,16 @@ Convert(BluetoothSspVariant aIn, uint8_t
     aOut = 0; // silences compiler warning
     return NS_ERROR_ILLEGAL_VALUE;
   }
   aOut = sValue[aIn];
   return NS_OK;
 }
 
 nsresult
-Convert(BluetoothSspVariant aIn, nsAString& aOut)
-{
-  static const char* const sString[] = {
-    CONVERT(SSP_VARIANT_PASSKEY_CONFIRMATION, "PasskeyConfirmation"),
-    CONVERT(SSP_VARIANT_PASSKEY_ENTRY, "PasskeyEntry"),
-    CONVERT(SSP_VARIANT_CONSENT, "Consent"),
-    CONVERT(SSP_VARIANT_PASSKEY_NOTIFICATION, "PasskeyNotification")
-  };
-  if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sString))) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = NS_ConvertUTF8toUTF16(sString[aIn]);
-  return NS_OK;
-}
-
-nsresult
 Convert(ControlPlayStatus aIn, uint8_t& aOut)
 {
   static const uint8_t sValue[] = {
     CONVERT(PLAYSTATUS_STOPPED, 0x00),
     CONVERT(PLAYSTATUS_PLAYING, 0x01),
     CONVERT(PLAYSTATUS_PAUSED, 0x02),
     CONVERT(PLAYSTATUS_FWD_SEEK, 0x03),
     CONVERT(PLAYSTATUS_REV_SEEK, 0x04)
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
@@ -256,23 +256,16 @@ nsresult
 Convert(const nsAString& aIn, BluetoothPinCode& aOut);
 
 nsresult
 Convert(const nsAString& aIn, BluetoothPropertyType& aOut);
 
 nsresult
 Convert(const nsAString& aIn, BluetoothServiceName& aOut);
 
-#ifdef MOZ_B2G_BT_API_V2
-// Removed in bluetooth2
-#else
-nsresult
-Convert(const nsAString& aIn, BluetoothSspVariant& aOut);
-#endif
-
 nsresult
 Convert(BluetoothAclState aIn, bool& aOut);
 
 nsresult
 Convert(const BluetoothAddress& aIn, nsAString& aOut);
 
 nsresult
 Convert(BluetoothAvrcpEvent aIn, uint8_t& aOut);
@@ -330,19 +323,16 @@ Convert(BluetoothScanMode aIn, uint8_t& 
 
 nsresult
 Convert(BluetoothSocketType aIn, uint8_t& aOut);
 
 nsresult
 Convert(BluetoothSspVariant aIn, uint8_t& aOut);
 
 nsresult
-Convert(BluetoothSspVariant aIn, nsAString& aOut);
-
-nsresult
 Convert(ControlPlayStatus aIn, uint8_t& aOut);
 
 #ifdef MOZ_B2G_BT_API_V2
 nsresult
 Convert(nsresult aIn, BluetoothStatus& aOut);
 #else
 // Missing in bluetooth1
 #endif
--- a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
@@ -503,17 +503,16 @@ public:
     rv = Send(pdu, aRes);
     if (NS_FAILED(rv)) {
       return rv;
     }
     unused << pdu.forget();
     return rv;
   }
 
-#ifdef MOZ_B2G_BT_API_V2
   nsresult SspReplyCmd(const nsAString& aBdAddr, BluetoothSspVariant aVariant,
                        bool aAccept, uint32_t aPasskey,
                        BluetoothResultHandler* aRes)
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     nsAutoPtr<BluetoothDaemonPDU> pdu(new BluetoothDaemonPDU(0x01, 0x11, 0));
 
@@ -525,40 +524,16 @@ public:
     }
     rv = Send(pdu, aRes);
     if (NS_FAILED(rv)) {
       return rv;
     }
     unused << pdu.forget();
     return rv;
   }
-#else
-  nsresult SspReplyCmd(const nsAString& aBdAddr, const nsAString& aVariant,
-                       bool aAccept, uint32_t aPasskey,
-                       BluetoothResultHandler* aRes)
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    nsAutoPtr<BluetoothDaemonPDU> pdu(new BluetoothDaemonPDU(0x01, 0x11, 0));
-
-    nsresult rv = PackPDU(
-      PackConversion<nsAString, BluetoothAddress>(aBdAddr),
-      PackConversion<nsAString, BluetoothSspVariant>(aVariant),
-      aAccept, aPasskey, *pdu);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Send(pdu, aRes);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    unused << pdu.forget();
-    return rv;
-  }
-#endif
 
   nsresult DutModeConfigureCmd(bool aEnable, BluetoothResultHandler* aRes)
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     nsAutoPtr<BluetoothDaemonPDU> pdu(new BluetoothDaemonPDU(0x01, 0x12, 0));
 
     nsresult rv = PackPDU(aEnable, *pdu);
@@ -2424,43 +2399,28 @@ BluetoothDaemonInterface::PinReply(const
 {
   nsresult rv = static_cast<BluetoothDaemonCoreModule*>
     (mProtocol)->PinReplyCmd(aBdAddr, aAccept, aPinCode, aRes);
   if (NS_FAILED(rv)) {
     DispatchError(aRes, rv);
   }
 }
 
-#ifdef MOZ_B2G_BT_API_V2
 void
 BluetoothDaemonInterface::SspReply(const nsAString& aBdAddr,
                                    BluetoothSspVariant aVariant,
                                    bool aAccept, uint32_t aPasskey,
                                    BluetoothResultHandler* aRes)
 {
   nsresult rv = static_cast<BluetoothDaemonCoreModule*>
     (mProtocol)->SspReplyCmd(aBdAddr, aVariant, aAccept, aPasskey, aRes);
   if (NS_FAILED(rv)) {
     DispatchError(aRes, rv);
   }
 }
-#else
-void
-BluetoothDaemonInterface::SspReply(const nsAString& aBdAddr,
-                                   const nsAString& aVariant,
-                                   bool aAccept, uint32_t aPasskey,
-                                   BluetoothResultHandler* aRes)
-{
-  nsresult rv = static_cast<BluetoothDaemonCoreModule*>
-    (mProtocol)->SspReplyCmd(aBdAddr, aVariant, aAccept, aPasskey, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-#endif
 
 /* DUT Mode */
 
 void
 BluetoothDaemonInterface::DutModeConfigure(bool aEnable,
                                            BluetoothResultHandler* aRes)
 {
   nsresult rv = static_cast<BluetoothDaemonCoreModule*>
--- a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.h
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.h
@@ -84,25 +84,19 @@ public:
                           BluetoothResultHandler* aRes);
 
   /* Authentication */
 
   void PinReply(const nsAString& aBdAddr, bool aAccept,
                 const nsAString& aPinCode,
                 BluetoothResultHandler* aRes);
 
-#ifdef MOZ_B2G_BT_API_V2
   void SspReply(const nsAString& aBdAddr, BluetoothSspVariant aVariant,
                 bool aAccept, uint32_t aPasskey,
                 BluetoothResultHandler* aRes);
-#else
-  void SspReply(const nsAString& aBdAddr, const nsAString& aVariant,
-                bool aAccept, uint32_t aPasskey,
-                BluetoothResultHandler* aRes);
-#endif
 
   /* DUT Mode */
 
   void DutModeConfigure(bool aEnable, BluetoothResultHandler* aRes);
   void DutModeSend(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
                    BluetoothResultHandler* aRes);
 
   /* LE Mode */
--- a/dom/bluetooth/bluedroid/BluetoothHALHelpers.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothHALHelpers.cpp
@@ -75,17 +75,16 @@ Convert(const nsAString& aIn, bt_bdaddr_
   for (size_t i = 0; i < MOZ_ARRAY_LENGTH(aOut.address); ++i, ++str) {
     aOut.address[i] =
       static_cast<uint8_t>(strtoul(str, const_cast<char**>(&str), 16));
   }
 
   return NS_OK;
 }
 
-#ifdef MOZ_B2G_BT_API_V2
 nsresult
 Convert(const BluetoothSspVariant aIn, bt_ssp_variant_t& aOut)
 {
   static const bt_ssp_variant_t sSspVariant[] = {
     CONVERT(SSP_VARIANT_PASSKEY_CONFIRMATION,
       BT_SSP_VARIANT_PASSKEY_CONFIRMATION),
     CONVERT(SSP_VARIANT_PASSKEY_ENTRY, BT_SSP_VARIANT_PASSKEY_ENTRY),
     CONVERT(SSP_VARIANT_CONSENT, BT_SSP_VARIANT_CONSENT),
@@ -93,36 +92,16 @@ Convert(const BluetoothSspVariant aIn, b
       BT_SSP_VARIANT_PASSKEY_NOTIFICATION)
   };
   if (aIn >= MOZ_ARRAY_LENGTH(sSspVariant)) {
     return NS_ERROR_ILLEGAL_VALUE;
   }
   aOut = sSspVariant[aIn];
   return NS_OK;
 }
-#else
-nsresult
-Convert(const nsAString& aIn, bt_ssp_variant_t& aOut)
-{
-  if (aIn.EqualsLiteral("PasskeyConfirmation")) {
-    aOut = BT_SSP_VARIANT_PASSKEY_CONFIRMATION;
-  } else if (aIn.EqualsLiteral("PasskeyEntry")) {
-    aOut = BT_SSP_VARIANT_PASSKEY_ENTRY;
-  } else if (aIn.EqualsLiteral("Consent")) {
-    aOut = BT_SSP_VARIANT_CONSENT;
-  } else if (aIn.EqualsLiteral("PasskeyNotification")) {
-    aOut = BT_SSP_VARIANT_PASSKEY_NOTIFICATION;
-  } else {
-    BT_LOGR("Invalid SSP variant name: %s", NS_ConvertUTF16toUTF8(aIn).get());
-    aOut = BT_SSP_VARIANT_PASSKEY_CONFIRMATION; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  return NS_OK;
-}
-#endif
 
 nsresult
 Convert(const uint8_t aIn[16], bt_uuid_t& aOut)
 {
   if (sizeof(aOut.uu) != 16) {
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
--- a/dom/bluetooth/bluedroid/BluetoothHALHelpers.h
+++ b/dom/bluetooth/bluedroid/BluetoothHALHelpers.h
@@ -114,23 +114,18 @@ struct ConvertNamedValue
 };
 
 nsresult
 Convert(ConvertNamedValue& aIn, bt_property_t& aOut);
 
 nsresult
 Convert(const nsAString& aIn, bt_bdaddr_t& aOut);
 
-#ifdef MOZ_B2G_BT_API_V2
 nsresult
 Convert(BluetoothSspVariant aIn, bt_ssp_variant_t& aOut);
-#else
-nsresult
-Convert(const nsAString& aIn, bt_ssp_variant_t& aOut);
-#endif
 
 inline nsresult
 Convert(const bt_ssp_variant_t& aIn, BluetoothSspVariant& aOut)
 {
   static const BluetoothSspVariant sSspVariant[] = {
     CONVERT(BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
       SSP_VARIANT_PASSKEY_CONFIRMATION),
     CONVERT(BT_SSP_VARIANT_PASSKEY_ENTRY, SSP_VARIANT_PASSKEY_ENTRY),
--- a/dom/bluetooth/bluedroid/BluetoothHALInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothHALInterface.cpp
@@ -878,17 +878,16 @@ BluetoothHALInterface::PinReply(const ns
 
   if (aRes) {
     DispatchBluetoothHALResult(aRes,
                                &BluetoothResultHandler::PinReply,
                                ConvertDefault(status, STATUS_FAIL));
   }
 }
 
-#ifdef MOZ_B2G_BT_API_V2
 void
 BluetoothHALInterface::SspReply(const nsAString& aBdAddr,
                                 BluetoothSspVariant aVariant,
                                 bool aAccept, uint32_t aPasskey,
                                 BluetoothResultHandler* aRes)
 {
   int status;
   bt_bdaddr_t bdAddr;
@@ -904,43 +903,16 @@ BluetoothHALInterface::SspReply(const ns
   }
 
   if (aRes) {
     DispatchBluetoothHALResult(aRes,
                                &BluetoothResultHandler::SspReply,
                                ConvertDefault(status, STATUS_FAIL));
   }
 }
-#else
-void
-BluetoothHALInterface::SspReply(const nsAString& aBdAddr,
-                                const nsAString& aVariant,
-                                bool aAccept, uint32_t aPasskey,
-                                BluetoothResultHandler* aRes)
-{
-  int status;
-  bt_bdaddr_t bdAddr;
-  bt_ssp_variant_t variant;
-  uint8_t accept;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr)) &&
-      NS_SUCCEEDED(Convert(aVariant, variant)) &&
-      NS_SUCCEEDED(Convert(aAccept, accept))) {
-    status = mInterface->ssp_reply(&bdAddr, variant, accept, aPasskey);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::SspReply,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-#endif
 
 /* DUT Mode */
 
 void
 BluetoothHALInterface::DutModeConfigure(bool aEnable,
                                         BluetoothResultHandler* aRes)
 {
   int status;
--- a/dom/bluetooth/bluedroid/BluetoothHALInterface.h
+++ b/dom/bluetooth/bluedroid/BluetoothHALInterface.h
@@ -70,25 +70,19 @@ public:
                           BluetoothResultHandler* aRes);
 
   /* Authentication */
 
   void PinReply(const nsAString& aBdAddr, bool aAccept,
                 const nsAString& aPinCode,
                 BluetoothResultHandler* aRes);
 
-#ifdef MOZ_B2G_BT_API_V2
   void SspReply(const nsAString& aBdAddr, BluetoothSspVariant aVariant,
                 bool aAccept, uint32_t aPasskey,
                 BluetoothResultHandler* aRes);
-#else
-  void SspReply(const nsAString& aBdAddr, const nsAString& aVariant,
-                bool aAccept, uint32_t aPasskey,
-                BluetoothResultHandler* aRes);
-#endif
 
   /* DUT Mode */
 
   void DutModeConfigure(bool aEnable, BluetoothResultHandler* aRes);
   void DutModeSend(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
                    BluetoothResultHandler* aRes);
 
   /* LE Mode */
--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
@@ -1561,17 +1561,17 @@ BluetoothServiceBluedroid::SetPairingCon
   const nsAString& aDeviceAddress, bool aConfirm,
   BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   ENSURE_BLUETOOTH_IS_READY(aRunnable, false);
 
   sBtInterface->SspReply(aDeviceAddress,
-                         NS_ConvertUTF8toUTF16("PasskeyConfirmation"),
+                         SSP_VARIANT_PASSKEY_CONFIRMATION,
                          aConfirm, 0, new SspReplyResultHandler(aRunnable));
   return true;
 }
 #endif
 
 #ifdef MOZ_B2G_BT_API_V2
 // Missing in bluetooth2
 #else
--- a/dom/bluetooth/bluetooth1/BluetoothInterface.h
+++ b/dom/bluetooth/bluetooth1/BluetoothInterface.h
@@ -648,17 +648,18 @@ public:
                                   BluetoothResultHandler* aRes) = 0;
 
   /* Authentication */
 
   virtual void PinReply(const nsAString& aBdAddr, bool aAccept,
                         const nsAString& aPinCode,
                         BluetoothResultHandler* aRes) = 0;
 
-  virtual void SspReply(const nsAString& aBdAddr, const nsAString& aVariant,
+  virtual void SspReply(const nsAString& aBdAddr,
+                        BluetoothSspVariant aVariant,
                         bool aAccept, uint32_t aPasskey,
                         BluetoothResultHandler* aRes) = 0;
 
   /* DUT Mode */
 
   virtual void DutModeConfigure(bool aEnable,
                                 BluetoothResultHandler* aRes) = 0;
   virtual void DutModeSend(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,