Revert "[Bluetooth] Moved checking privileges to JS layer."
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 5 Nov 2015 06:39:05 +0000 (07:39 +0100)
committerPiotr Kosko <p.kosko@samsung.com>
Fri, 4 Dec 2015 11:18:43 +0000 (12:18 +0100)
This reverts commit 6e2fa04538acf45e71a1d03bc65406057e3af314.

Commit moves also missing privilege checking.
Commit also squashed with
  [Bluetooth] Fixes for checking privileges
  I498c7a9a0eae3236ea71deb119385ae575926bdc

[Verification] Code compiles without errors.

Change-Id: I00e8d529a07df2606f14b74b98820ed4d0587596
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
14 files changed:
src/bluetooth/bluetooth.gyp
src/bluetooth/bluetooth_adapter.cc
src/bluetooth/bluetooth_api.js
src/bluetooth/bluetooth_device.cc
src/bluetooth/bluetooth_gatt_service.cc
src/bluetooth/bluetooth_health_application.cc
src/bluetooth/bluetooth_health_channel.cc
src/bluetooth/bluetooth_health_profile_handler.cc
src/bluetooth/bluetooth_le_adapter.cc
src/bluetooth/bluetooth_le_device.cc
src/bluetooth/bluetooth_privilege.cc [new file with mode: 0644]
src/bluetooth/bluetooth_privilege.h [new file with mode: 0644]
src/bluetooth/bluetooth_service_handler.cc
src/bluetooth/bluetooth_socket.cc

index bc91dc49398b8a2e0b5b089aa8d72de22bf8af4f..72eb206832d188bda084cd2fbf20661a77d0f642 100644 (file)
@@ -27,6 +27,8 @@
         'bluetooth_health_profile_handler.h',
         'bluetooth_instance.cc',
         'bluetooth_instance.h',
+        'bluetooth_privilege.cc',
+        'bluetooth_privilege.h',
         'bluetooth_le_adapter.cc',
         'bluetooth_le_adapter.h',
         'bluetooth_service_handler.cc',
index 29bdaf60b6163d54b660ad99c2ed82cd14d35e75..6d0692d6556e559a8d156c5f941700975eecc712 100755 (executable)
@@ -39,6 +39,7 @@
 #include "bluetooth/bluetooth_class.h"
 #include "bluetooth/bluetooth_device.h"
 #include "bluetooth/bluetooth_instance.h"
+#include "bluetooth/bluetooth_privilege.h"
 #include "bluetooth/bluetooth_socket.h"
 #include "bluetooth/bluetooth_util.h"
 
@@ -456,6 +457,9 @@ bool BluetoothAdapter::is_initialized() const {
 void BluetoothAdapter::SetName(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothAdmin, &out);
+
   const auto callback_handle = util::GetAsyncCallbackHandle(data);
   const auto& args = util::GetArguments(data);
   const auto name = FromJson<std::string>(args, "name");
@@ -513,6 +517,9 @@ void BluetoothAdapter::SetName(const picojson::value& data, picojson::object& ou
 void BluetoothAdapter::SetPowered(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothAdmin, &out);
+
   const auto callback_handle = util::GetAsyncCallbackHandle(data);
   const auto& args = util::GetArguments(data);
   const auto new_powered = FromJson<bool>(args, "powered");
@@ -629,6 +636,9 @@ void BluetoothAdapter::SetPowered(const picojson::value& data, picojson::object&
 void BluetoothAdapter::SetVisible(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothManager, &out);
+
   const auto callback_handle = util::GetAsyncCallbackHandle(data);
   const auto& args = util::GetArguments(data);
   const auto visible = FromJson<bool>(args, "visible");
@@ -771,6 +781,9 @@ void BluetoothAdapter::SetVisible(const picojson::value& data, picojson::object&
 void BluetoothAdapter::DiscoverDevices(const picojson::value& /* data */, picojson::object& out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothGap, &out);
+
   PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
 
   if (!is_initialized_) {
@@ -803,6 +816,9 @@ void BluetoothAdapter::DiscoverDevices(const picojson::value& /* data */, picojs
 void BluetoothAdapter::StopDiscovery(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothGap, &out);
+
   const auto callback_handle = util::GetAsyncCallbackHandle(data);
 
   PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
@@ -851,6 +867,9 @@ void BluetoothAdapter::StopDiscovery(const picojson::value& data, picojson::obje
 void BluetoothAdapter::GetKnownDevices(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothGap, &out);
+
   const auto callback_handle = util::GetAsyncCallbackHandle(data);
 
   auto get_known_devices = [this](const std::shared_ptr<picojson::value>& response) -> void {
@@ -903,6 +922,9 @@ void BluetoothAdapter::GetKnownDevices(const picojson::value& data, picojson::ob
 void BluetoothAdapter::GetDevice(const picojson::value& data, picojson::object&  out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothGap, &out);
+
   const auto callback_handle = util::GetAsyncCallbackHandle(data);
   const auto& args = util::GetArguments(data);
 
@@ -1005,6 +1027,9 @@ class BondingHandler {
 void BluetoothAdapter::CreateBonding(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothGap, &out);
+
   const auto callback_handle = util::GetAsyncCallbackHandle(data);
   const auto& args = util::GetArguments(data);
 
@@ -1127,6 +1152,9 @@ void BluetoothAdapter::DestroyBonding(const picojson::value& data, picojson::obj
 {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothGap, &out);
+
   const auto callback_handle = util::GetAsyncCallbackHandle(data);
   const auto& args = util::GetArguments(data);
 
@@ -1242,6 +1270,9 @@ void BluetoothAdapter::DestroyBonding(const picojson::value& data, picojson::obj
 void BluetoothAdapter::RegisterRFCOMMServiceByUUID(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothSpp, &out);
+
   const auto callback_handle = util::GetAsyncCallbackHandle(data);
   const auto& args = util::GetArguments(data);
 
index 36e8fbec6c3cac3d6c393530afad91944b2eb927..5628a8bb04dd1e7fc6cf1a8acedefffc80ff6422 100755 (executable)
@@ -18,7 +18,7 @@ var T = xwalk.utils.type;
 var Converter = xwalk.utils.converter;
 var AV = xwalk.utils.validator;
 var Privilege = xwalk.utils.privilege;
-
+var privUtils_ = xwalk.utils;
 var native = new xwalk.utils.NativeManager(extension);
 
 // class BluetoothClassDeviceMajor /////////////////////////////////////////
@@ -412,24 +412,28 @@ var BluetoothClass = function(data) {
     });
 };
 
-BluetoothClass.prototype.hasService = function() {
-    console.log('Entered BluetoothClass.hasService()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_GAP);
+var BluetoothClass_hasService = function() {
+  console.log('Entered BluetoothClass.hasService()');
+  privUtils_.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_GAP);
 
-    var args = AV.validateMethod(arguments, [
-        {
-            name : 'service',
-            type : AV.Types.UNSIGNED_LONG
-        }
-    ]);
+  var args = AV.validateMethod(arguments, [
+      {
+          name : 'service',
+          type : AV.Types.UNSIGNED_LONG
+      }
+  ]);
 
-    var size = this.services.length;
-    for (var i = 0; i < size; i++) {
-        if (this.services[i] === args.service) {
-            return true;
-        }
-    }
-    return false;
+  var size = this.services.length;
+  for (var i = 0; i < size; i++) {
+      if (this.services[i] === args.service) {
+          return true;
+      }
+  }
+  return false;
+};
+
+BluetoothClass.prototype.hasService = function() {
+    return BluetoothClass_hasService.apply(this, arguments);
 };
 
 // class BluetoothSocket ////////////////////////////////////////////////////
@@ -494,7 +498,6 @@ var BluetoothSocket = function(data) {
 
 BluetoothSocket.prototype.writeData = function() {
     console.log('Entered BluetoothSocket.writeData()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_SPP);
 
     var args = AV.validateMethod(arguments, [
         {
@@ -520,7 +523,6 @@ BluetoothSocket.prototype.writeData = function() {
 
 BluetoothSocket.prototype.readData = function() {
     console.log('Entered BluetoothSocket.readData()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_SPP);
 
     var callArgs = {
         id : this._id
@@ -537,7 +539,6 @@ BluetoothSocket.prototype.readData = function() {
 
 BluetoothSocket.prototype.close = function() {
     console.log('Entered BluetoothSocket.close()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_SPP);
 
     if (_BLUETOOTH_SOCKET_STATE_CLOSED !== this.state) {
         var callArgs = {
@@ -609,8 +610,6 @@ var BluetoothLEDevice = function(data) {
 
 BluetoothLEDevice.prototype.connect = function() {
     console.log('Entered BluetoothLEDevice.connect()');
-
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
     var args = AV.validateMethod(arguments, [
     {
         name : 'successCallback',
@@ -634,13 +633,14 @@ BluetoothLEDevice.prototype.connect = function() {
         }
     };
     // Errors are handled by error callback
-    native.call('BluetoothLEDevice_connect', {address : this.address}, callback);
+    var result = native.call('BluetoothLEDevice_connect', {address : this.address}, callback);
+    if (native.isFailure(result)) {
+      throw native.getErrorObject(result);
+    }
 };
 
 BluetoothLEDevice.prototype.disconnect = function() {
     console.log('Entered BluetoothLEDevice.disconnect()');
-
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
     var args = AV.validateMethod(arguments, [
     {
         name : 'successCallback',
@@ -671,9 +671,6 @@ BluetoothLEDevice.prototype.disconnect = function() {
 
 BluetoothLEDevice.prototype.getService = function() {
     console.log('Entered BluetoothLEDevice.getService()');
-
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
-
     var args = AV.validateMethod(arguments, [
         {
             name: 'uuid',
@@ -687,7 +684,6 @@ BluetoothLEDevice.prototype.getService = function() {
     };
 
     var result = native.callSync('BluetoothLEDevice_getService', callArgs);
-
     if (native.isFailure(result)) {
         throw native.getErrorObject(result);
     } else {
@@ -697,7 +693,6 @@ BluetoothLEDevice.prototype.getService = function() {
 
 BluetoothLEDevice.prototype.addConnectStateChangeListener = function() {
     console.log('Entered BluetoothLEDevice.addConnectStateChangeListener()');
-
     var args = AV.validateMethod(arguments, [
         {
             name: 'listener',
@@ -798,7 +793,6 @@ var BluetoothDevice = function(data) {
 
 BluetoothDevice.prototype.connectToServiceByUUID = function() {
     console.log('Entered BluetoothDevice.connectToServiceByUUID()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_SPP);
 
     var args = AV.validateMethod(arguments, [
         {
@@ -829,9 +823,10 @@ BluetoothDevice.prototype.connectToServiceByUUID = function() {
         }
     };
 
-    // The native function BluetoothDevice_connectToServiceByUUID always returns success
-    // Errors are handled by error callback
-    native.call('BluetoothDevice_connectToServiceByUUID', callArgs, callback);
+    var result = native.call('BluetoothDevice_connectToServiceByUUID', callArgs, callback);
+    if (native.isFailure(result)) {
+      throw native.getErrorObject(result);
+    }
 };
 
 // class BluetoothServiceHandler ////////////////////////////////////////////////////
@@ -900,8 +895,6 @@ var BluetoothServiceHandler = function(data) {
 
 BluetoothServiceHandler.prototype.unregister = function() {
     console.log('Entered BluetoothServiceHandler.unregister()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_SPP);
-
     var args = AV.validateMethod(arguments, [
         {
             name : 'successCallback',
@@ -929,9 +922,10 @@ BluetoothServiceHandler.prototype.unregister = function() {
         }
     };
 
-    // native.call does not inform if call results in failure
-    // Errors are handled by error callback
-    native.call('BluetoothServiceHandler_unregister', callArgs, callback);
+    var result = native.call('BluetoothServiceHandler_unregister', callArgs, callback);
+    if (native.isFailure(result)) {
+      throw native.getErrorObject(result);
+    }
 
     _bluetoothServiceListeners.removeListener(this.uuid);
 };
@@ -997,8 +991,6 @@ var BluetoothHealthApplication = function(data) {
 
 BluetoothHealthApplication.prototype.unregister = function() {
     console.log('Entered BluetoothHealthApplication.unregister()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_HEALTH);
-
     var args = AV.validateMethod(arguments, [
         {
             name : 'successCallback',
@@ -1024,9 +1016,10 @@ BluetoothHealthApplication.prototype.unregister = function() {
         }
     };
 
-    // native.call does not inform if call results in failure
-    // Errors are handled by error callback
-    native.call('BluetoothHealthApplication_unregister', callArgs, callback);
+    var result = native.call('BluetoothHealthApplication_unregister', callArgs, callback);
+    if (native.isFailure(result)) {
+      throw native.getErrorObject(result);
+    }
 
     _bluetoothHealthApplicationListeners.removeListener(this._id);
 };
@@ -1055,7 +1048,6 @@ BluetoothHealthProfileHandler.prototype.constructor = BluetoothProfileHandler;
 
 BluetoothHealthProfileHandler.prototype.registerSinkApplication = function() {
     console.log('Entered BluetoothHealthProfileHandler.registerSinkApplication()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_HEALTH);
 
     var args = AV.validateMethod(arguments, [
         {
@@ -1091,14 +1083,14 @@ BluetoothHealthProfileHandler.prototype.registerSinkApplication = function() {
         }
     };
 
-    // native.call does not inform if call results in failure
-    // Errors are handled by error callback
-    native.call('BluetoothHealthProfileHandler_registerSinkApp', callArgs, callback);
+    var result = native.call('BluetoothHealthProfileHandler_registerSinkApp', callArgs, callback);
+    if (native.isFailure(result)) {
+      throw native.getErrorObject(result);
+    }
 };
 
 BluetoothHealthProfileHandler.prototype.connectToSource = function() {
     console.log('Entered BluetoothHealthProfileHandler.connectToSource()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_HEALTH);
 
     var args = AV.validateMethod(arguments, [
         {
@@ -1139,9 +1131,10 @@ BluetoothHealthProfileHandler.prototype.connectToSource = function() {
         }
     };
 
-    // native.call does not inform if call results in failure
-    // Errors are handled by error callback
-    native.call('BluetoothHealthProfileHandler_connectToSource', callArgs, callback);
+    var result = native.call('BluetoothHealthProfileHandler_connectToSource', callArgs, callback);
+    if (native.isFailure(result)) {
+      throw native.getErrorObject(result);
+    }
 };
 
 // class BluetoothHealthChannel ////////////////////////////////////////////////////
@@ -1165,7 +1158,6 @@ var BluetoothHealthChannel = function(data) {
 
 BluetoothHealthChannel.prototype.close = function() {
     console.log('Entered BluetoothHealthChannel.close()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_HEALTH);
 
     if (this.isConnected) {
         var callArgs = {
@@ -1185,8 +1177,6 @@ BluetoothHealthChannel.prototype.close = function() {
 
 BluetoothHealthChannel.prototype.sendData = function() {
     console.log('Entered BluetoothHealthChannel.sendData()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_HEALTH);
-
     var args = AV.validateMethod(arguments, [
         {
             name : 'data',
@@ -1234,35 +1224,45 @@ function _BluetoothHealthChannelChangeCallback(event) {
     }
 }
 
-BluetoothHealthChannel.prototype.setListener = function() {
-    console.log('Entered BluetoothHealthChannel.setListener()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_HEALTH);
+var BluetoothHealthChannel_setListener = function() {
+  console.log('Entered BluetoothHealthChannel.setListener()');
+  privUtils_.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_HEALTH);
+  var args = AV.validateMethod(arguments, [
+      {
+          name : 'changeCallback',
+          type : AV.Types.LISTENER,
+          values : ['onmessage', 'onclose']
+      }
+  ]);
 
-    var args = AV.validateMethod(arguments, [
-        {
-            name : 'changeCallback',
-            type : AV.Types.LISTENER,
-            values : ['onmessage', 'onclose']
-        }
-    ]);
+  if (T.isEmptyObject(_healthListeners)) {
+      native.addListener('BluetoothHealthChannelChangeCallback',
+              _BluetoothHealthChannelChangeCallback);
+  }
+  _healthListeners[this._id] = args.changeCallback;
+};
 
-    if (T.isEmptyObject(_healthListeners)) {
-        native.addListener('BluetoothHealthChannelChangeCallback',
-                _BluetoothHealthChannelChangeCallback);
-    }
-    _healthListeners[this._id] = args.changeCallback;
+
+BluetoothHealthChannel.prototype.setListener = function() {
+    BluetoothHealthChannel_setListener.apply(this, arguments);
 };
 
-BluetoothHealthChannel.prototype.unsetListener  = function() {
-    console.log('Entered BluetoothHealthChannel.unsetListener ()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_HEALTH);
+var BluetoothHealthChannel_unsetListener  = function() {
+  console.log('Entered BluetoothHealthChannel.unsetListener ()');
+  if (T.isEmptyObject(_healthListeners)) {
+    privUtils_.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_HEALTH);
+  }
 
-    delete _healthListeners[this._id];
+  delete _healthListeners[this._id];
 
-    if (T.isEmptyObject(_healthListeners)) {
-        native.removeListener('BluetoothHealthChannelChangeCallback',
-                _BluetoothHealthChannelChangeCallback);
-    }
+  if (T.isEmptyObject(_healthListeners)) {
+      native.removeListener('BluetoothHealthChannelChangeCallback',
+              _BluetoothHealthChannelChangeCallback);
+  }
+};
+
+BluetoothHealthChannel.prototype.unsetListener  = function() {
+  BluetoothHealthChannel_unsetListener.apply(this, arguments);
 };
 
 
@@ -1375,9 +1375,6 @@ var BluetoothLEAdapter = function() {
 
 BluetoothLEAdapter.prototype.startScan = function() {
   console.log('Entered BluetoothLEAdapter.startScan()');
-
-  xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
-
   var args = AV.validateMethod(arguments, [{
     name: 'successCallback',
     type: AV.Types.FUNCTION
@@ -1389,7 +1386,6 @@ BluetoothLEAdapter.prototype.startScan = function() {
   }]);
 
   var result = native.callSync('BluetoothLEAdapter_startScan', {});
-
   if (native.isFailure(result)) {
     throw native.getErrorObject(result);
   }
@@ -1400,12 +1396,9 @@ BluetoothLEAdapter.prototype.startScan = function() {
 BluetoothLEAdapter.prototype.stopScan = function() {
   console.log('Entered BluetoothLEAdapter.stopScan()');
 
-  xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
-
   _bleScanListener.removeListener();
 
   var result = native.callSync('BluetoothLEAdapter_stopScan', {});
-
   if (native.isFailure(result)) {
     throw native.getErrorObject(result);
   }
@@ -1424,9 +1417,6 @@ var _BluetoothAdvertisingMode = {
 
 BluetoothLEAdapter.prototype.startAdvertise = function() {
   console.log('Entered BluetoothLEAdapter.startAdvertise()');
-
-  xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
-
   var args = AV.validateMethod(arguments, [{
     name: 'advertiseData',
     type: AV.Types.PLATFORM_OBJECT,
@@ -1475,8 +1465,6 @@ BluetoothLEAdapter.prototype.startAdvertise = function() {
 BluetoothLEAdapter.prototype.stopAdvertise = function() {
   console.log('Entered BluetoothLEAdapter.stopAdvertise()');
 
-  xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
-
   _bleAdvertiseListener.removeListener();
   var result = native.callSync('BluetoothLEAdapter_stopAdvertise', {});
 
@@ -1637,9 +1625,6 @@ var BluetoothGATTCharacteristic = function(data, address) {
 
   this.readValue = function() {
       console.log('Entered BluetoothGATTCharacteristic.readValue()');
-
-      xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
-
       var args = AV.validateMethod(arguments, [{
         name: 'successCallback',
         type: AV.Types.FUNCTION
@@ -1670,9 +1655,6 @@ var BluetoothGATTCharacteristic = function(data, address) {
 
     this.writeValue = function() {
       console.log('Entered BluetoothGATTCharacteristic.writeValue()');
-
-      xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
-
       var args = AV.validateMethod(arguments, [{
         name: 'value',
         type: AV.Types.ARRAY,
@@ -1706,39 +1688,41 @@ var BluetoothGATTCharacteristic = function(data, address) {
       }
     };
 
-  this.addValueChangeListener = function() {
-    console.log('Entered BluetoothGATTCharacteristic.addValueChangeListener()');
-
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
+    var addValueChangeListener = function() {
+      console.log('Entered BluetoothGATTCharacteristic.addValueChangeListener()');
+      privUtils_.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
+      var args = AV.validateMethod(arguments, [{
+        name: 'callback',
+        type: AV.Types.FUNCTION
+      }]);
 
-    var args = AV.validateMethod(arguments, [{
-      name: 'callback',
-      type: AV.Types.FUNCTION
-    }]);
+      var callArgs = { handle: handle_, address : address_ };
 
-    var callArgs = { handle: handle_, address : address_ };
+      var callback = function(event) {
+        if (event.handle === handle_) {
+          args.callback(toByteArray(native.getResultObject(event)));
+        }
+      };
 
-    var callback = function(event) {
-      if (event.handle === handle_) {
-        args.callback(toByteArray(native.getResultObject(event)));
-      }
+      return _bluetoothGATTCharacteristicListener.addListener(callback, callArgs);
     };
 
-    return _bluetoothGATTCharacteristicListener.addListener(callback, callArgs);
-  };
+    this.addValueChangeListener = function() {
+      return addValueChangeListener.apply(this, arguments);
+    };
 
-  this.removeValueChangeListener = function() {
-    console.log('Entered BluetoothGATTCharacteristic.removeValueChangeListener()');
+    this.removeValueChangeListener = function() {
+      console.log('Entered BluetoothGATTCharacteristic.removeValueChangeListener()');
 
-    var args = AV.validateMethod(arguments, [{
-      name: 'watchID',
-      type: AV.Types.LONG
-    }]);
+      var args = AV.validateMethod(arguments, [{
+        name: 'watchID',
+        type: AV.Types.LONG
+      }]);
 
-    var callArgs = { handle: handle_, address : address_ };
+      var callArgs = { handle: handle_, address : address_ };
 
-    return _bluetoothGATTCharacteristicListener.removeListener(args.watchID, callArgs);
-  };
+      return _bluetoothGATTCharacteristicListener.removeListener(args.watchID, callArgs);
+    };
 };
 
 
@@ -1855,9 +1839,6 @@ var BluetoothGATTDescriptor = function(data, address) {
 
   this.readValue = function() {
     console.log('Entered BluetoothGATTDescriptor.readValue()');
-
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
-
     var args = AV.validateMethod(arguments, [{
       name: 'successCallback',
       type: AV.Types.FUNCTION
@@ -1888,9 +1869,6 @@ var BluetoothGATTDescriptor = function(data, address) {
 
   this.writeValue = function() {
     console.log('Entered BluetoothGATTDescriptor.writeValue()');
-
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
-
     var args = AV.validateMethod(arguments, [{
       name: 'value',
       type: AV.Types.ARRAY,
@@ -1995,8 +1973,6 @@ var BluetoothAdapter = function() {
 
 BluetoothAdapter.prototype.setName = function() {
     console.log('Entered BluetoothAdapter.setName()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
-
     var args = AV.validateMethod(arguments, [
         {
             name : 'name',
@@ -2028,15 +2004,14 @@ BluetoothAdapter.prototype.setName = function() {
         }
     };
 
-    // native.call does not inform if call results in failure
-    // Errors are handled by error callback
-    native.call('BluetoothAdapter_setName', callArgs, callback);
+    var result = native.call('BluetoothAdapter_setName', callArgs, callback);
+    if (native.isFailure(result)) {
+      throw native.getErrorObject(result);
+    }
 };
 
 BluetoothAdapter.prototype.setPowered = function() {
     console.log('Entered BluetoothAdapter.setPowered()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
-
     var args = AV.validateMethod(arguments, [
         {
             name : 'powered',
@@ -2068,17 +2043,16 @@ BluetoothAdapter.prototype.setPowered = function() {
         }
     };
 
-    // native.call does not inform if call results in failure
-    // Errors are handled by error callback
-    native.call('BluetoothAdapter_setPowered', callArgs, callback);
+    var result = native.call('BluetoothAdapter_setPowered', callArgs, callback);
+    if (native.isFailure(result)) {
+      throw native.getErrorObject(result);
+    }
 };
 
 
 // This method is deprecated since Tizen 2.3 and will be removed in Tizen 3.0.
 BluetoothAdapter.prototype.setVisible = function() {
     console.log('Entered BluetoothAdapter.setVisible()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTHMANAGER);
-
     var args = AV.validateMethod(arguments, [
         {
             name : 'visible',
@@ -2124,9 +2098,10 @@ BluetoothAdapter.prototype.setVisible = function() {
         }
     };
 
-    // native.call does not inform if call results in failure
-    // Errors are handled by error callback
-    native.call('BluetoothAdapter_setVisible', callArgs, callback);
+    var result = native.call('BluetoothAdapter_setVisible', callArgs, callback);
+    if (native.isFailure(result)) {
+      throw native.getErrorObject(result);
+    }
 };
 
 var _listener;
@@ -2236,8 +2211,6 @@ function _BluetoothDiscoverDevicesErrorCallback(event) {
 
 BluetoothAdapter.prototype.discoverDevices = function() {
     console.log('Entered BluetoothAdapter.discoverDevices()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_GAP);
-
     var args = AV.validateMethod(arguments, [
         {
             name : 'successCallback',
@@ -2272,8 +2245,6 @@ BluetoothAdapter.prototype.discoverDevices = function() {
 
 BluetoothAdapter.prototype.stopDiscovery = function() {
     console.log('Entered BluetoothAdapter.stopDiscovery()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_GAP);
-
     var args = AV.validateMethod(arguments, [
         {
             name : 'successCallback',
@@ -2297,15 +2268,14 @@ BluetoothAdapter.prototype.stopDiscovery = function() {
         }
     };
 
-    // native.call does not inform if call results in failure
-    // Errors are handled by error callback
-    native.call('BluetoothAdapter_stopDiscovery', {}, callback);
+    var result = native.call('BluetoothAdapter_stopDiscovery', {}, callback);
+    if (native.isFailure(result)) {
+      throw native.getErrorObject(result);
+    }
 };
 
 BluetoothAdapter.prototype.getKnownDevices = function() {
     console.log('Entered BluetoothAdapter.getKnownDevices()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_GAP);
-
     var args = AV.validateMethod(arguments, [
         {
             name : 'successCallback',
@@ -2332,15 +2302,14 @@ BluetoothAdapter.prototype.getKnownDevices = function() {
         }
     };
 
-    // native.call does not inform if call results in failure
-    // Errors are handled by error callback
-    native.call('BluetoothAdapter_getKnownDevices', {}, callback);
+    var result = native.call('BluetoothAdapter_getKnownDevices', {}, callback);
+    if (native.isFailure(result)) {
+      throw native.getErrorObject(result);
+    }
 };
 
 BluetoothAdapter.prototype.getDevice = function() {
     console.log('Entered BluetoothAdapter.getDevice()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_GAP);
-
     var args = AV.validateMethod(arguments, [
         {
             name : 'address',
@@ -2366,15 +2335,14 @@ BluetoothAdapter.prototype.getDevice = function() {
         }
     };
 
-    // native.call does not inform if call results in failure
-    // Errors are handled by error callback
-    native.call('BluetoothAdapter_getDevice', {address : args.address}, callback);
+    var result = native.call('BluetoothAdapter_getDevice', {address : args.address}, callback);
+    if (native.isFailure(result)) {
+      throw native.getErrorObject(result);
+    }
 };
 
 BluetoothAdapter.prototype.createBonding = function() {
     console.log('Entered BluetoothAdapter.createBonding()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_GAP);
-
     var args = AV.validateMethod(arguments, [
         {
             name : 'address',
@@ -2406,15 +2374,14 @@ BluetoothAdapter.prototype.createBonding = function() {
         }
     };
 
-    // native.call does not inform if call results in failure
-    // Errors are handled by error callback
-    native.call('BluetoothAdapter_createBonding', callArgs, callback);
+    var result = native.call('BluetoothAdapter_createBonding', callArgs, callback);
+    if (native.isFailure(result)) {
+      throw native.getErrorObject(result);
+    }
 };
 
 BluetoothAdapter.prototype.destroyBonding = function() {
     console.log('Entered BluetoothAdapter.destroyBonding()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_GAP);
-
     var args = AV.validateMethod(arguments, [
         {
             name : 'address',
@@ -2446,15 +2413,14 @@ BluetoothAdapter.prototype.destroyBonding = function() {
         }
     };
 
-    // native.call does not inform if call results in failure
-    // Errors are handled by error callback
-    native.call('BluetoothAdapter_destroyBonding', callArgs, callback);
+    var result = native.call('BluetoothAdapter_destroyBonding', callArgs, callback);
+    if (native.isFailure(result)) {
+      throw native.getErrorObject(result);
+    }
 };
 
 BluetoothAdapter.prototype.registerRFCOMMServiceByUUID = function() {
     console.log('Entered BluetoothAdapter.registerRFCOMMServiceByUUID()');
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_SPP);
-
     var args = AV.validateMethod(arguments, [
         {
             name : 'uuid',
@@ -2491,9 +2457,10 @@ BluetoothAdapter.prototype.registerRFCOMMServiceByUUID = function() {
         }
     };
 
-    // native.call does not inform if call results in failure
-    // Errors are handled by error callback
-    native.call('BluetoothAdapter_registerRFCOMMServiceByUUID', callArgs, callback);
+    var result = native.call('BluetoothAdapter_registerRFCOMMServiceByUUID', callArgs, callback);
+    if (native.isFailure(result)) {
+      throw native.getErrorObject(result);
+    }
 };
 
 BluetoothAdapter.prototype.getBluetoothProfileHandler = function() {
@@ -2545,20 +2512,27 @@ var BluetoothManager = function() {
     });
 };
 
+var BluetoothManager_getDefaultAdapter = function() {
+  privUtils_.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_GAP);
+
+  return new BluetoothAdapter();
+};
+
+
 BluetoothManager.prototype.getDefaultAdapter = function() {
     console.log('Entered BluetoothManager.getDefaultAdapter()');
+    return BluetoothManager_getDefaultAdapter();
+};
 
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_GAP);
+var BluetoothManager_getLEAdapter = function() {
+  privUtils_.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
 
-    return new BluetoothAdapter();
+  return new BluetoothLEAdapter();
 };
 
 BluetoothManager.prototype.getLEAdapter = function() {
     console.log('Entered BluetoothManager.getLEAdapter()');
-
-    xwalk.utils.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_ADMIN);
-
-    return new BluetoothLEAdapter();
+    return BluetoothManager_getLEAdapter();
 };
 // exports ///////////////////////////////////////////////////////////////////
 exports = new BluetoothManager();
index 0cf8c1b0c00aa6c3130390a7f9b18d9b50cd4067..51834e29e0cdc46a50155fd207791f60f99d21ca 100755 (executable)
@@ -23,6 +23,7 @@
 
 #include "bluetooth_adapter.h"
 #include "bluetooth_class.h"
+#include "bluetooth_privilege.h"
 #include "bluetooth_util.h"
 
 namespace extension {
@@ -104,6 +105,9 @@ void BluetoothDevice::ToJson(bt_adapter_device_discovery_info_s *info, picojson:
 void BluetoothDevice::ConnectToServiceByUUID(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothSpp, &out);
+
   const auto& args = util::GetArguments(data);
 
   adapter_.ConnectToServiceByUUID(FromJson<std::string>(args, "address"),
index a6c95b10d2f333c7ec8931eaea385e791735a3f1..421d5aa092d96bb1a0b203ed57a81184e647c765 100755 (executable)
@@ -26,6 +26,7 @@
 
 #include "bluetooth/bluetooth_instance.h"
 #include "bluetooth/bluetooth_util.h"
+#include "bluetooth/bluetooth_privilege.h"
 
 namespace extension {
 namespace bluetooth {
@@ -333,6 +334,8 @@ PlatformResult BluetoothGATTService::GetCharacteristicsHelper(bt_gatt_h handle,
 void BluetoothGATTService::ReadValue(const picojson::value& args,
                                      picojson::object& out) {
   LoggerD("Entered");
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothAdmin, &out);
 
   const std::string& address = args.get("address").get<std::string>();
   if (!IsStillConnected(address)) {
@@ -405,6 +408,8 @@ void BluetoothGATTService::ReadValue(const picojson::value& args,
 void BluetoothGATTService::WriteValue(const picojson::value& args,
                                      picojson::object& out) {
   LoggerD("Entered");
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothAdmin, &out);
 
   const std::string& address = args.get("address").get<std::string>();
   if (!IsStillConnected(address)) {
index 457e5d58a4cd3b1313ad5758c0a3acff9d77044f..dec2a6df96fa251f019a242310ec46a330eaa080 100755 (executable)
@@ -22,6 +22,7 @@
 #include "common/tools.h"
 
 #include "bluetooth_health_profile_handler.h"
+#include "bluetooth_privilege.h"
 #include "bluetooth_util.h"
 
 namespace extension {
@@ -43,6 +44,9 @@ BluetoothHealthApplication::BluetoothHealthApplication(
 void BluetoothHealthApplication::Unregister(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothHealth, &out);
+
   const auto& args = util::GetArguments(data);
 
   handler_.UnregisterSinkAppAsync(FromJson<std::string>(args, "id"),
index f6c7f65d49209b33e92b4457b175a6b6bc40d629..6ee27265245836cebc781c639efa2ef8268d0c20 100755 (executable)
@@ -24,6 +24,7 @@
 #include "common/tools.h"
 
 #include "bluetooth_device.h"
+#include "bluetooth_privilege.h"
 #include "bluetooth_util.h"
 
 namespace extension {
@@ -43,6 +44,9 @@ const std::string kId = "_id";
 void BluetoothHealthChannel::Close(const picojson::value& data , picojson::object& out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothHealth, &out);
+
   const auto& args = util::GetArguments(data);
 
   unsigned int channel = common::stol(FromJson<std::string>(args, "channel"));
@@ -62,6 +66,9 @@ void BluetoothHealthChannel::Close(const picojson::value& data , picojson::objec
 void BluetoothHealthChannel::SendData(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothHealth, &out);
+
   const auto& args = util::GetArguments(data);
 
   unsigned int channel = common::stol(FromJson<std::string>(args, "channel"));
index eb2be4fb1872b404ec66e2e82cab9c511f3e5f66..ab0fe0b0a073c710d6495a26bbe8a06fbb1bf83e 100755 (executable)
@@ -26,6 +26,7 @@
 #include "bluetooth/bluetooth_instance.h"
 #include "bluetooth/bluetooth_health_application.h"
 #include "bluetooth/bluetooth_health_channel.h"
+#include "bluetooth/bluetooth_privilege.h"
 #include "bluetooth/bluetooth_util.h"
 
 namespace extension {
@@ -228,6 +229,9 @@ void BluetoothHealthProfileHandler::OnDataReceived(unsigned int channel,
 void BluetoothHealthProfileHandler::RegisterSinkApp(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothHealth, &out);
+
   const auto& args = util::GetArguments(data);
   const auto data_type = static_cast<short>(FromJson<double>(args, "dataType"));
   const auto& name = FromJson<std::string>(args, "name");
@@ -290,6 +294,9 @@ void BluetoothHealthProfileHandler::RegisterSinkApp(const picojson::value& data,
 void BluetoothHealthProfileHandler::ConnectToSource(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothHealth, &out);
+
   const auto& args = util::GetArguments(data);
   const auto& address = FromJson<std::string>(args, "address");
   const auto& app_id = FromJson<std::string>(args, "appId");
index 2691cf45c307f1e877cac4906c88f25b767d2f97..9fd02ad4d545c55209070e4070ed5c83c487b0bf 100755 (executable)
@@ -22,6 +22,7 @@
 #include "bluetooth/bluetooth_instance.h"
 #include "bluetooth/bluetooth_le_device.h"
 #include "bluetooth/bluetooth_util.h"
+#include "bluetooth/bluetooth_privilege.h"
 
 namespace extension {
 namespace bluetooth {
@@ -422,6 +423,8 @@ BluetoothLEAdapter::~BluetoothLEAdapter() {
 
 void BluetoothLEAdapter::StartScan(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothAdmin, &out);
 
   int ret = bt_adapter_le_start_scan(OnScanResult, this);
 
@@ -449,6 +452,8 @@ void BluetoothLEAdapter::StartScan(const picojson::value& data, picojson::object
 
 void BluetoothLEAdapter::StopScan(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothAdmin, &out);
 
   int ret = bt_adapter_le_stop_scan();
 
@@ -464,6 +469,8 @@ void BluetoothLEAdapter::StopScan(const picojson::value& data, picojson::object&
 
 void BluetoothLEAdapter::StartAdvertise(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothAdmin, &out);
 
   const auto& json_advertise_data = data.get("advertiseData");
   const auto& json_packet_type = data.get("packetType");
@@ -674,6 +681,8 @@ void BluetoothLEAdapter::StartAdvertise(const picojson::value& data, picojson::o
 
 void BluetoothLEAdapter::StopAdvertise(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothAdmin, &out);
 
   if (nullptr != bt_advertiser_) {
     int ret = bt_adapter_le_stop_advertising(bt_advertiser_);
index 6d44b0da6f859ed4c8378b067b75dac4579775e9..24037505fe7965e69d6de320637be59d46c21949 100755 (executable)
@@ -19,6 +19,7 @@
 
 #include "bluetooth/bluetooth_instance.h"
 #include "bluetooth/bluetooth_util.h"
+#include "bluetooth/bluetooth_privilege.h"
 
 #include "common/converter.h"
 #include "common/logger.h"
@@ -302,6 +303,8 @@ PlatformResult BluetoothLEDevice::ToJson(
 void BluetoothLEDevice::Connect(const picojson::value& data,
                                 picojson::object& out) {
   LoggerD("Entered");
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothAdmin, &out);
 
   const auto callback_handle = util::GetAsyncCallbackHandle(data);
   const auto& args = util::GetArguments(data);
@@ -342,6 +345,8 @@ void BluetoothLEDevice::Connect(const picojson::value& data,
 void BluetoothLEDevice::Disconnect(const picojson::value& data,
                                    picojson::object& out) {
   LoggerD("Entered");
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothAdmin, &out);
 
   const auto callback_handle = util::GetAsyncCallbackHandle(data);
   const auto& args = util::GetArguments(data);
@@ -386,6 +391,8 @@ void BluetoothLEDevice::Disconnect(const picojson::value& data,
 void BluetoothLEDevice::GetService(const picojson::value& data,
                                    picojson::object& out) {
   LoggerD("Entered");
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothAdmin, &out);
 
   const auto& args = util::GetArguments(data);
 
diff --git a/src/bluetooth/bluetooth_privilege.cc b/src/bluetooth/bluetooth_privilege.cc
new file mode 100644 (file)
index 0000000..78a1f90
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include "bluetooth_privilege.h"
+
+namespace extension {
+namespace bluetooth {
+
+namespace Privilege {
+const std::string kBluetoothAdmin = "http://tizen.org/privilege/bluetooth.admin";
+const std::string kBluetoothManager = "http://tizen.org/privilege/bluetoothmanager";
+const std::string kBluetoothGap = "http://tizen.org/privilege/bluetooth.gap";
+const std::string kBluetoothSpp = "http://tizen.org/privilege/bluetooth.spp";
+const std::string kBluetoothHealth = "http://tizen.org/privilege/bluetooth.health";
+const std::string kBluetooth = "http://tizen.org/privilege/bluetooth";
+} // namespace Privilege
+
+} // namespace bluetooth
+} // namespace extension
diff --git a/src/bluetooth/bluetooth_privilege.h b/src/bluetooth/bluetooth_privilege.h
new file mode 100644 (file)
index 0000000..1c0ccff
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#ifndef BLUETOOTH_BLUETOOTH_PRIVILEGE_H_
+#define BLUETOOTH_BLUETOOTH_PRIVILEGE_H_
+
+#include <string>
+
+namespace extension {
+namespace bluetooth {
+
+namespace Privilege {
+
+extern const std::string kBluetoothAdmin;
+extern const std::string kBluetoothManager;
+extern const std::string kBluetoothGap;
+extern const std::string kBluetoothSpp;
+extern const std::string kBluetoothHealth;
+extern const std::string kBluetooth;
+
+} // namespace Privilege
+
+} // namespace bluetooth
+} // namespace extension
+
+#endif // BLUETOOTH_BLUETOOTH_PRIVILEGE_H_
index d9b6e1ebf00f6b4c4a3ae3b4c86d71cc66a412ce..e79c66a36b8088544d4ac2b011a2c5e39644ed2b 100755 (executable)
@@ -22,6 +22,7 @@
 #include "common/tools.h"
 
 #include "bluetooth_adapter.h"
+#include "bluetooth_privilege.h"
 #include "bluetooth_util.h"
 
 namespace extension {
@@ -36,6 +37,9 @@ BluetoothServiceHandler::BluetoothServiceHandler(BluetoothAdapter& adapter)
 void BluetoothServiceHandler::Unregister(const picojson::value& data, picojson::object& out) {
   LoggerD("Entered");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothSpp, &out);
+
   const auto& args = util::GetArguments(data);
 
   adapter_.UnregisterUUID(FromJson<std::string>(args, "uuid"),
index 5647db7c43103a45224ac497f187f7ccada225af..dad2a96b5e81865734102d24bf8177f8d9fdc00c 100755 (executable)
@@ -25,6 +25,7 @@
 
 #include "bluetooth_adapter.h"
 #include "bluetooth_device.h"
+#include "bluetooth_privilege.h"
 #include "bluetooth_util.h"
 
 namespace extension {
@@ -50,6 +51,9 @@ BluetoothSocket::BluetoothSocket(BluetoothAdapter& adapter)
 void BluetoothSocket::WriteData(const picojson::value& data, picojson::object& out) {
   LoggerD("Enter");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothSpp, &out);
+
   const auto& args = util::GetArguments(data);
 
   int socket = common::stol(FromJson<std::string>(args, "id"));
@@ -75,6 +79,9 @@ void BluetoothSocket::WriteData(const picojson::value& data, picojson::object& o
 void BluetoothSocket::ReadData(const picojson::value& data, picojson::object& out) {
   LoggerD("Enter");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothSpp, &out);
+
   const auto& args = util::GetArguments(data);
 
   int socket = common::stol(FromJson<std::string>(args, "id"));
@@ -95,6 +102,9 @@ void BluetoothSocket::ReadData(const picojson::value& data, picojson::object& ou
 void BluetoothSocket::Close(const picojson::value& data, picojson::object& out) {
   LoggerD("Enter");
 
+  CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth,
+                                              Privilege::kBluetoothSpp, &out);
+
   const auto& args = util::GetArguments(data);
 
   int socket = common::stol(FromJson<std::string>(args, "id"));