Bug 1310020 - Remove DOM/bluetooth and related code. r?jst draft
authorMichelangelo De Simone <mdesimone@mozilla.com>
Fri, 28 Oct 2016 14:25:23 -0700
changeset 431903 7cc2b8594445b2e29e1492e480568fdcb6beec2d
parent 431855 37ab1d54a08e7e1431660b22377428b74dcd090a
child 431905 8166440527deaba25850d70200e29edbf819a68a
push id34147
push usermdesimone@mozilla.com
push dateMon, 31 Oct 2016 23:04:33 +0000
reviewersjst
bugs1310020
milestone52.0a1
Bug 1310020 - Remove DOM/bluetooth and related code. r?jst MozReview-Commit-ID: IEhwzzBgb3x
b2g/app/b2g.js
b2g/installer/package-manifest.in
browser/installer/package-manifest.in
dom/apps/PermissionsTable.jsm
dom/base/DOMException.cpp
dom/base/Navigator.cpp
dom/base/Navigator.h
dom/base/domerr.msg
dom/base/moz.build
dom/bindings/Bindings.conf
dom/bindings/Exceptions.cpp
dom/bindings/moz.build
dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp
dom/bluetooth/bluedroid/BluetoothA2dpManager.h
dom/bluetooth/bluedroid/BluetoothAvrcpManager.cpp
dom/bluetooth/bluedroid/BluetoothAvrcpManager.h
dom/bluetooth/bluedroid/BluetoothDaemonA2dpInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonA2dpInterface.h
dom/bluetooth/bluedroid/BluetoothDaemonAvrcpInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonAvrcpInterface.h
dom/bluetooth/bluedroid/BluetoothDaemonCoreInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonCoreInterface.h
dom/bluetooth/bluedroid/BluetoothDaemonGattInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonGattInterface.h
dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.h
dom/bluetooth/bluedroid/BluetoothDaemonHelpers.cpp
dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
dom/bluetooth/bluedroid/BluetoothDaemonHidInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonHidInterface.h
dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonInterface.h
dom/bluetooth/bluedroid/BluetoothDaemonSetupInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonSetupInterface.h
dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.h
dom/bluetooth/bluedroid/BluetoothGattManager.cpp
dom/bluetooth/bluedroid/BluetoothGattManager.h
dom/bluetooth/bluedroid/BluetoothHidManager.cpp
dom/bluetooth/bluedroid/BluetoothHidManager.h
dom/bluetooth/bluedroid/BluetoothMapBMessage.cpp
dom/bluetooth/bluedroid/BluetoothMapBMessage.h
dom/bluetooth/bluedroid/BluetoothMapFolder.cpp
dom/bluetooth/bluedroid/BluetoothMapFolder.h
dom/bluetooth/bluedroid/BluetoothMapSmsManager.cpp
dom/bluetooth/bluedroid/BluetoothMapSmsManager.h
dom/bluetooth/bluedroid/BluetoothOppManager.cpp
dom/bluetooth/bluedroid/BluetoothOppManager.h
dom/bluetooth/bluedroid/BluetoothPbapManager.cpp
dom/bluetooth/bluedroid/BluetoothPbapManager.h
dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
dom/bluetooth/bluedroid/BluetoothServiceBluedroid.h
dom/bluetooth/bluedroid/BluetoothSocket.cpp
dom/bluetooth/bluedroid/BluetoothSocket.h
dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.cpp
dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.h
dom/bluetooth/bluedroid/hfp-fallback/BluetoothHfpManager.cpp
dom/bluetooth/bluedroid/hfp-fallback/BluetoothHfpManager.h
dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h
dom/bluetooth/bluez/BluetoothA2dpManager.cpp
dom/bluetooth/bluez/BluetoothA2dpManager.h
dom/bluetooth/bluez/BluetoothAvrcpManager.cpp
dom/bluetooth/bluez/BluetoothAvrcpManager.h
dom/bluetooth/bluez/BluetoothDBusService.cpp
dom/bluetooth/bluez/BluetoothDBusService.h
dom/bluetooth/bluez/BluetoothHfpManager.cpp
dom/bluetooth/bluez/BluetoothHfpManager.h
dom/bluetooth/bluez/BluetoothHidManager.cpp
dom/bluetooth/bluez/BluetoothHidManager.h
dom/bluetooth/bluez/BluetoothOppManager.cpp
dom/bluetooth/bluez/BluetoothOppManager.h
dom/bluetooth/bluez/BluetoothSocket.cpp
dom/bluetooth/bluez/BluetoothSocket.h
dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp
dom/bluetooth/bluez/BluetoothUnixSocketConnector.h
dom/bluetooth/common/BluetoothCommon.cpp
dom/bluetooth/common/BluetoothCommon.h
dom/bluetooth/common/BluetoothGattReplyRunnable.cpp
dom/bluetooth/common/BluetoothGattReplyRunnable.h
dom/bluetooth/common/BluetoothGattUUIDName.h
dom/bluetooth/common/BluetoothHashKeys.h
dom/bluetooth/common/BluetoothHfpManagerBase.h
dom/bluetooth/common/BluetoothInterface.cpp
dom/bluetooth/common/BluetoothInterface.h
dom/bluetooth/common/BluetoothProfileController.cpp
dom/bluetooth/common/BluetoothProfileController.h
dom/bluetooth/common/BluetoothProfileManagerBase.h
dom/bluetooth/common/BluetoothReplyRunnable.cpp
dom/bluetooth/common/BluetoothReplyRunnable.h
dom/bluetooth/common/BluetoothRilListener.cpp
dom/bluetooth/common/BluetoothRilListener.h
dom/bluetooth/common/BluetoothService.cpp
dom/bluetooth/common/BluetoothService.h
dom/bluetooth/common/BluetoothSocketObserver.h
dom/bluetooth/common/BluetoothUtils.cpp
dom/bluetooth/common/BluetoothUtils.h
dom/bluetooth/common/BluetoothUuidHelper.cpp
dom/bluetooth/common/BluetoothUuidHelper.h
dom/bluetooth/common/ObexBase.cpp
dom/bluetooth/common/ObexBase.h
dom/bluetooth/common/webapi/BluetoothAdapter.cpp
dom/bluetooth/common/webapi/BluetoothAdapter.h
dom/bluetooth/common/webapi/BluetoothClassOfDevice.cpp
dom/bluetooth/common/webapi/BluetoothClassOfDevice.h
dom/bluetooth/common/webapi/BluetoothDevice.cpp
dom/bluetooth/common/webapi/BluetoothDevice.h
dom/bluetooth/common/webapi/BluetoothDiscoveryHandle.cpp
dom/bluetooth/common/webapi/BluetoothDiscoveryHandle.h
dom/bluetooth/common/webapi/BluetoothGatt.cpp
dom/bluetooth/common/webapi/BluetoothGatt.h
dom/bluetooth/common/webapi/BluetoothGattAttributeEvent.cpp
dom/bluetooth/common/webapi/BluetoothGattAttributeEvent.h
dom/bluetooth/common/webapi/BluetoothGattCharacteristic.cpp
dom/bluetooth/common/webapi/BluetoothGattCharacteristic.h
dom/bluetooth/common/webapi/BluetoothGattDescriptor.cpp
dom/bluetooth/common/webapi/BluetoothGattDescriptor.h
dom/bluetooth/common/webapi/BluetoothGattServer.cpp
dom/bluetooth/common/webapi/BluetoothGattServer.h
dom/bluetooth/common/webapi/BluetoothGattService.cpp
dom/bluetooth/common/webapi/BluetoothGattService.h
dom/bluetooth/common/webapi/BluetoothLeDeviceEvent.cpp
dom/bluetooth/common/webapi/BluetoothLeDeviceEvent.h
dom/bluetooth/common/webapi/BluetoothManager.cpp
dom/bluetooth/common/webapi/BluetoothManager.h
dom/bluetooth/common/webapi/BluetoothMapRequestHandle.cpp
dom/bluetooth/common/webapi/BluetoothMapRequestHandle.h
dom/bluetooth/common/webapi/BluetoothObexAuthHandle.cpp
dom/bluetooth/common/webapi/BluetoothObexAuthHandle.h
dom/bluetooth/common/webapi/BluetoothPairingHandle.cpp
dom/bluetooth/common/webapi/BluetoothPairingHandle.h
dom/bluetooth/common/webapi/BluetoothPairingListener.cpp
dom/bluetooth/common/webapi/BluetoothPairingListener.h
dom/bluetooth/common/webapi/BluetoothPbapRequestHandle.cpp
dom/bluetooth/common/webapi/BluetoothPbapRequestHandle.h
dom/bluetooth/common/webapi/BluetoothUUID.cpp
dom/bluetooth/common/webapi/BluetoothUUID.h
dom/bluetooth/ipc/BluetoothChild.cpp
dom/bluetooth/ipc/BluetoothChild.h
dom/bluetooth/ipc/BluetoothMessageUtils.h
dom/bluetooth/ipc/BluetoothParent.cpp
dom/bluetooth/ipc/BluetoothParent.h
dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
dom/bluetooth/ipc/BluetoothServiceChildProcess.h
dom/bluetooth/ipc/BluetoothTypes.ipdlh
dom/bluetooth/ipc/PBluetooth.ipdl
dom/bluetooth/ipc/PBluetoothRequest.ipdl
dom/bluetooth/moz.build
dom/bluetooth/tests/marionette/head.js
dom/bluetooth/tests/marionette/manifest.ini
dom/bluetooth/tests/marionette/test_dom_BluetoothAdapter_discovery.js
dom/bluetooth/tests/marionette/test_dom_BluetoothAdapter_enable.js
dom/bluetooth/tests/marionette/test_dom_BluetoothAdapter_pair.js
dom/bluetooth/tests/marionette/test_dom_BluetoothAdapter_setters.js
dom/bluetooth/tests/marionette/test_dom_BluetoothDevice.js
dom/bluetooth/tests/marionette/test_dom_BluetoothManager.js
dom/browser-element/moz.build
dom/events/test/test_all_synthetic_events.html
dom/ipc/ContentChild.cpp
dom/ipc/ContentChild.h
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/PContent.ipdl
dom/ipc/moz.build
dom/moz.build
dom/permission/moz.build
dom/permission/tests/mochitest-bt.ini
dom/permission/tests/test_bluetooth.html
dom/webidl/BluetoothAdapter.webidl
dom/webidl/BluetoothAdapterEvent.webidl
dom/webidl/BluetoothAttributeEvent.webidl
dom/webidl/BluetoothClassOfDevice.webidl
dom/webidl/BluetoothDevice.webidl
dom/webidl/BluetoothDeviceEvent.webidl
dom/webidl/BluetoothDiscoveryHandle.webidl
dom/webidl/BluetoothGatt.webidl
dom/webidl/BluetoothGattAttributeEvent.webidl
dom/webidl/BluetoothGattCharacteristic.webidl
dom/webidl/BluetoothGattCharacteristicEvent.webidl
dom/webidl/BluetoothGattDescriptor.webidl
dom/webidl/BluetoothGattServer.webidl
dom/webidl/BluetoothGattService.webidl
dom/webidl/BluetoothLeDeviceEvent.webidl
dom/webidl/BluetoothManager.webidl
dom/webidl/BluetoothMapFolderListingEvent.webidl
dom/webidl/BluetoothMapGetMessageEvent.webidl
dom/webidl/BluetoothMapMessageUpdateEvent.webidl
dom/webidl/BluetoothMapMessagesListingEvent.webidl
dom/webidl/BluetoothMapParameters.webidl
dom/webidl/BluetoothMapRequestHandle.webidl
dom/webidl/BluetoothMapSendMessageEvent.webidl
dom/webidl/BluetoothMapSetMessageStatusEvent.webidl
dom/webidl/BluetoothObexAuthEvent.webidl
dom/webidl/BluetoothObexAuthHandle.webidl
dom/webidl/BluetoothPairingEvent.webidl
dom/webidl/BluetoothPairingHandle.webidl
dom/webidl/BluetoothPairingListener.webidl
dom/webidl/BluetoothPbapParameters.webidl
dom/webidl/BluetoothPbapRequestHandle.webidl
dom/webidl/BluetoothPhonebookPullingEvent.webidl
dom/webidl/BluetoothStatusChangedEvent.webidl
dom/webidl/BluetoothUUID.webidl
dom/webidl/BluetoothVCardListingEvent.webidl
dom/webidl/BluetoothVCardPullingEvent.webidl
dom/webidl/Navigator.webidl
dom/webidl/moz.build
ipc/dbus/moz.build
ipc/moz.build
js/xpconnect/src/moz.build
layout/build/moz.build
layout/build/nsLayoutModule.cpp
layout/build/nsLayoutStatics.cpp
old-configure.in
testing/marionette/harness/marionette/tests/webapi-tests.ini
toolkit/library/moz.build
xpcom/base/ErrorList.h
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -995,23 +995,16 @@ pref("dom.webnotifications.serviceworker
 #endif
 
 // Retain at most 10 processes' layers buffers
 pref("layers.compositor-lru-size", 10);
 
 // In B2G by deafult any AudioChannelAgent is muted when created.
 pref("dom.audiochannel.mutedByDefault", true);
 
-// The app origin of bluetooth app, which is responsible for listening pairing
-// requests.
-pref("dom.bluetooth.app-origin", "app://bluetooth.gaiamobile.org");
-
-// Enable W3C WebBluetooth API and disable B2G only GATT client API.
-pref("dom.bluetooth.webbluetooth.enabled", false);
-
 // Default device name for Presentation API
 pref("dom.presentation.device.name", "Firefox OS");
 
 // Enable notification of performance timing
 pref("dom.performance.enable_notify_performance_timing", true);
 
 // Multi-screen
 pref("b2g.multiscreen.chrome_remote_url", "chrome://b2g/content/shell_remote.html");
--- a/b2g/installer/package-manifest.in
+++ b/b2g/installer/package-manifest.in
@@ -156,19 +156,16 @@
 @RESPATH@/components/dom_workers.xpt
 #ifdef MOZ_WIDGET_GONK
 @RESPATH@/components/dom_wifi.xpt
 @RESPATH@/components/dom_system_gonk.xpt
 #endif
 #ifdef MOZ_B2G_RIL
 @RESPATH@/components/dom_mobileconnection.xpt
 #endif
-#ifdef MOZ_B2G_BT
-@RESPATH@/components/dom_bluetooth.xpt
-#endif
 @RESPATH@/components/dom_canvas.xpt
 @RESPATH@/components/dom_contacts.xpt
 @RESPATH@/components/dom_core.xpt
 @RESPATH@/components/dom_css.xpt
 @RESPATH@/components/dom_events.xpt
 @RESPATH@/components/dom_geolocation.xpt
 @RESPATH@/components/dom_media.xpt
 @RESPATH@/components/dom_network.xpt
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -180,19 +180,16 @@
 @RESPATH@/components/cookie.xpt
 @RESPATH@/components/directory.xpt
 @RESPATH@/components/docshell.xpt
 @RESPATH@/components/dom.xpt
 @RESPATH@/components/dom_apps.xpt
 @RESPATH@/components/dom_newapps.xpt
 @RESPATH@/components/dom_base.xpt
 @RESPATH@/components/dom_system.xpt
-#ifdef MOZ_B2G_BT
-@RESPATH@/components/dom_bluetooth.xpt
-#endif
 @RESPATH@/components/dom_canvas.xpt
 @RESPATH@/components/dom_core.xpt
 @RESPATH@/components/dom_css.xpt
 @RESPATH@/components/dom_events.xpt
 @RESPATH@/components/dom_geolocation.xpt
 @RESPATH@/components/dom_media.xpt
 @RESPATH@/components/dom_network.xpt
 @RESPATH@/components/dom_notification.xpt
--- a/dom/apps/PermissionsTable.jsm
+++ b/dom/apps/PermissionsTable.jsm
@@ -131,21 +131,16 @@ this.PermissionsTable =  { geolocation: 
                              privileged: ALLOW_ACTION,
                              certified: ALLOW_ACTION
                            },
                            "browser:embedded-system-app": {
                              app: DENY_ACTION,
                              privileged: DENY_ACTION,
                              certified: ALLOW_ACTION
                            },
-                           bluetooth: {
-                             app: DENY_ACTION,
-                             privileged: DENY_ACTION,
-                             certified: ALLOW_ACTION
-                           },
                            mobileconnection: {
                              app: DENY_ACTION,
                              privileged: DENY_ACTION,
                              certified: ALLOW_ACTION
                            },
                            mobilenetwork: {
                              app: DENY_ACTION,
                              privileged: ALLOW_ACTION,
--- a/dom/base/DOMException.cpp
+++ b/dom/base/DOMException.cpp
@@ -70,29 +70,16 @@ enum DOM4ErrorTypeCodeMap {
   NotReadableError         = 0,
 
   /* FileHandle API errors */
   FileHandleInactiveError = 0,
 
   /* WebCrypto errors https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#dfn-DataError */
   OperationError           = 0,
 
-  /* Bluetooth API errors */
-  BtFailError              = 0,
-  BtNotReadyError          = 0,
-  BtNoMemError             = 0,
-  BtBusyError              = 0,
-  BtDoneError              = 0,
-  BtUnsupportedError       = 0,
-  BtParmInvalidError       = 0,
-  BtUnhandledError         = 0,
-  BtAuthFailureError       = 0,
-  BtRmtDevDownError        = 0,
-  BtAuthRejectedError      = 0,
-
   /* Push API errors */
   NotAllowedError          = 0,
 };
 
 #define DOM4_MSG_DEF(name, message, nsresult) {(nsresult), name, #name, message},
 #define DOM_MSG_DEF(val, message) {(val), NS_ERROR_GET_CODE(val), #val, message},
 
 static const struct ResultStruct
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -74,19 +74,16 @@
 #include "nsStreamUtils.h"
 #include "nsIAppsService.h"
 #include "mozIApplication.h"
 #include "WidgetUtils.h"
 #include "nsIPresentationService.h"
 
 #include "mozilla/dom/MediaDevices.h"
 #include "MediaManager.h"
-#ifdef MOZ_B2G_BT
-#include "BluetoothManager.h"
-#endif
 
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
 #include "AudioChannelManager.h"
 #endif
 
 #include "nsIDOMGlobalPropertyInitializer.h"
 #include "nsJSUtils.h"
 
@@ -216,19 +213,16 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPowerManager)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIccManager)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInputPortManager)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConnection)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStorageManager)
 #ifdef MOZ_B2G_RIL
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMobileConnections)
 #endif
-#ifdef MOZ_B2G_BT
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBluetooth)
-#endif
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAudioChannelManager)
 #endif
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaDevices)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTimeManager)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mServiceWorkerContainer)
 
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
@@ -299,22 +293,16 @@ Navigator::Invalidate()
   }
 
 #ifdef MOZ_B2G_RIL
   if (mMobileConnections) {
     mMobileConnections = nullptr;
   }
 #endif
 
-#ifdef MOZ_B2G_BT
-  if (mBluetooth) {
-    mBluetooth = nullptr;
-  }
-#endif
-
   mMediaDevices = nullptr;
 
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
   if (mAudioChannelManager) {
     mAudioChannelManager = nullptr;
   }
 #endif
 
@@ -1795,32 +1783,16 @@ Navigator::GetConnection(ErrorResult& aR
       return nullptr;
     }
     mConnection = new network::Connection(mWindow);
   }
 
   return mConnection;
 }
 
-#ifdef MOZ_B2G_BT
-bluetooth::BluetoothManager*
-Navigator::GetMozBluetooth(ErrorResult& aRv)
-{
-  if (!mBluetooth) {
-    if (!mWindow) {
-      aRv.Throw(NS_ERROR_UNEXPECTED);
-      return nullptr;
-    }
-    mBluetooth = bluetooth::BluetoothManager::Create(mWindow);
-  }
-
-  return mBluetooth;
-}
-#endif //MOZ_B2G_BT
-
 #ifdef MOZ_TIME_MANAGER
 time::TimeManager*
 Navigator::GetMozTime(ErrorResult& aRv)
 {
   if (!mWindow) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return nullptr;
   }
--- a/dom/base/Navigator.h
+++ b/dom/base/Navigator.h
@@ -67,22 +67,16 @@ class GamepadServiceTest;
 class NavigatorUserMediaSuccessCallback;
 class NavigatorUserMediaErrorCallback;
 class MozGetUserMediaDevicesSuccessCallback;
 
 namespace network {
 class Connection;
 } // namespace network
 
-#ifdef MOZ_B2G_BT
-namespace bluetooth {
-class BluetoothManager;
-} // namespace bluetooth
-#endif // MOZ_B2G_BT
-
 #ifdef MOZ_B2G_RIL
 class MobileConnectionArray;
 #endif
 
 class PowerManager;
 class IccManager;
 class InputPortManager;
 class DeviceStorageAreaListener;
@@ -230,19 +224,16 @@ public:
   MobileConnectionArray* GetMozMobileConnections(ErrorResult& aRv);
 #endif // MOZ_B2G_RIL
 #ifdef MOZ_GAMEPAD
   void GetGamepads(nsTArray<RefPtr<Gamepad> >& aGamepads, ErrorResult& aRv);
   GamepadServiceTest* RequestGamepadServiceTest();
 #endif // MOZ_GAMEPAD
   already_AddRefed<Promise> GetVRDisplays(ErrorResult& aRv);
   void GetActiveVRDisplays(nsTArray<RefPtr<VRDisplay>>& aDisplays) const;
-#ifdef MOZ_B2G_BT
-  bluetooth::BluetoothManager* GetMozBluetooth(ErrorResult& aRv);
-#endif // MOZ_B2G_BT
 #ifdef MOZ_TIME_MANAGER
   time::TimeManager* GetMozTime(ErrorResult& aRv);
 #endif // MOZ_TIME_MANAGER
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
   system::AudioChannelManager* GetMozAudioChannelManager(ErrorResult& aRv);
 #endif // MOZ_AUDIO_CHANNEL_MANAGER
 
   Presentation* GetPresentation(ErrorResult& aRv);
@@ -321,19 +312,16 @@ private:
   RefPtr<Promise> mBatteryPromise;
   RefPtr<PowerManager> mPowerManager;
   RefPtr<IccManager> mIccManager;
   RefPtr<InputPortManager> mInputPortManager;
   RefPtr<network::Connection> mConnection;
 #ifdef MOZ_B2G_RIL
   RefPtr<MobileConnectionArray> mMobileConnections;
 #endif
-#ifdef MOZ_B2G_BT
-  RefPtr<bluetooth::BluetoothManager> mBluetooth;
-#endif
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
   RefPtr<system::AudioChannelManager> mAudioChannelManager;
 #endif
   RefPtr<MediaDevices> mMediaDevices;
   nsTArray<nsWeakPtr> mDeviceStorageStores;
   RefPtr<time::TimeManager> mTimeManager;
   RefPtr<ServiceWorkerContainer> mServiceWorkerContainer;
   nsCOMPtr<nsPIDOMWindowInner> mWindow;
--- a/dom/base/domerr.msg
+++ b/dom/base/domerr.msg
@@ -98,29 +98,16 @@ DOM_MSG_DEF(NS_ERROR_DOM_PROP_ACCESS_DEN
 DOM_MSG_DEF(NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED, "Access to XPConnect service denied")
 DOM_MSG_DEF(NS_ERROR_DOM_BAD_URI, "Access to restricted URI denied")
 DOM_MSG_DEF(NS_ERROR_DOM_RETVAL_UNDEFINED, "Return value is undefined")
 DOM_MSG_DEF(NS_ERROR_DOM_QUOTA_REACHED, "Persistent storage maximum size reached")
 
 DOM4_MSG_DEF(NotFoundError, "File was not found", NS_ERROR_DOM_FILE_NOT_FOUND_ERR)
 DOM4_MSG_DEF(NotReadableError, "File could not be read", NS_ERROR_DOM_FILE_NOT_READABLE_ERR)
 
-/* Non-standard Bluetooth DOM errors. */
-DOM4_MSG_DEF(BtFailError,         "Fail",  NS_ERROR_DOM_BLUETOOTH_FAIL)
-DOM4_MSG_DEF(BtNotReadyError,     "Not ready",  NS_ERROR_DOM_BLUETOOTH_NOT_READY)
-DOM4_MSG_DEF(BtNoMemError,        "No memory",  NS_ERROR_DOM_BLUETOOTH_NOMEM)
-DOM4_MSG_DEF(BtBusyError,         "Device busy with another command",  NS_ERROR_DOM_BLUETOOTH_BUSY)
-DOM4_MSG_DEF(BtDoneError,         "Request already done",  NS_ERROR_DOM_BLUETOOTH_DONE)
-DOM4_MSG_DEF(BtUnsupportedError,  "Unsupported",  NS_ERROR_DOM_BLUETOOTH_UNSUPPORTED)
-DOM4_MSG_DEF(BtParmInvalidError,  "Invalid parameter",  NS_ERROR_DOM_BLUETOOTH_PARM_INVALID)
-DOM4_MSG_DEF(BtUnhandledError,    "Unhandled",  NS_ERROR_DOM_BLUETOOTH_UNHANDLED)
-DOM4_MSG_DEF(BtAuthFailureError,  "Authentication failure",  NS_ERROR_DOM_BLUETOOTH_AUTH_FAILURE)
-DOM4_MSG_DEF(BtRmtDevDownError,   "Remote device down",  NS_ERROR_DOM_BLUETOOTH_RMT_DEV_DOWN)
-DOM4_MSG_DEF(BtAuthRejectedError, "Authentication rejected",  NS_ERROR_DOM_BLUETOOTH_AUTH_REJECTED)
-
 /* Web Animations errors */
 
 DOM4_MSG_DEF(NotSupportedError, "Animation to or from an underlying value is not yet supported.", NS_ERROR_DOM_ANIM_MISSING_PROPS_ERR)
 
 /* common global codes (from nsError.h) */
 
 DOM_MSG_DEF(NS_OK                                  , "Success")
 DOM_MSG_DEF(NS_ERROR_NOT_INITIALIZED               , "Component not initialized")
--- a/dom/base/moz.build
+++ b/dom/base/moz.build
@@ -414,18 +414,16 @@ if CONFIG['MOZ_BUILD_APP'] != 'mobile/an
 
 EXTRA_JS_MODULES += [
     'DOMRequestHelper.jsm',
     'IndexedDBHelper.jsm',
 ]
 
 LOCAL_INCLUDES += [
     '../battery',
-    '../bluetooth/common',
-    '../bluetooth/common/webapi',
     '../events',
     '../media',
     '../network',
     '../time',
     '/caps',
     '/docshell/base',
     '/dom/base',
     '/dom/geolocation',
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -102,85 +102,16 @@ DOMInterfaces = {
     'headerFile': 'mozilla/dom/File.h',
 },
 
 'BatteryManager': {
     'nativeType': 'mozilla::dom::battery::BatteryManager',
     'headerFile': 'BatteryManager.h'
 },
 
-'BluetoothAdapter': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothAdapter',
-},
-
-'BluetoothClassOfDevice': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothClassOfDevice',
-},
-
-'BluetoothDevice': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothDevice',
-},
-
-'BluetoothDiscoveryHandle': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothDiscoveryHandle',
-},
-
-'BluetoothGatt': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothGatt',
-},
-
-'BluetoothGattAttributeEvent': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothGattAttributeEvent',
-},
-
-'BluetoothGattCharacteristic': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothGattCharacteristic',
-},
-
-'BluetoothGattDescriptor': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothGattDescriptor',
-},
-
-'BluetoothGattServer': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothGattServer',
-},
-
-'BluetoothGattService': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothGattService',
-},
-
-'BluetoothLeDeviceEvent': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothLeDeviceEvent',
-},
-
-'BluetoothManager': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothManager',
-},
-
-'BluetoothObexAuthHandle': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothObexAuthHandle',
-},
-
-'BluetoothPairingHandle': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothPairingHandle',
-},
-
-'BluetoothPairingListener': {
-    'nativeType':
-      'mozilla::dom::bluetooth::BluetoothPairingListener',
-},
-
-'BluetoothPbapRequestHandle': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothPbapRequestHandle',
-},
-
-'BluetoothMapRequestHandle': {
-    'nativeType': 'mozilla::dom::bluetooth::BluetoothMapRequestHandle',
-},
-
 'BoxObject': {
     'resultNotAddRefed': ['element'],
 },
 
 'Cache': {
     'implicitJSContext': [ 'add', 'addAll' ],
     'nativeType': 'mozilla::dom::cache::Cache',
 },
--- a/dom/bindings/Exceptions.cpp
+++ b/dom/bindings/Exceptions.cpp
@@ -188,17 +188,16 @@ CreateException(JSContext* aCx, nsresult
 {
   // Do we use DOM exceptions for this error code?
   switch (NS_ERROR_GET_MODULE(aRv)) {
   case NS_ERROR_MODULE_DOM:
   case NS_ERROR_MODULE_SVG:
   case NS_ERROR_MODULE_DOM_XPATH:
   case NS_ERROR_MODULE_DOM_INDEXEDDB:
   case NS_ERROR_MODULE_DOM_FILEHANDLE:
-  case NS_ERROR_MODULE_DOM_BLUETOOTH:
   case NS_ERROR_MODULE_DOM_ANIM:
   case NS_ERROR_MODULE_DOM_PUSH:
   case NS_ERROR_MODULE_DOM_MEDIA:
     if (aMessage.IsEmpty()) {
       return DOMException::Create(aRv);
     }
     return DOMException::Create(aRv, aMessage);
   default:
--- a/dom/bindings/moz.build
+++ b/dom/bindings/moz.build
@@ -54,17 +54,16 @@ EXPORTS.mozilla.dom += [
 # Bug 932082 tracks.
 LOCAL_INCLUDES += [
     '!/dist/include/mozilla/dom',
 ]
 
 LOCAL_INCLUDES += [
     '/dom/base',
     '/dom/battery',
-    '/dom/bluetooth/common/webapi',
     '/dom/canvas',
     '/dom/geolocation',
     '/dom/html',
     '/dom/indexedDB',
     '/dom/media/webaudio',
     '/dom/media/webspeech/recognition',
     '/dom/svg',
     '/dom/workers',
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp
+++ /dev/null
@@ -1,779 +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 "base/basictypes.h"
-
-#include "BluetoothA2dpManager.h"
-#include "BluetoothCommon.h"
-#include "BluetoothService.h"
-#include "BluetoothSocket.h"
-#include "BluetoothUtils.h"
-
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/Services.h"
-#include "mozilla/StaticPtr.h"
-#include "MainThreadUtils.h"
-#include "nsIObserverService.h"
-#include "nsThreadUtils.h"
-
-using namespace mozilla;
-USING_BLUETOOTH_NAMESPACE
-// AVRC_ID op code follows bluedroid avrc_defs.h
-#define AVRC_ID_REWIND  0x48
-#define AVRC_ID_FAST_FOR 0x49
-#define AVRC_KEY_PRESS_STATE  1
-#define AVRC_KEY_RELEASE_STATE  0
-// bluedroid bt_rc.h
-#define AVRC_MAX_ATTR_STR_LEN 255
-
-namespace {
-  StaticRefPtr<BluetoothA2dpManager> sBluetoothA2dpManager;
-  bool sInShutdown = false;
-  static BluetoothA2dpInterface* sBtA2dpInterface;
-} // namespace
-
-const int BluetoothA2dpManager::MAX_NUM_CLIENTS = 1;
-
-NS_IMETHODIMP
-BluetoothA2dpManager::Observe(nsISupports* aSubject,
-                              const char* aTopic,
-                              const char16_t* aData)
-{
-  MOZ_ASSERT(sBluetoothA2dpManager);
-
-  if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    HandleShutdown();
-    return NS_OK;
-  }
-
-  MOZ_ASSERT(false, "BluetoothA2dpManager got unexpected topic!");
-  return NS_ERROR_UNEXPECTED;
-}
-
-BluetoothA2dpManager::BluetoothA2dpManager()
-{
-  Reset();
-}
-
-void
-BluetoothA2dpManager::Reset()
-{
-  mA2dpConnected = false;
-  mSinkState = SinkState::SINK_DISCONNECTED;
-  mController = nullptr;
-}
-
-static void
-AvStatusToSinkString(BluetoothA2dpConnectionState aState, nsAString& aString)
-{
-  switch (aState) {
-    case A2DP_CONNECTION_STATE_DISCONNECTED:
-      aString.AssignLiteral("disconnected");
-      break;
-    case A2DP_CONNECTION_STATE_CONNECTING:
-      aString.AssignLiteral("connecting");
-      break;
-    case A2DP_CONNECTION_STATE_CONNECTED:
-      aString.AssignLiteral("connected");
-      break;
-    case A2DP_CONNECTION_STATE_DISCONNECTING:
-      aString.AssignLiteral("disconnecting");
-      break;
-    default:
-      BT_WARNING("Unknown sink state %d", static_cast<int>(aState));
-      return;
-  }
-}
-
-class BluetoothA2dpManager::RegisterModuleResultHandler final
-  : public BluetoothSetupResultHandler
-{
-public:
-  RegisterModuleResultHandler(BluetoothA2dpInterface* aInterface,
-                              BluetoothProfileResultHandler* aRes)
-    : mInterface(aInterface)
-    , mRes(aRes)
-  { }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_WARNING("BluetoothSetupInterface::RegisterModule failed for A2DP: %d",
-               (int)aStatus);
-
-    mInterface->SetNotificationHandler(nullptr);
-
-    if (mRes) {
-      mRes->OnError(NS_ERROR_FAILURE);
-    }
-  }
-
-  void RegisterModule() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    sBtA2dpInterface = mInterface;
-
-    if (mRes) {
-      mRes->Init();
-    }
-  }
-
-private:
-  BluetoothA2dpInterface* mInterface;
-  RefPtr<BluetoothProfileResultHandler> mRes;
-};
-
-class BluetoothA2dpManager::InitProfileResultHandlerRunnable final
-  : public Runnable
-{
-public:
-  InitProfileResultHandlerRunnable(BluetoothProfileResultHandler* aRes,
-                                   nsresult aRv)
-    : mRes(aRes)
-    , mRv(aRv)
-  {
-    MOZ_ASSERT(mRes);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (NS_SUCCEEDED(mRv)) {
-      mRes->Init();
-    } else {
-      mRes->OnError(mRv);
-    }
-    return NS_OK;
-  }
-
-private:
-  RefPtr<BluetoothProfileResultHandler> mRes;
-  nsresult mRv;
-};
-
-/*
- * This function will be only called when Bluetooth is turning on.
- * It is important to register a2dp callbacks before enable() gets called.
- * It is required to register a2dp callbacks before a2dp media task
- * starts up.
- */
-// static
-void
-BluetoothA2dpManager::InitA2dpInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (sBtA2dpInterface) {
-    BT_LOGR("Bluetooth A2DP interface is already initalized.");
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_OK);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch A2DP Init runnable");
-    }
-    return;
-  }
-
-  auto btInf = BluetoothInterface::GetInstance();
-
-  if (NS_WARN_IF(!btInf)) {
-    // If there's no Bluetooth interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch A2DP OnError runnable");
-    }
-    return;
-  }
-
-  auto setupInterface = btInf->GetBluetoothSetupInterface();
-
-  if (NS_WARN_IF(!setupInterface)) {
-    // If there's no Setup interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch A2DP OnError runnable");
-    }
-    return;
-  }
-
-  auto a2dpInterface = btInf->GetBluetoothA2dpInterface();
-
-  if (NS_WARN_IF(!a2dpInterface)) {
-    // If there's no A2DP interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch A2DP OnError runnable");
-    }
-    return;
-  }
-
-  // Set notification handler _before_ registering the module. It could
-  // happen that we receive notifications, before the result handler runs.
-  a2dpInterface->SetNotificationHandler(BluetoothA2dpManager::Get());
-
-  setupInterface->RegisterModule(
-    SETUP_SERVICE_ID_A2DP, 0, MAX_NUM_CLIENTS,
-    new RegisterModuleResultHandler(a2dpInterface, aRes));
-}
-
-BluetoothA2dpManager::~BluetoothA2dpManager()
-{ }
-
-void
-BluetoothA2dpManager::Uninit()
-{
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-  if (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID))) {
-    BT_WARNING("Failed to remove shutdown observer!");
-  }
-}
-
-/*
- * Static functions
- */
-
-static BluetoothA2dpManager::SinkState
-StatusStringToSinkState(const nsAString& aStatus)
-{
-  BluetoothA2dpManager::SinkState state =
-    BluetoothA2dpManager::SinkState::SINK_UNKNOWN;
-  if (aStatus.EqualsLiteral("disconnected")) {
-    state = BluetoothA2dpManager::SinkState::SINK_DISCONNECTED;
-  } else if (aStatus.EqualsLiteral("connecting")) {
-    state = BluetoothA2dpManager::SinkState::SINK_CONNECTING;
-  } else if (aStatus.EqualsLiteral("connected")) {
-    state = BluetoothA2dpManager::SinkState::SINK_CONNECTED;
-  } else if (aStatus.EqualsLiteral("playing")) {
-    state = BluetoothA2dpManager::SinkState::SINK_PLAYING;
-  } else {
-    BT_WARNING("Unknown sink state");
-  }
-  return state;
-}
-
-//static
-BluetoothA2dpManager*
-BluetoothA2dpManager::Get()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // If sBluetoothA2dpManager already exists, exit early
-  if (sBluetoothA2dpManager) {
-    return sBluetoothA2dpManager;
-  }
-
-  // If we're in shutdown, don't create a new instance
-  NS_ENSURE_FALSE(sInShutdown, nullptr);
-
-  // Create a new instance and return
-  sBluetoothA2dpManager = new BluetoothA2dpManager();
-
-  return sBluetoothA2dpManager;
-}
-
-class BluetoothA2dpManager::UnregisterModuleResultHandler final
-  : public BluetoothSetupResultHandler
-{
-public:
-  UnregisterModuleResultHandler(BluetoothProfileResultHandler* aRes)
-    : mRes(aRes)
-  { }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_WARNING("BluetoothSetupInterface::UnregisterModule failed for A2DP: %d",
-               (int)aStatus);
-
-    sBtA2dpInterface->SetNotificationHandler(nullptr);
-    sBtA2dpInterface = nullptr;
-
-    sBluetoothA2dpManager->Uninit();
-    sBluetoothA2dpManager = nullptr;
-
-    if (mRes) {
-      mRes->OnError(NS_ERROR_FAILURE);
-    }
-  }
-
-  void UnregisterModule() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    sBtA2dpInterface->SetNotificationHandler(nullptr);
-    sBtA2dpInterface = nullptr;
-
-    sBluetoothA2dpManager->Uninit();
-    sBluetoothA2dpManager = nullptr;
-
-    if (mRes) {
-      mRes->Deinit();
-    }
-  }
-
-private:
-  RefPtr<BluetoothProfileResultHandler> mRes;
-};
-
-class BluetoothA2dpManager::DeinitProfileResultHandlerRunnable final
-  : public Runnable
-{
-public:
-  DeinitProfileResultHandlerRunnable(BluetoothProfileResultHandler* aRes,
-                                     nsresult aRv)
-    : mRes(aRes)
-    , mRv(aRv)
-  {
-    MOZ_ASSERT(mRes);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (NS_SUCCEEDED(mRv)) {
-      mRes->Deinit();
-    } else {
-      mRes->OnError(mRv);
-    }
-    return NS_OK;
-  }
-
-private:
-  RefPtr<BluetoothProfileResultHandler> mRes;
-  nsresult mRv;
-};
-
-// static
-void
-BluetoothA2dpManager::DeinitA2dpInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!sBtA2dpInterface) {
-    BT_LOGR("Bluetooth A2DP interface has not been initalized.");
-    RefPtr<Runnable> r =
-      new DeinitProfileResultHandlerRunnable(aRes, NS_OK);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch A2DP Deinit runnable");
-    }
-    return;
-  }
-
-  auto btInf = BluetoothInterface::GetInstance();
-
-  if (NS_WARN_IF(!btInf)) {
-    // If there's no backend interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new DeinitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch A2DP OnError runnable");
-    }
-    return;
-  }
-
-  auto setupInterface = btInf->GetBluetoothSetupInterface();
-
-  if (NS_WARN_IF(!setupInterface)) {
-    // If there's no Setup interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new DeinitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch A2DP OnError runnable");
-    }
-    return;
-  }
-
-  setupInterface->UnregisterModule(
-    SETUP_SERVICE_ID_A2DP,
-    new UnregisterModuleResultHandler(aRes));
-}
-
-void
-BluetoothA2dpManager::HandleShutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  sInShutdown = true;
-  Disconnect(nullptr);
-  sBluetoothA2dpManager = nullptr;
-}
-
-void
-BluetoothA2dpManager::OnConnectError()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mController->NotifyCompletion(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
-
-  mController = nullptr;
-  mDeviceAddress.Clear();
-}
-
-class BluetoothA2dpManager::ConnectResultHandler final
-  : public BluetoothA2dpResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_LOGR("BluetoothA2dpInterface::Connect failed: %d", (int)aStatus);
-
-    NS_ENSURE_TRUE_VOID(sBluetoothA2dpManager);
-    sBluetoothA2dpManager->OnConnectError();
-  }
-};
-
-void
-BluetoothA2dpManager::Connect(const BluetoothAddress& aDeviceAddress,
-                              BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!aDeviceAddress.IsCleared());
-  MOZ_ASSERT(aController);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs || sInShutdown) {
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    return;
-  }
-
-  if (mA2dpConnected) {
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
-    return;
-  }
-
-  mDeviceAddress = aDeviceAddress;
-  mController = aController;
-
-  if (!sBtA2dpInterface) {
-    BT_LOGR("sBluetoothA2dpInterface is null");
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    return;
-  }
-
-  sBtA2dpInterface->Connect(mDeviceAddress, new ConnectResultHandler());
-}
-
-void
-BluetoothA2dpManager::OnDisconnectError()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  NS_ENSURE_TRUE_VOID(mController);
-
-  mController->NotifyCompletion(NS_LITERAL_STRING(ERR_DISCONNECTION_FAILED));
-}
-
-class BluetoothA2dpManager::DisconnectResultHandler final
-  : public BluetoothA2dpResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_LOGR("BluetoothA2dpInterface::Disconnect failed: %d", (int)aStatus);
-
-    NS_ENSURE_TRUE_VOID(sBluetoothA2dpManager);
-    sBluetoothA2dpManager->OnDisconnectError();
-  }
-};
-
-void
-BluetoothA2dpManager::Disconnect(BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!mController);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    if (aController) {
-      aController->NotifyCompletion(
-        NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    }
-    return;
-  }
-
-  if (!mA2dpConnected) {
-    if (aController) {
-      aController->NotifyCompletion(
-        NS_LITERAL_STRING(ERR_ALREADY_DISCONNECTED));
-    }
-    return;
-  }
-
-  MOZ_ASSERT(!mDeviceAddress.IsCleared());
-
-  mController = aController;
-
-  if (!sBtA2dpInterface) {
-    BT_LOGR("sBluetoothA2dpInterface is null");
-    if (aController) {
-      aController->NotifyCompletion(
-        NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    }
-    return;
-  }
-
-  sBtA2dpInterface->Disconnect(mDeviceAddress, new DisconnectResultHandler());
-}
-
-void
-BluetoothA2dpManager::OnConnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  RefPtr<BluetoothProfileController> controller = mController.forget();
-  controller->NotifyCompletion(aErrorStr);
-}
-
-void
-BluetoothA2dpManager::OnDisconnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  RefPtr<BluetoothProfileController> controller = mController.forget();
-  controller->NotifyCompletion(aErrorStr);
-
-  Reset();
-}
-
-/* HandleSinkPropertyChanged update sink state in A2dp
- *
- * Possible values: "disconnected", "connecting", "connected", "playing"
- *
- * 1. "disconnected" -> "connecting"
- *    Either an incoming or outgoing connection attempt ongoing
- * 2. "connecting" -> "disconnected"
- *    Connection attempt failed
- * 3. "connecting" -> "connected"
- *    Successfully connected
- * 4. "connected" -> "playing"
- *    Audio stream active
- * 5. "playing" -> "connected"
- *    Audio stream suspended
- * 6. "connected" -> "disconnected"
- *    "playing" -> "disconnected"
- *    Disconnected from local or the remote device
- */
-void
-BluetoothA2dpManager::HandleSinkPropertyChanged(const BluetoothSignal& aSignal)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aSignal.value().type() ==
-             BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  BluetoothAddress address;
-  NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(StringToAddress(aSignal.path(), address)));
-
-  /**
-   * Update sink property only if
-   * - mDeviceAddress is empty (A2dp is disconnected), or
-   * - this property change is from the connected sink.
-   */
-  NS_ENSURE_TRUE_VOID(mDeviceAddress.IsCleared() || mDeviceAddress == address);
-
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aSignal.value().get_ArrayOfBluetoothNamedValue();
-  MOZ_ASSERT(arr.Length() == 1);
-
-  /**
-   * There are three properties:
-   * - "State": a string
-   * - "Connected": a boolean value
-   * - "Playing": a boolean value
-   *
-   * Note that only "State" is handled in this function.
-   */
-
-  const nsString& name = arr[0].name();
-  NS_ENSURE_TRUE_VOID(name.EqualsLiteral("State"));
-
-  const BluetoothValue& value = arr[0].value();
-  MOZ_ASSERT(value.type() == BluetoothValue::TnsString);
-  SinkState newState = StatusStringToSinkState(value.get_nsString());
-  NS_ENSURE_TRUE_VOID((newState != SinkState::SINK_UNKNOWN) &&
-                      (newState != mSinkState));
-
-  SinkState prevState = mSinkState;
-  mSinkState = newState;
-
-  switch(mSinkState) {
-    case SinkState::SINK_CONNECTING:
-      // case 1: Either an incoming or outgoing connection attempt ongoing
-      MOZ_ASSERT(prevState == SinkState::SINK_DISCONNECTED);
-      break;
-    case SinkState::SINK_PLAYING:
-      // case 4: Audio stream active
-      MOZ_ASSERT(prevState == SinkState::SINK_CONNECTED);
-      break;
-    case SinkState::SINK_CONNECTED:
-      // case 5: Audio stream suspended
-      if (prevState == SinkState::SINK_PLAYING ||
-          prevState == SinkState::SINK_CONNECTED) {
-        break;
-      }
-
-      // case 3: Successfully connected
-      mA2dpConnected = true;
-      mDeviceAddress = address;
-      NotifyConnectionStatusChanged();
-
-      OnConnect(EmptyString());
-      break;
-    case SinkState::SINK_DISCONNECTED:
-      // case 2: Connection attempt failed
-      if (prevState == SinkState::SINK_CONNECTING) {
-        OnConnect(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
-        break;
-      }
-
-      // case 6: Disconnected from the remote device
-      MOZ_ASSERT(prevState == SinkState::SINK_CONNECTED ||
-                 prevState == SinkState::SINK_PLAYING) ;
-
-      mA2dpConnected = false;
-      NotifyConnectionStatusChanged();
-      mDeviceAddress.Clear();
-      OnDisconnect(EmptyString());
-      break;
-    default:
-      break;
-  }
-}
-
-/*
- * Reset connection state to DISCONNECTED to handle backend error. The state
- * change triggers UI status bar update as ordinary bluetooth turn-off sequence.
- */
-void
-BluetoothA2dpManager::HandleBackendError()
-{
-  if (mSinkState != SinkState::SINK_DISCONNECTED) {
-    ConnectionStateNotification(A2DP_CONNECTION_STATE_DISCONNECTED,
-                                mDeviceAddress);
-  }
-}
-
-void
-BluetoothA2dpManager::NotifyConnectionStatusChanged()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Notify Gecko observers
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-
-  nsAutoString deviceAddressStr;
-  AddressToString(mDeviceAddress, deviceAddressStr);
-
-  if (NS_FAILED(obs->NotifyObservers(this,
-                                     BLUETOOTH_A2DP_STATUS_CHANGED_ID,
-                                     deviceAddressStr.get()))) {
-    BT_WARNING("Failed to notify bluetooth-a2dp-status-changed observsers!");
-  }
-
-  // Dispatch an event of status change
-  DispatchStatusChangedEvent(
-    NS_LITERAL_STRING(A2DP_STATUS_CHANGED_ID), mDeviceAddress, mA2dpConnected);
-}
-
-void
-BluetoothA2dpManager::OnGetServiceChannel(const BluetoothAddress& aDeviceAddress,
-                                          const BluetoothUuid& aServiceUuid,
-                                          int aChannel)
-{
-}
-
-void
-BluetoothA2dpManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
-{
-}
-
-void
-BluetoothA2dpManager::GetAddress(BluetoothAddress& aDeviceAddress)
-{
-  aDeviceAddress = mDeviceAddress;
-}
-
-bool
-BluetoothA2dpManager::IsConnected()
-{
-  return mA2dpConnected;
-}
-
-/*
- * Notifications
- */
-
-void
-BluetoothA2dpManager::ConnectionStateNotification(
-  BluetoothA2dpConnectionState aState, const BluetoothAddress& aBdAddr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsString a2dpState;
-  AvStatusToSinkString(aState, a2dpState);
-
-  InfallibleTArray<BluetoothNamedValue> props;
-  AppendNamedValue(props, "State", a2dpState);
-
-  nsAutoString addressStr;
-  AddressToString(aBdAddr, addressStr);
-
-  HandleSinkPropertyChanged(BluetoothSignal(NS_LITERAL_STRING("AudioSink"),
-                                            addressStr, props));
-}
-
-void
-BluetoothA2dpManager::AudioStateNotification(BluetoothA2dpAudioState aState,
-                                             const BluetoothAddress& aBdAddr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsString a2dpState;
-
-  if (aState == A2DP_AUDIO_STATE_STARTED) {
-    a2dpState = NS_LITERAL_STRING("playing");
-  } else if (aState == A2DP_AUDIO_STATE_STOPPED) {
-    // for avdtp state stop stream
-    a2dpState = NS_LITERAL_STRING("connected");
-  } else if (aState == A2DP_AUDIO_STATE_REMOTE_SUSPEND) {
-    // for avdtp state suspend stream from remote side
-    a2dpState = NS_LITERAL_STRING("connected");
-  }
-
-  InfallibleTArray<BluetoothNamedValue> props;
-  AppendNamedValue(props, "State", a2dpState);
-
-  nsAutoString addressStr;
-  AddressToString(aBdAddr, addressStr);
-
-  HandleSinkPropertyChanged(BluetoothSignal(NS_LITERAL_STRING("AudioSink"),
-                                            addressStr, props));
-}
-
-NS_IMPL_ISUPPORTS(BluetoothA2dpManager, nsIObserver)
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothA2dpManager.h
+++ /dev/null
@@ -1,80 +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_BluetoothA2dpManager_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothA2dpManager_h
-
-#include "BluetoothCommon.h"
-#include "BluetoothInterface.h"
-#include "BluetoothProfileController.h"
-#include "BluetoothProfileManagerBase.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-class BluetoothA2dpManager : public BluetoothProfileManagerBase
-                           , public BluetoothA2dpNotificationHandler
-{
-public:
-  static const int MAX_NUM_CLIENTS;
-
-  BT_DECL_PROFILE_MGR_BASE
-  virtual void GetName(nsACString& aName)
-  {
-    aName.AssignLiteral("A2DP");
-  }
-
-  enum SinkState {
-    SINK_UNKNOWN,
-    SINK_DISCONNECTED,
-    SINK_CONNECTING,
-    SINK_CONNECTED,
-    SINK_PLAYING,
-  };
-
-  static BluetoothA2dpManager* Get();
-  static void InitA2dpInterface(BluetoothProfileResultHandler* aRes);
-  static void DeinitA2dpInterface(BluetoothProfileResultHandler* aRes);
-
-  void OnConnectError();
-  void OnDisconnectError();
-
-  // A2DP-specific functions
-  void HandleSinkPropertyChanged(const BluetoothSignal& aSignal);
-
-  void HandleBackendError();
-
-protected:
-  virtual ~BluetoothA2dpManager();
-
-private:
-  class ConnectResultHandler;
-  class DeinitProfileResultHandlerRunnable;
-  class DisconnectResultHandler;
-  class InitProfileResultHandlerRunnable;
-  class RegisterModuleResultHandler;
-  class UnregisterModuleResultHandler;
-
-  BluetoothA2dpManager();
-
-  void Uninit();
-  void HandleShutdown();
-  void NotifyConnectionStatusChanged();
-
-  void ConnectionStateNotification(BluetoothA2dpConnectionState aState,
-                                   const BluetoothAddress& aBdAddr) override;
-  void AudioStateNotification(BluetoothA2dpAudioState aState,
-                              const BluetoothAddress& aBdAddr) override;
-
-  BluetoothAddress mDeviceAddress;
-  RefPtr<BluetoothProfileController> mController;
-
-  // A2DP data member
-  bool mA2dpConnected;
-  SinkState mSinkState;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothAvrcpManager.cpp
+++ /dev/null
@@ -1,951 +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 "base/basictypes.h"
-
-#include "BluetoothAvrcpManager.h"
-#include "BluetoothCommon.h"
-#include "BluetoothService.h"
-#include "BluetoothSocket.h"
-#include "BluetoothUtils.h"
-
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/Services.h"
-#include "mozilla/StaticPtr.h"
-#include "mozilla/UniquePtr.h"
-#include "MainThreadUtils.h"
-#include "nsIObserverService.h"
-#include "nsThreadUtils.h"
-
-using namespace mozilla;
-USING_BLUETOOTH_NAMESPACE
-// AVRC_ID op code follows bluedroid avrc_defs.h
-#define AVRC_ID_REWIND  0x48
-#define AVRC_ID_FAST_FOR 0x49
-#define AVRC_KEY_PRESS_STATE  1
-#define AVRC_KEY_RELEASE_STATE  0
-// bluedroid bt_rc.h
-#define AVRC_MAX_ATTR_STR_LEN 255
-
-namespace {
-  StaticRefPtr<BluetoothAvrcpManager> sBluetoothAvrcpManager;
-  bool sInShutdown = false;
-  static BluetoothAvrcpInterface* sBtAvrcpInterface;
-} // namespace
-
-const int BluetoothAvrcpManager::MAX_NUM_CLIENTS = 1;
-
-/*
- * This function maps attribute id and returns corresponding values
- */
-static void
-ConvertAttributeString(BluetoothAvrcpMediaAttribute aAttrId,
-                       nsAString& aAttrStr)
-{
-  BluetoothAvrcpManager* avrcp = BluetoothAvrcpManager::Get();
-  NS_ENSURE_TRUE_VOID(avrcp);
-
-  switch (aAttrId) {
-    case AVRCP_MEDIA_ATTRIBUTE_TITLE:
-      avrcp->GetTitle(aAttrStr);
-      /*
-       * bluedroid can only send string length AVRC_MAX_ATTR_STR_LEN - 1
-       */
-      if (aAttrStr.Length() >= AVRC_MAX_ATTR_STR_LEN) {
-        aAttrStr.Truncate(AVRC_MAX_ATTR_STR_LEN - 1);
-        BT_WARNING("Truncate media item attribute title, length is over 255");
-      }
-      break;
-    case AVRCP_MEDIA_ATTRIBUTE_ARTIST:
-      avrcp->GetArtist(aAttrStr);
-      if (aAttrStr.Length() >= AVRC_MAX_ATTR_STR_LEN) {
-        aAttrStr.Truncate(AVRC_MAX_ATTR_STR_LEN - 1);
-        BT_WARNING("Truncate media item attribute artist, length is over 255");
-      }
-      break;
-    case AVRCP_MEDIA_ATTRIBUTE_ALBUM:
-      avrcp->GetAlbum(aAttrStr);
-      if (aAttrStr.Length() >= AVRC_MAX_ATTR_STR_LEN) {
-        aAttrStr.Truncate(AVRC_MAX_ATTR_STR_LEN - 1);
-        BT_WARNING("Truncate media item attribute album, length is over 255");
-      }
-      break;
-    case AVRCP_MEDIA_ATTRIBUTE_TRACK_NUM:
-      aAttrStr.AppendInt(avrcp->GetMediaNumber());
-      break;
-    case AVRCP_MEDIA_ATTRIBUTE_NUM_TRACKS:
-      aAttrStr.AppendInt(avrcp->GetTotalMediaNumber());
-      break;
-    case AVRCP_MEDIA_ATTRIBUTE_GENRE:
-      // TODO: we currently don't support genre from music player
-      aAttrStr.Truncate();
-      break;
-    case AVRCP_MEDIA_ATTRIBUTE_PLAYING_TIME:
-      aAttrStr.AppendInt(avrcp->GetDuration());
-      break;
-  }
-}
-
-NS_IMETHODIMP
-BluetoothAvrcpManager::Observe(nsISupports* aSubject,
-                               const char* aTopic,
-                               const char16_t* aData)
-{
-  MOZ_ASSERT(sBluetoothAvrcpManager);
-
-  if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    HandleShutdown();
-    return NS_OK;
-  }
-
-  MOZ_ASSERT(false, "BluetoothAvrcpManager got unexpected topic!");
-  return NS_ERROR_UNEXPECTED;
-}
-
-BluetoothAvrcpManager::BluetoothAvrcpManager()
-{
-  Reset();
-}
-
-void
-BluetoothAvrcpManager::Reset()
-{
-  mAvrcpConnected = false;
-  mDuration = 0;
-  mMediaNumber = 0;
-  mTotalMediaCount = 0;
-  mPosition = 0;
-  mPlayStatus = ControlPlayStatus::PLAYSTATUS_STOPPED;
-}
-
-class BluetoothAvrcpManager::RegisterModuleResultHandler final
-  : public BluetoothSetupResultHandler
-{
-public:
-  RegisterModuleResultHandler(BluetoothAvrcpInterface* aInterface,
-                              BluetoothProfileResultHandler* aRes)
-    : mInterface(aInterface)
-    , mRes(aRes)
-  {
-    MOZ_ASSERT(mInterface);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_WARNING("BluetoothSetupInterface::RegisterModule failed for AVRCP: %d",
-               (int)aStatus);
-
-    mInterface->SetNotificationHandler(nullptr);
-
-    if (mRes) {
-      if (aStatus == STATUS_UNSUPPORTED) {
-        /* Not all versions of Bluedroid support AVRCP. So if the
-         * initialization fails with STATUS_UNSUPPORTED, we still
-         * signal success.
-         */
-        mRes->Init();
-      } else {
-        mRes->OnError(NS_ERROR_FAILURE);
-      }
-    }
-  }
-
-  void RegisterModule() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    sBtAvrcpInterface = mInterface;
-
-    if (mRes) {
-      mRes->Init();
-    }
-  }
-
-private:
-  BluetoothAvrcpInterface* mInterface;
-  RefPtr<BluetoothProfileResultHandler> mRes;
-};
-
-class BluetoothAvrcpManager::InitProfileResultHandlerRunnable final
-  : public Runnable
-{
-public:
-  InitProfileResultHandlerRunnable(BluetoothProfileResultHandler* aRes,
-                                   nsresult aRv)
-    : mRes(aRes)
-    , mRv(aRv)
-  {
-    MOZ_ASSERT(mRes);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (NS_SUCCEEDED(mRv)) {
-      mRes->Init();
-    } else {
-      mRes->OnError(mRv);
-    }
-    return NS_OK;
-  }
-
-private:
-  RefPtr<BluetoothProfileResultHandler> mRes;
-  nsresult mRv;
-};
-
-/*
- * This function will be only called when Bluetooth is turning on.
- */
-// static
-void
-BluetoothAvrcpManager::InitAvrcpInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (sBtAvrcpInterface) {
-    BT_LOGR("Bluetooth AVRCP interface is already initalized.");
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_OK);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch AVRCP Init runnable");
-    }
-    return;
-  }
-
-  auto btInf = BluetoothInterface::GetInstance();
-
-  if (NS_WARN_IF(!btInf)) {
-    // If there's no Bluetooth interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch AVRCP OnError runnable");
-    }
-    return;
-  }
-
-  auto setupInterface = btInf->GetBluetoothSetupInterface();
-
-  if (NS_WARN_IF(!setupInterface)) {
-    // If there's no Setup interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch AVRCP OnError runnable");
-    }
-    return;
-  }
-
-  auto avrcpInterface = btInf->GetBluetoothAvrcpInterface();
-
-  if (NS_WARN_IF(!avrcpInterface)) {
-    // If there's no AVRCP interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch AVRCP OnError runnable");
-    }
-    return;
-  }
-
-  // Set notification handler _before_ registering the module. It could
-  // happen that we receive notifications, before the result handler runs.
-  avrcpInterface->SetNotificationHandler(BluetoothAvrcpManager::Get());
-
-  setupInterface->RegisterModule(
-    SETUP_SERVICE_ID_AVRCP, 0, MAX_NUM_CLIENTS,
-    new RegisterModuleResultHandler(avrcpInterface, aRes));
-}
-
-BluetoothAvrcpManager::~BluetoothAvrcpManager()
-{ }
-
-void
-BluetoothAvrcpManager::Uninit()
-{
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-  if (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID))) {
-    BT_WARNING("Failed to remove shutdown observer!");
-  }
-}
-
-/*
- * Static functions
- */
-
-//static
-BluetoothAvrcpManager*
-BluetoothAvrcpManager::Get()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // If sBluetoothAvrcpManager already exists, exit early
-  if (sBluetoothAvrcpManager) {
-    return sBluetoothAvrcpManager;
-  }
-
-  // If we're in shutdown, don't create a new instance
-  NS_ENSURE_FALSE(sInShutdown, nullptr);
-
-  // Create a new instance and return
-  sBluetoothAvrcpManager = new BluetoothAvrcpManager();
-
-  return sBluetoothAvrcpManager;
-}
-
-class BluetoothAvrcpManager::UnregisterModuleResultHandler final
-  : public BluetoothSetupResultHandler
-{
-public:
-  UnregisterModuleResultHandler(BluetoothProfileResultHandler* aRes)
-    : mRes(aRes)
-  { }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_WARNING("BluetoothSetupInterface::UnregisterModule failed for AVRCP: %d",
-               (int)aStatus);
-
-    sBtAvrcpInterface->SetNotificationHandler(nullptr);
-    sBtAvrcpInterface = nullptr;
-
-    sBluetoothAvrcpManager->Uninit();
-    sBluetoothAvrcpManager = nullptr;
-
-    if (mRes) {
-      mRes->OnError(NS_ERROR_FAILURE);
-    }
-  }
-
-  void UnregisterModule() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    sBtAvrcpInterface->SetNotificationHandler(nullptr);
-    sBtAvrcpInterface = nullptr;
-
-    sBluetoothAvrcpManager->Uninit();
-    sBluetoothAvrcpManager = nullptr;
-
-    if (mRes) {
-      mRes->Deinit();
-    }
-  }
-
-private:
-  RefPtr<BluetoothProfileResultHandler> mRes;
-};
-
-class BluetoothAvrcpManager::DeinitProfileResultHandlerRunnable final
-  : public Runnable
-{
-public:
-  DeinitProfileResultHandlerRunnable(BluetoothProfileResultHandler* aRes,
-                                     nsresult aRv)
-    : mRes(aRes)
-    , mRv(aRv)
-  {
-    MOZ_ASSERT(mRes);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (NS_SUCCEEDED(mRv)) {
-      mRes->Deinit();
-    } else {
-      mRes->OnError(mRv);
-    }
-    return NS_OK;
-  }
-
-private:
-  RefPtr<BluetoothProfileResultHandler> mRes;
-  nsresult mRv;
-};
-
-// static
-void
-BluetoothAvrcpManager::DeinitAvrcpInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!sBtAvrcpInterface) {
-    BT_LOGR("Bluetooth AVRCP interface has not been initalized.");
-    RefPtr<Runnable> r =
-      new DeinitProfileResultHandlerRunnable(aRes, NS_OK);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch AVRCP Deinit runnable");
-    }
-    return;
-  }
-
-  auto btInf = BluetoothInterface::GetInstance();
-
-  if (NS_WARN_IF(!btInf)) {
-    // If there's no backend interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new DeinitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch AVRCP OnError runnable");
-    }
-    return;
-  }
-
-  auto setupInterface = btInf->GetBluetoothSetupInterface();
-
-  if (NS_WARN_IF(!setupInterface)) {
-    // If there's no Setup interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new DeinitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch AVRCP OnError runnable");
-    }
-    return;
-  }
-
-  setupInterface->UnregisterModule(
-    SETUP_SERVICE_ID_AVRCP,
-    new UnregisterModuleResultHandler(aRes));
-}
-
-void
-BluetoothAvrcpManager::HandleShutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  sInShutdown = true;
-  Disconnect(nullptr);
-  sBluetoothAvrcpManager = nullptr;
-}
-
-class BluetoothAvrcpManager::ConnectRunnable final : public Runnable
-{
-public:
-  ConnectRunnable(BluetoothAvrcpManager* aManager)
-    : mManager(aManager)
-  {
-    MOZ_ASSERT(mManager);
-  }
-  NS_IMETHOD Run() override
-  {
-    mManager->OnConnect(EmptyString());
-    return NS_OK;
-  }
-private:
-  BluetoothAvrcpManager* mManager;
-};
-
-void
-BluetoothAvrcpManager::Connect(const BluetoothAddress& aDeviceAddress,
-                               BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!aDeviceAddress.IsCleared());
-  MOZ_ASSERT(aController);
-
-  // AVRCP doesn't require connecting. We just set the remote address here.
-  mDeviceAddress = aDeviceAddress;
-  mController = aController;
-  SetConnected(true);
-
-  NS_DispatchToMainThread(new ConnectRunnable(this));
-}
-
-class BluetoothAvrcpManager::DisconnectRunnable final : public Runnable
-{
-public:
-  DisconnectRunnable(BluetoothAvrcpManager* aManager)
-    : mManager(aManager)
-  {
-    MOZ_ASSERT(mManager);
-  }
-  NS_IMETHOD Run() override
-  {
-    mManager->OnDisconnect(EmptyString());
-    return NS_OK;
-  }
-private:
-  BluetoothAvrcpManager* mManager;
-};
-
-void
-BluetoothAvrcpManager::Disconnect(BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!mController);
-
-  mDeviceAddress.Clear();
-  mController = aController;
-  SetConnected(false);
-
-  NS_DispatchToMainThread(new DisconnectRunnable(this));
-}
-
-void
-BluetoothAvrcpManager::OnConnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  RefPtr<BluetoothProfileController> controller = mController.forget();
-  controller->NotifyCompletion(aErrorStr);
-}
-
-void
-BluetoothAvrcpManager::OnDisconnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  RefPtr<BluetoothProfileController> controller = mController.forget();
-  controller->NotifyCompletion(aErrorStr);
-
-  Reset();
-}
-
-void
-BluetoothAvrcpManager::OnGetServiceChannel(
-  const BluetoothAddress& aDeviceAddress,
-  const BluetoothUuid& aServiceUuid,
-  int aChannel)
-{ }
-
-void
-BluetoothAvrcpManager::OnUpdateSdpRecords(
-  const BluetoothAddress& aDeviceAddress)
-{ }
-
-void
-BluetoothAvrcpManager::GetAddress(BluetoothAddress& aDeviceAddress)
-{
-  aDeviceAddress = mDeviceAddress;
-}
-
-bool
-BluetoothAvrcpManager::IsConnected()
-{
-  return mAvrcpConnected;
-}
-
-/*
- * In bluedroid stack case, there is no interface to know exactly
- * avrcp connection status. All connection are managed by bluedroid stack.
- */
-void
-BluetoothAvrcpManager::SetConnected(bool aConnected)
-{
-  mAvrcpConnected = aConnected;
-  if (!aConnected) {
-    Reset();
-  }
-}
-
-/*
- * This function only updates meta data in BluetoothAvrcpManager. Send
- * "Get Element Attributes response" in AvrcpGetElementAttrCallback
- */
-void
-BluetoothAvrcpManager::UpdateMetaData(const nsAString& aTitle,
-                                      const nsAString& aArtist,
-                                      const nsAString& aAlbum,
-                                      uint64_t aMediaNumber,
-                                      uint64_t aTotalMediaCount,
-                                      uint32_t aDuration)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE_VOID(sBtAvrcpInterface);
-
-  // Send track changed and position changed if track num is not the same.
-  // See also AVRCP 1.3 Spec 5.4.2
-  if (mMediaNumber != aMediaNumber &&
-      mTrackChangedNotifyType == AVRCP_NTF_INTERIM) {
-    BluetoothAvrcpNotificationParam param;
-    // convert to network big endian format
-    // since track stores as uint8[8]
-    // 56 = 8 * (AVRCP_UID_SIZE -1)
-    for (int i = 0; i < AVRCP_UID_SIZE; ++i) {
-      param.mTrack[i] = (aMediaNumber >> (56 - 8 * i));
-    }
-    mTrackChangedNotifyType = AVRCP_NTF_CHANGED;
-    sBtAvrcpInterface->RegisterNotificationRsp(AVRCP_EVENT_TRACK_CHANGE,
-                                               AVRCP_NTF_CHANGED,
-                                               param, nullptr);
-    if (mPlayPosChangedNotifyType == AVRCP_NTF_INTERIM) {
-      param.mSongPos = mPosition;
-      // EVENT_PLAYBACK_POS_CHANGED shall be notified if changed current track
-      mPlayPosChangedNotifyType = AVRCP_NTF_CHANGED;
-      sBtAvrcpInterface->RegisterNotificationRsp(AVRCP_EVENT_PLAY_POS_CHANGED,
-                                                 AVRCP_NTF_CHANGED,
-                                                 param, nullptr);
-    }
-  }
-
-  mTitle.Assign(aTitle);
-  mArtist.Assign(aArtist);
-  mAlbum.Assign(aAlbum);
-  mMediaNumber = aMediaNumber;
-  mTotalMediaCount = aTotalMediaCount;
-  mDuration = aDuration;
-}
-
-/*
- * This function is to reply AvrcpGetPlayStatusCallback (play-status-request)
- * from media player application (Gaia side)
- */
-void
-BluetoothAvrcpManager::UpdatePlayStatus(uint32_t aDuration,
-                                        uint32_t aPosition,
-                                        ControlPlayStatus aPlayStatus)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE_VOID(sBtAvrcpInterface);
-  // always update playstatus first
-  sBtAvrcpInterface->GetPlayStatusRsp(aPlayStatus, aDuration,
-                                      aPosition, nullptr);
-  // when play status changed, send both play status and position
-  if (mPlayStatus != aPlayStatus &&
-      mPlayStatusChangedNotifyType == AVRCP_NTF_INTERIM) {
-    BluetoothAvrcpNotificationParam param;
-    param.mPlayStatus = aPlayStatus;
-    mPlayStatusChangedNotifyType = AVRCP_NTF_CHANGED;
-    sBtAvrcpInterface->RegisterNotificationRsp(AVRCP_EVENT_PLAY_STATUS_CHANGED,
-                                               AVRCP_NTF_CHANGED,
-                                               param, nullptr);
-  }
-
-  if (mPosition != aPosition &&
-      mPlayPosChangedNotifyType == AVRCP_NTF_INTERIM) {
-    BluetoothAvrcpNotificationParam param;
-    param.mSongPos = aPosition;
-    mPlayPosChangedNotifyType = AVRCP_NTF_CHANGED;
-    sBtAvrcpInterface->RegisterNotificationRsp(AVRCP_EVENT_PLAY_POS_CHANGED,
-                                               AVRCP_NTF_CHANGED,
-                                               param, nullptr);
-  }
-
-  mDuration = aDuration;
-  mPosition = aPosition;
-  mPlayStatus = aPlayStatus;
-}
-
-/*
- * This function handles RegisterNotification request from
- * AvrcpRegisterNotificationCallback, which updates current
- * track/status/position status in the INTERRIM response.
- *
- * aParam is only valid when position changed
- */
-void
-BluetoothAvrcpManager::UpdateRegisterNotification(BluetoothAvrcpEvent aEvent,
-                                                  uint32_t aParam)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE_VOID(sBtAvrcpInterface);
-
-  BluetoothAvrcpNotificationParam param;
-
-  switch (aEvent) {
-    case AVRCP_EVENT_PLAY_STATUS_CHANGED:
-      mPlayStatusChangedNotifyType = AVRCP_NTF_INTERIM;
-      param.mPlayStatus = mPlayStatus;
-      break;
-    case AVRCP_EVENT_TRACK_CHANGE:
-      // In AVRCP 1.3 and 1.4, the identifier parameter of EVENT_TRACK_CHANGED
-      // is different.
-      // AVRCP 1.4: If no track is selected, we shall return 0xFFFFFFFFFFFFFFFF,
-      // otherwise return 0x0 in the INTERRIM response. The expanded text in
-      // version 1.4 is to allow for new UID feature. As for AVRCP 1.3, we shall
-      // return 0xFFFFFFFF. Since PTS enforces to check this part to comply with
-      // the most updated spec.
-      mTrackChangedNotifyType = AVRCP_NTF_INTERIM;
-      // needs to convert to network big endian format since track stores
-      // as uint8[8]. 56 = 8 * (BTRC_UID_SIZE -1).
-      for (int index = 0; index < AVRCP_UID_SIZE; ++index) {
-        // We cannot easily check if a track is selected, so whenever A2DP is
-        // streaming, we assume a track is selected.
-        if (mPlayStatus == ControlPlayStatus::PLAYSTATUS_PLAYING) {
-          param.mTrack[index] = 0x0;
-        } else {
-          param.mTrack[index] = 0xFF;
-        }
-      }
-      break;
-    case AVRCP_EVENT_PLAY_POS_CHANGED:
-      // If no track is selected, return 0xFFFFFFFF in the INTERIM response
-      mPlayPosChangedNotifyType = AVRCP_NTF_INTERIM;
-      if (mPlayStatus == ControlPlayStatus::PLAYSTATUS_PLAYING) {
-        param.mSongPos = mPosition;
-      } else {
-        param.mSongPos = 0xFFFFFFFF;
-      }
-      mPlaybackInterval = aParam;
-      break;
-    case AVRCP_EVENT_APP_SETTINGS_CHANGED:
-      mAppSettingsChangedNotifyType = AVRCP_NTF_INTERIM;
-      param.mNumAttr = 2;
-      param.mIds[0] = AVRCP_PLAYER_ATTRIBUTE_REPEAT;
-      param.mValues[0] = AVRCP_PLAYER_VAL_OFF_REPEAT;
-      param.mIds[1] = AVRCP_PLAYER_ATTRIBUTE_SHUFFLE;
-      param.mValues[1] = AVRCP_PLAYER_VAL_OFF_SHUFFLE;
-      break;
-    default:
-      break;
-  }
-
-  sBtAvrcpInterface->RegisterNotificationRsp(aEvent, AVRCP_NTF_INTERIM,
-                                             param, nullptr);
-}
-
-void
-BluetoothAvrcpManager::GetAlbum(nsAString& aAlbum)
-{
-  aAlbum.Assign(mAlbum);
-}
-
-uint32_t
-BluetoothAvrcpManager::GetDuration()
-{
-  return mDuration;
-}
-
-ControlPlayStatus
-BluetoothAvrcpManager::GetPlayStatus()
-{
-  return mPlayStatus;
-}
-
-uint32_t
-BluetoothAvrcpManager::GetPosition()
-{
-  return mPosition;
-}
-
-uint64_t
-BluetoothAvrcpManager::GetMediaNumber()
-{
-  return mMediaNumber;
-}
-
-uint64_t
-BluetoothAvrcpManager::GetTotalMediaNumber()
-{
-  return mTotalMediaCount;
-}
-
-void
-BluetoothAvrcpManager::GetTitle(nsAString& aTitle)
-{
-  aTitle.Assign(mTitle);
-}
-
-void
-BluetoothAvrcpManager::GetArtist(nsAString& aArtist)
-{
-  aArtist.Assign(mArtist);
-}
-
-/*
- * Notifications
- */
-
-void
-BluetoothAvrcpManager::GetPlayStatusNotification()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    return;
-  }
-
-  bs->DistributeSignal(NS_LITERAL_STRING(REQUEST_MEDIA_PLAYSTATUS_ID),
-                       NS_LITERAL_STRING(KEY_ADAPTER));
-}
-
-/* Player application settings is optional for AVRCP 1.3. B2G
- * currently does not support player-application-setting related
- * functionality.
- */
-void
-BluetoothAvrcpManager::ListPlayerAppAttrNotification()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // TODO: Support AVRCP application-setting-related functions
-}
-
-void
-BluetoothAvrcpManager::ListPlayerAppValuesNotification(
-  BluetoothAvrcpPlayerAttribute aAttrId)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // TODO: Support AVRCP application-setting-related functions
-}
-
-void
-BluetoothAvrcpManager::GetPlayerAppValueNotification(
-  uint8_t aNumAttrs, const BluetoothAvrcpPlayerAttribute* aAttrs)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // TODO: Support AVRCP application-setting-related functions
-}
-
-void
-BluetoothAvrcpManager::GetPlayerAppAttrsTextNotification(
-  uint8_t aNumAttrs, const BluetoothAvrcpPlayerAttribute* aAttrs)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // TODO: Support AVRCP application-setting-related functions
-}
-
-void
-BluetoothAvrcpManager::GetPlayerAppValuesTextNotification(
-  uint8_t aAttrId, uint8_t aNumVals, const uint8_t* aValues)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // TODO: Support AVRCP application-setting-related functions
-}
-
-void
-BluetoothAvrcpManager::SetPlayerAppValueNotification(
-  const BluetoothAvrcpPlayerSettings& aSettings)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // TODO: Support AVRCP application-setting-related functions
-}
-
-/* This method returns element attributes, which are requested from
- * CT. Unlike BlueZ it calls only UpdateMetaData. Bluedroid does not cache
- * meta-data information, but instead uses |GetElementAttrNotifications|
- * and |GetElementAttrRsp| request them.
- */
-void
-BluetoothAvrcpManager::GetElementAttrNotification(
-  uint8_t aNumAttrs, const BluetoothAvrcpMediaAttribute* aAttrs)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  auto attrs = MakeUnique<BluetoothAvrcpElementAttribute[]>(aNumAttrs);
-
-  for (uint8_t i = 0; i < aNumAttrs; ++i) {
-    attrs[i].mId = aAttrs[i];
-    ConvertAttributeString(
-      static_cast<BluetoothAvrcpMediaAttribute>(attrs[i].mId),
-      attrs[i].mValue);
-  }
-
-  MOZ_ASSERT(sBtAvrcpInterface);
-  sBtAvrcpInterface->GetElementAttrRsp(aNumAttrs, attrs.get(), nullptr);
-}
-
-void
-BluetoothAvrcpManager::RegisterNotificationNotification(
-  BluetoothAvrcpEvent aEvent, uint32_t aParam)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothAvrcpManager* avrcp = BluetoothAvrcpManager::Get();
-  if (!avrcp) {
-    return;
-  }
-
-  avrcp->UpdateRegisterNotification(aEvent, aParam);
-}
-
-/* This method is used to get CT features from the Feature Bit Mask. If
- * Advanced Control Player bit is set, the CT supports volume sync (absolute
- * volume feature). If Browsing bit is set, AVRCP 1.4 Browse feature will be
- * supported.
- */
-void
-BluetoothAvrcpManager::RemoteFeatureNotification(
-  const BluetoothAddress& aBdAddr, unsigned long aFeatures)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // TODO: Support AVRCP 1.4 absolute volume/browse
-}
-
-/* This method is used to get notifications about volume changes on the
- * remote car kit (if it supports AVRCP 1.4), not notification from phone.
- */
-void
-BluetoothAvrcpManager::VolumeChangeNotification(uint8_t aVolume,
-                                                uint8_t aCType)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // TODO: Support AVRCP 1.4 absolute volume/browse
-}
-
-void
-BluetoothAvrcpManager::PassthroughCmdNotification(uint8_t aId,
-                                                  uint8_t aKeyState)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Fast-forward and rewind key events won't be generated from bluedroid
-  // stack after ANDROID_VERSION > 18, but via passthrough callback.
-  nsAutoString name;
-  NS_ENSURE_TRUE_VOID(aKeyState == AVRC_KEY_PRESS_STATE ||
-                      aKeyState == AVRC_KEY_RELEASE_STATE);
-  switch (aId) {
-    case AVRC_ID_FAST_FOR:
-      if (aKeyState == AVRC_KEY_PRESS_STATE) {
-        name.AssignLiteral("media-fast-forward-button-press");
-      } else {
-        name.AssignLiteral("media-fast-forward-button-release");
-      }
-      break;
-    case AVRC_ID_REWIND:
-      if (aKeyState == AVRC_KEY_PRESS_STATE) {
-        name.AssignLiteral("media-rewind-button-press");
-      } else {
-        name.AssignLiteral("media-rewind-button-release");
-      }
-      break;
-    default:
-      BT_WARNING("Unable to handle the unknown PassThrough command %d", aId);
-      return;
-  }
-
-  NS_NAMED_LITERAL_STRING(type, "media-button");
-  BroadcastSystemMessage(type, BluetoothValue(name));
-}
-
-NS_IMPL_ISUPPORTS(BluetoothAvrcpManager, nsIObserver)
-
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothAvrcpManager.h
+++ /dev/null
@@ -1,150 +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_BluetoothAvrcpManager_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothAvrcpManager_h
-
-#include "BluetoothCommon.h"
-#include "BluetoothInterface.h"
-#include "BluetoothProfileController.h"
-#include "BluetoothProfileManagerBase.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-class BluetoothAvrcpManager : public BluetoothProfileManagerBase
-                            , public BluetoothAvrcpNotificationHandler
-{
-public:
-  static const int MAX_NUM_CLIENTS;
-
-  BT_DECL_PROFILE_MGR_BASE
-  virtual void GetName(nsACString& aName)
-  {
-    aName.AssignLiteral("AVRCP");
-  }
-
-  enum SinkState {
-    SINK_UNKNOWN,
-    SINK_DISCONNECTED,
-    SINK_CONNECTING,
-    SINK_CONNECTED,
-    SINK_PLAYING,
-  };
-
-  static BluetoothAvrcpManager* Get();
-  static void InitAvrcpInterface(BluetoothProfileResultHandler* aRes);
-  static void DeinitAvrcpInterface(BluetoothProfileResultHandler* aRes);
-
-  void SetConnected(bool aConnected);
-  void UpdateMetaData(const nsAString& aTitle,
-                      const nsAString& aArtist,
-                      const nsAString& aAlbum,
-                      uint64_t aMediaNumber,
-                      uint64_t aTotalMediaCount,
-                      uint32_t aDuration);
-  void UpdatePlayStatus(uint32_t aDuration,
-                        uint32_t aPosition,
-                        ControlPlayStatus aPlayStatus);
-  void UpdateRegisterNotification(BluetoothAvrcpEvent aEvent, uint32_t aParam);
-  void GetAlbum(nsAString& aAlbum);
-  uint32_t GetDuration();
-  ControlPlayStatus GetPlayStatus();
-  uint32_t GetPosition();
-  uint64_t GetMediaNumber();
-  uint64_t GetTotalMediaNumber();
-  void GetTitle(nsAString& aTitle);
-  void GetArtist(nsAString& aArtist);
-  void HandleBackendError();
-
-protected:
-  virtual ~BluetoothAvrcpManager();
-
-private:
-  class ConnectRunnable;
-  class DeinitProfileResultHandlerRunnable;
-  class DisconnectRunnable;
-  class InitProfileResultHandlerRunnable;
-  class RegisterModuleResultHandler;
-  class UnregisterModuleResultHandler;
-
-  BluetoothAvrcpManager();
-
-  void Uninit();
-  void HandleShutdown();
-  void NotifyConnectionStatusChanged();
-
-  void GetPlayStatusNotification() override;
-
-  void ListPlayerAppAttrNotification() override;
-
-  void ListPlayerAppValuesNotification(
-    BluetoothAvrcpPlayerAttribute aAttrId) override;
-
-  void GetPlayerAppValueNotification(
-    uint8_t aNumAttrs,
-    const BluetoothAvrcpPlayerAttribute* aAttrs) override;
-
-  void GetPlayerAppAttrsTextNotification(
-    uint8_t aNumAttrs,
-    const BluetoothAvrcpPlayerAttribute* aAttrs) override;
-
-  void GetPlayerAppValuesTextNotification(
-    uint8_t aAttrId, uint8_t aNumVals, const uint8_t* aValues) override;
-
-  void SetPlayerAppValueNotification(
-    const BluetoothAvrcpPlayerSettings& aSettings) override;
-
-  void GetElementAttrNotification(
-    uint8_t aNumAttrs,
-    const BluetoothAvrcpMediaAttribute* aAttrs) override;
-
-  void RegisterNotificationNotification(
-    BluetoothAvrcpEvent aEvent, uint32_t aParam) override;
-
-  void RemoteFeatureNotification(
-    const BluetoothAddress& aBdAddr, unsigned long aFeatures) override;
-
-  void VolumeChangeNotification(uint8_t aVolume, uint8_t aCType) override;
-
-  void PassthroughCmdNotification(uint8_t aId, uint8_t aKeyState) override;
-
-  BluetoothAddress mDeviceAddress;
-  RefPtr<BluetoothProfileController> mController;
-
-  bool mAvrcpConnected;
-  nsString mAlbum;
-  nsString mArtist;
-  nsString mTitle;
-  uint32_t mDuration;
-  uint64_t mMediaNumber;
-  uint64_t mTotalMediaCount;
-  uint32_t mPosition;
-  /*
-   * mPlaybackInterval specifies the time interval (in seconds) at which
-   * the change in playback position will be notified. If the song is being
-   * forwarded / rewound, a notification will be received whenever the playback
-   * position will change by this value.
-   */
-  uint32_t mPlaybackInterval;
-  ControlPlayStatus mPlayStatus;
-  /*
-   * Notification types: 1. INTERIM 2. CHANGED
-   * 1. The initial response to this Notify command shall be an INTERIM
-   * response with current status.
-   * 2. The following response shall be a CHANGED response with the updated
-   * status.
-   * mPlayStatusChangedNotifType, mTrackChangedNotifType,
-   * mPlayPosChangedNotifType represents current RegisterNotification
-   * notification type.
-   */
-  BluetoothAvrcpNotification mPlayStatusChangedNotifyType;
-  BluetoothAvrcpNotification mTrackChangedNotifyType;
-  BluetoothAvrcpNotification mPlayPosChangedNotifyType;
-  BluetoothAvrcpNotification mAppSettingsChangedNotifyType;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothAvrcpManager_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonA2dpInterface.cpp
+++ /dev/null
@@ -1,296 +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 "BluetoothDaemonA2dpInterface.h"
-#include "mozilla/UniquePtr.h"
-#include "mozilla/Unused.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using namespace mozilla::ipc;
-
-//
-// A2DP module
-//
-
-BluetoothA2dpNotificationHandler*
-  BluetoothDaemonA2dpModule::sNotificationHandler;
-
-void
-BluetoothDaemonA2dpModule::SetNotificationHandler(
-  BluetoothA2dpNotificationHandler* aNotificationHandler)
-{
-  sNotificationHandler = aNotificationHandler;
-}
-
-void
-BluetoothDaemonA2dpModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
-                                     DaemonSocketPDU& aPDU,
-                                     DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonA2dpModule::* const HandleOp[])(
-    const DaemonSocketPDUHeader&, DaemonSocketPDU&,
-    DaemonSocketResultHandler*) = {
-    [0] = &BluetoothDaemonA2dpModule::HandleRsp,
-    [1] = &BluetoothDaemonA2dpModule::HandleNtf
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread());
-
-  // negate twice to map bit to 0/1
-  unsigned int isNtf = !!(aHeader.mOpcode & 0x80);
-
-  (this->*(HandleOp[isNtf]))(aHeader, aPDU, aRes);
-}
-
-// Commands
-//
-
-nsresult
-BluetoothDaemonA2dpModule::ConnectCmd(
-  const BluetoothAddress& aRemoteAddr, BluetoothA2dpResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CONNECT,
-                                6); // Address
-
-  nsresult rv = PackPDU(aRemoteAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonA2dpModule::DisconnectCmd(
-  const BluetoothAddress& aRemoteAddr, BluetoothA2dpResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_DISCONNECT,
-                                6); // Address
-
-  nsresult rv = PackPDU(aRemoteAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-// Responses
-//
-
-void
-BluetoothDaemonA2dpModule::ErrorRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothA2dpResultHandler* aRes)
-{
-  ErrorRunnable::Dispatch(
-    aRes, &BluetoothA2dpResultHandler::OnError, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonA2dpModule::ConnectRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothA2dpResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothA2dpResultHandler::Connect, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonA2dpModule::DisconnectRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothA2dpResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothA2dpResultHandler::Disconnect, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonA2dpModule::HandleRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonA2dpModule::* const HandleRsp[])(
-    const DaemonSocketPDUHeader&,
-    DaemonSocketPDU&,
-    BluetoothA2dpResultHandler*) = {
-    [OPCODE_ERROR] = &BluetoothDaemonA2dpModule::ErrorRsp,
-    [OPCODE_CONNECT] = &BluetoothDaemonA2dpModule::ConnectRsp,
-    [OPCODE_DISCONNECT] = &BluetoothDaemonA2dpModule::DisconnectRsp
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-  if (NS_WARN_IF(!(aHeader.mOpcode < MOZ_ARRAY_LENGTH(HandleRsp))) ||
-      NS_WARN_IF(!HandleRsp[aHeader.mOpcode])) {
-    return;
-  }
-
-  RefPtr<BluetoothA2dpResultHandler> res =
-    static_cast<BluetoothA2dpResultHandler*>(aRes);
-
-  if (!res) {
-    return; // Return early if no result handler has been set for response
-  }
-
-  (this->*(HandleRsp[aHeader.mOpcode]))(aHeader, aPDU, res);
-}
-
-// Notifications
-//
-
-// Returns the current notification handler to a notification runnable
-class BluetoothDaemonA2dpModule::NotificationHandlerWrapper final
-{
-public:
-  typedef BluetoothA2dpNotificationHandler ObjectType;
-
-  static ObjectType* GetInstance()
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    return sNotificationHandler;
-  }
-};
-
-void
-BluetoothDaemonA2dpModule::ConnectionStateNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ConnectionStateNotification::Dispatch(
-    &BluetoothA2dpNotificationHandler::ConnectionStateNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonA2dpModule::AudioStateNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  AudioStateNotification::Dispatch(
-    &BluetoothA2dpNotificationHandler::AudioStateNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonA2dpModule::AudioConfigNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  AudioConfigNotification::Dispatch(
-    &BluetoothA2dpNotificationHandler::AudioConfigNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonA2dpModule::HandleNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonA2dpModule::* const HandleNtf[])(
-    const DaemonSocketPDUHeader&, DaemonSocketPDU&) = {
-    [0] = &BluetoothDaemonA2dpModule::ConnectionStateNtf,
-    [1] = &BluetoothDaemonA2dpModule::AudioStateNtf,
-#if ANDROID_VERSION >= 21
-    [2] = &BluetoothDaemonA2dpModule::AudioConfigNtf
-#endif
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread());
-
-  uint8_t index = aHeader.mOpcode - 0x81;
-
-  if (NS_WARN_IF(!(index < MOZ_ARRAY_LENGTH(HandleNtf))) ||
-      NS_WARN_IF(!HandleNtf[index])) {
-    return;
-  }
-
-  (this->*(HandleNtf[index]))(aHeader, aPDU);
-}
-
-//
-// A2DP interface
-//
-
-BluetoothDaemonA2dpInterface::BluetoothDaemonA2dpInterface(
-  BluetoothDaemonA2dpModule* aModule)
-  : mModule(aModule)
-{ }
-
-BluetoothDaemonA2dpInterface::~BluetoothDaemonA2dpInterface()
-{ }
-
-void
-BluetoothDaemonA2dpInterface::SetNotificationHandler(
-  BluetoothA2dpNotificationHandler* aNotificationHandler)
-{
-  MOZ_ASSERT(mModule);
-
-  mModule->SetNotificationHandler(aNotificationHandler);
-}
-
-/* Connect / Disconnect */
-
-void
-BluetoothDaemonA2dpInterface::Connect(
-  const BluetoothAddress& aBdAddr, BluetoothA2dpResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ConnectCmd(aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonA2dpInterface::Disconnect(
-  const BluetoothAddress& aBdAddr, BluetoothA2dpResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->DisconnectCmd(aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonA2dpInterface::DispatchError(
-  BluetoothA2dpResultHandler* aRes, BluetoothStatus aStatus)
-{
-  DaemonResultRunnable1<BluetoothA2dpResultHandler, void,
-                        BluetoothStatus, BluetoothStatus>::Dispatch(
-    aRes, &BluetoothA2dpResultHandler::OnError,
-    ConstantInitOp1<BluetoothStatus>(aStatus));
-}
-
-void
-BluetoothDaemonA2dpInterface::DispatchError(
-  BluetoothA2dpResultHandler* aRes, nsresult aRv)
-{
-  BluetoothStatus status;
-
-  if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
-    status = STATUS_FAIL;
-  }
-  DispatchError(aRes, status);
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonA2dpInterface.h
+++ /dev/null
@@ -1,147 +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_BluetoothDaemonA2dpInterface_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothDaemonA2dpInterface_h
-
-#include "BluetoothDaemonHelpers.h"
-#include "BluetoothInterface.h"
-#include "mozilla/ipc/DaemonRunnables.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using mozilla::ipc::DaemonSocketPDU;
-using mozilla::ipc::DaemonSocketPDUHeader;
-using mozilla::ipc::DaemonSocketResultHandler;
-
-class BluetoothDaemonA2dpModule
-{
-public:
-  enum {
-    SERVICE_ID = 0x06
-  };
-
-  enum {
-    OPCODE_ERROR = 0x00,
-    OPCODE_CONNECT = 0x01,
-    OPCODE_DISCONNECT = 0x02
-  };
-
-  virtual nsresult Send(DaemonSocketPDU* aPDU,
-                        DaemonSocketResultHandler* aRes) = 0;
-
-  void SetNotificationHandler(
-    BluetoothA2dpNotificationHandler* aNotificationHandler);
-
-  //
-  // Commands
-  //
-
-  nsresult ConnectCmd(const BluetoothAddress& aBdAddr,
-                      BluetoothA2dpResultHandler* aRes);
-  nsresult DisconnectCmd(const BluetoothAddress& aBdAddr,
-                         BluetoothA2dpResultHandler* aRes);
-
-protected:
-  void HandleSvc(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes);
-
-  //
-  // Responses
-  //
-
-  typedef mozilla::ipc::DaemonResultRunnable0<
-    BluetoothA2dpResultHandler, void>
-    ResultRunnable;
-
-  typedef mozilla::ipc::DaemonResultRunnable1<
-    BluetoothA2dpResultHandler, void, BluetoothStatus, BluetoothStatus>
-    ErrorRunnable;
-
-  void ErrorRsp(const DaemonSocketPDUHeader& aHeader,
-                DaemonSocketPDU& aPDU,
-                BluetoothA2dpResultHandler* aRes);
-
-  void ConnectRsp(const DaemonSocketPDUHeader& aHeader,
-                  DaemonSocketPDU& aPDU,
-                  BluetoothA2dpResultHandler* aRes);
-
-  void DisconnectRsp(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU,
-                     BluetoothA2dpResultHandler* aRes);
-
-  void HandleRsp(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU,
-                 DaemonSocketResultHandler* aRes);
-
-  //
-  // Notifications
-  //
-
-  class NotificationHandlerWrapper;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    BluetoothA2dpConnectionState, BluetoothAddress,
-    BluetoothA2dpConnectionState, const BluetoothAddress&>
-    ConnectionStateNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    BluetoothA2dpAudioState, BluetoothAddress,
-    BluetoothA2dpAudioState, const BluetoothAddress&>
-    AudioStateNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, uint32_t, uint8_t,
-    const BluetoothAddress&, uint32_t, uint8_t>
-    AudioConfigNotification;
-
-  void ConnectionStateNtf(const DaemonSocketPDUHeader& aHeader,
-                          DaemonSocketPDU& aPDU);
-
-  void AudioStateNtf(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU);
-
-  void AudioConfigNtf(const DaemonSocketPDUHeader& aHeader,
-                      DaemonSocketPDU& aPDU);
-
-  void HandleNtf(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU,
-                 DaemonSocketResultHandler* aRes);
-
-  static BluetoothA2dpNotificationHandler* sNotificationHandler;
-};
-
-class BluetoothDaemonA2dpInterface final
-  : public BluetoothA2dpInterface
-{
-public:
-  BluetoothDaemonA2dpInterface(BluetoothDaemonA2dpModule* aModule);
-  ~BluetoothDaemonA2dpInterface();
-
-  void SetNotificationHandler(
-    BluetoothA2dpNotificationHandler* aNotificationHandler) override;
-
-  /* Connect / Disconnect */
-
-  void Connect(const BluetoothAddress& aBdAddr,
-               BluetoothA2dpResultHandler* aRes) override;
-  void Disconnect(const BluetoothAddress& aBdAddr,
-                  BluetoothA2dpResultHandler* aRes) override;
-
-private:
-  void DispatchError(BluetoothA2dpResultHandler* aRes,
-                     BluetoothStatus aStatus);
-  void DispatchError(BluetoothA2dpResultHandler* aRes, nsresult aRv);
-
-  BluetoothDaemonA2dpModule* mModule;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothDaemonA2dpInterface_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonAvrcpInterface.cpp
+++ /dev/null
@@ -1,976 +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 "BluetoothDaemonAvrcpInterface.h"
-#include "mozilla/UniquePtr.h"
-#include "mozilla/Unused.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using namespace mozilla::ipc;
-
-//
-// AVRCP module
-//
-
-BluetoothAvrcpNotificationHandler*
-  BluetoothDaemonAvrcpModule::sNotificationHandler;
-
-void
-BluetoothDaemonAvrcpModule::SetNotificationHandler(
-  BluetoothAvrcpNotificationHandler* aNotificationHandler)
-{
-  sNotificationHandler = aNotificationHandler;
-}
-
-void
-BluetoothDaemonAvrcpModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
-                                      DaemonSocketPDU& aPDU,
-                                      DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonAvrcpModule::* const HandleOp[])(
-    const DaemonSocketPDUHeader&, DaemonSocketPDU&,
-    DaemonSocketResultHandler*) = {
-    [0] = &BluetoothDaemonAvrcpModule::HandleRsp,
-    [1] = &BluetoothDaemonAvrcpModule::HandleNtf
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread());
-
-  unsigned int isNtf = !!(aHeader.mOpcode & 0x80);
-
-  (this->*(HandleOp[isNtf]))(aHeader, aPDU, aRes);
-}
-
-// Commands
-//
-
-nsresult
-BluetoothDaemonAvrcpModule::GetPlayStatusRspCmd(
-  ControlPlayStatus aPlayStatus, uint32_t aSongLen, uint32_t aSongPos,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_PLAY_STATUS_RSP,
-                                1 + // Play status
-                                4 + // Duration
-                                4); // Position
-
-  nsresult rv = PackPDU(aPlayStatus, aSongLen, aSongPos, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonAvrcpModule::ListPlayerAppAttrRspCmd(
-  int aNumAttr, const BluetoothAvrcpPlayerAttribute* aPAttrs,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_LIST_PLAYER_APP_ATTR_RSP,
-                                1 + // # Attributes
-                                aNumAttr); // Player attributes
-
-  nsresult rv = PackPDU(
-    PackConversion<int, uint8_t>(aNumAttr),
-    PackArray<BluetoothAvrcpPlayerAttribute>(aPAttrs, aNumAttr), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonAvrcpModule::ListPlayerAppValueRspCmd(
-  int aNumVal, uint8_t* aPVals, BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_LIST_PLAYER_APP_VALUE_RSP,
-                                1 + // # Values
-                                aNumVal); // Player values
-
-  nsresult rv = PackPDU(PackConversion<int, uint8_t>(aNumVal),
-                        PackArray<uint8_t>(aPVals, aNumVal), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonAvrcpModule::GetPlayerAppValueRspCmd(
-  uint8_t aNumAttrs, const uint8_t* aIds, const uint8_t* aValues,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_PLAYER_APP_VALUE_RSP,
-                                1 + // # Pairs
-                                2 * aNumAttrs); // Attribute-value pairs
-
-  nsresult rv = PackPDU(
-    aNumAttrs,
-    BluetoothAvrcpAttributeValuePairs(aIds, aValues, aNumAttrs), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonAvrcpModule::GetPlayerAppAttrTextRspCmd(
-  int aNumAttr, const uint8_t* aIds, const char** aTexts,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_PLAYER_APP_ATTR_TEXT_RSP,
-                                0); // Dynamically allocated
-
-  nsresult rv = PackPDU(
-    PackConversion<int, uint8_t>(aNumAttr),
-    BluetoothAvrcpAttributeTextPairs(aIds, aTexts, aNumAttr), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonAvrcpModule::GetPlayerAppValueTextRspCmd(
-  int aNumVal, const uint8_t* aIds, const char** aTexts,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_PLAYER_APP_VALUE_TEXT_RSP,
-                                0); // Dynamically allocated
-
-  nsresult rv = PackPDU(
-    PackConversion<int, uint8_t>(aNumVal),
-    BluetoothAvrcpAttributeTextPairs(aIds, aTexts, aNumVal), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonAvrcpModule::GetElementAttrRspCmd(
-  uint8_t aNumAttr, const BluetoothAvrcpElementAttribute* aAttr,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_ELEMENT_ATTR_RSP,
-                                0); // Dynamically allocated
-
-  nsresult rv = PackPDU(
-    aNumAttr,
-    PackArray<BluetoothAvrcpElementAttribute>(aAttr, aNumAttr), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonAvrcpModule::SetPlayerAppValueRspCmd(
-  BluetoothAvrcpStatus aRspStatus, BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SET_PLAYER_APP_VALUE_RSP,
-                                1); // Status code
-
-  nsresult rv = PackPDU(aRspStatus, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonAvrcpModule::RegisterNotificationRspCmd(
-  BluetoothAvrcpEvent aEvent, BluetoothAvrcpNotification aType,
-  const BluetoothAvrcpNotificationParam& aParam,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_REGISTER_NOTIFICATION_RSP,
-                                1 + // Event
-                                1 + // Type
-                                1 + // Data length
-                                256); // Maximum data length
-
-  BluetoothAvrcpEventParamPair data(aEvent, aParam);
-  nsresult rv = PackPDU(aEvent, aType, static_cast<uint8_t>(data.GetLength()),
-                        data, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonAvrcpModule::SetVolumeCmd(uint8_t aVolume,
-                                         BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SET_VOLUME,
-                                1); // Volume
-
-  nsresult rv = PackPDU(aVolume, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-// Responses
-//
-
-void
-BluetoothDaemonAvrcpModule::ErrorRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothAvrcpResultHandler* aRes)
-{
-  ErrorRunnable::Dispatch(
-    aRes, &BluetoothAvrcpResultHandler::OnError, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::GetPlayStatusRspRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothAvrcpResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothAvrcpResultHandler::GetPlayStatusRsp,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::ListPlayerAppAttrRspRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothAvrcpResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothAvrcpResultHandler::ListPlayerAppAttrRsp,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::ListPlayerAppValueRspRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothAvrcpResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothAvrcpResultHandler::ListPlayerAppValueRsp,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::GetPlayerAppValueRspRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothAvrcpResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothAvrcpResultHandler::GetPlayerAppValueRsp,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::GetPlayerAppAttrTextRspRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothAvrcpResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothAvrcpResultHandler::GetPlayerAppAttrTextRsp,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::GetPlayerAppValueTextRspRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothAvrcpResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothAvrcpResultHandler::GetPlayerAppValueTextRsp,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::GetElementAttrRspRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothAvrcpResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothAvrcpResultHandler::GetElementAttrRsp,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::SetPlayerAppValueRspRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothAvrcpResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothAvrcpResultHandler::SetPlayerAppValueRsp,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::RegisterNotificationRspRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothAvrcpResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothAvrcpResultHandler::RegisterNotificationRsp,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::SetVolumeRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothAvrcpResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothAvrcpResultHandler::SetVolume,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::HandleRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonAvrcpModule::* const HandleRsp[])(
-    const DaemonSocketPDUHeader&,
-    DaemonSocketPDU&,
-    BluetoothAvrcpResultHandler*) = {
-    [OPCODE_ERROR] =
-      &BluetoothDaemonAvrcpModule::ErrorRsp,
-    [OPCODE_GET_PLAY_STATUS_RSP] =
-      &BluetoothDaemonAvrcpModule::GetPlayStatusRspRsp,
-    [OPCODE_LIST_PLAYER_APP_ATTR_RSP] =
-      &BluetoothDaemonAvrcpModule::ListPlayerAppAttrRspRsp,
-    [OPCODE_LIST_PLAYER_APP_VALUE_RSP] =
-      &BluetoothDaemonAvrcpModule::ListPlayerAppValueRspRsp,
-    [OPCODE_GET_PLAYER_APP_VALUE_RSP] =
-      &BluetoothDaemonAvrcpModule::GetPlayerAppValueRspRsp,
-    [OPCODE_GET_PLAYER_APP_ATTR_TEXT_RSP] =
-      &BluetoothDaemonAvrcpModule::GetPlayerAppAttrTextRspRsp,
-    [OPCODE_GET_PLAYER_APP_VALUE_TEXT_RSP] =
-      &BluetoothDaemonAvrcpModule::GetPlayerAppValueTextRspRsp,
-    [OPCODE_GET_ELEMENT_ATTR_RSP]=
-      &BluetoothDaemonAvrcpModule::GetElementAttrRspRsp,
-    [OPCODE_SET_PLAYER_APP_VALUE_RSP] =
-      &BluetoothDaemonAvrcpModule::SetPlayerAppValueRspRsp,
-    [OPCODE_REGISTER_NOTIFICATION_RSP] =
-      &BluetoothDaemonAvrcpModule::RegisterNotificationRspRsp,
-    [OPCODE_SET_VOLUME] =
-      &BluetoothDaemonAvrcpModule::SetVolumeRsp
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-  if (NS_WARN_IF(!(aHeader.mOpcode < MOZ_ARRAY_LENGTH(HandleRsp))) ||
-      NS_WARN_IF(!HandleRsp[aHeader.mOpcode])) {
-    return;
-  }
-
-  RefPtr<BluetoothAvrcpResultHandler> res =
-    static_cast<BluetoothAvrcpResultHandler*>(aRes);
-
-  if (!res) {
-    return; // Return early if no result handler has been set for response
-  }
-
-  (this->*(HandleRsp[aHeader.mOpcode]))(aHeader, aPDU, res);
-}
-
-// Notifications
-//
-
-// Returns the current notification handler to a notification runnable
-class BluetoothDaemonAvrcpModule::NotificationHandlerWrapper final
-{
-public:
-  typedef BluetoothAvrcpNotificationHandler ObjectType;
-
-  static ObjectType* GetInstance()
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    return sNotificationHandler;
-  }
-};
-
-// Init operator class for RemoteFeatureNotification
-class BluetoothDaemonAvrcpModule::RemoteFeatureInitOp final
-  : private PDUInitOp
-{
-public:
-  RemoteFeatureInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothAddress& aArg1, unsigned long& aArg2) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read address */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read feature */
-    rv = UnpackPDU(
-      pdu,
-      UnpackConversion<BluetoothAvrcpRemoteFeatureBits, unsigned long>(aArg2));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonAvrcpModule::RemoteFeatureNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  RemoteFeatureNotification::Dispatch(
-    &BluetoothAvrcpNotificationHandler::RemoteFeatureNotification,
-    RemoteFeatureInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::GetPlayStatusNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  GetPlayStatusNotification::Dispatch(
-    &BluetoothAvrcpNotificationHandler::GetPlayStatusNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::ListPlayerAppAttrNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ListPlayerAppAttrNotification::Dispatch(
-    &BluetoothAvrcpNotificationHandler::ListPlayerAppAttrNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::ListPlayerAppValuesNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ListPlayerAppValuesNotification::Dispatch(
-    &BluetoothAvrcpNotificationHandler::ListPlayerAppValuesNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-// Init operator class for GetPlayerAppValueNotification
-class BluetoothDaemonAvrcpModule::GetPlayerAppValueInitOp final
-  : private PDUInitOp
-{
-public:
-  GetPlayerAppValueInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (uint8_t& aArg1,
-               UniquePtr<BluetoothAvrcpPlayerAttribute[]>& aArg2) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read number of attributes */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read attributes */
-    rv = UnpackPDU(
-      pdu, UnpackArray<BluetoothAvrcpPlayerAttribute>(aArg2, aArg1));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonAvrcpModule::GetPlayerAppValueNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  GetPlayerAppValueNotification::Dispatch(
-    &BluetoothAvrcpNotificationHandler::GetPlayerAppValueNotification,
-    GetPlayerAppValueInitOp(aPDU));
-}
-
-// Init operator class for GetPlayerAppAttrsTextNotification
-class BluetoothDaemonAvrcpModule::GetPlayerAppAttrsTextInitOp final
-  : private PDUInitOp
-{
-public:
-  GetPlayerAppAttrsTextInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (uint8_t& aArg1,
-               UniquePtr<BluetoothAvrcpPlayerAttribute[]>& aArg2) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read number of attributes */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read attributes */
-    rv = UnpackPDU(
-      pdu, UnpackArray<BluetoothAvrcpPlayerAttribute>(aArg2, aArg1));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonAvrcpModule::GetPlayerAppAttrsTextNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  GetPlayerAppAttrsTextNotification::Dispatch(
-    &BluetoothAvrcpNotificationHandler::GetPlayerAppAttrsTextNotification,
-    GetPlayerAppAttrsTextInitOp(aPDU));
-}
-
-// Init operator class for GetPlayerAppValuesTextNotification
-class BluetoothDaemonAvrcpModule::GetPlayerAppValuesTextInitOp final
-  : private PDUInitOp
-{
-public:
-  GetPlayerAppValuesTextInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (uint8_t& aArg1, uint8_t& aArg2,
-               UniquePtr<uint8_t[]>& aArg3) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read attribute */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read number of values */
-    rv = UnpackPDU(pdu, aArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read values */
-    rv = UnpackPDU(pdu, UnpackArray<uint8_t>(aArg3, aArg2));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonAvrcpModule::GetPlayerAppValuesTextNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  GetPlayerAppValuesTextNotification::Dispatch(
-    &BluetoothAvrcpNotificationHandler::GetPlayerAppValuesTextNotification,
-    GetPlayerAppValuesTextInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::SetPlayerAppValueNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  SetPlayerAppValueNotification::Dispatch(
-    &BluetoothAvrcpNotificationHandler::SetPlayerAppValueNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-// Init operator class for GetElementAttrNotification
-class BluetoothDaemonAvrcpModule::GetElementAttrInitOp final
-  : private PDUInitOp
-{
-public:
-  GetElementAttrInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (uint8_t& aArg1,
-               UniquePtr<BluetoothAvrcpMediaAttribute[]>& aArg2) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read number of attributes */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read attributes */
-    rv = UnpackPDU(
-      pdu, UnpackArray<BluetoothAvrcpMediaAttribute>(aArg2, aArg1));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonAvrcpModule::GetElementAttrNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  GetElementAttrNotification::Dispatch(
-    &BluetoothAvrcpNotificationHandler::GetElementAttrNotification,
-    GetElementAttrInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::RegisterNotificationNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  RegisterNotificationNotification::Dispatch(
-    &BluetoothAvrcpNotificationHandler::RegisterNotificationNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-#if ANDROID_VERSION >= 19
-void
-BluetoothDaemonAvrcpModule::VolumeChangeNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  VolumeChangeNotification::Dispatch(
-    &BluetoothAvrcpNotificationHandler::VolumeChangeNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonAvrcpModule::PassthroughCmdNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  PassthroughCmdNotification::Dispatch(
-    &BluetoothAvrcpNotificationHandler::PassthroughCmdNotification,
-    UnpackPDUInitOp(aPDU));
-}
-#endif
-
-void
-BluetoothDaemonAvrcpModule::HandleNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonAvrcpModule::* const HandleNtf[])(
-    const DaemonSocketPDUHeader&, DaemonSocketPDU&) = {
-#if ANDROID_VERSION >= 19
-    [0] = &BluetoothDaemonAvrcpModule::RemoteFeatureNtf,
-    [1] = &BluetoothDaemonAvrcpModule::GetPlayStatusNtf,
-    [2] = &BluetoothDaemonAvrcpModule::ListPlayerAppAttrNtf,
-    [3] = &BluetoothDaemonAvrcpModule::ListPlayerAppValuesNtf,
-    [4] = &BluetoothDaemonAvrcpModule::GetPlayerAppValueNtf,
-    [5] = &BluetoothDaemonAvrcpModule::GetPlayerAppAttrsTextNtf,
-    [6] = &BluetoothDaemonAvrcpModule::GetPlayerAppValuesTextNtf,
-    [7] = &BluetoothDaemonAvrcpModule::SetPlayerAppValueNtf,
-    [8] = &BluetoothDaemonAvrcpModule::GetElementAttrNtf,
-    [9] = &BluetoothDaemonAvrcpModule::RegisterNotificationNtf,
-    [10] = &BluetoothDaemonAvrcpModule::VolumeChangeNtf,
-    [11] = &BluetoothDaemonAvrcpModule::PassthroughCmdNtf
-#else
-    [0] = &BluetoothDaemonAvrcpModule::GetPlayStatusNtf,
-    [1] = &BluetoothDaemonAvrcpModule::ListPlayerAppAttrNtf,
-    [2] = &BluetoothDaemonAvrcpModule::ListPlayerAppValuesNtf,
-    [3] = &BluetoothDaemonAvrcpModule::GetPlayerAppValueNtf,
-    [4] = &BluetoothDaemonAvrcpModule::GetPlayerAppAttrsTextNtf,
-    [5] = &BluetoothDaemonAvrcpModule::GetPlayerAppValuesTextNtf,
-    [6] = &BluetoothDaemonAvrcpModule::SetPlayerAppValueNtf,
-    [7] = &BluetoothDaemonAvrcpModule::GetElementAttrNtf,
-    [8] = &BluetoothDaemonAvrcpModule::RegisterNotificationNtf
-#endif
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread());
-
-  uint8_t index = aHeader.mOpcode - 0x81;
-
-  if (NS_WARN_IF(!(index < MOZ_ARRAY_LENGTH(HandleNtf))) ||
-      NS_WARN_IF(!HandleNtf[index])) {
-    return;
-  }
-
-  (this->*(HandleNtf[index]))(aHeader, aPDU);
-}
-
-//
-// AVRCP interface
-//
-
-BluetoothDaemonAvrcpInterface::BluetoothDaemonAvrcpInterface(
-  BluetoothDaemonAvrcpModule* aModule)
-  : mModule(aModule)
-{ }
-
-BluetoothDaemonAvrcpInterface::~BluetoothDaemonAvrcpInterface()
-{ }
-
-void
-BluetoothDaemonAvrcpInterface::SetNotificationHandler(
-  BluetoothAvrcpNotificationHandler* aNotificationHandler)
-{
-  MOZ_ASSERT(mModule);
-
-  mModule->SetNotificationHandler(aNotificationHandler);
-}
-
-void
-BluetoothDaemonAvrcpInterface::GetPlayStatusRsp(
-  ControlPlayStatus aPlayStatus, uint32_t aSongLen, uint32_t aSongPos,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->GetPlayStatusRspCmd(aPlayStatus, aSongLen,
-                                             aSongPos, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonAvrcpInterface::ListPlayerAppAttrRsp(
-  int aNumAttr, const BluetoothAvrcpPlayerAttribute* aPAttrs,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ListPlayerAppAttrRspCmd(aNumAttr, aPAttrs, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonAvrcpInterface::ListPlayerAppValueRsp(
-  int aNumVal, uint8_t* aPVals, BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ListPlayerAppValueRspCmd(aNumVal, aPVals, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonAvrcpInterface::GetPlayerAppValueRsp(
-  uint8_t aNumAttrs, const uint8_t* aIds, const uint8_t* aValues,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->GetPlayerAppValueRspCmd(aNumAttrs, aIds,
-                                                 aValues, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonAvrcpInterface::GetPlayerAppAttrTextRsp(
-  int aNumAttr, const uint8_t* aIds, const char** aTexts,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->GetPlayerAppAttrTextRspCmd(aNumAttr, aIds,
-                                                    aTexts, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonAvrcpInterface::GetPlayerAppValueTextRsp(
-  int aNumVal, const uint8_t* aIds, const char** aTexts,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->GetPlayerAppValueTextRspCmd(aNumVal, aIds,
-                                                     aTexts, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonAvrcpInterface::GetElementAttrRsp(
-  uint8_t aNumAttr, const BluetoothAvrcpElementAttribute* aAttr,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->GetElementAttrRspCmd(aNumAttr, aAttr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonAvrcpInterface::SetPlayerAppValueRsp(
-  BluetoothAvrcpStatus aRspStatus, BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->SetPlayerAppValueRspCmd(aRspStatus, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonAvrcpInterface::RegisterNotificationRsp(
-  BluetoothAvrcpEvent aEvent,
-  BluetoothAvrcpNotification aType,
-  const BluetoothAvrcpNotificationParam& aParam,
-  BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->RegisterNotificationRspCmd(aEvent, aType,
-                                                    aParam, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonAvrcpInterface::SetVolume(
-  uint8_t aVolume, BluetoothAvrcpResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->SetVolumeCmd(aVolume, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonAvrcpInterface::DispatchError(
-  BluetoothAvrcpResultHandler* aRes, BluetoothStatus aStatus)
-{
-  DaemonResultRunnable1<BluetoothAvrcpResultHandler, void,
-                        BluetoothStatus, BluetoothStatus>::Dispatch(
-    aRes, &BluetoothAvrcpResultHandler::OnError,
-    ConstantInitOp1<BluetoothStatus>(aStatus));
-}
-
-void
-BluetoothDaemonAvrcpInterface::DispatchError(
-  BluetoothAvrcpResultHandler* aRes, nsresult aRv)
-{
-  BluetoothStatus status;
-
-  if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
-    status = STATUS_FAIL;
-  }
-  DispatchError(aRes, status);
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonAvrcpInterface.h
+++ /dev/null
@@ -1,350 +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_BluetoothDaemonAvrcpInterface_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothDaemonAvrcpInterface_h
-
-#include "BluetoothDaemonHelpers.h"
-#include "BluetoothInterface.h"
-#include "mozilla/ipc/DaemonRunnables.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using mozilla::ipc::DaemonSocketPDU;
-using mozilla::ipc::DaemonSocketPDUHeader;
-using mozilla::ipc::DaemonSocketResultHandler;
-
-class BluetoothDaemonAvrcpModule
-{
-public:
-  enum {
-    SERVICE_ID = 0x08
-  };
-
-  enum {
-    OPCODE_ERROR = 0x00,
-    OPCODE_GET_PLAY_STATUS_RSP = 0x01,
-    OPCODE_LIST_PLAYER_APP_ATTR_RSP = 0x02,
-    OPCODE_LIST_PLAYER_APP_VALUE_RSP = 0x03,
-    OPCODE_GET_PLAYER_APP_VALUE_RSP = 0x04,
-    OPCODE_GET_PLAYER_APP_ATTR_TEXT_RSP = 0x05,
-    OPCODE_GET_PLAYER_APP_VALUE_TEXT_RSP = 0x06,
-    OPCODE_GET_ELEMENT_ATTR_RSP = 0x07,
-    OPCODE_SET_PLAYER_APP_VALUE_RSP = 0x08,
-    OPCODE_REGISTER_NOTIFICATION_RSP = 0x09,
-    OPCODE_SET_VOLUME = 0x0a,
-#if ANDROID_VERSION >= 19
-    OPCODE_REMOTE_FEATURES_NTF = 0x81,
-    OPCODE_GET_PLAY_STATUS_NTF = 0x82,
-    OPCODE_LIST_PLAYER_APP_ATTR_NTF = 0x83,
-    OPCODE_LIST_PLAYER_APP_VALUES_NTF = 0x84,
-    OPCODE_GET_PLAYER_APP_VALUE_NTF = 0x85,
-    OPCODE_GET_PLAYER_APP_ATTRS_TEXT_NTF = 0x86,
-    OPCODE_GET_PLAYER_APP_VALUES_TEXT_NTF = 0x87,
-    OPCODE_SET_PLAYER_APP_VALUE_NTF = 0x88,
-    OPCODE_GET_ELEMENT_ATTR_NTF = 0x89,
-    OPCODE_REGISTER_NOTIFICATION_NTF = 0x8a,
-    OPCODE_VOLUME_CHANGE_NTF = 0x8b,
-    OPCODE_PASSTHROUGH_CMD_NTF = 0x8c
-#else /* defined by BlueZ 5.14 */
-    OPCODE_GET_PLAY_STATUS_NTF = 0x81,
-    OPCODE_LIST_PLAYER_APP_ATTR_NTF = 0x82,
-    OPCODE_LIST_PLAYER_APP_VALUES_NTF = 0x83,
-    OPCODE_GET_PLAYER_APP_VALUE_NTF = 0x84,
-    OPCODE_GET_PLAYER_APP_ATTRS_TEXT_NTF = 0x85,
-    OPCODE_GET_PLAYER_APP_VALUES_TEXT_NTF = 0x86,
-    OPCODE_SET_PLAYER_APP_VALUE_NTF = 0x87,
-    OPCODE_GET_ELEMENT_ATTR_NTF = 0x88,
-    OPCODE_REGISTER_NOTIFICATION_NTF = 0x89
-#endif
-  };
-
-  virtual nsresult Send(DaemonSocketPDU* aPDU,
-                        DaemonSocketResultHandler* aRes) = 0;
-
-  void SetNotificationHandler(
-    BluetoothAvrcpNotificationHandler* aNotificationHandler);
-
-  //
-  // Commands
-  //
-
-  nsresult GetPlayStatusRspCmd(
-    ControlPlayStatus aPlayStatus, uint32_t aSongLen, uint32_t aSongPos,
-    BluetoothAvrcpResultHandler* aRes);
-
-  nsresult ListPlayerAppAttrRspCmd(
-    int aNumAttr, const BluetoothAvrcpPlayerAttribute* aPAttrs,
-    BluetoothAvrcpResultHandler* aRes);
-
-  nsresult ListPlayerAppValueRspCmd(
-    int aNumVal, uint8_t* aPVals, BluetoothAvrcpResultHandler* aRes);
-
-  nsresult GetPlayerAppValueRspCmd(
-    uint8_t aNumAttrs, const uint8_t* aIds, const uint8_t* aValues,
-    BluetoothAvrcpResultHandler* aRes);
-
-  nsresult GetPlayerAppAttrTextRspCmd(
-    int aNumAttr, const uint8_t* aIds, const char** aTexts,
-    BluetoothAvrcpResultHandler* aRes);
-
-  nsresult GetPlayerAppValueTextRspCmd(
-    int aNumVal, const uint8_t* aIds, const char** aTexts,
-    BluetoothAvrcpResultHandler* aRes);
-
-  nsresult GetElementAttrRspCmd(
-    uint8_t aNumAttr, const BluetoothAvrcpElementAttribute* aAttr,
-    BluetoothAvrcpResultHandler* aRes);
-
-  nsresult SetPlayerAppValueRspCmd(
-    BluetoothAvrcpStatus aRspStatus, BluetoothAvrcpResultHandler* aRes);
-
-  nsresult RegisterNotificationRspCmd(
-    BluetoothAvrcpEvent aEvent, BluetoothAvrcpNotification aType,
-    const BluetoothAvrcpNotificationParam& aParam,
-    BluetoothAvrcpResultHandler* aRes);
-
-  nsresult SetVolumeCmd(uint8_t aVolume, BluetoothAvrcpResultHandler* aRes);
-
-protected:
-  void HandleSvc(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes);
-
-  //
-  // Responses
-  //
-
-  typedef mozilla::ipc::DaemonResultRunnable0<
-    BluetoothAvrcpResultHandler, void>
-    ResultRunnable;
-
-  typedef mozilla::ipc::DaemonResultRunnable1<
-    BluetoothAvrcpResultHandler, void, BluetoothStatus, BluetoothStatus>
-    ErrorRunnable;
-
-  void ErrorRsp(const DaemonSocketPDUHeader& aHeader,
-                DaemonSocketPDU& aPDU,
-                BluetoothAvrcpResultHandler* aRes);
-
-  void GetPlayStatusRspRsp(const DaemonSocketPDUHeader& aHeader,
-                           DaemonSocketPDU& aPDU,
-                           BluetoothAvrcpResultHandler* aRes);
-
-  void ListPlayerAppAttrRspRsp(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU,
-                               BluetoothAvrcpResultHandler* aRes);
-
-  void ListPlayerAppValueRspRsp(const DaemonSocketPDUHeader& aHeader,
-                                DaemonSocketPDU& aPDU,
-                                BluetoothAvrcpResultHandler* aRes);
-
-  void GetPlayerAppValueRspRsp(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU,
-                               BluetoothAvrcpResultHandler* aRes);
-
-  void GetPlayerAppAttrTextRspRsp(const DaemonSocketPDUHeader& aHeader,
-                                  DaemonSocketPDU& aPDU,
-                                  BluetoothAvrcpResultHandler* aRes);
-
-  void GetPlayerAppValueTextRspRsp(const DaemonSocketPDUHeader& aHeader,
-                                   DaemonSocketPDU& aPDU,
-                                   BluetoothAvrcpResultHandler* aRes);
-
-  void GetElementAttrRspRsp(const DaemonSocketPDUHeader& aHeader,
-                            DaemonSocketPDU& aPDU,
-                            BluetoothAvrcpResultHandler* aRes);
-
-  void SetPlayerAppValueRspRsp(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU,
-                               BluetoothAvrcpResultHandler* aRes);
-
-  void RegisterNotificationRspRsp(const DaemonSocketPDUHeader& aHeader,
-                                  DaemonSocketPDU& aPDU,
-                                  BluetoothAvrcpResultHandler* aRes);
-
-  void SetVolumeRsp(const DaemonSocketPDUHeader& aHeader,
-                    DaemonSocketPDU& aPDU,
-                    BluetoothAvrcpResultHandler* aRes);
-
-  void HandleRsp(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU,
-                 DaemonSocketResultHandler* aRes);
-
-  //
-  // Notifications
-  //
-
-  class NotificationHandlerWrapper;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, unsigned long,
-    const BluetoothAddress&>
-    RemoteFeatureNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable0<
-    NotificationHandlerWrapper, void>
-    GetPlayStatusNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable0<
-    NotificationHandlerWrapper, void>
-    ListPlayerAppAttrNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable1<
-    NotificationHandlerWrapper, void, BluetoothAvrcpPlayerAttribute>
-    ListPlayerAppValuesNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void, uint8_t,
-    UniquePtr<BluetoothAvrcpPlayerAttribute[]>,
-    uint8_t, const BluetoothAvrcpPlayerAttribute*>
-    GetPlayerAppValueNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void, uint8_t,
-    UniquePtr<BluetoothAvrcpPlayerAttribute[]>,
-    uint8_t, const BluetoothAvrcpPlayerAttribute*>
-    GetPlayerAppAttrsTextNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void, uint8_t, uint8_t,
-    UniquePtr<uint8_t[]>, uint8_t, uint8_t, const uint8_t*>
-    GetPlayerAppValuesTextNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable1<
-    NotificationHandlerWrapper, void, BluetoothAvrcpPlayerSettings,
-    const BluetoothAvrcpPlayerSettings&>
-    SetPlayerAppValueNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void, uint8_t,
-    UniquePtr<BluetoothAvrcpMediaAttribute[]>,
-    uint8_t, const BluetoothAvrcpMediaAttribute*>
-    GetElementAttrNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void, BluetoothAvrcpEvent, uint32_t>
-    RegisterNotificationNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void, uint8_t, uint8_t>
-    VolumeChangeNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void, uint8_t, uint8_t, uint8_t, uint8_t>
-    PassthroughCmdNotification;
-
-  class GetElementAttrInitOp;
-  class GetPlayerAppAttrsTextInitOp;
-  class GetPlayerAppValueInitOp;
-  class GetPlayerAppValuesTextInitOp;
-  class RemoteFeatureInitOp;
-
-  void RemoteFeatureNtf(const DaemonSocketPDUHeader& aHeader,
-                        DaemonSocketPDU& aPDU);
-
-  void GetPlayStatusNtf(const DaemonSocketPDUHeader& aHeader,
-                        DaemonSocketPDU& aPDU);
-
-  void ListPlayerAppAttrNtf(const DaemonSocketPDUHeader& aHeader,
-                            DaemonSocketPDU& aPDU);
-
-  void ListPlayerAppValuesNtf(const DaemonSocketPDUHeader& aHeader,
-                              DaemonSocketPDU& aPDU);
-
-  void GetPlayerAppValueNtf(const DaemonSocketPDUHeader& aHeader,
-                            DaemonSocketPDU& aPDU);
-
-  void GetPlayerAppAttrsTextNtf(const DaemonSocketPDUHeader& aHeader,
-                                DaemonSocketPDU& aPDU);
-
-  void GetPlayerAppValuesTextNtf(const DaemonSocketPDUHeader& aHeader,
-                                 DaemonSocketPDU& aPDU);
-
-  void SetPlayerAppValueNtf(const DaemonSocketPDUHeader& aHeader,
-                            DaemonSocketPDU& aPDU);
-
-  void GetElementAttrNtf(const DaemonSocketPDUHeader& aHeader,
-                         DaemonSocketPDU& aPDU);
-
-  void RegisterNotificationNtf(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU);
-
-  void VolumeChangeNtf(const DaemonSocketPDUHeader& aHeader,
-                       DaemonSocketPDU& aPDU);
-
-  void PassthroughCmdNtf(const DaemonSocketPDUHeader& aHeader,
-                         DaemonSocketPDU& aPDU);
-
-  void HandleNtf(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU,
-                 DaemonSocketResultHandler* aRes);
-
-  static BluetoothAvrcpNotificationHandler* sNotificationHandler;
-};
-
-class BluetoothDaemonAvrcpInterface final
-  : public BluetoothAvrcpInterface
-{
-  class CleanupResultHandler;
-  class InitResultHandler;
-
-public:
-  BluetoothDaemonAvrcpInterface(BluetoothDaemonAvrcpModule* aModule);
-  ~BluetoothDaemonAvrcpInterface();
-
-  void SetNotificationHandler(
-    BluetoothAvrcpNotificationHandler* aNotificationHandler) override;
-
-  void GetPlayStatusRsp(ControlPlayStatus aPlayStatus,
-                        uint32_t aSongLen, uint32_t aSongPos,
-                        BluetoothAvrcpResultHandler* aRes) override;
-
-  void ListPlayerAppAttrRsp(int aNumAttr,
-                            const BluetoothAvrcpPlayerAttribute* aPAttrs,
-                            BluetoothAvrcpResultHandler* aRes) override;
-
-  void ListPlayerAppValueRsp(int aNumVal, uint8_t* aPVals,
-                             BluetoothAvrcpResultHandler* aRes) override;
-
-  void GetPlayerAppValueRsp(uint8_t aNumAttrs, const uint8_t* aIds,
-                            const uint8_t* aValues,
-                            BluetoothAvrcpResultHandler* aRes) override;
-
-  void GetPlayerAppAttrTextRsp(int aNumAttr, const uint8_t* aIds,
-                               const char** aTexts,
-                               BluetoothAvrcpResultHandler* aRes) override;
-
-  void GetPlayerAppValueTextRsp(int aNumVal, const uint8_t* aIds,
-                                const char** aTexts,
-                                BluetoothAvrcpResultHandler* aRes) override;
-
-  void GetElementAttrRsp(uint8_t aNumAttr,
-                         const BluetoothAvrcpElementAttribute* aAttr,
-                         BluetoothAvrcpResultHandler* aRes) override;
-
-  void SetPlayerAppValueRsp(BluetoothAvrcpStatus aRspStatus,
-                            BluetoothAvrcpResultHandler* aRes) override;
-
-  void RegisterNotificationRsp(BluetoothAvrcpEvent aEvent,
-                               BluetoothAvrcpNotification aType,
-                               const BluetoothAvrcpNotificationParam& aParam,
-                               BluetoothAvrcpResultHandler* aRes) override;
-
-  void SetVolume(uint8_t aVolume,
-                 BluetoothAvrcpResultHandler* aRes) override;
-
-private:
-  void DispatchError(BluetoothAvrcpResultHandler* aRes,
-                     BluetoothStatus aStatus);
-  void DispatchError(BluetoothAvrcpResultHandler* aRes, nsresult aRv);
-
-  BluetoothDaemonAvrcpModule* mModule;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothDaemonAvrcpInterface_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonCoreInterface.cpp
+++ /dev/null
@@ -1,1358 +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 "BluetoothDaemonCoreInterface.h"
-#include "mozilla/UniquePtr.h"
-#include "mozilla/Unused.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using namespace mozilla::ipc;
-
-//
-// Core module
-//
-
-const int BluetoothDaemonCoreModule::MAX_NUM_CLIENTS = 1;
-
-BluetoothCoreNotificationHandler*
-  BluetoothDaemonCoreModule::sNotificationHandler;
-
-void
-BluetoothDaemonCoreModule::SetNotificationHandler(
-  BluetoothCoreNotificationHandler* aNotificationHandler)
-{
-  sNotificationHandler = aNotificationHandler;
-}
-
-void
-BluetoothDaemonCoreModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
-                                     DaemonSocketPDU& aPDU,
-                                     DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonCoreModule::* const HandleOp[])(
-    const DaemonSocketPDUHeader&, DaemonSocketPDU&,
-    DaemonSocketResultHandler*) = {
-    [0] = &BluetoothDaemonCoreModule::HandleRsp,
-    [1] = &BluetoothDaemonCoreModule::HandleNtf
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread());
-
-  (this->*(HandleOp[!!(aHeader.mOpcode & 0x80)]))(aHeader, aPDU, aRes);
-}
-
-// Commands
-//
-
-nsresult
-BluetoothDaemonCoreModule::EnableCmd(BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_ENABLE,
-                                0);
-
-  nsresult rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::DisableCmd(BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_DISABLE,
-                                0);
-
-  nsresult rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::GetAdapterPropertiesCmd(
-  BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_ADAPTER_PROPERTIES,
-                                0);
-
-  nsresult rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::GetAdapterPropertyCmd(
-  BluetoothPropertyType aType, BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_ADAPTER_PROPERTY,
-                                0);
-
-  nsresult rv = PackPDU(aType, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::SetAdapterPropertyCmd(
-  const BluetoothProperty& aProperty, BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SET_ADAPTER_PROPERTY,
-                                0);
-
-  nsresult rv = PackPDU(aProperty, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::GetRemoteDevicePropertiesCmd(
-  const BluetoothAddress& aRemoteAddr, BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_REMOTE_DEVICE_PROPERTIES,
-                                0);
-
-  nsresult rv = PackPDU(aRemoteAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::GetRemoteDevicePropertyCmd(
-  const BluetoothAddress& aRemoteAddr,
-  BluetoothPropertyType aType,
-  BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_REMOTE_DEVICE_PROPERTY,
-                                0);
-
-  nsresult rv = PackPDU(aRemoteAddr, aType, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::SetRemoteDevicePropertyCmd(
-  const BluetoothAddress& aRemoteAddr,
-  const BluetoothProperty& aProperty,
-  BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SET_REMOTE_DEVICE_PROPERTY,
-                                0);
-
-  nsresult rv = PackPDU(aRemoteAddr, aProperty, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::GetRemoteServiceRecordCmd(
-  const BluetoothAddress& aRemoteAddr, const BluetoothUuid& aUuid,
-  BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_REMOTE_SERVICE_RECORD,
-                                0);
-
-  nsresult rv = PackPDU(aRemoteAddr, aUuid, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::GetRemoteServicesCmd(
-  const BluetoothAddress& aRemoteAddr, BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_REMOTE_SERVICES,
-                                0);
-
-  nsresult rv = PackPDU(aRemoteAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::StartDiscoveryCmd(BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_START_DISCOVERY,
-                                0);
-
-  nsresult rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::CancelDiscoveryCmd(BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CANCEL_DISCOVERY,
-                                0);
-
-  nsresult rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::CreateBondCmd(const BluetoothAddress& aBdAddr,
-                                         BluetoothTransport aTransport,
-                                         BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CREATE_BOND,
-                                0);
-
-#if ANDROID_VERSION >= 21
-  nsresult rv = PackPDU(aBdAddr, aTransport, *pdu);
-#else
-  nsresult rv = PackPDU(aBdAddr, *pdu);
-#endif
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::RemoveBondCmd(const BluetoothAddress& aBdAddr,
-                                         BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_REMOVE_BOND,
-                                0);
-
-  nsresult rv = PackPDU(aBdAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::CancelBondCmd(const BluetoothAddress& aBdAddr,
-                                         BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CANCEL_BOND,
-                                0);
-
-  nsresult rv = PackPDU(aBdAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::PinReplyCmd(const BluetoothAddress& aBdAddr,
-                                       bool aAccept,
-                                       const BluetoothPinCode& aPinCode,
-                                       BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_PIN_REPLY,
-                                0);
-
-  nsresult rv = PackPDU(aBdAddr, aAccept, aPinCode, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::SspReplyCmd(const BluetoothAddress& aBdAddr,
-                                       BluetoothSspVariant aVariant,
-                                       bool aAccept, uint32_t aPasskey,
-                                       BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SSP_REPLY,
-                                0);
-
-  nsresult rv = PackPDU(aBdAddr, aVariant, aAccept, aPasskey, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::DutModeConfigureCmd(
-  bool aEnable, BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_DUT_MODE_CONFIGURE,
-                                0);
-
-  nsresult rv = PackPDU(aEnable, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::DutModeSendCmd(uint16_t aOpcode,
-                                          uint8_t* aBuf, uint8_t aLen,
-                                          BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_DUT_MODE_SEND,
-                                0);
-
-  nsresult rv = PackPDU(aOpcode, aLen, PackArray<uint8_t>(aBuf, aLen),
-                        *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonCoreModule::LeTestModeCmd(uint16_t aOpcode,
-                                         uint8_t* aBuf, uint8_t aLen,
-                                         BluetoothCoreResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_LE_TEST_MODE,
-                                0);
-
-  nsresult rv = PackPDU(aOpcode, aLen, PackArray<uint8_t>(aBuf, aLen),
-                        *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-// Responses
-//
-
-void
-BluetoothDaemonCoreModule::ErrorRsp(const DaemonSocketPDUHeader& aHeader,
-                                    DaemonSocketPDU& aPDU,
-                                    BluetoothCoreResultHandler* aRes)
-{
-  ErrorRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::OnError, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::EnableRsp(const DaemonSocketPDUHeader& aHeader,
-                                     DaemonSocketPDU& aPDU,
-                                     BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::Enable, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::DisableRsp(const DaemonSocketPDUHeader& aHeader,
-                                      DaemonSocketPDU& aPDU,
-                                      BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::Disable, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::GetAdapterPropertiesRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::GetAdapterProperties,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::GetAdapterPropertyRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::GetAdapterProperty,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::SetAdapterPropertyRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::SetAdapterProperty,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::GetRemoteDevicePropertiesRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::GetRemoteDeviceProperties,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::GetRemoteDevicePropertyRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::GetRemoteDeviceProperty,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::SetRemoteDevicePropertyRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::SetRemoteDeviceProperty,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::GetRemoteServiceRecordRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::GetRemoteServiceRecord,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::GetRemoteServicesRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::GetRemoteServices,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::StartDiscoveryRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::StartDiscovery,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::CancelDiscoveryRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::CancelDiscovery,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::CreateBondRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::CreateBond,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::RemoveBondRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::RemoveBond,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::CancelBondRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::CancelBond,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::PinReplyRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::PinReply,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::SspReplyRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::SspReply,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::DutModeConfigureRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::DutModeConfigure,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::DutModeSendRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::DutModeSend,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::LeTestModeRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothCoreResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothCoreResultHandler::LeTestMode,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::HandleRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonCoreModule::* const HandleRsp[])(
-    const DaemonSocketPDUHeader&,
-    DaemonSocketPDU&,
-    BluetoothCoreResultHandler*) = {
-    [OPCODE_ERROR] =
-      &BluetoothDaemonCoreModule::ErrorRsp,
-    [OPCODE_ENABLE] =
-      &BluetoothDaemonCoreModule::EnableRsp,
-    [OPCODE_DISABLE] =
-      &BluetoothDaemonCoreModule::DisableRsp,
-    [OPCODE_GET_ADAPTER_PROPERTIES] =
-      &BluetoothDaemonCoreModule::GetAdapterPropertiesRsp,
-    [OPCODE_GET_ADAPTER_PROPERTY] =
-      &BluetoothDaemonCoreModule::GetAdapterPropertyRsp,
-    [OPCODE_SET_ADAPTER_PROPERTY] =
-      &BluetoothDaemonCoreModule::SetAdapterPropertyRsp,
-    [OPCODE_GET_REMOTE_DEVICE_PROPERTIES] =
-      &BluetoothDaemonCoreModule::GetRemoteDevicePropertiesRsp,
-    [OPCODE_GET_REMOTE_DEVICE_PROPERTY] =
-      &BluetoothDaemonCoreModule::GetRemoteDevicePropertyRsp,
-    [OPCODE_SET_REMOTE_DEVICE_PROPERTY] =
-      &BluetoothDaemonCoreModule::SetRemoteDevicePropertyRsp,
-    [OPCODE_GET_REMOTE_SERVICE_RECORD] =
-      &BluetoothDaemonCoreModule::GetRemoteServiceRecordRsp,
-    [OPCODE_GET_REMOTE_SERVICES] =
-      &BluetoothDaemonCoreModule::GetRemoteServicesRsp,
-    [OPCODE_START_DISCOVERY] =
-      &BluetoothDaemonCoreModule::StartDiscoveryRsp,
-    [OPCODE_CANCEL_DISCOVERY] =
-      &BluetoothDaemonCoreModule::CancelDiscoveryRsp,
-    [OPCODE_CREATE_BOND] =
-      &BluetoothDaemonCoreModule::CreateBondRsp,
-    [OPCODE_REMOVE_BOND] =
-      &BluetoothDaemonCoreModule::RemoveBondRsp,
-    [OPCODE_CANCEL_BOND] =
-      &BluetoothDaemonCoreModule::CancelBondRsp,
-    [OPCODE_PIN_REPLY] =
-      &BluetoothDaemonCoreModule::PinReplyRsp,
-    [OPCODE_SSP_REPLY] =
-      &BluetoothDaemonCoreModule::SspReplyRsp,
-    [OPCODE_DUT_MODE_CONFIGURE] =
-      &BluetoothDaemonCoreModule::DutModeConfigureRsp,
-    [OPCODE_DUT_MODE_SEND] =
-      &BluetoothDaemonCoreModule::DutModeSendRsp,
-    [OPCODE_LE_TEST_MODE] =
-      &BluetoothDaemonCoreModule::LeTestModeRsp,
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread());
-
-  if (NS_WARN_IF(!(aHeader.mOpcode < MOZ_ARRAY_LENGTH(HandleRsp))) ||
-      NS_WARN_IF(!HandleRsp[aHeader.mOpcode])) {
-    return;
-  }
-
-  RefPtr<BluetoothCoreResultHandler> res =
-    static_cast<BluetoothCoreResultHandler*>(aRes);
-
-  if (!res) {
-    return; // Return early if no result handler has been set for response
-  }
-
-  (this->*(HandleRsp[aHeader.mOpcode]))(aHeader, aPDU, res);
-}
-
-// Notifications
-//
-
-class BluetoothDaemonCoreModule::NotificationHandlerWrapper final
-{
-public:
-  typedef BluetoothCoreNotificationHandler ObjectType;
-
-  static ObjectType* GetInstance()
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    return sNotificationHandler;
-  }
-};
-
-void
-BluetoothDaemonCoreModule::AdapterStateChangedNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  AdapterStateChangedNotification::Dispatch(
-    &BluetoothCoreNotificationHandler::AdapterStateChangedNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-// Init operator class for AdapterPropertiesNotification
-class BluetoothDaemonCoreModule::AdapterPropertiesInitOp final
-  : private PDUInitOp
-{
-public:
-  AdapterPropertiesInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothStatus& aArg1, int& aArg2,
-               UniquePtr<BluetoothProperty[]>& aArg3) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read status */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-        return rv;
-    }
-
-    /* Read number of properties */
-    uint8_t numProperties;
-    rv = UnpackPDU(pdu, numProperties);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    aArg2 = numProperties;
-
-    /* Read properties array */
-    UnpackArray<BluetoothProperty> properties(aArg3, aArg2);
-    rv = UnpackPDU(pdu, properties);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonCoreModule::AdapterPropertiesNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  AdapterPropertiesNotification::Dispatch(
-    &BluetoothCoreNotificationHandler::AdapterPropertiesNotification,
-    AdapterPropertiesInitOp(aPDU));
-}
-
-// Init operator class for RemoteDevicePropertiesNotification
-class BluetoothDaemonCoreModule::RemoteDevicePropertiesInitOp final
-  : private PDUInitOp
-{
-public:
-  RemoteDevicePropertiesInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothStatus& aArg1, BluetoothAddress& aArg2, int& aArg3,
-               UniquePtr<BluetoothProperty[]>& aArg4) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read status */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read address */
-    rv = UnpackPDU(pdu, aArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read number of properties */
-    uint8_t numProperties;
-    rv = UnpackPDU(pdu, numProperties);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    aArg3 = numProperties;
-
-    /* Read properties array */
-    UnpackArray<BluetoothProperty> properties(aArg4, aArg3);
-    rv = UnpackPDU(pdu, properties);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonCoreModule::RemoteDevicePropertiesNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  RemoteDevicePropertiesNotification::Dispatch(
-    &BluetoothCoreNotificationHandler::RemoteDevicePropertiesNotification,
-    RemoteDevicePropertiesInitOp(aPDU));
-}
-
-// Init operator class for DeviceFoundNotification
-class BluetoothDaemonCoreModule::DeviceFoundInitOp final
-  : private PDUInitOp
-{
-public:
-  DeviceFoundInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (int& aArg1, UniquePtr<BluetoothProperty[]>& aArg2) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read number of properties */
-    uint8_t numProperties;
-    nsresult rv = UnpackPDU(pdu, numProperties);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    aArg1 = numProperties;
-
-    /* Read properties array */
-    UnpackArray<BluetoothProperty> properties(aArg2, aArg1);
-    rv = UnpackPDU(pdu, properties);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonCoreModule::DeviceFoundNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  DeviceFoundNotification::Dispatch(
-    &BluetoothCoreNotificationHandler::DeviceFoundNotification,
-    DeviceFoundInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::DiscoveryStateChangedNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  DiscoveryStateChangedNotification::Dispatch(
-    &BluetoothCoreNotificationHandler::DiscoveryStateChangedNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::PinRequestNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  PinRequestNotification::Dispatch(
-    &BluetoothCoreNotificationHandler::PinRequestNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::SspRequestNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  SspRequestNotification::Dispatch(
-    &BluetoothCoreNotificationHandler::SspRequestNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::BondStateChangedNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  BondStateChangedNotification::Dispatch(
-    &BluetoothCoreNotificationHandler::BondStateChangedNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::AclStateChangedNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  AclStateChangedNotification::Dispatch(
-    &BluetoothCoreNotificationHandler::AclStateChangedNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-// Init operator class for DutModeRecvNotification
-class BluetoothDaemonCoreModule::DutModeRecvInitOp final
-  : private PDUInitOp
-{
-public:
-  DutModeRecvInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (uint16_t& aArg1, UniquePtr<uint8_t[]>& aArg2,
-               uint8_t& aArg3) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read opcode */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read length */
-    rv = UnpackPDU(pdu, aArg3);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read data */
-    rv = UnpackPDU(pdu, UnpackArray<uint8_t>(aArg2, aArg3));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonCoreModule::DutModeRecvNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  DutModeRecvNotification::Dispatch(
-    &BluetoothCoreNotificationHandler::DutModeRecvNotification,
-    DutModeRecvInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::LeTestModeNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  LeTestModeNotification::Dispatch(
-    &BluetoothCoreNotificationHandler::LeTestModeNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonCoreModule::HandleNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonCoreModule::* const HandleNtf[])(
-    const DaemonSocketPDUHeader&, DaemonSocketPDU&) = {
-    [0] = &BluetoothDaemonCoreModule::AdapterStateChangedNtf,
-    [1] = &BluetoothDaemonCoreModule::AdapterPropertiesNtf,
-    [2] = &BluetoothDaemonCoreModule::RemoteDevicePropertiesNtf,
-    [3] = &BluetoothDaemonCoreModule::DeviceFoundNtf,
-    [4] = &BluetoothDaemonCoreModule::DiscoveryStateChangedNtf,
-    [5] = &BluetoothDaemonCoreModule::PinRequestNtf,
-    [6] = &BluetoothDaemonCoreModule::SspRequestNtf,
-    [7] = &BluetoothDaemonCoreModule::BondStateChangedNtf,
-    [8] = &BluetoothDaemonCoreModule::AclStateChangedNtf,
-    [9] = &BluetoothDaemonCoreModule::DutModeRecvNtf,
-    [10] = &BluetoothDaemonCoreModule::LeTestModeNtf
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread());
-
-  uint8_t index = aHeader.mOpcode - 0x81;
-
-  if (NS_WARN_IF(!(index < MOZ_ARRAY_LENGTH(HandleNtf))) ||
-      NS_WARN_IF(!HandleNtf[index])) {
-    return;
-  }
-
-    (this->*(HandleNtf[index]))(aHeader, aPDU);
-}
-
-//
-// Core interface
-//
-
-BluetoothDaemonCoreInterface::BluetoothDaemonCoreInterface(
-  BluetoothDaemonCoreModule* aModule)
-  : mModule(aModule)
-{ }
-
-BluetoothDaemonCoreInterface::~BluetoothDaemonCoreInterface()
-{ }
-
-void
-BluetoothDaemonCoreInterface::SetNotificationHandler(
-  BluetoothCoreNotificationHandler* aNotificationHandler)
-{
-  MOZ_ASSERT(mModule);
-
-  mModule->SetNotificationHandler(aNotificationHandler);
-}
-
-/* Enable / Disable */
-
-void
-BluetoothDaemonCoreInterface::Enable(BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->EnableCmd(aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonCoreInterface::Disable(BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->DisableCmd(aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Adapter Properties */
-
-void
-BluetoothDaemonCoreInterface::GetAdapterProperties(
-  BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->GetAdapterPropertiesCmd(aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonCoreInterface::GetAdapterProperty(
-  BluetoothPropertyType aType, BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->GetAdapterPropertyCmd(aType, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonCoreInterface::SetAdapterProperty(
-  const BluetoothProperty& aProperty, BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->SetAdapterPropertyCmd(aProperty, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Remote Device Properties */
-
-void
-BluetoothDaemonCoreInterface::GetRemoteDeviceProperties(
-  const BluetoothAddress& aRemoteAddr, BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->GetRemoteDevicePropertiesCmd(aRemoteAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonCoreInterface::GetRemoteDeviceProperty(
-  const BluetoothAddress& aRemoteAddr, BluetoothPropertyType aType,
-  BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->GetRemoteDevicePropertyCmd(aRemoteAddr, aType, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonCoreInterface::SetRemoteDeviceProperty(
-  const BluetoothAddress& aRemoteAddr, const BluetoothProperty& aProperty,
-  BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->SetRemoteDevicePropertyCmd(aRemoteAddr,
-                                                    aProperty,
-                                                    aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Remote Services */
-
-void
-BluetoothDaemonCoreInterface::GetRemoteServiceRecord(
-  const BluetoothAddress& aRemoteAddr, const BluetoothUuid& aUuid,
-  BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->GetRemoteServiceRecordCmd(aRemoteAddr, aUuid, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonCoreInterface::GetRemoteServices(
-  const BluetoothAddress& aRemoteAddr, BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->GetRemoteServicesCmd(aRemoteAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Discovery */
-
-void
-BluetoothDaemonCoreInterface::StartDiscovery(BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->StartDiscoveryCmd(aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonCoreInterface::CancelDiscovery(BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->CancelDiscoveryCmd(aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Bonds */
-
-void
-BluetoothDaemonCoreInterface::CreateBond(const BluetoothAddress& aBdAddr,
-                                         BluetoothTransport aTransport,
-                                         BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->CreateBondCmd(aBdAddr, aTransport, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonCoreInterface::RemoveBond(const BluetoothAddress& aBdAddr,
-                                         BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->RemoveBondCmd(aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonCoreInterface::CancelBond(
-  const BluetoothAddress& aBdAddr, BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->CancelBondCmd(aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Connection */
-
-void
-BluetoothDaemonCoreInterface::GetConnectionState(
-  const BluetoothAddress& aBdAddr, BluetoothCoreResultHandler* aRes)
-{
-  // NO-OP: no corresponding interface of current BlueZ
-}
-
-/* Authentication */
-
-void
-BluetoothDaemonCoreInterface::PinReply(const BluetoothAddress& aBdAddr,
-                                       bool aAccept,
-                                       const BluetoothPinCode& aPinCode,
-                                       BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->PinReplyCmd(aBdAddr, aAccept, aPinCode, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonCoreInterface::SspReply(const BluetoothAddress& aBdAddr,
-                                       BluetoothSspVariant aVariant,
-                                       bool aAccept, uint32_t aPasskey,
-                                       BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->SspReplyCmd(aBdAddr, aVariant, aAccept, aPasskey,
-                                     aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* DUT Mode */
-
-void
-BluetoothDaemonCoreInterface::DutModeConfigure(
-  bool aEnable, BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->DutModeConfigureCmd(aEnable, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonCoreInterface::DutModeSend(uint16_t aOpcode,
-                                          uint8_t* aBuf,
-                                          uint8_t aLen,
-                                          BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->DutModeSendCmd(aOpcode, aBuf, aLen, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* LE Mode */
-
-void
-BluetoothDaemonCoreInterface::LeTestMode(uint16_t aOpcode,
-                                         uint8_t* aBuf,
-                                         uint8_t aLen,
-                                         BluetoothCoreResultHandler* aRes)
-{
-  nsresult rv = mModule->LeTestModeCmd(aOpcode, aBuf, aLen, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Energy Information */
-
-void
-BluetoothDaemonCoreInterface::ReadEnergyInfo(BluetoothCoreResultHandler* aRes)
-{
-  // NO-OP: no corresponding interface of current BlueZ
-}
-
-void
-BluetoothDaemonCoreInterface::DispatchError(BluetoothCoreResultHandler* aRes,
-                                            BluetoothStatus aStatus)
-{
-  DaemonResultRunnable1<
-    BluetoothCoreResultHandler, void,
-    BluetoothStatus, BluetoothStatus>::Dispatch(
-    aRes, &BluetoothCoreResultHandler::OnError,
-    ConstantInitOp1<BluetoothStatus>(aStatus));
-}
-
-void
-BluetoothDaemonCoreInterface::DispatchError(BluetoothCoreResultHandler* aRes,
-                                            nsresult aRv)
-{
-  BluetoothStatus status;
-
-  if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
-    status = STATUS_FAIL;
-  }
-  DispatchError(aRes, status);
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonCoreInterface.h
+++ /dev/null
@@ -1,442 +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_BluetoothDaemonCoreInterface_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothDaemonCoreInterface_h
-
-#include "BluetoothDaemonHelpers.h"
-#include "BluetoothInterface.h"
-#include "mozilla/ipc/DaemonRunnables.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using mozilla::ipc::DaemonSocketPDU;
-using mozilla::ipc::DaemonSocketPDUHeader;
-using mozilla::ipc::DaemonSocketResultHandler;
-
-class BluetoothDaemonCoreModule
-{
-public:
-  enum {
-    SERVICE_ID = 0x01
-  };
-
-  enum {
-    OPCODE_ERROR = 0x00,
-    OPCODE_ENABLE = 0x01,
-    OPCODE_DISABLE = 0x02,
-    OPCODE_GET_ADAPTER_PROPERTIES = 0x03,
-    OPCODE_GET_ADAPTER_PROPERTY = 0x04,
-    OPCODE_SET_ADAPTER_PROPERTY = 0x05,
-    OPCODE_GET_REMOTE_DEVICE_PROPERTIES = 0x06,
-    OPCODE_GET_REMOTE_DEVICE_PROPERTY = 0x07,
-    OPCODE_SET_REMOTE_DEVICE_PROPERTY = 0x08,
-    OPCODE_GET_REMOTE_SERVICE_RECORD = 0x09,
-    OPCODE_GET_REMOTE_SERVICES = 0x0a,
-    OPCODE_START_DISCOVERY = 0x0b,
-    OPCODE_CANCEL_DISCOVERY = 0x0c,
-    OPCODE_CREATE_BOND = 0x0d,
-    OPCODE_REMOVE_BOND = 0x0e,
-    OPCODE_CANCEL_BOND = 0x0f,
-    OPCODE_PIN_REPLY = 0x10,
-    OPCODE_SSP_REPLY = 0x11,
-    OPCODE_DUT_MODE_CONFIGURE = 0x12,
-    OPCODE_DUT_MODE_SEND = 0x13,
-    OPCODE_LE_TEST_MODE = 0x14,
-    OPCODE_ADAPTER_STATE_CHANGED_NTF = 0x81,
-    OPCODE_ADAPTER_PROPERTIES_NTF = 0x82,
-    OPCODE_REMOTE_DEVICE_PROPERTIES_NTF = 0x83,
-    OPCODE_DEVICE_FOUND_NTF = 0x84,
-    OPCODE_DISCOVERY_STATE_CHANGED_NTF = 0x85,
-    OPCODE_PIN_REQUEST_NTF = 0x86,
-    OPCODE_SSP_REQUEST_NTF = 0x87,
-    OPCODE_BOND_STATE_CHANGED_NTF = 0x88,
-    OPCODE_ACL_STATE_CHANGED_NTF = 0x89,
-    OPCODE_DUT_MODE_RECV_NTF = 0x8a,
-    OPCODE_LE_TEST_MODE_NTF = 0x8b
-  };
-
-  static const int MAX_NUM_CLIENTS;
-
-  virtual nsresult Send(DaemonSocketPDU* aPDU,
-                        DaemonSocketResultHandler* aRes) = 0;
-
-  void SetNotificationHandler(
-    BluetoothCoreNotificationHandler* aNotificationHandler);
-
-  //
-  // Commands
-  //
-
-  nsresult EnableCmd(BluetoothCoreResultHandler* aRes);
-
-  nsresult DisableCmd(BluetoothCoreResultHandler* aRes);
-
-  nsresult GetAdapterPropertiesCmd(BluetoothCoreResultHandler* aRes);
-
-  nsresult GetAdapterPropertyCmd(BluetoothPropertyType aType,
-                                 BluetoothCoreResultHandler* aRes);
-
-  nsresult SetAdapterPropertyCmd(const BluetoothProperty& aProperty,
-                                 BluetoothCoreResultHandler* aRes);
-
-  nsresult GetRemoteDevicePropertiesCmd(const BluetoothAddress& aRemoteAddr,
-                                        BluetoothCoreResultHandler* aRes);
-
-  nsresult GetRemoteDevicePropertyCmd(const BluetoothAddress& aRemoteAddr,
-                                      BluetoothPropertyType aType,
-                                      BluetoothCoreResultHandler* aRes);
-
-  nsresult SetRemoteDevicePropertyCmd(const BluetoothAddress& aRemoteAddr,
-                                      const BluetoothProperty& aProperty,
-                                      BluetoothCoreResultHandler* aRes);
-
-  nsresult GetRemoteServiceRecordCmd(const BluetoothAddress& aRemoteAddr,
-                                     const BluetoothUuid& aUuid,
-                                     BluetoothCoreResultHandler* aRes);
-
-  nsresult GetRemoteServicesCmd(const BluetoothAddress& aRemoteAddr,
-                                BluetoothCoreResultHandler* aRes);
-
-  nsresult StartDiscoveryCmd(BluetoothCoreResultHandler* aRes);
-
-  nsresult CancelDiscoveryCmd(BluetoothCoreResultHandler* aRes);
-
-  nsresult CreateBondCmd(const BluetoothAddress& aBdAddr,
-                         BluetoothTransport aTransport,
-                         BluetoothCoreResultHandler* aRes);
-
-  nsresult RemoveBondCmd(const BluetoothAddress& aBdAddr,
-                         BluetoothCoreResultHandler* aRes);
-
-  nsresult CancelBondCmd(const BluetoothAddress& aBdAddr,
-                         BluetoothCoreResultHandler* aRes);
-
-  nsresult PinReplyCmd(const BluetoothAddress& aBdAddr, bool aAccept,
-                       const BluetoothPinCode& aPinCode,
-                       BluetoothCoreResultHandler* aRes);
-
-  nsresult SspReplyCmd(const BluetoothAddress& aBdAddr,
-                       BluetoothSspVariant aVariant,
-                       bool aAccept, uint32_t aPasskey,
-                       BluetoothCoreResultHandler* aRes);
-
-  nsresult DutModeConfigureCmd(bool aEnable,
-                               BluetoothCoreResultHandler* aRes);
-
-  nsresult DutModeSendCmd(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
-                          BluetoothCoreResultHandler* aRes);
-
-  nsresult LeTestModeCmd(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
-                         BluetoothCoreResultHandler* aRes);
-
-protected:
-  void HandleSvc(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes);
-
-private:
-
-  //
-  // Responses
-  //
-
-  typedef mozilla::ipc::DaemonResultRunnable0<
-    BluetoothCoreResultHandler, void>
-    ResultRunnable;
-
-  typedef mozilla::ipc::DaemonResultRunnable1<
-    BluetoothCoreResultHandler, void, BluetoothStatus, BluetoothStatus>
-    ErrorRunnable;
-
-  void ErrorRsp(const DaemonSocketPDUHeader& aHeader,
-                DaemonSocketPDU& aPDU,
-                BluetoothCoreResultHandler* aRes);
-
-  void EnableRsp(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU,
-                 BluetoothCoreResultHandler* aRes);
-
-  void DisableRsp(const DaemonSocketPDUHeader& aHeader,
-                  DaemonSocketPDU& aPDU,
-                  BluetoothCoreResultHandler* aRes);
-
-  void GetAdapterPropertiesRsp(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU,
-                               BluetoothCoreResultHandler* aRes);
-
-  void GetAdapterPropertyRsp(const DaemonSocketPDUHeader& aHeader,
-                             DaemonSocketPDU& aPDU,
-                             BluetoothCoreResultHandler* aRes);
-
-  void SetAdapterPropertyRsp(const DaemonSocketPDUHeader& aHeader,
-                             DaemonSocketPDU& aPDU,
-                             BluetoothCoreResultHandler* aRes);
-
-  void GetRemoteDevicePropertiesRsp(const DaemonSocketPDUHeader& aHeader,
-                                    DaemonSocketPDU& aPDU,
-                                    BluetoothCoreResultHandler* aRes);
-
-  void GetRemoteDevicePropertyRsp(const DaemonSocketPDUHeader& aHeader,
-                                  DaemonSocketPDU& aPDU,
-                                  BluetoothCoreResultHandler* aRes);
-
-  void SetRemoteDevicePropertyRsp(const DaemonSocketPDUHeader& aHeader,
-                                  DaemonSocketPDU& aPDU,
-                                  BluetoothCoreResultHandler* aRes);
-  void GetRemoteServiceRecordRsp(const DaemonSocketPDUHeader& aHeader,
-                                 DaemonSocketPDU& aPDU,
-                                 BluetoothCoreResultHandler* aRes);
-  void GetRemoteServicesRsp(const DaemonSocketPDUHeader& aHeader,
-                            DaemonSocketPDU& aPDU,
-                            BluetoothCoreResultHandler* aRes);
-
-  void StartDiscoveryRsp(const DaemonSocketPDUHeader& aHeader,
-                         DaemonSocketPDU& aPDU,
-                         BluetoothCoreResultHandler* aRes);
-  void CancelDiscoveryRsp(const DaemonSocketPDUHeader& aHeader,
-                          DaemonSocketPDU& aPDU,
-                          BluetoothCoreResultHandler* aRes);
-
-  void CreateBondRsp(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU,
-                     BluetoothCoreResultHandler* aRes);
-  void RemoveBondRsp(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU,
-                     BluetoothCoreResultHandler* aRes);
-  void CancelBondRsp(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU,
-                     BluetoothCoreResultHandler* aRes);
-
-  void PinReplyRsp(const DaemonSocketPDUHeader& aHeader,
-                   DaemonSocketPDU& aPDU,
-                   BluetoothCoreResultHandler* aRes);
-  void SspReplyRsp(const DaemonSocketPDUHeader& aHeader,
-                   DaemonSocketPDU& aPDU,
-                   BluetoothCoreResultHandler* aRes);
-
-  void DutModeConfigureRsp(const DaemonSocketPDUHeader& aHeader,
-                           DaemonSocketPDU& aPDU,
-                           BluetoothCoreResultHandler* aRes);
-
-  void DutModeSendRsp(const DaemonSocketPDUHeader& aHeader,
-                      DaemonSocketPDU& aPDU,
-                      BluetoothCoreResultHandler* aRes);
-
-  void LeTestModeRsp(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU,
-                     BluetoothCoreResultHandler* aRes);
-
-  void HandleRsp(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes);
-
-  //
-  // Notifications
-  //
-
-  class NotificationHandlerWrapper;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable1<
-    NotificationHandlerWrapper, void, bool>
-    AdapterStateChangedNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void, BluetoothStatus, int,
-    UniquePtr<BluetoothProperty[]>, BluetoothStatus, int,
-    const BluetoothProperty*>
-    AdapterPropertiesNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable4<
-    NotificationHandlerWrapper, void, BluetoothStatus, BluetoothAddress, int,
-    UniquePtr<BluetoothProperty[]>, BluetoothStatus,
-    const BluetoothAddress&, int, const BluetoothProperty*>
-    RemoteDevicePropertiesNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void, int, UniquePtr<BluetoothProperty[]>,
-    int, const BluetoothProperty*>
-    DeviceFoundNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable1<
-    NotificationHandlerWrapper, void, bool>
-    DiscoveryStateChangedNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, BluetoothRemoteName, uint32_t,
-    const BluetoothAddress&, const BluetoothRemoteName&>
-    PinRequestNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable5<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, BluetoothRemoteName, uint32_t, BluetoothSspVariant,
-    uint32_t,
-    const BluetoothAddress&, const BluetoothRemoteName&>
-    SspRequestNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void, BluetoothStatus, BluetoothAddress,
-    BluetoothBondState, BluetoothStatus, const BluetoothAddress&>
-    BondStateChangedNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    BluetoothStatus, BluetoothAddress, BluetoothAclState,
-    BluetoothStatus, const BluetoothAddress&>
-    AclStateChangedNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void, uint16_t, UniquePtr<uint8_t[]>,
-    uint8_t, uint16_t, const uint8_t*>
-    DutModeRecvNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void, BluetoothStatus, uint16_t>
-    LeTestModeNotification;
-
-  class AdapterPropertiesInitOp;
-  class DeviceFoundInitOp;
-  class DutModeRecvInitOp;
-  class RemoteDevicePropertiesInitOp;
-
-  void AdapterStateChangedNtf(const DaemonSocketPDUHeader& aHeader,
-                              DaemonSocketPDU& aPDU);
-
-  void AdapterPropertiesNtf(const DaemonSocketPDUHeader& aHeader,
-                            DaemonSocketPDU& aPDU);
-
-  void RemoteDevicePropertiesNtf(const DaemonSocketPDUHeader& aHeader,
-                                 DaemonSocketPDU& aPDU);
-
-  void DeviceFoundNtf(const DaemonSocketPDUHeader& aHeader,
-                      DaemonSocketPDU& aPDU);
-
-  void DiscoveryStateChangedNtf(const DaemonSocketPDUHeader& aHeader,
-                                DaemonSocketPDU& aPDU);
-
-  void PinRequestNtf(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU);
-
-  void SspRequestNtf(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU);
-
-  void BondStateChangedNtf(const DaemonSocketPDUHeader& aHeader,
-                           DaemonSocketPDU& aPDU);
-
-  void AclStateChangedNtf(const DaemonSocketPDUHeader& aHeader,
-                          DaemonSocketPDU& aPDU);
-
-  void DutModeRecvNtf(const DaemonSocketPDUHeader& aHeader,
-                      DaemonSocketPDU& aPDU);
-
-  void LeTestModeNtf(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU);
-
-  void HandleNtf(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes);
-
-  static BluetoothCoreNotificationHandler* sNotificationHandler;
-};
-
-class BluetoothDaemonCoreInterface final
-  : public BluetoothCoreInterface
-{
-public:
-  BluetoothDaemonCoreInterface(BluetoothDaemonCoreModule* aModule);
-  ~BluetoothDaemonCoreInterface();
-
-  void SetNotificationHandler(
-    BluetoothCoreNotificationHandler* aNotificationHandler) override;
-
-  /* Enable / Disable */
-
-  void Enable(BluetoothCoreResultHandler* aRes) override;
-  void Disable(BluetoothCoreResultHandler* aRes) override;
-
-  /* Adapter Properties */
-
-  void GetAdapterProperties(BluetoothCoreResultHandler* aRes) override;
-  void GetAdapterProperty(BluetoothPropertyType aType,
-                          BluetoothCoreResultHandler* aRes) override;
-  void SetAdapterProperty(const BluetoothProperty& aProperty,
-                          BluetoothCoreResultHandler* aRes) override;
-
-  /* Remote Device Properties */
-
-  void GetRemoteDeviceProperties(const BluetoothAddress& aRemoteAddr,
-                                 BluetoothCoreResultHandler* aRes) override;
-  void GetRemoteDeviceProperty(const BluetoothAddress& aRemoteAddr,
-                               BluetoothPropertyType aType,
-                               BluetoothCoreResultHandler* aRes) override;
-  void SetRemoteDeviceProperty(const BluetoothAddress& aRemoteAddr,
-                               const BluetoothProperty& aProperty,
-                               BluetoothCoreResultHandler* aRes) override;
-
-  /* Remote Services */
-
-  void GetRemoteServiceRecord(const BluetoothAddress& aRemoteAddr,
-                              const BluetoothUuid& aUuid,
-                              BluetoothCoreResultHandler* aRes) override;
-  void GetRemoteServices(const BluetoothAddress& aRemoteAddr,
-                         BluetoothCoreResultHandler* aRes) override;
-
-  /* Discovery */
-
-  void StartDiscovery(BluetoothCoreResultHandler* aRes) override;
-  void CancelDiscovery(BluetoothCoreResultHandler* aRes) override;
-
-  /* Bonds */
-
-  void CreateBond(const BluetoothAddress& aBdAddr,
-                  BluetoothTransport aTransport,
-                  BluetoothCoreResultHandler* aRes) override;
-  void RemoveBond(const BluetoothAddress& aBdAddr,
-                  BluetoothCoreResultHandler* aRes) override;
-  void CancelBond(const BluetoothAddress& aBdAddr,
-                  BluetoothCoreResultHandler* aRes) override;
-
-  /* Connection */
-
-  void GetConnectionState(const BluetoothAddress& aBdAddr,
-                          BluetoothCoreResultHandler* aRes) override;
-
-  /* Authentication */
-
-  void PinReply(const BluetoothAddress& aBdAddr, bool aAccept,
-                const BluetoothPinCode& aPinCode,
-                BluetoothCoreResultHandler* aRes) override;
-
-  void SspReply(const BluetoothAddress& aBdAddr,
-                BluetoothSspVariant aVariant,
-                bool aAccept, uint32_t aPasskey,
-                BluetoothCoreResultHandler* aRes) override;
-
-  /* DUT Mode */
-
-  void DutModeConfigure(bool aEnable, BluetoothCoreResultHandler* aRes);
-  void DutModeSend(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
-                   BluetoothCoreResultHandler* aRes) override;
-
-  /* LE Mode */
-
-  void LeTestMode(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
-                  BluetoothCoreResultHandler* aRes) override;
-
-  /* Energy Information */
-
-  void ReadEnergyInfo(BluetoothCoreResultHandler* aRes) override;
-
-private:
-  void DispatchError(BluetoothCoreResultHandler* aRes,
-                     BluetoothStatus aStatus);
-  void DispatchError(BluetoothCoreResultHandler* aRes,
-                     nsresult aRv);
-
-  BluetoothDaemonCoreModule* mModule;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothDaemonCoreInterface_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonGattInterface.cpp
+++ /dev/null
@@ -1,2689 +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 "BluetoothDaemonGattInterface.h"
-#include "mozilla/UniquePtr.h"
-#include "mozilla/Unused.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using namespace mozilla::ipc;
-
-//
-// GATT module
-//
-
-BluetoothGattNotificationHandler*
-  BluetoothDaemonGattModule::sNotificationHandler;
-
-void
-BluetoothDaemonGattModule::SetNotificationHandler(
-  BluetoothGattNotificationHandler* aNotificationHandler)
-{
-  sNotificationHandler = aNotificationHandler;
-}
-
-void
-BluetoothDaemonGattModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
-                                     DaemonSocketPDU& aPDU,
-                                     DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonGattModule::* const HandleOp[])(
-    const DaemonSocketPDUHeader&, DaemonSocketPDU&,
-    DaemonSocketResultHandler*) = {
-    [0] = &BluetoothDaemonGattModule::HandleRsp,
-    [1] = &BluetoothDaemonGattModule::HandleNtf
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread());
-
-  // Negate twice to map bit to 0/1
-  unsigned long isNtf = !!(aHeader.mOpcode & 0x80);
-
-  (this->*(HandleOp[isNtf]))(aHeader, aPDU, aRes);
-}
-
-// Commands
-//
-
-nsresult
-BluetoothDaemonGattModule::ClientRegisterCmd(
-  const BluetoothUuid& aUuid, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_REGISTER,
-                                16); // Service UUID
-
-  nsresult rv = PackPDU(aUuid, *pdu);
-
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientUnregisterCmd(
-  int aClientIf, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_UNREGISTER,
-                                4); // Client Interface
-
-  nsresult rv = PackPDU(aClientIf, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientScanCmd(
-  int aClientIf, bool aStart, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_SCAN,
-                                4 + // Client Interface
-                                1); // Start
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aClientIf),
-                        PackConversion<bool, uint8_t>(aStart), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientConnectCmd(
-  int aClientIf, const BluetoothAddress& aBdAddr, bool aIsDirect,
-  BluetoothTransport aTransport, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_CONNECT,
-                                4 + // Client Interface
-                                6 + // Remote Address
-                                1 + // Is Direct
-                                4); // Transport
-
-  nsresult rv = PackPDU(
-    PackConversion<int, int32_t>(aClientIf),
-    aBdAddr,
-    PackConversion<bool, uint8_t>(aIsDirect),
-    PackConversion<BluetoothTransport, int32_t>(aTransport), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientDisconnectCmd(
-  int aClientIf, const BluetoothAddress& aBdAddr, int aConnId,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_DISCONNECT,
-                                4 + // Client Interface
-                                6 + // Remote Address
-                                4); // Connection ID
-
-  nsresult rv;
-  rv = PackPDU(PackConversion<int, int32_t>(aClientIf),
-               aBdAddr,
-               PackConversion<int, int32_t>(aConnId), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientListenCmd(
-  int aClientIf, bool aIsStart, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_LISTEN,
-                                4 + // Client Interface
-                                1); // Start
-
-  nsresult rv;
-  rv = PackPDU(PackConversion<int, int32_t>(aClientIf),
-               PackConversion<bool, uint8_t>(aIsStart), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientRefreshCmd(
-  int aClientIf, const BluetoothAddress& aBdAddr,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_REFRESH,
-                                4 + // Client Interface
-                                6); // Remote Address
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aClientIf),
-                        aBdAddr,
-                        *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientSearchServiceCmd(
-  int aConnId, bool aFiltered, const BluetoothUuid& aUuid,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_SEARCH_SERVICE,
-                                4 + // Connection ID
-                                1 + // Filtered
-                                16); // UUID
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aConnId),
-                        PackConversion<bool, uint8_t>(aFiltered),
-                        PackReversed<BluetoothUuid>(aUuid),
-                        *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientGetIncludedServiceCmd(
-  int aConnId, const BluetoothGattServiceId& aServiceId, bool aContinuation,
-  const BluetoothGattServiceId& aStartServiceId,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_GET_INCLUDED_SERVICE,
-                                4 + // Connection ID
-                                18 + // Service ID
-                                1 + // Continuation
-                                18); // Start Service ID
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aConnId), aServiceId,
-                        PackConversion<bool, uint8_t>(aContinuation),
-                        aStartServiceId, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientGetCharacteristicCmd(
-  int aConnId, const BluetoothGattServiceId& aServiceId, bool aContinuation,
-  const BluetoothGattId& aStartCharId,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_GET_CHARACTERISTIC,
-                                4 + // Connection ID
-                                18 + // Service ID
-                                1 + // Continuation
-                                17); // Start Characteristic ID
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aConnId), aServiceId,
-                        PackConversion<bool, uint8_t>(aContinuation),
-                        aStartCharId, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientGetDescriptorCmd(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId, bool aContinuation,
-  const BluetoothGattId& aStartDescriptorId,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_GET_DESCRIPTOR,
-                                4 + // Connection ID
-                                18 + // Service ID
-                                17 + // Characteristic ID
-                                1 + // Continuation
-                                17); // Start Descriptor ID
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aConnId),
-                        aServiceId, aCharId,
-                        PackConversion<bool, uint8_t>(aContinuation),
-                        aStartDescriptorId, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientReadCharacteristicCmd(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId, BluetoothGattAuthReq aAuthReq,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_READ_CHARACTERISTIC,
-                                4 + // Connection ID
-                                18 + // Service ID
-                                17 + // Characteristic ID
-                                4); // Authorization
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aConnId), aServiceId,
-                        aCharId, aAuthReq, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientWriteCharacteristicCmd(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId, BluetoothGattWriteType aWriteType,
-  int aLength, BluetoothGattAuthReq aAuthReq, char* aValue,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_WRITE_CHARACTERISTIC,
-                                0);
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aConnId), aServiceId,
-                        aCharId, aWriteType,
-                        PackConversion<int, int32_t>(aLength), aAuthReq,
-                        PackArray<char>(aValue, aLength), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientReadDescriptorCmd(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId, const BluetoothGattId& aDescriptorId,
-  BluetoothGattAuthReq aAuthReq, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_READ_DESCRIPTOR,
-                                4 + // Connection ID
-                                18 + // Service ID
-                                17 + // Characteristic ID
-                                17 + // Descriptor ID
-                                4); // Authorization
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aConnId), aServiceId,
-                        aCharId, aDescriptorId, aAuthReq, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientWriteDescriptorCmd(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId, const BluetoothGattId& aDescriptorId,
-  BluetoothGattWriteType aWriteType, int aLength,
-  BluetoothGattAuthReq aAuthReq, char* aValue,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_WRITE_DESCRIPTOR,
-                                0);
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aConnId), aServiceId,
-                        aCharId, aDescriptorId, aWriteType,
-                        PackConversion<int, int32_t>(aLength), aAuthReq,
-                        PackArray<char>(aValue, aLength), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientExecuteWriteCmd(
-  int aConnId, int aIsExecute, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_EXECUTE_WRITE,
-                                4 + // Connection ID
-                                4); // Execute
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aConnId),
-                        PackConversion<int, int32_t>(aIsExecute), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientRegisterNotificationCmd(
-  int aClientIf, const BluetoothAddress& aBdAddr,
-  const BluetoothGattServiceId& aServiceId, const BluetoothGattId& aCharId,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_REGISTER_NOTIFICATION,
-                                4 + // Client Interface
-                                6 + // Remote Address
-                                18 + // Service ID
-                                17); // Characteristic ID
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aClientIf),
-                        aBdAddr, aServiceId, aCharId, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientDeregisterNotificationCmd(
-  int aClientIf, const BluetoothAddress& aBdAddr,
-  const BluetoothGattServiceId& aServiceId, const BluetoothGattId& aCharId,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_DEREGISTER_NOTIFICATION,
-                                4 + // Client Interface
-                                6 + // Remote Address
-                                18 + // Service ID
-                                17); // Characteristic ID
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aClientIf),
-                        aBdAddr, aServiceId, aCharId, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientReadRemoteRssiCmd(
-  int aClientIf, const BluetoothAddress& aBdAddr,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_READ_REMOTE_RSSI,
-                                4 + // Client Interface
-                                6); // Remote Address
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aClientIf),
-                        aBdAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientGetDeviceTypeCmd(
-  const BluetoothAddress& aBdAddr, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_GET_DEVICE_TYPE,
-                                6); // Remote Address
-
-  nsresult rv = PackPDU(aBdAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientSetAdvDataCmd(
-  int aServerIf, bool aIsScanRsp, bool aIsNameIncluded,
-  bool aIsTxPowerIncluded, int aMinInterval, int aMaxInterval, int aApperance,
-  const nsTArray<uint8_t>& aManufacturerData,
-  const nsTArray<uint8_t>& aServiceData,
-  const nsTArray<BluetoothUuid>& aServiceUuids,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_SET_ADV_DATA,
-                                0);
-
-  uint16_t manufacturerDataByteLen =
-    aManufacturerData.Length() * sizeof(uint8_t);
-  uint16_t serviceDataByteLen = aServiceData.Length() * sizeof(uint8_t);
-  uint16_t serviceUuidsByteLen =
-    aServiceUuids.Length() * sizeof(BluetoothUuid::mUuid);
-  uint8_t* manufacturerData =
-    const_cast<uint8_t*>(aManufacturerData.Elements());
-  uint8_t* serviceData = const_cast<uint8_t*>(aServiceData.Elements());
-  BluetoothUuid* serviceUuids =
-    const_cast<BluetoothUuid*>(aServiceUuids.Elements());
-
-  nsresult rv = PackPDU(
-    PackConversion<int, int32_t>(aServerIf),
-    PackConversion<bool, uint8_t>(aIsScanRsp),
-    PackConversion<bool, uint8_t>(aIsNameIncluded),
-    PackConversion<bool, uint8_t>(aIsTxPowerIncluded),
-    PackConversion<int, int32_t>(aMinInterval),
-    PackConversion<int, int32_t>(aMaxInterval),
-    PackConversion<int, int32_t>(aApperance),
-    manufacturerDataByteLen, serviceDataByteLen, serviceUuidsByteLen,
-    PackArray<uint8_t>(manufacturerData, aManufacturerData.Length()),
-    PackArray<uint8_t>(serviceData, aServiceData.Length()),
-    PackArray<PackReversed<BluetoothUuid>>(
-      serviceUuids, aServiceUuids.Length()),
-    *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ClientTestCommandCmd(
-  int aCommand, const BluetoothGattTestParam& aTestParam,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLIENT_TEST_COMMAND,
-                                4 + // Command
-                                6 + // Address
-                                16 + // UUID
-                                2 + // U1
-                                2 + // U2
-                                2 + // U3
-                                2 + // U4
-                                2); // U5
-
-  nsresult rv = PackPDU(
-    PackConversion<int, int32_t>(aCommand),
-    aTestParam.mBdAddr,
-    aTestParam.mU1, aTestParam.mU2, aTestParam.mU3, aTestParam.mU4,
-    aTestParam.mU5, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ServerRegisterCmd(
-  const BluetoothUuid& aUuid, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SERVER_REGISTER,
-                                16); // Uuid
-
-  nsresult rv = PackPDU(aUuid, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ServerUnregisterCmd(
-  int aServerIf, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SERVER_UNREGISTER,
-                                4); // Server Interface
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aServerIf), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ServerConnectPeripheralCmd(
-  int aServerIf, const BluetoothAddress& aBdAddr, bool aIsDirect,
-  BluetoothTransport aTransport, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SERVER_CONNECT_PERIPHERAL,
-                                4 + // Server Interface
-                                6 + // Remote Address
-                                1 + // Is Direct
-                                4); // Transport
-
-  nsresult rv = PackPDU(
-    PackConversion<int, int32_t>(aServerIf),
-    aBdAddr,
-    PackConversion<bool, uint8_t>(aIsDirect),
-    PackConversion<BluetoothTransport, int32_t>(aTransport), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ServerDisconnectPeripheralCmd(
-  int aServerIf, const BluetoothAddress& aBdAddr, int aConnId,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SERVER_DISCONNECT_PERIPHERAL,
-                                4 + // Server Interface
-                                6 + // Remote Address
-                                4); // Connection Id
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aServerIf),
-                        aBdAddr,
-                        PackConversion<int, int32_t>(aConnId), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ServerAddServiceCmd(
-  int aServerIf, const BluetoothGattServiceId& aServiceId, uint16_t aNumHandles,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SERVER_ADD_SERVICE,
-                                4 + // Server Interface
-                                18 + // Service ID
-                                4); // Number of Handles
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aServerIf), aServiceId,
-                        PackConversion<uint16_t, int32_t>(aNumHandles), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ServerAddIncludedServiceCmd(
-  int aServerIf, const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aIncludedServiceHandle,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SERVER_ADD_INCLUDED_SERVICE,
-                                4 + // Server Interface
-                                4 + // Service Handle
-                                4); // Included Service Handle
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aServerIf),
-                        aServiceHandle, aIncludedServiceHandle, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ServerAddCharacteristicCmd(
-  int aServerIf, const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothUuid& aUuid, BluetoothGattCharProp aProperties,
-  BluetoothGattAttrPerm aPermissions, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SERVER_ADD_CHARACTERISTIC,
-                                4 + // Server Interface
-                                4 + // Service Handle
-                                16 + // UUID
-                                4 + // Properties
-                                4); // Permissions
-
-  nsresult rv = PackPDU(
-    PackConversion<int, int32_t>(aServerIf), aServiceHandle,
-    PackReversed<BluetoothUuid>(aUuid),
-    PackConversion<BluetoothGattCharProp, int32_t>(aProperties),
-    PackConversion<BluetoothGattAttrPerm, int32_t>(aPermissions), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ServerAddDescriptorCmd(
-  int aServerIf, const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothUuid& aUuid, BluetoothGattAttrPerm aPermissions,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SERVER_ADD_DESCRIPTOR,
-                                4 + // Server Interface
-                                4 + // Service Handle
-                                16 + // UUID
-                                4); // Permissions
-
-  nsresult rv = PackPDU(
-    PackConversion<int, int32_t>(aServerIf), aServiceHandle,
-    PackReversed<BluetoothUuid>(aUuid),
-    PackConversion<BluetoothGattAttrPerm, int32_t>(aPermissions), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ServerStartServiceCmd(
-  int aServerIf, const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothTransport aTransport, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SERVER_START_SERVICE,
-                                4 + // Server Interface
-                                4 + // Service Handle
-                                4); // Transport
-
-  nsresult rv = PackPDU(
-    PackConversion<int, int32_t>(aServerIf), aServiceHandle,
-    PackConversion<BluetoothTransport, int32_t>(aTransport), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ServerStopServiceCmd(
-  int aServerIf, const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SERVER_STOP_SERVICE,
-                                4 + // Server Interface
-                                4); // Service Handle
-
-  nsresult rv = PackPDU(
-    PackConversion<int, int32_t>(aServerIf), aServiceHandle, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ServerDeleteServiceCmd(
-  int aServerIf, const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SERVER_DELETE_SERVICE,
-                                4 + // Server Interface
-                                4); // Service Handle
-
-  nsresult rv = PackPDU(
-    PackConversion<int, int32_t>(aServerIf), aServiceHandle, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ServerSendIndicationCmd(
-  int aServerIf, const BluetoothAttributeHandle& aCharacteristicHandle,
-  int aConnId, int aLength, bool aConfirm,
-  uint8_t* aValue, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SERVER_SEND_INDICATION,
-                                0);
-
-  nsresult rv = PackPDU(PackConversion<int, int32_t>(aServerIf),
-                        aCharacteristicHandle,
-                        PackConversion<int, int32_t>(aConnId),
-                        PackConversion<int, int32_t>(aLength),
-                        PackConversion<bool, int32_t>(aConfirm),
-                        PackArray<uint8_t>(aValue, aLength), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonGattModule::ServerSendResponseCmd(
-  int aConnId, int aTransId, uint16_t aStatus,
-  const BluetoothGattResponse& aResponse,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SERVER_SEND_RESPONSE,
-                                0);
-
-  nsresult rv = PackPDU(
-    PackConversion<int, int32_t>(aConnId),
-    PackConversion<int, int32_t>(aTransId),
-    PackConversion<BluetoothAttributeHandle, uint16_t>(aResponse.mHandle),
-    aResponse.mOffset,
-    PackConversion<BluetoothGattAuthReq, uint8_t>(aResponse.mAuthReq),
-    PackConversion<uint16_t, int32_t>(aStatus),
-    aResponse.mLength,
-    PackArray<uint8_t>(aResponse.mValue, aResponse.mLength), *pdu);
-
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-// Responses
-//
-
-void
-BluetoothDaemonGattModule::ErrorRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothGattResultHandler* aRes)
-{
-  ErrorRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::OnError, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientRegisterRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::RegisterClient,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientUnregisterRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::UnregisterClient,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientScanRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::Scan, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientConnectRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::Connect, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientDisconnectRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::Disconnect,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientListenRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::Listen, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientRefreshRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::Refresh, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientSearchServiceRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::SearchService,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientGetIncludedServiceRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::GetIncludedService,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientGetCharacteristicRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::GetCharacteristic,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientGetDescriptorRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::GetDescriptor,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientReadCharacteristicRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::ReadCharacteristic,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientWriteCharacteristicRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::WriteCharacteristic,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientReadDescriptorRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::ReadDescriptor,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientWriteDescriptorRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::WriteDescriptor,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientExecuteWriteRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::ExecuteWrite,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientRegisterNotificationRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::RegisterNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientDeregisterNotificationRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::DeregisterNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientReadRemoteRssiRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::ReadRemoteRssi,
-    UnpackPDUInitOp(aPDU));
-}
-
-// Init operator class for ClientGetDeviceTypeRsp
-class BluetoothDaemonGattModule::ClientGetDeviceTypeInitOp final
-  : private PDUInitOp
-{
-public:
-  ClientGetDeviceTypeInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothTypeOfDevice& aArg1) const
-  {
-    /* Read device type */
-    nsresult rv = UnpackPDU(
-      GetPDU(), UnpackConversion<uint8_t, BluetoothTypeOfDevice>(aArg1));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonGattModule::ClientGetDeviceTypeRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ClientGetDeviceTypeResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::GetDeviceType,
-    ClientGetDeviceTypeInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientSetAdvDataRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::SetAdvData,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientTestCommandRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::TestCommand,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerRegisterRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::RegisterServer,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerUnregisterRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::UnregisterServer,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerConnectPeripheralRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::ConnectPeripheral,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerDisconnectPeripheralRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::DisconnectPeripheral,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerAddServiceRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::AddService,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerAddIncludedServiceRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::AddIncludedService,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerAddCharacteristicRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::AddCharacteristic,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerAddDescriptorRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::AddDescriptor,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerStartServiceRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::StartService,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerStopServiceRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::StopService,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerDeleteServiceRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::DeleteService,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerSendIndicationRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::SendIndication,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerSendResponseRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothGattResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothGattResultHandler::SendResponse,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::HandleRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonGattModule::* const HandleRsp[])(
-    const DaemonSocketPDUHeader&,
-    DaemonSocketPDU&,
-    BluetoothGattResultHandler*) = {
-    [OPCODE_ERROR] =
-      &BluetoothDaemonGattModule::ErrorRsp,
-    [OPCODE_CLIENT_REGISTER] =
-      &BluetoothDaemonGattModule::ClientRegisterRsp,
-    [OPCODE_CLIENT_UNREGISTER] =
-      &BluetoothDaemonGattModule::ClientUnregisterRsp,
-    [OPCODE_CLIENT_SCAN] =
-      &BluetoothDaemonGattModule::ClientScanRsp,
-    [OPCODE_CLIENT_CONNECT] =
-      &BluetoothDaemonGattModule::ClientConnectRsp,
-    [OPCODE_CLIENT_DISCONNECT] =
-      &BluetoothDaemonGattModule::ClientDisconnectRsp,
-    [OPCODE_CLIENT_LISTEN] =
-      &BluetoothDaemonGattModule::ClientListenRsp,
-    [OPCODE_CLIENT_REFRESH] =
-      &BluetoothDaemonGattModule::ClientRefreshRsp,
-    [OPCODE_CLIENT_SEARCH_SERVICE] =
-      &BluetoothDaemonGattModule::ClientSearchServiceRsp,
-    [OPCODE_CLIENT_GET_INCLUDED_SERVICE] =
-      &BluetoothDaemonGattModule::ClientGetIncludedServiceRsp,
-    [OPCODE_CLIENT_GET_CHARACTERISTIC] =
-      &BluetoothDaemonGattModule::ClientGetCharacteristicRsp,
-    [OPCODE_CLIENT_GET_DESCRIPTOR] =
-      &BluetoothDaemonGattModule::ClientGetDescriptorRsp,
-    [OPCODE_CLIENT_READ_CHARACTERISTIC] =
-      &BluetoothDaemonGattModule::ClientReadCharacteristicRsp,
-    [OPCODE_CLIENT_WRITE_CHARACTERISTIC] =
-      &BluetoothDaemonGattModule::ClientWriteCharacteristicRsp,
-    [OPCODE_CLIENT_READ_DESCRIPTOR] =
-      &BluetoothDaemonGattModule::ClientReadDescriptorRsp,
-    [OPCODE_CLIENT_WRITE_DESCRIPTOR] =
-      &BluetoothDaemonGattModule::ClientWriteDescriptorRsp,
-    [OPCODE_CLIENT_EXECUTE_WRITE] =
-      &BluetoothDaemonGattModule::ClientExecuteWriteRsp,
-    [OPCODE_CLIENT_REGISTER_NOTIFICATION] =
-      &BluetoothDaemonGattModule::ClientRegisterNotificationRsp,
-    [OPCODE_CLIENT_DEREGISTER_NOTIFICATION] =
-      &BluetoothDaemonGattModule::ClientDeregisterNotificationRsp,
-    [OPCODE_CLIENT_READ_REMOTE_RSSI] =
-      &BluetoothDaemonGattModule::ClientReadRemoteRssiRsp,
-    [OPCODE_CLIENT_GET_DEVICE_TYPE] =
-      &BluetoothDaemonGattModule::ClientGetDeviceTypeRsp,
-    [OPCODE_CLIENT_SET_ADV_DATA] =
-      &BluetoothDaemonGattModule::ClientSetAdvDataRsp,
-    [OPCODE_CLIENT_TEST_COMMAND] =
-      &BluetoothDaemonGattModule::ClientTestCommandRsp,
-    [OPCODE_SERVER_REGISTER] =
-      &BluetoothDaemonGattModule::ServerRegisterRsp,
-    [OPCODE_SERVER_UNREGISTER] =
-      &BluetoothDaemonGattModule::ServerUnregisterRsp,
-    [OPCODE_SERVER_CONNECT_PERIPHERAL] =
-      &BluetoothDaemonGattModule::ServerConnectPeripheralRsp,
-    [OPCODE_SERVER_DISCONNECT_PERIPHERAL] =
-      &BluetoothDaemonGattModule::ServerDisconnectPeripheralRsp,
-    [OPCODE_SERVER_ADD_SERVICE] =
-      &BluetoothDaemonGattModule::ServerAddServiceRsp,
-    [OPCODE_SERVER_ADD_INCLUDED_SERVICE] =
-      &BluetoothDaemonGattModule::ServerAddIncludedServiceRsp,
-    [OPCODE_SERVER_ADD_CHARACTERISTIC] =
-      &BluetoothDaemonGattModule::ServerAddCharacteristicRsp,
-    [OPCODE_SERVER_ADD_DESCRIPTOR] =
-      &BluetoothDaemonGattModule::ServerAddDescriptorRsp,
-    [OPCODE_SERVER_START_SERVICE] =
-      &BluetoothDaemonGattModule::ServerStartServiceRsp,
-    [OPCODE_SERVER_STOP_SERVICE] =
-      &BluetoothDaemonGattModule::ServerStopServiceRsp,
-    [OPCODE_SERVER_DELETE_SERVICE] =
-      &BluetoothDaemonGattModule::ServerDeleteServiceRsp,
-    [OPCODE_SERVER_SEND_INDICATION] =
-      &BluetoothDaemonGattModule::ServerSendIndicationRsp,
-    [OPCODE_SERVER_SEND_RESPONSE] =
-      &BluetoothDaemonGattModule::ServerSendResponseRsp
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-  if (NS_WARN_IF(!(aHeader.mOpcode < MOZ_ARRAY_LENGTH(HandleRsp))) ||
-      NS_WARN_IF(!HandleRsp[aHeader.mOpcode])) {
-    return;
-  }
-
-  RefPtr<BluetoothGattResultHandler> res =
-    static_cast<BluetoothGattResultHandler*>(aRes);
-
-  if (!res) {
-    return;
-  } // Return early if no result handler has been set for response
-
-  (this->*(HandleRsp[aHeader.mOpcode]))(aHeader, aPDU, res);
-}
-
-// Notifications
-//
-
-// Returns the current notification handler to a notification runnable
-class BluetoothDaemonGattModule::NotificationHandlerWrapper final
-{
-public:
-  typedef BluetoothGattNotificationHandler ObjectType;
-
-  static ObjectType* GetInstance()
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    return sNotificationHandler;
-  }
-};
-
-void
-BluetoothDaemonGattModule::ClientRegisterNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientRegisterNotification::Dispatch(
-    &BluetoothGattNotificationHandler::RegisterClientNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-// Init operator class for ClientScanResultNotification
-class BluetoothDaemonGattModule::ClientScanResultInitOp final
-  : private PDUInitOp
-{
-public:
-  ClientScanResultInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothAddress& aArg1,
-               int& aArg2,
-               BluetoothGattAdvData& aArg3) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read address */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read RSSI */
-    rv = UnpackPDU(pdu, aArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read Length */
-    uint16_t length;
-    rv = UnpackPDU(pdu, length);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read Adv Data */
-    rv = UnpackPDU(pdu, UnpackArray<uint8_t>(aArg3.mAdvData, length));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonGattModule::ClientScanResultNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientScanResultNotification::Dispatch(
-    &BluetoothGattNotificationHandler::ScanResultNotification,
-    ClientScanResultInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientConnectNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientConnectNotification::Dispatch(
-    &BluetoothGattNotificationHandler::ConnectNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientDisconnectNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientDisconnectNotification::Dispatch(
-    &BluetoothGattNotificationHandler::DisconnectNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientSearchCompleteNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientSearchCompleteNotification::Dispatch(
-    &BluetoothGattNotificationHandler::SearchCompleteNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientSearchResultNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientSearchResultNotification::Dispatch(
-    &BluetoothGattNotificationHandler::SearchResultNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientGetCharacteristicNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientGetCharacteristicNotification::Dispatch(
-    &BluetoothGattNotificationHandler::GetCharacteristicNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientGetDescriptorNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientGetDescriptorNotification::Dispatch(
-    &BluetoothGattNotificationHandler::GetDescriptorNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientGetIncludedServiceNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientGetIncludedServiceNotification::Dispatch(
-    &BluetoothGattNotificationHandler::GetIncludedServiceNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientRegisterNotificationNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientRegisterNotificationNotification::Dispatch(
-    &BluetoothGattNotificationHandler::RegisterNotificationNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientNotifyNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientNotifyNotification::Dispatch(
-    &BluetoothGattNotificationHandler::NotifyNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientReadCharacteristicNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientReadCharacteristicNotification::Dispatch(
-    &BluetoothGattNotificationHandler::ReadCharacteristicNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientWriteCharacteristicNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientWriteCharacteristicNotification::Dispatch(
-    &BluetoothGattNotificationHandler::WriteCharacteristicNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientReadDescriptorNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientReadDescriptorNotification::Dispatch(
-    &BluetoothGattNotificationHandler::ReadDescriptorNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientWriteDescriptorNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientWriteDescriptorNotification::Dispatch(
-    &BluetoothGattNotificationHandler::WriteDescriptorNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientExecuteWriteNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientExecuteWriteNotification::Dispatch(
-    &BluetoothGattNotificationHandler::ExecuteWriteNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientReadRemoteRssiNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientReadRemoteRssiNotification::Dispatch(
-    &BluetoothGattNotificationHandler::ReadRemoteRssiNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ClientListenNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClientListenNotification::Dispatch(
-    &BluetoothGattNotificationHandler::ListenNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerRegisterNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ServerRegisterNotification::Dispatch(
-    &BluetoothGattNotificationHandler::RegisterServerNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-// Init operator class for ServerConnectionNotification
-class BluetoothDaemonGattModule::ServerConnectionInitOp final
-  : private PDUInitOp
-{
-public:
-  ServerConnectionInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (int& aArg1,
-               int& aArg2,
-               bool& aArg3,
-               BluetoothAddress& aArg4) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read connection ID */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read server interface */
-    rv = UnpackPDU(pdu, aArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read connected */
-    rv = UnpackPDU(pdu, UnpackConversion<int32_t, bool>(aArg3));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read address */
-    rv = UnpackPDU(pdu, aArg4);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonGattModule::ServerConnectionNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ServerConnectionNotification::Dispatch(
-    &BluetoothGattNotificationHandler::ConnectionNotification,
-    ServerConnectionInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerServiceAddedNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ServerServiceAddedNotification::Dispatch(
-    &BluetoothGattNotificationHandler::ServiceAddedNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerIncludedServiceAddedNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ServerIncludedServiceAddedNotification::Dispatch(
-    &BluetoothGattNotificationHandler::IncludedServiceAddedNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-// Init operator class for ServerCharacteristicAddedNotification
-class BluetoothDaemonGattModule::ServerCharacteristicAddedInitOp final
-  : private PDUInitOp
-{
-public:
-  ServerCharacteristicAddedInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothGattStatus& aArg1,
-               int& aArg2,
-               BluetoothUuid& aArg3,
-               BluetoothAttributeHandle& aArg4,
-               BluetoothAttributeHandle& aArg5) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read GATT status */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read server interface */
-    rv = UnpackPDU(pdu, aArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read characteristic UUID */
-    rv = UnpackPDU(pdu, UnpackReversed<BluetoothUuid>(aArg3));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read service handle */
-    rv = UnpackPDU(pdu, aArg4);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read characteristic handle */
-    rv = UnpackPDU(pdu, aArg5);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonGattModule::ServerCharacteristicAddedNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ServerCharacteristicAddedNotification::Dispatch(
-    &BluetoothGattNotificationHandler::CharacteristicAddedNotification,
-    ServerCharacteristicAddedInitOp(aPDU));
-}
-
-// Init operator class for ServerDescriptorAddedNotification
-class BluetoothDaemonGattModule::ServerDescriptorAddedInitOp final
-  : private PDUInitOp
-{
-public:
-  ServerDescriptorAddedInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothGattStatus& aArg1,
-               int& aArg2,
-               BluetoothUuid& aArg3,
-               BluetoothAttributeHandle& aArg4,
-               BluetoothAttributeHandle& aArg5) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read GATT status */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read server interface */
-    rv = UnpackPDU(pdu, aArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read characteristic UUID */
-    rv = UnpackPDU(pdu, UnpackReversed<BluetoothUuid>(aArg3));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read service handle */
-    rv = UnpackPDU(pdu, aArg4);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read descriptor handle */
-    rv = UnpackPDU(pdu, aArg5);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-void
-BluetoothDaemonGattModule::ServerDescriptorAddedNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ServerDescriptorAddedNotification::Dispatch(
-    &BluetoothGattNotificationHandler::DescriptorAddedNotification,
-    ServerDescriptorAddedInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerServiceStartedNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ServerServiceStartedNotification::Dispatch(
-    &BluetoothGattNotificationHandler::ServiceStartedNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerServiceStoppedNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ServerServiceStoppedNotification::Dispatch(
-    &BluetoothGattNotificationHandler::ServiceStoppedNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerServiceDeletedNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ServerServiceDeletedNotification::Dispatch(
-    &BluetoothGattNotificationHandler::ServiceDeletedNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerRequestReadNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ServerRequestReadNotification::Dispatch(
-    &BluetoothGattNotificationHandler::RequestReadNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-// Init operator class for ServerRequestWriteNotification
-class BluetoothDaemonGattModule::ServerRequestWriteInitOp final
-  : private PDUInitOp
-{
-public:
-  ServerRequestWriteInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (int& aArg1,
-               int& aArg2,
-               BluetoothAddress& aArg3,
-               BluetoothAttributeHandle& aArg4,
-               int& aArg5,
-               int& aArg6,
-               UniquePtr<uint8_t[]>& aArg7,
-               bool& aArg8,
-               bool& aArg9) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read connection ID */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read trans ID */
-    rv = UnpackPDU(pdu, aArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read address */
-    rv = UnpackPDU(pdu, aArg3);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read attribute handle */
-    rv = UnpackPDU(pdu, aArg4);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read offset */
-    rv = UnpackPDU(pdu, aArg5);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read Length */
-    rv = UnpackPDU(pdu, aArg6);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read value */
-    rv = UnpackPDU(pdu,
-                   UnpackArray<uint8_t>(aArg7, static_cast<size_t>(aArg6)));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read need response */
-    rv = UnpackPDU(pdu, aArg8);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    /* Read isPrepare */
-    rv = UnpackPDU(pdu, aArg9);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonGattModule::ServerRequestWriteNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ServerRequestWriteNotification::Dispatch(
-    &BluetoothGattNotificationHandler::RequestWriteNotification,
-    ServerRequestWriteInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerRequestExecuteWriteNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ServerRequestExecuteWriteNotification::Dispatch(
-    &BluetoothGattNotificationHandler::RequestExecuteWriteNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::ServerResponseConfirmationNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ServerResponseConfirmationNotification::Dispatch(
-    &BluetoothGattNotificationHandler::ResponseConfirmationNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonGattModule::HandleNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonGattModule::* const HandleNtf[])(
-    const DaemonSocketPDUHeader&, DaemonSocketPDU&) = {
-    [0] = &BluetoothDaemonGattModule::ClientRegisterNtf,
-    [1] = &BluetoothDaemonGattModule::ClientScanResultNtf,
-    [2] = &BluetoothDaemonGattModule::ClientConnectNtf,
-    [3] = &BluetoothDaemonGattModule::ClientDisconnectNtf,
-    [4] = &BluetoothDaemonGattModule::ClientSearchCompleteNtf,
-    [5] = &BluetoothDaemonGattModule::ClientSearchResultNtf,
-    [6] = &BluetoothDaemonGattModule::ClientGetCharacteristicNtf,
-    [7] = &BluetoothDaemonGattModule::ClientGetDescriptorNtf,
-    [8] = &BluetoothDaemonGattModule::ClientGetIncludedServiceNtf,
-    [9] = &BluetoothDaemonGattModule::ClientRegisterNotificationNtf,
-    [10] = &BluetoothDaemonGattModule::ClientNotifyNtf,
-    [11] = &BluetoothDaemonGattModule::ClientReadCharacteristicNtf,
-    [12] = &BluetoothDaemonGattModule::ClientWriteCharacteristicNtf,
-    [13] = &BluetoothDaemonGattModule::ClientReadDescriptorNtf,
-    [14] = &BluetoothDaemonGattModule::ClientWriteDescriptorNtf,
-    [15] = &BluetoothDaemonGattModule::ClientExecuteWriteNtf,
-    [16] = &BluetoothDaemonGattModule::ClientReadRemoteRssiNtf,
-    [17] = &BluetoothDaemonGattModule::ClientListenNtf,
-    [18] = &BluetoothDaemonGattModule::ServerRegisterNtf,
-    [19] = &BluetoothDaemonGattModule::ServerConnectionNtf,
-    [20] = &BluetoothDaemonGattModule::ServerServiceAddedNtf,
-    [21] = &BluetoothDaemonGattModule::ServerIncludedServiceAddedNtf,
-    [22] = &BluetoothDaemonGattModule::ServerCharacteristicAddedNtf,
-    [23] = &BluetoothDaemonGattModule::ServerDescriptorAddedNtf,
-    [24] = &BluetoothDaemonGattModule::ServerServiceStartedNtf,
-    [25] = &BluetoothDaemonGattModule::ServerServiceStoppedNtf,
-    [26] = &BluetoothDaemonGattModule::ServerServiceDeletedNtf,
-    [27] = &BluetoothDaemonGattModule::ServerRequestReadNtf,
-    [28] = &BluetoothDaemonGattModule::ServerRequestWriteNtf,
-    [29] = &BluetoothDaemonGattModule::ServerRequestExecuteWriteNtf,
-    [30] = &BluetoothDaemonGattModule::ServerResponseConfirmationNtf
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread());
-
-  uint8_t index = aHeader.mOpcode - 0x81;
-
-  if (NS_WARN_IF(!(index < MOZ_ARRAY_LENGTH(HandleNtf))) ||
-      NS_WARN_IF(!HandleNtf[index])) {
-    return;
-  }
-
-  (this->*(HandleNtf[index]))(aHeader, aPDU);
-}
-
-//
-// Gatt interface
-//
-
-BluetoothDaemonGattInterface::BluetoothDaemonGattInterface(
-  BluetoothDaemonGattModule* aModule)
-  : mModule(aModule)
-{ }
-
-BluetoothDaemonGattInterface::~BluetoothDaemonGattInterface()
-{ }
-
-void
-BluetoothDaemonGattInterface::SetNotificationHandler(
-  BluetoothGattNotificationHandler* aNotificationHandler)
-{
-  MOZ_ASSERT(mModule);
-
-  mModule->SetNotificationHandler(aNotificationHandler);
-}
-
-/* Register / Unregister */
-void
-BluetoothDaemonGattInterface::RegisterClient(
-  const BluetoothUuid& aUuid, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientRegisterCmd(aUuid, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::UnregisterClient(
-  int aClientIf, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientUnregisterCmd(aClientIf, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Start / Stop LE Scan */
-void
-BluetoothDaemonGattInterface::Scan(
-  int aClientIf, bool aStart, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientScanCmd(aClientIf, aStart, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Connect / Disconnect */
-
-void
-BluetoothDaemonGattInterface::Connect(
-  int aClientIf, const BluetoothAddress& aBdAddr, bool aIsDirect,
-  BluetoothTransport aTransport, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientConnectCmd(
-    aClientIf, aBdAddr, aIsDirect, aTransport, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::Disconnect(
-  int aClientIf, const BluetoothAddress& aBdAddr, int aConnId,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientDisconnectCmd(
-    aClientIf, aBdAddr, aConnId, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Start / Stop advertisements to listen for incoming connections */
-void
-BluetoothDaemonGattInterface::Listen(
-  int aClientIf, bool aIsStart, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientListenCmd(aClientIf, aIsStart, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Clear the attribute cache for a given device*/
-void
-BluetoothDaemonGattInterface::Refresh(
-  int aClientIf, const BluetoothAddress& aBdAddr,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientRefreshCmd(aClientIf, aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Enumerate Attributes */
-void
-BluetoothDaemonGattInterface::SearchService(
-  int aConnId, bool aSearchAll, const BluetoothUuid& aUuid,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientSearchServiceCmd(
-    aConnId, !aSearchAll /* Filtered */, aUuid, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::GetIncludedService(
-  int aConnId, const BluetoothGattServiceId& aServiceId, bool aFirst,
-  const BluetoothGattServiceId& aStartServiceId,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientGetIncludedServiceCmd(
-    aConnId, aServiceId, !aFirst /* Continuation */, aStartServiceId, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::GetCharacteristic(
-  int aConnId, const BluetoothGattServiceId& aServiceId, bool aFirst,
-  const BluetoothGattId& aStartCharId, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientGetCharacteristicCmd(
-    aConnId, aServiceId, !aFirst /* Continuation */, aStartCharId, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::GetDescriptor(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId, bool aFirst,
-  const BluetoothGattId& aDescriptorId, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientGetDescriptorCmd(
-    aConnId, aServiceId, aCharId, !aFirst /* Continuation */, aDescriptorId,
-    aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Read / Write An Attribute */
-void
-BluetoothDaemonGattInterface::ReadCharacteristic(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId, BluetoothGattAuthReq aAuthReq,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientReadCharacteristicCmd(
-    aConnId, aServiceId, aCharId, aAuthReq, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::WriteCharacteristic(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId, BluetoothGattWriteType aWriteType,
-  BluetoothGattAuthReq aAuthReq, const nsTArray<uint8_t>& aValue,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientWriteCharacteristicCmd(
-    aConnId, aServiceId, aCharId, aWriteType,
-    aValue.Length() * sizeof(uint8_t), aAuthReq,
-    reinterpret_cast<char*>(const_cast<uint8_t*>(aValue.Elements())), aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::ReadDescriptor(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId, const BluetoothGattId& aDescriptorId,
-  BluetoothGattAuthReq aAuthReq, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientReadDescriptorCmd(
-    aConnId, aServiceId, aCharId, aDescriptorId, aAuthReq, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::WriteDescriptor(
-  int aConnId, const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId, const BluetoothGattId& aDescriptorId,
-  BluetoothGattWriteType aWriteType, BluetoothGattAuthReq aAuthReq,
-  const nsTArray<uint8_t>& aValue, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientWriteDescriptorCmd(
-    aConnId, aServiceId, aCharId, aDescriptorId, aWriteType,
-    aValue.Length() * sizeof(uint8_t), aAuthReq,
-    reinterpret_cast<char*>(const_cast<uint8_t*>(aValue.Elements())), aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Execute / Abort Prepared Write*/
-void
-BluetoothDaemonGattInterface::ExecuteWrite(
-  int aConnId, int aIsExecute, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientExecuteWriteCmd(aConnId, aIsExecute, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Register / Deregister Characteristic Notifications or Indications */
-void
-BluetoothDaemonGattInterface::RegisterNotification(
-  int aClientIf, const BluetoothAddress& aBdAddr,
-  const BluetoothGattServiceId& aServiceId, const BluetoothGattId& aCharId,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientRegisterNotificationCmd(
-    aClientIf, aBdAddr, aServiceId, aCharId, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::DeregisterNotification(
-  int aClientIf, const BluetoothAddress& aBdAddr,
-  const BluetoothGattServiceId& aServiceId, const BluetoothGattId& aCharId,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientDeregisterNotificationCmd(
-    aClientIf, aBdAddr, aServiceId, aCharId, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::ReadRemoteRssi(
-  int aClientIf, const BluetoothAddress& aBdAddr,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientReadRemoteRssiCmd(
-    aClientIf, aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::GetDeviceType(
-  const BluetoothAddress& aBdAddr, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientGetDeviceTypeCmd(aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::SetAdvData(
-  int aServerIf, bool aIsScanRsp, bool aIsNameIncluded,
-  bool aIsTxPowerIncluded, int aMinInterval, int aMaxInterval, int aApperance,
-  const nsTArray<uint8_t>& aManufacturerData,
-  const nsTArray<uint8_t>& aServiceData,
-  const nsTArray<BluetoothUuid>& aServiceUuids,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientSetAdvDataCmd(
-    aServerIf, aIsScanRsp, aIsNameIncluded, aIsTxPowerIncluded, aMinInterval,
-    aMaxInterval, aApperance, aManufacturerData, aServiceData, aServiceUuids,
-    aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::TestCommand(
-  int aCommand, const BluetoothGattTestParam& aTestParam,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClientTestCommandCmd(aCommand, aTestParam, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Register / Unregister */
-void
-BluetoothDaemonGattInterface::RegisterServer(
-  const BluetoothUuid& aUuid, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ServerRegisterCmd(aUuid, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::UnregisterServer(
-  int aServerIf, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ServerUnregisterCmd(aServerIf, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Connect / Disconnect */
-void
-BluetoothDaemonGattInterface::ConnectPeripheral(
-  int aServerIf, const BluetoothAddress& aBdAddr, bool aIsDirect, /* auto connect */
-  BluetoothTransport aTransport, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ServerConnectPeripheralCmd(
-    aServerIf, aBdAddr, aIsDirect, aTransport, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::DisconnectPeripheral(
-  int aServerIf, const BluetoothAddress& aBdAddr, int aConnId,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ServerDisconnectPeripheralCmd(
-    aServerIf, aBdAddr, aConnId, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Add a services / a characteristic / a descriptor */
-void
-BluetoothDaemonGattInterface::AddService(
-  int aServerIf, const BluetoothGattServiceId& aServiceId, uint16_t aNumHandles,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ServerAddServiceCmd(
-    aServerIf, aServiceId, aNumHandles, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::AddIncludedService(
-  int aServerIf, const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aIncludedServiceHandle,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ServerAddIncludedServiceCmd(
-    aServerIf, aServiceHandle, aIncludedServiceHandle, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::AddCharacteristic(
-  int aServerIf, const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothUuid& aUuid, BluetoothGattCharProp aProperties,
-  BluetoothGattAttrPerm aPermissions, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ServerAddCharacteristicCmd(
-    aServerIf, aServiceHandle, aUuid, aProperties, aPermissions, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::AddDescriptor(
-  int aServerIf, const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothUuid& aUuid, BluetoothGattAttrPerm aPermissions,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ServerAddDescriptorCmd(
-    aServerIf, aServiceHandle, aUuid, aPermissions, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Start / Stop / Delete a service */
-void
-BluetoothDaemonGattInterface::StartService(
-  int aServerIf, const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothTransport aTransport, BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ServerStartServiceCmd(
-    aServerIf, aServiceHandle, aTransport, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::StopService(
-  int aServerIf, const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ServerStopServiceCmd(aServerIf, aServiceHandle, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::DeleteService(
-  int aServerIf, const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ServerDeleteServiceCmd(
-    aServerIf, aServiceHandle, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::SendIndication(
-  int aServerIf, const BluetoothAttributeHandle& aCharacteristicHandle,
-  int aConnId, const nsTArray<uint8_t>& aValue, bool aConfirm,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ServerSendIndicationCmd(
-    aServerIf, aCharacteristicHandle, aConnId,
-    aValue.Length() * sizeof(uint8_t), aConfirm,
-    const_cast<uint8_t*>(aValue.Elements()), aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::SendResponse(
-  int aConnId, int aTransId, uint16_t aStatus,
-  const BluetoothGattResponse& aResponse,
-  BluetoothGattResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ServerSendResponseCmd(
-    aConnId, aTransId, aStatus, aResponse, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonGattInterface::DispatchError(
-  BluetoothGattResultHandler* aRes, BluetoothStatus aStatus)
-{
-  DaemonResultRunnable1<BluetoothGattResultHandler, void,
-                        BluetoothStatus, BluetoothStatus>::Dispatch(
-    aRes, &BluetoothGattResultHandler::OnError,
-    ConstantInitOp1<BluetoothStatus>(aStatus));
-}
-
-void
-BluetoothDaemonGattInterface::DispatchError(
-  BluetoothGattResultHandler* aRes, nsresult aRv)
-{
-  BluetoothStatus status;
-
-  if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
-    status = STATUS_FAIL;
-  }
-  DispatchError(aRes, status);
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonGattInterface.h
+++ /dev/null
@@ -1,993 +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_BluetoothDaemonGattInterface_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothDaemonGattInterface_h
-
-#include "BluetoothDaemonHelpers.h"
-#include "BluetoothInterface.h"
-#include "mozilla/ipc/DaemonRunnables.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using mozilla::ipc::DaemonSocketPDU;
-using mozilla::ipc::DaemonSocketPDUHeader;
-using mozilla::ipc::DaemonSocketResultHandler;
-
-class BluetoothDaemonGattModule
-{
-public:
-  enum {
-    SERVICE_ID = 0x09
-  };
-
-  enum {
-    OPCODE_ERROR = 0x00,
-    OPCODE_CLIENT_REGISTER = 0x01,
-    OPCODE_CLIENT_UNREGISTER = 0x02,
-    OPCODE_CLIENT_SCAN = 0x03,
-    OPCODE_CLIENT_CONNECT = 0x04,
-    OPCODE_CLIENT_DISCONNECT = 0x05,
-    OPCODE_CLIENT_LISTEN =0x06,
-    OPCODE_CLIENT_REFRESH = 0x07,
-    OPCODE_CLIENT_SEARCH_SERVICE = 0x08,
-    OPCODE_CLIENT_GET_INCLUDED_SERVICE = 0x09,
-    OPCODE_CLIENT_GET_CHARACTERISTIC = 0x0a,
-    OPCODE_CLIENT_GET_DESCRIPTOR = 0x0b,
-    OPCODE_CLIENT_READ_CHARACTERISTIC = 0x0c,
-    OPCODE_CLIENT_WRITE_CHARACTERISTIC = 0x0d,
-    OPCODE_CLIENT_READ_DESCRIPTOR = 0x0e,
-    OPCODE_CLIENT_WRITE_DESCRIPTOR = 0x0f,
-    OPCODE_CLIENT_EXECUTE_WRITE = 0x10,
-    OPCODE_CLIENT_REGISTER_NOTIFICATION = 0x11,
-    OPCODE_CLIENT_DEREGISTER_NOTIFICATION = 0x12,
-    OPCODE_CLIENT_READ_REMOTE_RSSI = 0x13,
-    OPCODE_CLIENT_GET_DEVICE_TYPE = 0x14,
-    OPCODE_CLIENT_SET_ADV_DATA = 0x15,
-    OPCODE_CLIENT_TEST_COMMAND = 0x16,
-    OPCODE_SERVER_REGISTER = 0x17,
-    OPCODE_SERVER_UNREGISTER = 0x18,
-    OPCODE_SERVER_CONNECT_PERIPHERAL = 0x19,
-    OPCODE_SERVER_DISCONNECT_PERIPHERAL = 0x1a,
-    OPCODE_SERVER_ADD_SERVICE = 0x1b,
-    OPCODE_SERVER_ADD_INCLUDED_SERVICE = 0x1c,
-    OPCODE_SERVER_ADD_CHARACTERISTIC = 0x1d,
-    OPCODE_SERVER_ADD_DESCRIPTOR = 0x1e,
-    OPCODE_SERVER_START_SERVICE = 0x1f,
-    OPCODE_SERVER_STOP_SERVICE = 0x20,
-    OPCODE_SERVER_DELETE_SERVICE = 0x21,
-    OPCODE_SERVER_SEND_INDICATION = 0x22,
-    OPCODE_SERVER_SEND_RESPONSE = 0x23
-    // TODO: Add L support
-  };
-
-  virtual nsresult Send(DaemonSocketPDU* aPDU,
-                        DaemonSocketResultHandler* aRes) = 0;
-
-  void SetNotificationHandler(
-    BluetoothGattNotificationHandler* aNotificationHandler);
-
-  //
-  // Commands
-  //
-
-  /* Register / Unregister */
-  nsresult ClientRegisterCmd(const BluetoothUuid& aUuid,
-                             BluetoothGattResultHandler* aRes);
-
-  nsresult ClientUnregisterCmd(int aClientIf,
-                               BluetoothGattResultHandler* aRes);
-
-  /* Start / Stop LE Scan */
-  nsresult ClientScanCmd(int aClientIf, bool aStart,
-                         BluetoothGattResultHandler* aRes);
-
-  /* Connect / Disconnect */
-  nsresult ClientConnectCmd(int aClientIf,
-                            const BluetoothAddress& aBdAddr,
-                            bool aIsDirect, /* auto connect */
-                            BluetoothTransport aTransport,
-                            BluetoothGattResultHandler* aRes);
-
-  nsresult ClientDisconnectCmd(int aClientIf,
-                               const BluetoothAddress& aBdAddr,
-                               int aConnId,
-                               BluetoothGattResultHandler* aRes);
-
-  /* Start / Stop advertisements to listen for incoming connections */
-  nsresult ClientListenCmd(int aClientIf,
-                           bool aIsStart,
-                           BluetoothGattResultHandler* aRes);
-
-  /* Clear the attribute cache for a given device*/
-  nsresult ClientRefreshCmd(int aClientIf,
-                            const BluetoothAddress& aBdAddr,
-                            BluetoothGattResultHandler* aRes);
-
-  /* Enumerate Attributes */
-  nsresult ClientSearchServiceCmd(int aConnId,
-                                  bool aFiltered,
-                                  const BluetoothUuid& aUuid,
-                                  BluetoothGattResultHandler* aRes);
-
-  nsresult ClientGetIncludedServiceCmd(
-    int aConnId,
-    const BluetoothGattServiceId& aServiceId,
-    bool aContinuation,
-    const BluetoothGattServiceId& aStartServiceId,
-    BluetoothGattResultHandler* aRes);
-
-  nsresult ClientGetCharacteristicCmd(int aConnId,
-                                      const BluetoothGattServiceId& aServiceId,
-                                      bool aContinuation,
-                                      const BluetoothGattId& aStartCharId,
-                                      BluetoothGattResultHandler* aRes);
-
-  nsresult ClientGetDescriptorCmd(int aConnId,
-                                  const BluetoothGattServiceId& aServiceId,
-                                  const BluetoothGattId& aCharId,
-                                  bool aContinuation,
-                                  const BluetoothGattId& aDescriptorId,
-                                  BluetoothGattResultHandler* aRes);
-
-  /* Read / Write An Attribute */
-  nsresult ClientReadCharacteristicCmd(
-    int aConnId,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharId,
-    BluetoothGattAuthReq aAuthReq,
-    BluetoothGattResultHandler* aRes);
-
-  nsresult ClientWriteCharacteristicCmd(
-    int aConnId,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharId,
-    BluetoothGattWriteType aWriteType,
-    int aLength,
-    BluetoothGattAuthReq aAuthReq,
-    char* aValue,
-    BluetoothGattResultHandler* aRes);
-
-  nsresult ClientReadDescriptorCmd(int aConnId,
-                                   const BluetoothGattServiceId& aServiceId,
-                                   const BluetoothGattId& aCharId,
-                                   const BluetoothGattId& aDescriptorId,
-                                   BluetoothGattAuthReq aAuthReq,
-                                   BluetoothGattResultHandler* aRes);
-
-  nsresult ClientWriteDescriptorCmd(int aConnId,
-                                    const BluetoothGattServiceId& aServiceId,
-                                    const BluetoothGattId& aCharId,
-                                    const BluetoothGattId& aDescriptorId,
-                                    BluetoothGattWriteType aWriteType,
-                                    int aLength,
-                                    BluetoothGattAuthReq aAuthReq,
-                                    char* aValue,
-                                    BluetoothGattResultHandler* aRes);
-
-  /* Execute / Abort Prepared Write*/
-  nsresult ClientExecuteWriteCmd(int aConnId,
-                                 int aIsExecute,
-                                 BluetoothGattResultHandler* aRes);
-
-  /* Register / Deregister Characteristic Notifications or Indications */
-  nsresult ClientRegisterNotificationCmd(
-    int aClientIf,
-    const BluetoothAddress& aBdAddr,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharId,
-    BluetoothGattResultHandler* aRes);
-
-  nsresult ClientDeregisterNotificationCmd(
-    int aClientIf,
-    const BluetoothAddress& aBdAddr,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharId,
-    BluetoothGattResultHandler* aRes);
-
-  nsresult ClientReadRemoteRssiCmd(int aClientIf,
-                                   const BluetoothAddress& aBdAddr,
-                                   BluetoothGattResultHandler* aRes);
-
-  nsresult ClientGetDeviceTypeCmd(const BluetoothAddress& aBdAddr,
-                                  BluetoothGattResultHandler* aRes);
-
-  /* Set advertising data or scan response data */
-  nsresult ClientSetAdvDataCmd(int aServerIf,
-                               bool aIsScanRsp,
-                               bool aIsNameIncluded,
-                               bool aIsTxPowerIncluded,
-                               int aMinInterval,
-                               int aMaxInterval,
-                               int aApperance,
-                               const nsTArray<uint8_t>& aManufacturerData,
-                               const nsTArray<uint8_t>& aServiceData,
-                               const nsTArray<BluetoothUuid>& aServiceUuids,
-                               BluetoothGattResultHandler* aRes);
-
-  nsresult ClientTestCommandCmd(int aCommand,
-                                const BluetoothGattTestParam& aTestParam,
-                                BluetoothGattResultHandler* aRes);
-
-  /* Register / Unregister */
-  nsresult ServerRegisterCmd(const BluetoothUuid& aUuid,
-                             BluetoothGattResultHandler* aRes);
-
-  nsresult ServerUnregisterCmd(int aServerIf,
-                               BluetoothGattResultHandler* aRes);
-
-  /* Connect / Disconnect */
-  nsresult ServerConnectPeripheralCmd(int aServerIf,
-                                      const BluetoothAddress& aBdAddr,
-                                      bool aIsDirect,
-                                      BluetoothTransport aTransport,
-                                      BluetoothGattResultHandler* aRes);
-
-  nsresult ServerDisconnectPeripheralCmd(
-    int aServerIf,
-    const BluetoothAddress& aBdAddr,
-    int aConnId,
-    BluetoothGattResultHandler* aRes);
-
-  /* Add a services / a characteristic / a descriptor */
-  nsresult ServerAddServiceCmd(int aServerIf,
-                               const BluetoothGattServiceId& aServiceId,
-                               uint16_t aNumHandles,
-                               BluetoothGattResultHandler* aRes);
-
-  nsresult ServerAddIncludedServiceCmd(
-    int aServerIf,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aIncludedServiceHandle,
-    BluetoothGattResultHandler* aRes);
-
-  nsresult ServerAddCharacteristicCmd(
-    int aServerIf,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothUuid& aUuid,
-    BluetoothGattCharProp aProperties,
-    BluetoothGattAttrPerm aPermissions,
-    BluetoothGattResultHandler* aRes);
-
-  nsresult ServerAddDescriptorCmd(
-    int aServerIf,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothUuid& aUuid,
-    BluetoothGattAttrPerm aPermissions,
-    BluetoothGattResultHandler* aRes);
-
-  /* Start / Stop / Delete a service */
-  nsresult ServerStartServiceCmd(int aServerIf,
-                                 const BluetoothAttributeHandle& aServiceHandle,
-                                 BluetoothTransport aTransport,
-                                 BluetoothGattResultHandler* aRes);
-
-  nsresult ServerStopServiceCmd(int aServerIf,
-                                const BluetoothAttributeHandle& aServiceHandle,
-                                BluetoothGattResultHandler* aRes);
-
-  nsresult ServerDeleteServiceCmd(
-    int aServerIf,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothGattResultHandler* aRes);
-
-  /* Send an indication or a notification */
-  nsresult ServerSendIndicationCmd(
-    int aServerIf,
-    const BluetoothAttributeHandle& aCharacteristicHandle,
-    int aConnId,
-    int aLength,
-    bool aConfirm,
-    uint8_t* aValue,
-    BluetoothGattResultHandler* aRes);
-
-  /* Send a response for an incoming indication */
-  nsresult ServerSendResponseCmd(int aConnId,
-                                 int aTransId,
-                                 uint16_t aStatus,
-                                 const BluetoothGattResponse& aResponse,
-                                 BluetoothGattResultHandler* aRes);
-  // TODO: Add L support
-
-protected:
-  void HandleSvc(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes);
-
-  //
-  // Responses
-  //
-
-  typedef mozilla::ipc::DaemonResultRunnable0<
-    BluetoothGattResultHandler, void>
-    ResultRunnable;
-
-  typedef mozilla::ipc::DaemonResultRunnable1<
-    BluetoothGattResultHandler, void,
-    BluetoothTypeOfDevice, BluetoothTypeOfDevice>
-    ClientGetDeviceTypeResultRunnable;
-
-  typedef mozilla::ipc::DaemonResultRunnable1<
-    BluetoothGattResultHandler, void, BluetoothStatus, BluetoothStatus>
-    ErrorRunnable;
-
-  void ErrorRsp(const DaemonSocketPDUHeader& aHeader,
-                DaemonSocketPDU& aPDU,
-                BluetoothGattResultHandler* aRes);
-
-  void ClientRegisterRsp(const DaemonSocketPDUHeader& aHeader,
-                         DaemonSocketPDU& aPDU,
-                         BluetoothGattResultHandler* aRes);
-
-  void ClientUnregisterRsp(const DaemonSocketPDUHeader& aHeader,
-                           DaemonSocketPDU& aPDU,
-                           BluetoothGattResultHandler* aRes);
-
-  void ClientScanRsp(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU,
-                     BluetoothGattResultHandler* aRes);
-
-  void ClientConnectRsp(const DaemonSocketPDUHeader& aHeader,
-                        DaemonSocketPDU& aPDU,
-                        BluetoothGattResultHandler* aRes);
-
-  void ClientDisconnectRsp(const DaemonSocketPDUHeader& aHeader,
-                           DaemonSocketPDU& aPDU,
-                           BluetoothGattResultHandler* aRes);
-
-  void ClientListenRsp(const DaemonSocketPDUHeader& aHeader,
-                       DaemonSocketPDU& aPDU,
-                       BluetoothGattResultHandler* aRes);
-
-  void ClientRefreshRsp(const DaemonSocketPDUHeader& aHeader,
-                        DaemonSocketPDU& aPDU,
-                        BluetoothGattResultHandler* aRes);
-
-  void ClientSearchServiceRsp(const DaemonSocketPDUHeader& aHeader,
-                              DaemonSocketPDU& aPDU,
-                              BluetoothGattResultHandler* aRes);
-
-  void ClientGetIncludedServiceRsp(const DaemonSocketPDUHeader& aHeader,
-                                   DaemonSocketPDU& aPDU,
-                                   BluetoothGattResultHandler* aRes);
-
-  void ClientGetCharacteristicRsp(const DaemonSocketPDUHeader& aHeader,
-                                  DaemonSocketPDU& aPDU,
-                                  BluetoothGattResultHandler* aRes);
-
-  void ClientGetDescriptorRsp(const DaemonSocketPDUHeader& aHeader,
-                              DaemonSocketPDU& aPDU,
-                              BluetoothGattResultHandler* aRes);
-
-  void ClientReadCharacteristicRsp(const DaemonSocketPDUHeader& aHeader,
-                                   DaemonSocketPDU& aPDU,
-                                   BluetoothGattResultHandler* aRes);
-
-  void ClientWriteCharacteristicRsp(const DaemonSocketPDUHeader& aHeader,
-                                    DaemonSocketPDU& aPDU,
-                                    BluetoothGattResultHandler* aRes);
-
-  void ClientReadDescriptorRsp(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU,
-                               BluetoothGattResultHandler* aRes);
-
-  void ClientWriteDescriptorRsp(const DaemonSocketPDUHeader& aHeader,
-                                DaemonSocketPDU& aPDU,
-                                BluetoothGattResultHandler* aRes);
-
-  void ClientExecuteWriteRsp(const DaemonSocketPDUHeader& aHeader,
-                             DaemonSocketPDU& aPDU,
-                             BluetoothGattResultHandler* aRes);
-
-  void ClientRegisterNotificationRsp(const DaemonSocketPDUHeader& aHeader,
-                                     DaemonSocketPDU& aPDU,
-                                     BluetoothGattResultHandler* aRes);
-
-  void ClientDeregisterNotificationRsp(const DaemonSocketPDUHeader& aHeader,
-                                       DaemonSocketPDU& aPDU,
-                                       BluetoothGattResultHandler* aRes);
-
-  void ClientReadRemoteRssiRsp(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU,
-                               BluetoothGattResultHandler* aRes);
-
-  void ClientGetDeviceTypeRsp(const DaemonSocketPDUHeader& aHeader,
-                              DaemonSocketPDU& aPDU,
-                              BluetoothGattResultHandler* aRes);
-
-  void ClientSetAdvDataRsp(const DaemonSocketPDUHeader& aHeader,
-                           DaemonSocketPDU& aPDU,
-                           BluetoothGattResultHandler* aRes);
-
-  void ClientTestCommandRsp(const DaemonSocketPDUHeader& aHeader,
-                            DaemonSocketPDU& aPDU,
-                            BluetoothGattResultHandler* aRes);
-
-  void ServerRegisterRsp(const DaemonSocketPDUHeader& aHeader,
-                         DaemonSocketPDU& aPDU,
-                         BluetoothGattResultHandler* aRes);
-
-  void ServerUnregisterRsp(const DaemonSocketPDUHeader& aHeader,
-                           DaemonSocketPDU& aPDU,
-                           BluetoothGattResultHandler* aRes);
-
-  void ServerConnectPeripheralRsp(const DaemonSocketPDUHeader& aHeader,
-                                  DaemonSocketPDU& aPDU,
-                                  BluetoothGattResultHandler* aRes);
-
-  void ServerDisconnectPeripheralRsp(const DaemonSocketPDUHeader& aHeader,
-                                     DaemonSocketPDU& aPDU,
-                                     BluetoothGattResultHandler* aRes);
-
-  void ServerAddServiceRsp(const DaemonSocketPDUHeader& aHeader,
-                           DaemonSocketPDU& aPDU,
-                           BluetoothGattResultHandler* aRes);
-
-  void ServerAddIncludedServiceRsp(const DaemonSocketPDUHeader& aHeader,
-                                   DaemonSocketPDU& aPDU,
-                                   BluetoothGattResultHandler* aRes);
-
-  void ServerAddCharacteristicRsp(const DaemonSocketPDUHeader& aHeader,
-                                  DaemonSocketPDU& aPDU,
-                                  BluetoothGattResultHandler* aRes);
-
-  void ServerAddDescriptorRsp(const DaemonSocketPDUHeader& aHeader,
-                              DaemonSocketPDU& aPDU,
-                              BluetoothGattResultHandler* aRes);
-
-  void ServerStartServiceRsp(const DaemonSocketPDUHeader& aHeader,
-                             DaemonSocketPDU& aPDU,
-                             BluetoothGattResultHandler* aRes);
-
-  void ServerStopServiceRsp(const DaemonSocketPDUHeader& aHeader,
-                            DaemonSocketPDU& aPDU,
-                            BluetoothGattResultHandler* aRes);
-
-  void ServerDeleteServiceRsp(const DaemonSocketPDUHeader& aHeader,
-                              DaemonSocketPDU& aPDU,
-                              BluetoothGattResultHandler* aRes);
-
-  void ServerSendIndicationRsp(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU,
-                               BluetoothGattResultHandler* aRes);
-
-  void ServerSendResponseRsp(const DaemonSocketPDUHeader& aHeader,
-                             DaemonSocketPDU& aPDU,
-                             BluetoothGattResultHandler* aRes);
-
-  // TODO: Add L support
-
-  void HandleRsp(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU,
-                 DaemonSocketResultHandler* aRes);
-
-  //
-  // Notifications
-  //
-
-  class NotificationHandlerWrapper;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, BluetoothUuid,
-    BluetoothGattStatus, int, const BluetoothUuid&>
-    ClientRegisterNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, int, BluetoothGattAdvData,
-    const BluetoothAddress&, int, const BluetoothGattAdvData&>
-    ClientScanResultNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable4<
-    NotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, int, BluetoothAddress,
-    int, BluetoothGattStatus, int, const BluetoothAddress&>
-    ClientConnectNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable4<
-    NotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, int, BluetoothAddress,
-    int, BluetoothGattStatus, int, const BluetoothAddress&>
-    ClientDisconnectNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    int, BluetoothGattStatus>
-    ClientSearchCompleteNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    int, BluetoothGattServiceId,
-    int, const BluetoothGattServiceId&>
-    ClientSearchResultNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable5<
-    NotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, BluetoothGattServiceId,
-    BluetoothGattId, BluetoothGattCharProp,
-    int, BluetoothGattStatus, const BluetoothGattServiceId&,
-    const BluetoothGattId&, const BluetoothGattCharProp&>
-    ClientGetCharacteristicNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable5<
-    NotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, BluetoothGattServiceId,
-    BluetoothGattId, BluetoothGattId,
-    int, BluetoothGattStatus, const BluetoothGattServiceId&,
-    const BluetoothGattId&, const BluetoothGattId&>
-    ClientGetDescriptorNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable4<
-    NotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, BluetoothGattServiceId, BluetoothGattServiceId,
-    int, BluetoothGattStatus, const BluetoothGattServiceId&,
-    const BluetoothGattServiceId&>
-    ClientGetIncludedServiceNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable5<
-    NotificationHandlerWrapper, void,
-    int, int, BluetoothGattStatus,
-    BluetoothGattServiceId, BluetoothGattId,
-    int, int, BluetoothGattStatus,
-    const BluetoothGattServiceId&, const BluetoothGattId&>
-    ClientRegisterNotificationNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    int, BluetoothGattNotifyParam,
-    int, const BluetoothGattNotifyParam&>
-    ClientNotifyNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, BluetoothGattReadParam,
-    int, BluetoothGattStatus, const BluetoothGattReadParam&>
-    ClientReadCharacteristicNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, BluetoothGattWriteParam,
-    int, BluetoothGattStatus, const BluetoothGattWriteParam&>
-    ClientWriteCharacteristicNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, BluetoothGattReadParam,
-    int, BluetoothGattStatus, const BluetoothGattReadParam&>
-    ClientReadDescriptorNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    int, BluetoothGattStatus, BluetoothGattWriteParam,
-    int, BluetoothGattStatus, const BluetoothGattWriteParam&>
-    ClientWriteDescriptorNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    int, BluetoothGattStatus>
-    ClientExecuteWriteNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable4<
-    NotificationHandlerWrapper, void,
-    int, BluetoothAddress, int, BluetoothGattStatus,
-    int, const BluetoothAddress&, int, BluetoothGattStatus>
-    ClientReadRemoteRssiNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    BluetoothGattStatus, int>
-    ClientListenNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, BluetoothUuid,
-    BluetoothGattStatus, int, const BluetoothUuid&>
-    ServerRegisterNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable4<
-    NotificationHandlerWrapper, void,
-    int, int, bool, BluetoothAddress,
-    int, int, bool, const BluetoothAddress&>
-    ServerConnectionNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable4<
-    NotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, BluetoothGattServiceId, BluetoothAttributeHandle,
-    BluetoothGattStatus, int, const BluetoothGattServiceId&,
-    const BluetoothAttributeHandle&>
-    ServerServiceAddedNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable4<
-    NotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, BluetoothAttributeHandle,
-    BluetoothAttributeHandle,
-    BluetoothGattStatus, int, const BluetoothAttributeHandle&,
-    const BluetoothAttributeHandle&>
-    ServerIncludedServiceAddedNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable5<
-    NotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, BluetoothUuid, BluetoothAttributeHandle,
-    BluetoothAttributeHandle,
-    BluetoothGattStatus, int, const BluetoothUuid&,
-    const BluetoothAttributeHandle&, const BluetoothAttributeHandle&>
-    ServerCharacteristicAddedNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable5<
-    NotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, BluetoothUuid, BluetoothAttributeHandle,
-    BluetoothAttributeHandle,
-    BluetoothGattStatus, int, const BluetoothUuid&,
-    const BluetoothAttributeHandle&, const BluetoothAttributeHandle&>
-    ServerDescriptorAddedNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, BluetoothAttributeHandle,
-    BluetoothGattStatus, int, const BluetoothAttributeHandle&>
-    ServerServiceStartedNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, BluetoothAttributeHandle,
-    BluetoothGattStatus, int, const BluetoothAttributeHandle&>
-    ServerServiceStoppedNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    BluetoothGattStatus, int, BluetoothAttributeHandle,
-    BluetoothGattStatus, int, const BluetoothAttributeHandle&>
-    ServerServiceDeletedNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable6<
-    NotificationHandlerWrapper, void,
-    int, int, BluetoothAddress, BluetoothAttributeHandle,
-    int, bool,
-    int, int, const BluetoothAddress&, const BluetoothAttributeHandle&,
-    int, bool>
-    ServerRequestReadNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable9<
-    NotificationHandlerWrapper, void,
-    int, int, BluetoothAddress, BluetoothAttributeHandle,
-    int, int, UniquePtr<uint8_t[]>, bool, bool,
-    int, int, const BluetoothAddress&, const BluetoothAttributeHandle&,
-    int, int, const uint8_t*, bool, bool>
-    ServerRequestWriteNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable4<
-    NotificationHandlerWrapper, void,
-    int, int, BluetoothAddress, bool,
-    int, int, const BluetoothAddress&, bool>
-    ServerRequestExecuteWriteNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    BluetoothGattStatus, int>
-    ServerResponseConfirmationNotification;
-
-  class ClientGetDeviceTypeInitOp;
-  class ClientScanResultInitOp;
-  class ServerConnectionInitOp;
-  class ServerRequestWriteInitOp;
-  class ServerCharacteristicAddedInitOp;
-  class ServerDescriptorAddedInitOp;
-
-  void ClientRegisterNtf(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU);
-
-  void ClientScanResultNtf(const DaemonSocketPDUHeader& aHeader,
-                           DaemonSocketPDU& aPDU);
-
-  void ClientConnectNtf(const DaemonSocketPDUHeader& aHeader,
-                        DaemonSocketPDU& aPDU);
-
-  void ClientDisconnectNtf(const DaemonSocketPDUHeader& aHeader,
-                           DaemonSocketPDU& aPDU);
-
-  void ClientSearchCompleteNtf(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU);
-
-  void ClientSearchResultNtf(const DaemonSocketPDUHeader& aHeader,
-                             DaemonSocketPDU& aPDU);
-
-  void ClientGetCharacteristicNtf(const DaemonSocketPDUHeader& aHeader,
-                                  DaemonSocketPDU& aPDU);
-
-  void ClientGetDescriptorNtf(const DaemonSocketPDUHeader& aHeader,
-                              DaemonSocketPDU& aPDU);
-
-  void ClientGetIncludedServiceNtf(const DaemonSocketPDUHeader& aHeader,
-                                   DaemonSocketPDU& aPDU);
-
-  void ClientRegisterNotificationNtf(const DaemonSocketPDUHeader& aHeader,
-                                     DaemonSocketPDU& aPDU);
-
-  void ClientNotifyNtf(const DaemonSocketPDUHeader& aHeader,
-                       DaemonSocketPDU& aPDU);
-
-  void ClientReadCharacteristicNtf(const DaemonSocketPDUHeader& aHeader,
-                                   DaemonSocketPDU& aPDU);
-
-  void ClientWriteCharacteristicNtf(const DaemonSocketPDUHeader& aHeader,
-                                    DaemonSocketPDU& aPDU);
-
-  void ClientReadDescriptorNtf(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU);
-
-  void ClientWriteDescriptorNtf(const DaemonSocketPDUHeader& aHeader,
-                                DaemonSocketPDU& aPDU);
-
-  void ClientExecuteWriteNtf(const DaemonSocketPDUHeader& aHeader,
-                             DaemonSocketPDU& aPDU);
-
-  void ClientReadRemoteRssiNtf(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU);
-
-  void ClientListenNtf(const DaemonSocketPDUHeader& aHeader,
-                       DaemonSocketPDU& aPDU);
-
-  void ServerRegisterNtf(const DaemonSocketPDUHeader& aHeader,
-                         DaemonSocketPDU& aPDU);
-
-  void ServerConnectionNtf(const DaemonSocketPDUHeader& aHeader,
-                           DaemonSocketPDU& aPDU);
-
-  void ServerServiceAddedNtf(const DaemonSocketPDUHeader& aHeader,
-                             DaemonSocketPDU& aPDU);
-
-  void ServerIncludedServiceAddedNtf(const DaemonSocketPDUHeader& aHeader,
-                                     DaemonSocketPDU& aPDU);
-
-  void ServerCharacteristicAddedNtf(const DaemonSocketPDUHeader& aHeader,
-                                    DaemonSocketPDU& aPDU);
-
-  void ServerDescriptorAddedNtf(const DaemonSocketPDUHeader& aHeader,
-                                DaemonSocketPDU& aPDU);
-
-  void ServerServiceStartedNtf(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU);
-
-  void ServerServiceStoppedNtf(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU);
-
-  void ServerServiceDeletedNtf(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU);
-
-  void ServerRequestReadNtf(const DaemonSocketPDUHeader& aHeader,
-                            DaemonSocketPDU& aPDU);
-
-  void ServerRequestWriteNtf(const DaemonSocketPDUHeader& aHeader,
-                             DaemonSocketPDU& aPDU);
-
-  void ServerRequestExecuteWriteNtf(const DaemonSocketPDUHeader& aHeader,
-                                    DaemonSocketPDU& aPDU);
-
-  void ServerResponseConfirmationNtf(const DaemonSocketPDUHeader& aHeader,
-                                     DaemonSocketPDU& aPDU);
-
-  // TODO: Add L support
-
-  void HandleNtf(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU,
-                 DaemonSocketResultHandler* aRes);
-
-  static BluetoothGattNotificationHandler* sNotificationHandler;
-};
-
-class BluetoothDaemonGattInterface final
-  : public BluetoothGattInterface
-{
-  class CleanupResultHandler;
-  class InitResultHandler;
-
-public:
-  BluetoothDaemonGattInterface(BluetoothDaemonGattModule* aModule);
-  ~BluetoothDaemonGattInterface();
-
-  void SetNotificationHandler(
-    BluetoothGattNotificationHandler* aNotificationHandler) override;
-
-  /* Register / Unregister */
-  void RegisterClient(const BluetoothUuid& aUuid,
-                      BluetoothGattResultHandler* aRes) override;
-  void UnregisterClient(int aClientIf,
-                        BluetoothGattResultHandler* aRes) override;
-
-  /* Start / Stop LE Scan */
-  void Scan(int aClientIf, bool aStart,
-            BluetoothGattResultHandler* aRes) override;
-
-  /* Connect / Disconnect */
-  void Connect(int aClientIf,
-               const BluetoothAddress& aBdAddr,
-               bool aIsDirect, /* auto connect */
-               BluetoothTransport aTransport,
-               BluetoothGattResultHandler* aRes) override;
-  void Disconnect(int aClientIf,
-                  const BluetoothAddress& aBdAddr,
-                  int aConnId,
-                  BluetoothGattResultHandler* aRes) override;
-
-  /* Start / Stop advertisements to listen for incoming connections */
-  void Listen(int aClientIf,
-              bool aIsStart,
-              BluetoothGattResultHandler* aRes) override;
-
-  /* Clear the attribute cache for a given device*/
-  void Refresh(int aClientIf,
-               const BluetoothAddress& aBdAddr,
-               BluetoothGattResultHandler* aRes) override;
-
-  /* Enumerate Attributes */
-  void SearchService(int aConnId,
-                     bool aSearchAll,
-                     const BluetoothUuid& aUuid,
-                     BluetoothGattResultHandler* aRes) override;
-  void GetIncludedService(int aConnId,
-                          const BluetoothGattServiceId& aServiceId,
-                          bool aFirst,
-                          const BluetoothGattServiceId& aStartServiceId,
-                          BluetoothGattResultHandler* aRes) override;
-  void GetCharacteristic(int aConnId,
-                         const BluetoothGattServiceId& aServiceId,
-                         bool aFirst,
-                         const BluetoothGattId& aStartCharId,
-                         BluetoothGattResultHandler* aRes) override;
-  void GetDescriptor(int aConnId,
-                     const BluetoothGattServiceId& aServiceId,
-                     const BluetoothGattId& aCharId,
-                     bool aFirst,
-                     const BluetoothGattId& aDescriptorId,
-                     BluetoothGattResultHandler* aRes) override;
-
-  /* Read / Write An Attribute */
-  void ReadCharacteristic(int aConnId,
-                          const BluetoothGattServiceId& aServiceId,
-                          const BluetoothGattId& aCharId,
-                          BluetoothGattAuthReq aAuthReq,
-                          BluetoothGattResultHandler* aRes) override;
-  void WriteCharacteristic(int aConnId,
-                           const BluetoothGattServiceId& aServiceId,
-                           const BluetoothGattId& aCharId,
-                           BluetoothGattWriteType aWriteType,
-                           BluetoothGattAuthReq aAuthReq,
-                           const nsTArray<uint8_t>& aValue,
-                           BluetoothGattResultHandler* aRes) override;
-  void ReadDescriptor(int aConnId,
-                      const BluetoothGattServiceId& aServiceId,
-                      const BluetoothGattId& aCharId,
-                      const BluetoothGattId& aDescriptorId,
-                      BluetoothGattAuthReq aAuthReq,
-                      BluetoothGattResultHandler* aRes) override;
-  void WriteDescriptor(int aConnId,
-                       const BluetoothGattServiceId& aServiceId,
-                       const BluetoothGattId& aCharId,
-                       const BluetoothGattId& aDescriptorId,
-                       BluetoothGattWriteType aWriteType,
-                       BluetoothGattAuthReq aAuthReq,
-                       const nsTArray<uint8_t>& aValue,
-                       BluetoothGattResultHandler* aRes) override;
-
-  /* Execute / Abort Prepared Write*/
-  void ExecuteWrite(int aConnId,
-                    int aIsExecute,
-                    BluetoothGattResultHandler* aRes) override;
-
-
-  /* Register / Deregister Characteristic Notifications or Indications */
-  void RegisterNotification(int aClientIf,
-                            const BluetoothAddress& aBdAddr,
-                            const BluetoothGattServiceId& aServiceId,
-                            const BluetoothGattId& aCharId,
-                            BluetoothGattResultHandler* aRes) override;
-  void DeregisterNotification(int aClientIf,
-                              const BluetoothAddress& aBdAddr,
-                              const BluetoothGattServiceId& aServiceId,
-                              const BluetoothGattId& aCharId,
-                              BluetoothGattResultHandler* aRes) override;
-
-  void ReadRemoteRssi(int aClientIf,
-                      const BluetoothAddress& aBdAddr,
-                      BluetoothGattResultHandler* aRes) override;
-
-  void GetDeviceType(const BluetoothAddress& aBdAddr,
-                     BluetoothGattResultHandler* aRes) override;
-
-  /* Set advertising data or scan response data */
-  void SetAdvData(int aServerIf,
-                  bool aIsScanRsp,
-                  bool aIsNameIncluded,
-                  bool aIsTxPowerIncluded,
-                  int aMinInterval,
-                  int aMaxInterval,
-                  int aApperance,
-                  const nsTArray<uint8_t>& aManufacturerData,
-                  const nsTArray<uint8_t>& aServiceData,
-                  const nsTArray<BluetoothUuid>& aServiceUuids,
-                  BluetoothGattResultHandler* aRes) override;
-
-  void TestCommand(int aCommand,
-                   const BluetoothGattTestParam& aTestParam,
-                   BluetoothGattResultHandler* aRes) override;
-
-  /* Register / Unregister */
-  void RegisterServer(const BluetoothUuid& aUuid,
-                      BluetoothGattResultHandler* aRes) override;
-  void UnregisterServer(int aServerIf,
-                        BluetoothGattResultHandler* aRes) override;
-
-  /* Connect / Disconnect */
-  void ConnectPeripheral(int aServerIf,
-                         const BluetoothAddress& aBdAddr,
-                         bool aIsDirect, /* auto connect */
-                         BluetoothTransport aTransport,
-                         BluetoothGattResultHandler* aRes) override;
-  void DisconnectPeripheral(int aServerIf,
-                            const BluetoothAddress& aBdAddr,
-                            int aConnId,
-                            BluetoothGattResultHandler* aRes) override;
-
-  /* Add a services / a characteristic / a descriptor */
-  void AddService(int aServerIf,
-                  const BluetoothGattServiceId& aServiceId,
-                  uint16_t aNumHandles,
-                  BluetoothGattResultHandler* aRes) override;
-  void AddIncludedService(int aServerIf,
-                          const BluetoothAttributeHandle& aServiceHandle,
-                          const BluetoothAttributeHandle& aIncludedServiceHandle,
-                          BluetoothGattResultHandler* aRes) override;
-  void AddCharacteristic(int aServerIf,
-                         const BluetoothAttributeHandle& aServiceHandle,
-                         const BluetoothUuid& aUuid,
-                         BluetoothGattCharProp aProperties,
-                         BluetoothGattAttrPerm aPermissions,
-                         BluetoothGattResultHandler* aRes) override;
-  void AddDescriptor(int aServerIf,
-                     const BluetoothAttributeHandle& aServiceHandle,
-                     const BluetoothUuid& aUuid,
-                     BluetoothGattAttrPerm aPermissions,
-                     BluetoothGattResultHandler* aRes) override;
-
-  /* Start / Stop / Delete a service */
-  void StartService(int aServerIf,
-                    const BluetoothAttributeHandle& aServiceHandle,
-                    BluetoothTransport aTransport,
-                    BluetoothGattResultHandler* aRes) override;
-  void StopService(int aServerIf,
-                   const BluetoothAttributeHandle& aServiceHandle,
-                   BluetoothGattResultHandler* aRes) override;
-  void DeleteService(int aServerIf,
-                     const BluetoothAttributeHandle& aServiceHandle,
-                     BluetoothGattResultHandler* aRes) override;
-
-  /* Send an indication or a notification */
-  void SendIndication(
-    int aServerIf,
-    const BluetoothAttributeHandle& aCharacteristicHandle,
-    int aConnId,
-    const nsTArray<uint8_t>& aValue,
-    bool aConfirm, /* true: indication, false: notification */
-    BluetoothGattResultHandler* aRes) override;
-
-  /* Send a response for an incoming indication */
-  void SendResponse(int aConnId,
-                    int aTransId,
-                    uint16_t aStatus,
-                    const BluetoothGattResponse& aResponse,
-                    BluetoothGattResultHandler* aRes) override;
-
-private:
-  void DispatchError(BluetoothGattResultHandler* aRes,
-                     BluetoothStatus aStatus);
-  void DispatchError(BluetoothGattResultHandler* aRes, nsresult aRv);
-
-  BluetoothDaemonGattModule* mModule;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothDaemonGattInterface_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.cpp
+++ /dev/null
@@ -1,1667 +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 "BluetoothDaemonHandsfreeInterface.h"
-#include "mozilla/UniquePtr.h"
-#include "mozilla/Unused.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using namespace mozilla::ipc;
-
-//
-// Handsfree module
-//
-
-BluetoothHandsfreeNotificationHandler*
-  BluetoothDaemonHandsfreeModule::sNotificationHandler;
-
-#if ANDROID_VERSION < 21
-BluetoothAddress BluetoothDaemonHandsfreeModule::sConnectedDeviceAddress(
-  BluetoothAddress::ANY());
-#endif
-
-void
-BluetoothDaemonHandsfreeModule::SetNotificationHandler(
-  BluetoothHandsfreeNotificationHandler* aNotificationHandler)
-{
-  sNotificationHandler = aNotificationHandler;
-}
-
-void
-BluetoothDaemonHandsfreeModule::HandleSvc(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonHandsfreeModule::* const HandleOp[])(
-    const DaemonSocketPDUHeader&, DaemonSocketPDU&,
-    DaemonSocketResultHandler*) = {
-    [0] = &BluetoothDaemonHandsfreeModule::HandleRsp,
-    [1] = &BluetoothDaemonHandsfreeModule::HandleNtf
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread());
-
-  // Negate twice to map bit to 0/1
-  unsigned long isNtf = !!(aHeader.mOpcode & 0x80);
-
-  (this->*(HandleOp[isNtf]))(aHeader, aPDU, aRes);
-}
-
-// Commands
-//
-
-nsresult
-BluetoothDaemonHandsfreeModule::ConnectCmd(
-  const BluetoothAddress& aRemoteAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CONNECT,
-                                6); // Address
-
-  nsresult rv = PackPDU(aRemoteAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHandsfreeModule::DisconnectCmd(
-  const BluetoothAddress& aRemoteAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_DISCONNECT,
-                                6); // Address
-
-  nsresult rv = PackPDU(aRemoteAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHandsfreeModule::ConnectAudioCmd(
-  const BluetoothAddress& aRemoteAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu(
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CONNECT_AUDIO,
-                                6)); // Address
-
-  nsresult rv = PackPDU(aRemoteAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHandsfreeModule::DisconnectAudioCmd(
-  const BluetoothAddress& aRemoteAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_DISCONNECT_AUDIO,
-                                6); // Address
-
-  nsresult rv = PackPDU(aRemoteAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHandsfreeModule::StartVoiceRecognitionCmd(
-  const BluetoothAddress& aRemoteAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_START_VOICE_RECOGNITION,
-                                6); // Address (BlueZ 5.25)
-
-  nsresult rv;
-#if ANDROID_VERSION >= 21
-  rv = PackPDU(aRemoteAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-#endif
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHandsfreeModule::StopVoiceRecognitionCmd(
-  const BluetoothAddress& aRemoteAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_STOP_VOICE_RECOGNITION,
-                                6); // Address (BlueZ 5.25)
-
-  nsresult rv;
-#if ANDROID_VERSION >= 21
-  rv = PackPDU(aRemoteAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-#endif
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHandsfreeModule::VolumeControlCmd(
-  BluetoothHandsfreeVolumeType aType, int aVolume,
-  const BluetoothAddress& aRemoteAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_VOLUME_CONTROL,
-                                1 + // Volume type
-                                1 + // Volume
-                                6); // Address (BlueZ 5.25)
-
-#if ANDROID_VERSION >= 21
-  nsresult rv = PackPDU(
-    aType, PackConversion<int, uint8_t>(aVolume), aRemoteAddr, *pdu);
-#else
-  nsresult rv = PackPDU(aType, PackConversion<int, uint8_t>(aVolume), *pdu);
-#endif
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHandsfreeModule::DeviceStatusNotificationCmd(
-  BluetoothHandsfreeNetworkState aNtkState,
-  BluetoothHandsfreeServiceType aSvcType, int aSignal, int aBattChg,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_DEVICE_STATUS_NOTIFICATION,
-                                1 + // Network state
-                                1 + // Service type
-                                1 + // Signal strength
-                                1); // Battery level
-
-  nsresult rv = PackPDU(aNtkState, aSvcType,
-                        PackConversion<int, uint8_t>(aSignal),
-                        PackConversion<int, uint8_t>(aBattChg), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHandsfreeModule::CopsResponseCmd(
-  const char* aCops, const BluetoothAddress& aRemoteAddr,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_COPS_RESPONSE,
-                                0 + // Dynamically allocated
-                                6); // Address (BlueZ 5.25)
-
-#if ANDROID_VERSION >= 21
-  nsresult rv = PackPDU(PackCString0(nsDependentCString(aCops)), aRemoteAddr,
-                        *pdu);
-#else
-  nsresult rv = PackPDU(PackCString0(nsDependentCString(aCops)), *pdu);
-#endif
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHandsfreeModule::CindResponseCmd(
-  int aSvc, int aNumActive, int aNumHeld,
-  BluetoothHandsfreeCallState aCallSetupState,
-  int aSignal, int aRoam, int aBattChg,
-  const BluetoothAddress& aRemoteAddr,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CIND_RESPONSE,
-                                1 + // Service
-                                1 + // # Active
-                                1 + // # Held
-                                1 + // Call state
-                                1 + // Signal strength
-                                1 + // Roaming
-                                1 + // Battery level
-                                6); // Address (BlueZ 5.25)
-
-#if ANDROID_VERSION >= 21
-  nsresult rv = PackPDU(
-    PackConversion<int, uint8_t>(aSvc),
-    PackConversion<int, uint8_t>(aNumActive),
-    PackConversion<int, uint8_t>(aNumHeld),
-    aCallSetupState,
-    PackConversion<int, uint8_t>(aSignal),
-    PackConversion<int, uint8_t>(aRoam),
-    PackConversion<int, uint8_t>(aBattChg),
-    aRemoteAddr, *pdu);
-#else
-  nsresult rv = PackPDU(PackConversion<int, uint8_t>(aSvc),
-                        PackConversion<int, uint8_t>(aNumActive),
-                        PackConversion<int, uint8_t>(aNumHeld),
-                        aCallSetupState,
-                        PackConversion<int, uint8_t>(aSignal),
-                        PackConversion<int, uint8_t>(aRoam),
-                        PackConversion<int, uint8_t>(aBattChg), *pdu);
-#endif
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHandsfreeModule::FormattedAtResponseCmd(
-  const char* aRsp, const BluetoothAddress& aRemoteAddr,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_FORMATTED_AT_RESPONSE,
-                                0 + // Dynamically allocated
-                                6); // Address (BlueZ 5.25)
-
-#if ANDROID_VERSION >= 21
-  nsresult rv = PackPDU(PackCString0(nsDependentCString(aRsp)), aRemoteAddr,
-                                     *pdu);
-#else
-  nsresult rv = PackPDU(PackCString0(nsDependentCString(aRsp)), *pdu);
-#endif
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHandsfreeModule::AtResponseCmd(
-  BluetoothHandsfreeAtResponse aResponseCode, int aErrorCode,
-  const BluetoothAddress& aRemoteAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_AT_RESPONSE,
-                                1 + // AT Response code
-                                1 + // Error code
-                                6); // Address (BlueZ 5.25)
-
-#if ANDROID_VERSION >= 21
-  nsresult rv = PackPDU(aResponseCode,
-                        PackConversion<int, uint8_t>(aErrorCode),
-                        aRemoteAddr, *pdu);
-#else
-  nsresult rv = PackPDU(aResponseCode,
-                        PackConversion<int, uint8_t>(aErrorCode), *pdu);
-#endif
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHandsfreeModule::ClccResponseCmd(
-  int aIndex,
-  BluetoothHandsfreeCallDirection aDir, BluetoothHandsfreeCallState aState,
-  BluetoothHandsfreeCallMode aMode, BluetoothHandsfreeCallMptyType aMpty,
-  const nsAString& aNumber, BluetoothHandsfreeCallAddressType aType,
-  const BluetoothAddress& aRemoteAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ConvertUTF16toUTF8 number(aNumber);
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CLCC_RESPONSE,
-                                1 + // Call index
-                                1 + // Call direction
-                                1 + // Call state
-                                1 + // Call mode
-                                1 + // Call MPTY
-                                1 + // Address type
-                                number.Length() + 1 + // Number string + \0
-                                6); // Address (BlueZ 5.25)
-
-#if ANDROID_VERSION >= 21
-  nsresult rv = PackPDU(PackConversion<int, uint8_t>(aIndex),
-                        aDir, aState, aMode, aMpty, aType,
-                        PackCString0(number), aRemoteAddr, *pdu);
-#else
-  nsresult rv = PackPDU(PackConversion<int, uint8_t>(aIndex),
-                        aDir, aState, aMode, aMpty, aType,
-                        PackCString0(number), *pdu);
-#endif
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHandsfreeModule::PhoneStateChangeCmd(
-  int aNumActive, int aNumHeld, BluetoothHandsfreeCallState aCallSetupState,
-  const nsAString& aNumber, BluetoothHandsfreeCallAddressType aType,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ConvertUTF16toUTF8 number(aNumber);
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_PHONE_STATE_CHANGE,
-                                1 + // # Active
-                                1 + // # Held
-                                1 + // Call state
-                                1 + // Address type
-                                number.Length() + 1); // Number string + \0
-
-  nsresult rv = PackPDU(PackConversion<int, uint8_t>(aNumActive),
-                        PackConversion<int, uint8_t>(aNumHeld),
-                        aCallSetupState, aType,
-                        PackCString0(NS_ConvertUTF16toUTF8(aNumber)), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHandsfreeModule::ConfigureWbsCmd(
-  const BluetoothAddress& aRemoteAddr,
-  BluetoothHandsfreeWbsConfig aConfig,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CONFIGURE_WBS,
-                                6 + // Address
-                                1); // Config
-
-  nsresult rv = PackPDU(aRemoteAddr, aConfig, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-// Responses
-//
-
-void
-BluetoothDaemonHandsfreeModule::ErrorRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothHandsfreeResultHandler* aRes)
-{
-  ErrorRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::OnError, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::ConnectRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::Connect, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::DisconnectRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::Disconnect, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::ConnectAudioRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::ConnectAudio,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::DisconnectAudioRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::DisconnectAudio,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::StartVoiceRecognitionRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::StartVoiceRecognition,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::StopVoiceRecognitionRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::StopVoiceRecognition,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::VolumeControlRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::VolumeControl,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::DeviceStatusNotificationRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::DeviceStatusNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::CopsResponseRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::CopsResponse,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::CindResponseRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::CindResponse,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::FormattedAtResponseRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::FormattedAtResponse,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::AtResponseRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::AtResponse,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::ClccResponseRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::ClccResponse,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::PhoneStateChangeRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::PhoneStateChange,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::ConfigureWbsRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::ConfigureWbs,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::HandleRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonHandsfreeModule::* const HandleRsp[])(
-    const DaemonSocketPDUHeader&,
-    DaemonSocketPDU&,
-    BluetoothHandsfreeResultHandler*) = {
-    [OPCODE_ERROR] =
-      &BluetoothDaemonHandsfreeModule::ErrorRsp,
-    [OPCODE_CONNECT] =
-      &BluetoothDaemonHandsfreeModule::ConnectRsp,
-    [OPCODE_DISCONNECT] =
-      &BluetoothDaemonHandsfreeModule::DisconnectRsp,
-    [OPCODE_CONNECT_AUDIO] =
-      &BluetoothDaemonHandsfreeModule::ConnectAudioRsp,
-    [OPCODE_DISCONNECT_AUDIO] =
-      &BluetoothDaemonHandsfreeModule::DisconnectAudioRsp,
-    [OPCODE_START_VOICE_RECOGNITION] =
-      &BluetoothDaemonHandsfreeModule::StartVoiceRecognitionRsp,
-    [OPCODE_STOP_VOICE_RECOGNITION] =
-      &BluetoothDaemonHandsfreeModule::StopVoiceRecognitionRsp,
-    [OPCODE_VOLUME_CONTROL] =
-      &BluetoothDaemonHandsfreeModule::VolumeControlRsp,
-    [OPCODE_DEVICE_STATUS_NOTIFICATION] =
-      &BluetoothDaemonHandsfreeModule::DeviceStatusNotificationRsp,
-    [OPCODE_COPS_RESPONSE] =
-      &BluetoothDaemonHandsfreeModule::CopsResponseRsp,
-    [OPCODE_CIND_RESPONSE] =
-      &BluetoothDaemonHandsfreeModule::CindResponseRsp,
-    [OPCODE_FORMATTED_AT_RESPONSE] =
-      &BluetoothDaemonHandsfreeModule::FormattedAtResponseRsp,
-    [OPCODE_AT_RESPONSE] =
-      &BluetoothDaemonHandsfreeModule::AtResponseRsp,
-    [OPCODE_CLCC_RESPONSE] =
-      &BluetoothDaemonHandsfreeModule::ClccResponseRsp,
-    [OPCODE_PHONE_STATE_CHANGE] =
-      &BluetoothDaemonHandsfreeModule::PhoneStateChangeRsp,
-    [OPCODE_CONFIGURE_WBS] =
-      &BluetoothDaemonHandsfreeModule::ConfigureWbsRsp
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-  if (NS_WARN_IF(!(aHeader.mOpcode < MOZ_ARRAY_LENGTH(HandleRsp))) ||
-      NS_WARN_IF(!HandleRsp[aHeader.mOpcode])) {
-    return;
-  }
-
-  RefPtr<BluetoothHandsfreeResultHandler> res =
-    static_cast<BluetoothHandsfreeResultHandler*>(aRes);
-
-  if (!res) {
-    return; // Return early if no result handler has been set for response
-  }
-
-  (this->*(HandleRsp[aHeader.mOpcode]))(aHeader, aPDU, res);
-}
-
-// Notifications
-//
-
-// Returns the current notification handler to a notification runnable
-class BluetoothDaemonHandsfreeModule::NotificationHandlerWrapper final
-{
-public:
-  typedef BluetoothHandsfreeNotificationHandler ObjectType;
-
-  static ObjectType* GetInstance()
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    return sNotificationHandler;
-  }
-};
-
-// Init operator class for ConnectionStateNotification
-class BluetoothDaemonHandsfreeModule::ConnectionStateInitOp final
-  : private PDUInitOp
-{
-public:
-  ConnectionStateInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothHandsfreeConnectionState& aArg1,
-               BluetoothAddress& aArg2) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read state */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read address */
-    rv = UnpackPDU(pdu, aArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-#if ANDROID_VERSION < 21
-    if (aArg1 == HFP_CONNECTION_STATE_CONNECTED) {
-      sConnectedDeviceAddress = aArg2;
-    } else if (aArg1 == HFP_CONNECTION_STATE_DISCONNECTED) {
-      sConnectedDeviceAddress = BluetoothAddress::ANY();
-    }
-#endif
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonHandsfreeModule::ConnectionStateNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ConnectionStateNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::ConnectionStateNotification,
-    ConnectionStateInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::AudioStateNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  AudioStateNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::AudioStateNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-// Init operator class for VoiceRecognitionNotification
-class BluetoothDaemonHandsfreeModule::VoiceRecognitionInitOp final
-  : private PDUInitOp
-{
-public:
-  VoiceRecognitionInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothHandsfreeVoiceRecognitionState& aArg1,
-               BluetoothAddress& aArg2) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read state */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read address */
-#if ANDROID_VERSION >= 21
-    rv = UnpackPDU(pdu, aArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-#else
-    aArg2 = sConnectedDeviceAddress;
-#endif
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonHandsfreeModule::VoiceRecognitionNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  VoiceRecognitionNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::VoiceRecognitionNotification,
-    VoiceRecognitionInitOp(aPDU));
-}
-
-// Init operator class for AnswerCallNotification
-class BluetoothDaemonHandsfreeModule::AnswerCallInitOp final
-  : private PDUInitOp
-{
-public:
-  AnswerCallInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothAddress& aArg1) const
-  {
-    /* Read address */
-#if ANDROID_VERSION >= 21
-    nsresult rv = UnpackPDU(GetPDU(), aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-#else
-    aArg1 = sConnectedDeviceAddress;
-#endif
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonHandsfreeModule::AnswerCallNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  AnswerCallNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::AnswerCallNotification,
-    AnswerCallInitOp(aPDU));
-}
-
-// Init operator class for HangupCallNotification
-class BluetoothDaemonHandsfreeModule::HangupCallInitOp final
-  : private PDUInitOp
-{
-public:
-  HangupCallInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothAddress& aArg1) const
-  {
-    /* Read address */
-#if ANDROID_VERSION >= 21
-    nsresult rv = UnpackPDU(GetPDU(), aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-#else
-    aArg1 = sConnectedDeviceAddress;
-#endif
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonHandsfreeModule::HangupCallNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  HangupCallNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::HangupCallNotification,
-    HangupCallInitOp(aPDU));
-}
-
-// Init operator class for VolumeNotification
-class BluetoothDaemonHandsfreeModule::VolumeInitOp final
-  : private PDUInitOp
-{
-public:
-  VolumeInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothHandsfreeVolumeType& aArg1, int& aArg2,
-               BluetoothAddress& aArg3) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read volume type */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read volume */
-    rv = UnpackPDU(pdu, UnpackConversion<uint8_t, int>(aArg2));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read address */
-#if ANDROID_VERSION >= 21
-    rv = UnpackPDU(pdu, aArg3);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-#else
-    aArg3 = sConnectedDeviceAddress;
-#endif
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonHandsfreeModule::VolumeNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  VolumeNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::VolumeNotification,
-    VolumeInitOp(aPDU));
-}
-
-// Init operator class for DialCallNotification
-class BluetoothDaemonHandsfreeModule::DialCallInitOp final
-  : private PDUInitOp
-{
-public:
-  DialCallInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (nsString& aArg1, BluetoothAddress& aArg2) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    nsresult rv;
-    /* Read address
-     * It's a little weird to parse aArg2 (aBdAddr) before parsing
-     * aArg1 (aNumber), but this order is defined in BlueZ 5.25 anyway.
-     */
-#if ANDROID_VERSION >= 21
-    rv = UnpackPDU( pdu, aArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-#else
-    aArg2 = sConnectedDeviceAddress;
-#endif
-
-    /* Read number */
-    rv = UnpackPDU(pdu, UnpackString0(aArg1));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonHandsfreeModule::DialCallNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  DialCallNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::DialCallNotification,
-    DialCallInitOp(aPDU));
-}
-
-// Init operator class for DtmfNotification
-class BluetoothDaemonHandsfreeModule::DtmfInitOp final
-  : private PDUInitOp
-{
-public:
-  DtmfInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (char& aArg1, BluetoothAddress& aArg2) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read tone */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read address */
-#if ANDROID_VERSION >= 21
-    rv = UnpackPDU(pdu, aArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-#else
-    aArg2 = sConnectedDeviceAddress;
-#endif
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonHandsfreeModule::DtmfNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  DtmfNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::DtmfNotification,
-    DtmfInitOp(aPDU));
-}
-
-// Init operator class for NRECNotification
-class BluetoothDaemonHandsfreeModule::NRECInitOp final
-  : private PDUInitOp
-{
-public:
-  NRECInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothHandsfreeNRECState& aArg1,
-               BluetoothAddress& aArg2) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read state */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read address */
-#if ANDROID_VERSION >= 21
-    rv = UnpackPDU(pdu, aArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-#else
-    aArg2 = sConnectedDeviceAddress;
-#endif
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonHandsfreeModule::NRECNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  NRECNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::NRECNotification,
-    NRECInitOp(aPDU));
-}
-
-// Init operator class for CallHoldNotification
-class BluetoothDaemonHandsfreeModule::CallHoldInitOp final
-  : private PDUInitOp
-{
-public:
-  CallHoldInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothHandsfreeCallHoldType& aArg1,
-               BluetoothAddress& aArg2) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    /* Read type */
-    nsresult rv = UnpackPDU(pdu, aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    /* Read address */
-#if ANDROID_VERSION >= 21
-    rv = UnpackPDU(pdu, aArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-#else
-    aArg2 = sConnectedDeviceAddress;
-#endif
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonHandsfreeModule::CallHoldNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  CallHoldNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::CallHoldNotification,
-    CallHoldInitOp(aPDU));
-}
-
-// Init operator class for CnumNotification
-class BluetoothDaemonHandsfreeModule::CnumInitOp final
-  : private PDUInitOp
-{
-public:
-  CnumInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothAddress& aArg1) const
-  {
-    /* Read address */
-#if ANDROID_VERSION >= 21
-    nsresult rv = UnpackPDU(GetPDU(), aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-#else
-    aArg1 = sConnectedDeviceAddress;
-#endif
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonHandsfreeModule::CnumNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  CnumNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::CnumNotification,
-    CnumInitOp(aPDU));
-}
-
-// Init operator class for CindNotification
-class BluetoothDaemonHandsfreeModule::CindInitOp final
-  : private PDUInitOp
-{
-public:
-  CindInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothAddress& aArg1) const
-  {
-    /* Read address */
-#if ANDROID_VERSION >= 21
-    nsresult rv = UnpackPDU(GetPDU(), aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-#else
-    aArg1 = sConnectedDeviceAddress;
-#endif
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonHandsfreeModule::CindNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  CindNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::CindNotification,
-    CindInitOp(aPDU));
-}
-
-// Init operator class for CopsNotification
-class BluetoothDaemonHandsfreeModule::CopsInitOp final
-  : private PDUInitOp
-{
-public:
-  CopsInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothAddress& aArg1) const
-  {
-    /* Read address */
-#if ANDROID_VERSION >= 21
-    nsresult rv = UnpackPDU(GetPDU(), aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-#else
-    aArg1 = sConnectedDeviceAddress;
-#endif
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonHandsfreeModule::CopsNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  CopsNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::CopsNotification,
-    CopsInitOp(aPDU));
-}
-
-// Init operator class for ClccNotification
-class BluetoothDaemonHandsfreeModule::ClccInitOp final
-  : private PDUInitOp
-{
-public:
-  ClccInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothAddress& aArg1) const
-  {
-    /* Read address */
-#if ANDROID_VERSION >= 21
-    nsresult rv = UnpackPDU(GetPDU(), aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-#else
-    aArg1 = sConnectedDeviceAddress;
-#endif
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonHandsfreeModule::ClccNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ClccNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::ClccNotification,
-    ClccInitOp(aPDU));
-}
-
-// Init operator class for UnknownAtNotification
-class BluetoothDaemonHandsfreeModule::UnknownAtInitOp final
-  : private PDUInitOp
-{
-public:
-  UnknownAtInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (nsCString& aArg1, BluetoothAddress& aArg2) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    nsresult rv;
-    /* Read address
-     * It's a little weird to parse aArg2(aBdAddr) before parsing
-     * aArg1(aAtString), but this order is defined in BlueZ 5.25 anyway.
-     */
-#if ANDROID_VERSION >= 21
-    rv = UnpackPDU(pdu, aArg2);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-#else
-    aArg2 = sConnectedDeviceAddress;
-#endif
-
-    /* Read string */
-    rv = UnpackPDU(pdu, UnpackCString0(aArg1));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonHandsfreeModule::UnknownAtNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  UnknownAtNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::UnknownAtNotification,
-    UnknownAtInitOp(aPDU));
-}
-
-// Init operator class for KeyPressedNotification
-class BluetoothDaemonHandsfreeModule::KeyPressedInitOp final
-  : private PDUInitOp
-{
-public:
-  KeyPressedInitOp(DaemonSocketPDU& aPDU)
-    : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (BluetoothAddress& aArg1) const
-  {
-    /* Read address */
-#if ANDROID_VERSION >= 21
-    nsresult rv = UnpackPDU(GetPDU(), aArg1);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-#else
-    aArg1 = sConnectedDeviceAddress;
-#endif
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonHandsfreeModule::KeyPressedNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  KeyPressedNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::KeyPressedNotification,
-    KeyPressedInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::WbsNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  WbsNotification::Dispatch(
-    &BluetoothHandsfreeNotificationHandler::WbsNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHandsfreeModule::HandleNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonHandsfreeModule::* const HandleNtf[])(
-    const DaemonSocketPDUHeader&, DaemonSocketPDU&) = {
-    [0] = &BluetoothDaemonHandsfreeModule::ConnectionStateNtf,
-    [1] = &BluetoothDaemonHandsfreeModule::AudioStateNtf,
-    [2] = &BluetoothDaemonHandsfreeModule::VoiceRecognitionNtf,
-    [3] = &BluetoothDaemonHandsfreeModule::AnswerCallNtf,
-    [4] = &BluetoothDaemonHandsfreeModule::HangupCallNtf,
-    [5] = &BluetoothDaemonHandsfreeModule::VolumeNtf,
-    [6] = &BluetoothDaemonHandsfreeModule::DialCallNtf,
-    [7] = &BluetoothDaemonHandsfreeModule::DtmfNtf,
-    [8] = &BluetoothDaemonHandsfreeModule::NRECNtf,
-    [9] = &BluetoothDaemonHandsfreeModule::CallHoldNtf,
-    [10] = &BluetoothDaemonHandsfreeModule::CnumNtf,
-    [11] = &BluetoothDaemonHandsfreeModule::CindNtf,
-    [12] = &BluetoothDaemonHandsfreeModule::CopsNtf,
-    [13] = &BluetoothDaemonHandsfreeModule::ClccNtf,
-    [14] = &BluetoothDaemonHandsfreeModule::UnknownAtNtf,
-    [15] = &BluetoothDaemonHandsfreeModule::KeyPressedNtf,
-    [16] = &BluetoothDaemonHandsfreeModule::WbsNtf
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread());
-
-  uint8_t index = aHeader.mOpcode - 0x81;
-
-  if (NS_WARN_IF(!(index < MOZ_ARRAY_LENGTH(HandleNtf))) ||
-      NS_WARN_IF(!HandleNtf[index])) {
-    return;
-  }
-
-  (this->*(HandleNtf[index]))(aHeader, aPDU);
-}
-
-//
-// Handsfree interface
-//
-
-BluetoothDaemonHandsfreeInterface::BluetoothDaemonHandsfreeInterface(
-  BluetoothDaemonHandsfreeModule* aModule)
-  : mModule(aModule)
-{ }
-
-BluetoothDaemonHandsfreeInterface::~BluetoothDaemonHandsfreeInterface()
-{ }
-
-void BluetoothDaemonHandsfreeInterface::SetNotificationHandler(
-  BluetoothHandsfreeNotificationHandler* aNotificationHandler)
-{
-  MOZ_ASSERT(mModule);
-
-  mModule->SetNotificationHandler(aNotificationHandler);
-}
-
-/* Connect / Disconnect */
-
-void
-BluetoothDaemonHandsfreeInterface::Connect(
-  const BluetoothAddress& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ConnectCmd(aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonHandsfreeInterface::Disconnect(
-  const BluetoothAddress& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->DisconnectCmd(aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonHandsfreeInterface::ConnectAudio(
-  const BluetoothAddress& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ConnectAudioCmd(aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonHandsfreeInterface::DisconnectAudio(
-  const BluetoothAddress& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->DisconnectAudioCmd(aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Voice Recognition */
-
-void
-BluetoothDaemonHandsfreeInterface::StartVoiceRecognition(
-  const BluetoothAddress& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->StartVoiceRecognitionCmd(aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonHandsfreeInterface::StopVoiceRecognition(
-  const BluetoothAddress& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->StopVoiceRecognitionCmd(aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Volume */
-
-void
-BluetoothDaemonHandsfreeInterface::VolumeControl(
-  BluetoothHandsfreeVolumeType aType, int aVolume,
-  const BluetoothAddress& aBdAddr,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->VolumeControlCmd(aType, aVolume, aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Device status */
-
-void
-BluetoothDaemonHandsfreeInterface::DeviceStatusNotification(
-  BluetoothHandsfreeNetworkState aNtkState,
-  BluetoothHandsfreeServiceType aSvcType, int aSignal, int aBattChg,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->DeviceStatusNotificationCmd(aNtkState, aSvcType,
-                                                     aSignal, aBattChg,
-                                                     aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Responses */
-
-void
-BluetoothDaemonHandsfreeInterface::CopsResponse(
-  const char* aCops, const BluetoothAddress& aBdAddr,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->CopsResponseCmd(aCops, aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonHandsfreeInterface::CindResponse(
-  int aSvc, int aNumActive, int aNumHeld,
-  BluetoothHandsfreeCallState aCallSetupState,
-  int aSignal, int aRoam, int aBattChg,
-  const BluetoothAddress& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->CindResponseCmd(aSvc, aNumActive, aNumHeld,
-                                         aCallSetupState, aSignal,
-                                         aRoam, aBattChg, aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonHandsfreeInterface::FormattedAtResponse(
-  const char* aRsp, const BluetoothAddress& aBdAddr,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->FormattedAtResponseCmd(aRsp, aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonHandsfreeInterface::AtResponse(
-  BluetoothHandsfreeAtResponse aResponseCode, int aErrorCode,
-  const BluetoothAddress& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->AtResponseCmd(aResponseCode, aErrorCode,
-                                       aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonHandsfreeInterface::ClccResponse(
-  int aIndex, BluetoothHandsfreeCallDirection aDir,
-  BluetoothHandsfreeCallState aState,
-  BluetoothHandsfreeCallMode aMode,
-  BluetoothHandsfreeCallMptyType aMpty,
-  const nsAString& aNumber,
-  BluetoothHandsfreeCallAddressType aType,
-  const BluetoothAddress& aBdAddr,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ClccResponseCmd(aIndex, aDir, aState, aMode, aMpty,
-                                         aNumber, aType, aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Phone State */
-
-void
-BluetoothDaemonHandsfreeInterface::PhoneStateChange(
-  int aNumActive, int aNumHeld,
-  BluetoothHandsfreeCallState aCallSetupState,
-  const nsAString& aNumber,
-  BluetoothHandsfreeCallAddressType aType,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->PhoneStateChangeCmd(aNumActive, aNumHeld,
-                                             aCallSetupState, aNumber,
-                                             aType, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Wide Band Speech */
-
-void
-BluetoothDaemonHandsfreeInterface::ConfigureWbs(
-  const BluetoothAddress& aBdAddr, BluetoothHandsfreeWbsConfig aConfig,
-  BluetoothHandsfreeResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ConfigureWbsCmd(aBdAddr, aConfig, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonHandsfreeInterface::DispatchError(
-  BluetoothHandsfreeResultHandler* aRes, BluetoothStatus aStatus)
-{
-  DaemonResultRunnable1<BluetoothHandsfreeResultHandler, void,
-                        BluetoothStatus, BluetoothStatus>::Dispatch(
-    aRes, &BluetoothHandsfreeResultHandler::OnError,
-    ConstantInitOp1<BluetoothStatus>(aStatus));
-}
-
-void
-BluetoothDaemonHandsfreeInterface::DispatchError(
-  BluetoothHandsfreeResultHandler* aRes, nsresult aRv)
-{
-  BluetoothStatus status;
-
-  if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
-    status = STATUS_FAIL;
-  }
-  DispatchError(aRes, status);
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.h
+++ /dev/null
@@ -1,480 +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_BluetoothDaemonHandsfreeInterface_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothDaemonHandsfreeInterface_h
-
-#include "BluetoothDaemonHelpers.h"
-#include "BluetoothInterface.h"
-#include "mozilla/ipc/DaemonRunnables.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using mozilla::ipc::DaemonSocketPDU;
-using mozilla::ipc::DaemonSocketPDUHeader;
-using mozilla::ipc::DaemonSocketResultHandler;
-
-class BluetoothDaemonHandsfreeModule
-{
-public:
-  enum {
-    SERVICE_ID = 0x05
-  };
-
-  enum {
-    OPCODE_ERROR = 0x00,
-    OPCODE_CONNECT = 0x01,
-    OPCODE_DISCONNECT = 0x02,
-    OPCODE_CONNECT_AUDIO = 0x03,
-    OPCODE_DISCONNECT_AUDIO = 0x04,
-    OPCODE_START_VOICE_RECOGNITION = 0x05,
-    OPCODE_STOP_VOICE_RECOGNITION =0x06,
-    OPCODE_VOLUME_CONTROL = 0x07,
-    OPCODE_DEVICE_STATUS_NOTIFICATION = 0x08,
-    OPCODE_COPS_RESPONSE = 0x09,
-    OPCODE_CIND_RESPONSE = 0x0a,
-    OPCODE_FORMATTED_AT_RESPONSE = 0x0b,
-    OPCODE_AT_RESPONSE = 0x0c,
-    OPCODE_CLCC_RESPONSE = 0x0d,
-    OPCODE_PHONE_STATE_CHANGE = 0x0e,
-    OPCODE_CONFIGURE_WBS = 0x0f
-  };
-
-  virtual nsresult Send(DaemonSocketPDU* aPDU,
-                        DaemonSocketResultHandler* aRes) = 0;
-
-  void SetNotificationHandler(
-    BluetoothHandsfreeNotificationHandler* aNotificationHandler);
-
-  //
-  // Commands
-  //
-
-  nsresult ConnectCmd(const BluetoothAddress& aBdAddr,
-                      BluetoothHandsfreeResultHandler* aRes);
-  nsresult DisconnectCmd(const BluetoothAddress& aBdAddr,
-                         BluetoothHandsfreeResultHandler* aRes);
-  nsresult ConnectAudioCmd(const BluetoothAddress& aBdAddr,
-                           BluetoothHandsfreeResultHandler* aRes);
-  nsresult DisconnectAudioCmd(const BluetoothAddress& aBdAddr,
-                              BluetoothHandsfreeResultHandler* aRes);
-
-  /* Voice Recognition */
-
-  nsresult StartVoiceRecognitionCmd(const BluetoothAddress& aBdAddr,
-                                    BluetoothHandsfreeResultHandler* aRes);
-  nsresult StopVoiceRecognitionCmd(const BluetoothAddress& aBdAddr,
-                                   BluetoothHandsfreeResultHandler* aRes);
-
-  /* Volume */
-
-  nsresult VolumeControlCmd(BluetoothHandsfreeVolumeType aType, int aVolume,
-                            const BluetoothAddress& aBdAddr,
-                            BluetoothHandsfreeResultHandler* aRes);
-
-  /* Device status */
-
-  nsresult DeviceStatusNotificationCmd(
-    BluetoothHandsfreeNetworkState aNtkState,
-    BluetoothHandsfreeServiceType aSvcType,
-    int aSignal, int aBattChg,
-    BluetoothHandsfreeResultHandler* aRes);
-
-  /* Responses */
-
-  nsresult CopsResponseCmd(const char* aCops, const BluetoothAddress& aBdAddr,
-                           BluetoothHandsfreeResultHandler* aRes);
-  nsresult CindResponseCmd(int aSvc, int aNumActive, int aNumHeld,
-                           BluetoothHandsfreeCallState aCallSetupState,
-                           int aSignal, int aRoam, int aBattChg,
-                           const BluetoothAddress& aBdAddr,
-                           BluetoothHandsfreeResultHandler* aRes);
-  nsresult FormattedAtResponseCmd(const char* aRsp,
-                                  const BluetoothAddress& aBdAddr,
-                                  BluetoothHandsfreeResultHandler* aRes);
-  nsresult AtResponseCmd(BluetoothHandsfreeAtResponse aResponseCode,
-                         int aErrorCode, const BluetoothAddress& aBdAddr,
-                         BluetoothHandsfreeResultHandler* aRes);
-  nsresult ClccResponseCmd(int aIndex, BluetoothHandsfreeCallDirection aDir,
-                           BluetoothHandsfreeCallState aState,
-                           BluetoothHandsfreeCallMode aMode,
-                           BluetoothHandsfreeCallMptyType aMpty,
-                           const nsAString& aNumber,
-                           BluetoothHandsfreeCallAddressType aType,
-                           const BluetoothAddress& aBdAddr,
-                           BluetoothHandsfreeResultHandler* aRes);
-
-  /* Phone State */
-
-  nsresult PhoneStateChangeCmd(int aNumActive, int aNumHeld,
-                               BluetoothHandsfreeCallState aCallSetupState,
-                               const nsAString& aNumber,
-                               BluetoothHandsfreeCallAddressType aType,
-                               BluetoothHandsfreeResultHandler* aRes);
-
-  /* Wide Band Speech */
-
-  nsresult ConfigureWbsCmd(const BluetoothAddress& aBdAddr,
-                           BluetoothHandsfreeWbsConfig aConfig,
-                           BluetoothHandsfreeResultHandler* aRes);
-
-protected:
-  void HandleSvc(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU,
-                 DaemonSocketResultHandler* aRes);
-
-  //
-  // Responses
-  //
-
-  typedef mozilla::ipc::DaemonResultRunnable0<
-    BluetoothHandsfreeResultHandler, void>
-    ResultRunnable;
-
-  typedef mozilla::ipc::DaemonResultRunnable1<
-    BluetoothHandsfreeResultHandler, void, BluetoothStatus, BluetoothStatus>
-    ErrorRunnable;
-
-  void ErrorRsp(const DaemonSocketPDUHeader& aHeader,
-                DaemonSocketPDU& aPDU,
-                BluetoothHandsfreeResultHandler* aRes);
-
-  void ConnectRsp(const DaemonSocketPDUHeader& aHeader,
-                  DaemonSocketPDU& aPDU,
-                  BluetoothHandsfreeResultHandler* aRes);
-
-  void DisconnectRsp(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU,
-                     BluetoothHandsfreeResultHandler* aRes);
-
-  void ConnectAudioRsp(const DaemonSocketPDUHeader& aHeader,
-                       DaemonSocketPDU& aPDU,
-                       BluetoothHandsfreeResultHandler* aRes);
-
-  void DisconnectAudioRsp(const DaemonSocketPDUHeader& aHeader,
-                          DaemonSocketPDU& aPDU,
-                          BluetoothHandsfreeResultHandler* aRes);
-
-  void StartVoiceRecognitionRsp(const DaemonSocketPDUHeader& aHeader,
-                                DaemonSocketPDU& aPDU,
-                                BluetoothHandsfreeResultHandler* aRes);
-
-  void StopVoiceRecognitionRsp(const DaemonSocketPDUHeader& aHeader,
-                               DaemonSocketPDU& aPDU,
-                               BluetoothHandsfreeResultHandler* aRes);
-
-  void VolumeControlRsp(const DaemonSocketPDUHeader& aHeader,
-                        DaemonSocketPDU& aPDU,
-                        BluetoothHandsfreeResultHandler* aRes);
-
-  void DeviceStatusNotificationRsp(const DaemonSocketPDUHeader& aHeader,
-                                   DaemonSocketPDU& aPDU,
-                                   BluetoothHandsfreeResultHandler* aRes);
-
-  void CopsResponseRsp(const DaemonSocketPDUHeader& aHeader,
-                       DaemonSocketPDU& aPDU,
-                       BluetoothHandsfreeResultHandler* aRes);
-
-  void CindResponseRsp(const DaemonSocketPDUHeader& aHeader,
-                       DaemonSocketPDU& aPDU,
-                       BluetoothHandsfreeResultHandler* aRes);
-
-  void FormattedAtResponseRsp(const DaemonSocketPDUHeader& aHeader,
-                              DaemonSocketPDU& aPDU,
-                              BluetoothHandsfreeResultHandler* aRes);
-
-  void AtResponseRsp(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU,
-                     BluetoothHandsfreeResultHandler* aRes);
-
-  void ClccResponseRsp(const DaemonSocketPDUHeader& aHeader,
-                       DaemonSocketPDU& aPDU,
-                       BluetoothHandsfreeResultHandler* aRes);
-
-  void PhoneStateChangeRsp(const DaemonSocketPDUHeader& aHeader,
-                           DaemonSocketPDU& aPDU,
-                           BluetoothHandsfreeResultHandler* aRes);
-
-  void ConfigureWbsRsp(const DaemonSocketPDUHeader& aHeader,
-                       DaemonSocketPDU& aPDU,
-                       BluetoothHandsfreeResultHandler* aRes);
-
-  void HandleRsp(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU,
-                 DaemonSocketResultHandler* aRes);
-
-  //
-  // Notifications
-  //
-
-  class NotificationHandlerWrapper;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    BluetoothHandsfreeConnectionState, BluetoothAddress,
-    BluetoothHandsfreeConnectionState, const BluetoothAddress&>
-    ConnectionStateNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    BluetoothHandsfreeAudioState, BluetoothAddress,
-    BluetoothHandsfreeAudioState, const BluetoothAddress&>
-    AudioStateNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    BluetoothHandsfreeVoiceRecognitionState, BluetoothAddress,
-    BluetoothHandsfreeVoiceRecognitionState, const BluetoothAddress&>
-    VoiceRecognitionNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable1<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, const BluetoothAddress&>
-    AnswerCallNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable1<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, const BluetoothAddress&>
-    HangupCallNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    BluetoothHandsfreeVolumeType, int, BluetoothAddress,
-    BluetoothHandsfreeVolumeType, int, const BluetoothAddress&>
-    VolumeNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    nsString, BluetoothAddress,
-    const nsAString&, const BluetoothAddress&>
-    DialCallNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    char, BluetoothAddress, char, const BluetoothAddress&>
-    DtmfNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    BluetoothHandsfreeNRECState, BluetoothAddress,
-    BluetoothHandsfreeNRECState, const BluetoothAddress&>
-    NRECNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    BluetoothHandsfreeCallHoldType, BluetoothAddress,
-    BluetoothHandsfreeCallHoldType, const BluetoothAddress&>
-    CallHoldNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable1<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, const BluetoothAddress&>
-    CnumNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable1<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, const BluetoothAddress&>
-    CindNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable1<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, const BluetoothAddress&>
-    CopsNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable1<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, const BluetoothAddress&>
-    ClccNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    nsCString, BluetoothAddress,
-    const nsACString&, const BluetoothAddress&>
-    UnknownAtNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable1<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, const BluetoothAddress&>
-    KeyPressedNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    BluetoothHandsfreeWbsConfig, BluetoothAddress,
-    BluetoothHandsfreeWbsConfig, const BluetoothAddress&>
-    WbsNotification;
-
-  class ConnectionStateInitOp;
-  class VoiceRecognitionInitOp;
-  class AnswerCallInitOp;
-  class HangupCallInitOp;
-  class VolumeInitOp;
-  class DialCallInitOp;
-  class DtmfInitOp;
-  class NRECInitOp;
-  class CallHoldInitOp;
-  class CnumInitOp;
-  class CindInitOp;
-  class CopsInitOp;
-  class ClccInitOp;
-  class VolumeInitOp;
-  class UnknownAtInitOp;
-  class KeyPressedInitOp;
-
-  void ConnectionStateNtf(const DaemonSocketPDUHeader& aHeader,
-                          DaemonSocketPDU& aPDU);
-
-  void AudioStateNtf(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU);
-
-  void VoiceRecognitionNtf(const DaemonSocketPDUHeader& aHeader,
-                           DaemonSocketPDU& aPDU);
-
-  void AnswerCallNtf(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU);
-
-  void HangupCallNtf(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU);
-
-  void VolumeNtf(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU);
-
-  void DialCallNtf(const DaemonSocketPDUHeader& aHeader,
-                   DaemonSocketPDU& aPDU);
-
-  void DtmfNtf(const DaemonSocketPDUHeader& aHeader,
-               DaemonSocketPDU& aPDU);
-
-  void NRECNtf(const DaemonSocketPDUHeader& aHeader,
-               DaemonSocketPDU& aPDU);
-
-  void CallHoldNtf(const DaemonSocketPDUHeader& aHeader,
-                   DaemonSocketPDU& aPDU);
-
-  void CnumNtf(const DaemonSocketPDUHeader& aHeader,
-               DaemonSocketPDU& aPDU);
-
-  void CindNtf(const DaemonSocketPDUHeader& aHeader,
-               DaemonSocketPDU& aPDU);
-
-  void CopsNtf(const DaemonSocketPDUHeader& aHeader,
-               DaemonSocketPDU& aPDU);
-
-  void ClccNtf(const DaemonSocketPDUHeader& aHeader,
-               DaemonSocketPDU& aPDU);
-
-  void UnknownAtNtf(const DaemonSocketPDUHeader& aHeader,
-                    DaemonSocketPDU& aPDU);
-
-  void KeyPressedNtf(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU);
-
-  void WbsNtf(const DaemonSocketPDUHeader& aHeader,
-              DaemonSocketPDU& aPDU);
-
-  void HandleNtf(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU,
-                 DaemonSocketResultHandler* aRes);
-
-  static BluetoothHandsfreeNotificationHandler* sNotificationHandler;
-#if ANDROID_VERSION < 21
-  /* |sConnectedDeviceAddress| stores Bluetooth device address of the
-   * connected device. Before BlueZ 5.25, we maintain this address by
-   * ourselves through ConnectionStateNtf(); after BlueZ 5.25, every
-   * callback carries this address directly so we don't have to keep
-   * it.
-   */
-  static BluetoothAddress sConnectedDeviceAddress;
-#endif
-};
-
-class BluetoothDaemonHandsfreeInterface final
-  : public BluetoothHandsfreeInterface
-{
-public:
-  BluetoothDaemonHandsfreeInterface(BluetoothDaemonHandsfreeModule* aModule);
-  ~BluetoothDaemonHandsfreeInterface();
-
-  void SetNotificationHandler(
-    BluetoothHandsfreeNotificationHandler* aNotificationHandler) override;
-
-  /* Connect / Disconnect */
-
-  void Connect(const BluetoothAddress& aBdAddr,
-               BluetoothHandsfreeResultHandler* aRes) override;
-  void Disconnect(const BluetoothAddress& aBdAddr,
-                  BluetoothHandsfreeResultHandler* aRes) override;
-  void ConnectAudio(const BluetoothAddress& aBdAddr,
-                    BluetoothHandsfreeResultHandler* aRes) override;
-  void DisconnectAudio(const BluetoothAddress& aBdAddr,
-                       BluetoothHandsfreeResultHandler* aRes) override;
-
-  /* Voice Recognition */
-
-  void StartVoiceRecognition(const BluetoothAddress& aBdAddr,
-                             BluetoothHandsfreeResultHandler* aRes) override;
-  void StopVoiceRecognition(const BluetoothAddress& aBdAddr,
-                            BluetoothHandsfreeResultHandler* aRes) override;
-
-  /* Volume */
-
-  void VolumeControl(BluetoothHandsfreeVolumeType aType, int aVolume,
-                     const BluetoothAddress& aBdAddr,
-                     BluetoothHandsfreeResultHandler* aRes) override;
-
-  /* Device status */
-
-  void DeviceStatusNotification(BluetoothHandsfreeNetworkState aNtkState,
-                                BluetoothHandsfreeServiceType aSvcType,
-                                int aSignal, int aBattChg,
-                                BluetoothHandsfreeResultHandler* aRes) override;
-
-  /* Responses */
-
-  void CopsResponse(const char* aCops, const BluetoothAddress& aBdAddr,
-                    BluetoothHandsfreeResultHandler* aRes);
-  void CindResponse(int aSvc, int aNumActive, int aNumHeld,
-                    BluetoothHandsfreeCallState aCallSetupState,
-                    int aSignal, int aRoam, int aBattChg,
-                    const BluetoothAddress& aBdAddr,
-                    BluetoothHandsfreeResultHandler* aRes) override;
-  void FormattedAtResponse(const char* aRsp, const BluetoothAddress& aBdAddr,
-                           BluetoothHandsfreeResultHandler* aRes) override;
-  void AtResponse(BluetoothHandsfreeAtResponse aResponseCode, int aErrorCode,
-                  const BluetoothAddress& aBdAddr,
-                  BluetoothHandsfreeResultHandler* aRes) override;
-  void ClccResponse(int aIndex, BluetoothHandsfreeCallDirection aDir,
-                    BluetoothHandsfreeCallState aState,
-                    BluetoothHandsfreeCallMode aMode,
-                    BluetoothHandsfreeCallMptyType aMpty,
-                    const nsAString& aNumber,
-                    BluetoothHandsfreeCallAddressType aType,
-                    const BluetoothAddress& aBdAddr,
-                    BluetoothHandsfreeResultHandler* aRes) override;
-
-  /* Phone State */
-
-  void PhoneStateChange(int aNumActive, int aNumHeld,
-                        BluetoothHandsfreeCallState aCallSetupState,
-                        const nsAString& aNumber,
-                        BluetoothHandsfreeCallAddressType aType,
-                        BluetoothHandsfreeResultHandler* aRes) override;
-
-  /* Wide Band Speech */
-  void ConfigureWbs(const BluetoothAddress& aBdAddr,
-                    BluetoothHandsfreeWbsConfig aConfig,
-                    BluetoothHandsfreeResultHandler* aRes) override;
-
-private:
-  void DispatchError(BluetoothHandsfreeResultHandler* aRes,
-                     BluetoothStatus aStatus);
-  void DispatchError(BluetoothHandsfreeResultHandler* aRes, nsresult aRv);
-
-  BluetoothDaemonHandsfreeModule* mModule;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothDaemonHandsfreeInterface_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.cpp
+++ /dev/null
@@ -1,2065 +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 "BluetoothDaemonHelpers.h"
-#include <limits>
-
-#define MAX_UUID_SIZE 16
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using mozilla::ipc::DaemonSocketPDUHelpers::Convert;
-using mozilla::ipc::DaemonSocketPDUHelpers::PackPDU;
-
-//
-// Conversion
-//
-
-nsresult
-Convert(bool aIn, BluetoothScanMode& aOut)
-{
-  static const BluetoothScanMode sScanMode[] = {
-    [false] = SCAN_MODE_CONNECTABLE,
-    [true] = SCAN_MODE_CONNECTABLE_DISCOVERABLE
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sScanMode), bool, BluetoothScanMode)) {
-    aOut = SCAN_MODE_NONE; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sScanMode[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(int32_t aIn, BluetoothTypeOfDevice& aOut)
-{
-  static const BluetoothTypeOfDevice sTypeOfDevice[] = {
-    [0x00] = static_cast<BluetoothTypeOfDevice>(0), // invalid, required by gcc
-    [0x01] = TYPE_OF_DEVICE_BREDR,
-    [0x02] = TYPE_OF_DEVICE_BLE,
-    [0x03] = TYPE_OF_DEVICE_DUAL
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        !aIn, int32_t, BluetoothTypeOfDevice) ||
-      MOZ_HAL_IPC_CONVERT_WARN_IF(
-        static_cast<size_t>(aIn) >= MOZ_ARRAY_LENGTH(sTypeOfDevice), int32_t,
-        BluetoothTypeOfDevice)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sTypeOfDevice[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(int32_t aIn, BluetoothScanMode& aOut)
-{
-  static const BluetoothScanMode sScanMode[] = {
-    [0x00] = SCAN_MODE_NONE,
-    [0x01] = SCAN_MODE_CONNECTABLE,
-    [0x02] = SCAN_MODE_CONNECTABLE_DISCOVERABLE
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn < 0, int32_t, BluetoothScanMode) ||
-      MOZ_HAL_IPC_CONVERT_WARN_IF(
-        static_cast<size_t>(aIn) >= MOZ_ARRAY_LENGTH(sScanMode), int32_t,
-        BluetoothScanMode)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sScanMode[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothA2dpAudioState& aOut)
-{
-  static const BluetoothA2dpAudioState sAudioState[] = {
-    [0x00] = A2DP_AUDIO_STATE_REMOTE_SUSPEND,
-    [0x01] = A2DP_AUDIO_STATE_STOPPED,
-    [0x02] = A2DP_AUDIO_STATE_STARTED
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sAudioState), uint8_t,
-        BluetoothA2dpAudioState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sAudioState[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothA2dpConnectionState& aOut)
-{
-  static const BluetoothA2dpConnectionState sConnectionState[] = {
-    [0x00] = A2DP_CONNECTION_STATE_DISCONNECTED,
-    [0x01] = A2DP_CONNECTION_STATE_CONNECTING,
-    [0x02] = A2DP_CONNECTION_STATE_CONNECTED,
-    [0x03] = A2DP_CONNECTION_STATE_DISCONNECTING
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sConnectionState), uint8_t,
-        BluetoothA2dpConnectionState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sConnectionState[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothAclState& aOut)
-{
-  static const BluetoothAclState sAclState[] = {
-    [0x00] = ACL_STATE_CONNECTED,
-    [0x01] = ACL_STATE_DISCONNECTED
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sAclState), uint8_t, BluetoothAclState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sAclState[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothAvrcpEvent& aOut)
-{
-  static const BluetoothAvrcpEvent sAvrcpEvent[] = {
-    [0x00] = static_cast<BluetoothAvrcpEvent>(0),
-    [0x01] = AVRCP_EVENT_PLAY_STATUS_CHANGED,
-    [0x02] = AVRCP_EVENT_TRACK_CHANGE,
-    [0x03] = AVRCP_EVENT_TRACK_REACHED_END,
-    [0x04] = AVRCP_EVENT_TRACK_REACHED_START,
-    [0x05] = AVRCP_EVENT_PLAY_POS_CHANGED,
-    [0x06] = static_cast<BluetoothAvrcpEvent>(0),
-    [0x07] = static_cast<BluetoothAvrcpEvent>(0),
-    [0x08] = AVRCP_EVENT_APP_SETTINGS_CHANGED
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        !aIn, uint8_t, BluetoothAvrcpEvent) ||
-      MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn == 0x06, uint8_t, BluetoothAvrcpEvent) ||
-      MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn == 0x07, uint8_t, BluetoothAvrcpEvent) ||
-      MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sAvrcpEvent), uint8_t, BluetoothAvrcpEvent)) {
-    aOut = static_cast<BluetoothAvrcpEvent>(0); // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sAvrcpEvent[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothAvrcpMediaAttribute& aOut)
-{
-  static const BluetoothAvrcpMediaAttribute sAvrcpMediaAttribute[] = {
-    [0x00] = static_cast<BluetoothAvrcpMediaAttribute>(0),
-    [0x01] = AVRCP_MEDIA_ATTRIBUTE_TITLE,
-    [0x02] = AVRCP_MEDIA_ATTRIBUTE_ARTIST,
-    [0x03] = AVRCP_MEDIA_ATTRIBUTE_ALBUM,
-    [0x04] = AVRCP_MEDIA_ATTRIBUTE_TRACK_NUM,
-    [0x05] = AVRCP_MEDIA_ATTRIBUTE_NUM_TRACKS,
-    [0x06] = AVRCP_MEDIA_ATTRIBUTE_GENRE,
-    [0x07] = AVRCP_MEDIA_ATTRIBUTE_PLAYING_TIME
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        !aIn, uint8_t, BluetoothAvrcpMediaAttrbiute) ||
-      MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sAvrcpMediaAttribute), uint8_t,
-        BluetoothAvrcpMediaAttribute)) {
-    // silences compiler warning
-    aOut = static_cast<BluetoothAvrcpMediaAttribute>(0);
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sAvrcpMediaAttribute[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothAvrcpPlayerAttribute& aOut)
-{
-  static const BluetoothAvrcpPlayerAttribute sAvrcpPlayerAttribute[] = {
-    [0x00] = static_cast<BluetoothAvrcpPlayerAttribute>(0),
-    [0x01] = AVRCP_PLAYER_ATTRIBUTE_EQUALIZER,
-    [0x02] = AVRCP_PLAYER_ATTRIBUTE_REPEAT,
-    [0x03] = AVRCP_PLAYER_ATTRIBUTE_SHUFFLE,
-    [0x04] = AVRCP_PLAYER_ATTRIBUTE_SCAN
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        !aIn, uint8_t, BluetoothAvrcpPlayerAttrbiute) ||
-      MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sAvrcpPlayerAttribute), uint8_t,
-        BluetoothAvrcpPlayerAttribute)) {
-    // silences compiler warning
-    aOut = static_cast<BluetoothAvrcpPlayerAttribute>(0);
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sAvrcpPlayerAttribute[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothAvrcpRemoteFeatureBits& aOut)
-{
-  static const uint8_t sAvrcpRemoteFeatureBits[] = {
-    [0] = AVRCP_REMOTE_FEATURE_METADATA,
-    [1] = AVRCP_REMOTE_FEATURE_ABSOLUTE_VOLUME,
-    [2] = AVRCP_REMOTE_FEATURE_BROWSE
-  };
-  uint8_t bits = 0;
-  size_t i;
-  for (i = 0; i < MOZ_ARRAY_LENGTH(sAvrcpRemoteFeatureBits); ++i, aIn >>= 1) {
-    if (aIn & 0x01) {
-      bits |= sAvrcpRemoteFeatureBits[i];
-    }
-  }
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn << i, 'uint8_t', BluetoothAvrcpRemoteFeatureBits)) {
-    aOut = AVRCP_REMOTE_FEATURE_NONE; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = static_cast<BluetoothAvrcpRemoteFeatureBits>(bits);
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothBondState& aOut)
-{
-  static const BluetoothBondState sBondState[] = {
-    [0x00] = BOND_STATE_NONE,
-    [0x01] = BOND_STATE_BONDING,
-    [0x02] = BOND_STATE_BONDED
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sBondState), uint8_t, BluetoothBondState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sBondState[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothHandsfreeAudioState& aOut)
-{
-  static const BluetoothHandsfreeAudioState sAudioState[] = {
-    [0x00] = HFP_AUDIO_STATE_DISCONNECTED,
-    [0x01] = HFP_AUDIO_STATE_CONNECTING,
-    [0x02] = HFP_AUDIO_STATE_CONNECTED,
-    [0x03] = HFP_AUDIO_STATE_DISCONNECTING
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sAudioState), uint8_t,
-        BluetoothHandsfreeAudioState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sAudioState[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothHandsfreeCallHoldType& aOut)
-{
-  static const BluetoothHandsfreeCallHoldType sCallHoldType[] = {
-    [0x00] = HFP_CALL_HOLD_RELEASEHELD,
-    [0x01] = HFP_CALL_HOLD_RELEASEACTIVE_ACCEPTHELD,
-    [0x02] = HFP_CALL_HOLD_HOLDACTIVE_ACCEPTHELD,
-    [0x03] = HFP_CALL_HOLD_ADDHELDTOCONF
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sCallHoldType), uint8_t,
-        BluetoothHandsfreeCallHoldType)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sCallHoldType[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothHandsfreeConnectionState& aOut)
-{
-  static const BluetoothHandsfreeConnectionState sConnectionState[] = {
-    [0x00] = HFP_CONNECTION_STATE_DISCONNECTED,
-    [0x01] = HFP_CONNECTION_STATE_CONNECTING,
-    [0x02] = HFP_CONNECTION_STATE_CONNECTED,
-    [0x03] = HFP_CONNECTION_STATE_SLC_CONNECTED,
-    [0x04] = HFP_CONNECTION_STATE_DISCONNECTING
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sConnectionState), uint8_t,
-        BluetoothHandsfreeConnectionState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sConnectionState[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothHandsfreeNRECState& aOut)
-{
-  static const BluetoothHandsfreeNRECState sNRECState[] = {
-    [0x00] = HFP_NREC_STOPPED,
-    [0x01] = HFP_NREC_STARTED
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sNRECState), uint8_t,
-        BluetoothHandsfreeNRECState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sNRECState[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothHandsfreeVoiceRecognitionState& aOut)
-{
-  static const BluetoothHandsfreeVoiceRecognitionState sState[] = {
-    [0x00] = HFP_VOICE_RECOGNITION_STOPPED,
-    [0x01] = HFP_VOICE_RECOGNITION_STARTED
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sState), uint8_t,
-        BluetoothHandsfreeVoiceRecognitionState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sState[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothHandsfreeVolumeType& aOut)
-{
-  static const BluetoothHandsfreeVolumeType sVolumeType[] = {
-    [0x00] = HFP_VOLUME_TYPE_SPEAKER,
-    [0x01] = HFP_VOLUME_TYPE_MICROPHONE
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sVolumeType), uint8_t,
-        BluetoothHandsfreeVolumeType)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sVolumeType[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothHandsfreeWbsConfig& aOut)
-{
-  static const BluetoothHandsfreeWbsConfig sWbsConfig[] = {
-    [0x00] = HFP_WBS_NONE,
-    [0x01] = HFP_WBS_NO,
-    [0x02] = HFP_WBS_YES
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sWbsConfig), uint8_t,
-        BluetoothHandsfreeWbsConfig)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sWbsConfig[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothTypeOfDevice& aOut)
-{
-  return Convert((int32_t)aIn, aOut);
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothPropertyType& aOut)
-{
-  static const BluetoothPropertyType sPropertyType[] = {
-    [0x00] = static_cast<BluetoothPropertyType>(0), // invalid, required by gcc
-    [0x01] = PROPERTY_BDNAME,
-    [0x02] = PROPERTY_BDADDR,
-    [0x03] = PROPERTY_UUIDS,
-    [0x04] = PROPERTY_CLASS_OF_DEVICE,
-    [0x05] = PROPERTY_TYPE_OF_DEVICE,
-    [0x06] = PROPERTY_SERVICE_RECORD,
-    [0x07] = PROPERTY_ADAPTER_SCAN_MODE,
-    [0x08] = PROPERTY_ADAPTER_BONDED_DEVICES,
-    [0x09] = PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
-    [0x0a] = PROPERTY_REMOTE_FRIENDLY_NAME,
-    [0x0b] = PROPERTY_REMOTE_RSSI,
-    [0x0c] = PROPERTY_REMOTE_VERSION_INFO
-  };
-  if (aIn == 0xff) {
-    /* This case is handled separately to not populate
-     * |sPropertyType| with empty entries. */
-    aOut = PROPERTY_REMOTE_DEVICE_TIMESTAMP;
-    return NS_OK;
-  }
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        !aIn, uint8_t, BluetoothPropertyType) ||
-      MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sPropertyType), uint8_t,
-        BluetoothPropertyType)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sPropertyType[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothSocketType aIn, uint8_t& aOut)
-{
-  static const uint8_t sSocketType[] = {
-    [0] = 0, // silences compiler warning
-    [BluetoothSocketType::RFCOMM] = 0x01,
-    [BluetoothSocketType::SCO] = 0x02,
-    [BluetoothSocketType::L2CAP] = 0x03
-    // EL2CAP not supported
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn == BluetoothSocketType::EL2CAP, BluetoothSocketType, uint8_t) ||
-      MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sSocketType), BluetoothSocketType, uint8_t) ||
-      MOZ_HAL_IPC_CONVERT_WARN_IF(
-        !sSocketType[aIn], BluetoothSocketType, uint8_t)) {
-    aOut = 0; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sSocketType[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothSspVariant& aOut)
-{
-  static const BluetoothSspVariant sSspVariant[] = {
-    [0x00] = SSP_VARIANT_PASSKEY_CONFIRMATION,
-    [0x01] = SSP_VARIANT_PASSKEY_ENTRY,
-    [0x02] = SSP_VARIANT_CONSENT,
-    [0x03] = SSP_VARIANT_PASSKEY_NOTIFICATION
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sSspVariant), uint8_t, BluetoothSspVariant)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sSspVariant[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothStatus& aOut)
-{
-  static const BluetoothStatus sStatus[] = {
-    [0x00] = STATUS_SUCCESS,
-    [0x01] = STATUS_FAIL,
-    [0x02] = STATUS_NOT_READY,
-    [0x03] = STATUS_NOMEM,
-    [0x04] = STATUS_BUSY,
-    [0x05] = STATUS_DONE,
-    [0x06] = STATUS_UNSUPPORTED,
-    [0x07] = STATUS_PARM_INVALID,
-    [0x08] = STATUS_UNHANDLED,
-    [0x09] = STATUS_AUTH_FAILURE,
-    [0x0a] = STATUS_RMT_DEV_DOWN,
-    [0x0b] = STATUS_AUTH_REJECTED
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sStatus), uint8_t, BluetoothStatus)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sStatus[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(int32_t aIn, BluetoothAttributeHandle& aOut)
-{
-  if (NS_WARN_IF(aIn < 0x0000) || NS_WARN_IF(aIn > 0xFFFF)) {
-    aOut.mHandle = 0x0000; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut.mHandle = static_cast<uint16_t>(aIn);
-  return NS_OK;
-}
-
-nsresult
-Convert(int32_t aIn, BluetoothGattStatus& aOut)
-{
-  /* Reference: $B2G/external/bluetooth/bluedroid/stack/include/gatt_api.h */
-  static const BluetoothGattStatus sGattStatus[] = {
-    [0x0000] = GATT_STATUS_SUCCESS,
-    [0x0001] = GATT_STATUS_INVALID_HANDLE,
-    [0x0002] = GATT_STATUS_READ_NOT_PERMITTED,
-    [0x0003] = GATT_STATUS_WRITE_NOT_PERMITTED,
-    [0x0004] = GATT_STATUS_INVALID_PDU,
-    [0x0005] = GATT_STATUS_INSUFFICIENT_AUTHENTICATION,
-    [0x0006] = GATT_STATUS_REQUEST_NOT_SUPPORTED,
-    [0x0007] = GATT_STATUS_INVALID_OFFSET,
-    [0x0008] = GATT_STATUS_INSUFFICIENT_AUTHORIZATION,
-    [0x0009] = GATT_STATUS_PREPARE_QUEUE_FULL,
-    [0x000a] = GATT_STATUS_ATTRIBUTE_NOT_FOUND,
-    [0x000b] = GATT_STATUS_ATTRIBUTE_NOT_LONG,
-    [0x000c] = GATT_STATUS_INSUFFICIENT_ENCRYPTION_KEY_SIZE,
-    [0x000d] = GATT_STATUS_INVALID_ATTRIBUTE_LENGTH,
-    [0x000e] = GATT_STATUS_UNLIKELY_ERROR,
-    [0x000f] = GATT_STATUS_INSUFFICIENT_ENCRYPTION,
-    [0x0010] = GATT_STATUS_UNSUPPORTED_GROUP_TYPE,
-    [0x0011] = GATT_STATUS_INSUFFICIENT_RESOURCES
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn < 0, int32_t, BluetoothGattStatus) ||
-      MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= static_cast<ssize_t>(MOZ_ARRAY_LENGTH(sGattStatus)), int32_t,
-        BluetoothGattStatus)) {
-    aOut = GATT_STATUS_UNKNOWN_ERROR;
-  } else {
-    aOut = sGattStatus[aIn];
-  }
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothHidProtocolMode& aOut)
-{
-  static const BluetoothHidProtocolMode sMode[] = {
-    [0x00] = HID_PROTOCOL_MODE_REPORT,
-    [0x01] = HID_PROTOCOL_MODE_BOOT
-  };
-  if (aIn == 0xff) {
-    /* This case is handled separately to not populate
-     * |sMode| with empty entries. */
-    aOut = HID_PROTOCOL_MODE_UNSUPPORTED;
-    return NS_OK;
-  }
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sMode), uint8_t, BluetoothHidProtocolMode)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sMode[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothHidConnectionState& aOut)
-{
-  static const BluetoothHidConnectionState sConnectionState[] = {
-    [0x00] = HID_CONNECTION_STATE_CONNECTED,
-    [0x01] = HID_CONNECTION_STATE_CONNECTING,
-    [0x02] = HID_CONNECTION_STATE_DISCONNECTED,
-    [0x03] = HID_CONNECTION_STATE_DISCONNECTING,
-    [0x04] = HID_CONNECTION_STATE_FAILED_MOUSE_FROM_HOST,
-    [0x05] = HID_CONNECTION_STATE_FAILED_KEYBOARD_FROM_HOST,
-    [0x06] = HID_CONNECTION_STATE_FAILED_TOO_MANY_DEVICES,
-    [0x07] = HID_CONNECTION_STATE_FAILED_NO_HID_DRIVER,
-    [0x08] = HID_CONNECTION_STATE_FAILED_GENERIC,
-    [0x09] = HID_CONNECTION_STATE_UNKNOWN
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sConnectionState),
-        uint8_t, BluetoothHidConnectionState)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sConnectionState[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(uint8_t aIn, BluetoothHidStatus& aOut)
-{
-  static const BluetoothHidStatus sStatus[] = {
-    [0x00] = HID_STATUS_OK,
-    [0x01] = HID_STATUS_HANDSHAKE_DEVICE_NOT_READY,
-    [0x02] = HID_STATUS_HANDSHAKE_INVALID_REPORT_ID,
-    [0x03] = HID_STATUS_HANDSHAKE_TRANSACTION_NOT_SPT,
-    [0x04] = HID_STATUS_HANDSHAKE_INVALID_PARAMETER,
-    [0x05] = HID_STATUS_HANDSHAKE_GENERIC_ERROR,
-    [0x06] = HID_STATUS_GENERAL_ERROR,
-    [0x07] = HID_STATUS_SDP_ERROR,
-    [0x08] = HID_STATUS_SET_PROTOCOL_ERROR,
-    [0x09] = HID_STATUS_DEVICE_DATABASE_FULL,
-    [0x0a] = HID_STATUS_DEVICE_TYPE_NOT_SUPPORTED,
-    [0x0b] = HID_STATUS_NO_RESOURCES,
-    [0x0c] = HID_STATUS_AUTHENTICATION_FAILED,
-    [0x0d] = HID_STATUS_HDL
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sStatus), uint8_t, BluetoothHidStatus)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sStatus[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(nsresult aIn, BluetoothStatus& aOut)
-{
-  if (NS_SUCCEEDED(aIn)) {
-    aOut = STATUS_SUCCESS;
-  } else if (aIn == NS_ERROR_OUT_OF_MEMORY) {
-    aOut = STATUS_NOMEM;
-  } else {
-    aOut = STATUS_FAIL;
-  }
-  return NS_OK;
-}
-
-nsresult
-Convert(const BluetoothAttributeHandle& aIn, int32_t& aOut)
-{
-  aOut = static_cast<int32_t>(aIn.mHandle);
-  return NS_OK;
-}
-
-nsresult
-Convert(const BluetoothAttributeHandle& aIn, uint16_t& aOut)
-{
-  aOut = aIn.mHandle;
-  return NS_OK;
-}
-
-
-nsresult
-Convert(BluetoothAvrcpEvent aIn, uint8_t& aOut)
-{
-  static const uint8_t sValue[] = {
-    [AVRCP_EVENT_PLAY_STATUS_CHANGED] = 0x01,
-    [AVRCP_EVENT_TRACK_CHANGE] = 0x02,
-    [AVRCP_EVENT_TRACK_REACHED_END] = 0x03,
-    [AVRCP_EVENT_TRACK_REACHED_START] = 0x04,
-    [AVRCP_EVENT_PLAY_POS_CHANGED] = 0x05,
-    [AVRCP_EVENT_APP_SETTINGS_CHANGED] = 0x08
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sValue), BluetoothAvrcpEvent, uint8_t)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sValue[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothAvrcpNotification aIn, uint8_t& aOut)
-{
-  static const bool sValue[] = {
-    [AVRCP_NTF_INTERIM] = 0x00,
-    [AVRCP_NTF_CHANGED] = 0x01
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sValue), BluetoothAvrcpNotification,
-        uint8_t)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sValue[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothAvrcpPlayerAttribute aIn, uint8_t& aOut)
-{
-  static const uint8_t sValue[] = {
-    [AVRCP_PLAYER_ATTRIBUTE_EQUALIZER] = 0x01,
-    [AVRCP_PLAYER_ATTRIBUTE_REPEAT] = 0x02,
-    [AVRCP_PLAYER_ATTRIBUTE_SHUFFLE] = 0x03,
-    [AVRCP_PLAYER_ATTRIBUTE_SCAN] = 0x04
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sValue), BluetoothAvrcpPlayerAttribute, uint8_t)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sValue[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothAvrcpRemoteFeatureBits aIn, unsigned long& aOut)
-{
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn < std::numeric_limits<unsigned long>::min(),
-        BluetoothAvrcpRemoteFeature, unsigned long) ||
-      MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn > std::numeric_limits<unsigned long>::max(),
-        BluetoothAvrcpRemoteFeature, unsigned long)) {
-    aOut = 0; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = static_cast<unsigned long>(aIn);
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothAvrcpStatus aIn, uint8_t& aOut)
-{
-  static const uint8_t sValue[] = {
-    [AVRCP_STATUS_BAD_COMMAND] = 0x00,
-    [AVRCP_STATUS_BAD_PARAMETER] = 0x01,
-    [AVRCP_STATUS_NOT_FOUND] = 0x02,
-    [AVRCP_STATUS_INTERNAL_ERROR] = 0x03,
-    [AVRCP_STATUS_SUCCESS] = 0x04
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sValue), BluetoothAvrcpStatus, uint8_t)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sValue[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothHandsfreeAtResponse aIn, uint8_t& aOut)
-{
-  static const uint8_t sAtResponse[] = {
-    [HFP_AT_RESPONSE_ERROR] = 0x00,
-    [HFP_AT_RESPONSE_OK] = 0x01
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sAtResponse), BluetoothHandsfreeAtResponse,
-        uint8_t)) {
-    aOut = 0x00; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sAtResponse[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothHandsfreeCallAddressType aIn, uint8_t& aOut)
-{
-  static const uint8_t sCallAddressType[] = {
-    [HFP_CALL_ADDRESS_TYPE_UNKNOWN] = 0x81,
-    [HFP_CALL_ADDRESS_TYPE_INTERNATIONAL] = 0x91
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sCallAddressType),
-        BluetoothHandsfreeCallAddressType, uint8_t)) {
-    aOut = 0x00; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sCallAddressType[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothHandsfreeCallDirection aIn, uint8_t& aOut)
-{
-  static const uint8_t sCallDirection[] = {
-    [HFP_CALL_DIRECTION_OUTGOING] = 0x00,
-    [HFP_CALL_DIRECTION_INCOMING] = 0x01
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sCallDirection),
-        BluetoothHandsfreeCallDirection, uint8_t)) {
-    aOut = 0x00; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sCallDirection[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothHandsfreeCallState aIn, uint8_t& aOut)
-{
-  static const uint8_t sCallState[] = {
-    [HFP_CALL_STATE_ACTIVE] = 0x00,
-    [HFP_CALL_STATE_HELD] = 0x01,
-    [HFP_CALL_STATE_DIALING] = 0x02,
-    [HFP_CALL_STATE_ALERTING] = 0x03,
-    [HFP_CALL_STATE_INCOMING] = 0x04,
-    [HFP_CALL_STATE_WAITING] = 0x05,
-    [HFP_CALL_STATE_IDLE] = 0x06
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sCallState), BluetoothHandsfreeCallState,
-        uint8_t)) {
-    aOut = 0x00; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sCallState[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothHandsfreeCallMode aIn, uint8_t& aOut)
-{
-  static const uint8_t sCallMode[] = {
-    [HFP_CALL_MODE_VOICE] = 0x00,
-    [HFP_CALL_MODE_DATA] = 0x01,
-    [HFP_CALL_MODE_FAX] = 0x02
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sCallMode), BluetoothHandsfreeCallMode, uint8_t)) {
-    aOut = 0x00; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sCallMode[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothHandsfreeCallMptyType aIn, uint8_t& aOut)
-{
-  static const uint8_t sCallMptyType[] = {
-    [HFP_CALL_MPTY_TYPE_SINGLE] = 0x00,
-    [HFP_CALL_MPTY_TYPE_MULTI] = 0x01
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sCallMptyType),
-        BluetoothHandsfreeCallMptyType, uint8_t)) {
-    aOut = 0x00; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sCallMptyType[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothHandsfreeNetworkState aIn, uint8_t& aOut)
-{
-  static const uint8_t sNetworkState[] = {
-    [HFP_NETWORK_STATE_NOT_AVAILABLE] = 0x00,
-    [HFP_NETWORK_STATE_AVAILABLE] = 0x01
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sNetworkState), BluetoothHandsfreeNetworkState,
-        uint8_t)) {
-    aOut = 0x00; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sNetworkState[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothHandsfreeServiceType aIn, uint8_t& aOut)
-{
-  static const uint8_t sServiceType[] = {
-    [HFP_SERVICE_TYPE_HOME] = 0x00,
-    [HFP_SERVICE_TYPE_ROAMING] = 0x01
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sServiceType), BluetoothHandsfreeServiceType,
-        uint8_t)) {
-    aOut = 0x00; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sServiceType[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothHandsfreeVolumeType aIn, uint8_t& aOut)
-{
-  static const uint8_t sVolumeType[] = {
-    [HFP_VOLUME_TYPE_SPEAKER] = 0x00,
-    [HFP_VOLUME_TYPE_MICROPHONE] = 0x01
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sVolumeType), BluetoothHandsfreeVolumeType,
-        uint8_t)) {
-    aOut = 0x00; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sVolumeType[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothHandsfreeWbsConfig aIn, uint8_t& aOut)
-{
-  static const uint8_t sWbsConfig[] = {
-    [HFP_WBS_NONE] = 0x00,
-    [HFP_WBS_NO] = 0x01,
-    [HFP_WBS_YES] = 0x02
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sWbsConfig), BluetoothHandsfreeWbsConfig,
-        uint8_t)) {
-    aOut = 0x00; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sWbsConfig[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothPropertyType aIn, uint8_t& aOut)
-{
-  static const uint8_t sPropertyType[] = {
-    [PROPERTY_UNKNOWN] = 0x00,
-    [PROPERTY_BDNAME] = 0x01,
-    [PROPERTY_BDADDR] = 0x02,
-    [PROPERTY_UUIDS] = 0x03,
-    [PROPERTY_CLASS_OF_DEVICE] = 0x04,
-    [PROPERTY_TYPE_OF_DEVICE] = 0x05,
-    [PROPERTY_SERVICE_RECORD] = 0x06,
-    [PROPERTY_ADAPTER_SCAN_MODE] = 0x07,
-    [PROPERTY_ADAPTER_BONDED_DEVICES] = 0x08,
-    [PROPERTY_ADAPTER_DISCOVERY_TIMEOUT] = 0x09,
-    [PROPERTY_REMOTE_FRIENDLY_NAME] = 0x0a,
-    [PROPERTY_REMOTE_RSSI] = 0x0b,
-    [PROPERTY_REMOTE_VERSION_INFO] = 0x0c,
-    [PROPERTY_REMOTE_DEVICE_TIMESTAMP] = 0xff
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sPropertyType), BluetoothPropertyType,
-        uint8_t)) {
-    aOut = 0x00; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sPropertyType[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothScanMode aIn, int32_t& aOut)
-{
-  static const int32_t sScanMode[] = {
-    [SCAN_MODE_NONE] = 0x00,
-    [SCAN_MODE_CONNECTABLE] = 0x01,
-    [SCAN_MODE_CONNECTABLE_DISCOVERABLE] = 0x02
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sScanMode), BluetoothScanMode, int32_t)) {
-    aOut = 0; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sScanMode[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothSetupServiceId aIn, uint8_t& aOut)
-{
-  static const uint8_t sServiceId[] = {
-    [SETUP_SERVICE_ID_SETUP] = 0x00,
-    [SETUP_SERVICE_ID_CORE] = 0x01,
-    [SETUP_SERVICE_ID_SOCKET] = 0x02,
-    [SETUP_SERVICE_ID_HID] = 0x03,
-    [SETUP_SERVICE_ID_PAN] = 0x04,
-    [SETUP_SERVICE_ID_HANDSFREE] = 0x05,
-    [SETUP_SERVICE_ID_A2DP] = 0x06,
-    [SETUP_SERVICE_ID_HEALTH] = 0x07,
-    [SETUP_SERVICE_ID_AVRCP] = 0x08,
-    [SETUP_SERVICE_ID_GATT] = 0x09,
-    [SETUP_SERVICE_ID_HANDSFREE_CLIENT] = 0x0a,
-    [SETUP_SERVICE_ID_MAP_CLIENT] = 0x0b,
-    [SETUP_SERVICE_ID_AVRCP_CONTROLLER] = 0x0c,
-    [SETUP_SERVICE_ID_A2DP_SINK] = 0x0d
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sServiceId),
-        BluetoothServiceSetupId, uint8_t)) {
-    aOut = 0; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sServiceId[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothSspVariant aIn, uint8_t& aOut)
-{
-  static const uint8_t sValue[] = {
-    [SSP_VARIANT_PASSKEY_CONFIRMATION] = 0x00,
-    [SSP_VARIANT_PASSKEY_ENTRY] = 0x01,
-    [SSP_VARIANT_CONSENT] = 0x02,
-    [SSP_VARIANT_PASSKEY_NOTIFICATION] = 0x03
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sValue), BluetoothSspVariant, uint8_t)) {
-    aOut = 0; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sValue[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(ControlPlayStatus aIn, uint8_t& aOut)
-{
-  static const uint8_t sValue[] = {
-    [PLAYSTATUS_STOPPED] = 0x00,
-    [PLAYSTATUS_PLAYING] = 0x01,
-    [PLAYSTATUS_PAUSED] = 0x02,
-    [PLAYSTATUS_FWD_SEEK] = 0x03,
-    [PLAYSTATUS_REV_SEEK] = 0x04
-  };
-  if (aIn == PLAYSTATUS_ERROR) {
-    /* This case is handled separately to not populate
-     * |sValue| with empty entries. */
-    aOut = 0xff;
-    return NS_OK;
-  }
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sValue), ControlPlayStatus, uint8_t)) {
-    aOut = 0; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sValue[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothGattAuthReq aIn, int32_t& aOut)
-{
-  static const int32_t sGattAuthReq[] = {
-    [GATT_AUTH_REQ_NONE] = 0x00,
-    [GATT_AUTH_REQ_NO_MITM] = 0x01,
-    [GATT_AUTH_REQ_MITM] = 0x02,
-    [GATT_AUTH_REQ_SIGNED_NO_MITM] = 0x03,
-    [GATT_AUTH_REQ_SIGNED_MITM] = 0x04
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sGattAuthReq), BluetoothGattAuthReq,
-        int32_t)) {
-    aOut = GATT_AUTH_REQ_NONE; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sGattAuthReq[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothGattAuthReq aIn, uint8_t& aOut)
-{
-  static const uint8_t sGattAuthReq[] = {
-    [GATT_AUTH_REQ_NONE] = 0x00,
-    [GATT_AUTH_REQ_NO_MITM] = 0x01,
-    [GATT_AUTH_REQ_MITM] = 0x02,
-    [GATT_AUTH_REQ_SIGNED_NO_MITM] = 0x03,
-    [GATT_AUTH_REQ_SIGNED_MITM] = 0x04
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sGattAuthReq), BluetoothGattAuthReq,
-        uint8_t)) {
-    aOut = GATT_AUTH_REQ_NONE; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sGattAuthReq[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothGattWriteType aIn, int32_t& aOut)
-{
-  static const int32_t sGattWriteType[] = {
-    [GATT_WRITE_TYPE_NO_RESPONSE] = 0x01,
-    [GATT_WRITE_TYPE_NORMAL] = 0x02,
-    [GATT_WRITE_TYPE_PREPARE] = 0x03,
-    [GATT_WRITE_TYPE_SIGNED] = 0x04
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sGattWriteType), BluetoothGattWriteType,
-        int32_t)) {
-    aOut = GATT_WRITE_TYPE_NORMAL; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sGattWriteType[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothHidProtocolMode aIn, uint8_t& aOut)
-{
-  static const uint8_t sMode[] = {
-    [HID_PROTOCOL_MODE_REPORT] = 0x00,
-    [HID_PROTOCOL_MODE_BOOT] = 0x01
-  };
-  if (aIn == HID_PROTOCOL_MODE_UNSUPPORTED) {
-    /* This case is handled separately to not populate
-     * |sValue| with empty entries. */
-    aOut = 0xff;
-    return NS_OK;
-  }
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sMode), BluetoothHidProtocolMode, uint8_t)) {
-    aOut = 0x00; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sMode[aIn];
-  return NS_OK;
-}
-
-nsresult
-Convert(BluetoothHidReportType aIn, uint8_t& aOut)
-{
-  static const uint8_t sType[] = {
-    [0x00] = static_cast<BluetoothHidReportType>(0),
-    [HID_REPORT_TYPE_INPUT] = 0x01,
-    [HID_REPORT_TYPE_OUTPUT] = 0x02,
-    [HID_REPORT_TYPE_FEATURE] = 0x03
-  };
-  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
-        aIn >= MOZ_ARRAY_LENGTH(sType),
-        BluetoothHidReportType, uint8_t)) {
-    aOut = 0x00; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  aOut = sType[aIn];
-  return NS_OK;
-}
-
-/* |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;
-}
-
-//
-// Packing
-//
-
-nsresult
-PackPDU(const BluetoothAddress& aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(PackArray<uint8_t>(aIn.mAddr, sizeof(aIn.mAddr)), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothAttributeHandle& aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(PackConversion<BluetoothAttributeHandle, int32_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothAvrcpAttributeTextPairs& aIn,
-        DaemonSocketPDU& aPDU)
-{
-  size_t i;
-
-  for (i = 0; i < aIn.mLength; ++i) {
-    nsresult rv = PackPDU(aIn.mAttr[i], aPDU);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    uint8_t len;
-    const uint8_t* str;
-
-    if (aIn.mText[i]) {
-      str = reinterpret_cast<const uint8_t*>(aIn.mText[i]);
-      len = strlen(aIn.mText[i]) + 1;
-    } else {
-      /* write \0 character for NULL strings */
-      str = reinterpret_cast<const uint8_t*>("\0");
-      len = 1;
-    }
-
-    rv = PackPDU(len, aPDU);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = PackPDU(PackArray<uint8_t>(str, len), aPDU);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-  }
-  return NS_OK;
-}
-
-nsresult
-PackPDU(const BluetoothAvrcpAttributeValuePairs& aIn,
-        DaemonSocketPDU& aPDU)
-{
-  size_t i;
-
-  for (i = 0; i < aIn.mLength; ++i) {
-    nsresult rv = PackPDU(aIn.mAttr[i], aPDU);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = PackPDU(aIn.mValue[i], aPDU);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-  }
-  return NS_OK;
-}
-
-nsresult
-PackPDU(const BluetoothAvrcpElementAttribute& aIn, DaemonSocketPDU& aPDU)
-{
-  nsresult rv = PackPDU(PackConversion<uint32_t, uint8_t>(aIn.mId), aPDU);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  const NS_ConvertUTF16toUTF8 cstr(aIn.mValue);
-
-  if (MOZ_HAL_IPC_PACK_WARN_IF(
-        cstr.Length() == PR_UINT32_MAX, BluetoothAvrcpElementAttribute)) {
-    return NS_ERROR_ILLEGAL_VALUE; /* integer overflow detected */
-  }
-
-  uint32_t clen = cstr.Length() + 1; /* include \0 character */
-
-  rv = PackPDU(PackConversion<uint32_t, uint8_t>(clen), aPDU);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  return PackPDU(
-    PackArray<uint8_t>(reinterpret_cast<const uint8_t*>(cstr.get()), clen),
-    aPDU);
-}
-
-nsresult
-PackPDU(BluetoothAvrcpEvent aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(PackConversion<BluetoothAvrcpEvent, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothAvrcpEventParamPair& aIn, DaemonSocketPDU& aPDU)
-{
-  nsresult rv;
-
-  switch (aIn.mEvent) {
-    case AVRCP_EVENT_PLAY_STATUS_CHANGED:
-      rv = PackPDU(aIn.mParam.mPlayStatus, aPDU);
-      break;
-    case AVRCP_EVENT_TRACK_CHANGE:
-      rv = PackPDU(PackArray<uint8_t>(aIn.mParam.mTrack,
-                                      MOZ_ARRAY_LENGTH(aIn.mParam.mTrack)),
-                   aPDU);
-      break;
-    case AVRCP_EVENT_TRACK_REACHED_END:
-      /* fall through */
-    case AVRCP_EVENT_TRACK_REACHED_START:
-      /* no data to pack */
-      rv = NS_OK;
-      break;
-    case AVRCP_EVENT_PLAY_POS_CHANGED:
-      rv = PackPDU(aIn.mParam.mSongPos, aPDU);
-      break;
-    case AVRCP_EVENT_APP_SETTINGS_CHANGED:
-      /* pack number of attribute-value pairs */
-      rv = PackPDU(aIn.mParam.mNumAttr, aPDU);
-      if (NS_FAILED(rv)) {
-        return rv;
-      }
-      /* pack attribute-value pairs */
-      rv = PackPDU(BluetoothAvrcpAttributeValuePairs(aIn.mParam.mIds,
-                                                     aIn.mParam.mValues,
-                                                     aIn.mParam.mNumAttr),
-                   aPDU);
-      break;
-    default:
-      rv = NS_ERROR_ILLEGAL_VALUE;
-      break;
-  }
-  return rv;
-}
-
-nsresult
-PackPDU(BluetoothAvrcpNotification aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(
-    PackConversion<BluetoothAvrcpNotification, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(BluetoothAvrcpPlayerAttribute aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(
-    PackConversion<BluetoothAvrcpPlayerAttribute, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(BluetoothAvrcpStatus aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(PackConversion<BluetoothAvrcpStatus, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothConfigurationParameter& aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(aIn.mType, aIn.mLength,
-                 PackArray<uint8_t>(aIn.mValue.get(), aIn.mLength), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothHandsfreeAtResponse& aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(
-    PackConversion<BluetoothHandsfreeAtResponse, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothHandsfreeCallAddressType& aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(
-    PackConversion<BluetoothHandsfreeCallAddressType, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothHandsfreeCallDirection& aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(
-    PackConversion<BluetoothHandsfreeCallDirection, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothHandsfreeCallMode& aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(
-    PackConversion<BluetoothHandsfreeCallMode, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothHandsfreeCallMptyType& aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(
-    PackConversion<BluetoothHandsfreeCallMptyType, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothHandsfreeCallState& aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(
-    PackConversion<BluetoothHandsfreeCallState, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothHandsfreeNetworkState& aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(
-    PackConversion<BluetoothHandsfreeNetworkState, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothHandsfreeServiceType& aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(
-    PackConversion<BluetoothHandsfreeServiceType, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothHandsfreeVolumeType& aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(
-    PackConversion<BluetoothHandsfreeVolumeType, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothHandsfreeWbsConfig& aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(
-    PackConversion<BluetoothHandsfreeWbsConfig, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothProperty& aIn, DaemonSocketPDU& aPDU)
-{
-  nsresult rv = PackPDU(aIn.mType, aPDU);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  switch (aIn.mType) {
-    case PROPERTY_BDNAME:
-      rv = PackPDU(PackConversion<uint8_t, uint16_t>(aIn.mRemoteName.mLength),
-                   PackArray<uint8_t>(aIn.mRemoteName.mName,
-                                      aIn.mRemoteName.mLength),
-                   aPDU);
-      break;
-    case PROPERTY_REMOTE_FRIENDLY_NAME: {
-        NS_ConvertUTF16toUTF8 stringUTF8(aIn.mString);
-
-        rv = PackPDU(PackConversion<size_t, uint16_t>(stringUTF8.Length()),
-                     PackArray<uint8_t>(
-                       reinterpret_cast<const uint8_t*>(stringUTF8.get()),
-                       stringUTF8.Length()),
-                     aPDU);
-      }
-      break;
-    case PROPERTY_CLASS_OF_DEVICE:
-      /* fall through */
-    case PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
-      rv = PackPDU(PackConversion<size_t, uint16_t>(sizeof(aIn.mUint32)),
-                   aIn.mUint32,
-                   aPDU);
-      break;
-    case PROPERTY_ADAPTER_SCAN_MODE:
-      /* |mScanMode| is sent as signed int of 4 bytes */
-      rv = PackPDU(PackConversion<size_t, uint16_t>(sizeof(int32_t)),
-                   aIn.mScanMode,
-                   aPDU);
-      break;
-    default:
-      NS_NOTREACHED("Invalid property for packing");
-      return NS_ERROR_ILLEGAL_VALUE;
-  }
-  return rv;
-}
-
-nsresult
-PackPDU(const BluetoothPinCode& aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(aIn.mLength,
-                 PackArray<uint8_t>(aIn.mPinCode, sizeof(aIn.mPinCode)),
-                 aPDU);
-}
-
-nsresult
-PackPDU(BluetoothPropertyType aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(PackConversion<BluetoothPropertyType, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(BluetoothSspVariant aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(PackConversion<BluetoothSspVariant, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(BluetoothScanMode aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(PackConversion<BluetoothScanMode, int32_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(BluetoothSetupServiceId aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(PackConversion<BluetoothSetupServiceId, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothServiceName& aIn, DaemonSocketPDU& aPDU)
-{
-  static const uint8_t sTerminator = '\0';
-
-  nsresult rv =
-    PackPDU(PackArray<uint8_t>(aIn.mName, sizeof(aIn.mName)), aPDU);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* The PDU requries one additional byte for \0 termination */
-  return aPDU.Write(sTerminator);
-}
-
-nsresult
-PackPDU(BluetoothSocketType aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(PackConversion<BluetoothSocketType, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(ControlPlayStatus aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(PackConversion<ControlPlayStatus, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(BluetoothTransport aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(PackConversion<BluetoothTransport, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothUuid& aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(
-    PackArray<uint8_t>(aIn.mUuid, sizeof(aIn.mUuid)), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothGattId& aIn, DaemonSocketPDU& aPDU)
-{
-  nsresult rv = PackPDU(PackReversed<BluetoothUuid>(aIn.mUuid), aPDU);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  return PackPDU(aIn.mInstanceId, aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothGattServiceId& aIn, DaemonSocketPDU& aPDU)
-{
-  nsresult rv = PackPDU(aIn.mId, aPDU);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  return PackPDU(aIn.mIsPrimary, aPDU);
-}
-
-nsresult
-PackPDU(BluetoothGattAuthReq aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(PackConversion<BluetoothGattAuthReq, int32_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(BluetoothGattWriteType aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(PackConversion<BluetoothGattWriteType, int32_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothHidInfoParam& aIn, DaemonSocketPDU& aPDU)
-{
-  if (MOZ_HAL_IPC_PACK_WARN_IF(
-        aIn.mDescriptorLength > BLUETOOTH_HID_MAX_DESC_LEN,
-        BluetoothHidInfoParam)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-
-  nsresult rv =  PackPDU(aIn.mAttributeMask,
-                         aIn.mSubclass,
-                         aIn.mApplicationId,
-                         aIn.mVendorId,
-                         aIn.mProductId,
-                         aIn.mVersion,
-                         aIn.mCountryCode,
-                         aIn.mDescriptorLength,
-                         aPDU);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  return PackPDU(
-    PackArray<uint8_t>(aIn.mDescriptorValue, aIn.mDescriptorLength), aPDU);
-}
-
-nsresult
-PackPDU(const BluetoothHidReport& aIn, DaemonSocketPDU& aPDU)
-{
-  uint8_t* reportData =
-    const_cast<uint8_t*>(aIn.mReportData.Elements());
-
-  nsresult rv = PackPDU(
-    PackConversion<uint32_t, uint16_t>(aIn.mReportData.Length()), aPDU);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  return PackPDU(
-    PackArray<uint8_t>(reportData, aIn.mReportData.Length()),
-    aPDU);
-}
-
-nsresult
-PackPDU(BluetoothHidProtocolMode aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(
-    PackConversion<BluetoothHidProtocolMode, uint8_t>(aIn), aPDU);
-}
-
-nsresult
-PackPDU(BluetoothHidReportType aIn, DaemonSocketPDU& aPDU)
-{
-  return PackPDU(
-    PackConversion<BluetoothHidReportType, uint8_t>(aIn), aPDU);
-}
-
-//
-// Unpacking
-//
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothA2dpAudioState& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothA2dpAudioState>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothA2dpConnectionState& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothA2dpConnectionState>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothAclState& aOut)
-{
-  return UnpackPDU(aPDU, UnpackConversion<uint8_t, BluetoothAclState>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothAttributeHandle& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<int32_t, BluetoothAttributeHandle>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothAvrcpEvent& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothAvrcpEvent>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothAvrcpMediaAttribute& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothAvrcpMediaAttribute>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothAvrcpPlayerAttribute& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothAvrcpPlayerAttribute>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothAvrcpPlayerSettings& aOut)
-{
-  /* Read number of attribute-value pairs */
-  nsresult rv = UnpackPDU(aPDU, aOut.mNumAttr);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* Read attribute-value pairs */
-  for (uint8_t i = 0; i < aOut.mNumAttr; ++i) {
-    nsresult rv = UnpackPDU(aPDU, aOut.mIds[i]);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = UnpackPDU(aPDU, aOut.mValues[i]);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-  }
-  return NS_OK;
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothAvrcpRemoteFeatureBits& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothAvrcpRemoteFeatureBits>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothBondState& aOut)
-{
-  return UnpackPDU(aPDU, UnpackConversion<uint8_t, BluetoothBondState>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothTypeOfDevice& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<int32_t, BluetoothTypeOfDevice>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHandsfreeAudioState& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothHandsfreeAudioState>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHandsfreeCallHoldType& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothHandsfreeCallHoldType>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHandsfreeConnectionState& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothHandsfreeConnectionState>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHandsfreeNRECState& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothHandsfreeNRECState>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHandsfreeWbsConfig& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothHandsfreeWbsConfig>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU,
-          BluetoothHandsfreeVoiceRecognitionState& aOut)
-{
-  return UnpackPDU(
-    aPDU,
-    UnpackConversion<uint8_t, BluetoothHandsfreeVoiceRecognitionState>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHandsfreeVolumeType& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothHandsfreeVolumeType>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothProperty& aOut)
-{
-  nsresult rv = UnpackPDU(aPDU, aOut.mType);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  uint16_t len;
-  rv = UnpackPDU(aPDU, len);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  switch (aOut.mType) {
-    case PROPERTY_BDNAME: {
-        const uint8_t* data = aPDU.Consume(len);
-        if (MOZ_HAL_IPC_UNPACK_WARN_IF(!data, BluetoothProperty)) {
-          return NS_ERROR_ILLEGAL_VALUE;
-        }
-        // We construct an nsCString here because the string
-        // returned from the PDU is not 0-terminated.
-        aOut.mRemoteName.Assign(data, len);
-      }
-      break;
-    case PROPERTY_REMOTE_FRIENDLY_NAME: {
-        const uint8_t* data = aPDU.Consume(len);
-        if (MOZ_HAL_IPC_UNPACK_WARN_IF(!data, BluetoothProperty)) {
-          return NS_ERROR_ILLEGAL_VALUE;
-        }
-        // We construct an nsCString here because the string
-        // returned from the PDU is not 0-terminated.
-        aOut.mString = NS_ConvertUTF8toUTF16(
-          nsCString(reinterpret_cast<const char*>(data), len));
-      }
-      break;
-    case PROPERTY_BDADDR:
-      rv = UnpackPDU(aPDU, aOut.mBdAddress);
-      break;
-    case PROPERTY_UUIDS: {
-        size_t numUuids = len / MAX_UUID_SIZE;
-        aOut.mUuidArray.SetLength(numUuids);
-        rv = UnpackPDU(aPDU, aOut.mUuidArray);
-      }
-      break;
-    case PROPERTY_CLASS_OF_DEVICE:
-      /* fall through */
-    case PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
-      rv = UnpackPDU(aPDU, aOut.mUint32);
-      break;
-    case PROPERTY_TYPE_OF_DEVICE:
-      rv = UnpackPDU(aPDU, aOut.mTypeOfDevice);
-      break;
-    case PROPERTY_SERVICE_RECORD:
-      rv = UnpackPDU(aPDU, aOut.mServiceRecord);
-      break;
-    case PROPERTY_ADAPTER_SCAN_MODE:
-      rv = UnpackPDU(aPDU, aOut.mScanMode);
-      break;
-    case PROPERTY_ADAPTER_BONDED_DEVICES: {
-        /* unpack addresses */
-        size_t numAddresses = len / BLUETOOTH_ADDRESS_BYTES;
-        aOut.mBdAddressArray.SetLength(numAddresses);
-        rv = UnpackPDU(aPDU, aOut.mBdAddressArray);
-      }
-      break;
-    case PROPERTY_REMOTE_RSSI: {
-        int8_t rssi;
-        rv = UnpackPDU(aPDU, rssi);
-        aOut.mInt32 = rssi;
-      }
-      break;
-    case PROPERTY_REMOTE_VERSION_INFO:
-      rv = UnpackPDU(aPDU, aOut.mRemoteInfo);
-      break;
-    case PROPERTY_REMOTE_DEVICE_TIMESTAMP:
-      /* nothing to do */
-      break;
-    default:
-      break;
-  }
-  return rv;
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothPropertyType& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothPropertyType>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothRemoteInfo& aOut)
-{
-  nsresult rv = UnpackPDU(aPDU,
-                          UnpackConversion<uint32_t, int>(aOut.mVerMajor));
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = UnpackPDU(aPDU, UnpackConversion<uint32_t, int>(aOut.mVerMinor));
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  return UnpackPDU(aPDU, UnpackConversion<uint32_t, int>(aOut.mManufacturer));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothScanMode& aOut)
-{
-  return UnpackPDU(aPDU, UnpackConversion<int32_t, BluetoothScanMode>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothServiceRecord& aOut)
-{
-  /* unpack UUID */
-  nsresult rv = UnpackPDU(aPDU, aOut.mUuid);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack channel */
-  rv = UnpackPDU(aPDU, aOut.mChannel);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack name */
-  return aPDU.Read(aOut.mName, sizeof(aOut.mName));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothSspVariant& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothSspVariant>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothStatus& aOut)
-{
-  return UnpackPDU(aPDU, UnpackConversion<uint8_t, BluetoothStatus>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothGattStatus& aOut)
-{
-  return UnpackPDU(aPDU, UnpackConversion<int32_t, BluetoothGattStatus>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothGattId& aOut)
-{
-  /* unpack UUID */
-  nsresult rv = UnpackPDU(aPDU, UnpackReversed<BluetoothUuid>(aOut.mUuid));
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack instance id */
-  return UnpackPDU(aPDU, aOut.mInstanceId);
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothGattServiceId& aOut)
-{
-  /* unpack id */
-  nsresult rv = UnpackPDU(aPDU, aOut.mId);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack isPrimary */
-  return UnpackPDU(aPDU, aOut.mIsPrimary);
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothGattReadParam& aOut)
-{
-  /* unpack service id */
-  nsresult rv = UnpackPDU(aPDU, aOut.mServiceId);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack characteristic id */
-  rv = UnpackPDU(aPDU, aOut.mCharId);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack descriptor id */
-  rv = UnpackPDU(aPDU, aOut.mDescriptorId);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack status */
-  rv = UnpackPDU(aPDU, aOut.mStatus);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack value type */
-  rv = UnpackPDU(aPDU, aOut.mValueType);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack length */
-  rv = UnpackPDU(aPDU, aOut.mValueLength);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack value */
-  return aPDU.Read(aOut.mValue, aOut.mValueLength);
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothGattWriteParam& aOut)
-{
-  /* unpack service id */
-  nsresult rv = UnpackPDU(aPDU, aOut.mServiceId);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack characteristic id */
-  rv = UnpackPDU(aPDU, aOut.mCharId);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack descriptor id */
-  rv = UnpackPDU(aPDU, aOut.mDescriptorId);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack status */
-  return UnpackPDU(aPDU, aOut.mStatus);
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothGattNotifyParam& aOut)
-{
-  /* unpack address */
-  nsresult rv = UnpackPDU(aPDU, aOut.mBdAddr);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack service id */
-  rv = UnpackPDU(aPDU, aOut.mServiceId);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack characteristic id */
-  rv = UnpackPDU(aPDU, aOut.mCharId);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack isNotify */
-  rv = UnpackPDU(aPDU, aOut.mIsNotify);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack length */
-  rv = UnpackPDU(aPDU, aOut.mLength);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack value */
-  return aPDU.Read(aOut.mValue, aOut.mLength);
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHidInfoParam& aOut)
-{
-  /* unpack attribute mask */
-  nsresult rv = UnpackPDU(aPDU, aOut.mAttributeMask);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack subclass */
-  rv = UnpackPDU(aPDU, aOut.mSubclass);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack application id */
-  rv = UnpackPDU(aPDU, aOut.mApplicationId);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack vendor id */
-  rv = UnpackPDU(aPDU, aOut.mVendorId);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack product id */
-  rv = UnpackPDU(aPDU, aOut.mProductId);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack version */
-  rv = UnpackPDU(aPDU, aOut.mVersion);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack country code */
-  rv = UnpackPDU(aPDU, aOut.mCountryCode);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* unpack descriptor length */
-  rv = UnpackPDU(aPDU, aOut.mDescriptorLength);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  if (MOZ_HAL_IPC_PACK_WARN_IF(
-        aOut.mDescriptorLength > BLUETOOTH_HID_MAX_DESC_LEN,
-        BluetoothHidInfoParam)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  /* unpack descriptor value */
-  return UnpackPDU(
-    aPDU,
-    UnpackArray<uint8_t>(aOut.mDescriptorValue, aOut.mDescriptorLength));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHidReport& aOut)
-{
-  return UnpackPDU(aPDU, aOut.mReportData);
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHidProtocolMode& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothHidProtocolMode>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHidConnectionState& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothHidConnectionState>(aOut));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHidStatus& aOut)
-{
-  return UnpackPDU(
-    aPDU, UnpackConversion<uint8_t, BluetoothHidStatus>(aOut));
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
+++ /dev/null
@@ -1,572 +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_BluetoothDaemonHelpers_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothDaemonHelpers_h
-
-#include "BluetoothCommon.h"
-#include "mozilla/ArrayUtils.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/ipc/DaemonSocketPDU.h"
-#include "mozilla/ipc/DaemonSocketPDUHelpers.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using mozilla::ipc::DaemonSocketPDU;
-using mozilla::ipc::DaemonSocketPDUHeader;
-using mozilla::ipc::DaemonSocketPDUHelpers::Convert;
-using mozilla::ipc::DaemonSocketPDUHelpers::PackPDU;
-using mozilla::ipc::DaemonSocketPDUHelpers::UnpackPDU;
-
-using namespace mozilla::ipc::DaemonSocketPDUHelpers;
-
-//
-// Helper structures
-//
-
-struct BluetoothAvrcpAttributeTextPairs {
-  BluetoothAvrcpAttributeTextPairs(const uint8_t* aAttr,
-                                   const char** aText,
-                                   size_t aLength)
-    : mAttr(aAttr)
-    , mText(aText)
-    , mLength(aLength)
-  { }
-
-  const uint8_t* mAttr;
-  const char** mText;
-  size_t mLength;
-};
-
-struct BluetoothAvrcpAttributeValuePairs {
-  BluetoothAvrcpAttributeValuePairs(const uint8_t* aAttr,
-                                    const uint8_t* aValue,
-                                    size_t aLength)
-    : mAttr(aAttr)
-    , mValue(aValue)
-    , mLength(aLength)
-  { }
-
-  const uint8_t* mAttr;
-  const uint8_t* mValue;
-  size_t mLength;
-};
-
-struct BluetoothAvrcpEventParamPair {
-  BluetoothAvrcpEventParamPair(BluetoothAvrcpEvent aEvent,
-                               const BluetoothAvrcpNotificationParam& aParam)
-    : mEvent(aEvent)
-    , mParam(aParam)
-  { }
-
-  size_t GetLength()
-  {
-    size_t size;
-
-    switch(mEvent) {
-      case AVRCP_EVENT_PLAY_STATUS_CHANGED:
-        /* PackPDU casts ControlPlayStatus to uint8_t */
-        size = sizeof(static_cast<uint8_t>(mParam.mPlayStatus));
-        break;
-      case AVRCP_EVENT_TRACK_CHANGE:
-        size = sizeof(mParam.mTrack);
-        break;
-      case AVRCP_EVENT_TRACK_REACHED_END:
-      case AVRCP_EVENT_TRACK_REACHED_START:
-        /* no data to pack */
-        size = 0;
-        break;
-      case AVRCP_EVENT_PLAY_POS_CHANGED:
-        size = sizeof(mParam.mSongPos);
-        break;
-      case AVRCP_EVENT_APP_SETTINGS_CHANGED:
-        size = (sizeof(mParam.mIds[0]) + sizeof(mParam.mValues[0])) * mParam.mNumAttr;
-        break;
-      default:
-        size = 0;
-        break;
-    }
-
-    return size;
-  }
-
-  BluetoothAvrcpEvent mEvent;
-  const BluetoothAvrcpNotificationParam& mParam;
-};
-
-//
-// Conversion
-//
-
-nsresult
-Convert(bool aIn, BluetoothScanMode& aOut);
-
-nsresult
-Convert(int32_t aIn, BluetoothTypeOfDevice& aOut);
-
-nsresult
-Convert(int32_t aIn, BluetoothScanMode& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothA2dpAudioState& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothA2dpConnectionState& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothAclState& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothAvrcpEvent& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothAvrcpMediaAttribute& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothAvrcpPlayerAttribute& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothAvrcpRemoteFeatureBits& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothHandsfreeAudioState& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothHandsfreeCallHoldType& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothHandsfreeConnectionState& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothHandsfreeNRECState& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothHandsfreeVoiceRecognitionState& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothHandsfreeVolumeType& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothHandsfreeWbsConfig& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothBondState& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothTypeOfDevice& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothPropertyType& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothScanMode& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothSspVariant& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothStatus& aOut);
-
-nsresult
-Convert(int32_t aIn, BluetoothAttributeHandle& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothHidProtocolMode& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothHidConnectionState& aOut);
-
-nsresult
-Convert(uint8_t aIn, BluetoothHidStatus& aOut);
-
-nsresult
-Convert(int32_t aIn, BluetoothGattStatus& aOut);
-
-nsresult
-Convert(const BluetoothAttributeHandle& aIn, int32_t& aOut);
-
-nsresult
-Convert(const BluetoothAttributeHandle& aIn, uint16_t& aOut);
-
-nsresult
-Convert(BluetoothAvrcpEvent aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothAvrcpNotification aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothAvrcpPlayerAttribute aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothAvrcpRemoteFeatureBits aIn, unsigned long& aOut);
-
-nsresult
-Convert(BluetoothAvrcpStatus aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothHandsfreeAtResponse aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothHandsfreeCallAddressType aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothHandsfreeCallDirection aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothHandsfreeCallState aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothHandsfreeCallMode aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothHandsfreeCallMptyType aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothHandsfreeNetworkState aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothHandsfreeServiceType aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothHandsfreeVolumeType aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothHandsfreeWbsConfig aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothPropertyType aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothScanMode aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothSetupServiceId aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothSocketType aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothSspVariant aIn, uint8_t& aOut);
-
-nsresult
-Convert(ControlPlayStatus aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothGattAuthReq aIn, int32_t& aOut);
-
-nsresult
-Convert(BluetoothGattAuthReq aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothGattWriteType aIn, int32_t& aOut);
-
-nsresult
-Convert(nsresult aIn, BluetoothStatus& aOut);
-
-nsresult
-Convert(BluetoothHidProtocolMode aIn, uint8_t& aOut);
-
-nsresult
-Convert(BluetoothHidReportType aIn, uint8_t& aOut);
-
-//
-// Packing
-//
-
-nsresult
-PackPDU(const BluetoothAddress& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothAttributeHandle& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothAvrcpAttributeTextPairs& aIn,
-        DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothAvrcpAttributeValuePairs& aIn,
-        DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothAvrcpElementAttribute& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(BluetoothAvrcpEvent aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothAvrcpEventParamPair& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(BluetoothAvrcpNotification aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(BluetoothAvrcpPlayerAttribute aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(BluetoothAvrcpStatus aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothConfigurationParameter& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothHandsfreeAtResponse& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothHandsfreeCallAddressType& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothHandsfreeCallDirection& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothHandsfreeCallMode& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothHandsfreeCallMptyType& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothHandsfreeCallState& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothHandsfreeNetworkState& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothHandsfreeServiceType& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothHandsfreeVolumeType& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothHandsfreeWbsConfig& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothProperty& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothPinCode& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(BluetoothPropertyType aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothServiceName& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(BluetoothSetupServiceId aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(BluetoothSocketType aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(BluetoothSspVariant aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(BluetoothScanMode aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(ControlPlayStatus aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothUuid& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothGattId& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothGattServiceId& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(BluetoothGattAuthReq aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(BluetoothGattWriteType aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(BluetoothTransport aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothHidInfoParam& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(const BluetoothHidReport& aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(BluetoothHidProtocolMode aIn, DaemonSocketPDU& aPDU);
-
-nsresult
-PackPDU(BluetoothHidReportType aIn, DaemonSocketPDU& aPDU);
-
-/* This implementation of |PackPDU| packs |BluetoothUuid| in reversed order.
- * (ex. reversed GATT UUID, see bug 1171866)
- */
-inline nsresult
-PackPDU(const PackReversed<BluetoothUuid>& aIn, DaemonSocketPDU& aPDU)
-{
- return PackPDU(
-   PackReversed<PackArray<uint8_t>>(
-     PackArray<uint8_t>(aIn.mValue.mUuid, sizeof(aIn.mValue.mUuid))),
-   aPDU);
-}
-
-//
-// Unpacking
-//
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothA2dpAudioState& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothA2dpConnectionState& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothAclState& aOut);
-
-inline nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothAddress& aOut)
-{
-  return aPDU.Read(aOut.mAddr, sizeof(aOut.mAddr));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothAttributeHandle& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothAvrcpEvent& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothAvrcpMediaAttribute& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothAvrcpPlayerAttribute& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothAvrcpPlayerSettings& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothAvrcpRemoteFeatureBits& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothBondState& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothTypeOfDevice& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHandsfreeAudioState& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHandsfreeCallHoldType& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHandsfreeConnectionState& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHandsfreeNRECState& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHandsfreeWbsConfig& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU,
-          BluetoothHandsfreeVoiceRecognitionState& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHandsfreeVolumeType& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothRemoteInfo& aOut);
-
-inline nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothRemoteName& aOut)
-{
-  nsresult rv = aPDU.Read(aOut.mName, sizeof(aOut.mName));
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  /* The PDU stores one extra byte for the trailing \0 character. We
-   * consume the byte, but don't store the character.
-   */
-  if (!aPDU.Consume(1)) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  auto end = std::find(aOut.mName, aOut.mName + sizeof(aOut.mName), '\0');
-
-  aOut.mLength = end - aOut.mName;
-  return NS_OK;
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothProperty& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothPropertyType& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothScanMode& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothServiceRecord& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothSspVariant& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothStatus& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothGattStatus& aOut);
-
-inline nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothUuid& aOut)
-{
-  return aPDU.Read(aOut.mUuid, sizeof(aOut.mUuid));
-}
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothGattId& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothGattServiceId& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothGattReadParam& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothGattWriteParam& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothGattNotifyParam& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHidInfoParam& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHidReport& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHidProtocolMode& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHidConnectionState& aOut);
-
-nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, BluetoothHidStatus& aOut);
-
-/* This implementation of |UnpackPDU| unpacks |BluetoothUuid| in reversed
- * order. (ex. reversed GATT UUID, see bug 1171866)
- */
-inline nsresult
-UnpackPDU(DaemonSocketPDU& aPDU, const UnpackReversed<BluetoothUuid>& aOut)
-{
-  return UnpackPDU(
-    aPDU,
-    UnpackReversed<UnpackArray<uint8_t>>(
-      UnpackArray<uint8_t>(aOut.mValue->mUuid, sizeof(aOut.mValue->mUuid))));
-}
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothDaemonHelpers_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHidInterface.cpp
+++ /dev/null
@@ -1,690 +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 "BluetoothDaemonHidInterface.h"
-#include "mozilla/UniquePtr.h"
-#include "mozilla/Unused.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using namespace mozilla::ipc;
-
-//
-// Hid module
-//
-
-BluetoothHidNotificationHandler*
-  BluetoothDaemonHidModule::sNotificationHandler;
-
-void
-BluetoothDaemonHidModule::SetNotificationHandler(
-  BluetoothHidNotificationHandler* aNotificationHandler)
-{
-  sNotificationHandler = aNotificationHandler;
-}
-
-void
-BluetoothDaemonHidModule::HandleSvc(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonHidModule::* const HandleOp[])(
-    const DaemonSocketPDUHeader&, DaemonSocketPDU&,
-    DaemonSocketResultHandler*) = {
-    [0] = &BluetoothDaemonHidModule::HandleRsp,
-    [1] = &BluetoothDaemonHidModule::HandleNtf
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread());
-
-  // Negate twice to map bit to 0/1
-  unsigned long isNtf = !!(aHeader.mOpcode & 0x80);
-
-  (this->*(HandleOp[isNtf]))(aHeader, aPDU, aRes);
-}
-
-// Commands
-//
-
-nsresult
-BluetoothDaemonHidModule::ConnectCmd(
-  const BluetoothAddress& aRemoteAddr, BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CONNECT,
-                                6); // Address
-
-  nsresult rv = PackPDU(aRemoteAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHidModule::DisconnectCmd(
-  const BluetoothAddress& aRemoteAddr, BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_DISCONNECT,
-                                6); // Address
-
-  nsresult rv = PackPDU(aRemoteAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHidModule::VirtualUnplugCmd(
-  const BluetoothAddress& aRemoteAddr, BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_VIRTUAL_UNPLUG,
-                                6); // Address
-
-  nsresult rv = PackPDU(aRemoteAddr, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHidModule::SetInfoCmd(
-  const BluetoothAddress& aRemoteAddr,
-  const BluetoothHidInfoParam& aHidInfoParam,
-  BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SET_INFO,
-                                6 + // Address
-                                897); // Info
-
-  nsresult rv = PackPDU(aRemoteAddr, aHidInfoParam, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHidModule::GetProtocolCmd(
-  const BluetoothAddress& aRemoteAddr,
-  BluetoothHidProtocolMode aHidProtocolMode,
-  BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_PROTOCOL,
-                                6 + // Address
-                                1); // Protocol Mode
-
-  nsresult rv = PackPDU(aRemoteAddr, aHidProtocolMode, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHidModule::SetProtocolCmd(
-  const BluetoothAddress& aRemoteAddr,
-  BluetoothHidProtocolMode aHidProtocolMode,
-  BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SET_PROTOCOL,
-                                6 + // Remote Address
-                                1); // Protocol Mode
-
-  nsresult rv = PackPDU(aRemoteAddr, aHidProtocolMode, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHidModule::GetReportCmd(
-  const BluetoothAddress& aRemoteAddr, BluetoothHidReportType aType,
-  uint8_t aReportId, uint16_t aBuffSize, BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_REPORT,
-                                6 + // Address
-                                1 + // Report Type
-                                1 + // Report ID
-                                2); // Buffer Size
-
-  nsresult rv = PackPDU(aRemoteAddr, aType, aReportId, aBuffSize, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHidModule::SetReportCmd(
-  const BluetoothAddress& aRemoteAddr, BluetoothHidReportType aType,
-  const BluetoothHidReport& aReport, BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SET_REPORT,
-                                6 + // Address
-                                1 + // Type
-                                2 + // Length
-                                0); // Dynamically allocated
-
-  nsresult rv = PackPDU(aRemoteAddr, aType, aReport, *pdu);
-
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonHidModule::SendDataCmd(
-  const BluetoothAddress& aRemoteAddr, uint16_t aDataLen, const uint8_t* aData,
-  BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SEND_DATA,
-                                6 + // Address
-                                2 + // Length
-                                0); // Dynamically allocated
-
-  nsresult rv = PackPDU(aRemoteAddr, aDataLen,
-                        PackArray<uint8_t>(aData, aDataLen), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return NS_OK;
-}
-
-// Responses
-//
-
-void
-BluetoothDaemonHidModule::ErrorRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothHidResultHandler* aRes)
-{
-  ErrorRunnable::Dispatch(
-    aRes, &BluetoothHidResultHandler::OnError, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::ConnectRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothHidResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHidResultHandler::Connect, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::DisconnectRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothHidResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHidResultHandler::Disconnect, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::VirtualUnplugRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothHidResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHidResultHandler::VirtualUnplug, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::SetInfoRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothHidResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHidResultHandler::SetInfo, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::GetProtocolRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothHidResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHidResultHandler::GetProtocol, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::SetProtocolRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothHidResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHidResultHandler::SetProtocol, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::GetReportRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothHidResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHidResultHandler::GetReport, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::SetReportRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothHidResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHidResultHandler::SetReport, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::SendDataRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, BluetoothHidResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothHidResultHandler::SendData, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::HandleRsp(
-  const DaemonSocketPDUHeader& aHeader,
-  DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonHidModule::* const HandleRsp[])(
-    const DaemonSocketPDUHeader&,
-    DaemonSocketPDU&,
-    BluetoothHidResultHandler*) = {
-    [OPCODE_ERROR] = &BluetoothDaemonHidModule::ErrorRsp,
-    [OPCODE_CONNECT] = &BluetoothDaemonHidModule::ConnectRsp,
-    [OPCODE_DISCONNECT] = &BluetoothDaemonHidModule::DisconnectRsp,
-    [OPCODE_VIRTUAL_UNPLUG] = &BluetoothDaemonHidModule::VirtualUnplugRsp,
-    [OPCODE_SET_INFO] = &BluetoothDaemonHidModule::SetInfoRsp,
-    [OPCODE_GET_PROTOCOL] = &BluetoothDaemonHidModule::GetProtocolRsp,
-    [OPCODE_SET_PROTOCOL] = &BluetoothDaemonHidModule::SetProtocolRsp,
-    [OPCODE_GET_REPORT] = &BluetoothDaemonHidModule::GetReportRsp,
-    [OPCODE_SET_REPORT] = &BluetoothDaemonHidModule::SetReportRsp,
-    [OPCODE_SEND_DATA] = &BluetoothDaemonHidModule::SendDataRsp
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-  if (NS_WARN_IF(!(aHeader.mOpcode < MOZ_ARRAY_LENGTH(HandleRsp))) ||
-      NS_WARN_IF(!HandleRsp[aHeader.mOpcode])) {
-    return;
-  }
-
-  RefPtr<BluetoothHidResultHandler> res =
-    static_cast<BluetoothHidResultHandler*>(aRes);
-
-  if (!res) {
-    return; // Return early if no result handler has been set for response
-  }
-
-  (this->*(HandleRsp[aHeader.mOpcode]))(aHeader, aPDU, res);
-}
-
-// Notifications
-//
-
-// Returns the current notification handler to a notification runnable
-class BluetoothDaemonHidModule::NotificationHandlerWrapper final
-{
-public:
-  typedef BluetoothHidNotificationHandler ObjectType;
-
-  static ObjectType* GetInstance()
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    return sNotificationHandler;
-  }
-};
-
-void
-BluetoothDaemonHidModule::ConnectionStateNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ConnectionStateNotification::Dispatch(
-    &BluetoothHidNotificationHandler::ConnectionStateNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::HidInfoNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  HidInfoNotification::Dispatch(
-    &BluetoothHidNotificationHandler::HidInfoNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::ProtocolModeNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  ProtocolModeNotification::Dispatch(
-    &BluetoothHidNotificationHandler::ProtocolModeNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::IdleTimeNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  IdleTimeNotification::Dispatch(
-    &BluetoothHidNotificationHandler::IdleTimeNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::GetReportNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  GetReportNotification::Dispatch(
-    &BluetoothHidNotificationHandler::GetReportNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::VirtualUnplugNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  VirtualUnplugNotification::Dispatch(
-    &BluetoothHidNotificationHandler::VirtualUnplugNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::HandshakeNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
-{
-  HandshakeNotification::Dispatch(
-    &BluetoothHidNotificationHandler::HandshakeNotification,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonHidModule::HandleNtf(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonHidModule::* const HandleNtf[])(
-    const DaemonSocketPDUHeader&, DaemonSocketPDU&) = {
-      [0] = &BluetoothDaemonHidModule::ConnectionStateNtf,
-      [1] = &BluetoothDaemonHidModule::HidInfoNtf,
-      [2] = &BluetoothDaemonHidModule::ProtocolModeNtf,
-      [3] = &BluetoothDaemonHidModule::IdleTimeNtf,
-      [4] = &BluetoothDaemonHidModule::GetReportNtf,
-      [5] = &BluetoothDaemonHidModule::VirtualUnplugNtf,
-      [6] = &BluetoothDaemonHidModule::HandshakeNtf
-  };
-
-  MOZ_ASSERT(!NS_IsMainThread());
-
-  uint8_t index = aHeader.mOpcode - 0x81;
-
-  if (NS_WARN_IF(!(index < MOZ_ARRAY_LENGTH(HandleNtf))) ||
-      NS_WARN_IF(!HandleNtf[index])) {
-    return;
-  }
-
-  (this->*(HandleNtf[index]))(aHeader, aPDU);
-}
-
-//
-// Hid Interface
-//
-
-BluetoothDaemonHidInterface::BluetoothDaemonHidInterface(
-  BluetoothDaemonHidModule* aModule)
-  : mModule(aModule)
-{ }
-
-BluetoothDaemonHidInterface::~BluetoothDaemonHidInterface()
-{ }
-
-void
-BluetoothDaemonHidInterface::SetNotificationHandler(
-  BluetoothHidNotificationHandler* aNotificationHandler)
-{
-  MOZ_ASSERT(mModule);
-
-  mModule->SetNotificationHandler(aNotificationHandler);
-}
-
-/* Connect / Disconnect */
-
-void
-BluetoothDaemonHidInterface::Connect(
-  const BluetoothAddress& aBdAddr, BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ConnectCmd(aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonHidInterface::Disconnect(
-  const BluetoothAddress& aBdAddr, BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->DisconnectCmd(aBdAddr, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Virtual Unplug */
-
-void
-BluetoothDaemonHidInterface::VirtualUnplug(
-  const BluetoothAddress& aBdAddr, BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->VirtualUnplugCmd(aBdAddr, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Set Info */
-
-void
-BluetoothDaemonHidInterface::SetInfo(
-  const BluetoothAddress& aBdAddr,
-  const BluetoothHidInfoParam& aHidInfoParam,
-  BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->SetInfoCmd(aBdAddr, aHidInfoParam, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Protocol */
-
-void
-BluetoothDaemonHidInterface::GetProtocol(
-  const BluetoothAddress& aBdAddr,
-  BluetoothHidProtocolMode aHidProtocolMode, BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->GetProtocolCmd(aBdAddr, aHidProtocolMode, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonHidInterface::SetProtocol(
-  const BluetoothAddress& aBdAddr,
-  BluetoothHidProtocolMode aHidProtocolMode, BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->SetProtocolCmd(aBdAddr, aHidProtocolMode, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Report */
-
-void
-BluetoothDaemonHidInterface::GetReport(
-  const BluetoothAddress& aBdAddr, BluetoothHidReportType aType,
-  uint8_t aReportId, uint16_t aBuffSize, BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->GetReportCmd(
-    aBdAddr, aType, aReportId, aBuffSize, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonHidInterface::SetReport(
-  const BluetoothAddress& aBdAddr, BluetoothHidReportType aType,
-  const BluetoothHidReport& aReport, BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->SetReportCmd(
-    aBdAddr, aType, aReport, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-/* Send Data */
-
-void
-BluetoothDaemonHidInterface::SendData(
-  const BluetoothAddress& aBdAddr, uint16_t aDataLen, const uint8_t* aData,
-  BluetoothHidResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->SendDataCmd(aBdAddr, aDataLen, aData, aRes);
-
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonHidInterface::DispatchError(
-  BluetoothHidResultHandler* aRes, BluetoothStatus aStatus)
-{
-  DaemonResultRunnable1<BluetoothHidResultHandler, void,
-                        BluetoothStatus, BluetoothStatus>::Dispatch(
-    aRes, &BluetoothHidResultHandler::OnError,
-    ConstantInitOp1<BluetoothStatus>(aStatus));
-}
-
-void
-BluetoothDaemonHidInterface::DispatchError(
-  BluetoothHidResultHandler* aRes, nsresult aRv)
-{
-  BluetoothStatus status;
-
-  if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
-    status = STATUS_FAIL;
-  }
-  DispatchError(aRes, status);
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHidInterface.h
+++ /dev/null
@@ -1,298 +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_BluetoothDaemonHidInterface_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothDaemonHidInterface_h
-
-#include "BluetoothDaemonHelpers.h"
-#include "BluetoothInterface.h"
-#include "mozilla/ipc/DaemonRunnables.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using mozilla::ipc::DaemonSocketPDU;
-using mozilla::ipc::DaemonSocketPDUHeader;
-using mozilla::ipc::DaemonSocketResultHandler;
-
-class BluetoothDaemonHidModule
-{
-public:
-  enum {
-    SERVICE_ID = 0x03
-  };
-
-  enum {
-    OPCODE_ERROR = 0x00,
-    OPCODE_CONNECT = 0x01,
-    OPCODE_DISCONNECT = 0x02,
-    OPCODE_VIRTUAL_UNPLUG = 0x03,
-    OPCODE_SET_INFO = 0x04,
-    OPCODE_GET_PROTOCOL = 0x05,
-    OPCODE_SET_PROTOCOL = 0x06,
-    OPCODE_GET_REPORT = 0x07,
-    OPCODE_SET_REPORT = 0x08,
-    OPCODE_SEND_DATA = 0x09
-  };
-
-  virtual nsresult Send(DaemonSocketPDU* aPDU,
-                        DaemonSocketResultHandler* aRes) = 0;
-
-  void SetNotificationHandler(
-    BluetoothHidNotificationHandler* aNotificationHandler);
-
-  //
-  // Commands
-  //
-
-  nsresult ConnectCmd(const BluetoothAddress& aBdAddr,
-                      BluetoothHidResultHandler* aRes);
-  nsresult DisconnectCmd(const BluetoothAddress& aBdAddr,
-                         BluetoothHidResultHandler* aRes);
-
-  /* Virtual Unplug */
-
-  nsresult VirtualUnplugCmd(const BluetoothAddress& aBdAddr,
-                            BluetoothHidResultHandler* aRes);
-
-  /* Set Info */
-
-  nsresult SetInfoCmd(
-    const BluetoothAddress& aBdAddr,
-    const BluetoothHidInfoParam& aHidInfoParam,
-    BluetoothHidResultHandler* aRes);
-
-  /* Protocol */
-
-  nsresult GetProtocolCmd(const BluetoothAddress& aBdAddr,
-                          BluetoothHidProtocolMode aHidProtocolMode,
-                          BluetoothHidResultHandler* aRes);
-  nsresult SetProtocolCmd(const BluetoothAddress& aBdAddr,
-                          BluetoothHidProtocolMode aHidProtocolMode,
-                          BluetoothHidResultHandler* aRes);
-
-  /* Report */
-
-  nsresult GetReportCmd(const BluetoothAddress& aBdAddr,
-                        BluetoothHidReportType aType,
-                        uint8_t aReportId,
-                        uint16_t aBuffSize,
-                        BluetoothHidResultHandler* aRes);
-  nsresult SetReportCmd(const BluetoothAddress& aBdAddr,
-                        BluetoothHidReportType aType,
-                        const BluetoothHidReport& aReport,
-                        BluetoothHidResultHandler* aRes);
-
-  /* Send Data */
-
-  nsresult SendDataCmd(const BluetoothAddress& aBdAddr,
-                       uint16_t aDataLen, const uint8_t* aData,
-                       BluetoothHidResultHandler* aRes);
-
-protected:
-  void HandleSvc(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU,
-                 DaemonSocketResultHandler* aRes);
-
-  //
-  // Responses
-  //
-
-  typedef mozilla::ipc::DaemonResultRunnable0<
-    BluetoothHidResultHandler, void>
-    ResultRunnable;
-
-  typedef mozilla::ipc::DaemonResultRunnable1<
-    BluetoothHidResultHandler, void, BluetoothStatus, BluetoothStatus>
-    ErrorRunnable;
-
-  void ErrorRsp(const DaemonSocketPDUHeader& aHeader,
-                DaemonSocketPDU& aPDU,
-                BluetoothHidResultHandler* aRes);
-
-  void ConnectRsp(const DaemonSocketPDUHeader& aHeader,
-                  DaemonSocketPDU& aPDU,
-                  BluetoothHidResultHandler* aRes);
-
-  void DisconnectRsp(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU,
-                     BluetoothHidResultHandler* aRes);
-
-  void VirtualUnplugRsp(const DaemonSocketPDUHeader& aHeader,
-                        DaemonSocketPDU& aPDU,
-                        BluetoothHidResultHandler* aRes);
-
-  void SetInfoRsp(const DaemonSocketPDUHeader& aHeader,
-                  DaemonSocketPDU& aPDU,
-                  BluetoothHidResultHandler* aRes);
-
-  void GetProtocolRsp(const DaemonSocketPDUHeader& aHeader,
-                      DaemonSocketPDU& aPDU,
-                      BluetoothHidResultHandler* aRes);
-
-  void SetProtocolRsp(const DaemonSocketPDUHeader& aHeader,
-                      DaemonSocketPDU& aPDU,
-                      BluetoothHidResultHandler* aRes);
-
-  void GetReportRsp(const DaemonSocketPDUHeader& aHeader,
-                    DaemonSocketPDU& aPDU,
-                    BluetoothHidResultHandler* aRes);
-
-  void SetReportRsp(const DaemonSocketPDUHeader& aHeader,
-                    DaemonSocketPDU& aPDU,
-                    BluetoothHidResultHandler* aRes);
-
-  void SendDataRsp(const DaemonSocketPDUHeader& aHeader,
-                   DaemonSocketPDU& aPDU,
-                   BluetoothHidResultHandler* aRes);
-
-  void HandleRsp(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU,
-                 DaemonSocketResultHandler* aRes);
-
-  //
-  // Notifications
-  //
-
-  class NotificationHandlerWrapper;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, BluetoothHidConnectionState,
-    const BluetoothAddress&, BluetoothHidConnectionState>
-    ConnectionStateNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, BluetoothHidInfoParam,
-    const BluetoothAddress&, const BluetoothHidInfoParam&>
-    HidInfoNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, BluetoothHidStatus, BluetoothHidProtocolMode,
-    const BluetoothAddress&, BluetoothHidStatus, BluetoothHidProtocolMode>
-    ProtocolModeNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, BluetoothHidStatus, uint16_t,
-    const BluetoothAddress&, BluetoothHidStatus, uint16_t>
-    IdleTimeNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable3<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, BluetoothHidStatus, BluetoothHidReport,
-    const BluetoothAddress&, BluetoothHidStatus,
-    const BluetoothHidReport&>
-    GetReportNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, BluetoothHidStatus,
-    const BluetoothAddress&, BluetoothHidStatus>
-    VirtualUnplugNotification;
-
-  typedef mozilla::ipc::DaemonNotificationRunnable2<
-    NotificationHandlerWrapper, void,
-    BluetoothAddress, BluetoothHidStatus,
-    const BluetoothAddress&, BluetoothHidStatus>
-    HandshakeNotification;
-
-  void ConnectionStateNtf(const DaemonSocketPDUHeader& aHeader,
-                          DaemonSocketPDU& aPDU);
-
-  void HidInfoNtf(const DaemonSocketPDUHeader& aHeader,
-                  DaemonSocketPDU& aPDU);
-
-  void ProtocolModeNtf(const DaemonSocketPDUHeader& aHeader,
-                       DaemonSocketPDU& aPDU);
-
-  void IdleTimeNtf(const DaemonSocketPDUHeader& aHeader,
-                   DaemonSocketPDU& aPDU);
-
-  void GetReportNtf(const DaemonSocketPDUHeader& aHeader,
-                    DaemonSocketPDU& aPDU);
-
-  void VirtualUnplugNtf(const DaemonSocketPDUHeader& aHeader,
-                        DaemonSocketPDU& aPDU);
-
-  void HandshakeNtf(const DaemonSocketPDUHeader& aHeader,
-                    DaemonSocketPDU& aPDU);
-
-  void HandleNtf(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU,
-                 DaemonSocketResultHandler* aRes);
-
-  static BluetoothHidNotificationHandler* sNotificationHandler;
-};
-
-class BluetoothDaemonHidInterface final
-  : public BluetoothHidInterface
-{
-public:
-  BluetoothDaemonHidInterface(BluetoothDaemonHidModule* aModule);
-  ~BluetoothDaemonHidInterface();
-
-  void SetNotificationHandler(
-    BluetoothHidNotificationHandler* aNotificationHandler) override;
-
-  /* Connect / Disconnect */
-
-  void Connect(const BluetoothAddress& aBdAddr,
-               BluetoothHidResultHandler* aRes) override;
-  void Disconnect(const BluetoothAddress& aBdAddr,
-                  BluetoothHidResultHandler* aRes) override;
-
-  /* Virtual Unplug */
-
-  void VirtualUnplug(const BluetoothAddress& aBdAddr,
-                     BluetoothHidResultHandler* aRes) override;
-
-  /* Set Info */
-
-  void SetInfo(
-    const BluetoothAddress& aBdAddr,
-    const BluetoothHidInfoParam& aHidInfoParam,
-    BluetoothHidResultHandler* aRes) override;
-
-  /* Protocol */
-
-  void GetProtocol(const BluetoothAddress& aBdAddr,
-                   BluetoothHidProtocolMode aHidProtoclMode,
-                   BluetoothHidResultHandler* aRes) override;
-
-  void SetProtocol(const BluetoothAddress& aBdAddr,
-                   BluetoothHidProtocolMode aHidProtocolMode,
-                   BluetoothHidResultHandler* aRes) override;
-
-  /* Report */
-
-  void GetReport(const BluetoothAddress& aBdAddr,
-                 BluetoothHidReportType aType,
-                 uint8_t aReportId, uint16_t aBuffSize,
-                 BluetoothHidResultHandler* aRes) override;
-  void SetReport(const BluetoothAddress& aBdAddr,
-                 BluetoothHidReportType aType,
-                 const BluetoothHidReport& aReport,
-                 BluetoothHidResultHandler* aRes) override;
-
-  /* Send Data */
-
-  void SendData(const BluetoothAddress& aBdAddr,
-                uint16_t aDataLen, const uint8_t* aData,
-                BluetoothHidResultHandler* aRes) override;
-
-private:
-  void DispatchError(BluetoothHidResultHandler* aRes,
-                     BluetoothStatus aStatus);
-  void DispatchError(BluetoothHidResultHandler* aRes, nsresult aRv);
-
-  BluetoothDaemonHidModule* mModule;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothDaemonHidInterface_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
+++ /dev/null
@@ -1,796 +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 "BluetoothDaemonInterface.h"
-#include <cutils/properties.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include "BluetoothDaemonA2dpInterface.h"
-#include "BluetoothDaemonAvrcpInterface.h"
-#include "BluetoothDaemonCoreInterface.h"
-#include "BluetoothDaemonGattInterface.h"
-#include "BluetoothDaemonHandsfreeInterface.h"
-#include "BluetoothDaemonHelpers.h"
-#include "BluetoothDaemonHidInterface.h"
-#include "BluetoothDaemonSetupInterface.h"
-#include "BluetoothDaemonSocketInterface.h"
-#include "mozilla/Hal.h"
-#include "mozilla/ipc/DaemonRunnables.h"
-#include "mozilla/ipc/DaemonSocket.h"
-#include "mozilla/ipc/DaemonSocketConnector.h"
-#include "mozilla/ipc/ListenSocket.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using namespace mozilla::ipc;
-
-static const int sRetryInterval = 100; // ms
-
-BluetoothNotificationHandler*
-  BluetoothDaemonInterface::sNotificationHandler;
-
-//
-// Protocol handling
-//
-
-// |BluetoothDaemonProtocol| is the central class for communicating
-// with the Bluetooth daemon. It maintains both socket connections
-// to the external daemon and implements the complete HAL protocol
-// by inheriting from base-class modules.
-//
-// Each |BluetoothDaemon*Module| class implements an individual
-// module of the HAL protocol. Each class contains the abstract
-// method
-//
-//  - |Send|.
-//
-// Module classes use |Send| to send out command PDUs. The socket
-// in |BluetoothDaemonProtocol| is required for sending. The abstract
-// method hides all these internal details from the modules.
-//
-// |BluetoothDaemonProtocol| also handles PDU receiving. It implements
-// the method |Handle| from |DaemonSocketIOConsumer|. The socket
-// connections of type |DaemonSocket| invoke this method
-// to forward received PDUs for processing by higher layers. The
-// implementation of |Handle| checks the service id of the PDU and
-// forwards it to the correct module class using the module's method
-// |HandleSvc|. Further PDU processing is module-dependent.
-//
-// To summarize the interface between |BluetoothDaemonProtocol| and
-// modules; the former implements the abstract method
-//
-//  - |Send|,
-//
-// which allow modules to send out data. Each module implements the
-// method
-//
-//  - |HandleSvc|,
-//
-// which is called by |BluetoothDaemonProtcol| to hand over received
-// PDUs into a module.
-//
-class BluetoothDaemonProtocol final
-  : public DaemonSocketIOConsumer
-  , public BluetoothDaemonSetupModule
-  , public BluetoothDaemonCoreModule
-  , public BluetoothDaemonSocketModule
-  , public BluetoothDaemonHandsfreeModule
-  , public BluetoothDaemonA2dpModule
-  , public BluetoothDaemonAvrcpModule
-  , public BluetoothDaemonGattModule
-  , public BluetoothDaemonHidModule
-{
-public:
-  BluetoothDaemonProtocol();
-
-  void SetConnection(DaemonSocket* aConnection);
-
-  // Outgoing PDUs
-  //
-
-  nsresult Send(DaemonSocketPDU* aPDU,
-                DaemonSocketResultHandler* aRes) override;
-
-  void StoreResultHandler(const DaemonSocketPDU& aPDU) override;
-
-  // Incoming PUDs
-  //
-
-  void Handle(DaemonSocketPDU& aPDU) override;
-
-  already_AddRefed<DaemonSocketResultHandler> FetchResultHandler(
-    const DaemonSocketPDUHeader& aHeader);
-
-private:
-  void HandleSetupSvc(const DaemonSocketPDUHeader& aHeader,
-                      DaemonSocketPDU& aPDU,
-                      DaemonSocketResultHandler* aRes);
-  void HandleCoreSvc(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU,
-                     DaemonSocketResultHandler* aRes);
-  void HandleSocketSvc(const DaemonSocketPDUHeader& aHeader,
-                       DaemonSocketPDU& aPDU,
-                       DaemonSocketResultHandler* aRes);
-  void HandleHandsfreeSvc(const DaemonSocketPDUHeader& aHeader,
-                          DaemonSocketPDU& aPDU,
-                          DaemonSocketResultHandler* aRes);
-  void HandleA2dpSvc(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU,
-                     DaemonSocketResultHandler* aUserData);
-  void HandleAvrcpSvc(const DaemonSocketPDUHeader& aHeader,
-                      DaemonSocketPDU& aPDU,
-                      DaemonSocketResultHandler* aRes);
-  void HandleGattSvc(const DaemonSocketPDUHeader& aHeader,
-                     DaemonSocketPDU& aPDU,
-                     DaemonSocketResultHandler* aRes);
-  void HandleHidSvc(const DaemonSocketPDUHeader& aHeader,
-                    DaemonSocketPDU& aPDU,
-                    DaemonSocketResultHandler* aRes);
-
-  DaemonSocket* mConnection;
-  nsTArray<RefPtr<DaemonSocketResultHandler>> mResQ;
-};
-
-BluetoothDaemonProtocol::BluetoothDaemonProtocol()
-{ }
-
-void
-BluetoothDaemonProtocol::SetConnection(DaemonSocket* aConnection)
-{
-  mConnection = aConnection;
-}
-
-nsresult
-BluetoothDaemonProtocol::Send(DaemonSocketPDU* aPDU,
-                              DaemonSocketResultHandler* aRes)
-{
-  MOZ_ASSERT(mConnection);
-  MOZ_ASSERT(aPDU);
-
-  if (mConnection->GetConnectionStatus() == SOCKET_DISCONNECTED) {
-    BT_LOGR("Connection to Bluetooth daemon is closed.");
-    return NS_ERROR_FAILURE;
-  }
-
-  aPDU->SetConsumer(this);
-  aPDU->SetResultHandler(aRes);
-  aPDU->UpdateHeader();
-
-  mConnection->SendSocketData(aPDU); // Forward PDU to command channel
-
-  return NS_OK;
-}
-
-void
-BluetoothDaemonProtocol::HandleSetupSvc(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  BluetoothDaemonSetupModule::HandleSvc(aHeader, aPDU, aRes);
-}
-
-void
-BluetoothDaemonProtocol::HandleCoreSvc(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  BluetoothDaemonCoreModule::HandleSvc(aHeader, aPDU, aRes);
-}
-
-void
-BluetoothDaemonProtocol::HandleSocketSvc(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  BluetoothDaemonSocketModule::HandleSvc(aHeader, aPDU, aRes);
-}
-
-void
-BluetoothDaemonProtocol::HandleHandsfreeSvc(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  BluetoothDaemonHandsfreeModule::HandleSvc(aHeader, aPDU, aRes);
-}
-
-void
-BluetoothDaemonProtocol::HandleA2dpSvc(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  BluetoothDaemonA2dpModule::HandleSvc(aHeader, aPDU, aRes);
-}
-
-void
-BluetoothDaemonProtocol::HandleAvrcpSvc(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  BluetoothDaemonAvrcpModule::HandleSvc(aHeader, aPDU, aRes);
-}
-
-void
-BluetoothDaemonProtocol::HandleGattSvc(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  BluetoothDaemonGattModule::HandleSvc(aHeader, aPDU, aRes);
-}
-
-void
-BluetoothDaemonProtocol::HandleHidSvc(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  DaemonSocketResultHandler* aRes)
-{
-  BluetoothDaemonHidModule::HandleSvc(aHeader, aPDU, aRes);
-}
-
-void
-BluetoothDaemonProtocol::Handle(DaemonSocketPDU& aPDU)
-{
-  static void (BluetoothDaemonProtocol::* const HandleSvc[])(
-    const DaemonSocketPDUHeader&, DaemonSocketPDU&,
-    DaemonSocketResultHandler*) = {
-    [BluetoothDaemonSetupModule::SERVICE_ID] =
-      &BluetoothDaemonProtocol::HandleSetupSvc,
-    [BluetoothDaemonCoreModule::SERVICE_ID] =
-      &BluetoothDaemonProtocol::HandleCoreSvc,
-    [BluetoothDaemonSocketModule::SERVICE_ID] =
-      &BluetoothDaemonProtocol::HandleSocketSvc,
-    [BluetoothDaemonHidModule::SERVICE_ID] =
-      &BluetoothDaemonProtocol::HandleHidSvc,
-    [0x04] = nullptr, // PAN
-    [BluetoothDaemonHandsfreeModule::SERVICE_ID] =
-      &BluetoothDaemonProtocol::HandleHandsfreeSvc,
-    [BluetoothDaemonA2dpModule::SERVICE_ID] =
-      &BluetoothDaemonProtocol::HandleA2dpSvc,
-    [0x07] = nullptr, // Health
-    [BluetoothDaemonAvrcpModule::SERVICE_ID] =
-      &BluetoothDaemonProtocol::HandleAvrcpSvc,
-    [BluetoothDaemonGattModule::SERVICE_ID] =
-      &BluetoothDaemonProtocol::HandleGattSvc
-  };
-
-  DaemonSocketPDUHeader header;
-
-  if (NS_FAILED(UnpackPDU(aPDU, header)) ||
-      NS_WARN_IF(!(header.mService < MOZ_ARRAY_LENGTH(HandleSvc))) ||
-      NS_WARN_IF(!(HandleSvc[header.mService]))) {
-    return;
-  }
-
-  RefPtr<DaemonSocketResultHandler> res = FetchResultHandler(header);
-
-  (this->*(HandleSvc[header.mService]))(header, aPDU, res);
-}
-
-void
-BluetoothDaemonProtocol::StoreResultHandler(const DaemonSocketPDU& aPDU)
-{
-  MOZ_ASSERT(!NS_IsMainThread());
-
-  mResQ.AppendElement(aPDU.GetResultHandler());
-}
-
-already_AddRefed<DaemonSocketResultHandler>
-BluetoothDaemonProtocol::FetchResultHandler(
-  const DaemonSocketPDUHeader& aHeader)
-{
-  MOZ_ASSERT(!NS_IsMainThread());
-
-  if (aHeader.mOpcode & 0x80) {
-    return nullptr; // Ignore notifications
-  }
-
-  RefPtr<DaemonSocketResultHandler> userData = mResQ.ElementAt(0);
-  mResQ.RemoveElementAt(0);
-
-  return userData.forget();
-}
-
-//
-// Interface
-//
-
-BluetoothDaemonInterface*
-BluetoothDaemonInterface::GetInstance()
-{
-  static BluetoothDaemonInterface* sBluetoothInterface;
-
-  if (sBluetoothInterface) {
-    return sBluetoothInterface;
-  }
-
-  sBluetoothInterface = new BluetoothDaemonInterface();
-
-  return sBluetoothInterface;
-}
-
-BluetoothDaemonInterface::BluetoothDaemonInterface()
-{ }
-
-BluetoothDaemonInterface::~BluetoothDaemonInterface()
-{ }
-
-class BluetoothDaemonInterface::InitResultHandler final
-  : public BluetoothSetupResultHandler
-{
-public:
-  InitResultHandler(BluetoothDaemonInterface* aInterface,
-                    BluetoothResultHandler* aRes)
-    : mInterface(aInterface)
-    , mRes(aRes)
-    , mRegisteredSocketModule(false)
-  {
-    MOZ_ASSERT(mInterface);
-  }
-
-  // We need to call methods from the |BluetoothResultHandler|. Since
-  // we're already on the main thread and returned from Init, we don't
-  // need to dispatch a new runnable.
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (mRes) {
-      mRes->OnError(aStatus);
-    }
-  }
-
-  void RegisterModule() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-    MOZ_ASSERT(mInterface->mProtocol);
-
-    if (!mRegisteredSocketModule) {
-      mRegisteredSocketModule = true;
-      // Init, step 5: Register Socket module
-      mInterface->mProtocol->RegisterModuleCmd(
-        SETUP_SERVICE_ID_SOCKET,
-        0x00,
-        BluetoothDaemonSocketModule::MAX_NUM_CLIENTS, this);
-    } else if (mRes) {
-      // Init, step 6: Signal success to caller
-      mRes->Init();
-    }
-  }
-
-private:
-  BluetoothDaemonInterface* mInterface;
-  RefPtr<BluetoothResultHandler> mRes;
-  bool mRegisteredSocketModule;
-};
-
-/*
- * The init procedure consists of several steps.
- *
- *  (1) Start listening for the command channel's socket connection: We
- *      do this before anything else, so that we don't miss connection
- *      requests from the Bluetooth daemon. This step will create a
- *      listen socket.
- *
- *  (2) Start the Bluetooth daemon: When the daemon starts up it will
- *      open two socket connections to Gecko and thus create the command
- *      and notification channels. Gecko already opened the listen socket
- *      in step (1). Step (2) ends with the creation of the command channel.
- *
- *  (3) Start listening for the notification channel's socket connection:
- *      At the end of step (2), the command channel was opened by the
- *      daemon. In step (3), the daemon immediately tries to open the
- *      next socket for the notification channel. Gecko will accept the
- *      incoming connection request for the notification channel. The
- *      listen socket remained open after step (2), so there's no race
- *      condition between Gecko and the Bluetooth daemon.
- *
- *  (4)(5) Register Core and Socket modules: The Core and Socket modules
- *      are always available and have to be registered after opening the
- *      socket connections during the initialization.
- *
- *  (6) Signal success to the caller.
- *
- * If any step fails, we roll-back the procedure and signal an error to the
- * caller.
- */
-void
-BluetoothDaemonInterface::Init(
-  BluetoothNotificationHandler* aNotificationHandler,
-  BluetoothResultHandler* aRes)
-{
-#define BASE_SOCKET_NAME "bluetoothd"
-  static unsigned long POSTFIX_LENGTH = 16;
-
-  // First of all, we set the notification handler. Backend crashes
-  // will be reported this way.
-  sNotificationHandler = aNotificationHandler;
-
-  // If we could not cleanup properly before and an old
-  // instance of the daemon is still running, we kill it
-  // here.
-  mozilla::hal::StopSystemService("bluetoothd");
-
-  mResultHandlerQ.AppendElement(aRes);
-
-  if (!mProtocol) {
-    mProtocol = MakeUnique<BluetoothDaemonProtocol>();
-  }
-
-  if (!mListenSocket) {
-    mListenSocket = new ListenSocket(this, LISTEN_SOCKET);
-  }
-
-  // Init, step 1: Listen for command channel... */
-
-  if (!mCmdChannel) {
-    mCmdChannel = new DaemonSocket(mProtocol.get(), this, CMD_CHANNEL);
-  } else if (
-    NS_WARN_IF(mCmdChannel->GetConnectionStatus() == SOCKET_CONNECTED)) {
-    // Command channel should not be open; let's close it.
-    mCmdChannel->Close();
-  }
-
-  // The listen socket's name is generated with a random postfix. This
-  // avoids naming collisions if we still have a listen socket from a
-  // previously failed cleanup. It also makes it hard for malicious
-  // external programs to capture the socket name or connect before
-  // the daemon can do so. If no random postfix can be generated, we
-  // simply use the base name as-is.
-  nsresult rv = DaemonSocketConnector::CreateRandomAddressString(
-    NS_LITERAL_CSTRING(BASE_SOCKET_NAME), POSTFIX_LENGTH, mListenSocketName);
-  if (NS_FAILED(rv)) {
-    mListenSocketName.AssignLiteral(BASE_SOCKET_NAME);
-  }
-
-  rv = mListenSocket->Listen(new DaemonSocketConnector(mListenSocketName),
-                             mCmdChannel);
-  if (NS_FAILED(rv)) {
-    OnConnectError(CMD_CHANNEL);
-    return;
-  }
-
-  // The protocol implementation needs a command channel for
-  // sending commands to the daemon. We set it here, because
-  // this is the earliest time when it's available.
-  mProtocol->SetConnection(mCmdChannel);
-}
-
-class BluetoothDaemonInterface::CleanupResultHandler final
-  : public BluetoothSetupResultHandler
-{
-public:
-  CleanupResultHandler(BluetoothDaemonInterface* aInterface)
-    : mInterface(aInterface)
-    , mUnregisteredCoreModule(false)
-  {
-    MOZ_ASSERT(mInterface);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    Proceed();
-  }
-
-  void UnregisterModule() override
-  {
-    Proceed();
-  }
-
-private:
-  void Proceed()
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-    MOZ_ASSERT(mInterface->mProtocol);
-
-    if (!mUnregisteredCoreModule) {
-      mUnregisteredCoreModule = true;
-      // Cleanup, step 2: Unregister Core module
-      mInterface->mProtocol->UnregisterModuleCmd(SETUP_SERVICE_ID_CORE, this);
-    } else {
-      // Cleanup, step 3: Close command channel
-      mInterface->mCmdChannel->Close();
-    }
-  }
-
-  BluetoothDaemonInterface* mInterface;
-  bool mUnregisteredCoreModule;
-};
-
-/*
- * Cleaning up is inverse to initialization, except for the shutdown
- * of the socket connections in step (3)
- *
- *  (1)(2) Unregister Socket and Core modules: These modules have been
- *      registered during initialization and need to be unregistered
- *      here. We assume that all other modules are already unregistered.
- *
- *  (3) Close command socket: We only close the command socket. The
- *      daemon will then send any final notifications and close the
- *      notification socket on its side. Once we see the notification
- *      socket's disconnect, we continue with the cleanup.
- *
- *  (4) Close listen socket: The listen socket is not active any longer
- *      and we simply close it.
- *
- *  (5) Signal success to the caller.
- *
- * We don't have to stop the daemon explicitly. It will cleanup and quit
- * after it closed the notification socket.
- *
- * Rolling-back half-completed cleanups is not possible. In the case of
- * an error, we simply push forward and try to recover during the next
- * initialization.
- */
-void
-BluetoothDaemonInterface::Cleanup(BluetoothResultHandler* aRes)
-{
-  sNotificationHandler = nullptr;
-
-  // Cleanup, step 1: Unregister Socket module
-  nsresult rv = mProtocol->UnregisterModuleCmd(
-    SETUP_SERVICE_ID_SOCKET, new CleanupResultHandler(this));
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-    return;
-  }
-
-  mResultHandlerQ.AppendElement(aRes);
-}
-
-void
-BluetoothDaemonInterface::DispatchError(BluetoothResultHandler* aRes,
-                                        BluetoothStatus aStatus)
-{
-  DaemonResultRunnable1<
-    BluetoothResultHandler, void, BluetoothStatus, BluetoothStatus>::Dispatch(
-    aRes, &BluetoothResultHandler::OnError,
-    ConstantInitOp1<BluetoothStatus>(aStatus));
-}
-
-void
-BluetoothDaemonInterface::DispatchError(BluetoothResultHandler* aRes,
-                                        nsresult aRv)
-{
-  BluetoothStatus status;
-
-  if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
-    status = STATUS_FAIL;
-  }
-  DispatchError(aRes, status);
-}
-
-// Service Interfaces
-//
-
-BluetoothSetupInterface*
-BluetoothDaemonInterface::GetBluetoothSetupInterface()
-{
-  if (mSetupInterface) {
-    return mSetupInterface.get();
-  }
-
-  mSetupInterface = MakeUnique<BluetoothDaemonSetupInterface>(mProtocol.get());
-
-  return mSetupInterface.get();
-}
-
-BluetoothCoreInterface*
-BluetoothDaemonInterface::GetBluetoothCoreInterface()
-{
-  if (mCoreInterface) {
-    return mCoreInterface.get();
-  }
-
-  mCoreInterface = MakeUnique<BluetoothDaemonCoreInterface>(mProtocol.get());
-
-  return mCoreInterface.get();
-}
-
-BluetoothSocketInterface*
-BluetoothDaemonInterface::GetBluetoothSocketInterface()
-{
-  if (mSocketInterface) {
-    return mSocketInterface.get();
-  }
-
-  mSocketInterface = MakeUnique<BluetoothDaemonSocketInterface>(mProtocol.get());
-
-  return mSocketInterface.get();
-}
-
-BluetoothHidInterface*
-BluetoothDaemonInterface::GetBluetoothHidInterface()
-{
-  if (mHidInterface) {
-    return mHidInterface.get();
-  }
-
-  mHidInterface = MakeUnique<BluetoothDaemonHidInterface>(mProtocol.get());
-
-  return mHidInterface.get();
-}
-
-BluetoothHandsfreeInterface*
-BluetoothDaemonInterface::GetBluetoothHandsfreeInterface()
-{
-  if (mHandsfreeInterface) {
-    return mHandsfreeInterface.get();
-  }
-
-  mHandsfreeInterface =
-    MakeUnique<BluetoothDaemonHandsfreeInterface>(mProtocol.get());
-
-  return mHandsfreeInterface.get();
-}
-
-BluetoothA2dpInterface*
-BluetoothDaemonInterface::GetBluetoothA2dpInterface()
-{
-  if (mA2dpInterface) {
-    return mA2dpInterface.get();
-  }
-
-  mA2dpInterface = MakeUnique<BluetoothDaemonA2dpInterface>(mProtocol.get());
-
-  return mA2dpInterface.get();
-}
-
-BluetoothAvrcpInterface*
-BluetoothDaemonInterface::GetBluetoothAvrcpInterface()
-{
-  if (mAvrcpInterface) {
-    return mAvrcpInterface.get();
-  }
-
-  mAvrcpInterface = MakeUnique<BluetoothDaemonAvrcpInterface>(mProtocol.get());
-
-  return mAvrcpInterface.get();
-}
-
-BluetoothGattInterface*
-BluetoothDaemonInterface::GetBluetoothGattInterface()
-{
-  if (mGattInterface) {
-    return mGattInterface.get();
-  }
-
-  mGattInterface = MakeUnique<BluetoothDaemonGattInterface>(mProtocol.get());
-
-  return mGattInterface.get();
-}
-
-// |DaemonSocketConsumer|, |ListenSocketConsumer|
-
-void
-BluetoothDaemonInterface::OnConnectSuccess(int aIndex)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!mResultHandlerQ.IsEmpty());
-
-  switch (aIndex) {
-    case LISTEN_SOCKET: {
-        // Init, step 2: Start Bluetooth daemon */
-        nsCString args("-a ");
-        args.Append(mListenSocketName);
-        mozilla::hal::StartSystemService("bluetoothd", args.get());
-      }
-      break;
-    case CMD_CHANNEL:
-      // Init, step 3: Listen for notification channel...
-      if (!mNtfChannel) {
-        mNtfChannel = new DaemonSocket(mProtocol.get(), this, NTF_CHANNEL);
-      } else if (
-        NS_WARN_IF(mNtfChannel->GetConnectionStatus() == SOCKET_CONNECTED)) {
-        /* Notification channel should not be open; let's close it. */
-        mNtfChannel->Close();
-      }
-      if (NS_FAILED(mListenSocket->Listen(mNtfChannel))) {
-        OnConnectError(NTF_CHANNEL);
-      }
-      break;
-    case NTF_CHANNEL: {
-        RefPtr<BluetoothResultHandler> res = mResultHandlerQ.ElementAt(0);
-        mResultHandlerQ.RemoveElementAt(0);
-
-        // Init, step 4: Register Core module
-        nsresult rv = mProtocol->RegisterModuleCmd(
-          SETUP_SERVICE_ID_CORE,
-          0x00,
-          BluetoothDaemonCoreModule::MAX_NUM_CLIENTS,
-          new InitResultHandler(this, res));
-        if (NS_FAILED(rv) && res) {
-          DispatchError(res, STATUS_FAIL);
-        }
-      }
-      break;
-  }
-}
-
-void
-BluetoothDaemonInterface::OnConnectError(int aIndex)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!mResultHandlerQ.IsEmpty());
-
-  switch (aIndex) {
-    case NTF_CHANNEL:
-      // Close command channel
-      mCmdChannel->Close();
-    case CMD_CHANNEL:
-      // Stop daemon and close listen socket
-      mozilla::hal::StopSystemService("bluetoothd");
-      mListenSocket->Close();
-    case LISTEN_SOCKET:
-      if (!mResultHandlerQ.IsEmpty()) {
-        // Signal error to caller
-        RefPtr<BluetoothResultHandler> res = mResultHandlerQ.ElementAt(0);
-        mResultHandlerQ.RemoveElementAt(0);
-
-        if (res) {
-          DispatchError(res, STATUS_FAIL);
-        }
-      }
-      break;
-  }
-}
-
-/*
- * Three cases for restarting:
- * a) during startup
- * b) during regular service
- * c) during shutdown
- * For (a)/(c) cases, mResultHandlerQ contains an element, but case (b)
- * mResultHandlerQ shall be empty. The following procedure to recover from crashed
- * consists of several steps for case (b).
- * 1) Close listen socket.
- * 2) Wait for all sockets disconnected and inform BluetoothServiceBluedroid to
- * perform the regular stop bluetooth procedure.
- * 3) When stop bluetooth procedures complete, fire
- * AdapterStateChangedNotification to cleanup all necessary data members and
- * deinit ProfileManagers.
- * 4) After all resources cleanup, call |StartBluetooth|
- */
-void
-BluetoothDaemonInterface::OnDisconnect(int aIndex)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  switch (aIndex) {
-    case CMD_CHANNEL:
-      // We don't have to do anything here. Step 4 is triggered
-      // by the daemon.
-      break;
-    case NTF_CHANNEL:
-      // Cleanup, step 4 (Recovery, step 1): Close listen socket
-      mListenSocket->Close();
-      break;
-    case LISTEN_SOCKET:
-      if (!mResultHandlerQ.IsEmpty()) {
-        RefPtr<BluetoothResultHandler> res = mResultHandlerQ.ElementAt(0);
-        mResultHandlerQ.RemoveElementAt(0);
-        // Cleanup, step 5: Signal success to caller
-        if (res) {
-          res->Cleanup();
-        }
-      }
-      break;
-  }
-
-  /* For recovery make sure all sockets disconnected, in order to avoid
-   * the remaining disconnects interfere with the restart procedure.
-   */
-  if (sNotificationHandler && mResultHandlerQ.IsEmpty()) {
-    if (mListenSocket->GetConnectionStatus() == SOCKET_DISCONNECTED &&
-        mCmdChannel->GetConnectionStatus() == SOCKET_DISCONNECTED &&
-        mNtfChannel->GetConnectionStatus() == SOCKET_DISCONNECTED) {
-      // Assume daemon crashed during regular service; notify
-      // BluetoothServiceBluedroid to prepare restart-daemon procedure
-      sNotificationHandler->BackendErrorNotification(true);
-      sNotificationHandler = nullptr;
-    }
-  }
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.h
+++ /dev/null
@@ -1,108 +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_BluetoothDaemonInterface_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothDaemonInterface_h
-
-#include "BluetoothInterface.h"
-#include "mozilla/ipc/DaemonSocketConsumer.h"
-#include "mozilla/ipc/ListenSocketConsumer.h"
-#include "mozilla/UniquePtr.h"
-
-namespace mozilla {
-namespace ipc {
-
-class DaemonSocket;
-class ListenSocket;
-
-}
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothDaemonA2dpInterface;
-class BluetoothDaemonAvrcpInterface;
-class BluetoothDaemonCoreInterface;
-class BluetoothDaemonGattInterface;
-class BluetoothDaemonHandsfreeInterface;
-class BluetoothDaemonProtocol;
-class BluetoothDaemonSetupInterface;
-class BluetoothDaemonSocketInterface;
-class BluetoothDaemonHidInterface;
-
-class BluetoothDaemonInterface final
-  : public BluetoothInterface
-  , public mozilla::ipc::DaemonSocketConsumer
-  , public mozilla::ipc::ListenSocketConsumer
-{
-public:
-  class CleanupResultHandler;
-  class InitResultHandler;
-
-  friend class CleanupResultHandler;
-  friend class InitResultHandler;
-
-  static BluetoothDaemonInterface* GetInstance();
-
-  void Init(BluetoothNotificationHandler* aNotificationHandler,
-            BluetoothResultHandler* aRes) override;
-  void Cleanup(BluetoothResultHandler* aRes) override;
-
-  /* Service Interfaces */
-
-  BluetoothSetupInterface* GetBluetoothSetupInterface() override;
-  BluetoothCoreInterface* GetBluetoothCoreInterface() override;
-  BluetoothSocketInterface* GetBluetoothSocketInterface() override;
-  BluetoothHandsfreeInterface* GetBluetoothHandsfreeInterface() override;
-  BluetoothA2dpInterface* GetBluetoothA2dpInterface() override;
-  BluetoothAvrcpInterface* GetBluetoothAvrcpInterface() override;
-  BluetoothGattInterface* GetBluetoothGattInterface() override;
-  BluetoothHidInterface* GetBluetoothHidInterface() override;
-
-protected:
-  enum Channel {
-    LISTEN_SOCKET,
-    CMD_CHANNEL,
-    NTF_CHANNEL
-  };
-
-  BluetoothDaemonInterface();
-  ~BluetoothDaemonInterface();
-
-  // Methods for |DaemonSocketConsumer| and |ListenSocketConsumer|
-  //
-
-  void OnConnectSuccess(int aIndex) override;
-  void OnConnectError(int aIndex) override;
-  void OnDisconnect(int aIndex) override;
-
-private:
-  void DispatchError(BluetoothResultHandler* aRes, BluetoothStatus aStatus);
-  void DispatchError(BluetoothResultHandler* aRes, nsresult aRv);
-
-  static BluetoothNotificationHandler* sNotificationHandler;
-
-  nsCString mListenSocketName;
-  RefPtr<mozilla::ipc::ListenSocket> mListenSocket;
-  RefPtr<mozilla::ipc::DaemonSocket> mCmdChannel;
-  RefPtr<mozilla::ipc::DaemonSocket> mNtfChannel;
-  UniquePtr<BluetoothDaemonProtocol> mProtocol;
-
-  nsTArray<RefPtr<BluetoothResultHandler> > mResultHandlerQ;
-
-  UniquePtr<BluetoothDaemonSetupInterface> mSetupInterface;
-  UniquePtr<BluetoothDaemonCoreInterface> mCoreInterface;
-  UniquePtr<BluetoothDaemonSocketInterface> mSocketInterface;
-  UniquePtr<BluetoothDaemonHidInterface> mHidInterface;
-  UniquePtr<BluetoothDaemonHandsfreeInterface> mHandsfreeInterface;
-  UniquePtr<BluetoothDaemonA2dpInterface> mA2dpInterface;
-  UniquePtr<BluetoothDaemonAvrcpInterface> mAvrcpInterface;
-  UniquePtr<BluetoothDaemonGattInterface> mGattInterface;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothDaemonInterface_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonSetupInterface.cpp
+++ /dev/null
@@ -1,246 +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 "BluetoothDaemonSetupInterface.h"
-#include "mozilla/UniquePtr.h"
-#include "mozilla/Unused.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using namespace mozilla::ipc;
-
-//
-// Setup module
-//
-
-// Called to handle PDUs with Service field equal to 0x00, which
-// contains internal operations for setup and configuration.
-void
-BluetoothDaemonSetupModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
-                                      DaemonSocketPDU& aPDU,
-                                      DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonSetupModule::* const HandleRsp[])(
-    const DaemonSocketPDUHeader&,
-    DaemonSocketPDU&,
-    BluetoothSetupResultHandler*) = {
-    [OPCODE_ERROR] =
-      &BluetoothDaemonSetupModule::ErrorRsp,
-    [OPCODE_REGISTER_MODULE] =
-      &BluetoothDaemonSetupModule::RegisterModuleRsp,
-    [OPCODE_UNREGISTER_MODULE] =
-      &BluetoothDaemonSetupModule::UnregisterModuleRsp,
-    [OPCODE_CONFIGURATION] =
-      &BluetoothDaemonSetupModule::ConfigurationRsp
-  };
-
-  if (NS_WARN_IF(aHeader.mOpcode >= MOZ_ARRAY_LENGTH(HandleRsp)) ||
-      NS_WARN_IF(!HandleRsp[aHeader.mOpcode])) {
-    return;
-  }
-
-  RefPtr<BluetoothSetupResultHandler> res =
-    static_cast<BluetoothSetupResultHandler*>(aRes);
-
-  if (!aRes) {
-    return; // Return early if no result handler has been set
-  }
-
-  (this->*(HandleRsp[aHeader.mOpcode]))(aHeader, aPDU, res);
-}
-
-// Commands
-//
-
-nsresult
-BluetoothDaemonSetupModule::RegisterModuleCmd(
-  BluetoothSetupServiceId aId, uint8_t aMode, uint32_t aMaxNumClients,
-  BluetoothSetupResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_REGISTER_MODULE,
-                                0);
-
-#if ANDROID_VERSION >= 21
-  nsresult rv = PackPDU(aId, aMode, aMaxNumClients, *pdu);
-#else
-  nsresult rv = PackPDU(aId, aMode, *pdu);
-#endif
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonSetupModule::UnregisterModuleCmd(
-  BluetoothSetupServiceId aId, BluetoothSetupResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_UNREGISTER_MODULE,
-                                0);
-
-  nsresult rv = PackPDU(aId, *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonSetupModule::ConfigurationCmd(
-  const BluetoothConfigurationParameter* aParam, uint8_t aLen,
-  BluetoothSetupResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CONFIGURATION,
-                                0);
-
-  nsresult rv = PackPDU(
-    aLen, PackArray<BluetoothConfigurationParameter>(aParam, aLen), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-// Responses
-//
-
-void
-BluetoothDaemonSetupModule::ErrorRsp(const DaemonSocketPDUHeader& aHeader,
-                                     DaemonSocketPDU& aPDU,
-                                     BluetoothSetupResultHandler* aRes)
-{
-  ErrorRunnable::Dispatch(
-    aRes, &BluetoothSetupResultHandler::OnError, UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonSetupModule::RegisterModuleRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothSetupResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothSetupResultHandler::RegisterModule,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonSetupModule::UnregisterModuleRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothSetupResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothSetupResultHandler::UnregisterModule,
-    UnpackPDUInitOp(aPDU));
-}
-
-void
-BluetoothDaemonSetupModule::ConfigurationRsp(
-  const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
-  BluetoothSetupResultHandler* aRes)
-{
-  ResultRunnable::Dispatch(
-    aRes, &BluetoothSetupResultHandler::Configuration,
-    UnpackPDUInitOp(aPDU));
-}
-
-//
-// Setup interface
-//
-
-BluetoothDaemonSetupInterface::BluetoothDaemonSetupInterface(
-  BluetoothDaemonSetupModule* aModule)
-  : mModule(aModule)
-{ }
-
-BluetoothDaemonSetupInterface::~BluetoothDaemonSetupInterface()
-{ }
-
-void
-BluetoothDaemonSetupInterface::RegisterModule(
-  BluetoothSetupServiceId aId, uint8_t aMode, uint32_t aMaxNumClients,
-  BluetoothSetupResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->RegisterModuleCmd(aId, aMode, aMaxNumClients, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonSetupInterface::UnregisterModule(
-  BluetoothSetupServiceId aId,
-  BluetoothSetupResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->UnregisterModuleCmd(aId, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonSetupInterface::Configuration(
-  const BluetoothConfigurationParameter* aParam, uint8_t aLen,
-  BluetoothSetupResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ConfigurationCmd(aParam, aLen, aRes);
-  if (NS_FAILED(rv)) {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonSetupInterface::DispatchError(
-  BluetoothSetupResultHandler* aRes, BluetoothStatus aStatus)
-{
-  DaemonResultRunnable1<BluetoothSetupResultHandler, void,
-                        BluetoothStatus, BluetoothStatus>::Dispatch(
-    aRes, &BluetoothSetupResultHandler::OnError,
-    ConstantInitOp1<BluetoothStatus>(aStatus));
-}
-
-void
-BluetoothDaemonSetupInterface::DispatchError(
-  BluetoothSetupResultHandler* aRes, nsresult aRv)
-{
-  BluetoothStatus status;
-
-  if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
-    status = STATUS_FAIL;
-  }
-  DispatchError(aRes, status);
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonSetupInterface.h
+++ /dev/null
@@ -1,117 +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_BluetoothDaemonSetupInterface_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothDaemonSetupInterface_h
-
-#include "BluetoothDaemonHelpers.h"
-#include "BluetoothInterface.h"
-#include "mozilla/ipc/DaemonRunnables.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using mozilla::ipc::DaemonSocketPDU;
-using mozilla::ipc::DaemonSocketPDUHeader;
-using mozilla::ipc::DaemonSocketResultHandler;
-
-class BluetoothDaemonSetupModule
-{
-public:
-  enum {
-    SERVICE_ID = 0x00
-  };
-
-  enum {
-    OPCODE_ERROR = 0x00,
-    OPCODE_REGISTER_MODULE = 0x01,
-    OPCODE_UNREGISTER_MODULE = 0x02,
-    OPCODE_CONFIGURATION = 0x03
-  };
-
-  virtual nsresult Send(DaemonSocketPDU* aPDU,
-                        DaemonSocketResultHandler* aRes) = 0;
-
-  // Commands
-  //
-
-  nsresult RegisterModuleCmd(BluetoothSetupServiceId aId, uint8_t aMode,
-                             uint32_t aMaxNumClients,
-                             BluetoothSetupResultHandler* aRes);
-
-  nsresult UnregisterModuleCmd(BluetoothSetupServiceId aId,
-                               BluetoothSetupResultHandler* aRes);
-
-  nsresult ConfigurationCmd(const BluetoothConfigurationParameter* aParam,
-                            uint8_t aLen, BluetoothSetupResultHandler* aRes);
-
-protected:
-
-  void HandleSvc(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes);
-
-private:
-
-  // Responses
-  //
-
-  typedef mozilla::ipc::DaemonResultRunnable0<
-    BluetoothSetupResultHandler, void>
-    ResultRunnable;
-
-  typedef mozilla::ipc::DaemonResultRunnable1<
-    BluetoothSetupResultHandler, void, BluetoothStatus, BluetoothStatus>
-    ErrorRunnable;
-
-  void
-  ErrorRsp(const DaemonSocketPDUHeader& aHeader,
-           DaemonSocketPDU& aPDU,
-           BluetoothSetupResultHandler* aRes);
-
-  void
-  RegisterModuleRsp(const DaemonSocketPDUHeader& aHeader,
-                    DaemonSocketPDU& aPDU,
-                    BluetoothSetupResultHandler* aRes);
-
-  void
-  UnregisterModuleRsp(const DaemonSocketPDUHeader& aHeader,
-                      DaemonSocketPDU& aPDU,
-                      BluetoothSetupResultHandler* aRes);
-
-  void
-  ConfigurationRsp(const DaemonSocketPDUHeader& aHeader,
-                   DaemonSocketPDU& aPDU,
-                   BluetoothSetupResultHandler* aRes);
-};
-
-class BluetoothDaemonSetupInterface final
-  : public BluetoothSetupInterface
-{
-public:
-  BluetoothDaemonSetupInterface(BluetoothDaemonSetupModule* aModule);
-  ~BluetoothDaemonSetupInterface();
-
-  void RegisterModule(BluetoothSetupServiceId aId, uint8_t aMode,
-                      uint32_t aMaxNumClients,
-                      BluetoothSetupResultHandler* aRes) override;
-
-  void UnregisterModule(BluetoothSetupServiceId aId,
-                        BluetoothSetupResultHandler* aRes) override;
-
-  void Configuration(const BluetoothConfigurationParameter* aParam,
-                     uint8_t aLen,
-                     BluetoothSetupResultHandler* aRes) override;
-
-private:
-  void DispatchError(BluetoothSetupResultHandler* aRes,
-                     BluetoothStatus aStatus);
-  void DispatchError(BluetoothSetupResultHandler* aRes, nsresult aRv);
-
-  BluetoothDaemonSetupModule* mModule;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothDaemonSetupInterface_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.cpp
+++ /dev/null
@@ -1,399 +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 "BluetoothDaemonSocketInterface.h"
-#include "BluetoothSocketMessageWatcher.h"
-#include "mozilla/UniquePtr.h"
-#include "mozilla/Unused.h"
-#include "nsXULAppAPI.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using namespace mozilla::ipc;
-
-//
-// Socket module
-//
-
-const int BluetoothDaemonSocketModule::MAX_NUM_CLIENTS = 1;
-
-// Commands
-//
-
-nsresult
-BluetoothDaemonSocketModule::ListenCmd(BluetoothSocketType aType,
-                                       const BluetoothServiceName& aServiceName,
-                                       const BluetoothUuid& aServiceUuid,
-                                       int aChannel, bool aEncrypt,
-                                       bool aAuth,
-                                       BluetoothSocketResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_LISTEN,
-                                0);
-
-  nsresult rv = PackPDU(
-    aType,
-    aServiceName,
-    aServiceUuid,
-    PackConversion<int, int32_t>(aChannel),
-    SocketFlags(aEncrypt, aAuth), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-nsresult
-BluetoothDaemonSocketModule::ConnectCmd(const BluetoothAddress& aBdAddr,
-                                        BluetoothSocketType aType,
-                                        const BluetoothUuid& aServiceUuid,
-                                        int aChannel, bool aEncrypt,
-                                        bool aAuth,
-                                        BluetoothSocketResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  UniquePtr<DaemonSocketPDU> pdu =
-    MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CONNECT,
-                                0);
-
-  nsresult rv = PackPDU(
-    aBdAddr,
-    aType,
-    aServiceUuid,
-    PackConversion<int, int32_t>(aChannel),
-    SocketFlags(aEncrypt, aAuth), *pdu);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = Send(pdu.get(), aRes);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  Unused << pdu.release();
-  return rv;
-}
-
-/* |DeleteTask| deletes a class instance on the I/O thread
- */
-template <typename T>
-class DeleteTask final : public Runnable
-{
-public:
-  DeleteTask(T* aPtr)
-  : mPtr(aPtr)
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    mPtr = nullptr;
-    return NS_OK;
-  }
-
-private:
-  UniquePtr<T> mPtr;
-};
-
-/* |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 BluetoothDaemonSocketModule::AcceptWatcher final
-  : public SocketMessageWatcher
-{
-public:
-  AcceptWatcher(int aFd, BluetoothSocketResultHandler* aRes)
-  : SocketMessageWatcher(aFd, aRes)
-  { }
-
-  void Proceed(BluetoothStatus aStatus) override
-  {
-    if (aStatus == STATUS_SUCCESS) {
-      AcceptResultRunnable::Dispatch(
-        GetResultHandler(), &BluetoothSocketResultHandler::Accept,
-        ConstantInitOp3<int, BluetoothAddress, int>(GetClientFd(),
-                                                    GetBdAddress(),
-                                                    GetConnectionStatus()));
-    } else {
-      ErrorRunnable::Dispatch(GetResultHandler(),
-                              &BluetoothSocketResultHandler::OnError,
-                              ConstantInitOp1<BluetoothStatus>(aStatus));
-    }
-
-    MessageLoopForIO::current()->PostTask(
-      MakeAndAddRef<DeleteTask<AcceptWatcher>>(this));
-  }
-};
-
-nsresult
-BluetoothDaemonSocketModule::AcceptCmd(int aFd,
-                                       BluetoothSocketResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /* receive Bluedroid's socket-setup messages and client fd */
-  XRE_GetIOMessageLoop()->PostTask(
-    MakeAndAddRef<SocketMessageWatcherTask>(new AcceptWatcher(aFd, aRes)));
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonSocketModule::CloseCmd(BluetoothSocketResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /* stop the watcher corresponding to |aRes| */
-  XRE_GetIOMessageLoop()->PostTask(
-    MakeAndAddRef<DeleteSocketMessageWatcherTask>(aRes));
-
-  return NS_OK;
-}
-
-void
-BluetoothDaemonSocketModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
-                                       DaemonSocketPDU& aPDU,
-                                       DaemonSocketResultHandler* aRes)
-{
-  static void (BluetoothDaemonSocketModule::* const HandleRsp[])(
-    const DaemonSocketPDUHeader&,
-    DaemonSocketPDU&,
-    BluetoothSocketResultHandler*) = {
-    [OPCODE_ERROR] = &BluetoothDaemonSocketModule::ErrorRsp,
-    [OPCODE_LISTEN] = &BluetoothDaemonSocketModule::ListenRsp,
-    [OPCODE_CONNECT] = &BluetoothDaemonSocketModule::ConnectRsp
-  };
-
-  if (NS_WARN_IF(MOZ_ARRAY_LENGTH(HandleRsp) <= aHeader.mOpcode) ||
-      NS_WARN_IF(!HandleRsp[aHeader.mOpcode])) {
-    return;
-  }
-
-  RefPtr<BluetoothSocketResultHandler> res =
-    static_cast<BluetoothSocketResultHandler*>(aRes);
-
-  if (!res) {
-    return; // Return early if no result handler has been set
-  }
-
-  (this->*(HandleRsp[aHeader.mOpcode]))(aHeader, aPDU, res);
-}
-
-uint8_t
-BluetoothDaemonSocketModule::SocketFlags(bool aEncrypt, bool aAuth)
-{
-  return (0x01 * aEncrypt) | (0x02 * aAuth);
-}
-
-// Responses
-//
-
-void
-BluetoothDaemonSocketModule::ErrorRsp(const DaemonSocketPDUHeader& aHeader,
-                                      DaemonSocketPDU& aPDU,
-                                      BluetoothSocketResultHandler* aRes)
-{
-  ErrorRunnable::Dispatch(
-    aRes, &BluetoothSocketResultHandler::OnError, UnpackPDUInitOp(aPDU));
-}
-
-class BluetoothDaemonSocketModule::ListenInitOp final : private PDUInitOp
-{
-public:
-  ListenInitOp(DaemonSocketPDU& aPDU)
-  : PDUInitOp(aPDU)
-  { }
-
-  nsresult
-  operator () (int& aArg1) const
-  {
-    DaemonSocketPDU& pdu = GetPDU();
-
-    auto receiveFds = pdu.AcquireFds();
-    if (NS_WARN_IF(receiveFds.Length() == 0)) {
-      return NS_ERROR_ILLEGAL_VALUE;
-    }
-    aArg1 = receiveFds[0];
-
-    if (NS_WARN_IF(aArg1 < 0)) {
-      return NS_ERROR_ILLEGAL_VALUE;
-    }
-    WarnAboutTrailingData();
-    return NS_OK;
-  }
-};
-
-void
-BluetoothDaemonSocketModule::ListenRsp(const DaemonSocketPDUHeader& aHeader,
-                                       DaemonSocketPDU& aPDU,
-                                       BluetoothSocketResultHandler* aRes)
-{
-  ListenResultRunnable::Dispatch(
-    aRes, &BluetoothSocketResultHandler::Listen, ListenInitOp(aPDU));
-}
-
-/* |ConnectWatcher| specializes SocketMessageWatcher for
- * connect operations by reading the socket messages from
- * Bluedroid and forwarding the connected socket to the
- * resource handler.
- */
-class BluetoothDaemonSocketModule::ConnectWatcher final
-  : public SocketMessageWatcher
-{
-public:
-  ConnectWatcher(int aFd, BluetoothSocketResultHandler* aRes)
-  : SocketMessageWatcher(aFd, aRes)
-  { }
-
-  void Proceed(BluetoothStatus aStatus) override
-  {
-    if (aStatus == STATUS_SUCCESS) {
-      ConnectResultRunnable::Dispatch(
-        GetResultHandler(), &BluetoothSocketResultHandler::Connect,
-        ConstantInitOp3<int, BluetoothAddress, int>(GetFd(),
-                                                    GetBdAddress(),
-                                                    GetConnectionStatus()));
-    } else {
-      ErrorRunnable::Dispatch(GetResultHandler(),
-                              &BluetoothSocketResultHandler::OnError,
-                              ConstantInitOp1<BluetoothStatus>(aStatus));
-    }
-
-    MessageLoopForIO::current()->PostTask(
-      MakeAndAddRef<DeleteTask<ConnectWatcher>>(this));
-  }
-};
-
-void
-BluetoothDaemonSocketModule::ConnectRsp(const DaemonSocketPDUHeader& aHeader,
-                                        DaemonSocketPDU& aPDU,
-                                        BluetoothSocketResultHandler* aRes)
-{
-  /* the file descriptor is attached in the PDU's ancillary data */
-  auto receiveFds = aPDU.AcquireFds();
-  if (receiveFds.Length() == 0) {
-    ErrorRunnable::Dispatch(aRes, &BluetoothSocketResultHandler::OnError,
-                            ConstantInitOp1<BluetoothStatus>(STATUS_FAIL));
-    return;
-  }
-  int fd = -1;
-  fd = receiveFds[0];
-  if (fd < 0) {
-    ErrorRunnable::Dispatch(aRes, &BluetoothSocketResultHandler::OnError,
-                            ConstantInitOp1<BluetoothStatus>(STATUS_FAIL));
-    return;
-  }
-
-  /* receive Bluedroid's socket-setup messages */
-  XRE_GetIOMessageLoop()->PostTask(
-    MakeAndAddRef<SocketMessageWatcherTask>(new ConnectWatcher(fd, aRes)));
-}
-
-//
-// Socket interface
-//
-
-BluetoothDaemonSocketInterface::BluetoothDaemonSocketInterface(
-  BluetoothDaemonSocketModule* aModule)
-: mModule(aModule)
-{
-  MOZ_ASSERT(mModule);
-}
-
-BluetoothDaemonSocketInterface::~BluetoothDaemonSocketInterface()
-{ }
-
-void
-BluetoothDaemonSocketInterface::Listen(BluetoothSocketType aType,
-                                       const BluetoothServiceName& aServiceName,
-                                       const BluetoothUuid& aServiceUuid,
-                                       int aChannel, bool aEncrypt,
-                                       bool aAuth,
-                                       BluetoothSocketResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ListenCmd(aType, aServiceName, aServiceUuid,
-                                   aChannel, aEncrypt, aAuth, aRes);
-  if (NS_FAILED(rv))  {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonSocketInterface::Connect(const BluetoothAddress& aBdAddr,
-                                        BluetoothSocketType aType,
-                                        const BluetoothUuid& aServiceUuid,
-                                        int aChannel, bool aEncrypt,
-                                        bool aAuth,
-                                        BluetoothSocketResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->ConnectCmd(aBdAddr, aType, aServiceUuid, aChannel,
-                                    aEncrypt, aAuth, aRes);
-  if (NS_FAILED(rv))  {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonSocketInterface::Accept(int aFd,
-                                    BluetoothSocketResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->AcceptCmd(aFd, aRes);
-  if (NS_FAILED(rv))  {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonSocketInterface::Close(BluetoothSocketResultHandler* aRes)
-{
-  MOZ_ASSERT(mModule);
-
-  nsresult rv = mModule->CloseCmd(aRes);
-  if (NS_FAILED(rv))  {
-    DispatchError(aRes, rv);
-  }
-}
-
-void
-BluetoothDaemonSocketInterface::DispatchError(
-  BluetoothSocketResultHandler* aRes, BluetoothStatus aStatus)
-{
-  DaemonResultRunnable1<BluetoothSocketResultHandler, void,
-                        BluetoothStatus, BluetoothStatus>::Dispatch(
-    aRes, &BluetoothSocketResultHandler::OnError,
-    ConstantInitOp1<BluetoothStatus>(aStatus));
-}
-
-void
-BluetoothDaemonSocketInterface::DispatchError(
-  BluetoothSocketResultHandler* aRes, nsresult aRv)
-{
-  BluetoothStatus status;
-
-  if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
-    status = STATUS_FAIL;
-  }
-  DispatchError(aRes, status);
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.h
+++ /dev/null
@@ -1,140 +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_BluetoothDaemonSocketInterface_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothDaemonSocketInterface_h
-
-#include "BluetoothDaemonHelpers.h"
-#include "BluetoothInterface.h"
-#include "mozilla/ipc/DaemonRunnables.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-using mozilla::ipc::DaemonSocketPDU;
-using mozilla::ipc::DaemonSocketPDUHeader;
-using mozilla::ipc::DaemonSocketResultHandler;
-
-class BluetoothDaemonSocketModule
-{
-public:
-  enum {
-    SERVICE_ID = 0x02
-  };
-
-  enum {
-    OPCODE_ERROR = 0x00,
-    OPCODE_LISTEN = 0x01,
-    OPCODE_CONNECT = 0x02
-  };
-
-  static const int MAX_NUM_CLIENTS;
-
-  virtual nsresult Send(DaemonSocketPDU* aPDU,
-                        DaemonSocketResultHandler* aRes) = 0;
-
-  // Commands
-  //
-
-  nsresult ListenCmd(BluetoothSocketType aType,
-                     const BluetoothServiceName& aServiceName,
-                     const BluetoothUuid& aServiceUuid,
-                     int aChannel, bool aEncrypt, bool aAuth,
-                     BluetoothSocketResultHandler* aRes);
-
-  nsresult ConnectCmd(const BluetoothAddress& aBdAddr,
-                      BluetoothSocketType aType,
-                      const BluetoothUuid& aServiceUuid,
-                      int aChannel, bool aEncrypt, bool aAuth,
-                      BluetoothSocketResultHandler* aRes);
-
-  nsresult AcceptCmd(int aFd, BluetoothSocketResultHandler* aRes);
-
-  nsresult CloseCmd(BluetoothSocketResultHandler* aRes);
-
-protected:
-
-  void HandleSvc(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes);
-
-private:
-  class AcceptWatcher;
-  class ConnectWatcher;
-  class ListenInitOp;
-
-  uint8_t SocketFlags(bool aEncrypt, bool aAuth);
-
-  // Responses
-  //
-
-  typedef mozilla::ipc::DaemonResultRunnable3<
-    BluetoothSocketResultHandler, void, int, BluetoothAddress, int, int,
-    const BluetoothAddress&, int>
-    AcceptResultRunnable;
-
-  typedef mozilla::ipc::DaemonResultRunnable3<
-    BluetoothSocketResultHandler, void, int, BluetoothAddress, int, int,
-    const BluetoothAddress&, int>
-    ConnectResultRunnable;
-
-  typedef mozilla::ipc::DaemonResultRunnable1<
-    BluetoothSocketResultHandler, void, BluetoothStatus, BluetoothStatus>
-    ErrorRunnable;
-
-  typedef mozilla::ipc::DaemonResultRunnable1<
-    BluetoothSocketResultHandler, void, int, int>
-    ListenResultRunnable;
-
-  typedef mozilla::ipc::DaemonResultRunnable0<
-    BluetoothSocketResultHandler, void>
-    ResultRunnable;
-
-  void ErrorRsp(const DaemonSocketPDUHeader& aHeader,
-                DaemonSocketPDU& aPDU,
-                BluetoothSocketResultHandler* aRes);
-
-  void ListenRsp(const DaemonSocketPDUHeader& aHeader,
-                 DaemonSocketPDU& aPDU,
-                 BluetoothSocketResultHandler* aRes);
-
-  void ConnectRsp(const DaemonSocketPDUHeader& aHeader,
-                  DaemonSocketPDU& aPDU,
-                  BluetoothSocketResultHandler* aRes);
-};
-
-class BluetoothDaemonSocketInterface final
-  : public BluetoothSocketInterface
-{
-public:
-  BluetoothDaemonSocketInterface(BluetoothDaemonSocketModule* aModule);
-  ~BluetoothDaemonSocketInterface();
-
-  void Listen(BluetoothSocketType aType,
-              const BluetoothServiceName& aServiceName,
-              const BluetoothUuid& aServiceUuid,
-              int aChannel, bool aEncrypt, bool aAuth,
-              BluetoothSocketResultHandler* aRes) override;
-
-  void Connect(const BluetoothAddress& aBdAddr,
-               BluetoothSocketType aType,
-               const BluetoothUuid& aServiceUuid,
-               int aChannel, bool aEncrypt, bool aAuth,
-               BluetoothSocketResultHandler* aRes) override;
-
-  void Accept(int aFd, BluetoothSocketResultHandler* aRes) override;
-
-  void Close(BluetoothSocketResultHandler* aRes) override;
-
-private:
-  void DispatchError(BluetoothSocketResultHandler* aRes,
-                     BluetoothStatus aStatus);
-  void DispatchError(BluetoothSocketResultHandler* aRes, nsresult aRv);
-
-  BluetoothDaemonSocketModule* mModule;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothDaemonSocketInterface_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothGattManager.cpp
+++ /dev/null
@@ -1,4186 +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 "BluetoothGattManager.h"
-
-#include "BluetoothHashKeys.h"
-#include "BluetoothInterface.h"
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-#include "BluetoothUtils.h"
-#include "MainThreadUtils.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/Services.h"
-#include "mozilla/StaticPtr.h"
-#include "nsDataHashtable.h"
-#include "nsIObserverService.h"
-#include "nsThreadUtils.h"
-
-#define ENSURE_GATT_INTF_IS_READY_VOID(runnable)                              \
-  do {                                                                        \
-    if (NS_WARN_IF(!sBluetoothGattInterface)) {                               \
-      DispatchReplyError(runnable,                                            \
-        NS_LITERAL_STRING("BluetoothGattInterface is not ready"));            \
-        runnable = nullptr;                                                   \
-      return;                                                                 \
-    }                                                                         \
-  } while(0)
-
-#define ENSURE_GATT_INTF_IN_ATTR_DISCOVER(client)                             \
-  do {                                                                        \
-    if (NS_WARN_IF(!sBluetoothGattInterface)) {                               \
-      client->NotifyDiscoverCompleted(false);                                 \
-      return;                                                                 \
-    }                                                                         \
-  } while(0)
-
-using namespace mozilla;
-USING_BLUETOOTH_NAMESPACE
-
-class BluetoothGattServer;
-
-namespace {
-  StaticRefPtr<BluetoothGattManager> sBluetoothGattManager;
-  static BluetoothGattInterface* sBluetoothGattInterface;
-} // namespace
-
-const int BluetoothGattManager::MAX_NUM_CLIENTS = 1;
-
-bool BluetoothGattManager::mInShutdown = false;
-
-static StaticAutoPtr<nsTArray<RefPtr<BluetoothGattClient> > > sClients;
-static StaticAutoPtr<nsTArray<RefPtr<BluetoothGattServer> > > sServers;
-
-struct BluetoothGattClientReadCharState
-{
-  bool mAuthRetry;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-
-  void Assign(bool aAuthRetry,
-              BluetoothReplyRunnable* aRunnable)
-  {
-    mAuthRetry = aAuthRetry;
-    mRunnable = aRunnable;
-  }
-
-  void Reset()
-  {
-    mAuthRetry = false;
-    mRunnable = nullptr;
-  }
-};
-
-struct BluetoothGattClientWriteCharState
-{
-  BluetoothGattWriteType mWriteType;
-  nsTArray<uint8_t> mWriteValue;
-  bool mAuthRetry;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-
-  void Assign(BluetoothGattWriteType aWriteType,
-              const nsTArray<uint8_t>& aWriteValue,
-              bool aAuthRetry,
-              BluetoothReplyRunnable* aRunnable)
-  {
-    mWriteType = aWriteType;
-    mWriteValue = aWriteValue;
-    mAuthRetry = aAuthRetry;
-    mRunnable = aRunnable;
-  }
-
-  void Reset()
-  {
-    mWriteType = GATT_WRITE_TYPE_NORMAL;
-    mWriteValue.Clear();
-    mAuthRetry = false;
-    mRunnable = nullptr;
-  }
-};
-
-struct BluetoothGattClientReadDescState
-{
-  bool mAuthRetry;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-
-  void Assign(bool aAuthRetry,
-              BluetoothReplyRunnable* aRunnable)
-  {
-    mAuthRetry = aAuthRetry;
-    mRunnable = aRunnable;
-  }
-
-  void Reset()
-  {
-    mAuthRetry = false;
-    mRunnable = nullptr;
-  }
-};
-
-struct BluetoothGattClientWriteDescState
-{
-  nsTArray<uint8_t> mWriteValue;
-  bool mAuthRetry;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-
-  void Assign(const nsTArray<uint8_t>& aWriteValue,
-              bool aAuthRetry,
-              BluetoothReplyRunnable* aRunnable)
-  {
-    mWriteValue = aWriteValue;
-    mAuthRetry = aAuthRetry;
-    mRunnable = aRunnable;
-  }
-
-  void Reset()
-  {
-    mWriteValue.Clear();
-    mAuthRetry = false;
-    mRunnable = nullptr;
-  }
-};
-
-class mozilla::dom::bluetooth::BluetoothGattClient final : public nsISupports
-{
-public:
-  NS_DECL_ISUPPORTS
-
-  BluetoothGattClient(const BluetoothUuid& aAppUuid,
-                      const BluetoothAddress& aDeviceAddr)
-    : mAppUuid(aAppUuid)
-    , mDeviceAddr(aDeviceAddr)
-    , mClientIf(0)
-    , mConnId(0)
-  { }
-
-  void NotifyDiscoverCompleted(bool aSuccess)
-  {
-    MOZ_ASSERT(!mAppUuid.IsCleared());
-    MOZ_ASSERT(mDiscoverRunnable);
-
-    BluetoothService* bs = BluetoothService::Get();
-    NS_ENSURE_TRUE_VOID(bs);
-
-    // Notify application to clear the cache values of
-    // service/characteristic/descriptor.
-    bs->DistributeSignal(NS_LITERAL_STRING("DiscoverCompleted"),
-                         mAppUuid,
-                         BluetoothValue(aSuccess));
-
-    // Resolve/Reject the Promise.
-    if (aSuccess) {
-      DispatchReplySuccess(mDiscoverRunnable);
-    } else {
-      DispatchReplyError(mDiscoverRunnable,
-                         NS_LITERAL_STRING("Discover failed"));
-    }
-
-    // Cleanup
-    mServices.Clear();
-    mIncludedServices.Clear();
-    mCharacteristics.Clear();
-    mDescriptors.Clear();
-    mDiscoverRunnable = nullptr;
-  }
-
-  BluetoothUuid mAppUuid;
-  BluetoothAddress mDeviceAddr;
-  int mClientIf;
-  int mConnId;
-  RefPtr<BluetoothReplyRunnable> mStartLeScanRunnable;
-  RefPtr<BluetoothReplyRunnable> mStartAdvertisingRunnable;
-  RefPtr<BluetoothReplyRunnable> mStopAdvertisingRunnable;
-  RefPtr<BluetoothReplyRunnable> mConnectRunnable;
-  RefPtr<BluetoothReplyRunnable> mDisconnectRunnable;
-  RefPtr<BluetoothReplyRunnable> mDiscoverRunnable;
-  RefPtr<BluetoothReplyRunnable> mReadRemoteRssiRunnable;
-  RefPtr<BluetoothReplyRunnable> mRegisterNotificationsRunnable;
-  RefPtr<BluetoothReplyRunnable> mDeregisterNotificationsRunnable;
-  RefPtr<BluetoothReplyRunnable> mUnregisterClientRunnable;
-
-  BluetoothGattClientReadCharState mReadCharacteristicState;
-  BluetoothGattClientWriteCharState mWriteCharacteristicState;
-  BluetoothGattClientReadDescState mReadDescriptorState;
-  BluetoothGattClientWriteDescState mWriteDescriptorState;
-
-  BluetoothGattAdvertisingData mAdvertisingData;
-
-  /**
-   * These temporary arrays are used only during discover operations.
-   * All of them are empty if there are no ongoing discover operations.
-   */
-  nsTArray<BluetoothGattServiceId> mServices;
-  nsTArray<BluetoothGattServiceId> mIncludedServices;
-  nsTArray<BluetoothGattCharAttribute> mCharacteristics;
-  nsTArray<BluetoothGattId> mDescriptors;
-
-private:
-  ~BluetoothGattClient()
-  { }
-};
-
-NS_IMPL_ISUPPORTS0(BluetoothGattClient)
-
-struct BluetoothGattServerAddServiceState
-{
-  BluetoothGattServiceId mServiceId;
-  uint16_t mHandleCount;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-
-  void Assign(const BluetoothGattServiceId& aServiceId,
-              uint16_t aHandleCount,
-              BluetoothReplyRunnable* aRunnable)
-  {
-    mServiceId = aServiceId;
-    mHandleCount = aHandleCount;
-    mRunnable = aRunnable;
-  }
-
-  void Reset()
-  {
-    memset(&mServiceId, 0, sizeof(mServiceId));
-    mHandleCount = 0;
-    mRunnable = nullptr;
-  }
-};
-
-struct BluetoothGattServerAddDescriptorState
-{
-  BluetoothAttributeHandle mServiceHandle;
-  BluetoothAttributeHandle mCharacteristicHandle;
-  BluetoothUuid mDescriptorUuid;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-
-  void Assign(const BluetoothAttributeHandle& aServiceHandle,
-              const BluetoothAttributeHandle& aCharacteristicHandle,
-              const BluetoothUuid& aDescriptorUuid,
-              BluetoothReplyRunnable* aRunnable)
-  {
-    mServiceHandle = aServiceHandle;
-    mCharacteristicHandle = aCharacteristicHandle;
-    mDescriptorUuid = aDescriptorUuid;
-    mRunnable = aRunnable;
-  }
-
-  void Reset()
-  {
-    memset(&mServiceHandle, 0, sizeof(mServiceHandle));
-    memset(&mCharacteristicHandle, 0, sizeof(mCharacteristicHandle));
-    mDescriptorUuid.Clear();
-    mRunnable = nullptr;
-  }
-};
-
-class BluetoothGattServer final : public nsISupports
-{
-public:
-  NS_DECL_ISUPPORTS
-
-  BluetoothGattServer(const BluetoothUuid& aAppUuid)
-    : mAppUuid(aAppUuid)
-    , mServerIf(0)
-    , mIsRegistering(false)
-  { }
-
-  BluetoothUuid mAppUuid;
-  int mServerIf;
-
-  /*
-   * Some actions will trigger the registration procedure:
-   *  - Connect the GATT server to a peripheral client
-   *  - Add a service to the GATT server
-   * These actions will be taken only after the registration has been done
-   * successfully. If the registration fails, all the existing actions above
-   * should be rejected.
-   */
-  bool mIsRegistering;
-
-  RefPtr<BluetoothReplyRunnable> mRegisterServerRunnable;
-  RefPtr<BluetoothReplyRunnable> mConnectPeripheralRunnable;
-  RefPtr<BluetoothReplyRunnable> mDisconnectPeripheralRunnable;
-  RefPtr<BluetoothReplyRunnable> mUnregisterServerRunnable;
-
-  BluetoothGattServerAddServiceState mAddServiceState;
-  RefPtr<BluetoothReplyRunnable> mAddIncludedServiceRunnable;
-  RefPtr<BluetoothReplyRunnable> mAddCharacteristicRunnable;
-  BluetoothGattServerAddDescriptorState mAddDescriptorState;
-  RefPtr<BluetoothReplyRunnable> mRemoveServiceRunnable;
-  RefPtr<BluetoothReplyRunnable> mStartServiceRunnable;
-  RefPtr<BluetoothReplyRunnable> mStopServiceRunnable;
-  RefPtr<BluetoothReplyRunnable> mSendResponseRunnable;
-  RefPtr<BluetoothReplyRunnable> mSendIndicationRunnable;
-
-  // Map connection id from device address
-  nsDataHashtable<BluetoothAddressHashKey, int> mConnectionMap;
-private:
-  ~BluetoothGattServer()
-  { }
-};
-
-NS_IMPL_ISUPPORTS0(BluetoothGattServer)
-
-class UuidComparator
-{
-public:
-  bool Equals(const RefPtr<BluetoothGattClient>& aClient,
-              const BluetoothUuid& aAppUuid) const
-  {
-    return aClient->mAppUuid == aAppUuid;
-  }
-
-  bool Equals(const RefPtr<BluetoothGattServer>& aServer,
-              const BluetoothUuid& aAppUuid) const
-  {
-    return aServer->mAppUuid == aAppUuid;
-  }
-};
-
-class InterfaceIdComparator
-{
-public:
-  bool Equals(const RefPtr<BluetoothGattClient>& aClient,
-              int aClientIf) const
-  {
-    return aClient->mClientIf == aClientIf;
-  }
-
-  bool Equals(const RefPtr<BluetoothGattServer>& aServer,
-              int aServerIf) const
-  {
-    return aServer->mServerIf == aServerIf;
-  }
-};
-
-class ConnIdComparator
-{
-public:
-  bool Equals(const RefPtr<BluetoothGattClient>& aClient,
-              int aConnId) const
-  {
-    return aClient->mConnId == aConnId;
-  }
-
-  bool Equals(const RefPtr<BluetoothGattServer>& aServer,
-              int aConnId) const
-  {
-    for (
-      auto iter = aServer->mConnectionMap.Iter(); !iter.Done(); iter.Next()) {
-      if (aConnId == iter.Data()) {
-        return true;
-      }
-    }
-    return false;
-  }
-};
-
-BluetoothGattManager*
-BluetoothGattManager::Get()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // If sBluetoothGattManager already exists, exit early
-  if (sBluetoothGattManager) {
-    return sBluetoothGattManager;
-  }
-
-  // If we're in shutdown, don't create a new instance
-  NS_ENSURE_FALSE(mInShutdown, nullptr);
-
-  // Create a new instance, register, and return
-  RefPtr<BluetoothGattManager> manager = new BluetoothGattManager();
-  NS_ENSURE_SUCCESS(manager->Init(), nullptr);
-
-  sBluetoothGattManager = manager;
-
-  return sBluetoothGattManager;
-}
-
-nsresult
-BluetoothGattManager::Init()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE(obs, NS_ERROR_NOT_AVAILABLE);
-
-  auto rv = obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("Failed to add observers!");
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-void
-BluetoothGattManager::Uninit()
-{
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-  if (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID))) {
-    BT_WARNING("Failed to remove shutdown observer!");
-  }
-}
-
-class BluetoothGattManager::RegisterModuleResultHandler final
-  : public BluetoothSetupResultHandler
-{
-public:
-  RegisterModuleResultHandler(BluetoothGattInterface* aInterface,
-                              BluetoothProfileResultHandler* aRes)
-    : mInterface(aInterface)
-    , mRes(aRes)
-  { }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_WARNING("BluetoothSetupInterface::RegisterModule failed for GATT: %d",
-               (int)aStatus);
-
-    mInterface->SetNotificationHandler(nullptr);
-
-    if (mRes) {
-      mRes->OnError(NS_ERROR_FAILURE);
-    }
-  }
-
-  void RegisterModule() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    sBluetoothGattInterface = mInterface;
-
-    if (mRes) {
-      mRes->Init();
-    }
-  }
-
-private:
-  BluetoothGattInterface* mInterface;
-  RefPtr<BluetoothProfileResultHandler> mRes;
-};
-
-class BluetoothGattManager::InitProfileResultHandlerRunnable final
-  : public Runnable
-{
-public:
-  InitProfileResultHandlerRunnable(BluetoothProfileResultHandler* aRes,
-                                   nsresult aRv)
-    : mRes(aRes)
-    , mRv(aRv)
-  {
-    MOZ_ASSERT(mRes);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (NS_SUCCEEDED(mRv)) {
-      mRes->Init();
-    } else {
-      mRes->OnError(mRv);
-    }
-    return NS_OK;
-  }
-
-private:
-  RefPtr<BluetoothProfileResultHandler> mRes;
-  nsresult mRv;
-};
-
-// static
-void
-BluetoothGattManager::InitGattInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (sBluetoothGattInterface) {
-    BT_LOGR("Bluetooth GATT interface is already initalized.");
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_OK);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch GATT Init runnable");
-    }
-    return;
-  }
-
-  auto btInf = BluetoothInterface::GetInstance();
-
-  if (NS_WARN_IF(!btInf)) {
-    // If there's no Bluetooth interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch GATT OnError runnable");
-    }
-    return;
-  }
-
-  auto setupInterface = btInf->GetBluetoothSetupInterface();
-
-  if (NS_WARN_IF(!setupInterface)) {
-    // If there's no Setup interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch GATT OnError runnable");
-    }
-    return;
-  }
-
-  auto gattInterface = btInf->GetBluetoothGattInterface();
-
-  if (NS_WARN_IF(!gattInterface)) {
-    // If there's no GATT interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch GATT OnError runnable");
-    }
-    return;
-  }
-
-  if (!sClients) {
-    sClients = new nsTArray<RefPtr<BluetoothGattClient> >;
-  }
-
-  if (!sServers) {
-    sServers = new nsTArray<RefPtr<BluetoothGattServer> >;
-  }
-
-  // Set notification handler _before_ registering the module. It could
-  // happen that we receive notifications, before the result handler runs.
-  gattInterface->SetNotificationHandler(BluetoothGattManager::Get());
-
-  setupInterface->RegisterModule(
-    SETUP_SERVICE_ID_GATT, 0, MAX_NUM_CLIENTS,
-    new RegisterModuleResultHandler(gattInterface, aRes));
-}
-
-class BluetoothGattManager::UnregisterModuleResultHandler final
-  : public BluetoothSetupResultHandler
-{
-public:
-  UnregisterModuleResultHandler(BluetoothProfileResultHandler* aRes)
-    : mRes(aRes)
-  { }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_WARNING("BluetoothSetupInterface::UnregisterModule failed for GATT: %d",
-               (int)aStatus);
-
-    sBluetoothGattInterface->SetNotificationHandler(nullptr);
-    sBluetoothGattInterface = nullptr;
-    sClients = nullptr;
-    sServers = nullptr;
-
-    sBluetoothGattManager->Uninit();
-    sBluetoothGattManager = nullptr;
-
-    if (mRes) {
-      mRes->OnError(NS_ERROR_FAILURE);
-    }
-  }
-
-  void UnregisterModule() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    sBluetoothGattInterface->SetNotificationHandler(nullptr);
-    sBluetoothGattInterface = nullptr;
-    sClients = nullptr;
-    sServers = nullptr;
-
-    sBluetoothGattManager->Uninit();
-    sBluetoothGattManager = nullptr;
-
-    if (mRes) {
-      mRes->Deinit();
-    }
-  }
-
-private:
-  RefPtr<BluetoothProfileResultHandler> mRes;
-};
-
-class BluetoothGattManager::DeinitProfileResultHandlerRunnable final
-  : public Runnable
-{
-public:
-  DeinitProfileResultHandlerRunnable(BluetoothProfileResultHandler* aRes,
-                                     nsresult aRv)
-    : mRes(aRes)
-    , mRv(aRv)
-  {
-    MOZ_ASSERT(mRes);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (NS_SUCCEEDED(mRv)) {
-      mRes->Deinit();
-    } else {
-      mRes->OnError(mRv);
-    }
-    return NS_OK;
-  }
-
-private:
-  RefPtr<BluetoothProfileResultHandler> mRes;
-  nsresult mRv;
-};
-
-// static
-void
-BluetoothGattManager::DeinitGattInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!sBluetoothGattInterface) {
-    BT_LOGR("Bluetooth GATT interface has not been initalized.");
-    RefPtr<Runnable> r =
-      new DeinitProfileResultHandlerRunnable(aRes, NS_OK);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch GATT Deinit runnable");
-    }
-    return;
-  }
-
-  auto btInf = BluetoothInterface::GetInstance();
-
-  if (NS_WARN_IF(!btInf)) {
-    // If there's no backend interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new DeinitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch GATT OnError runnable");
-    }
-    return;
-  }
-
-  auto setupInterface = btInf->GetBluetoothSetupInterface();
-
-  if (NS_WARN_IF(!setupInterface)) {
-    // If there's no Setup interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new DeinitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch GATT OnError runnable");
-    }
-    return;
-  }
-
-  setupInterface->UnregisterModule(
-    SETUP_SERVICE_ID_GATT,
-    new UnregisterModuleResultHandler(aRes));
-}
-
-class BluetoothGattManager::RegisterClientResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  RegisterClientResultHandler(BluetoothGattClient* aClient)
-  : mClient(aClient)
-  {
-    MOZ_ASSERT(mClient);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattInterface::RegisterClient failed: %d",
-               (int)aStatus);
-
-    BluetoothService* bs = BluetoothService::Get();
-    NS_ENSURE_TRUE_VOID(bs);
-
-    // Notify BluetoothGatt for client disconnected
-    bs->DistributeSignal(
-      NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID),
-      mClient->mAppUuid,
-      BluetoothValue(false)); // Disconnected
-
-    // Reject the connect request
-    if (mClient->mConnectRunnable) {
-      DispatchReplyError(mClient->mConnectRunnable,
-                         NS_LITERAL_STRING("Register GATT client failed"));
-      mClient->mConnectRunnable = nullptr;
-    }
-
-    sClients->RemoveElement(mClient);
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-class BluetoothGattManager::UnregisterClientResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  UnregisterClientResultHandler(BluetoothGattClient* aClient)
-  : mClient(aClient)
-  {
-    MOZ_ASSERT(mClient);
-  }
-
-  void UnregisterClient() override
-  {
-    MOZ_ASSERT(mClient->mUnregisterClientRunnable);
-    BluetoothService* bs = BluetoothService::Get();
-    NS_ENSURE_TRUE_VOID(bs);
-
-    // Notify BluetoothGatt to clear the clientIf
-    bs->DistributeSignal(NS_LITERAL_STRING("ClientUnregistered"),
-                         mClient->mAppUuid);
-
-    // Resolve the unregister request
-    DispatchReplySuccess(mClient->mUnregisterClientRunnable);
-    mClient->mUnregisterClientRunnable = nullptr;
-
-    sClients->RemoveElement(mClient);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattInterface::UnregisterClient failed: %d",
-               (int)aStatus);
-    MOZ_ASSERT(mClient->mUnregisterClientRunnable);
-
-    // Reject the unregister request
-    DispatchReplyError(mClient->mUnregisterClientRunnable,
-                       NS_LITERAL_STRING("Unregister GATT client failed"));
-    mClient->mUnregisterClientRunnable = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-void
-BluetoothGattManager::UnregisterClient(int aClientIf,
-                                       BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sClients->IndexOf(aClientIf, 0 /* Start */,
-                                   InterfaceIdComparator());
-  if (NS_WARN_IF(index == sClients->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-  client->mUnregisterClientRunnable = aRunnable;
-
-  sBluetoothGattInterface->UnregisterClient(
-    aClientIf,
-    new UnregisterClientResultHandler(client));
-}
-
-class BluetoothGattManager::StartLeScanResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  StartLeScanResultHandler(BluetoothGattClient* aClient)
-    : mClient(aClient)
-  { }
-
-  void Scan() override
-  {
-    MOZ_ASSERT(mClient > 0);
-
-    DispatchReplySuccess(mClient->mStartLeScanRunnable,
-                         BluetoothValue(mClient->mAppUuid));
-    mClient->mStartLeScanRunnable = nullptr;
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattInterface::StartLeScan failed: %d",
-               (int)aStatus);
-    MOZ_ASSERT(mClient->mStartLeScanRunnable);
-
-    // Unregister client if startLeScan failed
-    if (mClient->mClientIf > 0) {
-      BluetoothGattManager* gattManager = BluetoothGattManager::Get();
-      NS_ENSURE_TRUE_VOID(gattManager);
-
-      RefPtr<BluetoothVoidReplyRunnable> result =
-        new BluetoothVoidReplyRunnable(nullptr);
-      gattManager->UnregisterClient(mClient->mClientIf, result);
-    }
-
-    DispatchReplyError(mClient->mStartLeScanRunnable, aStatus);
-    mClient->mStartLeScanRunnable = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-class BluetoothGattManager::StopLeScanResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-   StopLeScanResultHandler(BluetoothReplyRunnable* aRunnable, int aClientIf)
-     : mRunnable(aRunnable), mClientIf(aClientIf)
-  { }
-
-  void Scan() override
-  {
-    DispatchReplySuccess(mRunnable);
-
-    // Unregister client when stopLeScan succeeded
-    if (mClientIf > 0) {
-      BluetoothGattManager* gattManager = BluetoothGattManager::Get();
-      NS_ENSURE_TRUE_VOID(gattManager);
-
-      RefPtr<BluetoothVoidReplyRunnable> result =
-        new BluetoothVoidReplyRunnable(nullptr);
-      gattManager->UnregisterClient(mClientIf, result);
-    }
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattInterface::StopLeScan failed: %d",
-                (int)aStatus);
-    DispatchReplyError(mRunnable, aStatus);
-  }
-
-private:
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-  int mClientIf;
-};
-
-void
-BluetoothGattManager::StartLeScan(const nsTArray<BluetoothUuid>& aServiceUuids,
-                                  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  BluetoothUuid appUuid;
-  if (NS_WARN_IF(NS_FAILED(GenerateUuid(appUuid)))) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("start LE scan failed"));
-    return;
-  }
-
-  size_t index = sClients->IndexOf(appUuid, 0 /* Start */, UuidComparator());
-
-  // Reject the startLeScan request if the clientIf is being used.
-  if (NS_WARN_IF(index != sClients->NoIndex)) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("start LE scan failed"));
-    return;
-  }
-
-  index = sClients->Length();
-  sClients->AppendElement(new BluetoothGattClient(appUuid,
-                                                  BluetoothAddress::ANY()));
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-  client->mStartLeScanRunnable = aRunnable;
-
-  // 'startLeScan' will be proceeded after client registered
-  sBluetoothGattInterface->RegisterClient(
-    appUuid, new RegisterClientResultHandler(client));
-}
-
-void
-BluetoothGattManager::StopLeScan(const BluetoothUuid& aScanUuid,
-                                 BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sClients->IndexOf(aScanUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sClients->NoIndex)) {
-    // Reject the stop LE scan request
-    DispatchReplyError(aRunnable, NS_LITERAL_STRING("StopLeScan failed"));
-    return;
-  }
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-  sBluetoothGattInterface->Scan(
-    client->mClientIf,
-    false /* Stop */,
-    new StopLeScanResultHandler(aRunnable, client->mClientIf));
-}
-
-class BluetoothGattManager::StartAdvertisingResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  StartAdvertisingResultHandler(BluetoothGattClient* aClient)
-    : mClient(aClient)
-  {
-    MOZ_ASSERT(mClient);
-  }
-
-  void Listen() override
-  {
-    MOZ_ASSERT(mClient->mStartAdvertisingRunnable);
-
-    DispatchReplySuccess(mClient->mStartAdvertisingRunnable);
-    mClient->mStartAdvertisingRunnable = nullptr;
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattInterface::StartLeAdvertising failed: %d",
-               (int)aStatus);
-    MOZ_ASSERT(mClient->mStartAdvertisingRunnable);
-
-    // Unregister client if startAdvertising failed
-    if (mClient->mClientIf > 0) {
-      BluetoothGattManager* gattManager = BluetoothGattManager::Get();
-      NS_ENSURE_TRUE_VOID(gattManager);
-
-      RefPtr<BluetoothVoidReplyRunnable> result =
-        new BluetoothVoidReplyRunnable(nullptr);
-      gattManager->UnregisterClient(mClient->mClientIf, result);
-    }
-
-    DispatchReplyError(mClient->mStartAdvertisingRunnable, aStatus);
-    mClient->mStartAdvertisingRunnable = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-class BluetoothGattManager::SetAdvDataResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  SetAdvDataResultHandler(BluetoothGattClient* aClient)
-    : mClient(aClient)
-  {
-    MOZ_ASSERT(mClient);
-  }
-
-  void SetAdvData() override
-  {
-    sBluetoothGattInterface->Listen(
-      mClient->mClientIf,
-      true /* Start */,
-      new StartAdvertisingResultHandler(mClient));
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattInterface::StartLeAdvertising failed: %d",
-               (int)aStatus);
-    MOZ_ASSERT(mClient->mStartAdvertisingRunnable);
-
-    // Unregister client if startAdvertising failed
-    if (mClient->mClientIf > 0) {
-      BluetoothGattManager* gattManager = BluetoothGattManager::Get();
-      NS_ENSURE_TRUE_VOID(gattManager);
-
-      RefPtr<BluetoothVoidReplyRunnable> result =
-        new BluetoothVoidReplyRunnable(nullptr);
-      gattManager->UnregisterClient(mClient->mClientIf, result);
-    }
-
-    DispatchReplyError(mClient->mStartAdvertisingRunnable, aStatus);
-    mClient->mStartAdvertisingRunnable = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-void
-BluetoothGattManager::StartAdvertising(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattAdvertisingData& aData,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-
-  // Reject the startAdvertising request if the clientIf is being used.
-  if (NS_WARN_IF(index != sClients->NoIndex)) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("start advertising failed"));
-    return;
-  }
-
-  index = sClients->Length();
-  sClients->AppendElement(new BluetoothGattClient(aAppUuid,
-                                                  BluetoothAddress::ANY()));
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-  client->mStartAdvertisingRunnable = aRunnable;
-  client->mAdvertisingData = aData;
-
-  // 'startAdvertising' will be proceeded after client registered
-  sBluetoothGattInterface->RegisterClient(
-    aAppUuid, new RegisterClientResultHandler(client));
-}
-
-class BluetoothGattManager::StopAdvertisingResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-   StopAdvertisingResultHandler(BluetoothGattClient* aClient)
-     : mClient(aClient)
-  {
-    MOZ_ASSERT(mClient);
-  }
-
-  void Listen() override
-  {
-    MOZ_ASSERT(mClient->mStopAdvertisingRunnable);
-
-    // Unregister client when stopLeScan succeeded
-    if (mClient->mClientIf > 0) {
-      BluetoothGattManager* gattManager = BluetoothGattManager::Get();
-      NS_ENSURE_TRUE_VOID(gattManager);
-
-      RefPtr<BluetoothVoidReplyRunnable> result =
-        new BluetoothVoidReplyRunnable(nullptr);
-      gattManager->UnregisterClient(mClient->mClientIf, result);
-    }
-
-    DispatchReplySuccess(mClient->mStopAdvertisingRunnable);
-    mClient->mStopAdvertisingRunnable = nullptr;
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattInterface::StopAdvertising failed: %d",
-                (int)aStatus);
-    MOZ_ASSERT(mClient->mStopAdvertisingRunnable);
-
-    DispatchReplyError(mClient->mStopAdvertisingRunnable, aStatus);
-    mClient->mStopAdvertisingRunnable = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-void
-BluetoothGattManager::StopAdvertising(const BluetoothUuid& aAppUuid,
-                                      BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sClients->NoIndex)) {
-    // Reject the stop advertising request
-    DispatchReplyError(aRunnable, NS_LITERAL_STRING("StopAdvertising failed"));
-    return;
-  }
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  // Reject the stop advertising request if there is an ongoing one.
-  if (client->mStopAdvertisingRunnable) {
-    DispatchReplyError(aRunnable, STATUS_BUSY);
-    return;
-  }
-
-  client->mStopAdvertisingRunnable = aRunnable;
-  sBluetoothGattInterface->Listen(
-    client->mClientIf,
-    false /* Stop */,
-    new StopAdvertisingResultHandler(client));
-}
-
-class BluetoothGattManager::ConnectResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  ConnectResultHandler(BluetoothGattClient* aClient)
-  : mClient(aClient)
-  {
-    MOZ_ASSERT(mClient);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattInterface::Connect failed: %d",
-               (int)aStatus);
-    MOZ_ASSERT(mClient->mConnectRunnable);
-
-    BluetoothService* bs = BluetoothService::Get();
-    NS_ENSURE_TRUE_VOID(bs);
-
-    // Notify BluetoothGatt for client disconnected
-    bs->DistributeSignal(
-      NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID),
-      mClient->mAppUuid,
-      BluetoothValue(false)); // Disconnected
-
-    // Reject the connect request
-    DispatchReplyError(mClient->mConnectRunnable,
-                       NS_LITERAL_STRING("Connect failed"));
-    mClient->mConnectRunnable = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-void
-BluetoothGattManager::Connect(const BluetoothUuid& aAppUuid,
-                              const BluetoothAddress& aDeviceAddr,
-                              BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (index == sClients->NoIndex) {
-    index = sClients->Length();
-    sClients->AppendElement(new BluetoothGattClient(aAppUuid, aDeviceAddr));
-  }
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-  client->mConnectRunnable = aRunnable;
-
-  if (client->mClientIf > 0) {
-    sBluetoothGattInterface->Connect(client->mClientIf,
-                                     aDeviceAddr,
-                                     true, // direct connect
-                                     TRANSPORT_AUTO,
-                                     new ConnectResultHandler(client));
-  } else {
-    // connect will be proceeded after client registered
-    sBluetoothGattInterface->RegisterClient(
-      aAppUuid, new RegisterClientResultHandler(client));
-  }
-}
-
-class BluetoothGattManager::DisconnectResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  DisconnectResultHandler(BluetoothGattClient* aClient)
-  : mClient(aClient)
-  {
-    MOZ_ASSERT(mClient);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattInterface::Disconnect failed: %d",
-               (int)aStatus);
-    MOZ_ASSERT(mClient->mDisconnectRunnable);
-
-    BluetoothService* bs = BluetoothService::Get();
-    NS_ENSURE_TRUE_VOID(bs);
-
-    // Notify BluetoothGatt that the client remains connected
-    bs->DistributeSignal(
-      NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID),
-      mClient->mAppUuid,
-      BluetoothValue(true)); // Connected
-
-    // Reject the disconnect request
-    DispatchReplyError(mClient->mDisconnectRunnable,
-                       NS_LITERAL_STRING("Disconnect failed"));
-    mClient->mDisconnectRunnable = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-void
-BluetoothGattManager::Disconnect(const BluetoothUuid& aAppUuid,
-                                 const BluetoothAddress& aDeviceAddr,
-                                 BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sClients->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-  client->mDisconnectRunnable = aRunnable;
-
-  sBluetoothGattInterface->Disconnect(
-    client->mClientIf,
-    aDeviceAddr,
-    client->mConnId,
-    new DisconnectResultHandler(client));
-}
-
-class BluetoothGattManager::DiscoverResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  DiscoverResultHandler(BluetoothGattClient* aClient)
-  : mClient(aClient)
-  {
-    MOZ_ASSERT(mClient);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattInterface::Discover failed: %d",
-               (int)aStatus);
-
-    mClient->NotifyDiscoverCompleted(false);
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-void
-BluetoothGattManager::Discover(const BluetoothUuid& aAppUuid,
-                               BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sClients->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-  MOZ_ASSERT(client->mConnId > 0);
-  MOZ_ASSERT(!client->mDiscoverRunnable);
-
-  client->mDiscoverRunnable = aRunnable;
-
-  /**
-   * Discover all services/characteristics/descriptors offered by the remote
-   * GATT server.
-   *
-   * The discover procesure includes following steps.
-   * 1) Discover all services.
-   * 2) After all services are discovered, for each service S, we will do
-   *    following actions.
-   *    2-1) Discover all included services of service S.
-   *    2-2) Discover all characteristics of service S.
-   *    2-3) Discover all descriptors of those characteristics discovered in
-   *         2-2).
-   */
-  sBluetoothGattInterface->SearchService(
-    client->mConnId,
-    true, // search all services
-    BluetoothUuid(),
-    new DiscoverResultHandler(client));
-}
-
-class BluetoothGattManager::ReadRemoteRssiResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  ReadRemoteRssiResultHandler(BluetoothGattClient* aClient)
-  : mClient(aClient)
-  {
-    MOZ_ASSERT(mClient);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattInterface::ReadRemoteRssi failed: %d",
-               (int)aStatus);
-    MOZ_ASSERT(mClient->mReadRemoteRssiRunnable);
-
-    // Reject the read remote rssi request
-    DispatchReplyError(mClient->mReadRemoteRssiRunnable,
-                       NS_LITERAL_STRING("ReadRemoteRssi failed"));
-    mClient->mReadRemoteRssiRunnable = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-void
-BluetoothGattManager::ReadRemoteRssi(int aClientIf,
-                                     const BluetoothAddress& aDeviceAddr,
-                                     BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sClients->IndexOf(aClientIf, 0 /* Start */,
-                                   InterfaceIdComparator());
-  if (NS_WARN_IF(index == sClients->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-  client->mReadRemoteRssiRunnable = aRunnable;
-
-  sBluetoothGattInterface->ReadRemoteRssi(
-    aClientIf, aDeviceAddr,
-    new ReadRemoteRssiResultHandler(client));
-}
-
-class BluetoothGattManager::RegisterNotificationsResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  RegisterNotificationsResultHandler(BluetoothGattClient* aClient)
-  : mClient(aClient)
-  {
-    MOZ_ASSERT(mClient);
-  }
-
-  void RegisterNotification() override
-  {
-    MOZ_ASSERT(mClient->mRegisterNotificationsRunnable);
-
-    /**
-     * Resolve the promise directly if we successfully issued this request to
-     * stack.
-     *
-     * We resolve the promise here since bluedroid stack always returns
-     * incorrect connId in |RegisterNotificationNotification| and we cannot map
-     * back to the target client because of it.
-     * Please see Bug 1149043 for more information.
-     */
-    DispatchReplySuccess(mClient->mRegisterNotificationsRunnable);
-    mClient->mRegisterNotificationsRunnable = nullptr;
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING(
-      "BluetoothGattInterface::RegisterNotifications failed: %d",
-      (int)aStatus);
-    MOZ_ASSERT(mClient->mRegisterNotificationsRunnable);
-
-    DispatchReplyError(mClient->mRegisterNotificationsRunnable,
-                       NS_LITERAL_STRING("RegisterNotifications failed"));
-    mClient->mRegisterNotificationsRunnable = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-void
-BluetoothGattManager::RegisterNotifications(
-  const BluetoothUuid& aAppUuid, const BluetoothGattServiceId& aServId,
-  const BluetoothGattId& aCharId, BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sClients->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  // Reject the request if there is an ongoing request or client is already
-  // disconnected
-  if (client->mRegisterNotificationsRunnable || client->mConnId <= 0) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("RegisterNotifications failed"));
-    return;
-  }
-
-  client->mRegisterNotificationsRunnable = aRunnable;
-
-  sBluetoothGattInterface->RegisterNotification(
-    client->mClientIf, client->mDeviceAddr, aServId, aCharId,
-    new RegisterNotificationsResultHandler(client));
-}
-
-class BluetoothGattManager::DeregisterNotificationsResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  DeregisterNotificationsResultHandler(BluetoothGattClient* aClient)
-  : mClient(aClient)
-  {
-    MOZ_ASSERT(mClient);
-  }
-
-  void DeregisterNotification() override
-  {
-    MOZ_ASSERT(mClient->mDeregisterNotificationsRunnable);
-
-    /**
-     * Resolve the promise directly if we successfully issued this request to
-     * stack.
-     *
-     * We resolve the promise here since bluedroid stack always returns
-     * incorrect connId in |RegisterNotificationNotification| and we cannot map
-     * back to the target client because of it.
-     * Please see Bug 1149043 for more information.
-     */
-    DispatchReplySuccess(mClient->mDeregisterNotificationsRunnable);
-    mClient->mDeregisterNotificationsRunnable = nullptr;
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING(
-      "BluetoothGattInterface::DeregisterNotifications failed: %d",
-      (int)aStatus);
-    MOZ_ASSERT(mClient->mDeregisterNotificationsRunnable);
-
-    DispatchReplyError(mClient->mDeregisterNotificationsRunnable,
-                       NS_LITERAL_STRING("DeregisterNotifications failed"));
-    mClient->mDeregisterNotificationsRunnable = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-void
-BluetoothGattManager::DeregisterNotifications(
-  const BluetoothUuid& aAppUuid, const BluetoothGattServiceId& aServId,
-  const BluetoothGattId& aCharId, BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sClients->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  // Reject the request if there is an ongoing request
-  if (client->mDeregisterNotificationsRunnable) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("DeregisterNotifications failed"));
-    return;
-  }
-
-  client->mDeregisterNotificationsRunnable = aRunnable;
-
-  sBluetoothGattInterface->DeregisterNotification(
-    client->mClientIf, client->mDeviceAddr, aServId, aCharId,
-    new DeregisterNotificationsResultHandler(client));
-}
-
-class BluetoothGattManager::ReadCharacteristicValueResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  ReadCharacteristicValueResultHandler(BluetoothGattClient* aClient)
-    : mClient(aClient)
-  {
-    MOZ_ASSERT(mClient);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattInterface::ReadCharacteristicValue failed" \
-               ": %d", (int)aStatus);
-    MOZ_ASSERT(mClient->mReadCharacteristicState.mRunnable);
-
-    RefPtr<BluetoothReplyRunnable> runnable =
-      mClient->mReadCharacteristicState.mRunnable;
-    mClient->mReadCharacteristicState.Reset();
-
-    // Reject the read characteristic value request
-    DispatchReplyError(runnable,
-                       NS_LITERAL_STRING("ReadCharacteristicValue failed"));
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-void
-BluetoothGattManager::ReadCharacteristicValue(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sClients->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  /**
-   * Reject subsequent reading requests to follow ATT sequential protocol that
-   * handles one request at a time. Otherwise underlying layers would drop the
-   * subsequent requests silently.
-   *
-   * Bug 1147776 intends to solve a larger problem that other kind of requests
-   * may still interfere the ongoing request.
-   */
-  if (client->mReadCharacteristicState.mRunnable) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("ReadCharacteristicValue failed"));
-    return;
-  }
-
-  client->mReadCharacteristicState.Assign(false, aRunnable);
-
-  /**
-   * First, read the characteristic value through an unauthenticated physical
-   * link. If the operation fails due to insufficient authentication/encryption
-   * key size, retry to read through an authenticated physical link.
-   */
-  sBluetoothGattInterface->ReadCharacteristic(
-    client->mConnId,
-    aServiceId,
-    aCharacteristicId,
-    GATT_AUTH_REQ_NONE,
-    new ReadCharacteristicValueResultHandler(client));
-}
-
-class BluetoothGattManager::WriteCharacteristicValueResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  WriteCharacteristicValueResultHandler(BluetoothGattClient* aClient)
-  : mClient(aClient)
-  {
-    MOZ_ASSERT(mClient);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattInterface::WriteCharacteristicValue failed" \
-               ": %d", (int)aStatus);
-    MOZ_ASSERT(mClient->mWriteCharacteristicState.mRunnable);
-
-    RefPtr<BluetoothReplyRunnable> runnable =
-      mClient->mWriteCharacteristicState.mRunnable;
-    mClient->mWriteCharacteristicState.Reset();
-
-    // Reject the write characteristic value request
-    DispatchReplyError(runnable,
-                       NS_LITERAL_STRING("WriteCharacteristicValue failed"));
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-void
-BluetoothGattManager::WriteCharacteristicValue(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  const BluetoothGattWriteType& aWriteType,
-  const nsTArray<uint8_t>& aValue,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sClients->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  /**
-   * Reject subsequent writing requests to follow ATT sequential protocol that
-   * handles one request at a time. Otherwise underlying layers would drop the
-   * subsequent requests silently.
-   *
-   * Bug 1147776 intends to solve a larger problem that other kind of requests
-   * may still interfere the ongoing request.
-   */
-  if (client->mWriteCharacteristicState.mRunnable) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("WriteCharacteristicValue failed"));
-    return;
-  }
-
-  client->mWriteCharacteristicState.Assign(
-    aWriteType, aValue, false, aRunnable);
-
-  /**
-   * First, write the characteristic value through an unauthenticated physical
-   * link. If the operation fails due to insufficient authentication/encryption
-   * key size, retry to write through an authenticated physical link.
-   */
-  sBluetoothGattInterface->WriteCharacteristic(
-    client->mConnId,
-    aServiceId,
-    aCharacteristicId,
-    aWriteType,
-    GATT_AUTH_REQ_NONE,
-    aValue,
-    new WriteCharacteristicValueResultHandler(client));
-}
-
-class BluetoothGattManager::ReadDescriptorValueResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  ReadDescriptorValueResultHandler(BluetoothGattClient* aClient)
-  : mClient(aClient)
-  {
-    MOZ_ASSERT(mClient);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattInterface::ReadDescriptorValue failed: %d",
-               (int)aStatus);
-    MOZ_ASSERT(mClient->mReadDescriptorState.mRunnable);
-
-    RefPtr<BluetoothReplyRunnable> runnable =
-      mClient->mReadDescriptorState.mRunnable;
-    mClient->mReadDescriptorState.Reset();
-
-    // Reject the read descriptor value request
-    DispatchReplyError(runnable,
-                       NS_LITERAL_STRING("ReadDescriptorValue failed"));
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-void
-BluetoothGattManager::ReadDescriptorValue(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  const BluetoothGattId& aDescriptorId,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sClients->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  /**
-   * Reject subsequent reading requests to follow ATT sequential protocol that
-   * handles one request at a time. Otherwise underlying layers would drop the
-   * subsequent requests silently.
-   *
-   * Bug 1147776 intends to solve a larger problem that other kind of requests
-   * may still interfere the ongoing request.
-   */
-  if (client->mReadDescriptorState.mRunnable) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("ReadDescriptorValue failed"));
-    return;
-  }
-
-  client->mReadDescriptorState.Assign(false, aRunnable);
-
-  /**
-   * First, read the descriptor value through an unauthenticated physical
-   * link. If the operation fails due to insufficient authentication/encryption
-   * key size, retry to read through an authenticated physical link.
-   */
-  sBluetoothGattInterface->ReadDescriptor(
-    client->mConnId,
-    aServiceId,
-    aCharacteristicId,
-    aDescriptorId,
-    GATT_AUTH_REQ_NONE,
-    new ReadDescriptorValueResultHandler(client));
-}
-
-class BluetoothGattManager::WriteDescriptorValueResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  WriteDescriptorValueResultHandler(BluetoothGattClient* aClient)
-  : mClient(aClient)
-  {
-    MOZ_ASSERT(mClient);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattInterface::WriteDescriptorValue failed: %d",
-               (int)aStatus);
-    MOZ_ASSERT(mClient->mWriteDescriptorState.mRunnable);
-
-    RefPtr<BluetoothReplyRunnable> runnable =
-      mClient->mWriteDescriptorState.mRunnable;
-    mClient->mWriteDescriptorState.Reset();
-
-    // Reject the write descriptor value request
-    DispatchReplyError(runnable,
-                       NS_LITERAL_STRING("WriteDescriptorValue failed"));
-  }
-
-private:
-  RefPtr<BluetoothGattClient> mClient;
-};
-
-void
-BluetoothGattManager::WriteDescriptorValue(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  const BluetoothGattId& aDescriptorId,
-  const nsTArray<uint8_t>& aValue,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sClients->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  /**
-   * Reject subsequent writing requests to follow ATT sequential protocol that
-   * handles one request at a time. Otherwise underlying layers would drop the
-   * subsequent requests silently.
-   *
-   * Bug 1147776 intends to solve a larger problem that other kind of requests
-   * may still interfere the ongoing request.
-   */
-  if (client->mWriteDescriptorState.mRunnable) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("WriteDescriptorValue failed"));
-    return;
-  }
-
-  /**
-   * First, write the descriptor value through an unauthenticated physical
-   * link. If the operation fails due to insufficient authentication/encryption
-   * key size, retry to write through an authenticated physical link.
-   */
-  client->mWriteDescriptorState.Assign(aValue, false, aRunnable);
-
-  sBluetoothGattInterface->WriteDescriptor(
-    client->mConnId,
-    aServiceId,
-    aCharacteristicId,
-    aDescriptorId,
-    GATT_WRITE_TYPE_NORMAL,
-    GATT_AUTH_REQ_NONE,
-    aValue,
-    new WriteDescriptorValueResultHandler(client));
-}
-
-class BluetoothGattManager::RegisterServerResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  RegisterServerResultHandler(BluetoothGattServer* aServer)
-  : mServer(aServer)
-  {
-    MOZ_ASSERT(mServer);
-    MOZ_ASSERT(!mServer->mIsRegistering);
-
-    mServer->mIsRegistering = true;
-  }
-
-  /*
-   * Some actions will trigger the registration procedure. These actions will
-   * be taken only after the registration has been done successfully.
-   * If the registration fails, all the existing actions above should be
-   * rejected.
-   */
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattServerInterface::RegisterServer failed: %d",
-               (int)aStatus);
-
-    // Reject the connect request
-    if (mServer->mConnectPeripheralRunnable) {
-      DispatchReplyError(mServer->mConnectPeripheralRunnable,
-                         NS_LITERAL_STRING("Register GATT server failed"));
-      mServer->mConnectPeripheralRunnable = nullptr;
-    }
-
-    // Reject the add service request
-    if (mServer->mAddServiceState.mRunnable) {
-      DispatchReplyError(mServer->mAddServiceState.mRunnable,
-                         NS_LITERAL_STRING("Register GATT server failed"));
-      mServer->mAddServiceState.Reset();
-    }
-
-    if (mServer->mRegisterServerRunnable) {
-      DispatchReplyError(mServer->mRegisterServerRunnable,
-                         NS_LITERAL_STRING("Register GATT server failed"));
-      mServer->mRegisterServerRunnable = nullptr;
-    }
-
-    mServer->mIsRegistering = false;
-    sServers->RemoveElement(mServer);
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-};
-
-void
-BluetoothGattManager::RegisterServer(const BluetoothUuid& aAppUuid,
-                                     BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sServers->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (index == sServers->NoIndex) {
-    index = sServers->Length();
-    sServers->AppendElement(new BluetoothGattServer(aAppUuid));
-  }
-  RefPtr<BluetoothGattServer> server = (*sServers)[index];
-
-  /**
-   * There are four cases here for handling aRunnable.
-   * 1) Server interface is already registered: Resolve the runnable.
-   * 2) Server interface is not registered, but there is
-   *    an existing |RegisterServerRunnable|: Reject with STATUS_BUSY.
-   * 3) Server interface is registering without an existing
-   *    |RegisterServerRunnable|: Save the runnable into |GattServer| and will
-   *    resolve or reject it in |RegisterServerNotification| later.
-   * 4) Server interface is neither registered nor registering: Save the
-   *    the runnable into |GattServer| and trigger a registration procedure.
-   *    The runnable will be resolved or rejected in
-   *    |RegisterServerNotification| later.
-   */
-  if (server->mServerIf > 0) {
-    DispatchReplySuccess(aRunnable);
-  } else if (server->mRegisterServerRunnable) {
-    DispatchReplyError(aRunnable, STATUS_BUSY);
-  } else if (server->mIsRegistering) {
-    server->mRegisterServerRunnable = aRunnable;
-  } else {
-    server->mRegisterServerRunnable = aRunnable;
-    sBluetoothGattInterface->RegisterServer(
-      aAppUuid, new RegisterServerResultHandler(server));
-  }
-}
-
-class BluetoothGattManager::ConnectPeripheralResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  ConnectPeripheralResultHandler(BluetoothGattServer* aServer,
-                                 const BluetoothAddress& aDeviceAddr)
-    : mServer(aServer)
-    , mDeviceAddr(aDeviceAddr)
-  {
-    MOZ_ASSERT(mServer);
-    MOZ_ASSERT(!mDeviceAddr.IsCleared());
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattServerInterface::ConnectPeripheral failed: %d",
-               (int)aStatus);
-    MOZ_ASSERT(mServer->mConnectPeripheralRunnable);
-
-    DispatchReplyError(mServer->mConnectPeripheralRunnable,
-                       NS_LITERAL_STRING("ConnectPeripheral failed"));
-    mServer->mConnectPeripheralRunnable = nullptr;
-    mServer->mConnectionMap.Remove(mDeviceAddr);
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-  BluetoothAddress mDeviceAddr;
-};
-
-void
-BluetoothGattManager::ConnectPeripheral(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAddress& aAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sServers->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (index == sServers->NoIndex) {
-    index = sServers->Length();
-    sServers->AppendElement(new BluetoothGattServer(aAppUuid));
-  }
-  RefPtr<BluetoothGattServer> server = (*sServers)[index];
-
-  /**
-   * Early resolve or reject the request based on the current status before
-   * sending a request to bluetooth stack.
-   *
-   * case 1) Connecting/Disconnecting: If connect/disconnect peripheral
-   *         runnable exists, reject the request since the local GATT server is
-   *         busy connecting or disconnecting to a device.
-   * case 2) Connected: If there is an entry whose key is |aAddress| in the
-   *         connection map, resolve the request. Since disconnected devices
-   *         will not be in the map, all entries in the map are connected
-   *         devices.
-   */
-  if (server->mConnectPeripheralRunnable ||
-      server->mDisconnectPeripheralRunnable) {
-    DispatchReplyError(aRunnable, STATUS_BUSY);
-    return;
-  }
-
-  int connId = 0;
-  if (server->mConnectionMap.Get(aAddress, &connId)) {
-    MOZ_ASSERT(connId > 0);
-    DispatchReplySuccess(aRunnable);
-    return;
-  }
-
-  server->mConnectionMap.Put(aAddress, 0);
-  server->mConnectPeripheralRunnable = aRunnable;
-
-  if (server->mServerIf > 0) {
-    sBluetoothGattInterface->ConnectPeripheral(
-      server->mServerIf,
-      aAddress,
-      true, // direct connect
-      TRANSPORT_AUTO,
-      new ConnectPeripheralResultHandler(server, aAddress));
-  } else if (!server->mIsRegistering) { /* avoid triggering another registration
-                                         * procedure if there is an on-going one
-                                         * already */
-    // connect will be proceeded after server registered
-    sBluetoothGattInterface->RegisterServer(
-      aAppUuid, new RegisterServerResultHandler(server));
-  }
-}
-
-class BluetoothGattManager::DisconnectPeripheralResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  DisconnectPeripheralResultHandler(BluetoothGattServer* aServer)
-  : mServer(aServer)
-  {
-    MOZ_ASSERT(mServer);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattServerInterface::DisconnectPeripheral failed: %d",
-               (int)aStatus);
-    MOZ_ASSERT(mServer->mDisconnectPeripheralRunnable);
-
-    // Reject the disconnect request
-    DispatchReplyError(mServer->mDisconnectPeripheralRunnable,
-                       NS_LITERAL_STRING("DisconnectPeripheral failed"));
-    mServer->mDisconnectPeripheralRunnable = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-};
-
-void
-BluetoothGattManager::DisconnectPeripheral(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAddress& aAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sServers->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sServers->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-  RefPtr<BluetoothGattServer> server = (*sServers)[index];
-
-  if (NS_WARN_IF(server->mServerIf <= 0)) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("Disconnect failed"));
-    return;
-  }
-
-  // Reject the request if there is an ongoing connect/disconnect request.
-  if (server->mConnectPeripheralRunnable ||
-      server->mDisconnectPeripheralRunnable) {
-    DispatchReplyError(aRunnable, STATUS_BUSY);
-    return;
-  }
-
-  // Resolve the request if the device is not connected.
-  int connId = 0;
-  if (!server->mConnectionMap.Get(aAddress, &connId)) {
-    DispatchReplySuccess(aRunnable);
-    return;
-  }
-
-  server->mDisconnectPeripheralRunnable = aRunnable;
-
-  sBluetoothGattInterface->DisconnectPeripheral(
-    server->mServerIf,
-    aAddress,
-    connId,
-    new DisconnectPeripheralResultHandler(server));
-}
-
-class BluetoothGattManager::UnregisterServerResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  UnregisterServerResultHandler(BluetoothGattServer* aServer)
-  : mServer(aServer)
-  {
-    MOZ_ASSERT(mServer);
-  }
-
-  void UnregisterServer() override
-  {
-    BluetoothService* bs = BluetoothService::Get();
-    NS_ENSURE_TRUE_VOID(bs);
-
-    // Notify BluetoothGattServer to clear the serverIf
-    bs->DistributeSignal(NS_LITERAL_STRING("ServerUnregistered"),
-                         mServer->mAppUuid);
-
-    // Resolve the unregister request
-    if (mServer->mUnregisterServerRunnable) {
-      DispatchReplySuccess(mServer->mUnregisterServerRunnable);
-      mServer->mUnregisterServerRunnable = nullptr;
-    }
-
-    sServers->RemoveElement(mServer);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattServerInterface::UnregisterServer failed: %d",
-               (int)aStatus);
-
-    // Reject the unregister request
-    if (mServer->mUnregisterServerRunnable) {
-      DispatchReplyError(mServer->mUnregisterServerRunnable,
-                         NS_LITERAL_STRING("Unregister GATT Server failed"));
-      mServer->mUnregisterServerRunnable = nullptr;
-    }
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-};
-
-void
-BluetoothGattManager::UnregisterServer(int aServerIf,
-                                       BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sServers->IndexOf(aServerIf, 0 /* Start */,
-                                   InterfaceIdComparator());
-  if (NS_WARN_IF(index == sServers->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-
-  RefPtr<BluetoothGattServer> server = (*sServers)[index];
-  server->mUnregisterServerRunnable = aRunnable;
-
-  sBluetoothGattInterface->UnregisterServer(
-    aServerIf,
-    new UnregisterServerResultHandler(server));
-}
-
-class BluetoothGattManager::ServerAddServiceResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  ServerAddServiceResultHandler(BluetoothGattServer* aServer)
-  : mServer(aServer)
-  {
-    MOZ_ASSERT(mServer);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattServerInterface::ServerAddService failed: %d",
-               (int)aStatus);
-    MOZ_ASSERT(mServer->mAddServiceState.mRunnable);
-
-    DispatchReplyError(mServer->mAddServiceState.mRunnable,
-                       NS_LITERAL_STRING("ServerAddService failed"));
-    mServer->mAddServiceState.Reset();
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-};
-
-void
-BluetoothGattManager::ServerAddService(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  uint16_t aHandleCount,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sServers->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (index == sServers->NoIndex) {
-    index = sServers->Length();
-    sServers->AppendElement(new BluetoothGattServer(aAppUuid));
-  }
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-
-  // Reject the request if there is an ongoing add service request.
-  if (server->mAddServiceState.mRunnable) {
-    DispatchReplyError(aRunnable, STATUS_BUSY);
-    return;
-  }
-
-  server->mAddServiceState.Assign(aServiceId, aHandleCount, aRunnable);
-
-  if (server->mServerIf > 0) {
-    sBluetoothGattInterface->AddService(
-      server->mServerIf,
-      aServiceId,
-      aHandleCount,
-      new ServerAddServiceResultHandler(server));
-  } else if (!server->mIsRegistering) { /* avoid triggering another registration
-                                         * procedure if there is an on-going one
-                                         * already */
-    // add service will be proceeded after server registered
-    sBluetoothGattInterface->RegisterServer(
-      aAppUuid, new RegisterServerResultHandler(server));
-  }
-}
-
-class BluetoothGattManager::ServerAddIncludedServiceResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  ServerAddIncludedServiceResultHandler(BluetoothGattServer* aServer)
-  : mServer(aServer)
-  {
-    MOZ_ASSERT(mServer);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattServerInterface::AddIncludedService failed: %d",
-               (int)aStatus);
-
-    // Reject the add included service request
-    if (mServer->mAddIncludedServiceRunnable) {
-      DispatchReplyError(mServer->mAddIncludedServiceRunnable,
-                         NS_LITERAL_STRING("Add GATT included service failed"));
-      mServer->mAddIncludedServiceRunnable = nullptr;
-    }
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-};
-
-void
-BluetoothGattManager::ServerAddIncludedService(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aIncludedServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sServers->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sServers->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-
-  // Reject the request if the service has not been registered successfully.
-  if (!server->mServerIf) {
-    DispatchReplyError(aRunnable, STATUS_NOT_READY);
-    return;
-  }
-  // Reject the request if there is an ongoing add included service request.
-  if (server->mAddIncludedServiceRunnable) {
-    DispatchReplyError(aRunnable, STATUS_BUSY);
-    return;
-  }
-
-  server->mAddIncludedServiceRunnable = aRunnable;
-
-  sBluetoothGattInterface->AddIncludedService(
-    server->mServerIf,
-    aServiceHandle,
-    aIncludedServiceHandle,
-    new ServerAddIncludedServiceResultHandler(server));
-}
-
-class BluetoothGattManager::ServerAddCharacteristicResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  ServerAddCharacteristicResultHandler(BluetoothGattServer* aServer)
-  : mServer(aServer)
-  {
-    MOZ_ASSERT(mServer);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattServerInterface::AddCharacteristic failed: %d",
-               (int)aStatus);
-
-    // Reject the add characteristic request
-    if (mServer->mAddCharacteristicRunnable) {
-      DispatchReplyError(mServer->mAddCharacteristicRunnable,
-                         NS_LITERAL_STRING("Add GATT characteristic failed"));
-      mServer->mAddCharacteristicRunnable = nullptr;
-    }
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-};
-
-void
-BluetoothGattManager::ServerAddCharacteristic(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothUuid& aCharacteristicUuid,
-  BluetoothGattAttrPerm aPermissions,
-  BluetoothGattCharProp aProperties,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sServers->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sServers->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-
-  // Reject the request if the service has not been registered successfully.
-  if (!server->mServerIf) {
-    DispatchReplyError(aRunnable, STATUS_NOT_READY);
-    return;
-  }
-  // Reject the request if there is an ongoing add characteristic request.
-  if (server->mAddCharacteristicRunnable) {
-    DispatchReplyError(aRunnable, STATUS_BUSY);
-    return;
-  }
-
-  server->mAddCharacteristicRunnable = aRunnable;
-
-  sBluetoothGattInterface->AddCharacteristic(
-    server->mServerIf,
-    aServiceHandle,
-    aCharacteristicUuid,
-    aProperties,
-    aPermissions,
-    new ServerAddCharacteristicResultHandler(server));
-}
-
-class BluetoothGattManager::ServerAddDescriptorResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  ServerAddDescriptorResultHandler(BluetoothGattServer* aServer)
-  : mServer(aServer)
-  {
-    MOZ_ASSERT(mServer);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattServerInterface::AddDescriptor failed: %d",
-               (int)aStatus);
-
-    // Reject the add descriptor request
-    if (mServer->mAddDescriptorState.mRunnable) {
-      DispatchReplyError(mServer->mAddDescriptorState.mRunnable,
-                         NS_LITERAL_STRING("Add GATT descriptor failed"));
-      mServer->mAddDescriptorState.Reset();
-    }
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-};
-
-void
-BluetoothGattManager::ServerAddDescriptor(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aCharacteristicHandle,
-  const BluetoothUuid& aDescriptorUuid,
-  BluetoothGattAttrPerm aPermissions,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sServers->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sServers->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-
-  // Reject the request if the service has not been registered successfully.
-  if (!server->mServerIf) {
-    DispatchReplyError(aRunnable, STATUS_NOT_READY);
-    return;
-  }
-  // Reject the request if there is an ongoing add descriptor request.
-  if (server->mAddDescriptorState.mRunnable) {
-    DispatchReplyError(aRunnable, STATUS_BUSY);
-    return;
-  }
-
-  server->mAddDescriptorState.Assign(aServiceHandle,
-                                     aCharacteristicHandle,
-                                     aDescriptorUuid,
-                                     aRunnable);
-
-  sBluetoothGattInterface->AddDescriptor(
-    server->mServerIf,
-    aServiceHandle,
-    aDescriptorUuid,
-    aPermissions,
-    new ServerAddDescriptorResultHandler(server));
-}
-
-class BluetoothGattManager::ServerRemoveDescriptorResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  ServerRemoveDescriptorResultHandler(BluetoothGattServer* aServer)
-  : mServer(aServer)
-  {
-    MOZ_ASSERT(mServer);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattServerInterface::RemoveService failed: %d",
-               (int)aStatus);
-
-    // Reject the remove service request
-    if (mServer->mRemoveServiceRunnable) {
-      DispatchReplyError(mServer->mRemoveServiceRunnable,
-                         NS_LITERAL_STRING("Remove GATT service failed"));
-      mServer->mRemoveServiceRunnable = nullptr;
-    }
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-};
-
-void
-BluetoothGattManager::ServerRemoveService(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sServers->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sServers->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-
-  // Reject the request if the service has not been registered successfully.
-  if (!server->mServerIf) {
-    DispatchReplyError(aRunnable, STATUS_NOT_READY);
-    return;
-  }
-  // Reject the request if there is an ongoing remove service request.
-  if (server->mRemoveServiceRunnable) {
-    DispatchReplyError(aRunnable, STATUS_BUSY);
-    return;
-  }
-
-  server->mRemoveServiceRunnable = aRunnable;
-
-  sBluetoothGattInterface->DeleteService(
-    server->mServerIf,
-    aServiceHandle,
-    new ServerRemoveDescriptorResultHandler(server));
-}
-
-class BluetoothGattManager::ServerStartServiceResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  ServerStartServiceResultHandler(BluetoothGattServer* aServer)
-  : mServer(aServer)
-  {
-    MOZ_ASSERT(mServer);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattServerInterface::StartService failed: %d",
-               (int)aStatus);
-
-    // Reject the remove service request
-    if (mServer->mStartServiceRunnable) {
-      DispatchReplyError(mServer->mStartServiceRunnable,
-                         NS_LITERAL_STRING("Start GATT service failed"));
-      mServer->mStartServiceRunnable = nullptr;
-    }
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-};
-
-void
-BluetoothGattManager::ServerStartService(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sServers->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sServers->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-
-  // Reject the request if the service has not been registered successfully.
-  if (!server->mServerIf) {
-    DispatchReplyError(aRunnable, STATUS_NOT_READY);
-    return;
-  }
-  // Reject the request if there is an ongoing start service request.
-  if (server->mStartServiceRunnable) {
-    DispatchReplyError(aRunnable, STATUS_BUSY);
-    return;
-  }
-
-  server->mStartServiceRunnable = aRunnable;
-
-  sBluetoothGattInterface->StartService(
-    server->mServerIf,
-    aServiceHandle,
-    TRANSPORT_AUTO,
-    new ServerStartServiceResultHandler(server));
-}
-
-class BluetoothGattManager::ServerStopServiceResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  ServerStopServiceResultHandler(BluetoothGattServer* aServer)
-  : mServer(aServer)
-  {
-    MOZ_ASSERT(mServer);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattServerInterface::StopService failed: %d",
-               (int)aStatus);
-
-    // Reject the remove service request
-    if (mServer->mStopServiceRunnable) {
-      DispatchReplyError(mServer->mStopServiceRunnable,
-                         NS_LITERAL_STRING("Stop GATT service failed"));
-      mServer->mStopServiceRunnable = nullptr;
-    }
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-};
-
-void
-BluetoothGattManager::ServerStopService(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sServers->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (NS_WARN_IF(index == sServers->NoIndex)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-
-  // Reject the request if the service has not been registered successfully.
-  if (!server->mServerIf) {
-    DispatchReplyError(aRunnable, STATUS_NOT_READY);
-    return;
-  }
-  // Reject the request if there is an ongoing stop service request.
-  if (server->mStopServiceRunnable) {
-    DispatchReplyError(aRunnable, STATUS_BUSY);
-    return;
-  }
-
-  server->mStopServiceRunnable = aRunnable;
-
-  sBluetoothGattInterface->StopService(
-    server->mServerIf,
-    aServiceHandle,
-    new ServerStopServiceResultHandler(server));
-}
-
-class BluetoothGattManager::ServerSendResponseResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  ServerSendResponseResultHandler(BluetoothGattServer* aServer)
-  : mServer(aServer)
-  {
-    MOZ_ASSERT(mServer);
-  }
-
-  void SendResponse() override
-  {
-    if (mServer->mSendResponseRunnable) {
-      DispatchReplySuccess(mServer->mSendResponseRunnable);
-      mServer->mSendResponseRunnable = nullptr;
-    }
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattServerInterface::SendResponse failed: %d",
-               (int)aStatus);
-
-    // Reject the send response request
-    if (mServer->mSendResponseRunnable) {
-      DispatchReplyError(mServer->mSendResponseRunnable,
-                         NS_LITERAL_STRING("Send response failed"));
-      mServer->mSendResponseRunnable = nullptr;
-    }
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-};
-
-void
-BluetoothGattManager::ServerSendResponse(const BluetoothUuid& aAppUuid,
-                                         const BluetoothAddress& aAddress,
-                                         uint16_t aStatus,
-                                         int aRequestId,
-                                         const BluetoothGattResponse& aRsp,
-                                         BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sServers->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  if (index == sServers->NoIndex) {
-    DispatchReplyError(aRunnable, STATUS_NOT_READY);
-    return;
-  }
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-
-  if (server->mSendResponseRunnable) {
-    DispatchReplyError(aRunnable, STATUS_BUSY);
-    return;
-  }
-
-  int connId = 0;
-  server->mConnectionMap.Get(aAddress, &connId);
-  if (!connId) {
-    DispatchReplyError(aRunnable, STATUS_NOT_READY);
-    return;
-  }
-
-  sBluetoothGattInterface->SendResponse(
-    connId,
-    aRequestId,
-    aStatus,
-    aRsp,
-    new ServerSendResponseResultHandler(server));
-}
-
-class BluetoothGattManager::ServerSendIndicationResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  ServerSendIndicationResultHandler(BluetoothGattServer* aServer)
-  : mServer(aServer)
-  {
-    MOZ_ASSERT(mServer);
-  }
-
-  void SendIndication() override
-  {
-    if (mServer->mSendIndicationRunnable) {
-      DispatchReplySuccess(mServer->mSendIndicationRunnable);
-      mServer->mSendIndicationRunnable = nullptr;
-    }
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothGattServerInterface::NotifyCharacteristicChanged"
-               "failed: %d", (int)aStatus);
-
-    // Reject the send indication request
-    if (mServer->mSendIndicationRunnable) {
-      DispatchReplyError(mServer->mSendIndicationRunnable,
-                         NS_LITERAL_STRING("Send GATT indication failed"));
-      mServer->mSendIndicationRunnable = nullptr;
-    }
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-};
-
-void
-BluetoothGattManager::ServerSendIndication(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAddress& aAddress,
-  const BluetoothAttributeHandle& aCharacteristicHandle,
-  bool aConfirm,
-  const nsTArray<uint8_t>& aValue,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  ENSURE_GATT_INTF_IS_READY_VOID(aRunnable);
-
-  size_t index = sServers->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  // Reject the request if the server has not been registered yet.
-  if (index == sServers->NoIndex) {
-    DispatchReplyError(aRunnable, STATUS_NOT_READY);
-    return;
-  }
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-
-  // Reject the request if the server has not been registered successfully.
-  if (!server->mServerIf) {
-    DispatchReplyError(aRunnable, STATUS_NOT_READY);
-    return;
-  }
-  // Reject the request if there is an ongoing send indication request.
-  if (server->mSendIndicationRunnable) {
-    DispatchReplyError(aRunnable, STATUS_BUSY);
-    return;
-  }
-
-  int connId = 0;
-  if (!server->mConnectionMap.Get(aAddress, &connId)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return;
-  }
-
-  if (!connId) {
-    DispatchReplyError(aRunnable, STATUS_NOT_READY);
-    return;
-  }
-
-  server->mSendIndicationRunnable = aRunnable;
-
-  sBluetoothGattInterface->SendIndication(
-    server->mServerIf,
-    aCharacteristicHandle,
-    connId,
-    aValue,
-    aConfirm,
-    new ServerSendIndicationResultHandler(server));
-}
-
-//
-// Notification Handlers
-//
-void
-BluetoothGattManager::RegisterClientNotification(BluetoothGattStatus aStatus,
-                                                 int aClientIf,
-                                                 const BluetoothUuid& aAppUuid)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  if (aStatus != GATT_STATUS_SUCCESS) {
-    nsAutoString appUuidStr;
-    UuidToString(aAppUuid, appUuidStr);
-
-    BT_LOGD("RegisterClient failed: clientIf = %d, status = %d, appUuid = %s",
-            aClientIf, aStatus, NS_ConvertUTF16toUTF8(appUuidStr).get());
-
-    // Notify BluetoothGatt for client disconnected
-    bs->DistributeSignal(
-      NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID),
-      aAppUuid, BluetoothValue(false)); // Disconnected
-
-    if (client->mStartLeScanRunnable) {
-      // Reject the LE scan request
-      DispatchReplyError(client->mStartLeScanRunnable,
-                         NS_LITERAL_STRING(
-                           "StartLeScan failed due to registration failed"));
-      client->mStartLeScanRunnable = nullptr;
-    }
-
-    if (client->mConnectRunnable) {
-      // Reject the connect request
-      DispatchReplyError(client->mConnectRunnable,
-                         NS_LITERAL_STRING(
-                           "Connect failed due to registration failed"));
-      client->mConnectRunnable = nullptr;
-    }
-
-    if (client->mStartAdvertisingRunnable) {
-      // Reject the start advertising request
-      DispatchReplyError(
-        client->mStartAdvertisingRunnable,
-        NS_LITERAL_STRING(
-          "StartAdvertising failed due to registration failed"));
-      client->mStartAdvertisingRunnable = nullptr;
-    }
-
-    sClients->RemoveElement(client);
-    return;
-  }
-
-  client->mClientIf = aClientIf;
-
-  // Notify BluetoothGatt to update the clientIf
-  bs->DistributeSignal(
-    NS_LITERAL_STRING("ClientRegistered"),
-    aAppUuid, BluetoothValue(uint32_t(aClientIf)));
-
-  if (client->mStartLeScanRunnable) {
-    // Client just registered, proceed remaining startLeScan request.
-    ENSURE_GATT_INTF_IS_READY_VOID(client->mStartLeScanRunnable);
-    sBluetoothGattInterface->Scan(
-      aClientIf, true /* start */,
-      new StartLeScanResultHandler(client));
-  }
-
-  if (client->mConnectRunnable) {
-    // Client just registered, proceed remaining connect request.
-    ENSURE_GATT_INTF_IS_READY_VOID(client->mConnectRunnable);
-    sBluetoothGattInterface->Connect(
-      aClientIf, client->mDeviceAddr, true /* direct connect */,
-      TRANSPORT_AUTO,
-      new ConnectResultHandler(client));
-  }
-
-  if (client->mStartAdvertisingRunnable) {
-    // StartAdvertising request will be proceed after SetAdvData succeeded.
-    ENSURE_GATT_INTF_IS_READY_VOID(client->mStartAdvertisingRunnable);
-    BluetoothGattAdvertisingData* data = &(client->mAdvertisingData);
-    sBluetoothGattInterface->SetAdvData(
-      aClientIf, false /* isScanRsp */, data->mIncludeDevName,
-      data->mIncludeTxPower, 0 /* min interval */, 0 /* max interval */,
-      data->mAppearance, data->mManufacturerData, data->mServiceData,
-      data->mServiceUuids, new SetAdvDataResultHandler(client));
-  }
-}
-
-class BluetoothGattManager::ScanDeviceTypeResultHandler final
-  : public BluetoothGattResultHandler
-{
-public:
-  ScanDeviceTypeResultHandler(const BluetoothAddress& aBdAddr, int aRssi,
-                              const BluetoothGattAdvData& aAdvData)
-    : mBdAddr(aBdAddr)
-    , mRssi(static_cast<int32_t>(aRssi))
-  {
-    mAdvData.AppendElements(aAdvData.mAdvData, sizeof(aAdvData.mAdvData));
-  }
-
-  void GetDeviceType(BluetoothTypeOfDevice type)
-  {
-    DistributeSignalDeviceFound(type);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    DistributeSignalDeviceFound(TYPE_OF_DEVICE_BLE);
-  }
-
-private:
-  void DistributeSignalDeviceFound(BluetoothTypeOfDevice type)
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    InfallibleTArray<BluetoothNamedValue> properties;
-
-    AppendNamedValue(properties, "Address", mBdAddr);
-    AppendNamedValue(properties, "Rssi", mRssi);
-    AppendNamedValue(properties, "GattAdv", mAdvData);
-    AppendNamedValue(properties, "Type", static_cast<uint32_t>(type));
-
-    BluetoothService* bs = BluetoothService::Get();
-    NS_ENSURE_TRUE_VOID(bs);
-
-    bs->DistributeSignal(NS_LITERAL_STRING("LeDeviceFound"),
-                         NS_LITERAL_STRING(KEY_ADAPTER),
-                         BluetoothValue(properties));
-  }
-
-  BluetoothAddress mBdAddr;
-  int32_t mRssi;
-  nsTArray<uint8_t> mAdvData;
-};
-
-void
-BluetoothGattManager::ScanResultNotification(
-  const BluetoothAddress& aBdAddr, int aRssi,
-  const BluetoothGattAdvData& aAdvData)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE_VOID(sBluetoothGattInterface);
-
-  // Distribute "LeDeviceFound" signal after we know the corresponding
-  // BluetoothTypeOfDevice of the device
-  sBluetoothGattInterface->GetDeviceType(
-    aBdAddr,
-    new ScanDeviceTypeResultHandler(aBdAddr, aRssi, aAdvData));
-}
-
-void
-BluetoothGattManager::ConnectNotification(int aConnId,
-                                          BluetoothGattStatus aStatus,
-                                          int aClientIf,
-                                          const BluetoothAddress& aDeviceAddr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  size_t index = sClients->IndexOf(aClientIf, 0 /* Start */,
-                                   InterfaceIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  if (aStatus != GATT_STATUS_SUCCESS) {
-    BT_LOGD("Connect failed: clientIf = %d, connId = %d, status = %d",
-            aClientIf, aConnId, aStatus);
-
-    // Notify BluetoothGatt that the client remains disconnected
-    bs->DistributeSignal(
-      NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID),
-      client->mAppUuid,
-      BluetoothValue(false)); // Disconnected
-
-    // Reject the connect request
-    if (client->mConnectRunnable) {
-      DispatchReplyError(client->mConnectRunnable,
-                         NS_LITERAL_STRING("Connect failed"));
-      client->mConnectRunnable = nullptr;
-    }
-
-    return;
-  }
-
-  client->mConnId = aConnId;
-
-  // Notify BluetoothGatt for client connected
-  bs->DistributeSignal(
-    NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID),
-    client->mAppUuid,
-    BluetoothValue(true)); // Connected
-
-  // Resolve the connect request
-  if (client->mConnectRunnable) {
-    DispatchReplySuccess(client->mConnectRunnable);
-    client->mConnectRunnable = nullptr;
-  }
-}
-
-void
-BluetoothGattManager::DisconnectNotification(
-  int aConnId,
-  BluetoothGattStatus aStatus,
-  int aClientIf,
-  const BluetoothAddress& aDeviceAddr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  size_t index = sClients->IndexOf(aClientIf, 0 /* Start */,
-                                   InterfaceIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  if (aStatus != GATT_STATUS_SUCCESS) {
-    // Notify BluetoothGatt that the client remains connected
-    bs->DistributeSignal(
-      NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID),
-      client->mAppUuid,
-      BluetoothValue(true)); // Connected
-
-    // Reject the disconnect request
-    if (client->mDisconnectRunnable) {
-      DispatchReplyError(client->mDisconnectRunnable,
-                         NS_LITERAL_STRING("Disconnect failed"));
-      client->mDisconnectRunnable = nullptr;
-    }
-
-    return;
-  }
-
-  client->mConnId = 0;
-
-  // Notify BluetoothGatt for client disconnected
-  bs->DistributeSignal(
-    NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID),
-    client->mAppUuid,
-    BluetoothValue(false)); // Disconnected
-
-  // Resolve the disconnect request
-  if (client->mDisconnectRunnable) {
-    DispatchReplySuccess(client->mDisconnectRunnable);
-    client->mDisconnectRunnable = nullptr;
-  }
-}
-
-void
-BluetoothGattManager::SearchCompleteNotification(int aConnId,
-                                                 BluetoothGattStatus aStatus)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  size_t index = sClients->IndexOf(aConnId, 0 /* Start */,
-                                   ConnIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-  MOZ_ASSERT(client->mDiscoverRunnable);
-
-  if (aStatus != GATT_STATUS_SUCCESS) {
-    client->NotifyDiscoverCompleted(false);
-    return;
-  }
-
-  // Notify BluetoothGatt to create all services
-  bs->DistributeSignal(NS_LITERAL_STRING("ServicesDiscovered"),
-                       client->mAppUuid,
-                       BluetoothValue(client->mServices));
-
-  // All services are discovered, continue to search included services of each
-  // service if existed, otherwise, notify application that discover completed
-  if (!client->mServices.IsEmpty()) {
-    ENSURE_GATT_INTF_IN_ATTR_DISCOVER(client);
-    sBluetoothGattInterface->GetIncludedService(
-      aConnId,
-      client->mServices[0], // start from first service
-      true, // first included service
-      BluetoothGattServiceId(),
-      new DiscoverResultHandler(client));
-  } else {
-    client->NotifyDiscoverCompleted(true);
-  }
-}
-
-void
-BluetoothGattManager::SearchResultNotification(
-  int aConnId, const BluetoothGattServiceId& aServiceId)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  size_t index = sClients->IndexOf(aConnId, 0 /* Start */,
-                                   ConnIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
-
-  // Save to mServices for distributing to application and discovering
-  // included services, characteristics of this service later
-  sClients->ElementAt(index)->mServices.AppendElement(aServiceId);
-}
-
-void
-BluetoothGattManager::GetCharacteristicNotification(
-  int aConnId, BluetoothGattStatus aStatus,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId,
-  const BluetoothGattCharProp& aCharProperty)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  size_t index = sClients->IndexOf(aConnId, 0 /* Start */,
-                                   ConnIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-  MOZ_ASSERT(client->mDiscoverRunnable);
-
-  if (aStatus == GATT_STATUS_SUCCESS) {
-    BluetoothGattCharAttribute attribute;
-    attribute.mId = aCharId;
-    attribute.mProperties = aCharProperty;
-    attribute.mWriteType =
-      aCharProperty & GATT_CHAR_PROP_BIT_WRITE_NO_RESPONSE
-        ? GATT_WRITE_TYPE_NO_RESPONSE
-        : GATT_WRITE_TYPE_NORMAL;
-
-    // Save to mCharacteristics for distributing to applications and
-    // discovering descriptors of this characteristic later
-    client->mCharacteristics.AppendElement(attribute);
-
-    // Get next characteristic of this service
-    ENSURE_GATT_INTF_IN_ATTR_DISCOVER(client);
-    sBluetoothGattInterface->GetCharacteristic(
-      aConnId,
-      aServiceId,
-      false,
-      aCharId,
-      new DiscoverResultHandler(client));
-  } else { // all characteristics of this service are discovered
-    // Notify BluetoothGatt to make BluetoothGattService create characteristics
-    // then proceed
-    nsTArray<BluetoothNamedValue> values;
-    AppendNamedValue(values, "serviceId", aServiceId);
-    AppendNamedValue(values, "characteristics", client->mCharacteristics);
-
-    bs->DistributeSignal(NS_LITERAL_STRING("CharacteristicsDiscovered"),
-                         client->mAppUuid,
-                         BluetoothValue(values));
-
-    ProceedDiscoverProcess(client, aServiceId);
-  }
-}
-
-void
-BluetoothGattManager::GetDescriptorNotification(
-  int aConnId, BluetoothGattStatus aStatus,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId,
-  const BluetoothGattId& aDescriptorId)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  size_t index = sClients->IndexOf(aConnId, 0 /* Start */,
-                                   ConnIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-  MOZ_ASSERT(client->mDiscoverRunnable);
-
-  if (aStatus == GATT_STATUS_SUCCESS) {
-    // Save to mDescriptors for distributing to applications
-    client->mDescriptors.AppendElement(aDescriptorId);
-
-    // Get next descriptor of this characteristic
-    ENSURE_GATT_INTF_IN_ATTR_DISCOVER(client);
-    sBluetoothGattInterface->GetDescriptor(
-      aConnId,
-      aServiceId,
-      aCharId,
-      false,
-      aDescriptorId,
-      new DiscoverResultHandler(client));
-  } else { // all descriptors of this characteristic are discovered
-    // Notify BluetoothGatt to make BluetoothGattCharacteristic create
-    // descriptors then proceed
-    nsTArray<BluetoothNamedValue> values;
-    AppendNamedValue(values, "serviceId", aServiceId);
-    AppendNamedValue(values, "characteristicId", aCharId);
-    AppendNamedValue(values, "descriptors", client->mDescriptors);
-
-    bs->DistributeSignal(NS_LITERAL_STRING("DescriptorsDiscovered"),
-                         client->mAppUuid,
-                         BluetoothValue(values));
-    client->mDescriptors.Clear();
-
-    ProceedDiscoverProcess(client, aServiceId);
-  }
-}
-
-void
-BluetoothGattManager::GetIncludedServiceNotification(
-  int aConnId, BluetoothGattStatus aStatus,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattServiceId& aIncludedServId)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  size_t index = sClients->IndexOf(aConnId, 0 /* Start */,
-                                   ConnIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-  MOZ_ASSERT(client->mDiscoverRunnable);
-
-  ENSURE_GATT_INTF_IN_ATTR_DISCOVER(client);
-  if (aStatus == GATT_STATUS_SUCCESS) {
-    // Save to mIncludedServices for distributing to applications
-    client->mIncludedServices.AppendElement(aIncludedServId);
-
-    // Get next included service of this service
-    sBluetoothGattInterface->GetIncludedService(
-      aConnId,
-      aServiceId,
-      false,
-      aIncludedServId,
-      new DiscoverResultHandler(client));
-  } else { // all included services of this service are discovered
-    // Notify BluetoothGatt to make BluetoothGattService create included
-    // services
-    nsTArray<BluetoothNamedValue> values;
-    AppendNamedValue(values, "serviceId", aServiceId);
-    AppendNamedValue(values, "includedServices", client->mIncludedServices);
-
-    bs->DistributeSignal(NS_LITERAL_STRING("IncludedServicesDiscovered"),
-                         client->mAppUuid,
-                         BluetoothValue(values));
-    client->mIncludedServices.Clear();
-
-    // Start to discover characteristics of this service
-    sBluetoothGattInterface->GetCharacteristic(
-      aConnId,
-      aServiceId,
-      true, // first characteristic
-      BluetoothGattId(),
-      new DiscoverResultHandler(client));
-  }
-}
-
-void
-BluetoothGattManager::RegisterNotificationNotification(
-  int aConnId, int aIsRegister, BluetoothGattStatus aStatus,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  BT_LOGD("aStatus = %d, aConnId = %d, aIsRegister = %d",
-          aStatus, aConnId, aIsRegister);
-
-  /**
-   * FIXME: Bug 1149043
-   *
-   * aConnId reported by bluedroid stack is wrong, with these limited
-   * information we have, we currently cannot map back to the client from this
-   * callback. Therefore, we resolve/reject the Promise for registering or
-   * deregistering notifications in their result handlers instead of this
-   * callback.
-   * We should resolve/reject the Promise for registering or deregistering
-   * notifications here if this bluedroid stack bug is fixed.
-   *
-   * Please see Bug 1149043 for more information.
-   */
-}
-
-void
-BluetoothGattManager::NotifyNotification(
-  int aConnId, const BluetoothGattNotifyParam& aNotifyParam)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  size_t index = sClients->IndexOf(aConnId, 0 /* Start */, ConnIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  // Notify BluetoothGattCharacteristic to update characteristic value
-  nsString path;
-  GeneratePathFromGattId(aNotifyParam.mCharId, path);
-
-  nsTArray<uint8_t> value;
-  value.AppendElements(aNotifyParam.mValue, aNotifyParam.mLength);
-
-  bs->DistributeSignal(NS_LITERAL_STRING("CharacteristicValueUpdated"),
-                       path,
-                       BluetoothValue(value));
-
-  // Notify BluetoothGatt for characteristic changed
-  nsTArray<BluetoothNamedValue> ids;
-  ids.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("serviceId"),
-                                        aNotifyParam.mServiceId));
-  ids.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("charId"),
-                                        aNotifyParam.mCharId));
-
-  bs->DistributeSignal(NS_LITERAL_STRING(GATT_CHARACTERISTIC_CHANGED_ID),
-                       client->mAppUuid,
-                       BluetoothValue(ids));
-}
-
-void
-BluetoothGattManager::ReadCharacteristicNotification(
-  int aConnId, BluetoothGattStatus aStatus,
-  const BluetoothGattReadParam& aReadParam)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  size_t index = sClients->IndexOf(aConnId, 0 /* Start */, ConnIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  MOZ_ASSERT(client->mReadCharacteristicState.mRunnable);
-  RefPtr<BluetoothReplyRunnable> runnable =
-    client->mReadCharacteristicState.mRunnable;
-
-  if (aStatus == GATT_STATUS_SUCCESS) {
-    client->mReadCharacteristicState.Reset();
-    // Notify BluetoothGattCharacteristic to update characteristic value
-    nsString path;
-    GeneratePathFromGattId(aReadParam.mCharId, path);
-
-    nsTArray<uint8_t> value;
-    value.AppendElements(aReadParam.mValue, aReadParam.mValueLength);
-
-    bs->DistributeSignal(NS_LITERAL_STRING("CharacteristicValueUpdated"),
-                         path,
-                         BluetoothValue(value));
-
-    // Notify BluetoothGatt for characteristic changed
-    nsTArray<BluetoothNamedValue> ids;
-    ids.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("serviceId"),
-                                          aReadParam.mServiceId));
-    ids.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("charId"),
-                                          aReadParam.mCharId));
-
-    bs->DistributeSignal(NS_LITERAL_STRING(GATT_CHARACTERISTIC_CHANGED_ID),
-                         client->mAppUuid,
-                         BluetoothValue(ids));
-
-    // Resolve the promise
-    DispatchReplySuccess(runnable, BluetoothValue(value));
-  } else if (!client->mReadCharacteristicState.mAuthRetry &&
-             (aStatus == GATT_STATUS_INSUFFICIENT_AUTHENTICATION ||
-              aStatus == GATT_STATUS_INSUFFICIENT_ENCRYPTION)) {
-    if (NS_WARN_IF(!sBluetoothGattInterface)) {
-      client->mReadCharacteristicState.Reset();
-      // Reject the promise
-      DispatchReplyError(runnable,
-                         NS_LITERAL_STRING("ReadCharacteristicValue failed"));
-      return;
-    }
-
-    client->mReadCharacteristicState.mAuthRetry = true;
-    // Retry with another authentication requirement
-    sBluetoothGattInterface->ReadCharacteristic(
-      aConnId,
-      aReadParam.mServiceId,
-      aReadParam.mCharId,
-      GATT_AUTH_REQ_MITM,
-      new ReadCharacteristicValueResultHandler(client));
-  } else {
-    client->mReadCharacteristicState.Reset();
-    // Reject the promise
-    DispatchReplyError(runnable,
-                       NS_LITERAL_STRING("ReadCharacteristicValue failed"));
-  }
-}
-
-void
-BluetoothGattManager::WriteCharacteristicNotification(
-  int aConnId, BluetoothGattStatus aStatus,
-  const BluetoothGattWriteParam& aWriteParam)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  size_t index = sClients->IndexOf(aConnId, 0 /* Start */, ConnIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  MOZ_ASSERT(client->mWriteCharacteristicState.mRunnable);
-  RefPtr<BluetoothReplyRunnable> runnable =
-    client->mWriteCharacteristicState.mRunnable;
-
-  if (aStatus == GATT_STATUS_SUCCESS) {
-    client->mWriteCharacteristicState.Reset();
-    // Resolve the promise
-    DispatchReplySuccess(runnable);
-  } else if (!client->mWriteCharacteristicState.mAuthRetry &&
-             (aStatus == GATT_STATUS_INSUFFICIENT_AUTHENTICATION ||
-              aStatus == GATT_STATUS_INSUFFICIENT_ENCRYPTION)) {
-    if (NS_WARN_IF(!sBluetoothGattInterface)) {
-      client->mWriteCharacteristicState.Reset();
-      // Reject the promise
-      DispatchReplyError(runnable,
-                         NS_LITERAL_STRING("WriteCharacteristicValue failed"));
-      return;
-    }
-
-    client->mWriteCharacteristicState.mAuthRetry = true;
-    // Retry with another authentication requirement
-    sBluetoothGattInterface->WriteCharacteristic(
-      aConnId,
-      aWriteParam.mServiceId,
-      aWriteParam.mCharId,
-      client->mWriteCharacteristicState.mWriteType,
-      GATT_AUTH_REQ_MITM,
-      client->mWriteCharacteristicState.mWriteValue,
-      new WriteCharacteristicValueResultHandler(client));
-  } else {
-    client->mWriteCharacteristicState.Reset();
-    // Reject the promise
-    DispatchReplyError(runnable,
-                       NS_LITERAL_STRING("WriteCharacteristicValue failed"));
-  }
-}
-
-void
-BluetoothGattManager::ReadDescriptorNotification(
-  int aConnId, BluetoothGattStatus aStatus,
-  const BluetoothGattReadParam& aReadParam)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  size_t index = sClients->IndexOf(aConnId, 0 /* Start */, ConnIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  MOZ_ASSERT(client->mReadDescriptorState.mRunnable);
-  RefPtr<BluetoothReplyRunnable> runnable =
-    client->mReadDescriptorState.mRunnable;
-
-  if (aStatus == GATT_STATUS_SUCCESS) {
-    client->mReadDescriptorState.Reset();
-    // Notify BluetoothGattDescriptor to update descriptor value
-    nsString path;
-    GeneratePathFromGattId(aReadParam.mDescriptorId, path);
-
-    nsTArray<uint8_t> value;
-    value.AppendElements(aReadParam.mValue, aReadParam.mValueLength);
-
-    bs->DistributeSignal(NS_LITERAL_STRING("DescriptorValueUpdated"),
-                         path,
-                         BluetoothValue(value));
-
-    // Resolve the promise
-    DispatchReplySuccess(runnable, BluetoothValue(value));
-  } else if (!client->mReadDescriptorState.mAuthRetry &&
-             (aStatus == GATT_STATUS_INSUFFICIENT_AUTHENTICATION ||
-              aStatus == GATT_STATUS_INSUFFICIENT_ENCRYPTION)) {
-    if (NS_WARN_IF(!sBluetoothGattInterface)) {
-      client->mReadDescriptorState.Reset();
-      // Reject the promise
-      DispatchReplyError(runnable,
-                         NS_LITERAL_STRING("ReadDescriptorValue failed"));
-      return;
-    }
-
-    client->mReadDescriptorState.mAuthRetry = true;
-    // Retry with another authentication requirement
-    sBluetoothGattInterface->ReadDescriptor(
-      aConnId,
-      aReadParam.mServiceId,
-      aReadParam.mCharId,
-      aReadParam.mDescriptorId,
-      GATT_AUTH_REQ_MITM,
-      new ReadDescriptorValueResultHandler(client));
-  } else {
-    client->mReadDescriptorState.Reset();
-    // Reject the promise
-    DispatchReplyError(runnable,
-                       NS_LITERAL_STRING("ReadDescriptorValue failed"));
-  }
-}
-
-void
-BluetoothGattManager::WriteDescriptorNotification(
-  int aConnId, BluetoothGattStatus aStatus,
-  const BluetoothGattWriteParam& aWriteParam)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  size_t index = sClients->IndexOf(aConnId, 0 /* Start */, ConnIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  MOZ_ASSERT(client->mWriteDescriptorState.mRunnable);
-  RefPtr<BluetoothReplyRunnable> runnable =
-    client->mWriteDescriptorState.mRunnable;
-
-  if (aStatus == GATT_STATUS_SUCCESS) {
-    client->mWriteDescriptorState.Reset();
-    // Resolve the promise
-    DispatchReplySuccess(runnable);
-  } else if (!client->mWriteDescriptorState.mAuthRetry &&
-             (aStatus == GATT_STATUS_INSUFFICIENT_AUTHENTICATION ||
-              aStatus == GATT_STATUS_INSUFFICIENT_ENCRYPTION)) {
-    if (NS_WARN_IF(!sBluetoothGattInterface)) {
-      client->mWriteDescriptorState.Reset();
-      // Reject the promise
-      DispatchReplyError(runnable,
-                         NS_LITERAL_STRING("WriteDescriptorValue failed"));
-      return;
-    }
-
-    client->mWriteDescriptorState.mAuthRetry = true;
-    // Retry with another authentication requirement
-    sBluetoothGattInterface->WriteDescriptor(
-      aConnId,
-      aWriteParam.mServiceId,
-      aWriteParam.mCharId,
-      aWriteParam.mDescriptorId,
-      GATT_WRITE_TYPE_NORMAL,
-      GATT_AUTH_REQ_MITM,
-      client->mWriteDescriptorState.mWriteValue,
-      new WriteDescriptorValueResultHandler(client));
-  } else {
-    client->mWriteDescriptorState.Reset();
-    // Reject the promise
-    DispatchReplyError(runnable,
-                       NS_LITERAL_STRING("WriteDescriptorValue failed"));
-  }
-}
-
-void
-BluetoothGattManager::ExecuteWriteNotification(int aConnId,
-                                               BluetoothGattStatus aStatus)
-{ }
-
-void
-BluetoothGattManager::ReadRemoteRssiNotification(
-  int aClientIf,
-  const BluetoothAddress& aBdAddr,
-  int aRssi,
-  BluetoothGattStatus aStatus)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  size_t index = sClients->IndexOf(aClientIf, 0 /* Start */,
-                                   InterfaceIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
-
-  RefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
-
-  if (aStatus != GATT_STATUS_SUCCESS) { // operation failed
-    nsAutoString addressStr;
-    AddressToString(aBdAddr, addressStr);
-    BT_LOGD("ReadRemoteRssi failed: clientIf = %d, bdAddr = %s, rssi = %d, "
-            "status = %d", aClientIf, NS_ConvertUTF16toUTF8(addressStr).get(),
-            aRssi, (int)aStatus);
-
-    // Reject the read remote rssi request
-    if (client->mReadRemoteRssiRunnable) {
-      DispatchReplyError(client->mReadRemoteRssiRunnable,
-                         NS_LITERAL_STRING("ReadRemoteRssi failed"));
-      client->mReadRemoteRssiRunnable = nullptr;
-    }
-
-    return;
-  }
-
-  // Resolve the read remote rssi request
-  if (client->mReadRemoteRssiRunnable) {
-    DispatchReplySuccess(client->mReadRemoteRssiRunnable,
-                         BluetoothValue(static_cast<int32_t>(aRssi)));
-    client->mReadRemoteRssiRunnable = nullptr;
-  }
-}
-
-void
-BluetoothGattManager::ListenNotification(BluetoothGattStatus aStatus,
-                                         int aServerIf)
-{ }
-
-/*
- * Some actions will trigger the registration procedure. These actions will
- * be taken only after the registration has been done successfully.
- * If the registration fails, all the existing actions above should be
- * rejected.
- */
-void
-BluetoothGattManager::RegisterServerNotification(BluetoothGattStatus aStatus,
-                                                 int aServerIf,
-                                                 const BluetoothUuid& aAppUuid)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  size_t index = sServers->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
-  NS_ENSURE_TRUE_VOID(index != sServers->NoIndex);
-
-  RefPtr<BluetoothGattServer> server = (*sServers)[index];
-
-  server->mIsRegistering = false;
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs || aStatus != GATT_STATUS_SUCCESS || !sBluetoothGattInterface) {
-    nsAutoString appUuidStr;
-    UuidToString(aAppUuid, appUuidStr);
-
-    BT_LOGD("RegisterServer failed: serverIf = %d, status = %d, appUuid = %s",
-             aServerIf, aStatus, NS_ConvertUTF16toUTF8(appUuidStr).get());
-
-    if (server->mConnectPeripheralRunnable) {
-      // Reject the connect peripheral request
-      DispatchReplyError(
-        server->mConnectPeripheralRunnable,
-        NS_LITERAL_STRING(
-          "ConnectPeripheral failed due to registration failed"));
-      server->mConnectPeripheralRunnable = nullptr;
-    }
-
-    if (server->mAddServiceState.mRunnable) {
-      // Reject the add service request
-      DispatchReplyError(
-        server->mAddServiceState.mRunnable,
-        NS_LITERAL_STRING(
-          "AddService failed due to registration failed"));
-      server->mAddServiceState.Reset();
-    }
-
-    if (server->mRegisterServerRunnable) {
-      // Reject the register server request
-      DispatchReplyError(
-        server->mRegisterServerRunnable,
-        NS_LITERAL_STRING("Register server failed"));
-      server->mRegisterServerRunnable = nullptr;
-    }
-
-    sServers->RemoveElement(server);
-    return;
-  }
-
-  server->mServerIf = aServerIf;
-
-  // Notify BluetoothGattServer to update the serverIf
-  bs->DistributeSignal(
-    NS_LITERAL_STRING("ServerRegistered"),
-    aAppUuid, BluetoothValue(uint32_t(aServerIf)));
-
-  if (server->mConnectPeripheralRunnable) {
-    // Only one entry exists in the map during first connect peripheral request
-    const BluetoothAddress& deviceAddr = server->mConnectionMap.Iter().Key();
-
-    sBluetoothGattInterface->ConnectPeripheral(
-      aServerIf, deviceAddr, true /* direct connect */, TRANSPORT_AUTO,
-      new ConnectPeripheralResultHandler(server, deviceAddr));
-  }
-
-  if (server->mAddServiceState.mRunnable) {
-    sBluetoothGattInterface->AddService(
-      server->mServerIf,
-      server->mAddServiceState.mServiceId,
-      server->mAddServiceState.mHandleCount,
-      new ServerAddServiceResultHandler(server));
-  }
-
-  if (server->mRegisterServerRunnable) {
-    DispatchReplySuccess(server->mRegisterServerRunnable);
-    server->mRegisterServerRunnable = nullptr;
-  }
-}
-
-void
-BluetoothGattManager::ConnectionNotification(int aConnId,
-                                             int aServerIf,
-                                             bool aConnected,
-                                             const BluetoothAddress& aBdAddr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  size_t index = sServers->IndexOf(aServerIf, 0 /* Start */,
-                                   InterfaceIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sServers->NoIndex);
-
-  RefPtr<BluetoothGattServer> server = (*sServers)[index];
-
-  // Update the connection map based on the connection status
-  if (aConnected) {
-    server->mConnectionMap.Put(aBdAddr, aConnId);
-  } else {
-    server->mConnectionMap.Remove(aBdAddr);
-  }
-
-  // Notify BluetoothGattServer that connection status changed
-  InfallibleTArray<BluetoothNamedValue> props;
-  AppendNamedValue(props, "Connected", aConnected);
-  AppendNamedValue(props, "Address", aBdAddr);
-  bs->DistributeSignal(
-    NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID),
-    server->mAppUuid,
-    BluetoothValue(props));
-
-  // Resolve or reject connect/disconnect peripheral requests
-  if (server->mConnectPeripheralRunnable) {
-    if (aConnected) {
-      DispatchReplySuccess(server->mConnectPeripheralRunnable);
-    } else {
-      DispatchReplyError(server->mConnectPeripheralRunnable,
-                         NS_LITERAL_STRING("ConnectPeripheral failed"));
-    }
-    server->mConnectPeripheralRunnable = nullptr;
-  } else if (server->mDisconnectPeripheralRunnable) {
-    if (!aConnected) {
-      DispatchReplySuccess(server->mDisconnectPeripheralRunnable);
-    } else {
-      DispatchReplyError(server->mDisconnectPeripheralRunnable,
-                         NS_LITERAL_STRING("DisconnectPeripheral failed"));
-    }
-    server->mDisconnectPeripheralRunnable = nullptr;
-  }
-}
-
-void
-BluetoothGattManager::ServiceAddedNotification(
-  BluetoothGattStatus aStatus,
-  int aServerIf,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothAttributeHandle& aServiceHandle)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  size_t index = sServers->IndexOf(aServerIf, 0 /* Start */,
-                                   InterfaceIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sServers->NoIndex);
-
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs || aStatus != GATT_STATUS_SUCCESS) {
-    if (server->mAddServiceState.mRunnable) {
-      DispatchReplyError(server->mAddServiceState.mRunnable,
-                         NS_LITERAL_STRING("ServiceAddedNotification failed"));
-      server->mAddServiceState.Reset();
-    }
-    return;
-  }
-
-  // Notify BluetoothGattServer to update service handle
-  InfallibleTArray<BluetoothNamedValue> props;
-  AppendNamedValue(props, "ServiceId", aServiceId);
-  AppendNamedValue(props, "ServiceHandle", aServiceHandle);
-  bs->DistributeSignal(NS_LITERAL_STRING("ServiceHandleUpdated"),
-                       server->mAppUuid,
-                       BluetoothValue(props));
-
-  if (server->mAddServiceState.mRunnable) {
-    DispatchReplySuccess(server->mAddServiceState.mRunnable);
-    server->mAddServiceState.Reset();
-  }
-}
-
-void
-BluetoothGattManager::IncludedServiceAddedNotification(
-  BluetoothGattStatus aStatus,
-  int aServerIf,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aIncludedServiceHandle)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  size_t index = sServers->IndexOf(aServerIf, 0 /* Start */,
-                                   InterfaceIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sServers->NoIndex);
-
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-
-  if (aStatus != GATT_STATUS_SUCCESS) {
-    if (server->mAddIncludedServiceRunnable) {
-      DispatchReplyError(
-        server->mAddIncludedServiceRunnable,
-        NS_LITERAL_STRING("IncludedServiceAddedNotification failed"));
-      server->mAddIncludedServiceRunnable = nullptr;
-    }
-    return;
-  }
-
-  if (server->mAddIncludedServiceRunnable) {
-    DispatchReplySuccess(server->mAddIncludedServiceRunnable);
-    server->mAddIncludedServiceRunnable = nullptr;
-  }
-}
-
-void
-BluetoothGattManager::CharacteristicAddedNotification(
-  BluetoothGattStatus aStatus,
-  int aServerIf,
-  const BluetoothUuid& aCharId,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aCharacteristicHandle)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  size_t index = sServers->IndexOf(aServerIf, 0 /* Start */,
-                                   InterfaceIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sServers->NoIndex);
-
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs || aStatus != GATT_STATUS_SUCCESS) {
-    if (server->mAddCharacteristicRunnable) {
-      DispatchReplyError(
-        server->mAddCharacteristicRunnable,
-        NS_LITERAL_STRING("CharacteristicAddedNotification failed"));
-      server->mAddCharacteristicRunnable = nullptr;
-    }
-    return;
-  }
-
-  // Notify BluetoothGattServer to update characteristic handle
-  InfallibleTArray<BluetoothNamedValue> props;
-  AppendNamedValue(props, "CharacteristicUuid", aCharId);
-  AppendNamedValue(props, "ServiceHandle", aServiceHandle);
-  AppendNamedValue(props, "CharacteristicHandle", aCharacteristicHandle);
-  bs->DistributeSignal(NS_LITERAL_STRING("CharacteristicHandleUpdated"),
-                       server->mAppUuid,
-                       BluetoothValue(props));
-
-  if (server->mAddCharacteristicRunnable) {
-    DispatchReplySuccess(server->mAddCharacteristicRunnable);
-    server->mAddCharacteristicRunnable = nullptr;
-  }
-}
-
-void
-BluetoothGattManager::DescriptorAddedNotification(
-  BluetoothGattStatus aStatus,
-  int aServerIf,
-  const BluetoothUuid& aCharId,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aDescriptorHandle)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  size_t index = sServers->IndexOf(aServerIf, 0 /* Start */,
-                                   InterfaceIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sServers->NoIndex);
-
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-  MOZ_ASSERT(aServiceHandle == server->mAddDescriptorState.mServiceHandle);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs || aStatus != GATT_STATUS_SUCCESS) {
-    if (server->mAddDescriptorState.mRunnable) {
-      DispatchReplyError(
-        server->mAddDescriptorState.mRunnable,
-        NS_LITERAL_STRING("DescriptorAddedNotification failed"));
-      server->mAddDescriptorState.Reset();
-    }
-    return;
-  }
-
-  // Notify BluetoothGattServer to update descriptor handle
-  InfallibleTArray<BluetoothNamedValue> props;
-  AppendNamedValue(props, "CharacteristicUuid", aCharId);
-  AppendNamedValue(props, "ServiceHandle", aServiceHandle);
-  AppendNamedValue(props, "CharacteristicHandle",
-    server->mAddDescriptorState.mCharacteristicHandle);
-  AppendNamedValue(props, "DescriptorHandle", aDescriptorHandle);
-  bs->DistributeSignal(NS_LITERAL_STRING("DescriptorHandleUpdated"),
-                       server->mAppUuid,
-                       BluetoothValue(props));
-
-  if (server->mAddDescriptorState.mRunnable) {
-    DispatchReplySuccess(server->mAddDescriptorState.mRunnable);
-    server->mAddDescriptorState.Reset();
-  }
-}
-
-void
-BluetoothGattManager::ServiceStartedNotification(
-  BluetoothGattStatus aStatus,
-  int aServerIf,
-  const BluetoothAttributeHandle& aServiceHandle)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  size_t index = sServers->IndexOf(aServerIf, 0 /* Start */,
-                                   InterfaceIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sServers->NoIndex);
-
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-
-  if (aStatus != GATT_STATUS_SUCCESS) {
-    if (server->mStartServiceRunnable) {
-      DispatchReplyError(
-        server->mStartServiceRunnable,
-        NS_LITERAL_STRING("ServiceStartedNotification failed"));
-      server->mStartServiceRunnable = nullptr;
-    }
-    return;
-  }
-
-  if (server->mStartServiceRunnable) {
-    DispatchReplySuccess(server->mStartServiceRunnable);
-    server->mStartServiceRunnable = nullptr;
-  }
-}
-
-void
-BluetoothGattManager::ServiceStoppedNotification(
-  BluetoothGattStatus aStatus,
-  int aServerIf,
-  const BluetoothAttributeHandle& aServiceHandle)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  size_t index = sServers->IndexOf(aServerIf, 0 /* Start */,
-                                   InterfaceIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sServers->NoIndex);
-
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-
-  if (aStatus != GATT_STATUS_SUCCESS) {
-    if (server->mStopServiceRunnable) {
-      DispatchReplyError(
-        server->mStopServiceRunnable,
-        NS_LITERAL_STRING("ServiceStoppedNotification failed"));
-      server->mStopServiceRunnable = nullptr;
-    }
-    return;
-  }
-
-  if (server->mStopServiceRunnable) {
-    DispatchReplySuccess(server->mStopServiceRunnable);
-    server->mStopServiceRunnable = nullptr;
-  }
-}
-
-void
-BluetoothGattManager::ServiceDeletedNotification(
-  BluetoothGattStatus aStatus,
-  int aServerIf,
-  const BluetoothAttributeHandle& aServiceHandle)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  size_t index = sServers->IndexOf(aServerIf, 0 /* Start */,
-                                   InterfaceIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sServers->NoIndex);
-
-  RefPtr<BluetoothGattServer> server = sServers->ElementAt(index);
-
-  if (aStatus != GATT_STATUS_SUCCESS) {
-    if (server->mRemoveServiceRunnable) {
-      DispatchReplyError(
-        server->mRemoveServiceRunnable,
-        NS_LITERAL_STRING("ServiceStoppedNotification failed"));
-      server->mRemoveServiceRunnable = nullptr;
-    }
-    return;
-  }
-
-  if (server->mRemoveServiceRunnable) {
-    DispatchReplySuccess(server->mRemoveServiceRunnable);
-    server->mRemoveServiceRunnable = nullptr;
-  }
-}
-
-void
-BluetoothGattManager::RequestReadNotification(
-  int aConnId,
-  int aTransId,
-  const BluetoothAddress& aBdAddr,
-  const BluetoothAttributeHandle& aAttributeHandle,
-  int aOffset,
-  bool aIsLong)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE_VOID(aConnId);
-  NS_ENSURE_TRUE_VOID(sBluetoothGattInterface);
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  size_t index = sServers->IndexOf(aConnId, 0 /* Start */, ConnIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sServers->NoIndex);
-
-  RefPtr<BluetoothGattServer> server = (*sServers)[index];
-
-  // Send an error response for unsupported requests
-  if (aIsLong || aOffset > 0) {
-    BT_LOGR("Unsupported long attribute read requests");
-    BluetoothGattResponse response;
-    memset(&response, 0, sizeof(BluetoothGattResponse));
-    sBluetoothGattInterface->SendResponse(
-      aConnId,
-      aTransId,
-      GATT_STATUS_REQUEST_NOT_SUPPORTED,
-      response,
-      new ServerSendResponseResultHandler(server));
-    return;
-  }
-
-  // Distribute a signal to gattServer
-  InfallibleTArray<BluetoothNamedValue> properties;
-
-  AppendNamedValue(properties, "TransId", aTransId);
-  AppendNamedValue(properties, "AttrHandle", aAttributeHandle);
-  AppendNamedValue(properties, "Address", aBdAddr);
-  AppendNamedValue(properties, "NeedResponse", true);
-  AppendNamedValue(properties, "Value", nsTArray<uint8_t>());
-
-  bs->DistributeSignal(NS_LITERAL_STRING("ReadRequested"),
-                       server->mAppUuid,
-                       properties);
-}
-
-void
-BluetoothGattManager::RequestWriteNotification(
-  int aConnId,
-  int aTransId,
-  const BluetoothAddress& aBdAddr,
-  const BluetoothAttributeHandle& aAttributeHandle,
-  int aOffset,
-  int aLength,
-  const uint8_t* aValue,
-  bool aNeedResponse,
-  bool aIsPrepareWrite)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE_VOID(aConnId);
-  NS_ENSURE_TRUE_VOID(sBluetoothGattInterface);
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  size_t index = sServers->IndexOf(aConnId, 0 /* Start */, ConnIdComparator());
-  NS_ENSURE_TRUE_VOID(index != sServers->NoIndex);
-
-  RefPtr<BluetoothGattServer> server = (*sServers)[index];
-
-  // Send an error response for unsupported requests
-  if (aIsPrepareWrite || aOffset > 0) {
-    BT_LOGR("Unsupported prepare write or long attribute write requests");
-    if (aNeedResponse) {
-      BluetoothGattResponse response;
-      memset(&response, 0, sizeof(BluetoothGattResponse));
-      sBluetoothGattInterface->SendResponse(
-        aConnId,
-        aTransId,
-        GATT_STATUS_REQUEST_NOT_SUPPORTED,
-        response,
-        new ServerSendResponseResultHandler(server));
-    }
-    return;
-  }
-
-  // Distribute a signal to gattServer
-  InfallibleTArray<BluetoothNamedValue> properties;
-
-  AppendNamedValue(properties, "TransId", aTransId);
-  AppendNamedValue(properties, "AttrHandle", aAttributeHandle);
-  AppendNamedValue(properties, "Address", aBdAddr);
-  AppendNamedValue(properties, "NeedResponse", aNeedResponse);
-
-  nsTArray<uint8_t> value;
-  value.AppendElements(aValue, aLength);
-  AppendNamedValue(properties, "Value", value);
-
-  bs->DistributeSignal(NS_LITERAL_STRING("WriteRequested"),
-                       server->mAppUuid,
-                       properties);
-}
-
-BluetoothGattManager::BluetoothGattManager()
-{ }
-
-BluetoothGattManager::~BluetoothGattManager()
-{ }
-
-NS_IMETHODIMP
-BluetoothGattManager::Observe(nsISupports* aSubject,
-                              const char* aTopic,
-                              const char16_t* aData)
-{
-  MOZ_ASSERT(sBluetoothGattManager);
-
-  if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    HandleShutdown();
-    return NS_OK;
-  }
-
-  MOZ_ASSERT(false, "BluetoothGattManager got unexpected topic!");
-  return NS_ERROR_UNEXPECTED;
-}
-
-void
-BluetoothGattManager::HandleShutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  mInShutdown = true;
-  sBluetoothGattManager = nullptr;
-  sClients = nullptr;
-  sServers = nullptr;
-}
-
-void
-BluetoothGattManager::ProceedDiscoverProcess(
-  BluetoothGattClient* aClient,
-  const BluetoothGattServiceId& aServiceId)
-{
-  /**
-   * This function will be called to decide how to proceed the discover process
-   * after discovering all characteristics of a given service, or after
-   * discovering all descriptors of a given characteristic.
-   *
-   * There are three cases here,
-   * 1) mCharacteristics is not empty:
-   *      Proceed to discover descriptors of the first saved characteristic.
-   * 2) mCharacteristics is empty but mServices is not empty:
-   *      This service does not have any saved characteristics left, proceed to
-   *      discover included services of the next service.
-   * 3) Both arrays are already empty:
-   *      Discover is done, notify application.
-   */
-  MOZ_ASSERT(aClient->mDiscoverRunnable);
-  ENSURE_GATT_INTF_IN_ATTR_DISCOVER(aClient);
-
-  if (!aClient->mCharacteristics.IsEmpty()) {
-    sBluetoothGattInterface->GetDescriptor(
-      aClient->mConnId,
-      aServiceId,
-      aClient->mCharacteristics[0].mId,
-      true, // first descriptor
-      BluetoothGattId(),
-      new DiscoverResultHandler(aClient));
-    aClient->mCharacteristics.RemoveElementAt(0);
-  } else if (!aClient->mServices.IsEmpty()) {
-    sBluetoothGattInterface->GetIncludedService(
-      aClient->mConnId,
-      aClient->mServices[0],
-      true, // first included service
-      BluetoothGattServiceId(),
-      new DiscoverResultHandler(aClient));
-    aClient->mServices.RemoveElementAt(0);
-  } else {
-    aClient->NotifyDiscoverCompleted(true);
-  }
-}
-
-NS_IMPL_ISUPPORTS(BluetoothGattManager, nsIObserver)
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothGattManager.h
+++ /dev/null
@@ -1,389 +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_BluetoothGattManager_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothGattManager_h
-
-#include "BluetoothCommon.h"
-#include "BluetoothInterface.h"
-#include "BluetoothProfileManagerBase.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothGattClient;
-class BluetoothReplyRunnable;
-
-class BluetoothGattManager final : public nsIObserver
-                                 , public BluetoothGattNotificationHandler
-{
-public:
-  static const int MAX_NUM_CLIENTS;
-
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIOBSERVER
-
-  static BluetoothGattManager* Get();
-  static void InitGattInterface(BluetoothProfileResultHandler* aRes);
-  static void DeinitGattInterface(BluetoothProfileResultHandler* aRes);
-
-  void StartLeScan(const nsTArray<BluetoothUuid>& aServiceUuids,
-                   BluetoothReplyRunnable* aRunnable);
-
-  void StopLeScan(const BluetoothUuid& aScanUuid,
-                  BluetoothReplyRunnable* aRunnable);
-
-  void StartAdvertising(const BluetoothUuid& aAppUuid,
-                        const BluetoothGattAdvertisingData& aData,
-                        BluetoothReplyRunnable* aRunnable);
-
-  void StopAdvertising(const BluetoothUuid& aAppUuid,
-                       BluetoothReplyRunnable* aRunnable);
-
-  void Connect(const BluetoothUuid& aAppUuid,
-               const BluetoothAddress& aDeviceAddr,
-               BluetoothReplyRunnable* aRunnable);
-
-  void Disconnect(const BluetoothUuid& aAppUuid,
-                  const BluetoothAddress& aDeviceAddr,
-                  BluetoothReplyRunnable* aRunnable);
-
-  void Discover(const BluetoothUuid& aAppUuid,
-                BluetoothReplyRunnable* aRunnable);
-
-  void UnregisterClient(int aClientIf,
-                        BluetoothReplyRunnable* aRunnable);
-
-  void ReadRemoteRssi(int aClientIf,
-                      const BluetoothAddress& aDeviceAddr,
-                      BluetoothReplyRunnable* aRunnable);
-
-  void RegisterNotifications(const BluetoothUuid& aAppUuid,
-                             const BluetoothGattServiceId& aServId,
-                             const BluetoothGattId& aCharId,
-                             BluetoothReplyRunnable* aRunnable);
-
-  void DeregisterNotifications(const BluetoothUuid& aAppUuid,
-                               const BluetoothGattServiceId& aServId,
-                               const BluetoothGattId& aCharId,
-                               BluetoothReplyRunnable* aRunnable);
-
-  void ReadCharacteristicValue(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    BluetoothReplyRunnable* aRunnable);
-
-  void WriteCharacteristicValue(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    const BluetoothGattWriteType& aWriteType,
-    const nsTArray<uint8_t>& aValue,
-    BluetoothReplyRunnable* aRunnable);
-
-  void ReadDescriptorValue(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    const BluetoothGattId& aDescriptorId,
-    BluetoothReplyRunnable* aRunnable);
-
-  void WriteDescriptorValue(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    const BluetoothGattId& aDescriptorId,
-    const nsTArray<uint8_t>& aValue,
-    BluetoothReplyRunnable* aRunnable);
-
-  void RegisterServer(const BluetoothUuid& aAppUuid,
-                      BluetoothReplyRunnable* aRunnable);
-
-  void ConnectPeripheral(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    BluetoothReplyRunnable* aRunnable);
-
-  void DisconnectPeripheral(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    BluetoothReplyRunnable* aRunnable);
-
-  void UnregisterServer(int aServerIf,
-                        BluetoothReplyRunnable* aRunnable);
-
-  void ServerAddService(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    uint16_t aHandleCount,
-    BluetoothReplyRunnable* aRunnable);
-
-  void ServerAddIncludedService(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aIncludedServiceHandle,
-    BluetoothReplyRunnable* aRunnable);
-
-  void ServerAddCharacteristic(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothUuid& aCharacteristicUuid,
-    BluetoothGattAttrPerm aPermissions,
-    BluetoothGattCharProp aProperties,
-    BluetoothReplyRunnable* aRunnable);
-
-  void ServerAddDescriptor(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aCharacteristicHandle,
-    const BluetoothUuid& aDescriptorUuid,
-    BluetoothGattAttrPerm aPermissions,
-    BluetoothReplyRunnable* aRunnable);
-
-  void ServerRemoveService(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothReplyRunnable* aRunnable);
-
-  void ServerStartService(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothReplyRunnable* aRunnable);
-
-  void ServerStopService(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothReplyRunnable* aRunnable);
-
-  void ServerSendResponse(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    uint16_t aStatus,
-    int32_t aRequestId,
-    const BluetoothGattResponse& aRsp,
-    BluetoothReplyRunnable* aRunnable);
-
-  void ServerSendIndication(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    const BluetoothAttributeHandle& aCharacteristicHandle,
-    bool aConfirm,
-    const nsTArray<uint8_t>& aValue,
-    BluetoothReplyRunnable* aRunnable);
-
-private:
-  ~BluetoothGattManager();
-
-  class DeinitProfileResultHandlerRunnable;
-  class InitProfileResultHandlerRunnable;
-  class RegisterModuleResultHandler;
-  class UnregisterModuleResultHandler;
-
-  class RegisterClientResultHandler;
-  class UnregisterClientResultHandler;
-  class StartLeScanResultHandler;
-  class StopLeScanResultHandler;
-  class StartAdvertisingResultHandler;
-  class SetAdvDataResultHandler;
-  class StopAdvertisingResultHandler;
-  class ConnectResultHandler;
-  class DisconnectResultHandler;
-  class DiscoverResultHandler;
-  class ReadRemoteRssiResultHandler;
-  class RegisterNotificationsResultHandler;
-  class DeregisterNotificationsResultHandler;
-  class ReadCharacteristicValueResultHandler;
-  class WriteCharacteristicValueResultHandler;
-  class ReadDescriptorValueResultHandler;
-  class WriteDescriptorValueResultHandler;
-  class ScanDeviceTypeResultHandler;
-
-  class RegisterServerResultHandler;
-  class ConnectPeripheralResultHandler;
-  class DisconnectPeripheralResultHandler;
-  class UnregisterServerResultHandler;
-  class ServerAddServiceResultHandler;
-  class ServerAddIncludedServiceResultHandler;
-  class ServerAddCharacteristicResultHandler;
-  class ServerAddDescriptorResultHandler;
-  class ServerRemoveDescriptorResultHandler;
-  class ServerStartServiceResultHandler;
-  class ServerStopServiceResultHandler;
-  class ServerSendResponseResultHandler;
-  class ServerSendIndicationResultHandler;
-
-  BluetoothGattManager();
-
-  nsresult Init();
-  void Uninit();
-  void HandleShutdown();
-
-  void RegisterClientNotification(BluetoothGattStatus aStatus,
-                                  int aClientIf,
-                                  const BluetoothUuid& aAppUuid) override;
-
-  void ScanResultNotification(
-    const BluetoothAddress& aBdAddr, int aRssi,
-    const BluetoothGattAdvData& aAdvData) override;
-
-  void ConnectNotification(int aConnId,
-                           BluetoothGattStatus aStatus,
-                           int aClientIf,
-                           const BluetoothAddress& aBdAddr) override;
-
-  void DisconnectNotification(int aConnId,
-                              BluetoothGattStatus aStatus,
-                              int aClientIf,
-                              const BluetoothAddress& aBdAddr) override;
-
-  void SearchCompleteNotification(int aConnId,
-                                  BluetoothGattStatus aStatus) override;
-
-  void SearchResultNotification(int aConnId,
-                                const BluetoothGattServiceId& aServiceId)
-                                override;
-
-  void GetCharacteristicNotification(
-    int aConnId, BluetoothGattStatus aStatus,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharId,
-    const BluetoothGattCharProp& aCharProperty) override;
-
-  void GetDescriptorNotification(
-    int aConnId, BluetoothGattStatus aStatus,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharId,
-    const BluetoothGattId& aDescriptorId) override;
-
-  void GetIncludedServiceNotification(
-    int aConnId, BluetoothGattStatus aStatus,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattServiceId& aIncludedServId) override;
-
-  void RegisterNotificationNotification(
-    int aConnId, int aIsRegister, BluetoothGattStatus aStatus,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharId) override;
-
-  void NotifyNotification(int aConnId,
-                          const BluetoothGattNotifyParam& aNotifyParam)
-                          override;
-
-  void ReadCharacteristicNotification(int aConnId,
-                                      BluetoothGattStatus aStatus,
-                                      const BluetoothGattReadParam& aReadParam)
-                                      override;
-
-  void WriteCharacteristicNotification(
-    int aConnId, BluetoothGattStatus aStatus,
-    const BluetoothGattWriteParam& aWriteParam) override;
-
-  void ReadDescriptorNotification(int aConnId,
-                                  BluetoothGattStatus aStatus,
-                                  const BluetoothGattReadParam& aReadParam)
-                                  override;
-
-  void WriteDescriptorNotification(int aConnId,
-                                   BluetoothGattStatus aStatus,
-                                   const BluetoothGattWriteParam& aWriteParam)
-                                   override;
-
-  void ExecuteWriteNotification(int aConnId,
-                                BluetoothGattStatus aStatus) override;
-
-  void ReadRemoteRssiNotification(int aClientIf,
-                                  const BluetoothAddress& aBdAddr,
-                                  int aRssi,
-                                  BluetoothGattStatus aStatus) override;
-
-  void ListenNotification(BluetoothGattStatus aStatus,
-                          int aServerIf) override;
-
-  void ProceedDiscoverProcess(BluetoothGattClient* aClient,
-                              const BluetoothGattServiceId& aServiceId);
-
-  void RegisterServerNotification(BluetoothGattStatus aStatus,
-                                  int aServerIf,
-                                  const BluetoothUuid& aAppUuid) override;
-
-  void ConnectionNotification(int aConnId,
-                              int aServerIf,
-                              bool aConnected,
-                              const BluetoothAddress& aBdAddr) override;
-
-  void
-  ServiceAddedNotification(
-    BluetoothGattStatus aStatus,
-    int aServerIf,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothAttributeHandle& aServiceHandle) override;
-
-  void
-  IncludedServiceAddedNotification(
-    BluetoothGattStatus aStatus,
-    int aServerIf,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aIncludedServiceHandle) override;
-
-  void
-  CharacteristicAddedNotification(
-    BluetoothGattStatus aStatus,
-    int aServerIf,
-    const BluetoothUuid& aCharId,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aCharacteristicHandle) override;
-
-  void
-  DescriptorAddedNotification(
-    BluetoothGattStatus aStatus,
-    int aServerIf,
-    const BluetoothUuid& aCharId,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aDescriptorHandle) override;
-
-  void
-  ServiceStartedNotification(
-    BluetoothGattStatus aStatus,
-    int aServerIf,
-    const BluetoothAttributeHandle& aServiceHandle) override;
-
-  void
-  ServiceStoppedNotification(
-    BluetoothGattStatus aStatus,
-    int aServerIf,
-    const BluetoothAttributeHandle& aServiceHandle) override;
-
-  void
-  ServiceDeletedNotification(
-    BluetoothGattStatus aStatus,
-    int aServerIf,
-    const BluetoothAttributeHandle& aServiceHandle) override;
-
-  void
-  RequestReadNotification(int aConnId,
-                          int aTransId,
-                          const BluetoothAddress& aBdAddr,
-                          const BluetoothAttributeHandle& aAttributeHandle,
-                          int aOffset,
-                          bool aIsLong) override;
-
-  void
-  RequestWriteNotification(int aConnId,
-                           int aTransId,
-                           const BluetoothAddress& aBdAddr,
-                           const BluetoothAttributeHandle& aAttributeHandle,
-                           int aOffset,
-                           int aLength,
-                           const uint8_t* aValue,
-                           bool aNeedResponse,
-                           bool aIsPrepareWrite) override;
-
-  static bool mInShutdown;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothGattManager_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothHidManager.cpp
+++ /dev/null
@@ -1,718 +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 "BluetoothHidManager.h"
-#include "BluetoothService.h"
-#include "BluetoothUtils.h"
-#include "mozilla/Services.h"
-#include "mozilla/StaticPtr.h"
-#include "nsIObserverService.h"
-
-using namespace mozilla;
-USING_BLUETOOTH_NAMESPACE
-
-#define ENSURE_HID_DEV_IS_CONNECTED                                           \
-  do {                                                                        \
-    if(!IsConnected()) {                                                      \
-      BT_LOGR("Device is not connected");                                     \
-      return;                                                                 \
-    }                                                                         \
-  } while(0)                                                                  \
-
-#define ENSURE_HID_INTF_IS_EXISTED                                            \
-  do {                                                                        \
-    if(!sBluetoothHidInterface) {                                             \
-      BT_LOGR("sBluetoothHidInterface is null");                              \
-      return;                                                                 \
-    }                                                                         \
-  } while(0)                                                                  \
-
-namespace {
-  StaticRefPtr<BluetoothHidManager> sBluetoothHidManager;
-  static BluetoothHidInterface* sBluetoothHidInterface = nullptr;
-  bool sInShutdown = false;
-} // namesapce
-
-const int BluetoothHidManager::MAX_NUM_CLIENTS = 1;
-
-BluetoothHidManager::BluetoothHidManager()
-  : mHidConnected(false)
-{
-}
-
-void
-BluetoothHidManager::Reset()
-{
-  mDeviceAddress.Clear();
-  mController = nullptr;
-  mHidConnected = false;
-}
-
-class BluetoothHidManager::RegisterModuleResultHandler final
-  : public BluetoothSetupResultHandler
-{
-public:
-  RegisterModuleResultHandler(BluetoothHidInterface* aInterface,
-                              BluetoothProfileResultHandler* aRes)
-    : mInterface(aInterface)
-    , mRes(aRes)
-  {
-    MOZ_ASSERT(mInterface);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_WARNING("BluetoothSetupInterface::RegisterModule failed for HID: %d",
-               (int)aStatus);
-
-    mInterface->SetNotificationHandler(nullptr);
-
-    if (mRes) {
-      mRes->OnError(NS_ERROR_FAILURE);
-    }
-  }
-
-  void RegisterModule() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    sBluetoothHidInterface = mInterface;
-
-    if (mRes) {
-      mRes->Init();
-    }
-  }
-
-private:
-  BluetoothHidInterface* mInterface;
-  RefPtr<BluetoothProfileResultHandler> mRes;
-};
-
-class BluetoothHidManager::InitProfileResultHandlerRunnable final
-  : public Runnable
-{
-public:
-  InitProfileResultHandlerRunnable(BluetoothProfileResultHandler* aRes,
-                                   nsresult aRv)
-    : mRes(aRes)
-    , mRv(aRv)
-  {
-    MOZ_ASSERT(mRes);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (NS_SUCCEEDED(mRv)) {
-      mRes->Init();
-    } else {
-      mRes->OnError(mRv);
-    }
-    return NS_OK;
-  }
-
-private:
-  RefPtr<BluetoothProfileResultHandler> mRes;
-  nsresult mRv;
-};
-
-// static
-void
-BluetoothHidManager::InitHidInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (sBluetoothHidInterface) {
-    BT_LOGR("Bluetooth HID interface is already initialized.");
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_OK);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch HID Init runnable");
-    }
-    return;
-  }
-
-  auto btInf = BluetoothInterface::GetInstance();
-
-  if (NS_WARN_IF(!btInf)) {
-    // If there's no backend interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch HID OnError runnable");
-    }
-    return;
-  }
-
-  auto setupInterface = btInf->GetBluetoothSetupInterface();
-
-  if (NS_WARN_IF(!setupInterface)) {
-    // If there's no Setup interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch HID OnError runnable");
-    }
-    return;
-  }
-
-  auto hidinterface = btInf->GetBluetoothHidInterface();
-
-  if (NS_WARN_IF(!hidinterface)) {
-    // If there's no HID interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch HID OnError runnable");
-    }
-    return;
-  }
-
-  // Set notification handler _before_ registering the module. It could
-  // happen that we receive notifications, before the result handler runs.
-  hidinterface->SetNotificationHandler(BluetoothHidManager::Get());
-
-  setupInterface->RegisterModule(
-    SETUP_SERVICE_ID_HID, 0, MAX_NUM_CLIENTS,
-    new RegisterModuleResultHandler(hidinterface, aRes));
-}
-
-BluetoothHidManager::~BluetoothHidManager()
-{ }
-
-void
-BluetoothHidManager::Uninit()
-{
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-
-  if (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID))) {
-    BT_WARNING("Failed to remove shutdown observer!");
-  }
-}
-
-class BluetoothHidManager::UnregisterModuleResultHandler final
-  : public BluetoothSetupResultHandler
-{
-public:
-  UnregisterModuleResultHandler(BluetoothProfileResultHandler* aRes)
-    : mRes(aRes)
-  { }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_WARNING("BluetoothSetupInterface::UnregisterModule failed for HID: %d",
-               (int)aStatus);
-
-    sBluetoothHidInterface->SetNotificationHandler(nullptr);
-    sBluetoothHidInterface = nullptr;
-
-    sBluetoothHidManager->Uninit();
-    sBluetoothHidManager = nullptr;
-
-    if (mRes) {
-      mRes->OnError(NS_ERROR_FAILURE);
-    }
-  }
-
-  void UnregisterModule() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    sBluetoothHidInterface->SetNotificationHandler(nullptr);
-    sBluetoothHidInterface = nullptr;
-
-    sBluetoothHidManager->Uninit();
-    sBluetoothHidManager = nullptr;
-
-    if (mRes) {
-      mRes->Deinit();
-    }
-  }
-
-private:
-  RefPtr<BluetoothProfileResultHandler> mRes;
-};
-
-class BluetoothHidManager::DeinitProfileResultHandlerRunnable final
-  : public Runnable
-{
-public:
-  DeinitProfileResultHandlerRunnable(BluetoothProfileResultHandler* aRes,
-                                     nsresult aRv)
-    : mRes(aRes)
-    , mRv(aRv)
-  {
-    MOZ_ASSERT(mRes);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (NS_SUCCEEDED(mRv)) {
-      mRes->Deinit();
-    } else {
-      mRes->OnError(mRv);
-    }
-    return NS_OK;
-  }
-
-private:
-  RefPtr<BluetoothProfileResultHandler> mRes;
-  nsresult mRv;
-};
-
-// static
-void
-BluetoothHidManager::DeinitHidInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!sBluetoothHidInterface) {
-    BT_LOGR("Bluetooth Hid interface has not been initialized.");
-    RefPtr<Runnable> r =
-      new DeinitProfileResultHandlerRunnable(aRes, NS_OK);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch HID Deinit runnable");
-    }
-    return;
-  }
-
-  auto btInf = BluetoothInterface::GetInstance();
-
-  if (NS_WARN_IF(!btInf)) {
-    // If there's no backend interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new DeinitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch HID OnError runnable");
-    }
-    return;
-  }
-
-  auto setupInterface = btInf->GetBluetoothSetupInterface();
-
-  if (NS_WARN_IF(!setupInterface)) {
-    // If there's no Setup interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new DeinitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch HID OnError runnable");
-    }
-    return;
-  }
-
-  setupInterface->UnregisterModule(
-    SETUP_SERVICE_ID_HID,
-    new UnregisterModuleResultHandler(aRes));
-}
-
-NS_IMETHODIMP
-BluetoothHidManager::Observe(nsISupports* aSubject,
-                            const char* aTopic,
-                            const char16_t* aData)
-{
-  MOZ_ASSERT(sBluetoothHidManager);
-
-  if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    HandleShutdown();
-    return NS_OK;
-  }
-
-  MOZ_ASSERT(false, "BluetoothHidManager got unexpected topic!");
-  return NS_ERROR_UNEXPECTED;
-}
-
-// static
-BluetoothHidManager*
-BluetoothHidManager::Get()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // If we already exist, exit early
-  if (sBluetoothHidManager) {
-    return sBluetoothHidManager;
-  }
-
-  // If we're in shutdown, don't create a new instance
-  NS_ENSURE_FALSE(sInShutdown, nullptr);
-
-  // Create a new instance, register, and return
-  sBluetoothHidManager = new BluetoothHidManager();
-
-  return sBluetoothHidManager;
-}
-
-void
-BluetoothHidManager::NotifyConnectionStateChanged(const nsAString& aType)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Notify Gecko observers
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-
-  nsAutoString deviceAddressStr;
-  AddressToString(mDeviceAddress, deviceAddressStr);
-
-  if (NS_FAILED(obs->NotifyObservers(this, NS_ConvertUTF16toUTF8(aType).get(),
-                                     deviceAddressStr.get()))) {
-    BT_WARNING("Failed to notify observsers!");
-  }
-
-  // Dispatch an event of status change
-  DispatchStatusChangedEvent(
-    NS_LITERAL_STRING(HID_STATUS_CHANGED_ID), mDeviceAddress, IsConnected());
-}
-
-bool
-BluetoothHidManager::IsConnected()
-{
-  return mHidConnected;
-}
-
-void
-BluetoothHidManager::OnConnectError()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mController->NotifyCompletion(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
-  Reset();
-}
-
-class BluetoothHidManager::ConnectResultHandler final
-  : public BluetoothHidResultHandler
-{
-public:
-  ConnectResultHandler(BluetoothHidManager* aHidManager)
-    : mHidManager(aHidManager)
-  {
-    MOZ_ASSERT(mHidManager);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHidInterface::Connect failed: %d",
-               (int)aStatus);
-    mHidManager->OnConnectError();
-  }
-
-private:
-  BluetoothHidManager* mHidManager;
-};
-
-void
-BluetoothHidManager::Connect(const BluetoothAddress& aDeviceAddress,
-                             BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!aDeviceAddress.IsCleared());
-  MOZ_ASSERT(aController && !mController);
-
-  if(sInShutdown) {
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    return;
-  }
-
-  if(IsConnected()) {
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
-    return;
-  }
-
-  if(!sBluetoothHidInterface) {
-    BT_LOGR("sBluetoothHidInterface is null");
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    return;
-  }
-
-  mDeviceAddress = aDeviceAddress;
-  mController = aController;
-
-  sBluetoothHidInterface->Connect(mDeviceAddress,
-                                  new ConnectResultHandler(this));
-}
-
-void
-BluetoothHidManager::OnDisconnectError()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  NS_ENSURE_TRUE_VOID(mController);
-
-  mController->NotifyCompletion(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
-
-  mController = nullptr;
-}
-
-class BluetoothHidManager::DisconnectResultHandler final
-  : public BluetoothHidResultHandler
-{
-public:
-  DisconnectResultHandler(BluetoothHidManager* aHidManager)
-    : mHidManager(aHidManager)
-  {
-    MOZ_ASSERT(mHidManager);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHidInterface::Disconnect failed: %d",
-               (int)aStatus);
-    mHidManager->OnDisconnectError();
-  }
-
-private:
-  BluetoothHidManager* mHidManager;
-};
-
-void
-BluetoothHidManager::Disconnect(BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!mController);
-
-  if (!IsConnected()) {
-    if (aController) {
-      aController->NotifyCompletion(
-        NS_LITERAL_STRING(ERR_ALREADY_DISCONNECTED));
-    }
-    return;
-  }
-
-  MOZ_ASSERT(!mDeviceAddress.IsCleared());
-
-  if (!sBluetoothHidInterface) {
-    BT_LOGR("sBluetoothHidInterface is null");
-    if (aController) {
-      aController->NotifyCompletion(
-        NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    }
-    return;
-  }
-
-  mController = aController;
-
-  sBluetoothHidInterface->Disconnect(mDeviceAddress,
-                                     new DisconnectResultHandler(this));
-}
-
-void
-BluetoothHidManager::OnConnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  mController->NotifyCompletion(aErrorStr);
-  mController = nullptr;
-}
-
-void
-BluetoothHidManager::OnDisconnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  mController->NotifyCompletion(aErrorStr);
-  Reset();
-}
-
-class BluetoothHidManager::VirtualUnplugResultHandler final
-  : public BluetoothHidResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHidInterface::VirtualUnplug failed: %d", (int)aStatus);
-  }
-};
-
-void
-BluetoothHidManager::VirtualUnplug()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  ENSURE_HID_DEV_IS_CONNECTED;
-  MOZ_ASSERT(!mDeviceAddress.IsCleared());
-  ENSURE_HID_INTF_IS_EXISTED;
-
-  sBluetoothHidInterface->VirtualUnplug(
-    mDeviceAddress, new VirtualUnplugResultHandler());
-}
-
-class BluetoothHidManager::GetReportResultHandler final
-  : public BluetoothHidResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHidInterface::GetReport failed: %d", (int)aStatus);
-  }
-};
-
-void
-BluetoothHidManager::GetReport(const BluetoothHidReportType& aReportType,
-                               const uint8_t aReportId,
-                               const uint16_t aBufSize)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  ENSURE_HID_DEV_IS_CONNECTED;
-  MOZ_ASSERT(!mDeviceAddress.IsCleared());
-  ENSURE_HID_INTF_IS_EXISTED;
-
-  sBluetoothHidInterface->GetReport(
-    mDeviceAddress, aReportType, aReportId, aBufSize,
-    new GetReportResultHandler());
-}
-
-class BluetoothHidManager::SetReportResultHandler final
-  : public BluetoothHidResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHidInterface::SetReport failed: %d", (int)aStatus);
-  }
-};
-
-void
-BluetoothHidManager::SetReport(const BluetoothHidReportType& aReportType,
-                               const BluetoothHidReport& aReport)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  ENSURE_HID_DEV_IS_CONNECTED;
-  MOZ_ASSERT(!mDeviceAddress.IsCleared());
-  ENSURE_HID_INTF_IS_EXISTED;
-
-  sBluetoothHidInterface->SetReport(
-    mDeviceAddress, aReportType, aReport, new SetReportResultHandler());
-}
-
-class BluetoothHidManager::SendDataResultHandler final
-  : public BluetoothHidResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHidInterface::SendData failed: %d", (int)aStatus);
-  }
-};
-
-void
-BluetoothHidManager::SendData(const uint16_t aDataLen, const uint8_t* aData)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  ENSURE_HID_DEV_IS_CONNECTED;
-  MOZ_ASSERT(!mDeviceAddress.IsCleared());
-  ENSURE_HID_INTF_IS_EXISTED;
-
-  sBluetoothHidInterface->SendData(
-    mDeviceAddress, aDataLen, aData, new SendDataResultHandler());
-}
-
-void
-BluetoothHidManager::HandleShutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  sInShutdown = true;
-  Disconnect(nullptr);
-  sBluetoothHidManager = nullptr;
-}
-
-void
-BluetoothHidManager::HandleBackendError()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (mHidConnected) {
-    ConnectionStateNotification(mDeviceAddress,
-                                HID_CONNECTION_STATE_DISCONNECTED);
-  }
-}
-
-void
-BluetoothHidManager::GetAddress(BluetoothAddress& aDeviceAddress)
-{
-  aDeviceAddress = mDeviceAddress;
-}
-
-void
-BluetoothHidManager::OnUpdateSdpRecords(
-  const BluetoothAddress& aDeviceAddress)
-{
-  // Bluedroid handles this part
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothHidManager::OnGetServiceChannel(
-  const BluetoothAddress& aDeviceAddress,
-  const BluetoothUuid& aServiceUuid,
-  int aChannel)
-{
-  // Bluedroid handles this part
-  MOZ_ASSERT(false);
-}
-
-//
-// Bluetooth notifications
-//
-
-/**
- * There are totally 10 connection states, and will receive 4 possible
- * states: "connected", "connecting", "disconnected", "disconnecting".
- * Here we only handle connected and disconnected states. We do nothing
- * for remaining states.
- *
- * Possible cases are listed below:
- * CONNECTED:
- *   1. Successful inbound or outbound connection
- * DISCONNECTED:
- *   2. Attempt disconnection succeeded
- *   3. Attempt connection failed
- *   4. Either unpair from the remote device or the remote device is
- *      out of range in connected state
- */
-void
-BluetoothHidManager::ConnectionStateNotification(
-  const BluetoothAddress& aBdAddr, BluetoothHidConnectionState aState)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  BT_LOGR("state %d", aState);
-
-  if (aState == HID_CONNECTION_STATE_CONNECTED) {
-    mHidConnected = true;
-    mDeviceAddress = aBdAddr;
-    NotifyConnectionStateChanged(
-      NS_LITERAL_STRING(BLUETOOTH_HID_STATUS_CHANGED_ID));
-    OnConnect(EmptyString());
-  } else if (aState == HID_CONNECTION_STATE_DISCONNECTED) {
-    mHidConnected = false;
-    NotifyConnectionStateChanged(
-      NS_LITERAL_STRING(BLUETOOTH_HID_STATUS_CHANGED_ID));
-    OnDisconnect(EmptyString());
-  }
-}
-
-NS_IMPL_ISUPPORTS(BluetoothHidManager, nsIObserver)
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothHidManager.h
+++ /dev/null
@@ -1,82 +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_BluetoothHidManager_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothHidMnagaer_h
-
-#include "BluetoothCommon.h"
-#include "BluetoothInterface.h"
-#include "BluetoothProfileController.h"
-#include "BluetoothProfileManagerBase.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothHidManager : public BluetoothProfileManagerBase
-                          , public BluetoothHidNotificationHandler
-{
-public:
-  BT_DECL_PROFILE_MGR_BASE
-
-  static const int MAX_NUM_CLIENTS;
-
-  void OnConnectError();
-  void OnDisconnectError();
-
-  virtual void GetName(nsACString& aName)
-  {
-    aName.AssignLiteral("HID");
-  }
-
-  static BluetoothHidManager* Get();
-  static void InitHidInterface(BluetoothProfileResultHandler* aRes);
-  static void DeinitHidInterface(BluetoothProfileResultHandler* aRes);
-
-  void HandleBackendError();
-  void GetReport(const BluetoothHidReportType& aReportType,
-                 const uint8_t aReportId,
-                 const uint16_t aBufSize);
-  void SendData(const uint16_t aDataLen, const uint8_t* aData);
-  void SetReport(const BluetoothHidReportType& aReportType,
-                 const BluetoothHidReport& aReport);
-  void VirtualUnplug();
-
-protected:
-  virtual ~BluetoothHidManager();
-
-private:
-  class DeinitProfileResultHandlerRunnable;
-  class InitProfileResultHandlerRunnable;
-  class RegisterModuleResultHandler;
-  class UnregisterModuleResultHandler;
-
-  class ConnectResultHandler;
-  class DisconnectResultHandler;
-  class GetReportResultHandler;
-  class SendDataResultHandler;
-  class SetReportResultHandler;
-  class VirtualUnplugResultHandler;
-
-  BluetoothHidManager();
-  void Uninit();
-  void HandleShutdown();
-  void NotifyConnectionStateChanged(const nsAString& aType);
-
-  //
-  // Bluetooth notifications
-  //
-
-  void ConnectionStateNotification(
-    const BluetoothAddress& aBdAddr,
-    BluetoothHidConnectionState aState) override;
-
-  bool mHidConnected;
-  BluetoothAddress mDeviceAddress;
-  RefPtr<BluetoothProfileController> mController;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothHidManager_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothMapBMessage.cpp
+++ /dev/null
@@ -1,417 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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 "BluetoothMapBMessage.h"
-#include "base/basictypes.h"
-#include "plstr.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-namespace {
-  static const char kMapCrlf[] = "\r\n";
-}
-
-BluetoothMapBMessage::BluetoothMapBMessage(uint8_t* aObexBody, int aLength)
-  : mReadStatus(false)
-  , mPartId(0)
-  , mState(BMSG_PARSING_STATE_INVALID)
-  , mUnwindState(BMSG_PARSING_STATE_INVALID)
-  , mEnvelopeLevel(0)
-{
-  const nsCString body = nsCString(reinterpret_cast<const char*>(aObexBody),
-                                   aLength);
-  ProcessDecode(body.get());
-}
-
-BluetoothMapBMessage::~BluetoothMapBMessage()
-{}
-
-/**
- * Read one line by one line.
- *
- * @param aNextLineStart [in][out] On input, aNextLineStart is the start of
- *        the current line. On output, aNextLineStart is the start of the next
- *        line.
- * @param aLine [out] The next line read.
- */
-static int
-ReadLine(const char* & aNextLineStart, nsACString& aLine)
-{
-  aLine.Truncate();
-  for (;;) {
-    const char* eol = PL_strpbrk(aNextLineStart, kMapCrlf);
-
-    if (!eol) { // Reached end of file before newline
-      eol = aNextLineStart + strlen(aNextLineStart);
-    }
-
-    aLine.Append(aNextLineStart, eol - aNextLineStart);
-
-    if (*eol == '\r') {
-      ++eol;
-    }
-    if (*eol == '\n') {
-      ++eol;
-    }
-
-    aNextLineStart = eol;
-
-    if (*eol != ' ') {
-      // not a continuation
-      return 0;
-    }
-  }
-}
-
-static bool
-ExtractParameter(const nsAutoCString& aCurrLine,
-                 const char* aPattern, nsACString& aParam)
-{
-  aParam.Truncate();
-  if (aCurrLine.Find(aPattern, false, 0, PL_strlen(aPattern)) == kNotFound) {
-    return false;
-  }
-
-  int32_t colonPos = aCurrLine.FindChar(':');
-  aParam = nsDependentCSubstring(aCurrLine, colonPos + 1, aCurrLine.Length());
-  return true;
-}
-
-/*
- * |ProcessDecode| parses bMessage based on following MAP 3.1.3 Message Format.
- * The state transition follows by BMsgParserState.
- * BNF:
- * <bmessage-object>::= {
- * "BEGIN:BMSG" <CRLF>
- * <bmessage-property>
- * [<bmessage-originator>]*
- * <bmessage-envelope>
- * "END:BMSG" <CRLF>
- * }
- *
- * <bmessage-envelope> ::= {
- * "BEGIN:BENV" <CRLF>
- * [<bmessage-recipient>]*
- * <bmessage-envelope> | <bmessage-content>
- * "END:BENV" <CRLF>
- * }
- *
- * The state transition follows:
- * BEGIN_BMSG->VERSION->STATUS->TYPE->FOLDER->ORIGINATOR->VCARD->ENVELOPE->
- * VCARD->RECIPIENT->BODY->BMSG
- */
-void
-BluetoothMapBMessage::ProcessDecode(const char* aBuf)
-{
-  mState = BMSG_PARSING_STATE_BEGIN_BMSG;
-
-  static void (BluetoothMapBMessage::* const ParserActions[])(const
-    nsAutoCString&) = {
-    nullptr, /* BMSG_PARSING_STATE_INVALID */
-    &BluetoothMapBMessage::ParseBeginBmsg,
-    &BluetoothMapBMessage::ParseVersion,
-    &BluetoothMapBMessage::ParseStatus,
-    &BluetoothMapBMessage::ParseType,
-    &BluetoothMapBMessage::ParseFolder,
-    &BluetoothMapBMessage::ParseOriginator,
-    &BluetoothMapBMessage::ParseVCard,
-    &BluetoothMapBMessage::ParseEnvelope,
-    &BluetoothMapBMessage::ParseRecipient,
-    &BluetoothMapBMessage::ParseBody,
-    &BluetoothMapBMessage::ParseBMsg
-  };
-
-  for (;;) {
-    nsAutoCString curLine;
-    if (ReadLine(aBuf, curLine) == -1) {
-      // Cannot find eol symbol
-      return;
-    }
-    if (curLine.IsEmpty()) {
-      // Blank line or eof, exit
-      return;
-    }
-
-    MOZ_ASSERT(mState != BMSG_PARSING_STATE_INVALID);
-
-    // Parse bMessage
-    (this->*(ParserActions[mState]))(curLine);
-  }
-}
-
-void
-BluetoothMapBMessage::ParseBeginBmsg(const nsAutoCString& aCurrLine)
-{
-  if (aCurrLine.EqualsLiteral("BEGIN:BMSG")) {
-    mState = BMSG_PARSING_STATE_VERSION;
-  }
-}
-
-void
-BluetoothMapBMessage::ParseVersion(const nsAutoCString& aCurrLine)
-{
-  nsCString version;
-  if (ExtractParameter(aCurrLine, "VERSION:", version)) {
-    /* The value for this property shall be "VERSION:1.0",
-     * based on Message Access Profile 3.1.3.
-     */
-    if (version.EqualsLiteral("1.0")) {
-      mState = BMSG_PARSING_STATE_STATUS;
-    }
-  }
-}
-
-void
-BluetoothMapBMessage::ParseStatus(const nsAutoCString& aCurrLine)
-{
-  nsCString status;
-  if (ExtractParameter(aCurrLine, "STATUS:", status)) {
-    // only READ or UNREAD status
-    mReadStatus = status.EqualsLiteral("READ");
-    mState = BMSG_PARSING_STATE_TYPE;
-  }
-}
-
-void
-BluetoothMapBMessage::ParseType(const nsAutoCString& aCurrLine)
-{
-  nsCString type;
-  if (ExtractParameter(aCurrLine, "TYPE:", type)) {
-    mType = type;
-    mState = BMSG_PARSING_STATE_FOLDER;
-  }
-}
-
-void
-BluetoothMapBMessage::ParseFolder(const nsAutoCString& aCurrLine)
-{
-  nsCString folder;
-  if (ExtractParameter(aCurrLine, "FOLDER:", folder)) {
-    mFolderName = folder;
-  }
-
-  mState = BMSG_PARSING_STATE_ORIGINATOR;
-}
-
-void
-BluetoothMapBMessage::ParseOriginator(const nsAutoCString& aCurrLine)
-{
-  if (aCurrLine.EqualsLiteral("BEGIN:VCARD")) {
-    mOriginators.AppendElement(new VCard());
-
-    // We may parse vCard multiple times
-    mUnwindState = mState;
-    mState = BMSG_PARSING_STATE_VCARD;
-  } else if (aCurrLine.EqualsLiteral("BEGIN:BENV")) {
-    mState = BMSG_PARSING_STATE_BEGIN_ENVELOPE;
-  }
-}
-
-void
-BluetoothMapBMessage::ParseVCard(const nsAutoCString& aCurrLine)
-{
-  if (aCurrLine.EqualsLiteral("END:VCARD")) {
-    mState = mUnwindState;
-    return;
-  }
-
-  if (mUnwindState == BMSG_PARSING_STATE_ORIGINATOR &&
-      !mOriginators.IsEmpty()) {
-    mOriginators.LastElement()->Parse(aCurrLine);
-  } else if (mUnwindState == BMSG_PARSING_STATE_RECIPIENT &&
-             !mRecipients.IsEmpty()) {
-    mRecipients.LastElement()->Parse(aCurrLine);
-  }
-}
-
-void
-BluetoothMapBMessage::ParseEnvelope(const nsAutoCString& aCurrLine)
-{
-  if(!aCurrLine.EqualsLiteral("BEGIN:VCARD") &&
-     !aCurrLine.EqualsLiteral("BEGIN:BENV")) {
-    mState = BMSG_PARSING_STATE_BEGIN_BODY;
-    return;
-  }
-
-  if (aCurrLine.EqualsLiteral("BEGIN:BENV")) {
-    // nested BENV
-    // TODO: Check nested BENV envelope level for Email use case
-    ++mEnvelopeLevel;
-  }
-
-  mRecipients.AppendElement(new VCard());
-
-  mState = BMSG_PARSING_STATE_VCARD;
-  // In case there are many recipients
-  mUnwindState = BMSG_PARSING_STATE_RECIPIENT;
-}
-
-void
-BluetoothMapBMessage::ParseRecipient(const nsAutoCString& aCurrLine)
-{
-  /* After parsing vCard, check whether it's bMessage BODY or VCARD.
-   * bmessage-recipient may appear more than once.
-   */
-  if (aCurrLine.EqualsLiteral("BEGIN:BBODY")) {
-    mState = BMSG_PARSING_STATE_BEGIN_BODY;
-  } else if (aCurrLine.EqualsLiteral("BEGIN:VCARD")) {
-    mState = BMSG_PARSING_STATE_VCARD;
-  }
-}
-
-/* |ParseBody| parses based on the following BNF format:
- * <bmessage-body-property>::=[<bmessage-body-encoding-property>]
- * [<bmessage-body-charset-property>]
- * [<bmessage-body-language-property>]
- * <bmessage-body-content-length-property>
- *
- * <bmessage-content>::= {
- * "BEGIN:BBODY"<CRLF>
- * [<bmessage-body-part-ID> <CRLF>]
- * <bmessage-body-property>
- * <bmessage-body-content>* <CRLF>
- * "END:BBODY"<CRLF>
- * }
- */
-void
-BluetoothMapBMessage::ParseBody(const nsAutoCString& aCurrLine)
-{
-  nsCString param;
-  if (ExtractParameter(aCurrLine, "PARTID::", param)) {
-    nsresult rv;
-    mPartId = param.ToInteger(&rv);
-
-    if (NS_FAILED(rv)) {
-      BT_LOGR("Failed to convert PARTID, error: 0x%x",
-              static_cast<uint32_t>(rv));
-    }
-  } else if (ExtractParameter(aCurrLine, "ENCODING:", param)) {
-    mEncoding = param;
-  } else if (ExtractParameter(aCurrLine, "CHARSET:", param)) {
-    mCharset = param;
-  } else if (ExtractParameter(aCurrLine, "LANGUAGE:", param)) {
-    mLanguage = param;
-  } else if (ExtractParameter(aCurrLine, "LENGTH:", param)) {
-    mBMsgLength = param;
-  } else if (aCurrLine.EqualsLiteral("BEGIN:MSG")) {
-    // Parse <bmessage-body-content>
-    mState = BMSG_PARSING_STATE_BEGIN_MSG;
-  }
-}
-
-/* |ParseBMsg| parses based on the following BNF format:
- * <bmessage-body-content>::={
- * "BEGIN:MSG"<CRLF>
- * 'message'<CRLF>
- * "END:MSG"<CRLF>
- * }
- */
-void
-BluetoothMapBMessage::ParseBMsg(const nsAutoCString& aCurrLine)
-{
-  /* TODO: Support binary message content
-   * For SMS: currently only UTF-8 is supported for textual content.
-   */
-  if (aCurrLine.EqualsLiteral("END:MSG") ||
-      aCurrLine.EqualsLiteral("BEGIN:MSG")) {
-    /* Set state to STATE_BEGIN_MSG due to <bmessage-body-content> may appear
-     * many times.
-     */
-    mState = BMSG_PARSING_STATE_BEGIN_MSG;
-    return;
-  }
-
-  mBMsgBody += aCurrLine.get();
-  // restore <CRLF>
-  mBMsgBody.AppendLiteral(kMapCrlf);
-}
-
-void
-BluetoothMapBMessage::GetRecipients(nsTArray<RefPtr<VCard>>& aRecipients)
-{
-  aRecipients = mRecipients;
-}
-
-void
-BluetoothMapBMessage::GetOriginators(nsTArray<RefPtr<VCard>>& aOriginators)
-{
-  aOriginators = mOriginators;
-}
-
-void
-BluetoothMapBMessage::GetBody(nsACString& aBody)
-{
-  aBody = mBMsgBody;
-}
-
-void
-BluetoothMapBMessage::Dump()
-{
-  BT_LOGR("Dump: message body %s", mBMsgBody.get());
-  BT_LOGR("Dump: read status %s", mReadStatus? "true" : "false");
-  BT_LOGR("Dump: folder %s", mFolderName.get());
-  BT_LOGR("Dump encoding %s", mEncoding.get());
-  BT_LOGR("Dump charset: %s" , mCharset.get());
-  BT_LOGR("Dump language: %s", mLanguage.get());
-  BT_LOGR("Dump length: %s", mBMsgLength.get());
-  BT_LOGR("Dump type: %s ", mType.get());
-}
-
-VCard::VCard()
-{}
-
-VCard::~VCard()
-{}
-
-void
-VCard::Parse(const nsAutoCString& aCurrLine)
-{
-  nsCString param;
-  if (ExtractParameter(aCurrLine, "N:", param)) {
-    mName = param;
-  } else if (ExtractParameter(aCurrLine, "FN:", param)) {
-    mFormattedName = param;
-  } else if (ExtractParameter(aCurrLine, "TEL:", param)) {
-    mTelephone = param;
-  } else if (ExtractParameter(aCurrLine, "Email:", param)) {
-    mEmail = param;
-  }
-}
-
-void
-VCard::GetTelephone(nsACString& aTelephone)
-{
-  aTelephone = mTelephone;
-}
-
-void
-VCard::GetName(nsACString& aName)
-{
-  aName = mName;
-}
-
-void
-VCard::GetFormattedName(nsACString& aFormattedName)
-{
-  aFormattedName = mFormattedName;
-}
-
-void
-VCard::GetEmail(nsACString& aEmail)
-{
-  aEmail = mEmail;
-}
-
-void
-VCard::Dump()
-{
-  BT_LOGR("Dump: Name %s", mName.get());
-  BT_LOGR("Dump: FormattedName %s", mFormattedName.get());
-  BT_LOGR("Dump: Telephone %s", mTelephone.get());
-  BT_LOGR("Dump: Email %s", mEmail.get());
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothMapBMessage.h
+++ /dev/null
@@ -1,134 +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_BluetoothMapBMessage_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothMapBMessage_h
-
-#include "BluetoothCommon.h"
-#include "nsRefPtrHashtable.h"
-#include "nsTArray.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-enum BMsgParserState {
-  BMSG_PARSING_STATE_INVALID,
-  BMSG_PARSING_STATE_BEGIN_BMSG,
-  BMSG_PARSING_STATE_VERSION,
-  BMSG_PARSING_STATE_STATUS,
-  BMSG_PARSING_STATE_TYPE,
-  BMSG_PARSING_STATE_FOLDER,
-  BMSG_PARSING_STATE_ORIGINATOR,
-  BMSG_PARSING_STATE_VCARD,
-  BMSG_PARSING_STATE_BEGIN_ENVELOPE,
-  BMSG_PARSING_STATE_RECIPIENT,
-  BMSG_PARSING_STATE_BEGIN_BODY,
-  BMSG_PARSING_STATE_BEGIN_MSG,
-};
-
-class VCard {
-public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VCard)
-  VCard();
-
-  void Parse(const nsAutoCString& aCurrLine);
-  void GetName(nsACString& aName);
-  void GetFormattedName(nsACString& aFormattedName);
-  void GetTelephone(nsACString& aTelephone);
-  void GetEmail(nsACString& aEmail);
-  void Dump();
-
-private:
-  ~VCard();
-
-  nsCString mName;
-  nsCString mFormattedName;
-  nsCString mTelephone;
-  nsCString mEmail;
-};
-
-/* This class represents MAP bMessage. The bMessage object encapsulates
- * delivered message objects and provides additionally a suitable set properties
- * with helpful information. The general encoding characteristics as defined for
- * vCards.
- */
-class BluetoothMapBMessage
-{
-public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BluetoothMapBMessage)
-  // Parse OBEX body and return bMessage object.
-  BluetoothMapBMessage(uint8_t* aObexBody, int aLength);
-  void GetRecipients(nsTArray<RefPtr<VCard>>& aRecipients);
-  void GetOriginators(nsTArray<RefPtr<VCard>>& aRecipients);
-  void GetBody(nsACString& aBody);
-  void Dump();
-
-private:
-  ~BluetoothMapBMessage();
-  void ProcessDecode(const char* aBody);
-  void ParseBeginBmsg(const nsAutoCString& aCurrLine);
-  void ParseVersion(const nsAutoCString& aCurrLine);
-  void ParseStatus(const nsAutoCString& aCurrLine);
-  void ParseType(const nsAutoCString& aCurrLine);
-  void ParseFolder(const nsAutoCString& aCurrLine);
-  void ParseOriginator(const nsAutoCString& aCurrLine);
-  void ParseVCard(const nsAutoCString& aCurrLine);
-  void ParseEnvelope(const nsAutoCString& aCurrLine);
-  void ParseRecipient(const nsAutoCString& aCurrLine);
-  void ParseBody(const nsAutoCString& aCurrLine);
-  void ParseBMsg(const nsAutoCString& aCurrLine);
-
-  /* Indicate whether a message has been read by MCE or not.
-   * MCE shall be responsible to set this status.
-   */
-  bool mReadStatus;
-  // Indicate bMessage location
-  nsCString mFolderName;
-  /* Part-ID is used when the content cannot be delivered in ones
-   * bmessage-content object.
-   * The first bmessage-content object's part-ID shall be 0, and the following
-   * ones have part-ID incremented by 1 each.
-   */
-  int mPartId;
-  // The encoding used by bmessage-body-content if the content is binary
-  nsCString mEncoding;
-
-  /* The character-set is used in bmessage-body-content if the content
-   * is textual.
-   */
-  nsCString mCharset;
-  // mLanguage may be used if the message includes textual content
-  nsCString mLanguage;
-
-  /* Length of the bmessage-body-content, starting with the "B" of the first
-   * occurrence of "BEGIN_BMSG" and ending with the <CRLF> of the last occurrence
-   * of "END:MSG"<CRLF>.
-   */
-  nsCString mBMsgLength;
-  // mMessageBody represents bmessage-body-content
-  nsCString mBMsgBody;
-  // mType: EMAIL/SMS_GSM/SMS_CDMA/MMS
-  nsCString mType;
-  // Current parser state
-  enum BMsgParserState mState;
-  // Previous parser state
-  enum BMsgParserState mUnwindState;
-
-  /* Current level of bmessage-envelope. The maximum level of <bmessage-envelope>
-   * encapsulation shall be 3.
-   */
-  int mEnvelopeLevel;
-
-  /* Based on the formal BNF definition of the bMessage format, originators
-   * and recipients may appear 0 or more times.
-   * |mOriginators| represents the original sender of the messages, and
-   * |mRecipients| represents the recipient of the message.
-   */
-  nsTArray<RefPtr<VCard>> mOriginators;
-  nsTArray<RefPtr<VCard>> mRecipients;
-};
-
-END_BLUETOOTH_NAMESPACE
-#endif //mozilla_dom_bluetooth_bluedroid_BluetoothMapBMessage_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothMapFolder.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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 "BluetoothMapFolder.h"
-#include "base/basictypes.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-BluetoothMapFolder::~BluetoothMapFolder()
-{ }
-
-BluetoothMapFolder::BluetoothMapFolder(const nsAString& aFolderName,
-                                       BluetoothMapFolder* aParent)
-  : mName(aFolderName)
-  , mParent(aParent)
-{
-}
-
-BluetoothMapFolder*
-BluetoothMapFolder::AddSubFolder(const nsAString& aFolderName)
-{
-  RefPtr<BluetoothMapFolder> folder = new BluetoothMapFolder(aFolderName,
-                                                               this);
-  mSubFolders.Put(nsString(aFolderName), folder);
-
-  return folder;
-}
-
-BluetoothMapFolder*
-BluetoothMapFolder::GetSubFolder(const nsAString& aFolderName)
-{
-  BluetoothMapFolder* subfolder;
-  mSubFolders.Get(aFolderName, &subfolder);
-
-  return subfolder;
-}
-
-BluetoothMapFolder*
-BluetoothMapFolder::GetParentFolder()
-{
-  return mParent;
-}
-
-int
-BluetoothMapFolder::GetSubFolderCount()
-{
-  return mSubFolders.Count();
-}
-
-void
-BluetoothMapFolder::GetFolderListingObjectString(nsAString& aString,
-                                                 uint16_t aMaxListCount,
-                                                 uint16_t aStartOffset)
-{
-  const char* folderListingPrefix =
-    "<?xml version=\"1.0\"?>\n"
-    "<!DOCTYPE folder-listing SYSTEM \" obex-folder-listing.dtd\">\n"
-    "<folder-listing version=\"1.0\">\n";
-  const char* folderListingSuffix = "</folder-listing>";
-
-  // Based on Element Specification, 9.1.1, IrObex 1.2
-  nsAutoCString folderListingObejct(folderListingPrefix);
-
-  int count = 0;
-  for (auto iter = mSubFolders.Iter(); !iter.Done(); iter.Next()) {
-    if (count < aStartOffset) {
-      continue;
-    }
-
-    if (count > aMaxListCount) {
-      break;
-    }
-
-    const nsAString& key = iter.Key();
-    folderListingObejct.Append("<folder name=\"");
-    folderListingObejct.Append(NS_ConvertUTF16toUTF8(key).get());
-    folderListingObejct.Append("\"/>");
-    count++;
-  }
-
-  folderListingObejct.Append(folderListingSuffix);
-  aString = NS_ConvertUTF8toUTF16(folderListingObejct);
-}
-
-void
-BluetoothMapFolder::DumpFolderInfo()
-{
-  BT_LOGR("Folder name: %s, subfolder counts: %d",
-          NS_ConvertUTF16toUTF8(mName).get(), mSubFolders.Count());
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothMapFolder.h
+++ /dev/null
@@ -1,40 +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_BluetoothMapFolder_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothMapFolder_h
-
-#include "BluetoothCommon.h"
-#include "nsRefPtrHashtable.h"
-#include "nsTArray.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-/* This class maps MAP virtual folder structures */
-class BluetoothMapFolder
-{
-public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BluetoothMapFolder)
-
-  BluetoothMapFolder(const nsAString& aFolderName, BluetoothMapFolder* aParent);
-  // Add virtual folder to subfolders
-  BluetoothMapFolder* AddSubFolder(const nsAString& aFolderName);
-  BluetoothMapFolder* GetSubFolder(const nsAString& aFolderName);
-  BluetoothMapFolder* GetParentFolder();
-  int GetSubFolderCount();
-  // Format folder listing object string
-  void GetFolderListingObjectString(nsAString& aString, uint16_t aMaxListCount,
-                                    uint16_t aStartOffset);
-  void DumpFolderInfo();
-private:
-  ~BluetoothMapFolder();
-  nsString mName;
-  RefPtr<BluetoothMapFolder> mParent;
-  nsRefPtrHashtable<nsStringHashKey, BluetoothMapFolder> mSubFolders;
-};
-
-END_BLUETOOTH_NAMESPACE
-#endif //mozilla_dom_bluetooth_bluedroid_BluetoothMapFolder_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothMapSmsManager.cpp
+++ /dev/null
@@ -1,1666 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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 "base/basictypes.h"
-#include "BluetoothMapSmsManager.h"
-
-#include "BluetoothService.h"
-#include "BluetoothSocket.h"
-#include "BluetoothUtils.h"
-#include "BluetoothUuidHelper.h"
-#include "ObexBase.h"
-
-#include "mozilla/dom/BluetoothMapParametersBinding.h"
-#include "mozilla/dom/ipc/BlobParent.h"
-#include "mozilla/EndianUtils.h"
-#include "mozilla/dom/File.h"
-
-#include "mozilla/RefPtr.h"
-#include "mozilla/Services.h"
-#include "mozilla/StaticPtr.h"
-#include "nsIInputStream.h"
-#include "nsIObserver.h"
-#include "nsIObserverService.h"
-
-#include "mozilla/Unused.h"
-
-#define FILTER_NO_SMS_GSM   0x01
-#define FILTER_NO_SMS_CDMA  0x02
-#define FILTER_NO_EMAIL     0x04
-#define FILTER_NO_MMS       0x08
-
-USING_BLUETOOTH_NAMESPACE
-using namespace mozilla;
-using namespace mozilla::dom;
-using namespace mozilla::ipc;
-
-namespace {
-  // UUID of Map Mas
-  static const BluetoothUuid kMapMas(MAP_MAS);
-
-  // UUID of Map Mns
-  static const BluetoothUuid kMapMns(MAP_MNS);
-
-  // UUID used in Map OBEX MAS target header
-  static const BluetoothUuid kMapMasObexTarget(0xBB, 0x58, 0x2B, 0x40,
-                                               0x42, 0x0C, 0x11, 0xDB,
-                                               0xB0, 0xDE, 0x08, 0x00,
-                                               0x20, 0x0C, 0x9A, 0x66);
-
-  // UUID used in Map OBEX MNS target header
-  static const BluetoothUuid kMapMnsObexTarget(0xBB, 0x58, 0x2B, 0x41,
-                                               0x42, 0x0C, 0x11, 0xDB,
-                                               0xB0, 0xDE, 0x08, 0x00,
-                                               0x20, 0x0C, 0x9A, 0x66);
-
-  StaticRefPtr<BluetoothMapSmsManager> sMapSmsManager;
-  static bool sInShutdown = false;
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-NS_IMETHODIMP
-BluetoothMapSmsManager::Observe(nsISupports* aSubject,
-                                const char* aTopic,
-                                const char16_t* aData)
-{
-  MOZ_ASSERT(sMapSmsManager);
-
-  if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    HandleShutdown();
-    return NS_OK;
-  }
-
-  MOZ_ASSERT(false, "MapSmsManager got unexpected topic!");
-  return NS_ERROR_UNEXPECTED;
-}
-
-void
-BluetoothMapSmsManager::HandleShutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  sInShutdown = true;
-  Disconnect(nullptr);
-  Uninit();
-
-  sMapSmsManager = nullptr;
-}
-
-BluetoothMapSmsManager::BluetoothMapSmsManager()
-  : mBodyRequired(false)
-  , mFractionDeliverRequired(false)
-  , mMasConnected(false)
-  , mMnsConnected(false)
-  , mNtfRequired(false)
-{
-  BuildDefaultFolderStructure();
-}
-
-BluetoothMapSmsManager::~BluetoothMapSmsManager()
-{ }
-
-nsresult
-BluetoothMapSmsManager::Init()
-{
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  if (NS_WARN_IF(!obs)) {
-    return NS_ERROR_NOT_AVAILABLE;
-  }
-
-  auto rv = obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  /**
-   * We don't start listening here as BluetoothServiceBluedroid calls Listen()
-   * immediately when BT stops.
-   *
-   * If we start listening here, the listening fails when device boots up since
-   * Listen() is called again and restarts server socket. The restart causes
-   * absence of read events when device boots up.
-   */
-
-  return NS_OK;
-}
-
-void
-BluetoothMapSmsManager::Uninit()
-{
-  if (mMasServerSocket) {
-    mMasServerSocket->SetObserver(nullptr);
-
-    if (mMasServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-      mMasServerSocket->Close();
-    }
-    mMasServerSocket = nullptr;
-  }
-
-  if (mMasSocket) {
-    mMasSocket->SetObserver(nullptr);
-
-    if (mMasSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-      mMasSocket->Close();
-    }
-    mMasSocket = nullptr;
-  }
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  if (NS_WARN_IF(!obs)) {
-    return;
-  }
-
-  Unused << NS_WARN_IF(NS_FAILED(
-    obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)));
-}
-
-// static
-void
-BluetoothMapSmsManager::InitMapSmsInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (aRes) {
-    aRes->Init();
-  }
-}
-
-// static
-void
-BluetoothMapSmsManager::DeinitMapSmsInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (sMapSmsManager) {
-    sMapSmsManager->Uninit();
-    sMapSmsManager = nullptr;
-  }
-
-  if (aRes) {
-    aRes->Deinit();
-  }
-}
-
-//static
-BluetoothMapSmsManager*
-BluetoothMapSmsManager::Get()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Exit early if sMapSmsManager already exists
-  if (sMapSmsManager) {
-    return sMapSmsManager;
-  }
-
-  // Do not create a new instance if we're in shutdown
-  if (NS_WARN_IF(sInShutdown)) {
-    return nullptr;
-  }
-
-  // Create a new instance, register, and return
-  RefPtr<BluetoothMapSmsManager> manager = new BluetoothMapSmsManager();
-  if (NS_WARN_IF(NS_FAILED(manager->Init()))) {
-    return nullptr;
-  }
-
-  sMapSmsManager = manager;
-
-  return sMapSmsManager;
-}
-
-bool
-BluetoothMapSmsManager::Listen()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Fail to listen if |mMasSocket| already exists
-  if (NS_WARN_IF(mMasSocket)) {
-    return false;
-  }
-
-  /**
-   * Restart server socket since its underlying fd becomes invalid when
-   * BT stops; otherwise no more read events would be received even if
-   * BT restarts.
-   */
-  if (mMasServerSocket &&
-      mMasServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-    mMasServerSocket->Close();
-  }
-  mMasServerSocket = nullptr;
-
-  mMasServerSocket = new BluetoothSocket(this);
-
-  nsString sdpString;
-#if ANDROID_VERSION >= 21
-  /**
-   * The way bluedroid handles MAP SDP record is very hacky.
-   * In Lollipop version, SDP string format would be instanceId + msg type
-   * + msg name. See add_maps_sdp in btif/src/btif_sock_sdp.c
-   */
-  // MAS instance id
-  sdpString.AppendPrintf("%02x", SDP_SMS_MMS_INSTANCE_ID);
-  // Supported message type
-  sdpString.AppendPrintf("%02x", SDP_MESSAGE_TYPE_SMS_GSM |
-                                 SDP_MESSAGE_TYPE_SMS_CDMA |
-                                 SDP_MESSAGE_TYPE_MMS);
-#endif
-  /**
-   * SDP service name, we don't assign RFCOMM channel directly
-   * bluedroid automatically assign channel number randomly.
-   */
-  sdpString.AppendLiteral("SMS/MMS Message Access");
-  nsresult rv = mMasServerSocket->Listen(sdpString, kMapMas,
-                                         BluetoothSocketType::RFCOMM, -1, false,
-                                         true);
-  if (NS_FAILED(rv)) {
-    mMasServerSocket = nullptr;
-    return false;
-  }
-
-  return true;
-}
-
-void
-BluetoothMapSmsManager::MnsDataHandler(UnixSocketBuffer* aMessage)
-{
-  // Ensure valid access to data[0], i.e., opCode
-  int receivedLength = aMessage->GetSize();
-  if (receivedLength < 1) {
-    BT_LOGR("Receive empty response packet");
-    return;
-  }
-
-  const uint8_t* data = aMessage->GetData();
-  uint8_t opCode = data[0];
-  if (opCode != ObexResponseCode::Success) {
-    BT_LOGR("Unexpected OpCode: %x", opCode);
-    if (mLastCommand == ObexRequestCode::Put ||
-        mLastCommand == ObexRequestCode::Abort ||
-        mLastCommand == ObexRequestCode::PutFinal) {
-      SendMnsDisconnectRequest();
-    }
-  }
-}
-
-void
-BluetoothMapSmsManager::MasDataHandler(UnixSocketBuffer* aMessage)
-{
-  /**
-   * Ensure
-   * - valid access to data[0], i.e., opCode
-   * - received packet length smaller than max packet length
-   */
-  int receivedLength = aMessage->GetSize();
-  if (receivedLength < 1 || receivedLength > MAX_PACKET_LENGTH) {
-    SendReply(ObexResponseCode::BadRequest);
-    return;
-  }
-
-  const uint8_t* data = aMessage->GetData();
-  uint8_t opCode = data[0];
-  ObexHeaderSet pktHeaders;
-  nsString type;
-  switch (opCode) {
-    case ObexRequestCode::Connect:
-      // Section 3.3.1 "Connect", IrOBEX 1.2
-      // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
-      // [Headers:var]
-      if (receivedLength < 7 ||
-          !ParseHeaders(&data[7], receivedLength - 7, &pktHeaders)) {
-        SendReply(ObexResponseCode::BadRequest);
-        return;
-      }
-
-      // "Establishing an OBEX Session"
-      // The OBEX header target shall equal to MAS obex target UUID.
-      if (!CompareHeaderTarget(pktHeaders)) {
-        SendReply(ObexResponseCode::BadRequest);
-        return;
-      }
-
-      mRemoteMaxPacketLength = BigEndian::readUint16(&data[5]);
-
-      if (mRemoteMaxPacketLength < kObexLeastMaxSize)  {
-        BT_LOGR("Remote maximum packet length %d", mRemoteMaxPacketLength);
-        mRemoteMaxPacketLength = 0;
-        SendReply(ObexResponseCode::BadRequest);
-        return;
-      }
-
-      ReplyToConnect();
-      AfterMapSmsConnected();
-      break;
-    case ObexRequestCode::Disconnect:
-    case ObexRequestCode::Abort:
-      // Section 3.3.2 "Disconnect" and Section 3.3.5 "Abort", IrOBEX 1.2
-      // The format of request packet of "Disconnect" and "Abort" are the same
-      // [opcode:1][length:2][Headers:var]
-      if (receivedLength < 3 ||
-          !ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
-        SendReply(ObexResponseCode::BadRequest);
-        return;
-      }
-
-      ReplyToDisconnectOrAbort();
-      AfterMapSmsDisconnected();
-      break;
-    case ObexRequestCode::SetPath: {
-        // Section 3.3.6 "SetPath", IrOBEX 1.2
-        // [opcode:1][length:2][flags:1][contants:1][Headers:var]
-        if (receivedLength < 5 ||
-            !ParseHeaders(&data[5], receivedLength - 5, &pktHeaders)) {
-          SendReply(ObexResponseCode::BadRequest);
-          return;
-        }
-
-        uint8_t response = SetPath(data[3], pktHeaders);
-        if (response != ObexResponseCode::Success) {
-          SendReply(response);
-          return;
-        }
-
-        ReplyToSetPath();
-      }
-      break;
-    case ObexRequestCode::Put:
-    case ObexRequestCode::PutFinal:
-      // Section 3.3.3 "Put", IrOBEX 1.2
-      // [opcode:1][length:2][Headers:var]
-      if (receivedLength < 3 ||
-          !ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
-        SendReply(ObexResponseCode::BadRequest);
-        return;
-      }
-
-      // Multi-packet PUT request (0x02) may not contain Type header
-      if (!pktHeaders.Has(ObexHeaderId::Type)) {
-        BT_LOGR("Missing OBEX PUT request Type header");
-        SendReply(ObexResponseCode::BadRequest);
-        return;
-      }
-
-      pktHeaders.GetContentType(type);
-      BT_LOGR("Type: %s", NS_ConvertUTF16toUTF8(type).get());
-
-      if (type.EqualsLiteral("x-bt/MAP-NotificationRegistration")) {
-        HandleNotificationRegistration(pktHeaders);
-        ReplyToPut();
-      } else if (type.EqualsLiteral("x-bt/messageStatus")) {
-        HandleSetMessageStatus(pktHeaders);
-      } else if (type.EqualsLiteral("x-bt/message")) {
-        HandleSmsMmsPushMessage(pktHeaders);
-      } else if (type.EqualsLiteral("x-bt/MAP-messageUpdate")) {
-        /* MAP 5.9, There is no concept for Sms/Mms to update inbox. If the
-         * MSE does NOT allowed the polling of its mailbox it shall answer
-         * with a 'Not implemented' error response.
-         */
-        SendReply(ObexResponseCode::NotImplemented);
-      } else {
-        BT_LOGR("Unknown MAP PUT request type: %s",
-          NS_ConvertUTF16toUTF8(type).get());
-        SendReply(ObexResponseCode::NotImplemented);
-      }
-      break;
-    case ObexRequestCode::Get:
-    case ObexRequestCode::GetFinal: {
-      /* When |mDataStream| requires multiple response packets to complete,
-       * the client should continue to issue GET requests until the final body
-       * information (i.e., End-of-Body header) arrives, along with
-       * ObexResponseCode::Success
-       */
-      if (mDataStream) {
-        auto res = MakeUnique<uint8_t[]>(mRemoteMaxPacketLength);
-        if (!ReplyToGetWithHeaderBody(Move(res), kObexRespHeaderSize)) {
-          BT_LOGR("Failed to reply to MAP GET request.");
-          SendReply(ObexResponseCode::InternalServerError);
-        }
-        return;
-      }
-
-      // [opcode:1][length:2][Headers:var]
-      if (receivedLength < 3 ||
-          !ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
-        SendReply(ObexResponseCode::BadRequest);
-        return;
-      }
-
-      if (!pktHeaders.Has(ObexHeaderId::Type)) {
-        BT_LOGR("Missing OBEX GET request Type header");
-        SendReply(ObexResponseCode::BadRequest);
-        return;
-      }
-
-      pktHeaders.GetContentType(type);
-      if (type.EqualsLiteral("x-obex/folder-listing")) {
-        HandleSmsMmsFolderListing(pktHeaders);
-      } else if (type.EqualsLiteral("x-bt/MAP-msg-listing")) {
-        HandleSmsMmsMsgListing(pktHeaders);
-      } else if (type.EqualsLiteral("x-bt/message")) {
-        HandleSmsMmsGetMessage(pktHeaders);
-      } else {
-        BT_LOGR("Unknown MAP GET request type: %s",
-          NS_ConvertUTF16toUTF8(type).get());
-        SendReply(ObexResponseCode::NotImplemented);
-      }
-      break;
-    }
-    default:
-      SendReply(ObexResponseCode::NotImplemented);
-      BT_LOGR("Unrecognized ObexRequestCode %x", opCode);
-      break;
-  }
-}
-
-// Virtual function of class SocketConsumer
-void
-BluetoothMapSmsManager::ReceiveSocketData(BluetoothSocket* aSocket,
-                                          UniquePtr<UnixSocketBuffer>& aMessage)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (aSocket == mMnsSocket) {
-    MnsDataHandler(aMessage.get());
-  } else {
-    MasDataHandler(aMessage.get());
-  }
-}
-
-bool
-BluetoothMapSmsManager::CompareHeaderTarget(const ObexHeaderSet& aHeader)
-{
-  const ObexHeader* header = aHeader.GetHeader(ObexHeaderId::Target);
-
-  if (!header) {
-    BT_LOGR("No ObexHeaderId::Target in header");
-    return false;
-  }
-
-  if (header->mDataLength != sizeof(BluetoothUuid)) {
-    BT_LOGR("Length mismatch: %d != 16", header->mDataLength);
-    return false;
-  }
-
-  for (uint8_t i = 0; i < sizeof(BluetoothUuid); i++) {
-    if (header->mData[i] != kMapMasObexTarget.mUuid[i]) {
-      BT_LOGR("UUID mismatch: received target[%d]=0x%x != 0x%x",
-              i, header->mData[i], kMapMasObexTarget.mUuid[i]);
-      return false;
-    }
-  }
-
-  return true;
-}
-
-uint8_t
-BluetoothMapSmsManager::SetPath(uint8_t flags,
-                                const ObexHeaderSet& aHeader)
-{
-  // Section 5.2 "SetPath Function", MapSms 1.2
-  // flags bit 1 must be 1 and bit 2~7 be 0
-  if ((flags >> 1) != 1) {
-    BT_LOGR("Illegal flags [0x%x]: bits 1~7 must be 0x01", flags);
-    return ObexResponseCode::BadRequest;
-  }
-
-  /**
-   * Three cases:
-   * 1) Go up 1 level   - flags bit 0 is 1
-   * 2) Go back to root - flags bit 0 is 0 AND name header is empty
-   * 3) Go down 1 level - flags bit 0 is 0 AND name header is not empty,
-   *                      where name header is the name of child folder
-   */
-  if (flags & 1) {
-    // Go up 1 level
-    BluetoothMapFolder* parent = mCurrentFolder->GetParentFolder();
-    if (!parent) {
-      mCurrentFolder = parent;
-      BT_LOGR("MAS SetPath Go up 1 level");
-    }
-  } else {
-    MOZ_ASSERT(aHeader.Has(ObexHeaderId::Name));
-
-    nsString childFolderName;
-    aHeader.GetName(childFolderName);
-
-    if (childFolderName.IsEmpty()) {
-      // Go back to root
-      mCurrentFolder = mRootFolder;
-      BT_LOGR("MAS SetPath Go back to root");
-    } else {
-      // Go down 1 level
-      BluetoothMapFolder* child = mCurrentFolder->GetSubFolder(childFolderName);
-      if (!child) {
-        BT_LOGR("Illegal sub-folder name [%s]",
-                NS_ConvertUTF16toUTF8(childFolderName).get());
-        return ObexResponseCode::NotFound;
-      }
-
-      mCurrentFolder = child;
-      BT_LOGR("MAS SetPath Go down to 1 level");
-    }
-  }
-
-  mCurrentFolder->DumpFolderInfo();
-
-  return ObexResponseCode::Success;
-}
-
-void
-BluetoothMapSmsManager::AfterMapSmsConnected()
-{
-  mMasConnected = true;
-}
-
-void
-BluetoothMapSmsManager::AfterMapSmsDisconnected()
-{
-  mMasConnected = false;
-  mBodyRequired = false;
-  mFractionDeliverRequired = false;
-
-  // To ensure we close MNS connection
-  DestroyMnsObexConnection();
-}
-
-bool
-BluetoothMapSmsManager::IsConnected()
-{
-  return mMasConnected;
-}
-
-void
-BluetoothMapSmsManager::GetAddress(BluetoothAddress& aDeviceAddress)
-{
-  return mMasSocket->GetAddress(aDeviceAddress);
-}
-
-void
-BluetoothMapSmsManager::ReplyToConnect()
-{
-  if (mMasConnected) {
-    return;
-  }
-
-  // Section 3.3.1 "Connect", IrOBEX 1.2
-  // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
-  // [Headers:var]
-  uint8_t req[255];
-  int index = 7;
-
-  req[3] = 0x10; // version=1.0
-  req[4] = 0x00; // flag=0x00
-  BigEndian::writeUint16(&req[5], BluetoothMapSmsManager::MAX_PACKET_LENGTH);
-
-  // Section 6.4 "Establishing an OBEX Session", MapSms 1.2
-  // Headers: [Who:16][Connection ID]
-  index += AppendHeaderWho(&req[index], 255, kMapMasObexTarget.mUuid,
-                           sizeof(BluetoothUuid));
-  index += AppendHeaderConnectionId(&req[index], 0x01);
-  SendMasObexData(req, ObexResponseCode::Success, index);
-}
-
-void
-BluetoothMapSmsManager::ReplyToDisconnectOrAbort()
-{
-  if (!mMasConnected) {
-    return;
-  }
-
-  // Section 3.3.2 "Disconnect" and Section 3.3.5 "Abort", IrOBEX 1.2
-  // The format of response packet of "Disconnect" and "Abort" are the same
-  // [opcode:1][length:2][Headers:var]
-  uint8_t req[255];
-  int index = 3;
-
-  SendMasObexData(req, ObexResponseCode::Success, index);
-}
-
-void
-BluetoothMapSmsManager::ReplyToSetPath()
-{
-  if (!mMasConnected) {
-    return;
-  }
-
-  // Section 3.3.6 "SetPath", IrOBEX 1.2
-  // [opcode:1][length:2][Headers:var]
-  uint8_t req[255];
-  int index = 3;
-
-  SendMasObexData(req, ObexResponseCode::Success, index);
-}
-
-bool
-BluetoothMapSmsManager::ReplyToGetWithHeaderBody(UniquePtr<uint8_t[]> aResponse,
-                                                 unsigned int aIndex)
-{
-  if (!mMasConnected) {
-    return false;
-  }
-
-  /**
-   * This response consists of following parts:
-   * - Part 1: [response code:1][length:2]
-   * - Part 2a: [headerId:1][length:2][EndOfBody:0]
-   *   or
-   * - Part 2b: [headerId:1][length:2][Body:var]
-   */
-  // ---- Part 1: [response code:1][length:2] ---- //
-  // [response code:1][length:2] will be set in |SendObexData|.
-  // Reserve index for them here
-  uint64_t bytesAvailable = 0;
-  nsresult rv = mDataStream->Available(&bytesAvailable);
-  if (NS_FAILED(rv)) {
-    BT_LOGR("Failed to get available bytes from input stream. rv=0x%x",
-            static_cast<uint32_t>(rv));
-    return false;
-  }
-
-  /* In practice, some platforms can only handle zero length End-of-Body
-   * header separately with Body header.
-   * Thus, append End-of-Body only if the data stream had been sent out,
-   * otherwise, send 'Continue' to request for next GET request.
-   */
-  unsigned int opcode;
-  if (!bytesAvailable) {
-    // ----  Part 2a: [headerId:1][length:2][EndOfBody:0] ---- //
-    aIndex += AppendHeaderEndOfBody(&aResponse[aIndex]);
-
-    // Close input stream
-    mDataStream->Close();
-    mDataStream = nullptr;
-
-    opcode = ObexResponseCode::Success;
-  } else {
-    // ---- Part 2b: [headerId:1][length:2][Body:var] ---- //
-    MOZ_ASSERT(mDataStream);
-
-    // Compute remaining packet size to append Body, excluding Body's header
-    uint32_t remainingPacketSize =
-      mRemoteMaxPacketLength - kObexBodyHeaderSize - aIndex;
-
-    // Read blob data from input stream
-    uint32_t numRead = 0;
-    auto buf = MakeUnique<char[]>(remainingPacketSize);
-    nsresult rv = mDataStream->Read(buf.get(), remainingPacketSize, &numRead);
-    if (NS_FAILED(rv)) {
-      BT_LOGR("Failed to read from input stream. rv=0x%x",
-              static_cast<uint32_t>(rv));
-      return false;
-    }
-
-    // |numRead| must be non-zero
-    MOZ_ASSERT(numRead);
-
-    aIndex += AppendHeaderBody(&aResponse[aIndex],
-                               remainingPacketSize,
-                               reinterpret_cast<uint8_t*>(buf.get()),
-                               numRead);
-
-    opcode = ObexResponseCode::Continue;
-  }
-
-  SendMasObexData(Move(aResponse), opcode, aIndex);
-
-  return true;
-}
-
-void
-BluetoothMapSmsManager::ReplyToPut()
-{
-  if (!mMasConnected) {
-    return;
-  }
-
-  // Section 3.3.3.2 "PutResponse", IrOBEX 1.2
-  // [opcode:1][length:2][Headers:var]
-  uint8_t req[kObexRespHeaderSize];
-
-  SendMasObexData(req, ObexResponseCode::Success, kObexRespHeaderSize);
-}
-
-bool
-BluetoothMapSmsManager::ReplyToFolderListing(long aMasId,
-                                             const nsAString& aFolderlists)
-{
-  // TODO: Implement this for future Email support
-  return false;
-}
-
-bool
-BluetoothMapSmsManager::ReplyToMessagesListing(BlobParent* aActor,
-                                               long aMasId,
-                                               bool aNewMessage,
-                                               const nsAString& aTimestamp,
-                                               int aSize)
-{
-  RefPtr<BlobImpl> impl = aActor->GetBlobImpl();
-  RefPtr<Blob> blob = Blob::Create(nullptr, impl);
-
-  return ReplyToMessagesListing(blob.get(), aMasId, aNewMessage, aTimestamp,
-                                aSize);
-}
-
-bool
-BluetoothMapSmsManager::ReplyToMessagesListing(Blob* aBlob, long aMasId,
-                                               bool aNewMessage,
-                                               const nsAString& aTimestamp,
-                                               int aSize)
-{
-  /* If the response code is 0x90 or 0xA0, response consists of following parts:
-   * - Part 1: [response code:1][length:2]
-   * - Part 2: [headerId:1][length:2][appParam:var]
-   *   where [appParam:var] includes:
-   *   [NewMessage:3] = [tagId:1][length:1][value:1]
-   *   [MseTime:var] = [tagId:1][length:1][value:var]
-   *   [MessageListingSize:4] = [tagId:1][length:1][value:2]
-   * If mBodyRequired is true,
-   * - Part 3: [headerId:1][length:2][Body:var]
-   */
-  // ---- Part 1: [response code:1][length:2] ---- //
-  // [response code:1][length:2] will be set in |SendObexData|.
-  // Reserve index here
-  auto res = MakeUnique<uint8_t[]>(mRemoteMaxPacketLength);
-  unsigned int index = kObexRespHeaderSize;
-
-  // ---- Part 2: headerId:1][length:2][appParam:var] ---- //
-  // MSETime - String with the current time basis and UTC-offset of the MSE
-  nsCString timestampStr = NS_ConvertUTF16toUTF8(aTimestamp);
-  const uint8_t* str = reinterpret_cast<const uint8_t*>(timestampStr.get());
-  uint8_t len = timestampStr.Length();
-
-  // Total length: [NewMessage:3] + [MseTime:var] + [MessageListingSize:4]
-  auto appParameters = MakeUnique<uint8_t[]>(len + 9);
-  uint8_t newMessage = aNewMessage ? 1 : 0;
-
-  AppendAppParameter(&appParameters[0],
-                     3,
-                     (uint8_t) Map::AppParametersTagId::NewMessage,
-                     &newMessage,
-                     sizeof(newMessage));
-
-  AppendAppParameter(&appParameters[3],
-                     len + 2,
-                     (uint8_t) Map::AppParametersTagId::MSETime,
-                     str,
-                     len);
-
-  uint8_t msgListingSize[2];
-  BigEndian::writeUint16(&msgListingSize[0], aSize);
-
-  AppendAppParameter(&appParameters[5 + len],
-                     4,
-                     (uint8_t) Map::AppParametersTagId::MessagesListingSize,
-                     msgListingSize,
-                     sizeof(msgListingSize));
-
-  index += AppendHeaderAppParameters(&res[index],
-                                     mRemoteMaxPacketLength,
-                                     appParameters.get(),
-                                     len + 9);
-
-  if (mBodyRequired) {
-    // Open input stream only if |mBodyRequired| is true
-    if (!GetInputStreamFromBlob(aBlob)) {
-      SendReply(ObexResponseCode::InternalServerError);
-      return false;
-    }
-
-    // ---- Part 3: [headerId:1][length:2][Body:var] ---- //
-    ReplyToGetWithHeaderBody(Move(res), index);
-    // Reset flag
-    mBodyRequired = false;
-  } else {
-    SendMasObexData(Move(res), ObexResponseCode::Success, index);
-  }
-
-  return true;
-}
-
-bool
-BluetoothMapSmsManager::ReplyToGetMessage(BlobParent* aActor, long aMasId)
-{
-  RefPtr<BlobImpl> impl = aActor->GetBlobImpl();
-  RefPtr<Blob> blob = Blob::Create(nullptr, impl);
-
-  return ReplyToGetMessage(blob.get(), aMasId);
-}
-
-bool
-BluetoothMapSmsManager::ReplyToGetMessage(Blob* aBlob, long aMasId)
-{
-  if (!GetInputStreamFromBlob(aBlob)) {
-    SendReply(ObexResponseCode::InternalServerError);
-    return false;
-  }
-
-  /*
-   * If the response code is 0x90 or 0xA0, response consists of following parts:
-   * - Part 1: [response code:1][length:2]
-   * If mFractionDeliverRequired is true,
-   * - Part 2: [headerId:1][length:2][appParameters:3]
-   * - Part 3: [headerId:1][length:2][Body:var]
-   *   where [appParameters] includes:
-   *   [FractionDeliver:3] = [tagId:1][length:1][value: 1]
-   * otherwise,
-   * - Part 2: [headerId:1][length:2][appParameters:3]
-   */
-  // ---- Part 1: [response code:1][length:2] ---- //
-  // [response code:1][length:2] will be set in |SendObexData|.
-  // Reserve index here
-  auto res = MakeUnique<uint8_t[]>(mRemoteMaxPacketLength);
-  unsigned int index = kObexRespHeaderSize;
-
-  if (mFractionDeliverRequired) {
-    // ---- Part 2: [headerId:1][length:2][appParam:3] ---- //
-    uint8_t appParameters[3];
-    // TODO: Support FractionDeliver, reply "1(last)" now.
-    uint8_t fractionDeliver = 1;
-    AppendAppParameter(appParameters,
-                       sizeof(appParameters),
-                       (uint8_t) Map::AppParametersTagId::FractionDeliver,
-                       &fractionDeliver,
-                       sizeof(fractionDeliver));
-
-    index += AppendHeaderAppParameters(&res[index],
-                                       mRemoteMaxPacketLength,
-                                       appParameters,
-                                       sizeof(appParameters));
-  }
-
-  // TODO: Support bMessage encoding in bug 1166652.
-  // ---- Part 3: [headerId:1][length:2][Body:var] ---- //
-  ReplyToGetWithHeaderBody(Move(res), index);
-  mFractionDeliverRequired = false;
-
-  return true;
-}
-
-bool
-BluetoothMapSmsManager::ReplyToSendMessage(
-  long aMasId, const nsAString& aHandleId, bool aStatus)
-{
-  if (!aStatus) {
-    SendReply(ObexResponseCode::InternalServerError);
-    return true;
-  }
-
-  /* Handle is mandatory if the response code is success (0x90 or 0xA0).
-   * The Name header shall be used to contain the handle that was assigned by
-   * the MSE device to the message that was pushed by the MCE device.
-   * The handle shall be represented by a null-terminated Unicode text strings
-   * with 16 hexadecimal digits.
-   */
-  int len = aHandleId.Length();
-  auto handleId = MakeUnique<uint8_t[]>((len + 1) * 2);
-
-  for (int i = 0; i < len; i++) {
-    BigEndian::writeUint16(&handleId[i * 2], aHandleId[i]);
-  }
-  BigEndian::writeUint16(&handleId[len * 2], 0);
-
-  auto res = MakeUnique<uint8_t[]>(mRemoteMaxPacketLength);
-  int index = kObexRespHeaderSize;
-  index += AppendHeaderName(&res[index], mRemoteMaxPacketLength - index,
-                            handleId.get(), (len + 1) * 2);
-  SendMasObexData(Move(res), ObexResponseCode::Success, index);
-
-  return true;
-}
-
-bool
-BluetoothMapSmsManager::ReplyToSetMessageStatus(long aMasId, bool aStatus)
-{
-  SendReply(aStatus ? ObexResponseCode::Success :
-                      ObexResponseCode::InternalServerError);
-  return true;
-}
-
-bool
-BluetoothMapSmsManager::ReplyToMessageUpdate(long aMasId, bool aStatus)
-{
-  SendReply(aStatus ? ObexResponseCode::Success :
-                      ObexResponseCode::InternalServerError);
-  return true;
-}
-
-void
-BluetoothMapSmsManager::CreateMnsObexConnection()
-{
-  if (mMnsSocket) {
-    return;
-  }
-
-  mMnsSocket = new BluetoothSocket(this);
-  // Already encrypted in previous session
-  mMnsSocket->Connect(mDeviceAddress, kMapMns,
-                      BluetoothSocketType::RFCOMM, -1, false, false);
-}
-
-void
-BluetoothMapSmsManager::DestroyMnsObexConnection()
-{
-  if (!mMnsSocket) {
-    return;
-  }
-
-  mMnsSocket->Close();
-  mMnsSocket = nullptr;
-  mNtfRequired = false;
-}
-
-void
-BluetoothMapSmsManager::SendMnsConnectRequest()
-{
-  MOZ_ASSERT(mMnsSocket);
-
-  // Section 3.3.1 "Connect", IrOBEX 1.2
-  // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
-  // [Headers:var]
-  uint8_t req[255];
-  int index = 7;
-
-  req[3] = 0x10; // version=1.0
-  req[4] = 0x00; // flag=0x00
-  req[5] = BluetoothMapSmsManager::MAX_PACKET_LENGTH >> 8;
-  req[6] = (uint8_t)BluetoothMapSmsManager::MAX_PACKET_LENGTH;
-
-  index += AppendHeaderTarget(&req[index], 255, kMapMnsObexTarget.mUuid,
-                              sizeof(BluetoothUuid));
-  SendMnsObexData(req, ObexRequestCode::Connect, index);
-}
-
-void
-BluetoothMapSmsManager::SendMnsDisconnectRequest()
-{
-  MOZ_ASSERT(mMnsSocket);
-
-  if (!mMasConnected) {
-    return;
-  }
-
-  // Section 3.3.2 "Disconnect", IrOBEX 1.2
-  // [opcode:1][length:2][Headers:var]
-  uint8_t req[255];
-  int index = 3;
-
-  SendMnsObexData(req, ObexRequestCode::Disconnect, index);
-}
-
-void
-BluetoothMapSmsManager::HandleSmsMmsFolderListing(const ObexHeaderSet& aHeader)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  uint8_t buf[64];
-  uint16_t maxListCount = 0;
-
-  if (aHeader.GetAppParameter(Map::AppParametersTagId::MaxListCount,
-                              buf, 64)) {
-    maxListCount = BigEndian::readUint16(buf);
-  }
-
-  uint16_t startOffset = 0;
-  if (aHeader.GetAppParameter(Map::AppParametersTagId::StartOffset,
-                              buf, 64)) {
-    startOffset = BigEndian::readUint16(buf);
-  }
-
-  // Folder listing size
-  int foldersize = mCurrentFolder->GetSubFolderCount();
-
-  uint8_t folderListingSizeValue[2];
-  BigEndian::writeUint16(&folderListingSizeValue[0], foldersize);
-
-  // Section 3.3.4 "GetResponse", IrOBEX 1.2
-  // [opcode:1][length:2][FolderListingSize:4][Headers:var] where
-  // Application Parameter [FolderListingSize:4] = [tagId:1][length:1][value: 2]
-  uint8_t appParameter[4];
-  AppendAppParameter(appParameter, sizeof(appParameter),
-                     (uint8_t)Map::AppParametersTagId::FolderListingSize,
-                     folderListingSizeValue, sizeof(folderListingSizeValue));
-
-  uint8_t resp[255];
-  int index = 3;
-  index += AppendHeaderAppParameters(&resp[index], 255, appParameter,
-                                     sizeof(appParameter));
-
-  /*
-   * MCE wants to query sub-folder size FolderListingSize AppParameter shall
-   * be used in the response if the value of MaxListCount in the request is 0.
-   * If MaxListCount = 0, the MSE shall ignore all other applications
-   * parameters that may be presented in the request. The response shall
-   * contain any Body header.
-   */
-  if (maxListCount) {
-    nsString output;
-    mCurrentFolder->GetFolderListingObjectString(output, maxListCount,
-                                                 startOffset);
-    index += AppendHeaderBody(&resp[index],
-                              mRemoteMaxPacketLength - index,
-                              reinterpret_cast<const uint8_t*>(
-                                NS_ConvertUTF16toUTF8(output).get()),
-                              NS_ConvertUTF16toUTF8(output).Length());
-
-    index += AppendHeaderEndOfBody(&resp[index]);
-  }
-
-  SendMasObexData(resp, ObexResponseCode::Success, index);
-}
-
-void
-BluetoothMapSmsManager::AppendBtNamedValueByTagId(
-  const ObexHeaderSet& aHeader,
-  InfallibleTArray<BluetoothNamedValue>& aValues,
-  const Map::AppParametersTagId aTagId)
-{
-  uint8_t buf[64];
-  if (!aHeader.GetAppParameter(aTagId, buf, 64)) {
-    return;
-  }
-
-  /*
-   * Follow MAP 6.3.1 Application Parameter Header
-   */
-  switch (aTagId) {
-    case Map::AppParametersTagId::MaxListCount: {
-      uint16_t maxListCount = BigEndian::readUint16(buf);
-      /* MAP specification 5.4.3.1/5.5.4.1
-       * If MaxListCount = 0, the response shall not contain the Body header.
-       * The MSE shall ignore the request-parameters "ListStartOffset",
-       * "SubjectLength" and "ParameterMask".
-       */
-      mBodyRequired = (maxListCount != 0);
-      BT_LOGR("max list count: %d", maxListCount);
-      AppendNamedValue(aValues, "maxListCount",
-                       static_cast<uint32_t>(maxListCount));
-      break;
-    }
-    case Map::AppParametersTagId::StartOffset: {
-      uint16_t startOffset = BigEndian::readUint16(buf);
-      BT_LOGR("start offset : %d", startOffset);
-      AppendNamedValue(aValues, "startOffset",
-                       static_cast<uint32_t>(startOffset));
-      break;
-    }
-    case Map::AppParametersTagId::SubjectLength: {
-      uint8_t subLength = *((uint8_t *)buf);
-      BT_LOGR("msg subLength : %d", subLength);
-      AppendNamedValue(aValues, "subLength", static_cast<uint32_t>(subLength));
-      break;
-    }
-    case Map::AppParametersTagId::ParameterMask: {
-      InfallibleTArray<uint32_t> parameterMask = PackParameterMask(buf, 64);
-      AppendNamedValue(aValues, "parameterMask", BluetoothValue(parameterMask));
-      break;
-    }
-    case Map::AppParametersTagId::FilterMessageType: {
-      /* Follow MAP 1.2, 6.3.1
-       * 0000xxx1 = "SMS_GSM"
-       * 0000xx1x = "SMS_CDMA"
-       * 0000x1xx = "EMAIL"
-       * 00001xxx = "MMS"
-       * Where
-       * 0 = "no filtering, get this type"
-       * 1 = "filter out this type"
-       */
-      uint32_t filterMessageType = *((uint8_t *)buf);
-
-      if (filterMessageType == (FILTER_NO_EMAIL | FILTER_NO_MMS |
-                                FILTER_NO_SMS_GSM) ||
-          filterMessageType == (FILTER_NO_EMAIL | FILTER_NO_MMS |
-                                FILTER_NO_SMS_CDMA)) {
-        filterMessageType = static_cast<uint32_t>(MessageType::Sms);
-      } else if (filterMessageType == (FILTER_NO_EMAIL | FILTER_NO_SMS_GSM |
-                                       FILTER_NO_SMS_CDMA)) {
-        filterMessageType = static_cast<uint32_t>(MessageType::Mms);
-      } else if (filterMessageType == (FILTER_NO_MMS | FILTER_NO_SMS_GSM |
-                                          FILTER_NO_SMS_CDMA)) {
-        filterMessageType = static_cast<uint32_t>(MessageType::Email);
-      } else {
-        BT_LOGR("Unsupportted filter message type");
-        filterMessageType = static_cast<uint32_t>(MessageType::Sms);
-      }
-
-      BT_LOGR("msg filterMessageType : %d", filterMessageType);
-      AppendNamedValue(aValues, "filterMessageType",
-                       static_cast<uint32_t>(filterMessageType));
-      break;
-    }
-    case Map::AppParametersTagId::FilterPeriodBegin: {
-      nsCString filterPeriodBegin((char *) buf);
-      BT_LOGR("msg FilterPeriodBegin : %s", filterPeriodBegin.get());
-      AppendNamedValue(aValues, "filterPeriodBegin",
-                       NS_ConvertUTF8toUTF16(filterPeriodBegin));
-      break;
-    }
-    case Map::AppParametersTagId::FilterPeriodEnd: {
-      nsCString filterPeriodEnd((char*)buf);
-      BT_LOGR("msg filterPeriodEnd : %s", filterPeriodEnd.get());
-      AppendNamedValue(aValues, "filterPeriodEnd",
-                       NS_ConvertUTF8toUTF16(filterPeriodEnd));
-      break;
-    }
-    case Map::AppParametersTagId::FilterReadStatus: {
-      using namespace mozilla::dom::ReadStatusValues;
-      uint32_t filterReadStatus =
-        buf[0] < ArrayLength(strings) ? static_cast<uint32_t>(buf[0]) : 0;
-      BT_LOGR("msg filter read status : %d", filterReadStatus);
-      AppendNamedValue(aValues, "filterReadStatus", filterReadStatus);
-      break;
-    }
-    case Map::AppParametersTagId::FilterRecipient: {
-      // FilterRecipient encodes as UTF-8
-      nsCString filterRecipient((char*) buf);
-      BT_LOGR("msg filterRecipient : %s", filterRecipient.get());
-      AppendNamedValue(aValues, "filterRecipient",
-                       NS_ConvertUTF8toUTF16(filterRecipient));
-      break;
-    }
-    case Map::AppParametersTagId::FilterOriginator: {
-      // FilterOriginator encodes as UTF-8
-      nsCString filterOriginator((char*) buf);
-      BT_LOGR("msg filter Originator : %s", filterOriginator.get());
-      AppendNamedValue(aValues, "filterOriginator",
-                       NS_ConvertUTF8toUTF16(filterOriginator));
-      break;
-    }
-    case Map::AppParametersTagId::FilterPriority: {
-      using namespace mozilla::dom::PriorityValues;
-      uint32_t filterPriority =
-        buf[0] < ArrayLength(strings) ? static_cast<uint32_t>(buf[0]) : 0;
-
-      BT_LOGR("msg filter priority: %d", filterPriority);
-      AppendNamedValue(aValues, "filterPriority", filterPriority);
-      break;
-    }
-    case Map::AppParametersTagId::Attachment: {
-      uint8_t attachment = *((uint8_t *)buf);
-      BT_LOGR("msg filter attachment: %d", attachment);
-      AppendNamedValue(aValues, "attachment", static_cast<uint32_t>(attachment));
-      break;
-    }
-    case Map::AppParametersTagId::Charset: {
-      using namespace mozilla::dom::FilterCharsetValues;
-      uint32_t filterCharset =
-        buf[0] < ArrayLength(strings) ? static_cast<uint32_t>(buf[0]) : 0;
-
-      BT_LOGR("msg filter charset: %d", filterCharset);
-      AppendNamedValue(aValues, "charset", filterCharset);
-      break;
-    }
-    case Map::AppParametersTagId::FractionRequest: {
-      mFractionDeliverRequired = true;
-      AppendNamedValue(aValues, "fractionRequest", (buf[0] != 0));
-      break;
-    }
-    case Map::AppParametersTagId::StatusIndicator: {
-      using namespace mozilla::dom::StatusIndicatorsValues;
-      uint32_t filterStatusIndicator =
-        buf[0] < ArrayLength(strings) ? static_cast<uint32_t>(buf[0]) : 0;
-
-      BT_LOGR("msg filter statusIndicator: %d", filterStatusIndicator);
-      AppendNamedValue(aValues, "statusIndicator", filterStatusIndicator);
-      break;
-    }
-    case Map::AppParametersTagId::StatusValue: {
-      uint8_t statusValue = *((uint8_t *)buf);
-      BT_LOGR("msg filter statusvalue: %d", statusValue);
-      AppendNamedValue(aValues, "statusValue",
-                       static_cast<uint32_t>(statusValue));
-      break;
-    }
-    case Map::AppParametersTagId::Transparent: {
-      uint8_t transparent = *((uint8_t *)buf);
-      BT_LOGR("msg filter statusvalue: %d", transparent);
-      AppendNamedValue(aValues, "transparent",
-                       static_cast<uint32_t>(transparent));
-      break;
-    }
-    case Map::AppParametersTagId::Retry: {
-      uint8_t retry = *((uint8_t *)buf);
-      BT_LOGR("msg filter retry: %d", retry);
-      AppendNamedValue(aValues, "retry", static_cast<uint32_t>(retry));
-      break;
-    }
-    default:
-      BT_LOGR("Unsupported AppParameterTag: %x", aTagId);
-      break;
-  }
-}
-
-InfallibleTArray<uint32_t>
-BluetoothMapSmsManager::PackParameterMask(uint8_t* aData, int aSize)
-{
-  InfallibleTArray<uint32_t> parameterMask;
-
-  /* Table 6.5, MAP 6.3.1. ParameterMask is Bit 16-31 Reserved for future
-   * use. The reserved bits shall be set to 0 by MCE and discarded by MSE.
-   * convert big endian to little endian
-   */
-  uint32_t x = BigEndian::readUint32(aData);
-
-  uint32_t count = 0;
-  while (x) {
-    if (x & 1) {
-      parameterMask.AppendElement(count);
-    }
-
-    ++count;
-    x >>= 1;
-  }
-
-  return parameterMask;
-}
-
-void
-BluetoothMapSmsManager::HandleSmsMmsMsgListing(const ObexHeaderSet& aHeader)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-
-  InfallibleTArray<BluetoothNamedValue> data;
-
-  static Map::AppParametersTagId sMsgListingParameters[] = {
-    [0] = Map::AppParametersTagId::MaxListCount,
-    [1] = Map::AppParametersTagId::StartOffset,
-    [2] = Map::AppParametersTagId::SubjectLength,
-    [3] = Map::AppParametersTagId::ParameterMask,
-    [4] = Map::AppParametersTagId::FilterMessageType,
-    [5] = Map::AppParametersTagId::FilterPeriodBegin,
-    [6] = Map::AppParametersTagId::FilterPeriodEnd,
-    [7] = Map::AppParametersTagId::FilterReadStatus,
-    [8] = Map::AppParametersTagId::FilterRecipient,
-    [9] = Map::AppParametersTagId::FilterOriginator,
-    [10] = Map::AppParametersTagId::FilterPriority
-  };
-
-  for (uint8_t i = 0; i < MOZ_ARRAY_LENGTH(sMsgListingParameters); i++) {
-    AppendBtNamedValueByTagId(aHeader, data, sMsgListingParameters[i]);
-  }
-
-  bs->DistributeSignal(NS_LITERAL_STRING(MAP_MESSAGES_LISTING_REQ_ID),
-                       NS_LITERAL_STRING(KEY_ADAPTER),
-                       data);
-}
-
-void
-BluetoothMapSmsManager::HandleSmsMmsGetMessage(const ObexHeaderSet& aHeader)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  InfallibleTArray<BluetoothNamedValue> data;
-  nsString name;
-  aHeader.GetName(name);
-  AppendNamedValue(data, "handle", name);
-
-  AppendBtNamedValueByTagId(aHeader, data,
-                            Map::AppParametersTagId::Attachment);
-  AppendBtNamedValueByTagId(aHeader, data,
-                            Map::AppParametersTagId::Charset);
-  AppendBtNamedValueByTagId(aHeader, data,
-                            Map::AppParametersTagId::FractionRequest);
-
-  bs->DistributeSignal(NS_LITERAL_STRING(MAP_GET_MESSAGE_REQ_ID),
-                       NS_LITERAL_STRING(KEY_ADAPTER),
-                       data);
-}
-
-void
-BluetoothMapSmsManager::BuildDefaultFolderStructure()
-{
-  /* MAP specification defines virtual folders structure
-   * /
-   * /telecom
-   * /telecom/msg
-   * /telecom/msg/inbox
-   * /telecom/msg/draft
-   * /telecom/msg/outbox
-   * /telecom/msg/sent
-   * /telecom/msg/deleted
-   */
-  mRootFolder = new BluetoothMapFolder(NS_LITERAL_STRING("root"), nullptr);
-  BluetoothMapFolder* folder =
-    mRootFolder->AddSubFolder(NS_LITERAL_STRING("telecom"));
-  folder = folder->AddSubFolder(NS_LITERAL_STRING("msg"));
-
-  // Add mandatory folders
-  folder->AddSubFolder(NS_LITERAL_STRING("inbox"));
-  folder->AddSubFolder(NS_LITERAL_STRING("sent"));
-  folder->AddSubFolder(NS_LITERAL_STRING("deleted"));
-  folder->AddSubFolder(NS_LITERAL_STRING("outbox"));
-  folder->AddSubFolder(NS_LITERAL_STRING("draft"));
-  mCurrentFolder = mRootFolder;
-}
-
-void
-BluetoothMapSmsManager::HandleNotificationRegistration(
-  const ObexHeaderSet& aHeader)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  uint8_t buf[64];
-  if (!aHeader.GetAppParameter(Map::AppParametersTagId::NotificationStatus,
-                               buf, 64)) {
-    return;
-  }
-
-  bool ntfRequired = static_cast<bool>(buf[0]);
-  if (mNtfRequired == ntfRequired) {
-    // Ignore request
-    return;
-  }
-
-  mNtfRequired = ntfRequired;
-  /*
-   * Initialization sequence for a MAP session that uses both the Messsage
-   * Access service and the Message Notification service. The MNS connection
-   * shall be established by the first SetNotificationRegistration set to ON
-   * during MAP session. Only one MNS connection per device pair.
-   * Section 6.4.2, MAP
-   * If the Message Access connection is disconnected after Message Notification
-   * connection establishment, this will automatically indicate a MAS
-   * Notification-Deregistration for this MAS instance.
-   */
-  if (mNtfRequired) {
-    CreateMnsObexConnection();
-  } else {
-    /*
-     * TODO: we shall check multiple MAS instances unregister notification to
-     * drop MNS connection, but now we only support SMS/MMS, so drop connection
-     * directly.
-     */
-    DestroyMnsObexConnection();
-  }
-}
-
-void
-BluetoothMapSmsManager::HandleSetMessageStatus(const ObexHeaderSet& aHeader)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  InfallibleTArray<BluetoothNamedValue> data;
-  nsString name;
-  aHeader.GetName(name);
-  /* The Name header shall contain the handle of the message the status of which
-   * shall be modified. The handle shall be represented by a null-terminated
-   * Unicode text string with 16 hexadecimal digits.
-   */
-  AppendNamedValue(data, "handle", name);
-
-  AppendBtNamedValueByTagId(aHeader, data,
-                            Map::AppParametersTagId::StatusIndicator);
-  AppendBtNamedValueByTagId(aHeader, data,
-                            Map::AppParametersTagId::StatusValue);
-
-  bs->DistributeSignal(NS_LITERAL_STRING(MAP_SET_MESSAGE_STATUS_REQ_ID),
-                       NS_LITERAL_STRING(KEY_ADAPTER), data);
-}
-
-void
-BluetoothMapSmsManager::HandleSmsMmsPushMessage(const ObexHeaderSet& aHeader)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  if (!aHeader.Has(ObexHeaderId::Body) &&
-      !aHeader.Has(ObexHeaderId::EndOfBody)) {
-    BT_LOGR("Error! Fail to find Body/EndOfBody. Ignore this push request");
-    return;
-  }
-
-  InfallibleTArray<BluetoothNamedValue> data;
-  nsString name;
-  aHeader.GetName(name);
-  AppendNamedValue(data, "folderName", name);
-
-  AppendBtNamedValueByTagId(aHeader, data,
-                            Map::AppParametersTagId::Transparent);
-  AppendBtNamedValueByTagId(aHeader, data, Map::AppParametersTagId::Retry);
-
-  /* TODO: Support native format charset (mandatory format).
-   *
-   * Charset indicates Gaia application how to deal with encoding.
-   * - Native: If the message object shall be delivered without trans-coding.
-   * - UTF-8:  If the message text shall be trans-coded to UTF-8.
-   *
-   * We only support UTF-8 charset due to current SMS API limitation.
-   */
-  AppendBtNamedValueByTagId(aHeader, data, Map::AppParametersTagId::Charset);
-
-  // Get Body
-  uint8_t* bodyPtr = nullptr;
-  aHeader.GetBody(&bodyPtr, &mBodySegmentLength);
-  mBodySegment.reset(bodyPtr);
-
-  RefPtr<BluetoothMapBMessage> bmsg =
-    new BluetoothMapBMessage(bodyPtr, mBodySegmentLength);
-
-  /* If FolderName is outbox:
-   *   1. Parse body to get SMS
-   *   2. Get receipent subject
-   *   3. Send it to Gaia
-   * Otherwise reply HTTP_NOT_ACCEPTABLE
-   */
-
-  nsCString subject;
-  bmsg->GetBody(subject);
-  // It's possible that subject is empty, send it anyway
-  AppendNamedValue(data, "messageBody", subject);
-
-  nsTArray<RefPtr<VCard>> recipients;
-  bmsg->GetRecipients(recipients);
-
-  // Get the topmost level, only one recipient for SMS case
-  if (!recipients.IsEmpty()) {
-    nsCString recipient;
-    recipients[0]->GetTelephone(recipient);
-    AppendNamedValue(data, "recipient", recipient);
-  }
-
-  bs->DistributeSignal(NS_LITERAL_STRING(MAP_SEND_MESSAGE_REQ_ID),
-                       NS_LITERAL_STRING(KEY_ADAPTER), data);
-}
-
-bool
-BluetoothMapSmsManager::GetInputStreamFromBlob(Blob* aBlob)
-{
-  if (mDataStream) {
-    mDataStream->Close();
-    mDataStream = nullptr;
-  }
-
-  ErrorResult rv;
-  aBlob->GetInternalStream(getter_AddRefs(mDataStream), rv);
-  if (rv.Failed()) {
-    BT_LOGR("Failed to get internal stream from blob. rv=0x%x",
-            rv.ErrorCodeAsInt());
-    return false;
-  }
-
-  return true;
-}
-
-void
-BluetoothMapSmsManager::SendReply(uint8_t aResponseCode)
-{
-  BT_LOGR("[0x%x]", aResponseCode);
-
-  // Section 3.2 "Response Format", IrOBEX 1.2
-  // [opcode:1][length:2][Headers:var]
-  uint8_t req[kObexRespHeaderSize];
-
-  SendMasObexData(req, aResponseCode, kObexRespHeaderSize);
-}
-
-void
-BluetoothMapSmsManager::SendMasObexData(uint8_t* aData, uint8_t aOpcode,
-                                        int aSize)
-{
-  SetObexPacketInfo(aData, aOpcode, aSize);
-  mMasSocket->SendSocketData(new UnixSocketRawData(aData, aSize));
-}
-
-void
-BluetoothMapSmsManager::SendMasObexData(UniquePtr<uint8_t[]> aData,
-                                        uint8_t aOpcode, int aSize)
-{
-  SetObexPacketInfo(aData.get(), aOpcode, aSize);
-  mMasSocket->SendSocketData(new UnixSocketRawData(Move(aData), aSize));
-}
-
-void
-BluetoothMapSmsManager::SendMnsObexData(uint8_t* aData, uint8_t aOpcode,
-                                        int aSize)
-{
-  mLastCommand = aOpcode;
-  SetObexPacketInfo(aData, aOpcode, aSize);
-  mMnsSocket->SendSocketData(new UnixSocketRawData(aData, aSize));
-}
-
-void
-BluetoothMapSmsManager::OnSocketConnectSuccess(BluetoothSocket* aSocket)
-{
-  MOZ_ASSERT(aSocket);
-
-  // MNS socket is connected
-  if (aSocket == mMnsSocket) {
-    mMnsConnected = true;
-    SendMnsConnectRequest();
-    return;
-  }
-  // MAS socket is connected
-  // Close server socket as only one session is allowed at a time
-  mMasServerSocket.swap(mMasSocket);
-
-  // Cache device address since we can't get socket address when a remote
-  // device disconnect with us.
-  mMasSocket->GetAddress(mDeviceAddress);
-}
-
-void
-BluetoothMapSmsManager::OnSocketConnectError(BluetoothSocket* aSocket)
-{
-  // MNS socket connection error
-  if (aSocket == mMnsSocket) {
-    mMnsConnected = false;
-    mMnsSocket = nullptr;
-    return;
-  }
-
-  // MAS socket connection error
-
-  if (mMasServerSocket &&
-      mMasServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-    mMasServerSocket->Close();
-  }
-  mMasServerSocket = nullptr;
-
-  if (mMasSocket &&
-      mMasSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-    mMasSocket->Close();
-  }
-  mMasSocket = nullptr;
-}
-
-void
-BluetoothMapSmsManager::OnSocketDisconnect(BluetoothSocket* aSocket)
-{
-  MOZ_ASSERT(aSocket);
-
-  if (mDataStream) {
-    mDataStream->Close();
-    mDataStream = nullptr;
-  }
-
-  // MNS socket is disconnected
-  if (aSocket == mMnsSocket) {
-    mMnsConnected = false;
-    mMnsSocket = nullptr;
-    BT_LOGR("MNS socket disconnected");
-    return;
-  }
-
-  // MAS server socket is closed
-  if (aSocket != mMasSocket) {
-    // Do nothing when a listening server socket is closed.
-    return;
-  }
-
-  // MAS socket is disconnected
-  AfterMapSmsDisconnected();
-  mDeviceAddress.Clear();
-
-  mMasSocket = nullptr;
-
-  Listen();
-}
-
-void
-BluetoothMapSmsManager::Disconnect(BluetoothProfileController* aController)
-{
-  if (!mMasSocket) {
-    BT_WARNING("%s: No ongoing connection to disconnect", __FUNCTION__);
-    return;
-  }
-
-  mMasSocket->Close();
-}
-
-NS_IMPL_ISUPPORTS(BluetoothMapSmsManager, nsIObserver)
-
-void
-BluetoothMapSmsManager::Connect(const BluetoothAddress& aDeviceAddress,
-                                BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothMapSmsManager::OnGetServiceChannel(
-  const BluetoothAddress& aDeviceAddress,
-  const BluetoothUuid& aServiceUuid,
-  int aChannel)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothMapSmsManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothMapSmsManager::OnConnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothMapSmsManager::OnDisconnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothMapSmsManager::Reset()
-{
-  MOZ_ASSERT(false);
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothMapSmsManager.h
+++ /dev/null
@@ -1,298 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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_BluetoothMapSmsManager_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothMapSmsManager_h
-
-#include "BluetoothCommon.h"
-#include "BluetoothMapBMessage.h"
-#include "BluetoothMapFolder.h"
-#include "BluetoothProfileManagerBase.h"
-#include "BluetoothSocketObserver.h"
-#include "mozilla/ipc/SocketBase.h"
-#include "mozilla/UniquePtr.h"
-
-class nsIInputStream;
-
-namespace mozilla {
-  namespace dom {
-    class Blob;
-    class BlobParent;
-  }
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-struct Map {
-  enum AppParametersTagId {
-    MaxListCount                  = 0x1,
-    StartOffset                   = 0x2,
-    FilterMessageType             = 0x3,
-    FilterPeriodBegin             = 0x4,
-    FilterPeriodEnd               = 0x5,
-    FilterReadStatus              = 0x6,
-    FilterRecipient               = 0x7,
-    FilterOriginator              = 0x8,
-    FilterPriority                = 0x9,
-    Attachment                    = 0x0A,
-    Transparent                   = 0x0B,
-    Retry                         = 0x0C,
-    NewMessage                    = 0x0D,
-    NotificationStatus            = 0x0E,
-    MASInstanceId                 = 0x0F,
-    ParameterMask                 = 0x10,
-    FolderListingSize             = 0x11,
-    MessagesListingSize           = 0x12,
-    SubjectLength                 = 0x13,
-    Charset                       = 0x14,
-    FractionRequest               = 0x15,
-    FractionDeliver               = 0x16,
-    StatusIndicator               = 0x17,
-    StatusValue                   = 0x18,
-    MSETime                       = 0x19
-  };
-};
-
-class BluetoothNamedValue;
-class BluetoothSocket;
-class ObexHeaderSet;
-
-/*
- * BluetoothMapSmsManager acts as Message Server Equipment (MSE) and runs both
- * MAS server and MNS client to exchange SMS/MMS message.
- */
-
-class BluetoothMapSmsManager : public BluetoothSocketObserver
-                             , public BluetoothProfileManagerBase
-{
-public:
-  BT_DECL_PROFILE_MGR_BASE
-  BT_DECL_SOCKET_OBSERVER
-  virtual void GetName(nsACString& aName)
-  {
-    aName.AssignLiteral("MapSms");
-  }
-
-  static const int MAX_PACKET_LENGTH = 0xFFFE;
-  static const int MAX_INSTANCE_ID = 255;
-  // SDP record for SupportedMessageTypes
-  static const int SDP_MESSAGE_TYPE_EMAIL = 0x01;
-  static const int SDP_MESSAGE_TYPE_SMS_GSM = 0x02;
-  static const int SDP_MESSAGE_TYPE_SMS_CDMA = 0x04;
-  static const int SDP_MESSAGE_TYPE_MMS = 0x08;
-  // By defualt SMS/MMS is default supported
-  static const int SDP_SMS_MMS_INSTANCE_ID = 0;
-
-  static void InitMapSmsInterface(BluetoothProfileResultHandler* aRes);
-  static void DeinitMapSmsInterface(BluetoothProfileResultHandler* aRes);
-  static BluetoothMapSmsManager* Get();
-
-  bool Listen();
-
-  /**
-   * Reply folder-listing object to the *IPC* 'folderlisting'
-   *
-   * @param aMasId [in]          MAS id
-   * @param aFolderlists [in]    folder listing object
-   *
-   * @return true if the response packet has been packed correctly and started
-   *         to be sent to the remote device; false otherwise.
-   */
-  bool ReplyToFolderListing(long aMasId, const nsAString& aFolderlists);
-
-  /**
-   * Reply message-listing object to the *IPC* 'messageslisting'
-   *
-   * @param aActor [in]          a blob actor containing message-listing objects
-   * @param aMasId [in]          MAS id
-   * @param aNewMessage [in]     indicate whether there are unread messages
-   * @param aTimestamp [in]      time stamp
-   * @param aSize [in]           total number of messages
-   *
-   * @return true if the response packet has been packed correctly and started
-   *         to be sent to the remote device; false otherwise.
-   */
-  bool ReplyToMessagesListing(
-    BlobParent* aActor, long aMasId, bool aNewMessage,
-    const nsAString& aTimestamp, int aSize);
-
-  /**
-   * Reply messages-listing object to the *in-process* 'messageslisting' request
-   *
-   * @param aBlob [in]           a blob contained the vCard objects
-   * @param aMasId [in]          MAS id
-   * @param aNewMessage [in]     indicate whether there are unread messages
-   * @param aTimestamp [in]      time stamp
-   * @param aSize [in]           total number of messages
-   *
-   * @return true if the response packet has been packed correctly and started
-   *         to be sent to the remote device; false otherwise.
-   */
-  bool ReplyToMessagesListing(
-    Blob* aBlob, long aMasId, bool aNewMessage, const nsAString& aTimestamp,
-    int aSize);
-
-  /**
-   * Reply bMessage object to the *IPC* 'getmessage' request.
-   *
-   * @param aActor [in]          a blob actor containing the bMessage object
-   * @param aMasId [in]          MAS id
-   *
-   * @return true if the response packet has been packed correctly and started
-   *         to be sent to the remote device; false otherwise.
-   */
-  bool ReplyToGetMessage(BlobParent* aActor, long aMasId);
-
-  /**
-   * Reply bMessage to the *in-process* 'getmessage' request.
-   *
-   * @param aBlob [in]          a blob containing the bMessage object
-   * @param aMasId [in]         the number of vCard indexes in the blob
-   *
-   * @return true if the response packet has been packed correctly and started
-   *         to be sent to the remote device; false otherwise.
-   */
-  bool ReplyToGetMessage(Blob* aBlob, long aMasId);
-
-  /**
-   * Reply to the *IPC* 'setmessage' request.
-   *
-   * @param aMasId [in]         MAS id
-   * @param aStatus [in]        success or failure
-   *
-   * @return true if the response packet has been packed correctly and started
-   *         to be sent to the remote device; false otherwise.
-   */
-  bool ReplyToSetMessageStatus(long aMasId, bool aStatus);
-
-  /**
-   * Reply to the *in-process* 'sendmessage' request.
-   *
-   * @param aMasId [in]         MAS id
-   * @param aHandleId [in]      Handle id
-   * @param aStatus [in]        success or failure
-   *
-   * @return true if the response packet has been packed correctly and started
-   *         to be sent to the remote device; false otherwise.
-   */
-  bool ReplyToSendMessage(
-    long aMasId, const nsAString& aHandleId , bool aStatus);
-
-  /**
-   * Reply to the *in-process* 'messageupdate' request.
-   *
-   * @param aMasId [in]         MAS id
-   * @param aStatus [in]        success or failure
-   *
-   * @return true if the response packet has been packed correctly and started
-   *         to be sent to the remote device; false otherwise.
-   */
-  bool ReplyToMessageUpdate(long aMasId, bool aStatus);
-
-protected:
-  virtual ~BluetoothMapSmsManager();
-
-private:
-  BluetoothMapSmsManager();
-
-  nsresult Init();
-  void Uninit();
-  void HandleShutdown();
-
-  void ReplyToConnect();
-  void ReplyToDisconnectOrAbort();
-
-  /*
-   * This function replies to Get request with Header Body, in case of a GET
-   * operation returning an object that is too big to fit in one response
-   * packet. If the operation requires multiple response packets to complete
-   * after the Final bit is set in the request.
-   */
-  bool ReplyToGetWithHeaderBody(UniquePtr<uint8_t[]> aResponse, unsigned int aIndex);
-  void ReplyToSetPath();
-  void ReplyToPut();
-  void SendReply(uint8_t aResponse);
-
-  void HandleNotificationRegistration(const ObexHeaderSet& aHeader);
-  void HandleSetMessageStatus(const ObexHeaderSet& aHeader);
-  void HandleSmsMmsFolderListing(const ObexHeaderSet& aHeader);
-  void HandleSmsMmsMsgListing(const ObexHeaderSet& aHeader);
-  void HandleSmsMmsGetMessage(const ObexHeaderSet& aHeader);
-  void HandleSmsMmsPushMessage(const ObexHeaderSet& aHeader);
-
-  void AppendBtNamedValueByTagId(const ObexHeaderSet& aHeader,
-    InfallibleTArray<BluetoothNamedValue>& aValues,
-    const Map::AppParametersTagId aTagId);
-  void SendMasObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
-  void SendMasObexData(UniquePtr<uint8_t[]> aData, uint8_t aOpcode, int aSize);
-  void SendMnsObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
-  bool StatusResponse(bool aStatus);
-
-  uint8_t SetPath(uint8_t flags, const ObexHeaderSet& aHeader);
-  bool CompareHeaderTarget(const ObexHeaderSet& aHeader);
-  void AfterMapSmsConnected();
-  void AfterMapSmsDisconnected();
-  void CreateMnsObexConnection();
-  void DestroyMnsObexConnection();
-  void SendMnsConnectRequest();
-  void SendMnsDisconnectRequest();
-  void MnsDataHandler(mozilla::ipc::UnixSocketBuffer* aMessage);
-  void MasDataHandler(mozilla::ipc::UnixSocketBuffer* aMessage);
-  bool GetInputStreamFromBlob(Blob* aBlob);
-  InfallibleTArray<uint32_t> PackParameterMask(uint8_t* aData, int aSize);
-
-  /*
-   * Build mandatory folders
-   */
-  void BuildDefaultFolderStructure();
-  /**
-   * Current virtual folder path
-   */
-  BluetoothMapFolder* mCurrentFolder;
-  RefPtr<BluetoothMapFolder> mRootFolder;
-
-  /*
-   * Record the last command
-   */
-  int mLastCommand;
-  // Whether header body is required for the current MessagesListing response.
-  bool mBodyRequired;
-  // Whether FractionDeliver is required for the current GetMessage response
-  bool mFractionDeliverRequired;
-  // MAS OBEX session status. Set when MAS OBEX session is established.
-  bool mMasConnected;
-  // MNS OBEX session status. Set when MNS OBEX session is established.
-  bool mMnsConnected;
-  bool mNtfRequired;
-
-  BluetoothAddress mDeviceAddress;
-  unsigned int mRemoteMaxPacketLength;
-
-  // If a connection has been established, mMasSocket will be the socket
-  // communicating with the remote socket. We maintain the invariant that if
-  // mMasSocket is non-null, mServerSocket must be null (and vice versa).
-  RefPtr<BluetoothSocket> mMasSocket;
-
-  // Server socket. Once an inbound connection is established, it will hand
-  // over the ownership to mMasSocket, and get a new server socket while Listen()
-  // is called.
-  RefPtr<BluetoothSocket> mMasServerSocket;
-
-  // Message notification service client socket
-  RefPtr<BluetoothSocket> mMnsSocket;
-
-  int mBodySegmentLength;
-  UniquePtr<uint8_t[]> mBodySegment;
-
-  /**
-   * The bMessage/message-listing data stream for current processing response
-   */
-  nsCOMPtr<nsIInputStream> mDataStream;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif //mozilla_dom_bluetooth_bluedroid_BluetoothMapSmsManager_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothOppManager.cpp
+++ /dev/null
@@ -1,1760 +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 "base/basictypes.h"
-#include "BluetoothOppManager.h"
-
-#include "BluetoothService.h"
-#include "BluetoothSocket.h"
-#include "BluetoothUtils.h"
-#include "BluetoothUuidHelper.h"
-#include "ObexBase.h"
-
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/dom/ipc/BlobParent.h"
-#include "mozilla/dom/File.h"
-#include "mozilla/RefPtr.h"
-#include "mozilla/Services.h"
-#include "mozilla/StaticPtr.h"
-#include "mozilla/UniquePtr.h"
-#include "nsCExternalHandlerService.h"
-#include "nsIObserver.h"
-#include "nsIObserverService.h"
-#include "nsIFile.h"
-#include "nsIInputStream.h"
-#include "nsIMIMEService.h"
-#include "nsIOutputStream.h"
-#include "nsIVolumeService.h"
-#include "nsNetUtil.h"
-#include "nsServiceManagerUtils.h"
-
-#define TARGET_SUBDIR "Download/Bluetooth/"
-
-USING_BLUETOOTH_NAMESPACE
-using namespace mozilla;
-using namespace mozilla::dom;
-using namespace mozilla::ipc;
-
-namespace {
-  // Sending system message "bluetooth-opp-update-progress" every 50kb
-  static const uint32_t kUpdateProgressBase = 50 * 1024;
-
-  /*
-   * The format of the header of an PUT request is
-   * [opcode:1][packet length:2][headerId:1][header length:2]
-   */
-  static const uint32_t kPutRequestHeaderSize = 6;
-
-  /*
-   * The format of the appended header of an PUT request is
-   * [headerId:1][header length:4]
-   * P.S. Length of name header is 4 since unicode is 2 bytes per char.
-   */
-  static const uint32_t kPutRequestAppendHeaderSize = 5;
-
-  // The default timeout we permit to wait for SDP updating if we can't get
-  // service channel.
-  static const double kSdpUpdatingTimeoutMs = 3000.0;
-
-  // UUID of OBEX Object Push
-  static const BluetoothUuid kObexObjectPush(OBJECT_PUSH);
-
-  StaticRefPtr<BluetoothOppManager> sBluetoothOppManager;
-  static bool sInShutdown = false;
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothOppManager::SendFileBatch final
-{
-public:
-  SendFileBatch(const BluetoothAddress& aDeviceAddress, Blob* aBlob)
-    : mDeviceAddress(aDeviceAddress)
-  {
-    mBlobs.AppendElement(aBlob);
-  }
-
-  BluetoothAddress mDeviceAddress;
-  nsTArray<RefPtr<Blob>> mBlobs;
-};
-
-NS_IMETHODIMP
-BluetoothOppManager::Observe(nsISupports* aSubject,
-                             const char* aTopic,
-                             const char16_t* aData)
-{
-  MOZ_ASSERT(sBluetoothOppManager);
-
-  if (!strcmp(aTopic, NS_VOLUME_STATE_CHANGED)) {
-    HandleVolumeStateChanged(aSubject);
-    return NS_OK;
-  }
-
-  if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    HandleShutdown();
-    return NS_OK;
-  }
-
-  MOZ_ASSERT(false, "BluetoothOppManager got unexpected topic!");
-  return NS_ERROR_UNEXPECTED;
-}
-
-class BluetoothOppManager::SendSocketDataTask final : public Runnable
-{
-public:
-  SendSocketDataTask(UniquePtr<uint8_t[]> aStream, uint32_t aSize)
-    : mStream(Move(aStream))
-    , mSize(aSize)
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    sBluetoothOppManager->SendPutRequest(mStream.get(), mSize);
-
-    return NS_OK;
-  }
-
-private:
-  UniquePtr<uint8_t[]> mStream;
-  uint32_t mSize;
-};
-
-class BluetoothOppManager::ReadFileTask final : public Runnable
-{
-public:
-  ReadFileTask(nsIInputStream* aInputStream,
-               uint32_t aRemoteMaxPacketSize) : mInputStream(aInputStream)
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    mAvailablePacketSize = aRemoteMaxPacketSize - kPutRequestHeaderSize;
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-
-    uint32_t numRead;
-    auto buf = MakeUnique<uint8_t[]>(mAvailablePacketSize);
-
-    // function inputstream->Read() only works on non-main thread
-    nsresult rv = mInputStream->Read((char*)buf.get(), mAvailablePacketSize,
-                                     &numRead);
-    if (NS_FAILED(rv)) {
-      // Needs error handling here
-      BT_WARNING("Failed to read from input stream");
-      return NS_ERROR_FAILURE;
-    }
-
-    if (numRead > 0) {
-      sBluetoothOppManager->CheckPutFinal(numRead);
-
-      RefPtr<SendSocketDataTask> task =
-        new SendSocketDataTask(Move(buf), numRead);
-      if (NS_FAILED(NS_DispatchToMainThread(task))) {
-        BT_WARNING("Failed to dispatch to main thread!");
-        return NS_ERROR_FAILURE;
-      }
-    }
-
-    return NS_OK;
-  };
-
-private:
-  nsCOMPtr<nsIInputStream> mInputStream;
-  uint32_t mAvailablePacketSize;
-};
-
-class BluetoothOppManager::CloseSocketTask final : public Runnable
-{
-public:
-  CloseSocketTask(BluetoothSocket* aSocket) : mSocket(aSocket)
-  {
-    MOZ_ASSERT(aSocket);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-    mSocket->Close();
-    return NS_OK;
-  }
-
-private:
-  RefPtr<BluetoothSocket> mSocket;
-};
-
-BluetoothOppManager::BluetoothOppManager() : mConnected(false)
-                                           , mRemoteObexVersion(0)
-                                           , mRemoteConnectionFlags(0)
-                                           , mRemoteMaxPacketLength(0)
-                                           , mLastCommand(0)
-                                           , mPacketLength(0)
-                                           , mPutPacketReceivedLength(0)
-                                           , mBodySegmentLength(0)
-                                           , mNeedsUpdatingSdpRecords(false)
-                                           , mAbortFlag(false)
-                                           , mNewFileFlag(false)
-                                           , mPutFinalFlag(false)
-                                           , mSendTransferCompleteFlag(false)
-                                           , mSuccessFlag(false)
-                                           , mIsServer(true)
-                                           , mWaitingForConfirmationFlag(false)
-                                           , mFileLength(0)
-                                           , mSentFileLength(0)
-                                           , mWaitingToSendPutFinal(false)
-                                           , mCurrentBlobIndex(-1)
-{ }
-
-BluetoothOppManager::~BluetoothOppManager()
-{ }
-
-nsresult
-BluetoothOppManager::Init()
-{
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE(obs, NS_ERROR_NOT_AVAILABLE);
-
-  auto rv = obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("Failed to add shutdown observer!");
-    return rv;
-  }
-
-  rv = obs->AddObserver(this, NS_VOLUME_STATE_CHANGED, false);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("Failed to add ns volume observer!");
-    return rv;
-  }
-
-  /**
-   * We don't start listening here as BluetoothServiceBluedroid calls Listen()
-   * immediately when BT stops.
-   *
-   * If we start listening here, the listening fails when device boots up since
-   * Listen() is called again and restarts server socket. The restart causes
-   * absence of read events when device boots up.
-   */
-
-  return NS_OK;
-}
-
-void
-BluetoothOppManager::Uninit()
-{
-  if (mServerSocket) {
-    mServerSocket->SetObserver(nullptr);
-
-    if (mServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-      mServerSocket->Close();
-    }
-    mServerSocket = nullptr;
-  }
-
-  if (mSocket) {
-    mSocket->SetObserver(nullptr);
-
-    if (mSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-      mSocket->Close();
-    }
-    mSocket = nullptr;
-  }
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-
-  if (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID))) {
-    BT_WARNING("Failed to remove shutdown observer!");
-  }
-
-  if (NS_FAILED(obs->RemoveObserver(this, NS_VOLUME_STATE_CHANGED))) {
-    BT_WARNING("Failed to remove volume observer!");
-  }
-}
-
-// static
-void
-BluetoothOppManager::InitOppInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (aRes) {
-    aRes->Init();
-  }
-}
-
-// static
-void
-BluetoothOppManager::DeinitOppInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (sBluetoothOppManager) {
-    sBluetoothOppManager->Uninit();
-    sBluetoothOppManager = nullptr;
-  }
-
-  if (aRes) {
-    aRes->Deinit();
-  }
-}
-
-//static
-BluetoothOppManager*
-BluetoothOppManager::Get()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // If sBluetoothOppManager already exists, exit early
-  if (sBluetoothOppManager) {
-    return sBluetoothOppManager;
-  }
-
-  // If we're in shutdown, don't create a new instance
-  NS_ENSURE_FALSE(sInShutdown, nullptr);
-
-  // Create a new instance, register, and return
-  RefPtr<BluetoothOppManager> manager = new BluetoothOppManager();
-  NS_ENSURE_SUCCESS(manager->Init(), nullptr);
-
-  sBluetoothOppManager = manager;
-
-  return sBluetoothOppManager;
-}
-
-void
-BluetoothOppManager::ConnectInternal(const BluetoothAddress& aDeviceAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Stop listening because currently we only support one connection at a time.
-  if (mServerSocket &&
-      mServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-    mServerSocket->Close();
-  }
-  mServerSocket = nullptr;
-
-  mIsServer = false;
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs || sInShutdown || mSocket) {
-    OnSocketConnectError(mSocket);
-    return;
-  }
-
-  mNeedsUpdatingSdpRecords = true;
-
-  if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress, kObexObjectPush, this))) {
-    OnSocketConnectError(mSocket);
-    return;
-  }
-
-  mSocket = new BluetoothSocket(this);
-}
-
-void
-BluetoothOppManager::HandleShutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  sInShutdown = true;
-  Disconnect(nullptr);
-  Uninit();
-
-  sBluetoothOppManager = nullptr;
-}
-
-void
-BluetoothOppManager::HandleVolumeStateChanged(nsISupports* aSubject)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!mConnected) {
-    return;
-  }
-
-  /**
-   * Disconnect ongoing OPP connection when a volume becomes non-mounted, in
-   * case files of transfer are located on that volume. |OnSocketDisconnect|
-   * will handle incomplete file transfers.
-   */
-
-  nsCOMPtr<nsIVolume> vol = do_QueryInterface(aSubject);
-  if (!vol) {
-    return;
-  }
-
-  int32_t state;
-  vol->GetState(&state);
-  if (nsIVolume::STATE_MOUNTED != state) {
-    BT_LOGR("Volume becomes non-mounted. Abort ongoing OPP connection");
-    Disconnect(nullptr);
-  }
-}
-
-bool
-BluetoothOppManager::Listen()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (mSocket) {
-    BT_WARNING("mSocket exists. Failed to listen.");
-    return false;
-  }
-
-  /**
-   * Restart server socket since its underlying fd becomes invalid when
-   * BT stops; otherwise no more read events would be received even if
-   * BT restarts.
-   */
-  if (mServerSocket &&
-      mServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-    mServerSocket->Close();
-  }
-  mServerSocket = nullptr;
-
-  mServerSocket = new BluetoothSocket(this);
-
-  nsresult rv = mServerSocket->Listen(NS_LITERAL_STRING("OBEX Object Push"),
-                                      kObexObjectPush,
-                                      BluetoothSocketType::RFCOMM,
-                                      BluetoothReservedChannels::CHANNEL_OPUSH,
-                                      false, true);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("[OPP] Can't listen on RFCOMM socket!");
-    mServerSocket = nullptr;
-    return false;
-  }
-
-  mIsServer = true;
-
-  return true;
-}
-
-void
-BluetoothOppManager::StartSendingNextFile()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  MOZ_ASSERT(!mBatches.IsEmpty());
-  MOZ_ASSERT((int)mBatches[0].mBlobs.Length() > mCurrentBlobIndex + 1);
-
-  mBlob = mBatches[0].mBlobs[++mCurrentBlobIndex];
-
-  // Before sending content, we have to send a header including
-  // information such as file name, file length and content type.
-  ExtractBlobHeaders();
-  StartFileTransfer();
-
-  if (mCurrentBlobIndex == 0) {
-    // We may have more than one file waiting for transferring, but only one
-    // CONNECT request would be sent. Therefore check if this is the very first
-    // file at the head of queue.
-    SendConnectRequest();
-  } else {
-    SendPutHeaderRequest(mFileName, mFileLength);
-    AfterFirstPut();
-  }
-}
-
-bool
-BluetoothOppManager::SendFile(const BluetoothAddress& aDeviceAddress,
-                              BlobParent* aActor)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  RefPtr<BlobImpl> impl = aActor->GetBlobImpl();
-  RefPtr<Blob> blob = Blob::Create(nullptr, impl);
-
-  return SendFile(aDeviceAddress, blob.get());
-}
-
-bool
-BluetoothOppManager::SendFile(const BluetoothAddress& aDeviceAddress,
-                              Blob* aBlob)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  AppendBlobToSend(aDeviceAddress, aBlob);
-  if (!mSocket) {
-    ProcessNextBatch();
-  }
-
-  return true;
-}
-
-void
-BluetoothOppManager::AppendBlobToSend(const BluetoothAddress& aDeviceAddress,
-                                      Blob* aBlob)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  int indexTail = mBatches.Length() - 1;
-
-  /**
-   * Create a new batch if
-   * - mBatches is empty, or
-   * - aDeviceAddress differs from mDeviceAddress of the last batch
-   */
-  if (mBatches.IsEmpty() ||
-      aDeviceAddress != mBatches[indexTail].mDeviceAddress) {
-    SendFileBatch batch(aDeviceAddress, aBlob);
-    mBatches.AppendElement(batch);
-  } else {
-    mBatches[indexTail].mBlobs.AppendElement(aBlob);
-  }
-}
-
-void
-BluetoothOppManager::DiscardBlobsToSend()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  MOZ_ASSERT(!mBatches.IsEmpty());
-  MOZ_ASSERT(!mIsServer);
-
-  int length = (int) mBatches[0].mBlobs.Length();
-  while (length > mCurrentBlobIndex + 1) {
-    mBlob = mBatches[0].mBlobs[++mCurrentBlobIndex];
-
-    BT_LOGR("idx %d", mCurrentBlobIndex);
-    ExtractBlobHeaders();
-    StartFileTransfer();
-    FileTransferComplete();
-  }
-}
-
-bool
-BluetoothOppManager::ProcessNextBatch()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!IsConnected());
-
-  // Remove the processed batch.
-  // A batch is processed if we've incremented mCurrentBlobIndex for it.
-  if (mCurrentBlobIndex >= 0) {
-    ClearQueue();
-    mBatches.RemoveElementAt(0);
-    BT_LOGR("REMOVE. %d remaining", mBatches.Length());
-  }
-
-  // Process the next batch
-  if (!mBatches.IsEmpty()) {
-    ConnectInternal(mBatches[0].mDeviceAddress);
-    return true;
-  }
-
-  // No more batch to process
-  return false;
-}
-
-void
-BluetoothOppManager::ClearQueue()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  MOZ_ASSERT(!mIsServer);
-  MOZ_ASSERT(!mBatches.IsEmpty());
-  MOZ_ASSERT(!mBatches[0].mBlobs.IsEmpty());
-
-  mCurrentBlobIndex = -1;
-  mBlob = nullptr;
-  mBatches[0].mBlobs.Clear();
-}
-
-bool
-BluetoothOppManager::StopSendingFile()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (mIsServer) {
-    mAbortFlag = true;
-  } else {
-    Disconnect(nullptr);
-  }
-
-  return true;
-}
-
-bool
-BluetoothOppManager::ConfirmReceivingFile(bool aConfirm)
-{
-  NS_ENSURE_TRUE(mConnected, false);
-  NS_ENSURE_TRUE(mWaitingForConfirmationFlag, false);
-
-  mWaitingForConfirmationFlag = false;
-
-  // For the first packet of first file
-  bool success = false;
-  if (aConfirm) {
-    StartFileTransfer();
-    if (CreateFile()) {
-      success = WriteToFile(mBodySegment.get(), mBodySegmentLength);
-    }
-  }
-
-  if (success && mPutFinalFlag) {
-    mSuccessFlag = true;
-    RestoreReceivedFileAndNotify();
-    FileTransferComplete();
-  }
-
-  ReplyToPut(mPutFinalFlag, success);
-
-  return true;
-}
-
-void
-BluetoothOppManager::AfterFirstPut()
-{
-  mUpdateProgressCounter = 1;
-  mPutFinalFlag = false;
-  mPutPacketReceivedLength = 0;
-  mSentFileLength = 0;
-  mWaitingToSendPutFinal = false;
-  mSuccessFlag = false;
-  mBodySegmentLength = 0;
-}
-
-void
-BluetoothOppManager::AfterOppConnected()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mConnected = true;
-  mAbortFlag = false;
-  mWaitingForConfirmationFlag = true;
-  AfterFirstPut();
-  // Get a mount lock to prevent the sdcard from being shared with
-  // the PC while we're doing a OPP file transfer. After OPP transaction
-  // were done, the mount lock will be freed.
-  if (!AcquireSdcardMountLock()) {
-    // If we fail to get a mount lock, abort this transaction
-    // Directly sending disconnect-request is better than abort-request
-    BT_WARNING("BluetoothOPPManager couldn't get a mount lock!");
-    Disconnect(nullptr);
-  }
-}
-
-void
-BluetoothOppManager::AfterOppDisconnected()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mConnected = false;
-  mLastCommand = 0;
-  mPutPacketReceivedLength = 0;
-  mDsFile = nullptr;
-  mDummyDsFile = nullptr;
-
-  // We can't reset mSuccessFlag here since this function may be called
-  // before we send system message of transfer complete
-  // mSuccessFlag = false;
-
-  if (mInputStream) {
-    mInputStream->Close();
-    mInputStream = nullptr;
-  }
-
-  if (mOutputStream) {
-    mOutputStream->Close();
-    mOutputStream = nullptr;
-  }
-
-  // Store local pointer of |mReadFileThread| to avoid shutdown reentry crash
-  // See bug 1191715 comment 19 for more details.
-  nsCOMPtr<nsIThread> thread = mReadFileThread.forget();
-  if (thread) {
-    thread->Shutdown();
-  }
-
-  // Release the mount lock if file transfer completed
-  if (mMountLock) {
-    // The mount lock will be implicitly unlocked
-    mMountLock = nullptr;
-  }
-}
-
-void
-BluetoothOppManager::RestoreReceivedFileAndNotify()
-{
-  // Remove the empty dummy file
-  if (mDummyDsFile && mDummyDsFile->mFile) {
-    mDummyDsFile->mFile->Remove(false);
-    mDummyDsFile = nullptr;
-  }
-
-  // Remove the trailing ".part" file name from mDsFile by two steps
-  // 1. mDsFile->SetPath() so that the notification sent to Gaia will carry
-  //    correct information of the file.
-  // 2. mDsFile->mFile->RenameTo() so that the file name would actually be
-  //    changed in file system.
-  if (mDsFile && mDsFile->mFile) {
-    nsString path;
-    path.AssignLiteral(TARGET_SUBDIR);
-    path.Append(mFileName);
-
-    mDsFile->SetPath(path);
-    mDsFile->mFile->RenameTo(nullptr, mFileName);
-  }
-
-  // Notify about change of received file
-  NotifyAboutFileChange();
-}
-
-void
-BluetoothOppManager::DeleteReceivedFile()
-{
-  if (mOutputStream) {
-    mOutputStream->Close();
-    mOutputStream = nullptr;
-  }
-
-  if (mDsFile && mDsFile->mFile) {
-    mDsFile->mFile->Remove(false);
-    mDsFile = nullptr;
-  }
-
-  // Remove the empty dummy file
-  if (mDummyDsFile && mDummyDsFile->mFile) {
-    mDummyDsFile->mFile->Remove(false);
-    mDummyDsFile = nullptr;
-  }
-}
-
-bool
-BluetoothOppManager::CreateFile()
-{
-  MOZ_ASSERT(mPutPacketReceivedLength == mPacketLength);
-
-  // Create one dummy file to be a placeholder for the target file name, and
-  // create another file with a meaningless file extension to write the received
-  // data. By doing this, we can prevent applications from parsing incomplete
-  // data in the middle of the receiving process.
-  nsString path;
-  path.AssignLiteral(TARGET_SUBDIR);
-  path.Append(mFileName);
-
-  // Use an empty dummy file object to occupy the file name, so that after the
-  // whole file has been received successfully by using mDsFile, we could just
-  // remove mDummyDsFile and rename mDsFile to the file name of mDummyDsFile.
-  mDummyDsFile =
-    DeviceStorageFile::CreateUnique(path, nsIFile::NORMAL_FILE_TYPE, 0644);
-  NS_ENSURE_TRUE(mDummyDsFile, false);
-
-  // The function CreateUnique() may create a file with a different file
-  // name from the original mFileName. Therefore we have to retrieve
-  // the file name again.
-  mDummyDsFile->mFile->GetLeafName(mFileName);
-
-  BT_LOGR("mFileName: %s", NS_ConvertUTF16toUTF8(mFileName).get());
-
-  // Prepare the entire file path for the .part file
-  path.Truncate();
-  path.AssignLiteral(TARGET_SUBDIR);
-  path.Append(mFileName);
-  path.AppendLiteral(".part");
-
-  mDsFile =
-    DeviceStorageFile::CreateUnique(path, nsIFile::NORMAL_FILE_TYPE, 0644);
-  NS_ENSURE_TRUE(mDsFile, false);
-
-  NS_NewLocalFileOutputStream(getter_AddRefs(mOutputStream), mDsFile->mFile);
-  NS_ENSURE_TRUE(mOutputStream, false);
-
-  return true;
-}
-
-bool
-BluetoothOppManager::WriteToFile(const uint8_t* aData, int aDataLength)
-{
-  NS_ENSURE_TRUE(mOutputStream, false);
-
-  uint32_t wrote = 0;
-  mOutputStream->Write((const char*)aData, aDataLength, &wrote);
-  NS_ENSURE_TRUE(aDataLength == (int) wrote, false);
-
-  return true;
-}
-
-// Virtual function of class SocketConsumer
-void
-BluetoothOppManager::ExtractPacketHeaders(const ObexHeaderSet& aHeader)
-{
-  if (aHeader.Has(ObexHeaderId::Name)) {
-    aHeader.GetName(mFileName);
-  }
-
-  if (aHeader.Has(ObexHeaderId::Type)) {
-    aHeader.GetContentType(mContentType);
-  }
-
-  if (aHeader.Has(ObexHeaderId::Length)) {
-    aHeader.GetLength(&mFileLength);
-  }
-
-  if (aHeader.Has(ObexHeaderId::Body) ||
-      aHeader.Has(ObexHeaderId::EndOfBody)) {
-    uint8_t* bodyPtr;
-    aHeader.GetBody(&bodyPtr, &mBodySegmentLength);
-    mBodySegment.reset(bodyPtr);
-  }
-}
-
-bool
-BluetoothOppManager::ExtractBlobHeaders()
-{
-  RetrieveSentFileName();
-  mBlob->GetType(mContentType);
-
-  ErrorResult rv;
-  uint64_t fileLength = mBlob->GetSize(rv);
-  if (NS_WARN_IF(rv.Failed())) {
-    SendDisconnectRequest();
-    rv.SuppressException();
-    return false;
-  }
-
-  // Currently we keep the size of files which were sent/received via
-  // Bluetooth not exceed UINT32_MAX because the Length header in OBEX
-  // is only 4-byte long. Although it is possible to transfer a file
-  // larger than UINT32_MAX, it needs to parse another OBEX Header
-  // and I would like to leave it as a feature.
-  if (fileLength > (uint64_t)UINT32_MAX) {
-    BT_WARNING("The file size is too large for now");
-    SendDisconnectRequest();
-    return false;
-  }
-
-  mFileLength = fileLength;
-  rv = NS_NewThread(getter_AddRefs(mReadFileThread));
-  if (NS_WARN_IF(rv.Failed())) {
-    SendDisconnectRequest();
-    rv.SuppressException();
-    return false;
-  }
-
-  return true;
-}
-
-void
-BluetoothOppManager::RetrieveSentFileName()
-{
-  mFileName.Truncate();
-
-  RefPtr<File> file = static_cast<Blob*>(mBlob.get())->ToFile();
-  if (file) {
-    file->GetName(mFileName);
-  }
-
-  /**
-   * We try our best to get the file extension to avoid interoperability issues.
-   * However, once we found that we are unable to get suitable extension or
-   * information about the content type, sending a pre-defined file name without
-   * extension would be fine.
-   */
-  if (mFileName.IsEmpty()) {
-    mFileName.AssignLiteral("Unknown");
-  }
-
-  int32_t offset = mFileName.RFindChar('/');
-  if (offset != kNotFound) {
-    mFileName = Substring(mFileName, offset + 1);
-  }
-
-  offset = mFileName.RFindChar('.');
-  if (offset == kNotFound) {
-    nsCOMPtr<nsIMIMEService> mimeSvc = do_GetService(NS_MIMESERVICE_CONTRACTID);
-
-    if (mimeSvc) {
-      nsString mimeType;
-      mBlob->GetType(mimeType);
-
-      nsCString extension;
-      nsresult rv =
-        mimeSvc->GetPrimaryExtension(NS_LossyConvertUTF16toASCII(mimeType),
-                                     EmptyCString(),
-                                     extension);
-      if (NS_SUCCEEDED(rv)) {
-        mFileName.Append('.');
-        AppendUTF8toUTF16(extension, mFileName);
-      }
-    }
-  }
-}
-
-bool
-BluetoothOppManager::IsReservedChar(char16_t c)
-{
-  return (c < 0x0020 ||
-          c == char16_t('?') || c == char16_t('|') || c == char16_t('<') ||
-          c == char16_t('>') || c == char16_t('"') || c == char16_t(':') ||
-          c == char16_t('/') || c == char16_t('*') || c == char16_t('\\'));
-}
-
-void
-BluetoothOppManager::ValidateFileName()
-{
-  int length = mFileName.Length();
-
-  for (int i = 0; i < length; ++i) {
-    // Replace reserved char of fat file system with '_'
-    if (IsReservedChar(mFileName.CharAt(i))) {
-      mFileName.Replace(i, 1, char16_t('_'));
-    }
-  }
-}
-
-bool
-BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketBuffer* aMessage)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aMessage);
-
-  const uint8_t* data = aMessage->GetData();
-  int frameHeaderLength = 0;
-
-  // See if this is the first part of each Put packet
-  if (mPutPacketReceivedLength == 0) {
-    // Section 3.3.3 "Put", IrOBEX 1.2
-    // [opcode:1][length:2][Headers:var]
-    frameHeaderLength = 3;
-
-    mPacketLength = BigEndian::readUint16(&data[1]) - frameHeaderLength;
-
-    /**
-     * A PUT request from remote devices may be divided into multiple parts.
-     * In other words, one request may need to be received multiple times,
-     * so here we keep a variable mPutPacketReceivedLength to indicate if
-     * current PUT request is done.
-     */
-    mReceivedDataBuffer.reset(new uint8_t[mPacketLength]);
-    mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal);
-  }
-
-  int dataLength = aMessage->GetSize() - frameHeaderLength;
-
-  // Check length before memcpy to prevent from memory pollution
-  if (dataLength < 0 ||
-      mPutPacketReceivedLength + dataLength > mPacketLength) {
-    BT_LOGR("Received packet size is unreasonable");
-
-    ReplyToPut(mPutFinalFlag, false);
-    DeleteReceivedFile();
-    FileTransferComplete();
-
-    return false;
-  }
-
-  memcpy(mReceivedDataBuffer.get() + mPutPacketReceivedLength,
-         &data[frameHeaderLength], dataLength);
-
-  mPutPacketReceivedLength += dataLength;
-
-  return (mPutPacketReceivedLength == mPacketLength);
-}
-
-void
-BluetoothOppManager::ServerDataHandler(UnixSocketBuffer* aMessage)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * Ensure
-   * - valid access to data[0], i.e., opCode
-   * - received packet length smaller than max packet length
-   */
-  int receivedLength = aMessage->GetSize();
-  if (receivedLength < 1 || receivedLength > MAX_PACKET_LENGTH) {
-    ReplyError(ObexResponseCode::BadRequest);
-    return;
-  }
-
-  uint8_t opCode;
-  const uint8_t* data = aMessage->GetData();
-  if (mPutPacketReceivedLength > 0) {
-    opCode = mPutFinalFlag ? ObexRequestCode::PutFinal : ObexRequestCode::Put;
-  } else {
-    opCode = data[0];
-
-    // When there's a Put packet right after a PutFinal packet,
-    // which means it's the start point of a new file.
-    if (mPutFinalFlag &&
-        (opCode == ObexRequestCode::Put ||
-         opCode == ObexRequestCode::PutFinal)) {
-      mNewFileFlag = true;
-      AfterFirstPut();
-    }
-  }
-
-  ObexHeaderSet pktHeaders;
-  if (opCode == ObexRequestCode::Connect) {
-    // Section 3.3.1 "Connect", IrOBEX 1.2
-    // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
-    // [Headers:var]
-    if (receivedLength < 7 ||
-        !ParseHeaders(&data[7], receivedLength - 7, &pktHeaders)) {
-      ReplyError(ObexResponseCode::BadRequest);
-      return;
-    }
-
-    ReplyToConnect();
-    AfterOppConnected();
-  } else if (opCode == ObexRequestCode::Abort) {
-    // Section 3.3.5 "Abort", IrOBEX 1.2
-    // [opcode:1][length:2][Headers:var]
-    if (receivedLength < 3 ||
-        !ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
-      ReplyError(ObexResponseCode::BadRequest);
-      return;
-    }
-
-    ReplyToDisconnectOrAbort();
-    DeleteReceivedFile();
-  } else if (opCode == ObexRequestCode::Disconnect) {
-    // Section 3.3.2 "Disconnect", IrOBEX 1.2
-    // [opcode:1][length:2][Headers:var]
-    if (receivedLength < 3 ||
-        !ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
-      ReplyError(ObexResponseCode::BadRequest);
-      return;
-    }
-
-    ReplyToDisconnectOrAbort();
-    AfterOppDisconnected();
-    FileTransferComplete();
-  } else if (opCode == ObexRequestCode::Put ||
-             opCode == ObexRequestCode::PutFinal) {
-    if (!ComposePacket(opCode, aMessage)) {
-      return;
-    }
-
-    // A Put packet is received completely
-    ParseHeaders(mReceivedDataBuffer.get(),
-                 mPutPacketReceivedLength, &pktHeaders);
-    ExtractPacketHeaders(pktHeaders);
-    ValidateFileName();
-
-    // When we cancel the transfer, delete the file and notify completion
-    if (mAbortFlag) {
-      ReplyToPut(mPutFinalFlag, false);
-      mSentFileLength += mBodySegmentLength;
-      DeleteReceivedFile();
-      FileTransferComplete();
-      return;
-    }
-
-    // Wait until get confirmation from user, then create file and write to it
-    if (mWaitingForConfirmationFlag) {
-      ReceivingFileConfirmation();
-      mSentFileLength += mBodySegmentLength;
-      return;
-    }
-
-    // Already get confirmation from user, create a new file if needed and
-    // write to output stream
-    if (mNewFileFlag) {
-      StartFileTransfer();
-      if (!CreateFile()) {
-        ReplyToPut(mPutFinalFlag, false);
-        return;
-      }
-      mNewFileFlag = false;
-    }
-
-    if (!WriteToFile(mBodySegment.get(), mBodySegmentLength)) {
-      ReplyToPut(mPutFinalFlag, false);
-      return;
-    }
-
-    ReplyToPut(mPutFinalFlag, true);
-
-    // Send progress update
-    mSentFileLength += mBodySegmentLength;
-    if (mSentFileLength > kUpdateProgressBase * mUpdateProgressCounter) {
-      UpdateProgress();
-      mUpdateProgressCounter = mSentFileLength / kUpdateProgressBase + 1;
-    }
-
-    // Success to receive a file and notify completion
-    if (mPutFinalFlag) {
-      mSuccessFlag = true;
-      RestoreReceivedFileAndNotify();
-      FileTransferComplete();
-    }
-  } else if (opCode == ObexRequestCode::Get ||
-             opCode == ObexRequestCode::GetFinal ||
-             opCode == ObexRequestCode::SetPath) {
-    ReplyError(ObexResponseCode::BadRequest);
-    BT_WARNING("Unsupported ObexRequestCode");
-  } else {
-    ReplyError(ObexResponseCode::NotImplemented);
-    BT_WARNING("Unrecognized ObexRequestCode");
-  }
-}
-
-void
-BluetoothOppManager::ClientDataHandler(UnixSocketBuffer* aMessage)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Ensure valid access to data[0], i.e., opCode
-  int receivedLength = aMessage->GetSize();
-  if (receivedLength < 1) {
-    BT_LOGR("Receive empty response packet");
-    return;
-  }
-
-  const uint8_t* data = aMessage->GetData();
-  uint8_t opCode = data[0];
-
-  // Check response code and send out system message as finished if the response
-  // code is somehow incorrect.
-  uint8_t expectedOpCode = ObexResponseCode::Success;
-  if (mLastCommand == ObexRequestCode::Put) {
-    expectedOpCode = ObexResponseCode::Continue;
-  }
-
-  if (opCode != expectedOpCode) {
-    if (mLastCommand == ObexRequestCode::Put ||
-        mLastCommand == ObexRequestCode::Abort ||
-        mLastCommand == ObexRequestCode::PutFinal) {
-      SendDisconnectRequest();
-    }
-    nsAutoCString str;
-    str += "[OPP] 0x";
-    str.AppendInt(mLastCommand, 16);
-    str += " failed";
-    BT_WARNING(str.get());
-    FileTransferComplete();
-    return;
-  }
-
-  if (mLastCommand == ObexRequestCode::PutFinal) {
-    mSuccessFlag = true;
-    FileTransferComplete();
-
-    if (mInputStream) {
-      mInputStream->Close();
-      mInputStream = nullptr;
-    }
-
-    if (mCurrentBlobIndex + 1 == (int) mBatches[0].mBlobs.Length()) {
-      SendDisconnectRequest();
-    } else {
-      StartSendingNextFile();
-    }
-  } else if (mLastCommand == ObexRequestCode::Abort) {
-    SendDisconnectRequest();
-    FileTransferComplete();
-  } else if (mLastCommand == ObexRequestCode::Disconnect) {
-    AfterOppDisconnected();
-    // Most devices will directly terminate connection after receiving
-    // Disconnect request, so we make a delay here. If the socket hasn't been
-    // disconnected, we will close it.
-    if (mSocket) {
-      MessageLoop::current()->PostDelayedTask(
-        MakeAndAddRef<CloseSocketTask>(mSocket), 1000);
-    }
-  } else if (mLastCommand == ObexRequestCode::Connect) {
-    MOZ_ASSERT(!mFileName.IsEmpty());
-    MOZ_ASSERT(mBlob);
-
-    AfterOppConnected();
-
-    // Ensure valid access to remote information
-    if (receivedLength < 7) {
-      BT_LOGR("The length of connect response packet is invalid");
-      SendDisconnectRequest();
-      return;
-    }
-
-    // Keep remote information
-    mRemoteObexVersion = data[3];
-    mRemoteConnectionFlags = data[4];
-    mRemoteMaxPacketLength = BigEndian::readUint16(&data[5]);
-
-    // The length of file name exceeds maximum length.
-    int fileNameByteLen = (mFileName.Length() + 1) * 2;
-    int headerLen = kPutRequestHeaderSize + kPutRequestAppendHeaderSize;
-    if (fileNameByteLen > mRemoteMaxPacketLength - headerLen) {
-      BT_WARNING("The length of file name is aberrant.");
-      SendDisconnectRequest();
-      return;
-    }
-
-    SendPutHeaderRequest(mFileName, mFileLength);
-  } else if (mLastCommand == ObexRequestCode::Put) {
-    if (mWaitingToSendPutFinal) {
-      SendPutFinalRequest();
-      return;
-    }
-
-    if (kUpdateProgressBase * mUpdateProgressCounter < mSentFileLength) {
-      UpdateProgress();
-      mUpdateProgressCounter = mSentFileLength / kUpdateProgressBase + 1;
-    }
-
-    ErrorResult rv;
-    if (!mInputStream) {
-      mBlob->GetInternalStream(getter_AddRefs(mInputStream), rv);
-      if (NS_WARN_IF(rv.Failed())) {
-        SendDisconnectRequest();
-        rv.SuppressException();
-        return;
-      }
-    }
-
-    RefPtr<ReadFileTask> task = new ReadFileTask(mInputStream,
-                                                   mRemoteMaxPacketLength);
-    rv = mReadFileThread->Dispatch(task, NS_DISPATCH_NORMAL);
-    if (NS_WARN_IF(rv.Failed())) {
-      SendDisconnectRequest();
-      rv.SuppressException();
-      return;
-    }
-  } else {
-    BT_WARNING("Unhandled ObexRequestCode");
-  }
-}
-
-// Virtual function of class SocketConsumer
-void
-BluetoothOppManager::ReceiveSocketData(BluetoothSocket* aSocket,
-                                       UniquePtr<UnixSocketBuffer>& aBuffer)
-{
-  if (mIsServer) {
-    ServerDataHandler(aBuffer.get());
-  } else {
-    ClientDataHandler(aBuffer.get());
-  }
-}
-
-void
-BluetoothOppManager::SendConnectRequest()
-{
-  if (mConnected) {
-    return;
-  }
-
-  // Section 3.3.1 "Connect", IrOBEX 1.2
-  // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
-  // [Headers:var]
-  uint8_t req[255];
-  int index = 7;
-
-  req[3] = 0x10; // version=1.0
-  req[4] = 0x00; // flag=0x00
-  req[5] = BluetoothOppManager::MAX_PACKET_LENGTH >> 8;
-  req[6] = (uint8_t)BluetoothOppManager::MAX_PACKET_LENGTH;
-
-  SendObexData(req, ObexRequestCode::Connect, index);
-}
-
-void
-BluetoothOppManager::SendPutHeaderRequest(const nsAString& aFileName,
-                                          int aFileSize)
-{
-  if (!mConnected) {
-    return;
-  }
-
-  int len = aFileName.Length();
-  auto fileName = MakeUnique<uint8_t[]>((len + 1) * 2);
-
-  for (int i = 0; i < len; i++) {
-    BigEndian::writeUint16(&fileName[i * 2], aFileName[i]);
-  }
-  BigEndian::writeUint16(&fileName[len * 2], 0);
-
-  // Prepare packet
-  auto req = MakeUnique<uint8_t[]>(mRemoteMaxPacketLength);
-  int index = 3;
-  index += AppendHeaderName(&req[index], mRemoteMaxPacketLength - index,
-                            fileName.get(), (len + 1) * 2);
-  index += AppendHeaderLength(&req[index], aFileSize);
-
-  // This is final put packet if file size equals to 0
-  uint8_t opcode = (aFileSize > 0) ? ObexRequestCode::Put
-                                   : ObexRequestCode::PutFinal;
-  SendObexData(Move(req), opcode, index);
-}
-
-void
-BluetoothOppManager::SendPutRequest(uint8_t* aFileBody,
-                                    int aFileBodyLength)
-{
-  if (!mConnected) {
-    return;
-  }
-
-  int packetLeftSpace = mRemoteMaxPacketLength - kPutRequestHeaderSize;
-  if (aFileBodyLength > packetLeftSpace) {
-    BT_WARNING("Not allowed such a small MaxPacketLength value");
-    return;
-  }
-
-  // Section 3.3.3 "Put", IrOBEX 1.2
-  // [opcode:1][length:2][Headers:var]
-  auto req = MakeUnique<uint8_t[]>(mRemoteMaxPacketLength);
-
-  int index = 3;
-  index += AppendHeaderBody(&req[index], mRemoteMaxPacketLength - index,
-                            aFileBody, aFileBodyLength);
-
-  SendObexData(Move(req), ObexRequestCode::Put, index);
-
-  mSentFileLength += aFileBodyLength;
-}
-
-void
-BluetoothOppManager::SendPutFinalRequest()
-{
-  if (!mConnected) {
-    return;
-  }
-
-  /**
-   * Section 2.2.9, "End-of-Body", IrObex 1.2
-   * End-of-Body is used to identify the last chunk of the object body.
-   * For most platforms, a PutFinal packet is sent with an zero length
-   * End-of-Body header.
-   */
-
-  // [opcode:1][length:2]
-  int index = 3;
-  auto req = MakeUnique<uint8_t[]>(mRemoteMaxPacketLength);
-  index += AppendHeaderEndOfBody(&req[index]);
-
-  SendObexData(Move(req), ObexRequestCode::PutFinal, index);
-
-  mWaitingToSendPutFinal = false;
-}
-
-void
-BluetoothOppManager::SendDisconnectRequest()
-{
-  if (!mConnected) {
-    return;
-  }
-
-  // Section 3.3.2 "Disconnect", IrOBEX 1.2
-  // [opcode:1][length:2][Headers:var]
-  uint8_t req[255];
-  int index = 3;
-
-  SendObexData(req, ObexRequestCode::Disconnect, index);
-}
-
-void
-BluetoothOppManager::CheckPutFinal(uint32_t aNumRead)
-{
-  if (mSentFileLength + aNumRead >= mFileLength) {
-    mWaitingToSendPutFinal = true;
-  }
-}
-
-bool
-BluetoothOppManager::IsConnected()
-{
-  return mConnected;
-}
-
-void
-BluetoothOppManager::GetAddress(BluetoothAddress& aDeviceAddress)
-{
-  return mSocket->GetAddress(aDeviceAddress);
-}
-
-void
-BluetoothOppManager::ReplyToConnect()
-{
-  if (mConnected) {
-    return;
-  }
-
-  // Section 3.3.1 "Connect", IrOBEX 1.2
-  // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
-  // [Headers:var]
-  uint8_t req[255];
-  int index = 7;
-
-  req[3] = 0x10; // version=1.0
-  req[4] = 0x00; // flag=0x00
-  req[5] = BluetoothOppManager::MAX_PACKET_LENGTH >> 8;
-  req[6] = (uint8_t)BluetoothOppManager::MAX_PACKET_LENGTH;
-
-  SendObexData(req, ObexResponseCode::Success, index);
-}
-
-void
-BluetoothOppManager::ReplyToDisconnectOrAbort()
-{
-  if (!mConnected) {
-    return;
-  }
-
-  // Section 3.3.2 "Disconnect" and Section 3.3.5 "Abort", IrOBEX 1.2
-  // The format of response packet of "Disconnect" and "Abort" are the same
-  // [opcode:1][length:2][Headers:var]
-  uint8_t req[255];
-  int index = 3;
-
-  SendObexData(req, ObexResponseCode::Success, index);
-}
-
-void
-BluetoothOppManager::ReplyToPut(bool aFinal, bool aContinue)
-{
-  if (!mConnected) {
-    return;
-  }
-
-  // The received length can be reset here because this is where we reply to a
-  // complete put packet.
-  mPutPacketReceivedLength = 0;
-
-  // Section 3.3.2 "Disconnect", IrOBEX 1.2
-  // [opcode:1][length:2][Headers:var]
-  uint8_t req[255];
-  int index = 3;
-  uint8_t opcode;
-
-  if (aContinue) {
-    opcode = (aFinal)? ObexResponseCode::Success :
-                       ObexResponseCode::Continue;
-  } else {
-    opcode = (aFinal)? ObexResponseCode::Unauthorized :
-                       ObexResponseCode::Unauthorized & (~FINAL_BIT);
-  }
-
-  SendObexData(req, opcode, index);
-}
-
-void
-BluetoothOppManager::ReplyError(uint8_t aError)
-{
-  BT_LOGR("error: %d", aError);
-
-  // Section 3.2 "Response Format", IrOBEX 1.2
-  // [opcode:1][length:2][Headers:var]
-  uint8_t req[255];
-  int index = 3;
-
-  SendObexData(req, aError, index);
-}
-
-void
-BluetoothOppManager::SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize)
-{
-  if (!mIsServer) {
-    mLastCommand = aOpcode;
-  }
-
-  SetObexPacketInfo(aData, aOpcode, aSize);
-  mSocket->SendSocketData(new UnixSocketRawData(aData, aSize));
-}
-
-void
-BluetoothOppManager::SendObexData(UniquePtr<uint8_t[]> aData, uint8_t aOpcode,
-                                  int aSize)
-{
-  if (!mIsServer) {
-    mLastCommand = aOpcode;
-  }
-
-  SetObexPacketInfo(aData.get(), aOpcode, aSize);
-  mSocket->SendSocketData(new UnixSocketRawData(Move(aData), aSize));
-}
-
-void
-BluetoothOppManager::FileTransferComplete()
-{
-  if (mSendTransferCompleteFlag) {
-    return;
-  }
-
-  NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-transfer-complete");
-  InfallibleTArray<BluetoothNamedValue> parameters;
-
-  AppendNamedValue(parameters, "address", mDeviceAddress);
-  AppendNamedValue(parameters, "success", mSuccessFlag);
-  AppendNamedValue(parameters, "received", mIsServer);
-  AppendNamedValue(parameters, "fileName", mFileName);
-  AppendNamedValue(parameters, "fileLength", mSentFileLength);
-  AppendNamedValue(parameters, "contentType", mContentType);
-
-  BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
-
-  mSendTransferCompleteFlag = true;
-}
-
-void
-BluetoothOppManager::StartFileTransfer()
-{
-  NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-transfer-start");
-  InfallibleTArray<BluetoothNamedValue> parameters;
-
-  AppendNamedValue(parameters, "address", mDeviceAddress);
-  AppendNamedValue(parameters, "received", mIsServer);
-  AppendNamedValue(parameters, "fileName", mFileName);
-  AppendNamedValue(parameters, "fileLength", mFileLength);
-  AppendNamedValue(parameters, "contentType", mContentType);
-
-  BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
-
-  mSendTransferCompleteFlag = false;
-}
-
-void
-BluetoothOppManager::UpdateProgress()
-{
-  NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-update-progress");
-  InfallibleTArray<BluetoothNamedValue> parameters;
-
-  AppendNamedValue(parameters, "address", mDeviceAddress);
-  AppendNamedValue(parameters, "received", mIsServer);
-  AppendNamedValue(parameters, "processedLength", mSentFileLength);
-  AppendNamedValue(parameters, "fileLength", mFileLength);
-
-  BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
-}
-
-void
-BluetoothOppManager::ReceivingFileConfirmation()
-{
-  NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-receiving-file-confirmation");
-  InfallibleTArray<BluetoothNamedValue> parameters;
-
-  AppendNamedValue(parameters, "address", mDeviceAddress);
-  AppendNamedValue(parameters, "fileName", mFileName);
-  AppendNamedValue(parameters, "fileLength", mFileLength);
-  AppendNamedValue(parameters, "contentType", mContentType);
-
-  BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
-}
-
-void
-BluetoothOppManager::NotifyAboutFileChange()
-{
-  NS_NAMED_LITERAL_STRING(data, "modified");
-
-  nsCOMPtr<nsIObserverService> obs =
-    mozilla::services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-
-  obs->NotifyObservers(mDsFile, "file-watcher-notify", data.get());
-}
-
-void
-BluetoothOppManager::OnSocketConnectSuccess(BluetoothSocket* aSocket)
-{
-  BT_LOGR("[%s]", (mIsServer)? "server" : "client");
-  MOZ_ASSERT(aSocket);
-
-  /**
-   * If the created connection is an inbound connection, close server socket
-   * because currently only one file-transfer session is allowed. After that,
-   * we need to make sure that server socket would be nulled out.
-   * As for outbound connections, we just notify the controller that it's done.
-   */
-  if (aSocket == mServerSocket) {
-    MOZ_ASSERT(!mSocket);
-    mServerSocket.swap(mSocket);
-  }
-
-  // Cache device address since we can't get socket address when a remote
-  // device disconnect with us.
-  mSocket->GetAddress(mDeviceAddress);
-
-  // Start sending file if we connect as a client
-  if (!mIsServer) {
-    StartSendingNextFile();
-  }
-}
-
-void
-BluetoothOppManager::OnSocketConnectError(BluetoothSocket* aSocket)
-{
-  BT_LOGR("[%s]", (mIsServer)? "server" : "client");
-
-  if (mServerSocket &&
-      mServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-    mServerSocket->Close();
-  }
-  mServerSocket = nullptr;
-
-  if (mSocket &&
-      mSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-    mSocket->Close();
-  }
-  mSocket = nullptr;
-
-  if (!mIsServer) {
-    // Inform gaia of remaining blobs' sending failure
-    DiscardBlobsToSend();
-  }
-
-  // Listen as a server if there's no more batch to process
-  if (!ProcessNextBatch()) {
-    Listen();
-  }
-}
-
-void
-BluetoothOppManager::OnSocketDisconnect(BluetoothSocket* aSocket)
-{
-  MOZ_ASSERT(aSocket);
-  if (aSocket != mSocket) {
-    // Do nothing when a listening server socket is closed.
-    return;
-  }
-  BT_LOGR("[%s]", (mIsServer) ? "server" : "client");
-
-  /**
-   * It is valid for a bluetooth device which is transfering file via OPP
-   * closing socket without sending OBEX disconnect request first. So we
-   * delete the broken file when we failed to receive a file from the remote,
-   * and notify the transfer has been completed (but failed). We also call
-   * AfterOppDisconnected here to ensure all variables will be cleaned.
-   */
-  if (!mSuccessFlag) {
-    if (mIsServer) {
-      // Remove received file and inform gaia of receiving failure
-      DeleteReceivedFile();
-      FileTransferComplete();
-    } else {
-      // Inform gaia of current blob transfer failure
-      if (mCurrentBlobIndex >= 0) {
-        FileTransferComplete();
-      }
-      // Inform gaia of remaining blobs' sending failure
-      DiscardBlobsToSend();
-    }
-  }
-
-  AfterOppDisconnected();
-  mDeviceAddress.Clear();
-  mSuccessFlag = false;
-
-  mSocket = nullptr; // should already be closed
-
-  // Listen as a server if there's no more batch to process
-  if (!ProcessNextBatch()) {
-    Listen();
-  }
-}
-
-void
-BluetoothOppManager::Disconnect(BluetoothProfileController* aController)
-{
-  if (mSocket) {
-    mSocket->Close();
-  } else {
-    BT_WARNING("%s: No ongoing file transfer to stop", __FUNCTION__);
-  }
-}
-
-NS_IMPL_ISUPPORTS(BluetoothOppManager, nsIObserver)
-
-bool
-BluetoothOppManager::AcquireSdcardMountLock()
-{
-  nsCOMPtr<nsIVolumeService> volumeSrv =
-    do_GetService(NS_VOLUMESERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(volumeSrv, false);
-
-  NS_ENSURE_SUCCESS(
-    volumeSrv->CreateMountLock(NS_LITERAL_STRING("sdcard"),
-                               getter_AddRefs(mMountLock)),
-    false);
-
-  return true;
-}
-
-void
-BluetoothOppManager::OnGetServiceChannel(
-  const BluetoothAddress& aDeviceAddress,
-  const BluetoothUuid& aServiceUuid,
-  int aChannel)
-{
-  if (aChannel < 0) {
-    BluetoothService* bs = BluetoothService::Get();
-    if (!bs || sInShutdown) {
-      OnSocketConnectError(mSocket);
-      return;
-    }
-
-    if (mNeedsUpdatingSdpRecords) {
-      mNeedsUpdatingSdpRecords = false;
-      mLastServiceChannelCheck = TimeStamp::Now();
-    } else {
-      // Refresh SDP records until it gets valid service channel
-      // unless timeout is hit.
-      TimeDuration duration = TimeStamp::Now() - mLastServiceChannelCheck;
-      if (duration.ToMilliseconds() >= kSdpUpdatingTimeoutMs) {
-        OnSocketConnectError(mSocket);
-        return;
-      }
-    }
-
-    if (!bs->UpdateSdpRecords(aDeviceAddress, this)) {
-      OnSocketConnectError(mSocket);
-      return;
-    }
-
-    return; // We update the service records before we connect.
-  }
-
-  mSocket->Connect(aDeviceAddress, aServiceUuid,
-                   BluetoothSocketType::RFCOMM, aChannel,
-                   false, true);
-}
-
-void
-BluetoothOppManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
-{
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs || sInShutdown) {
-    OnSocketConnectError(mSocket);
-    return;
-  }
-
-  if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress, kObexObjectPush, this))) {
-    OnSocketConnectError(mSocket);
-    return;
-  }
-}
-
-void
-BluetoothOppManager::Connect(const BluetoothAddress& aDeviceAddress,
-                             BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothOppManager::OnConnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothOppManager::OnDisconnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothOppManager::Reset()
-{
-  MOZ_ASSERT(false);
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothOppManager.h
+++ /dev/null
@@ -1,241 +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_BluetoothOppManager_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothOppManager_h
-
-#include "BluetoothCommon.h"
-#include "BluetoothProfileManagerBase.h"
-#include "BluetoothSocketObserver.h"
-#include "DeviceStorage.h"
-#include "mozilla/ipc/SocketBase.h"
-#include "mozilla/UniquePtr.h"
-#include "nsCOMArray.h"
-
-class nsIOutputStream;
-class nsIInputStream;
-class nsIVolumeMountLock;
-
-namespace mozilla {
-namespace dom {
-class Blob;
-class BlobParent;
-}
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothSocket;
-class ObexHeaderSet;
-
-class BluetoothOppManager : public BluetoothSocketObserver
-                          , public BluetoothProfileManagerBase
-{
-  class CloseSocketTask;
-  class ReadFileTask;
-  class SendFileBatch;
-  class SendSocketDataTask;
-
-public:
-
-  BT_DECL_PROFILE_MGR_BASE
-  BT_DECL_SOCKET_OBSERVER
-  virtual void GetName(nsACString& aName)
-  {
-    aName.AssignLiteral("OPP");
-  }
-
-  static const int MAX_PACKET_LENGTH = 0xFFFE;
-
-  static void InitOppInterface(BluetoothProfileResultHandler* aRes);
-  static void DeinitOppInterface(BluetoothProfileResultHandler* aRes);
-  static BluetoothOppManager* Get();
-
-  void ClientDataHandler(mozilla::ipc::UnixSocketBuffer* aMessage);
-  void ServerDataHandler(mozilla::ipc::UnixSocketBuffer* aMessage);
-
-  bool Listen();
-
-  bool SendFile(const BluetoothAddress& aDeviceAddress, BlobParent* aActor);
-  bool SendFile(const BluetoothAddress& aDeviceAddress, Blob* aBlob);
-  bool StopSendingFile();
-  bool ConfirmReceivingFile(bool aConfirm);
-
-  void SendConnectRequest();
-  void SendPutHeaderRequest(const nsAString& aFileName, int aFileSize);
-  void SendPutRequest(uint8_t* aFileBody, int aFileBodyLength);
-  void SendPutFinalRequest();
-  void SendDisconnectRequest();
-
-  void ExtractPacketHeaders(const ObexHeaderSet& aHeader);
-  bool ExtractBlobHeaders();
-  void CheckPutFinal(uint32_t aNumRead);
-
-protected:
-  virtual ~BluetoothOppManager();
-
-private:
-  BluetoothOppManager();
-  nsresult Init();
-  void Uninit();
-  void HandleShutdown();
-  void HandleVolumeStateChanged(nsISupports* aSubject);
-
-  void StartFileTransfer();
-  void StartSendingNextFile();
-  void FileTransferComplete();
-  void UpdateProgress();
-  void ReceivingFileConfirmation();
-  bool CreateFile();
-  bool WriteToFile(const uint8_t* aData, int aDataLength);
-  void RestoreReceivedFileAndNotify();
-  void DeleteReceivedFile();
-  void ReplyToConnect();
-  void ReplyToDisconnectOrAbort();
-  void ReplyToPut(bool aFinal, bool aContinue);
-  void ReplyError(uint8_t aError);
-  void AfterOppConnected();
-  void AfterFirstPut();
-  void AfterOppDisconnected();
-  void ValidateFileName();
-  bool IsReservedChar(char16_t c);
-  void ClearQueue();
-  void RetrieveSentFileName();
-  void NotifyAboutFileChange();
-  bool AcquireSdcardMountLock();
-  void SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
-  void SendObexData(UniquePtr<uint8_t[]> aData, uint8_t aOpcode, int aSize);
-  void AppendBlobToSend(const BluetoothAddress& aDeviceAddress, Blob* aBlob);
-  void DiscardBlobsToSend();
-  bool ProcessNextBatch();
-  void ConnectInternal(const BluetoothAddress& aDeviceAddress);
-
-  /**
-   * Usually we won't get a full PUT packet in one operation, which means that
-   * a packet may be devided into several parts and BluetoothOppManager should
-   * be in charge of assembling.
-   *
-   * @return true if a packet has been fully received.
-   *         false if the received length exceeds/not reaches the expected
-   *         length.
-   */
-  bool ComposePacket(uint8_t aOpCode,
-                     mozilla::ipc::UnixSocketBuffer* aMessage);
-
-  /**
-   * OBEX session status.
-   * Set when OBEX session is established.
-   */
-  bool mConnected;
-  BluetoothAddress mDeviceAddress;
-
-  /**
-   * Remote information
-   */
-  uint8_t mRemoteObexVersion;
-  uint8_t mRemoteConnectionFlags;
-  int mRemoteMaxPacketLength;
-
-  /**
-   * For sending files, we decide our next action based on current command and
-   * previous one.
-   * For receiving files, we don't need previous command and it is set to 0
-   * as a default value.
-   */
-  int mLastCommand;
-
-  int mPacketLength;
-  int mPutPacketReceivedLength;
-  int mBodySegmentLength;
-  int mUpdateProgressCounter;
-
-  /**
-   * When it is true and the target service on target device couldn't be found,
-   * refreshing SDP records is necessary.
-   */
-  bool mNeedsUpdatingSdpRecords;
-
-  /**
-   * This holds the time when OPP manager fail to get service channel and
-   * prepare to refresh SDP records.
-   */
-  mozilla::TimeStamp mLastServiceChannelCheck;
-
-  /**
-   * Set when StopSendingFile() is called.
-   */
-  bool mAbortFlag;
-
-  /**
-   * Set when receiving the first PUT packet of a new file
-   */
-  bool mNewFileFlag;
-
-  /**
-   * Set when receiving a PutFinal packet
-   */
-  bool mPutFinalFlag;
-
-  /**
-   * Set when FileTransferComplete() is called
-   */
-  bool mSendTransferCompleteFlag;
-
-  /**
-   * Set when a transfer is successfully completed.
-   */
-  bool mSuccessFlag;
-
-  /**
-   * True: Receive file (Server)
-   * False: Send file (Client)
-   */
-  bool mIsServer;
-
-  /**
-   * Set when receiving the first PUT packet and wait for
-   * ConfirmReceivingFile() to be called.
-   */
-  bool mWaitingForConfirmationFlag;
-
-  nsString mFileName;
-  nsString mContentType;
-  uint32_t mFileLength;
-  uint32_t mSentFileLength;
-  bool mWaitingToSendPutFinal;
-
-  UniquePtr<uint8_t[]> mBodySegment;
-  UniquePtr<uint8_t[]> mReceivedDataBuffer;
-
-  int mCurrentBlobIndex;
-  RefPtr<Blob> mBlob;
-  nsTArray<SendFileBatch> mBatches;
-
-  /**
-   * A seperate member thread is required because our read calls can block
-   * execution, which is not allowed to happen on the IOThread.
-   */
-  nsCOMPtr<nsIThread> mReadFileThread;
-  nsCOMPtr<nsIOutputStream> mOutputStream;
-  nsCOMPtr<nsIInputStream> mInputStream;
-  nsCOMPtr<nsIVolumeMountLock> mMountLock;
-  RefPtr<DeviceStorageFile> mDsFile;
-  RefPtr<DeviceStorageFile> mDummyDsFile;
-
-  // If a connection has been established, mSocket will be the socket
-  // communicating with the remote socket. We maintain the invariant that if
-  // mSocket is non-null, mServerSocket must be null (and vice versa).
-  RefPtr<BluetoothSocket> mSocket;
-
-  // Server sockets. Once an inbound connection is established, it will hand
-  // over the ownership to mSocket, and get a new server socket while Listen()
-  // is called.
-  RefPtr<BluetoothSocket> mServerSocket;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothOppManager_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothPbapManager.cpp
+++ /dev/null
@@ -1,1272 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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 "base/basictypes.h"
-#include "BluetoothPbapManager.h"
-
-#include "BluetoothService.h"
-#include "BluetoothSocket.h"
-#include "BluetoothUtils.h"
-#include "BluetoothUuidHelper.h"
-
-#include "mozilla/dom/BluetoothPbapParametersBinding.h"
-#include "mozilla/EndianUtils.h"
-#include "mozilla/dom/File.h"
-#include "mozilla/dom/ipc/BlobParent.h"
-#include "mozilla/RefPtr.h"
-#include "mozilla/Services.h"
-#include "mozilla/StaticPtr.h"
-#include "nsIInputStream.h"
-#include "nsIObserver.h"
-#include "nsIObserverService.h"
-#include "nsNetCID.h"
-
-#include "mozilla/Unused.h"
-
-USING_BLUETOOTH_NAMESPACE
-using namespace mozilla;
-using namespace mozilla::dom;
-using namespace mozilla::ipc;
-
-namespace {
-  // UUID of PBAP PSE
-  static const BluetoothUuid kPbapPSE(PBAP_PSE);
-
-  // UUID used in PBAP OBEX target header
-  static const BluetoothUuid kPbapObexTarget(0x79, 0x61, 0x35, 0xF0,
-                                             0xF0, 0xC5, 0x11, 0xD8,
-                                             0x09, 0x66, 0x08, 0x00,
-                                             0x20, 0x0C, 0x9A, 0x66);
-
-  // App parameters to pull phonebook
-  static const AppParameterTag sPhonebookTags[] = {
-    AppParameterTag::Format,
-    AppParameterTag::PropertySelector,
-    AppParameterTag::MaxListCount,
-    AppParameterTag::ListStartOffset,
-    AppParameterTag::vCardSelector
-  };
-
-  // App parameters to pull vCard listing
-  static const AppParameterTag sVCardListingTags[] = {
-    AppParameterTag::Order,
-    AppParameterTag::SearchValue,
-    AppParameterTag::SearchProperty,
-    AppParameterTag::MaxListCount,
-    AppParameterTag::ListStartOffset,
-    AppParameterTag::vCardSelector
-  };
-
-  // App parameters to pull vCard entry
-  static const AppParameterTag sVCardEntryTags[] = {
-    AppParameterTag::Format,
-    AppParameterTag::PropertySelector
-  };
-
-  StaticRefPtr<BluetoothPbapManager> sPbapManager;
-  static bool sInShutdown = false;
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-NS_IMETHODIMP
-BluetoothPbapManager::Observe(nsISupports* aSubject,
-                              const char* aTopic,
-                              const char16_t* aData)
-{
-  MOZ_ASSERT(sPbapManager);
-
-  if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    HandleShutdown();
-    return NS_OK;
-  }
-
-  MOZ_ASSERT(false, "PbapManager got unexpected topic!");
-  return NS_ERROR_UNEXPECTED;
-}
-
-void
-BluetoothPbapManager::HandleShutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  sInShutdown = true;
-  Disconnect(nullptr);
-  Uninit();
-
-  sPbapManager = nullptr;
-}
-
-BluetoothPbapManager::BluetoothPbapManager() : mPhonebookSizeRequired(false)
-                                             , mConnected(false)
-                                             , mRemoteMaxPacketLength(0)
-{
-  mCurrentPath.AssignLiteral("");
-}
-
-BluetoothPbapManager::~BluetoothPbapManager()
-{ }
-
-nsresult
-BluetoothPbapManager::Init()
-{
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  if (NS_WARN_IF(!obs)) {
-    return NS_ERROR_NOT_AVAILABLE;
-  }
-
-  auto rv = obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  /**
-   * We don't start listening here as BluetoothServiceBluedroid calls Listen()
-   * immediately when BT stops.
-   *
-   * If we start listening here, the listening fails when device boots up since
-   * Listen() is called again and restarts server socket. The restart causes
-   * absence of read events when device boots up.
-   */
-
-  return NS_OK;
-}
-
-void
-BluetoothPbapManager::Uninit()
-{
-  if (mServerSocket) {
-    mServerSocket->SetObserver(nullptr);
-
-    if (mServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-      mServerSocket->Close();
-    }
-    mServerSocket = nullptr;
-  }
-
-  if (mSocket) {
-    mSocket->SetObserver(nullptr);
-
-    if (mSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-      mSocket->Close();
-    }
-    mSocket = nullptr;
-  }
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  if (NS_WARN_IF(!obs)) {
-    return;
-  }
-
-  Unused << NS_WARN_IF(NS_FAILED(
-    obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)));
-}
-
-// static
-void
-BluetoothPbapManager::InitPbapInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (aRes) {
-    aRes->Init();
-  }
-}
-
-// static
-void
-BluetoothPbapManager::DeinitPbapInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (sPbapManager) {
-    sPbapManager->Uninit();
-    sPbapManager = nullptr;
-  }
-
-  if (aRes) {
-    aRes->Deinit();
-  }
-}
-
-//static
-BluetoothPbapManager*
-BluetoothPbapManager::Get()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Exit early if sPbapManager already exists
-  if (sPbapManager) {
-    return sPbapManager;
-  }
-
-  // Do not create a new instance if we're in shutdown
-  if (NS_WARN_IF(sInShutdown)) {
-    return nullptr;
-  }
-
-  // Create a new instance, register, and return
-  RefPtr<BluetoothPbapManager> manager = new BluetoothPbapManager();
-  if (NS_WARN_IF(NS_FAILED(manager->Init()))) {
-    return nullptr;
-  }
-
-  sPbapManager = manager;
-  return sPbapManager;
-}
-
-bool
-BluetoothPbapManager::Listen()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Fail to listen if |mSocket| already exists
-  if (NS_WARN_IF(mSocket)) {
-    return false;
-  }
-
-  /**
-   * Restart server socket since its underlying fd becomes invalid when
-   * BT stops; otherwise no more read events would be received even if
-   * BT restarts.
-   */
-  if (mServerSocket &&
-      mServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-    mServerSocket->Close();
-  }
-  mServerSocket = nullptr;
-
-  mServerSocket = new BluetoothSocket(this);
-
-  nsresult rv = mServerSocket->Listen(
-    NS_LITERAL_STRING("OBEX Phonebook Access Server"),
-    kPbapPSE,
-    BluetoothSocketType::RFCOMM,
-    BluetoothReservedChannels::CHANNEL_PBAP_PSE, false, true);
-
-  if (NS_FAILED(rv)) {
-    mServerSocket = nullptr;
-    return false;
-  }
-
-  BT_LOGR("PBAP socket is listening");
-  return true;
-}
-
-// Virtual function of class SocketConsumer
-void
-BluetoothPbapManager::ReceiveSocketData(BluetoothSocket* aSocket,
-                                        UniquePtr<UnixSocketBuffer>& aMessage)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * Ensure
-   * - valid access to data[0], i.e., opCode
-   * - received packet length smaller than max packet length
-   */
-  int receivedLength = aMessage->GetSize();
-  if (receivedLength < 1 || receivedLength > MAX_PACKET_LENGTH) {
-    ReplyError(ObexResponseCode::BadRequest);
-    return;
-  }
-
-  const uint8_t* data = aMessage->GetData();
-  uint8_t opCode = data[0];
-  ObexHeaderSet pktHeaders;
-  switch (opCode) {
-    case ObexRequestCode::Connect:
-      // Section 3.3.1 "Connect", IrOBEX 1.2
-      // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
-      // [Headers:var]
-      if (receivedLength < 7 ||
-          !ParseHeaders(&data[7], receivedLength - 7, &pktHeaders)) {
-        ReplyError(ObexResponseCode::BadRequest);
-        return;
-      }
-
-      // Section 6.4 "Establishing an OBEX Session", PBAP 1.2
-      // The OBEX header target shall equal to kPbapObexTarget.
-      if (!CompareHeaderTarget(pktHeaders)) {
-        ReplyError(ObexResponseCode::BadRequest);
-        return;
-      }
-
-      // Section 3.5 "Authentication Procedure", IrOBEX 1.2
-      // An user input password is required to reply to authentication
-      // challenge. The OBEX success response will be sent after gaia
-      // replies correct password.
-      if (pktHeaders.Has(ObexHeaderId::AuthChallenge)) {
-        ObexResponseCode response = NotifyPasswordRequest(pktHeaders);
-        if (response != ObexResponseCode::Success) {
-          ReplyError(response);
-        }
-        return;
-      }
-
-      // Save the max packet length from remote information
-      mRemoteMaxPacketLength = BigEndian::readUint16(&data[5]);
-
-      if (mRemoteMaxPacketLength < kObexLeastMaxSize) {
-        BT_LOGR("Remote maximum packet length %d is smaller than %d bytes",
-          mRemoteMaxPacketLength, kObexLeastMaxSize);
-        mRemoteMaxPacketLength = 0;
-        ReplyError(ObexResponseCode::BadRequest);
-        return;
-      }
-
-      ReplyToConnect();
-      AfterPbapConnected();
-      break;
-    case ObexRequestCode::Disconnect:
-    case ObexRequestCode::Abort:
-      // Section 3.3.2 "Disconnect" and Section 3.3.5 "Abort", IrOBEX 1.2
-      // The format of request packet of "Disconnect" and "Abort" are the same
-      // [opcode:1][length:2][Headers:var]
-      if (receivedLength < 3 ||
-          !ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
-        ReplyError(ObexResponseCode::BadRequest);
-        return;
-      }
-
-      ReplyToDisconnectOrAbort();
-      AfterPbapDisconnected();
-      break;
-    case ObexRequestCode::SetPath: {
-      // Section 3.3.6 "SetPath", IrOBEX 1.2
-      // [opcode:1][length:2][flags:1][contants:1][Headers:var]
-      if (receivedLength < 5 ||
-          !ParseHeaders(&data[5], receivedLength - 5, &pktHeaders)) {
-        ReplyError(ObexResponseCode::BadRequest);
-        return;
-      }
-
-      ObexResponseCode response = SetPhoneBookPath(pktHeaders, data[3]);
-      if (response != ObexResponseCode::Success) {
-        ReplyError(response);
-        return;
-      }
-
-      ReplyToSetPath();
-      break;
-    }
-    case ObexRequestCode::Get:
-      /*
-       * Section 6.2.2 "OBEX Headers in Multi-Packet Responses", IrOBEX 1.2
-       * All OBEX request messages shall be sent as one OBEX packet containing
-       * all the headers, i.e., OBEX GET with opcode 0x83 shall always be
-       * used, and GET with opcode 0x03 shall never be used.
-       */
-      BT_LOGR("PBAP shall always use OBEX GetFinal instead of Get.");
-
-      // no break. Treat 'Get' as 'GetFinal' for error tolerance.
-    case ObexRequestCode::GetFinal: {
-      /*
-       * When |mVCardDataStream| requires multiple response packets to complete,
-       * the client should continue to issue GET requests until the final body
-       * information (i.e., End-of-Body header) arrives, along with
-       * ObexResponseCode::Success
-       */
-      if (mVCardDataStream) {
-        if (!ReplyToGet()) {
-          BT_LOGR("Failed to reply to PBAP GET request.");
-          ReplyError(ObexResponseCode::InternalServerError);
-        }
-        return;
-      }
-
-      // Section 3.1 "Request format", IrOBEX 1.2
-      // The format of an OBEX request is
-      // [opcode:1][length:2][Headers:var]
-      if (receivedLength < 3 ||
-          !ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
-        ReplyError(ObexResponseCode::BadRequest);
-        return;
-      }
-
-      ObexResponseCode response = NotifyPbapRequest(pktHeaders);
-      if (response != ObexResponseCode::Success) {
-        ReplyError(response);
-        return;
-      }
-      // OBEX success response will be sent after gaia replies PBAP request
-      break;
-    }
-    case ObexRequestCode::Put:
-    case ObexRequestCode::PutFinal:
-      ReplyError(ObexResponseCode::BadRequest);
-      BT_LOGR("Unsupported ObexRequestCode %x", opCode);
-      break;
-    default:
-      ReplyError(ObexResponseCode::NotImplemented);
-      BT_LOGR("Unrecognized ObexRequestCode %x", opCode);
-      break;
-  }
-}
-
-bool
-BluetoothPbapManager::CompareHeaderTarget(const ObexHeaderSet& aHeader)
-{
-  const ObexHeader* header = aHeader.GetHeader(ObexHeaderId::Target);
-
-  if (!header) {
-    BT_LOGR("No ObexHeaderId::Target in header");
-    return false;
-  }
-
-  if (header->mDataLength != sizeof(BluetoothUuid)) {
-    BT_LOGR("Length mismatch: %d != 16", header->mDataLength);
-    return false;
-  }
-
-  for (uint8_t i = 0; i < sizeof(BluetoothUuid); i++) {
-    if (header->mData[i] != kPbapObexTarget.mUuid[i]) {
-      BT_LOGR("UUID mismatch: received target[%d]=0x%x != 0x%x",
-              i, header->mData[i], kPbapObexTarget.mUuid[i]);
-      return false;
-    }
-  }
-
-  return true;
-}
-
-ObexResponseCode
-BluetoothPbapManager::SetPhoneBookPath(const ObexHeaderSet& aHeader,
-                                       uint8_t flags)
-{
-  // Section 5.2 "SetPhoneBook Function", PBAP 1.2
-  // flags bit 1 must be 1 and bit 2~7 be 0
-  if ((flags >> 1) != 1) {
-    BT_LOGR("Illegal flags [0x%x]: bits 1~7 must be 0x01", flags);
-    return ObexResponseCode::BadRequest;
-  }
-
-  nsString newPath = mCurrentPath;
-
-  /**
-   * Three cases:
-   * 1) Go up 1 level   - flags bit 0 is 1
-   * 2) Go back to root - flags bit 0 is 0 AND name header is empty
-   * 3) Go down 1 level - flags bit 0 is 0 AND name header is not empty,
-   *                      where name header is the name of child folder
-   */
-  if (flags & 1) {
-    // Go up 1 level
-    if (!newPath.IsEmpty()) {
-      int32_t lastSlashIdx = newPath.RFindChar('/');
-      if (lastSlashIdx != -1) {
-        newPath = StringHead(newPath, lastSlashIdx);
-      } else {
-        // The parent folder is root.
-        newPath.AssignLiteral("");
-      }
-    }
-  } else {
-    MOZ_ASSERT(aHeader.Has(ObexHeaderId::Name));
-
-    nsString childFolderName;
-    aHeader.GetName(childFolderName);
-    if (childFolderName.IsEmpty()) {
-      // Go back to root
-      newPath.AssignLiteral("");
-    } else {
-      // Go down 1 level
-      if (!newPath.IsEmpty()) {
-        newPath.AppendLiteral("/");
-      }
-      newPath.Append(childFolderName);
-    }
-  }
-
-  // Ensure the new path is legal
-  if (!IsLegalPath(newPath)) {
-    BT_LOGR("Illegal phone book path [%s]",
-            NS_ConvertUTF16toUTF8(newPath).get());
-    return ObexResponseCode::NotFound;
-  }
-
-  mCurrentPath = newPath;
-  BT_LOGR("current path [%s]", NS_ConvertUTF16toUTF8(mCurrentPath).get());
-
-  return ObexResponseCode::Success;
-}
-
-ObexResponseCode
-BluetoothPbapManager::NotifyPbapRequest(const ObexHeaderSet& aHeader)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Get content type and name
-  nsString type, name;
-  aHeader.GetContentType(type);
-  aHeader.GetName(name);
-
-  // Configure request based on content type
-  nsString reqId;
-  uint8_t tagCount;
-  const AppParameterTag* tags;
-  if (type.EqualsLiteral("x-bt/phonebook")) {
-    reqId.AssignLiteral(PULL_PHONEBOOK_REQ_ID);
-    tagCount = MOZ_ARRAY_LENGTH(sPhonebookTags);
-    tags = sPhonebookTags;
-
-    // Ensure the name of phonebook object is legal
-    if (!IsLegalPhonebookName(name)) {
-      BT_LOGR("Illegal phone book object name [%s]",
-              NS_ConvertUTF16toUTF8(name).get());
-      return ObexResponseCode::NotFound;
-    }
-  } else if (type.EqualsLiteral("x-bt/vcard-listing")) {
-    reqId.AssignLiteral(PULL_VCARD_LISTING_REQ_ID);
-    tagCount = MOZ_ARRAY_LENGTH(sVCardListingTags);
-    tags = sVCardListingTags;
-
-    // Section 5.3.3 "Name", PBAP 1.2:
-    // ... PullvCardListing function uses relative paths. An empty name header
-    // may be sent to retrieve the vCard Listing object of the current folder.
-    name = name.IsEmpty() ? mCurrentPath
-                          : mCurrentPath + NS_LITERAL_STRING("/") + name;
-  } else if (type.EqualsLiteral("x-bt/vcard")) {
-    reqId.AssignLiteral(PULL_VCARD_ENTRY_REQ_ID);
-    tagCount = MOZ_ARRAY_LENGTH(sVCardEntryTags);
-    tags = sVCardEntryTags;
-
-    // Convert relative path to absolute path if it's not using X-BT-UID.
-    if (name.Find(NS_LITERAL_STRING("X-BT-UID")) == kNotFound) {
-      name = mCurrentPath + NS_LITERAL_STRING("/") + name;
-    }
-  } else {
-    BT_LOGR("Unknown PBAP request type: %s",
-            NS_ConvertUTF16toUTF8(type).get());
-    return ObexResponseCode::BadRequest;
-  }
-
-  // Ensure bluetooth service is available
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    BT_LOGR("Failed to get Bluetooth service");
-    return ObexResponseCode::PreconditionFailed;
-  }
-
-  // Pack PBAP request
-  InfallibleTArray<BluetoothNamedValue> data;
-  AppendNamedValue(data, "name", name);
-  for (uint8_t i = 0; i < tagCount; i++) {
-    AppendNamedValueByTagId(aHeader, data, tags[i]);
-  }
-
-  bs->DistributeSignal(reqId, NS_LITERAL_STRING(KEY_ADAPTER), data);
-
-  return ObexResponseCode::Success;
-}
-
-ObexResponseCode
-BluetoothPbapManager::NotifyPasswordRequest(const ObexHeaderSet& aHeader)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aHeader.Has(ObexHeaderId::AuthChallenge));
-
-  // Get authentication challenge data
-  const ObexHeader* authHeader = aHeader.GetHeader(ObexHeaderId::AuthChallenge);
-
-  // Get nonce from authentication challenge
-  // Section 3.5.1 "Digest Challenge", IrOBEX spec 1.2
-  // The tag-length-value triplet of nonce is
-  //   [tagId:1][length:1][nonce:16]
-  uint8_t offset = 0;
-  do {
-    uint8_t tagId = authHeader->mData[offset++];
-    uint8_t length = authHeader->mData[offset++];
-
-    BT_LOGR("AuthChallenge header includes tagId %d", tagId);
-    if (tagId == ObexDigestChallenge::Nonce) {
-      memcpy(mRemoteNonce, &authHeader->mData[offset], DIGEST_LENGTH);
-    }
-
-    offset += length;
-  } while (offset < authHeader->mDataLength);
-
-  // Ensure bluetooth service is available
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    return ObexResponseCode::PreconditionFailed;
-  }
-
-  // Notify gaia of authentiation challenge
-  // TODO: Append realm if 1) gaia needs to display it and
-  //       2) it's in authenticate challenge header
-  InfallibleTArray<BluetoothNamedValue> props;
-  bs->DistributeSignal(NS_LITERAL_STRING(OBEX_PASSWORD_REQ_ID),
-                       NS_LITERAL_STRING(KEY_ADAPTER),
-                       props);
-
-  return ObexResponseCode::Success;
-}
-
-void
-BluetoothPbapManager::AppendNamedValueByTagId(
-  const ObexHeaderSet& aHeader,
-  InfallibleTArray<BluetoothNamedValue>& aValues,
-  const AppParameterTag aTagId)
-{
-  uint8_t buf[64];
-  if (!aHeader.GetAppParameter(aTagId, buf, 64)) {
-    return;
-  }
-
-  switch (aTagId) {
-    case AppParameterTag::Order: {
-      using namespace mozilla::dom::vCardOrderTypeValues;
-      uint32_t order =
-        buf[0] < ArrayLength(strings) ? static_cast<uint32_t>(buf[0])
-                                      : 0; // default: indexed
-      AppendNamedValue(aValues, "order", order);
-      break;
-    }
-    case AppParameterTag::SearchProperty: {
-      using namespace mozilla::dom::vCardSearchKeyTypeValues;
-      uint32_t searchKey =
-        buf[0] < ArrayLength(strings) ? static_cast<uint32_t>(buf[0])
-                                      : 0; // default: name
-      AppendNamedValue(aValues, "searchKey", searchKey);
-      break;
-    }
-    case AppParameterTag::SearchValue:
-      // Section 5.3.4.3 "SearchValue {<text string>}", PBAP 1.2
-      // The UTF-8 character set shall be used for <text string>.
-
-      // Store UTF-8 string with nsCString to follow MDN:Internal_strings
-      AppendNamedValue(aValues, "searchText", nsCString((char *) buf));
-      break;
-    case AppParameterTag::MaxListCount: {
-      uint16_t maxListCount = BigEndian::readUint16(buf);
-      AppendNamedValue(aValues, "maxListCount",
-                       static_cast<uint32_t>(maxListCount));
-
-      // Section 5 "Phone Book Access Profile Functions", PBAP 1.2
-      // Replying 'PhonebookSize' is mandatory if 'MaxListCount' parameter
-      // is present in the request with a value of 0, else it is excluded.
-      mPhonebookSizeRequired = !maxListCount;
-      break;
-    }
-    case AppParameterTag::ListStartOffset:
-      AppendNamedValue(aValues, "listStartOffset",
-                       static_cast<uint32_t>(BigEndian::readUint16(buf)));
-      break;
-    case AppParameterTag::PropertySelector:
-      AppendNamedValue(aValues, "propSelector", PackPropertiesMask(buf, 64));
-      break;
-    case AppParameterTag::Format:
-      AppendNamedValue(aValues, "format", static_cast<bool>(buf[0]));
-      break;
-    case AppParameterTag::vCardSelector: {
-      bool hasSelectorOperator = aHeader.GetAppParameter(
-        AppParameterTag::vCardSelectorOperator, buf, 64);
-      AppendNamedValue(aValues,
-                       hasSelectorOperator && buf[0] ? "vCardSelector_AND"
-                                                     : "vCardSelector_OR",
-                       PackPropertiesMask(buf, 64));
-      break;
-    }
-    default:
-      BT_LOGR("Unsupported AppParameterTag: %x", aTagId);
-      break;
-  }
-}
-
-bool
-BluetoothPbapManager::IsLegalPath(const nsAString& aPath)
-{
-  static const char* sLegalPaths[] = {
-    "", // root
-    "telecom",
-    "telecom/pb",
-    "telecom/ich",
-    "telecom/och",
-    "telecom/mch",
-    "telecom/cch",
-    "SIM1",
-    "SIM1/telecom",
-    "SIM1/telecom/pb",
-    "SIM1/telecom/ich",
-    "SIM1/telecom/och",
-    "SIM1/telecom/mch",
-    "SIM1/telecom/cch"
-  };
-
-  NS_ConvertUTF16toUTF8 path(aPath);
-  for (uint8_t i = 0; i < MOZ_ARRAY_LENGTH(sLegalPaths); i++) {
-    if (!strcmp(path.get(), sLegalPaths[i])) {
-      return true;
-    }
-  }
-
-  return false;
-}
-
-bool
-BluetoothPbapManager::IsLegalPhonebookName(const nsAString& aName)
-{
-  static const char* sLegalNames[] = {
-    "telecom/pb.vcf",
-    "telecom/ich.vcf",
-    "telecom/och.vcf",
-    "telecom/mch.vcf",
-    "telecom/cch.vcf",
-    "SIM1/telecom/pb.vcf",
-    "SIM1/telecom/ich.vcf",
-    "SIM1/telecom/och.vcf",
-    "SIM1/telecom/mch.vcf",
-    "SIM1/telecom/cch.vcf"
-  };
-
-  NS_ConvertUTF16toUTF8 name(aName);
-  for (uint8_t i = 0; i < MOZ_ARRAY_LENGTH(sLegalNames); i++) {
-    if (!strcmp(name.get(), sLegalNames[i])) {
-      return true;
-    }
-  }
-
-  return false;
-}
-
-void
-BluetoothPbapManager::AfterPbapConnected()
-{
-  mCurrentPath.AssignLiteral("");
-  mConnected = true;
-}
-
-void
-BluetoothPbapManager::AfterPbapDisconnected()
-{
-  mConnected = false;
-
-  mRemoteMaxPacketLength = 0;
-  mPhonebookSizeRequired = false;
-
-  if (mVCardDataStream) {
-    mVCardDataStream->Close();
-    mVCardDataStream = nullptr;
-  }
-}
-
-bool
-BluetoothPbapManager::IsConnected()
-{
-  return mConnected;
-}
-
-void
-BluetoothPbapManager::GetAddress(BluetoothAddress& aDeviceAddress)
-{
-  return mSocket->GetAddress(aDeviceAddress);
-}
-
-void
-BluetoothPbapManager::ReplyToConnect(const nsAString& aPassword)
-{
-  if (mConnected) {
-    return;
-  }
-
-  // Section 3.3.1 "Connect", IrOBEX 1.2
-  // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
-  // [Headers:var]
-  uint8_t res[kObexLeastMaxSize];
-  int index = 7;
-
-  res[3] = 0x10; // version=1.0
-  res[4] = 0x00; // flag=0x00
-  res[5] = BluetoothPbapManager::MAX_PACKET_LENGTH >> 8;
-  res[6] = (uint8_t)BluetoothPbapManager::MAX_PACKET_LENGTH;
-
-  // Section 6.4 "Establishing an OBEX Session", PBAP 1.2
-  // Headers: [Who:16][Connection ID]
-  index += AppendHeaderWho(&res[index], kObexLeastMaxSize,
-                           kPbapObexTarget.mUuid, sizeof(BluetoothUuid));
-  index += AppendHeaderConnectionId(&res[index], 0x01);
-
-  // Authentication response
-  if (!aPassword.IsEmpty()) {
-    // Section 3.5.2.1 "Request-digest", PBAP 1.2
-    // The request-digest is required and calculated as follows:
-    //   H(nonce ":" password)
-    uint32_t hashStringLength = DIGEST_LENGTH + aPassword.Length() + 1;
-    UniquePtr<char[]> hashString(new char[hashStringLength]);
-
-    memcpy(hashString.get(), mRemoteNonce, DIGEST_LENGTH);
-    hashString[DIGEST_LENGTH] = ':';
-    memcpy(&hashString[DIGEST_LENGTH + 1],
-           NS_ConvertUTF16toUTF8(aPassword).get(),
-           aPassword.Length());
-    MD5Hash(hashString.get(), hashStringLength);
-
-    // 2 tag-length-value triplets: <request-digest:16><nonce:16>
-    uint8_t digestResponse[(DIGEST_LENGTH + 2) * 2];
-    int offset = AppendAppParameter(digestResponse, sizeof(digestResponse),
-                                    ObexDigestResponse::ReqDigest,
-                                    mHashRes, DIGEST_LENGTH);
-    offset += AppendAppParameter(&digestResponse[offset],
-                                 sizeof(digestResponse) - offset,
-                                 ObexDigestResponse::NonceChallenged,
-                                 mRemoteNonce, DIGEST_LENGTH);
-
-    index += AppendAuthResponse(&res[index], kObexLeastMaxSize - index,
-                                digestResponse, offset);
-  }
-
-  SendObexData(res, ObexResponseCode::Success, index);
-}
-
-nsresult
-BluetoothPbapManager::MD5Hash(char *buf, uint32_t len)
-{
-  nsresult rv;
-
-  // Cache a reference to the nsICryptoHash instance since we'll be calling
-  // this function frequently.
-  if (!mVerifier) {
-    mVerifier = do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID, &rv);
-    if (NS_FAILED(rv)) {
-      BT_LOGR("MD5Hash: no crypto hash!");
-      return rv;
-    }
-  }
-
-  rv = mVerifier->Init(nsICryptoHash::MD5);
-  if (NS_FAILED(rv)) return rv;
-
-  rv = mVerifier->Update((unsigned char*)buf, len);
-  if (NS_FAILED(rv)) return rv;
-
-  nsAutoCString hashString;
-  rv = mVerifier->Finish(false, hashString);
-  if (NS_FAILED(rv)) return rv;
-
-  NS_ENSURE_STATE(hashString.Length() == sizeof(mHashRes));
-  memcpy(mHashRes, hashString.get(), hashString.Length());
-
-  return rv;
-}
-
-void
-BluetoothPbapManager::ReplyToDisconnectOrAbort()
-{
-  if (!mConnected) {
-    return;
-  }
-
-  // Section 3.3.2 "Disconnect" and Section 3.3.5 "Abort", IrOBEX 1.2
-  // The format of response packet of "Disconnect" and "Abort" are the same
-  // [opcode:1][length:2][Headers:var]
-  uint8_t res[kObexLeastMaxSize];
-  int index = kObexRespHeaderSize;
-
-  SendObexData(res, ObexResponseCode::Success, index);
-}
-
-void
-BluetoothPbapManager::ReplyToSetPath()
-{
-  if (!mConnected) {
-    return;
-  }
-
-  // Section 3.3.6 "SetPath", IrOBEX 1.2
-  // [opcode:1][length:2][Headers:var]
-  uint8_t res[kObexLeastMaxSize];
-  int index = kObexRespHeaderSize;
-
-  SendObexData(res, ObexResponseCode::Success, index);
-}
-
-InfallibleTArray<uint32_t>
-BluetoothPbapManager::PackPropertiesMask(uint8_t* aData, int aSize)
-{
-  InfallibleTArray<uint32_t> propSelector;
-
-  // Table 5.1 "Property Mask", PBAP 1.2
-  // PropertyMask is a 64-bit mask that indicates the properties contained in
-  // the requested vCard objects. We only support bit 0~31 since the rest are
-  // reserved for future use or vendor specific properties.
-
-  uint32_t x = BigEndian::readUint32(&aData[4]);
-
-  uint32_t count = 0;
-  while (x) {
-    if (x & 1) {
-      propSelector.AppendElement(count);
-    }
-
-    ++count;
-    x >>= 1;
-  }
-
-  return propSelector;
-}
-
-void
-BluetoothPbapManager::ReplyToAuthChallenge(const nsAString& aPassword)
-{
-  // Cancel authentication
-  if (aPassword.IsEmpty()) {
-    ReplyError(ObexResponseCode::Unauthorized);
-    return;
-  }
-
-  ReplyToConnect(aPassword);
-  AfterPbapConnected();
-}
-
-bool
-BluetoothPbapManager::ReplyToPullPhonebook(BlobParent* aActor,
-                                           uint16_t aPhonebookSize)
-{
-  RefPtr<BlobImpl> impl = aActor->GetBlobImpl();
-  RefPtr<Blob> blob = Blob::Create(nullptr, impl);
-
-  return ReplyToPullPhonebook(blob.get(), aPhonebookSize);
-}
-
-bool
-BluetoothPbapManager::ReplyToPullPhonebook(Blob* aBlob, uint16_t aPhonebookSize)
-{
-  if (!mConnected) {
-    return false;
-  }
-
-  /**
-   * Open vCard input stream only if |mPhonebookSizeRequired| is false,
-   * according to section 2.1.4.3 "MaxListCount", PBAP 1.2:
-   * "When MaxListCount = 0, ... The response shall not contain any
-   *  Body header."
-   */
-  if (!mPhonebookSizeRequired && !GetInputStreamFromBlob(aBlob)) {
-    ReplyError(ObexResponseCode::InternalServerError);
-    return false;
-  }
-
-  return ReplyToGet(aPhonebookSize);
-}
-
-bool
-BluetoothPbapManager::ReplyToPullvCardListing(BlobParent* aActor,
-                                              uint16_t aPhonebookSize)
-{
-  RefPtr<BlobImpl> impl = aActor->GetBlobImpl();
-  RefPtr<Blob> blob = Blob::Create(nullptr, impl);
-
-  return ReplyToPullvCardListing(blob.get(), aPhonebookSize);
-}
-
-bool
-BluetoothPbapManager::ReplyToPullvCardListing(Blob* aBlob,
-                                              uint16_t aPhonebookSize)
-{
-  if (!mConnected) {
-    return false;
-  }
-
-  /**
-   * Open vCard input stream only if |mPhonebookSizeRequired| is false,
-   * according to section 5.3.4.4 "MaxListCount", PBAP 1.2:
-   * "When MaxListCount = 0, ... The response shall not contain a Body header."
-   */
-  if (!mPhonebookSizeRequired && !GetInputStreamFromBlob(aBlob)) {
-    ReplyError(ObexResponseCode::InternalServerError);
-    return false;
-  }
-
-  return ReplyToGet(aPhonebookSize);
-}
-
-bool
-BluetoothPbapManager::ReplyToPullvCardEntry(BlobParent* aActor)
-{
-  RefPtr<BlobImpl> impl = aActor->GetBlobImpl();
-  RefPtr<Blob> blob = Blob::Create(nullptr, impl);
-
-  return ReplyToPullvCardEntry(blob.get());
-}
-
-bool
-BluetoothPbapManager::ReplyToPullvCardEntry(Blob* aBlob)
-{
-  if (!mConnected) {
-    return false;
-  }
-
-  if (!GetInputStreamFromBlob(aBlob)) {
-    ReplyError(ObexResponseCode::InternalServerError);
-    return false;
-  }
-
-  return ReplyToGet();
-}
-
-bool
-BluetoothPbapManager::ReplyToGet(uint16_t aPhonebookSize)
-{
-  MOZ_ASSERT(mRemoteMaxPacketLength >= kObexLeastMaxSize);
-
-  /**
-   * This response consists of following parts:
-   * - Part 1: [response code:1][length:2]
-   *
-   * If |mPhonebookSizeRequired| is true,
-   * - Part 2: [headerId:1][length:2][PhonebookSize:4]
-   * - Part 3: [headerId:1][length:2][EndOfBody:0]
-   * Otherwise,
-   * - Part 2a: [headerId:1][length:2][EndOfBody:0]
-   *   or
-   * - Part 2b: [headerId:1][length:2][Body:var]
-   */
-  auto res = MakeUnique<uint8_t[]>(mRemoteMaxPacketLength);
-  uint8_t opcode;
-
-  // ---- Part 1: [response code:1][length:2] ---- //
-  // [response code:1][length:2] will be set in |SendObexData|.
-  // Reserve index for them here
-  unsigned int index = kObexRespHeaderSize;
-
-  if (mPhonebookSizeRequired) {
-    // ---- Part 2: [headerId:1][length:2][PhonebookSize:4] ---- //
-    uint8_t phonebookSize[2];
-    BigEndian::writeUint16(&phonebookSize[0], aPhonebookSize);
-
-    // Section 6.2.1 "Application Parameters Header", PBAP 1.2
-    // appParameters: [headerId:1][length:2][PhonebookSize:4], where
-    //                [PhonebookSize:4] = [tagId:1][length:1][value:2]
-    uint8_t appParameters[4];
-    AppendAppParameter(appParameters,
-                       sizeof(appParameters),
-                       static_cast<uint8_t>(AppParameterTag::PhonebookSize),
-                       phonebookSize,
-                       sizeof(phonebookSize));
-
-    index += AppendHeaderAppParameters(&res[index],
-                                       mRemoteMaxPacketLength,
-                                       appParameters,
-                                       sizeof(appParameters));
-
-    // ---- Part 3: [headerId:1][length:2][EndOfBody:0] ---- //
-    opcode = ObexResponseCode::Success;
-    index += AppendHeaderEndOfBody(&res[index]);
-
-    mPhonebookSizeRequired = false;
-  } else {
-    MOZ_ASSERT(mVCardDataStream);
-
-    uint64_t bytesAvailable = 0;
-    nsresult rv = mVCardDataStream->Available(&bytesAvailable);
-    if (NS_FAILED(rv)) {
-      BT_LOGR("Failed to get available bytes from input stream. rv=0x%x",
-              static_cast<uint32_t>(rv));
-      return false;
-    }
-
-    /*
-     * In practice, some platforms can only handle zero length End-of-Body
-     * header separately with Body header.
-     * Thus, append End-of-Body only if the data stream had been sent out,
-     * otherwise, send 'Continue' to request for next GET request.
-     */
-    if (!bytesAvailable) {
-      // ----  Part 2a: [headerId:1][length:2][EndOfBody:0] ---- //
-      index += AppendHeaderEndOfBody(&res[index]);
-
-      // Close input stream
-      mVCardDataStream->Close();
-      mVCardDataStream = nullptr;
-
-      opcode = ObexResponseCode::Success;
-    } else {
-      // Compute remaining packet size to append Body, excluding Body's header
-      uint32_t remainingPacketSize =
-        mRemoteMaxPacketLength - kObexBodyHeaderSize - index;
-
-      // Read vCard data from input stream
-      uint32_t numRead = 0;
-      UniquePtr<char[]> buf(new char[remainingPacketSize]);
-      rv = mVCardDataStream->Read(buf.get(), remainingPacketSize, &numRead);
-      if (NS_FAILED(rv)) {
-        BT_LOGR("Failed to read from input stream. rv=0x%x",
-                static_cast<uint32_t>(rv));
-        return false;
-      }
-
-      // |numRead| must be non-zero as |bytesAvailable| is non-zero
-      MOZ_ASSERT(numRead);
-
-      // ----  Part 2b: [headerId:1][length:2][Body:var] ---- //
-      index += AppendHeaderBody(&res[index],
-                                remainingPacketSize,
-                                reinterpret_cast<uint8_t*>(buf.get()),
-                                numRead);
-
-      opcode = ObexResponseCode::Continue;
-    }
-  }
-
-  SendObexData(Move(res), opcode, index);
-
-  return true;
-}
-
-bool
-BluetoothPbapManager::GetInputStreamFromBlob(Blob* aBlob)
-{
-  // PBAP can only handle one OBEX BODY transfer at the same time.
-  if (mVCardDataStream) {
-    BT_LOGR("Shouldn't handle multiple PBAP responses simultaneously");
-    mVCardDataStream->Close();
-    mVCardDataStream = nullptr;
-  }
-
-  ErrorResult rv;
-  aBlob->GetInternalStream(getter_AddRefs(mVCardDataStream), rv);
-  if (rv.Failed()) {
-    BT_LOGR("Failed to get internal stream from blob. rv=0x%x",
-            rv.ErrorCodeAsInt());
-    return false;
-  }
-
-  return true;
-}
-
-void
-BluetoothPbapManager::ReplyError(uint8_t aError)
-{
-  BT_LOGR("[0x%x]", aError);
-
-  // Section 3.2 "Response Format", IrOBEX 1.2
-  // [response code:1][length:2][data:var]
-  uint8_t res[kObexLeastMaxSize];
-  SendObexData(res, aError, kObexBodyHeaderSize);
-}
-
-void
-BluetoothPbapManager::SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize)
-{
-  SetObexPacketInfo(aData, aOpcode, aSize);
-  mSocket->SendSocketData(new UnixSocketRawData(aData, aSize));
-}
-
-void
-BluetoothPbapManager::SendObexData(UniquePtr<uint8_t[]> aData, uint8_t aOpcode,
-                                   int aSize)
-{
-  SetObexPacketInfo(aData.get(), aOpcode, aSize);
-  mSocket->SendSocketData(new UnixSocketRawData(Move(aData), aSize));
-}
-
-void
-BluetoothPbapManager::OnSocketConnectSuccess(BluetoothSocket* aSocket)
-{
-  MOZ_ASSERT(aSocket);
-  MOZ_ASSERT(aSocket == mServerSocket);
-  MOZ_ASSERT(!mSocket);
-
-  BT_LOGR("PBAP socket is connected");
-
-  // Close server socket as only one session is allowed at a time
-  mServerSocket.swap(mSocket);
-
-  // Cache device address since we can't get socket address when a remote
-  // device disconnect with us.
-  mSocket->GetAddress(mDeviceAddress);
-}
-
-void
-BluetoothPbapManager::OnSocketConnectError(BluetoothSocket* aSocket)
-{
-  if (mServerSocket &&
-      mServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-    mServerSocket->Close();
-  }
-  mServerSocket = nullptr;
-
-  if (mSocket &&
-      mSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
-    mSocket->Close();
-  }
-  mSocket = nullptr;
-}
-
-void
-BluetoothPbapManager::OnSocketDisconnect(BluetoothSocket* aSocket)
-{
-  MOZ_ASSERT(aSocket);
-
-  if (aSocket != mSocket) {
-    // Do nothing when a listening server socket is closed.
-    return;
-  }
-
-  AfterPbapDisconnected();
-  mDeviceAddress.Clear();
-
-  mSocket = nullptr; // should already be closed
-
-  Listen();
-}
-
-void
-BluetoothPbapManager::Disconnect(BluetoothProfileController* aController)
-{
-  if (!mSocket) {
-    BT_LOGR("No ongoing connection to disconnect");
-    return;
-  }
-
-  mSocket->Close();
-}
-
-NS_IMPL_ISUPPORTS(BluetoothPbapManager, nsIObserver)
-
-void
-BluetoothPbapManager::Connect(const BluetoothAddress& aDeviceAddress,
-                              BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothPbapManager::OnGetServiceChannel(
-  const BluetoothAddress& aDeviceAddress,
-  const BluetoothUuid& aServiceUuid,
-  int aChannel)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothPbapManager::OnUpdateSdpRecords(
-  const BluetoothAddress& aDeviceAddress)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothPbapManager::OnConnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothPbapManager::OnDisconnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothPbapManager::Reset()
-{
-  MOZ_ASSERT(false);
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothPbapManager.h
+++ /dev/null
@@ -1,229 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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_BluetoothPbapManager_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothPbapManager_h
-
-#include "BluetoothCommon.h"
-#include "BluetoothProfileManagerBase.h"
-#include "BluetoothSocketObserver.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/ipc/SocketBase.h"
-#include "mozilla/UniquePtr.h"
-#include "nsICryptoHash.h"
-#include "ObexBase.h"
-
-class nsICryptoHash;
-class nsIInputStream;
-namespace mozilla {
-  namespace dom {
-    class Blob;
-    class BlobParent;
-  }
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-/*
- * Defined in section 6.2.1 "Application Parameters Header", PBAP ver 1.2
- */
-enum AppParameterTag {
-  Order                   = 0x01,
-  SearchValue             = 0x02,
-  SearchProperty          = 0x03,
-  MaxListCount            = 0x04,
-  ListStartOffset         = 0x05,
-  PropertySelector        = 0x06,
-  Format                  = 0x07,
-  PhonebookSize           = 0x08,
-  NewMissedCalls          = 0x09,
-  // ----- enumerators below are supported since PBAP 1.2 ----- //
-  PrimaryVersionCounter   = 0x0A,
-  SecondaryVersionCounter = 0x0B,
-  vCardSelector           = 0x0C,
-  DatabaseIdentifier      = 0x0D,
-  vCardSelectorOperator   = 0x0E,
-  ResetNewMissedCalls     = 0x0F,
-  PbapSupportedFeatures   = 0x10
-};
-
-class BluetoothSocket;
-class ObexHeaderSet;
-
-class BluetoothPbapManager : public BluetoothSocketObserver
-                           , public BluetoothProfileManagerBase
-{
-public:
-  BT_DECL_PROFILE_MGR_BASE
-  BT_DECL_SOCKET_OBSERVER
-  virtual void GetName(nsACString& aName)
-  {
-    aName.AssignLiteral("PBAP");
-  }
-
-  static const int MAX_PACKET_LENGTH = 0xFFFE;
-  static const int DIGEST_LENGTH = 16;
-
-  static void InitPbapInterface(BluetoothProfileResultHandler* aRes);
-  static void DeinitPbapInterface(BluetoothProfileResultHandler* aRes);
-  static BluetoothPbapManager* Get();
-
-  bool Listen();
-
-  /**
-   * Reply to OBEX authenticate challenge with password.
-   *
-   * @param aPassword [in]  the password known by only client and server.
-   *
-   * @return true if the response packet has been packed correctly and started
-   *         to be sent to the remote device; false otherwise.
-   */
-  void ReplyToAuthChallenge(const nsAString& aPassword);
-
-  /**
-   * Reply vCard objects to IPC 'pullphonebook' request.
-   *
-   * @param aActor         [in]  blob actor of the vCard objects
-   * @param aPhonebookSize [in]  number of vCard indexes in the blob
-   *
-   * @return true if the response packet has been packed correctly and started
-   *         to be sent to the remote device; false otherwise.
-   */
-  bool ReplyToPullPhonebook(BlobParent* aActor, uint16_t aPhonebookSize);
-  /**
-   * Reply vCard objects to in-process 'pullphonebook' request.
-   *
-   * @param aBlob          [in]  blob of the vCard objects
-   * @param aPhonebookSize [in]  number of vCard indexes in the blob
-   *
-   * @return true if the response packet has been packed correctly and started
-   *         to be sent to the remote device; false otherwise.
-   */
-  bool ReplyToPullPhonebook(Blob* aBlob, uint16_t aPhonebookSize);
-
-  /**
-   * Reply vCard objects to IPC 'pullvcardlisting' request.
-   *
-   * @param aActor         [in]  blob actor of the vCard objects
-   * @param aPhonebookSize [in]  number of vCard indexes in the blob
-   *
-   * @return true if the response packet has been packed correctly and started
-   *         to be sent to the remote device; false otherwise.
-   */
-  bool ReplyToPullvCardListing(BlobParent* aActor, uint16_t aPhonebookSize);
-  /**
-   * Reply vCard objects to in-process 'pullvcardlisting' request.
-   *
-   * @param aBlob          [in]  blob of the vCard objects
-   * @param aPhonebookSize [in]  number of vCard indexes in the blob
-   *
-   * @return true if the response packet has been packed correctly and started
-   *         to be sent to the remote device; false otherwise.
-   */
-  bool ReplyToPullvCardListing(Blob* aBlob, uint16_t aPhonebookSize);
-
-  /**
-   * Reply vCard object to IPC 'pullvcardentry' request.
-   *
-   * @param aActor [in]  blob actor of the vCard object
-   *
-   * @return true if the response packet has been packed correctly and started
-   *         to be sent to the remote device; false otherwise.
-   */
-  bool ReplyToPullvCardEntry(BlobParent* aActor);
-  /**
-   * Reply vCard object to in-process 'pullvcardentry' request.
-   *
-   * @param aBlob  [in]  blob of the vCard object
-   *
-   * @return true if the response packet has been packed correctly and started
-   *         to be sent to the remote device; false otherwise.
-   */
-  bool ReplyToPullvCardEntry(Blob* aBlob);
-
-protected:
-  virtual ~BluetoothPbapManager();
-
-private:
-  BluetoothPbapManager();
-
-  nsresult Init();
-  void Uninit();
-  void HandleShutdown();
-
-  void ReplyToConnect(const nsAString& aPassword = EmptyString());
-  void ReplyToDisconnectOrAbort();
-  void ReplyToSetPath();
-  bool ReplyToGet(uint16_t aPhonebookSize = 0);
-  void ReplyError(uint8_t aError);
-  void SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
-  void SendObexData(UniquePtr<uint8_t[]> aData, uint8_t aOpcode, int aSize);
-
-  ObexResponseCode SetPhoneBookPath(const ObexHeaderSet& aHeader,
-                                    uint8_t flags);
-  ObexResponseCode NotifyPbapRequest(const ObexHeaderSet& aHeader);
-  ObexResponseCode NotifyPasswordRequest(const ObexHeaderSet& aHeader);
-  void AppendNamedValueByTagId(const ObexHeaderSet& aHeader,
-                               InfallibleTArray<BluetoothNamedValue>& aValues,
-                               const AppParameterTag aTagId);
-
-  InfallibleTArray<uint32_t> PackPropertiesMask(uint8_t* aData, int aSize);
-  bool CompareHeaderTarget(const ObexHeaderSet& aHeader);
-  bool IsLegalPath(const nsAString& aPath);
-  bool IsLegalPhonebookName(const nsAString& aName);
-  bool GetInputStreamFromBlob(Blob* aBlob);
-  void AfterPbapConnected();
-  void AfterPbapDisconnected();
-  nsresult MD5Hash(char *buf, uint32_t len); // mHashRes stores the result
-
-  /**
-   * The nonce for OBEX authentication procedure.
-   * Its value shall differ each time remote OBEX client sends it
-   */
-  uint8_t mRemoteNonce[DIGEST_LENGTH];
-  uint8_t mHashRes[DIGEST_LENGTH];
-  nsCOMPtr<nsICryptoHash> mVerifier;
-
-  /**
-   * Whether phonebook size is required for OBEX response
-   */
-  bool mPhonebookSizeRequired;
-
-  /**
-   * OBEX session status. Set when OBEX session is established
-   */
-  bool mConnected;
-  BluetoothAddress mDeviceAddress;
-
-  /**
-   * Current phonebook path
-   */
-  nsString mCurrentPath;
-
-  /**
-   * Maximum packet length that remote device can receive
-   */
-  unsigned int mRemoteMaxPacketLength;
-
-  // If a connection has been established, mSocket will be the socket
-  // communicating with the remote socket. We maintain the invariant that if
-  // mSocket is non-null, mServerSocket must be null (and vice versa).
-  RefPtr<BluetoothSocket> mSocket;
-
-  // Server socket. Once an inbound connection is established, it will hand
-  // over the ownership to mSocket, and get a new server socket while Listen()
-  // is called.
-  RefPtr<BluetoothSocket> mServerSocket;
-
-  /**
-   * The vCard data stream for current processing response
-   */
-  nsCOMPtr<nsIInputStream> mVCardDataStream;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothPbapManager_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
+++ /dev/null
@@ -1,2669 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/*
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-#include "BluetoothServiceBluedroid.h"
-
-#include "BluetoothA2dpManager.h"
-#include "BluetoothAvrcpManager.h"
-#include "BluetoothGattManager.h"
-#include "BluetoothHfpManager.h"
-#include "BluetoothHidManager.h"
-#include "BluetoothMapSmsManager.h"
-#include "BluetoothOppManager.h"
-#include "BluetoothPbapManager.h"
-#include "BluetoothProfileController.h"
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothUtils.h"
-#include "BluetoothUuidHelper.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/ipc/SocketBase.h"
-#include "mozilla/StaticMutex.h"
-#include "mozilla/StaticPtr.h"
-#include "mozilla/Unused.h"
-
-#define ENSURE_BLUETOOTH_IS_ENABLED(runnable, result)                  \
-  do {                                                                 \
-    if (!IsEnabled()) {                                                \
-      DispatchReplyError(runnable,                                     \
-        NS_LITERAL_STRING("Bluetooth is not enabled"));                \
-      return result;                                                   \
-    }                                                                  \
-  } while(0)
-
-#define ENSURE_BLUETOOTH_IS_ENABLED_VOID(runnable)                     \
-  do {                                                                 \
-    if (!IsEnabled()) {                                                \
-      DispatchReplyError(runnable,                                     \
-        NS_LITERAL_STRING("Bluetooth is not enabled"));                \
-      return;                                                          \
-    }                                                                  \
-  } while(0)
-
-#define ENSURE_GATT_MGR_IS_READY_VOID(gatt, runnable)                  \
-  do {                                                                 \
-    if (!gatt) {                                                       \
-      DispatchReplyError(runnable,                                     \
-        NS_LITERAL_STRING("GattManager is not ready"));                \
-      return;                                                          \
-    }                                                                  \
-  } while(0)
-
-using namespace mozilla;
-using namespace mozilla::ipc;
-USING_BLUETOOTH_NAMESPACE
-
-static BluetoothInterface* sBtInterface;
-static BluetoothCoreInterface* sBtCoreInterface;
-static nsTArray<RefPtr<BluetoothProfileController> > sControllerArray;
-
-class BluetoothServiceBluedroid::EnableResultHandler final
-  : public BluetoothCoreResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_LOGR("BluetoothInterface::Enable failed: %d", aStatus);
-
-    BluetoothService::AcknowledgeToggleBt(false);
-  }
-};
-
-/* |ProfileInitResultHandler| collects the results of all profile
- * result handlers and calls |Proceed| after all results handlers
- * have been run.
- */
-class BluetoothServiceBluedroid::ProfileInitResultHandler final
-  : public BluetoothProfileResultHandler
-{
-public:
-  ProfileInitResultHandler(unsigned char aNumProfiles)
-    : mNumProfiles(aNumProfiles)
-  {
-    MOZ_ASSERT(mNumProfiles);
-  }
-
-  void Init() override
-  {
-    if (!(--mNumProfiles)) {
-      Proceed();
-    }
-  }
-
-  void OnError(nsresult aResult) override
-  {
-    if (!(--mNumProfiles)) {
-      Proceed();
-    }
-  }
-
-private:
-  void Proceed() const
-  {
-    BluetoothService* bs = BluetoothService::Get();
-    NS_ENSURE_TRUE_VOID(bs);
-
-    sBtCoreInterface = sBtInterface->GetBluetoothCoreInterface();
-    NS_ENSURE_TRUE_VOID(sBtCoreInterface);
-
-    sBtCoreInterface->SetNotificationHandler(
-      reinterpret_cast<BluetoothServiceBluedroid*>(bs));
-
-    sBtCoreInterface->Enable(new EnableResultHandler());
-  }
-
-  unsigned char mNumProfiles;
-};
-
-class BluetoothServiceBluedroid::InitResultHandler final
-  : public BluetoothResultHandler
-{
-public:
-  void Init() override
-  {
-    static void (* const sInitManager[])(BluetoothProfileResultHandler*) = {
-      BluetoothMapSmsManager::InitMapSmsInterface,
-      BluetoothOppManager::InitOppInterface,
-      BluetoothPbapManager::InitPbapInterface,
-      BluetoothHidManager::InitHidInterface,
-      BluetoothHfpManager::InitHfpInterface,
-      BluetoothA2dpManager::InitA2dpInterface,
-      BluetoothAvrcpManager::InitAvrcpInterface,
-      BluetoothGattManager::InitGattInterface
-    };
-
-    MOZ_ASSERT(NS_IsMainThread());
-
-    // Register all the bluedroid callbacks before enable() gets called. This is
-    // required to register a2dp callbacks before a2dp media task starts up.
-    // If any interface cannot be initialized, turn on bluetooth core anyway.
-    RefPtr<ProfileInitResultHandler> res =
-      new ProfileInitResultHandler(MOZ_ARRAY_LENGTH(sInitManager));
-
-    for (size_t i = 0; i < MOZ_ARRAY_LENGTH(sInitManager); ++i) {
-      sInitManager[i](res);
-    }
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_LOGR("BluetoothInterface::Init failed: %d", aStatus);
-
-    sBtInterface = nullptr;
-
-    BluetoothService::AcknowledgeToggleBt(false);
-  }
-};
-
-nsresult
-BluetoothServiceBluedroid::StartGonkBluetooth()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE(sBtInterface, NS_ERROR_FAILURE);
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-
-  if (bs->IsEnabled()) {
-    // Keep current enable status
-    BluetoothService::AcknowledgeToggleBt(true);
-    return NS_OK;
-  }
-
-  sBtInterface->Init(reinterpret_cast<BluetoothServiceBluedroid*>(bs),
-                     new InitResultHandler());
-
-  return NS_OK;
-}
-
-class BluetoothServiceBluedroid::DisableResultHandler final
-  : public BluetoothCoreResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_LOGR("BluetoothInterface::Disable failed: %d", aStatus);
-
-    // Always make progress; even on failures
-    BluetoothService::AcknowledgeToggleBt(false);
-  }
-};
-
-nsresult
-BluetoothServiceBluedroid::StopGonkBluetooth()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE(sBtInterface, NS_ERROR_FAILURE);
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-
-  if (!bs->IsEnabled()) {
-    // Keep current enable status
-    BluetoothService::AcknowledgeToggleBt(false);
-    return NS_OK;
-  }
-
-  sBtCoreInterface->Disable(new DisableResultHandler());
-
-  return NS_OK;
-}
-
-/*
- *  Member functions
- */
-
-BluetoothServiceBluedroid::BluetoothServiceBluedroid()
-  : mEnabled(false)
-  , mDiscoverable(false)
-  , mDiscovering(false)
-  , mIsRestart(false)
-  , mIsFirstTimeToggleOffBt(false)
-{
-  sBtInterface = BluetoothInterface::GetInstance();
-  if (!sBtInterface) {
-    BT_LOGR("Error! Failed to get instance of bluetooth interface");
-    return;
-  }
-}
-
-BluetoothServiceBluedroid::~BluetoothServiceBluedroid()
-{
-}
-
-nsresult
-BluetoothServiceBluedroid::StartInternal(BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // aRunnable will be a nullptr while startup
-  if (aRunnable) {
-    mChangeAdapterStateRunnables.AppendElement(aRunnable);
-  }
-
-  nsresult ret = StartGonkBluetooth();
-  if (NS_FAILED(ret)) {
-    BluetoothService::AcknowledgeToggleBt(false);
-
-    // Reject Promise
-    if (aRunnable) {
-      DispatchReplyError(aRunnable, NS_LITERAL_STRING("StartBluetoothError"));
-      mChangeAdapterStateRunnables.RemoveElement(aRunnable);
-    }
-
-    BT_LOGR("Error");
-  }
-
-  return ret;
-}
-
-nsresult
-BluetoothServiceBluedroid::StopInternal(BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothProfileManagerBase* sProfiles[] = {
-    // BluetoothGattManager not handled here
-    BluetoothAvrcpManager::Get(),
-    BluetoothA2dpManager::Get(),
-    BluetoothHfpManager::Get(),
-    BluetoothHidManager::Get(),
-    BluetoothPbapManager::Get(),
-    BluetoothOppManager::Get(),
-    BluetoothMapSmsManager::Get()
-  };
-
-  // Disconnect all connected profiles
-  for (uint8_t i = 0; i < MOZ_ARRAY_LENGTH(sProfiles); i++) {
-    nsCString profileName;
-    sProfiles[i]->GetName(profileName);
-
-    if (NS_WARN_IF(!sProfiles[i])) {
-      BT_LOGR("Profile manager [%s] is null", profileName.get());
-      return NS_ERROR_FAILURE;
-    }
-
-    if (sProfiles[i]->IsConnected()) {
-      sProfiles[i]->Disconnect(nullptr);
-    } else if (!profileName.EqualsLiteral("OPP") &&
-               !profileName.EqualsLiteral("PBAP") &&
-               !profileName.EqualsLiteral("MapSms")) {
-      sProfiles[i]->Reset();
-    }
-  }
-
-  // aRunnable will be a nullptr during starup and shutdown
-  if (aRunnable) {
-    mChangeAdapterStateRunnables.AppendElement(aRunnable);
-  }
-
-  nsresult ret = StopGonkBluetooth();
-  if (NS_FAILED(ret)) {
-    BluetoothService::AcknowledgeToggleBt(true);
-
-    // Reject Promise
-    if (aRunnable) {
-      DispatchReplyError(aRunnable, NS_LITERAL_STRING("StopBluetoothError"));
-      mChangeAdapterStateRunnables.RemoveElement(aRunnable);
-    }
-
-    BT_LOGR("Error");
-  }
-
-  return ret;
-}
-
-//
-// GATT Client
-//
-
-void
-BluetoothServiceBluedroid::StartLeScanInternal(
-  const nsTArray<BluetoothUuid>& aServiceUuids,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->StartLeScan(aServiceUuids, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::StopLeScanInternal(
-  const BluetoothUuid& aScanUuid,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->StopLeScan(aScanUuid, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::StartAdvertisingInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattAdvertisingData& aAdvData,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->StartAdvertising(aAppUuid, aAdvData, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::StopAdvertisingInternal(
-  const BluetoothUuid& aAppUuid,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->StopAdvertising(aAppUuid, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::ConnectGattClientInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothAddress& aDeviceAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->Connect(aAppUuid, aDeviceAddress, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::DisconnectGattClientInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothAddress& aDeviceAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->Disconnect(aAppUuid, aDeviceAddress, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::DiscoverGattServicesInternal(
-  const BluetoothUuid& aAppUuid, BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->Discover(aAppUuid, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattClientStartNotificationsInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothGattServiceId& aServId,
-  const BluetoothGattId& aCharId, BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->RegisterNotifications(aAppUuid, aServId, aCharId, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattClientStopNotificationsInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothGattServiceId& aServId,
-  const BluetoothGattId& aCharId, BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->DeregisterNotifications(aAppUuid, aServId, aCharId, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::UnregisterGattClientInternal(
-  int aClientIf, BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->UnregisterClient(aClientIf, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattClientReadRemoteRssiInternal(
-  int aClientIf, const BluetoothAddress& aDeviceAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->ReadRemoteRssi(aClientIf, aDeviceAddress, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattClientReadCharacteristicValueInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->ReadCharacteristicValue(aAppUuid, aServiceId, aCharacteristicId,
-                                aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattClientWriteCharacteristicValueInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  const BluetoothGattWriteType& aWriteType,
-  const nsTArray<uint8_t>& aValue,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->WriteCharacteristicValue(aAppUuid, aServiceId, aCharacteristicId,
-                                 aWriteType, aValue, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattClientReadDescriptorValueInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  const BluetoothGattId& aDescriptorId,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->ReadDescriptorValue(aAppUuid, aServiceId, aCharacteristicId,
-                            aDescriptorId, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattClientWriteDescriptorValueInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  const BluetoothGattId& aDescriptorId,
-  const nsTArray<uint8_t>& aValue,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->WriteDescriptorValue(aAppUuid, aServiceId, aCharacteristicId,
-                             aDescriptorId, aValue, aRunnable);
-}
-
-// GATT Server
-void
-BluetoothServiceBluedroid::GattServerRegisterInternal(
-  const BluetoothUuid& aAppUuid, BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->RegisterServer(aAppUuid, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattServerConnectPeripheralInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothAddress& aAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->ConnectPeripheral(aAppUuid, aAddress, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattServerDisconnectPeripheralInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothAddress& aAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->DisconnectPeripheral(aAppUuid, aAddress, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::UnregisterGattServerInternal(
-  int aServerIf, BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->UnregisterServer(aServerIf, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattServerAddServiceInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  uint16_t aHandleCount,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->ServerAddService(aAppUuid, aServiceId, aHandleCount, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattServerAddIncludedServiceInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aIncludedServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->ServerAddIncludedService(aAppUuid,
-                                 aServiceHandle,
-                                 aIncludedServiceHandle,
-                                 aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattServerAddCharacteristicInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothUuid& aCharacteristicUuid,
-  BluetoothGattAttrPerm aPermissions,
-  BluetoothGattCharProp aProperties,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->ServerAddCharacteristic(aAppUuid,
-                                aServiceHandle,
-                                aCharacteristicUuid,
-                                aPermissions,
-                                aProperties,
-                                aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattServerAddDescriptorInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aCharacteristicHandle,
-  const BluetoothUuid& aDescriptorUuid,
-  BluetoothGattAttrPerm aPermissions,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->ServerAddDescriptor(aAppUuid,
-                            aServiceHandle,
-                            aCharacteristicHandle,
-                            aDescriptorUuid,
-                            aPermissions,
-                            aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattServerRemoveServiceInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->ServerRemoveService(aAppUuid, aServiceHandle, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattServerStartServiceInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->ServerStartService(aAppUuid, aServiceHandle, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattServerStopServiceInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->ServerStopService(aAppUuid, aServiceHandle, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattServerSendResponseInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAddress& aAddress,
-  uint16_t aStatus,
-  int32_t aRequestId,
-  const BluetoothGattResponse& aRsp,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->ServerSendResponse(
-    aAppUuid, aAddress, aStatus, aRequestId, aRsp, aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::GattServerSendIndicationInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAddress& aAddress,
-  const BluetoothAttributeHandle& aCharacteristicHandle,
-  bool aConfirm,
-  const nsTArray<uint8_t>& aValue,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothGattManager* gatt = BluetoothGattManager::Get();
-  ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
-
-  gatt->ServerSendIndication(aAppUuid,
-                             aAddress,
-                             aCharacteristicHandle,
-                             aConfirm,
-                             aValue,
-                             aRunnable);
-}
-
-nsresult
-BluetoothServiceBluedroid::GetAdaptersInternal(
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * Wrap BluetoothValue =
-   *   BluetoothNamedValue[]
-   *     |
-   *     |__ BluetoothNamedValue =
-   *     |     {"Adapter", BluetoothValue = BluetoothNamedValue[]}
-   *     |
-   *     |__ BluetoothNamedValue =
-   *     |     {"Adapter", BluetoothValue = BluetoothNamedValue[]}
-   *     ...
-   */
-  InfallibleTArray<BluetoothNamedValue> adaptersProperties;
-  uint32_t numAdapters = 1; // Bluedroid supports single adapter only
-
-  for (uint32_t i = 0; i < numAdapters; i++) {
-    InfallibleTArray<BluetoothNamedValue> properties;
-
-    AppendNamedValue(properties, "State", mEnabled);
-    AppendNamedValue(properties, "Address", mBdAddress);
-    AppendNamedValue(properties, "Name", mBdName);
-    AppendNamedValue(properties, "Discoverable", mDiscoverable);
-    AppendNamedValue(properties, "Discovering", mDiscovering);
-    AppendNamedValue(properties, "PairedDevices", mBondedAddresses);
-
-    AppendNamedValue(adaptersProperties, "Adapter",
-                     BluetoothValue(properties));
-  }
-
-  DispatchReplySuccess(aRunnable, adaptersProperties);
-  return NS_OK;
-}
-
-class BluetoothServiceBluedroid::GetDeviceRequest final
-{
-public:
-  GetDeviceRequest(int aDeviceCount, BluetoothReplyRunnable* aRunnable)
-    : mDeviceCount(aDeviceCount)
-    , mRunnable(aRunnable)
-  { }
-
-  int mDeviceCount;
-  InfallibleTArray<BluetoothNamedValue> mDevicesPack;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-};
-
-class BluetoothServiceBluedroid::GetRemoteDevicePropertiesResultHandler final
-  : public BluetoothCoreResultHandler
-{
-public:
-  GetRemoteDevicePropertiesResultHandler(
-    nsTArray<GetDeviceRequest>& aRequests,
-    const BluetoothAddress& aDeviceAddress)
-    : mRequests(aRequests)
-    , mDeviceAddress(aDeviceAddress)
-  { }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-    MOZ_ASSERT(!mRequests.IsEmpty());
-
-    nsAutoString addressString;
-    AddressToString(mDeviceAddress, addressString);
-
-    BT_WARNING("GetRemoteDeviceProperties(%s) failed: %d",
-               NS_ConvertUTF16toUTF8(addressString).get(), aStatus);
-
-    /* Dispatch result after the final pending operation */
-    if (--mRequests[0].mDeviceCount == 0) {
-      if (mRequests[0].mRunnable) {
-        DispatchReplySuccess(mRequests[0].mRunnable,
-                             mRequests[0].mDevicesPack);
-      }
-      mRequests.RemoveElementAt(0);
-    }
-  }
-
-private:
-  nsTArray<GetDeviceRequest>& mRequests;
-  BluetoothAddress mDeviceAddress;
-};
-
-nsresult
-BluetoothServiceBluedroid::GetConnectedDevicePropertiesInternal(
-  uint16_t aServiceUuid, BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED(aRunnable, NS_OK);
-
-  BluetoothProfileManagerBase* profile =
-    BluetoothUuidHelper::GetBluetoothProfileManager(aServiceUuid);
-  if (!profile) {
-    DispatchReplyError(aRunnable, NS_LITERAL_STRING(ERR_UNKNOWN_PROFILE));
-    return NS_OK;
-  }
-
-  // Reply success if no device of this profile is connected
-  if (!profile->IsConnected()) {
-    DispatchReplySuccess(aRunnable, InfallibleTArray<BluetoothNamedValue>());
-    return NS_OK;
-  }
-
-  // Get address of the connected device
-  BluetoothAddress address;
-  profile->GetAddress(address);
-
-  // Append request of the connected device
-  GetDeviceRequest request(1, aRunnable);
-  mGetDeviceRequests.AppendElement(request);
-
-  sBtCoreInterface->GetRemoteDeviceProperties(address,
-    new GetRemoteDevicePropertiesResultHandler(mGetDeviceRequests, address));
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothServiceBluedroid::GetPairedDevicePropertiesInternal(
-  const nsTArray<BluetoothAddress>& aDeviceAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED(aRunnable, NS_OK);
-
-  if (aDeviceAddress.IsEmpty()) {
-    DispatchReplySuccess(aRunnable);
-    return NS_OK;
-  }
-
-  // Append request of all paired devices
-  GetDeviceRequest request(aDeviceAddress.Length(), aRunnable);
-  mGetDeviceRequests.AppendElement(request);
-
-  for (uint8_t i = 0; i < aDeviceAddress.Length(); i++) {
-    // Retrieve all properties of devices
-    sBtCoreInterface->GetRemoteDeviceProperties(aDeviceAddress[i],
-      new GetRemoteDevicePropertiesResultHandler(mGetDeviceRequests,
-                                                 aDeviceAddress[i]));
-  }
-
-  return NS_OK;
-}
-
-class BluetoothServiceBluedroid::DispatchReplyErrorResultHandler final
-  : public BluetoothCoreResultHandler
-{
-public:
-  DispatchReplyErrorResultHandler(
-    nsTArray<RefPtr<BluetoothReplyRunnable>>& aRunnableArray,
-    BluetoothReplyRunnable* aRunnable)
-    : mRunnableArray(aRunnableArray)
-    , mRunnable(aRunnable)
-  { }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    mRunnableArray.RemoveElement(mRunnable);
-    if (mRunnable) {
-      DispatchReplyError(mRunnable, aStatus);
-    }
-  }
-
-private:
-  nsTArray<RefPtr<BluetoothReplyRunnable>>& mRunnableArray;
-  BluetoothReplyRunnable* mRunnable;
-};
-
-void
-BluetoothServiceBluedroid::StartDiscoveryInternal(
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  mChangeDiscoveryRunnables.AppendElement(aRunnable);
-  sBtCoreInterface->StartDiscovery(
-    new DispatchReplyErrorResultHandler(mChangeDiscoveryRunnables, aRunnable));
-}
-
-nsresult
-BluetoothServiceBluedroid::FetchUuidsInternal(
-  const BluetoothAddress& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED(aRunnable, NS_OK);
-
-  /*
-   * get_remote_services request will not be performed by bluedroid
-   * if it is currently discovering nearby remote devices.
-   */
-  if (mDiscovering) {
-    StopDiscoveryInternal(aRunnable);
-  }
-
-  mFetchUuidsRunnables.AppendElement(aRunnable);
-  sBtCoreInterface->GetRemoteServices(aDeviceAddress,
-    new DispatchReplyErrorResultHandler(mFetchUuidsRunnables, aRunnable));
-
-  return NS_OK;
-}
-
-void
-BluetoothServiceBluedroid::StopDiscoveryInternal(
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  mChangeDiscoveryRunnables.AppendElement(aRunnable);
-  sBtCoreInterface->CancelDiscovery(
-    new DispatchReplyErrorResultHandler(mChangeDiscoveryRunnables, aRunnable));
-}
-
-nsresult
-BluetoothServiceBluedroid::SetProperty(BluetoothObjectType aType,
-                                       const BluetoothNamedValue& aValue,
-                                       BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED(aRunnable, NS_OK);
-
-  BluetoothProperty property;
-  nsresult rv = NamedValueToProperty(aValue, property);
-  if (NS_FAILED(rv)) {
-    DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
-    return rv;
-  }
-
-  mSetAdapterPropertyRunnables.AppendElement(aRunnable);
-  sBtCoreInterface->SetAdapterProperty(
-    property,
-    new DispatchReplyErrorResultHandler(mSetAdapterPropertyRunnables,
-                                        aRunnable));
-
-  return NS_OK;
-}
-
-struct BluetoothServiceBluedroid::GetRemoteServiceRecordRequest final
-{
-  GetRemoteServiceRecordRequest(const BluetoothAddress& aDeviceAddress,
-                                const BluetoothUuid& aUuid,
-                                BluetoothProfileManagerBase* aManager)
-    : mDeviceAddress(aDeviceAddress)
-    , mUuid(aUuid)
-    , mManager(aManager)
-  {
-    MOZ_ASSERT(mManager);
-  }
-
-  BluetoothAddress mDeviceAddress;
-  BluetoothUuid mUuid;
-  BluetoothProfileManagerBase* mManager;
-};
-
-class BluetoothServiceBluedroid::GetRemoteServiceRecordResultHandler final
-  : public BluetoothCoreResultHandler
-{
-public:
-  GetRemoteServiceRecordResultHandler(
-    nsTArray<GetRemoteServiceRecordRequest>& aGetRemoteServiceRecordArray,
-    const BluetoothAddress& aDeviceAddress,
-    const BluetoothUuid& aUuid)
-    : mGetRemoteServiceRecordArray(aGetRemoteServiceRecordArray)
-    , mDeviceAddress(aDeviceAddress)
-    , mUuid(aUuid)
-  { }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    // Find call in array
-
-    ssize_t i = FindRequest();
-
-    if (i == -1) {
-      BT_WARNING("No GetRemoteService request found");
-      return;
-    }
-
-    // Signal error to profile manager
-
-    mGetRemoteServiceRecordArray[i].mManager->OnGetServiceChannel(
-      mDeviceAddress, mUuid, -1);
-    mGetRemoteServiceRecordArray.RemoveElementAt(i);
-  }
-
-  void CancelDiscovery() override
-  {
-    // Disabled discovery mode, now perform SDP operation.
-    sBtCoreInterface->GetRemoteServiceRecord(mDeviceAddress, mUuid, this);
-  }
-
-private:
-  ssize_t FindRequest() const
-  {
-    for (size_t i = 0; i < mGetRemoteServiceRecordArray.Length(); ++i) {
-      if ((mGetRemoteServiceRecordArray[i].mDeviceAddress == mDeviceAddress) &&
-          (mGetRemoteServiceRecordArray[i].mUuid == mUuid)) {
-        return i;
-      }
-    }
-
-    return -1;
-  }
-
-  nsTArray<GetRemoteServiceRecordRequest>& mGetRemoteServiceRecordArray;
-  BluetoothAddress mDeviceAddress;
-  BluetoothUuid mUuid;
-};
-
-nsresult
-BluetoothServiceBluedroid::GetServiceChannel(
-  const BluetoothAddress& aDeviceAddress,
-  const BluetoothUuid& aServiceUuid,
-  BluetoothProfileManagerBase* aManager)
-{
-  mGetRemoteServiceRecordArray.AppendElement(
-    GetRemoteServiceRecordRequest(aDeviceAddress, aServiceUuid, aManager));
-
-  RefPtr<BluetoothCoreResultHandler> res =
-    new GetRemoteServiceRecordResultHandler(mGetRemoteServiceRecordArray,
-                                            aDeviceAddress, aServiceUuid);
-
-  /* Stop discovery of remote devices here, because SDP operations
-   * won't be performed while the adapter is in discovery mode.
-   */
-  if (mDiscovering) {
-    sBtCoreInterface->CancelDiscovery(res);
-  } else {
-    sBtCoreInterface->GetRemoteServiceRecord(aDeviceAddress, aServiceUuid, res);
-  }
-
-  return NS_OK;
-}
-
-struct BluetoothServiceBluedroid::GetRemoteServicesRequest final
-{
-  GetRemoteServicesRequest(const BluetoothAddress& aDeviceAddress,
-                           BluetoothProfileManagerBase* aManager)
-    : mDeviceAddress(aDeviceAddress)
-    , mManager(aManager)
-  {
-    MOZ_ASSERT(mManager);
-  }
-
-  BluetoothAddress mDeviceAddress;
-  BluetoothProfileManagerBase* mManager;
-};
-
-class BluetoothServiceBluedroid::GetRemoteServicesResultHandler final
-  : public BluetoothCoreResultHandler
-{
-public:
-  GetRemoteServicesResultHandler(
-    nsTArray<GetRemoteServicesRequest>& aGetRemoteServicesArray,
-    const BluetoothAddress& aDeviceAddress,
-    BluetoothProfileManagerBase* aManager)
-    : mGetRemoteServicesArray(aGetRemoteServicesArray)
-    , mDeviceAddress(aDeviceAddress)
-    , mManager(aManager)
-  { }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    // Find call in array
-
-    ssize_t i = FindRequest();
-
-    if (i == -1) {
-      BT_WARNING("No GetRemoteServices request found");
-      return;
-    }
-
-    // Cleanup array
-    mGetRemoteServicesArray.RemoveElementAt(i);
-
-    // There's no error-signaling mechanism; just call manager
-    mManager->OnUpdateSdpRecords(mDeviceAddress);
-  }
-
-  void CancelDiscovery() override
-  {
-    // Disabled discovery mode, now perform SDP operation.
-    sBtCoreInterface->GetRemoteServices(mDeviceAddress, this);
-  }
-
-private:
-  ssize_t FindRequest() const
-  {
-    for (size_t i = 0; i < mGetRemoteServicesArray.Length(); ++i) {
-      if ((mGetRemoteServicesArray[i].mDeviceAddress == mDeviceAddress) &&
-          (mGetRemoteServicesArray[i].mManager == mManager)) {
-        return i;
-      }
-    }
-
-    return -1;
-  }
-
-  nsTArray<GetRemoteServicesRequest>& mGetRemoteServicesArray;
-  BluetoothAddress mDeviceAddress;
-  BluetoothProfileManagerBase* mManager;
-};
-
-bool
-BluetoothServiceBluedroid::UpdateSdpRecords(
-  const BluetoothAddress& aDeviceAddress,
-  BluetoothProfileManagerBase* aManager)
-{
-  mGetRemoteServicesArray.AppendElement(
-    GetRemoteServicesRequest(aDeviceAddress, aManager));
-
-  RefPtr<BluetoothCoreResultHandler> res =
-    new GetRemoteServicesResultHandler(mGetRemoteServicesArray,
-                                       aDeviceAddress, aManager);
-
-  /* Stop discovery of remote devices here, because SDP operations
-   * won't be performed while the adapter is in discovery mode.
-   */
-  if (mDiscovering) {
-    sBtCoreInterface->CancelDiscovery(res);
-  } else {
-    sBtCoreInterface->GetRemoteServices(aDeviceAddress, res);
-  }
-
-  return true;
-}
-
-nsresult
-BluetoothServiceBluedroid::CreatePairedDeviceInternal(
-  const BluetoothAddress& aDeviceAddress, int aTimeout,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED(aRunnable, NS_OK);
-
-  mCreateBondRunnables.AppendElement(aRunnable);
-  sBtCoreInterface->CreateBond(aDeviceAddress, TRANSPORT_AUTO,
-    new DispatchReplyErrorResultHandler(mCreateBondRunnables, aRunnable));
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothServiceBluedroid::RemoveDeviceInternal(
-  const BluetoothAddress& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED(aRunnable, NS_OK);
-
-  mRemoveBondRunnables.AppendElement(aRunnable);
-  sBtCoreInterface->RemoveBond(aDeviceAddress,
-    new DispatchReplyErrorResultHandler(mRemoveBondRunnables, aRunnable));
-
-  return NS_OK;
-}
-
-class BluetoothServiceBluedroid::PinReplyResultHandler final
-  : public BluetoothCoreResultHandler
-{
-public:
-  PinReplyResultHandler(BluetoothReplyRunnable* aRunnable)
-    : mRunnable(aRunnable)
-  { }
-
-  void PinReply() override
-  {
-    DispatchReplySuccess(mRunnable);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    DispatchReplyError(mRunnable, aStatus);
-  }
-
-private:
-  BluetoothReplyRunnable* mRunnable;
-};
-
-class BluetoothServiceBluedroid::CancelBondResultHandler final
-  : public BluetoothCoreResultHandler
-{
-public:
-  CancelBondResultHandler(BluetoothReplyRunnable* aRunnable)
-    : mRunnable(aRunnable)
-  { }
-
-  void CancelBond() override
-  {
-    DispatchReplySuccess(mRunnable);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    DispatchReplyError(mRunnable, aStatus);
-  }
-
-private:
-  BluetoothReplyRunnable* mRunnable;
-};
-
-void
-BluetoothServiceBluedroid::PinReplyInternal(
-  const BluetoothAddress& aDeviceAddress, bool aAccept,
-  const BluetoothPinCode& aPinCode, BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  if (aAccept && aPinCode.mLength) {
-    sBtCoreInterface->PinReply(aDeviceAddress, aAccept, aPinCode,
-                               new PinReplyResultHandler(aRunnable));
-  } else {
-    // Call CancelBond to trigger BondStateChangedNotification
-    sBtCoreInterface->CancelBond(aDeviceAddress,
-                                 new CancelBondResultHandler(aRunnable));
-  }
-}
-
-void
-BluetoothServiceBluedroid::SetPinCodeInternal(
-  const BluetoothAddress& aDeviceAddress, const BluetoothPinCode& aPinCode,
-  BluetoothReplyRunnable* aRunnable)
-{
-  // Legacy method used by BlueZ only.
-}
-
-void
-BluetoothServiceBluedroid::SetPasskeyInternal(
-  const BluetoothAddress& aDeviceAddress, uint32_t aPasskey,
-  BluetoothReplyRunnable* aRunnable)
-{
-  // Legacy method used by BlueZ only.
-}
-
-class BluetoothServiceBluedroid::SspReplyResultHandler final
-  : public BluetoothCoreResultHandler
-{
-public:
-  SspReplyResultHandler(BluetoothReplyRunnable* aRunnable)
-    : mRunnable(aRunnable)
-  { }
-
-  void SspReply() override
-  {
-    DispatchReplySuccess(mRunnable);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    DispatchReplyError(mRunnable, aStatus);
-  }
-
-private:
-  BluetoothReplyRunnable* mRunnable;
-};
-
-void
-BluetoothServiceBluedroid::SspReplyInternal(
-  const BluetoothAddress& aDeviceAddress, BluetoothSspVariant aVariant,
-  bool aAccept, BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  sBtCoreInterface->SspReply(aDeviceAddress, aVariant, aAccept,
-                             0 /* passkey */,
-                             new SspReplyResultHandler(aRunnable));
-}
-
-void
-BluetoothServiceBluedroid::SetPairingConfirmationInternal(
-  const BluetoothAddress& aDeviceAddress, bool aConfirm,
-  BluetoothReplyRunnable* aRunnable)
-{
-  // Legacy method used by BlueZ only.
-}
-
-void
-BluetoothServiceBluedroid::NextBluetoothProfileController()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Remove the completed task at the head
-  NS_ENSURE_FALSE_VOID(sControllerArray.IsEmpty());
-  sControllerArray.RemoveElementAt(0);
-
-  // Start the next task if task array is not empty
-  if (!sControllerArray.IsEmpty()) {
-    sControllerArray[0]->StartSession();
-  }
-}
-
-void
-BluetoothServiceBluedroid::ConnectDisconnect(
-  bool aConnect, const BluetoothAddress& aDeviceAddress,
-  BluetoothReplyRunnable* aRunnable,
-  uint16_t aServiceUuid, uint32_t aCod)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  BluetoothProfileController* controller =
-    new BluetoothProfileController(aConnect, aDeviceAddress, aRunnable,
-                                   NextBluetoothProfileController,
-                                   aServiceUuid, aCod);
-  sControllerArray.AppendElement(controller);
-
-  /**
-   * If the request is the first element of the queue, start from here. Note
-   * that other requests are pushed into the queue and popped out after the
-   * first one is completed. See NextBluetoothProfileController() for details.
-   */
-  if (sControllerArray.Length() == 1) {
-    sControllerArray[0]->StartSession();
-  }
-}
-
-void
-BluetoothServiceBluedroid::Connect(const BluetoothAddress& aDeviceAddress,
-                                   uint32_t aCod,
-                                   uint16_t aServiceUuid,
-                                   BluetoothReplyRunnable* aRunnable)
-{
-  ConnectDisconnect(true, aDeviceAddress, aRunnable, aServiceUuid, aCod);
-}
-
-void
-BluetoothServiceBluedroid::Disconnect(
-  const BluetoothAddress& aDeviceAddress, uint16_t aServiceUuid,
-  BluetoothReplyRunnable* aRunnable)
-{
-  ConnectDisconnect(false, aDeviceAddress, aRunnable, aServiceUuid);
-}
-
-void
-BluetoothServiceBluedroid::SendFile(const BluetoothAddress& aDeviceAddress,
-                                    BlobParent* aBlobParent,
-                                    BlobChild* aBlobChild,
-                                    BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Currently we only support one device sending one file at a time,
-  // so we don't need aDeviceAddress here because the target device
-  // has been determined when calling 'Connect()'. Nevertheless, keep
-  // it for future use.
-
-  BluetoothOppManager* opp = BluetoothOppManager::Get();
-  if (!opp || !opp->SendFile(aDeviceAddress, aBlobParent)) {
-    DispatchReplyError(aRunnable, NS_LITERAL_STRING("SendFile failed"));
-    return;
-  }
-
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::SendFile(const BluetoothAddress& aDeviceAddress,
-                                    Blob* aBlob,
-                                    BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Currently we only support one device sending one file at a time,
-  // so we don't need aDeviceAddress here because the target device
-  // has been determined when calling 'Connect()'. Nevertheless, keep
-  // it for future use.
-
-  BluetoothOppManager* opp = BluetoothOppManager::Get();
-  if (!opp || !opp->SendFile(aDeviceAddress, aBlob)) {
-    DispatchReplyError(aRunnable, NS_LITERAL_STRING("SendFile failed"));
-    return;
-  }
-
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::StopSendingFile(
-  const BluetoothAddress& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Currently we only support one device sending one file at a time,
-  // so we don't need aDeviceAddress here because the target device
-  // has been determined when calling 'Connect()'. Nevertheless, keep
-  // it for future use.
-
-  BluetoothOppManager* opp = BluetoothOppManager::Get();
-  nsAutoString errorStr;
-  if (!opp || !opp->StopSendingFile()) {
-    DispatchReplyError(aRunnable, NS_LITERAL_STRING("StopSendingFile failed"));
-    return;
-  }
-
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::ConfirmReceivingFile(
-  const BluetoothAddress& aDeviceAddress, bool aConfirm,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Currently we only support one device sending one file at a time,
-  // so we don't need aDeviceAddress here because the target device
-  // has been determined when calling 'Connect()'. Nevertheless, keep
-  // it for future use.
-
-  BluetoothOppManager* opp = BluetoothOppManager::Get();
-  nsAutoString errorStr;
-  if (!opp || !opp->ConfirmReceivingFile(aConfirm)) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("ConfirmReceivingFile failed"));
-    return;
-  }
-
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::ConnectSco(BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-  if (!hfp || !hfp->ConnectSco()) {
-    DispatchReplyError(aRunnable, NS_LITERAL_STRING("ConnectSco failed"));
-    return;
-  }
-
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::DisconnectSco(BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-  if (!hfp || !hfp->DisconnectSco()) {
-    DispatchReplyError(aRunnable, NS_LITERAL_STRING("DisconnectSco failed"));
-    return;
-  }
-
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::IsScoConnected(BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-  if (!hfp) {
-    DispatchReplyError(aRunnable, NS_LITERAL_STRING("IsScoConnected failed"));
-    return;
-  }
-
-  DispatchReplySuccess(aRunnable, BluetoothValue(hfp->IsScoConnected()));
-}
-
-void
-BluetoothServiceBluedroid::SetObexPassword(const nsAString& aPassword,
-                                           BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
-  if (!pbap) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("Failed to set OBEX password"));
-    return;
-  }
-
-  pbap->ReplyToAuthChallenge(aPassword);
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::RejectObexAuth(
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ENSURE_BLUETOOTH_IS_ENABLED_VOID(aRunnable);
-
-  BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
-  if (!pbap) {
-    DispatchReplyError(aRunnable,
-      NS_LITERAL_STRING("Failed to reject OBEX authentication request"));
-    return;
-  }
-
-  pbap->ReplyToAuthChallenge(EmptyString());
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::ReplyTovCardPulling(
-  BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  BluetoothReplyRunnable* aRunnable)
-{
-  BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
-  if (!pbap) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("Reply to vCardPulling failed"));
-    return;
-  }
-
-  pbap->ReplyToPullvCardEntry(aBlobParent);
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::ReplyTovCardPulling(
-  Blob* aBlob,
-  BluetoothReplyRunnable* aRunnable)
-{
-  BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
-  if (!pbap) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("Reply to vCardPulling failed"));
-    return;
-  }
-
-  pbap->ReplyToPullvCardEntry(aBlob);
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::ReplyToPhonebookPulling(
-  BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  uint16_t aPhonebookSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-  BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
-  if (!pbap) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("Reply to Phonebook Pulling failed"));
-    return;
-  }
-
-  pbap->ReplyToPullPhonebook(aBlobParent, aPhonebookSize);
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::ReplyToPhonebookPulling(
-  Blob* aBlob,
-  uint16_t aPhonebookSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-  BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
-  if (!pbap) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("Reply to Phonebook Pulling failed"));
-    return;
-  }
-
-  pbap->ReplyToPullPhonebook(aBlob, aPhonebookSize);
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::ReplyTovCardListing(
-  BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  uint16_t aPhonebookSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-  BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
-  if (!pbap) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("Reply to vCard Listing failed"));
-    return;
-  }
-
-  pbap->ReplyToPullvCardListing(aBlobParent, aPhonebookSize);
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::ReplyTovCardListing(
-  Blob* aBlob,
-  uint16_t aPhonebookSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-  BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
-  if (!pbap) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("Reply to vCard Listing failed"));
-    return;
-  }
-
-  pbap->ReplyToPullvCardListing(aBlob, aPhonebookSize);
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::ReplyToMapFolderListing(
-  long aMasId,
-  const nsAString& aFolderlists,
-  BluetoothReplyRunnable* aRunnable)
-{
-  // TODO: Implement for future Email support
-}
-
-void
-BluetoothServiceBluedroid::ReplyToMapMessagesListing(
-  BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  long aMasId,
-  bool aNewMessage,
-  const nsAString& aTimestamp,
-  int aSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-  BluetoothMapSmsManager* map = BluetoothMapSmsManager::Get();
-  if (!map) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("Reply to Messages Listing failed"));
-    return;
-  }
-
-  map->ReplyToMessagesListing(aBlobParent, aMasId, aNewMessage, aTimestamp,
-                              aSize);
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid:: ReplyToMapMessagesListing(
-  long aMasId,
-  Blob* aBlob,
-  bool aNewMessage,
-  const nsAString& aTimestamp,
-  int aSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-  BluetoothMapSmsManager* map = BluetoothMapSmsManager::Get();
-  if (!map) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("Reply to Messages Listing failed"));
-    return;
-  }
-
-  map->ReplyToMessagesListing(aBlob, aMasId, aNewMessage, aTimestamp, aSize);
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid:: ReplyToMapGetMessage(
-  BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  long aMasId,
-  BluetoothReplyRunnable* aRunnable)
-{
-  BluetoothMapSmsManager* map = BluetoothMapSmsManager::Get();
-  if (!map) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("Reply to Get Message failed"));
-    return;
-  }
-
-  map->ReplyToGetMessage(aBlobParent, aMasId);
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid:: ReplyToMapGetMessage(
-  Blob* aBlob,
-  long aMasId,
-  BluetoothReplyRunnable* aRunnable)
-{
-  BluetoothMapSmsManager* map = BluetoothMapSmsManager::Get();
-  if (!map) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("Reply to Get Message failed"));
-    return;
-  }
-
-  map->ReplyToGetMessage(aBlob, aMasId);
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid:: ReplyToMapSetMessageStatus(
-  long aMasId,
-  bool aStatus,
-  BluetoothReplyRunnable* aRunnable)
-{
-  BluetoothMapSmsManager* map = BluetoothMapSmsManager::Get();
-  if (!map) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("Reply to Set Message failed"));
-    return;
-  }
-
-  map->ReplyToSetMessageStatus(aMasId, aStatus);
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid:: ReplyToMapSendMessage(
-  long aMasId,
-  const nsAString& aHandleId,
-  bool aStatus,
-  BluetoothReplyRunnable* aRunnable)
-{
-  BluetoothMapSmsManager* map = BluetoothMapSmsManager::Get();
-  if (!map) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("Reply to Send Message failed"));
-    return;
-  }
-
-  map->ReplyToSendMessage(aMasId, aHandleId, aStatus);
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid:: ReplyToMapMessageUpdate(
-  long aMasId,
-  bool aStatus,
-  BluetoothReplyRunnable* aRunnable)
-{
-  BluetoothMapSmsManager* map = BluetoothMapSmsManager::Get();
-  if (!map) {
-    DispatchReplyError(aRunnable,
-                       NS_LITERAL_STRING("Reply to MessageUpdate failed"));
-    return;
-  }
-
-  map->ReplyToMessageUpdate(aMasId, aStatus);
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::SendMetaData(const nsAString& aTitle,
-                                        const nsAString& aArtist,
-                                        const nsAString& aAlbum,
-                                        int64_t aMediaNumber,
-                                        int64_t aTotalMediaCount,
-                                        int64_t aDuration,
-                                        BluetoothReplyRunnable* aRunnable)
-{
-  BluetoothAvrcpManager* avrcp = BluetoothAvrcpManager::Get();
-  if (avrcp) {
-    avrcp->UpdateMetaData(aTitle, aArtist, aAlbum, aMediaNumber,
-                          aTotalMediaCount, aDuration);
-  }
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::SendPlayStatus(
-  int64_t aDuration, int64_t aPosition, ControlPlayStatus aPlayStatus,
-  BluetoothReplyRunnable* aRunnable)
-{
-  BluetoothAvrcpManager* avrcp = BluetoothAvrcpManager::Get();
-  if (avrcp) {
-    avrcp->UpdatePlayStatus(aDuration, aPosition, aPlayStatus);
-  }
-  DispatchReplySuccess(aRunnable);
-}
-
-void
-BluetoothServiceBluedroid::UpdatePlayStatus(
-  uint32_t aDuration, uint32_t aPosition, ControlPlayStatus aPlayStatus)
-{
-  // We don't need this function for bluedroid.
-  // In bluez, it only calls dbus api
-  // But it does not update BluetoothA2dpManager member fields
-  MOZ_ASSERT(false);
-}
-
-nsresult
-BluetoothServiceBluedroid::SendSinkMessage(const nsAString& aDeviceAddresses,
-                                           const nsAString& aMessage)
-{
-  return NS_OK;
-}
-
-nsresult
-BluetoothServiceBluedroid::SendInputMessage(const nsAString& aDeviceAddresses,
-                                            const nsAString& aMessage)
-{
-  return NS_OK;
-}
-
-void
-BluetoothServiceBluedroid::AnswerWaitingCall(BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothServiceBluedroid::IgnoreWaitingCall(BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothServiceBluedroid::ToggleCalls(BluetoothReplyRunnable* aRunnable)
-{
-}
-
-//
-// Bluetooth notifications
-//
-
-class BluetoothServiceBluedroid::CleanupResultHandler final
-  : public BluetoothResultHandler
-{
-public:
-  void Cleanup() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BluetoothService::AcknowledgeToggleBt(false);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_LOGR("BluetoothInterface::Cleanup failed: %d", aStatus);
-
-    BluetoothService::AcknowledgeToggleBt(false);
-  }
-};
-
-/* |ProfileDeinitResultHandler| collects the results of all profile
- * result handlers and cleans up the Bluedroid driver after all handlers
- * have been run.
- */
-class BluetoothServiceBluedroid::ProfileDeinitResultHandler final
-  : public BluetoothProfileResultHandler
-{
-public:
-  ProfileDeinitResultHandler(unsigned char aNumProfiles, bool aIsRestart)
-    : mNumProfiles(aNumProfiles)
-    , mIsRestart(aIsRestart)
-  {
-    MOZ_ASSERT(mNumProfiles);
-  }
-
-  void Deinit() override
-  {
-    if (!(--mNumProfiles)) {
-      Proceed();
-    }
-  }
-
-  void OnError(nsresult aResult) override
-  {
-    if (!(--mNumProfiles)) {
-      Proceed();
-    }
-  }
-
-private:
-  void Proceed() const
-  {
-    if (mIsRestart) {
-      BT_LOGR("ProfileDeinitResultHandler::Proceed cancel cleanup() ");
-      return;
-    }
-
-    sBtCoreInterface = nullptr;
-    sBtInterface->Cleanup(new CleanupResultHandler());
-  }
-
-  unsigned char mNumProfiles;
-  bool mIsRestart;
-};
-
-class BluetoothServiceBluedroid::SetAdapterPropertyDiscoverableResultHandler
-  final
-  : public BluetoothCoreResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_LOGR("Fail to set: BT_SCAN_MODE_CONNECTABLE");
-  }
-};
-
-void
-BluetoothServiceBluedroid::AdapterStateChangedNotification(bool aState)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BT_LOGR("BT_STATE: %d", aState);
-
-  if (mIsRestart && aState) {
-    // daemon restarted, reset flag
-    BT_LOGR("daemon restarted, reset flag");
-    mIsRestart = false;
-    mIsFirstTimeToggleOffBt = false;
-  }
-
-  mEnabled = aState;
-
-  if (!mEnabled) {
-    static void (* const sDeinitManager[])(BluetoothProfileResultHandler*) = {
-      // Cleanup interfaces in opposite order to initialization.
-      BluetoothGattManager::DeinitGattInterface,
-      BluetoothAvrcpManager::DeinitAvrcpInterface,
-      BluetoothA2dpManager::DeinitA2dpInterface,
-      BluetoothHfpManager::DeinitHfpInterface,
-      BluetoothHidManager::DeinitHidInterface,
-      BluetoothPbapManager::DeinitPbapInterface,
-      BluetoothOppManager::DeinitOppInterface,
-      BluetoothMapSmsManager::DeinitMapSmsInterface
-    };
-
-    // Return error if BluetoothService is unavailable
-    BluetoothService* bs = BluetoothService::Get();
-    NS_ENSURE_TRUE_VOID(bs);
-
-    // Cleanup static adapter properties and notify adapter.
-    mBdAddress.Clear();
-    mBdName.Clear();
-
-    InfallibleTArray<BluetoothNamedValue> props;
-    AppendNamedValue(props, "Name", mBdName);
-    AppendNamedValue(props, "Address", mBdAddress);
-    if (mDiscoverable) {
-      mDiscoverable = false;
-      AppendNamedValue(props, "Discoverable", false);
-    }
-    if (mDiscovering) {
-      mDiscovering = false;
-      AppendNamedValue(props, "Discovering", false);
-    }
-
-    bs->DistributeSignal(NS_LITERAL_STRING("PropertyChanged"),
-                         NS_LITERAL_STRING(KEY_ADAPTER),
-                         BluetoothValue(props));
-
-    // Cleanup Bluetooth interfaces after state becomes BT_STATE_OFF. This
-    // will also stop the Bluetooth daemon and disable the adapter.
-    RefPtr<ProfileDeinitResultHandler> res =
-      new ProfileDeinitResultHandler(MOZ_ARRAY_LENGTH(sDeinitManager),
-                                     mIsRestart);
-
-    for (size_t i = 0; i < MOZ_ARRAY_LENGTH(sDeinitManager); ++i) {
-      sDeinitManager[i](res);
-    }
-  }
-
-  if (mEnabled) {
-
-    // We enable the Bluetooth adapter here. Disabling is implemented
-    // in |CleanupResultHandler|, which runs at the end of the shutdown
-    // procedure. We cannot disable the adapter immediately, because re-
-    // enabling it might interfere with the shutdown procedure.
-    BluetoothService::AcknowledgeToggleBt(true);
-
-    // Bluetooth just enabled, clear profile controllers and runnable arrays.
-    sControllerArray.Clear();
-    mGetDeviceRequests.Clear();
-    mChangeDiscoveryRunnables.Clear();
-    mSetAdapterPropertyRunnables.Clear();
-    mFetchUuidsRunnables.Clear();
-    mCreateBondRunnables.Clear();
-    mRemoveBondRunnables.Clear();
-    mDeviceNameMap.Clear();
-
-    // Bluetooth scan mode is SCAN_MODE_CONNECTABLE by default, i.e., it should
-    // be connectable and non-discoverable.
-    sBtCoreInterface->SetAdapterProperty(
-      BluetoothProperty(PROPERTY_ADAPTER_SCAN_MODE, SCAN_MODE_CONNECTABLE),
-      new SetAdapterPropertyDiscoverableResultHandler());
-
-    // Trigger OPP & PBAP managers to listen
-    BluetoothOppManager* opp = BluetoothOppManager::Get();
-    if (!opp || !opp->Listen()) {
-      BT_LOGR("Fail to start BluetoothOppManager listening");
-    }
-
-    BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
-    if (!pbap || !pbap->Listen()) {
-      BT_LOGR("Fail to start BluetoothPbapManager listening");
-    }
-
-    BluetoothMapSmsManager* map = BluetoothMapSmsManager::Get();
-    if (!map || !map->Listen()) {
-      BT_LOGR("Fail to start BluetoothMapSmsManager listening");
-    }
-  }
-
-  // Resolve promise if existed
-  if (!mChangeAdapterStateRunnables.IsEmpty()) {
-    DispatchReplySuccess(mChangeAdapterStateRunnables[0]);
-    mChangeAdapterStateRunnables.RemoveElementAt(0);
-  }
-
-  // After ProfileManagers deinit and cleanup, now restart bluetooth daemon
-  if (mIsRestart && !aState) {
-    BT_LOGR("mIsRestart and off, now restart");
-    StartBluetooth(false, nullptr);
-  }
-}
-
-/**
- * AdapterPropertiesNotification will be called after enable() but before
- * AdapterStateChangeCallback is called. At that moment, both BluetoothManager
- * and BluetoothAdapter have not registered observer yet.
- */
-void
-BluetoothServiceBluedroid::AdapterPropertiesNotification(
-  BluetoothStatus aStatus, int aNumProperties,
-  const BluetoothProperty* aProperties)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  InfallibleTArray<BluetoothNamedValue> propertiesArray;
-
-  for (int i = 0; i < aNumProperties; i++) {
-
-    const BluetoothProperty& p = aProperties[i];
-
-    if (p.mType == PROPERTY_BDADDR) {
-      mBdAddress = p.mBdAddress;
-      AppendNamedValue(propertiesArray, "Address", mBdAddress);
-
-    } else if (p.mType == PROPERTY_BDNAME) {
-      mBdName = p.mRemoteName;
-      AppendNamedValue(propertiesArray, "Name", mBdName);
-
-    } else if (p.mType == PROPERTY_ADAPTER_SCAN_MODE) {
-
-      // If BT is not enabled, Bluetooth scan mode should be non-discoverable
-      // by defalut. |AdapterStateChangedNotification| would set default
-      // properties to bluetooth backend once Bluetooth is enabled.
-      if (IsEnabled()) {
-        mDiscoverable = (p.mScanMode == SCAN_MODE_CONNECTABLE_DISCOVERABLE);
-        AppendNamedValue(propertiesArray, "Discoverable", mDiscoverable);
-      }
-    } else if (p.mType == PROPERTY_ADAPTER_BONDED_DEVICES) {
-      // We have to cache addresses of bonded devices. Unlike BlueZ,
-      // Bluedroid would not send another PROPERTY_ADAPTER_BONDED_DEVICES
-      // event after bond completed.
-      BT_LOGD("Adapter property: BONDED_DEVICES. Count: %d",
-              p.mBdAddressArray.Length());
-
-      // Whenever reloading paired devices, force refresh
-      mBondedAddresses.Clear();
-      mBondedAddresses.AppendElements(p.mBdAddressArray);
-
-      AppendNamedValue(propertiesArray, "PairedDevices", mBondedAddresses);
-    } else if (p.mType == PROPERTY_UNKNOWN) {
-      /* Bug 1065999: working around unknown properties */
-    } else {
-      BT_LOGD("Unhandled adapter property type: %d", p.mType);
-      continue;
-    }
-  }
-
-  NS_ENSURE_TRUE_VOID(propertiesArray.Length() > 0);
-
-  DistributeSignal(NS_LITERAL_STRING("PropertyChanged"),
-                   NS_LITERAL_STRING(KEY_ADAPTER),
-                   BluetoothValue(propertiesArray));
-
-  // Send reply for SetProperty
-  if (!mSetAdapterPropertyRunnables.IsEmpty()) {
-    DispatchReplySuccess(mSetAdapterPropertyRunnables[0]);
-    mSetAdapterPropertyRunnables.RemoveElementAt(0);
-  }
-}
-
-/**
- * RemoteDevicePropertiesNotification will be called
- *
- *   (1) automatically by Bluedroid when BT is turning on, or
- *   (2) as result of remote device properties update during discovery, or
- *   (3) as result of CreateBond, or
- *   (4) as result of GetRemoteDeviceProperties, or
- *   (5) as result of GetRemoteServices.
- */
-void
-BluetoothServiceBluedroid::RemoteDevicePropertiesNotification(
-  BluetoothStatus aStatus, const BluetoothAddress& aBdAddr,
-  int aNumProperties, const BluetoothProperty* aProperties)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  InfallibleTArray<BluetoothNamedValue> propertiesArray;
-
-  AppendNamedValue(propertiesArray, "Address", aBdAddr);
-
-  for (int i = 0; i < aNumProperties; ++i) {
-
-    const BluetoothProperty& p = aProperties[i];
-
-    if (p.mType == PROPERTY_BDNAME) {
-      AppendNamedValue(propertiesArray, "Name", p.mRemoteName);
-
-      // Update <address, name> mapping
-      mDeviceNameMap.Remove(aBdAddr);
-      mDeviceNameMap.Put(aBdAddr, p.mRemoteName);
-    } else if (p.mType == PROPERTY_CLASS_OF_DEVICE) {
-      uint32_t cod = p.mUint32;
-      AppendNamedValue(propertiesArray, "Cod", cod);
-
-    } else if (p.mType == PROPERTY_UUIDS) {
-
-      size_t index;
-
-      // Handler for |UpdateSdpRecords|
-
-      for (index = 0; index < mGetRemoteServicesArray.Length(); ++index) {
-        if (mGetRemoteServicesArray[index].mDeviceAddress == aBdAddr) {
-          break;
-        }
-      }
-
-      if (index < mGetRemoteServicesArray.Length()) {
-        mGetRemoteServicesArray[index].mManager->OnUpdateSdpRecords(aBdAddr);
-        mGetRemoteServicesArray.RemoveElementAt(index);
-        continue; // continue with outer loop
-      }
-
-      // Handler for |FetchUuidsInternal|
-      AppendNamedValue(propertiesArray, "UUIDs", p.mUuidArray);
-
-    } else if (p.mType == PROPERTY_TYPE_OF_DEVICE) {
-      AppendNamedValue(propertiesArray, "Type",
-                       static_cast<uint32_t>(p.mTypeOfDevice));
-
-    } else if (p.mType == PROPERTY_SERVICE_RECORD) {
-
-      size_t i;
-
-      // Find call in array
-
-      for (i = 0; i < mGetRemoteServiceRecordArray.Length(); ++i) {
-        if ((mGetRemoteServiceRecordArray[i].mDeviceAddress == aBdAddr) &&
-            (mGetRemoteServiceRecordArray[i].mUuid == p.mServiceRecord.mUuid)) {
-
-          // Signal channel to profile manager
-          mGetRemoteServiceRecordArray[i].mManager->OnGetServiceChannel(
-            aBdAddr,
-            mGetRemoteServiceRecordArray[i].mUuid,
-            p.mServiceRecord.mChannel);
-
-          mGetRemoteServiceRecordArray.RemoveElementAt(i);
-          break;
-        }
-      }
-      Unused << NS_WARN_IF(i == mGetRemoteServiceRecordArray.Length());
-    } else if (p.mType == PROPERTY_UNKNOWN) {
-      /* Bug 1065999: working around unknown properties */
-    } else {
-      BT_LOGD("Other non-handled device properties. Type: %d", p.mType);
-    }
-  }
-
-  // The order of operations below is
-  //
-  //  (1) modify global state (i.e., the variables starting with 's'),
-  //  (2) distribute the signal, and finally
-  //  (3) send any pending Bluetooth replies.
-  //
-  // |DispatchReplySuccess| creates its own internal runnable, which is
-  // always run after we completed the current method. This means that we
-  // can exchange |DispatchReplySuccess| with other operations without
-  // changing the order of (1,2) and (3).
-
-  // Update to registered BluetoothDevice objects
-  nsAutoString bdAddrStr;
-  AddressToString(aBdAddr, bdAddrStr);
-  BluetoothSignal signal(NS_LITERAL_STRING("PropertyChanged"),
-                         bdAddrStr, propertiesArray);
-
-  // FetchUuids task
-  if (!mFetchUuidsRunnables.IsEmpty()) {
-    // propertiesArray contains Address and Uuids only
-    DispatchReplySuccess(mFetchUuidsRunnables[0],
-                         propertiesArray[1].value()); /* Uuids */
-    mFetchUuidsRunnables.RemoveElementAt(0);
-    DistributeSignal(signal);
-    return;
-  }
-
-  // GetDevices task
-  if (mGetDeviceRequests.IsEmpty()) {
-    // Callback is called after Bluetooth is turned on
-    DistributeSignal(signal);
-    return;
-  }
-
-  // Use address as the index
-  mGetDeviceRequests[0].mDevicesPack.AppendElement(
-    BluetoothNamedValue(bdAddrStr, propertiesArray));
-
-  if (--mGetDeviceRequests[0].mDeviceCount == 0) {
-    if (mGetDeviceRequests[0].mRunnable) {
-      DispatchReplySuccess(mGetDeviceRequests[0].mRunnable,
-                           mGetDeviceRequests[0].mDevicesPack);
-    }
-    mGetDeviceRequests.RemoveElementAt(0);
-  }
-
-  DistributeSignal(signal);
-}
-
-void
-BluetoothServiceBluedroid::DeviceFoundNotification(
-  int aNumProperties, const BluetoothProperty* aProperties)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  InfallibleTArray<BluetoothNamedValue> propertiesArray;
-
-  BluetoothAddress bdAddr;
-  BluetoothRemoteName bdName;
-
-  for (int i = 0; i < aNumProperties; i++) {
-
-    const BluetoothProperty& p = aProperties[i];
-
-    if (p.mType == PROPERTY_BDADDR) {
-      AppendNamedValue(propertiesArray, "Address", p.mBdAddress);
-      bdAddr = p.mBdAddress;
-    } else if (p.mType == PROPERTY_BDNAME) {
-      AppendNamedValue(propertiesArray, "Name", p.mRemoteName);
-      bdName = p.mRemoteName;
-    } else if (p.mType == PROPERTY_CLASS_OF_DEVICE) {
-      AppendNamedValue(propertiesArray, "Cod", p.mUint32);
-
-    } else if (p.mType == PROPERTY_UUIDS) {
-      AppendNamedValue(propertiesArray, "UUIDs", p.mUuidArray);
-
-    } else if (p.mType == PROPERTY_TYPE_OF_DEVICE) {
-      AppendNamedValue(propertiesArray, "Type",
-                       static_cast<uint32_t>(p.mTypeOfDevice));
-
-    } else if (p.mType == PROPERTY_UNKNOWN) {
-      /* Bug 1065999: working around unknown properties */
-    } else {
-      BT_LOGD("Not handled remote device property: %d", p.mType);
-    }
-  }
-
-  // Update <address, name> mapping
-  mDeviceNameMap.Remove(bdAddr);
-  mDeviceNameMap.Put(bdAddr, bdName);
-
-  DistributeSignal(NS_LITERAL_STRING("DeviceFound"),
-                   NS_LITERAL_STRING(KEY_ADAPTER),
-                   BluetoothValue(propertiesArray));
-}
-
-void
-BluetoothServiceBluedroid::DiscoveryStateChangedNotification(bool aState)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mDiscovering = aState;
-
-  // Fire PropertyChanged of Discovering
-  InfallibleTArray<BluetoothNamedValue> propertiesArray;
-  AppendNamedValue(propertiesArray, "Discovering", mDiscovering);
-
-  DistributeSignal(NS_LITERAL_STRING("PropertyChanged"),
-                   NS_LITERAL_STRING(KEY_ADAPTER),
-                   BluetoothValue(propertiesArray));
-
-  // Reply that Promise is resolved
-  if (!mChangeDiscoveryRunnables.IsEmpty()) {
-    DispatchReplySuccess(mChangeDiscoveryRunnables[0]);
-    mChangeDiscoveryRunnables.RemoveElementAt(0);
-  }
-}
-
-void
-BluetoothServiceBluedroid::PinRequestNotification(
-  const BluetoothAddress& aRemoteBdAddr, const BluetoothRemoteName& aBdName,
-  uint32_t aCod)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothRemoteName bdName;
-  InfallibleTArray<BluetoothNamedValue> propertiesArray;
-
-  // If |aBdName| is empty, get device name from |mDeviceNameMap|;
-  // Otherwise update <address, name> mapping with |aBdName|
-  if (aBdName.IsCleared()) {
-    mDeviceNameMap.Get(aRemoteBdAddr, &bdName);
-  } else {
-    bdName.Assign(aBdName.mName, aBdName.mLength);
-    mDeviceNameMap.Remove(aRemoteBdAddr);
-    mDeviceNameMap.Put(aRemoteBdAddr, bdName);
-  }
-
-  AppendNamedValue(propertiesArray, "address", aRemoteBdAddr);
-  AppendNamedValue(propertiesArray, "name", bdName);
-  AppendNamedValue(propertiesArray, "passkey", EmptyString());
-  AppendNamedValue(propertiesArray, "type",
-                   NS_LITERAL_STRING(PAIRING_REQ_TYPE_ENTERPINCODE));
-
-  DistributeSignal(NS_LITERAL_STRING("PairingRequest"),
-                   NS_LITERAL_STRING(KEY_PAIRING_LISTENER),
-                   BluetoothValue(propertiesArray));
-}
-
-void
-BluetoothServiceBluedroid::SspRequestNotification(
-  const BluetoothAddress& aRemoteBdAddr, const BluetoothRemoteName& aBdName,
-  uint32_t aCod, BluetoothSspVariant aPairingVariant, uint32_t aPassKey)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothRemoteName bdName;
-  InfallibleTArray<BluetoothNamedValue> propertiesArray;
-
-  // If |aBdName| is empty, get device name from |mDeviceNameMap|;
-  // Otherwise update <address, name> mapping with |aBdName|
-  if (aBdName.IsCleared()) {
-    mDeviceNameMap.Get(aRemoteBdAddr, &bdName);
-  } else {
-    bdName.Assign(aBdName.mName, aBdName.mLength);
-    mDeviceNameMap.Remove(aRemoteBdAddr);
-    mDeviceNameMap.Put(aRemoteBdAddr, bdName);
-  }
-
-  /**
-   * Assign pairing request type and passkey based on the pairing variant.
-   *
-   * passkey value based on pairing request type:
-   * 1) aPasskey: PAIRING_REQ_TYPE_CONFIRMATION and
-   *              PAIRING_REQ_TYPE_DISPLAYPASSKEY
-   * 2) empty string: PAIRING_REQ_TYPE_CONSENT
-   */
-  nsAutoString passkey;
-  nsAutoString pairingType;
-  switch (aPairingVariant) {
-    case SSP_VARIANT_PASSKEY_CONFIRMATION:
-      pairingType.AssignLiteral(PAIRING_REQ_TYPE_CONFIRMATION);
-      passkey.AppendInt(aPassKey);
-      break;
-    case SSP_VARIANT_PASSKEY_NOTIFICATION:
-      pairingType.AssignLiteral(PAIRING_REQ_TYPE_DISPLAYPASSKEY);
-      passkey.AppendInt(aPassKey);
-      break;
-    case SSP_VARIANT_CONSENT:
-      pairingType.AssignLiteral(PAIRING_REQ_TYPE_CONSENT);
-      break;
-    default:
-      BT_WARNING("Unhandled SSP Bonding Variant: %d", aPairingVariant);
-      return;
-  }
-
-  AppendNamedValue(propertiesArray, "address", aRemoteBdAddr);
-  AppendNamedValue(propertiesArray, "name", bdName);
-  AppendNamedValue(propertiesArray, "passkey", passkey);
-  AppendNamedValue(propertiesArray, "type", pairingType);
-
-  DistributeSignal(NS_LITERAL_STRING("PairingRequest"),
-                   NS_LITERAL_STRING(KEY_PAIRING_LISTENER),
-                   BluetoothValue(propertiesArray));
-}
-
-void
-BluetoothServiceBluedroid::BondStateChangedNotification(
-  BluetoothStatus aStatus, const BluetoothAddress& aRemoteBdAddr,
-  BluetoothBondState aState)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (aState == BOND_STATE_BONDING) {
-    // No need to handle bonding state
-    return;
-  }
-
-  BT_LOGR("Bond state: %d status: %d", aState, aStatus);
-
-  bool bonded = (aState == BOND_STATE_BONDED);
-  if (aStatus != STATUS_SUCCESS) {
-    if (!bonded) { // Active/passive pair failed
-      BT_LOGR("Pair failed! Abort pairing.");
-
-      // Notify adapter of pairing aborted
-      DistributeSignal(NS_LITERAL_STRING(PAIRING_ABORTED_ID),
-                       NS_LITERAL_STRING(KEY_ADAPTER));
-
-      // Reject pair promise
-      if (!mCreateBondRunnables.IsEmpty()) {
-        DispatchReplyError(mCreateBondRunnables[0], aStatus);
-        mCreateBondRunnables.RemoveElementAt(0);
-      }
-    } else if (!mRemoveBondRunnables.IsEmpty()) { // Active unpair failed
-      // Reject unpair promise
-      DispatchReplyError(mRemoveBondRunnables[0], aStatus);
-      mRemoveBondRunnables.RemoveElementAt(0);
-    }
-
-    return;
-  }
-
-  // Query pairing device name from hash table
-  BluetoothRemoteName remotebdName;
-  mDeviceNameMap.Get(aRemoteBdAddr, &remotebdName);
-
-  // Update bonded address array and append pairing device name
-  InfallibleTArray<BluetoothNamedValue> propertiesArray;
-  if (!bonded) {
-    mBondedAddresses.RemoveElement(aRemoteBdAddr);
-  } else {
-    if (!mBondedAddresses.Contains(aRemoteBdAddr)) {
-      mBondedAddresses.AppendElement(aRemoteBdAddr);
-    }
-
-    // We don't assert |!remotebdName.IsEmpty()| since empty string is also
-    // valid, according to Bluetooth Core Spec. v3.0 - Sec. 6.22:
-    // "a valid Bluetooth name is a UTF-8 encoding string which is up to 248
-    // bytes in length."
-    AppendNamedValue(propertiesArray, "Name", remotebdName);
-  }
-
-  // Notify device of attribute changed
-  nsAutoString remoteBdAddr;
-  AddressToString(aRemoteBdAddr, remoteBdAddr);
-  AppendNamedValue(propertiesArray, "Paired", bonded);
-  DistributeSignal(NS_LITERAL_STRING("PropertyChanged"),
-                   remoteBdAddr,
-                   BluetoothValue(propertiesArray));
-
-  // Notify adapter of device paired/unpaired
-  InsertNamedValue(propertiesArray, 0, "Address", aRemoteBdAddr);
-  DistributeSignal(bonded ? NS_LITERAL_STRING(DEVICE_PAIRED_ID)
-                          : NS_LITERAL_STRING(DEVICE_UNPAIRED_ID),
-                   NS_LITERAL_STRING(KEY_ADAPTER),
-                   BluetoothValue(propertiesArray));
-
-  // Resolve existing pair/unpair promise
-  if (bonded && !mCreateBondRunnables.IsEmpty()) {
-    DispatchReplySuccess(mCreateBondRunnables[0]);
-    mCreateBondRunnables.RemoveElementAt(0);
-  } else if (!bonded && !mRemoveBondRunnables.IsEmpty()) {
-    DispatchReplySuccess(mRemoveBondRunnables[0]);
-    mRemoveBondRunnables.RemoveElementAt(0);
-  }
-}
-
-void
-BluetoothServiceBluedroid::AclStateChangedNotification(
-  BluetoothStatus aStatus, const BluetoothAddress& aRemoteBdAddr,
-  BluetoothAclState aState)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // FIXME: This will be implemented in the later patchset
-}
-
-void
-BluetoothServiceBluedroid::DutModeRecvNotification(uint16_t aOpcode,
-                                                   const uint8_t* aBuf,
-                                                   uint8_t aLen)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // FIXME: This will be implemented in the later patchset
-}
-
-void
-BluetoothServiceBluedroid::LeTestModeNotification(BluetoothStatus aStatus,
-                                                  uint16_t aNumPackets)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // FIXME: This will be implemented in the later patchset
-}
-
-void
-BluetoothServiceBluedroid::EnergyInfoNotification(
-  const BluetoothActivityEnergyInfo& aInfo)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // FIXME: This will be implemented in the later patchset
-}
-
-void
-BluetoothServiceBluedroid::BackendErrorNotification(bool aCrashed)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!aCrashed) {
-    return;
-  }
-
-  /*
-   * Reset following profile manager states for unexpected backend crash.
-   * - HFP: connection state and audio state
-   * - A2DP: connection state
-   * - HID: connection state
-   */
-  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-  NS_ENSURE_TRUE_VOID(hfp);
-  hfp->HandleBackendError();
-  BluetoothA2dpManager* a2dp = BluetoothA2dpManager::Get();
-  NS_ENSURE_TRUE_VOID(a2dp);
-  a2dp->HandleBackendError();
-  BluetoothHidManager* hid = BluetoothHidManager::Get();
-  NS_ENSURE_TRUE_VOID(hid);
-  hid->HandleBackendError();
-
-  mIsRestart = true;
-  BT_LOGR("Recovery step2: stop bluetooth");
-  StopBluetooth(false, nullptr);
-}
-
-void
-BluetoothServiceBluedroid::CompleteToggleBt(bool aEnabled)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (mIsRestart && !aEnabled && mIsFirstTimeToggleOffBt) {
-    // Both StopBluetooth and AdapterStateChangedNotification
-    // trigger CompleteToggleBt. We don't need to call CompleteToggleBt again
-  } else if (mIsRestart && !aEnabled && !mIsFirstTimeToggleOffBt) {
-    // Recovery step 3: cleanup and deinit Profile managers
-    BT_LOGR("CompleteToggleBt set mIsFirstTimeToggleOffBt = true");
-    mIsFirstTimeToggleOffBt = true;
-    BluetoothService::CompleteToggleBt(aEnabled);
-    AdapterStateChangedNotification(false);
-  } else {
-    BluetoothService::CompleteToggleBt(aEnabled);
-  }
-}
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.h
+++ /dev/null
@@ -1,548 +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_BluetoothServiceBluedroid_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothServiceBluedroid_h
-
-#include "BluetoothCommon.h"
-#include "BluetoothHashKeys.h"
-#include "BluetoothInterface.h"
-#include "BluetoothService.h"
-#include "nsDataHashtable.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothServiceBluedroid
-  : public BluetoothService
-  , public BluetoothCoreNotificationHandler
-  , public BluetoothNotificationHandler
-{
-  class CancelBondResultHandler;
-  class CleanupResultHandler;
-  class DisableResultHandler;
-  class DispatchReplyErrorResultHandler;
-  class EnableResultHandler;
-  class GetRemoteDevicePropertiesResultHandler;
-  class GetRemoteServiceRecordResultHandler;
-  class GetRemoteServicesResultHandler;
-  class InitResultHandler;
-  class PinReplyResultHandler;
-  class ProfileDeinitResultHandler;
-  class ProfileInitResultHandler;
-  class SetAdapterPropertyDiscoverableResultHandler;
-  class SspReplyResultHandler;
-
-  class GetDeviceRequest;
-  struct GetRemoteServiceRecordRequest;
-  struct GetRemoteServicesRequest;
-
-public:
-  BluetoothServiceBluedroid();
-  ~BluetoothServiceBluedroid();
-
-  virtual nsresult StartInternal(BluetoothReplyRunnable* aRunnable);
-  virtual nsresult StopInternal(BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult GetAdaptersInternal(BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult
-  GetConnectedDevicePropertiesInternal(uint16_t aProfileId,
-                                       BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult
-  GetPairedDevicePropertiesInternal(
-    const nsTArray<BluetoothAddress>& aDeviceAddress,
-    BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult
-  FetchUuidsInternal(const BluetoothAddress& aDeviceAddress,
-                     BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
-  virtual void StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult
-  SetProperty(BluetoothObjectType aType,
-              const BluetoothNamedValue& aValue,
-              BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult
-  GetServiceChannel(const BluetoothAddress& aDeviceAddress,
-                    const BluetoothUuid& aServiceUuid,
-                    BluetoothProfileManagerBase* aManager);
-
-  virtual bool
-  UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
-                   BluetoothProfileManagerBase* aManager);
-
-  virtual nsresult
-  CreatePairedDeviceInternal(const BluetoothAddress& aDeviceAddress,
-                             int aTimeout,
-                             BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult
-  RemoveDeviceInternal(const BluetoothAddress& aDeviceAddress,
-                       BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  PinReplyInternal(const BluetoothAddress& aDeviceAddress,
-                   bool aAccept,
-                   const BluetoothPinCode& aPinCode,
-                   BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  SspReplyInternal(const BluetoothAddress& aDeviceAddress,
-                   BluetoothSspVariant aVariant,
-                   bool aAccept,
-                   BluetoothReplyRunnable* aRunnable);
-  virtual void
-  SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
-                     const BluetoothPinCode& aPinCode,
-                     BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  SetPasskeyInternal(const BluetoothAddress& aDeviceAddress,
-                     uint32_t aPasskey,
-                     BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  SetPairingConfirmationInternal(const BluetoothAddress& aDeviceAddress,
-                                 bool aConfirm,
-                                 BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  Connect(const BluetoothAddress& aDeviceAddress,
-          uint32_t aCod,
-          uint16_t aServiceUuid,
-          BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  Disconnect(const BluetoothAddress& aDeviceAddress, uint16_t aServiceUuid,
-             BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  SendFile(const BluetoothAddress& aDeviceAddress,
-           BlobParent* aBlobParent,
-           BlobChild* aBlobChild,
-           BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  SendFile(const BluetoothAddress& aDeviceAddress,
-           Blob* aBlob,
-           BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  StopSendingFile(const BluetoothAddress& aDeviceAddress,
-                  BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ConfirmReceivingFile(const BluetoothAddress& aDeviceAddress, bool aConfirm,
-                       BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ConnectSco(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  DisconnectSco(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  IsScoConnected(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  SetObexPassword(const nsAString& aPassword,
-                  BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  RejectObexAuth(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ReplyTovCardPulling(BlobParent* aBlobParent,
-                      BlobChild* aBlobChild,
-                      BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ReplyTovCardPulling(Blob* aBlob,
-                      BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ReplyToPhonebookPulling(BlobParent* aBlobParent,
-                          BlobChild* aBlobChild,
-                          uint16_t aPhonebookSize,
-                          BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ReplyToPhonebookPulling(Blob* aBlob,
-                          uint16_t aPhonebookSize,
-                          BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ReplyTovCardListing(BlobParent* aBlobParent,
-                      BlobChild* aBlobChild,
-                      uint16_t aPhonebookSize,
-                      BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ReplyTovCardListing(Blob* aBlob,
-                      uint16_t aPhonebookSize,
-                      BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ReplyToMapFolderListing(long aMasId,
-                          const nsAString& aFolderlists,
-                          BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ReplyToMapMessagesListing(BlobParent* aBlobParent,
-                            BlobChild* aBlobChild,
-                            long aMasId,
-                            bool aNewMessage,
-                            const nsAString& aTimestamp,
-                            int aSize,
-                            BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ReplyToMapMessagesListing(long aMasId,
-                            Blob* aBlob,
-                            bool aNewMessage,
-                            const nsAString& aTimestamp,
-                            int aSize,
-                            BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ReplyToMapGetMessage(BlobParent* aBlobParent,
-                       BlobChild* aBlobChild,
-                       long aMasId,
-                       BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ReplyToMapGetMessage(Blob* aBlob,
-                       long aMasId,
-                       BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ReplyToMapSetMessageStatus(long aMasId,
-                             bool aStatus,
-                             BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ReplyToMapSendMessage(long aMasId,
-                        const nsAString& aHandleId,
-                        bool aStatus,
-                        BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ReplyToMapMessageUpdate(
-    long aMasId, bool aStatus, BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  AnswerWaitingCall(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  IgnoreWaitingCall(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ToggleCalls(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  SendMetaData(const nsAString& aTitle,
-               const nsAString& aArtist,
-               const nsAString& aAlbum,
-               int64_t aMediaNumber,
-               int64_t aTotalMediaCount,
-               int64_t aDuration,
-               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SendPlayStatus(int64_t aDuration,
-                 int64_t aPosition,
-                 ControlPlayStatus aPlayStatus,
-                 BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  UpdatePlayStatus(uint32_t aDuration,
-                   uint32_t aPosition,
-                   ControlPlayStatus aPlayStatus) override;
-
-  virtual nsresult
-  SendSinkMessage(const nsAString& aDeviceAddresses,
-                  const nsAString& aMessage) override;
-
-  virtual nsresult
-  SendInputMessage(const nsAString& aDeviceAddresses,
-                   const nsAString& aMessage) override;
-
-  //
-  // GATT Client
-  //
-
-  virtual void StartLeScanInternal(const nsTArray<BluetoothUuid>& aServiceUuids,
-                                   BluetoothReplyRunnable* aRunnable);
-
-  virtual void StopLeScanInternal(const BluetoothUuid& aScanUuid,
-                                  BluetoothReplyRunnable* aRunnable);
-
-  virtual void StartAdvertisingInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattAdvertisingData& aAdvData,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void StopAdvertisingInternal(
-    const BluetoothUuid& aAppUuid,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ConnectGattClientInternal(const BluetoothUuid& aAppUuid,
-                            const BluetoothAddress& aDeviceAddress,
-                            BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  DisconnectGattClientInternal(const BluetoothUuid& aAppUuid,
-                               const BluetoothAddress& aDeviceAddress,
-                               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  DiscoverGattServicesInternal(const BluetoothUuid& aAppUuid,
-                               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientStartNotificationsInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServId,
-    const BluetoothGattId& aCharId,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientStopNotificationsInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServId,
-    const BluetoothGattId& aCharId,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  UnregisterGattClientInternal(int aClientIf,
-                               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientReadRemoteRssiInternal(
-    int aClientIf, const BluetoothAddress& aDeviceAddress,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientReadCharacteristicValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientWriteCharacteristicValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    const BluetoothGattWriteType& aWriteType,
-    const nsTArray<uint8_t>& aValue,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientReadDescriptorValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    const BluetoothGattId& aDescriptorId,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientWriteDescriptorValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    const BluetoothGattId& aDescriptorId,
-    const nsTArray<uint8_t>& aValue,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerRegisterInternal(
-    const BluetoothUuid& aAppUuid,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerConnectPeripheralInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerDisconnectPeripheralInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  UnregisterGattServerInternal(int aServerIf,
-                               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerAddServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    uint16_t aHandleCount,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerAddIncludedServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aIncludedServiceHandle,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerAddCharacteristicInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothUuid& aCharacteristicUuid,
-    BluetoothGattAttrPerm aPermissions,
-    BluetoothGattCharProp aProperties,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerAddDescriptorInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aCharacteristicHandle,
-    const BluetoothUuid& aDescriptorUuid,
-    BluetoothGattAttrPerm aPermissions,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerRemoveServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerStartServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerStopServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerSendResponseInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    uint16_t aStatus,
-    int32_t aRequestId,
-    const BluetoothGattResponse& aRsp,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerSendIndicationInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    const BluetoothAttributeHandle& aCharacteristicHandle,
-    bool aConfirm,
-    const nsTArray<uint8_t>& aValue,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  //
-  // Bluetooth notifications
-  //
-
-  virtual void AdapterStateChangedNotification(bool aState) override;
-  virtual void AdapterPropertiesNotification(
-    BluetoothStatus aStatus, int aNumProperties,
-    const BluetoothProperty* aProperties) override;
-
-  virtual void RemoteDevicePropertiesNotification(
-    BluetoothStatus aStatus, const BluetoothAddress& aBdAddr,
-    int aNumProperties, const BluetoothProperty* aProperties) override;
-
-  virtual void DeviceFoundNotification(
-    int aNumProperties, const BluetoothProperty* aProperties) override;
-
-  virtual void DiscoveryStateChangedNotification(bool aState) override;
-
-  virtual void PinRequestNotification(const BluetoothAddress& aRemoteBdAddr,
-                                      const BluetoothRemoteName& aBdName,
-                                      uint32_t aCod) override;
-  virtual void SspRequestNotification(const BluetoothAddress& aRemoteBdAddr,
-                                      const BluetoothRemoteName& aBdName,
-                                      uint32_t aCod,
-                                      BluetoothSspVariant aPairingVariant,
-                                      uint32_t aPasskey) override;
-
-  virtual void BondStateChangedNotification(
-    BluetoothStatus aStatus, const BluetoothAddress& aRemoteBdAddr,
-    BluetoothBondState aState) override;
-  virtual void AclStateChangedNotification(
-    BluetoothStatus aStatus, const BluetoothAddress& aRemoteBdAddr,
-    BluetoothAclState aState) override;
-
-  virtual void DutModeRecvNotification(uint16_t aOpcode,
-                                       const uint8_t* aBuf,
-                                       uint8_t aLen) override;
-  virtual void LeTestModeNotification(BluetoothStatus aStatus,
-                                      uint16_t aNumPackets) override;
-
-  virtual void EnergyInfoNotification(
-    const BluetoothActivityEnergyInfo& aInfo) override;
-
-  virtual void BackendErrorNotification(bool aCrashed) override;
-
-  virtual void CompleteToggleBt(bool aEnabled) override;
-
-protected:
-  static nsresult StartGonkBluetooth();
-  static nsresult StopGonkBluetooth();
-
-  static void ConnectDisconnect(bool aConnect,
-                                const BluetoothAddress& aDeviceAddress,
-                                BluetoothReplyRunnable* aRunnable,
-                                uint16_t aServiceUuid, uint32_t aCod = 0);
-  static void NextBluetoothProfileController();
-
-  // Adapter properties
-  BluetoothAddress mBdAddress;
-  BluetoothRemoteName mBdName;
-  bool mEnabled;
-  bool mDiscoverable;
-  bool mDiscovering;
-  nsTArray<BluetoothAddress> mBondedAddresses;
-
-  // Backend error recovery
-  bool mIsRestart;
-  bool mIsFirstTimeToggleOffBt;
-
-  // Runnable arrays
-  nsTArray<RefPtr<BluetoothReplyRunnable>> mChangeAdapterStateRunnables;
-  nsTArray<RefPtr<BluetoothReplyRunnable>> mSetAdapterPropertyRunnables;
-  nsTArray<RefPtr<BluetoothReplyRunnable>> mChangeDiscoveryRunnables;
-  nsTArray<RefPtr<BluetoothReplyRunnable>> mFetchUuidsRunnables;
-  nsTArray<RefPtr<BluetoothReplyRunnable>> mCreateBondRunnables;
-  nsTArray<RefPtr<BluetoothReplyRunnable>> mRemoveBondRunnables;
-
-  // Array of get device requests. Each request remembers
-  // 1) remaining device count to receive properties,
-  // 2) received remote device properties, and
-  // 3) runnable to reply success/error
-  nsTArray<GetDeviceRequest> mGetDeviceRequests;
-
-  // <address, name> mapping table for remote devices
-  nsDataHashtable<BluetoothAddressHashKey, BluetoothRemoteName> mDeviceNameMap;
-
-  // Arrays for SDP operations
-  nsTArray<GetRemoteServiceRecordRequest> mGetRemoteServiceRecordArray;
-  nsTArray<GetRemoteServicesRequest> mGetRemoteServicesArray;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothServiceBluedroid_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothSocket.cpp
+++ /dev/null
@@ -1,882 +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 "BluetoothSocket.h"
-#include <fcntl.h>
-#include <sys/socket.h>
-#include "BluetoothSocketObserver.h"
-#include "BluetoothInterface.h"
-#include "BluetoothUtils.h"
-#include "mozilla/ipc/UnixSocketWatcher.h"
-#include "mozilla/FileUtils.h"
-#include "mozilla/RefPtr.h"
-#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
-#include "nsXULAppAPI.h"
-
-using namespace mozilla::ipc;
-USING_BLUETOOTH_NAMESPACE
-
-static const size_t MAX_READ_SIZE = 1 << 16;
-
-class mozilla::dom::bluetooth::DroidSocketImpl
-  : public mozilla::ipc::UnixFdWatcher
-  , public DataSocketIO
-{
-public:
-  /* The connection status in DroidSocketImpl indicates the current
-   * phase of the socket connection. The initial settign should always
-   * be DISCONNECTED, when no connection is present.
-   *
-   * To establish a connection on the server, DroidSocketImpl moves
-   * to LISTENING. It now waits for incoming connection attempts by
-   * installing a read watcher on the I/O thread. When its socket file
-   * descriptor becomes readable, DroidSocketImpl accepts the connection
-   * and finally moves DroidSocketImpl to CONNECTED. DroidSocketImpl now
-   * uses read and write watchers during data transfers. Any socket setup
-   * is handled internally by the accept method.
-   *
-   * On the client side, DroidSocketImpl moves to CONNECTING and installs
-   * a write watcher on the I/O thread to wait until the connection is
-   * ready. The socket setup is handled internally by the connect method.
-   * Installing the write handler makes the code compatible with POSIX
-   * semantics for non-blocking connects and gives a clear signal when the
-   * conncetion is ready. DroidSocketImpl then moves to CONNECTED and uses
-   * read and write watchers during data transfers.
-   */
-  enum ConnectionStatus {
-    SOCKET_IS_DISCONNECTED = 0,
-    SOCKET_IS_LISTENING,
-    SOCKET_IS_CONNECTING,
-    SOCKET_IS_CONNECTED
-  };
-
-  DroidSocketImpl(MessageLoop* aConsumerLoop,
-                  MessageLoop* aIOLoop,
-                  BluetoothSocket* aConsumer)
-    : mozilla::ipc::UnixFdWatcher(aIOLoop)
-    , DataSocketIO(aConsumerLoop)
-    , mConsumer(aConsumer)
-    , mShuttingDownOnIOThread(false)
-    , mConnectionStatus(SOCKET_IS_DISCONNECTED)
-  {
-    MOZ_COUNT_CTOR_INHERITED(DroidSocketImpl, DataSocketIO);
-  }
-
-  ~DroidSocketImpl()
-  {
-    MOZ_ASSERT(IsConsumerThread());
-
-    MOZ_COUNT_DTOR_INHERITED(DroidSocketImpl, DataSocketIO);
-  }
-
-  void Send(UnixSocketIOBuffer* aBuffer)
-  {
-    EnqueueData(aBuffer);
-    AddWatchers(WRITE_WATCHER, false);
-  }
-
-  void Connect(int aFd);
-  void Listen(int aFd);
-  void Accept(int aFd);
-
-  void ConnectClientFd()
-  {
-    // Stop current read watch
-    RemoveWatchers(READ_WATCHER);
-
-    mConnectionStatus = SOCKET_IS_CONNECTED;
-
-    // Restart read & write watch on client fd
-    AddWatchers(READ_WATCHER, true);
-    AddWatchers(WRITE_WATCHER, false);
-  }
-
-  BluetoothSocket* GetBluetoothSocket()
-  {
-    return mConsumer;
-  }
-
-  DataSocket* GetDataSocket()
-  {
-    return GetBluetoothSocket();
-  }
-
-  /**
-   * Consumer pointer. Non-thread-safe pointer, so should only be manipulated
-   * directly from consumer thread. All non-consumer-thread accesses should
-   * happen with mImpl as container.
-   */
-  BluetoothSocket* mConsumer;
-
-  // Methods for |DataSocket|
-  //
-
-  nsresult QueryReceiveBuffer(UnixSocketIOBuffer** aBuffer);
-  void ConsumeBuffer();
-  void DiscardBuffer();
-
-  // Methods for |SocketIOBase|
-  //
-
-  SocketBase* GetSocketBase() override
-  {
-    return GetDataSocket();
-  }
-
-  bool IsShutdownOnConsumerThread() const override
-  {
-    MOZ_ASSERT(IsConsumerThread());
-
-    return mConsumer == nullptr;
-  }
-
-  bool IsShutdownOnIOThread() const override
-  {
-    return mShuttingDownOnIOThread;
-  }
-
-  void ShutdownOnConsumerThread() override
-  {
-    MOZ_ASSERT(IsConsumerThread());
-    MOZ_ASSERT(!IsShutdownOnConsumerThread());
-
-    mConsumer = nullptr;
-  }
-
-  void ShutdownOnIOThread() override
-  {
-    MOZ_ASSERT(!IsConsumerThread());
-    MOZ_ASSERT(!mShuttingDownOnIOThread);
-
-    Close(); // will also remove fd from I/O loop
-    mShuttingDownOnIOThread = true;
-  }
-
-private:
-  class ReceiveTask;
-
-  /**
-   * libevent triggered functions that reads data from socket when available and
-   * guarenteed non-blocking. Only to be called on IO thread.
-   *
-   * @param aFd [in] File descriptor to read from
-   */
-  virtual void OnFileCanReadWithoutBlocking(int aFd);
-
-  /**
-   * libevent or developer triggered functions that writes data to socket when
-   * available and guarenteed non-blocking. Only to be called on IO thread.
-   *
-   * @param aFd [in] File descriptor to read from
-   */
-  virtual void OnFileCanWriteWithoutBlocking(int aFd);
-
-  void OnSocketCanReceiveWithoutBlocking(int aFd);
-  void OnSocketCanAcceptWithoutBlocking(int aFd);
-  void OnSocketCanSendWithoutBlocking(int aFd);
-  void OnSocketCanConnectWithoutBlocking(int aFd);
-
-  /**
-   * If true, do not requeue whatever task we're running
-   */
-  bool mShuttingDownOnIOThread;
-
-  ConnectionStatus mConnectionStatus;
-
-  /**
-   * I/O buffer for received data
-   */
-  UniquePtr<UnixSocketRawData> mBuffer;
-};
-
-class SocketConnectTask final : public SocketIOTask<DroidSocketImpl>
-{
-public:
-  SocketConnectTask(DroidSocketImpl* aDroidSocketImpl, int aFd)
-  : SocketIOTask<DroidSocketImpl>(aDroidSocketImpl)
-  , mFd(aFd)
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!GetIO()->IsConsumerThread());
-    MOZ_ASSERT(!IsCanceled());
-
-    GetIO()->Connect(mFd);
-
-    return NS_OK;
-  }
-
-private:
-  int mFd;
-};
-
-class SocketListenTask final : public SocketIOTask<DroidSocketImpl>
-{
-public:
-  SocketListenTask(DroidSocketImpl* aDroidSocketImpl, int aFd)
-  : SocketIOTask<DroidSocketImpl>(aDroidSocketImpl)
-  , mFd(aFd)
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!GetIO()->IsConsumerThread());
-
-    if (!IsCanceled()) {
-      GetIO()->Listen(mFd);
-    }
-    return NS_OK;
-  }
-
-private:
-  int mFd;
-};
-
-class SocketConnectClientFdTask final
-: public SocketIOTask<DroidSocketImpl>
-{
-  SocketConnectClientFdTask(DroidSocketImpl* aImpl)
-  : SocketIOTask<DroidSocketImpl>(aImpl)
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!GetIO()->IsConsumerThread());
-
-    GetIO()->ConnectClientFd();
-
-    return NS_OK;
-  }
-};
-
-void
-DroidSocketImpl::Connect(int aFd)
-{
-  MOZ_ASSERT(aFd >= 0);
-
-  int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL));
-  NS_ENSURE_TRUE_VOID(flags >= 0);
-
-  if (!(flags & O_NONBLOCK)) {
-    int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags | O_NONBLOCK));
-    NS_ENSURE_TRUE_VOID(!res);
-  }
-
-  SetFd(aFd);
-  mConnectionStatus = SOCKET_IS_CONNECTING;
-
-  AddWatchers(WRITE_WATCHER, false);
-}
-
-void
-DroidSocketImpl::Listen(int aFd)
-{
-  MOZ_ASSERT(aFd >= 0);
-
-  int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL));
-  NS_ENSURE_TRUE_VOID(flags >= 0);
-
-  if (!(flags & O_NONBLOCK)) {
-    int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags | O_NONBLOCK));
-    NS_ENSURE_TRUE_VOID(!res);
-  }
-
-  SetFd(aFd);
-  mConnectionStatus = SOCKET_IS_LISTENING;
-
-  AddWatchers(READ_WATCHER, true);
-}
-
-void
-DroidSocketImpl::Accept(int aFd)
-{
-  Close();
-
-  int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL));
-  NS_ENSURE_TRUE_VOID(flags >= 0);
-
-  if (!(flags & O_NONBLOCK)) {
-    int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags | O_NONBLOCK));
-    NS_ENSURE_TRUE_VOID(!res);
-  }
-
-  SetFd(aFd);
-  mConnectionStatus = SOCKET_IS_CONNECTED;
-
-  GetConsumerThread()->PostTask(
-    MakeAndAddRef<SocketEventTask>(this, SocketEventTask::CONNECT_SUCCESS));
-
-  AddWatchers(READ_WATCHER, true);
-  if (HasPendingData()) {
-    AddWatchers(WRITE_WATCHER, false);
-  }
-}
-
-void
-DroidSocketImpl::OnFileCanReadWithoutBlocking(int aFd)
-{
-  if (mConnectionStatus == SOCKET_IS_CONNECTED) {
-    OnSocketCanReceiveWithoutBlocking(aFd);
-  } else if (mConnectionStatus == SOCKET_IS_LISTENING) {
-    OnSocketCanAcceptWithoutBlocking(aFd);
-  } else {
-    NS_NOTREACHED("invalid connection state for reading");
-  }
-}
-
-void
-DroidSocketImpl::OnSocketCanReceiveWithoutBlocking(int aFd)
-{
-  MOZ_ASSERT(!IsConsumerThread());
-  MOZ_ASSERT(!mShuttingDownOnIOThread);
-
-  ssize_t res = ReceiveData(aFd);
-  if (res < 0) {
-    /* I/O error */
-    RemoveWatchers(READ_WATCHER|WRITE_WATCHER);
-  } else if (!res) {
-    /* EOF or peer shutdown */
-    RemoveWatchers(READ_WATCHER);
-  }
-}
-
-class AcceptTask final : public SocketIOTask<DroidSocketImpl>
-{
-public:
-  AcceptTask(DroidSocketImpl* aDroidSocketImpl, int aFd)
-  : SocketIOTask<DroidSocketImpl>(aDroidSocketImpl)
-  , mFd(aFd)
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!GetIO()->IsConsumerThread());
-    MOZ_ASSERT(!IsCanceled());
-
-    GetIO()->Accept(mFd);
-
-    return NS_OK;
-  }
-
-private:
-  int mFd;
-};
-
-class AcceptResultHandler final : public BluetoothSocketResultHandler
-{
-public:
-  AcceptResultHandler(DroidSocketImpl* aImpl)
-  : mImpl(aImpl)
-  {
-    MOZ_ASSERT(mImpl);
-  }
-
-  void Accept(int aFd, const BluetoothAddress& aBdAddress,
-              int aConnectionStatus) override
-  {
-    MOZ_ASSERT(mImpl->IsConsumerThread());
-
-    mozilla::ScopedClose fd(aFd); // Close received socket fd on error
-
-    if (mImpl->IsShutdownOnConsumerThread()) {
-      BT_LOGD("mConsumer is null, aborting receive!");
-      return;
-    }
-
-    if (aConnectionStatus != 0) {
-      mImpl->mConsumer->NotifyError();
-      return;
-    }
-
-    mImpl->mConsumer->SetAddress(aBdAddress);
-    mImpl->GetIOLoop()->PostTask(
-      mozilla::MakeAndAddRef<AcceptTask>(mImpl, fd.forget()));
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(mImpl->IsConsumerThread());
-    BT_LOGR("BluetoothSocketInterface::Accept failed: %d", (int)aStatus);
-
-    if (!mImpl->IsShutdownOnConsumerThread()) {
-      // Instead of NotifyError(), call NotifyDisconnect() to trigger
-      // BluetoothOppManager::OnSocketDisconnect() as
-      // DroidSocketImpl::OnFileCanReadWithoutBlocking() in Firefox OS 2.0 in
-      // order to keep the same behavior and reduce regression risk.
-      mImpl->mConsumer->NotifyDisconnect();
-    }
-  }
-
-private:
-  DroidSocketImpl* mImpl;
-};
-
-class InvokeAcceptTask final : public SocketTask<DroidSocketImpl>
-{
-public:
-  InvokeAcceptTask(DroidSocketImpl* aImpl, int aListenFd)
-    : SocketTask<DroidSocketImpl>(aImpl)
-    , mListenFd(aListenFd)
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(GetIO()->IsConsumerThread());
-
-    GetIO()->mConsumer->Accept(mListenFd, new AcceptResultHandler(GetIO()));
-
-    return NS_OK;
-  }
-
-private:
-  int mListenFd;
-};
-
-void
-DroidSocketImpl::OnSocketCanAcceptWithoutBlocking(int aFd)
-{
-  MOZ_ASSERT(!IsConsumerThread());
-  MOZ_ASSERT(!mShuttingDownOnIOThread);
-
-  /* When a listening socket is ready for receiving data,
-   * we can call |Accept| on it.
-   */
-
-  RemoveWatchers(READ_WATCHER);
-  GetConsumerThread()->PostTask(MakeAndAddRef<InvokeAcceptTask>(this, aFd));
-}
-
-void
-DroidSocketImpl::OnFileCanWriteWithoutBlocking(int aFd)
-{
-  if (mConnectionStatus == SOCKET_IS_CONNECTED) {
-    OnSocketCanSendWithoutBlocking(aFd);
-  } else if (mConnectionStatus == SOCKET_IS_CONNECTING) {
-    OnSocketCanConnectWithoutBlocking(aFd);
-  } else {
-    NS_NOTREACHED("invalid connection state for writing");
-  }
-}
-
-void
-DroidSocketImpl::OnSocketCanSendWithoutBlocking(int aFd)
-{
-  MOZ_ASSERT(!IsConsumerThread());
-  MOZ_ASSERT(!mShuttingDownOnIOThread);
-  MOZ_ASSERT(aFd >= 0);
-
-  nsresult rv = SendPendingData(aFd);
-  if (NS_FAILED(rv)) {
-    return;
-  }
-
-  if (HasPendingData()) {
-    AddWatchers(WRITE_WATCHER, false);
-  }
-}
-
-void
-DroidSocketImpl::OnSocketCanConnectWithoutBlocking(int aFd)
-{
-  MOZ_ASSERT(!IsConsumerThread());
-  MOZ_ASSERT(!mShuttingDownOnIOThread);
-
-  /* We follow Posix behaviour here: Connect operations are
-   * complete once we can write to the connecting socket.
-   */
-
-  mConnectionStatus = SOCKET_IS_CONNECTED;
-
-  GetConsumerThread()->PostTask(
-    MakeAndAddRef<SocketEventTask>(this, SocketEventTask::CONNECT_SUCCESS));
-
-  AddWatchers(READ_WATCHER, true);
-  if (HasPendingData()) {
-    AddWatchers(WRITE_WATCHER, false);
-  }
-}
-
-// |DataSocketIO|
-
-nsresult
-DroidSocketImpl::QueryReceiveBuffer(
-  UnixSocketIOBuffer** aBuffer)
-{
-  MOZ_ASSERT(aBuffer);
-
-  if (!mBuffer) {
-    mBuffer = MakeUnique<UnixSocketRawData>(MAX_READ_SIZE);
-  }
-  *aBuffer = mBuffer.get();
-
-  return NS_OK;
-}
-
-/**
- * |ReceiveRunnable| transfers data received on the I/O thread
- * to an instance of |BluetoothSocket| on the consumer thread.
- */
-class DroidSocketImpl::ReceiveTask final : public SocketTask<DroidSocketImpl>
-{
-public:
-  ReceiveTask(DroidSocketImpl* aIO, UnixSocketBuffer* aBuffer)
-    : SocketTask<DroidSocketImpl>(aIO)
-    , mBuffer(aBuffer)
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    DroidSocketImpl* io = SocketTask<DroidSocketImpl>::GetIO();
-
-    MOZ_ASSERT(io->IsConsumerThread());
-
-    if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
-      // Since we've already explicitly closed and the close
-      // happened before this, this isn't really an error.
-      return NS_OK;
-    }
-
-    BluetoothSocket* bluetoothSocket = io->GetBluetoothSocket();
-    MOZ_ASSERT(bluetoothSocket);
-
-    bluetoothSocket->ReceiveSocketData(mBuffer);
-
-    return NS_OK;
-  }
-
-private:
-  UniquePtr<UnixSocketBuffer> mBuffer;
-};
-
-void
-DroidSocketImpl::ConsumeBuffer()
-{
-  GetConsumerThread()->PostTask(
-    MakeAndAddRef<ReceiveTask>(this, mBuffer.release()));
-}
-
-void
-DroidSocketImpl::DiscardBuffer()
-{
-  // Nothing to do.
-}
-
-//
-// |BluetoothSocket|
-//
-
-BluetoothSocket::BluetoothSocket(BluetoothSocketObserver* aObserver)
-  : mSocketInterface(nullptr)
-  , mObserver(aObserver)
-  , mCurrentRes(nullptr)
-  , mImpl(nullptr)
-{
-  MOZ_COUNT_CTOR_INHERITED(BluetoothSocket, DataSocket);
-}
-
-BluetoothSocket::~BluetoothSocket()
-{
-  MOZ_ASSERT(!mImpl); // Socket is closed
-
-  MOZ_COUNT_DTOR_INHERITED(BluetoothSocket, DataSocket);
-}
-
-void
-BluetoothSocket::SetObserver(BluetoothSocketObserver* aObserver)
-{
-  mObserver = aObserver;
-}
-
-class ConnectSocketResultHandler final : public BluetoothSocketResultHandler
-{
-public:
-  ConnectSocketResultHandler(DroidSocketImpl* aImpl)
-  : mImpl(aImpl)
-  {
-    MOZ_ASSERT(mImpl);
-  }
-
-  void Connect(int aFd, const BluetoothAddress& aBdAddress,
-               int aConnectionStatus) override
-  {
-    MOZ_ASSERT(mImpl->IsConsumerThread());
-
-    if (mImpl->IsShutdownOnConsumerThread()) {
-      BT_LOGD("mConsumer is null, aborting send!");
-      return;
-    }
-
-    if (aConnectionStatus != 0) {
-      mImpl->mConsumer->NotifyError();
-      return;
-    }
-
-    mImpl->mConsumer->SetAddress(aBdAddress);
-    mImpl->GetIOLoop()->PostTask(
-      mozilla::MakeAndAddRef<SocketConnectTask>(mImpl, aFd));
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(mImpl->IsConsumerThread());
-    BT_WARNING("Connect failed: %d", (int)aStatus);
-
-    if (!mImpl->IsShutdownOnConsumerThread()) {
-      // Instead of NotifyError(), call NotifyDisconnect() to trigger
-      // BluetoothOppManager::OnSocketDisconnect() as
-      // DroidSocketImpl::OnFileCanReadWithoutBlocking() in Firefox OS 2.0 in
-      // order to keep the same behavior and reduce regression risk.
-      mImpl->mConsumer->NotifyDisconnect();
-    }
-  }
-
-private:
-  DroidSocketImpl* mImpl;
-};
-
-nsresult
-BluetoothSocket::Connect(const BluetoothAddress& aDeviceAddress,
-                         const BluetoothUuid& aServiceUuid,
-                         BluetoothSocketType aType,
-                         int aChannel,
-                         bool aAuth, bool aEncrypt,
-                         MessageLoop* aConsumerLoop,
-                         MessageLoop* aIOLoop)
-{
-  MOZ_ASSERT(!mImpl);
-
-  auto rv = LoadSocketInterface();
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  SetConnectionStatus(SOCKET_CONNECTING);
-
-  mImpl = new DroidSocketImpl(aConsumerLoop, aIOLoop, this);
-
-  BluetoothSocketResultHandler* res = new ConnectSocketResultHandler(mImpl);
-  SetCurrentResultHandler(res);
-
-  mSocketInterface->Connect(
-    aDeviceAddress, aType,
-    aServiceUuid, aChannel,
-    aEncrypt, aAuth, res);
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothSocket::Connect(const BluetoothAddress& aDeviceAddress,
-                         const BluetoothUuid& aServiceUuid,
-                         BluetoothSocketType aType,
-                         int aChannel,
-                         bool aAuth, bool aEncrypt)
-{
-  return Connect(aDeviceAddress, aServiceUuid, aType, aChannel, aAuth,
-                 aEncrypt, MessageLoop::current(), XRE_GetIOMessageLoop());
-}
-
-class ListenResultHandler final : public BluetoothSocketResultHandler
-{
-public:
-  ListenResultHandler(DroidSocketImpl* aImpl)
-  : mImpl(aImpl)
-  {
-    MOZ_ASSERT(mImpl);
-  }
-
-  void Listen(int aFd) override
-  {
-    MOZ_ASSERT(mImpl->IsConsumerThread());
-
-    mImpl->GetIOLoop()->PostTask(
-      mozilla::MakeAndAddRef<SocketListenTask>(mImpl, aFd));
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(mImpl->IsConsumerThread());
-
-    BT_WARNING("Listen failed: %d", (int)aStatus);
-  }
-
-private:
-  DroidSocketImpl* mImpl;
-};
-
-nsresult
-BluetoothSocket::Listen(const nsAString& aServiceName,
-                        const BluetoothUuid& aServiceUuid,
-                        BluetoothSocketType aType,
-                        int aChannel,
-                        bool aAuth, bool aEncrypt,
-                        MessageLoop* aConsumerLoop,
-                        MessageLoop* aIOLoop)
-{
-  MOZ_ASSERT(!mImpl);
-
-  auto rv = LoadSocketInterface();
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  BluetoothServiceName serviceName;
-  rv = StringToServiceName(aServiceName, serviceName);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  SetConnectionStatus(SOCKET_LISTENING);
-
-  mImpl = new DroidSocketImpl(aConsumerLoop, aIOLoop, this);
-
-  BluetoothSocketResultHandler* res = new ListenResultHandler(mImpl);
-  SetCurrentResultHandler(res);
-
-  mSocketInterface->Listen(
-    aType,
-    serviceName, aServiceUuid, aChannel,
-    aEncrypt, aAuth, res);
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothSocket::Listen(const nsAString& aServiceName,
-                        const BluetoothUuid& aServiceUuid,
-                        BluetoothSocketType aType,
-                        int aChannel,
-                        bool aAuth, bool aEncrypt)
-{
-  return Listen(aServiceName, aServiceUuid, aType, aChannel, aAuth, aEncrypt,
-                MessageLoop::current(), XRE_GetIOMessageLoop());
-}
-
-nsresult
-BluetoothSocket::Accept(int aListenFd, BluetoothSocketResultHandler* aRes)
-{
-  auto rv = LoadSocketInterface();
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  SetCurrentResultHandler(aRes);
-  mSocketInterface->Accept(aListenFd, aRes);
-
-  return NS_OK;
-}
-
-void
-BluetoothSocket::ReceiveSocketData(UniquePtr<UnixSocketBuffer>& aBuffer)
-{
-  if (mObserver) {
-    mObserver->ReceiveSocketData(this, aBuffer);
-  }
-}
-
-// |DataSocket|
-
-void
-BluetoothSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
-{
-  MOZ_ASSERT(mImpl);
-  MOZ_ASSERT(mImpl->IsConsumerThread());
-  MOZ_ASSERT(!mImpl->IsShutdownOnConsumerThread());
-
-  mImpl->GetIOLoop()->PostTask(
-    MakeAndAddRef<SocketIOSendTask<DroidSocketImpl, UnixSocketIOBuffer>>(
-      mImpl, aBuffer));
-}
-
-// |SocketBase|
-
-void
-BluetoothSocket::Close()
-{
-  if (!mImpl) {
-    return;
-  }
-
-  NotifyDisconnect();
-}
-
-void
-BluetoothSocket::OnConnectSuccess()
-{
-  SetCurrentResultHandler(nullptr);
-
-  if (mObserver) {
-    mObserver->OnSocketConnectSuccess(this);
-  }
-}
-
-void
-BluetoothSocket::OnConnectError()
-{
-  auto observer = mObserver;
-
-  Cleanup();
-
-  if (observer) {
-    observer->OnSocketConnectError(this);
-  }
-}
-
-void
-BluetoothSocket::OnDisconnect()
-{
-  auto observer = mObserver;
-
-  Cleanup();
-
-  if (observer) {
-    observer->OnSocketDisconnect(this);
-  }
-}
-
-nsresult
-BluetoothSocket::LoadSocketInterface()
-{
-  if (mSocketInterface) {
-    return NS_OK;
-  }
-
-  auto interface = BluetoothInterface::GetInstance();
-  NS_ENSURE_TRUE(!!interface, NS_ERROR_FAILURE);
-
-  auto socketInterface = interface->GetBluetoothSocketInterface();
-  NS_ENSURE_TRUE(!!socketInterface, NS_ERROR_FAILURE);
-
-  mSocketInterface = socketInterface;
-
-  return NS_OK;
-}
-
-void
-BluetoothSocket::Cleanup()
-{
-  MOZ_ASSERT(mSocketInterface);
-  MOZ_ASSERT(mImpl);
-  MOZ_ASSERT(mImpl->IsConsumerThread());
-
-  // Stop any watching |SocketMessageWatcher|
-  if (mCurrentRes) {
-    mSocketInterface->Close(mCurrentRes);
-  }
-
-  // From this point on, we consider mImpl as being deleted. We
-  // sever the relationship here so any future calls to listen
-  // or connect will create a new implementation.
-  mImpl->ShutdownOnConsumerThread();
-  mImpl->GetIOLoop()->PostTask(MakeAndAddRef<SocketIOShutdownTask>(mImpl));
-  mImpl = nullptr;
-
-  mSocketInterface = nullptr;
-  mObserver = nullptr;
-  mCurrentRes = nullptr;
-  mDeviceAddress.Clear();
-}
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothSocket.h
+++ /dev/null
@@ -1,110 +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_BluetoothSocket_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothSocket_h
-
-#include "BluetoothCommon.h"
-#include "mozilla/ipc/DataSocket.h"
-
-class MessageLoop;
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothSocketInterface;
-class BluetoothSocketObserver;
-class BluetoothSocketResultHandler;
-class DroidSocketImpl;
-
-class BluetoothSocket final : public mozilla::ipc::DataSocket
-{
-public:
-  BluetoothSocket(BluetoothSocketObserver* aObserver);
-  ~BluetoothSocket();
-
-  void SetObserver(BluetoothSocketObserver* aObserver);
-
-  nsresult Connect(const BluetoothAddress& aDeviceAddress,
-                   const BluetoothUuid& aServiceUuid,
-                   BluetoothSocketType aType,
-                   int aChannel,
-                   bool aAuth, bool aEncrypt,
-                   MessageLoop* aConsumerLoop,
-                   MessageLoop* aIOLoop);
-
-  nsresult Connect(const BluetoothAddress& aDeviceAddress,
-                   const BluetoothUuid& aServiceUuid,
-                   BluetoothSocketType aType,
-                   int aChannel,
-                   bool aAuth, bool aEncrypt);
-
-  nsresult Listen(const nsAString& aServiceName,
-                  const BluetoothUuid& aServiceUuid,
-                  BluetoothSocketType aType,
-                  int aChannel,
-                  bool aAuth, bool aEncrypt,
-                  MessageLoop* aConsumerLoop,
-                  MessageLoop* aIOLoop);
-
-  nsresult Listen(const nsAString& aServiceName,
-                  const BluetoothUuid& aServiceUuid,
-                  BluetoothSocketType aType,
-                  int aChannel,
-                  bool aAuth, bool aEncrypt);
-
-  nsresult Accept(int aListenFd, BluetoothSocketResultHandler* aRes);
-
-  /**
-   * Method to be called whenever data is received. This is only called on the
-   * consumer thread.
-   *
-   * @param aBuffer Data received from the socket.
-   */
-  void ReceiveSocketData(UniquePtr<mozilla::ipc::UnixSocketBuffer>& aBuffer);
-
-  inline void GetAddress(BluetoothAddress& aDeviceAddress)
-  {
-    aDeviceAddress = mDeviceAddress;
-  }
-
-  inline void SetAddress(const BluetoothAddress& aDeviceAddress)
-  {
-    mDeviceAddress = aDeviceAddress;
-  }
-
-  // Methods for |DataSocket|
-  //
-
-  void SendSocketData(mozilla::ipc::UnixSocketIOBuffer* aBuffer) override;
-
-  // Methods for |SocketBase|
-  //
-
-  void Close() override;
-
-  void OnConnectSuccess() override;
-  void OnConnectError() override;
-  void OnDisconnect() override;
-
-private:
-  nsresult LoadSocketInterface();
-  void Cleanup();
-
-  inline void SetCurrentResultHandler(BluetoothSocketResultHandler* aRes)
-  {
-    mCurrentRes = aRes;
-  }
-
-  BluetoothSocketInterface* mSocketInterface;
-  BluetoothSocketObserver* mObserver;
-  BluetoothSocketResultHandler* mCurrentRes;
-  DroidSocketImpl* mImpl;
-  BluetoothAddress mDeviceAddress;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothSocket_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.cpp
+++ /dev/null
@@ -1,314 +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 "BluetoothSocketMessageWatcher.h"
-#include <errno.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include "BluetoothInterface.h"
-#include "mozilla/EndianUtils.h"
-#include "nsClassHashtable.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-//
-// SocketMessageWatcherWrapper
-//
-
-/* |SocketMessageWatcherWrapper| wraps SocketMessageWatcher to keep it from
- * being released by hash table's Remove() method.
- */
-class SocketMessageWatcherWrapper
-{
-public:
-  SocketMessageWatcherWrapper(SocketMessageWatcher* aSocketMessageWatcher)
-    : mSocketMessageWatcher(aSocketMessageWatcher)
-  {
-    MOZ_ASSERT(mSocketMessageWatcher);
-  }
-
-  SocketMessageWatcher* GetSocketMessageWatcher()
-  {
-    return mSocketMessageWatcher;
-  }
-
-private:
-  SocketMessageWatcher* mSocketMessageWatcher;
-};
-
-/* |sWatcherHashTable| maps result handlers to corresponding watchers */
-static nsClassHashtable<nsRefPtrHashKey<BluetoothSocketResultHandler>,
-                        SocketMessageWatcherWrapper>
-  sWatcherHashtable;
-
-//
-// SocketMessageWatcher
-//
-
-SocketMessageWatcher::SocketMessageWatcher(
-  int aFd, BluetoothSocketResultHandler* aRes)
-  : mFd(aFd)
-  , mClientFd(-1)
-  , mLen(0)
-  , mRes(aRes)
-{
-  MOZ_ASSERT(mRes);
-}
-
-SocketMessageWatcher::~SocketMessageWatcher()
-{ }
-
-void
-SocketMessageWatcher::OnFileCanReadWithoutBlocking(int aFd)
-{
-  BluetoothStatus status;
-
-  switch (mLen) {
-    case 0:
-      status = RecvMsg1();
-      break;
-    case MSG1_SIZE:
-      status = RecvMsg2();
-      break;
-    default:
-      /* message-size error */
-      status = STATUS_FAIL;
-      break;
-  }
-
-  if (IsComplete() || status != STATUS_SUCCESS) {
-    StopWatching();
-    Proceed(status);
-  }
-}
-
-void
-SocketMessageWatcher::OnFileCanWriteWithoutBlocking(int aFd)
-{ }
-
-void
-SocketMessageWatcher::Watch()
-{
-  // add this watcher and its result handler to hash table
-  sWatcherHashtable.Put(mRes, new SocketMessageWatcherWrapper(this));
-
-  MessageLoopForIO::current()->WatchFileDescriptor(
-    mFd,
-    true,
-    MessageLoopForIO::WATCH_READ,
-    &mWatcher,
-    this);
-}
-
-void
-SocketMessageWatcher::StopWatching()
-{
-  mWatcher.StopWatchingFileDescriptor();
-
-  // remove this watcher and its result handler from hash table
-  sWatcherHashtable.Remove(mRes);
-}
-
-bool
-SocketMessageWatcher::IsComplete() const
-{
-  return mLen == (MSG1_SIZE + MSG2_SIZE);
-}
-
-int
-SocketMessageWatcher::GetFd() const
-{
-  return mFd;
-}
-
-int32_t
-SocketMessageWatcher::GetChannel1() const
-{
-  return ReadInt32(OFF_CHANNEL1);
-}
-
-int32_t
-SocketMessageWatcher::GetSize() const
-{
-  return ReadInt16(OFF_SIZE);
-}
-
-BluetoothAddress
-SocketMessageWatcher::GetBdAddress() const
-{
-  BluetoothAddress bdAddress;
-  ReadBdAddress(OFF_BDADDRESS, bdAddress);
-  return bdAddress;
-}
-
-int32_t
-SocketMessageWatcher::GetChannel2() const
-{
-  return ReadInt32(OFF_CHANNEL2);
-}
-
-int32_t
-SocketMessageWatcher::GetConnectionStatus() const
-{
-  return ReadInt32(OFF_STATUS);
-}
-
-int
-SocketMessageWatcher::GetClientFd() const
-{
-  return mClientFd;
-}
-
-BluetoothSocketResultHandler*
-SocketMessageWatcher::GetResultHandler() const
-{
-  return mRes;
-}
-
-BluetoothStatus
-SocketMessageWatcher::RecvMsg1()
-{
-  struct iovec iv;
-  memset(&iv, 0, sizeof(iv));
-  iv.iov_base = mBuf;
-  iv.iov_len = MSG1_SIZE;
-
-  struct msghdr msg;
-  memset(&msg, 0, sizeof(msg));
-  msg.msg_iov = &iv;
-  msg.msg_iovlen = 1;
-
-  ssize_t res = TEMP_FAILURE_RETRY(recvmsg(mFd, &msg, MSG_NOSIGNAL));
-  if (res <= 0) {
-    return STATUS_FAIL;
-  }
-
-  mLen += res;
-
-  return STATUS_SUCCESS;
-}
-
-#define CMSGHDR_CONTAINS_FD(_cmsghdr) \
-    ( ((_cmsghdr)->cmsg_level == SOL_SOCKET) && \
-      ((_cmsghdr)->cmsg_type == SCM_RIGHTS) )
-
-BluetoothStatus
-SocketMessageWatcher::RecvMsg2()
-{
-  struct iovec iv;
-  memset(&iv, 0, sizeof(iv));
-  iv.iov_base = mBuf + MSG1_SIZE;
-  iv.iov_len = MSG2_SIZE;
-
-  struct msghdr msg;
-  struct cmsghdr cmsgbuf[CMSG_SPACE(sizeof(int))];
-  memset(&msg, 0, sizeof(msg));
-  msg.msg_iov = &iv;
-  msg.msg_iovlen = 1;
-  msg.msg_control = cmsgbuf;
-  msg.msg_controllen = sizeof(cmsgbuf);
-
-  ssize_t res = TEMP_FAILURE_RETRY(recvmsg(mFd, &msg, MSG_NOSIGNAL));
-  if (res <= 0) {
-    return STATUS_FAIL;
-  }
-
-  mLen += res;
-
-  if (msg.msg_flags & (MSG_CTRUNC | MSG_OOB | MSG_ERRQUEUE)) {
-    return STATUS_FAIL;
-  }
-
-  struct cmsghdr *cmsgptr = CMSG_FIRSTHDR(&msg);
-
-  // Extract client fd from message header
-  for (; cmsgptr; cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) {
-    if (CMSGHDR_CONTAINS_FD(cmsgptr)) {
-      // if multiple file descriptors have been sent, we close
-      // all but the final one.
-      if (mClientFd != -1) {
-        TEMP_FAILURE_RETRY(close(mClientFd));
-      }
-      // retrieve sent client fd
-      memcpy(&mClientFd, CMSG_DATA(cmsgptr), sizeof(mClientFd));
-    }
-  }
-
-  return STATUS_SUCCESS;
-}
-
-int16_t
-SocketMessageWatcher::ReadInt16(unsigned long aOffset) const
-{
-  /* little-endian buffer */
-  return LittleEndian::readInt16(&mBuf[aOffset]);
-}
-
-int32_t
-SocketMessageWatcher::ReadInt32(unsigned long aOffset) const
-{
-  /* little-endian buffer */
-  return LittleEndian::readInt32(&mBuf[aOffset]);
-}
-
-void
-SocketMessageWatcher::ReadBdAddress(unsigned long aOffset,
-                                    BluetoothAddress& aBdAddress) const
-{
-  aBdAddress = BluetoothAddress(mBuf[aOffset + 0],
-                                mBuf[aOffset + 1],
-                                mBuf[aOffset + 2],
-                                mBuf[aOffset + 3],
-                                mBuf[aOffset + 4],
-                                mBuf[aOffset + 5]);
-}
-
-//
-// SocketMessageWatcherTask
-//
-
-SocketMessageWatcherTask::SocketMessageWatcherTask(
-  SocketMessageWatcher* aWatcher)
-  : mWatcher(aWatcher)
-{
-  MOZ_ASSERT(mWatcher);
-}
-
-NS_IMETHODIMP
-SocketMessageWatcherTask::Run()
-{
-  mWatcher->Watch();
-  return NS_OK;
-}
-
-//
-// DeleteSocketMessageWatcherTask
-//
-
-DeleteSocketMessageWatcherTask::DeleteSocketMessageWatcherTask(
-  BluetoothSocketResultHandler* aRes)
-  : mRes(aRes)
-{
-  MOZ_ASSERT(mRes);
-}
-
-NS_IMETHODIMP
-DeleteSocketMessageWatcherTask::Run()
-{
-  // look up hash table for the watcher corresponding to |mRes|
-  SocketMessageWatcherWrapper* wrapper = sWatcherHashtable.Get(mRes);
-  if (!wrapper) {
-    return NS_OK;
-  }
-
-  // stop the watcher if it exists
-  SocketMessageWatcher* watcher = wrapper->GetSocketMessageWatcher();
-  watcher->StopWatching();
-  watcher->Proceed(STATUS_DONE);
-  return NS_OK;
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.h
+++ /dev/null
@@ -1,114 +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_BluetoothSocketMessageWatcher_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothSocketMessageWatcher_h
-
-#include "base/message_loop.h"
-#include "BluetoothCommon.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothSocketResultHandler;
-
-/* |SocketMessageWatcher| receives Bluedroid's socket setup
- * messages on the I/O thread. You need to inherit from this
- * class to make use of it.
- *
- * Bluedroid sends two socket info messages (20 bytes) at
- * the beginning of a connection to both peers.
- *
- *   - 1st message: [channel:4]
- *   - 2nd message: [size:2][bd address:6][channel:4][connection status:4]
- *
- * On the server side, the second message will contain a
- * socket file descriptor for the connection. The client
- * uses the original file descriptor.
- */
-class SocketMessageWatcher : public MessageLoopForIO::Watcher
-{
-public:
-  static const unsigned char MSG1_SIZE = 4;
-  static const unsigned char MSG2_SIZE = 16;
-
-  static const unsigned char OFF_CHANNEL1 = 0;
-  static const unsigned char OFF_SIZE = 4;
-  static const unsigned char OFF_BDADDRESS = 6;
-  static const unsigned char OFF_CHANNEL2 = 12;
-  static const unsigned char OFF_STATUS = 16;
-
-  virtual ~SocketMessageWatcher();
-
-  virtual void Proceed(BluetoothStatus aStatus) = 0;
-
-  void OnFileCanReadWithoutBlocking(int aFd) override;
-  void OnFileCanWriteWithoutBlocking(int aFd) override;
-
-  void Watch();
-  void StopWatching();
-
-  bool IsComplete() const;
-
-  int              GetFd() const;
-  int32_t          GetChannel1() const;
-  int32_t          GetSize() const;
-  BluetoothAddress GetBdAddress() const;
-  int32_t          GetChannel2() const;
-  int32_t          GetConnectionStatus() const;
-  int              GetClientFd() const;
-
-  BluetoothSocketResultHandler* GetResultHandler() const;
-
-protected:
-  SocketMessageWatcher(int aFd, BluetoothSocketResultHandler* aRes);
-
-private:
-  BluetoothStatus RecvMsg1();
-  BluetoothStatus RecvMsg2();
-
-  int16_t ReadInt16(unsigned long aOffset) const;
-  int32_t ReadInt32(unsigned long aOffset) const;
-  void    ReadBdAddress(unsigned long aOffset, BluetoothAddress& aBdAddress) const;
-
-  MessageLoopForIO::FileDescriptorWatcher mWatcher;
-  int mFd;
-  int mClientFd;
-  unsigned char mLen;
-  uint8_t mBuf[MSG1_SIZE + MSG2_SIZE];
-  RefPtr<BluetoothSocketResultHandler> mRes;
-};
-
-/* |SocketMessageWatcherTask| starts a SocketMessageWatcher
- * on the I/O task
- */
-class SocketMessageWatcherTask final : public Runnable
-{
-public:
-  SocketMessageWatcherTask(SocketMessageWatcher* aWatcher);
-
-  NS_IMETHOD Run() override;
-
-private:
-  SocketMessageWatcher* mWatcher;
-};
-
-/* |DeleteSocketMessageWatcherTask| deletes a watching SocketMessageWatcher
- * on the I/O task
- */
-class DeleteSocketMessageWatcherTask final : public Runnable
-{
-public:
-  DeleteSocketMessageWatcherTask(BluetoothSocketResultHandler* aRes);
-
-  NS_IMETHOD Run() override;
-
-private:
-  BluetoothSocketResultHandler* mRes;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothSocketMessageWatcher_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/hfp-fallback/BluetoothHfpManager.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 "base/basictypes.h"
-#include "BluetoothHfpManager.h"
-#include "BluetoothProfileController.h"
-#include "mozilla/Services.h"
-#include "mozilla/StaticPtr.h"
-#include "nsIObserverService.h"
-#include "nsThreadUtils.h"
-
-using namespace mozilla;
-USING_BLUETOOTH_NAMESPACE
-
-namespace {
-  StaticRefPtr<BluetoothHfpManager> sBluetoothHfpManager;
-  bool sInShutdown = false;
-} // namespace
-
-/**
- * nsIObserver function
- */
-NS_IMETHODIMP
-BluetoothHfpManager::Observe(nsISupports* aSubject,
-                             const char* aTopic,
-                             const char16_t* aData)
-{
-  if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    HandleShutdown();
-  } else {
-    MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!");
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  return NS_OK;
-}
-
-/**
- * BluetoothProfileManagerBase functions
- */
-void
-BluetoothHfpManager::Connect(const BluetoothAddress& aDeviceAddress,
-                             BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(aController);
-
-  aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-}
-
-void
-BluetoothHfpManager::Disconnect(BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(aController);
-
-  aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-}
-
-bool
-BluetoothHfpManager::IsConnected()
-{
-  return false;
-}
-
-void
-BluetoothHfpManager::OnConnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothHfpManager::OnDisconnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothHfpManager::GetAddress(BluetoothAddress& aDeviceAddress)
-{
-  aDeviceAddress.Clear();
-}
-
-void
-BluetoothHfpManager::OnGetServiceChannel(
-  const BluetoothAddress& aDeviceAddress,
-  const BluetoothUuid& aServiceUuid,
-  int aChannel)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothHfpManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
-{
-  MOZ_ASSERT(false);
-}
-
-/**
- * BluetoothHfpManagerBase function
- */
-bool
-BluetoothHfpManager::IsScoConnected()
-{
-  return false;
-}
-
-bool
-BluetoothHfpManager::IsNrecEnabled()
-{
-  return false;
-}
-
-/**
- * Non-inherited functions
- */
-// static
-BluetoothHfpManager*
-BluetoothHfpManager::Get()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // If sBluetoothHfpManager already exists, exit early
-  if (sBluetoothHfpManager) {
-    return sBluetoothHfpManager;
-  }
-
-  // If we're in shutdown, don't create a new instance
-  NS_ENSURE_FALSE(sInShutdown, nullptr);
-
-  // Create a new instance and return
-  BluetoothHfpManager* manager = new BluetoothHfpManager();
-  NS_ENSURE_TRUE(manager->Init(), nullptr);
-
-  sBluetoothHfpManager = manager;
-  return sBluetoothHfpManager;
-}
-
-bool
-BluetoothHfpManager::Init()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE(obs, false);
-
-  if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
-    BT_WARNING("Failed to add observers!");
-    return false;
-  }
-
-  return true;
-}
-
-// static
-void
-BluetoothHfpManager::InitHfpInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * TODO:
-   *   Implement InitHfpInterface() for applications that want to create SCO
-   *   link without a HFP connection (e.g., VoIP).
-   */
-
-  if (aRes) {
-    aRes->Init();
-  }
-}
-
-// static
-void
-BluetoothHfpManager::DeinitHfpInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  sBluetoothHfpManager = nullptr;
-
-  /**
-   * TODO:
-   *   Implement DeinitHfpInterface() for applications that want to create SCO
-   *   link without a HFP connection (e.g., VoIP).
-   */
-
-  if (aRes) {
-    aRes->Deinit();
-  }
-}
-
-void
-BluetoothHfpManager::HandleShutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  sInShutdown = true;
-  sBluetoothHfpManager = nullptr;
-}
-
-bool
-BluetoothHfpManager::ConnectSco()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * TODO:
-   *   Implement ConnectSco() for applications that want to create SCO link
-   *   without a HFP connection (e.g., VoIP).
-   */
-  return false;
-}
-
-void
-BluetoothHfpManager::HandleBackendError()
-{
-  /**
-   * TODO:
-   *   Reset connection state and audio state to DISCONNECTED to handle backend
-   *   error. The state change triggers UI status bar update as ordinary
-   *   bluetooth turn-off sequence.
-   */
-}
-
-bool
-BluetoothHfpManager::DisconnectSco()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * TODO:
-   *   Implement DisconnectSco() for applications that want to destroy SCO link
-   *   without a HFP connection (e.g., VoIP).
-   */
-  return false;
-}
-
-void
-BluetoothHfpManager::Reset()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-}
-
-NS_IMPL_ISUPPORTS(BluetoothHfpManager, nsIObserver)
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/hfp-fallback/BluetoothHfpManager.h
+++ /dev/null
@@ -1,51 +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_BluetoothHfpManager_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothHfpManager_h
-
-#include "BluetoothHfpManagerBase.h"
-
-/**
- * Fallback BluetoothHfpManager is built for non-phone devices (e.g., tablets).
- * These devices has no radio interface and the build flag MOZ_B2G_RIL is
- * disabled. To prevent build breaks of accessing radio interface, we implement
- * fallback BluetoothHfpManager with empty functions to keep original
- * BluetoothHfpManager away from numerous #ifdef/#endif statements.
- */
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothHfpManager : public BluetoothHfpManagerBase
-{
-public:
-  BT_DECL_HFP_MGR_BASE
-  virtual void GetName(nsACString& aName)
-  {
-    aName.AssignLiteral("Fallback HFP/HSP");
-  }
-
-  static BluetoothHfpManager* Get();
-  static void InitHfpInterface(BluetoothProfileResultHandler* aRes);
-  static void DeinitHfpInterface(BluetoothProfileResultHandler* aRes);
-
-  bool ConnectSco();
-  bool DisconnectSco();
-  // Handle unexpected backend crash
-  void HandleBackendError();
-
-protected:
-  virtual ~BluetoothHfpManager() { }
-
-private:
-  BluetoothHfpManager() { }
-  bool Init();
-  void HandleShutdown();
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothHfpManager_h
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
+++ /dev/null
@@ -1,1774 +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 "base/basictypes.h"
-
-#include "BluetoothHfpManager.h"
-#include "BluetoothProfileController.h"
-#include "BluetoothUtils.h"
-
-#include "jsapi.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/Services.h"
-#include "mozilla/StaticPtr.h"
-#include "nsContentUtils.h"
-#include "nsIAudioManager.h"
-#include "nsIIccInfo.h"
-#include "nsIIccService.h"
-#include "nsIMobileConnectionInfo.h"
-#include "nsIMobileConnectionService.h"
-#include "nsIMobileNetworkInfo.h"
-#include "nsIObserverService.h"
-#include "nsISettingsService.h"
-#include "nsITelephonyService.h"
-#include "nsServiceManagerUtils.h"
-#include "nsThreadUtils.h"
-#include "mozilla/dom/BindingUtils.h"
-#include "mozilla/dom/SettingChangeNotificationBinding.h"
-
-#define MOZSETTINGS_CHANGED_ID               "mozsettings-changed"
-#define AUDIO_VOLUME_BT_SCO_ID               "audio.volume.bt_sco"
-
-/**
- * Dispatch task with arguments to main thread.
- */
-using namespace mozilla;
-using namespace mozilla::ipc;
-USING_BLUETOOTH_NAMESPACE
-
-namespace {
-  StaticRefPtr<BluetoothHfpManager> sBluetoothHfpManager;
-  static BluetoothHandsfreeInterface* sBluetoothHfpInterface = nullptr;
-
-  bool sInShutdown = false;
-
-  // Wait for 2 seconds for Dialer processing event 'BLDN'. '2' seconds is a
-  // magic number. The mechanism should be revised once we can get call history.
-  static int sWaitingForDialingInterval = 2000; //unit: ms
-
-  // Wait 3.7 seconds until Dialer stops playing busy tone. '3' seconds is the
-  // time window set in Dialer and the extra '0.7' second is a magic number.
-  // The mechanism should be revised once we know the exact time at which
-  // Dialer stops playing.
-  static int sBusyToneInterval = 3700; //unit: ms
-} // namespace
-
-const int BluetoothHfpManager::MAX_NUM_CLIENTS = 1;
-
-static bool
-IsValidDtmf(const char aChar) {
-  // Valid DTMF: [*#0-9ABCD]
-  return (aChar == '*' || aChar == '#') ||
-         (aChar >= '0' && aChar <= '9') ||
-         (aChar >= 'A' && aChar <= 'D');
-}
-
-static bool
-IsSupportedChld(const int aChld) {
-  // We currently only support CHLD=0~3.
-  return (aChld >= 0 && aChld <= 3);
-}
-
-class BluetoothHfpManager::GetVolumeTask final
-  : public nsISettingsServiceCallback
-{
-public:
-  NS_DECL_ISUPPORTS
-
-  NS_IMETHOD
-  Handle(const nsAString& aName, JS::Handle<JS::Value> aResult)
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    JSContext *cx = nsContentUtils::GetCurrentJSContext();
-    NS_ENSURE_TRUE(cx, NS_OK);
-
-    if (!aResult.isNumber()) {
-      BT_WARNING("'" AUDIO_VOLUME_BT_SCO_ID "' is not a number!");
-      return NS_OK;
-    }
-
-    BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-    hfp->mCurrentVgs = aResult.toNumber();
-
-    return NS_OK;
-  }
-
-  NS_IMETHOD
-  HandleError(const nsAString& aName)
-  {
-    BT_WARNING("Unable to get value for '" AUDIO_VOLUME_BT_SCO_ID "'");
-    return NS_OK;
-  }
-
-protected:
-  ~GetVolumeTask() { }
-};
-
-class BluetoothHfpManager::CloseScoTask : public Runnable
-{
-private:
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(sBluetoothHfpManager);
-    sBluetoothHfpManager->DisconnectSco();
-    return NS_OK;
-  }
-};
-
-class BluetoothHfpManager::CloseScoRunnable : public Runnable
-{
-public:
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    MessageLoop::current()->PostDelayedTask(
-      MakeAndAddRef<CloseScoTask>(), sBusyToneInterval);
-
-    return NS_OK;
-  }
-};
-
-class BluetoothHfpManager::RespondToBLDNTask : public Runnable
-{
-private:
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(sBluetoothHfpManager);
-
-    if (!sBluetoothHfpManager->mDialingRequestProcessed) {
-      sBluetoothHfpManager->mDialingRequestProcessed = true;
-      sBluetoothHfpManager->SendResponse(HFP_AT_RESPONSE_ERROR);
-    }
-    return NS_OK;
-  }
-};
-
-NS_IMPL_ISUPPORTS(BluetoothHfpManager::GetVolumeTask,
-                  nsISettingsServiceCallback);
-
-/**
- *  Call
- */
-Call::Call()
-{
-  Reset();
-}
-
-void
-Call::Set(const nsAString& aNumber, const bool aIsOutgoing)
-{
-  mNumber = aNumber;
-  mDirection = (aIsOutgoing) ? HFP_CALL_DIRECTION_OUTGOING :
-                               HFP_CALL_DIRECTION_INCOMING;
-  // Same logic as implementation in ril_worker.js
-  if (aNumber.Length() && aNumber[0] == '+') {
-    mType = HFP_CALL_ADDRESS_TYPE_INTERNATIONAL;
-  } else {
-    mType = HFP_CALL_ADDRESS_TYPE_UNKNOWN;
-  }
-}
-
-void
-Call::Reset()
-{
-  mState = nsITelephonyService::CALL_STATE_DISCONNECTED;
-  mDirection = HFP_CALL_DIRECTION_OUTGOING;
-  mNumber.Truncate();
-  mType = HFP_CALL_ADDRESS_TYPE_UNKNOWN;
-}
-
-bool
-Call::IsActive()
-{
-  return (mState == nsITelephonyService::CALL_STATE_CONNECTED);
-}
-
-/**
- *  BluetoothHfpManager
- */
-BluetoothHfpManager::BluetoothHfpManager() : mPhoneType(PhoneType::NONE)
-{
-  Reset();
-}
-
-void
-BluetoothHfpManager::ResetCallArray()
-{
-  mCurrentCallArray.Clear();
-  // Append a call object at the beginning of mCurrentCallArray since call
-  // index from RIL starts at 1.
-  Call call;
-  mCurrentCallArray.AppendElement(call);
-
-  if (mPhoneType == PhoneType::CDMA) {
-    mCdmaSecondCall.Reset();
-  }
-}
-
-void
-BluetoothHfpManager::Cleanup()
-{
-  mReceiveVgsFlag = false;
-  mDialingRequestProcessed = true;
-
-  mConnectionState = HFP_CONNECTION_STATE_DISCONNECTED;
-  mPrevConnectionState = HFP_CONNECTION_STATE_DISCONNECTED;
-  mBattChg = 5;
-  mService = HFP_NETWORK_STATE_NOT_AVAILABLE;
-  mRoam = HFP_SERVICE_TYPE_HOME;
-  mSignal = 0;
-  mNrecEnabled = HFP_NREC_STARTED;
-
-  mController = nullptr;
-}
-
-void
-BluetoothHfpManager::Reset()
-{
-  // Phone & Device CIND
-  ResetCallArray();
-  // Clear Sco state
-  mAudioState = HFP_AUDIO_STATE_DISCONNECTED;
-  Cleanup();
-}
-
-bool
-BluetoothHfpManager::Init()
-{
-  // The function must run at b2g process since it would access SettingsService.
-  MOZ_ASSERT(XRE_IsParentProcess());
-
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE(obs, false);
-
-  if (NS_FAILED(obs->AddObserver(this, MOZSETTINGS_CHANGED_ID, false)) ||
-      NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
-    BT_WARNING("Failed to add observers!");
-    return false;
-  }
-
-  hal::RegisterBatteryObserver(this);
-  // Update to the latest battery level
-  hal::BatteryInformation batteryInfo;
-  hal::GetCurrentBatteryInformation(&batteryInfo);
-  Notify(batteryInfo);
-
-  mListener = MakeUnique<BluetoothRilListener>();
-  NS_ENSURE_TRUE(mListener->Listen(true), false);
-
-  nsCOMPtr<nsISettingsService> settings =
-    do_GetService("@mozilla.org/settingsService;1");
-  NS_ENSURE_TRUE(settings, false);
-
-  nsCOMPtr<nsISettingsServiceLock> settingsLock;
-  nsresult rv = settings->CreateLock(nullptr, getter_AddRefs(settingsLock));
-  NS_ENSURE_SUCCESS(rv, false);
-
-  RefPtr<GetVolumeTask> callback = new GetVolumeTask();
-  rv = settingsLock->Get(AUDIO_VOLUME_BT_SCO_ID, callback);
-  NS_ENSURE_SUCCESS(rv, false);
-
-  return true;
-}
-
-class BluetoothHfpManager::RegisterModuleResultHandler final
-  : public BluetoothSetupResultHandler
-{
-public:
-  RegisterModuleResultHandler(BluetoothHandsfreeInterface* aInterface,
-                              BluetoothProfileResultHandler* aRes)
-    : mInterface(aInterface)
-    , mRes(aRes)
-  {
-    MOZ_ASSERT(mInterface);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_WARNING("BluetoothSetupInterface::RegisterModule failed for HFP: %d",
-               (int)aStatus);
-
-    mInterface->SetNotificationHandler(nullptr);
-
-    if (mRes) {
-      mRes->OnError(NS_ERROR_FAILURE);
-    }
-  }
-
-  void RegisterModule() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    sBluetoothHfpInterface = mInterface;
-
-    if (mRes) {
-      mRes->Init();
-    }
-  }
-
-private:
-  BluetoothHandsfreeInterface* mInterface;
-  RefPtr<BluetoothProfileResultHandler> mRes;
-};
-
-class BluetoothHfpManager::InitProfileResultHandlerRunnable final
-  : public Runnable
-{
-public:
-  InitProfileResultHandlerRunnable(BluetoothProfileResultHandler* aRes,
-                                   nsresult aRv)
-    : mRes(aRes)
-    , mRv(aRv)
-  {
-    MOZ_ASSERT(mRes);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (NS_SUCCEEDED(mRv)) {
-      mRes->Init();
-    } else {
-      mRes->OnError(mRv);
-    }
-    return NS_OK;
-  }
-
-private:
-  RefPtr<BluetoothProfileResultHandler> mRes;
-  nsresult mRv;
-};
-
-// static
-void
-BluetoothHfpManager::InitHfpInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (sBluetoothHfpInterface) {
-    BT_LOGR("Bluetooth Handsfree interface is already initalized.");
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_OK);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch HFP Init runnable");
-    }
-    return;
-  }
-
-  auto btInf = BluetoothInterface::GetInstance();
-
-  if (NS_WARN_IF(!btInf)) {
-    // If there's no backend interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch HFP OnError runnable");
-    }
-    return;
-  }
-
-  auto setupInterface = btInf->GetBluetoothSetupInterface();
-
-  if (NS_WARN_IF(!setupInterface)) {
-    // If there's no Setup interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch HFP OnError runnable");
-    }
-    return;
-  }
-
-  auto interface = btInf->GetBluetoothHandsfreeInterface();
-
-  if (NS_WARN_IF(!interface)) {
-    // If there's no HFP interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new InitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch HFP OnError runnable");
-    }
-    return;
-  }
-
-  // Set notification handler _before_ registering the module. It could
-  // happen that we receive notifications, before the result handler runs.
-  interface->SetNotificationHandler(BluetoothHfpManager::Get());
-
-  setupInterface->RegisterModule(
-    SETUP_SERVICE_ID_HANDSFREE, MODE_NARROWBAND_SPEECH, MAX_NUM_CLIENTS,
-    new RegisterModuleResultHandler(interface, aRes));
-}
-
-BluetoothHfpManager::~BluetoothHfpManager()
-{
-  if (!mListener->Listen(false)) {
-    BT_WARNING("Failed to stop listening RIL");
-  }
-  mListener = nullptr;
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-
-  if (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) ||
-      NS_FAILED(obs->RemoveObserver(this, MOZSETTINGS_CHANGED_ID))) {
-    BT_WARNING("Failed to remove observers!");
-  }
-
-  hal::UnregisterBatteryObserver(this);
-}
-
-class BluetoothHfpManager::UnregisterModuleResultHandler final
-  : public BluetoothSetupResultHandler
-{
-public:
-  UnregisterModuleResultHandler(BluetoothProfileResultHandler* aRes)
-    : mRes(aRes)
-  { }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_WARNING("BluetoothSetupInterface::UnregisterModule failed for HFP: %d",
-               (int)aStatus);
-
-    sBluetoothHfpInterface->SetNotificationHandler(nullptr);
-    sBluetoothHfpInterface = nullptr;
-    sBluetoothHfpManager = nullptr;
-
-    if (mRes) {
-      mRes->OnError(NS_ERROR_FAILURE);
-    }
-  }
-
-  void UnregisterModule() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    sBluetoothHfpInterface->SetNotificationHandler(nullptr);
-    sBluetoothHfpInterface = nullptr;
-    sBluetoothHfpManager = nullptr;
-
-    if (mRes) {
-      mRes->Deinit();
-    }
-  }
-
-private:
-  RefPtr<BluetoothProfileResultHandler> mRes;
-};
-
-class BluetoothHfpManager::DeinitProfileResultHandlerRunnable final
-  : public Runnable
-{
-public:
-  DeinitProfileResultHandlerRunnable(BluetoothProfileResultHandler* aRes,
-                                     nsresult aRv)
-    : mRes(aRes)
-    , mRv(aRv)
-  {
-    MOZ_ASSERT(mRes);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (NS_SUCCEEDED(mRv)) {
-      mRes->Deinit();
-    } else {
-      mRes->OnError(mRv);
-    }
-    return NS_OK;
-  }
-
-private:
-  RefPtr<BluetoothProfileResultHandler> mRes;
-  nsresult mRv;
-};
-
-// static
-void
-BluetoothHfpManager::DeinitHfpInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!sBluetoothHfpInterface) {
-    BT_LOGR("Bluetooth Handsfree interface has not been initialized.");
-    RefPtr<Runnable> r =
-      new DeinitProfileResultHandlerRunnable(aRes, NS_OK);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch HFP Deinit runnable");
-    }
-    return;
-  }
-
-  auto btInf = BluetoothInterface::GetInstance();
-
-  if (NS_WARN_IF(!btInf)) {
-    // If there's no backend interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new DeinitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch HFP OnError runnable");
-    }
-    return;
-  }
-
-  auto setupInterface = btInf->GetBluetoothSetupInterface();
-
-  if (NS_WARN_IF(!setupInterface)) {
-    // If there's no Setup interface, we dispatch a runnable
-    // that calls the profile result handler.
-    RefPtr<Runnable> r =
-      new DeinitProfileResultHandlerRunnable(aRes, NS_ERROR_FAILURE);
-    if (NS_FAILED(NS_DispatchToMainThread(r))) {
-      BT_LOGR("Failed to dispatch HFP OnError runnable");
-    }
-    return;
-  }
-
-  setupInterface->UnregisterModule(
-    SETUP_SERVICE_ID_HANDSFREE,
-    new UnregisterModuleResultHandler(aRes));
-}
-
-//static
-BluetoothHfpManager*
-BluetoothHfpManager::Get()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // If sBluetoothHfpManager already exists, exit early
-  if (sBluetoothHfpManager) {
-    return sBluetoothHfpManager;
-  }
-
-  // If we're in shutdown, don't create a new instance
-  NS_ENSURE_FALSE(sInShutdown, nullptr);
-
-  // Create a new instance, register, and return
-  BluetoothHfpManager* manager = new BluetoothHfpManager();
-  NS_ENSURE_TRUE(manager->Init(), nullptr);
-
-  sBluetoothHfpManager = manager;
-  return sBluetoothHfpManager;
-}
-
-NS_IMETHODIMP
-BluetoothHfpManager::Observe(nsISupports* aSubject,
-                             const char* aTopic,
-                             const char16_t* aData)
-{
-  if (!strcmp(aTopic, MOZSETTINGS_CHANGED_ID)) {
-    HandleVolumeChanged(aSubject);
-  } else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    HandleShutdown();
-  } else {
-    MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!");
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  return NS_OK;
-}
-
-void
-BluetoothHfpManager::Notify(const hal::BatteryInformation& aBatteryInfo)
-{
-  // Range of battery level: [0, 1], double
-  // Range of CIND::BATTCHG: [0, 5], int
-  mBattChg = (int) round(aBatteryInfo.level() * 5.0);
-  UpdateDeviceCIND();
-}
-
-void
-BluetoothHfpManager::NotifyConnectionStateChanged(const nsAString& aType)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Notify Gecko observers
-  nsCOMPtr<nsIObserverService> obs =
-    do_GetService("@mozilla.org/observer-service;1");
-  NS_ENSURE_TRUE_VOID(obs);
-
-  nsAutoString deviceAddressStr;
-  AddressToString(mDeviceAddress, deviceAddressStr);
-
-  if (NS_FAILED(obs->NotifyObservers(this, NS_ConvertUTF16toUTF8(aType).get(),
-                                     deviceAddressStr.get()))) {
-    BT_WARNING("Failed to notify observsers!");
-  }
-
-  // Dispatch an event of status change
-  bool status;
-  nsAutoString eventName;
-  if (aType.EqualsLiteral(BLUETOOTH_HFP_STATUS_CHANGED_ID)) {
-    status = IsConnected();
-    eventName.AssignLiteral(HFP_STATUS_CHANGED_ID);
-  } else if (aType.EqualsLiteral(BLUETOOTH_SCO_STATUS_CHANGED_ID)) {
-    status = IsScoConnected();
-    eventName.AssignLiteral(SCO_STATUS_CHANGED_ID);
-  } else {
-    MOZ_ASSERT(false);
-    return;
-  }
-
-  DispatchStatusChangedEvent(eventName, mDeviceAddress, status);
-
-  // Notify profile controller
-  if (aType.EqualsLiteral(BLUETOOTH_HFP_STATUS_CHANGED_ID)) {
-    if (IsConnected()) {
-      MOZ_ASSERT(mListener);
-
-      // Enumerate current calls
-      mListener->EnumerateCalls();
-
-      OnConnect(EmptyString());
-    } else if (mConnectionState == HFP_CONNECTION_STATE_DISCONNECTED) {
-      mDeviceAddress.Clear();
-      if (mPrevConnectionState == HFP_CONNECTION_STATE_DISCONNECTED) {
-        // Bug 979160: This implies the outgoing connection failure.
-        // When the outgoing hfp connection fails, state changes to disconnected
-        // state. Since bluedroid would not report connecting state, but only
-        // report connected/disconnected.
-        OnConnect(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
-      } else {
-        OnDisconnect(EmptyString());
-      }
-      Cleanup();
-    }
-  }
-}
-
-void
-BluetoothHfpManager::NotifyDialer(const nsAString& aCommand)
-{
-  NS_NAMED_LITERAL_STRING(type, "bluetooth-dialer-command");
-  InfallibleTArray<BluetoothNamedValue> parameters;
-
-  AppendNamedValue(parameters, "command", nsString(aCommand));
-
-  BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
-}
-
-class BluetoothHfpManager::VolumeControlResultHandler final
-  : public BluetoothHandsfreeResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHandsfreeInterface::VolumeControl failed: %d",
-               (int)aStatus);
-  }
-};
-
-void
-BluetoothHfpManager::HandleVolumeChanged(nsISupports* aSubject)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // The string that we're interested in will be a JSON string that looks like:
-  //  {"key":"volumeup", "value":10}
-  //  {"key":"volumedown", "value":2}
-  RootedDictionary<dom::SettingChangeNotification> setting(RootingCx());
-  if (!WrappedJSToDictionary(aSubject, setting)) {
-    return;
-  }
-  if (!setting.mKey.EqualsASCII(AUDIO_VOLUME_BT_SCO_ID)) {
-    return;
-  }
-  if (!setting.mValue.isNumber()) {
-    return;
-  }
-
-  mCurrentVgs = setting.mValue.toNumber();
-
-  // Adjust volume by headset and we don't have to send volume back to headset
-  if (mReceiveVgsFlag) {
-    mReceiveVgsFlag = false;
-    return;
-  }
-
-  // Only send volume back when there's a connected headset
-  if (IsConnected()) {
-    NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
-    sBluetoothHfpInterface->VolumeControl(
-      HFP_VOLUME_TYPE_SPEAKER, mCurrentVgs, mDeviceAddress,
-      new VolumeControlResultHandler());
-  }
-}
-
-void
-BluetoothHfpManager::HandleVoiceConnectionChanged(uint32_t aClientId)
-{
-  nsCOMPtr<nsIMobileConnectionService> mcService =
-    do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE_VOID(mcService);
-
-  nsCOMPtr<nsIMobileConnection> connection;
-  mcService->GetItemByServiceId(aClientId, getter_AddRefs(connection));
-  NS_ENSURE_TRUE_VOID(connection);
-
-  nsCOMPtr<nsIMobileConnectionInfo> voiceInfo;
-  connection->GetVoice(getter_AddRefs(voiceInfo));
-  NS_ENSURE_TRUE_VOID(voiceInfo);
-
-  nsString type;
-  voiceInfo->GetType(type);
-  mPhoneType = GetPhoneType(type);
-
-  // Roam
-  bool roaming;
-  voiceInfo->GetRoaming(&roaming);
-  mRoam = (roaming) ? HFP_SERVICE_TYPE_ROAMING : HFP_SERVICE_TYPE_HOME;
-
-  // Service
-  nsString regState;
-  voiceInfo->GetState(regState);
-
-  BluetoothHandsfreeNetworkState service =
-    (regState.EqualsLiteral("registered")) ? HFP_NETWORK_STATE_AVAILABLE :
-                                             HFP_NETWORK_STATE_NOT_AVAILABLE;
-  if (service != mService) {
-    // Notify BluetoothRilListener of service change
-    mListener->ServiceChanged(aClientId, service);
-  }
-  mService = service;
-
-  // Signal
-  JS::Rooted<JS::Value> value(dom::RootingCx());
-  voiceInfo->GetRelSignalStrength(&value);
-  if (value.isNumber()) {
-    mSignal = (int)ceil(value.toNumber() / 20.0);
-  }
-
-  UpdateDeviceCIND();
-
-  // Operator name
-  nsCOMPtr<nsIMobileNetworkInfo> network;
-  voiceInfo->GetNetwork(getter_AddRefs(network));
-  if (!network) {
-    BT_LOGD("Unable to get network information");
-    return;
-  }
-  network->GetLongName(mOperatorName);
-
-  // According to GSM 07.07, "<format> indicates if the format is alphanumeric
-  // or numeric; long alphanumeric format can be upto 16 characters long and
-  // short format up to 8 characters (refer GSM MoU SE.13 [9])..."
-  // However, we found that the operator name may sometimes be longer than 16
-  // characters. After discussion, we decided to fix this here but not in RIL
-  // or modem.
-  //
-  // Please see Bug 871366 for more information.
-  if (mOperatorName.Length() > 16) {
-    BT_WARNING("The operator name was longer than 16 characters. We cut it.");
-    mOperatorName.Left(mOperatorName, 16);
-  }
-}
-
-void
-BluetoothHfpManager::HandleIccInfoChanged(uint32_t aClientId)
-{
-  nsCOMPtr<nsIIccService> service =
-    do_GetService(ICC_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE_VOID(service);
-
-  nsCOMPtr<nsIIcc> icc;
-  service->GetIccByServiceId(aClientId, getter_AddRefs(icc));
-  NS_ENSURE_TRUE_VOID(icc);
-
-  nsCOMPtr<nsIIccInfo> iccInfo;
-  icc->GetIccInfo(getter_AddRefs(iccInfo));
-  NS_ENSURE_TRUE_VOID(iccInfo);
-
-  nsCOMPtr<nsIGsmIccInfo> gsmIccInfo = do_QueryInterface(iccInfo);
-  NS_ENSURE_TRUE_VOID(gsmIccInfo);
-  gsmIccInfo->GetMsisdn(mMsisdn);
-}
-
-void
-BluetoothHfpManager::HandleShutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  sInShutdown = true;
-  Disconnect(nullptr);
-  DisconnectSco();
-  sBluetoothHfpManager = nullptr;
-}
-
-class BluetoothHfpManager::ClccResponseResultHandler final
-  : public BluetoothHandsfreeResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHandsfreeInterface::ClccResponse failed: %d",
-               (int)aStatus);
-  }
-};
-
-void
-BluetoothHfpManager::SendCLCC(Call& aCall, int aIndex)
-{
-  NS_ENSURE_TRUE_VOID(aCall.mState !=
-                        nsITelephonyService::CALL_STATE_DISCONNECTED);
-  NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
-
-  BluetoothHandsfreeCallState callState =
-    ConvertToBluetoothHandsfreeCallState(aCall.mState);
-
-  if (mPhoneType == PhoneType::CDMA && aIndex == 1 && aCall.IsActive()) {
-    callState = (mCdmaSecondCall.IsActive()) ? HFP_CALL_STATE_HELD :
-                                               HFP_CALL_STATE_ACTIVE;
-  }
-
-  if (callState == HFP_CALL_STATE_INCOMING &&
-      FindFirstCall(nsITelephonyService::CALL_STATE_CONNECTED)) {
-    callState = HFP_CALL_STATE_WAITING;
-  }
-
-  sBluetoothHfpInterface->ClccResponse(
-    aIndex, aCall.mDirection, callState, HFP_CALL_MODE_VOICE,
-    HFP_CALL_MPTY_TYPE_SINGLE, aCall.mNumber,
-    aCall.mType, mDeviceAddress, new ClccResponseResultHandler());
-}
-
-class BluetoothHfpManager::FormattedAtResponseResultHandler final
-  : public BluetoothHandsfreeResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHandsfreeInterface::FormattedAtResponse failed: %d",
-               (int)aStatus);
-  }
-};
-
-void
-BluetoothHfpManager::SendLine(const char* aMessage)
-{
-  NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
-
-  sBluetoothHfpInterface->FormattedAtResponse(
-    aMessage, mDeviceAddress, new FormattedAtResponseResultHandler());
-}
-
-class BluetoothHfpManager::AtResponseResultHandler final
-  : public BluetoothHandsfreeResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHandsfreeInterface::AtResponse failed: %d",
-               (int)aStatus);
-  }
-};
-
-void
-BluetoothHfpManager::SendResponse(BluetoothHandsfreeAtResponse aResponseCode)
-{
-  NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
-
-  sBluetoothHfpInterface->AtResponse(
-    aResponseCode, 0, mDeviceAddress, new AtResponseResultHandler());
-}
-
-class BluetoothHfpManager::PhoneStateChangeResultHandler final
-  : public BluetoothHandsfreeResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHandsfreeInterface::PhoneStateChange failed: %d",
-               (int)aStatus);
-  }
-};
-
-void
-BluetoothHfpManager::UpdatePhoneCIND(uint32_t aCallIndex)
-{
-  NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
-
-  int numActive = GetNumberOfCalls(nsITelephonyService::CALL_STATE_CONNECTED);
-  int numHeld = GetNumberOfCalls(nsITelephonyService::CALL_STATE_HELD);
-  BluetoothHandsfreeCallState callSetupState =
-    ConvertToBluetoothHandsfreeCallState(GetCallSetupState());
-  BluetoothHandsfreeCallAddressType type = mCurrentCallArray[aCallIndex].mType;
-
-  BT_LOGR("[%d] state %d => BTHF: active[%d] held[%d] setupstate[%d]",
-          aCallIndex, mCurrentCallArray[aCallIndex].mState,
-          numActive, numHeld, callSetupState);
-
-  sBluetoothHfpInterface->PhoneStateChange(
-    numActive, numHeld, callSetupState,
-    mCurrentCallArray[aCallIndex].mNumber, type,
-    new PhoneStateChangeResultHandler());
-}
-
-class BluetoothHfpManager::DeviceStatusNotificationResultHandler final
-  : public BluetoothHandsfreeResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING(
-      "BluetoothHandsfreeInterface::DeviceStatusNotification failed: %d",
-      (int)aStatus);
-  }
-};
-
-void
-BluetoothHfpManager::UpdateDeviceCIND()
-{
-  if (sBluetoothHfpInterface) {
-    sBluetoothHfpInterface->DeviceStatusNotification(
-      mService,
-      mRoam,
-      mSignal,
-      mBattChg, new DeviceStatusNotificationResultHandler());
-  }
-}
-
-uint32_t
-BluetoothHfpManager::FindFirstCall(uint16_t aState)
-{
-  uint32_t callLength = mCurrentCallArray.Length();
-
-  for (uint32_t i = 1; i < callLength; ++i) {
-    if (mCurrentCallArray[i].mState == aState) {
-      return i;
-    }
-  }
-
-  return 0;
-}
-
-uint32_t
-BluetoothHfpManager::GetNumberOfCalls(uint16_t aState)
-{
-  uint32_t num = 0;
-  uint32_t callLength = mCurrentCallArray.Length();
-
-  for (uint32_t i = 1; i < callLength; ++i) {
-    if (mCurrentCallArray[i].mState == aState) {
-      ++num;
-    }
-  }
-
-  return num;
-}
-
-uint16_t
-BluetoothHfpManager::GetCallSetupState()
-{
-  uint32_t callLength = mCurrentCallArray.Length();
-
-  for (uint32_t i = 1; i < callLength; ++i) {
-    switch (mCurrentCallArray[i].mState) {
-      case nsITelephonyService::CALL_STATE_INCOMING:
-      case nsITelephonyService::CALL_STATE_DIALING:
-      case nsITelephonyService::CALL_STATE_ALERTING:
-        return mCurrentCallArray[i].mState;
-      default:
-        break;
-    }
-  }
-
-  return nsITelephonyService::CALL_STATE_DISCONNECTED;
-}
-
-BluetoothHandsfreeCallState
-BluetoothHfpManager::ConvertToBluetoothHandsfreeCallState(int aCallState) const
-{
-  BluetoothHandsfreeCallState state;
-
-  // Refer to AOSP BluetoothPhoneService.convertCallState
-  if (aCallState == nsITelephonyService::CALL_STATE_INCOMING) {
-    state = HFP_CALL_STATE_INCOMING;
-  } else if (aCallState == nsITelephonyService::CALL_STATE_DIALING) {
-    state = HFP_CALL_STATE_DIALING;
-  } else if (aCallState == nsITelephonyService::CALL_STATE_ALERTING) {
-    state = HFP_CALL_STATE_ALERTING;
-  } else if (aCallState == nsITelephonyService::CALL_STATE_CONNECTED) {
-    state = HFP_CALL_STATE_ACTIVE;
-  } else if (aCallState == nsITelephonyService::CALL_STATE_HELD) {
-    state = HFP_CALL_STATE_HELD;
-  } else { // disconnected
-    state = HFP_CALL_STATE_IDLE;
-  }
-
-  return state;
-}
-
-bool
-BluetoothHfpManager::IsTransitionState(uint16_t aCallState, bool aIsConference)
-{
-  /**
-   * Regard this callstate change as during CHLD=2 transition state if
-   * - the call becomes active, and numActive > 1
-   * - the call becomes held, and numHeld > 1 or an incoming call exists
-   *
-   * TODO:
-   * 1) handle CHLD=1 transition state
-   * 2) handle conference call cases
-   */
-  if (!aIsConference) {
-    switch (aCallState) {
-      case nsITelephonyService::CALL_STATE_CONNECTED:
-        return (GetNumberOfCalls(aCallState) > 1);
-      case nsITelephonyService::CALL_STATE_HELD:
-        return (GetNumberOfCalls(aCallState) > 1 ||
-                FindFirstCall(nsITelephonyService::CALL_STATE_INCOMING));
-      default:
-        break;
-    }
-  }
-
-  return false;
-}
-
-void
-BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
-                                            uint16_t aCallState,
-                                            const nsAString& aError,
-                                            const nsAString& aNumber,
-                                            const bool aIsOutgoing,
-                                            const bool aIsConference,
-                                            bool aSend)
-{
-  // aCallIndex can be UINT32_MAX for the pending outgoing call state update.
-  // aCallIndex will be updated again after real call state changes. See Bug
-  // 990467.
-  if (aCallIndex == UINT32_MAX) {
-    return;
-  }
-
-  // Update call state only
-  while (aCallIndex >= mCurrentCallArray.Length()) {
-    Call call;
-    mCurrentCallArray.AppendElement(call);
-  }
-  mCurrentCallArray[aCallIndex].mState = aCallState;
-
-  // Return if SLC is disconnected
-  if (!IsConnected()) {
-    return;
-  }
-
-  // Update call information besides call state
-  mCurrentCallArray[aCallIndex].Set(aNumber, aIsOutgoing);
-
-  // Notify bluedroid of phone state change if this
-  // call state change is not during transition state
-  if (!IsTransitionState(aCallState, aIsConference)) {
-    UpdatePhoneCIND(aCallIndex);
-  }
-
-  switch (aCallState) {
-    case nsITelephonyService::CALL_STATE_DIALING:
-      // We've send Dialer a dialing request and this is the response.
-      if (!mDialingRequestProcessed) {
-        SendResponse(HFP_AT_RESPONSE_OK);
-        mDialingRequestProcessed = true;
-      }
-      break;
-    case nsITelephonyService::CALL_STATE_DISCONNECTED:
-      // -1 is necessary because call 0 is an invalid (padding) call object.
-      if (mCurrentCallArray.Length() - 1 ==
-          GetNumberOfCalls(nsITelephonyService::CALL_STATE_DISCONNECTED)) {
-        // In order to let user hear busy tone via connected Bluetooth headset,
-        // we postpone the timing of dropping SCO.
-        if (aError.EqualsLiteral("BusyError")) {
-          // FIXME: UpdatePhoneCIND later since it causes SCO close but
-          // Dialer is still playing busy tone via HF.
-          NS_DispatchToMainThread(new CloseScoRunnable());
-        }
-
-        ResetCallArray();
-      }
-      break;
-    default:
-      break;
-  }
-}
-
-PhoneType
-BluetoothHfpManager::GetPhoneType(const nsAString& aType)
-{
-  // FIXME: Query phone type from RIL after RIL implements new API (bug 912019)
-  if (aType.EqualsLiteral("gsm") || aType.EqualsLiteral("gprs") ||
-      aType.EqualsLiteral("edge") || aType.EqualsLiteral("umts") ||
-      aType.EqualsLiteral("hspa") || aType.EqualsLiteral("hsdpa") ||
-      aType.EqualsLiteral("hsupa") || aType.EqualsLiteral("hspa+")) {
-    return PhoneType::GSM;
-  } else if (aType.EqualsLiteral("is95a") || aType.EqualsLiteral("is95b") ||
-             aType.EqualsLiteral("1xrtt") || aType.EqualsLiteral("evdo0") ||
-             aType.EqualsLiteral("evdoa") || aType.EqualsLiteral("evdob")) {
-    return PhoneType::CDMA;
-  }
-
-  return PhoneType::NONE;
-}
-
-void
-BluetoothHfpManager::UpdateSecondNumber(const nsAString& aNumber)
-{
-  MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
-
-  // Always regard second call as incoming call since v1.2 RIL
-  // doesn't support outgoing second call in CDMA.
-  mCdmaSecondCall.Set(aNumber, false);
-
-  // FIXME: check CDMA + bluedroid
-  //UpdateCIND(CINDType::CALLSETUP, CallSetupState::INCOMING, true);
-}
-
-void
-BluetoothHfpManager::AnswerWaitingCall()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
-
-  // Pick up second call. First call is held now.
-  mCdmaSecondCall.mState = nsITelephonyService::CALL_STATE_CONNECTED;
-  // FIXME: check CDMA + bluedroid
-  //UpdateCIND(CINDType::CALLSETUP, CallSetupState::NO_CALLSETUP, true);
-
-  //sCINDItems[CINDType::CALLHELD].value = CallHeldState::ONHOLD_ACTIVE;
-  //SendCommand("+CIEV: ", CINDType::CALLHELD);
-}
-
-void
-BluetoothHfpManager::IgnoreWaitingCall()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
-
-  mCdmaSecondCall.Reset();
-  // FIXME: check CDMA + bluedroid
-  //UpdateCIND(CINDType::CALLSETUP, CallSetupState::NO_CALLSETUP, true);
-}
-
-void
-BluetoothHfpManager::ToggleCalls()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
-
-  // Toggle acitve and held calls
-  mCdmaSecondCall.mState = (mCdmaSecondCall.IsActive()) ?
-                             nsITelephonyService::CALL_STATE_HELD :
-                             nsITelephonyService::CALL_STATE_CONNECTED;
-}
-
-/*
- * Reset connection state and audio state to DISCONNECTED to handle backend
- * error. The state change triggers UI status bar update as ordinary bluetooth
- * turn-off sequence.
- */
-void
-BluetoothHfpManager::HandleBackendError()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (mConnectionState != HFP_CONNECTION_STATE_DISCONNECTED) {
-    ConnectionStateNotification(HFP_CONNECTION_STATE_DISCONNECTED,
-                                mDeviceAddress);
-  }
-
-  if (mAudioState != HFP_AUDIO_STATE_DISCONNECTED) {
-    AudioStateNotification(HFP_AUDIO_STATE_DISCONNECTED, mDeviceAddress);
-  }
-}
-
-class BluetoothHfpManager::ConnectAudioResultHandler final
-  : public BluetoothHandsfreeResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHandsfreeInterface::ConnectAudio failed: %d",
-               (int)aStatus);
-  }
-};
-
-bool
-BluetoothHfpManager::ConnectSco()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE(!sInShutdown, false);
-  NS_ENSURE_TRUE(IsConnected() && !IsScoConnected(), false);
-  NS_ENSURE_TRUE(sBluetoothHfpInterface, false);
-
-  sBluetoothHfpInterface->ConnectAudio(mDeviceAddress,
-                                       new ConnectAudioResultHandler());
-
-  return true;
-}
-
-class BluetoothHfpManager::DisconnectAudioResultHandler final
-  : public BluetoothHandsfreeResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHandsfreeInterface::DisconnectAudio failed: %d",
-               (int)aStatus);
-  }
-};
-
-bool
-BluetoothHfpManager::DisconnectSco()
-{
-  NS_ENSURE_TRUE(IsScoConnected(), false);
-  NS_ENSURE_TRUE(sBluetoothHfpInterface, false);
-
-  sBluetoothHfpInterface->DisconnectAudio(mDeviceAddress,
-                                          new DisconnectAudioResultHandler());
-
-  return true;
-}
-
-bool
-BluetoothHfpManager::IsScoConnected()
-{
-  return (mAudioState == HFP_AUDIO_STATE_CONNECTED);
-}
-
-bool
-BluetoothHfpManager::IsConnected()
-{
-  return (mConnectionState == HFP_CONNECTION_STATE_SLC_CONNECTED);
-}
-
-bool
-BluetoothHfpManager::IsNrecEnabled()
-{
-  return mNrecEnabled;
-}
-
-void
-BluetoothHfpManager::OnConnectError()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mController->NotifyCompletion(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
-
-  mController = nullptr;
-  mDeviceAddress.Clear();
-}
-
-class BluetoothHfpManager::ConnectResultHandler final
-  : public BluetoothHandsfreeResultHandler
-{
-public:
-  ConnectResultHandler(BluetoothHfpManager* aHfpManager)
-    : mHfpManager(aHfpManager)
-  {
-    MOZ_ASSERT(mHfpManager);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHandsfreeInterface::Connect failed: %d",
-               (int)aStatus);
-    mHfpManager->OnConnectError();
-  }
-
-private:
-  BluetoothHfpManager* mHfpManager;
-};
-
-void
-BluetoothHfpManager::Connect(const BluetoothAddress& aDeviceAddress,
-                             BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aController && !mController);
-
-  if (sInShutdown) {
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    return;
-  }
-
-  if (!sBluetoothHfpInterface) {
-    BT_LOGR("sBluetoothHfpInterface is null");
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    return;
-  }
-
-  mDeviceAddress = aDeviceAddress;
-  mController = aController;
-
-  sBluetoothHfpInterface->Connect(mDeviceAddress,
-                                  new ConnectResultHandler(this));
-}
-
-void
-BluetoothHfpManager::OnDisconnectError()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  NS_ENSURE_TRUE_VOID(mController);
-
-  mController->NotifyCompletion(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
-}
-
-class BluetoothHfpManager::DisconnectResultHandler final
-  : public BluetoothHandsfreeResultHandler
-{
-public:
-  DisconnectResultHandler(BluetoothHfpManager* aHfpManager)
-    : mHfpManager(aHfpManager)
-  {
-    MOZ_ASSERT(mHfpManager);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHandsfreeInterface::Disconnect failed: %d",
-               (int)aStatus);
-    mHfpManager->OnDisconnectError();
-  }
-
-private:
-  BluetoothHfpManager* mHfpManager;
-};
-
-
-void
-BluetoothHfpManager::Disconnect(BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!mController);
-
-  if (!sBluetoothHfpInterface) {
-    BT_LOGR("sBluetoothHfpInterface is null");
-    if (aController) {
-      aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    }
-    return;
-  }
-
-  mController = aController;
-
-  sBluetoothHfpInterface->Disconnect(mDeviceAddress,
-                                     new DisconnectResultHandler(this));
-}
-
-void
-BluetoothHfpManager::OnConnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  mController->NotifyCompletion(aErrorStr);
-  mController = nullptr;
-}
-
-void
-BluetoothHfpManager::OnDisconnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  mController->NotifyCompletion(aErrorStr);
-  mController = nullptr;
-}
-
-void
-BluetoothHfpManager::OnUpdateSdpRecords(
-  const BluetoothAddress& aDeviceAddress)
-{
-  // Bluedroid handles this part
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothHfpManager::OnGetServiceChannel(
-  const BluetoothAddress& aDeviceAddress,
-  const BluetoothUuid& aServiceUuid,
-  int aChannel)
-{
-  // Bluedroid handles this part
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothHfpManager::GetAddress(BluetoothAddress& aDeviceAddress)
-{
-  aDeviceAddress = mDeviceAddress;
-}
-
-//
-// Bluetooth notifications
-//
-
-void
-BluetoothHfpManager::ConnectionStateNotification(
-  BluetoothHandsfreeConnectionState aState, const BluetoothAddress& aBdAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BT_LOGR("state %d", aState);
-
-  mPrevConnectionState = mConnectionState;
-  mConnectionState = aState;
-
-  if (aState == HFP_CONNECTION_STATE_SLC_CONNECTED) {
-    mDeviceAddress = aBdAddress;
-    NotifyConnectionStateChanged(
-      NS_LITERAL_STRING(BLUETOOTH_HFP_STATUS_CHANGED_ID));
-
-  } else if (aState == HFP_CONNECTION_STATE_DISCONNECTED) {
-    DisconnectSco();
-    NotifyConnectionStateChanged(
-      NS_LITERAL_STRING(BLUETOOTH_HFP_STATUS_CHANGED_ID));
-
-  } else if (aState == HFP_CONNECTION_STATE_CONNECTED) {
-    // Once RFCOMM is connected, enable NREC before each new SLC connection
-    NRECNotification(HFP_NREC_STARTED, mDeviceAddress);
-  }
-}
-
-void
-BluetoothHfpManager::AudioStateNotification(
-  BluetoothHandsfreeAudioState aState, const BluetoothAddress& aBdAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BT_LOGR("state %d", aState);
-
-  mAudioState = aState;
-
-  if (aState == HFP_AUDIO_STATE_CONNECTED ||
-      aState == HFP_AUDIO_STATE_DISCONNECTED) {
-    NotifyConnectionStateChanged(
-      NS_LITERAL_STRING(BLUETOOTH_SCO_STATUS_CHANGED_ID));
-  }
-}
-
-void
-BluetoothHfpManager::AnswerCallNotification(const BluetoothAddress& aBdAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NotifyDialer(NS_LITERAL_STRING("ATA"));
-}
-
-void
-BluetoothHfpManager::HangupCallNotification(const BluetoothAddress& aBdAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NotifyDialer(NS_LITERAL_STRING("CHUP"));
-}
-
-void
-BluetoothHfpManager::VolumeNotification(
-  BluetoothHandsfreeVolumeType aType, int aVolume, const BluetoothAddress& aBdAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE_VOID(aVolume >= 0 && aVolume <= 15);
-
-  if (aType == HFP_VOLUME_TYPE_MICROPHONE) {
-    mCurrentVgm = aVolume;
-  } else if (aType == HFP_VOLUME_TYPE_SPEAKER) {
-    mReceiveVgsFlag = true;
-
-    if (aVolume == mCurrentVgs) {
-      // Keep current volume
-      return;
-    }
-
-    nsString data;
-    data.AppendInt(aVolume);
-
-    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
-    NS_ENSURE_TRUE_VOID(os);
-
-    os->NotifyObservers(nullptr, "bluetooth-volume-change", data.get());
-  }
-}
-
-void
-BluetoothHfpManager::DtmfNotification(char aDtmf, const BluetoothAddress& aBdAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE_VOID(IsValidDtmf(aDtmf));
-
-  nsAutoCString message("VTS=");
-  message += aDtmf;
-  NotifyDialer(NS_ConvertUTF8toUTF16(message));
-}
-
-/**
- * NREC status will be set when:
- * 1. Get an AT command from HF device.
- *    (Bluetooth HFP spec v1.6 merely defines for the "Disable" part.)
- * 2. Once RFCOMM is connected, enable NREC before each new SLC connection.
- */
-void
-BluetoothHfpManager::NRECNotification(BluetoothHandsfreeNRECState aNrec,
-                                      const BluetoothAddress& aBdAddr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Notify Gecko observers
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-
-  mNrecEnabled = static_cast<bool>(aNrec);
-
-  nsAutoString deviceAddressStr;
-  AddressToString(mDeviceAddress, deviceAddressStr);
-
-  // Notify audio manager
-  if (NS_FAILED(obs->NotifyObservers(this,
-                                     BLUETOOTH_HFP_NREC_STATUS_CHANGED_ID,
-                                     deviceAddressStr.get()))) {
-    BT_WARNING("Failed to notify bluetooth-hfp-nrec-status-changed observsers!");
-  }
-
-}
-
-void
-BluetoothHfpManager::CallHoldNotification(BluetoothHandsfreeCallHoldType aChld,
-                                          const BluetoothAddress& aBdAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!IsSupportedChld((int)aChld)) {
-    // We currently don't support Enhanced Call Control.
-    // AT+CHLD=1x and AT+CHLD=2x will be ignored
-    SendResponse(HFP_AT_RESPONSE_ERROR);
-    return;
-  }
-
-  SendResponse(HFP_AT_RESPONSE_OK);
-
-  nsAutoCString message("CHLD=");
-  message.AppendInt((int)aChld);
-  NotifyDialer(NS_ConvertUTF8toUTF16(message));
-}
-
-void BluetoothHfpManager::DialCallNotification(const nsAString& aNumber,
-                                               const BluetoothAddress& aBdAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsCString message = NS_ConvertUTF16toUTF8(aNumber);
-
-  // There are three cases based on aNumber,
-  // 1) Empty value:    Redial, BLDN
-  // 2) >xxx:           Memory dial, ATD>xxx
-  // 3) xxx:            Normal dial, ATDxxx
-  // We need to respond OK/Error for dial requests for every case listed above,
-  // 1) and 2):         Respond in either RespondToBLDNTask or
-  //                    HandleCallStateChanged()
-  // 3):                Respond here
-  if (message.IsEmpty()) {
-    mDialingRequestProcessed = false;
-    NotifyDialer(NS_LITERAL_STRING("BLDN"));
-
-    MessageLoop::current()->PostDelayedTask(MakeAndAddRef<RespondToBLDNTask>(),
-                                            sWaitingForDialingInterval);
-  } else if (message[0] == '>') {
-    mDialingRequestProcessed = false;
-
-    nsAutoCString newMsg("ATD");
-    newMsg += StringHead(message, message.Length() - 1);
-    NotifyDialer(NS_ConvertUTF8toUTF16(newMsg));
-
-    MessageLoop::current()->PostDelayedTask(MakeAndAddRef<RespondToBLDNTask>(),
-                                            sWaitingForDialingInterval);
-  } else {
-    SendResponse(HFP_AT_RESPONSE_OK);
-
-    nsAutoCString newMsg("ATD");
-    newMsg += StringHead(message, message.Length() - 1);
-    NotifyDialer(NS_ConvertUTF8toUTF16(newMsg));
-  }
-}
-
-void
-BluetoothHfpManager::CnumNotification(const BluetoothAddress& aBdAddress)
-{
-  static const uint8_t sAddressType[] {
-    [HFP_CALL_ADDRESS_TYPE_UNKNOWN] = 0x81,
-    [HFP_CALL_ADDRESS_TYPE_INTERNATIONAL] = 0x91 // for completeness
-  };
-
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!mMsisdn.IsEmpty()) {
-    nsAutoCString message("+CNUM: ,\"");
-    message.Append(NS_ConvertUTF16toUTF8(mMsisdn).get());
-    message.AppendLiteral("\",");
-    message.AppendInt(sAddressType[HFP_CALL_ADDRESS_TYPE_UNKNOWN]);
-    message.AppendLiteral(",,4");
-
-    SendLine(message.get());
-  }
-
-  SendResponse(HFP_AT_RESPONSE_OK);
-}
-
-class BluetoothHfpManager::CindResponseResultHandler final
-  : public BluetoothHandsfreeResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHandsfreeInterface::CindResponse failed: %d",
-               (int)aStatus);
-  }
-};
-
-void
-BluetoothHfpManager::CindNotification(const BluetoothAddress& aBdAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
-
-  int numActive = GetNumberOfCalls(nsITelephonyService::CALL_STATE_CONNECTED);
-  int numHeld = GetNumberOfCalls(nsITelephonyService::CALL_STATE_HELD);
-  BluetoothHandsfreeCallState callState =
-    ConvertToBluetoothHandsfreeCallState(GetCallSetupState());
-
-  sBluetoothHfpInterface->CindResponse(
-    mService, numActive, numHeld,
-    callState, mSignal, mRoam, mBattChg,
-    aBdAddress,
-    new CindResponseResultHandler());
-}
-
-class BluetoothHfpManager::CopsResponseResultHandler final
-  : public BluetoothHandsfreeResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    BT_WARNING("BluetoothHandsfreeInterface::CopsResponse failed: %d",
-               (int)aStatus);
-  }
-};
-
-void
-BluetoothHfpManager::CopsNotification(const BluetoothAddress& aBdAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
-
-  sBluetoothHfpInterface->CopsResponse(
-    NS_ConvertUTF16toUTF8(mOperatorName).get(),
-    aBdAddress, new CopsResponseResultHandler());
-}
-
-void
-BluetoothHfpManager::ClccNotification(const BluetoothAddress& aBdAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  uint32_t callNumbers = mCurrentCallArray.Length();
-  uint32_t i;
-  for (i = 1; i < callNumbers; i++) {
-    SendCLCC(mCurrentCallArray[i], i);
-  }
-
-  if (!mCdmaSecondCall.mNumber.IsEmpty()) {
-    MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
-    MOZ_ASSERT(i == 2);
-
-    SendCLCC(mCdmaSecondCall, 2);
-  }
-
-  SendResponse(HFP_AT_RESPONSE_OK);
-}
-
-void
-BluetoothHfpManager::UnknownAtNotification(const nsACString& aAtString,
-                                           const BluetoothAddress& aBdAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BT_LOGR("[%s]", nsCString(aAtString).get());
-
-  SendResponse(HFP_AT_RESPONSE_ERROR);
-}
-
-void
-BluetoothHfpManager::KeyPressedNotification(const BluetoothAddress& aBdAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  bool hasActiveCall =
-    (FindFirstCall(nsITelephonyService::CALL_STATE_CONNECTED) > 0);
-
-  // Refer to AOSP HeadsetStateMachine.processKeyPressed
-  if (FindFirstCall(nsITelephonyService::CALL_STATE_INCOMING)
-      && !hasActiveCall) {
-    /*
-     * Bluetooth HSP spec 4.2.2
-     * There is an incoming call, notify Dialer to pick up the phone call
-     * and SCO will be established after we get the CallStateChanged event
-     * indicating the call is answered successfully.
-     */
-    NotifyDialer(NS_LITERAL_STRING("ATA"));
-  } else if (hasActiveCall) {
-    if (!IsScoConnected()) {
-      /*
-       * Bluetooth HSP spec 4.3
-       * If there's no SCO, set up a SCO link.
-       */
-      ConnectSco();
-    } else {
-      /*
-       * Bluetooth HSP spec 4.5
-       * There are two ways to release SCO: sending CHUP to dialer or closing
-       * SCO socket directly. We notify dialer only if there is at least one
-       * active call.
-       */
-      NotifyDialer(NS_LITERAL_STRING("CHUP"));
-    }
-  } else {
-    // BLDN
-
-    NotifyDialer(NS_LITERAL_STRING("BLDN"));
-
-    MessageLoop::current()->PostDelayedTask(MakeAndAddRef<RespondToBLDNTask>(),
-                                            sWaitingForDialingInterval);
-  }
-}
-
-NS_IMPL_ISUPPORTS(BluetoothHfpManager, nsIObserver)
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h
+++ /dev/null
@@ -1,239 +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_BluetoothHfpManager_h
-#define mozilla_dom_bluetooth_bluedroid_BluetoothHfpManager_h
-
-#include "BluetoothInterface.h"
-#include "BluetoothCommon.h"
-#include "BluetoothHfpManagerBase.h"
-#include "BluetoothRilListener.h"
-#include "BluetoothSocketObserver.h"
-#include "mozilla/ipc/SocketBase.h"
-#include "mozilla/Hal.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothSocket;
-class Call;
-
-/**
- * These costants are defined in 4.33.2 "AT Capabilities Re-Used from GSM 07.07
- * and 3GPP 27.007" in Bluetooth hands-free profile 1.6
- */
-enum BluetoothCmeError {
-  AG_FAILURE = 0,
-  NO_CONNECTION_TO_PHONE = 1,
-  OPERATION_NOT_ALLOWED = 3,
-  OPERATION_NOT_SUPPORTED = 4,
-  PIN_REQUIRED = 5,
-  SIM_NOT_INSERTED = 10,
-  SIM_PIN_REQUIRED = 11,
-  SIM_PUK_REQUIRED = 12,
-  SIM_FAILURE = 13,
-  SIM_BUSY = 14,
-  INCORRECT_PASSWORD = 16,
-  SIM_PIN2_REQUIRED = 17,
-  SIM_PUK2_REQUIRED = 18,
-  MEMORY_FULL = 20,
-  INVALID_INDEX = 21,
-  MEMORY_FAILURE = 23,
-  TEXT_STRING_TOO_LONG = 24,
-  INVALID_CHARACTERS_IN_TEXT_STRING = 25,
-  DIAL_STRING_TOO_LONG = 26,
-  INVALID_CHARACTERS_IN_DIAL_STRING = 27,
-  NO_NETWORK_SERVICE = 30,
-  NETWORK_TIMEOUT = 31,
-  NETWORK_NOT_ALLOWED = 32
-};
-
-enum PhoneType {
-  NONE, // no connection
-  GSM,
-  CDMA
-};
-
-class Call {
-public:
-  Call();
-  void Set(const nsAString& aNumber, const bool aIsOutgoing);
-  void Reset();
-  bool IsActive();
-
-  uint16_t mState;
-  nsString mNumber;
-  BluetoothHandsfreeCallDirection mDirection;
-  BluetoothHandsfreeCallAddressType mType;
-};
-
-class BluetoothHfpManager : public BluetoothHfpManagerBase
-                          , public BluetoothHandsfreeNotificationHandler
-                          , public BatteryObserver
-{
-  enum {
-    MODE_HEADSET = 0x00,
-    MODE_NARROWBAND_SPEECH = 0x01,
-    MODE_NARRAWBAND_WIDEBAND_SPEECH = 0x02
-  };
-
-public:
-  BT_DECL_HFP_MGR_BASE
-
-  static const int MAX_NUM_CLIENTS;
-
-  void OnConnectError();
-  void OnDisconnectError();
-
-  virtual void GetName(nsACString& aName)
-  {
-    aName.AssignLiteral("HFP/HSP");
-  }
-
-  static BluetoothHfpManager* Get();
-  static void InitHfpInterface(BluetoothProfileResultHandler* aRes);
-  static void DeinitHfpInterface(BluetoothProfileResultHandler* aRes);
-
-  bool ConnectSco();
-  bool DisconnectSco();
-
-  /**
-   * @param aSend A boolean indicates whether we need to notify headset or not
-   */
-  void HandleCallStateChanged(uint32_t aCallIndex, uint16_t aCallState,
-                              const nsAString& aError, const nsAString& aNumber,
-                              const bool aIsOutgoing, const bool aIsConference,
-                              bool aSend);
-  void HandleIccInfoChanged(uint32_t aClientId);
-  void HandleVoiceConnectionChanged(uint32_t aClientId);
-
-  // CDMA-specific functions
-  void UpdateSecondNumber(const nsAString& aNumber);
-  void AnswerWaitingCall();
-  void IgnoreWaitingCall();
-  void ToggleCalls();
-
-  // Handle unexpected backend crash
-  void HandleBackendError();
-
-  //
-  // Bluetooth notifications
-  //
-
-  void ConnectionStateNotification(BluetoothHandsfreeConnectionState aState,
-                                   const BluetoothAddress& aBdAddress) override;
-  void AudioStateNotification(BluetoothHandsfreeAudioState aState,
-                              const BluetoothAddress& aBdAddress) override;
-  void AnswerCallNotification(const BluetoothAddress& aBdAddress) override;
-  void HangupCallNotification(const BluetoothAddress& aBdAddress) override;
-  void VolumeNotification(BluetoothHandsfreeVolumeType aType,
-                          int aVolume,
-                          const BluetoothAddress& aBdAddress) override;
-  void DtmfNotification(char aDtmf,
-                        const BluetoothAddress& aBdAddress) override;
-  void NRECNotification(BluetoothHandsfreeNRECState aNrec,
-                        const BluetoothAddress& aBdAddr) override;
-  void CallHoldNotification(BluetoothHandsfreeCallHoldType aChld,
-                            const BluetoothAddress& aBdAddress) override;
-  void DialCallNotification(const nsAString& aNumber,
-                            const BluetoothAddress& aBdAddress) override;
-  void CnumNotification(const BluetoothAddress& aBdAddress) override;
-  void CindNotification(const BluetoothAddress& aBdAddress) override;
-  void CopsNotification(const BluetoothAddress& aBdAddress) override;
-  void ClccNotification(const BluetoothAddress& aBdAddress) override;
-  void UnknownAtNotification(const nsACString& aAtString,
-                             const BluetoothAddress& aBdAddress) override;
-  void KeyPressedNotification(const BluetoothAddress& aBdAddress) override;
-
-protected:
-  virtual ~BluetoothHfpManager();
-
-private:
-  class AtResponseResultHandler;
-  class CindResponseResultHandler;
-  class ConnectAudioResultHandler;
-  class ConnectResultHandler;
-  class CopsResponseResultHandler;
-  class ClccResponseResultHandler;
-  class CloseScoRunnable;
-  class CloseScoTask;
-  class DeinitProfileResultHandlerRunnable;
-  class DeviceStatusNotificationResultHandler;
-  class DisconnectAudioResultHandler;
-  class DisconnectResultHandler;
-  class FormattedAtResponseResultHandler;
-  class GetVolumeTask;
-  class InitProfileResultHandlerRunnable;
-  class MainThreadTask;
-  class PhoneStateChangeResultHandler;
-  class RegisterModuleResultHandler;
-  class RespondToBLDNTask;
-  class UnregisterModuleResultHandler;
-  class VolumeControlResultHandler;
-
-  friend class BluetoothHfpManagerObserver;
-  friend class GetVolumeTask;
-  friend class CloseScoTask;
-  friend class RespondToBLDNTask;
-  friend class MainThreadTask;
-
-  BluetoothHfpManager();
-  bool Init();
-
-  void Cleanup();
-
-  void HandleShutdown();
-  void HandleVolumeChanged(nsISupports* aSubject);
-  void Notify(const hal::BatteryInformation& aBatteryInfo);
-
-  void NotifyConnectionStateChanged(const nsAString& aType);
-  void NotifyDialer(const nsAString& aCommand);
-
-  PhoneType GetPhoneType(const nsAString& aType);
-  void ResetCallArray();
-  uint32_t FindFirstCall(uint16_t aState);
-  uint32_t GetNumberOfCalls(uint16_t aState);
-  uint16_t GetCallSetupState();
-  bool IsTransitionState(uint16_t aCallState, bool aIsConference);
-  BluetoothHandsfreeCallState
-    ConvertToBluetoothHandsfreeCallState(int aCallState) const;
-
-  void UpdatePhoneCIND(uint32_t aCallIndex);
-  void UpdateDeviceCIND();
-  void SendCLCC(Call& aCall, int aIndex);
-  void SendLine(const char* aMessage);
-  void SendResponse(BluetoothHandsfreeAtResponse aResponseCode);
-
-  BluetoothHandsfreeConnectionState mConnectionState;
-  BluetoothHandsfreeConnectionState mPrevConnectionState;
-  BluetoothHandsfreeAudioState mAudioState;
-  // Device CIND
-  int mBattChg;
-  BluetoothHandsfreeNetworkState mService;
-  BluetoothHandsfreeServiceType mRoam;
-  int mSignal;
-
-  int mCurrentVgs;
-  int mCurrentVgm;
-  bool mReceiveVgsFlag;
-  // This flag is for HFP only, not for HSP.
-  bool mDialingRequestProcessed;
-  bool mNrecEnabled;
-  PhoneType mPhoneType;
-  BluetoothAddress mDeviceAddress;
-  nsString mMsisdn;
-  nsString mOperatorName;
-
-  nsTArray<Call> mCurrentCallArray;
-  UniquePtr<BluetoothRilListener> mListener;
-  RefPtr<BluetoothProfileController> mController;
-
-  // CDMA-specific variable
-  Call mCdmaSecondCall;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluedroid_BluetoothHfpManager_h
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothA2dpManager.cpp
+++ /dev/null
@@ -1,396 +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 "base/basictypes.h"
-
-#include "BluetoothA2dpManager.h"
-
-#include "BluetoothCommon.h"
-#include "BluetoothService.h"
-#include "BluetoothSocket.h"
-#include "BluetoothUtils.h"
-
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/Services.h"
-#include "mozilla/StaticPtr.h"
-#include "nsIObserverService.h"
-#include "MainThreadUtils.h"
-
-
-using namespace mozilla;
-USING_BLUETOOTH_NAMESPACE
-
-namespace {
-  StaticRefPtr<BluetoothA2dpManager> sBluetoothA2dpManager;
-  bool sInShutdown = false;
-} // namespace
-
-NS_IMETHODIMP
-BluetoothA2dpManager::Observe(nsISupports* aSubject,
-                              const char* aTopic,
-                              const char16_t* aData)
-{
-  MOZ_ASSERT(sBluetoothA2dpManager);
-
-  if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    HandleShutdown();
-    return NS_OK;
-  }
-
-  MOZ_ASSERT(false, "BluetoothA2dpManager got unexpected topic!");
-  return NS_ERROR_UNEXPECTED;
-}
-
-BluetoothA2dpManager::BluetoothA2dpManager()
-{
-  Reset();
-}
-
-void
-BluetoothA2dpManager::Reset()
-{
-  mA2dpConnected = false;
-  mSinkState = SinkState::SINK_DISCONNECTED;
-  mController = nullptr;
-}
-
-bool
-BluetoothA2dpManager::Init()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE(obs, false);
-  if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
-    BT_WARNING("Failed to add shutdown observer!");
-    return false;
-  }
-
-  return true;
-}
-
-BluetoothA2dpManager::~BluetoothA2dpManager()
-{
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-  if (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID))) {
-    BT_WARNING("Failed to remove shutdown observer!");
-  }
-}
-
-static BluetoothA2dpManager::SinkState
-StatusStringToSinkState(const nsAString& aStatus)
-{
-  BluetoothA2dpManager::SinkState state =
-    BluetoothA2dpManager::SinkState::SINK_UNKNOWN;
-  if (aStatus.EqualsLiteral("disconnected")) {
-    state = BluetoothA2dpManager::SinkState::SINK_DISCONNECTED;
-  } else if (aStatus.EqualsLiteral("connecting")) {
-    state = BluetoothA2dpManager::SinkState::SINK_CONNECTING;
-  } else if (aStatus.EqualsLiteral("connected")) {
-    state = BluetoothA2dpManager::SinkState::SINK_CONNECTED;
-  } else if (aStatus.EqualsLiteral("playing")) {
-    state = BluetoothA2dpManager::SinkState::SINK_PLAYING;
-  } else {
-    BT_WARNING("Unknown sink state");
-  }
-  return state;
-}
-
-//static
-BluetoothA2dpManager*
-BluetoothA2dpManager::Get()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // If sBluetoothA2dpManager already exists, exit early
-  if (sBluetoothA2dpManager) {
-    return sBluetoothA2dpManager;
-  }
-
-  // If we're in shutdown, don't create a new instance
-  NS_ENSURE_FALSE(sInShutdown, nullptr);
-
-  // Create a new instance, register, and return
-  BluetoothA2dpManager* manager = new BluetoothA2dpManager();
-  NS_ENSURE_TRUE(manager->Init(), nullptr);
-
-  sBluetoothA2dpManager = manager;
-  return sBluetoothA2dpManager;
-}
-
-void
-BluetoothA2dpManager::HandleShutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  sInShutdown = true;
-  Disconnect(nullptr);
-  sBluetoothA2dpManager = nullptr;
-}
-
-void
-BluetoothA2dpManager::Connect(const BluetoothAddress& aDeviceAddress,
-                              BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!aDeviceAddress.IsCleared());
-  MOZ_ASSERT(aController && !mController);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs || sInShutdown) {
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    return;
-  }
-
-  if (mA2dpConnected) {
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
-    return;
-  }
-
-  mDeviceAddress = aDeviceAddress;
-  mController = aController;
-
-  nsAutoString deviceAddressStr;
-  AddressToString(aDeviceAddress, deviceAddressStr);
-
-  if (NS_FAILED(bs->SendSinkMessage(deviceAddressStr,
-                                    NS_LITERAL_STRING("Connect")))) {
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    return;
-  }
-}
-
-void
-BluetoothA2dpManager::Disconnect(BluetoothProfileController* aController)
-{
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    if (aController) {
-      aController->NotifyCompletion(
-        NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    }
-    return;
-  }
-
-  if (!mA2dpConnected) {
-    if (aController) {
-      aController->NotifyCompletion(
-        NS_LITERAL_STRING(ERR_ALREADY_DISCONNECTED));
-    }
-    return;
-  }
-
-  MOZ_ASSERT(!mDeviceAddress.IsCleared());
-  MOZ_ASSERT(!mController);
-
-  mController = aController;
-
-  nsAutoString deviceAddressStr;
-  AddressToString(mDeviceAddress, deviceAddressStr);
-
-  if (NS_FAILED(bs->SendSinkMessage(deviceAddressStr,
-                                    NS_LITERAL_STRING("Disconnect")))) {
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    return;
-  }
-}
-
-void
-BluetoothA2dpManager::OnConnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  RefPtr<BluetoothProfileController> controller = mController.forget();
-  controller->NotifyCompletion(aErrorStr);
-}
-
-void
-BluetoothA2dpManager::OnDisconnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  RefPtr<BluetoothProfileController> controller = mController.forget();
-  controller->NotifyCompletion(aErrorStr);
-
-  Reset();
-}
-
-/* HandleSinkPropertyChanged update sink state in A2dp
- *
- * Possible values: "disconnected", "connecting", "connected", "playing"
- *
- * 1. "disconnected" -> "connecting"
- *    Either an incoming or outgoing connection attempt ongoing
- * 2. "connecting" -> "disconnected"
- *    Connection attempt failed
- * 3. "connecting" -> "connected"
- *    Successfully connected
- * 4. "connected" -> "playing"
- *    Audio stream active
- * 5. "playing" -> "connected"
- *    Audio stream suspended
- * 6. "connected" -> "disconnected"
- *    "playing" -> "disconnected"
- *    Disconnected from local or the remote device
- */
-void
-BluetoothA2dpManager::HandleSinkPropertyChanged(const BluetoothSignal& aSignal)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aSignal.value().type() ==
-             BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const nsString& addressStr = aSignal.path();
-
-  BluetoothAddress address;
-  StringToAddress(addressStr, address);
-
-  /**
-   * Update sink property only if
-   * - mDeviceAddress is empty (A2dp is disconnected), or
-   * - this property change is from the connected sink.
-   */
-  NS_ENSURE_TRUE_VOID(mDeviceAddress.IsCleared() || mDeviceAddress == address);
-
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aSignal.value().get_ArrayOfBluetoothNamedValue();
-  MOZ_ASSERT(arr.Length() == 1);
-
-  /**
-   * There are three properties:
-   * - "State": a string
-   * - "Connected": a boolean value
-   * - "Playing": a boolean value
-   *
-   * Note that only "State" is handled in this function.
-   */
-
-  const nsString& name = arr[0].name();
-  NS_ENSURE_TRUE_VOID(name.EqualsLiteral("State"));
-
-  const BluetoothValue& value = arr[0].value();
-  MOZ_ASSERT(value.type() == BluetoothValue::TnsString);
-  SinkState newState = StatusStringToSinkState(value.get_nsString());
-  NS_ENSURE_TRUE_VOID((newState != SinkState::SINK_UNKNOWN) &&
-                      (newState != mSinkState));
-
-  /**
-   * Reject 'connected' state change if bluetooth is already disabled.
-   * Sink state would be reset to 'disconnected' when bluetooth is disabled.
-   *
-   * See bug 984284 for more information about the edge case.
-   */
-  NS_ENSURE_FALSE_VOID(newState == SinkState::SINK_CONNECTED &&
-                       mSinkState == SinkState::SINK_DISCONNECTED);
-
-  SinkState prevState = mSinkState;
-  mSinkState = newState;
-
-  switch(mSinkState) {
-    case SinkState::SINK_CONNECTING:
-      // case 1: Either an incoming or outgoing connection attempt ongoing
-      MOZ_ASSERT(prevState == SinkState::SINK_DISCONNECTED);
-      break;
-    case SinkState::SINK_PLAYING:
-      // case 4: Audio stream active
-      MOZ_ASSERT(prevState == SinkState::SINK_CONNECTED);
-      break;
-    case SinkState::SINK_CONNECTED:
-      // case 5: Audio stream suspended
-      if (prevState == SinkState::SINK_PLAYING) {
-        break;
-      }
-
-      // case 3: Successfully connected
-      MOZ_ASSERT(prevState == SinkState::SINK_CONNECTING);
-
-      mA2dpConnected = true;
-      mDeviceAddress = address;
-      NotifyConnectionStatusChanged();
-
-      OnConnect(EmptyString());
-      break;
-    case SinkState::SINK_DISCONNECTED:
-      // case 2: Connection attempt failed
-      if (prevState == SinkState::SINK_CONNECTING) {
-        OnConnect(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
-        break;
-      }
-
-      // case 6: Disconnected from the remote device
-      MOZ_ASSERT(prevState == SinkState::SINK_CONNECTED ||
-                 prevState == SinkState::SINK_PLAYING);
-
-      mA2dpConnected = false;
-      NotifyConnectionStatusChanged();
-      mDeviceAddress.Clear();
-      OnDisconnect(EmptyString());
-      break;
-    default:
-      break;
-  }
-}
-
-void
-BluetoothA2dpManager::NotifyConnectionStatusChanged()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Notify Gecko observers
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-
-  nsAutoString deviceAddressStr;
-  AddressToString(mDeviceAddress, deviceAddressStr);
-
-  if (NS_FAILED(obs->NotifyObservers(this,
-                                     BLUETOOTH_A2DP_STATUS_CHANGED_ID,
-                                     deviceAddressStr.get()))) {
-    BT_WARNING("Failed to notify bluetooth-a2dp-status-changed observsers!");
-  }
-
-  // Dispatch an event of status change
-  DispatchStatusChangedEvent(
-    NS_LITERAL_STRING(A2DP_STATUS_CHANGED_ID), mDeviceAddress, mA2dpConnected);
-}
-
-void
-BluetoothA2dpManager::OnGetServiceChannel(const BluetoothAddress& aDeviceAddress,
-                                          const BluetoothUuid& aServiceUuid,
-                                          int aChannel)
-{
-}
-
-void
-BluetoothA2dpManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
-{
-}
-
-void
-BluetoothA2dpManager::GetAddress(BluetoothAddress& aDeviceAddress)
-{
-  aDeviceAddress = mDeviceAddress;
-}
-
-bool
-BluetoothA2dpManager::IsConnected()
-{
-  return mA2dpConnected;
-}
-
-NS_IMPL_ISUPPORTS(BluetoothA2dpManager, nsIObserver)
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothA2dpManager.h
+++ /dev/null
@@ -1,60 +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_bluez_BluetoothA2dpManager_h
-#define mozilla_dom_bluetooth_bluez_BluetoothA2dpManager_h
-
-#include "BluetoothCommon.h"
-#include "BluetoothProfileController.h"
-#include "BluetoothProfileManagerBase.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothA2dpManager : public BluetoothProfileManagerBase
-{
-public:
-  BT_DECL_PROFILE_MGR_BASE
-  virtual void GetName(nsACString& aName)
-  {
-    aName.AssignLiteral("A2DP");
-  }
-
-  enum SinkState {
-    SINK_UNKNOWN,
-    SINK_DISCONNECTED,
-    SINK_CONNECTING,
-    SINK_CONNECTED,
-    SINK_PLAYING,
-  };
-
-  static BluetoothA2dpManager* Get();
-
-  // A2DP-specific functions
-  void HandleSinkPropertyChanged(const BluetoothSignal& aSignal);
-
-protected:
-  virtual ~BluetoothA2dpManager();
-
-private:
-  BluetoothA2dpManager();
-  bool Init();
-  void ResetA2dp();
-
-  void HandleShutdown();
-  void NotifyConnectionStatusChanged();
-
-  BluetoothAddress mDeviceAddress;
-  RefPtr<BluetoothProfileController> mController;
-
-  // A2DP data member
-  bool mA2dpConnected;
-  SinkState mSinkState;
-
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluez_BluetoothA2dpManager_h
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothAvrcpManager.cpp
+++ /dev/null
@@ -1,263 +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 "base/basictypes.h"
-
-#include "BluetoothAvrcpManager.h"
-
-#include "BluetoothCommon.h"
-#include "BluetoothService.h"
-#include "BluetoothSocket.h"
-#include "BluetoothUtils.h"
-
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/Services.h"
-#include "mozilla/StaticPtr.h"
-#include "nsIObserverService.h"
-#include "MainThreadUtils.h"
-
-
-using namespace mozilla;
-USING_BLUETOOTH_NAMESPACE
-
-namespace {
-  StaticRefPtr<BluetoothAvrcpManager> sBluetoothAvrcpManager;
-  bool sInShutdown = false;
-} // namespace
-
-NS_IMETHODIMP
-BluetoothAvrcpManager::Observe(nsISupports* aSubject,
-                               const char* aTopic,
-                               const char16_t* aData)
-{
-  MOZ_ASSERT(sBluetoothAvrcpManager);
-
-  if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    HandleShutdown();
-    return NS_OK;
-  }
-
-  MOZ_ASSERT(false, "BluetoothAvrcpManager got unexpected topic!");
-  return NS_ERROR_UNEXPECTED;
-}
-
-BluetoothAvrcpManager::BluetoothAvrcpManager()
-{
-  Reset();
-}
-
-void
-BluetoothAvrcpManager::Reset()
-{
-  mAvrcpConnected = false;
-  mDuration = 0;
-  mMediaNumber = 0;
-  mTotalMediaCount = 0;
-  mPosition = 0;
-  mPlayStatus = ControlPlayStatus::PLAYSTATUS_UNKNOWN;
-}
-
-bool
-BluetoothAvrcpManager::Init()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE(obs, false);
-  if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
-    BT_WARNING("Failed to add shutdown observer!");
-    return false;
-  }
-
-  return true;
-}
-
-BluetoothAvrcpManager::~BluetoothAvrcpManager()
-{
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-  if (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID))) {
-    BT_WARNING("Failed to remove shutdown observer!");
-  }
-}
-
-//static
-BluetoothAvrcpManager*
-BluetoothAvrcpManager::Get()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // If sBluetoothA2dpManager already exists, exit early
-  if (sBluetoothAvrcpManager) {
-    return sBluetoothAvrcpManager;
-  }
-
-  // If we're in shutdown, don't create a new instance
-  NS_ENSURE_FALSE(sInShutdown, nullptr);
-
-  // Create a new instance, register, and return
-  BluetoothAvrcpManager* manager = new BluetoothAvrcpManager();
-  NS_ENSURE_TRUE(manager->Init(), nullptr);
-
-  sBluetoothAvrcpManager = manager;
-  return sBluetoothAvrcpManager;
-}
-
-void
-BluetoothAvrcpManager::HandleShutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  sInShutdown = true;
-  Disconnect(nullptr);
-  sBluetoothAvrcpManager = nullptr;
-}
-
-void
-BluetoothAvrcpManager::Connect(const BluetoothAddress& aDeviceAddress,
-                              BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!aDeviceAddress.IsCleared());
-  MOZ_ASSERT(aController && !mController);
-
-  mDeviceAddress = aDeviceAddress;
-  OnConnect(EmptyString());
-}
-
-void
-BluetoothAvrcpManager::Disconnect(BluetoothProfileController* aController)
-{
-  mDeviceAddress.Clear();
-  OnDisconnect(EmptyString());
-}
-
-void
-BluetoothAvrcpManager::OnConnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  RefPtr<BluetoothProfileController> controller = mController.forget();
-  controller->NotifyCompletion(aErrorStr);
-}
-
-void
-BluetoothAvrcpManager::OnDisconnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  RefPtr<BluetoothProfileController> controller = mController.forget();
-  controller->NotifyCompletion(aErrorStr);
-
-  Reset();
-}
-
-void
-BluetoothAvrcpManager::OnGetServiceChannel(
-  const BluetoothAddress& aDeviceAddress,
-  const BluetoothUuid& aServiceUuid,
-  int aChannel)
-{ }
-
-void
-BluetoothAvrcpManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
-{ }
-
-void
-BluetoothAvrcpManager::GetAddress(BluetoothAddress& aDeviceAddress)
-{
-  aDeviceAddress = mDeviceAddress;
-}
-
-bool
-BluetoothAvrcpManager::IsConnected()
-{
-  return mAvrcpConnected;
-}
-
-void
-BluetoothAvrcpManager::SetConnected(bool aConnected)
-{
-  mAvrcpConnected = aConnected;
-  if (!aConnected) {
-    Reset();
-  }
-}
-
-void
-BluetoothAvrcpManager::UpdateMetaData(const nsAString& aTitle,
-                                      const nsAString& aArtist,
-                                      const nsAString& aAlbum,
-                                      uint64_t aMediaNumber,
-                                      uint64_t aTotalMediaCount,
-                                      uint32_t aDuration)
-{
-  mTitle.Assign(aTitle);
-  mArtist.Assign(aArtist);
-  mAlbum.Assign(aAlbum);
-  mMediaNumber = aMediaNumber;
-  mTotalMediaCount = aTotalMediaCount;
-  mDuration = aDuration;
-}
-
-void
-BluetoothAvrcpManager::UpdatePlayStatus(uint32_t aDuration,
-                                        uint32_t aPosition,
-                                        ControlPlayStatus aPlayStatus)
-{
-  mDuration = aDuration;
-  mPosition = aPosition;
-  mPlayStatus = aPlayStatus;
-}
-
-void
-BluetoothAvrcpManager::GetAlbum(nsAString& aAlbum)
-{
-    aAlbum.Assign(mAlbum);
-}
-
-uint32_t
-BluetoothAvrcpManager::GetDuration()
-{
-  return mDuration;
-}
-
-ControlPlayStatus
-BluetoothAvrcpManager::GetPlayStatus()
-{
-  return mPlayStatus;
-}
-
-uint32_t
-BluetoothAvrcpManager::GetPosition()
-{
-  return mPosition;
-}
-
-uint64_t
-BluetoothAvrcpManager::GetMediaNumber()
-{
-  return mMediaNumber;
-}
-
-void
-BluetoothAvrcpManager::GetTitle(nsAString& aTitle)
-{
-  aTitle.Assign(mTitle);
-}
-
-NS_IMPL_ISUPPORTS(BluetoothAvrcpManager, nsIObserver)
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothAvrcpManager.h
+++ /dev/null
@@ -1,72 +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_bluez_BluetoothAvrcpManager_h
-#define mozilla_dom_bluetooth_bluez_BluetoothAvrcpManager_h
-
-#include "BluetoothCommon.h"
-#include "BluetoothProfileController.h"
-#include "BluetoothProfileManagerBase.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothAvrcpManager : public BluetoothProfileManagerBase
-{
-public:
-  BT_DECL_PROFILE_MGR_BASE
-  virtual void GetName(nsACString& aName)
-  {
-    aName.AssignLiteral("AVRCP");
-  }
-
-  static BluetoothAvrcpManager* Get();
-
-  // AVRCP-specific functions
-  void SetConnected(bool aConnected);
-  void UpdateMetaData(const nsAString& aTitle,
-                      const nsAString& aArtist,
-                      const nsAString& aAlbum,
-                      uint64_t aMediaNumber,
-                      uint64_t aTotalMediaCount,
-                      uint32_t aDuration);
-  void UpdatePlayStatus(uint32_t aDuration,
-                        uint32_t aPosition,
-                        ControlPlayStatus aPlayStatus);
-  void GetAlbum(nsAString& aAlbum);
-  uint32_t GetDuration();
-  ControlPlayStatus GetPlayStatus();
-  uint32_t GetPosition();
-  uint64_t GetMediaNumber();
-  void GetTitle(nsAString& aTitle);
-
-protected:
-  virtual ~BluetoothAvrcpManager();
-
-private:
-  BluetoothAvrcpManager();
-  bool Init();
-
-  void HandleShutdown();
-  void NotifyConnectionStatusChanged();
-
-  BluetoothAddress mDeviceAddress;
-  RefPtr<BluetoothProfileController> mController;
-
-  // AVRCP data member
-  bool mAvrcpConnected;
-  nsString mAlbum;
-  nsString mArtist;
-  nsString mTitle;
-  uint32_t mDuration;
-  uint64_t mMediaNumber;
-  uint64_t mTotalMediaCount;
-  uint32_t mPosition;
-  ControlPlayStatus mPlayStatus;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluez_BluetoothAvrcpManager_h
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothDBusService.cpp
+++ /dev/null
@@ -1,4675 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/*
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-#include "base/basictypes.h"
-#include "BluetoothDBusService.h"
-#include "BluetoothA2dpManager.h"
-#include "BluetoothAvrcpManager.h"
-#include "BluetoothHashKeys.h"
-#include "BluetoothHfpManager.h"
-#include "BluetoothHidManager.h"
-#include "BluetoothOppManager.h"
-#include "BluetoothProfileController.h"
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothUnixSocketConnector.h"
-#include "BluetoothUtils.h"
-#include "BluetoothUuidHelper.h"
-
-#include <cstdio>
-#include <dbus/dbus.h>
-
-#include "nsThreadUtils.h"
-#include "nsDebug.h"
-#include "nsDataHashtable.h"
-#include "mozilla/ArrayUtils.h"
-#include "mozilla/Atomics.h"
-#include "mozilla/ClearOnShutdown.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/Hal.h"
-#include "mozilla/ipc/SocketBase.h"
-#include "mozilla/ipc/DBusUtils.h"
-#include "mozilla/ipc/RawDBusConnection.h"
-#include "mozilla/LazyIdleThread.h"
-#include "mozilla/Monitor.h"
-#include "mozilla/Mutex.h"
-#include "mozilla/StaticMutex.h"
-#include "mozilla/Unused.h"
-
-#if defined(MOZ_WIDGET_GONK)
-#include "cutils/properties.h"
-#include <dlfcn.h>
-#endif
-
-/**
- * Some rules for dealing with memory in DBus:
- * - A DBusError only needs to be deleted if it's been set, not just
- *   initialized. This is why LOG_AND_FREE... is called only when an error is
- *   set, and the macro cleans up the error itself.
- * - A DBusMessage needs to be unrefed when it is newed explicitly. DBusMessages
- *   from signals do not need to be unrefed, as they will be cleaned by DBus
- *   after DBUS_HANDLER_RESULT_HANDLED is returned from the filter.
- */
-
-using namespace mozilla;
-using namespace mozilla::ipc;
-USING_BLUETOOTH_NAMESPACE
-
-#define B2G_AGENT_CAPABILITIES "DisplayYesNo"
-#define DBUS_MANAGER_IFACE BLUEZ_DBUS_BASE_IFC  ".Manager"
-#define DBUS_ADAPTER_IFACE BLUEZ_DBUS_BASE_IFC  ".Adapter"
-#define DBUS_DEVICE_IFACE  BLUEZ_DBUS_BASE_IFC  ".Device"
-#define DBUS_AGENT_IFACE   BLUEZ_DBUS_BASE_IFC  ".Agent"
-#define DBUS_SINK_IFACE    BLUEZ_DBUS_BASE_IFC  ".AudioSink"
-#define DBUS_CTL_IFACE     BLUEZ_DBUS_BASE_IFC  ".Control"
-#define DBUS_INPUT_IFACE   BLUEZ_DBUS_BASE_IFC  ".Input"
-#define BLUEZ_DBUS_BASE_PATH      "/org/bluez"
-#define BLUEZ_DBUS_BASE_IFC       "org.bluez"
-#define BLUEZ_ERROR_IFC           "org.bluez.Error"
-
-#define ERR_A2DP_IS_DISCONNECTED      "A2dpIsDisconnected"
-#define ERR_AVRCP_IS_DISCONNECTED     "AvrcpIsDisconnected"
-
-/**
- * To not lock Bluetooth switch button on Settings UI because of any accident,
- * we will force disabling Bluetooth 5 seconds after the user requesting to
- * turn off Bluetooth.
- */
-#define TIMEOUT_FORCE_TO_DISABLE_BT 5
-#define BT_LAZY_THREAD_TIMEOUT_MS 3000
-
-#ifdef MOZ_WIDGET_GONK
-class Bluedroid
-{
-  struct ScopedDlHandleTraits
-  {
-    typedef void* type;
-    static void* empty()
-    {
-      return nullptr;
-    }
-    static void release(void* handle)
-    {
-      if (!handle) {
-        return;
-      }
-      int res = dlclose(handle);
-      if (res) {
-        BT_WARNING("Failed to close libbluedroid.so: %s", dlerror());
-      }
-    }
-  };
-
-public:
-  Bluedroid()
-  : m_bt_enable(nullptr)
-  , m_bt_disable(nullptr)
-  , m_bt_is_enabled(nullptr)
-  {}
-
-  bool Enable()
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // BT thread
-
-    if (!mHandle && !Init()) {
-      return false;
-    } else if (m_bt_is_enabled() == 1) {
-      return true;
-    }
-    // 0 == success, -1 == error
-    return !m_bt_enable();
-  }
-
-  bool Disable()
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // BT thread
-
-    if (!IsEnabled()) {
-      return true;
-    }
-
-    // TODO: This is the wrong place for handling manager classes
-    BluetoothProfileManagerBase* profile;
-    profile = BluetoothHfpManager::Get();
-    NS_ENSURE_TRUE(profile, false);
-    if (profile->IsConnected()) {
-      profile->Disconnect(nullptr);
-    } else {
-      profile->Reset();
-    }
-
-    profile = BluetoothOppManager::Get();
-    NS_ENSURE_TRUE(profile, false);
-    if (profile->IsConnected()) {
-      profile->Disconnect(nullptr);
-    }
-
-    profile = BluetoothA2dpManager::Get();
-    NS_ENSURE_TRUE(profile, false);
-    if (profile->IsConnected()) {
-      profile->Disconnect(nullptr);
-    } else {
-      profile->Reset();
-    }
-
-    profile = BluetoothHidManager::Get();
-    NS_ENSURE_TRUE(profile, false);
-    if (profile->IsConnected()) {
-      profile->Disconnect(nullptr);
-    } else {
-      profile->Reset();
-    }
-
-    // 0 == success, -1 == error
-    return !m_bt_disable();
-  }
-
-  bool IsEnabled() const
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // BT thread
-
-    if (!mHandle) {
-      return false;
-    }
-    // 1 == enabled, 0 == disabled, -1 == error
-    return m_bt_is_enabled() > 0;
-  }
-
-private:
-  bool Init()
-  {
-    MOZ_ASSERT(!mHandle);
-
-    Scoped<ScopedDlHandleTraits> handle(dlopen("libbluedroid.so", RTLD_LAZY));
-    if (!handle) {
-      BT_WARNING("Failed to open libbluedroid.so: %s", dlerror());
-      return false;
-    }
-    int (*bt_enable)() = (int (*)())dlsym(handle, "bt_enable");
-    if (!bt_enable) {
-      BT_WARNING("Failed to lookup bt_enable: %s", dlerror());
-      return false;
-    }
-    int (*bt_disable)() = (int (*)())dlsym(handle, "bt_disable");
-    if (!bt_disable) {
-      BT_WARNING("Failed to lookup bt_disable: %s", dlerror());
-      return false;
-    }
-    int (*bt_is_enabled)() = (int (*)())dlsym(handle, "bt_is_enabled");
-    if (!bt_is_enabled) {
-      BT_WARNING("Failed to lookup bt_is_enabled: %s", dlerror());
-      return false;
-    }
-
-    m_bt_enable = bt_enable;
-    m_bt_disable = bt_disable;
-    m_bt_is_enabled = bt_is_enabled;
-    mHandle.reset(handle.forget());
-
-    return true;
-  }
-
-  Scoped<ScopedDlHandleTraits> mHandle;
-  int (* m_bt_enable)(void);
-  int (* m_bt_disable)(void);
-  int (* m_bt_is_enabled)(void);
-};
-
-//
-// BT-thread-only variables
-//
-// The variables below must only be accessed from within the BT thread.
-//
-
-static class Bluedroid sBluedroid;
-#endif
-
-//
-// Read-only constants
-//
-// The constants below are read-only and may be accessed from any
-// thread. Most of the contain DBus state or settings, so keep them
-// on the I/O thread if somehow possible.
-//
-
-typedef struct {
-  const char* name;
-  int type;
-} Properties;
-
-static const Properties sDeviceProperties[] = {
-  {"Address", DBUS_TYPE_STRING},
-  {"Name", DBUS_TYPE_STRING},
-  {"Icon", DBUS_TYPE_STRING},
-  {"Class", DBUS_TYPE_UINT32},
-  {"UUIDs", DBUS_TYPE_ARRAY},
-  {"Paired", DBUS_TYPE_BOOLEAN},
-  {"Connected", DBUS_TYPE_BOOLEAN},
-  {"Trusted", DBUS_TYPE_BOOLEAN},
-  {"Blocked", DBUS_TYPE_BOOLEAN},
-  {"Alias", DBUS_TYPE_STRING},
-  {"Nodes", DBUS_TYPE_ARRAY},
-  {"Adapter", DBUS_TYPE_OBJECT_PATH},
-  {"LegacyPairing", DBUS_TYPE_BOOLEAN},
-  {"RSSI", DBUS_TYPE_INT16},
-  {"TX", DBUS_TYPE_UINT32},
-  {"Type", DBUS_TYPE_STRING},
-  {"Broadcaster", DBUS_TYPE_BOOLEAN},
-  {"Services", DBUS_TYPE_ARRAY}
-};
-
-static const Properties sAdapterProperties[] = {
-  {"Address", DBUS_TYPE_STRING},
-  {"Name", DBUS_TYPE_STRING},
-  {"Class", DBUS_TYPE_UINT32},
-  {"Powered", DBUS_TYPE_BOOLEAN},
-  {"Discoverable", DBUS_TYPE_BOOLEAN},
-  {"DiscoverableTimeout", DBUS_TYPE_UINT32},
-  {"Pairable", DBUS_TYPE_BOOLEAN},
-  {"PairableTimeout", DBUS_TYPE_UINT32},
-  {"Discovering", DBUS_TYPE_BOOLEAN},
-  {"Devices", DBUS_TYPE_ARRAY},
-  {"UUIDs", DBUS_TYPE_ARRAY},
-  {"Type", DBUS_TYPE_STRING}
-};
-
-static const Properties sManagerProperties[] = {
-  {"Adapters", DBUS_TYPE_ARRAY},
-};
-
-static const Properties sSinkProperties[] = {
-  {"State", DBUS_TYPE_STRING},
-  {"Connected", DBUS_TYPE_BOOLEAN},
-  {"Playing", DBUS_TYPE_BOOLEAN}
-};
-
-static const Properties sControlProperties[] = {
-  {"Connected", DBUS_TYPE_BOOLEAN}
-};
-
-static const Properties sInputProperties[] = {
-  {"Connected", DBUS_TYPE_BOOLEAN}
-};
-
-static const char* const sBluetoothDBusIfaces[] = {
-  DBUS_MANAGER_IFACE,
-  DBUS_ADAPTER_IFACE,
-  DBUS_DEVICE_IFACE
-};
-
-static const char* const sBluetoothDBusSignals[] = {
-  "type='signal',interface='org.freedesktop.DBus'",
-  "type='signal',interface='org.bluez.Adapter'",
-  "type='signal',interface='org.bluez.Manager'",
-  "type='signal',interface='org.bluez.Device'",
-  "type='signal',interface='org.bluez.Input'",
-  "type='signal',interface='org.bluez.Network'",
-  "type='signal',interface='org.bluez.NetworkServer'",
-  "type='signal',interface='org.bluez.HealthDevice'",
-  "type='signal',interface='org.bluez.AudioSink'",
-  "type='signal',interface='org.bluez.Control'"
-};
-
-// Only A2DP and HID are authorized.
-static const BluetoothServiceClass sAuthorizedServiceClass[] = {
-  BluetoothServiceClass::A2DP,
-  BluetoothServiceClass::HID
-};
-
-/**
- * The adapter name may not be ready whenever event 'AdapterAdded' is received,
- * so we'd like to wait for a bit. Only used on main thread.
- */
-static const int sWaitingForAdapterNameInterval = 1000; // unit: ms
-
-//
-// main-thread-only variables
-//
-// The variables below must be accessed from within the main thread.
-//
-
-// A queue for connect/disconnect request. See Bug 913372 for details.
-static nsTArray<RefPtr<BluetoothProfileController> > sControllerArray;
-
-//
-// I/O-thread-only variables
-//
-// The variables below must be accessed from within the I/O thread.
-//
-
-// The DBus connection to the BlueZ daemon
-static StaticAutoPtr<RawDBusConnection> sDBusConnection;
-
-// Keep the pairing requests.
-static unsigned int sIsPairing = 0;
-
-static nsDataHashtable<BluetoothAddressHashKey, DBusMessage* >* sPairingReqTable;
-
-// The object path of the adapter that should
-// be updated after switching Bluetooth.
-static nsString sAdapterPath;
-
-//
-// The variables below are currently accessed from within multiple
-// threads and should be moved to one specific thread if possible.
-//
-// TODO: Concurrency control is implemented by locking. Maybe there's
-//       a non-blocking way to implement this.
-//
-
-// Disconnect all profiles before turning off Bluetooth. Please see Bug 891257
-// for more details. |sStopBluetoothMonitor| protects access to this variable.
-static int sConnectedDeviceCount = 0;
-static StaticAutoPtr<Monitor> sStopBluetoothMonitor;
-
-// Protects against bug 969447.
-static StaticAutoPtr<Monitor> sGetPropertyMonitor;
-
-typedef void (*UnpackFunc)(DBusMessage*, DBusError*,
-                           BluetoothValue&, nsAString&);
-typedef bool (*FilterFunc)(const BluetoothValue&);
-
-static void
-DispatchToDBusThread(already_AddRefed<Runnable> task)
-{
-  XRE_GetIOMessageLoop()->PostTask(Move(task));
-}
-
-static nsresult
-DispatchToBtThread(nsIRunnable* aRunnable)
-{
-  /* Due to the fact that the startup and shutdown of the Bluetooth
-   * system can take an indefinite amount of time, a separate thread
-   * is used for running blocking calls. The thread is not intended
-   * for regular Bluetooth operations though.
-   */
-  static StaticRefPtr<LazyIdleThread> sBluetoothThread;
-
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!sBluetoothThread) {
-    sBluetoothThread =
-      new LazyIdleThread(BT_LAZY_THREAD_TIMEOUT_MS,
-                         NS_LITERAL_CSTRING("BluetoothDBusService"),
-                         LazyIdleThread::ManualShutdown);
-    ClearOnShutdown(&sBluetoothThread);
-  }
-  return sBluetoothThread->Dispatch(aRunnable, NS_DISPATCH_NORMAL);
-}
-
-static void
-DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable,
-                       const BluetoothValue& aValue,
-                       const nsAString& aErrorStr)
-{
-  if (!aErrorStr.IsEmpty()) {
-    DispatchReplyError(aRunnable, aErrorStr);
-  } else {
-    DispatchReplySuccess(aRunnable, aValue);
-  }
-}
-
-BluetoothDBusService::BluetoothDBusService()
-{
-  sGetPropertyMonitor = new Monitor("BluetoothService.sGetPropertyMonitor");
-  sStopBluetoothMonitor = new Monitor("BluetoothService.sStopBluetoothMonitor");
-}
-
-BluetoothDBusService::~BluetoothDBusService()
-{
-  sStopBluetoothMonitor = nullptr;
-  sGetPropertyMonitor = nullptr;
-}
-
-static nsString
-GetObjectPathFromAddress(const nsAString& aAdapterPath,
-                         const nsAString& aDeviceAddress)
-{
-  // The object path would be like /org/bluez/2906/hci0/dev_00_23_7F_CB_B4_F1,
-  // and the adapter path would be the first part of the object path, according
-  // to the example above, it's /org/bluez/2906/hci0.
-  nsString devicePath(aAdapterPath);
-  devicePath.AppendLiteral("/dev_");
-  devicePath.Append(aDeviceAddress);
-  devicePath.ReplaceChar(':', '_');
-  return devicePath;
-}
-
-static nsString
-GetObjectPathFromAddress(const nsAString& aAdapterPath,
-                         const BluetoothAddress& aDeviceAddress)
-{
-  nsAutoString deviceAddressStr;
-  AddressToString(aDeviceAddress, deviceAddressStr);
-
-  return GetObjectPathFromAddress(aAdapterPath, deviceAddressStr);
-}
-
-static nsString
-GetAddressFromObjectPath(const nsAString& aObjectPath)
-{
-  // The object path would be like /org/bluez/2906/hci0/dev_00_23_7F_CB_B4_F1,
-  // and the adapter path would be the first part of the object path, according
-  // to the example above, it's /org/bluez/2906/hci0.
-  nsString address(aObjectPath);
-  int addressHead = address.RFind("/") + 5;
-
-  MOZ_ASSERT(addressHead + BLUETOOTH_ADDRESS_LENGTH == (int)address.Length());
-
-  address.Cut(0, addressHead);
-  address.ReplaceChar('_', ':');
-
-  return address;
-}
-
-static void
-GetAddressFromObjectPath(const nsAString& aObjectPath,
-                         BluetoothAddress& aAddress)
-{
-  DebugOnly<nsresult> rv =
-    StringToAddress(GetAddressFromObjectPath(aObjectPath), aAddress);
-  MOZ_ASSERT(NS_SUCCEEDED(rv));
-}
-
-static bool
-GetConnectedDevicesFilter(const BluetoothValue& aValue)
-{
-  // We don't have to filter device here
-  return true;
-}
-
-static bool
-GetPairedDevicesFilter(const BluetoothValue& aValue)
-{
-  // Check property 'Paired' and only paired device will be returned
-  if (aValue.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
-    BT_WARNING("Not a BluetoothNamedValue array!");
-    return false;
-  }
-
-  const InfallibleTArray<BluetoothNamedValue>& deviceProperties =
-    aValue.get_ArrayOfBluetoothNamedValue();
-  uint32_t length = deviceProperties.Length();
-  for (uint32_t p = 0; p < length; ++p) {
-    if (deviceProperties[p].name().EqualsLiteral("Paired")) {
-      return deviceProperties[p].value().get_bool();
-    }
-  }
-
-  return false;
-}
-
-class DistributeBluetoothSignalTask : public Runnable
-{
-public:
-  DistributeBluetoothSignalTask(const BluetoothSignal& aSignal)
-    : mSignal(aSignal)
-  {
-  }
-
-  nsresult Run()
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BluetoothService* bs = BluetoothService::Get();
-    NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-    bs->DistributeSignal(mSignal);
-
-    return NS_OK;
-  }
-
-private:
-  BluetoothSignal mSignal;
-};
-
-class ControlPropertyChangedHandler : public Runnable
-{
-public:
-  ControlPropertyChangedHandler(const BluetoothSignal& aSignal)
-    : mSignal(aSignal)
-  {
-  }
-
-  nsresult Run()
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-    if (mSignal.value().type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
-       BT_WARNING("Wrong value type for ControlPropertyChangedHandler");
-       return NS_ERROR_FAILURE;
-    }
-
-    InfallibleTArray<BluetoothNamedValue>& arr =
-      mSignal.value().get_ArrayOfBluetoothNamedValue();
-    MOZ_ASSERT(arr[0].name().EqualsLiteral("Connected"));
-    MOZ_ASSERT(arr[0].value().type() == BluetoothValue::Tbool);
-    bool connected = arr[0].value().get_bool();
-
-    BluetoothAvrcpManager* avrcp = BluetoothAvrcpManager::Get();
-    NS_ENSURE_TRUE(avrcp, NS_ERROR_FAILURE);
-    avrcp->SetConnected(connected);
-    return NS_OK;
-  }
-
-private:
-  BluetoothSignal mSignal;
-};
-
-class SinkPropertyChangedHandler : public Runnable
-{
-public:
-  SinkPropertyChangedHandler(const BluetoothSignal& aSignal)
-    : mSignal(aSignal)
-  {
-  }
-
-  NS_IMETHOD
-  Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-    MOZ_ASSERT(mSignal.name().EqualsLiteral("PropertyChanged"));
-    MOZ_ASSERT(mSignal.value().type() ==
-               BluetoothValue::TArrayOfBluetoothNamedValue);
-
-    // Replace object path with device address
-    nsString address = GetAddressFromObjectPath(mSignal.path());
-    mSignal.path() = address;
-
-    BluetoothA2dpManager* a2dp = BluetoothA2dpManager::Get();
-    NS_ENSURE_TRUE(a2dp, NS_ERROR_FAILURE);
-    a2dp->HandleSinkPropertyChanged(mSignal);
-    return NS_OK;
-  }
-
-private:
-  BluetoothSignal mSignal;
-};
-
-class InputPropertyChangedHandler : public Runnable
-{
-public:
-  InputPropertyChangedHandler(const BluetoothSignal& aSignal)
-    : mSignal(aSignal)
-  {
-  }
-
-  NS_IMETHOD
-  Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-    MOZ_ASSERT(mSignal.name().EqualsLiteral("PropertyChanged"));
-    MOZ_ASSERT(mSignal.value().type() ==
-               BluetoothValue::TArrayOfBluetoothNamedValue);
-
-    // Replace object path with device address
-    nsString address = GetAddressFromObjectPath(mSignal.path());
-    mSignal.path() = address;
-
-    BluetoothHidManager* hid = BluetoothHidManager::Get();
-    NS_ENSURE_TRUE(hid, NS_ERROR_FAILURE);
-    hid->HandleInputPropertyChanged(mSignal);
-    return NS_OK;
-  }
-
-private:
-  BluetoothSignal mSignal;
-};
-
-class TryFiringAdapterAddedTask : public Runnable
-{
-public:
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-    return NS_OK;
-  }
-};
-
-class TryFiringAdapterAddedRunnable : public Runnable
-{
-public:
-  TryFiringAdapterAddedRunnable(bool aDelay)
-    : mDelay(aDelay)
-  { }
-
-  nsresult Run()
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (mDelay) {
-      MessageLoop::current()->
-        PostDelayedTask(MakeAndAddRef<TryFiringAdapterAddedTask>(),
-                        sWaitingForAdapterNameInterval);
-    } else {
-      MessageLoop::current()->
-        PostTask(MakeAndAddRef<TryFiringAdapterAddedTask>());
-    }
-
-    return NS_OK;
-  }
-
-private:
-  bool mDelay;
-};
-
-static bool
-IsDBusMessageError(DBusMessage* aMsg, DBusError* aErr, nsAString& aErrorStr)
-{
-  if (aErr && dbus_error_is_set(aErr)) {
-    aErrorStr = NS_ConvertUTF8toUTF16(aErr->message);
-    LOG_AND_FREE_DBUS_ERROR(aErr);
-    return true;
-  }
-
-  DBusError err;
-  dbus_error_init(&err);
-  if (dbus_message_get_type(aMsg) == DBUS_MESSAGE_TYPE_ERROR) {
-    const char* error_msg;
-    if (!dbus_message_get_args(aMsg, &err, DBUS_TYPE_STRING,
-                               &error_msg, DBUS_TYPE_INVALID) ||
-        !error_msg) {
-      if (dbus_error_is_set(&err)) {
-        aErrorStr = NS_ConvertUTF8toUTF16(err.message);
-        LOG_AND_FREE_DBUS_ERROR(&err);
-        return true;
-      } else {
-        aErrorStr.AssignLiteral("Unknown Error");
-        return true;
-      }
-    } else {
-      aErrorStr = NS_ConvertUTF8toUTF16(error_msg);
-      return true;
-    }
-  }
-  return false;
-}
-
-static void
-UnpackObjectPathMessage(DBusMessage* aMsg, DBusError* aErr,
-                        BluetoothValue& aValue, nsAString& aErrorStr)
-{
-  DBusError err;
-  dbus_error_init(&err);
-  if (!IsDBusMessageError(aMsg, aErr, aErrorStr)) {
-    MOZ_ASSERT(dbus_message_get_type(aMsg) == DBUS_MESSAGE_TYPE_METHOD_RETURN,
-               "Got dbus callback that's not a METHOD_RETURN!");
-    const char* object_path;
-    if (!dbus_message_get_args(aMsg, &err, DBUS_TYPE_OBJECT_PATH,
-                               &object_path, DBUS_TYPE_INVALID) ||
-        !object_path) {
-      if (dbus_error_is_set(&err)) {
-        aErrorStr = NS_ConvertUTF8toUTF16(err.message);
-        LOG_AND_FREE_DBUS_ERROR(&err);
-      }
-    } else {
-      aValue = NS_ConvertUTF8toUTF16(object_path);
-    }
-  }
-}
-
-class PrepareProfileManagersRunnable : public Runnable
-{
-public:
-  nsresult Run()
-  {
-    BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-    if (!hfp || !hfp->Listen()) {
-      BT_WARNING("Failed to start listening for BluetoothHfpManager!");
-      return NS_ERROR_FAILURE;
-    }
-
-    BluetoothOppManager* opp = BluetoothOppManager::Get();
-    if (!opp || !opp->Listen()) {
-      BT_WARNING("Failed to start listening for BluetoothOppManager!");
-      return NS_ERROR_FAILURE;
-    }
-
-    BluetoothA2dpManager* a2dp = BluetoothA2dpManager::Get();
-    NS_ENSURE_TRUE(a2dp, NS_ERROR_FAILURE);
-    a2dp->Reset();
-
-    return NS_OK;
-  }
-};
-
-static void
-RunDBusCallback(DBusMessage* aMsg, void* aBluetoothReplyRunnable,
-                UnpackFunc aFunc)
-{
-#ifdef MOZ_WIDGET_GONK
-  // Due to the fact that we're running two dbus loops on desktop implicitly by
-  // being gtk based, sometimes we'll get signals/reply coming in on the main
-  // thread. There's not a lot we can do about that for the time being and it
-  // (technically) shouldn't hurt anything. However, on gonk, die.
-  MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-#endif
-  RefPtr<BluetoothReplyRunnable> replyRunnable =
-    dont_AddRef(static_cast<BluetoothReplyRunnable*>(aBluetoothReplyRunnable));
-
-  MOZ_ASSERT(replyRunnable, "Callback reply runnable is null!");
-
-  nsAutoString replyError;
-  BluetoothValue v;
-  aFunc(aMsg, nullptr, v, replyError);
-
-  // Bug 941462. When blueZ replys 'I/O error', we treat it as 'internal error'.
-  // This usually happned when the first pairing request has not yet finished,
-  // the second pairing request issued immediately.
-  if (replyError.EqualsLiteral("I/O error")) {
-    replyError.AssignLiteral(ERR_INTERNAL_ERROR);
-  }
-
-  DispatchBluetoothReply(replyRunnable, v, replyError);
-}
-
-static void
-GetObjectPathCallback(DBusMessage* aMsg, void* aBluetoothReplyRunnable)
-{
-  if (sIsPairing) {
-    RunDBusCallback(aMsg, aBluetoothReplyRunnable,
-                    UnpackObjectPathMessage);
-    sIsPairing--;
-  }
-}
-
-static void
-UnpackVoidMessage(DBusMessage* aMsg, DBusError* aErr, BluetoothValue& aValue,
-                  nsAString& aErrorStr)
-{
-  DBusError err;
-  dbus_error_init(&err);
-  if (!IsDBusMessageError(aMsg, aErr, aErrorStr) &&
-      dbus_message_get_type(aMsg) == DBUS_MESSAGE_TYPE_METHOD_RETURN &&
-      !dbus_message_get_args(aMsg, &err, DBUS_TYPE_INVALID)) {
-    if (dbus_error_is_set(&err)) {
-      aErrorStr = NS_ConvertUTF8toUTF16(err.message);
-      LOG_AND_FREE_DBUS_ERROR(&err);
-    }
-  }
-  aValue = aErrorStr.IsEmpty();
-}
-
-static void
-GetVoidCallback(DBusMessage* aMsg, void* aBluetoothReplyRunnable)
-{
-  RunDBusCallback(aMsg, aBluetoothReplyRunnable,
-                  UnpackVoidMessage);
-}
-
-class ReplyErrorToProfileManager : public Runnable
-{
-public:
-  ReplyErrorToProfileManager(BluetoothServiceClass aServiceClass,
-                             bool aConnect,
-                             const nsAString& aErrorString)
-    : mServiceClass(aServiceClass)
-    , mConnect(aConnect)
-    , mErrorString(aErrorString)
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-  }
-
-  nsresult Run()
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BluetoothProfileManagerBase* profile;
-    if (mServiceClass == BluetoothServiceClass::HID) {
-      profile = BluetoothHidManager::Get();
-    } else if (mServiceClass == BluetoothServiceClass::A2DP) {
-      profile = BluetoothA2dpManager::Get();
-    } else {
-      MOZ_ASSERT(false);
-      return NS_ERROR_FAILURE;
-    }
-
-    if (mConnect) {
-      profile->OnConnect(mErrorString);
-    } else {
-      profile->OnDisconnect(mErrorString);
-    }
-
-    return NS_OK;
-  }
-
-private:
-  BluetoothServiceClass mServiceClass;
-  bool mConnect;
-  nsString mErrorString;
-};
-
-static void
-CheckDBusReply(DBusMessage* aMsg, void* aServiceClass, bool aConnect)
-{
-  MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-  NS_ENSURE_TRUE_VOID(aMsg);
-
-  BluetoothValue v;
-  nsAutoString replyError;
-  UnpackVoidMessage(aMsg, nullptr, v, replyError);
-
-  BluetoothServiceClass serviceClass =
-    static_cast<BluetoothServiceClass>(NS_PTR_TO_INT32(aServiceClass));
-
-  if (!replyError.IsEmpty()) {
-    NS_DispatchToMainThread(
-      new ReplyErrorToProfileManager(serviceClass, aConnect, replyError));
-  }
-}
-
-static void
-InputConnectCallback(DBusMessage* aMsg, void* aParam)
-{
-  CheckDBusReply(aMsg, aParam, true);
-}
-
-static void
-InputDisconnectCallback(DBusMessage* aMsg, void* aParam)
-{
-  CheckDBusReply(aMsg, aParam, false);
-}
-
-static void
-SinkConnectCallback(DBusMessage* aMsg, void* aParam)
-{
-  CheckDBusReply(aMsg, aParam, true);
-}
-
-static void
-SinkDisconnectCallback(DBusMessage* aMsg, void* aParam)
-{
-  CheckDBusReply(aMsg, aParam, false);
-}
-
-static bool
-HasAudioService(uint32_t aCodValue)
-{
-  return ((aCodValue & 0x200000) == 0x200000);
-}
-
-static bool
-ContainsIcon(const InfallibleTArray<BluetoothNamedValue>& aProperties)
-{
-  for (uint8_t i = 0; i < aProperties.Length(); i++) {
-    if (aProperties[i].name().EqualsLiteral("Icon")) {
-      return true;
-    }
-  }
-  return false;
-}
-
-static bool
-GetProperty(DBusMessageIter aIter, const Properties* aPropertyTypes,
-            int aPropertyTypeLen, int* aPropIndex,
-            InfallibleTArray<BluetoothNamedValue>& aProperties)
-{
-  /**
-   * Ensure GetProperty runs in critical section otherwise
-   * crash due to timing issue occurs when BT is enabled.
-   *
-   * TODO: Revise GetProperty to solve the crash
-   */
-  MonitorAutoLock lock(*sGetPropertyMonitor);
-
-  DBusMessageIter prop_val, array_val_iter;
-  char* property = nullptr;
-  uint32_t array_type;
-  int i, expectedType, receivedType;
-
-  if (dbus_message_iter_get_arg_type(&aIter) != DBUS_TYPE_STRING) {
-    return false;
-  }
-
-  dbus_message_iter_get_basic(&aIter, &property);
-
-  if (!dbus_message_iter_next(&aIter) ||
-      dbus_message_iter_get_arg_type(&aIter) != DBUS_TYPE_VARIANT) {
-    return false;
-  }
-
-  for (i = 0; i < aPropertyTypeLen; i++) {
-    if (!strncmp(property, aPropertyTypes[i].name, strlen(property))) {
-      break;
-    }
-  }
-
-  if (i == aPropertyTypeLen) {
-    BT_LOGR("unknown property: %s", property);
-    return false;
-  }
-
-  nsAutoString propertyName;
-  propertyName.AssignASCII(aPropertyTypes[i].name);
-  *aPropIndex = i;
-
-  // Preprocessing
-  dbus_message_iter_recurse(&aIter, &prop_val);
-  expectedType = aPropertyTypes[*aPropIndex].type;
-  receivedType = dbus_message_iter_get_arg_type(&prop_val);
-
-  /**
-   * Bug 857896. Since device property "Connected" could be a boolean value or
-   * an 2-byte array, we need to check the value type here and convert the
-   * first byte into a boolean manually.
-   */
-  bool convert = false;
-  if (propertyName.EqualsLiteral("Connected") &&
-      receivedType == DBUS_TYPE_ARRAY) {
-    MOZ_ASSERT(aPropertyTypes == sDeviceProperties);
-    convert = true;
-  }
-
-  if ((receivedType != expectedType) && !convert) {
-    BT_WARNING("Iterator not type we expect! Property name: %s,"
-      "Property Type Expected: %d, Property Type Received: %d",
-      NS_ConvertUTF16toUTF8(propertyName).get(), expectedType, receivedType);
-    return false;
-  }
-
-  // Extract data
-  BluetoothValue propertyValue;
-  switch (receivedType) {
-    case DBUS_TYPE_STRING:
-    case DBUS_TYPE_OBJECT_PATH:
-      const char* c;
-      dbus_message_iter_get_basic(&prop_val, &c);
-      propertyValue = NS_ConvertUTF8toUTF16(c);
-      break;
-    case DBUS_TYPE_UINT32:
-    case DBUS_TYPE_INT16:
-      uint32_t i;
-      dbus_message_iter_get_basic(&prop_val, &i);
-      propertyValue = i;
-      break;
-    case DBUS_TYPE_BOOLEAN:
-      bool b;
-      dbus_message_iter_get_basic(&prop_val, &b);
-      propertyValue = b;
-      break;
-    case DBUS_TYPE_ARRAY:
-      dbus_message_iter_recurse(&prop_val, &array_val_iter);
-      array_type = dbus_message_iter_get_arg_type(&array_val_iter);
-      if (array_type == DBUS_TYPE_OBJECT_PATH ||
-          array_type == DBUS_TYPE_STRING) {
-        InfallibleTArray<nsString> arr;
-        do {
-          const char* tmp;
-          dbus_message_iter_get_basic(&array_val_iter, &tmp);
-          nsAutoString s;
-          s = NS_ConvertUTF8toUTF16(tmp);
-          arr.AppendElement(s);
-        } while (dbus_message_iter_next(&array_val_iter));
-        propertyValue = arr;
-      } else if (array_type == DBUS_TYPE_BYTE) {
-        InfallibleTArray<uint8_t> arr;
-        do {
-          uint8_t tmp;
-          dbus_message_iter_get_basic(&array_val_iter, &tmp);
-          arr.AppendElement(tmp);
-        } while (dbus_message_iter_next(&array_val_iter));
-        propertyValue = arr;
-      } else {
-        // This happens when the array is 0-length. Apparently we get a
-        // DBUS_TYPE_INVALID type.
-        propertyValue = InfallibleTArray<nsString>();
-      }
-      break;
-    default:
-      NS_NOTREACHED("Cannot find dbus message type!");
-  }
-
-  // Postprocessing
-  if (convert) {
-    MOZ_ASSERT(propertyValue.type() == BluetoothValue::TArrayOfuint8_t);
-
-    bool b = propertyValue.get_ArrayOfuint8_t()[0];
-    propertyValue = BluetoothValue(b);
-  } else if (propertyName.EqualsLiteral("Devices")) {
-    MOZ_ASSERT(aPropertyTypes == sAdapterProperties);
-    MOZ_ASSERT(propertyValue.type() == BluetoothValue::TArrayOfnsString);
-
-    uint32_t length = propertyValue.get_ArrayOfnsString().Length();
-    for (uint32_t i= 0; i < length; i++) {
-      nsString& data = propertyValue.get_ArrayOfnsString()[i];
-      data = GetAddressFromObjectPath(data);
-    }
-  }
-
-  aProperties.AppendElement(BluetoothNamedValue(propertyName, propertyValue));
-  return true;
-}
-
-static void
-ParseProperties(DBusMessageIter* aIter,
-                BluetoothValue& aValue,
-                nsAString& aErrorStr,
-                const Properties* aPropertyTypes,
-                const int aPropertyTypeLen)
-{
-  DBusMessageIter dict_entry, dict;
-  int prop_index = -1;
-
-  MOZ_ASSERT(dbus_message_iter_get_arg_type(aIter) == DBUS_TYPE_ARRAY,
-             "Trying to parse a property from sth. that's not an array");
-
-  dbus_message_iter_recurse(aIter, &dict);
-  InfallibleTArray<BluetoothNamedValue> props;
-  do {
-    MOZ_ASSERT(dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY,
-               "Trying to parse a property from sth. that's not an dict!");
-    dbus_message_iter_recurse(&dict, &dict_entry);
-
-    if (!GetProperty(dict_entry, aPropertyTypes, aPropertyTypeLen, &prop_index,
-                     props)) {
-      aErrorStr.AssignLiteral("Can't Create Property!");
-      BT_WARNING("Can't create property!");
-      return;
-    }
-  } while (dbus_message_iter_next(&dict));
-
-  aValue = props;
-}
-
-static bool
-UnpackPropertiesMessage(DBusMessage* aMsg, DBusError* aErr,
-                        BluetoothValue& aValue, const char* aIface)
-{
-  MOZ_ASSERT(aMsg);
-
-  const Properties* propertyTypes;
-  int propertyTypesLength;
-
-  nsAutoString errorStr;
-  if (IsDBusMessageError(aMsg, aErr, errorStr) ||
-      dbus_message_get_type(aMsg) != DBUS_MESSAGE_TYPE_METHOD_RETURN) {
-    BT_WARNING("dbus message has an error.");
-    return false;
-  }
-
-  DBusMessageIter iter;
-  if (!dbus_message_iter_init(aMsg, &iter)) {
-    BT_WARNING("Cannot create dbus message iter!");
-    return false;
-  }
-
-  if (!strcmp(aIface, DBUS_DEVICE_IFACE)) {
-    propertyTypes = sDeviceProperties;
-    propertyTypesLength = ArrayLength(sDeviceProperties);
-  } else if (!strcmp(aIface, DBUS_ADAPTER_IFACE)) {
-    propertyTypes = sAdapterProperties;
-    propertyTypesLength = ArrayLength(sAdapterProperties);
-  } else if (!strcmp(aIface, DBUS_MANAGER_IFACE)) {
-    propertyTypes = sManagerProperties;
-    propertyTypesLength = ArrayLength(sManagerProperties);
-  } else {
-    return false;
-  }
-
-  ParseProperties(&iter, aValue, errorStr, propertyTypes,
-                  propertyTypesLength);
-  return true;
-}
-
-static void
-ParsePropertyChange(DBusMessage* aMsg, BluetoothValue& aValue,
-                    nsAString& aErrorStr, const Properties* aPropertyTypes,
-                    const int aPropertyTypeLen)
-{
-  DBusMessageIter iter;
-  DBusError err;
-  int prop_index = -1;
-  InfallibleTArray<BluetoothNamedValue> props;
-
-  dbus_error_init(&err);
-  if (!dbus_message_iter_init(aMsg, &iter)) {
-    BT_WARNING("Can't create iterator!");
-    return;
-  }
-
-  if (!GetProperty(iter, aPropertyTypes, aPropertyTypeLen,
-                   &prop_index, props)) {
-    BT_WARNING("Can't get property!");
-    aErrorStr.AssignLiteral("Can't get property!");
-    return;
-  }
-  aValue = props;
-}
-
-class AppendDeviceNameReplyHandler: public DBusReplyHandler
-{
-public:
-  AppendDeviceNameReplyHandler(const nsCString& aIface,
-                               const nsString& aDevicePath,
-                               const BluetoothSignal& aSignal)
-    : mIface(aIface)
-    , mDevicePath(aDevicePath)
-    , mSignal(aSignal)
-  {
-    MOZ_ASSERT(!mIface.IsEmpty());
-    MOZ_ASSERT(!mDevicePath.IsEmpty());
-  }
-
-  void Handle(DBusMessage* aReply) override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-    if (!aReply || (dbus_message_get_type(aReply) == DBUS_MESSAGE_TYPE_ERROR)) {
-      return;
-    }
-
-    // Get device properties from result of GetProperties
-
-    DBusError err;
-    dbus_error_init(&err);
-
-    BluetoothValue deviceProperties;
-
-    bool success = UnpackPropertiesMessage(aReply, &err, deviceProperties,
-                                           mIface.get());
-    if (!success) {
-      BT_WARNING("Failed to get device properties");
-      return;
-    }
-
-    // First we replace object path with device address.
-
-    InfallibleTArray<BluetoothNamedValue>& parameters =
-      mSignal.value().get_ArrayOfBluetoothNamedValue();
-    nsString address =
-      GetAddressFromObjectPath(mDevicePath);
-    parameters[0].name().AssignLiteral("address");
-    parameters[0].value() = address;
-
-    // Then we append the device's name to the original signal's data.
-
-    InfallibleTArray<BluetoothNamedValue>& properties =
-      deviceProperties.get_ArrayOfBluetoothNamedValue();
-    uint32_t i;
-    for (i = 0; i < properties.Length(); i++) {
-      if (properties[i].name().EqualsLiteral("Name")) {
-        properties[i].name().AssignLiteral("name");
-        parameters.AppendElement(properties[i]);
-        break;
-      }
-    }
-    MOZ_ASSERT(i != properties.Length(), "failed to get device name");
-
-    RefPtr<DistributeBluetoothSignalTask> task =
-      new DistributeBluetoothSignalTask(mSignal);
-    NS_DispatchToMainThread(task);
-  }
-
-private:
-  nsCString mIface;
-  nsString mDevicePath;
-  BluetoothSignal mSignal;
-};
-
-static void
-AppendDeviceName(BluetoothSignal& aSignal)
-{
-  MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-  MOZ_ASSERT(sDBusConnection);
-
-  BluetoothValue v = aSignal.value();
-  if (v.type() != BluetoothValue::TArrayOfBluetoothNamedValue ||
-      v.get_ArrayOfBluetoothNamedValue().Length() == 0) {
-    BT_WARNING("Invalid argument type for AppendDeviceNameRunnable");
-    return;
-  }
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    v.get_ArrayOfBluetoothNamedValue();
-
-  // Device object path should be put in the first element
-  if (!arr[0].name().EqualsLiteral("path") ||
-       arr[0].value().type() != BluetoothValue::TnsString) {
-    BT_WARNING("Invalid object path for AppendDeviceNameRunnable");
-    return;
-  }
-
-  nsString devicePath = arr[0].value().get_nsString();
-
-  RefPtr<AppendDeviceNameReplyHandler> handler =
-    new AppendDeviceNameReplyHandler(nsCString(DBUS_DEVICE_IFACE),
-                                     devicePath, aSignal);
-
-  bool success = sDBusConnection->SendWithReply(
-    AppendDeviceNameReplyHandler::Callback, handler.get(), 1000,
-    BLUEZ_DBUS_BASE_IFC, NS_ConvertUTF16toUTF8(devicePath).get(),
-    DBUS_DEVICE_IFACE, "GetProperties", DBUS_TYPE_INVALID);
-
-  NS_ENSURE_TRUE_VOID(success);
-
-  Unused << handler.forget(); // picked up by callback handler
-}
-
-class SetPairingConfirmationTask : public Runnable
-{
-public:
-  SetPairingConfirmationTask(const BluetoothAddress& aDeviceAddress,
-                             bool aConfirm,
-                             BluetoothReplyRunnable* aRunnable)
-    : mDeviceAddress(aDeviceAddress)
-    , mConfirm(aConfirm)
-    , mRunnable(aRunnable)
-  {
-    MOZ_ASSERT(!mDeviceAddress.IsCleared());
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-
-    nsAutoString errorStr;
-    BluetoothValue v = true;
-    DBusMessage *msg = nullptr;
-
-    if (!sPairingReqTable->Get(mDeviceAddress, &msg) && mRunnable) {
-      BT_WARNING("%s: Couldn't get original request message.", __FUNCTION__);
-      errorStr.AssignLiteral("Couldn't get original request message.");
-      DispatchBluetoothReply(mRunnable, v, errorStr);
-
-      return NS_OK;
-    }
-
-    DBusMessage *reply;
-
-    if (mConfirm) {
-      reply = dbus_message_new_method_return(msg);
-    } else {
-      reply = dbus_message_new_error(msg, "org.bluez.Error.Rejected",
-                                     "User rejected confirmation");
-    }
-
-    if (!reply) {
-      BT_WARNING("%s: Memory can't be allocated for the message.", __FUNCTION__);
-      dbus_message_unref(msg);
-      errorStr.AssignLiteral("Memory can't be allocated for the message.");
-      if (mRunnable) {
-        DispatchBluetoothReply(mRunnable, v, errorStr);
-      }
-      return NS_OK;
-    }
-
-    bool result = sDBusConnection->Send(reply);
-    if (!result) {
-      errorStr.AssignLiteral("Can't send message!");
-    }
-
-    dbus_message_unref(msg);
-    dbus_message_unref(reply);
-    sPairingReqTable->Remove(mDeviceAddress);
-    if (mRunnable) {
-      DispatchBluetoothReply(mRunnable, v, errorStr);
-    }
-    return NS_OK;
-  }
-
-private:
-  BluetoothAddress mDeviceAddress;
-  bool mConfirm;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-};
-
-static DBusHandlerResult
-AgentEventFilter(DBusConnection *conn, DBusMessage *msg, void *data)
-{
-  if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_METHOD_CALL) {
-    BT_WARNING("%s: agent handler not interested (not a method call).\n",
-               __FUNCTION__);
-    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-  }
-
-  DBusError err;
-  dbus_error_init(&err);
-
-  BT_LOGD("%s: %s, %s", __FUNCTION__,
-                       dbus_message_get_path(msg),
-                       dbus_message_get_member(msg));
-
-  nsString signalPath = NS_ConvertUTF8toUTF16(dbus_message_get_path(msg));
-  nsString signalName = NS_ConvertUTF8toUTF16(dbus_message_get_member(msg));
-  nsString errorStr;
-  BluetoothValue v;
-  InfallibleTArray<BluetoothNamedValue> parameters;
-  bool isPairingReq = false;
-  BluetoothSignal signal(signalName, signalPath, v);
-  char *objectPath;
-
-  // The following descriptions of each signal are retrieved from:
-  //
-  // http://maemo.org/api_refs/5.0/beta/bluez/agent.html
-  //
-  if (dbus_message_is_method_call(msg, DBUS_AGENT_IFACE, "Cancel")) {
-    // This method gets called to indicate that the agent request failed before
-    // a reply was returned.
-
-    // Return directly
-    DBusMessage *reply = dbus_message_new_method_return(msg);
-
-    if (!reply) {
-      errorStr.AssignLiteral("Memory can't be allocated for the message.");
-      goto handle_error;
-    }
-
-    dbus_connection_send(conn, reply, nullptr);
-    dbus_message_unref(reply);
-    v = parameters;
-  } else if (dbus_message_is_method_call(msg, DBUS_AGENT_IFACE, "Authorize")) {
-    // This method gets called when the service daemon needs to authorize a
-    // connection/service request.
-    const char *uuid;
-    if (!dbus_message_get_args(msg, nullptr,
-                               DBUS_TYPE_OBJECT_PATH, &objectPath,
-                               DBUS_TYPE_STRING, &uuid,
-                               DBUS_TYPE_INVALID)) {
-      errorStr.AssignLiteral("Invalid arguments for Authorize() method");
-      goto handle_error;
-    }
-
-    NS_ConvertUTF8toUTF16 uuidStr(uuid);
-    BluetoothServiceClass serviceClass =
-      BluetoothUuidHelper::GetBluetoothServiceClass(uuidStr);
-    if (serviceClass == BluetoothServiceClass::UNKNOWN) {
-      errorStr.AssignLiteral("Failed to get service class");
-      goto handle_error;
-    }
-
-    DBusMessage* reply = nullptr;
-    uint32_t i;
-    for (i = 0; i < MOZ_ARRAY_LENGTH(sAuthorizedServiceClass); i++) {
-      if (serviceClass == sAuthorizedServiceClass[i]) {
-        reply = dbus_message_new_method_return(msg);
-        break;
-      }
-    }
-
-    // The uuid isn't authorized
-    if (i == MOZ_ARRAY_LENGTH(sAuthorizedServiceClass)) {
-      BT_WARNING("Uuid is not authorized.");
-      reply = dbus_message_new_error(msg, "org.bluez.Error.Rejected",
-                                     "The uuid is not authorized");
-    }
-
-    if (!reply) {
-      errorStr.AssignLiteral("Memory can't be allocated for the message.");
-      goto handle_error;
-    }
-
-    dbus_connection_send(conn, reply, nullptr);
-    dbus_message_unref(reply);
-    return DBUS_HANDLER_RESULT_HANDLED;
-  } else if (dbus_message_is_method_call(msg, DBUS_AGENT_IFACE,
-                                         "RequestConfirmation")) {
-    // This method gets called when the service daemon needs to confirm a
-    // passkey for an authentication.
-    uint32_t passkey;
-    if (!dbus_message_get_args(msg, nullptr,
-                               DBUS_TYPE_OBJECT_PATH, &objectPath,
-                               DBUS_TYPE_UINT32, &passkey,
-                               DBUS_TYPE_INVALID)) {
-      errorStr.AssignLiteral("Invalid arguments: RequestConfirmation()");
-      goto handle_error;
-    }
-
-    parameters.AppendElement(
-      BluetoothNamedValue(NS_LITERAL_STRING("path"),
-                          NS_ConvertUTF8toUTF16(objectPath)));
-    parameters.AppendElement(
-      BluetoothNamedValue(NS_LITERAL_STRING("method"),
-                          NS_LITERAL_STRING("confirmation")));
-    parameters.AppendElement(
-      BluetoothNamedValue(NS_LITERAL_STRING("passkey"), passkey));
-
-    v = parameters;
-    isPairingReq = true;
-  } else if (dbus_message_is_method_call(msg, DBUS_AGENT_IFACE,
-                                         "RequestPinCode")) {
-    // This method gets called when the service daemon needs to get the passkey
-    // for an authentication. The return value should be a string of 1-16
-    // characters length. The string can be alphanumeric.
-    if (!dbus_message_get_args(msg, nullptr,
-                               DBUS_TYPE_OBJECT_PATH, &objectPath,
-                               DBUS_TYPE_INVALID)) {
-      errorStr.AssignLiteral("Invalid arguments for RequestPinCode() method");
-      goto handle_error;
-    }
-
-    parameters.AppendElement(
-      BluetoothNamedValue(NS_LITERAL_STRING("path"),
-                          NS_ConvertUTF8toUTF16(objectPath)));
-    parameters.AppendElement(
-      BluetoothNamedValue(NS_LITERAL_STRING("method"),
-                          NS_LITERAL_STRING("pincode")));
-
-    v = parameters;
-    isPairingReq = true;
-  } else if (dbus_message_is_method_call(msg, DBUS_AGENT_IFACE,
-                                         "RequestPasskey")) {
-    // This method gets called when the service daemon needs to get the passkey
-    // for an authentication. The return value should be a numeric value
-    // between 0-999999.
-    if (!dbus_message_get_args(msg, nullptr,
-                               DBUS_TYPE_OBJECT_PATH, &objectPath,
-                               DBUS_TYPE_INVALID)) {
-      errorStr.AssignLiteral("Invalid arguments for RequestPasskey() method");
-      goto handle_error;
-    }
-
-    parameters.AppendElement(BluetoothNamedValue(
-                               NS_LITERAL_STRING("path"),
-                               NS_ConvertUTF8toUTF16(objectPath)));
-    parameters.AppendElement(BluetoothNamedValue(
-                               NS_LITERAL_STRING("method"),
-                               NS_LITERAL_STRING("passkey")));
-
-    v = parameters;
-    isPairingReq = true;
-  } else if (dbus_message_is_method_call(msg, DBUS_AGENT_IFACE, "Release")) {
-    // This method gets called when the service daemon unregisters the agent.
-    // An agent can use it to do cleanup tasks. There is no need to unregister
-    // the agent, because when this method gets called it has already been
-    // unregistered.
-    DBusMessage *reply = dbus_message_new_method_return(msg);
-
-    if (!reply) {
-      errorStr.AssignLiteral("Memory can't be allocated for the message.");
-      goto handle_error;
-    }
-
-    dbus_connection_send(conn, reply, nullptr);
-    dbus_message_unref(reply);
-
-    // Do not send a notification to upper layer, too annoying.
-    return DBUS_HANDLER_RESULT_HANDLED;
-  } else if (dbus_message_is_method_call(msg, DBUS_AGENT_IFACE,
-                                         "RequestPairingConsent")) {
-    // Directly SetPairingconfirmation for RequestPairingConsent here
-    if (!dbus_message_get_args(msg, nullptr,
-                               DBUS_TYPE_OBJECT_PATH, &objectPath,
-                               DBUS_TYPE_INVALID)) {
-      errorStr.AssignLiteral("Invalid arguments: RequestPairingConsent()");
-      goto handle_error;
-    }
-
-    BluetoothAddress address;
-    GetAddressFromObjectPath(NS_ConvertUTF8toUTF16(objectPath), address);
-
-    sPairingReqTable->Put(address, msg);
-    DispatchToDBusThread(
-      MakeAndAddRef<SetPairingConfirmationTask>(address, true, nullptr));
-    // Increase dbus message reference counts, it will be decreased in
-    // SetPairingConfirmationTask
-    dbus_message_ref(msg);
-    // Do not send a notification to upper layer
-    return DBUS_HANDLER_RESULT_HANDLED;
-  } else {
-#ifdef DEBUG
-    BT_WARNING("agent handler %s: Unhandled event. Ignore.", __FUNCTION__);
-#endif
-    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-  }
-
-  if (!errorStr.IsEmpty()) {
-    BT_WARNING(NS_ConvertUTF16toUTF8(errorStr).get());
-    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-  }
-
-  // Update value after parsing DBus message
-  signal.value() = v;
-
-  if (isPairingReq) {
-
-    BluetoothAddress address;
-    GetAddressFromObjectPath(NS_ConvertUTF8toUTF16(objectPath), address);
-
-    sPairingReqTable->Put(address, msg);
-
-    // Increase ref count here because we need this message later.
-    // It'll be unrefed when set*Internal() is called.
-    dbus_message_ref(msg);
-
-    AppendDeviceName(signal);
-  } else {
-    NS_DispatchToMainThread(new DistributeBluetoothSignalTask(signal));
-  }
-
-  return DBUS_HANDLER_RESULT_HANDLED;
-
-handle_error:
-  BT_WARNING(NS_ConvertUTF16toUTF8(errorStr).get());
-  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-class RegisterAgentReplyHandler : public DBusReplyHandler
-{
-public:
-  RegisterAgentReplyHandler(const DBusObjectPathVTable* aAgentVTable)
-    : mAgentVTable(aAgentVTable)
-  {
-    MOZ_ASSERT(aAgentVTable);
-  }
-
-  void Handle(DBusMessage* aReply)
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-
-    if (!aReply || (dbus_message_get_type(aReply) == DBUS_MESSAGE_TYPE_ERROR)) {
-      return;
-    }
-
-    // There is no "RegisterAgent" function defined in device interface.
-    // When we call "CreatePairedDevice", it will do device agent registration
-    // for us. (See maemo.org/api_refs/5.0/beta/bluez/adapter.html)
-    if (!dbus_connection_register_object_path(sDBusConnection->GetConnection(),
-                                              KEY_REMOTE_AGENT,
-                                              mAgentVTable,
-                                              nullptr)) {
-      BT_WARNING("%s: Can't register object path %s for remote device agent!",
-                 __FUNCTION__, KEY_REMOTE_AGENT);
-      return;
-    }
-
-    NS_DispatchToMainThread(new PrepareProfileManagersRunnable());
-  }
-
-private:
-  const DBusObjectPathVTable* mAgentVTable;
-};
-
-class AddReservedServiceRecordsReplyHandler : public DBusReplyHandler
-{
-public:
-  void Handle(DBusMessage* aReply)
-  {
-    static const DBusObjectPathVTable sAgentVTable = {
-      nullptr, AgentEventFilter, nullptr, nullptr, nullptr, nullptr
-    };
-
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-    if (!aReply || (dbus_message_get_type(aReply) == DBUS_MESSAGE_TYPE_ERROR)) {
-      return;
-    }
-
-    // TODO/qdot: This needs to be held for the life of the bluetooth connection
-    // so we could clean it up. For right now though, we can throw it away.
-    nsTArray<uint32_t> handles;
-
-    ExtractHandles(aReply, handles);
-
-    if(!RegisterAgent(&sAgentVTable)) {
-      BT_WARNING("Failed to register agent");
-    }
-  }
-
-private:
-  void ExtractHandles(DBusMessage *aMessage, nsTArray<uint32_t>& aOutHandles)
-  {
-    DBusError error;
-    int length;
-    uint32_t* handles = nullptr;
-
-    dbus_error_init(&error);
-
-    bool success = dbus_message_get_args(aMessage, &error,
-                                         DBUS_TYPE_ARRAY,
-                                         DBUS_TYPE_UINT32,
-                                         &handles, &length,
-                                         DBUS_TYPE_INVALID);
-    if (success != TRUE) {
-      LOG_AND_FREE_DBUS_ERROR(&error);
-      return;
-    }
-
-    if (!handles) {
-      BT_WARNING("Null array in extract_handles");
-      return;
-    }
-
-    for (int i = 0; i < length; ++i) {
-      aOutHandles.AppendElement(handles[i]);
-    }
-  }
-
-  bool RegisterAgent(const DBusObjectPathVTable* aAgentVTable)
-  {
-    const char* agentPath = KEY_LOCAL_AGENT;
-    const char* capabilities = B2G_AGENT_CAPABILITIES;
-
-    MOZ_ASSERT(sDBusConnection);
-
-    // Local agent means agent for Adapter, not agent for Device. Some signals
-    // will be passed to local agent, some will be passed to device agent.
-    // For example, if a remote device would like to pair with us, then the
-    // signal will be passed to local agent. If we start pairing process with
-    // calling CreatePairedDevice, we'll get signal which should be passed to
-    // device agent.
-    if (!dbus_connection_register_object_path(sDBusConnection->GetConnection(),
-                                              KEY_LOCAL_AGENT,
-                                              aAgentVTable,
-                                              nullptr)) {
-      BT_WARNING("%s: Can't register object path %s for agent!",
-                 __FUNCTION__, KEY_LOCAL_AGENT);
-      return false;
-    }
-
-    RefPtr<RegisterAgentReplyHandler> handler =
-      new RegisterAgentReplyHandler(aAgentVTable);
-    MOZ_ASSERT(!sAdapterPath.IsEmpty());
-
-    bool success = sDBusConnection->SendWithReply(
-      RegisterAgentReplyHandler::Callback, handler.get(), -1,
-      BLUEZ_DBUS_BASE_IFC,
-      NS_ConvertUTF16toUTF8(sAdapterPath).get(),
-      DBUS_ADAPTER_IFACE, "RegisterAgent",
-      DBUS_TYPE_OBJECT_PATH, &agentPath,
-      DBUS_TYPE_STRING, &capabilities,
-      DBUS_TYPE_INVALID);
-
-    NS_ENSURE_TRUE(success, false);
-
-    Unused << handler.forget(); // picked up by callback handler
-
-    return true;
-  }
-};
-
-class AddReservedServiceRecordsTask : public Runnable
-{
-public:
-  AddReservedServiceRecordsTask()
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    static const dbus_uint32_t sServices[] = {
-      BluetoothServiceClass::HANDSFREE_AG,
-      BluetoothServiceClass::HEADSET_AG,
-      BluetoothServiceClass::OBJECT_PUSH
-    };
-
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-    MOZ_ASSERT(!sAdapterPath.IsEmpty());
-
-    RefPtr<DBusReplyHandler> handler =
-      new AddReservedServiceRecordsReplyHandler();
-
-    const dbus_uint32_t* services = sServices;
-
-    bool success = sDBusConnection->SendWithReply(
-      DBusReplyHandler::Callback, handler.get(), -1,
-      BLUEZ_DBUS_BASE_IFC,
-      NS_ConvertUTF16toUTF8(sAdapterPath).get(),
-      DBUS_ADAPTER_IFACE, "AddReservedServiceRecords",
-      DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32,
-      &services, ArrayLength(sServices), DBUS_TYPE_INVALID);
-
-    NS_ENSURE_TRUE(success, NS_OK);
-
-    Unused << handler.forget(); /* picked up by callback handler */
-
-    return NS_OK;
-  }
-};
-
-class PrepareAdapterRunnable : public Runnable
-{
-public:
-  PrepareAdapterRunnable()
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    DispatchToDBusThread(MakeAndAddRef<AddReservedServiceRecordsTask>());
-
-    return NS_OK;
-  }
-};
-
-class RequestPlayStatusTask : public Runnable
-{
-public:
-  RequestPlayStatusTask()
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-  }
-
-  nsresult Run()
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BluetoothService* bs = BluetoothService::Get();
-    NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-
-    bs->DistributeSignal(NS_LITERAL_STRING(REQUEST_MEDIA_PLAYSTATUS_ID),
-                         NS_LITERAL_STRING(KEY_ADAPTER));
-
-    return NS_OK;
-  }
-};
-
-// Called by dbus during WaitForAndDispatchEventNative()
-// This function is called on the IOThread
-static DBusHandlerResult
-EventFilter(DBusConnection* aConn, DBusMessage* aMsg, void* aData)
-{
-  // I/O thread
-  MOZ_ASSERT(!NS_IsMainThread(), "Shouldn't be called from Main Thread!");
-
-  if (dbus_message_get_type(aMsg) != DBUS_MESSAGE_TYPE_SIGNAL) {
-    BT_WARNING("%s: event handler not interested in %s (not a signal).\n",
-        __FUNCTION__, dbus_message_get_member(aMsg));
-    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-  }
-
-  if (dbus_message_get_path(aMsg) == nullptr) {
-    BT_WARNING("DBusMessage %s has no bluetooth destination, ignoring\n",
-               dbus_message_get_member(aMsg));
-    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-  }
-
-  DBusError err;
-  dbus_error_init(&err);
-
-  nsAutoString signalPath;
-  nsAutoString signalName;
-  nsAutoString signalInterface;
-
-  BT_LOGD("%s: %s, %s, %s", __FUNCTION__,
-                          dbus_message_get_interface(aMsg),
-                          dbus_message_get_path(aMsg),
-                          dbus_message_get_member(aMsg));
-
-  signalInterface = NS_ConvertUTF8toUTF16(dbus_message_get_interface(aMsg));
-  signalPath = NS_ConvertUTF8toUTF16(dbus_message_get_path(aMsg));
-  signalName = NS_ConvertUTF8toUTF16(dbus_message_get_member(aMsg));
-  nsString errorStr;
-  BluetoothValue v;
-
-  // Since the signalPath extracted from dbus message is a object path,
-  // we'd like to re-assign them to corresponding key entry in
-  // BluetoothSignalObserverTable
-  if (signalInterface.EqualsLiteral(DBUS_MANAGER_IFACE)) {
-    signalPath.AssignLiteral(KEY_MANAGER);
-  } else if (signalInterface.EqualsLiteral(DBUS_ADAPTER_IFACE)) {
-    signalPath.AssignLiteral(KEY_ADAPTER);
-  } else if (signalInterface.EqualsLiteral(DBUS_DEVICE_IFACE)){
-    signalPath = GetAddressFromObjectPath(signalPath);
-  }
-
-  if (dbus_message_is_signal(aMsg, DBUS_ADAPTER_IFACE, "DeviceFound")) {
-    DBusMessageIter iter;
-
-    if (!dbus_message_iter_init(aMsg, &iter)) {
-      BT_WARNING("Can't create iterator!");
-      return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-    }
-
-    const char* addr;
-    dbus_message_iter_get_basic(&iter, &addr);
-
-    if (!dbus_message_iter_next(&iter)) {
-      errorStr.AssignLiteral("Unexpected message struct in msg DeviceFound");
-    } else {
-      ParseProperties(&iter,
-                      v,
-                      errorStr,
-                      sDeviceProperties,
-                      ArrayLength(sDeviceProperties));
-
-      InfallibleTArray<BluetoothNamedValue>& properties =
-        v.get_ArrayOfBluetoothNamedValue();
-
-      // The DBus DeviceFound message actually passes back a key value object
-      // with the address as the key and the rest of the device properties as
-      // a dict value. After we parse out the properties, we need to go back
-      // and add the address to the ipdl dict we've created to make sure we
-      // have all of the information to correctly build the device.
-      nsAutoString address = NS_ConvertUTF8toUTF16(addr);
-      properties.AppendElement(
-        BluetoothNamedValue(NS_LITERAL_STRING("Address"), address));
-      properties.AppendElement(
-        BluetoothNamedValue(NS_LITERAL_STRING("Path"),
-                            GetObjectPathFromAddress(signalPath, address)));
-
-      if (!ContainsIcon(properties)) {
-        for (uint32_t i = 0; i < properties.Length(); i++) {
-          // It is possible that property Icon missed due to CoD of major
-          // class is TOY but service class is "Audio", we need to assign
-          // Icon as audio-card. This is for PTS test TC_AG_COD_BV_02_I.
-          // As HFP specification defined that
-          // service class is "Audio" can be considered as HFP AG.
-          if (properties[i].name().EqualsLiteral("Class")) {
-            if (HasAudioService(properties[i].value().get_uint32_t())) {
-              v.get_ArrayOfBluetoothNamedValue().AppendElement(
-                BluetoothNamedValue(NS_LITERAL_STRING("Icon"),
-                                    NS_LITERAL_STRING("audio-card")));
-            }
-            break;
-          }
-        }
-      }
-    }
-  } else if (dbus_message_is_signal(aMsg, DBUS_ADAPTER_IFACE,
-                                    "DeviceDisappeared")) {
-    const char* str;
-    if (!dbus_message_get_args(aMsg, &err,
-                               DBUS_TYPE_STRING, &str,
-                               DBUS_TYPE_INVALID)) {
-      LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, aMsg);
-      errorStr.AssignLiteral("Cannot parse device address!");
-    } else {
-      v = NS_ConvertUTF8toUTF16(str);
-    }
-  } else if (dbus_message_is_signal(aMsg, DBUS_ADAPTER_IFACE,
-                                    "DeviceCreated")) {
-    const char* str;
-    if (!dbus_message_get_args(aMsg, &err,
-                               DBUS_TYPE_OBJECT_PATH, &str,
-                               DBUS_TYPE_INVALID)) {
-      LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, aMsg);
-      errorStr.AssignLiteral("Cannot parse device path!");
-    } else {
-      v = NS_ConvertUTF8toUTF16(str);
-    }
-  } else if (dbus_message_is_signal(aMsg, DBUS_ADAPTER_IFACE,
-                                    "DeviceRemoved")) {
-    const char* str;
-    if (!dbus_message_get_args(aMsg, &err,
-                               DBUS_TYPE_OBJECT_PATH, &str,
-                               DBUS_TYPE_INVALID)) {
-      LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, aMsg);
-      errorStr.AssignLiteral("Cannot parse device path!");
-    } else {
-      v = NS_ConvertUTF8toUTF16(str);
-    }
-  } else if (dbus_message_is_signal(aMsg, DBUS_ADAPTER_IFACE,
-                                    "PropertyChanged")) {
-    ParsePropertyChange(aMsg,
-                        v,
-                        errorStr,
-                        sAdapterProperties,
-                        ArrayLength(sAdapterProperties));
-
-  } else if (dbus_message_is_signal(aMsg, DBUS_DEVICE_IFACE,
-                                    "PropertyChanged")) {
-    ParsePropertyChange(aMsg,
-                        v,
-                        errorStr,
-                        sDeviceProperties,
-                        ArrayLength(sDeviceProperties));
-
-    if (v.type() == BluetoothValue::T__None) {
-      BT_WARNING("PropertyChanged event couldn't be parsed.");
-      return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-    }
-
-    BluetoothNamedValue& property = v.get_ArrayOfBluetoothNamedValue()[0];
-    if (property.name().EqualsLiteral("Paired")) {
-      // Original approach: Broadcast system message of
-      // "bluetooth-pairedstatuschanged" from BluetoothService.
-      BluetoothValue newValue(v);
-      ToLowerCase(newValue.get_ArrayOfBluetoothNamedValue()[0].name());
-
-      BluetoothSignal signal(NS_LITERAL_STRING("pairedstatuschanged"),
-                             NS_LITERAL_STRING(KEY_LOCAL_AGENT),
-                             newValue);
-      NS_DispatchToMainThread(new DistributeBluetoothSignalTask(signal));
-
-      // New approach: Dispatch event from BluetoothAdapter
-      bool status = property.value();
-      InfallibleTArray<BluetoothNamedValue> parameters;
-      parameters.AppendElement(
-        BluetoothNamedValue(NS_LITERAL_STRING("address"), signalPath));
-      parameters.AppendElement(
-        BluetoothNamedValue(NS_LITERAL_STRING("status"), status));
-      signal.path() = NS_LITERAL_STRING(KEY_ADAPTER);
-      signal.value() = parameters;
-      NS_DispatchToMainThread(new DistributeBluetoothSignalTask(signal));
-    } else if (property.name().EqualsLiteral("Connected")) {
-      MonitorAutoLock lock(*sStopBluetoothMonitor);
-
-      if (property.value().get_bool()) {
-        ++sConnectedDeviceCount;
-      } else {
-        MOZ_ASSERT(sConnectedDeviceCount > 0);
-        if (--sConnectedDeviceCount == 0) {
-          lock.Notify();
-        }
-      }
-    }
-  } else if (dbus_message_is_signal(aMsg, DBUS_MANAGER_IFACE, "AdapterAdded")) {
-    const char* str;
-    if (!dbus_message_get_args(aMsg, &err,
-                               DBUS_TYPE_OBJECT_PATH, &str,
-                               DBUS_TYPE_INVALID)) {
-      LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, aMsg);
-      errorStr.AssignLiteral("Cannot parse manager path!");
-    } else {
-      v = NS_ConvertUTF8toUTF16(str);
-      sAdapterPath = v.get_nsString();
-      NS_DispatchToMainThread(new TryFiringAdapterAddedRunnable(true));
-      NS_DispatchToMainThread(new PrepareAdapterRunnable());
-
-      /**
-       * The adapter name isn't ready for the time being. Wait for the upcoming
-       * signal PropertyChanged of adapter name, and then propagate signal
-       * AdapterAdded to BluetoothManager.
-       */
-      return DBUS_HANDLER_RESULT_HANDLED;
-    }
-  } else if (dbus_message_is_signal(aMsg, DBUS_MANAGER_IFACE,
-                                    "PropertyChanged")) {
-    ParsePropertyChange(aMsg,
-                        v,
-                        errorStr,
-                        sManagerProperties,
-                        ArrayLength(sManagerProperties));
-  } else if (dbus_message_is_signal(aMsg, DBUS_SINK_IFACE,
-                                    "PropertyChanged")) {
-    ParsePropertyChange(aMsg,
-                        v,
-                        errorStr,
-                        sSinkProperties,
-                        ArrayLength(sSinkProperties));
-  } else if (dbus_message_is_signal(aMsg, DBUS_CTL_IFACE, "GetPlayStatus")) {
-    NS_DispatchToMainThread(new RequestPlayStatusTask());
-    return DBUS_HANDLER_RESULT_HANDLED;
-  } else if (dbus_message_is_signal(aMsg, DBUS_CTL_IFACE, "PropertyChanged")) {
-    ParsePropertyChange(aMsg,
-                        v,
-                        errorStr,
-                        sControlProperties,
-                        ArrayLength(sControlProperties));
-  } else if (dbus_message_is_signal(aMsg, DBUS_INPUT_IFACE,
-                                    "PropertyChanged")) {
-    ParsePropertyChange(aMsg,
-                        v,
-                        errorStr,
-                        sInputProperties,
-                        ArrayLength(sInputProperties));
-  } else {
-    errorStr = NS_ConvertUTF8toUTF16(dbus_message_get_member(aMsg));
-    errorStr.AppendLiteral(" Signal not handled!");
-  }
-
-  if (!errorStr.IsEmpty()) {
-    BT_WARNING(NS_ConvertUTF16toUTF8(errorStr).get());
-    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-  }
-
-  BluetoothSignal signal(signalName, signalPath, v);
-  RefPtr<Runnable> task;
-  if (signalInterface.EqualsLiteral(DBUS_SINK_IFACE)) {
-    task = new SinkPropertyChangedHandler(signal);
-  } else if (signalInterface.EqualsLiteral(DBUS_CTL_IFACE)) {
-    task = new ControlPropertyChangedHandler(signal);
-  } else if (signalInterface.EqualsLiteral(DBUS_INPUT_IFACE)) {
-    task = new InputPropertyChangedHandler(signal);
-  } else {
-    task = new DistributeBluetoothSignalTask(signal);
-  }
-
-  NS_DispatchToMainThread(task);
-
-  return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-static void
-OnDefaultAdapterReply(DBusMessage* aReply, void* aData)
-{
-  MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-  if (!aReply || dbus_message_is_error(aReply, DBUS_ERROR_TIMEOUT)) {
-    return;
-  }
-
-  DBusError err;
-  dbus_error_init(&err);
-
-  BluetoothValue v;
-  nsAutoString errorString;
-
-  UnpackObjectPathMessage(aReply, &err, v, errorString);
-
-  if (!errorString.IsEmpty()) {
-    return;
-  }
-
-  sAdapterPath = v.get_nsString();
-
-  RefPtr<PrepareAdapterRunnable> b = new PrepareAdapterRunnable();
-  if (NS_FAILED(NS_DispatchToMainThread(b))) {
-    BT_WARNING("Failed to dispatch to main thread!");
-  }
-}
-
-bool
-BluetoothDBusService::IsReady()
-{
-  if (!IsEnabled() || !sDBusConnection || IsToggling()) {
-    BT_WARNING("Bluetooth service is not ready yet!");
-    return false;
-  }
-  return true;
-}
-
-class StartDBusConnectionTask : public Runnable
-{
-public:
-  StartDBusConnectionTask(RawDBusConnection* aConnection)
-  : mConnection(aConnection)
-  {
-    MOZ_ASSERT(mConnection);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-    if (sDBusConnection) {
-      BT_WARNING("DBus connection has already been established.");
-      RefPtr<Runnable> runnable = new BluetoothService::ToggleBtAck(true);
-      if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
-        BT_WARNING("Failed to dispatch to main thread!");
-      }
-      return NS_OK;
-    }
-
-    // Add a filter for all incoming messages_base
-    if (!dbus_connection_add_filter(mConnection->GetConnection(),
-                                    EventFilter, nullptr, nullptr)) {
-      BT_WARNING("Cannot create DBus Event Filter for DBus Thread!");
-      RefPtr<Runnable> runnable = new BluetoothService::ToggleBtAck(false);
-      if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
-        BT_WARNING("Failed to dispatch to main thread!");
-      }
-      return NS_OK;
-    }
-
-    mConnection->Watch();
-
-    if (!sPairingReqTable) {
-      sPairingReqTable = new nsDataHashtable<BluetoothAddressHashKey, DBusMessage* >;
-    }
-
-    sDBusConnection = mConnection.release();
-
-    RefPtr<Runnable> runnable =
-      new BluetoothService::ToggleBtAck(true);
-    if (NS_FAILED(NS_DispatchToMainThread(runnable.forget()))) {
-      BT_WARNING("Failed to dispatch to main thread!");
-      return NS_OK;
-    }
-
-    /* Normally we'll receive the signal 'AdapterAdded' with the adapter object
-     * path from the DBus daemon during start up. So, there's no need to query
-     * the object path of default adapter here. However, if we restart from a
-     * crash, the default adapter might already be available, so we ask the
-     * daemon explicitly here.
-     */
-    if (sAdapterPath.IsEmpty()) {
-      bool success = sDBusConnection->SendWithReply(OnDefaultAdapterReply,
-                                                    nullptr, 1000,
-                                                    BLUEZ_DBUS_BASE_IFC, "/",
-                                                    DBUS_MANAGER_IFACE,
-                                                    "DefaultAdapter",
-                                                    DBUS_TYPE_INVALID);
-      if (!success) {
-        BT_WARNING("Failed to query default adapter!");
-      }
-    }
-    return NS_OK;
-  }
-
-private:
-  UniquePtr<RawDBusConnection> mConnection;
-};
-
-class StartBluetoothRunnable final : public Runnable
-{
-public:
-  NS_IMETHOD Run() override
-  {
-    // This could block. It should never be run on the main thread.
-    MOZ_ASSERT(!NS_IsMainThread()); // BT thread
-
-#ifdef MOZ_WIDGET_GONK
-    if (!sBluedroid.Enable()) {
-      BT_WARNING("Bluetooth not available.");
-      RefPtr<Runnable> runnable = new BluetoothService::ToggleBtAck(false);
-      if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
-        BT_WARNING("Failed to dispatch to main thread!");
-      }
-      return NS_ERROR_FAILURE;
-    }
-#endif
-
-    RawDBusConnection* connection = new RawDBusConnection();
-    nsresult rv = connection->EstablishDBusConnection();
-    if (NS_FAILED(rv)) {
-      BT_WARNING("Failed to establish connection to BlueZ daemon");
-      RefPtr<Runnable> runnable = new BluetoothService::ToggleBtAck(false);
-      if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
-        BT_WARNING("Failed to dispatch to main thread!");
-      }
-      return NS_ERROR_FAILURE;
-    }
-
-    DBusError err;
-    dbus_error_init(&err);
-
-    // Set which messages will be processed by this dbus connection.
-    // Since we are maintaining a single thread for all the DBus bluez
-    // signals we want, register all of them in this thread at startup.
-    // The event handler will sort the destinations out as needed. The
-    // call to dbus_bus_add_match has to run on the BT thread because
-    // it can block.
-    for (uint32_t i = 0; i < ArrayLength(sBluetoothDBusSignals); ++i) {
-      dbus_bus_add_match(connection->GetConnection(),
-                         sBluetoothDBusSignals[i],
-                         &err);
-      if (dbus_error_is_set(&err)) {
-        LOG_AND_FREE_DBUS_ERROR(&err);
-      }
-    }
-
-    DispatchToDBusThread(MakeAndAddRef<StartDBusConnectionTask>(connection));
-
-    return NS_OK;
-  }
-};
-
-nsresult
-BluetoothDBusService::StartInternal(BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(!aRunnable);
-
-  RefPtr<Runnable> runnable = new StartBluetoothRunnable();
-  nsresult rv = DispatchToBtThread(runnable);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("Failed to dispatch to BT thread!");
-  }
-  return rv;
-}
-
-class DisableBluetoothRunnable final : public Runnable
-{
-public:
-  NS_IMETHOD Run() override
-  {
-    if (NS_IsMainThread()) {
-      // Clear |sControllerArray| here while we're on the main thread
-      sControllerArray.Clear();
-      // Forward this runnable to BT thread
-      return DispatchToBtThread(this);
-    }
-
-#ifdef MOZ_WIDGET_GONK
-    MOZ_ASSERT(sBluedroid.IsEnabled());
-    // Disable() return true on success, so we need to invert it
-    bool isEnabled = !sBluedroid.Disable();
-#else
-    bool isEnabled = false;
-#endif
-
-    RefPtr<Runnable> runnable =
-      new BluetoothService::ToggleBtAck(isEnabled);
-    nsresult rv = NS_DispatchToMainThread(runnable);
-    if (NS_FAILED(rv)) {
-      BT_WARNING("Failed to dispatch to main thread!");
-    }
-    return rv;
-  }
-};
-
-class DeleteDBusConnectionTask final : public Runnable
-{
-public:
-  DeleteDBusConnectionTask()
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-    if (!sDBusConnection) {
-      BT_WARNING("DBus connection has not been established.");
-      RefPtr<Runnable> runnable = new BluetoothService::ToggleBtAck(false);
-      if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
-        BT_WARNING("Failed to dispatch to main thread!");
-      }
-      return NS_OK;
-    }
-
-    for (uint32_t i = 0; i < ArrayLength(sBluetoothDBusSignals); ++i) {
-      dbus_bus_remove_match(sDBusConnection->GetConnection(),
-                            sBluetoothDBusSignals[i], NULL);
-    }
-
-    dbus_connection_remove_filter(sDBusConnection->GetConnection(),
-                                  EventFilter, nullptr);
-
-    if (!dbus_connection_unregister_object_path(sDBusConnection->GetConnection(),
-                                                KEY_LOCAL_AGENT)) {
-      BT_WARNING("%s: Can't unregister object path %s for agent!",
-          __FUNCTION__, KEY_LOCAL_AGENT);
-    }
-
-    if (!dbus_connection_unregister_object_path(sDBusConnection->GetConnection(),
-                                                KEY_REMOTE_AGENT)) {
-      BT_WARNING("%s: Can't unregister object path %s for agent!",
-          __FUNCTION__, KEY_REMOTE_AGENT);
-    }
-
-    // unref stored DBusMessages before clearing the hashtable
-    for (auto iter = sPairingReqTable->Iter(); !iter.Done(); iter.Next()) {
-      dbus_message_unref(iter.UserData());
-    }
-    sPairingReqTable->Clear();
-
-    sIsPairing = 0;
-    sConnectedDeviceCount = 0;
-
-    // This command closes the DBus connection and all its instances
-    // of DBusWatch will be removed and free'd.
-    sDBusConnection = nullptr;
-
-    // We can only dispatch to the BT thread if we're on the main
-    // thread. Thus we dispatch our runnable to the main thread
-    // from where it will forward itself to the BT thread.
-    RefPtr<Runnable> runnable = new DisableBluetoothRunnable();
-    if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
-      BT_WARNING("Failed to dispatch to BT thread!");
-    }
-    return NS_OK;
-  }
-};
-
-class StopBluetoothRunnable final : public Runnable
-{
-public:
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // BT thread
-
-    // This could block. It should never be run on the main thread.
-    MonitorAutoLock lock(*sStopBluetoothMonitor);
-    if (sConnectedDeviceCount > 0) {
-      lock.Wait(PR_SecondsToInterval(TIMEOUT_FORCE_TO_DISABLE_BT));
-    }
-
-    DispatchToDBusThread(MakeAndAddRef<DeleteDBusConnectionTask>());
-
-    return NS_OK;
-  }
-};
-
-nsresult
-BluetoothDBusService::StopInternal(BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(!aRunnable);
-
-  RefPtr<Runnable> runnable = new StopBluetoothRunnable();
-  nsresult rv = DispatchToBtThread(runnable);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("Failed to dispatch to BT thread!");
-  }
-  return rv;
-}
-
-class DefaultAdapterPathReplyHandler : public DBusReplyHandler
-{
-public:
-  DefaultAdapterPathReplyHandler(BluetoothReplyRunnable* aRunnable)
-    : mRunnable(aRunnable)
-  {
-    MOZ_ASSERT(mRunnable);
-  }
-
-  void Handle(DBusMessage* aReply) override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-    if (!aReply || (dbus_message_get_type(aReply) == DBUS_MESSAGE_TYPE_ERROR)) {
-      const char* errStr = "Timeout in DefaultAdapterPathReplyHandler";
-      if (aReply) {
-        errStr = dbus_message_get_error_name(aReply);
-        if (!errStr) {
-          errStr = "Bluetooth DBus Error";
-        }
-      }
-      DispatchBluetoothReply(mRunnable, BluetoothValue(),
-                             NS_ConvertUTF8toUTF16(errStr));
-      return;
-    }
-
-    bool success;
-    nsAutoString replyError;
-
-    if (mAdapterPath.IsEmpty()) {
-      success = HandleDefaultAdapterPathReply(aReply, replyError);
-    } else {
-      success = HandleGetPropertiesReply(aReply, replyError);
-    }
-
-    if (!success) {
-      DispatchBluetoothReply(mRunnable, BluetoothValue(), replyError);
-    }
-  }
-
-protected:
-  bool HandleDefaultAdapterPathReply(DBusMessage* aReply,
-                                     nsAString& aReplyError)
-  {
-    BluetoothValue value;
-    DBusError error;
-    dbus_error_init(&error);
-
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-
-    UnpackObjectPathMessage(aReply, &error, value, aReplyError);
-
-    if (!aReplyError.IsEmpty()) {
-      return false;
-    }
-
-    mAdapterPath = value.get_nsString();
-
-    // Acquire another reference to this reply handler
-    RefPtr<DefaultAdapterPathReplyHandler> handler = this;
-
-    bool success = sDBusConnection->SendWithReply(
-      DefaultAdapterPathReplyHandler::Callback, handler.get(), 1000,
-      BLUEZ_DBUS_BASE_IFC,
-      NS_ConvertUTF16toUTF8(mAdapterPath).get(),
-      DBUS_ADAPTER_IFACE, "GetProperties", DBUS_TYPE_INVALID);
-
-    if (!success) {
-      aReplyError = NS_LITERAL_STRING("SendWithReply failed");
-      return false;
-    }
-
-    Unused << handler.forget(); // picked up by callback handler
-
-    return true;
-  }
-
-  bool HandleGetPropertiesReply(DBusMessage* aReply,
-                                nsAutoString& aReplyError)
-  {
-    BluetoothValue value;
-    DBusError error;
-    dbus_error_init(&error);
-
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-    bool success = UnpackPropertiesMessage(aReply, &error, value,
-                                           DBUS_ADAPTER_IFACE);
-    if (!success) {
-      aReplyError = NS_ConvertUTF8toUTF16(error.message);
-      return false;
-    }
-
-    // We have to manually attach the path to the rest of the elements
-    value.get_ArrayOfBluetoothNamedValue().AppendElement(
-      BluetoothNamedValue(NS_LITERAL_STRING("Path"), mAdapterPath));
-
-    // Dispatch result
-    DispatchBluetoothReply(mRunnable, value, aReplyError);
-
-    return true;
-  }
-
-private:
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-  nsString mAdapterPath;
-};
-
-class DefaultAdapterTask : public Runnable
-{
-public:
-  DefaultAdapterTask(BluetoothReplyRunnable* aRunnable)
-    : mRunnable(aRunnable)
-  {
-    MOZ_ASSERT(mRunnable);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-
-    RefPtr<DefaultAdapterPathReplyHandler> handler =
-      new DefaultAdapterPathReplyHandler(mRunnable);
-
-    bool success = sDBusConnection->SendWithReply(
-      DefaultAdapterPathReplyHandler::Callback,
-      handler.get(), 1000, BLUEZ_DBUS_BASE_IFC,
-      "/", DBUS_MANAGER_IFACE, "DefaultAdapter",
-      DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE(success, NS_OK);
-
-    Unused << handler.forget(); // picked up by callback handler
-
-    return NS_OK;
-  }
-
-private:
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-};
-
-nsresult
-BluetoothDBusService::GetAdaptersInternal(BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * TODO: implement method GetAdaptersInternal for bluez
-   */
-
-  if (!IsReady()) {
-    NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
-    DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
-    return NS_OK;
-  }
-
-  DispatchToDBusThread(MakeAndAddRef<DefaultAdapterTask>(aRunnable));
-
-  return NS_OK;
-}
-
-static void
-OnSendDiscoveryMessageReply(DBusMessage *aReply, void *aData)
-{
-  MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-  nsAutoString errorStr;
-
-  if (!aReply) {
-    errorStr.AssignLiteral("SendDiscovery failed");
-  }
-
-  RefPtr<BluetoothReplyRunnable> runnable =
-    dont_AddRef<BluetoothReplyRunnable>(
-      static_cast<BluetoothReplyRunnable*>(aData));
-
-  DispatchBluetoothReply(runnable.get(), BluetoothValue(true), errorStr);
-}
-
-class SendDiscoveryMessageTask : public Runnable
-{
-public:
-  SendDiscoveryMessageTask(const char* aMessageName,
-                           BluetoothReplyRunnable* aRunnable)
-    : mMessageName(aMessageName)
-    , mRunnable(aRunnable)
-  {
-    MOZ_ASSERT(!mMessageName.IsEmpty());
-    MOZ_ASSERT(mRunnable);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-    MOZ_ASSERT(!sAdapterPath.IsEmpty());
-
-    bool success = sDBusConnection->SendWithReply(
-      OnSendDiscoveryMessageReply,
-      static_cast<void*>(mRunnable.get()), -1,
-      BLUEZ_DBUS_BASE_IFC,
-      NS_ConvertUTF16toUTF8(sAdapterPath).get(),
-      DBUS_ADAPTER_IFACE, mMessageName.get(),
-      DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE(success, NS_OK);
-
-    Unused << mRunnable.forget(); // picked up by callback handler
-
-    return NS_OK;
-  }
-
-private:
-  const nsCString mMessageName;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-};
-
-nsresult
-BluetoothDBusService::SendDiscoveryMessage(const char* aMessageName,
-                                           BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!sAdapterPath.IsEmpty());
-
-  if (!IsReady()) {
-    NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
-    DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
-
-    return NS_OK;
-  }
-
-  DispatchToDBusThread(
-    MakeAndAddRef<SendDiscoveryMessageTask>(aMessageName, aRunnable));
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothDBusService::SendInputMessage(const nsAString& aDeviceAddress,
-                                       const nsAString& aMessage)
-{
-  DBusReplyCallback callback;
-  if (aMessage.EqualsLiteral("Connect")) {
-    callback = InputConnectCallback;
-  } else if (aMessage.EqualsLiteral("Disconnect")) {
-    callback = InputDisconnectCallback;
-  } else {
-    MOZ_ASSERT(false);
-    return NS_ERROR_FAILURE;
-  }
-
-  MOZ_ASSERT(!sAdapterPath.IsEmpty());
-  nsString objectPath = GetObjectPathFromAddress(sAdapterPath, aDeviceAddress);
-  return SendAsyncDBusMessage(objectPath, DBUS_INPUT_IFACE, aMessage, callback);
-}
-
-class SendAsyncDBusMessageTask : public Runnable
-{
-public:
-  SendAsyncDBusMessageTask(DBusReplyCallback aCallback,
-                           BluetoothServiceClass aServiceClass,
-                           const nsACString& aObjectPath,
-                           const char* aInterface,
-                           const nsACString& aMessage)
-    : mCallback(aCallback)
-    , mServiceClass(aServiceClass)
-    , mObjectPath(aObjectPath)
-    , mInterface(aInterface)
-    , mMessage(aMessage)
-  {
-    MOZ_ASSERT(!mObjectPath.IsEmpty());
-    MOZ_ASSERT(!mInterface.IsEmpty());
-    MOZ_ASSERT(!mMessage.IsEmpty());
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-
-    static_assert(sizeof(BluetoothServiceClass) <= sizeof(intptr_t),
-                  "BluetoothServiceClass cannot be passed via intptr_t");
-    bool success = sDBusConnection->SendWithReply(
-      mCallback, NS_INT32_TO_PTR(mServiceClass), -1,
-      BLUEZ_DBUS_BASE_IFC, mObjectPath.get(), mInterface.get(),
-      mMessage.get(), DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE(success, NS_OK);
-
-    return NS_OK;
-  }
-
-private:
-  DBusReplyCallback mCallback;
-  BluetoothServiceClass mServiceClass;
-  const nsCString mObjectPath;
-  const nsCString mInterface;
-  const nsCString mMessage;
-};
-
-nsresult
-BluetoothDBusService::SendAsyncDBusMessage(const nsAString& aObjectPath,
-                                           const char* aInterface,
-                                           const nsAString& aMessage,
-                                           DBusReplyCallback aCallback)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(IsEnabled());
-  MOZ_ASSERT(aCallback);
-  MOZ_ASSERT(!aObjectPath.IsEmpty());
-  MOZ_ASSERT(aInterface);
-
-  BluetoothServiceClass serviceClass;
-  if (!strcmp(aInterface, DBUS_SINK_IFACE)) {
-    serviceClass = BluetoothServiceClass::A2DP;
-  } else if (!strcmp(aInterface, DBUS_INPUT_IFACE)) {
-    serviceClass = BluetoothServiceClass::HID;
-  } else {
-    MOZ_ASSERT(false);
-    return NS_ERROR_FAILURE;
-  }
-
-  DispatchToDBusThread(
-    MakeAndAddRef<SendAsyncDBusMessageTask>(aCallback,
-                                            serviceClass,
-                                            NS_ConvertUTF16toUTF8(aObjectPath),
-                                            aInterface,
-                                            NS_ConvertUTF16toUTF8(aMessage)));
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothDBusService::SendSinkMessage(const nsAString& aDeviceAddress,
-                                      const nsAString& aMessage)
-{
-  DBusReplyCallback callback;
-  if (aMessage.EqualsLiteral("Connect")) {
-    callback = SinkConnectCallback;
-  } else if (aMessage.EqualsLiteral("Disconnect")) {
-    callback = SinkDisconnectCallback;
-  } else {
-    MOZ_ASSERT(false);
-    return NS_ERROR_FAILURE;
-  }
-
-  MOZ_ASSERT(!sAdapterPath.IsEmpty());
-  nsString objectPath = GetObjectPathFromAddress(sAdapterPath, aDeviceAddress);
-  return SendAsyncDBusMessage(objectPath, DBUS_SINK_IFACE, aMessage, callback);
-}
-
-void
-BluetoothDBusService::StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable)
-{
-  SendDiscoveryMessage("StopDiscovery", aRunnable);
-}
-
-void
-BluetoothDBusService::StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable)
-{
-  SendDiscoveryMessage("StartDiscovery", aRunnable);
-}
-
-class BluetoothArrayOfDevicePropertiesReplyHandler : public DBusReplyHandler
-{
-public:
-  BluetoothArrayOfDevicePropertiesReplyHandler(
-    const nsTArray<BluetoothAddress>& aDeviceAddresses,
-    const FilterFunc aFilterFunc, BluetoothReplyRunnable* aRunnable)
-    : mDeviceAddresses(aDeviceAddresses)
-    , mProcessedDeviceAddresses(0)
-    , mFilterFunc(aFilterFunc)
-    , mRunnable(aRunnable)
-    , mValues(InfallibleTArray<BluetoothNamedValue>())
-  {
-    MOZ_ASSERT(mRunnable);
-  }
-
-  void Handle(DBusMessage* aReply) override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(!sAdapterPath.IsEmpty());
-    MOZ_ASSERT(!mObjectPath.IsEmpty());
-    MOZ_ASSERT(mProcessedDeviceAddresses < mDeviceAddresses.Length());
-
-    const nsTArray<nsString>::index_type i = mProcessedDeviceAddresses++;
-
-    if (!aReply ||
-        (dbus_message_get_type(aReply) == DBUS_MESSAGE_TYPE_ERROR)) {
-      BT_WARNING("Invalid DBus message");
-      ProcessRemainingDeviceAddresses();
-      return;
-    }
-
-    // Get device properties from result of GetProperties
-
-    DBusError err;
-    dbus_error_init(&err);
-
-    BluetoothValue deviceProperties;
-
-    bool success = UnpackPropertiesMessage(aReply, &err, deviceProperties,
-                                           DBUS_DEVICE_IFACE);
-    if (!success) {
-      BT_WARNING("Failed to get device properties");
-      ProcessRemainingDeviceAddresses();
-      return;
-    }
-
-    InfallibleTArray<BluetoothNamedValue>& devicePropertiesArray =
-      deviceProperties.get_ArrayOfBluetoothNamedValue();
-
-    // We have to manually attach the path to the rest of the elements
-    devicePropertiesArray.AppendElement(
-      BluetoothNamedValue(NS_LITERAL_STRING("Path"), mObjectPath));
-
-    // It is possible that property Icon missed due to CoD of major
-    // class is TOY but service class is "Audio", we need to assign
-    // Icon as audio-card. This is for PTS test TC_AG_COD_BV_02_I.
-    // As HFP specification defined that
-    // service class is "Audio" can be considered as HFP AG.
-    if (!ContainsIcon(devicePropertiesArray)) {
-      for (uint32_t j = 0; j < devicePropertiesArray.Length(); ++j) {
-        BluetoothNamedValue& deviceProperty = devicePropertiesArray[j];
-        if (deviceProperty.name().EqualsLiteral("Class")) {
-          if (HasAudioService(deviceProperty.value().get_uint32_t())) {
-            devicePropertiesArray.AppendElement(
-              BluetoothNamedValue(NS_LITERAL_STRING("Icon"),
-                                  NS_LITERAL_STRING("audio-card")));
-          }
-          break;
-        }
-      }
-    }
-
-    if (mFilterFunc(deviceProperties)) {
-      nsString deviceAddressStr;
-      AddressToString(mDeviceAddresses[i], deviceAddressStr);
-
-      mValues.get_ArrayOfBluetoothNamedValue().AppendElement(
-        BluetoothNamedValue(deviceAddressStr, deviceProperties));
-    }
-
-    ProcessRemainingDeviceAddresses();
-  }
-
-  void ProcessRemainingDeviceAddresses()
-  {
-    if (mProcessedDeviceAddresses < mDeviceAddresses.Length()) {
-      if (!SendNextGetProperties()) {
-        DispatchBluetoothReply(mRunnable, BluetoothValue(),
-                               NS_LITERAL_STRING(
-                                 "SendNextGetProperties failed"));
-      }
-    } else {
-      // Send resulting device properties
-      DispatchBluetoothReply(mRunnable, mValues, EmptyString());
-    }
-  }
-
-protected:
-  bool SendNextGetProperties()
-  {
-    MOZ_ASSERT(mProcessedDeviceAddresses < mDeviceAddresses.Length());
-    MOZ_ASSERT(!sAdapterPath.IsEmpty());
-    MOZ_ASSERT(sDBusConnection);
-
-    // cache object path for reply
-    mObjectPath = GetObjectPathFromAddress(sAdapterPath,
-      mDeviceAddresses[mProcessedDeviceAddresses]);
-
-    RefPtr<BluetoothArrayOfDevicePropertiesReplyHandler> handler = this;
-
-    bool success = sDBusConnection->SendWithReply(
-      BluetoothArrayOfDevicePropertiesReplyHandler::Callback,
-      handler.get(), 1000, BLUEZ_DBUS_BASE_IFC,
-      NS_ConvertUTF16toUTF8(mObjectPath).get(),
-      DBUS_DEVICE_IFACE, "GetProperties",
-      DBUS_TYPE_INVALID);
-
-    NS_ENSURE_TRUE(success, false);
-
-    Unused << handler.forget(); // picked up by callback handler
-
-    return true;
-  }
-
-private:
-  nsString mObjectPath;
-  const nsTArray<BluetoothAddress> mDeviceAddresses;
-  nsTArray<nsString>::size_type mProcessedDeviceAddresses;
-  const FilterFunc mFilterFunc;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-  BluetoothValue mValues;
-};
-
-class ProcessRemainingDeviceAddressesTask : public Runnable
-{
-public:
-  ProcessRemainingDeviceAddressesTask(
-    BluetoothArrayOfDevicePropertiesReplyHandler* aHandler,
-    BluetoothReplyRunnable* aRunnable)
-    : mHandler(aHandler)
-    , mRunnable(aRunnable)
-  {
-    MOZ_ASSERT(mHandler);
-    MOZ_ASSERT(mRunnable);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-    mHandler->ProcessRemainingDeviceAddresses();
-
-    return NS_OK;
-  }
-
-private:
-  RefPtr<BluetoothArrayOfDevicePropertiesReplyHandler> mHandler;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-};
-
-nsresult
-BluetoothDBusService::GetConnectedDevicePropertiesInternal(
-  uint16_t aServiceUuid, BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsAutoString errorStr;
-  BluetoothValue values = InfallibleTArray<BluetoothNamedValue>();
-  if (!IsReady()) {
-    NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
-    DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
-    return NS_OK;
-  }
-
-  nsTArray<BluetoothAddress> deviceAddresses;
-
-  BluetoothProfileManagerBase* profile =
-    BluetoothUuidHelper::GetBluetoothProfileManager(aServiceUuid);
-  if (!profile) {
-    DispatchBluetoothReply(aRunnable, values,
-                           NS_LITERAL_STRING(ERR_UNKNOWN_PROFILE));
-    return NS_OK;
-  }
-
-  if (profile->IsConnected()) {
-    BluetoothAddress address;
-    profile->GetAddress(address);
-    deviceAddresses.AppendElement(address);
-  }
-
-  BluetoothArrayOfDevicePropertiesReplyHandler* handler =
-    new BluetoothArrayOfDevicePropertiesReplyHandler(deviceAddresses,
-                                                     GetConnectedDevicesFilter,
-                                                     aRunnable);
-  DispatchToDBusThread(
-    MakeAndAddRef<ProcessRemainingDeviceAddressesTask>(handler, aRunnable));
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothDBusService::GetPairedDevicePropertiesInternal(
-  const nsTArray<BluetoothAddress>& aDeviceAddresses,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!IsReady()) {
-    NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
-    DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
-    return NS_OK;
-  }
-
-  BluetoothArrayOfDevicePropertiesReplyHandler* handler =
-    new BluetoothArrayOfDevicePropertiesReplyHandler(aDeviceAddresses,
-                                                     GetPairedDevicesFilter,
-                                                     aRunnable);
-  DispatchToDBusThread(
-    MakeAndAddRef<ProcessRemainingDeviceAddressesTask>(handler, aRunnable));
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothDBusService::FetchUuidsInternal(const BluetoothAddress& aDeviceAddress,
-                                         BluetoothReplyRunnable* aRunnable)
-{
-  return NS_OK;
-}
-
-class SetPropertyTask : public Runnable
-{
-public:
-  SetPropertyTask(BluetoothObjectType aType,
-                  const nsACString& aName,
-                  BluetoothReplyRunnable* aRunnable)
-    : mType(aType)
-    , mName(aName)
-    , mRunnable(aRunnable)
-  {
-    MOZ_ASSERT(mRunnable);
-  }
-
-  void Send(unsigned int aType, const void* aValue)
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-    MOZ_ASSERT(!sAdapterPath.IsEmpty());
-
-    DBusMessage* msg =
-      dbus_message_new_method_call(BLUEZ_DBUS_BASE_IFC,
-                                   NS_ConvertUTF16toUTF8(sAdapterPath).get(),
-                                   sBluetoothDBusIfaces[mType],
-                                   "SetProperty");
-    if (!msg) {
-      BT_WARNING("Could not allocate D-Bus message object!");
-      return;
-    }
-
-    const char* name = mName.get();
-    if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
-                                  DBUS_TYPE_INVALID)) {
-      BT_WARNING("Couldn't append arguments to dbus message!");
-      return;
-    }
-
-    DBusMessageIter value_iter, iter;
-    dbus_message_iter_init_append(msg, &iter);
-    char var_type[2] = {(char)aType, '\0'};
-    if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
-                                          var_type, &value_iter) ||
-        !dbus_message_iter_append_basic(&value_iter, aType, aValue) ||
-        !dbus_message_iter_close_container(&iter, &value_iter)) {
-      BT_WARNING("Could not append argument to method call!");
-      dbus_message_unref(msg);
-      return;
-    }
-
-    // msg is unref'd as part of SendWithReply
-    bool success = sDBusConnection->SendWithReply(
-      GetVoidCallback,
-      static_cast<void*>(mRunnable),
-      1000, msg);
-    NS_ENSURE_TRUE_VOID(success);
-
-    Unused << mRunnable.forget(); // picked up by callback handler
-  }
-
-private:
-  BluetoothObjectType mType;
-  const nsCString mName;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-};
-
-class SetUInt32PropertyTask : public SetPropertyTask
-{
-public:
-  SetUInt32PropertyTask(BluetoothObjectType aType,
-                        const nsACString& aName,
-                        uint32_t aValue,
-                        BluetoothReplyRunnable* aRunnable)
-    : SetPropertyTask(aType, aName, aRunnable)
-    , mValue(aValue)
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    Send(DBUS_TYPE_UINT32, &mValue);
-
-    return NS_OK;
-  }
-
-private:
-  dbus_uint32_t mValue;
-};
-
-class SetStringPropertyTask : public SetPropertyTask
-{
-public:
-  SetStringPropertyTask(BluetoothObjectType aType,
-                        const nsACString& aName,
-                        const nsACString& aValue,
-                        BluetoothReplyRunnable* aRunnable)
-    : SetPropertyTask(aType, aName, aRunnable)
-    , mValue(aValue)
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    const char* value = mValue.get();
-    Send(DBUS_TYPE_STRING, &value);
-
-    return NS_OK;
-  }
-
-private:
-  const nsCString mValue;
-};
-
-class SetBooleanPropertyTask : public SetPropertyTask
-{
-public:
-  SetBooleanPropertyTask(BluetoothObjectType aType,
-                         const nsACString& aName,
-                         dbus_bool_t aValue,
-                         BluetoothReplyRunnable* aRunnable)
-    : SetPropertyTask(aType, aName, aRunnable)
-    , mValue(aValue)
-  {
-  }
-
-  NS_IMETHOD Run() override
-  {
-    Send(DBUS_TYPE_BOOLEAN, &mValue);
-
-    return NS_OK;
-  }
-
-private:
-  dbus_bool_t mValue;
-};
-
-nsresult
-BluetoothDBusService::SetProperty(BluetoothObjectType aType,
-                                  const BluetoothNamedValue& aValue,
-                                  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!IsReady()) {
-    NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
-    DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
-    return NS_OK;
-  }
-
-  RefPtr<Runnable> task;
-
-  if (aValue.value().type() == BluetoothValue::Tuint32_t) {
-    task = MakeAndAddRef<SetUInt32PropertyTask>(aType,
-      NS_ConvertUTF16toUTF8(aValue.name()),
-      aValue.value().get_uint32_t(), aRunnable);
-  } else if (aValue.value().type() == BluetoothValue::TnsString) {
-    task = MakeAndAddRef<SetStringPropertyTask>(aType,
-      NS_ConvertUTF16toUTF8(aValue.name()),
-      NS_ConvertUTF16toUTF8(aValue.value().get_nsString()), aRunnable);
-  } else if (aValue.value().type() == BluetoothValue::Tbool) {
-    task = MakeAndAddRef<SetBooleanPropertyTask>(aType,
-      NS_ConvertUTF16toUTF8(aValue.name()),
-      aValue.value().get_bool(), aRunnable);
-  } else {
-    BT_WARNING("Property type not handled!");
-    return NS_ERROR_FAILURE;
-  }
-  DispatchToDBusThread(task.forget());
-
-  return NS_OK;
-}
-
-class CreatePairedDeviceInternalTask : public Runnable
-{
-public:
-  CreatePairedDeviceInternalTask(const BluetoothAddress& aDeviceAddress,
-                                 int aTimeout,
-                                 BluetoothReplyRunnable* aRunnable)
-    : mDeviceAddress(aDeviceAddress)
-    , mTimeout(aTimeout)
-    , mRunnable(aRunnable)
-  {
-    MOZ_ASSERT(!mDeviceAddress.IsCleared());
-    MOZ_ASSERT(mRunnable);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-    MOZ_ASSERT(!sAdapterPath.IsEmpty());
-
-    nsString deviceAddressStr;
-    AddressToString(mDeviceAddress, deviceAddressStr);
-    auto utf8DeviceAddressStr = NS_ConvertUTF16toUTF8(deviceAddressStr);
-
-    const char *deviceAddress = utf8DeviceAddressStr.get();
-    const char *deviceAgentPath = KEY_REMOTE_AGENT;
-    const char *capabilities = B2G_AGENT_CAPABILITIES;
-
-    // Then send CreatePairedDevice, it will register a temp device agent then
-    // unregister it after pairing process is over
-    bool success = sDBusConnection->SendWithReply(
-      GetObjectPathCallback, static_cast<void*>(mRunnable), mTimeout,
-      BLUEZ_DBUS_BASE_IFC,
-      NS_ConvertUTF16toUTF8(sAdapterPath).get(),
-      DBUS_ADAPTER_IFACE,
-      "CreatePairedDevice",
-      DBUS_TYPE_STRING, &deviceAddress,
-      DBUS_TYPE_OBJECT_PATH, &deviceAgentPath,
-      DBUS_TYPE_STRING, &capabilities,
-      DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE(success, NS_OK);
-
-    Unused << mRunnable.forget(); // picked up by callback handler
-
-    /**
-     * FIXME: Bug 820274
-     *
-     * If the user turns off Bluetooth in the middle of pairing process,
-     * the callback function GetObjectPathCallback may still be called
-     * while enabling next time by dbus daemon. To prevent this from
-     * happening, added a flag to distinguish if Bluetooth has been
-     * turned off. Nevertheless, we need a check if there is a better
-     * solution.
-     *
-     * Please see Bug 818696 for more information.
-     */
-    sIsPairing++;
-
-    return NS_OK;
-  }
-
-private:
-  BluetoothAddress mDeviceAddress;
-  int mTimeout;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-};
-
-nsresult
-BluetoothDBusService::CreatePairedDeviceInternal(
-  const BluetoothAddress& aDeviceAddress,
-  int aTimeout,
-  BluetoothReplyRunnable* aRunnable)
-{
-  DispatchToDBusThread(
-    MakeAndAddRef<CreatePairedDeviceInternalTask>(aDeviceAddress,
-                                                  aTimeout,
-                                                  aRunnable));
-
-  return NS_OK;
-}
-
-class RemoveDeviceTask : public Runnable
-{
-public:
-  RemoveDeviceTask(const BluetoothAddress& aDeviceAddress,
-                   BluetoothReplyRunnable* aRunnable)
-    : mDeviceAddress(aDeviceAddress)
-    , mRunnable(aRunnable)
-  {
-    MOZ_ASSERT(!mDeviceAddress.IsCleared());
-    MOZ_ASSERT(mRunnable);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-    MOZ_ASSERT(!sAdapterPath.IsEmpty());
-
-    nsCString deviceObjectPath =
-      NS_ConvertUTF16toUTF8(GetObjectPathFromAddress(sAdapterPath,
-                                                     mDeviceAddress));
-    const char* cstrDeviceObjectPath = deviceObjectPath.get();
-
-    bool success = sDBusConnection->SendWithReply(
-      OnRemoveDeviceReply, static_cast<void*>(mRunnable.get()), -1,
-      BLUEZ_DBUS_BASE_IFC,
-      NS_ConvertUTF16toUTF8(sAdapterPath).get(),
-      DBUS_ADAPTER_IFACE, "RemoveDevice",
-      DBUS_TYPE_OBJECT_PATH, &cstrDeviceObjectPath,
-      DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE(success, NS_OK);
-
-    Unused << mRunnable.forget(); // picked up by callback handler
-
-    return NS_OK;
-  }
-
-protected:
-  static void OnRemoveDeviceReply(DBusMessage* aReply, void* aData)
-  {
-    nsAutoString errorStr;
-
-    if (!aReply) {
-      errorStr.AssignLiteral("RemoveDevice failed");
-    }
-
-    RefPtr<BluetoothReplyRunnable> runnable =
-      dont_AddRef<BluetoothReplyRunnable>(
-        static_cast<BluetoothReplyRunnable*>(aData));
-
-    DispatchBluetoothReply(runnable.get(), BluetoothValue(true), errorStr);
-  }
-
-private:
-  const BluetoothAddress mDeviceAddress;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-};
-
-nsresult
-BluetoothDBusService::RemoveDeviceInternal(
-  const BluetoothAddress& aDeviceAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!IsReady()) {
-    NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
-    DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
-    return NS_OK;
-  }
-
-  DispatchToDBusThread(
-    MakeAndAddRef<RemoveDeviceTask>(aDeviceAddress, aRunnable));
-
-  return NS_OK;
-}
-
-class SetPinCodeTask : public Runnable
-{
-public:
-  SetPinCodeTask(const BluetoothAddress& aDeviceAddress,
-                 const BluetoothPinCode& aPinCode,
-                 BluetoothReplyRunnable* aRunnable)
-    : mDeviceAddress(aDeviceAddress)
-    , mPinCode(aPinCode)
-    , mRunnable(aRunnable)
-  {
-    MOZ_ASSERT(!mDeviceAddress.IsCleared());
-    MOZ_ASSERT(mRunnable);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-    nsAutoString errorStr;
-    BluetoothValue v = true;
-    DBusMessage *msg;
-    if (!sPairingReqTable->Get(mDeviceAddress, &msg)) {
-      BT_WARNING("%s: Couldn't get original request message.", __FUNCTION__);
-      errorStr.AssignLiteral("Couldn't get original request message.");
-      DispatchBluetoothReply(mRunnable, v, errorStr);
-      return NS_OK;
-    }
-
-    DBusMessage *reply = dbus_message_new_method_return(msg);
-
-    if (!reply) {
-      BT_WARNING("%s: Memory can't be allocated for the message.", __FUNCTION__);
-      dbus_message_unref(msg);
-      errorStr.AssignLiteral("Memory can't be allocated for the message.");
-      DispatchBluetoothReply(mRunnable, v, errorStr);
-      return NS_OK;
-    }
-
-    nsAutoString pinCodeStr;
-    if (NS_FAILED(PinCodeToString(mPinCode, pinCodeStr))) {
-      BT_WARNING("%s: Cannot convert pin code to string.", __FUNCTION__);
-      dbus_message_unref(msg);
-      dbus_message_unref(reply);
-      errorStr.AssignLiteral("Cannot convert pin code to string.");
-      DispatchBluetoothReply(mRunnable, v, errorStr);
-      return NS_OK;
-    }
-
-    auto utf8PinCodeStr = NS_ConvertUTF16toUTF8(pinCodeStr);
-
-    const char* pinCode = utf8PinCodeStr.get();
-
-    if (!dbus_message_append_args(reply,
-                                  DBUS_TYPE_STRING, &pinCode,
-                                  DBUS_TYPE_INVALID)) {
-      BT_WARNING("%s: Couldn't append arguments to dbus message.", __FUNCTION__);
-      errorStr.AssignLiteral("Couldn't append arguments to dbus message.");
-    } else {
-      MOZ_ASSERT(sDBusConnection);
-      sDBusConnection->Send(reply);
-    }
-
-    dbus_message_unref(msg);
-    dbus_message_unref(reply);
-
-    sPairingReqTable->Remove(mDeviceAddress);
-    DispatchBluetoothReply(mRunnable, v, errorStr);
-
-    return NS_OK;
-  }
-
-private:
-  const BluetoothAddress mDeviceAddress;
-  const BluetoothPinCode mPinCode;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-};
-
-void
-BluetoothDBusService::PinReplyInternal(
-  const BluetoothAddress& aDeviceAddress, bool aAccept,
-  const BluetoothPinCode& aPinCode, BluetoothReplyRunnable* aRunnable)
-{
-  // Legacy interface used by Bluedroid only.
-}
-
-void
-BluetoothDBusService::SspReplyInternal(
-  const BluetoothAddress& aDeviceAddress, BluetoothSspVariant aVariant,
-  bool aAccept, BluetoothReplyRunnable* aRunnable)
-{
-  // Legacy interface used by Bluedroid only.
-}
-
-void
-BluetoothDBusService::SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
-                                         const BluetoothPinCode& aPinCode,
-                                         BluetoothReplyRunnable* aRunnable)
-{
-  DispatchToDBusThread(
-    MakeAndAddRef<SetPinCodeTask>(aDeviceAddress, aPinCode, aRunnable));
-}
-
-class SetPasskeyTask : public Runnable
-{
-public:
-  SetPasskeyTask(const BluetoothAddress& aDeviceAddress,
-                 uint32_t aPasskey,
-                 BluetoothReplyRunnable* aRunnable)
-    : mDeviceAddress(aDeviceAddress)
-    , mPasskey(aPasskey)
-    , mRunnable(aRunnable)
-  {
-    MOZ_ASSERT(!mDeviceAddress.IsCleared());
-    MOZ_ASSERT(mRunnable);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-    nsAutoString errorStr;
-    BluetoothValue v = true;
-    DBusMessage *msg;
-    if (!sPairingReqTable->Get(mDeviceAddress, &msg)) {
-      BT_WARNING("%s: Couldn't get original request message.", __FUNCTION__);
-      errorStr.AssignLiteral("Couldn't get original request message.");
-      DispatchBluetoothReply(mRunnable, v, errorStr);
-      return NS_OK;
-    }
-
-    DBusMessage *reply = dbus_message_new_method_return(msg);
-
-    if (!reply) {
-      BT_WARNING("%s: Memory can't be allocated for the message.", __FUNCTION__);
-      dbus_message_unref(msg);
-      errorStr.AssignLiteral("Memory can't be allocated for the message.");
-      DispatchBluetoothReply(mRunnable, v, errorStr);
-      return NS_OK;
-    }
-
-    uint32_t passkey = mPasskey;
-
-    if (!dbus_message_append_args(reply,
-                                  DBUS_TYPE_UINT32, &passkey,
-                                  DBUS_TYPE_INVALID)) {
-      BT_WARNING("%s: Couldn't append arguments to dbus message.", __FUNCTION__);
-      errorStr.AssignLiteral("Couldn't append arguments to dbus message.");
-    } else {
-      MOZ_ASSERT(sDBusConnection);
-      sDBusConnection->Send(reply);
-    }
-
-    dbus_message_unref(msg);
-    dbus_message_unref(reply);
-
-    sPairingReqTable->Remove(mDeviceAddress);
-    DispatchBluetoothReply(mRunnable, v, errorStr);
-
-    return NS_OK;
-  }
-
-private:
-  BluetoothAddress mDeviceAddress;
-  uint32_t mPasskey;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-};
-
-void
-BluetoothDBusService::SetPasskeyInternal(
-  const BluetoothAddress& aDeviceAddress,
-  uint32_t aPasskey,
-  BluetoothReplyRunnable* aRunnable)
-{
-  DispatchToDBusThread(
-    MakeAndAddRef<SetPasskeyTask>(aDeviceAddress,
-                                  aPasskey,
-                                  aRunnable));
-}
-
-void
-BluetoothDBusService::SetPairingConfirmationInternal(
-  const BluetoothAddress& aDeviceAddress,
-  bool aConfirm,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  DispatchToDBusThread(
-    MakeAndAddRef<SetPairingConfirmationTask>(aDeviceAddress,
-                                              aConfirm,
-                                              aRunnable));
-}
-
-static void
-NextBluetoothProfileController()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // First, remove the task at the front which has been already done.
-  NS_ENSURE_FALSE_VOID(sControllerArray.IsEmpty());
-  sControllerArray.RemoveElementAt(0);
-
-  // Re-check if the task array is empty, if it's not, the next task will begin.
-  NS_ENSURE_FALSE_VOID(sControllerArray.IsEmpty());
-  sControllerArray[0]->StartSession();
-}
-
-static void
-ConnectDisconnect(bool aConnect, const BluetoothAddress& aDeviceAddress,
-                  BluetoothReplyRunnable* aRunnable,
-                  uint16_t aServiceUuid, uint32_t aCod = 0)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  BluetoothProfileController* controller =
-    new BluetoothProfileController(aConnect, aDeviceAddress, aRunnable,
-                                   NextBluetoothProfileController,
-                                   aServiceUuid, aCod);
-  sControllerArray.AppendElement(controller);
-
-  /**
-   * If the request is the first element of the quene, start from here. Note
-   * that other request is pushed into the quene and is popped out after the
-   * first one is completed. See NextBluetoothProfileController() for details.
-   */
-  if (sControllerArray.Length() == 1) {
-    sControllerArray[0]->StartSession();
-  }
-}
-
-void
-BluetoothDBusService::Connect(const BluetoothAddress& aDeviceAddress,
-                              uint32_t aCod,
-                              uint16_t aServiceUuid,
-                              BluetoothReplyRunnable* aRunnable)
-{
-  ConnectDisconnect(true, aDeviceAddress, aRunnable, aServiceUuid, aCod);
-}
-
-void
-BluetoothDBusService::Disconnect(const BluetoothAddress& aDeviceAddress,
-                                 uint16_t aServiceUuid,
-                                 BluetoothReplyRunnable* aRunnable)
-{
-  ConnectDisconnect(false, aDeviceAddress, aRunnable, aServiceUuid);
-}
-
-#ifdef MOZ_B2G_RIL
-void
-BluetoothDBusService::AnswerWaitingCall(BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-  hfp->AnswerWaitingCall();
-
-  DispatchBluetoothReply(aRunnable, BluetoothValue(true), EmptyString());
-}
-
-void
-BluetoothDBusService::IgnoreWaitingCall(BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-  hfp->IgnoreWaitingCall();
-
-  DispatchBluetoothReply(aRunnable, BluetoothValue(true), EmptyString());
-}
-
-void
-BluetoothDBusService::ToggleCalls(BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-  hfp->ToggleCalls();
-
-  DispatchBluetoothReply(aRunnable, BluetoothValue(true), EmptyString());
-}
-#endif // MOZ_B2G_RIL
-
-class OnUpdateSdpRecordsRunnable : public Runnable
-{
-public:
-  OnUpdateSdpRecordsRunnable(const BluetoothAddress& aDeviceAddress,
-                             BluetoothProfileManagerBase* aManager)
-    : mDeviceAddress(aDeviceAddress)
-    , mManager(aManager)
-  {
-    MOZ_ASSERT(!mDeviceAddress.IsCleared());
-    MOZ_ASSERT(mManager);
-  }
-
-  NS_IMETHOD
-  Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    mManager->OnUpdateSdpRecords(mDeviceAddress);
-
-    return NS_OK;
-  }
-
-private:
-  BluetoothAddress mDeviceAddress;
-  BluetoothProfileManagerBase* mManager;
-};
-
-class OnGetServiceChannelRunnable : public Runnable
-{
-public:
-  OnGetServiceChannelRunnable(const BluetoothAddress& aDeviceAddress,
-                              const BluetoothUuid& aServiceUuid,
-                              int aChannel,
-                              BluetoothProfileManagerBase* aManager)
-    : mDeviceAddress(aDeviceAddress)
-    , mServiceUuid(aServiceUuid)
-    , mChannel(aChannel)
-    , mManager(aManager)
-  {
-    MOZ_ASSERT(!aDeviceAddress.IsCleared());
-    MOZ_ASSERT(!aServiceUuid.IsCleared());
-    MOZ_ASSERT(aManager);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    mManager->OnGetServiceChannel(mDeviceAddress, mServiceUuid, mChannel);
-
-    return NS_OK;
-  }
-
-private:
-  BluetoothAddress mDeviceAddress;
-  BluetoothUuid mServiceUuid;
-  int mChannel;
-  BluetoothProfileManagerBase* mManager;
-};
-
-class OnGetServiceChannelReplyHandler : public DBusReplyHandler
-{
-public:
-  OnGetServiceChannelReplyHandler(
-    const BluetoothAddress& aDeviceAddress,
-    const BluetoothUuid& aServiceUUID,
-    BluetoothProfileManagerBase* aBluetoothProfileManager)
-    : mDeviceAddress(aDeviceAddress),
-      mServiceUUID(aServiceUUID),
-      mBluetoothProfileManager(aBluetoothProfileManager)
-  {
-    MOZ_ASSERT(mBluetoothProfileManager);
-  }
-
-  void Handle(DBusMessage* aReply)
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-    // The default channel is an invalid value of -1. We
-    // update it if we have received a correct reply. Both
-    // cases, valid and invalid channel numbers, are handled
-    // in BluetoothProfileManagerBase::OnGetServiceChannel.
-
-    int channel = -1;
-
-    if (aReply && (dbus_message_get_type(aReply) != DBUS_MESSAGE_TYPE_ERROR)) {
-      channel = dbus_returns_int32(aReply);
-    }
-
-    RefPtr<Runnable> r =
-      new OnGetServiceChannelRunnable(mDeviceAddress, mServiceUUID, channel,
-                                      mBluetoothProfileManager);
-    nsresult rv = NS_DispatchToMainThread(r);
-    NS_ENSURE_SUCCESS_VOID(rv);
-  }
-
-private:
-  BluetoothAddress mDeviceAddress;
-  BluetoothUuid mServiceUUID;
-  BluetoothProfileManagerBase* mBluetoothProfileManager;
-};
-
-class GetServiceChannelTask : public Runnable
-{
-public:
-  GetServiceChannelTask(const BluetoothAddress& aDeviceAddress,
-                        const BluetoothUuid& aServiceUUID,
-                        BluetoothProfileManagerBase* aBluetoothProfileManager)
-    : mDeviceAddress(aDeviceAddress)
-    , mServiceUUID(aServiceUUID)
-    , mBluetoothProfileManager(aBluetoothProfileManager)
-  {
-    MOZ_ASSERT(!mDeviceAddress.IsCleared());
-    MOZ_ASSERT(mBluetoothProfileManager);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    static const int sProtocolDescriptorList = 0x0004;
-
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-    MOZ_ASSERT(!sAdapterPath.IsEmpty());
-
-    const nsString objectPath =
-      GetObjectPathFromAddress(sAdapterPath, mDeviceAddress);
-
-    RefPtr<OnGetServiceChannelReplyHandler> handler =
-      new OnGetServiceChannelReplyHandler(mDeviceAddress, mServiceUUID,
-                                          mBluetoothProfileManager);
-
-    nsAutoString serviceUuidStr;
-    UuidToString(mServiceUUID, serviceUuidStr);
-
-    nsCString serviceUUID = NS_ConvertUTF16toUTF8(serviceUuidStr);
-    const char* cstrServiceUUID = serviceUUID.get();
-
-    bool success = sDBusConnection->SendWithReply(
-      OnGetServiceChannelReplyHandler::Callback, handler, -1,
-      BLUEZ_DBUS_BASE_IFC,
-      NS_ConvertUTF16toUTF8(objectPath).get(),
-      DBUS_DEVICE_IFACE, "GetServiceAttributeValue",
-      DBUS_TYPE_STRING, &cstrServiceUUID,
-      DBUS_TYPE_UINT16, &sProtocolDescriptorList,
-      DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE(success, NS_OK);
-
-    Unused << handler.forget(); // picked up by callback handler
-
-    return NS_OK;
-  }
-
-private:
-  BluetoothAddress mDeviceAddress;
-  BluetoothUuid mServiceUUID;
-  BluetoothProfileManagerBase* mBluetoothProfileManager;
-};
-
-nsresult
-BluetoothDBusService::GetServiceChannel(const BluetoothAddress& aDeviceAddress,
-                                        const BluetoothUuid& aServiceUUID,
-                                        BluetoothProfileManagerBase* aManager)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!IsReady()) {
-    NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
-    return NS_OK;
-  }
-
-#ifdef MOZ_WIDGET_GONK
-  // GetServiceAttributeValue only exists in android's bluez dbus binding
-  // implementation
-  DispatchToDBusThread(
-    MakeAndAddRef<GetServiceChannelTask>(aDeviceAddress,
-                                         aServiceUUID,
-                                         aManager));
-#else
-  // FIXME/Bug 793977 qdot: Just set something for desktop, until we have a
-  // parser for the GetServiceAttributes xml block
-  //
-  // Even though we are on the main thread already, we need to dispatch a
-  // runnable here. OnGetServiceChannel needs mRunnable to be set, which
-  // happens after GetServiceChannel returns.
-  RefPtr<Runnable> r = new OnGetServiceChannelRunnable(aDeviceAddress,
-                                                         aServiceUUID,
-                                                         1,
-                                                         aManager);
-  NS_DispatchToMainThread(r);
-#endif
-
-  return NS_OK;
-}
-
-class UpdateSdpRecordsTask : public Runnable
-{
-public:
-  UpdateSdpRecordsTask(const BluetoothAddress& aDeviceAddress,
-                       BluetoothProfileManagerBase* aBluetoothProfileManager)
-    : mDeviceAddress(aDeviceAddress)
-    , mBluetoothProfileManager(aBluetoothProfileManager)
-  {
-    MOZ_ASSERT(!mDeviceAddress.IsCleared());
-    MOZ_ASSERT(mBluetoothProfileManager);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-    MOZ_ASSERT(!sAdapterPath.IsEmpty());
-
-    const nsString objectPath =
-      GetObjectPathFromAddress(sAdapterPath, mDeviceAddress);
-
-    // I choose to use raw pointer here because this is going to be passed as an
-    // argument into SendWithReply() at once.
-    OnUpdateSdpRecordsRunnable* callbackRunnable =
-      new OnUpdateSdpRecordsRunnable(mDeviceAddress, mBluetoothProfileManager);
-
-    sDBusConnection->SendWithReply(DiscoverServicesCallback,
-                                   (void*)callbackRunnable, -1,
-                                   BLUEZ_DBUS_BASE_IFC,
-                                   NS_ConvertUTF16toUTF8(objectPath).get(),
-                                   DBUS_DEVICE_IFACE,
-                                   "DiscoverServices",
-                                   DBUS_TYPE_STRING, &EmptyCString(),
-                                   DBUS_TYPE_INVALID);
-    return NS_OK;
-  }
-
-protected:
-  static void DiscoverServicesCallback(DBusMessage* aMsg, void* aData)
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-
-    RefPtr<OnUpdateSdpRecordsRunnable> r(
-      static_cast<OnUpdateSdpRecordsRunnable*>(aData));
-    NS_DispatchToMainThread(r);
-  }
-
-private:
-  const BluetoothAddress mDeviceAddress;
-  BluetoothProfileManagerBase* mBluetoothProfileManager;
-};
-
-bool
-BluetoothDBusService::UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
-                                       BluetoothProfileManagerBase* aManager)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  DispatchToDBusThread(
-    MakeAndAddRef<UpdateSdpRecordsTask>(aDeviceAddress, aManager));
-
-  return true;
-}
-
-void
-BluetoothDBusService::SendFile(const BluetoothAddress& aDeviceAddress,
-                               BlobParent* aBlobParent,
-                               BlobChild* aBlobChild,
-                               BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Currently we only support one device sending one file at a time,
-  // so we don't need aDeviceAddress here because the target device
-  // has been determined when calling 'Connect()'. Nevertheless, keep
-  // it for future use.
-  BluetoothOppManager* opp = BluetoothOppManager::Get();
-  nsAutoString errorStr;
-  if (!opp || !opp->SendFile(aDeviceAddress, aBlobParent)) {
-    errorStr.AssignLiteral("Calling SendFile() failed");
-  }
-
-  DispatchBluetoothReply(aRunnable, BluetoothValue(true), errorStr);
-}
-
-void
-BluetoothDBusService::SendFile(const BluetoothAddress& aDeviceAddress,
-                               Blob* aBlob,
-                               BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Currently we only support one device sending one file at a time,
-  // so we don't need aDeviceAddress here because the target device
-  // has been determined when calling 'Connect()'. Nevertheless, keep
-  // it for future use.
-  BluetoothOppManager* opp = BluetoothOppManager::Get();
-  nsAutoString errorStr;
-  if (!opp || !opp->SendFile(aDeviceAddress, aBlob)) {
-    errorStr.AssignLiteral("Calling SendFile() failed");
-  }
-
-  DispatchBluetoothReply(aRunnable, BluetoothValue(true), errorStr);
-}
-
-void
-BluetoothDBusService::StopSendingFile(const BluetoothAddress& aDeviceAddress,
-                                      BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Currently we only support one device sending one file at a time,
-  // so we don't need aDeviceAddress here because the target device
-  // has been determined when calling 'Connect()'. Nevertheless, keep
-  // it for future use.
-  BluetoothOppManager* opp = BluetoothOppManager::Get();
-  nsAutoString errorStr;
-  if (!opp || !opp->StopSendingFile()) {
-    errorStr.AssignLiteral("Calling StopSendingFile() failed");
-  }
-
-  DispatchBluetoothReply(aRunnable, BluetoothValue(true), errorStr);
-}
-
-void
-BluetoothDBusService::ConfirmReceivingFile(
-  const BluetoothAddress& aDeviceAddress,
-  bool aConfirm,
-  BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Must be called from main thread!");
-
-  // Currently we only support one device sending one file at a time,
-  // so we don't need aDeviceAddress here because the target device
-  // has been determined when calling 'Connect()'. Nevertheless, keep
-  // it for future use.
-  BluetoothOppManager* opp = BluetoothOppManager::Get();
-  nsAutoString errorStr;
-  if (!opp || !opp->ConfirmReceivingFile(aConfirm)) {
-    errorStr.AssignLiteral("Calling ConfirmReceivingFile() failed");
-  }
-
-  DispatchBluetoothReply(aRunnable, BluetoothValue(true), errorStr);
-}
-
-void
-BluetoothDBusService::ConnectSco(BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-  if (!hfp || !hfp->ConnectSco(aRunnable)) {
-    NS_NAMED_LITERAL_STRING(replyError, "Calling ConnectSco() failed");
-    DispatchBluetoothReply(aRunnable, BluetoothValue(), replyError);
-  }
-}
-
-void
-BluetoothDBusService::DisconnectSco(BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-  if (!hfp || !hfp->DisconnectSco()) {
-    NS_NAMED_LITERAL_STRING(replyError, "Calling DisconnectSco() failed");
-    DispatchBluetoothReply(aRunnable, BluetoothValue(), replyError);
-    return;
-  }
-
-  DispatchBluetoothReply(aRunnable, BluetoothValue(true), EmptyString());
-}
-
-void
-BluetoothDBusService::IsScoConnected(BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-  if (!hfp) {
-    NS_NAMED_LITERAL_STRING(replyError, "Fail to get BluetoothHfpManager");
-    DispatchBluetoothReply(aRunnable, BluetoothValue(), replyError);
-    return;
-  }
-
-  DispatchBluetoothReply(aRunnable, hfp->IsScoConnected(), EmptyString());
-}
-
-class SendMetadataTask : public Runnable
-{
-public:
-  SendMetadataTask(const BluetoothAddress& aDeviceAddress,
-                   const nsACString& aTitle,
-                   const nsACString& aArtist,
-                   const nsACString& aAlbum,
-                   int64_t aMediaNumber,
-                   int64_t aTotalMediaCount,
-                   int64_t aDuration,
-                   BluetoothReplyRunnable* aRunnable)
-    : mDeviceAddress(aDeviceAddress)
-    , mTitle(aTitle)
-    , mArtist(aArtist)
-    , mAlbum(aAlbum)
-    , mMediaNumber(aMediaNumber)
-    , mTotalMediaCount(aTotalMediaCount)
-    , mDuration(aDuration)
-    , mRunnable(aRunnable)
-  {
-    MOZ_ASSERT(!mDeviceAddress.IsCleared());
-    MOZ_ASSERT(mRunnable);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-    MOZ_ASSERT(!sAdapterPath.IsEmpty());
-
-    // We currently don't support genre field in music player.
-    // In order to send media metadata through AVRCP, we set genre to an empty
-    // string to match the BlueZ method "UpdateMetaData" with signature
-    // "sssssss", which takes genre field as the last parameter.
-    nsCString tempGenre = EmptyCString();
-    nsCString tempMediaNumber = EmptyCString();
-    nsCString tempTotalMediaCount = EmptyCString();
-    nsCString tempDuration = EmptyCString();
-
-    if (mMediaNumber >= 0) {
-      tempMediaNumber.AppendInt(mMediaNumber);
-    }
-    if (mTotalMediaCount >= 0) {
-      tempTotalMediaCount.AppendInt(mTotalMediaCount);
-    }
-    if (mDuration >= 0) {
-      tempDuration.AppendInt(mDuration);
-    }
-
-    const nsCString objectPath = NS_ConvertUTF16toUTF8(
-      GetObjectPathFromAddress(sAdapterPath, mDeviceAddress));
-
-    const char* title = mTitle.get();
-    const char* album = mAlbum.get();
-    const char* artist = mArtist.get();
-    const char* mediaNumber = tempMediaNumber.get();
-    const char* totalMediaCount = tempTotalMediaCount.get();
-    const char* duration = tempDuration.get();
-    const char* genre = tempGenre.get();
-
-    bool success = sDBusConnection->SendWithReply(
-      GetVoidCallback, static_cast<void*>(mRunnable.get()), -1,
-      BLUEZ_DBUS_BASE_IFC,
-      objectPath.get(),
-      DBUS_CTL_IFACE, "UpdateMetaData",
-      DBUS_TYPE_STRING, &title,
-      DBUS_TYPE_STRING, &artist,
-      DBUS_TYPE_STRING, &album,
-      DBUS_TYPE_STRING, &mediaNumber,
-      DBUS_TYPE_STRING, &totalMediaCount,
-      DBUS_TYPE_STRING, &duration,
-      DBUS_TYPE_STRING, &genre,
-      DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE(success, NS_OK);
-
-    Unused << mRunnable.forget(); // picked up by callback handler
-
-    return NS_OK;
-  }
-
-private:
-  const BluetoothAddress mDeviceAddress;
-  const nsCString mTitle;
-  const nsCString mArtist;
-  const nsCString mAlbum;
-  int64_t mMediaNumber;
-  int64_t mTotalMediaCount;
-  int64_t mDuration;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-};
-
-void
-BluetoothDBusService::SendMetaData(const nsAString& aTitle,
-                                   const nsAString& aArtist,
-                                   const nsAString& aAlbum,
-                                   int64_t aMediaNumber,
-                                   int64_t aTotalMediaCount,
-                                   int64_t aDuration,
-                                   BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!IsReady()) {
-    NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
-    DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
-    return;
-  }
-
-  BluetoothAvrcpManager* avrcp = BluetoothAvrcpManager::Get();
-  NS_ENSURE_TRUE_VOID(avrcp);
-
-  if (!avrcp->IsConnected()) {
-    DispatchBluetoothReply(aRunnable, BluetoothValue(),
-                           NS_LITERAL_STRING(ERR_AVRCP_IS_DISCONNECTED));
-    return;
-  }
-
-  nsAutoString prevTitle, prevAlbum;
-  avrcp->GetTitle(prevTitle);
-  avrcp->GetAlbum(prevAlbum);
-
-  uint64_t mediaNumber = static_cast<uint64_t>(aMediaNumber);
-  if (mediaNumber != avrcp->GetMediaNumber() ||
-      !aTitle.Equals(prevTitle) ||
-      !aAlbum.Equals(prevAlbum)) {
-    UpdateNotification(ControlEventId::EVENT_TRACK_CHANGED, aMediaNumber);
-  }
-
-  BluetoothAddress deviceAddress;
-  avrcp->GetAddress(deviceAddress);
-
-  DispatchToDBusThread(
-    MakeAndAddRef<SendMetadataTask>(
-      deviceAddress,
-      NS_ConvertUTF16toUTF8(aTitle),
-      NS_ConvertUTF16toUTF8(aArtist),
-      NS_ConvertUTF16toUTF8(aAlbum),
-      aMediaNumber,
-      aTotalMediaCount,
-      aDuration,
-      aRunnable));
-
-  avrcp->UpdateMetaData(aTitle, aArtist, aAlbum,
-                        aMediaNumber, aTotalMediaCount, aDuration);
-}
-
-class SendPlayStatusTask : public Runnable
-{
-public:
-  SendPlayStatusTask(const BluetoothAddress& aDeviceAddress,
-                     int64_t aDuration,
-                     int64_t aPosition,
-                     ControlPlayStatus aPlayStatus,
-                     BluetoothReplyRunnable* aRunnable)
-    : mDeviceAddress(aDeviceAddress)
-    , mDuration(aDuration)
-    , mPosition(aPosition)
-    , mPlayStatus(aPlayStatus)
-    , mRunnable(aRunnable)
-  {
-    MOZ_ASSERT(!mDeviceAddress.IsCleared());
-    MOZ_ASSERT(mRunnable);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-    MOZ_ASSERT(!sAdapterPath.IsEmpty());
-
-    const nsCString objectPath = NS_ConvertUTF16toUTF8(
-      GetObjectPathFromAddress(sAdapterPath, mDeviceAddress));
-
-    uint32_t tempPlayStatus = mPlayStatus;
-
-    bool success = sDBusConnection->SendWithReply(
-      GetVoidCallback, static_cast<void*>(mRunnable.get()), -1,
-      BLUEZ_DBUS_BASE_IFC,
-      objectPath.get(),
-      DBUS_CTL_IFACE, "UpdatePlayStatus",
-      DBUS_TYPE_UINT32, &mDuration,
-      DBUS_TYPE_UINT32, &mPosition,
-      DBUS_TYPE_UINT32, &tempPlayStatus,
-      DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE(success, NS_OK);
-
-    Unused << mRunnable.forget(); // picked up by callback handler
-
-    return NS_OK;
-  }
-
-private:
-  const BluetoothAddress mDeviceAddress;
-  int64_t mDuration;
-  int64_t mPosition;
-  ControlPlayStatus mPlayStatus;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-};
-
-void
-BluetoothDBusService::SendPlayStatus(int64_t aDuration,
-                                     int64_t aPosition,
-                                     ControlPlayStatus aPlayStatus,
-                                     BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!IsReady()) {
-    NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
-    DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
-    return;
-  }
-
-  if (aPlayStatus == ControlPlayStatus::PLAYSTATUS_UNKNOWN) {
-    DispatchBluetoothReply(aRunnable, BluetoothValue(),
-                           NS_LITERAL_STRING("Invalid play status"));
-    return;
-  } else if (aDuration < 0) {
-    DispatchBluetoothReply(aRunnable, BluetoothValue(),
-                           NS_LITERAL_STRING("Invalid duration"));
-    return;
-  } else if (aPosition < 0) {
-    DispatchBluetoothReply(aRunnable, BluetoothValue(),
-                           NS_LITERAL_STRING("Invalid position"));
-    return;
-  }
-
-  BluetoothAvrcpManager* avrcp = BluetoothAvrcpManager::Get();
-  NS_ENSURE_TRUE_VOID(avrcp);
-
-  if (!avrcp->IsConnected()) {
-    DispatchBluetoothReply(aRunnable, BluetoothValue(),
-                           NS_LITERAL_STRING(ERR_AVRCP_IS_DISCONNECTED));
-    return;
-  }
-
-  if (aPlayStatus != avrcp->GetPlayStatus()) {
-    UpdateNotification(ControlEventId::EVENT_PLAYBACK_STATUS_CHANGED,
-                       aPlayStatus);
-  } else if (aPosition != avrcp->GetPosition()) {
-    UpdateNotification(ControlEventId::EVENT_PLAYBACK_POS_CHANGED, aPosition);
-  }
-
-  BluetoothAddress deviceAddress;
-  avrcp->GetAddress(deviceAddress);
-
-  DispatchToDBusThread(
-    MakeAndAddRef<SendPlayStatusTask>(deviceAddress,
-                                      aDuration,
-                                      aPosition,
-                                      aPlayStatus,
-                                      aRunnable));
-
-  avrcp->UpdatePlayStatus(aDuration, aPosition, aPlayStatus);
-}
-
-static void
-ControlCallback(DBusMessage* aMsg, void* aParam)
-{
-  NS_ENSURE_TRUE_VOID(aMsg);
-
-  BluetoothValue v;
-  nsAutoString replyError;
-  UnpackVoidMessage(aMsg, nullptr, v, replyError);
-  if (!v.get_bool()) {
-    BT_WARNING(NS_ConvertUTF16toUTF8(replyError).get());
-  }
-}
-
-class UpdatePlayStatusTask : public Runnable
-{
-public:
-  UpdatePlayStatusTask(const BluetoothAddress& aDeviceAddress,
-                       int32_t aDuration,
-                       int32_t aPosition,
-                       ControlPlayStatus aPlayStatus)
-    : mDeviceAddress(aDeviceAddress)
-    , mDuration(aDuration)
-    , mPosition(aPosition)
-    , mPlayStatus(aPlayStatus)
-  {
-    MOZ_ASSERT(!mDeviceAddress.IsCleared());
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-    MOZ_ASSERT(!sAdapterPath.IsEmpty());
-
-    const nsCString objectPath = NS_ConvertUTF16toUTF8(
-      GetObjectPathFromAddress(sAdapterPath, mDeviceAddress));
-
-    uint32_t tempPlayStatus = mPlayStatus;
-
-    bool success = sDBusConnection->SendWithReply(
-      ControlCallback, nullptr, -1,
-      BLUEZ_DBUS_BASE_IFC,
-      objectPath.get(),
-      DBUS_CTL_IFACE, "UpdatePlayStatus",
-      DBUS_TYPE_UINT32, &mDuration,
-      DBUS_TYPE_UINT32, &mPosition,
-      DBUS_TYPE_UINT32, &tempPlayStatus,
-      DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE(success, NS_OK);
-
-    return NS_OK;
-  }
-
-private:
-  const BluetoothAddress mDeviceAddress;
-  int32_t mDuration;
-  int32_t mPosition;
-  ControlPlayStatus mPlayStatus;
-};
-
-void
-BluetoothDBusService::UpdatePlayStatus(uint32_t aDuration,
-                                       uint32_t aPosition,
-                                       ControlPlayStatus aPlayStatus)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  NS_ENSURE_TRUE_VOID(this->IsReady());
-
-  BluetoothAvrcpManager* avrcp = BluetoothAvrcpManager::Get();
-  NS_ENSURE_TRUE_VOID(avrcp);
-  MOZ_ASSERT(avrcp->IsConnected());
-  MOZ_ASSERT(!sAdapterPath.IsEmpty());
-
-  BluetoothAddress deviceAddress;
-  avrcp->GetAddress(deviceAddress);
-
-  DispatchToDBusThread(
-    MakeAndAddRef<UpdatePlayStatusTask>(deviceAddress,
-                                        aDuration,
-                                        aPosition,
-                                        aPlayStatus));
-}
-
-class UpdateNotificationTask : public Runnable
-{
-public:
-  UpdateNotificationTask(const BluetoothAddress& aDeviceAddress,
-                         BluetoothDBusService::ControlEventId aEventId,
-                         uint64_t aData)
-    : mDeviceAddress(aDeviceAddress)
-    , mEventId(aEventId)
-    , mData(aData)
-  {
-    MOZ_ASSERT(!mDeviceAddress.IsCleared());
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
-    MOZ_ASSERT(sDBusConnection);
-    MOZ_ASSERT(!sAdapterPath.IsEmpty());
-
-    const nsCString objectPath = NS_ConvertUTF16toUTF8(
-      GetObjectPathFromAddress(sAdapterPath, mDeviceAddress));
-
-    uint16_t eventId = mEventId;
-
-    bool success = sDBusConnection->SendWithReply(
-      ControlCallback, nullptr, -1,
-      BLUEZ_DBUS_BASE_IFC,
-      objectPath.get(),
-      DBUS_CTL_IFACE, "UpdateNotification",
-      DBUS_TYPE_UINT16, &eventId,
-      DBUS_TYPE_UINT64, &mData,
-      DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE(success, NS_OK);
-
-    return NS_OK;
-  }
-
-private:
-  const BluetoothAddress mDeviceAddress;
-  int16_t mEventId;
-  int32_t mData;
-};
-
-void
-BluetoothDBusService::UpdateNotification(ControlEventId aEventId,
-                                         uint64_t aData)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  NS_ENSURE_TRUE_VOID(this->IsReady());
-
-  BluetoothAvrcpManager* avrcp = BluetoothAvrcpManager::Get();
-  NS_ENSURE_TRUE_VOID(avrcp);
-  MOZ_ASSERT(avrcp->IsConnected());
-  MOZ_ASSERT(!sAdapterPath.IsEmpty());
-
-  BluetoothAddress deviceAddress;
-  avrcp->GetAddress(deviceAddress);
-
-  DispatchToDBusThread(
-    MakeAndAddRef<UpdateNotificationTask>(deviceAddress, aEventId, aData));
-}
-
-void
-BluetoothDBusService::StartLeScanInternal(
-  const nsTArray<BluetoothUuid>& aServiceUuids,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::StopLeScanInternal(
-  const BluetoothUuid& aAppUuid,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::StartAdvertisingInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattAdvertisingData& aAdvData,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::StopAdvertisingInternal(
-  const BluetoothUuid& aAppUuid,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::ConnectGattClientInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothAddress& aDeviceAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::DisconnectGattClientInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothAddress& aDeviceAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::DiscoverGattServicesInternal(
-  const BluetoothUuid& aAppUuid, BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattClientStartNotificationsInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothGattServiceId& aServId,
-  const BluetoothGattId& aCharId, BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattClientStopNotificationsInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothGattServiceId& aServId,
-  const BluetoothGattId& aCharId, BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::UnregisterGattClientInternal(
-  int aClientIf, BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattClientReadRemoteRssiInternal(
-  int aClientIf, const BluetoothAddress& aDeviceAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattClientReadCharacteristicValueInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattClientWriteCharacteristicValueInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  const BluetoothGattWriteType& aWriteType,
-  const nsTArray<uint8_t>& aValue,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattClientReadDescriptorValueInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  const BluetoothGattId& aDescriptorId,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattClientWriteDescriptorValueInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  const BluetoothGattId& aDescriptorId,
-  const nsTArray<uint8_t>& aValue,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::SetObexPassword(const nsAString& aPassword,
-                                      BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::RejectObexAuth(BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::ReplyTovCardPulling(
-  BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::ReplyTovCardPulling(
-  Blob* aBlob,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::ReplyToPhonebookPulling(
-  BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  uint16_t aPhonebookSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::ReplyToPhonebookPulling(
-  Blob* aBlob,
-  uint16_t aPhonebookSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::ReplyTovCardListing(
-  BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  uint16_t aPhonebookSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::ReplyTovCardListing(
-  Blob* aBlob,
-  uint16_t aPhonebookSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::ReplyToMapFolderListing(long aMasId,
-  const nsAString& aFolderlists,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::ReplyToMapMessagesListing(BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  long aMasId,
-  bool aNewMessage,
-  const nsAString& aTimestamp,
-  int aSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::ReplyToMapMessagesListing(long aMasId,
-  Blob* aBlob,
-  bool aNewMessage,
-  const nsAString& aTimestamp,
-  int aSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::ReplyToMapGetMessage(BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  long aMasId,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::ReplyToMapGetMessage(Blob* aBlob,
-  long aMasId,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::ReplyToMapSetMessageStatus(long aMasId,
-  bool aStatus,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::ReplyToMapSendMessage(long aMasId,
-  const nsAString& aHandleId,
-  bool aStatus,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::ReplyToMapMessageUpdate(long aMasId, bool aStatus,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattServerRegisterInternal(
-  const BluetoothUuid& aAppUuid, BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattServerConnectPeripheralInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothAddress& aAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattServerDisconnectPeripheralInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothAddress& aAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::UnregisterGattServerInternal(
-  int aServerIf, BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattServerAddServiceInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  uint16_t aHandleCount,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattServerAddIncludedServiceInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aIncludedServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattServerAddCharacteristicInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothUuid& aCharacteristicUuid,
-  BluetoothGattAttrPerm aPermissions,
-  BluetoothGattCharProp aProperties,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattServerAddDescriptorInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aCharacteristicHandle,
-  const BluetoothUuid& aDescriptorUuid,
-  BluetoothGattAttrPerm aPermissions,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattServerRemoveServiceInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattServerStartServiceInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattServerStopServiceInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattServerSendIndicationInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAddress& aAddress,
-  const BluetoothAttributeHandle& aCharacteristicHandle,
-  bool aConfirm,
-  const nsTArray<uint8_t>& aValue,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
-
-void
-BluetoothDBusService::GattServerSendResponseInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAddress& aAddress,
-  uint16_t aStatus,
-  int32_t aRequestId,
-  const BluetoothGattResponse& aRsp,
-  BluetoothReplyRunnable* aRunnable)
-{
-}
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothDBusService.h
+++ /dev/null
@@ -1,486 +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_bluez_BluetoothDBusService_h
-#define mozilla_dom_bluetooth_bluez_BluetoothDBusService_h
-
-#include "mozilla/Attributes.h"
-#include "BluetoothCommon.h"
-#include "mozilla/ipc/RawDBusConnection.h"
-#include "BluetoothService.h"
-#include "nsIThread.h"
-
-class DBusMessage;
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-/**
- * BluetoothDBusService is the implementation of BluetoothService for DBus on
- * linux/android/B2G. Function comments are in BluetoothService.h
- */
-
-class BluetoothDBusService : public BluetoothService
-{
-public:
-  /**
-   * For DBus Control method of "UpdateNotification", event id should be
-   * specified as following:
-   * (Please see specification of AVRCP 1.3, Table 5.28 for more details.)
-   */
-  enum ControlEventId {
-    EVENT_PLAYBACK_STATUS_CHANGED            = 0x01,
-    EVENT_TRACK_CHANGED                      = 0x02,
-    EVENT_TRACK_REACHED_END                  = 0x03,
-    EVENT_TRACK_REACHED_START                = 0x04,
-    EVENT_PLAYBACK_POS_CHANGED               = 0x05,
-    EVENT_BATT_STATUS_CHANGED                = 0x06,
-    EVENT_SYSTEM_STATUS_CHANGED              = 0x07,
-    EVENT_PLAYER_APPLICATION_SETTING_CHANGED = 0x08,
-    EVENT_UNKNOWN
-  };
-
-  BluetoothDBusService();
-  ~BluetoothDBusService();
-
-  bool IsReady();
-
-  virtual nsresult StartInternal(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual nsresult StopInternal(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual nsresult
-  GetAdaptersInternal(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual nsresult
-  GetConnectedDevicePropertiesInternal(
-    uint16_t aServiceUuid, BluetoothReplyRunnable* aRunnable) override;
-
-  virtual nsresult
-  GetPairedDevicePropertiesInternal(
-    const nsTArray<BluetoothAddress>& aDeviceAddresses,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual nsresult
-  FetchUuidsInternal(const BluetoothAddress& aDeviceAddress,
-                     BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual nsresult
-  SetProperty(BluetoothObjectType aType,
-              const BluetoothNamedValue& aValue,
-              BluetoothReplyRunnable* aRunnable) override;
-
-  virtual nsresult
-  GetServiceChannel(const BluetoothAddress& aDeviceAddress,
-                    const BluetoothUuid& aServiceUuid,
-                    BluetoothProfileManagerBase* aManager) override;
-
-  virtual bool
-  UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
-                   BluetoothProfileManagerBase* aManager) override;
-
-  virtual nsresult
-  CreatePairedDeviceInternal(const BluetoothAddress& aDeviceAddress,
-                             int aTimeout,
-                             BluetoothReplyRunnable* aRunnable) override;
-
-  virtual nsresult
-  RemoveDeviceInternal(const BluetoothAddress& aDeviceAddress,
-                       BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  PinReplyInternal(const BluetoothAddress& aDeviceAddress,
-                   bool aAccept,
-                   const BluetoothPinCode& aPinCode,
-                   BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  SspReplyInternal(const BluetoothAddress& aDeviceAddress,
-                   BluetoothSspVariant aVariant,
-                   bool aAccept,
-                   BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
-                     const BluetoothPinCode& aPinCode,
-                     BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SetPasskeyInternal(const BluetoothAddress& aDeviceAddress, uint32_t aPasskey,
-                     BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SetPairingConfirmationInternal(const BluetoothAddress& aDeviceAddress,
-                                 bool aConfirm,
-                                 BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  Connect(const BluetoothAddress& aDeviceAddress,
-          uint32_t aCod,
-          uint16_t aServiceUuid,
-          BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  Disconnect(const BluetoothAddress& aDeviceAddress, uint16_t aServiceUuid,
-             BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SendFile(const BluetoothAddress& aDeviceAddress,
-           BlobParent* aBlobParent,
-           BlobChild* aBlobChild,
-           BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SendFile(const BluetoothAddress& aDeviceAddress,
-           Blob* aBlob,
-           BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  StopSendingFile(const BluetoothAddress& aDeviceAddress,
-                  BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ConfirmReceivingFile(const BluetoothAddress& aDeviceAddress, bool aConfirm,
-                       BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ConnectSco(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  DisconnectSco(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  IsScoConnected(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SetObexPassword(const nsAString& aPassword,
-                  BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  RejectObexAuth(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyTovCardPulling(BlobParent* aBlobParent,
-                      BlobChild* aBlobChild,
-                      BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyTovCardPulling(Blob* aBlob,
-                      BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToPhonebookPulling(BlobParent* aBlobParent,
-                          BlobChild* aBlobChild,
-                          uint16_t aPhonebookSize,
-                          BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToPhonebookPulling(Blob* aBlob,
-                          uint16_t aPhonebookSize,
-                          BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyTovCardListing(BlobParent* aBlobParent,
-                      BlobChild* aBlobChild,
-                      uint16_t aPhonebookSize,
-                      BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyTovCardListing(Blob* aBlob,
-                      uint16_t aPhonebookSize,
-                      BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapFolderListing(long aMasId, const nsAString& aFolderlists,
-                          BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapMessagesListing(BlobParent* aBlobParent, BlobChild* aBlobChild,
-                            long aMasId,
-                            bool aNewMessage,
-                            const nsAString& aTimestamp,
-                            int aSize,
-                            BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapMessagesListing(long aMasId,
-                            Blob* aBlob,
-                            bool aNewMessage,
-                            const nsAString& aTimestamp,
-                            int aSize,
-                            BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapGetMessage(BlobParent* aBlobParent,
-                       BlobChild* aBlobChild,
-                       long aMasId,
-                       BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapGetMessage(Blob* aBlob,
-                       long aMasId,
-                       BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapSetMessageStatus(long aMasId,
-                             bool aStatus,
-                             BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapSendMessage(long aMasId,
-                        const nsAString& aHandleId,
-                        bool aStatus,
-                        BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapMessageUpdate(long aMasId,
-                          bool aStatus,
-                          BluetoothReplyRunnable* aRunnable) override;
-
-#ifdef MOZ_B2G_RIL
-  virtual void
-  AnswerWaitingCall(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  IgnoreWaitingCall(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ToggleCalls(BluetoothReplyRunnable* aRunnable);
-#endif
-
-  virtual void
-  SendMetaData(const nsAString& aTitle,
-               const nsAString& aArtist,
-               const nsAString& aAlbum,
-               int64_t aMediaNumber,
-               int64_t aTotalMediaCount,
-               int64_t aDuration,
-               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SendPlayStatus(int64_t aDuration,
-                 int64_t aPosition,
-                 ControlPlayStatus aPlayStatus,
-                 BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  UpdatePlayStatus(uint32_t aDuration,
-                   uint32_t aPosition,
-                   ControlPlayStatus aPlayStatus) override;
-
-  virtual nsresult
-  SendSinkMessage(const nsAString& aDeviceAddresses,
-                  const nsAString& aMessage) override;
-
-  virtual nsresult
-  SendInputMessage(const nsAString& aDeviceAddresses,
-                   const nsAString& aMessage) override;
-
-  virtual void
-  StartLeScanInternal(const nsTArray<BluetoothUuid>& aServiceUuids,
-                      BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  StopLeScanInternal(const BluetoothUuid& aAppUuid,
-                     BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  StartAdvertisingInternal(const BluetoothUuid& aAppUuid,
-                           const BluetoothGattAdvertisingData& aAdvData,
-                           BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  StopAdvertisingInternal(const BluetoothUuid& aAppUuid,
-                          BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ConnectGattClientInternal(const BluetoothUuid& aAppUuid,
-                            const BluetoothAddress& aDeviceAddress,
-                            BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  DisconnectGattClientInternal(const BluetoothUuid& aAppUuid,
-                               const BluetoothAddress& aDeviceAddress,
-                               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  DiscoverGattServicesInternal(const BluetoothUuid& aAppUuid,
-                               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientStartNotificationsInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServId,
-    const BluetoothGattId& aCharId,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientStopNotificationsInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServId,
-    const BluetoothGattId& aCharId,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  UnregisterGattClientInternal(int aClientIf,
-                               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientReadRemoteRssiInternal(
-    int aClientIf, const BluetoothAddress& aDeviceAddress,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientReadCharacteristicValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientWriteCharacteristicValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    const BluetoothGattWriteType& aWriteType,
-    const nsTArray<uint8_t>& aValue,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientReadDescriptorValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    const BluetoothGattId& aDescriptorId,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientWriteDescriptorValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    const BluetoothGattId& aDescriptorId,
-    const nsTArray<uint8_t>& aValue,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerRegisterInternal(
-    const BluetoothUuid& aAppUuid,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerConnectPeripheralInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerDisconnectPeripheralInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  UnregisterGattServerInternal(int aServerIf,
-                               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerAddServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    uint16_t aHandleCount,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerAddIncludedServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aIncludedServiceHandle,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerAddCharacteristicInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothUuid& aCharacteristicUuid,
-    BluetoothGattAttrPerm aPermissions,
-    BluetoothGattCharProp aProperties,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerAddDescriptorInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aCharacteristicHandle,
-    const BluetoothUuid& aDescriptorUuid,
-    BluetoothGattAttrPerm aPermissions,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerRemoveServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerStartServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerStopServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerSendResponseInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    uint16_t aStatus,
-    int32_t aRequestId,
-    const BluetoothGattResponse& aRsp,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerSendIndicationInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    const BluetoothAttributeHandle& aCharacteristicHandle,
-    bool aConfirm,
-    const nsTArray<uint8_t>& aValue,
-    BluetoothReplyRunnable* aRunnable) override;
-
-private:
-  nsresult SendGetPropertyMessage(const nsAString& aPath,
-                                  const char* aInterface,
-                                  void (*aCB)(DBusMessage *, void *),
-                                  BluetoothReplyRunnable* aRunnable);
-
-  nsresult SendDiscoveryMessage(const char* aMessageName,
-                                BluetoothReplyRunnable* aRunnable);
-
-  nsresult SendSetPropertyMessage(const char* aInterface,
-                                  const BluetoothNamedValue& aValue,
-                                  BluetoothReplyRunnable* aRunnable);
-
-  void UpdateNotification(ControlEventId aEventId, uint64_t aData);
-
-  nsresult SendAsyncDBusMessage(const nsAString& aObjectPath,
-                                const char* aInterface,
-                                const nsAString& aMessage,
-                                mozilla::ipc::DBusReplyCallback aCallback);
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluez_BluetoothDBusService_h
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothHfpManager.cpp
+++ /dev/null
@@ -1,2115 +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 "base/basictypes.h"
-
-#include "BluetoothHfpManager.h"
-
-#include "BluetoothProfileController.h"
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-#include "BluetoothSocket.h"
-#include "BluetoothUtils.h"
-#include "BluetoothUuidHelper.h"
-
-#include "jsapi.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/Services.h"
-#include "mozilla/StaticPtr.h"
-#include "nsContentUtils.h"
-#include "nsIObserverService.h"
-#include "nsISettingsService.h"
-#include "nsServiceManagerUtils.h"
-#include "mozilla/dom/BindingUtils.h"
-#include "mozilla/dom/SettingChangeNotificationBinding.h"
-
-#ifdef MOZ_B2G_RIL
-#include "nsIIccInfo.h"
-#include "nsIIccService.h"
-#include "nsIMobileConnectionInfo.h"
-#include "nsIMobileConnectionService.h"
-#include "nsIMobileNetworkInfo.h"
-#include "nsITelephonyService.h"
-#endif
-
-/**
- * BRSF bitmask of AG supported features. See 4.34.1 "Bluetooth Defined AT
- * Capabilities" in Bluetooth hands-free profile 1.6
- */
-#define BRSF_BIT_THREE_WAY_CALLING         1
-#define BSRF_BIT_EC_NR_FUNCTION            (1 << 1)
-#define BRSF_BIT_VOICE_RECOGNITION         (1 << 2)
-#define BRSF_BIT_IN_BAND_RING_TONE         (1 << 3)
-#define BRSF_BIT_ATTACH_NUM_TO_VOICE_TAG   (1 << 4)
-#define BRSF_BIT_ABILITY_TO_REJECT_CALL    (1 << 5)
-#define BRSF_BIT_ENHANCED_CALL_STATUS      (1 << 6)
-#define BRSF_BIT_ENHANCED_CALL_CONTROL     (1 << 7)
-#define BRSF_BIT_EXTENDED_ERR_RESULT_CODES (1 << 8)
-#define BRSF_BIT_CODEC_NEGOTIATION         (1 << 9)
-
-#ifdef MOZ_B2G_RIL
-/**
- * These constants are used in result code such as +CLIP and +CCWA. The value
- * of these constants is the same as TOA_INTERNATIONAL/TOA_UNKNOWN defined in
- * ril_consts.js
- */
-#define TOA_UNKNOWN 0x81
-#define TOA_INTERNATIONAL 0x91
-#endif
-
-#define CR_LF "\xd\xa";
-
-#define MOZSETTINGS_CHANGED_ID               "mozsettings-changed"
-#define AUDIO_VOLUME_BT_SCO_ID               "audio.volume.bt_sco"
-
-#define RESPONSE_CIEV      "+CIEV: "
-#define RESPONSE_CIND      "+CIND: "
-#define RESPONSE_CLCC      "+CLCC: "
-#define RESPONSE_BRSF      "+BRSF: "
-#define RESPONSE_VGS       "+VGS: "
-#define RESPONSE_CME_ERROR "+CME ERROR: "
-
-using namespace mozilla;
-using namespace mozilla::ipc;
-USING_BLUETOOTH_NAMESPACE
-
-namespace {
-  StaticRefPtr<BluetoothHfpManager> sBluetoothHfpManager;
-  bool sInShutdown = false;
-  static const char kHfpCrlf[] = "\xd\xa";
-
-  // UUID of Handsfree Audio Gateway
-  static const BluetoothUuid kHandsfreeAG(HANDSFREE_AG);
-
-  // UUID of Headset Audio Gateway
-  static const BluetoothUuid kHeadsetAG(HEADSET_AG);
-
-  // Unknown service UUID (for SCO socket)
-  static const BluetoothUuid kUnknownService(BluetoothServiceClass::UNKNOWN);
-
-#ifdef MOZ_B2G_RIL
-  // Sending ringtone related
-  static bool sStopSendingRingFlag = true;
-  static int sRingInterval = 3000; //unit: ms
-
-  // Wait for 2 seconds for Dialer processing event 'BLDN'. '2' seconds is a
-  // magic number. The mechanism should be revised once we can get call history.
-  static int sWaitingForDialingInterval = 2000; //unit: ms
-
-  // Wait 3.7 seconds until Dialer stops playing busy tone. '3' seconds is the
-  // time window set in Dialer and the extra '0.7' second is a magic number.
-  // The mechanism should be revised once we know the exact time at which
-  // Dialer stops playing.
-  static int sBusyToneInterval = 3700; //unit: ms
-#endif // MOZ_B2G_RIL
-} // namespace
-
-#ifdef MOZ_B2G_RIL
-/* CallState for sCINDItems[CINDType::CALL].value
- * - NO_CALL: there are no calls in progress
- * - IN_PROGRESS: at least one call is in progress
- */
-enum CallState {
-  NO_CALL,
-  IN_PROGRESS
-};
-
-/* CallSetupState for sCINDItems[CINDType::CALLSETUP].value
- * - NO_CALLSETUP: not currently in call set up
- * - INCOMING: an incoming call process ongoing
- * - OUTGOING: an outgoing call set up is ongoing
- * - OUTGOING_ALERTING: remote party being alerted in an outgoing call
- */
-enum CallSetupState {
-  NO_CALLSETUP,
-  INCOMING,
-  OUTGOING,
-  OUTGOING_ALERTING
-};
-
-/* CallHeldState for sCINDItems[CINDType::CALLHELD].value
- * - NO_CALLHELD: no calls held
- * - ONHOLD_ACTIVE: both an active and a held call
- * - ONHOLD_NOACTIVE: call on hold, no active call
- */
-enum CallHeldState {
-  NO_CALLHELD,
-  ONHOLD_ACTIVE,
-  ONHOLD_NOACTIVE
-};
-#endif // MOZ_B2G_RIL
-
-typedef struct {
-  const char* name;
-  const char* range;
-  int value;
-  bool activated;
-} CINDItem;
-
-enum CINDType {
-  BATTCHG = 1,
-#ifdef MOZ_B2G_RIL
-  CALL,
-  CALLHELD,
-  CALLSETUP,
-  SERVICE,
-  SIGNAL,
-  ROAM
-#endif
-};
-
-static CINDItem sCINDItems[] = {
-  {},
-  {"battchg", "0-5", 5, true},
-#ifdef MOZ_B2G_RIL
-  {"call", "0,1", CallState::NO_CALL, true},
-  {"callheld", "0-2", CallHeldState::NO_CALLHELD, true},
-  {"callsetup", "0-3", CallSetupState::NO_CALLSETUP, true},
-  {"service", "0,1", 0, true},
-  {"signal", "0-5", 0, true},
-  {"roam", "0,1", 0, true}
-#endif
-};
-
-class BluetoothHfpManager::GetVolumeTask final : public nsISettingsServiceCallback
-{
-public:
-  NS_DECL_ISUPPORTS
-
-  NS_IMETHOD
-  Handle(const nsAString& aName, JS::Handle<JS::Value> aResult)
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    JSContext *cx = nsContentUtils::GetCurrentJSContext();
-    NS_ENSURE_TRUE(cx, NS_OK);
-
-    if (!aResult.isNumber()) {
-      BT_WARNING("'" AUDIO_VOLUME_BT_SCO_ID "' is not a number!");
-      return NS_OK;
-    }
-
-    BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-    hfp->mCurrentVgs = aResult.toNumber();
-
-    return NS_OK;
-  }
-
-  NS_IMETHOD
-  HandleError(const nsAString& aName)
-  {
-    BT_WARNING("Unable to get value for '" AUDIO_VOLUME_BT_SCO_ID "'");
-    return NS_OK;
-  }
-
-protected:
-  ~GetVolumeTask() { }
-};
-
-NS_IMPL_ISUPPORTS(BluetoothHfpManager::GetVolumeTask,
-                  nsISettingsServiceCallback);
-
-NS_IMETHODIMP
-BluetoothHfpManager::Observe(nsISupports* aSubject,
-                             const char* aTopic,
-                             const char16_t* aData)
-{
-  if (!strcmp(aTopic, MOZSETTINGS_CHANGED_ID)) {
-    HandleVolumeChanged(aSubject);
-  } else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    HandleShutdown();
-  } else {
-    MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!");
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  return NS_OK;
-}
-
-void
-BluetoothHfpManager::Notify(const hal::BatteryInformation& aBatteryInfo)
-{
-  // Range of battery level: [0, 1], double
-  // Range of CIND::BATTCHG: [0, 5], int
-  int level = round(aBatteryInfo.level() * 5.0);
-  if (level != sCINDItems[CINDType::BATTCHG].value) {
-    sCINDItems[CINDType::BATTCHG].value = level;
-    SendCommand(RESPONSE_CIEV, CINDType::BATTCHG);
-  }
-}
-
-#ifdef MOZ_B2G_RIL
-class BluetoothHfpManager::RespondToBLDNTask : public Runnable
-{
-private:
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(sBluetoothHfpManager);
-
-    if (!sBluetoothHfpManager->mDialingRequestProcessed) {
-      sBluetoothHfpManager->mDialingRequestProcessed = true;
-      sBluetoothHfpManager->SendLine("ERROR");
-    }
-    return NS_OK;
-  }
-};
-
-class BluetoothHfpManager::SendRingIndicatorTask : public Runnable
-{
-public:
-  SendRingIndicatorTask(const nsAString& aNumber, int aType)
-    : mNumber(aNumber)
-    , mType(aType)
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    // Stop sending RING indicator
-    if (sStopSendingRingFlag) {
-      return NS_OK;
-    }
-
-    if (!sBluetoothHfpManager) {
-      BT_WARNING("BluetoothHfpManager no longer exists, cannot send ring!");
-      return NS_OK;
-    }
-
-    nsAutoCString ringMsg("RING");
-    sBluetoothHfpManager->SendLine(ringMsg.get());
-
-    if (!mNumber.IsEmpty()) {
-      nsAutoCString clipMsg("+CLIP: \"");
-      clipMsg.Append(NS_ConvertUTF16toUTF8(mNumber).get());
-      clipMsg.AppendLiteral("\",");
-      clipMsg.AppendInt(mType);
-      sBluetoothHfpManager->SendLine(clipMsg.get());
-    }
-
-    MessageLoop::current()->PostDelayedTask(
-      MakeAndAddRef<SendRingIndicatorTask>(mNumber, mType), sRingInterval);
-
-    return NS_OK;
-  }
-
-private:
-  nsString mNumber;
-  int mType;
-};
-#endif // MOZ_B2G_RIL
-
-class BluetoothHfpManager::CloseScoTask : public Runnable
-{
-private:
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(sBluetoothHfpManager);
-
-    sBluetoothHfpManager->DisconnectSco();
-
-    return NS_OK;
-  }
-};
-
-#ifdef MOZ_B2G_RIL
-static bool
-IsValidDtmf(const char aChar) {
-  // Valid DTMF: [*#0-9ABCD]
-  if (aChar == '*' || aChar == '#') {
-    return true;
-  } else if (aChar >= '0' && aChar <= '9') {
-    return true;
-  } else if (aChar >= 'A' && aChar <= 'D') {
-    return true;
-  }
-  return false;
-}
-
-static bool
-IsMandatoryIndicator(const CINDType aType) {
-  return (aType == CINDType::CALL) ||
-         (aType == CINDType::CALLHELD) ||
-         (aType == CINDType::CALLSETUP);
-}
-
-/**
- *  Call
- */
-Call::Call()
-{
-  Reset();
-}
-
-void
-Call::Reset()
-{
-  mState = nsITelephonyService::CALL_STATE_DISCONNECTED;
-  mDirection = false;
-  mIsConference = false;
-  mNumber.Truncate();
-  mType = TOA_UNKNOWN;
-}
-
-bool
-Call::IsActive()
-{
-  return (mState == nsITelephonyService::CALL_STATE_CONNECTED);
-}
-#endif // MOZ_B2G_RIL
-
-/**
- *  BluetoothHfpManager
- */
-BluetoothHfpManager::BluetoothHfpManager()
-{
-#ifdef MOZ_B2G_RIL
-  mPhoneType = PhoneType::NONE;
-#endif // MOZ_B2G_RIL
-
-  Reset();
-}
-
-#ifdef MOZ_B2G_RIL
-void
-BluetoothHfpManager::ResetCallArray()
-{
-  mCurrentCallArray.Clear();
-  // Append a call object at the beginning of mCurrentCallArray since call
-  // index from RIL starts at 1.
-  Call call;
-  mCurrentCallArray.AppendElement(call);
-
-  if (mPhoneType == PhoneType::CDMA) {
-    mCdmaSecondCall.Reset();
-  }
-}
-#endif // MOZ_B2G_RIL
-
-void
-BluetoothHfpManager::Reset()
-{
-#ifdef MOZ_B2G_RIL
-  sStopSendingRingFlag = true;
-  sCINDItems[CINDType::CALL].value = CallState::NO_CALL;
-  sCINDItems[CINDType::CALLSETUP].value = CallSetupState::NO_CALLSETUP;
-  sCINDItems[CINDType::CALLHELD].value = CallHeldState::NO_CALLHELD;
-#endif
-  for (uint8_t i = 1; i < ArrayLength(sCINDItems); i++) {
-    sCINDItems[i].activated = true;
-  }
-
-#ifdef MOZ_B2G_RIL
-  mCCWA = false;
-  mCLIP = false;
-  mDialingRequestProcessed = true;
-
-  // We disable BSIR by default as it requires OEM implement BT SCO + SPEAKER
-  // output audio path in audio driver. OEM can enable BSIR by setting
-  // mBSIR=true here.
-  //
-  // Please see Bug 878728 for more information.
-  mBSIR = false;
-
-  ResetCallArray();
-#endif
-  mCMEE = false;
-  mCMER = false;
-  mConnectScoRequest = false;
-  mSlcConnected = false;
-  mIsHsp = false;
-  mReceiveVgsFlag = false;
-  mController = nullptr;
-}
-
-bool
-BluetoothHfpManager::Init()
-{
-  // The function must run at b2g process since it would access SettingsService.
-  MOZ_ASSERT(XRE_IsParentProcess());
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE(obs, false);
-
-  if (NS_FAILED(obs->AddObserver(this, MOZSETTINGS_CHANGED_ID, false)) ||
-      NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
-    BT_WARNING("Failed to add observers!");
-    return false;
-  }
-
-  hal::RegisterBatteryObserver(this);
-  // Update to the latest battery level
-  hal::BatteryInformation batteryInfo;
-  hal::GetCurrentBatteryInformation(&batteryInfo);
-  Notify(batteryInfo);
-
-#ifdef MOZ_B2G_RIL
-  mListener = MakeUnique<BluetoothRilListener>();
-  if (!mListener->Listen(true)) {
-    BT_WARNING("Failed to start listening RIL");
-    return false;
-  }
-#endif
-
-  nsCOMPtr<nsISettingsService> settings =
-    do_GetService("@mozilla.org/settingsService;1");
-  NS_ENSURE_TRUE(settings, false);
-
-  nsCOMPtr<nsISettingsServiceLock> settingsLock;
-  nsresult rv = settings->CreateLock(nullptr, getter_AddRefs(settingsLock));
-  NS_ENSURE_SUCCESS(rv, false);
-
-  RefPtr<GetVolumeTask> callback = new GetVolumeTask();
-  rv = settingsLock->Get(AUDIO_VOLUME_BT_SCO_ID, callback);
-  NS_ENSURE_SUCCESS(rv, false);
-
-  Listen();
-
-  mScoSocket = new BluetoothSocket(this);
-  mScoSocketStatus = mScoSocket->GetConnectionStatus();
-  ListenSco();
-  return true;
-}
-
-BluetoothHfpManager::~BluetoothHfpManager()
-{
-#ifdef MOZ_B2G_RIL
-  if (!mListener->Listen(false)) {
-    BT_WARNING("Failed to stop listening RIL");
-  }
-  mListener = nullptr;
-#endif
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-
-  if (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) ||
-      NS_FAILED(obs->RemoveObserver(this, MOZSETTINGS_CHANGED_ID))) {
-    BT_WARNING("Failed to remove observers!");
-  }
-
-  hal::UnregisterBatteryObserver(this);
-}
-
-//static
-BluetoothHfpManager*
-BluetoothHfpManager::Get()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // If sBluetoothHfpManager already exists, exit early
-  if (sBluetoothHfpManager) {
-    return sBluetoothHfpManager;
-  }
-
-  // If we're in shutdown, don't create a new instance
-  NS_ENSURE_FALSE(sInShutdown, nullptr);
-
-  // Create a new instance, register, and return
-  BluetoothHfpManager* manager = new BluetoothHfpManager();
-  NS_ENSURE_TRUE(manager->Init(), nullptr);
-
-  sBluetoothHfpManager = manager;
-  return sBluetoothHfpManager;
-}
-
-void
-BluetoothHfpManager::NotifyConnectionStatusChanged(const nsAString& aType)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Notify Gecko observers
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-
-  nsAutoString deviceAddressStr;
-  AddressToString(mDeviceAddress, deviceAddressStr);
-
-  if (NS_FAILED(obs->NotifyObservers(this, NS_ConvertUTF16toUTF8(aType).get(),
-                                     deviceAddressStr.get()))) {
-    BT_WARNING("Failed to notify observsers!");
-  }
-
-  // Dispatch an event of status change
-  bool status;
-  nsAutoString eventName;
-  if (aType.EqualsLiteral(BLUETOOTH_HFP_STATUS_CHANGED_ID)) {
-    status = IsConnected();
-    eventName.AssignLiteral(HFP_STATUS_CHANGED_ID);
-  } else if (aType.EqualsLiteral(BLUETOOTH_SCO_STATUS_CHANGED_ID)) {
-    status = IsScoConnected();
-    eventName.AssignLiteral(SCO_STATUS_CHANGED_ID);
-  } else {
-    MOZ_ASSERT(false);
-    return;
-  }
-
-  DispatchStatusChangedEvent(eventName, mDeviceAddress, status);
-}
-
-#ifdef MOZ_B2G_RIL
-void
-BluetoothHfpManager::NotifyDialer(const nsAString& aCommand)
-{
-  nsString type, name;
-  BluetoothValue v;
-  InfallibleTArray<BluetoothNamedValue> parameters;
-  type.AssignLiteral("bluetooth-dialer-command");
-
-  name.AssignLiteral("command");
-  v = nsString(aCommand);
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  if (!BroadcastSystemMessage(type, parameters)) {
-    BT_WARNING("Failed to broadcast system message to dialer");
-  }
-}
-#endif // MOZ_B2G_RIL
-
-void
-BluetoothHfpManager::HandleVolumeChanged(nsISupports* aSubject)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // The string that we're interested in will be a JSON string that looks like:
-  //  {"key":"volumeup", "value":10}
-  //  {"key":"volumedown", "value":2}
-
-  RootedDictionary<dom::SettingChangeNotification>
-    setting(RootingCx());
-
-  if (!WrappedJSToDictionary(aSubject, setting)) {
-    return;
-  }
-  if (!setting.mKey.EqualsASCII(AUDIO_VOLUME_BT_SCO_ID)) {
-    return;
-  }
-  if (!setting.mValue.isNumber()) {
-    return;
-  }
-
-  mCurrentVgs = setting.mValue.toNumber();
-
-  // Adjust volume by headset and we don't have to send volume back to headset
-  if (mReceiveVgsFlag) {
-    mReceiveVgsFlag = false;
-    return;
-  }
-
-  // Only send volume back when there's a connected headset
-  if (IsConnected()) {
-    SendCommand(RESPONSE_VGS, mCurrentVgs);
-  }
-}
-
-#ifdef MOZ_B2G_RIL
-void
-BluetoothHfpManager::HandleVoiceConnectionChanged(uint32_t aClientId)
-{
-  nsCOMPtr<nsIMobileConnectionService> mcService =
-    do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE_VOID(mcService);
-
-  nsCOMPtr<nsIMobileConnection> connection;
-  mcService->GetItemByServiceId(aClientId, getter_AddRefs(connection));
-  NS_ENSURE_TRUE_VOID(connection);
-
-  nsCOMPtr<nsIMobileConnectionInfo> voiceInfo;
-  connection->GetVoice(getter_AddRefs(voiceInfo));
-  NS_ENSURE_TRUE_VOID(voiceInfo);
-
-  nsString type;
-  voiceInfo->GetType(type);
-  mPhoneType = GetPhoneType(type);
-
-  bool roaming;
-  voiceInfo->GetRoaming(&roaming);
-  UpdateCIND(CINDType::ROAM, roaming);
-
-  nsString regState;
-  voiceInfo->GetState(regState);
-  bool service = regState.EqualsLiteral("registered");
-  if (service != sCINDItems[CINDType::SERVICE].value) {
-    // Notify BluetoothRilListener of service change
-    mListener->ServiceChanged(aClientId, service);
-  }
-  UpdateCIND(CINDType::SERVICE, service);
-
-  JS::Rooted<JS::Value> value(dom::RootingCx());
-  voiceInfo->GetRelSignalStrength(&value);
-  if (value.isNumber()) {
-    uint8_t signal = ceil(value.toNumber() / 20.0);
-    UpdateCIND(CINDType::SIGNAL, signal);
-  }
-
-  /**
-   * Possible return values for mode are:
-   * - -1 (unknown): set mNetworkSelectionMode to 0 (auto)
-   * - 0 (automatic): set mNetworkSelectionMode to 0 (auto)
-   * - 1 (manual): set mNetworkSelectionMode to 1 (manual)
-   */
-  int32_t mode;
-  connection->GetNetworkSelectionMode(&mode);
-  mNetworkSelectionMode = (mode == 1) ? 1 : 0;
-
-  nsCOMPtr<nsIMobileNetworkInfo> network;
-  voiceInfo->GetNetwork(getter_AddRefs(network));
-  if (!network) {
-    BT_LOGD("Unable to get network information");
-    return;
-  }
-  network->GetLongName(mOperatorName);
-
-  // According to GSM 07.07, "<format> indicates if the format is alphanumeric
-  // or numeric; long alphanumeric format can be upto 16 characters long and
-  // short format up to 8 characters (refer GSM MoU SE.13 [9])..."
-  // However, we found that the operator name may sometimes be longer than 16
-  // characters. After discussion, we decided to fix this here but not in RIL
-  // or modem.
-  //
-  // Please see Bug 871366 for more information.
-  if (mOperatorName.Length() > 16) {
-    BT_WARNING("The operator name was longer than 16 characters. We cut it.");
-    mOperatorName.Left(mOperatorName, 16);
-  }
-}
-
-void
-BluetoothHfpManager::HandleIccInfoChanged(uint32_t aClientId)
-{
-  nsCOMPtr<nsIIccService> service =
-    do_GetService(ICC_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE_VOID(service);
-
-  nsCOMPtr<nsIIcc> icc;
-  service->GetIccByServiceId(aClientId, getter_AddRefs(icc));
-  NS_ENSURE_TRUE_VOID(icc);
-
-  nsCOMPtr<nsIIccInfo> iccInfo;
-  icc->GetIccInfo(getter_AddRefs(iccInfo));
-  NS_ENSURE_TRUE_VOID(iccInfo);
-
-  nsCOMPtr<nsIGsmIccInfo> gsmIccInfo = do_QueryInterface(iccInfo);
-  NS_ENSURE_TRUE_VOID(gsmIccInfo);
-  gsmIccInfo->GetMsisdn(mMsisdn);
-}
-#endif // MOZ_B2G_RIL
-
-void
-BluetoothHfpManager::HandleShutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  sInShutdown = true;
-  Disconnect(nullptr);
-  DisconnectSco();
-  sBluetoothHfpManager = nullptr;
-}
-
-void
-BluetoothHfpManager::ParseAtCommand(const nsACString& aAtCommand,
-                                    const int aStart,
-                                    nsTArray<nsCString>& aRetValues)
-{
-  int length = aAtCommand.Length();
-  int begin = aStart;
-
-  for (int i = aStart; i < length; ++i) {
-    // Use ',' as separator
-    if (aAtCommand[i] == ',') {
-      nsCString tmp(nsDependentCSubstring(aAtCommand, begin, i - begin));
-      aRetValues.AppendElement(tmp);
-
-      begin = i + 1;
-    }
-  }
-
-  nsCString tmp(nsDependentCSubstring(aAtCommand, begin));
-  aRetValues.AppendElement(tmp);
-}
-
-// Virtual function of class SocketConsumer
-void
-BluetoothHfpManager::ReceiveSocketData(BluetoothSocket* aSocket,
-                                       UniquePtr<UnixSocketBuffer>& aMessage)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aSocket);
-
-  nsAutoCString msg(reinterpret_cast<const char*>(aMessage->GetData()),
-                    aMessage->GetSize());
-  msg.StripWhitespace();
-
-  nsTArray<nsCString> atCommandValues;
-
-  // For more information, please refer to 4.34.1 "Bluetooth Defined AT
-  // Capabilities" in Bluetooth hands-free profile 1.6
-  if (msg.Find("AT+BRSF=") != -1) {
-#ifdef MOZ_B2G_RIL
-    uint32_t brsf = BRSF_BIT_ABILITY_TO_REJECT_CALL |
-                    BRSF_BIT_ENHANCED_CALL_STATUS;
-
-    // No support for three way calling in CDMA since
-    // CDMA disallows to hang existing call for CHLD=1
-    if (mPhoneType != PhoneType::CDMA) {
-      brsf |= BRSF_BIT_THREE_WAY_CALLING;
-    }
-
-    if (mBSIR) {
-      brsf |= BRSF_BIT_IN_BAND_RING_TONE;
-    }
-#else
-    uint32_t brsf = 0;
-#endif // MOZ_B2G_RIL
-
-    SendCommand(RESPONSE_BRSF, brsf);
-  } else if (msg.Find("AT+CIND=?") != -1) {
-    // Asking for CIND range
-    SendCommand(RESPONSE_CIND, 0);
-  } else if (msg.Find("AT+CIND?") != -1) {
-    // Asking for CIND value
-    SendCommand(RESPONSE_CIND, 1);
-  } else if (msg.Find("AT+CMER=") != -1) {
-    /**
-     * SLC establishment is done when AT+CMER has been received.
-     * Do nothing but respond with "OK".
-     */
-    ParseAtCommand(msg, 8, atCommandValues);
-
-    if (atCommandValues.Length() < 4) {
-      BT_WARNING("Could't get the value of command [AT+CMER=]");
-      goto respond_with_ok;
-    }
-
-    if (!atCommandValues[0].EqualsLiteral("3") ||
-        !atCommandValues[1].EqualsLiteral("0") ||
-        !atCommandValues[2].EqualsLiteral("0")) {
-      BT_WARNING("Wrong value of CMER");
-      goto respond_with_ok;
-    }
-
-    mCMER = atCommandValues[3].EqualsLiteral("1");
-
-    /**
-     * SLC is connected once the "indicator status update" is enabled by
-     * AT+CMER command. See 4.2.1 in Bluetooth hands-free profile 1.6
-     * for more details.
-     */
-    if (mCMER) {
-      mSlcConnected = true;
-    }
-
-    // If we get internal request for SCO connection,
-    // setup SCO after Service Level Connection established.
-    if (mConnectScoRequest) {
-      mConnectScoRequest = false;
-      ConnectSco();
-    }
-  } else if (msg.Find("AT+CMEE=") != -1) {
-    ParseAtCommand(msg, 8, atCommandValues);
-
-    if (atCommandValues.IsEmpty()) {
-      BT_WARNING("Could't get the value of command [AT+CMEE=]");
-      goto respond_with_ok;
-    }
-
-    // AT+CMEE = 0: +CME ERROR shall not be used
-    // AT+CMEE = 1: use numeric <err>
-    // AT+CMEE = 2: use verbose <err>
-    mCMEE = !atCommandValues[0].EqualsLiteral("0");
-#ifdef MOZ_B2G_RIL
-  } else if (msg.Find("AT+COPS=") != -1) {
-    ParseAtCommand(msg, 8, atCommandValues);
-
-    if (atCommandValues.Length() != 2) {
-      BT_WARNING("Could't get the value of command [AT+COPS=]");
-      goto respond_with_ok;
-    }
-
-    // Handsfree only support AT+COPS=3,0
-    if (!atCommandValues[0].EqualsLiteral("3") ||
-        !atCommandValues[1].EqualsLiteral("0")) {
-      if (mCMEE) {
-        SendCommand(RESPONSE_CME_ERROR,
-                    BluetoothCmeError::OPERATION_NOT_SUPPORTED);
-      } else {
-        SendLine("ERROR");
-      }
-      return;
-    }
-  } else if (msg.Find("AT+COPS?") != -1) {
-    nsAutoCString message("+COPS: ");
-    message.AppendInt(mNetworkSelectionMode);
-    message.AppendLiteral(",0,\"");
-    message.Append(NS_ConvertUTF16toUTF8(mOperatorName));
-    message.Append('"');
-    SendLine(message.get());
-  } else if (msg.Find("AT+VTS=") != -1) {
-    ParseAtCommand(msg, 7, atCommandValues);
-
-    if (atCommandValues.Length() != 1) {
-      BT_WARNING("Couldn't get the value of command [AT+VTS=]");
-      goto respond_with_ok;
-    }
-
-    if (IsValidDtmf(atCommandValues[0].get()[0])) {
-      nsAutoCString message("VTS=");
-      message += atCommandValues[0].get()[0];
-      NotifyDialer(NS_ConvertUTF8toUTF16(message));
-    }
-#endif // MOZ_B2G_RIL
-  } else if (msg.Find("AT+VGM=") != -1) {
-    ParseAtCommand(msg, 7, atCommandValues);
-
-    if (atCommandValues.IsEmpty()) {
-      BT_WARNING("Couldn't get the value of command [AT+VGM]");
-      goto respond_with_ok;
-    }
-
-    nsresult rv;
-    int vgm = atCommandValues[0].ToInteger(&rv);
-    if (NS_FAILED(rv)) {
-      BT_WARNING("Failed to extract microphone volume from bluetooth headset!");
-      goto respond_with_ok;
-    }
-
-    if (vgm < 0 || vgm > 15) {
-      BT_WARNING("Received invalid VGM value");
-      goto respond_with_ok;
-    }
-
-    mCurrentVgm = vgm;
-#ifdef MOZ_B2G_RIL
-  } else if (msg.Find("AT+CHLD=?") != -1) {
-    SendLine("+CHLD: (0,1,2,3)");
-  } else if (msg.Find("AT+CHLD=") != -1) {
-    ParseAtCommand(msg, 8, atCommandValues);
-
-    if (atCommandValues.IsEmpty()) {
-      BT_WARNING("Could't get the value of command [AT+CHLD=]");
-      goto respond_with_ok;
-    }
-
-    /**
-     * The following three cases are supported:
-     * AT+CHLD=0 - Releases all held calls or sets User Determined User Busy
-     *             (UDUB) for a waiting call
-     * AT+CHLD=1 - Releases active calls and accepts the other (held or
-     *             waiting) call
-     * AT+CHLD=2 - Places active calls on hold and accepts the other (held
-     *             or waiting) call
-     * AT+CHLD=3 - Adds a held call to the conversation.
-     *
-     * The following cases are NOT supported yet:
-     * AT+CHLD=1<idx>, AT+CHLD=2<idx>, AT+CHLD=4
-     * Please see 4.33.2 in Bluetooth hands-free profile 1.6 for more
-     * information.
-     */
-    char chld = atCommandValues[0][0];
-    bool valid = true;
-    if (atCommandValues[0].Length() > 1) {
-      BT_WARNING("No index should be included in command [AT+CHLD]");
-      valid = false;
-    } else if (chld == '4') {
-      BT_WARNING("The value of command [AT+CHLD] is not supported");
-      valid = false;
-    } else if (chld == '0') {
-      // We need to rename these dialer commands for better readability
-      // and expandability.
-      // See bug 884190 for more information.
-      NotifyDialer(NS_LITERAL_STRING("CHLD=0"));
-    } else if (chld == '1') {
-      NotifyDialer(NS_LITERAL_STRING("CHLD=1"));
-    } else if (chld == '2') {
-      NotifyDialer(NS_LITERAL_STRING("CHLD=2"));
-    } else if (chld == '3') {
-      NotifyDialer(NS_LITERAL_STRING("CHLD=3"));
-    } else {
-      BT_WARNING("Wrong value of command [AT+CHLD]");
-      valid = false;
-    }
-
-    if (!valid) {
-      SendLine("ERROR");
-      return;
-    }
-#endif // MOZ_B2G_RIL
-  } else if (msg.Find("AT+VGS=") != -1) {
-    // Adjust volume by headset
-    mReceiveVgsFlag = true;
-    ParseAtCommand(msg, 7, atCommandValues);
-
-    if (atCommandValues.IsEmpty()) {
-      BT_WARNING("Could't get the value of command [AT+VGS=]");
-      goto respond_with_ok;
-    }
-
-    nsresult rv;
-    int newVgs = atCommandValues[0].ToInteger(&rv);
-    if (NS_FAILED(rv)) {
-      BT_WARNING("Failed to extract volume value from bluetooth headset!");
-      goto respond_with_ok;
-    }
-
-    if (newVgs == mCurrentVgs) {
-      goto respond_with_ok;
-    }
-
-    if (newVgs < 0 || newVgs > 15) {
-      BT_WARNING("Received invalid VGS value");
-      goto respond_with_ok;
-    }
-
-    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
-    if (!os) {
-      BT_WARNING("Failed to get observer service!");
-      goto respond_with_ok;
-    }
-
-    nsString data;
-    data.AppendInt(newVgs);
-    os->NotifyObservers(nullptr, "bluetooth-volume-change", data.get());
-#ifdef MOZ_B2G_RIL
-  } else if ((msg.Find("AT+BLDN") != -1) || (msg.Find("ATD>") != -1)) {
-    // Dialer app of FFOS v1 does not have plan to support Memory Dailing.
-    // However, in order to pass Bluetooth HFP certification, we still have to
-    // make a call when we receive AT command 'ATD>n'.
-    mDialingRequestProcessed = false;
-
-    if (msg.Find("AT+BLDN") != -1) {
-      NotifyDialer(NS_LITERAL_STRING("BLDN"));
-    } else {
-      NotifyDialer(NS_ConvertUTF8toUTF16(msg));
-    }
-
-    MessageLoop::current()->
-      PostDelayedTask(MakeAndAddRef<RespondToBLDNTask>(),
-                      sWaitingForDialingInterval);
-
-    // Don't send response 'OK' here because we'll respond later in either
-    // RespondToBLDNTask or HandleCallStateChanged()
-    return;
-  } else if (msg.Find("ATA") != -1) {
-    NotifyDialer(NS_LITERAL_STRING("ATA"));
-  } else if (msg.Find("AT+CHUP") != -1) {
-    NotifyDialer(NS_LITERAL_STRING("CHUP"));
-  } else if (msg.Find("AT+CLCC") != -1) {
-    SendCommand(RESPONSE_CLCC);
-  } else if (msg.Find("ATD") != -1) {
-    nsAutoCString message(msg), newMsg;
-    int end = message.FindChar(';');
-    if (end < 0) {
-      BT_WARNING("Could't get the value of command [ATD]");
-      goto respond_with_ok;
-    }
-
-    newMsg += nsDependentCSubstring(message, 0, end);
-    NotifyDialer(NS_ConvertUTF8toUTF16(newMsg));
-  } else if (msg.Find("AT+CLIP=") != -1) {
-    ParseAtCommand(msg, 8, atCommandValues);
-
-    if (atCommandValues.IsEmpty()) {
-      BT_WARNING("Could't get the value of command [AT+CLIP=]");
-      goto respond_with_ok;
-    }
-
-    mCLIP = atCommandValues[0].EqualsLiteral("1");
-  } else if (msg.Find("AT+CCWA=") != -1) {
-    ParseAtCommand(msg, 8, atCommandValues);
-
-    if (atCommandValues.IsEmpty()) {
-      BT_WARNING("Could't get the value of command [AT+CCWA=]");
-      goto respond_with_ok;
-    }
-
-    mCCWA = atCommandValues[0].EqualsLiteral("1");
-  } else if (msg.Find("AT+CKPD") != -1) {
-    if (!sStopSendingRingFlag) {
-      // Bluetooth HSP spec 4.2.2
-      // There is an incoming call, notify Dialer to pick up the phone call
-      // and SCO will be established after we get the CallStateChanged event
-      // indicating the call is answered successfully.
-      NotifyDialer(NS_LITERAL_STRING("ATA"));
-    } else {
-      if (!IsScoConnected()) {
-        // Bluetooth HSP spec 4.3
-        // If there's no SCO, set up a SCO link.
-        ConnectSco();
-      } else if (!mFirstCKPD) {
-        // Bluetooth HSP spec 4.5
-        // There are two ways to release SCO: sending CHUP to dialer or closing
-        // SCO socket directly. We notify dialer only if there is at least one
-        // active call.
-        if (mCurrentCallArray.Length() > 1) {
-          NotifyDialer(NS_LITERAL_STRING("CHUP"));
-        } else {
-          DisconnectSco();
-        }
-      } else {
-        // Three conditions have to be matched to come in here:
-        // (1) Not sending RING indicator
-        // (2) A SCO link exists
-        // (3) This is the very first AT+CKPD=200 of this session
-        // It is the case of Figure 4.3, Bluetooth HSP spec. Do nothing.
-        BT_WARNING("AT+CKPD=200: Do nothing");
-      }
-    }
-
-    mFirstCKPD = false;
-  } else if (msg.Find("AT+CNUM") != -1) {
-    if (!mMsisdn.IsEmpty()) {
-      nsAutoCString message("+CNUM: ,\"");
-      message.Append(NS_ConvertUTF16toUTF8(mMsisdn).get());
-      message.AppendLiteral("\",");
-      message.AppendInt(TOA_UNKNOWN);
-      message.AppendLiteral(",,4");
-      SendLine(message.get());
-    }
-  } else if (msg.Find("AT+BIA=") != -1) {
-    ParseAtCommand(msg, 7, atCommandValues);
-
-    for (uint8_t i = 0; i < atCommandValues.Length(); i++) {
-      CINDType indicatorType = (CINDType) (i + 1);
-      if (indicatorType >= (int)ArrayLength(sCINDItems)) {
-        // Ignore excess parameters at the end
-        break;
-      }
-
-      if (!IsMandatoryIndicator(indicatorType)) {
-        /**
-         * Accept only following indicator states:
-         * - "1": activate
-         * - "0": deactivate
-         * - "" : maintain current state
-         * Otherwise we regard the command incorrectly formatted.
-         */
-        if (atCommandValues[i].EqualsLiteral("1")) {
-          sCINDItems[indicatorType].activated = 1;
-        } else if (atCommandValues[i].EqualsLiteral("0")) {
-          sCINDItems[indicatorType].activated = 0;
-        } else if (!atCommandValues[i].EqualsLiteral("")) {
-          SendLine("ERROR");
-          return;
-        }
-      } else {
-        // Ignore requests to activate/deactivate mandatory indicators
-      }
-    }
-#endif // MOZ_B2G_RIL
-  } else {
-    BT_WARNING("Unsupported AT command: %s, reply with ERROR", msg.get());
-    SendLine("ERROR");
-    return;
-  }
-
-respond_with_ok:
-  // We always respond to remote device with "OK" in general cases.
-  SendLine("OK");
-}
-
-void
-BluetoothHfpManager::Connect(const BluetoothAddress& aDeviceAddress,
-                             BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aController && !mController);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs || sInShutdown) {
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    return;
-  }
-
-  if (mSocket) {
-    if (mDeviceAddress == aDeviceAddress) {
-      aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
-    } else {
-      aController->NotifyCompletion(NS_LITERAL_STRING(ERR_REACHED_CONNECTION_LIMIT));
-    }
-    return;
-  }
-
-  const BluetoothUuid uuid(HANDSFREE);
-
-  if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress, uuid, this))) {
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    return;
-  }
-
-  // Stop listening because currently we only support one connection at a time.
-  if (mHandsfreeSocket) {
-    mHandsfreeSocket->Close();
-    mHandsfreeSocket = nullptr;
-  }
-
-  if (mHeadsetSocket) {
-    mHeadsetSocket->Close();
-    mHeadsetSocket = nullptr;
-  }
-
-  mController = aController;
-  mSocket = new BluetoothSocket(this);
-}
-
-bool
-BluetoothHfpManager::Listen()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (sInShutdown) {
-    BT_WARNING("Listen called while in shutdown!");
-    return false;
-  }
-
-  if (mSocket) {
-    BT_WARNING("mSocket exists. Failed to listen.");
-    return false;
-  }
-
-  if (!mHandsfreeSocket) {
-    mHandsfreeSocket = new BluetoothSocket(this);
-
-    nsresult rv = mHandsfreeSocket->Listen(
-      NS_LITERAL_STRING("Handsfree Audio Gateway"),
-      kHandsfreeAG,
-      BluetoothSocketType::RFCOMM,
-      BluetoothReservedChannels::CHANNEL_HANDSFREE_AG,
-      true, true);
-
-    if (NS_FAILED(rv)) {
-      BT_WARNING("[HFP] Can't listen on RFCOMM socket!");
-      mHandsfreeSocket = nullptr;
-      return false;
-    }
-  }
-
-  if (!mHeadsetSocket) {
-    mHeadsetSocket = new BluetoothSocket(this);
-
-    nsresult rv = mHeadsetSocket->Listen(
-      NS_LITERAL_STRING("Headset Audio Gateway"),
-      kHeadsetAG,
-      BluetoothSocketType::RFCOMM,
-      BluetoothReservedChannels::CHANNEL_HEADSET_AG,
-      true, true);
-
-    if (NS_FAILED(rv)) {
-      BT_WARNING("[HSP] Can't listen on RFCOMM socket!");
-      mHandsfreeSocket->Close();
-      mHandsfreeSocket = nullptr;
-      mHeadsetSocket = nullptr;
-      return false;
-    }
-  }
-
-  return true;
-}
-
-void
-BluetoothHfpManager::Disconnect(BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!mSocket) {
-    if (aController) {
-      aController->NotifyCompletion(
-        NS_LITERAL_STRING(ERR_ALREADY_DISCONNECTED));
-    }
-    return;
-  }
-
-  MOZ_ASSERT(!mController);
-
-  mController = aController;
-  mSocket->Close();
-}
-
-#ifdef MOZ_B2G_RIL
-void
-BluetoothHfpManager::SendCCWA(const nsAString& aNumber, int aType)
-{
-  if (mCCWA) {
-    nsAutoCString ccwaMsg("+CCWA: \"");
-    ccwaMsg.Append(NS_ConvertUTF16toUTF8(aNumber));
-    ccwaMsg.AppendLiteral("\",");
-    ccwaMsg.AppendInt(aType);
-    SendLine(ccwaMsg.get());
-  }
-}
-
-bool
-BluetoothHfpManager::SendCLCC(const Call& aCall, int aIndex)
-{
-  if (aCall.mState == nsITelephonyService::CALL_STATE_DISCONNECTED) {
-    return true;
-  }
-
-  nsAutoCString message(RESPONSE_CLCC);
-  message.AppendInt(aIndex);
-  message.Append(',');
-  message.AppendInt(aCall.mDirection);
-  message.Append(',');
-
-  int status = 0;
-  switch (aCall.mState) {
-    case nsITelephonyService::CALL_STATE_CONNECTED:
-      if (mPhoneType == PhoneType::CDMA && aIndex == 1) {
-        status = (mCdmaSecondCall.IsActive()) ? 1 : 0;
-      }
-      message.AppendInt(status);
-      break;
-    case nsITelephonyService::CALL_STATE_HELD:
-      message.AppendInt(1);
-      break;
-    case nsITelephonyService::CALL_STATE_DIALING:
-      message.AppendInt(2);
-      break;
-    case nsITelephonyService::CALL_STATE_ALERTING:
-      message.AppendInt(3);
-      break;
-    case nsITelephonyService::CALL_STATE_INCOMING:
-      if (!FindFirstCall(nsITelephonyService::CALL_STATE_CONNECTED)) {
-        message.AppendInt(4);
-      } else {
-        message.AppendInt(5);
-      }
-      break;
-    default:
-      BT_WARNING("Not handling call status for CLCC");
-      break;
-  }
-
-  message.AppendLiteral(",0,0,\"");
-  message.Append(NS_ConvertUTF16toUTF8(aCall.mNumber));
-  message.AppendLiteral("\",");
-  message.AppendInt(aCall.mType);
-
-  return SendLine(message.get());
-}
-#endif // MOZ_B2G_RIL
-
-bool
-BluetoothHfpManager::SendLine(const char* aMessage)
-{
-  MOZ_ASSERT(mSocket);
-
-  nsAutoCString msg;
-
-  msg.AppendLiteral(kHfpCrlf);
-  msg.Append(aMessage);
-  msg.AppendLiteral(kHfpCrlf);
-
-  return mSocket->SendSocketData(msg);
-}
-
-bool
-BluetoothHfpManager::SendCommand(const char* aCommand, uint32_t aValue)
-{
-  if (!IsConnected()) {
-    BT_WARNING("Trying to SendCommand() without a SLC");
-    return false;
-  }
-
-  nsAutoCString message;
-  message += aCommand;
-
-  if (!strcmp(aCommand, RESPONSE_CIEV)) {
-    if (!mCMER || !sCINDItems[aValue].activated) {
-      // Indicator status update is disabled
-      return true;
-    }
-
-    if ((aValue < 1) || (aValue > ArrayLength(sCINDItems) - 1)) {
-      BT_WARNING("unexpected CINDType for CIEV command");
-      return false;
-    }
-
-    message.AppendInt(aValue);
-    message.Append(',');
-    message.AppendInt(sCINDItems[aValue].value);
-  } else if (!strcmp(aCommand, RESPONSE_CIND)) {
-    if (!aValue) {
-      // Query for range
-      for (uint8_t i = 1; i < ArrayLength(sCINDItems); i++) {
-        message.AppendLiteral("(\"");
-        message.Append(sCINDItems[i].name);
-        message.AppendLiteral("\",(");
-        message.Append(sCINDItems[i].range);
-        message.Append(')');
-        if (i == (ArrayLength(sCINDItems) - 1)) {
-          message.Append(')');
-          break;
-        }
-        message.AppendLiteral("),");
-      }
-    } else {
-      // Query for value
-      for (uint8_t i = 1; i < ArrayLength(sCINDItems); i++) {
-        message.AppendInt(sCINDItems[i].value);
-        if (i == (ArrayLength(sCINDItems) - 1)) {
-          break;
-        }
-        message.Append(',');
-      }
-    }
-#ifdef MOZ_B2G_RIL
-  } else if (!strcmp(aCommand, RESPONSE_CLCC)) {
-    bool rv = true;
-    uint32_t callNumbers = mCurrentCallArray.Length();
-    uint32_t i;
-    for (i = 1; i < callNumbers; i++) {
-      rv &= SendCLCC(mCurrentCallArray[i], i);
-    }
-
-    if (!mCdmaSecondCall.mNumber.IsEmpty()) {
-      MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
-      MOZ_ASSERT(i == 2);
-
-      rv &= SendCLCC(mCdmaSecondCall, 2);
-    }
-
-    return rv;
-#endif // MOZ_B2G_RIL
-  } else {
-    message.AppendInt(aValue);
-  }
-
-  return SendLine(message.get());
-}
-
-#ifdef MOZ_B2G_RIL
-void
-BluetoothHfpManager::UpdateCIND(uint8_t aType, uint8_t aValue, bool aSend)
-{
-  if (sCINDItems[aType].value != aValue) {
-    sCINDItems[aType].value = aValue;
-    if (aSend) {
-      SendCommand(RESPONSE_CIEV, aType);
-    }
-  }
-}
-
-uint32_t
-BluetoothHfpManager::FindFirstCall(uint16_t aState)
-{
-  uint32_t callLength = mCurrentCallArray.Length();
-
-  for (uint32_t i = 1; i < callLength; ++i) {
-    if (mCurrentCallArray[i].mState == aState) {
-      return i;
-    }
-  }
-
-  return 0;
-}
-
-uint32_t
-BluetoothHfpManager::GetNumberOfCalls(uint16_t aState)
-{
-  uint32_t num = 0;
-  uint32_t callLength = mCurrentCallArray.Length();
-
-  for (uint32_t i = 1; i < callLength; ++i) {
-    if (mCurrentCallArray[i].mState == aState) {
-      ++num;
-    }
-  }
-
-  return num;
-}
-
-uint32_t
-BluetoothHfpManager::GetNumberOfConCalls()
-{
-  uint32_t num = 0;
-  uint32_t callLength = mCurrentCallArray.Length();
-
-  for (uint32_t i = 1; i < callLength; ++i) {
-    if (mCurrentCallArray[i].mIsConference) {
-      ++num;
-    }
-  }
-
-  return num;
-}
-
-uint32_t
-BluetoothHfpManager::GetNumberOfConCalls(uint16_t aState)
-{
-  uint32_t num = 0;
-  uint32_t callLength = mCurrentCallArray.Length();
-
-  for (uint32_t i = 1; i < callLength; ++i) {
-    if (mCurrentCallArray[i].mIsConference
-        && mCurrentCallArray[i].mState == aState) {
-      ++num;
-    }
-  }
-
-  return num;
-}
-
-void
-BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
-                                            uint16_t aCallState,
-                                            const nsAString& aError,
-                                            const nsAString& aNumber,
-                                            const bool aIsOutgoing,
-                                            const bool aIsConference,
-                                            bool aSend)
-{
-  if (!IsConnected()) {
-    // Normal case. No need to print out warnings.
-    return;
-  }
-
-  // aCallIndex can be UINT32_MAX for the pending outgoing call state update.
-  // aCallIndex will be updated again after real call state changes. See Bug
-  // 990467.
-  if (aCallIndex == UINT32_MAX) {
-    return;
-  }
-
-  while (aCallIndex >= mCurrentCallArray.Length()) {
-    Call call;
-    mCurrentCallArray.AppendElement(call);
-  }
-
-  uint16_t prevCallState = mCurrentCallArray[aCallIndex].mState;
-  mCurrentCallArray[aCallIndex].mState = aCallState;
-  mCurrentCallArray[aCallIndex].mDirection = !aIsOutgoing;
-
-  bool prevCallIsConference = mCurrentCallArray[aCallIndex].mIsConference;
-  mCurrentCallArray[aCallIndex].mIsConference = aIsConference;
-
-  // Same logic as implementation in ril_worker.js
-  if (aNumber.Length() && aNumber[0] == '+') {
-    mCurrentCallArray[aCallIndex].mType = TOA_INTERNATIONAL;
-  }
-  mCurrentCallArray[aCallIndex].mNumber = aNumber;
-
-  RefPtr<Runnable> sendRingTask;
-  nsString address;
-
-  switch (aCallState) {
-    case nsITelephonyService::CALL_STATE_HELD:
-      switch (prevCallState) {
-        case nsITelephonyService::CALL_STATE_CONNECTED: {
-          uint32_t numActive =
-            GetNumberOfCalls(nsITelephonyService::CALL_STATE_CONNECTED);
-          uint32_t numHeld =
-            GetNumberOfCalls(nsITelephonyService::CALL_STATE_HELD);
-          uint32_t numConCalls = GetNumberOfConCalls();
-
-          /**
-           * An active call becomes a held call.
-           *
-           * If this call is not a conference call,
-           * - callheld state = ONHOLD_NOACTIVE if no active call remains;
-           * - callheld state = ONHOLD_ACTIVE otherwise.
-           * If this call belongs to a conference call and all other members of
-           * the conference call have become held calls,
-           * - callheld state = ONHOLD_NOACTIVE if no active call remains;
-           * - callheld state = ONHOLD_ACTIVE otherwise.
-           *
-           * Note number of active calls may be 0 in-between state transition
-           * (c1 has become held but c2 has not become active yet), so we regard
-           * no active call remains if there is no other active/held call
-           * besides this changed call/group of conference call.
-           */
-          if (!aIsConference) {
-            if (numActive + numHeld == 1) {
-              // A single active call is put on hold.
-              sCINDItems[CINDType::CALLHELD].value =
-                CallHeldState::ONHOLD_NOACTIVE;
-            } else {
-              // An active call is placed on hold or active/held calls swapped.
-              sCINDItems[CINDType::CALLHELD].value =
-                CallHeldState::ONHOLD_ACTIVE;
-            }
-            SendCommand(RESPONSE_CIEV, CINDType::CALLHELD);
-          } else if (GetNumberOfConCalls(nsITelephonyService::CALL_STATE_HELD)
-                     == numConCalls) {
-            if (numActive + numHeld == numConCalls) {
-              // An active conference call is put on hold.
-              sCINDItems[CINDType::CALLHELD].value =
-                CallHeldState::ONHOLD_NOACTIVE;
-            } else {
-              // Active calls are placed on hold or active/held calls swapped.
-              sCINDItems[CINDType::CALLHELD].value =
-                CallHeldState::ONHOLD_ACTIVE;
-            }
-            SendCommand(RESPONSE_CIEV, CINDType::CALLHELD);
-          }
-          break;
-        }
-        case nsITelephonyService::CALL_STATE_DISCONNECTED:
-          // The call state changed from DISCONNECTED to HELD. It could happen
-          // when user held a call before Bluetooth got connected.
-          if (FindFirstCall(nsITelephonyService::CALL_STATE_CONNECTED)) {
-            // callheld = ONHOLD_ACTIVE if an active call already exists.
-            sCINDItems[CINDType::CALLHELD].value = CallHeldState::ONHOLD_ACTIVE;
-            SendCommand(RESPONSE_CIEV, CINDType::CALLHELD);
-          }
-          break;
-      }
-      break;
-    case nsITelephonyService::CALL_STATE_INCOMING:
-      if (FindFirstCall(nsITelephonyService::CALL_STATE_CONNECTED)) {
-        SendCCWA(aNumber, mCurrentCallArray[aCallIndex].mType);
-        UpdateCIND(CINDType::CALLSETUP, CallSetupState::INCOMING, aSend);
-      } else {
-        // Start sending RING indicator to HF
-        sStopSendingRingFlag = false;
-        UpdateCIND(CINDType::CALLSETUP, CallSetupState::INCOMING, aSend);
-
-        if (mBSIR) {
-          // Setup audio connection for in-band ring tone
-          ConnectSco();
-        }
-
-        nsAutoString number(aNumber);
-        if (!mCLIP) {
-          number.Truncate();
-        }
-
-        MessageLoop::current()->PostDelayedTask(
-          MakeAndAddRef<SendRingIndicatorTask>(
-            number, mCurrentCallArray[aCallIndex].mType),
-          sRingInterval);
-      }
-      break;
-    case nsITelephonyService::CALL_STATE_DIALING:
-      if (!mDialingRequestProcessed) {
-        SendLine("OK");
-        mDialingRequestProcessed = true;
-      }
-
-      UpdateCIND(CINDType::CALLSETUP, CallSetupState::OUTGOING, aSend);
-      ConnectSco();
-      break;
-    case nsITelephonyService::CALL_STATE_ALERTING:
-      UpdateCIND(CINDType::CALLSETUP, CallSetupState::OUTGOING_ALERTING, aSend);
-
-      // If there's an ongoing call when the headset is just connected, we have
-      // to open a sco socket here.
-      ConnectSco();
-      break;
-    case nsITelephonyService::CALL_STATE_CONNECTED:
-      /**
-       * A call becomes active because:
-       * - user answers an incoming call,
-       * - user dials a outgoing call and it is answered, or
-       * - SLC is connected when a call is active.
-       */
-      switch (prevCallState) {
-        case nsITelephonyService::CALL_STATE_INCOMING:
-        case nsITelephonyService::CALL_STATE_DISCONNECTED:
-          // Incoming call, no break
-          sStopSendingRingFlag = true;
-          ConnectSco();
-          // NO BREAK HERE. continue to next statement
-        case nsITelephonyService::CALL_STATE_DIALING:
-        case nsITelephonyService::CALL_STATE_ALERTING:
-          // Outgoing call
-          UpdateCIND(CINDType::CALL, CallState::IN_PROGRESS, aSend);
-          UpdateCIND(CINDType::CALLSETUP, CallSetupState::NO_CALLSETUP, aSend);
-
-          if (FindFirstCall(nsITelephonyService::CALL_STATE_HELD)) {
-            // callheld state = ONHOLD_ACTIVE if a held call already exists.
-            UpdateCIND(CINDType::CALLHELD, CallHeldState::ONHOLD_ACTIVE, aSend);
-          }
-          break;
-        case nsITelephonyService::CALL_STATE_CONNECTED:
-          // User wants to add a held call to the conversation.
-          // The original connected call becomes a conference call here.
-          if (aIsConference) {
-            UpdateCIND(CINDType::CALLHELD, CallHeldState::NO_CALLHELD, aSend);
-          }
-          break;
-        case nsITelephonyService::CALL_STATE_HELD:
-          if (!FindFirstCall(nsITelephonyService::CALL_STATE_HELD)) {
-            if (aIsConference && !prevCallIsConference) {
-              // The held call was merged and becomes a conference call.
-              UpdateCIND(CINDType::CALLHELD, CallHeldState::NO_CALLHELD, aSend);
-            } else if (sCINDItems[CINDType::CALLHELD].value ==
-                       CallHeldState::ONHOLD_NOACTIVE) {
-              // The held call(s) become connected call(s).
-              UpdateCIND(CINDType::CALLHELD, CallHeldState::NO_CALLHELD, aSend);
-            }
-          }
-          break;
-
-        default:
-          BT_WARNING("Not handling state changed");
-      }
-      break;
-    case nsITelephonyService::CALL_STATE_DISCONNECTED:
-      switch (prevCallState) {
-        case nsITelephonyService::CALL_STATE_INCOMING:
-          // Incoming call, no break
-          sStopSendingRingFlag = true;
-        case nsITelephonyService::CALL_STATE_DIALING:
-        case nsITelephonyService::CALL_STATE_ALERTING:
-          // Outgoing call
-          UpdateCIND(CINDType::CALLSETUP, CallSetupState::NO_CALLSETUP, aSend);
-          break;
-        case nsITelephonyService::CALL_STATE_CONNECTED:
-          // No call is ongoing
-          if (sCINDItems[CINDType::CALLHELD].value ==
-              CallHeldState::NO_CALLHELD) {
-            UpdateCIND(CINDType::CALL, CallState::NO_CALL, aSend);
-          }
-          break;
-        default:
-          BT_WARNING("Not handling state changed");
-      }
-
-      // Handle held calls separately
-      if (!FindFirstCall(nsITelephonyService::CALL_STATE_HELD)) {
-        UpdateCIND(CINDType::CALLHELD, CallHeldState::NO_CALLHELD, aSend);
-      } else if (!FindFirstCall(nsITelephonyService::CALL_STATE_CONNECTED)) {
-        UpdateCIND(CINDType::CALLHELD, CallHeldState::ONHOLD_NOACTIVE, aSend);
-      } else {
-        UpdateCIND(CINDType::CALLHELD, CallHeldState::ONHOLD_ACTIVE, aSend);
-      }
-
-      // -1 is necessary because call 0 is an invalid (padding) call object.
-      if (mCurrentCallArray.Length() - 1 ==
-          GetNumberOfCalls(nsITelephonyService::CALL_STATE_DISCONNECTED)) {
-        // In order to let user hear busy tone via connected Bluetooth headset,
-        // we postpone the timing of dropping SCO.
-        if (!(aError.Equals(NS_LITERAL_STRING("BusyError")))) {
-          DisconnectSco();
-        } else {
-          // Close Sco later since Dialer is still playing busy tone via HF.
-          MessageLoop::current()->PostDelayedTask(MakeAndAddRef<CloseScoTask>(),
-                                                  sBusyToneInterval);
-        }
-
-        ResetCallArray();
-      }
-      break;
-    default:
-      BT_WARNING("Not handling state changed");
-      break;
-  }
-}
-
-PhoneType
-BluetoothHfpManager::GetPhoneType(const nsAString& aType)
-{
-  // FIXME: Query phone type from RIL after RIL implements new API (bug 912019)
-  if (aType.EqualsLiteral("gsm") || aType.EqualsLiteral("gprs") ||
-      aType.EqualsLiteral("edge") || aType.EqualsLiteral("umts") ||
-      aType.EqualsLiteral("hspa") || aType.EqualsLiteral("hsdpa") ||
-      aType.EqualsLiteral("hsupa") || aType.EqualsLiteral("hspa+")) {
-    return PhoneType::GSM;
-  } else if (aType.EqualsLiteral("is95a") || aType.EqualsLiteral("is95b") ||
-             aType.EqualsLiteral("1xrtt") || aType.EqualsLiteral("evdo0") ||
-             aType.EqualsLiteral("evdoa") || aType.EqualsLiteral("evdob")) {
-    return PhoneType::CDMA;
-  }
-
-  return PhoneType::NONE;
-}
-
-void
-BluetoothHfpManager::UpdateSecondNumber(const nsAString& aNumber)
-{
-  MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
-
-  // Always regard second call as incoming call since v1.2 RIL
-  // doesn't support outgoing second call in CDMA.
-  mCdmaSecondCall.mDirection = true;
-
-  mCdmaSecondCall.mNumber = aNumber;
-  mCdmaSecondCall.mType = (aNumber[0] == '+') ? TOA_INTERNATIONAL :
-                                                TOA_UNKNOWN;
-
-  SendCCWA(aNumber, mCdmaSecondCall.mType);
-  UpdateCIND(CINDType::CALLSETUP, CallSetupState::INCOMING, true);
-}
-
-void
-BluetoothHfpManager::AnswerWaitingCall()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
-
-  // Pick up second call. First call is held now.
-  mCdmaSecondCall.mState = nsITelephonyService::CALL_STATE_CONNECTED;
-  UpdateCIND(CINDType::CALLSETUP, CallSetupState::NO_CALLSETUP, true);
-
-  sCINDItems[CINDType::CALLHELD].value = CallHeldState::ONHOLD_ACTIVE;
-  SendCommand(RESPONSE_CIEV, CINDType::CALLHELD);
-}
-
-void
-BluetoothHfpManager::IgnoreWaitingCall()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
-
-  mCdmaSecondCall.Reset();
-  UpdateCIND(CINDType::CALLSETUP, CallSetupState::NO_CALLSETUP, true);
-}
-
-void
-BluetoothHfpManager::ToggleCalls()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
-
-  // Toggle acitve and held calls
-  mCdmaSecondCall.mState = (mCdmaSecondCall.IsActive()) ?
-                             nsITelephonyService::CALL_STATE_HELD :
-                             nsITelephonyService::CALL_STATE_CONNECTED;
-}
-#endif // MOZ_B2G_RIL
-
-void
-BluetoothHfpManager::OnSocketConnectSuccess(BluetoothSocket* aSocket)
-{
-  MOZ_ASSERT(aSocket);
-#ifdef MOZ_B2G_RIL
-  MOZ_ASSERT(mListener);
-#endif
-
-  // Success to create a SCO socket
-  if (aSocket == mScoSocket) {
-    OnScoConnectSuccess();
-    return;
-  }
-
-  /**
-   * If the created connection is an inbound connection, close another server
-   * socket because currently only one SLC is allowed. After that, we need to
-   * make sure that both server socket would be nulled out. As for outbound
-   * connections, we do nothing since sockets have been already handled in
-   * function Connect().
-   */
-  if (aSocket == mHandsfreeSocket) {
-    MOZ_ASSERT(!mSocket);
-    mIsHsp = false;
-    mHandsfreeSocket.swap(mSocket);
-
-    mHeadsetSocket->Close();
-    mHeadsetSocket = nullptr;
-  } else if (aSocket == mHeadsetSocket) {
-    MOZ_ASSERT(!mSocket);
-    mIsHsp = true;
-    mHeadsetSocket.swap(mSocket);
-
-    mHandsfreeSocket->Close();
-    mHandsfreeSocket = nullptr;
-  }
-
-#ifdef MOZ_B2G_RIL
-  // Enumerate current calls
-  mListener->EnumerateCalls();
-
-  mFirstCKPD = true;
-#endif
-
-  // Cache device path for NotifySettings() since we can't get socket address
-  // when a headset disconnect with us
-  mSocket->GetAddress(mDeviceAddress);
-  NotifyConnectionStatusChanged(
-    NS_LITERAL_STRING(BLUETOOTH_HFP_STATUS_CHANGED_ID));
-
-  ListenSco();
-
-  OnConnect(EmptyString());
-}
-
-void
-BluetoothHfpManager::OnSocketConnectError(BluetoothSocket* aSocket)
-{
-  // Failed to create a SCO socket
-  if (aSocket == mScoSocket) {
-    OnScoConnectError();
-    return;
-  }
-
-  mHandsfreeSocket = nullptr;
-  mHeadsetSocket = nullptr;
-
-  OnConnect(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
-}
-
-void
-BluetoothHfpManager::OnSocketDisconnect(BluetoothSocket* aSocket)
-{
-  MOZ_ASSERT(aSocket);
-
-  if (aSocket == mScoSocket) {
-    // SCO socket is closed
-    OnScoDisconnect();
-    return;
-  }
-
-  if (aSocket != mSocket) {
-    // Do nothing when a listening server socket is closed.
-    return;
-  }
-
-  DisconnectSco();
-
-  NotifyConnectionStatusChanged(
-    NS_LITERAL_STRING(BLUETOOTH_HFP_STATUS_CHANGED_ID));
-  OnDisconnect(EmptyString());
-
-  Reset();
-}
-
-void
-BluetoothHfpManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
-{
-  // UpdateSdpRecord() is not called so this callback function should not
-  // be invoked.
-  MOZ_ASSERT_UNREACHABLE("UpdateSdpRecords() should be called somewhere");
-}
-
-void
-BluetoothHfpManager::OnGetServiceChannel(
-  const BluetoothAddress& aDeviceAddress,
-  const BluetoothUuid& aServiceUuid,
-  int aChannel)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!aDeviceAddress.IsCleared());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  if (aChannel < 0) {
-    // If we can't find Handsfree server channel number on the remote device,
-    // try to create HSP connection instead.
-    const BluetoothUuid uuid(HEADSET);
-
-    if (aServiceUuid == uuid) {
-      OnConnect(NS_LITERAL_STRING(ERR_SERVICE_CHANNEL_NOT_FOUND));
-    } else if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress,
-                                               uuid, this))) {
-      OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    } else {
-      mIsHsp = true;
-    }
-
-    return;
-  }
-
-  MOZ_ASSERT(mSocket);
-
-  nsresult rv = mSocket->Connect(aDeviceAddress,
-                                 mIsHsp? kHeadsetAG : kHandsfreeAG,
-                                 BluetoothSocketType::RFCOMM,
-                                 aChannel,
-                                 true, true);
-  if (NS_FAILED(rv)) {
-    OnConnect(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
-  }
-}
-
-void
-BluetoothHfpManager::OnScoConnectSuccess()
-{
-  // For active connection request, we need to reply the DOMRequest
-  if (mScoRunnable) {
-    DispatchReplySuccess(mScoRunnable);
-    mScoRunnable = nullptr;
-  }
-
-  NotifyConnectionStatusChanged(
-    NS_LITERAL_STRING(BLUETOOTH_SCO_STATUS_CHANGED_ID));
-
-  mScoSocketStatus = mScoSocket->GetConnectionStatus();
-}
-
-void
-BluetoothHfpManager::OnScoConnectError()
-{
-  if (mScoRunnable) {
-    DispatchReplyError(mScoRunnable,
-                       NS_LITERAL_STRING("Failed to create SCO socket!"));
-    mScoRunnable = nullptr;
-  }
-
-  ListenSco();
-}
-
-void
-BluetoothHfpManager::OnScoDisconnect()
-{
-  if (mScoSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) {
-    ListenSco();
-    NotifyConnectionStatusChanged(
-      NS_LITERAL_STRING(BLUETOOTH_SCO_STATUS_CHANGED_ID));
-  }
-}
-
-bool
-BluetoothHfpManager::IsConnected()
-{
-  if (mSocket) {
-    return mSocket->GetConnectionStatus() ==
-           SocketConnectionStatus::SOCKET_CONNECTED;
-  }
-
-  return false;
-}
-
-void
-BluetoothHfpManager::GetAddress(BluetoothAddress& aDeviceAddress)
-{
-  return mSocket->GetAddress(aDeviceAddress);
-}
-
-bool
-BluetoothHfpManager::ConnectSco(BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE(!sInShutdown, false);
-  NS_ENSURE_TRUE(IsConnected(), false);
-
-  SocketConnectionStatus status = mScoSocket->GetConnectionStatus();
-  if (status == SocketConnectionStatus::SOCKET_CONNECTED ||
-      status == SocketConnectionStatus::SOCKET_CONNECTING ||
-      (mScoRunnable && (mScoRunnable != aRunnable))) {
-    BT_WARNING("SCO connection exists or is being established");
-    return false;
-  }
-
-  // If we are not using HSP, we have to make sure Service Level Connection
-  // established before we start to set up SCO (synchronous connection).
-  if (!mSlcConnected && !mIsHsp) {
-    mConnectScoRequest = true;
-    BT_WARNING("ConnectSco called before Service Level Connection established");
-    return false;
-  }
-
-  // Stop listening
-  mScoSocket->Close();
-
-  mScoSocket->Connect(mDeviceAddress, kUnknownService,
-                      BluetoothSocketType::SCO,
-                      -1, true, false);
-  mScoSocketStatus = mScoSocket->GetConnectionStatus();
-
-  mScoRunnable = aRunnable;
-  return true;
-}
-
-bool
-BluetoothHfpManager::DisconnectSco()
-{
-  if (!IsScoConnected()) {
-    BT_WARNING("SCO has been already disconnected.");
-    return false;
-  }
-
-  mScoSocket->Close();
-  return true;
-}
-
-bool
-BluetoothHfpManager::ListenSco()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (sInShutdown) {
-    BT_WARNING("ListenSco called while in shutdown!");
-    return false;
-  }
-
-  if (mScoSocket->GetConnectionStatus() ==
-      SocketConnectionStatus::SOCKET_LISTENING) {
-    BT_WARNING("SCO socket has been already listening");
-    return false;
-  }
-
-  mScoSocket->Close();
-
-  nsresult rv = mScoSocket->Listen(
-    NS_LITERAL_STRING("Handsfree Audio Gateway SCO"),
-    kUnknownService,
-    BluetoothSocketType::SCO,
-    -1, true, false);
-
-  if (NS_FAILED(rv)) {
-    BT_WARNING("Can't listen on SCO socket!");
-    return false;
-  }
-
-  mScoSocketStatus = mScoSocket->GetConnectionStatus();
-  return true;
-}
-
-bool
-BluetoothHfpManager::IsScoConnected()
-{
-  if (mScoSocket) {
-    return mScoSocket->GetConnectionStatus() ==
-           SocketConnectionStatus::SOCKET_CONNECTED;
-  }
-  return false;
-}
-
-void
-BluetoothHfpManager::OnConnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // When we failed to create a socket, restart listening.
-  if (!aErrorStr.IsEmpty()) {
-    mSocket = nullptr;
-    Listen();
-  }
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  RefPtr<BluetoothProfileController> controller = mController.forget();
-  controller->NotifyCompletion(aErrorStr);
-}
-
-void
-BluetoothHfpManager::OnDisconnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Start listening
-  mSocket = nullptr;
-  Listen();
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  RefPtr<BluetoothProfileController> controller = mController.forget();
-  controller->NotifyCompletion(aErrorStr);
-}
-
-bool
-BluetoothHfpManager::IsNrecEnabled()
-{
-  // Add this function and return default value to avoid build break
-  // since NREC function isn't developed in bluez yet.
-  // Please see Bug 825149 for more information.
-  return HFP_NREC_STARTED;
-}
-
-NS_IMPL_ISUPPORTS(BluetoothHfpManager, nsIObserver)
-
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothHfpManager.h
+++ /dev/null
@@ -1,233 +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_bluez_BluetoothHfpManager_h
-#define mozilla_dom_bluetooth_bluez_BluetoothHfpManager_h
-
-#include "BluetoothCommon.h"
-#include "BluetoothHfpManagerBase.h"
-#ifdef MOZ_B2G_RIL
-#include "BluetoothRilListener.h"
-#endif
-#include "BluetoothSocketObserver.h"
-#include "mozilla/ipc/SocketBase.h"
-#include "mozilla/Hal.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothReplyRunnable;
-class BluetoothSocket;
-
-#ifdef MOZ_B2G_RIL
-class Call;
-
-/**
- * These costants are defined in 4.33.2 "AT Capabilities Re-Used from GSM 07.07
- * and 3GPP 27.007" in Bluetooth hands-free profile 1.6
- */
-enum BluetoothCmeError {
-  AG_FAILURE = 0,
-  NO_CONNECTION_TO_PHONE = 1,
-  OPERATION_NOT_ALLOWED = 3,
-  OPERATION_NOT_SUPPORTED = 4,
-  PIN_REQUIRED = 5,
-  SIM_NOT_INSERTED = 10,
-  SIM_PIN_REQUIRED = 11,
-  SIM_PUK_REQUIRED = 12,
-  SIM_FAILURE = 13,
-  SIM_BUSY = 14,
-  INCORRECT_PASSWORD = 16,
-  SIM_PIN2_REQUIRED = 17,
-  SIM_PUK2_REQUIRED = 18,
-  MEMORY_FULL = 20,
-  INVALID_INDEX = 21,
-  MEMORY_FAILURE = 23,
-  TEXT_STRING_TOO_LONG = 24,
-  INVALID_CHARACTERS_IN_TEXT_STRING = 25,
-  DIAL_STRING_TOO_LONG = 26,
-  INVALID_CHARACTERS_IN_DIAL_STRING = 27,
-  NO_NETWORK_SERVICE = 30,
-  NETWORK_TIMEOUT = 31,
-  NETWORK_NOT_ALLOWED = 32
-};
-
-enum PhoneType {
-  NONE, // no connection
-  GSM,
-  CDMA
-};
-
-class Call {
-public:
-  Call();
-  void Reset();
-  bool IsActive();
-
-  uint16_t mState;
-  bool mDirection; // true: incoming call; false: outgoing call
-  bool mIsConference;
-  nsString mNumber;
-  int mType;
-};
-#endif // MOZ_B2G_RIL
-
-class BluetoothHfpManager : public BluetoothSocketObserver
-                          , public BluetoothHfpManagerBase
-                          , public BatteryObserver
-{
-public:
-  BT_DECL_HFP_MGR_BASE
-  BT_DECL_SOCKET_OBSERVER
-  virtual void GetName(nsACString& aName)
-  {
-    aName.AssignLiteral("HFP/HSP");
-  }
-
-  static BluetoothHfpManager* Get();
-  bool Listen();
-
-  /**
-   * This function set up a Synchronous Connection (SCO) link for HFP.
-   * Service Level Connection (SLC) should be established before SCO setup
-   * process.
-   * If SLC haven't been established, this function will return false and
-   * send a request to set up SCO ater HfpManager receive AT+CMER, unless we are
-   * connecting HSP socket rather than HFP socket.
-   *
-   * @param  aRunnable Indicate a BluetoothReplyRunnable to execute this
-   *                   function. The default value is nullpter
-   * @return <code>true</code> if SCO established successfully
-   */
-  bool ConnectSco(BluetoothReplyRunnable* aRunnable = nullptr);
-  bool DisconnectSco();
-  bool ListenSco();
-
-#ifdef MOZ_B2G_RIL
-  /**
-   * @param aSend A boolean indicates whether we need to notify headset or not
-   */
-  void HandleCallStateChanged(uint32_t aCallIndex, uint16_t aCallState,
-                              const nsAString& aError, const nsAString& aNumber,
-                              const bool aIsOutgoing, const bool aIsConference,
-                              bool aSend);
-  void HandleIccInfoChanged(uint32_t aClientId);
-  void HandleVoiceConnectionChanged(uint32_t aClientId);
-
-  // CDMA-specific functions
-  void UpdateSecondNumber(const nsAString& aNumber);
-  void AnswerWaitingCall();
-  void IgnoreWaitingCall();
-  void ToggleCalls();
-#endif
-
-protected:
-  ~BluetoothHfpManager();
-
-private:
-  void ParseAtCommand(const nsACString& aAtCommand, const int aStart,
-                      nsTArray<nsCString>& aRetValues);
-
-  class CloseScoTask;
-  class GetVolumeTask;
-#ifdef MOZ_B2G_RIL
-  class RespondToBLDNTask;
-  class SendRingIndicatorTask;
-#endif
-
-  friend class CloseScoTask;
-  friend class GetVolumeTask;
-#ifdef MOZ_B2G_RIL
-  friend class RespondToBLDNTask;
-  friend class SendRingIndicatorTask;
-#endif
-  friend class BluetoothHfpManagerObserver;
-
-  BluetoothHfpManager();
-  void HandleShutdown();
-  void HandleVolumeChanged(nsISupports* aSubject);
-
-  bool Init();
-  void Notify(const hal::BatteryInformation& aBatteryInfo);
-#ifdef MOZ_B2G_RIL
-  void ResetCallArray();
-  uint32_t FindFirstCall(uint16_t aState);
-  uint32_t GetNumberOfCalls(uint16_t aState);
-  uint32_t GetNumberOfConCalls();
-  uint32_t GetNumberOfConCalls(uint16_t aState);
-  PhoneType GetPhoneType(const nsAString& aType);
-#endif
-
-  void NotifyConnectionStatusChanged(const nsAString& aType);
-  void NotifyDialer(const nsAString& aCommand);
-
-#ifdef MOZ_B2G_RIL
-  void SendCCWA(const nsAString& aNumber, int aType);
-  bool SendCLCC(const Call& aCall, int aIndex);
-#endif
-  bool SendCommand(const char* aCommand, uint32_t aValue = 0);
-  bool SendLine(const char* aMessage);
-#ifdef MOZ_B2G_RIL
-  void UpdateCIND(uint8_t aType, uint8_t aValue, bool aSend = true);
-#endif
-  void OnScoConnectSuccess();
-  void OnScoConnectError();
-  void OnScoDisconnect();
-
-  int mCurrentVgs;
-  int mCurrentVgm;
-#ifdef MOZ_B2G_RIL
-  bool mBSIR;
-  bool mCCWA;
-  bool mCLIP;
-#endif
-  bool mCMEE;
-  bool mCMER;
-  bool mConnectScoRequest;
-  bool mSlcConnected;
-  bool mIsHsp;
-#ifdef MOZ_B2G_RIL
-  bool mFirstCKPD;
-  int mNetworkSelectionMode;
-  PhoneType mPhoneType;
-#endif
-  bool mReceiveVgsFlag;
-#ifdef MOZ_B2G_RIL
-  bool mDialingRequestProcessed;
-#endif
-  BluetoothAddress mDeviceAddress;
-#ifdef MOZ_B2G_RIL
-  nsString mMsisdn;
-  nsString mOperatorName;
-
-  nsTArray<Call> mCurrentCallArray;
-  UniquePtr<BluetoothRilListener> mListener;
-#endif
-  RefPtr<BluetoothProfileController> mController;
-  RefPtr<BluetoothReplyRunnable> mScoRunnable;
-
-  // If a connection has been established, mSocket will be the socket
-  // communicating with the remote socket. We maintain the invariant that if
-  // mSocket is non-null, mHandsfreeSocket and mHeadsetSocket must be null (and
-  // vice versa).
-  RefPtr<BluetoothSocket> mSocket;
-
-  // Server sockets. Once an inbound connection is established, it will hand
-  // over the ownership to mSocket, and get a new server socket while Listen()
-  // is called.
-  RefPtr<BluetoothSocket> mHandsfreeSocket;
-  RefPtr<BluetoothSocket> mHeadsetSocket;
-  RefPtr<BluetoothSocket> mScoSocket;
-  mozilla::ipc::SocketConnectionStatus mScoSocketStatus;
-
-#ifdef MOZ_B2G_RIL
-  // CDMA-specific variable
-  Call mCdmaSecondCall;
-#endif
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluez_BluetoothHfpManager_h
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothHidManager.cpp
+++ /dev/null
@@ -1,304 +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 "base/basictypes.h"
-
-#include "BluetoothHidManager.h"
-
-#include "BluetoothCommon.h"
-#include "BluetoothService.h"
-#include "BluetoothUtils.h"
-
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/Services.h"
-#include "mozilla/StaticPtr.h"
-#include "nsIObserverService.h"
-#include "MainThreadUtils.h"
-
-using namespace mozilla;
-USING_BLUETOOTH_NAMESPACE
-
-namespace {
-  StaticRefPtr<BluetoothHidManager> sBluetoothHidManager;
-  bool sInShutdown = false;
-} // namespace
-
-NS_IMETHODIMP
-BluetoothHidManager::Observe(nsISupports* aSubject,
-                             const char* aTopic,
-                             const char16_t* aData)
-{
-  MOZ_ASSERT(sBluetoothHidManager);
-
-  if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    HandleShutdown();
-    return NS_OK;
-  }
-
-  MOZ_ASSERT(false, "BluetoothHidManager got unexpected topic!");
-  return NS_ERROR_UNEXPECTED;
-}
-
-BluetoothHidManager::BluetoothHidManager()
-{
-  Reset();
-}
-
-void
-BluetoothHidManager::Reset()
-{
-  mConnected = false;
-  mController = nullptr;
-}
-
-bool
-BluetoothHidManager::Init()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE(obs, false);
-  if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
-    BT_WARNING("Failed to add shutdown observer!");
-    return false;
-  }
-
-  return true;
-}
-
-BluetoothHidManager::~BluetoothHidManager()
-{
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-  if (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID))) {
-    BT_WARNING("Failed to remove shutdown observer!");
-  }
-}
-
-// static
-void
-BluetoothHidManager::InitHidInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (aRes) {
-    aRes->Init();
-  }
-}
-
-// static
-void
-BluetoothHidManager::DeinitHidInterface(BluetoothProfileResultHandler* aRes)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  sBluetoothHidManager = nullptr;
-
-  if (aRes) {
-    aRes->Deinit();
-  }
-}
-
-//static
-BluetoothHidManager*
-BluetoothHidManager::Get()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // If we already exist, exit early
-  if (sBluetoothHidManager) {
-    return sBluetoothHidManager;
-  }
-
-  // If we're in shutdown, don't create a new instance
-  NS_ENSURE_FALSE(sInShutdown, nullptr);
-
-  // Create a new instance, register, and return
-  BluetoothHidManager* manager = new BluetoothHidManager();
-  NS_ENSURE_TRUE(manager->Init(), nullptr);
-
-  sBluetoothHidManager = manager;
-  return sBluetoothHidManager;
-}
-
-void
-BluetoothHidManager::HandleShutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  sInShutdown = true;
-  Disconnect(nullptr);
-  sBluetoothHidManager = nullptr;
-}
-
-void
-BluetoothHidManager::Connect(const BluetoothAddress& aDeviceAddress,
-                             BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!aDeviceAddress.IsCleared());
-  MOZ_ASSERT(aController && !mController);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs || sInShutdown) {
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    return;
-  }
-
-  if (mConnected) {
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
-    return;
-  }
-
-  mDeviceAddress = aDeviceAddress;
-  mController = aController;
-
-  nsAutoString deviceAddressStr;
-  AddressToString(mDeviceAddress, deviceAddressStr);
-
-  if (NS_FAILED(bs->SendInputMessage(deviceAddressStr,
-                                     NS_LITERAL_STRING("Connect")))) {
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    return;
-  }
-}
-
-void
-BluetoothHidManager::Disconnect(BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    if (aController) {
-      aController->NotifyCompletion(
-        NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    }
-    return;
-  }
-
-  if (!mConnected) {
-    if (aController) {
-      aController->NotifyCompletion(
-        NS_LITERAL_STRING(ERR_ALREADY_DISCONNECTED));
-    }
-    return;
-  }
-
-  MOZ_ASSERT(!mDeviceAddress.IsCleared());
-  MOZ_ASSERT(!mController);
-
-  mController = aController;
-
-  nsAutoString deviceAddressStr;
-  AddressToString(mDeviceAddress, deviceAddressStr);
-
-  if (NS_FAILED(bs->SendInputMessage(deviceAddressStr,
-                                     NS_LITERAL_STRING("Disconnect")))) {
-    aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    return;
-  }
-}
-
-void
-BluetoothHidManager::OnConnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  RefPtr<BluetoothProfileController> controller = mController.forget();
-  controller->NotifyCompletion(aErrorStr);
-}
-
-void
-BluetoothHidManager::OnDisconnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * On the one hand, notify the controller that we've done for outbound
-   * connections. On the other hand, we do nothing for inbound connections.
-   */
-  NS_ENSURE_TRUE_VOID(mController);
-
-  RefPtr<BluetoothProfileController> controller = mController.forget();
-  controller->NotifyCompletion(aErrorStr);
-}
-
-bool
-BluetoothHidManager::IsConnected()
-{
-  return mConnected;
-}
-
-void
-BluetoothHidManager::HandleInputPropertyChanged(const BluetoothSignal& aSignal)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aSignal.value().type() ==
-             BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aSignal.value().get_ArrayOfBluetoothNamedValue();
-  MOZ_ASSERT(arr.Length() == 1);
-
-  const nsString& name = arr[0].name();
-  const BluetoothValue& value = arr[0].value();
-
-  if (name.EqualsLiteral("Connected")) {
-    MOZ_ASSERT(value.type() == BluetoothValue::Tbool);
-    MOZ_ASSERT(mConnected != value.get_bool());
-
-    mConnected = value.get_bool();
-    NotifyStatusChanged();
-    if (mConnected) {
-      OnConnect(EmptyString());
-    } else {
-      OnDisconnect(EmptyString());
-    }
-  }
-}
-
-void
-BluetoothHidManager::NotifyStatusChanged()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_NAMED_LITERAL_STRING(type, BLUETOOTH_HID_STATUS_CHANGED_ID);
-  InfallibleTArray<BluetoothNamedValue> parameters;
-
-  AppendNamedValue(parameters, "connected", mConnected);
-  AppendNamedValue(parameters, "address", mDeviceAddress);
-
-  BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
-}
-
-void
-BluetoothHidManager::OnGetServiceChannel(
-  const BluetoothAddress& aDeviceAddress,
-  const BluetoothUuid& aServiceUuid,
-  int aChannel)
-{
-  // Do nothing here as bluez acquires service channel and connects for us
-}
-
-void
-BluetoothHidManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
-{
-  // Do nothing here as bluez acquires service channel and connects for us
-}
-
-void
-BluetoothHidManager::GetAddress(BluetoothAddress& aDeviceAddress)
-{
-  aDeviceAddress = mDeviceAddress;
-}
-
-NS_IMPL_ISUPPORTS(BluetoothHidManager, nsIObserver)
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothHidManager.h
+++ /dev/null
@@ -1,51 +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_BluetoothHidManager_h
-#define mozilla_dom_bluetooth_BluetoothHidManager_h
-
-#include "BluetoothCommon.h"
-#include "BluetoothProfileController.h"
-#include "BluetoothProfileManagerBase.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothHidManager : public BluetoothProfileManagerBase
-{
-public:
-  BT_DECL_PROFILE_MGR_BASE
-  virtual void GetName(nsACString& aName)
-  {
-    aName.AssignLiteral("HID");
-  }
-
-  static void InitHidInterface(BluetoothProfileResultHandler* aRes);
-  static void DeinitHidInterface(BluetoothProfileResultHandler* aRes);
-  static BluetoothHidManager* Get();
-
-  // HID-specific functions
-  void HandleInputPropertyChanged(const BluetoothSignal& aSignal);
-
-protected:
-  virtual ~BluetoothHidManager();
-
-private:
-  BluetoothHidManager();
-  bool Init();
-  void Cleanup();
-  void HandleShutdown();
-
-  void NotifyStatusChanged();
-
-  // data member
-  bool mConnected;
-  BluetoothAddress mDeviceAddress;
-  RefPtr<BluetoothProfileController> mController;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothHidManager_h
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothOppManager.cpp
+++ /dev/null
@@ -1,1736 +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 "base/basictypes.h"
-#include "BluetoothOppManager.h"
-
-#include "BluetoothService.h"
-#include "BluetoothSocket.h"
-#include "BluetoothUtils.h"
-#include "BluetoothUuidHelper.h"
-#include "ObexBase.h"
-
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/dom/File.h"
-#include "mozilla/dom/ipc/BlobParent.h"
-#include "mozilla/RefPtr.h"
-#include "mozilla/Services.h"
-#include "mozilla/StaticPtr.h"
-#include "mozilla/UniquePtr.h"
-#include "nsCExternalHandlerService.h"
-#include "nsIObserver.h"
-#include "nsIObserverService.h"
-#include "nsIFile.h"
-#include "nsIInputStream.h"
-#include "nsIMIMEService.h"
-#include "nsIOutputStream.h"
-#include "nsIVolumeService.h"
-#include "nsNetUtil.h"
-#include "nsServiceManagerUtils.h"
-
-#define TARGET_SUBDIR "Download/Bluetooth/"
-
-USING_BLUETOOTH_NAMESPACE
-using namespace mozilla;
-using namespace mozilla::dom;
-using namespace mozilla::ipc;
-using mozilla::TimeDuration;
-using mozilla::TimeStamp;
-
-namespace {
-  // Sending system message "bluetooth-opp-update-progress" every 50kb
-  static const uint32_t kUpdateProgressBase = 50 * 1024;
-
-  /*
-   * The format of the header of an PUT request is
-   * [opcode:1][packet length:2][headerId:1][header length:2]
-   */
-  static const uint32_t kPutRequestHeaderSize = 6;
-
-  /*
-   * The format of the appended header of an PUT request is
-   * [headerId:1][header length:4]
-   * P.S. Length of name header is 4 since unicode is 2 bytes per char.
-   */
-  static const uint32_t kPutRequestAppendHeaderSize = 5;
-
-  // The default timeout we permit to wait for SDP updating if we can't get
-  // service channel.
-  static const double kSdpUpdatingTimeoutMs = 3000.0;
-
-  // UUID of OBEX Object Push
-  static const BluetoothUuid kObexObjectPush(OBJECT_PUSH);
-
-  StaticRefPtr<BluetoothOppManager> sBluetoothOppManager;
-  static bool sInShutdown = false;
-}
-
-class mozilla::dom::bluetooth::SendFileBatch
-{
-public:
-  SendFileBatch(const BluetoothAddress& aDeviceAddress, Blob* aBlob)
-    : mDeviceAddress(aDeviceAddress)
-  {
-    mBlobs.AppendElement(aBlob);
-  }
-
-  BluetoothAddress mDeviceAddress;
-  nsTArray<RefPtr<Blob>> mBlobs;
-};
-
-NS_IMETHODIMP
-BluetoothOppManager::Observe(nsISupports* aSubject,
-                             const char* aTopic,
-                             const char16_t* aData)
-{
-  MOZ_ASSERT(sBluetoothOppManager);
-
-  if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    HandleShutdown();
-    return NS_OK;
-  }
-
-  MOZ_ASSERT(false, "BluetoothOppManager got unexpected topic!");
-  return NS_ERROR_UNEXPECTED;
-}
-
-class SendSocketDataTask : public Runnable
-{
-public:
-  SendSocketDataTask(UniquePtr<uint8_t[]> aStream, uint32_t aSize)
-    : mStream(Move(aStream))
-    , mSize(aSize)
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    sBluetoothOppManager->SendPutRequest(mStream.get(), mSize);
-
-    return NS_OK;
-  }
-
-private:
-  UniquePtr<uint8_t[]> mStream;
-  uint32_t mSize;
-};
-
-class ReadFileTask : public Runnable
-{
-public:
-  ReadFileTask(nsIInputStream* aInputStream,
-               uint32_t aRemoteMaxPacketSize) : mInputStream(aInputStream)
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    mAvailablePacketSize = aRemoteMaxPacketSize - kPutRequestHeaderSize;
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-
-    uint32_t numRead;
-    auto buf = MakeUnique<uint8_t[]>(mAvailablePacketSize);
-
-    // function inputstream->Read() only works on non-main thread
-    nsresult rv = mInputStream->Read((char*)buf.get(), mAvailablePacketSize,
-                                     &numRead);
-    if (NS_FAILED(rv)) {
-      // Needs error handling here
-      BT_WARNING("Failed to read from input stream");
-      return NS_ERROR_FAILURE;
-    }
-
-    if (numRead > 0) {
-      sBluetoothOppManager->CheckPutFinal(numRead);
-
-      RefPtr<SendSocketDataTask> task =
-        new SendSocketDataTask(Move(buf), numRead);
-      if (NS_FAILED(NS_DispatchToMainThread(task))) {
-        BT_WARNING("Failed to dispatch to main thread!");
-        return NS_ERROR_FAILURE;
-      }
-    }
-
-    return NS_OK;
-  };
-
-private:
-  nsCOMPtr<nsIInputStream> mInputStream;
-  uint32_t mAvailablePacketSize;
-};
-
-class CloseSocketTask : public Runnable
-{
-public:
-  CloseSocketTask(BluetoothSocket* aSocket) : mSocket(aSocket)
-  {
-    MOZ_ASSERT(aSocket);
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (mSocket->GetConnectionStatus() ==
-        SocketConnectionStatus::SOCKET_CONNECTED) {
-      mSocket->Close();
-    }
-    return NS_OK;
-  }
-
-private:
-  RefPtr<BluetoothSocket> mSocket;
-};
-
-BluetoothOppManager::BluetoothOppManager()
-  : mConnected(false)
-  , mRemoteObexVersion(0)
-  , mRemoteConnectionFlags(0)
-  , mRemoteMaxPacketLength(0)
-  , mLastCommand(0)
-  , mPacketLength(0)
-  , mPutPacketReceivedLength(0)
-  , mBodySegmentLength(0)
-  , mAbortFlag(false)
-  , mNewFileFlag(false)
-  , mPutFinalFlag(false)
-  , mSendTransferCompleteFlag(false)
-  , mSuccessFlag(false)
-  , mIsServer(true)
-  , mWaitingForConfirmationFlag(false)
-  , mFileLength(0)
-  , mSentFileLength(0)
-  , mWaitingToSendPutFinal(false)
-  , mCurrentBlobIndex(-1)
-  , mSocketType(static_cast<BluetoothSocketType>(0))
-{ }
-
-BluetoothOppManager::~BluetoothOppManager()
-{
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-  if (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID))) {
-    BT_WARNING("Failed to remove shutdown observer!");
-  }
-}
-
-bool
-BluetoothOppManager::Init()
-{
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE(obs, false);
-  if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
-    BT_WARNING("Failed to add shutdown observer!");
-    return false;
-  }
-
-  Listen();
-
-  return true;
-}
-
-//static
-BluetoothOppManager*
-BluetoothOppManager::Get()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // If sBluetoothOppManager already exists, exit early
-  if (sBluetoothOppManager) {
-    return sBluetoothOppManager;
-  }
-
-  // If we're in shutdown, don't create a new instance
-  NS_ENSURE_FALSE(sInShutdown, nullptr);
-
-  // Create a new instance, register, and return
-  BluetoothOppManager *manager = new BluetoothOppManager();
-  NS_ENSURE_TRUE(manager->Init(), nullptr);
-
-  sBluetoothOppManager = manager;
-  return sBluetoothOppManager;
-}
-
-void
-BluetoothOppManager::ConnectInternal(const BluetoothAddress& aDeviceAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Stop listening because currently we only support one connection at a time.
-  if (mRfcommSocket) {
-    mRfcommSocket->Close();
-    mRfcommSocket = nullptr;
-  }
-
-  if (mL2capSocket) {
-    mL2capSocket->Close();
-    mL2capSocket = nullptr;
-  }
-
-  mIsServer = false;
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs || sInShutdown || mSocket) {
-    OnSocketConnectError(mSocket);
-    return;
-  }
-
-  mNeedsUpdatingSdpRecords = true;
-
-  auto rv = bs->GetServiceChannel(aDeviceAddress, kObexObjectPush, this);
-  if (NS_FAILED(rv)) {
-    OnSocketConnectError(mSocket);
-    return;
-  }
-
-  mSocket = new BluetoothSocket(this);
-  mSocketType = BluetoothSocketType::RFCOMM;
-}
-
-void
-BluetoothOppManager::HandleShutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  sInShutdown = true;
-  Disconnect(nullptr);
-  sBluetoothOppManager = nullptr;
-}
-
-bool
-BluetoothOppManager::Listen()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (mSocket) {
-    BT_WARNING("mSocket exists. Failed to listen.");
-    return false;
-  }
-
-  if (!mRfcommSocket) {
-    mRfcommSocket = new BluetoothSocket(this);
-
-    nsresult rv = mRfcommSocket->Listen(
-      NS_LITERAL_STRING("OBEX Object Push"),
-      kObexObjectPush,
-      BluetoothSocketType::RFCOMM,
-      BluetoothReservedChannels::CHANNEL_OPUSH,
-      true, true);
-
-    if (NS_FAILED(rv)) {
-      BT_WARNING("[OPP] Can't listen on RFCOMM socket!");
-      mRfcommSocket = nullptr;
-      return false;
-    }
-  }
-
-  if (!mL2capSocket) {
-    mL2capSocket = new BluetoothSocket(this);
-
-    nsresult rv = mL2capSocket->Listen(
-      NS_LITERAL_STRING("OBEX Object Push"),
-      kObexObjectPush,
-      BluetoothSocketType::EL2CAP,
-      BluetoothReservedChannels::CHANNEL_OPUSH_L2CAP,
-      true, true);
-
-    if (NS_FAILED(rv)) {
-      BT_WARNING("[OPP] Can't listen on L2CAP socket!");
-      mRfcommSocket->Close();
-      mRfcommSocket = nullptr;
-      mL2capSocket = nullptr;
-      return false;
-    }
-  }
-
-  mIsServer = true;
-
-  return true;
-}
-
-void
-BluetoothOppManager::StartSendingNextFile()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  MOZ_ASSERT(!mBatches.IsEmpty());
-  MOZ_ASSERT((int)mBatches[0].mBlobs.Length() > mCurrentBlobIndex + 1);
-
-  mBlob = mBatches[0].mBlobs[++mCurrentBlobIndex];
-
-  // Before sending content, we have to send a header including
-  // information such as file name, file length and content type.
-  ExtractBlobHeaders();
-  StartFileTransfer();
-
-  if (mCurrentBlobIndex == 0) {
-    // We may have more than one file waiting for transferring, but only one
-    // CONNECT request would be sent. Therefore check if this is the very first
-    // file at the head of queue.
-    SendConnectRequest();
-  } else {
-    SendPutHeaderRequest(mFileName, mFileLength);
-    AfterFirstPut();
-  }
-}
-
-bool
-BluetoothOppManager::SendFile(const BluetoothAddress& aDeviceAddress,
-                              BlobParent* aActor)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  RefPtr<BlobImpl> impl = aActor->GetBlobImpl();
-  RefPtr<Blob> blob = Blob::Create(nullptr, impl);
-
-  return SendFile(aDeviceAddress, blob);
-}
-
-bool
-BluetoothOppManager::SendFile(const BluetoothAddress& aDeviceAddress,
-                              Blob* aBlob)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  AppendBlobToSend(aDeviceAddress, aBlob);
-  if (!mSocket) {
-    ProcessNextBatch();
-  }
-
-  return true;
-}
-
-void
-BluetoothOppManager::AppendBlobToSend(const BluetoothAddress& aDeviceAddress,
-                                      Blob* aBlob)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  int indexTail = mBatches.Length() - 1;
-
-  /**
-   * Create a new batch if
-   * - mBatches is empty, or
-   * - aDeviceAddress differs from mDeviceAddress of the last batch
-   */
-  if (mBatches.IsEmpty() ||
-      aDeviceAddress != mBatches[indexTail].mDeviceAddress) {
-    SendFileBatch batch(aDeviceAddress, aBlob);
-    mBatches.AppendElement(batch);
-  } else {
-    mBatches[indexTail].mBlobs.AppendElement(aBlob);
-  }
-}
-
-void
-BluetoothOppManager::DiscardBlobsToSend()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  MOZ_ASSERT(!mBatches.IsEmpty());
-  MOZ_ASSERT(!mIsServer);
-
-  int length = (int) mBatches[0].mBlobs.Length();
-  while (length > mCurrentBlobIndex + 1) {
-    mBlob = mBatches[0].mBlobs[++mCurrentBlobIndex];
-
-    BT_LOGR("idx %d", mCurrentBlobIndex);
-    ExtractBlobHeaders();
-    StartFileTransfer();
-    FileTransferComplete();
-  }
-}
-
-bool
-BluetoothOppManager::ProcessNextBatch()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!IsConnected());
-
-  // Remove the processed batch.
-  // A batch is processed if we've incremented mCurrentBlobIndex for it.
-  if (mCurrentBlobIndex >= 0) {
-    ClearQueue();
-    mBatches.RemoveElementAt(0);
-    BT_LOGR("REMOVE. %d remaining", mBatches.Length());
-  }
-
-  // Process the next batch
-  if (!mBatches.IsEmpty()) {
-    ConnectInternal(mBatches[0].mDeviceAddress);
-    return true;
-  }
-
-  // No more batch to process
-  return false;
-}
-
-void
-BluetoothOppManager::ClearQueue()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  MOZ_ASSERT(!mIsServer);
-  MOZ_ASSERT(!mBatches.IsEmpty());
-  MOZ_ASSERT(!mBatches[0].mBlobs.IsEmpty());
-
-  mCurrentBlobIndex = -1;
-  mBlob = nullptr;
-  mBatches[0].mBlobs.Clear();
-}
-
-bool
-BluetoothOppManager::StopSendingFile()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (mIsServer) {
-    mAbortFlag = true;
-  } else {
-    Disconnect(nullptr);
-  }
-
-  return true;
-}
-
-bool
-BluetoothOppManager::ConfirmReceivingFile(bool aConfirm)
-{
-  NS_ENSURE_TRUE(mConnected, false);
-  NS_ENSURE_TRUE(mWaitingForConfirmationFlag, false);
-
-  mWaitingForConfirmationFlag = false;
-
-  // For the first packet of first file
-  bool success = false;
-  if (aConfirm) {
-    StartFileTransfer();
-    if (CreateFile()) {
-      success = WriteToFile(mBodySegment.get(), mBodySegmentLength);
-    }
-  }
-
-  if (success && mPutFinalFlag) {
-    mSuccessFlag = true;
-    RestoreReceivedFileAndNotify();
-    FileTransferComplete();
-  }
-
-  ReplyToPut(mPutFinalFlag, success);
-
-  return true;
-}
-
-void
-BluetoothOppManager::AfterFirstPut()
-{
-  mUpdateProgressCounter = 1;
-  mPutFinalFlag = false;
-  mPutPacketReceivedLength = 0;
-  mSentFileLength = 0;
-  mWaitingToSendPutFinal = false;
-  mSuccessFlag = false;
-  mBodySegmentLength = 0;
-}
-
-void
-BluetoothOppManager::AfterOppConnected()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mConnected = true;
-  mAbortFlag = false;
-  mWaitingForConfirmationFlag = true;
-  AfterFirstPut();
-  // Get a mount lock to prevent the sdcard from being shared with
-  // the PC while we're doing a OPP file transfer. After OPP transaction
-  // were done, the mount lock will be freed.
-  if (!AcquireSdcardMountLock()) {
-    // If we fail to get a mount lock, abort this transaction
-    // Directly sending disconnect-request is better than abort-request
-    BT_WARNING("BluetoothOPPManager couldn't get a mount lock!");
-    Disconnect(nullptr);
-  }
-}
-
-void
-BluetoothOppManager::AfterOppDisconnected()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mConnected = false;
-  mLastCommand = 0;
-  mPutPacketReceivedLength = 0;
-  mDsFile = nullptr;
-  mDummyDsFile = nullptr;
-
-  // We can't reset mSuccessFlag here since this function may be called
-  // before we send system message of transfer complete
-  // mSuccessFlag = false;
-
-  if (mInputStream) {
-    mInputStream->Close();
-    mInputStream = nullptr;
-  }
-
-  if (mOutputStream) {
-    mOutputStream->Close();
-    mOutputStream = nullptr;
-  }
-
-  // Store local pointer of |mReadFileThread| to avoid shutdown reentry crash
-  // See bug 1191715 comment 19 for more details.
-  nsCOMPtr<nsIThread> thread = mReadFileThread.forget();
-  if (thread) {
-    thread->Shutdown();
-  }
-
-  // Release the mount lock if file transfer completed
-  if (mMountLock) {
-    // The mount lock will be implicitly unlocked
-    mMountLock = nullptr;
-  }
-}
-
-void
-BluetoothOppManager::RestoreReceivedFileAndNotify()
-{
-  // Remove the empty dummy file
-  if (mDummyDsFile && mDummyDsFile->mFile) {
-    mDummyDsFile->mFile->Remove(false);
-    mDummyDsFile = nullptr;
-  }
-
-  // Remove the trailing ".part" file name from mDsFile by two steps
-  // 1. mDsFile->SetPath() so that the notification sent to Gaia will carry
-  //    correct information of the file.
-  // 2. mDsFile->mFile->RenameTo() so that the file name would actually be
-  //    changed in file system.
-  if (mDsFile && mDsFile->mFile) {
-    nsString path;
-    path.AssignLiteral(TARGET_SUBDIR);
-    path.Append(mFileName);
-
-    mDsFile->SetPath(path);
-    mDsFile->mFile->RenameTo(nullptr, mFileName);
-  }
-
-  // Notify about change of received file
-  NotifyAboutFileChange();
-}
-
-void
-BluetoothOppManager::DeleteReceivedFile()
-{
-  if (mOutputStream) {
-    mOutputStream->Close();
-    mOutputStream = nullptr;
-  }
-
-  if (mDsFile && mDsFile->mFile) {
-    mDsFile->mFile->Remove(false);
-    mDsFile = nullptr;
-  }
-
-  // Remove the empty dummy file
-  if (mDummyDsFile && mDummyDsFile->mFile) {
-    mDummyDsFile->mFile->Remove(false);
-    mDummyDsFile = nullptr;
-  }
-}
-
-bool
-BluetoothOppManager::CreateFile()
-{
-  MOZ_ASSERT(mPutPacketReceivedLength == mPacketLength);
-
-  // Create one dummy file to be a placeholder for the target file name, and
-  // create another file with a meaningless file extension to write the received
-  // data. By doing this, we can prevent applications from parsing incomplete
-  // data in the middle of the receiving process.
-  nsString path;
-  path.AssignLiteral(TARGET_SUBDIR);
-  path.Append(mFileName);
-
-  // Use an empty dummy file object to occupy the file name, so that after the
-  // whole file has been received successfully by using mDsFile, we could just
-  // remove mDummyDsFile and rename mDsFile to the file name of mDummyDsFile.
-  mDummyDsFile =
-    DeviceStorageFile::CreateUnique(path, nsIFile::NORMAL_FILE_TYPE, 0644);
-  NS_ENSURE_TRUE(mDummyDsFile, false);
-
-  // The function CreateUnique() may create a file with a different file
-  // name from the original mFileName. Therefore we have to retrieve
-  // the file name again.
-  mDummyDsFile->mFile->GetLeafName(mFileName);
-
-  BT_LOGR("mFileName: %s", NS_ConvertUTF16toUTF8(mFileName).get());
-
-  // Prepare the entire file path for the .part file
-  path.Truncate();
-  path.AssignLiteral(TARGET_SUBDIR);
-  path.Append(mFileName);
-  path.AppendLiteral(".part");
-
-  mDsFile =
-    DeviceStorageFile::CreateUnique(path, nsIFile::NORMAL_FILE_TYPE, 0644);
-  NS_ENSURE_TRUE(mDsFile, false);
-
-  NS_NewLocalFileOutputStream(getter_AddRefs(mOutputStream), mDsFile->mFile);
-  NS_ENSURE_TRUE(mOutputStream, false);
-
-  return true;
-}
-
-bool
-BluetoothOppManager::WriteToFile(const uint8_t* aData, int aDataLength)
-{
-  NS_ENSURE_TRUE(mOutputStream, false);
-
-  uint32_t wrote = 0;
-  mOutputStream->Write((const char*)aData, aDataLength, &wrote);
-  NS_ENSURE_TRUE(aDataLength == (int) wrote, false);
-
-  return true;
-}
-
-// Virtual function of class SocketConsumer
-void
-BluetoothOppManager::ExtractPacketHeaders(const ObexHeaderSet& aHeader)
-{
-  if (aHeader.Has(ObexHeaderId::Name)) {
-    aHeader.GetName(mFileName);
-  }
-
-  if (aHeader.Has(ObexHeaderId::Type)) {
-    aHeader.GetContentType(mContentType);
-  }
-
-  if (aHeader.Has(ObexHeaderId::Length)) {
-    aHeader.GetLength(&mFileLength);
-  }
-
-  if (aHeader.Has(ObexHeaderId::Body) ||
-      aHeader.Has(ObexHeaderId::EndOfBody)) {
-    uint8_t* bodyPtr;
-    aHeader.GetBody(&bodyPtr, &mBodySegmentLength);
-    mBodySegment.reset(bodyPtr);
-  }
-}
-
-bool
-BluetoothOppManager::ExtractBlobHeaders()
-{
-  RetrieveSentFileName();
-  mBlob->GetType(mContentType);
-
-  ErrorResult rv;
-  uint64_t fileLength = mBlob->GetSize(rv);
-  if (NS_WARN_IF(rv.Failed())) {
-    SendDisconnectRequest();
-    rv.SuppressException();
-    return false;
-  }
-
-  // Currently we keep the size of files which were sent/received via
-  // Bluetooth not exceed UINT32_MAX because the Length header in OBEX
-  // is only 4-byte long. Although it is possible to transfer a file
-  // larger than UINT32_MAX, it needs to parse another OBEX Header
-  // and I would like to leave it as a feature.
-  if (fileLength > (uint64_t)UINT32_MAX) {
-    BT_WARNING("The file size is too large for now");
-    SendDisconnectRequest();
-    return false;
-  }
-
-  mFileLength = fileLength;
-  rv = NS_NewThread(getter_AddRefs(mReadFileThread));
-  if (NS_WARN_IF(rv.Failed())) {
-    SendDisconnectRequest();
-    rv.SuppressException();
-    return false;
-  }
-
-  return true;
-}
-
-void
-BluetoothOppManager::RetrieveSentFileName()
-{
-  mFileName.Truncate();
-
-  RefPtr<File> file = mBlob->ToFile();
-  if (file) {
-    file->GetName(mFileName);
-  }
-
-  /**
-   * We try our best to get the file extension to avoid interoperability issues.
-   * However, once we found that we are unable to get suitable extension or
-   * information about the content type, sending a pre-defined file name without
-   * extension would be fine.
-   */
-  if (mFileName.IsEmpty()) {
-    mFileName.AssignLiteral("Unknown");
-  }
-
-  int32_t offset = mFileName.RFindChar('/');
-  if (offset != kNotFound) {
-    mFileName = Substring(mFileName, offset + 1);
-  }
-
-  offset = mFileName.RFindChar('.');
-  if (offset == kNotFound) {
-    nsCOMPtr<nsIMIMEService> mimeSvc = do_GetService(NS_MIMESERVICE_CONTRACTID);
-
-    if (mimeSvc) {
-      nsString mimeType;
-      mBlob->GetType(mimeType);
-
-      nsCString extension;
-      nsresult rv =
-        mimeSvc->GetPrimaryExtension(NS_LossyConvertUTF16toASCII(mimeType),
-                                     EmptyCString(),
-                                     extension);
-      if (NS_SUCCEEDED(rv)) {
-        mFileName.Append('.');
-        AppendUTF8toUTF16(extension, mFileName);
-      }
-    }
-  }
-}
-
-bool
-BluetoothOppManager::IsReservedChar(char16_t c)
-{
-  return (c < 0x0020 ||
-          c == char16_t('?') || c == char16_t('|') || c == char16_t('<') ||
-          c == char16_t('>') || c == char16_t('"') || c == char16_t(':') ||
-          c == char16_t('/') || c == char16_t('*') || c == char16_t('\\'));
-}
-
-void
-BluetoothOppManager::ValidateFileName()
-{
-  int length = mFileName.Length();
-
-  for (int i = 0; i < length; ++i) {
-    // Replace reserved char of fat file system with '_'
-    if (IsReservedChar(mFileName.CharAt(i))) {
-      mFileName.Replace(i, 1, char16_t('_'));
-    }
-  }
-}
-
-bool
-BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketBuffer* aMessage)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aMessage);
-
-  int frameHeaderLength = 0;
-  const uint8_t* data = aMessage->GetData();
-
-  // See if this is the first part of each Put packet
-  if (mPutPacketReceivedLength == 0) {
-    // Section 3.3.3 "Put", IrOBEX 1.2
-    // [opcode:1][length:2][Headers:var]
-    frameHeaderLength = 3;
-
-    mPacketLength = BigEndian::readUint16(&data[1]) - frameHeaderLength;
-    /**
-     * A PUT request from remote devices may be divided into multiple parts.
-     * In other words, one request may need to be received multiple times,
-     * so here we keep a variable mPutPacketReceivedLength to indicate if
-     * current PUT request is done.
-     */
-    mReceivedDataBuffer.reset(new uint8_t[mPacketLength]);
-    mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal);
-  }
-
-  int dataLength = aMessage->GetSize() - frameHeaderLength;
-
-  // Check length before memcpy to prevent from memory pollution
-  if (dataLength < 0 ||
-      mPutPacketReceivedLength + dataLength > mPacketLength) {
-    BT_LOGR("Received packet size is unreasonable");
-
-    ReplyToPut(mPutFinalFlag, false);
-    DeleteReceivedFile();
-    FileTransferComplete();
-
-    return false;
-  }
-
-  memcpy(mReceivedDataBuffer.get() + mPutPacketReceivedLength,
-         &data[frameHeaderLength], dataLength);
-
-  mPutPacketReceivedLength += dataLength;
-
-  return (mPutPacketReceivedLength == mPacketLength);
-}
-
-void
-BluetoothOppManager::ServerDataHandler(UnixSocketBuffer* aMessage)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * Ensure
-   * - valid access to data[0], i.e., opCode
-   * - received packet length smaller than max packet length
-   */
-  int receivedLength = aMessage->GetSize();
-  if (receivedLength < 1 || receivedLength > MAX_PACKET_LENGTH) {
-    ReplyError(ObexResponseCode::BadRequest);
-    return;
-  }
-
-  uint8_t opCode;
-  const uint8_t* data = aMessage->GetData();
-  if (mPutPacketReceivedLength > 0) {
-    opCode = mPutFinalFlag ? ObexRequestCode::PutFinal : ObexRequestCode::Put;
-  } else {
-    opCode = data[0];
-
-    // When there's a Put packet right after a PutFinal packet,
-    // which means it's the start point of a new file.
-    if (mPutFinalFlag &&
-        (opCode == ObexRequestCode::Put ||
-         opCode == ObexRequestCode::PutFinal)) {
-      mNewFileFlag = true;
-      AfterFirstPut();
-    }
-  }
-
-  ObexHeaderSet pktHeaders;
-  if (opCode == ObexRequestCode::Connect) {
-    // Section 3.3.1 "Connect", IrOBEX 1.2
-    // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
-    // [Headers:var]
-    if (receivedLength < 7 ||
-        !ParseHeaders(&data[7], receivedLength - 7, &pktHeaders)) {
-      ReplyError(ObexResponseCode::BadRequest);
-      return;
-    }
-
-    ReplyToConnect();
-    AfterOppConnected();
-  } else if (opCode == ObexRequestCode::Abort) {
-    // Section 3.3.5 "Abort", IrOBEX 1.2
-    // [opcode:1][length:2][Headers:var]
-    if (receivedLength < 3 ||
-        !ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
-      ReplyError(ObexResponseCode::BadRequest);
-      return;
-    }
-
-    ReplyToDisconnectOrAbort();
-    DeleteReceivedFile();
-  } else if (opCode == ObexRequestCode::Disconnect) {
-    // Section 3.3.2 "Disconnect", IrOBEX 1.2
-    // [opcode:1][length:2][Headers:var]
-    if (receivedLength < 3 ||
-        !ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
-      ReplyError(ObexResponseCode::BadRequest);
-      return;
-    }
-
-    ReplyToDisconnectOrAbort();
-    AfterOppDisconnected();
-    FileTransferComplete();
-  } else if (opCode == ObexRequestCode::Put ||
-             opCode == ObexRequestCode::PutFinal) {
-    if (!ComposePacket(opCode, aMessage)) {
-      return;
-    }
-
-    // A Put packet is received completely
-    ParseHeaders(mReceivedDataBuffer.get(),
-                 mPutPacketReceivedLength, &pktHeaders);
-    ExtractPacketHeaders(pktHeaders);
-    ValidateFileName();
-
-    // When we cancel the transfer, delete the file and notify completion
-    if (mAbortFlag) {
-      ReplyToPut(mPutFinalFlag, false);
-      mSentFileLength += mBodySegmentLength;
-      DeleteReceivedFile();
-      FileTransferComplete();
-      return;
-    }
-
-    // Wait until get confirmation from user, then create file and write to it
-    if (mWaitingForConfirmationFlag) {
-      ReceivingFileConfirmation();
-      mSentFileLength += mBodySegmentLength;
-      return;
-    }
-
-    // Already get confirmation from user, create a new file if needed and
-    // write to output stream
-    if (mNewFileFlag) {
-      StartFileTransfer();
-      if (!CreateFile()) {
-        ReplyToPut(mPutFinalFlag, false);
-        return;
-      }
-      mNewFileFlag = false;
-    }
-
-    if (!WriteToFile(mBodySegment.get(), mBodySegmentLength)) {
-      ReplyToPut(mPutFinalFlag, false);
-      return;
-    }
-
-    ReplyToPut(mPutFinalFlag, true);
-
-    // Send progress update
-    mSentFileLength += mBodySegmentLength;
-    if (mSentFileLength > kUpdateProgressBase * mUpdateProgressCounter) {
-      UpdateProgress();
-      mUpdateProgressCounter = mSentFileLength / kUpdateProgressBase + 1;
-    }
-
-    // Success to receive a file and notify completion
-    if (mPutFinalFlag) {
-      mSuccessFlag = true;
-      RestoreReceivedFileAndNotify();
-      FileTransferComplete();
-    }
-  } else if (opCode == ObexRequestCode::Get ||
-             opCode == ObexRequestCode::GetFinal ||
-             opCode == ObexRequestCode::SetPath) {
-    ReplyError(ObexResponseCode::BadRequest);
-    BT_WARNING("Unsupported ObexRequestCode");
-  } else {
-    ReplyError(ObexResponseCode::NotImplemented);
-    BT_WARNING("Unrecognized ObexRequestCode");
-  }
-}
-
-void
-BluetoothOppManager::ClientDataHandler(UnixSocketBuffer* aMessage)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Ensure valid access to data[0], i.e., opCode
-  int receivedLength = aMessage->GetSize();
-  if (receivedLength < 1) {
-    BT_LOGR("Receive empty response packet");
-    return;
-  }
-
-  const uint8_t* data = aMessage->GetData();
-  uint8_t opCode = data[0];
-
-  // Check response code and send out system message as finished if the response
-  // code is somehow incorrect.
-  uint8_t expectedOpCode = ObexResponseCode::Success;
-  if (mLastCommand == ObexRequestCode::Put) {
-    expectedOpCode = ObexResponseCode::Continue;
-  }
-
-  if (opCode != expectedOpCode) {
-    if (mLastCommand == ObexRequestCode::Put ||
-        mLastCommand == ObexRequestCode::Abort ||
-        mLastCommand == ObexRequestCode::PutFinal) {
-      SendDisconnectRequest();
-    }
-    nsAutoCString str;
-    str += "[OPP] 0x";
-    str.AppendInt(mLastCommand, 16);
-    str += " failed";
-    BT_WARNING(str.get());
-    FileTransferComplete();
-    return;
-  }
-
-  if (mLastCommand == ObexRequestCode::PutFinal) {
-    mSuccessFlag = true;
-    FileTransferComplete();
-
-    if (mInputStream) {
-      mInputStream->Close();
-      mInputStream = nullptr;
-    }
-
-    if (mCurrentBlobIndex + 1 == (int) mBatches[0].mBlobs.Length()) {
-      SendDisconnectRequest();
-    } else {
-      StartSendingNextFile();
-    }
-  } else if (mLastCommand == ObexRequestCode::Abort) {
-    SendDisconnectRequest();
-    FileTransferComplete();
-  } else if (mLastCommand == ObexRequestCode::Disconnect) {
-    AfterOppDisconnected();
-    // Most devices will directly terminate connection after receiving
-    // Disconnect request, so we make a delay here. If the socket hasn't been
-    // disconnected, we will close it.
-    if (mSocket) {
-      MessageLoop::current()->
-        PostDelayedTask(MakeAndAddRef<CloseSocketTask>(mSocket), 1000);
-    }
-  } else if (mLastCommand == ObexRequestCode::Connect) {
-    MOZ_ASSERT(!mFileName.IsEmpty());
-    MOZ_ASSERT(mBlob);
-
-    AfterOppConnected();
-
-    // Ensure valid access to remote information
-    if (receivedLength < 7) {
-      BT_LOGR("The length of connect response packet is invalid");
-      SendDisconnectRequest();
-      return;
-    }
-
-    // Keep remote information
-    mRemoteObexVersion = data[3];
-    mRemoteConnectionFlags = data[4];
-    mRemoteMaxPacketLength = BigEndian::readUint16(&data[5]);
-
-    // The length of file name exceeds maximum length.
-    int fileNameByteLen = (mFileName.Length() + 1) * 2;
-    int headerLen = kPutRequestHeaderSize + kPutRequestAppendHeaderSize;
-    if (fileNameByteLen > mRemoteMaxPacketLength - headerLen) {
-      BT_WARNING("The length of file name is aberrant.");
-      SendDisconnectRequest();
-      return;
-    }
-
-    SendPutHeaderRequest(mFileName, mFileLength);
-  } else if (mLastCommand == ObexRequestCode::Put) {
-    if (mWaitingToSendPutFinal) {
-      SendPutFinalRequest();
-      return;
-    }
-
-    if (kUpdateProgressBase * mUpdateProgressCounter < mSentFileLength) {
-      UpdateProgress();
-      mUpdateProgressCounter = mSentFileLength / kUpdateProgressBase + 1;
-    }
-
-    ErrorResult rv;
-    if (!mInputStream) {
-      mBlob->GetInternalStream(getter_AddRefs(mInputStream), rv);
-      if (NS_WARN_IF(rv.Failed())) {
-        SendDisconnectRequest();
-        rv.SuppressException();
-        return;
-      }
-    }
-
-    RefPtr<ReadFileTask> task = new ReadFileTask(mInputStream,
-                                                   mRemoteMaxPacketLength);
-    rv = mReadFileThread->Dispatch(task, NS_DISPATCH_NORMAL);
-    if (NS_WARN_IF(rv.Failed())) {
-      SendDisconnectRequest();
-      rv.SuppressException();
-      return;
-    }
-  } else {
-    BT_WARNING("Unhandled ObexRequestCode");
-  }
-}
-
-// Virtual function of class SocketConsumer
-void
-BluetoothOppManager::ReceiveSocketData(BluetoothSocket* aSocket,
-                                       UniquePtr<UnixSocketBuffer>& aMessage)
-{
-  if (mIsServer) {
-    ServerDataHandler(aMessage.get());
-  } else {
-    ClientDataHandler(aMessage.get());
-  }
-}
-
-void
-BluetoothOppManager::SendConnectRequest()
-{
-  if (mConnected) return;
-
-  // Section 3.3.1 "Connect", IrOBEX 1.2
-  // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
-  // [Headers:var]
-  uint8_t req[255];
-  int index = 7;
-
-  req[3] = 0x10; // version=1.0
-  req[4] = 0x00; // flag=0x00
-  req[5] = BluetoothOppManager::MAX_PACKET_LENGTH >> 8;
-  req[6] = (uint8_t)BluetoothOppManager::MAX_PACKET_LENGTH;
-
-  SendObexData(req, ObexRequestCode::Connect, index);
-}
-
-void
-BluetoothOppManager::SendPutHeaderRequest(const nsAString& aFileName,
-                                          int aFileSize)
-{
-  if (!mConnected) return;
-
-  auto req = MakeUnique<uint8_t[]>(mRemoteMaxPacketLength);
-
-  int len = aFileName.Length();
-  uint8_t* fileName = new uint8_t[(len + 1) * 2];
-  const char16_t* fileNamePtr = aFileName.BeginReading();
-
-  for (int i = 0; i < len; i++) {
-    fileName[i * 2] = (uint8_t)(fileNamePtr[i] >> 8);
-    fileName[i * 2 + 1] = (uint8_t)fileNamePtr[i];
-  }
-
-  fileName[len * 2] = 0x00;
-  fileName[len * 2 + 1] = 0x00;
-
-  int index = 3;
-  index += AppendHeaderName(&req[index], mRemoteMaxPacketLength - index,
-                            fileName, (len + 1) * 2);
-  index += AppendHeaderLength(&req[index], aFileSize);
-
-  // This is final put packet if file size equals to 0
-  uint8_t opcode = (aFileSize > 0) ? ObexRequestCode::Put
-                                   : ObexRequestCode::PutFinal;
-  SendObexData(Move(req), opcode, index);
-
-  delete [] fileName;
-}
-
-void
-BluetoothOppManager::SendPutRequest(uint8_t* aFileBody,
-                                    int aFileBodyLength)
-{
-  if (!mConnected) return;
-  int packetLeftSpace = mRemoteMaxPacketLength - kPutRequestHeaderSize;
-  if (aFileBodyLength > packetLeftSpace) {
-    BT_WARNING("Not allowed such a small MaxPacketLength value");
-    return;
-  }
-
-  // Section 3.3.3 "Put", IrOBEX 1.2
-  // [opcode:1][length:2][Headers:var]
-  auto req = MakeUnique<uint8_t[]>(mRemoteMaxPacketLength);
-
-  int index = 3;
-  index += AppendHeaderBody(&req[index], mRemoteMaxPacketLength - index,
-                            aFileBody, aFileBodyLength);
-
-  SendObexData(Move(req), ObexRequestCode::Put, index);
-  mSentFileLength += aFileBodyLength;
-}
-
-void
-BluetoothOppManager::SendPutFinalRequest()
-{
-  if (!mConnected) return;
-
-  /**
-   * Section 2.2.9, "End-of-Body", IrObex 1.2
-   * End-of-Body is used to identify the last chunk of the object body.
-   * For most platforms, a PutFinal packet is sent with an zero length
-   * End-of-Body header.
-   */
-
-  // [opcode:1][length:2]
-  int index = 3;
-  auto req = MakeUnique<uint8_t[]>(mRemoteMaxPacketLength);
-  index += AppendHeaderEndOfBody(&req[index]);
-
-  SendObexData(Move(req), ObexRequestCode::PutFinal, index);
-
-  mWaitingToSendPutFinal = false;
-}
-
-void
-BluetoothOppManager::SendDisconnectRequest()
-{
-  if (!mConnected) return;
-
-  // Section 3.3.2 "Disconnect", IrOBEX 1.2
-  // [opcode:1][length:2][Headers:var]
-  uint8_t req[255];
-  int index = 3;
-
-  SendObexData(req, ObexRequestCode::Disconnect, index);
-}
-
-void
-BluetoothOppManager::CheckPutFinal(uint32_t aNumRead)
-{
-  if (mSentFileLength + aNumRead >= mFileLength) {
-    mWaitingToSendPutFinal = true;
-  }
-}
-
-bool
-BluetoothOppManager::IsConnected()
-{
-  return mConnected;
-}
-
-void
-BluetoothOppManager::GetAddress(BluetoothAddress& aDeviceAddress)
-{
-  return mSocket->GetAddress(aDeviceAddress);
-}
-
-void
-BluetoothOppManager::ReplyToConnect()
-{
-  if (mConnected) return;
-
-  // Section 3.3.1 "Connect", IrOBEX 1.2
-  // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
-  // [Headers:var]
-  uint8_t req[255];
-  int index = 7;
-
-  req[3] = 0x10; // version=1.0
-  req[4] = 0x00; // flag=0x00
-  req[5] = BluetoothOppManager::MAX_PACKET_LENGTH >> 8;
-  req[6] = (uint8_t)BluetoothOppManager::MAX_PACKET_LENGTH;
-
-  SendObexData(req, ObexResponseCode::Success, index);
-}
-
-void
-BluetoothOppManager::ReplyToDisconnectOrAbort()
-{
-  if (!mConnected) return;
-
-  // Section 3.3.2 "Disconnect" and Section 3.3.5 "Abort", IrOBEX 1.2
-  // The format of response packet of "Disconnect" and "Abort" are the same
-  // [opcode:1][length:2][Headers:var]
-  uint8_t req[255];
-  int index = 3;
-
-  SendObexData(req, ObexResponseCode::Success, index);
-}
-
-void
-BluetoothOppManager::ReplyToPut(bool aFinal, bool aContinue)
-{
-  if (!mConnected) return;
-
-  // The received length can be reset here because this is where we reply to a
-  // complete put packet.
-  mPutPacketReceivedLength = 0;
-
-  // Section 3.3.2 "Disconnect", IrOBEX 1.2
-  // [opcode:1][length:2][Headers:var]
-  uint8_t req[255];
-  int index = 3;
-  uint8_t opcode;
-
-  if (aContinue) {
-    opcode = (aFinal)? ObexResponseCode::Success :
-                       ObexResponseCode::Continue;
-  } else {
-    opcode = (aFinal)? ObexResponseCode::Unauthorized :
-                       ObexResponseCode::Unauthorized & (~FINAL_BIT);
-  }
-
-  SendObexData(req, opcode, index);
-}
-
-void
-BluetoothOppManager::ReplyError(uint8_t aError)
-{
-  BT_LOGR("error: %d", aError);
-
-  // Section 3.2 "Response Format", IrOBEX 1.2
-  // [opcode:1][length:2][Headers:var]
-  uint8_t req[255];
-  int index = 3;
-
-  SendObexData(req, aError, index);
-}
-
-void
-BluetoothOppManager::SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize)
-{
-  if (!mIsServer) {
-    mLastCommand = aOpcode;
-  }
-
-  SetObexPacketInfo(aData, aOpcode, aSize);
-  mSocket->SendSocketData(new UnixSocketRawData(aData, aSize));
-}
-
-void
-BluetoothOppManager::SendObexData(UniquePtr<uint8_t[]> aData, uint8_t aOpcode,
-                                  int aSize)
-{
-  if (!mIsServer) {
-    mLastCommand = aOpcode;
-  }
-
-  SetObexPacketInfo(aData.get(), aOpcode, aSize);
-  mSocket->SendSocketData(new UnixSocketRawData(Move(aData), aSize));
-}
-
-void
-BluetoothOppManager::FileTransferComplete()
-{
-  if (mSendTransferCompleteFlag) {
-    return;
-  }
-
-  nsString type, name;
-  BluetoothValue v;
-  InfallibleTArray<BluetoothNamedValue> parameters;
-  type.AssignLiteral("bluetooth-opp-transfer-complete");
-
-  name.AssignLiteral("address");
-  v = mConnectedDeviceAddress;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  name.AssignLiteral("success");
-  v = mSuccessFlag;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  name.AssignLiteral("received");
-  v = mIsServer;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  name.AssignLiteral("fileName");
-  v = mFileName;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  name.AssignLiteral("fileLength");
-  v = mSentFileLength;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  name.AssignLiteral("contentType");
-  v = mContentType;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  if (!BroadcastSystemMessage(type, parameters)) {
-    BT_WARNING("Failed to broadcast [bluetooth-opp-transfer-complete]");
-    return;
-  }
-
-  mSendTransferCompleteFlag = true;
-}
-
-void
-BluetoothOppManager::StartFileTransfer()
-{
-  nsString type, name;
-  BluetoothValue v;
-  InfallibleTArray<BluetoothNamedValue> parameters;
-  type.AssignLiteral("bluetooth-opp-transfer-start");
-
-  name.AssignLiteral("address");
-  v = mConnectedDeviceAddress;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  name.AssignLiteral("received");
-  v = mIsServer;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  name.AssignLiteral("fileName");
-  v = mFileName;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  name.AssignLiteral("fileLength");
-  v = mFileLength;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  name.AssignLiteral("contentType");
-  v = mContentType;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  if (!BroadcastSystemMessage(type, parameters)) {
-    BT_WARNING("Failed to broadcast [bluetooth-opp-transfer-start]");
-    return;
-  }
-
-  mSendTransferCompleteFlag = false;
-}
-
-void
-BluetoothOppManager::UpdateProgress()
-{
-  nsString type, name;
-  BluetoothValue v;
-  InfallibleTArray<BluetoothNamedValue> parameters;
-  type.AssignLiteral("bluetooth-opp-update-progress");
-
-  name.AssignLiteral("address");
-  v = mConnectedDeviceAddress;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  name.AssignLiteral("received");
-  v = mIsServer;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  name.AssignLiteral("processedLength");
-  v = mSentFileLength;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  name.AssignLiteral("fileLength");
-  v = mFileLength;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  if (!BroadcastSystemMessage(type, parameters)) {
-    BT_WARNING("Failed to broadcast [bluetooth-opp-update-progress]");
-    return;
-  }
-}
-
-void
-BluetoothOppManager::ReceivingFileConfirmation()
-{
-  nsString type, name;
-  BluetoothValue v;
-  InfallibleTArray<BluetoothNamedValue> parameters;
-  type.AssignLiteral("bluetooth-opp-receiving-file-confirmation");
-
-  name.AssignLiteral("address");
-  v = mConnectedDeviceAddress;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  name.AssignLiteral("fileName");
-  v = mFileName;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  name.AssignLiteral("fileLength");
-  v = mFileLength;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  name.AssignLiteral("contentType");
-  v = mContentType;
-  parameters.AppendElement(BluetoothNamedValue(name, v));
-
-  if (!BroadcastSystemMessage(type, parameters)) {
-    BT_WARNING("Failed to send [bluetooth-opp-receiving-file-confirmation]");
-    return;
-  }
-}
-
-void
-BluetoothOppManager::NotifyAboutFileChange()
-{
-  NS_NAMED_LITERAL_STRING(data, "modified");
-
-  nsCOMPtr<nsIObserverService> obs =
-    mozilla::services::GetObserverService();
-  NS_ENSURE_TRUE_VOID(obs);
-
-  obs->NotifyObservers(mDsFile, "file-watcher-notify", data.get());
-}
-
-void
-BluetoothOppManager::OnSocketConnectSuccess(BluetoothSocket* aSocket)
-{
-  BT_LOGR("[%s]", (mIsServer)? "server" : "client");
-  MOZ_ASSERT(aSocket);
-
-  /**
-   * If the created connection is an inbound connection, close another server
-   * socket because currently only one file-transfer session is allowed. After
-   * that, we need to make sure that both server socket would be nulled out.
-   * As for outbound connections, we just notify the controller that it's done.
-   */
-  if (aSocket == mRfcommSocket) {
-    MOZ_ASSERT(!mSocket);
-    mRfcommSocket.swap(mSocket);
-    mSocketType = BluetoothSocketType::RFCOMM;
-
-    mL2capSocket->Close();
-    mL2capSocket = nullptr;
-  } else if (aSocket == mL2capSocket) {
-    MOZ_ASSERT(!mSocket);
-    mL2capSocket.swap(mSocket);
-    mSocketType = BluetoothSocketType::EL2CAP;
-
-    mRfcommSocket->Close();
-    mRfcommSocket = nullptr;
-  }
-
-  // Cache device address since we can't get socket address when a remote
-  // device disconnect with us.
-  mSocket->GetAddress(mConnectedDeviceAddress);
-
-  // Start sending file if we connect as a client
-  if (!mIsServer) {
-    StartSendingNextFile();
-  }
-}
-
-void
-BluetoothOppManager::OnSocketConnectError(BluetoothSocket* aSocket)
-{
-  BT_LOGR("[%s]", (mIsServer)? "server" : "client");
-
-  mRfcommSocket = nullptr;
-  mL2capSocket = nullptr;
-  mSocket = nullptr;
-  mSocketType = static_cast<BluetoothSocketType>(0);
-
-  if (!mIsServer) {
-    // Inform gaia of remaining blobs' sending failure
-    DiscardBlobsToSend();
-  }
-
-  // Listen as a server if there's no more batch to process
-  if (!ProcessNextBatch() && !mIsServer) {
-    Listen();
-  }
-}
-
-void
-BluetoothOppManager::OnSocketDisconnect(BluetoothSocket* aSocket)
-{
-  BT_LOGR("[%s]", (mIsServer)? "server" : "client");
-  MOZ_ASSERT(aSocket);
-
-  if (aSocket != mSocket) {
-    // Do nothing when a listening server socket is closed.
-    return;
-  }
-
-  /**
-   * It is valid for a bluetooth device which is transfering file via OPP
-   * closing socket without sending OBEX disconnect request first. So we
-   * delete the broken file when we failed to receive a file from the remote,
-   * and notify the transfer has been completed (but failed). We also call
-   * AfterOppDisconnected here to ensure all variables will be cleaned.
-   */
-  if (!mSuccessFlag) {
-    if (mIsServer) {
-      DeleteReceivedFile();
-    }
-
-    FileTransferComplete();
-    if (!mIsServer) {
-      // Inform gaia of remaining blobs' sending failure
-      DiscardBlobsToSend();
-    }
-  }
-
-  AfterOppDisconnected();
-  mConnectedDeviceAddress.Clear();
-  mSuccessFlag = false;
-
-  mSocket = nullptr;
-  mSocketType = static_cast<BluetoothSocketType>(0);
-
-  // Listen as a server if there's no more batch to process
-  if (!ProcessNextBatch()) {
-    Listen();
-  }
-}
-
-void
-BluetoothOppManager::Disconnect(BluetoothProfileController* aController)
-{
-  if (mSocket) {
-    mSocket->Close();
-  } else {
-    BT_WARNING("%s: No ongoing file transfer to stop", __FUNCTION__);
-  }
-}
-
-void
-BluetoothOppManager::OnGetServiceChannel(
-  const BluetoothAddress& aDeviceAddress,
-  const BluetoothUuid& aServiceUuid,
-  int aChannel)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!aDeviceAddress.IsCleared());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  if (aChannel < 0) {
-    if (mNeedsUpdatingSdpRecords) {
-      mNeedsUpdatingSdpRecords = false;
-      mLastServiceChannelCheck = TimeStamp::Now();
-      bs->UpdateSdpRecords(aDeviceAddress, this);
-    } else {
-      TimeDuration duration = TimeStamp::Now() - mLastServiceChannelCheck;
-      // Refresh SDP records until it gets valid service channel
-      // unless timeout is hit.
-      if (duration.ToMilliseconds() < kSdpUpdatingTimeoutMs) {
-        bs->UpdateSdpRecords(aDeviceAddress, this);
-      } else {
-        OnSocketConnectError(mSocket);
-      }
-    }
-
-    return;
-  }
-
-  nsresult rv = mSocket->Connect(aDeviceAddress, kObexObjectPush,
-                                 mSocketType, aChannel, true, true);
-  if (NS_FAILED(rv)) {
-    OnSocketConnectError(mSocket);
-  }
-}
-
-void
-BluetoothOppManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!aDeviceAddress.IsCleared());
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  auto rv = bs->GetServiceChannel(aDeviceAddress, kObexObjectPush, this);
-  if (NS_FAILED(rv)) {
-    OnSocketConnectError(mSocket);
-  }
-}
-
-NS_IMPL_ISUPPORTS(BluetoothOppManager, nsIObserver)
-
-bool
-BluetoothOppManager::AcquireSdcardMountLock()
-{
-  nsCOMPtr<nsIVolumeService> volumeSrv =
-    do_GetService(NS_VOLUMESERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(volumeSrv, false);
-  nsresult rv;
-  rv = volumeSrv->CreateMountLock(NS_LITERAL_STRING("sdcard"),
-                                  getter_AddRefs(mMountLock));
-  NS_ENSURE_SUCCESS(rv, false);
-  return true;
-}
-
-void
-BluetoothOppManager::Connect(const BluetoothAddress& aDeviceAddress,
-                             BluetoothProfileController* aController)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothOppManager::OnConnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothOppManager::OnDisconnect(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(false);
-}
-
-void
-BluetoothOppManager::Reset()
-{
-  MOZ_ASSERT(false);
-}
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothOppManager.h
+++ /dev/null
@@ -1,233 +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_bluez_BluetoothOppManager_h
-#define mozilla_dom_bluetooth_bluez_BluetoothOppManager_h
-
-#include "BluetoothCommon.h"
-#include "BluetoothProfileManagerBase.h"
-#include "BluetoothSocketObserver.h"
-#include "DeviceStorage.h"
-#include "mozilla/ipc/SocketBase.h"
-#include "mozilla/UniquePtr.h"
-#include "nsCOMArray.h"
-
-class nsIOutputStream;
-class nsIInputStream;
-class nsIVolumeMountLock;
-
-namespace mozilla {
-namespace dom {
-class Blob;
-class BlobParent;
-}
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothSocket;
-class ObexHeaderSet;
-class SendFileBatch;
-
-class BluetoothOppManager : public BluetoothSocketObserver
-                          , public BluetoothProfileManagerBase
-{
-public:
-  BT_DECL_PROFILE_MGR_BASE
-  BT_DECL_SOCKET_OBSERVER
-  virtual void GetName(nsACString& aName)
-  {
-    aName.AssignLiteral("OPP");
-  }
-
-  static const int MAX_PACKET_LENGTH = 0xFFFE;
-
-  static BluetoothOppManager* Get();
-  void ClientDataHandler(mozilla::ipc::UnixSocketBuffer* aMessage);
-  void ServerDataHandler(mozilla::ipc::UnixSocketBuffer* aMessage);
-
-  bool Listen();
-
-  bool SendFile(const BluetoothAddress& aDeviceAddress, BlobParent* aActor);
-  bool SendFile(const BluetoothAddress& aDeviceAddress, Blob* aBlob);
-  bool StopSendingFile();
-  bool ConfirmReceivingFile(bool aConfirm);
-
-  void SendConnectRequest();
-  void SendPutHeaderRequest(const nsAString& aFileName, int aFileSize);
-  void SendPutRequest(uint8_t* aFileBody, int aFileBodyLength);
-  void SendPutFinalRequest();
-  void SendDisconnectRequest();
-
-  void ExtractPacketHeaders(const ObexHeaderSet& aHeader);
-  bool ExtractBlobHeaders();
-  void CheckPutFinal(uint32_t aNumRead);
-
-protected:
-  virtual ~BluetoothOppManager();
-
-private:
-  BluetoothOppManager();
-  bool Init();
-  void HandleShutdown();
-
-  void StartFileTransfer();
-  void StartSendingNextFile();
-  void FileTransferComplete();
-  void UpdateProgress();
-  void ReceivingFileConfirmation();
-  bool CreateFile();
-  bool WriteToFile(const uint8_t* aData, int aDataLength);
-  void RestoreReceivedFileAndNotify();
-  void DeleteReceivedFile();
-  void ReplyToConnect();
-  void ReplyToDisconnectOrAbort();
-  void ReplyToPut(bool aFinal, bool aContinue);
-  void ReplyError(uint8_t aError);
-  void AfterOppConnected();
-  void AfterFirstPut();
-  void AfterOppDisconnected();
-  void ValidateFileName();
-  bool IsReservedChar(char16_t c);
-  void ClearQueue();
-  void RetrieveSentFileName();
-  void NotifyAboutFileChange();
-  bool AcquireSdcardMountLock();
-  void SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
-  void SendObexData(UniquePtr<uint8_t[]> aData, uint8_t aOpcode, int aSize);
-  void AppendBlobToSend(const BluetoothAddress& aDeviceAddress, Blob* aBlob);
-  void DiscardBlobsToSend();
-  bool ProcessNextBatch();
-  void ConnectInternal(const BluetoothAddress& aDeviceAddress);
-
-  /**
-   * Usually we won't get a full PUT packet in one operation, which means that
-   * a packet may be devided into several parts and BluetoothOppManager should
-   * be in charge of assembling.
-   *
-   * @return true if a packet has been fully received.
-   *         false if the received length exceeds/not reaches the expected
-   *         length.
-   */
-  bool ComposePacket(uint8_t aOpCode,
-                     mozilla::ipc::UnixSocketBuffer* aMessage);
-
-  /**
-   * OBEX session status.
-   * Set when OBEX session is established.
-   */
-  bool mConnected;
-  BluetoothAddress mConnectedDeviceAddress;
-
-  /**
-   * Remote information
-   */
-  uint8_t mRemoteObexVersion;
-  uint8_t mRemoteConnectionFlags;
-  int mRemoteMaxPacketLength;
-
-  /**
-   * For sending files, we decide our next action based on current command and
-   * previous one.
-   * For receiving files, we don't need previous command and it is set to 0
-   * as a default value.
-   */
-  int mLastCommand;
-
-  int mPacketLength;
-  int mPutPacketReceivedLength;
-  int mBodySegmentLength;
-  int mUpdateProgressCounter;
-
-  /**
-   * When it is true and the target service on target device couldn't be found,
-   * refreshing SDP records is necessary.
-   */
-  bool mNeedsUpdatingSdpRecords;
-
-  /**
-   * Set when StopSendingFile() is called.
-   */
-  bool mAbortFlag;
-
-  /**
-   * Set when receiving the first PUT packet of a new file
-   */
-  bool mNewFileFlag;
-
-  /**
-   * Set when receiving a PutFinal packet
-   */
-  bool mPutFinalFlag;
-
-  /**
-   * Set when FileTransferComplete() is called
-   */
-  bool mSendTransferCompleteFlag;
-
-  /**
-   * Set when a transfer is successfully completed.
-   */
-  bool mSuccessFlag;
-
-  /**
-   * True: Receive file (Server)
-   * False: Send file (Client)
-   */
-  bool mIsServer;
-
-  /**
-   * Set when receiving the first PUT packet and wait for
-   * ConfirmReceivingFile() to be called.
-   */
-  bool mWaitingForConfirmationFlag;
-
-  nsString mFileName;
-  nsString mContentType;
-  uint32_t mFileLength;
-  uint32_t mSentFileLength;
-  bool mWaitingToSendPutFinal;
-
-  UniquePtr<uint8_t[]> mBodySegment;
-  UniquePtr<uint8_t[]> mReceivedDataBuffer;
-
-  int mCurrentBlobIndex;
-  RefPtr<Blob> mBlob;
-  nsTArray<SendFileBatch> mBatches;
-
-  /**
-   * A seperate member thread is required because our read calls can block
-   * execution, which is not allowed to happen on the IOThread.
-   */
-  nsCOMPtr<nsIThread> mReadFileThread;
-  nsCOMPtr<nsIOutputStream> mOutputStream;
-  nsCOMPtr<nsIInputStream> mInputStream;
-  nsCOMPtr<nsIVolumeMountLock> mMountLock;
-  RefPtr<DeviceStorageFile> mDsFile;
-  RefPtr<DeviceStorageFile> mDummyDsFile;
-
-  // If a connection has been established, mSocket will be the socket
-  // communicating with the remote socket. We maintain the invariant that if
-  // mSocket is non-null, mRfcommSocket and mL2capSocket must be null (and vice
-  // versa).
-  RefPtr<BluetoothSocket> mSocket;
-
-  // Server sockets. Once an inbound connection is established, it will hand
-  // over the ownership to mSocket, and get a new server socket while Listen()
-  // is called.
-  RefPtr<BluetoothSocket> mRfcommSocket;
-  RefPtr<BluetoothSocket> mL2capSocket;
-
-  BluetoothSocketType mSocketType;
-
-  // This holds the time when OPP manager fail to get service channel and
-  // prepare to refresh SDP records.
-  mozilla::TimeStamp mLastServiceChannelCheck;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluez_BluetoothOppManager_h
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothSocket.cpp
+++ /dev/null
@@ -1,792 +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 "BluetoothSocket.h"
-#include <fcntl.h>
-#include "BluetoothSocketObserver.h"
-#include "BluetoothUnixSocketConnector.h"
-#include "BluetoothUtils.h"
-#include "mozilla/DebugOnly.h"
-#include "mozilla/RefPtr.h"
-#include "mozilla/Unused.h"
-#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
-#include "nsXULAppAPI.h"
-
-using namespace mozilla::ipc;
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-static const size_t MAX_READ_SIZE = 1 << 16;
-
-//
-// BluetoothSocketIO
-//
-
-class BluetoothSocket::BluetoothSocketIO final
-  : public UnixSocketWatcher
-  , public DataSocketIO
-{
-public:
-  BluetoothSocketIO(MessageLoop* aConsumerLoop,
-                    MessageLoop* aIOLoop,
-                    BluetoothSocket* aConsumer,
-                    BluetoothUnixSocketConnector* aConnector);
-  ~BluetoothSocketIO();
-
-  void GetSocketAddr(BluetoothAddress& aAddress) const;
-
-  BluetoothSocket* GetBluetoothSocket();
-  DataSocket* GetDataSocket();
-
-  // Delayed-task handling
-  //
-
-  void SetDelayedConnectTask(CancelableRunnable* aTask);
-  void ClearDelayedConnectTask();
-  void CancelDelayedConnectTask();
-
-  // Task callback methods
-  //
-
-  /**
-   * Run bind/listen to prepare for further runs of accept()
-   */
-  void Listen();
-
-  /**
-   * Connect to a socket
-   */
-  void Connect();
-
-  void Send(UnixSocketIOBuffer* aBuffer);
-
-  // I/O callback methods
-  //
-
-  void OnConnected() override;
-  void OnError(const char* aFunction, int aErrno) override;
-  void OnListening() override;
-  void OnSocketCanAcceptWithoutBlocking() override;
-  void OnSocketCanReceiveWithoutBlocking() override;
-  void OnSocketCanSendWithoutBlocking() override;
-
-  // Methods for |DataSocket|
-  //
-
-  nsresult QueryReceiveBuffer(UnixSocketIOBuffer** aBuffer);
-  void ConsumeBuffer();
-  void DiscardBuffer();
-
-  // Methods for |SocketIOBase|
-  //
-
-  SocketBase* GetSocketBase() override;
-
-  bool IsShutdownOnConsumerThread() const override;
-  bool IsShutdownOnIOThread() const override;
-
-  void ShutdownOnConsumerThread() override;
-  void ShutdownOnIOThread() override;
-
-private:
-  class ReceiveTask;
-
-  void FireSocketError();
-
-  /**
-   * Consumer pointer. Non-thread-safe pointer, so should only be manipulated
-   * directly from consumer thread. All non-consumer-thread accesses should
-   * happen with mIO as container.
-   */
-  BluetoothSocket* mConsumer;
-
-  /**
-   * Connector object used to create the connection we are currently using.
-   */
-  UniquePtr<BluetoothUnixSocketConnector> mConnector;
-
-  /**
-   * If true, do not requeue whatever task we're running
-   */
-  bool mShuttingDownOnIOThread;
-
-  /**
-   * Number of valid bytes in |mAddress|
-   */
-  socklen_t mAddressLength;
-
-  /**
-   * Address structure of the socket currently in use
-   */
-  struct sockaddr_storage mAddress;
-
-  /**
-   * Task member for delayed connect task. Should only be access on consumer
-   * thread.
-   */
-  CancelableRunnable* mDelayedConnectTask;
-
-  /**
-   * I/O buffer for received data
-   */
-  UniquePtr<UnixSocketRawData> mBuffer;
-};
-
-BluetoothSocket::BluetoothSocketIO::BluetoothSocketIO(
-  MessageLoop* aConsumerLoop,
-  MessageLoop* aIOLoop,
-  BluetoothSocket* aConsumer,
-  BluetoothUnixSocketConnector* aConnector)
-  : UnixSocketWatcher(aIOLoop)
-  , DataSocketIO(aConsumerLoop)
-  , mConsumer(aConsumer)
-  , mConnector(aConnector)
-  , mShuttingDownOnIOThread(false)
-  , mAddressLength(0)
-  , mDelayedConnectTask(nullptr)
-{
-  MOZ_ASSERT(mConsumer);
-  MOZ_ASSERT(mConnector);
-
-  MOZ_COUNT_CTOR_INHERITED(BluetoothSocketIO, DataSocketIO);
-}
-
-BluetoothSocket::BluetoothSocketIO::~BluetoothSocketIO()
-{
-  MOZ_ASSERT(IsConsumerThread());
-  MOZ_ASSERT(IsShutdownOnConsumerThread());
-
-  MOZ_COUNT_DTOR_INHERITED(BluetoothSocketIO, DataSocketIO);
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::GetSocketAddr(
-  BluetoothAddress& aAddress) const
-{
-  if (!mConnector) {
-    NS_WARNING("No connector to get socket address from!");
-    aAddress.Clear();
-    return;
-  }
-
-  nsresult rv = mConnector->ConvertAddress(
-    *reinterpret_cast<const struct sockaddr*>(&mAddress), sizeof(mAddress),
-    aAddress);
-  if (NS_FAILED(rv)) {
-    aAddress.Clear();
-    return;
-  }
-}
-
-BluetoothSocket*
-BluetoothSocket::BluetoothSocketIO::GetBluetoothSocket()
-{
-  return mConsumer;
-}
-
-DataSocket*
-BluetoothSocket::BluetoothSocketIO::GetDataSocket()
-{
-  return GetBluetoothSocket();
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::SetDelayedConnectTask(CancelableRunnable* aTask)
-{
-  MOZ_ASSERT(IsConsumerThread());
-
-  mDelayedConnectTask = aTask;
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::ClearDelayedConnectTask()
-{
-  MOZ_ASSERT(IsConsumerThread());
-
-  mDelayedConnectTask = nullptr;
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::CancelDelayedConnectTask()
-{
-  MOZ_ASSERT(IsConsumerThread());
-
-  if (!mDelayedConnectTask) {
-    return;
-  }
-
-  mDelayedConnectTask->Cancel();
-  ClearDelayedConnectTask();
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::Listen()
-{
-  MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
-  MOZ_ASSERT(mConnector);
-
-  if (!IsOpen()) {
-    mAddressLength = sizeof(mAddress);
-
-    int fd;
-    nsresult rv = mConnector->CreateListenSocket(
-      reinterpret_cast<struct sockaddr*>(&mAddress), &mAddressLength, fd);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      FireSocketError();
-      return;
-    }
-    SetFd(fd);
-
-    // calls OnListening on success, or OnError otherwise
-    rv = UnixSocketWatcher::Listen(
-      reinterpret_cast<struct sockaddr*>(&mAddress), mAddressLength);
-    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Listen failed");
-  }
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::Connect()
-{
-  MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
-  MOZ_ASSERT(mConnector);
-
-  if (!IsOpen()) {
-    mAddressLength = sizeof(mAddress);
-
-    int fd;
-    nsresult rv = mConnector->CreateStreamSocket(
-      reinterpret_cast<struct sockaddr*>(&mAddress), &mAddressLength, fd);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      FireSocketError();
-      return;
-    }
-    SetFd(fd);
-  }
-
-  // calls OnConnected() on success, or OnError() otherwise
-  DebugOnly<nsresult> rv = UnixSocketWatcher::Connect(
-    reinterpret_cast<struct sockaddr*>(&mAddress), mAddressLength);
-  NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Connect failed");
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::Send(UnixSocketIOBuffer* aBuffer)
-{
-  EnqueueData(aBuffer);
-  AddWatchers(WRITE_WATCHER, false);
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::OnConnected()
-{
-  MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
-  MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_CONNECTED);
-
-  GetConsumerThread()->PostTask(
-    MakeAndAddRef<SocketEventTask>(this, SocketEventTask::CONNECT_SUCCESS));
-
-  AddWatchers(READ_WATCHER, true);
-  if (HasPendingData()) {
-    AddWatchers(WRITE_WATCHER, false);
-  }
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::OnListening()
-{
-  MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
-  MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_LISTENING);
-
-  AddWatchers(READ_WATCHER, true);
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::OnError(const char* aFunction, int aErrno)
-{
-  MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
-
-  UnixFdWatcher::OnError(aFunction, aErrno);
-  FireSocketError();
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::OnSocketCanAcceptWithoutBlocking()
-{
-  MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
-  MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_LISTENING);
-
-  RemoveWatchers(READ_WATCHER|WRITE_WATCHER);
-
-  mAddressLength = sizeof(mAddress);
-
-  int fd;
-  nsresult rv = mConnector->AcceptStreamSocket(
-    GetFd(),
-    reinterpret_cast<struct sockaddr*>(&mAddress), &mAddressLength, fd);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    FireSocketError();
-    return;
-  }
-
-  Close();
-  SetSocket(fd, SOCKET_IS_CONNECTED);
-
-  GetConsumerThread()->PostTask(
-    MakeAndAddRef<SocketEventTask>(this, SocketEventTask::CONNECT_SUCCESS));
-
-  AddWatchers(READ_WATCHER, true);
-  if (HasPendingData()) {
-    AddWatchers(WRITE_WATCHER, false);
-  }
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::OnSocketCanReceiveWithoutBlocking()
-{
-  MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
-  MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_CONNECTED); // see bug 990984
-
-  ssize_t res = ReceiveData(GetFd());
-  if (res < 0) {
-    /* I/O error */
-    RemoveWatchers(READ_WATCHER|WRITE_WATCHER);
-  } else if (!res) {
-    /* EOF or peer shutdown */
-    RemoveWatchers(READ_WATCHER);
-  }
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::OnSocketCanSendWithoutBlocking()
-{
-  MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
-  MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_CONNECTED); // see bug 990984
-
-  nsresult rv = SendPendingData(GetFd());
-  if (NS_FAILED(rv)) {
-    return;
-  }
-
-  if (HasPendingData()) {
-    AddWatchers(WRITE_WATCHER, false);
-  }
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::FireSocketError()
-{
-  MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
-
-  // Clean up watchers, statuses, fds
-  Close();
-
-  // Tell the consumer thread we've errored
-  GetConsumerThread()->PostTask(
-    MakeAndAddRef<SocketEventTask>(this, SocketEventTask::CONNECT_ERROR));
-}
-
-// |DataSocketIO|
-
-nsresult
-BluetoothSocket::BluetoothSocketIO::QueryReceiveBuffer(
-  UnixSocketIOBuffer** aBuffer)
-{
-  MOZ_ASSERT(aBuffer);
-
-  if (!mBuffer) {
-    mBuffer = MakeUnique<UnixSocketRawData>(MAX_READ_SIZE);
-  }
-  *aBuffer = mBuffer.get();
-
-  return NS_OK;
-}
-
-/**
- * |ReceiveTask| transfers data received on the I/O thread
- * to an instance of |BluetoothSocket| on the consumer thread.
- */
-class BluetoothSocket::BluetoothSocketIO::ReceiveTask final
-  : public SocketTask<BluetoothSocketIO>
-{
-public:
-  ReceiveTask(BluetoothSocketIO* aIO, UnixSocketBuffer* aBuffer)
-    : SocketTask<BluetoothSocketIO>(aIO)
-    , mBuffer(aBuffer)
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    BluetoothSocketIO* io = SocketTask<BluetoothSocketIO>::GetIO();
-
-    MOZ_ASSERT(io->IsConsumerThread());
-
-    if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
-      // Since we've already explicitly closed and the close
-      // happened before this, this isn't really an error.
-      return NS_OK;
-    }
-
-    BluetoothSocket* bluetoothSocket = io->GetBluetoothSocket();
-    MOZ_ASSERT(bluetoothSocket);
-
-    bluetoothSocket->ReceiveSocketData(mBuffer);
-
-    return NS_OK;
-  }
-
-private:
-  UniquePtr<UnixSocketBuffer> mBuffer;
-};
-
-void
-BluetoothSocket::BluetoothSocketIO::ConsumeBuffer()
-{
-  GetConsumerThread()->PostTask(
-    MakeAndAddRef<ReceiveTask>(this, mBuffer.release()));
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::DiscardBuffer()
-{
-  // Nothing to do.
-}
-
-// |SocketIOBase|
-
-SocketBase*
-BluetoothSocket::BluetoothSocketIO::GetSocketBase()
-{
-  return GetDataSocket();
-}
-
-bool
-BluetoothSocket::BluetoothSocketIO::IsShutdownOnConsumerThread() const
-{
-  MOZ_ASSERT(IsConsumerThread());
-
-  return mConsumer == nullptr;
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::ShutdownOnConsumerThread()
-{
-  MOZ_ASSERT(IsConsumerThread());
-  MOZ_ASSERT(!IsShutdownOnConsumerThread());
-
-  mConsumer = nullptr;
-}
-
-bool
-BluetoothSocket::BluetoothSocketIO::IsShutdownOnIOThread() const
-{
-  return mShuttingDownOnIOThread;
-}
-
-void
-BluetoothSocket::BluetoothSocketIO::ShutdownOnIOThread()
-{
-  MOZ_ASSERT(!IsConsumerThread());
-  MOZ_ASSERT(!mShuttingDownOnIOThread);
-
-  Close(); // will also remove fd from I/O loop
-  mShuttingDownOnIOThread = true;
-}
-
-
-//
-// Socket tasks
-//
-
-class BluetoothSocket::ListenTask final
-  : public SocketIOTask<BluetoothSocketIO>
-{
-public:
-  ListenTask(BluetoothSocketIO* aIO)
-    : SocketIOTask<BluetoothSocketIO>(aIO)
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!GetIO()->IsConsumerThread());
-
-    if (!IsCanceled()) {
-      GetIO()->Listen();
-    }
-    return NS_OK;
-  }
-};
-
-class BluetoothSocket::ConnectTask final
-  : public SocketIOTask<BluetoothSocketIO>
-{
-public:
-  ConnectTask(BluetoothSocketIO* aIO)
-    : SocketIOTask<BluetoothSocketIO>(aIO)
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!GetIO()->IsConsumerThread());
-    MOZ_ASSERT(!IsCanceled());
-
-    GetIO()->Connect();
-
-    return NS_OK;
-  }
-};
-
-class BluetoothSocket::DelayedConnectTask final
-  : public SocketIOTask<BluetoothSocketIO>
-{
-public:
-  DelayedConnectTask(BluetoothSocketIO* aIO)
-    : SocketIOTask<BluetoothSocketIO>(aIO)
-  { }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(GetIO()->IsConsumerThread());
-
-    if (IsCanceled()) {
-      return NS_OK;
-    }
-
-    BluetoothSocketIO* io = GetIO();
-    if (io->IsShutdownOnConsumerThread()) {
-      return NS_OK;
-    }
-
-    io->ClearDelayedConnectTask();
-    io->GetIOLoop()->PostTask(MakeAndAddRef<ConnectTask>(io));
-
-    return NS_OK;
-  }
-};
-
-//
-// BluetoothSocket
-//
-
-BluetoothSocket::BluetoothSocket(BluetoothSocketObserver* aObserver)
-  : mObserver(aObserver)
-  , mIO(nullptr)
-{
-  MOZ_ASSERT(aObserver);
-
-  MOZ_COUNT_CTOR_INHERITED(BluetoothSocket, DataSocket);
-}
-
-BluetoothSocket::~BluetoothSocket()
-{
-  MOZ_ASSERT(!mIO);
-
-  MOZ_COUNT_DTOR_INHERITED(BluetoothSocket, DataSocket);
-}
-
-nsresult
-BluetoothSocket::Connect(const BluetoothAddress& aDeviceAddress,
-                         const BluetoothUuid& aServiceUuid,
-                         BluetoothSocketType aType,
-                         int aChannel,
-                         bool aAuth, bool aEncrypt)
-{
-  MOZ_ASSERT(!aDeviceAddress.IsCleared());
-
-  UniquePtr<BluetoothUnixSocketConnector> connector =
-    MakeUnique<BluetoothUnixSocketConnector>(aDeviceAddress, aType, aChannel,
-                                             aAuth, aEncrypt);
-
-  nsresult rv = Connect(connector.get());
-  if (NS_FAILED(rv)) {
-    BluetoothAddress address;
-    GetAddress(address);
-
-    nsAutoString addressStr;
-    AddressToString(address, addressStr);
-
-    BT_LOGD("%s failed. Current connected device address: %s",
-           __FUNCTION__, NS_ConvertUTF16toUTF8(addressStr).get());
-    return rv;
-  }
-  Unused << connector.release();
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothSocket::Listen(const nsAString& aServiceName,
-                        const BluetoothUuid& aServiceUuid,
-                        BluetoothSocketType aType,
-                        int aChannel,
-                        bool aAuth, bool aEncrypt)
-{
-  UniquePtr<BluetoothUnixSocketConnector> connector =
-    MakeUnique<BluetoothUnixSocketConnector>(BluetoothAddress::ANY(), aType,
-                                             aChannel, aAuth, aEncrypt);
-
-  nsresult rv = Listen(connector.get());
-  if (NS_FAILED(rv)) {
-    BluetoothAddress address;
-    GetAddress(address);
-
-    nsAutoString addressStr;
-    AddressToString(address, addressStr);
-
-    BT_LOGD("%s failed. Current connected device address: %s",
-           __FUNCTION__, NS_ConvertUTF16toUTF8(addressStr).get());
-    return rv;
-  }
-  Unused << connector.release();
-
-  return NS_OK;
-}
-
-void
-BluetoothSocket::ReceiveSocketData(UniquePtr<UnixSocketBuffer>& aBuffer)
-{
-  MOZ_ASSERT(mObserver);
-
-  mObserver->ReceiveSocketData(this, aBuffer);
-}
-
-bool
-BluetoothSocket::SendSocketData(const nsACString& aStr)
-{
-  if (aStr.Length() > MAX_READ_SIZE) {
-    return false;
-  }
-
-  SendSocketData(new UnixSocketRawData(aStr.BeginReading(), aStr.Length()));
-
-  return true;
-}
-
-nsresult
-BluetoothSocket::Connect(BluetoothUnixSocketConnector* aConnector,
-                         int aDelayMs,
-                         MessageLoop* aConsumerLoop, MessageLoop* aIOLoop)
-{
-  MOZ_ASSERT(aConnector);
-  MOZ_ASSERT(aConsumerLoop);
-  MOZ_ASSERT(aIOLoop);
-  MOZ_ASSERT(!mIO);
-
-  mIO = new BluetoothSocketIO(aConsumerLoop, aIOLoop, this, aConnector);
-  SetConnectionStatus(SOCKET_CONNECTING);
-
-  if (aDelayMs > 0) {
-    RefPtr<DelayedConnectTask> connectTask =
-      MakeAndAddRef<DelayedConnectTask>(mIO);
-    mIO->SetDelayedConnectTask(connectTask);
-    MessageLoop::current()->PostDelayedTask(connectTask.forget(), aDelayMs);
-  } else {
-    aIOLoop->PostTask(MakeAndAddRef<ConnectTask>(mIO));
-  }
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothSocket::Connect(BluetoothUnixSocketConnector* aConnector,
-                         int aDelayMs)
-{
-  return Connect(aConnector, aDelayMs, MessageLoop::current(),
-                 XRE_GetIOMessageLoop());
-}
-
-nsresult
-BluetoothSocket::Listen(BluetoothUnixSocketConnector* aConnector,
-                        MessageLoop* aConsumerLoop, MessageLoop* aIOLoop)
-{
-  MOZ_ASSERT(aConnector);
-  MOZ_ASSERT(aConsumerLoop);
-  MOZ_ASSERT(aIOLoop);
-  MOZ_ASSERT(!mIO);
-
-  mIO = new BluetoothSocketIO(aConsumerLoop, aIOLoop, this, aConnector);
-  SetConnectionStatus(SOCKET_LISTENING);
-
-  aIOLoop->PostTask(MakeAndAddRef<ListenTask>(mIO));
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothSocket::Listen(BluetoothUnixSocketConnector* aConnector)
-{
-  return Listen(aConnector, MessageLoop::current(), XRE_GetIOMessageLoop());
-}
-
-void
-BluetoothSocket::GetAddress(BluetoothAddress& aAddress)
-{
-  if (!mIO || GetConnectionStatus() != SOCKET_CONNECTED) {
-    NS_WARNING("No socket currently open!");
-    aAddress.Clear();
-    return;
-  }
-
-  mIO->GetSocketAddr(aAddress);
-}
-
-// |DataSocket|
-
-void
-BluetoothSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
-{
-  MOZ_ASSERT(mIO);
-  MOZ_ASSERT(mIO->IsConsumerThread());
-  MOZ_ASSERT(!mIO->IsShutdownOnConsumerThread());
-
-  mIO->GetIOLoop()->PostTask(
-    MakeAndAddRef<SocketIOSendTask<BluetoothSocketIO, UnixSocketIOBuffer>>(mIO, aBuffer));
-}
-
-// |SocketBase|
-
-void
-BluetoothSocket::Close()
-{
-  if (!mIO) {
-    return;
-  }
-
-  MOZ_ASSERT(mIO->IsConsumerThread());
-
-  mIO->CancelDelayedConnectTask();
-
-  // From this point on, we consider mIO as being deleted.
-  // We sever the relationship here so any future calls to listen or connect
-  // will create a new implementation.
-  mIO->ShutdownOnConsumerThread();
-  mIO->GetIOLoop()->PostTask(MakeAndAddRef<SocketIOShutdownTask>(mIO));
-  mIO = nullptr;
-
-  NotifyDisconnect();
-}
-
-void
-BluetoothSocket::OnConnectSuccess()
-{
-  MOZ_ASSERT(mObserver);
-  mObserver->OnSocketConnectSuccess(this);
-}
-
-void
-BluetoothSocket::OnConnectError()
-{
-  MOZ_ASSERT(mObserver);
-  mObserver->OnSocketConnectError(this);
-}
-
-void
-BluetoothSocket::OnDisconnect()
-{
-  MOZ_ASSERT(mObserver);
-  mObserver->OnSocketDisconnect(this);
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothSocket.h
+++ /dev/null
@@ -1,138 +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_bluez_BluetoothSocket_h
-#define mozilla_dom_bluetooth_bluez_BluetoothSocket_h
-
-#include "BluetoothCommon.h"
-#include "mozilla/ipc/DataSocket.h"
-#include "mozilla/ipc/UnixSocketWatcher.h"
-#include "mozilla/UniquePtr.h"
-#include "nsString.h"
-
-class MessageLoop;
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothSocketObserver;
-class BluetoothUnixSocketConnector;
-
-class BluetoothSocket final : public mozilla::ipc::DataSocket
-{
-public:
-  BluetoothSocket(BluetoothSocketObserver* aObserver);
-  ~BluetoothSocket();
-
-  nsresult Connect(const BluetoothAddress& aDeviceAddress,
-                   const BluetoothUuid& aServiceUuid,
-                   BluetoothSocketType aType,
-                   int aChannel,
-                   bool aAuth, bool aEncrypt);
-
-  nsresult Listen(const nsAString& aServiceName,
-                  const BluetoothUuid& aServiceUuid,
-                  BluetoothSocketType aType,
-                  int aChannel,
-                  bool aAuth, bool aEncrypt);
-
-  /**
-   * Method to be called whenever data is received. This is only called on the
-   * consumer thread.
-   *
-   * @param aBuffer Data received from the socket.
-   */
-  void ReceiveSocketData(UniquePtr<mozilla::ipc::UnixSocketBuffer>& aBuffer);
-
-  /**
-   * Convenience function for sending strings to the socket (common in bluetooth
-   * profile usage). Converts to a UnixSocketRawData struct. Can only be called
-   * on originating thread.
-   *
-   * @param aMessage String to be sent to socket
-   *
-   * @return true if data is queued, false otherwise (i.e. not connected)
-   */
-  bool SendSocketData(const nsACString& aMessage);
-
-  /**
-   * Starts a task on the socket that will try to connect to a socket in a
-   * non-blocking manner.
-   *
-   * @param aConnector Connector object for socket type specific functions
-   * @param aDelayMs Time delay in milli-seconds.
-   * @param aConsumerLoop The socket's consumer thread.
-   * @param aIOLoop The socket's I/O thread.
-   * @return NS_OK on success, or an XPCOM error code otherwise.
-   */
-  nsresult Connect(BluetoothUnixSocketConnector* aConnector, int aDelayMs,
-                   MessageLoop* aConsumerLoop, MessageLoop* aIOLoop);
-
-  /**
-   * Starts a task on the socket that will try to connect to a socket in a
-   * non-blocking manner.
-   *
-   * @param aConnector Connector object for socket type specific functions
-   * @param aDelayMs Time delay in milli-seconds.
-   * @return NS_OK on success, or an XPCOM error code otherwise.
-   */
-  nsresult Connect(BluetoothUnixSocketConnector* aConnector,
-                   int aDelayMs = 0);
-
-  /**
-   * Starts a task on the socket that will try to accept a new connection in a
-   * non-blocking manner.
-   *
-   * @param aConnector Connector object for socket type specific functions
-   * @param aConsumerLoop The socket's consumer thread.
-   * @param aIOLoop The socket's I/O thread.
-   * @return NS_OK on success, or an XPCOM error code otherwise.
-   */
-  nsresult Listen(BluetoothUnixSocketConnector* aConnector,
-                  MessageLoop* aConsumerLoop, MessageLoop* aIOLoop);
-
-  /**
-   * Starts a task on the socket that will try to accept a new connection in a
-   * non-blocking manner.
-   *
-   * @param aConnector Connector object for socket type specific functions
-   * @return NS_OK on success, or an XPCOM error code otherwise.
-   */
-  nsresult Listen(BluetoothUnixSocketConnector* aConnector);
-
-  /**
-   * Get the current socket address.
-   *
-   * @param[out] aDeviceAddress Returns the address.
-   */
-  void GetAddress(BluetoothAddress& aDeviceAddress);
-
-  // Methods for |DataSocket|
-  //
-
-  void SendSocketData(mozilla::ipc::UnixSocketIOBuffer* aBuffer) override;
-
-  // Methods for |SocketBase|
-  //
-
-  void Close() override;
-
-  void OnConnectSuccess() override;
-  void OnConnectError() override;
-  void OnDisconnect() override;
-
-private:
-  class BluetoothSocketIO;
-  class ConnectTask;
-  class DelayedConnectTask;
-  class ListenTask;
-
-  BluetoothSocketObserver* mObserver;
-  BluetoothSocketIO* mIO;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluez_BluetoothSocket_h
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp
+++ /dev/null
@@ -1,476 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-
-/*
- * Copyright 2009, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * NOTE: Due to being based on the D-Bus compatibility layer for
- * Android's Bluetooth implementation, this file is licensed under the
- * Apache License instead of MPL.
- */
-
-#include "BluetoothUnixSocketConnector.h"
-#include <bluetooth/l2cap.h>
-#include <bluetooth/rfcomm.h>
-#include <bluetooth/sco.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
-#include "nsThreadUtils.h" // For NS_IsMainThread.
-
-using namespace mozilla::ipc;
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-static const int RFCOMM_SO_SNDBUF = 70 * 1024;  // 70 KB send buffer
-static const int L2CAP_SO_SNDBUF = 400 * 1024;  // 400 KB send buffer
-static const int L2CAP_SO_RCVBUF = 400 * 1024;  // 400 KB receive buffer
-static const int L2CAP_MAX_MTU = 65000;
-
-BluetoothUnixSocketConnector::BluetoothUnixSocketConnector(
-  const BluetoothAddress& aAddress,
-  BluetoothSocketType aType,
-  int aChannel,
-  bool aAuth,
-  bool aEncrypt)
-  : mAddress(aAddress)
-  , mType(aType)
-  , mChannel(aChannel)
-  , mAuth(aAuth)
-  , mEncrypt(aEncrypt)
-{
-  MOZ_COUNT_CTOR_INHERITED(BluetoothUnixSocketConnector, UnixSocketConnector);
-}
-
-BluetoothUnixSocketConnector::~BluetoothUnixSocketConnector()
-{
-  MOZ_COUNT_DTOR_INHERITED(BluetoothUnixSocketConnector, UnixSocketConnector);
-}
-
-nsresult
-BluetoothUnixSocketConnector::CreateSocket(int& aFd) const
-{
-  static const int sType[] = {
-    [0] = 0,
-    [BluetoothSocketType::RFCOMM] = SOCK_STREAM,
-    [BluetoothSocketType::SCO] = SOCK_SEQPACKET,
-    [BluetoothSocketType::L2CAP] = SOCK_SEQPACKET,
-    [BluetoothSocketType::EL2CAP] = SOCK_STREAM
-  };
-  static const int sProtocol[] = {
-    [0] = 0,
-    [BluetoothSocketType::RFCOMM] = BTPROTO_RFCOMM,
-    [BluetoothSocketType::SCO] = BTPROTO_SCO,
-    [BluetoothSocketType::L2CAP] = BTPROTO_L2CAP,
-    [BluetoothSocketType::EL2CAP] = BTPROTO_L2CAP
-  };
-
-  MOZ_ASSERT(mType < MOZ_ARRAY_LENGTH(sType));
-  MOZ_ASSERT(mType < MOZ_ARRAY_LENGTH(sProtocol));
-
-  BT_LOGR("mType=%d, sType=%d sProtocol=%d",
-          static_cast<int>(mType), sType[mType], sProtocol[mType]);
-
-  aFd = socket(AF_BLUETOOTH, sType[mType], sProtocol[mType]);
-  if (aFd < 0) {
-    BT_LOGR("Could not open Bluetooth socket: %d(%s)",
-            errno, strerror(errno));
-    return NS_ERROR_FAILURE;
-  }
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothUnixSocketConnector::SetSocketFlags(int aFd) const
-{
-  static const int sReuseAddress = 1;
-
-  // Set close-on-exec bit.
-  int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFD));
-  if (flags < 0) {
-    return NS_ERROR_FAILURE;
-  }
-  flags |= FD_CLOEXEC;
-  int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFD, flags));
-  if (res < 0) {
-    return NS_ERROR_FAILURE;
-  }
-
-  // Set non-blocking status flag.
-  flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL));
-  if (flags < 0) {
-    return NS_ERROR_FAILURE;
-  }
-  flags |= O_NONBLOCK;
-  res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags));
-  if (res < 0) {
-    return NS_ERROR_FAILURE;
-  }
-
-  // Set socket addr to be reused even if kernel is still waiting to close.
-  res = setsockopt(aFd, SOL_SOCKET, SO_REUSEADDR, &sReuseAddress,
-                   sizeof(sReuseAddress));
-  if (res < 0) {
-    return NS_ERROR_FAILURE;
-  }
-
-  int lm;
-
-  switch (mType) {
-    case BluetoothSocketType::RFCOMM:
-      lm |= mAuth ? RFCOMM_LM_AUTH : 0;
-      lm |= mEncrypt ? RFCOMM_LM_ENCRYPT : 0;
-      break;
-    case BluetoothSocketType::L2CAP:
-    case BluetoothSocketType::EL2CAP:
-      lm |= mAuth ? L2CAP_LM_AUTH : 0;
-      lm |= mEncrypt ? L2CAP_LM_ENCRYPT : 0;
-      break;
-    default:
-      // kernel does not yet support LM for SCO
-      lm = 0;
-      break;
-  }
-
-  if (lm) {
-    static const int sLevel[] = {
-      [0] = 0,
-      [BluetoothSocketType::RFCOMM] = SOL_RFCOMM,
-      [BluetoothSocketType::SCO] = 0,
-      [BluetoothSocketType::L2CAP] = SOL_L2CAP,
-      [BluetoothSocketType::EL2CAP] = SOL_L2CAP
-    };
-    static const int sOptname[] = {
-      [0] = 0,
-      [BluetoothSocketType::RFCOMM] = RFCOMM_LM,
-      [BluetoothSocketType::SCO] = 0,
-      [BluetoothSocketType::L2CAP] = L2CAP_LM,
-      [BluetoothSocketType::EL2CAP] = L2CAP_LM
-    };
-
-    MOZ_ASSERT(mType < MOZ_ARRAY_LENGTH(sLevel));
-    MOZ_ASSERT(mType < MOZ_ARRAY_LENGTH(sOptname));
-
-    if (setsockopt(aFd, sLevel[mType], sOptname[mType], &lm, sizeof(lm)) < 0) {
-      BT_LOGR("setsockopt(RFCOMM_LM) failed, throwing");
-      return NS_ERROR_FAILURE;
-    }
-  }
-
-  if (mType == BluetoothSocketType::RFCOMM) {
-
-    /* Setting RFCOMM socket options */
-
-    int sndbuf = RFCOMM_SO_SNDBUF;
-    if (setsockopt(aFd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf))) {
-      BT_WARNING("setsockopt(SO_SNDBUF) failed, throwing");
-      return NS_ERROR_FAILURE;
-    }
-  }
-
-  if (mType == BluetoothSocketType::L2CAP ||
-      mType == BluetoothSocketType::EL2CAP) {
-
-    /* Setting L2CAP/EL2CAP socket options */
-
-    struct l2cap_options opts;
-    socklen_t optlen = sizeof(opts);
-    int res = getsockopt(aFd, SOL_L2CAP, L2CAP_OPTIONS, &opts, &optlen);
-    if (!res) {
-      /* setting MTU for [E]L2CAP */
-      opts.omtu = opts.imtu = L2CAP_MAX_MTU;
-
-      /* Enable ERTM for [E]L2CAP */
-      if (mType == BluetoothSocketType::EL2CAP) {
-        opts.flush_to = 0xffff; /* infinite */
-        opts.mode = L2CAP_MODE_ERTM;
-        opts.fcs = 1;
-        opts.txwin_size = 64;
-        opts.max_tx = 10;
-      }
-
-      setsockopt(aFd, SOL_L2CAP, L2CAP_OPTIONS, &opts, optlen);
-    }
-
-    if (mType == BluetoothSocketType::EL2CAP) {
-
-      /* Set larger SNDBUF and RCVBUF for EL2CAP connections */
-
-      int sndbuf = L2CAP_SO_SNDBUF;
-      if (setsockopt(aFd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf)) < 0) {
-        BT_LOGR("setsockopt(SO_SNDBUF) failed, throwing");
-        return NS_ERROR_FAILURE;
-      }
-
-      int rcvbuf = L2CAP_SO_RCVBUF;
-      if (setsockopt(aFd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf)) < 0) {
-        BT_LOGR("setsockopt(SO_RCVBUF) failed, throwing");
-        return NS_ERROR_FAILURE;
-      }
-    }
-  }
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothUnixSocketConnector::CreateAddress(struct sockaddr& aAddress,
-                                            socklen_t& aAddressLength) const
-{
-  switch (mType) {
-    case BluetoothSocketType::RFCOMM: {
-        struct sockaddr_rc* rc =
-          reinterpret_cast<struct sockaddr_rc*>(&aAddress);
-        rc->rc_family = AF_BLUETOOTH;
-        nsresult rv = ConvertAddress(mAddress, rc->rc_bdaddr);
-        if (NS_FAILED(rv)) {
-          return rv;
-        }
-        rc->rc_channel = mChannel;
-        aAddressLength = sizeof(*rc);
-      }
-      break;
-    case BluetoothSocketType::L2CAP:
-    case BluetoothSocketType::EL2CAP: {
-        struct sockaddr_l2* l2 =
-          reinterpret_cast<struct sockaddr_l2*>(&aAddress);
-        l2->l2_family = AF_BLUETOOTH;
-        l2->l2_psm = mChannel;
-        nsresult rv = ConvertAddress(mAddress, l2->l2_bdaddr);
-        if (NS_FAILED(rv)) {
-          return rv;
-        }
-        l2->l2_cid = 0;
-        aAddressLength = sizeof(*l2);
-      }
-      break;
-    case BluetoothSocketType::SCO: {
-        struct sockaddr_sco* sco =
-          reinterpret_cast<struct sockaddr_sco*>(&aAddress);
-        sco->sco_family = AF_BLUETOOTH;
-        nsresult rv = ConvertAddress(mAddress, sco->sco_bdaddr);
-        if (NS_FAILED(rv)) {
-          return rv;
-        }
-        sco->sco_pkt_type = 0;
-        aAddressLength = sizeof(*sco);
-      }
-      break;
-    default:
-      MOZ_CRASH("Socket type unknown!");
-      return NS_ERROR_ABORT;
-  }
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothUnixSocketConnector::ConvertAddress(const BluetoothAddress& aAddress,
-                                             bdaddr_t& aBdAddr)
-{
-  MOZ_ASSERT(MOZ_ARRAY_LENGTH(aBdAddr.b) == MOZ_ARRAY_LENGTH(aAddress.mAddr));
-
-  /* read source address from end backwards */
-  auto src = aAddress.mAddr + MOZ_ARRAY_LENGTH(aAddress.mAddr) - 1;
-
-  for (size_t i = 0ul; i < MOZ_ARRAY_LENGTH(aBdAddr.b); ++i) {
-    aBdAddr.b[i] = *src--;
-  }
-  return NS_OK;
-}
-
-nsresult
-BluetoothUnixSocketConnector::ConvertAddress(const bdaddr_t& aBdAddr,
-                                             BluetoothAddress& aAddress)
-{
-  MOZ_ASSERT(MOZ_ARRAY_LENGTH(aBdAddr.b) == MOZ_ARRAY_LENGTH(aAddress.mAddr));
-
-  /* read source address from end backwards */
-  auto src = aBdAddr.b + MOZ_ARRAY_LENGTH(aBdAddr.b) - 1;
-
-  for (size_t i = 0ul; i < MOZ_ARRAY_LENGTH(aAddress.mAddr); ++i) {
-    aAddress.mAddr[i] = *src--;
-  }
-  return NS_OK;
-}
-
-nsresult
-BluetoothUnixSocketConnector::ConvertAddress(
-  const struct sockaddr& aAddress, socklen_t aAddressLength,
-  BluetoothAddress& aAddressOut)
-{
-  MOZ_ASSERT(aAddress.sa_family == AF_BLUETOOTH);
-
-  switch (mType) {
-    case BluetoothSocketType::RFCOMM: {
-        const struct sockaddr_rc* rc =
-          reinterpret_cast<const struct sockaddr_rc*>(&aAddress);
-        return ConvertAddress(rc->rc_bdaddr, aAddressOut);
-      }
-      break;
-    case BluetoothSocketType::SCO: {
-        const struct sockaddr_sco* sco =
-          reinterpret_cast<const struct sockaddr_sco*>(&aAddress);
-        return ConvertAddress(sco->sco_bdaddr, aAddressOut);
-      }
-      break;
-    case BluetoothSocketType::L2CAP:
-    case BluetoothSocketType::EL2CAP: {
-        const struct sockaddr_l2* l2 =
-          reinterpret_cast<const struct sockaddr_l2*>(&aAddress);
-        return ConvertAddress(l2->l2_bdaddr, aAddressOut);
-      }
-      break;
-    default:
-      BT_LOGR("Unknown socket type %d", static_cast<int>(mType));
-      return NS_ERROR_ILLEGAL_VALUE;
-  }
-}
-
-
-// |UnixSocketConnector|
-
-nsresult
-BluetoothUnixSocketConnector::ConvertAddressToString(
-  const struct sockaddr& aAddress, socklen_t aAddressLength,
-  nsACString& aAddressString)
-{
-  MOZ_ASSERT(aAddress.sa_family == AF_BLUETOOTH);
-
-  const uint8_t* b;
-
-  switch (mType) {
-    case BluetoothSocketType::RFCOMM: {
-        const struct sockaddr_rc* rc =
-          reinterpret_cast<const struct sockaddr_rc*>(&aAddress);
-        b = rc->rc_bdaddr.b;
-      }
-      break;
-    case BluetoothSocketType::SCO: {
-        const struct sockaddr_sco* sco =
-          reinterpret_cast<const struct sockaddr_sco*>(&aAddress);
-        b = sco->sco_bdaddr.b;
-      }
-      break;
-    case BluetoothSocketType::L2CAP:
-    case BluetoothSocketType::EL2CAP: {
-        const struct sockaddr_l2* l2 =
-          reinterpret_cast<const struct sockaddr_l2*>(&aAddress);
-        b = l2->l2_bdaddr.b;
-      }
-      break;
-    default:
-      BT_LOGR("Unknown socket type %d", static_cast<int>(mType));
-      return NS_ERROR_ILLEGAL_VALUE;
-  }
-
-  char str[32];
-  snprintf(str, sizeof(str), "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
-           b[5], b[4], b[3], b[2], b[1], b[0]);
-
-  aAddressString.Assign(str);
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothUnixSocketConnector::CreateListenSocket(struct sockaddr* aAddress,
-                                                 socklen_t* aAddressLength,
-                                                 int& aListenFd)
-{
-  ScopedClose fd;
-
-  nsresult rv = CreateSocket(fd.rwget());
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = SetSocketFlags(fd);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  if (aAddress && aAddressLength) {
-    rv = CreateAddress(*aAddress, *aAddressLength);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-  }
-
-  aListenFd = fd.forget();
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothUnixSocketConnector::AcceptStreamSocket(int aListenFd,
-                                                 struct sockaddr* aAddress,
-                                                 socklen_t* aAddressLength,
-                                                 int& aStreamFd)
-{
-  ScopedClose fd(
-    TEMP_FAILURE_RETRY(accept(aListenFd, aAddress, aAddressLength)));
-  if (fd < 0) {
-    NS_WARNING("Cannot accept file descriptor!");
-    return NS_ERROR_FAILURE;
-  }
-  nsresult rv = SetSocketFlags(fd);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  aStreamFd = fd.forget();
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothUnixSocketConnector::CreateStreamSocket(struct sockaddr* aAddress,
-                                                 socklen_t* aAddressLength,
-                                                 int& aStreamFd)
-{
-  ScopedClose fd;
-
-  nsresult rv = CreateSocket(fd.rwget());
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = SetSocketFlags(fd);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  if (aAddress && aAddressLength) {
-    rv = CreateAddress(*aAddress, *aAddressLength);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-  }
-
-  aStreamFd = fd.forget();
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothUnixSocketConnector::Duplicate(UnixSocketConnector*& aConnector)
-{
-  aConnector = new BluetoothUnixSocketConnector(*this);
-
-  return NS_OK;
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.h
+++ /dev/null
@@ -1,72 +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_bluez_BluetoothUnixSocketConnector_h
-#define mozilla_dom_bluetooth_bluez_BluetoothUnixSocketConnector_h
-
-#include <bluetooth/bluetooth.h>
-#include "BluetoothCommon.h"
-#include "mozilla/ipc/UnixSocketConnector.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothUnixSocketConnector final
-  : public mozilla::ipc::UnixSocketConnector
-{
-public:
-  BluetoothUnixSocketConnector(const BluetoothAddress& aAddress,
-                               BluetoothSocketType aType,
-                               int aChannel, bool aAuth, bool aEncrypt);
-  ~BluetoothUnixSocketConnector();
-
-  nsresult ConvertAddress(const struct sockaddr& aAddress,
-                          socklen_t aAddressLength,
-                          BluetoothAddress& aAddressOut);
-
-  // Methods for |UnixSocketConnector|
-  //
-
-  nsresult ConvertAddressToString(const struct sockaddr& aAddress,
-                                  socklen_t aAddressLength,
-                                  nsACString& aAddressString) override;
-
-  nsresult CreateListenSocket(struct sockaddr* aAddress,
-                              socklen_t* aAddressLength,
-                              int& aListenFd) override;
-
-  nsresult AcceptStreamSocket(int aListenFd,
-                              struct sockaddr* aAddress,
-                              socklen_t* aAddressLen,
-                              int& aStreamFd) override;
-
-  nsresult CreateStreamSocket(struct sockaddr* aAddress,
-                              socklen_t* aAddressLength,
-                              int& aStreamFd) override;
-
-  nsresult Duplicate(UnixSocketConnector*& aConnector) override;
-
-private:
-  static nsresult ConvertAddress(const BluetoothAddress& aAddress,
-                                 bdaddr_t& aBdAddr);
-
-  static nsresult ConvertAddress(const bdaddr_t& aBdAddr,
-                                 BluetoothAddress& aAddress);
-
-  nsresult CreateSocket(int& aFd) const;
-  nsresult SetSocketFlags(int aFd) const;
-  nsresult CreateAddress(struct sockaddr& aAddress,
-                         socklen_t& aAddressLength) const;
-
-  BluetoothAddress mAddress;
-  BluetoothSocketType mType;
-  int mChannel;
-  bool mAuth;
-  bool mEncrypt;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluez_BluetoothUnixSocketConnector_h
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothCommon.cpp
+++ /dev/null
@@ -1,68 +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 "BluetoothCommon.h"
-
-// FIXME: Bug 1224171: This variable needs to be cleaned up and
-//                     remove from global namespace.
-bool gBluetoothDebugFlag = false;
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-//
-// |BluetoothAddress|
-//
-
-const BluetoothAddress& BluetoothAddress::ANY()
-{
-  static const BluetoothAddress sAddress(0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
-  return sAddress;
-}
-
-const BluetoothAddress& BluetoothAddress::ALL()
-{
-  static const BluetoothAddress sAddress(0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
-  return sAddress;
-}
-
-const BluetoothAddress& BluetoothAddress::LOCAL()
-{
-  static const BluetoothAddress sAddress(0x00, 0x00, 0x00, 0xff, 0xff, 0xff);
-  return sAddress;
-}
-
-//
-// |BluetoothUuid|
-//
-
-const BluetoothUuid& BluetoothUuid::ZERO()
-{
-  static const BluetoothUuid sUuid(0x00, 0x00, 0x00, 0x00,
-                                   0x00, 0x00, 0x00, 0x00,
-                                   0x00, 0x00, 0x00, 0x00,
-                                   0x00, 0x00, 0x00, 0x00);
-  return sUuid;
-}
-
-/*
- * [Bluetooth Specification Version 4.2, Volume 3, Part B, Section 2.5.1]
- *
- * To reduce the burden of storing and transferring 128-bit UUID values, a
- * range of UUID values has been pre-allocated for assignment to often-used,
- * registered purposes. The first UUID in this pre-allocated range is known as
- * the Bluetooth Base UUID and has the value 00000000-0000-1000-8000-
- * 00805F9B34FB, from the Bluetooth Assigned Numbers document.
- */
-const BluetoothUuid& BluetoothUuid::BASE()
-{
-  static const BluetoothUuid sUuid(0x00, 0x00, 0x00, 0x00,
-                                   0x00, 0x00, 0x10, 0x00,
-                                   0x80, 0x00, 0x00, 0x80,
-                                   0x5f, 0x9b, 0x34, 0xfb);
-  return sUuid;
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothCommon.h
+++ /dev/null
@@ -1,1433 +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_BluetoothCommon_h
-#define mozilla_dom_bluetooth_BluetoothCommon_h
-
-#include <algorithm>
-#include "mozilla/Compiler.h"
-#include "mozilla/EndianUtils.h"
-#include "mozilla/Observer.h"
-#include "mozilla/UniquePtr.h"
-#include "nsPrintfCString.h"
-#include "nsString.h"
-#include "nsTArray.h"
-
-extern bool gBluetoothDebugFlag;
-
-#define SWITCH_BT_DEBUG(V) (gBluetoothDebugFlag = V)
-
-#undef BT_LOG
-#if defined(MOZ_WIDGET_GONK)
-#include <android/log.h>
-
-/**
- * Prints 'D'EBUG build logs, which show in DEBUG build only when
- * developer setting 'Bluetooth output in adb' is enabled.
- */
-#define BT_LOGD(msg, ...)                                            \
-  do {                                                               \
-    if (gBluetoothDebugFlag) {                                       \
-      __android_log_print(ANDROID_LOG_INFO, "GeckoBluetooth",        \
-                          "%s: " msg, __FUNCTION__, ##__VA_ARGS__);  \
-    }                                                                \
-  } while(0)
-
-/**
- * Prints 'R'ELEASE build logs, which show in both RELEASE and DEBUG builds.
- */
-#define BT_LOGR(msg, ...)                                            \
-  __android_log_print(ANDROID_LOG_INFO, "GeckoBluetooth",            \
-                      "%s: " msg, __FUNCTION__, ##__VA_ARGS__)
-
-/**
- * Prints DEBUG build warnings, which show in DEBUG build only.
- */
-#define BT_WARNING(args...)                                          \
-  NS_WARNING(nsPrintfCString(args).get())
-
-#else
-#define BT_LOGD(msg, ...)                                            \
-  do {                                                               \
-    if (gBluetoothDebugFlag) {                                       \
-      printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__);               \
-    }                                                                \
-  } while(0)
-
-#define BT_LOGR(msg, ...) printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__)
-#define BT_WARNING(msg, ...) printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__)
-#endif
-
-/**
- * Convert an enum value to string and append it to a fallible array.
- */
-#define BT_APPEND_ENUM_STRING_FALLIBLE(array, enumType, enumValue)   \
-  do {                                                               \
-    uint32_t index = uint32_t(enumValue);                            \
-    nsAutoString name;                                               \
-    name.AssignASCII(enumType##Values::strings[index].value,         \
-                     enumType##Values::strings[index].length);       \
-    array.AppendElement(name, mozilla::fallible);                    \
-  } while(0)
-
-/**
- * Ensure success of system message broadcast with void return.
- */
-#define BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters)       \
-  do {                                                               \
-    if (!BroadcastSystemMessage(type, parameters)) {                 \
-      BT_WARNING("Failed to broadcast [%s]",                         \
-                 NS_ConvertUTF16toUTF8(type).get());                 \
-      return;                                                        \
-    }                                                                \
-  } while(0)
-
-/**
- * Resolve |promise| with |ret| if |x| is false.
- */
-#define BT_ENSURE_TRUE_RESOLVE(x, promise, ret)                      \
-  do {                                                               \
-    if (MOZ_UNLIKELY(!(x))) {                                        \
-      BT_LOGR("BT_ENSURE_TRUE_RESOLVE(" #x ") failed");              \
-      (promise)->MaybeResolve(ret);                                  \
-      return (promise).forget();                                     \
-    }                                                                \
-  } while(0)
-
-/**
- * Reject |promise| with |ret| if |x| is false.
- */
-#define BT_ENSURE_TRUE_REJECT(x, promise, ret)                       \
-  do {                                                               \
-    if (MOZ_UNLIKELY(!(x))) {                                        \
-      BT_LOGR("BT_ENSURE_TRUE_REJECT(" #x ") failed");               \
-      (promise)->MaybeReject(ret);                                   \
-      return (promise).forget();                                     \
-    }                                                                \
-  } while(0)
-
-/**
- * Reject |promise| with |ret| if nsresult |rv| is not successful.
- */
-#define BT_ENSURE_SUCCESS_REJECT(rv, promise, ret)                   \
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(rv), promise, ret)
-
-/**
- * Resolve |promise| with |value| and return |ret| if |x| is false.
- */
-#define BT_ENSURE_TRUE_RESOLVE_RETURN(x, promise, value, ret)        \
-  do {                                                               \
-    if (MOZ_UNLIKELY(!(x))) {                                        \
-      BT_LOGR("BT_ENSURE_TRUE_RESOLVE_RETURN(" #x ") failed");       \
-      (promise)->MaybeResolve(value);                                \
-      return ret;                                                    \
-    }                                                                \
-  } while(0)
-
-/**
- * Resolve |promise| with |value| and return if |x| is false.
- */
-#define BT_ENSURE_TRUE_RESOLVE_VOID(x, promise, value)               \
-  do {                                                               \
-    if (MOZ_UNLIKELY(!(x))) {                                        \
-      BT_LOGR("BT_ENSURE_TRUE_RESOLVE_VOID(" #x ") failed");         \
-      (promise)->MaybeResolve(value);                                \
-      return;                                                        \
-    }                                                                \
-  } while(0)
-
-/**
- * Reject |promise| with |value| and return |ret| if |x| is false.
- */
-#define BT_ENSURE_TRUE_REJECT_RETURN(x, promise, value, ret)         \
-  do {                                                               \
-    if (MOZ_UNLIKELY(!(x))) {                                        \
-      BT_LOGR("BT_ENSURE_TRUE_REJECT_RETURN(" #x ") failed");        \
-      (promise)->MaybeReject(value);                                 \
-      return ret;                                                    \
-    }                                                                \
-  } while(0)
-
-/**
- * Reject |promise| with |value| and return if |x| is false.
- */
-#define BT_ENSURE_TRUE_REJECT_VOID(x, promise, value)                \
-  do {                                                               \
-    if (MOZ_UNLIKELY(!(x))) {                                        \
-      BT_LOGR("BT_ENSURE_TRUE_REJECT_VOID(" #x ") failed");          \
-      (promise)->MaybeReject(value);                                 \
-      return;                                                        \
-    }                                                                \
-  } while(0)
-
-/**
- * Reject |promise| with |value| and return |ret| if nsresult |rv|
- * is not successful.
- */
-#define BT_ENSURE_SUCCESS_REJECT_RETURN(rv, promise, value, ret)     \
-  BT_ENSURE_TRUE_REJECT_RETURN(NS_SUCCEEDED(rv), promise, value, ret)
-
-/**
- * Reject |promise| with |value| and return if nsresult |rv|
- * is not successful.
- */
-#define BT_ENSURE_SUCCESS_REJECT_VOID(rv, promise, value)            \
-  BT_ENSURE_TRUE_REJECT_VOID(NS_SUCCEEDED(rv), promise, value)
-
-#define BEGIN_BLUETOOTH_NAMESPACE \
-  namespace mozilla { namespace dom { namespace bluetooth {
-#define END_BLUETOOTH_NAMESPACE \
-  } /* namespace bluetooth */ } /* namespace dom */ } /* namespace mozilla */
-#define USING_BLUETOOTH_NAMESPACE \
-  using namespace mozilla::dom::bluetooth;
-
-#define KEY_LOCAL_AGENT       "/B2G/bluetooth/agent"
-#define KEY_REMOTE_AGENT      "/B2G/bluetooth/remote_device_agent"
-#define KEY_MANAGER           "/B2G/bluetooth/manager"
-#define KEY_ADAPTER           "/B2G/bluetooth/adapter"
-#define KEY_PAIRING_LISTENER  "/B2G/bluetooth/pairing_listener"
-
-/**
- * When the connection status of a Bluetooth profile is changed, we'll notify
- * observers which register the following topics.
- */
-#define BLUETOOTH_A2DP_STATUS_CHANGED_ID "bluetooth-a2dp-status-changed"
-#define BLUETOOTH_HFP_STATUS_CHANGED_ID  "bluetooth-hfp-status-changed"
-#define BLUETOOTH_HFP_NREC_STATUS_CHANGED_ID  "bluetooth-hfp-nrec-status-changed"
-#define BLUETOOTH_HID_STATUS_CHANGED_ID  "bluetooth-hid-status-changed"
-#define BLUETOOTH_SCO_STATUS_CHANGED_ID  "bluetooth-sco-status-changed"
-
-/**
- * When the connection status of a Bluetooth profile is changed, we'll
- * dispatch one of the following events.
- */
-#define A2DP_STATUS_CHANGED_ID               "a2dpstatuschanged"
-#define HFP_STATUS_CHANGED_ID                "hfpstatuschanged"
-#define HID_STATUS_CHANGED_ID                "hidstatuschanged"
-#define SCO_STATUS_CHANGED_ID                "scostatuschanged"
-
-/**
- * Types of pairing requests for constructing BluetoothPairingEvent and
- * BluetoothPairingHandle.
- */
-#define PAIRING_REQ_TYPE_DISPLAYPASSKEY       "displaypasskeyreq"
-#define PAIRING_REQ_TYPE_ENTERPINCODE         "enterpincodereq"
-#define PAIRING_REQ_TYPE_CONFIRMATION         "pairingconfirmationreq"
-#define PAIRING_REQ_TYPE_CONSENT              "pairingconsentreq"
-
-/**
- * System message to launch bluetooth app if no pairing listener is ready to
- * receive pairing requests.
- */
-#define SYS_MSG_BT_PAIRING_REQ                "bluetooth-pairing-request"
-
-/**
- * The preference name of bluetooth app origin of bluetooth app. The default
- * value is defined in b2g/app/b2g.js.
- */
-#define PREF_BLUETOOTH_APP_ORIGIN             "dom.bluetooth.app-origin"
-
-/**
- * When a remote device gets paired / unpaired with local bluetooth adapter or
- * pairing process is aborted, we'll dispatch an event.
- */
-#define DEVICE_PAIRED_ID                     "devicepaired"
-#define DEVICE_UNPAIRED_ID                   "deviceunpaired"
-#define PAIRING_ABORTED_ID                   "pairingaborted"
-
-/**
- * When receiving a query about current play status from remote device, we'll
- * dispatch an event.
- */
-#define REQUEST_MEDIA_PLAYSTATUS_ID          "requestmediaplaystatus"
-
-/**
- * When receiving an OBEX authenticate challenge request from a remote device,
- * we'll dispatch an event.
- */
-#define OBEX_PASSWORD_REQ_ID                 "obexpasswordreq"
-
-/**
- * When receiving a PBAP request from a remote device, we'll dispatch an event.
- */
-#define PULL_PHONEBOOK_REQ_ID                "pullphonebookreq"
-#define PULL_VCARD_ENTRY_REQ_ID              "pullvcardentryreq"
-#define PULL_VCARD_LISTING_REQ_ID            "pullvcardlistingreq"
-
-/**
- * When receiving a MAP request from a remote device,
- * we'll dispatch an event.
- */
-#define MAP_MESSAGES_LISTING_REQ_ID          "mapmessageslistingreq"
-#define MAP_GET_MESSAGE_REQ_ID               "mapgetmessagereq"
-#define MAP_SET_MESSAGE_STATUS_REQ_ID        "mapsetmessagestatusreq"
-#define MAP_SEND_MESSAGE_REQ_ID              "mapsendmessagereq"
-#define MAP_FOLDER_LISTING_REQ_ID            "mapfolderlistingreq"
-#define MAP_MESSAGE_UPDATE_REQ_ID            "mapmessageupdatereq"
-
-/**
- * When the value of a characteristic of a remote BLE device changes, we'll
- * dispatch an event
- */
-#define GATT_CHARACTERISTIC_CHANGED_ID       "characteristicchanged"
-
-/**
- * When a remote BLE device gets connected / disconnected, we'll dispatch an
- * event.
- */
-#define GATT_CONNECTION_STATE_CHANGED_ID     "connectionstatechanged"
-
-/**
- * When attributes of BluetoothManager, BluetoothAdapter, or BluetoothDevice
- * are changed, we'll dispatch an event.
- */
-#define ATTRIBUTE_CHANGED_ID                 "attributechanged"
-
-/**
- * When the local GATT server received attribute read/write requests, we'll
- * dispatch an event.
- */
-#define ATTRIBUTE_READ_REQUEST               "attributereadreq"
-#define ATTRIBUTE_WRITE_REQUEST              "attributewritereq"
-
-// Bluetooth address format: xx:xx:xx:xx:xx:xx (or xx_xx_xx_xx_xx_xx)
-#define BLUETOOTH_ADDRESS_LENGTH 17
-#define BLUETOOTH_ADDRESS_NONE   "00:00:00:00:00:00"
-#define BLUETOOTH_ADDRESS_BYTES  6
-
-// Bluetooth stack internal error, such as I/O error
-#define ERR_INTERNAL_ERROR "InternalError"
-
-/**
- * BT specification v4.1 defines the maximum attribute length as 512 octets.
- * Currently use 600 here to conform to bluedroid's BTGATT_MAX_ATTR_LEN.
- */
-#define BLUETOOTH_GATT_MAX_ATTR_LEN 600
-
-/**
- * The maximum descriptor length defined in BlueZ ipc spec.
- * Please refer to http://git.kernel.org/cgit/bluetooth/bluez.git/tree/\
- * android/hal-ipc-api.txt#n532
- */
-#define BLUETOOTH_HID_MAX_DESC_LEN 884
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-enum BluetoothStatus {
-  STATUS_SUCCESS,
-  STATUS_FAIL,
-  STATUS_NOT_READY,
-  STATUS_NOMEM,
-  STATUS_BUSY,
-  STATUS_DONE,
-  STATUS_UNSUPPORTED,
-  STATUS_PARM_INVALID,
-  STATUS_UNHANDLED,
-  STATUS_AUTH_FAILURE,
-  STATUS_RMT_DEV_DOWN,
-  STATUS_AUTH_REJECTED,
-  NUM_STATUS
-};
-
-enum BluetoothAclState {
-  ACL_STATE_CONNECTED,
-  ACL_STATE_DISCONNECTED
-};
-
-enum BluetoothBondState {
-  BOND_STATE_NONE,
-  BOND_STATE_BONDING,
-  BOND_STATE_BONDED
-};
-
-enum BluetoothSetupServiceId {
-  SETUP_SERVICE_ID_SETUP,
-  SETUP_SERVICE_ID_CORE,
-  SETUP_SERVICE_ID_SOCKET,
-  SETUP_SERVICE_ID_HID,
-  SETUP_SERVICE_ID_PAN,
-  SETUP_SERVICE_ID_HANDSFREE,
-  SETUP_SERVICE_ID_A2DP,
-  SETUP_SERVICE_ID_HEALTH,
-  SETUP_SERVICE_ID_AVRCP,
-  SETUP_SERVICE_ID_GATT,
-  SETUP_SERVICE_ID_HANDSFREE_CLIENT,
-  SETUP_SERVICE_ID_MAP_CLIENT,
-  SETUP_SERVICE_ID_AVRCP_CONTROLLER,
-  SETUP_SERVICE_ID_A2DP_SINK
-};
-
-/* Physical transport for GATT connections to remote dual-mode devices */
-enum BluetoothTransport {
-  TRANSPORT_AUTO,   /* No preference of physical transport */
-  TRANSPORT_BREDR,  /* Prefer BR/EDR transport */
-  TRANSPORT_LE      /* Prefer LE transport */
-};
-
-enum BluetoothTypeOfDevice {
-  TYPE_OF_DEVICE_BREDR,
-  TYPE_OF_DEVICE_BLE,
-  TYPE_OF_DEVICE_DUAL
-};
-
-enum BluetoothPropertyType {
-  PROPERTY_UNKNOWN,
-  PROPERTY_BDNAME,
-  PROPERTY_BDADDR,
-  PROPERTY_UUIDS,
-  PROPERTY_CLASS_OF_DEVICE,
-  PROPERTY_TYPE_OF_DEVICE,
-  PROPERTY_SERVICE_RECORD,
-  PROPERTY_ADAPTER_SCAN_MODE,
-  PROPERTY_ADAPTER_BONDED_DEVICES,
-  PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
-  PROPERTY_REMOTE_FRIENDLY_NAME,
-  PROPERTY_REMOTE_RSSI,
-  PROPERTY_REMOTE_VERSION_INFO,
-  PROPERTY_REMOTE_DEVICE_TIMESTAMP
-};
-
-enum BluetoothScanMode {
-  SCAN_MODE_NONE,
-  SCAN_MODE_CONNECTABLE,
-  SCAN_MODE_CONNECTABLE_DISCOVERABLE
-};
-
-enum BluetoothSspVariant {
-  SSP_VARIANT_PASSKEY_CONFIRMATION,
-  SSP_VARIANT_PASSKEY_ENTRY,
-  SSP_VARIANT_CONSENT,
-  SSP_VARIANT_PASSKEY_NOTIFICATION,
-  NUM_SSP_VARIANT
-};
-
-struct BluetoothActivityEnergyInfo {
-  uint8_t mStatus;
-  uint8_t mStackState;  /* stack reported state */
-  uint64_t mTxTime;     /* in ms */
-  uint64_t mRxTime;     /* in ms */
-  uint64_t mIdleTime;   /* in ms */
-  uint64_t mEnergyUsed; /* a product of mA, V and ms */
-};
-
-/**
- * |BluetoothAddress| stores the 6-byte MAC address of a Bluetooth
- * device. The constants returned from ANY(), ALL() and LOCAL()
- * represent addresses with special meaning.
- */
-struct BluetoothAddress {
-  static const BluetoothAddress& ANY();
-  static const BluetoothAddress& ALL();
-  static const BluetoothAddress& LOCAL();
-
-  uint8_t mAddr[6];
-
-  BluetoothAddress()
-  {
-    Clear(); // assign ANY()
-  }
-
-  MOZ_IMPLICIT BluetoothAddress(const BluetoothAddress&) = default;
-
-  BluetoothAddress(uint8_t aAddr0, uint8_t aAddr1,
-                   uint8_t aAddr2, uint8_t aAddr3,
-                   uint8_t aAddr4, uint8_t aAddr5)
-  {
-    mAddr[0] = aAddr0;
-    mAddr[1] = aAddr1;
-    mAddr[2] = aAddr2;
-    mAddr[3] = aAddr3;
-    mAddr[4] = aAddr4;
-    mAddr[5] = aAddr5;
-  }
-
-  BluetoothAddress& operator=(const BluetoothAddress&) = default;
-
-  bool operator==(const BluetoothAddress& aRhs) const
-  {
-    return !memcmp(mAddr, aRhs.mAddr, sizeof(mAddr));
-  }
-
-  bool operator!=(const BluetoothAddress& aRhs) const
-  {
-    return !operator==(aRhs);
-  }
-
-  /**
-   * |Clear| assigns an invalid value (i.e., ANY()) to the address.
-   */
-  void Clear()
-  {
-    operator=(ANY());
-  }
-
-  /**
-   * |IsCleared| returns true if the address does not contain a
-   * specific value (i.e., it contains ANY()).
-   */
-  bool IsCleared() const
-  {
-    return operator==(ANY());
-  }
-
-  /*
-   * Getter and setter methods for the address parts. The figure
-   * below illustrates the mapping to bytes; from LSB to MSB.
-   *
-   *    |       LAP       | UAP |    NAP    |
-   *    |  0  |  1  |  2  |  3  |  4  |  5  |
-   *
-   * See Bluetooth Core Spec 2.1, Sec 1.2.
-   */
-
-  uint32_t GetLAP() const
-  {
-    return (static_cast<uint32_t>(mAddr[0])) |
-           (static_cast<uint32_t>(mAddr[1]) << 8) |
-           (static_cast<uint32_t>(mAddr[2]) << 16);
-  }
-
-  void SetLAP(uint32_t aLAP)
-  {
-    MOZ_ASSERT(!(aLAP & 0xff000000)); // no top-8 bytes in LAP
-
-    mAddr[0] = aLAP;
-    mAddr[1] = aLAP >> 8;
-    mAddr[2] = aLAP >> 16;
-  }
-
-  uint8_t GetUAP() const
-  {
-    return mAddr[3];
-  }
-
-  void SetUAP(uint8_t aUAP)
-  {
-    mAddr[3] = aUAP;
-  }
-
-  uint16_t GetNAP() const
-  {
-    return LittleEndian::readUint16(&mAddr[4]);
-  }
-
-  void SetNAP(uint16_t aNAP)
-  {
-    LittleEndian::writeUint16(&mAddr[4], aNAP);
-  }
-
-};
-
-struct BluetoothConfigurationParameter {
-  uint8_t mType;
-  uint16_t mLength;
-  mozilla::UniquePtr<uint8_t[]> mValue;
-};
-
-/*
- * Service classes and Profile Identifiers
- *
- * Supported Bluetooth services for v1 are listed as below.
- *
- * The value of each service class is defined in "AssignedNumbers/Service
- * Discovery Protocol (SDP)/Service classes and Profile Identifiers" in the
- * Bluetooth Core Specification.
- */
-enum BluetoothServiceClass {
-  UNKNOWN          = 0x0000,
-  OBJECT_PUSH      = 0x1105,
-  HEADSET          = 0x1108,
-  A2DP_SINK        = 0x110b,
-  AVRCP_TARGET     = 0x110c,
-  A2DP             = 0x110d,
-  AVRCP            = 0x110e,
-  AVRCP_CONTROLLER = 0x110f,
-  HEADSET_AG       = 0x1112,
-  HANDSFREE        = 0x111e,
-  HANDSFREE_AG     = 0x111f,
-  HID              = 0x1124,
-  PBAP_PCE         = 0x112e,
-  PBAP_PSE         = 0x112f,
-  MAP_MAS          = 0x1132,
-  MAP_MNS          = 0x1133
-};
-
-struct BluetoothUuid {
-  static const BluetoothUuid& ZERO();
-  static const BluetoothUuid& BASE();
-
-  uint8_t mUuid[16];  // store 128-bit UUID value in big-endian order
-
-  BluetoothUuid()
-    : BluetoothUuid(ZERO())
-  { }
-
-  MOZ_IMPLICIT BluetoothUuid(const BluetoothUuid&) = default;
-
-  BluetoothUuid(uint8_t aUuid0, uint8_t aUuid1,
-                uint8_t aUuid2, uint8_t aUuid3,
-                uint8_t aUuid4, uint8_t aUuid5,
-                uint8_t aUuid6, uint8_t aUuid7,
-                uint8_t aUuid8, uint8_t aUuid9,
-                uint8_t aUuid10, uint8_t aUuid11,
-                uint8_t aUuid12, uint8_t aUuid13,
-                uint8_t aUuid14, uint8_t aUuid15)
-  {
-    mUuid[0] = aUuid0;
-    mUuid[1] = aUuid1;
-    mUuid[2] = aUuid2;
-    mUuid[3] = aUuid3;
-    mUuid[4] = aUuid4;
-    mUuid[5] = aUuid5;
-    mUuid[6] = aUuid6;
-    mUuid[7] = aUuid7;
-    mUuid[8] = aUuid8;
-    mUuid[9] = aUuid9;
-    mUuid[10] = aUuid10;
-    mUuid[11] = aUuid11;
-    mUuid[12] = aUuid12;
-    mUuid[13] = aUuid13;
-    mUuid[14] = aUuid14;
-    mUuid[15] = aUuid15;
-  }
-
-  explicit BluetoothUuid(uint32_t aUuid32)
-  {
-    SetUuid32(aUuid32);
-  }
-
-  explicit BluetoothUuid(uint16_t aUuid16)
-  {
-    SetUuid16(aUuid16);
-  }
-
-  explicit BluetoothUuid(BluetoothServiceClass aServiceClass)
-  {
-    SetUuid16(static_cast<uint16_t>(aServiceClass));
-  }
-
-  BluetoothUuid& operator=(const BluetoothUuid& aRhs) = default;
-
-  /**
-   * |Clear| assigns an invalid value (i.e., zero) to the UUID.
-   */
-  void Clear()
-  {
-    operator=(ZERO());
-  }
-
-  /**
-   * |IsCleared| returns true if the UUID contains a value of
-   * zero.
-   */
-  bool IsCleared() const
-  {
-    return operator==(ZERO());
-  }
-
-  bool operator==(const BluetoothUuid& aRhs) const
-  {
-    return std::equal(aRhs.mUuid,
-                      aRhs.mUuid + MOZ_ARRAY_LENGTH(aRhs.mUuid), mUuid);
-  }
-
-  bool operator!=(const BluetoothUuid& aRhs) const
-  {
-    return !operator==(aRhs);
-  }
-
-  /* This less-than operator is used for sorted insertion of nsTArray */
-  bool operator<(const BluetoothUuid& aUuid) const
-  {
-    return memcmp(mUuid, aUuid.mUuid, sizeof(aUuid.mUuid)) < 0;
-  };
-
-  /*
-   * Getter-setter methods for short UUIDS. The first 4 bytes in the
-   * UUID are represented by the short notation UUID32, and bytes 3
-   * and 4 (indices 2 and 3) are represented by UUID16. The rest of
-   * the UUID is filled with the Bluetooth Base UUID.
-   *
-   * Below are helpers for accessing these values.
-   */
-
-  void SetUuid32(uint32_t aUuid32)
-  {
-    operator=(BASE());
-    BigEndian::writeUint32(&mUuid[0], aUuid32);
-  }
-
-  uint32_t GetUuid32() const
-  {
-    return BigEndian::readUint32(&mUuid[0]);
-  }
-
-  void SetUuid16(uint16_t aUuid16)
-  {
-    operator=(BASE());
-    BigEndian::writeUint16(&mUuid[2], aUuid16);
-  }
-
-  uint16_t GetUuid16() const
-  {
-    return BigEndian::readUint16(&mUuid[2]);
-  }
-};
-
-struct BluetoothPinCode {
-  uint8_t mPinCode[16]; /* not \0-terminated */
-  uint8_t mLength;
-
-  BluetoothPinCode()
-    : mLength(0)
-  {
-    std::fill(mPinCode, mPinCode + MOZ_ARRAY_LENGTH(mPinCode), 0);
-  }
-
-  bool operator==(const BluetoothPinCode& aRhs) const
-  {
-    MOZ_ASSERT(mLength <= MOZ_ARRAY_LENGTH(mPinCode));
-    return (mLength == aRhs.mLength) &&
-            std::equal(aRhs.mPinCode, aRhs.mPinCode + aRhs.mLength, mPinCode);
-  }
-
-  bool operator!=(const BluetoothPinCode& aRhs) const
-  {
-    return !operator==(aRhs);
-  }
-};
-
-struct BluetoothServiceName {
-  uint8_t mName[255]; /* not \0-terminated */
-};
-
-struct BluetoothServiceRecord {
-  BluetoothUuid mUuid;
-  uint16_t mChannel;
-  char mName[256];
-};
-
-struct BluetoothRemoteInfo {
-  int mVerMajor;
-  int mVerMinor;
-  int mManufacturer;
-};
-
-struct BluetoothRemoteName {
-  uint8_t mName[248]; /* not \0-terminated */
-  uint8_t mLength;
-
-  BluetoothRemoteName()
-    : mLength(0)
-  { }
-
-  explicit BluetoothRemoteName(const nsACString_internal& aString)
-    : mLength(0)
-  {
-    MOZ_ASSERT(aString.Length() <= MOZ_ARRAY_LENGTH(mName));
-    memcpy(mName, aString.Data(), aString.Length());
-    mLength = aString.Length();
-  }
-
-  BluetoothRemoteName(const BluetoothRemoteName&) = default;
-
-  BluetoothRemoteName& operator=(const BluetoothRemoteName&) = default;
-
-  bool operator==(const BluetoothRemoteName& aRhs) const
-  {
-    MOZ_ASSERT(mLength <= MOZ_ARRAY_LENGTH(mName));
-    return (mLength == aRhs.mLength) &&
-            std::equal(aRhs.mName, aRhs.mName + aRhs.mLength, mName);
-  }
-
-  bool operator!=(const BluetoothRemoteName& aRhs) const
-  {
-    return !operator==(aRhs);
-  }
-
-  void Assign(const uint8_t* aName, size_t aLength)
-  {
-    MOZ_ASSERT(aLength <= MOZ_ARRAY_LENGTH(mName));
-    memcpy(mName, aName, aLength);
-    mLength = aLength;
-  }
-
-  void Clear()
-  {
-    mLength = 0;
-  }
-
-  bool IsCleared() const
-  {
-    return !mLength;
-  }
-};
-
-struct BluetoothProperty {
-  /* Type */
-  BluetoothPropertyType mType;
-
-  /* Value
-   */
-
-  /* PROPERTY_BDADDR */
-  BluetoothAddress mBdAddress;
-
-  /* PROPERTY_BDNAME */
-  BluetoothRemoteName mRemoteName;
-
-  /* PROPERTY_REMOTE_FRIENDLY_NAME */
-  nsString mString;
-
-  /* PROPERTY_UUIDS */
-  nsTArray<BluetoothUuid> mUuidArray;
-
-  /* PROPERTY_ADAPTER_BONDED_DEVICES */
-  nsTArray<BluetoothAddress> mBdAddressArray;
-
-  /* PROPERTY_CLASS_OF_DEVICE
-     PROPERTY_ADAPTER_DISCOVERY_TIMEOUT */
-  uint32_t mUint32;
-
-  /* PROPERTY_RSSI_VALUE */
-  int32_t mInt32;
-
-  /* PROPERTY_TYPE_OF_DEVICE */
-  BluetoothTypeOfDevice mTypeOfDevice;
-
-  /* PROPERTY_SERVICE_RECORD */
-  BluetoothServiceRecord mServiceRecord;
-
-  /* PROPERTY_SCAN_MODE */
-  BluetoothScanMode mScanMode;
-
-  /* PROPERTY_REMOTE_VERSION_INFO */
-  BluetoothRemoteInfo mRemoteInfo;
-
-  BluetoothProperty()
-    : mType(PROPERTY_UNKNOWN)
-  { }
-
-  explicit BluetoothProperty(BluetoothPropertyType aType,
-                             const BluetoothAddress& aBdAddress)
-    : mType(aType)
-    , mBdAddress(aBdAddress)
-  { }
-
-  explicit BluetoothProperty(BluetoothPropertyType aType,
-                             const BluetoothRemoteName& aRemoteName)
-    : mType(aType)
-    , mRemoteName(aRemoteName)
-  { }
-
-  explicit BluetoothProperty(BluetoothPropertyType aType,
-                             const nsAString& aString)
-    : mType(aType)
-    , mString(aString)
-  { }
-
-  explicit BluetoothProperty(BluetoothPropertyType aType,
-                             const nsTArray<BluetoothUuid>& aUuidArray)
-    : mType(aType)
-    , mUuidArray(aUuidArray)
-  { }
-
-  explicit BluetoothProperty(BluetoothPropertyType aType,
-                             const nsTArray<BluetoothAddress>& aBdAddressArray)
-    : mType(aType)
-    , mBdAddressArray(aBdAddressArray)
-  { }
-
-  explicit BluetoothProperty(BluetoothPropertyType aType, uint32_t aUint32)
-    : mType(aType)
-    , mUint32(aUint32)
-  { }
-
-  explicit BluetoothProperty(BluetoothPropertyType aType, int32_t aInt32)
-    : mType(aType)
-    , mInt32(aInt32)
-  { }
-
-  explicit BluetoothProperty(BluetoothPropertyType aType,
-                             BluetoothTypeOfDevice aTypeOfDevice)
-    : mType(aType)
-    , mTypeOfDevice(aTypeOfDevice)
-  { }
-
-  explicit BluetoothProperty(BluetoothPropertyType aType,
-                             const BluetoothServiceRecord& aServiceRecord)
-    : mType(aType)
-    , mServiceRecord(aServiceRecord)
-  { }
-
-  explicit BluetoothProperty(BluetoothPropertyType aType,
-                             BluetoothScanMode aScanMode)
-    : mType(aType)
-    , mScanMode(aScanMode)
-  { }
-
-  explicit BluetoothProperty(BluetoothPropertyType aType,
-                             const BluetoothRemoteInfo& aRemoteInfo)
-    : mType(aType)
-    , mRemoteInfo(aRemoteInfo)
-  { }
-};
-
-enum BluetoothSocketType {
-  RFCOMM = 1,
-  SCO    = 2,
-  L2CAP  = 3,
-  EL2CAP = 4
-};
-
-struct BluetoothHidInfoParam {
-  uint16_t mAttributeMask;
-  uint8_t mSubclass;
-  uint8_t mApplicationId;
-  uint16_t mVendorId;
-  uint16_t mProductId;
-  uint16_t mVersion;
-  uint8_t mCountryCode;
-  uint16_t mDescriptorLength;
-  uint8_t mDescriptorValue[BLUETOOTH_HID_MAX_DESC_LEN];
-};
-
-struct BluetoothHidReport {
-  nsTArray<uint8_t> mReportData;
-};
-
-enum BluetoothHidProtocolMode {
-  HID_PROTOCOL_MODE_REPORT = 0x00,
-  HID_PROTOCOL_MODE_BOOT = 0x01,
-  HID_PROTOCOL_MODE_UNSUPPORTED = 0xff
-};
-
-enum BluetoothHidReportType {
-  HID_REPORT_TYPE_INPUT = 0x01,
-  HID_REPORT_TYPE_OUTPUT = 0x02,
-  HID_REPORT_TYPE_FEATURE = 0x03
-};
-
-enum BluetoothHidConnectionState {
-  HID_CONNECTION_STATE_CONNECTED,
-  HID_CONNECTION_STATE_CONNECTING,
-  HID_CONNECTION_STATE_DISCONNECTED,
-  HID_CONNECTION_STATE_DISCONNECTING,
-  HID_CONNECTION_STATE_FAILED_MOUSE_FROM_HOST,
-  HID_CONNECTION_STATE_FAILED_KEYBOARD_FROM_HOST,
-  HID_CONNECTION_STATE_FAILED_TOO_MANY_DEVICES,
-  HID_CONNECTION_STATE_FAILED_NO_HID_DRIVER,
-  HID_CONNECTION_STATE_FAILED_GENERIC,
-  HID_CONNECTION_STATE_UNKNOWN
-};
-
-enum BluetoothHidStatus {
-  HID_STATUS_OK,
-  HID_STATUS_HANDSHAKE_DEVICE_NOT_READY,
-  HID_STATUS_HANDSHAKE_INVALID_REPORT_ID,
-  HID_STATUS_HANDSHAKE_TRANSACTION_NOT_SPT,
-  HID_STATUS_HANDSHAKE_INVALID_PARAMETER,
-  HID_STATUS_HANDSHAKE_GENERIC_ERROR,
-  HID_STATUS_GENERAL_ERROR,
-  HID_STATUS_SDP_ERROR,
-  HID_STATUS_SET_PROTOCOL_ERROR,
-  HID_STATUS_DEVICE_DATABASE_FULL,
-  HID_STATUS_DEVICE_TYPE_NOT_SUPPORTED,
-  HID_STATUS_NO_RESOURCES,
-  HID_STATUS_AUTHENTICATION_FAILED,
-  HID_STATUS_HDL
-};
-
-enum BluetoothHandsfreeAtResponse {
-  HFP_AT_RESPONSE_ERROR,
-  HFP_AT_RESPONSE_OK
-};
-
-enum BluetoothHandsfreeAudioState {
-  HFP_AUDIO_STATE_DISCONNECTED,
-  HFP_AUDIO_STATE_CONNECTING,
-  HFP_AUDIO_STATE_CONNECTED,
-  HFP_AUDIO_STATE_DISCONNECTING,
-};
-
-enum BluetoothHandsfreeCallAddressType {
-  HFP_CALL_ADDRESS_TYPE_UNKNOWN,
-  HFP_CALL_ADDRESS_TYPE_INTERNATIONAL
-};
-
-enum BluetoothHandsfreeCallDirection {
-  HFP_CALL_DIRECTION_OUTGOING,
-  HFP_CALL_DIRECTION_INCOMING
-};
-
-enum BluetoothHandsfreeCallHoldType {
-  HFP_CALL_HOLD_RELEASEHELD,
-  HFP_CALL_HOLD_RELEASEACTIVE_ACCEPTHELD,
-  HFP_CALL_HOLD_HOLDACTIVE_ACCEPTHELD,
-  HFP_CALL_HOLD_ADDHELDTOCONF
-};
-
-enum BluetoothHandsfreeCallMode {
-  HFP_CALL_MODE_VOICE,
-  HFP_CALL_MODE_DATA,
-  HFP_CALL_MODE_FAX
-};
-
-enum BluetoothHandsfreeCallMptyType {
-  HFP_CALL_MPTY_TYPE_SINGLE,
-  HFP_CALL_MPTY_TYPE_MULTI
-};
-
-enum BluetoothHandsfreeCallState {
-  HFP_CALL_STATE_ACTIVE,
-  HFP_CALL_STATE_HELD,
-  HFP_CALL_STATE_DIALING,
-  HFP_CALL_STATE_ALERTING,
-  HFP_CALL_STATE_INCOMING,
-  HFP_CALL_STATE_WAITING,
-  HFP_CALL_STATE_IDLE
-};
-
-enum BluetoothHandsfreeConnectionState
-{
-  HFP_CONNECTION_STATE_DISCONNECTED,
-  HFP_CONNECTION_STATE_CONNECTING,
-  HFP_CONNECTION_STATE_CONNECTED,
-  HFP_CONNECTION_STATE_SLC_CONNECTED,
-  HFP_CONNECTION_STATE_DISCONNECTING
-};
-
-enum BluetoothHandsfreeNetworkState {
-  HFP_NETWORK_STATE_NOT_AVAILABLE,
-  HFP_NETWORK_STATE_AVAILABLE
-};
-
-enum BluetoothHandsfreeNRECState {
-  HFP_NREC_STOPPED,
-  HFP_NREC_STARTED
-};
-
-enum BluetoothHandsfreeServiceType {
-  HFP_SERVICE_TYPE_HOME,
-  HFP_SERVICE_TYPE_ROAMING
-};
-
-enum BluetoothHandsfreeVoiceRecognitionState {
-  HFP_VOICE_RECOGNITION_STOPPED,
-  HFP_VOICE_RECOGNITION_STARTED
-};
-
-enum BluetoothHandsfreeVolumeType {
-  HFP_VOLUME_TYPE_SPEAKER,
-  HFP_VOLUME_TYPE_MICROPHONE
-};
-
-enum BluetoothHandsfreeWbsConfig {
-  HFP_WBS_NONE, /* Neither CVSD nor mSBC codec, but other optional codec.*/
-  HFP_WBS_NO,   /* CVSD */
-  HFP_WBS_YES   /* mSBC */
-};
-
-class BluetoothSignal;
-
-class BluetoothSignalObserver : public mozilla::Observer<BluetoothSignal>
-{
-public:
-  BluetoothSignalObserver() : mSignalRegistered(false)
-  { }
-
-  void SetSignalRegistered(bool aSignalRegistered)
-  {
-    mSignalRegistered = aSignalRegistered;
-  }
-
-protected:
-  bool mSignalRegistered;
-};
-
-// Enums for object types, currently used for shared function lookups
-// (get/setproperty, etc...). Possibly discernable via dbus paths, but this
-// method is future-proofed for platform independence.
-enum BluetoothObjectType {
-  TYPE_MANAGER = 0,
-  TYPE_ADAPTER = 1,
-  TYPE_DEVICE = 2,
-  NUM_TYPE
-};
-
-enum BluetoothA2dpAudioState {
-  A2DP_AUDIO_STATE_REMOTE_SUSPEND,
-  A2DP_AUDIO_STATE_STOPPED,
-  A2DP_AUDIO_STATE_STARTED,
-};
-
-enum BluetoothA2dpConnectionState {
-  A2DP_CONNECTION_STATE_DISCONNECTED,
-  A2DP_CONNECTION_STATE_CONNECTING,
-  A2DP_CONNECTION_STATE_CONNECTED,
-  A2DP_CONNECTION_STATE_DISCONNECTING
-};
-
-enum ControlPlayStatus {
-  PLAYSTATUS_STOPPED  = 0x00,
-  PLAYSTATUS_PLAYING  = 0x01,
-  PLAYSTATUS_PAUSED   = 0x02,
-  PLAYSTATUS_FWD_SEEK = 0x03,
-  PLAYSTATUS_REV_SEEK = 0x04,
-  PLAYSTATUS_UNKNOWN,
-  PLAYSTATUS_ERROR    = 0xFF,
-};
-
-enum {
-  AVRCP_UID_SIZE = 8
-};
-
-enum BluetoothAvrcpMediaAttribute {
-  AVRCP_MEDIA_ATTRIBUTE_TITLE = 0x01,
-  AVRCP_MEDIA_ATTRIBUTE_ARTIST = 0x02,
-  AVRCP_MEDIA_ATTRIBUTE_ALBUM = 0x03,
-  AVRCP_MEDIA_ATTRIBUTE_TRACK_NUM = 0x04,
-  AVRCP_MEDIA_ATTRIBUTE_NUM_TRACKS = 0x05,
-  AVRCP_MEDIA_ATTRIBUTE_GENRE = 0x06,
-  AVRCP_MEDIA_ATTRIBUTE_PLAYING_TIME = 0x07
-};
-
-enum BluetoothAvrcpPlayerAttribute {
-  AVRCP_PLAYER_ATTRIBUTE_EQUALIZER,
-  AVRCP_PLAYER_ATTRIBUTE_REPEAT,
-  AVRCP_PLAYER_ATTRIBUTE_SHUFFLE,
-  AVRCP_PLAYER_ATTRIBUTE_SCAN
-};
-
-enum BluetoothAvrcpPlayerRepeatValue {
-  AVRCP_PLAYER_VAL_OFF_REPEAT = 0x01,
-  AVRCP_PLAYER_VAL_SINGLE_REPEAT = 0x02,
-  AVRCP_PLAYER_VAL_ALL_REPEAT = 0x03,
-  AVRCP_PLAYER_VAL_GROUP_REPEAT = 0x04
-};
-
-enum BluetoothAvrcpPlayerShuffleValue {
-  AVRCP_PLAYER_VAL_OFF_SHUFFLE = 0x01,
-  AVRCP_PLAYER_VAL_ALL_SHUFFLE = 0x02,
-  AVRCP_PLAYER_VAL_GROUP_SHUFFLE = 0x03
-};
-
-enum BluetoothAvrcpStatus {
-  AVRCP_STATUS_BAD_COMMAND,
-  AVRCP_STATUS_BAD_PARAMETER,
-  AVRCP_STATUS_NOT_FOUND,
-  AVRCP_STATUS_INTERNAL_ERROR,
-  AVRCP_STATUS_SUCCESS
-};
-
-enum BluetoothAvrcpEvent {
-  AVRCP_EVENT_PLAY_STATUS_CHANGED,
-  AVRCP_EVENT_TRACK_CHANGE,
-  AVRCP_EVENT_TRACK_REACHED_END,
-  AVRCP_EVENT_TRACK_REACHED_START,
-  AVRCP_EVENT_PLAY_POS_CHANGED,
-  AVRCP_EVENT_APP_SETTINGS_CHANGED
-};
-
-enum BluetoothAvrcpNotification {
-  AVRCP_NTF_INTERIM,
-  AVRCP_NTF_CHANGED
-};
-
-enum BluetoothAvrcpRemoteFeatureBits {
-  AVRCP_REMOTE_FEATURE_NONE,
-  AVRCP_REMOTE_FEATURE_METADATA = 0x01,
-  AVRCP_REMOTE_FEATURE_ABSOLUTE_VOLUME = 0x02,
-  AVRCP_REMOTE_FEATURE_BROWSE = 0x04
-};
-
-struct BluetoothAvrcpElementAttribute {
-  uint32_t mId;
-  nsString mValue;
-};
-
-struct BluetoothAvrcpNotificationParam {
-  ControlPlayStatus mPlayStatus;
-  uint8_t mTrack[8];
-  uint32_t mSongPos;
-  uint8_t mNumAttr;
-  uint8_t mIds[256];
-  uint8_t mValues[256];
-};
-
-struct BluetoothAvrcpPlayerSettings {
-  uint8_t mNumAttr;
-  uint8_t mIds[256];
-  uint8_t mValues[256];
-};
-
-enum BluetoothAttRole {
-  ATT_SERVER_ROLE,
-  ATT_CLIENT_ROLE
-};
-
-enum BluetoothGattStatus {
-  GATT_STATUS_SUCCESS,
-  GATT_STATUS_INVALID_HANDLE,
-  GATT_STATUS_READ_NOT_PERMITTED,
-  GATT_STATUS_WRITE_NOT_PERMITTED,
-  GATT_STATUS_INVALID_PDU,
-  GATT_STATUS_INSUFFICIENT_AUTHENTICATION,
-  GATT_STATUS_REQUEST_NOT_SUPPORTED,
-  GATT_STATUS_INVALID_OFFSET,
-  GATT_STATUS_INSUFFICIENT_AUTHORIZATION,
-  GATT_STATUS_PREPARE_QUEUE_FULL,
-  GATT_STATUS_ATTRIBUTE_NOT_FOUND,
-  GATT_STATUS_ATTRIBUTE_NOT_LONG,
-  GATT_STATUS_INSUFFICIENT_ENCRYPTION_KEY_SIZE,
-  GATT_STATUS_INVALID_ATTRIBUTE_LENGTH,
-  GATT_STATUS_UNLIKELY_ERROR,
-  GATT_STATUS_INSUFFICIENT_ENCRYPTION,
-  GATT_STATUS_UNSUPPORTED_GROUP_TYPE,
-  GATT_STATUS_INSUFFICIENT_RESOURCES,
-  GATT_STATUS_UNKNOWN_ERROR,
-  GATT_STATUS_BEGIN_OF_APPLICATION_ERROR = 0x80,
-  GATT_STATUS_END_OF_APPLICATION_ERROR = 0x9f,
-  GATT_STATUS_END_OF_ERROR = 0x100
-};
-
-enum BluetoothGattAuthReq {
-  GATT_AUTH_REQ_NONE,
-  GATT_AUTH_REQ_NO_MITM,
-  GATT_AUTH_REQ_MITM,
-  GATT_AUTH_REQ_SIGNED_NO_MITM,
-  GATT_AUTH_REQ_SIGNED_MITM,
-  GATT_AUTH_REQ_END_GUARD
-};
-
-enum BluetoothGattWriteType {
-  GATT_WRITE_TYPE_NO_RESPONSE,
-  GATT_WRITE_TYPE_NORMAL,
-  GATT_WRITE_TYPE_PREPARE,
-  GATT_WRITE_TYPE_SIGNED,
-  GATT_WRITE_TYPE_END_GUARD
-};
-
-/*
- * Bluetooth GATT Characteristic Properties bit field
- */
-enum BluetoothGattCharPropBit {
-  GATT_CHAR_PROP_BIT_BROADCAST            = (1 << 0),
-  GATT_CHAR_PROP_BIT_READ                 = (1 << 1),
-  GATT_CHAR_PROP_BIT_WRITE_NO_RESPONSE    = (1 << 2),
-  GATT_CHAR_PROP_BIT_WRITE                = (1 << 3),
-  GATT_CHAR_PROP_BIT_NOTIFY               = (1 << 4),
-  GATT_CHAR_PROP_BIT_INDICATE             = (1 << 5),
-  GATT_CHAR_PROP_BIT_SIGNED_WRITE         = (1 << 6),
-  GATT_CHAR_PROP_BIT_EXTENDED_PROPERTIES  = (1 << 7)
-};
-
-/*
- * BluetoothGattCharProp is used to store a bit mask value which contains
- * each corresponding bit value of each BluetoothGattCharPropBit.
- */
-typedef uint8_t BluetoothGattCharProp;
-#define BLUETOOTH_EMPTY_GATT_CHAR_PROP  static_cast<BluetoothGattCharProp>(0x00)
-
-/*
- * Bluetooth GATT Attribute Permissions bit field
- */
-enum BluetoothGattAttrPermBit {
-  GATT_ATTR_PERM_BIT_READ                 = (1 << 0),
-  GATT_ATTR_PERM_BIT_READ_ENCRYPTED       = (1 << 1),
-  GATT_ATTR_PERM_BIT_READ_ENCRYPTED_MITM  = (1 << 2),
-  GATT_ATTR_PERM_BIT_WRITE                = (1 << 4),
-  GATT_ATTR_PERM_BIT_WRITE_ENCRYPTED      = (1 << 5),
-  GATT_ATTR_PERM_BIT_WRITE_ENCRYPTED_MITM = (1 << 6),
-  GATT_ATTR_PERM_BIT_WRITE_SIGNED         = (1 << 7),
-  GATT_ATTR_PERM_BIT_WRITE_SIGNED_MITM    = (1 << 8)
-};
-
-/*
- * BluetoothGattAttrPerm is used to store a bit mask value which contains
- * each corresponding bit value of each BluetoothGattAttrPermBit.
- */
-typedef int32_t BluetoothGattAttrPerm;
-#define BLUETOOTH_EMPTY_GATT_ATTR_PERM  static_cast<BluetoothGattAttrPerm>(0x00)
-
-struct BluetoothGattAdvData {
-  uint8_t mAdvData[62];
-};
-
-struct BluetoothGattId {
-  BluetoothUuid mUuid;
-  uint8_t mInstanceId;
-
-  bool operator==(const BluetoothGattId& aOther) const
-  {
-    return mUuid == aOther.mUuid && mInstanceId == aOther.mInstanceId;
-  }
-};
-
-struct BluetoothGattServiceId {
-  BluetoothGattId mId;
-  uint8_t mIsPrimary;
-
-  bool operator==(const BluetoothGattServiceId& aOther) const
-  {
-    return mId == aOther.mId && mIsPrimary == aOther.mIsPrimary;
-  }
-};
-
-struct BluetoothGattCharAttribute {
-  BluetoothGattId mId;
-  BluetoothGattCharProp mProperties;
-  BluetoothGattWriteType mWriteType;
-
-  bool operator==(const BluetoothGattCharAttribute& aOther) const
-  {
-    return mId == aOther.mId &&
-           mProperties == aOther.mProperties &&
-           mWriteType == aOther.mWriteType;
-  }
-};
-
-struct BluetoothGattReadParam {
-  BluetoothGattServiceId mServiceId;
-  BluetoothGattId mCharId;
-  BluetoothGattId mDescriptorId;
-  uint16_t mValueType;
-  uint16_t mValueLength;
-  uint8_t mValue[BLUETOOTH_GATT_MAX_ATTR_LEN];
-  uint8_t mStatus;
-};
-
-struct BluetoothGattWriteParam {
-  BluetoothGattServiceId mServiceId;
-  BluetoothGattId mCharId;
-  BluetoothGattId mDescriptorId;
-  uint8_t mStatus;
-};
-
-struct BluetoothGattNotifyParam {
-  BluetoothAddress mBdAddr;
-  BluetoothGattServiceId mServiceId;
-  BluetoothGattId mCharId;
-  uint16_t mLength;
-  uint8_t mValue[BLUETOOTH_GATT_MAX_ATTR_LEN];
-  bool mIsNotify;
-};
-
-struct BluetoothGattTestParam {
-  BluetoothAddress mBdAddr;
-  BluetoothUuid mUuid;
-  uint16_t mU1;
-  uint16_t mU2;
-  uint16_t mU3;
-  uint16_t mU4;
-  uint16_t mU5;
-};
-
-struct BluetoothAttributeHandle {
-  uint16_t mHandle;
-
-  BluetoothAttributeHandle()
-    : mHandle(0x0000)
-  { }
-
-  bool operator==(const BluetoothAttributeHandle& aOther) const
-  {
-    return mHandle == aOther.mHandle;
-  }
-};
-
-struct BluetoothGattResponse {
-  BluetoothAttributeHandle mHandle;
-  uint16_t mOffset;
-  uint16_t mLength;
-  BluetoothGattAuthReq mAuthReq;
-  uint8_t mValue[BLUETOOTH_GATT_MAX_ATTR_LEN];
-
-  bool operator==(const BluetoothGattResponse& aOther) const
-  {
-    return mHandle == aOther.mHandle &&
-           mOffset == aOther.mOffset &&
-           mLength == aOther.mLength &&
-           mAuthReq == aOther.mAuthReq &&
-           !memcmp(mValue, aOther.mValue, mLength);
-  }
-};
-
-/**
- * EIR Data Type, Advertising Data Type (AD Type) and OOB Data Type Definitions
- * Please refer to https://www.bluetooth.org/en-us/specification/\
- * assigned-numbers/generic-access-profile
- */
-enum BluetoothGapDataType {
-  GAP_INCOMPLETE_UUID16  = 0X02, // Incomplete List of 16-bit Service Class UUIDs
-  GAP_COMPLETE_UUID16    = 0X03, // Complete List of 16-bit Service Class UUIDs
-  GAP_INCOMPLETE_UUID32  = 0X04, // Incomplete List of 32-bit Service Class UUIDs
-  GAP_COMPLETE_UUID32    = 0X05, // Complete List of 32-bit Service Class UUIDs
-  GAP_INCOMPLETE_UUID128 = 0X06, // Incomplete List of 128-bit Service Class UUIDs
-  GAP_COMPLETE_UUID128   = 0X07, // Complete List of 128-bit Service Class UUIDs
-  GAP_SHORTENED_NAME     = 0X08, // Shortened Local Name
-  GAP_COMPLETE_NAME      = 0X09, // Complete Local Name
-};
-
-struct BluetoothGattAdvertisingData {
-  /**
-   * Uuid value of Appearance characteristic of the GAP service which can be
-   * mapped to an icon or string that describes the physical representation of
-   * the device during the device discovery procedure.
-   */
-  uint16_t mAppearance;
-
-  /**
-   * Whether to broadcast with device name or not.
-   */
-  bool mIncludeDevName;
-
-  /**
-   * Whether to broadcast with TX power or not.
-   */
-  bool mIncludeTxPower;
-
-  /**
-   * Byte array of custom manufacturer specific data.
-   *
-   * The first 2 octets contain the Company Identifier Code followed by
-   * additional manufacturer specific data. See Core Specification Supplement
-   * (CSS) v6 1.4 for more details.
-   */
-  nsTArray<uint8_t> mManufacturerData;
-
-  /**
-   * Consists of a service UUID with the data associated with that service.
-   * Please see Core Specification Supplement (CSS) v6 1.11 for more details.
-   */
-  nsTArray<uint8_t> mServiceData;
-
-  /**
-   * A list of Service or Service Class UUIDs.
-   * Please see Core Specification Supplement (CSS) v6 1.1 for more details.
-   */
-  nsTArray<BluetoothUuid> mServiceUuids;
-
-  BluetoothGattAdvertisingData()
-    : mAppearance(0)
-    , mIncludeDevName(false)
-    , mIncludeTxPower(false)
-  { }
-
-  bool operator==(const BluetoothGattAdvertisingData& aOther) const
-  {
-    return mIncludeDevName == aOther.mIncludeDevName &&
-           mIncludeTxPower == aOther.mIncludeTxPower &&
-           mAppearance == aOther.mAppearance &&
-           mManufacturerData == aOther.mManufacturerData &&
-           mServiceData == aOther.mServiceData &&
-           mServiceUuids == aOther.mServiceUuids;
-  }
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothCommon_h
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothGattReplyRunnable.cpp
+++ /dev/null
@@ -1,117 +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 "BluetoothGattReplyRunnable.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/dom/Promise.h"
-
-using namespace mozilla::dom;
-
-USING_BLUETOOTH_NAMESPACE
-
-BluetoothGattReplyRunnable::BluetoothGattReplyRunnable(Promise* aPromise)
-  : BluetoothReplyRunnable(nullptr, aPromise)
-{
-  MOZ_ASSERT(aPromise);
-}
-
-void
-BluetoothGattReplyRunnable::GattStatusToDOMStatus(
-  const BluetoothGattStatus aGattStatus, nsresult& aDOMStatus)
-{
-  /**
-   * https://webbluetoothcg.github.io/web-bluetooth/#error-handling
-   *
-   * ToDo:
-   * If the procedure times out or the ATT Bearer is terminated for any
-   * reason, return |NS_ERROR_DOM_NETWORK_ERR|.
-   */
-
-  // Error Code Mapping
-  if ((aGattStatus >= GATT_STATUS_BEGIN_OF_APPLICATION_ERROR) &&
-      (aGattStatus <= GATT_STATUS_END_OF_APPLICATION_ERROR) &&
-      IsWrite()) {
-    aDOMStatus = NS_ERROR_DOM_INVALID_MODIFICATION_ERR;
-    return;
-  }
-
-  switch (aGattStatus) {
-    case GATT_STATUS_INVALID_ATTRIBUTE_LENGTH:
-      aDOMStatus = NS_ERROR_DOM_INVALID_MODIFICATION_ERR;
-      break;
-    case GATT_STATUS_ATTRIBUTE_NOT_LONG:
-      /**
-       * ToDo:
-       * While receiving |GATT_STATUS_ATTRIBUTE_NOT_LONG|, we need to check
-       * whether 'Long' sub-procedure has been used or not.
-       * If we have used 'Long' sub-procedure, we need to retry the step
-       * without using 'Long' sub-procedure (e.g. Read Blob Request) based on
-       * W3C reuqirements. If it fails again due to the length of the value
-       * being written, convert the error status to
-       * |NS_ERROR_DOM_INVALID_MODIFICATION_ERR|.
-       * If 'Long' sub-procedure has not been used, convert the error status to
-       * |NS_ERROR_DOM_NOT_SUPPORTED_ERR|.
-       */
-      aDOMStatus = NS_ERROR_DOM_INVALID_MODIFICATION_ERR;
-      break;
-    case GATT_STATUS_INSUFFICIENT_AUTHENTICATION:
-    case GATT_STATUS_INSUFFICIENT_ENCRYPTION:
-    case GATT_STATUS_INSUFFICIENT_ENCRYPTION_KEY_SIZE:
-      /**
-       * ToDo:
-       * In W3C requirement, UA SHOULD attempt to increase the security level
-       * of the connection while receiving those error statuses. If it fails or
-       * UA doesn't suuport return the |NS_ERROR_DOM_SECURITY_ERR|.
-       *
-       * Note: The Gecko have already attempted to increase the security level
-       * after receiving |GATT_STATUS_INSUFFICIENT_AUTHENTICATION| or
-       * |GATT_STATUS_INSUFFICIENT_ENCRYPTION|. Only need to handle
-       * |GATT_STATUS_INSUFFICIENT_ENCRYPTION_KEY_SIZE| in the future.
-       */
-      aDOMStatus = NS_ERROR_DOM_SECURITY_ERR;
-      break;
-    case GATT_STATUS_INSUFFICIENT_AUTHORIZATION:
-      aDOMStatus = NS_ERROR_DOM_SECURITY_ERR;
-      break;
-    case GATT_STATUS_INVALID_HANDLE:
-    case GATT_STATUS_INVALID_PDU:
-    case GATT_STATUS_INVALID_OFFSET:
-    case GATT_STATUS_ATTRIBUTE_NOT_FOUND:
-    case GATT_STATUS_UNSUPPORTED_GROUP_TYPE:
-    case GATT_STATUS_READ_NOT_PERMITTED:
-    case GATT_STATUS_WRITE_NOT_PERMITTED:
-    case GATT_STATUS_REQUEST_NOT_SUPPORTED:
-    case GATT_STATUS_PREPARE_QUEUE_FULL:
-    case GATT_STATUS_INSUFFICIENT_RESOURCES:
-    case GATT_STATUS_UNLIKELY_ERROR:
-    default:
-      aDOMStatus = NS_ERROR_DOM_NOT_SUPPORTED_ERR;
-      break;
-  }
-}
-
-nsresult
-BluetoothGattReplyRunnable::FireErrorString()
-{
-  MOZ_ASSERT(mReply);
-
-  if (!mPromise ||
-      mReply->type() != BluetoothReply::TBluetoothReplyError ||
-      mReply->get_BluetoothReplyError().errorStatus().type() !=
-        BluetoothErrorStatus::TBluetoothGattStatus) {
-    return BluetoothReplyRunnable::FireErrorString();
-  }
-
-  nsresult domStatus = NS_OK;
-
-  GattStatusToDOMStatus(
-    mReply->get_BluetoothReplyError().errorStatus().get_BluetoothGattStatus(),
-    domStatus);
-  nsresult rv = NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM, domStatus);
-  mPromise->MaybeReject(rv);
-
-  return NS_OK;
-}
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothGattReplyRunnable.h
+++ /dev/null
@@ -1,62 +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_BluetoothGattReplyRunnable_h
-#define mozilla_dom_bluetooth_BluetoothGattReplyRunnable_h
-
-#include "BluetoothReplyRunnable.h"
-
-class nsIDOMDOMRequest;
-
-namespace mozilla {
-namespace dom {
-class Promise;
-}
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothReply;
-
-class BluetoothGattReplyRunnable : public BluetoothReplyRunnable
-{
-public:
-  BluetoothGattReplyRunnable(Promise* aPromise);
-
-protected:
-  virtual ~BluetoothGattReplyRunnable() {}
-
-private:
-  virtual nsresult FireErrorString() override;
-
-  void GattStatusToDOMStatus(const BluetoothGattStatus aGattStatus,
-                             nsresult& aDOMStatus);
-
-  virtual bool IsWrite()
-  {
-    return false;
-  }
-};
-
-class BluetoothGattVoidReplyRunnable : public BluetoothGattReplyRunnable
-{
-public:
-  BluetoothGattVoidReplyRunnable(Promise* aPromise)
-    : BluetoothGattReplyRunnable(aPromise) {}
-  ~BluetoothGattVoidReplyRunnable() {}
-
-protected:
-  virtual bool
-  ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue) override
-  {
-    aValue.setUndefined();
-    return true;
-  }
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothGattReplyRunnable_h
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothGattUUIDName.h
+++ /dev/null
@@ -1,273 +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_BluetoothGattUUIDName_h
-#define mozilla_dom_BluetoothGattUUIDName_h
-
-namespace mozilla {
-namespace dom {
-
-struct BluetoothGattUUIDName
-{
-  const char* name;
-  uint16_t uuid;
-};
-
-static BluetoothGattUUIDName ServiceTable[] = {
-  /**
-   * https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx
-   */
-  {"alert_notification", 0x1811},
-  {"automation_io", 0x1815},
-  {"battery_service", 0x180F},
-  {"blood_pressure", 0x1810},
-  {"body_composition", 0x181B},
-  {"bond_management", 0x181E},
-  {"continuous_glucose_monitoring", 0x181F},
-  {"current_time", 0x1805},
-  {"cycling_power", 0x1818},
-  {"cycling_speed_and_cadence", 0x1816},
-  {"device_information", 0x180A},
-  {"environmental_sensing", 0x181A},
-  {"generic_access", 0x1800},
-  {"generic_attribute", 0x1801},
-  {"glucose", 0x1808},
-  {"health_thermometer", 0x1809},
-  {"heart_rate", 0x180D},
-  {"http_proxy", 0x1823},
-  {"human_interface_device", 0x1812},
-  {"immediate_alert", 0x1802},
-  {"indoor_positioning", 0x1821},
-  {"internet_protocol_support", 0x1820},
-  {"link_loss", 0x1803},
-  {"location_and_navigation", 0x1819},
-  {"next_dst_change", 0x1807},
-  {"object_transfer", 0x1825},
-  {"phone_alert_status", 0x180E},
-  {"pulse_oximeter", 0x1822},
-  {"reference_time_update", 0x1806},
-  {"running_speed_and_cadence", 0x1814},
-  {"scan_parameters", 0x1813},
-  {"transport_discovery", 0x1824},
-  {"tx_power", 0x1804},
-  {"user_data", 0x181C},
-  {"weight_scale", 0x181D},
-};
-
-static BluetoothGattUUIDName CharacteristicTable[] = {
-  /**
-   * https://developer.bluetooth.org/gatt/characteristics/Pages/\
-   * CharacteristicsHome.aspx
-   */
-  {"aerobic_heart_rate_lower_limit", 0x2A7E},
-  {"aerobic_heart_rate_upper_limit", 0x2A84},
-  {"aerobic_threshold", 0x2A7F},
-  {"age", 0x2A80},
-  {"aggregate", 0x2A5A},
-  {"alert_category_id", 0x2A43},
-  {"alert_category_id_bit_mask", 0x2A42},
-  {"alert_level", 0x2A06},
-  {"alert_notification_control_point", 0x2A44},
-  {"alert_status", 0x2A3F},
-  {"altitude", 0x2AB3},
-  {"anaerobic_heart_rate_lower_limit", 0x2A81},
-  {"anaerobic_heart_rate_upper_limit", 0x2A82},
-  {"anaerobic_threshold", 0x2A83},
-  {"analog", 0x2A58},
-  {"apparent_wind_direction", 0x2A73},
-  {"apparent_wind_speed", 0x2A72},
-  {"gap.appearance", 0x2A01},
-  {"barometric_pressure_trend", 0x2AA3},
-  {"battery_level", 0x2A19},
-  {"blood_pressure_feature", 0x2A49},
-  {"blood_pressure_measurement", 0x2A35},
-  {"body_composition_feature", 0x2A9B},
-  {"body_composition_measurement", 0x2A9C},
-  {"body_sensor_location", 0x2A38},
-  {"bond_management_control_point", 0x2AA4},
-  {"bond_management_feature", 0x2AA5},
-  {"boot_keyboard_input_report", 0x2A22},
-  {"boot_keyboard_output_report", 0x2A32},
-  {"boot_mouse_input_report", 0x2A33},
-  {"gap.central_address_resolution_support", 0x2AA6},
-  {"cgm_feature", 0x2AA8},
-  {"cgm_measurement", 0x2AA7},
-  {"cgm_session_run_time", 0x2AAB},
-  {"cgm_session_start_time", 0x2AAA},
-  {"cgm_specific_ops_control_point", 0x2AAC},
-  {"cgm_status", 0x2AA9},
-  {"csc_feature", 0x2A5C},
-  {"csc_measurement", 0x2A5B},
-  {"current_time", 0x2A2B},
-  {"cycling_power_control_point", 0x2A66},
-  {"cycling_power_feature", 0x2A65},
-  {"cycling_power_measurement", 0x2A63},
-  {"cycling_power_vector", 0x2A64},
-  {"database_change_increment", 0x2A99},
-  {"date_of_birth", 0x2A85},
-  {"date_of_threshold_assessment", 0x2A86},
-  {"date_time", 0x2A08},
-  {"day_date_time", 0x2A0A},
-  {"day_of_week", 0x2A09},
-  {"descriptor_value_changed", 0x2A7D},
-  {"gap.device_name", 0x2A00},
-  {"dew_point", 0x2A7B},
-  {"digital", 0x2A56},
-  {"dst_offset", 0x2A0D},
-  {"elevation", 0x2A6C},
-  {"email_address", 0x2A87},
-  {"exact_time_256", 0x2A0C},
-  {"fat_burn_heart_rate_lower_limit", 0x2A88},
-  {"fat_burn_heart_rate_upper_limit", 0x2A89},
-  {"firmware_revision_string", 0x2A26},
-  {"first_name", 0x2A8A},
-  {"five_zone_heart_rate_limits", 0x2A8B},
-  {"floor_number", 0x2AB2},
-  {"gender", 0x2A8C},
-  {"glucose_feature", 0x2A51},
-  {"glucose_measurement", 0x2A18},
-  {"glucose_measurement_context", 0x2A34},
-  {"gust_factor", 0x2A74},
-  {"hardware_revision_string", 0x2A27},
-  {"heart_rate_control_point", 0x2A39},
-  {"heart_rate_max", 0x2A8D},
-  {"heart_rate_measurement", 0x2A37},
-  {"heat_index", 0x2A7A},
-  {"height", 0x2A8E},
-  {"hid_control_point", 0x2A4C},
-  {"hid_information", 0x2A4A},
-  {"hip_circumference", 0x2A8F},
-  {"http_control_point", 0x2ABA},
-  {"http_entity_body", 0x2AB9},
-  {"http_headers", 0x2AB7},
-  {"http_status_code", 0x2AB8},
-  {"http_security", 0x2ABB},
-  {"humidity", 0x2A6F},
-  {"ieee_11073-20601_regulatory_certification_data_list",
-     0x2A2A},
-  {"indoor_positioning_configuration", 0x2AAD},
-  {"intermediate_blood_pressure", 0x2A36},
-  {"intermediate_temperature", 0x2A1E},
-  {"irradiance", 0x2A77},
-  {"language", 0x2AA2},
-  {"last_name", 0x2A90},
-  {"latitude", 0x2AAE},
-  {"ln_control_point", 0x2A6B},
-  {"ln_feature", 0x2A6A},
-  {"local_east_coordinate.xml", 0x2AB1},
-  {"local_north_coordinate", 0x2AB0},
-  {"local_time_information", 0x2A0F},
-  {"location_and_speed", 0x2A67},
-  {"location_name", 0x2AB5},
-  {"longitude", 0x2AAF},
-  {"magnetic_declination", 0x2A2C},
-  {"magnetic_flux_density_2D", 0x2AA0},
-  {"magnetic_flux_density_3D", 0x2AA1},
-  {"manufacturer_name_string", 0x2A29},
-  {"maximum_recommended_heart_rate", 0x2A91},
-  {"measurement_interval", 0x2A21},
-  {"model_number_string", 0x2A24},
-  {"navigation", 0x2A68},
-  {"new_alert", 0x2A46},
-  {"object_action_control_point", 0x2AC5},
-  {"object_changed", 0x2AC8},
-  {"object_first_created", 0x2AC1},
-  {"object_id", 0x2AC3},
-  {"object_last_modified", 0x2AC2},
-  {"object_list_control_point", 0x2AC6},
-  {"object_list_filter", 0x2AC7},
-  {"object_name", 0x2ABE},
-  {"object_properties", 0x2AC4},
-  {"object_size", 0x2AC0},
-  {"object_type", 0x2ABF},
-  {"object_ots_feature", 0x2ABD},
-  {"gap.peripheral_preferred_connection_parameters",
-     0x2A04},
-  {"gap.peripheral_privacy_flag", 0x2A02},
-  {"plx_continuous_measurement", 0x2A5F},
-  {"plx_features", 0x2A60},
-  {"plx_spot_check_measurement", 0x2A5E},
-  {"pnp_id", 0x2A50},
-  {"pollen_concentration", 0x2A75},
-  {"position_quality", 0x2A69},
-  {"pressure", 0x2A6D},
-  {"protocol_mode", 0x2A4E},
-  {"rainfall", 0x2A78},
-  {"gap.reconnection_address", 0x2A03},
-  {"record_access_control_point", 0x2A52},
-  {"reference_time_information", 0x2A14},
-  {"report", 0x2A4D},
-  {"report_map", 0x2A4B},
-  {"resting_heart_rate", 0x2A92},
-  {"ringer_control_point", 0x2A40},
-  {"ringer_setting", 0x2A41},
-  {"rsc_feature", 0x2A54},
-  {"rsc_measurement", 0x2A53},
-  {"sc_control_point", 0x2A55},
-  {"scan_interval_window", 0x2A4F},
-  {"scan_refresh", 0x2A31},
-  {"sensor_location", 0x2A5D},
-  {"serial_number_string", 0x2A25},
-  {"gatt.service_changed", 0x2A05},
-  {"software_revision_string", 0x2A28},
-  {"sport_type_for_aerobic_and_anaerobic_thresholds",
-     0x2A93},
-  {"supported_new_alert_category", 0x2A47},
-  {"supported_unread_alert_category", 0x2A48},
-  {"system_id", 0x2A23},
-  {"temperature", 0x2A6E},
-  {"temperature_measurement", 0x2A1C},
-  {"temperature_type", 0x2A1D},
-  {"three_zone_heart_rate_limits", 0x2A94},
-  {"time_accuracy", 0x2A12},
-  {"time_source", 0x2A13},
-  {"time_update_control_point", 0x2A16},
-  {"time_update_state", 0x2A17},
-  {"time_with_dst", 0x2A11},
-  {"time_zone", 0x2A0E},
-  {"true_wind_direction", 0x2A71},
-  {"true_wind_speed", 0x2A70},
-  {"two_zone_heart_rate_limit", 0x2A95},
-  {"tx_power_level", 0x2A07},
-  {"uncertainty", 0x2AB4},
-  {"unread_alert_status", 0x2A45},
-  {"uri", 0x2AB6},
-  {"user_control_point", 0x2A9F},
-  {"user_index", 0x2A9A},
-  {"uv_index", 0x2A76},
-  {"vo2_max", 0x2A96},
-  {"waist_circumference", 0x2A97},
-  {"weight", 0x2A98},
-  {"weight_measurement", 0x2A9D},
-  {"weight_scale_feature", 0x2A9E},
-  {"wind_chill", 0x2A79},
-};
-
-static BluetoothGattUUIDName DescriptorTable[] = {
-  /**
-   * https://developer.bluetooth.org/gatt/descriptors/Pages\
-   * /DescriptorsHomePage.aspx
-   */
-  {"gatt.characteristic_extended_properties", 0x2900},
-  {"gatt.characteristic_user_description", 0x2901},
-  {"gatt.client_characteristic_configuration", 0x2902},
-  {"gatt.server_characteristic_configuration", 0x2903},
-  {"gatt.characteristic_presentation_format", 0x2904},
-  {"gatt.characteristic_aggregate_format", 0x2905},
-  {"valid_range", 0x2906},
-  {"external_report_reference", 0x2907},
-  {"report_reference", 0x2908},
-  {"number_of_digitals", 0x2909},
-  {"value_trigger_setting", 0x290A},
-  {"es_configuration", 0x290B},
-  {"es_measurement", 0x290C},
-  {"es_trigger_setting", 0x290D},
-  {"time_trigger_setting", 0x290E},
-};
-
-}// dom
-}// mozilla
-#endif // mozilla_dom_BluetoothGattUUIDName_h
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothHashKeys.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 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/. */
-
-/* This file contains hash-table keys for Bluetooth classes. */
-
-#ifndef mozilla_dom_bluetooth_BluetoothHashKeys_h
-#define mozilla_dom_bluetooth_BluetoothHashKeys_h
-
-#include "BluetoothCommon.h"
-#include <mozilla/HashFunctions.h>
-#include <nsHashKeys.h>
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-/**
- * Implements a hash-table key for |BluetoothAddress|.
- */
-class BluetoothAddressHashKey : public PLDHashEntryHdr
-{
-public:
-  enum {
-    ALLOW_MEMMOVE = true
-  };
-
-  typedef const BluetoothAddress& KeyType;
-  typedef const BluetoothAddress* KeyTypePointer;
-
-  explicit BluetoothAddressHashKey(KeyTypePointer aKey)
-    : mValue(*aKey)
-  { }
-  BluetoothAddressHashKey(const BluetoothAddressHashKey& aToCopy)
-    : mValue(aToCopy.mValue)
-  { }
-  ~BluetoothAddressHashKey()
-  { }
-  KeyType GetKey() const
-  {
-    return mValue;
-  }
-  bool KeyEquals(KeyTypePointer aKey) const
-  {
-    return *aKey == mValue;
-  }
-  static KeyTypePointer KeyToPointer(KeyType aKey)
-  {
-    return &aKey;
-  }
-  static PLDHashNumber HashKey(KeyTypePointer aKey)
-  {
-    return HashBytes(aKey->mAddr, MOZ_ARRAY_LENGTH(aKey->mAddr));
-  }
-private:
-  const BluetoothAddress mValue;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothHashKeys_h
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothHfpManagerBase.h
+++ /dev/null
@@ -1,32 +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_bluetoothhfpmanagerbase_h__
-#define mozilla_dom_bluetooth_bluetoothhfpmanagerbase_h__
-
-#include "BluetoothProfileManagerBase.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothHfpManagerBase : public BluetoothProfileManagerBase
-{
-public:
-  /**
-   * Returns true if Sco is connected.
-   */
-  virtual bool IsScoConnected() = 0;
-
-  virtual bool IsNrecEnabled() = 0;
-};
-
-#define BT_DECL_HFP_MGR_BASE                  \
-  BT_DECL_PROFILE_MGR_BASE                    \
-  virtual bool IsScoConnected() override;     \
-  virtual bool IsNrecEnabled() override;
-
-END_BLUETOOTH_NAMESPACE
-
-#endif  //#ifndef mozilla_dom_bluetooth_bluetoothhfpmanagerbase_h__
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothInterface.cpp
+++ /dev/null
@@ -1,1219 +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 "BluetoothInterface.h"
-#if ANDROID_VERSION >= 17
-#include <cutils/properties.h>
-#endif
-#ifdef MOZ_B2G_BT_DAEMON
-#include "BluetoothDaemonInterface.h"
-#endif
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-//
-// Setup Interface
-//
-
-// Result handling
-//
-
-void
-BluetoothSetupResultHandler::OnError(BluetoothStatus aStatus)
-{
-  BT_WARNING("Received error code %d", (int)aStatus);
-}
-
-void
-BluetoothSetupResultHandler::RegisterModule()
-{ }
-
-void
-BluetoothSetupResultHandler::UnregisterModule()
-{ }
-
-void
-BluetoothSetupResultHandler::Configuration()
-{ }
-
-// Interface
-//
-
-BluetoothSetupInterface::~BluetoothSetupInterface()
-{ }
-
-//
-// Bluetooth Core Interface
-//
-
-// Notification handling
-//
-
-BluetoothCoreNotificationHandler::BluetoothCoreNotificationHandler()
-{ }
-
-BluetoothCoreNotificationHandler::~BluetoothCoreNotificationHandler()
-{ }
-
-void
-BluetoothCoreNotificationHandler::AdapterStateChangedNotification(bool aState)
-{ }
-
-void
-BluetoothCoreNotificationHandler::AdapterPropertiesNotification(
-  BluetoothStatus aStatus,int aNumProperties,
-  const BluetoothProperty* aProperties)
-{ }
-
-void
-BluetoothCoreNotificationHandler::RemoteDevicePropertiesNotification(
-  BluetoothStatus aStatus, const BluetoothAddress& aBdAddr,
-  int aNumProperties, const BluetoothProperty* aProperties)
-{ }
-
-void
-BluetoothCoreNotificationHandler::DeviceFoundNotification(
-  int aNumProperties, const BluetoothProperty* aProperties)
-{ }
-
-void
-BluetoothCoreNotificationHandler::DiscoveryStateChangedNotification(
-  bool aState)
-{ }
-
-void
-BluetoothCoreNotificationHandler::PinRequestNotification(
-  const BluetoothAddress& aRemoteBdAddr, const BluetoothRemoteName& aBdName,
-  uint32_t aCod)
-{ }
-
-void
-BluetoothCoreNotificationHandler::SspRequestNotification(
-  const BluetoothAddress& aRemoteBdAddr, const BluetoothRemoteName& aBdName,
-  uint32_t aCod, BluetoothSspVariant aPairingVariant, uint32_t aPassKey)
-{ }
-
-void
-BluetoothCoreNotificationHandler::BondStateChangedNotification(
-  BluetoothStatus aStatus, const BluetoothAddress& aRemoteBdAddr,
-  BluetoothBondState aState)
-{ }
-
-void
-BluetoothCoreNotificationHandler::AclStateChangedNotification(
-  BluetoothStatus aStatus, const BluetoothAddress& aRemoteBdAddr,
-  BluetoothAclState aState)
-{ }
-
-void
-BluetoothCoreNotificationHandler::DutModeRecvNotification(
-  uint16_t aOpcode,
-  const uint8_t* aBuf,
-  uint8_t aLen)
-{ }
-
-void
-BluetoothCoreNotificationHandler::LeTestModeNotification(
-  BluetoothStatus aStatus,
-  uint16_t aNumPackets)
-{ }
-
-void
-BluetoothCoreNotificationHandler::EnergyInfoNotification(
-  const BluetoothActivityEnergyInfo& aInfo)
-{ }
-
-// Result handling
-//
-
-void
-BluetoothCoreResultHandler::OnError(BluetoothStatus aStatus)
-{
-  BT_LOGR("Received error code %d", aStatus);
-}
-
-void
-BluetoothCoreResultHandler::Enable()
-{ }
-
-void
-BluetoothCoreResultHandler::Disable()
-{ }
-
-void
-BluetoothCoreResultHandler::GetAdapterProperties()
-{ }
-
-void
-BluetoothCoreResultHandler::GetAdapterProperty()
-{ }
-
-void
-BluetoothCoreResultHandler::SetAdapterProperty()
-{ }
-
-void
-BluetoothCoreResultHandler::GetRemoteDeviceProperties()
-{ }
-
-void
-BluetoothCoreResultHandler::GetRemoteDeviceProperty()
-{ }
-
-void
-BluetoothCoreResultHandler::SetRemoteDeviceProperty()
-{ }
-
-void
-BluetoothCoreResultHandler::GetRemoteServiceRecord()
-{ }
-
-void
-BluetoothCoreResultHandler::GetRemoteServices()
-{ }
-
-void
-BluetoothCoreResultHandler::StartDiscovery()
-{ }
-
-void
-BluetoothCoreResultHandler::CancelDiscovery()
-{ }
-
-void
-BluetoothCoreResultHandler::CreateBond()
-{ }
-
-void
-BluetoothCoreResultHandler::RemoveBond()
-{ }
-
-void
-BluetoothCoreResultHandler::CancelBond()
-{ }
-
-void
-BluetoothCoreResultHandler::GetConnectionState()
-{ }
-
-void
-BluetoothCoreResultHandler::PinReply()
-{ }
-
-void
-BluetoothCoreResultHandler::SspReply()
-{ }
-
-void
-BluetoothCoreResultHandler::DutModeConfigure()
-{ }
-
-void
-BluetoothCoreResultHandler::DutModeSend()
-{ }
-
-void
-BluetoothCoreResultHandler::LeTestMode()
-{ }
-
-void
-BluetoothCoreResultHandler::ReadEnergyInfo()
-{ }
-
-// Interface
-//
-
-BluetoothCoreInterface::BluetoothCoreInterface()
-{ }
-
-BluetoothCoreInterface::~BluetoothCoreInterface()
-{ }
-
-//
-// Socket Interface
-//
-
-// Result handling
-//
-
-void
-BluetoothSocketResultHandler::OnError(BluetoothStatus aStatus)
-{
-  BT_WARNING("Received error code %d", (int)aStatus);
-}
-
-void
-BluetoothSocketResultHandler::Listen(int aSockFd)
-{ }
-
-void
-BluetoothSocketResultHandler::Connect(int aSockFd,
-                                      const BluetoothAddress& aBdAddress,
-                                      int aConnectionState)
-{ }
-
-void
-BluetoothSocketResultHandler::Accept(int aSockFd,
-                                     const BluetoothAddress& aBdAddress,
-                                     int aConnectionState)
-{ }
-
-// Interface
-//
-
-BluetoothSocketInterface::~BluetoothSocketInterface()
-{ }
-
-//
-//Hid Interface
-//
-
-//Notification handling
-//
-
-BluetoothHidNotificationHandler::BluetoothHidNotificationHandler()
-{ }
-
-BluetoothHidNotificationHandler::~BluetoothHidNotificationHandler()
-{ }
-
-void
-BluetoothHidNotificationHandler::ConnectionStateNotification(
-  const BluetoothAddress& aBdAddr, BluetoothHidConnectionState aState)
-{ }
-
-void
-BluetoothHidNotificationHandler::HidInfoNotification(
-  const BluetoothAddress& aBdAddr,
-  const BluetoothHidInfoParam& aHidInfoParam)
-{ }
-
-void
-BluetoothHidNotificationHandler::ProtocolModeNotification(
-  const BluetoothAddress& aBdAddr, BluetoothHidStatus aStatus,
-  BluetoothHidProtocolMode aProtocolMode)
-{ }
-
-void
-BluetoothHidNotificationHandler::IdleTimeNotification(
-  const BluetoothAddress& aBdAddr,
-  BluetoothHidStatus aStatus, uint16_t aIdleTime)
-{ }
-
-void
-BluetoothHidNotificationHandler::GetReportNotification(
-  const BluetoothAddress& aBdAddr, BluetoothHidStatus aStatus,
-  const BluetoothHidReport& aReport)
-{ }
-
-void
-BluetoothHidNotificationHandler::VirtualUnplugNotification(
-  const BluetoothAddress& aBdAddr, BluetoothHidStatus aStatus)
-{ }
-
-void
-BluetoothHidNotificationHandler::HandshakeNotification(
-  const BluetoothAddress& aBdAddr, BluetoothHidStatus aStatus)
-{ }
-
-// Result handling
-//
-
-void BluetoothHidResultHandler::OnError(BluetoothStatus aStatus)
-{
-  BT_WARNING("Received error code %d", (int)aStatus);
-}
-
-void
-BluetoothHidResultHandler::Connect()
-{ }
-
-void
-BluetoothHidResultHandler::Disconnect()
-{ }
-
-void
-BluetoothHidResultHandler::VirtualUnplug()
-{ }
-
-void
-BluetoothHidResultHandler::SetInfo()
-{ }
-
-void
-BluetoothHidResultHandler::GetProtocol()
-{ }
-
-void
-BluetoothHidResultHandler::SetProtocol()
-{ }
-
-void
-BluetoothHidResultHandler::GetReport()
-{ }
-
-void
-BluetoothHidResultHandler::SetReport()
-{ }
-
-void
-BluetoothHidResultHandler::SendData()
-{ }
-
-// Interface
-//
-
-BluetoothHidInterface::BluetoothHidInterface()
-{ }
-
-BluetoothHidInterface::~BluetoothHidInterface()
-{ }
-
-//
-// Handsfree Interface
-//
-
-// Notification handling
-//
-
-BluetoothHandsfreeNotificationHandler::BluetoothHandsfreeNotificationHandler()
-{ }
-
-BluetoothHandsfreeNotificationHandler::~BluetoothHandsfreeNotificationHandler()
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::ConnectionStateNotification(
-  BluetoothHandsfreeConnectionState aState, const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::AudioStateNotification(
-  BluetoothHandsfreeAudioState aState, const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::VoiceRecognitionNotification(
-  BluetoothHandsfreeVoiceRecognitionState aState, const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::AnswerCallNotification(
-  const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::HangupCallNotification(
-  const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::VolumeNotification(
-  BluetoothHandsfreeVolumeType aType, int aVolume, const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::DialCallNotification(
-  const nsAString& aNumber, const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::DtmfNotification(
-  char aDtmf, const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::NRECNotification(
-  BluetoothHandsfreeNRECState aNrec, const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::WbsNotification(
-  BluetoothHandsfreeWbsConfig aWbs, const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::CallHoldNotification(
-  BluetoothHandsfreeCallHoldType aChld, const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::CnumNotification(
-  const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::CindNotification(
-  const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::CopsNotification(
-  const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::ClccNotification(
-  const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::UnknownAtNotification(
-  const nsACString& aAtString, const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothHandsfreeNotificationHandler::KeyPressedNotification(
-  const BluetoothAddress& aBdAddr)
-{ }
-
-// Result handling
-//
-
-void
-BluetoothHandsfreeResultHandler::OnError(BluetoothStatus aStatus)
-{
-  BT_WARNING("Received error code %d", (int)aStatus);
-}
-
-void
-BluetoothHandsfreeResultHandler::Connect()
-{ }
-
-void
-BluetoothHandsfreeResultHandler::Disconnect()
-{ }
-
-void
-BluetoothHandsfreeResultHandler::ConnectAudio()
-{ }
-
-void
-BluetoothHandsfreeResultHandler::DisconnectAudio()
-{ }
-
-void
-BluetoothHandsfreeResultHandler::StartVoiceRecognition()
-{ }
-
-void
-BluetoothHandsfreeResultHandler::StopVoiceRecognition()
-{ }
-
-void
-BluetoothHandsfreeResultHandler::VolumeControl()
-{ }
-
-void
-BluetoothHandsfreeResultHandler::DeviceStatusNotification()
-{ }
-
-void
-BluetoothHandsfreeResultHandler::CopsResponse()
-{ }
-
-void
-BluetoothHandsfreeResultHandler::CindResponse()
-{ }
-
-void
-BluetoothHandsfreeResultHandler::FormattedAtResponse()
-{ }
-
-void
-BluetoothHandsfreeResultHandler::AtResponse()
-{ }
-
-void
-BluetoothHandsfreeResultHandler::ClccResponse()
-{ }
-
-void
-BluetoothHandsfreeResultHandler::PhoneStateChange()
-{ }
-
-void
-BluetoothHandsfreeResultHandler::ConfigureWbs()
-{ }
-
-// Interface
-//
-
-BluetoothHandsfreeInterface::BluetoothHandsfreeInterface()
-{ }
-
-BluetoothHandsfreeInterface::~BluetoothHandsfreeInterface()
-{ }
-
-//
-// Bluetooth Advanced Audio Interface
-//
-
-// Notification handling
-//
-
-BluetoothA2dpNotificationHandler::BluetoothA2dpNotificationHandler()
-{ }
-
-BluetoothA2dpNotificationHandler::~BluetoothA2dpNotificationHandler()
-{ }
-
-void
-BluetoothA2dpNotificationHandler::ConnectionStateNotification(
-  BluetoothA2dpConnectionState aState, const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothA2dpNotificationHandler::AudioStateNotification(
-  BluetoothA2dpAudioState aState, const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothA2dpNotificationHandler::AudioConfigNotification(
-  const BluetoothAddress& aBdAddr, uint32_t aSampleRate, uint8_t aChannelCount)
-{ }
-
-// Result handling
-//
-
-void
-BluetoothA2dpResultHandler::OnError(BluetoothStatus aStatus)
-{
-  BT_WARNING("Received error code %d", (int)aStatus);
-}
-
-void
-BluetoothA2dpResultHandler::Connect()
-{ }
-
-void
-BluetoothA2dpResultHandler::Disconnect()
-{ }
-
-// Interface
-//
-
-BluetoothA2dpInterface::BluetoothA2dpInterface()
-{ }
-
-BluetoothA2dpInterface::~BluetoothA2dpInterface()
-{ }
-
-//
-// Bluetooth AVRCP Interface
-//
-
-// Notification handling
-//
-
-BluetoothAvrcpNotificationHandler::BluetoothAvrcpNotificationHandler()
-{ }
-
-BluetoothAvrcpNotificationHandler::~BluetoothAvrcpNotificationHandler()
-{ }
-
-void
-BluetoothAvrcpNotificationHandler::GetPlayStatusNotification()
-{ }
-
-void
-BluetoothAvrcpNotificationHandler::ListPlayerAppAttrNotification()
-{ }
-
-void
-BluetoothAvrcpNotificationHandler::ListPlayerAppValuesNotification(
-  BluetoothAvrcpPlayerAttribute aAttrId)
-{ }
-
-void
-BluetoothAvrcpNotificationHandler::GetPlayerAppValueNotification(
-  uint8_t aNumAttrs, const BluetoothAvrcpPlayerAttribute* aAttrs)
-{ }
-
-void
-BluetoothAvrcpNotificationHandler::GetPlayerAppAttrsTextNotification(
-  uint8_t aNumAttrs, const BluetoothAvrcpPlayerAttribute* aAttrs)
-{ }
-
-void
-BluetoothAvrcpNotificationHandler::GetPlayerAppValuesTextNotification(
-  uint8_t aAttrId, uint8_t aNumVals, const uint8_t* aValues)
-{ }
-
-void
-BluetoothAvrcpNotificationHandler::SetPlayerAppValueNotification(
-  const BluetoothAvrcpPlayerSettings& aSettings)
-{ }
-
-void
-BluetoothAvrcpNotificationHandler::GetElementAttrNotification(
-  uint8_t aNumAttrs, const BluetoothAvrcpMediaAttribute* aAttrs)
-{ }
-
-void
-BluetoothAvrcpNotificationHandler::RegisterNotificationNotification(
-  BluetoothAvrcpEvent aEvent, uint32_t aParam)
-{ }
-
-void
-BluetoothAvrcpNotificationHandler::RemoteFeatureNotification(
-  const BluetoothAddress& aBdAddr, unsigned long aFeatures)
-{ }
-
-void
-BluetoothAvrcpNotificationHandler::VolumeChangeNotification(
-  uint8_t aVolume, uint8_t aCType)
-{ }
-
-void
-BluetoothAvrcpNotificationHandler::PassthroughCmdNotification(
-  uint8_t aId, uint8_t aKeyState)
-{ }
-
-// Result handling
-//
-
-void
-BluetoothAvrcpResultHandler::OnError(BluetoothStatus aStatus)
-{
-  BT_WARNING("Received error code %d", (int)aStatus);
-}
-
-void
-BluetoothAvrcpResultHandler::GetPlayStatusRsp()
-{ }
-
-void
-BluetoothAvrcpResultHandler::ListPlayerAppAttrRsp()
-{ }
-
-void
-BluetoothAvrcpResultHandler::ListPlayerAppValueRsp()
-{ }
-
-void
-BluetoothAvrcpResultHandler::GetPlayerAppValueRsp()
-{ }
-
-void
-BluetoothAvrcpResultHandler::GetPlayerAppAttrTextRsp()
-{ }
-
-void
-BluetoothAvrcpResultHandler::GetPlayerAppValueTextRsp()
-{ }
-
-void
-BluetoothAvrcpResultHandler::GetElementAttrRsp()
-{ }
-
-void
-BluetoothAvrcpResultHandler::SetPlayerAppValueRsp()
-{ }
-
-void
-BluetoothAvrcpResultHandler::RegisterNotificationRsp()
-{ }
-
-void
-BluetoothAvrcpResultHandler::SetVolume()
-{ }
-
-// Interface
-//
-
-BluetoothAvrcpInterface::BluetoothAvrcpInterface()
-{ }
-
-BluetoothAvrcpInterface::~BluetoothAvrcpInterface()
-{ }
-
-//
-// Bluetooth GATT Interface
-//
-
-// Notification handling
-//
-
-BluetoothGattNotificationHandler::BluetoothGattNotificationHandler()
-{ }
-
-BluetoothGattNotificationHandler::~BluetoothGattNotificationHandler()
-{ }
-
-void
-BluetoothGattNotificationHandler::RegisterClientNotification(
-  BluetoothGattStatus aStatus, int aClientIf, const BluetoothUuid& aAppUuid)
-{ }
-
-void
-BluetoothGattNotificationHandler::ScanResultNotification(
-  const BluetoothAddress& aBdAddr, int aRssi, const BluetoothGattAdvData& aAdvData)
-{ }
-
-void
-BluetoothGattNotificationHandler::ConnectNotification(
-  int aConnId, BluetoothGattStatus aStatus, int aClientIf,
-  const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothGattNotificationHandler::DisconnectNotification(
-  int aConnId, BluetoothGattStatus aStatus, int aClientIf,
-  const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothGattNotificationHandler::SearchCompleteNotification(
-  int aConnId, BluetoothGattStatus aStatus)
-{ }
-
-void
-BluetoothGattNotificationHandler::SearchResultNotification(
-  int aConnId, const BluetoothGattServiceId& aServiceId)
-{ }
-
-void
-BluetoothGattNotificationHandler::GetCharacteristicNotification(
-  int aConnId, BluetoothGattStatus aStatus,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId,
-  const BluetoothGattCharProp& aCharProperty)
-{ }
-
-void
-BluetoothGattNotificationHandler::GetDescriptorNotification(
-  int aConnId, BluetoothGattStatus aStatus,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharId,
-  const BluetoothGattId& aDescriptorId)
-{ }
-
-void
-BluetoothGattNotificationHandler::GetIncludedServiceNotification(
-  int aConnId, BluetoothGattStatus aStatus,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattServiceId& aIncludedServId)
-{ }
-
-void
-BluetoothGattNotificationHandler::RegisterNotificationNotification(
-  int aConnId, int aIsRegister, BluetoothGattStatus aStatus,
-  const BluetoothGattServiceId& aServiceId, const BluetoothGattId& aCharId)
-{ }
-
-void
-BluetoothGattNotificationHandler::NotifyNotification(
-  int aConnId, const BluetoothGattNotifyParam& aNotifyParam)
-{ }
-
-void
-BluetoothGattNotificationHandler::ReadCharacteristicNotification(
-  int aConnId, BluetoothGattStatus aStatus,
-  const BluetoothGattReadParam& aReadParam)
-{ }
-
-void
-BluetoothGattNotificationHandler::WriteCharacteristicNotification(
-  int aConnId, BluetoothGattStatus aStatus,
-  const BluetoothGattWriteParam& aWriteParam)
-{ }
-
-void
-BluetoothGattNotificationHandler::ReadDescriptorNotification(
-  int aConnId, BluetoothGattStatus aStatus,
-  const BluetoothGattReadParam& aReadParam)
-{ }
-
-void
-BluetoothGattNotificationHandler::WriteDescriptorNotification(
-  int aConnId, BluetoothGattStatus aStatus,
-  const BluetoothGattWriteParam& aWriteParam)
-{ }
-
-void
-BluetoothGattNotificationHandler::ExecuteWriteNotification(
-  int aConnId, BluetoothGattStatus aStatus)
-{ }
-
-void
-BluetoothGattNotificationHandler::ReadRemoteRssiNotification(
-  int aClientIf, const BluetoothAddress& aBdAddr, int aRssi,
-  BluetoothGattStatus aStatus)
-{ }
-
-void
-BluetoothGattNotificationHandler::ListenNotification(
-  BluetoothGattStatus aStatus, int aServerIf)
-{ }
-
-void
-BluetoothGattNotificationHandler::RegisterServerNotification(
-  BluetoothGattStatus aStatus, int aServerIf, const BluetoothUuid& aAppUuid)
-{ }
-
-void
-BluetoothGattNotificationHandler::ConnectionNotification(
-  int aConnId, int aServerIf, bool aConnected, const BluetoothAddress& aBdAddr)
-{ }
-
-void
-BluetoothGattNotificationHandler::ServiceAddedNotification(
-  BluetoothGattStatus aStatus, int aServerIf,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothAttributeHandle& aServiceHandle)
-{ }
-
-void
-BluetoothGattNotificationHandler::IncludedServiceAddedNotification(
-  BluetoothGattStatus aStatus, int aServerIf,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aIncludedServiceHandle)
-{ }
-
-void
-BluetoothGattNotificationHandler::CharacteristicAddedNotification(
-  BluetoothGattStatus aStatus, int aServerIf, const BluetoothUuid& aCharId,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aCharacteristicHandle)
-{ }
-
-void
-BluetoothGattNotificationHandler::DescriptorAddedNotification(
-  BluetoothGattStatus aStatus, int aServerIf, const BluetoothUuid& aCharId,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aDescriptorHandle)
-{ }
-
-void
-BluetoothGattNotificationHandler::ServiceStartedNotification(
-  BluetoothGattStatus aStatus, int aServerIf,
-  const BluetoothAttributeHandle& aServiceHandle)
-{ }
-
-void
-BluetoothGattNotificationHandler::ServiceStoppedNotification(
-  BluetoothGattStatus aStatus, int aServerIf,
-  const BluetoothAttributeHandle& aServiceHandle)
-{ }
-
-void
-BluetoothGattNotificationHandler::ServiceDeletedNotification(
-  BluetoothGattStatus aStatus, int aServerIf,
-  const BluetoothAttributeHandle& aServiceHandle)
-{ }
-
-void
-BluetoothGattNotificationHandler::RequestReadNotification(
-  int aConnId, int aTransId, const BluetoothAddress& aBdAddr,
-  const BluetoothAttributeHandle& aAttributeHandle, int aOffset, bool aIsLong)
-{ }
-
-void
-BluetoothGattNotificationHandler::RequestWriteNotification(
-  int aConnId, int aTransId, const BluetoothAddress& aBdAddr,
-  const BluetoothAttributeHandle& aAttributeHandle, int aOffset, int aLength,
-  const uint8_t* aValue, bool aNeedResponse, bool aIsPrepareWrite)
-{ }
-
-void
-BluetoothGattNotificationHandler::RequestExecuteWriteNotification(
-  int aConnId, int aTransId, const BluetoothAddress& aBdAddr, bool aExecute)
-{ }
-
-void
-BluetoothGattNotificationHandler::ResponseConfirmationNotification(
-  BluetoothGattStatus aStatus, int aHandle)
-{ }
-
-void
-BluetoothGattNotificationHandler::IndicationSentNotification(
-  int aConnId, BluetoothGattStatus aStatus)
-{ }
-
-void
-BluetoothGattNotificationHandler::CongestionNotification(int aConnId,
-                                                         bool aCongested)
-{ }
-
-void
-BluetoothGattNotificationHandler::MtuChangedNotification(int aConnId,
-                                                         int aMtu)
-{ }
-
-// Result handling
-//
-
-void
-BluetoothGattResultHandler::OnError(BluetoothStatus aStatus)
-{
-  BT_WARNING("Received error code %d", (int)aStatus);
-}
-
-void
-BluetoothGattResultHandler::RegisterClient()
-{ }
-
-void
-BluetoothGattResultHandler::UnregisterClient()
-{ }
-
-void
-BluetoothGattResultHandler::Scan()
-{ }
-
-void
-BluetoothGattResultHandler::Connect()
-{ }
-
-void
-BluetoothGattResultHandler::Disconnect()
-{ }
-
-void
-BluetoothGattResultHandler::Listen()
-{ }
-
-void
-BluetoothGattResultHandler::Refresh()
-{ }
-
-void
-BluetoothGattResultHandler::SearchService()
-{ }
-
-void
-BluetoothGattResultHandler::GetIncludedService()
-{ }
-
-void
-BluetoothGattResultHandler::GetCharacteristic()
-{ }
-
-void
-BluetoothGattResultHandler::GetDescriptor()
-{ }
-
-void
-BluetoothGattResultHandler::ReadCharacteristic()
-{ }
-
-void
-BluetoothGattResultHandler::WriteCharacteristic()
-{ }
-
-void
-BluetoothGattResultHandler::ReadDescriptor()
-{ }
-
-void
-BluetoothGattResultHandler::WriteDescriptor()
-{ }
-
-void
-BluetoothGattResultHandler::ExecuteWrite()
-{ }
-
-void
-BluetoothGattResultHandler::RegisterNotification()
-{ }
-
-void
-BluetoothGattResultHandler::DeregisterNotification()
-{ }
-
-void
-BluetoothGattResultHandler::ReadRemoteRssi()
-{ }
-
-void
-BluetoothGattResultHandler::GetDeviceType(BluetoothTypeOfDevice aType)
-{ }
-
-void
-BluetoothGattResultHandler::SetAdvData()
-{ }
-
-void
-BluetoothGattResultHandler::TestCommand()
-{ }
-
-void
-BluetoothGattResultHandler::RegisterServer()
-{ }
-
-void
-BluetoothGattResultHandler::UnregisterServer()
-{ }
-
-void
-BluetoothGattResultHandler::ConnectPeripheral()
-{ }
-
-void
-BluetoothGattResultHandler::DisconnectPeripheral()
-{ }
-
-void
-BluetoothGattResultHandler::AddService()
-{ }
-
-void
-BluetoothGattResultHandler::AddIncludedService()
-{ }
-
-void
-BluetoothGattResultHandler::AddCharacteristic()
-{ }
-
-void
-BluetoothGattResultHandler::AddDescriptor()
-{ }
-
-void
-BluetoothGattResultHandler::StartService()
-{ }
-
-void
-BluetoothGattResultHandler::StopService()
-{ }
-
-void
-BluetoothGattResultHandler::DeleteService()
-{ }
-
-void
-BluetoothGattResultHandler::SendIndication()
-{ }
-
-void
-BluetoothGattResultHandler::SendResponse()
-{ }
-
-// Interface
-//
-
-BluetoothGattInterface::BluetoothGattInterface()
-{ }
-
-BluetoothGattInterface::~BluetoothGattInterface()
-{ }
-
-//
-// Bluetooth Interface
-//
-
-// Notification handling
-//
-
-BluetoothNotificationHandler::BluetoothNotificationHandler()
-{ }
-
-BluetoothNotificationHandler::~BluetoothNotificationHandler()
-{ }
-
-void
-BluetoothNotificationHandler::BackendErrorNotification(bool aCrashed)
-{ }
-
-// Result handling
-//
-
-void
-BluetoothResultHandler::OnError(BluetoothStatus aStatus)
-{
-  BT_LOGR("Received error code %d", aStatus);
-}
-
-void
-BluetoothResultHandler::Init()
-{ }
-
-void
-BluetoothResultHandler::Cleanup()
-{ }
-
-// Interface
-//
-
-BluetoothInterface*
-BluetoothInterface::GetInstance()
-{
-#if ANDROID_VERSION >= 17
-  /* We pick a default backend from the available ones. The options are
-   * ordered by preference. If a backend is supported but not available
-   * on the current system, we pick the next one. The selected default
-   * 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
-    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 */
-    defaultBackend = sDefaultBackend[i];
-
-    if (defaultBackend) {
-      if (!strcmp(defaultBackend, "bluetoothd") &&
-          access("/init.bluetooth.rc", F_OK) == -1) {
-        continue; /* bluetoothd not available */
-      }
-    }
-    break;
-  }
-
-  char value[PROPERTY_VALUE_MAX];
-  int len;
-
-  len = property_get("ro.moz.bluetooth.backend", value, defaultBackend);
-  if (len < 0) {
-    BT_WARNING("No Bluetooth backend available.");
-    return nullptr;
-  }
-
-  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_DAEMON
-  if (backend.LowerCaseEqualsLiteral("bluetoothd")) {
-    return BluetoothDaemonInterface::GetInstance();
-  } else
-#endif
-  {
-    BT_WARNING("Bluetooth backend '%s' is unknown or not available.",
-               backend.get());
-  }
-  return nullptr;
-
-#else
-  /* Anything that's not Android 4.2 or later uses BlueZ instead. The
-   * code should actually never reach this point.
-   */
-  BT_WARNING("No Bluetooth backend available for your system.");
-  return nullptr;
-#endif
-}
-
-BluetoothInterface::BluetoothInterface()
-{ }
-
-BluetoothInterface::~BluetoothInterface()
-{ }
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothInterface.h
+++ /dev/null
@@ -1,1290 +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_BluetoothInterface_h
-#define mozilla_dom_bluetooth_BluetoothInterface_h
-
-#include "BluetoothCommon.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/ipc/DaemonSocketMessageHandlers.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-//
-// Setup Interface
-//
-
-class BluetoothSetupResultHandler
-  : public mozilla::ipc::DaemonSocketResultHandler
-{
-public:
-  virtual void OnError(BluetoothStatus aStatus);
-  virtual void RegisterModule();
-  virtual void UnregisterModule();
-  virtual void Configuration();
-
-protected:
-  virtual ~BluetoothSetupResultHandler() { }
-};
-
-class BluetoothSetupInterface
-{
-public:
-  virtual void RegisterModule(BluetoothSetupServiceId aId,
-                              uint8_t aMode,
-                              uint32_t aMaxNumClients,
-                              BluetoothSetupResultHandler* aRes) = 0;
-
-  virtual void UnregisterModule(BluetoothSetupServiceId aId,
-                                BluetoothSetupResultHandler* aRes) = 0;
-
-  virtual void Configuration(const BluetoothConfigurationParameter* aParam,
-                             uint8_t aLen,
-                             BluetoothSetupResultHandler* aRes) = 0;
-
-protected:
-  virtual ~BluetoothSetupInterface();
-};
-
-//
-// Bluetooth Core Interface
-//
-
-class BluetoothCoreNotificationHandler
-{
-public:
-  virtual void AdapterStateChangedNotification(bool aState);
-  virtual void AdapterPropertiesNotification(
-    BluetoothStatus aStatus, int aNumProperties,
-    const BluetoothProperty* aProperties);
-
-  virtual void RemoteDevicePropertiesNotification(
-    BluetoothStatus aStatus, const BluetoothAddress& aBdAddr,
-    int aNumProperties, const BluetoothProperty* aProperties);
-
-  virtual void DeviceFoundNotification(
-    int aNumProperties, const BluetoothProperty* aProperties);
-
-  virtual void DiscoveryStateChangedNotification(bool aState);
-
-  virtual void PinRequestNotification(const BluetoothAddress& aRemoteBdAddr,
-                                      const BluetoothRemoteName& aBdName,
-                                      uint32_t aCod);
-  virtual void SspRequestNotification(const BluetoothAddress& aRemoteBdAddr,
-                                      const BluetoothRemoteName& aBdName,
-                                      uint32_t aCod,
-                                      BluetoothSspVariant aPairingVariant,
-                                      uint32_t aPassKey);
-
-  virtual void BondStateChangedNotification(
-    BluetoothStatus aStatus, const BluetoothAddress& aRemoteBdAddr,
-    BluetoothBondState aState);
-  virtual void AclStateChangedNotification(
-    BluetoothStatus aStatus, const BluetoothAddress& aRemoteBdAddr,
-    BluetoothAclState aState);
-
-  virtual void DutModeRecvNotification(uint16_t aOpcode,
-                                       const uint8_t* aBuf, uint8_t aLen);
-  virtual void LeTestModeNotification(BluetoothStatus aStatus,
-                                      uint16_t aNumPackets);
-
-  virtual void EnergyInfoNotification(const BluetoothActivityEnergyInfo& aInfo);
-
-protected:
-  BluetoothCoreNotificationHandler();
-  virtual ~BluetoothCoreNotificationHandler();
-};
-
-class BluetoothCoreResultHandler
-  : public mozilla::ipc::DaemonSocketResultHandler
-{
-public:
-  virtual void OnError(BluetoothStatus aStatus);
-
-  virtual void Enable();
-  virtual void Disable();
-
-  virtual void GetAdapterProperties();
-  virtual void GetAdapterProperty();
-  virtual void SetAdapterProperty();
-
-  virtual void GetRemoteDeviceProperties();
-  virtual void GetRemoteDeviceProperty();
-  virtual void SetRemoteDeviceProperty();
-
-  virtual void GetRemoteServiceRecord();
-  virtual void GetRemoteServices();
-
-  virtual void StartDiscovery();
-  virtual void CancelDiscovery();
-
-  virtual void CreateBond();
-  virtual void RemoveBond();
-  virtual void CancelBond();
-
-  virtual void GetConnectionState();
-
-  virtual void PinReply();
-  virtual void SspReply();
-
-  virtual void DutModeConfigure();
-  virtual void DutModeSend();
-
-  virtual void LeTestMode();
-
-  virtual void ReadEnergyInfo();
-
-protected:
-  virtual ~BluetoothCoreResultHandler() { }
-};
-
-class BluetoothCoreInterface
-{
-public:
-  virtual void SetNotificationHandler(
-    BluetoothCoreNotificationHandler* aNotificationHandler) = 0;
-
-  /* Enable/Disable */
-
-  virtual void Enable(BluetoothCoreResultHandler* aRes) = 0;
-  virtual void Disable(BluetoothCoreResultHandler* aRes) = 0;
-
-  /* Adapter Properties */
-
-  virtual void GetAdapterProperties(BluetoothCoreResultHandler* aRes) = 0;
-  virtual void GetAdapterProperty(BluetoothPropertyType,
-                                  BluetoothCoreResultHandler* aRes) = 0;
-  virtual void SetAdapterProperty(const BluetoothProperty& aProperty,
-                                  BluetoothCoreResultHandler* aRes) = 0;
-
-  /* Remote Device Properties */
-
-  virtual void GetRemoteDeviceProperties(const BluetoothAddress& aRemoteAddr,
-                                         BluetoothCoreResultHandler* aRes) = 0;
-  virtual void GetRemoteDeviceProperty(const BluetoothAddress& aRemoteAddr,
-                                       BluetoothPropertyType aType,
-                                       BluetoothCoreResultHandler* aRes) = 0;
-  virtual void SetRemoteDeviceProperty(const BluetoothAddress& aRemoteAddr,
-                                       const BluetoothProperty& aProperty,
-                                       BluetoothCoreResultHandler* aRes) = 0;
-
-  /* Remote Services */
-
-  virtual void GetRemoteServiceRecord(const BluetoothAddress& aRemoteAddr,
-                                      const BluetoothUuid& aUuid,
-                                      BluetoothCoreResultHandler* aRes) = 0;
-  virtual void GetRemoteServices(const BluetoothAddress& aRemoteAddr,
-                                 BluetoothCoreResultHandler* aRes) = 0;
-
-  /* Discovery */
-
-  virtual void StartDiscovery(BluetoothCoreResultHandler* aRes) = 0;
-  virtual void CancelDiscovery(BluetoothCoreResultHandler* aRes) = 0;
-
-  /* Bonds */
-
-  virtual void CreateBond(const BluetoothAddress& aBdAddr,
-                          BluetoothTransport aTransport,
-                          BluetoothCoreResultHandler* aRes) = 0;
-  virtual void RemoveBond(const BluetoothAddress& aBdAddr,
-                          BluetoothCoreResultHandler* aRes) = 0;
-  virtual void CancelBond(const BluetoothAddress& aBdAddr,
-                          BluetoothCoreResultHandler* aRes) = 0;
-
-  /* Connection */
-
-  virtual void GetConnectionState(const BluetoothAddress& aBdAddr,
-                                  BluetoothCoreResultHandler* aRes) = 0;
-
-  /* Authentication */
-
-  virtual void PinReply(const BluetoothAddress& aBdAddr, bool aAccept,
-                        const BluetoothPinCode& aPinCode,
-                        BluetoothCoreResultHandler* aRes) = 0;
-
-  virtual void SspReply(const BluetoothAddress& aBdAddr,
-                        BluetoothSspVariant aVariant,
-                        bool aAccept, uint32_t aPasskey,
-                        BluetoothCoreResultHandler* aRes) = 0;
-
-  /* DUT Mode */
-
-  virtual void DutModeConfigure(bool aEnable,
-                                BluetoothCoreResultHandler* aRes) = 0;
-  virtual void DutModeSend(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
-                           BluetoothCoreResultHandler* aRes) = 0;
-
-  /* LE Mode */
-
-  virtual void LeTestMode(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
-                          BluetoothCoreResultHandler* aRes) = 0;
-
-  /* Energy Info */
-
-  virtual void ReadEnergyInfo(BluetoothCoreResultHandler* aRes) = 0;
-
-protected:
-  BluetoothCoreInterface();
-  virtual ~BluetoothCoreInterface();
-};
-
-//
-// Socket Interface
-//
-
-class BluetoothSocketResultHandler
-  : public mozilla::ipc::DaemonSocketResultHandler
-{
-public:
-  virtual void OnError(BluetoothStatus aStatus);
-
-  virtual void Listen(int aSockFd);
-  virtual void Connect(int aSockFd, const BluetoothAddress& aBdAddress,
-                       int aConnectionState);
-  virtual void Accept(int aSockFd, const BluetoothAddress& aBdAddress,
-                      int aConnectionState);
-
-protected:
-  virtual ~BluetoothSocketResultHandler() { }
-};
-
-class BluetoothSocketInterface
-{
-public:
-  // Init and Cleanup is handled by BluetoothInterface
-
-  virtual void Listen(BluetoothSocketType aType,
-                      const BluetoothServiceName& aServiceName,
-                      const BluetoothUuid& aServiceUuid,
-                      int aChannel, bool aEncrypt, bool aAuth,
-                      BluetoothSocketResultHandler* aRes) = 0;
-
-  virtual void Connect(const BluetoothAddress& aBdAddr,
-                       BluetoothSocketType aType,
-                       const BluetoothUuid& aServiceUuid,
-                       int aChannel, bool aEncrypt, bool aAuth,
-                       BluetoothSocketResultHandler* aRes) = 0;
-
-  virtual void Accept(int aFd, BluetoothSocketResultHandler* aRes) = 0;
-
-  virtual void Close(BluetoothSocketResultHandler* aRes) = 0;
-
-protected:
-  virtual ~BluetoothSocketInterface();
-};
-
-//
-// HID Interface
-//
-
-class BluetoothHidNotificationHandler
-{
-public:
-  virtual void
-  ConnectionStateNotification(const BluetoothAddress& aBdAddr,
-                              BluetoothHidConnectionState aState);
-
-  virtual void
-  HidInfoNotification(
-    const BluetoothAddress& aBdAddr,
-    const BluetoothHidInfoParam& aHidInfoParam);
-
-  virtual void
-  ProtocolModeNotification(const BluetoothAddress& aBdAddr,
-                           BluetoothHidStatus aStatus,
-                           BluetoothHidProtocolMode aProtocolMode);
-
-  virtual void
-  IdleTimeNotification(const BluetoothAddress& aBdAddr,
-                       BluetoothHidStatus aStatus,
-                       uint16_t aIdleTime);
-
-  virtual void
-  GetReportNotification(const BluetoothAddress& aBdAddr,
-                        BluetoothHidStatus aStatus,
-                        const BluetoothHidReport& aReport);
-
-  virtual void
-  VirtualUnplugNotification(const BluetoothAddress& aBdAddr,
-                            BluetoothHidStatus aStatus);
-
-  virtual void
-  HandshakeNotification(const BluetoothAddress& aBdAddr,
-                        BluetoothHidStatus aStatus);
-
-protected:
-  BluetoothHidNotificationHandler();
-  virtual ~BluetoothHidNotificationHandler();
-};
-
-class BluetoothHidResultHandler
-  : public mozilla::ipc::DaemonSocketResultHandler
-{
-public:
-  virtual void OnError(BluetoothStatus aStatus);
-
-  virtual void Connect();
-  virtual void Disconnect();
-
-  virtual void VirtualUnplug();
-
-  virtual void SetInfo();
-
-  virtual void GetProtocol();
-  virtual void SetProtocol();
-
-  virtual void GetReport();
-  virtual void SetReport();
-
-  virtual void SendData();
-
-protected:
-  virtual ~BluetoothHidResultHandler() { }
-};
-
-class BluetoothHidInterface
-{
-public:
-  virtual void SetNotificationHandler(
-    BluetoothHidNotificationHandler* aNotificationHandler) = 0;
-
-  /* Connect / Disconnect */
-
-  virtual void Connect(const BluetoothAddress& aBdAddr,
-                       BluetoothHidResultHandler* aRes) = 0;
-  virtual void Disconnect(const BluetoothAddress& aBdAddr,
-                          BluetoothHidResultHandler* aRes) = 0;
-
-  /* Virtual Unplug */
-  virtual void VirtualUnplug(const BluetoothAddress& aBdAddr,
-                             BluetoothHidResultHandler* aRes) = 0;
-
-  /* Set Info */
-
-  virtual void SetInfo(const BluetoothAddress& aBdAddr,
-                       const BluetoothHidInfoParam& aHidInfoParam,
-                       BluetoothHidResultHandler* aRes) = 0;
-
-  /* Protocol */
-
-  virtual void GetProtocol(const BluetoothAddress& aBdAddr,
-                           BluetoothHidProtocolMode aHidProtoclMode,
-                           BluetoothHidResultHandler* aRes) = 0;
-  virtual void SetProtocol(const BluetoothAddress& aBdAddr,
-                           BluetoothHidProtocolMode aHidProtocolMode,
-                           BluetoothHidResultHandler* aRes) = 0;
-
-  /* Report */
-
-  virtual void GetReport(const BluetoothAddress& aBdAddr,
-                         BluetoothHidReportType aType,
-                         uint8_t aReportId,
-                         uint16_t aBuffSize,
-                         BluetoothHidResultHandler* aRes) = 0;
-  virtual void SetReport(const BluetoothAddress& aBdAddr,
-                         BluetoothHidReportType aType,
-                         const BluetoothHidReport& aReport,
-                         BluetoothHidResultHandler* aRes) = 0;
-
-  /* Send Data */
-
-  virtual void SendData(const BluetoothAddress& aBdAddr,
-                        uint16_t aDataLen, const uint8_t* aData,
-                        BluetoothHidResultHandler* aRes) = 0;
-
-protected:
-  BluetoothHidInterface();
-  virtual ~BluetoothHidInterface();
-};
-
-//
-// Handsfree Interface
-//
-
-class BluetoothHandsfreeNotificationHandler
-{
-public:
-  virtual void
-  ConnectionStateNotification(BluetoothHandsfreeConnectionState aState,
-                              const BluetoothAddress& aBdAddr);
-
-  virtual void
-  AudioStateNotification(BluetoothHandsfreeAudioState aState,
-                         const BluetoothAddress& aBdAddr);
-
-  virtual void
-  VoiceRecognitionNotification(BluetoothHandsfreeVoiceRecognitionState aState,
-                               const BluetoothAddress& aBdAddr);
-
-  virtual void
-  AnswerCallNotification(const BluetoothAddress& aBdAddr);
-
-  virtual void
-  HangupCallNotification(const BluetoothAddress& aBdAddr);
-
-  virtual void
-  VolumeNotification(BluetoothHandsfreeVolumeType aType,
-                     int aVolume,
-                     const BluetoothAddress& aBdAddr);
-
-  virtual void
-  DialCallNotification(const nsAString& aNumber,
-                       const BluetoothAddress& aBdAddr);
-
-  virtual void
-  DtmfNotification(char aDtmf,
-                   const BluetoothAddress& aBdAddr);
-
-  virtual void
-  NRECNotification(BluetoothHandsfreeNRECState aNrec,
-                   const BluetoothAddress& aBdAddr);
-
-  virtual void
-  WbsNotification(BluetoothHandsfreeWbsConfig aWbs,
-                  const BluetoothAddress& aBdAddr);
-
-  virtual void
-  CallHoldNotification(BluetoothHandsfreeCallHoldType aChld,
-                       const BluetoothAddress& aBdAddr);
-
-  virtual void
-  CnumNotification(const BluetoothAddress& aBdAddr);
-
-  virtual void
-  CindNotification(const BluetoothAddress& aBdAddr);
-
-  virtual void
-  CopsNotification(const BluetoothAddress& aBdAddr);
-
-  virtual void
-  ClccNotification(const BluetoothAddress& aBdAddr);
-
-  virtual void
-  UnknownAtNotification(const nsACString& aAtString,
-                        const BluetoothAddress& aBdAddr);
-
-  virtual void
-  KeyPressedNotification(const BluetoothAddress& aBdAddr);
-
-protected:
-  BluetoothHandsfreeNotificationHandler();
-  virtual ~BluetoothHandsfreeNotificationHandler();
-};
-
-class BluetoothHandsfreeResultHandler
-  : public mozilla::ipc::DaemonSocketResultHandler
-{
-public:
-  virtual void OnError(BluetoothStatus aStatus);
-
-  virtual void Connect();
-  virtual void Disconnect();
-  virtual void ConnectAudio();
-  virtual void DisconnectAudio();
-
-  virtual void StartVoiceRecognition();
-  virtual void StopVoiceRecognition();
-
-  virtual void VolumeControl();
-
-  virtual void DeviceStatusNotification();
-
-  virtual void CopsResponse();
-  virtual void CindResponse();
-  virtual void FormattedAtResponse();
-  virtual void AtResponse();
-  virtual void ClccResponse();
-  virtual void PhoneStateChange();
-
-  virtual void ConfigureWbs();
-
-protected:
-  virtual ~BluetoothHandsfreeResultHandler() { }
-};
-
-class BluetoothHandsfreeInterface
-{
-public:
-  virtual void SetNotificationHandler(
-    BluetoothHandsfreeNotificationHandler* aNotificationHandler) = 0;
-
-  /* Connect / Disconnect */
-
-  virtual void Connect(const BluetoothAddress& aBdAddr,
-                       BluetoothHandsfreeResultHandler* aRes) = 0;
-  virtual void Disconnect(const BluetoothAddress& aBdAddr,
-                          BluetoothHandsfreeResultHandler* aRes) = 0;
-  virtual void ConnectAudio(const BluetoothAddress& aBdAddr,
-                            BluetoothHandsfreeResultHandler* aRes) = 0;
-  virtual void DisconnectAudio(const BluetoothAddress& aBdAddr,
-                               BluetoothHandsfreeResultHandler* aRes) = 0;
-
-  /* Voice Recognition */
-
-  virtual void StartVoiceRecognition(const BluetoothAddress& aBdAddr,
-                                     BluetoothHandsfreeResultHandler* aRes) = 0;
-  virtual void StopVoiceRecognition(const BluetoothAddress& aBdAddr,
-                                    BluetoothHandsfreeResultHandler* aRes) = 0;
-
-  /* Volume */
-
-  virtual void VolumeControl(BluetoothHandsfreeVolumeType aType, int aVolume,
-                             const BluetoothAddress& aBdAddr,
-                             BluetoothHandsfreeResultHandler* aRes) = 0;
-
-  /* Device status */
-
-  virtual void DeviceStatusNotification(
-    BluetoothHandsfreeNetworkState aNtkState,
-    BluetoothHandsfreeServiceType aSvcType,
-    int aSignal, int aBattChg, BluetoothHandsfreeResultHandler* aRes) = 0;
-
-  /* Responses */
-
-  virtual void CopsResponse(const char* aCops, const BluetoothAddress& aBdAddr,
-                            BluetoothHandsfreeResultHandler* aRes) = 0;
-  virtual void CindResponse(int aSvc, int aNumActive, int aNumHeld,
-                            BluetoothHandsfreeCallState aCallSetupState,
-                            int aSignal, int aRoam, int aBattChg,
-                            const BluetoothAddress& aBdAddr,
-                            BluetoothHandsfreeResultHandler* aRes) = 0;
-  virtual void FormattedAtResponse(const char* aRsp,
-                                   const BluetoothAddress& aBdAddr,
-                                   BluetoothHandsfreeResultHandler* aRes) = 0;
-  virtual void AtResponse(BluetoothHandsfreeAtResponse aResponseCode,
-                          int aErrorCode, const BluetoothAddress& aBdAddr,
-                          BluetoothHandsfreeResultHandler* aRes) = 0;
-  virtual void ClccResponse(int aIndex, BluetoothHandsfreeCallDirection aDir,
-                            BluetoothHandsfreeCallState aState,
-                            BluetoothHandsfreeCallMode aMode,
-                            BluetoothHandsfreeCallMptyType aMpty,
-                            const nsAString& aNumber,
-                            BluetoothHandsfreeCallAddressType aType,
-                            const BluetoothAddress& aBdAddr,
-                            BluetoothHandsfreeResultHandler* aRes) = 0;
-
-  /* Phone State */
-
-  virtual void PhoneStateChange(int aNumActive, int aNumHeld,
-                                BluetoothHandsfreeCallState aCallSetupState,
-                                const nsAString& aNumber,
-                                BluetoothHandsfreeCallAddressType aType,
-                                BluetoothHandsfreeResultHandler* aRes) = 0;
-
-  /* Wide Band Speech */
-  virtual void ConfigureWbs(const BluetoothAddress& aBdAddr,
-                            BluetoothHandsfreeWbsConfig aConfig,
-                            BluetoothHandsfreeResultHandler* aRes) = 0;
-
-protected:
-  BluetoothHandsfreeInterface();
-  virtual ~BluetoothHandsfreeInterface();
-};
-
-//
-// Bluetooth Advanced Audio Interface
-//
-
-class BluetoothA2dpNotificationHandler
-{
-public:
-  virtual void
-  ConnectionStateNotification(BluetoothA2dpConnectionState aState,
-                              const BluetoothAddress& aBdAddr);
-
-  virtual void
-  AudioStateNotification(BluetoothA2dpAudioState aState,
-                         const BluetoothAddress& aBdAddr);
-
-  virtual void
-  AudioConfigNotification(const BluetoothAddress& aBdAddr,
-                          uint32_t aSampleRate,
-                          uint8_t aChannelCount);
-
-protected:
-  BluetoothA2dpNotificationHandler();
-  virtual ~BluetoothA2dpNotificationHandler();
-};
-
-class BluetoothA2dpResultHandler
-  : public mozilla::ipc::DaemonSocketResultHandler
-{
-public:
-  virtual void OnError(BluetoothStatus aStatus);
-
-  virtual void Connect();
-  virtual void Disconnect();
-
-protected:
-  virtual ~BluetoothA2dpResultHandler() { }
-};
-
-class BluetoothA2dpInterface
-{
-public:
-  virtual void SetNotificationHandler(
-    BluetoothA2dpNotificationHandler* aNotificationHandler) = 0;
-
-  virtual void Connect(const BluetoothAddress& aBdAddr,
-                       BluetoothA2dpResultHandler* aRes) = 0;
-  virtual void Disconnect(const BluetoothAddress& aBdAddr,
-                          BluetoothA2dpResultHandler* aRes) = 0;
-
-protected:
-  BluetoothA2dpInterface();
-  virtual ~BluetoothA2dpInterface();
-};
-
-//
-// Bluetooth AVRCP Interface
-//
-
-class BluetoothAvrcpNotificationHandler
-{
-public:
-  virtual void
-  GetPlayStatusNotification();
-
-  virtual void
-  ListPlayerAppAttrNotification();
-
-  virtual void
-  ListPlayerAppValuesNotification(BluetoothAvrcpPlayerAttribute aAttrId);
-
-  virtual void
-  GetPlayerAppValueNotification(uint8_t aNumAttrs,
-                                const BluetoothAvrcpPlayerAttribute* aAttrs);
-
-  virtual void
-  GetPlayerAppAttrsTextNotification(
-    uint8_t aNumAttrs, const BluetoothAvrcpPlayerAttribute* aAttrs);
-
-  virtual void
-  GetPlayerAppValuesTextNotification(uint8_t aAttrId, uint8_t aNumVals,
-                                     const uint8_t* aValues);
-
-  virtual void
-  SetPlayerAppValueNotification(
-    const BluetoothAvrcpPlayerSettings& aSettings);
-
-  virtual void
-  GetElementAttrNotification(uint8_t aNumAttrs,
-                             const BluetoothAvrcpMediaAttribute* aAttrs);
-
-  virtual void
-  RegisterNotificationNotification(BluetoothAvrcpEvent aEvent,
-                                   uint32_t aParam);
-
-  virtual void
-  RemoteFeatureNotification(const BluetoothAddress& aBdAddr,
-                            unsigned long aFeatures);
-
-  virtual void
-  VolumeChangeNotification(uint8_t aVolume, uint8_t aCType);
-
-  virtual void
-  PassthroughCmdNotification(uint8_t aId, uint8_t aKeyState);
-
-protected:
-  BluetoothAvrcpNotificationHandler();
-  virtual ~BluetoothAvrcpNotificationHandler();
-};
-
-class BluetoothAvrcpResultHandler
-  : public mozilla::ipc::DaemonSocketResultHandler
-{
-public:
-  virtual void OnError(BluetoothStatus aStatus);
-
-  virtual void GetPlayStatusRsp();
-
-  virtual void ListPlayerAppAttrRsp();
-  virtual void ListPlayerAppValueRsp();
-
-  virtual void GetPlayerAppValueRsp();
-  virtual void GetPlayerAppAttrTextRsp();
-  virtual void GetPlayerAppValueTextRsp();
-
-  virtual void GetElementAttrRsp();
-
-  virtual void SetPlayerAppValueRsp();
-
-  virtual void RegisterNotificationRsp();
-
-  virtual void SetVolume();
-
-protected:
-  virtual ~BluetoothAvrcpResultHandler() { }
-};
-
-class BluetoothAvrcpInterface
-{
-public:
-  virtual void SetNotificationHandler(
-    BluetoothAvrcpNotificationHandler* aNotificationHandler) = 0;
-
-  virtual void GetPlayStatusRsp(ControlPlayStatus aPlayStatus,
-                                uint32_t aSongLen, uint32_t aSongPos,
-                                BluetoothAvrcpResultHandler* aRes) = 0;
-
-  virtual void ListPlayerAppAttrRsp(
-    int aNumAttr, const BluetoothAvrcpPlayerAttribute* aPAttrs,
-    BluetoothAvrcpResultHandler* aRes) = 0;
-  virtual void ListPlayerAppValueRsp(int aNumVal, uint8_t* aPVals,
-                                     BluetoothAvrcpResultHandler* aRes) = 0;
-
-  /* TODO: redesign this interface once we actually use it */
-  virtual void GetPlayerAppValueRsp(uint8_t aNumAttrs, const uint8_t* aIds,
-                                    const uint8_t* aValues,
-                                    BluetoothAvrcpResultHandler* aRes) = 0;
-  /* TODO: redesign this interface once we actually use it */
-  virtual void GetPlayerAppAttrTextRsp(int aNumAttr, const uint8_t* aIds,
-                                       const char** aTexts,
-                                       BluetoothAvrcpResultHandler* aRes) = 0;
-  /* TODO: redesign this interface once we actually use it */
-  virtual void GetPlayerAppValueTextRsp(int aNumVal, const uint8_t* aIds,
-                                        const char** aTexts,
-                                        BluetoothAvrcpResultHandler* aRes) = 0;
-
-  virtual void GetElementAttrRsp(uint8_t aNumAttr,
-                                 const BluetoothAvrcpElementAttribute* aAttr,
-                                 BluetoothAvrcpResultHandler* aRes) = 0;
-
-  virtual void SetPlayerAppValueRsp(BluetoothAvrcpStatus aRspStatus,
-                                    BluetoothAvrcpResultHandler* aRes) = 0;
-
-  virtual void RegisterNotificationRsp(
-    BluetoothAvrcpEvent aEvent, BluetoothAvrcpNotification aType,
-    const BluetoothAvrcpNotificationParam& aParam,
-    BluetoothAvrcpResultHandler* aRes) = 0;
-
-  virtual void SetVolume(uint8_t aVolume,
-                         BluetoothAvrcpResultHandler* aRes) = 0;
-
-protected:
-  BluetoothAvrcpInterface();
-  virtual ~BluetoothAvrcpInterface();
-};
-
-//
-// GATT Interface
-//
-
-class BluetoothGattNotificationHandler
-{
-public:
-  virtual void
-  RegisterClientNotification(BluetoothGattStatus aStatus,
-                             int aClientIf,
-                             const BluetoothUuid& aAppUuid);
-
-  virtual void
-  ScanResultNotification(const BluetoothAddress& aBdAddr,
-                         int aRssi,
-                         const BluetoothGattAdvData& aAdvData);
-
-  virtual void
-  ConnectNotification(int aConnId,
-                      BluetoothGattStatus aStatus,
-                      int aClientIf,
-                      const BluetoothAddress& aBdAddr);
-
-  virtual void
-  DisconnectNotification(int aConnId,
-                         BluetoothGattStatus aStatus,
-                         int aClientIf,
-                         const BluetoothAddress& aBdAddr);
-
-  virtual void
-  SearchCompleteNotification(int aConnId, BluetoothGattStatus aStatus);
-
-  virtual void
-  SearchResultNotification(int aConnId,
-                           const BluetoothGattServiceId& aServiceId);
-
-  virtual void
-  GetCharacteristicNotification(int aConnId,
-                                BluetoothGattStatus aStatus,
-                                const BluetoothGattServiceId& aServiceId,
-                                const BluetoothGattId& aCharId,
-                                const BluetoothGattCharProp& aCharProperty);
-
-  virtual void
-  GetDescriptorNotification(int aConnId,
-                            BluetoothGattStatus aStatus,
-                            const BluetoothGattServiceId& aServiceId,
-                            const BluetoothGattId& aCharId,
-                            const BluetoothGattId& aDescriptorId);
-
-  virtual void
-  GetIncludedServiceNotification(int aConnId,
-                                 BluetoothGattStatus aStatus,
-                                 const BluetoothGattServiceId& aServiceId,
-                                 const BluetoothGattServiceId& aIncludedServId);
-
-  virtual void
-  RegisterNotificationNotification(int aConnId,
-                                   int aIsRegister,
-                                   BluetoothGattStatus aStatus,
-                                   const BluetoothGattServiceId& aServiceId,
-                                   const BluetoothGattId& aCharId);
-
-  virtual void
-  NotifyNotification(int aConnId,
-                     const BluetoothGattNotifyParam& aNotifyParam);
-
-  virtual void
-  ReadCharacteristicNotification(int aConnId,
-                                 BluetoothGattStatus aStatus,
-                                 const BluetoothGattReadParam& aReadParam);
-
-  virtual void
-  WriteCharacteristicNotification(int aConnId,
-                                  BluetoothGattStatus aStatus,
-                                  const BluetoothGattWriteParam& aWriteParam);
-
-  virtual void
-  ReadDescriptorNotification(int aConnId,
-                             BluetoothGattStatus aStatus,
-                             const BluetoothGattReadParam& aReadParam);
-
-  virtual void
-  WriteDescriptorNotification(int aConnId,
-                              BluetoothGattStatus aStatus,
-                              const BluetoothGattWriteParam& aWriteParam);
-
-  virtual void
-  ExecuteWriteNotification(int aConnId, BluetoothGattStatus aStatus);
-
-  virtual void
-  ReadRemoteRssiNotification(int aClientIf,
-                             const BluetoothAddress& aBdAddr,
-                             int aRssi,
-                             BluetoothGattStatus aStatus);
-
-  virtual void
-  ListenNotification(BluetoothGattStatus aStatus, int aServerIf);
-
-  virtual void
-  RegisterServerNotification(BluetoothGattStatus aStatus,
-                             int aServerIf,
-                             const BluetoothUuid& aAppUuid);
-
-  virtual void
-  ConnectionNotification(int aConnId,
-                         int aServerIf,
-                         bool aConnected,
-                         const BluetoothAddress& aBdAddr);
-
-  virtual void
-  ServiceAddedNotification(BluetoothGattStatus aStatus,
-                           int aServerIf,
-                           const BluetoothGattServiceId& aServiceId,
-                           const BluetoothAttributeHandle& aServiceHandle);
-
-  virtual void
-  IncludedServiceAddedNotification(
-    BluetoothGattStatus aStatus,
-    int aServerIf,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aIncludedServiceHandle);
-
-  virtual void
-  CharacteristicAddedNotification(
-    BluetoothGattStatus aStatus,
-    int aServerIf,
-    const BluetoothUuid& aCharId,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aCharacteristicHandle);
-
-  virtual void
-  DescriptorAddedNotification(
-    BluetoothGattStatus aStatus,
-    int aServerIf,
-    const BluetoothUuid& aCharId,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aDescriptorHandle);
-
-  virtual void
-  ServiceStartedNotification(BluetoothGattStatus aStatus,
-                             int aServerIf,
-                             const BluetoothAttributeHandle& aServiceHandle);
-
-  virtual void
-  ServiceStoppedNotification(BluetoothGattStatus aStatus,
-                             int aServerIf,
-                             const BluetoothAttributeHandle& aServiceHandle);
-
-  virtual void
-  ServiceDeletedNotification(BluetoothGattStatus aStatus,
-                             int aServerIf,
-                             const BluetoothAttributeHandle& aServiceHandle);
-
-  virtual void
-  RequestReadNotification(int aConnId,
-                          int aTransId,
-                          const BluetoothAddress& aBdAddr,
-                          const BluetoothAttributeHandle& aAttributeHandle,
-                          int aOffset,
-                          bool aIsLong);
-
-  virtual void
-  RequestWriteNotification(int aConnId,
-                           int aTransId,
-                           const BluetoothAddress& aBdAddr,
-                           const BluetoothAttributeHandle& aAttributeHandle,
-                           int aOffset,
-                           int aLength,
-                           const uint8_t* aValue,
-                           bool aNeedResponse,
-                           bool aIsPrepareWrite);
-
-  virtual void
-  RequestExecuteWriteNotification(int aConnId,
-                                  int aTransId,
-                                  const BluetoothAddress& aBdAddr,
-                                  bool aExecute); /* true: execute */
-                                                  /* false: cancel */
-
-  virtual void
-  ResponseConfirmationNotification(BluetoothGattStatus aStatus,
-                                   int aHandle);
-
-  virtual void
-  IndicationSentNotification(int aConnId,
-                             BluetoothGattStatus aStatus);
-
-  virtual void
-  CongestionNotification(int aConnId,
-                         bool aCongested);
-
-  virtual void
-  MtuChangedNotification(int aConnId,
-                         int aMtu);
-
-protected:
-  BluetoothGattNotificationHandler();
-  virtual ~BluetoothGattNotificationHandler();
-};
-
-class BluetoothGattResultHandler
-  : public mozilla::ipc::DaemonSocketResultHandler
-{
-public:
-  virtual void OnError(BluetoothStatus aStatus);
-
-  virtual void RegisterClient();
-  virtual void UnregisterClient();
-
-  virtual void Scan();
-
-  virtual void Connect();
-  virtual void Disconnect();
-
-  virtual void Listen();
-  virtual void Refresh();
-
-  virtual void SearchService();
-  virtual void GetIncludedService();
-  virtual void GetCharacteristic();
-  virtual void GetDescriptor();
-
-  virtual void ReadCharacteristic();
-  virtual void WriteCharacteristic();
-  virtual void ReadDescriptor();
-  virtual void WriteDescriptor();
-
-  virtual void ExecuteWrite();
-
-  virtual void RegisterNotification();
-  virtual void DeregisterNotification();
-
-  virtual void ReadRemoteRssi();
-  virtual void GetDeviceType(BluetoothTypeOfDevice aType);
-  virtual void SetAdvData();
-  virtual void TestCommand();
-
-  virtual void RegisterServer();
-  virtual void UnregisterServer();
-
-  virtual void ConnectPeripheral();
-  virtual void DisconnectPeripheral();
-
-  virtual void AddService();
-  virtual void AddIncludedService();
-  virtual void AddCharacteristic();
-  virtual void AddDescriptor();
-
-  virtual void StartService();
-  virtual void StopService();
-  virtual void DeleteService();
-
-  virtual void SendIndication();
-
-  virtual void SendResponse();
-
-protected:
-  virtual ~BluetoothGattResultHandler() { }
-};
-
-class BluetoothGattInterface
-{
-public:
-  virtual void SetNotificationHandler(
-    BluetoothGattNotificationHandler* aNotificationHandler) = 0;
-
-  /* Register / Unregister */
-  virtual void RegisterClient(const BluetoothUuid& aUuid,
-                              BluetoothGattResultHandler* aRes) = 0;
-  virtual void UnregisterClient(int aClientIf,
-                                BluetoothGattResultHandler* aRes) = 0;
-
-  /* Start / Stop LE Scan */
-  virtual void Scan(int aClientIf, bool aStart,
-                    BluetoothGattResultHandler* aRes) = 0;
-
-  /* Connect / Disconnect */
-  virtual void Connect(int aClientIf,
-                       const BluetoothAddress& aBdAddr,
-                       bool aIsDirect, /* auto connect */
-                       BluetoothTransport aTransport,
-                       BluetoothGattResultHandler* aRes) = 0;
-  virtual void Disconnect(int aClientIf,
-                          const BluetoothAddress& aBdAddr,
-                          int aConnId,
-                          BluetoothGattResultHandler* aRes) = 0;
-
-  /* Start / Stop advertisements to listen for incoming connections */
-  virtual void Listen(int aClientIf,
-                      bool aIsStart,
-                      BluetoothGattResultHandler* aRes) = 0;
-
-  /* Clear the attribute cache for a given device*/
-  virtual void Refresh(int aClientIf,
-                       const BluetoothAddress& aBdAddr,
-                       BluetoothGattResultHandler* aRes) = 0;
-
-  /* Enumerate Attributes */
-  virtual void SearchService(int aConnId,
-                             bool aSearchAll,
-                             const BluetoothUuid& aUuid,
-                             BluetoothGattResultHandler* aRes) = 0;
-  virtual void GetIncludedService(
-    int aConnId,
-    const BluetoothGattServiceId& aServiceId,
-    bool aFirst,
-    const BluetoothGattServiceId& aStartServiceId,
-    BluetoothGattResultHandler* aRes) = 0;
-  virtual void GetCharacteristic(int aConnId,
-                                 const BluetoothGattServiceId& aServiceId,
-                                 bool aFirst,
-                                 const BluetoothGattId& aStartCharId,
-                                 BluetoothGattResultHandler* aRes) = 0;
-  virtual void GetDescriptor(int aConnId,
-                             const BluetoothGattServiceId& aServiceId,
-                             const BluetoothGattId& aCharId,
-                             bool aFirst,
-                             const BluetoothGattId& aDescriptorId,
-                             BluetoothGattResultHandler* aRes) = 0;
-
-  /* Read / Write An Attribute */
-  virtual void ReadCharacteristic(int aConnId,
-                                  const BluetoothGattServiceId& aServiceId,
-                                  const BluetoothGattId& aCharId,
-                                  BluetoothGattAuthReq aAuthReq,
-                                  BluetoothGattResultHandler* aRes) = 0;
-  virtual void WriteCharacteristic(int aConnId,
-                                   const BluetoothGattServiceId& aServiceId,
-                                   const BluetoothGattId& aCharId,
-                                   BluetoothGattWriteType aWriteType,
-                                   BluetoothGattAuthReq aAuthReq,
-                                   const nsTArray<uint8_t>& aValue,
-                                   BluetoothGattResultHandler* aRes) = 0;
-  virtual void ReadDescriptor(int aConnId,
-                              const BluetoothGattServiceId& aServiceId,
-                              const BluetoothGattId& aCharId,
-                              const BluetoothGattId& aDescriptorId,
-                              BluetoothGattAuthReq aAuthReq,
-                              BluetoothGattResultHandler* aRes) = 0;
-  virtual void WriteDescriptor(int aConnId,
-                               const BluetoothGattServiceId& aServiceId,
-                               const BluetoothGattId& aCharId,
-                               const BluetoothGattId& aDescriptorId,
-                               BluetoothGattWriteType aWriteType,
-                               BluetoothGattAuthReq aAuthReq,
-                               const nsTArray<uint8_t>& aValue,
-                               BluetoothGattResultHandler* aRes) = 0;
-
-  /* Execute / Abort Prepared Write*/
-  virtual void ExecuteWrite(int aConnId,
-                            int aIsExecute,
-                            BluetoothGattResultHandler* aRes) = 0;
-
-  /* Register / Deregister Characteristic Notifications or Indications */
-  virtual void RegisterNotification(
-    int aClientIf,
-    const BluetoothAddress& aBdAddr,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharId,
-    BluetoothGattResultHandler* aRes) = 0;
-  virtual void DeregisterNotification(
-    int aClientIf,
-    const BluetoothAddress& aBdAddr,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharId,
-    BluetoothGattResultHandler* aRes) = 0;
-
-  virtual void ReadRemoteRssi(int aClientIf,
-                              const BluetoothAddress& aBdAddr,
-                              BluetoothGattResultHandler* aRes) = 0;
-
-  virtual void GetDeviceType(const BluetoothAddress& aBdAddr,
-                             BluetoothGattResultHandler* aRes) = 0;
-
-  /* Set advertising data or scan response data */
-  virtual void SetAdvData(int aServerIf,
-                          bool aIsScanRsp,
-                          bool aIsNameIncluded,
-                          bool aIsTxPowerIncluded,
-                          int aMinInterval,
-                          int aMaxInterval,
-                          int aApperance,
-                          const nsTArray<uint8_t>& aManufacturerData,
-                          const nsTArray<uint8_t>& aServiceData,
-                          const nsTArray<BluetoothUuid>& aServiceUuids,
-                          BluetoothGattResultHandler* aRes) = 0;
-
-  virtual void TestCommand(int aCommand,
-                           const BluetoothGattTestParam& aTestParam,
-                           BluetoothGattResultHandler* aRes) = 0;
-
-  /* Register / Unregister */
-  virtual void RegisterServer(const BluetoothUuid& aUuid,
-                              BluetoothGattResultHandler* aRes) = 0;
-  virtual void UnregisterServer(int aServerIf,
-                                BluetoothGattResultHandler* aRes) = 0;
-
-  /* Connect / Disconnect */
-  virtual void ConnectPeripheral(int aServerIf,
-                                 const BluetoothAddress& aBdAddr,
-                                 bool aIsDirect, /* auto connect */
-                                 BluetoothTransport aTransport,
-                                 BluetoothGattResultHandler* aRes) = 0;
-  virtual void DisconnectPeripheral(int aServerIf,
-                                    const BluetoothAddress& aBdAddr,
-                                    int aConnId,
-                                    BluetoothGattResultHandler* aRes) = 0;
-
-  /* Add a services / a characteristic / a descriptor */
-  virtual void AddService(int aServerIf,
-                          const BluetoothGattServiceId& aServiceId,
-                          uint16_t aNumHandles,
-                          BluetoothGattResultHandler* aRes) = 0;
-  virtual void AddIncludedService(
-    int aServerIf,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aIncludedServiceHandle,
-    BluetoothGattResultHandler* aRes) = 0;
-  virtual void AddCharacteristic(int aServerIf,
-                                 const BluetoothAttributeHandle& aServiceHandle,
-                                 const BluetoothUuid& aUuid,
-                                 BluetoothGattCharProp aProperties,
-                                 BluetoothGattAttrPerm aPermissions,
-                                 BluetoothGattResultHandler* aRes) = 0;
-  virtual void AddDescriptor(int aServerIf,
-                             const BluetoothAttributeHandle& aServiceHandle,
-                             const BluetoothUuid& aUuid,
-                             BluetoothGattAttrPerm aPermissions,
-                             BluetoothGattResultHandler* aRes) = 0;
-
-  /* Start / Stop / Delete a service */
-  virtual void StartService(int aServerIf,
-                            const BluetoothAttributeHandle& aServiceHandle,
-                            BluetoothTransport aTransport,
-                            BluetoothGattResultHandler* aRes) = 0;
-  virtual void StopService(int aServerIf,
-                           const BluetoothAttributeHandle& aServiceHandle,
-                           BluetoothGattResultHandler* aRes) = 0;
-  virtual void DeleteService(int aServerIf,
-                             const BluetoothAttributeHandle& aServiceHandle,
-                             BluetoothGattResultHandler* aRes) = 0;
-
-  /* Send an indication or a notification */
-  virtual void SendIndication(
-    int aServerIf,
-    const BluetoothAttributeHandle& aCharacteristicHandle,
-    int aConnId,
-    const nsTArray<uint8_t>& aValue,
-    bool aConfirm, /* true: indication; false: notification */
-    BluetoothGattResultHandler* aRes) = 0;
-
-  /* Send a response for an incoming indication */
-  virtual void SendResponse(int aConnId,
-                            int aTransId,
-                            uint16_t aStatus,
-                            const BluetoothGattResponse& aResponse,
-                            BluetoothGattResultHandler* aRes) = 0;
-
-protected:
-  BluetoothGattInterface();
-  virtual ~BluetoothGattInterface();
-};
-
-//
-// Bluetooth Interface
-//
-
-class BluetoothNotificationHandler
-{
-public:
-  virtual void BackendErrorNotification(bool aCrashed);
-
-protected:
-  BluetoothNotificationHandler();
-  virtual ~BluetoothNotificationHandler();
-};
-
-class BluetoothResultHandler
-  : public mozilla::ipc::DaemonSocketResultHandler
-{
-public:
-  virtual void OnError(BluetoothStatus aStatus);
-
-  virtual void Init();
-  virtual void Cleanup();
-
-protected:
-  virtual ~BluetoothResultHandler() { }
-};
-
-class BluetoothInterface
-{
-public:
-  static BluetoothInterface* GetInstance();
-
-  virtual void Init(BluetoothNotificationHandler* aNotificationHandler,
-                    BluetoothResultHandler* aRes) = 0;
-  virtual void Cleanup(BluetoothResultHandler* aRes) = 0;
-
-  /* Profile Interfaces */
-
-  virtual BluetoothSetupInterface* GetBluetoothSetupInterface() = 0;
-  virtual BluetoothCoreInterface* GetBluetoothCoreInterface() = 0;
-  virtual BluetoothSocketInterface* GetBluetoothSocketInterface() = 0;
-  virtual BluetoothHandsfreeInterface* GetBluetoothHandsfreeInterface() = 0;
-  virtual BluetoothA2dpInterface* GetBluetoothA2dpInterface() = 0;
-  virtual BluetoothAvrcpInterface* GetBluetoothAvrcpInterface() = 0;
-  virtual BluetoothGattInterface* GetBluetoothGattInterface() = 0;
-  virtual BluetoothHidInterface* GetBluetoothHidInterface() = 0;
-
-protected:
-  BluetoothInterface();
-  virtual ~BluetoothInterface();
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothInterface_h
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothProfileController.cpp
+++ /dev/null
@@ -1,363 +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 "BluetoothProfileController.h"
-
-#include "BluetoothA2dpManager.h"
-#include "BluetoothAvrcpManager.h"
-#include "BluetoothHfpManager.h"
-#include "BluetoothHidManager.h"
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-#include "BluetoothUtils.h"
-
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "nsComponentManagerUtils.h"
-
-USING_BLUETOOTH_NAMESPACE
-
-#define BT_LOGR_PROFILE(mgr, msg, ...)               \
-  do {                                               \
-    nsCString name;                                  \
-    mgr->GetName(name);                              \
-    BT_LOGR("[%s] " msg, name.get(), ##__VA_ARGS__); \
-  } while(0)
-
-#define CONNECTION_TIMEOUT_MS 15000
-
-class CheckProfileStatusCallback : public nsITimerCallback
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSITIMERCALLBACK
-
-  CheckProfileStatusCallback(BluetoothProfileController* aController)
-    : mController(aController)
-  {
-    MOZ_ASSERT(aController);
-  }
-
-private:
-  virtual ~CheckProfileStatusCallback()
-  {
-    mController = nullptr;
-  }
-
-  RefPtr<BluetoothProfileController> mController;
-};
-
-BluetoothProfileController::BluetoothProfileController(
-                                   bool aConnect,
-                                   const BluetoothAddress& aDeviceAddress,
-                                   BluetoothReplyRunnable* aRunnable,
-                                   BluetoothProfileControllerCallback aCallback,
-                                   uint16_t aServiceUuid,
-                                   uint32_t aCod)
-  : mConnect(aConnect)
-  , mDeviceAddress(aDeviceAddress)
-  , mRunnable(aRunnable)
-  , mCallback(aCallback)
-  , mCurrentProfileFinished(false)
-  , mSuccess(false)
-  , mProfilesIndex(-1)
-{
-  MOZ_ASSERT(!aDeviceAddress.IsCleared());
-  MOZ_ASSERT(aRunnable);
-  MOZ_ASSERT(aCallback);
-
-  mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
-  MOZ_ASSERT(mTimer);
-
-  mProfiles.Clear();
-
-  /**
-   * If the service uuid is not specified, either connect multiple profiles
-   * based on Cod, or disconnect all connected profiles.
-   */
-  if (!aServiceUuid) {
-    mTarget.cod = aCod;
-    SetupProfiles(false);
-  } else {
-    BluetoothServiceClass serviceClass =
-      BluetoothUuidHelper::GetBluetoothServiceClass(aServiceUuid);
-    mTarget.service = serviceClass;
-    SetupProfiles(true);
-  }
-}
-
-BluetoothProfileController::~BluetoothProfileController()
-{
-  mProfiles.Clear();
-  mRunnable = nullptr;
-  mCallback = nullptr;
-
-  if (mTimer) {
-    mTimer->Cancel();
-  }
-}
-
-void
-BluetoothProfileController::AddProfileWithServiceClass(
-                                                   BluetoothServiceClass aClass)
-{
-  BluetoothProfileManagerBase* profile;
-  switch (aClass) {
-    case BluetoothServiceClass::HANDSFREE:
-    case BluetoothServiceClass::HEADSET:
-      profile = BluetoothHfpManager::Get();
-      break;
-    case BluetoothServiceClass::A2DP:
-      profile = BluetoothA2dpManager::Get();
-      break;
-    case BluetoothServiceClass::AVRCP:
-      profile = BluetoothAvrcpManager::Get();
-      break;
-    case BluetoothServiceClass::HID:
-      profile = BluetoothHidManager::Get();
-      break;
-    default:
-      DispatchReplyError(mRunnable, NS_LITERAL_STRING(ERR_UNKNOWN_PROFILE));
-      mCallback();
-      return;
-  }
-
-  AddProfile(profile);
-}
-
-void
-BluetoothProfileController::AddProfile(BluetoothProfileManagerBase* aProfile,
-                                       bool aCheckConnected)
-{
-  if (!aProfile) {
-    DispatchReplyError(mRunnable, NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
-    mCallback();
-    return;
-  }
-
-  if (aCheckConnected && !aProfile->IsConnected()) {
-    BT_WARNING("The profile is not connected.");
-    return;
-  }
-
-  mProfiles.AppendElement(aProfile);
-}
-
-void
-BluetoothProfileController::SetupProfiles(bool aAssignServiceClass)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /**
-   * When a service class is assigned, only its corresponding profile is put
-   * into array.
-   */
-  if (aAssignServiceClass) {
-    AddProfileWithServiceClass(mTarget.service);
-    return;
-  }
-
-  // For a disconnect request, all connected profiles are put into array.
-  if (!mConnect) {
-    AddProfile(BluetoothHidManager::Get(), true);
-    AddProfile(BluetoothAvrcpManager::Get(), true);
-    AddProfile(BluetoothA2dpManager::Get(), true);
-    AddProfile(BluetoothHfpManager::Get(), true);
-    return;
-  }
-
-  /**
-   * For a connect request, put multiple profiles into array and connect to
-   * all of them sequencely.
-   */
-  bool hasAudio = HAS_AUDIO(mTarget.cod);
-  bool hasRendering = HAS_RENDERING(mTarget.cod);
-  bool isPeripheral = IS_PERIPHERAL(mTarget.cod);
-  bool isRemoteControl = IS_REMOTE_CONTROL(mTarget.cod);
-  bool isKeyboard = IS_KEYBOARD(mTarget.cod);
-  bool isPointingDevice = IS_POINTING_DEVICE(mTarget.cod);
-  bool isInvalid = IS_INVALID(mTarget.cod);
-
-  // The value of CoD is invalid. Since the device didn't declare its class of
-  // device properly, we assume the device may support all of these profiles.
-  // Note the invalid CoD from bluedroid callback usually results from
-  // NFC-triggered direct pairing for no EIR query records.
-  if (isInvalid) {
-    AddProfile(BluetoothHfpManager::Get());
-    AddProfile(BluetoothA2dpManager::Get());
-    AddProfile(BluetoothAvrcpManager::Get()); // register after A2DP
-    AddProfile(BluetoothHidManager::Get());
-    return;
-  }
-
-  NS_ENSURE_TRUE_VOID(hasAudio || hasRendering || isPeripheral);
-
-  // Audio bit should be set if remote device supports HFP/HSP.
-  if (hasAudio) {
-    AddProfile(BluetoothHfpManager::Get());
-  }
-
-  // Rendering bit should be set if remote device supports A2DP.
-  if (hasRendering) {
-    AddProfile(BluetoothA2dpManager::Get());
-  }
-
-  // A remote control may either support HID or AVRCP since class of device
-  // value are the same. So we can only differentiate between AVRCP and HID
-  // by using hasRendering bit.
-  if ((isPeripheral && isRemoteControl)) {
-    if (hasRendering) {
-      AddProfile(BluetoothAvrcpManager::Get());
-    } else {
-      AddProfile(BluetoothHidManager::Get());
-    }
-  }
-
-  // A device which supports HID should claim that it's a peripheral and it's
-  // either a keyboard, a pointing device, or both.
-  if (isPeripheral && (isKeyboard || isPointingDevice)) {
-    AddProfile(BluetoothHidManager::Get());
-  }
-}
-
-NS_IMPL_ISUPPORTS(CheckProfileStatusCallback, nsITimerCallback)
-
-NS_IMETHODIMP
-CheckProfileStatusCallback::Notify(nsITimer* aTimer)
-{
-  MOZ_ASSERT(mController);
-  // Continue on the next profile since we haven't got the callback after
-  // timeout.
-  mController->GiveupAndContinue();
-
-  return NS_OK;
-}
-
-void
-BluetoothProfileController::StartSession()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mProfilesIndex == -1);
-  MOZ_ASSERT(mTimer);
-
-  if (!IsBtServiceAvailable()) {
-    EndSession();
-    return;
-  }
-
-  if (mProfiles.Length() < 1) {
-    BT_LOGR("No queued profile.");
-    EndSession();
-    return;
-  }
-
-  if (mTimer) {
-    mTimer->InitWithCallback(new CheckProfileStatusCallback(this),
-                             CONNECTION_TIMEOUT_MS, nsITimer::TYPE_ONE_SHOT);
-  }
-
-  BT_LOGR("%s", mConnect ? "connecting" : "disconnecting");
-
-  Next();
-}
-
-void
-BluetoothProfileController::EndSession()
-{
-  MOZ_ASSERT(mRunnable && mCallback);
-
-  BT_LOGR("mSuccess %d", mSuccess);
-
-  // Don't have to check profile status and retrigger session after connection
-  // timeout, since session is end.
-  if (mTimer) {
-    mTimer->Cancel();
-  }
-
-  // The action has completed, so the DOM request should be replied then invoke
-  // the callback.
-  if (mSuccess) {
-    DispatchReplySuccess(mRunnable);
-  } else if (mConnect) {
-    DispatchReplyError(mRunnable, NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
-  } else {
-    DispatchReplyError(mRunnable, NS_LITERAL_STRING(ERR_DISCONNECTION_FAILED));
-  }
-
-  mCallback();
-}
-
-void
-BluetoothProfileController::Next()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mProfilesIndex < (int)mProfiles.Length());
-  MOZ_ASSERT(mTimer);
-
-  mCurrentProfileFinished = false;
-
-  if (!IsBtServiceAvailable()) {
-    EndSession();
-    return;
-  }
-
-  if (++mProfilesIndex >= (int)mProfiles.Length()) {
-    EndSession();
-    return;
-  }
-
-  BT_LOGR_PROFILE(mProfiles[mProfilesIndex], "");
-
-  if (mConnect) {
-    mProfiles[mProfilesIndex]->Connect(mDeviceAddress, this);
-  } else {
-    mProfiles[mProfilesIndex]->Disconnect(this);
-  }
-}
-
-bool
-BluetoothProfileController::IsBtServiceAvailable() const
-{
-  BluetoothService* bs = BluetoothService::Get();
-  return (bs && bs->IsEnabled() && !bs->IsToggling());
-}
-
-void
-BluetoothProfileController::NotifyCompletion(const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mTimer);
-  MOZ_ASSERT(mProfiles.Length() > 0);
-
-  BT_LOGR_PROFILE(mProfiles[mProfilesIndex], "<%s>",
-                  NS_ConvertUTF16toUTF8(aErrorStr).get());
-
-  mCurrentProfileFinished = true;
-
-  if (mTimer) {
-    mTimer->Cancel();
-  }
-
-  mSuccess |= aErrorStr.IsEmpty();
-
-  Next();
-}
-
-void
-BluetoothProfileController::GiveupAndContinue()
-{
-  MOZ_ASSERT(!mCurrentProfileFinished);
-  MOZ_ASSERT(mProfilesIndex < (int)mProfiles.Length());
-
-  BT_LOGR_PROFILE(mProfiles[mProfilesIndex], ERR_OPERATION_TIMEOUT);
-  mProfiles[mProfilesIndex]->Reset();
-
-  if (IsBtServiceAvailable()) {
-    Next();
-  } else {
-    EndSession();
-  }
-}
-
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothProfileController.h
+++ /dev/null
@@ -1,162 +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_BluetoothProfileController_h
-#define mozilla_dom_bluetooth_BluetoothProfileController_h
-
-#include "BluetoothUuidHelper.h"
-#include "nsCOMPtr.h"
-#include "nsISupportsImpl.h"
-#include "nsITimer.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-/*
- * Class of Device(CoD): 32-bit unsigned integer
- *
- *  31   24  23    13 12     8 7      2 1 0
- * |       | Major   | Major  | Minor  |   |
- * |       | service | device | device |   |
- * |       | class   | class  | class  |   |
- * |       |<- 11  ->|<- 5  ->|<- 6  ->|   |
- *
- * https://www.bluetooth.org/en-us/specification/assigned-numbers/baseband
- */
-
-// Bit 23 ~ Bit 13: Major service class
-#define GET_MAJOR_SERVICE_CLASS(cod) (((cod) & 0xffe000) >> 13)
-
-// Bit 12 ~ Bit 8: Major device class
-#define GET_MAJOR_DEVICE_CLASS(cod)  (((cod) & 0x1f00) >> 8)
-
-// Bit 7 ~ Bit 2: Minor device class
-#define GET_MINOR_DEVICE_CLASS(cod)  (((cod) & 0xfc) >> 2)
-
-// Audio: Major service class = 0x100 (Bit 21 is set)
-#define HAS_AUDIO(cod)               ((cod) & 0x200000)
-
-// Rendering: Major service class = 0x20 (Bit 18 is set)
-#define HAS_RENDERING(cod)           ((cod) & 0x40000)
-
-// Peripheral: Major device class = 0x5
-#define IS_PERIPHERAL(cod)           (GET_MAJOR_DEVICE_CLASS(cod) == 0x5)
-
-// Remote Control: sub-field of minor device class, Bit 5 ~ Bit 2 = 0x3
-#define IS_REMOTE_CONTROL(cod)       ((GET_MINOR_DEVICE_CLASS(cod) & 0xf) == 0x3)
-
-// Keyboard: sub-field of minor device class (Bit 6)
-#define IS_KEYBOARD(cod)             ((GET_MINOR_DEVICE_CLASS(cod) & 0x10) >> 4)
-
-// Pointing device: sub-field of minor device class (Bit 7)
-#define IS_POINTING_DEVICE(cod)      ((GET_MINOR_DEVICE_CLASS(cod) & 0x20) >> 5)
-
-/**
- * Check whether the value of CoD is invalid:
- * - Bit 31 ~ Bit 24 != 0x0, or
- * - CoD value is 0x1f00 (unclassified).
- *
- * According to Bluetooth core spec v4.1. Vol 2, Sec. 7.3, the data length of
- * CoD (class of device) is 3 bytes: the two least significant bits indicate
- * 'format type', and the following 22 bits indicate category of service class
- * and device type. As bluedroid stores CoD with uint32_t, the remaining 8 bits
- * (Bit 31 ~ Bit 24) should be unassigned.
- */
-#define IS_INVALID(cod)              ((cod) >> 24 || (cod) == 0x1f00)
-
-class BluetoothProfileManagerBase;
-class BluetoothReplyRunnable;
-typedef void (*BluetoothProfileControllerCallback)();
-
-class BluetoothProfileController final
-{
-  ~BluetoothProfileController();
-
-public:
-  NS_INLINE_DECL_REFCOUNTING(BluetoothProfileController)
-  /**
-   * @param aConnect:       If it's a connect request, the value should be set
-   *                        to true. For disconnect request, set it to false.
-   * @param aDeviceAddress: The address of remote device.
-   * @param aRunnable:      Once the controller has done, the runnable will be
-   *                        replied. When all connection/disconnection attemps
-   *                        have failed, an error is fired. In other words,
-   *                        reply a success if any attemp successes.
-   * @param aCallback:      The callback will be invoked after the runnable is
-   *                        replied.
-   * @param aServiceUuid:   Connect/Disconnect to the specified profile. Please
-   *                        see enum BluetoothServiceClass for valid value.
-   * @param aCod:           If aServiceUuid is not assigned, i.e. the value is
-   *                        0, the controller connect multiple profiles based on
-   *                        aCod or disconnect all connected profiles.
-   */
-  BluetoothProfileController(bool aConnect,
-                             const BluetoothAddress& aDeviceAddress,
-                             BluetoothReplyRunnable* aRunnable,
-                             BluetoothProfileControllerCallback aCallback,
-                             uint16_t aServiceUuid,
-                             uint32_t aCod = 0);
-
-  /**
-   * The controller starts connecting/disconnecting profiles one by one
-   * according to the order in array mProfiles.
-   */
-  void StartSession();
-
-  /**
-   * The original DOM request would be fired in this function.
-   */
-  void EndSession();
-
-  /**
-   * It would be invoked after connect/disconnect operation is completed.
-   * An error string would be returned when it fails.
-   */
-  void NotifyCompletion(const nsAString& aErrorStr);
-
-  /**
-   * It is invoked after a profile has reached timeout, reset mProfiles.
-   */
-  void GiveupAndContinue();
-
-private:
-  // Setup data member mProfiles
-  void SetupProfiles(bool aAssignServiceClass);
-
-  // Add profiles into array with/without checking connection status
-  void AddProfile(BluetoothProfileManagerBase* aProfile,
-                  bool aCheckConnected = false);
-
-  // Add specified profile into array
-  void AddProfileWithServiceClass(BluetoothServiceClass aClass);
-
-  // Connect/Disconnect next profile in the array
-  void Next();
-
-  // Is Bluetooth service available for profile connection/disconnection ?
-  bool IsBtServiceAvailable() const;
-
-  const bool mConnect;
-  BluetoothAddress mDeviceAddress;
-  RefPtr<BluetoothReplyRunnable> mRunnable;
-  BluetoothProfileControllerCallback mCallback;
-
-  bool mCurrentProfileFinished;
-  bool mSuccess;
-  int8_t mProfilesIndex;
-  nsTArray<BluetoothProfileManagerBase*> mProfiles;
-
-  // Either CoD or BluetoothServiceClass is assigned.
-  union {
-    uint32_t cod;
-    BluetoothServiceClass service;
-  } mTarget;
-
-  nsCOMPtr<nsITimer> mTimer;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothProfileController_h
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothProfileManagerBase.h
+++ /dev/null
@@ -1,112 +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_BluetoothProfileManagerBase_h
-#define mozilla_dom_bluetooth_BluetoothProfileManagerBase_h
-
-/**
- * Error Messages used in Bluetooth profiles
- *
- * These error messages would be sent to Gaia as an argument of onError event.
- */
-#define ERR_ALREADY_CONNECTED           "AlreadyConnectedError"
-#define ERR_ALREADY_DISCONNECTED        "AlreadyDisconnectedError"
-#define ERR_CONNECTION_FAILED           "ConnectionFailedError"
-#define ERR_DISCONNECTION_FAILED        "DisconnectionFailedError"
-#define ERR_NO_AVAILABLE_RESOURCE       "NoAvailableResourceError"
-#define ERR_REACHED_CONNECTION_LIMIT    "ReachedConnectionLimitError"
-#define ERR_SERVICE_CHANNEL_NOT_FOUND   "DeviceChannelRetrievalError"
-#define ERR_UNKNOWN_PROFILE             "UnknownProfileError"
-#define ERR_OPERATION_TIMEOUT           "OperationTimeout"
-
-#include "BluetoothCommon.h"
-#include "nsIObserver.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-class BluetoothProfileController;
-
-class BluetoothProfileResultHandler
-{
-public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BluetoothProfileResultHandler);
-
-  virtual void OnError(nsresult aResult) { }
-  virtual void Init() { }
-  virtual void Deinit() { }
-
-protected:
-  virtual ~BluetoothProfileResultHandler() { }
-};
-
-class BluetoothProfileManagerBase : public nsIObserver
-{
-public:
-  virtual void OnGetServiceChannel(const BluetoothAddress& aDeviceAddress,
-                                   const BluetoothUuid& aServiceUuid,
-                                   int aChannel) = 0;
-  virtual void OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress) = 0;
-
-  /**
-   * Return the address of the connected device.
-   */
-  virtual void GetAddress(BluetoothAddress& aDeviceAddress) = 0;
-
-  /**
-   * Return true if the profile is connected.
-   */
-  virtual bool IsConnected() = 0;
-
-  /**
-   * Connect to a specific remote device. When it has been done, the
-   * callback "OnConnect" will be invoked.
-   */
-  virtual void Connect(const BluetoothAddress& aDeviceAddress,
-                       BluetoothProfileController* aController) = 0;
-
-  /**
-   * Close the socket and then invoke the callback "OnDisconnect".
-   */
-  virtual void Disconnect(BluetoothProfileController* aController) = 0;
-
-  /**
-   * If it establishes/releases a connection successfully, the error string
-   * will be empty. Otherwise, the error string shows the failure reason.
-   */
-  virtual void OnConnect(const nsAString& aErrorStr) = 0;
-  virtual void OnDisconnect(const nsAString& aErrorStr) = 0;
-
-  /**
-   * Clean up profile resources and set mController as null.
-   */
-  virtual void Reset() = 0;
-
-  /**
-   * Return string of profile name.
-   */
-  virtual void GetName(nsACString& aName) = 0;
-};
-
-#define BT_DECL_PROFILE_MGR_BASE                                             \
-public:                                                                      \
-  NS_DECL_ISUPPORTS                                                          \
-  NS_DECL_NSIOBSERVER                                                        \
-  virtual void OnGetServiceChannel(const BluetoothAddress& aDeviceAddress,   \
-                                   const BluetoothUuid& aServiceUuid,        \
-                                   int aChannel) override;                   \
-  virtual void OnUpdateSdpRecords(                                           \
-    const BluetoothAddress& aDeviceAddress) override;                        \
-  virtual void GetAddress(BluetoothAddress& aDeviceAddress) override;        \
-  virtual bool IsConnected() override;                                       \
-  virtual void Connect(const BluetoothAddress& aDeviceAddress,               \
-                       BluetoothProfileController* aController) override;    \
-  virtual void Disconnect(BluetoothProfileController* aController) override; \
-  virtual void OnConnect(const nsAString& aErrorStr) override;               \
-  virtual void OnDisconnect(const nsAString& aErrorStr) override;            \
-  virtual void Reset() override;
-
-END_BLUETOOTH_NAMESPACE
-
-#endif  // mozilla_dom_bluetooth_BluetoothProfileManagerBase_h
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothReplyRunnable.cpp
+++ /dev/null
@@ -1,332 +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 "base/basictypes.h"
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothUtils.h"
-#include "DOMRequest.h"
-#include "nsContentUtils.h"
-#include "mozilla/dom/ScriptSettings.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/dom/Promise.h"
-#include "nsServiceManagerUtils.h"
-
-using namespace mozilla::dom;
-
-USING_BLUETOOTH_NAMESPACE
-
-BluetoothReplyRunnable::BluetoothReplyRunnable(nsIDOMDOMRequest* aReq,
-                                               Promise* aPromise)
-  : mPromise(aPromise)
-  , mDOMRequest(aReq)
-  , mErrorStatus(STATUS_FAIL)
-{}
-
-void
-BluetoothReplyRunnable::SetReply(BluetoothReply* aReply)
-{
-  mReply.reset(aReply);
-}
-
-void
-BluetoothReplyRunnable::ReleaseMembers()
-{
-  mDOMRequest = nullptr;
-  mPromise = nullptr;
-}
-
-BluetoothReplyRunnable::~BluetoothReplyRunnable()
-{}
-
-nsresult
-BluetoothReplyRunnable::FireReplySuccess(JS::Handle<JS::Value> aVal)
-{
-  MOZ_ASSERT(mReply->type() == BluetoothReply::TBluetoothReplySuccess);
-
-  // DOMRequest
-  if (mDOMRequest) {
-    nsCOMPtr<nsIDOMRequestService> rs =
-      do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
-    NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
-
-    return rs->FireSuccessAsync(mDOMRequest, aVal);
-  }
-
-  // Promise
-  if (mPromise) {
-    mPromise->MaybeResolve(aVal);
-  }
-
-  OnSuccessFired();
-  return NS_OK;
-}
-
-nsresult
-BluetoothReplyRunnable::FireErrorString()
-{
-  // DOMRequest
-  if (mDOMRequest) {
-    nsCOMPtr<nsIDOMRequestService> rs =
-      do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
-    NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
-
-    return rs->FireErrorAsync(mDOMRequest, mErrorString);
-  }
-
-  // Promise
-  if (mPromise) {
-    nsresult rv =
-      NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_BLUETOOTH, mErrorStatus);
-    mPromise->MaybeReject(rv);
-  }
-
-  OnErrorFired();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-BluetoothReplyRunnable::Run()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mReply);
-
-  JS::Rooted<JS::Value> v(RootingCx(), JS::UndefinedValue());
-
-  nsresult rv;
-  if (mReply->type() != BluetoothReply::TBluetoothReplySuccess) {
-    ParseErrorStatus();
-    rv = FireErrorString();
-  } else if (!ParseSuccessfulReply(&v)) {
-    rv = FireErrorString();
-  } else {
-    rv = FireReplySuccess(v);
-  }
-
-  if (NS_FAILED(rv)) {
-    BT_WARNING("Could not fire DOMRequest/Promise!");
-  }
-
-  ReleaseMembers();
-  MOZ_ASSERT(!mDOMRequest,
-             "mDOMRequest is still alive! Deriving class should call "
-             "BluetoothReplyRunnable::ReleaseMembers()!");
-  MOZ_ASSERT(!mPromise,
-             "mPromise is still alive! Deriving class should call "
-             "BluetoothReplyRunnable::ReleaseMembers()!");
-
-  return rv;
-}
-
-void
-BluetoothReplyRunnable::OnSuccessFired()
-{}
-
-void
-BluetoothReplyRunnable::OnErrorFired()
-{}
-
-void
-BluetoothReplyRunnable::ParseErrorStatus()
-{
-  MOZ_ASSERT(mReply);
-  MOZ_ASSERT(mReply->type() == BluetoothReply::TBluetoothReplyError);
-
-  if (mReply->get_BluetoothReplyError().errorStatus().type() ==
-      BluetoothErrorStatus::TBluetoothStatus) {
-    SetError(
-      mReply->get_BluetoothReplyError().errorString(),
-      mReply->get_BluetoothReplyError().errorStatus().get_BluetoothStatus());
-  } else {
-    SetError(mReply->get_BluetoothReplyError().errorString(), STATUS_FAIL);
-  }
-}
-
-BluetoothVoidReplyRunnable::BluetoothVoidReplyRunnable(nsIDOMDOMRequest* aReq,
-                                                       Promise* aPromise)
-  : BluetoothReplyRunnable(aReq, aPromise)
-{}
-
-BluetoothVoidReplyRunnable::~BluetoothVoidReplyRunnable()
-{}
-
-BluetoothReplyTaskQueue::SubReplyRunnable::SubReplyRunnable(
-  nsIDOMDOMRequest* aReq,
-  Promise* aPromise,
-  BluetoothReplyTaskQueue* aRootQueue)
-  : BluetoothReplyRunnable(aReq, aPromise)
-  , mRootQueue(aRootQueue)
-{}
-
-BluetoothReplyTaskQueue::SubReplyRunnable::~SubReplyRunnable()
-{}
-
-BluetoothReplyTaskQueue*
-BluetoothReplyTaskQueue::SubReplyRunnable::GetRootQueue() const
-{
-  return mRootQueue;
-}
-
-void
-BluetoothReplyTaskQueue::SubReplyRunnable::OnSuccessFired()
-{
-  mRootQueue->OnSubReplySuccessFired(this);
-}
-
-void
-BluetoothReplyTaskQueue::SubReplyRunnable::OnErrorFired()
-{
-  mRootQueue->OnSubReplyErrorFired(this);
-}
-
-BluetoothReplyTaskQueue::VoidSubReplyRunnable::VoidSubReplyRunnable(
-  nsIDOMDOMRequest* aReq,
-  Promise* aPromise,
-  BluetoothReplyTaskQueue* aRootQueue)
-  : BluetoothReplyTaskQueue::SubReplyRunnable(aReq, aPromise, aRootQueue)
-{}
-
-BluetoothReplyTaskQueue::VoidSubReplyRunnable::~VoidSubReplyRunnable()
-{}
-
-bool
-BluetoothReplyTaskQueue::VoidSubReplyRunnable::ParseSuccessfulReply(
-  JS::MutableHandle<JS::Value> aValue)
-{
-  aValue.setUndefined();
-  return true;
-}
-
-BluetoothReplyTaskQueue::SubTask::SubTask(
-  BluetoothReplyTaskQueue* aRootQueue,
-  SubReplyRunnable* aReply)
-  : mRootQueue(aRootQueue)
-  , mReply(aReply)
-{
-  if (!mReply) {
-    mReply = new VoidSubReplyRunnable(nullptr, nullptr, mRootQueue);
-  }
-}
-
-BluetoothReplyTaskQueue::SubTask::~SubTask()
-{}
-
-BluetoothReplyTaskQueue*
-BluetoothReplyTaskQueue::SubTask::GetRootQueue() const
-{
-  return mRootQueue;
-}
-
-BluetoothReplyTaskQueue::SubReplyRunnable*
-BluetoothReplyTaskQueue::SubTask::GetReply() const
-{
-  return mReply;
-}
-
-BluetoothReplyTaskQueue::BluetoothReplyTaskQueue(
-  BluetoothReplyRunnable* aReply)
-  : mReply(aReply)
-{}
-
-BluetoothReplyTaskQueue::~BluetoothReplyTaskQueue()
-{
-  Clear();
-}
-
-void
-BluetoothReplyTaskQueue::AppendTask(already_AddRefed<SubTask> aTask)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  RefPtr<SubTask> task(aTask);
-
-  if (task) {
-    mTasks.AppendElement(task.forget());
-  }
-}
-
-NS_IMETHODIMP
-BluetoothReplyTaskQueue::Run()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!mTasks.IsEmpty()) {
-    RefPtr<SubTask> task = mTasks[0];
-    mTasks.RemoveElementAt(0);
-
-    MOZ_ASSERT(task);
-
-    if (!task->Execute()) {
-      FireErrorReply();
-    }
-  }
-
-  return NS_OK;
-}
-
-void
-BluetoothReplyTaskQueue::OnSubReplySuccessFired(SubReplyRunnable* aSubReply)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aSubReply);
-
-  if (mTasks.IsEmpty()) {
-    FireSuccessReply();
-  } else {
-    if (NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(this)))) {
-      FireErrorReply();
-    }
-  }
-}
-
-void
-BluetoothReplyTaskQueue::OnSubReplyErrorFired(SubReplyRunnable* aSubReply)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aSubReply);
-
-  FireErrorReply();
-}
-
-void
-BluetoothReplyTaskQueue::FireSuccessReply()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (mReply) {
-    DispatchReplySuccess(mReply);
-  }
-  OnSuccessFired();
-  Clear();
-}
-
-void
-BluetoothReplyTaskQueue::FireErrorReply()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (mReply) {
-    DispatchReplyError(mReply, STATUS_FAIL);
-  }
-  OnErrorFired();
-  Clear();
-}
-
-void
-BluetoothReplyTaskQueue::OnSuccessFired()
-{}
-
-void
-BluetoothReplyTaskQueue::OnErrorFired()
-{}
-
-void
-BluetoothReplyTaskQueue::Clear()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mReply = nullptr;
-  mTasks.Clear();
-}
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothReplyRunnable.h
+++ /dev/null
@@ -1,202 +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_BluetoothReplyRunnable_h
-#define mozilla_dom_bluetooth_BluetoothReplyRunnable_h
-
-#include "BluetoothCommon.h"
-#include "js/Value.h"
-#include "mozilla/Attributes.h"
-#include "mozilla/UniquePtr.h"
-#include "nsThreadUtils.h"
-
-class nsIDOMDOMRequest;
-
-namespace mozilla {
-namespace dom {
-class Promise;
-}
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothReply;
-
-class BluetoothReplyRunnable : public Runnable
-{
-public:
-  NS_DECL_NSIRUNNABLE
-
-  BluetoothReplyRunnable(nsIDOMDOMRequest* aReq,
-                         Promise* aPromise = nullptr);
-
-  void SetReply(BluetoothReply* aReply);
-
-  void SetError(const nsAString& aErrorString,
-                const enum BluetoothStatus aErrorStatus = STATUS_FAIL)
-  {
-    mErrorString = aErrorString;
-    mErrorStatus = aErrorStatus;
-  }
-
-  virtual void ReleaseMembers();
-
-protected:
-  virtual ~BluetoothReplyRunnable();
-
-  virtual bool ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue) = 0;
-
-  virtual nsresult FireErrorString();
-
-  // This is an autoptr so we don't have to bring the ipdl include into the
-  // header. We assume we'll only be running this once and it should die on
-  // scope out of Run() anyways.
-  UniquePtr<BluetoothReply> mReply;
-
-  RefPtr<Promise> mPromise;
-
-private:
-  virtual void ParseErrorStatus();
-
-  nsresult FireReplySuccess(JS::Handle<JS::Value> aVal);
-
-  virtual void OnSuccessFired();
-  virtual void OnErrorFired();
-
-  /**
-   * Either mDOMRequest or mPromise is not nullptr to reply applications
-   * success or error string. One special case is internal IPC that require
-   * neither mDOMRequest nor mPromise to reply applications.
-   * E.g., GetAdaptersTask triggered by BluetoothManager
-   *
-   * TODO: remove mDOMRequest once all methods adopt Promise.
-   */
-  nsCOMPtr<nsIDOMDOMRequest> mDOMRequest;
-
-  BluetoothStatus mErrorStatus;
-  nsString mErrorString;
-};
-
-class BluetoothVoidReplyRunnable : public BluetoothReplyRunnable
-{
-public:
-  BluetoothVoidReplyRunnable(nsIDOMDOMRequest* aReq,
-                             Promise* aPromise = nullptr);
- ~BluetoothVoidReplyRunnable();
-
-protected:
-  virtual bool
-  ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue) override
-  {
-    aValue.setUndefined();
-    return true;
-  }
-};
-
-class BluetoothReplyTaskQueue : public Runnable
-{
-public:
-  NS_DECL_NSIRUNNABLE
-
-  class SubReplyRunnable : public BluetoothReplyRunnable
-  {
-  public:
-    SubReplyRunnable(nsIDOMDOMRequest* aReq,
-                     Promise* aPromise,
-                     BluetoothReplyTaskQueue* aRootQueue);
-    ~SubReplyRunnable();
-
-    BluetoothReplyTaskQueue* GetRootQueue() const;
-
-  private:
-    virtual void OnSuccessFired() override;
-    virtual void OnErrorFired() override;
-
-    RefPtr<BluetoothReplyTaskQueue> mRootQueue;
-  };
-  friend class BluetoothReplyTaskQueue::SubReplyRunnable;
-
-  class VoidSubReplyRunnable : public SubReplyRunnable
-  {
-  public:
-    VoidSubReplyRunnable(nsIDOMDOMRequest* aReq,
-                         Promise* aPromise,
-                         BluetoothReplyTaskQueue* aRootQueue);
-    ~VoidSubReplyRunnable();
-
-  protected:
-    virtual bool ParseSuccessfulReply(
-      JS::MutableHandle<JS::Value> aValue) override;
-  };
-
-  class SubTask
-  {
-    NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SubTask)
-  public:
-    SubTask(BluetoothReplyTaskQueue* aRootQueue,
-            SubReplyRunnable* aReply);
-
-    BluetoothReplyTaskQueue* GetRootQueue() const;
-    SubReplyRunnable* GetReply() const;
-
-    /*
-     * Use SubReplyRunnable as the reply runnable to execute the task.
-     *
-     * Example:
-     * <pre>
-     * <code>
-     * bool SomeInheritedSubTask::Execute()
-     * {
-     *   BluetoothService* bs = BluetoothService::Get();
-     *   if (!bs) {
-     *     return false;
-     *   }
-     *   bs->DoSomethingInternal(
-     *     aSomeParameter,
-     *     new SomeInheritedSubReplyRunnable(aSomeDOMRequest,
-     *                                       aSomePromise,
-     *                                       GetRootQueue()));
-     *   return true;
-     * }
-     * </code>
-     * </pre>
-     */
-    virtual bool Execute() = 0;
-
-  protected:
-    virtual ~SubTask();
-
-  private:
-    RefPtr<BluetoothReplyTaskQueue> mRootQueue;
-    RefPtr<SubReplyRunnable> mReply;
-  };
-
-  BluetoothReplyTaskQueue(BluetoothReplyRunnable* aReply);
-
-  void AppendTask(already_AddRefed<SubTask> aTask);
-
-protected:
-  ~BluetoothReplyTaskQueue();
-
-  void FireSuccessReply();
-  void FireErrorReply();
-
-private:
-  void Clear();
-
-  void OnSubReplySuccessFired(SubReplyRunnable* aSubReply);
-  void OnSubReplyErrorFired(SubReplyRunnable* aSubReply);
-
-  virtual void OnSuccessFired();
-  virtual void OnErrorFired();
-
-  RefPtr<BluetoothReplyRunnable> mReply;
-  nsTArray<RefPtr<SubTask>> mTasks;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothReplyRunnable_h
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothRilListener.cpp
+++ /dev/null
@@ -1,441 +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 "BluetoothRilListener.h"
-
-#include "BluetoothHfpManager.h"
-#include "nsIIccService.h"
-#include "nsIMobileConnectionInfo.h"
-#include "nsIMobileConnectionService.h"
-#include "nsITelephonyCallInfo.h"
-#include "nsITelephonyService.h"
-#include "nsServiceManagerUtils.h"
-#include "nsString.h"
-#include "nsQueryObject.h"
-
-USING_BLUETOOTH_NAMESPACE
-
-/**
- *  IccListener
- */
-NS_IMPL_ISUPPORTS(IccListener, nsIIccListener)
-
-NS_IMETHODIMP
-IccListener::NotifyIccInfoChanged()
-{
-  // mOwner would be set to nullptr only in the dtor of BluetoothRilListener
-  NS_ENSURE_TRUE(mOwner, NS_ERROR_FAILURE);
-
-  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-  NS_ENSURE_TRUE(hfp, NS_ERROR_FAILURE);
-
-  hfp->HandleIccInfoChanged(mOwner->mClientId);
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-IccListener::NotifyStkCommand(nsIStkProactiveCmd *aStkProactiveCmd)
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-IccListener::NotifyStkSessionEnd()
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-IccListener::NotifyCardStateChanged()
-{
-  return NS_OK;
-}
-
-bool
-IccListener::Listen(bool aStart)
-{
-  NS_ENSURE_TRUE(mOwner, false);
-
-  nsCOMPtr<nsIIccService> service =
-    do_GetService(ICC_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(service, false);
-
-  nsCOMPtr<nsIIcc> icc;
-  service->GetIccByServiceId(mOwner->mClientId, getter_AddRefs(icc));
-  NS_ENSURE_TRUE(icc, false);
-
-  nsresult rv;
-  if (aStart) {
-    rv = icc->RegisterListener(this);
-  } else {
-    rv = icc->UnregisterListener(this);
-  }
-
-  return NS_SUCCEEDED(rv);
-}
-
-void
-IccListener::SetOwner(BluetoothRilListener *aOwner)
-{
-  mOwner = aOwner;
-}
-
-/**
- *  MobileConnectionListener
- */
-NS_IMPL_ISUPPORTS(MobileConnectionListener, nsIMobileConnectionListener)
-
-NS_IMETHODIMP
-MobileConnectionListener::NotifyVoiceChanged()
-{
-  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-  NS_ENSURE_TRUE(hfp, NS_OK);
-
-  hfp->HandleVoiceConnectionChanged(mClientId);
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-MobileConnectionListener::NotifyDataChanged()
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-MobileConnectionListener::NotifyDataError(const nsAString & message)
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-MobileConnectionListener::NotifyCFStateChanged(uint16_t action,
-                                               uint16_t reason,
-                                               const nsAString& number,
-                                               uint16_t timeSeconds,
-                                               uint16_t serviceClass)
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-MobileConnectionListener::NotifyEmergencyCbModeChanged(bool active,
-                                                       uint32_t timeoutMs)
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-MobileConnectionListener::NotifyOtaStatusChanged(const nsAString & status)
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-MobileConnectionListener::NotifyRadioStateChanged()
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-MobileConnectionListener::NotifyClirModeChanged(uint32_t aMode)
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-MobileConnectionListener::NotifyLastKnownNetworkChanged()
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-MobileConnectionListener::NotifyLastKnownHomeNetworkChanged()
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-MobileConnectionListener::NotifyNetworkSelectionModeChanged()
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-MobileConnectionListener::NotifyDeviceIdentitiesChanged()
-{
-  return NS_OK;
-}
-
-bool
-MobileConnectionListener::Listen(bool aStart)
-{
-  nsCOMPtr<nsIMobileConnectionService> service =
-    do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(service, false);
-
-  nsCOMPtr<nsIMobileConnection> connection;
-  service->GetItemByServiceId(mClientId, getter_AddRefs(connection));
-  NS_ENSURE_TRUE(connection, false);
-
-  nsresult rv;
-  if (aStart) {
-    rv = connection->RegisterListener(this);
-  } else {
-    rv = connection->UnregisterListener(this);
-  }
-
-  return NS_SUCCEEDED(rv);
-}
-
-/**
- *  TelephonyListener Implementation
- */
-NS_IMPL_ISUPPORTS(TelephonyListener, nsITelephonyListener)
-
-/**
- * @param aSend A boolean indicates whether we need to notify headset or not
- */
-nsresult
-TelephonyListener::HandleCallInfo(nsITelephonyCallInfo* aInfo, bool aSend)
-{
-  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-  NS_ENSURE_TRUE(hfp, NS_ERROR_FAILURE);
-
-  uint32_t callIndex;
-  uint16_t callState;
-  nsAutoString number;
-  nsAutoString disconnectedReason;
-  bool isOutgoing;
-  bool isConference;
-
-  aInfo->GetCallIndex(&callIndex);
-  aInfo->GetCallState(&callState);
-  aInfo->GetNumber(number);
-  aInfo->GetDisconnectedReason(disconnectedReason);
-  aInfo->GetIsOutgoing(&isOutgoing);
-  aInfo->GetIsConference(&isConference);
-
-  // The disconnectedReason of a disconnected call must be nonempty no matter
-  // the call is disconnected for a normal reason or an error.
-  MOZ_ASSERT((callState != nsITelephonyService::CALL_STATE_DISCONNECTED ||
-              !disconnectedReason.IsEmpty()),
-             "disconnectedReason of an disconnected call must be nonempty.");
-  hfp->HandleCallStateChanged(callIndex, callState, disconnectedReason, number,
-                              isOutgoing, isConference, aSend);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-TelephonyListener::CallStateChanged(uint32_t aLength,
-                                    nsITelephonyCallInfo** aAllInfo)
-{
-  for (uint32_t i = 0; i < aLength; ++i) {
-    HandleCallInfo(aAllInfo[i], true);
-  }
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-TelephonyListener::EnumerateCallState(nsITelephonyCallInfo* aInfo)
-{
-  return HandleCallInfo(aInfo, false);
-}
-
-NS_IMETHODIMP
-TelephonyListener::EnumerateCallStateComplete()
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-TelephonyListener::SupplementaryServiceNotification(uint32_t aServiceId,
-                                                    int32_t aCallIndex,
-                                                    uint16_t aNotification)
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-TelephonyListener::NotifyConferenceError(const nsAString& aName,
-                                         const nsAString& aMessage)
-{
-  BT_WARNING(NS_ConvertUTF16toUTF8(aName).get());
-  BT_WARNING(NS_ConvertUTF16toUTF8(aMessage).get());
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-TelephonyListener::NotifyCdmaCallWaiting(uint32_t aServiceId,
-                                         const nsAString& aNumber,
-                                         uint16_t aNumberPresentation,
-                                         const nsAString& aName,
-                                         uint16_t aNamePresentation)
-{
-  BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
-  NS_ENSURE_TRUE(hfp, NS_ERROR_FAILURE);
-
-  hfp->UpdateSecondNumber(aNumber);
-
-  return NS_OK;
-}
-
-bool
-TelephonyListener::Listen(bool aStart)
-{
-  nsCOMPtr<nsITelephonyService> service =
-    do_GetService(TELEPHONY_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(service, false);
-
-  nsresult rv;
-  if (aStart) {
-    rv = service->RegisterListener(this);
-  } else {
-    rv = service->UnregisterListener(this);
-  }
-
-  return NS_SUCCEEDED(rv);
-}
-
-/**
- *  BluetoothRilListener
- */
-BluetoothRilListener::BluetoothRilListener()
-{
-  nsCOMPtr<nsIMobileConnectionService> service =
-    do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE_VOID(service);
-
-  // Query number of total clients (sim slots)
-  uint32_t numItems = 0;
-  if (NS_SUCCEEDED(service->GetNumItems(&numItems))) {
-    // Init MobileConnectionListener array and IccInfoListener
-    for (uint32_t i = 0; i < numItems; i++) {
-      mMobileConnListeners.AppendElement(new MobileConnectionListener(i));
-    }
-  }
-
-  mTelephonyListener = new TelephonyListener();
-  mIccListener = new IccListener();
-  mIccListener->SetOwner(this);
-
-  // Probe for available client
-  SelectClient();
-}
-
-BluetoothRilListener::~BluetoothRilListener()
-{
-  mIccListener->SetOwner(nullptr);
-}
-
-bool
-BluetoothRilListener::Listen(bool aStart)
-{
-  NS_ENSURE_TRUE(ListenMobileConnAndIccInfo(aStart), false);
-  NS_ENSURE_TRUE(mTelephonyListener->Listen(aStart), false);
-
-  return true;
-}
-
-void
-BluetoothRilListener::SelectClient()
-{
-  // Reset mClientId
-  mClientId = mMobileConnListeners.Length();
-
-  nsCOMPtr<nsIMobileConnectionService> service =
-    do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE_VOID(service);
-
-  for (uint32_t i = 0; i < mMobileConnListeners.Length(); i++) {
-    nsCOMPtr<nsIMobileConnection> connection;
-    service->GetItemByServiceId(i, getter_AddRefs(connection));
-    if (!connection) {
-      BT_WARNING("%s: Failed to get mobile connection", __FUNCTION__);
-      continue;
-    }
-
-    nsCOMPtr<nsIMobileConnectionInfo> voiceInfo;
-    connection->GetVoice(getter_AddRefs(voiceInfo));
-    if (!voiceInfo) {
-      BT_WARNING("%s: Failed to get voice connection info", __FUNCTION__);
-      continue;
-    }
-
-    nsString regState;
-    voiceInfo->GetState(regState);
-    if (regState.EqualsLiteral("registered")) {
-      // Found available client
-      mClientId = i;
-      return;
-    }
-  }
-}
-
-void
-BluetoothRilListener::ServiceChanged(uint32_t aClientId, bool aRegistered)
-{
-  // Stop listening
-  ListenMobileConnAndIccInfo(false);
-
-  /**
-   * aRegistered:
-   * - TRUE:  service becomes registered. We were listening to all clients
-   *          and one of them becomes available. Select it to listen.
-   * - FALSE: service becomes un-registered. The client we were listening
-   *          becomes unavailable. Select another registered one to listen.
-   */
-  if (aRegistered) {
-    mClientId = aClientId;
-  } else {
-    SelectClient();
-  }
-
-  // Restart listening
-  ListenMobileConnAndIccInfo(true);
-
-  BT_LOGD("%d client %d. new mClientId %d", aRegistered, aClientId,
-          (mClientId < mMobileConnListeners.Length()) ? mClientId : -1);
-}
-
-void
-BluetoothRilListener::EnumerateCalls()
-{
-  nsCOMPtr<nsITelephonyService> service =
-    do_GetService(TELEPHONY_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE_VOID(service);
-
-  nsCOMPtr<nsITelephonyListener> listener(
-    do_QueryObject(mTelephonyListener));
-
-  service->EnumerateCalls(listener);
-}
-
-bool
-BluetoothRilListener::ListenMobileConnAndIccInfo(bool aStart)
-{
-  /**
-   * mClientId < number of total clients:
-   *   The client with mClientId is available. Start/Stop listening
-   *   mobile connection and icc info of this client only.
-   *
-   * mClientId >= number of total clients:
-   *   All clients are unavailable. Start/Stop listening mobile
-   *   connections of all clients.
-   */
-  if (mClientId < mMobileConnListeners.Length()) {
-    NS_ENSURE_TRUE(mMobileConnListeners[mClientId]->Listen(aStart), false);
-    NS_ENSURE_TRUE(mIccListener->Listen(aStart), false);
-  } else {
-    for (uint32_t i = 0; i < mMobileConnListeners.Length(); i++) {
-      NS_ENSURE_TRUE(mMobileConnListeners[i]->Listen(aStart), false);
-    }
-  }
-
-  return true;
-}
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothRilListener.h
+++ /dev/null
@@ -1,137 +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_BluetoothRilListener_h
-#define mozilla_dom_bluetooth_BluetoothRilListener_h
-
-#include "BluetoothCommon.h"
-#include "nsIIccService.h"
-#include "nsIMobileConnectionService.h"
-#include "nsITelephonyCallInfo.h"
-#include "nsITelephonyService.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothRilListener;
-
-class IccListener : public nsIIccListener
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIICCLISTENER
-
-  IccListener() { }
-
-  bool Listen(bool aStart);
-  void SetOwner(BluetoothRilListener *aOwner);
-
-protected:
-  virtual ~IccListener() { }
-
-private:
-  BluetoothRilListener* mOwner;
-};
-
-class MobileConnectionListener : public nsIMobileConnectionListener
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIMOBILECONNECTIONLISTENER
-
-  MobileConnectionListener(uint32_t aClientId)
-  : mClientId(aClientId) { }
-
-  bool Listen(bool aStart);
-
-protected:
-  virtual ~MobileConnectionListener() { }
-
-private:
-  uint32_t mClientId;
-};
-
-class TelephonyListener : public nsITelephonyListener
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSITELEPHONYLISTENER
-
-  TelephonyListener() { }
-
-  bool Listen(bool aStart);
-
-protected:
-  virtual ~TelephonyListener() { }
-
-private:
-  nsresult HandleCallInfo(nsITelephonyCallInfo* aInfo, bool aSend);
-};
-
-class BluetoothRilListener
-{
-public:
-  BluetoothRilListener();
-  ~BluetoothRilListener();
-
-  /**
-   * Start/Stop listening.
-   *
-   * @param aStart [in] whether to start/stop listening
-   */
-  bool Listen(bool aStart);
-
-  /**
-   * Be informed that certain client's service has changed.
-   *
-   * @param aClientId   [in] the client id with service change
-   * @param aRegistered [in] whether changed service is registered
-   */
-  void ServiceChanged(uint32_t aClientId, bool aRegistered);
-
-  /**
-   * Enumerate current calls.
-   */
-  void EnumerateCalls();
-
-  /**
-   * The id of client that mobile connection and icc info listeners
-   * are listening to.
-   *
-   * mClientId equals to number of total clients (array length of
-   * mobile connection listeners) if there is no available client to listen.
-   */
-  uint32_t mClientId;
-
-private:
-  /**
-   * Start/Stop listening of mobile connection and icc info.
-   *
-   * @param aStart [in] whether to start/stop listening
-   */
-  bool ListenMobileConnAndIccInfo(bool aStart);
-
-  /**
-   * Select available client to listen and assign mClientId.
-   *
-   * mClientId is assigned to number of total clients (array length of
-   * mobile connection listeners) if there is no available client to listen.
-   */
-  void SelectClient();
-
-  /**
-   * Array of mobile connection listeners.
-   *
-   * The length equals to number of total clients.
-   */
-  nsTArray<RefPtr<MobileConnectionListener> > mMobileConnListeners;
-
-  RefPtr<IccListener> mIccListener;
-  RefPtr<TelephonyListener> mTelephonyListener;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothRilListener_h
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothService.cpp
+++ /dev/null
@@ -1,762 +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 "base/basictypes.h"
-
-#include "BluetoothService.h"
-
-#include "BluetoothCommon.h"
-#include "BluetoothParent.h"
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothServiceChildProcess.h"
-#include "BluetoothUtils.h"
-
-#include "jsapi.h"
-#include "mozilla/ClearOnShutdown.h"
-#include "mozilla/Services.h"
-#include "mozilla/StaticPtr.h"
-#include "mozilla/Unused.h"
-#include "mozilla/dom/BindingUtils.h"
-#include "mozilla/dom/ContentParent.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/dom/ipc/BlobChild.h"
-#include "mozilla/dom/ipc/BlobParent.h"
-#include "nsAutoPtr.h"
-#include "nsContentUtils.h"
-#include "nsIObserverService.h"
-#include "nsISettingsService.h"
-#include "nsISystemMessagesInternal.h"
-#include "nsITimer.h"
-#include "nsServiceManagerUtils.h"
-#include "nsXPCOM.h"
-#include "mozilla/dom/SettingChangeNotificationBinding.h"
-
-#if defined(MOZ_WIDGET_GONK)
-#include "cutils/properties.h"
-#endif
-
-#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_DAEMON)
-/**
- * B2G Bluetooth daemon:
- *   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.
- */
-#include "BluetoothDBusService.h"
-#else
-#error No backend
-#endif
-
-#define MOZSETTINGS_CHANGED_ID      "mozsettings-changed"
-#define BLUETOOTH_ENABLED_SETTING   "bluetooth.enabled"
-#define BLUETOOTH_DEBUGGING_SETTING "bluetooth.debugging.enabled"
-
-#define PROP_BLUETOOTH_ENABLED      "bluetooth.isEnabled"
-
-#define DEFAULT_SHUTDOWN_TIMER_MS 5000
-
-using namespace mozilla;
-using namespace mozilla::dom;
-USING_BLUETOOTH_NAMESPACE
-
-namespace {
-
-StaticRefPtr<BluetoothService> sBluetoothService;
-
-bool sInShutdown = false;
-bool sToggleInProgress = false;
-
-void
-ShutdownTimeExceeded(nsITimer* aTimer, void* aClosure)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  *static_cast<bool*>(aClosure) = true;
-}
-
-void
-GetAllBluetoothActors(InfallibleTArray<BluetoothParent*>& aActors)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aActors.IsEmpty());
-
-  AutoTArray<ContentParent*, 20> contentActors;
-  ContentParent::GetAll(contentActors);
-
-  for (uint32_t contentIndex = 0;
-       contentIndex < contentActors.Length();
-       contentIndex++) {
-    MOZ_ASSERT(contentActors[contentIndex]);
-
-    AutoTArray<PBluetoothParent*, 5> bluetoothActors;
-    contentActors[contentIndex]->ManagedPBluetoothParent(bluetoothActors);
-
-    for (uint32_t bluetoothIndex = 0;
-         bluetoothIndex < bluetoothActors.Length();
-         bluetoothIndex++) {
-      MOZ_ASSERT(bluetoothActors[bluetoothIndex]);
-
-      BluetoothParent* actor =
-        static_cast<BluetoothParent*>(bluetoothActors[bluetoothIndex]);
-      aActors.AppendElement(actor);
-    }
-  }
-}
-
-} // namespace
-
-BluetoothService::ToggleBtAck::ToggleBtAck(bool aEnabled)
-  : mEnabled(aEnabled)
-{ }
-
-NS_IMETHODIMP
-BluetoothService::ToggleBtAck::Run()
-{
-  BluetoothService::AcknowledgeToggleBt(mEnabled);
-
-  return NS_OK;
-}
-
-class BluetoothService::StartupTask final : public nsISettingsServiceCallback
-{
-public:
-  NS_DECL_ISUPPORTS
-
-  NS_IMETHOD Handle(const nsAString& aName, JS::Handle<JS::Value> aResult)
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (!aResult.isBoolean()) {
-      BT_WARNING("Setting for '" BLUETOOTH_ENABLED_SETTING "' is not a boolean!");
-      return NS_OK;
-    }
-
-    // It is theoretically possible to shut down before the first settings check
-    // has completed (though extremely unlikely).
-    if (sBluetoothService) {
-      return sBluetoothService->HandleStartupSettingsCheck(aResult.toBoolean());
-    }
-
-    return NS_OK;
-  }
-
-  NS_IMETHOD HandleError(const nsAString& aName)
-  {
-    BT_WARNING("Unable to get value for '" BLUETOOTH_ENABLED_SETTING "'");
-    return NS_OK;
-  }
-
-private:
-  ~StartupTask()
-  { }
-};
-
-NS_IMPL_ISUPPORTS(BluetoothService::StartupTask, nsISettingsServiceCallback);
-
-NS_IMPL_ISUPPORTS(BluetoothService, nsIObserver)
-
-bool
-BluetoothService::IsToggling() const
-{
-  return sToggleInProgress;
-}
-
-BluetoothService::~BluetoothService()
-{
-  Cleanup();
-}
-
-// static
-BluetoothService*
-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_DAEMON)
-  return new BluetoothServiceBluedroid();
-#endif
-#elif defined(MOZ_BLUETOOTH_DBUS)
-  return new BluetoothDBusService();
-#endif
-
-  BT_WARNING("No platform support for bluetooth!");
-  return nullptr;
-}
-
-bool
-BluetoothService::Init()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  NS_ENSURE_TRUE(obs, false);
-
-  if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
-                                 false))) {
-    BT_WARNING("Failed to add shutdown observer!");
-    return false;
-  }
-
-  // Only the main process should observe bluetooth settings changes.
-  if (XRE_IsParentProcess() &&
-      NS_FAILED(obs->AddObserver(this, MOZSETTINGS_CHANGED_ID, false))) {
-    BT_WARNING("Failed to add settings change observer!");
-    return false;
-  }
-
-  return true;
-}
-
-void
-BluetoothService::Cleanup()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
-  if (obs &&
-      (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) ||
-       NS_FAILED(obs->RemoveObserver(this, MOZSETTINGS_CHANGED_ID)))) {
-    BT_WARNING("Can't unregister observers!");
-  }
-}
-
-void
-BluetoothService::RegisterBluetoothSignalHandler(
-  const nsAString& aNodeName, BluetoothSignalObserver* aHandler)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aHandler);
-
-  BT_LOGD("[S] %s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(aNodeName).get());
-
-  BluetoothSignalObserverList* ol;
-  if (!mBluetoothSignalObserverTable.Get(aNodeName, &ol)) {
-    ol = new BluetoothSignalObserverList();
-    mBluetoothSignalObserverTable.Put(aNodeName, ol);
-  }
-
-  ol->AddObserver(aHandler);
-
-  // Distribute pending pairing requests when pairing listener has been added
-  // to signal observer table.
-  if (XRE_IsParentProcess() &&
-      !mPendingPairReqSignals.IsEmpty() &&
-      aNodeName.EqualsLiteral(KEY_PAIRING_LISTENER)) {
-    for (uint32_t i = 0; i < mPendingPairReqSignals.Length(); ++i) {
-      DistributeSignal(mPendingPairReqSignals[i]);
-    }
-    mPendingPairReqSignals.Clear();
-  }
-}
-
-void
-BluetoothService::UnregisterBluetoothSignalHandler(
-                                              const nsAString& aNodeName,
-                                              BluetoothSignalObserver* aHandler)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aHandler);
-
-  BT_LOGD("[S] %s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(aNodeName).get());
-
-  BluetoothSignalObserverList* ol;
-  if (mBluetoothSignalObserverTable.Get(aNodeName, &ol)) {
-    ol->RemoveObserver(aHandler);
-    // We shouldn't have duplicate instances in the ObserverList, but there's
-    // no appropriate way to do duplication check while registering, so
-    // assertions are added here.
-    MOZ_ASSERT(!ol->RemoveObserver(aHandler));
-    if (ol->Length() == 0) {
-      mBluetoothSignalObserverTable.Remove(aNodeName);
-    }
-  }
-  else {
-    BT_WARNING("Node was never registered!");
-  }
-}
-
-void
-BluetoothService::UnregisterAllSignalHandlers(BluetoothSignalObserver* aHandler)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aHandler);
-
-  for (auto iter = mBluetoothSignalObserverTable.Iter();
-       !iter.Done();
-       iter.Next()) {
-
-    // FIXME: Remove #include <nsAutoPtr.h> near the top
-    // of this file when the hash table has been converted
-    // to |UniquePtr<>|
-    nsAutoPtr<BluetoothSignalObserverList>& ol = iter.Data();
-
-    ol->RemoveObserver(aHandler);
-    // We shouldn't have duplicate instances in the ObserverList, but there's
-    // no appropriate way to do duplication check while registering, so
-    // assertions are added here.
-    MOZ_ASSERT(!ol->RemoveObserver(aHandler));
-    if (ol->Length() == 0) {
-      iter.Remove();
-    }
-  }
-}
-
-void
-BluetoothService::DistributeSignal(const nsAString& aName,
-                                   const nsAString& aPath)
-{
-  DistributeSignal(aName, aPath, BluetoothValue(true));
-}
-
-void
-BluetoothService::DistributeSignal(const nsAString& aName,
-                                   const nsAString& aPath,
-                                   const BluetoothValue& aValue)
-{
-  BluetoothSignal signal(nsString(aName), nsString(aPath), aValue);
-  DistributeSignal(signal);
-}
-
-void
-BluetoothService::DistributeSignal(const nsAString& aName,
-                                   const BluetoothAddress& aAddress)
-{
-  nsAutoString path;
-  AddressToString(aAddress, path);
-
-  DistributeSignal(aName, path);
-}
-
-void
-BluetoothService::DistributeSignal(const nsAString& aName,
-                                   const BluetoothAddress& aAddress,
-                                   const BluetoothValue& aValue)
-{
-  nsAutoString path;
-  AddressToString(aAddress, path);
-
-  DistributeSignal(aName, path, aValue);
-}
-
-void
-BluetoothService::DistributeSignal(const nsAString& aName,
-                                   const BluetoothUuid& aUuid)
-{
-  nsAutoString path;
-  UuidToString(aUuid, path);
-
-  DistributeSignal(aName, path);
-}
-
-void
-BluetoothService::DistributeSignal(const nsAString& aName,
-                                   const BluetoothUuid& aUuid,
-                                   const BluetoothValue& aValue)
-{
-  nsAutoString path;
-  UuidToString(aUuid, path);
-
-  DistributeSignal(aName, path, aValue);
-}
-
-void
-BluetoothService::DistributeSignal(const BluetoothSignal& aSignal)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  BluetoothSignalObserverList* ol;
-  if (!mBluetoothSignalObserverTable.Get(aSignal.path(), &ol)) {
-    // If there is no BluetoohPairingListener in observer table, put the signal
-    // into a pending queue of pairing requests and send a system message to
-    // launch bluetooth certified app.
-    if (aSignal.path().EqualsLiteral(KEY_PAIRING_LISTENER)) {
-      mPendingPairReqSignals.AppendElement(aSignal);
-
-      BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(
-        NS_LITERAL_STRING(SYS_MSG_BT_PAIRING_REQ),
-        BluetoothValue(EmptyString()));
-    } else {
-      BT_WARNING("No observer registered for path %s",
-                 NS_ConvertUTF16toUTF8(aSignal.path()).get());
-    }
-    return;
-  }
-
-  MOZ_ASSERT(ol->Length());
-  ol->Broadcast(aSignal);
-}
-
-nsresult
-BluetoothService::StartBluetooth(bool aIsStartup,
-                                 BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (sInShutdown) {
-    // Don't try to start if we're already shutting down.
-    MOZ_ASSERT(false, "Start called while in shutdown!");
-    return NS_ERROR_FAILURE;
-  }
-
-  /* When IsEnabled() is true, we don't switch on Bluetooth but we still
-   * send ToggleBtAck task. One special case happens at startup stage. At
-   * startup, the initialization of BluetoothService still has to be done
-   * even if Bluetooth is already enabled.
-   *
-   * Please see bug 892392 for more information.
-   */
-  if (aIsStartup || !IsEnabled()) {
-    // Switch Bluetooth on
-    nsresult rv = StartInternal(aRunnable);
-    if (NS_FAILED(rv)) {
-      BT_WARNING("Bluetooth service failed to start!");
-      return rv;
-    }
-  } else {
-    BT_WARNING("Bluetooth has already been enabled before.");
-    RefPtr<Runnable> runnable = new BluetoothService::ToggleBtAck(true);
-    if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
-      BT_WARNING("Failed to dispatch to main thread!");
-    }
-  }
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothService::StopBluetooth(bool aIsStartup,
-                                BluetoothReplyRunnable* aRunnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  /* When IsEnabled() is false, we don't switch off Bluetooth but we still
-   * send ToggleBtAck task. One special case happens at startup stage. At
-   * startup, the initialization of BluetoothService still has to be done
-   * even if Bluetooth is disabled.
-   *
-   * Please see bug 892392 for more information.
-   */
-  if (aIsStartup || IsEnabled()) {
-    // Any connected Bluetooth profile would be disconnected.
-    nsresult rv = StopInternal(aRunnable);
-    if (NS_FAILED(rv)) {
-      BT_WARNING("Bluetooth service failed to stop!");
-      return rv;
-    }
-  } else {
-    BT_WARNING("Bluetooth has already been enabled/disabled before.");
-    RefPtr<Runnable> runnable = new BluetoothService::ToggleBtAck(false);
-    if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
-      BT_WARNING("Failed to dispatch to main thread!");
-    }
-  }
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothService::StartStopBluetooth(bool aStart,
-                                     bool aIsStartup,
-                                     BluetoothReplyRunnable* aRunnable)
-{
-  nsresult rv;
-  if (aStart) {
-    rv = StartBluetooth(aIsStartup, aRunnable);
-  } else {
-    rv = StopBluetooth(aIsStartup, aRunnable);
-  }
-  return rv;
-}
-
-void
-BluetoothService::SetEnabled(bool aEnabled)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  AutoTArray<BluetoothParent*, 10> childActors;
-  GetAllBluetoothActors(childActors);
-
-  for (uint32_t index = 0; index < childActors.Length(); index++) {
-    Unused << childActors[index]->SendEnabled(aEnabled);
-  }
-
-  /**
-   * mEnabled: real status of bluetooth
-   * aEnabled: expected status of bluetooth
-   */
-  if (mEnabled == aEnabled) {
-    BT_WARNING("Bluetooth is already %s, or the toggling failed.",
-               mEnabled ? "enabled" : "disabled");
-  }
-
-  mEnabled = aEnabled;
-}
-
-nsresult
-BluetoothService::HandleStartup()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!sToggleInProgress);
-
-  nsCOMPtr<nsISettingsService> settings =
-    do_GetService("@mozilla.org/settingsService;1");
-  NS_ENSURE_TRUE(settings, NS_ERROR_UNEXPECTED);
-
-  nsCOMPtr<nsISettingsServiceLock> settingsLock;
-  nsresult rv = settings->CreateLock(nullptr, getter_AddRefs(settingsLock));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  RefPtr<StartupTask> callback = new StartupTask();
-  rv = settingsLock->Get(BLUETOOTH_ENABLED_SETTING, callback);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  sToggleInProgress = true;
-  return NS_OK;
-}
-
-nsresult
-BluetoothService::HandleStartupSettingsCheck(bool aEnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  return StartStopBluetooth(aEnable, true, nullptr);
-}
-
-nsresult
-BluetoothService::HandleSettingsChanged(nsISupports* aSubject)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // The string that we're interested in will be a JSON string that looks like:
-  //  {"key":"bluetooth.enabled","value":true}
-
-  RootedDictionary<SettingChangeNotification> setting(RootingCx());
-  if (!WrappedJSToDictionary(aSubject, setting)) {
-    return NS_OK;
-  }
-  if (!setting.mKey.EqualsASCII(BLUETOOTH_DEBUGGING_SETTING)) {
-    return NS_OK;
-  }
-  if (!setting.mValue.isBoolean()) {
-    MOZ_ASSERT(false, "Expecting a boolean for 'bluetooth.debugging.enabled'!");
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  SWITCH_BT_DEBUG(setting.mValue.toBoolean());
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothService::HandleShutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // This is a two phase shutdown. First we notify all child processes that
-  // bluetooth is going away, and then we wait for them to acknowledge. Then we
-  // close down all the bluetooth machinery.
-
-  Cleanup();
-
-  AutoTArray<BluetoothParent*, 10> childActors;
-  GetAllBluetoothActors(childActors);
-
-  if (!childActors.IsEmpty()) {
-    // Notify child processes that they should stop using bluetooth now.
-    for (uint32_t index = 0; index < childActors.Length(); index++) {
-      childActors[index]->BeginShutdown();
-    }
-
-    // Create a timer to ensure that we don't wait forever for a child process
-    // or the bluetooth threads to finish. If we don't get a timer or can't use
-    // it for some reason then we skip all the waiting entirely since we really
-    // can't afford to hang on shutdown.
-    nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID);
-    MOZ_ASSERT(timer);
-
-    if (timer) {
-      bool timeExceeded = false;
-
-      if (NS_SUCCEEDED(timer->InitWithFuncCallback(ShutdownTimeExceeded,
-                                                   &timeExceeded,
-                                                   DEFAULT_SHUTDOWN_TIMER_MS,
-                                                   nsITimer::TYPE_ONE_SHOT))) {
-        nsIThread* currentThread = NS_GetCurrentThread();
-        MOZ_ASSERT(currentThread);
-
-        // Wait for those child processes to acknowledge.
-        while (!timeExceeded && !childActors.IsEmpty()) {
-          if (!NS_ProcessNextEvent(currentThread)) {
-            MOZ_ASSERT(false, "Something horribly wrong here!");
-            break;
-          }
-          GetAllBluetoothActors(childActors);
-        }
-
-        if (NS_FAILED(timer->Cancel())) {
-          MOZ_CRASH("Failed to cancel shutdown timer, this will crash!");
-        }
-      }
-      else {
-        MOZ_ASSERT(false, "Failed to initialize shutdown timer!");
-      }
-    }
-  }
-
-  if (IsEnabled() && NS_FAILED(StopBluetooth(false, nullptr))) {
-    MOZ_ASSERT(false, "Failed to deliver stop message!");
-  }
-
-  return NS_OK;
-}
-
-// static
-BluetoothService*
-BluetoothService::Get()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // If we already exist, exit early
-  if (sBluetoothService) {
-    return sBluetoothService;
-  }
-
-  // If we're in shutdown, don't create a new instance
-  if (sInShutdown) {
-    BT_WARNING("BluetoothService can't be created during shutdown");
-    return nullptr;
-  }
-
-  // Create new instance, register, return
-  sBluetoothService = BluetoothService::Create();
-  NS_ENSURE_TRUE(sBluetoothService, nullptr);
-
-  if (!sBluetoothService->Init()) {
-    sBluetoothService->Cleanup();
-    return nullptr;
-  }
-
-  ClearOnShutdown(&sBluetoothService);
-  return sBluetoothService;
-}
-
-nsresult
-BluetoothService::Observe(nsISupports* aSubject, const char* aTopic,
-                          const char16_t* aData)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!strcmp(aTopic, "profile-after-change")) {
-    return HandleStartup();
-  }
-
-  if (!strcmp(aTopic, MOZSETTINGS_CHANGED_ID)) {
-    return HandleSettingsChanged(aSubject);
-  }
-
-  if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    /**
-     * |sInShutdown| flag should be set for instances created in content
-     * processes or parent processes. Please see bug 1199653 for detailed
-     * information.
-     */
-    sInShutdown = true;
-
-    return HandleShutdown();
-  }
-
-  MOZ_ASSERT(false, "BluetoothService got unexpected topic!");
-  return NS_ERROR_UNEXPECTED;
-}
-
-/**
- * Enable/Disable the local adapter.
- *
- * There is only one adapter on the mobile in current use cases.
- * In addition, bluedroid couldn't enable/disable a single adapter.
- * So currently we will turn on/off BT to enable/disable the adapter.
- *
- * TODO: To support enable/disable single adapter in the future,
- *       we will need to implement EnableDisableInternal for different stacks.
- */
-nsresult
-BluetoothService::EnableDisable(bool aEnable,
-                                BluetoothReplyRunnable* aRunnable)
-{
-  sToggleInProgress = true;
-  return StartStopBluetooth(aEnable, false, aRunnable);
-}
-
-void
-BluetoothService::FireAdapterStateChanged(bool aEnable)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  InfallibleTArray<BluetoothNamedValue> props;
-  AppendNamedValue(props, "State", aEnable);
-
-  DistributeSignal(NS_LITERAL_STRING("PropertyChanged"),
-                   NS_LITERAL_STRING(KEY_ADAPTER),
-                   BluetoothValue(props));
-}
-
-void
-BluetoothService::AcknowledgeToggleBt(bool aEnabled)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-#if defined(MOZ_WIDGET_GONK)
-  // This is requested in Bug 836516. With settings this property, WLAN
-  // firmware could be aware of Bluetooth has been turned on/off, so that the
-  // mecahnism of handling coexistence of WIFI and Bluetooth could be started.
-  //
-  // In the future, we may have our own way instead of setting a system
-  // property to let firmware developers be able to sense that Bluetooth has
-  // been toggled.
-  if (property_set(PROP_BLUETOOTH_ENABLED, aEnabled ? "true" : "false") != 0) {
-    BT_WARNING("Failed to set bluetooth enabled property");
-  }
-#endif
-
-  if (sInShutdown) {
-    sBluetoothService = nullptr;
-    return;
-  }
-
-  NS_ENSURE_TRUE_VOID(sBluetoothService);
-
-  sBluetoothService->CompleteToggleBt(aEnabled);
-}
-
-void
-BluetoothService::CompleteToggleBt(bool aEnabled)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Update |mEnabled| of |BluetoothService| object since
-  // |StartInternal| and |StopInternal| have been already
-  // done.
-  SetEnabled(aEnabled);
-  sToggleInProgress = false;
-
-  FireAdapterStateChanged(aEnabled);
-}
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothService.h
+++ /dev/null
@@ -1,795 +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_BluetoothService_h
-#define mozilla_dom_bluetooth_BluetoothService_h
-
-#include "BluetoothCommon.h"
-#include "BluetoothInterface.h"
-#include "BluetoothProfileManagerBase.h"
-#include "nsClassHashtable.h"
-#include "nsIObserver.h"
-#include "nsTObserverArray.h"
-#include "nsThreadUtils.h"
-
-namespace mozilla {
-namespace dom {
-class Blob;
-class BlobChild;
-class BlobParent;
-}
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothManager;
-class BluetoothNamedValue;
-class BluetoothReplyRunnable;
-class BluetoothSignal;
-
-typedef mozilla::ObserverList<BluetoothSignal> BluetoothSignalObserverList;
-
-class BluetoothService : public nsIObserver
-{
-  class ToggleBtTask;
-  friend class ToggleBtTask;
-
-  class StartupTask;
-  friend class StartupTask;
-
-public:
-  class ToggleBtAck : public Runnable
-  {
-  public:
-    ToggleBtAck(bool aEnabled);
-    NS_IMETHOD Run();
-
-  private:
-    bool mEnabled;
-  };
-  friend class ToggleBtAck;
-
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIOBSERVER
-
-  /**
-   * Add a message handler object from message distribution observer.
-   * Must be called from the main thread.
-   *
-   * @param aNodeName Node name of the object
-   * @param aMsgHandler Weak pointer to the object
-   */
-  virtual void
-  RegisterBluetoothSignalHandler(const nsAString& aNodeName,
-                                 BluetoothSignalObserver* aMsgHandler);
-
-  /**
-   * Remove a message handler object from message distribution observer.
-   * Must be called from the main thread.
-   *
-   * @param aNodeName Node name of the object
-   * @param aMsgHandler Weak pointer to the object
-   */
-  virtual void
-  UnregisterBluetoothSignalHandler(const nsAString& aNodeName,
-                                   BluetoothSignalObserver* aMsgHandler);
-
-  /**
-   * Remove a message handlers for the given observer.
-   * Must be called from the main thread.
-   *
-   * @param aMsgHandler Weak pointer to the object
-   */
-  void
-  UnregisterAllSignalHandlers(BluetoothSignalObserver* aMsgHandler);
-
-  /**
-   * Create a signal without value and distribute it to the observer list
-   *
-   * @param aName Name of the signal
-   * @param aPath Path of the signal to distribute to
-   */
-  void
-  DistributeSignal(const nsAString& aName, const nsAString& aPath);
-
-  /**
-   * Create a signal and distribute it to the observer list
-   *
-   * @param aName Name of the signal
-   * @param aPath Path of the signal to distribute to
-   * @param aValue Value of the signal to carry
-   */
-  void
-  DistributeSignal(const nsAString& aName, const nsAString& aPath,
-                   const BluetoothValue& aValue);
-
-  /**
-   * Create a signal without value and distribute it to the observer list
-   *
-   * @param aName Name of the signal
-   * @param aAddress Path of the signal to distribute to
-   */
-  void
-  DistributeSignal(const nsAString& aName, const BluetoothAddress& aAddress);
-
-  /**
-   * Create a signal and distribute it to the observer list
-   *
-   * @param aName Name of the signal
-   * @param aAddress Path of the signal to distribute to
-   * @param aValue Value of the signal to carry
-   */
-  void
-  DistributeSignal(const nsAString& aName, const BluetoothAddress& aAddress,
-                   const BluetoothValue& aValue);
-
-  /**
-   * Create a signal without value and distribute it to the observer list
-   *
-   * @param aName Name of the signal
-   * @param aUuid Path of the signal to distribute to
-   */
-  void
-  DistributeSignal(const nsAString& aName, const BluetoothUuid& aUuid);
-
-  /**
-   * Create a signal and distribute it to the observer list
-   *
-   * @param aName Name of the signal
-   * @param aUuid Path of the signal to distribute to
-   * @param aValue Value of the signal to carry
-   */
-  void
-  DistributeSignal(const nsAString& aName, const BluetoothUuid& aUuid,
-                   const BluetoothValue& aValue);
-
-  /**
-   * Distribute a signal to the observer list
-   *
-   * @param aSignal Signal object to distribute
-   */
-  void
-  DistributeSignal(const BluetoothSignal& aSignal);
-
-  /**
-   * Returns the BluetoothService singleton. Only to be called from main thread.
-   *
-   * @param aService Pointer to return singleton into.
-   *
-   * @return non-nullptr on proper assignment, nullptr otherwise (if service
-   * has not yet been started, for instance)
-   */
-  static BluetoothService*
-  Get();
-
-  static already_AddRefed<BluetoothService>
-  FactoryCreate()
-  {
-    RefPtr<BluetoothService> service = Get();
-    return service.forget();
-  }
-
-  /**
-   * Returns an array of each adapter's properties, implemented via a platform
-   * specific method.
-   *
-   * @return NS_OK on success, NS_ERROR_FAILURE otherwise
-   */
-  virtual nsresult
-  GetAdaptersInternal(BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Returns the properties of paired devices, implemented via a platform
-   * specific method.
-   *
-   * @return NS_OK on success, NS_ERROR_FAILURE otherwise
-   */
-  virtual nsresult
-  GetPairedDevicePropertiesInternal(
-    const nsTArray<BluetoothAddress>& aDeviceAddresses,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Returns the properties of connected devices regarding to specific profile,
-   * implemented via a platform specific methood.
-   *
-   * @return NS_OK on success, NS_ERROR_FAILURE otherwise
-   */
-  virtual nsresult
-  GetConnectedDevicePropertiesInternal(uint16_t aServiceUuid,
-                                       BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Returns up-to-date uuids of given device address,
-   * implemented via a platform specific methood.
-   *
-   * @return NS_OK on success, NS_ERROR_FAILURE otherwise
-   */
-  virtual nsresult
-  FetchUuidsInternal(const BluetoothAddress& aDeviceAddress,
-                     BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Stop device discovery (platform specific implementation)
-   */
-  virtual void
-  StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Start device discovery (platform specific implementation)
-   */
-  virtual void
-  StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Stops an ongoing Bluetooth LE device scan.
-   */
-  virtual void
-  StopLeScanInternal(const BluetoothUuid& aScanUuid,
-                     BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Starts a Bluetooth LE device scan.
-   */
-  virtual void
-  StartLeScanInternal(const nsTArray<BluetoothUuid>& aServiceUuids,
-                      BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Start/Stop advertising.
-   */
-  virtual void
-  StartAdvertisingInternal(const BluetoothUuid& aAppUuid,
-                           const BluetoothGattAdvertisingData& aAdvData,
-                           BluetoothReplyRunnable* aRunnable) { }
-
-  virtual void
-  StopAdvertisingInternal(const BluetoothUuid& aAppUuid,
-                          BluetoothReplyRunnable* aRunnable) { }
-
-  /**
-   * Set a property for the specified object
-   *
-   * @param aPropName Name of the property
-   * @param aValue Boolean value
-   * @param aRunnable Runnable to run on async reply
-   *
-   * @return NS_OK if property is set correctly, NS_ERROR_FAILURE otherwise
-   */
-  virtual nsresult
-  SetProperty(BluetoothObjectType aType,
-              const BluetoothNamedValue& aValue,
-              BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual nsresult
-  CreatePairedDeviceInternal(const BluetoothAddress& aDeviceAddress,
-                             int aTimeout,
-                             BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual nsresult
-  RemoveDeviceInternal(const BluetoothAddress& aDeviceAddress,
-                       BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Get corresponding service channel of specific service on remote device.
-   * It's usually the very first step of establishing an outbound connection.
-   *
-   * @param aObjectPath Address of remote device
-   * @param aServiceUuid UUID of the target service
-   * @param aManager Instance which has callback function OnGetServiceChannel()
-   *
-   * @return NS_OK if the task begins, NS_ERROR_FAILURE otherwise
-   */
-  virtual nsresult
-  GetServiceChannel(const BluetoothAddress& aDeviceAddress,
-                    const BluetoothUuid& aServiceUuid,
-                    BluetoothProfileManagerBase* aManager) = 0;
-
-  virtual bool
-  UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
-                   BluetoothProfileManagerBase* aManager) = 0;
-
-  virtual void
-  PinReplyInternal(const BluetoothAddress& aDeviceAddress,
-                   bool aAccept,
-                   const BluetoothPinCode& aPinCode,
-                   BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  SspReplyInternal(const BluetoothAddress& aDeviceAddress,
-                   BluetoothSspVariant aVariant,
-                   bool aAccept,
-                   BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Legacy method used by bluez only to reply pincode request.
-   */
-  virtual void
-  SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
-                     const BluetoothPinCode& aPinCode,
-                     BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Legacy method used by bluez only to reply passkey entry request.
-   */
-  virtual void
-  SetPasskeyInternal(const BluetoothAddress& aDeviceAddress, uint32_t aPasskey,
-                     BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Legacy method used by bluez only to reply pairing confirmation request.
-   */
-  virtual void
-  SetPairingConfirmationInternal(const BluetoothAddress& aDeviceAddress,
-                                 bool aConfirm,
-                                 BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  Connect(const BluetoothAddress& aDeviceAddress,
-          uint32_t aCod, uint16_t aServiceUuid,
-          BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  Disconnect(const BluetoothAddress& aDeviceAddress, uint16_t aServiceUuid,
-             BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  SendFile(const BluetoothAddress& aDeviceAddress,
-           BlobParent* aBlobParent,
-           BlobChild* aBlobChild,
-           BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  SendFile(const BluetoothAddress& aDeviceAddress,
-           Blob* aBlob,
-           BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  StopSendingFile(const BluetoothAddress& aDeviceAddress,
-                  BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ConfirmReceivingFile(const BluetoothAddress& aDeviceAddress, bool aConfirm,
-                       BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ConnectSco(BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  DisconnectSco(BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  IsScoConnected(BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  SetObexPassword(const nsAString& aPassword,
-                  BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  RejectObexAuth(BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ReplyTovCardPulling(BlobParent* aBlobParent,
-                      BlobChild* aBlobChild,
-                      BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ReplyTovCardPulling(Blob* aBlob,
-                      BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ReplyToPhonebookPulling(BlobParent* aBlobParent,
-                          BlobChild* aBlobChild,
-                          uint16_t aPhonebookSize,
-                          BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ReplyToPhonebookPulling(Blob* aBlob,
-                          uint16_t aPhonebookSize,
-                          BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ReplyTovCardListing(BlobParent* aBlobParent,
-                      BlobChild* aBlobChild,
-                      uint16_t aPhonebookSize,
-                      BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ReplyTovCardListing(Blob* aBlob,
-                      uint16_t aPhonebookSize,
-                      BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ReplyToMapFolderListing(long aMasId,
-                          const nsAString& aFolderlists,
-                          BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ReplyToMapMessagesListing(BlobParent* aBlobParent,
-                            BlobChild* aBlobChild,
-                            long aMasId,
-                            bool aNewMessage,
-                            const nsAString& aTimestamp,
-                            int aSize,
-                            BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ReplyToMapMessagesListing(long aMasId,
-                            Blob* aBlob,
-                            bool aNewMessage,
-                            const nsAString& aTimestamp,
-                            int aSize,
-                            BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ReplyToMapGetMessage(BlobParent* aBlobParent,
-                       BlobChild* aBlobChild,
-                       long aMasId,
-                       BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ReplyToMapGetMessage(Blob* aBlob,
-                       long aMasId,
-                       BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ReplyToMapSetMessageStatus(long aMasId,
-                             bool aStatus,
-                             BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ReplyToMapSendMessage(
-    long aMasId, const nsAString& aHandleId, bool aStatus,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ReplyToMapMessageUpdate(
-    long aMasId, bool aStatus, BluetoothReplyRunnable* aRunnable) = 0;
-
-#ifdef MOZ_B2G_RIL
-  virtual void
-  AnswerWaitingCall(BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  IgnoreWaitingCall(BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  ToggleCalls(BluetoothReplyRunnable* aRunnable) = 0;
-#endif
-
-  virtual void
-  SendMetaData(const nsAString& aTitle,
-               const nsAString& aArtist,
-               const nsAString& aAlbum,
-               int64_t aMediaNumber,
-               int64_t aTotalMediaCount,
-               int64_t aDuration,
-               BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  SendPlayStatus(int64_t aDuration,
-                 int64_t aPosition,
-                 ControlPlayStatus aPlayStatus,
-                 BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  UpdatePlayStatus(uint32_t aDuration,
-                   uint32_t aPosition,
-                   ControlPlayStatus aPlayStatus) = 0;
-
-  virtual nsresult
-  SendSinkMessage(const nsAString& aDeviceAddresses,
-                  const nsAString& aMessage) = 0;
-
-  virtual nsresult
-  SendInputMessage(const nsAString& aDeviceAddresses,
-                   const nsAString& aMessage) = 0;
-
-  /**
-   * Connect to a remote GATT server. (platform specific implementation)
-   */
-  virtual void
-  ConnectGattClientInternal(const BluetoothUuid& aAppUuid,
-                            const BluetoothAddress& aDeviceAddress,
-                            BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Disconnect GATT client from a remote GATT server.
-   * (platform specific implementation)
-   */
-  virtual void
-  DisconnectGattClientInternal(const BluetoothUuid& aAppUuid,
-                               const BluetoothAddress& aDeviceAddress,
-                               BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Discover GATT services, characteristic, descriptors from a remote GATT
-   * server. (platform specific implementation)
-   */
-  virtual void
-  DiscoverGattServicesInternal(const BluetoothUuid& aAppUuid,
-                               BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Enable notifications of a given GATT characteristic.
-   * (platform specific implementation)
-   */
-  virtual void
-  GattClientStartNotificationsInternal(const BluetoothUuid& aAppUuid,
-                                       const BluetoothGattServiceId& aServId,
-                                       const BluetoothGattId& aCharId,
-                                       BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Disable notifications of a given GATT characteristic.
-   * (platform specific implementation)
-   */
-  virtual void
-  GattClientStopNotificationsInternal(const BluetoothUuid& aAppUuid,
-                                      const BluetoothGattServiceId& aServId,
-                                      const BluetoothGattId& aCharId,
-                                      BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Unregister a GATT client. (platform specific implementation)
-   */
-  virtual void
-  UnregisterGattClientInternal(int aClientIf,
-                               BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Request RSSI for a remote GATT server. (platform specific implementation)
-   */
-  virtual void
-  GattClientReadRemoteRssiInternal(int aClientIf,
-                                   const BluetoothAddress& aDeviceAddress,
-                                   BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Read the value of a characteristic on a GATT client.
-   * (platform specific implementation)
-   */
-  virtual void
-  GattClientReadCharacteristicValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Write the value of a characteristic on a GATT client.
-   * (platform specific implementation)
-   */
-  virtual void
-  GattClientWriteCharacteristicValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    const BluetoothGattWriteType& aWriteType,
-    const nsTArray<uint8_t>& aValue,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Read the value of a descriptor of a characteristic on a GATT client.
-   * (platform specific implementation)
-   */
-  virtual void
-  GattClientReadDescriptorValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    const BluetoothGattId& aDescriptorId,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Write the value of a descriptor of a characteristic on a GATT client.
-   * (platform specific implementation)
-   */
-  virtual void
-  GattClientWriteDescriptorValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    const BluetoothGattId& aDescriptorId,
-    const nsTArray<uint8_t>& aValue,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  GattServerRegisterInternal(
-    const BluetoothUuid& aAppUuid,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  GattServerConnectPeripheralInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  GattServerDisconnectPeripheralInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Unregister a GATT server. (platform specific implementation)
-   */
-  virtual void
-  UnregisterGattServerInternal(int aServerIf,
-                               BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  GattServerAddServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    uint16_t aHandleCount,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  GattServerAddIncludedServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aIncludedServiceHandle,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  GattServerAddCharacteristicInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothUuid& aCharacteristicUuid,
-    BluetoothGattAttrPerm aPermissions,
-    BluetoothGattCharProp aProperties,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  GattServerAddDescriptorInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aCharacteristicHandle,
-    const BluetoothUuid& aDescriptorUuid,
-    BluetoothGattAttrPerm aPermissions,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  GattServerRemoveServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  GattServerStartServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  GattServerStopServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  GattServerSendResponseInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    uint16_t aStatus,
-    int32_t aRequestId,
-    const BluetoothGattResponse& aRsp,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  virtual void
-  GattServerSendIndicationInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    const BluetoothAttributeHandle& aCharacteristicHandle,
-    bool aConfirm,
-    const nsTArray<uint8_t>& aValue,
-    BluetoothReplyRunnable* aRunnable) = 0;
-
-  bool
-  IsEnabled() const
-  {
-    return mEnabled;
-  }
-
-  bool
-  IsToggling() const;
-
-  static void AcknowledgeToggleBt(bool aEnabled);
-
-  void FireAdapterStateChanged(bool aEnable);
-  nsresult EnableDisable(bool aEnable,
-                         BluetoothReplyRunnable* aRunnable);
-
-  /**
-   * Platform specific startup functions go here. Usually deals with member
-   * variables, so not static. Guaranteed to be called outside of main thread.
-   *
-   * @return NS_OK on correct startup, NS_ERROR_FAILURE otherwise
-   */
-  virtual nsresult
-  StartInternal(BluetoothReplyRunnable* aRunnable) = 0;
-
-  /**
-   * Platform specific startup functions go here. Usually deals with member
-   * variables, so not static. Guaranteed to be called outside of main thread.
-   *
-   * @return NS_OK on correct startup, NS_ERROR_FAILURE otherwise
-   */
-  virtual nsresult
-  StopInternal(BluetoothReplyRunnable* aRunnable) = 0;
-
-protected:
-  BluetoothService() : mEnabled(false)
-  { }
-
-  virtual ~BluetoothService();
-
-  bool
-  Init();
-
-  void
-  Cleanup();
-
-  nsresult
-  StartBluetooth(bool aIsStartup, BluetoothReplyRunnable* aRunnable);
-
-  nsresult
-  StopBluetooth(bool aIsStartup, BluetoothReplyRunnable* aRunnable);
-
-  nsresult
-  StartStopBluetooth(bool aStart,
-                     bool aIsStartup,
-                     BluetoothReplyRunnable* aRunnable);
-
-  /**
-   * Called when XPCOM first creates this service.
-   */
-  virtual nsresult
-  HandleStartup();
-
-  virtual void
-  CompleteToggleBt(bool aEnabled);
-
-  /**
-   * Called when the startup settings check has completed.
-   */
-  nsresult
-  HandleStartupSettingsCheck(bool aEnable);
-
-  /**
-   * Called when "mozsettings-changed" observer topic fires.
-   */
-  nsresult
-  HandleSettingsChanged(nsISupports* aSubject);
-
-  /**
-   * Called when XPCOM is shutting down.
-   */
-  virtual nsresult
-  HandleShutdown();
-
-  // Called by ToggleBtAck.
-  void
-  SetEnabled(bool aEnabled);
-
-  // Called by Get().
-  static BluetoothService*
-  Create();
-
-  typedef nsClassHashtable<nsStringHashKey, BluetoothSignalObserverList >
-  BluetoothSignalObserverTable;
-
-  BluetoothSignalObserverTable mBluetoothSignalObserverTable;
-
-  nsTArray<BluetoothSignal> mPendingPairReqSignals;
-
-  bool mEnabled;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothService_h
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothSocketObserver.h
+++ /dev/null
@@ -1,56 +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_BluetoothSocketObserver_h
-#define mozilla_dom_bluetooth_BluetoothSocketObserver_h
-
-#include "BluetoothCommon.h"
-#include "mozilla/ipc/SocketBase.h"
-#include "mozilla/UniquePtr.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothSocket;
-
-class BluetoothSocketObserver
-{
-public:
-  virtual void ReceiveSocketData(
-    BluetoothSocket* aSocket,
-    UniquePtr<mozilla::ipc::UnixSocketBuffer>& aBuffer) = 0;
-
-   /**
-    * A callback function which would be called when a socket connection
-    * is established successfully. To be more specific, this would be called
-    * when socket state changes from CONNECTING/LISTENING to CONNECTED.
-    */
-  virtual void OnSocketConnectSuccess(BluetoothSocket* aSocket) = 0;
-
-   /**
-    * A callback function which would be called when BluetoothSocket::Connect()
-    * fails.
-    */
-  virtual void OnSocketConnectError(BluetoothSocket* aSocket) = 0;
-
-   /**
-    * A callback function which would be called when a socket connection
-    * is dropped. To be more specific, this would be called when socket state
-    * changes from CONNECTED/LISTENING to DISCONNECTED.
-    */
-  virtual void OnSocketDisconnect(BluetoothSocket* aSocket) = 0;
-};
-
-#define BT_DECL_SOCKET_OBSERVER                                             \
-public:                                                                     \
-  virtual void ReceiveSocketData(BluetoothSocket* aSocket,                  \
-    UniquePtr<mozilla::ipc::UnixSocketBuffer>& aMessage) override;          \
-  virtual void OnSocketConnectSuccess(BluetoothSocket* aSocket) override;   \
-  virtual void OnSocketConnectError(BluetoothSocket* aSocket) override;     \
-  virtual void OnSocketDisconnect(BluetoothSocket* aSocket) override;
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothSocketObserver_h
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothUtils.cpp
+++ /dev/null
@@ -1,868 +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 "BluetoothUtils.h"
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-#include "jsapi.h"
-#include "mozilla/dom/BluetoothGattCharacteristicBinding.h"
-#include "mozilla/dom/BluetoothGattServerBinding.h"
-#include "mozilla/dom/ScriptSettings.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "nsContentUtils.h"
-#include "nsISystemMessagesInternal.h"
-#include "nsIUUIDGenerator.h"
-#include "nsServiceManagerUtils.h"
-#include "nsXULAppAPI.h"
-#include "mozilla/Unused.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-void
-AddressToString(const BluetoothAddress& aAddress, nsAString& aString)
-{
-  char str[BLUETOOTH_ADDRESS_LENGTH + 1];
-
-  int res = snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x",
-                     static_cast<int>(aAddress.mAddr[0]),
-                     static_cast<int>(aAddress.mAddr[1]),
-                     static_cast<int>(aAddress.mAddr[2]),
-                     static_cast<int>(aAddress.mAddr[3]),
-                     static_cast<int>(aAddress.mAddr[4]),
-                     static_cast<int>(aAddress.mAddr[5]));
-
-  if ((res == EOF) ||
-      (res < 0) ||
-      (static_cast<size_t>(res) >= sizeof(str))) {
-    /* Conversion should have succeeded or (a) we're out of memory, or
-     * (b) our code is massively broken. We should crash in both cases.
-     */
-    MOZ_CRASH("Failed to convert Bluetooth address to string");
-  }
-
-  aString = NS_ConvertUTF8toUTF16(str);
-}
-
-nsresult
-StringToAddress(const nsAString& aString, BluetoothAddress& aAddress)
-{
-  int res = sscanf(NS_ConvertUTF16toUTF8(aString).get(),
-                   "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
-                   &aAddress.mAddr[0],
-                   &aAddress.mAddr[1],
-                   &aAddress.mAddr[2],
-                   &aAddress.mAddr[3],
-                   &aAddress.mAddr[4],
-                   &aAddress.mAddr[5]);
-  if (res < static_cast<ssize_t>(MOZ_ARRAY_LENGTH(aAddress.mAddr))) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  return NS_OK;
-}
-
-nsresult
-PinCodeToString(const BluetoothPinCode& aPinCode, nsAString& aString)
-{
-  if (aPinCode.mLength > sizeof(aPinCode.mPinCode)) {
-    BT_LOGR("Pin-code string too long");
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-
-  aString = NS_ConvertUTF8toUTF16(
-    nsCString(reinterpret_cast<const char*>(aPinCode.mPinCode),
-              aPinCode.mLength));
-
-  return NS_OK;
-}
-
-nsresult
-StringToPinCode(const nsAString& aString, BluetoothPinCode& aPinCode)
-{
-  NS_ConvertUTF16toUTF8 stringUTF8(aString);
-
-  auto len = stringUTF8.Length();
-
-  if (len > sizeof(aPinCode.mPinCode)) {
-    BT_LOGR("Pin-code string too long");
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-
-  auto str = stringUTF8.get();
-
-  memcpy(aPinCode.mPinCode, str, len);
-  memset(aPinCode.mPinCode + len, 0, sizeof(aPinCode.mPinCode) - len);
-  aPinCode.mLength = len;
-
-  return NS_OK;
-}
-
-nsresult
-StringToControlPlayStatus(const nsAString& aString,
-                          ControlPlayStatus& aPlayStatus)
-{
-  if (aString.EqualsLiteral("STOPPED")) {
-    aPlayStatus = ControlPlayStatus::PLAYSTATUS_STOPPED;
-  } else if (aString.EqualsLiteral("PLAYING")) {
-    aPlayStatus = ControlPlayStatus::PLAYSTATUS_PLAYING;
-  } else if (aString.EqualsLiteral("PAUSED")) {
-    aPlayStatus = ControlPlayStatus::PLAYSTATUS_PAUSED;
-  } else if (aString.EqualsLiteral("FWD_SEEK")) {
-    aPlayStatus = ControlPlayStatus::PLAYSTATUS_FWD_SEEK;
-  } else if (aString.EqualsLiteral("REV_SEEK")) {
-    aPlayStatus = ControlPlayStatus::PLAYSTATUS_REV_SEEK;
-  } else if (aString.EqualsLiteral("ERROR")) {
-    aPlayStatus = ControlPlayStatus::PLAYSTATUS_ERROR;
-  } else {
-    BT_LOGR("Invalid play status: %s", NS_ConvertUTF16toUTF8(aString).get());
-    aPlayStatus = ControlPlayStatus::PLAYSTATUS_UNKNOWN;
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-
-  return NS_OK;
-}
-
-nsresult
-StringToPropertyType(const nsAString& aString, BluetoothPropertyType& aType)
-{
-  if (aString.EqualsLiteral("Name")) {
-    aType = PROPERTY_BDNAME;
-  } else if (aString.EqualsLiteral("Discoverable")) {
-    aType = PROPERTY_ADAPTER_SCAN_MODE;
-  } else if (aString.EqualsLiteral("DiscoverableTimeout")) {
-    aType = PROPERTY_ADAPTER_DISCOVERY_TIMEOUT;
-  } else {
-    BT_LOGR("Invalid property name: %s", NS_ConvertUTF16toUTF8(aString).get());
-    aType = PROPERTY_UNKNOWN; // silences compiler warning
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  return NS_OK;
-}
-
-nsresult
-NamedValueToProperty(const BluetoothNamedValue& aValue,
-                     BluetoothProperty& aProperty)
-{
-  nsresult rv = StringToPropertyType(aValue.name(), aProperty.mType);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  switch (aProperty.mType) {
-    case PROPERTY_BDNAME:
-      if (aValue.value().type() != BluetoothValue::TBluetoothRemoteName) {
-        BT_LOGR("Bluetooth property value is not a remote name");
-        return NS_ERROR_ILLEGAL_VALUE;
-      }
-      // Set name
-      aProperty.mRemoteName = aValue.value().get_BluetoothRemoteName();
-      break;
-
-    case PROPERTY_ADAPTER_SCAN_MODE:
-      if (aValue.value().type() != BluetoothValue::Tbool) {
-        BT_LOGR("Bluetooth property value is not a boolean");
-        return NS_ERROR_ILLEGAL_VALUE;
-      }
-      // Set scan mode
-      if (aValue.value().get_bool()) {
-        aProperty.mScanMode = SCAN_MODE_CONNECTABLE_DISCOVERABLE;
-      } else {
-        aProperty.mScanMode = SCAN_MODE_CONNECTABLE;
-      }
-      break;
-
-    case PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
-      if (aValue.value().type() != BluetoothValue::Tuint32_t) {
-        BT_LOGR("Bluetooth property value is not an unsigned integer");
-        return NS_ERROR_ILLEGAL_VALUE;
-      }
-      // Set discoverable timeout
-      aProperty.mUint32 = aValue.value().get_uint32_t();
-      break;
-
-    default:
-      BT_LOGR("Invalid property value type");
-      return NS_ERROR_ILLEGAL_VALUE;
-  }
-
-  return NS_OK;
-}
-
-void
-RemoteNameToString(const BluetoothRemoteName& aRemoteName, nsAString& aString)
-{
-  MOZ_ASSERT(aRemoteName.mLength <= sizeof(aRemoteName.mName));
-
-  auto name = reinterpret_cast<const char*>(aRemoteName.mName);
-
-  /* The content in |BluetoothRemoteName| is not a C string and not
-   * terminated by \0. We use |mLength| to limit its length.
-   */
-  aString = NS_ConvertUTF8toUTF16(name, aRemoteName.mLength);
-}
-
-nsresult
-StringToServiceName(const nsAString& aString,
-                    BluetoothServiceName& aServiceName)
-{
-  NS_ConvertUTF16toUTF8 serviceNameUTF8(aString);
-
-  auto len = serviceNameUTF8.Length();
-
-  if (len > sizeof(aServiceName.mName)) {
-    BT_LOGR("Service-name string too long");
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-
-  auto str = serviceNameUTF8.get();
-
-  memcpy(aServiceName.mName, str, len);
-  memset(aServiceName.mName + len, 0, sizeof(aServiceName.mName) - len);
-
-  return NS_OK;
-}
-
-void
-UuidToString(const BluetoothUuid& aUuid, nsAString& aString)
-{
-  char uuidStr[37];
-  uint32_t uuid0, uuid4;
-  uint16_t uuid1, uuid2, uuid3, uuid5;
-
-  memcpy(&uuid0, &aUuid.mUuid[0], sizeof(uint32_t));
-  memcpy(&uuid1, &aUuid.mUuid[4], sizeof(uint16_t));
-  memcpy(&uuid2, &aUuid.mUuid[6], sizeof(uint16_t));
-  memcpy(&uuid3, &aUuid.mUuid[8], sizeof(uint16_t));
-  memcpy(&uuid4, &aUuid.mUuid[10], sizeof(uint32_t));
-  memcpy(&uuid5, &aUuid.mUuid[14], sizeof(uint16_t));
-
-  snprintf(uuidStr, sizeof(uuidStr),
-           "%.8x-%.4x-%.4x-%.4x-%.8x%.4x",
-           ntohl(uuid0), ntohs(uuid1),
-           ntohs(uuid2), ntohs(uuid3),
-           ntohl(uuid4), ntohs(uuid5));
-
-  aString.Truncate();
-  aString.AssignLiteral(uuidStr);
-}
-
-nsresult
-StringToUuid(const nsAString& aString, BluetoothUuid& aUuid)
-{
-  uint32_t uuid0, uuid4;
-  uint16_t uuid1, uuid2, uuid3, uuid5;
-
-  auto res = sscanf(NS_ConvertUTF16toUTF8(aString).get(),
-                    "%08x-%04hx-%04hx-%04hx-%08x%04hx",
-                    &uuid0, &uuid1, &uuid2, &uuid3, &uuid4, &uuid5);
-  if (res == EOF || res < 6) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-
-  uuid0 = htonl(uuid0);
-  uuid1 = htons(uuid1);
-  uuid2 = htons(uuid2);
-  uuid3 = htons(uuid3);
-  uuid4 = htonl(uuid4);
-  uuid5 = htons(uuid5);
-
-  memcpy(&aUuid.mUuid[0], &uuid0, sizeof(uint32_t));
-  memcpy(&aUuid.mUuid[4], &uuid1, sizeof(uint16_t));
-  memcpy(&aUuid.mUuid[6], &uuid2, sizeof(uint16_t));
-  memcpy(&aUuid.mUuid[8], &uuid3, sizeof(uint16_t));
-  memcpy(&aUuid.mUuid[10], &uuid4, sizeof(uint32_t));
-  memcpy(&aUuid.mUuid[14], &uuid5, sizeof(uint16_t));
-
-  return NS_OK;
-}
-
-nsresult
-BytesToUuid(const nsTArray<uint8_t>& aArray,
-            nsTArray<uint8_t>::index_type aOffset,
-            BluetoothUuidType aType,
-            BluetoothProfileEndian aEndian,
-            BluetoothUuid& aUuid)
-{
-  MOZ_ASSERT(aType == UUID_16_BIT ||
-             aType == UUID_32_BIT ||
-             aType == UUID_128_BIT);
-  MOZ_ASSERT(aEndian == ENDIAN_BIG || aEndian == ENDIAN_LITTLE);
-
-  size_t index = (aType == UUID_16_BIT) ? 2 : 0;
-  size_t length = 0;
-
-  if (aType == UUID_16_BIT) {
-    length =  sizeof(uint16_t);
-  } else if (aType == UUID_32_BIT) {
-    length = sizeof(uint32_t);
-  } else {
-    length = MOZ_ARRAY_LENGTH(aUuid.mUuid);
-  }
-
-  if (aArray.Length() < aOffset + length) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-
-  aUuid = BluetoothUuid::BASE();
-
-  if (aEndian == ENDIAN_BIG) {
-    for (size_t i = 0; i < length; ++i) {
-      aUuid.mUuid[index + i] = aArray[aOffset + i];
-    }
-  } else {
-    for (size_t i = 0; i < length; ++i) {
-      aUuid.mUuid[index + i] = aArray[aOffset + length - i - 1];
-    }
-  }
-
-  return NS_OK;
-}
-
-nsresult
-UuidToBytes(const BluetoothUuid& aUuid,
-            BluetoothUuidType aType,
-            BluetoothProfileEndian aEndian,
-            nsTArray<uint8_t>& aArray,
-            nsTArray<uint8_t>::index_type aOffset)
-{
-  MOZ_ASSERT(aType == UUID_16_BIT ||
-             aType == UUID_32_BIT ||
-             aType == UUID_128_BIT);
-  MOZ_ASSERT(aEndian == ENDIAN_BIG || aEndian == ENDIAN_LITTLE);
-
-  size_t index = (aType == UUID_16_BIT) ? 2 : 0;
-  size_t length = 0;
-
-  if (aType == UUID_16_BIT) {
-    length =  sizeof(uint16_t);
-  } else if (aType == UUID_32_BIT) {
-    length = sizeof(uint32_t);
-  } else {
-    length = MOZ_ARRAY_LENGTH(aUuid.mUuid);
-  }
-
-  aArray.SetCapacity(aOffset + length);
-
-  if (aEndian == ENDIAN_BIG) {
-    for (size_t i = 0; i < length; ++i) {
-      aArray[aOffset + i] = aUuid.mUuid[index + i];
-    }
-  } else {
-    for (size_t i = 0; i < length; ++i) {
-      aArray[aOffset + length - i - 1] = aUuid.mUuid[index + i];
-    }
-  }
-
-  return NS_OK;
-}
-
-nsresult
-GenerateUuid(BluetoothUuid &aUuid)
-{
-  nsresult rv;
-  nsCOMPtr<nsIUUIDGenerator> uuidGenerator =
-    do_GetService("@mozilla.org/uuid-generator;1", &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsID uuid;
-  rv = uuidGenerator->GenerateUUIDInPlace(&uuid);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  aUuid = BluetoothUuid(uuid.m0 >> 24, uuid.m0 >> 16, uuid.m0 >> 8, uuid.m0,
-                        uuid.m1 >> 8, uuid.m1,
-                        uuid.m2 >> 8, uuid.m2,
-                        uuid.m3[0], uuid.m3[1], uuid.m3[2], uuid.m3[3],
-                        uuid.m3[4], uuid.m3[5], uuid.m3[6], uuid.m3[7]);
-  return NS_OK;
-}
-
-nsresult
-GenerateUuid(nsAString &aUuidString)
-{
-  nsresult rv;
-  nsCOMPtr<nsIUUIDGenerator> uuidGenerator =
-    do_GetService("@mozilla.org/uuid-generator;1", &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsID uuid;
-  rv = uuidGenerator->GenerateUUIDInPlace(&uuid);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // Build a string in {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format
-  char uuidBuffer[NSID_LENGTH];
-  uuid.ToProvidedString(uuidBuffer);
-  NS_ConvertASCIItoUTF16 uuidString(uuidBuffer);
-
-  // Remove {} and the null terminator
-  aUuidString.Assign(Substring(uuidString, 1, NSID_LENGTH - 3));
-
-  return NS_OK;
-}
-
-void
-GattPermissionsToDictionary(BluetoothGattAttrPerm aBits,
-                            GattPermissions& aPermissions)
-{
-  aPermissions.mRead = aBits & GATT_ATTR_PERM_BIT_READ;
-  aPermissions.mReadEncrypted = aBits & GATT_ATTR_PERM_BIT_READ_ENCRYPTED;
-  aPermissions.mReadEncryptedMITM =
-    aBits & GATT_ATTR_PERM_BIT_READ_ENCRYPTED_MITM;
-  aPermissions.mWrite = aBits & GATT_ATTR_PERM_BIT_WRITE;
-  aPermissions.mWriteEncrypted = aBits & GATT_ATTR_PERM_BIT_WRITE_ENCRYPTED;
-  aPermissions.mWriteEncryptedMITM =
-    aBits & GATT_ATTR_PERM_BIT_WRITE_ENCRYPTED_MITM;
-  aPermissions.mWriteSigned = aBits & GATT_ATTR_PERM_BIT_WRITE_SIGNED;
-  aPermissions.mWriteSignedMITM = aBits & GATT_ATTR_PERM_BIT_WRITE_SIGNED_MITM;
-}
-
-void
-GattPermissionsToBits(const GattPermissions& aPermissions,
-                      BluetoothGattAttrPerm& aBits)
-{
-  aBits = BLUETOOTH_EMPTY_GATT_ATTR_PERM;
-
-  if (aPermissions.mRead) {
-    aBits |= GATT_ATTR_PERM_BIT_READ;
-  }
-  if (aPermissions.mReadEncrypted) {
-    aBits |= GATT_ATTR_PERM_BIT_READ_ENCRYPTED;
-  }
-  if (aPermissions.mReadEncryptedMITM) {
-    aBits |= GATT_ATTR_PERM_BIT_READ_ENCRYPTED_MITM;
-  }
-  if (aPermissions.mWrite) {
-    aBits |= GATT_ATTR_PERM_BIT_WRITE;
-  }
-  if (aPermissions.mWriteEncrypted) {
-    aBits |= GATT_ATTR_PERM_BIT_WRITE_ENCRYPTED;
-  }
-  if (aPermissions.mWriteEncryptedMITM) {
-    aBits |= GATT_ATTR_PERM_BIT_WRITE_ENCRYPTED_MITM;
-  }
-  if (aPermissions.mWriteSigned) {
-    aBits |= GATT_ATTR_PERM_BIT_WRITE_SIGNED;
-  }
-  if (aPermissions.mWriteSignedMITM) {
-    aBits |= GATT_ATTR_PERM_BIT_WRITE_SIGNED_MITM;
-  }
-}
-
-void
-GattPropertiesToDictionary(BluetoothGattCharProp aBits,
-                           GattCharacteristicProperties& aProperties)
-{
-  aProperties.mBroadcast = aBits & GATT_CHAR_PROP_BIT_BROADCAST;
-  aProperties.mRead = aBits & GATT_CHAR_PROP_BIT_READ;
-  aProperties.mWriteNoResponse = aBits & GATT_CHAR_PROP_BIT_WRITE_NO_RESPONSE;
-  aProperties.mWrite = aBits & GATT_CHAR_PROP_BIT_WRITE;
-  aProperties.mNotify = aBits & GATT_CHAR_PROP_BIT_NOTIFY;
-  aProperties.mIndicate = aBits & GATT_CHAR_PROP_BIT_INDICATE;
-  aProperties.mSignedWrite = aBits & GATT_CHAR_PROP_BIT_SIGNED_WRITE;
-  aProperties.mExtendedProps = aBits & GATT_CHAR_PROP_BIT_EXTENDED_PROPERTIES;
-}
-
-void
-GattPropertiesToBits(const GattCharacteristicProperties& aProperties,
-                     BluetoothGattCharProp& aBits)
-{
-  aBits = BLUETOOTH_EMPTY_GATT_CHAR_PROP;
-
-  if (aProperties.mBroadcast) {
-    aBits |= GATT_CHAR_PROP_BIT_BROADCAST;
-  }
-  if (aProperties.mRead) {
-    aBits |= GATT_CHAR_PROP_BIT_READ;
-  }
-  if (aProperties.mWriteNoResponse) {
-    aBits |= GATT_CHAR_PROP_BIT_WRITE_NO_RESPONSE;
-  }
-  if (aProperties.mWrite) {
-    aBits |= GATT_CHAR_PROP_BIT_WRITE;
-  }
-  if (aProperties.mNotify) {
-    aBits |= GATT_CHAR_PROP_BIT_NOTIFY;
-  }
-  if (aProperties.mIndicate) {
-    aBits |= GATT_CHAR_PROP_BIT_INDICATE;
-  }
-  if (aProperties.mSignedWrite) {
-    aBits |= GATT_CHAR_PROP_BIT_SIGNED_WRITE;
-  }
-  if (aProperties.mExtendedProps) {
-    aBits |= GATT_CHAR_PROP_BIT_EXTENDED_PROPERTIES;
-  }
-}
-
-nsresult
-AdvertisingDataToGattAdvertisingData(
-  const BluetoothAdvertisingData& aAdvData,
-  BluetoothGattAdvertisingData& aGattAdvData)
-{
-  aGattAdvData.mAppearance = aAdvData.mAppearance;
-  aGattAdvData.mIncludeDevName = aAdvData.mIncludeDevName;
-  aGattAdvData.mIncludeTxPower = aAdvData.mIncludeTxPower;
-
-  for (size_t i = 0; i < aAdvData.mServiceUuids.Length(); i++) {
-    BluetoothUuid uuid;
-    if (NS_WARN_IF(NS_FAILED(StringToUuid(aAdvData.mServiceUuids[i], uuid)))) {
-      return NS_ERROR_ILLEGAL_VALUE;
-    }
-    aGattAdvData.mServiceUuids.AppendElement(uuid);
-  }
-
-  if (!aAdvData.mManufacturerData.IsNull()) {
-    // First two bytes are manufacturer ID in little-endian.
-    LittleEndian::writeUint16(aGattAdvData.mManufacturerData.Elements(),
-                              aAdvData.mManufacturerId);
-
-    // Concatenate custom manufacturer data.
-    const ArrayBuffer& manufacturerData = aAdvData.mManufacturerData.Value();
-    manufacturerData.ComputeLengthAndData();
-    aGattAdvData.mManufacturerData.AppendElements(manufacturerData.Data(),
-                                                  manufacturerData.Length());
-  }
-
-  if (!aAdvData.mServiceData.IsNull()) {
-    BluetoothUuid uuid;
-    if (NS_WARN_IF(NS_FAILED(StringToUuid(aAdvData.mServiceUuid, uuid)))) {
-      return NS_ERROR_ILLEGAL_VALUE;
-    }
-
-    // First 16 bytes are service UUID in little-endian.
-    for (size_t i = 0; i < sizeof(uuid.mUuid); i++) {
-      aGattAdvData.mServiceData[i] = uuid.mUuid[sizeof(uuid.mUuid) - i - 1];
-    }
-
-    // Concatenate custom service data.
-    const ArrayBuffer& serviceData = aAdvData.mServiceData.Value();
-    serviceData.ComputeLengthAndData();
-    aGattAdvData.mServiceData.AppendElements(serviceData.Data(),
-                                             serviceData.Length());
-  }
-
-  return NS_OK;
-}
-
-void
-GeneratePathFromGattId(const BluetoothGattId& aId,
-                       nsAString& aPath)
-{
-  nsString uuidStr;
-  UuidToString(aId.mUuid, uuidStr);
-
-  aPath.Assign(uuidStr);
-  aPath.AppendLiteral("_");
-  aPath.AppendInt(aId.mInstanceId);
-}
-
-void
-RegisterBluetoothSignalHandler(const nsAString& aPath,
-                               BluetoothSignalObserver* aHandler)
-{
-  MOZ_ASSERT(!aPath.IsEmpty());
-  MOZ_ASSERT(aHandler);
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  bs->RegisterBluetoothSignalHandler(aPath, aHandler);
-  aHandler->SetSignalRegistered(true);
-}
-
-void
-RegisterBluetoothSignalHandler(const BluetoothAddress& aAddress,
-                               BluetoothSignalObserver* aHandler)
-{
-  nsAutoString path;
-  AddressToString(aAddress, path);
-
-  RegisterBluetoothSignalHandler(path, aHandler);
-}
-
-void
-RegisterBluetoothSignalHandler(const BluetoothUuid& aUuid,
-                               BluetoothSignalObserver* aHandler)
-{
-  nsAutoString path;
-  UuidToString(aUuid, path);
-
-  RegisterBluetoothSignalHandler(path, aHandler);
-}
-
-void
-UnregisterBluetoothSignalHandler(const nsAString& aPath,
-                                 BluetoothSignalObserver* aHandler)
-{
-  MOZ_ASSERT(!aPath.IsEmpty());
-  MOZ_ASSERT(aHandler);
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  bs->UnregisterBluetoothSignalHandler(aPath, aHandler);
-  aHandler->SetSignalRegistered(false);
-}
-
-void
-UnregisterBluetoothSignalHandler(const BluetoothAddress& aAddress,
-                                 BluetoothSignalObserver* aHandler)
-{
-  nsAutoString path;
-  AddressToString(aAddress, path);
-
-  UnregisterBluetoothSignalHandler(path, aHandler);
-}
-
-void
-UnregisterBluetoothSignalHandler(const BluetoothUuid& aUuid,
-                                 BluetoothSignalObserver* aHandler)
-{
-  nsAutoString path;
-  UuidToString(aUuid, path);
-
-  UnregisterBluetoothSignalHandler(path, aHandler);
-}
-
-/**
- * |SetJsObject| is an internal function used by |BroadcastSystemMessage| only
- */
-static bool
-SetJsObject(JSContext* aContext,
-            const BluetoothValue& aValue,
-            JS::Handle<JSObject*> aObj)
-{
-  MOZ_ASSERT(aContext && aObj);
-
-  if (aValue.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
-    BT_WARNING("SetJsObject: Invalid parameter type");
-    return false;
-  }
-
-  const nsTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  for (uint32_t i = 0; i < arr.Length(); i++) {
-    JS::Rooted<JS::Value> val(aContext);
-    const BluetoothValue& v = arr[i].value();
-
-    switch(v.type()) {
-       case BluetoothValue::TBluetoothAddress: {
-        nsAutoString addressStr;
-        AddressToString(v.get_BluetoothAddress(), addressStr);
-
-        JSString* jsData = JS_NewUCStringCopyN(aContext,
-                                               addressStr.BeginReading(),
-                                               addressStr.Length());
-        NS_ENSURE_TRUE(jsData, false);
-        val.setString(jsData);
-        break;
-      }
-      case BluetoothValue::TnsString: {
-        JSString* jsData = JS_NewUCStringCopyN(aContext,
-                                     v.get_nsString().BeginReading(),
-                                     v.get_nsString().Length());
-        NS_ENSURE_TRUE(jsData, false);
-        val.setString(jsData);
-        break;
-      }
-      case BluetoothValue::Tuint32_t:
-        val.setInt32(v.get_uint32_t());
-        break;
-      case BluetoothValue::Tbool:
-        val.setBoolean(v.get_bool());
-        break;
-      default:
-        BT_WARNING("SetJsObject: Parameter is not handled");
-        break;
-    }
-
-    if (!JS_SetProperty(aContext, aObj,
-                        NS_ConvertUTF16toUTF8(arr[i].name()).get(),
-                        val)) {
-      BT_WARNING("Failed to set property");
-      return false;
-    }
-  }
-
-  return true;
-}
-
-bool
-BroadcastSystemMessage(const nsAString& aType,
-                       const BluetoothValue& aData)
-{
-  mozilla::AutoSafeJSContext cx;
-  MOZ_ASSERT(!::JS_IsExceptionPending(cx),
-      "Shouldn't get here when an exception is pending!");
-
-  nsCOMPtr<nsISystemMessagesInternal> systemMessenger =
-    do_GetService("@mozilla.org/system-message-internal;1");
-  NS_ENSURE_TRUE(systemMessenger, false);
-
-  JS::Rooted<JS::Value> value(cx);
-  if (aData.type() == BluetoothValue::TnsString) {
-    JSString* jsData = JS_NewUCStringCopyN(cx,
-                                           aData.get_nsString().BeginReading(),
-                                           aData.get_nsString().Length());
-    value.setString(jsData);
-  } else if (aData.type() == BluetoothValue::TArrayOfBluetoothNamedValue) {
-    JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
-    if (!obj) {
-      BT_WARNING("Failed to new JSObject for system message!");
-      return false;
-    }
-
-    if (!SetJsObject(cx, aData, obj)) {
-      BT_WARNING("Failed to set properties of system message!");
-      return false;
-    }
-    value = JS::ObjectValue(*obj);
-  } else {
-    BT_WARNING("Not support the unknown BluetoothValue type");
-    return false;
-  }
-
-  nsCOMPtr<nsISupports> promise;
-  systemMessenger->BroadcastMessage(aType, value,
-                                    JS::UndefinedHandleValue,
-                                    getter_AddRefs(promise));
-
-  return true;
-}
-
-bool
-BroadcastSystemMessage(const nsAString& aType,
-                       const InfallibleTArray<BluetoothNamedValue>& aData)
-{
-  mozilla::AutoSafeJSContext cx;
-  MOZ_ASSERT(!::JS_IsExceptionPending(cx),
-      "Shouldn't get here when an exception is pending!");
-
-  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
-  if (!obj) {
-    BT_WARNING("Failed to new JSObject for system message!");
-    return false;
-  }
-
-  if (!SetJsObject(cx, aData, obj)) {
-    BT_WARNING("Failed to set properties of system message!");
-    return false;
-  }
-
-  nsCOMPtr<nsISystemMessagesInternal> systemMessenger =
-    do_GetService("@mozilla.org/system-message-internal;1");
-  NS_ENSURE_TRUE(systemMessenger, false);
-
-  JS::Rooted<JS::Value> value(cx, JS::ObjectValue(*obj));
-  nsCOMPtr<nsISupports> promise;
-  systemMessenger->BroadcastMessage(aType, value,
-                                    JS::UndefinedHandleValue,
-                                    getter_AddRefs(promise));
-
-  return true;
-}
-
-void
-DispatchReplySuccess(BluetoothReplyRunnable* aRunnable)
-{
-  DispatchReplySuccess(aRunnable, BluetoothValue(true));
-}
-
-void
-DispatchReplySuccess(BluetoothReplyRunnable* aRunnable,
-                     const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aRunnable);
-  MOZ_ASSERT(aValue.type() != BluetoothValue::T__None);
-
-  BluetoothReply* reply = new BluetoothReply(BluetoothReplySuccess(aValue));
-
-  aRunnable->SetReply(reply); // runnable will delete reply after Run()
-  Unused << NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(aRunnable)));
-}
-
-void
-DispatchReplyError(BluetoothReplyRunnable* aRunnable,
-                   const nsAString& aErrorStr)
-{
-  MOZ_ASSERT(aRunnable);
-  MOZ_ASSERT(!aErrorStr.IsEmpty());
-
-  // Reply will be deleted by the runnable after running on main thread
-  BluetoothReply* reply =
-    new BluetoothReply(BluetoothReplyError(STATUS_FAIL, nsString(aErrorStr)));
-
-  aRunnable->SetReply(reply);
-  Unused << NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(aRunnable)));
-}
-
-void
-DispatchReplyError(BluetoothReplyRunnable* aRunnable,
-                   const enum BluetoothStatus aStatus)
-{
-  MOZ_ASSERT(aRunnable);
-  MOZ_ASSERT(aStatus != STATUS_SUCCESS);
-
-  // Reply will be deleted by the runnable after running on main thread
-  BluetoothReply* reply =
-    new BluetoothReply(BluetoothReplyError(aStatus, EmptyString()));
-
-  aRunnable->SetReply(reply);
-  Unused << NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(aRunnable)));
-}
-
-void
-DispatchReplyError(BluetoothReplyRunnable* aRunnable,
-                   const enum BluetoothGattStatus aGattStatus)
-{
-  MOZ_ASSERT(aRunnable);
-
-  // Reply will be deleted by the runnable after running on main thread
-  BluetoothReply* reply =
-    new BluetoothReply(BluetoothReplyError(aGattStatus, EmptyString()));
-
-  aRunnable->SetReply(reply);
-  Unused << NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(aRunnable)));
-}
-
-void
-DispatchStatusChangedEvent(const nsAString& aType,
-                           const BluetoothAddress& aAddress,
-                           bool aStatus)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  InfallibleTArray<BluetoothNamedValue> data;
-  AppendNamedValue(data, "address", aAddress);
-  AppendNamedValue(data, "status", aStatus);
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  bs->DistributeSignal(aType, NS_LITERAL_STRING(KEY_ADAPTER), data);
-}
-
-void
-AppendNamedValue(InfallibleTArray<BluetoothNamedValue>& aArray,
-                 const char* aName, const BluetoothValue& aValue)
-{
-  nsString name;
-  name.AssignASCII(aName);
-
-  aArray.AppendElement(BluetoothNamedValue(name, aValue));
-}
-
-void
-InsertNamedValue(InfallibleTArray<BluetoothNamedValue>& aArray,
-                 uint8_t aIndex, const char* aName,
-                 const BluetoothValue& aValue)
-{
-  nsString name;
-  name.AssignASCII(aName);
-
-  aArray.InsertElementAt(aIndex, BluetoothNamedValue(name, aValue));
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothUtils.h
+++ /dev/null
@@ -1,422 +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_BluetoothUtils_h
-#define mozilla_dom_bluetooth_BluetoothUtils_h
-
-#include "BluetoothCommon.h"
-#include "js/TypeDecls.h"
-
-namespace mozilla {
-namespace dom {
-class GattPermissions;
-class GattCharacteristicProperties;
-class BluetoothAdvertisingData;
-}
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothNamedValue;
-class BluetoothReplyRunnable;
-class BluetoothValue;
-
-/*
- * Each profile has its distinct endianness for multi-byte values
- */
-enum BluetoothProfileEndian {
-  ENDIAN_BIG,
-  ENDIAN_LITTLE,
-  ENDIAN_SDP      = ENDIAN_BIG,     // SDP uses big endian
-  ENDIAN_GAP      = ENDIAN_LITTLE,  // GAP uses little endian
-  ENDIAN_GATT     = ENDIAN_LITTLE,  // GATT uses little endian
-};
-
-/*
- * A UUID is a 128-bit value. To reduce the burden of storing and transferring
- * 128-bit UUID values, a range of UUID values has been pre-allocated for
- * assignment to often-used, registered purposes. UUID values in the
- * pre-allocated range have aliases that are represented as 16-bit or 32-bit
- * values.
- */
-enum BluetoothUuidType {
-  UUID_16_BIT,
-  UUID_32_BIT,
-  UUID_128_BIT,
-};
-
-//
-// Address/String conversion
-//
-
-void
-AddressToString(const BluetoothAddress& aAddress, nsAString& aString);
-
-nsresult
-StringToAddress(const nsAString& aString, BluetoothAddress& aAddress);
-
-//
-// Pin code/string conversion
-//
-
-nsresult
-PinCodeToString(const BluetoothPinCode& aPinCode, nsAString& aString);
-
-nsresult
-StringToPinCode(const nsAString& aString, BluetoothPinCode& aPinCode);
-
-//
-// Play status/string conversion
-//
-
-nsresult
-StringToControlPlayStatus(const nsAString& aString,
-                          ControlPlayStatus& aPlayStatus);
-
-//
-// Property type/string conversion
-//
-
-nsresult
-StringToPropertyType(const nsAString& aString, BluetoothPropertyType& aType);
-
-//
-// Property conversion
-//
-
-nsresult
-NamedValueToProperty(const BluetoothNamedValue& aIn,
-                     BluetoothProperty& aProperty);
-
-//
-// Remote name/string conversion
-//
-
-void
-RemoteNameToString(const BluetoothRemoteName& aRemoteName, nsAString& aString);
-
-//
-// Service name/string conversion
-//
-
-nsresult
-StringToServiceName(const nsAString& aString,
-                    BluetoothServiceName& aServiceName);
-
-//
-// BluetoothUuid <-> uuid string conversion
-//
-
-/**
- * Convert BluetoothUuid object to xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx uuid string.
- *
- * Note: This utility function is used by gecko internal only to convert
- * BluetoothUuid created by bluetooth stack to uuid string representation.
- */
-void
-UuidToString(const BluetoothUuid& aUuid, nsAString& aString);
-
-/**
- * Convert xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx uuid string to BluetoothUuid object.
- *
- * Note: This utility function is used by gecko internal only to convert uuid
- * string created by gecko back to BluetoothUuid representation.
- */
-nsresult
-StringToUuid(const nsAString& aString, BluetoothUuid& aUuid);
-
-/**
- * Convert continuous bytes from nsTArray to BluetoothUuid object.
- * @param aArray [in] The byte array.
- * @param aOffset [in] The offset of continuous bytes of UUID value.
- * @param aType [in] The type of UUID.
- * @param aEndian [in] The endianness of UUID value.
- * @param aUuid [out] The BluetoothUuid object.
- */
-nsresult
-BytesToUuid(const nsTArray<uint8_t>& aArray,
-            nsTArray<uint8_t>::index_type aOffset,
-            BluetoothUuidType aType,
-            BluetoothProfileEndian aEndian,
-            BluetoothUuid& aUuid);
-
-/**
- * Convert BluetoothUuid object to nsTArray with continuous bytes.
- * @param aUuid [in] The BluetoothUuid object.
- * @param aType [in] The type of UUID.
- * @param aEndian [in] The endianness of UUID value.
- * @param aArray [out] The byte array.
- * @param aOffset [in] The offset of continuous bytes of UUID value.
- */
-nsresult
-UuidToBytes(const BluetoothUuid& aUuid,
-            BluetoothUuidType aType,
-            BluetoothProfileEndian aEndian,
-            nsTArray<uint8_t>& aArray,
-            nsTArray<uint8_t>::index_type aOffset);
-
-/**
- * Generate a random uuid.
- *
- * @param aUuid [out] The generated uuid.
- */
-nsresult
-GenerateUuid(BluetoothUuid &aUuid);
-
-/**
- * Generate a random uuid.
- *
- * @param aUuidString [out] String to store the generated uuid.
- */
-nsresult
-GenerateUuid(nsAString &aUuidString);
-
-/**
- * Convert BluetoothGattAttrPerm bit masks to GattPermissions object.
- *
- * @param aBits [in] BluetoothGattAttrPerm bit masks.
- * @param aPermissions [out] GattPermissions object.
- */
-void
-GattPermissionsToDictionary(BluetoothGattAttrPerm aBits,
-                            GattPermissions& aPermissions);
-
-/**
- * Convert GattPermissions object to BluetoothGattAttrPerm bit masks.
- *
- * @param aPermissions [in] GattPermissions object.
- * @param aBits [out] BluetoothGattAttrPerm bit masks.
- */
-void
-GattPermissionsToBits(const GattPermissions& aPermissions,
-                      BluetoothGattAttrPerm& aBits);
-
-/**
- * Convert BluetoothGattCharProp bit masks to GattCharacteristicProperties
- * object.
- *
- * @param aBits [in] BluetoothGattCharProp bit masks.
- * @param aProperties [out] GattCharacteristicProperties object.
- */
-void
-GattPropertiesToDictionary(BluetoothGattCharProp aBits,
-                           GattCharacteristicProperties& aProperties);
-
-/**
- * Convert GattCharacteristicProperties object to BluetoothGattCharProp bit
- * masks.
- *
- * @param aProperties [in] GattCharacteristicProperties object.
- * @param aBits [out] BluetoothGattCharProp bit masks.
- */
-void
-GattPropertiesToBits(const GattCharacteristicProperties& aProperties,
-                     BluetoothGattCharProp& aBits);
-
-//
-// Generate bluetooth signal path from GattId
-//
-
-/**
- * Generate bluetooth signal path from a GattId.
- *
- * @param aId   [in] GattId value to convert.
- * @param aPath [out] Bluetooth signal path generated from aId.
- */
-void
-GeneratePathFromGattId(const BluetoothGattId& aId,
-                       nsAString& aPath);
-
-/**
- * Convert BluetoothAdvertisingData object used by applications to
- * BluetoothGattAdvertisingData object used by gecko backend.
- *
- * @param aAdvData [in] BluetoothAdvertisingData object.
- * @param aGattAdData [out] Target BluetoothGattAdvertisingData.
- * @return NS_OK on success, NS_ERROR_ILLEGAL_VALUE otherwise.
- */
-nsresult
-AdvertisingDataToGattAdvertisingData(
-  const BluetoothAdvertisingData& aAdvData,
-  BluetoothGattAdvertisingData& aGattAdvData);
-
-//
-// Register/Unregister bluetooth signal handlers
-//
-
-/**
- * Register the Bluetooth signal handler.
- *
- * @param aPath Path of the signal to be registered.
- * @param aHandler The message handler object to be added into the observer
- *                 list. Note that this function doesn't take references to it.
- */
-void
-RegisterBluetoothSignalHandler(const nsAString& aPath,
-                               BluetoothSignalObserver* aHandler);
-
-/**
- * Register the Bluetooth signal handler.
- *
- * @param aAddress Address of the signal to be unregistered.
- * @param aHandler The message handler object to be added into the observer
- *                 list. Note that this function doesn't take references to it.
- */
-void
-RegisterBluetoothSignalHandler(const BluetoothAddress& aAddress,
-                               BluetoothSignalObserver* aHandler);
-
-/**
- * Register the Bluetooth signal handler.
- *
- * @param aUuid UUID of the signal to be unregistered.
- * @param aHandler The message handler object to be added into the observer
- *                 list. Note that this function doesn't take references to it.
- */
-void
-RegisterBluetoothSignalHandler(const BluetoothUuid& aUuid,
-                               BluetoothSignalObserver* aHandler);
-
-/**
- * Unregister the Bluetooth signal handler.
- *
- * @param aPath Path of the signal to be unregistered.
- * @param aHandler The message handler object to be removed from the observer
- *                 list. Note that this function doesn't take references to it.
- */
-void
-UnregisterBluetoothSignalHandler(const nsAString& aPath,
-                                 BluetoothSignalObserver* aHandler);
-
-/**
- * Unregister the Bluetooth signal handler.
- *
- * @param aAddress Address of the signal to be unregistered.
- * @param aHandler The message handler object to be removed from the observer
- *                 list. Note that this function doesn't take references to it.
- */
-void
-UnregisterBluetoothSignalHandler(const BluetoothAddress& aAddress,
-                                 BluetoothSignalObserver* aHandler);
-
-/**
- * Unregister the Bluetooth signal handler.
- *
- * @param aUuid UUID of the signal to be unregistered.
- * @param aHandler The message handler object to be removed from the observer
- *                 list. Note that this function doesn't take references to it.
- */
-void
-UnregisterBluetoothSignalHandler(const BluetoothUuid& aUuid,
-                                 BluetoothSignalObserver* aHandler);
-
-//
-// Broadcast system message
-//
-
-bool
-BroadcastSystemMessage(const nsAString& aType,
-                       const BluetoothValue& aData);
-
-bool
-BroadcastSystemMessage(const nsAString& aType,
-                       const InfallibleTArray<BluetoothNamedValue>& aData);
-
-//
-// Dispatch bluetooth reply to main thread
-//
-
-/**
- * Dispatch successful bluetooth reply with NO value to reply request.
- *
- * @param aRunnable  the runnable to reply bluetooth request.
- */
-void
-DispatchReplySuccess(BluetoothReplyRunnable* aRunnable);
-
-/**
- * Dispatch successful bluetooth reply with value to reply request.
- *
- * @param aRunnable  the runnable to reply bluetooth request.
- * @param aValue     the BluetoothValue to reply successful request.
- */
-void
-DispatchReplySuccess(BluetoothReplyRunnable* aRunnable,
-                     const BluetoothValue& aValue);
-
-/**
- * Dispatch failed bluetooth reply with error string.
- *
- * This function is for methods returning DOMRequest. If |aErrorStr| is not
- * empty, the DOMRequest property 'error.name' would be updated to |aErrorStr|
- * before callback function 'onerror' is fired.
- *
- * NOTE: For methods returning Promise, |aErrorStr| would be ignored and only
- * STATUS_FAIL is returned in BluetoothReplyRunnable.
- *
- * @param aRunnable  the runnable to reply bluetooth request.
- * @param aErrorStr  the error string to reply failed request.
- */
-void
-DispatchReplyError(BluetoothReplyRunnable* aRunnable,
-                   const nsAString& aErrorStr);
-
-/**
- * Dispatch failed bluetooth reply with error status.
- *
- * This function is for methods returning Promise. The Promise would reject
- * with an Exception object that carries nsError associated with |aStatus|.
- * The name and messege of Exception (defined in dom/base/domerr.msg) are
- * filled automatically during promise rejection.
- *
- * @param aRunnable  the runnable to reply bluetooth request.
- * @param aStatus    the error status to reply failed request.
- */
-void
-DispatchReplyError(BluetoothReplyRunnable* aRunnable,
-                   const enum BluetoothStatus aStatus);
-
-/**
- * Dispatch failed bluetooth reply with error bluetooth gatt status and
- * string.
- *
- * This function is for bluetooth to return Promise as the error status is
- * bluetooth gatt status.
- *
- * @param aRunnable   the runnable to reply bluetooth request.
- * @param aGattStatus the bluettoh gatt error status to reply failed request.
- */
-void
-DispatchReplyError(BluetoothReplyRunnable* aRunnable,
-                   const enum BluetoothGattStatus aGattStatus);
-
-void
-DispatchStatusChangedEvent(const nsAString& aType,
-                           const BluetoothAddress& aDeviceAddress,
-                           bool aStatus);
-
-//
-// BluetoothNamedValue manipulation
-//
-
-/**
- * Wrap literal name and value into a BluetoothNamedValue and
- * append it to the array.
- */
-void AppendNamedValue(InfallibleTArray<BluetoothNamedValue>& aArray,
-                      const char* aName, const BluetoothValue& aValue);
-
-/**
- * Wrap literal name and value into a BluetoothNamedValue and
- * insert it to the array.
- */
-void InsertNamedValue(InfallibleTArray<BluetoothNamedValue>& aArray,
-                      uint8_t aIndex, const char* aName,
-                      const BluetoothValue& aValue);
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothUtils_h
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothUuidHelper.cpp
+++ /dev/null
@@ -1,85 +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 "BluetoothUuidHelper.h"
-
-#include "BluetoothA2dpManager.h"
-#include "BluetoothAvrcpManager.h"
-#include "BluetoothHfpManager.h"
-#include "BluetoothHidManager.h"
-#include "BluetoothOppManager.h"
-
-USING_BLUETOOTH_NAMESPACE
-
-BluetoothServiceClass
-BluetoothUuidHelper::GetBluetoothServiceClass(const nsAString& aUuidStr)
-{
-  // An example of input UUID string: 0000110D-0000-1000-8000-00805F9B34FB
-  MOZ_ASSERT(aUuidStr.Length() == 36);
-
-  /**
-   * Extract uuid16 from input UUID string and return a value of enum
-   * BluetoothServiceClass. If we failed to recognize the value,
-   * BluetoothServiceClass::UNKNOWN is returned.
-   */
-  BluetoothServiceClass retValue = BluetoothServiceClass::UNKNOWN;
-  nsString uuid(Substring(aUuidStr, 4, 4));
-
-  nsresult rv;
-  int32_t integer = uuid.ToInteger(&rv, 16);
-  NS_ENSURE_SUCCESS(rv, retValue);
-
-  return GetBluetoothServiceClass(integer);
-}
-
-BluetoothServiceClass
-BluetoothUuidHelper::GetBluetoothServiceClass(uint16_t aServiceUuid)
-{
-  BluetoothServiceClass retValue = BluetoothServiceClass::UNKNOWN;
-  switch (aServiceUuid) {
-    case BluetoothServiceClass::A2DP:
-    case BluetoothServiceClass::A2DP_SINK:
-    case BluetoothServiceClass::AVRCP:
-    case BluetoothServiceClass::AVRCP_TARGET:
-    case BluetoothServiceClass::AVRCP_CONTROLLER:
-    case BluetoothServiceClass::HANDSFREE:
-    case BluetoothServiceClass::HANDSFREE_AG:
-    case BluetoothServiceClass::HEADSET:
-    case BluetoothServiceClass::HEADSET_AG:
-    case BluetoothServiceClass::HID:
-    case BluetoothServiceClass::OBJECT_PUSH:
-      retValue = (BluetoothServiceClass)aServiceUuid;
-  }
-  return retValue;
-}
-
-BluetoothProfileManagerBase*
-BluetoothUuidHelper::GetBluetoothProfileManager(uint16_t aServiceUuid)
-{
-  BluetoothProfileManagerBase* profile;
-  BluetoothServiceClass serviceClass = GetBluetoothServiceClass(aServiceUuid);
-  switch (serviceClass) {
-    case BluetoothServiceClass::HANDSFREE:
-    case BluetoothServiceClass::HEADSET:
-      profile = BluetoothHfpManager::Get();
-      break;
-    case BluetoothServiceClass::HID:
-      profile = BluetoothHidManager::Get();
-      break;
-    case BluetoothServiceClass::A2DP:
-      profile = BluetoothA2dpManager::Get();
-      break;
-    case BluetoothServiceClass::AVRCP:
-      profile = BluetoothAvrcpManager::Get();
-      break;
-    case BluetoothServiceClass::OBJECT_PUSH:
-      profile = BluetoothOppManager::Get();
-      break;
-    default:
-      profile = nullptr;
-  }
-  return profile;
-}
deleted file mode 100644
--- a/dom/bluetooth/common/BluetoothUuidHelper.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_BluetoothUuidHelper_h
-#define mozilla_dom_bluetooth_BluetoothUuidHelper_h
-
-#include "BluetoothCommon.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothProfileManagerBase;
-
-class BluetoothUuidHelper
-{
-public:
-
-  /**
-   * Convert a 128-bit uuid string to a value of BluetoothServiceClass
-   *
-   * @param aUuidStr  128-bit uuid string
-   * @return  a value of BluetoothServiceClass
-   */
-  static BluetoothServiceClass
-  GetBluetoothServiceClass(const nsAString& aUuidStr);
-
-  static BluetoothServiceClass
-  GetBluetoothServiceClass(uint16_t aServiceUuid);
-
-  static BluetoothProfileManagerBase*
-  GetBluetoothProfileManager(uint16_t aServiceUuid);
-};
-
-// TODO/qdot: Move these back into gonk and make the service handler deal with
-// it there.
-//
-// Gotten from reading the "u8" values in B2G/external/bluez/src/adapter.c
-// These were hardcoded into android
-enum BluetoothReservedChannels {
-  CHANNEL_DIALUP_NETWORK = 1,
-  CHANNEL_HANDSFREE_AG   = 10,
-  CHANNEL_HEADSET_AG     = 11,
-  CHANNEL_OPUSH          = 12,
-  CHANNEL_SIM_ACCESS     = 15,
-  CHANNEL_PBAP_PSE       = 19,
-  CHANNEL_FTP            = 20,
-  CHANNEL_OPUSH_L2CAP    = 5255
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothUuidHelper_h
deleted file mode 100644
--- a/dom/bluetooth/common/ObexBase.cpp
+++ /dev/null
@@ -1,196 +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 "ObexBase.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-//
-// Internal functions
-//
-
-/**
- * Append byte array and length to header
- */
-int
-AppendHeader(uint8_t aHeaderId, uint8_t* aRetBuf, int aBufferSize,
-             const uint8_t* aData, int aLength)
-{
-  int headerLength = aLength + 3;
-  int writtenLength = (headerLength < aBufferSize) ? headerLength : aBufferSize;
-
-  aRetBuf[0] = aHeaderId;
-  BigEndian::writeUint16(&aRetBuf[1], headerLength);
-  memcpy(&aRetBuf[3], aData, writtenLength - 3);
-
-  return writtenLength;
-}
-
-/**
- * Append 4-byte integer to header
- */
-int
-AppendHeader(uint8_t aHeaderId, uint8_t* aRetBuf, int aValue)
-{
-  aRetBuf[0] = aHeaderId;
-  BigEndian::writeInt32(&aRetBuf[1], aValue);
-
-  return 5;
-}
-
-//
-// Exposed functions
-//
-
-int
-AppendHeaderName(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aName,
-                 int aLength)
-{
-  return AppendHeader(ObexHeaderId::Name, aRetBuf, aBufferSize,
-                      aName, aLength);
-}
-
-int
-AppendHeaderBody(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aBody,
-                 int aLength)
-{
-  return AppendHeader(ObexHeaderId::Body, aRetBuf, aBufferSize,
-                      aBody, aLength);
-}
-
-int
-AppendHeaderTarget(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aTarget,
-                   int aLength)
-{
-  return AppendHeader(ObexHeaderId::Target, aRetBuf, aBufferSize,
-                      aTarget, aLength);
-}
-
-int
-AppendHeaderWho(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aWho,
-                int aLength)
-{
-  return AppendHeader(ObexHeaderId::Who, aRetBuf, aBufferSize,
-                      aWho, aLength);
-}
-
-int
-AppendAuthResponse(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aDigest,
-                   int aLength)
-{
-  return AppendHeader(ObexHeaderId::AuthResponse, aRetBuf, aBufferSize,
-                      aDigest, aLength);
-}
-
-int
-AppendHeaderAppParameters(uint8_t* aRetBuf, int aBufferSize,
-                          const uint8_t* aAppParameters, int aLength)
-{
-  return AppendHeader(ObexHeaderId::AppParameters, aRetBuf, aBufferSize,
-                      aAppParameters, aLength);
-}
-
-int
-AppendAppParameter(uint8_t* aRetBuf, int aBufferSize, const uint8_t aTagId,
-                   const uint8_t* aValue, int aLength)
-{
-  // An application parameter is a [tag]-[length]-[value] triplet. The [tag] and
-  // [length] fields are 1-byte length each.
-
-  if (aBufferSize < aLength + 2) {
-    // aBufferSize should be larger than size of AppParameter + header.
-    BT_WARNING("Return buffer size is too small for the AppParameter");
-    return 0;
-  }
-
-  aRetBuf[0] = aTagId;
-  aRetBuf[1] = aLength;
-  memcpy(&aRetBuf[2], aValue, aLength);
-
-  return aLength + 2;
-}
-
-int
-AppendHeaderLength(uint8_t* aRetBuf, int aObjectLength)
-{
-  return AppendHeader(ObexHeaderId::Length, aRetBuf, aObjectLength);
-}
-
-int
-AppendHeaderConnectionId(uint8_t* aRetBuf, int aConnectionId)
-{
-  return AppendHeader(ObexHeaderId::ConnectionId, aRetBuf, aConnectionId);
-}
-
-int
-AppendHeaderEndOfBody(uint8_t* aRetBuf)
-{
-  aRetBuf[0] = ObexHeaderId::EndOfBody;
-  aRetBuf[1] = 0x00;
-  aRetBuf[2] = 0x03;
-
-  return 3;
-}
-
-void
-SetObexPacketInfo(uint8_t* aRetBuf, uint8_t aOpcode, int aPacketLength)
-{
-  aRetBuf[0] = aOpcode;
-  BigEndian::writeUint16(&aRetBuf[1], aPacketLength);
-}
-
-bool
-ParseHeaders(const uint8_t* aHeaderStart,
-             int aTotalLength,
-             ObexHeaderSet* aRetHandlerSet)
-{
-  const uint8_t* ptr = aHeaderStart;
-
-  while (ptr - aHeaderStart < aTotalLength) {
-    ObexHeaderId headerId = (ObexHeaderId)*ptr++;
-
-    uint16_t contentLength = 0;
-
-    // Defined in 2.1 OBEX Headers, IrOBEX 1.2
-    switch (headerId >> 6)
-    {
-      case 0x00:
-        // Null-terminated Unicode text, length prefixed with 2-byte
-        // unsigned integer.
-      case 0x01:
-        // byte sequence, length prefixed with 2 byte unsigned integer.
-        contentLength = BigEndian::readUint16(ptr) - 3;
-        ptr += 2;
-        break;
-
-      case 0x02:
-        // 1 byte quantity
-        contentLength = 1;
-        break;
-
-      case 0x03:
-        // 4 byte quantity
-        contentLength = 4;
-        break;
-    }
-
-    // Length check to prevent from memory pollution.
-    if (ptr + contentLength > aHeaderStart + aTotalLength) {
-      // Severe error occurred. We can't even believe the received data, so
-      // clear all headers.
-      MOZ_ASSERT(false);
-      aRetHandlerSet->ClearHeaders();
-      return false;
-    }
-
-    aRetHandlerSet->AddHeader(new ObexHeader(headerId, contentLength, ptr));
-    ptr += contentLength;
-  }
-
-  return true;
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/common/ObexBase.h
+++ /dev/null
@@ -1,367 +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_ObexBase_h
-#define mozilla_dom_bluetooth_ObexBase_h
-
-#include "BluetoothCommon.h"
-#include "mozilla/EndianUtils.h"
-#include "mozilla/UniquePtr.h"
-#include "nsTArray.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-const char FINAL_BIT = 0x80;
-
-/**
- * Section 3.2 "Response format", IrOBEX ver 1.2
- * The format of an OBEX response header is
- * [response code:1][response length:2]
- */
-static const uint32_t kObexRespHeaderSize = 3;
-
-/**
- * Section 2.2.9 "Body, End-of-Body", IrOBEX ver 1.2
- * The format of an OBEX Body header is
- * [headerId:1][header length:2]
- */
-static const uint32_t kObexBodyHeaderSize = 3;
-
-/**
- * Section 3.3.1.4 "Minimum OBEX Packet Length", IrOBEX ver 1.2
- * The minimum size of the OBEX Maximum packet length allowed for negotiation is
- * 255 bytes.
- */
-static const uint32_t kObexLeastMaxSize = 255;
-
-/*
- * Defined in section 2.1 "OBEX Headers", IrOBEX ver 1.2
- */
-enum ObexHeaderId {
-  Count = 0xC0,
-  Name = 0x01,
-  Type = 0x42,
-  Length = 0xC3,
-  TimeISO8601 = 0x44,
-  Time4Byte = 0xC4,
-  Description = 0x05,
-  Target = 0x46,
-  HTTP = 0x47,
-  Body = 0x48,
-  EndOfBody = 0x49,
-  Who = 0x4A,
-  ConnectionId = 0xCB,
-  AppParameters = 0x4C,
-  AuthChallenge = 0x4D,
-  AuthResponse = 0x4E,
-  ObjectClass = 0x4F
-};
-
-/*
- * Defined in section 3.3 "OBEX Operations and Opcode definitions",
- * IrOBEX ver 1.2
- */
-enum ObexRequestCode {
-  Connect = 0x80,
-  Disconnect = 0x81,
-  Put = 0x02,
-  PutFinal = 0x82,
-  Get = 0x03,
-  GetFinal = 0x83,
-  SetPath = 0x85,
-  Abort = 0xFF
-};
-
-/*
- * Defined in section 3.2.1 "Response Code values", IrOBEX ver 1.2
- */
-enum ObexResponseCode {
-  Continue = 0x90,
-
-  Success = 0xA0,
-  Created = 0xA1,
-  Accepted = 0xA2,
-  NonAuthoritativeInfo = 0xA3,
-  NoContent = 0xA4,
-  ResetContent = 0xA5,
-  PartialContent = 0xA6,
-
-  MultipleChoices = 0xB0,
-  MovedPermanently = 0xB1,
-  MovedTemporarily = 0xB2,
-  SeeOther = 0xB3,
-  NotModified = 0xB4,
-  UseProxy = 0xB5,
-
-  BadRequest = 0xC0,
-  Unauthorized = 0xC1,
-  PaymentRequired = 0xC2,
-  Forbidden = 0xC3,
-  NotFound = 0xC4,
-  MethodNotAllowed = 0xC5,
-  NotAcceptable = 0xC6,
-  ProxyAuthenticationRequired = 0xC7,
-  RequestTimeOut = 0xC8,
-  Conflict = 0xC9,
-  Gone = 0xCA,
-  LengthRequired = 0xCB,
-  PreconditionFailed = 0xCC,
-  RequestedEntityTooLarge = 0xCD,
-  RequestUrlTooLarge = 0xCE,
-  UnsupprotedMediaType = 0xCF,
-
-  InternalServerError = 0xD0,
-  NotImplemented = 0xD1,
-  BadGateway = 0xD2,
-  ServiceUnavailable = 0xD3,
-  GatewayTimeout = 0xD4,
-  HttpVersionNotSupported = 0xD5,
-
-  DatabaseFull = 0xE0,
-  DatabaseLocked = 0xE1,
-};
-
-enum ObexDigestChallenge {
-  Nonce = 0x00,
-  Options = 0x01,
-  Realm = 0x02
-};
-
-enum ObexDigestResponse {
-  ReqDigest = 0x00,
-  UserId = 0x01,
-  NonceChallenged = 0x02
-};
-
-class ObexHeader
-{
-public:
-  ObexHeader(ObexHeaderId aId, int aDataLength, const uint8_t* aData)
-    : mId(aId)
-    , mDataLength(aDataLength)
-    , mData(nullptr)
-  {
-    mData.reset(new uint8_t[mDataLength]);
-    memcpy(mData.get(), aData, aDataLength);
-  }
-
-  ~ObexHeader()
-  {
-  }
-
-  ObexHeaderId mId;
-  int mDataLength;
-  UniquePtr<uint8_t[]> mData;
-};
-
-class ObexHeaderSet
-{
-public:
-  ObexHeaderSet()
-  {
-  }
-
-  ~ObexHeaderSet()
-  {
-  }
-
-  void AddHeader(ObexHeader* aHeader)
-  {
-    mHeaders.AppendElement(aHeader);
-  }
-
-  void GetName(nsString& aRetName) const
-  {
-    aRetName.Truncate();
-
-    int length = mHeaders.Length();
-
-    for (int i = 0; i < length; ++i) {
-      if (mHeaders[i]->mId == ObexHeaderId::Name) {
-        /*
-         * According to section 2.2.2 [Name] of IrOBEX spec, we know that
-         * the Name header is "a null terminated Unicode text string describing
-         * the name of the object.", and that's the reason why we need to minus
-         * 1 to get the real length of the file name.
-         */
-        int nameLength = mHeaders[i]->mDataLength / 2 - 1;
-        uint8_t* ptr = mHeaders[i]->mData.get();
-
-        for (int j = 0; j < nameLength; ++j) {
-          char16_t c = BigEndian::readUint16(&ptr[j * 2]);
-          aRetName += c;
-        }
-
-        break;
-      }
-    }
-  }
-
-  void GetContentType(nsString& aRetContentType) const
-  {
-    aRetContentType.Truncate();
-
-    int length = mHeaders.Length();
-
-    for (int i = 0; i < length; ++i) {
-      if (mHeaders[i]->mId == ObexHeaderId::Type) {
-        uint8_t* ptr = mHeaders[i]->mData.get();
-        aRetContentType.AssignASCII((const char*)ptr);
-        break;
-      }
-    }
-  }
-
-  // @return file length, 0 means file length is unknown.
-  void GetLength(uint32_t* aRetLength) const
-  {
-    int length = mHeaders.Length();
-    *aRetLength = 0;
-
-    for (int i = 0; i < length; ++i) {
-      if (mHeaders[i]->mId == ObexHeaderId::Length) {
-        uint8_t* ptr = mHeaders[i]->mData.get();
-        *aRetLength = BigEndian::readUint32(&ptr[0]);
-        return;
-      }
-    }
-  }
-
-  void GetBody(uint8_t** aRetBody, int* aRetBodyLength) const
-  {
-    int length = mHeaders.Length();
-    *aRetBody = nullptr;
-    *aRetBodyLength = 0;
-
-    for (int i = 0; i < length; ++i) {
-      if (mHeaders[i]->mId == ObexHeaderId::Body ||
-          mHeaders[i]->mId == ObexHeaderId::EndOfBody) {
-        uint8_t* ptr = mHeaders[i]->mData.get();
-        *aRetBody = new uint8_t[mHeaders[i]->mDataLength];
-        memcpy(*aRetBody, ptr, mHeaders[i]->mDataLength);
-        *aRetBodyLength = mHeaders[i]->mDataLength;
-        return;
-      }
-    }
-  }
-
-  uint32_t GetConnectionId() const
-  {
-    int length = mHeaders.Length();
-
-    for (int i = 0; i < length; ++i) {
-      if (mHeaders[i]->mId == ObexHeaderId::ConnectionId) {
-        uint32_t* id = (uint32_t *) mHeaders[i]->mData.get();
-        return *id;
-      }
-    }
-
-    // According to OBEX spec., the value 0xFFFFFFFF is reserved and it's
-    // considered invalid for Connection ID.
-    return 0xFFFFFFFF;
-  }
-
-  /**
-   * Get a specified parameter from the 'Application Parameters' header with
-   * big-endian byte ordering.
-   *
-   * @param aTagId      [in]  The tag ID of parameter which is defined by
-   *                          applications or upper protocol layer.
-   * @param aRetBuf     [out] The buffer which is used to return the parameter.
-   * @param aBufferSize [in]  The size of the given buffer.
-   *
-   * @return a boolean value to indicate whether the given paramter exists.
-   */
-  bool GetAppParameter(uint8_t aTagId, uint8_t* aRetBuf, int aBufferSize) const
-  {
-    int length = mHeaders.Length();
-
-    for (int i = 0; i < length; ++i) {
-      // Parse the 'Application Parameters' header.
-      if (mHeaders[i]->mId == ObexHeaderId::AppParameters) {
-        uint8_t* ptr = mHeaders[i]->mData.get();
-        int dataLen = mHeaders[i]->mDataLength;
-
-        // An application parameters header may contain more than one
-        // [tag]-[length]-[value] triplet. The [tag] and [length] fields are
-        // each one byte in length.
-        uint8_t tagId;
-        uint8_t offset = 0;
-        do {
-          tagId = *(ptr + offset++);
-
-          // The length of value field, it should not exceed 255.
-          uint8_t paramLen = *(ptr + offset++);
-
-          if (tagId == aTagId) {
-            memcpy(aRetBuf, ptr + offset, paramLen < aBufferSize ? paramLen
-                                                                 : aBufferSize);
-            return true;
-          }
-
-          offset += paramLen;
-        } while (offset < dataLen);
-      }
-    }
-
-    // The specified parameter don't exist in 'Application Parameters' header.
-    return false;
-  }
-
-  const ObexHeader* GetHeader(ObexHeaderId aId) const
-  {
-    for (int i = 0, length = mHeaders.Length(); i < length; ++i) {
-      if (mHeaders[i]->mId == aId) {
-        return mHeaders[i].get();
-      }
-    }
-
-    return nullptr;
-  }
-
-  bool Has(ObexHeaderId aId) const
-  {
-    return !!GetHeader(aId);
-  }
-
-  void ClearHeaders()
-  {
-    mHeaders.Clear();
-  }
-
-private:
-  nsTArray<UniquePtr<ObexHeader> > mHeaders;
-};
-
-int AppendHeaderName(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aName,
-                     int aLength);
-int AppendHeaderBody(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aBody,
-                     int aLength);
-int AppendHeaderTarget(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aTarget,
-                       int aLength);
-int AppendHeaderWho(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aWho,
-                    int aLength);
-int AppendAuthResponse(uint8_t* aRetBuf, int aBufferSize,
-                       const uint8_t* aDigest, int aLength);
-int AppendHeaderAppParameters(uint8_t* aRetBuf, int aBufferSize,
-                              const uint8_t* aAppParameters, int aLength);
-int AppendAppParameter(uint8_t* aRetBuf, int aBufferSize, const uint8_t aTagId,
-                       const uint8_t* aValue, int aLength);
-int AppendHeaderLength(uint8_t* aRetBuf, int aObjectLength);
-int AppendHeaderConnectionId(uint8_t* aRetBuf, int aConnectionId);
-int AppendHeaderEndOfBody(uint8_t* aRetBuf);
-void SetObexPacketInfo(uint8_t* aRetBuf, uint8_t aOpcode, int aPacketLength);
-
-/**
- * @return true when the message was parsed without any error, false otherwise.
- */
-bool ParseHeaders(const uint8_t* aHeaderStart,
-                  int aTotalLength,
-                  ObexHeaderSet* aRetHanderSet);
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_ObexBase_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothAdapter.cpp
+++ /dev/null
@@ -1,2106 +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 "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-#include "BluetoothUtils.h"
-#include "DOMRequest.h"
-#include "nsIDocument.h"
-#include "nsIPrefBranch.h"
-#include "nsIPrefService.h"
-#include "nsIPrincipal.h"
-#include "nsTArrayHelpers.h"
-
-#include "mozilla/dom/BluetoothAdapterBinding.h"
-#include "mozilla/dom/BluetoothAttributeEvent.h"
-#include "mozilla/dom/BluetoothMapFolderListingEvent.h"
-#include "mozilla/dom/BluetoothMapGetMessageEvent.h"
-#include "mozilla/dom/BluetoothMapMessagesListingEvent.h"
-#include "mozilla/dom/BluetoothMapMessageUpdateEvent.h"
-#include "mozilla/dom/BluetoothMapSetMessageStatusEvent.h"
-#include "mozilla/dom/BluetoothMapSendMessageEvent.h"
-#include "mozilla/dom/BluetoothObexAuthEvent.h"
-#include "mozilla/dom/BluetoothPhonebookPullingEvent.h"
-#include "mozilla/dom/BluetoothStatusChangedEvent.h"
-#include "mozilla/dom/BluetoothVCardListingEvent.h"
-#include "mozilla/dom/BluetoothVCardPullingEvent.h"
-#include "mozilla/dom/ContentChild.h"
-#include "mozilla/dom/Event.h"
-#include "mozilla/dom/File.h"
-
-#include "mozilla/dom/bluetooth/BluetoothAdapter.h"
-#include "mozilla/dom/bluetooth/BluetoothClassOfDevice.h"
-#include "mozilla/dom/bluetooth/BluetoothDevice.h"
-#include "mozilla/dom/bluetooth/BluetoothDiscoveryHandle.h"
-#include "mozilla/dom/bluetooth/BluetoothGattServer.h"
-#include "mozilla/dom/bluetooth/BluetoothObexAuthHandle.h"
-#include "mozilla/dom/bluetooth/BluetoothPairingListener.h"
-#include "mozilla/dom/bluetooth/BluetoothPbapRequestHandle.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-
-using namespace mozilla;
-using namespace mozilla::dom;
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothAdapter)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothAdapter,
-                                                DOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mDevices)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mDiscoveryHandleInUse)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mPairingReqs)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mLeScanHandleArray)
-
-  /**
-   * Unregister the bluetooth signal handler after unlinked.
-   *
-   * This is needed to avoid ending up with exposing a deleted object to JS or
-   * accessing deleted objects while receiving signals from parent process
-   * after unlinked. Please see Bug 1138267 for detail informations.
-   */
-  UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_ADAPTER), tmp);
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothAdapter,
-                                                  DOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDevices)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDiscoveryHandleInUse)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPairingReqs)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLeScanHandleArray)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-// QueryInterface implementation for BluetoothAdapter
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothAdapter)
-NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
-
-NS_IMPL_ADDREF_INHERITED(BluetoothAdapter, DOMEventTargetHelper)
-NS_IMPL_RELEASE_INHERITED(BluetoothAdapter, DOMEventTargetHelper)
-
-class StartDiscoveryTask final : public BluetoothReplyRunnable
-{
-public:
-  StartDiscoveryTask(BluetoothAdapter* aAdapter, Promise* aPromise)
-    : BluetoothReplyRunnable(nullptr, aPromise)
-    , mAdapter(aAdapter)
-  {
-    MOZ_ASSERT(aPromise);
-    MOZ_ASSERT(aAdapter);
-  }
-
-  bool
-  ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue)
-  {
-    aValue.setUndefined();
-
-    AutoJSAPI jsapi;
-    NS_ENSURE_TRUE(jsapi.Init(mAdapter->GetParentObject()), false);
-    JSContext* cx = jsapi.cx();
-
-    /**
-     * Create a new discovery handle and wrap it to return. Each
-     * discovery handle is one-time-use only.
-     */
-    RefPtr<BluetoothDiscoveryHandle> discoveryHandle =
-      BluetoothDiscoveryHandle::Create(mAdapter->GetParentObject());
-    if (!ToJSValue(cx, discoveryHandle, aValue)) {
-      jsapi.ClearException();
-      return false;
-    }
-
-    // Set the created discovery handle as the one in use.
-    mAdapter->SetDiscoveryHandleInUse(discoveryHandle);
-    return true;
-  }
-
-  virtual void
-  ReleaseMembers() override
-  {
-    BluetoothReplyRunnable::ReleaseMembers();
-    mAdapter = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothAdapter> mAdapter;
-};
-
-class StartLeScanTask final : public BluetoothReplyRunnable
-{
-public:
-  StartLeScanTask(BluetoothAdapter* aAdapter, Promise* aPromise,
-                  const nsTArray<BluetoothUuid>& aServiceUuids)
-    : BluetoothReplyRunnable(nullptr, aPromise)
-    , mAdapter(aAdapter)
-    , mServiceUuids(aServiceUuids)
-  {
-    MOZ_ASSERT(aPromise);
-    MOZ_ASSERT(aAdapter);
-  }
-
-  bool
-  ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue)
-  {
-    aValue.setUndefined();
-
-    AutoJSAPI jsapi;
-    NS_ENSURE_TRUE(jsapi.Init(mAdapter->GetParentObject()), false);
-    JSContext* cx = jsapi.cx();
-
-    const BluetoothValue& v = mReply->get_BluetoothReplySuccess().value();
-    NS_ENSURE_TRUE(v.type() == BluetoothValue::TBluetoothUuid, false);
-
-    /**
-     * Create a new discovery handle and wrap it to return. Each
-     * discovery handle is one-time-use only.
-     */
-    RefPtr<BluetoothDiscoveryHandle> discoveryHandle =
-      BluetoothDiscoveryHandle::Create(mAdapter->GetParentObject(),
-                                       mServiceUuids, v.get_BluetoothUuid());
-
-    if (!ToJSValue(cx, discoveryHandle, aValue)) {
-      jsapi.ClearException();
-      return false;
-    }
-
-    // Append a BluetoothDiscoveryHandle to LeScan handle array.
-    mAdapter->AppendLeScanHandle(discoveryHandle);
-
-    return true;
-  }
-
-  virtual void
-  ReleaseMembers() override
-  {
-    BluetoothReplyRunnable::ReleaseMembers();
-    mAdapter = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothAdapter> mAdapter;
-  nsTArray<BluetoothUuid> mServiceUuids;
-};
-
-class StopLeScanTask final : public BluetoothReplyRunnable
-{
-public:
-  StopLeScanTask(BluetoothAdapter* aAdapter,
-                 Promise* aPromise,
-                 const BluetoothUuid& aScanUuid)
-      : BluetoothReplyRunnable(nullptr, aPromise)
-      , mAdapter(aAdapter)
-      , mScanUuid(aScanUuid)
-  {
-    MOZ_ASSERT(aPromise);
-    MOZ_ASSERT(aAdapter);
-    MOZ_ASSERT(!aScanUuid.IsCleared());
-  }
-
-protected:
-  virtual bool
-  ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue) override
-  {
-    mAdapter->RemoveLeScanHandle(mScanUuid);
-    aValue.setUndefined();
-    return true;
-  }
-
-  virtual void
-  ReleaseMembers() override
-  {
-    BluetoothReplyRunnable::ReleaseMembers();
-    mAdapter = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothAdapter> mAdapter;
-  BluetoothUuid mScanUuid;
-};
-
-class GetDevicesTask : public BluetoothReplyRunnable
-{
-public:
-  GetDevicesTask(BluetoothAdapter* aAdapterPtr, nsIDOMDOMRequest* aReq)
-    : BluetoothReplyRunnable(aReq)
-    , mAdapterPtr(aAdapterPtr)
-  {
-    MOZ_ASSERT(aReq && aAdapterPtr);
-  }
-
-  virtual bool ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue)
-  {
-    aValue.setUndefined();
-
-    const BluetoothValue& v = mReply->get_BluetoothReplySuccess().value();
-    if (v.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
-      BT_WARNING("Not a BluetoothNamedValue array!");
-      SetError(NS_LITERAL_STRING("BluetoothReplyTypeError"));
-      return false;
-    }
-
-    const InfallibleTArray<BluetoothNamedValue>& values =
-      v.get_ArrayOfBluetoothNamedValue();
-
-    nsTArray<RefPtr<BluetoothDevice> > devices;
-    for (uint32_t i = 0; i < values.Length(); i++) {
-      const BluetoothValue properties = values[i].value();
-      if (properties.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
-        BT_WARNING("Not a BluetoothNamedValue array!");
-        SetError(NS_LITERAL_STRING("BluetoothReplyTypeError"));
-        return false;
-      }
-      RefPtr<BluetoothDevice> d =
-        BluetoothDevice::Create(mAdapterPtr->GetOwner(),
-                                properties);
-      devices.AppendElement(d);
-    }
-
-    AutoJSAPI jsapi;
-    if (!jsapi.Init(mAdapterPtr->GetOwner())) {
-      BT_WARNING("Failed to initialise AutoJSAPI!");
-      SetError(NS_LITERAL_STRING("BluetoothAutoJSAPIInitError"));
-      return false;
-    }
-    JSContext* cx = jsapi.cx();
-    JS::Rooted<JSObject*> JsDevices(cx);
-    if (NS_FAILED(nsTArrayToJSArray(cx, devices, &JsDevices))) {
-      BT_WARNING("Cannot create JS array!");
-      SetError(NS_LITERAL_STRING("BluetoothError"));
-      return false;
-    }
-
-    aValue.setObject(*JsDevices);
-    return true;
-  }
-
-  void
-  ReleaseMembers()
-  {
-    BluetoothReplyRunnable::ReleaseMembers();
-    mAdapterPtr = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothAdapter> mAdapterPtr;
-};
-
-class GetScoConnectionStatusTask : public BluetoothReplyRunnable
-{
-public:
-  GetScoConnectionStatusTask(nsIDOMDOMRequest* aReq) :
-    BluetoothReplyRunnable(aReq)
-  {
-    MOZ_ASSERT(aReq);
-  }
-
-  virtual bool ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue)
-  {
-    aValue.setUndefined();
-
-    const BluetoothValue& v = mReply->get_BluetoothReplySuccess().value();
-    if (v.type() != BluetoothValue::Tbool) {
-      BT_WARNING("Not a boolean!");
-      SetError(NS_LITERAL_STRING("BluetoothReplyTypeError"));
-      return false;
-    }
-
-    aValue.setBoolean(v.get_bool());
-    return true;
-  }
-
-  void
-  ReleaseMembers()
-  {
-    BluetoothReplyRunnable::ReleaseMembers();
-  }
-};
-
-static int kCreatePairedDeviceTimeout = 50000; // unit: msec
-
-BluetoothAdapter::BluetoothAdapter(nsPIDOMWindowInner* aWindow,
-                                   const BluetoothValue& aValue)
-  : DOMEventTargetHelper(aWindow)
-  , mState(BluetoothAdapterState::Disabled)
-  , mDiscoverable(false)
-  , mDiscovering(false)
-  , mPairingReqs(nullptr)
-  , mDiscoveryHandleInUse(nullptr)
-{
-  MOZ_ASSERT(aWindow);
-
-  // Only allow certified bluetooth application to receive pairing requests
-  if (IsBluetoothCertifiedApp()) {
-    mPairingReqs = BluetoothPairingListener::Create(aWindow);
-  }
-
-  const InfallibleTArray<BluetoothNamedValue>& values =
-    aValue.get_ArrayOfBluetoothNamedValue();
-  for (uint32_t i = 0; i < values.Length(); ++i) {
-    SetPropertyByValue(values[i]);
-  }
-
-  RegisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_ADAPTER), this);
-}
-
-BluetoothAdapter::~BluetoothAdapter()
-{
-  Cleanup();
-}
-
-void
-BluetoothAdapter::DisconnectFromOwner()
-{
-  DOMEventTargetHelper::DisconnectFromOwner();
-  Cleanup();
-}
-
-void
-BluetoothAdapter::Cleanup()
-{
-  UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_ADAPTER), this);
-
-  // Stop ongoing LE scans and clear the LeScan handle array
-  if (!mLeScanHandleArray.IsEmpty()) {
-    BluetoothService* bs = BluetoothService::Get();
-    NS_ENSURE_TRUE_VOID(bs);
-
-    for (size_t i = 0; i < mLeScanHandleArray.Length(); ++i) {
-      BluetoothUuid uuid;
-      mLeScanHandleArray[i]->GetLeScanUuid(uuid);
-      RefPtr<BluetoothVoidReplyRunnable> results =
-        new BluetoothVoidReplyRunnable(nullptr);
-      bs->StopLeScanInternal(uuid, results);
-    }
-    mLeScanHandleArray.Clear();
-  }
-}
-
-BluetoothGattServer*
-BluetoothAdapter::GetGattServer()
-{
-  /* Only expose GATT server if the adapter is enabled. It would be worth
-   * noting that the enabling state and the disabling state are just
-   * intermediate states, and the adapter would change into the enabled state
-   * or the disabled state sooner or later. So we invalidate and nullify the
-   * created GATT server object only when the adapter changes to a steady
-   * state, i.e., the disabled state.
-   */
-  if (mState != BluetoothAdapterState::Enabled) {
-    return nullptr;
-  }
-
-  if (!mGattServer) {
-    mGattServer = new BluetoothGattServer(GetOwner());
-  }
-
-  return mGattServer;
-}
-
-void
-BluetoothAdapter::GetPairedDeviceProperties(
-  const nsTArray<nsString>& aDeviceAddresses)
-{
-  nsTArray<BluetoothAddress> deviceAddresses;
-  deviceAddresses.SetLength(aDeviceAddresses.Length());
-
-  for (size_t i = 0; i < deviceAddresses.Length(); ++i) {
-    auto rv = StringToAddress(aDeviceAddresses[i], deviceAddresses[i]);
-    if (NS_FAILED(rv)) {
-      BT_WARNING("GetPairedDeviceProperties failed");
-      return;
-    }
-  }
-
-  GetPairedDeviceProperties(deviceAddresses);
-}
-
-void
-BluetoothAdapter::GetPairedDeviceProperties(
-  const nsTArray<BluetoothAddress>& aDeviceAddresses)
-{
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  RefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(nullptr);
-
-  auto rv = bs->GetPairedDevicePropertiesInternal(aDeviceAddresses, results);
-  if (NS_FAILED(rv)) {
-    BT_WARNING("GetPairedDeviceProperties failed");
-    return;
-  }
-}
-
-void
-BluetoothAdapter::SetPropertyByValue(const BluetoothNamedValue& aValue)
-{
-  const nsString& name = aValue.name();
-  const BluetoothValue& value = aValue.value();
-  if (name.EqualsLiteral("State")) {
-    mState = value.get_bool() ? BluetoothAdapterState::Enabled
-                              : BluetoothAdapterState::Disabled;
-
-    // Clear saved devices and LE scan handles when state changes to disabled
-    if (mState == BluetoothAdapterState::Disabled) {
-      mDevices.Clear();
-      mLeScanHandleArray.Clear();
-      if (mGattServer) {
-        mGattServer->Invalidate();
-        mGattServer = nullptr;
-      }
-    }
-  } else if (name.EqualsLiteral("Name")) {
-    RemoteNameToString(value.get_BluetoothRemoteName(), mName);
-  } else if (name.EqualsLiteral("Address")) {
-    if (value.get_BluetoothAddress().IsCleared()) {
-      mAddress.Truncate(); // Reset to empty string
-    } else {
-      AddressToString(value.get_BluetoothAddress(), mAddress);
-    }
-  } else if (name.EqualsLiteral("Discoverable")) {
-    mDiscoverable = value.get_bool();
-  } else if (name.EqualsLiteral("Discovering")) {
-    mDiscovering = value.get_bool();
-    if (!mDiscovering) {
-      // Reset discovery handle in use to nullptr
-      SetDiscoveryHandleInUse(nullptr);
-    }
-  } else if (name.EqualsLiteral("PairedDevices")) {
-    const InfallibleTArray<BluetoothAddress>& pairedDeviceAddresses
-      = value.get_ArrayOfBluetoothAddress();
-
-    for (uint32_t i = 0; i < pairedDeviceAddresses.Length(); i++) {
-      nsString pairedDeviceAddressStr;
-      AddressToString(pairedDeviceAddresses[i], pairedDeviceAddressStr);
-
-      if (mDevices.Contains(pairedDeviceAddressStr)) {
-        // Existing paired devices handle 'PropertyChanged' signal
-        // in BluetoothDevice::Notify()
-        continue;
-      }
-
-      InfallibleTArray<BluetoothNamedValue> props;
-      AppendNamedValue(props, "Address", pairedDeviceAddresses[i]);
-      AppendNamedValue(props, "Paired", true);
-
-      // Create paired device and append to adapter's device array
-      mDevices.AppendElement(
-        BluetoothDevice::Create(GetOwner(), BluetoothValue(props)));
-    }
-
-    // Retrieve device properties, result will be handled by device objects.
-    GetPairedDeviceProperties(pairedDeviceAddresses);
-  } else {
-    BT_WARNING("Not handling adapter property: %s",
-               NS_ConvertUTF16toUTF8(name).get());
-  }
-}
-
-// static
-already_AddRefed<BluetoothAdapter>
-BluetoothAdapter::Create(nsPIDOMWindowInner* aWindow, const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aWindow);
-
-  RefPtr<BluetoothAdapter> adapter = new BluetoothAdapter(aWindow, aValue);
-  return adapter.forget();
-}
-
-void
-BluetoothAdapter::Notify(const BluetoothSignal& aData)
-{
-  BT_LOGD("[A] %s", NS_ConvertUTF16toUTF8(aData.name()).get());
-  NS_ENSURE_TRUE_VOID(mSignalRegistered);
-
-  BluetoothValue v = aData.value();
-  if (aData.name().EqualsLiteral("PropertyChanged")) {
-    HandlePropertyChanged(v);
-  } else if (aData.name().EqualsLiteral("DeviceFound")) {
-    /*
-     * DeviceFound signal will be distributed to all existing adapters while
-     * doing discovery operations.
-     * The signal needs to be handled only if this adapter is holding a valid
-     * discovery handle, which means that the discovery operation is triggered
-     * by this adapter.
-     */
-    if (mDiscoveryHandleInUse) {
-      HandleDeviceFound(v);
-    }
-  } else if (aData.name().EqualsLiteral("LeDeviceFound")) {
-    if (!mLeScanHandleArray.IsEmpty()) {
-      HandleLeDeviceFound(v);
-    }
-  } else if (aData.name().EqualsLiteral(DEVICE_PAIRED_ID)) {
-    HandleDevicePaired(aData.value());
-  } else if (aData.name().EqualsLiteral(DEVICE_UNPAIRED_ID)) {
-    HandleDeviceUnpaired(aData.value());
-  } else if (aData.name().EqualsLiteral(HFP_STATUS_CHANGED_ID) ||
-             aData.name().EqualsLiteral(SCO_STATUS_CHANGED_ID) ||
-             aData.name().EqualsLiteral(HID_STATUS_CHANGED_ID) ||
-             aData.name().EqualsLiteral(A2DP_STATUS_CHANGED_ID)) {
-    MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-    const InfallibleTArray<BluetoothNamedValue>& arr =
-      v.get_ArrayOfBluetoothNamedValue();
-
-    MOZ_ASSERT(arr.Length() == 2 &&
-               arr[0].value().type() == BluetoothValue::TBluetoothAddress &&
-               arr[1].value().type() == BluetoothValue::Tbool);
-    BluetoothAddress address = arr[0].value().get_BluetoothAddress();
-    bool status = arr[1].value().get_bool();
-
-    BluetoothStatusChangedEventInit init;
-    init.mBubbles = false;
-    init.mCancelable = false;
-    AddressToString(address, init.mAddress);
-    init.mStatus = status;
-    RefPtr<BluetoothStatusChangedEvent> event =
-      BluetoothStatusChangedEvent::Constructor(this, aData.name(), init);
-    DispatchTrustedEvent(event);
-  } else if (aData.name().EqualsLiteral(PAIRING_ABORTED_ID) ||
-             aData.name().EqualsLiteral(REQUEST_MEDIA_PLAYSTATUS_ID)) {
-    DispatchEmptyEvent(aData.name());
-  } else if (aData.name().EqualsLiteral(OBEX_PASSWORD_REQ_ID)) {
-    HandleObexPasswordReq(aData.value());
-  } else if (aData.name().EqualsLiteral(PULL_PHONEBOOK_REQ_ID)) {
-    HandlePullPhonebookReq(aData.value());
-  } else if (aData.name().EqualsLiteral(PULL_VCARD_ENTRY_REQ_ID)) {
-    HandlePullVCardEntryReq(aData.value());
-  } else if (aData.name().EqualsLiteral(PULL_VCARD_LISTING_REQ_ID)) {
-    HandlePullVCardListingReq(aData.value());
-  } else if (aData.name().EqualsLiteral(MAP_MESSAGES_LISTING_REQ_ID)) {
-    HandleMapMessagesListing(aData.value());
-  } else if (aData.name().EqualsLiteral(MAP_FOLDER_LISTING_REQ_ID)) {
-    HandleMapFolderListing(aData.value());
-  } else if (aData.name().EqualsLiteral(MAP_GET_MESSAGE_REQ_ID)) {
-    HandleMapGetMessage(aData.value());
-  } else if (aData.name().EqualsLiteral(MAP_SET_MESSAGE_STATUS_REQ_ID)) {
-    HandleMapSetMessageStatus(aData.value());
-  } else if (aData.name().EqualsLiteral(MAP_SEND_MESSAGE_REQ_ID)) {
-    HandleMapSendMessage(aData.value());
-  } else if (aData.name().EqualsLiteral(MAP_MESSAGE_UPDATE_REQ_ID)) {
-    HandleMapMessageUpdate(aData.value());
-  } else {
-    BT_WARNING("Not handling adapter signal: %s",
-               NS_ConvertUTF16toUTF8(aData.name()).get());
-  }
-}
-
-void
-BluetoothAdapter::SetDiscoveryHandleInUse(
-  BluetoothDiscoveryHandle* aDiscoveryHandle)
-{
-  mDiscoveryHandleInUse = aDiscoveryHandle;
-}
-
-void
-BluetoothAdapter::AppendLeScanHandle(
-  BluetoothDiscoveryHandle* aDiscoveryHandle)
-{
-  mLeScanHandleArray.AppendElement(aDiscoveryHandle);
-}
-
-void
-BluetoothAdapter::RemoveLeScanHandle(const BluetoothUuid& aScanUuid)
-{
-  for (size_t i = 0; i < mLeScanHandleArray.Length(); ++i) {
-    BluetoothUuid uuid;
-    mLeScanHandleArray[i]->GetLeScanUuid(uuid);
-    if (aScanUuid == uuid) {
-      mLeScanHandleArray.RemoveElementAt(i);
-      break;
-    }
-  }
-}
-
-already_AddRefed<Promise>
-BluetoothAdapter::StartDiscovery(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  /**
-   * Ensure
-   * - adapter is not discovering (note we reject here to ensure
-       each resolved promise returns a new BluetoothDiscoveryHandle),
-   * - adapter is already enabled, and
-   * - BluetoothService is available
-   */
-  BT_ENSURE_TRUE_REJECT(!mDiscovering, promise, NS_ERROR_DOM_INVALID_STATE_ERR);
-  BT_ENSURE_TRUE_REJECT(mState == BluetoothAdapterState::Enabled,
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  // Clear unpaired devices before start discovery
-  for (int32_t i = mDevices.Length() - 1; i >= 0; i--) {
-    if (!mDevices[i]->Paired()) {
-      mDevices.RemoveElementAt(i);
-    }
-  }
-
-  // Return BluetoothDiscoveryHandle in StartDiscoveryTask
-  bs->StartDiscoveryInternal(new StartDiscoveryTask(this, promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothAdapter::StopDiscovery(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  /**
-   * Ensure
-   * - adapter is discovering,
-   * - adapter is already enabled, and
-   * - BluetoothService is available
-   */
-  BT_ENSURE_TRUE_RESOLVE(mDiscovering, promise, JS::UndefinedHandleValue);
-  BT_ENSURE_TRUE_REJECT(mState == BluetoothAdapterState::Enabled,
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  bs->StopDiscoveryInternal(new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothAdapter::StartLeScan(const nsTArray<nsString>& aServiceUuids,
-                              ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  nsTArray<BluetoothUuid> serviceUuids;
-  serviceUuids.SetLength(aServiceUuids.Length());
-
-  for (size_t i = 0; i < serviceUuids.Length(); ++i) {
-    BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToUuid(aServiceUuids[i],
-                                                    serviceUuids[i])),
-                          promise,
-                          NS_ERROR_DOM_OPERATION_ERR);
-  }
-
-  BT_ENSURE_TRUE_REJECT(mState == BluetoothAdapterState::Enabled,
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  RefPtr<BluetoothReplyRunnable> result =
-    new StartLeScanTask(this, promise, serviceUuids);
-  bs->StartLeScanInternal(serviceUuids, result);
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothAdapter::StopLeScan(BluetoothDiscoveryHandle& aDiscoveryHandle,
-                             ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(mState == BluetoothAdapterState::Enabled,
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  // Reject the request if there's no ongoing LE Scan using this handle.
-  BT_ENSURE_TRUE_REJECT(mLeScanHandleArray.Contains(&aDiscoveryHandle),
-                        promise,
-                        NS_ERROR_DOM_BLUETOOTH_DONE);
-
-  BluetoothUuid scanUuid;
-  aDiscoveryHandle.GetLeScanUuid(scanUuid);
-
-  RefPtr<BluetoothReplyRunnable> result =
-    new StopLeScanTask(this, promise, scanUuid);
-  bs->StopLeScanInternal(scanUuid, result);
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothAdapter::SetName(const nsAString& aName, ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  /**
-   * Ensure
-   * - adapter's name does not equal to aName,
-   * - adapter is already enabled, and
-   * - BluetoothService is available
-   */
-  BT_ENSURE_TRUE_RESOLVE(!mName.Equals(aName),
-                         promise,
-                         JS::UndefinedHandleValue);
-  BT_ENSURE_TRUE_REJECT(mState == BluetoothAdapterState::Enabled,
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  // Wrap property to set and runnable to handle result
-  BluetoothNamedValue property(NS_LITERAL_STRING("Name"),
-                               BluetoothValue(
-                                 BluetoothRemoteName(
-                                   NS_ConvertUTF16toUTF8(aName))));
-  BT_ENSURE_SUCCESS_REJECT(
-    bs->SetProperty(BluetoothObjectType::TYPE_ADAPTER, property,
-                    new BluetoothVoidReplyRunnable(nullptr, promise)),
-    promise, NS_ERROR_DOM_OPERATION_ERR);
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothAdapter::SetDiscoverable(bool aDiscoverable, ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  /**
-   * Ensure
-   * - mDiscoverable does not equal to aDiscoverable,
-   * - adapter is already enabled, and
-   * - BluetoothService is available
-   */
-  BT_ENSURE_TRUE_RESOLVE(mDiscoverable != aDiscoverable,
-                         promise,
-                         JS::UndefinedHandleValue);
-  BT_ENSURE_TRUE_REJECT(mState == BluetoothAdapterState::Enabled,
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  // Wrap property to set and runnable to handle result
-  BluetoothNamedValue property(NS_LITERAL_STRING("Discoverable"),
-                               BluetoothValue(aDiscoverable));
-  BT_ENSURE_SUCCESS_REJECT(
-    bs->SetProperty(BluetoothObjectType::TYPE_ADAPTER, property,
-                    new BluetoothVoidReplyRunnable(nullptr, promise)),
-    promise, NS_ERROR_DOM_OPERATION_ERR);
-
-  return promise.forget();
-}
-
-already_AddRefed<DOMRequest>
-BluetoothAdapter::GetConnectedDevices(uint16_t aServiceUuid, ErrorResult& aRv)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothReplyRunnable> results =
-    new GetDevicesTask(this, request);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-  nsresult rv = bs->GetConnectedDevicePropertiesInternal(aServiceUuid, results);
-  if (NS_FAILED(rv)) {
-    aRv.Throw(rv);
-    return nullptr;
-  }
-
-  return request.forget();
-}
-
-void
-BluetoothAdapter::GetPairedDevices(
-  nsTArray<RefPtr<BluetoothDevice> >& aDevices)
-{
-  for (uint32_t i = 0; i < mDevices.Length(); ++i) {
-    if (mDevices[i]->Paired()) {
-      aDevices.AppendElement(mDevices[i]);
-    }
-  }
-}
-
-already_AddRefed<Promise>
-BluetoothAdapter::PairUnpair(bool aPair, const nsAString& aDeviceAddress,
-                             ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  /**
-   * Ensure
-   * - device address is valid,
-   * - adapter is already enabled, and
-   * - BluetoothService is available.
-   */
-  BluetoothAddress deviceAddress;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToAddress(aDeviceAddress,
-                                                     deviceAddress)),
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-  BT_ENSURE_TRUE_REJECT(mState == BluetoothAdapterState::Enabled,
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  nsresult rv;
-  if (aPair) {
-    rv = bs->CreatePairedDeviceInternal(
-           deviceAddress, kCreatePairedDeviceTimeout,
-           new BluetoothVoidReplyRunnable(nullptr, promise));
-  } else {
-    rv = bs->RemoveDeviceInternal(deviceAddress,
-           new BluetoothVoidReplyRunnable(nullptr, promise));
-  }
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(rv), promise, NS_ERROR_DOM_OPERATION_ERR);
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothAdapter::Pair(const nsAString& aDeviceAddress, ErrorResult& aRv)
-{
-  return PairUnpair(true, aDeviceAddress, aRv);
-}
-
-already_AddRefed<Promise>
-BluetoothAdapter::Unpair(const nsAString& aDeviceAddress, ErrorResult& aRv)
-{
-  return PairUnpair(false, aDeviceAddress, aRv);
-}
-
-already_AddRefed<Promise>
-BluetoothAdapter::Enable(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  /**
-   * Ensure
-   * - adapter is disabled, and
-   * - BluetoothService is available.
-   */
-  BT_ENSURE_TRUE_REJECT(mState == BluetoothAdapterState::Disabled,
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  // Set adapter state "Enabling"
-  SetAdapterState(BluetoothAdapterState::Enabling);
-
-  // Wrap runnable to handle result
-  RefPtr<BluetoothReplyRunnable> result =
-    new BluetoothVoidReplyRunnable(nullptr, promise);
-
-  if (NS_FAILED(bs->EnableDisable(true, result))) {
-    // Restore adapter state and reject promise
-    SetAdapterState(BluetoothAdapterState::Disabled);
-    promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
-  }
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothAdapter::Disable(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  /**
-   * Ensure
-   * - adapter is enabled, and
-   * - BluetoothService is available.
-   */
-  BT_ENSURE_TRUE_REJECT(mState == BluetoothAdapterState::Enabled,
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  // Set adapter state "Disabling"
-  SetAdapterState(BluetoothAdapterState::Disabling);
-
-  // Wrap runnable to handle result
-  RefPtr<BluetoothReplyRunnable> result =
-    new BluetoothVoidReplyRunnable(nullptr, promise);
-
-  if (NS_FAILED(bs->EnableDisable(false, result))) {
-    // Restore adapter state and reject promise
-    SetAdapterState(BluetoothAdapterState::Enabled);
-    promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
-  }
-
-  return promise.forget();
-}
-
-BluetoothAdapterAttribute
-BluetoothAdapter::ConvertStringToAdapterAttribute(const nsAString& aString)
-{
-  using namespace
-    mozilla::dom::BluetoothAdapterAttributeValues;
-
-  for (size_t index = 0; index < ArrayLength(strings) - 1; index++) {
-    if (aString.LowerCaseEqualsASCII(strings[index].value,
-                                     strings[index].length)) {
-      return static_cast<BluetoothAdapterAttribute>(index);
-    }
-  }
-  return BluetoothAdapterAttribute::Unknown;
-}
-
-bool
-BluetoothAdapter::IsAdapterAttributeChanged(BluetoothAdapterAttribute aType,
-                                            const BluetoothValue& aValue)
-{
-  switch(aType) {
-    case BluetoothAdapterAttribute::State:
-      MOZ_ASSERT(aValue.type() == BluetoothValue::Tbool);
-      return aValue.get_bool() ? mState != BluetoothAdapterState::Enabled
-                               : mState != BluetoothAdapterState::Disabled;
-    case BluetoothAdapterAttribute::Name: {
-        MOZ_ASSERT(aValue.type() == BluetoothValue::TBluetoothRemoteName);
-        nsAutoString name;
-        RemoteNameToString(aValue.get_BluetoothRemoteName(), name);
-        return !name.Equals(mName);
-      }
-    case BluetoothAdapterAttribute::Address: {
-        MOZ_ASSERT(aValue.type() == BluetoothValue::TBluetoothAddress);
-        BluetoothAddress address;
-        StringToAddress(mAddress, address);
-        return address != aValue.get_BluetoothAddress();
-      }
-    case BluetoothAdapterAttribute::Discoverable:
-      MOZ_ASSERT(aValue.type() == BluetoothValue::Tbool);
-      return mDiscoverable != aValue.get_bool();
-    case BluetoothAdapterAttribute::Discovering:
-      MOZ_ASSERT(aValue.type() == BluetoothValue::Tbool);
-      return mDiscovering != aValue.get_bool();
-    default:
-      BT_WARNING("Type %d is not handled", uint32_t(aType));
-      return false;
-  }
-}
-
-bool
-BluetoothAdapter::IsBluetoothCertifiedApp()
-{
-  NS_ENSURE_TRUE(GetOwner(), false);
-
-  // Retrieve the app status and origin for permission checking
-  nsCOMPtr<nsIDocument> doc = GetOwner()->GetExtantDoc();
-  NS_ENSURE_TRUE(doc, false);
-
-  uint16_t appStatus = nsIPrincipal::APP_STATUS_NOT_INSTALLED;
-  doc->NodePrincipal()->GetAppStatus(&appStatus);
-  if (appStatus != nsIPrincipal::APP_STATUS_CERTIFIED) {
-   return false;
-  }
-
-  // Get the app origin of Bluetooth app from PrefService.
-  nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
-  if (!prefs) {
-    BT_WARNING("Failed to get preference service");
-    return false;
-  }
-
-  nsAutoCString prefOrigin;
-  nsresult rv = prefs->GetCharPref(PREF_BLUETOOTH_APP_ORIGIN,
-                                   getter_Copies(prefOrigin));
-  if (NS_FAILED(rv)) {
-    BT_WARNING("Failed to get the pref value '" PREF_BLUETOOTH_APP_ORIGIN "'");
-    return false;
-  }
-
-  nsAutoCString appOrigin;
-  doc->NodePrincipal()->GetOriginNoSuffix(appOrigin);
-
-  return appOrigin.Equals(prefOrigin);
-}
-
-void
-BluetoothAdapter::SetAdapterState(BluetoothAdapterState aState)
-{
-  if (mState == aState) {
-    return;
-  }
-
-  mState = aState;
-
-  if (mState == BluetoothAdapterState::Disabled) {
-    if (mGattServer) {
-      mGattServer->Invalidate();
-      mGattServer = nullptr;
-    }
-  }
-
-  // Fire BluetoothAttributeEvent for changed adapter state
-  Sequence<nsString> types;
-  BT_APPEND_ENUM_STRING_FALLIBLE(types,
-                                 BluetoothAdapterAttribute,
-                                 BluetoothAdapterAttribute::State);
-  DispatchAttributeEvent(types);
-}
-
-void
-BluetoothAdapter::HandlePropertyChanged(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  Sequence<nsString> types;
-  for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) {
-    BluetoothAdapterAttribute type =
-      ConvertStringToAdapterAttribute(arr[i].name());
-
-    // Non-BluetoothAdapterAttribute properties
-    if (type == BluetoothAdapterAttribute::Unknown) {
-      SetPropertyByValue(arr[i]);
-      continue;
-    }
-
-    // BluetoothAdapterAttribute properties
-    if (IsAdapterAttributeChanged(type, arr[i].value())) {
-      SetPropertyByValue(arr[i]);
-      BT_APPEND_ENUM_STRING_FALLIBLE(types, BluetoothAdapterAttribute, type);
-    }
-  }
-
-  if (types.IsEmpty()) {
-    // No adapter attribute changed
-    return;
-  }
-
-  DispatchAttributeEvent(types);
-}
-
-void
-BluetoothAdapter::HandleDeviceFound(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(mDiscoveryHandleInUse);
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  // Create a temporary discovered BluetoothDevice to check existence
-  RefPtr<BluetoothDevice> discoveredDevice =
-    BluetoothDevice::Create(GetOwner(), aValue);
-
-  size_t index = mDevices.IndexOf(discoveredDevice);
-  if (index == mDevices.NoIndex) {
-    // New device, append it to adapter's device array
-    mDevices.AppendElement(discoveredDevice);
-  } else {
-    // Existing device, discard temporary discovered device
-    discoveredDevice = mDevices[index];
-  }
-
-  // Notify application of discovered device via discovery handle
-  mDiscoveryHandleInUse->DispatchDeviceEvent(discoveredDevice);
-}
-
-void
-BluetoothAdapter::HandleLeDeviceFound(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& values =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  int rssi = 0;
-  nsTArray<uint8_t> advData;
-  for (uint32_t i = 0; i < values.Length(); ++i) {
-    nsString name = values[i].name();
-    BluetoothValue value = values[i].value();
-    if (name.EqualsLiteral("Rssi")) {
-      MOZ_ASSERT(value.type() == BluetoothValue::Tint32_t);
-      rssi = value.get_int32_t();
-    } else if (name.EqualsLiteral("GattAdv")) {
-      MOZ_ASSERT(value.type() == BluetoothValue::TArrayOfuint8_t);
-      advData = value.get_ArrayOfuint8_t();
-    } else {
-      BT_WARNING("Receive an unexpected value name '%s'",
-                 NS_ConvertUTF16toUTF8(name).get());
-    }
-  }
-
-  // Create an individual scanned BluetoothDevice for each LeDeviceEvent even
-  // the device exists in adapter's devices array
-  RefPtr<BluetoothDevice> scannedDevice =
-    BluetoothDevice::Create(GetOwner(), aValue);
-
-  // Notify application of scanned devices via discovery handle
-  for (uint32_t i = 0; i < mLeScanHandleArray.Length(); ++i) {
-    mLeScanHandleArray[i]->DispatchLeDeviceEvent(scannedDevice, rssi, advData);
-  }
-}
-
-void
-BluetoothAdapter::HandleDevicePaired(const BluetoothValue& aValue)
-{
-  if (NS_WARN_IF(mState != BluetoothAdapterState::Enabled)) {
-    return;
-  }
-
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() == 3 &&
-             arr[0].value().type() == BluetoothValue::TBluetoothAddress && // Address
-             arr[1].value().type() == BluetoothValue::TBluetoothRemoteName && // Name
-             arr[2].value().type() == BluetoothValue::Tbool);      // Paired
-  MOZ_ASSERT(!arr[0].value().get_BluetoothAddress().IsCleared() &&
-             arr[2].value().get_bool());
-
-  // Append the paired device if it doesn't exist in adapter's devices array
-  nsString addressStr;
-  AddressToString(arr[0].value().get_BluetoothAddress(), addressStr);
-  size_t index = mDevices.IndexOf(addressStr);
-  if (index == mDevices.NoIndex) {
-    index = mDevices.Length(); // the new device's index
-    mDevices.AppendElement(
-      BluetoothDevice::Create(GetOwner(), aValue));
-  }
-
-  // Notify application of paired device
-  BluetoothDeviceEventInit init;
-  init.mDevice = mDevices[index];
-  DispatchDeviceEvent(NS_LITERAL_STRING(DEVICE_PAIRED_ID), init);
-}
-
-void
-BluetoothAdapter::HandleDeviceUnpaired(const BluetoothValue& aValue)
-{
-  if (NS_WARN_IF(mState != BluetoothAdapterState::Enabled)) {
-    return;
-  }
-
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() == 2 &&
-             arr[0].value().type() == BluetoothValue::TBluetoothAddress && // Address
-             arr[1].value().type() == BluetoothValue::Tbool);              // Paired
-  MOZ_ASSERT(!arr[0].value().get_BluetoothAddress().IsCleared() &&
-             !arr[1].value().get_bool());
-
-  // Remove the device with the same address
-  nsString deviceAddress;
-  AddressToString(arr[0].value().get_BluetoothAddress(), deviceAddress);
-  mDevices.RemoveElement(deviceAddress);
-
-  // Notify application of unpaired device
-  BluetoothDeviceEventInit init;
-  init.mAddress = deviceAddress;
-  DispatchDeviceEvent(NS_LITERAL_STRING(DEVICE_UNPAIRED_ID), init);
-}
-
-void
-BluetoothAdapter::HandleObexPasswordReq(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-  MOZ_ASSERT(aValue.get_ArrayOfBluetoothNamedValue().Length() <= 1);
-
-  BluetoothObexAuthEventInit init;
-  init.mHandle = BluetoothObexAuthHandle::Create(GetOwner());
-
-  // TODO: Retrieve optional userId from aValue and assign into event
-
-  RefPtr<BluetoothObexAuthEvent> event =
-    BluetoothObexAuthEvent::Constructor(this,
-      NS_LITERAL_STRING(OBEX_PASSWORD_REQ_ID), init);
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothAdapter::HandlePullPhonebookReq(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() >= 1 &&
-             arr[0].value().type() == BluetoothValue::TnsString);
-
-  BluetoothPhonebookPullingEventInit init;
-
-  for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) {
-    const nsString& name = arr[i].name();
-    const BluetoothValue& value = arr[i].value();
-    if (name.EqualsLiteral("name")) {
-      init.mName = value.get_nsString();
-    } else if (name.EqualsLiteral("format")) {
-      init.mFormat = value.get_bool() ? vCardVersion::VCard30
-                                      : vCardVersion::VCard21;
-    } else if (name.EqualsLiteral("propSelector")) {
-      init.mPropSelector = getVCardProperties(value);
-    } else if (name.EqualsLiteral("maxListCount")) {
-      init.mMaxListCount = value.get_uint32_t();
-    } else if (name.EqualsLiteral("listStartOffset")) {
-      init.mListStartOffset = value.get_uint32_t();
-    } else if (name.EqualsLiteral("vCardSelector_AND")) {
-      init.mVcardSelector = getVCardProperties(value);
-      init.mVcardSelectorOperator = vCardSelectorOp::AND;
-    } else if (name.EqualsLiteral("vCardSelector_OR")) {
-      init.mVcardSelector = getVCardProperties(value);
-      init.mVcardSelectorOperator = vCardSelectorOp::OR;
-    }
-  }
-
-  init.mHandle = BluetoothPbapRequestHandle::Create(GetOwner());
-
-  RefPtr<BluetoothPhonebookPullingEvent> event =
-    BluetoothPhonebookPullingEvent::Constructor(this,
-      NS_LITERAL_STRING(PULL_PHONEBOOK_REQ_ID), init);
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothAdapter::HandlePullVCardEntryReq(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() >= 1 &&
-             arr[0].value().type() == BluetoothValue::TnsString);
-
-  BluetoothVCardPullingEventInit init;
-  Sequence<vCardProperties> propSelector;
-
-  for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) {
-    const nsString& name = arr[i].name();
-    const BluetoothValue& value = arr[i].value();
-    if (name.EqualsLiteral("name")) {
-      init.mName = value.get_nsString();
-    } else if (name.EqualsLiteral("format")) {
-      init.mFormat = value.get_bool() ? vCardVersion::VCard30
-                                      : vCardVersion::VCard21;
-    } else if (name.EqualsLiteral("propSelector")) {
-      init.mPropSelector = getVCardProperties(value);
-    }
-  }
-
-  init.mHandle = BluetoothPbapRequestHandle::Create(GetOwner());
-
-  RefPtr<BluetoothVCardPullingEvent> event =
-    BluetoothVCardPullingEvent::Constructor(this,
-      NS_LITERAL_STRING(PULL_VCARD_ENTRY_REQ_ID), init);
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothAdapter::HandlePullVCardListingReq(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() >= 1 &&
-             arr[0].value().type() == BluetoothValue::TnsString);
-
-  BluetoothVCardListingEventInit init;
-
-  for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) {
-    const nsString& name = arr[i].name();
-    const BluetoothValue& value = arr[i].value();
-    if (name.EqualsLiteral("name")) {
-      init.mName = value.get_nsString();
-    } else if (name.EqualsLiteral("order")) {
-      init.mOrder = static_cast<vCardOrderType>(value.get_uint32_t());
-    } else if (name.EqualsLiteral("searchKey")) {
-      init.mSearchKey = static_cast<vCardSearchKeyType>(value.get_uint32_t());
-    } else if (name.EqualsLiteral("searchText")) {
-      init.mSearchValue = NS_ConvertUTF8toUTF16(value.get_nsCString());
-    } else if (name.EqualsLiteral("maxListCount")) {
-      init.mMaxListCount = value.get_uint32_t();
-    } else if (name.EqualsLiteral("listStartOffset")) {
-      init.mListStartOffset = value.get_uint32_t();
-    } else if (name.EqualsLiteral("vCardSelector_AND")) {
-      init.mVcardSelector = getVCardProperties(value);
-      init.mVcardSelectorOperator = vCardSelectorOp::AND;
-    } else if (name.EqualsLiteral("vCardSelector_OR")) {
-      init.mVcardSelector = getVCardProperties(value);
-      init.mVcardSelectorOperator = vCardSelectorOp::OR;
-    }
-  }
-
-  init.mHandle = BluetoothPbapRequestHandle::Create(GetOwner());
-
-  RefPtr<BluetoothVCardListingEvent> event =
-    BluetoothVCardListingEvent::Constructor(this,
-      NS_LITERAL_STRING(PULL_VCARD_LISTING_REQ_ID), init);
-  DispatchTrustedEvent(event);
-}
-
-Sequence<vCardProperties>
-BluetoothAdapter::getVCardProperties(const BluetoothValue &aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfuint32_t);
-
-  Sequence<vCardProperties> propSelector;
-
-  const InfallibleTArray<uint32_t>& propSelectorArr =
-    aValue.get_ArrayOfuint32_t();
-  for (uint32_t i = 0; i < propSelectorArr.Length(); ++i) {
-    propSelector.AppendElement(
-      static_cast<vCardProperties>(propSelectorArr[i]), mozilla::fallible);
-  }
-
-  return propSelector;
-}
-
-Sequence<ParameterMask>
-BluetoothAdapter::GetParameterMask(const BluetoothValue &aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfuint32_t);
-
-  Sequence<ParameterMask> parameterMask;
-
-  const InfallibleTArray<uint32_t>& parameterMaskArr =
-    aValue.get_ArrayOfuint32_t();
-  for (uint32_t i = 0; i < parameterMaskArr.Length(); ++i) {
-    parameterMask.AppendElement(
-      static_cast<ParameterMask>(parameterMaskArr[i]), mozilla::fallible);
-  }
-
-  return parameterMask;
-}
-
-void
-BluetoothAdapter::HandleMapFolderListing(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() >= 1 &&
-             arr[0].value().type() == BluetoothValue::Tuint32_t);
-
-  BluetoothMapFolderListingEventInit init;
-
-  for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) {
-    const nsString& name = arr[i].name();
-    const BluetoothValue& value = arr[i].value();
-    if (name.EqualsLiteral("maxListCount")) {
-      init.mMaxListCount = value.get_uint32_t();
-    } else if (name.EqualsLiteral("startOffset")) {
-      init.mListStartOffset = value.get_uint32_t();
-    }
-  }
-
-  init.mHandle = BluetoothMapRequestHandle::Create(GetOwner());
-
-  RefPtr<BluetoothMapFolderListingEvent> event =
-    BluetoothMapFolderListingEvent::Constructor(this,
-      NS_LITERAL_STRING(MAP_FOLDER_LISTING_REQ_ID), init);
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothAdapter::HandleMapMessagesListing(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() >= 1 &&
-    arr[0].value().type() == BluetoothValue::Tuint32_t);
-
-  BluetoothMapMessagesListingEventInit init;
-
-  for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) {
-    const nsString& name = arr[i].name();
-    const BluetoothValue& value = arr[i].value();
-    if (name.EqualsLiteral("maxListCount")) {
-      init.mMaxListCount = value.get_uint32_t();
-    } else if (name.EqualsLiteral("startOffset")) {
-      init.mListStartOffset = value.get_uint32_t();
-    } else if (name.EqualsLiteral("subLength")) {
-      init.mSubjectLength = value.get_uint32_t();
-    } else if (name.EqualsLiteral("parameterMask")) {
-      init.mParameterMask = GetParameterMask(value);
-    } else if (name.EqualsLiteral("filterMessageType")) {
-      init.mFilterMessageType = static_cast<MessageType>(value.get_uint32_t());
-    } else if (name.EqualsLiteral("filterPeriodBegin")) {
-      init.mFilterPeriodBegin = value.get_nsString();
-    } else if (name.EqualsLiteral("filterPeriodEnd")) {
-      init.mFilterPeriodEnd = value.get_nsString();
-    } else if (name.EqualsLiteral("filterReadStatus")) {
-      init.mFilterReadStatus = static_cast<ReadStatus>(value.get_uint32_t());
-    } else if (name.EqualsLiteral("filterRecipient")) {
-      init.mFilterRecipient = value.get_nsString();
-    } else if (name.EqualsLiteral("filterOriginator")) {
-      init.mFilterOriginator = value.get_nsString();
-    } else if (name.EqualsLiteral("filterPriority")) {
-      init.mFilterPriority = static_cast<Priority>(value.get_uint32_t());
-    }
-  }
-
-  init.mHandle = BluetoothMapRequestHandle::Create(GetOwner());
-
-  RefPtr<BluetoothMapMessagesListingEvent> event =
-    BluetoothMapMessagesListingEvent::Constructor(this,
-      NS_LITERAL_STRING(MAP_MESSAGES_LISTING_REQ_ID), init);
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothAdapter::HandleMapGetMessage(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() >= 1 &&
-    arr[0].value().type() == BluetoothValue::Tbool);
-
-  BluetoothMapGetMessageEventInit init;
-
-  for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) {
-    const nsString& name = arr[i].name();
-    const BluetoothValue& value = arr[i].value();
-    if (name.EqualsLiteral("hasAttachment")) {
-      init.mHasAttachment = value.get_bool();
-    } else if (name.EqualsLiteral("charset")) {
-      if (value.get_uint32_t() == 0) {
-        init.mCharset = FilterCharset::Native;
-      } else {
-        init.mCharset = FilterCharset::Utf_8;
-      }
-    }
-  }
-
-  init.mHandle = BluetoothMapRequestHandle::Create(GetOwner());
-
-  RefPtr<BluetoothMapGetMessageEvent> event =
-    BluetoothMapGetMessageEvent::Constructor(this,
-      NS_LITERAL_STRING(MAP_GET_MESSAGE_REQ_ID), init);
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothAdapter::HandleMapSetMessageStatus(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() >= 1 &&
-    arr[0].value().type() == BluetoothValue::Tuint32_t);
-
-  BluetoothMapSetMessageStatusEventInit init;
-
-  for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) {
-    const nsString& name = arr[i].name();
-    const BluetoothValue& value = arr[i].value();
-    if (name.EqualsLiteral("handleId")) {
-      init.mHandleId = value.get_uint32_t();
-    } else if (name.EqualsLiteral("statusIndicator")) {
-      if (value.get_uint32_t()) {
-        init.mStatusIndicator = StatusIndicators::Deletedstatus;
-      } else {
-        init.mStatusIndicator = StatusIndicators::Readstatus;
-      }
-    } else if (name.EqualsLiteral("statusValue")) {
-      init.mStatusValue = static_cast<bool>(value.get_uint32_t());
-    }
-  }
-
-  init.mHandle = BluetoothMapRequestHandle::Create(GetOwner());
-
-  RefPtr<BluetoothMapSetMessageStatusEvent> event =
-    BluetoothMapSetMessageStatusEvent::Constructor(this,
-      NS_LITERAL_STRING(MAP_SET_MESSAGE_STATUS_REQ_ID), init);
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothAdapter::HandleMapSendMessage(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() >= 1 &&
-    arr[0].value().type() == BluetoothValue::TnsString);
-
-  BluetoothMapSendMessageEventInit init;
-
-  for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) {
-    const nsString& name = arr[i].name();
-    const BluetoothValue& value = arr[i].value();
-    if (name.EqualsLiteral("recipient")) {
-      init.mRecipient = NS_ConvertUTF8toUTF16(value.get_nsCString());
-    } else if (name.EqualsLiteral("messageBody")) {
-      init.mMessageBody = NS_ConvertUTF8toUTF16(value.get_nsCString());
-    } else if (name.EqualsLiteral("retry")) {
-      init.mRetry = value.get_uint32_t();
-    }
-  }
-
-  init.mHandle = BluetoothMapRequestHandle::Create(GetOwner());
-
-  RefPtr<BluetoothMapSendMessageEvent> event =
-    BluetoothMapSendMessageEvent::Constructor(this,
-      NS_LITERAL_STRING(MAP_SEND_MESSAGE_REQ_ID), init);
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothAdapter::HandleMapMessageUpdate(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() >= 1 &&
-    arr[0].value().type() == BluetoothValue::TnsString);
-
-  BluetoothMapMessageUpdateEventInit init;
-
-  for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) {
-    const nsString& name = arr[i].name();
-    const BluetoothValue& value = arr[i].value();
-    if (name.EqualsLiteral("instanceId")) {
-      init.mInstanceId = value.get_uint32_t();
-    }
-  }
-
-  init.mHandle = BluetoothMapRequestHandle::Create(GetOwner());
-
-  RefPtr<BluetoothMapMessageUpdateEvent> event =
-    BluetoothMapMessageUpdateEvent::Constructor(this,
-      NS_LITERAL_STRING(MAP_MESSAGE_UPDATE_REQ_ID), init);
-  DispatchTrustedEvent(event);
-}
-
-
-void
-BluetoothAdapter::DispatchAttributeEvent(const Sequence<nsString>& aTypes)
-{
-  MOZ_ASSERT(!aTypes.IsEmpty());
-
-  BluetoothAttributeEventInit init;
-  init.mAttrs = aTypes;
-
-  RefPtr<BluetoothAttributeEvent> event =
-    BluetoothAttributeEvent::Constructor(
-      this, NS_LITERAL_STRING(ATTRIBUTE_CHANGED_ID), init);
-
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothAdapter::DispatchDeviceEvent(const nsAString& aType,
-                                      const BluetoothDeviceEventInit& aInit)
-{
-  RefPtr<BluetoothDeviceEvent> event =
-    BluetoothDeviceEvent::Constructor(this, aType, aInit);
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothAdapter::DispatchEmptyEvent(const nsAString& aType)
-{
-  RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
-
-  event->InitEvent(aType, false, false);
-
-  DispatchTrustedEvent(event);
-}
-
-already_AddRefed<DOMRequest>
-BluetoothAdapter::Connect(BluetoothDevice& aDevice,
-                          const Optional<short unsigned int>& aServiceUuid,
-                          ErrorResult& aRv)
-{
-  nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(request);
-
-  nsAutoString address;
-  aDevice.GetAddress(address);
-  BluetoothAddress deviceAddress;
-  if (NS_FAILED(StringToAddress(address, deviceAddress))) {
-    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
-    return nullptr;
-  }
-
-  uint32_t deviceClass = aDevice.Cod()->ToUint32();
-  uint16_t serviceUuid = 0;
-  if (aServiceUuid.WasPassed()) {
-    serviceUuid = aServiceUuid.Value();
-  }
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-  bs->Connect(deviceAddress, deviceClass, serviceUuid, results);
-
-  return request.forget();
-}
-
-already_AddRefed<DOMRequest>
-BluetoothAdapter::Disconnect(BluetoothDevice& aDevice,
-                             const Optional<short unsigned int>& aServiceUuid,
-                             ErrorResult& aRv)
-{
-  nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(request);
-
-  nsAutoString address;
-  aDevice.GetAddress(address);
-  BluetoothAddress deviceAddress;
-  if (NS_FAILED(StringToAddress(address, deviceAddress))) {
-    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
-    return nullptr;
-  }
-
-  uint16_t serviceUuid = 0;
-  if (aServiceUuid.WasPassed()) {
-    serviceUuid = aServiceUuid.Value();
-  }
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-  bs->Disconnect(deviceAddress, serviceUuid, results);
-
-  return request.forget();
-}
-
-already_AddRefed<DOMRequest>
-BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
-                           Blob& aBlob, ErrorResult& aRv)
-{
-  nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(request);
-
-  BluetoothAddress deviceAddress;
-  auto rv = StringToAddress(aDeviceAddress, deviceAddress);
-  if (NS_FAILED(rv)) {
-    aRv.Throw(rv);
-    return nullptr;
-  }
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  if (XRE_IsParentProcess()) {
-    // In-process transfer
-    bs->SendFile(deviceAddress, &aBlob, results);
-  } else {
-    ContentChild *cc = ContentChild::GetSingleton();
-    if (!cc) {
-      aRv.Throw(NS_ERROR_FAILURE);
-      return nullptr;
-    }
-
-    BlobChild* actor = cc->GetOrCreateActorForBlob(&aBlob);
-    if (!actor) {
-      aRv.Throw(NS_ERROR_FAILURE);
-      return nullptr;
-    }
-
-    bs->SendFile(deviceAddress, nullptr, actor, results);
-  }
-
-  return request.forget();
-}
-
-already_AddRefed<DOMRequest>
-BluetoothAdapter::StopSendingFile(
-  const nsAString& aDeviceAddress, ErrorResult& aRv)
-{
-  nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(request);
-
-  BluetoothAddress deviceAddress;
-  auto rv = StringToAddress(aDeviceAddress, deviceAddress);
-  if (NS_FAILED(rv)) {
-    aRv.Throw(rv);
-    return nullptr;
-  }
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-  bs->StopSendingFile(deviceAddress, results);
-
-  return request.forget();
-}
-
-already_AddRefed<DOMRequest>
-BluetoothAdapter::ConfirmReceivingFile(const nsAString& aDeviceAddress,
-                                       bool aConfirmation, ErrorResult& aRv)
-{
-  nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(request);
-
-  BluetoothAddress deviceAddress;
-  auto rv = StringToAddress(aDeviceAddress, deviceAddress);
-  if (NS_FAILED(rv)) {
-    aRv.Throw(rv);
-    return nullptr;
-  }
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-  bs->ConfirmReceivingFile(deviceAddress, aConfirmation, results);
-
-  return request.forget();
-}
-
-already_AddRefed<DOMRequest>
-BluetoothAdapter::ConnectSco(ErrorResult& aRv)
-{
-  nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(request);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-  bs->ConnectSco(results);
-
-  return request.forget();
-}
-
-already_AddRefed<DOMRequest>
-BluetoothAdapter::DisconnectSco(ErrorResult& aRv)
-{
-  nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(request);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-  bs->DisconnectSco(results);
-
-  return request.forget();
-}
-
-already_AddRefed<DOMRequest>
-BluetoothAdapter::IsScoConnected(ErrorResult& aRv)
-{
-  nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothReplyRunnable> results =
-    new GetScoConnectionStatusTask(request);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-  bs->IsScoConnected(results);
-
-  return request.forget();
-}
-
-already_AddRefed<DOMRequest>
-BluetoothAdapter::AnswerWaitingCall(ErrorResult& aRv)
-{
-#ifdef MOZ_B2G_RIL
-  nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(request);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-  bs->AnswerWaitingCall(results);
-
-  return request.forget();
-#else
-  aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
-  return nullptr;
-#endif // MOZ_B2G_RIL
-}
-
-already_AddRefed<DOMRequest>
-BluetoothAdapter::IgnoreWaitingCall(ErrorResult& aRv)
-{
-#ifdef MOZ_B2G_RIL
-  nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(request);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-  bs->IgnoreWaitingCall(results);
-
-  return request.forget();
-#else
-  aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
-  return nullptr;
-#endif // MOZ_B2G_RIL
-}
-
-already_AddRefed<DOMRequest>
-BluetoothAdapter::ToggleCalls(ErrorResult& aRv)
-{
-#ifdef MOZ_B2G_RIL
-  nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(request);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-  bs->ToggleCalls(results);
-
-  return request.forget();
-#else
-  aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
-  return nullptr;
-#endif // MOZ_B2G_RIL
-}
-
-already_AddRefed<DOMRequest>
-BluetoothAdapter::SendMediaMetaData(
-  const MediaMetaData& aMediaMetaData, ErrorResult& aRv)
-{
-  nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(request);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-  bs->SendMetaData(aMediaMetaData.mTitle,
-                   aMediaMetaData.mArtist,
-                   aMediaMetaData.mAlbum,
-                   aMediaMetaData.mMediaNumber,
-                   aMediaMetaData.mTotalMediaCount,
-                   aMediaMetaData.mDuration,
-                   results);
-
-  return request.forget();
-}
-
-already_AddRefed<DOMRequest>
-BluetoothAdapter::SendMediaPlayStatus(
-  const MediaPlayStatus& aMediaPlayStatus, ErrorResult& aRv)
-{
-  nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  ControlPlayStatus playStatus;
-  auto rv = StringToControlPlayStatus(aMediaPlayStatus.mPlayStatus, playStatus);
-  if (NS_FAILED(rv)) {
-    aRv.Throw(rv);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(request);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-  bs->SendPlayStatus(aMediaPlayStatus.mDuration,
-                     aMediaPlayStatus.mPosition,
-                     playStatus,
-                     results);
-
-  return request.forget();
-}
-
-JSObject*
-BluetoothAdapter::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothAdapterBinding::Wrap(aCx, this, aGivenProto);
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothAdapter.h
+++ /dev/null
@@ -1,583 +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_BluetoothAdapter_h
-#define mozilla_dom_bluetooth_BluetoothAdapter_h
-
-#include "BluetoothCommon.h"
-#include "mozilla/Attributes.h"
-#include "mozilla/DOMEventTargetHelper.h"
-#include "mozilla/dom/BluetoothAdapterBinding.h"
-#include "mozilla/dom/BluetoothDeviceEvent.h"
-#include "mozilla/dom/BluetoothMapParametersBinding.h"
-#include "mozilla/dom/BluetoothPbapParametersBinding.h"
-#include "mozilla/dom/Promise.h"
-#include "nsCOMPtr.h"
-
-namespace mozilla {
-namespace dom {
-class Blob;
-class DOMRequest;
-struct MediaMetaData;
-struct MediaPlayStatus;
-}
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothDevice;
-class BluetoothDiscoveryHandle;
-class BluetoothGattServer;
-class BluetoothNamedValue;
-class BluetoothPairingListener;
-class BluetoothSignal;
-class BluetoothValue;
-
-class BluetoothAdapter : public DOMEventTargetHelper
-                       , public BluetoothSignalObserver
-{
-public:
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BluetoothAdapter,
-                                           DOMEventTargetHelper)
-
-  /****************************************************************************
-   * Attribute Getters
-   ***************************************************************************/
-  BluetoothAdapterState State() const
-  {
-    return mState;
-  }
-
-  void GetAddress(nsString& aAddress) const
-  {
-    aAddress = mAddress;
-  }
-
-  void
-  GetName(nsString& aName) const
-  {
-    aName = mName;
-  }
-
-  bool
-  Discovering() const
-  {
-    return mDiscovering;
-  }
-
-  bool
-  Discoverable() const
-  {
-    return mDiscoverable;
-  }
-
-  BluetoothPairingListener* GetPairingReqs() const
-  {
-    return mPairingReqs;
-  }
-
-  BluetoothGattServer* GetGattServer();
-
-  /****************************************************************************
-   * Event Handlers
-   ***************************************************************************/
-  IMPL_EVENT_HANDLER(attributechanged);
-  // PAIRING
-  IMPL_EVENT_HANDLER(devicepaired);
-  IMPL_EVENT_HANDLER(deviceunpaired);
-  IMPL_EVENT_HANDLER(pairingaborted);
-  // HFP/A2DP/AVRCP/HID
-  IMPL_EVENT_HANDLER(a2dpstatuschanged);
-  IMPL_EVENT_HANDLER(hfpstatuschanged);
-  IMPL_EVENT_HANDLER(hidstatuschanged);
-  IMPL_EVENT_HANDLER(scostatuschanged);
-  IMPL_EVENT_HANDLER(requestmediaplaystatus);
-  // PBAP
-  IMPL_EVENT_HANDLER(obexpasswordreq);
-  IMPL_EVENT_HANDLER(pullphonebookreq);
-  IMPL_EVENT_HANDLER(pullvcardentryreq);
-  IMPL_EVENT_HANDLER(pullvcardlistingreq);
-  // MAP
-  IMPL_EVENT_HANDLER(mapfolderlistingreq);
-  IMPL_EVENT_HANDLER(mapmessageslistingreq);
-  IMPL_EVENT_HANDLER(mapgetmessagereq);
-  IMPL_EVENT_HANDLER(mapsetmessagestatusreq);
-  IMPL_EVENT_HANDLER(mapsendmessagereq);
-  IMPL_EVENT_HANDLER(mapmessageupdatereq);
-
-  /****************************************************************************
-   * Methods (Web API Implementation)
-   ***************************************************************************/
-  already_AddRefed<Promise> Enable(ErrorResult& aRv);
-  already_AddRefed<Promise> Disable(ErrorResult& aRv);
-
-  already_AddRefed<Promise> SetName(const nsAString& aName, ErrorResult& aRv);
-  already_AddRefed<Promise> SetDiscoverable(bool aDiscoverable,
-                                            ErrorResult& aRv);
-  already_AddRefed<Promise> StartDiscovery(ErrorResult& aRv);
-  already_AddRefed<Promise> StopDiscovery(ErrorResult& aRv);
-
-  already_AddRefed<Promise> StartLeScan(
-    const nsTArray<nsString>& aServiceUuids, ErrorResult& aRv);
-  already_AddRefed<Promise> StopLeScan(
-    BluetoothDiscoveryHandle& aDiscoveryHandle, ErrorResult& aRv);
-
-  already_AddRefed<Promise> Pair(const nsAString& aDeviceAddress,
-                                 ErrorResult& aRv);
-  already_AddRefed<Promise> Unpair(const nsAString& aDeviceAddress,
-                                   ErrorResult& aRv);
-
-  /**
-   * Get a list of paired bluetooth devices.
-   *
-   * @param aDevices [out] Devices array to return
-   */
-  void GetPairedDevices(nsTArray<RefPtr<BluetoothDevice> >& aDevices);
-
-  // Connection related methods
-  already_AddRefed<DOMRequest>
-    Connect(BluetoothDevice& aDevice,
-            const Optional<short unsigned int>& aServiceUuid,
-            ErrorResult& aRv);
-  already_AddRefed<DOMRequest>
-    Disconnect(BluetoothDevice& aDevice,
-               const Optional<short unsigned int>& aServiceUuid,
-               ErrorResult& aRv);
-  already_AddRefed<DOMRequest> GetConnectedDevices(uint16_t aServiceUuid,
-                                                   ErrorResult& aRv);
-
-  // OPP file transfer related methods
-  already_AddRefed<DOMRequest> SendFile(const nsAString& aDeviceAddress,
-                                        Blob& aBlob,
-                                        ErrorResult& aRv);
-  already_AddRefed<DOMRequest> StopSendingFile(const nsAString& aDeviceAddress,
-                                               ErrorResult& aRv);
-  already_AddRefed<DOMRequest>
-    ConfirmReceivingFile(const nsAString& aDeviceAddress,
-                         bool aConfirmation,
-                         ErrorResult& aRv);
-
-  // SCO related methods
-  already_AddRefed<DOMRequest> ConnectSco(ErrorResult& aRv);
-  already_AddRefed<DOMRequest> DisconnectSco(ErrorResult& aRv);
-  already_AddRefed<DOMRequest> IsScoConnected(ErrorResult& aRv);
-
-  // Handfree CDMA related methods
-  already_AddRefed<DOMRequest> AnswerWaitingCall(ErrorResult& aRv);
-  already_AddRefed<DOMRequest> IgnoreWaitingCall(ErrorResult& aRv);
-  already_AddRefed<DOMRequest> ToggleCalls(ErrorResult& aRv);
-
-  // AVRCP related methods
-  already_AddRefed<DOMRequest>
-    SendMediaMetaData(const MediaMetaData& aMediaMetaData, ErrorResult& aRv);
-  already_AddRefed<DOMRequest>
-    SendMediaPlayStatus(const MediaPlayStatus& aMediaPlayStatus,
-                        ErrorResult& aRv);
-
-  /****************************************************************************
-   * Others
-   ***************************************************************************/
-  static already_AddRefed<BluetoothAdapter>
-    Create(nsPIDOMWindowInner* aOwner, const BluetoothValue& aValue);
-
-  void Notify(const BluetoothSignal& aParam); // BluetoothSignalObserver
-  nsPIDOMWindowInner* GetParentObject() const
-  {
-     return GetOwner();
-  }
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-  virtual void DisconnectFromOwner() override;
-
-  void GetPairedDeviceProperties(
-    const nsTArray<BluetoothAddress>& aDeviceAddresses);
-
-  /**
-   * Set this adapter's discovery handle in use (mDiscoveryHandleInUse).
-   *
-   * |mDiscoveryHandleInUse| is set to the latest discovery handle when adapter
-   * just starts discovery, and is reset to nullptr when discovery is stopped
-   * by some adapter.
-   *
-   * @param aDiscoveryHandle [in] Discovery handle to set.
-   */
-  void SetDiscoveryHandleInUse(BluetoothDiscoveryHandle* aDiscoveryHandle);
-
-  /**
-   * Append a BluetoothDiscoveryHandle to LeScan handle array.
-   *
-   * @param aDiscoveryHandle [in] Discovery handle to be appended.
-   */
-  void AppendLeScanHandle(BluetoothDiscoveryHandle* aDiscoveryHandle);
-
-  /**
-   * Remove the BluetoothDiscoverHandle with the given UUID from LeScan handle
-   * array.
-   *
-   * @param aScanUuid [in] The UUID of the LE scan task.
-   */
-  void RemoveLeScanHandle(const BluetoothUuid& aScanUuid);
-
-private:
-  BluetoothAdapter(nsPIDOMWindowInner* aOwner, const BluetoothValue& aValue);
-  ~BluetoothAdapter();
-
-  /**
-   * Unregister signal handler and clean up LE scan handles.
-   */
-  void Cleanup();
-
-  /**
-   * Set adapter properties according to properties array.
-   *
-   * @param aValue [in] Properties array to set with
-   */
-  void SetPropertyByValue(const BluetoothNamedValue& aValue);
-
-  /**
-   * Set adapter state and fire BluetoothAttributeEvent if state changed.
-   *
-   * @param aState [in] The new adapter state
-   */
-  void SetAdapterState(BluetoothAdapterState aState);
-
-  /**
-   * Pair/Unpair adapter to device of given address.
-   * This function is called by methods Enable() and Disable().
-   *
-   * @param aPair          [in]  Whether to pair or unpair adapter to device.
-   * @param aDeviceAddress [in]  Address of device to pair/unpair.
-   * @param aRv            [out] Error result to set in case of error.
-   */
-  already_AddRefed<Promise> PairUnpair(bool aPair,
-                            const nsAString& aDeviceAddress,
-                            ErrorResult& aRv);
-
-  /**
-   * Retrieve properties of paired devices.
-   *
-   * @param aDeviceAddresses [in] Addresses array of paired devices
-   */
-  void GetPairedDeviceProperties(const nsTArray<nsString>& aDeviceAddresses);
-
-  /**
-   * Handle "PropertyChanged" bluetooth signal.
-   *
-   * @param aValue [in] Array of changed properties
-   */
-  void HandlePropertyChanged(const BluetoothValue& aValue);
-
-  /**
-   * Handle "DeviceFound" bluetooth signal.
-   *
-   * @param aValue [in] Properties array of the discovered device.
-   */
-  void HandleDeviceFound(const BluetoothValue& aValue);
-
-  /**
-   * Handle DEVICE_PAIRED_ID bluetooth signal.
-   *
-   * @param aValue [in] Properties array of the paired device.
-   *                    The array should contain two properties:
-   *                    - nsString  'Address'
-   *                    - bool      'Paired'
-   */
-  void HandleDevicePaired(const BluetoothValue& aValue);
-
-  /**
-   * Handle DEVICE_UNPAIRED_ID bluetooth signal.
-   *
-   * @param aValue [in] Properties array of the unpaired device.
-   *                    The array should contain two properties:
-   *                    - nsString  'Address'
-   *                    - bool      'Paired'
-   */
-  void HandleDeviceUnpaired(const BluetoothValue& aValue);
-
-  /**
-   * Handle "LeDeviceFound" bluetooth signal.
-   *
-   * @param aValue [in] Properties array of the scanned device.
-   */
-  void HandleLeDeviceFound(const BluetoothValue& aValue);
-
-  /**
-   * Handle PULL_PHONEBOOK_REQ_ID bluetooth signal.
-   *
-   * @param aValue [in] Properties array of the PBAP request.
-   *                    The array should contain few properties:
-   *                    - nsString   'name'
-   *                    - bool       'format'
-   *                    - uint32_t[] 'propSelector'
-   *                    - uint32_t   'maxListCount'
-   *                    - uint32_t   'listStartOffset'
-   *                    - uint32_t[] 'vCardSelector_AND'
-   *                    - uint32_t[] 'vCardSelector_OR'
-   */
-  void HandlePullPhonebookReq(const BluetoothValue& aValue);
-
-  /**
-   * Handle PULL_VCARD_ENTRY_REQ_ID bluetooth signal.
-   *
-   * @param aValue [in] Properties array of the PBAP request.
-   *                    The array should contain few properties:
-   *                    - nsString   'name'
-   *                    - bool       'format'
-   *                    - uint32_t[] 'propSelector'
-   */
-  void HandlePullVCardEntryReq(const BluetoothValue& aValue);
-
-  /**
-   * Handle PULL_VCARD_LISTING_REQ_ID bluetooth signal.
-   *
-   * @param aValue [in] Properties array of the PBAP request.
-   *                    The array should contain few properties:
-   *                    - nsString   'name'
-   *                    - nsString   'order'
-   *                    - nsString   'searchText'
-   *                    - nsString   'searchKey'
-   *                    - uint32_t   'maxListCount'
-   *                    - uint32_t   'listStartOffset'
-   *                    - uint32_t[] 'vCardSelector_AND'
-   *                    - uint32_t[] 'vCardSelector_OR'
-   */
-  void HandlePullVCardListingReq(const BluetoothValue& aValue);
-
-  /**
-   * Handle OBEX_PASSWORD_REQ_ID bluetooth signal.
-   *
-   * @param aValue [in] Properties array of the PBAP request.
-   *                    The array may contain the property:
-   *                    - nsString   'userId'
-   */
-  void HandleObexPasswordReq(const BluetoothValue& aValue);
-
-  /**
-   * Get a Sequence of vCard properies from a BluetoothValue. The name of
-   * BluetoothValue must be propSelector, vCardSelector_OR or vCardSelector_AND.
-   *
-   * @param aValue [in] a BluetoothValue with 'TArrayOfuint32_t' type
-   *                    The name of BluetoothValue must be 'propSelector',
-   *                    'vCardSelector_OR' or 'vCardSelector_AND'.
-   */
-  Sequence<vCardProperties> getVCardProperties(const BluetoothValue &aValue);
-
-   /**
-   * Handle "MapFolderListing" bluetooth signal.
-   *
-   * @param aValue [in] Properties array of the MAP request.
-   *                    The array should contain a few properties:
-   *                    - uint32_t  'MaxListCount'
-   *                    - uint32_t  'ListStartOffset'
-   */
-  void HandleMapFolderListing(const BluetoothValue& aValue);
-
-  /**
-   * Handle "MapMessageListing" bluetooth signal.
-   *
-   * @param aValue [in] Properties array of the MAP request.
-   *                    The array should contain a few properties:
-   *                    - uint32_t  'MaxListCount'
-   *                    - uint32_t  'ListStartOffset'
-   *                    - uint32_t  'SubjectLength'
-   *                    - uint32_t  'ParameterMask'
-   *                    - uint32_t  'FilterMessageType'
-   *                    - nsString  'FilterPeriodBegin'
-   *                    - nsString  'FilterPeriodEnd'
-   *                    - uint32_t  'FilterReadStatus'
-   *                    - nsString  'FilterRecipient'
-   *                    - nsString  'FilterOriginator'
-   *                    - uint32_t  'FilterPriority'
-   */
-  void HandleMapMessagesListing(const BluetoothValue& aValue);
-
-  /**
-   * Handle "MapGetMessage" bluetooth signal.
-   *
-   * @param aValue [in] Properties array of the MAP request.
-   *                    The array should contain a few properties:
-   *                    - bool       'Attachment'
-   *                    - nsString   'Charset'
-   */
-  void HandleMapGetMessage(const BluetoothValue& aValue);
-
-  /**
-   * Handle "MapSetMessageStatus" bluetooth signal.
-   *
-   * @param aValue [in] Properties array of the scanned device.
-   *                    The array should contain a few properties:
-   *                    - long       'HandleId'
-   *                    - uint32_t   'StatusIndicator'
-   *                    - bool       'StatusValue'
-   */
-  void HandleMapSetMessageStatus(const BluetoothValue& aValue);
-
-  /**
-   * Handle "MapSendMessage" bluetooth signal.
-   *
-   * @param aValue [in] Properties array of the scanned device.
-   *                    The array should contain a few properties:
-   *                    - nsString    'Recipient'
-   *                    - nsString    'MessageBody'
-   *                    - uint32_t    'Retry'
-   */
-  void HandleMapSendMessage(const BluetoothValue& aValue);
-
-  /**
-   * Handle "MapMessageUpdate" bluetooth signal.
-   *
-   * @param aValue [in] Properties array of the scanned device.
-   *                    - nsString     'MASInstanceID'
-   */
-  void HandleMapMessageUpdate(const BluetoothValue& aValue);
-
-  /**
-   * Get a Sequence of ParameterMask from a BluetoothValue. The name of
-   * BluetoothValue must be parameterMask.
-   *
-   * @param aValue [in] a BluetoothValue with 'TArrayOfuint32_t' type
-   *                    The name of BluetoothValue must be 'parameterMask'.
-   */
-  Sequence<ParameterMask> GetParameterMask(const BluetoothValue &aValue);
-
-  /**
-   * Fire BluetoothAttributeEvent to trigger onattributechanged event handler.
-   *
-   * @param aTypes [in] Array of changed attributes. Must be non-empty.
-   */
-  void DispatchAttributeEvent(const Sequence<nsString>& aTypes);
-
-  /**
-   * Fire BluetoothDeviceEvent to trigger
-   * ondeviceparied/ondeviceunpaired event handler.
-   *
-   * @param aType [in] Event type to fire
-   * @param aInit [in] Event initialization value
-   */
-  void DispatchDeviceEvent(const nsAString& aType,
-                           const BluetoothDeviceEventInit& aInit);
-
-  /**
-   * Fire event with no argument
-   *
-   * @param aType [in] Event type to fire
-   */
-  void DispatchEmptyEvent(const nsAString& aType);
-
-  /**
-   * Convert string to BluetoothAdapterAttribute.
-   *
-   * @param aString [in] String to convert
-   *
-   * @return the adapter attribute converted from |aString|
-   */
-  BluetoothAdapterAttribute
-    ConvertStringToAdapterAttribute(const nsAString& aString);
-
-  /**
-   * Check whether value of given adapter property has changed.
-   *
-   * @param aType  [in] Adapter property to check
-   * @param aValue [in] New value of the adapter property
-   *
-   * @return true if the adapter property has changed; false otherwise
-   */
-  bool IsAdapterAttributeChanged(BluetoothAdapterAttribute aType,
-                                 const BluetoothValue& aValue);
-
-  /**
-   * Check whether this adapter belongs to Bluetooth certified app.
-   *
-   * @return true if this adapter belongs to Bluetooth app; false otherwise
-   */
-  bool IsBluetoothCertifiedApp();
-
-  /****************************************************************************
-   * Variables
-   ***************************************************************************/
-  /**
-   * Current state of this adapter. Can be Disabled/Disabling/Enabled/Enabling.
-   */
-  BluetoothAdapterState mState;
-
-  /**
-   * BD address of this adapter.
-   */
-  nsString mAddress;
-
-  /**
-   * Human-readable name of this adapter.
-   */
-  nsString mName;
-
-  /**
-   * Whether this adapter can be discovered by nearby devices.
-   */
-  bool mDiscoverable;
-
-  /**
-   * Whether this adapter is discovering nearby devices.
-   */
-  bool mDiscovering;
-
-  /**
-   * GATT server object of this adapter.
-   *
-   * A new GATT server object will be created at the first time when
-   * |GetGattServer| is called after the adapter has been enabled. If the
-   * adapter has been disabled later on, the created GATT server will be
-   * discard by the adapter, and this GATT object should stop working till the
-   * end of its life. When |GetGattServer| is called after the adapter has been
-   * enabled again, a new GATT server object will be created.
-   */
-  RefPtr<BluetoothGattServer> mGattServer;
-
-  /**
-   * Handle to fire pairing requests of different pairing types.
-   */
-  RefPtr<BluetoothPairingListener> mPairingReqs;
-
-  /**
-   * Handle to fire 'ondevicefound' event handler for discovered device.
-   *
-   * This variable is set to the latest discovery handle when adapter just
-   * starts discovery, and is reset to nullptr when discovery is stopped by
-   * some adapter.
-   */
-  RefPtr<BluetoothDiscoveryHandle> mDiscoveryHandleInUse;
-
-  /**
-   * Handles to fire 'ondevicefound' event handler for scanned device
-   *
-   * Each non-stopped LeScan process has a LeScan handle which is
-   * responsible to dispatch LeDeviceEvent.
-   */
-  nsTArray<RefPtr<BluetoothDiscoveryHandle> > mLeScanHandleArray;
-
-  /**
-   * RefPtr array of BluetoothDevices created by this adapter. The array is
-   * empty when adapter state is Disabled.
-   *
-   * Devices will be appended when
-   *   1) adapter is enabling: Paired devices reported by stack.
-   *   2) adapter is discovering: Discovered devices during discovery operation.
-   *   3) adapter paired with a device: The paired device reported by stack.
-   * Note devices with identical address won't be appended.
-   *
-   * Devices will be removed when
-   *   1) adapter is disabling: All devices will be removed.
-   *   2) adapter starts discovery: All unpaired devices will be removed before
-   *      this new discovery starts.
-   *   3) adapter unpaired with a device: The unpaired device will be removed.
-   */
-  nsTArray<RefPtr<BluetoothDevice> > mDevices;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothAdapter_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothClassOfDevice.cpp
+++ /dev/null
@@ -1,102 +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 "BluetoothClassOfDevice.h"
-
-#include "mozilla/dom/BluetoothClassOfDeviceBinding.h"
-#include "nsThreadUtils.h"
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(BluetoothClassOfDevice, mOwnerWindow)
-NS_IMPL_CYCLE_COLLECTING_ADDREF(BluetoothClassOfDevice)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(BluetoothClassOfDevice)
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BluetoothClassOfDevice)
-  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
-
-/*
- * Class of Device(CoD): 32-bit unsigned integer
- *
- *  31   24  23    13 12     8 7      2 1 0
- * |       | Major   | Major  | Minor  |   |
- * |       | service | device | device |   |
- * |       | class   | class  | class  |   |
- * |       |<- 11  ->|<- 5  ->|<- 6  ->|   |
- *
- * https://www.bluetooth.org/en-us/specification/assigned-numbers/baseband
- */
-
-// Bit 23 ~ Bit 13: Major service class
-#define GET_MAJOR_SERVICE_CLASS(cod) (((cod) & 0xffe000) >> 13)
-
-// Bit 12 ~ Bit 8: Major device class
-#define GET_MAJOR_DEVICE_CLASS(cod)  (((cod) & 0x1f00) >> 8)
-
-// Bit 7 ~ Bit 2: Minor device class
-#define GET_MINOR_DEVICE_CLASS(cod)  (((cod) & 0xfc) >> 2)
-
-BluetoothClassOfDevice::BluetoothClassOfDevice(nsPIDOMWindowInner* aOwner)
-  : mOwnerWindow(aOwner)
-{
-  MOZ_ASSERT(aOwner);
-
-  Reset();
-}
-
-BluetoothClassOfDevice::~BluetoothClassOfDevice()
-{}
-
-void
-BluetoothClassOfDevice::Reset()
-{
-  mMajorServiceClass = 0;
-  mMajorDeviceClass = 0x1F; // UNCATEGORIZED
-  mMinorDeviceClass = 0;
-}
-
-bool
-BluetoothClassOfDevice::Equals(const uint32_t aValue)
-{
-  return (mMajorServiceClass == GET_MAJOR_SERVICE_CLASS(aValue) &&
-          mMajorDeviceClass == GET_MAJOR_DEVICE_CLASS(aValue) &&
-          mMinorDeviceClass == GET_MINOR_DEVICE_CLASS(aValue));
-}
-
-uint32_t
-BluetoothClassOfDevice::ToUint32()
-{
-  return (mMajorServiceClass & 0x7ff) << 13 |
-         (mMajorDeviceClass & 0x1f) << 8 |
-         (mMinorDeviceClass & 0x3f) << 2;
-}
-
-void
-BluetoothClassOfDevice::Update(const uint32_t aValue)
-{
-  mMajorServiceClass = GET_MAJOR_SERVICE_CLASS(aValue);
-  mMajorDeviceClass = GET_MAJOR_DEVICE_CLASS(aValue);
-  mMinorDeviceClass = GET_MINOR_DEVICE_CLASS(aValue);
-}
-
-// static
-already_AddRefed<BluetoothClassOfDevice>
-BluetoothClassOfDevice::Create(nsPIDOMWindowInner* aOwner)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aOwner);
-
-  RefPtr<BluetoothClassOfDevice> cod = new BluetoothClassOfDevice(aOwner);
-  return cod.forget();
-}
-
-JSObject*
-BluetoothClassOfDevice::WrapObject(JSContext* aCx,
-                                   JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothClassOfDeviceBinding::Wrap(aCx, this, aGivenProto);
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothClassOfDevice.h
+++ /dev/null
@@ -1,93 +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_BluetoothClassOfDevice_h
-#define mozilla_dom_bluetooth_BluetoothClassOfDevice_h
-
-#include "BluetoothCommon.h"
-#include "mozilla/Attributes.h"
-#include "mozilla/ErrorResult.h"
-#include "nsCycleCollectionParticipant.h"
-#include "nsPIDOMWindow.h"
-#include "nsWrapperCache.h"
-
-struct JSContext;
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothClassOfDevice final : public nsISupports
-                                   , public nsWrapperCache
-{
-public:
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(BluetoothClassOfDevice)
-
-  static already_AddRefed<BluetoothClassOfDevice>
-    Create(nsPIDOMWindowInner* aOwner);
-
-  uint16_t MajorServiceClass() const
-  {
-    return mMajorServiceClass;
-  }
-
-  uint8_t MajorDeviceClass() const
-  {
-    return mMajorDeviceClass;
-  }
-
-  uint8_t MinorDeviceClass() const
-  {
-    return mMinorDeviceClass;
-  }
-
-  /**
-   * Compare whether CoD equals to CoD value.
-   *
-   * @param aValue [in] CoD value to compare
-   */
-  bool Equals(const uint32_t aValue);
-
-  /**
-   * Convert CoD to uint32_t CoD value.
-   *
-   * TODO: Remove this function once we replace uint32_t cod value with
-   *       BluetoothClassOfDevice in BluetoothProfileController.
-   */
-  uint32_t ToUint32();
-
-  /**
-   * Update CoD.
-   *
-   * @param aValue [in] CoD value to update
-   */
-  void Update(const uint32_t aValue);
-
-  nsPIDOMWindowInner* GetParentObject() const
-  {
-    return mOwnerWindow;
-  }
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-
-private:
-  BluetoothClassOfDevice(nsPIDOMWindowInner* aOwner);
-  ~BluetoothClassOfDevice();
-
-  /**
-   * Reset CoD to default value.
-   */
-  void Reset();
-
-  uint16_t mMajorServiceClass;
-  uint8_t mMajorDeviceClass;
-  uint8_t mMinorDeviceClass;
-
-  nsCOMPtr<nsPIDOMWindowInner> mOwnerWindow;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothClassOfDevice_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothDevice.cpp
+++ /dev/null
@@ -1,454 +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 "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-#include "BluetoothUtils.h"
-
-#include "mozilla/dom/BluetoothAttributeEvent.h"
-#include "mozilla/dom/BluetoothDeviceBinding.h"
-#include "mozilla/dom/bluetooth/BluetoothClassOfDevice.h"
-#include "mozilla/dom/bluetooth/BluetoothDevice.h"
-#include "mozilla/dom/bluetooth/BluetoothGatt.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/dom/Promise.h"
-
-using namespace mozilla;
-using namespace mozilla::dom;
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothDevice)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothDevice,
-                                                DOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mCod)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mGatt)
-
-  /**
-   * Unregister the bluetooth signal handler after unlinked.
-   *
-   * This is needed to avoid ending up with exposing a deleted object to JS or
-   * accessing deleted objects while receiving signals from parent process
-   * after unlinked. Please see Bug 1138267 for detail informations.
-   */
-  UnregisterBluetoothSignalHandler(tmp->mAddress, tmp);
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothDevice,
-                                                  DOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCod)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGatt)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothDevice)
-NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
-
-NS_IMPL_ADDREF_INHERITED(BluetoothDevice, DOMEventTargetHelper)
-NS_IMPL_RELEASE_INHERITED(BluetoothDevice, DOMEventTargetHelper)
-
-class FetchUuidsTask final : public BluetoothReplyRunnable
-{
-public:
-  FetchUuidsTask(Promise* aPromise,
-                 BluetoothDevice* aDevice)
-    : BluetoothReplyRunnable(nullptr, aPromise)
-    , mDevice(aDevice)
-  {
-    MOZ_ASSERT(aPromise);
-    MOZ_ASSERT(aDevice);
-  }
-
-  bool ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue)
-  {
-    aValue.setUndefined();
-
-    const BluetoothValue& v = mReply->get_BluetoothReplySuccess().value();
-    NS_ENSURE_TRUE(v.type() == BluetoothValue::TArrayOfnsString, false);
-    const InfallibleTArray<nsString>& uuids = v.get_ArrayOfnsString();
-
-    AutoJSAPI jsapi;
-    NS_ENSURE_TRUE(jsapi.Init(mDevice->GetParentObject()), false);
-
-    JSContext* cx = jsapi.cx();
-    if (!ToJSValue(cx, uuids, aValue)) {
-      BT_WARNING("Cannot create JS array!");
-      jsapi.ClearException();
-      return false;
-    }
-
-    return true;
-  }
-
-  virtual void ReleaseMembers() override
-  {
-    BluetoothReplyRunnable::ReleaseMembers();
-    mDevice = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothDevice> mDevice;
-};
-
-BluetoothDevice::BluetoothDevice(nsPIDOMWindowInner* aWindow,
-                                 const BluetoothValue& aValue)
-  : DOMEventTargetHelper(aWindow)
-  , mPaired(false)
-  , mType(BluetoothDeviceType::Unknown)
-{
-  MOZ_ASSERT(aWindow);
-
-  mCod = BluetoothClassOfDevice::Create(aWindow);
-
-  const InfallibleTArray<BluetoothNamedValue>& values =
-    aValue.get_ArrayOfBluetoothNamedValue();
-  for (uint32_t i = 0; i < values.Length(); ++i) {
-    SetPropertyByValue(values[i]);
-  }
-
-  RegisterBluetoothSignalHandler(mAddress, this);
-}
-
-BluetoothDevice::~BluetoothDevice()
-{
-  UnregisterBluetoothSignalHandler(mAddress, this);
-}
-
-void
-BluetoothDevice::GetUuids(nsTArray<nsString>& aUuids) const
-{
-  aUuids.Clear();
-  for (size_t i = 0; i < mUuids.Length(); ++i) {
-    nsAutoString uuidStr;
-    UuidToString(mUuids[i], uuidStr);
-    aUuids.AppendElement(uuidStr);
-  }
-}
-
-void
-BluetoothDevice::DisconnectFromOwner()
-{
-  DOMEventTargetHelper::DisconnectFromOwner();
-  UnregisterBluetoothSignalHandler(mAddress, this);
-}
-
-BluetoothDeviceType
-BluetoothDevice::ConvertUint32ToDeviceType(const uint32_t aValue)
-{
-  static const BluetoothDeviceType sDeviceType[] = {
-    [TYPE_OF_DEVICE_BREDR] = BluetoothDeviceType::Classic,
-    [TYPE_OF_DEVICE_BLE] = BluetoothDeviceType::Le,
-    [TYPE_OF_DEVICE_DUAL] = BluetoothDeviceType::Dual,
-  };
-
-  BluetoothTypeOfDevice type = static_cast<BluetoothTypeOfDevice>(aValue);
-  if (type >= MOZ_ARRAY_LENGTH(sDeviceType)) {
-    return BluetoothDeviceType::Unknown;
-  }
-  return sDeviceType[type];
-}
-
-void
-BluetoothDevice::SetPropertyByValue(const BluetoothNamedValue& aValue)
-{
-  const nsString& name = aValue.name();
-  const BluetoothValue& value = aValue.value();
-  if (name.EqualsLiteral("Name")) {
-    RemoteNameToString(value.get_BluetoothRemoteName(), mName);
-  } else if (name.EqualsLiteral("Address")) {
-    if (value.get_BluetoothAddress().IsCleared()) {
-      mAddress.Truncate(); // Reset to empty string
-    } else {
-      AddressToString(value.get_BluetoothAddress(), mAddress);
-    }
-  } else if (name.EqualsLiteral("Cod")) {
-    mCod->Update(value.get_uint32_t());
-  } else if (name.EqualsLiteral("Paired")) {
-    mPaired = value.get_bool();
-  } else if (name.EqualsLiteral("UUIDs")) {
-    // We sort the received UUIDs and remove any duplicates.
-    const nsTArray<BluetoothUuid>& uuids = value.get_ArrayOfBluetoothUuid();
-    nsTArray<nsString> uuidStrs;
-    mUuids.Clear();
-    for (uint32_t index = 0; index < uuids.Length(); ++index) {
-      if (!mUuids.Contains(uuids[index])) { // filter out duplicate UUIDs
-        mUuids.InsertElementSorted(uuids[index]);
-      }
-    }
-    BluetoothDeviceBinding::ClearCachedUuidsValue(this);
-  } else if (name.EqualsLiteral("Type")) {
-    mType = ConvertUint32ToDeviceType(value.get_uint32_t());
-  } else if (name.EqualsLiteral("GattAdv")) {
-    MOZ_ASSERT(value.type() == BluetoothValue::TArrayOfuint8_t);
-    nsTArray<uint8_t> advData;
-    advData = value.get_ArrayOfuint8_t();
-    UpdatePropertiesFromAdvData(advData);
-  } else {
-    BT_WARNING("Not handling device property: %s",
-               NS_ConvertUTF16toUTF8(name).get());
-  }
-}
-
-already_AddRefed<Promise>
-BluetoothDevice::FetchUuids(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  // Ensure BluetoothService is available
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-  BluetoothAddress address;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToAddress(mAddress, address)),
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-  BT_ENSURE_TRUE_REJECT(
-    NS_SUCCEEDED(
-      bs->FetchUuidsInternal(address, new FetchUuidsTask(promise, this))),
-    promise, NS_ERROR_DOM_OPERATION_ERR);
-
-  return promise.forget();
-}
-
-// static
-already_AddRefed<BluetoothDevice>
-BluetoothDevice::Create(nsPIDOMWindowInner* aWindow,
-                        const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aWindow);
-
-  RefPtr<BluetoothDevice> device = new BluetoothDevice(aWindow, aValue);
-  return device.forget();
-}
-
-void
-BluetoothDevice::Notify(const BluetoothSignal& aData)
-{
-  BT_LOGD("[D] %s", NS_ConvertUTF16toUTF8(aData.name()).get());
-  NS_ENSURE_TRUE_VOID(mSignalRegistered);
-
-  BluetoothValue v = aData.value();
-  if (aData.name().EqualsLiteral("PropertyChanged")) {
-    HandlePropertyChanged(v);
-  } else {
-    BT_WARNING("Not handling device signal: %s",
-               NS_ConvertUTF16toUTF8(aData.name()).get());
-  }
-}
-
-BluetoothDeviceAttribute
-BluetoothDevice::ConvertStringToDeviceAttribute(const nsAString& aString)
-{
-  using namespace
-    mozilla::dom::BluetoothDeviceAttributeValues;
-
-  for (size_t index = 0; index < ArrayLength(strings) - 1; index++) {
-    if (aString.LowerCaseEqualsASCII(strings[index].value,
-                                     strings[index].length)) {
-      return static_cast<BluetoothDeviceAttribute>(index);
-    }
-  }
-
-  return BluetoothDeviceAttribute::Unknown;
-}
-
-bool
-BluetoothDevice::IsDeviceAttributeChanged(BluetoothDeviceAttribute aType,
-                                          const BluetoothValue& aValue)
-{
-  switch (aType) {
-    case BluetoothDeviceAttribute::Cod:
-      MOZ_ASSERT(aValue.type() == BluetoothValue::Tuint32_t);
-      return !mCod->Equals(aValue.get_uint32_t());
-    case BluetoothDeviceAttribute::Name: {
-        MOZ_ASSERT(aValue.type() == BluetoothValue::TBluetoothRemoteName);
-        nsAutoString remoteNameStr;
-        RemoteNameToString(aValue.get_BluetoothRemoteName(), remoteNameStr);
-        return !mName.Equals(remoteNameStr);
-      }
-    case BluetoothDeviceAttribute::Paired:
-      MOZ_ASSERT(aValue.type() == BluetoothValue::Tbool);
-      return mPaired != aValue.get_bool();
-    case BluetoothDeviceAttribute::Uuids: {
-      MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothUuid);
-      const auto& uuids = aValue.get_ArrayOfBluetoothUuid();
-      nsTArray<BluetoothUuid> sortedUuids;
-      // Construct a sorted UUID set
-      for (size_t index = 0; index < uuids.Length(); ++index) {
-        if (!sortedUuids.Contains(uuids[index])) { // filter out duplicate uuids
-          sortedUuids.InsertElementSorted(uuids[index]);
-        }
-      }
-      return mUuids != sortedUuids;
-    }
-    default:
-      BT_WARNING("Type %d is not handled", uint32_t(aType));
-      return false;
-  }
-}
-
-void
-BluetoothDevice::HandlePropertyChanged(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  Sequence<nsString> types;
-  for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) {
-    BluetoothDeviceAttribute type =
-      ConvertStringToDeviceAttribute(arr[i].name());
-
-    // Non-BluetoothDeviceAttribute properties
-    if (type == BluetoothDeviceAttribute::Unknown) {
-      SetPropertyByValue(arr[i]);
-      continue;
-    }
-
-    // BluetoothDeviceAttribute properties
-    if (IsDeviceAttributeChanged(type, arr[i].value())) {
-      SetPropertyByValue(arr[i]);
-      BT_APPEND_ENUM_STRING_FALLIBLE(types, BluetoothDeviceAttribute, type);
-    }
-  }
-
-  if (types.IsEmpty()) {
-    // No device attribute changed
-    return;
-  }
-
-  DispatchAttributeEvent(types);
-}
-
-void
-BluetoothDevice::DispatchAttributeEvent(const Sequence<nsString>& aTypes)
-{
-  MOZ_ASSERT(!aTypes.IsEmpty());
-
-  BluetoothAttributeEventInit init;
-  init.mAttrs = aTypes;
-  RefPtr<BluetoothAttributeEvent> event =
-    BluetoothAttributeEvent::Constructor(
-      this, NS_LITERAL_STRING(ATTRIBUTE_CHANGED_ID), init);
-
-  DispatchTrustedEvent(event);
-}
-
-BluetoothGatt*
-BluetoothDevice::GetGatt()
-{
-  NS_ENSURE_TRUE(mType == BluetoothDeviceType::Le ||
-                 mType == BluetoothDeviceType::Dual,
-                 nullptr);
-  if (!mGatt) {
-    mGatt = new BluetoothGatt(GetOwner(), mAddress);
-  }
-
-  return mGatt;
-}
-
-void
-BluetoothDevice::UpdatePropertiesFromAdvData(const nsTArray<uint8_t>& aAdvData)
-{
-  // According to BT Core Spec. Vol 3 - Ch 11, advertisement data consists of a
-  // significant part and a non-significant part.
-  // The significant part contains a sequence of AD structures. Each AD
-  // structure shall have a Length field of one octet, which contains the
-  // Length value, and a Data field of Length octets.
-  unsigned int offset = 0;
-  while (offset < aAdvData.Length()) {
-    int dataFieldLength = aAdvData[offset++];
-
-    // According to BT Core Spec, it only occurs to allow an early termination
-    // of the Advertising data.
-    if (dataFieldLength <= 0) {
-      break;
-    }
-
-    // Length of the data field which is composed by AD type (1 byte) and
-    // AD data (dataFieldLength -1 bytes)
-    int dataLength = dataFieldLength - 1;
-    if (offset + dataLength >= aAdvData.Length()) {
-      break;
-    }
-
-    // Update UUIDs and name of BluetoothDevice.
-    BluetoothGapDataType type =
-      static_cast<BluetoothGapDataType>(aAdvData[offset++]);
-    switch (type) {
-      case GAP_INCOMPLETE_UUID16:
-      case GAP_COMPLETE_UUID16:
-      case GAP_INCOMPLETE_UUID32:
-      case GAP_COMPLETE_UUID32:
-      case GAP_INCOMPLETE_UUID128:
-      case GAP_COMPLETE_UUID128: {
-        mUuids.Clear();
-
-        while (dataLength > 0) {
-          BluetoothUuid uuid;
-          size_t length = 0;
-          if (type == GAP_INCOMPLETE_UUID16 || type == GAP_COMPLETE_UUID16) {
-            length = 2;
-            if (NS_FAILED(BytesToUuid(aAdvData, offset, UUID_16_BIT,
-                                      ENDIAN_GAP, uuid))) {
-              break;
-            }
-          } else if (type == GAP_INCOMPLETE_UUID32 ||
-                     type == GAP_COMPLETE_UUID32) {
-            length = 4;
-            if (NS_FAILED(BytesToUuid(aAdvData, offset, UUID_32_BIT,
-                                      ENDIAN_GAP, uuid))) {
-              break;
-            }
-          } else if (type == GAP_INCOMPLETE_UUID128 ||
-                     type == GAP_COMPLETE_UUID128) {
-            length = 16;
-            if (NS_FAILED(BytesToUuid(aAdvData, offset, UUID_128_BIT,
-                                      ENDIAN_GAP, uuid))) {
-              break;
-            }
-          }
-          mUuids.AppendElement(uuid);
-          offset += length;
-          dataLength -= length;
-        }
-
-        BluetoothDeviceBinding::ClearCachedUuidsValue(this);
-        break;
-      }
-      case GAP_SHORTENED_NAME:
-        if (!mName.IsEmpty()) break;
-      case GAP_COMPLETE_NAME: {
-        // Read device name from data buffer.
-        char deviceName[dataLength];
-        for (int i = 0; i < dataLength; ++i) {
-          deviceName[i] = aAdvData[offset++];
-        }
-
-        mName.AssignASCII(deviceName, dataLength);
-        break;
-      }
-      default:
-        offset += dataLength;
-        break;
-    }
-  }
-}
-
-JSObject*
-BluetoothDevice::WrapObject(JSContext* aContext,
-                            JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothDeviceBinding::Wrap(aContext, this, aGivenProto);
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothDevice.h
+++ /dev/null
@@ -1,255 +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_BluetoothDevice_h
-#define mozilla_dom_bluetooth_BluetoothDevice_h
-
-#include "mozilla/Attributes.h"
-#include "mozilla/DOMEventTargetHelper.h"
-#include "mozilla/dom/BluetoothDeviceBinding.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "nsString.h"
-#include "nsCOMPtr.h"
-
-namespace mozilla {
-namespace dom {
-  class Promise;
-}
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothClassOfDevice;
-class BluetoothGatt;
-class BluetoothNamedValue;
-class BluetoothValue;
-class BluetoothSignal;
-
-class BluetoothDevice final : public DOMEventTargetHelper
-                            , public BluetoothSignalObserver
-{
-public:
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BluetoothDevice,
-                                           DOMEventTargetHelper)
-
-  /****************************************************************************
-   * Attribute Getters
-   ***************************************************************************/
-  void GetAddress(nsString& aAddress) const
-  {
-    aAddress = mAddress;
-  }
-
-  BluetoothClassOfDevice* Cod() const
-  {
-    return mCod;
-  }
-
-  void GetName(nsString& aName) const
-  {
-    aName = mName;
-  }
-
-  bool Paired() const
-  {
-    return mPaired;
-  }
-
-  void GetUuids(nsTArray<nsString>& aUuids) const;
-
-  BluetoothDeviceType Type() const
-  {
-    return mType;
-  }
-
-  BluetoothGatt* GetGatt();
-
-  /****************************************************************************
-   * Event Handlers
-   ***************************************************************************/
-  IMPL_EVENT_HANDLER(attributechanged);
-
-  /****************************************************************************
-   * Methods (Web API Implementation)
-   ***************************************************************************/
-  already_AddRefed<Promise> FetchUuids(ErrorResult& aRv);
-
-  /****************************************************************************
-   * Others
-   ***************************************************************************/
-  static already_AddRefed<BluetoothDevice>
-    Create(nsPIDOMWindowInner* aOwner, const BluetoothValue& aValue);
-
-  void Notify(const BluetoothSignal& aParam); // BluetoothSignalObserver
-  nsPIDOMWindowInner* GetParentObject() const
-  {
-     return GetOwner();
-  }
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-  virtual void DisconnectFromOwner() override;
-
-  void GetUuids(nsTArray<BluetoothUuid>& aUuids) const
-  {
-    aUuids = mUuids;
-  }
-
-private:
-  BluetoothDevice(nsPIDOMWindowInner* aOwner, const BluetoothValue& aValue);
-  ~BluetoothDevice();
-
-  /**
-   * Set device properties according to properties array
-   *
-   * @param aValue [in] Properties array to set with
-   */
-  void SetPropertyByValue(const BluetoothNamedValue& aValue);
-
-  /**
-   * Handle "PropertyChanged" bluetooth signal.
-   *
-   * @param aValue [in] Array of changed properties
-   */
-  void HandlePropertyChanged(const BluetoothValue& aValue);
-
-  /**
-   * Fire BluetoothAttributeEvent to trigger onattributechanged event handler.
-   *
-   * @param aTypes [in] Array of changed attributes. Must be non-empty.
-   */
-  void DispatchAttributeEvent(const Sequence<nsString>& aTypes);
-
-  /**
-   * Convert uint32_t to BluetoothDeviceType.
-   *
-   * @param aValue [in] uint32_t to convert
-   *
-   * @return the device type converted from |aValue|
-   */
-  BluetoothDeviceType ConvertUint32ToDeviceType(const uint32_t aValue);
-
-  /**
-   * Convert string to BluetoothDeviceAttribute.
-   *
-   * @param aString [in] String to convert
-   *
-   * @return the device attribute converted from |aString|
-   */
-  BluetoothDeviceAttribute
-    ConvertStringToDeviceAttribute(const nsAString& aString);
-
-  /**
-   * Check whether value of given device property has changed.
-   *
-   * @param aType  [in] Device property to check
-   * @param aValue [in] New value of the device property
-   *
-   * @return true is the device attribute has changed; false otherwise
-   */
-  bool IsDeviceAttributeChanged(BluetoothDeviceAttribute aType,
-                                const BluetoothValue& aValue);
-
-  /**
-   * Parse advertising data to update device properties.
-   *
-   * Parse 'Advertising Data Type' from an inquiry response and set name, UUIDs
-   * and COD if they exist in ADV data.
-   *
-   * @param aAdvData [in] advertising data from LeScan result.
-   */
-  void UpdatePropertiesFromAdvData(const nsTArray<uint8_t>& aAdvData);
-
-  /****************************************************************************
-   * Variables
-   ***************************************************************************/
-  /**
-   * BD address of this device.
-   */
-  nsString mAddress;
-
-  /**
-   * Class of device (CoD) that describes this device's capabilities.
-   */
-  RefPtr<BluetoothClassOfDevice> mCod;
-
-  /**
-   * Human-readable name of this device.
-   */
-  nsString mName;
-
-  /**
-   * Whether this device is paired or not.
-   */
-  bool mPaired;
-
-  /**
-   * Cached UUID list of services which this device provides.
-   */
-  nsTArray<BluetoothUuid> mUuids;
-
-  /**
-   * Type of this device. Can be unknown/classic/le/dual.
-   */
-  BluetoothDeviceType mType;
-
-  /**
-   * GATT client object to interact with the remote device.
-   */
-  RefPtr<BluetoothGatt> mGatt;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-/**
- * Explicit Specialization of Function Templates
- *
- * Allows customizing the template code for a given set of template arguments.
- * With this function template, nsTArray can handle comparison of
- * 'RefPtr<BluetoothDevice>' properly, including IndexOf() and Contains();
- */
-template <>
-class nsDefaultComparator <RefPtr<mozilla::dom::bluetooth::BluetoothDevice>,
-                           RefPtr<mozilla::dom::bluetooth::BluetoothDevice>> {
-  public:
-
-    bool Equals(
-      const RefPtr<mozilla::dom::bluetooth::BluetoothDevice>& aDeviceA,
-      const RefPtr<mozilla::dom::bluetooth::BluetoothDevice>& aDeviceB) const
-    {
-      nsString addressA, addressB;
-      aDeviceA->GetAddress(addressA);
-      aDeviceB->GetAddress(addressB);
-
-      return addressA.Equals(addressB);
-    }
-};
-
-/**
- * Explicit Specialization of Function Templates
- *
- * Allows customizing the template code for a given set of template arguments.
- * With this function template, nsTArray can handle comparison between
- * 'RefPtr<BluetoothDevice>' and nsString properly, including IndexOf() and
- * Contains();
- */
-template <>
-class nsDefaultComparator <RefPtr<mozilla::dom::bluetooth::BluetoothDevice>,
-                           nsString> {
-public:
-  bool Equals(
-    const RefPtr<mozilla::dom::bluetooth::BluetoothDevice>& aDevice,
-    const nsString& aAddress) const
-  {
-    nsString deviceAddress;
-    aDevice->GetAddress(deviceAddress);
-
-    return deviceAddress.Equals(aAddress);
-  }
-};
-
-#endif // mozilla_dom_bluetooth_BluetoothDevice_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothDiscoveryHandle.cpp
+++ /dev/null
@@ -1,134 +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 "BluetoothService.h"
-#include "mozilla/dom/BluetoothDeviceEvent.h"
-#include "mozilla/dom/BluetoothDiscoveryHandleBinding.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/bluetooth/BluetoothDiscoveryHandle.h"
-#include "mozilla/dom/bluetooth/BluetoothLeDeviceEvent.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "nsThreadUtils.h"
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothDiscoveryHandle)
-NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
-
-NS_IMPL_ADDREF_INHERITED(BluetoothDiscoveryHandle, DOMEventTargetHelper)
-NS_IMPL_RELEASE_INHERITED(BluetoothDiscoveryHandle, DOMEventTargetHelper)
-
-BluetoothDiscoveryHandle::BluetoothDiscoveryHandle(nsPIDOMWindowInner* aWindow)
-  : DOMEventTargetHelper(aWindow)
-{
-  MOZ_ASSERT(aWindow);
-}
-
-BluetoothDiscoveryHandle::BluetoothDiscoveryHandle(
-  nsPIDOMWindowInner* aWindow,
-  const nsTArray<BluetoothUuid>& aServiceUuids,
-  const BluetoothUuid& aLeScanUuid)
-  : DOMEventTargetHelper(aWindow)
-  , mLeScanUuid(aLeScanUuid)
-  , mServiceUuids(aServiceUuids)
-{
-  MOZ_ASSERT(aWindow);
-}
-
-BluetoothDiscoveryHandle::~BluetoothDiscoveryHandle()
-{
-}
-
-// static
-already_AddRefed<BluetoothDiscoveryHandle>
-BluetoothDiscoveryHandle::Create(nsPIDOMWindowInner* aWindow)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aWindow);
-
-  RefPtr<BluetoothDiscoveryHandle> handle =
-    new BluetoothDiscoveryHandle(aWindow);
-  return handle.forget();
-}
-
-already_AddRefed<BluetoothDiscoveryHandle>
-BluetoothDiscoveryHandle::Create(
-  nsPIDOMWindowInner* aWindow,
-  const nsTArray<BluetoothUuid>& aServiceUuids,
-  const BluetoothUuid& aLeScanUuid)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aWindow);
-
-  RefPtr<BluetoothDiscoveryHandle> handle =
-    new BluetoothDiscoveryHandle(aWindow, aServiceUuids, aLeScanUuid);
-  return handle.forget();
-}
-
-void
-BluetoothDiscoveryHandle::DispatchDeviceEvent(BluetoothDevice* aDevice)
-{
-  MOZ_ASSERT(aDevice);
-
-  BluetoothDeviceEventInit init;
-  init.mDevice = aDevice;
-
-  RefPtr<BluetoothDeviceEvent> event =
-    BluetoothDeviceEvent::Constructor(this,
-                                      NS_LITERAL_STRING("devicefound"),
-                                      init);
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothDiscoveryHandle::DispatchLeDeviceEvent(BluetoothDevice* aLeDevice,
-  int32_t aRssi, nsTArray<uint8_t>& aScanRecord)
-{
-  MOZ_ASSERT(aLeDevice);
-
-  nsTArray<BluetoothUuid> remoteUuids;
-  aLeDevice->GetUuids(remoteUuids);
-
-  bool hasUuidsFilter = !mServiceUuids.IsEmpty();
-  bool noAdvertisingUuid  = remoteUuids.IsEmpty();
-  // If an LE device doesn't advertise its service UUIDs, it can't possibly pass
-  // the UUIDs filter.
-  if (hasUuidsFilter && noAdvertisingUuid) {
-    return;
-  }
-
-  // The web API startLeScan() makes the device's adapter start seeking for
-  // remote LE devices advertising given service UUIDs.
-  // Since current Bluetooth stack can't filter the results of LeScan by UUIDs,
-  // gecko has to filter the results and dispatch what API asked for.
-  bool matched = false;
-  for (size_t index = 0; index < remoteUuids.Length(); ++index) {
-    if (mServiceUuids.Contains(remoteUuids[index])) {
-      matched = true;
-      break;
-    }
-  }
-
-  // Dispatch 'devicefound' event only if
-  //  - the service UUID in the scan record matches one of the given UUIDs.
-  //  - the given UUIDs is empty.
-  if (matched || mServiceUuids.IsEmpty()) {
-    RefPtr<BluetoothLeDeviceEvent> event =
-      BluetoothLeDeviceEvent::Constructor(this,
-                                          NS_LITERAL_STRING("devicefound"),
-                                          aLeDevice,
-                                          aRssi,
-                                          aScanRecord);
-    DispatchTrustedEvent(event);
-  }
-}
-
-JSObject*
-BluetoothDiscoveryHandle::WrapObject(JSContext* aCx,
-                                     JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothDiscoveryHandleBinding::Wrap(aCx, this, aGivenProto);
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothDiscoveryHandle.h
+++ /dev/null
@@ -1,79 +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_BluetoothDiscoveryHandle_h
-#define mozilla_dom_bluetooth_BluetoothDiscoveryHandle_h
-
-#include "mozilla/Attributes.h"
-#include "mozilla/DOMEventTargetHelper.h"
-#include "mozilla/dom/bluetooth/BluetoothAdapter.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "nsISupportsImpl.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothDevice;
-
-class BluetoothDiscoveryHandle final : public DOMEventTargetHelper
-{
-public:
-  NS_DECL_ISUPPORTS_INHERITED
-
-  static already_AddRefed<BluetoothDiscoveryHandle>
-    Create(nsPIDOMWindowInner* aWindow);
-
-  static already_AddRefed<BluetoothDiscoveryHandle>
-    Create(nsPIDOMWindowInner* aWindow,
-           const nsTArray<BluetoothUuid>& aServiceUuids,
-           const BluetoothUuid& aLeScanUuid);
-
-  void DispatchDeviceEvent(BluetoothDevice* aDevice);
-
-  void DispatchLeDeviceEvent(BluetoothDevice* aLeDevice,
-                             int32_t aRssi,
-                             nsTArray<uint8_t>& aScanRecord);
-
-  IMPL_EVENT_HANDLER(devicefound);
-
-  void GetLeScanUuid(BluetoothUuid& aLeScanUuid) const
-  {
-    aLeScanUuid = mLeScanUuid;
-  }
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-
-private:
-  BluetoothDiscoveryHandle(nsPIDOMWindowInner* aWindow);
-
-  BluetoothDiscoveryHandle(nsPIDOMWindowInner* aWindow,
-                           const nsTArray<BluetoothUuid>& aServiceUuids,
-                           const BluetoothUuid& aLeScanUuid);
-
-  ~BluetoothDiscoveryHandle();
-
-  /**
-   * Random generated UUID of LE scan
-   *
-   * This UUID is used only when the handle is built for LE scan.
-   * If BluetoothDiscoveryHandle is built for classic discovery, the value would
-   * remain empty string during the entire life cycle.
-   */
-  BluetoothUuid mLeScanUuid;
-
-  /**
-   * A BluetoothUuid array of service UUIDs to discover / scan for.
-   *
-   * This array is only used by LE scan. If BluetoothDiscoveryHandle is built
-   * for classic discovery, the array should be empty.
-   */
-  nsTArray<BluetoothUuid> mServiceUuids;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothDiscoveryHandle_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothGatt.cpp
+++ /dev/null
@@ -1,462 +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 "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-#include "BluetoothUtils.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/bluetooth/BluetoothGatt.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/dom/BluetoothGattBinding.h"
-#include "mozilla/dom/BluetoothGattCharacteristicEvent.h"
-#include "mozilla/dom/Event.h"
-#include "mozilla/dom/Promise.h"
-#include "nsServiceManagerUtils.h"
-
-using namespace mozilla;
-using namespace mozilla::dom;
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothGatt)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothGatt,
-                                                DOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mServices)
-
-  /**
-   * Unregister the bluetooth signal handler after unlinked.
-   *
-   * This is needed to avoid ending up with exposing a deleted object to JS or
-   * accessing deleted objects while receiving signals from parent process
-   * after unlinked. Please see Bug 1138267 for detail informations.
-   */
-  UnregisterBluetoothSignalHandler(tmp->mAppUuid, tmp);
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothGatt,
-                                                  DOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mServices)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothGatt)
-NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
-
-NS_IMPL_ADDREF_INHERITED(BluetoothGatt, DOMEventTargetHelper)
-NS_IMPL_RELEASE_INHERITED(BluetoothGatt, DOMEventTargetHelper)
-
-BluetoothGatt::BluetoothGatt(nsPIDOMWindowInner* aWindow,
-                             const nsAString& aDeviceAddr)
-  : DOMEventTargetHelper(aWindow)
-  , mClientIf(0)
-  , mConnectionState(BluetoothConnectionState::Disconnected)
-  , mDeviceAddr(aDeviceAddr)
-  , mDiscoveringServices(false)
-{
-  MOZ_ASSERT(aWindow);
-  MOZ_ASSERT(!mDeviceAddr.IsEmpty());
-}
-
-BluetoothGatt::~BluetoothGatt()
-{
-  BluetoothService* bs = BluetoothService::Get();
-  // bs can be null on shutdown, where destruction might happen.
-  NS_ENSURE_TRUE_VOID(bs);
-
-  if (mClientIf > 0) {
-    RefPtr<BluetoothVoidReplyRunnable> result =
-      new BluetoothVoidReplyRunnable(nullptr);
-    bs->UnregisterGattClientInternal(mClientIf, result);
-  }
-
-  UnregisterBluetoothSignalHandler(mAppUuid, this);
-}
-
-void
-BluetoothGatt::DisconnectFromOwner()
-{
-  DOMEventTargetHelper::DisconnectFromOwner();
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  if (mClientIf > 0) {
-    RefPtr<BluetoothVoidReplyRunnable> result =
-      new BluetoothVoidReplyRunnable(nullptr);
-    bs->UnregisterGattClientInternal(mClientIf, result);
-  }
-
-  UnregisterBluetoothSignalHandler(mAppUuid, this);
-}
-
-already_AddRefed<Promise>
-BluetoothGatt::Connect(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(
-    mConnectionState == BluetoothConnectionState::Disconnected,
-    promise,
-    NS_ERROR_DOM_INVALID_STATE_ERR);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  BluetoothAddress deviceAddr;
-  BT_ENSURE_TRUE_REJECT(
-    NS_SUCCEEDED(StringToAddress(mDeviceAddr, deviceAddr)),
-    promise,
-    NS_ERROR_DOM_OPERATION_ERR);
-
-  if (mAppUuid.IsEmpty()) {
-    nsresult rv = GenerateUuid(mAppUuid);
-    BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(rv) && !mAppUuid.IsEmpty(),
-                          promise,
-                          NS_ERROR_DOM_OPERATION_ERR);
-    RegisterBluetoothSignalHandler(mAppUuid, this);
-  }
-
-  BluetoothUuid appUuid;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToUuid(mAppUuid, appUuid)),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  UpdateConnectionState(BluetoothConnectionState::Connecting);
-  bs->ConnectGattClientInternal(
-    appUuid, deviceAddr, new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothGatt::Disconnect(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(
-    mConnectionState == BluetoothConnectionState::Connected,
-    promise,
-    NS_ERROR_DOM_INVALID_STATE_ERR);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  BluetoothUuid appUuid;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToUuid(mAppUuid, appUuid)),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  BluetoothAddress deviceAddr;
-  BT_ENSURE_TRUE_REJECT(
-    NS_SUCCEEDED(StringToAddress(mDeviceAddr, deviceAddr)),
-    promise,
-    NS_ERROR_DOM_OPERATION_ERR);
-
-  UpdateConnectionState(BluetoothConnectionState::Disconnecting);
-  bs->DisconnectGattClientInternal(
-    appUuid, deviceAddr, new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-class ReadRemoteRssiTask final : public BluetoothReplyRunnable
-{
-public:
-  ReadRemoteRssiTask(Promise* aPromise)
-    : BluetoothReplyRunnable(nullptr, aPromise)
-  {
-    MOZ_ASSERT(aPromise);
-  }
-
-  bool
-  ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue)
-  {
-    aValue.setUndefined();
-
-    const BluetoothValue& v = mReply->get_BluetoothReplySuccess().value();
-    NS_ENSURE_TRUE(v.type() == BluetoothValue::Tint32_t, false);
-
-    aValue.setInt32(static_cast<int32_t>(v.get_int32_t()));
-    return true;
-  }
-};
-
-already_AddRefed<Promise>
-BluetoothGatt::ReadRemoteRssi(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(
-    mConnectionState == BluetoothConnectionState::Connected,
-    promise,
-    NS_ERROR_DOM_INVALID_STATE_ERR);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  BluetoothAddress deviceAddr;
-  BT_ENSURE_TRUE_REJECT(
-    NS_SUCCEEDED(StringToAddress(mDeviceAddr, deviceAddr)),
-    promise,
-    NS_ERROR_DOM_OPERATION_ERR);
-
-  bs->GattClientReadRemoteRssiInternal(
-    mClientIf, deviceAddr, new ReadRemoteRssiTask(promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothGatt::DiscoverServices(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BluetoothUuid appUuid;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToUuid(mAppUuid, appUuid)),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  BT_ENSURE_TRUE_REJECT(
-    mConnectionState == BluetoothConnectionState::Connected &&
-    !mDiscoveringServices,
-    promise,
-    NS_ERROR_DOM_INVALID_STATE_ERR);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  mDiscoveringServices = true;
-  mServices.Clear();
-  BluetoothGattBinding::ClearCachedServicesValue(this);
-
-  bs->DiscoverGattServicesInternal(
-    appUuid, new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-void
-BluetoothGatt::UpdateConnectionState(BluetoothConnectionState aState)
-{
-  BT_LOGR("GATT connection state changes to: %d", int(aState));
-  mConnectionState = aState;
-
-  // Dispatch connectionstatechanged event to application
-  RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
-
-  event->InitEvent(NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID),
-                   false,
-                   false);
-
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothGatt::HandleServicesDiscovered(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothGattServiceId);
-
-  const InfallibleTArray<BluetoothGattServiceId>& serviceIds =
-    aValue.get_ArrayOfBluetoothGattServiceId();
-
-  mServices.Clear();
-  for (uint32_t i = 0; i < serviceIds.Length(); i++) {
-    mServices.AppendElement(new BluetoothGattService(
-      GetParentObject(), mAppUuid, serviceIds[i]));
-  }
-
-  BluetoothGattBinding::ClearCachedServicesValue(this);
-}
-
-void
-BluetoothGatt::HandleIncludedServicesDiscovered(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& values =
-    aValue.get_ArrayOfBluetoothNamedValue();
-  MOZ_ASSERT(values.Length() == 2); // ServiceId, IncludedServices
-  MOZ_ASSERT(values[0].name().EqualsLiteral("serviceId"));
-  MOZ_ASSERT(values[0].value().type() ==
-             BluetoothValue::TBluetoothGattServiceId);
-  MOZ_ASSERT(values[1].name().EqualsLiteral("includedServices"));
-  MOZ_ASSERT(values[1].value().type() ==
-             BluetoothValue::TArrayOfBluetoothGattServiceId);
-
-  size_t index = mServices.IndexOf(
-    values[0].value().get_BluetoothGattServiceId());
-  NS_ENSURE_TRUE_VOID(index != mServices.NoIndex);
-
-  RefPtr<BluetoothGattService> service = mServices.ElementAt(index);
-  service->AssignIncludedServices(
-    values[1].value().get_ArrayOfBluetoothGattServiceId());
-}
-
-void
-BluetoothGatt::HandleCharacteristicsDiscovered(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& values =
-    aValue.get_ArrayOfBluetoothNamedValue();
-  MOZ_ASSERT(values.Length() == 2); // ServiceId, Characteristics
-  MOZ_ASSERT(values[0].name().EqualsLiteral("serviceId"));
-  MOZ_ASSERT(values[0].value().type() ==
-             BluetoothValue::TBluetoothGattServiceId);
-  MOZ_ASSERT(values[1].name().EqualsLiteral("characteristics"));
-  MOZ_ASSERT(values[1].value().type() ==
-             BluetoothValue::TArrayOfBluetoothGattCharAttribute);
-
-  size_t index = mServices.IndexOf(
-    values[0].value().get_BluetoothGattServiceId());
-  NS_ENSURE_TRUE_VOID(index != mServices.NoIndex);
-
-  RefPtr<BluetoothGattService> service = mServices.ElementAt(index);
-  service->AssignCharacteristics(
-    values[1].value().get_ArrayOfBluetoothGattCharAttribute());
-}
-
-void
-BluetoothGatt::HandleDescriptorsDiscovered(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& values =
-    aValue.get_ArrayOfBluetoothNamedValue();
-  MOZ_ASSERT(values.Length() == 3); // ServiceId, CharacteristicId, Descriptors
-  MOZ_ASSERT(values[0].name().EqualsLiteral("serviceId"));
-  MOZ_ASSERT(values[0].value().type() ==
-             BluetoothValue::TBluetoothGattServiceId);
-  MOZ_ASSERT(values[1].name().EqualsLiteral("characteristicId"));
-  MOZ_ASSERT(values[1].value().type() == BluetoothValue::TBluetoothGattId);
-  MOZ_ASSERT(values[2].name().EqualsLiteral("descriptors"));
-  MOZ_ASSERT(values[2].value().type() ==
-             BluetoothValue::TArrayOfBluetoothGattId);
-
-  size_t index = mServices.IndexOf(
-    values[0].value().get_BluetoothGattServiceId());
-  NS_ENSURE_TRUE_VOID(index != mServices.NoIndex);
-
-  RefPtr<BluetoothGattService> service = mServices.ElementAt(index);
-  service->AssignDescriptors(values[1].value().get_BluetoothGattId(),
-                             values[2].value().get_ArrayOfBluetoothGattId());
-}
-
-void
-BluetoothGatt::HandleCharacteristicChanged(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  const InfallibleTArray<BluetoothNamedValue>& ids =
-    aValue.get_ArrayOfBluetoothNamedValue();
-  MOZ_ASSERT(ids.Length() == 2); // ServiceId, CharId
-  MOZ_ASSERT(ids[0].name().EqualsLiteral("serviceId"));
-  MOZ_ASSERT(ids[0].value().type() == BluetoothValue::TBluetoothGattServiceId);
-  MOZ_ASSERT(ids[1].name().EqualsLiteral("charId"));
-  MOZ_ASSERT(ids[1].value().type() == BluetoothValue::TBluetoothGattId);
-
-  size_t index = mServices.IndexOf(ids[0].value().get_BluetoothGattServiceId());
-  NS_ENSURE_TRUE_VOID(index != mServices.NoIndex);
-
-  RefPtr<BluetoothGattService> service = mServices.ElementAt(index);
-  nsTArray<RefPtr<BluetoothGattCharacteristic>> chars;
-  service->GetCharacteristics(chars);
-
-  index = chars.IndexOf(ids[1].value().get_BluetoothGattId());
-  NS_ENSURE_TRUE_VOID(index != chars.NoIndex);
-  RefPtr<BluetoothGattCharacteristic> characteristic = chars.ElementAt(index);
-
-  // Dispatch characteristicchanged event to application
-  BluetoothGattCharacteristicEventInit init;
-  init.mCharacteristic = characteristic;
-  RefPtr<BluetoothGattCharacteristicEvent> event =
-    BluetoothGattCharacteristicEvent::Constructor(
-      this,
-      NS_LITERAL_STRING(GATT_CHARACTERISTIC_CHANGED_ID),
-      init);
-
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothGatt::Notify(const BluetoothSignal& aData)
-{
-  BT_LOGD("[D] %s", NS_ConvertUTF16toUTF8(aData.name()).get());
-  NS_ENSURE_TRUE_VOID(mSignalRegistered);
-
-  BluetoothValue v = aData.value();
-  if (aData.name().EqualsLiteral("ClientRegistered")) {
-    MOZ_ASSERT(v.type() == BluetoothValue::Tuint32_t);
-    mClientIf = v.get_uint32_t();
-  } else if (aData.name().EqualsLiteral("ClientUnregistered")) {
-    mClientIf = 0;
-  } else if (aData.name().EqualsLiteral(GATT_CONNECTION_STATE_CHANGED_ID)) {
-    MOZ_ASSERT(v.type() == BluetoothValue::Tbool);
-
-    BluetoothConnectionState state =
-      v.get_bool() ? BluetoothConnectionState::Connected
-                   : BluetoothConnectionState::Disconnected;
-    UpdateConnectionState(state);
-  } else if (aData.name().EqualsLiteral("ServicesDiscovered")) {
-    HandleServicesDiscovered(v);
-  } else if (aData.name().EqualsLiteral("DiscoverCompleted")) {
-    MOZ_ASSERT(v.type() == BluetoothValue::Tbool);
-
-    bool isDiscoverSuccess = v.get_bool();
-    if (!isDiscoverSuccess) { // Clean all discovered attributes if failed
-      mServices.Clear();
-      BluetoothGattBinding::ClearCachedServicesValue(this);
-    }
-
-    mDiscoveringServices = false;
-  } else if (aData.name().EqualsLiteral("IncludedServicesDiscovered")) {
-    HandleIncludedServicesDiscovered(v);
-  } else if (aData.name().EqualsLiteral("CharacteristicsDiscovered")) {
-    HandleCharacteristicsDiscovered(v);
-  } else if (aData.name().EqualsLiteral("DescriptorsDiscovered")) {
-    HandleDescriptorsDiscovered(v);
-  } else if (aData.name().EqualsLiteral(GATT_CHARACTERISTIC_CHANGED_ID)) {
-    HandleCharacteristicChanged(v);
-  } else {
-    BT_WARNING("Not handling GATT signal: %s",
-               NS_ConvertUTF16toUTF8(aData.name()).get());
-  }
-}
-
-JSObject*
-BluetoothGatt::WrapObject(JSContext* aContext,
-                          JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothGattBinding::Wrap(aContext, this, aGivenProto);
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothGatt.h
+++ /dev/null
@@ -1,194 +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_BluetoothGatt_h
-#define mozilla_dom_bluetooth_BluetoothGatt_h
-
-#include "mozilla/Attributes.h"
-#include "mozilla/DOMEventTargetHelper.h"
-#include "mozilla/dom/BluetoothGattBinding.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/bluetooth/BluetoothGattService.h"
-#include "nsCOMPtr.h"
-
-namespace mozilla {
-namespace dom {
-class Promise;
-}
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothSignal;
-class BluetoothValue;
-
-class BluetoothGatt final : public DOMEventTargetHelper
-                          , public BluetoothSignalObserver
-{
-public:
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BluetoothGatt, DOMEventTargetHelper)
-
-  /****************************************************************************
-   * Attribute Getters
-   ***************************************************************************/
-  BluetoothConnectionState ConnectionState() const
-  {
-    return mConnectionState;
-  }
-
-  void GetServices(nsTArray<RefPtr<BluetoothGattService>>& aServices) const
-  {
-    aServices = mServices;
-  }
-
-  /****************************************************************************
-   * Event Handlers
-   ***************************************************************************/
-  IMPL_EVENT_HANDLER(characteristicchanged);
-  IMPL_EVENT_HANDLER(connectionstatechanged);
-
-  /****************************************************************************
-   * Methods (Web API Implementation)
-   ***************************************************************************/
-  already_AddRefed<Promise> Connect(ErrorResult& aRv);
-  already_AddRefed<Promise> Disconnect(ErrorResult& aRv);
-  already_AddRefed<Promise> DiscoverServices(ErrorResult& aRv);
-  already_AddRefed<Promise> ReadRemoteRssi(ErrorResult& aRv);
-
-  /****************************************************************************
-   * Others
-   ***************************************************************************/
-  void Notify(const BluetoothSignal& aParam); // BluetoothSignalObserver
-
-  nsPIDOMWindowInner* GetParentObject() const
-  {
-     return GetOwner();
-  }
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-  virtual void DisconnectFromOwner() override;
-
-  BluetoothGatt(nsPIDOMWindowInner* aOwner,
-                const nsAString& aDeviceAddr);
-
-private:
-  ~BluetoothGatt();
-
-  /**
-   * Update mConnectionState to aState and fire
-   * connectionstatechanged event to the application.
-   *
-   * @param aState [in] New connection state
-   */
-  void UpdateConnectionState(BluetoothConnectionState aState);
-
-  /**
-   * Add newly discovered GATT services into mServices and update the cache
-   * value of mServices.
-   *
-   * @param aValue [in] BluetoothValue which contains an array of
-   *                    BluetoothGattServiceId of all discovered services.
-   */
-  void HandleServicesDiscovered(const BluetoothValue& aValue);
-
-  /**
-   * Add newly discovered GATT included services into mIncludedServices of
-   * BluetoothGattService and update the cache value of mIncludedServices.
-   *
-   * @param aValue [in] BluetoothValue which contains an array of
-   *                    BluetoothNamedValue. There are exact two elements in
-   *                    the array. The first element uses 'serviceId' as the
-   *                    name and uses BluetoothGattServiceId as the value. The
-   *                    second element uses 'includedServices' as the name and
-   *                    uses an array of BluetoothGattServiceId of all
-   *                    discovered included services as the value.
-   */
-  void HandleIncludedServicesDiscovered(const BluetoothValue& aValue);
-
-  /**
-   * Add newly discovered GATT characteristics into mCharacteristics of
-   * BluetoothGattService and update the cache value of mCharacteristics.
-   *
-   * @param aValue [in] BluetoothValue which contains an array of
-   *                    BluetoothNamedValue. There are exact two elements in
-   *                    the array. The first element uses 'serviceId' as the
-   *                    name and uses BluetoothGattServiceId as the value. The
-   *                    second element uses 'characteristics' as the name and
-   *                    uses an array of BluetoothGattCharAttribute of all
-   *                    discovered characteristics as the value.
-   */
-  void HandleCharacteristicsDiscovered(const BluetoothValue& aValue);
-
-  /**
-   * Add newly discovered GATT descriptors into mDescriptors of
-   * BluetoothGattCharacteristic and update the cache value of mDescriptors.
-   *
-   * @param aValue [in] BluetoothValue which contains an array of
-   *                    BluetoothNamedValue. There are exact three elements in
-   *                    the array. The first element uses 'serviceId' as the
-   *                    name and uses BluetoothGattServiceId as the value. The
-   *                    second element uses 'characteristicId' as the name and
-   *                    uses BluetoothGattId as the value. The third element
-   *                    uses 'descriptors' as the name and uses an array of
-   *                    BluetoothGattId of all discovered descriptors as the
-   *                    value.
-   */
-  void HandleDescriptorsDiscovered(const BluetoothValue& aValue);
-
-  /**
-   * The value of a GATT characteristic has changed. In the mean time, the
-   * cached value of this GATT characteristic has already been updated. A
-   * 'characteristicchanged' event will be fired by this function.
-   *
-   * @param aValue [in] BluetoothValue which contains an array of
-   *                    BluetoothNamedValue. There are exact two elements in
-   *                    the array. The first element uses 'serviceId' as the
-   *                    name and uses BluetoothGattServiceId as the value. The
-   *                    second element uses 'charId' as the name and uses
-   *                    BluetoothGattId as the value.
-   */
-  void HandleCharacteristicChanged(const BluetoothValue& aValue);
-
-  /****************************************************************************
-   * Variables
-   ***************************************************************************/
-  /**
-   * Random generated UUID of this GATT client.
-   */
-  nsString mAppUuid;
-
-  /**
-   * Id of the GATT client interface given by bluetooth stack.
-   * 0 if the client is not registered yet, nonzero otherwise.
-   */
-  int mClientIf;
-
-  /**
-   * Connection state of this remote device.
-   */
-  BluetoothConnectionState mConnectionState;
-
-  /**
-   * Address of the remote device.
-   */
-  nsString mDeviceAddr;
-
-  /**
-   * Array of discovered services from the remote GATT server.
-   */
-  nsTArray<RefPtr<BluetoothGattService>> mServices;
-
-  /**
-   * Indicate whether there is ongoing discoverServices request or not.
-   */
-  bool mDiscoveringServices;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothGatt_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothGattAttributeEvent.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:set ts=2 sw=2 sts=2 et cindent: */
-/* 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 "mozilla/dom/bluetooth/BluetoothGattAttributeEvent.h"
-
-#include "js/GCAPI.h"
-#include "jsfriendapi.h"
-#include "mozilla/dom/BluetoothGattAttributeEventBinding.h"
-#include "mozilla/dom/bluetooth/BluetoothGattCharacteristic.h"
-#include "mozilla/dom/bluetooth/BluetoothGattDescriptor.h"
-#include "mozilla/dom/EventBinding.h"
-#include "mozilla/dom/Nullable.h"
-#include "mozilla/dom/PrimitiveConversions.h"
-#include "mozilla/dom/TypedArray.h"
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothGattAttributeEvent)
-
-NS_IMPL_ADDREF_INHERITED(BluetoothGattAttributeEvent, Event)
-NS_IMPL_RELEASE_INHERITED(BluetoothGattAttributeEvent, Event)
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothGattAttributeEvent,
-                                                  Event)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCharacteristic)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDescriptor)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(BluetoothGattAttributeEvent,
-                                               Event)
-  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mValue)
-NS_IMPL_CYCLE_COLLECTION_TRACE_END
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothGattAttributeEvent,
-                                                Event)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mCharacteristic)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mDescriptor)
-  tmp->mValue = nullptr;
-  mozilla::DropJSObjects(this);
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothGattAttributeEvent)
-NS_INTERFACE_MAP_END_INHERITING(Event)
-
-BluetoothGattAttributeEvent::BluetoothGattAttributeEvent(EventTarget* aOwner)
-  : Event(aOwner, nullptr, nullptr)
-{
-  mozilla::HoldJSObjects(this);
-}
-
-BluetoothGattAttributeEvent::~BluetoothGattAttributeEvent()
-{
-  mozilla::DropJSObjects(this);
-}
-
-JSObject*
-BluetoothGattAttributeEvent::WrapObjectInternal(
-  JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothGattAttributeEventBinding::Wrap(aCx, this, aGivenProto);
-}
-
-already_AddRefed<BluetoothGattAttributeEvent>
-BluetoothGattAttributeEvent::Constructor(
-  EventTarget* aOwner,
-  const nsAString& aType,
-  const nsAString& aAddress,
-  int32_t aRequestId,
-  BluetoothGattCharacteristic* aCharacteristic,
-  BluetoothGattDescriptor* aDescriptor,
-  const nsTArray<uint8_t>* aValue,
-  bool aNeedResponse,
-  bool aBubbles,
-  bool aCancelable)
-{
-  RefPtr<BluetoothGattAttributeEvent> e =
-    new BluetoothGattAttributeEvent(aOwner);
-  bool trusted = e->Init(aOwner);
-
-  e->InitEvent(aType, aBubbles, aCancelable);
-  e->mAddress = aAddress;
-  e->mRequestId = aRequestId;
-  e->mCharacteristic = aCharacteristic;
-  e->mDescriptor = aDescriptor;
-  e->mNeedResponse = aNeedResponse;
-
-  if (aValue) {
-    e->mRawValue = *aValue;
-  }
-
-  e->SetTrusted(trusted);
-
-  return e.forget();
-}
-
-already_AddRefed<BluetoothGattAttributeEvent>
-BluetoothGattAttributeEvent::Constructor(
-  const GlobalObject& aGlobal,
-  const nsAString& aType,
-  const BluetoothGattAttributeEventInit& aEventInitDict,
-  ErrorResult& aRv)
-{
-  nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports());
-
-  RefPtr<BluetoothGattAttributeEvent> e =
-    Constructor(owner, aType, aEventInitDict.mAddress,
-                aEventInitDict.mRequestId, aEventInitDict.mCharacteristic,
-                aEventInitDict.mDescriptor, nullptr,
-                aEventInitDict.mNeedResponse, aEventInitDict.mBubbles,
-                aEventInitDict.mCancelable);
-
-  if (!aEventInitDict.mValue.IsNull()) {
-    const auto& value = aEventInitDict.mValue.Value();
-    value.ComputeLengthAndData();
-    e->mValue = ArrayBuffer::Create(aGlobal.Context(),
-                                    value.Length(),
-                                    value.Data());
-
-    if (!e->mValue) {
-      aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
-      return nullptr;
-    }
-  }
-
-  return e.forget();
-}
-
-void
-BluetoothGattAttributeEvent::GetAddress(nsString& aRetVal) const
-{
-  aRetVal = mAddress;
-}
-
-int32_t
-BluetoothGattAttributeEvent::RequestId() const
-{
-  return mRequestId;
-}
-
-BluetoothGattCharacteristic*
-BluetoothGattAttributeEvent::GetCharacteristic() const
-{
-  return mCharacteristic;
-}
-
-BluetoothGattDescriptor*
-BluetoothGattAttributeEvent::GetDescriptor() const
-{
-  return mDescriptor;
-}
-
-void
-BluetoothGattAttributeEvent::GetValue(
-  JSContext* cx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv)
-{
-  if (!mValue) {
-    mValue = ArrayBuffer::Create(
-      cx, this, mRawValue.Length(), mRawValue.Elements());
-
-    if (!mValue) {
-      aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
-      return;
-    }
-
-    mRawValue.Clear();
-  }
-
-  aValue.set(mValue);
-
-  return;
-}
-
-bool
-BluetoothGattAttributeEvent::NeedResponse() const
-{
-  return mNeedResponse;
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothGattAttributeEvent.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:set ts=2 sw=2 sts=2 et cindent: */
-/* 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_BluetoothGattAttributeEvent_h
-#define mozilla_dom_bluetooth_BluetoothGattAttributeEvent_h
-
-#include "mozilla/Attributes.h"
-#include "mozilla/ErrorResult.h"
-#include "mozilla/dom/BindingUtils.h"
-#include "mozilla/dom/BluetoothGattAttributeEventBinding.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/Event.h"
-
-struct JSContext;
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothGattAttributeEvent final : public Event
-{
-public:
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(
-    BluetoothGattAttributeEvent, Event)
-protected:
-  virtual ~BluetoothGattAttributeEvent();
-  explicit BluetoothGattAttributeEvent(EventTarget* aOwner);
-
-  nsString mAddress;
-  int32_t mRequestId;
-  RefPtr<BluetoothGattCharacteristic> mCharacteristic;
-  RefPtr<BluetoothGattDescriptor> mDescriptor;
-  JS::Heap<JSObject*> mValue;
-  bool mNeedResponse;
-
-public:
-  virtual
-  JSObject* WrapObjectInternal(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-
-  static already_AddRefed<BluetoothGattAttributeEvent>
-  Constructor(EventTarget* aOwner,
-              const nsAString& aType,
-              const nsAString& aAddress,
-              int32_t aRequestId,
-              BluetoothGattCharacteristic* aCharacteristic,
-              BluetoothGattDescriptor* aDescriptor,
-              const nsTArray<uint8_t>* aValue,
-              bool aNeedResponse,
-              bool aBubbles,
-              bool aCancelable);
-
-  static already_AddRefed<BluetoothGattAttributeEvent>
-  Constructor(const GlobalObject& aGlobal,
-              const nsAString& aType,
-              const BluetoothGattAttributeEventInit& aEventInitDict,
-              ErrorResult& aRv);
-
-  void GetAddress(nsString& aRetVal) const;
-
-  int32_t RequestId() const;
-
-  BluetoothGattCharacteristic* GetCharacteristic() const;
-
-  BluetoothGattDescriptor* GetDescriptor() const;
-
-  void
-  GetValue(JSContext* cx,
-           JS::MutableHandle<JSObject*> aValue,
-           ErrorResult& aRv);
-
-  bool NeedResponse() const;
-
-private:
-  nsTArray<uint8_t> mRawValue;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_BluetoothGattAttributeEvent_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothGattCharacteristic.cpp
+++ /dev/null
@@ -1,473 +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 "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-#include "BluetoothUtils.h"
-#include "mozilla/dom/BluetoothGattCharacteristicBinding.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/bluetooth/BluetoothGattCharacteristic.h"
-#include "mozilla/dom/bluetooth/BluetoothGattService.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/dom/Promise.h"
-
-using namespace mozilla;
-using namespace mozilla::dom;
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothGattCharacteristic)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(BluetoothGattCharacteristic)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mService)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mDescriptors)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
-
-  /**
-   * Unregister the bluetooth signal handler after unlinked.
-   *
-   * This is needed to avoid ending up with exposing a deleted object to JS or
-   * accessing deleted objects while receiving signals from parent process
-   * after unlinked. Please see Bug 1138267 for detail informations.
-   */
-  nsString path;
-  GeneratePathFromGattId(tmp->mCharId, path);
-  UnregisterBluetoothSignalHandler(path, tmp);
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(BluetoothGattCharacteristic)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mService)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDescriptors)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(BluetoothGattCharacteristic)
-
-NS_IMPL_CYCLE_COLLECTING_ADDREF(BluetoothGattCharacteristic)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(BluetoothGattCharacteristic)
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BluetoothGattCharacteristic)
-  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
-
-/*
- * "A characteristic definition shall contain a characteristic declaration, a
- *  Characteristic Value declaration and may contain characteristic descriptor
- *  declarations."
- *  ...
- * "Each declaration above is contained in a separate Attribute. Two required
- *  declarations are the characteristic declaration and the Characteristic
- *  Value declaration."
- * -- Bluetooth Core Specification version 4.2, Volume 3, Part G, Section 3.3
- */
-const uint16_t BluetoothGattCharacteristic::sHandleCount = 2;
-
-// Constructor of BluetoothGattCharacteristic in ATT client role
-BluetoothGattCharacteristic::BluetoothGattCharacteristic(
-  nsPIDOMWindowInner* aOwner,
-  BluetoothGattService* aService,
-  const BluetoothGattCharAttribute& aChar)
-  : mOwner(aOwner)
-  , mService(aService)
-  , mCharId(aChar.mId)
-  , mPermissions(BLUETOOTH_EMPTY_GATT_ATTR_PERM)
-  , mProperties(aChar.mProperties)
-  , mWriteType(aChar.mWriteType)
-  , mAttRole(ATT_CLIENT_ROLE)
-  , mActive(true)
-{
-  MOZ_ASSERT(aOwner);
-  MOZ_ASSERT(mService);
-
-  UuidToString(mCharId.mUuid, mUuidStr);
-
-  // Generate bluetooth signal path of this characteristic to applications
-  nsString path;
-  GeneratePathFromGattId(mCharId, path);
-  RegisterBluetoothSignalHandler(path, this);
-}
-
-
-// Constructor of BluetoothGattCharacteristic in ATT server role
-BluetoothGattCharacteristic::BluetoothGattCharacteristic(
-  nsPIDOMWindowInner* aOwner,
-  BluetoothGattService* aService,
-  const nsAString& aCharacteristicUuid,
-  const GattPermissions& aPermissions,
-  const GattCharacteristicProperties& aProperties,
-  const ArrayBuffer& aValue)
-  : mOwner(aOwner)
-  , mService(aService)
-  , mUuidStr(aCharacteristicUuid)
-  , mPermissions(BLUETOOTH_EMPTY_GATT_ATTR_PERM)
-  , mProperties(BLUETOOTH_EMPTY_GATT_CHAR_PROP)
-  , mWriteType(GATT_WRITE_TYPE_NORMAL)
-  , mAttRole(ATT_SERVER_ROLE)
-  , mActive(false)
-{
-  MOZ_ASSERT(aOwner);
-  MOZ_ASSERT(aService);
-
-  // UUID
-  memset(&mCharId, 0, sizeof(mCharId));
-  StringToUuid(aCharacteristicUuid, mCharId.mUuid);
-
-  // permissions
-  GattPermissionsToBits(aPermissions, mPermissions);
-
-  // properties
-  GattPropertiesToBits(aProperties, mProperties);
-
-  // value
-  aValue.ComputeLengthAndData();
-  mValue.AppendElements(aValue.Data(), aValue.Length());
-}
-
-BluetoothGattCharacteristic::~BluetoothGattCharacteristic()
-{
-  nsString path;
-  GeneratePathFromGattId(mCharId, path);
-  UnregisterBluetoothSignalHandler(path, this);
-}
-
-already_AddRefed<Promise>
-BluetoothGattCharacteristic::StartNotifications(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(mAttRole == ATT_CLIENT_ROLE,
-                        promise,
-                        NS_ERROR_UNEXPECTED);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-  BT_ENSURE_TRUE_REJECT(mService, promise, NS_ERROR_NOT_AVAILABLE);
-
-  BluetoothUuid appUuid;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToUuid(mService->GetAppUuid(),
-                                                  appUuid)),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  bs->GattClientStartNotificationsInternal(
-    appUuid, mService->GetServiceId(), mCharId,
-    new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothGattCharacteristic::StopNotifications(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(mAttRole == ATT_CLIENT_ROLE,
-                        promise,
-                        NS_ERROR_UNEXPECTED);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-  BT_ENSURE_TRUE_REJECT(mService, promise, NS_ERROR_NOT_AVAILABLE);
-
-  BluetoothUuid appUuid;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToUuid(mService->GetAppUuid(),
-                                                  appUuid)),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  bs->GattClientStopNotificationsInternal(
-    appUuid, mService->GetServiceId(), mCharId,
-    new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-void
-BluetoothGattCharacteristic::AssignDescriptors(
-  const nsTArray<BluetoothGattId>& aDescriptorIds)
-{
-  mDescriptors.Clear();
-  for (uint32_t i = 0; i < aDescriptorIds.Length(); i++) {
-    mDescriptors.AppendElement(new BluetoothGattDescriptor(
-      GetParentObject(), this, aDescriptorIds[i]));
-  }
-
-  BluetoothGattCharacteristicBinding::ClearCachedDescriptorsValue(this);
-}
-
-void
-BluetoothGattCharacteristic::HandleCharacteristicValueUpdated(
-  const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfuint8_t);
-
-  mValue = aValue.get_ArrayOfuint8_t();
-}
-
-void
-BluetoothGattCharacteristic::AssignCharacteristicHandle(
-  const BluetoothAttributeHandle& aCharacteristicHandle)
-{
-  MOZ_ASSERT(mAttRole == ATT_SERVER_ROLE);
-  MOZ_ASSERT(!mActive);
-  MOZ_ASSERT(!mCharacteristicHandle.mHandle);
-
-  mCharacteristicHandle = aCharacteristicHandle;
-  mActive = true;
-}
-
-void
-BluetoothGattCharacteristic::AssignDescriptorHandle(
-  const BluetoothUuid& aDescriptorUuid,
-  const BluetoothAttributeHandle& aDescriptorHandle)
-{
-  MOZ_ASSERT(mAttRole == ATT_SERVER_ROLE);
-  MOZ_ASSERT(mActive);
-
-  size_t index = mDescriptors.IndexOf(aDescriptorUuid);
-  NS_ENSURE_TRUE_VOID(index != mDescriptors.NoIndex);
-  mDescriptors[index]->AssignDescriptorHandle(aDescriptorHandle);
-}
-
-void
-BluetoothGattCharacteristic::Notify(const BluetoothSignal& aData)
-{
-  BT_LOGD("[D] %s", NS_ConvertUTF16toUTF8(aData.name()).get());
-  NS_ENSURE_TRUE_VOID(mSignalRegistered);
-
-  BluetoothValue v = aData.value();
-  if (aData.name().EqualsLiteral("CharacteristicValueUpdated")) {
-    HandleCharacteristicValueUpdated(v);
-  } else {
-    BT_WARNING("Not handling GATT Characteristic signal: %s",
-               NS_ConvertUTF16toUTF8(aData.name()).get());
-  }
-}
-
-void
-BluetoothGattCharacteristic::GetUuid(BluetoothUuid& aUuid) const
-{
-  aUuid = mCharId.mUuid;
-}
-
-uint16_t
-BluetoothGattCharacteristic::GetHandleCount() const
-{
-  uint16_t count = sHandleCount;
-  for (size_t i = 0; i < mDescriptors.Length(); ++i) {
-    count += mDescriptors[i]->GetHandleCount();
-  }
-  return count;
-}
-
-JSObject*
-BluetoothGattCharacteristic::WrapObject(JSContext* aContext,
-                                        JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothGattCharacteristicBinding::Wrap(aContext, this, aGivenProto);
-}
-
-void
-BluetoothGattCharacteristic::GetValue(JSContext* cx,
-                                      JS::MutableHandle<JSObject*> aValue) const
-{
-  aValue.set(mValue.IsEmpty()
-             ? nullptr
-             : ArrayBuffer::Create(cx, mValue.Length(), mValue.Elements()));
-}
-
-void
-BluetoothGattCharacteristic::GetPermissions(
-  GattPermissions& aPermissions) const
-{
-  GattPermissionsToDictionary(mPermissions, aPermissions);
-}
-
-void
-BluetoothGattCharacteristic::GetProperties(
-  GattCharacteristicProperties& aProperties) const
-{
-  GattPropertiesToDictionary(mProperties, aProperties);
-}
-
-class ReadValueTask final : public BluetoothReplyRunnable
-{
-public:
-  ReadValueTask(BluetoothGattCharacteristic* aCharacteristic, Promise* aPromise)
-    : BluetoothReplyRunnable(nullptr, aPromise)
-    , mCharacteristic(aCharacteristic)
-  {
-    MOZ_ASSERT(aCharacteristic);
-    MOZ_ASSERT(aPromise);
-  }
-
-  bool
-  ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue)
-  {
-    aValue.setUndefined();
-
-    const BluetoothValue& v = mReply->get_BluetoothReplySuccess().value();
-    NS_ENSURE_TRUE(v.type() == BluetoothValue::TArrayOfuint8_t, false);
-
-    AutoJSAPI jsapi;
-    NS_ENSURE_TRUE(jsapi.Init(mCharacteristic->GetParentObject()), false);
-
-    JSContext* cx = jsapi.cx();
-    if (!ToJSValue(cx, v.get_ArrayOfuint8_t(), aValue)) {
-      jsapi.ClearException();
-      return false;
-    }
-
-    return true;
-  }
-
-  void
-  ReleaseMembers()
-  {
-    BluetoothReplyRunnable::ReleaseMembers();
-    mCharacteristic = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothGattCharacteristic> mCharacteristic;
-};
-
-already_AddRefed<Promise>
-BluetoothGattCharacteristic::ReadValue(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  if (mAttRole == ATT_SERVER_ROLE) {
-    promise->MaybeResolve(mValue);
-    return promise.forget();
-  }
-
-  BT_ENSURE_TRUE_REJECT(mProperties & GATT_CHAR_PROP_BIT_READ,
-                        promise,
-                        NS_ERROR_NOT_AVAILABLE);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  BluetoothUuid appUuid;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToUuid(mService->GetAppUuid(),
-                                                  appUuid)),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  bs->GattClientReadCharacteristicValueInternal(
-    appUuid, mService->GetServiceId(), mCharId,
-    new ReadValueTask(this, promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothGattCharacteristic::WriteValue(const ArrayBuffer& aValue,
-                                        ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  aValue.ComputeLengthAndData();
-
-  if (mAttRole == ATT_SERVER_ROLE) {
-    mValue.Clear();
-    mValue.AppendElements(aValue.Data(), aValue.Length());
-
-    promise->MaybeResolveWithUndefined();
-    return promise.forget();
-  }
-
-  BT_ENSURE_TRUE_REJECT(mProperties &
-                          (GATT_CHAR_PROP_BIT_WRITE_NO_RESPONSE |
-                           GATT_CHAR_PROP_BIT_WRITE |
-                           GATT_CHAR_PROP_BIT_SIGNED_WRITE),
-                        promise,
-                        NS_ERROR_NOT_AVAILABLE);
-
-  nsTArray<uint8_t> value;
-  value.AppendElements(aValue.Data(), aValue.Length());
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  BluetoothUuid appUuid;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToUuid(mService->GetAppUuid(),
-                                                  appUuid)),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  bs->GattClientWriteCharacteristicValueInternal(
-    appUuid, mService->GetServiceId(), mCharId, mWriteType, value,
-    new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothGattCharacteristic::AddDescriptor(const nsAString& aDescriptorUuid,
-                                           const GattPermissions& aPermissions,
-                                           const ArrayBuffer& aValue,
-                                           ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(mAttRole == ATT_SERVER_ROLE,
-                        promise,
-                        NS_ERROR_UNEXPECTED);
-
-  /* The characteristic should not be actively acting with the Bluetooth
-   * backend. Otherwise, descriptors cannot be added into the characteristic. */
-  BT_ENSURE_TRUE_REJECT(!mActive, promise, NS_ERROR_UNEXPECTED);
-
-  RefPtr<BluetoothGattDescriptor> descriptor =
-    new BluetoothGattDescriptor(GetParentObject(),
-                                this,
-                                aDescriptorUuid,
-                                aPermissions,
-                                aValue);
-
-  mDescriptors.AppendElement(descriptor);
-  promise->MaybeResolve(descriptor);
-
-  return promise.forget();
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothGattCharacteristic.h
+++ /dev/null
@@ -1,342 +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_BluetoothGattCharacteristic_h
-#define mozilla_dom_bluetooth_BluetoothGattCharacteristic_h
-
-#include "mozilla/Attributes.h"
-#include "mozilla/dom/BluetoothGattCharacteristicBinding.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/bluetooth/BluetoothGattDescriptor.h"
-#include "mozilla/dom/TypedArray.h"
-#include "nsCOMPtr.h"
-#include "nsWrapperCache.h"
-#include "nsPIDOMWindow.h"
-
-namespace mozilla {
-namespace dom {
-class Promise;
-}
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothGattService;
-class BluetoothSignal;
-class BluetoothValue;
-
-class BluetoothGattCharacteristic final : public nsISupports
-                                        , public nsWrapperCache
-                                        , public BluetoothSignalObserver
-{
-  friend class BluetoothGattServer;
-  friend class BluetoothGattService;
-public:
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(BluetoothGattCharacteristic)
-
-  /****************************************************************************
-   * Attribute Getters
-   ***************************************************************************/
-  BluetoothGattService* Service() const
-  {
-    return mService;
-  }
-
-  void GetDescriptors(
-    nsTArray<RefPtr<BluetoothGattDescriptor>>& aDescriptors) const
-  {
-    aDescriptors = mDescriptors;
-  }
-
-  void GetUuid(nsString& aUuidStr) const
-  {
-    aUuidStr = mUuidStr;
-  }
-
-  int InstanceId() const
-  {
-    return mCharId.mInstanceId;
-  }
-
-  void GetValue(JSContext* cx, JS::MutableHandle<JSObject*> aValue) const;
-
-  void GetPermissions(GattPermissions& aPermissions) const;
-
-  void GetProperties(GattCharacteristicProperties& aProperties) const;
-
-  /****************************************************************************
-   * Methods (Web API Implementation)
-   ***************************************************************************/
-  already_AddRefed<Promise> ReadValue(ErrorResult& aRv);
-  already_AddRefed<Promise> WriteValue(const ArrayBuffer& aValue,
-                                       ErrorResult& aRv);
-  already_AddRefed<Promise> StartNotifications(ErrorResult& aRv);
-  already_AddRefed<Promise> StopNotifications(ErrorResult& aRv);
-  already_AddRefed<Promise> AddDescriptor(const nsAString& aDescriptorUuid,
-                                          const GattPermissions& aPermissions,
-                                          const ArrayBuffer& aValue,
-                                          ErrorResult& aRv);
-
-  /****************************************************************************
-   * Others
-   ***************************************************************************/
-  const BluetoothGattId& GetCharacteristicId() const
-  {
-    return mCharId;
-  }
-
-  void Notify(const BluetoothSignal& aData); // BluetoothSignalObserver
-
-  const BluetoothAttributeHandle& GetCharacteristicHandle() const
-  {
-    return mCharacteristicHandle;
-  }
-
-  void GetUuid(BluetoothUuid& aUuid) const;
-
-  nsPIDOMWindowInner* GetParentObject() const
-  {
-     return mOwner;
-  }
-
-  BluetoothGattAttrPerm GetPermissions() const
-  {
-    return mPermissions;
-  }
-
-  BluetoothGattCharProp GetProperties() const
-  {
-    return mProperties;
-  }
-
-  uint16_t GetHandleCount() const;
-
-  const nsTArray<uint8_t>& GetValue() const
-  {
-    return mValue;
-  }
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-
-  // Constructor of BluetoothGattCharacteristic in ATT client role
-  BluetoothGattCharacteristic(nsPIDOMWindowInner* aOwner,
-                              BluetoothGattService* aService,
-                              const BluetoothGattCharAttribute& aChar);
-
-  // Constructor of BluetoothGattCharacteristic in ATT server role
-  BluetoothGattCharacteristic(nsPIDOMWindowInner* aOwner,
-                              BluetoothGattService* aService,
-                              const nsAString& aCharacteristicUuid,
-                              const GattPermissions& aPermissions,
-                              const GattCharacteristicProperties& aProperties,
-                              const ArrayBuffer& aValue);
-
-private:
-  ~BluetoothGattCharacteristic();
-
-  /**
-   * Add newly discovered GATT descriptors into mDescriptors and update the
-   * cache value of mDescriptors.
-   *
-   * @param aDescriptorIds [in] An array of BluetoothGattId for each descriptor
-   *                            that belongs to this characteristic.
-   */
-  void AssignDescriptors(const nsTArray<BluetoothGattId>& aDescriptorIds);
-
-  /**
-   * Update the value of this characteristic.
-   *
-   * @param aValue [in] BluetoothValue which contains an uint8_t array.
-   */
-  void HandleCharacteristicValueUpdated(const BluetoothValue& aValue);
-
-  /**
-   * Assign the handle value for this GATT characteristic. This function would
-   * be called only after a valid handle value is retrieved from the Bluetooth
-   * backend.
-   *
-   * @param aCharacteristicHandle [in] The handle value of this GATT
-   *                                   characteristic.
-   */
-  void AssignCharacteristicHandle(
-    const BluetoothAttributeHandle& aCharacteristicHandle);
-
-  /**
-   * Assign the handle value for one of the descriptor within this GATT
-   * characteristic. This function would be called only after a valid handle
-   * value is retrieved from the Bluetooth backend.
-   *
-   * @param aDescriptorUuid [in] BluetoothUuid of the target GATT descriptor.
-   * @param aDescriptorHandle [in] The handle value of the target GATT
-   *                               descriptor.
-   */
-  void AssignDescriptorHandle(
-    const BluetoothUuid& aDescriptorUuid,
-    const BluetoothAttributeHandle& aDescriptorHandle);
-
-  /**
-   * Examine whether this GATT characteristic can react with the Bluetooth
-   * backend.
-   *
-   * @return true if this characteristic can react with the Bluetooth backend;
-   *         false if this characteristic cannot react with the Bluetooth
-   *         backend.
-   */
-  bool IsActivated() const
-  {
-    return mActive;
-  }
-
-  /****************************************************************************
-   * Variables
-   ***************************************************************************/
-  nsCOMPtr<nsPIDOMWindowInner> mOwner;
-
-  /**
-   * Service that this characteristic belongs to.
-   */
-  RefPtr<BluetoothGattService> mService;
-
-  /**
-   * Array of discovered descriptors for this characteristic.
-   */
-  nsTArray<RefPtr<BluetoothGattDescriptor>> mDescriptors;
-
-  /**
-   * GattId of this GATT characteristic which contains
-   * 1) mUuid: UUID of this characteristic in byte array format.
-   * 2) mInstanceId: Instance id of this characteristic.
-   */
-  BluetoothGattId mCharId;
-
-  /**
-   * UUID string of this GATT characteristic.
-   */
-  nsString mUuidStr;
-
-  /**
-   * Value of this GATT characteristic.
-   */
-  nsTArray<uint8_t> mValue;
-
-  /**
-   * Permissions of this GATT characteristic.
-   */
-  BluetoothGattAttrPerm mPermissions;
-
-  /**
-   * Properties of this GATT characteristic.
-   */
-  BluetoothGattCharProp mProperties;
-
-  /**
-   * Write type of this GATT characteristic.
-   */
-  BluetoothGattWriteType mWriteType;
-
-  /**
-   * ATT role of this GATT characteristic.
-   */
-  const BluetoothAttRole mAttRole;
-
-  /**
-   * Activeness of this GATT characteristic.
-   *
-   * True means this service does react with the Bluetooth backend. False means
-   * this characteristic doesn't react with the Bluetooth backend. The value
-   * should be true if |mAttRole| equals |ATT_CLIENT_ROLE| because the
-   * characteristic instance could be created only when the Bluetooth backend
-   * has found one GATT characteristic. The value would be false at the
-   * beginning if |mAttRole| equals |ATT_SERVER_ROLE|. Then the value would
-   * become true later if the corresponding GATT service has been added into
-   * Bluetooth backend.
-   */
-  bool mActive;
-
-  /**
-   * Handle of this GATT characteristic.
-   *
-   * The value is only valid if |mAttRole| equals |ATT_SERVER_ROLE|.
-   */
-  BluetoothAttributeHandle mCharacteristicHandle;
-
-  /**
-   * Total count of handles of this GATT characteristic itself.
-   */
-  static const uint16_t sHandleCount;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-/**
- * Explicit Specialization of Function Templates
- *
- * Allows customizing the template code for a given set of template arguments.
- * With this function template, nsTArray can handle comparison between
- * 'RefPtr<BluetoothGattCharacteristic>' and 'BluetoothGattId' properly,
- * including IndexOf() and Contains();
- */
-template <>
-class nsDefaultComparator <
-  RefPtr<mozilla::dom::bluetooth::BluetoothGattCharacteristic>,
-  mozilla::dom::bluetooth::BluetoothGattId> {
-public:
-  bool Equals(
-    const RefPtr<mozilla::dom::bluetooth::BluetoothGattCharacteristic>& aChar,
-    const mozilla::dom::bluetooth::BluetoothGattId& aCharId) const
-  {
-    return aChar->GetCharacteristicId() == aCharId;
-  }
-};
-
-/**
- * Explicit Specialization of Function Templates
- *
- * Allows customizing the template code for a given set of template arguments.
- * With this function template, nsTArray can handle comparison between
- * 'RefPtr<BluetoothGattCharacteristic>' and 'BluetoothUuid' properly,
- * including IndexOf() and Contains();
- */
-template <>
-class nsDefaultComparator <
-  RefPtr<mozilla::dom::bluetooth::BluetoothGattCharacteristic>,
-  mozilla::dom::bluetooth::BluetoothUuid> {
-public:
-  bool Equals(
-    const RefPtr<mozilla::dom::bluetooth::BluetoothGattCharacteristic>& aChar,
-    const mozilla::dom::bluetooth::BluetoothUuid& aUuid) const
-  {
-    mozilla::dom::bluetooth::BluetoothUuid uuid;
-    aChar->GetUuid(uuid);
-    return uuid == aUuid;
-  }
-};
-
-/**
- * Explicit Specialization of Function Templates
- *
- * Allows customizing the template code for a given set of template arguments.
- * With this function template, nsTArray can handle comparison between
- * 'RefPtr<BluetoothGattCharacteristic>' and 'BluetoothAttributeHandle'
- * properly, including IndexOf() and Contains();
- */
-template <>
-class nsDefaultComparator <
-  RefPtr<mozilla::dom::bluetooth::BluetoothGattCharacteristic>,
-  mozilla::dom::bluetooth::BluetoothAttributeHandle> {
-public:
-  bool Equals(
-    const RefPtr<mozilla::dom::bluetooth::BluetoothGattCharacteristic>& aChar,
-    const mozilla::dom::bluetooth::BluetoothAttributeHandle& aCharacteristicHandle)
-    const
-  {
-    return aChar->GetCharacteristicHandle() == aCharacteristicHandle;
-  }
-};
-
-#endif // mozilla_dom_bluetooth_BluetoothGattCharacteristic_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothGattDescriptor.cpp
+++ /dev/null
@@ -1,303 +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 "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-#include "BluetoothUtils.h"
-#include "mozilla/dom/BluetoothGattCharacteristicBinding.h"
-#include "mozilla/dom/BluetoothGattDescriptorBinding.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/bluetooth/BluetoothGattCharacteristic.h"
-#include "mozilla/dom/bluetooth/BluetoothGattDescriptor.h"
-#include "mozilla/dom/bluetooth/BluetoothGattService.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-
-using namespace mozilla;
-using namespace mozilla::dom;
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothGattDescriptor)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(BluetoothGattDescriptor)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mCharacteristic)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
-
-  /**
-   * Unregister the bluetooth signal handler after unlinked.
-   *
-   * This is needed to avoid ending up with exposing a deleted object to JS or
-   * accessing deleted objects while receiving signals from parent process
-   * after unlinked. Please see Bug 1138267 for detail informations.
-   */
-  nsString path;
-  GeneratePathFromGattId(tmp->mDescriptorId, path);
-  UnregisterBluetoothSignalHandler(path, tmp);
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(BluetoothGattDescriptor)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCharacteristic)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(BluetoothGattDescriptor)
-
-NS_IMPL_CYCLE_COLLECTING_ADDREF(BluetoothGattDescriptor)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(BluetoothGattDescriptor)
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BluetoothGattDescriptor)
-  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
-
-const uint16_t BluetoothGattDescriptor::sHandleCount = 1;
-
-// Constructor of BluetoothGattDescriptor in ATT client role
-BluetoothGattDescriptor::BluetoothGattDescriptor(
-  nsPIDOMWindowInner* aOwner,
-  BluetoothGattCharacteristic* aCharacteristic,
-  const BluetoothGattId& aDescriptorId)
-  : mOwner(aOwner)
-  , mCharacteristic(aCharacteristic)
-  , mDescriptorId(aDescriptorId)
-  , mPermissions(BLUETOOTH_EMPTY_GATT_ATTR_PERM)
-  , mAttRole(ATT_CLIENT_ROLE)
-  , mActive(true)
-{
-  MOZ_ASSERT(aOwner);
-  MOZ_ASSERT(aCharacteristic);
-
-  UuidToString(mDescriptorId.mUuid, mUuidStr);
-
-  // Generate bluetooth signal path of this descriptor to applications
-  nsString path;
-  GeneratePathFromGattId(mDescriptorId, path);
-  RegisterBluetoothSignalHandler(path, this);
-}
-
-// Constructor of BluetoothGattDescriptor in ATT server role
-BluetoothGattDescriptor::BluetoothGattDescriptor(
-  nsPIDOMWindowInner* aOwner,
-  BluetoothGattCharacteristic* aCharacteristic,
-  const nsAString& aDescriptorUuid,
-  const GattPermissions& aPermissions,
-  const ArrayBuffer& aValue)
-  : mOwner(aOwner)
-  , mCharacteristic(aCharacteristic)
-  , mUuidStr(aDescriptorUuid)
-  , mPermissions(BLUETOOTH_EMPTY_GATT_ATTR_PERM)
-  , mAttRole(ATT_SERVER_ROLE)
-  , mActive(false)
-{
-  MOZ_ASSERT(aOwner);
-  MOZ_ASSERT(aCharacteristic);
-
-  // UUID
-  memset(&mDescriptorId, 0, sizeof(mDescriptorId));
-  StringToUuid(aDescriptorUuid, mDescriptorId.mUuid);
-
-  // permissions
-  GattPermissionsToBits(aPermissions, mPermissions);
-
-  // value
-  aValue.ComputeLengthAndData();
-  mValue.AppendElements(aValue.Data(), aValue.Length());
-}
-
-BluetoothGattDescriptor::~BluetoothGattDescriptor()
-{
-  nsString path;
-  GeneratePathFromGattId(mDescriptorId, path);
-  UnregisterBluetoothSignalHandler(path, this);
-}
-
-void
-BluetoothGattDescriptor::HandleDescriptorValueUpdated(
-  const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfuint8_t);
-
-  mValue = aValue.get_ArrayOfuint8_t();
-}
-
-void
-BluetoothGattDescriptor::AssignDescriptorHandle(
-  const BluetoothAttributeHandle& aDescriptorHandle)
-{
-  MOZ_ASSERT(mAttRole == ATT_SERVER_ROLE);
-  MOZ_ASSERT(!mActive);
-  MOZ_ASSERT(!mDescriptorHandle.mHandle);
-
-  mDescriptorHandle = aDescriptorHandle;
-  mActive = true;
-}
-
-void
-BluetoothGattDescriptor::Notify(const BluetoothSignal& aData)
-{
-  BT_LOGD("[D] %s", NS_ConvertUTF16toUTF8(aData.name()).get());
-  NS_ENSURE_TRUE_VOID(mSignalRegistered);
-
-  BluetoothValue v = aData.value();
-  if (aData.name().EqualsLiteral("DescriptorValueUpdated")) {
-    HandleDescriptorValueUpdated(v);
-  } else {
-    BT_WARNING("Not handling GATT Descriptor signal: %s",
-               NS_ConvertUTF16toUTF8(aData.name()).get());
-  }
-}
-
-void
-BluetoothGattDescriptor::GetUuid(BluetoothUuid& aUuid) const
-{
-  aUuid = mDescriptorId.mUuid;
-}
-
-JSObject*
-BluetoothGattDescriptor::WrapObject(JSContext* aContext,
-                                    JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothGattDescriptorBinding::Wrap(aContext, this, aGivenProto);
-}
-
-void
-BluetoothGattDescriptor::GetValue(JSContext* cx,
-                                  JS::MutableHandle<JSObject*> aValue) const
-{
-  aValue.set(mValue.IsEmpty()
-             ? nullptr
-             : ArrayBuffer::Create(cx, mValue.Length(), mValue.Elements()));
-}
-
-void
-BluetoothGattDescriptor::GetPermissions(GattPermissions& aPermissions) const
-{
-  GattPermissionsToDictionary(mPermissions, aPermissions);
-}
-
-class ReadValueTask final : public BluetoothReplyRunnable
-{
-public:
-  ReadValueTask(BluetoothGattDescriptor* aDescriptor, Promise* aPromise)
-    : BluetoothReplyRunnable(nullptr, aPromise)
-    , mDescriptor(aDescriptor)
-  {
-    MOZ_ASSERT(aDescriptor);
-    MOZ_ASSERT(aPromise);
-  }
-
-  bool
-  ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue)
-  {
-    aValue.setUndefined();
-
-    const BluetoothValue& v = mReply->get_BluetoothReplySuccess().value();
-    NS_ENSURE_TRUE(v.type() == BluetoothValue::TArrayOfuint8_t, false);
-
-    AutoJSAPI jsapi;
-    NS_ENSURE_TRUE(jsapi.Init(mDescriptor->GetParentObject()), false);
-
-    JSContext* cx = jsapi.cx();
-    if (!ToJSValue(cx, v.get_ArrayOfuint8_t(), aValue)) {
-      jsapi.ClearException();
-      return false;
-    }
-
-    return true;
-  }
-
-  void
-  ReleaseMembers()
-  {
-    BluetoothReplyRunnable::ReleaseMembers();
-    mDescriptor = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothGattDescriptor> mDescriptor;
-};
-
-already_AddRefed<Promise>
-BluetoothGattDescriptor::ReadValue(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BluetoothUuid appUuid;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToUuid(
-                        mCharacteristic->Service()->GetAppUuid(), appUuid)),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  if (mAttRole == ATT_SERVER_ROLE) {
-    promise->MaybeResolve(mValue);
-    return promise.forget();
-  }
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  bs->GattClientReadDescriptorValueInternal(
-    appUuid,
-    mCharacteristic->Service()->GetServiceId(),
-    mCharacteristic->GetCharacteristicId(),
-    mDescriptorId,
-    new ReadValueTask(this, promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothGattDescriptor::WriteValue(
-  const RootedTypedArray<ArrayBuffer>& aValue, ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BluetoothUuid appUuid;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToUuid(
-                        mCharacteristic->Service()->GetAppUuid(), appUuid)),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  aValue.ComputeLengthAndData();
-
-  if (mAttRole == ATT_SERVER_ROLE) {
-    mValue.Clear();
-    mValue.AppendElements(aValue.Data(), aValue.Length());
-
-    promise->MaybeResolveWithUndefined();
-    return promise.forget();
-  }
-
-  nsTArray<uint8_t> value;
-  value.AppendElements(aValue.Data(), aValue.Length());
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  bs->GattClientWriteDescriptorValueInternal(
-    appUuid,
-    mCharacteristic->Service()->GetServiceId(),
-    mCharacteristic->GetCharacteristicId(),
-    mDescriptorId,
-    value,
-    new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothGattDescriptor.h
+++ /dev/null
@@ -1,258 +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_BluetoothGattDescriptor_h
-#define mozilla_dom_bluetooth_BluetoothGattDescriptor_h
-
-#include "mozilla/Attributes.h"
-#include "mozilla/dom/BluetoothGattDescriptorBinding.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/Promise.h"
-#include "mozilla/dom/TypedArray.h"
-#include "nsCOMPtr.h"
-#include "nsWrapperCache.h"
-#include "nsPIDOMWindow.h"
-
-namespace mozilla {
-namespace dom {
-struct GattPermissions;
-}
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothGattCharacteristic;
-class BluetoothSignal;
-class BluetoothValue;
-
-class BluetoothGattDescriptor final : public nsISupports
-                                    , public nsWrapperCache
-                                    , public BluetoothSignalObserver
-{
-  friend class BluetoothGattServer;
-  friend class BluetoothGattCharacteristic;
-public:
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(BluetoothGattDescriptor)
-
-  /****************************************************************************
-   * Attribute Getters
-   ***************************************************************************/
-  BluetoothGattCharacteristic* Characteristic() const
-  {
-    return mCharacteristic;
-  }
-
-  void GetUuid(nsString& aUuidStr) const
-  {
-    aUuidStr = mUuidStr;
-  }
-
-  void GetValue(JSContext* cx, JS::MutableHandle<JSObject*> aValue) const;
-
-  void GetPermissions(GattPermissions& aPermissions) const;
-
-  /****************************************************************************
-   * Methods (Web API Implementation)
-   ***************************************************************************/
-  already_AddRefed<Promise> ReadValue(ErrorResult& aRv);
-  already_AddRefed<Promise> WriteValue(
-    const RootedTypedArray<ArrayBuffer>& aValue, ErrorResult& aRv);
-
-  /****************************************************************************
-   * Others
-   ***************************************************************************/
-  void Notify(const BluetoothSignal& aData); // BluetoothSignalObserver
-
-  const BluetoothAttributeHandle& GetDescriptorHandle() const
-  {
-    return mDescriptorHandle;
-  }
-
-  nsPIDOMWindowInner* GetParentObject() const
-  {
-     return mOwner;
-  }
-
-  void GetUuid(BluetoothUuid& aUuid) const;
-
-  BluetoothGattAttrPerm GetPermissions() const
-  {
-    return mPermissions;
-  }
-
-  uint16_t GetHandleCount() const
-  {
-    return sHandleCount;
-  }
-
-  const nsTArray<uint8_t>& GetValue() const
-  {
-    return mValue;
-  }
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-
-  // Constructor of BluetoothGattDescriptor in ATT client role
-  BluetoothGattDescriptor(nsPIDOMWindowInner* aOwner,
-                          BluetoothGattCharacteristic* aCharacteristic,
-                          const BluetoothGattId& aDescriptorId);
-
-  // Constructor of BluetoothGattDescriptor in ATT server role
-  BluetoothGattDescriptor(nsPIDOMWindowInner* aOwner,
-                          BluetoothGattCharacteristic* aCharacteristic,
-                          const nsAString& aDescriptorUuid,
-                          const GattPermissions& aPermissions,
-                          const ArrayBuffer& aValue);
-
-private:
-  ~BluetoothGattDescriptor();
-
-  /**
-   * Update the value of this descriptor.
-   *
-   * @param aValue [in] BluetoothValue which contains an uint8_t array.
-   */
-  void HandleDescriptorValueUpdated(const BluetoothValue& aValue);
-
-  /**
-   * Assign AppUuid of this GATT descriptor.
-   *
-   * @param aAppUuid The value of AppUuid.
-   */
-  void AssignAppUuid(const nsAString& aAppUuid);
-
-  /**
-   * Assign the handle value for this GATT descriptor. This function would be
-   * called only after a valid handle value is retrieved from the Bluetooth
-   * backend.
-   *
-   * @param aDescriptorHandle [in] The handle value of this GATT descriptor.
-   */
-  void AssignDescriptorHandle(const BluetoothAttributeHandle& aDescriptorHandle);
-
-  /**
-   * Examine whether this GATT descriptor can react with the Bluetooth backend.
-   *
-   * @return true if this descriptor can react with the Bluetooth backend;
-   *         false if this descriptor cannot react with the Bluetooth backend.
-   */
-  bool IsActivated() const
-  {
-    return mActive;
-  }
-
-  /****************************************************************************
-   * Variables
-   ***************************************************************************/
-  nsCOMPtr<nsPIDOMWindowInner> mOwner;
-
-  /**
-   * Characteristic that this descriptor belongs to.
-   */
-  RefPtr<BluetoothGattCharacteristic> mCharacteristic;
-
-  /**
-   * GattId of this GATT descriptor which contains
-   * 1) mUuid: UUID of this descriptor in byte array format.
-   * 2) mInstanceId: Instance id of this descriptor.
-   */
-  BluetoothGattId mDescriptorId;
-
-  /**
-   * UUID string of this GATT descriptor.
-   */
-  nsString mUuidStr;
-
-  /**
-   * Value of this GATT descriptor.
-   */
-  nsTArray<uint8_t> mValue;
-
-  /**
-   * Permissions of this GATT descriptor.
-   */
-  BluetoothGattAttrPerm mPermissions;
-
-  /**
-   * ATT role of this GATT descriptor.
-   */
-  const BluetoothAttRole mAttRole;
-
-  /**
-   * Activeness of this GATT descriptor.
-   *
-   * True means this service does react with the Bluetooth backend. False means
-   * this descriptor doesn't react with the Bluetooth backend. The value should
-   * be true if |mAttRole| equals |ATT_CLIENT_ROLE| because the descriptor
-   * instance could be created only when the Bluetooth backend has found one
-   * GATT descriptor. The value would be false at the beginning if |mAttRole|
-   * equals |ATT_SERVER_ROLE|. Then the value would become true later if the
-   * corresponding GATT service has been added into Bluetooth backend.
-   */
-  bool mActive;
-
-  /**
-   * Handle of this GATT descriptor.
-   *
-   * The value is only valid if |mAttRole| equals |ATT_SERVER_ROLE|.
-   */
-  BluetoothAttributeHandle mDescriptorHandle;
-
-  /**
-   * Total count of handles of this GATT descriptor itself.
-   */
-  static const uint16_t sHandleCount;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-/**
- * Explicit Specialization of Function Templates
- *
- * Allows customizing the template code for a given set of template arguments.
- * With this function template, nsTArray can handle comparison between
- * 'RefPtr<BluetoothGattDescriptor>' and 'BluetoothUuid' properly,
- * including IndexOf() and Contains();
- */
-template <>
-class nsDefaultComparator <
-  RefPtr<mozilla::dom::bluetooth::BluetoothGattDescriptor>,
-  mozilla::dom::bluetooth::BluetoothUuid> {
-public:
-  bool Equals(
-    const RefPtr<mozilla::dom::bluetooth::BluetoothGattDescriptor>& aDesc,
-    const mozilla::dom::bluetooth::BluetoothUuid& aUuid) const
-  {
-    mozilla::dom::bluetooth::BluetoothUuid uuid;
-    aDesc->GetUuid(uuid);
-    return uuid == aUuid;
-  }
-};
-
-/**
- * Explicit Specialization of Function Templates
- *
- * Allows customizing the template code for a given set of template arguments.
- * With this function template, nsTArray can handle comparison between
- * 'RefPtr<BluetoothGattDescriptor>' and 'BluetoothAttributeHandle'
- * properly, including IndexOf() and Contains();
- */
-template <>
-class nsDefaultComparator <
-  RefPtr<mozilla::dom::bluetooth::BluetoothGattDescriptor>,
-  mozilla::dom::bluetooth::BluetoothAttributeHandle> {
-public:
-  bool Equals(
-    const RefPtr<mozilla::dom::bluetooth::BluetoothGattDescriptor>& aDesc,
-    const mozilla::dom::bluetooth::BluetoothAttributeHandle& aHandle) const
-  {
-    return aDesc->GetDescriptorHandle() == aHandle;
-  }
-};
-
-#endif // mozilla_dom_bluetooth_BluetoothGattDescriptor_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothGattServer.cpp
+++ /dev/null
@@ -1,1142 +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 "BluetoothGattServer.h"
-
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-#include "BluetoothUtils.h"
-#include "mozilla/dom/BluetoothStatusChangedEvent.h"
-#include "mozilla/dom/bluetooth/BluetoothGattAttributeEvent.h"
-#include "mozilla/dom/bluetooth/BluetoothGattCharacteristic.h"
-#include "mozilla/dom/bluetooth/BluetoothGattService.h"
-#include "mozilla/dom/Promise.h"
-
-using namespace mozilla;
-using namespace mozilla::dom;
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothGattServer)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothGattServer,
-                                                DOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mServices)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mPendingService)
-
-  /**
-   * Unregister the bluetooth signal handler after unlinked.
-   *
-   * This is needed to avoid ending up with exposing a deleted object to JS or
-   * accessing deleted objects while receiving signals from parent process
-   * after unlinked. Please see Bug 1138267 for detail informations.
-   */
-  UnregisterBluetoothSignalHandler(tmp->mAppUuid, tmp);
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothGattServer,
-                                                  DOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mServices)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPendingService)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothGattServer)
-NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
-
-NS_IMPL_ADDREF_INHERITED(BluetoothGattServer, DOMEventTargetHelper)
-NS_IMPL_RELEASE_INHERITED(BluetoothGattServer, DOMEventTargetHelper)
-
-BluetoothGattServer::BluetoothGattServer(nsPIDOMWindowInner* aOwner)
-  : mOwner(aOwner)
-  , mServerIf(0)
-  , mValid(true)
-{
-  if (NS_SUCCEEDED(GenerateUuid(mAppUuid)) && !mAppUuid.IsEmpty()) {
-    RegisterBluetoothSignalHandler(mAppUuid, this);
-  }
-  if (!mSignalRegistered) {
-    Invalidate();
-  }
-}
-
-BluetoothGattServer::~BluetoothGattServer()
-{
-  Invalidate();
-}
-
-void BluetoothGattServer::HandleServerRegistered(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::Tuint32_t);
-  mServerIf = aValue.get_uint32_t();
-}
-
-void BluetoothGattServer::HandleServerUnregistered(const BluetoothValue& aValue)
-{
-  mServerIf = 0;
-}
-
-void BluetoothGattServer::HandleConnectionStateChanged(
-  const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() == 2 &&
-             arr[0].value().type() == BluetoothValue::Tbool &&
-             arr[1].value().type() == BluetoothValue::TBluetoothAddress);
-
-  BluetoothStatusChangedEventInit init;
-  init.mStatus = arr[0].value().get_bool();
-  AddressToString(arr[1].value().get_BluetoothAddress(), init.mAddress);
-
-  RefPtr<BluetoothStatusChangedEvent> event =
-    BluetoothStatusChangedEvent::Constructor(
-      this, NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID), init);
-
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothGattServer::HandleServiceHandleUpdated(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() == 2 &&
-    arr[0].value().type() == BluetoothValue::TBluetoothGattServiceId &&
-    arr[1].value().type() == BluetoothValue::TBluetoothAttributeHandle);
-
-  BluetoothGattServiceId serviceId =
-    arr[0].value().get_BluetoothGattServiceId();
-  BluetoothAttributeHandle serviceHandle =
-    arr[1].value().get_BluetoothAttributeHandle();
-
-  NS_ENSURE_TRUE_VOID(mPendingService);
-  NS_ENSURE_TRUE_VOID(mPendingService->GetServiceId() == serviceId);
-  mPendingService->AssignServiceHandle(serviceHandle);
-}
-
-void
-BluetoothGattServer::HandleCharacteristicHandleUpdated(
-  const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() == 3 &&
-    arr[0].value().type() == BluetoothValue::TBluetoothUuid &&
-    arr[1].value().type() == BluetoothValue::TBluetoothAttributeHandle &&
-    arr[2].value().type() == BluetoothValue::TBluetoothAttributeHandle);
-
-  BluetoothUuid characteristicUuid =
-    arr[0].value().get_BluetoothUuid();
-  BluetoothAttributeHandle serviceHandle =
-    arr[1].value().get_BluetoothAttributeHandle();
-  BluetoothAttributeHandle characteristicHandle =
-    arr[2].value().get_BluetoothAttributeHandle();
-
-  NS_ENSURE_TRUE_VOID(mPendingService);
-  NS_ENSURE_TRUE_VOID(mPendingService->GetServiceHandle() == serviceHandle);
-  mPendingService->AssignCharacteristicHandle(characteristicUuid,
-                                              characteristicHandle);
-}
-
-void
-BluetoothGattServer::HandleDescriptorHandleUpdated(
-  const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() == 4 &&
-    arr[0].value().type() == BluetoothValue::TBluetoothUuid &&
-    arr[1].value().type() == BluetoothValue::TBluetoothAttributeHandle &&
-    arr[2].value().type() == BluetoothValue::TBluetoothAttributeHandle &&
-    arr[3].value().type() == BluetoothValue::TBluetoothAttributeHandle);
-
-  BluetoothUuid descriptorUuid =
-    arr[0].value().get_BluetoothUuid();
-  BluetoothAttributeHandle serviceHandle =
-    arr[1].value().get_BluetoothAttributeHandle();
-  BluetoothAttributeHandle characteristicHandle =
-    arr[2].value().get_BluetoothAttributeHandle();
-  BluetoothAttributeHandle descriptorHandle =
-    arr[3].value().get_BluetoothAttributeHandle();
-
-  NS_ENSURE_TRUE_VOID(mPendingService);
-  NS_ENSURE_TRUE_VOID(mPendingService->GetServiceHandle() == serviceHandle);
-  mPendingService->AssignDescriptorHandle(descriptorUuid,
-                                          characteristicHandle,
-                                          descriptorHandle);
-}
-
-void
-BluetoothGattServer::HandleReadWriteRequest(const BluetoothValue& aValue,
-                                            const nsAString& aEventName)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-  const InfallibleTArray<BluetoothNamedValue>& arr =
-    aValue.get_ArrayOfBluetoothNamedValue();
-
-  MOZ_ASSERT(arr.Length() == 5 &&
-    arr[0].value().type() == BluetoothValue::Tint32_t &&
-    arr[1].value().type() == BluetoothValue::TBluetoothAttributeHandle &&
-    arr[2].value().type() == BluetoothValue::TBluetoothAddress &&
-    arr[3].value().type() == BluetoothValue::Tbool &&
-    arr[4].value().type() == BluetoothValue::TArrayOfuint8_t);
-
-  int32_t requestId = arr[0].value().get_int32_t();
-  BluetoothAttributeHandle handle =
-    arr[1].value().get_BluetoothAttributeHandle();
-  nsString address;
-  AddressToString(arr[2].value().get_BluetoothAddress(), address);
-  bool needResponse = arr[3].value().get_bool();
-  nsTArray<uint8_t> value;
-  value = arr[4].value().get_ArrayOfuint8_t();
-
-  // Find the target characteristic or descriptor from the given handle
-  RefPtr<BluetoothGattCharacteristic> characteristic = nullptr;
-  RefPtr<BluetoothGattDescriptor> descriptor = nullptr;
-  for (uint32_t i = 0; i < mServices.Length(); i++) {
-    for (uint32_t j = 0; j < mServices[i]->mCharacteristics.Length(); j++) {
-      RefPtr<BluetoothGattCharacteristic> currentChar =
-        mServices[i]->mCharacteristics[j];
-
-      if (handle == currentChar->GetCharacteristicHandle()) {
-        characteristic = currentChar;
-        break;
-      }
-
-      size_t index = currentChar->mDescriptors.IndexOf(handle);
-      if (index != currentChar->mDescriptors.NoIndex) {
-        descriptor = currentChar->mDescriptors[index];
-        break;
-      }
-    }
-  }
-
-  if (!(characteristic || descriptor)) {
-    BT_WARNING("Wrong handle: no matched characteristic or descriptor");
-    return;
-  }
-
-  // Save the request information for sending the response later
-  RequestData data(handle,
-                   characteristic,
-                   descriptor);
-  mRequestMap.Put(requestId, &data);
-
-  RefPtr<BluetoothGattAttributeEvent> event =
-    BluetoothGattAttributeEvent::Constructor(
-      this, aEventName, address, requestId, characteristic, descriptor,
-      &value, needResponse, false /* Bubble */, false /* Cancelable*/);
-
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothGattServer::Notify(const BluetoothSignal& aData)
-{
-  BT_LOGD("[GattServer] %s", NS_ConvertUTF16toUTF8(aData.name()).get());
-  NS_ENSURE_TRUE_VOID(mSignalRegistered);
-
-  BluetoothValue v = aData.value();
-  if (aData.name().EqualsLiteral("ServerRegistered")) {
-    HandleServerRegistered(v);
-  } else if (aData.name().EqualsLiteral("ServerUnregistered")) {
-    HandleServerUnregistered(v);
-  } else if (aData.name().EqualsLiteral(GATT_CONNECTION_STATE_CHANGED_ID)) {
-    HandleConnectionStateChanged(v);
-  } else if (aData.name().EqualsLiteral("ServiceHandleUpdated")) {
-    HandleServiceHandleUpdated(v);
-  } else if (aData.name().EqualsLiteral("CharacteristicHandleUpdated")) {
-    HandleCharacteristicHandleUpdated(v);
-  } else if (aData.name().EqualsLiteral("DescriptorHandleUpdated")) {
-    HandleDescriptorHandleUpdated(v);
-  } else if (aData.name().EqualsLiteral("ReadRequested")) {
-    HandleReadWriteRequest(v, NS_LITERAL_STRING(ATTRIBUTE_READ_REQUEST));
-  } else if (aData.name().EqualsLiteral("WriteRequested")) {
-    HandleReadWriteRequest(v, NS_LITERAL_STRING(ATTRIBUTE_WRITE_REQUEST));
-  } else {
-    BT_WARNING("Not handling GATT signal: %s",
-               NS_ConvertUTF16toUTF8(aData.name()).get());
-  }
-}
-
-JSObject*
-BluetoothGattServer::WrapObject(JSContext* aContext,
-                                JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothGattServerBinding::Wrap(aContext, this, aGivenProto);
-}
-
-void
-BluetoothGattServer::DisconnectFromOwner()
-{
-  DOMEventTargetHelper::DisconnectFromOwner();
-  Invalidate();
-}
-
-void
-BluetoothGattServer::Invalidate()
-{
-  mValid = false;
-  mPendingService = nullptr;
-  mServices.Clear();
-  mRequestMap.Clear();
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  if (mServerIf > 0) {
-    bs->UnregisterGattServerInternal(mServerIf,
-                                     new BluetoothVoidReplyRunnable(nullptr,
-                                                                    nullptr));
-  }
-
-  if (!mAppUuid.IsEmpty() && mSignalRegistered) {
-    UnregisterBluetoothSignalHandler(mAppUuid, this);
-  }
-}
-
-already_AddRefed<Promise>
-BluetoothGattServer::Connect(const nsAString& aAddress, ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BluetoothUuid appUuid;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToUuid(mAppUuid, appUuid)),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  BluetoothAddress address;
-  BT_ENSURE_TRUE_REJECT(
-    NS_SUCCEEDED(StringToAddress(aAddress, address)),
-    promise,
-    NS_ERROR_INVALID_ARG);
-
-  BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  bs->GattServerConnectPeripheralInternal(
-    appUuid, address, new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothGattServer::Disconnect(const nsAString& aAddress, ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BluetoothUuid appUuid;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToUuid(mAppUuid, appUuid)),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  BluetoothAddress address;
-  BT_ENSURE_TRUE_REJECT(
-    NS_SUCCEEDED(StringToAddress(aAddress, address)),
-    promise,
-    NS_ERROR_INVALID_ARG);
-
-  BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  bs->GattServerDisconnectPeripheralInternal(
-    appUuid, address, new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-class BluetoothGattServer::StartAdvertisingTask final
-  : public BluetoothVoidReplyRunnable
-{
-public:
-  StartAdvertisingTask(BluetoothGattServer* aServer, Promise* aPromise)
-    : BluetoothVoidReplyRunnable(nullptr, aPromise)
-    , mServer(aServer)
-  {
-    MOZ_ASSERT(aServer);
-    MOZ_ASSERT(aPromise);
-  }
-
-  virtual void
-  ReleaseMembers() override
-  {
-    BluetoothReplyRunnable::ReleaseMembers();
-    mServer = nullptr;
-  }
-
-protected:
-  virtual void OnErrorFired() override
-  {
-    mServer->mAdvertisingAppUuid.Clear();
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-};
-
-class BluetoothGattServer::RegisterServerAndStartAdvertisingTask final
-  : public BluetoothVoidReplyRunnable
-{
-public:
-  RegisterServerAndStartAdvertisingTask(
-    BluetoothGattServer* aServer,
-    const BluetoothGattAdvertisingData& aAdvData,
-    Promise* aPromise)
-    : BluetoothVoidReplyRunnable(nullptr, nullptr)
-      /**
-       * aPromise is not managed by BluetoothVoidReplyRunnable. It would be
-       * passed to |StartAdvertisingTask| after this one executes successfully.
-       */
-    , mServer(aServer)
-    , mAdvData(aAdvData)
-    , mPromise(aPromise)
-  {
-    MOZ_ASSERT(mServer);
-    MOZ_ASSERT(mPromise);
-  }
-
-  void ReleaseMembers() override
-  {
-    BluetoothReplyRunnable::ReleaseMembers();
-    mServer = nullptr;
-    mPromise = nullptr;
-  }
-
-private:
-  virtual void OnSuccessFired() override
-  {
-    BluetoothService* bs = BluetoothService::Get();
-    if (NS_WARN_IF(!bs)) {
-      mPromise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
-    }
-
-    if (NS_WARN_IF(mServer->mAdvertisingAppUuid.IsCleared())) {
-      mPromise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
-    }
-
-    bs->StartAdvertisingInternal(
-      mServer->mAdvertisingAppUuid, mAdvData,
-      new StartAdvertisingTask(mServer, mPromise));
-  }
-
-  virtual void OnErrorFired() override
-  {
-    mServer->mAdvertisingAppUuid.Clear();
-    mPromise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
-  }
-
-  RefPtr<BluetoothGattServer> mServer;
-  BluetoothGattAdvertisingData mAdvData;
-  RefPtr<Promise> mPromise;
-};
-
-already_AddRefed<Promise>
-BluetoothGattServer::StartAdvertising(const BluetoothAdvertisingData& aAdvData,
-                                      ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
-
-  BT_ENSURE_TRUE_REJECT(mAdvertisingAppUuid.IsCleared(),
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-
-  nsresult rv = GenerateUuid(mAdvertisingAppUuid);
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(rv) && !mAdvertisingAppUuid.IsCleared(),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  BluetoothGattAdvertisingData data;
-  rv = AdvertisingDataToGattAdvertisingData(aAdvData, data);
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(rv), promise, rv);
-
-  BluetoothUuid appUuid;
-  rv = StringToUuid(mAppUuid, appUuid);
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(rv), promise, rv);
-
-  bs->GattServerRegisterInternal(
-    appUuid,
-    new RegisterServerAndStartAdvertisingTask(this, data, promise));
-
-  return promise.forget();
-}
-
-class BluetoothGattServer::StopAdvertisingTask final
-  : public BluetoothVoidReplyRunnable
-{
-public:
-  StopAdvertisingTask(BluetoothGattServer* aServer, Promise* aPromise)
-    : BluetoothVoidReplyRunnable(nullptr, aPromise)
-    , mServer(aServer)
-  {
-    MOZ_ASSERT(aPromise);
-    MOZ_ASSERT(aServer);
-  }
-
-  virtual void
-  ReleaseMembers() override
-  {
-    BluetoothReplyRunnable::ReleaseMembers();
-    mServer = nullptr;
-  }
-
-protected:
-  virtual void OnSuccessFired() override
-  {
-    mServer->mAdvertisingAppUuid.Clear();
-  }
-
-  virtual void OnErrorFired() override
-  {
-    mServer->mAdvertisingAppUuid.Clear();
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-};
-
-already_AddRefed<Promise>
-BluetoothGattServer::StopAdvertising(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
-
-  if (mAdvertisingAppUuid.IsCleared()) {
-    promise->MaybeResolveWithUndefined();
-    return promise.forget();
-  }
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  bs->StopAdvertisingInternal(mAdvertisingAppUuid,
-                              new StopAdvertisingTask(this, promise));
-
-  return promise.forget();
-}
-
-class BluetoothGattServer::AddIncludedServiceTask final
-  : public BluetoothReplyTaskQueue::SubTask
-{
-public:
-  AddIncludedServiceTask(BluetoothReplyTaskQueue* aRootQueue,
-                         BluetoothGattServer* aServer,
-                         BluetoothGattService* aService,
-                         BluetoothGattService* aIncludedService)
-    : BluetoothReplyTaskQueue::SubTask(aRootQueue, nullptr)
-    , mServer(aServer)
-    , mService(aService)
-    , mIncludedService(aIncludedService)
-  { }
-
-  bool Execute() override
-  {
-    BluetoothService* bs = BluetoothService::Get();
-    if (NS_WARN_IF(!bs)) {
-      return false;
-    }
-
-    BluetoothUuid appUuid;
-    if (NS_FAILED(StringToUuid(mServer->mAppUuid, appUuid))) {
-      return false;
-    }
-
-    bs->GattServerAddIncludedServiceInternal(
-      appUuid,
-      mService->GetServiceHandle(),
-      mIncludedService->GetServiceHandle(),
-      GetReply());
-
-    return true;
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-  RefPtr<BluetoothGattService> mService;
-  RefPtr<BluetoothGattService> mIncludedService;
-};
-
-class BluetoothGattServer::AddCharacteristicTask final
-  : public BluetoothReplyTaskQueue::SubTask
-{
-public:
-  AddCharacteristicTask(BluetoothReplyTaskQueue* aRootQueue,
-                        BluetoothGattServer* aServer,
-                        BluetoothGattService* aService,
-                        BluetoothGattCharacteristic* aCharacteristic)
-    : BluetoothReplyTaskQueue::SubTask(aRootQueue, nullptr)
-    , mServer(aServer)
-    , mService(aService)
-    , mCharacteristic(aCharacteristic)
-  { }
-
-  bool Execute() override
-  {
-    BluetoothService* bs = BluetoothService::Get();
-    if (NS_WARN_IF(!bs)) {
-      return false;
-    }
-
-    BluetoothUuid appUuid;
-    if (NS_FAILED(StringToUuid(mServer->mAppUuid, appUuid))) {
-      return false;
-    }
-
-    BluetoothUuid uuid;
-    mCharacteristic->GetUuid(uuid);
-    bs->GattServerAddCharacteristicInternal(
-      appUuid,
-      mService->GetServiceHandle(),
-      uuid,
-      mCharacteristic->GetPermissions(),
-      mCharacteristic->GetProperties(),
-      GetReply());
-
-    return true;
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-  RefPtr<BluetoothGattService> mService;
-  RefPtr<BluetoothGattCharacteristic> mCharacteristic;
-};
-
-class BluetoothGattServer::AddDescriptorTask final
-  : public BluetoothReplyTaskQueue::SubTask
-{
-public:
-  AddDescriptorTask(BluetoothReplyTaskQueue* aRootQueue,
-                    BluetoothGattServer* aServer,
-                    BluetoothGattService* aService,
-                    BluetoothGattCharacteristic* aCharacteristic,
-                    BluetoothGattDescriptor* aDescriptor)
-    : BluetoothReplyTaskQueue::SubTask(aRootQueue, nullptr)
-    , mServer(aServer)
-    , mService(aService)
-    , mCharacteristic(aCharacteristic)
-    , mDescriptor(aDescriptor)
-  { }
-
-  bool Execute() override
-  {
-    BluetoothService* bs = BluetoothService::Get();
-    if (NS_WARN_IF(!bs)) {
-      return false;
-    }
-
-    BluetoothUuid appUuid;
-    if (NS_FAILED(StringToUuid(mServer->mAppUuid, appUuid))) {
-      return false;
-    }
-
-    BluetoothUuid uuid;
-    mDescriptor->GetUuid(uuid);
-    bs->GattServerAddDescriptorInternal(
-      appUuid,
-      mService->GetServiceHandle(),
-      mCharacteristic->GetCharacteristicHandle(),
-      uuid,
-      mDescriptor->GetPermissions(),
-      GetReply());
-
-    return true;
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-  RefPtr<BluetoothGattService> mService;
-  RefPtr<BluetoothGattCharacteristic> mCharacteristic;
-  RefPtr<BluetoothGattDescriptor> mDescriptor;
-};
-
-class BluetoothGattServer::StartServiceTask final
-  : public BluetoothReplyTaskQueue::SubTask
-{
-public:
-  StartServiceTask(BluetoothReplyTaskQueue* aRootQueue,
-                   BluetoothGattServer* aServer,
-                   BluetoothGattService* aService)
-    : BluetoothReplyTaskQueue::SubTask(aRootQueue, nullptr)
-    , mServer(aServer)
-    , mService(aService)
-  { }
-
-  bool Execute() override
-  {
-    BluetoothService* bs = BluetoothService::Get();
-    if (NS_WARN_IF(!bs)) {
-      return false;
-    }
-
-    BluetoothUuid appUuid;
-    if (NS_FAILED(StringToUuid(mServer->mAppUuid, appUuid))) {
-      return false;
-    }
-
-    bs->GattServerStartServiceInternal(
-      appUuid,
-      mService->GetServiceHandle(),
-      GetReply());
-
-    return true;
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-  RefPtr<BluetoothGattService> mService;
-};
-
-/*
- * CancelAddServiceTask is used when failing to completely add a service. No
- * matter CancelAddServiceTask executes successfully or not, the promose should
- * be rejected because we fail to adding the service eventually.
- */
-class BluetoothGattServer::CancelAddServiceTask final
-  : public BluetoothVoidReplyRunnable
-{
-public:
-  CancelAddServiceTask(BluetoothGattServer* aServer,
-                       BluetoothGattService* aService,
-                       Promise* aPromise)
-    : BluetoothVoidReplyRunnable(nullptr, nullptr)
-      /* aPromise is not managed by BluetoothVoidReplyRunnable. It would be
-       * rejected after this task has been executed anyway. */
-    , mServer(aServer)
-    , mService(aService)
-    , mPromise(aPromise)
-  {
-    MOZ_ASSERT(mPromise);
-  }
-
-  void ReleaseMembers() override
-  {
-    BluetoothVoidReplyRunnable::ReleaseMembers();
-    mServer = nullptr;
-    mService = nullptr;
-    mPromise = nullptr;
-  }
-
-private:
-  void OnSuccessFired() override
-  {
-    mServer->mPendingService = nullptr;
-    mPromise->MaybeReject(NS_ERROR_FAILURE);
-  }
-
-  void OnErrorFired() override
-  {
-    mServer->mPendingService = nullptr;
-    mPromise->MaybeReject(NS_ERROR_FAILURE);
-  }
-
-  RefPtr<BluetoothGattServer> mServer;
-  RefPtr<BluetoothGattService> mService;
-  RefPtr<Promise> mPromise;
-};
-
-class BluetoothGattServer::AddServiceTaskQueue final
-  : public BluetoothReplyTaskQueue
-{
-public:
-  AddServiceTaskQueue(BluetoothGattServer* aServer,
-                      BluetoothGattService* aService,
-                      Promise* aPromise)
-    : BluetoothReplyTaskQueue(nullptr)
-    , mServer(aServer)
-    , mService(aService)
-    , mPromise(aPromise)
-  {
-    /* add included services */
-    nsTArray<RefPtr<BluetoothGattService>> includedServices;
-    mService->GetIncludedServices(includedServices);
-    for (size_t i = 0; i < includedServices.Length(); ++i) {
-      RefPtr<SubTask> includedServiceTask =
-        new AddIncludedServiceTask(this, mServer, mService, includedServices[i]);
-      AppendTask(includedServiceTask.forget());
-    }
-
-    /* add characteristics */
-    nsTArray<RefPtr<BluetoothGattCharacteristic>> characteristics;
-    mService->GetCharacteristics(characteristics);
-    for (size_t i = 0; i < characteristics.Length(); ++i) {
-      RefPtr<SubTask> characteristicTask =
-        new AddCharacteristicTask(this, mServer, mService, characteristics[i]);
-      AppendTask(characteristicTask.forget());
-
-      /* add descriptors */
-      nsTArray<RefPtr<BluetoothGattDescriptor>> descriptors;
-      characteristics[i]->GetDescriptors(descriptors);
-      for (size_t j = 0; j < descriptors.Length(); ++j) {
-        RefPtr<SubTask> descriptorTask =
-          new AddDescriptorTask(this,
-                                mServer,
-                                mService,
-                                characteristics[i],
-                                descriptors[j]);
-
-        AppendTask(descriptorTask.forget());
-      }
-    }
-
-    /* start service */
-    RefPtr<SubTask> startTask = new StartServiceTask(this, mServer, mService);
-    AppendTask(startTask.forget());
-  }
-
-protected:
-  virtual ~AddServiceTaskQueue()
-  { }
-
-private:
-  void OnSuccessFired() override
-  {
-    mServer->mPendingService = nullptr;
-    mServer->mServices.AppendElement(mService);
-    mPromise->MaybeResolveWithUndefined();
-  }
-
-  void OnErrorFired() override
-  {
-    BluetoothService* bs = BluetoothService::Get();
-    BT_ENSURE_TRUE_REJECT_VOID(bs, mPromise, NS_ERROR_NOT_AVAILABLE);
-
-    BluetoothUuid appUuid;
-    BT_ENSURE_TRUE_REJECT_VOID(NS_SUCCEEDED(StringToUuid(mServer->mAppUuid,
-                                                         appUuid)),
-                               mPromise,
-                               NS_ERROR_DOM_OPERATION_ERR);
-
-    bs->GattServerRemoveServiceInternal(
-      appUuid,
-      mService->GetServiceHandle(),
-      new CancelAddServiceTask(mServer, mService, mPromise));
-  }
-
-  RefPtr<BluetoothGattServer> mServer;
-  RefPtr<BluetoothGattService> mService;
-  RefPtr<Promise> mPromise;
-};
-
-class BluetoothGattServer::AddServiceTask final
-  : public BluetoothVoidReplyRunnable
-{
-public:
-  AddServiceTask(BluetoothGattServer* aServer,
-                 BluetoothGattService* aService,
-                 Promise* aPromise)
-    : BluetoothVoidReplyRunnable(nullptr, nullptr)
-      /* aPromise is not managed by BluetoothVoidReplyRunnable. It would be
-       * passed to other tasks after this task executes successfully. */
-    , mServer(aServer)
-    , mService(aService)
-    , mPromise(aPromise)
-  {
-    MOZ_ASSERT(mServer);
-    MOZ_ASSERT(mService);
-    MOZ_ASSERT(mPromise);
-  }
-
-  void ReleaseMembers() override
-  {
-    BluetoothReplyRunnable::ReleaseMembers();
-    mServer = nullptr;
-    mService = nullptr;
-    mPromise = nullptr;
-  }
-
-private:
-  virtual void OnSuccessFired() override
-  {
-    mService->AssignAppUuid(mServer->mAppUuid);
-
-    RefPtr<Runnable> runnable = new AddServiceTaskQueue(mServer,
-                                                          mService,
-                                                          mPromise);
-    nsresult rv = NS_DispatchToMainThread(runnable.forget());
-
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      mServer->mPendingService = nullptr;
-      mPromise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
-    }
-  }
-
-  virtual void OnErrorFired() override
-  {
-    mServer->mPendingService = nullptr;
-    mPromise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
-  }
-
-  RefPtr<BluetoothGattServer> mServer;
-  RefPtr<BluetoothGattService> mService;
-  RefPtr<Promise> mPromise;
-};
-
-already_AddRefed<Promise>
-BluetoothGattServer::AddService(BluetoothGattService& aService,
-                                ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
-  BT_ENSURE_TRUE_REJECT(!aService.IsActivated(),
-                        promise,
-                        NS_ERROR_INVALID_ARG);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  mPendingService = &aService;
-
-  BluetoothUuid appUuid;
-  if (NS_FAILED(StringToUuid(mAppUuid, appUuid))) {
-    return false;
-  }
-
-  bs->GattServerAddServiceInternal(appUuid,
-                                   mPendingService->GetServiceId(),
-                                   mPendingService->GetHandleCount(),
-                                   new AddServiceTask(this,
-                                                      mPendingService,
-                                                      promise));
-
-  return promise.forget();
-}
-
-class BluetoothGattServer::RemoveServiceTask final
-  : public BluetoothReplyRunnable
-{
-public:
-  RemoveServiceTask(BluetoothGattServer* aServer,
-                    BluetoothGattService* aService,
-                    Promise* aPromise)
-    : BluetoothReplyRunnable(nullptr, aPromise)
-    , mServer(aServer)
-    , mService(aService)
-  {
-    MOZ_ASSERT(mServer);
-    MOZ_ASSERT(mService);
-  }
-
-  void ReleaseMembers() override
-  {
-    BluetoothReplyRunnable::ReleaseMembers();
-    mServer = nullptr;
-    mService = nullptr;
-  }
-
-protected:
-  bool ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue) override
-  {
-    aValue.setUndefined();
-
-    mServer->mServices.RemoveElement(mService);
-
-    return true;
-  }
-
-private:
-  RefPtr<BluetoothGattServer> mServer;
-  RefPtr<BluetoothGattService> mService;
-};
-
-already_AddRefed<Promise>
-BluetoothGattServer::RemoveService(BluetoothGattService& aService,
-                                   ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
-  BT_ENSURE_TRUE_REJECT(mServices.Contains(&aService),
-                        promise,
-                        NS_ERROR_INVALID_ARG);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  BluetoothUuid appUuid;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToUuid(mAppUuid, appUuid)),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  bs->GattServerRemoveServiceInternal(
-    appUuid, aService.GetServiceHandle(), new RemoveServiceTask(this,
-                                                                 &aService,
-                                                                 promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothGattServer::NotifyCharacteristicChanged(
-  const nsAString& aAddress,
-  BluetoothGattCharacteristic& aCharacteristic,
-  bool aConfirm,
-  ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
-
-  BluetoothUuid appUuid;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToUuid(mAppUuid, appUuid)),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  BluetoothAddress address;
-  BT_ENSURE_TRUE_REJECT(
-    NS_SUCCEEDED(StringToAddress(aAddress, address)),
-    promise,
-    NS_ERROR_INVALID_ARG);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  RefPtr<BluetoothGattService> service = aCharacteristic.Service();
-  BT_ENSURE_TRUE_REJECT(service, promise, NS_ERROR_NOT_AVAILABLE);
-  BT_ENSURE_TRUE_REJECT(mServices.Contains(service),
-                        promise,
-                        NS_ERROR_NOT_AVAILABLE);
-
-  bs->GattServerSendIndicationInternal(
-    appUuid, address, aCharacteristic.GetCharacteristicHandle(), aConfirm,
-    aCharacteristic.GetValue(),
-    new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothGattServer::SendResponse(const nsAString& aAddress,
-                                  uint16_t aStatus,
-                                  int32_t aRequestId,
-                                  ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BluetoothUuid appUuid;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToUuid(mAppUuid, appUuid)),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  BluetoothAddress address;
-  BT_ENSURE_TRUE_REJECT(
-    NS_SUCCEEDED(StringToAddress(aAddress, address)),
-    promise,
-    NS_ERROR_INVALID_ARG);
-
-  BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
-
-  RequestData* requestData;
-  mRequestMap.Get(aRequestId, &requestData);
-  BT_ENSURE_TRUE_REJECT(requestData, promise, NS_ERROR_UNEXPECTED);
-
-  BluetoothGattResponse response;
-  memset(&response, 0, sizeof(response));
-  response.mHandle = requestData->mHandle;
-
-  if (requestData->mCharacteristic) {
-    const nsTArray<uint8_t>& value = requestData->mCharacteristic->GetValue();
-    response.mLength = value.Length();
-    memcpy(&response.mValue, value.Elements(), response.mLength);
-  } else if (requestData->mDescriptor) {
-    const nsTArray<uint8_t>& value = requestData->mDescriptor->GetValue();
-    response.mLength = value.Length();
-    memcpy(&response.mValue, value.Elements(), response.mLength);
-  } else {
-    MOZ_ASSERT_UNREACHABLE(
-      "There should be at least one characteristic or descriptor in the "
-      "request data.");
-
-    promise->MaybeReject(NS_ERROR_INVALID_ARG);
-    return promise.forget();
-  }
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  bs->GattServerSendResponseInternal(
-    appUuid,
-    address,
-    aStatus,
-    aRequestId,
-    response,
-    new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothGattServer.h
+++ /dev/null
@@ -1,196 +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_BluetoothGattServer_h
-#define mozilla_dom_bluetooth_BluetoothGattServer_h
-
-#include "mozilla/DOMEventTargetHelper.h"
-#include "mozilla/dom/BluetoothGattServerBinding.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/bluetooth/BluetoothGattService.h"
-#include "mozilla/dom/Promise.h"
-#include "nsClassHashtable.h"
-#include "nsCOMPtr.h"
-#include "nsPIDOMWindow.h"
-
-namespace mozilla {
-namespace dom {
-class Promise;
-struct BluetoothAdvertisingData;
-}
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothSignal;
-
-class BluetoothGattServer final : public DOMEventTargetHelper
-                                , public BluetoothSignalObserver
-{
-public:
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BluetoothGattServer,
-                                           DOMEventTargetHelper)
-
-  /****************************************************************************
-   * Attribute Getters
-   ***************************************************************************/
-  void GetServices(
-    nsTArray<RefPtr<BluetoothGattService>>& aServices) const
-  {
-    aServices = mServices;
-  }
-
-  /****************************************************************************
-   * Event Handlers
-   ***************************************************************************/
-  IMPL_EVENT_HANDLER(connectionstatechanged);
-  IMPL_EVENT_HANDLER(attributereadreq);
-  IMPL_EVENT_HANDLER(attributewritereq);
-
-  /****************************************************************************
-   * Methods (Web API Implementation)
-   ***************************************************************************/
-  already_AddRefed<Promise> Connect(
-    const nsAString& aAddress, ErrorResult& aRv);
-  already_AddRefed<Promise> Disconnect(
-    const nsAString& aAddress, ErrorResult& aRv);
-
-  already_AddRefed<Promise> StartAdvertising(
-    const BluetoothAdvertisingData& aAdvData, ErrorResult& aRv);
-  already_AddRefed<Promise> StopAdvertising(ErrorResult& aRv);
-
-  already_AddRefed<Promise> AddService(BluetoothGattService& aService,
-                                       ErrorResult& aRv);
-  already_AddRefed<Promise> RemoveService(BluetoothGattService& aService,
-                                          ErrorResult& aRv);
-
-  already_AddRefed<Promise> NotifyCharacteristicChanged(
-    const nsAString& aAddress,
-    BluetoothGattCharacteristic& aCharacteristic,
-    bool aConfirm,
-    ErrorResult& aRv);
-
-  already_AddRefed<Promise> SendResponse(const nsAString& aAddress,
-                                         uint16_t aStatus,
-                                         int32_t aRequestId,
-                                         ErrorResult& aRv);
-
-  /****************************************************************************
-   * Others
-   ***************************************************************************/
-  void Notify(const BluetoothSignal& aData); // BluetoothSignalObserver
-
-  nsPIDOMWindowInner* GetParentObject() const
-  {
-     return mOwner;
-  }
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-
-  virtual void DisconnectFromOwner() override;
-  BluetoothGattServer(nsPIDOMWindowInner* aOwner);
-
-  /* Invalidate the GATT server.
-   * If the BluetoothAdapter turns off, existing BluetoothGattServer instances
-   * should stop working till the end of life.
-   */
-  void Invalidate();
-
-private:
-  ~BluetoothGattServer();
-
-  class StartAdvertisingTask;
-  class RegisterServerAndStartAdvertisingTask;
-  class StopAdvertisingTask;
-  class AddIncludedServiceTask;
-  class AddCharacteristicTask;
-  class AddDescriptorTask;
-  class StartServiceTask;
-  class CancelAddServiceTask;
-  class AddServiceTaskQueue;
-  class AddServiceTask;
-  class RemoveServiceTask;
-
-  friend class StartAdvertisingTask;
-  friend class RegisterServerAndStartAdvertisingTask;
-  friend class StopAdvertisingTask;
-  friend class AddIncludedServiceTask;
-  friend class AddCharacteristicTask;
-  friend class AddDescriptorTask;
-  friend class StartServiceTask;
-  friend class CancelAddServiceTask;
-  friend class AddServiceTaskQueue;
-  friend class AddServiceTask;
-  friend class RemoveServiceTask;
-
-  struct RequestData
-  {
-    RequestData(const BluetoothAttributeHandle& aHandle,
-                BluetoothGattCharacteristic* aCharacteristic,
-                BluetoothGattDescriptor* aDescriptor)
-    : mHandle(aHandle)
-    , mCharacteristic(aCharacteristic)
-    , mDescriptor(aDescriptor)
-    { }
-
-    BluetoothAttributeHandle mHandle;
-    RefPtr<BluetoothGattCharacteristic> mCharacteristic;
-    RefPtr<BluetoothGattDescriptor> mDescriptor;
-  };
-
-  void HandleServerRegistered(const BluetoothValue& aValue);
-  void HandleServerUnregistered(const BluetoothValue& aValue);
-  void HandleConnectionStateChanged(const BluetoothValue& aValue);
-  void HandleServiceHandleUpdated(const BluetoothValue& aValue);
-  void HandleCharacteristicHandleUpdated(const BluetoothValue& aValue);
-  void HandleDescriptorHandleUpdated(const BluetoothValue& aValue);
-  void HandleReadWriteRequest(const BluetoothValue& aValue,
-                              const nsAString& aString);
-
-  /****************************************************************************
-   * Variables
-   ***************************************************************************/
-  nsCOMPtr<nsPIDOMWindowInner> mOwner;
-
-  /**
-   * Random generated UUID of this GATT client.
-   */
-  nsString mAppUuid;
-
-  /**
-   * Id of the GATT server interface given by bluetooth stack.
-   * 0 if the interface is not registered yet, nonzero otherwise.
-   */
-  int mServerIf;
-
-  bool mValid;
-
-  /**
-   * Array of services for this server.
-   */
-  nsTArray<RefPtr<BluetoothGattService>> mServices;
-
-  /**
-   * The service that is being added to this server.
-   */
-  RefPtr<BluetoothGattService> mPendingService;
-
-  /**
-   * Map request information from the request ID.
-   */
-  nsClassHashtable<nsUint32HashKey, RequestData> mRequestMap;
-
-  /**
-   * AppUuid of the GATT client interface which is used to advertise.
-   */
-  BluetoothUuid mAdvertisingAppUuid;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothGattServer_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothGattService.cpp
+++ /dev/null
@@ -1,259 +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 "BluetoothService.h"
-#include "BluetoothUtils.h"
-#include "mozilla/dom/BluetoothGattServiceBinding.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/bluetooth/BluetoothGattCharacteristic.h"
-#include "mozilla/dom/bluetooth/BluetoothGattService.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-
-using namespace mozilla;
-using namespace mozilla::dom;
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(BluetoothGattService,
-                                      mOwner,
-                                      mIncludedServices,
-                                      mCharacteristics)
-
-NS_IMPL_CYCLE_COLLECTING_ADDREF(BluetoothGattService)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(BluetoothGattService)
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BluetoothGattService)
-  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
-
-const uint16_t BluetoothGattService::sHandleCount = 1;
-
-// Constructor of BluetoothGattService in ATT client role
-BluetoothGattService::BluetoothGattService(
-  nsPIDOMWindowInner* aOwner, const nsAString& aAppUuid,
-  const BluetoothGattServiceId& aServiceId)
-  : mOwner(aOwner)
-  , mAppUuid(aAppUuid)
-  , mServiceId(aServiceId)
-  , mAttRole(ATT_CLIENT_ROLE)
-  , mActive(true)
-{
-  MOZ_ASSERT(aOwner);
-  MOZ_ASSERT(!mAppUuid.IsEmpty());
-
-  UuidToString(mServiceId.mId.mUuid, mUuidStr);
-}
-
-// Constructor of BluetoothGattService in ATT server role
-BluetoothGattService::BluetoothGattService(
-  nsPIDOMWindowInner* aOwner,
-  const BluetoothGattServiceInit& aInit)
-  : mOwner(aOwner)
-  , mUuidStr(aInit.mUuid)
-  , mAttRole(ATT_SERVER_ROLE)
-  , mActive(false)
-{
-  memset(&mServiceId, 0, sizeof(mServiceId));
-  StringToUuid(aInit.mUuid, mServiceId.mId.mUuid);
-  mServiceId.mIsPrimary = aInit.mIsPrimary;
-}
-
-BluetoothGattService::~BluetoothGattService()
-{
-}
-
-void
-BluetoothGattService::AssignIncludedServices(
-  const nsTArray<BluetoothGattServiceId>& aServiceIds)
-{
-  mIncludedServices.Clear();
-  for (uint32_t i = 0; i < aServiceIds.Length(); i++) {
-    mIncludedServices.AppendElement(new BluetoothGattService(
-      GetParentObject(), mAppUuid, aServiceIds[i]));
-  }
-
-  BluetoothGattServiceBinding::ClearCachedIncludedServicesValue(this);
-}
-
-void
-BluetoothGattService::AssignCharacteristics(
-  const nsTArray<BluetoothGattCharAttribute>& aCharacteristics)
-{
-  mCharacteristics.Clear();
-  for (uint32_t i = 0; i < aCharacteristics.Length(); i++) {
-    mCharacteristics.AppendElement(new BluetoothGattCharacteristic(
-      GetParentObject(), this, aCharacteristics[i]));
-  }
-
-  BluetoothGattServiceBinding::ClearCachedCharacteristicsValue(this);
-}
-
-void
-BluetoothGattService::AssignDescriptors(
-  const BluetoothGattId& aCharacteristicId,
-  const nsTArray<BluetoothGattId>& aDescriptorIds)
-{
-  size_t index = mCharacteristics.IndexOf(aCharacteristicId);
-  NS_ENSURE_TRUE_VOID(index != mCharacteristics.NoIndex);
-
-  RefPtr<BluetoothGattCharacteristic> characteristic =
-    mCharacteristics.ElementAt(index);
-  characteristic->AssignDescriptors(aDescriptorIds);
-}
-
-void
-BluetoothGattService::AssignAppUuid(const nsAString& aAppUuid)
-{
-  MOZ_ASSERT(mAttRole == ATT_SERVER_ROLE);
-
-  mAppUuid = aAppUuid;
-}
-
-void
-BluetoothGattService::AssignServiceHandle(
-  const BluetoothAttributeHandle& aServiceHandle)
-{
-  MOZ_ASSERT(mAttRole == ATT_SERVER_ROLE);
-  MOZ_ASSERT(!mActive);
-  MOZ_ASSERT(!mServiceHandle.mHandle);
-
-  mServiceHandle = aServiceHandle;
-  mActive = true;
-}
-
-void
-BluetoothGattService::AssignCharacteristicHandle(
-  const BluetoothUuid& aCharacteristicUuid,
-  const BluetoothAttributeHandle& aCharacteristicHandle)
-{
-  MOZ_ASSERT(mAttRole == ATT_SERVER_ROLE);
-  MOZ_ASSERT(mActive);
-
-  size_t index = mCharacteristics.IndexOf(aCharacteristicUuid);
-  NS_ENSURE_TRUE_VOID(index != mCharacteristics.NoIndex);
-  mCharacteristics[index]->AssignCharacteristicHandle(aCharacteristicHandle);
-}
-
-void
-BluetoothGattService::AssignDescriptorHandle(
-  const BluetoothUuid& aDescriptorUuid,
-  const BluetoothAttributeHandle& aCharacteristicHandle,
-  const BluetoothAttributeHandle& aDescriptorHandle)
-{
-  MOZ_ASSERT(mAttRole == ATT_SERVER_ROLE);
-  MOZ_ASSERT(mActive);
-
-  size_t index = mCharacteristics.IndexOf(aCharacteristicHandle);
-  NS_ENSURE_TRUE_VOID(index != mCharacteristics.NoIndex);
-  mCharacteristics[index]->AssignDescriptorHandle(aDescriptorUuid,
-                                                  aDescriptorHandle);
-}
-
-uint16_t
-BluetoothGattService::GetHandleCount() const
-{
-  uint16_t count = sHandleCount;
-  for (size_t i = 0; i < mCharacteristics.Length(); ++i) {
-    count += mCharacteristics[i]->GetHandleCount();
-  }
-  return count;
-}
-
-JSObject*
-BluetoothGattService::WrapObject(JSContext* aContext,
-                                 JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothGattServiceBinding::Wrap(aContext, this, aGivenProto);
-}
-
-already_AddRefed<BluetoothGattService>
-BluetoothGattService::Constructor(const GlobalObject& aGlobal,
-                                  const BluetoothGattServiceInit& aInit,
-                                  ErrorResult& aRv)
-{
-  nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports());
-  if (!window) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<BluetoothGattService> service = new BluetoothGattService(window,
-                                                                    aInit);
-
-  return service.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothGattService::AddCharacteristic(
-  const nsAString& aCharacteristicUuid,
-  const GattPermissions& aPermissions,
-  const GattCharacteristicProperties& aProperties,
-  const ArrayBuffer& aValue,
-  ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(mAttRole == ATT_SERVER_ROLE,
-                        promise,
-                        NS_ERROR_UNEXPECTED);
-
-  /* The service should not be actively acting with the Bluetooth backend.
-   * Otherwise, characteristics cannot be added into the service. */
-  BT_ENSURE_TRUE_REJECT(!mActive, promise, NS_ERROR_UNEXPECTED);
-
-  RefPtr<BluetoothGattCharacteristic> characteristic =
-    new BluetoothGattCharacteristic(GetParentObject(),
-                                    this,
-                                    aCharacteristicUuid,
-                                    aPermissions,
-                                    aProperties,
-                                    aValue);
-
-  mCharacteristics.AppendElement(characteristic);
-  promise->MaybeResolve(characteristic);
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothGattService::AddIncludedService(BluetoothGattService& aIncludedService,
-                                         ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(mAttRole == ATT_SERVER_ROLE,
-                        promise,
-                        NS_ERROR_UNEXPECTED);
-
-  /* The service should not be actively acting with the Bluetooth backend.
-   * Otherwise, included services cannot be added into the service. */
-  BT_ENSURE_TRUE_REJECT(!mActive, promise, NS_ERROR_UNEXPECTED);
-
-  /* The included service itself should be actively acting with the Bluetooth
-   * backend. Otherwise, that service cannot be included by any services. */
-  BT_ENSURE_TRUE_REJECT(aIncludedService.mActive,
-                        promise,
-                        NS_ERROR_UNEXPECTED);
-
-  mIncludedServices.AppendElement(&aIncludedService);
-  promise->MaybeResolveWithUndefined();
-
-  return promise.forget();
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothGattService.h
+++ /dev/null
@@ -1,318 +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_BluetoothGattService_h
-#define mozilla_dom_bluetooth_BluetoothGattService_h
-
-#include "mozilla/Attributes.h"
-#include "mozilla/dom/BluetoothGattServiceBinding.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/bluetooth/BluetoothGattCharacteristic.h"
-#include "nsCOMPtr.h"
-#include "nsWrapperCache.h"
-#include "nsPIDOMWindow.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothGatt;
-class BluetoothSignal;
-class BluetoothValue;
-
-class BluetoothGattService final : public nsISupports
-                                 , public nsWrapperCache
-{
-  friend class BluetoothGatt;
-  friend class BluetoothGattServer;
-public:
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(BluetoothGattService)
-
-  /****************************************************************************
-   * Attribute Getters
-   ***************************************************************************/
-  bool IsPrimary() const
-  {
-    return mServiceId.mIsPrimary;
-  }
-
-  void GetUuid(nsString& aUuidStr) const
-  {
-    aUuidStr = mUuidStr;
-  }
-
-  int InstanceId() const
-  {
-    return mServiceId.mId.mInstanceId;
-  }
-
-  void GetIncludedServices(
-    nsTArray<RefPtr<BluetoothGattService>>& aIncludedServices) const
-  {
-    aIncludedServices = mIncludedServices;
-  }
-
-  void GetCharacteristics(
-    nsTArray<RefPtr<BluetoothGattCharacteristic>>& aCharacteristics) const
-  {
-    aCharacteristics = mCharacteristics;
-  }
-
-  /****************************************************************************
-   * Methods (Web API Implementation)
-   ***************************************************************************/
-  static already_AddRefed<BluetoothGattService> Constructor(
-    const GlobalObject& aGlobal,
-    const BluetoothGattServiceInit& aInit,
-    ErrorResult& aRv);
-  already_AddRefed<Promise> AddCharacteristic(
-    const nsAString& aCharacteristicUuid,
-    const GattPermissions& aPermissions,
-    const GattCharacteristicProperties& aProperties,
-    const ArrayBuffer& aValue,
-    ErrorResult& aRv);
-  already_AddRefed<Promise> AddIncludedService(
-    BluetoothGattService& aIncludedService,
-    ErrorResult& aRv);
-
-  /****************************************************************************
-   * Others
-   ***************************************************************************/
-  const nsAString& GetAppUuid() const
-  {
-    return mAppUuid;
-  }
-
-  const BluetoothGattServiceId& GetServiceId() const
-  {
-    return mServiceId;
-  }
-
-  const BluetoothAttributeHandle& GetServiceHandle() const
-  {
-    return mServiceHandle;
-  }
-
-  nsPIDOMWindowInner* GetParentObject() const
-  {
-     return mOwner;
-  }
-
-  uint16_t GetHandleCount() const;
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-
-  // Constructor of BluetoothGattService in ATT client role
-  BluetoothGattService(nsPIDOMWindowInner* aOwner,
-                       const nsAString& aAppUuid,
-                       const BluetoothGattServiceId& aServiceId);
-  // Constructor of BluetoothGattService in ATT server role
-  BluetoothGattService(nsPIDOMWindowInner* aOwner,
-                       const BluetoothGattServiceInit& aInit);
-
-private:
-  ~BluetoothGattService();
-
-  /**
-   * Add newly discovered GATT included services into mIncludedServices and
-   * update the cache value of mIncludedServices.
-   *
-   * @param aServiceIds [in] An array of BluetoothGattServiceId for each
-   *                         included service that belongs to this service.
-   */
-  void AssignIncludedServices(
-    const nsTArray<BluetoothGattServiceId>& aServiceIds);
-
-  /**
-   * Add newly discovered GATT characteristics into mCharacteristics and
-   * update the cache value of mCharacteristics.
-   *
-   * @param aCharacteristics [in] An array of BluetoothGattCharAttribute for
-   *                              each characteristic that belongs to this
-   *                              service.
-   */
-  void AssignCharacteristics(
-    const nsTArray<BluetoothGattCharAttribute>& aCharacteristics);
-
-  /**
-   * Add newly discovered GATT descriptors into mDescriptors of
-   * BluetoothGattCharacteristic and update the cache value of mDescriptors.
-   *
-   * @param aCharacteristicId [in] BluetoothGattId of a characteristic that
-   *                               belongs to this service.
-   * @param aDescriptorIds [in] An array of BluetoothGattId for each descriptor
-   *                            that belongs to the characteristic referred by
-   *                            aCharacteristicId.
-   */
-  void AssignDescriptors(
-    const BluetoothGattId& aCharacteristicId,
-    const nsTArray<BluetoothGattId>& aDescriptorIds);
-
-  /**
-   * Assign AppUuid of this GATT service.
-   *
-   * @param aAppUuid The value of AppUuid.
-   */
-  void AssignAppUuid(const nsAString& aAppUuid);
-
-  /**
-   * Assign the handle value for this GATT service. This function would be
-   * called only after a valid handle value is retrieved from the Bluetooth
-   * backend.
-   *
-   * @param aServiceHandle [in] The handle value of this GATT service.
-   */
-  void AssignServiceHandle(const BluetoothAttributeHandle& aServiceHandle);
-
-  /**
-   * Assign the handle value for one of the characteristic within this GATT
-   * service. This function would be called only after a valid handle value is
-   * retrieved from the Bluetooth backend.
-   *
-   * @param aCharacteristicUuid [in] BluetoothUuid of this GATT characteristic.
-   * @param aCharacteristicHandle [in] The handle value of this GATT
-   *                                   characteristic.
-   */
-  void AssignCharacteristicHandle(
-    const BluetoothUuid& aCharacteristicUuid,
-    const BluetoothAttributeHandle& aCharacteristicHandle);
-
-  /**
-   * Assign the handle value for one of the descriptor within this GATT
-   * service. This function would be called only after a valid handle value is
-   * retrieved from the Bluetooth backend.
-   *
-   * @param aDescriptorUuid [in] BluetoothUuid of this GATT descriptor.
-   * @param aCharacteristicHandle [in] The handle value of this GATT
-   *                                   characteristic.
-   * @param aDescriptorHandle [in] The handle value of this GATT descriptor.
-   */
-  void AssignDescriptorHandle(
-    const BluetoothUuid& aDescriptorUuid,
-    const BluetoothAttributeHandle& aCharacteristicHandle,
-    const BluetoothAttributeHandle& aDescriptorHandle);
-
-  /**
-   * Examine whether this GATT service can react with the Bluetooth backend.
-   *
-   * @return true if this service can react with the Bluetooth backend; false
-   *         if this service cannot react with the Bluetooth backend.
-   */
-  bool IsActivated() const
-  {
-    return mActive;
-  }
-
-  /****************************************************************************
-   * Variables
-   ***************************************************************************/
-  nsCOMPtr<nsPIDOMWindowInner> mOwner;
-
-  /**
-   * UUID of the GATT client.
-   */
-  nsString mAppUuid;
-
-  /**
-   * ServiceId of this GATT service which contains
-   * 1) mId.mUuid: UUID of this service in byte array format.
-   * 2) mId.mInstanceId: Instance id of this service.
-   * 3) mIsPrimary: Indicate whether this is a primary service or not.
-   */
-  BluetoothGattServiceId mServiceId;
-
-  /**
-   * UUID string of this GATT service.
-   */
-  nsString mUuidStr;
-
-  /**
-   * Array of discovered included services for this service.
-   */
-  nsTArray<RefPtr<BluetoothGattService>> mIncludedServices;
-
-  /**
-   * Array of discovered characteristics for this service.
-   */
-  nsTArray<RefPtr<BluetoothGattCharacteristic>> mCharacteristics;
-
-  /**
-   * ATT role of this GATT service.
-   */
-  const BluetoothAttRole mAttRole;
-
-  /**
-   * Activeness of this GATT service.
-   *
-   * True means this service does react with the Bluetooth backend. False means
-   * this service doesn't react with the Bluetooth backend. The value should be
-   * true if |mAttRole| equals |ATT_CLIENT_ROLE| because the service instance
-   * could be created only when the Bluetooth backend has found one GATT
-   * service. The value would be false at the beginning if |mAttRole| equals
-   * |ATT_SERVER_ROLE|. Then the value would become true later if this GATT
-   * service has been added into Bluetooth backend.
-   */
-  bool mActive;
-
-  /**
-   * Handle of this GATT service.
-   *
-   * The value is only valid if |mAttRole| equals |ATT_SERVER_ROLE|.
-   */
-  BluetoothAttributeHandle mServiceHandle;
-
-  /**
-   * Total count of handles of this GATT service itself.
-   */
-  static const uint16_t sHandleCount;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-/**
- * Explicit Specialization of Function Templates
- *
- * Allows customizing the template code for a given set of template arguments.
- * With this function template, nsTArray can handle comparison between
- * 'RefPtr<BluetoothGattService>' and 'BluetoothGattServiceId' properly,
- * including IndexOf() and Contains();
- */
-template <>
-class nsDefaultComparator <
-  RefPtr<mozilla::dom::bluetooth::BluetoothGattService>,
-  mozilla::dom::bluetooth::BluetoothGattServiceId> {
-public:
-  bool Equals(
-    const RefPtr<mozilla::dom::bluetooth::BluetoothGattService>& aService,
-    const mozilla::dom::bluetooth::BluetoothGattServiceId& aServiceId) const
-  {
-    return aService->GetServiceId() == aServiceId;
-  }
-};
-
-/**
- * Explicit Specialization of Function Templates
- *
- * Allows customizing the template code for a given set of template arguments.
- * With this function template, nsTArray can handle comparison between
- * 'RefPtr<BluetoothGattService>' and 'BluetoothAttributeHandle' properly,
- * including IndexOf() and Contains();
- */
-template <>
-class nsDefaultComparator <
-  RefPtr<mozilla::dom::bluetooth::BluetoothGattService>,
-  mozilla::dom::bluetooth::BluetoothAttributeHandle> {
-public:
-  bool Equals(
-    const RefPtr<mozilla::dom::bluetooth::BluetoothGattService>& aService,
-    const mozilla::dom::bluetooth::BluetoothAttributeHandle& aServiceHandle)
-    const
-  {
-    return aService->GetServiceHandle() == aServiceHandle;
-  }
-};
-
-#endif // mozilla_dom_bluetooth_BluetoothGattService_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothLeDeviceEvent.cpp
+++ /dev/null
@@ -1,146 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:set ts=2 sw=2 sts=2 et cindent: */
-/* 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 "mozilla/dom/bluetooth/BluetoothLeDeviceEvent.h"
-
-#include "js/GCAPI.h"
-#include "jsfriendapi.h"
-#include "mozilla/HoldDropJSObjects.h"
-#include "mozilla/dom/BluetoothLeDeviceEventBinding.h"
-#include "mozilla/dom/Nullable.h"
-#include "mozilla/dom/PrimitiveConversions.h"
-#include "mozilla/dom/TypedArray.h"
-#include "mozilla/dom/bluetooth/BluetoothDevice.h"
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothLeDeviceEvent)
-
-NS_IMPL_ADDREF_INHERITED(BluetoothLeDeviceEvent, Event)
-NS_IMPL_RELEASE_INHERITED(BluetoothLeDeviceEvent, Event)
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothLeDeviceEvent, Event)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDevice)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(BluetoothLeDeviceEvent, Event)
-  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mScanRecord)
-NS_IMPL_CYCLE_COLLECTION_TRACE_END
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothLeDeviceEvent, Event)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mDevice)
-  tmp->mScanRecord = nullptr;
-  mozilla::DropJSObjects(this);
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothLeDeviceEvent)
-NS_INTERFACE_MAP_END_INHERITING(Event)
-
-BluetoothLeDeviceEvent::BluetoothLeDeviceEvent(
-  mozilla::dom::EventTarget* aOwner)
-  : Event(aOwner, nullptr, nullptr)
-{
-  mozilla::HoldJSObjects(this);
-}
-
-BluetoothLeDeviceEvent::~BluetoothLeDeviceEvent()
-{
-  mScanRecord = nullptr;
-  mozilla::DropJSObjects(this);
-}
-
-JSObject*
-BluetoothLeDeviceEvent::WrapObjectInternal(JSContext* aCx,
-                                           JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothLeDeviceEventBinding::Wrap(aCx, this, aGivenProto);
-}
-
-already_AddRefed<BluetoothLeDeviceEvent>
-BluetoothLeDeviceEvent::Constructor(
-  mozilla::dom::EventTarget* aOwner,
-  const nsAString& aType,
-  BluetoothDevice* const aDevice,
-  const int16_t aRssi,
-  const nsTArray<uint8_t>& aScanRecord)
-{
-  RefPtr<BluetoothLeDeviceEvent> e = new BluetoothLeDeviceEvent(aOwner);
-  bool trusted = e->Init(aOwner);
-  e->InitEvent(aType, false, false);
-  e->mDevice = aDevice;
-  e->mRssi = aRssi;
-  e->mRawScanRecord = aScanRecord;
-
-  e->SetTrusted(trusted);
-  return e.forget();
-}
-
-already_AddRefed<BluetoothLeDeviceEvent>
-BluetoothLeDeviceEvent::Constructor(
-  const GlobalObject& aGlobal,
-  const nsAString& aType,
-  const BluetoothLeDeviceEventInit& aEventInitDict,
-  ErrorResult& aRv)
-{
-  nsCOMPtr<mozilla::dom::EventTarget> owner =
-    do_QueryInterface(aGlobal.GetAsSupports());
-
-  RefPtr<BluetoothLeDeviceEvent> e = new BluetoothLeDeviceEvent(owner);
-  bool trusted = e->Init(owner);
-  e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable);
-  e->mDevice = aEventInitDict.mDevice;
-  e->mRssi = aEventInitDict.mRssi;
-
-  if (!aEventInitDict.mScanRecord.IsNull()) {
-    const auto& scanRecord = aEventInitDict.mScanRecord.Value();
-    scanRecord.ComputeLengthAndData();
-    e->mScanRecord = ArrayBuffer::Create(aGlobal.Context(),
-                                         scanRecord.Length(),
-                                         scanRecord.Data());
-    if (!e->mScanRecord) {
-      aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
-      return nullptr;
-    }
-  }
-
-  e->SetTrusted(trusted);
-  e->SetComposed(aEventInitDict.mComposed);
-  return e.forget();
-}
-
-BluetoothDevice*
-BluetoothLeDeviceEvent::GetDevice() const
-{
-  return mDevice;
-}
-
-int16_t
-BluetoothLeDeviceEvent::Rssi() const
-{
-  return mRssi;
-}
-
-void
-BluetoothLeDeviceEvent::GetScanRecord(
-  JSContext* cx,
-  JS::MutableHandle<JSObject*> aScanRecord,
-  ErrorResult& aRv)
-{
-  if (!mScanRecord) {
-    mScanRecord = ArrayBuffer::Create(cx,
-                                      this,
-                                      mRawScanRecord.Length(),
-                                      mRawScanRecord.Elements());
-    if (!mScanRecord) {
-      aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
-      return;
-    }
-    mRawScanRecord.Clear();
-  }
-  aScanRecord.set(mScanRecord);
-
-  return;
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothLeDeviceEvent.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:set ts=2 sw=2 sts=2 et cindent: */
-/* 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_BluetoothLeDeviceEvent_h
-#define mozilla_dom_bluetooth_BluetoothLeDeviceEvent_h
-
-#include "mozilla/Attributes.h"
-#include "mozilla/ErrorResult.h"
-#include "mozilla/dom/BluetoothLeDeviceEventBinding.h"
-#include "mozilla/dom/Event.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothLeDeviceEvent : public Event
-{
-public:
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(BluetoothLeDeviceEvent,
-                                                         Event)
-protected:
-  virtual ~BluetoothLeDeviceEvent();
-  explicit BluetoothLeDeviceEvent(mozilla::dom::EventTarget* aOwner);
-
-  RefPtr<BluetoothDevice> mDevice;
-  int16_t mRssi;
-  JS::Heap<JSObject*> mScanRecord;
-
-public:
-  virtual JSObject* WrapObjectInternal(
-    JSContext* aCx,
-    JS::Handle<JSObject*> aGivenProto) override;
-
-  static already_AddRefed<BluetoothLeDeviceEvent>
-    Constructor(EventTarget* aOwner,
-                const nsAString& aType,
-                BluetoothDevice* const aDevice,
-                const int16_t aRssi,
-                const nsTArray<uint8_t>& aScanRecord);
-
-  static already_AddRefed<BluetoothLeDeviceEvent>
-    Constructor(const GlobalObject& aGlobal,
-                const nsAString& aType,
-                const BluetoothLeDeviceEventInit& aEventInitDict,
-                ErrorResult& aRv);
-
-  BluetoothDevice* GetDevice() const;
-
-  int16_t Rssi() const;
-
-  void GetScanRecord(JSContext* cx,
-                     JS::MutableHandle<JSObject*> aScanRecord,
-                     ErrorResult& aRv);
-
-  private:
-    nsTArray<uint8_t> mRawScanRecord;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothLeDeviceEvent_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothManager.cpp
+++ /dev/null
@@ -1,294 +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 "base/basictypes.h"
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-#include "BluetoothUtils.h"
-
-#include "mozilla/dom/bluetooth/BluetoothAdapter.h"
-#include "mozilla/dom/bluetooth/BluetoothManager.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/dom/BluetoothManagerBinding.h"
-#include "mozilla/Preferences.h"
-#include "mozilla/Services.h"
-#include "nsContentUtils.h"
-#include "nsDOMClassInfo.h"
-#include "nsIPermissionManager.h"
-#include "nsThreadUtils.h"
-
-using namespace mozilla;
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothManager)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothManager,
-                                                DOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mAdapters)
-
-  /**
-   * Unregister the bluetooth signal handler after unlinked.
-   *
-   * This is needed to avoid ending up with exposing a deleted object to JS or
-   * accessing deleted objects while receiving signals from parent process
-   * after unlinked. Please see Bug 1138267 for detail informations.
-   */
-  UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_MANAGER), tmp);
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothManager,
-                                                  DOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAdapters)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothManager)
-NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
-
-NS_IMPL_ADDREF_INHERITED(BluetoothManager, DOMEventTargetHelper)
-NS_IMPL_RELEASE_INHERITED(BluetoothManager, DOMEventTargetHelper)
-
-class GetAdaptersTask : public BluetoothReplyRunnable
-{
- public:
-  GetAdaptersTask(BluetoothManager* aManager)
-    : BluetoothReplyRunnable(nullptr)
-    , mManager(aManager)
-  { }
-
-  bool
-  ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue)
-  {
-    /**
-     * Unwrap BluetoothReply.BluetoothReplySuccess.BluetoothValue =
-     *   BluetoothNamedValue[]
-     *     |
-     *     |__ BluetoothNamedValue =
-     *     |     {"Adapter", BluetoothValue = BluetoothNamedValue[]}
-     *     |
-     *     |__ BluetoothNamedValue =
-     *     |     {"Adapter", BluetoothValue = BluetoothNamedValue[]}
-     *     ...
-     */
-
-    // Extract the array of all adapters' properties
-    const BluetoothValue& adaptersProperties =
-      mReply->get_BluetoothReplySuccess().value();
-    NS_ENSURE_TRUE(adaptersProperties.type() ==
-                   BluetoothValue::TArrayOfBluetoothNamedValue, false);
-
-    const InfallibleTArray<BluetoothNamedValue>& adaptersPropertiesArray =
-      adaptersProperties.get_ArrayOfBluetoothNamedValue();
-
-    // Append a BluetoothAdapter into adapters array for each properties array
-    uint32_t numAdapters = adaptersPropertiesArray.Length();
-    for (uint32_t i = 0; i < numAdapters; i++) {
-      MOZ_ASSERT(adaptersPropertiesArray[i].name().EqualsLiteral("Adapter"));
-
-      const BluetoothValue& properties = adaptersPropertiesArray[i].value();
-      mManager->AppendAdapter(properties);
-    }
-
-    aValue.setUndefined();
-    return true;
-  }
-
-  virtual void
-  ReleaseMembers() override
-  {
-    BluetoothReplyRunnable::ReleaseMembers();
-    mManager = nullptr;
-  }
-
-private:
-  RefPtr<BluetoothManager> mManager;
-};
-
-BluetoothManager::BluetoothManager(nsPIDOMWindowInner *aWindow)
-  : DOMEventTargetHelper(aWindow)
-  , mDefaultAdapterIndex(-1)
-{
-  MOZ_ASSERT(aWindow);
-
-  RegisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_MANAGER), this);
-
-  // Query adapters list from bluetooth backend
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  RefPtr<BluetoothReplyRunnable> result = new GetAdaptersTask(this);
-  NS_ENSURE_SUCCESS_VOID(bs->GetAdaptersInternal(result));
-}
-
-BluetoothManager::~BluetoothManager()
-{
-  UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_MANAGER), this);
-}
-
-void
-BluetoothManager::DisconnectFromOwner()
-{
-  DOMEventTargetHelper::DisconnectFromOwner();
-  UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_MANAGER), this);
-}
-
-BluetoothAdapter*
-BluetoothManager::GetDefaultAdapter()
-{
-  if (!DefaultAdapterExists()) {
-    return nullptr;
-  }
-  return mAdapters[mDefaultAdapterIndex];
-}
-
-void
-BluetoothManager::AppendAdapter(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  // Create a new BluetoothAdapter and append it to adapters array
-  const InfallibleTArray<BluetoothNamedValue>& values =
-    aValue.get_ArrayOfBluetoothNamedValue();
-  RefPtr<BluetoothAdapter> adapter =
-    BluetoothAdapter::Create(GetOwner(), values);
-
-  mAdapters.AppendElement(adapter);
-
-  // Set this adapter as default adapter if no adapter exists
-  if (!DefaultAdapterExists()) {
-    MOZ_ASSERT(mAdapters.Length() == 1);
-    ReselectDefaultAdapter();
-  }
-}
-
-void
-BluetoothManager::GetAdapters(nsTArray<RefPtr<BluetoothAdapter> >& aAdapters)
-{
-  aAdapters = mAdapters;
-}
-
-// static
-already_AddRefed<BluetoothManager>
-BluetoothManager::Create(nsPIDOMWindowInner* aWindow)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aWindow);
-
-  RefPtr<BluetoothManager> manager = new BluetoothManager(aWindow);
-  return manager.forget();
-}
-
-void
-BluetoothManager::HandleAdapterAdded(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-  AppendAdapter(aValue);
-
-  // Notify application of added adapter
-  BluetoothAdapterEventInit init;
-  init.mAdapter = mAdapters.LastElement();
-  DispatchAdapterEvent(NS_LITERAL_STRING("adapteradded"), init);
-}
-
-void
-BluetoothManager::HandleAdapterRemoved(const BluetoothValue& aValue)
-{
-  MOZ_ASSERT(aValue.type() == BluetoothValue::TBluetoothAddress);
-  MOZ_ASSERT(DefaultAdapterExists());
-
-  // Remove the adapter of given address from adapters array
-  nsString addressToRemove;
-  AddressToString(aValue.get_BluetoothAddress(), addressToRemove);
-
-  uint32_t i;
-  for (i = 0; i < mAdapters.Length(); i++) {
-    nsString address;
-    mAdapters[i]->GetAddress(address);
-    if (address.Equals(addressToRemove)) {
-      mAdapters.RemoveElementAt(i);
-      break;
-    }
-  }
-
-  // Notify application of removed adapter
-  BluetoothAdapterEventInit init;
-  init.mAddress = addressToRemove;
-  DispatchAdapterEvent(NS_LITERAL_STRING("adapterremoved"), init);
-
-  // Reselect default adapter if it's removed
-  if (mDefaultAdapterIndex == (int)i) {
-    ReselectDefaultAdapter();
-  }
-}
-
-void
-BluetoothManager::ReselectDefaultAdapter()
-{
-  // Select the first of existing/remaining adapters as default adapter
-  mDefaultAdapterIndex = mAdapters.IsEmpty() ? -1 : 0;
-
-  // Notify application of default adapter change
-  DispatchAttributeEvent();
-}
-
-void
-BluetoothManager::DispatchAdapterEvent(const nsAString& aType,
-                                       const BluetoothAdapterEventInit& aInit)
-{
-  RefPtr<BluetoothAdapterEvent> event =
-    BluetoothAdapterEvent::Constructor(this, aType, aInit);
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothManager::DispatchAttributeEvent()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  Sequence<nsString> types;
-  BT_APPEND_ENUM_STRING_FALLIBLE(types,
-                                 BluetoothManagerAttribute,
-                                 BluetoothManagerAttribute::DefaultAdapter);
-
-  // Notify application of default adapter change
-  BluetoothAttributeEventInit init;
-  init.mAttrs = types;
-  RefPtr<BluetoothAttributeEvent> event =
-    BluetoothAttributeEvent::Constructor(
-      this, NS_LITERAL_STRING(ATTRIBUTE_CHANGED_ID), init);
-
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothManager::Notify(const BluetoothSignal& aData)
-{
-  BT_LOGD("[M] %s", NS_ConvertUTF16toUTF8(aData.name()).get());
-  NS_ENSURE_TRUE_VOID(mSignalRegistered);
-
-  if (aData.name().EqualsLiteral("AdapterAdded")) {
-    HandleAdapterAdded(aData.value());
-  } else if (aData.name().EqualsLiteral("AdapterRemoved")) {
-    HandleAdapterRemoved(aData.value());
-  } else {
-    BT_WARNING("Not handling manager signal: %s",
-               NS_ConvertUTF16toUTF8(aData.name()).get());
-  }
-}
-
-JSObject*
-BluetoothManager::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothManagerBinding::Wrap(aCx, this, aGivenProto);
-}
-
-// static
-bool
-BluetoothManager::B2GGattClientEnabled(JSContext* cx, JSObject* aGlobal)
-{
-  return !Preferences::GetBool("dom.bluetooth.webbluetooth.enabled");
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothManager.h
+++ /dev/null
@@ -1,149 +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_BluetoothManager_h
-#define mozilla_dom_bluetooth_BluetoothManager_h
-
-#include "BluetoothCommon.h"
-#include "mozilla/Attributes.h"
-#include "mozilla/dom/BluetoothAdapterEvent.h"
-#include "mozilla/dom/BluetoothAttributeEvent.h"
-#include "mozilla/DOMEventTargetHelper.h"
-#include "mozilla/Observer.h"
-#include "nsISupportsImpl.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothAdapter;
-class BluetoothValue;
-
-class BluetoothManager final : public DOMEventTargetHelper
-                             , public BluetoothSignalObserver
-{
-public:
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BluetoothManager,
-                                           DOMEventTargetHelper)
-
-  /****************************************************************************
-   * Event Handlers
-   ***************************************************************************/
-  IMPL_EVENT_HANDLER(attributechanged);
-  IMPL_EVENT_HANDLER(adapteradded);
-  IMPL_EVENT_HANDLER(adapterremoved);
-
-  /****************************************************************************
-   * Methods (Web API Implementation)
-   ***************************************************************************/
-  /**
-   * Return default adapter if it exists, nullptr otherwise. The function is
-   * called when applications access property BluetoothManager.defaultAdapter
-   */
-  BluetoothAdapter* GetDefaultAdapter();
-
-  /**
-   * Return adapters array. The function is called when applications call
-   * method BluetoothManager.getAdapters()
-   *
-   * @param aAdapters [out] Adapters array to return
-   */
-  void GetAdapters(nsTArray<RefPtr<BluetoothAdapter> >& aAdapters);
-
-  /****************************************************************************
-   * Others
-   ***************************************************************************/
-  // Never returns null
-  static already_AddRefed<BluetoothManager> Create(nsPIDOMWindowInner* aWindow);
-  static bool CheckPermission(nsPIDOMWindowInner* aWindow);
-
-  void Notify(const BluetoothSignal& aData); // BluetoothSignalObserver
-  nsPIDOMWindowInner* GetParentObject() const
-  {
-    return GetOwner();
-  }
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-  virtual void DisconnectFromOwner() override;
-
-  /**
-   * Create a BluetoothAdapter object based on properties array
-   * and append it into adapters array.
-   *
-   * @param aValue [in] Properties array to create BluetoothAdapter object
-   */
-  void AppendAdapter(const BluetoothValue& aValue);
-
-  /**
-   * Check whether B2G only GATT client API is enabled (true) or W3C
-   * WebBluetooth API is enabled (false).
-   */
-  static bool B2GGattClientEnabled(JSContext* cx, JSObject* aGlobal);
-
-private:
-  BluetoothManager(nsPIDOMWindowInner* aWindow);
-  ~BluetoothManager();
-
-  /**
-   * Check whether default adapter exists.
-   */
-  bool DefaultAdapterExists()
-  {
-    return (mDefaultAdapterIndex >= 0);
-  }
-
-  /**
-   * Handle "AdapterAdded" bluetooth signal.
-   *
-   * @param aValue [in] Properties array of the added adapter
-   */
-  void HandleAdapterAdded(const BluetoothValue& aValue);
-
-  /**
-   * Handle "AdapterRemoved" bluetooth signal.
-   *
-   * @param aValue [in] Address of the removed adapter
-   */
-  void HandleAdapterRemoved(const BluetoothValue& aValue);
-
-  /**
-   * Re-select default adapter from adapters array. The function is called
-   * when an adapter is added/removed.
-   */
-  void ReselectDefaultAdapter();
-
-  /**
-   * Fire BluetoothAdapterEvent to trigger
-   * onadapteradded/onadapterremoved event handler.
-   *
-   * @param aType [in] Event type to fire
-   * @param aInit [in] Event initialization value
-   */
-  void DispatchAdapterEvent(const nsAString& aType,
-                            const BluetoothAdapterEventInit& aInit);
-
-  /**
-   * Fire BluetoothAttributeEvent to trigger onattributechanged event handler.
-   */
-  void DispatchAttributeEvent();
-
-  /****************************************************************************
-   * Variables
-   ***************************************************************************/
-  /**
-   * The index of default adapter in the adapters array.
-   */
-  int mDefaultAdapterIndex;
-
-  /**
-   * The adapters array.
-   */
-  nsTArray<RefPtr<BluetoothAdapter> > mAdapters;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothManager_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothMapRequestHandle.cpp
+++ /dev/null
@@ -1,249 +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 "BluetoothCommon.h"
-#include "BluetoothMapRequestHandle.h"
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-
-#include "mozilla/dom/BluetoothMapRequestHandleBinding.h"
-#include "mozilla/dom/ContentChild.h"
-#include "mozilla/dom/Promise.h"
-
-using namespace mozilla;
-using namespace dom;
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(BluetoothMapRequestHandle, mOwner)
-NS_IMPL_CYCLE_COLLECTING_ADDREF(BluetoothMapRequestHandle)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(BluetoothMapRequestHandle)
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BluetoothMapRequestHandle)
-  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
-
-BluetoothMapRequestHandle::BluetoothMapRequestHandle(nsPIDOMWindowInner* aOwner)
-  : mOwner(aOwner)
-{
-  MOZ_ASSERT(aOwner);
-}
-
-BluetoothMapRequestHandle::~BluetoothMapRequestHandle()
-{
-}
-
-already_AddRefed<BluetoothMapRequestHandle>
-BluetoothMapRequestHandle::Create(nsPIDOMWindowInner* aOwner)
-{
-  MOZ_ASSERT(aOwner);
-
-  RefPtr<BluetoothMapRequestHandle> handle =
-    new BluetoothMapRequestHandle(aOwner);
-
-  return handle.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothMapRequestHandle::ReplyToFolderListing(long aMasId,
-  const nsAString& aFolderlists, ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  bs->ReplyToMapFolderListing(aMasId, aFolderlists,
-    new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothMapRequestHandle::ReplyToMessagesListing(long aMasId,
-                                                  Blob& aBlob,
-                                                  bool aNewMessage,
-                                                  const nsAString& aTimestamp,
-                                                  int aSize,
-                                                  ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  if (XRE_GetProcessType() == GeckoProcessType_Default) {
-    // In-process reply
-    bs->ReplyToMapMessagesListing(aMasId, &aBlob, aNewMessage, aTimestamp,
-      aSize, new BluetoothVoidReplyRunnable(nullptr, promise));
-  } else {
-    ContentChild *cc = ContentChild::GetSingleton();
-    if (!cc) {
-      aRv.Throw(NS_ERROR_FAILURE);
-      return nullptr;
-    }
-
-    BlobChild* actor = cc->GetOrCreateActorForBlob(&aBlob);
-    if (!actor) {
-      aRv.Throw(NS_ERROR_FAILURE);
-      return nullptr;
-    }
-
-    bs->ReplyToMapMessagesListing(nullptr, actor, aMasId, aNewMessage,
-      aTimestamp, aSize, new BluetoothVoidReplyRunnable(nullptr, promise));
-  }
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothMapRequestHandle::ReplyToGetMessage(long aMasId, Blob& aBlob,
-                                             ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  if (XRE_GetProcessType() == GeckoProcessType_Default) {
-    // In-process reply
-    bs->ReplyToMapGetMessage(&aBlob, aMasId,
-      new BluetoothVoidReplyRunnable(nullptr, promise));
-  } else {
-    ContentChild *cc = ContentChild::GetSingleton();
-    if (!cc) {
-      aRv.Throw(NS_ERROR_FAILURE);
-      return nullptr;
-    }
-
-    BlobChild* actor = cc->GetOrCreateActorForBlob(&aBlob);
-    if (!actor) {
-      aRv.Throw(NS_ERROR_FAILURE);
-      return nullptr;
-    }
-
-    bs->ReplyToMapGetMessage(nullptr, actor, aMasId,
-      new BluetoothVoidReplyRunnable(nullptr, promise));
-  }
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothMapRequestHandle::ReplyToSetMessageStatus(long aMasId,
-                                                   bool aStatus,
-                                                   ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  bs->ReplyToMapSetMessageStatus(aMasId, aStatus,
-    new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothMapRequestHandle::ReplyToSendMessage(long aMasId,
-                                              const nsAString& aHandleId,
-                                              bool aStatus,
-                                              ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  bs->ReplyToMapSendMessage(aMasId, aHandleId, aStatus,
-    new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothMapRequestHandle::ReplyToMessageUpdate(long aMasId,
-                                                bool aStatus,
-                                                ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  bs->ReplyToMapMessageUpdate(aMasId, aStatus,
-    new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-JSObject*
-BluetoothMapRequestHandle::WrapObject(JSContext* aCx,
-                                      JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothMapRequestHandleBinding::Wrap(aCx, this, aGivenProto);
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothMapRequestHandle.h
+++ /dev/null
@@ -1,118 +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_BluetoothMapRequestHandle_h
-#define mozilla_dom_bluetooth_BluetoothMapRequestHandle_h
-
-#include "nsCOMPtr.h"
-#include "nsPIDOMWindow.h"
-#include "nsWrapperCache.h"
-#include "mozilla/dom/File.h"
-
-namespace mozilla {
-  class ErrorResult;
-  namespace dom {
-    class Promise;
-  }
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothMapRequestHandle final : public nsISupports
-                                      , public nsWrapperCache
-{
-public:
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(BluetoothMapRequestHandle)
-
-  static already_AddRefed<BluetoothMapRequestHandle>
-    Create(nsPIDOMWindowInner* aOwner);
-
-  nsPIDOMWindowInner* GetParentObject() const
-  {
-    return mOwner;
-  }
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-  /**
-   * Reply to folder listing
-   *
-   * @param aMasId         [in]  MAS ID.
-   * @param aFolderlists   [in]  MAP folder Name.
-   * @param aRv            [out] Error result to set in case of error.
-   */
-  already_AddRefed<Promise> ReplyToFolderListing(long aMasId,
-    const nsAString& aFolderlists, ErrorResult& aRv);
-
-  /**
-   * Reply to messages listing
-   *
-   * @param aMasId         [in]  MAS ID.
-   * @param aBlob          [in]  MAP messages listing content.
-   * @param aNewMessage    [in]  Whether MSE has received a new message.
-   * @param aTimestamp     [in]  The local time basis and UTC offset of the
-   *                             MSE. MCE will interpret the timestamps of The
-   *                             messages listing entries.
-   * @param aSize          [in]  The number of accessible messages in the
-   *                             corresponding folder fulfilling.
-   * @param aRv            [out] Error result to set in case of error.
-   */
-  already_AddRefed<Promise> ReplyToMessagesListing(
-    long aMasId, Blob& aBlob, bool aNewMessage, const nsAString& aTimestamp,
-    int aSize, ErrorResult& aRv);
-
-  /**
-   * Reply to get-message request
-   *
-   * @param aMasId         [in]  MAS ID.
-   * @param aBlob          [in]  MAP get messages content.
-   * @param aRv            [out] Error result to set in case of error.
-   */
-  already_AddRefed<Promise> ReplyToGetMessage(long aMasId, Blob& aBlob,
-                                              ErrorResult& aRv);
-
-  /**
-   * Reply to set-message request
-   *
-   * @param aMasId         [in]  MAS ID.
-   * @param aStatus        [in]  MAP set message result.
-   * @param aRv            [out] Error result to set in case of error.
-   */
-  already_AddRefed<Promise> ReplyToSetMessageStatus(long aMasId, bool aStatus,
-                                                    ErrorResult& aRv);
-
-  /**
-   * Reply to send-message request
-   *
-   * @param aMasId         [in]  MAS ID.
-   * @param aHandleId      [in]  Handle ID.
-   * @param aStatus        [in]  MAP send message result.
-   * @param aRv            [out] Error result to set in case of error.
-   */
-  already_AddRefed<Promise> ReplyToSendMessage(
-    long aMasId, const nsAString& aHandleId, bool aStatus, ErrorResult& aRv);
-
-  /**
-   * Reply to message update request
-   *
-   * @param aMasId         [in]  MAS ID.
-   * @param aStatus        [in]  Update inbox results.
-   * @param aRv            [out] Error result to set in case of error.
-   */
-  already_AddRefed<Promise> ReplyToMessageUpdate(long aMasId, bool aStatus,
-                                                 ErrorResult& aRv);
-
-private:
-  BluetoothMapRequestHandle(nsPIDOMWindowInner* aOwner);
-  ~BluetoothMapRequestHandle();
-
-  nsCOMPtr<nsPIDOMWindowInner> mOwner;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothMapRequestHandle_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothObexAuthHandle.cpp
+++ /dev/null
@@ -1,96 +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 "BluetoothCommon.h"
-#include "BluetoothDevice.h"
-#include "BluetoothObexAuthHandle.h"
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-
-#include "mozilla/dom/BluetoothObexAuthHandleBinding.h"
-#include "mozilla/dom/Promise.h"
-
-using namespace mozilla;
-using namespace dom;
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(BluetoothObexAuthHandle, mOwner)
-NS_IMPL_CYCLE_COLLECTING_ADDREF(BluetoothObexAuthHandle)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(BluetoothObexAuthHandle)
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BluetoothObexAuthHandle)
-  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
-
-BluetoothObexAuthHandle::BluetoothObexAuthHandle(nsPIDOMWindowInner* aOwner)
-  : mOwner(aOwner)
-{
-  MOZ_ASSERT(aOwner);
-}
-
-BluetoothObexAuthHandle::~BluetoothObexAuthHandle()
-{
-}
-
-already_AddRefed<BluetoothObexAuthHandle>
-BluetoothObexAuthHandle::Create(nsPIDOMWindowInner* aOwner)
-{
-  MOZ_ASSERT(aOwner);
-
-  RefPtr<BluetoothObexAuthHandle> handle =
-    new BluetoothObexAuthHandle(aOwner);
-
-  return handle.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothObexAuthHandle::SetPassword(const nsAString& aPassword, ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  bs->SetObexPassword(aPassword,
-                      new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothObexAuthHandle::Reject(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  bs->RejectObexAuth(new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-JSObject*
-BluetoothObexAuthHandle::WrapObject(JSContext* aCx,
-                                    JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothObexAuthHandleBinding::Wrap(aCx, this, aGivenProto);
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothObexAuthHandle.h
+++ /dev/null
@@ -1,57 +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_BluetoothObexAuthHandle_h
-#define mozilla_dom_bluetooth_BluetoothObexAuthHandle_h
-
-#include "BluetoothCommon.h"
-#include "nsPIDOMWindow.h"
-#include "nsWrapperCache.h"
-
-namespace mozilla {
-class ErrorResult;
-namespace dom {
-class Promise;
-}
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothObexAuthHandle final : public nsISupports
-                                    , public nsWrapperCache
-{
-public:
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(BluetoothObexAuthHandle)
-
-  static already_AddRefed<BluetoothObexAuthHandle>
-    Create(nsPIDOMWindowInner* aOwner);
-
-  nsPIDOMWindowInner* GetParentObject() const
-  {
-    return mOwner;
-  }
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-
-  // Set password to the OBEX authentication request
-  already_AddRefed<Promise>
-    SetPassword(const nsAString& aPassword, ErrorResult& aRv);
-
-  // Reject the OBEX authentication request
-  already_AddRefed<Promise> Reject(ErrorResult& aRv);
-
-private:
-  BluetoothObexAuthHandle(nsPIDOMWindowInner* aOwner);
-  ~BluetoothObexAuthHandle();
-
-  nsCOMPtr<nsPIDOMWindowInner> mOwner;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothObexAuthHandle_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothPairingHandle.cpp
+++ /dev/null
@@ -1,202 +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 "BluetoothCommon.h"
-#include "BluetoothDevice.h"
-#include "BluetoothPairingHandle.h"
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-#include "BluetoothUtils.h"
-
-#include "mozilla/dom/BluetoothPairingHandleBinding.h"
-#include "mozilla/dom/Promise.h"
-
-using namespace mozilla;
-using namespace dom;
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(BluetoothPairingHandle, mOwner)
-NS_IMPL_CYCLE_COLLECTING_ADDREF(BluetoothPairingHandle)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(BluetoothPairingHandle)
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BluetoothPairingHandle)
-  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
-
-BluetoothPairingHandle::BluetoothPairingHandle(nsPIDOMWindowInner* aOwner,
-                                               const nsAString& aDeviceAddress,
-                                               const nsAString& aType,
-                                               const nsAString& aPasskey)
-  : mOwner(aOwner)
-  , mDeviceAddress(aDeviceAddress)
-  , mType(aType)
-  , mPasskey(aPasskey)
-{
-  MOZ_ASSERT(aOwner && !aDeviceAddress.IsEmpty() && !aType.IsEmpty());
-
-  if (aType.EqualsLiteral(PAIRING_REQ_TYPE_DISPLAYPASSKEY) ||
-      aType.EqualsLiteral(PAIRING_REQ_TYPE_CONFIRMATION)) {
-    MOZ_ASSERT(!aPasskey.IsEmpty());
-  } else {
-    MOZ_ASSERT(aPasskey.IsEmpty());
-  }
-}
-
-BluetoothPairingHandle::~BluetoothPairingHandle()
-{
-}
-
-already_AddRefed<BluetoothPairingHandle>
-BluetoothPairingHandle::Create(nsPIDOMWindowInner* aOwner,
-                               const nsAString& aDeviceAddress,
-                               const nsAString& aType,
-                               const nsAString& aPasskey)
-{
-  MOZ_ASSERT(aOwner && !aDeviceAddress.IsEmpty() && !aType.IsEmpty());
-
-  RefPtr<BluetoothPairingHandle> handle =
-    new BluetoothPairingHandle(aOwner, aDeviceAddress, aType, aPasskey);
-
-  return handle.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothPairingHandle::SetPinCode(const nsAString& aPinCode, ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(mType.EqualsLiteral(PAIRING_REQ_TYPE_ENTERPINCODE),
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-
-  BluetoothAddress deviceAddress;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToAddress(mDeviceAddress,
-                                                     deviceAddress)),
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-
-  BluetoothPinCode pinCode;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToPinCode(aPinCode, pinCode)),
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  bs->PinReplyInternal(deviceAddress, true /* accept */, pinCode,
-                       new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothPairingHandle::Accept(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BT_ENSURE_TRUE_REJECT(mType.EqualsLiteral(PAIRING_REQ_TYPE_CONFIRMATION) ||
-                        mType.EqualsLiteral(PAIRING_REQ_TYPE_CONSENT),
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  BluetoothAddress deviceAddress;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToAddress(mDeviceAddress,
-                                                     deviceAddress)),
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-
-  BluetoothSspVariant variant;
-  BT_ENSURE_TRUE_REJECT(GetSspVariant(variant),
-                        promise,
-                        NS_ERROR_DOM_OPERATION_ERR);
-
-  bs->SspReplyInternal(deviceAddress, variant, true /* aAccept */,
-                       new BluetoothVoidReplyRunnable(nullptr, promise));
-
-  return promise.forget();
-}
-
-already_AddRefed<Promise>
-BluetoothPairingHandle::Reject(ErrorResult& aRv)
-{
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
-  if (!global) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  BluetoothAddress deviceAddress;
-  BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToAddress(mDeviceAddress,
-                                                     deviceAddress)),
-                        promise,
-                        NS_ERROR_DOM_INVALID_STATE_ERR);
-
-  BluetoothService* bs = BluetoothService::Get();
-  BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
-  if (mType.EqualsLiteral(PAIRING_REQ_TYPE_ENTERPINCODE)) { // Pin request
-    bs->PinReplyInternal(deviceAddress, false /* aAccept */,
-                         BluetoothPinCode(),
-                         new BluetoothVoidReplyRunnable(nullptr, promise));
-  } else { // Ssp request
-    BluetoothSspVariant variant;
-    BT_ENSURE_TRUE_REJECT(GetSspVariant(variant),
-                          promise,
-                          NS_ERROR_DOM_OPERATION_ERR);
-
-    bs->SspReplyInternal(deviceAddress, variant, false /* aAccept */,
-                         new BluetoothVoidReplyRunnable(nullptr, promise));
-  }
-
-  return promise.forget();
-}
-
-bool
-BluetoothPairingHandle::GetSspVariant(BluetoothSspVariant& aVariant)
-{
-  if (mType.EqualsLiteral(PAIRING_REQ_TYPE_DISPLAYPASSKEY)) {
-    aVariant = BluetoothSspVariant::SSP_VARIANT_PASSKEY_NOTIFICATION;
-  } else if (mType.EqualsLiteral(PAIRING_REQ_TYPE_CONFIRMATION)) {
-    aVariant = BluetoothSspVariant::SSP_VARIANT_PASSKEY_CONFIRMATION;
-  } else if (mType.EqualsLiteral(PAIRING_REQ_TYPE_CONSENT)) {
-    aVariant = BluetoothSspVariant::SSP_VARIANT_CONSENT;
-  } else {
-    BT_LOGR("Invalid SSP variant name: %s",
-            NS_ConvertUTF16toUTF8(mType).get());
-    aVariant = SSP_VARIANT_PASSKEY_CONFIRMATION; // silences compiler warning
-    return false;
-  }
-
-  return true;
-}
-
-JSObject*
-BluetoothPairingHandle::WrapObject(JSContext* aCx,
-                                   JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothPairingHandleBinding::Wrap(aCx, this, aGivenProto);
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothPairingHandle.h
+++ /dev/null
@@ -1,82 +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_BluetoothPairingHandle_h
-#define mozilla_dom_bluetooth_BluetoothPairingHandle_h
-
-#include "BluetoothCommon.h"
-#include "nsWrapperCache.h"
-
-namespace mozilla {
-class ErrorResult;
-namespace dom {
-class Promise;
-}
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothPairingHandle final : public nsISupports
-                                   , public nsWrapperCache
-{
-public:
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(BluetoothPairingHandle)
-
-  static already_AddRefed<BluetoothPairingHandle>
-    Create(nsPIDOMWindowInner* aOwner,
-           const nsAString& aDeviceAddress,
-           const nsAString& aType,
-           const nsAString& aPasskey);
-
-  nsPIDOMWindowInner* GetParentObject() const
-  {
-    return mOwner;
-  }
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-
-  void GetPasskey(nsString& aPasskey) const
-  {
-    aPasskey = mPasskey;
-  }
-
-  // Reply to the enterpincodereq pairing request
-  already_AddRefed<Promise>
-    SetPinCode(const nsAString& aPinCode, ErrorResult& aRv);
-
-  // Accept the pairingconfirmationreq or pairingconsentreq pairing request
-  already_AddRefed<Promise> Accept(ErrorResult& aRv);
-
-  // Reject the pairing request
-  already_AddRefed<Promise> Reject(ErrorResult& aRv);
-
-private:
-  BluetoothPairingHandle(nsPIDOMWindowInner* aOwner,
-                         const nsAString& aDeviceAddress,
-                         const nsAString& aType,
-                         const nsAString& aPasskey);
-  ~BluetoothPairingHandle();
-
-  /**
-   * Map mType into a BluetoothSspVariant enum value.
-   *
-   * @param aVariant [out] BluetoothSspVariant value mapped from mType.
-   * @return a boolean value to indicate whether mType can map into a
-   *         BluetoothSspVariant value.
-   */
-  bool GetSspVariant(BluetoothSspVariant& aVariant);
-
-  nsCOMPtr<nsPIDOMWindowInner> mOwner;
-  nsString mDeviceAddress;
-  nsString mType;
-  nsString mPasskey;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothPairingHandle_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothPairingListener.cpp
+++ /dev/null
@@ -1,163 +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 "BluetoothService.h"
-#include "BluetoothUtils.h"
-#include "mozilla/dom/bluetooth/BluetoothPairingListener.h"
-#include "mozilla/dom/bluetooth/BluetoothPairingHandle.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/dom/BluetoothPairingEvent.h"
-#include "mozilla/dom/BluetoothPairingListenerBinding.h"
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BluetoothPairingListener)
-NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
-
-NS_IMPL_ADDREF_INHERITED(BluetoothPairingListener, DOMEventTargetHelper)
-NS_IMPL_RELEASE_INHERITED(BluetoothPairingListener, DOMEventTargetHelper)
-
-BluetoothPairingListener::BluetoothPairingListener(nsPIDOMWindowInner* aWindow)
-  : DOMEventTargetHelper(aWindow)
-  , mHasListenedToSignal(false)
-{
-  MOZ_ASSERT(aWindow);
-
-  TryListeningToBluetoothSignal();
-}
-
-already_AddRefed<BluetoothPairingListener>
-BluetoothPairingListener::Create(nsPIDOMWindowInner* aWindow)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aWindow);
-
-  RefPtr<BluetoothPairingListener> handle =
-    new BluetoothPairingListener(aWindow);
-
-  return handle.forget();
-}
-
-BluetoothPairingListener::~BluetoothPairingListener()
-{
-  UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_PAIRING_LISTENER),
-                                   this);
-}
-
-void
-BluetoothPairingListener::DispatchPairingEvent(
-  const BluetoothRemoteName& aName,
-  const BluetoothAddress& aAddress,
-  const nsAString& aPasskey,
-  const nsAString& aType)
-{
-  MOZ_ASSERT(!aAddress.IsCleared());
-  MOZ_ASSERT(!aName.IsCleared() && !aType.IsEmpty());
-
-  nsString nameStr;
-  RemoteNameToString(aName, nameStr);
-
-  nsString addressStr;
-  AddressToString(aAddress, addressStr);
-
-  RefPtr<BluetoothPairingHandle> handle =
-    BluetoothPairingHandle::Create(GetOwner(),
-                                   addressStr,
-                                   aType,
-                                   aPasskey);
-
-  BluetoothPairingEventInit init;
-  init.mDeviceName = nameStr;
-  init.mHandle = handle;
-
-  RefPtr<BluetoothPairingEvent> event =
-    BluetoothPairingEvent::Constructor(this,
-                                       aType,
-                                       init);
-
-  DispatchTrustedEvent(event);
-}
-
-void
-BluetoothPairingListener::Notify(const BluetoothSignal& aData)
-{
-  InfallibleTArray<BluetoothNamedValue> arr;
-
-  BluetoothValue value = aData.value();
-  if (aData.name().EqualsLiteral("PairingRequest")) {
-
-    MOZ_ASSERT(value.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
-
-    const InfallibleTArray<BluetoothNamedValue>& arr =
-      value.get_ArrayOfBluetoothNamedValue();
-
-    MOZ_ASSERT(arr.Length() == 4 &&
-               arr[0].value().type() == BluetoothValue::TBluetoothAddress && // address
-               arr[1].value().type() == BluetoothValue::TBluetoothRemoteName && // name
-               arr[2].value().type() == BluetoothValue::TnsString && // passkey
-               arr[3].value().type() == BluetoothValue::TnsString);  // type
-
-    BluetoothAddress address = arr[0].value().get_BluetoothAddress();
-    const BluetoothRemoteName& name = arr[1].value().get_BluetoothRemoteName();
-    nsString passkey = arr[2].value().get_nsString();
-    nsString type = arr[3].value().get_nsString();
-
-    // Notify pairing listener of pairing requests
-    DispatchPairingEvent(name, address, passkey, type);
-  } else {
-    BT_WARNING("Not handling pairing listener signal: %s",
-               NS_ConvertUTF16toUTF8(aData.name()).get());
-  }
-}
-
-JSObject*
-BluetoothPairingListener::WrapObject(JSContext* aCx,
-                                     JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothPairingListenerBinding::Wrap(aCx, this, aGivenProto);
-}
-
-void
-BluetoothPairingListener::DisconnectFromOwner()
-{
-  DOMEventTargetHelper::DisconnectFromOwner();
-  UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_PAIRING_LISTENER),
-                                   this);
-}
-
-void
-BluetoothPairingListener::EventListenerAdded(nsIAtom* aType)
-{
-  DOMEventTargetHelper::EventListenerAdded(aType);
-
-  TryListeningToBluetoothSignal();
-}
-
-void
-BluetoothPairingListener::TryListeningToBluetoothSignal()
-{
-  if (mHasListenedToSignal) {
-    // We've handled prior pending pairing requests
-    return;
-  }
-
-  // Listen to bluetooth signal only if all pairing event handlers have been
-  // attached. All pending pairing requests queued in BluetoothService would
-  // be fired when pairing listener starts listening to bluetooth signal.
-  if (!HasListenersFor(nsGkAtoms::ondisplaypasskeyreq) ||
-      !HasListenersFor(nsGkAtoms::onenterpincodereq) ||
-      !HasListenersFor(nsGkAtoms::onpairingconfirmationreq) ||
-      !HasListenersFor(nsGkAtoms::onpairingconsentreq)) {
-    BT_LOGD("Pairing listener is not ready to handle pairing requests!");
-    return;
-  }
-
-  // Start listening to bluetooth signal to handle pairing requests
-  RegisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_PAIRING_LISTENER),
-                                 this);
-
-  mHasListenedToSignal = true;
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothPairingListener.h
+++ /dev/null
@@ -1,71 +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_BluetoothPairingListener_h
-#define mozilla_dom_bluetooth_BluetoothPairingListener_h
-
-#include "BluetoothCommon.h"
-#include "mozilla/Attributes.h"
-#include "mozilla/DOMEventTargetHelper.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothSignal;
-
-class BluetoothPairingListener final : public DOMEventTargetHelper
-                                     , public BluetoothSignalObserver
-{
-public:
-  NS_DECL_ISUPPORTS_INHERITED
-
-  static already_AddRefed<BluetoothPairingListener>
-    Create(nsPIDOMWindowInner* aWindow);
-
-  void DispatchPairingEvent(const BluetoothRemoteName& aName,
-                            const BluetoothAddress& aAddress,
-                            const nsAString& aPasskey,
-                            const nsAString& aType);
-
-  void Notify(const BluetoothSignal& aParam); // BluetoothSignalObserver
-
-  nsPIDOMWindowInner* GetParentObject() const
-  {
-    return GetOwner();
-  }
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-  virtual void DisconnectFromOwner() override;
-  virtual void EventListenerAdded(nsIAtom* aType) override;
-
-  IMPL_EVENT_HANDLER(displaypasskeyreq);
-  IMPL_EVENT_HANDLER(enterpincodereq);
-  IMPL_EVENT_HANDLER(pairingconfirmationreq);
-  IMPL_EVENT_HANDLER(pairingconsentreq);
-
-private:
-  BluetoothPairingListener(nsPIDOMWindowInner* aWindow);
-  ~BluetoothPairingListener();
-
-  /**
-   * Listen to bluetooth signal if all pairing event handlers are ready.
-   *
-   * Listen to bluetooth signal only if all pairing event handlers have been
-   * attached. All pending pairing requests queued in BluetoothService would be
-   * fired when pairing listener starts listening to bluetooth signal.
-   */
-  void TryListeningToBluetoothSignal();
-
-  /**
-   * Indicate whether or not this pairing listener has started listening to
-   * Bluetooth signal.
-   */
-  bool mHasListenedToSignal;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_BluetoothPairingListener_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothPbapRequestHandle.cpp
+++ /dev/null
@@ -1,182 +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 "BluetoothCommon.h"
-#include "BluetoothPbapRequestHandle.h"
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-
-#include "mozilla/dom/BluetoothPbapRequestHandleBinding.h"
-#include "mozilla/dom/ContentChild.h"
-
-using namespace mozilla;
-using namespace dom;
-
-USING_BLUETOOTH_NAMESPACE
-
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(BluetoothPbapRequestHandle, mOwner)
-NS_IMPL_CYCLE_COLLECTING_ADDREF(BluetoothPbapRequestHandle)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(BluetoothPbapRequestHandle)
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BluetoothPbapRequestHandle)
-  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
-
-BluetoothPbapRequestHandle::BluetoothPbapRequestHandle(nsPIDOMWindowInner* aOwner)
-  : mOwner(aOwner)
-{
-  MOZ_ASSERT(aOwner);
-}
-
-BluetoothPbapRequestHandle::~BluetoothPbapRequestHandle()
-{
-}
-
-already_AddRefed<BluetoothPbapRequestHandle>
-BluetoothPbapRequestHandle::Create(nsPIDOMWindowInner* aOwner)
-{
-  MOZ_ASSERT(aOwner);
-
-  RefPtr<BluetoothPbapRequestHandle> handle =
-    new BluetoothPbapRequestHandle(aOwner);
-
-  return handle.forget();
-}
-
-already_AddRefed<DOMRequest>
-BluetoothPbapRequestHandle::ReplyTovCardPulling(Blob& aBlob,
-                                                ErrorResult& aRv)
-{
-  nsCOMPtr<nsPIDOMWindowInner> win = GetParentObject();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothVoidReplyRunnable> result =
-    new BluetoothVoidReplyRunnable(request);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  if (XRE_GetProcessType() == GeckoProcessType_Default) {
-    // In-process reply
-    bs->ReplyTovCardPulling(&aBlob, result);
-  } else {
-    ContentChild *cc = ContentChild::GetSingleton();
-    if (!cc) {
-      aRv.Throw(NS_ERROR_FAILURE);
-      return nullptr;
-    }
-
-    BlobChild* actor = cc->GetOrCreateActorForBlob(&aBlob);
-    if (!actor) {
-      aRv.Throw(NS_ERROR_FAILURE);
-      return nullptr;
-    }
-
-    bs->ReplyTovCardPulling(nullptr, actor, result);
-  }
-
-  return request.forget();
-}
-
-already_AddRefed<DOMRequest>
-BluetoothPbapRequestHandle::ReplyToPhonebookPulling(Blob& aBlob,
-                                                    uint16_t phonebookSize,
-                                                    ErrorResult& aRv)
-{
-  nsCOMPtr<nsPIDOMWindowInner> win = GetParentObject();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothVoidReplyRunnable> result =
-    new BluetoothVoidReplyRunnable(request);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  if (XRE_GetProcessType() == GeckoProcessType_Default) {
-    // In-process reply
-    bs->ReplyToPhonebookPulling(&aBlob, phonebookSize, result);
-  } else {
-    ContentChild *cc = ContentChild::GetSingleton();
-    if (!cc) {
-      aRv.Throw(NS_ERROR_FAILURE);
-      return nullptr;
-    }
-
-    BlobChild* actor = cc->GetOrCreateActorForBlob(&aBlob);
-    if (!actor) {
-      aRv.Throw(NS_ERROR_FAILURE);
-      return nullptr;
-    }
-
-    bs->ReplyToPhonebookPulling(nullptr, actor, phonebookSize, result);
-  }
-
-  return request.forget();
-}
-
-already_AddRefed<DOMRequest>
-BluetoothPbapRequestHandle::ReplyTovCardListing(Blob& aBlob,
-                                                uint16_t phonebookSize,
-                                                ErrorResult& aRv)
-{
-  nsCOMPtr<nsPIDOMWindowInner> win = GetParentObject();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  RefPtr<DOMRequest> request = new DOMRequest(win);
-  RefPtr<BluetoothVoidReplyRunnable> result =
-    new BluetoothVoidReplyRunnable(request);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  if (XRE_GetProcessType() == GeckoProcessType_Default) {
-    // In-process reply
-    bs->ReplyTovCardListing(&aBlob, phonebookSize, result);
-  } else {
-    ContentChild *cc = ContentChild::GetSingleton();
-    if (!cc) {
-      aRv.Throw(NS_ERROR_FAILURE);
-      return nullptr;
-    }
-
-    BlobChild* actor = cc->GetOrCreateActorForBlob(&aBlob);
-    if (!actor) {
-      aRv.Throw(NS_ERROR_FAILURE);
-      return nullptr;
-    }
-
-    bs->ReplyTovCardListing(nullptr, actor, phonebookSize, result);
-  }
-
-  return request.forget();
-}
-
-JSObject*
-BluetoothPbapRequestHandle::WrapObject(JSContext* aCx,
-                                   JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothPbapRequestHandleBinding::Wrap(aCx, this, aGivenProto);
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothPbapRequestHandle.h
+++ /dev/null
@@ -1,62 +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_bluetoothpbaprequesthandle_h
-#define mozilla_dom_bluetooth_bluetoothpbaprequesthandle_h
-
-#include "nsCOMPtr.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/DOMRequest.h"
-
-namespace mozilla {
-  class ErrorResult;
-  namespace dom {
-    class Blob;
-    class DOMRequest;
-  }
-}
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothPbapRequestHandle final : public nsISupports
-                                       , public nsWrapperCache
-{
-public:
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(BluetoothPbapRequestHandle)
-
-  static already_AddRefed<BluetoothPbapRequestHandle>
-    Create(nsPIDOMWindowInner* aOwner);
-
-  nsPIDOMWindowInner* GetParentObject() const
-  {
-    return mOwner;
-  }
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-
-  already_AddRefed<DOMRequest> ReplyTovCardPulling(Blob& aBlob,
-                                                   ErrorResult& aRv);
-
-  already_AddRefed<DOMRequest> ReplyToPhonebookPulling(Blob& aBlob,
-                                                       uint16_t phonebookSize,
-                                                       ErrorResult& aRv);
-
-  already_AddRefed<DOMRequest> ReplyTovCardListing(Blob& aBlob,
-                                                   uint16_t phonebookSize,
-                                                   ErrorResult& aRv);
-
-private:
-  BluetoothPbapRequestHandle(nsPIDOMWindowInner* aOwner);
-  ~BluetoothPbapRequestHandle();
-
-  nsCOMPtr<nsPIDOMWindowInner> mOwner;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_bluetoothpbaprequesthandle_h
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothUUID.cpp
+++ /dev/null
@@ -1,234 +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 "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/bluetooth/BluetoothGattUUIDName.h"
-#include "mozilla/dom/BluetoothUUID.h"
-#include "mozilla/dom/UnionTypes.h" /* StringOrUnsignedLong */
-
-
-using namespace mozilla;
-using namespace mozilla::dom;
-
-bool BluetoothUUID::sInShutdown = false;
-// static
-nsDataHashtable<nsStringHashKey, uint32_t>*
-  BluetoothUUID::sUUIDServiceTable;
-// static
-nsDataHashtable<nsStringHashKey, uint32_t>*
-  BluetoothUUID::sUUIDCharacteristicTable;
-// static
-nsDataHashtable<nsStringHashKey, uint32_t>*
-  BluetoothUUID::sUUIDDescriptorTable;
-
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(BluetoothUUID, mOwner)
-NS_IMPL_CYCLE_COLLECTING_ADDREF(BluetoothUUID)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(BluetoothUUID)
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BluetoothUUID)
-  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
-
-BluetoothUUID::BluetoothUUID(nsPIDOMWindowInner* aOwner)
-  : mOwner(aOwner)
-{
-  MOZ_ASSERT(aOwner);
-}
-
-BluetoothUUID::~BluetoothUUID()
-{
-}
-
-JSObject*
-BluetoothUUID::WrapObject(JSContext* aCx,
-                          JS::Handle<JSObject*> aGivenProto)
-{
-  return BluetoothUUIDBinding::Wrap(aCx, this, aGivenProto);
-}
-
-//static
-void BluetoothUUID::HandleShutdown()
-{
-  sInShutdown = true;
-  delete sUUIDServiceTable;
-  delete sUUIDCharacteristicTable;
-  delete sUUIDDescriptorTable;
-  sUUIDServiceTable = nullptr;
-  sUUIDCharacteristicTable = nullptr;
-  sUUIDDescriptorTable = nullptr;
-}
-
-// static
-void
-BluetoothUUID::InitServiceTable()
-{
-  size_t length = sizeof(ServiceTable) / sizeof(BluetoothGattUUIDName);
-  for (size_t i = 0; i < length; ++i) {
-    sUUIDServiceTable->Put(NS_ConvertUTF8toUTF16(ServiceTable[i].name),
-                           ServiceTable[i].uuid);
-  }
-}
-
-// static
-void
-BluetoothUUID::InitCharacteristicTable()
-{
-  size_t length = sizeof(CharacteristicTable) / sizeof(BluetoothGattUUIDName);
-  for (size_t i = 0; i < length; ++i) {
-    sUUIDCharacteristicTable->Put(NS_ConvertUTF8toUTF16(
-                                    CharacteristicTable[i].name),
-                                  CharacteristicTable[i].uuid);
-  }
-}
-
-// static
-void
-BluetoothUUID::InitDescriptorTable()
-{
-  size_t length = sizeof(DescriptorTable) / sizeof(BluetoothGattUUIDName);
-  for (size_t i = 0; i < length; ++i) {
-    sUUIDDescriptorTable->Put(NS_ConvertUTF8toUTF16(DescriptorTable[i].name),
-                              DescriptorTable[i].uuid);
-  }
-}
-
-/**
- * Check whether the UUID(aString) is valid or not
- */
-bool IsValidUUID(const nsAString& aString)
-{
-  size_t length = aString.Length();
-  if (length != 36) {
-    return false;
-  }
-
-  const char16_t* uuid = aString.BeginReading();
-
-  for (size_t i = 0; i < length; ++i) {
-    if (i == 8 || i == 13 || i == 18 || i == 23) {
-      if (uuid[i] != '-') {
-        return false;
-      }
-    } else if ((uuid[i] < '0' || uuid[i] > '9') &&
-               (uuid[i] < 'a' || uuid[i] > 'f')) {
-      return false;
-    }
-  }
-
-  return true;
-}
-
-// static
-void
-BluetoothUUID::ResolveUUIDName(const GlobalObject& aGlobal,
-                               const StringOrUnsignedLong& aName,
-                               GattAttribute aAttr, nsAString& aReturn,
-                               ErrorResult& aRv)
-{
-  aReturn.Truncate();
-
-  if (aName.IsUnsignedLong()) {
-    // aName is a 16-bit or 32-bit UUID alias.
-    CanonicalUUID(aGlobal, aName.GetAsUnsignedLong(), aReturn);
-  } else if (aName.IsString()) {
-    uint32_t alias = 0;
-    nsString aString(aName.GetAsString());
-
-    if (IsValidUUID(aString)) {
-      // aName is a valid UUID String.
-      aReturn.Assign(aString);
-    } else if (GetTable(aAttr, aString, alias)) {
-      // The UUID string can be mapped to a known UUID alias.
-      CanonicalUUID(aGlobal, alias, aReturn);
-    } else {
-      // Exception, Syntax error, assign aReturn the error message
-      aRv.ThrowDOMException(NS_ERROR_DOM_SYNTAX_ERR,
-                            NS_LITERAL_CSTRING("Invalid name: It can be a"
-                              " 32-bit UUID alias, 128-bit valid UUID "
-                              "(lower-case hex characters) or known "
-                              "Service/Characteristic/Descriptor name."));
-
-      return ;
-    }
-  } else {
-    MOZ_ASSERT(false, "Invalid name: It can be a 32-bit UUID alias, 128-bit "
-                      "valid UUID (lower-case hex characters) or known "
-                      "Service/Characteristic/Descriptor name.");
-  }
-}
-
-// static
-bool
-BluetoothUUID::GetTable(GattAttribute aAttr, const nsAString& aString,
-                        uint32_t& aAlias)
-{
-  // If we're in shutdown, don't create a new instance.
-  NS_ENSURE_FALSE(sInShutdown, false);
-
-  nsDataHashtable<nsStringHashKey, uint32_t>** tableSlot;
-
-  if (aAttr == SERVICE) {
-    tableSlot = &sUUIDServiceTable;
-  } else if (aAttr == CHARACTERISTIC) {
-    tableSlot = &sUUIDCharacteristicTable;
-  } else if (aAttr == DESCRIPTOR) {
-    tableSlot = &sUUIDDescriptorTable;
-  }
-
-  if (!*tableSlot) {
-    (*tableSlot) = new nsDataHashtable<nsStringHashKey, uint32_t>;
-    if (aAttr == SERVICE) {
-      InitServiceTable();
-    } else if (aAttr == CHARACTERISTIC) {
-      InitCharacteristicTable();
-    } else if (aAttr == DESCRIPTOR) {
-      InitDescriptorTable();
-    }
-  }
-
-  return (*tableSlot)->Get(aString, &aAlias);
-}
-
-// static
-void
-BluetoothUUID::GetService(const GlobalObject& aGlobal,
-                          const StringOrUnsignedLong& aName,
-                          nsAString& aReturn, ErrorResult& aRv)
-{
-  ResolveUUIDName(aGlobal, aName, SERVICE, aReturn, aRv);
-}
-
-// static
-void
-BluetoothUUID::GetCharacteristic(const GlobalObject& aGlobal,
-                                 const StringOrUnsignedLong& aName,
-                                 nsAString& aReturn, ErrorResult& aRv)
-{
-  ResolveUUIDName(aGlobal, aName, CHARACTERISTIC, aReturn, aRv);
-}
-
-// static
-void
-BluetoothUUID::GetDescriptor(const GlobalObject& aGlobal,
-                             const StringOrUnsignedLong& aName,
-                             nsAString& aReturn, ErrorResult& aRv)
-{
-  ResolveUUIDName(aGlobal, aName, DESCRIPTOR, aReturn, aRv);
-}
-
-// static
-void
-BluetoothUUID::CanonicalUUID(const GlobalObject& aGlobal, uint32_t aAlias,
-                             nsAString& aReturn)
-{
-  char uuidStr[37];
-
-  // Convert to 128-bit UUID: alias + "-0000-1000-8000-00805f9b34fb".
-  snprintf(uuidStr, sizeof(uuidStr), "%.8x-0000-1000-8000-00805f9b34fb",
-           aAlias);
-
-  aReturn.AssignLiteral(uuidStr);
-}
deleted file mode 100644
--- a/dom/bluetooth/common/webapi/BluetoothUUID.h
+++ /dev/null
@@ -1,126 +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_BluetoothUUID_h
-#define mozilla_dom_BluetoothUUID_h
-
-#include "mozilla/dom/BluetoothUUIDBinding.h"
-#include "mozilla/StaticPtr.h"
-#include "nsCOMPtr.h"
-#include "nsDataHashtable.h"
-#include "nsHashKeys.h"
-#include "nsIObserver.h"
-#include "nsPIDOMWindow.h"
-#include "nsWrapperCache.h"
-
-namespace mozilla {
-namespace dom {
-
-class StringOrUnsignedLong;
-
-class BluetoothUUID final : public nsISupports
-                          , public nsWrapperCache
-{
-public:
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(BluetoothUUID)
-
-  nsPIDOMWindowInner* GetParentObject() const
-  {
-    return mOwner;
-  }
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aGivenProto) override;
-
-  /**
-   * Delete sUUIDServiceTable, sUUIDCharacteristicTable, sUUIDDescriptorTable
-   * used by ResolveUUIDName(). To be called from nsLayoutStatics only.
-   */
-  static void HandleShutdown();
-
-  static void GetService(const GlobalObject& aGlobal,
-                         const StringOrUnsignedLong& aName,
-                         nsAString& aReturn, ErrorResult& aRv);
-  static void GetCharacteristic(const GlobalObject& aGlobal,
-                                const StringOrUnsignedLong& aName,
-                                nsAString& aReturn, ErrorResult& aRv);
-  static void GetDescriptor(const GlobalObject& aGlobal,
-                            const StringOrUnsignedLong& aName,
-                            nsAString& aReturn, ErrorResult& aRv);
-
-  static void CanonicalUUID(const GlobalObject& aGlobal, uint32_t aAlias,
-                            nsAString& aReturn);
-
-private:
-  BluetoothUUID(nsPIDOMWindowInner* aOwner);
-  ~BluetoothUUID();
-
-  static void InitServiceTable();
-  static void InitCharacteristicTable();
-  static void InitDescriptorTable();
-
-  enum GattAttribute {
-    SERVICE,
-    CHARACTERISTIC,
-    DESCRIPTOR
-  };
-
-  /**
-   * Convert an UUID string or 16-bit/32-bit UUID alias to a 128-bit UUID based
-   * on its bluetooth attribute.
-   *
-   * @param aGlobal [in] a Global object for static attributes. We have this
-   *                     argument because it needs to call |CanonicalUUID|.
-   * @param aName   [in] an UUID string or 16-bit/32-bit UUID alias.
-   * @param aAttr   [in] a GATT Attribute type.
-   * @param aReturn [out] a 128-bit UUID.
-   */
-  static void ResolveUUIDName(const GlobalObject& aGlobal,
-                              const StringOrUnsignedLong& aName,
-                              GattAttribute aAttr, nsAString& aReturn,
-                              ErrorResult& aRv);
-
-  /**
-   * Get the GATT attribute table based on the GATT attribute and check whether
-   * the UUID string can be mapped to a known alias.
-   *
-   * @param aAttr   [in] a GATT Attribute type.
-   * @param aString [in] an UUID string.
-   * @param aAlias  [out] a known UUID alias if success.
-   * @return success if a UUID string can be mapped in table, fail if it
-   *         cannot.
-   */
-  static bool GetTable(GattAttribute aAttr, const nsAString& aString,
-                       uint32_t& aAlias);
-
-  /****************************************************************************
-   * Variables
-   ***************************************************************************/
-  nsCOMPtr<nsPIDOMWindowInner> mOwner;
-
-  static bool sInShutdown;
-
-  /**
-   * Hash Table of services for mapping service names to its UUID's prefix.
-   */
-  static nsDataHashtable<nsStringHashKey, uint32_t>* sUUIDServiceTable;
-
-  /**
-   * Hash Table of characteristics for mapping characteristic names to its UUID's prefix.
-   */
-  static nsDataHashtable<nsStringHashKey, uint32_t>* sUUIDCharacteristicTable;
-
-  /**
-   * Hash Table of descriptors for mapping descriptor names to its UUID's prefix.
-   */
-  static nsDataHashtable<nsStringHashKey, uint32_t>* sUUIDDescriptorTable;
-};
-
-} // dom
-} // mozilla
-
-#endif // mozilla_dom_BluetoothUUID_h
deleted file mode 100644
--- a/dom/bluetooth/ipc/BluetoothChild.cpp
+++ /dev/null
@@ -1,173 +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 "base/basictypes.h"
-
-#include "BluetoothChild.h"
-
-#include "mozilla/Assertions.h"
-#include "nsDebug.h"
-#include "nsISupportsImpl.h"
-#include "nsThreadUtils.h"
-
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-#include "BluetoothServiceChildProcess.h"
-
-USING_BLUETOOTH_NAMESPACE
-
-namespace {
-
-BluetoothServiceChildProcess* sBluetoothService;
-
-} // namespace
-
-/*******************************************************************************
- * BluetoothChild
- ******************************************************************************/
-
-BluetoothChild::BluetoothChild(BluetoothServiceChildProcess* aBluetoothService)
-: mShutdownState(Running)
-{
-  MOZ_COUNT_CTOR(BluetoothChild);
-  MOZ_ASSERT(!sBluetoothService);
-  MOZ_ASSERT(aBluetoothService);
-
-  sBluetoothService = aBluetoothService;
-}
-
-BluetoothChild::~BluetoothChild()
-{
-  MOZ_COUNT_DTOR(BluetoothChild);
-  MOZ_ASSERT(sBluetoothService);
-  MOZ_ASSERT(mShutdownState == Dead);
-
-  sBluetoothService = nullptr;
-}
-
-void
-BluetoothChild::BeginShutdown()
-{
-  // Only do something here if we haven't yet begun the shutdown sequence.
-  if (mShutdownState == Running) {
-    SendStopNotifying();
-    mShutdownState = SentStopNotifying;
-  }
-}
-
-void
-BluetoothChild::ActorDestroy(ActorDestroyReason aWhy)
-{
-  MOZ_ASSERT(sBluetoothService);
-
-  sBluetoothService->NoteDeadActor();
-
-#ifdef DEBUG
-  mShutdownState = Dead;
-#endif
-}
-
-bool
-BluetoothChild::RecvNotify(const BluetoothSignal& aSignal)
-{
-  MOZ_ASSERT(sBluetoothService);
-
-  if (sBluetoothService) {
-    sBluetoothService->DistributeSignal(aSignal);
-  }
-  return true;
-}
-
-bool
-BluetoothChild::RecvEnabled(const bool& aEnabled)
-{
-  MOZ_ASSERT(sBluetoothService);
-
-  if (sBluetoothService) {
-    sBluetoothService->SetEnabled(aEnabled);
-  }
-  return true;
-}
-
-bool
-BluetoothChild::RecvBeginShutdown()
-{
-  if (mShutdownState != Running && mShutdownState != SentStopNotifying) {
-    MOZ_ASSERT(false, "Bad state!");
-    return false;
-  }
-
-  SendStopNotifying();
-  mShutdownState = SentStopNotifying;
-
-  return true;
-}
-
-bool
-BluetoothChild::RecvNotificationsStopped()
-{
-  if (mShutdownState != SentStopNotifying) {
-    MOZ_ASSERT(false, "Bad state!");
-    return false;
-  }
-
-  Send__delete__(this);
-  return true;
-}
-
-PBluetoothRequestChild*
-BluetoothChild::AllocPBluetoothRequestChild(const Request& aRequest)
-{
-  MOZ_CRASH("Caller is supposed to manually construct a request!");
-}
-
-bool
-BluetoothChild::DeallocPBluetoothRequestChild(PBluetoothRequestChild* aActor)
-{
-  delete aActor;
-  return true;
-}
-
-/*******************************************************************************
- * BluetoothRequestChild
- ******************************************************************************/
-
-BluetoothRequestChild::BluetoothRequestChild(
-                                         BluetoothReplyRunnable* aReplyRunnable)
-: mReplyRunnable(aReplyRunnable)
-{
-  MOZ_COUNT_CTOR(BluetoothRequestChild);
-  MOZ_ASSERT(aReplyRunnable);
-}
-
-BluetoothRequestChild::~BluetoothRequestChild()
-{
-  MOZ_COUNT_DTOR(BluetoothRequestChild);
-}
-
-void
-BluetoothRequestChild::ActorDestroy(ActorDestroyReason aWhy)
-{
-  // Nothing needed here.
-}
-
-bool
-BluetoothRequestChild::Recv__delete__(const BluetoothReply& aReply)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mReplyRunnable);
-
-  RefPtr<BluetoothReplyRunnable> replyRunnable;
-  mReplyRunnable.swap(replyRunnable);
-
-  if (replyRunnable) {
-    // XXXbent Need to fix this, it copies unnecessarily.
-    replyRunnable->SetReply(new BluetoothReply(aReply));
-    return NS_SUCCEEDED(NS_DispatchToCurrentThread(replyRunnable));
-  }
-
-  return true;
-}
deleted file mode 100644
--- a/dom/bluetooth/ipc/BluetoothChild.h
+++ /dev/null
@@ -1,102 +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_ipc_BluetoothChild_h
-#define mozilla_dom_bluetooth_ipc_BluetoothChild_h
-
-#include "mozilla/Attributes.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/bluetooth/BluetoothTypes.h"
-#include "mozilla/dom/bluetooth/PBluetoothChild.h"
-#include "mozilla/dom/bluetooth/PBluetoothRequestChild.h"
-
-namespace mozilla {
-namespace dom {
-namespace bluetooth {
-
-class BluetoothServiceChildProcess;
-
-} // namespace bluetooth
-} // namespace dom
-} // namespace mozilla
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothReplyRunnable;
-
-/*******************************************************************************
- * BluetoothChild
- ******************************************************************************/
-
-class BluetoothChild : public PBluetoothChild
-{
-  friend class mozilla::dom::bluetooth::BluetoothServiceChildProcess;
-
-  enum ShutdownState
-  {
-    Running = 0,
-    SentStopNotifying,
-    ReceivedNotificationsStopped,
-    Dead
-  };
-
-  ShutdownState mShutdownState;
-
-protected:
-  BluetoothChild(BluetoothServiceChildProcess* aBluetoothService);
-  virtual ~BluetoothChild();
-
-  void
-  BeginShutdown();
-
-  virtual void
-  ActorDestroy(ActorDestroyReason aWhy) override;
-
-  virtual bool
-  RecvNotify(const BluetoothSignal& aSignal);
-
-  virtual bool
-  RecvEnabled(const bool& aEnabled) override;
-
-  virtual bool
-  RecvBeginShutdown() override;
-
-  virtual bool
-  RecvNotificationsStopped() override;
-
-  virtual PBluetoothRequestChild*
-  AllocPBluetoothRequestChild(const Request& aRequest) override;
-
-  virtual bool
-  DeallocPBluetoothRequestChild(PBluetoothRequestChild* aActor) override;
-};
-
-/*******************************************************************************
- * BluetoothRequestChild
- ******************************************************************************/
-
-class BluetoothRequestChild : public PBluetoothRequestChild
-{
-  friend class mozilla::dom::bluetooth::BluetoothChild;
-
-  RefPtr<BluetoothReplyRunnable> mReplyRunnable;
-
-public:
-  BluetoothRequestChild(BluetoothReplyRunnable* aReplyRunnable);
-
-protected:
-  virtual ~BluetoothRequestChild();
-
-  virtual void
-  ActorDestroy(ActorDestroyReason aWhy) override;
-
-  virtual bool
-  Recv__delete__(const BluetoothReply& aReply) override;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_ipc_BluetoothChild_h
deleted file mode 100644
--- a/dom/bluetooth/ipc/BluetoothMessageUtils.h
+++ /dev/null
@@ -1,380 +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_ipc_BluetoothMessageUtils_h
-#define mozilla_dom_bluetooth_ipc_BluetoothMessageUtils_h
-
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "ipc/IPCMessageUtils.h"
-
-namespace IPC {
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothAddress>
-{
-  typedef mozilla::dom::bluetooth::BluetoothAddress paramType;
-
-  static void Write(Message* aMsg, const paramType& aParam)
-  {
-    for (size_t i = 0; i < MOZ_ARRAY_LENGTH(aParam.mAddr); ++i) {
-      WriteParam(aMsg, aParam.mAddr[i]);
-    }
-  }
-
-  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
-  {
-    for (size_t i = 0; i < MOZ_ARRAY_LENGTH(aResult->mAddr); ++i) {
-      if (!ReadParam(aMsg, aIter, aResult->mAddr + i)) {
-        return false;
-      }
-    }
-    return true;
-  }
-};
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothObjectType>
-  : public ContiguousEnumSerializer<
-             mozilla::dom::bluetooth::BluetoothObjectType,
-             mozilla::dom::bluetooth::TYPE_MANAGER,
-             mozilla::dom::bluetooth::NUM_TYPE>
-{ };
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothPinCode>
-{
-  typedef mozilla::dom::bluetooth::BluetoothPinCode paramType;
-
-  static void Write(Message* aMsg, const paramType& aParam)
-  {
-    auto length = aParam.mLength;
-    if (length > MOZ_ARRAY_LENGTH(aParam.mPinCode)) {
-      length = MOZ_ARRAY_LENGTH(aParam.mPinCode);
-    }
-
-    WriteParam(aMsg, length);
-    for (uint8_t i = 0; i < length; ++i) {
-      WriteParam(aMsg, aParam.mPinCode[i]);
-    }
-  }
-
-  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
-  {
-    if (!ReadParam(aMsg, aIter, &aResult->mLength)) {
-      return false;
-    }
-
-    auto maxLength = MOZ_ARRAY_LENGTH(aResult->mPinCode);
-
-    if (aResult->mLength > maxLength) {
-      return false;
-    }
-    for (uint8_t i = 0; i < aResult->mLength; ++i) {
-      if (!ReadParam(aMsg, aIter, aResult->mPinCode + i)) {
-        return false;
-      }
-    }
-    for (uint8_t i = aResult->mLength; i < maxLength; ++i) {
-      aResult->mPinCode[i] = 0;
-    }
-    return true;
-  }
-};
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothRemoteName>
-{
-  typedef mozilla::dom::bluetooth::BluetoothRemoteName paramType;
-
-  static void Write(Message* aMsg, const paramType& aParam)
-  {
-    WriteParam(aMsg, aParam.mLength);
-    for (size_t i = 0; i < aParam.mLength; ++i) {
-      WriteParam(aMsg, aParam.mName[i]);
-    }
-  }
-
-  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
-  {
-    if (!ReadParam(aMsg, aIter, &aResult->mLength)) {
-      return false;
-    }
-    if (aResult->mLength > MOZ_ARRAY_LENGTH(aResult->mName)) {
-      return false;
-    }
-    for (uint8_t i = 0; i < aResult->mLength; ++i) {
-      if (!ReadParam(aMsg, aIter, aResult->mName + i)) {
-        return false;
-      }
-    }
-    return true;
-  }
-};
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothSspVariant>
-  : public ContiguousEnumSerializer<
-             mozilla::dom::bluetooth::BluetoothSspVariant,
-             mozilla::dom::bluetooth::SSP_VARIANT_PASSKEY_CONFIRMATION,
-             mozilla::dom::bluetooth::NUM_SSP_VARIANT>
-{ };
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothStatus>
-  : public ContiguousEnumSerializer<
-             mozilla::dom::bluetooth::BluetoothStatus,
-             mozilla::dom::bluetooth::STATUS_SUCCESS,
-             mozilla::dom::bluetooth::NUM_STATUS>
-{ };
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothGattWriteType>
-  : public ContiguousEnumSerializer<
-             mozilla::dom::bluetooth::BluetoothGattWriteType,
-             mozilla::dom::bluetooth::GATT_WRITE_TYPE_NO_RESPONSE,
-             mozilla::dom::bluetooth::GATT_WRITE_TYPE_END_GUARD>
-{ };
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothGattAuthReq>
-  : public ContiguousEnumSerializer<
-             mozilla::dom::bluetooth::BluetoothGattAuthReq,
-             mozilla::dom::bluetooth::GATT_AUTH_REQ_NONE,
-             mozilla::dom::bluetooth::GATT_AUTH_REQ_END_GUARD>
-{ };
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothUuid>
-{
-  typedef mozilla::dom::bluetooth::BluetoothUuid paramType;
-
-  static void Write(Message* aMsg, const paramType& aParam)
-  {
-    for (uint8_t i = 0; i < 16; i++) {
-      WriteParam(aMsg, aParam.mUuid[i]);
-    }
-  }
-
-  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
-  {
-    for (uint8_t i = 0; i < 16; i++) {
-      if (!ReadParam(aMsg, aIter, &(aResult->mUuid[i]))) {
-        return false;
-      }
-    }
-
-    return true;
-  }
-};
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothGattId>
-{
-  typedef mozilla::dom::bluetooth::BluetoothGattId paramType;
-
-  static void Write(Message* aMsg, const paramType& aParam)
-  {
-    WriteParam(aMsg, aParam.mUuid);
-    WriteParam(aMsg, aParam.mInstanceId);
-  }
-
-  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
-  {
-    if (!ReadParam(aMsg, aIter, &(aResult->mUuid)) ||
-        !ReadParam(aMsg, aIter, &(aResult->mInstanceId))) {
-      return false;
-    }
-
-    return true;
-  }
-};
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothGattServiceId>
-{
-  typedef mozilla::dom::bluetooth::BluetoothGattServiceId paramType;
-
-  static void Write(Message* aMsg, const paramType& aParam)
-  {
-    WriteParam(aMsg, aParam.mId);
-    WriteParam(aMsg, aParam.mIsPrimary);
-  }
-
-  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
-  {
-    if (!ReadParam(aMsg, aIter, &(aResult->mId)) ||
-        !ReadParam(aMsg, aIter, &(aResult->mIsPrimary))) {
-      return false;
-    }
-
-    return true;
-  }
-};
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothGattCharAttribute>
-{
-  typedef mozilla::dom::bluetooth::BluetoothGattCharAttribute paramType;
-
-  static void Write(Message* aMsg, const paramType& aParam)
-  {
-    WriteParam(aMsg, aParam.mId);
-    WriteParam(aMsg, aParam.mProperties);
-    WriteParam(aMsg, aParam.mWriteType);
-  }
-
-  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
-  {
-    if (!ReadParam(aMsg, aIter, &(aResult->mId)) ||
-        !ReadParam(aMsg, aIter, &(aResult->mProperties)) ||
-        !ReadParam(aMsg, aIter, &(aResult->mWriteType))) {
-      return false;
-    }
-
-    return true;
-  }
-};
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothAttributeHandle>
-{
-  typedef mozilla::dom::bluetooth::BluetoothAttributeHandle paramType;
-
-  static void Write(Message* aMsg, const paramType& aParam)
-  {
-    WriteParam(aMsg, aParam.mHandle);
-  }
-
-  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
-  {
-    if (!ReadParam(aMsg, aIter, &(aResult->mHandle))) {
-      return false;
-    }
-
-    return true;
-  }
-};
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothGattResponse>
-{
-  typedef mozilla::dom::bluetooth::BluetoothGattResponse paramType;
-
-  static void Write(Message* aMsg, const paramType& aParam)
-  {
-    auto length = aParam.mLength;
-    if (length > MOZ_ARRAY_LENGTH(aParam.mValue)) {
-      length = MOZ_ARRAY_LENGTH(aParam.mValue);
-    }
-
-    WriteParam(aMsg, aParam.mHandle);
-    WriteParam(aMsg, aParam.mOffset);
-    WriteParam(aMsg, length);
-    WriteParam(aMsg, aParam.mAuthReq);
-    for (uint16_t i = 0; i < length; i++) {
-      WriteParam(aMsg, aParam.mValue[i]);
-    }
-  }
-
-  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
-  {
-    if (!ReadParam(aMsg, aIter, &(aResult->mHandle)) ||
-        !ReadParam(aMsg, aIter, &(aResult->mOffset)) ||
-        !ReadParam(aMsg, aIter, &(aResult->mLength)) ||
-        !ReadParam(aMsg, aIter, &(aResult->mAuthReq))) {
-      return false;
-    }
-
-    if (aResult->mLength > MOZ_ARRAY_LENGTH(aResult->mValue)) {
-      return false;
-    }
-
-    for (uint16_t i = 0; i < aResult->mLength; i++) {
-      if (!ReadParam(aMsg, aIter, &(aResult->mValue[i]))) {
-        return false;
-      }
-    }
-
-    return true;
-  }
-};
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::ControlPlayStatus>
-{
-  typedef mozilla::dom::bluetooth::ControlPlayStatus paramType;
-
-  static void Write(Message* aMsg, const paramType& aParam)
-  {
-    WriteParam(aMsg, static_cast<uint8_t>(aParam));
-  }
-
-  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
-  {
-    uint8_t value;
-    if (!ReadParam(aMsg, aIter, &value)) {
-      return false;
-    }
-
-    mozilla::dom::bluetooth::ControlPlayStatus result =
-      static_cast<mozilla::dom::bluetooth::ControlPlayStatus>(value);
-
-    switch (result) {
-      case mozilla::dom::bluetooth::ControlPlayStatus::PLAYSTATUS_STOPPED:
-      case mozilla::dom::bluetooth::ControlPlayStatus::PLAYSTATUS_PLAYING:
-      case mozilla::dom::bluetooth::ControlPlayStatus::PLAYSTATUS_PAUSED:
-      case mozilla::dom::bluetooth::ControlPlayStatus::PLAYSTATUS_FWD_SEEK:
-      case mozilla::dom::bluetooth::ControlPlayStatus::PLAYSTATUS_REV_SEEK:
-      case mozilla::dom::bluetooth::ControlPlayStatus::PLAYSTATUS_ERROR:
-        *aResult = result;
-        return true;
-      default:
-        return false;
-    }
-  }
-};
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothGattAdvertisingData>
-{
-  typedef mozilla::dom::bluetooth::BluetoothGattAdvertisingData paramType;
-
-  static void Write(Message* aMsg, const paramType& aParam)
-  {
-    WriteParam(aMsg, aParam.mAppearance);
-    WriteParam(aMsg, aParam.mIncludeDevName);
-    WriteParam(aMsg, aParam.mIncludeTxPower);
-    WriteParam(aMsg, aParam.mManufacturerData);
-    WriteParam(aMsg, aParam.mServiceData);
-    WriteParam(aMsg, aParam.mServiceUuids);
-  }
-
-  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
-  {
-    if (!ReadParam(aMsg, aIter, &(aResult->mAppearance)) ||
-        !ReadParam(aMsg, aIter, &(aResult->mIncludeDevName)) ||
-        !ReadParam(aMsg, aIter, &(aResult->mIncludeTxPower)) ||
-        !ReadParam(aMsg, aIter, &(aResult->mManufacturerData)) ||
-        !ReadParam(aMsg, aIter, &(aResult->mServiceData)) ||
-        !ReadParam(aMsg, aIter, &(aResult->mServiceUuids))) {
-      return false;
-    }
-
-    return true;
-  }
-};
-
-template <>
-struct ParamTraits<mozilla::dom::bluetooth::BluetoothGattStatus>
-  : public ContiguousEnumSerializer<
-             mozilla::dom::bluetooth::BluetoothGattStatus,
-             mozilla::dom::bluetooth::GATT_STATUS_SUCCESS,
-             mozilla::dom::bluetooth::GATT_STATUS_END_OF_ERROR>
-{ };
-
-} // namespace IPC
-
-#endif // mozilla_dom_bluetooth_ipc_BluetoothMessageUtils_h
deleted file mode 100644
--- a/dom/bluetooth/ipc/BluetoothParent.cpp
+++ /dev/null
@@ -1,1360 +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 "base/basictypes.h"
-
-#include "BluetoothParent.h"
-
-#include "mozilla/Assertions.h"
-#include "mozilla/Unused.h"
-#include "nsDebug.h"
-#include "nsISupportsImpl.h"
-#include "nsThreadUtils.h"
-
-#include "BluetoothReplyRunnable.h"
-#include "BluetoothService.h"
-
-using mozilla::Unused;
-USING_BLUETOOTH_NAMESPACE
-
-/*******************************************************************************
- * BluetoothRequestParent::ReplyRunnable
- ******************************************************************************/
-
-class BluetoothRequestParent::ReplyRunnable final : public BluetoothReplyRunnable
-{
-  BluetoothRequestParent* mRequest;
-
-public:
-  ReplyRunnable(BluetoothRequestParent* aRequest)
-  : BluetoothReplyRunnable(nullptr), mRequest(aRequest)
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-    MOZ_ASSERT(aRequest);
-  }
-
-  NS_IMETHOD
-  Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-    MOZ_ASSERT(mReply);
-
-    if (mRequest) {
-      // Must do this first because Send__delete__ will delete mRequest.
-      mRequest->RequestComplete();
-
-      if (!mRequest->Send__delete__(mRequest, *mReply)) {
-        BT_WARNING("Failed to send response to child process!");
-        return NS_ERROR_FAILURE;
-      }
-    }
-
-    ReleaseMembers();
-    return NS_OK;
-  }
-
-  void
-  Revoke()
-  {
-    ReleaseMembers();
-  }
-
-  virtual bool
-  ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue) override
-  {
-    MOZ_CRASH("This should never be called!");
-  }
-
-  virtual void
-  ReleaseMembers() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-    mRequest = nullptr;
-    BluetoothReplyRunnable::ReleaseMembers();
-  }
-};
-
-/*******************************************************************************
- * BluetoothParent
- ******************************************************************************/
-
-BluetoothParent::BluetoothParent()
-: mShutdownState(Running)
-{
-  MOZ_COUNT_CTOR(BluetoothParent);
-}
-
-BluetoothParent::~BluetoothParent()
-{
-  MOZ_COUNT_DTOR(BluetoothParent);
-  MOZ_ASSERT(!mService);
-  MOZ_ASSERT(mShutdownState == Dead);
-}
-
-void
-BluetoothParent::BeginShutdown()
-{
-  // Only do something here if we haven't yet begun the shutdown sequence.
-  if (mShutdownState == Running) {
-    Unused << SendBeginShutdown();
-    mShutdownState = SentBeginShutdown;
-  }
-}
-
-bool
-BluetoothParent::InitWithService(BluetoothService* aService)
-{
-  MOZ_ASSERT(aService);
-  MOZ_ASSERT(!mService);
-
-  if (!SendEnabled(aService->IsEnabled())) {
-    return false;
-  }
-
-  mService = aService;
-  return true;
-}
-
-void
-BluetoothParent::UnregisterAllSignalHandlers()
-{
-  MOZ_ASSERT(mService);
-  mService->UnregisterAllSignalHandlers(this);
-}
-
-void
-BluetoothParent::ActorDestroy(ActorDestroyReason aWhy)
-{
-  if (mService) {
-    UnregisterAllSignalHandlers();
-#ifdef DEBUG
-    mService = nullptr;
-#endif
-  }
-
-#ifdef DEBUG
-  mShutdownState = Dead;
-#endif
-}
-
-bool
-BluetoothParent::RecvRegisterSignalHandler(const nsString& aNode)
-{
-  MOZ_ASSERT(mService);
-  mService->RegisterBluetoothSignalHandler(aNode, this);
-  return true;
-}
-
-bool
-BluetoothParent::RecvUnregisterSignalHandler(const nsString& aNode)
-{
-  MOZ_ASSERT(mService);
-  mService->UnregisterBluetoothSignalHandler(aNode, this);
-  return true;
-}
-
-bool
-BluetoothParent::RecvStopNotifying()
-{
-  MOZ_ASSERT(mService);
-
-  if (mShutdownState != Running && mShutdownState != SentBeginShutdown) {
-    MOZ_ASSERT(false, "Bad state!");
-    return false;
-  }
-
-  mShutdownState = ReceivedStopNotifying;
-
-  UnregisterAllSignalHandlers();
-
-  if (SendNotificationsStopped()) {
-    mShutdownState = SentNotificationsStopped;
-    return true;
-  }
-
-  return false;
-}
-
-bool
-BluetoothParent::RecvPBluetoothRequestConstructor(
-                                                PBluetoothRequestParent* aActor,
-                                                const Request& aRequest)
-{
-  BluetoothRequestParent* actor = static_cast<BluetoothRequestParent*>(aActor);
-
-#ifdef DEBUG
-  actor->mRequestType = aRequest.type();
-#endif
-
-  switch (aRequest.type()) {
-    case Request::TGetAdaptersRequest:
-      return actor->DoRequest(aRequest.get_GetAdaptersRequest());
-    case Request::TStartBluetoothRequest:
-      return actor->DoRequest(aRequest.get_StartBluetoothRequest());
-    case Request::TStopBluetoothRequest:
-      return actor->DoRequest(aRequest.get_StopBluetoothRequest());
-    case Request::TSetPropertyRequest:
-      return actor->DoRequest(aRequest.get_SetPropertyRequest());
-    case Request::TStartDiscoveryRequest:
-      return actor->DoRequest(aRequest.get_StartDiscoveryRequest());
-    case Request::TStopDiscoveryRequest:
-      return actor->DoRequest(aRequest.get_StopDiscoveryRequest());
-    case Request::TStartLeScanRequest:
-      return actor->DoRequest(aRequest.get_StartLeScanRequest());
-    case Request::TStopLeScanRequest:
-      return actor->DoRequest(aRequest.get_StopLeScanRequest());
-    case Request::TStartAdvertisingRequest:
-      return actor->DoRequest(aRequest.get_StartAdvertisingRequest());
-    case Request::TStopAdvertisingRequest:
-      return actor->DoRequest(aRequest.get_StopAdvertisingRequest());
-    case Request::TPairRequest:
-      return actor->DoRequest(aRequest.get_PairRequest());
-    case Request::TUnpairRequest:
-      return actor->DoRequest(aRequest.get_UnpairRequest());
-    case Request::TPairedDevicePropertiesRequest:
-      return actor->DoRequest(aRequest.get_PairedDevicePropertiesRequest());
-    case Request::TConnectedDevicePropertiesRequest:
-      return actor->DoRequest(aRequest.get_ConnectedDevicePropertiesRequest());
-    case Request::TFetchUuidsRequest:
-      return actor->DoRequest(aRequest.get_FetchUuidsRequest());
-    case Request::TPinReplyRequest:
-      return actor->DoRequest(aRequest.get_PinReplyRequest());
-    case Request::TSspReplyRequest:
-      return actor->DoRequest(aRequest.get_SspReplyRequest());
-    case Request::TSetPinCodeRequest:
-      return actor->DoRequest(aRequest.get_SetPinCodeRequest());
-    case Request::TSetPasskeyRequest:
-      return actor->DoRequest(aRequest.get_SetPasskeyRequest());
-    case Request::TConfirmPairingConfirmationRequest:
-      return actor->DoRequest(aRequest.get_ConfirmPairingConfirmationRequest());
-    case Request::TDenyPairingConfirmationRequest:
-      return actor->DoRequest(aRequest.get_DenyPairingConfirmationRequest());
-    case Request::TConnectRequest:
-      return actor->DoRequest(aRequest.get_ConnectRequest());
-    case Request::TDisconnectRequest:
-      return actor->DoRequest(aRequest.get_DisconnectRequest());
-    case Request::TSendFileRequest:
-      return actor->DoRequest(aRequest.get_SendFileRequest());
-    case Request::TStopSendingFileRequest:
-      return actor->DoRequest(aRequest.get_StopSendingFileRequest());
-    case Request::TConfirmReceivingFileRequest:
-      return actor->DoRequest(aRequest.get_ConfirmReceivingFileRequest());
-    case Request::TDenyReceivingFileRequest:
-      return actor->DoRequest(aRequest.get_DenyReceivingFileRequest());
-    case Request::TConnectScoRequest:
-      return actor->DoRequest(aRequest.get_ConnectScoRequest());
-    case Request::TDisconnectScoRequest:
-      return actor->DoRequest(aRequest.get_DisconnectScoRequest());
-    case Request::TIsScoConnectedRequest:
-      return actor->DoRequest(aRequest.get_IsScoConnectedRequest());
-    case Request::TSetObexPasswordRequest:
-      return actor->DoRequest(aRequest.get_SetObexPasswordRequest());
-    case Request::TRejectObexAuthRequest:
-      return actor->DoRequest(aRequest.get_RejectObexAuthRequest());
-    case Request::TReplyTovCardPullingRequest:
-      return actor->DoRequest(aRequest.get_ReplyTovCardPullingRequest());
-    case Request::TReplyToPhonebookPullingRequest:
-      return actor->DoRequest(aRequest.get_ReplyToPhonebookPullingRequest());
-    case Request::TReplyTovCardListingRequest:
-      return actor->DoRequest(aRequest.get_ReplyTovCardListingRequest());
-    case Request::TReplyToFolderListingRequest:
-      return actor->DoRequest(aRequest.get_ReplyToFolderListingRequest());
-    case Request::TReplyToMessagesListingRequest:
-      return actor->DoRequest(aRequest.get_ReplyToMessagesListingRequest());
-    case Request::TReplyToGetMessageRequest:
-      return actor->DoRequest(aRequest.get_ReplyToGetMessageRequest());
-    case Request::TReplyToSetMessageStatusRequest:
-      return actor->DoRequest(aRequest.get_ReplyToSetMessageStatusRequest());
-    case Request::TReplyToSendMessageRequest:
-      return actor->DoRequest(aRequest.get_ReplyToSendMessageRequest());
-    case Request::TReplyToMessageUpdateRequest:
-      return actor->DoRequest(aRequest.get_ReplyToMessageUpdateRequest());
-#ifdef MOZ_B2G_RIL
-    case Request::TAnswerWaitingCallRequest:
-      return actor->DoRequest(aRequest.get_AnswerWaitingCallRequest());
-    case Request::TIgnoreWaitingCallRequest:
-      return actor->DoRequest(aRequest.get_IgnoreWaitingCallRequest());
-    case Request::TToggleCallsRequest:
-      return actor->DoRequest(aRequest.get_ToggleCallsRequest());
-#endif
-    case Request::TSendMetaDataRequest:
-      return actor->DoRequest(aRequest.get_SendMetaDataRequest());
-    case Request::TSendPlayStatusRequest:
-      return actor->DoRequest(aRequest.get_SendPlayStatusRequest());
-    case Request::TConnectGattClientRequest:
-      return actor->DoRequest(aRequest.get_ConnectGattClientRequest());
-    case Request::TDisconnectGattClientRequest:
-      return actor->DoRequest(aRequest.get_DisconnectGattClientRequest());
-    case Request::TDiscoverGattServicesRequest:
-      return actor->DoRequest(aRequest.get_DiscoverGattServicesRequest());
-    case Request::TGattClientStartNotificationsRequest:
-      return actor->DoRequest(
-        aRequest.get_GattClientStartNotificationsRequest());
-    case Request::TGattClientStopNotificationsRequest:
-      return actor->DoRequest(
-        aRequest.get_GattClientStopNotificationsRequest());
-    case Request::TUnregisterGattClientRequest:
-      return actor->DoRequest(aRequest.get_UnregisterGattClientRequest());
-    case Request::TGattClientReadRemoteRssiRequest:
-      return actor->DoRequest(aRequest.get_GattClientReadRemoteRssiRequest());
-    case Request::TGattClientReadCharacteristicValueRequest:
-      return actor->DoRequest(
-        aRequest.get_GattClientReadCharacteristicValueRequest());
-    case Request::TGattClientWriteCharacteristicValueRequest:
-      return actor->DoRequest(
-        aRequest.get_GattClientWriteCharacteristicValueRequest());
-    case Request::TGattClientReadDescriptorValueRequest:
-      return actor->DoRequest(
-        aRequest.get_GattClientReadDescriptorValueRequest());
-    case Request::TGattClientWriteDescriptorValueRequest:
-      return actor->DoRequest(
-        aRequest.get_GattClientWriteDescriptorValueRequest());
-    case Request::TGattServerRegisterRequest:
-      return actor->DoRequest(
-        aRequest.get_GattServerRegisterRequest());
-    case Request::TGattServerConnectPeripheralRequest:
-      return actor->DoRequest(
-        aRequest.get_GattServerConnectPeripheralRequest());
-    case Request::TGattServerDisconnectPeripheralRequest:
-      return actor->DoRequest(
-        aRequest.get_GattServerDisconnectPeripheralRequest());
-    case Request::TUnregisterGattServerRequest:
-      return actor->DoRequest(aRequest.get_UnregisterGattServerRequest());
-    case Request::TGattServerAddServiceRequest:
-      return actor->DoRequest(aRequest.get_GattServerAddServiceRequest());
-    case Request::TGattServerAddIncludedServiceRequest:
-      return actor->DoRequest(
-               aRequest.get_GattServerAddIncludedServiceRequest());
-    case Request::TGattServerAddCharacteristicRequest:
-      return actor->DoRequest(
-               aRequest.get_GattServerAddCharacteristicRequest());
-    case Request::TGattServerAddDescriptorRequest:
-      return actor->DoRequest(aRequest.get_GattServerAddDescriptorRequest());
-    case Request::TGattServerRemoveServiceRequest:
-      return actor->DoRequest(aRequest.get_GattServerRemoveServiceRequest());
-    case Request::TGattServerStartServiceRequest:
-      return actor->DoRequest(aRequest.get_GattServerStartServiceRequest());
-    case Request::TGattServerStopServiceRequest:
-      return actor->DoRequest(aRequest.get_GattServerStopServiceRequest());
-    case Request::TGattServerSendResponseRequest:
-      return actor->DoRequest(aRequest.get_GattServerSendResponseRequest());
-    case Request::TGattServerSendIndicationRequest:
-      return actor->DoRequest(
-        aRequest.get_GattServerSendIndicationRequest());
-    default:
-      MOZ_CRASH("Unknown type!");
-  }
-
-  MOZ_CRASH("Should never get here!");
-}
-
-PBluetoothRequestParent*
-BluetoothParent::AllocPBluetoothRequestParent(const Request& aRequest)
-{
-  MOZ_ASSERT(mService);
-  return new BluetoothRequestParent(mService);
-}
-
-bool
-BluetoothParent::DeallocPBluetoothRequestParent(PBluetoothRequestParent* aActor)
-{
-  delete aActor;
-  return true;
-}
-
-void
-BluetoothParent::Notify(const BluetoothSignal& aSignal)
-{
-  Unused << SendNotify(aSignal);
-}
-
-/*******************************************************************************
- * BluetoothRequestParent
- ******************************************************************************/
-
-BluetoothRequestParent::BluetoothRequestParent(BluetoothService* aService)
-: mService(aService)
-#ifdef DEBUG
-  , mRequestType(Request::T__None)
-#endif
-{
-  MOZ_COUNT_CTOR(BluetoothRequestParent);
-  MOZ_ASSERT(aService);
-
-  mReplyRunnable = new ReplyRunnable(this);
-}
-
-BluetoothRequestParent::~BluetoothRequestParent()
-{
-  MOZ_COUNT_DTOR(BluetoothRequestParent);
-
-  // mReplyRunnable will be automatically revoked.
-}
-
-void
-BluetoothRequestParent::ActorDestroy(ActorDestroyReason aWhy)
-{
-  mReplyRunnable.Revoke();
-}
-
-void
-BluetoothRequestParent::RequestComplete()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mReplyRunnable.IsPending());
-
-  mReplyRunnable.Forget();
-}
-
-bool
-BluetoothRequestParent::DoRequest(const GetAdaptersRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TGetAdaptersRequest);
-
-  nsresult rv = mService->GetAdaptersInternal(mReplyRunnable.get());
-  NS_ENSURE_SUCCESS(rv, false);
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const StartBluetoothRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TStartBluetoothRequest);
-
-  nsresult rv = mService->StartInternal(mReplyRunnable.get());
-  NS_ENSURE_SUCCESS(rv, false);
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const StopBluetoothRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TStopBluetoothRequest);
-
-  nsresult rv = mService->StopInternal(mReplyRunnable.get());
-  NS_ENSURE_SUCCESS(rv, false);
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const SetPropertyRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TSetPropertyRequest);
-
-  nsresult rv =
-    mService->SetProperty(aRequest.type(), aRequest.value(),
-                          mReplyRunnable.get());
-  NS_ENSURE_SUCCESS(rv, false);
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const StartDiscoveryRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TStartDiscoveryRequest);
-
-  mService->StartDiscoveryInternal(mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const StopDiscoveryRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TStopDiscoveryRequest);
-
-  mService->StopDiscoveryInternal(mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const StartLeScanRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TStartLeScanRequest);
-
-  mService->StartLeScanInternal(aRequest.serviceUuids(), mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const StopLeScanRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TStopLeScanRequest);
-
-  mService->StopLeScanInternal(aRequest.scanUuid(), mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const StartAdvertisingRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TStartAdvertisingRequest);
-
-  mService->StartAdvertisingInternal(aRequest.appUuid(),
-                                     aRequest.data(),
-                                     mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const StopAdvertisingRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TStopAdvertisingRequest);
-
-  mService->StopAdvertisingInternal(aRequest.appUuid(), mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const PairRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TPairRequest);
-
-  nsresult rv =
-    mService->CreatePairedDeviceInternal(aRequest.address(),
-                                         aRequest.timeoutMS(),
-                                         mReplyRunnable.get());
-  NS_ENSURE_SUCCESS(rv, false);
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const UnpairRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TUnpairRequest);
-
-  nsresult rv =
-    mService->RemoveDeviceInternal(aRequest.address(),
-                                   mReplyRunnable.get());
-  NS_ENSURE_SUCCESS(rv, false);
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const PairedDevicePropertiesRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TPairedDevicePropertiesRequest);
-
-  nsresult rv =
-    mService->GetPairedDevicePropertiesInternal(aRequest.addresses(),
-                                                mReplyRunnable.get());
-  NS_ENSURE_SUCCESS(rv, false);
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-    const ConnectedDevicePropertiesRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TConnectedDevicePropertiesRequest);
-  nsresult rv =
-    mService->GetConnectedDevicePropertiesInternal(aRequest.serviceUuid(),
-                                                   mReplyRunnable.get());
-  NS_ENSURE_SUCCESS(rv, false);
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const FetchUuidsRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TFetchUuidsRequest);
-  nsresult rv =
-    mService->FetchUuidsInternal(aRequest.address(), mReplyRunnable.get());
-
-  NS_ENSURE_SUCCESS(rv, false);
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const PinReplyRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TPinReplyRequest);
-
-  mService->PinReplyInternal(aRequest.address(),
-                             aRequest.accept(),
-                             aRequest.pinCode(),
-                             mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const SspReplyRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TSspReplyRequest);
-
-  mService->SspReplyInternal(aRequest.address(),
-                             aRequest.variant(),
-                             aRequest.accept(),
-                             mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const SetPinCodeRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TSetPinCodeRequest);
-
-  mService->SetPinCodeInternal(aRequest.address(),
-                               aRequest.pincode(),
-                               mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const SetPasskeyRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TSetPasskeyRequest);
-
-  mService->SetPasskeyInternal(aRequest.address(),
-                               aRequest.passkey(),
-                               mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const ConfirmPairingConfirmationRequest&
-                                  aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TConfirmPairingConfirmationRequest);
-
-  mService->SetPairingConfirmationInternal(aRequest.address(),
-                                           true,
-                                           mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const DenyPairingConfirmationRequest&
-                                  aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TDenyPairingConfirmationRequest);
-
-  mService->SetPairingConfirmationInternal(aRequest.address(),
-                                           false,
-                                           mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const ConnectRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TConnectRequest);
-
-  mService->Connect(aRequest.address(),
-                    aRequest.cod(),
-                    aRequest.serviceUuid(),
-                    mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const DisconnectRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TDisconnectRequest);
-
-  mService->Disconnect(aRequest.address(),
-                       aRequest.serviceUuid(),
-                       mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const SendFileRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TSendFileRequest);
-
-  mService->SendFile(aRequest.address(),
-                     (BlobParent*)aRequest.blobParent(),
-                     (BlobChild*)aRequest.blobChild(),
-                     mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const StopSendingFileRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TStopSendingFileRequest);
-
-  mService->StopSendingFile(aRequest.address(),
-                            mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const ConfirmReceivingFileRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TConfirmReceivingFileRequest);
-
-  mService->ConfirmReceivingFile(aRequest.address(),
-                                 true,
-                                 mReplyRunnable.get());
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const DenyReceivingFileRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TDenyReceivingFileRequest);
-
-  mService->ConfirmReceivingFile(aRequest.address(),
-                                 false,
-                                 mReplyRunnable.get());
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const ConnectScoRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TConnectScoRequest);
-
-  mService->ConnectSco(mReplyRunnable.get());
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const DisconnectScoRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TDisconnectScoRequest);
-
-  mService->DisconnectSco(mReplyRunnable.get());
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const IsScoConnectedRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TIsScoConnectedRequest);
-
-  mService->IsScoConnected(mReplyRunnable.get());
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const SetObexPasswordRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TSetObexPasswordRequest);
-
-  mService->SetObexPassword(aRequest.password(), mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const RejectObexAuthRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TRejectObexAuthRequest);
-
-  mService->RejectObexAuth(mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const ReplyTovCardPullingRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TReplyTovCardPullingRequest);
-
-  mService->ReplyTovCardPulling((BlobParent*)aRequest.blobParent(),
-                                (BlobChild*)aRequest.blobChild(),
-                                mReplyRunnable.get());
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const ReplyToPhonebookPullingRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TReplyToPhonebookPullingRequest);
-
-  mService->ReplyToPhonebookPulling((BlobParent*)aRequest.blobParent(),
-                                    (BlobChild*)aRequest.blobChild(),
-                                    aRequest.phonebookSize(),
-                                    mReplyRunnable.get());
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const ReplyTovCardListingRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TReplyTovCardListingRequest);
-
-  mService->ReplyTovCardListing((BlobParent*)aRequest.blobParent(),
-                                (BlobChild*)aRequest.blobChild(),
-                                aRequest.phonebookSize(),
-                                mReplyRunnable.get());
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const ReplyToFolderListingRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TReplyToFolderListingRequest);
-
-  mService->ReplyToMapFolderListing(aRequest.masId(),
-                                           aRequest.folderList(),
-                                           mReplyRunnable.get());
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const ReplyToMessagesListingRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TReplyToMessagesListingRequest);
-
-  mService->ReplyToMapMessagesListing((BlobParent*)aRequest.blobParent(),
-                                             (BlobChild*)aRequest.blobChild(),
-                                             aRequest.masId(),
-                                             aRequest.newMessage(),
-                                             aRequest.timeStamp(),
-                                             aRequest.size(),
-                                             mReplyRunnable.get());
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const ReplyToGetMessageRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TReplyToGetMessageRequest);
-
-  mService->ReplyToMapGetMessage((BlobParent*)aRequest.blobParent(),
-                                     (BlobChild*)aRequest.blobChild(),
-                                     aRequest.masId(),
-                                     mReplyRunnable.get());
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const ReplyToSetMessageStatusRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TReplyToSetMessageStatusRequest);
-
-  mService->ReplyToMapSetMessageStatus(aRequest.masId(),
-                                       aRequest.messageStatus(),
-                                       mReplyRunnable.get());
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const ReplyToSendMessageRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TReplyToSendMessageRequest);
-
-  mService->ReplyToMapSendMessage(aRequest.masId(),
-                                  aRequest.handleId(),
-                                  aRequest.messageStatus(),
-                                  mReplyRunnable.get());
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const ReplyToMessageUpdateRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TReplyToMessageUpdateRequest);
-
-  mService->ReplyToMapMessageUpdate(aRequest.masId(),
-                                    aRequest.messageStatus(),
-                                    mReplyRunnable.get());
-  return true;
-}
-
-#ifdef MOZ_B2G_RIL
-bool
-BluetoothRequestParent::DoRequest(const AnswerWaitingCallRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TAnswerWaitingCallRequest);
-
-  mService->AnswerWaitingCall(mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const IgnoreWaitingCallRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TAnswerWaitingCallRequest);
-
-  mService->IgnoreWaitingCall(mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const ToggleCallsRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TAnswerWaitingCallRequest);
-
-  mService->ToggleCalls(mReplyRunnable.get());
-
-  return true;
-}
-#endif // MOZ_B2G_RIL
-
-bool
-BluetoothRequestParent::DoRequest(const SendMetaDataRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TSendMetaDataRequest);
-
-  mService->SendMetaData(aRequest.title(),
-                         aRequest.artist(),
-                         aRequest.album(),
-                         aRequest.mediaNumber(),
-                         aRequest.totalMediaCount(),
-                         aRequest.duration(),
-                         mReplyRunnable.get());
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const SendPlayStatusRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TSendPlayStatusRequest);
-
-  mService->SendPlayStatus(aRequest.duration(),
-                           aRequest.position(),
-                           aRequest.playStatus(),
-                           mReplyRunnable.get());
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const ConnectGattClientRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TConnectGattClientRequest);
-
-  mService->ConnectGattClientInternal(aRequest.appUuid(),
-                                      aRequest.deviceAddress(),
-                                      mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const DisconnectGattClientRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TDisconnectGattClientRequest);
-
-  mService->DisconnectGattClientInternal(aRequest.appUuid(),
-                                         aRequest.deviceAddress(),
-                                         mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const DiscoverGattServicesRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TDiscoverGattServicesRequest);
-
-  mService->DiscoverGattServicesInternal(aRequest.appUuid(),
-                                         mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattClientStartNotificationsRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TGattClientStartNotificationsRequest);
-
-  mService->GattClientStartNotificationsInternal(aRequest.appUuid(),
-                                                 aRequest.servId(),
-                                                 aRequest.charId(),
-                                                 mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattClientStopNotificationsRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TGattClientStopNotificationsRequest);
-
-  mService->GattClientStopNotificationsInternal(aRequest.appUuid(),
-                                                aRequest.servId(),
-                                                aRequest.charId(),
-                                                mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const UnregisterGattClientRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TUnregisterGattClientRequest);
-
-  mService->UnregisterGattClientInternal(aRequest.clientIf(),
-                                         mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattClientReadRemoteRssiRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TGattClientReadRemoteRssiRequest);
-
-  mService->GattClientReadRemoteRssiInternal(aRequest.clientIf(),
-                                             aRequest.deviceAddress(),
-                                             mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattClientReadCharacteristicValueRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType ==
-             Request::TGattClientReadCharacteristicValueRequest);
-
-  mService->GattClientReadCharacteristicValueInternal(aRequest.appUuid(),
-                                                      aRequest.serviceId(),
-                                                      aRequest.charId(),
-                                                      mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattClientWriteCharacteristicValueRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType ==
-             Request::TGattClientWriteCharacteristicValueRequest);
-
-  mService->GattClientWriteCharacteristicValueInternal(aRequest.appUuid(),
-                                                       aRequest.serviceId(),
-                                                       aRequest.charId(),
-                                                       aRequest.writeType(),
-                                                       aRequest.value(),
-                                                       mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattClientReadDescriptorValueRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType ==
-             Request::TGattClientReadDescriptorValueRequest);
-
-  mService->GattClientReadDescriptorValueInternal(aRequest.appUuid(),
-                                                  aRequest.serviceId(),
-                                                  aRequest.charId(),
-                                                  aRequest.descId(),
-                                                  mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattClientWriteDescriptorValueRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType ==
-             Request::TGattClientWriteDescriptorValueRequest);
-
-  mService->GattClientWriteDescriptorValueInternal(aRequest.appUuid(),
-                                                   aRequest.serviceId(),
-                                                   aRequest.charId(),
-                                                   aRequest.descId(),
-                                                   aRequest.value(),
-                                                   mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const GattServerRegisterRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TGattServerRegisterRequest);
-
-  mService->GattServerRegisterInternal(aRequest.appUuid(),
-                                       mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattServerConnectPeripheralRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType ==
-             Request::TGattServerConnectPeripheralRequest);
-
-  mService->GattServerConnectPeripheralInternal(aRequest.appUuid(),
-                                                aRequest.address(),
-                                                mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattServerDisconnectPeripheralRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType ==
-             Request::TGattServerDisconnectPeripheralRequest);
-
-  mService->GattServerDisconnectPeripheralInternal(aRequest.appUuid(),
-                                                   aRequest.address(),
-                                                   mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(const UnregisterGattServerRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TUnregisterGattServerRequest);
-
-  mService->UnregisterGattServerInternal(aRequest.serverIf(),
-                                         mReplyRunnable.get());
-
-  return true;
-}
-bool
-BluetoothRequestParent::DoRequest(
-  const GattServerAddServiceRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType ==
-             Request::TGattServerAddServiceRequest);
-
-  mService->GattServerAddServiceInternal(aRequest.appUuid(),
-                                         aRequest.serviceId(),
-                                         aRequest.handleCount(),
-                                         mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattServerAddIncludedServiceRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType ==
-             Request::TGattServerAddIncludedServiceRequest);
-
-  mService->GattServerAddIncludedServiceInternal(
-    aRequest.appUuid(),
-    aRequest.serviceHandle(),
-    aRequest.includedServiceHandle(),
-    mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattServerAddCharacteristicRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType ==
-             Request::TGattServerAddCharacteristicRequest);
-
-  mService->GattServerAddCharacteristicInternal(
-    aRequest.appUuid(),
-    aRequest.serviceHandle(),
-    aRequest.characteristicUuid(),
-    aRequest.permissions(),
-    aRequest.properties(),
-    mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattServerAddDescriptorRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType ==
-             Request::TGattServerAddDescriptorRequest);
-
-  mService->GattServerAddDescriptorInternal(
-    aRequest.appUuid(),
-    aRequest.serviceHandle(),
-    aRequest.characteristicHandle(),
-    aRequest.descriptorUuid(),
-    aRequest.permissions(),
-    mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattServerRemoveServiceRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType ==
-             Request::TGattServerRemoveServiceRequest);
-
-  mService->GattServerRemoveServiceInternal(
-    aRequest.appUuid(),
-    aRequest.serviceHandle(),
-    mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattServerStartServiceRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType ==
-             Request::TGattServerStartServiceRequest);
-
-  mService->GattServerStartServiceInternal(
-    aRequest.appUuid(),
-    aRequest.serviceHandle(),
-    mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattServerStopServiceRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType ==
-             Request::TGattServerStopServiceRequest);
-
-  mService->GattServerStopServiceInternal(
-    aRequest.appUuid(),
-    aRequest.serviceHandle(),
-    mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattServerSendIndicationRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TGattServerSendIndicationRequest);
-
-  mService->GattServerSendIndicationInternal(
-    aRequest.appUuid(),
-    aRequest.address(),
-    aRequest.characteristicHandle(),
-    aRequest.confirm(),
-    aRequest.value(),
-    mReplyRunnable.get());
-
-  return true;
-}
-
-bool
-BluetoothRequestParent::DoRequest(
-  const GattServerSendResponseRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType ==
-             Request::TGattServerSendResponseRequest);
-
-  mService->GattServerSendResponseInternal(
-    aRequest.appUuid(),
-    aRequest.address(),
-    aRequest.status(),
-    aRequest.requestId(),
-    aRequest.response(),
-    mReplyRunnable.get());
-
-  return true;
-}
deleted file mode 100644
--- a/dom/bluetooth/ipc/BluetoothParent.h
+++ /dev/null
@@ -1,343 +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_ipc_BluetoothParent_h
-#define mozilla_dom_bluetooth_ipc_BluetoothParent_h
-
-#include "mozilla/Attributes.h"
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/dom/bluetooth/PBluetoothParent.h"
-#include "mozilla/dom/bluetooth/PBluetoothRequestParent.h"
-#include "mozilla/Observer.h"
-#include "nsTArray.h"
-#include "nsThreadUtils.h"
-
-template <class T>
-class nsRevocableEventPtr;
-
-namespace mozilla {
-namespace dom {
-
-class ContentParent;
-
-} // namespace dom
-} // namespace mozilla
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothService;
-
-/*******************************************************************************
- * BluetoothParent
- ******************************************************************************/
-
-class BluetoothParent : public PBluetoothParent
-                      , public BluetoothSignalObserver
-{
-  friend class mozilla::dom::ContentParent;
-
-  enum ShutdownState
-  {
-    Running = 0,
-    SentBeginShutdown,
-    ReceivedStopNotifying,
-    SentNotificationsStopped,
-    Dead
-  };
-
-  RefPtr<BluetoothService> mService;
-  ShutdownState mShutdownState;
-  bool mReceivedStopNotifying;
-  bool mSentBeginShutdown;
-
-public:
-  void
-  BeginShutdown();
-
-protected:
-  BluetoothParent();
-  virtual ~BluetoothParent();
-
-  bool
-  InitWithService(BluetoothService* aService);
-
-  virtual void
-  ActorDestroy(ActorDestroyReason aWhy) override;
-
-  virtual bool
-  RecvRegisterSignalHandler(const nsString& aNode) override;
-
-  virtual bool
-  RecvUnregisterSignalHandler(const nsString& aNode) override;
-
-  virtual bool
-  RecvStopNotifying() override;
-
-  virtual bool
-  RecvPBluetoothRequestConstructor(PBluetoothRequestParent* aActor,
-                                   const Request& aRequest) override;
-
-  virtual PBluetoothRequestParent*
-  AllocPBluetoothRequestParent(const Request& aRequest) override;
-
-  virtual bool
-  DeallocPBluetoothRequestParent(PBluetoothRequestParent* aActor) override;
-
-  virtual void
-  Notify(const BluetoothSignal& aSignal) override;
-
-private:
-  void
-  UnregisterAllSignalHandlers();
-};
-
-/*******************************************************************************
- * BluetoothAdapterRequestParent
- ******************************************************************************/
-
-class BluetoothRequestParent : public PBluetoothRequestParent
-{
-  class ReplyRunnable;
-  friend class BluetoothParent;
-
-  friend class ReplyRunnable;
-
-  RefPtr<BluetoothService> mService;
-  nsRevocableEventPtr<ReplyRunnable> mReplyRunnable;
-
-#ifdef DEBUG
-  Request::Type mRequestType;
-#endif
-
-protected:
-  BluetoothRequestParent(BluetoothService* aService);
-  virtual ~BluetoothRequestParent();
-
-  virtual void
-  ActorDestroy(ActorDestroyReason aWhy) override;
-
-  void
-  RequestComplete();
-
-  bool
-  DoRequest(const GetAdaptersRequest& aRequest);
-
-  bool
-  DoRequest(const StartBluetoothRequest& aRequest);
-
-  bool
-  DoRequest(const StopBluetoothRequest& aRequest);
-
-  bool
-  DoRequest(const SetPropertyRequest& aRequest);
-
-  bool
-  DoRequest(const GetPropertyRequest& aRequest);
-
-  bool
-  DoRequest(const StartDiscoveryRequest& aRequest);
-
-  bool
-  DoRequest(const StopDiscoveryRequest& aRequest);
-
-  bool
-  DoRequest(const StartLeScanRequest& aRequest);
-
-  bool
-  DoRequest(const StopLeScanRequest& aRequest);
-
-  bool
-  DoRequest(const StartAdvertisingRequest& aRequest);
-
-  bool
-  DoRequest(const StopAdvertisingRequest& aRequest);
-
-  bool
-  DoRequest(const PairRequest& aRequest);
-
-  bool
-  DoRequest(const UnpairRequest& aRequest);
-
-  bool
-  DoRequest(const PairedDevicePropertiesRequest& aRequest);
-
-  bool
-  DoRequest(const ConnectedDevicePropertiesRequest& aRequest);
-
-  bool
-  DoRequest(const FetchUuidsRequest& aRequest);
-
-  bool
-  DoRequest(const SetPinCodeRequest& aRequest);
-
-  bool
-  DoRequest(const SetPasskeyRequest& aRequest);
-
-  bool
-  DoRequest(const ConfirmPairingConfirmationRequest& aRequest);
-
-  bool
-  DoRequest(const DenyPairingConfirmationRequest& aRequest);
-
-  bool
-  DoRequest(const PinReplyRequest& aRequest);
-
-  bool
-  DoRequest(const SspReplyRequest& aRequest);
-
-  bool
-  DoRequest(const ConnectRequest& aRequest);
-
-  bool
-  DoRequest(const DisconnectRequest& aRequest);
-
-  bool
-  DoRequest(const SendFileRequest& aRequest);
-
-  bool
-  DoRequest(const StopSendingFileRequest& aRequest);
-
-  bool
-  DoRequest(const ConfirmReceivingFileRequest& aRequest);
-
-  bool
-  DoRequest(const DenyReceivingFileRequest& aRequest);
-
-  bool
-  DoRequest(const ConnectScoRequest& aRequest);
-
-  bool
-  DoRequest(const DisconnectScoRequest& aRequest);
-
-  bool
-  DoRequest(const IsScoConnectedRequest& aRequest);
-
-  bool
-  DoRequest(const SetObexPasswordRequest& aRequest);
-
-  bool
-  DoRequest(const RejectObexAuthRequest& aRequest);
-
-  bool
-  DoRequest(const ReplyTovCardPullingRequest& aRequest);
-
-  bool
-  DoRequest(const ReplyToPhonebookPullingRequest& aRequest);
-
-  bool
-  DoRequest(const ReplyTovCardListingRequest& aRequest);
-
-  bool
-  DoRequest(const ReplyToFolderListingRequest& aRequest);
-
-  bool
-  DoRequest(const ReplyToMessagesListingRequest& aRequest);
-
-  bool
-  DoRequest(const ReplyToGetMessageRequest& aRequest);
-
-  bool
-  DoRequest(const ReplyToSetMessageStatusRequest& aRequest);
-
-  bool
-  DoRequest(const ReplyToSendMessageRequest& aRequest);
-
-  bool
-  DoRequest(const ReplyToMessageUpdateRequest& aRequest);
-
-#ifdef MOZ_B2G_RIL
-  bool
-  DoRequest(const AnswerWaitingCallRequest& aRequest);
-
-  bool
-  DoRequest(const IgnoreWaitingCallRequest& aRequest);
-
-  bool
-  DoRequest(const ToggleCallsRequest& aRequest);
-#endif
-
-  bool
-  DoRequest(const SendMetaDataRequest& aRequest);
-
-  bool
-  DoRequest(const SendPlayStatusRequest& aRequest);
-
-  bool
-  DoRequest(const ConnectGattClientRequest& aRequest);
-
-  bool
-  DoRequest(const DisconnectGattClientRequest& aRequest);
-
-  bool
-  DoRequest(const DiscoverGattServicesRequest& aRequest);
-
-  bool
-  DoRequest(const GattClientStartNotificationsRequest& aRequest);
-
-  bool
-  DoRequest(const GattClientStopNotificationsRequest& aRequest);
-
-  bool
-  DoRequest(const UnregisterGattClientRequest& aRequest);
-
-  bool
-  DoRequest(const GattClientReadRemoteRssiRequest& aRequest);
-
-  bool
-  DoRequest(const GattClientReadCharacteristicValueRequest& aRequest);
-
-  bool
-  DoRequest(const GattClientWriteCharacteristicValueRequest& aRequest);
-
-  bool
-  DoRequest(const GattClientReadDescriptorValueRequest& aRequest);
-
-  bool
-  DoRequest(const GattClientWriteDescriptorValueRequest& aRequest);
-
-  bool
-  DoRequest(const GattServerRegisterRequest& aRequest);
-
-  bool
-  DoRequest(const GattServerConnectPeripheralRequest& aRequest);
-
-  bool
-  DoRequest(const GattServerDisconnectPeripheralRequest& aRequest);
-
-  bool
-  DoRequest(const UnregisterGattServerRequest& aRequest);
-
-  bool
-  DoRequest(const GattServerAddServiceRequest& aRequest);
-
-  bool
-  DoRequest(const GattServerAddIncludedServiceRequest& aRequest);
-
-  bool
-  DoRequest(const GattServerAddCharacteristicRequest& aRequest);
-
-  bool
-  DoRequest(const GattServerAddDescriptorRequest& aRequest);
-
-  bool
-  DoRequest(const GattServerRemoveServiceRequest& aRequest);
-
-  bool
-  DoRequest(const GattServerStartServiceRequest& aRequest);
-
-  bool
-  DoRequest(const GattServerStopServiceRequest& aRequest);
-
-  bool
-  DoRequest(const GattServerSendResponseRequest& aRequest);
-
-  bool
-  DoRequest(const GattServerSendIndicationRequest& aRequest);
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_ipc_BluetoothParent_h
deleted file mode 100644
--- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
+++ /dev/null
@@ -1,885 +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 "base/basictypes.h"
-
-#include "BluetoothServiceChildProcess.h"
-
-#include "mozilla/Assertions.h"
-#include "mozilla/dom/ContentChild.h"
-#include "mozilla/dom/ipc/BlobChild.h"
-
-#include "BluetoothChild.h"
-#include "MainThreadUtils.h"
-
-USING_BLUETOOTH_NAMESPACE
-
-namespace {
-
-BluetoothChild* sBluetoothChild;
-
-inline
-void
-SendRequest(BluetoothReplyRunnable* aRunnable, const Request& aRequest)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aRunnable);
-
-  NS_WARNING_ASSERTION(
-    sBluetoothChild,
-    "Calling methods on BluetoothServiceChildProcess during shutdown!");
-
-  if (sBluetoothChild) {
-    BluetoothRequestChild* actor = new BluetoothRequestChild(aRunnable);
-    sBluetoothChild->SendPBluetoothRequestConstructor(actor, aRequest);
-  }
-}
-
-} // namespace
-
-// static
-BluetoothServiceChildProcess*
-BluetoothServiceChildProcess::Create()
-{
-  MOZ_ASSERT(!sBluetoothChild);
-
-  mozilla::dom::ContentChild* contentChild =
-    mozilla::dom::ContentChild::GetSingleton();
-  MOZ_ASSERT(contentChild);
-
-  BluetoothServiceChildProcess* btService = new BluetoothServiceChildProcess();
-
-  sBluetoothChild = new BluetoothChild(btService);
-  contentChild->SendPBluetoothConstructor(sBluetoothChild);
-
-  return btService;
-}
-
-BluetoothServiceChildProcess::BluetoothServiceChildProcess()
-{
-}
-
-BluetoothServiceChildProcess::~BluetoothServiceChildProcess()
-{
-  sBluetoothChild = nullptr;
-}
-
-void
-BluetoothServiceChildProcess::NoteDeadActor()
-{
-  MOZ_ASSERT(sBluetoothChild);
-  sBluetoothChild = nullptr;
-}
-
-void
-BluetoothServiceChildProcess::RegisterBluetoothSignalHandler(
-                                              const nsAString& aNodeName,
-                                              BluetoothSignalObserver* aHandler)
-{
-  if (sBluetoothChild && !IsSignalRegistered(aNodeName)) {
-    sBluetoothChild->SendRegisterSignalHandler(nsString(aNodeName));
-  }
-  BluetoothService::RegisterBluetoothSignalHandler(aNodeName, aHandler);
-}
-
-void
-BluetoothServiceChildProcess::UnregisterBluetoothSignalHandler(
-                                              const nsAString& aNodeName,
-                                              BluetoothSignalObserver* aHandler)
-{
-  BluetoothService::UnregisterBluetoothSignalHandler(aNodeName, aHandler);
-  if (sBluetoothChild && !IsSignalRegistered(aNodeName)) {
-    sBluetoothChild->SendUnregisterSignalHandler(nsString(aNodeName));
-  }
-}
-
-nsresult
-BluetoothServiceChildProcess::GetAdaptersInternal(
-                                              BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, GetAdaptersRequest());
-  return NS_OK;
-}
-
-nsresult
-BluetoothServiceChildProcess::StartInternal(BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, StartBluetoothRequest());
-  return NS_OK;
-}
-
-nsresult
-BluetoothServiceChildProcess::StopInternal(BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, StopBluetoothRequest());
-  return NS_OK;
-}
-
-nsresult
-BluetoothServiceChildProcess::GetConnectedDevicePropertiesInternal(
-                                              uint16_t aServiceUuid,
-                                              BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, ConnectedDevicePropertiesRequest(aServiceUuid));
-  return NS_OK;
-}
-
-nsresult
-BluetoothServiceChildProcess::GetPairedDevicePropertiesInternal(
-  const nsTArray<BluetoothAddress>& aDeviceAddresses,
-  BluetoothReplyRunnable* aRunnable)
-{
-  PairedDevicePropertiesRequest request;
-  request.addresses().AppendElements(aDeviceAddresses);
-
-  SendRequest(aRunnable, request);
-  return NS_OK;
-}
-
-nsresult
-BluetoothServiceChildProcess::FetchUuidsInternal(
-  const BluetoothAddress& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, FetchUuidsRequest(aDeviceAddress));
-  return NS_OK;
-}
-
-void
-BluetoothServiceChildProcess::StopDiscoveryInternal(
-   BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, StopDiscoveryRequest());
-}
-
-void
-BluetoothServiceChildProcess::StartDiscoveryInternal(
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, StartDiscoveryRequest());
-}
-
-void
-BluetoothServiceChildProcess::StopLeScanInternal(
-  const BluetoothUuid& aScanUuid,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, StopLeScanRequest(aScanUuid));
-}
-
-void
-BluetoothServiceChildProcess::StartLeScanInternal(
-  const nsTArray<BluetoothUuid>& aServiceUuids,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, StartLeScanRequest(aServiceUuids));
-}
-
-void
-BluetoothServiceChildProcess::StartAdvertisingInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattAdvertisingData& aAdvData,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, StartAdvertisingRequest(aAppUuid, aAdvData));
-}
-
-void
-BluetoothServiceChildProcess::StopAdvertisingInternal(
-  const BluetoothUuid& aAppUuid,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, StopAdvertisingRequest(aAppUuid));
-}
-
-nsresult
-BluetoothServiceChildProcess::SetProperty(BluetoothObjectType aType,
-                                          const BluetoothNamedValue& aValue,
-                                          BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, SetPropertyRequest(aType, aValue));
-  return NS_OK;
-}
-
-nsresult
-BluetoothServiceChildProcess::CreatePairedDeviceInternal(
-  const BluetoothAddress& aDeviceAddress, int aTimeout,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, PairRequest(aDeviceAddress, aTimeout));
-  return NS_OK;
-}
-
-nsresult
-BluetoothServiceChildProcess::RemoveDeviceInternal(
-  const BluetoothAddress& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, UnpairRequest(aDeviceAddress));
-  return NS_OK;
-}
-
-nsresult
-BluetoothServiceChildProcess::GetServiceChannel(const BluetoothAddress& aDeviceAddress,
-                                                const BluetoothUuid& aServiceUuid,
-                                                BluetoothProfileManagerBase* aManager)
-{
-  MOZ_CRASH("This should never be called!");
-}
-
-bool
-BluetoothServiceChildProcess::UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
-                                               BluetoothProfileManagerBase* aManager)
-{
-  MOZ_CRASH("This should never be called!");
-}
-
-void
-BluetoothServiceChildProcess::PinReplyInternal(
-  const BluetoothAddress& aDeviceAddress, bool aAccept,
-  const BluetoothPinCode& aPinCode, BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, PinReplyRequest(aDeviceAddress, aAccept, aPinCode));
-}
-
-void
-BluetoothServiceChildProcess::SspReplyInternal(
-  const BluetoothAddress& aDeviceAddress,
-  BluetoothSspVariant aVariant, bool aAccept,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, SspReplyRequest(aDeviceAddress, aVariant, aAccept));
-}
-
-void
-BluetoothServiceChildProcess::SetPinCodeInternal(
-  const BluetoothAddress& aDeviceAddress,
-  const BluetoothPinCode& aPinCode,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, SetPinCodeRequest(aDeviceAddress, aPinCode));
-}
-
-void
-BluetoothServiceChildProcess::SetPasskeyInternal(
-  const BluetoothAddress& aDeviceAddress,
-  uint32_t aPasskey,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, SetPasskeyRequest(aDeviceAddress, aPasskey));
-}
-
-void
-BluetoothServiceChildProcess::SetPairingConfirmationInternal(
-                                                const BluetoothAddress& aDeviceAddress,
-                                                bool aConfirm,
-                                                BluetoothReplyRunnable* aRunnable)
-{
-  if (aConfirm) {
-    SendRequest(aRunnable, ConfirmPairingConfirmationRequest(aDeviceAddress));
-  } else {
-    SendRequest(aRunnable, DenyPairingConfirmationRequest(aDeviceAddress));
-  }
-}
-
-void
-BluetoothServiceChildProcess::Connect(
-  const BluetoothAddress& aDeviceAddress,
-  uint32_t aCod, uint16_t aServiceUuid,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, ConnectRequest(aDeviceAddress, aCod, aServiceUuid));
-}
-
-void
-BluetoothServiceChildProcess::Disconnect(
-  const BluetoothAddress& aDeviceAddress,
-  uint16_t aServiceUuid,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, DisconnectRequest(aDeviceAddress, aServiceUuid));
-}
-
-void
-BluetoothServiceChildProcess::SendFile(
-  const BluetoothAddress& aDeviceAddress,
-  BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, SendFileRequest(aDeviceAddress, nullptr, aBlobChild));
-}
-
-void
-BluetoothServiceChildProcess::SendFile(
-  const BluetoothAddress& aDeviceAddress,
-  Blob* aBlobChild,
-  BluetoothReplyRunnable* aRunnable)
-{
-  // Parent-process-only method
-  MOZ_CRASH("This should never be called!");
-}
-
-void
-BluetoothServiceChildProcess::StopSendingFile(
-  const BluetoothAddress& aDeviceAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, StopSendingFileRequest(aDeviceAddress));
-}
-
-void
-BluetoothServiceChildProcess::ConfirmReceivingFile(
-  const BluetoothAddress& aDeviceAddress, bool aConfirm,
-  BluetoothReplyRunnable* aRunnable)
-{
-  if(aConfirm) {
-    SendRequest(aRunnable, ConfirmReceivingFileRequest(aDeviceAddress));
-    return;
-  }
-
-  SendRequest(aRunnable, DenyReceivingFileRequest(aDeviceAddress));
-}
-
-void
-BluetoothServiceChildProcess::ConnectSco(BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, ConnectScoRequest());
-}
-
-void
-BluetoothServiceChildProcess::DisconnectSco(BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, DisconnectScoRequest());
-}
-
-void
-BluetoothServiceChildProcess::IsScoConnected(BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, IsScoConnectedRequest());
-}
-
-void
-BluetoothServiceChildProcess::SetObexPassword(
-  const nsAString& aPassword,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, SetObexPasswordRequest(nsString(aPassword)));
-}
-
-void
-BluetoothServiceChildProcess::RejectObexAuth(BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, RejectObexAuthRequest());
-}
-
-void
-BluetoothServiceChildProcess::ReplyTovCardPulling(
-  BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, ReplyTovCardPullingRequest(nullptr, aBlobChild));
-}
-
-void
-BluetoothServiceChildProcess::ReplyTovCardPulling(
-  Blob* aBlobChild,
-  BluetoothReplyRunnable* aRunnable)
-{
-  // Parent-process-only method
-  MOZ_CRASH("This should never be called!");
-}
-
-void
-BluetoothServiceChildProcess::ReplyToPhonebookPulling(
-  BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  uint16_t aPhonebookSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    ReplyToPhonebookPullingRequest(nullptr, aBlobChild, aPhonebookSize));
-}
-
-void
-BluetoothServiceChildProcess::ReplyToPhonebookPulling(
-  Blob* aBlobChild,
-  uint16_t aPhonebookSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-  // Parent-process-only method
-  MOZ_CRASH("This should never be called!");
-}
-
-void
-BluetoothServiceChildProcess::ReplyTovCardListing(
-  BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  uint16_t aPhonebookSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    ReplyTovCardListingRequest(nullptr, aBlobChild, aPhonebookSize));
-}
-
-void
-BluetoothServiceChildProcess::ReplyTovCardListing(
-  Blob* aBlobChild,
-  uint16_t aPhonebookSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-  // Parent-process-only method
-  MOZ_CRASH("This should never be called!");
-}
-
-void
-BluetoothServiceChildProcess::ReplyToMapFolderListing(long aMasId,
-  const nsAString& aFolderList,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-              ReplyToFolderListingRequest(aMasId, nsString(aFolderList)));
-}
-
-void
-BluetoothServiceChildProcess::ReplyToMapMessagesListing(BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  long aMasId,
-  bool aNewMessage,
-  const nsAString& aTimestamp,
-  int aSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-              ReplyToMessagesListingRequest(aMasId, nullptr, aBlobChild,
-                                            aNewMessage, nsString(aTimestamp), aSize));
-}
-
-void
-BluetoothServiceChildProcess::ReplyToMapMessagesListing(long aMasId,
-  Blob* aBlob,
-  bool aNewMessage,
-  const nsAString& aTimestamp,
-  int aSize,
-  BluetoothReplyRunnable* aRunnable)
-{
-  // Parent-process-only method
-  MOZ_CRASH("This should never be called!");
-}
-
-
-void
-BluetoothServiceChildProcess::ReplyToMapGetMessage(BlobParent* aBlobParent,
-  BlobChild* aBlobChild,
-  long aMasId,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    ReplyToGetMessageRequest(aMasId, nullptr, aBlobChild));
-}
-
-void
-BluetoothServiceChildProcess::ReplyToMapGetMessage(Blob* aBlob,
-  long aMasId,
-  BluetoothReplyRunnable* aRunnable)
-{
-  // Parent-process-only method
-  MOZ_CRASH("This should never be called!");
-}
-
-void
-BluetoothServiceChildProcess::ReplyToMapSetMessageStatus(long aMasId,
-  bool aStatus,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    ReplyToSetMessageStatusRequest(aMasId, aStatus));
-}
-
-void
-BluetoothServiceChildProcess::ReplyToMapSendMessage(long aMasId,
-  const nsAString& aHandleId,
-  bool aStatus,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    ReplyToSendMessageRequest(aMasId, nsString(aHandleId), aStatus));
-}
-
-void
-BluetoothServiceChildProcess::ReplyToMapMessageUpdate(long aMasId,
-  bool aStatus,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    ReplyToMessageUpdateRequest(aMasId, aStatus));
-}
-
-#ifdef MOZ_B2G_RIL
-void
-BluetoothServiceChildProcess::AnswerWaitingCall(
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, AnswerWaitingCallRequest());
-}
-
-void
-BluetoothServiceChildProcess::IgnoreWaitingCall(
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, IgnoreWaitingCallRequest());
-}
-
-void
-BluetoothServiceChildProcess::ToggleCalls(
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, ToggleCallsRequest());
-}
-#endif // MOZ_B2G_RIL
-
-void
-BluetoothServiceChildProcess::SendMetaData(const nsAString& aTitle,
-                                           const nsAString& aArtist,
-                                           const nsAString& aAlbum,
-                                           int64_t aMediaNumber,
-                                           int64_t aTotalMediaCount,
-                                           int64_t aDuration,
-                                           BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-              SendMetaDataRequest(nsString(aTitle), nsString(aArtist),
-                                  nsString(aAlbum), aMediaNumber,
-                                  aTotalMediaCount, aDuration));
-}
-
-void
-BluetoothServiceChildProcess::SendPlayStatus(int64_t aDuration,
-                                             int64_t aPosition,
-                                             ControlPlayStatus aPlayStatus,
-                                             BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-              SendPlayStatusRequest(aDuration, aPosition, aPlayStatus));
-}
-
-void
-BluetoothServiceChildProcess::ConnectGattClientInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothAddress& aDeviceAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, ConnectGattClientRequest(aAppUuid, aDeviceAddress));
-}
-
-void
-BluetoothServiceChildProcess::DisconnectGattClientInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothAddress& aDeviceAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-              DisconnectGattClientRequest(aAppUuid, aDeviceAddress));
-}
-
-void
-BluetoothServiceChildProcess::DiscoverGattServicesInternal(
-  const BluetoothUuid& aAppUuid, BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, DiscoverGattServicesRequest(aAppUuid));
-}
-
-void
-BluetoothServiceChildProcess::GattClientStartNotificationsInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothGattServiceId& aServId,
-  const BluetoothGattId& aCharId, BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattClientStartNotificationsRequest(aAppUuid, aServId, aCharId));
-}
-
-void
-BluetoothServiceChildProcess::GattClientStopNotificationsInternal(
-  const BluetoothUuid& aAppUuid, const BluetoothGattServiceId& aServId,
-  const BluetoothGattId& aCharId, BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattClientStopNotificationsRequest(aAppUuid, aServId, aCharId));
-}
-
-void
-BluetoothServiceChildProcess::UnregisterGattClientInternal(
-  int aClientIf, BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, UnregisterGattClientRequest(aClientIf));
-}
-
-void
-BluetoothServiceChildProcess::GattClientReadRemoteRssiInternal(
-  int aClientIf, const BluetoothAddress& aDeviceAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-              GattClientReadRemoteRssiRequest(aClientIf, aDeviceAddress));
-}
-
-void
-BluetoothServiceChildProcess::GattClientReadCharacteristicValueInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattClientReadCharacteristicValueRequest(aAppUuid,
-                                             aServiceId,
-                                             aCharacteristicId));
-}
-
-void
-BluetoothServiceChildProcess::GattClientWriteCharacteristicValueInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  const BluetoothGattWriteType& aWriteType,
-  const nsTArray<uint8_t>& aValue,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattClientWriteCharacteristicValueRequest(aAppUuid,
-                                              aServiceId,
-                                              aCharacteristicId,
-                                              aWriteType,
-                                              aValue));
-}
-
-void
-BluetoothServiceChildProcess::GattClientReadDescriptorValueInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  const BluetoothGattId& aDescriptorId,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattClientReadDescriptorValueRequest(aAppUuid,
-                                         aServiceId,
-                                         aCharacteristicId,
-                                         aDescriptorId));
-}
-
-void
-BluetoothServiceChildProcess::GattClientWriteDescriptorValueInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  const BluetoothGattId& aCharacteristicId,
-  const BluetoothGattId& aDescriptorId,
-  const nsTArray<uint8_t>& aValue,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattClientWriteDescriptorValueRequest(aAppUuid,
-                                          aServiceId,
-                                          aCharacteristicId,
-                                          aDescriptorId,
-                                          aValue));
-}
-
-void
-BluetoothServiceChildProcess::GattServerRegisterInternal(
-  const BluetoothUuid& aAppUuid,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,GattServerRegisterRequest(aAppUuid));
-}
-
-void
-BluetoothServiceChildProcess::GattServerConnectPeripheralInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAddress& aAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattServerConnectPeripheralRequest(aAppUuid, aAddress));
-}
-
-void
-BluetoothServiceChildProcess::GattServerDisconnectPeripheralInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAddress& aAddress,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattServerDisconnectPeripheralRequest(aAppUuid, aAddress));
-}
-
-void
-BluetoothServiceChildProcess::UnregisterGattServerInternal(
-  int aServerIf, BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable, UnregisterGattServerRequest(aServerIf));
-}
-
-void
-BluetoothServiceChildProcess::GattServerAddServiceInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothGattServiceId& aServiceId,
-  uint16_t aHandleCount,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattServerAddServiceRequest(aAppUuid, aServiceId, aHandleCount));
-}
-
-void
-BluetoothServiceChildProcess::GattServerAddIncludedServiceInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aIncludedServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattServerAddIncludedServiceRequest(aAppUuid,
-                                        aServiceHandle,
-                                        aIncludedServiceHandle));
-}
-
-void
-BluetoothServiceChildProcess::GattServerAddCharacteristicInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothUuid& aCharacteristicUuid,
-  BluetoothGattAttrPerm aPermissions,
-  BluetoothGattCharProp aProperties,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattServerAddCharacteristicRequest(aAppUuid,
-                                       aServiceHandle,
-                                       aCharacteristicUuid,
-                                       aPermissions,
-                                       aProperties));
-}
-
-void
-BluetoothServiceChildProcess::GattServerAddDescriptorInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  const BluetoothAttributeHandle& aCharacteristicHandle,
-  const BluetoothUuid& aDescriptorUuid,
-  BluetoothGattAttrPerm aPermissions,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattServerAddDescriptorRequest(aAppUuid,
-                                   aServiceHandle,
-                                   aCharacteristicHandle,
-                                   aDescriptorUuid,
-                                   aPermissions));
-}
-
-void
-BluetoothServiceChildProcess::GattServerRemoveServiceInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattServerRemoveServiceRequest(aAppUuid, aServiceHandle));
-}
-
-void
-BluetoothServiceChildProcess::GattServerStartServiceInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattServerStartServiceRequest(aAppUuid, aServiceHandle));
-}
-
-void
-BluetoothServiceChildProcess::GattServerStopServiceInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAttributeHandle& aServiceHandle,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattServerStopServiceRequest(aAppUuid, aServiceHandle));
-}
-
-void
-BluetoothServiceChildProcess::GattServerSendResponseInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAddress& aAddress,
-  uint16_t aStatus,
-  int32_t aRequestId,
-  const BluetoothGattResponse& aRsp,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattServerSendResponseRequest(aAppUuid,
-                                  aAddress,
-                                  aStatus,
-                                  aRequestId,
-                                  aRsp));
-}
-
-void
-BluetoothServiceChildProcess::GattServerSendIndicationInternal(
-  const BluetoothUuid& aAppUuid,
-  const BluetoothAddress& aAddress,
-  const BluetoothAttributeHandle& aCharacteristicHandle,
-  bool aConfirm,
-  const nsTArray<uint8_t>& aValue,
-  BluetoothReplyRunnable* aRunnable)
-{
-  SendRequest(aRunnable,
-    GattServerSendIndicationRequest(aAppUuid,
-                                    aAddress,
-                                    aCharacteristicHandle,
-                                    aConfirm,
-                                    aValue));
-}
-
-nsresult
-BluetoothServiceChildProcess::HandleStartup()
-{
-  // Don't need to do anything here for startup since our Create function takes
-  // care of the actor machinery.
-  return NS_OK;
-}
-
-nsresult
-BluetoothServiceChildProcess::HandleShutdown()
-{
-  // If this process is shutting down then we need to disconnect ourselves from
-  // the parent.
-  if (sBluetoothChild) {
-    sBluetoothChild->BeginShutdown();
-  }
-  return NS_OK;
-}
-
-nsresult
-BluetoothServiceChildProcess::SendSinkMessage(const nsAString& aDeviceAddresses,
-                                              const nsAString& aMessage)
-{
-  MOZ_CRASH("This should never be called!");
-}
-
-nsresult
-BluetoothServiceChildProcess::SendInputMessage(const nsAString& aDeviceAddresses,
-                                               const nsAString& aMessage)
-{
-  MOZ_CRASH("This should never be called!");
-}
-
-void
-BluetoothServiceChildProcess::UpdatePlayStatus(uint32_t aDuration,
-                                               uint32_t aPosition,
-                                               ControlPlayStatus aPlayStatus)
-{
-  MOZ_CRASH("This should never be called!");
-}
-
deleted file mode 100644
--- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.h
+++ /dev/null
@@ -1,479 +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_ipc_BluetoothServiceChildProcess_h
-#define mozilla_dom_bluetooth_ipc_BluetoothServiceChildProcess_h
-
-#include "BluetoothService.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothChild;
-
-class BluetoothServiceChildProcess : public BluetoothService
-{
-  friend class mozilla::dom::bluetooth::BluetoothChild;
-
-public:
-  static BluetoothServiceChildProcess*
-  Create();
-
-  virtual void
-  RegisterBluetoothSignalHandler(const nsAString& aNodeName,
-                                 BluetoothSignalObserver* aMsgHandler)
-                                 override;
-
-  virtual void
-  UnregisterBluetoothSignalHandler(const nsAString& aNodeName,
-                                   BluetoothSignalObserver* aMsgHandler)
-                                   override;
-
-  virtual nsresult
-  GetAdaptersInternal(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual nsresult
-  StartInternal(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual nsresult
-  StopInternal(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual nsresult
-  GetPairedDevicePropertiesInternal(const nsTArray<BluetoothAddress>& aDeviceAddresses,
-                                    BluetoothReplyRunnable* aRunnable)
-                                    override;
-
-  virtual nsresult
-  GetConnectedDevicePropertiesInternal(uint16_t aServiceUuid,
-                                       BluetoothReplyRunnable* aRunnable)
-                                       override;
-  virtual nsresult
-  FetchUuidsInternal(const BluetoothAddress& aDeviceAddress,
-                     BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  StopLeScanInternal(const BluetoothUuid& aScanUuid,
-                     BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  StartLeScanInternal(const nsTArray<BluetoothUuid>& aServiceUuids,
-                      BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  StartAdvertisingInternal(const BluetoothUuid& aAppUuid,
-                           const BluetoothGattAdvertisingData& aAdvData,
-                           BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  StopAdvertisingInternal(const BluetoothUuid& aAppUuid,
-                          BluetoothReplyRunnable* aRunnable) override;
-
-  virtual nsresult
-  SetProperty(BluetoothObjectType aType,
-              const BluetoothNamedValue& aValue,
-              BluetoothReplyRunnable* aRunnable) override;
-
-  virtual nsresult
-  CreatePairedDeviceInternal(const BluetoothAddress& aDeviceAddress,
-                             int aTimeout,
-                             BluetoothReplyRunnable* aRunnable) override;
-
-  virtual nsresult
-  RemoveDeviceInternal(const BluetoothAddress& aDeviceAddress,
-                       BluetoothReplyRunnable* aRunnable) override;
-
-  virtual nsresult
-  GetServiceChannel(const BluetoothAddress& aDeviceAddress,
-                    const BluetoothUuid& aServiceUuid,
-                    BluetoothProfileManagerBase* aManager) override;
-
-  virtual bool
-  UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
-                   BluetoothProfileManagerBase* aManager) override;
-
-  virtual void
-  SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
-                     const BluetoothPinCode& aPinCode,
-                     BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SetPasskeyInternal(const BluetoothAddress& aDeviceAddress,
-                     uint32_t aPasskey,
-                     BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SetPairingConfirmationInternal(const BluetoothAddress& aDeviceAddress,
-                                 bool aConfirm,
-                                 BluetoothReplyRunnable* aRunnable)
-                                 override;
-
-  virtual void
-  PinReplyInternal(const BluetoothAddress& aDeviceAddress,
-                   bool aAccept,
-                   const BluetoothPinCode& aPinCode,
-                   BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SspReplyInternal(const BluetoothAddress& aDeviceAddress,
-                   BluetoothSspVariant aVariant,
-                   bool aAccept,
-                   BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  Connect(const BluetoothAddress& aDeviceAddress,
-          uint32_t aCod,
-          uint16_t aServiceUuid,
-          BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  Disconnect(const BluetoothAddress& aDeviceAddress,
-             uint16_t aServiceUuid,
-             BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SendFile(const BluetoothAddress& aDeviceAddress,
-           BlobParent* aBlobParent,
-           BlobChild* aBlobChild,
-           BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SendFile(const BluetoothAddress& aDeviceAddress,
-           Blob* aBlob,
-           BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  StopSendingFile(const BluetoothAddress& aDeviceAddress,
-                  BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ConfirmReceivingFile(const BluetoothAddress& aDeviceAddress,
-                       bool aConfirm,
-                       BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ConnectSco(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  DisconnectSco(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  IsScoConnected(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SetObexPassword(const nsAString& aPassword,
-                  BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  RejectObexAuth(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyTovCardPulling(BlobParent* aBlobParent,
-                      BlobChild* aBlobChild,
-                      BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyTovCardPulling(Blob* aBlob,
-                      BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToPhonebookPulling(BlobParent* aBlobParent,
-                          BlobChild* aBlobChild,
-                          uint16_t aPhonebookSize,
-                          BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToPhonebookPulling(Blob* aBlob,
-                          uint16_t aPhonebookSize,
-                          BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyTovCardListing(BlobParent* aBlobParent,
-                      BlobChild* aBlobChild,
-                      uint16_t aPhonebookSize,
-                      BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyTovCardListing(Blob* aBlob,
-                      uint16_t aPhonebookSize,
-                      BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapFolderListing(long aMasId,
-                          const nsAString& aFolderlists,
-                          BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapMessagesListing(BlobParent* aBlobParent,
-                            BlobChild* aBlobChild,
-                            long aMasId,
-                            bool aNewMessage,
-                            const nsAString& aTimestamp,
-                            int aSize,
-                            BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapMessagesListing(long aMasId,
-                            Blob* aBlob,
-                            bool aNewMessage,
-                            const nsAString& aTimestamp,
-                            int aSize,
-                            BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapGetMessage(BlobParent* aBlobParent,
-                       BlobChild* aBlobChild,
-                       long aMasId,
-                       BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapGetMessage(Blob* aBlob,
-                       long aMasId,
-                       BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapSetMessageStatus(long aMasId,
-                             bool aStatus,
-                             BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapSendMessage(long aMasId,
-                        const nsAString& aHandleId,
-                        bool aStatus,
-                        BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ReplyToMapMessageUpdate(
-    long aMasId, bool aStatus, BluetoothReplyRunnable* aRunnable) override;
-
-#ifdef MOZ_B2G_RIL
-  virtual void
-  AnswerWaitingCall(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  IgnoreWaitingCall(BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  ToggleCalls(BluetoothReplyRunnable* aRunnable) override;
-#endif
-
-  virtual void
-  SendMetaData(const nsAString& aTitle,
-               const nsAString& aArtist,
-               const nsAString& aAlbum,
-               int64_t aMediaNumber,
-               int64_t aTotalMediaCount,
-               int64_t aDuration,
-               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SendPlayStatus(int64_t aDuration,
-                 int64_t aPosition,
-                 ControlPlayStatus aPlayStatus,
-                 BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  UpdatePlayStatus(uint32_t aDuration,
-                   uint32_t aPosition,
-                   ControlPlayStatus aPlayStatus) override;
-
-  virtual nsresult
-  SendSinkMessage(const nsAString& aDeviceAddresses,
-                  const nsAString& aMessage) override;
-
-  virtual nsresult
-  SendInputMessage(const nsAString& aDeviceAddresses,
-                   const nsAString& aMessage) override;
-
-  virtual void
-  ConnectGattClientInternal(const BluetoothUuid& aAppUuid,
-                            const BluetoothAddress& aDeviceAddress,
-                            BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  DisconnectGattClientInternal(const BluetoothUuid& aAppUuid,
-                               const BluetoothAddress& aDeviceAddress,
-                               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  DiscoverGattServicesInternal(const BluetoothUuid& aAppUuid,
-                               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientStartNotificationsInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServId,
-    const BluetoothGattId& aCharId,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientStopNotificationsInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServId,
-    const BluetoothGattId& aCharId,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  UnregisterGattClientInternal(int aClientIf,
-                               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientReadRemoteRssiInternal(int aClientIf,
-                                   const BluetoothAddress& aDeviceAddress,
-                                   BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientReadCharacteristicValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientWriteCharacteristicValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    const BluetoothGattWriteType& aWriteType,
-    const nsTArray<uint8_t>& aValue,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientReadDescriptorValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    const BluetoothGattId& aDescriptorId,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattClientWriteDescriptorValueInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    const BluetoothGattId& aCharacteristicId,
-    const BluetoothGattId& aDescriptorId,
-    const nsTArray<uint8_t>& aValue,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerRegisterInternal(
-    const BluetoothUuid& aAppUuid,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerConnectPeripheralInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerDisconnectPeripheralInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  UnregisterGattServerInternal(int aServerIf,
-                               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerAddServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothGattServiceId& aServiceId,
-    uint16_t aHandleCount,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerAddIncludedServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aIncludedServiceHandle,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerAddCharacteristicInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothUuid& aCharacteristicUuid,
-    BluetoothGattAttrPerm aPermissions,
-    BluetoothGattCharProp aProperties,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerAddDescriptorInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    const BluetoothAttributeHandle& aCharacteristicHandle,
-    const BluetoothUuid& aDescriptorUuid,
-    BluetoothGattAttrPerm aPermissions,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerRemoveServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerStartServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerStopServiceInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAttributeHandle& aServiceHandle,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerSendResponseInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    uint16_t aStatus,
-    int32_t aRequestId,
-    const BluetoothGattResponse& aRsp,
-    BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  GattServerSendIndicationInternal(
-    const BluetoothUuid& aAppUuid,
-    const BluetoothAddress& aAddress,
-    const BluetoothAttributeHandle& aCharacteristicHandle,
-    bool aConfirm,
-    const nsTArray<uint8_t>& aValue,
-    BluetoothReplyRunnable* aRunnable) override;
-
-protected:
-  BluetoothServiceChildProcess();
-  virtual ~BluetoothServiceChildProcess();
-
-  void
-  NoteDeadActor();
-
-  void
-  NoteShutdownInitiated();
-
-  virtual nsresult
-  HandleStartup() override;
-
-  virtual nsresult
-  HandleShutdown() override;
-
-private:
-  bool
-  IsSignalRegistered(const nsAString& aNodeName) {
-    return !!mBluetoothSignalObserverTable.Get(aNodeName);
-  }
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif // mozilla_dom_bluetooth_ipc_BluetoothServiceChildProcess_h
deleted file mode 100644
--- a/dom/bluetooth/ipc/BluetoothTypes.ipdlh
+++ /dev/null
@@ -1,111 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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/. */
-
-using mozilla::dom::bluetooth::BluetoothAddress
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothAttributeHandle
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothGattAttrPerm
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothGattCharAttribute
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothGattCharProp
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothGattId
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothGattResponse
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothGattServiceId
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothGattStatus
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothGattWriteType
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothRemoteName
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothSspVariant
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothStatus
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothUuid
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-
-namespace mozilla {
-namespace dom {
-namespace bluetooth {
-
-/**
- * Value structure for returns from bluetooth. Currently modeled after dbus
- * returns, which can be a 32-bit int, an UTF16 string, a bool, or an array of
- * UTF16 strings. Can also hold key-value pairs for dictionary-ish access.
- */
-union BluetoothValue
-{
-  int32_t;
-  uint32_t;
-  nsCString;
-  nsString;
-  bool;
-  nsString[];
-  uint8_t[];
-  uint32_t[];
-  BluetoothNamedValue[];
-  BluetoothGattId;
-  BluetoothGattId[];
-  BluetoothGattServiceId;
-  BluetoothGattServiceId[];
-  BluetoothGattCharAttribute[];
-  BluetoothAddress;
-  BluetoothAddress[];
-  BluetoothAttributeHandle;
-  BluetoothRemoteName;
-  BluetoothUuid;
-  BluetoothUuid[];
-};
-
-/**
- * Key-value pair for dicts returned by the bluetooth backend. Used for things
- * like property updates, where the property will have a name and a type.
- */
-struct BluetoothNamedValue
-{
-  nsString name;
-  BluetoothValue value;
-};
-
-struct BluetoothSignal
-{
-  nsString name;
-  nsString path;
-  BluetoothValue value;
-};
-
-struct BluetoothReplySuccess
-{
-  BluetoothValue value;
-};
-
-union BluetoothErrorStatus
-{
-  BluetoothStatus;
-  BluetoothGattStatus;
-};
-
-struct BluetoothReplyError
-{
-  BluetoothErrorStatus errorStatus;
-  nsString errorString;
-};
-
-union BluetoothReply
-{
-  BluetoothReplySuccess;
-  BluetoothReplyError;
-};
-
-}
-}
-}
deleted file mode 100644
--- a/dom/bluetooth/ipc/PBluetooth.ipdl
+++ /dev/null
@@ -1,627 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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 protocol PBlob;
-include protocol PBluetoothRequest;
-include protocol PContent;
-
-include BluetoothTypes;
-
-include "mozilla/dom/bluetooth/ipc/BluetoothMessageUtils.h";
-
-using mozilla::dom::bluetooth::BluetoothAddress
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothGattAdvertisingData
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothObjectType
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothPinCode
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::ControlPlayStatus
-  from "mozilla/dom/bluetooth/BluetoothCommon.h";
-
-namespace mozilla {
-namespace dom {
-namespace bluetooth {
-
-/**
- * Bluetooth request types.
- */
-
-struct GetAdaptersRequest
-{ };
-
-struct StartBluetoothRequest
-{
-};
-
-struct StopBluetoothRequest
-{
-};
-
-struct SetPropertyRequest
-{
-  BluetoothObjectType type;
-  BluetoothNamedValue value;
-};
-
-struct GetPropertyRequest
-{
-  BluetoothObjectType type;
-  BluetoothAddress address;
-};
-
-struct StartDiscoveryRequest
-{
-};
-
-struct StopDiscoveryRequest
-{
-};
-
-struct StartLeScanRequest
-{
-  BluetoothUuid[] serviceUuids;
-};
-
-struct StopLeScanRequest
-{
-  BluetoothUuid scanUuid;
-};
-
-struct StartAdvertisingRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothGattAdvertisingData data;
-};
-
-struct StopAdvertisingRequest
-{
-  BluetoothUuid appUuid;
-};
-
-struct PairRequest
-{
-  BluetoothAddress address;
-  uint32_t timeoutMS;
-};
-
-struct UnpairRequest
-{
-  BluetoothAddress address;
-};
-
-struct PinReplyRequest
-{
-  BluetoothAddress address;
-  bool accept;
-  BluetoothPinCode pinCode;
-};
-
-struct SspReplyRequest
-{
-  BluetoothAddress address;
-  BluetoothSspVariant variant;
-  bool accept;
-};
-
-struct SetPinCodeRequest
-{
-  BluetoothAddress address;
-  BluetoothPinCode pincode;
-};
-
-struct SetPasskeyRequest
-{
-  BluetoothAddress address;
-  uint32_t passkey;
-};
-
-struct ConfirmPairingConfirmationRequest
-{
-  BluetoothAddress address;
-};
-
-struct DenyPairingConfirmationRequest
-{
-  BluetoothAddress address;
-};
-
-struct PairedDevicePropertiesRequest
-{
-  BluetoothAddress[] addresses;
-};
-
-struct ConnectedDevicePropertiesRequest
-{
-  uint16_t serviceUuid;
-};
-
-struct FetchUuidsRequest
-{
-  BluetoothAddress address;
-};
-
-struct ConnectRequest
-{
-  BluetoothAddress address;
-  uint32_t cod;
-  uint16_t serviceUuid;
-};
-
-struct DisconnectRequest
-{
-  BluetoothAddress address;
-  uint16_t serviceUuid;
-};
-
-struct SendFileRequest
-{
-  BluetoothAddress address;
-  PBlob blob;
-};
-
-struct StopSendingFileRequest
-{
-  BluetoothAddress address;
-};
-
-struct ConfirmReceivingFileRequest
-{
-  BluetoothAddress address;
-};
-
-struct DenyReceivingFileRequest
-{
-  BluetoothAddress address;
-};
-
-struct ConnectScoRequest
-{
-};
-
-struct DisconnectScoRequest
-{
-};
-
-struct IsScoConnectedRequest
-{
-};
-
-struct SetObexPasswordRequest
-{
-  nsString password;
-};
-
-struct RejectObexAuthRequest
-{
-};
-
-struct ReplyTovCardPullingRequest
-{
-  PBlob blob;
-};
-
-struct ReplyToPhonebookPullingRequest
-{
-  PBlob blob;
-  uint16_t phonebookSize;
-};
-
-struct ReplyTovCardListingRequest
-{
-  PBlob blob;
-  uint16_t phonebookSize;
-};
-
-struct ReplyToFolderListingRequest
-{
-  uint16_t masId;
-  nsString folderList;
-};
-
-struct ReplyToMessagesListingRequest
-{
-  uint16_t masId;
-  PBlob blob;
-  bool newMessage;
-  nsString timeStamp;
-  uint16_t size;
-};
-
-struct ReplyToGetMessageRequest
-{
-  uint16_t masId;
-  PBlob blob;
-};
-
-struct ReplyToSetMessageStatusRequest
-{
-  uint16_t masId;
-  bool messageStatus;
-};
-
-struct ReplyToSendMessageRequest
-{
-  uint16_t masId;
-  nsString handleId;
-  bool messageStatus;
-};
-
-struct ReplyToMessageUpdateRequest
-{
-  uint16_t masId;
-  bool messageStatus;
-};
-
-struct AnswerWaitingCallRequest
-{
-};
-
-struct IgnoreWaitingCallRequest
-{
-};
-
-struct ToggleCallsRequest
-{
-};
-
-struct SendMetaDataRequest
-{
-  nsString title;
-  nsString artist;
-  nsString album;
-  int64_t mediaNumber;
-  int64_t totalMediaCount;
-  int64_t duration;
-};
-
-struct SendPlayStatusRequest
-{
-  int64_t duration;
-  int64_t position;
-  ControlPlayStatus playStatus;
-};
-
-struct ConnectGattClientRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothAddress deviceAddress;
-};
-
-struct DisconnectGattClientRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothAddress deviceAddress;
-};
-
-struct DiscoverGattServicesRequest
-{
-  BluetoothUuid appUuid;
-};
-
-struct GattClientStartNotificationsRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothGattServiceId servId;
-  BluetoothGattId charId;
-};
-
-struct GattClientStopNotificationsRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothGattServiceId servId;
-  BluetoothGattId charId;
-};
-
-struct UnregisterGattClientRequest
-{
-  int clientIf;
-};
-
-struct GattClientReadRemoteRssiRequest
-{
-  int clientIf;
-  BluetoothAddress deviceAddress;
-};
-
-struct GattClientReadCharacteristicValueRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothGattServiceId serviceId;
-  BluetoothGattId charId;
-};
-
-struct GattClientWriteCharacteristicValueRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothGattServiceId serviceId;
-  BluetoothGattId charId;
-  BluetoothGattWriteType writeType;
-  uint8_t[] value;
-};
-
-struct GattClientReadDescriptorValueRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothGattServiceId serviceId;
-  BluetoothGattId charId;
-  BluetoothGattId descId;
-};
-
-struct GattClientWriteDescriptorValueRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothGattServiceId serviceId;
-  BluetoothGattId charId;
-  BluetoothGattId descId;
-  uint8_t[] value;
-};
-
-struct GattServerRegisterRequest
-{
-  BluetoothUuid appUuid;
-};
-
-struct GattServerConnectPeripheralRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothAddress address;
-};
-
-struct GattServerDisconnectPeripheralRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothAddress address;
-};
-
-struct UnregisterGattServerRequest
-{
-  int serverIf;
-};
-
-struct GattServerAddServiceRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothGattServiceId serviceId;
-  uint16_t handleCount;
-};
-
-struct GattServerAddIncludedServiceRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothAttributeHandle serviceHandle;
-  BluetoothAttributeHandle includedServiceHandle;
-};
-
-struct GattServerAddCharacteristicRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothAttributeHandle serviceHandle;
-  BluetoothUuid characteristicUuid;
-  BluetoothGattAttrPerm permissions;
-  BluetoothGattCharProp properties;
-};
-
-struct GattServerAddDescriptorRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothAttributeHandle serviceHandle;
-  BluetoothAttributeHandle characteristicHandle;
-  BluetoothUuid descriptorUuid;
-  BluetoothGattAttrPerm permissions;
-};
-
-struct GattServerRemoveServiceRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothAttributeHandle serviceHandle;
-};
-
-struct GattServerStartServiceRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothAttributeHandle serviceHandle;
-};
-
-struct GattServerStopServiceRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothAttributeHandle serviceHandle;
-};
-
-struct GattServerSendResponseRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothAddress address;
-  uint16_t status;
-  int32_t requestId;
-  BluetoothGattResponse response;
-};
-
-struct GattServerSendIndicationRequest
-{
-  BluetoothUuid appUuid;
-  BluetoothAddress address;
-  BluetoothAttributeHandle characteristicHandle;
-  bool confirm;
-  uint8_t[] value;
-};
-
-union Request
-{
-  GetAdaptersRequest;
-  StartBluetoothRequest;
-  StopBluetoothRequest;
-  SetPropertyRequest;
-  GetPropertyRequest;
-  StartDiscoveryRequest;
-  StopDiscoveryRequest;
-  StartLeScanRequest;
-  StopLeScanRequest;
-  StartAdvertisingRequest;
-  StopAdvertisingRequest;
-  PairRequest;
-  UnpairRequest;
-  PinReplyRequest;
-  SspReplyRequest;
-  SetPinCodeRequest;
-  SetPasskeyRequest;
-  ConfirmPairingConfirmationRequest;
-  DenyPairingConfirmationRequest;
-  ConnectedDevicePropertiesRequest;
-  PairedDevicePropertiesRequest;
-  FetchUuidsRequest;
-  ConnectRequest;
-  DisconnectRequest;
-  SendFileRequest;
-  StopSendingFileRequest;
-  ConfirmReceivingFileRequest;
-  DenyReceivingFileRequest;
-  ConnectScoRequest;
-  DisconnectScoRequest;
-  IsScoConnectedRequest;
-  SetObexPasswordRequest;
-  RejectObexAuthRequest;
-  ReplyTovCardPullingRequest;
-  ReplyToPhonebookPullingRequest;
-  ReplyTovCardListingRequest;
-  ReplyToFolderListingRequest;
-  ReplyToMessagesListingRequest;
-  ReplyToGetMessageRequest;
-  ReplyToSetMessageStatusRequest;
-  ReplyToSendMessageRequest;
-  ReplyToMessageUpdateRequest;
-  AnswerWaitingCallRequest;
-  IgnoreWaitingCallRequest;
-  ToggleCallsRequest;
-  SendMetaDataRequest;
-  SendPlayStatusRequest;
-  ConnectGattClientRequest;
-  DisconnectGattClientRequest;
-  DiscoverGattServicesRequest;
-  GattClientStartNotificationsRequest;
-  GattClientStopNotificationsRequest;
-  UnregisterGattClientRequest;
-  GattClientReadRemoteRssiRequest;
-  GattClientReadCharacteristicValueRequest;
-  GattClientWriteCharacteristicValueRequest;
-  GattClientReadDescriptorValueRequest;
-  GattClientWriteDescriptorValueRequest;
-  GattServerRegisterRequest;
-  GattServerConnectPeripheralRequest;
-  GattServerDisconnectPeripheralRequest;
-  UnregisterGattServerRequest;
-  GattServerAddServiceRequest;
-  GattServerAddIncludedServiceRequest;
-  GattServerAddCharacteristicRequest;
-  GattServerAddDescriptorRequest;
-  GattServerRemoveServiceRequest;
-  GattServerStartServiceRequest;
-  GattServerStopServiceRequest;
-  GattServerSendResponseRequest;
-  GattServerSendIndicationRequest;
-};
-
-protocol PBluetooth
-{
-  manager PContent;
-  manages PBluetoothRequest;
-
-  /**
-   * The potential exists for a racy shutdown so the following sequence of
-   * messages is used to shutdown safely:
-   *
-   *   1. [BeginShutdown]       (Parent -> Child [Optional])
-   *   2. StopNotifying         (Child  -> Parent)
-   *   3. NotificationsStopped  (Parent -> Child)
-   *   4. __delete__()          (Child  -> Parent)
-   */
-
-child:
-  /**
-   * Sent when a settings change has enabled or disabled the bluetooth firmware.
-   */
-  async Enabled(bool enabled);
-
-  /**
-   * Sent when a bluetooth signal is broadcasted to child processes.
-   */
-  async Notify(BluetoothSignal signal);
-
-  /**
-   * Sent when the parent process is about to be shut down. See shutdown note
-   * above.
-   */
-  async BeginShutdown();
-
-  /**
-   * Sent to inform the child process that it will no longer receive any
-   * messages from the parent. See shutdown note above.
-   */
-  async NotificationsStopped();
-
-parent:
-  /**
-   * Sent when the child no longer needs to use bluetooth. See shutdown note
-   * above.
-   */
-  async __delete__();
-
-  /**
-   * Sent when the child needs to receive signals related to the given node.
-   */
-  async RegisterSignalHandler(nsString node);
-
-  /**
-   * Sent when the child no longer needs to receive signals related to the given
-   * node.
-   */
-  async UnregisterSignalHandler(nsString node);
-
-  /**
-   * Sent when the child no longer needs to receive any messages from the
-   * parent. See shutdown note above.
-   */
-  async StopNotifying();
-
-  /**
-   * Sent when the child makes an asynchronous request to the parent.
-   */
-  async PBluetoothRequest(Request request);
-
-  /**
-   * FIXME: Bug 547703.
-   *
-   * This is the state machine we want:
-   *
-   * start state NOTIFYING:
-   *   send Enabled goto NOTIFYING;
-   *   send Notify goto NOTIFYING;
-   *   recv RegisterSignalHandler goto NOTIFYING;
-   *   recv UnregisterSignalHandler goto NOTIFYING;
-   *   send BeginShutdown goto PARENT_DONE;
-   *   recv StopNotifying goto CHILD_DONE;
-   *
-   * state PARENT_DONE:
-   *   recv RegisterSignalHandler goto PARENT_DONE;
-   *   recv UnregisterSignalHandler goto PARENT_DONE;
-   *   recv StopNotifying goto CHILD_DONE;
-   *
-   * state CHILD_DONE:
-   *   send Enabled goto CHILD_DONE;
-   *   send Notify goto CHILD_DONE;
-   *   send BeginShutdown goto CHILD_DONE;
-   *   send NotificationsStopped goto DONE;
-   *
-   * state DONE:
-   *   recv __delete__;
-   */
-};
-
-} // namespace bluetooth
-} // namespace dom
-} // namespace mozilla
deleted file mode 100644
--- a/dom/bluetooth/ipc/PBluetoothRequest.ipdl
+++ /dev/null
@@ -1,28 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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 protocol PBluetooth;
-
-include BluetoothTypes;
-
-namespace mozilla {
-namespace dom {
-namespace bluetooth {
-
-protocol PBluetoothRequest
-{
-  manager PBluetooth;
-
-child:
-  /**
-   * Sent when the asynchronous request has completed.
-   */
-  async __delete__(BluetoothReply response);
-};
-
-} // namespace bluetooth
-} // namespace dom
-} // namespace mozilla
deleted file mode 100644
--- a/dom/bluetooth/moz.build
+++ /dev/null
@@ -1,193 +0,0 @@
-# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
-# vim: set filetype=python:
-# 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/.
-
-if CONFIG['MOZ_B2G_BT']:
-
-    #
-    # Generic code
-    #
-
-    if CONFIG['MOZ_B2G_RIL']:
-        SOURCES += [
-            'common/BluetoothRilListener.cpp'
-        ]
-
-    SOURCES += [
-        'common/BluetoothGattReplyRunnable.cpp',
-        'common/BluetoothInterface.cpp',
-        'common/BluetoothProfileController.cpp',
-        'common/BluetoothReplyRunnable.cpp',
-        'common/BluetoothService.cpp',
-        'common/BluetoothUtils.cpp',
-        'common/BluetoothUuidHelper.cpp',
-        'common/ObexBase.cpp',
-        'common/webapi/BluetoothAdapter.cpp',
-        'common/webapi/BluetoothClassOfDevice.cpp',
-        'common/webapi/BluetoothDevice.cpp',
-        'common/webapi/BluetoothDiscoveryHandle.cpp',
-        'common/webapi/BluetoothGatt.cpp',
-        'common/webapi/BluetoothGattAttributeEvent.cpp',
-        'common/webapi/BluetoothGattCharacteristic.cpp',
-        'common/webapi/BluetoothGattDescriptor.cpp',
-        'common/webapi/BluetoothGattServer.cpp',
-        'common/webapi/BluetoothGattService.cpp',
-        'common/webapi/BluetoothLeDeviceEvent.cpp',
-        'common/webapi/BluetoothManager.cpp',
-        'common/webapi/BluetoothMapRequestHandle.cpp',
-        'common/webapi/BluetoothObexAuthHandle.cpp',
-        'common/webapi/BluetoothPairingHandle.cpp',
-        'common/webapi/BluetoothPairingListener.cpp',
-        'common/webapi/BluetoothPbapRequestHandle.cpp',
-        'common/webapi/BluetoothUUID.cpp',
-        'ipc/BluetoothChild.cpp',
-        'ipc/BluetoothParent.cpp',
-        'ipc/BluetoothServiceChildProcess.cpp'
-    ]
-    LOCAL_INCLUDES += [
-        'common',
-        'common/webapi',
-        'ipc'
-    ]
-
-    #
-    # Bluetooth backends
-    #
-
-    if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
-        if CONFIG['MOZ_B2G_BT_BLUEZ']:
-            CXXFLAGS += CONFIG['MOZ_DBUS_CFLAGS']
-            SOURCES += [
-                'bluez/BluetoothA2dpManager.cpp',
-                'bluez/BluetoothAvrcpManager.cpp',
-                'bluez/BluetoothDBusService.cpp',
-                'bluez/BluetoothHfpManager.cpp',
-                'bluez/BluetoothHidManager.cpp',
-                'bluez/BluetoothOppManager.cpp',
-                'bluez/BluetoothSocket.cpp',
-                'bluez/BluetoothUnixSocketConnector.cpp'
-            ]
-            LOCAL_INCLUDES += [
-                'bluez',
-            ]
-            LOCAL_INCLUDES += [
-                '%' + '%s/%s' % (CONFIG['ANDROID_SOURCE'], d) for d in [
-                    'external/bluetooth/bluez/lib',
-                    'external/dbus',
-                ]
-            ]
-            DEFINES['MOZ_B2G_BT_BLUEZ'] = True
-        elif CONFIG['MOZ_B2G_BT_DAEMON']:
-            SOURCES += [
-                'bluedroid/BluetoothA2dpManager.cpp',
-                'bluedroid/BluetoothAvrcpManager.cpp',
-                'bluedroid/BluetoothDaemonA2dpInterface.cpp',
-                'bluedroid/BluetoothDaemonAvrcpInterface.cpp',
-                'bluedroid/BluetoothDaemonCoreInterface.cpp',
-                'bluedroid/BluetoothDaemonGattInterface.cpp',
-                'bluedroid/BluetoothDaemonHandsfreeInterface.cpp',
-                'bluedroid/BluetoothDaemonHelpers.cpp',
-                'bluedroid/BluetoothDaemonHidInterface.cpp',
-                'bluedroid/BluetoothDaemonInterface.cpp',
-                'bluedroid/BluetoothDaemonSetupInterface.cpp',
-                'bluedroid/BluetoothDaemonSocketInterface.cpp',
-                'bluedroid/BluetoothGattManager.cpp',
-                'bluedroid/BluetoothHidManager.cpp',
-                'bluedroid/BluetoothMapBMessage.cpp',
-                'bluedroid/BluetoothMapFolder.cpp',
-                'bluedroid/BluetoothMapSmsManager.cpp',
-                'bluedroid/BluetoothOppManager.cpp',
-                'bluedroid/BluetoothPbapManager.cpp',
-                'bluedroid/BluetoothServiceBluedroid.cpp',
-                'bluedroid/BluetoothSocket.cpp',
-                'bluedroid/BluetoothSocketMessageWatcher.cpp'
-            ]
-            LOCAL_INCLUDES += [
-                'bluedroid',
-            ]
-
-            if CONFIG['MOZ_B2G_RIL']:
-                SOURCES += [
-                    'bluedroid/hfp/BluetoothHfpManager.cpp',
-                ]
-                LOCAL_INCLUDES += [
-                    'bluedroid/hfp',
-                ]
-            else:
-                SOURCES += [
-                    'bluedroid/hfp-fallback/BluetoothHfpManager.cpp',
-                ]
-                LOCAL_INCLUDES += [
-                    'bluedroid/hfp-fallback',
-                ]
-
-            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',
-        ]
-        LOCAL_INCLUDES += [
-            'bluez',
-        ]
-        DEFINES['MOZ_BLUETOOTH_DBUS'] = True
-        DEFINES['HAVE_PTHREADS'] = True
-
-#
-# Exported interfaces
-#
-
-EXPORTS.mozilla.dom.bluetooth.ipc += [
-    'ipc/BluetoothMessageUtils.h',
-]
-EXPORTS.mozilla.dom.bluetooth += [
-    'common/BluetoothCommon.h',
-    'common/BluetoothGattUUIDName.h',
-    'common/BluetoothHashKeys.h',
-    'common/webapi/BluetoothAdapter.h',
-    'common/webapi/BluetoothClassOfDevice.h',
-    'common/webapi/BluetoothDevice.h',
-    'common/webapi/BluetoothDiscoveryHandle.h',
-    'common/webapi/BluetoothGatt.h',
-    'common/webapi/BluetoothGattAttributeEvent.h',
-    'common/webapi/BluetoothGattCharacteristic.h',
-    'common/webapi/BluetoothGattDescriptor.h',
-    'common/webapi/BluetoothGattServer.h',
-    'common/webapi/BluetoothGattService.h',
-    'common/webapi/BluetoothLeDeviceEvent.h',
-    'common/webapi/BluetoothManager.h',
-    'common/webapi/BluetoothMapRequestHandle.h',
-    'common/webapi/BluetoothObexAuthHandle.h',
-    'common/webapi/BluetoothPairingHandle.h',
-    'common/webapi/BluetoothPairingListener.h',
-    'common/webapi/BluetoothPbapRequestHandle.h'
-]
-EXPORTS.mozilla.dom += [
-    'common/webapi/BluetoothUUID.h'
-]
-
-UNIFIED_SOURCES += [
-    'common/BluetoothCommon.cpp',
-]
-
-IPDL_SOURCES += [
-    'ipc/BluetoothTypes.ipdlh',
-    'ipc/PBluetooth.ipdl',
-    'ipc/PBluetoothRequest.ipdl'
-]
-
-LOCAL_INCLUDES += [
-    '../base',
-    '../network',
-    '../system/gonk'
-]
-
-include('/ipc/chromium/chromium-config.mozbuild')
-
-FINAL_LIBRARY = 'xul'
deleted file mode 100644
--- a/dom/bluetooth/tests/marionette/head.js
+++ /dev/null
@@ -1,910 +0,0 @@
-/* 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/. */
-
-// https://github.com/mozilla-b2g/platform_external_qemu/blob/master/vl-android.c#L765
-// static int bt_hci_parse(const char *str) {
-//   ...
-//   bdaddr.b[0] = 0x52;
-//   bdaddr.b[1] = 0x54;
-//   bdaddr.b[2] = 0x00;
-//   bdaddr.b[3] = 0x12;
-//   bdaddr.b[4] = 0x34;
-//   bdaddr.b[5] = 0x56 + nb_hcis;
-const EMULATOR_ADDRESS = "56:34:12:00:54:52";
-
-// $ adb shell hciconfig /dev/ttyS2 name
-// hci0:  Type: BR/EDR  Bus: UART
-//        BD Address: 56:34:12:00:54:52  ACL MTU: 512:1  SCO MTU: 0:0
-//        Name: 'Full Android on Emulator'
-const EMULATOR_NAME = "Full Android on Emulator";
-
-// $ adb shell hciconfig /dev/ttyS2 class
-// hci0:  Type: BR/EDR  Bus: UART
-//        BD Address: 56:34:12:00:54:52  ACL MTU: 512:1  SCO MTU: 0:0
-//        Class: 0x58020c
-//        Service Classes: Capturing, Object Transfer, Telephony
-//        Device Class: Phone, Smart phone
-const EMULATOR_CLASS = 0x58020c;
-
-// Use same definition in QEMU for special bluetooth address,
-// which were defined at external/qemu/hw/bt.h:
-const BDADDR_ANY   = "00:00:00:00:00:00";
-const BDADDR_ALL   = "ff:ff:ff:ff:ff:ff";
-const BDADDR_LOCAL = "ff:ff:ff:00:00:00";
-
-// A user friendly name for remote BT device.
-const REMOTE_DEVICE_NAME = "Remote_BT_Device";
-
-// Emulate Promise.jsm semantics.
-Promise.defer = function() { return new Deferred(); }
-function Deferred()  {
-  this.promise = new Promise(function(resolve, reject) {
-    this.resolve = resolve;
-    this.reject = reject;
-  }.bind(this));
-  Object.freeze(this);
-}
-
-var bluetoothManager;
-
-var pendingEmulatorCmdCount = 0;
-
-/**
- * Push required permissions and test if |navigator.mozBluetooth| exists.
- * Resolve if it does, reject otherwise.
- *
- * Fulfill params:
- *   bluetoothManager -- an reference to navigator.mozBluetooth.
- * Reject params: (none)
- *
- * @param aPermissions
- *        Additional permissions to push before any test cases.  Could be either
- *        a string or an array of strings.
- *
- * @return A deferred promise.
- */
-function ensureBluetoothManager(aPermissions) {
-  let deferred = Promise.defer();
-
-  let permissions = ["bluetooth"];
-  if (aPermissions) {
-    if (Array.isArray(aPermissions)) {
-      permissions = permissions.concat(aPermissions);
-    } else if (typeof aPermissions == "string") {
-      permissions.push(aPermissions);
-    }
-  }
-
-  let obj = [];
-  for (let perm of permissions) {
-    obj.push({
-      "type": perm,
-      "allow": 1,
-      "context": document,
-    });
-  }
-
-  SpecialPowers.pushPermissions(obj, function() {
-    ok(true, "permissions pushed: " + JSON.stringify(permissions));
-
-    bluetoothManager = window.navigator.mozBluetooth;
-    log("navigator.mozBluetooth is " +
-        (bluetoothManager ? "available" : "unavailable"));
-
-    if (bluetoothManager instanceof BluetoothManager) {
-      deferred.resolve(bluetoothManager);
-    } else {
-      deferred.reject();
-    }
-  });
-
-  return deferred.promise;
-}
-
-/**
- * Send emulator command with safe guard.
- *
- * We should only call |finish()| after all emulator command transactions
- * end, so here comes with the pending counter.  Resolve when the emulator
- * gives positive response, and reject otherwise.
- *
- * Fulfill params:
- *   result -- an array of emulator response lines.
- *
- * Reject params:
- *   result -- an array of emulator response lines.
- *
- * @return A deferred promise.
- */
-function runEmulatorCmdSafe(aCommand) {
-  let deferred = Promise.defer();
-
-  ++pendingEmulatorCmdCount;
-  runEmulatorCmd(aCommand, function(aResult) {
-    --pendingEmulatorCmdCount;
-
-    ok(true, "Emulator response: " + JSON.stringify(aResult));
-    if (Array.isArray(aResult) && aResult[aResult.length - 1] === "OK") {
-      deferred.resolve(aResult);
-    } else {
-      ok(false, "Got an abnormal response from emulator.");
-      log("Fail to execute emulator command: [" + aCommand + "]");
-      deferred.reject(aResult);
-    }
-  });
-
-  return deferred.promise;
-}
-
-/**
- * Add a Bluetooth remote device to scatternet and set its properties.
- *
- * Use QEMU command 'bt remote add' to add a virtual Bluetooth remote
- * and set its properties by setEmulatorDeviceProperty().
- *
- * Fulfill params:
- *   result -- bluetooth address of the remote device.
- * Reject params: (none)
- *
- * @param aProperies
- *        A javascript object with zero or several properties for initializing
- *        the remote device. By now, the properies could be 'name' or
- *        'discoverable'. It valid to put a null object or a javascript object
- *        which don't have any properies.
- *
- * @return A promise object.
- */
-function addEmulatorRemoteDevice(aProperties) {
-  let address;
-  let promise = runEmulatorCmdSafe("bt remote add")
-    .then(function(aResults) {
-      address = aResults[0].toUpperCase();
-    });
-
-  for (let key in aProperties) {
-    let value = aProperties[key];
-    let propertyName = key;
-    promise = promise.then(function() {
-      return setEmulatorDeviceProperty(address, propertyName, value);
-    });
-  }
-
-  return promise.then(function() {
-    return address;
-  });
-}
-
-/**
- * Remove Bluetooth remote devices in scatternet.
- *
- * Use QEMU command 'bt remote remove <addr>' to remove a specific virtual
- * Bluetooth remote device in scatternet or remove them all by  QEMU command
- * 'bt remote remove BDADDR_ALL'.
- *
- * @param aAddress
- *        The string of Bluetooth address with format xx:xx:xx:xx:xx:xx.
- *
- * Fulfill params:
- *   result -- an array of emulator response lines.
- * Reject params: (none)
- *
- * @return A promise object.
- */
-function removeEmulatorRemoteDevice(aAddress) {
-  let cmd = "bt remote remove " + aAddress;
-  return runEmulatorCmdSafe(cmd)
-    .then(function(aResults) {
-      // 'bt remote remove <bd_addr>' returns a list of removed device one at a line.
-      // The last item is "OK".
-      return aResults.slice(0, -1);
-    });
-}
-
-/**
- * Set a property for a Bluetooth device.
- *
- * Use QEMU command 'bt property <bd_addr> <prop_name> <value>' to set property.
- *
- * Fulfill params:
- *   result -- an array of emulator response lines.
- * Reject params:
- *   result -- an array of emulator response lines.
- *
- * @param aAddress
- *        The string of Bluetooth address with format xx:xx:xx:xx:xx:xx.
- * @param aPropertyName
- *        The property name of Bluetooth device.
- * @param aValue
- *        The new value of the specifc property.
- *
- * @return A deferred promise.
- */
-function setEmulatorDeviceProperty(aAddress, aPropertyName, aValue) {
-  let cmd = "bt property " + aAddress + " " + aPropertyName + " " + aValue;
-  return runEmulatorCmdSafe(cmd);
-}
-
-/**
- * Get a property from a Bluetooth device.
- *
- * Use QEMU command 'bt property <bd_addr> <prop_name>' to get properties.
- *
- * Fulfill params:
- *   result -- a string with format <prop_name>: <value_of_prop>
- * Reject params:
- *   result -- an array of emulator response lines.
- *
- * @param aAddress
- *        The string of Bluetooth address with format xx:xx:xx:xx:xx:xx.
- * @param aPropertyName
- *        The property name of Bluetooth device.
- *
- * @return A deferred promise.
- */
-function getEmulatorDeviceProperty(aAddress, aPropertyName) {
-  let cmd = "bt property " + aAddress + " " + aPropertyName;
-  return runEmulatorCmdSafe(cmd)
-    .then(function(aResults) {
-      return aResults[0];
-    });
-}
-
-/**
- * Get mozSettings value specified by @aKey.
- *
- * Resolve if that mozSettings value is retrieved successfully, reject
- * otherwise.
- *
- * Fulfill params:
- *   The corresponding mozSettings value of the key.
- * Reject params: (none)
- *
- * @param aKey
- *        A string.
- *
- * @return A deferred promise.
- */
-function getSettings(aKey) {
-  let deferred = Promise.defer();
-
-  let request = navigator.mozSettings.createLock().get(aKey);
-  request.addEventListener("success", function(aEvent) {
-    ok(true, "getSettings(" + aKey + ")");
-    deferred.resolve(aEvent.target.result[aKey]);
-  });
-  request.addEventListener("error", function() {
-    ok(false, "getSettings(" + aKey + ")");
-    deferred.reject();
-  });
-
-  return deferred.promise;
-}
-
-/**
- * Set mozSettings values.
- *
- * Resolve if that mozSettings value is set successfully, reject otherwise.
- *
- * Fulfill params: (none)
- * Reject params: (none)
- *
- * @param aSettings
- *        An object of format |{key1: value1, key2: value2, ...}|.
- *
- * @return A deferred promise.
- */
-function setSettings(aSettings) {
-  let lock = window.navigator.mozSettings.createLock();
-  let request = lock.set(aSettings);
-  let deferred = Promise.defer();
-  lock.onsettingstransactionsuccess = function () {
-    ok(true, "setSettings(" + JSON.stringify(aSettings) + ")");
-    deferred.resolve();
-  };
-  lock.onsettingstransactionfailure = function (aEvent) {
-    ok(false, "setSettings(" + JSON.stringify(aSettings) + ")");
-    deferred.reject();
-  };
-  return deferred.promise;
-}
-
-/**
- * Get the boolean value which indicates defaultAdapter of bluetooth is enabled.
- *
- * Resolve if that defaultAdapter is enabled
- *
- * Fulfill params:
- *   A boolean value.
- * Reject params: (none)
- *
- * @return A deferred promise.
- */
-function getBluetoothEnabled() {
-  log("bluetoothManager.defaultAdapter.state: " + bluetoothManager.defaultAdapter.state);
-
-  return (bluetoothManager.defaultAdapter.state == "enabled");
-}
-
-/**
- * Set mozSettings value of 'bluetooth.enabled'.
- *
- * Resolve if that mozSettings value is set successfully, reject otherwise.
- *
- * Fulfill params: (none)
- * Reject params: (none)
- *
- * @param aEnabled
- *        A boolean value.
- *
- * @return A deferred promise.
- */
-function setBluetoothEnabled(aEnabled) {
-  let obj = {};
-  obj["bluetooth.enabled"] = aEnabled;
-  return setSettings(obj);
-}
-
-/**
- * Wait for one named BluetoothManager event.
- *
- * Resolve if that named event occurs. Never reject.
- *
- * Fulfill params: the DOMEvent passed.
- *
- * @param aEventName
- *        The name of the EventHandler.
- *
- * @return A deferred promise.
- */
-function waitForManagerEvent(aEventName) {
-  let deferred = Promise.defer();
-
-  bluetoothManager.addEventListener(aEventName, function onevent(aEvent) {
-    bluetoothManager.removeEventListener(aEventName, onevent);
-
-    ok(true, "BluetoothManager event '" + aEventName + "' got.");
-    deferred.resolve(aEvent);
-  });
-
-  return deferred.promise;
-}
-
-/**
- * Wait for one named BluetoothAdapter event.
- *
- * Resolve if that named event occurs. Never reject.
- *
- * Fulfill params: the DOMEvent passed.
- *
- * @param aAdapter
- *        The BluetoothAdapter you want to use.
- * @param aEventName
- *        The name of the EventHandler.
- *
- * @return A deferred promise.
- */
-function waitForAdapterEvent(aAdapter, aEventName) {
-  let deferred = Promise.defer();
-
-  aAdapter.addEventListener(aEventName, function onevent(aEvent) {
-    aAdapter.removeEventListener(aEventName, onevent);
-
-    ok(true, "BluetoothAdapter event '" + aEventName + "' got.");
-    deferred.resolve(aEvent);
-  });
-
-  return deferred.promise;
-}
-
-/**
- * Wait for 'onattributechanged' events for state changes of BluetoothAdapter
- * with specified order.
- *
- * Resolve if those expected events occur in order. Never reject.
- *
- * Fulfill params: an array which contains every changed attributes during
- *                 the waiting.
- *
- * @param aAdapter
- *        The BluetoothAdapter you want to use.
- * @param aStateChangesInOrder
- *        An array which contains an expected order of BluetoothAdapterState.
- *        Example 1: [enabling, enabled]
- *        Example 2: [disabling, disabled]
- *
- * @return A deferred promise.
- */
-function waitForAdapterStateChanged(aAdapter, aStateChangesInOrder) {
-  let deferred = Promise.defer();
-
-  let stateIndex = 0;
-  let prevStateIndex = 0;
-  let statesArray = [];
-  let changedAttrs = [];
-  aAdapter.onattributechanged = function(aEvent) {
-    for (let i in aEvent.attrs) {
-      changedAttrs.push(aEvent.attrs[i]);
-      switch (aEvent.attrs[i]) {
-        case "state":
-          log("  'state' changed to " + aAdapter.state);
-
-          // Received state change order may differ from expected one even though
-          // state changes in expected order, because the value of state may change
-          // again before we receive prior 'onattributechanged' event.
-          //
-          // For example, expected state change order [A,B,C] may result in
-          // received ones:
-          // - [A,C,C] if state becomes C before we receive 2nd 'onattributechanged'
-          // - [B,B,C] if state becomes B before we receive 1st 'onattributechanged'
-          // - [C,C,C] if state becomes C before we receive 1st 'onattributechanged'
-          // - [A,B,C] if all 'onattributechanged' are received in perfect timing
-          //
-          // As a result, we ensure only following conditions instead of exactly
-          // matching received and expected state change order.
-          // - Received state change order never reverse expected one. For example,
-          //   [B,A,C] should never occur with expected state change order [A,B,C].
-          // - The changed value of state in received state change order never
-          //   appears later than that in expected one. For example, [A,A,C] should
-          //   never occur with expected state change order [A,B,C].
-          let stateIndex = aStateChangesInOrder.indexOf(aAdapter.state);
-          if (stateIndex >= prevStateIndex && stateIndex + 1 > statesArray.length) {
-            statesArray.push(aAdapter.state);
-            prevStateIndex = stateIndex;
-
-            if (statesArray.length == aStateChangesInOrder.length) {
-              aAdapter.onattributechanged = null;
-              ok(true, "BluetoothAdapter event 'onattributechanged' got.");
-              deferred.resolve(changedAttrs);
-            }
-          } else {
-            ok(false, "The order of 'onattributechanged' events is unexpected.");
-          }
-
-          break;
-        case "name":
-          log("  'name' changed to " + aAdapter.name);
-          if (aAdapter.state == "enabling") {
-            isnot(aAdapter.name, "", "adapter.name");
-          }
-          else if (aAdapter.state == "disabling") {
-            is(aAdapter.name, "", "adapter.name");
-          }
-          break;
-        case "address":
-          log("  'address' changed to " + aAdapter.address);
-          if (aAdapter.state == "enabling") {
-            isnot(aAdapter.address, "", "adapter.address");
-          }
-          else if (aAdapter.state == "disabling") {
-            is(aAdapter.address, "", "adapter.address");
-          }
-          break;
-        case "discoverable":
-          log("  'discoverable' changed to " + aAdapter.discoverable);
-          if (aAdapter.state == "enabling") {
-            is(aAdapter.discoverable, true, "adapter.discoverable");
-          }
-          else if (aAdapter.state == "disabling") {
-            is(aAdapter.discoverable, false, "adapter.discoverable");
-          }
-          break;
-        case "discovering":
-          log("  'discovering' changed to " + aAdapter.discovering);
-          if (aAdapter.state == "enabling") {
-            is(aAdapter.discovering, true, "adapter.discovering");
-          }
-          else if (aAdapter.state == "disabling") {
-            is(aAdapter.discovering, false, "adapter.discovering");
-          }
-          break;
-        case "unknown":
-        default:
-          ok(false, "Unknown attribute '" + aEvent.attrs[i] + "' changed." );
-          break;
-      }
-    }
-  };
-
-  return deferred.promise;
-}
-
-/**
- * Wait for an 'onattributechanged' event for a specified attribute and compare
- * the new value with the expected value.
- *
- * Resolve if the specified event occurs. Never reject.
- *
- * Fulfill params: a BluetoothAttributeEvent with property attrs that contains
- *                 changed BluetoothAdapterAttributes.
- *
- * @param aAdapter
- *        The BluetoothAdapter you want to use.
- * @param aAttrName
- *        The name of the attribute of adapter.
- * @param aExpectedValue
- *        The expected new value of the attribute.
- *
- * @return A deferred promise.
- */
-function waitForAdapterAttributeChanged(aAdapter, aAttrName, aExpectedValue) {
-  let deferred = Promise.defer();
-
-  aAdapter.onattributechanged = function(aEvent) {
-    let i = aEvent.attrs.indexOf(aAttrName);
-    if (i >= 0) {
-      switch (aEvent.attrs[i]) {
-        case "state":
-          log("  'state' changed to " + aAdapter.state);
-          is(aAdapter.state, aExpectedValue, "adapter.state");
-          break;
-        case "name":
-          log("  'name' changed to " + aAdapter.name);
-          is(aAdapter.name, aExpectedValue, "adapter.name");
-          break;
-        case "address":
-          log("  'address' changed to " + aAdapter.address);
-          is(aAdapter.address, aExpectedValue, "adapter.address");
-          break;
-        case "discoverable":
-          log("  'discoverable' changed to " + aAdapter.discoverable);
-          is(aAdapter.discoverable, aExpectedValue, "adapter.discoverable");
-          break;
-        case "discovering":
-          log("  'discovering' changed to " + aAdapter.discovering);
-          is(aAdapter.discovering, aExpectedValue, "adapter.discovering");
-          break;
-        case "unknown":
-        default:
-          ok(false, "Unknown attribute '" + aAttrName + "' changed." );
-          break;
-      }
-      aAdapter.onattributechanged = null;
-      deferred.resolve(aEvent);
-    }
-  };
-
-  return deferred.promise;
-}
-
-/**
- * Wait for specified number of 'devicefound' events.
- *
- * Resolve if specified number of devices has been found. Never reject.
- *
- * Fulfill params: an array which contains BluetoothDeviceEvents that we
- *                 received from the BluetoothDiscoveryHandle.
- *
- * @param aDiscoveryHandle
- *        A BluetoothDiscoveryHandle which is used to notify application of
- *        discovered remote bluetooth devices.
- * @param aExpectedNumberOfDevices
- *        The number of remote devices we expect to discover.
- *
- * @return A deferred promise.
- */
-function waitForDevicesFound(aDiscoveryHandle, aExpectedNumberOfDevices) {
-  let deferred = Promise.defer();
-
-  ok(aDiscoveryHandle instanceof BluetoothDiscoveryHandle,
-    "aDiscoveryHandle should be a BluetoothDiscoveryHandle");
-
-  let devicesArray = [];
-  aDiscoveryHandle.ondevicefound = function onDeviceFound(aEvent) {
-    ok(aEvent instanceof BluetoothDeviceEvent,
-      "aEvent should be a BluetoothDeviceEvent");
-
-    devicesArray.push(aEvent);
-    if (devicesArray.length >= aExpectedNumberOfDevices) {
-      aDiscoveryHandle.ondevicefound = null;
-      deferred.resolve(devicesArray);
-    }
-  };
-
-  return deferred.promise;
-}
-
-/**
- * Wait for 'devicefound' events of specified devices.
- *
- * Resolve if every specified device has been found. Never reject.
- *
- * Fulfill params: an array which contains the BluetoothDeviceEvents that we
- *                 expected to receive from the BluetoothDiscoveryHandle.
- *
- * @param aDiscoveryHandle
- *        A BluetoothDiscoveryHandle which is used to notify application of
- *        discovered remote bluetooth devices.
- * @param aRemoteAddresses
- *        An array which contains addresses of remote devices.
- *
- * @return A deferred promise.
- */
-function waitForSpecifiedDevicesFound(aDiscoveryHandle, aRemoteAddresses) {
-  let deferred = Promise.defer();
-
-  ok(aDiscoveryHandle instanceof BluetoothDiscoveryHandle,
-    "aDiscoveryHandle should be a BluetoothDiscoveryHandle");
-
-  let devicesArray = [];
-  aDiscoveryHandle.ondevicefound = function onDeviceFound(aEvent) {
-    ok(aEvent instanceof BluetoothDeviceEvent,
-      "aEvent should be a BluetoothDeviceEvent");
-
-    if (aRemoteAddresses.indexOf(aEvent.device.address) != -1) {
-      devicesArray.push(aEvent);
-    }
-    if (devicesArray.length == aRemoteAddresses.length) {
-      aDiscoveryHandle.ondevicefound = null;
-      ok(true, "BluetoothAdapter has found all remote devices.");
-      deferred.resolve(devicesArray);
-    }
-  };
-
-  return deferred.promise;
-}
-
-/**
- * Verify the correctness of 'devicepaired' or 'deviceunpaired' events.
- *
- * Use BluetoothAdapter.getPairedDevices() to get current device array.
- * Resolve if the device of from 'devicepaired' event exists in device array or
- * the device of address from 'deviceunpaired' event has been removed from
- * device array.
- * Otherwise, reject the promise.
- *
- * Fulfill params: the device event from 'devicepaired' or 'deviceunpaired'.
- *
- * @param aAdapter
- *        The BluetoothAdapter you want to use.
- * @param aDeviceEvent
- *        The device event from "devicepaired" or "deviceunpaired".
- *
- * @return A deferred promise.
- */
-function verifyDevicePairedUnpairedEvent(aAdapter, aDeviceEvent) {
-  let deferred = Promise.defer();
-
-  let devices = aAdapter.getPairedDevices();
-  let isPromisePending = true;
-  if (aDeviceEvent.device) {
-    log("  - Verify 'devicepaired' event");
-    for (let i in devices) {
-      if (devices[i].address == aDeviceEvent.device.address) {
-        deferred.resolve(aDeviceEvent);
-        isPromisePending = false;
-      }
-    }
-    if (isPromisePending) {
-      deferred.reject(aDeviceEvent);
-      isPromisePending = false;
-    }
-  } else if (aDeviceEvent.address) {
-    log("  - Verify 'deviceunpaired' event");
-    for (let i in devices) {
-      if (devices[i].address == aDeviceEvent.address) {
-        deferred.reject(aDeviceEvent);
-        isPromisePending = false;
-      }
-    }
-    if (isPromisePending) {
-      deferred.resolve(aDeviceEvent);
-      isPromisePending = false;
-    }
-  } else {
-    log("  - Exception occurs. Unexpected aDeviceEvent properties.");
-    deferred.reject(aDeviceEvent);
-    isPromisePending = false;
-  }
-
-  return deferred.promise;
-}
-
-/**
- * Add event handlers for pairing request listener.
- *
- * @param aAdapter
- *        The BluetoothAdapter you want to use.
- * @param aSpecifiedBdAddress (optional)
- *        Bluetooth address of the specified remote device which adapter wants
- *        to pair with. If aSpecifiedBdAddress is an empty string, 'null' or
- *        'undefined', this function accepts every pairing request.
- */
-function addEventHandlerForPairingRequest(aAdapter, aSpecifiedBdAddress) {
-  log("  - Add event handlers for pairing requests.");
-
-  aAdapter.pairingReqs.ondisplaypasskeyreq = function onDisplayPasskeyReq(evt) {
-    let passkey = evt.handle.passkey; // passkey to display
-    ok(typeof passkey === 'string', "type checking for passkey.");
-    log("  - Received 'ondisplaypasskeyreq' event with passkey: " + passkey);
-
-    let device = evt.device;
-    if (!aSpecifiedBdAddress || device.address == aSpecifiedBdAddress) {
-      cleanupPairingListener(aAdapter.pairingReqs);
-    }
-  };
-
-  aAdapter.pairingReqs.onenterpincodereq = function onEnterPinCodeReq(evt) {
-    log("  - Received 'onenterpincodereq' event.");
-
-    let device = evt.device;
-    if (!aSpecifiedBdAddress || device.address == aSpecifiedBdAddress) {
-      // TODO: Allow user to enter pincode.
-      let UserEnteredPinCode = "0000";
-      let pinCode = UserEnteredPinCode;
-
-      evt.handle.setPinCode(pinCode).then(
-        function onResolve() {
-          log("  - 'setPinCode' resolve.");
-          cleanupPairingListener(aAdapter.pairingReqs);
-        },
-        function onReject() {
-          log("  - 'setPinCode' reject.");
-          cleanupPairingListener(aAdapter.pairingReqs);
-        });
-    }
-  };
-
-  aAdapter.pairingReqs.onpairingconfirmationreq
-    = function onPairingConfirmationReq(evt) {
-    let passkey = evt.handle.passkey; // passkey for user to confirm
-    ok(typeof passkey === 'string', "type checking for passkey.");
-    log("  - Received 'onpairingconfirmationreq' event with passkey: " + passkey);
-
-    let device = evt.device;
-    if (!aSpecifiedBdAddress || device.address == aSpecifiedBdAddress) {
-      evt.handle.accept().then(
-        function onResolve() {
-          log("  - 'accept' resolve.");
-          cleanupPairingListener(aAdapter.pairingReqs);
-        },
-        function onReject() {
-          log("  - 'accept' reject.");
-          cleanupPairingListener(aAdapter.pairingReqs);
-        });
-    }
-  };
-
-  aAdapter.pairingReqs.onpairingconsentreq = function onPairingConsentReq(evt) {
-    log("  - Received 'onpairingconsentreq' event.");
-
-    let device = evt.device;
-    if (!aSpecifiedBdAddress || device.address == aSpecifiedBdAddress) {
-      evt.handle.accept().then(
-        function onResolve() {
-          log("  - 'accept' resolve.");
-          cleanupPairingListener(aAdapter.pairingReqs);
-        },
-        function onReject() {
-          log("  - 'accept' reject.");
-          cleanupPairingListener(aAdapter.pairingReqs);
-        });
-    }
-  };
-}
-
-/**
- * Clean up event handlers for pairing listener.
- *
- * @param aPairingReqs
- *        A BluetoothPairingListener with event handlers.
- */
-function cleanupPairingListener(aPairingReqs) {
-  aPairingReqs.ondisplaypasskeyreq = null;
-  aPairingReqs.onenterpasskeyreq = null;
-  aPairingReqs.onpairingconfirmationreq = null;
-  aPairingReqs.onpairingconsentreq = null;
-}
-
-/**
- * Compare two uuid arrays to see if them are the same.
- *
- * @param aUuidArray1
- *        An array which contains uuid strings.
- * @param aUuidArray2
- *        Another array which contains uuid strings.
- *
- * @return A boolean value.
- */
-function isUuidsEqual(aUuidArray1, aUuidArray2) {
-  if (!Array.isArray(aUuidArray1) || !Array.isArray(aUuidArray2)) {
-    return false;
-  }
-
-  if (aUuidArray1.length != aUuidArray2.length) {
-    return false;
-  }
-
-  for (let i = 0, l = aUuidArray1.length; i < l; i++) {
-    if (aUuidArray1[i] != aUuidArray2[i]) {
-      return false;
-    }
-  }
-  return true;
-}
-
-/**
- * Wait for pending emulator transactions and call |finish()|.
- */
-function cleanUp() {
-  // Use ok here so that we have at least one test run.
-  ok(true, ":: CLEANING UP ::");
-
-  waitFor(finish, function() {
-    return pendingEmulatorCmdCount === 0;
-  });
-}
-
-function startBluetoothTestBase(aPermissions, aTestCaseMain) {
-  ensureBluetoothManager(aPermissions)
-    .then(function() {
-      log("Wait for creating bluetooth adapter...");
-      return waitForManagerStateChanged(bluetoothManager);
-    })
-    .then(aTestCaseMain)
-    .then(cleanUp, function() {
-      ok(false, "Unhandled rejected promise.");
-      cleanUp();
-    });
-}
-
-function startBluetoothTest(aReenable, aTestCaseMain) {
-  startBluetoothTestBase([], function() {
-    let origEnabled, needEnable;
-    return Promise.resolve()
-      .then(function() {
-        origEnabled = getBluetoothEnabled();
-
-        needEnable = !origEnabled;
-        log("Original state of bluetooth is " + bluetoothManager.defaultAdapter.state);
-
-        if (origEnabled && aReenable) {
-          log("Disable Bluetooth ...");
-          needEnable = true;
-
-          isnot(bluetoothManager.defaultAdapter, null,
-            "bluetoothManager.defaultAdapter")
-
-          return bluetoothManager.defaultAdapter.disable();
-        }
-      })
-      .then(function() {
-        if (needEnable) {
-          log("Enable Bluetooth ...");
-
-          isnot(bluetoothManager.defaultAdapter, null,
-            "bluetoothManager.defaultAdapter")
-
-          return bluetoothManager.defaultAdapter.enable();
-        }
-      })
-      .then(() => bluetoothManager.defaultAdapter)
-      .then(aTestCaseMain)
-      .then(function() {
-        if (!origEnabled) {
-          log("Disable Bluetooth ...");
-
-          return bluetoothManager.defaultAdapter.disable();
-        }
-      });
-  });
-}
-
-function waitForManagerStateChanged(aManager) {
-  let deferred = Promise.defer();
-
-  aManager.onattributechanged = function(evt) {
-    for (var i in evt.attrs) {
-      switch (evt.attrs[i]) {
-        case 'defaultAdapter':
-          deferred.resolve(evt);
-          break;
-        default:
-          break;
-      }
-    }
-  }
-
-  return deferred.promise;
-}
-
deleted file mode 100644
--- a/dom/bluetooth/tests/marionette/manifest.ini
+++ /dev/null
@@ -1,18 +0,0 @@
-[DEFAULT]
-run-if = buildapp == 'b2g'
-
-[test_dom_BluetoothManager.js]
-skip-if = android_version < '19'
-[test_dom_BluetoothAdapter_enable.js]
-skip-if = android_version < '19'
-[test_dom_BluetoothAdapter_setters.js]
-skip-if = android_version < '19'
-[test_dom_BluetoothDevice.js]
-skip-if = true # Bug 1175389
-
-[test_dom_BluetoothAdapter_discovery.js]
-skip-if = true # Bug 1175389
-
-[test_dom_BluetoothAdapter_pair.js]
-skip-if = true # Bug 1175389
-
deleted file mode 100644
--- a/dom/bluetooth/tests/marionette/test_dom_BluetoothAdapter_discovery.js
+++ /dev/null
@@ -1,124 +0,0 @@
-/* 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/. */
-
-///////////////////////////////////////////////////////////////////////////////
-// Test Purpose:
-//   To verify the discovery process of BluetoothAdapter.
-//   Testers have to put the B2G devices in an environment which is surrounded
-//   by N discoverable remote devices. To pass this test, the number N has to be
-//   greater or equals than EXPECTED_NUMBER_OF_REMOTE_DEVICES.
-//
-// Test Procedure:
-//   [0] Set Bluetooth permission and enable default adapter.
-//   [1] Start discovery and verify the correctness.
-//   [2] Attach event handler for 'ondevicefound'.
-//   [3] Stop discovery and verify the correctness.
-//   [4] Mark the BluetoothDiscoveryHandle from [1] as expired.
-//   [5] Start discovery and verify the correctness.
-//   [6] Wait for 'devicefound' events.
-//   [7] Stop discovery and verify the correctness.
-//   [8] Call 'startDiscovery' twice continuously.
-//   [9] Call 'stopDiscovery' twice continuously.
-//   [10] Clean up the event handler of [2].
-//
-// Test Coverage:
-//   - BluetoothAdapter.discovering
-//   - BluetoothAdapter.startDiscovery()
-//   - BluetoothAdapter.stopDiscovery()
-//   - BluetoothAdapter.onattributechanged()
-//   - BluetoothDiscoveryHandle.ondevicefound()
-//
-///////////////////////////////////////////////////////////////////////////////
-
-MARIONETTE_TIMEOUT = 60000;
-MARIONETTE_HEAD_JS = 'head.js';
-
-const EXPECTED_NUMBER_OF_REMOTE_DEVICES = 2;
-
-startBluetoothTest(true, function testCaseMain(aAdapter) {
-  log("Checking adapter attributes ...");
-
-  is(aAdapter.state, "enabled", "adapter.state");
-  isnot(aAdapter.address, "", "adapter.address");
-
-  // Since adapter has just been re-enabled, these properties should be 'false'.
-  is(aAdapter.discovering, false, "adapter.discovering");
-  is(aAdapter.discoverable, false, "adapter.discoverable");
-
-  log("adapter.address: " + aAdapter.address);
-  log("adapter.name: " + aAdapter.name);
-
-  let discoveryHandle = null;
-  return Promise.resolve()
-    .then(function() {
-      log("[1] Start discovery and verify the correctness ... ");
-      let promises = [];
-      promises.push(waitForAdapterAttributeChanged(aAdapter, "discovering", true));
-      promises.push(aAdapter.startDiscovery());
-      return Promise.all(promises);
-    })
-    .then(function(aResults) {
-      log("[2] Attach event handler for 'ondevicefound' ... ");
-      discoveryHandle = aResults[1];
-      isHandleExpired = false;
-      discoveryHandle.ondevicefound = function onDeviceFound(aEvent) {
-        if (isHandleExpired) {
-          ok(false, "Expired BluetoothDiscoveryHandle received an event.");
-        }
-      };
-    })
-    .then(function() {
-      log("[3] Stop discovery and and verify the correctness ... ");
-      let promises = [];
-      if (aAdapter.discovering) {
-        promises.push(waitForAdapterAttributeChanged(aAdapter, "discovering", false));
-      }
-      promises.push(aAdapter.stopDiscovery());
-      return Promise.all(promises);
-    })
-    .then(function() {
-      log("[4] Mark the BluetoothDiscoveryHandle from [1] as expired ... ");
-      isHandleExpired = true;
-    })
-    .then(function() {
-      log("[5] Start discovery and verify the correctness ... ");
-      let promises = [];
-      promises.push(waitForAdapterAttributeChanged(aAdapter, "discovering", true));
-      promises.push(aAdapter.startDiscovery());
-      return Promise.all(promises);
-    })
-    .then(function(aResults) {
-      log("[6] Wait for 'devicefound' events ... ");
-      return waitForDevicesFound(aResults[1], EXPECTED_NUMBER_OF_REMOTE_DEVICES);
-    })
-    .then(function() {
-      log("[7] Stop discovery and and verify the correctness ... ");
-      let promises = [];
-      if (aAdapter.discovering) {
-        promises.push(waitForAdapterAttributeChanged(aAdapter, "discovering", false));
-      }
-      promises.push(aAdapter.stopDiscovery());
-      return Promise.all(promises);
-    })
-    .then(function() {
-      log("[8] Call 'startDiscovery' twice continuously ... ");
-      return aAdapter.startDiscovery()
-        .then(() => aAdapter.startDiscovery())
-        .then(() => ok(false, "Call startDiscovery() when adapter is discovering. - Fail"),
-              () => ok(true, "Call startDiscovery() when adapter is discovering. - Success"));
-    })
-    .then(function() {
-      log("[9] Call 'stopDiscovery' twice continuously ... ");
-      return aAdapter.stopDiscovery()
-        .then(() => aAdapter.stopDiscovery())
-        .then(() => ok(true, "Call stopDiscovery() when adapter isn't discovering. - Success"),
-              () => ok(false, "Call stopDiscovery() when adapter isn't discovering. - Fail"));
-    })
-    .then(function() {
-      log("[10] Clean up the event handler of [2] ... ");
-      if (discoveryHandle) {
-        discoveryHandle.ondevicefound = null;
-      }
-    });
-});
deleted file mode 100644
--- a/dom/bluetooth/tests/marionette/test_dom_BluetoothAdapter_enable.js
+++ /dev/null
@@ -1,76 +0,0 @@
-/* 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/. */
-
-///////////////////////////////////////////////////////////////////////////////
-// Test Purpose:
-//   To verify that enable/disable process of BluetoothAdapter is correct.
-//
-// Test Procedure:
-//   [0] Set Bluetooth permission and enable default adapter.
-//   [1] Disable Bluetooth and check the correctness of 'onattributechanged'.
-//   [2] Enable Bluetooth and check the correctness of 'onattributechanged'.
-//
-// Test Coverage:
-//   - BluetoothAdapter.enable()
-//   - BluetoothAdapter.disable()
-//   - BluetoothAdapter.onattributechanged()
-//   - BluetoothAdapter.address
-//   - BluetoothAdapter.state
-//
-///////////////////////////////////////////////////////////////////////////////
-
-MARIONETTE_TIMEOUT = 60000;
-MARIONETTE_HEAD_JS = 'head.js';
-
-startBluetoothTest(true, function testCaseMain(aAdapter) {
-  log("Checking adapter attributes ...");
-
-  is(aAdapter.state, "enabled", "adapter.state");
-  isnot(aAdapter.address, "", "adapter.address");
-
-  // Since adapter has just been re-enabled, these properties should be 'false'.
-  is(aAdapter.discovering, false, "adapter.discovering");
-  is(aAdapter.discoverable, false, "adapter.discoverable");
-  // TODO: Check the correctness of name and address if we use emulator.
-  // is(aAdapter.name, EMULATOR_NAME, "adapter.name");
-  // is(aAdapter.address, EMULATOR_ADDRESS, "adapter.address");
-
-  log("  adapter.address: " + aAdapter.address);
-  log("  adapter.name: " + aAdapter.name);
-
-  let originalAddr = aAdapter.address;
-  let originalName = aAdapter.name;
-
-  return Promise.resolve()
-    .then(function() {
-      log("[1] Disable Bluetooth and check the correctness of 'onattributechanged'");
-      let promises = [];
-      promises.push(waitForAdapterStateChanged(aAdapter, ["disabling", "disabled"]));
-      promises.push(aAdapter.disable());
-      return Promise.all(promises);
-    })
-    .then(function(aResults) {
-      isnot(aResults[0].indexOf("address"), -1, "Indicator of 'address' changed event");
-      if (originalName != "") {
-        isnot(aResults[0].indexOf("name"), -1, "Indicator of 'name' changed event");
-      }
-      is(aAdapter.address, "", "adapter.address");
-      is(aAdapter.name, "", "adapter.name");
-    })
-    .then(function() {
-      log("[2] Enable Bluetooth and check the correctness of 'onattributechanged'");
-      let promises = [];
-      promises.push(waitForAdapterStateChanged(aAdapter, ["enabling", "enabled"]));
-      promises.push(aAdapter.enable());
-      return Promise.all(promises);
-    })
-    .then(function(aResults) {
-      isnot(aResults[0].indexOf("address"), -1, "Indicator of 'address' changed event");
-      if (originalName != "") {
-        isnot(aResults[0].indexOf("name"), -1, "Indicator of 'name' changed event");
-      }
-      is(aAdapter.address, originalAddr, "adapter.address");
-      is(aAdapter.name, originalName, "adapter.name");
-    })
-});
deleted file mode 100644
--- a/dom/bluetooth/tests/marionette/test_dom_BluetoothAdapter_pair.js
+++ /dev/null
@@ -1,141 +0,0 @@
-/* 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/. */
-
-///////////////////////////////////////////////////////////////////////////////
-// Test Purpose:
-//   To verify entire paring process of BluetoothAdapter, except for
-//   in-line pairing.
-//   Testers have to put a discoverable remote device near the testing device
-//   and click the 'confirm' button on remote device when it receives a pairing
-//   request from testing device.
-//   To pass this test, Bluetooth address of the remote device should equal to
-//   ADDRESS_OF_TARGETED_REMOTE_DEVICE.
-//
-// Test Procedure:
-//   [0] Set Bluetooth permission and enable default adapter.
-//   [1] Unpair device if it's already paired.
-//   [2] Start discovery.
-//   [3] Wait for the specified 'devicefound' event.
-//   [4] Type checking for BluetoothDeviceEvent and BluetoothDevice.
-//   [5] Pair and wait for confirmation.
-//   [6] Get paired devices and verify 'devicepaired' event.
-//   [7] Pair again.
-//   [8] Unpair.
-//   [9] Get paired devices and verify 'deviceunpaired' event.
-//   [10] Unpair again.
-//   [11] Stop discovery.
-//
-// Test Coverage:
-//   - BluetoothAdapter.pair()
-//   - BluetoothAdapter.unpair()
-//   - BluetoothAdapter.getPairedDevices()
-//   - BluetoothAdapter.ondevicepaired()
-//   - BluetoothAdapter.ondeviceunpaired()
-//   - BluetoothAdapter.pairingReqs
-//
-//   - BluetoothPairingListener.ondisplaypassykeyreq()
-//   - BluetoothPairingListener.onenterpincodereq()
-//   - BluetoothPairingListener.onpairingconfirmationreq()
-//   - BluetoothPairingListener.onpairingconsentreq()
-//
-//   - BluetoothPairingEvent.device
-//   - BluetoothPairingEvent.handle
-//
-//   - BluetoothPairingHandle.setPinCode()
-//   - BluetoothPairingHandle.accept()
-//
-///////////////////////////////////////////////////////////////////////////////
-
-MARIONETTE_TIMEOUT = 60000;
-MARIONETTE_HEAD_JS = 'head.js';
-
-const ADDRESS_OF_TARGETED_REMOTE_DEVICE = "0c:bd:51:20:a1:e0";
-
-startBluetoothTest(true, function testCaseMain(aAdapter) {
-  log("Checking adapter attributes ...");
-
-  is(aAdapter.state, "enabled", "adapter.state");
-  isnot(aAdapter.address, "", "adapter.address");
-
-  // Since adapter has just been re-enabled, these properties should be 'false'.
-  is(aAdapter.discovering, false, "adapter.discovering");
-  is(aAdapter.discoverable, false, "adapter.discoverable");
-
-  log("adapter.address: " + aAdapter.address);
-  log("adapter.name: " + aAdapter.name);
-
-  return Promise.resolve()
-    .then(function() {
-      log("[1] Unpair device if it's already paired ... ");
-      let devices = aAdapter.getPairedDevices();
-      for (let i in devices) {
-        if (devices[i].address == ADDRESS_OF_TARGETED_REMOTE_DEVICE) {
-          log("  - The device has already been paired. Unpair it ...");
-          return aAdapter.unpair(devices[i].address);
-        }
-      }
-      log("  - The device hasn't been paired. Skip to Step [2] ...");
-      return;
-    })
-    .then(function() {
-      log("[2] Start discovery ... ");
-      return aAdapter.startDiscovery();
-    })
-    .then(function(discoveryHandle) {
-      log("[3] Wait for the specified 'devicefound' event ... ");
-      return waitForSpecifiedDevicesFound(discoveryHandle, [ADDRESS_OF_TARGETED_REMOTE_DEVICE]);
-    })
-    .then(function(deviceEvents) {
-      log("[4] Type checking for BluetoothDeviceEvent and BluetoothDevice ... ");
-
-      let device = deviceEvents[0].device;
-      ok(deviceEvents[0] instanceof BluetoothDeviceEvent, "device should be a BluetoothDeviceEvent");
-      ok(device instanceof BluetoothDevice, "device should be a BluetoothDevice");
-
-      log("  - BluetoothDevice.address: " + device.address);
-      log("  - BluetoothDevice.name: " + device.name);
-      log("  - BluetoothDevice.cod: " + device.cod);
-      log("  - BluetoothDevice.paired: " + device.paired);
-      log("  - BluetoothDevice.uuids: " + device.uuids);
-
-      return device;
-    })
-    .then(function(device) {
-      log("[5] Pair and wait for confirmation ... ");
-
-      addEventHandlerForPairingRequest(aAdapter, device.address);
-
-      let promises = [];
-      promises.push(waitForAdapterEvent(aAdapter, "devicepaired"));
-      promises.push(aAdapter.pair(device.address));
-      return Promise.all(promises);
-    })
-    .then(function(results) {
-      log("[6] Get paired devices and verify 'devicepaired' event ... ");
-      return verifyDevicePairedUnpairedEvent(aAdapter, results[0]);
-    })
-    .then(function(deviceEvent) {
-      log("[7] Pair again... ");
-      return aAdapter.pair(deviceEvent.device.address).then(deviceEvent.device.address);
-    })
-    .then(function(deviceAddress) {
-      log("[8] Unpair ... ");
-      let promises = [];
-      promises.push(waitForAdapterEvent(aAdapter, "deviceunpaired"));
-      promises.push(aAdapter.unpair(deviceAddress));
-      return Promise.all(promises);
-    })
-    .then(function(results) {
-      log("[9] Get paired devices and verify 'deviceunpaired' event ... ");
-      return verifyDevicePairedUnpairedEvent(aAdapter, results[0])
-    })
-    .then(function(deviceEvent) {
-      log("[10] Unpair again... ");
-      return aAdapter.unpair(deviceEvent.address);
-    })
-    .then(function() {
-      log("[11] Stop discovery ... ");
-      return aAdapter.stopDiscovery();
-    });
-});
deleted file mode 100644
--- a/dom/bluetooth/tests/marionette/test_dom_BluetoothAdapter_setters.js
+++ /dev/null
@@ -1,111 +0,0 @@
-/* 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/. */
-
-///////////////////////////////////////////////////////////////////////////////
-// Test Purpose:
-//   To verify that all setters of BluetoothAdapter (except for pairing related
-//   APIs) can change properties correctly.
-//
-// Test Procedure:
-//   [0] Set Bluetooth permission and enable default adapter.
-//   [1] Verify the functionality of 'setName'.
-//   [2] Verify the functionality of 'setDiscoverable'.
-//   [3] Disable Bluetooth and collect changed attributes.
-//   [4] Verify the changes of attributes when BT is disabled.
-//   [5] Set properties when Bluetooth is disabled.
-//   [6] Enable Bluetooth and collect changed attributes.
-//   [7] Verify the changes of attributes when BT is enabled.
-//   [8] Restore the original 'adapter.name'.
-//   [9] Check the validity of setting properties to their present value.
-//
-// Test Coverage:
-//   - BluetoothAdapter.setName()
-//   - BluetoothAdapter.setDiscoverable()
-//   - BluetoothAdapter.onattributechanged()
-//   - BluetoothAdapter.state
-//   - BluetoothAdapter.name
-//   - BluetoothAdapter.discoverable
-//
-///////////////////////////////////////////////////////////////////////////////
-
-MARIONETTE_TIMEOUT = 60000;
-MARIONETTE_HEAD_JS = 'head.js';
-
-startBluetoothTest(true, function testCaseMain(aAdapter) {
-  log("Checking adapter attributes ...");
-
-  is(aAdapter.state, "enabled", "adapter.state");
-  isnot(aAdapter.address, "", "adapter.address");
-
-  // Since adapter has just been re-enabled, these properties should be 'false'.
-  is(aAdapter.discovering, false, "adapter.discovering");
-  is(aAdapter.discoverable, false, "adapter.discoverable at step [0]");
-
-  log("adapter.address: " + aAdapter.address);
-  log("adapter.name: " + aAdapter.name);
-
-  let originalName = aAdapter.name;
-  return Promise.resolve()
-    .then(function() {
-      log("[1] Set 'name' ... ");
-      let promises = [];
-      promises.push(waitForAdapterAttributeChanged(aAdapter, "name", originalName + "_modified"));
-      promises.push(aAdapter.setName(originalName + "_modified"));
-      return Promise.all(promises);
-    })
-    .then(function() {
-      log("[2] Set 'discoverable' ... ");
-      let promises = [];
-      promises.push(waitForAdapterAttributeChanged(aAdapter, "discoverable", !aAdapter.discoverable));
-      promises.push(aAdapter.setDiscoverable(!aAdapter.discoverable));
-      return Promise.all(promises);
-    })
-    .then(function() {
-      log("[3] Disable Bluetooth ...");
-      let promises = [];
-      promises.push(waitForAdapterStateChanged(aAdapter, ["disabling", "disabled"]));
-      promises.push(aAdapter.disable());
-      return Promise.all(promises);
-    })
-    .then(function(aResults) {
-      log("[4] Verify the changes of attributes ...");
-      isnot(aResults[0].indexOf("name"), -1, "Indicator of 'name' changed event");
-      isnot(aResults[0].indexOf("discoverable"), -1, "Indicator of 'discoverable' changed event");
-      is(aAdapter.name, "", "adapter.name");
-      is(aAdapter.discoverable, false, "adapter.discoverable at step [4]");
-    })
-    .then(() => log("[5] Set properties when Bluetooth is disabled ..."))
-    .then(() => aAdapter.setName(originalName))
-    .then(() => ok(false, "Failed to handle 'setName' when BT is disabled."),
-          () => aAdapter.setDiscoverable(true))
-    .then(() => ok(false, "Failed to handle 'setDiscoverable' when BT is disabled."),
-          () => null)
-    .then(function() {
-      log("[6] Enable Bluetooth ...");
-      let promises = [];
-      promises.push(waitForAdapterStateChanged(aAdapter, ["enabling", "enabled"]));
-      promises.push(aAdapter.enable());
-      return Promise.all(promises);
-    })
-    .then(function(aResults) {
-      log("[7] Verify the changes of attributes ...");
-      isnot(aResults[0].indexOf("name"), -1, "Indicator of 'name' changed event");
-      is(aAdapter.name, originalName + "_modified", "adapter.name");
-      is(aAdapter.discoverable, false, "adapter.discoverable at step [7]");
-    })
-    .then(function() {
-      log("[8] Restore the original 'name' ...");
-      let promises = [];
-      promises.push(waitForAdapterAttributeChanged(aAdapter, "name", originalName));
-      promises.push(aAdapter.setName(originalName));
-      return Promise.all(promises);
-    })
-    .then(function() {
-      log("[9] Check the validity of setting properties to their present value ...");
-      let promises = [];
-      promises.push(aAdapter.setName(aAdapter.name));
-      promises.push(aAdapter.setDiscoverable(aAdapter.discoverable));
-      return Promise.all(promises);
-    });
-});
deleted file mode 100644
--- a/dom/bluetooth/tests/marionette/test_dom_BluetoothDevice.js
+++ /dev/null
@@ -1,146 +0,0 @@
-/* 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/. */
-
-///////////////////////////////////////////////////////////////////////////////
-// Test Purpose:
-//   To verify that all properties of BluetoothDevice is correct when they've
-//   been discovered by adapter and delivered by BluetoothDeviceEvent.
-//   Testers have to put the B2G devices in an environment which is surrounded
-//   by N discoverable remote devices. To pass this test, the number N has to be
-//   be greater than (or equal to) EXPECTED_NUMBER_OF_REMOTE_DEVICES.
-//
-// Test Procedure:
-//   [0] Set Bluetooth permission and enable default adapter.
-//   [1] Start discovery.
-//   [2] Wait for 'devicefound' events.
-//   [3] Type checking for BluetoothDeviceEvent and BluetoothDevice.
-//   [4] Attach the 'onattributechanged' handler for the first device.
-//   [5] Fetch the UUIDs of the first device.
-//   [6] Verify the UUIDs.
-//   [7] Stop discovery.
-//
-// Test Coverage:
-//   - BluetoothDevice.address
-//   - BluetoothDevice.cod
-//   - BluetoothDevice.name
-//   - BluetoothDevice.paired
-//   - BluetoothDevice.uuids
-//   - BluetoothDevice.onattributechanged()
-//   - BluetoothDevice.fetchUuids()
-//   - BluetoothDeviceEvent.address
-//   - BluetoothDeviceEvent.device
-//
-///////////////////////////////////////////////////////////////////////////////
-
-MARIONETTE_TIMEOUT = 60000;
-MARIONETTE_HEAD_JS = 'head.js';
-
-const EXPECTED_NUMBER_OF_REMOTE_DEVICES = 1;
-
-var hasReceivedUuidsChanged = false;
-var originalUuids;
-
-startBluetoothTest(true, function testCaseMain(aAdapter) {
-  log("Checking adapter attributes ...");
-
-  is(aAdapter.state, "enabled", "adapter.state");
-  isnot(aAdapter.address, "", "adapter.address");
-
-  // Since adapter has just been re-enabled, these properties should be 'false'.
-  is(aAdapter.discovering, false, "adapter.discovering");
-  is(aAdapter.discoverable, false, "adapter.discoverable at step [0]");
-
-  log("adapter.address: " + aAdapter.address);
-  log("adapter.name: " + aAdapter.name);
-
-  return Promise.resolve()
-    .then(function(discoveryHandle) {
-      log("[1] Start discovery ... ");
-      return aAdapter.startDiscovery();
-    })
-    .then(function(discoveryHandle) {
-      log("[2] Wait for 'devicefound' events ... ");
-      return waitForDevicesFound(discoveryHandle, EXPECTED_NUMBER_OF_REMOTE_DEVICES);
-    })
-    .then(function(deviceEvents) {
-      log("[3] Type checking for BluetoothDeviceEvent and BluetoothDevice ... ");
-
-      for (let i in deviceEvents) {
-        let deviceEvt = deviceEvents[i];
-        is(deviceEvt.address, null, "deviceEvt.address");
-        isnot(deviceEvt.device, null, "deviceEvt.device");
-        ok(deviceEvt.device instanceof BluetoothDevice,
-          "deviceEvt.device should be a BluetoothDevice");
-
-        let device = deviceEvt.device;
-        ok(typeof device.address === 'string', "type checking for address.");
-        ok(typeof device.name === 'string', "type checking for name.");
-        ok(device.cod instanceof BluetoothClassOfDevice, "type checking for cod.");
-        ok(typeof device.paired === 'boolean', "type checking for paired.");
-        ok(Array.isArray(device.uuids), "type checking for uuids.");
-
-        originalUuids = device.uuids;
-
-        log("  - BluetoothDevice.address: " + device.address);
-        log("  - BluetoothDevice.name: " + device.name);
-        log("  - BluetoothDevice.cod: " + device.cod);
-        log("  - BluetoothDevice.paired: " + device.paired);
-        log("  - BluetoothDevice.uuids: " + device.uuids);
-      }
-      return deviceEvents[0].device;
-    })
-    .then(function(device) {
-      log("[4] Attach the 'onattributechanged' handler for the remote device ... ");
-      device.onattributechanged = function(aEvent) {
-        for (let i in aEvent.attrs) {
-          switch (aEvent.attrs[i]) {
-            case "cod":
-              log("  'cod' changed to " + device.cod);
-              break;
-            case "name":
-              log("  'name' changed to " + device.name);
-              break;
-            case "paired":
-              log("  'paired' changed to " + device.paired);
-              break;
-            case "uuids":
-              log("  'uuids' changed to " + device.uuids);
-              hasReceivedUuidsChanged = true;
-              break;
-            case "unknown":
-            default:
-              ok(false, "Unknown attribute '" + aEvent.attrs[i] + "' changed." );
-              break;
-          }
-        }
-      };
-      return device;
-    })
-    .then(function(device) {
-      log("[5] Fetch the UUIDs of remote device ... ");
-      let promises = [];
-      promises.push(Promise.resolve(device));
-      promises.push(device.fetchUuids());
-      return Promise.all(promises);
-    })
-    .then(function(aResults) {
-      log("[6] Verify the UUIDs ... ");
-      let device = aResults[0];
-      let uuids = aResults[1];
-
-      ok(Array.isArray(uuids), "type checking for 'fetchUuids'.");
-
-      ok(isUuidsEqual(uuids, device.uuids),
-        "device.uuids should equal to the result from 'fetchUuids'");
-
-      bool isUuidsChanged = !isUuidsEqual(originalUuids, device.uuids);
-      is(isUuidsChanged, hasReceivedUuidsChanged, "device.uuids has changed.");
-
-      device.onattributechanged = null;
-    })
-    .then(function() {
-      log("[7] Stop discovery ... ");
-      return aAdapter.stopDiscovery();
-    })
-});
deleted file mode 100644
--- a/dom/bluetooth/tests/marionette/test_dom_BluetoothManager.js
+++ /dev/null
@@ -1,48 +0,0 @@
-/* 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/. */
-
-///////////////////////////////////////////////////////////////////////////////
-// Test Purpose:
-//   To verify the basic functionality of BluetoothManager.
-//
-// Test Coverage:
-//   - BluetoothManager.defaultAdapter
-//   - BluetoothManager.getAdapters()
-// TODO:
-//   - BluetoothManager.onattributechanged()
-//   - BluetoothManager.onadapteradded()
-//   - BluetoothManager.onadapterremoved()
-//
-///////////////////////////////////////////////////////////////////////////////
-
-MARIONETTE_TIMEOUT = 60000;
-MARIONETTE_HEAD_JS = 'head.js';
-
-// TODO: Listens to 'onattributechanged' when B2G supports the feature that
-//       allows user to add/remove Bluetooth adapter.
-// Currently, B2G recognizes build-in Bluetooth chip as default adapter and
-// don't support adding additional Bluetooth dongles in gonk layer.
-// Therefore, the 'onattributechanged' would be triggered *only* when the
-// instance of BluetoothManager is created.
-function waitForManagerAttributeChanged() {
-  let deferred = Promise.defer();
-
-  bluetoothManager.onattributechanged = function(aEvent) {
-    if(aEvent.attrs.indexOf("defaultAdapter")) {
-      bluetoothManager.onattributechanged = null;
-      ok(true, "BluetoothManager event 'onattributechanged' got.");
-      deferred.resolve(aEvent);
-    }
-  };
-
-  return deferred.promise;
-}
-
-startBluetoothTestBase(["settings-read", "settings-write", "settings-api-read", "settings-api-write"],
-                       function testCaseMain() {
-  let adapters = bluetoothManager.getAdapters();
-  ok(Array.isArray(adapters), "Can not got the array of adapters");
-  ok(adapters.length, "The number of adapters should not be zero");
-  ok(bluetoothManager.defaultAdapter, "defaultAdapter should not be null.");
-});
--- a/dom/browser-element/moz.build
+++ b/dom/browser-element/moz.build
@@ -30,17 +30,16 @@ EXTRA_COMPONENTS += [
     'BrowserElementProxy.manifest',
 ]
 
 EXTRA_JS_MODULES += [
     'BrowserElementPromptService.jsm',
 ]
 
 LOCAL_INCLUDES += [
-    '../bluetooth',
     '/dom/html',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 LOCAL_INCLUDES += [
--- a/dom/events/test/test_all_synthetic_events.html
+++ b/dom/events/test/test_all_synthetic_events.html
@@ -47,88 +47,16 @@ const kEventConstructors = {
                                                          e.initEvent(aName, aProps.bubbles, aProps.cancelable);
                                                          return e;
                                                        },
                                              },
   BlobEvent:                                 { create: function (aName, aProps) {
                                                          return new BlobEvent(aName, aProps);
                                                        },
                                              },
-  BluetoothAdapterEvent:                     { create: function (aName, aProps) {
-                                                          return new BluetoothAdapterEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothAttributeEvent:                   { create: function (aName, aProps) {
-                                                          return new BluetoothAttributeEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothDeviceEvent:                      { create: function (aName, aProps) {
-                                                          return new BluetoothDeviceEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothGattAttributeEvent:               { create: function (aName, aProps) {
-                                                          return new BluetoothGattAttributeEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothGattCharacteristicEvent:          { create: function (aName, aProps) {
-                                                          return new BluetoothGattCharacteristicEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothLeDeviceEvent:                    { create: function (aName, aProps) {
-                                                          return new BluetoothLeDeviceEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothObexAuthEvent:                    { create: function (aName, aProps) {
-                                                          return new BluetoothObexAuthEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothPairingEvent:                     { create: function (aName, aProps) {
-                                                          return new BluetoothPairingEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothMapFolderListingEvent:            { create: function (aName, aProps) {
-                                                          return new BluetoothMapFolderListingEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothMapGetMessageEvent:               { create: function (aName, aProps) {
-                                                          return new BluetoothMapGetMessageEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothMapMessagesListingEvent:          { create: function (aName, aProps) {
-                                                          return new BluetoothMapMessagesListingEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothMapMessageUpdateEvent:            { create: function (aName, aProps) {
-                                                          return new BluetoothMapMessageUpdateEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothMapSendMessageEvent:              { create: function (aName, aProps) {
-                                                          return new BluetoothMapSendMessageEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothMapSetMessageStatusEvent:         { create: function (aName, aProps) {
-                                                          return new BluetoothMapSetMessageStatusEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothPhonebookPullingEvent:            { create: function (aName, aProps) {
-                                                          return new BluetoothPhonebookPullingEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothStatusChangedEvent:               { create: function (aName, aProps) {
-                                                          return new BluetoothStatusChangedEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothVCardListingEvent:                { create: function (aName, aProps) {
-                                                          return new BluetoothVCardListingEvent(aName, aProps);
-                                                       },
-                                             },
-  BluetoothVCardPullingEvent:                { create: function (aName, aProps) {
-                                                          return new BluetoothVCardPullingEvent(aName, aProps);
-                                                       },
-                                             },
   CallEvent:                                 { create: function (aName, aProps) {
                                                           return new CallEvent(aName, aProps);
                                                        },
                                              },
   CallGroupErrorEvent:                       { create: function (aName, aProps) {
                                                           return new CallGroupErrorEvent(aName, aProps);
                                                        },
                                              },
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -168,17 +168,16 @@
 #ifdef ACCESSIBILITY
 #include "nsAccessibilityService.h"
 #endif
 
 #include "mozilla/dom/File.h"
 #include "mozilla/dom/icc/IccChild.h"
 #include "mozilla/dom/mobileconnection/MobileConnectionChild.h"
 #include "mozilla/dom/devicestorage/DeviceStorageRequestChild.h"
-#include "mozilla/dom/bluetooth/PBluetoothChild.h"
 #include "mozilla/dom/PPresentationChild.h"
 #include "mozilla/dom/PresentationIPCService.h"
 #include "mozilla/ipc/InputStreamUtils.h"
 
 #ifdef MOZ_WEBSPEECH
 #include "mozilla/dom/PSpeechSynthesisChild.h"
 #endif
 
@@ -196,17 +195,16 @@
 #include "GMPServiceChild.h"
 #include "GMPDecoderModule.h"
 #include "gfxPlatform.h"
 #include "nscore.h" // for NS_FREE_PERMANENT_DATA
 #include "VRManagerChild.h"
 
 using namespace mozilla;
 using namespace mozilla::docshell;
-using namespace mozilla::dom::bluetooth;
 using namespace mozilla::dom::devicestorage;
 using namespace mozilla::dom::icc;
 using namespace mozilla::dom::ipc;
 using namespace mozilla::dom::mobileconnection;
 using namespace mozilla::dom::workers;
 using namespace mozilla::media;
 using namespace mozilla::embedding;
 using namespace mozilla::gmp;
@@ -2012,37 +2010,16 @@ ContentChild::AllocPStorageChild()
 bool
 ContentChild::DeallocPStorageChild(PStorageChild* aActor)
 {
   DOMStorageDBChild* child = static_cast<DOMStorageDBChild*>(aActor);
   child->ReleaseIPDLReference();
   return true;
 }
 
-PBluetoothChild*
-ContentChild::AllocPBluetoothChild()
-{
-#ifdef MOZ_B2G_BT
-  MOZ_CRASH("No one should be allocating PBluetoothChild actors");
-#else
-  MOZ_CRASH("No support for bluetooth on this platform!");
-#endif
-}
-
-bool
-ContentChild::DeallocPBluetoothChild(PBluetoothChild* aActor)
-{
-#ifdef MOZ_B2G_BT
-  delete aActor;
-  return true;
-#else
-  MOZ_CRASH("No support for bluetooth on this platform!");
-#endif
-}
-
 PSpeechSynthesisChild*
 ContentChild::AllocPSpeechSynthesisChild()
 {
 #ifdef MOZ_WEBSPEECH
   MOZ_CRASH("No one should be allocating PSpeechSynthesisChild actors");
 #else
   return nullptr;
 #endif
--- a/dom/ipc/ContentChild.h
+++ b/dom/ipc/ContentChild.h
@@ -335,20 +335,16 @@ public:
   virtual PMediaChild* AllocPMediaChild() override;
 
   virtual bool DeallocPMediaChild(PMediaChild* aActor) override;
 
   virtual PStorageChild* AllocPStorageChild() override;
 
   virtual bool DeallocPStorageChild(PStorageChild* aActor) override;
 
-  virtual PBluetoothChild* AllocPBluetoothChild() override;
-
-  virtual bool DeallocPBluetoothChild(PBluetoothChild* aActor) override;
-
   virtual PPresentationChild* AllocPPresentationChild() override;
 
   virtual bool DeallocPPresentationChild(PPresentationChild* aActor) override;
 
   virtual PFlyWebPublishedServerChild*
     AllocPFlyWebPublishedServerChild(const nsString& name,
                                      const FlyWebPublishOptions& params) override;
 
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -52,17 +52,16 @@
 #include "mozilla/dom/GeolocationBinding.h"
 #include "mozilla/dom/MediaKeySystemAccess.h"
 #include "mozilla/dom/Notification.h"
 #include "mozilla/dom/PContentBridgeParent.h"
 #include "mozilla/dom/PContentPermissionRequestParent.h"
 #include "mozilla/dom/PCycleCollectWithLogsParent.h"
 #include "mozilla/dom/PMemoryReportRequestParent.h"
 #include "mozilla/dom/ServiceWorkerRegistrar.h"
-#include "mozilla/dom/bluetooth/PBluetoothParent.h"
 #include "mozilla/dom/devicestorage/DeviceStorageRequestParent.h"
 #include "mozilla/dom/icc/IccParent.h"
 #include "mozilla/dom/mobileconnection/MobileConnectionParent.h"
 #include "mozilla/dom/power/PowerManagerService.h"
 #include "mozilla/dom/Permissions.h"
 #include "mozilla/dom/PresentationParent.h"
 #include "mozilla/dom/PPresentationParent.h"
 #include "mozilla/dom/PushNotifier.h"
@@ -220,21 +219,16 @@
 #include "SpeakerManagerService.h"
 using namespace mozilla::system;
 #endif
 
 #ifdef MOZ_WIDGET_GTK
 #include <gdk/gdk.h>
 #endif
 
-#ifdef MOZ_B2G_BT
-#include "BluetoothParent.h"
-#include "BluetoothService.h"
-#endif
-
 #include "mozilla/RemoteSpellCheckEngineParent.h"
 
 #include "Crypto.h"
 
 #ifdef MOZ_WEBSPEECH
 #include "mozilla/dom/SpeechSynthesisParent.h"
 #endif
 
@@ -279,17 +273,16 @@ using base::ChildPrivileges;
 using base::KillProcess;
 #ifdef MOZ_ENABLE_PROFILER_SPS
 using mozilla::ProfileGatherer;
 #endif
 
 #ifdef MOZ_CRASHREPORTER
 using namespace CrashReporter;
 #endif
-using namespace mozilla::dom::bluetooth;
 using namespace mozilla::dom::devicestorage;
 using namespace mozilla::dom::icc;
 using namespace mozilla::dom::power;
 using namespace mozilla::dom::mobileconnection;
 using namespace mozilla::media;
 using namespace mozilla::embedding;
 using namespace mozilla::gfx;
 using namespace mozilla::gmp;
@@ -3439,53 +3432,16 @@ ContentParent::AllocPStorageParent()
 bool
 ContentParent::DeallocPStorageParent(PStorageParent* aActor)
 {
   DOMStorageDBParent* child = static_cast<DOMStorageDBParent*>(aActor);
   child->ReleaseIPDLReference();
   return true;
 }
 
-PBluetoothParent*
-ContentParent::AllocPBluetoothParent()
-{
-#ifdef MOZ_B2G_BT
-  if (!AssertAppProcessPermission(this, "bluetooth")) {
-  return nullptr;
-  }
-  return new mozilla::dom::bluetooth::BluetoothParent();
-#else
-  MOZ_CRASH("No support for bluetooth on this platform!");
-#endif
-}
-
-bool
-ContentParent::DeallocPBluetoothParent(PBluetoothParent* aActor)
-{
-#ifdef MOZ_B2G_BT
-  delete aActor;
-  return true;
-#else
-  MOZ_CRASH("No support for bluetooth on this platform!");
-#endif
-}
-
-bool
-ContentParent::RecvPBluetoothConstructor(PBluetoothParent* aActor)
-{
-#ifdef MOZ_B2G_BT
-  RefPtr<BluetoothService> btService = BluetoothService::Get();
-  NS_ENSURE_TRUE(btService, false);
-
-  return static_cast<BluetoothParent*>(aActor)->InitWithService(btService);
-#else
-  MOZ_CRASH("No support for bluetooth on this platform!");
-#endif
-}
-
 PPresentationParent*
 ContentParent::AllocPPresentationParent()
 {
   RefPtr<PresentationParent> actor = new PresentationParent();
   return actor.forget().take();
 }
 
 bool
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -839,22 +839,16 @@ private:
   virtual bool DeallocPHandlerServiceParent(PHandlerServiceParent*) override;
 
   virtual PMediaParent* AllocPMediaParent() override;
 
   virtual bool DeallocPMediaParent(PMediaParent* aActor) override;
 
   virtual bool DeallocPStorageParent(PStorageParent* aActor) override;
 
-  virtual PBluetoothParent* AllocPBluetoothParent() override;
-
-  virtual bool DeallocPBluetoothParent(PBluetoothParent* aActor) override;
-
-  virtual bool RecvPBluetoothConstructor(PBluetoothParent* aActor) override;
-
   virtual PPresentationParent* AllocPPresentationParent() override;
 
   virtual bool DeallocPPresentationParent(PPresentationParent* aActor) override;
 
   virtual bool RecvPPresentationConstructor(PPresentationParent* aActor) override;
 
   virtual PFlyWebPublishedServerParent*
     AllocPFlyWebPublishedServerParent(const nsString& name,
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
 /* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
 /* 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 protocol PBackground;
 include protocol PBlob;
-include protocol PBluetooth;
 include protocol PBrowser;
 include protocol PCompositorBridge;
 include protocol PContentBridge;
 include protocol PContentPermissionRequest;
 include protocol PCycleCollectWithLogs;
 include protocol PCrashReporter;
 include protocol PPSMContentDownloader;
 include protocol PExternalHelperApp;
@@ -341,17 +340,16 @@ nested(upto inside_cpow) sync protocol P
 {
     parent spawns PPluginModule;
 
     parent opens PProcessHangMonitor;
     parent opens PGMPService;
     child opens PBackground;
 
     manages PBlob;
-    manages PBluetooth;
     manages PBrowser;
     manages PContentPermissionRequest;
     manages PCrashReporter;
     manages PCycleCollectWithLogs;
     manages PDeviceStorageRequest;
     manages PPSMContentDownloader;
     manages PExternalHelperApp;
     manages PFileDescriptorSet;
@@ -815,18 +813,16 @@ parent:
                  bool success);
 
     async PSpeechSynthesis();
 
     nested(inside_cpow) async PStorage();
 
     async PMedia();
 
-    async PBluetooth();
-
     async PWebrtcGlobal();
 
     async PPresentation();
 
     async PFlyWebPublishedServer(nsString name, FlyWebPublishOptions params);
 
     // Services remoting
 
--- a/dom/ipc/moz.build
+++ b/dom/ipc/moz.build
@@ -124,18 +124,16 @@ if CONFIG['MOZ_CONTENT_SANDBOX'] and CON
         'mozsandbox',
     ]
 
 LOCAL_INCLUDES += [
     '/caps',
     '/chrome',
     '/docshell/base',
     '/dom/base',
-    '/dom/bluetooth/common',
-    '/dom/bluetooth/ipc',
     '/dom/devicestorage',
     '/dom/events',
     '/dom/filesystem',
     '/dom/geolocation',
     '/dom/media/webspeech/synth/ipc',
     '/dom/security',
     '/dom/storage',
     '/dom/workers',
--- a/dom/moz.build
+++ b/dom/moz.build
@@ -35,17 +35,16 @@ interfaces = [
 ]
 
 DIRS += ['interfaces/' + i for i in interfaces]
 
 DIRS += [
     'animation',
     'apps',
     'base',
-    'bluetooth',
     'archivereader',
     'bindings',
     'battery',
     'browser-element',
     'cache',
     'canvas',
     'contacts',
     'crypto',
--- a/dom/permission/moz.build
+++ b/dom/permission/moz.build
@@ -29,17 +29,14 @@ EXTRA_JS_MODULES += [
 
 XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini']
 
 MOCHITEST_MANIFESTS += ['tests/mochitest.ini']
 
 if CONFIG['MOZ_B2G_RIL']:
     MOCHITEST_MANIFESTS += ['tests/mochitest-ril.ini']
 
-if CONFIG['MOZ_B2G_BT']:
-    MOCHITEST_MANIFESTS += ['tests/mochitest-bt.ini']
-
 if CONFIG['MOZ_TIME_MANAGER']:
     MOCHITEST_MANIFESTS += ['tests/mochitest-time.ini']
 
 FINAL_LIBRARY = 'xul'
 
 include('/ipc/chromium/chromium-config.mozbuild')
deleted file mode 100644
--- a/dom/permission/tests/mochitest-bt.ini
+++ /dev/null
@@ -1,2 +0,0 @@
-[test_bluetooth.html]
-skip-if = (toolkit == 'gonk' && debug) # bug 1093079
deleted file mode 100644
--- a/dom/permission/tests/test_bluetooth.html
+++ /dev/null
@@ -1,30 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=815105
--->
-<head>
-  <meta charset="utf-8">
-  <title>Test for Bug 815105 </title>
-  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-</head>
-<body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=815105">Mozilla Bug 815105 </a>
-<p id="display"></p>
-<div id="content" style="display: none"></div>
-<pre id="test">
-<script type="application/javascript;version=1.8" src="file_framework.js"></script>
-<script type="application/javascript;version=1.8">
-var gData = [
-  {
-    perm: ["bluetooth"],
-    obj: "mozBluetooth",
-    webidl: "BluetoothManager",
-  },
-]
-</script>
-</pre>
-</body>
-</html>
-
deleted file mode 100644
--- a/dom/webidl/BluetoothAdapter.webidl
+++ /dev/null
@@ -1,228 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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/. */
-
-// MediaMetadata and MediaPlayStatus are used to keep data from Applications.
-// Please see specification of AVRCP 1.3 for more details.
-dictionary MediaMetaData
-{
-  // track title
-  DOMString   title = "";
-  // artist name
-  DOMString   artist = "";
-  // album name
-  DOMString   album = "";
-  // track number
-  long long   mediaNumber = -1;
-  // number of tracks in the album
-  long long   totalMediaCount = -1;
-  // playing time (ms)
-  long long   duration = -1;
-};
-
-dictionary MediaPlayStatus
-{
-  // current track length (ms)
-  long long   duration = -1;
-  // playing time (ms)
-  long long   position = -1;
-  // one of 'STOPPED'/'PLAYING'/'PAUSED'/'FWD_SEEK'/'REV_SEEK'/'ERROR'
-  DOMString   playStatus = "";
-};
-
-[ChromeOnly]
-interface BluetoothAdapter : EventTarget {
-  readonly attribute BluetoothAdapterState  state;
-  readonly attribute DOMString              address;
-  readonly attribute DOMString              name;
-  readonly attribute boolean                discoverable;
-  readonly attribute boolean                discovering;
-  readonly attribute BluetoothGattServer?   gattServer;
-
-  readonly attribute BluetoothPairingListener? pairingReqs;
-
-  // Fired when attribute(s) of BluetoothAdapter changed
-           attribute EventHandler   onattributechanged;
-
-  // Fired when a remote device gets paired with the adapter
-           attribute EventHandler   ondevicepaired;
-
-  // Fired when a remote device gets unpaired from the adapter
-           attribute EventHandler   ondeviceunpaired;
-
-  // Fired when the pairing process aborted
-           attribute EventHandler   onpairingaborted;
-
-  // Fired when a2dp connection status changed
-           attribute EventHandler   ona2dpstatuschanged;
-
-  // Fired when handsfree connection status changed
-           attribute EventHandler   onhfpstatuschanged;
-
-  // Fired when handsfree connection status changed
-           attribute EventHandler   onhidstatuschanged;
-
-  // Fired when sco connection status changed
-           attribute EventHandler   onscostatuschanged;
-
-  // Fired when remote devices query current media play status
-           attribute EventHandler   onrequestmediaplaystatus;
-
-  // Fired when remote devices request password for OBEX authentication
-           attribute EventHandler   onobexpasswordreq;
-
-  // Fired when PBAP manager requests for 'pullphonebook'
-           attribute EventHandler   onpullphonebookreq;
-
-  // Fired when PBAP manager requests for 'pullvcardentry'
-           attribute EventHandler   onpullvcardentryreq;
-
-  // Fired when PBAP manager requests for 'pullvcardlisting'
-           attribute EventHandler   onpullvcardlistingreq;
-
-  // Fired when remote devices request to list SMS/MMS/Email folders
-           attribute EventHandler   onmapfolderlistingreq;
-
-  // Fired when remote devices request to list SMS/MMS/Email messages
-           attribute EventHandler   onmapmessageslistingreq;
-
-  // Fired when remote devices fetch the specific message
-           attribute EventHandler   onmapgetmessagereq;
-
-  // Fired when remote devices set message status
-           attribute EventHandler   onmapsetmessagestatusreq;
-
-  // Fired when remote devices send out SMS/MMS/Email message
-           attribute EventHandler   onmapsendmessagereq;
-
-  // Fired when remote devices download SMS/MMS/Email messages
-           attribute EventHandler   onmapmessageupdatereq;
-
-  /**
-   * Enable/Disable a local bluetooth adapter by asynchronus methods and return
-   * its result through a Promise.
-   *
-   * Several onattributechanged events would be triggered during processing the
-   * request, and the last one indicates adapter.state becomes enabled/disabled.
-   */
-  [NewObject]
-  Promise<void> enable();
-  [NewObject]
-  Promise<void> disable();
-
-  [NewObject]
-  Promise<void> setName(DOMString name);
-  [NewObject]
-  Promise<void> setDiscoverable(boolean discoverable);
-
-  [NewObject]
-  Promise<BluetoothDiscoveryHandle> startDiscovery();
-  [NewObject]
-  Promise<void> stopDiscovery();
-
-  [NewObject]
-  Promise<void> pair(DOMString deviceAddress);
-  [NewObject]
-  Promise<void> unpair(DOMString deviceAddress);
-
-  sequence<BluetoothDevice> getPairedDevices();
-
-  /**
-   * [B2G only GATT client API]
-   * |startLeScan| and |stopLeScan| methods are exposed only if
-   * "dom.bluetooth.webbluetooth.enabled" preference is false.
-   */
-  [NewObject,
-   Func="mozilla::dom::bluetooth::BluetoothManager::B2GGattClientEnabled"]
-  Promise<BluetoothDiscoveryHandle> startLeScan(sequence<DOMString> serviceUuids);
-
-  [NewObject,
-   Func="mozilla::dom::bluetooth::BluetoothManager::B2GGattClientEnabled"]
-  Promise<void> stopLeScan(BluetoothDiscoveryHandle discoveryHandle);
-
-  [NewObject, Throws]
-  DOMRequest getConnectedDevices(unsigned short serviceUuid);
-
-  /**
-   * Connect/Disconnect to a specific service of a target remote device.
-   * To check the value of service UUIDs, please check "Bluetooth Assigned
-   * Numbers" / "Service Discovery Protocol" for more information.
-   *
-   * Note that service UUID is optional. If it isn't passed when calling
-   * Connect, multiple profiles are tried sequentially based on the class of
-   * device (CoD). If it isn't passed when calling Disconnect, all connected
-   * profiles are going to be closed.
-   *
-   * Reply success if the connection of any profile is successfully
-   * established/released; reply error if we failed to connect/disconnect all
-   * of the planned profiles.
-   *
-   * @param device Remote device
-   * @param profile 2-octets service UUID. This is optional.
-   */
-  [NewObject, Throws]
-  DOMRequest connect(BluetoothDevice device, optional unsigned short serviceUuid);
-
-  [NewObject, Throws]
-  DOMRequest disconnect(BluetoothDevice device, optional unsigned short serviceUuid);
-
-  // One device can only send one file at a time
-  [NewObject, Throws]
-  DOMRequest sendFile(DOMString deviceAddress, Blob blob);
-  [NewObject, Throws]
-  DOMRequest stopSendingFile(DOMString deviceAddress);
-  [NewObject, Throws]
-  DOMRequest confirmReceivingFile(DOMString deviceAddress, boolean confirmation);
-
-  // Connect/Disconnect SCO (audio) connection
-  [NewObject, Throws]
-  DOMRequest connectSco();
-  [NewObject, Throws]
-  DOMRequest disconnectSco();
-  [NewObject, Throws]
-  DOMRequest isScoConnected();
-
-  /**
-   * Additional HFP methods to handle CDMA network.
-   *
-   * In GSM network we observe call operations from RIL call state changes;
-   * however in CDMA network RIL call states do not change under some call
-   * operations, so we need these additional methods to be informed of these
-   * operations from dialer.
-   *
-   * For more information please refer to bug 912005 and 925638.
-   */
-  [NewObject, Throws]
-  DOMRequest answerWaitingCall();
-  [NewObject, Throws]
-  DOMRequest ignoreWaitingCall();
-  [NewObject, Throws]
-  DOMRequest toggleCalls();
-
-  // AVRCP 1.3 methods
-  [NewObject, Throws]
-  DOMRequest sendMediaMetaData(optional MediaMetaData mediaMetaData);
-  [NewObject, Throws]
-  DOMRequest sendMediaPlayStatus(optional MediaPlayStatus mediaPlayStatus);
-};
-
-enum BluetoothAdapterState
-{
-  "disabled",
-  "disabling",
-  "enabled",
-  "enabling"
-};
-
-enum BluetoothAdapterAttribute
-{
-  "unknown",
-  "state",
-  "address",
-  "name",
-  "discoverable",
-  "discovering"
-};
-
deleted file mode 100644
--- a/dom/webidl/BluetoothAdapterEvent.webidl
+++ /dev/null
@@ -1,19 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[ChromeOnly,
- Constructor(DOMString type, optional BluetoothAdapterEventInit eventInitDict)]
-interface BluetoothAdapterEvent : Event
-{
-  readonly attribute BluetoothAdapter? adapter;
-  readonly attribute DOMString?        address;
-};
-
-dictionary BluetoothAdapterEventInit : EventInit
-{
-  BluetoothAdapter? adapter = null;
-  DOMString?        address = "";
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothAttributeEvent.webidl
+++ /dev/null
@@ -1,19 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[ChromeOnly,
- Constructor(DOMString type,
-             optional BluetoothAttributeEventInit eventInitDict)]
-interface BluetoothAttributeEvent : Event
-{
-  [Cached, Constant]
-  readonly attribute sequence<DOMString> attrs;
-};
-
-dictionary BluetoothAttributeEventInit : EventInit
-{
-  sequence<DOMString> attrs = [];
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothClassOfDevice.webidl
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-[ChromeOnly]
-interface BluetoothClassOfDevice
-{
-  /**
-   * The following constants are defined in Assigned Numbers of bluetooth
-   * General Access Profile (GAP) spec. For more information see
-   *   https://www.bluetooth.org/en-us/specification/assigned-numbers/baseband
-   */
-
-  // Major service class
-  const unsigned short LIMITED_DISCOVERABILITY = 0x0001;
-  const unsigned short POSITIONING             = 0x0008;
-  const unsigned short NETWORKING              = 0x0010;
-  const unsigned short RENDERING               = 0x0020;
-  const unsigned short CAPTURING               = 0x0040;
-  const unsigned short OBJECT_TRANSFER         = 0x0080;
-  const unsigned short AUDIO                   = 0x0100;
-  const unsigned short TELEPHONY               = 0x0200;
-  const unsigned short INFORMATION             = 0x0400;
-
-  // Major device class
-  const octet MISC          = 0x00;
-  const octet COMPUTER      = 0x01;
-  const octet PHONE         = 0x02;
-  const octet NETWORK       = 0x03;
-  const octet AUDIO_VIDEO   = 0x04;
-  const octet PERIPHERAL    = 0x05;
-  const octet IMAGING       = 0x06;
-  const octet WEARABLE      = 0x07;
-  const octet TOY           = 0x08;
-  const octet HEALTH        = 0x09;
-  const octet UNCATEGORIZED = 0x1F;
-
-  readonly attribute unsigned short majorServiceClass;
-  readonly attribute octet majorDeviceClass;
-  readonly attribute octet minorDeviceClass;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothDevice.webidl
+++ /dev/null
@@ -1,65 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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/. */
-
-[ChromeOnly]
-interface BluetoothDevice : EventTarget
-{
-  readonly attribute DOMString              address;
-  readonly attribute BluetoothClassOfDevice cod;
-  readonly attribute DOMString              name;
-  readonly attribute boolean                paired;
-  readonly attribute BluetoothDeviceType    type;
-
-  /**
-   * Retrieve the BluetoothGatt interface to interact with remote BLE devices.
-   * This attribute is null if the device type is not dual or le.
-   *
-   * [B2G only GATT client API]
-   * gatt attribute is exposed only if "dom.bluetooth.webbluetooth.enabled"
-   * preference is false.
-   */
-  [Func="mozilla::dom::bluetooth::BluetoothManager::B2GGattClientEnabled"]
-  readonly attribute BluetoothGatt?         gatt;
-
-  [Cached, Pure]
-  readonly attribute sequence<DOMString>    uuids;
-
-  // Fired when attribute(s) of BluetoothDevice changed
-           attribute EventHandler           onattributechanged;
-
-  /**
-   * Fetch the up-to-date UUID list of each bluetooth service that the device
-   * provides and refresh the cache value of attribute uuids if it is updated.
-   *
-   * If the operation succeeds, the promise will be resolved with up-to-date
-   * UUID list which is identical to attribute uuids.
-   */
-  [NewObject]
-  Promise<sequence<DOMString>>              fetchUuids();
-};
-
-enum BluetoothDeviceType
-{
-  "unknown",
-  "classic",
-  "le",
-  "dual"
-};
-
-/*
- * Possible device attributes that attributechanged event reports.
- * Note "address" and "type" are excluded since they never change once
- * BluetoothDevice is created.
- */
-enum BluetoothDeviceAttribute
-{
-  "unknown",
-  "cod",
-  "name",
-  "paired",
-  "uuids"
-};
-
deleted file mode 100644
--- a/dom/webidl/BluetoothDeviceEvent.webidl
+++ /dev/null
@@ -1,19 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[ChromeOnly,
- Constructor(DOMString type, optional BluetoothDeviceEventInit eventInitDict)]
-interface BluetoothDeviceEvent : Event
-{
-  readonly attribute BluetoothDevice? device;
-  readonly attribute DOMString?       address;
-};
-
-dictionary BluetoothDeviceEventInit : EventInit
-{
-  BluetoothDevice? device = null;
-  DOMString?       address = "";
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothDiscoveryHandle.webidl
+++ /dev/null
@@ -1,9 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-[ChromeOnly]
-interface BluetoothDiscoveryHandle : EventTarget {
-  attribute EventHandler ondevicefound;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothGatt.webidl
+++ /dev/null
@@ -1,63 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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/. */
-
-/**
- * [B2G only GATT client API]
- * BluetoothGatt interface is exposed only if
- * "dom.bluetooth.webbluetooth.enabled" preference is false.
- */
-[ChromeOnly,
- Func="mozilla::dom::bluetooth::BluetoothManager::B2GGattClientEnabled"]
-interface BluetoothGatt : EventTarget
-{
-  [Cached, Pure]
-  readonly attribute sequence<BluetoothGattService> services;
-  readonly attribute BluetoothConnectionState       connectionState;
-
-  // Fired when the value of any characteristic changed
-           attribute EventHandler                   oncharacteristicchanged;
-  // Fired when attribute connectionState changed
-           attribute EventHandler                   onconnectionstatechanged;
-
-  /**
-   * Connect/Disconnect to the remote BLE device if the connectionState is
-   * disconnected/connected. Otherwise, the Promise will be rejected directly.
-   *
-   * If current connectionState is disconnected/connected,
-   *   1) connectionState change to connecting/disconnecting along with a
-   *      connectionstatechanged event.
-   *   2) connectionState change to connected/disconnected if the operation
-   *      succeeds. Otherwise, change to disconnected/connected.
-   *   3) Promise is resolved or rejected according to the operation result.
-   */
-  [NewObject]
-  Promise<void>                                     connect();
-  [NewObject]
-  Promise<void>                                     disconnect();
-
-  /**
-   * Discover services, characteristics, descriptors offered by the remote GATT
-   * server. The promise will be rejected if the connState is not connected or
-   * operation fails.
-   */
-  [NewObject]
-  Promise<void>                                     discoverServices();
-
-  /**
-   * Read RSSI for the remote BLE device if the connectState is connected.
-   * Otherwise, the Promise will be rejected directly.
-   */
-  [NewObject]
-  Promise<short>                                    readRemoteRssi();
-};
-
-enum BluetoothConnectionState
-{
-  "disconnected",
-  "disconnecting",
-  "connected",
-  "connecting"
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothGattAttributeEvent.webidl
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[Constructor(DOMString type,
-             optional BluetoothGattAttributeEventInit eventInitDict),
- ChromeOnly]
-interface BluetoothGattAttributeEvent : Event
-{
-  readonly attribute DOMString                    address;
-  readonly attribute long                         requestId;
-  readonly attribute BluetoothGattCharacteristic? characteristic;
-  readonly attribute BluetoothGattDescriptor?     descriptor;
-  [Throws]
-  readonly attribute ArrayBuffer?                 value;
-  readonly attribute boolean                      needResponse;
-};
-
-dictionary BluetoothGattAttributeEventInit : EventInit
-{
-  DOMString address = "";
-  long requestId = 0;
-  BluetoothGattCharacteristic? characteristic = null;
-  BluetoothGattDescriptor? descriptor = null;
-  /**
-   * Note that the passed-in value will be copied by the event constructor
-   * here instead of storing the reference.
-   */
-  ArrayBuffer? value = null;
-  boolean needResponse = true;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothGattCharacteristic.webidl
+++ /dev/null
@@ -1,85 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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/. */
-
-dictionary GattCharacteristicProperties
-{
-  boolean broadcast = false;
-  boolean read = false;
-  boolean writeNoResponse = false;
-  boolean write = false;
-  boolean notify = false;
-  boolean indicate = false;
-  boolean signedWrite = false;
-  boolean extendedProps = false;
-};
-
-dictionary GattPermissions
-{
-  boolean read = false;
-  boolean readEncrypted = false;
-  boolean readEncryptedMITM = false;
-  boolean write = false;
-  boolean writeEncrypted = false;
-  boolean writeEncryptedMITM = false;
-  boolean writeSigned = false;
-  boolean writeSignedMITM = false;
-};
-
-/**
- * BluetoothGattCharacteristic could be in the server role as a characteristic
- * provided by a local GATT server, or in the client role as a characteristic
- * provided by a remote GATT server.
- */
-[ChromeOnly]
-interface BluetoothGattCharacteristic
-{
-  readonly attribute BluetoothGattService                   service;
-  [Cached, Pure]
-  readonly attribute sequence<BluetoothGattDescriptor>      descriptors;
-
-  readonly attribute DOMString                              uuid;
-  readonly attribute unsigned short                         instanceId;
-  readonly attribute ArrayBuffer?                           value;
-  [Cached, Constant]
-  readonly attribute GattPermissions                        permissions;
-  [Cached, Constant]
-  readonly attribute GattCharacteristicProperties           properties;
-
-  /**
-   * Read or write the value of this characteristic.
-   *
-   * If this charactersitic is in the client role, the value will be
-   * read from or written to the remote GATT server. Otherwise, the local value
-   * will be read/written.
-   */
-  [NewObject]
-  Promise<ArrayBuffer>  readValue();
-  [NewObject]
-  Promise<void>         writeValue(ArrayBuffer value);
-
-  /**
-   * Start or stop subscribing notifications of this characteristic from the
-   * remote GATT server.
-   *
-   * This API will be rejected if this characteristic is in the server role.
-   */
-  [NewObject]
-  Promise<void> startNotifications();
-  [NewObject]
-  Promise<void> stopNotifications();
-
-  /**
-   * Add a BLE descriptor to the local GATT characteristic.
-   *
-   * The promise will be rejected if this characteristic is in the client role
-   * since a GATT client is not allowed to manipulate the descriptor list in a
-   * remote GATT server.
-   */
-  [NewObject]
-  Promise<BluetoothGattDescriptor> addDescriptor(DOMString uuid,
-                                                 GattPermissions permissions,
-                                                 ArrayBuffer value);
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothGattCharacteristicEvent.webidl
+++ /dev/null
@@ -1,24 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-/**
- * [B2G only GATT client API]
- * BluetoothGattCharacteristicEvent interface is exposed only if
- * "dom.bluetooth.webbluetooth.enabled" preference is false.
- */
-[ChromeOnly,
- Func="mozilla::dom::bluetooth::BluetoothManager::B2GGattClientEnabled",
- Constructor(DOMString type,
-             optional BluetoothGattCharacteristicEventInit eventInitDict)]
-interface BluetoothGattCharacteristicEvent : Event
-{
-  readonly attribute BluetoothGattCharacteristic? characteristic;
-};
-
-dictionary BluetoothGattCharacteristicEventInit : EventInit
-{
-  BluetoothGattCharacteristic? characteristic = null;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothGattDescriptor.webidl
+++ /dev/null
@@ -1,32 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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/. */
-
-/**
- * BluetoothGattDescriptor could be in the server role as a descriptor provided
- * by a local GATT server, or in the client role as a descriptor provided by a
- * remote GATT server.
- */
-[ChromeOnly]
-interface BluetoothGattDescriptor
-{
-  readonly attribute BluetoothGattCharacteristic            characteristic;
-  readonly attribute DOMString                              uuid;
-  readonly attribute ArrayBuffer?                           value;
-  [Cached, Constant]
-  readonly attribute GattPermissions                        permissions;
-
-  /**
-   * Read or write the value of this descriptor.
-   *
-   * If this descriptor is in the client role, the value will be read from or
-   * written to the remote GATT server. Otherwise, the local value will be
-   * read/written.
-   */
-  [NewObject]
-  Promise<ArrayBuffer>  readValue();
-  [NewObject]
-  Promise<void>         writeValue(ArrayBuffer value);
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothGattServer.webidl
+++ /dev/null
@@ -1,141 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-dictionary BluetoothAdvertisingData
-{
-  /**
-   * Uuid value of Appearance characteristic of the GAP service which can be
-   * mapped to an icon or string that describes the physical representation of
-   * the device during the device discovery procedure.
-   */
-  unsigned short appearance = 0;
-
-  /**
-   * Whether to broadcast with device name or not.
-   */
-  boolean includeDevName = false;
-
-  /**
-   * Whether to broadcast with TX power or not.
-   */
-  boolean includeTxPower = false;
-
-  /**
-   * Company Identifier Code for manufacturer data.
-   *
-   * This ID will be combined with |manufacturerData| byte array specified
-   * below as the broadcasting manufacturer data. Please see Core Specification
-   * Supplement (CSS) v6 1.4 for more details.
-   */
-  unsigned short manufacturerId = 0;
-
-  /**
-   * Byte array of custom manufacturer specific data.
-   *
-   * These bytes will be appended to |manufacturerId| specified above as the
-   * broadcasting manufacturer data. Please see Core Specification Supplement
-   * (CSS) v6 1.4 for more details.
-   */
-  ArrayBuffer? manufacturerData = null;
-
-  /**
-   * 128-bit Service UUID for service data.
-   *
-   * This UUID will be combinded with |serviceData| specified below as the
-   * broadcasting service data. Please see Core Specification Supplement (CSS)
-   * v6 1.11 for more details.
-   */
-  DOMString serviceUuid = "";
-
-  /**
-   * Data associated with |serviceUuid|.
-   *
-   * These bytes will be appended to |serviceUuid| specified above as the
-   * broadcasting manufacturer data. Please see Core Specification Supplement
-   * (CSS) v6 1.11 for more details.
-   */
-  ArrayBuffer? serviceData = null;
-
-  /**
-   * A list of Service or Service Class UUIDs.
-   * Please see Core Specification Supplement (CSS) v6 1.1 for more details.
-   */
-  sequence<DOMString> serviceUuids = [];
-};
-
-[ChromeOnly]
-interface BluetoothGattServer : EventTarget
-{
-  [Cached, Pure]
-  readonly attribute sequence<BluetoothGattService> services;
-
-  // Fired when a remote device has been connected/disconnected
-  attribute EventHandler  onconnectionstatechanged;
-
-  // Fired when a remote BLE client send a read/write request
-  attribute EventHandler  onattributereadreq;
-  attribute EventHandler  onattributewritereq;
-
-  /**
-   * Connect/Disconnect to the remote BLE device with the target address.
-   *
-   * Promise will be rejected if the local GATT server is busy connecting or
-   * disconnecting to other devices.
-   */
-  [NewObject]
-  Promise<void> connect(DOMString address);
-  [NewObject]
-  Promise<void> disconnect(DOMString address);
-
-  /**
-   * Start or stop advertising data to nearby devices.
-   *
-   * Application may customize the advertising data by passing advData to
-   * |startAdvertising|. By performing |startAdvertising|, remote central
-   * devices can then discover and initiate a connection with our local device.
-   * A 'connectionstatechanged' event will be fired when a remote central
-   * device connects to the local device.
-   */
-  [NewObject]
-  Promise<void> startAdvertising(optional BluetoothAdvertisingData advData);
-  [NewObject]
-  Promise<void> stopAdvertising();
-
-  /**
-   * Add a BLE service to the local GATT server.
-   *
-   * This API will be rejected if this service has been added to the GATT
-   * server.
-   */
-  [NewObject]
-  Promise<void> addService(BluetoothGattService service);
-
-  /**
-   * Remove a BLE service to the local GATT server.
-   *
-   * This API will be rejected if this service does not exist in the GATT
-   * server.
-   */
-  [NewObject]
-  Promise<void> removeService(BluetoothGattService service);
-
-  /**
-   * Notify the remote BLE device that the value of a characteristic has been
-   * changed.
-   */
-  [NewObject]
-  Promise<void> notifyCharacteristicChanged(
-    DOMString address,
-    BluetoothGattCharacteristic characteristic,
-    boolean confirm);
-
-  /**
-   * Send a read/write response to a remote BLE client
-   */
-  [NewObject]
-  Promise<void> sendResponse(
-    DOMString address, unsigned short status, long requestId);
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothGattService.webidl
+++ /dev/null
@@ -1,54 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* vim: set ts=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/. */
-
-/**
- * BluetoothGattService could be in the server role as a service provided by a
- * local GATT server, or in the client role as a service provided by a remote
- * GATT server.
- */
-[ChromeOnly, Constructor(BluetoothGattServiceInit init)]
-interface BluetoothGattService
-{
-  [Cached, Pure]
-  readonly attribute sequence<BluetoothGattCharacteristic>  characteristics;
-  [Cached, Pure]
-  readonly attribute sequence<BluetoothGattService>         includedServices;
-
-  readonly attribute boolean                                isPrimary;
-  readonly attribute DOMString                              uuid;
-  readonly attribute unsigned short                         instanceId;
-
-  /**
-   * Add a BLE characteristic to the local GATT service.
-   *
-   * This API will be rejected if this service is in the client role since a
-   * GATT client is not allowed to manipulate the characteristic list in a
-   * remote GATT server.
-   */
-  [NewObject]
-  Promise<BluetoothGattCharacteristic> addCharacteristic(
-    DOMString uuid,
-    GattPermissions permissions,
-    GattCharacteristicProperties properties,
-    ArrayBuffer value);
-
-  /**
-   * Add a BLE included service to the local GATT service.
-   *
-   * This API will be rejected if this service is in the client role since a
-   * GATT client is not allowed to manipulate the included service list in a
-   * remote GATT server. The included service to be added should be an existing
-   * service of the same GATT server. Otherwise this API will be rejected.
-   */
-  [NewObject]
-  Promise<void> addIncludedService(BluetoothGattService service);
-};
-
-dictionary BluetoothGattServiceInit
-{
-  boolean isPrimary = false;
-  DOMString uuid = "";
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothLeDeviceEvent.webidl
+++ /dev/null
@@ -1,28 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-/**
- * [B2G only GATT client API]
- * BluetoothLeDeviceEvent interface is exposed only if
- * "dom.bluetooth.webbluetooth.enabled" preference is false.
- */
-[ChromeOnly,
- Func="mozilla::dom::bluetooth::BluetoothManager::B2GGattClientEnabled",
- Constructor(DOMString type, optional BluetoothLeDeviceEventInit eventInitDict)]
-interface BluetoothLeDeviceEvent : Event
-{
-  readonly attribute BluetoothDevice? device;
-  readonly attribute short rssi;
-  [Throws]
-  readonly attribute ArrayBuffer? scanRecord;
-};
-
-dictionary BluetoothLeDeviceEventInit : EventInit
-{
-  BluetoothDevice? device = null;
-  short rssi = 0;
-  ArrayBuffer? scanRecord = null;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothManager.webidl
+++ /dev/null
@@ -1,27 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-[ChromeOnly]
-interface BluetoothManager: EventTarget
-{
-  readonly attribute BluetoothAdapter? defaultAdapter;
-
-  // Fired when attribute(s) of BluetoothManager changed
-           attribute EventHandler onattributechanged;
-
-  // Fired when a new adapter is plugged in
-           attribute EventHandler onadapteradded;
-
-  // Fired when an existing adapter is unplugged
-           attribute EventHandler onadapterremoved;
-
-  sequence<BluetoothAdapter> getAdapters();
-};
-
-enum BluetoothManagerAttribute
-{
-  "unknown",
-  "defaultAdapter"
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothMapFolderListingEvent.webidl
+++ /dev/null
@@ -1,24 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[ChromeOnly,
- Constructor(DOMString type,
-             optional BluetoothMapFolderListingEventInit eventInitDict)]
-interface BluetoothMapFolderListingEvent : Event
-{
-  readonly attribute unsigned long              maxListCount;
-  readonly attribute unsigned long              listStartOffset;
-
-  readonly attribute BluetoothMapRequestHandle? handle;
-};
-
-dictionary BluetoothMapFolderListingEventInit : EventInit
-{
-  unsigned long             maxListCount = 0;
-  unsigned long             listStartOffset = 0;
-
-  BluetoothMapRequestHandle? handle = null;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothMapGetMessageEvent.webidl
+++ /dev/null
@@ -1,24 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[ChromeOnly,
- Constructor(DOMString type,
-             optional BluetoothMapGetMessageEventInit eventInitDict)]
-interface BluetoothMapGetMessageEvent : Event
-{
-  readonly attribute boolean          hasAttachment;
-  readonly attribute FilterCharset    charset;
-
-  readonly attribute BluetoothMapRequestHandle? handle;
-};
-
-dictionary BluetoothMapGetMessageEventInit : EventInit
-{
-  boolean                   hasAttachment = false;
-  FilterCharset             charset = "utf-8";
-
-  BluetoothMapRequestHandle? handle = null;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothMapMessageUpdateEvent.webidl
+++ /dev/null
@@ -1,22 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[ChromeOnly,
- Constructor(DOMString type,
-             optional BluetoothMapMessageUpdateEventInit eventInitDict)]
-interface BluetoothMapMessageUpdateEvent : Event
-{
-  readonly attribute unsigned long         instanceId;
-
-  readonly attribute BluetoothMapRequestHandle? handle;
-};
-
-dictionary BluetoothMapMessageUpdateEventInit : EventInit
-{
-  unsigned long                   instanceId = 0;
-
-  BluetoothMapRequestHandle? handle = null;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothMapMessagesListingEvent.webidl
+++ /dev/null
@@ -1,43 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[ChromeOnly,
- Constructor(DOMString type,
-             optional BluetoothMapMessagesListingEventInit eventInitDict)]
-interface BluetoothMapMessagesListingEvent : Event
-{
-  readonly attribute unsigned long              maxListCount;
-  readonly attribute unsigned long              listStartOffset;
-  readonly attribute unsigned long              subjectLength;
-  [Cached, Constant]
-  readonly attribute sequence<ParameterMask>    parameterMask;
-  readonly attribute MessageType                filterMessageType;
-  readonly attribute DOMString                  filterPeriodBegin;
-  readonly attribute DOMString                  filterPeriodEnd;
-  readonly attribute ReadStatus                 filterReadStatus;
-  readonly attribute DOMString                  filterRecipient;
-  readonly attribute DOMString                  filterOriginator;
-  readonly attribute Priority                   filterPriority;
-
-  readonly attribute BluetoothMapRequestHandle? handle;
-};
-
-dictionary BluetoothMapMessagesListingEventInit : EventInit
-{
-  unsigned long             maxListCount = 0;
-  unsigned long             listStartOffset = 0;
-  unsigned long             subjectLength = 0;
-  sequence<ParameterMask>   parameterMask = [];
-  MessageType               filterMessageType = "no-filtering";
-  DOMString                 filterPeriodBegin = "";
-  DOMString                 filterPeriodEnd = "";
-  ReadStatus                filterReadStatus = "no-filtering";
-  DOMString                 filterRecipient = "";
-  DOMString                 filterOriginator = "";
-  Priority                  filterPriority = "no-filtering";
-
-  BluetoothMapRequestHandle? handle = null;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothMapParameters.webidl
+++ /dev/null
@@ -1,62 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-/**
- * MAP Application Parameters
- */
-enum MessageType
-{
-  "no-filtering",
-  "sms",
-  "email",
-  "mms"
-};
-
-enum ReadStatus
-{
-  "no-filtering",
-  "unread",
-  "read"
-};
-
-enum Priority
-{
-  "no-filtering",
-  "high-priority",
-  "non-priority"
-};
-
-enum ParameterMask
-{
-  "subject",
-  "datetime",
-  "sender_name",
-  "sender_addressing",
-  "recipient_name",
-  "recipient_addressing",
-  "type",
-  "size",
-  "reception_status",
-  "text",
-  "attachment_size",
-  "priority",
-  "read",
-  "sent",
-  "protected",
-  "replyto_addressing",
-};
-
-enum FilterCharset
-{
-  "native",
-  "utf-8"
-};
-
-enum StatusIndicators
-{
-  "readstatus",
-  "deletedstatus"
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothMapRequestHandle.webidl
+++ /dev/null
@@ -1,55 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-[ChromeOnly]
-interface BluetoothMapRequestHandle
-{
-  /**
-   * Reply to Folder-Listing object for MAP request. The Promise will be
-   * rejected if the MAP request operation fails.
-   */
-  [NewObject, Throws]
-  Promise<void> replyToFolderListing(long masId, DOMString folders);
-
-  /**
-   * Reply the Messages-Listing object to the MAP request. The Promise will
-   * be rejected if the MAP request operation fails.
-   */
-  [NewObject, Throws]
-  Promise<void> replyToMessagesListing(
-    long masId,
-    Blob messageslisting,
-    boolean newmessage,
-    DOMString timestamp,
-    unsigned long size);
-
-  /**
-   * Reply GetMessage object to the MAP request. The Promise will be rejected
-   * if the MAP request operation fails.
-   */
-  [NewObject, Throws]
-  Promise<void> replyToGetMessage(long masId, Blob bmessage);
-
-  /**
-   * Reply SetMessage object to the MAP request. The Promise will be rejected
-   * if the MAP request operation fails.
-   */
-  [NewObject, Throws]
-  Promise<void> replyToSetMessageStatus(long masId, boolean status);
-
-  /**
-   * Reply SendMessage request to the MAP request. The Promise will be rejected
-   * if the MAP request operation fails.
-   */
-  [NewObject, Throws]
-  Promise<void> replyToSendMessage(long masId, DOMString handleId, boolean status);
-
-  /**
-   * Reply Message-Update object to the MAP request. The Promise will be
-   * rejected if the MAP request operation fails.
-   */
-  [NewObject, Throws]
-  Promise<void> replyToMessageUpdate(long masId, boolean status);
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothMapSendMessageEvent.webidl
+++ /dev/null
@@ -1,26 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[ChromeOnly,
- Constructor(DOMString type,
-             optional BluetoothMapSendMessageEventInit eventInitDict)]
-interface BluetoothMapSendMessageEvent : Event
-{
-  readonly attribute DOMString        recipient;
-  readonly attribute DOMString        messageBody;
-  readonly attribute unsigned long    retry;
-
-  readonly attribute BluetoothMapRequestHandle? handle;
-};
-
-dictionary BluetoothMapSendMessageEventInit : EventInit
-{
-  DOMString                 recipient = "";
-  DOMString                 messageBody = "";
-  unsigned long             retry = 0;
-
-  BluetoothMapRequestHandle? handle = null;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothMapSetMessageStatusEvent.webidl
+++ /dev/null
@@ -1,26 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[ChromeOnly,
- Constructor(DOMString type,
-             optional BluetoothMapSetMessageStatusEventInit eventInitDict)]
-interface BluetoothMapSetMessageStatusEvent : Event
-{
-  readonly attribute unsigned long     handleId;
-  readonly attribute StatusIndicators  statusIndicator;
-  readonly attribute boolean           statusValue;
-
-  readonly attribute BluetoothMapRequestHandle? handle;
-};
-
-dictionary BluetoothMapSetMessageStatusEventInit : EventInit
-{
-  unsigned long             handleId = 0;
-  StatusIndicators          statusIndicator = "readstatus";
-  boolean                   statusValue = false;
-
-  BluetoothMapRequestHandle? handle = null;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothObexAuthEvent.webidl
+++ /dev/null
@@ -1,20 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[ChromeOnly,
- Constructor(DOMString type,
-             optional BluetoothObexAuthEventInit eventInitDict)]
-interface BluetoothObexAuthEvent : Event
-{
-  readonly attribute DOMString?               userId;
-  readonly attribute BluetoothObexAuthHandle? handle;
-};
-
-dictionary BluetoothObexAuthEventInit : EventInit
-{
-  DOMString? userId = "";
-  BluetoothObexAuthHandle? handle = null;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothObexAuthHandle.webidl
+++ /dev/null
@@ -1,20 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-[ChromeOnly]
-interface BluetoothObexAuthHandle
-{
-  /**
-   * Reply password for obexpasswordreq. The promise will be rejected if the
-   * operation fails.
-   */
-  [NewObject]
-  Promise<void> setPassword(DOMString aPassword);
-
-  // Reject the OBEX authentication request. The promise will be rejected if
-  // operation fails.
-  [NewObject]
-  Promise<void> reject();
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothPairingEvent.webidl
+++ /dev/null
@@ -1,20 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[ChromeOnly,
- Constructor(DOMString type,
-             optional BluetoothPairingEventInit eventInitDict)]
-interface BluetoothPairingEvent : Event
-{
-  readonly attribute DOMString               deviceName;
-  readonly attribute BluetoothPairingHandle? handle;
-};
-
-dictionary BluetoothPairingEventInit : EventInit
-{
-  DOMString deviceName = "";
-  BluetoothPairingHandle? handle = null;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothPairingHandle.webidl
+++ /dev/null
@@ -1,34 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-[ChromeOnly]
-interface BluetoothPairingHandle
-{
-  /**
-   * A 6-digit string ranging from decimal 000000 to 999999.
-   * This attribute is an empty string for enterpincodereq and
-   * pairingconsentreq.
-   */
-  readonly attribute DOMString passkey;
-
-  /**
-   * Reply pin code for enterpincodereq. The promise will be rejected if the
-   * pairing request type is not enterpincodereq or operation fails.
-   */
-  [NewObject]
-  Promise<void> setPinCode(DOMString aPinCode);
-
-  /**
-   * Accept pairing requests. The promise will be rejected if the pairing
-   * request type is not pairingconfirmationreq or pairingconsentreq or
-   * operation fails.
-   */
-  [NewObject]
-  Promise<void> accept();
-
-  // Reject pairing requests. The promise will be rejected if operation fails.
-  [NewObject]
-  Promise<void> reject();
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothPairingListener.webidl
+++ /dev/null
@@ -1,13 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-[ChromeOnly]
-interface BluetoothPairingListener: EventTarget
-{
-  attribute EventHandler ondisplaypasskeyreq;
-  attribute EventHandler onenterpincodereq;
-  attribute EventHandler onpairingconfirmationreq;
-  attribute EventHandler onpairingconsentreq;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothPbapParameters.webidl
+++ /dev/null
@@ -1,81 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-/**
- * This enum holds the parameters to indicate the properties contained in the
- * requested vCard objects.
- */
-enum vCardProperties
-{
-  "version",
-  "fn",
-  "n",
-  "photo",
-  "bday",
-  "adr",
-  "label",
-  "tel",
-  "email",
-  "mailer",
-  "tz",
-  "geo",
-  "title",
-  "role",
-  "logo",
-  "agent",
-  "org",
-  "note",
-  "rev",
-  "sound",
-  "url",
-  "uid",
-  "key",
-  "nickname",
-  "categories",
-  "proid",
-  "class",
-  "sort-string",
-  "x-irmc-call-datetime",
-  "x-bt-speeddialkey",
-  "x-bt-uci",
-  "x-bt-uid"
-};
-
-/**
- * This enum holds the parameters to indicate the sorting order of vCard
- * objects.
- */
-enum vCardOrderType {
-  "indexed",  // default
-  "alphabetical",
-  "phonetical"
-};
-
-/**
- * This enum holds the parameters to indicate the search key of the search
- * operation.
- */
-enum vCardSearchKeyType {
-  "name",  // default
-  "number",
-  "sound"
-};
-
-/**
- * This enum holds the parameters to indicate the vCard version.
- */
-enum vCardVersion {
-  "vCard21", // default
-  "vCard30"
-};
-
-/**
- * This enum holds the parameters to indicate the type of vCard selector.
- */
-enum vCardSelectorOp {
-  "OR", // default
-  "AND"
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothPbapRequestHandle.webidl
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-[ChromeOnly]
-interface BluetoothPbapRequestHandle
-{
-  /**
-   * Reply vCard object to the PBAP request. The DOMRequest will get onerror
-   * callback if the PBAP request type is not 'pullvcardentryreq' or operation
-   * fails.
-   */
-  [NewObject, Throws]
-  DOMRequest replyTovCardPulling(Blob vcardObject);
-
-  /**
-   * Reply vCard object to the PBAP request. The DOMRequest will get onerror
-   * callback if the PBAP request type is not 'pullphonebookreq' or operation
-   * fails.
-   */
-  [NewObject, Throws]
-  DOMRequest replyToPhonebookPulling(Blob vcardObject,
-                                     unsigned long long phonebookSize);
-  /**
-   * Reply vCard object to the PBAP request. The DOMRequest will get onerror
-   * callback if the PBAP request type is not 'pullvcardlistingreq' or operation
-   * fails.
-   */
-  [NewObject, Throws]
-  DOMRequest replyTovCardListing(Blob vcardObject,
-                                 unsigned long long phonebookSize);
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothPhonebookPullingEvent.webidl
+++ /dev/null
@@ -1,36 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[ChromeOnly,
- Constructor(DOMString type,
-             optional BluetoothPhonebookPullingEventInit eventInitDict)]
-interface BluetoothPhonebookPullingEvent : Event
-{
-  readonly attribute DOMString                  name;
-  readonly attribute vCardVersion               format;
-  [Cached, Constant]
-  readonly attribute sequence<vCardProperties>  propSelector;
-  readonly attribute unsigned long              maxListCount;
-  readonly attribute unsigned long              listStartOffset;
-  [Cached, Constant]
-  readonly attribute sequence<vCardProperties>  vcardSelector;
-  readonly attribute vCardSelectorOp            vcardSelectorOperator;
-
-  readonly attribute BluetoothPbapRequestHandle? handle;
-};
-
-dictionary BluetoothPhonebookPullingEventInit : EventInit
-{
-  DOMString                 name = "";
-  vCardVersion              format = "vCard21";
-  sequence<vCardProperties> propSelector = [];
-  unsigned long             maxListCount = 0;
-  unsigned long             listStartOffset = 0;
-  sequence<vCardProperties> vcardSelector = [];
-  vCardSelectorOp           vcardSelectorOperator = "OR";
-
-  BluetoothPbapRequestHandle? handle = null;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothStatusChangedEvent.webidl
+++ /dev/null
@@ -1,20 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[Constructor(DOMString type,
-             optional BluetoothStatusChangedEventInit eventInitDict),
- ChromeOnly]
-interface BluetoothStatusChangedEvent : Event
-{
-  readonly attribute DOMString address;
-  readonly attribute boolean status;
-};
-
-dictionary BluetoothStatusChangedEventInit : EventInit
-{
-  DOMString address = "";
-  boolean status = false;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothUUID.webidl
+++ /dev/null
@@ -1,27 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- *
- * The origin of this IDL file is
- * https://webbluetoothcg.github.io/web-bluetooth/#uuids
- *
- */
-
-typedef DOMString UUID;
-typedef (DOMString or unsigned long) BluetoothServiceUUID;
-typedef (DOMString or unsigned long) BluetoothCharacteristicUUID;
-typedef (DOMString or unsigned long) BluetoothDescriptorUUID;
-
-[Pref="dom.bluetooth.webbluetooth.enable", ChromeOnly]
-interface BluetoothUUID
-{
-  [Throws]
-  static UUID getService(BluetoothServiceUUID name);
-  [Throws]
-  static UUID getCharacteristic(BluetoothCharacteristicUUID name);
-  [Throws]
-  static UUID getDescriptor(BluetoothDescriptorUUID name);
-
-  static UUID canonicalUUID([EnforceRange] unsigned long alias);
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothVCardListingEvent.webidl
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[ChromeOnly,
- Constructor(DOMString type,
-             optional BluetoothVCardListingEventInit eventInitDict)]
-interface BluetoothVCardListingEvent : Event
-{
-  readonly attribute DOMString                 name;
-  readonly attribute vCardOrderType            order;
-  readonly attribute DOMString                 searchValue;
-  readonly attribute vCardSearchKeyType        searchKey;
-  readonly attribute unsigned long             maxListCount;
-  readonly attribute unsigned long             listStartOffset;
-  [Cached, Constant]
-  readonly attribute sequence<vCardProperties> vcardSelector;
-  readonly attribute vCardSelectorOp           vcardSelectorOperator;
-
-  readonly attribute BluetoothPbapRequestHandle? handle;
-};
-
-dictionary BluetoothVCardListingEventInit : EventInit
-{
-  DOMString                  name = "";
-  vCardOrderType             order = "indexed";
-  DOMString                  searchValue = "";
-  vCardSearchKeyType         searchKey = "name";
-  unsigned long              maxListCount = 0;
-  unsigned long              listStartOffset = 0;
-  sequence<vCardProperties>  vcardSelector = [];
-  vCardSelectorOp            vcardSelectorOperator = "OR";
-
-  BluetoothPbapRequestHandle? handle = null;
-};
deleted file mode 100644
--- a/dom/webidl/BluetoothVCardPullingEvent.webidl
+++ /dev/null
@@ -1,27 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[ChromeOnly,
- Constructor(DOMString type,
-             optional BluetoothVCardPullingEventInit eventInitDict)]
-interface BluetoothVCardPullingEvent : Event
-{
-  readonly attribute DOMString                 name;
-  readonly attribute vCardVersion              format;
-  [Cached, Constant]
-  readonly attribute sequence<vCardProperties> propSelector;
-
-  readonly attribute BluetoothPbapRequestHandle? handle;
-};
-
-dictionary BluetoothVCardPullingEventInit : EventInit
-{
-  DOMString                 name = "";
-  vCardVersion              format = "vCard21";
-  sequence<vCardProperties> propSelector = [];
-
-  BluetoothPbapRequestHandle? handle = null;
-};
--- a/dom/webidl/Navigator.webidl
+++ b/dom/webidl/Navigator.webidl
@@ -299,23 +299,16 @@ partial interface Navigator {
 partial interface Navigator {
   [Throws, Pref="dom.vr.enabled"]
   Promise<sequence<VRDisplay>> getVRDisplays();
   // TODO: Use FrozenArray once available. (Bug 1236777)
   [Frozen, Cached, Pure, Pref="dom.vr.enabled"]
   readonly attribute sequence<VRDisplay> activeVRDisplays;
 };
 
-#ifdef MOZ_B2G_BT
-partial interface Navigator {
-  [Throws, ChromeOnly, UnsafeInPrerendering]
-  readonly attribute BluetoothManager mozBluetooth;
-};
-#endif // MOZ_B2G_BT
-
 #ifdef MOZ_TIME_MANAGER
 // nsIDOMMozNavigatorTime
 partial interface Navigator {
   [Throws, ChromeOnly, UnsafeInPrerendering]
   readonly attribute MozTimeManager mozTime;
 };
 #endif // MOZ_TIME_MANAGER
 
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -680,40 +680,16 @@ WEBIDL_FILES += [
 # We only expose our prefable test interfaces in debug builds, just to be on
 # the safe side.
 if CONFIG['MOZ_DEBUG']:
     WEBIDL_FILES += ['TestFunctions.webidl',
                      'TestInterfaceJS.webidl',
                      'TestInterfaceJSDictionaries.webidl',
                      'TestInterfaceJSMaplikeSetlikeIterable.webidl']
 
-if CONFIG['MOZ_B2G_BT']:
-    WEBIDL_FILES += [
-        'BluetoothAdapter.webidl',
-        'BluetoothClassOfDevice.webidl',
-        'BluetoothDevice.webidl',
-        'BluetoothDiscoveryHandle.webidl',
-        'BluetoothGatt.webidl',
-        'BluetoothGattAttributeEvent.webidl',
-        'BluetoothGattCharacteristic.webidl',
-        'BluetoothGattDescriptor.webidl',
-        'BluetoothGattServer.webidl',
-        'BluetoothGattService.webidl',
-        'BluetoothLeDeviceEvent.webidl',
-        'BluetoothManager.webidl',
-        'BluetoothMapParameters.webidl',
-        'BluetoothMapRequestHandle.webidl',
-        'BluetoothObexAuthHandle.webidl',
-        'BluetoothPairingHandle.webidl',
-        'BluetoothPairingListener.webidl',
-        'BluetoothPbapParameters.webidl',
-        'BluetoothPbapRequestHandle.webidl',
-        'BluetoothUUID.webidl',
-    ]
-
 if CONFIG['MOZ_SECUREELEMENT']:
     WEBIDL_FILES += [
          'SecureElement.webidl',
          'SecureElementManager.webidl',
     ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     WEBIDL_FILES += [
@@ -802,36 +778,16 @@ if CONFIG['MOZ_WEBSPEECH']:
 
 if CONFIG['MOZ_GAMEPAD']:
     GENERATED_EVENTS_WEBIDL_FILES += [
         'GamepadAxisMoveEvent.webidl',
         'GamepadButtonEvent.webidl',
         'GamepadEvent.webidl',
     ]
 
-if CONFIG['MOZ_B2G_BT']:
-    GENERATED_EVENTS_WEBIDL_FILES += [
-        'BluetoothAdapterEvent.webidl',
-        'BluetoothAttributeEvent.webidl',
-        'BluetoothDeviceEvent.webidl',
-        'BluetoothGattCharacteristicEvent.webidl',
-        'BluetoothMapFolderListingEvent.webidl',
-        'BluetoothMapGetMessageEvent.webidl',
-        'BluetoothMapMessagesListingEvent.webidl',
-        'BluetoothMapMessageUpdateEvent.webidl',
-        'BluetoothMapSendMessageEvent.webidl',
-        'BluetoothMapSetMessageStatusEvent.webidl',
-        'BluetoothObexAuthEvent.webidl',
-        'BluetoothPairingEvent.webidl',
-        'BluetoothPhonebookPullingEvent.webidl',
-        'BluetoothStatusChangedEvent.webidl',
-        'BluetoothVCardListingEvent.webidl',
-        'BluetoothVCardPullingEvent.webidl'
-    ]
-
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     GENERATED_EVENTS_WEBIDL_FILES += [
         'MozWifiConnectionInfoEvent.webidl',
         'MozWifiP2pStatusChangeEvent.webidl',
         'MozWifiStationInfoEvent.webidl',
         'MozWifiStatusChangeEvent.webidl',
     ]
 
--- a/ipc/dbus/moz.build
+++ b/ipc/dbus/moz.build
@@ -17,21 +17,16 @@ EXPORTS.mozilla.ipc += [
 
 SOURCES += [
     'DBusHelpers.cpp',
     'DBusUtils.cpp',
     'DBusWatcher.cpp',
     'RawDBusConnection.cpp',
 ]
 
-if CONFIG['MOZ_B2G_BT_BLUEZ']:
-    LOCAL_INCLUDES += [
-        '%' + '%s/external/dbus' % CONFIG['ANDROID_SOURCE']
-    ]
-
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 if CONFIG['MOZ_ENABLE_DBUS']:
     CFLAGS += CONFIG['MOZ_DBUS_CFLAGS']
     CFLAGS += CONFIG['MOZ_DBUS_GLIB_CFLAGS']
     CXXFLAGS += CONFIG['MOZ_DBUS_CFLAGS']
--- a/ipc/moz.build
+++ b/ipc/moz.build
@@ -9,20 +9,20 @@ DIRS += [
     'glue',
     'ipdl',
     'testshell',
 ]
 
 if CONFIG['MOZ_B2G_RIL']:
     DIRS += ['ril']
 
-if CONFIG['MOZ_ENABLE_DBUS'] or CONFIG['MOZ_B2G_BT_BLUEZ']:
+if CONFIG['MOZ_ENABLE_DBUS']:
     DIRS += ['dbus']
 
-if CONFIG['MOZ_B2G_RIL'] or CONFIG['MOZ_B2G_BT'] or CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
+if CONFIG['MOZ_B2G_RIL'] or CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     DIRS += ['unixfd', 'unixsocket']
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     DIRS += ['hal', 'keystore', 'netd']
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android':
     DIRS += ['contentproc']
 
--- a/js/xpconnect/src/moz.build
+++ b/js/xpconnect/src/moz.build
@@ -61,15 +61,10 @@ LOCAL_INCLUDES += [
     '/dom/html',
     '/dom/svg',
     '/dom/workers',
     '/layout/base',
     '/layout/style',
     '/xpcom/reflect/xptinfo',
 ]
 
-if CONFIG['MOZ_B2G_BT']:
-    LOCAL_INCLUDES += [
-        '/dom/bluetooth/common',
-    ]
-
 if CONFIG['GNU_CXX']:
     CXXFLAGS += ['-Wno-shadow', '-Werror=format']
--- a/layout/build/moz.build
+++ b/layout/build/moz.build
@@ -73,21 +73,16 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'an
         '/dom/system',
         '/dom/system/android',
     ]
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     LOCAL_INCLUDES += [
         '/dom/system/gonk',
     ]
 
-if CONFIG['MOZ_B2G_BT']:
-    LOCAL_INCLUDES += [
-        '/dom/bluetooth/common',
-    ]
-
 if CONFIG['MOZ_WEBSPEECH']:
     LOCAL_INCLUDES += [
         '/dom/media/webspeech/recognition',
         '/dom/media/webspeech/synth',
     ]
 
 if CONFIG['MOZ_WEBSPEECH_POCKETSPHINX']:
     LOCAL_INCLUDES += [
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -102,25 +102,16 @@
 
 #ifdef MOZ_WIDGET_GONK
 #include "SystemWorkerManager.h"
 using mozilla::dom::gonk::SystemWorkerManager;
 #define SYSTEMWORKERMANAGER_CID \
   {0xd53b6524, 0x6ac3, 0x42b0, {0xae, 0xca, 0x62, 0xb3, 0xc4, 0xe5, 0x2b, 0x04}}
 #endif
 
-#ifdef MOZ_B2G_BT
-#include "BluetoothService.h"
-using mozilla::dom::bluetooth::BluetoothService;
-#define BLUETOOTHSERVICE_CID \
-  {0xa753b487, 0x3344, 0x4de4, {0xad, 0x5f, 0x06, 0x36, 0x76, 0xa7, 0xc1, 0x04}}
-#define BLUETOOTHSERVICE_CONTRACTID \
-  "@mozilla.org/bluetooth/service;1"
-#endif
-
 #ifdef MOZ_WIDGET_GONK
 #include "AudioManager.h"
 using mozilla::dom::gonk::AudioManager;
 #include "nsVolumeService.h"
 using mozilla::system::nsVolumeService;
 #endif
 
 #include "mozilla/dom/PushNotifier.h"
@@ -304,20 +295,16 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR
                                          ServiceWorkerManager::GetInstance)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(WorkerDebuggerManager,
                                          WorkerDebuggerManager::GetInstance)
 
 #ifdef MOZ_WIDGET_GONK
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(SystemWorkerManager,
                                          SystemWorkerManager::FactoryCreate)
 #endif
-#ifdef MOZ_B2G_BT
-NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(BluetoothService,
-                                         BluetoothService::FactoryCreate)
-#endif
 
 #ifdef MOZ_WEBSPEECH
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSynthVoiceRegistry,
                                          nsSynthVoiceRegistry::GetInstanceForService)
 #endif
 
 #ifdef MOZ_WIDGET_GONK
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(AudioManager,
@@ -736,19 +723,16 @@ NS_DEFINE_NAMED_CID(QUOTAMANAGER_SERVICE
 NS_DEFINE_NAMED_CID(SERVICEWORKERMANAGER_CID);
 NS_DEFINE_NAMED_CID(NOTIFICATIONTELEMETRYSERVICE_CID);
 NS_DEFINE_NAMED_CID(PUSHNOTIFIER_CID);
 
 NS_DEFINE_NAMED_CID(WORKERDEBUGGERMANAGER_CID);
 #ifdef MOZ_WIDGET_GONK
 NS_DEFINE_NAMED_CID(SYSTEMWORKERMANAGER_CID);
 #endif
-#ifdef MOZ_B2G_BT
-NS_DEFINE_NAMED_CID(BLUETOOTHSERVICE_CID);
-#endif
 #ifdef MOZ_WIDGET_GONK
 NS_DEFINE_NAMED_CID(NS_AUDIOMANAGER_CID);
 NS_DEFINE_NAMED_CID(NS_VOLUMESERVICE_CID);
 #endif
 
 NS_DEFINE_NAMED_CID(NS_AUDIOCHANNELAGENT_CID);
 
 NS_DEFINE_NAMED_CID(NS_HTMLEDITOR_CID);
@@ -1029,19 +1013,16 @@ static const mozilla::Module::CIDEntry k
   { &kQUOTAMANAGER_SERVICE_CID, false, nullptr, QuotaManagerServiceConstructor },
   { &kSERVICEWORKERMANAGER_CID, false, nullptr, ServiceWorkerManagerConstructor },
   { &kNOTIFICATIONTELEMETRYSERVICE_CID, false, nullptr, NotificationTelemetryServiceConstructor },
   { &kPUSHNOTIFIER_CID, false, nullptr, PushNotifierConstructor },
   { &kWORKERDEBUGGERMANAGER_CID, true, nullptr, WorkerDebuggerManagerConstructor },
 #ifdef MOZ_WIDGET_GONK
   { &kSYSTEMWORKERMANAGER_CID, true, nullptr, SystemWorkerManagerConstructor },
 #endif
-#ifdef MOZ_B2G_BT
-  { &kBLUETOOTHSERVICE_CID, true, nullptr, BluetoothServiceConstructor },
-#endif
 #ifdef MOZ_WIDGET_GONK
   { &kNS_AUDIOMANAGER_CID, true, nullptr, AudioManagerConstructor },
   { &kNS_VOLUMESERVICE_CID, true, nullptr, nsVolumeServiceConstructor },
 #endif
   { &kNS_AUDIOCHANNELAGENT_CID, true, nullptr, AudioChannelAgentConstructor },
   { &kNS_HTMLEDITOR_CID, false, nullptr, HTMLEditorConstructor },
   { &kNS_EDITORCONTROLLER_CID, false, nullptr, EditorControllerConstructor },
   { &kNS_EDITINGCONTROLLER_CID, false, nullptr, nsEditingControllerConstructor },
@@ -1183,19 +1164,16 @@ static const mozilla::Module::ContractID
   { QUOTAMANAGER_SERVICE_CONTRACTID, &kQUOTAMANAGER_SERVICE_CID },
   { SERVICEWORKERMANAGER_CONTRACTID, &kSERVICEWORKERMANAGER_CID },
   { NOTIFICATIONTELEMETRYSERVICE_CONTRACTID, &kNOTIFICATIONTELEMETRYSERVICE_CID },
   { PUSHNOTIFIER_CONTRACTID, &kPUSHNOTIFIER_CID },
   { WORKERDEBUGGERMANAGER_CONTRACTID, &kWORKERDEBUGGERMANAGER_CID },
 #ifdef MOZ_WIDGET_GONK
   { SYSTEMWORKERMANAGER_CONTRACTID, &kSYSTEMWORKERMANAGER_CID },
 #endif
-#ifdef MOZ_B2G_BT
-  { BLUETOOTHSERVICE_CONTRACTID, &kBLUETOOTHSERVICE_CID },
-#endif
 #ifdef MOZ_WIDGET_GONK
   { NS_AUDIOMANAGER_CONTRACTID, &kNS_AUDIOMANAGER_CID },
   { NS_VOLUMESERVICE_CONTRACTID, &kNS_VOLUMESERVICE_CID },
 #endif
   { NS_AUDIOCHANNELAGENT_CONTRACTID, &kNS_AUDIOCHANNELAGENT_CID },
   { "@mozilla.org/editor/htmleditor;1", &kNS_HTMLEDITOR_CID },
   { "@mozilla.org/editor/editorcontroller;1", &kNS_EDITORCONTROLLER_CID },
   { "@mozilla.org/editor/editingcontroller;1", &kNS_EDITINGCONTROLLER_CID },
@@ -1278,19 +1256,16 @@ static const mozilla::Module::CategoryEn
   { OBSERVER_TOPIC_IDLE_DAILY, "QuotaManagerService", QUOTAMANAGER_SERVICE_CONTRACTID },
 #ifdef MOZ_WIDGET_GONK
   { "app-startup", "Volume Service", "service," NS_VOLUMESERVICE_CONTRACTID },
 #endif
   CONTENTDLF_CATEGORIES
 #ifdef MOZ_WIDGET_GONK
   { "profile-after-change", "Gonk System Worker Manager", SYSTEMWORKERMANAGER_CONTRACTID },
 #endif
-#ifdef MOZ_B2G_BT
-  { "profile-after-change", "Bluetooth Service", BLUETOOTHSERVICE_CONTRACTID },
-#endif
   { "profile-after-change", "PresentationDeviceManager", PRESENTATION_DEVICE_MANAGER_CONTRACTID },
   { "profile-after-change", "PresentationService", PRESENTATION_SERVICE_CONTRACTID },
   { "profile-after-change", "Notification Telemetry Service", NOTIFICATIONTELEMETRYSERVICE_CONTRACTID },
   { nullptr }
 };
 
 static void
 LayoutModuleDtor()
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -125,20 +125,16 @@ using namespace mozilla::system;
 #include "TouchManager.h"
 #include "MediaDecoder.h"
 #include "MediaPrefs.h"
 #include "mozilla/dom/devicestorage/DeviceStorageStatics.h"
 #include "mozilla/ServoBindings.h"
 #include "mozilla/StaticPresData.h"
 #include "mozilla/dom/WebIDLGlobalNameHash.h"
 
-#ifdef MOZ_B2G_BT
-#include "mozilla/dom/BluetoothUUID.h"
-#endif
-
 using namespace mozilla;
 using namespace mozilla::net;
 using namespace mozilla::dom;
 using namespace mozilla::dom::ipc;
 
 nsrefcnt nsLayoutStatics::sLayoutStaticRefcnt = 0;
 
 nsresult
@@ -435,13 +431,9 @@ nsLayoutStatics::Shutdown()
 
   DisplayItemClip::Shutdown();
 
   CustomElementRegistry::XPCOMShutdown();
 
   CacheObserver::Shutdown();
 
   PromiseDebugging::Shutdown();
-
-#ifdef MOZ_B2G_BT
-  BluetoothUUID::HandleShutdown();
-#endif
 }
--- a/old-configure.in
+++ b/old-configure.in
@@ -99,17 +99,17 @@ if test -n "$gonkdir"; then
     dnl because it's a `--enable-project=b2g`-only option.
     export gonkdir
     kernel_name=`uname -s | tr "[[:upper:]]" "[[:lower:]]"`
     android_source="$gonkdir"
     ANDROID_SOURCE="$android_source"
 
     case "$android_version" in
     15)
-        CPPFLAGS="-I$gonkdir/frameworks/base/opengl/include -I$gonkdir/frameworks/base/native/include -I$gonkdir/frameworks/base/include -I$gonkdir/frameworks/base/services/camera -I$gonkdir/frameworks/base/include/media/ -I$gonkdir/frameworks/base/include/media/stagefright -I$gonkdir/frameworks/base/include/media/stagefright/openmax -I$gonkdir/frameworks/base/media/libstagefright/rtsp -I$gonkdir/frameworks/base/media/libstagefright/include -I$gonkdir/external/dbus -I$gonkdir/external/bluetooth/bluez/lib -I$gonkdir/dalvik/libnativehelper/include/nativehelper $CPPFLAGS"
+        CPPFLAGS="-I$gonkdir/frameworks/base/opengl/include -I$gonkdir/frameworks/base/native/include -I$gonkdir/frameworks/base/include -I$gonkdir/frameworks/base/services/camera -I$gonkdir/frameworks/base/include/media/ -I$gonkdir/frameworks/base/include/media/stagefright -I$gonkdir/frameworks/base/include/media/stagefright/openmax -I$gonkdir/frameworks/base/media/libstagefright/rtsp -I$gonkdir/frameworks/base/media/libstagefright/include -I$gonkdir/external/dbus -I$gonkdir/dalvik/libnativehelper/include/nativehelper $CPPFLAGS"
         MOZ_SECUREELEMENT=1
         ;;
     17|18)
         CPPFLAGS="-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 $CPPFLAGS"
         MOZ_SECUREELEMENT=1
         ;;
     19)
         CPPFLAGS="-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 $CPPFLAGS"
@@ -124,26 +124,16 @@ if test -n "$gonkdir"; then
         AC_SUBST(MOZ_AUDIO_OFFLOAD)
         AC_DEFINE(MOZ_AUDIO_OFFLOAD)
         ;;
     *)
         AC_MSG_ERROR([Unsupported platform version: $android_version])
         ;;
     esac
 
-    dnl Enable Bluetooth backends depending on available drivers
-    if test -d "$gonkdir/system/bluetoothd"; then
-        MOZ_B2G_BT=1
-        MOZ_B2G_BT_DAEMON=1
-    fi
-    if test -d "$gonkdir/external/bluetooth/bluez"; then
-        MOZ_B2G_BT=1
-        MOZ_B2G_BT_BLUEZ=1
-    fi
-
     CPPFLAGS="-I$gonkdir/system -I$gonkdir/system/core/include -I$gonkdir/hardware/libhardware/include -I$gonkdir/external/valgrind/fxos-include $CPPFLAGS"
     LDFLAGS="-L$gonkdir/out/target/product/$GONK_PRODUCT/obj/lib -Wl,-rpath-link=$gonkdir/out/target/product/$GONK_PRODUCT/obj/lib $LDFLAGS"
 
     AC_DEFINE(ANDROID)
     AC_DEFINE_UNQUOTED(ANDROID_VERSION, $android_version)
     AC_DEFINE(HAVE_SYS_UIO_H)
     AC_DEFINE(HAVE_PTHREADS)
 
@@ -4736,30 +4726,16 @@ if test -n "$MOZ_B2G_RIL"; then
         AC_DEFINE(MOZ_B2G_RIL)
     else
         AC_MSG_ERROR([b2g-ril cannot be enabled because target platform doesn't support it.])
     fi
 fi
 AC_SUBST(MOZ_B2G_RIL)
 
 dnl ========================================================
-dnl = Enable Bluetooth Interface for B2G (Gonk usually)
-dnl ========================================================
-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_DAEMON)
-
-dnl ========================================================
 dnl = Enable Pico Speech Synthesis (Gonk usually)
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(synth-pico,
 [  --enable-synth-pico  Set compile flags necessary for compiling Pico Web Speech API ],
     MOZ_SYNTH_PICO=1,
     MOZ_SYNTH_PICO= )
 if test -n "$MOZ_SYNTH_PICO"; then
     AC_DEFINE(MOZ_SYNTH_PICO)
--- a/testing/marionette/harness/marionette/tests/webapi-tests.ini
+++ b/testing/marionette/harness/marionette/tests/webapi-tests.ini
@@ -1,9 +1,8 @@
-[include:../../../../../dom/bluetooth/tests/marionette/manifest.ini]
 [include:../../../../../dom/mobileconnection/tests/marionette/manifest.ini]
 [include:../../../../../dom/system/gonk/tests/marionette/manifest.ini]
 [include:../../../../../dom/icc/tests/marionette/manifest.ini]
 [include:../../../../../dom/system/tests/marionette/manifest.ini]
 skip-if = android_version > '15' # Bug 1203072
 [include:../../../../../dom/events/test/marionette/manifest.ini]
 [include:../../../../../dom/wifi/test/marionette/manifest.ini]
 [include:../../../../../dom/tethering/tests/marionette/manifest.ini]
--- a/toolkit/library/moz.build
+++ b/toolkit/library/moz.build
@@ -196,17 +196,17 @@ if CONFIG['OS_ARCH'] == 'WINNT':
     OS_LIBS += [
         'crypt32',
         'shell32',
         'ole32',
         'version',
         'winspool',
     ]
 
-if CONFIG['MOZ_B2G_BT_BLUEZ'] and CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     OS_LIBS += [
         'dbus',
     ]
 
 if CONFIG['OS_ARCH'] == 'Linux' and CONFIG['OS_TARGET'] != 'Android':
     OS_LIBS += [
         'rt',
     ]
--- a/xpcom/base/ErrorList.h
+++ b/xpcom/base/ErrorList.h
@@ -932,33 +932,16 @@
   ERROR(NS_ERROR_DOM_FILESYSTEM_INVALID_MODIFICATION_ERR,  FAILURE(2)),
   ERROR(NS_ERROR_DOM_FILESYSTEM_NO_MODIFICATION_ALLOWED_ERR, FAILURE(3)),
   ERROR(NS_ERROR_DOM_FILESYSTEM_PATH_EXISTS_ERR,           FAILURE(4)),
   ERROR(NS_ERROR_DOM_FILESYSTEM_TYPE_MISMATCH_ERR,         FAILURE(5)),
   ERROR(NS_ERROR_DOM_FILESYSTEM_UNKNOWN_ERR,               FAILURE(6)),
 #undef MODULE
 
   /* ======================================================================= */
-  /* 37: NS_ERROR_MODULE_DOM_BLUETOOTH */
-  /* ======================================================================= */
-#define MODULE NS_ERROR_MODULE_DOM_BLUETOOTH
-  ERROR(NS_ERROR_DOM_BLUETOOTH_FAIL,                      FAILURE(1)),
-  ERROR(NS_ERROR_DOM_BLUETOOTH_NOT_READY,                 FAILURE(2)),
-  ERROR(NS_ERROR_DOM_BLUETOOTH_NOMEM,                     FAILURE(3)),
-  ERROR(NS_ERROR_DOM_BLUETOOTH_BUSY,                      FAILURE(4)),
-  ERROR(NS_ERROR_DOM_BLUETOOTH_DONE,                      FAILURE(5)),
-  ERROR(NS_ERROR_DOM_BLUETOOTH_UNSUPPORTED,               FAILURE(6)),
-  ERROR(NS_ERROR_DOM_BLUETOOTH_PARM_INVALID,              FAILURE(7)),
-  ERROR(NS_ERROR_DOM_BLUETOOTH_UNHANDLED,                 FAILURE(8)),
-  ERROR(NS_ERROR_DOM_BLUETOOTH_AUTH_FAILURE,              FAILURE(9)),
-  ERROR(NS_ERROR_DOM_BLUETOOTH_RMT_DEV_DOWN,              FAILURE(10)),
-  ERROR(NS_ERROR_DOM_BLUETOOTH_AUTH_REJECTED,             FAILURE(11)),
-#undef MODULE
-
-  /* ======================================================================= */
   /* 38: NS_ERROR_MODULE_SIGNED_APP */
   /* ======================================================================= */
 #define MODULE NS_ERROR_MODULE_SIGNED_APP
   ERROR(NS_ERROR_SIGNED_APP_MANIFEST_INVALID,   FAILURE(1)),
 #undef MODULE
 
   /* ======================================================================= */
   /* 39: NS_ERROR_MODULE_DOM_ANIM */