Bug 889795 - Reply 'Authorize' signal for supported profile, r=echou, sr=mrbkap
authorGina Yeh <gyeh@mozilla.com>
Wed, 14 Aug 2013 13:54:18 +0800
changeset 142591 fab433e89f6d29bfb362251124d18bd9ca50b510
parent 142590 76a010d2a973458f9c662c2fb741beee74f6a9ad
child 142592 70c6eb60801eb9932850cd227635c597d01bc269
child 142641 a1884c9b556b1466895968796b09f66e598db954
push id32443
push userMs2ger@gmail.com
push dateWed, 14 Aug 2013 12:48:34 +0000
treeherdermozilla-inbound@c2050f734802 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechou, mrbkap
bugs889795
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 889795 - Reply 'Authorize' signal for supported profile, r=echou, sr=mrbkap
dom/bluetooth/BluetoothAdapter.cpp
dom/bluetooth/BluetoothService.cpp
dom/bluetooth/BluetoothService.h
dom/bluetooth/BluetoothUuid.cpp
dom/bluetooth/BluetoothUuid.h
dom/bluetooth/ipc/BluetoothParent.cpp
dom/bluetooth/ipc/BluetoothParent.h
dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
dom/bluetooth/ipc/BluetoothServiceChildProcess.h
dom/bluetooth/ipc/PBluetooth.ipdl
dom/bluetooth/linux/BluetoothDBusService.cpp
dom/bluetooth/linux/BluetoothDBusService.h
dom/messages/SystemMessagePermissionsChecker.jsm
dom/webidl/BluetoothAdapter.webidl
--- a/dom/bluetooth/BluetoothAdapter.cpp
+++ b/dom/bluetooth/BluetoothAdapter.cpp
@@ -651,44 +651,16 @@ BluetoothAdapter::SetPairingConfirmation
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
   return request.forget();
 }
 
 already_AddRefed<DOMRequest>
-BluetoothAdapter::SetAuthorization(const nsAString& aDeviceAddress, bool aAllow,
-                                   ErrorResult& aRv)
-{
-  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
-  if (!win) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  nsRefPtr<DOMRequest> request = new DOMRequest(win);
-  nsRefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(request);
-
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-  if (!bs->SetAuthorizationInternal(aDeviceAddress, aAllow, results)) {
-    NS_WARNING("SetAuthorization failed!");
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  return request.forget();
-}
-
-already_AddRefed<DOMRequest>
 BluetoothAdapter::Connect(const nsAString& aDeviceAddress,
                           uint16_t aProfileId, ErrorResult& aRv)
 {
   nsCOMPtr<nsPIDOMWindow> win = GetOwner();
   if (!win) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
--- a/dom/bluetooth/BluetoothService.cpp
+++ b/dom/bluetooth/BluetoothService.cpp
@@ -785,20 +785,16 @@ BluetoothService::Notify(const Bluetooth
     MOZ_ASSERT(aData.value().get_ArrayOfBluetoothNamedValue().Length() == 4,
       "RequestConfirmation: Wrong length of parameters");
   } else if (aData.name().EqualsLiteral("RequestPinCode")) {
     MOZ_ASSERT(aData.value().get_ArrayOfBluetoothNamedValue().Length() == 3,
       "RequestPinCode: Wrong length of parameters");
   } else if (aData.name().EqualsLiteral("RequestPasskey")) {
     MOZ_ASSERT(aData.value().get_ArrayOfBluetoothNamedValue().Length() == 3,
       "RequestPinCode: Wrong length of parameters");
-  } else if (aData.name().EqualsLiteral("Authorize")) {
-    MOZ_ASSERT(aData.value().get_ArrayOfBluetoothNamedValue().Length() == 2,
-      "Authorize: Wrong length of parameters");
-    type.AssignLiteral("bluetooth-authorize");
   } else if (aData.name().EqualsLiteral("Cancel")) {
     MOZ_ASSERT(aData.value().get_ArrayOfBluetoothNamedValue().Length() == 0,
       "Cancel: Wrong length of parameters");
     type.AssignLiteral("bluetooth-cancel");
   } else if (aData.name().EqualsLiteral(PAIRED_STATUS_CHANGED_ID)) {
     MOZ_ASSERT(aData.value().get_ArrayOfBluetoothNamedValue().Length() == 1,
       "pairedstatuschanged: Wrong length of parameters");
     type.AssignLiteral("bluetooth-pairedstatuschanged");
--- a/dom/bluetooth/BluetoothService.h
+++ b/dom/bluetooth/BluetoothService.h
@@ -227,20 +227,16 @@ public:
   virtual bool
   SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey,
                      BluetoothReplyRunnable* aRunnable) = 0;
 
   virtual bool
   SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm,
                                  BluetoothReplyRunnable* aRunnable) = 0;
 
-  virtual bool
-  SetAuthorizationInternal(const nsAString& aDeviceAddress, bool aAllow,
-                           BluetoothReplyRunnable* aRunnable) = 0;
-
   virtual void
   Connect(const nsAString& aDeviceAddress,
           uint16_t aProfileId,
           BluetoothReplyRunnable* aRunnable) = 0;
 
   virtual void
   Disconnect(uint16_t aProfileId, BluetoothReplyRunnable* aRunnable) = 0;
 
--- a/dom/bluetooth/BluetoothUuid.cpp
+++ b/dom/bluetooth/BluetoothUuid.cpp
@@ -13,8 +13,39 @@ BluetoothUuidHelper::GetString(Bluetooth
                                nsAString& aRetUuidStr)
 {
   aRetUuidStr.Truncate();
 
   aRetUuidStr.AppendLiteral("0000");
   aRetUuidStr.AppendInt(aServiceClassUuid, 16);
   aRetUuidStr.AppendLiteral("-0000-1000-8000-00805F9B34FB");
 }
+
+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);
+
+  switch (integer) {
+    case BluetoothServiceClass::A2DP:
+    case BluetoothServiceClass::HANDSFREE:
+    case BluetoothServiceClass::HANDSFREE_AG:
+    case BluetoothServiceClass::HEADSET:
+    case BluetoothServiceClass::HEADSET_AG:
+    case BluetoothServiceClass::HID:
+    case BluetoothServiceClass::OBJECT_PUSH:
+      retValue = (BluetoothServiceClass)integer;
+  }
+  return retValue;
+}
--- a/dom/bluetooth/BluetoothUuid.h
+++ b/dom/bluetooth/BluetoothUuid.h
@@ -17,36 +17,47 @@ BEGIN_BLUETOOTH_NAMESPACE
  * 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
 {
+  A2DP          = 0x110D,
+  HANDSFREE     = 0x111E,
+  HANDSFREE_AG  = 0x111F,
   HEADSET       = 0x1108,
   HEADSET_AG    = 0x1112,
-  HANDSFREE     = 0x111E,
-  HANDSFREE_AG  = 0x111F,
+  HID           = 0x1124,
   OBJECT_PUSH   = 0x1105,
-  HID           = 0x1124,
+  UNKNOWN       = 0x0000
 };
 
 class BluetoothUuidHelper
 {
 public:
   /**
    * Get a 128-bit uuid string calculated from a 16-bit service class UUID and
    * BASE_UUID
    *
    * @param aServiceClassUuid  16-bit service class UUID
    * @param aRetUuidStr  out parameter, 128-bit uuid string
    */
   static void
   GetString(BluetoothServiceClass aServiceClassUuid, nsAString& aRetUuidStr);
+
+  /**
+   * 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);
 };
 
 // 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 {
--- a/dom/bluetooth/ipc/BluetoothParent.cpp
+++ b/dom/bluetooth/ipc/BluetoothParent.cpp
@@ -201,22 +201,18 @@ BluetoothParent::RecvPBluetoothRequestCo
     case Request::TConnectedDevicePropertiesRequest:
       return actor->DoRequest(aRequest.get_ConnectedDevicePropertiesRequest());
     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::TConfirmAuthorizationRequest:
-      return actor->DoRequest(aRequest.get_ConfirmAuthorizationRequest());
     case Request::TDenyPairingConfirmationRequest:
       return actor->DoRequest(aRequest.get_DenyPairingConfirmationRequest());
-    case Request::TDenyAuthorizationRequest:
-      return actor->DoRequest(aRequest.get_DenyAuthorizationRequest());
     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());
@@ -450,32 +446,16 @@ BluetoothRequestParent::DoRequest(const 
                                              mReplyRunnable.get());
 
   NS_ENSURE_TRUE(result, false);
 
   return true;
 }
 
 bool
-BluetoothRequestParent::DoRequest(const ConfirmAuthorizationRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TConfirmAuthorizationRequest);
-
-  bool result =
-    mService->SetAuthorizationInternal(aRequest.path(),
-                                       true,
-                                       mReplyRunnable.get());
-
-  NS_ENSURE_TRUE(result, false);
-
-  return true;
-}
-
-bool
 BluetoothRequestParent::DoRequest(const DenyPairingConfirmationRequest&
                                   aRequest)
 {
   MOZ_ASSERT(mService);
   MOZ_ASSERT(mRequestType == Request::TDenyPairingConfirmationRequest);
 
   bool result =
     mService->SetPairingConfirmationInternal(aRequest.path(),
@@ -483,32 +463,16 @@ BluetoothRequestParent::DoRequest(const 
                                              mReplyRunnable.get());
 
   NS_ENSURE_TRUE(result, false);
 
   return true;
 }
 
 bool
-BluetoothRequestParent::DoRequest(const DenyAuthorizationRequest& aRequest)
-{
-  MOZ_ASSERT(mService);
-  MOZ_ASSERT(mRequestType == Request::TDenyAuthorizationRequest);
-
-  bool result =
-    mService->SetAuthorizationInternal(aRequest.path(),
-                                       false,
-                                       mReplyRunnable.get());
-
-  NS_ENSURE_TRUE(result, false);
-
-  return true;
-}
-
-bool
 BluetoothRequestParent::DoRequest(const ConnectRequest& aRequest)
 {
   MOZ_ASSERT(mService);
   MOZ_ASSERT(mRequestType == Request::TConnectRequest);
 
   mService->Connect(aRequest.address(),
                     aRequest.profileId(),
                     mReplyRunnable.get());
--- a/dom/bluetooth/ipc/BluetoothParent.h
+++ b/dom/bluetooth/ipc/BluetoothParent.h
@@ -158,22 +158,16 @@ protected:
 
   bool
   DoRequest(const ConfirmPairingConfirmationRequest& aRequest);
 
   bool
   DoRequest(const DenyPairingConfirmationRequest& aRequest);
 
   bool
-  DoRequest(const ConfirmAuthorizationRequest& aRequest);
-
-  bool
-  DoRequest(const DenyAuthorizationRequest& aRequest);
-
-  bool
   DoRequest(const ConnectRequest& aRequest);
 
   bool
   DoRequest(const DisconnectRequest& aRequest);
 
   bool
   DoRequest(const SendFileRequest& aRequest);
 
--- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
+++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
@@ -245,32 +245,16 @@ BluetoothServiceChildProcess::SetPairing
                 ConfirmPairingConfirmationRequest(nsString(aDeviceAddress)));
   } else {
     SendRequest(aRunnable,
                 DenyPairingConfirmationRequest(nsString(aDeviceAddress)));
   }
   return true;
 }
 
-bool
-BluetoothServiceChildProcess::SetAuthorizationInternal(
-                                                const nsAString& aDeviceAddress,
-                                                bool aAllow,
-                                                BluetoothReplyRunnable* aRunnable)
-{
-  if(aAllow) {
-    SendRequest(aRunnable,
-                ConfirmAuthorizationRequest(nsString(aDeviceAddress)));
-  } else {
-    SendRequest(aRunnable,
-                DenyAuthorizationRequest(nsString(aDeviceAddress)));
-  }
-  return true;
-}
-
 void
 BluetoothServiceChildProcess::Connect(
   const nsAString& aDeviceAddress,
   const uint16_t aProfileId,
   BluetoothReplyRunnable* aRunnable)
 {
   SendRequest(aRunnable,
               ConnectRequest(nsString(aDeviceAddress),
--- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.h
+++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.h
@@ -106,21 +106,16 @@ public:
                      BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
 
   virtual bool
   SetPairingConfirmationInternal(const nsAString& aDeviceAddress,
                                  bool aConfirm,
                                  BluetoothReplyRunnable* aRunnable)
                                  MOZ_OVERRIDE;
 
-  virtual bool
-  SetAuthorizationInternal(const nsAString& aDeviceAddress,
-                           bool aAllow,
-                           BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
-
   virtual void
   Connect(const nsAString& aDeviceAddress,
           const uint16_t aProfileId,
           BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
 
   virtual void
   Disconnect(const uint16_t aProfileId,
              BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
--- a/dom/bluetooth/ipc/PBluetooth.ipdl
+++ b/dom/bluetooth/ipc/PBluetooth.ipdl
@@ -73,26 +73,16 @@ struct ConfirmPairingConfirmationRequest
   nsString path;
 };
 
 struct DenyPairingConfirmationRequest
 {
   nsString path;
 };
 
-struct ConfirmAuthorizationRequest
-{
-  nsString path;
-};
-
-struct DenyAuthorizationRequest
-{
-  nsString path;
-};
-
 struct PairedDevicePropertiesRequest
 {
   nsString[] addresses;
 };
 struct ConnectedDevicePropertiesRequest
 {
   uint16_t profileId;
 };
@@ -166,18 +156,16 @@ union Request
   StartDiscoveryRequest;
   StopDiscoveryRequest;
   PairRequest;
   UnpairRequest;
   SetPinCodeRequest;
   SetPasskeyRequest;
   ConfirmPairingConfirmationRequest;
   DenyPairingConfirmationRequest;
-  ConfirmAuthorizationRequest;
-  DenyAuthorizationRequest;
   ConnectedDevicePropertiesRequest;
   PairedDevicePropertiesRequest;
   ConnectRequest;
   DisconnectRequest;
   SendFileRequest;
   StopSendingFileRequest;
   ConfirmReceivingFileRequest;
   DenyReceivingFileRequest;
--- a/dom/bluetooth/linux/BluetoothDBusService.cpp
+++ b/dom/bluetooth/linux/BluetoothDBusService.cpp
@@ -29,16 +29,17 @@
 
 #include <cstdio>
 #include <dbus/dbus.h>
 
 #include "nsAutoPtr.h"
 #include "nsThreadUtils.h"
 #include "nsDebug.h"
 #include "nsDataHashtable.h"
+#include "nsPrintfCString.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
 #include "mozilla/Hal.h"
 #include "mozilla/ipc/UnixSocket.h"
 #include "mozilla/ipc/DBusThread.h"
 #include "mozilla/ipc/DBusUtils.h"
 #include "mozilla/ipc/RawDBusConnection.h"
 #include "mozilla/Mutex.h"
@@ -168,17 +169,17 @@ static const char* sBluetoothDBusSignals
 
 /**
  * DBus Connection held for the BluetoothCommandThread to use. Should never be
  * used by any other thread.
  *
  */
 static nsRefPtr<RawDBusConnection> gThreadConnection;
 static nsDataHashtable<nsStringHashKey, DBusMessage* > sPairingReqTable;
-static nsDataHashtable<nsStringHashKey, DBusMessage* > sAuthorizeReqTable;
+static nsTArray<uint32_t> sAuthorizedServiceClass;
 static nsString sAdapterPath;
 static Atomic<int32_t> sIsPairing(0);
 static int sConnectedDeviceCount = 0;
 static Monitor sStopBluetoothMonitor("BluetoothService.sStopBluetoothMonitor");
 
 typedef void (*UnpackFunc)(DBusMessage*, DBusError*, BluetoothValue&, nsAString&);
 typedef bool (*FilterFunc)(const BluetoothValue&);
 
@@ -613,25 +614,19 @@ GetProperty(DBusMessageIter aIter, Prope
    */
   bool convert = false;
   if (propertyName.EqualsLiteral("Connected") &&
       receivedType == DBUS_TYPE_ARRAY) {
     convert = true;
   }
 
   if ((receivedType != expectedType) && !convert) {
-    NS_WARNING("Iterator not type we expect!");
-    nsCString str;
-    str.AppendLiteral("Property Name: ");
-    str.Append(NS_ConvertUTF16toUTF8(propertyName));
-    str.AppendLiteral(", Property Type Expected: ");
-    str.AppendInt(expectedType);
-    str.AppendLiteral(", Property Type Received: ");
-    str.AppendInt(receivedType);
-    NS_WARNING(str.get());
+    NS_WARNING(nsPrintfCString("Iterator not type we expect! Property name: %s,
+      Property Type Expected: %d, Property Type Received: %d",
+      NS_ConvertUTF16toUTF8(propertyName).get(), expectedType, receivedType).get());
     return false;
   }
 
   BluetoothValue propertyValue;
   switch (receivedType) {
     case DBUS_TYPE_STRING:
     case DBUS_TYPE_OBJECT_PATH:
       const char* c;
@@ -979,50 +974,62 @@ AgentEventFilter(DBusConnection *conn, D
   } 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, NULL,
                                DBUS_TYPE_OBJECT_PATH, &objectPath,
                                DBUS_TYPE_STRING, &uuid,
                                DBUS_TYPE_INVALID)) {
-      BT_WARNING("%s: Invalid arguments for Authorize() method", __FUNCTION__);
       errorStr.AssignLiteral("Invalid arguments for Authorize() method");
       goto handle_error;
     }
 
-    nsString deviceAddress =
-      GetAddressFromObjectPath(NS_ConvertUTF8toUTF16(objectPath));
-
-    parameters.AppendElement(
-      BluetoothNamedValue(NS_LITERAL_STRING("deviceAddress"), deviceAddress));
-    parameters.AppendElement(
-      BluetoothNamedValue(NS_LITERAL_STRING("uuid"),
-                          NS_ConvertUTF8toUTF16(uuid)));
-
-    // Because we may have authorization request and pairing request from the
-    // same remote device at the same time, we need two tables to keep these
-    // messages.
-    sAuthorizeReqTable.Put(deviceAddress, msg);
-
-    // Increase ref count here because we need this message later.
-    // It'll be unrefed when setAuthorizationInternal() is called.
-    dbus_message_ref(msg);
-
-    v = parameters;
+    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;
+    int i;
+    int length = sAuthorizedServiceClass.Length();
+    for (i = 0; i < length; i++) {
+      if (serviceClass == sAuthorizedServiceClass[i]) {
+        reply = dbus_message_new_method_return(msg);
+        break;
+      }
+    }
+
+    // The uuid isn't authorized
+    if (i == length) {
+      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, NULL);
+    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, NULL,
                                DBUS_TYPE_OBJECT_PATH, &objectPath,
                                DBUS_TYPE_UINT32, &passkey,
                                DBUS_TYPE_INVALID)) {
-      BT_WARNING("%s: Invalid arguments: RequestConfirmation()", __FUNCTION__);
       errorStr.AssignLiteral("Invalid arguments: RequestConfirmation()");
       goto handle_error;
     }
 
     parameters.AppendElement(
       BluetoothNamedValue(NS_LITERAL_STRING("path"),
                           NS_ConvertUTF8toUTF16(objectPath)));
     parameters.AppendElement(
@@ -1036,18 +1043,16 @@ AgentEventFilter(DBusConnection *conn, D
   } 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, NULL,
                                DBUS_TYPE_OBJECT_PATH, &objectPath,
                                DBUS_TYPE_INVALID)) {
-      BT_WARNING("%s: Invalid arguments for RequestPinCode() method",
-                 __FUNCTION__);
       errorStr.AssignLiteral("Invalid arguments for RequestPinCode() method");
       goto handle_error;
     }
 
     parameters.AppendElement(
       BluetoothNamedValue(NS_LITERAL_STRING("path"),
                           NS_ConvertUTF8toUTF16(objectPath)));
     parameters.AppendElement(
@@ -1059,18 +1064,16 @@ AgentEventFilter(DBusConnection *conn, D
   } 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, NULL,
                                DBUS_TYPE_OBJECT_PATH, &objectPath,
                                DBUS_TYPE_INVALID)) {
-      BT_WARNING("%s: Invalid arguments for RequestPasskey() method",
-                 __FUNCTION__);
       errorStr.AssignLiteral("Invalid arguments for RequestPasskey() method");
       goto handle_error;
     }
 
     parameters.AppendElement(BluetoothNamedValue(
                                NS_LITERAL_STRING("path"),
                                NS_ConvertUTF8toUTF16(objectPath)));
     parameters.AppendElement(BluetoothNamedValue(
@@ -1099,17 +1102,17 @@ AgentEventFilter(DBusConnection *conn, D
   } else {
 #ifdef DEBUG
     BT_WARNING("agent handler %s: Unhandled event. Ignore.", __FUNCTION__);
 #endif
     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
   }
 
   if (!errorStr.IsEmpty()) {
-    NS_WARNING(NS_ConvertUTF16toUTF8(errorStr).get());
+    BT_WARNING(NS_ConvertUTF16toUTF8(errorStr).get());
     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
   }
 
   // Update value after parsing DBus message
   signal.value() = v;
 
   if (isPairingReq) {
     sPairingReqTable.Put(
@@ -1123,17 +1126,17 @@ AgentEventFilter(DBusConnection *conn, D
   } else {
     handler = new DistributeBluetoothSignalTask(signal);
   }
   NS_DispatchToMainThread(handler);
 
   return DBUS_HANDLER_RESULT_HANDLED;
 
 handle_error:
-  NS_WARNING(NS_ConvertUTF16toUTF8(errorStr).get());
+  BT_WARNING(NS_ConvertUTF16toUTF8(errorStr).get());
   return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
 class RegisterAgentReplyHandler : public DBusReplyHandler
 {
 public:
   RegisterAgentReplyHandler(const DBusObjectPathVTable* aAgentVTable)
     : mAgentVTable(aAgentVTable)
@@ -1297,16 +1300,18 @@ public:
     nsRefPtr<RawDBusConnection> threadConnection = gThreadConnection;
 
     if (!threadConnection.get()) {
       BT_WARNING("%s: DBus connection has been closed.", __FUNCTION__);
       return NS_ERROR_FAILURE;
     }
 
     sAdapterPath = mAdapterPath;
+    sAuthorizedServiceClass.AppendElement(BluetoothServiceClass::A2DP);
+    sAuthorizedServiceClass.AppendElement(BluetoothServiceClass::HID);
 
     nsRefPtr<DBusReplyHandler> handler =
       new AddReservedServiceRecordsReplyHandler();
 
     const dbus_uint32_t* services = sServices;
 
     bool success = dbus_func_args_async(threadConnection->GetConnection(), -1,
                                         DBusReplyHandler::Callback, handler.get(),
@@ -1694,20 +1699,16 @@ BluetoothDBusService::StartInternal()
     NS_WARNING("Cannot create DBus Event Filter for DBus Thread!");
     return NS_ERROR_FAILURE;
   }
 
   if (!sPairingReqTable.IsInitialized()) {
     sPairingReqTable.Init();
   }
 
-  if (!sAuthorizeReqTable.IsInitialized()) {
-    sAuthorizeReqTable.Init();
-  }
-
   BluetoothValue v;
   nsAutoString replyError;
   if (!GetDefaultAdapterPath(v, replyError)) {
     // Adapter path is not ready yet
     // Let's do PrepareAdapterRunnable when we receive signal 'AdapterAdded'
   } else {
     // Adapter path has been ready. let's do PrepareAdapterRunnable now
     nsRefPtr<PrepareAdapterRunnable> b = new PrepareAdapterRunnable(v.get_nsString());
@@ -1772,22 +1773,21 @@ BluetoothDBusService::StopInternal()
 
   mConnection = nullptr;
   gThreadConnection = nullptr;
 
   // unref stored DBusMessages before clear the hashtable
   sPairingReqTable.EnumerateRead(UnrefDBusMessages, nullptr);
   sPairingReqTable.Clear();
 
-  sAuthorizeReqTable.EnumerateRead(UnrefDBusMessages, nullptr);
-  sAuthorizeReqTable.Clear();
-
   sIsPairing = 0;
   sConnectedDeviceCount = 0;
 
+  sAuthorizedServiceClass.Clear();
+
   StopDBus();
   return NS_OK;
 }
 
 bool
 BluetoothDBusService::IsEnabledInternal()
 {
   return mEnabled;
@@ -2484,62 +2484,16 @@ BluetoothDBusService::SetPairingConfirma
   dbus_message_unref(msg);
   dbus_message_unref(reply);
 
   sPairingReqTable.Remove(aDeviceAddress);
   DispatchBluetoothReply(aRunnable, v, errorStr);
   return result;
 }
 
-bool
-BluetoothDBusService::SetAuthorizationInternal(
-                                              const nsAString& aDeviceAddress,
-                                              bool aAllow,
-                                              BluetoothReplyRunnable* aRunnable)
-{
-  nsAutoString errorStr;
-  BluetoothValue v = true;
-  DBusMessage *msg;
-
-  if (!sAuthorizeReqTable.Get(aDeviceAddress, &msg)) {
-    BT_WARNING("%s: Couldn't get original request message.", __FUNCTION__);
-    errorStr.AssignLiteral("Couldn't get original request message.");
-    DispatchBluetoothReply(aRunnable, v, errorStr);
-    return false;
-  }
-
-  DBusMessage *reply;
-
-  if (aAllow) {
-    reply = dbus_message_new_method_return(msg);
-  } else {
-    reply = dbus_message_new_error(msg, "org.bluez.Error.Rejected",
-                                   "User rejected authorization");
-  }
-
-  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(aRunnable, v, errorStr);
-    return false;
-  }
-
-  bool result = dbus_func_send(mConnection, nullptr, reply);
-  if (!result) {
-    errorStr.AssignLiteral("Can't send message!");
-  }
-  dbus_message_unref(msg);
-  dbus_message_unref(reply);
-
-  sAuthorizeReqTable.Remove(aDeviceAddress);
-  DispatchBluetoothReply(aRunnable, v, errorStr);
-  return result;
-}
-
 void
 BluetoothDBusService::Connect(const nsAString& aDeviceAddress,
                               const uint16_t aProfileId,
                               BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (aProfileId == BluetoothServiceClass::HANDSFREE) {
--- a/dom/bluetooth/linux/BluetoothDBusService.h
+++ b/dom/bluetooth/linux/BluetoothDBusService.h
@@ -95,20 +95,16 @@ public:
   virtual bool
   SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey,
                      BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
 
   virtual bool
   SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm,
                                  BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
 
-  virtual bool
-  SetAuthorizationInternal(const nsAString& aDeviceAddress, bool aAllow,
-                           BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
-
   virtual void
   Connect(const nsAString& aDeviceAddress,
           const uint16_t aProfileId,
           BluetoothReplyRunnable* aRunnable);
 
   virtual bool
   IsConnected(uint16_t aProfileId) MOZ_OVERRIDE;
 
--- a/dom/messages/SystemMessagePermissionsChecker.jsm
+++ b/dom/messages/SystemMessagePermissionsChecker.jsm
@@ -29,19 +29,16 @@ function debug(aStr) {
 this.SystemMessagePermissionsTable = {
   "activity": { },
   "alarm": {
     "alarms": []
   },
   "bluetooth-dialer-command": {
     "telephony": []
   },
-  "bluetooth-authorize": {
-    "bluetooth": []
-  },
   "bluetooth-cancel": {
     "bluetooth": []
   },
   "bluetooth-pairedstatuschanged": {
     "bluetooth": []
   },
   "bluetooth-a2dp-status-changed": {
     "bluetooth": []
--- a/dom/webidl/BluetoothAdapter.webidl
+++ b/dom/webidl/BluetoothAdapter.webidl
@@ -86,18 +86,16 @@ interface BluetoothAdapter : EventTarget
   [Creator, Throws]
   DOMRequest getConnectedDevices(unsigned short profile);
   [Creator, Throws]
   DOMRequest setPinCode(DOMString deviceAddress, DOMString pinCode);
   [Creator, Throws]
   DOMRequest setPasskey(DOMString deviceAddress, unsigned long passkey);
   [Creator, Throws]
   DOMRequest setPairingConfirmation(DOMString deviceAddress, boolean confirmation);
-  [Creator, Throws]
-  DOMRequest setAuthorization(DOMString deviceAddress, boolean allow);
 
   /**
    * 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.
    *
    * @param deviceAddress Remote device address
    * @param profile 2-octets service UUID