Commit 547833ae authored by Qiyu Hu's avatar Qiyu Hu Committed by Commit Bot

arc: bluetooth: Add a type to specify read/write request to characteristic or descriptor

This is necessary as request_read/write_cb in android have become
request_read/write_characteristic/descriptor_cb

BUG: b:73743210
TEST: ./out/Default/unit_tests --gtest_filter="ArcBluetoothBridgeTest.*"
      Also push this to my device, working fine

Change-Id: Ib850fceae979c29746affd5591cbac7264de77d2
Reviewed-on: https://chromium-review.googlesource.com/998797Reviewed-by: default avatarLuis Hector Chavez <lhchavez@chromium.org>
Reviewed-by: default avatarGreg Kerr <kerrnel@chromium.org>
Commit-Queue: Qiyu Hu <qiyuh@google.com>
Cr-Commit-Position: refs/heads/master@{#548801}
parent 05f707ae
...@@ -692,6 +692,7 @@ void ArcBluetoothBridge::OnGattAttributeReadRequest( ...@@ -692,6 +692,7 @@ void ArcBluetoothBridge::OnGattAttributeReadRequest(
const BluetoothDevice* device, const BluetoothDevice* device,
const LocalGattAttribute* attribute, const LocalGattAttribute* attribute,
int offset, int offset,
mojom::BluetoothGattDBAttributeType attribute_type,
const ValueCallback& success_callback, const ValueCallback& success_callback,
const ErrorCallback& error_callback) { const ErrorCallback& error_callback) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
...@@ -707,6 +708,7 @@ void ArcBluetoothBridge::OnGattAttributeReadRequest( ...@@ -707,6 +708,7 @@ void ArcBluetoothBridge::OnGattAttributeReadRequest(
bluetooth_instance->RequestGattRead( bluetooth_instance->RequestGattRead(
mojom::BluetoothAddress::From(device->GetAddress()), mojom::BluetoothAddress::From(device->GetAddress()),
gatt_handle_[attribute->GetIdentifier()], offset, false /* is_long */, gatt_handle_[attribute->GetIdentifier()], offset, false /* is_long */,
attribute_type,
base::BindOnce(&OnGattServerRead, success_callback, error_callback)); base::BindOnce(&OnGattServerRead, success_callback, error_callback));
} }
...@@ -716,6 +718,7 @@ void ArcBluetoothBridge::OnGattAttributeWriteRequest( ...@@ -716,6 +718,7 @@ void ArcBluetoothBridge::OnGattAttributeWriteRequest(
const LocalGattAttribute* attribute, const LocalGattAttribute* attribute,
const std::vector<uint8_t>& value, const std::vector<uint8_t>& value,
int offset, int offset,
mojom::BluetoothGattDBAttributeType attribute_type,
const base::Closure& success_callback, const base::Closure& success_callback,
const ErrorCallback& error_callback) { const ErrorCallback& error_callback) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
...@@ -730,7 +733,7 @@ void ArcBluetoothBridge::OnGattAttributeWriteRequest( ...@@ -730,7 +733,7 @@ void ArcBluetoothBridge::OnGattAttributeWriteRequest(
bluetooth_instance->RequestGattWrite( bluetooth_instance->RequestGattWrite(
mojom::BluetoothAddress::From(device->GetAddress()), mojom::BluetoothAddress::From(device->GetAddress()),
gatt_handle_[attribute->GetIdentifier()], offset, value, gatt_handle_[attribute->GetIdentifier()], offset, value, attribute_type,
base::BindOnce(&OnGattServerWrite, success_callback, error_callback)); base::BindOnce(&OnGattServerWrite, success_callback, error_callback));
} }
...@@ -740,8 +743,10 @@ void ArcBluetoothBridge::OnCharacteristicReadRequest( ...@@ -740,8 +743,10 @@ void ArcBluetoothBridge::OnCharacteristicReadRequest(
int offset, int offset,
const ValueCallback& callback, const ValueCallback& callback,
const ErrorCallback& error_callback) { const ErrorCallback& error_callback) {
OnGattAttributeReadRequest(device, characteristic, offset, callback, OnGattAttributeReadRequest(
error_callback); device, characteristic, offset,
mojom::BluetoothGattDBAttributeType::BTGATT_DB_CHARACTERISTIC, callback,
error_callback);
} }
void ArcBluetoothBridge::OnCharacteristicWriteRequest( void ArcBluetoothBridge::OnCharacteristicWriteRequest(
...@@ -751,8 +756,10 @@ void ArcBluetoothBridge::OnCharacteristicWriteRequest( ...@@ -751,8 +756,10 @@ void ArcBluetoothBridge::OnCharacteristicWriteRequest(
int offset, int offset,
const base::Closure& callback, const base::Closure& callback,
const ErrorCallback& error_callback) { const ErrorCallback& error_callback) {
OnGattAttributeWriteRequest(device, characteristic, value, offset, callback, OnGattAttributeWriteRequest(
error_callback); device, characteristic, value, offset,
mojom::BluetoothGattDBAttributeType::BTGATT_DB_CHARACTERISTIC, callback,
error_callback);
} }
void ArcBluetoothBridge::OnDescriptorReadRequest( void ArcBluetoothBridge::OnDescriptorReadRequest(
...@@ -761,8 +768,10 @@ void ArcBluetoothBridge::OnDescriptorReadRequest( ...@@ -761,8 +768,10 @@ void ArcBluetoothBridge::OnDescriptorReadRequest(
int offset, int offset,
const ValueCallback& callback, const ValueCallback& callback,
const ErrorCallback& error_callback) { const ErrorCallback& error_callback) {
OnGattAttributeReadRequest(device, descriptor, offset, callback, OnGattAttributeReadRequest(
error_callback); device, descriptor, offset,
mojom::BluetoothGattDBAttributeType::BTGATT_DB_DESCRIPTOR, callback,
error_callback);
} }
void ArcBluetoothBridge::OnDescriptorWriteRequest( void ArcBluetoothBridge::OnDescriptorWriteRequest(
...@@ -772,8 +781,10 @@ void ArcBluetoothBridge::OnDescriptorWriteRequest( ...@@ -772,8 +781,10 @@ void ArcBluetoothBridge::OnDescriptorWriteRequest(
int offset, int offset,
const base::Closure& callback, const base::Closure& callback,
const ErrorCallback& error_callback) { const ErrorCallback& error_callback) {
OnGattAttributeWriteRequest(device, descriptor, value, offset, callback, OnGattAttributeWriteRequest(
error_callback); device, descriptor, value, offset,
mojom::BluetoothGattDBAttributeType::BTGATT_DB_DESCRIPTOR, callback,
error_callback);
} }
void ArcBluetoothBridge::OnNotificationsStart( void ArcBluetoothBridge::OnNotificationsStart(
......
...@@ -433,20 +433,24 @@ class ArcBluetoothBridge ...@@ -433,20 +433,24 @@ class ArcBluetoothBridge
// Common code for OnCharacteristicReadRequest and OnDescriptorReadRequest // Common code for OnCharacteristicReadRequest and OnDescriptorReadRequest
template <class LocalGattAttribute> template <class LocalGattAttribute>
void OnGattAttributeReadRequest(const device::BluetoothDevice* device, void OnGattAttributeReadRequest(
const LocalGattAttribute* attribute, const device::BluetoothDevice* device,
int offset, const LocalGattAttribute* attribute,
const ValueCallback& success_callback, int offset,
const ErrorCallback& error_callback); mojom::BluetoothGattDBAttributeType attribute_type,
const ValueCallback& success_callback,
const ErrorCallback& error_callback);
// Common code for OnCharacteristicWriteRequest and OnDescriptorWriteRequest // Common code for OnCharacteristicWriteRequest and OnDescriptorWriteRequest
template <class LocalGattAttribute> template <class LocalGattAttribute>
void OnGattAttributeWriteRequest(const device::BluetoothDevice* device, void OnGattAttributeWriteRequest(
const LocalGattAttribute* attribute, const device::BluetoothDevice* device,
const std::vector<uint8_t>& value, const LocalGattAttribute* attribute,
int offset, const std::vector<uint8_t>& value,
const base::Closure& success_callback, int offset,
const ErrorCallback& error_callback); mojom::BluetoothGattDBAttributeType attribute_type,
const base::Closure& success_callback,
const ErrorCallback& error_callback);
void OnSetDiscoverable(bool discoverable, bool success, uint32_t timeout); void OnSetDiscoverable(bool discoverable, bool success, uint32_t timeout);
void SetDiscoverable(bool discoverable, uint32_t timeout); void SetDiscoverable(bool discoverable, uint32_t timeout);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Next MinVersion: 9 // Next MinVersion: 10
module arc.mojom; module arc.mojom;
...@@ -451,15 +451,19 @@ interface BluetoothInstance { ...@@ -451,15 +451,19 @@ interface BluetoothInstance {
array<uint8> value); array<uint8> value);
// Bluetooth Gatt Server functions // Bluetooth Gatt Server functions
[MinVersion=3] RequestGattRead@14(BluetoothAddress address, [MinVersion=3] RequestGattRead@14(
int32 attribute_handle, BluetoothAddress address,
int32 offset, int32 attribute_handle,
bool is_long) int32 offset,
bool is_long,
[MinVersion=9] BluetoothGattDBAttributeType attribute_type)
=> (BluetoothGattStatus status, array<uint8> value); => (BluetoothGattStatus status, array<uint8> value);
[MinVersion=3] RequestGattWrite@15(BluetoothAddress address, [MinVersion=3] RequestGattWrite@15(
int32 attribute_handle, BluetoothAddress address,
int32 offset, int32 attribute_handle,
array<uint8> value) int32 offset,
array<uint8> value,
[MinVersion=9] BluetoothGattDBAttributeType attribute_type)
=> (BluetoothGattStatus status); => (BluetoothGattStatus status);
// Bluetooth SDP function // Bluetooth SDP function
......
...@@ -108,17 +108,20 @@ void FakeBluetoothInstance::OnGattNotify( ...@@ -108,17 +108,20 @@ void FakeBluetoothInstance::OnGattNotify(
bool is_notify, bool is_notify,
const std::vector<uint8_t>& value) {} const std::vector<uint8_t>& value) {}
void FakeBluetoothInstance::RequestGattRead(mojom::BluetoothAddressPtr address, void FakeBluetoothInstance::RequestGattRead(
int32_t attribute_handle, mojom::BluetoothAddressPtr address,
int32_t offset, int32_t attribute_handle,
bool is_long, int32_t offset,
RequestGattReadCallback callback) {} bool is_long,
mojom::BluetoothGattDBAttributeType attribute_type,
RequestGattReadCallback callback) {}
void FakeBluetoothInstance::RequestGattWrite( void FakeBluetoothInstance::RequestGattWrite(
mojom::BluetoothAddressPtr address, mojom::BluetoothAddressPtr address,
int32_t attribute_handle, int32_t attribute_handle,
int32_t offset, int32_t offset,
const std::vector<uint8_t>& value, const std::vector<uint8_t>& value,
mojom::BluetoothGattDBAttributeType attribute_type,
RequestGattWriteCallback callback) {} RequestGattWriteCallback callback) {}
void FakeBluetoothInstance::OnGetSdpRecords( void FakeBluetoothInstance::OnGetSdpRecords(
......
...@@ -116,12 +116,14 @@ class FakeBluetoothInstance : public mojom::BluetoothInstance { ...@@ -116,12 +116,14 @@ class FakeBluetoothInstance : public mojom::BluetoothInstance {
int32_t attribute_handle, int32_t attribute_handle,
int32_t offset, int32_t offset,
bool is_long, bool is_long,
mojom::BluetoothGattDBAttributeType attribute_type,
RequestGattReadCallback callback) override; RequestGattReadCallback callback) override;
void RequestGattWrite(mojom::BluetoothAddressPtr address, void RequestGattWrite(mojom::BluetoothAddressPtr address,
int32_t attribute_handle, int32_t attribute_handle,
int32_t offset, int32_t offset,
const std::vector<uint8_t>& value, const std::vector<uint8_t>& value,
mojom::BluetoothGattDBAttributeType attribute_type,
RequestGattWriteCallback callback) override; RequestGattWriteCallback callback) override;
void OnGetSdpRecords( void OnGetSdpRecords(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment