Bug 1187872: Remove HAL backend from Bluetooth, r=shuang
authorThomas Zimmermann <tdz@users.sourceforge.net>
Thu, 30 Jul 2015 09:09:26 +0200
changeset 288691 293dd17693db3d3533d3a59dc27eab7dbe178e3b
parent 288690 211aa8670c74c893a88ef4a028cc1eded5c02668
child 288692 aa72183e80c2dfed732728e6a6bd69b48c348def
push id934
push userraliiev@mozilla.com
push dateMon, 26 Oct 2015 12:58:05 +0000
treeherdermozilla-release@05704e35c1d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshuang
bugs1187872
milestone42.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 1187872: Remove HAL backend from Bluetooth, r=shuang Bluedroid's HAL backend has been superseded by the Bluetooth daemon, and already been unused in current releases. This patch removes the code from Gecko.
configure.in
dom/bluetooth/BluetoothInterface.cpp
dom/bluetooth/bluedroid/BluetoothA2dpHALInterface.cpp
dom/bluetooth/bluedroid/BluetoothA2dpHALInterface.h
dom/bluetooth/bluedroid/BluetoothAvrcpHALInterface.cpp
dom/bluetooth/bluedroid/BluetoothAvrcpHALInterface.h
dom/bluetooth/bluedroid/BluetoothGattHALInterface.cpp
dom/bluetooth/bluedroid/BluetoothGattHALInterface.h
dom/bluetooth/bluedroid/BluetoothHALHelpers.cpp
dom/bluetooth/bluedroid/BluetoothHALHelpers.h
dom/bluetooth/bluedroid/BluetoothHALInterface.cpp
dom/bluetooth/bluedroid/BluetoothHALInterface.h
dom/bluetooth/bluedroid/BluetoothHandsfreeHALInterface.cpp
dom/bluetooth/bluedroid/BluetoothHandsfreeHALInterface.h
dom/bluetooth/bluedroid/BluetoothSocketHALInterface.cpp
dom/bluetooth/bluedroid/BluetoothSocketHALInterface.h
dom/bluetooth/bluetooth1/BluetoothService.cpp
dom/bluetooth/bluetooth2/BluetoothService.cpp
dom/bluetooth/moz.build
--- a/configure.in
+++ b/configure.in
@@ -225,44 +225,40 @@ if test -n "$gonkdir" ; then
         AC_SUBST(MOZ_OMX_DECODER)
         MOZ_RTSP=1
         MOZ_FMP4=1
         MOZ_SECUREELEMENT=1
         ;;
     17|18)
         GONK_INCLUDES="-I$gonkdir/frameworks/native/include -I$gonkdir/frameworks/av/include -I$gonkdir/frameworks/av/include/media -I$gonkdir/frameworks/av/include/camera -I$gonkdir/frameworks/native/include/media/openmax -I$gonkdir/frameworks/av/media/libstagefright/include -I$gonkdir/external/mdnsresponder/mDNSShared"
         if test -d "$gonkdir/external/bluetooth/bluez"; then
-          GONK_INCLUDES="$GONK_INCLUDES -I$gonkdir/external/dbus -I$gonkdir/external/bluetooth/bluez/lib"
+            GONK_INCLUDES="$GONK_INCLUDES -I$gonkdir/external/dbus -I$gonkdir/external/bluetooth/bluez/lib"
             MOZ_B2G_BT=1
             MOZ_B2G_BT_BLUEZ=1
-        elif test -d "$gonkdir/external/bluetooth/bluedroid"; then
+        elif test -d "$gonkdir/system/bluetoothd"; then
             MOZ_B2G_BT=1
-            MOZ_B2G_BT_BLUEDROID=1
-            if test -d "$gonkdir/system/bluetoothd"; then
-                MOZ_B2G_BT_DAEMON=1
-            fi
+            MOZ_B2G_BT_DAEMON=1
         fi
 
         MOZ_RTSP=1
         MOZ_NFC=1
         MOZ_B2G_CAMERA=1
         MOZ_OMX_DECODER=1
         AC_SUBST(MOZ_OMX_DECODER)
         MOZ_OMX_ENCODER=1
         AC_SUBST(MOZ_OMX_ENCODER)
         AC_DEFINE(MOZ_OMX_ENCODER)
-	MOZ_FMP4=1
+        MOZ_FMP4=1
         MOZ_SECUREELEMENT=1
         ;;
     19)
         GONK_INCLUDES="-I$gonkdir/frameworks/native/include -I$gonkdir/frameworks/av/include -I$gonkdir/frameworks/av/include/media -I$gonkdir/frameworks/av/include/camera -I$gonkdir/frameworks/native/include/media/openmax -I$gonkdir/frameworks/av/media/libstagefright/include -I$gonkdir/external/mdnsresponder/mDNSShared"
         MOZ_B2G_CAMERA=1
-        MOZ_B2G_BT=1
-        MOZ_B2G_BT_BLUEDROID=1
         if test -d "$gonkdir/system/bluetoothd"; then
+            MOZ_B2G_BT=1
             MOZ_B2G_BT_DAEMON=1
         fi
         MOZ_NFC=1
         MOZ_RTSP=1
         MOZ_OMX_DECODER=1
         MOZ_OMX_ENCODER=1
         AC_DEFINE(MOZ_OMX_ENCODER)
         MOZ_AUDIO_OFFLOAD=1
@@ -276,19 +272,18 @@ if test -n "$gonkdir" ; then
         MOZ_AUDIO_OFFLOAD=1
         MOZ_OMX_DECODER=1
         MOZ_OMX_ENCODER=1
         AC_DEFINE(MOZ_OMX_ENCODER)
         AC_SUBST(MOZ_AUDIO_OFFLOAD)
         AC_DEFINE(MOZ_AUDIO_OFFLOAD)
         MOZ_FMP4=
         MOZ_B2G_CAMERA=1
-        MOZ_B2G_BT=1
-        MOZ_B2G_BT_BLUEDROID=1
         if test -d "$gonkdir/system/bluetoothd"; then
+            MOZ_B2G_BT=1
             MOZ_B2G_BT_DAEMON=1
         fi
         MOZ_NFC=1
         MOZ_RTSP=1
         ;;
     *)
         AC_MSG_ERROR([Unsupported platform version: $ANDROID_VERSION])
         ;;
@@ -7600,17 +7595,16 @@ MOZ_ARG_ENABLE_BOOL(b2g-bt,
 [  --enable-b2g-bt      Set compile flags necessary for compiling Bluetooth API for B2G ],
     MOZ_B2G_BT=1,
     MOZ_B2G_BT= )
 if test -n "$MOZ_B2G_BT"; then
     AC_DEFINE(MOZ_B2G_BT)
 fi
 AC_SUBST(MOZ_B2G_BT)
 AC_SUBST(MOZ_B2G_BT_BLUEZ)
-AC_SUBST(MOZ_B2G_BT_BLUEDROID)
 AC_SUBST(MOZ_B2G_BT_DAEMON)
 
 dnl ========================================================
 dnl = Enable NFC Interface for B2G (Gonk usually)
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(nfc,
 [  --enable-nfc         Set compile flags necessary for compiling NFC API ],
     MOZ_NFC=1,
--- a/dom/bluetooth/BluetoothInterface.cpp
+++ b/dom/bluetooth/BluetoothInterface.cpp
@@ -3,19 +3,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "BluetoothInterface.h"
 #if ANDROID_VERSION >= 17
 #include <cutils/properties.h>
 #endif
-#ifdef MOZ_B2G_BT_BLUEDROID
-#include "BluetoothHALInterface.h"
-#endif
 #ifdef MOZ_B2G_BT_DAEMON
 #include "BluetoothDaemonInterface.h"
 #endif
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 //
 // Socket Interface
@@ -142,19 +139,16 @@ BluetoothInterface::GetInstance()
    * can be overriden manually by storing the respective string in the
    * system property 'ro.moz.bluetooth.backend'.
    */
 
   static const char* const sDefaultBackend[] = {
 #ifdef MOZ_B2G_BT_DAEMON
     "bluetoothd",
 #endif
-#ifdef MOZ_B2G_BT_BLUEDROID
-    "bluedroid",
-#endif
     nullptr // no default backend; must be final element in array
   };
 
   const char* defaultBackend;
 
   for (size_t i = 0; i < MOZ_ARRAY_LENGTH(sDefaultBackend); ++i) {
 
     /* select current backend */
@@ -181,21 +175,16 @@ BluetoothInterface::GetInstance()
   const nsDependentCString backend(value, len);
 
   /* Here's where we decide which implementation to use. Currently
    * there is only Bluedroid and the Bluetooth daemon, but others are
    * possible. Having multiple interfaces built-in and selecting the
    * correct one at runtime is also an option.
    */
 
-#ifdef MOZ_B2G_BT_BLUEDROID
-  if (backend.LowerCaseEqualsLiteral("bluedroid")) {
-    return BluetoothHALInterface::GetInstance();
-  } else
-#endif
 #ifdef MOZ_B2G_BT_DAEMON
   if (backend.LowerCaseEqualsLiteral("bluetoothd")) {
     return BluetoothDaemonInterface::GetInstance();
   } else
 #endif
   {
     BT_WARNING("Bluetooth backend '%s' is unknown or not available.",
                backend.get());
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothA2dpHALInterface.cpp
+++ /dev/null
@@ -1,203 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "BluetoothA2dpHALInterface.h"
-#include "BluetoothHALHelpers.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-typedef
-  BluetoothHALInterfaceRunnable0<BluetoothA2dpResultHandler, void>
-  BluetoothA2dpHALResultRunnable;
-
-typedef
-  BluetoothHALInterfaceRunnable1<BluetoothA2dpResultHandler, void,
-                                 BluetoothStatus, BluetoothStatus>
-  BluetoothA2dpHALErrorRunnable;
-
-static nsresult
-DispatchBluetoothA2dpHALResult(
-  BluetoothA2dpResultHandler* aRes,
-  void (BluetoothA2dpResultHandler::*aMethod)(),
-  BluetoothStatus aStatus)
-{
-  MOZ_ASSERT(aRes);
-
-  nsRefPtr<nsRunnable> runnable;
-
-  if (aStatus == STATUS_SUCCESS) {
-    runnable = new BluetoothA2dpHALResultRunnable(aRes, aMethod);
-  } else {
-    runnable = new BluetoothA2dpHALErrorRunnable(aRes,
-      &BluetoothA2dpResultHandler::OnError, aStatus);
-  }
-  nsresult rv = NS_DispatchToMainThread(runnable);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-  }
-  return rv;
-}
-
-// Notification handling
-//
-
-static BluetoothA2dpNotificationHandler* sA2dpNotificationHandler;
-
-struct BluetoothA2dpHALCallback
-{
-  class A2dpNotificationHandlerWrapper
-  {
-  public:
-    typedef BluetoothA2dpNotificationHandler ObjectType;
-
-    static ObjectType* GetInstance()
-    {
-      MOZ_ASSERT(NS_IsMainThread());
-
-      return sA2dpNotificationHandler;
-    }
-  };
-
-  // Notifications
-
-  typedef BluetoothNotificationHALRunnable2<
-    A2dpNotificationHandlerWrapper, void,
-    BluetoothA2dpConnectionState, nsString,
-    BluetoothA2dpConnectionState, const nsAString&>
-    ConnectionStateNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    A2dpNotificationHandlerWrapper, void,
-    BluetoothA2dpAudioState, nsString,
-    BluetoothA2dpAudioState, const nsAString&>
-    AudioStateNotification;
-
-  typedef BluetoothNotificationHALRunnable3<
-    A2dpNotificationHandlerWrapper, void,
-    nsString, uint32_t, uint8_t,
-    const nsAString&, uint32_t, uint8_t>
-    AudioConfigNotification;
-
-  // Bluedroid A2DP callbacks
-
-  static void
-  ConnectionState(btav_connection_state_t aState, bt_bdaddr_t* aBdAddr)
-  {
-    ConnectionStateNotification::Dispatch(
-      &BluetoothA2dpNotificationHandler::ConnectionStateNotification,
-      aState, aBdAddr);
-  }
-
-  static void
-  AudioState(btav_audio_state_t aState, bt_bdaddr_t* aBdAddr)
-  {
-    AudioStateNotification::Dispatch(
-      &BluetoothA2dpNotificationHandler::AudioStateNotification,
-      aState, aBdAddr);
-  }
-
-#if ANDROID_VERSION >= 21
-  static void
-  AudioConfig(bt_bdaddr_t *aBdAddr, uint32_t aSampleRate, uint8_t aChannelCount)
-  {
-    AudioConfigNotification::Dispatch(
-      &BluetoothA2dpNotificationHandler::AudioConfigNotification,
-      aBdAddr, aSampleRate, aChannelCount);
-  }
-#endif
-};
-
-// Interface
-//
-
-BluetoothA2dpHALInterface::BluetoothA2dpHALInterface(
-  const btav_interface_t* aInterface)
-: mInterface(aInterface)
-{
-  MOZ_ASSERT(mInterface);
-}
-
-BluetoothA2dpHALInterface::~BluetoothA2dpHALInterface()
-{ }
-
-void
-BluetoothA2dpHALInterface::Init(
-  BluetoothA2dpNotificationHandler* aNotificationHandler,
-  BluetoothA2dpResultHandler* aRes)
-{
-  static btav_callbacks_t sCallbacks = {
-    sizeof(sCallbacks),
-    BluetoothA2dpHALCallback::ConnectionState,
-    BluetoothA2dpHALCallback::AudioState,
-#if ANDROID_VERSION >= 21
-    BluetoothA2dpHALCallback::AudioConfig
-#endif
-  };
-
-  sA2dpNotificationHandler = aNotificationHandler;
-
-  bt_status_t status = mInterface->init(&sCallbacks);
-
-  if (aRes) {
-    DispatchBluetoothA2dpHALResult(aRes,
-                                   &BluetoothA2dpResultHandler::Init,
-                                   ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothA2dpHALInterface::Cleanup(BluetoothA2dpResultHandler* aRes)
-{
-  mInterface->cleanup();
-
-  if (aRes) {
-    DispatchBluetoothA2dpHALResult(aRes,
-                                   &BluetoothA2dpResultHandler::Cleanup,
-                                   STATUS_SUCCESS);
-  }
-}
-
-void
-BluetoothA2dpHALInterface::Connect(const nsAString& aBdAddr,
-                                   BluetoothA2dpResultHandler* aRes)
-{
-  bt_status_t status;
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->connect(&bdAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothA2dpHALResult(
-      aRes, &BluetoothA2dpResultHandler::Connect,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothA2dpHALInterface::Disconnect(const nsAString& aBdAddr,
-                                      BluetoothA2dpResultHandler* aRes)
-{
-  bt_status_t status;
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->disconnect(&bdAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothA2dpHALResult(
-      aRes, &BluetoothA2dpResultHandler::Disconnect,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothA2dpHALInterface.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_dom_bluetooth_bluedroid_bluetootha2dphalinterface_h__
-#define mozilla_dom_bluetooth_bluedroid_bluetootha2dphalinterface_h__
-
-#include <hardware/bluetooth.h>
-#include <hardware/bt_av.h>
-#include "BluetoothCommon.h"
-#include "BluetoothInterface.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothHALInterface;
-
-class BluetoothA2dpHALInterface final
-  : public BluetoothA2dpInterface
-{
-public:
-  friend class BluetoothHALInterface;
-
-  void Init(BluetoothA2dpNotificationHandler* aNotificationHandler,
-            BluetoothA2dpResultHandler* aRes);
-  void Cleanup(BluetoothA2dpResultHandler* aRes);
-
-  void Connect(const nsAString& aBdAddr,
-               BluetoothA2dpResultHandler* aRes);
-  void Disconnect(const nsAString& aBdAddr,
-                  BluetoothA2dpResultHandler* aRes);
-
-protected:
-  BluetoothA2dpHALInterface(const btav_interface_t* aInterface);
-  ~BluetoothA2dpHALInterface();
-
-private:
-  const btav_interface_t* mInterface;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothAvrcpHALInterface.cpp
+++ /dev/null
@@ -1,593 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "BluetoothAvrcpHALInterface.h"
-#include "BluetoothHALHelpers.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-typedef
-  BluetoothHALInterfaceRunnable0<BluetoothAvrcpResultHandler, void>
-  BluetoothAvrcpHALResultRunnable;
-
-typedef
-  BluetoothHALInterfaceRunnable1<BluetoothAvrcpResultHandler, void,
-                                 BluetoothStatus, BluetoothStatus>
-  BluetoothAvrcpHALErrorRunnable;
-
-static nsresult
-DispatchBluetoothAvrcpHALResult(
-  BluetoothAvrcpResultHandler* aRes,
-  void (BluetoothAvrcpResultHandler::*aMethod)(),
-  BluetoothStatus aStatus)
-{
-  MOZ_ASSERT(aRes);
-
-  nsRefPtr<nsRunnable> runnable;
-
-  if (aStatus == STATUS_SUCCESS) {
-    runnable = new BluetoothAvrcpHALResultRunnable(aRes, aMethod);
-  } else {
-    runnable = new BluetoothAvrcpHALErrorRunnable(aRes,
-      &BluetoothAvrcpResultHandler::OnError, aStatus);
-  }
-  nsresult rv = NS_DispatchToMainThread(runnable);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-  }
-  return rv;
-}
-
-// Notification handling
-//
-
-static BluetoothAvrcpNotificationHandler* sAvrcpNotificationHandler;
-
-struct BluetoothAvrcpCallback
-{
-  class AvrcpNotificationHandlerWrapper
-  {
-  public:
-    typedef BluetoothAvrcpNotificationHandler ObjectType;
-
-    static ObjectType* GetInstance()
-    {
-      MOZ_ASSERT(NS_IsMainThread());
-
-      return sAvrcpNotificationHandler;
-    }
-  };
-
-  // Notifications
-
-  typedef BluetoothNotificationHALRunnable0<AvrcpNotificationHandlerWrapper,
-                                            void>
-    GetPlayStatusNotification;
-
-  typedef BluetoothNotificationHALRunnable0<AvrcpNotificationHandlerWrapper,
-                                            void>
-    ListPlayerAppAttrNotification;
-
-  typedef BluetoothNotificationHALRunnable1<AvrcpNotificationHandlerWrapper,
-                                            void,
-                                            BluetoothAvrcpPlayerAttribute>
-    ListPlayerAppValuesNotification;
-
-  typedef BluetoothNotificationHALRunnable2<AvrcpNotificationHandlerWrapper, void,
-    uint8_t, nsAutoArrayPtr<BluetoothAvrcpPlayerAttribute>,
-    uint8_t, const BluetoothAvrcpPlayerAttribute*>
-    GetPlayerAppValueNotification;
-
-  typedef BluetoothNotificationHALRunnable2<AvrcpNotificationHandlerWrapper, void,
-    uint8_t, nsAutoArrayPtr<BluetoothAvrcpPlayerAttribute>,
-    uint8_t, const BluetoothAvrcpPlayerAttribute*>
-    GetPlayerAppAttrsTextNotification;
-
-  typedef BluetoothNotificationHALRunnable3<AvrcpNotificationHandlerWrapper,
-                                            void,
-                                            uint8_t, uint8_t,
-                                            nsAutoArrayPtr<uint8_t>,
-                                            uint8_t, uint8_t, const uint8_t*>
-    GetPlayerAppValuesTextNotification;
-
-  typedef BluetoothNotificationHALRunnable1<AvrcpNotificationHandlerWrapper,
-                                            void,
-                                            BluetoothAvrcpPlayerSettings,
-                                            const BluetoothAvrcpPlayerSettings&>
-    SetPlayerAppValueNotification;
-
-  typedef BluetoothNotificationHALRunnable2<AvrcpNotificationHandlerWrapper, void,
-    uint8_t, nsAutoArrayPtr<BluetoothAvrcpMediaAttribute>,
-    uint8_t, const BluetoothAvrcpMediaAttribute*>
-    GetElementAttrNotification;
-
-  typedef BluetoothNotificationHALRunnable2<AvrcpNotificationHandlerWrapper,
-                                            void,
-                                            BluetoothAvrcpEvent, uint32_t>
-    RegisterNotificationNotification;
-
-  typedef BluetoothNotificationHALRunnable2<AvrcpNotificationHandlerWrapper,
-                                            void,
-                                            nsString, unsigned long,
-                                            const nsAString&>
-    RemoteFeatureNotification;
-
-  typedef BluetoothNotificationHALRunnable2<AvrcpNotificationHandlerWrapper,
-                                            void,
-                                            uint8_t, uint8_t>
-    VolumeChangeNotification;
-
-  typedef BluetoothNotificationHALRunnable2<AvrcpNotificationHandlerWrapper,
-                                            void,
-                                            int, int>
-    PassthroughCmdNotification;
-
-  // Bluedroid AVRCP callbacks
-
-#if ANDROID_VERSION >= 18
-  static void
-  GetPlayStatus()
-  {
-    GetPlayStatusNotification::Dispatch(
-      &BluetoothAvrcpNotificationHandler::GetPlayStatusNotification);
-  }
-
-  static void
-  ListPlayerAppAttr()
-  {
-    ListPlayerAppAttrNotification::Dispatch(
-      &BluetoothAvrcpNotificationHandler::ListPlayerAppAttrNotification);
-  }
-
-  static void
-  ListPlayerAppValues(btrc_player_attr_t aAttrId)
-  {
-    ListPlayerAppValuesNotification::Dispatch(
-      &BluetoothAvrcpNotificationHandler::ListPlayerAppValuesNotification,
-      aAttrId);
-  }
-
-  static void
-  GetPlayerAppValue(uint8_t aNumAttrs, btrc_player_attr_t* aAttrs)
-  {
-    GetPlayerAppValueNotification::Dispatch(
-      &BluetoothAvrcpNotificationHandler::GetPlayerAppValueNotification,
-      aNumAttrs, ConvertArray<btrc_player_attr_t>(aAttrs, aNumAttrs));
-  }
-
-  static void
-  GetPlayerAppAttrsText(uint8_t aNumAttrs, btrc_player_attr_t* aAttrs)
-  {
-    GetPlayerAppAttrsTextNotification::Dispatch(
-      &BluetoothAvrcpNotificationHandler::GetPlayerAppAttrsTextNotification,
-      aNumAttrs, ConvertArray<btrc_player_attr_t>(aAttrs, aNumAttrs));
-  }
-
-  static void
-  GetPlayerAppValuesText(uint8_t aAttrId, uint8_t aNumVals, uint8_t* aVals)
-  {
-    GetPlayerAppValuesTextNotification::Dispatch(
-      &BluetoothAvrcpNotificationHandler::GetPlayerAppValuesTextNotification,
-      aAttrId, aNumVals, ConvertArray<uint8_t>(aVals, aNumVals));
-  }
-
-  static void
-  SetPlayerAppValue(btrc_player_settings_t* aVals)
-  {
-    SetPlayerAppValueNotification::Dispatch(
-      &BluetoothAvrcpNotificationHandler::SetPlayerAppValueNotification,
-      *aVals);
-  }
-
-  static void
-  GetElementAttr(uint8_t aNumAttrs, btrc_media_attr_t* aAttrs)
-  {
-    GetElementAttrNotification::Dispatch(
-      &BluetoothAvrcpNotificationHandler::GetElementAttrNotification,
-      aNumAttrs, ConvertArray<btrc_media_attr_t>(aAttrs, aNumAttrs));
-  }
-
-  static void
-  RegisterNotification(btrc_event_id_t aEvent, uint32_t aParam)
-  {
-    RegisterNotificationNotification::Dispatch(
-      &BluetoothAvrcpNotificationHandler::RegisterNotificationNotification,
-      aEvent, aParam);
-  }
-#endif // ANDROID_VERSION >= 18
-
-#if ANDROID_VERSION >= 19
-  static void
-  RemoteFeature(bt_bdaddr_t* aBdAddr, btrc_remote_features_t aFeatures)
-  {
-    RemoteFeatureNotification::Dispatch(
-      &BluetoothAvrcpNotificationHandler::RemoteFeatureNotification,
-      aBdAddr, aFeatures);
-  }
-
-  static void
-  VolumeChange(uint8_t aVolume, uint8_t aCType)
-  {
-    VolumeChangeNotification::Dispatch(
-      &BluetoothAvrcpNotificationHandler::VolumeChangeNotification,
-      aVolume, aCType);
-  }
-
-  static void
-  PassthroughCmd(int aId, int aKeyState)
-  {
-    PassthroughCmdNotification::Dispatch(
-      &BluetoothAvrcpNotificationHandler::PassthroughCmdNotification,
-      aId, aKeyState);
-  }
-#endif // ANDROID_VERSION >= 19
-};
-
-// Interface
-//
-
-BluetoothAvrcpHALInterface::BluetoothAvrcpHALInterface(
-#if ANDROID_VERSION >= 18
-  const btrc_interface_t* aInterface
-#endif
-  )
-#if ANDROID_VERSION >= 18
-: mInterface(aInterface)
-#endif
-{
-#if ANDROID_VERSION >= 18
-  MOZ_ASSERT(mInterface);
-#endif
-}
-
-BluetoothAvrcpHALInterface::~BluetoothAvrcpHALInterface()
-{ }
-
-void
-BluetoothAvrcpHALInterface::Init(
-  BluetoothAvrcpNotificationHandler* aNotificationHandler,
-  BluetoothAvrcpResultHandler* aRes)
-{
-#if ANDROID_VERSION >= 18
-  static btrc_callbacks_t sCallbacks = {
-    sizeof(sCallbacks),
-#if ANDROID_VERSION >= 19
-    BluetoothAvrcpCallback::RemoteFeature,
-#endif
-    BluetoothAvrcpCallback::GetPlayStatus,
-    BluetoothAvrcpCallback::ListPlayerAppAttr,
-    BluetoothAvrcpCallback::ListPlayerAppValues,
-    BluetoothAvrcpCallback::GetPlayerAppValue,
-    BluetoothAvrcpCallback::GetPlayerAppAttrsText,
-    BluetoothAvrcpCallback::GetPlayerAppValuesText,
-    BluetoothAvrcpCallback::SetPlayerAppValue,
-    BluetoothAvrcpCallback::GetElementAttr,
-    BluetoothAvrcpCallback::RegisterNotification
-#if ANDROID_VERSION >= 19
-    ,
-    BluetoothAvrcpCallback::VolumeChange,
-    BluetoothAvrcpCallback::PassthroughCmd
-#endif
-  };
-#endif // ANDROID_VERSION >= 18
-
-  sAvrcpNotificationHandler = aNotificationHandler;
-
-#if ANDROID_VERSION >= 18
-  bt_status_t status = mInterface->init(&sCallbacks);
-#else
-  bt_status_t status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothAvrcpHALResult(aRes, &BluetoothAvrcpResultHandler::Init,
-                                    ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothAvrcpHALInterface::Cleanup(BluetoothAvrcpResultHandler* aRes)
-{
-#if ANDROID_VERSION >= 18
-  mInterface->cleanup();
-#endif
-
-  if (aRes) {
-    DispatchBluetoothAvrcpHALResult(aRes,
-      &BluetoothAvrcpResultHandler::Cleanup, STATUS_SUCCESS);
-  }
-}
-
-void
-BluetoothAvrcpHALInterface::GetPlayStatusRsp(
-  ControlPlayStatus aPlayStatus, uint32_t aSongLen, uint32_t aSongPos,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  bt_status_t status;
-
-#if ANDROID_VERSION >= 18
-  btrc_play_status_t playStatus = BTRC_PLAYSTATE_STOPPED;
-
-  if (!(NS_FAILED(Convert(aPlayStatus, playStatus)))) {
-    status = mInterface->get_play_status_rsp(playStatus, aSongLen, aSongPos);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothAvrcpHALResult(
-      aRes, &BluetoothAvrcpResultHandler::GetPlayStatusRsp,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothAvrcpHALInterface::ListPlayerAppAttrRsp(
-  int aNumAttr, const BluetoothAvrcpPlayerAttribute* aPAttrs,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  bt_status_t status;
-
-#if ANDROID_VERSION >= 18
-  ConvertArray<BluetoothAvrcpPlayerAttribute> pAttrsArray(aPAttrs, aNumAttr);
-  nsAutoArrayPtr<btrc_player_attr_t> pAttrs;
-
-  if (NS_SUCCEEDED(Convert(pAttrsArray, pAttrs))) {
-    status = mInterface->list_player_app_attr_rsp(aNumAttr, pAttrs);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothAvrcpHALResult(
-      aRes, &BluetoothAvrcpResultHandler::ListPlayerAppAttrRsp,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothAvrcpHALInterface::ListPlayerAppValueRsp(
-  int aNumVal, uint8_t* aPVals, BluetoothAvrcpResultHandler* aRes)
-{
-#if ANDROID_VERSION >= 18
-  bt_status_t status = mInterface->list_player_app_value_rsp(aNumVal, aPVals);
-#else
-  bt_status_t status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothAvrcpHALResult(
-      aRes, &BluetoothAvrcpResultHandler::ListPlayerAppValueRsp,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothAvrcpHALInterface::GetPlayerAppValueRsp(
-  uint8_t aNumAttrs, const uint8_t* aIds, const uint8_t* aValues,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  bt_status_t status;
-
-#if ANDROID_VERSION >= 18
-  btrc_player_settings_t pVals;
-
-  /* FIXME: you need to implement the missing conversion functions */
-  NS_NOTREACHED("Conversion function missing");
-
-  if (false /* TODO: we don't support any player app values currently */) {
-    status = mInterface->get_player_app_value_rsp(&pVals);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothAvrcpHALResult(
-      aRes, &BluetoothAvrcpResultHandler::GetPlayerAppValueRsp,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothAvrcpHALInterface::GetPlayerAppAttrTextRsp(
-  int aNumAttr, const uint8_t* aIds, const char** aTexts,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  bt_status_t status;
-
-#if ANDROID_VERSION >= 18
-  btrc_player_setting_text_t* aPAttrs;
-
-  /* FIXME: you need to implement the missing conversion functions */
-  NS_NOTREACHED("Conversion function missing");
-
-  if (false /* TODO: we don't support any attributes currently */) {
-    status = mInterface->get_player_app_attr_text_rsp(aNumAttr, aPAttrs);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothAvrcpHALResult(
-      aRes, &BluetoothAvrcpResultHandler::GetPlayerAppAttrTextRsp,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothAvrcpHALInterface::GetPlayerAppValueTextRsp(
-  int aNumVal, const uint8_t* aIds, const char** aTexts,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  bt_status_t status;
-
-#if ANDROID_VERSION >= 18
-  btrc_player_setting_text_t* pVals;
-
-  /* FIXME: you need to implement the missing conversion functions */
-  NS_NOTREACHED("Conversion function missing");
-
-  if (false /* TODO: we don't support any values currently */) {
-    status = mInterface->get_player_app_value_text_rsp(aNumVal, pVals);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothAvrcpHALResult(
-      aRes, &BluetoothAvrcpResultHandler::GetPlayerAppValueTextRsp,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothAvrcpHALInterface::GetElementAttrRsp(
-  uint8_t aNumAttr, const BluetoothAvrcpElementAttribute* aAttrs,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  bt_status_t status;
-
-#if ANDROID_VERSION >= 18
-  ConvertArray<BluetoothAvrcpElementAttribute> pAttrsArray(aAttrs, aNumAttr);
-  nsAutoArrayPtr<btrc_element_attr_val_t> pAttrs;
-
-  if (NS_SUCCEEDED(Convert(pAttrsArray, pAttrs))) {
-    status = mInterface->get_element_attr_rsp(aNumAttr, pAttrs);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothAvrcpHALResult(
-      aRes, &BluetoothAvrcpResultHandler::GetElementAttrRsp,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothAvrcpHALInterface::SetPlayerAppValueRsp(
-  BluetoothAvrcpStatus aRspStatus, BluetoothAvrcpResultHandler* aRes)
-{
-  bt_status_t status;
-
-#if ANDROID_VERSION >= 18
-  btrc_status_t rspStatus = BTRC_STS_BAD_CMD; // silences compiler warning
-
-  if (NS_SUCCEEDED(Convert(aRspStatus, rspStatus))) {
-    status = mInterface->set_player_app_value_rsp(rspStatus);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothAvrcpHALResult(
-      aRes, &BluetoothAvrcpResultHandler::SetPlayerAppValueRsp,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothAvrcpHALInterface::RegisterNotificationRsp(
-  BluetoothAvrcpEvent aEvent, BluetoothAvrcpNotification aType,
-  const BluetoothAvrcpNotificationParam& aParam,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  bt_status_t status;
-
-#if ANDROID_VERSION >= 18
-  nsresult rv;
-  btrc_event_id_t event = { };
-  btrc_notification_type_t type = BTRC_NOTIFICATION_TYPE_INTERIM;
-  btrc_register_notification_t param;
-
-  switch (aEvent) {
-    case AVRCP_EVENT_PLAY_STATUS_CHANGED:
-      rv = Convert(aParam.mPlayStatus, param.play_status);
-      break;
-    case AVRCP_EVENT_TRACK_CHANGE:
-      MOZ_ASSERT(sizeof(aParam.mTrack) == sizeof(param.track));
-      memcpy(param.track, aParam.mTrack, sizeof(param.track));
-      rv = NS_OK;
-      break;
-    case AVRCP_EVENT_TRACK_REACHED_END:
-      NS_NOTREACHED("Unknown conversion");
-      rv = NS_ERROR_ILLEGAL_VALUE;
-      break;
-    case AVRCP_EVENT_TRACK_REACHED_START:
-      NS_NOTREACHED("Unknown conversion");
-      rv = NS_ERROR_ILLEGAL_VALUE;
-      break;
-    case AVRCP_EVENT_PLAY_POS_CHANGED:
-      param.song_pos = aParam.mSongPos;
-      rv = NS_OK;
-      break;
-    case AVRCP_EVENT_APP_SETTINGS_CHANGED:
-      NS_NOTREACHED("Unknown conversion");
-      rv = NS_ERROR_ILLEGAL_VALUE;
-      break;
-    default:
-      NS_NOTREACHED("Unknown conversion");
-      rv = NS_ERROR_ILLEGAL_VALUE;
-      break;
-  }
-
-  if (NS_SUCCEEDED(rv) &&
-      NS_SUCCEEDED(Convert(aEvent, event)) &&
-      NS_SUCCEEDED(Convert(aType, type))) {
-    status = mInterface->register_notification_rsp(event, type, &param);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothAvrcpHALResult(
-      aRes, &BluetoothAvrcpResultHandler::RegisterNotificationRsp,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothAvrcpHALInterface::SetVolume(uint8_t aVolume,
-                                      BluetoothAvrcpResultHandler* aRes)
-{
-#if ANDROID_VERSION >= 19
-  bt_status_t status = mInterface->set_volume(aVolume);
-#else
-  bt_status_t status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothAvrcpHALResult(
-      aRes, &BluetoothAvrcpResultHandler::SetVolume,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothAvrcpHALInterface.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_dom_bluetooth_bluedroid_bluetoothavrcphalinterface_h__
-#define mozilla_dom_bluetooth_bluedroid_bluetoothavrcphalinterface_h__
-
-#include <hardware/bluetooth.h>
-#if ANDROID_VERSION >= 18
-#include <hardware/bt_rc.h>
-#endif
-#include "BluetoothCommon.h"
-#include "BluetoothInterface.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothHALInterface;
-
-class BluetoothAvrcpHALInterface final
-  : public BluetoothAvrcpInterface
-{
-public:
-  friend class BluetoothHALInterface;
-
-  void Init(BluetoothAvrcpNotificationHandler* aNotificationHandler,
-            BluetoothAvrcpResultHandler* aRes);
-  void Cleanup(BluetoothAvrcpResultHandler* aRes);
-
-  void GetPlayStatusRsp(ControlPlayStatus aPlayStatus,
-                        uint32_t aSongLen, uint32_t aSongPos,
-                        BluetoothAvrcpResultHandler* aRes);
-
-  void ListPlayerAppAttrRsp(int aNumAttr,
-                            const BluetoothAvrcpPlayerAttribute* aPAttrs,
-                            BluetoothAvrcpResultHandler* aRes);
-  void ListPlayerAppValueRsp(int aNumVal, uint8_t* aPVals,
-                             BluetoothAvrcpResultHandler* aRes);
-
-  /* TODO: redesign this interface once we actually use it */
-  void GetPlayerAppValueRsp(uint8_t aNumAttrs,
-                            const uint8_t* aIds, const uint8_t* aValues,
-                            BluetoothAvrcpResultHandler* aRes);
-  /* TODO: redesign this interface once we actually use it */
-  void GetPlayerAppAttrTextRsp(int aNumAttr,
-                               const uint8_t* aIds, const char** aTexts,
-                               BluetoothAvrcpResultHandler* aRes);
-  /* TODO: redesign this interface once we actually use it */
-  void GetPlayerAppValueTextRsp(int aNumVal,
-                                const uint8_t* aIds, const char** aTexts,
-                                BluetoothAvrcpResultHandler* aRes);
-
-  void GetElementAttrRsp(uint8_t aNumAttr,
-                         const BluetoothAvrcpElementAttribute* aAttr,
-                         BluetoothAvrcpResultHandler* aRes);
-
-  void SetPlayerAppValueRsp(BluetoothAvrcpStatus aRspStatus,
-                            BluetoothAvrcpResultHandler* aRes);
-
-  void RegisterNotificationRsp(BluetoothAvrcpEvent aEvent,
-                               BluetoothAvrcpNotification aType,
-                               const BluetoothAvrcpNotificationParam& aParam,
-                               BluetoothAvrcpResultHandler* aRes);
-
-  void SetVolume(uint8_t aVolume, BluetoothAvrcpResultHandler* aRes);
-
-protected:
-  BluetoothAvrcpHALInterface(
-#if ANDROID_VERSION >= 18
-    const btrc_interface_t* aInterface
-#endif
-    );
-  ~BluetoothAvrcpHALInterface();
-
-private:
-#if ANDROID_VERSION >= 18
-  const btrc_interface_t* mInterface;
-#endif
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothGattHALInterface.cpp
+++ /dev/null
@@ -1,1811 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "BluetoothGattHALInterface.h"
-#include "BluetoothHALHelpers.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-typedef
-  BluetoothHALInterfaceRunnable0<BluetoothGattClientResultHandler, void>
-  BluetoothGattClientHALResultRunnable;
-
-typedef
-  BluetoothHALInterfaceRunnable1<BluetoothGattClientResultHandler, void,
-                                 BluetoothTypeOfDevice, BluetoothTypeOfDevice>
-  BluetoothGattClientGetDeviceTypeHALResultRunnable;
-
-typedef
-  BluetoothHALInterfaceRunnable1<BluetoothGattClientResultHandler, void,
-                                 BluetoothStatus, BluetoothStatus>
-  BluetoothGattClientHALErrorRunnable;
-
-typedef
-  BluetoothHALInterfaceRunnable0<BluetoothGattServerResultHandler, void>
-  BluetoothGattServerHALResultRunnable;
-
-typedef
-  BluetoothHALInterfaceRunnable1<BluetoothGattServerResultHandler, void,
-                                 BluetoothStatus, BluetoothStatus>
-  BluetoothGattServerHALErrorRunnable;
-
-typedef
-  BluetoothHALInterfaceRunnable0<BluetoothGattResultHandler, void>
-  BluetoothGattHALResultRunnable;
-
-typedef
-  BluetoothHALInterfaceRunnable1<BluetoothGattResultHandler, void,
-                                 BluetoothStatus, BluetoothStatus>
-  BluetoothGattHALErrorRunnable;
-
-static nsresult
-DispatchBluetoothGattClientHALResult(
-  BluetoothGattClientResultHandler* aRes,
-  void (BluetoothGattClientResultHandler::*aMethod)(),
-  BluetoothStatus aStatus)
-{
-  MOZ_ASSERT(aRes);
-
-  nsRunnable* runnable;
-
-  if (aStatus == STATUS_SUCCESS) {
-    runnable = new BluetoothGattClientHALResultRunnable(aRes, aMethod);
-  } else {
-    runnable = new BluetoothGattClientHALErrorRunnable(aRes,
-      &BluetoothGattClientResultHandler::OnError, aStatus);
-  }
-  nsresult rv = NS_DispatchToMainThread(runnable);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-  }
-  return rv;
-}
-
-template <typename ResultRunnable, typename Tin1, typename Arg1>
-static nsresult
-DispatchBluetoothGattClientHALResult(
-  BluetoothGattClientResultHandler* aRes,
-  void (BluetoothGattClientResultHandler::*aMethod)(Arg1),
-  Tin1 aArg1,
-  BluetoothStatus aStatus)
-{
-  MOZ_ASSERT(aRes);
-
-  nsRunnable* runnable;
-  Arg1 arg1;
-
-  if (aStatus != STATUS_SUCCESS) {
-    runnable = new BluetoothGattClientHALErrorRunnable(aRes,
-      &BluetoothGattClientResultHandler::OnError, aStatus);
-  } else if (NS_FAILED(Convert(aArg1, arg1))) {
-    runnable = new BluetoothGattClientHALErrorRunnable(aRes,
-      &BluetoothGattClientResultHandler::OnError, STATUS_PARM_INVALID);
-  } else {
-    runnable = new ResultRunnable(aRes, aMethod, arg1);
-  }
-  nsresult rv = NS_DispatchToMainThread(runnable);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-  }
-  return rv;
-}
-
-static nsresult
-DispatchBluetoothGattServerHALResult(
-  BluetoothGattServerResultHandler* aRes,
-  void (BluetoothGattServerResultHandler::*aMethod)(),
-  BluetoothStatus aStatus)
-{
-  MOZ_ASSERT(aRes);
-
-  nsRunnable* runnable;
-
-  if (aStatus == STATUS_SUCCESS) {
-    runnable = new BluetoothGattServerHALResultRunnable(aRes, aMethod);
-  } else {
-    runnable = new BluetoothGattServerHALErrorRunnable(aRes,
-      &BluetoothGattServerResultHandler::OnError, aStatus);
-  }
-  nsresult rv = NS_DispatchToMainThread(runnable);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-  }
-  return rv;
-}
-
-static nsresult
-DispatchBluetoothGattHALResult(
-  BluetoothGattResultHandler* aRes,
-  void (BluetoothGattResultHandler::*aMethod)(),
-  BluetoothStatus aStatus)
-{
-  MOZ_ASSERT(aRes);
-
-  nsRunnable* runnable;
-
-  if (aStatus == STATUS_SUCCESS) {
-    runnable = new BluetoothGattHALResultRunnable(aRes, aMethod);
-  } else {
-    runnable = new BluetoothGattHALErrorRunnable(aRes,
-      &BluetoothGattResultHandler::OnError, aStatus);
-  }
-  nsresult rv = NS_DispatchToMainThread(runnable);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-  }
-  return rv;
-}
-
-// Notification Handling
-//
-
-static BluetoothGattNotificationHandler* sGattNotificationHandler;
-
-struct BluetoothGattClientCallback
-{
-  class GattClientNotificationHandlerWrapper
-  {
-  public:
-    typedef BluetoothGattClientNotificationHandler ObjectType;
-
-    static ObjectType* GetInstance()
-    {
-      MOZ_ASSERT(NS_IsMainThread());
-
-      return sGattNotificationHandler;
-    }
-  };
-
-  // Notifications
-
-  // GATT Client Notification
-  typedef BluetoothNotificationHALRunnable3<
-    GattClientNotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, BluetoothUuid,
-    BluetoothGattStatus, int, const BluetoothUuid&>
-    RegisterClientNotification;
-
-  typedef BluetoothNotificationHALRunnable3<
-    GattClientNotificationHandlerWrapper, void,
-    nsString, int, BluetoothGattAdvData,
-    const nsAString&, int, const BluetoothGattAdvData&>
-    ScanResultNotification;
-
-  typedef BluetoothNotificationHALRunnable4<
-    GattClientNotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, int, nsString,
-    int, BluetoothGattStatus, int, const nsAString&>
-    ConnectNotification;
-
-  typedef BluetoothNotificationHALRunnable4<
-    GattClientNotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, int, nsString,
-    int, BluetoothGattStatus, int, const nsAString&>
-    DisconnectNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    GattClientNotificationHandlerWrapper, void,
-    int, BluetoothGattStatus>
-    SearchCompleteNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    GattClientNotificationHandlerWrapper, void,
-    int, BluetoothGattServiceId,
-    int, const BluetoothGattServiceId&>
-    SearchResultNotification;
-
-  typedef BluetoothNotificationHALRunnable5<
-    GattClientNotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, BluetoothGattServiceId,
-    BluetoothGattId, BluetoothGattCharProp,
-    int, BluetoothGattStatus, const BluetoothGattServiceId&,
-    const BluetoothGattId&, const BluetoothGattCharProp&>
-    GetCharacteristicNotification;
-
-  typedef BluetoothNotificationHALRunnable5<
-    GattClientNotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, BluetoothGattServiceId,
-    BluetoothGattId, BluetoothGattId,
-    int, BluetoothGattStatus, const BluetoothGattServiceId&,
-    const BluetoothGattId&, const BluetoothGattId&>
-    GetDescriptorNotification;
-
-  typedef BluetoothNotificationHALRunnable4<
-    GattClientNotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, BluetoothGattServiceId, BluetoothGattServiceId,
-    int, BluetoothGattStatus, const BluetoothGattServiceId&,
-    const BluetoothGattServiceId&>
-    GetIncludedServiceNotification;
-
-  typedef BluetoothNotificationHALRunnable5<
-    GattClientNotificationHandlerWrapper, void,
-    int, int, BluetoothGattStatus,
-    BluetoothGattServiceId, BluetoothGattId,
-    int, int, BluetoothGattStatus,
-    const BluetoothGattServiceId&, const BluetoothGattId&>
-    RegisterNotificationNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    GattClientNotificationHandlerWrapper, void,
-    int, BluetoothGattNotifyParam,
-    int, const BluetoothGattNotifyParam&>
-    NotifyNotification;
-
-  typedef BluetoothNotificationHALRunnable3<
-    GattClientNotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, BluetoothGattReadParam,
-    int, BluetoothGattStatus, const BluetoothGattReadParam&>
-    ReadCharacteristicNotification;
-
-  typedef BluetoothNotificationHALRunnable3<
-    GattClientNotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, BluetoothGattWriteParam,
-    int, BluetoothGattStatus, const BluetoothGattWriteParam&>
-    WriteCharacteristicNotification;
-
-  typedef BluetoothNotificationHALRunnable3<
-    GattClientNotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, BluetoothGattReadParam,
-    int, BluetoothGattStatus, const BluetoothGattReadParam&>
-    ReadDescriptorNotification;
-
-  typedef BluetoothNotificationHALRunnable3<
-    GattClientNotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, BluetoothGattWriteParam,
-    int, BluetoothGattStatus, const BluetoothGattWriteParam&>
-    WriteDescriptorNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    GattClientNotificationHandlerWrapper, void,
-    int, BluetoothGattStatus>
-    ExecuteWriteNotification;
-
-  typedef BluetoothNotificationHALRunnable4<
-    GattClientNotificationHandlerWrapper, void,
-    int, nsString, int, BluetoothGattStatus,
-    int, const nsAString&, int, BluetoothGattStatus>
-    ReadRemoteRssiNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    GattClientNotificationHandlerWrapper, void,
-    BluetoothGattStatus, int>
-    ListenNotification;
-
-  // Bluedroid GATT client callbacks
-#if ANDROID_VERSION >= 19
-  static void
-  RegisterClient(int aStatus, int aClientIf, bt_uuid_t* aAppUuid)
-  {
-    RegisterClientNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::RegisterClientNotification,
-      aStatus, aClientIf, *aAppUuid);
-  }
-
-  static void
-  ScanResult(bt_bdaddr_t* aBdAddr, int aRssi, uint8_t* aAdvData)
-  {
-    ScanResultNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::ScanResultNotification,
-      aBdAddr, aRssi, aAdvData);
-  }
-
-  static void
-  Connect(int aConnId, int aStatus, int aClientIf, bt_bdaddr_t* aBdAddr)
-  {
-    ConnectNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::ConnectNotification,
-      aConnId, aStatus, aClientIf, aBdAddr);
-  }
-
-  static void
-  Disconnect(int aConnId, int aStatus, int aClientIf, bt_bdaddr_t* aBdAddr)
-  {
-    DisconnectNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::DisconnectNotification,
-      aConnId, aStatus, aClientIf, aBdAddr);
-  }
-
-  static void
-  SearchComplete(int aConnId, int aStatus)
-  {
-    SearchCompleteNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::SearchCompleteNotification,
-      aConnId, aStatus);
-  }
-
-  static void
-  SearchResult(int aConnId, btgatt_srvc_id_t* aServiceId)
-  {
-    SearchResultNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::SearchResultNotification,
-      aConnId, *aServiceId);
-  }
-
-  static void
-  GetCharacteristic(int aConnId, int aStatus,
-                    btgatt_srvc_id_t* aServiceId,
-                    btgatt_gatt_id_t* aCharId,
-                    int aCharProperty)
-  {
-    GetCharacteristicNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::GetCharacteristicNotification,
-      aConnId, aStatus, *aServiceId, *aCharId, aCharProperty);
-  }
-
-  static void
-  GetDescriptor(int aConnId, int aStatus,
-                btgatt_srvc_id_t* aServiceId,
-                btgatt_gatt_id_t* aCharId,
-                btgatt_gatt_id_t* aDescriptorId)
-  {
-    GetDescriptorNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::GetDescriptorNotification,
-      aConnId, aStatus, *aServiceId, *aCharId, *aDescriptorId);
-  }
-
-  static void
-  GetIncludedService(int aConnId, int aStatus,
-                     btgatt_srvc_id_t* aServiceId,
-                     btgatt_srvc_id_t* aIncludedServiceId)
-  {
-    GetIncludedServiceNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::GetIncludedServiceNotification,
-      aConnId, aStatus, *aServiceId, *aIncludedServiceId);
-  }
-
-  static void
-  RegisterNotification(int aConnId, int aIsRegister, int aStatus,
-                       btgatt_srvc_id_t* aServiceId,
-                       btgatt_gatt_id_t* aCharId)
-  {
-    RegisterNotificationNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::RegisterNotificationNotification,
-      aConnId, aIsRegister, aStatus, *aServiceId, *aCharId);
-  }
-
-  static void
-  Notify(int aConnId, btgatt_notify_params_t* aParam)
-  {
-    NotifyNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::NotifyNotification,
-      aConnId, *aParam);
-  }
-
-  static void
-  ReadCharacteristic(int aConnId, int aStatus, btgatt_read_params_t* aParam)
-  {
-    ReadCharacteristicNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::ReadCharacteristicNotification,
-      aConnId, aStatus, *aParam);
-  }
-
-  static void
-  WriteCharacteristic(int aConnId, int aStatus, btgatt_write_params_t* aParam)
-  {
-    WriteCharacteristicNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::WriteCharacteristicNotification,
-      aConnId, aStatus, *aParam);
-  }
-
-  static void
-  ReadDescriptor(int aConnId, int aStatus, btgatt_read_params_t* aParam)
-  {
-    ReadDescriptorNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::ReadDescriptorNotification,
-      aConnId, aStatus, *aParam);
-  }
-
-  static void
-  WriteDescriptor(int aConnId, int aStatus, btgatt_write_params_t* aParam)
-  {
-    WriteDescriptorNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::WriteDescriptorNotification,
-      aConnId, aStatus, *aParam);
-  }
-
-  static void
-  ExecuteWrite(int aConnId, int aStatus)
-  {
-    ExecuteWriteNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::ExecuteWriteNotification,
-      aConnId, aStatus);
-  }
-
-  static void
-  ReadRemoteRssi(int aClientIf, bt_bdaddr_t* aBdAddr, int aRssi, int aStatus)
-  {
-    ReadRemoteRssiNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::ReadRemoteRssiNotification,
-      aClientIf, aBdAddr, aRssi, aStatus);
-  }
-
-  static void
-  Listen(int aStatus, int aServerIf)
-  {
-    ListenNotification::Dispatch(
-      &BluetoothGattClientNotificationHandler::ListenNotification,
-      aStatus, aServerIf);
-  }
-#endif // ANDROID_VERSION >= 19
-};
-
-struct BluetoothGattServerCallback
-{
-  class GattServerNotificationHandlerWrapper
-  {
-  public:
-    typedef BluetoothGattServerNotificationHandler ObjectType;
-
-    static ObjectType* GetInstance()
-    {
-      MOZ_ASSERT(NS_IsMainThread());
-
-      return sGattNotificationHandler;
-    }
-  };
-
-  // Notifications
-  typedef BluetoothNotificationHALRunnable3<
-    GattServerNotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, BluetoothUuid,
-    BluetoothGattStatus, int, const BluetoothUuid&>
-    RegisterServerNotification;
-
-  typedef BluetoothNotificationHALRunnable4<
-    GattServerNotificationHandlerWrapper, void,
-    int, int, bool, nsString,
-    int, int, bool, const nsAString&>
-    ConnectionNotification;
-
-  typedef BluetoothNotificationHALRunnable4<
-    GattServerNotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, BluetoothGattServiceId, int,
-    BluetoothGattStatus, int, const BluetoothGattServiceId&, int>
-    ServiceAddedNotification;
-
-  typedef BluetoothNotificationHALRunnable4<
-    GattServerNotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, int, int>
-    IncludedServiceAddedNotification;
-
-  typedef BluetoothNotificationHALRunnable5<
-    GattServerNotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, BluetoothUuid, int, int,
-    BluetoothGattStatus, int, const BluetoothUuid&, int, int>
-    CharacteristicAddedNotification;
-
-  typedef BluetoothNotificationHALRunnable5<
-    GattServerNotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, BluetoothUuid, int, int,
-    BluetoothGattStatus, int, const BluetoothUuid&, int, int>
-    DescriptorAddedNotification;
-
-  typedef BluetoothNotificationHALRunnable3<
-    GattServerNotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, int>
-    ServiceStartedNotification;
-
-  typedef BluetoothNotificationHALRunnable3<
-    GattServerNotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, int>
-    ServiceStoppedNotification;
-
-  typedef BluetoothNotificationHALRunnable3<
-    GattServerNotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, int>
-    ServiceDeletedNotification;
-
-  typedef BluetoothNotificationHALRunnable6<
-    GattServerNotificationHandlerWrapper, void,
-    int, int, nsString, int, int, bool,
-    int, int, const nsAString&, int, int, bool>
-    RequestReadNotification;
-
-  typedef BluetoothNotificationHALRunnable9<
-    GattServerNotificationHandlerWrapper, void,
-    int, int, nsString, int, int, int, nsAutoArrayPtr<uint8_t>, bool, bool,
-    int, int, const nsAString&, int, int, int, const uint8_t*, bool, bool>
-    RequestWriteNotification;
-
-  typedef BluetoothNotificationHALRunnable4<
-    GattServerNotificationHandlerWrapper, void,
-    int, int, nsString, bool,
-    int, int, const nsAString&, bool>
-    RequestExecuteWriteNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    GattServerNotificationHandlerWrapper, void,
-    BluetoothGattStatus, int>
-    ResponseConfirmationNotification;
-
-#if ANDROID_VERSION >= 21
-  typedef BluetoothNotificationHALRunnable2<
-    GattServerNotificationHandlerWrapper, void,
-    int, BluetoothGattStatus>
-    IndicationSentNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    GattServerNotificationHandlerWrapper, void,
-    int, bool>
-    CongestionNotification;
-#endif // ANDROID_VERSION >= 21
-
-#if ANDROID_VERSION >=22
-  typedef BluetoothNotificationHALRunnable2<
-    GattServerNotificationHandlerWrapper, void,
-    int, int>
-    MtuChangedNotification;
-#endif // ANDROID_VERSION >=22
-
-  // GATT Server callbacks
-#if ANDROID_VERSION >= 19
-  static void
-  RegisterServer(int aStatus, int aServerIf, bt_uuid_t* aAppUuid)
-  {
-    RegisterServerNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::RegisterServerNotification,
-      aStatus, aServerIf, *aAppUuid);
-  }
-
-  static void
-  Connection(int aConnId, int aServerIf, int aIsConnected,
-             bt_bdaddr_t* aBdAddr)
-  {
-    ConnectionNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::ConnectionNotification,
-      aConnId, aServerIf, aIsConnected != 0, aBdAddr);
-  }
-
-  static void
-  ServiceAdded(int aStatus, int aServerIf, btgatt_srvc_id_t* aServiceId,
-               int aServiceHandle)
-  {
-    ServiceAddedNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::ServiceAddedNotification,
-      aStatus, aServerIf, *aServiceId, aServiceHandle);
-  }
-
-  static void
-  IncludedServiceAdded(int aStatus, int aServerIf, int aServiceHandle,
-                       int aIncludedServiceHandle)
-  {
-    IncludedServiceAddedNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::IncludedServiceAddedNotification,
-      aStatus, aServerIf, aServiceHandle, aIncludedServiceHandle);
-  }
-
-  static void
-  CharacteristicAdded(int aStatus, int aServerIf, bt_uuid_t* aUuid,
-                      int aServiceHandle, int aCharHandle)
-  {
-    CharacteristicAddedNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::CharacteristicAddedNotification,
-      aStatus, aServerIf, *aUuid, aServiceHandle, aCharHandle);
-  }
-
-  static void
-  DescriptorAdded(int aStatus, int aServerIf, bt_uuid_t* aUuid,
-                  int aServiceHandle, int aDescriptorHandle)
-  {
-    DescriptorAddedNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::DescriptorAddedNotification,
-      aStatus, aServerIf, *aUuid, aServiceHandle, aDescriptorHandle);
-  }
-
-  static void
-  ServiceStarted(int aStatus, int aServerIf, int aServiceHandle)
-  {
-    ServiceStartedNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::ServiceStartedNotification,
-      aStatus, aServerIf, aServiceHandle);
-  }
-
-  static void
-  ServiceStopped(int aStatus, int aServerIf, int aServiceHandle)
-  {
-    ServiceStoppedNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::ServiceStoppedNotification,
-      aStatus, aServerIf, aServiceHandle);
-  }
-
-  static void
-  ServiceDeleted(int aStatus, int aServerIf, int aServiceHandle)
-  {
-    ServiceDeletedNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::ServiceDeletedNotification,
-      aStatus, aServerIf, aServiceHandle);
-  }
-
-  static void
-  RequestRead(int aConnId, int aTransId, bt_bdaddr_t* aBdAddr,
-              int aAttrHandle, int aOffset, bool aIsLong)
-  {
-    RequestReadNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::RequestReadNotification,
-      aConnId, aTransId, *aBdAddr, aAttrHandle, aOffset, aIsLong);
-  }
-
-  static void
-  RequestWrite(int aConnId, int aTransId, bt_bdaddr_t* aBdAddr,
-               int aAttrHandle, int aOffset, int aLength,
-               bool aNeedRsp, bool aIsPrep, uint8_t* aValue)
-  {
-    RequestWriteNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::RequestWriteNotification,
-      aConnId, aTransId, *aBdAddr, aAttrHandle, aOffset, aLength,
-      ConvertArray<uint8_t>(aValue, aLength), aNeedRsp, aIsPrep);
-  }
-
-  static void
-  RequestExecuteWrite(int aConnId, int aTransId, bt_bdaddr_t* aBdAddr,
-                      int aExecWrite)
-  {
-    RequestExecuteWriteNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::RequestExecuteWriteNotification,
-      aConnId, aTransId, *aBdAddr, aExecWrite != 0);
-  }
-
-  static void
-  ResponseConfirmation(int aStatus, int aHandle)
-  {
-    ResponseConfirmationNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::ResponseConfirmationNotification,
-      aStatus, aHandle);
-  }
-#endif // ANDROID_VERSION >= 19
-
-#if ANDROID_VERSION >= 21
-  static void
-  IndicationSent(int aConnId, int aStatus)
-  {
-    IndicationSentNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::IndicationSentNotification,
-      aConnId, aStatus);
-  }
-
-  static void
-  Congestion(int aConnId, bool aCongested)
-  {
-    CongestionNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::CongestionNotification,
-      aConnId, aCongested);
-  }
-#endif // ANDROID_VERSION >= 21
-
-#if ANDROID_VERSION >= 22
-  static void
-  MtuChanged(int aConnId, int aMtu)
-  {
-    MtuChangedNotification::Dispatch(
-      &BluetoothGattServerNotificationHandler::MtuChangedNotification,
-      aConnId, aMtu);
-  }
-#endif // ANDROID_VERSION >= 22
-};
-
-// GATT Client Interface
-
-BluetoothGattClientHALInterface::BluetoothGattClientHALInterface(
-#if ANDROID_VERSION >= 19
-  const btgatt_client_interface_t* aInterface
-#endif
-  )
-#if ANDROID_VERSION >= 19
-  :mInterface(aInterface)
-#endif
-{
-#if ANDROID_VERSION >= 19
-  MOZ_ASSERT(mInterface);
-#endif
-}
-
-BluetoothGattClientHALInterface::~BluetoothGattClientHALInterface()
-{ }
-
-void
-BluetoothGattClientHALInterface::RegisterClient(
-  const BluetoothUuid& aUuid, BluetoothGattClientResultHandler* aRes)
-{
-  int status;
-
-#if ANDROID_VERSION >= 19
-  bt_uuid_t uuid;
-  if (NS_SUCCEEDED(Convert(aUuid, uuid))) {
-    status = mInterface->register_client(&uuid);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::RegisterClient,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::UnregisterClient(
-  int aClientIf, BluetoothGattClientResultHandler* aRes)
-{
-#if ANDROID_VERSION >= 19
-  int status = mInterface->unregister_client(aClientIf);
-#else
-  int status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::UnregisterClient,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::Scan(
-  int aClientIf, bool aStart, BluetoothGattClientResultHandler* aRes)
-{
-#if ANDROID_VERSION >= 21
-  int status = mInterface->scan(aStart);
-#elif ANDROID_VERSION >= 19
-  int status = mInterface->scan(aClientIf, aStart);
-#else
-  int status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::Scan,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::Connect(
-  int aClientIf, const nsAString& aBdAddr,
-  bool aIsDirect, BluetoothTransport aTransport,
-  BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 21
-  bt_bdaddr_t bdAddr;
-  btgatt_transport_t transport;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr)) ||
-      NS_SUCCEEDED(Convert(aTransport, transport))) {
-    status = mInterface->connect(aClientIf, &bdAddr, aIsDirect, transport);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#elif ANDROID_VERSION >= 19
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->connect(aClientIf, &bdAddr, aIsDirect);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::Connect,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::Disconnect(
-  int aClientIf, const nsAString& aBdAddr,
-  int aConnId, BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->disconnect(aClientIf, &bdAddr, aConnId);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::Disconnect,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::Listen(
-  int aClientIf, bool aIsStart, BluetoothGattClientResultHandler* aRes)
-{
-#if ANDROID_VERSION >= 19
-  bt_status_t status = mInterface->listen(aClientIf, aIsStart);
-#else
-  bt_status_t status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::Listen,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::Refresh(
-  int aClientIf, const nsAString& aBdAddr,
-  BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->refresh(aClientIf, &bdAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::Refresh,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::SearchService(
-  int aConnId, bool aSearchAll, const BluetoothUuid& aUuid,
-  BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  bt_uuid_t uuid;
-
-  if (aSearchAll) {
-    status = mInterface->search_service(aConnId, 0);
-  } else if (NS_SUCCEEDED(Convert(aUuid, uuid))) {
-    status = mInterface->search_service(aConnId, &uuid);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::SearchService,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::GetIncludedService(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  bool aFirst, const BluetoothGattServiceId& aStartServiceId,
-  BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  btgatt_srvc_id_t serviceId;
-  btgatt_srvc_id_t startServiceId;
-
-  if (aFirst && NS_SUCCEEDED(Convert(aServiceId, serviceId))) {
-    status = mInterface->get_included_service(aConnId, &serviceId, 0);
-  } else if (NS_SUCCEEDED(Convert(aServiceId, serviceId)) &&
-             NS_SUCCEEDED(Convert(aStartServiceId, startServiceId))) {
-    status = mInterface->get_included_service(aConnId, &serviceId,
-                                              &startServiceId);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::GetIncludedService,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::GetCharacteristic(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  bool aFirst, const BluetoothGattId& aStartCharId,
-  BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  btgatt_srvc_id_t serviceId;
-  btgatt_gatt_id_t startCharId;
-
-  if (aFirst && NS_SUCCEEDED(Convert(aServiceId, serviceId))) {
-    status = mInterface->get_characteristic(aConnId, &serviceId, 0);
-  } else if (NS_SUCCEEDED(Convert(aServiceId, serviceId)) &&
-             NS_SUCCEEDED(Convert(aStartCharId, startCharId))) {
-    status = mInterface->get_characteristic(aConnId, &serviceId, &startCharId);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::GetCharacteristic,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::GetDescriptor(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId, bool aFirst,
-  const BluetoothGattId& aDescriptorId, BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  btgatt_srvc_id_t serviceId;
-  btgatt_gatt_id_t charId;
-  btgatt_gatt_id_t descriptorId;
-
-  if (aFirst &&
-      NS_SUCCEEDED(Convert(aServiceId, serviceId)) &&
-      NS_SUCCEEDED(Convert(aCharId, charId))) {
-    status = mInterface->get_descriptor(aConnId, &serviceId, &charId, 0);
-  } else if (NS_SUCCEEDED(Convert(aServiceId, serviceId)) &&
-             NS_SUCCEEDED(Convert(aCharId, charId)) &&
-             NS_SUCCEEDED(Convert(aDescriptorId, descriptorId))) {
-    status = mInterface->get_descriptor(aConnId, &serviceId, &charId,
-                                        &descriptorId);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::GetDescriptor,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::ReadCharacteristic(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId, BluetoothGattAuthReq aAuthReq,
-  BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  btgatt_srvc_id_t serviceId;
-  btgatt_gatt_id_t charId;
-  int authReq;
-
-  if (NS_SUCCEEDED(Convert(aServiceId, serviceId)) &&
-      NS_SUCCEEDED(Convert(aCharId, charId)) &&
-      NS_SUCCEEDED(Convert(aAuthReq, authReq))) {
-    status = mInterface->read_characteristic(aConnId, &serviceId, &charId,
-                                             authReq);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::ReadCharacteristic,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::WriteCharacteristic(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId, BluetoothGattWriteType aWriteType,
-  BluetoothGattAuthReq aAuthReq, const nsTArray<uint8_t>& aValue,
-  BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  btgatt_srvc_id_t serviceId;
-  btgatt_gatt_id_t charId;
-  int writeType;
-  int authReq;
-
-  if (NS_SUCCEEDED(Convert(aServiceId, serviceId)) &&
-      NS_SUCCEEDED(Convert(aCharId, charId)) &&
-      NS_SUCCEEDED(Convert(aWriteType, writeType)) &&
-      NS_SUCCEEDED(Convert(aAuthReq, authReq))) {
-    status = mInterface->write_characteristic(
-      aConnId, &serviceId, &charId, writeType,
-      aValue.Length() * sizeof(uint8_t), authReq,
-      reinterpret_cast<char*>(const_cast<uint8_t*>(aValue.Elements())));
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::WriteCharacteristic,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::ReadDescriptor(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId,
-  const BluetoothGattId& aDescriptorId,
-  BluetoothGattAuthReq aAuthReq, BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  btgatt_srvc_id_t serviceId;
-  btgatt_gatt_id_t charId;
-  btgatt_gatt_id_t descriptorId;
-  int authReq;
-
-  if (NS_SUCCEEDED(Convert(aServiceId, serviceId)) &&
-      NS_SUCCEEDED(Convert(aCharId, charId)) &&
-      NS_SUCCEEDED(Convert(aDescriptorId, descriptorId)) &&
-      NS_SUCCEEDED(Convert(aAuthReq, authReq))) {
-    status = mInterface->read_descriptor(aConnId, &serviceId, &charId,
-                                         &descriptorId, authReq);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::ReadDescriptor,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::WriteDescriptor(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId,
-  const BluetoothGattId& aDescriptorId,
-  BluetoothGattWriteType aWriteType,
-  BluetoothGattAuthReq aAuthReq,
-  const nsTArray<uint8_t>& aValue,
-  BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  btgatt_srvc_id_t serviceId;
-  btgatt_gatt_id_t charId;
-  btgatt_gatt_id_t descriptorId;
-  int writeType;
-  int authReq;
-
-  if (NS_SUCCEEDED(Convert(aServiceId, serviceId)) &&
-      NS_SUCCEEDED(Convert(aCharId, charId)) &&
-      NS_SUCCEEDED(Convert(aDescriptorId, descriptorId)) &&
-      NS_SUCCEEDED(Convert(aWriteType, writeType)) &&
-      NS_SUCCEEDED(Convert(aAuthReq, authReq))) {
-    status = mInterface->write_descriptor(
-      aConnId, &serviceId, &charId, &descriptorId, writeType,
-      aValue.Length() * sizeof(uint8_t), authReq,
-      reinterpret_cast<char*>(const_cast<uint8_t*>(aValue.Elements())));
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::WriteDescriptor,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::ExecuteWrite(
-  int aConnId, int aIsExecute, BluetoothGattClientResultHandler* aRes)
-{
-#if ANDROID_VERSION >= 19
-  int status = mInterface->execute_write(aConnId, aIsExecute);
-#else
-  int status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::ExecuteWrite,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::RegisterNotification(
-  int aClientIf, const nsAString& aBdAddr,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId,
-  BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  bt_bdaddr_t bdAddr;
-  btgatt_srvc_id_t serviceId;
-  btgatt_gatt_id_t charId;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr)) &&
-      NS_SUCCEEDED(Convert(aServiceId, serviceId)) &&
-      NS_SUCCEEDED(Convert(aCharId, charId))) {
-    status = mInterface->register_for_notification(aClientIf, &bdAddr,
-                                                   &serviceId, &charId);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::RegisterNotification,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::DeregisterNotification(
-  int aClientIf, const nsAString& aBdAddr,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId,
-  BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  bt_bdaddr_t bdAddr;
-  btgatt_srvc_id_t serviceId;
-  btgatt_gatt_id_t charId;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr)) &&
-      NS_SUCCEEDED(Convert(aServiceId, serviceId)) &&
-      NS_SUCCEEDED(Convert(aCharId, charId))) {
-    status = mInterface->deregister_for_notification(aClientIf, &bdAddr,
-                                                     &serviceId, &charId);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::DeregisterNotification,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::ReadRemoteRssi(
-  int aClientIf, const nsAString& aBdAddr,
-  BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->read_remote_rssi(aClientIf, &bdAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::ReadRemoteRssi,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::GetDeviceType(
-  const nsAString& aBdAddr, BluetoothGattClientResultHandler* aRes)
-{
-  int status = BT_STATUS_FAIL;
-  bt_device_type_t type = BT_DEVICE_DEVTYPE_BLE;
-#if ANDROID_VERSION >= 19
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = BT_STATUS_SUCCESS;
-    type = static_cast<bt_device_type_t>(mInterface->get_device_type(&bdAddr));
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult<
-      BluetoothGattClientGetDeviceTypeHALResultRunnable>(
-      aRes, &BluetoothGattClientResultHandler::GetDeviceType, type,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::SetAdvData(
-  int aServerIf, bool aIsScanRsp, bool aIsNameIncluded,
-  bool aIsTxPowerIncluded, int aMinInterval, int aMaxInterval, int aApperance,
-  uint16_t aManufacturerLen, char* aManufacturerData,
-  uint16_t aServiceDataLen, char* aServiceData,
-  uint16_t aServiceUUIDLen, char* aServiceUUID,
-  BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 21
-  status = mInterface->set_adv_data(
-    aServerIf, aIsScanRsp, aIsNameIncluded, aIsTxPowerIncluded,
-    aMinInterval, aMaxInterval, aApperance,
-    aManufacturerLen, aManufacturerData,
-    aServiceDataLen, aServiceData, aServiceUUIDLen, aServiceUUID);
-#elif ANDROID_VERSION >= 19
-  status = mInterface->set_adv_data(
-    aServerIf, aIsScanRsp, aIsNameIncluded, aIsTxPowerIncluded, aMinInterval,
-    aMaxInterval, aApperance, aManufacturerLen, aManufacturerData);
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::SetAdvData,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattClientHALInterface::TestCommand(
-  int aCommand, const BluetoothGattTestParam& aTestParam,
-  BluetoothGattClientResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  btgatt_test_params_t testParam;
-
-  if (NS_SUCCEEDED(Convert(aTestParam, testParam))) {
-    status = mInterface->test_command(aCommand, &testParam);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattClientHALResult(
-      aRes, &BluetoothGattClientResultHandler::TestCommand,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-
-}
-
-// GATT Server Interface
-
-BluetoothGattServerHALInterface::BluetoothGattServerHALInterface(
-#if ANDROID_VERSION >= 19
-  const btgatt_server_interface_t* aInterface
-#endif
-  )
-#if ANDROID_VERSION >= 19
-  :mInterface(aInterface)
-#endif
-{
-#if ANDROID_VERSION >= 19
-  MOZ_ASSERT(mInterface);
-#endif
-}
-
-BluetoothGattServerHALInterface::~BluetoothGattServerHALInterface()
-{ }
-
-void
-BluetoothGattServerHALInterface::RegisterServer(
-  const BluetoothUuid& aUuid, BluetoothGattServerResultHandler* aRes)
-{
-  int status;
-#if ANDROID_VERSION >= 19
-  bt_uuid_t uuid;
-  if (NS_SUCCEEDED(Convert(aUuid, uuid))) {
-    status = mInterface->register_server(&uuid);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattServerHALResult(
-      aRes, &BluetoothGattServerResultHandler::RegisterServer,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattServerHALInterface::UnregisterServer(
-  int aServerIf, BluetoothGattServerResultHandler* aRes)
-{
-#if ANDROID_VERSION >= 19
-  int status = mInterface->unregister_server(aServerIf);
-#else
-  int status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattServerHALResult(
-      aRes, &BluetoothGattServerResultHandler::UnregisterServer,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattServerHALInterface::ConnectPeripheral(
-  int aServerIf, const nsAString& aBdAddr, bool aIsDirect, /* auto connect */
-  BluetoothTransport aTransport, BluetoothGattServerResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 21
-  bt_bdaddr_t bdAddr;
-  btgatt_transport_t transport;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr)) &&
-      NS_SUCCEEDED(Convert(aTransport, transport))) {
-    status = mInterface->connect(aServerIf, &bdAddr, aIsDirect, transport);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#elif ANDROID_VERSION >= 19
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->connect(aServerIf, &bdAddr, aIsDirect);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattServerHALResult(
-      aRes, &BluetoothGattServerResultHandler::ConnectPeripheral,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattServerHALInterface::DisconnectPeripheral(
-  int aServerIf, const nsAString& aBdAddr, int aConnId,
-  BluetoothGattServerResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->disconnect(aServerIf, &bdAddr, aConnId);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattServerHALResult(
-      aRes, &BluetoothGattServerResultHandler::DisconnectPeripheral,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattServerHALInterface::AddService(
-  int aServerIf, const BluetoothGattServiceId& aServiceId, int aNumHandles,
-  BluetoothGattServerResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  btgatt_srvc_id_t serviceId;
-
-  if (NS_SUCCEEDED(Convert(aServiceId, serviceId))) {
-    status = mInterface->add_service(aServerIf, &serviceId, aNumHandles);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattServerHALResult(
-      aRes, &BluetoothGattServerResultHandler::AddService,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattServerHALInterface::AddIncludedService(
-  int aServerIf, int aServiceHandle, int aIncludedServiceHandle,
-  BluetoothGattServerResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  status = mInterface->add_included_service(aServerIf, aServiceHandle,
-                                            aIncludedServiceHandle);
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattServerHALResult(
-      aRes, &BluetoothGattServerResultHandler::AddIncludedService,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattServerHALInterface::AddCharacteristic(
-  int aServerIf, int aServiceHandle, const BluetoothUuid& aUuid,
-  BluetoothGattCharProp aProperties, BluetoothGattAttrPerm aPermissions,
-  BluetoothGattServerResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  bt_uuid_t uuid;
-  int properties;
-  int permissions;
-
-  if (NS_SUCCEEDED(Convert(aUuid, uuid)) &&
-      NS_SUCCEEDED(Convert(aProperties, properties)) &&
-      NS_SUCCEEDED(Convert(aPermissions, permissions))) {
-    status = mInterface->add_characteristic(aServerIf, aServiceHandle, &uuid,
-                                            properties, permissions);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattServerHALResult(
-      aRes, &BluetoothGattServerResultHandler::AddCharacteristic,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattServerHALInterface::AddDescriptor(
-  int aServerIf, int aServiceHandle, const BluetoothUuid& aUuid,
-  BluetoothGattAttrPerm aPermissions, BluetoothGattServerResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  bt_uuid_t uuid;
-  int permissions;
-
-  if (NS_SUCCEEDED(Convert(aUuid, uuid)) &&
-      NS_SUCCEEDED(Convert(aPermissions, permissions))) {
-    status = mInterface->add_descriptor(aServerIf, aServiceHandle, &uuid,
-                                        permissions);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattServerHALResult(
-      aRes, &BluetoothGattServerResultHandler::AddDescriptor,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattServerHALInterface::StartService(
-  int aServerIf, int aServiceHandle, BluetoothTransport aTransport,
-  BluetoothGattServerResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  int transport;
-
-  if (NS_SUCCEEDED(Convert(aTransport, transport))) {
-    status = mInterface->start_service(aServerIf, aServiceHandle, transport);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattServerHALResult(
-      aRes, &BluetoothGattServerResultHandler::StartService,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattServerHALInterface::StopService(
-  int aServerIf, int aServiceHandle, BluetoothGattServerResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  status = mInterface->stop_service(aServerIf, aServiceHandle);
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattServerHALResult(
-      aRes, &BluetoothGattServerResultHandler::StopService,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattServerHALInterface::DeleteService(
-  int aServerIf, int aServiceHandle, BluetoothGattServerResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  status = mInterface->delete_service(aServerIf, aServiceHandle);
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattServerHALResult(
-      aRes, &BluetoothGattServerResultHandler::DeleteService,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattServerHALInterface::SendIndication(
-  int aServerIf, int aAttributeHandle, int aConnId,
-  const nsTArray<uint8_t>& aValue,
-  bool aConfirm, /* true: indication, false: notification */
-  BluetoothGattServerResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  char* value =
-    reinterpret_cast<char*>(const_cast<uint8_t*>(aValue.Elements()));
-  status = mInterface->send_indication(aServerIf, aAttributeHandle, aConnId,
-                                       aValue.Length(), aConfirm, value);
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattServerHALResult(
-      aRes, &BluetoothGattServerResultHandler::SendIndication,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattServerHALInterface::SendResponse(
-  int aConnId, int aTransId, BluetoothGattStatus aStatus,
-  const BluetoothGattResponse& aResponse,
-  BluetoothGattServerResultHandler* aRes)
-{
-  bt_status_t status;
-#if ANDROID_VERSION >= 19
-  int response_status;
-  btgatt_response_t response;
-  if (NS_SUCCEEDED(Convert(aStatus, response_status)) &&
-      NS_SUCCEEDED(Convert(aResponse, response))) {
-    status = mInterface->send_response(aConnId, aTransId, response_status,
-                                       &response);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattServerHALResult(
-      aRes, &BluetoothGattServerResultHandler::SendResponse,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-// GATT Interface
-
-BluetoothGattHALInterface::BluetoothGattHALInterface(
-#if ANDROID_VERSION >= 19
-  const btgatt_interface_t* aInterface
-#endif
-  )
-#if ANDROID_VERSION >= 19
-  :mInterface(aInterface)
-#endif
-{
-#if ANDROID_VERSION >= 19
-  MOZ_ASSERT(mInterface);
-#endif
-}
-
-BluetoothGattHALInterface::~BluetoothGattHALInterface()
-{ }
-
-void
-BluetoothGattHALInterface::Init(
-  BluetoothGattNotificationHandler* aNotificationHandler,
-  BluetoothGattResultHandler* aRes)
-{
-#if ANDROID_VERSION >= 19
-  static const btgatt_client_callbacks_t sGattClientCallbacks = {
-    BluetoothGattClientCallback::RegisterClient,
-    BluetoothGattClientCallback::ScanResult,
-    BluetoothGattClientCallback::Connect,
-    BluetoothGattClientCallback::Disconnect,
-    BluetoothGattClientCallback::SearchComplete,
-    BluetoothGattClientCallback::SearchResult,
-    BluetoothGattClientCallback::GetCharacteristic,
-    BluetoothGattClientCallback::GetDescriptor,
-    BluetoothGattClientCallback::GetIncludedService,
-    BluetoothGattClientCallback::RegisterNotification,
-    BluetoothGattClientCallback::Notify,
-    BluetoothGattClientCallback::ReadCharacteristic,
-    BluetoothGattClientCallback::WriteCharacteristic,
-    BluetoothGattClientCallback::ReadDescriptor,
-    BluetoothGattClientCallback::WriteDescriptor,
-    BluetoothGattClientCallback::ExecuteWrite,
-    BluetoothGattClientCallback::ReadRemoteRssi,
-    BluetoothGattClientCallback::Listen
-  };
-
-  static const btgatt_server_callbacks_t sGattServerCallbacks = {
-    BluetoothGattServerCallback::RegisterServer,
-    BluetoothGattServerCallback::Connection,
-    BluetoothGattServerCallback::ServiceAdded,
-    BluetoothGattServerCallback::IncludedServiceAdded,
-    BluetoothGattServerCallback::CharacteristicAdded,
-    BluetoothGattServerCallback::DescriptorAdded,
-    BluetoothGattServerCallback::ServiceStarted,
-    BluetoothGattServerCallback::ServiceStopped,
-    BluetoothGattServerCallback::ServiceDeleted,
-    BluetoothGattServerCallback::RequestRead,
-    BluetoothGattServerCallback::RequestWrite,
-    BluetoothGattServerCallback::RequestExecuteWrite,
-    BluetoothGattServerCallback::ResponseConfirmation,
-#if ANDROID_VERSION >= 21
-    BluetoothGattServerCallback::IndicationSent,
-    BluetoothGattServerCallback::Congestion,
-#endif // ANDROID_VERSION >= 21
-#if ANDROID_VERSION >= 22
-    BluetoothGattServerCallback::MtuChanged
-#endif // ANDROID_VERSION >= 22
-  };
-
-  static const btgatt_callbacks_t sCallbacks = {
-    sizeof(sCallbacks),
-    &sGattClientCallbacks,
-    &sGattServerCallbacks
-  };
-#endif // ANDROID_VERSION >= 19
-
-  sGattNotificationHandler = aNotificationHandler;
-
-#if ANDROID_VERSION >= 19
-  bt_status_t status = mInterface->init(&sCallbacks);
-#else
-  bt_status_t status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattHALResult(
-      aRes, &BluetoothGattResultHandler::Init,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothGattHALInterface::Cleanup(BluetoothGattResultHandler* aRes)
-{
-  bt_status_t status;
-
-#if ANDROID_VERSION >= 19
-  mInterface->cleanup();
-  status = BT_STATUS_SUCCESS;
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothGattHALResult(
-      aRes, &BluetoothGattResultHandler::Cleanup,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-BluetoothGattClientInterface*
-BluetoothGattHALInterface::GetBluetoothGattClientInterface()
-{
-  static BluetoothGattClientHALInterface* sBluetoothGattClientHALInterface;
-
-  if (sBluetoothGattClientHALInterface) {
-    return sBluetoothGattClientHALInterface;
-  }
-
-#if ANDROID_VERSION >= 19
-  MOZ_ASSERT(mInterface->client);
-  sBluetoothGattClientHALInterface =
-    new BluetoothGattClientHALInterface(mInterface->client);
-#else
-  sBluetoothGattClientHALInterface =
-    new BluetoothGattClientHALInterface();
-#endif
-
-  return sBluetoothGattClientHALInterface;
-}
-
-BluetoothGattServerInterface*
-BluetoothGattHALInterface::GetBluetoothGattServerInterface()
-{
-  static BluetoothGattServerHALInterface* sBluetoothGattServerHALInterface;
-
-  if (sBluetoothGattServerHALInterface) {
-    return sBluetoothGattServerHALInterface;
-  }
-
-#if ANDROID_VERSION >= 19
-  MOZ_ASSERT(mInterface->server);
-  sBluetoothGattServerHALInterface =
-    new BluetoothGattServerHALInterface(mInterface->server);
-#else
-  sBluetoothGattServerHALInterface =
-    new BluetoothGattServerHALInterface();
-#endif
-
-  return sBluetoothGattServerHALInterface;
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothGattHALInterface.h
+++ /dev/null
@@ -1,277 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_dom_bluetooth_bluedroid_bluetoothgatthalinterface_h__
-#define mozilla_dom_bluetooth_bluedroid_bluetoothgatthalinterface_h__
-
-#include <hardware/bluetooth.h>
-#if ANDROID_VERSION >= 19
-#include <hardware/bt_gatt.h>
-#endif
-#include "BluetoothCommon.h"
-#include "BluetoothInterface.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothHALInterface;
-
-class BluetoothGattClientHALInterface final
-  : public BluetoothGattClientInterface
-{
-public:
-  friend class BluetoothGattHALInterface;
-
-  /* Register / Unregister */
-  void RegisterClient(const BluetoothUuid& aUuid,
-                      BluetoothGattClientResultHandler* aRes);
-  void UnregisterClient(int aClientIf,
-                        BluetoothGattClientResultHandler* aRes);
-
-  /* Start / Stop LE Scan */
-  void Scan(int aClientIf, bool aStart,
-            BluetoothGattClientResultHandler* aRes);
-
-  /* Connect / Disconnect */
-  void Connect(int aClientIf,
-               const nsAString& aBdAddr,
-               bool aIsDirect, /* auto connect */
-               BluetoothTransport aTransport,
-               BluetoothGattClientResultHandler* aRes);
-  void Disconnect(int aClientIf,
-                  const nsAString& aBdAddr,
-                  int aConnId,
-                  BluetoothGattClientResultHandler* aRes);
-
-  /* Start / Stop advertisements to listen for incoming connections */
-  void Listen(int aClientIf,
-              bool aIsStart,
-              BluetoothGattClientResultHandler* aRes);
-
-  /* Clear the attribute cache for a given device*/
-  void Refresh(int aClientIf,
-               const nsAString& aBdAddr,
-               BluetoothGattClientResultHandler* aRes);
-
-  /* Enumerate Attributes */
-  void SearchService(int aConnId,
-                     bool aSearchAll,
-                     const BluetoothUuid& aUuid,
-                     BluetoothGattClientResultHandler* aRes);
-  void GetIncludedService(int aConnId,
-                          const BluetoothGattServiceId& aServiceId,
-                          bool aFirst,
-                          const BluetoothGattServiceId& aStartServiceId,
-                          BluetoothGattClientResultHandler* aRes);
-  void GetCharacteristic(int aConnId,
-                         const BluetoothGattServiceId& aServiceId,
-                         bool aFirst,
-                         const BluetoothGattId& aStartCharId,
-                         BluetoothGattClientResultHandler* aRes);
-  void GetDescriptor(int aConnId,
-                     const BluetoothGattServiceId& aServiceId,
-                     const BluetoothGattId& aCharId,
-                     bool aFirst,
-                     const BluetoothGattId& aDescriptorId,
-                     BluetoothGattClientResultHandler* aRes);
-
-  /* Read / Write An Attribute */
-  void ReadCharacteristic(int aConnId,
-                          const BluetoothGattServiceId& aServiceId,
-                          const BluetoothGattId& aCharId,
-                          BluetoothGattAuthReq aAuthReq,
-                          BluetoothGattClientResultHandler* aRes);
-  void WriteCharacteristic(int aConnId,
-                           const BluetoothGattServiceId& aServiceId,
-                           const BluetoothGattId& aCharId,
-                           BluetoothGattWriteType aWriteType,
-                           BluetoothGattAuthReq aAuthReq,
-                           const nsTArray<uint8_t>& aValue,
-                           BluetoothGattClientResultHandler* aRes);
-  void ReadDescriptor(int aConnId,
-                      const BluetoothGattServiceId& aServiceId,
-                      const BluetoothGattId& aCharId,
-                      const BluetoothGattId& aDescriptorId,
-                      BluetoothGattAuthReq aAuthReq,
-                      BluetoothGattClientResultHandler* aRes);
-  void WriteDescriptor(int aConnId,
-                       const BluetoothGattServiceId& aServiceId,
-                       const BluetoothGattId& aCharId,
-                       const BluetoothGattId& aDescriptorId,
-                       BluetoothGattWriteType aWriteType,
-                       BluetoothGattAuthReq aAuthReq,
-                       const nsTArray<uint8_t>& aValue,
-                       BluetoothGattClientResultHandler* aRes);
-
-  /* Execute / Abort Prepared Write*/
-  void ExecuteWrite(int aConnId,
-                    int aIsExecute,
-                    BluetoothGattClientResultHandler* aRes);
-
-
-  /* Register / Deregister Characteristic Notifications or Indications */
-  void RegisterNotification(int aClientIf,
-                            const nsAString& aBdAddr,
-                            const BluetoothGattServiceId& aServiceId,
-                            const BluetoothGattId& aCharId,
-                            BluetoothGattClientResultHandler* aRes);
-  void DeregisterNotification(int aClientIf,
-                              const nsAString& aBdAddr,
-                              const BluetoothGattServiceId& aServiceId,
-                              const BluetoothGattId& aCharId,
-                              BluetoothGattClientResultHandler* aRes);
-
-  void ReadRemoteRssi(int aClientIf,
-                      const nsAString& aBdAddr,
-                      BluetoothGattClientResultHandler* aRes);
-
-  void GetDeviceType(const nsAString& aBdAddr,
-                     BluetoothGattClientResultHandler* aRes);
-
-  /* Set advertising data or scan response data */
-  void SetAdvData(int aServerIf,
-                  bool aIsScanRsp,
-                  bool aIsNameIncluded,
-                  bool aIsTxPowerIncluded,
-                  int aMinInterval,
-                  int aMaxInterval,
-                  int aApperance,
-                  uint16_t aManufacturerLen, char* aManufacturerData,
-                  uint16_t aServiceDataLen, char* aServiceData,
-                  uint16_t aServiceUUIDLen, char* aServiceUUID,
-                  BluetoothGattClientResultHandler* aRes);
-
-  void TestCommand(int aCommand, const BluetoothGattTestParam& aTestParam,
-                   BluetoothGattClientResultHandler* aRes);
-
-protected:
-  BluetoothGattClientHALInterface(
-#if ANDROID_VERSION >= 19
-    const btgatt_client_interface_t* aInterface
-#endif
-    );
-  ~BluetoothGattClientHALInterface();
-
-private:
-#if ANDROID_VERSION >= 19
-  const btgatt_client_interface_t* mInterface;
-#endif
-};
-
-class BluetoothGattServerHALInterface final
-  : public BluetoothGattServerInterface
-{
-public:
-  friend class BluetoothGattHALInterface;
-
-  /* Register / Unregister */
-  void RegisterServer(const BluetoothUuid& aUuid,
-                      BluetoothGattServerResultHandler* aRes);
-  void UnregisterServer(int aServerIf,
-                        BluetoothGattServerResultHandler* aRes);
-
-  /* Connect / Disconnect */
-  void ConnectPeripheral(int aServerIf,
-                         const nsAString& aBdAddr,
-                         bool aIsDirect, /* auto connect */
-                         BluetoothTransport aTransport,
-                         BluetoothGattServerResultHandler* aRes);
-  void DisconnectPeripheral(int aServerIf,
-                            const nsAString& aBdAddr,
-                            int aConnId,
-                            BluetoothGattServerResultHandler* aRes);
-
-  /* Add a services / a characteristic / a descriptor */
-  void AddService(int aServerIf,
-                  const BluetoothGattServiceId& aServiceId,
-                  int aNumHandles,
-                  BluetoothGattServerResultHandler* aRes);
-  void AddIncludedService(int aServerIf,
-                          int aServiceHandle,
-                          int aIncludedServiceHandle,
-                          BluetoothGattServerResultHandler* aRes);
-  void AddCharacteristic(int aServerIf,
-                         int aServiceHandle,
-                         const BluetoothUuid& aUuid,
-                         BluetoothGattCharProp aProperties,
-                         BluetoothGattAttrPerm aPermissions,
-                         BluetoothGattServerResultHandler* aRes);
-  void AddDescriptor(int aServerIf,
-                     int aServiceHandle,
-                     const BluetoothUuid& aUuid,
-                     BluetoothGattAttrPerm aPermissions,
-                     BluetoothGattServerResultHandler* aRes);
-
-  /* Start / Stop / Delete a service */
-  void StartService(int aServerIf,
-                    int aServiceHandle,
-                    BluetoothTransport aTransport,
-                    BluetoothGattServerResultHandler* aRes);
-  void StopService(int aServerIf,
-                   int aServiceHandle,
-                   BluetoothGattServerResultHandler* aRes);
-  void DeleteService(int aServerIf,
-                     int aServiceHandle,
-                     BluetoothGattServerResultHandler* aRes);
-
-  /* Send an indication or a notification */
-  void SendIndication(int aServerIf,
-                      int aAttributeHandle,
-                      int aConnId,
-                      const nsTArray<uint8_t>& aValue,
-                      bool aConfirm, /* true: indication, false: notification */
-                      BluetoothGattServerResultHandler* aRes);
-
-  /* Send a response for an incoming indication */
-  void SendResponse(int aConnId,
-                    int aTransId,
-                    BluetoothGattStatus aStatus,
-                    const BluetoothGattResponse& aResponse,
-                    BluetoothGattServerResultHandler* aRes);
-
-protected:
-  BluetoothGattServerHALInterface(
-#if ANDROID_VERSION >= 19
-    const btgatt_server_interface_t* aInterface
-#endif
-    );
-  ~BluetoothGattServerHALInterface();
-
-private:
-#if ANDROID_VERSION >= 19
-  const btgatt_server_interface_t* mInterface;
-#endif
-};
-
-class BluetoothGattHALInterface final
- : public BluetoothGattInterface
-{
-public:
-  friend class BluetoothHALInterface;
-
-  void Init(BluetoothGattNotificationHandler* aNotificationHandler,
-            BluetoothGattResultHandler* aRes);
-  void Cleanup(BluetoothGattResultHandler* aRes);
-
-  BluetoothGattClientInterface* GetBluetoothGattClientInterface();
-  BluetoothGattServerInterface* GetBluetoothGattServerInterface();
-
-protected:
-  BluetoothGattHALInterface(
-#if ANDROID_VERSION >= 19
-    const btgatt_interface_t* aInterface
-#endif
-    );
-  ~BluetoothGattHALInterface();
-
-private:
-#if ANDROID_VERSION >= 19
-  const btgatt_interface_t* mInterface;
-#endif
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothHALHelpers.cpp
+++ /dev/null
@@ -1,558 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "BluetoothHALHelpers.h"
-
-#define MAX_UUID_SIZE 16
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-//
-// Conversion
-//
-
-nsresult
-Convert(const nsAString& aIn, bt_property_type_t& aOut)
-{
-  if (aIn.EqualsLiteral("Name")) {
-    aOut = BT_PROPERTY_BDNAME;
-  } else if (aIn.EqualsLiteral("Discoverable")) {
-    aOut = BT_PROPERTY_ADAPTER_SCAN_MODE;
-  } else if (aIn.EqualsLiteral("DiscoverableTimeout")) {
-    aOut = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT;
-  } else {
-    BT_LOGR("Invalid property name: %s", NS_ConvertUTF16toUTF8(aIn).get());
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  return NS_OK;
-}
-
-nsresult
-Convert(ConvertNamedValue& aIn, bt_property_t& aOut)
-{
-  nsresult rv = Convert(aIn.mNamedValue.name(), aOut.type);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  if (aIn.mNamedValue.value().type() == BluetoothValue::Tuint32_t) {
-    // Set discoverable timeout
-    aOut.val = const_cast<void*>(static_cast<const void*>(
-      &(aIn.mNamedValue.value().get_uint32_t())));
-      aOut.len = sizeof(uint32_t);
-  } else if (aIn.mNamedValue.value().type() == BluetoothValue::TnsString) {
-    // Set name
-    aIn.mStringValue =
-      NS_ConvertUTF16toUTF8(aIn.mNamedValue.value().get_nsString());
-    aOut.val =
-      const_cast<void*>(static_cast<const void*>(aIn.mStringValue.get()));
-    aOut.len = strlen(static_cast<char*>(aOut.val));
-  } else if (aIn.mNamedValue.value().type() == BluetoothValue::Tbool) {
-    // Set scan mode
-    rv = Convert(aIn.mNamedValue.value().get_bool(), aIn.mScanMode);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    aOut.val = &aIn.mScanMode;
-    aOut.len = sizeof(aIn.mScanMode);
-  } else {
-    BT_LOGR("Invalid property value type");
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-
-  return NS_OK;
-}
-
-nsresult
-Convert(const nsAString& aIn, bt_bdaddr_t& aOut)
-{
-  NS_ConvertUTF16toUTF8 bdAddressUTF8(aIn);
-  const char* str = bdAddressUTF8.get();
-
-  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;
-}
-
-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),
-    CONVERT(SSP_VARIANT_PASSKEY_NOTIFICATION,
-      BT_SSP_VARIANT_PASSKEY_NOTIFICATION)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sSspVariant)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sSspVariant[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(const uint8_t aIn[16], bt_uuid_t& aOut)
-{
-  if (sizeof(aOut.uu) != 16) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-
-  memcpy(aOut.uu, aIn, sizeof(aOut.uu));
-
-  return NS_OK;
-}
-
-nsresult
-Convert(const bt_uuid_t& aIn, BluetoothUuid& aOut)
-{
-  if (sizeof(aIn.uu) != sizeof(aOut.mUuid)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-
-  memcpy(aOut.mUuid, aIn.uu, sizeof(aOut.mUuid));
-
-  return NS_OK;
-}
-
-nsresult
-Convert(const BluetoothUuid& aIn, bt_uuid_t& aOut)
-{
-  if (sizeof(aIn.mUuid) != sizeof(aOut.uu)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-
-  memcpy(aOut.uu, aIn.mUuid, sizeof(aOut.uu));
-
-  return NS_OK;
-}
-
-nsresult
-Convert(const nsAString& aIn, bt_pin_code_t& aOut)
-{
-  if (aIn.Length() > MOZ_ARRAY_LENGTH(aOut.pin)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-
-  NS_ConvertUTF16toUTF8 pinCodeUTF8(aIn);
-  const char* str = pinCodeUTF8.get();
-
-  nsAString::size_type i;
-
-  // Fill pin into aOut
-  for (i = 0; i < aIn.Length(); ++i, ++str) {
-    aOut.pin[i] = static_cast<uint8_t>(*str);
-  }
-
-  // Clear remaining bytes in aOut
-  size_t ntrailing =
-    (MOZ_ARRAY_LENGTH(aOut.pin) - aIn.Length()) * sizeof(aOut.pin[0]);
-  memset(aOut.pin + aIn.Length(), 0, ntrailing);
-
-  return NS_OK;
-}
-
-nsresult
-Convert(const bt_bdaddr_t& aIn, nsAString& aOut)
-{
-  char str[BLUETOOTH_ADDRESS_LENGTH + 1];
-
-  int res = snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x",
-                     static_cast<int>(aIn.address[0]),
-                     static_cast<int>(aIn.address[1]),
-                     static_cast<int>(aIn.address[2]),
-                     static_cast<int>(aIn.address[3]),
-                     static_cast<int>(aIn.address[4]),
-                     static_cast<int>(aIn.address[5]));
-  if (res < 0) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  } else if ((size_t)res >= sizeof(str)) {
-    return NS_ERROR_OUT_OF_MEMORY; /* string buffer too small */
-  }
-
-  aOut = NS_ConvertUTF8toUTF16(str);
-
-  return NS_OK;
-}
-
-nsresult
-Convert(const bt_service_record_t& aIn, BluetoothServiceRecord& aOut)
-{
-  nsresult rv = Convert(aIn.uuid, aOut.mUuid);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  aOut.mChannel = aIn.channel;
-
-  MOZ_ASSERT(sizeof(aIn.name) == sizeof(aOut.mName));
-  memcpy(aOut.mName, aIn.name, sizeof(aOut.mName));
-
-  return NS_OK;
-}
-
-nsresult
-Convert(const uint8_t* aIn, BluetoothGattAdvData& aOut)
-{
-  memcpy(aOut.mAdvData, aIn, sizeof(aOut.mAdvData));
-  return NS_OK;
-}
-
-#if ANDROID_VERSION >= 18
-nsresult
-Convert(const BluetoothAvrcpElementAttribute& aIn, btrc_element_attr_val_t& aOut)
-{
-  const NS_ConvertUTF16toUTF8 value(aIn.mValue);
-  size_t len = std::min<size_t>(strlen(value.get()), sizeof(aOut.text) - 1);
-
-  memcpy(aOut.text, value.get(), len);
-  aOut.text[len] = '\0';
-  aOut.attr_id = aIn.mId;
-
-  return NS_OK;
-}
-
-nsresult
-Convert(const btrc_player_settings_t& aIn, BluetoothAvrcpPlayerSettings& aOut)
-{
-  aOut.mNumAttr = aIn.num_attr;
-  memcpy(aOut.mIds, aIn.attr_ids, aIn.num_attr);
-  memcpy(aOut.mValues, aIn.attr_values, aIn.num_attr);
-
-  return NS_OK;
-}
-#endif // ANDROID_VERSION >= 18
-
-#if ANDROID_VERSION >= 19
-nsresult
-Convert(const BluetoothGattId& aIn, btgatt_gatt_id_t& aOut)
-{
-  nsresult rv = Convert(aIn.mUuid, aOut.uuid);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  // HAL uses reversed UUID for GATT
-  for (uint8_t i = 0; i < sizeof(aOut.uuid.uu) / 2; i++) {
-    auto temp = aOut.uuid.uu[i];
-    aOut.uuid.uu[i] = aOut.uuid.uu[sizeof(aOut.uuid.uu) - i - 1];
-    aOut.uuid.uu[sizeof(aOut.uuid.uu) - i - 1] = temp;
-  }
-  aOut.inst_id = aIn.mInstanceId;
-  return NS_OK;
-}
-
-nsresult
-Convert(const btgatt_gatt_id_t& aIn, BluetoothGattId& aOut)
-{
-  nsresult rv = Convert(aIn.uuid, aOut.mUuid);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  // HAL uses reversed UUID for GATT
-  for (uint8_t i = 0; i < sizeof(aOut.mUuid.mUuid) / 2; i++) {
-    auto temp = aOut.mUuid.mUuid[i];
-    aOut.mUuid.mUuid[i] = aOut.mUuid.mUuid[sizeof(aOut.mUuid.mUuid) - i - 1];
-    aOut.mUuid.mUuid[sizeof(aOut.mUuid.mUuid) - i - 1] = temp;
-  }
-  aOut.mInstanceId = aIn.inst_id;
-  return NS_OK;
-}
-
-nsresult
-Convert(const BluetoothGattServiceId& aIn, btgatt_srvc_id_t& aOut)
-{
-  aOut.is_primary = aIn.mIsPrimary;
-  return Convert(aIn.mId, aOut.id);
-}
-
-nsresult
-Convert(const btgatt_srvc_id_t& aIn, BluetoothGattServiceId& aOut)
-{
-  aOut.mIsPrimary = aIn.is_primary;
-  return Convert(aIn.id, aOut.mId);
-}
-
-nsresult
-Convert(const btgatt_read_params_t& aIn, BluetoothGattReadParam& aOut)
-{
-  nsresult rv = Convert(aIn.srvc_id, aOut.mServiceId);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = Convert(aIn.char_id, aOut.mCharId);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = Convert(aIn.descr_id, aOut.mDescriptorId);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  memcpy(aOut.mValue, aIn.value.value, aIn.value.len);
-  aOut.mValueLength = aIn.value.len;
-  aOut.mValueType = aIn.value_type;
-  aOut.mStatus = aIn.status;
-
-  return NS_OK;
-}
-
-nsresult
-Convert(const btgatt_write_params_t& aIn, BluetoothGattWriteParam& aOut)
-{
-  nsresult rv = Convert(aIn.srvc_id, aOut.mServiceId);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = Convert(aIn.char_id, aOut.mCharId);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = Convert(aIn.descr_id, aOut.mDescriptorId);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  aOut.mStatus = aIn.status;
-
-  return NS_OK;
-}
-
-nsresult
-Convert(const btgatt_notify_params_t& aIn, BluetoothGattNotifyParam& aOut)
-{
-  nsresult rv = Convert(aIn.bda, aOut.mBdAddr);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = Convert(aIn.srvc_id, aOut.mServiceId);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = Convert(aIn.char_id, aOut.mCharId);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  memcpy(aOut.mValue, aIn.value, aIn.len);
-  aOut.mLength = aIn.len;
-  aOut.mIsNotify = (aIn.is_notify != 0);
-
-  return NS_OK;
-}
-
-nsresult
-Convert(const BluetoothGattTestParam& aIn, btgatt_test_params_t& aOut)
-{
-  nsresult rv = Convert(aIn.mBdAddr, *aOut.bda1);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  rv = Convert(aIn.mUuid, *aOut.uuid1);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  rv = Convert(aIn.mU1, aOut.u1);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  rv = Convert(aIn.mU2, aOut.u2);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  rv = Convert(aIn.mU3, aOut.u3);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  rv = Convert(aIn.mU4, aOut.u4);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  rv = Convert(aIn.mU5, aOut.u5);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult
-Convert(const BluetoothGattResponse& aIn, btgatt_response_t& aOut)
-{
-  // Only the read response format is used in bluedroid.
-  nsresult rv = Convert(
-    ConvertArray<uint8_t>(aIn.mValue, sizeof(aIn.mValue)),
-    aOut.attr_value.value);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  rv = Convert(aIn.mHandle, aOut.attr_value.handle);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  rv = Convert(aIn.mOffset, aOut.attr_value.offset);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  rv = Convert(aIn.mLength, aOut.attr_value.len);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  rv = Convert(aIn.mAuthReq, aOut.attr_value.auth_req);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-#endif // ANDROID_VERSION >= 19
-
-#if ANDROID_VERSION >= 21
-nsresult
-Convert(const BluetoothTransport& aIn, btgatt_transport_t& aOut)
-{
-  static const btgatt_transport_t sTransport[] = {
-    CONVERT(TRANSPORT_AUTO, GATT_TRANSPORT_AUTO),
-    CONVERT(TRANSPORT_BREDR, GATT_TRANSPORT_BREDR),
-    CONVERT(TRANSPORT_LE, GATT_TRANSPORT_LE)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sTransport)) {
-    aOut = static_cast<btgatt_transport_t>(0); // silence compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sTransport[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(const bt_activity_energy_info& aIn, BluetoothActivityEnergyInfo& aOut)
-{
-  nsresult rv = Convert(aIn.status, aOut.mStatus);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Convert(aIn.ctrl_state, aOut.mStackState);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Convert(aIn.tx_time, aOut.mTxTime);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Convert(aIn.rx_time, aOut.mRxTime);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Convert(aIn.idle_time, aOut.mIdleTime);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Convert(aIn.energy_used, aOut.mEnergyUsed);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-#endif // ANDROID_VERSION >= 21
-
-nsresult
-Convert(const bt_property_t& aIn, BluetoothProperty& aOut)
-{
-  /* type conversion */
-
-  nsresult rv = Convert(aIn.type, aOut.mType);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  /* value conversion */
-
-  switch (aOut.mType) {
-    case PROPERTY_UNKNOWN:
-      /* Bug 1065999: working around unknown properties */
-      break;
-    case PROPERTY_BDNAME:
-      /* fall through */
-    case PROPERTY_REMOTE_FRIENDLY_NAME:
-      {
-        // We construct an nsCString here because bdname
-        // returned from Bluedroid is not 0-terminated.
-        aOut.mString = NS_ConvertUTF8toUTF16(
-          nsCString(static_cast<char*>(aIn.val), aIn.len));
-      }
-      break;
-    case PROPERTY_BDADDR:
-      rv = Convert(*static_cast<bt_bdaddr_t*>(aIn.val), aOut.mString);
-      break;
-    case PROPERTY_UUIDS:
-      {
-        size_t numUuids = aIn.len / MAX_UUID_SIZE;
-        ConvertArray<bt_uuid_t> array(
-          static_cast<bt_uuid_t*>(aIn.val), numUuids);
-        aOut.mUuidArray.SetLength(numUuids);
-        rv = Convert(array, aOut.mUuidArray);
-      }
-      break;
-    case PROPERTY_CLASS_OF_DEVICE:
-      /* fall through */
-    case PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
-      aOut.mUint32 = *static_cast<uint32_t*>(aIn.val);
-      break;
-    case PROPERTY_TYPE_OF_DEVICE:
-      rv = Convert(*static_cast<bt_device_type_t*>(aIn.val),
-                   aOut.mTypeOfDevice);
-      break;
-    case PROPERTY_SERVICE_RECORD:
-      rv = Convert(*static_cast<bt_service_record_t*>(aIn.val),
-                   aOut.mServiceRecord);
-      break;
-    case PROPERTY_ADAPTER_SCAN_MODE:
-      rv = Convert(*static_cast<bt_scan_mode_t*>(aIn.val),
-                   aOut.mScanMode);
-      break;
-    case PROPERTY_ADAPTER_BONDED_DEVICES:
-      {
-        size_t numAddresses = aIn.len / BLUETOOTH_ADDRESS_BYTES;
-        ConvertArray<bt_bdaddr_t> array(
-          static_cast<bt_bdaddr_t*>(aIn.val), numAddresses);
-        aOut.mStringArray.SetLength(numAddresses);
-        rv = Convert(array, aOut.mStringArray);
-      }
-      break;
-    case PROPERTY_REMOTE_RSSI:
-      aOut.mInt32 = *static_cast<int8_t*>(aIn.val);
-      break;
-#if ANDROID_VERSION >= 18
-    case PROPERTY_REMOTE_VERSION_INFO:
-      rv = Convert(*static_cast<bt_remote_version_t*>(aIn.val),
-                   aOut.mRemoteInfo);
-      break;
-#endif
-    case PROPERTY_REMOTE_DEVICE_TIMESTAMP:
-      /* nothing to do */
-      break;
-    default:
-      /* mismatch with type conversion */
-      NS_NOTREACHED("Unhandled property type");
-      break;
-  }
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  return NS_OK;
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothHALHelpers.h
+++ /dev/null
@@ -1,2086 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_dom_bluetooth_bluedroid_bluetoothhalhelpers_h__
-#define mozilla_dom_bluetooth_bluedroid_bluetoothhalhelpers_h__
-
-#include <hardware/bluetooth.h>
-#include <hardware/bt_sock.h>
-#include <hardware/bt_hf.h>
-#include <hardware/bt_av.h>
-#if ANDROID_VERSION >= 18
-#include <hardware/bt_rc.h>
-#endif
-#if ANDROID_VERSION >= 19
-#include <hardware/bt_gatt.h>
-#endif
-#include "BluetoothCommon.h"
-#include "mozilla/ArrayUtils.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/dom/TypedArray.h"
-#include "nsThreadUtils.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-//
-// Conversion
-//
-
-inline nsresult
-Convert(bt_status_t aIn, BluetoothStatus& aOut)
-{
-  static const BluetoothStatus sStatus[] = {
-    CONVERT(BT_STATUS_SUCCESS, STATUS_SUCCESS),
-    CONVERT(BT_STATUS_FAIL, STATUS_FAIL),
-    CONVERT(BT_STATUS_NOT_READY, STATUS_NOT_READY),
-    CONVERT(BT_STATUS_NOMEM, STATUS_NOMEM),
-    CONVERT(BT_STATUS_BUSY, STATUS_BUSY),
-    CONVERT(BT_STATUS_DONE, STATUS_DONE),
-    CONVERT(BT_STATUS_UNSUPPORTED, STATUS_UNSUPPORTED),
-    CONVERT(BT_STATUS_PARM_INVALID, STATUS_PARM_INVALID),
-    CONVERT(BT_STATUS_UNHANDLED, STATUS_UNHANDLED),
-    CONVERT(BT_STATUS_AUTH_FAILURE, STATUS_AUTH_FAILURE),
-    CONVERT(BT_STATUS_RMT_DEV_DOWN, STATUS_RMT_DEV_DOWN)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sStatus)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sStatus[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(int aIn, BluetoothStatus& aOut)
-{
-  return Convert(static_cast<bt_status_t>(aIn), aOut);
-}
-
-nsresult
-Convert(const nsAString& aIn, bt_property_type_t& aOut);
-
-inline nsresult
-Convert(bool aIn, bt_scan_mode_t& aOut)
-{
-  static const bt_scan_mode_t sScanMode[] = {
-    CONVERT(false, BT_SCAN_MODE_CONNECTABLE),
-    CONVERT(true, BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sScanMode)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sScanMode[aIn];
-  return NS_OK;
-}
-
-
-inline nsresult
-Convert(bt_scan_mode_t aIn, BluetoothScanMode& aOut)
-{
-  static const BluetoothScanMode sScanMode[] = {
-    CONVERT(BT_SCAN_MODE_NONE, SCAN_MODE_NONE),
-    CONVERT(BT_SCAN_MODE_CONNECTABLE, SCAN_MODE_CONNECTABLE),
-    CONVERT(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE,
-      SCAN_MODE_CONNECTABLE_DISCOVERABLE)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sScanMode)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sScanMode[aIn];
-  return NS_OK;
-}
-
-struct ConvertNamedValue
-{
-  ConvertNamedValue(const BluetoothNamedValue& aNamedValue)
-  : mNamedValue(aNamedValue)
-  { }
-
-  const BluetoothNamedValue& mNamedValue;
-
-  // temporary fields
-  nsCString mStringValue;
-  bt_scan_mode_t mScanMode;
-};
-
-nsresult
-Convert(ConvertNamedValue& aIn, bt_property_t& aOut);
-
-nsresult
-Convert(const nsAString& aIn, bt_bdaddr_t& aOut);
-
-nsresult
-Convert(BluetoothSspVariant aIn, bt_ssp_variant_t& aOut);
-
-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),
-    CONVERT(BT_SSP_VARIANT_CONSENT, SSP_VARIANT_CONSENT),
-    CONVERT(BT_SSP_VARIANT_PASSKEY_NOTIFICATION,
-      SSP_VARIANT_PASSKEY_NOTIFICATION)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sSspVariant)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sSspVariant[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(const bool& aIn, uint8_t& aOut)
-{
-  // casting converts true/false to either 1 or 0
-  aOut = static_cast<uint8_t>(aIn);
-  return NS_OK;
-}
-
-nsresult
-Convert(const uint8_t aIn[16], bt_uuid_t& aOut);
-
-nsresult
-Convert(const bt_uuid_t& aIn, BluetoothUuid& aOut);
-
-nsresult
-Convert(const BluetoothUuid& aIn, bt_uuid_t& aOut);
-
-nsresult
-Convert(const nsAString& aIn, bt_pin_code_t& aOut);
-
-nsresult
-Convert(const bt_bdaddr_t& aIn, nsAString& aOut);
-
-inline nsresult
-Convert(const bt_bdaddr_t* aIn, nsAString& aOut)
-{
-  if (!aIn) {
-    aOut.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
-    return NS_OK;
-  }
-  return Convert(*aIn, aOut);
-}
-
-inline nsresult
-Convert(bt_state_t aIn, bool& aOut)
-{
-  static const bool sState[] = {
-    CONVERT(BT_STATE_OFF, false),
-    CONVERT(BT_STATE_ON, true)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sState[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(bt_property_type_t aIn, BluetoothPropertyType& aOut)
-{
-  static const BluetoothPropertyType sPropertyType[] = {
-    CONVERT(0, static_cast<BluetoothPropertyType>(0)), // invalid, required by gcc
-    CONVERT(BT_PROPERTY_BDNAME, PROPERTY_BDNAME),
-    CONVERT(BT_PROPERTY_BDADDR, PROPERTY_BDADDR),
-    CONVERT(BT_PROPERTY_UUIDS, PROPERTY_UUIDS),
-    CONVERT(BT_PROPERTY_CLASS_OF_DEVICE, PROPERTY_CLASS_OF_DEVICE),
-    CONVERT(BT_PROPERTY_TYPE_OF_DEVICE, PROPERTY_TYPE_OF_DEVICE),
-    CONVERT(BT_PROPERTY_SERVICE_RECORD, PROPERTY_SERVICE_RECORD),
-    CONVERT(BT_PROPERTY_ADAPTER_SCAN_MODE, PROPERTY_ADAPTER_SCAN_MODE),
-    CONVERT(BT_PROPERTY_ADAPTER_BONDED_DEVICES,
-      PROPERTY_ADAPTER_BONDED_DEVICES),
-    CONVERT(BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
-      PROPERTY_ADAPTER_DISCOVERY_TIMEOUT),
-    CONVERT(BT_PROPERTY_REMOTE_FRIENDLY_NAME, PROPERTY_REMOTE_FRIENDLY_NAME),
-    CONVERT(BT_PROPERTY_REMOTE_RSSI, PROPERTY_REMOTE_RSSI)
-#if ANDROID_VERSION >= 18
-    ,
-    CONVERT(BT_PROPERTY_REMOTE_VERSION_INFO,PROPERTY_REMOTE_VERSION_INFO)
-#endif
-  };
-  if (aIn == BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP) {
-    /* This case is handled separately to not populate
-     * |sPropertyType| with empty entries. */
-    aOut = PROPERTY_REMOTE_DEVICE_TIMESTAMP;
-    return NS_OK;
-  }
-  if (!aIn || aIn >= MOZ_ARRAY_LENGTH(sPropertyType)) {
-    /* Bug 1065999: working around unknown properties */
-    aOut = PROPERTY_UNKNOWN;
-    return NS_OK;
-  }
-  aOut = sPropertyType[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(bt_discovery_state_t aIn, bool& aOut)
-{
-  static const bool sDiscoveryState[] = {
-    CONVERT(BT_DISCOVERY_STOPPED, false),
-    CONVERT(BT_DISCOVERY_STARTED, true)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sDiscoveryState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sDiscoveryState[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(const char* aIn, nsACString& aOut)
-{
-  aOut.Assign(aIn);
-
-  return NS_OK;
-}
-
-inline nsresult
-Convert(const char* aIn, nsAString& aOut)
-{
-  aOut = NS_ConvertUTF8toUTF16(aIn);
-
-  return NS_OK;
-}
-
-inline nsresult
-Convert(const bt_bdname_t& aIn, nsAString& aOut)
-{
-  return Convert(reinterpret_cast<const char*>(aIn.name), aOut);
-}
-
-inline nsresult
-Convert(const bt_bdname_t* aIn, nsAString& aOut)
-{
-  if (!aIn) {
-    aOut.Truncate();
-    return NS_OK;
-  }
-  return Convert(*aIn, aOut);
-}
-
-inline nsresult
-Convert(bt_bond_state_t aIn, BluetoothBondState& aOut)
-{
-  static const BluetoothBondState sBondState[] = {
-    CONVERT(BT_BOND_STATE_NONE, BOND_STATE_NONE),
-    CONVERT(BT_BOND_STATE_BONDING, BOND_STATE_BONDING),
-    CONVERT(BT_BOND_STATE_BONDED, BOND_STATE_BONDED)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sBondState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sBondState[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(bt_acl_state_t aIn, bool& aOut)
-{
-  static const bool sAclState[] = {
-    CONVERT(BT_ACL_STATE_CONNECTED, true),
-    CONVERT(BT_ACL_STATE_DISCONNECTED, false)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sAclState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sAclState[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(bt_device_type_t aIn, BluetoothTypeOfDevice& aOut)
-{
-  static const BluetoothTypeOfDevice sTypeOfDevice[] = {
-    CONVERT(0, static_cast<BluetoothTypeOfDevice>(0)), // invalid, required by gcc
-    CONVERT(BT_DEVICE_DEVTYPE_BREDR, TYPE_OF_DEVICE_BREDR),
-    CONVERT(BT_DEVICE_DEVTYPE_BLE, TYPE_OF_DEVICE_BLE),
-    CONVERT(BT_DEVICE_DEVTYPE_DUAL, TYPE_OF_DEVICE_DUAL)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sTypeOfDevice)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sTypeOfDevice[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(const bt_service_record_t& aIn, BluetoothServiceRecord& aOut);
-
-inline nsresult
-Convert(BluetoothSocketType aIn, btsock_type_t& aOut)
-{
-  // FIXME: Array member [0] is currently invalid, but required
-  //        by gcc. Start values in |BluetoothSocketType| at index
-  //        0 to fix this problem.
-  static const btsock_type_t sSocketType[] = {
-    CONVERT(0, static_cast<btsock_type_t>(0)), // invalid, [0] required by gcc
-    CONVERT(BluetoothSocketType::RFCOMM, BTSOCK_RFCOMM),
-    CONVERT(BluetoothSocketType::SCO, BTSOCK_SCO),
-    CONVERT(BluetoothSocketType::L2CAP, BTSOCK_L2CAP),
-    // EL2CAP is not supported by Bluedroid
-  };
-  if (aIn == BluetoothSocketType::EL2CAP ||
-      aIn >= MOZ_ARRAY_LENGTH(sSocketType) || !sSocketType[aIn]) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sSocketType[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(BluetoothHandsfreeAtResponse aIn, bthf_at_response_t& aOut)
-{
-  static const bthf_at_response_t sAtResponse[] = {
-    CONVERT(HFP_AT_RESPONSE_ERROR, BTHF_AT_RESPONSE_ERROR),
-    CONVERT(HFP_AT_RESPONSE_OK, BTHF_AT_RESPONSE_OK)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sAtResponse)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sAtResponse[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(BluetoothHandsfreeCallAddressType aIn, bthf_call_addrtype_t& aOut)
-{
-  static const bthf_call_addrtype_t sCallAddressType[] = {
-    CONVERT(HFP_CALL_ADDRESS_TYPE_UNKNOWN, BTHF_CALL_ADDRTYPE_UNKNOWN),
-    CONVERT(HFP_CALL_ADDRESS_TYPE_INTERNATIONAL,
-      BTHF_CALL_ADDRTYPE_INTERNATIONAL)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sCallAddressType)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sCallAddressType[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(BluetoothHandsfreeCallDirection aIn, bthf_call_direction_t& aOut)
-{
-  static const bthf_call_direction_t sCallDirection[] = {
-    CONVERT(HFP_CALL_DIRECTION_OUTGOING, BTHF_CALL_DIRECTION_OUTGOING),
-    CONVERT(HFP_CALL_DIRECTION_INCOMING, BTHF_CALL_DIRECTION_INCOMING)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sCallDirection)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sCallDirection[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(BluetoothHandsfreeCallMode aIn, bthf_call_mode_t& aOut)
-{
-  static const bthf_call_mode_t sCallMode[] = {
-    CONVERT(HFP_CALL_MODE_VOICE, BTHF_CALL_TYPE_VOICE),
-    CONVERT(HFP_CALL_MODE_DATA, BTHF_CALL_TYPE_DATA),
-    CONVERT(HFP_CALL_MODE_FAX, BTHF_CALL_TYPE_FAX)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sCallMode)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sCallMode[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(BluetoothHandsfreeCallMptyType aIn, bthf_call_mpty_type_t& aOut)
-{
-  static const bthf_call_mpty_type_t sCallMptyType[] = {
-    CONVERT(HFP_CALL_MPTY_TYPE_SINGLE, BTHF_CALL_MPTY_TYPE_SINGLE),
-    CONVERT(HFP_CALL_MPTY_TYPE_MULTI, BTHF_CALL_MPTY_TYPE_MULTI)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sCallMptyType)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sCallMptyType[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(BluetoothHandsfreeCallState aIn, bthf_call_state_t& aOut)
-{
-  static const bthf_call_state_t sCallState[] = {
-    CONVERT(HFP_CALL_STATE_ACTIVE, BTHF_CALL_STATE_ACTIVE),
-    CONVERT(HFP_CALL_STATE_HELD, BTHF_CALL_STATE_HELD),
-    CONVERT(HFP_CALL_STATE_DIALING, BTHF_CALL_STATE_DIALING),
-    CONVERT(HFP_CALL_STATE_ALERTING, BTHF_CALL_STATE_ALERTING),
-    CONVERT(HFP_CALL_STATE_INCOMING, BTHF_CALL_STATE_INCOMING),
-    CONVERT(HFP_CALL_STATE_WAITING, BTHF_CALL_STATE_WAITING),
-    CONVERT(HFP_CALL_STATE_IDLE, BTHF_CALL_STATE_IDLE)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sCallState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sCallState[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(BluetoothHandsfreeNetworkState aIn, bthf_network_state_t& aOut)
-{
-  static const bthf_network_state_t sNetworkState[] = {
-    CONVERT(HFP_NETWORK_STATE_NOT_AVAILABLE, BTHF_NETWORK_STATE_NOT_AVAILABLE),
-    CONVERT(HFP_NETWORK_STATE_AVAILABLE,  BTHF_NETWORK_STATE_AVAILABLE)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sNetworkState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sNetworkState[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(BluetoothHandsfreeServiceType aIn, bthf_service_type_t& aOut)
-{
-  static const bthf_service_type_t sServiceType[] = {
-    CONVERT(HFP_SERVICE_TYPE_HOME, BTHF_SERVICE_TYPE_HOME),
-    CONVERT(HFP_SERVICE_TYPE_ROAMING, BTHF_SERVICE_TYPE_ROAMING)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sServiceType)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sServiceType[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(BluetoothHandsfreeVolumeType aIn, bthf_volume_type_t& aOut)
-{
-  static const bthf_volume_type_t sVolumeType[] = {
-    CONVERT(HFP_VOLUME_TYPE_SPEAKER, BTHF_VOLUME_TYPE_SPK),
-    CONVERT(HFP_VOLUME_TYPE_MICROPHONE, BTHF_VOLUME_TYPE_MIC)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sVolumeType)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sVolumeType[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(bthf_audio_state_t aIn, BluetoothHandsfreeAudioState& aOut)
-{
-  static const BluetoothHandsfreeAudioState sAudioState[] = {
-    CONVERT(BTHF_AUDIO_STATE_DISCONNECTED, HFP_AUDIO_STATE_DISCONNECTED),
-    CONVERT(BTHF_AUDIO_STATE_CONNECTING, HFP_AUDIO_STATE_CONNECTING),
-    CONVERT(BTHF_AUDIO_STATE_CONNECTED, HFP_AUDIO_STATE_CONNECTED),
-    CONVERT(BTHF_AUDIO_STATE_DISCONNECTING, HFP_AUDIO_STATE_DISCONNECTING)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sAudioState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sAudioState[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(bthf_chld_type_t aIn, BluetoothHandsfreeCallHoldType& aOut)
-{
-  static const BluetoothHandsfreeCallHoldType sCallHoldType[] = {
-    CONVERT(BTHF_CHLD_TYPE_RELEASEHELD, HFP_CALL_HOLD_RELEASEHELD),
-    CONVERT(BTHF_CHLD_TYPE_RELEASEACTIVE_ACCEPTHELD,
-      HFP_CALL_HOLD_RELEASEACTIVE_ACCEPTHELD),
-    CONVERT(BTHF_CHLD_TYPE_HOLDACTIVE_ACCEPTHELD,
-      HFP_CALL_HOLD_HOLDACTIVE_ACCEPTHELD),
-    CONVERT(BTHF_CHLD_TYPE_ADDHELDTOCONF, HFP_CALL_HOLD_ADDHELDTOCONF)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sCallHoldType)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sCallHoldType[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(bthf_connection_state_t aIn, BluetoothHandsfreeConnectionState& aOut)
-{
-  static const BluetoothHandsfreeConnectionState sConnectionState[] = {
-    CONVERT(BTHF_CONNECTION_STATE_DISCONNECTED,
-      HFP_CONNECTION_STATE_DISCONNECTED),
-    CONVERT(BTHF_CONNECTION_STATE_CONNECTING, HFP_CONNECTION_STATE_CONNECTING),
-    CONVERT(BTHF_CONNECTION_STATE_CONNECTED, HFP_CONNECTION_STATE_CONNECTED),
-    CONVERT(BTHF_CONNECTION_STATE_SLC_CONNECTED,
-      HFP_CONNECTION_STATE_SLC_CONNECTED),
-    CONVERT(BTHF_CONNECTION_STATE_DISCONNECTING,
-      HFP_CONNECTION_STATE_DISCONNECTING)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sConnectionState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sConnectionState[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(bthf_nrec_t aIn, BluetoothHandsfreeNRECState& aOut)
-{
-  static const BluetoothHandsfreeNRECState sNRECState[] = {
-    CONVERT(BTHF_NREC_STOP, HFP_NREC_STOPPED),
-    CONVERT(BTHF_NREC_START, HFP_NREC_STARTED)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sNRECState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sNRECState[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(bthf_vr_state_t aIn, BluetoothHandsfreeVoiceRecognitionState& aOut)
-{
-  static const BluetoothHandsfreeVoiceRecognitionState
-    sVoiceRecognitionState[] = {
-    CONVERT(BTHF_VR_STATE_STOPPED, HFP_VOICE_RECOGNITION_STOPPED),
-    CONVERT(BTHF_VR_STATE_STARTED, HFP_VOICE_RECOGNITION_STARTED)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sVoiceRecognitionState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sVoiceRecognitionState[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(bthf_volume_type_t aIn, BluetoothHandsfreeVolumeType& aOut)
-{
-  static const BluetoothHandsfreeVolumeType sVolumeType[] = {
-    CONVERT(BTHF_VOLUME_TYPE_SPK, HFP_VOLUME_TYPE_SPEAKER),
-    CONVERT(BTHF_VOLUME_TYPE_MIC, HFP_VOLUME_TYPE_MICROPHONE)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sVolumeType)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sVolumeType[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(btav_connection_state_t aIn, BluetoothA2dpConnectionState& aOut)
-{
-  static const BluetoothA2dpConnectionState sConnectionState[] = {
-    CONVERT(BTAV_CONNECTION_STATE_DISCONNECTED,
-      A2DP_CONNECTION_STATE_DISCONNECTED),
-    CONVERT(BTAV_CONNECTION_STATE_CONNECTING,
-      A2DP_CONNECTION_STATE_CONNECTING),
-    CONVERT(BTAV_CONNECTION_STATE_CONNECTED,
-      A2DP_CONNECTION_STATE_CONNECTED),
-    CONVERT(BTAV_CONNECTION_STATE_DISCONNECTING,
-      A2DP_CONNECTION_STATE_DISCONNECTING),
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sConnectionState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sConnectionState[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(btav_audio_state_t aIn, BluetoothA2dpAudioState& aOut)
-{
-  static const BluetoothA2dpAudioState sAudioState[] = {
-    CONVERT(BTAV_AUDIO_STATE_REMOTE_SUSPEND, A2DP_AUDIO_STATE_REMOTE_SUSPEND),
-    CONVERT(BTAV_AUDIO_STATE_STOPPED, A2DP_AUDIO_STATE_STOPPED),
-    CONVERT(BTAV_AUDIO_STATE_STARTED, A2DP_AUDIO_STATE_STARTED),
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sAudioState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sAudioState[aIn];
-  return NS_OK;
-}
-
-#if ANDROID_VERSION >= 18
-inline nsresult
-Convert(const bt_remote_version_t& aIn, BluetoothRemoteInfo& aOut)
-{
-  aOut.mVerMajor = aIn.version;
-  aOut.mVerMinor = aIn.sub_ver;
-  aOut.mManufacturer = aIn.manufacturer;
-
-  return NS_OK;
-}
-
-inline nsresult
-Convert(ControlPlayStatus aIn, btrc_play_status_t& aOut)
-{
-  static const btrc_play_status_t sPlayStatus[] = {
-    CONVERT(PLAYSTATUS_STOPPED, BTRC_PLAYSTATE_STOPPED),
-    CONVERT(PLAYSTATUS_PLAYING, BTRC_PLAYSTATE_PLAYING),
-    CONVERT(PLAYSTATUS_PAUSED, BTRC_PLAYSTATE_PAUSED),
-    CONVERT(PLAYSTATUS_FWD_SEEK, BTRC_PLAYSTATE_FWD_SEEK),
-    CONVERT(PLAYSTATUS_REV_SEEK, BTRC_PLAYSTATE_REV_SEEK)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sPlayStatus)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sPlayStatus[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(enum BluetoothAvrcpPlayerAttribute aIn, btrc_player_attr_t& aOut)
-{
-  static const btrc_player_attr_t sPlayerAttr[] = {
-    CONVERT(AVRCP_PLAYER_ATTRIBUTE_EQUALIZER, BTRC_PLAYER_ATTR_EQUALIZER),
-    CONVERT(AVRCP_PLAYER_ATTRIBUTE_REPEAT, BTRC_PLAYER_ATTR_REPEAT),
-    CONVERT(AVRCP_PLAYER_ATTRIBUTE_SHUFFLE, BTRC_PLAYER_ATTR_SHUFFLE),
-    CONVERT(AVRCP_PLAYER_ATTRIBUTE_SCAN, BTRC_PLAYER_ATTR_SCAN)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sPlayerAttr)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sPlayerAttr[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(btrc_player_attr_t aIn, enum BluetoothAvrcpPlayerAttribute& aOut)
-{
-  static const BluetoothAvrcpPlayerAttribute sPlayerAttr[] = {
-    CONVERT(0, static_cast<BluetoothAvrcpPlayerAttribute>(0)), // invalid, [0] required by gcc
-    CONVERT(BTRC_PLAYER_ATTR_EQUALIZER, AVRCP_PLAYER_ATTRIBUTE_EQUALIZER),
-    CONVERT(BTRC_PLAYER_ATTR_REPEAT, AVRCP_PLAYER_ATTRIBUTE_REPEAT),
-    CONVERT(BTRC_PLAYER_ATTR_SHUFFLE, AVRCP_PLAYER_ATTRIBUTE_SHUFFLE),
-    CONVERT(BTRC_PLAYER_ATTR_SCAN, AVRCP_PLAYER_ATTRIBUTE_SCAN)
-  };
-  if (!aIn || aIn >= MOZ_ARRAY_LENGTH(sPlayerAttr)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sPlayerAttr[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(enum BluetoothAvrcpStatus aIn, btrc_status_t& aOut)
-{
-  static const btrc_status_t sStatus[] = {
-    CONVERT(AVRCP_STATUS_BAD_COMMAND, BTRC_STS_BAD_CMD),
-    CONVERT(AVRCP_STATUS_BAD_PARAMETER, BTRC_STS_BAD_PARAM),
-    CONVERT(AVRCP_STATUS_NOT_FOUND, BTRC_STS_NOT_FOUND),
-    CONVERT(AVRCP_STATUS_INTERNAL_ERROR, BTRC_STS_INTERNAL_ERR),
-    CONVERT(AVRCP_STATUS_SUCCESS, BTRC_STS_NO_ERROR)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sStatus)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sStatus[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(enum BluetoothAvrcpEvent aIn, btrc_event_id_t& aOut)
-{
-  static const btrc_event_id_t sEventId[] = {
-    CONVERT(AVRCP_EVENT_PLAY_STATUS_CHANGED, BTRC_EVT_PLAY_STATUS_CHANGED),
-    CONVERT(AVRCP_EVENT_TRACK_CHANGE, BTRC_EVT_TRACK_CHANGE),
-    CONVERT(AVRCP_EVENT_TRACK_REACHED_END, BTRC_EVT_TRACK_REACHED_END),
-    CONVERT(AVRCP_EVENT_TRACK_REACHED_START, BTRC_EVT_TRACK_REACHED_START),
-    CONVERT(AVRCP_EVENT_PLAY_POS_CHANGED, BTRC_EVT_PLAY_POS_CHANGED),
-    CONVERT(AVRCP_EVENT_APP_SETTINGS_CHANGED, BTRC_EVT_APP_SETTINGS_CHANGED)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sEventId)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sEventId[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(btrc_event_id_t aIn, enum BluetoothAvrcpEvent& aOut)
-{
-  static const BluetoothAvrcpEvent sEventId[] = {
-    CONVERT(0, static_cast<BluetoothAvrcpEvent>(0)), // invalid, [0] required by gcc
-    CONVERT(BTRC_EVT_PLAY_STATUS_CHANGED, AVRCP_EVENT_PLAY_STATUS_CHANGED),
-    CONVERT(BTRC_EVT_TRACK_CHANGE, AVRCP_EVENT_TRACK_CHANGE),
-    CONVERT(BTRC_EVT_TRACK_REACHED_END, AVRCP_EVENT_TRACK_REACHED_END),
-    CONVERT(BTRC_EVT_TRACK_REACHED_START, AVRCP_EVENT_TRACK_REACHED_START),
-    CONVERT(BTRC_EVT_PLAY_POS_CHANGED, AVRCP_EVENT_PLAY_POS_CHANGED),
-    CONVERT(6, static_cast<BluetoothAvrcpEvent>(0)), // invalid, [6] required by gcc
-    CONVERT(7, static_cast<BluetoothAvrcpEvent>(0)), // invalid, [7] required by gcc
-    CONVERT(BTRC_EVT_APP_SETTINGS_CHANGED, AVRCP_EVENT_APP_SETTINGS_CHANGED)
-  };
-  if (!aIn || aIn >= MOZ_ARRAY_LENGTH(sEventId)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sEventId[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(btrc_media_attr_t aIn, enum BluetoothAvrcpMediaAttribute& aOut)
-{
-  static const BluetoothAvrcpMediaAttribute sEventId[] = {
-    CONVERT(0, static_cast<BluetoothAvrcpMediaAttribute>(0)), // invalid, [0] required by gcc
-    CONVERT(BTRC_MEDIA_ATTR_TITLE, AVRCP_MEDIA_ATTRIBUTE_TITLE),
-    CONVERT(BTRC_MEDIA_ATTR_ARTIST, AVRCP_MEDIA_ATTRIBUTE_ARTIST),
-    CONVERT(BTRC_MEDIA_ATTR_ALBUM, AVRCP_MEDIA_ATTRIBUTE_ALBUM),
-    CONVERT(BTRC_MEDIA_ATTR_TRACK_NUM, AVRCP_MEDIA_ATTRIBUTE_TRACK_NUM),
-    CONVERT(BTRC_MEDIA_ATTR_NUM_TRACKS, AVRCP_MEDIA_ATTRIBUTE_NUM_TRACKS),
-    CONVERT(BTRC_MEDIA_ATTR_GENRE, AVRCP_MEDIA_ATTRIBUTE_GENRE),
-    CONVERT(BTRC_MEDIA_ATTR_PLAYING_TIME, AVRCP_MEDIA_ATTRIBUTE_PLAYING_TIME)
-  };
-  if (!aIn || aIn >= MOZ_ARRAY_LENGTH(sEventId)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sEventId[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(enum BluetoothAvrcpNotification aIn, btrc_notification_type_t& aOut)
-{
-  static const btrc_notification_type_t sNotificationType[] = {
-    CONVERT(AVRCP_NTF_INTERIM, BTRC_NOTIFICATION_TYPE_INTERIM),
-    CONVERT(AVRCP_NTF_CHANGED, BTRC_NOTIFICATION_TYPE_CHANGED)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sNotificationType)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sNotificationType[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(const BluetoothAvrcpElementAttribute& aIn, btrc_element_attr_val_t& aOut);
-
-nsresult
-Convert(const btrc_player_settings_t& aIn, BluetoothAvrcpPlayerSettings& aOut);
-#endif // ANDROID_VERSION >= 18
-
-#if ANDROID_VERSION >= 19
-inline nsresult
-Convert(btrc_remote_features_t aIn, unsigned long& aOut)
-{
-  /* The input type's name is misleading. The converted value is
-   * actually a bitmask.
-   */
-  aOut = static_cast<unsigned long>(aIn);
-  return NS_OK;
-}
-#endif // ANDROID_VERSION >= 19
-
-inline nsresult
-Convert(int aIn, BluetoothGattStatus& aOut)
-{
-  /* Reference: $B2G/external/bluetooth/bluedroid/stack/include/gatt_api.h */
-  static const BluetoothGattStatus sGattStatus[] = {
-    CONVERT(0x0000, GATT_STATUS_SUCCESS),
-    CONVERT(0x0001, GATT_STATUS_INVALID_HANDLE),
-    CONVERT(0x0002, GATT_STATUS_READ_NOT_PERMITTED),
-    CONVERT(0x0003, GATT_STATUS_WRITE_NOT_PERMITTED),
-    CONVERT(0x0004, GATT_STATUS_INVALID_PDU),
-    CONVERT(0x0005, GATT_STATUS_INSUFFICIENT_AUTHENTICATION),
-    CONVERT(0x0006, GATT_STATUS_REQUEST_NOT_SUPPORTED),
-    CONVERT(0x0007, GATT_STATUS_INVALID_OFFSET),
-    CONVERT(0x0008, GATT_STATUS_INSUFFICIENT_AUTHORIZATION),
-    CONVERT(0x0009, GATT_STATUS_PREPARE_QUEUE_FULL),
-    CONVERT(0x000a, GATT_STATUS_ATTRIBUTE_NOT_FOUND),
-    CONVERT(0x000b, GATT_STATUS_ATTRIBUTE_NOT_LONG),
-    CONVERT(0x000c, GATT_STATUS_INSUFFICIENT_ENCRYPTION_KEY_SIZE),
-    CONVERT(0x000d, GATT_STATUS_INVALID_ATTRIBUTE_LENGTH),
-    CONVERT(0x000e, GATT_STATUS_UNLIKELY_ERROR),
-    CONVERT(0x000f, GATT_STATUS_INSUFFICIENT_ENCRYPTION),
-    CONVERT(0x0010, GATT_STATUS_UNSUPPORTED_GROUP_TYPE),
-    CONVERT(0x0011, GATT_STATUS_INSUFFICIENT_RESOURCES)
-  };
-  if (static_cast<uint32_t>(aIn) >= MOZ_ARRAY_LENGTH(sGattStatus)) {
-    aOut = GATT_STATUS_UNKNOWN_ERROR;
-    return NS_ERROR_ILLEGAL_VALUE;
-  } else {
-    aOut = sGattStatus[aIn];
-  }
-  return NS_OK;
-}
-
-inline nsresult
-Convert(BluetoothGattStatus aIn, int& aOut)
-{
-  /* Reference: $B2G/external/bluetooth/bluedroid/stack/include/gatt_api.h */
-  static const int sGattStatus[] = {
-    CONVERT(GATT_STATUS_SUCCESS, 0x0000),
-    CONVERT(GATT_STATUS_INVALID_HANDLE, 0x0001),
-    CONVERT(GATT_STATUS_READ_NOT_PERMITTED, 0x0002),
-    CONVERT(GATT_STATUS_WRITE_NOT_PERMITTED, 0x0003),
-    CONVERT(GATT_STATUS_INVALID_PDU, 0x0004),
-    CONVERT(GATT_STATUS_INSUFFICIENT_AUTHENTICATION, 0x0005),
-    CONVERT(GATT_STATUS_REQUEST_NOT_SUPPORTED, 0x0006),
-    CONVERT(GATT_STATUS_INVALID_OFFSET, 0x0007),
-    CONVERT(GATT_STATUS_INSUFFICIENT_AUTHORIZATION, 0x0008),
-    CONVERT(GATT_STATUS_PREPARE_QUEUE_FULL, 0x0009),
-    CONVERT(GATT_STATUS_ATTRIBUTE_NOT_FOUND, 0x000a),
-    CONVERT(GATT_STATUS_ATTRIBUTE_NOT_LONG, 0x000b),
-    CONVERT(GATT_STATUS_INSUFFICIENT_ENCRYPTION_KEY_SIZE, 0x000c),
-    CONVERT(GATT_STATUS_INVALID_ATTRIBUTE_LENGTH, 0x000d),
-    CONVERT(GATT_STATUS_UNLIKELY_ERROR, 0x000e),
-    CONVERT(GATT_STATUS_INSUFFICIENT_ENCRYPTION, 0x000f),
-    CONVERT(GATT_STATUS_UNSUPPORTED_GROUP_TYPE, 0x0010),
-    CONVERT(GATT_STATUS_INSUFFICIENT_RESOURCES, 0x0011)
-  };
-  if (static_cast<uint32_t>(aIn) >= MOZ_ARRAY_LENGTH(sGattStatus)) {
-    aOut = -1;
-    return NS_ERROR_ILLEGAL_VALUE;
-  } else {
-    aOut = sGattStatus[aIn];
-  }
-  return NS_OK;
-}
-
-nsresult
-Convert(const uint8_t* aIn, BluetoothGattAdvData& aOut);
-
-inline nsresult
-Convert(BluetoothGattAttrPerm aIn, int& aOut)
-{
-  /* Reference: $B2G/external/bluetooth/bluedroid/stack/include/gatt_api.h */
-  static const uint16_t sGattAttrPermBit[] = {
-    CONVERT(0, GATT_ATTR_PERM_BIT_READ),
-    CONVERT(1, GATT_ATTR_PERM_BIT_READ_ENCRYPTED),
-    CONVERT(2, GATT_ATTR_PERM_BIT_READ_ENCRYPTED_MITM),
-    CONVERT(3, 0),
-    CONVERT(4, GATT_ATTR_PERM_BIT_WRITE),
-    CONVERT(5, GATT_ATTR_PERM_BIT_WRITE_ENCRYPTED),
-    CONVERT(6, GATT_ATTR_PERM_BIT_WRITE_ENCRYPTED_MITM),
-    CONVERT(7, GATT_ATTR_PERM_BIT_WRITE_SIGNED),
-    CONVERT(8, GATT_ATTR_PERM_BIT_WRITE_SIGNED_MITM)
-  };
-  aOut = 0;
-  for (uint8_t i = 0; i < MOZ_ARRAY_LENGTH(sGattAttrPermBit); i++) {
-    if (aIn & sGattAttrPermBit[i]) {
-      aOut |= (1 << i);
-    }
-  }
-  return NS_OK;
-}
-
-inline nsresult
-Convert(int aIn, BluetoothGattCharProp& aOut)
-{
-  /* Reference: $B2G/external/bluetooth/bluedroid/stack/include/gatt_api.h */
-  static const uint8_t sGattCharPropBit[] = {
-    CONVERT(0, GATT_CHAR_PROP_BIT_BROADCAST),
-    CONVERT(1, GATT_CHAR_PROP_BIT_READ),
-    CONVERT(2, GATT_CHAR_PROP_BIT_WRITE_NO_RESPONSE),
-    CONVERT(3, GATT_CHAR_PROP_BIT_WRITE),
-    CONVERT(4, GATT_CHAR_PROP_BIT_NOTIFY),
-    CONVERT(5, GATT_CHAR_PROP_BIT_INDICATE),
-    CONVERT(6, GATT_CHAR_PROP_BIT_SIGNED_WRITE),
-    CONVERT(7, GATT_CHAR_PROP_BIT_EXTENDED_PROPERTIES)
-  };
-  aOut = BLUETOOTH_EMPTY_GATT_CHAR_PROP;
-  for (uint8_t i = 0; i < MOZ_ARRAY_LENGTH(sGattCharPropBit); i++) {
-    if (aIn & (1 << i)) {
-      aOut |= sGattCharPropBit[i];
-    }
-  }
-  return NS_OK;
-}
-
-inline nsresult
-Convert(BluetoothGattCharProp aIn, int& aOut)
-{
-  /* Reference: $B2G/external/bluetooth/bluedroid/stack/include/gatt_api.h */
-  static const uint8_t sGattCharPropBit[] = {
-    CONVERT(0, GATT_CHAR_PROP_BIT_BROADCAST),
-    CONVERT(1, GATT_CHAR_PROP_BIT_READ),
-    CONVERT(2, GATT_CHAR_PROP_BIT_WRITE_NO_RESPONSE),
-    CONVERT(3, GATT_CHAR_PROP_BIT_WRITE),
-    CONVERT(4, GATT_CHAR_PROP_BIT_NOTIFY),
-    CONVERT(5, GATT_CHAR_PROP_BIT_INDICATE),
-    CONVERT(6, GATT_CHAR_PROP_BIT_SIGNED_WRITE),
-    CONVERT(7, GATT_CHAR_PROP_BIT_EXTENDED_PROPERTIES)
-  };
-  aOut = 0;
-  for (uint8_t i = 0; i < MOZ_ARRAY_LENGTH(sGattCharPropBit); i++) {
-    if (aIn & sGattCharPropBit[i]) {
-      aOut |= (1 << i);
-    }
-  }
-  return NS_OK;
-}
-
-inline nsresult
-Convert(BluetoothGattAuthReq aIn, int& aOut)
-{
-  /* Reference: $B2G/external/bluetooth/bluedroid/stack/include/gatt_api.h */
-  static const int sGattAuthReq[] = {
-    CONVERT(GATT_AUTH_REQ_NONE, 0),
-    CONVERT(GATT_AUTH_REQ_NO_MITM, 1),
-    CONVERT(GATT_AUTH_REQ_MITM, 2),
-    CONVERT(GATT_AUTH_REQ_SIGNED_NO_MITM, 3),
-    CONVERT(GATT_AUTH_REQ_SIGNED_MITM, 4)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sGattAuthReq)) {
-    aOut = GATT_AUTH_REQ_NONE; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sGattAuthReq[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(BluetoothGattWriteType aIn, int& aOut)
-{
-  /* Reference: $B2G/external/bluetooth/bluedroid/stack/include/gatt_api.h */
-  static const int sGattWriteType[] = {
-    CONVERT(GATT_WRITE_TYPE_NO_RESPONSE, 1),
-    CONVERT(GATT_WRITE_TYPE_NORMAL, 2),
-    CONVERT(GATT_WRITE_TYPE_PREPARE, 3),
-    CONVERT(GATT_WRITE_TYPE_SIGNED, 4)
-  };
-  if (aIn >= MOZ_ARRAY_LENGTH(sGattWriteType)) {
-    aOut = GATT_WRITE_TYPE_NORMAL; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sGattWriteType[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(const ArrayBuffer& aIn, char* aOut)
-{
-  aIn.ComputeLengthAndData();
-  memcpy(aOut, aIn.Data(), aIn.Length());
-  return NS_OK;
-}
-
-#if ANDROID_VERSION >= 19
-nsresult
-Convert(const BluetoothGattId& aIn, btgatt_gatt_id_t& aOut);
-
-nsresult
-Convert(const btgatt_gatt_id_t& aIn, BluetoothGattId& aOut);
-
-nsresult
-Convert(const BluetoothGattServiceId& aIn, btgatt_srvc_id_t& aOut);
-
-nsresult
-Convert(const btgatt_srvc_id_t& aIn, BluetoothGattServiceId& aOut);
-
-nsresult
-Convert(const btgatt_read_params_t& aIn, BluetoothGattReadParam& aOut);
-
-nsresult
-Convert(const btgatt_write_params_t& aIn, BluetoothGattWriteParam& aOut);
-
-nsresult
-Convert(const btgatt_notify_params_t& aIn, BluetoothGattNotifyParam& aOut);
-
-nsresult
-Convert(const BluetoothGattTestParam& aIn, btgatt_test_params_t& aOut);
-
-inline nsresult
-Convert(BluetoothTransport aIn, int& aOut)
-{
-  static const int sTransport[] = {
-    CONVERT(TRANSPORT_AUTO, 0),
-    CONVERT(TRANSPORT_BREDR, 1),
-    CONVERT(TRANSPORT_LE, 2)
-  };
-  if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sTransport))) {
-    aOut = -1;
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sTransport[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(const BluetoothGattResponse& aIn, btgatt_response_t& aOut);
-#endif // ANDROID_VERSION >= 19
-
-#if ANDROID_VERSION >= 21
-nsresult
-Convert(const BluetoothTransport& aIn, btgatt_transport_t& aOut);
-
-nsresult
-Convert(const bt_activity_energy_info& aIn, BluetoothActivityEnergyInfo& aOut);
-
-inline nsresult
-Convert(bthf_wbs_config_t aIn, BluetoothHandsfreeWbsConfig& aOut)
-{
-  static const BluetoothHandsfreeWbsConfig sWbsConfig[] = {
-    CONVERT(BTHF_WBS_NONE, HFP_WBS_NONE),
-    CONVERT(BTHF_WBS_NO, HFP_WBS_NO),
-    CONVERT(BTHF_WBS_YES, HFP_WBS_YES)
-  };
-  if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sWbsConfig))) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sWbsConfig[aIn];
-  return NS_OK;
-}
-
-inline nsresult
-Convert(BluetoothHandsfreeWbsConfig aIn, bthf_wbs_config_t& aOut)
-{
-  static const bthf_wbs_config_t sWbsConfig[] = {
-    CONVERT(HFP_WBS_NONE, BTHF_WBS_NONE),
-    CONVERT(HFP_WBS_NO, BTHF_WBS_NO),
-    CONVERT(HFP_WBS_YES, BTHF_WBS_YES)
-  };
-  if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sWbsConfig))) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sWbsConfig[aIn];
-  return NS_OK;
-}
-#endif // ANDROID_VERSION >= 21
-
-/* |ConvertArray| is a helper for converting arrays. Pass an
- * instance of this structure as the first argument to |Convert|
- * to convert an array. The output type has to support the array
- * subscript operator.
- */
-template <typename T>
-struct ConvertArray
-{
-  ConvertArray(const T* aData, unsigned long aLength)
-  : mData(aData)
-  , mLength(aLength)
-  { }
-
-  const T* mData;
-  unsigned long mLength;
-};
-
-/* This implementation of |Convert| converts the elements of an
- * array one-by-one. The result data structures must have enough
- * memory allocated.
- */
-template<typename Tin, typename Tout>
-inline nsresult
-Convert(const ConvertArray<Tin>& aIn, Tout& aOut)
-{
-  for (unsigned long i = 0; i < aIn.mLength; ++i) {
-    nsresult rv = Convert(aIn.mData[i], aOut[i]);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-  }
-  return NS_OK;
-}
-
-/* This implementation of |Convert| is a helper that automatically
- * allocates enough memory to hold the conversion results. The
- * actual conversion is performed by the array-conversion helper
- * above.
- */
-template<typename Tin, typename Tout>
-inline nsresult
-Convert(const ConvertArray<Tin>& aIn, nsAutoArrayPtr<Tout>& aOut)
-{
-  aOut = new Tout[aIn.mLength];
-  Tout* out = aOut.get();
-
-  return Convert<Tin, Tout*>(aIn, out);
-}
-
-/* |ConvertDefault| is a helper function to return the result of a
- * conversion or a default value if the conversion fails.
- */
-template<typename Tin, typename Tout>
-inline Tout
-ConvertDefault(const Tin& aIn, const Tout& aDefault)
-{
-  Tout out = aDefault; // assignment silences compiler warning
-  if (NS_FAILED(Convert(aIn, out))) {
-    return aDefault;
-  }
-  return out;
-}
-
-/* This implementation of |Convert| is a helper for copying the
- * input value into the output value. It handles all cases that
- * need no conversion.
- */
-template<typename T>
-inline nsresult
-Convert(const T& aIn, T& aOut)
-{
-  aOut = aIn;
-
-  return NS_OK;
-}
-
-nsresult
-Convert(const bt_property_t& aIn, BluetoothProperty& aOut);
-
-//
-// Result handling
-//
-
-template <typename Obj, typename Res>
-class BluetoothHALInterfaceRunnable0 : public nsRunnable
-{
-public:
-  BluetoothHALInterfaceRunnable0(Obj* aObj, Res (Obj::*aMethod)())
-  : mObj(aObj)
-  , mMethod(aMethod)
-  {
-    MOZ_ASSERT(mObj);
-    MOZ_ASSERT(mMethod);
-  }
-
-  NS_METHOD
-  Run() override
-  {
-    ((*mObj).*mMethod)();
-    return NS_OK;
-  }
-
-private:
-  nsRefPtr<Obj> mObj;
-  void (Obj::*mMethod)();
-};
-
-template <typename Obj, typename Res, typename Tin1, typename Arg1>
-class BluetoothHALInterfaceRunnable1 : public nsRunnable
-{
-public:
-  BluetoothHALInterfaceRunnable1(Obj* aObj, Res (Obj::*aMethod)(Arg1),
-                                 const Arg1& aArg1)
-  : mObj(aObj)
-  , mMethod(aMethod)
-  , mArg1(aArg1)
-  {
-    MOZ_ASSERT(mObj);
-    MOZ_ASSERT(mMethod);
-  }
-
-  NS_METHOD
-  Run() override
-  {
-    ((*mObj).*mMethod)(mArg1);
-    return NS_OK;
-  }
-
-private:
-  nsRefPtr<Obj> mObj;
-  Res (Obj::*mMethod)(Arg1);
-  Tin1 mArg1;
-};
-
-template <typename Obj, typename Res,
-          typename Tin1, typename Tin2, typename Tin3,
-          typename Arg1, typename Arg2, typename Arg3>
-class BluetoothHALInterfaceRunnable3 : public nsRunnable
-{
-public:
-  BluetoothHALInterfaceRunnable3(Obj* aObj,
-                                 Res (Obj::*aMethod)(Arg1, Arg2, Arg3),
-                                 const Arg1& aArg1, const Arg2& aArg2,
-                                 const Arg3& aArg3)
-  : mObj(aObj)
-  , mMethod(aMethod)
-  , mArg1(aArg1)
-  , mArg2(aArg2)
-  , mArg3(aArg3)
-  {
-    MOZ_ASSERT(mObj);
-    MOZ_ASSERT(mMethod);
-  }
-
-  NS_METHOD
-  Run() override
-  {
-    ((*mObj).*mMethod)(mArg1, mArg2, mArg3);
-    return NS_OK;
-  }
-
-private:
-  nsRefPtr<Obj> mObj;
-  Res (Obj::*mMethod)(Arg1, Arg2, Arg3);
-  Tin1 mArg1;
-  Tin2 mArg2;
-  Tin3 mArg3;
-};
-
-//
-// Notification handling
-//
-
-template <typename ObjectWrapper, typename Res>
-class BluetoothNotificationHALRunnable0 : public nsRunnable
-{
-public:
-  typedef typename ObjectWrapper::ObjectType  ObjectType;
-  typedef BluetoothNotificationHALRunnable0<ObjectWrapper, Res> SelfType;
-
-  static already_AddRefed<SelfType> Create(Res (ObjectType::*aMethod)())
-  {
-    nsRefPtr<SelfType> runnable(new SelfType(aMethod));
-
-    return runnable.forget();
-  }
-
-  static void
-  Dispatch(Res (ObjectType::*aMethod)())
-  {
-    nsRefPtr<SelfType> runnable = Create(aMethod);
-
-    if (!runnable) {
-      BT_WARNING("BluetoothNotificationHALRunnable0::Create failed");
-      return;
-    }
-    nsresult rv = NS_DispatchToMainThread(runnable);
-    if (NS_FAILED(rv)) {
-      BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-    }
-  }
-
-  NS_METHOD
-  Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    ObjectType* obj = ObjectWrapper::GetInstance();
-
-    if (!obj) {
-      BT_WARNING("Notification handler not initialized");
-    } else {
-      ((*obj).*mMethod)();
-    }
-    return NS_OK;
-  }
-
-private:
-  BluetoothNotificationHALRunnable0(Res (ObjectType::*aMethod)())
-  : mMethod(aMethod)
-  {
-    MOZ_ASSERT(mMethod);
-  }
-
-  Res (ObjectType::*mMethod)();
-};
-
-template <typename ObjectWrapper, typename Res,
-          typename Tin1, typename Arg1=Tin1>
-class BluetoothNotificationHALRunnable1 : public nsRunnable
-{
-public:
-  typedef typename ObjectWrapper::ObjectType  ObjectType;
-  typedef BluetoothNotificationHALRunnable1<ObjectWrapper, Res,
-                                            Tin1, Arg1> SelfType;
-
-  template <typename T1>
-  static already_AddRefed<SelfType> Create(
-    Res (ObjectType::*aMethod)(Arg1), const T1& aIn1)
-  {
-    nsRefPtr<SelfType> runnable(new SelfType(aMethod));
-
-    if (NS_FAILED(runnable->ConvertAndSet(aIn1))) {
-      return nullptr;
-    }
-    return runnable.forget();
-  }
-
-  template <typename T1>
-  static void
-  Dispatch(Res (ObjectType::*aMethod)(Arg1), const T1& aIn1)
-  {
-    nsRefPtr<SelfType> runnable = Create(aMethod, aIn1);
-
-    if (!runnable) {
-      BT_WARNING("BluetoothNotificationHALRunnable1::Create failed");
-      return;
-    }
-    nsresult rv = NS_DispatchToMainThread(runnable);
-    if (NS_FAILED(rv)) {
-      BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-    }
-  }
-
-  NS_METHOD
-  Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    ObjectType* obj = ObjectWrapper::GetInstance();
-
-    if (!obj) {
-      BT_WARNING("Notification handler not initialized");
-    } else {
-      ((*obj).*mMethod)(mArg1);
-    }
-    return NS_OK;
-  }
-
-private:
-  BluetoothNotificationHALRunnable1(Res (ObjectType::*aMethod)(Arg1))
-  : mMethod(aMethod)
-  {
-    MOZ_ASSERT(mMethod);
-  }
-
-  template<typename T1>
-  nsresult
-  ConvertAndSet(const T1& aIn1)
-  {
-    nsresult rv = Convert(aIn1, mArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    return NS_OK;
-  }
-
-  Res (ObjectType::*mMethod)(Arg1);
-  Tin1 mArg1;
-};
-
-template <typename ObjectWrapper, typename Res,
-          typename Tin1, typename Tin2,
-          typename Arg1=Tin1, typename Arg2=Tin2>
-class BluetoothNotificationHALRunnable2 : public nsRunnable
-{
-public:
-  typedef typename ObjectWrapper::ObjectType  ObjectType;
-  typedef BluetoothNotificationHALRunnable2<ObjectWrapper, Res,
-                                            Tin1, Tin2,
-                                            Arg1, Arg2> SelfType;
-
-  template <typename T1, typename T2>
-  static already_AddRefed<SelfType> Create(
-    Res (ObjectType::*aMethod)(Arg1, Arg2), const T1& aIn1, const T2& aIn2)
-  {
-    nsRefPtr<SelfType> runnable(new SelfType(aMethod));
-
-    if (NS_FAILED(runnable->ConvertAndSet(aIn1, aIn2))) {
-      return nullptr;
-    }
-    return runnable.forget();
-  }
-
-  template <typename T1, typename T2>
-  static void
-  Dispatch(Res (ObjectType::*aMethod)(Arg1, Arg2),
-           const T1& aIn1, const T2& aIn2)
-  {
-    nsRefPtr<SelfType> runnable = Create(aMethod, aIn1, aIn2);
-
-    if (!runnable) {
-      BT_WARNING("BluetoothNotificationHALRunnable2::Create failed");
-      return;
-    }
-    nsresult rv = NS_DispatchToMainThread(runnable);
-    if (NS_FAILED(rv)) {
-      BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-    }
-  }
-
-  NS_METHOD
-  Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    ObjectType* obj = ObjectWrapper::GetInstance();
-
-    if (!obj) {
-      BT_WARNING("Notification handler not initialized");
-    } else {
-      ((*obj).*mMethod)(mArg1, mArg2);
-    }
-    return NS_OK;
-  }
-
-private:
-  BluetoothNotificationHALRunnable2(
-    Res (ObjectType::*aMethod)(Arg1, Arg2))
-  : mMethod(aMethod)
-  {
-    MOZ_ASSERT(mMethod);
-  }
-
-  template<typename T1, typename T2>
-  nsresult
-  ConvertAndSet(const T1& aIn1, const T2& aIn2)
-  {
-    nsresult rv = Convert(aIn1, mArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn2, mArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    return NS_OK;
-  }
-
-  Res (ObjectType::*mMethod)(Arg1, Arg2);
-  Tin1 mArg1;
-  Tin2 mArg2;
-};
-
-template <typename ObjectWrapper, typename Res,
-          typename Tin1, typename Tin2, typename Tin3,
-          typename Arg1=Tin1, typename Arg2=Tin2, typename Arg3=Tin3>
-class BluetoothNotificationHALRunnable3 : public nsRunnable
-{
-public:
-  typedef typename ObjectWrapper::ObjectType  ObjectType;
-  typedef BluetoothNotificationHALRunnable3<ObjectWrapper, Res,
-                                            Tin1, Tin2, Tin3,
-                                            Arg1, Arg2, Arg3> SelfType;
-
-  template <typename T1, typename T2, typename T3>
-  static already_AddRefed<SelfType> Create(
-    Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3),
-    const T1& aIn1, const T2& aIn2, const T3& aIn3)
-  {
-    nsRefPtr<SelfType> runnable(new SelfType(aMethod));
-
-    if (NS_FAILED(runnable->ConvertAndSet(aIn1, aIn2, aIn3))) {
-      return nullptr;
-    }
-    return runnable.forget();
-  }
-
-  template <typename T1, typename T2, typename T3>
-  static void
-  Dispatch(Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3),
-           const T1& aIn1, const T2& aIn2, const T3& aIn3)
-  {
-    nsRefPtr<SelfType> runnable = Create(aMethod, aIn1, aIn2, aIn3);
-
-    if (!runnable) {
-      BT_WARNING("BluetoothNotificationHALRunnable3::Create failed");
-      return;
-    }
-    nsresult rv = NS_DispatchToMainThread(runnable);
-    if (NS_FAILED(rv)) {
-      BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-    }
-  }
-
-  NS_METHOD
-  Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    ObjectType* obj = ObjectWrapper::GetInstance();
-
-    if (!obj) {
-      BT_WARNING("Notification handler not initialized");
-    } else {
-      ((*obj).*mMethod)(mArg1, mArg2, mArg3);
-    }
-    return NS_OK;
-  }
-
-private:
-  BluetoothNotificationHALRunnable3(
-    Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3))
-  : mMethod(aMethod)
-  {
-    MOZ_ASSERT(mMethod);
-  }
-
-  template<typename T1, typename T2, typename T3>
-  nsresult
-  ConvertAndSet(const T1& aIn1, const T2& aIn2, const T3& aIn3)
-  {
-    nsresult rv = Convert(aIn1, mArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn2, mArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn3, mArg3);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    return NS_OK;
-  }
-
-  Res (ObjectType::*mMethod)(Arg1, Arg2, Arg3);
-  Tin1 mArg1;
-  Tin2 mArg2;
-  Tin3 mArg3;
-};
-
-template <typename ObjectWrapper, typename Res,
-          typename Tin1, typename Tin2, typename Tin3, typename Tin4,
-          typename Arg1=Tin1, typename Arg2=Tin2,
-          typename Arg3=Tin3, typename Arg4=Tin4>
-class BluetoothNotificationHALRunnable4 : public nsRunnable
-{
-public:
-  typedef typename ObjectWrapper::ObjectType  ObjectType;
-  typedef BluetoothNotificationHALRunnable4<ObjectWrapper, Res,
-    Tin1, Tin2, Tin3, Tin4, Arg1, Arg2, Arg3, Arg4> SelfType;
-
-  template <typename T1, typename T2, typename T3, typename T4>
-  static already_AddRefed<SelfType> Create(
-    Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4),
-    const T1& aIn1, const T2& aIn2, const T3& aIn3, const T4& aIn4)
-  {
-    nsRefPtr<SelfType> runnable(new SelfType(aMethod));
-
-    if (NS_FAILED(runnable->ConvertAndSet(aIn1, aIn2, aIn3, aIn4))) {
-      return nullptr;
-    }
-    return runnable.forget();
-  }
-
-  template <typename T1, typename T2, typename T3, typename T4>
-  static void
-  Dispatch(Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4),
-           const T1& aIn1, const T2& aIn2, const T3& aIn3, const T4& aIn4)
-  {
-    nsRefPtr<SelfType> runnable = Create(aMethod, aIn1, aIn2, aIn3, aIn4);
-
-    if (!runnable) {
-      BT_WARNING("BluetoothNotificationHALRunnable4::Create failed");
-      return;
-    }
-    nsresult rv = NS_DispatchToMainThread(runnable);
-    if (NS_FAILED(rv)) {
-      BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-    }
-  }
-
-  NS_METHOD
-  Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    ObjectType* obj = ObjectWrapper::GetInstance();
-
-    if (!obj) {
-      BT_WARNING("Notification handler not initialized");
-    } else {
-      ((*obj).*mMethod)(mArg1, mArg2, mArg3, mArg4);
-    }
-    return NS_OK;
-  }
-
-private:
-  BluetoothNotificationHALRunnable4(
-    Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4))
-  : mMethod(aMethod)
-  {
-    MOZ_ASSERT(mMethod);
-  }
-
-  template<typename T1,typename T2, typename T3, typename T4>
-  nsresult
-  ConvertAndSet(const T1& aIn1, const T2& aIn2,
-                const T3& aIn3, const T4& aIn4)
-  {
-    nsresult rv = Convert(aIn1, mArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn2, mArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn3, mArg3);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn4, mArg4);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    return NS_OK;
-  }
-
-  Res (ObjectType::*mMethod)(Arg1, Arg2, Arg3, Arg4);
-  Tin1 mArg1;
-  Tin2 mArg2;
-  Tin3 mArg3;
-  Tin4 mArg4;
-};
-
-template <typename ObjectWrapper, typename Res,
-          typename Tin1, typename Tin2, typename Tin3,
-          typename Tin4, typename Tin5,
-          typename Arg1=Tin1, typename Arg2=Tin2, typename Arg3=Tin3,
-          typename Arg4=Tin4, typename Arg5=Tin5>
-class BluetoothNotificationHALRunnable5 : public nsRunnable
-{
-public:
-  typedef typename ObjectWrapper::ObjectType  ObjectType;
-  typedef BluetoothNotificationHALRunnable5<ObjectWrapper, Res,
-    Tin1, Tin2, Tin3, Tin4, Tin5, Arg1, Arg2, Arg3, Arg4, Arg5> SelfType;
-
-  template <typename T1, typename T2, typename T3, typename T4, typename T5>
-  static already_AddRefed<SelfType> Create(
-    Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5),
-    const T1& aIn1, const T2& aIn2, const T3& aIn3,
-    const T4& aIn4, const T5& aIn5)
-  {
-    nsRefPtr<SelfType> runnable(new SelfType(aMethod));
-
-    if (NS_FAILED(runnable->ConvertAndSet(aIn1, aIn2, aIn3, aIn4, aIn5))) {
-      return nullptr;
-    }
-    return runnable.forget();
-  }
-
-  template <typename T1, typename T2, typename T3, typename T4, typename T5>
-  static void
-  Dispatch(Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5),
-           const T1& aIn1, const T2& aIn2, const T3& aIn3,
-           const T4& aIn4, const T5& aIn5)
-  {
-    nsRefPtr<SelfType> runnable = Create(aMethod,
-                                         aIn1, aIn2, aIn3, aIn4, aIn5);
-    if (!runnable) {
-      BT_WARNING("BluetoothNotificationHALRunnable5::Create failed");
-      return;
-    }
-    nsresult rv = NS_DispatchToMainThread(runnable);
-    if (NS_FAILED(rv)) {
-      BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-    }
-  }
-
-  NS_METHOD
-  Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    ObjectType* obj = ObjectWrapper::GetInstance();
-
-    if (!obj) {
-      BT_WARNING("Notification handler not initialized");
-    } else {
-      ((*obj).*mMethod)(mArg1, mArg2, mArg3, mArg4, mArg5);
-    }
-    return NS_OK;
-  }
-
-private:
-  BluetoothNotificationHALRunnable5(
-    Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5))
-  : mMethod(aMethod)
-  {
-    MOZ_ASSERT(mMethod);
-  }
-
-  template<typename T1, typename T2, typename T3, typename T4, typename T5>
-  nsresult
-  ConvertAndSet(const T1& aIn1, const T2& aIn2, const T3& aIn3,
-                const T4& aIn4, const T5& aIn5)
-  {
-    nsresult rv = Convert(aIn1, mArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn2, mArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn3, mArg3);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn4, mArg4);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn5, mArg5);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    return NS_OK;
-  }
-
-  Res (ObjectType::*mMethod)(Arg1, Arg2, Arg3, Arg4, Arg5);
-  Tin1 mArg1;
-  Tin2 mArg2;
-  Tin3 mArg3;
-  Tin4 mArg4;
-  Tin5 mArg5;
-};
-
-template <typename ObjectWrapper, typename Res,
-          typename Tin1, typename Tin2, typename Tin3,
-          typename Tin4, typename Tin5, typename Tin6,
-          typename Arg1=Tin1, typename Arg2=Tin2, typename Arg3=Tin3,
-          typename Arg4=Tin4, typename Arg5=Tin5, typename Arg6=Tin6>
-class BluetoothNotificationHALRunnable6 : public nsRunnable
-{
-public:
-  typedef typename ObjectWrapper::ObjectType  ObjectType;
-  typedef BluetoothNotificationHALRunnable6<ObjectWrapper, Res,
-    Tin1, Tin2, Tin3, Tin4, Tin5, Tin6,
-    Arg1, Arg2, Arg3, Arg4, Arg5, Arg6> SelfType;
-
-  template <typename T1, typename T2, typename T3, typename T4, typename T5,
-            typename T6>
-  static already_AddRefed<SelfType> Create(
-    Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6),
-    const T1& aIn1, const T2& aIn2, const T3& aIn3,
-    const T4& aIn4, const T5& aIn5, const T6& aIn6)
-  {
-    nsRefPtr<SelfType> runnable(new SelfType(aMethod));
-
-    if (NS_FAILED(runnable->ConvertAndSet(aIn1, aIn2, aIn3, aIn4, aIn5,
-                                          aIn6))) {
-      return nullptr;
-    }
-    return runnable.forget();
-  }
-
-  template <typename T1, typename T2, typename T3, typename T4, typename T5,
-            typename T6>
-  static void
-  Dispatch(Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6),
-           const T1& aIn1, const T2& aIn2, const T3& aIn3,
-           const T4& aIn4, const T5& aIn5, const T6& aIn6)
-  {
-    nsRefPtr<SelfType> runnable = Create(aMethod,
-                                         aIn1, aIn2, aIn3, aIn4, aIn5, aIn6);
-    if (!runnable) {
-      BT_WARNING("BluetoothNotificationHALRunnable6::Create failed");
-      return;
-    }
-    nsresult rv = NS_DispatchToMainThread(runnable);
-    if (NS_FAILED(rv)) {
-      BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-    }
-  }
-
-  NS_METHOD
-  Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    ObjectType* obj = ObjectWrapper::GetInstance();
-
-    if (!obj) {
-      BT_WARNING("Notification handler not initialized");
-    } else {
-      ((*obj).*mMethod)(mArg1, mArg2, mArg3, mArg4, mArg5, mArg6);
-    }
-    return NS_OK;
-  }
-
-private:
-  BluetoothNotificationHALRunnable6(
-    Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6))
-  : mMethod(aMethod)
-  {
-    MOZ_ASSERT(mMethod);
-  }
-
-  template<typename T1, typename T2, typename T3, typename T4, typename T5,
-           typename T6>
-  nsresult
-  ConvertAndSet(const T1& aIn1, const T2& aIn2, const T3& aIn3,
-                const T4& aIn4, const T5& aIn5, const T6& aIn6)
-  {
-    nsresult rv = Convert(aIn1, mArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn2, mArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn3, mArg3);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn4, mArg4);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn5, mArg5);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn6, mArg6);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    return NS_OK;
-  }
-
-  Res (ObjectType::*mMethod)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6);
-  Tin1 mArg1;
-  Tin2 mArg2;
-  Tin3 mArg3;
-  Tin4 mArg4;
-  Tin5 mArg5;
-  Tin6 mArg6;
-};
-
-template <typename ObjectWrapper, typename Res,
-          typename Tin1, typename Tin2, typename Tin3,
-          typename Tin4, typename Tin5, typename Tin6,
-          typename Tin7,
-          typename Arg1=Tin1, typename Arg2=Tin2, typename Arg3=Tin3,
-          typename Arg4=Tin4, typename Arg5=Tin5, typename Arg6=Tin6,
-          typename Arg7=Tin7>
-class BluetoothNotificationHALRunnable7 : public nsRunnable
-{
-public:
-  typedef typename ObjectWrapper::ObjectType  ObjectType;
-  typedef BluetoothNotificationHALRunnable7<ObjectWrapper, Res,
-    Tin1, Tin2, Tin3, Tin4, Tin5, Tin6, Tin7,
-    Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7> SelfType;
-
-  template <typename T1, typename T2, typename T3, typename T4, typename T5,
-            typename T6, typename T7>
-  static already_AddRefed<SelfType> Create(
-    Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7),
-    const T1& aIn1, const T2& aIn2, const T3& aIn3,
-    const T4& aIn4, const T5& aIn5, const T6& aIn6,
-    const T7& aIn7)
-  {
-    nsRefPtr<SelfType> runnable(new SelfType(aMethod));
-
-    if (NS_FAILED(runnable->ConvertAndSet(aIn1, aIn2, aIn3, aIn4, aIn5,
-                                          aIn6, aIn7))) {
-      return nullptr;
-    }
-    return runnable.forget();
-  }
-
-  template <typename T1, typename T2, typename T3, typename T4, typename T5,
-            typename T6, typename T7>
-  static void
-  Dispatch(Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7),
-           const T1& aIn1, const T2& aIn2, const T3& aIn3,
-           const T4& aIn4, const T5& aIn5, const T6& aIn6,
-           const T7& aIn7)
-  {
-    nsRefPtr<SelfType> runnable = Create(aMethod,
-                                         aIn1, aIn2, aIn3, aIn4, aIn5, aIn6,
-                                         aIn7);
-    if (!runnable) {
-      BT_WARNING("BluetoothNotificationHALRunnable7::Create failed");
-      return;
-    }
-    nsresult rv = NS_DispatchToMainThread(runnable);
-    if (NS_FAILED(rv)) {
-      BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-    }
-  }
-
-  NS_METHOD
-  Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    ObjectType* obj = ObjectWrapper::GetInstance();
-
-    if (!obj) {
-      BT_WARNING("Notification handler not initialized");
-    } else {
-      ((*obj).*mMethod)(mArg1, mArg2, mArg3, mArg4, mArg5, mArg6, mArg7);
-    }
-    return NS_OK;
-  }
-
-private:
-  BluetoothNotificationHALRunnable7(
-    Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7))
-  : mMethod(aMethod)
-  {
-    MOZ_ASSERT(mMethod);
-  }
-
-  template<typename T1, typename T2, typename T3, typename T4, typename T5,
-           typename T6, typename T7>
-  nsresult
-  ConvertAndSet(const T1& aIn1, const T2& aIn2, const T3& aIn3,
-                const T4& aIn4, const T5& aIn5, const T6& aIn6,
-                const T7& aIn7)
-  {
-    nsresult rv = Convert(aIn1, mArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn2, mArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn3, mArg3);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn4, mArg4);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn5, mArg5);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn6, mArg6);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn7, mArg7);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    return NS_OK;
-  }
-
-  Res (ObjectType::*mMethod)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7);
-  Tin1 mArg1;
-  Tin2 mArg2;
-  Tin3 mArg3;
-  Tin4 mArg4;
-  Tin5 mArg5;
-  Tin6 mArg6;
-  Tin7 mArg7;
-};
-
-template <typename ObjectWrapper, typename Res,
-          typename Tin1, typename Tin2, typename Tin3,
-          typename Tin4, typename Tin5, typename Tin6,
-          typename Tin7, typename Tin8, typename Tin9,
-          typename Arg1=Tin1, typename Arg2=Tin2, typename Arg3=Tin3,
-          typename Arg4=Tin4, typename Arg5=Tin5, typename Arg6=Tin6,
-          typename Arg7=Tin7, typename Arg8=Tin8, typename Arg9=Tin9>
-class BluetoothNotificationHALRunnable9 : public nsRunnable
-{
-public:
-  typedef typename ObjectWrapper::ObjectType  ObjectType;
-  typedef BluetoothNotificationHALRunnable9<ObjectWrapper, Res,
-    Tin1, Tin2, Tin3, Tin4, Tin5, Tin6, Tin7, Tin8, Tin9,
-    Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9> SelfType;
-
-  template <typename T1, typename T2, typename T3, typename T4, typename T5,
-            typename T6, typename T7, typename T8, typename T9>
-  static already_AddRefed<SelfType> Create(
-    Res (ObjectType::*aMethod)(
-      Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9),
-    const T1& aIn1, const T2& aIn2, const T3& aIn3,
-    const T4& aIn4, const T5& aIn5, const T6& aIn6,
-    const T7& aIn7, const T8& aIn8, const T9& aIn9)
-  {
-    nsRefPtr<SelfType> runnable(new SelfType(aMethod));
-
-    if (NS_FAILED(runnable->ConvertAndSet(aIn1, aIn2, aIn3, aIn4, aIn5,
-                                          aIn6, aIn7, aIn8, aIn9))) {
-      return nullptr;
-    }
-    return runnable.forget();
-  }
-
-  template <typename T1, typename T2, typename T3, typename T4, typename T5,
-            typename T6, typename T7, typename T8, typename T9>
-  static void
-  Dispatch(Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7,
-                                      Arg8, Arg9),
-           const T1& aIn1, const T2& aIn2, const T3& aIn3,
-           const T4& aIn4, const T5& aIn5, const T6& aIn6,
-           const T7& aIn7, const T8& aIn8, const T9& aIn9)
-  {
-    nsRefPtr<SelfType> runnable = Create(aMethod,
-                                         aIn1, aIn2, aIn3, aIn4, aIn5, aIn6,
-                                         aIn7, aIn8, aIn9);
-    if (!runnable) {
-      BT_WARNING("BluetoothNotificationHALRunnable8::Create failed");
-      return;
-    }
-    nsresult rv = NS_DispatchToMainThread(runnable);
-    if (NS_FAILED(rv)) {
-      BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-    }
-  }
-
-  NS_METHOD
-  Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    ObjectType* obj = ObjectWrapper::GetInstance();
-
-    if (!obj) {
-      BT_WARNING("Notification handler not initialized");
-    } else {
-      ((*obj).*mMethod)(
-        mArg1, mArg2, mArg3, mArg4, mArg5, mArg6, mArg7, mArg8, mArg9);
-    }
-    return NS_OK;
-  }
-
-private:
-  BluetoothNotificationHALRunnable9(
-    Res (ObjectType::*aMethod)(
-      Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9))
-  : mMethod(aMethod)
-  {
-    MOZ_ASSERT(mMethod);
-  }
-
-  template<typename T1, typename T2, typename T3, typename T4, typename T5,
-           typename T6, typename T7, typename T8, typename T9>
-  nsresult
-  ConvertAndSet(const T1& aIn1, const T2& aIn2, const T3& aIn3,
-                const T4& aIn4, const T5& aIn5, const T6& aIn6,
-                const T7& aIn7, const T8& aIn8, const T9& aIn9)
-  {
-    nsresult rv = Convert(aIn1, mArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn2, mArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn3, mArg3);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn4, mArg4);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn5, mArg5);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn6, mArg6);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn7, mArg7);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn8, mArg8);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = Convert(aIn9, mArg9);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    return NS_OK;
-  }
-
-  Res (ObjectType::*mMethod)(
-    Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9);
-  Tin1 mArg1;
-  Tin2 mArg2;
-  Tin3 mArg3;
-  Tin4 mArg4;
-  Tin5 mArg5;
-  Tin6 mArg6;
-  Tin7 mArg7;
-  Tin8 mArg8;
-  Tin9 mArg9;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothHALInterface.cpp
+++ /dev/null
@@ -1,1078 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "BluetoothHALInterface.h"
-#include "BluetoothHALHelpers.h"
-#include "BluetoothA2dpHALInterface.h"
-#include "BluetoothAvrcpHALInterface.h"
-#include "BluetoothGattHALInterface.h"
-#include "BluetoothHandsfreeHALInterface.h"
-#include "BluetoothSocketHALInterface.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-template<class T>
-struct interface_traits
-{ };
-
-template<>
-struct interface_traits<BluetoothSocketHALInterface>
-{
-  typedef const btsock_interface_t const_interface_type;
-
-  static const char* profile_id()
-  {
-    return BT_PROFILE_SOCKETS_ID;
-  }
-};
-
-template<>
-struct interface_traits<BluetoothHandsfreeHALInterface>
-{
-  typedef const bthf_interface_t const_interface_type;
-
-  static const char* profile_id()
-  {
-    return BT_PROFILE_HANDSFREE_ID;
-  }
-};
-
-template<>
-struct interface_traits<BluetoothA2dpHALInterface>
-{
-  typedef const btav_interface_t const_interface_type;
-
-  static const char* profile_id()
-  {
-    return BT_PROFILE_ADVANCED_AUDIO_ID;
-  }
-};
-
-#if ANDROID_VERSION >= 18
-template<>
-struct interface_traits<BluetoothAvrcpHALInterface>
-{
-  typedef const btrc_interface_t const_interface_type;
-
-  static const char* profile_id()
-  {
-    return BT_PROFILE_AV_RC_ID;
-  }
-};
-#endif
-
-#if ANDROID_VERSION >= 19
-template<>
-struct interface_traits<BluetoothGattHALInterface>
-{
-  typedef const btgatt_interface_t const_interface_type;
-
-  static const char* profile_id()
-  {
-    return BT_PROFILE_GATT_ID;
-  }
-};
-#endif
-
-typedef
-  BluetoothHALInterfaceRunnable0<BluetoothResultHandler, void>
-  BluetoothHALResultRunnable;
-
-typedef
-  BluetoothHALInterfaceRunnable1<BluetoothResultHandler, void,
-                                 BluetoothStatus, BluetoothStatus>
-  BluetoothHALErrorRunnable;
-
-static nsresult
-DispatchBluetoothHALResult(BluetoothResultHandler* aRes,
-                           void (BluetoothResultHandler::*aMethod)(),
-                           BluetoothStatus aStatus)
-{
-  MOZ_ASSERT(aRes);
-
-  nsRefPtr<nsRunnable> runnable;
-
-  if (aStatus == STATUS_SUCCESS) {
-    runnable = new BluetoothHALResultRunnable(aRes, aMethod);
-  } else {
-    runnable = new BluetoothHALErrorRunnable(
-      aRes, &BluetoothResultHandler::OnError, aStatus);
-  }
-  nsresult rv = NS_DispatchToMainThread(runnable);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-  }
-  return rv;
-}
-
-// Notification handling
-//
-
-static BluetoothNotificationHandler* sNotificationHandler;
-
-struct BluetoothCallback
-{
-  class NotificationHandlerWrapper
-  {
-  public:
-    typedef BluetoothNotificationHandler  ObjectType;
-
-    static ObjectType* GetInstance()
-    {
-      MOZ_ASSERT(NS_IsMainThread());
-
-      return sNotificationHandler;
-    }
-  };
-
-  // Notifications
-
-  typedef BluetoothNotificationHALRunnable1<NotificationHandlerWrapper, void,
-                                            bool>
-    AdapterStateChangedNotification;
-
-  typedef BluetoothNotificationHALRunnable3<NotificationHandlerWrapper, void,
-                                            BluetoothStatus, int,
-                                            nsAutoArrayPtr<BluetoothProperty>,
-                                            BluetoothStatus, int,
-                                            const BluetoothProperty*>
-    AdapterPropertiesNotification;
-
-  typedef BluetoothNotificationHALRunnable4<NotificationHandlerWrapper, void,
-                                            BluetoothStatus, nsString, int,
-                                            nsAutoArrayPtr<BluetoothProperty>,
-                                            BluetoothStatus, const nsAString&,
-                                            int, const BluetoothProperty*>
-    RemoteDevicePropertiesNotification;
-
-  typedef BluetoothNotificationHALRunnable2<NotificationHandlerWrapper, void,
-                                            int,
-                                            nsAutoArrayPtr<BluetoothProperty>,
-                                            int, const BluetoothProperty*>
-    DeviceFoundNotification;
-
-  typedef BluetoothNotificationHALRunnable1<NotificationHandlerWrapper, void,
-                                         bool>
-    DiscoveryStateChangedNotification;
-
-  typedef BluetoothNotificationHALRunnable3<NotificationHandlerWrapper, void,
-                                            nsString, nsString, uint32_t,
-                                            const nsAString&, const nsAString&>
-    PinRequestNotification;
-
-  typedef BluetoothNotificationHALRunnable5<NotificationHandlerWrapper, void,
-                                            nsString, nsString, uint32_t,
-                                            BluetoothSspVariant, uint32_t,
-                                            const nsAString&, const nsAString&>
-    SspRequestNotification;
-
-  typedef BluetoothNotificationHALRunnable3<NotificationHandlerWrapper, void,
-                                            BluetoothStatus, nsString,
-                                            BluetoothBondState,
-                                            BluetoothStatus, const nsAString&>
-    BondStateChangedNotification;
-
-  typedef BluetoothNotificationHALRunnable3<NotificationHandlerWrapper, void,
-                                            BluetoothStatus, nsString, bool,
-                                            BluetoothStatus, const nsAString&>
-    AclStateChangedNotification;
-
-  typedef BluetoothNotificationHALRunnable3<NotificationHandlerWrapper, void,
-                                            uint16_t, nsAutoArrayPtr<uint8_t>,
-                                            uint8_t, uint16_t, const uint8_t*>
-    DutModeRecvNotification;
-
-  typedef BluetoothNotificationHALRunnable2<NotificationHandlerWrapper, void,
-                                            BluetoothStatus, uint16_t>
-    LeTestModeNotification;
-
-  typedef BluetoothNotificationHALRunnable1<NotificationHandlerWrapper, void,
-                                            BluetoothActivityEnergyInfo,
-                                            const BluetoothActivityEnergyInfo&>
-    EnergyInfoNotification;
-
-  // Bluedroid callbacks
-
-  static const bt_property_t*
-  AlignedProperties(bt_property_t* aProperties, size_t aNumProperties,
-                    nsAutoArrayPtr<bt_property_t>& aPropertiesArray)
-  {
-    // See Bug 989976: consider aProperties address is not aligned. If
-    // it is aligned, we return the pointer directly; otherwise we make
-    // an aligned copy. The argument |aPropertiesArray| keeps track of
-    // the memory buffer.
-    if (!(reinterpret_cast<uintptr_t>(aProperties) % sizeof(void*))) {
-      return aProperties;
-    }
-
-    bt_property_t* properties = new bt_property_t[aNumProperties];
-    memcpy(properties, aProperties, aNumProperties * sizeof(*properties));
-    aPropertiesArray = properties;
-
-    return properties;
-  }
-
-  static void
-  AdapterStateChanged(bt_state_t aStatus)
-  {
-    AdapterStateChangedNotification::Dispatch(
-      &BluetoothNotificationHandler::AdapterStateChangedNotification,
-      aStatus);
-  }
-
-  static void
-  AdapterProperties(bt_status_t aStatus, int aNumProperties,
-                    bt_property_t* aProperties)
-  {
-    nsAutoArrayPtr<bt_property_t> propertiesArray;
-
-    AdapterPropertiesNotification::Dispatch(
-      &BluetoothNotificationHandler::AdapterPropertiesNotification,
-      ConvertDefault(aStatus, STATUS_FAIL), aNumProperties,
-      ConvertArray<bt_property_t>(
-        AlignedProperties(aProperties, aNumProperties, propertiesArray),
-      aNumProperties));
-  }
-
-  static void
-  RemoteDeviceProperties(bt_status_t aStatus, bt_bdaddr_t* aBdAddress,
-                         int aNumProperties, bt_property_t* aProperties)
-  {
-    nsAutoArrayPtr<bt_property_t> propertiesArray;
-
-    RemoteDevicePropertiesNotification::Dispatch(
-      &BluetoothNotificationHandler::RemoteDevicePropertiesNotification,
-      ConvertDefault(aStatus, STATUS_FAIL), aBdAddress, aNumProperties,
-      ConvertArray<bt_property_t>(
-        AlignedProperties(aProperties, aNumProperties, propertiesArray),
-      aNumProperties));
-  }
-
-  static void
-  DeviceFound(int aNumProperties, bt_property_t* aProperties)
-  {
-    nsAutoArrayPtr<bt_property_t> propertiesArray;
-
-    DeviceFoundNotification::Dispatch(
-      &BluetoothNotificationHandler::DeviceFoundNotification,
-      aNumProperties,
-      ConvertArray<bt_property_t>(
-        AlignedProperties(aProperties, aNumProperties, propertiesArray),
-      aNumProperties));
-  }
-
-  static void
-  DiscoveryStateChanged(bt_discovery_state_t aState)
-  {
-    DiscoveryStateChangedNotification::Dispatch(
-      &BluetoothNotificationHandler::DiscoveryStateChangedNotification,
-      aState);
-  }
-
-  static void
-  PinRequest(bt_bdaddr_t* aRemoteBdAddress,
-             bt_bdname_t* aRemoteBdName, uint32_t aRemoteClass)
-  {
-    PinRequestNotification::Dispatch(
-      &BluetoothNotificationHandler::PinRequestNotification,
-      aRemoteBdAddress, aRemoteBdName, aRemoteClass);
-  }
-
-  static void
-  SspRequest(bt_bdaddr_t* aRemoteBdAddress, bt_bdname_t* aRemoteBdName,
-             uint32_t aRemoteClass, bt_ssp_variant_t aPairingVariant,
-             uint32_t aPasskey)
-  {
-    SspRequestNotification::Dispatch(
-      &BluetoothNotificationHandler::SspRequestNotification,
-      aRemoteBdAddress, aRemoteBdName, aRemoteClass,
-      aPairingVariant, aPasskey);
-  }
-
-  static void
-  BondStateChanged(bt_status_t aStatus, bt_bdaddr_t* aRemoteBdAddress,
-                   bt_bond_state_t aState)
-  {
-    BondStateChangedNotification::Dispatch(
-      &BluetoothNotificationHandler::BondStateChangedNotification,
-      aStatus, aRemoteBdAddress, aState);
-  }
-
-  static void
-  AclStateChanged(bt_status_t aStatus, bt_bdaddr_t* aRemoteBdAddress,
-                  bt_acl_state_t aState)
-  {
-    AclStateChangedNotification::Dispatch(
-      &BluetoothNotificationHandler::AclStateChangedNotification,
-      aStatus, aRemoteBdAddress, aState);
-  }
-
-  static void
-  ThreadEvt(bt_cb_thread_evt evt)
-  {
-    // This callback maintains internal state and is not exported.
-  }
-
-  static void
-  DutModeRecv(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen)
-  {
-    DutModeRecvNotification::Dispatch(
-      &BluetoothNotificationHandler::DutModeRecvNotification,
-      aOpcode, ConvertArray<uint8_t>(aBuf, aLen), aLen);
-  }
-
-  static void
-  LeTestMode(bt_status_t aStatus, uint16_t aNumPackets)
-  {
-    LeTestModeNotification::Dispatch(
-      &BluetoothNotificationHandler::LeTestModeNotification,
-      aStatus, aNumPackets);
-  }
-
-#if ANDROID_VERSION >= 21
-  static void
-  EnergyInfo(bt_activity_energy_info* aEnergyInfo)
-  {
-    if (NS_WARN_IF(!aEnergyInfo)) {
-      return;
-    }
-
-    EnergyInfoNotification::Dispatch(
-      &BluetoothNotificationHandler::EnergyInfoNotification,
-      *aEnergyInfo);
-  }
-#endif
-};
-
-#if ANDROID_VERSION >= 21
-struct BluetoothOsCallout
-{
-  static bool
-  SetWakeAlarm(uint64_t aDelayMilliseconds,
-               bool aShouldWake,
-               void (* aAlarmCallback)(void*),
-               void* aData)
-  {
-    // FIXME: need to be implemented in later patches
-    // HAL wants to manage an wake_alarm but Gecko cannot fulfill it for now.
-    // Simply pass the request until a proper implementation has been added.
-    return true;
-  }
-
-  static int
-  AcquireWakeLock(const char* aLockName)
-  {
-    // FIXME: need to be implemented in later patches
-    // HAL wants to manage an wake_lock but Gecko cannot fulfill it for now.
-    // Simply pass the request until a proper implementation has been added.
-    return BT_STATUS_SUCCESS;
-  }
-
-  static int
-  ReleaseWakeLock(const char* aLockName)
-  {
-    // FIXME: need to be implemented in later patches
-    // HAL wants to manage an wake_lock but Gecko cannot fulfill it for now.
-    // Simply pass the request until a proper implementation has been added.
-    return BT_STATUS_SUCCESS;
-  }
-};
-#endif
-
-// 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
- */
-#define container(_t, _v, _m) \
-  ( (_t*)( ((const unsigned char*)(_v)) - offsetof(_t, _m) ) )
-
-BluetoothHALInterface*
-BluetoothHALInterface::GetInstance()
-{
-  static BluetoothHALInterface* sBluetoothInterface;
-
-  if (sBluetoothInterface) {
-    return sBluetoothInterface;
-  }
-
-  /* get driver module */
-
-  const hw_module_t* module;
-  int err = hw_get_module(BT_HARDWARE_MODULE_ID, &module);
-  if (err) {
-    BT_WARNING("hw_get_module failed: %s", strerror(err));
-    return nullptr;
-  }
-
-  /* get device */
-
-  hw_device_t* device;
-  err = module->methods->open(module, BT_HARDWARE_MODULE_ID, &device);
-  if (err) {
-    BT_WARNING("open failed: %s", strerror(err));
-    return nullptr;
-  }
-
-  const bluetooth_device_t* bt_device =
-    container(bluetooth_device_t, device, common);
-
-  /* get interface */
-
-  const bt_interface_t* bt_interface = bt_device->get_bluetooth_interface();
-  if (!bt_interface) {
-    BT_WARNING("get_bluetooth_interface failed");
-    goto err_get_bluetooth_interface;
-  }
-
-  if (bt_interface->size != sizeof(*bt_interface)) {
-    BT_WARNING("interface of incorrect size");
-    goto err_bt_interface_size;
-  }
-
-  sBluetoothInterface = new BluetoothHALInterface(bt_interface);
-
-  return sBluetoothInterface;
-
-err_bt_interface_size:
-err_get_bluetooth_interface:
-  err = device->close(device);
-  if (err) {
-    BT_WARNING("close failed: %s", strerror(err));
-  }
-  return nullptr;
-}
-
-BluetoothHALInterface::BluetoothHALInterface(
-  const bt_interface_t* aInterface)
-: mInterface(aInterface)
-{
-  MOZ_ASSERT(mInterface);
-}
-
-BluetoothHALInterface::~BluetoothHALInterface()
-{ }
-
-void
-BluetoothHALInterface::Init(
-  BluetoothNotificationHandler* aNotificationHandler,
-  BluetoothResultHandler* aRes)
-{
-  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
-#if ANDROID_VERSION >= 21
-    BluetoothCallback::EnergyInfo
-#endif
-  };
-
-#if ANDROID_VERSION >= 21
-  static bt_os_callouts_t sBluetoothOsCallouts = {
-    sizeof(sBluetoothOsCallouts),
-    BluetoothOsCallout::SetWakeAlarm,
-    BluetoothOsCallout::AcquireWakeLock,
-    BluetoothOsCallout::ReleaseWakeLock
-  };
-#endif
-
-  sNotificationHandler = aNotificationHandler;
-
-  int status = mInterface->init(&sBluetoothCallbacks);
-
-#if ANDROID_VERSION >= 21
-  if (status == BT_STATUS_SUCCESS) {
-    status = mInterface->set_os_callouts(&sBluetoothOsCallouts);
-    if (status != BT_STATUS_SUCCESS) {
-      mInterface->cleanup();
-    }
-  }
-#endif
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes, &BluetoothResultHandler::Init,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHALInterface::Cleanup(BluetoothResultHandler* aRes)
-{
-  mInterface->cleanup();
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes, &BluetoothResultHandler::Cleanup,
-                               STATUS_SUCCESS);
-  }
-
-  sNotificationHandler = nullptr;
-}
-
-void
-BluetoothHALInterface::Enable(BluetoothResultHandler* aRes)
-{
-  int status = mInterface->enable();
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes, &BluetoothResultHandler::Enable,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHALInterface::Disable(BluetoothResultHandler* aRes)
-{
-  int status = mInterface->disable();
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes, &BluetoothResultHandler::Disable,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* Adapter Properties */
-
-void
-BluetoothHALInterface::GetAdapterProperties(BluetoothResultHandler* aRes)
-{
-  int status = mInterface->get_adapter_properties();
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::GetAdapterProperties,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHALInterface::GetAdapterProperty(const nsAString& aName,
-                                          BluetoothResultHandler* aRes)
-{
-  int status;
-  bt_property_type_t type;
-
-  /* FIXME: you need to implement the missing conversion functions */
-  NS_NOTREACHED("Conversion function missing");
-
-  if (false /* TODO: we don't support any values for aName currently */) {
-    status = mInterface->get_adapter_property(type);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::GetAdapterProperties,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHALInterface::SetAdapterProperty(
-  const BluetoothNamedValue& aProperty, BluetoothResultHandler* aRes)
-{
-  int status;
-  ConvertNamedValue convertProperty(aProperty);
-  bt_property_t property;
-
-  if (NS_SUCCEEDED(Convert(convertProperty, property))) {
-    status = mInterface->set_adapter_property(&property);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::SetAdapterProperty,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* Remote Device Properties */
-
-void
-BluetoothHALInterface::GetRemoteDeviceProperties(
-  const nsAString& aRemoteAddr, BluetoothResultHandler* aRes)
-{
-  int status;
-  bt_bdaddr_t addr;
-
-  if (NS_SUCCEEDED(Convert(aRemoteAddr, addr))) {
-    status = mInterface->get_remote_device_properties(&addr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::GetRemoteDeviceProperties,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHALInterface::GetRemoteDeviceProperty(
-  const nsAString& aRemoteAddr, const nsAString& aName,
-  BluetoothResultHandler* aRes)
-{
-  int status;
-  bt_bdaddr_t remoteAddr;
-  bt_property_type_t name;
-
-  /* FIXME: you need to implement the missing conversion functions */
-  NS_NOTREACHED("Conversion function missing");
-
-  if (NS_SUCCEEDED(Convert(aRemoteAddr, remoteAddr)) &&
-      false /* TODO: we don't support any values for aName currently */) {
-    // silence uninitialized variable warning for |name|
-    name = static_cast<bt_property_type_t>(0);
-    status = mInterface->get_remote_device_property(&remoteAddr, name);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::GetRemoteDeviceProperty,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHALInterface::SetRemoteDeviceProperty(
-  const nsAString& aRemoteAddr, const BluetoothNamedValue& aProperty,
-  BluetoothResultHandler* aRes)
-{
-  int status;
-  bt_bdaddr_t remoteAddr;
-  bt_property_t property;
-
-  /* FIXME: you need to implement the missing conversion functions */
-  NS_NOTREACHED("Conversion function missing");
-
-  if (NS_SUCCEEDED(Convert(aRemoteAddr, remoteAddr)) &&
-      false /* TODO: we don't support any values for aProperty currently */) {
-    status = mInterface->set_remote_device_property(&remoteAddr, &property);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::SetRemoteDeviceProperty,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* Remote Services */
-
-void
-BluetoothHALInterface::GetRemoteServiceRecord(const nsAString& aRemoteAddr,
-                                              const uint8_t aUuid[16],
-                                              BluetoothResultHandler* aRes)
-{
-  int status;
-  bt_bdaddr_t remoteAddr;
-  bt_uuid_t uuid;
-
-  if (NS_SUCCEEDED(Convert(aRemoteAddr, remoteAddr)) &&
-      NS_SUCCEEDED(Convert(aUuid, uuid))) {
-    status = mInterface->get_remote_service_record(&remoteAddr, &uuid);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::GetRemoteServiceRecord,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHALInterface::GetRemoteServices(const nsAString& aRemoteAddr,
-                                         BluetoothResultHandler* aRes)
-{
-  int status;
-  bt_bdaddr_t remoteAddr;
-
-  if (NS_SUCCEEDED(Convert(aRemoteAddr, remoteAddr))) {
-    status = mInterface->get_remote_services(&remoteAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::GetRemoteServices,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* Discovery */
-
-void
-BluetoothHALInterface::StartDiscovery(BluetoothResultHandler* aRes)
-{
-  int status = mInterface->start_discovery();
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::StartDiscovery,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHALInterface::CancelDiscovery(BluetoothResultHandler* aRes)
-{
-  int status = mInterface->cancel_discovery();
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::CancelDiscovery,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* Bonds */
-
-void
-BluetoothHALInterface::CreateBond(const nsAString& aBdAddr,
-                                  BluetoothTransport aTransport,
-                                  BluetoothResultHandler* aRes)
-{
-  bt_bdaddr_t bdAddr;
-  int status;
-
-#if ANDROID_VERSION >= 21
-  int transport = 0; /* TRANSPORT_AUTO */
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr)) &&
-      NS_SUCCEEDED(Convert(aTransport, transport))) {
-    status = mInterface->create_bond(&bdAddr, transport);
-#else
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->create_bond(&bdAddr);
-#endif
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::CreateBond,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHALInterface::RemoveBond(const nsAString& aBdAddr,
-                                  BluetoothResultHandler* aRes)
-{
-  bt_bdaddr_t bdAddr;
-  int status;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->remove_bond(&bdAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::RemoveBond,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHALInterface::CancelBond(const nsAString& aBdAddr,
-                                  BluetoothResultHandler* aRes)
-{
-  bt_bdaddr_t bdAddr;
-  int status;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->cancel_bond(&bdAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::CancelBond,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* Connection */
-
-void
-BluetoothHALInterface::GetConnectionState(const nsAString& aBdAddr,
-                                          BluetoothResultHandler* aRes)
-{
-  int status;
-
-#if ANDROID_VERSION >= 21
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->get_connection_state(&bdAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::GetConnectionState,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* Authentication */
-
-void
-BluetoothHALInterface::PinReply(const nsAString& aBdAddr, bool aAccept,
-                                const nsAString& aPinCode,
-                                BluetoothResultHandler* aRes)
-{
-  int status;
-  bt_bdaddr_t bdAddr;
-  uint8_t accept;
-  bt_pin_code_t pinCode;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr)) &&
-      NS_SUCCEEDED(Convert(aAccept, accept)) &&
-      NS_SUCCEEDED(Convert(aPinCode, pinCode))) {
-    status = mInterface->pin_reply(&bdAddr, accept, aPinCode.Length(),
-                                   &pinCode);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::PinReply,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHALInterface::SspReply(const nsAString& aBdAddr,
-                                BluetoothSspVariant 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));
-  }
-}
-
-/* DUT Mode */
-
-void
-BluetoothHALInterface::DutModeConfigure(bool aEnable,
-                                        BluetoothResultHandler* aRes)
-{
-  int status;
-  uint8_t enable;
-
-  if (NS_SUCCEEDED(Convert(aEnable, enable))) {
-    status = mInterface->dut_mode_configure(enable);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::DutModeConfigure,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHALInterface::DutModeSend(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
-                                   BluetoothResultHandler* aRes)
-{
-  int status = mInterface->dut_mode_send(aOpcode, aBuf, aLen);
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::DutModeSend,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* LE Mode */
-
-void
-BluetoothHALInterface::LeTestMode(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
-                                  BluetoothResultHandler* aRes)
-{
-#if ANDROID_VERSION >= 18
-  int status = mInterface->le_test_mode(aOpcode, aBuf, aLen);
-#else
-  int status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::LeTestMode,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* Energy Information */
-void
-BluetoothHALInterface::ReadEnergyInfo(BluetoothResultHandler* aRes)
-{
-#if ANDROID_VERSION >= 21
-  int status = mInterface->read_energy_info();
-#else
-  int status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothHALResult(aRes,
-                               &BluetoothResultHandler::ReadEnergyInfo,
-                               ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* Profile Interfaces */
-
-template <class T>
-T*
-BluetoothHALInterface::CreateProfileInterface()
-{
-  typename interface_traits<T>::const_interface_type* interface =
-    reinterpret_cast<typename interface_traits<T>::const_interface_type*>(
-      mInterface->get_profile_interface(interface_traits<T>::profile_id()));
-
-  if (!interface) {
-    BT_WARNING("Bluetooth profile '%s' is not supported",
-               interface_traits<T>::profile_id());
-    return nullptr;
-  }
-
-  if (interface->size != sizeof(*interface)) {
-    BT_WARNING("interface of incorrect size");
-    return nullptr;
-  }
-
-  return new T(interface);
-}
-
-#if ANDROID_VERSION < 18
-/*
- * Bluedroid versions that don't support AVRCP will call this function
- * to create an AVRCP interface. All interface methods will fail with
- * the error constant STATUS_UNSUPPORTED.
- */
-template <>
-BluetoothAvrcpHALInterface*
-BluetoothHALInterface::CreateProfileInterface<BluetoothAvrcpHALInterface>()
-{
-  BT_WARNING("Bluetooth profile 'avrcp' is not supported");
-
-  return new BluetoothAvrcpHALInterface();
-}
-#endif
-
-#if ANDROID_VERSION < 19
-/*
- * Versions that we don't support GATT will call this function
- * to create an GATT interface. All interface methods will fail with
- * the error constant STATUS_UNSUPPORTED.
- */
-template <>
-BluetoothGattHALInterface*
-BluetoothHALInterface::CreateProfileInterface<BluetoothGattHALInterface>()
-{
-  BT_WARNING("Bluetooth profile 'gatt' is not supported");
-
-  return new BluetoothGattHALInterface();
-}
-#endif
-
-template <class T>
-T*
-BluetoothHALInterface::GetProfileInterface()
-{
-  static T* sBluetoothProfileInterface;
-
-  if (sBluetoothProfileInterface) {
-    return sBluetoothProfileInterface;
-  }
-
-  sBluetoothProfileInterface = CreateProfileInterface<T>();
-
-  return sBluetoothProfileInterface;
-}
-
-BluetoothSocketInterface*
-BluetoothHALInterface::GetBluetoothSocketInterface()
-{
-  return GetProfileInterface<BluetoothSocketHALInterface>();
-}
-
-BluetoothHandsfreeInterface*
-BluetoothHALInterface::GetBluetoothHandsfreeInterface()
-{
-  return GetProfileInterface<BluetoothHandsfreeHALInterface>();
-}
-
-BluetoothA2dpInterface*
-BluetoothHALInterface::GetBluetoothA2dpInterface()
-{
-  return GetProfileInterface<BluetoothA2dpHALInterface>();
-}
-
-BluetoothAvrcpInterface*
-BluetoothHALInterface::GetBluetoothAvrcpInterface()
-{
-  return GetProfileInterface<BluetoothAvrcpHALInterface>();
-}
-
-BluetoothGattInterface*
-BluetoothHALInterface::GetBluetoothGattInterface()
-{
-  return GetProfileInterface<BluetoothGattHALInterface>();
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothHALInterface.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_dom_bluetooth_bluedroid_bluetoothhalinterface_h__
-#define mozilla_dom_bluetooth_bluedroid_bluetoothhalinterface_h__
-
-#include <hardware/bluetooth.h>
-#include "BluetoothInterface.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothHALInterface final : public BluetoothInterface
-{
-public:
-  static BluetoothHALInterface* GetInstance();
-
-  void Init(BluetoothNotificationHandler* aNotificationHandler,
-            BluetoothResultHandler* aRes);
-  void Cleanup(BluetoothResultHandler* aRes);
-
-  void Enable(BluetoothResultHandler* aRes);
-  void Disable(BluetoothResultHandler* aRes);
-
-
-  /* Adapter Properties */
-
-  void GetAdapterProperties(BluetoothResultHandler* aRes);
-  void GetAdapterProperty(const nsAString& aName,
-                          BluetoothResultHandler* aRes);
-  void SetAdapterProperty(const BluetoothNamedValue& aProperty,
-                          BluetoothResultHandler* aRes);
-
-  /* Remote Device Properties */
-
-  void GetRemoteDeviceProperties(const nsAString& aRemoteAddr,
-                                 BluetoothResultHandler* aRes);
-  void GetRemoteDeviceProperty(const nsAString& aRemoteAddr,
-                               const nsAString& aName,
-                               BluetoothResultHandler* aRes);
-  void SetRemoteDeviceProperty(const nsAString& aRemoteAddr,
-                               const BluetoothNamedValue& aProperty,
-                               BluetoothResultHandler* aRes);
-
-  /* Remote Services */
-
-  void GetRemoteServiceRecord(const nsAString& aRemoteAddr,
-                              const uint8_t aUuid[16],
-                              BluetoothResultHandler* aRes);
-  void GetRemoteServices(const nsAString& aRemoteAddr,
-                         BluetoothResultHandler* aRes);
-
-  /* Discovery */
-
-  void StartDiscovery(BluetoothResultHandler* aRes);
-  void CancelDiscovery(BluetoothResultHandler* aRes);
-
-  /* Bonds */
-
-  void CreateBond(const nsAString& aBdAddr, BluetoothTransport aTransport,
-                  BluetoothResultHandler* aRes);
-  void RemoveBond(const nsAString& aBdAddr, BluetoothResultHandler* aRes);
-  void CancelBond(const nsAString& aBdAddr, BluetoothResultHandler* aRes);
-
-  /* Connection */
-
-  void GetConnectionState(const nsAString& aBdAddr,
-                          BluetoothResultHandler* aRes);
-
-  /* Authentication */
-
-  void PinReply(const nsAString& aBdAddr, bool aAccept,
-                const nsAString& aPinCode,
-                BluetoothResultHandler* aRes);
-
-  void SspReply(const nsAString& aBdAddr, BluetoothSspVariant aVariant,
-                bool aAccept, uint32_t aPasskey,
-                BluetoothResultHandler* aRes);
-
-  /* DUT Mode */
-
-  void DutModeConfigure(bool aEnable, BluetoothResultHandler* aRes);
-  void DutModeSend(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
-                   BluetoothResultHandler* aRes);
-
-  /* LE Mode */
-
-  void LeTestMode(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
-                  BluetoothResultHandler* aRes);
-
-  /* Energy Information */
-
-  void ReadEnergyInfo(BluetoothResultHandler* aRes);
-
-  /* Profile Interfaces */
-
-  BluetoothSocketInterface* GetBluetoothSocketInterface();
-  BluetoothHandsfreeInterface* GetBluetoothHandsfreeInterface();
-  BluetoothA2dpInterface* GetBluetoothA2dpInterface();
-  BluetoothAvrcpInterface* GetBluetoothAvrcpInterface();
-  BluetoothGattInterface* GetBluetoothGattInterface();
-
-protected:
-  BluetoothHALInterface(const bt_interface_t* aInterface);
-  ~BluetoothHALInterface();
-
-private:
-  template <class T>
-  T* CreateProfileInterface();
-
-  template <class T>
-  T* GetProfileInterface();
-
-  const bt_interface_t* mInterface;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothHandsfreeHALInterface.cpp
+++ /dev/null
@@ -1,957 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "BluetoothHandsfreeHALInterface.h"
-#include "BluetoothHALHelpers.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-typedef
-  BluetoothHALInterfaceRunnable0<BluetoothHandsfreeResultHandler, void>
-  BluetoothHandsfreeHALResultRunnable;
-
-typedef
-  BluetoothHALInterfaceRunnable1<BluetoothHandsfreeResultHandler, void,
-                                 BluetoothStatus, BluetoothStatus>
-  BluetoothHandsfreeHALErrorRunnable;
-
-static nsresult
-DispatchBluetoothHandsfreeHALResult(
-  BluetoothHandsfreeResultHandler* aRes,
-  void (BluetoothHandsfreeResultHandler::*aMethod)(),
-  BluetoothStatus aStatus)
-{
-  MOZ_ASSERT(aRes);
-
-  nsRefPtr<nsRunnable> runnable;
-
-  if (aStatus == STATUS_SUCCESS) {
-    runnable = new BluetoothHandsfreeHALResultRunnable(aRes, aMethod);
-  } else {
-    runnable = new BluetoothHandsfreeHALErrorRunnable(aRes,
-      &BluetoothHandsfreeResultHandler::OnError, aStatus);
-  }
-  nsresult rv = NS_DispatchToMainThread(runnable);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-  }
-  return rv;
-}
-
-// Notification handling
-//
-
-static BluetoothHandsfreeNotificationHandler* sHandsfreeNotificationHandler;
-
-struct BluetoothHandsfreeHALCallback
-{
-  class HandsfreeNotificationHandlerWrapper
-  {
-  public:
-    typedef BluetoothHandsfreeNotificationHandler ObjectType;
-
-    static ObjectType* GetInstance()
-    {
-      MOZ_ASSERT(NS_IsMainThread());
-
-      return sHandsfreeNotificationHandler;
-    }
-  };
-
-  // Notifications
-
-  typedef BluetoothNotificationHALRunnable2<
-    HandsfreeNotificationHandlerWrapper, void,
-    BluetoothHandsfreeConnectionState, nsString,
-    BluetoothHandsfreeConnectionState, const nsAString&>
-    ConnectionStateNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    HandsfreeNotificationHandlerWrapper, void,
-    BluetoothHandsfreeAudioState, nsString,
-    BluetoothHandsfreeAudioState, const nsAString&>
-    AudioStateNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    HandsfreeNotificationHandlerWrapper, void,
-    BluetoothHandsfreeVoiceRecognitionState, nsString,
-    BluetoothHandsfreeVoiceRecognitionState, const nsAString&>
-    VoiceRecognitionNotification;
-
-  typedef BluetoothNotificationHALRunnable1<
-    HandsfreeNotificationHandlerWrapper, void,
-    nsString, const nsAString&>
-    AnswerCallNotification;
-
-  typedef BluetoothNotificationHALRunnable1<
-    HandsfreeNotificationHandlerWrapper, void,
-    nsString, const nsAString&>
-    HangupCallNotification;
-
-  typedef BluetoothNotificationHALRunnable3<
-    HandsfreeNotificationHandlerWrapper, void,
-    BluetoothHandsfreeVolumeType, int, nsString,
-    BluetoothHandsfreeVolumeType, int, const nsAString&>
-    VolumeNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    HandsfreeNotificationHandlerWrapper, void,
-    nsString, nsString, const nsAString&, const nsAString&>
-    DialCallNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    HandsfreeNotificationHandlerWrapper, void,
-    char, nsString, char, const nsAString&>
-    DtmfNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    HandsfreeNotificationHandlerWrapper, void,
-    BluetoothHandsfreeNRECState, nsString,
-    BluetoothHandsfreeNRECState, const nsAString&>
-    NRECNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    HandsfreeNotificationHandlerWrapper, void,
-    BluetoothHandsfreeWbsConfig, nsString,
-    BluetoothHandsfreeWbsConfig, const nsAString&>
-    WbsNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    HandsfreeNotificationHandlerWrapper, void,
-    BluetoothHandsfreeCallHoldType, nsString,
-    BluetoothHandsfreeCallHoldType, const nsAString&>
-    CallHoldNotification;
-
-  typedef BluetoothNotificationHALRunnable1<
-    HandsfreeNotificationHandlerWrapper, void,
-    nsString, const nsAString&>
-    CnumNotification;
-
-  typedef BluetoothNotificationHALRunnable1<
-    HandsfreeNotificationHandlerWrapper, void,
-    nsString, const nsAString&>
-    CindNotification;
-
-  typedef BluetoothNotificationHALRunnable1<
-    HandsfreeNotificationHandlerWrapper, void,
-    nsString, const nsAString&>
-    CopsNotification;
-
-  typedef BluetoothNotificationHALRunnable1<
-    HandsfreeNotificationHandlerWrapper, void,
-    nsString, const nsAString&>
-    ClccNotification;
-
-  typedef BluetoothNotificationHALRunnable2<
-    HandsfreeNotificationHandlerWrapper, void,
-    nsCString, nsString, const nsACString&, const nsAString&>
-    UnknownAtNotification;
-
-  typedef BluetoothNotificationHALRunnable1<
-    HandsfreeNotificationHandlerWrapper, void,
-    nsString, const nsAString&>
-    KeyPressedNotification;
-
-  // Bluedroid Handsfree callbacks
-
-  static void
-  ConnectionState(bthf_connection_state_t aState, bt_bdaddr_t* aBdAddr)
-  {
-#if ANDROID_VERSION < 21
-    if (aState == BTHF_CONNECTION_STATE_CONNECTED && aBdAddr) {
-      memcpy(&sConnectedDeviceAddress, aBdAddr,
-             sizeof(sConnectedDeviceAddress));
-    } else if (aState == BTHF_CONNECTION_STATE_DISCONNECTED) {
-      memset(&sConnectedDeviceAddress, 0,
-             sizeof(sConnectedDeviceAddress));
-    }
-#endif
-
-    ConnectionStateNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::ConnectionStateNotification,
-      aState, aBdAddr);
-  }
-
-  static void
-  AudioState(bthf_audio_state_t aState, bt_bdaddr_t* aBdAddr)
-  {
-    AudioStateNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::AudioStateNotification,
-      aState, aBdAddr);
-  }
-
-#if ANDROID_VERSION >= 21
-  static void
-  VoiceRecognition(bthf_vr_state_t aState, bt_bdaddr_t* aBdAddr)
-  {
-    VoiceRecognitionNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::VoiceRecognitionNotification,
-      aState, aBdAddr);
-  }
-#else
-  static void
-  VoiceRecognition(bthf_vr_state_t aState)
-  {
-    VoiceRecognitionNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::VoiceRecognitionNotification,
-      aState, &sConnectedDeviceAddress);
-  }
-#endif
-
-#if ANDROID_VERSION >= 21
-  static void
-  AnswerCall(bt_bdaddr_t* aBdAddr)
-  {
-    AnswerCallNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::AnswerCallNotification,
-      aBdAddr);
-  }
-#else
-  static void
-  AnswerCall()
-  {
-    AnswerCallNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::AnswerCallNotification,
-      &sConnectedDeviceAddress);
-  }
-#endif
-
-#if ANDROID_VERSION >= 21
-  static void
-  HangupCall(bt_bdaddr_t* aBdAddr)
-  {
-    HangupCallNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::HangupCallNotification,
-      aBdAddr);
-  }
-#else
-  static void
-  HangupCall()
-  {
-    HangupCallNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::HangupCallNotification,
-      &sConnectedDeviceAddress);
-  }
-#endif
-
-#if ANDROID_VERSION >= 21
-  static void
-  Volume(bthf_volume_type_t aType, int aVolume, bt_bdaddr_t* aBdAddr)
-  {
-    VolumeNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::VolumeNotification,
-      aType, aVolume, aBdAddr);
-  }
-#else
-  static void
-  Volume(bthf_volume_type_t aType, int aVolume)
-  {
-    VolumeNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::VolumeNotification,
-      aType, aVolume, &sConnectedDeviceAddress);
-  }
-#endif
-
-#if ANDROID_VERSION >= 21
-  static void
-  DialCall(char* aNumber, bt_bdaddr_t* aBdAddr)
-  {
-    DialCallNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::DialCallNotification,
-      aNumber, aBdAddr);
-  }
-#else
-  static void
-  DialCall(char* aNumber)
-  {
-    DialCallNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::DialCallNotification,
-      aNumber, &sConnectedDeviceAddress);
-  }
-#endif
-
-#if ANDROID_VERSION >= 21
-  static void
-  Dtmf(char aDtmf, bt_bdaddr_t* aBdAddr)
-  {
-    DtmfNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::DtmfNotification,
-      aDtmf, aBdAddr);
-  }
-#else
-  static void
-  Dtmf(char aDtmf)
-  {
-    DtmfNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::DtmfNotification,
-      aDtmf, &sConnectedDeviceAddress);
-  }
-#endif
-
-#if ANDROID_VERSION >= 21
-  static void
-  NoiseReductionEchoCancellation(bthf_nrec_t aNrec, bt_bdaddr_t* aBdAddr)
-  {
-    NRECNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::NRECNotification,
-      aNrec, aBdAddr);
-  }
-#else
-  static void
-  NoiseReductionEchoCancellation(bthf_nrec_t aNrec)
-  {
-    NRECNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::NRECNotification,
-      aNrec, &sConnectedDeviceAddress);
-  }
-#endif
-
-#if ANDROID_VERSION >= 21
-  static void
-  WideBandSpeech(bthf_wbs_config_t aWbs, bt_bdaddr_t* aBdAddr)
-  {
-    WbsNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::WbsNotification,
-      aWbs, aBdAddr);
-  }
-#endif
-
-#if ANDROID_VERSION >= 21
-  static void
-  CallHold(bthf_chld_type_t aChld, bt_bdaddr_t* aBdAddr)
-  {
-    CallHoldNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::CallHoldNotification,
-      aChld, aBdAddr);
-  }
-#else
-  static void
-  CallHold(bthf_chld_type_t aChld)
-  {
-    CallHoldNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::CallHoldNotification,
-      aChld, &sConnectedDeviceAddress);
-  }
-#endif
-
-#if ANDROID_VERSION >= 21
-  static void
-  Cnum(bt_bdaddr_t* aBdAddr)
-  {
-    CnumNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::CnumNotification,
-      aBdAddr);
-  }
-#else
-  static void
-  Cnum()
-  {
-    CnumNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::CnumNotification,
-      &sConnectedDeviceAddress);
-  }
-#endif
-
-#if ANDROID_VERSION >= 21
-  static void
-  Cind(bt_bdaddr_t* aBdAddr)
-  {
-    CindNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::CindNotification,
-      aBdAddr);
-  }
-#else
-  static void
-  Cind()
-  {
-    CindNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::CindNotification,
-      &sConnectedDeviceAddress);
-  }
-#endif
-
-#if ANDROID_VERSION >= 21
-  static void
-  Cops(bt_bdaddr_t* aBdAddr)
-  {
-    CopsNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::CopsNotification,
-      aBdAddr);
-  }
-#else
-  static void
-  Cops()
-  {
-    CopsNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::CopsNotification,
-      &sConnectedDeviceAddress);
-  }
-#endif
-
-#if ANDROID_VERSION >= 21
-  static void
-  Clcc(bt_bdaddr_t* aBdAddr)
-  {
-    ClccNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::ClccNotification,
-      aBdAddr);
-  }
-#else
-  static void
-  Clcc()
-  {
-    ClccNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::ClccNotification,
-      &sConnectedDeviceAddress);
-  }
-#endif
-
-#if ANDROID_VERSION >= 21
-  static void
-  UnknownAt(char* aAtString, bt_bdaddr_t* aBdAddr)
-  {
-    UnknownAtNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::UnknownAtNotification,
-      aAtString, aBdAddr);
-  }
-#else
-  static void
-  UnknownAt(char* aAtString)
-  {
-    UnknownAtNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::UnknownAtNotification,
-      aAtString, &sConnectedDeviceAddress);
-  }
-#endif
-
-#if ANDROID_VERSION >= 21
-  static void
-  KeyPressed(bt_bdaddr_t* aBdAddr)
-  {
-    KeyPressedNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::KeyPressedNotification,
-      aBdAddr);
-  }
-#else
-  static void
-  KeyPressed()
-  {
-    KeyPressedNotification::Dispatch(
-      &BluetoothHandsfreeNotificationHandler::KeyPressedNotification,
-      &sConnectedDeviceAddress);
-  }
-#endif
-
-#if ANDROID_VERSION < 21
-  /* |sConnectedDeviceAddress| stores Bluetooth device address of the
-  * connected device. Before Android Lollipop, we maintain this address by
-  * ourselves through ConnectionState(); after Android Lollipop, every callback
-  * carries this address directly so we don't have to keep it.
-  */
-  static bt_bdaddr_t sConnectedDeviceAddress;
-#endif
-};
-
-#if ANDROID_VERSION < 21
-bt_bdaddr_t BluetoothHandsfreeHALCallback::sConnectedDeviceAddress = {
-  {0, 0, 0, 0, 0, 0}
-};
-#endif
-
-// Interface
-//
-
-BluetoothHandsfreeHALInterface::BluetoothHandsfreeHALInterface(
-  const bthf_interface_t* aInterface)
-: mInterface(aInterface)
-{
-  MOZ_ASSERT(mInterface);
-}
-
-BluetoothHandsfreeHALInterface::~BluetoothHandsfreeHALInterface()
-{ }
-
-void
-BluetoothHandsfreeHALInterface::Init(
-  BluetoothHandsfreeNotificationHandler* aNotificationHandler,
-  int aMaxNumClients, BluetoothHandsfreeResultHandler* aRes)
-{
-  static bthf_callbacks_t sCallbacks = {
-    sizeof(sCallbacks),
-    BluetoothHandsfreeHALCallback::ConnectionState,
-    BluetoothHandsfreeHALCallback::AudioState,
-    BluetoothHandsfreeHALCallback::VoiceRecognition,
-    BluetoothHandsfreeHALCallback::AnswerCall,
-    BluetoothHandsfreeHALCallback::HangupCall,
-    BluetoothHandsfreeHALCallback::Volume,
-    BluetoothHandsfreeHALCallback::DialCall,
-    BluetoothHandsfreeHALCallback::Dtmf,
-    BluetoothHandsfreeHALCallback::NoiseReductionEchoCancellation,
-#if ANDROID_VERSION >= 21
-    BluetoothHandsfreeHALCallback::WideBandSpeech,
-#endif
-    BluetoothHandsfreeHALCallback::CallHold,
-    BluetoothHandsfreeHALCallback::Cnum,
-    BluetoothHandsfreeHALCallback::Cind,
-    BluetoothHandsfreeHALCallback::Cops,
-    BluetoothHandsfreeHALCallback::Clcc,
-    BluetoothHandsfreeHALCallback::UnknownAt,
-    BluetoothHandsfreeHALCallback::KeyPressed
-  };
-
-  sHandsfreeNotificationHandler = aNotificationHandler;
-
-#if ANDROID_VERSION >= 21
-  bt_status_t status = mInterface->init(&sCallbacks, aMaxNumClients);
-#else
-  bt_status_t status = mInterface->init(&sCallbacks);
-#endif
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::Init,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHandsfreeHALInterface::Cleanup(
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  mInterface->cleanup();
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::Cleanup, STATUS_SUCCESS);
-  }
-}
-
-/* Connect / Disconnect */
-
-void
-BluetoothHandsfreeHALInterface::Connect(
-  const nsAString& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  bt_status_t status;
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->connect(&bdAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::Connect,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHandsfreeHALInterface::Disconnect(
-  const nsAString& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  bt_status_t status;
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->disconnect(&bdAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::Disconnect,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHandsfreeHALInterface::ConnectAudio(
-  const nsAString& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  bt_status_t status;
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->connect_audio(&bdAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::ConnectAudio,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHandsfreeHALInterface::DisconnectAudio(
-  const nsAString& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  bt_status_t status;
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->disconnect_audio(&bdAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::DisconnectAudio,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* Voice Recognition */
-
-void
-BluetoothHandsfreeHALInterface::StartVoiceRecognition(
-  const nsAString& aBdAddr,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  bt_status_t status;
-
-#if ANDROID_VERSION >= 21
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->start_voice_recognition(&bdAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = mInterface->start_voice_recognition();
-#endif
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::StartVoiceRecognition,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHandsfreeHALInterface::StopVoiceRecognition(
-  const nsAString& aBdAddr,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  bt_status_t status;
-
-#if ANDROID_VERSION >= 21
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->stop_voice_recognition(&bdAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = mInterface->stop_voice_recognition();
-#endif
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::StopVoiceRecognition,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* Volume */
-
-void
-BluetoothHandsfreeHALInterface::VolumeControl(
-  BluetoothHandsfreeVolumeType aType, int aVolume, const nsAString& aBdAddr,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  bt_status_t status;
-  bthf_volume_type_t type = BTHF_VOLUME_TYPE_SPK;
-
-#if ANDROID_VERSION >= 21
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aType, type)) &&
-      NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->volume_control(type, aVolume, &bdAddr);
-#else
-  if (NS_SUCCEEDED(Convert(aType, type))) {
-    status = mInterface->volume_control(type, aVolume);
-#endif
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::VolumeControl,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* Device status */
-
-void
-BluetoothHandsfreeHALInterface::DeviceStatusNotification(
-  BluetoothHandsfreeNetworkState aNtkState,
-  BluetoothHandsfreeServiceType aSvcType, int aSignal,
-  int aBattChg, BluetoothHandsfreeResultHandler* aRes)
-{
-  bt_status_t status;
-  bthf_network_state_t ntkState = BTHF_NETWORK_STATE_NOT_AVAILABLE;
-  bthf_service_type_t svcType = BTHF_SERVICE_TYPE_HOME;
-
-  if (NS_SUCCEEDED(Convert(aNtkState, ntkState)) &&
-      NS_SUCCEEDED(Convert(aSvcType, svcType))) {
-    status = mInterface->device_status_notification(ntkState, svcType,
-                                                    aSignal, aBattChg);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::DeviceStatusNotification,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* Responses */
-
-void
-BluetoothHandsfreeHALInterface::CopsResponse(
-  const char* aCops, const nsAString& aBdAddr,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  bt_status_t status;
-
-#if ANDROID_VERSION >= 21
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->cops_response(aCops, &bdAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = mInterface->cops_response(aCops);
-#endif
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::CopsResponse,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHandsfreeHALInterface::CindResponse(
-  int aSvc, int aNumActive, int aNumHeld,
-  BluetoothHandsfreeCallState aCallSetupState,
-  int aSignal, int aRoam, int aBattChg,
-  const nsAString& aBdAddr,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  bt_status_t status;
-  bthf_call_state_t callSetupState = BTHF_CALL_STATE_ACTIVE;
-
-#if ANDROID_VERSION >= 21
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aCallSetupState, callSetupState)) &&
-      NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->cind_response(aSvc, aNumActive, aNumHeld,
-                                       callSetupState, aSignal,
-                                       aRoam, aBattChg, &bdAddr);
-#else
-  if (NS_SUCCEEDED(Convert(aCallSetupState, callSetupState))) {
-    status = mInterface->cind_response(aSvc, aNumActive, aNumHeld,
-                                       callSetupState, aSignal,
-                                       aRoam, aBattChg);
-#endif
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::CindResponse,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHandsfreeHALInterface::FormattedAtResponse(
-  const char* aRsp, const nsAString& aBdAddr,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  bt_status_t status;
-
-#if ANDROID_VERSION >= 21
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->formatted_at_response(aRsp, &bdAddr);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = mInterface->formatted_at_response(aRsp);
-#endif
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::FormattedAtResponse,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHandsfreeHALInterface::AtResponse(
-  BluetoothHandsfreeAtResponse aResponseCode, int aErrorCode,
-  const nsAString& aBdAddr,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  bt_status_t status;
-  bthf_at_response_t responseCode = BTHF_AT_RESPONSE_ERROR;
-
-#if ANDROID_VERSION >= 21
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aResponseCode, responseCode)) &&
-      NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->at_response(responseCode, aErrorCode, &bdAddr);
-#else
-  if (NS_SUCCEEDED(Convert(aResponseCode, responseCode))) {
-    status = mInterface->at_response(responseCode, aErrorCode);
-#endif
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::AtResponse,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-void
-BluetoothHandsfreeHALInterface::ClccResponse(
-  int aIndex,
-  BluetoothHandsfreeCallDirection aDir,
-  BluetoothHandsfreeCallState aState,
-  BluetoothHandsfreeCallMode aMode,
-  BluetoothHandsfreeCallMptyType aMpty,
-  const nsAString& aNumber,
-  BluetoothHandsfreeCallAddressType aType,
-  const nsAString& aBdAddr,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  bt_status_t status;
-  bthf_call_direction_t dir = BTHF_CALL_DIRECTION_OUTGOING;
-  bthf_call_state_t state = BTHF_CALL_STATE_ACTIVE;
-  bthf_call_mode_t mode = BTHF_CALL_TYPE_VOICE;
-  bthf_call_mpty_type_t mpty = BTHF_CALL_MPTY_TYPE_SINGLE;
-  bthf_call_addrtype_t type = BTHF_CALL_ADDRTYPE_UNKNOWN;
-
-#if ANDROID_VERSION >= 21
-  bt_bdaddr_t bdAddr;
-
-  if (NS_SUCCEEDED(Convert(aDir, dir)) &&
-      NS_SUCCEEDED(Convert(aState, state)) &&
-      NS_SUCCEEDED(Convert(aMode, mode)) &&
-      NS_SUCCEEDED(Convert(aMpty, mpty)) &&
-      NS_SUCCEEDED(Convert(aType, type)) &&
-      NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
-    status = mInterface->clcc_response(aIndex, dir, state, mode, mpty,
-                                       NS_ConvertUTF16toUTF8(aNumber).get(),
-                                       type, &bdAddr);
-#else
-  if (NS_SUCCEEDED(Convert(aDir, dir)) &&
-      NS_SUCCEEDED(Convert(aState, state)) &&
-      NS_SUCCEEDED(Convert(aMode, mode)) &&
-      NS_SUCCEEDED(Convert(aMpty, mpty)) &&
-      NS_SUCCEEDED(Convert(aType, type))) {
-    status = mInterface->clcc_response(aIndex, dir, state, mode, mpty,
-                                       NS_ConvertUTF16toUTF8(aNumber).get(),
-                                       type);
-#endif
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::ClccResponse,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* Phone State */
-
-void
-BluetoothHandsfreeHALInterface::PhoneStateChange(int aNumActive, int aNumHeld,
-  BluetoothHandsfreeCallState aCallSetupState, const nsAString& aNumber,
-  BluetoothHandsfreeCallAddressType aType,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  bt_status_t status;
-  bthf_call_state_t callSetupState = BTHF_CALL_STATE_ACTIVE;
-  bthf_call_addrtype_t type = BTHF_CALL_ADDRTYPE_UNKNOWN;
-
-  if (NS_SUCCEEDED(Convert(aCallSetupState, callSetupState)) &&
-      NS_SUCCEEDED(Convert(aType, type))) {
-    status = mInterface->phone_state_change(
-      aNumActive, aNumHeld, callSetupState,
-      NS_ConvertUTF16toUTF8(aNumber).get(), type);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::PhoneStateChange,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* Wide Band Speech */
-
-void
-BluetoothHandsfreeHALInterface::ConfigureWbs(
-  const nsAString& aBdAddr,
-  BluetoothHandsfreeWbsConfig aConfig,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  bt_status_t status;
-
-#if ANDROID_VERSION >= 21
-  bt_bdaddr_t bdAddr;
-  bthf_wbs_config_t wbsConfig;
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr)) &&
-      NS_SUCCEEDED(Convert(aConfig, wbsConfig))) {
-    status = mInterface->configure_wbs(&bdAddr, wbsConfig);
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-#else
-  status = BT_STATUS_UNSUPPORTED;
-#endif
-
-  if (aRes) {
-    DispatchBluetoothHandsfreeHALResult(
-      aRes, &BluetoothHandsfreeResultHandler::ConfigureWbs,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothHandsfreeHALInterface.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_dom_bluetooth_bluedroid_bluetoothhandsfreehalinterface_h__
-#define mozilla_dom_bluetooth_bluedroid_bluetoothhandsfreehalinterface_h__
-
-#include <hardware/bluetooth.h>
-#include <hardware/bt_hf.h>
-#include "BluetoothCommon.h"
-#include "BluetoothInterface.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothHALInterface;
-
-class BluetoothHandsfreeHALInterface final
-  : public BluetoothHandsfreeInterface
-{
-public:
-  friend class BluetoothHALInterface;
-
-  void Init(BluetoothHandsfreeNotificationHandler* aNotificationHandler,
-            int aMaxNumClients,
-            BluetoothHandsfreeResultHandler* aRes);
-  void Cleanup(BluetoothHandsfreeResultHandler* aRes);
-
-  /* Connect / Disconnect */
-
-  void Connect(const nsAString& aBdAddr,
-               BluetoothHandsfreeResultHandler* aRes);
-  void Disconnect(const nsAString& aBdAddr,
-                  BluetoothHandsfreeResultHandler* aRes);
-  void ConnectAudio(const nsAString& aBdAddr,
-                    BluetoothHandsfreeResultHandler* aRes);
-  void DisconnectAudio(const nsAString& aBdAddr,
-                       BluetoothHandsfreeResultHandler* aRes);
-
-  /* Voice Recognition */
-
-  void StartVoiceRecognition(const nsAString& aBdAddr,
-                             BluetoothHandsfreeResultHandler* aRes);
-  void StopVoiceRecognition(const nsAString& aBdAddr,
-                            BluetoothHandsfreeResultHandler* aRes);
-
-  /* Volume */
-
-  void VolumeControl(BluetoothHandsfreeVolumeType aType, int aVolume,
-                     const nsAString& aBdAddr,
-                     BluetoothHandsfreeResultHandler* aRes);
-
-  /* Device status */
-
-  void DeviceStatusNotification(BluetoothHandsfreeNetworkState aNtkState,
-                                BluetoothHandsfreeServiceType aSvcType,
-                                int aSignal, int aBattChg,
-                                BluetoothHandsfreeResultHandler* aRes);
-
-  /* Responses */
-
-  void CopsResponse(const char* aCops, const nsAString& aBdAddr,
-                    BluetoothHandsfreeResultHandler* aRes);
-  void CindResponse(int aSvc, int aNumActive, int aNumHeld,
-                    BluetoothHandsfreeCallState aCallSetupState, int aSignal,
-                    int aRoam, int aBattChg, const nsAString& aBdAddr,
-                    BluetoothHandsfreeResultHandler* aRes);
-  void FormattedAtResponse(const char* aRsp, const nsAString& aBdAddr,
-                           BluetoothHandsfreeResultHandler* aRes);
-  void AtResponse(BluetoothHandsfreeAtResponse aResponseCode, int aErrorCode,
-                  const nsAString& aBdAddr,
-                  BluetoothHandsfreeResultHandler* aRes);
-  void ClccResponse(int aIndex, BluetoothHandsfreeCallDirection aDir,
-                    BluetoothHandsfreeCallState aState,
-                    BluetoothHandsfreeCallMode aMode,
-                    BluetoothHandsfreeCallMptyType aMpty,
-                    const nsAString& aNumber,
-                    BluetoothHandsfreeCallAddressType aType,
-                    const nsAString& aBdAddr,
-                    BluetoothHandsfreeResultHandler* aRes);
-
-  /* Phone State */
-
-  void PhoneStateChange(int aNumActive, int aNumHeld,
-                        BluetoothHandsfreeCallState aCallSetupState,
-                        const nsAString& aNumber,
-                        BluetoothHandsfreeCallAddressType aType,
-                        BluetoothHandsfreeResultHandler* aRes);
-
-  /* Wide Band Speech */
-
-  void ConfigureWbs(const nsAString& aBdAddr,
-                    BluetoothHandsfreeWbsConfig aConfig,
-                    BluetoothHandsfreeResultHandler* aRes);
-
-protected:
-  BluetoothHandsfreeHALInterface(const bthf_interface_t* aInterface);
-  ~BluetoothHandsfreeHALInterface();
-
-private:
-  const bthf_interface_t* mInterface;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothSocketHALInterface.cpp
+++ /dev/null
@@ -1,243 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "BluetoothSocketHALInterface.h"
-#include "BluetoothHALHelpers.h"
-#include "BluetoothSocketMessageWatcher.h"
-#include "mozilla/FileUtils.h"
-#include "nsClassHashtable.h"
-#include "nsXULAppAPI.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-typedef
-  BluetoothHALInterfaceRunnable1<BluetoothSocketResultHandler, void,
-                                 int, int>
-  BluetoothSocketHALIntResultRunnable;
-
-typedef
-  BluetoothHALInterfaceRunnable3<BluetoothSocketResultHandler, void,
-                                 int, const nsString, int,
-                                 int, const nsAString_internal&, int>
-  BluetoothSocketHALIntStringIntResultRunnable;
-
-typedef
-  BluetoothHALInterfaceRunnable1<BluetoothSocketResultHandler, void,
-                                 BluetoothStatus, BluetoothStatus>
-  BluetoothSocketHALErrorRunnable;
-
-static nsresult
-DispatchBluetoothSocketHALResult(
-  BluetoothSocketResultHandler* aRes,
-  void (BluetoothSocketResultHandler::*aMethod)(int), int aArg,
-  BluetoothStatus aStatus)
-{
-  MOZ_ASSERT(aRes);
-
-  nsRefPtr<nsRunnable> runnable;
-
-  if (aStatus == STATUS_SUCCESS) {
-    runnable = new BluetoothSocketHALIntResultRunnable(aRes, aMethod, aArg);
-  } else {
-    runnable = new BluetoothSocketHALErrorRunnable(aRes,
-      &BluetoothSocketResultHandler::OnError, aStatus);
-  }
-  nsresult rv = NS_DispatchToMainThread(runnable);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-  }
-  return rv;
-}
-
-static nsresult
-DispatchBluetoothSocketHALResult(
-  BluetoothSocketResultHandler* aRes,
-  void (BluetoothSocketResultHandler::*aMethod)(int, const nsAString&, int),
-  int aArg1, const nsAString& aArg2, int aArg3, BluetoothStatus aStatus)
-{
-  MOZ_ASSERT(aRes);
-
-  nsRefPtr<nsRunnable> runnable;
-
-  if (aStatus == STATUS_SUCCESS) {
-    runnable = new BluetoothSocketHALIntStringIntResultRunnable(
-      aRes, aMethod, aArg1, aArg2, aArg3);
-  } else {
-    runnable = new BluetoothSocketHALErrorRunnable(aRes,
-      &BluetoothSocketResultHandler::OnError, aStatus);
-  }
-  nsresult rv = NS_DispatchToMainThread(runnable);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
-  }
-  return rv;
-}
-
-void
-BluetoothSocketHALInterface::Listen(BluetoothSocketType aType,
-                                    const nsAString& aServiceName,
-                                    const uint8_t aServiceUuid[16],
-                                    int aChannel, bool aEncrypt,
-                                    bool aAuth,
-                                    BluetoothSocketResultHandler* aRes)
-{
-  int fd;
-  bt_status_t status;
-  btsock_type_t type = BTSOCK_RFCOMM; // silences compiler warning
-
-  if (NS_SUCCEEDED(Convert(aType, type))) {
-    status = mInterface->listen(type,
-                                NS_ConvertUTF16toUTF8(aServiceName).get(),
-                                aServiceUuid, aChannel, &fd,
-                                (BTSOCK_FLAG_ENCRYPT * aEncrypt) |
-                                (BTSOCK_FLAG_AUTH * aAuth));
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (aRes) {
-    DispatchBluetoothSocketHALResult(
-      aRes, &BluetoothSocketResultHandler::Listen, fd,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* |DeleteTask| deletes a class instance on the I/O thread
- */
-template <typename T>
-class DeleteTask final : public Task
-{
-public:
-  DeleteTask(T* aPtr)
-  : mPtr(aPtr)
-  { }
-
-  void Run() override
-  {
-    mPtr = nullptr;
-  }
-
-private:
-  nsAutoPtr<T> mPtr;
-};
-
-/* |ConnectWatcher| specializes SocketMessageWatcher for
- * connect operations by reading the socket messages from
- * Bluedroid and forwarding the connected socket to the
- * resource handler.
- */
-class BluetoothSocketHALInterface::ConnectWatcher final
-  : public SocketMessageWatcher
-{
-public:
-  ConnectWatcher(int aFd, BluetoothSocketResultHandler* aRes)
-    : SocketMessageWatcher(aFd, aRes)
-  { }
-
-  void Proceed(BluetoothStatus aStatus) override
-  {
-    DispatchBluetoothSocketHALResult(
-      GetResultHandler(), &BluetoothSocketResultHandler::Connect,
-      GetFd(), GetBdAddress(), GetConnectionStatus(), aStatus);
-
-    MessageLoopForIO::current()->PostTask(
-      FROM_HERE, new DeleteTask<ConnectWatcher>(this));
-  }
-};
-
-void
-BluetoothSocketHALInterface::Connect(const nsAString& aBdAddr,
-                                     BluetoothSocketType aType,
-                                     const uint8_t aUuid[16],
-                                     int aChannel, bool aEncrypt,
-                                     bool aAuth,
-                                     BluetoothSocketResultHandler* aRes)
-{
-  int fd;
-  bt_status_t status;
-  bt_bdaddr_t bdAddr;
-  btsock_type_t type = BTSOCK_RFCOMM; // silences compiler warning
-
-  if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr)) &&
-      NS_SUCCEEDED(Convert(aType, type))) {
-    status = mInterface->connect(&bdAddr, type, aUuid, aChannel, &fd,
-                                 (BTSOCK_FLAG_ENCRYPT * aEncrypt) |
-                                 (BTSOCK_FLAG_AUTH * aAuth));
-  } else {
-    status = BT_STATUS_PARM_INVALID;
-  }
-
-  if (status == BT_STATUS_SUCCESS) {
-    /* receive Bluedroid's socket-setup messages */
-    Task* t = new SocketMessageWatcherTask(new ConnectWatcher(fd, aRes));
-    XRE_GetIOMessageLoop()->PostTask(FROM_HERE, t);
-  } else if (aRes) {
-    DispatchBluetoothSocketHALResult(
-      aRes, &BluetoothSocketResultHandler::Connect, -1, EmptyString(), 0,
-      ConvertDefault(status, STATUS_FAIL));
-  }
-}
-
-/* |AcceptWatcher| specializes SocketMessageWatcher for Accept
- * operations by reading the socket messages from Bluedroid and
- * forwarding the received client socket to the resource handler.
- * The first message is received immediately. When there's a new
- * connection, Bluedroid sends the 2nd message with the socket
- * info and socket file descriptor.
- */
-class BluetoothSocketHALInterface::AcceptWatcher final
-  : public SocketMessageWatcher
-{
-public:
-  AcceptWatcher(int aFd, BluetoothSocketResultHandler* aRes)
-    : SocketMessageWatcher(aFd, aRes)
-  { }
-
-  void Proceed(BluetoothStatus aStatus) override
-  {
-    if ((aStatus != STATUS_SUCCESS) && (GetClientFd() != -1)) {
-      mozilla::ScopedClose(GetClientFd()); // Close received socket fd on error
-    }
-
-    DispatchBluetoothSocketHALResult(
-      GetResultHandler(), &BluetoothSocketResultHandler::Accept,
-      GetClientFd(), GetBdAddress(), GetConnectionStatus(), aStatus);
-
-    MessageLoopForIO::current()->PostTask(
-      FROM_HERE, new DeleteTask<AcceptWatcher>(this));
-  }
-};
-
-void
-BluetoothSocketHALInterface::Accept(int aFd,
-                                    BluetoothSocketResultHandler* aRes)
-{
-  /* receive Bluedroid's socket-setup messages and client fd */
-  Task* t = new SocketMessageWatcherTask(new AcceptWatcher(aFd, aRes));
-  XRE_GetIOMessageLoop()->PostTask(FROM_HERE, t);
-}
-
-void
-BluetoothSocketHALInterface::Close(BluetoothSocketResultHandler* aRes)
-{
-  MOZ_ASSERT(aRes);
-
-  /* stop the watcher corresponding to |aRes| */
-  Task* t = new DeleteSocketMessageWatcherTask(aRes);
-  XRE_GetIOMessageLoop()->PostTask(FROM_HERE, t);
-}
-
-BluetoothSocketHALInterface::BluetoothSocketHALInterface(
-  const btsock_interface_t* aInterface)
-: mInterface(aInterface)
-{
-  MOZ_ASSERT(mInterface);
-}
-
-BluetoothSocketHALInterface::~BluetoothSocketHALInterface()
-{ }
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothSocketHALInterface.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_dom_bluetooth_bluedroid_bluetoothsockethalinterface_h__
-#define mozilla_dom_bluetooth_bluedroid_bluetoothsockethalinterface_h__
-
-#include <hardware/bluetooth.h>
-#include <hardware/bt_sock.h>
-#include "BluetoothCommon.h"
-#include "BluetoothInterface.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothHALInterface;
-
-class BluetoothSocketHALInterface final
-  : public BluetoothSocketInterface
-{
-public:
-  class ConnectWatcher;
-  class AcceptWatcher;
-
-  friend class BluetoothHALInterface;
-
-  void Listen(BluetoothSocketType aType,
-              const nsAString& aServiceName,
-              const uint8_t aServiceUuid[16],
-              int aChannel, bool aEncrypt, bool aAuth,
-              BluetoothSocketResultHandler* aRes);
-
-  void Connect(const nsAString& aBdAddr,
-               BluetoothSocketType aType,
-               const uint8_t aUuid[16],
-               int aChannel, bool aEncrypt, bool aAuth,
-               BluetoothSocketResultHandler* aRes);
-
-  void Accept(int aFd, BluetoothSocketResultHandler* aRes);
-
-  void Close(BluetoothSocketResultHandler* aRes);
-
-protected:
-  BluetoothSocketHALInterface(const btsock_interface_t* aInterface);
-  ~BluetoothSocketHALInterface();
-
-private:
-  const btsock_interface_t* mInterface;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif
--- a/dom/bluetooth/bluetooth1/BluetoothService.cpp
+++ b/dom/bluetooth/bluetooth1/BluetoothService.cpp
@@ -10,17 +10,17 @@
 
 #include "BluetoothCommon.h"
 #include "BluetoothA2dpManager.h"
 #include "BluetoothHfpManager.h"
 #include "BluetoothHidManager.h"
 #include "BluetoothManager.h"
 #include "BluetoothOppManager.h"
 #include "BluetoothParent.h"
-#if defined(MOZ_B2G_BT_BLUEDROID)
+#if defined(MOZ_B2G_BT_DAEMON)
 #include "BluetoothPbapManager.h"
 #endif
 #include "BluetoothReplyRunnable.h"
 #include "BluetoothServiceChildProcess.h"
 #include "BluetoothUtils.h"
 
 #include "jsapi.h"
 #include "mozilla/ClearOnShutdown.h"
@@ -47,27 +47,20 @@
 
 #if defined(MOZ_B2G_BT)
 #if defined(MOZ_B2G_BT_BLUEZ)
 /**
  * B2G blueZ:
  *   MOZ_B2G_BT and MOZ_B2G_BT_BLUEZ are both defined.
  */
 #include "BluetoothDBusService.h"
-#elif defined(MOZ_B2G_BT_BLUEDROID)
-/**
- * B2G bluedroid:
- *   MOZ_B2G_BT and MOZ_B2G_BT_BLUEDROID are both defined;
- *   MOZ_B2G_BLUEZ or MOZ_B2G_DAEMON are not defined.
- */
-#include "BluetoothServiceBluedroid.h"
 #elif defined(MOZ_B2G_BT_DAEMON)
 /**
  * B2G Bluetooth daemon:
- *   MOZ_B2G_BT, MOZ_B2G_BLUEDROID and MOZ_B2G_BT_DAEMON are defined;
+ *   MOZ_B2G_BT and MOZ_B2G_BT_DAEMON are defined;
  *   MOZ_B2G_BLUEZ is not defined.
  */
 #include "BluetoothServiceBluedroid.h"
 #endif
 #elif defined(MOZ_BLUETOOTH_DBUS)
 /**
  * Desktop bluetooth:
  *   MOZ_B2G_BT is not defined; MOZ_BLUETOOTH_DBUS is defined.
@@ -215,18 +208,16 @@ BluetoothService::Create()
 {
 #if defined(MOZ_B2G_BT)
   if (!XRE_IsParentProcess()) {
     return BluetoothServiceChildProcess::Create();
   }
 
 #if defined(MOZ_B2G_BT_BLUEZ)
   return new BluetoothDBusService();
-#elif defined(MOZ_B2G_BT_BLUEDROID)
-  return new BluetoothServiceBluedroid();
 #elif defined(MOZ_B2G_BT_DAEMON)
   return new BluetoothServiceBluedroid();
 #endif
 #elif defined(MOZ_BLUETOOTH_DBUS)
   return new BluetoothDBusService();
 #endif
 
   BT_WARNING("No platform support for bluetooth!");
@@ -404,17 +395,17 @@ nsresult
 BluetoothService::StopBluetooth(bool aIsStartup)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   static BluetoothProfileManagerBase* sProfiles[] = {
     BluetoothHfpManager::Get(),
     BluetoothA2dpManager::Get(),
     BluetoothOppManager::Get(),
-#if defined(MOZ_B2G_BT_BLUEDROID)
+#if defined(MOZ_B2G_BT_DAEMON)
     BluetoothPbapManager::Get(),
 #endif
     BluetoothHidManager::Get()
   };
 
   // Disconnect all connected profiles
   for (uint8_t i = 0; i < MOZ_ARRAY_LENGTH(sProfiles); i++) {
     nsCString profileName;
--- a/dom/bluetooth/bluetooth2/BluetoothService.cpp
+++ b/dom/bluetooth/bluetooth2/BluetoothService.cpp
@@ -38,27 +38,20 @@
 
 #if defined(MOZ_B2G_BT)
 #if defined(MOZ_B2G_BT_BLUEZ)
 /**
  * B2G blueZ:
  *   MOZ_B2G_BT and MOZ_B2G_BT_BLUEZ are both defined.
  */
 #include "BluetoothDBusService.h"
-#elif defined(MOZ_B2G_BT_BLUEDROID)
-/**
- * B2G bluedroid:
- *   MOZ_B2G_BT and MOZ_B2G_BT_BLUEDROID are both defined;
- *   MOZ_B2G_BLUEZ or MOZ_B2G_DAEMON are not defined.
- */
-#include "BluetoothServiceBluedroid.h"
 #elif defined(MOZ_B2G_BT_DAEMON)
 /**
  * B2G Bluetooth daemon:
- *   MOZ_B2G_BT, MOZ_B2G_BLUEDROID and MOZ_B2G_BT_DAEMON are defined;
+ *   MOZ_B2G_BT and MOZ_B2G_BT_DAEMON are defined;
  *   MOZ_B2G_BLUEZ is not defined.
  */
 #include "BluetoothServiceBluedroid.h"
 #endif
 #elif defined(MOZ_BLUETOOTH_DBUS)
 /**
  * Desktop bluetooth:
  *   MOZ_B2G_BT is not defined; MOZ_BLUETOOTH_DBUS is defined.
@@ -194,18 +187,16 @@ BluetoothService::Create()
 {
 #if defined(MOZ_B2G_BT)
   if (!XRE_IsParentProcess()) {
     return BluetoothServiceChildProcess::Create();
   }
 
 #if defined(MOZ_B2G_BT_BLUEZ)
   return new BluetoothDBusService();
-#elif defined(MOZ_B2G_BT_BLUEDROID)
-  return new BluetoothServiceBluedroid();
 #elif defined(MOZ_B2G_BT_DAEMON)
   return new BluetoothServiceBluedroid();
 #endif
 #elif defined(MOZ_BLUETOOTH_DBUS)
   return new BluetoothDBusService();
 #endif
 
   BT_WARNING("No platform support for bluetooth!");
--- a/dom/bluetooth/moz.build
+++ b/dom/bluetooth/moz.build
@@ -82,39 +82,32 @@ if CONFIG['MOZ_B2G_BT']:
                 'bluez/BluetoothOppManager.cpp',
                 'bluez/BluetoothSocket.cpp',
                 'bluez/BluetoothUnixSocketConnector.cpp'
             ]
             LOCAL_INCLUDES += [
                 'bluez',
             ]
             DEFINES['MOZ_B2G_BT_BLUEZ'] = True
-        elif CONFIG['MOZ_B2G_BT_BLUEDROID']:
+        elif CONFIG['MOZ_B2G_BT_DAEMON']:
             SOURCES += [
-                'bluedroid/BluetoothA2dpHALInterface.cpp',
                 'bluedroid/BluetoothA2dpManager.cpp',
-                'bluedroid/BluetoothAvrcpHALInterface.cpp',
                 'bluedroid/BluetoothDaemonA2dpInterface.cpp',
                 'bluedroid/BluetoothDaemonAvrcpInterface.cpp',
                 'bluedroid/BluetoothDaemonConnector.cpp',
                 'bluedroid/BluetoothDaemonGattInterface.cpp',
                 'bluedroid/BluetoothDaemonHandsfreeInterface.cpp',
                 'bluedroid/BluetoothDaemonHelpers.cpp',
                 'bluedroid/BluetoothDaemonInterface.cpp',
                 'bluedroid/BluetoothDaemonSetupInterface.cpp',
                 'bluedroid/BluetoothDaemonSocketInterface.cpp',
-                'bluedroid/BluetoothGattHALInterface.cpp',
-                'bluedroid/BluetoothHALHelpers.cpp',
-                'bluedroid/BluetoothHALInterface.cpp',
-                'bluedroid/BluetoothHandsfreeHALInterface.cpp',
                 'bluedroid/BluetoothOppManager.cpp',
                 'bluedroid/BluetoothPbapManager.cpp',
                 'bluedroid/BluetoothServiceBluedroid.cpp',
                 'bluedroid/BluetoothSocket.cpp',
-                'bluedroid/BluetoothSocketHALInterface.cpp',
                 'bluedroid/BluetoothSocketMessageWatcher.cpp'
             ]
             LOCAL_INCLUDES += [
                 'bluedroid',
             ]
 
             if CONFIG['MOZ_B2G_RIL']:
                 SOURCES += [
@@ -130,19 +123,17 @@ if CONFIG['MOZ_B2G_BT']:
                 LOCAL_INCLUDES += [
                     'bluedroid/hfp-fallback',
                 ]
             if not CONFIG['MOZ_B2G_BT_API_V1']:
                 SOURCES += [
                     'bluedroid/BluetoothGattManager.cpp',
                 ]
 
-            DEFINES['MOZ_B2G_BT_BLUEDROID'] = True
-            if CONFIG['MOZ_B2G_BT_DAEMON']:
-                DEFINES['MOZ_B2G_BT_DAEMON'] = True
+            DEFINES['MOZ_B2G_BT_DAEMON'] = True
     elif CONFIG['MOZ_ENABLE_DBUS']:
         CFLAGS += CONFIG['MOZ_DBUS_CFLAGS']
         CFLAGS += CONFIG['MOZ_DBUS_GLIB_CFLAGS']
         CXXFLAGS += CONFIG['MOZ_DBUS_CFLAGS']
         CXXFLAGS += CONFIG['MOZ_DBUS_GLIB_CFLAGS']
         SOURCES += [
             'bluez/BluetoothDBusService.cpp',
             'bluez/BluetoothHfpManager.cpp',