--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
@@ -1023,43 +1023,37 @@ BluetoothServiceBluedroid::GetConnectedD
sBtInterface->GetRemoteDeviceProperties(address,
new GetRemoteDevicePropertiesResultHandler(mGetDeviceRequests, address));
return NS_OK;
}
nsresult
BluetoothServiceBluedroid::GetPairedDevicePropertiesInternal(
- const nsTArray<nsString>& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
+ const nsTArray<BluetoothAddress>& aDeviceAddress,
+ BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY(aRunnable, NS_OK);
if (aDeviceAddress.IsEmpty()) {
DispatchReplySuccess(aRunnable);
return NS_OK;
}
// Append request of all paired devices
GetDeviceRequest request(aDeviceAddress.Length(), aRunnable);
mGetDeviceRequests.AppendElement(request);
for (uint8_t i = 0; i < aDeviceAddress.Length(); i++) {
-
- BluetoothAddress address;
- nsresult rv = StringToAddress(aDeviceAddress[i], address);
- if (NS_FAILED(rv)) {
- DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
- return rv;
- }
-
// Retrieve all properties of devices
- sBtInterface->GetRemoteDeviceProperties(address,
- new GetRemoteDevicePropertiesResultHandler(mGetDeviceRequests, address));
+ sBtInterface->GetRemoteDeviceProperties(aDeviceAddress[i],
+ new GetRemoteDevicePropertiesResultHandler(mGetDeviceRequests,
+ aDeviceAddress[i]));
}
return NS_OK;
}
class BluetoothServiceBluedroid::DispatchReplyErrorResultHandler final
: public BluetoothResultHandler
{
@@ -1095,39 +1089,32 @@ BluetoothServiceBluedroid::StartDiscover
mChangeDiscoveryRunnables.AppendElement(aRunnable);
sBtInterface->StartDiscovery(
new DispatchReplyErrorResultHandler(mChangeDiscoveryRunnables, aRunnable));
}
nsresult
BluetoothServiceBluedroid::FetchUuidsInternal(
- const nsAString& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
+ const BluetoothAddress& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY(aRunnable, NS_OK);
/*
* get_remote_services request will not be performed by bluedroid
* if it is currently discovering nearby remote devices.
*/
if (mDiscovering) {
StopDiscoveryInternal(aRunnable);
}
- BluetoothAddress address;
- nsresult rv = StringToAddress(aDeviceAddress, address);
- if (NS_FAILED(rv)) {
- DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
- return rv;
- }
-
mFetchUuidsRunnables.AppendElement(aRunnable);
- sBtInterface->GetRemoteServices(address,
+ sBtInterface->GetRemoteServices(aDeviceAddress,
new DispatchReplyErrorResultHandler(mFetchUuidsRunnables, aRunnable));
return NS_OK;
}
void
BluetoothServiceBluedroid::StopDiscoveryInternal(
BluetoothReplyRunnable* aRunnable)
@@ -1353,54 +1340,40 @@ BluetoothServiceBluedroid::UpdateSdpReco
sBtInterface->GetRemoteServices(aDeviceAddress, res);
}
return true;
}
nsresult
BluetoothServiceBluedroid::CreatePairedDeviceInternal(
- const nsAString& aDeviceAddress, int aTimeout,
+ const BluetoothAddress& aDeviceAddress, int aTimeout,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY(aRunnable, NS_OK);
- BluetoothAddress address;
- nsresult rv = StringToAddress(aDeviceAddress, address);
- if (NS_FAILED(rv)) {
- DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
- return rv;
- }
-
mCreateBondRunnables.AppendElement(aRunnable);
- sBtInterface->CreateBond(address, TRANSPORT_AUTO,
+ sBtInterface->CreateBond(aDeviceAddress, TRANSPORT_AUTO,
new DispatchReplyErrorResultHandler(mCreateBondRunnables, aRunnable));
return NS_OK;
}
nsresult
BluetoothServiceBluedroid::RemoveDeviceInternal(
- const nsAString& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
+ const BluetoothAddress& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY(aRunnable, NS_OK);
- BluetoothAddress address;
- nsresult rv = StringToAddress(aDeviceAddress, address);
- if (NS_FAILED(rv)) {
- DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
- return rv;
- }
-
mRemoveBondRunnables.AppendElement(aRunnable);
- sBtInterface->RemoveBond(address,
+ sBtInterface->RemoveBond(aDeviceAddress,
new DispatchReplyErrorResultHandler(mRemoveBondRunnables, aRunnable));
return NS_OK;
}
class BluetoothServiceBluedroid::PinReplyResultHandler final
: public BluetoothResultHandler
{
@@ -1420,52 +1393,45 @@ public:
}
private:
BluetoothReplyRunnable* mRunnable;
};
void
BluetoothServiceBluedroid::PinReplyInternal(
- const nsAString& aDeviceAddress, bool aAccept,
+ const BluetoothAddress& aDeviceAddress, bool aAccept,
const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
- BluetoothAddress address;
- nsresult rv = StringToAddress(aDeviceAddress, address);
+ BluetoothPinCode pinCode;
+ auto rv = StringToPinCode(aPinCode, pinCode);
if (NS_FAILED(rv)) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
- BluetoothPinCode pinCode;
- rv = StringToPinCode(aPinCode, pinCode);
- if (NS_FAILED(rv)) {
- DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
- return;
- }
-
- sBtInterface->PinReply(address, aAccept, pinCode,
+ sBtInterface->PinReply(aDeviceAddress, aAccept, pinCode,
new PinReplyResultHandler(aRunnable));
}
void
BluetoothServiceBluedroid::SetPinCodeInternal(
- const nsAString& aDeviceAddress, const nsAString& aPinCode,
+ const BluetoothAddress& aDeviceAddress, const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable)
{
// Legacy method used by BlueZ only.
}
void
BluetoothServiceBluedroid::SetPasskeyInternal(
- const nsAString& aDeviceAddress, uint32_t aPasskey,
+ const BluetoothAddress& aDeviceAddress, uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable)
{
// Legacy method used by BlueZ only.
}
class BluetoothServiceBluedroid::SspReplyResultHandler final
: public BluetoothResultHandler
{
@@ -1485,37 +1451,30 @@ public:
}
private:
BluetoothReplyRunnable* mRunnable;
};
void
BluetoothServiceBluedroid::SspReplyInternal(
- const nsAString& aDeviceAddress, BluetoothSspVariant aVariant,
+ const BluetoothAddress& aDeviceAddress, BluetoothSspVariant aVariant,
bool aAccept, BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
- BluetoothAddress address;
- nsresult rv = StringToAddress(aDeviceAddress, address);
- if (NS_FAILED(rv)) {
- DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
- return;
- }
-
- sBtInterface->SspReply(address, aVariant, aAccept, 0 /* passkey */,
+ sBtInterface->SspReply(aDeviceAddress, aVariant, aAccept, 0 /* passkey */,
new SspReplyResultHandler(aRunnable));
}
void
BluetoothServiceBluedroid::SetPairingConfirmationInternal(
- const nsAString& aDeviceAddress, bool aConfirm,
+ const BluetoothAddress& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable)
{
// Legacy method used by BlueZ only.
}
void
BluetoothServiceBluedroid::NextBluetoothProfileController()
{
@@ -1528,58 +1487,51 @@ BluetoothServiceBluedroid::NextBluetooth
// Start the next task if task array is not empty
if (!sControllerArray.IsEmpty()) {
sControllerArray[0]->StartSession();
}
}
void
BluetoothServiceBluedroid::ConnectDisconnect(
- bool aConnect, const nsAString& aDeviceAddress,
+ bool aConnect, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable,
uint16_t aServiceUuid, uint32_t aCod)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aRunnable);
- BluetoothAddress address;
- nsresult rv = StringToAddress(aDeviceAddress, address);
- if (NS_FAILED(rv)) {
- DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
- return;
- }
-
BluetoothProfileController* controller =
- new BluetoothProfileController(aConnect, address, aRunnable,
+ new BluetoothProfileController(aConnect, aDeviceAddress, aRunnable,
NextBluetoothProfileController,
aServiceUuid, aCod);
sControllerArray.AppendElement(controller);
/**
* If the request is the first element of the queue, start from here. Note
* that other requests are pushed into the queue and popped out after the
* first one is completed. See NextBluetoothProfileController() for details.
*/
if (sControllerArray.Length() == 1) {
sControllerArray[0]->StartSession();
}
}
void
-BluetoothServiceBluedroid::Connect(const nsAString& aDeviceAddress,
+BluetoothServiceBluedroid::Connect(const BluetoothAddress& aDeviceAddress,
uint32_t aCod,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
ConnectDisconnect(true, aDeviceAddress, aRunnable, aServiceUuid, aCod);
}
void
BluetoothServiceBluedroid::Disconnect(
- const nsAString& aDeviceAddress, uint16_t aServiceUuid,
+ const BluetoothAddress& aDeviceAddress, uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
ConnectDisconnect(false, aDeviceAddress, aRunnable, aServiceUuid);
}
void
BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress,
BlobParent* aBlobParent,
--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.h
+++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.h
@@ -45,21 +45,22 @@ public:
virtual nsresult GetAdaptersInternal(BluetoothReplyRunnable* aRunnable);
virtual nsresult
GetConnectedDevicePropertiesInternal(uint16_t aProfileId,
BluetoothReplyRunnable* aRunnable);
virtual nsresult
- GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddress,
- BluetoothReplyRunnable* aRunnable);
+ GetPairedDevicePropertiesInternal(
+ const nsTArray<BluetoothAddress>& aDeviceAddress,
+ BluetoothReplyRunnable* aRunnable);
virtual nsresult
- FetchUuidsInternal(const nsAString& aDeviceAddress,
+ FetchUuidsInternal(const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
virtual void StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
virtual nsresult
SetProperty(BluetoothObjectType aType,
const BluetoothNamedValue& aValue,
@@ -70,58 +71,58 @@ public:
const BluetoothUuid& aServiceUuid,
BluetoothProfileManagerBase* aManager);
virtual bool
UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
BluetoothProfileManagerBase* aManager);
virtual nsresult
- CreatePairedDeviceInternal(const nsAString& aDeviceAddress,
+ CreatePairedDeviceInternal(const BluetoothAddress& aDeviceAddress,
int aTimeout,
BluetoothReplyRunnable* aRunnable);
virtual nsresult
- RemoveDeviceInternal(const nsAString& aDeviceObjectPath,
+ RemoveDeviceInternal(const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable);
virtual void
- PinReplyInternal(const nsAString& aDeviceAddress,
+ PinReplyInternal(const BluetoothAddress& aDeviceAddress,
bool aAccept,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable);
virtual void
- SspReplyInternal(const nsAString& aDeviceAddress,
+ SspReplyInternal(const BluetoothAddress& aDeviceAddress,
BluetoothSspVariant aVariant,
bool aAccept,
BluetoothReplyRunnable* aRunnable);
virtual void
- SetPinCodeInternal(const nsAString& aDeviceAddress,
+ SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable);
virtual void
- SetPasskeyInternal(const nsAString& aDeviceAddress,
+ SetPasskeyInternal(const BluetoothAddress& aDeviceAddress,
uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable);
virtual void
- SetPairingConfirmationInternal(const nsAString& aDeviceAddress,
+ SetPairingConfirmationInternal(const BluetoothAddress& aDeviceAddress,
bool aConfirm,
BluetoothReplyRunnable* aRunnable);
virtual void
- Connect(const nsAString& aDeviceAddress,
+ Connect(const BluetoothAddress& aDeviceAddress,
uint32_t aCod,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable);
virtual void
- Disconnect(const nsAString& aDeviceAddress, uint16_t aServiceUuid,
+ Disconnect(const BluetoothAddress& aDeviceAddress, uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable);
virtual void
SendFile(const nsAString& aDeviceAddress,
BlobParent* aBlobParent,
BlobChild* aBlobChild,
BluetoothReplyRunnable* aRunnable);
@@ -484,17 +485,17 @@ public:
protected:
static nsresult StartGonkBluetooth();
static nsresult StopGonkBluetooth();
static ControlPlayStatus PlayStatusStringToControlPlayStatus(
const nsAString& aPlayStatus);
static void ConnectDisconnect(bool aConnect,
- const nsAString& aDeviceAddress,
+ const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable,
uint16_t aServiceUuid, uint32_t aCod = 0);
static void NextBluetoothProfileController();
// Adapter properties
BluetoothAddress mBdAddress;
nsString mBdName;
bool mEnabled;
--- a/dom/bluetooth/bluez/BluetoothDBusService.cpp
+++ b/dom/bluetooth/bluez/BluetoothDBusService.cpp
@@ -2698,17 +2698,17 @@ BluetoothDBusService::StartDiscoveryInte
{
SendDiscoveryMessage("StartDiscovery", aRunnable);
}
class BluetoothArrayOfDevicePropertiesReplyHandler : public DBusReplyHandler
{
public:
BluetoothArrayOfDevicePropertiesReplyHandler(
- const nsTArray<nsString>& aDeviceAddresses,
+ const nsTArray<BluetoothAddress>& aDeviceAddresses,
const FilterFunc aFilterFunc, BluetoothReplyRunnable* aRunnable)
: mDeviceAddresses(aDeviceAddresses)
, mProcessedDeviceAddresses(0)
, mFilterFunc(aFilterFunc)
, mRunnable(aRunnable)
, mValues(InfallibleTArray<BluetoothNamedValue>())
{
MOZ_ASSERT(mRunnable);
@@ -2767,18 +2767,21 @@ public:
NS_LITERAL_STRING("audio-card")));
}
break;
}
}
}
if (mFilterFunc(deviceProperties)) {
+ nsString deviceAddressStr;
+ AddressToString(mDeviceAddresses[i], deviceAddressStr);
+
mValues.get_ArrayOfBluetoothNamedValue().AppendElement(
- BluetoothNamedValue(mDeviceAddresses[i], deviceProperties));
+ BluetoothNamedValue(deviceAddressStr, deviceProperties));
}
ProcessRemainingDeviceAddresses();
}
void ProcessRemainingDeviceAddresses()
{
if (mProcessedDeviceAddresses < mDeviceAddresses.Length()) {
@@ -2817,17 +2820,17 @@ protected:
Unused << handler.forget(); // picked up by callback handler
return true;
}
private:
nsString mObjectPath;
- const nsTArray<nsString> mDeviceAddresses;
+ const nsTArray<BluetoothAddress> mDeviceAddresses;
nsTArray<nsString>::size_type mProcessedDeviceAddresses;
const FilterFunc mFilterFunc;
RefPtr<BluetoothReplyRunnable> mRunnable;
BluetoothValue mValues;
};
class ProcessRemainingDeviceAddressesTask : public Task
{
@@ -2863,49 +2866,46 @@ BluetoothDBusService::GetConnectedDevice
nsAutoString errorStr;
BluetoothValue values = InfallibleTArray<BluetoothNamedValue>();
if (!IsReady()) {
NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
return NS_OK;
}
- nsTArray<nsString> deviceAddresses;
+ nsTArray<BluetoothAddress> deviceAddresses;
+
BluetoothProfileManagerBase* profile =
BluetoothUuidHelper::GetBluetoothProfileManager(aServiceUuid);
if (!profile) {
DispatchBluetoothReply(aRunnable, values,
NS_LITERAL_STRING(ERR_UNKNOWN_PROFILE));
return NS_OK;
}
if (profile->IsConnected()) {
BluetoothAddress address;
profile->GetAddress(address);
-
- nsAutoString addressStr;
- AddressToString(address, addressStr);
-
- deviceAddresses.AppendElement(addressStr);
+ deviceAddresses.AppendElement(address);
}
BluetoothArrayOfDevicePropertiesReplyHandler* handler =
new BluetoothArrayOfDevicePropertiesReplyHandler(deviceAddresses,
GetConnectedDevicesFilter,
aRunnable);
Task* task = new ProcessRemainingDeviceAddressesTask(handler, aRunnable);
DispatchToDBusThread(task);
return NS_OK;
}
nsresult
BluetoothDBusService::GetPairedDevicePropertiesInternal(
- const nsTArray<nsString>& aDeviceAddresses,
- BluetoothReplyRunnable* aRunnable)
+ const nsTArray<BluetoothAddress>& aDeviceAddresses,
+ BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
if (!IsReady()) {
NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
return NS_OK;
}
@@ -2916,17 +2916,17 @@ BluetoothDBusService::GetPairedDevicePro
aRunnable);
Task* task = new ProcessRemainingDeviceAddressesTask(handler, aRunnable);
DispatchToDBusThread(task);
return NS_OK;
}
nsresult
-BluetoothDBusService::FetchUuidsInternal(const nsAString& aDeviceAddress,
+BluetoothDBusService::FetchUuidsInternal(const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable)
{
return NS_OK;
}
class SetPropertyTask : public Task
{
public:
@@ -3087,34 +3087,38 @@ BluetoothDBusService::SetProperty(Blueto
DispatchToDBusThread(task);
return NS_OK;
}
class CreatePairedDeviceInternalTask : public Task
{
public:
- CreatePairedDeviceInternalTask(const nsACString& aDeviceAddress,
+ CreatePairedDeviceInternalTask(const BluetoothAddress& aDeviceAddress,
int aTimeout,
BluetoothReplyRunnable* aRunnable)
: mDeviceAddress(aDeviceAddress)
, mTimeout(aTimeout)
, mRunnable(aRunnable)
{
- MOZ_ASSERT(!mDeviceAddress.IsEmpty());
+ MOZ_ASSERT(!mDeviceAddress.IsCleared());
MOZ_ASSERT(mRunnable);
}
void Run() override
{
MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
MOZ_ASSERT(sDBusConnection);
MOZ_ASSERT(!sAdapterPath.IsEmpty());
- const char *deviceAddress = mDeviceAddress.get();
+ nsString deviceAddressStr;
+ AddressToString(mDeviceAddress, deviceAddressStr);
+ auto utf8DeviceAddressStr = NS_ConvertUTF16toUTF8(deviceAddressStr);
+
+ const char *deviceAddress = utf8DeviceAddressStr.get();
const char *deviceAgentPath = KEY_REMOTE_AGENT;
const char *capabilities = B2G_AGENT_CAPABILITIES;
// Then send CreatePairedDevice, it will register a temp device agent then
// unregister it after pairing process is over
bool success = sDBusConnection->SendWithReply(
GetObjectPathCallback, static_cast<void*>(mRunnable), mTimeout,
BLUEZ_DBUS_BASE_IFC,
@@ -3140,30 +3144,30 @@ public:
* solution.
*
* Please see Bug 818696 for more information.
*/
sIsPairing++;
}
private:
- const nsCString mDeviceAddress;
+ BluetoothAddress mDeviceAddress;
int mTimeout;
RefPtr<BluetoothReplyRunnable> mRunnable;
};
nsresult
BluetoothDBusService::CreatePairedDeviceInternal(
- const nsAString& aDeviceAddress,
- int aTimeout,
- BluetoothReplyRunnable* aRunnable)
+ const BluetoothAddress& aDeviceAddress,
+ int aTimeout,
+ BluetoothReplyRunnable* aRunnable)
{
- Task* task = new CreatePairedDeviceInternalTask(
- NS_ConvertUTF16toUTF8(aDeviceAddress),
- aTimeout, aRunnable);
+ Task* task = new CreatePairedDeviceInternalTask(aDeviceAddress,
+ aTimeout,
+ aRunnable);
DispatchToDBusThread(task);
return NS_OK;
}
class RemoveDeviceTask : public Task
{
public:
@@ -3216,35 +3220,29 @@ protected:
}
private:
const BluetoothAddress mDeviceAddress;
RefPtr<BluetoothReplyRunnable> mRunnable;
};
nsresult
-BluetoothDBusService::RemoveDeviceInternal(const nsAString& aDeviceAddress,
- BluetoothReplyRunnable* aRunnable)
+BluetoothDBusService::RemoveDeviceInternal(
+ const BluetoothAddress& aDeviceAddress,
+ BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
if (!IsReady()) {
NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
return NS_OK;
}
- BluetoothAddress deviceAddress;
- auto rv = StringToAddress(aDeviceAddress, deviceAddress);
- if (NS_FAILED(rv)) {
- DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
- return rv;
- }
-
- Task* task = new RemoveDeviceTask(deviceAddress, aRunnable);
+ Task* task = new RemoveDeviceTask(aDeviceAddress, aRunnable);
DispatchToDBusThread(task);
return NS_OK;
}
class SetPinCodeTask : public Task
{
public:
@@ -3305,43 +3303,36 @@ public:
private:
const BluetoothAddress mDeviceAddress;
const nsCString mPinCode;
RefPtr<BluetoothReplyRunnable> mRunnable;
};
void
BluetoothDBusService::PinReplyInternal(
- const nsAString& aDeviceAddress, bool aAccept,
+ const BluetoothAddress& aDeviceAddress, bool aAccept,
const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable)
{
// Legacy interface used by Bluedroid only.
}
void
BluetoothDBusService::SspReplyInternal(
- const nsAString& aDeviceAddress, BluetoothSspVariant aVariant,
+ const BluetoothAddress& aDeviceAddress, BluetoothSspVariant aVariant,
bool aAccept, BluetoothReplyRunnable* aRunnable)
{
// Legacy interface used by Bluedroid only.
}
void
-BluetoothDBusService::SetPinCodeInternal(const nsAString& aDeviceAddress,
+BluetoothDBusService::SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable)
{
- BluetoothAddress deviceAddress;
- auto rv = StringToAddress(aDeviceAddress, deviceAddress);
- if (NS_FAILED(rv)) {
- DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
- return;
- }
-
- Task* task = new SetPinCodeTask(deviceAddress,
+ Task* task = new SetPinCodeTask(aDeviceAddress,
NS_ConvertUTF16toUTF8(aPinCode),
aRunnable);
DispatchToDBusThread(task);
}
class SetPasskeyTask : public Task
{
public:
@@ -3401,47 +3392,36 @@ public:
private:
BluetoothAddress mDeviceAddress;
uint32_t mPasskey;
RefPtr<BluetoothReplyRunnable> mRunnable;
};
void
-BluetoothDBusService::SetPasskeyInternal(const nsAString& aDeviceAddress,
- uint32_t aPasskey,
- BluetoothReplyRunnable* aRunnable)
+BluetoothDBusService::SetPasskeyInternal(
+ const BluetoothAddress& aDeviceAddress,
+ uint32_t aPasskey,
+ BluetoothReplyRunnable* aRunnable)
{
- BluetoothAddress deviceAddress;
- if (NS_FAILED(StringToAddress(aDeviceAddress, deviceAddress))) {
- DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
- return;
- }
-
- Task* task = new SetPasskeyTask(deviceAddress,
+ Task* task = new SetPasskeyTask(aDeviceAddress,
aPasskey,
aRunnable);
DispatchToDBusThread(task);
}
void
BluetoothDBusService::SetPairingConfirmationInternal(
- const nsAString& aDeviceAddress,
- bool aConfirm,
- BluetoothReplyRunnable* aRunnable)
+ const BluetoothAddress& aDeviceAddress,
+ bool aConfirm,
+ BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
- BluetoothAddress deviceAddress;
- if (NS_FAILED(StringToAddress(aDeviceAddress, deviceAddress))) {
- DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
- return;
- }
-
- Task* task = new SetPairingConfirmationTask(deviceAddress,
+ Task* task = new SetPairingConfirmationTask(aDeviceAddress,
aConfirm,
aRunnable);
DispatchToDBusThread(task);
}
static void
NextBluetoothProfileController()
{
@@ -3452,57 +3432,50 @@ NextBluetoothProfileController()
sControllerArray.RemoveElementAt(0);
// Re-check if the task array is empty, if it's not, the next task will begin.
NS_ENSURE_FALSE_VOID(sControllerArray.IsEmpty());
sControllerArray[0]->StartSession();
}
static void
-ConnectDisconnect(bool aConnect, const nsAString& aDeviceAddress,
+ConnectDisconnect(bool aConnect, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable,
uint16_t aServiceUuid, uint32_t aCod = 0)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aRunnable);
- BluetoothAddress deviceAddress;
- nsresult rv = StringToAddress(aDeviceAddress, deviceAddress);
- if (NS_FAILED(rv)) {
- DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
- return;
- }
-
BluetoothProfileController* controller =
- new BluetoothProfileController(aConnect, deviceAddress, aRunnable,
+ new BluetoothProfileController(aConnect, aDeviceAddress, aRunnable,
NextBluetoothProfileController,
aServiceUuid, aCod);
sControllerArray.AppendElement(controller);
/**
* If the request is the first element of the quene, start from here. Note
* that other request is pushed into the quene and is popped out after the
* first one is completed. See NextBluetoothProfileController() for details.
*/
if (sControllerArray.Length() == 1) {
sControllerArray[0]->StartSession();
}
}
void
-BluetoothDBusService::Connect(const nsAString& aDeviceAddress,
+BluetoothDBusService::Connect(const BluetoothAddress& aDeviceAddress,
uint32_t aCod,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
ConnectDisconnect(true, aDeviceAddress, aRunnable, aServiceUuid, aCod);
}
void
-BluetoothDBusService::Disconnect(const nsAString& aDeviceAddress,
+BluetoothDBusService::Disconnect(const BluetoothAddress& aDeviceAddress,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
ConnectDisconnect(false, aDeviceAddress, aRunnable, aServiceUuid);
}
#ifdef MOZ_B2G_RIL
void
@@ -3537,26 +3510,23 @@ BluetoothDBusService::ToggleCalls(Blueto
DispatchBluetoothReply(aRunnable, BluetoothValue(true), EmptyString());
}
#endif // MOZ_B2G_RIL
class OnUpdateSdpRecordsRunnable : public nsRunnable
{
public:
- OnUpdateSdpRecordsRunnable(const nsAString& aObjectPath,
+ OnUpdateSdpRecordsRunnable(const BluetoothAddress& aDeviceAddress,
BluetoothProfileManagerBase* aManager)
- : mManager(aManager)
+ : mDeviceAddress(aDeviceAddress)
+ , mManager(aManager)
{
- MOZ_ASSERT(!aObjectPath.IsEmpty());
- MOZ_ASSERT(aManager);
-
- const nsString deviceAddressStr = GetAddressFromObjectPath(aObjectPath);
-
- StringToAddress(deviceAddressStr, mDeviceAddress);
+ MOZ_ASSERT(!mDeviceAddress.IsCleared());
+ MOZ_ASSERT(mManager);
}
nsresult
Run()
{
MOZ_ASSERT(NS_IsMainThread());
mManager->OnUpdateSdpRecords(mDeviceAddress);
@@ -3753,17 +3723,17 @@ public:
MOZ_ASSERT(!sAdapterPath.IsEmpty());
const nsString objectPath =
GetObjectPathFromAddress(sAdapterPath, mDeviceAddress);
// I choose to use raw pointer here because this is going to be passed as an
// argument into SendWithReply() at once.
OnUpdateSdpRecordsRunnable* callbackRunnable =
- new OnUpdateSdpRecordsRunnable(objectPath, mBluetoothProfileManager);
+ new OnUpdateSdpRecordsRunnable(mDeviceAddress, mBluetoothProfileManager);
sDBusConnection->SendWithReply(DiscoverServicesCallback,
(void*)callbackRunnable, -1,
BLUEZ_DBUS_BASE_IFC,
NS_ConvertUTF16toUTF8(objectPath).get(),
DBUS_DEVICE_IFACE,
"DiscoverServices",
DBUS_TYPE_STRING, &EmptyCString(),
--- a/dom/bluetooth/bluez/BluetoothDBusService.h
+++ b/dom/bluetooth/bluez/BluetoothDBusService.h
@@ -54,21 +54,22 @@ public:
virtual nsresult
GetAdaptersInternal(BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
GetConnectedDevicePropertiesInternal(
uint16_t aServiceUuid, BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
- GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddresses,
- BluetoothReplyRunnable* aRunnable) override;
+ GetPairedDevicePropertiesInternal(
+ const nsTArray<BluetoothAddress>& aDeviceAddresses,
+ BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
- FetchUuidsInternal(const nsAString& aDeviceAddress,
+ FetchUuidsInternal(const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable) override;
virtual void
StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable) override;
@@ -82,56 +83,58 @@ public:
const BluetoothUuid& aServiceUuid,
BluetoothProfileManagerBase* aManager) override;
virtual bool
UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
BluetoothProfileManagerBase* aManager) override;
virtual nsresult
- CreatePairedDeviceInternal(const nsAString& aDeviceAddress,
+ CreatePairedDeviceInternal(const BluetoothAddress& aDeviceAddress,
int aTimeout,
BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
- RemoveDeviceInternal(const nsAString& aDeviceObjectPath,
+ RemoveDeviceInternal(const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- PinReplyInternal(const nsAString& aDeviceAddress,
+ PinReplyInternal(const BluetoothAddress& aDeviceAddress,
bool aAccept,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable);
virtual void
- SspReplyInternal(const nsAString& aDeviceAddress,
+ SspReplyInternal(const BluetoothAddress& aDeviceAddress,
BluetoothSspVariant aVariant,
bool aAccept,
BluetoothReplyRunnable* aRunnable);
virtual void
- SetPinCodeInternal(const nsAString& aDeviceAddress, const nsAString& aPinCode,
+ SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
+ const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey,
+ SetPasskeyInternal(const BluetoothAddress& aDeviceAddress, uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm,
+ SetPairingConfirmationInternal(const BluetoothAddress& aDeviceAddress,
+ bool aConfirm,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- Connect(const nsAString& aDeviceAddress,
+ Connect(const BluetoothAddress& aDeviceAddress,
uint32_t aCod,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- Disconnect(const nsAString& aDeviceAddress, uint16_t aServiceUuid,
+ Disconnect(const BluetoothAddress& aDeviceAddress, uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable) override;
virtual void
SendFile(const nsAString& aDeviceAddress,
BlobParent* aBlobParent,
BlobChild* aBlobChild,
BluetoothReplyRunnable* aRunnable) override;
--- a/dom/bluetooth/common/BluetoothService.h
+++ b/dom/bluetooth/common/BluetoothService.h
@@ -144,18 +144,19 @@ public:
/**
* Returns the properties of paired devices, implemented via a platform
* specific method.
*
* @return NS_OK on success, NS_ERROR_FAILURE otherwise
*/
virtual nsresult
- GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddresses,
- BluetoothReplyRunnable* aRunnable) = 0;
+ GetPairedDevicePropertiesInternal(
+ const nsTArray<BluetoothAddress>& aDeviceAddresses,
+ BluetoothReplyRunnable* aRunnable) = 0;
/**
* Returns the properties of connected devices regarding to specific profile,
* implemented via a platform specific methood.
*
* @return NS_OK on success, NS_ERROR_FAILURE otherwise
*/
virtual nsresult
@@ -164,17 +165,17 @@ public:
/**
* Returns up-to-date uuids of given device address,
* implemented via a platform specific methood.
*
* @return NS_OK on success, NS_ERROR_FAILURE otherwise
*/
virtual nsresult
- FetchUuidsInternal(const nsAString& aDeviceAddress,
+ FetchUuidsInternal(const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) = 0;
/**
* Stop device discovery (platform specific implementation)
*/
virtual void
StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable) = 0;
@@ -208,22 +209,22 @@ public:
* @return NS_OK if property is set correctly, NS_ERROR_FAILURE otherwise
*/
virtual nsresult
SetProperty(BluetoothObjectType aType,
const BluetoothNamedValue& aValue,
BluetoothReplyRunnable* aRunnable) = 0;
virtual nsresult
- CreatePairedDeviceInternal(const nsAString& aAddress,
+ CreatePairedDeviceInternal(const BluetoothAddress& aDeviceAddress,
int aTimeout,
BluetoothReplyRunnable* aRunnable) = 0;
virtual nsresult
- RemoveDeviceInternal(const nsAString& aObjectPath,
+ RemoveDeviceInternal(const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) = 0;
/**
* Get corresponding service channel of specific service on remote device.
* It's usually the very first step of establishing an outbound connection.
*
* @param aObjectPath Address of remote device
* @param aServiceUuid UUID of the target service
@@ -236,55 +237,57 @@ public:
const BluetoothUuid& aServiceUuid,
BluetoothProfileManagerBase* aManager) = 0;
virtual bool
UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
BluetoothProfileManagerBase* aManager) = 0;
virtual void
- PinReplyInternal(const nsAString& aDeviceAddress,
+ PinReplyInternal(const BluetoothAddress& aDeviceAddress,
bool aAccept,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void
- SspReplyInternal(const nsAString& aDeviceAddress,
+ SspReplyInternal(const BluetoothAddress& aDeviceAddress,
BluetoothSspVariant aVariant,
bool aAccept,
BluetoothReplyRunnable* aRunnable) = 0;
/**
* Legacy method used by bluez only to reply pincode request.
*/
virtual void
- SetPinCodeInternal(const nsAString& aDeviceAddress,
+ SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable) = 0;
/**
* Legacy method used by bluez only to reply passkey entry request.
*/
virtual void
- SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey,
+ SetPasskeyInternal(const BluetoothAddress& aDeviceAddress, uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable) = 0;
/**
* Legacy method used by bluez only to reply pairing confirmation request.
*/
virtual void
- SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm,
+ SetPairingConfirmationInternal(const BluetoothAddress& aDeviceAddress,
+ bool aConfirm,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void
- Connect(const nsAString& aDeviceAddress, uint32_t aCod, uint16_t aServiceUuid,
+ Connect(const BluetoothAddress& aDeviceAddress,
+ uint32_t aCod, uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void
- Disconnect(const nsAString& aDeviceAddress, uint16_t aServiceUuid,
+ Disconnect(const BluetoothAddress& aDeviceAddress, uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void
SendFile(const nsAString& aDeviceAddress,
BlobParent* aBlobParent,
BlobChild* aBlobChild,
BluetoothReplyRunnable* aRunnable) = 0;
--- a/dom/bluetooth/common/webapi/BluetoothAdapter.cpp
+++ b/dom/bluetooth/common/webapi/BluetoothAdapter.cpp
@@ -400,23 +400,34 @@ BluetoothAdapter::GetGattServer()
void
BluetoothAdapter::GetPairedDeviceProperties(
const nsTArray<nsString>& aDeviceAddresses)
{
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
+ nsTArray<BluetoothAddress> deviceAddresses;
+ deviceAddresses.SetLength(aDeviceAddresses.Length());
+
+ for (size_t i = 0; i < deviceAddresses.Length(); ++i) {
+ auto rv = StringToAddress(aDeviceAddresses[i], deviceAddresses[i]);
+ if (NS_FAILED(rv)) {
+ BT_WARNING("GetPairedDeviceProperties failed");
+ return;
+ }
+ }
+
RefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(nullptr);
- nsresult rv =
- bs->GetPairedDevicePropertiesInternal(aDeviceAddresses, results);
+ auto rv = bs->GetPairedDevicePropertiesInternal(deviceAddresses, results);
if (NS_FAILED(rv)) {
BT_WARNING("GetPairedDeviceProperties failed");
+ return;
}
}
void
BluetoothAdapter::SetPropertyByValue(const BluetoothNamedValue& aValue)
{
const nsString& name = aValue.name();
const BluetoothValue& value = aValue.value();
@@ -846,36 +857,38 @@ BluetoothAdapter::PairUnpair(bool aPair,
return nullptr;
}
RefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
/**
* Ensure
- * - device address is not empty,
+ * - device address is valid,
* - adapter is already enabled, and
* - BluetoothService is available.
*/
- BT_ENSURE_TRUE_REJECT(!aDeviceAddress.IsEmpty(),
+ BluetoothAddress deviceAddress;
+ BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToAddress(aDeviceAddress,
+ deviceAddress)),
promise,
NS_ERROR_DOM_INVALID_STATE_ERR);
BT_ENSURE_TRUE_REJECT(mState == BluetoothAdapterState::Enabled,
promise,
NS_ERROR_DOM_INVALID_STATE_ERR);
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
nsresult rv;
if (aPair) {
rv = bs->CreatePairedDeviceInternal(
- aDeviceAddress, kCreatePairedDeviceTimeout,
+ deviceAddress, kCreatePairedDeviceTimeout,
new BluetoothVoidReplyRunnable(nullptr, promise));
} else {
- rv = bs->RemoveDeviceInternal(aDeviceAddress,
+ rv = bs->RemoveDeviceInternal(deviceAddress,
new BluetoothVoidReplyRunnable(nullptr, promise));
}
BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(rv), promise, NS_ERROR_DOM_OPERATION_ERR);
return promise.forget();
}
already_AddRefed<Promise>
@@ -1656,28 +1669,34 @@ BluetoothAdapter::Connect(BluetoothDevic
}
RefPtr<DOMRequest> request = new DOMRequest(win);
RefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(request);
nsAutoString address;
aDevice.GetAddress(address);
+ BluetoothAddress deviceAddress;
+ if (NS_FAILED(StringToAddress(address, deviceAddress))) {
+ aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+ return nullptr;
+ }
+
uint32_t deviceClass = aDevice.Cod()->ToUint32();
uint16_t serviceUuid = 0;
if (aServiceUuid.WasPassed()) {
serviceUuid = aServiceUuid.Value();
}
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
- bs->Connect(address, deviceClass, serviceUuid, results);
+ bs->Connect(deviceAddress, deviceClass, serviceUuid, results);
return request.forget();
}
already_AddRefed<DOMRequest>
BluetoothAdapter::Disconnect(BluetoothDevice& aDevice,
const Optional<short unsigned int>& aServiceUuid,
ErrorResult& aRv)
@@ -1689,27 +1708,33 @@ BluetoothAdapter::Disconnect(BluetoothDe
}
RefPtr<DOMRequest> request = new DOMRequest(win);
RefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(request);
nsAutoString address;
aDevice.GetAddress(address);
+ BluetoothAddress deviceAddress;
+ if (NS_FAILED(StringToAddress(address, deviceAddress))) {
+ aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+ return nullptr;
+ }
+
uint16_t serviceUuid = 0;
if (aServiceUuid.WasPassed()) {
serviceUuid = aServiceUuid.Value();
}
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
- bs->Disconnect(address, serviceUuid, results);
+ bs->Disconnect(deviceAddress, serviceUuid, results);
return request.forget();
}
already_AddRefed<DOMRequest>
BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
Blob& aBlob, ErrorResult& aRv)
{
--- a/dom/bluetooth/common/webapi/BluetoothDevice.cpp
+++ b/dom/bluetooth/common/webapi/BluetoothDevice.cpp
@@ -182,20 +182,23 @@ BluetoothDevice::FetchUuids(ErrorResult&
}
RefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
// Ensure BluetoothService is available
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
-
+ BluetoothAddress address;
+ BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToAddress(mAddress, address)),
+ promise,
+ NS_ERROR_DOM_INVALID_STATE_ERR);
BT_ENSURE_TRUE_REJECT(
NS_SUCCEEDED(
- bs->FetchUuidsInternal(mAddress, new FetchUuidsTask(promise, this))),
+ bs->FetchUuidsInternal(address, new FetchUuidsTask(promise, this))),
promise, NS_ERROR_DOM_OPERATION_ERR);
return promise.forget();
}
// static
already_AddRefed<BluetoothDevice>
BluetoothDevice::Create(nsPIDOMWindow* aWindow,
--- a/dom/bluetooth/common/webapi/BluetoothPairingHandle.cpp
+++ b/dom/bluetooth/common/webapi/BluetoothPairingHandle.cpp
@@ -4,16 +4,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "BluetoothCommon.h"
#include "BluetoothDevice.h"
#include "BluetoothPairingHandle.h"
#include "BluetoothReplyRunnable.h"
#include "BluetoothService.h"
+#include "BluetoothUtils.h"
#include "mozilla/dom/BluetoothPairingHandleBinding.h"
#include "mozilla/dom/Promise.h"
using namespace mozilla;
using namespace dom;
USING_BLUETOOTH_NAMESPACE
@@ -74,20 +75,26 @@ BluetoothPairingHandle::SetPinCode(const
RefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
BT_ENSURE_TRUE_REJECT(mType.EqualsLiteral(PAIRING_REQ_TYPE_ENTERPINCODE),
promise,
NS_ERROR_DOM_INVALID_STATE_ERR);
+ BluetoothAddress deviceAddress;
+ BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToAddress(mDeviceAddress,
+ deviceAddress)),
+ promise,
+ NS_ERROR_DOM_INVALID_STATE_ERR);
+
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
- bs->PinReplyInternal(mDeviceAddress, true /* accept */, aPinCode,
+ bs->PinReplyInternal(deviceAddress, true /* accept */, aPinCode,
new BluetoothVoidReplyRunnable(nullptr, promise));
return promise.forget();
}
already_AddRefed<Promise>
BluetoothPairingHandle::Accept(ErrorResult& aRv)
{
@@ -103,22 +110,28 @@ BluetoothPairingHandle::Accept(ErrorResu
BT_ENSURE_TRUE_REJECT(mType.EqualsLiteral(PAIRING_REQ_TYPE_CONFIRMATION) ||
mType.EqualsLiteral(PAIRING_REQ_TYPE_CONSENT),
promise,
NS_ERROR_DOM_INVALID_STATE_ERR);
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
+ BluetoothAddress deviceAddress;
+ BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToAddress(mDeviceAddress,
+ deviceAddress)),
+ promise,
+ NS_ERROR_DOM_INVALID_STATE_ERR);
+
BluetoothSspVariant variant;
BT_ENSURE_TRUE_REJECT(GetSspVariant(variant),
promise,
NS_ERROR_DOM_OPERATION_ERR);
- bs->SspReplyInternal(mDeviceAddress, variant, true /* aAccept */,
+ bs->SspReplyInternal(deviceAddress, variant, true /* aAccept */,
new BluetoothVoidReplyRunnable(nullptr, promise));
return promise.forget();
}
already_AddRefed<Promise>
BluetoothPairingHandle::Reject(ErrorResult& aRv)
{
@@ -126,29 +139,35 @@ BluetoothPairingHandle::Reject(ErrorResu
if (!global) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
RefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
+ BluetoothAddress deviceAddress;
+ BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToAddress(mDeviceAddress,
+ deviceAddress)),
+ promise,
+ NS_ERROR_DOM_INVALID_STATE_ERR);
+
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
if (mType.EqualsLiteral(PAIRING_REQ_TYPE_ENTERPINCODE)) { // Pin request
- bs->PinReplyInternal(mDeviceAddress, false /* aAccept */, EmptyString(),
+ bs->PinReplyInternal(deviceAddress, false /* aAccept */, EmptyString(),
new BluetoothVoidReplyRunnable(nullptr, promise));
} else { // Ssp request
BluetoothSspVariant variant;
BT_ENSURE_TRUE_REJECT(GetSspVariant(variant),
promise,
NS_ERROR_DOM_OPERATION_ERR);
- bs->SspReplyInternal(mDeviceAddress, variant, false /* aAccept */,
+ bs->SspReplyInternal(deviceAddress, variant, false /* aAccept */,
new BluetoothVoidReplyRunnable(nullptr, promise));
}
return promise.forget();
}
bool
BluetoothPairingHandle::GetSspVariant(BluetoothSspVariant& aVariant)
--- a/dom/bluetooth/ipc/BluetoothParent.cpp
+++ b/dom/bluetooth/ipc/BluetoothParent.cpp
@@ -594,58 +594,58 @@ BluetoothRequestParent::DoRequest(const
}
bool
BluetoothRequestParent::DoRequest(const SetPinCodeRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TSetPinCodeRequest);
- mService->SetPinCodeInternal(aRequest.path(),
+ mService->SetPinCodeInternal(aRequest.address(),
aRequest.pincode(),
mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const SetPasskeyRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TSetPasskeyRequest);
- mService->SetPasskeyInternal(aRequest.path(),
+ mService->SetPasskeyInternal(aRequest.address(),
aRequest.passkey(),
mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const ConfirmPairingConfirmationRequest&
aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TConfirmPairingConfirmationRequest);
- mService->SetPairingConfirmationInternal(aRequest.path(),
+ mService->SetPairingConfirmationInternal(aRequest.address(),
true,
mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const DenyPairingConfirmationRequest&
aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TDenyPairingConfirmationRequest);
- mService->SetPairingConfirmationInternal(aRequest.path(),
+ mService->SetPairingConfirmationInternal(aRequest.address(),
false,
mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const ConnectRequest& aRequest)
--- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
+++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp
@@ -124,31 +124,31 @@ BluetoothServiceChildProcess::GetConnect
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, ConnectedDevicePropertiesRequest(aServiceUuid));
return NS_OK;
}
nsresult
BluetoothServiceChildProcess::GetPairedDevicePropertiesInternal(
- const nsTArray<nsString>& aDeviceAddresses,
- BluetoothReplyRunnable* aRunnable)
+ const nsTArray<BluetoothAddress>& aDeviceAddresses,
+ BluetoothReplyRunnable* aRunnable)
{
PairedDevicePropertiesRequest request;
request.addresses().AppendElements(aDeviceAddresses);
SendRequest(aRunnable, request);
return NS_OK;
}
nsresult
BluetoothServiceChildProcess::FetchUuidsInternal(
- const nsAString& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
+ const BluetoothAddress& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
{
- SendRequest(aRunnable, FetchUuidsRequest(nsString(aDeviceAddress)));
+ SendRequest(aRunnable, FetchUuidsRequest(aDeviceAddress));
return NS_OK;
}
void
BluetoothServiceChildProcess::StopDiscoveryInternal(
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, StopDiscoveryRequest());
@@ -183,32 +183,28 @@ BluetoothServiceChildProcess::SetPropert
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, SetPropertyRequest(aType, aValue));
return NS_OK;
}
nsresult
BluetoothServiceChildProcess::CreatePairedDeviceInternal(
- const nsAString& aAddress,
- int aTimeout,
- BluetoothReplyRunnable* aRunnable)
+ const BluetoothAddress& aDeviceAddress, int aTimeout,
+ BluetoothReplyRunnable* aRunnable)
{
- SendRequest(aRunnable,
- PairRequest(nsString(aAddress), aTimeout));
+ SendRequest(aRunnable, PairRequest(aDeviceAddress, aTimeout));
return NS_OK;
}
nsresult
BluetoothServiceChildProcess::RemoveDeviceInternal(
- const nsAString& aObjectPath,
- BluetoothReplyRunnable* aRunnable)
+ const BluetoothAddress& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
{
- SendRequest(aRunnable,
- UnpairRequest(nsString(aObjectPath)));
+ SendRequest(aRunnable, UnpairRequest(aDeviceAddress));
return NS_OK;
}
nsresult
BluetoothServiceChildProcess::GetServiceChannel(const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
BluetoothProfileManagerBase* aManager)
{
@@ -219,92 +215,82 @@ bool
BluetoothServiceChildProcess::UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
BluetoothProfileManagerBase* aManager)
{
MOZ_CRASH("This should never be called!");
}
void
BluetoothServiceChildProcess::PinReplyInternal(
- const nsAString& aDeviceAddress, bool aAccept,
+ const BluetoothAddress& aDeviceAddress, bool aAccept,
const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
- PinReplyRequest(nsString(aDeviceAddress),
+ PinReplyRequest(aDeviceAddress,
aAccept,
nsString(aPinCode)));
}
void
BluetoothServiceChildProcess::SspReplyInternal(
- const nsAString& aDeviceAddress, BluetoothSspVariant aVariant,
- bool aAccept, BluetoothReplyRunnable* aRunnable)
+ const BluetoothAddress& aDeviceAddress,
+ BluetoothSspVariant aVariant, bool aAccept,
+ BluetoothReplyRunnable* aRunnable)
{
- SendRequest(aRunnable,
- SspReplyRequest(nsString(aDeviceAddress),
- aVariant,
- aAccept));
+ SendRequest(aRunnable, SspReplyRequest(aDeviceAddress, aVariant, aAccept));
}
void
BluetoothServiceChildProcess::SetPinCodeInternal(
- const nsAString& aDeviceAddress,
- const nsAString& aPinCode,
- BluetoothReplyRunnable* aRunnable)
+ const BluetoothAddress& aDeviceAddress,
+ const nsAString& aPinCode,
+ BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
- SetPinCodeRequest(nsString(aDeviceAddress), nsString(aPinCode)));
+ SetPinCodeRequest(aDeviceAddress, nsString(aPinCode)));
}
void
BluetoothServiceChildProcess::SetPasskeyInternal(
- const nsAString& aDeviceAddress,
- uint32_t aPasskey,
- BluetoothReplyRunnable* aRunnable)
+ const BluetoothAddress& aDeviceAddress,
+ uint32_t aPasskey,
+ BluetoothReplyRunnable* aRunnable)
{
- SendRequest(aRunnable,
- SetPasskeyRequest(nsString(aDeviceAddress), aPasskey));
+ SendRequest(aRunnable, SetPasskeyRequest(aDeviceAddress, aPasskey));
}
void
BluetoothServiceChildProcess::SetPairingConfirmationInternal(
- const nsAString& aDeviceAddress,
+ const BluetoothAddress& aDeviceAddress,
bool aConfirm,
BluetoothReplyRunnable* aRunnable)
{
- if(aConfirm) {
- SendRequest(aRunnable,
- ConfirmPairingConfirmationRequest(nsString(aDeviceAddress)));
+ if (aConfirm) {
+ SendRequest(aRunnable, ConfirmPairingConfirmationRequest(aDeviceAddress));
} else {
- SendRequest(aRunnable,
- DenyPairingConfirmationRequest(nsString(aDeviceAddress)));
+ SendRequest(aRunnable, DenyPairingConfirmationRequest(aDeviceAddress));
}
}
void
BluetoothServiceChildProcess::Connect(
- const nsAString& aDeviceAddress,
- uint32_t aCod,
- uint16_t aServiceUuid,
+ const BluetoothAddress& aDeviceAddress,
+ uint32_t aCod, uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
- SendRequest(aRunnable,
- ConnectRequest(nsString(aDeviceAddress),
- aCod,
- aServiceUuid));
+ SendRequest(aRunnable, ConnectRequest(aDeviceAddress, aCod, aServiceUuid));
}
void
BluetoothServiceChildProcess::Disconnect(
- const nsAString& aDeviceAddress,
+ const BluetoothAddress& aDeviceAddress,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
- SendRequest(aRunnable,
- DisconnectRequest(nsString(aDeviceAddress), aServiceUuid));
+ SendRequest(aRunnable, DisconnectRequest(aDeviceAddress, aServiceUuid));
}
void
BluetoothServiceChildProcess::SendFile(
const nsAString& aDeviceAddress,
BlobParent* aBlobParent,
BlobChild* aBlobChild,
BluetoothReplyRunnable* aRunnable)
--- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.h
+++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.h
@@ -36,26 +36,26 @@ public:
virtual nsresult
StartInternal(BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
StopInternal(BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
- GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddresses,
+ GetPairedDevicePropertiesInternal(const nsTArray<BluetoothAddress>& aDeviceAddresses,
BluetoothReplyRunnable* aRunnable)
override;
virtual nsresult
GetConnectedDevicePropertiesInternal(uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
override;
virtual nsresult
- FetchUuidsInternal(const nsAString& aDeviceAddress,
+ FetchUuidsInternal(const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable) override;
virtual void
StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable) override;
@@ -68,69 +68,69 @@ public:
BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
SetProperty(BluetoothObjectType aType,
const BluetoothNamedValue& aValue,
BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
- CreatePairedDeviceInternal(const nsAString& aAddress,
+ CreatePairedDeviceInternal(const BluetoothAddress& aDeviceAddress,
int aTimeout,
BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
- RemoveDeviceInternal(const nsAString& aObjectPath,
+ RemoveDeviceInternal(const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
GetServiceChannel(const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
BluetoothProfileManagerBase* aManager) override;
virtual bool
UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
BluetoothProfileManagerBase* aManager) override;
virtual void
- SetPinCodeInternal(const nsAString& aDeviceAddress,
+ SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- SetPasskeyInternal(const nsAString& aDeviceAddress,
+ SetPasskeyInternal(const BluetoothAddress& aDeviceAddress,
uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- SetPairingConfirmationInternal(const nsAString& aDeviceAddress,
+ SetPairingConfirmationInternal(const BluetoothAddress& aDeviceAddress,
bool aConfirm,
BluetoothReplyRunnable* aRunnable)
override;
virtual void
- PinReplyInternal(const nsAString& aDeviceAddress,
+ PinReplyInternal(const BluetoothAddress& aDeviceAddress,
bool aAccept,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- SspReplyInternal(const nsAString& aDeviceAddress,
+ SspReplyInternal(const BluetoothAddress& aDeviceAddress,
BluetoothSspVariant aVariant,
bool aAccept,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- Connect(const nsAString& aDeviceAddress,
+ Connect(const BluetoothAddress& aDeviceAddress,
uint32_t aCod,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- Disconnect(const nsAString& aDeviceAddress,
+ Disconnect(const BluetoothAddress& aDeviceAddress,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable) override;
virtual void
SendFile(const nsAString& aDeviceAddress,
BlobParent* aBlobParent,
BlobChild* aBlobChild,
BluetoothReplyRunnable* aRunnable) override;
--- a/dom/bluetooth/ipc/PBluetooth.ipdl
+++ b/dom/bluetooth/ipc/PBluetooth.ipdl
@@ -7,17 +7,20 @@
include protocol PBlob;
include protocol PBluetoothRequest;
include protocol PContent;
include BluetoothTypes;
include "mozilla/dom/bluetooth/ipc/BluetoothMessageUtils.h";
-using mozilla::dom::bluetooth::BluetoothObjectType from "mozilla/dom/bluetooth/BluetoothCommon.h";
+using mozilla::dom::bluetooth::BluetoothAddress
+ from "mozilla/dom/bluetooth/BluetoothCommon.h";
+using mozilla::dom::bluetooth::BluetoothObjectType
+ from "mozilla/dom/bluetooth/BluetoothCommon.h";
namespace mozilla {
namespace dom {
namespace bluetooth {
/**
* Bluetooth request types.
*/
@@ -37,17 +40,17 @@ struct SetPropertyRequest
{
BluetoothObjectType type;
BluetoothNamedValue value;
};
struct GetPropertyRequest
{
BluetoothObjectType type;
- nsString path;
+ BluetoothAddress address;
};
struct StartDiscoveryRequest
{
};
struct StopDiscoveryRequest
{
@@ -60,86 +63,86 @@ struct StartLeScanRequest
struct StopLeScanRequest
{
nsString scanUuid;
};
struct PairRequest
{
- nsString address;
+ BluetoothAddress address;
uint32_t timeoutMS;
};
struct UnpairRequest
{
- nsString address;
+ BluetoothAddress address;
};
struct PinReplyRequest
{
- nsString address;
+ BluetoothAddress address;
bool accept;
nsString pinCode;
};
struct SspReplyRequest
{
- nsString address;
+ BluetoothAddress address;
BluetoothSspVariant variant;
bool accept;
};
struct SetPinCodeRequest
{
- nsString path;
+ BluetoothAddress address;
nsString pincode;
};
struct SetPasskeyRequest
{
- nsString path;
+ BluetoothAddress address;
uint32_t passkey;
};
struct ConfirmPairingConfirmationRequest
{
- nsString path;
+ BluetoothAddress address;
};
struct DenyPairingConfirmationRequest
{
- nsString path;
+ BluetoothAddress address;
};
struct PairedDevicePropertiesRequest
{
- nsString[] addresses;
+ BluetoothAddress[] addresses;
};
struct ConnectedDevicePropertiesRequest
{
uint16_t serviceUuid;
};
struct FetchUuidsRequest
{
- nsString address;
+ BluetoothAddress address;
};
struct ConnectRequest
{
- nsString address;
+ BluetoothAddress address;
uint32_t cod;
uint16_t serviceUuid;
};
struct DisconnectRequest
{
- nsString address;
+ BluetoothAddress address;
uint16_t serviceUuid;
};
struct SendFileRequest
{
nsString devicePath;
PBlob blob;
};