Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2462)

Unified Diff: device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider.cc

Issue 1947353002: //device/bluetooth support for attribute properties and permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@properties
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider.cc
diff --git a/device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider.cc b/device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider.cc
index b2eb66de12e8282577b97b735d72b6ed96d87750..2e9261a0cdb4b97cb7619bc826d32729a1000d00 100644
--- a/device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider.cc
+++ b/device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider.cc
@@ -4,15 +4,52 @@
#include "device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider.h"
+#include <algorithm>
+#include <iterator>
+
#include "base/callback.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
+#include "device/bluetooth/dbus/bluetooth_gatt_attribute_value_delegate.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_service_provider.h"
#include "device/bluetooth/dbus/fake_bluetooth_gatt_manager_client.h"
+#include "third_party/cros_system_api/dbus/service_constants.h"
namespace bluez {
+namespace {
+
+bool CanWrite(const std::vector<std::string>& flags) {
+ if (find(flags.begin(), flags.end(), bluetooth_gatt_descriptor::kFlagWrite) !=
+ flags.end())
+ return true;
+ if (find(flags.begin(), flags.end(),
+ bluetooth_gatt_descriptor::kFlagEncryptWrite) != flags.end())
+ return true;
+ if (find(flags.begin(), flags.end(),
+ bluetooth_gatt_descriptor::kFlagEncryptAuthenticatedWrite) !=
+ flags.end())
+ return true;
+ return false;
+}
+
+bool CanRead(const std::vector<std::string>& flags) {
+ if (find(flags.begin(), flags.end(), bluetooth_gatt_descriptor::kFlagRead) !=
+ flags.end())
+ return true;
+ if (find(flags.begin(), flags.end(),
+ bluetooth_gatt_descriptor::kFlagEncryptRead) != flags.end())
+ return true;
+ if (find(flags.begin(), flags.end(),
+ bluetooth_gatt_descriptor::kFlagEncryptAuthenticatedRead) !=
+ flags.end())
+ return true;
+ return false;
+}
+
+} // namespace
+
FakeBluetoothGattDescriptorServiceProvider::
FakeBluetoothGattDescriptorServiceProvider(
const dbus::ObjectPath& object_path,
@@ -22,6 +59,7 @@ FakeBluetoothGattDescriptorServiceProvider::
const dbus::ObjectPath& characteristic_path)
: object_path_(object_path),
uuid_(uuid),
+ flags_(flags),
characteristic_path_(characteristic_path),
delegate_(std::move(delegate)) {
VLOG(1) << "Creating Bluetooth GATT descriptor: " << object_path_.value();
@@ -82,6 +120,12 @@ void FakeBluetoothGattDescriptorServiceProvider::GetValue(
return;
}
+ if (!CanRead(flags_)) {
+ VLOG(1) << "GATT descriptor not readable.";
+ error_callback.Run();
+ return;
+ }
+
// Pass on to the delegate.
DCHECK(delegate_);
delegate_->GetValue(callback, error_callback);
@@ -114,6 +158,12 @@ void FakeBluetoothGattDescriptorServiceProvider::SetValue(
return;
}
+ if (!CanWrite(flags_)) {
+ VLOG(1) << "GATT descriptor not writeable.";
+ error_callback.Run();
+ return;
+ }
+
// Pass on to the delegate.
DCHECK(delegate_);
delegate_->SetValue(value, callback, error_callback);
« no previous file with comments | « device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698