Merge b2g-inbound to m-c. a=merge
authorRyan VanderMeulen <ryanvm@gmail.com>
Tue, 16 Jun 2015 14:34:48 -0400
changeset 279871 02f2b34ed5e40c7888eb5a0c207bc885f0aa1000
parent 279844 69dab4252c6a77f9b5bdd83bc2fe4a7204761a0e (current diff)
parent 279870 4fc861a7087f9802cb90c6d33ec0105299394328 (diff)
child 279909 27caa5299f9f1bacf8a92b898837edf360b3b212
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge b2g-inbound to m-c. a=merge
--- a/b2g/config/aries/sources.xml
+++ b/b2g/config/aries/sources.xml
@@ -10,17 +10,17 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="e862ab9177af664f00b4522e2350f4cb13866d73">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
--- a/b2g/config/dolphin/sources.xml
+++ b/b2g/config/dolphin/sources.xml
@@ -10,17 +10,17 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="e862ab9177af664f00b4522e2350f4cb13866d73">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
--- a/b2g/config/emulator-ics/sources.xml
+++ b/b2g/config/emulator-ics/sources.xml
@@ -14,17 +14,17 @@
   <!--original fetch url was git://github.com/apitrace/-->
   <remote fetch="https://git.mozilla.org/external/apitrace" name="apitrace"/>
   <default remote="caf" revision="refs/tags/android-4.0.4_r2.1" sync-j="4"/>
   <!-- Gonk specific things and forks -->
   <project name="platform_build" path="build" remote="b2g" revision="173b3104bfcbd23fc9dccd4b0035fc49aae3d444">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
   <project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
-  <project name="gaia.git" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia.git" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="platform_hardware_ril" path="hardware/ril" remote="b2g" revision="87a2d8ab9248540910e56921654367b78a587095"/>
   <project name="platform_external_qemu" path="external/qemu" remote="b2g" revision="9d0e5057ee5404a31ec1bf76131cb11336a7c3b6"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="34ea6163f9f0e0122fb0bb03607eccdca31ced7a"/>
   <!-- Stock Android things -->
   <project name="platform/abi/cpp" path="abi/cpp" revision="dd924f92906085b831bf1cbbc7484d3c043d613c"/>
--- a/b2g/config/emulator-jb/sources.xml
+++ b/b2g/config/emulator-jb/sources.xml
@@ -12,17 +12,17 @@
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="4efd19d199ae52656604f794c5a77518400220fd">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <!-- Stock Android things -->
   <project groups="linux" name="platform/prebuilts/clang/linux-x86/3.1" path="prebuilts/clang/linux-x86/3.1" revision="5c45f43419d5582949284eee9cef0c43d866e03b"/>
   <project groups="linux" name="platform/prebuilts/clang/linux-x86/3.2" path="prebuilts/clang/linux-x86/3.2" revision="3748b4168e7bd8d46457d4b6786003bc6a5223ce"/>
--- a/b2g/config/emulator-kk/sources.xml
+++ b/b2g/config/emulator-kk/sources.xml
@@ -10,17 +10,17 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="e862ab9177af664f00b4522e2350f4cb13866d73">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
--- a/b2g/config/emulator-l/sources.xml
+++ b/b2g/config/emulator-l/sources.xml
@@ -10,17 +10,17 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="61e82f99bb8bc78d52b5717e9a2481ec7267fa33">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
--- a/b2g/config/emulator/sources.xml
+++ b/b2g/config/emulator/sources.xml
@@ -14,17 +14,17 @@
   <!--original fetch url was git://github.com/apitrace/-->
   <remote fetch="https://git.mozilla.org/external/apitrace" name="apitrace"/>
   <default remote="caf" revision="refs/tags/android-4.0.4_r2.1" sync-j="4"/>
   <!-- Gonk specific things and forks -->
   <project name="platform_build" path="build" remote="b2g" revision="173b3104bfcbd23fc9dccd4b0035fc49aae3d444">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
   <project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
-  <project name="gaia.git" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia.git" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="platform_hardware_ril" path="hardware/ril" remote="b2g" revision="87a2d8ab9248540910e56921654367b78a587095"/>
   <project name="platform_external_qemu" path="external/qemu" remote="b2g" revision="9d0e5057ee5404a31ec1bf76131cb11336a7c3b6"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="34ea6163f9f0e0122fb0bb03607eccdca31ced7a"/>
   <!-- Stock Android things -->
   <project name="platform/abi/cpp" path="abi/cpp" revision="dd924f92906085b831bf1cbbc7484d3c043d613c"/>
--- a/b2g/config/flame-kk/sources.xml
+++ b/b2g/config/flame-kk/sources.xml
@@ -10,17 +10,17 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="e862ab9177af664f00b4522e2350f4cb13866d73">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
--- a/b2g/config/gaia.json
+++ b/b2g/config/gaia.json
@@ -1,9 +1,9 @@
 {
     "git": {
-        "git_revision": "c92e9d14022f0191f8ccdaadf1752352cde97be0", 
+        "git_revision": "9d42e94446f2dc01b519172b6d75d81d4d435bdc", 
         "remote": "https://git.mozilla.org/releases/gaia.git", 
         "branch": ""
     }, 
-    "revision": "d9efff50aff6c261c55cfdff66e4fedd81250e0b", 
+    "revision": "1518b9e2a13a377444083e4bb970bd701e2633c9", 
     "repo_path": "integration/gaia-central"
 }
--- a/b2g/config/nexus-4/sources.xml
+++ b/b2g/config/nexus-4/sources.xml
@@ -12,17 +12,17 @@
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="4efd19d199ae52656604f794c5a77518400220fd">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <!-- Stock Android things -->
   <project groups="linux" name="platform/prebuilts/clang/linux-x86/3.1" path="prebuilts/clang/linux-x86/3.1" revision="5c45f43419d5582949284eee9cef0c43d866e03b"/>
   <project groups="linux" name="platform/prebuilts/clang/linux-x86/3.2" path="prebuilts/clang/linux-x86/3.2" revision="3748b4168e7bd8d46457d4b6786003bc6a5223ce"/>
--- a/b2g/config/nexus-5-l/sources.xml
+++ b/b2g/config/nexus-5-l/sources.xml
@@ -10,17 +10,17 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="61e82f99bb8bc78d52b5717e9a2481ec7267fa33">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
@@ -59,61 +59,90 @@
     if (!sBtInterface || !IsEnabled()) {                               \
       DispatchReplyError(runnable,                                     \
         NS_LITERAL_STRING("Bluetooth is not ready"));                  \
       return;                                                          \
     }                                                                  \
   } while(0)
 
 #ifndef MOZ_B2G_BT_API_V1
-
 #define ENSURE_GATT_MGR_IS_READY_VOID(gatt, runnable)                  \
   do {                                                                 \
     if (!gatt) {                                                       \
       DispatchReplyError(runnable,                                     \
         NS_LITERAL_STRING("GattManager is not ready"));                \
       return;                                                          \
     }                                                                  \
   } while(0)
+#else
+  // Missing in Bluetooth v1
+#endif
+
+#ifndef MOZ_B2G_BT_API_V1
+// Missing in Bluetooth v2
+#else
+// Audio: Major service class = 0x100 (Bit 21 is set)
+#define SET_AUDIO_BIT(cod)               (cod |= 0x200000)
+// Rendering: Major service class = 0x20 (Bit 18 is set)
+#define SET_RENDERING_BIT(cod)           (cod |= 0x40000)
+#endif
 
 using namespace mozilla;
 using namespace mozilla::ipc;
 USING_BLUETOOTH_NAMESPACE
 
 static nsString sAdapterBdAddress;
 static nsString sAdapterBdName;
+
 static bool sAdapterDiscoverable(false);
 static bool sAdapterDiscovering(false);
-static bool sAdapterEnabled(false);
+
 // InfallibleTArray is an alias for nsTArray.
 static InfallibleTArray<nsString> sAdapterBondedAddressArray;
 
+static BluetoothInterface* sBtInterface;
+
+static nsTArray<nsRefPtr<BluetoothProfileController> > sControllerArray;
+static InfallibleTArray<BluetoothNamedValue> sRemoteDevicesPack;
+static nsTArray<int> sRequestedDeviceCountArray;
+
+static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sSetPropertyRunnableArray;
+static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sGetDeviceRunnableArray;
+
+static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sBondingRunnableArray;
+static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sUnbondingRunnableArray;
+static bool sIsRestart(false);
+static bool sIsFirstTimeToggleOffBt(false);
+
+#ifndef MOZ_B2G_BT_API_V1
+static bool sAdapterEnabled(false);
+
 // Use a static hash table to keep the name of remote device during the pairing
 // procedure. In this manner, BT service and adapter can get the name of paired
 // device name when bond state changed.
 // The hash Key is BD address, the Value is remote BD name.
 static nsDataHashtable<nsStringHashKey, nsString> sPairingNameTable;
 
-static BluetoothInterface* sBtInterface;
-static nsTArray<nsRefPtr<BluetoothProfileController> > sControllerArray;
-static InfallibleTArray<BluetoothNamedValue> sRemoteDevicesPack;
-static nsTArray<int> sRequestedDeviceCountArray;
 static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sChangeAdapterStateRunnableArray;
 static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sChangeDiscoveryRunnableArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sSetPropertyRunnableArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sGetDeviceRunnableArray;
 static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sFetchUuidsRunnableArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sBondingRunnableArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sUnbondingRunnableArray;
-static bool sIsRestart(false);
-static bool sIsFirstTimeToggleOffBt(false);
-
-/**
- *  Static callback functions
+#else
+// Missing in Bluetooth v1
+#endif
+
+#ifndef MOZ_B2G_BT_API_V1
+// Missing in Bluetooth v2
+#else
+static uint32_t sAdapterDiscoverableTimeout(0);
+#endif
+
+/*
+ *  Static methods
  */
+
 ControlPlayStatus
 BluetoothServiceBluedroid::PlayStatusStringToControlPlayStatus(
   const nsAString& aPlayStatus)
 {
   ControlPlayStatus playStatus = ControlPlayStatus::PLAYSTATUS_UNKNOWN;
   if (aPlayStatus.EqualsLiteral("STOPPED")) {
     playStatus = ControlPlayStatus::PLAYSTATUS_STOPPED;
   } else if (aPlayStatus.EqualsLiteral("PLAYING")) {
@@ -126,19 +155,139 @@ BluetoothServiceBluedroid::PlayStatusStr
     playStatus = ControlPlayStatus::PLAYSTATUS_REV_SEEK;
   } else if (aPlayStatus.EqualsLiteral("ERROR")) {
     playStatus = ControlPlayStatus::PLAYSTATUS_ERROR;
   }
 
   return playStatus;
 }
 
-/**
- *  Static functions
- */
+#ifndef MOZ_B2G_BT_API_V1
+// Missing in Bluetooth v2
+#else
+void
+BluetoothServiceBluedroid::ClassToIcon(uint32_t aClass, nsAString& aRetIcon)
+{
+  switch ((aClass & 0x1f00) >> 8) {
+    case 0x01:
+      aRetIcon.AssignLiteral("computer");
+      break;
+    case 0x02:
+      switch ((aClass & 0xfc) >> 2) {
+        case 0x01:
+        case 0x02:
+        case 0x03:
+        case 0x05:
+          aRetIcon.AssignLiteral("phone");
+          break;
+        case 0x04:
+          aRetIcon.AssignLiteral("modem");
+          break;
+      }
+      break;
+    case 0x03:
+      aRetIcon.AssignLiteral("network-wireless");
+      break;
+    case 0x04:
+      switch ((aClass & 0xfc) >> 2) {
+        case 0x01:
+        case 0x02:
+        case 0x06:
+          aRetIcon.AssignLiteral("audio-card");
+          break;
+        case 0x0b:
+        case 0x0c:
+        case 0x0d:
+          aRetIcon.AssignLiteral("camera-video");
+          break;
+        default:
+          aRetIcon.AssignLiteral("audio-card");
+          break;
+      }
+      break;
+    case 0x05:
+      switch ((aClass & 0xc0) >> 6) {
+        case 0x00:
+          switch ((aClass && 0x1e) >> 2) {
+            case 0x01:
+            case 0x02:
+              aRetIcon.AssignLiteral("input-gaming");
+              break;
+          }
+          break;
+        case 0x01:
+          aRetIcon.AssignLiteral("input-keyboard");
+          break;
+        case 0x02:
+          switch ((aClass && 0x1e) >> 2) {
+            case 0x05:
+              aRetIcon.AssignLiteral("input-tablet");
+              break;
+            default:
+              aRetIcon.AssignLiteral("input-mouse");
+              break;
+          }
+      }
+      break;
+    case 0x06:
+      if (aClass & 0x80) {
+        aRetIcon.AssignLiteral("printer");
+        break;
+      }
+      if (aClass & 0x20) {
+        aRetIcon.AssignLiteral("camera-photo");
+        break;
+      }
+      break;
+  }
+
+  if (aRetIcon.IsEmpty()) {
+    if (HAS_AUDIO(aClass)) {
+      /**
+       * Property 'Icon' may be missed due to CoD of major class is TOY(0x08).
+       * But we need to assign Icon as audio-card if service class is 'Audio'.
+       * This is for PTS test case TC_AG_COD_BV_02_I. As HFP specification
+       * defines that service class is 'Audio' can be considered as HFP HF.
+       */
+      aRetIcon.AssignLiteral("audio-card");
+    } else {
+      BT_LOGR("No icon to match class: %x", aClass);
+    }
+  }
+}
+
+static void
+ReplyStatusError(BluetoothReplyRunnable* aBluetoothReplyRunnable,
+                 BluetoothStatus aStatusCode, const nsAString& aCustomMsg)
+{
+  MOZ_ASSERT(aBluetoothReplyRunnable, "Reply runnable is nullptr");
+
+  BT_LOGR("error code(%d)", aStatusCode);
+
+  nsAutoString replyError;
+  replyError.Assign(aCustomMsg);
+
+  if (aStatusCode == STATUS_BUSY) {
+    replyError.AppendLiteral(":BT_STATUS_BUSY");
+  } else if (aStatusCode == STATUS_NOT_READY) {
+    replyError.AppendLiteral(":BT_STATUS_NOT_READY");
+  } else if (aStatusCode == STATUS_DONE) {
+    replyError.AppendLiteral(":BT_STATUS_DONE");
+  } else if (aStatusCode == STATUS_AUTH_FAILURE) {
+    replyError.AppendLiteral(":BT_STATUS_AUTH_FAILURE");
+  } else if (aStatusCode == STATUS_RMT_DEV_DOWN) {
+    replyError.AppendLiteral(":BT_STATUS_RMT_DEV_DOWN");
+  } else if (aStatusCode == STATUS_FAIL) {
+    replyError.AppendLiteral(":BT_STATUS_FAIL");
+  }
+
+  DispatchReplyError(aBluetoothReplyRunnable, replyError);
+}
+#endif
+
 class BluetoothServiceBluedroid::EnableResultHandler final
   : public BluetoothResultHandler
 {
 public:
   void OnError(BluetoothStatus aStatus) override
   {
     MOZ_ASSERT(NS_IsMainThread());
 
@@ -189,17 +338,21 @@ class BluetoothServiceBluedroid::InitRes
   : public BluetoothResultHandler
 {
 public:
   void Init() override
   {
     static void (* const sInitManager[])(BluetoothProfileResultHandler*) = {
       BluetoothHfpManager::InitHfpInterface,
       BluetoothA2dpManager::InitA2dpInterface,
+#ifndef MOZ_B2G_BT_API_V1
       BluetoothGattManager::InitGattInterface
+#else
+      // Missing in Bluetooth v1
+#endif
     };
 
     MOZ_ASSERT(NS_IsMainThread());
 
     // Register all the bluedroid callbacks before enable() get called
     // It is required to register a2dp callbacks before a2dp media task starts up.
     // If any interface cannot be initialized, turn on bluetooth core anyway.
     nsRefPtr<ProfileInitResultHandler> res =
@@ -249,17 +402,22 @@ class BluetoothServiceBluedroid::Disable
 {
 public:
   void OnError(BluetoothStatus aStatus) override
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     BT_LOGR("BluetoothInterface::Disable failed: %d", aStatus);
 
+#ifndef MOZ_B2G_BT_API_V1
     BluetoothService::AcknowledgeToggleBt(true);
+#else
+    // Always make progress; even on failures
+    BluetoothService::AcknowledgeToggleBt(false);
+#endif
   }
 };
 
 nsresult
 BluetoothServiceBluedroid::StopGonkBluetooth()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
@@ -274,47 +432,49 @@ BluetoothServiceBluedroid::StopGonkBluet
     return NS_OK;
   }
 
   sBtInterface->Disable(new DisableResultHandler());
 
   return NS_OK;
 }
 
-/**
+/*
  *  Member functions
  */
+
 BluetoothServiceBluedroid::BluetoothServiceBluedroid()
 {
   sBtInterface = BluetoothInterface::GetInstance();
   if (!sBtInterface) {
     BT_LOGR("Error! Failed to get instance of bluetooth interface");
   }
 }
 
 BluetoothServiceBluedroid::~BluetoothServiceBluedroid()
 {
 }
 
+#ifndef MOZ_B2G_BT_API_V1
 nsresult
 BluetoothServiceBluedroid::StartInternal(BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // aRunnable will be a nullptr while startup
-  if(aRunnable) {
+  if (aRunnable) {
     sChangeAdapterStateRunnableArray.AppendElement(aRunnable);
   }
 
   nsresult ret = StartGonkBluetooth();
   if (NS_FAILED(ret)) {
     BluetoothService::AcknowledgeToggleBt(false);
 
     // Reject Promise
-    if(aRunnable) {
+    if (aRunnable) {
       DispatchReplyError(aRunnable, NS_LITERAL_STRING("StartBluetoothError"));
       sChangeAdapterStateRunnableArray.RemoveElement(aRunnable);
     }
 
     BT_LOGR("Error");
   }
 
   return ret;
@@ -347,40 +507,70 @@ BluetoothServiceBluedroid::StopInternal(
       sProfiles[i]->Disconnect(nullptr);
     } else if (!profileName.EqualsLiteral("OPP") &&
                !profileName.EqualsLiteral("PBAP")) {
       sProfiles[i]->Reset();
     }
   }
 
   // aRunnable will be a nullptr during starup and shutdown
-  if(aRunnable) {
+  if (aRunnable) {
     sChangeAdapterStateRunnableArray.AppendElement(aRunnable);
   }
 
   nsresult ret = StopGonkBluetooth();
   if (NS_FAILED(ret)) {
     BluetoothService::AcknowledgeToggleBt(true);
 
     // Reject Promise
-    if(aRunnable) {
+    if (aRunnable) {
       DispatchReplyError(aRunnable, NS_LITERAL_STRING("StopBluetoothError"));
       sChangeAdapterStateRunnableArray.RemoveElement(aRunnable);
     }
 
     BT_LOGR("Error");
   }
 
   return ret;
 }
+#else
+nsresult
+BluetoothServiceBluedroid::StartInternal()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  nsresult ret = StartGonkBluetooth();
+  if (NS_FAILED(ret)) {
+    BluetoothService::AcknowledgeToggleBt(false);
+    BT_LOGR("Error");
+  }
+
+  return ret;
+}
+
+nsresult
+BluetoothServiceBluedroid::StopInternal()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  nsresult ret = StopGonkBluetooth();
+  if (NS_FAILED(ret)) {
+    BluetoothService::AcknowledgeToggleBt(true);
+    BT_LOGR("Error");
+  }
+
+  return ret;
+}
+#endif
 
 //
 // GATT Client
 //
 
+#ifndef MOZ_B2G_BT_API_V1
 void
 BluetoothServiceBluedroid::StartLeScanInternal(
   const nsTArray<nsString>& aServiceUuids,
   BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
   ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
 
@@ -579,377 +769,17 @@ BluetoothServiceBluedroid::GattClientWri
 
   BluetoothGattManager* gatt = BluetoothGattManager::Get();
   ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
 
   gatt->WriteDescriptorValue(aAppUuid, aServiceId, aCharacteristicId,
                              aDescriptorId, aValue, aRunnable);
 }
 #else
-
-// Audio: Major service class = 0x100 (Bit 21 is set)
-#define SET_AUDIO_BIT(cod)               (cod |= 0x200000)
-// Rendering: Major service class = 0x20 (Bit 18 is set)
-#define SET_RENDERING_BIT(cod)           (cod |= 0x40000)
-
-using namespace mozilla;
-using namespace mozilla::ipc;
-USING_BLUETOOTH_NAMESPACE
-
-static nsString sAdapterBdAddress;
-static nsString sAdapterBdName;
-static InfallibleTArray<nsString> sAdapterBondedAddressArray;
-static BluetoothInterface* sBtInterface;
-static nsTArray<nsRefPtr<BluetoothProfileController> > sControllerArray;
-static InfallibleTArray<BluetoothNamedValue> sRemoteDevicesPack;
-static nsTArray<int> sRequestedDeviceCountArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sSetPropertyRunnableArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sGetDeviceRunnableArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sBondingRunnableArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sUnbondingRunnableArray;
-static bool sAdapterDiscoverable(false);
-static bool sAdapterDiscovering(false);
-static bool sIsRestart(false);
-static bool sIsFirstTimeToggleOffBt(false);
-static uint32_t sAdapterDiscoverableTimeout(0);
-
-/**
- *  Static callback functions
- */
-void
-BluetoothServiceBluedroid::ClassToIcon(uint32_t aClass, nsAString& aRetIcon)
-{
-  switch ((aClass & 0x1f00) >> 8) {
-    case 0x01:
-      aRetIcon.AssignLiteral("computer");
-      break;
-    case 0x02:
-      switch ((aClass & 0xfc) >> 2) {
-        case 0x01:
-        case 0x02:
-        case 0x03:
-        case 0x05:
-          aRetIcon.AssignLiteral("phone");
-          break;
-        case 0x04:
-          aRetIcon.AssignLiteral("modem");
-          break;
-      }
-      break;
-    case 0x03:
-      aRetIcon.AssignLiteral("network-wireless");
-      break;
-    case 0x04:
-      switch ((aClass & 0xfc) >> 2) {
-        case 0x01:
-        case 0x02:
-        case 0x06:
-          aRetIcon.AssignLiteral("audio-card");
-          break;
-        case 0x0b:
-        case 0x0c:
-        case 0x0d:
-          aRetIcon.AssignLiteral("camera-video");
-          break;
-        default:
-          aRetIcon.AssignLiteral("audio-card");
-          break;
-      }
-      break;
-    case 0x05:
-      switch ((aClass & 0xc0) >> 6) {
-        case 0x00:
-          switch ((aClass && 0x1e) >> 2) {
-            case 0x01:
-            case 0x02:
-              aRetIcon.AssignLiteral("input-gaming");
-              break;
-          }
-          break;
-        case 0x01:
-          aRetIcon.AssignLiteral("input-keyboard");
-          break;
-        case 0x02:
-          switch ((aClass && 0x1e) >> 2) {
-            case 0x05:
-              aRetIcon.AssignLiteral("input-tablet");
-              break;
-            default:
-              aRetIcon.AssignLiteral("input-mouse");
-              break;
-          }
-      }
-      break;
-    case 0x06:
-      if (aClass & 0x80) {
-        aRetIcon.AssignLiteral("printer");
-        break;
-      }
-      if (aClass & 0x20) {
-        aRetIcon.AssignLiteral("camera-photo");
-        break;
-      }
-      break;
-  }
-
-  if (aRetIcon.IsEmpty()) {
-    if (HAS_AUDIO(aClass)) {
-      /**
-       * Property 'Icon' may be missed due to CoD of major class is TOY(0x08).
-       * But we need to assign Icon as audio-card if service class is 'Audio'.
-       * This is for PTS test case TC_AG_COD_BV_02_I. As HFP specification
-       * defines that service class is 'Audio' can be considered as HFP HF.
-       */
-      aRetIcon.AssignLiteral("audio-card");
-    } else {
-      BT_LOGR("No icon to match class: %x", aClass);
-    }
-  }
-}
-
-ControlPlayStatus
-BluetoothServiceBluedroid::PlayStatusStringToControlPlayStatus(
-  const nsAString& aPlayStatus)
-{
-  ControlPlayStatus playStatus = ControlPlayStatus::PLAYSTATUS_UNKNOWN;
-  if (aPlayStatus.EqualsLiteral("STOPPED")) {
-    playStatus = ControlPlayStatus::PLAYSTATUS_STOPPED;
-  } else if (aPlayStatus.EqualsLiteral("PLAYING")) {
-    playStatus = ControlPlayStatus::PLAYSTATUS_PLAYING;
-  } else if (aPlayStatus.EqualsLiteral("PAUSED")) {
-    playStatus = ControlPlayStatus::PLAYSTATUS_PAUSED;
-  } else if (aPlayStatus.EqualsLiteral("FWD_SEEK")) {
-    playStatus = ControlPlayStatus::PLAYSTATUS_FWD_SEEK;
-  } else if (aPlayStatus.EqualsLiteral("REV_SEEK")) {
-    playStatus = ControlPlayStatus::PLAYSTATUS_REV_SEEK;
-  } else if (aPlayStatus.EqualsLiteral("ERROR")) {
-    playStatus = ControlPlayStatus::PLAYSTATUS_ERROR;
-  }
-
-  return playStatus;
-}
-
-/**
- *  Static functions
- */
-class BluetoothServiceBluedroid::EnableResultHandler final
-  : public BluetoothResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_LOGR("BluetoothInterface::Enable failed: %d", aStatus);
-
-    BluetoothService::AcknowledgeToggleBt(false);
-  }
-};
-
-/* |ProfileInitResultHandler| collect 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
-  {
-    sBtInterface->Enable(new EnableResultHandler());
-  }
-
-  unsigned char mNumProfiles;
-};
-
-class BluetoothServiceBluedroid::InitResultHandler final
-  : public BluetoothResultHandler
-{
-public:
-  void Init() override
-  {
-    static void (* const sInitManager[])(BluetoothProfileResultHandler*) = {
-      BluetoothHfpManager::InitHfpInterface,
-      BluetoothA2dpManager::InitA2dpInterface
-    };
-
-    MOZ_ASSERT(NS_IsMainThread());
-
-    // Register all the bluedroid callbacks before enable() get called
-    // It is required to register a2dp callbacks before a2dp media task starts up.
-    // If any interface cannot be initialized, turn on bluetooth core anyway.
-    nsRefPtr<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 BluetoothResultHandler
-{
-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;
-  }
-
-  sBtInterface->Disable(new DisableResultHandler());
-
-  return NS_OK;
-}
-
-static void
-ReplyStatusError(BluetoothReplyRunnable* aBluetoothReplyRunnable,
-                 BluetoothStatus aStatusCode, const nsAString& aCustomMsg)
-{
-  MOZ_ASSERT(aBluetoothReplyRunnable, "Reply runnable is nullptr");
-
-  BT_LOGR("error code(%d)", aStatusCode);
-
-  nsAutoString replyError;
-  replyError.Assign(aCustomMsg);
-
-  if (aStatusCode == STATUS_BUSY) {
-    replyError.AppendLiteral(":BT_STATUS_BUSY");
-  } else if (aStatusCode == STATUS_NOT_READY) {
-    replyError.AppendLiteral(":BT_STATUS_NOT_READY");
-  } else if (aStatusCode == STATUS_DONE) {
-    replyError.AppendLiteral(":BT_STATUS_DONE");
-  } else if (aStatusCode == STATUS_AUTH_FAILURE) {
-    replyError.AppendLiteral(":BT_STATUS_AUTH_FAILURE");
-  } else if (aStatusCode == STATUS_RMT_DEV_DOWN) {
-    replyError.AppendLiteral(":BT_STATUS_RMT_DEV_DOWN");
-  } else if (aStatusCode == STATUS_FAIL) {
-    replyError.AppendLiteral(":BT_STATUS_FAIL");
-  }
-
-  DispatchReplyError(aBluetoothReplyRunnable, replyError);
-}
-
-/**
- *  Member functions
- */
-BluetoothServiceBluedroid::BluetoothServiceBluedroid()
-{
-  sBtInterface = BluetoothInterface::GetInstance();
-  if (!sBtInterface) {
-    BT_LOGR("Error! Failed to get instance of bluetooth interface");
-  }
-}
-
-BluetoothServiceBluedroid::~BluetoothServiceBluedroid()
-{
-}
-
-nsresult
-BluetoothServiceBluedroid::StartInternal()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsresult ret = StartGonkBluetooth();
-  if (NS_FAILED(ret)) {
-    BluetoothService::AcknowledgeToggleBt(false);
-    BT_LOGR("Error");
-  }
-
-  return ret;
-}
-
-nsresult
-BluetoothServiceBluedroid::StopInternal()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsresult ret = StopGonkBluetooth();
-  if (NS_FAILED(ret)) {
-    BluetoothService::AcknowledgeToggleBt(true);
-    BT_LOGR("Error");
-  }
-
-  return ret;
-}
+// Missing in Bluetooth v1
 #endif
 
 #ifndef MOZ_B2G_BT_API_V1
 nsresult
 BluetoothServiceBluedroid::GetAdaptersInternal(
   BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -1034,61 +864,48 @@ public:
   GetRemoteDevicePropertiesResultHandler(const nsAString& aDeviceAddress)
   : mDeviceAddress(aDeviceAddress)
   { }
 
   void OnError(BluetoothStatus aStatus) override
   {
     MOZ_ASSERT(NS_IsMainThread());
 
-#ifndef MOZ_B2G_BT_API_V1
     BT_WARNING("GetRemoteDeviceProperties(%s) failed: %d",
                NS_ConvertUTF16toUTF8(mDeviceAddress).get(), aStatus);
 
     /* dispatch result after final pending operation */
     if (--sRequestedDeviceCountArray[0] == 0) {
       if (!sGetDeviceRunnableArray.IsEmpty()) {
+#ifndef MOZ_B2G_BT_API_V1
         DispatchReplyError(sGetDeviceRunnableArray[0],
           NS_LITERAL_STRING("GetRemoteDeviceProperties failed"));
+#else
+        DispatchReplySuccess(sGetDeviceRunnableArray[0], sRemoteDevicesPack);
+#endif
         sGetDeviceRunnableArray.RemoveElementAt(0);
       }
 
       sRequestedDeviceCountArray.RemoveElementAt(0);
       sRemoteDevicesPack.Clear();
     }
-#else
-    BT_WARNING("GetRemoteDeviceProperties(%s) failed: %d",
-               mDeviceAddress.get(), aStatus);
-
-    /* dispatch result after final pending operation */
-    if (--sRequestedDeviceCountArray[0] == 0) {
-      if (!sGetDeviceRunnableArray.IsEmpty()) {
-        DispatchReplySuccess(sGetDeviceRunnableArray[0], sRemoteDevicesPack);
-        sGetDeviceRunnableArray.RemoveElementAt(0);
-      }
-
-      sRequestedDeviceCountArray.RemoveElementAt(0);
-      sRemoteDevicesPack.Clear();
-    }
-#endif
   }
 
 private:
   nsString mDeviceAddress;
 };
 
 nsresult
 BluetoothServiceBluedroid::GetConnectedDevicePropertiesInternal(
   uint16_t aServiceUuid, BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   ENSURE_BLUETOOTH_IS_READY(aRunnable, NS_OK);
 
-#ifndef MOZ_B2G_BT_API_V1
   BluetoothProfileManagerBase* profile =
     BluetoothUuidHelper::GetBluetoothProfileManager(aServiceUuid);
   if (!profile) {
     DispatchReplyError(aRunnable, NS_LITERAL_STRING(ERR_UNKNOWN_PROFILE));
     return NS_OK;
   }
 
   nsTArray<nsString> deviceAddresses;
@@ -1099,39 +916,16 @@ BluetoothServiceBluedroid::GetConnectedD
   }
 
   int requestedDeviceCount = deviceAddresses.Length();
   if (requestedDeviceCount == 0) {
     InfallibleTArray<BluetoothNamedValue> emptyArr;
     DispatchReplySuccess(aRunnable, emptyArr);
     return NS_OK;
   }
-#else
-  BluetoothProfileManagerBase* profile =
-    BluetoothUuidHelper::GetBluetoothProfileManager(aServiceUuid);
-  if (!profile) {
-    InfallibleTArray<BluetoothNamedValue> emptyArr;
-    DispatchReplyError(aRunnable, NS_LITERAL_STRING(ERR_UNKNOWN_PROFILE));
-    return NS_OK;
-  }
-
-  nsTArray<nsString> deviceAddresses;
-  if (profile->IsConnected()) {
-    nsString address;
-    profile->GetAddress(address);
-    deviceAddresses.AppendElement(address);
-  }
-
-  int requestedDeviceCount = deviceAddresses.Length();
-  if (requestedDeviceCount == 0) {
-    InfallibleTArray<BluetoothNamedValue> emptyArr;
-    DispatchReplySuccess(aRunnable, emptyArr);
-    return NS_OK;
-  }
-#endif
 
   sRequestedDeviceCountArray.AppendElement(requestedDeviceCount);
   sGetDeviceRunnableArray.AppendElement(aRunnable);
 
   for (int i = 0; i < requestedDeviceCount; i++) {
     // Retrieve all properties of devices
     sBtInterface->GetRemoteDeviceProperties(deviceAddresses[i],
       new GetRemoteDevicePropertiesResultHandler(deviceAddresses[i]));
@@ -1143,24 +937,24 @@ BluetoothServiceBluedroid::GetConnectedD
 nsresult
 BluetoothServiceBluedroid::GetPairedDevicePropertiesInternal(
   const nsTArray<nsString>& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   ENSURE_BLUETOOTH_IS_READY(aRunnable, NS_OK);
 
+  int requestedDeviceCount = aDeviceAddress.Length();
+
 #ifndef MOZ_B2G_BT_API_V1
-  int requestedDeviceCount = aDeviceAddress.Length();
   if (requestedDeviceCount == 0) {
     DispatchReplySuccess(aRunnable);
     return NS_OK;
   }
 #else
-  int requestedDeviceCount = aDeviceAddress.Length();
   if (requestedDeviceCount == 0) {
     DispatchReplySuccess(aRunnable, InfallibleTArray<BluetoothNamedValue>());
     return NS_OK;
   }
 
   sRequestedDeviceCountArray.AppendElement(requestedDeviceCount);
   sGetDeviceRunnableArray.AppendElement(aRunnable);
 #endif
@@ -1383,21 +1177,21 @@ public:
   CreateBondResultHandler(BluetoothReplyRunnable* aRunnable)
   : mRunnable(aRunnable)
   {
     MOZ_ASSERT(mRunnable);
   }
 
   void OnError(BluetoothStatus aStatus) override
   {
+    sBondingRunnableArray.RemoveElement(mRunnable);
+
 #ifndef MOZ_B2G_BT_API_V1
-    sBondingRunnableArray.RemoveElement(mRunnable);
     DispatchReplyError(mRunnable, aStatus);
 #else
-    sBondingRunnableArray.RemoveElement(mRunnable);
     ReplyStatusError(mRunnable, aStatus, NS_LITERAL_STRING("CreatedPairedDevice"));
 #endif
   }
 
 private:
   nsRefPtr<BluetoothReplyRunnable> mRunnable;
 };
 
@@ -1424,21 +1218,21 @@ public:
   RemoveBondResultHandler(BluetoothReplyRunnable* aRunnable)
   : mRunnable(aRunnable)
   {
     MOZ_ASSERT(mRunnable);
   }
 
   void OnError(BluetoothStatus aStatus) override
   {
+    sUnbondingRunnableArray.RemoveElement(mRunnable);
+
 #ifndef MOZ_B2G_BT_API_V1
-    sUnbondingRunnableArray.RemoveElement(mRunnable);
     DispatchReplyError(mRunnable, aStatus);
 #else
-    sUnbondingRunnableArray.RemoveElement(mRunnable);
     ReplyStatusError(mRunnable, aStatus, NS_LITERAL_STRING("RemoveDevice"));
 #endif
   }
 
 private:
   nsRefPtr<BluetoothReplyRunnable> mRunnable;
 };
 
@@ -1453,39 +1247,43 @@ BluetoothServiceBluedroid::RemoveDeviceI
   sUnbondingRunnableArray.AppendElement(aRunnable);
 
   sBtInterface->RemoveBond(aDeviceAddress,
                            new RemoveBondResultHandler(aRunnable));
 
   return NS_OK;
 }
 
-#ifndef MOZ_B2G_BT_API_V1
 class BluetoothServiceBluedroid::PinReplyResultHandler final
   : public BluetoothResultHandler
 {
 public:
   PinReplyResultHandler(BluetoothReplyRunnable* aRunnable)
   : mRunnable(aRunnable)
   { }
 
   void PinReply() override
   {
     DispatchReplySuccess(mRunnable);
   }
 
   void OnError(BluetoothStatus aStatus) override
   {
+#ifndef MOZ_B2G_BT_API_V1
     DispatchReplyError(mRunnable, aStatus);
+#else
+    ReplyStatusError(mRunnable, aStatus, NS_LITERAL_STRING("SetPinCode"));
+#endif
   }
 
 private:
   BluetoothReplyRunnable* mRunnable;
 };
 
+#ifndef MOZ_B2G_BT_API_V1
 void
 BluetoothServiceBluedroid::PinReplyInternal(
   const nsAString& aDeviceAddress, bool aAccept,
   const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
@@ -1497,38 +1295,16 @@ BluetoothServiceBluedroid::PinReplyInter
 void
 BluetoothServiceBluedroid::SetPinCodeInternal(
   const nsAString& aDeviceAddress, const nsAString& aPinCode,
   BluetoothReplyRunnable* aRunnable)
 {
   // Lecagy method used by BlueZ only.
 }
 #else
-class BluetoothServiceBluedroid::PinReplyResultHandler final
-  : public BluetoothResultHandler
-{
-public:
-  PinReplyResultHandler(BluetoothReplyRunnable* aRunnable)
-  : mRunnable(aRunnable)
-  { }
-
-  void PinReply() override
-  {
-    DispatchReplySuccess(mRunnable);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    ReplyStatusError(mRunnable, aStatus, NS_LITERAL_STRING("SetPinCode"));
-  }
-
-private:
-  BluetoothReplyRunnable* mRunnable;
-};
-
 bool
 BluetoothServiceBluedroid::SetPinCodeInternal(
   const nsAString& aDeviceAddress, const nsAString& aPinCode,
   BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   ENSURE_BLUETOOTH_IS_READY(aRunnable, false);
@@ -1553,39 +1329,44 @@ bool
 BluetoothServiceBluedroid::SetPasskeyInternal(
   const nsAString& aDeviceAddress, uint32_t aPasskey,
   BluetoothReplyRunnable* aRunnable)
 {
   return true;
 }
 #endif
 
-#ifndef MOZ_B2G_BT_API_V1
 class BluetoothServiceBluedroid::SspReplyResultHandler final
   : public BluetoothResultHandler
 {
 public:
   SspReplyResultHandler(BluetoothReplyRunnable* aRunnable)
   : mRunnable(aRunnable)
   { }
 
   void SspReply() override
   {
     DispatchReplySuccess(mRunnable);
   }
 
   void OnError(BluetoothStatus aStatus) override
   {
+#ifndef MOZ_B2G_BT_API_V1
     DispatchReplyError(mRunnable, aStatus);
+#else
+    ReplyStatusError(mRunnable, aStatus,
+                     NS_LITERAL_STRING("SetPairingConfirmation"));
+#endif
   }
 
 private:
   BluetoothReplyRunnable* mRunnable;
 };
 
+#ifndef MOZ_B2G_BT_API_V1
 void
 BluetoothServiceBluedroid::SspReplyInternal(
   const nsAString& aDeviceAddress, BluetoothSspVariant aVariant,
   bool aAccept, BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
@@ -1597,39 +1378,16 @@ BluetoothServiceBluedroid::SspReplyInter
 void
 BluetoothServiceBluedroid::SetPairingConfirmationInternal(
   const nsAString& aDeviceAddress, bool aConfirm,
   BluetoothReplyRunnable* aRunnable)
 {
   // Lecagy method used by BlueZ only.
 }
 #else
-class BluetoothServiceBluedroid::SspReplyResultHandler final
-  : public BluetoothResultHandler
-{
-public:
-  SspReplyResultHandler(BluetoothReplyRunnable* aRunnable)
-  : mRunnable(aRunnable)
-  { }
-
-  void SspReply() override
-  {
-    DispatchReplySuccess(mRunnable);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    ReplyStatusError(mRunnable, aStatus,
-                     NS_LITERAL_STRING("SetPairingConfirmation"));
-  }
-
-private:
-  BluetoothReplyRunnable* mRunnable;
-};
-
 bool
 BluetoothServiceBluedroid::SetPairingConfirmationInternal(
   const nsAString& aDeviceAddress, bool aConfirm,
   BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   ENSURE_BLUETOOTH_IS_READY(aRunnable, false);
@@ -1654,48 +1412,36 @@ BluetoothServiceBluedroid::SetAuthorizat
 
 nsresult
 BluetoothServiceBluedroid::PrepareAdapterInternal()
 {
   return NS_OK;
 }
 #endif
 
-#ifndef MOZ_B2G_BT_API_V1
 void
 BluetoothServiceBluedroid::NextBluetoothProfileController()
-#else
-static void
-NextBluetoothProfileController()
-#endif
 {
   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();
   }
 }
 
-#ifndef MOZ_B2G_BT_API_V1
 void
 BluetoothServiceBluedroid::ConnectDisconnect(
   bool aConnect, const nsAString& aDeviceAddress,
   BluetoothReplyRunnable* aRunnable,
   uint16_t aServiceUuid, uint32_t aCod)
-#else
-static void
-ConnectDisconnect(bool aConnect, const nsAString& aDeviceAddress,
-                  BluetoothReplyRunnable* aRunnable,
-                  uint16_t aServiceUuid, uint32_t aCod = 0)
-#endif
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aRunnable);
 
   BluetoothProfileController* controller =
     new BluetoothProfileController(aConnect, aDeviceAddress, aRunnable,
                                    NextBluetoothProfileController,
                                    aServiceUuid, aCod);
@@ -2821,26 +2567,26 @@ BluetoothServiceBluedroid::SspRequestNot
 #endif
 }
 
 void
 BluetoothServiceBluedroid::BondStateChangedNotification(
   BluetoothStatus aStatus, const nsAString& aRemoteBdAddr,
   BluetoothBondState aState)
 {
-#ifndef MOZ_B2G_BT_API_V1
   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);
 
+#ifndef MOZ_B2G_BT_API_V1
   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));
@@ -2904,23 +2650,16 @@ BluetoothServiceBluedroid::BondStateChan
   if (bonded && !sBondingRunnableArray.IsEmpty()) {
     DispatchReplySuccess(sBondingRunnableArray[0]);
     sBondingRunnableArray.RemoveElementAt(0);
   } else if (!bonded && !sUnbondingRunnableArray.IsEmpty()) {
     DispatchReplySuccess(sUnbondingRunnableArray[0]);
     sUnbondingRunnableArray.RemoveElementAt(0);
   }
 #else
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (aState == BOND_STATE_BONDING) {
-    // No need to handle bonding state
-    return;
-  }
-
   if (aState == BOND_STATE_BONDED &&
       sAdapterBondedAddressArray.Contains(aRemoteBdAddr)) {
     // See bug 940271 for more details about this case.
     return;
   }
 
   switch (aStatus) {
     case STATUS_SUCCESS:
@@ -3018,28 +2757,24 @@ void
 BluetoothServiceBluedroid::LeTestModeNotification(BluetoothStatus aStatus,
                                                   uint16_t aNumPackets)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // FIXME: This will be implemented in the later patchset
 }
 
-#ifndef MOZ_B2G_BT_API_V1
-// TODO: Support EnergyInfoNotification
-#else
 void
 BluetoothServiceBluedroid::EnergyInfoNotification(
   const BluetoothActivityEnergyInfo& aInfo)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // FIXME: This will be implemented in the later patchset
 }
-#endif
 
 void
 BluetoothServiceBluedroid::BackendErrorNotification(bool aCrashed)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!aCrashed) {
     return;
--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.h
+++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.h
@@ -2,64 +2,79 @@
 /* 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_bluetoothservicebluedroid_h__
 #define mozilla_dom_bluetooth_bluetoothservicebluedroid_h__
 
-#ifndef MOZ_B2G_BT_API_V1
-
 #include "BluetoothCommon.h"
 #include "BluetoothInterface.h"
 #include "BluetoothService.h"
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 class BluetoothServiceBluedroid : public BluetoothService
                                 , public BluetoothNotificationHandler
 {
   class CancelDiscoveryResultHandler;
   class CreateBondResultHandler;
   class DisableResultHandler;
   class EnableResultHandler;
   class GetRemoteDevicePropertiesResultHandler;
+#ifndef MOZ_B2G_BT_API_V1
   class GetRemoteServicesResultHandler;
+#else
+  // Missing in Bluetooth v1
+#endif
   class InitResultHandler;
   class PinReplyResultHandler;
   class ProfileDeinitResultHandler;
   class ProfileInitResultHandler;
   class RemoveBondResultHandler;
   class SetAdapterPropertyDiscoverableResultHandler;
   class SetAdapterPropertyResultHandler;
   class SspReplyResultHandler;
   class StartDiscoveryResultHandler;
 
 public:
   BluetoothServiceBluedroid();
   ~BluetoothServiceBluedroid();
 
+#ifndef MOZ_B2G_BT_API_V1
   virtual nsresult StartInternal(BluetoothReplyRunnable* aRunnable);
   virtual nsresult StopInternal(BluetoothReplyRunnable* aRunnable);
+#else
+  virtual nsresult StartInternal();
+  virtual nsresult StopInternal();
+#endif
 
-  virtual nsresult
-  GetAdaptersInternal(BluetoothReplyRunnable* aRunnable);
+#ifndef MOZ_B2G_BT_API_V1
+  virtual nsresult GetAdaptersInternal(BluetoothReplyRunnable* aRunnable);
+#else
+  virtual nsresult GetDefaultAdapterPathInternal(
+    BluetoothReplyRunnable* aRunnable);
+#endif
 
   virtual nsresult
   GetConnectedDevicePropertiesInternal(uint16_t aProfileId,
                                        BluetoothReplyRunnable* aRunnable);
 
   virtual nsresult
   GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddress,
                                     BluetoothReplyRunnable* aRunnable);
 
+#ifndef MOZ_B2G_BT_API_V1
   virtual nsresult
   FetchUuidsInternal(const nsAString& aDeviceAddress,
                      BluetoothReplyRunnable* aRunnable) override;
+#else
+  // Missing in Bluetooth v1
+#endif
 
   virtual void StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
   virtual void StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
 
   virtual nsresult
   SetProperty(BluetoothObjectType aType,
               const BluetoothNamedValue& aValue,
               BluetoothReplyRunnable* aRunnable);
@@ -77,51 +92,84 @@ public:
   CreatePairedDeviceInternal(const nsAString& aDeviceAddress,
                              int aTimeout,
                              BluetoothReplyRunnable* aRunnable);
 
   virtual nsresult
   RemoveDeviceInternal(const nsAString& aDeviceObjectPath,
                        BluetoothReplyRunnable* aRunnable);
 
+#ifndef MOZ_B2G_BT_API_V1
   virtual void
   PinReplyInternal(const nsAString& aDeviceAddress,
                    bool aAccept,
                    const nsAString& aPinCode,
                    BluetoothReplyRunnable* aRunnable);
 
   virtual void
   SspReplyInternal(const nsAString& aDeviceAddress,
                    BluetoothSspVariant aVariant,
                    bool aAccept,
                    BluetoothReplyRunnable* aRunnable);
-
   virtual void
   SetPinCodeInternal(const nsAString& aDeviceAddress,
                      const nsAString& aPinCode,
                      BluetoothReplyRunnable* aRunnable);
 
   virtual void
   SetPasskeyInternal(const nsAString& aDeviceAddress,
                      uint32_t aPasskey,
                      BluetoothReplyRunnable* aRunnable);
 
   virtual void
   SetPairingConfirmationInternal(const nsAString& aDeviceAddress,
                                  bool aConfirm,
                                  BluetoothReplyRunnable* aRunnable);
+#else
+  virtual bool
+  SetAuthorizationInternal(const nsAString& aDeviceAddress, bool aAllow,
+                           BluetoothReplyRunnable* aRunnable);
+
+  virtual bool
+  SetPinCodeInternal(const nsAString& aDeviceAddress,
+                     const nsAString& aPinCode,
+                     BluetoothReplyRunnable* aRunnable);
+
+  virtual bool
+  SetPasskeyInternal(const nsAString& aDeviceAddress,
+                     uint32_t aPasskey,
+                     BluetoothReplyRunnable* aRunnable);
+
+  virtual bool
+  SetPairingConfirmationInternal(const nsAString& aDeviceAddress,
+                                 bool aConfirm,
+                                 BluetoothReplyRunnable* aRunnable);
+#endif
+
+#ifndef MOZ_B2G_BT_API_V1
+  // Missing in Bluetooth v2
+#else
+  virtual nsresult
+  PrepareAdapterInternal();
+#endif
 
   virtual void
   Connect(const nsAString& aDeviceAddress,
           uint32_t aCod,
           uint16_t aServiceUuid,
           BluetoothReplyRunnable* aRunnable);
 
+#ifndef MOZ_B2G_BT_API_V1
   virtual bool
   IsConnected(uint16_t aProfileId);
+#else
+  virtual void
+  IsConnected(const uint16_t aServiceUuid,
+              BluetoothReplyRunnable* aRunnable) override;
+#endif
 
   virtual void
   Disconnect(const nsAString& aDeviceAddress, uint16_t aServiceUuid,
              BluetoothReplyRunnable* aRunnable);
 
   virtual void
   SendFile(const nsAString& aDeviceAddress,
            BlobParent* aBlobParent,
@@ -186,16 +234,17 @@ public:
   virtual nsresult
   SendInputMessage(const nsAString& aDeviceAddresses,
                    const nsAString& aMessage) override;
 
   //
   // GATT Client
   //
 
+#ifndef MOZ_B2G_BT_API_V1
   virtual void StartLeScanInternal(const nsTArray<nsString>& aServiceUuids,
                                    BluetoothReplyRunnable* aRunnable);
 
   virtual void StopLeScanInternal(const nsAString& aScanUuid,
                                   BluetoothReplyRunnable* aRunnable);
 
   virtual void
   ConnectGattClientInternal(const nsAString& aAppUuid,
@@ -261,16 +310,19 @@ public:
   virtual void
   GattClientWriteDescriptorValueInternal(
     const nsAString& aAppUuid,
     const BluetoothGattServiceId& aServiceId,
     const BluetoothGattId& aCharacteristicId,
     const BluetoothGattId& aDescriptorId,
     const nsTArray<uint8_t>& aValue,
     BluetoothReplyRunnable* aRunnable) override;
+#else
+  // Missing in Bluetooth v1
+#endif
 
   //
   // Bluetooth notifications
   //
 
   virtual void AdapterStateChangedNotification(bool aState) override;
   virtual void AdapterPropertiesNotification(
     BluetoothStatus aStatus, int aNumProperties,
@@ -301,259 +353,45 @@ public:
                                            const nsAString& aRemoteBdAddr,
                                            bool 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 ControlPlayStatus PlayStatusStringToControlPlayStatus(
+    const nsAString& aPlayStatus);
+
   static void ConnectDisconnect(bool aConnect,
                                 const nsAString& aDeviceAddress,
                                 BluetoothReplyRunnable* aRunnable,
                                 uint16_t aServiceUuid, uint32_t aCod = 0);
   static void NextBluetoothProfileController();
-  static ControlPlayStatus PlayStatusStringToControlPlayStatus(
-    const nsAString& aPlayStatus);
-};
 
-END_BLUETOOTH_NAMESPACE
-
+#ifndef MOZ_B2G_BT_API_V1
+  // Missing in Bluetooth v2
 #else
-
-#include "BluetoothCommon.h"
-#include "BluetoothInterface.h"
-#include "BluetoothService.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothServiceBluedroid : public BluetoothService
-                                , public BluetoothNotificationHandler
-{
-  class CancelDiscoveryResultHandler;
-  class CreateBondResultHandler;
-  class DisableResultHandler;
-  class EnableResultHandler;
-  class GetRemoteDevicePropertiesResultHandler;
-  class InitResultHandler;
-  class PinReplyResultHandler;
-  class ProfileDeinitResultHandler;
-  class ProfileInitResultHandler;
-  class RemoveBondResultHandler;
-  class SetAdapterPropertyDiscoverableResultHandler;
-  class SetAdapterPropertyResultHandler;
-  class SspReplyResultHandler;
-  class StartDiscoveryResultHandler;
-
-public:
-  BluetoothServiceBluedroid();
-  ~BluetoothServiceBluedroid();
-
-  virtual nsresult StartInternal();
-  virtual nsresult StopInternal();
-
-  virtual nsresult GetDefaultAdapterPathInternal(
-                                             BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult GetConnectedDevicePropertiesInternal(uint16_t aProfileId,
-                                             BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult GetPairedDevicePropertiesInternal(
-                                     const nsTArray<nsString>& aDeviceAddress,
-                                     BluetoothReplyRunnable* aRunnable);
-
-  virtual void StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
-  virtual void StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult
-  SetProperty(BluetoothObjectType aType,
-              const BluetoothNamedValue& aValue,
-              BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult
-  GetServiceChannel(const nsAString& aDeviceAddress,
-                    const nsAString& aServiceUuid,
-                    BluetoothProfileManagerBase* aManager);
-
-  virtual bool
-  UpdateSdpRecords(const nsAString& aDeviceAddress,
-                   BluetoothProfileManagerBase* aManager);
-
-  virtual nsresult
-  CreatePairedDeviceInternal(const nsAString& aDeviceAddress,
-                             int aTimeout,
-                             BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult
-  RemoveDeviceInternal(const nsAString& aDeviceObjectPath,
-                       BluetoothReplyRunnable* aRunnable);
-
-  virtual bool
-  SetPinCodeInternal(const nsAString& aDeviceAddress, const nsAString& aPinCode,
-                     BluetoothReplyRunnable* aRunnable);
-
-  virtual bool
-  SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey,
-                     BluetoothReplyRunnable* aRunnable);
-
-  virtual bool
-  SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm,
-                                 BluetoothReplyRunnable* aRunnable);
-
-  virtual bool
-  SetAuthorizationInternal(const nsAString& aDeviceAddress, bool aAllow,
-                           BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult
-  PrepareAdapterInternal();
-
-  virtual void
-  Connect(const nsAString& aDeviceAddress,
-          uint32_t aCod,
-          uint16_t aServiceUuid,
-          BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  Disconnect(const nsAString& aDeviceAddress, uint16_t aServiceUuid,
-             BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  IsConnected(const uint16_t aServiceUuid,
-              BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SendFile(const nsAString& aDeviceAddress,
-           BlobParent* aBlobParent,
-           BlobChild* aBlobChild,
-           BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  SendFile(const nsAString& aDeviceAddress,
-           Blob* aBlob,
-           BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  StopSendingFile(const nsAString& aDeviceAddress,
-                  BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirm,
-                       BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ConnectSco(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  DisconnectSco(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  IsScoConnected(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,
-                 const nsAString& 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;
-
-  //
-  // 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 nsAString& 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 nsAString& aRemoteBdAddr,
-                                      const nsAString& aBdName,
-                                      uint32_t aCod) override;
-  virtual void SspRequestNotification(const nsAString& aRemoteBdAddr,
-                                      const nsAString& aBdName,
-                                      uint32_t aCod,
-                                      BluetoothSspVariant aPairingVariant,
-                                      uint32_t aPassKey) override;
-
-  virtual void BondStateChangedNotification(
-    BluetoothStatus aStatus, const nsAString& aRemoteBdAddr,
-    BluetoothBondState aState) override;
-  virtual void AclStateChangedNotification(BluetoothStatus aStatus,
-                                           const nsAString& aRemoteBdAddr,
-                                           bool 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 bool EnsureBluetoothHalLoad();
 
   static void ClassToIcon(uint32_t aClass, nsAString& aRetIcon);
 
-  static ControlPlayStatus PlayStatusStringToControlPlayStatus(
-    const nsAString& aPlayStatus);
-
   uint16_t UuidToServiceClassInt(const BluetoothUuid& mUuid);
 
   static bool IsConnected(const nsAString& aRemoteBdAddr);
+#endif
 };
 
 END_BLUETOOTH_NAMESPACE
 
 #endif
-
-#endif
--- a/dom/media/platforms/gonk/GonkDecoderModule.cpp
+++ b/dom/media/platforms/gonk/GonkDecoderModule.cpp
@@ -61,14 +61,15 @@ GonkDecoderModule::DecoderNeedsConversio
 }
 
 bool
 GonkDecoderModule::SupportsMimeType(const nsACString& aMimeType)
 {
   return aMimeType.EqualsLiteral("audio/mp4a-latm") ||
     aMimeType.EqualsLiteral("audio/3gpp") ||
     aMimeType.EqualsLiteral("audio/amr-wb") ||
+    aMimeType.EqualsLiteral("audio/mpeg") ||
     aMimeType.EqualsLiteral("video/mp4") ||
     aMimeType.EqualsLiteral("video/mp4v-es") ||
     aMimeType.EqualsLiteral("video/avc") ||
     aMimeType.EqualsLiteral("video/3gpp");
 }
 } // namespace mozilla
--- a/dom/secureelement/gonk/UiccConnector.js
+++ b/dom/secureelement/gonk/UiccConnector.js
@@ -323,17 +323,17 @@ UiccConnector.prototype = {
     this._SEListeners.push(listener);
     // immediately notify listener about the current state
     listener.notifySEPresenceChanged(SE.TYPE_UICC, this._isPresent);
   },
 
   unregisterListener: function(listener) {
     let idx = this._SEListeners.indexOf(listener);
     if (idx !== -1) {
-      this._listeners.splice(idx, 1);
+      this._SEListeners.splice(idx, 1);
     }
   },
 
   /**
    * nsIIccListener interface methods.
    */
   notifyStkCommand: function() {},