--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
@@ -358,48 +358,60 @@ BluetoothServiceBluedroid::StopLeScanInt
BluetoothUuid scanUuid;
StringToUuid(aScanUuid, scanUuid);
gatt->StopLeScan(scanUuid, aRunnable);
}
void
BluetoothServiceBluedroid::ConnectGattClientInternal(
- const nsAString& aAppUuid, const BluetoothAddress& aDeviceAddress,
+ const nsAString& aAppUuid, const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
BluetoothGattManager* gatt = BluetoothGattManager::Get();
ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
BluetoothUuid appUuid;
StringToUuid(aAppUuid, appUuid);
- gatt->Connect(appUuid, aDeviceAddress, aRunnable);
+ BluetoothAddress deviceAddress;
+ if (NS_FAILED(StringToAddress(aDeviceAddress, deviceAddress))) {
+ DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
+ return;
+ }
+
+ gatt->Connect(appUuid, deviceAddress, aRunnable);
}
void
BluetoothServiceBluedroid::DisconnectGattClientInternal(
- const nsAString& aAppUuid, const BluetoothAddress& aDeviceAddress,
+ const nsAString& aAppUuid, const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
BluetoothGattManager* gatt = BluetoothGattManager::Get();
ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
BluetoothUuid appUuid;
StringToUuid(aAppUuid, appUuid);
- gatt->Disconnect(appUuid, aDeviceAddress, aRunnable);
+ BluetoothAddress deviceAddress;
+ if (NS_FAILED(StringToAddress(aDeviceAddress, deviceAddress))) {
+ DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
+ return;
+ }
+
+ gatt->Disconnect(appUuid, deviceAddress, aRunnable);
}
void
BluetoothServiceBluedroid::DiscoverGattServicesInternal(
const nsAString& aAppUuid, BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
@@ -461,27 +473,33 @@ BluetoothServiceBluedroid::UnregisterGat
BluetoothGattManager* gatt = BluetoothGattManager::Get();
ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
gatt->UnregisterClient(aClientIf, aRunnable);
}
void
BluetoothServiceBluedroid::GattClientReadRemoteRssiInternal(
- int aClientIf, const BluetoothAddress& aDeviceAddress,
+ int aClientIf, const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
BluetoothGattManager* gatt = BluetoothGattManager::Get();
ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
- gatt->ReadRemoteRssi(aClientIf, aDeviceAddress, aRunnable);
+ BluetoothAddress deviceAddress;
+ if (NS_FAILED(StringToAddress(aDeviceAddress, deviceAddress))) {
+ DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
+ return;
+ }
+
+ gatt->ReadRemoteRssi(aClientIf, deviceAddress, aRunnable);
}
void
BluetoothServiceBluedroid::GattClientReadCharacteristicValueInternal(
const nsAString& aAppUuid,
const BluetoothGattServiceId& aServiceId,
const BluetoothGattId& aCharacteristicId,
BluetoothReplyRunnable* aRunnable)
@@ -566,48 +584,60 @@ BluetoothServiceBluedroid::GattClientWri
gatt->WriteDescriptorValue(appUuid, aServiceId, aCharacteristicId,
aDescriptorId, aValue, aRunnable);
}
// GATT Server
void
BluetoothServiceBluedroid::GattServerConnectPeripheralInternal(
- const nsAString& aAppUuid, const BluetoothAddress& aAddress,
+ const nsAString& aAppUuid, const nsAString& aAddress,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
BluetoothGattManager* gatt = BluetoothGattManager::Get();
ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
BluetoothUuid appUuid;
StringToUuid(aAppUuid, appUuid);
- gatt->ConnectPeripheral(appUuid, aAddress, aRunnable);
+ BluetoothAddress address;
+ if (NS_FAILED(StringToAddress(aAddress, address))) {
+ DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
+ return;
+ }
+
+ gatt->ConnectPeripheral(appUuid, address, aRunnable);
}
void
BluetoothServiceBluedroid::GattServerDisconnectPeripheralInternal(
- const nsAString& aAppUuid, const BluetoothAddress& aAddress,
+ const nsAString& aAppUuid, const nsAString& aAddress,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
BluetoothGattManager* gatt = BluetoothGattManager::Get();
ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
BluetoothUuid appUuid;
StringToUuid(aAppUuid, appUuid);
- gatt->DisconnectPeripheral(appUuid, aAddress, aRunnable);
+ BluetoothAddress address;
+ if (NS_FAILED(StringToAddress(aAddress, address))) {
+ DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
+ return;
+ }
+
+ gatt->DisconnectPeripheral(appUuid, address, aRunnable);
}
void
BluetoothServiceBluedroid::UnregisterGattServerInternal(
int aServerIf, BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
@@ -771,57 +801,69 @@ BluetoothServiceBluedroid::GattServerSto
StringToUuid(aAppUuid, appUuid);
gatt->ServerStopService(appUuid, aServiceHandle, aRunnable);
}
void
BluetoothServiceBluedroid::GattServerSendResponseInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
uint16_t aStatus,
int32_t aRequestId,
const BluetoothGattResponse& aRsp,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
BluetoothGattManager* gatt = BluetoothGattManager::Get();
ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
BluetoothUuid appUuid;
StringToUuid(aAppUuid, appUuid);
+ BluetoothAddress address;
+ if (NS_FAILED(StringToAddress(aAddress, address))) {
+ DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
+ return;
+ }
+
gatt->ServerSendResponse(
- appUuid, aAddress, aStatus, aRequestId, aRsp, aRunnable);
+ appUuid, address, aStatus, aRequestId, aRsp, aRunnable);
}
void
BluetoothServiceBluedroid::GattServerSendIndicationInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
const BluetoothAttributeHandle& aCharacteristicHandle,
bool aConfirm,
const nsTArray<uint8_t>& aValue,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
BluetoothGattManager* gatt = BluetoothGattManager::Get();
ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
BluetoothUuid appUuid;
StringToUuid(aAppUuid, appUuid);
+ BluetoothAddress address;
+ if (NS_FAILED(StringToAddress(aAddress, address))) {
+ DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
+ return;
+ }
+
gatt->ServerSendIndication(appUuid,
- aAddress,
+ address,
aCharacteristicHandle,
aConfirm,
aValue,
aRunnable);
}
nsresult
BluetoothServiceBluedroid::GetAdaptersInternal(
--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.h
+++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.h
@@ -278,22 +278,22 @@ public:
virtual void StartLeScanInternal(const nsTArray<nsString>& aServiceUuids,
BluetoothReplyRunnable* aRunnable);
virtual void StopLeScanInternal(const nsAString& aScanUuid,
BluetoothReplyRunnable* aRunnable);
virtual void
ConnectGattClientInternal(const nsAString& aAppUuid,
- const BluetoothAddress& aDeviceAddress,
+ const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
DisconnectGattClientInternal(const nsAString& aAppUuid,
- const BluetoothAddress& aDeviceAddress,
+ const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
DiscoverGattServicesInternal(const nsAString& aAppUuid,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattClientStartNotificationsInternal(
@@ -310,17 +310,17 @@ public:
BluetoothReplyRunnable* aRunnable) override;
virtual void
UnregisterGattClientInternal(int aClientIf,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattClientReadRemoteRssiInternal(
- int aClientIf, const BluetoothAddress& aDeviceAddress,
+ int aClientIf, const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattClientReadCharacteristicValueInternal(
const nsAString& aAppUuid,
const BluetoothGattServiceId& aServiceId,
const BluetoothGattId& aCharacteristicId,
BluetoothReplyRunnable* aRunnable) override;
@@ -349,23 +349,23 @@ public:
const BluetoothGattId& aCharacteristicId,
const BluetoothGattId& aDescriptorId,
const nsTArray<uint8_t>& aValue,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattServerConnectPeripheralInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattServerDisconnectPeripheralInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
UnregisterGattServerInternal(int aServerIf,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattServerAddServiceInternal(
@@ -415,26 +415,26 @@ public:
GattServerStopServiceInternal(
const nsAString& aAppUuid,
const BluetoothAttributeHandle& aServiceHandle,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattServerSendResponseInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
uint16_t aStatus,
int32_t aRequestId,
const BluetoothGattResponse& aRsp,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattServerSendIndicationInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
const BluetoothAttributeHandle& aCharacteristicHandle,
bool aConfirm,
const nsTArray<uint8_t>& aValue,
BluetoothReplyRunnable* aRunnable) override;
//
// Bluetooth notifications
//
--- a/dom/bluetooth/bluez/BluetoothDBusService.cpp
+++ b/dom/bluetooth/bluez/BluetoothDBusService.cpp
@@ -4304,24 +4304,24 @@ void
BluetoothDBusService::StopLeScanInternal(
const nsAString& aAppUuid,
BluetoothReplyRunnable* aRunnable)
{
}
void
BluetoothDBusService::ConnectGattClientInternal(
- const nsAString& aAppUuid, const BluetoothAddress& aDeviceAddress,
+ const nsAString& aAppUuid, const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable)
{
}
void
BluetoothDBusService::DisconnectGattClientInternal(
- const nsAString& aAppUuid, const BluetoothAddress& aDeviceAddress,
+ const nsAString& aAppUuid, const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable)
{
}
void
BluetoothDBusService::DiscoverGattServicesInternal(
const nsAString& aAppUuid, BluetoothReplyRunnable* aRunnable)
{
@@ -4344,17 +4344,17 @@ BluetoothDBusService::GattClientStopNoti
void
BluetoothDBusService::UnregisterGattClientInternal(
int aClientIf, BluetoothReplyRunnable* aRunnable)
{
}
void
BluetoothDBusService::GattClientReadRemoteRssiInternal(
- int aClientIf, const BluetoothAddress& aDeviceAddress,
+ int aClientIf, const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable)
{
}
void
BluetoothDBusService::GattClientReadCharacteristicValueInternal(
const nsAString& aAppUuid,
const BluetoothGattServiceId& aServiceId,
@@ -4516,24 +4516,24 @@ BluetoothDBusService::ReplyToMapSendMess
void
BluetoothDBusService::ReplyToMapMessageUpdate(long aMasId, bool aStatus,
BluetoothReplyRunnable* aRunnable)
{
}
void
BluetoothDBusService::GattServerConnectPeripheralInternal(
- const nsAString& aAppUuid, const BluetoothAddress& aAddress,
+ const nsAString& aAppUuid, const nsAString& aAddress,
BluetoothReplyRunnable* aRunnable)
{
}
void
BluetoothDBusService::GattServerDisconnectPeripheralInternal(
- const nsAString& aAppUuid, const BluetoothAddress& aAddress,
+ const nsAString& aAppUuid, const nsAString& aAddress,
BluetoothReplyRunnable* aRunnable)
{
}
void
BluetoothDBusService::UnregisterGattServerInternal(
int aServerIf, BluetoothReplyRunnable* aRunnable)
{
@@ -4601,26 +4601,26 @@ BluetoothDBusService::GattServerStopServ
const BluetoothAttributeHandle& aServiceHandle,
BluetoothReplyRunnable* aRunnable)
{
}
void
BluetoothDBusService::GattServerSendIndicationInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
const BluetoothAttributeHandle& aCharacteristicHandle,
bool aConfirm,
const nsTArray<uint8_t>& aValue,
BluetoothReplyRunnable* aRunnable)
{
}
void
BluetoothDBusService::GattServerSendResponseInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
uint16_t aStatus,
int32_t aRequestId,
const BluetoothGattResponse& aRsp,
BluetoothReplyRunnable* aRunnable)
{
}
--- a/dom/bluetooth/bluez/BluetoothDBusService.h
+++ b/dom/bluetooth/bluez/BluetoothDBusService.h
@@ -289,22 +289,22 @@ public:
BluetoothReplyRunnable* aRunnable) override;
virtual void
StopLeScanInternal(const nsAString& aAppUuid,
BluetoothReplyRunnable* aRunnable) override;
virtual void
ConnectGattClientInternal(const nsAString& aAppUuid,
- const BluetoothAddress& aDeviceAddress,
+ const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
DisconnectGattClientInternal(const nsAString& aAppUuid,
- const BluetoothAddress& aDeviceAddress,
+ const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
DiscoverGattServicesInternal(const nsAString& aAppUuid,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattClientStartNotificationsInternal(
@@ -321,17 +321,17 @@ public:
BluetoothReplyRunnable* aRunnable) override;
virtual void
UnregisterGattClientInternal(int aClientIf,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattClientReadRemoteRssiInternal(
- int aClientIf, const BluetoothAddress& aDeviceAddress,
+ int aClientIf, const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattClientReadCharacteristicValueInternal(
const nsAString& aAppUuid,
const BluetoothGattServiceId& aServiceId,
const BluetoothGattId& aCharacteristicId,
BluetoothReplyRunnable* aRunnable) override;
@@ -360,23 +360,23 @@ public:
const BluetoothGattId& aCharacteristicId,
const BluetoothGattId& aDescriptorId,
const nsTArray<uint8_t>& aValue,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattServerConnectPeripheralInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattServerDisconnectPeripheralInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
UnregisterGattServerInternal(int aServerIf,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattServerAddServiceInternal(
@@ -426,26 +426,26 @@ public:
GattServerStopServiceInternal(
const nsAString& aAppUuid,
const BluetoothAttributeHandle& aServiceHandle,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattServerSendResponseInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
uint16_t aStatus,
int32_t aRequestId,
const BluetoothGattResponse& aRsp,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattServerSendIndicationInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
const BluetoothAttributeHandle& aCharacteristicHandle,
bool aConfirm,
const nsTArray<uint8_t>& aValue,
BluetoothReplyRunnable* aRunnable) override;
private:
nsresult SendGetPropertyMessage(const nsAString& aPath,
const char* aInterface,
--- a/dom/bluetooth/common/BluetoothService.h
+++ b/dom/bluetooth/common/BluetoothService.h
@@ -437,26 +437,26 @@ public:
SendInputMessage(const nsAString& aDeviceAddresses,
const nsAString& aMessage) = 0;
/**
* Connect to a remote GATT server. (platform specific implementation)
*/
virtual void
ConnectGattClientInternal(const nsAString& aAppUuid,
- const BluetoothAddress& aDeviceAddress,
+ const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) = 0;
/**
* Disconnect GATT client from a remote GATT server.
* (platform specific implementation)
*/
virtual void
DisconnectGattClientInternal(const nsAString& aAppUuid,
- const BluetoothAddress& aDeviceAddress,
+ const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) = 0;
/**
* Discover GATT services, characteristic, descriptors from a remote GATT
* server. (platform specific implementation)
*/
virtual void
DiscoverGattServicesInternal(const nsAString& aAppUuid,
@@ -489,17 +489,17 @@ public:
UnregisterGattClientInternal(int aClientIf,
BluetoothReplyRunnable* aRunnable) = 0;
/**
* Request RSSI for a remote GATT server. (platform specific implementation)
*/
virtual void
GattClientReadRemoteRssiInternal(int aClientIf,
- const BluetoothAddress& aDeviceAddress,
+ const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) = 0;
/**
* Read the value of a characteristic on a GATT client.
* (platform specific implementation)
*/
virtual void
GattClientReadCharacteristicValueInternal(
@@ -544,23 +544,23 @@ public:
const BluetoothGattId& aCharacteristicId,
const BluetoothGattId& aDescriptorId,
const nsTArray<uint8_t>& aValue,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void
GattServerConnectPeripheralInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void
GattServerDisconnectPeripheralInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
BluetoothReplyRunnable* aRunnable) = 0;
/**
* Unregister a GATT server. (platform specific implementation)
*/
virtual void
UnregisterGattServerInternal(int aServerIf,
BluetoothReplyRunnable* aRunnable) = 0;
@@ -613,26 +613,26 @@ public:
GattServerStopServiceInternal(
const nsAString& aAppUuid,
const BluetoothAttributeHandle& aServiceHandle,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void
GattServerSendResponseInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
uint16_t aStatus,
int32_t aRequestId,
const BluetoothGattResponse& aRsp,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void
GattServerSendIndicationInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
const BluetoothAttributeHandle& aCharacteristicHandle,
bool aConfirm,
const nsTArray<uint8_t>& aValue,
BluetoothReplyRunnable* aRunnable) = 0;
bool
IsEnabled() const
{
--- a/dom/bluetooth/common/webapi/BluetoothGatt.cpp
+++ b/dom/bluetooth/common/webapi/BluetoothGatt.cpp
@@ -107,33 +107,27 @@ BluetoothGatt::Connect(ErrorResult& aRv)
BT_ENSURE_TRUE_REJECT(
mConnectionState == BluetoothConnectionState::Disconnected,
promise,
NS_ERROR_DOM_INVALID_STATE_ERR);
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
- BluetoothAddress deviceAddr;
- BT_ENSURE_TRUE_REJECT(
- NS_SUCCEEDED(StringToAddress(mDeviceAddr, deviceAddr)),
- promise,
- NS_ERROR_DOM_OPERATION_ERR);
-
if (mAppUuid.IsEmpty()) {
nsresult rv = GenerateUuid(mAppUuid);
BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(rv) && !mAppUuid.IsEmpty(),
promise,
NS_ERROR_DOM_OPERATION_ERR);
RegisterBluetoothSignalHandler(mAppUuid, this);
}
UpdateConnectionState(BluetoothConnectionState::Connecting);
bs->ConnectGattClientInternal(
- mAppUuid, deviceAddr, new BluetoothVoidReplyRunnable(nullptr, promise));
+ mAppUuid, mDeviceAddr, new BluetoothVoidReplyRunnable(nullptr, promise));
return promise.forget();
}
already_AddRefed<Promise>
BluetoothGatt::Disconnect(ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
@@ -148,25 +142,19 @@ BluetoothGatt::Disconnect(ErrorResult& a
BT_ENSURE_TRUE_REJECT(
mConnectionState == BluetoothConnectionState::Connected,
promise,
NS_ERROR_DOM_INVALID_STATE_ERR);
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
- BluetoothAddress deviceAddr;
- BT_ENSURE_TRUE_REJECT(
- NS_SUCCEEDED(StringToAddress(mDeviceAddr, deviceAddr)),
- promise,
- NS_ERROR_DOM_OPERATION_ERR);
-
UpdateConnectionState(BluetoothConnectionState::Disconnecting);
bs->DisconnectGattClientInternal(
- mAppUuid, deviceAddr, new BluetoothVoidReplyRunnable(nullptr, promise));
+ mAppUuid, mDeviceAddr, new BluetoothVoidReplyRunnable(nullptr, promise));
return promise.forget();
}
class ReadRemoteRssiTask final : public BluetoothReplyRunnable
{
public:
ReadRemoteRssiTask(Promise* aPromise)
@@ -203,24 +191,18 @@ BluetoothGatt::ReadRemoteRssi(ErrorResul
BT_ENSURE_TRUE_REJECT(
mConnectionState == BluetoothConnectionState::Connected,
promise,
NS_ERROR_DOM_INVALID_STATE_ERR);
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
- BluetoothAddress deviceAddr;
- BT_ENSURE_TRUE_REJECT(
- NS_SUCCEEDED(StringToAddress(mDeviceAddr, deviceAddr)),
- promise,
- NS_ERROR_DOM_OPERATION_ERR);
-
bs->GattClientReadRemoteRssiInternal(
- mClientIf, deviceAddr, new ReadRemoteRssiTask(promise));
+ mClientIf, mDeviceAddr, new ReadRemoteRssiTask(promise));
return promise.forget();
}
already_AddRefed<Promise>
BluetoothGatt::DiscoverServices(ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
--- a/dom/bluetooth/common/webapi/BluetoothGattServer.cpp
+++ b/dom/bluetooth/common/webapi/BluetoothGattServer.cpp
@@ -314,56 +314,44 @@ BluetoothGattServer::Connect(const nsASt
if (!global) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
RefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
- BluetoothAddress address;
- BT_ENSURE_TRUE_REJECT(
- NS_SUCCEEDED(StringToAddress(aAddress, address)),
- promise,
- NS_ERROR_INVALID_ARG);
-
BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
bs->GattServerConnectPeripheralInternal(
- mAppUuid, address, new BluetoothVoidReplyRunnable(nullptr, promise));
+ mAppUuid, aAddress, new BluetoothVoidReplyRunnable(nullptr, promise));
return promise.forget();
}
already_AddRefed<Promise>
BluetoothGattServer::Disconnect(const nsAString& aAddress, ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
if (!global) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
RefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
- BluetoothAddress address;
- BT_ENSURE_TRUE_REJECT(
- NS_SUCCEEDED(StringToAddress(aAddress, address)),
- promise,
- NS_ERROR_INVALID_ARG);
-
BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
bs->GattServerDisconnectPeripheralInternal(
- mAppUuid, address, new BluetoothVoidReplyRunnable(nullptr, promise));
+ mAppUuid, aAddress, new BluetoothVoidReplyRunnable(nullptr, promise));
return promise.forget();
}
class BluetoothGattServer::AddIncludedServiceTask final
: public BluetoothReplyTaskQueue::SubTask
{
public:
@@ -805,33 +793,27 @@ BluetoothGattServer::NotifyCharacteristi
return nullptr;
}
RefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
- BluetoothAddress address;
- BT_ENSURE_TRUE_REJECT(
- NS_SUCCEEDED(StringToAddress(aAddress, address)),
- promise,
- NS_ERROR_INVALID_ARG);
-
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
RefPtr<BluetoothGattService> service = aCharacteristic.Service();
BT_ENSURE_TRUE_REJECT(service, promise, NS_ERROR_NOT_AVAILABLE);
BT_ENSURE_TRUE_REJECT(mServices.Contains(service),
promise,
NS_ERROR_NOT_AVAILABLE);
bs->GattServerSendIndicationInternal(
- mAppUuid, address, aCharacteristic.GetCharacteristicHandle(), aConfirm,
+ mAppUuid, aAddress, aCharacteristic.GetCharacteristicHandle(), aConfirm,
aCharacteristic.GetValue(),
new BluetoothVoidReplyRunnable(nullptr, promise));
return promise.forget();
}
already_AddRefed<Promise>
BluetoothGattServer::SendResponse(const nsAString& aAddress,
@@ -843,22 +825,16 @@ BluetoothGattServer::SendResponse(const
if (!global) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
RefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
- BluetoothAddress address;
- BT_ENSURE_TRUE_REJECT(
- NS_SUCCEEDED(StringToAddress(aAddress, address)),
- promise,
- NS_ERROR_INVALID_ARG);
-
BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
RequestData* requestData;
mRequestMap.Get(aRequestId, &requestData);
BT_ENSURE_TRUE_REJECT(requestData, promise, NS_ERROR_UNEXPECTED);
BluetoothGattResponse response;
memset(&response, 0, sizeof(response));
@@ -881,16 +857,16 @@ BluetoothGattServer::SendResponse(const
return promise.forget();
}
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
bs->GattServerSendResponseInternal(
mAppUuid,
- address,
+ aAddress,
aStatus,
aRequestId,
response,
new BluetoothVoidReplyRunnable(nullptr, promise));
return promise.forget();
}
--- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
+++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
@@ -545,30 +545,30 @@ BluetoothServiceChildProcess::SendPlaySt
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
SendPlayStatusRequest(aDuration, aPosition, aPlayStatus));
}
void
BluetoothServiceChildProcess::ConnectGattClientInternal(
- const nsAString& aAppUuid, const BluetoothAddress& aDeviceAddress,
+ const nsAString& aAppUuid, const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, ConnectGattClientRequest(nsString(aAppUuid),
- aDeviceAddress));
+ nsString(aDeviceAddress)));
}
void
BluetoothServiceChildProcess::DisconnectGattClientInternal(
- const nsAString& aAppUuid, const BluetoothAddress& aDeviceAddress,
+ const nsAString& aAppUuid, const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
- DisconnectGattClientRequest(nsString(aAppUuid), aDeviceAddress));
+ DisconnectGattClientRequest(nsString(aAppUuid), nsString(aDeviceAddress)));
}
void
BluetoothServiceChildProcess::DiscoverGattServicesInternal(
const nsAString& aAppUuid, BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
DiscoverGattServicesRequest(nsString(aAppUuid)));
@@ -596,21 +596,22 @@ void
BluetoothServiceChildProcess::UnregisterGattClientInternal(
int aClientIf, BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, UnregisterGattClientRequest(aClientIf));
}
void
BluetoothServiceChildProcess::GattClientReadRemoteRssiInternal(
- int aClientIf, const BluetoothAddress& aDeviceAddress,
+ int aClientIf, const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
- GattClientReadRemoteRssiRequest(aClientIf, aDeviceAddress));
+ GattClientReadRemoteRssiRequest(aClientIf,
+ nsString(aDeviceAddress)));
}
void
BluetoothServiceChildProcess::GattClientReadCharacteristicValueInternal(
const nsAString& aAppUuid,
const BluetoothGattServiceId& aServiceId,
const BluetoothGattId& aCharacteristicId,
BluetoothReplyRunnable* aRunnable)
@@ -668,31 +669,33 @@ BluetoothServiceChildProcess::GattClient
aCharacteristicId,
aDescriptorId,
aValue));
}
void
BluetoothServiceChildProcess::GattServerConnectPeripheralInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
- GattServerConnectPeripheralRequest(nsString(aAppUuid), aAddress));
+ GattServerConnectPeripheralRequest(nsString(aAppUuid),
+ nsString(aAddress)));
}
void
BluetoothServiceChildProcess::GattServerDisconnectPeripheralInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
- GattServerDisconnectPeripheralRequest(nsString(aAppUuid), aAddress));
+ GattServerDisconnectPeripheralRequest(nsString(aAppUuid),
+ nsString(aAddress)));
}
void
BluetoothServiceChildProcess::UnregisterGattServerInternal(
int aServerIf, BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, UnregisterGattServerRequest(aServerIf));
}
@@ -783,39 +786,39 @@ BluetoothServiceChildProcess::GattServer
{
SendRequest(aRunnable,
GattServerStopServiceRequest(nsString(aAppUuid), aServiceHandle));
}
void
BluetoothServiceChildProcess::GattServerSendResponseInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
uint16_t aStatus,
int32_t aRequestId,
const BluetoothGattResponse& aRsp,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
GattServerSendResponseRequest(
- nsString(aAppUuid), aAddress, aStatus, aRequestId, aRsp));
+ nsString(aAppUuid), nsString(aAddress), aStatus, aRequestId, aRsp));
}
void
BluetoothServiceChildProcess::GattServerSendIndicationInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
const BluetoothAttributeHandle& aCharacteristicHandle,
bool aConfirm,
const nsTArray<uint8_t>& aValue,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
GattServerSendIndicationRequest(nsString(aAppUuid),
- aAddress,
+ nsString(aAddress),
aCharacteristicHandle,
aConfirm,
aValue));
}
nsresult
BluetoothServiceChildProcess::HandleStartup()
{
--- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.h
+++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.h
@@ -280,22 +280,22 @@ public:
const nsAString& aMessage) override;
virtual nsresult
SendInputMessage(const nsAString& aDeviceAddresses,
const nsAString& aMessage) override;
virtual void
ConnectGattClientInternal(const nsAString& aAppUuid,
- const BluetoothAddress& aDeviceAddress,
+ const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
DisconnectGattClientInternal(const nsAString& aAppUuid,
- const BluetoothAddress& aDeviceAddress,
+ const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
DiscoverGattServicesInternal(const nsAString& aAppUuid,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattClientStartNotificationsInternal(
@@ -312,17 +312,17 @@ public:
BluetoothReplyRunnable* aRunnable) override;
virtual void
UnregisterGattClientInternal(int aClientIf,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattClientReadRemoteRssiInternal(int aClientIf,
- const BluetoothAddress& aDeviceAddress,
+ const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattClientReadCharacteristicValueInternal(
const nsAString& aAppUuid,
const BluetoothGattServiceId& aServiceId,
const BluetoothGattId& aCharacteristicId,
BluetoothReplyRunnable* aRunnable) override;
@@ -351,23 +351,23 @@ public:
const BluetoothGattId& aCharacteristicId,
const BluetoothGattId& aDescriptorId,
const nsTArray<uint8_t>& aValue,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattServerConnectPeripheralInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattServerDisconnectPeripheralInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
UnregisterGattServerInternal(int aServerIf,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattServerAddServiceInternal(
@@ -417,26 +417,26 @@ public:
GattServerStopServiceInternal(
const nsAString& aAppUuid,
const BluetoothAttributeHandle& aServiceHandle,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattServerSendResponseInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
uint16_t aStatus,
int32_t aRequestId,
const BluetoothGattResponse& aRsp,
BluetoothReplyRunnable* aRunnable) override;
virtual void
GattServerSendIndicationInternal(
const nsAString& aAppUuid,
- const BluetoothAddress& aAddress,
+ const nsAString& aAddress,
const BluetoothAttributeHandle& aCharacteristicHandle,
bool aConfirm,
const nsTArray<uint8_t>& aValue,
BluetoothReplyRunnable* aRunnable) override;
protected:
BluetoothServiceChildProcess();
virtual ~BluetoothServiceChildProcess();
--- a/dom/bluetooth/ipc/PBluetooth.ipdl
+++ b/dom/bluetooth/ipc/PBluetooth.ipdl
@@ -271,23 +271,23 @@ struct SendPlayStatusRequest
int64_t duration;
int64_t position;
ControlPlayStatus playStatus;
};
struct ConnectGattClientRequest
{
nsString appUuid;
- BluetoothAddress deviceAddress;
+ nsString deviceAddress;
};
struct DisconnectGattClientRequest
{
nsString appUuid;
- BluetoothAddress deviceAddress;
+ nsString deviceAddress;
};
struct DiscoverGattServicesRequest
{
nsString appUuid;
};
struct GattClientStartNotificationsRequest
@@ -307,17 +307,17 @@ struct GattClientStopNotificationsReques
struct UnregisterGattClientRequest
{
int clientIf;
};
struct GattClientReadRemoteRssiRequest
{
int clientIf;
- BluetoothAddress deviceAddress;
+ nsString deviceAddress;
};
struct GattClientReadCharacteristicValueRequest
{
nsString appUuid;
BluetoothGattServiceId serviceId;
BluetoothGattId charId;
};
@@ -346,23 +346,23 @@ struct GattClientWriteDescriptorValueReq
BluetoothGattId charId;
BluetoothGattId descId;
uint8_t[] value;
};
struct GattServerConnectPeripheralRequest
{
nsString appUuid;
- BluetoothAddress address;
+ nsString address;
};
struct GattServerDisconnectPeripheralRequest
{
nsString appUuid;
- BluetoothAddress address;
+ nsString address;
};
struct UnregisterGattServerRequest
{
int serverIf;
};
struct GattServerAddServiceRequest
@@ -413,26 +413,26 @@ struct GattServerStopServiceRequest
{
nsString appUuid;
BluetoothAttributeHandle serviceHandle;
};
struct GattServerSendResponseRequest
{
nsString appUuid;
- BluetoothAddress address;
+ nsString address;
uint16_t status;
int32_t requestId;
BluetoothGattResponse response;
};
struct GattServerSendIndicationRequest
{
nsString appUuid;
- BluetoothAddress address;
+ nsString address;
BluetoothAttributeHandle characteristicHandle;
bool confirm;
uint8_t[] value;
};
union Request
{
GetAdaptersRequest;