--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
@@ -1023,37 +1023,43 @@ BluetoothServiceBluedroid::GetConnectedD
sBtInterface->GetRemoteDeviceProperties(address,
new GetRemoteDevicePropertiesResultHandler(mGetDeviceRequests, address));
return NS_OK;
}
nsresult
BluetoothServiceBluedroid::GetPairedDevicePropertiesInternal(
- const nsTArray<BluetoothAddress>& aDeviceAddress,
- BluetoothReplyRunnable* aRunnable)
+ const nsTArray<nsString>& 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(aDeviceAddress[i],
- new GetRemoteDevicePropertiesResultHandler(mGetDeviceRequests,
- aDeviceAddress[i]));
+ sBtInterface->GetRemoteDeviceProperties(address,
+ new GetRemoteDevicePropertiesResultHandler(mGetDeviceRequests, address));
}
return NS_OK;
}
class BluetoothServiceBluedroid::DispatchReplyErrorResultHandler final
: public BluetoothResultHandler
{
@@ -1089,32 +1095,39 @@ BluetoothServiceBluedroid::StartDiscover
mChangeDiscoveryRunnables.AppendElement(aRunnable);
sBtInterface->StartDiscovery(
new DispatchReplyErrorResultHandler(mChangeDiscoveryRunnables, aRunnable));
}
nsresult
BluetoothServiceBluedroid::FetchUuidsInternal(
- const BluetoothAddress& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
+ const nsAString& 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(aDeviceAddress,
+ sBtInterface->GetRemoteServices(address,
new DispatchReplyErrorResultHandler(mFetchUuidsRunnables, aRunnable));
return NS_OK;
}
void
BluetoothServiceBluedroid::StopDiscoveryInternal(
BluetoothReplyRunnable* aRunnable)
@@ -1340,40 +1353,54 @@ BluetoothServiceBluedroid::UpdateSdpReco
sBtInterface->GetRemoteServices(aDeviceAddress, res);
}
return true;
}
nsresult
BluetoothServiceBluedroid::CreatePairedDeviceInternal(
- const BluetoothAddress& aDeviceAddress, int aTimeout,
+ const nsAString& 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(aDeviceAddress, TRANSPORT_AUTO,
+ sBtInterface->CreateBond(address, TRANSPORT_AUTO,
new DispatchReplyErrorResultHandler(mCreateBondRunnables, aRunnable));
return NS_OK;
}
nsresult
BluetoothServiceBluedroid::RemoveDeviceInternal(
- const BluetoothAddress& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
+ const nsAString& 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(aDeviceAddress,
+ sBtInterface->RemoveBond(address,
new DispatchReplyErrorResultHandler(mRemoveBondRunnables, aRunnable));
return NS_OK;
}
class BluetoothServiceBluedroid::PinReplyResultHandler final
: public BluetoothResultHandler
{
@@ -1393,45 +1420,52 @@ public:
}
private:
BluetoothReplyRunnable* mRunnable;
};
void
BluetoothServiceBluedroid::PinReplyInternal(
- const BluetoothAddress& aDeviceAddress, bool aAccept,
+ const nsAString& aDeviceAddress, bool aAccept,
const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
- BluetoothPinCode pinCode;
- auto rv = StringToPinCode(aPinCode, pinCode);
+ BluetoothAddress address;
+ nsresult rv = StringToAddress(aDeviceAddress, address);
if (NS_FAILED(rv)) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
- sBtInterface->PinReply(aDeviceAddress, aAccept, pinCode,
+ BluetoothPinCode pinCode;
+ rv = StringToPinCode(aPinCode, pinCode);
+ if (NS_FAILED(rv)) {
+ DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
+ return;
+ }
+
+ sBtInterface->PinReply(address, aAccept, pinCode,
new PinReplyResultHandler(aRunnable));
}
void
BluetoothServiceBluedroid::SetPinCodeInternal(
- const BluetoothAddress& aDeviceAddress, const nsAString& aPinCode,
+ const nsAString& aDeviceAddress, const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable)
{
// Legacy method used by BlueZ only.
}
void
BluetoothServiceBluedroid::SetPasskeyInternal(
- const BluetoothAddress& aDeviceAddress, uint32_t aPasskey,
+ const nsAString& aDeviceAddress, uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable)
{
// Legacy method used by BlueZ only.
}
class BluetoothServiceBluedroid::SspReplyResultHandler final
: public BluetoothResultHandler
{
@@ -1451,30 +1485,37 @@ public:
}
private:
BluetoothReplyRunnable* mRunnable;
};
void
BluetoothServiceBluedroid::SspReplyInternal(
- const BluetoothAddress& aDeviceAddress, BluetoothSspVariant aVariant,
+ const nsAString& aDeviceAddress, BluetoothSspVariant aVariant,
bool aAccept, BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
- sBtInterface->SspReply(aDeviceAddress, aVariant, aAccept, 0 /* passkey */,
+ BluetoothAddress address;
+ nsresult rv = StringToAddress(aDeviceAddress, address);
+ if (NS_FAILED(rv)) {
+ DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
+ return;
+ }
+
+ sBtInterface->SspReply(address, aVariant, aAccept, 0 /* passkey */,
new SspReplyResultHandler(aRunnable));
}
void
BluetoothServiceBluedroid::SetPairingConfirmationInternal(
- const BluetoothAddress& aDeviceAddress, bool aConfirm,
+ const nsAString& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable)
{
// Legacy method used by BlueZ only.
}
void
BluetoothServiceBluedroid::NextBluetoothProfileController()
{
@@ -1487,51 +1528,58 @@ BluetoothServiceBluedroid::NextBluetooth
// Start the next task if task array is not empty
if (!sControllerArray.IsEmpty()) {
sControllerArray[0]->StartSession();
}
}
void
BluetoothServiceBluedroid::ConnectDisconnect(
- bool aConnect, const BluetoothAddress& aDeviceAddress,
+ bool aConnect, const nsAString& 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, aDeviceAddress, aRunnable,
+ new BluetoothProfileController(aConnect, address, 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 BluetoothAddress& aDeviceAddress,
+BluetoothServiceBluedroid::Connect(const nsAString& aDeviceAddress,
uint32_t aCod,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
ConnectDisconnect(true, aDeviceAddress, aRunnable, aServiceUuid, aCod);
}
void
BluetoothServiceBluedroid::Disconnect(
- const BluetoothAddress& aDeviceAddress, uint16_t aServiceUuid,
+ const nsAString& 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,22 +45,21 @@ public:
virtual nsresult GetAdaptersInternal(BluetoothReplyRunnable* aRunnable);
virtual nsresult
GetConnectedDevicePropertiesInternal(uint16_t aProfileId,
BluetoothReplyRunnable* aRunnable);
virtual nsresult
- GetPairedDevicePropertiesInternal(
- const nsTArray<BluetoothAddress>& aDeviceAddress,
- BluetoothReplyRunnable* aRunnable);
+ GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddress,
+ BluetoothReplyRunnable* aRunnable);
virtual nsresult
- FetchUuidsInternal(const BluetoothAddress& aDeviceAddress,
+ FetchUuidsInternal(const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
virtual void StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
virtual nsresult
SetProperty(BluetoothObjectType aType,
const BluetoothNamedValue& aValue,
@@ -71,58 +70,58 @@ public:
const BluetoothUuid& aServiceUuid,
BluetoothProfileManagerBase* aManager);
virtual bool
UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
BluetoothProfileManagerBase* aManager);
virtual nsresult
- CreatePairedDeviceInternal(const BluetoothAddress& aDeviceAddress,
+ CreatePairedDeviceInternal(const nsAString& aDeviceAddress,
int aTimeout,
BluetoothReplyRunnable* aRunnable);
virtual nsresult
- RemoveDeviceInternal(const BluetoothAddress& aDeviceAddress,
+ RemoveDeviceInternal(const nsAString& aDeviceObjectPath,
BluetoothReplyRunnable* aRunnable);
virtual void
- PinReplyInternal(const BluetoothAddress& aDeviceAddress,
+ PinReplyInternal(const nsAString& aDeviceAddress,
bool aAccept,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable);
virtual void
- SspReplyInternal(const BluetoothAddress& aDeviceAddress,
+ SspReplyInternal(const nsAString& aDeviceAddress,
BluetoothSspVariant aVariant,
bool aAccept,
BluetoothReplyRunnable* aRunnable);
virtual void
- SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
+ SetPinCodeInternal(const nsAString& aDeviceAddress,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable);
virtual void
- SetPasskeyInternal(const BluetoothAddress& aDeviceAddress,
+ SetPasskeyInternal(const nsAString& aDeviceAddress,
uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable);
virtual void
- SetPairingConfirmationInternal(const BluetoothAddress& aDeviceAddress,
+ SetPairingConfirmationInternal(const nsAString& aDeviceAddress,
bool aConfirm,
BluetoothReplyRunnable* aRunnable);
virtual void
- Connect(const BluetoothAddress& aDeviceAddress,
+ Connect(const nsAString& aDeviceAddress,
uint32_t aCod,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable);
virtual void
- Disconnect(const BluetoothAddress& aDeviceAddress, uint16_t aServiceUuid,
+ Disconnect(const nsAString& aDeviceAddress, uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable);
virtual void
SendFile(const nsAString& aDeviceAddress,
BlobParent* aBlobParent,
BlobChild* aBlobChild,
BluetoothReplyRunnable* aRunnable);
@@ -485,17 +484,17 @@ public:
protected:
static nsresult StartGonkBluetooth();
static nsresult StopGonkBluetooth();
static ControlPlayStatus PlayStatusStringToControlPlayStatus(
const nsAString& aPlayStatus);
static void ConnectDisconnect(bool aConnect,
- const BluetoothAddress& aDeviceAddress,
+ const nsAString& 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<BluetoothAddress>& aDeviceAddresses,
+ const nsTArray<nsString>& aDeviceAddresses,
const FilterFunc aFilterFunc, BluetoothReplyRunnable* aRunnable)
: mDeviceAddresses(aDeviceAddresses)
, mProcessedDeviceAddresses(0)
, mFilterFunc(aFilterFunc)
, mRunnable(aRunnable)
, mValues(InfallibleTArray<BluetoothNamedValue>())
{
MOZ_ASSERT(mRunnable);
@@ -2767,21 +2767,18 @@ public:
NS_LITERAL_STRING("audio-card")));
}
break;
}
}
}
if (mFilterFunc(deviceProperties)) {
- nsString deviceAddressStr;
- AddressToString(mDeviceAddresses[i], deviceAddressStr);
-
mValues.get_ArrayOfBluetoothNamedValue().AppendElement(
- BluetoothNamedValue(deviceAddressStr, deviceProperties));
+ BluetoothNamedValue(mDeviceAddresses[i], deviceProperties));
}
ProcessRemainingDeviceAddresses();
}
void ProcessRemainingDeviceAddresses()
{
if (mProcessedDeviceAddresses < mDeviceAddresses.Length()) {
@@ -2820,17 +2817,17 @@ protected:
Unused << handler.forget(); // picked up by callback handler
return true;
}
private:
nsString mObjectPath;
- const nsTArray<BluetoothAddress> mDeviceAddresses;
+ const nsTArray<nsString> mDeviceAddresses;
nsTArray<nsString>::size_type mProcessedDeviceAddresses;
const FilterFunc mFilterFunc;
RefPtr<BluetoothReplyRunnable> mRunnable;
BluetoothValue mValues;
};
class ProcessRemainingDeviceAddressesTask : public Task
{
@@ -2866,46 +2863,49 @@ 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<BluetoothAddress> deviceAddresses;
-
+ nsTArray<nsString> 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);
- deviceAddresses.AppendElement(address);
+
+ nsAutoString addressStr;
+ AddressToString(address, addressStr);
+
+ deviceAddresses.AppendElement(addressStr);
}
BluetoothArrayOfDevicePropertiesReplyHandler* handler =
new BluetoothArrayOfDevicePropertiesReplyHandler(deviceAddresses,
GetConnectedDevicesFilter,
aRunnable);
Task* task = new ProcessRemainingDeviceAddressesTask(handler, aRunnable);
DispatchToDBusThread(task);
return NS_OK;
}
nsresult
BluetoothDBusService::GetPairedDevicePropertiesInternal(
- const nsTArray<BluetoothAddress>& aDeviceAddresses,
- BluetoothReplyRunnable* aRunnable)
+ const nsTArray<nsString>& 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 BluetoothAddress& aDeviceAddress,
+BluetoothDBusService::FetchUuidsInternal(const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable)
{
return NS_OK;
}
class SetPropertyTask : public Task
{
public:
@@ -3087,38 +3087,34 @@ BluetoothDBusService::SetProperty(Blueto
DispatchToDBusThread(task);
return NS_OK;
}
class CreatePairedDeviceInternalTask : public Task
{
public:
- CreatePairedDeviceInternalTask(const BluetoothAddress& aDeviceAddress,
+ CreatePairedDeviceInternalTask(const nsACString& aDeviceAddress,
int aTimeout,
BluetoothReplyRunnable* aRunnable)
: mDeviceAddress(aDeviceAddress)
, mTimeout(aTimeout)
, mRunnable(aRunnable)
{
- MOZ_ASSERT(!mDeviceAddress.IsCleared());
+ MOZ_ASSERT(!mDeviceAddress.IsEmpty());
MOZ_ASSERT(mRunnable);
}
void Run() override
{
MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
MOZ_ASSERT(sDBusConnection);
MOZ_ASSERT(!sAdapterPath.IsEmpty());
- nsString deviceAddressStr;
- AddressToString(mDeviceAddress, deviceAddressStr);
- auto utf8DeviceAddressStr = NS_ConvertUTF16toUTF8(deviceAddressStr);
-
- const char *deviceAddress = utf8DeviceAddressStr.get();
+ const char *deviceAddress = mDeviceAddress.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,
@@ -3144,30 +3140,30 @@ public:
* solution.
*
* Please see Bug 818696 for more information.
*/
sIsPairing++;
}
private:
- BluetoothAddress mDeviceAddress;
+ const nsCString mDeviceAddress;
int mTimeout;
RefPtr<BluetoothReplyRunnable> mRunnable;
};
nsresult
BluetoothDBusService::CreatePairedDeviceInternal(
- const BluetoothAddress& aDeviceAddress,
- int aTimeout,
- BluetoothReplyRunnable* aRunnable)
+ const nsAString& aDeviceAddress,
+ int aTimeout,
+ BluetoothReplyRunnable* aRunnable)
{
- Task* task = new CreatePairedDeviceInternalTask(aDeviceAddress,
- aTimeout,
- aRunnable);
+ Task* task = new CreatePairedDeviceInternalTask(
+ NS_ConvertUTF16toUTF8(aDeviceAddress),
+ aTimeout, aRunnable);
DispatchToDBusThread(task);
return NS_OK;
}
class RemoveDeviceTask : public Task
{
public:
@@ -3220,29 +3216,35 @@ protected:
}
private:
const BluetoothAddress mDeviceAddress;
RefPtr<BluetoothReplyRunnable> mRunnable;
};
nsresult
-BluetoothDBusService::RemoveDeviceInternal(
- const BluetoothAddress& aDeviceAddress,
- BluetoothReplyRunnable* aRunnable)
+BluetoothDBusService::RemoveDeviceInternal(const nsAString& 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;
}
- Task* task = new RemoveDeviceTask(aDeviceAddress, aRunnable);
+ BluetoothAddress deviceAddress;
+ auto rv = StringToAddress(aDeviceAddress, deviceAddress);
+ if (NS_FAILED(rv)) {
+ DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
+ return rv;
+ }
+
+ Task* task = new RemoveDeviceTask(deviceAddress, aRunnable);
DispatchToDBusThread(task);
return NS_OK;
}
class SetPinCodeTask : public Task
{
public:
@@ -3303,36 +3305,43 @@ public:
private:
const BluetoothAddress mDeviceAddress;
const nsCString mPinCode;
RefPtr<BluetoothReplyRunnable> mRunnable;
};
void
BluetoothDBusService::PinReplyInternal(
- const BluetoothAddress& aDeviceAddress, bool aAccept,
+ const nsAString& aDeviceAddress, bool aAccept,
const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable)
{
// Legacy interface used by Bluedroid only.
}
void
BluetoothDBusService::SspReplyInternal(
- const BluetoothAddress& aDeviceAddress, BluetoothSspVariant aVariant,
+ const nsAString& aDeviceAddress, BluetoothSspVariant aVariant,
bool aAccept, BluetoothReplyRunnable* aRunnable)
{
// Legacy interface used by Bluedroid only.
}
void
-BluetoothDBusService::SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
+BluetoothDBusService::SetPinCodeInternal(const nsAString& aDeviceAddress,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable)
{
- Task* task = new SetPinCodeTask(aDeviceAddress,
+ BluetoothAddress deviceAddress;
+ auto rv = StringToAddress(aDeviceAddress, deviceAddress);
+ if (NS_FAILED(rv)) {
+ DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
+ return;
+ }
+
+ Task* task = new SetPinCodeTask(deviceAddress,
NS_ConvertUTF16toUTF8(aPinCode),
aRunnable);
DispatchToDBusThread(task);
}
class SetPasskeyTask : public Task
{
public:
@@ -3392,36 +3401,47 @@ public:
private:
BluetoothAddress mDeviceAddress;
uint32_t mPasskey;
RefPtr<BluetoothReplyRunnable> mRunnable;
};
void
-BluetoothDBusService::SetPasskeyInternal(
- const BluetoothAddress& aDeviceAddress,
- uint32_t aPasskey,
- BluetoothReplyRunnable* aRunnable)
+BluetoothDBusService::SetPasskeyInternal(const nsAString& aDeviceAddress,
+ uint32_t aPasskey,
+ BluetoothReplyRunnable* aRunnable)
{
- Task* task = new SetPasskeyTask(aDeviceAddress,
+ BluetoothAddress deviceAddress;
+ if (NS_FAILED(StringToAddress(aDeviceAddress, deviceAddress))) {
+ DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
+ return;
+ }
+
+ Task* task = new SetPasskeyTask(deviceAddress,
aPasskey,
aRunnable);
DispatchToDBusThread(task);
}
void
BluetoothDBusService::SetPairingConfirmationInternal(
- const BluetoothAddress& aDeviceAddress,
- bool aConfirm,
- BluetoothReplyRunnable* aRunnable)
+ const nsAString& aDeviceAddress,
+ bool aConfirm,
+ BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
- Task* task = new SetPairingConfirmationTask(aDeviceAddress,
+ BluetoothAddress deviceAddress;
+ if (NS_FAILED(StringToAddress(aDeviceAddress, deviceAddress))) {
+ DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
+ return;
+ }
+
+ Task* task = new SetPairingConfirmationTask(deviceAddress,
aConfirm,
aRunnable);
DispatchToDBusThread(task);
}
static void
NextBluetoothProfileController()
{
@@ -3432,50 +3452,57 @@ 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 BluetoothAddress& aDeviceAddress,
+ConnectDisconnect(bool aConnect, const nsAString& 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, aDeviceAddress, aRunnable,
+ new BluetoothProfileController(aConnect, deviceAddress, 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 BluetoothAddress& aDeviceAddress,
+BluetoothDBusService::Connect(const nsAString& aDeviceAddress,
uint32_t aCod,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
ConnectDisconnect(true, aDeviceAddress, aRunnable, aServiceUuid, aCod);
}
void
-BluetoothDBusService::Disconnect(const BluetoothAddress& aDeviceAddress,
+BluetoothDBusService::Disconnect(const nsAString& aDeviceAddress,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
ConnectDisconnect(false, aDeviceAddress, aRunnable, aServiceUuid);
}
#ifdef MOZ_B2G_RIL
void
@@ -3510,23 +3537,26 @@ BluetoothDBusService::ToggleCalls(Blueto
DispatchBluetoothReply(aRunnable, BluetoothValue(true), EmptyString());
}
#endif // MOZ_B2G_RIL
class OnUpdateSdpRecordsRunnable : public nsRunnable
{
public:
- OnUpdateSdpRecordsRunnable(const BluetoothAddress& aDeviceAddress,
+ OnUpdateSdpRecordsRunnable(const nsAString& aObjectPath,
BluetoothProfileManagerBase* aManager)
- : mDeviceAddress(aDeviceAddress)
- , mManager(aManager)
+ : mManager(aManager)
{
- MOZ_ASSERT(!mDeviceAddress.IsCleared());
- MOZ_ASSERT(mManager);
+ MOZ_ASSERT(!aObjectPath.IsEmpty());
+ MOZ_ASSERT(aManager);
+
+ const nsString deviceAddressStr = GetAddressFromObjectPath(aObjectPath);
+
+ StringToAddress(deviceAddressStr, mDeviceAddress);
}
nsresult
Run()
{
MOZ_ASSERT(NS_IsMainThread());
mManager->OnUpdateSdpRecords(mDeviceAddress);
@@ -3723,17 +3753,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(mDeviceAddress, mBluetoothProfileManager);
+ new OnUpdateSdpRecordsRunnable(objectPath, 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,22 +54,21 @@ public:
virtual nsresult
GetAdaptersInternal(BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
GetConnectedDevicePropertiesInternal(
uint16_t aServiceUuid, BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
- GetPairedDevicePropertiesInternal(
- const nsTArray<BluetoothAddress>& aDeviceAddresses,
- BluetoothReplyRunnable* aRunnable) override;
+ GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddresses,
+ BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
- FetchUuidsInternal(const BluetoothAddress& aDeviceAddress,
+ FetchUuidsInternal(const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;
virtual void
StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable) override;
virtual void
StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable) override;
@@ -83,58 +82,56 @@ public:
const BluetoothUuid& aServiceUuid,
BluetoothProfileManagerBase* aManager) override;
virtual bool
UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
BluetoothProfileManagerBase* aManager) override;
virtual nsresult
- CreatePairedDeviceInternal(const BluetoothAddress& aDeviceAddress,
+ CreatePairedDeviceInternal(const nsAString& aDeviceAddress,
int aTimeout,
BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
- RemoveDeviceInternal(const BluetoothAddress& aDeviceAddress,
+ RemoveDeviceInternal(const nsAString& aDeviceObjectPath,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- PinReplyInternal(const BluetoothAddress& aDeviceAddress,
+ PinReplyInternal(const nsAString& aDeviceAddress,
bool aAccept,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable);
virtual void
- SspReplyInternal(const BluetoothAddress& aDeviceAddress,
+ SspReplyInternal(const nsAString& aDeviceAddress,
BluetoothSspVariant aVariant,
bool aAccept,
BluetoothReplyRunnable* aRunnable);
virtual void
- SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
- const nsAString& aPinCode,
+ SetPinCodeInternal(const nsAString& aDeviceAddress, const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- SetPasskeyInternal(const BluetoothAddress& aDeviceAddress, uint32_t aPasskey,
+ SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- SetPairingConfirmationInternal(const BluetoothAddress& aDeviceAddress,
- bool aConfirm,
+ SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- Connect(const BluetoothAddress& aDeviceAddress,
+ Connect(const nsAString& aDeviceAddress,
uint32_t aCod,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- Disconnect(const BluetoothAddress& aDeviceAddress, uint16_t aServiceUuid,
+ Disconnect(const nsAString& 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,19 +144,18 @@ 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<BluetoothAddress>& aDeviceAddresses,
- BluetoothReplyRunnable* aRunnable) = 0;
+ GetPairedDevicePropertiesInternal(const nsTArray<nsString>& 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
@@ -165,17 +164,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 BluetoothAddress& aDeviceAddress,
+ FetchUuidsInternal(const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) = 0;
/**
* Stop device discovery (platform specific implementation)
*/
virtual void
StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable) = 0;
@@ -209,22 +208,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 BluetoothAddress& aDeviceAddress,
+ CreatePairedDeviceInternal(const nsAString& aAddress,
int aTimeout,
BluetoothReplyRunnable* aRunnable) = 0;
virtual nsresult
- RemoveDeviceInternal(const BluetoothAddress& aDeviceAddress,
+ RemoveDeviceInternal(const nsAString& aObjectPath,
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
@@ -237,57 +236,55 @@ public:
const BluetoothUuid& aServiceUuid,
BluetoothProfileManagerBase* aManager) = 0;
virtual bool
UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
BluetoothProfileManagerBase* aManager) = 0;
virtual void
- PinReplyInternal(const BluetoothAddress& aDeviceAddress,
+ PinReplyInternal(const nsAString& aDeviceAddress,
bool aAccept,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void
- SspReplyInternal(const BluetoothAddress& aDeviceAddress,
+ SspReplyInternal(const nsAString& aDeviceAddress,
BluetoothSspVariant aVariant,
bool aAccept,
BluetoothReplyRunnable* aRunnable) = 0;
/**
* Legacy method used by bluez only to reply pincode request.
*/
virtual void
- SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
+ SetPinCodeInternal(const nsAString& aDeviceAddress,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable) = 0;
/**
* Legacy method used by bluez only to reply passkey entry request.
*/
virtual void
- SetPasskeyInternal(const BluetoothAddress& aDeviceAddress, uint32_t aPasskey,
+ SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable) = 0;
/**
* Legacy method used by bluez only to reply pairing confirmation request.
*/
virtual void
- SetPairingConfirmationInternal(const BluetoothAddress& aDeviceAddress,
- bool aConfirm,
+ SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void
- Connect(const BluetoothAddress& aDeviceAddress,
- uint32_t aCod, uint16_t aServiceUuid,
+ Connect(const nsAString& aDeviceAddress, uint32_t aCod, uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void
- Disconnect(const BluetoothAddress& aDeviceAddress, uint16_t aServiceUuid,
+ Disconnect(const nsAString& 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,34 +400,23 @@ 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);
- auto rv = bs->GetPairedDevicePropertiesInternal(deviceAddresses, results);
+ nsresult rv =
+ bs->GetPairedDevicePropertiesInternal(aDeviceAddresses, 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();
@@ -857,38 +846,36 @@ BluetoothAdapter::PairUnpair(bool aPair,
return nullptr;
}
RefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
/**
* Ensure
- * - device address is valid,
+ * - device address is not empty,
* - adapter is already enabled, and
* - BluetoothService is available.
*/
- BluetoothAddress deviceAddress;
- BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToAddress(aDeviceAddress,
- deviceAddress)),
+ BT_ENSURE_TRUE_REJECT(!aDeviceAddress.IsEmpty(),
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(
- deviceAddress, kCreatePairedDeviceTimeout,
+ aDeviceAddress, kCreatePairedDeviceTimeout,
new BluetoothVoidReplyRunnable(nullptr, promise));
} else {
- rv = bs->RemoveDeviceInternal(deviceAddress,
+ rv = bs->RemoveDeviceInternal(aDeviceAddress,
new BluetoothVoidReplyRunnable(nullptr, promise));
}
BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(rv), promise, NS_ERROR_DOM_OPERATION_ERR);
return promise.forget();
}
already_AddRefed<Promise>
@@ -1669,34 +1656,28 @@ 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(deviceAddress, deviceClass, serviceUuid, results);
+ bs->Connect(address, deviceClass, serviceUuid, results);
return request.forget();
}
already_AddRefed<DOMRequest>
BluetoothAdapter::Disconnect(BluetoothDevice& aDevice,
const Optional<short unsigned int>& aServiceUuid,
ErrorResult& aRv)
@@ -1708,33 +1689,27 @@ 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(deviceAddress, serviceUuid, results);
+ bs->Disconnect(address, 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,23 +182,20 @@ 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(address, new FetchUuidsTask(promise, this))),
+ bs->FetchUuidsInternal(mAddress, 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,17 +4,16 @@
* 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
@@ -75,26 +74,20 @@ 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(deviceAddress, true /* accept */, aPinCode,
+ bs->PinReplyInternal(mDeviceAddress, true /* accept */, aPinCode,
new BluetoothVoidReplyRunnable(nullptr, promise));
return promise.forget();
}
already_AddRefed<Promise>
BluetoothPairingHandle::Accept(ErrorResult& aRv)
{
@@ -110,28 +103,22 @@ 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(deviceAddress, variant, true /* aAccept */,
+ bs->SspReplyInternal(mDeviceAddress, variant, true /* aAccept */,
new BluetoothVoidReplyRunnable(nullptr, promise));
return promise.forget();
}
already_AddRefed<Promise>
BluetoothPairingHandle::Reject(ErrorResult& aRv)
{
@@ -139,35 +126,29 @@ 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(deviceAddress, false /* aAccept */, EmptyString(),
+ bs->PinReplyInternal(mDeviceAddress, 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(deviceAddress, variant, false /* aAccept */,
+ bs->SspReplyInternal(mDeviceAddress, 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.address(),
+ mService->SetPinCodeInternal(aRequest.path(),
aRequest.pincode(),
mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const SetPasskeyRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TSetPasskeyRequest);
- mService->SetPasskeyInternal(aRequest.address(),
+ mService->SetPasskeyInternal(aRequest.path(),
aRequest.passkey(),
mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const ConfirmPairingConfirmationRequest&
aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TConfirmPairingConfirmationRequest);
- mService->SetPairingConfirmationInternal(aRequest.address(),
+ mService->SetPairingConfirmationInternal(aRequest.path(),
true,
mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const DenyPairingConfirmationRequest&
aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TDenyPairingConfirmationRequest);
- mService->SetPairingConfirmationInternal(aRequest.address(),
+ mService->SetPairingConfirmationInternal(aRequest.path(),
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<BluetoothAddress>& aDeviceAddresses,
- BluetoothReplyRunnable* aRunnable)
+ const nsTArray<nsString>& aDeviceAddresses,
+ BluetoothReplyRunnable* aRunnable)
{
PairedDevicePropertiesRequest request;
request.addresses().AppendElements(aDeviceAddresses);
SendRequest(aRunnable, request);
return NS_OK;
}
nsresult
BluetoothServiceChildProcess::FetchUuidsInternal(
- const BluetoothAddress& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
+ const nsAString& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
{
- SendRequest(aRunnable, FetchUuidsRequest(aDeviceAddress));
+ SendRequest(aRunnable, FetchUuidsRequest(nsString(aDeviceAddress)));
return NS_OK;
}
void
BluetoothServiceChildProcess::StopDiscoveryInternal(
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, StopDiscoveryRequest());
@@ -183,28 +183,32 @@ BluetoothServiceChildProcess::SetPropert
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, SetPropertyRequest(aType, aValue));
return NS_OK;
}
nsresult
BluetoothServiceChildProcess::CreatePairedDeviceInternal(
- const BluetoothAddress& aDeviceAddress, int aTimeout,
- BluetoothReplyRunnable* aRunnable)
+ const nsAString& aAddress,
+ int aTimeout,
+ BluetoothReplyRunnable* aRunnable)
{
- SendRequest(aRunnable, PairRequest(aDeviceAddress, aTimeout));
+ SendRequest(aRunnable,
+ PairRequest(nsString(aAddress), aTimeout));
return NS_OK;
}
nsresult
BluetoothServiceChildProcess::RemoveDeviceInternal(
- const BluetoothAddress& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
+ const nsAString& aObjectPath,
+ BluetoothReplyRunnable* aRunnable)
{
- SendRequest(aRunnable, UnpairRequest(aDeviceAddress));
+ SendRequest(aRunnable,
+ UnpairRequest(nsString(aObjectPath)));
return NS_OK;
}
nsresult
BluetoothServiceChildProcess::GetServiceChannel(const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
BluetoothProfileManagerBase* aManager)
{
@@ -215,82 +219,92 @@ bool
BluetoothServiceChildProcess::UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
BluetoothProfileManagerBase* aManager)
{
MOZ_CRASH("This should never be called!");
}
void
BluetoothServiceChildProcess::PinReplyInternal(
- const BluetoothAddress& aDeviceAddress, bool aAccept,
+ const nsAString& aDeviceAddress, bool aAccept,
const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
- PinReplyRequest(aDeviceAddress,
+ PinReplyRequest(nsString(aDeviceAddress),
aAccept,
nsString(aPinCode)));
}
void
BluetoothServiceChildProcess::SspReplyInternal(
- const BluetoothAddress& aDeviceAddress,
- BluetoothSspVariant aVariant, bool aAccept,
- BluetoothReplyRunnable* aRunnable)
+ const nsAString& aDeviceAddress, BluetoothSspVariant aVariant,
+ bool aAccept, BluetoothReplyRunnable* aRunnable)
{
- SendRequest(aRunnable, SspReplyRequest(aDeviceAddress, aVariant, aAccept));
+ SendRequest(aRunnable,
+ SspReplyRequest(nsString(aDeviceAddress),
+ aVariant,
+ aAccept));
}
void
BluetoothServiceChildProcess::SetPinCodeInternal(
- const BluetoothAddress& aDeviceAddress,
- const nsAString& aPinCode,
- BluetoothReplyRunnable* aRunnable)
+ const nsAString& aDeviceAddress,
+ const nsAString& aPinCode,
+ BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
- SetPinCodeRequest(aDeviceAddress, nsString(aPinCode)));
+ SetPinCodeRequest(nsString(aDeviceAddress), nsString(aPinCode)));
}
void
BluetoothServiceChildProcess::SetPasskeyInternal(
- const BluetoothAddress& aDeviceAddress,
- uint32_t aPasskey,
- BluetoothReplyRunnable* aRunnable)
+ const nsAString& aDeviceAddress,
+ uint32_t aPasskey,
+ BluetoothReplyRunnable* aRunnable)
{
- SendRequest(aRunnable, SetPasskeyRequest(aDeviceAddress, aPasskey));
+ SendRequest(aRunnable,
+ SetPasskeyRequest(nsString(aDeviceAddress), aPasskey));
}
void
BluetoothServiceChildProcess::SetPairingConfirmationInternal(
- const BluetoothAddress& aDeviceAddress,
+ const nsAString& aDeviceAddress,
bool aConfirm,
BluetoothReplyRunnable* aRunnable)
{
- if (aConfirm) {
- SendRequest(aRunnable, ConfirmPairingConfirmationRequest(aDeviceAddress));
+ if(aConfirm) {
+ SendRequest(aRunnable,
+ ConfirmPairingConfirmationRequest(nsString(aDeviceAddress)));
} else {
- SendRequest(aRunnable, DenyPairingConfirmationRequest(aDeviceAddress));
+ SendRequest(aRunnable,
+ DenyPairingConfirmationRequest(nsString(aDeviceAddress)));
}
}
void
BluetoothServiceChildProcess::Connect(
- const BluetoothAddress& aDeviceAddress,
- uint32_t aCod, uint16_t aServiceUuid,
+ const nsAString& aDeviceAddress,
+ uint32_t aCod,
+ uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
- SendRequest(aRunnable, ConnectRequest(aDeviceAddress, aCod, aServiceUuid));
+ SendRequest(aRunnable,
+ ConnectRequest(nsString(aDeviceAddress),
+ aCod,
+ aServiceUuid));
}
void
BluetoothServiceChildProcess::Disconnect(
- const BluetoothAddress& aDeviceAddress,
+ const nsAString& aDeviceAddress,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
- SendRequest(aRunnable, DisconnectRequest(aDeviceAddress, aServiceUuid));
+ SendRequest(aRunnable,
+ DisconnectRequest(nsString(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<BluetoothAddress>& aDeviceAddresses,
+ GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddresses,
BluetoothReplyRunnable* aRunnable)
override;
virtual nsresult
GetConnectedDevicePropertiesInternal(uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
override;
virtual nsresult
- FetchUuidsInternal(const BluetoothAddress& aDeviceAddress,
+ FetchUuidsInternal(const nsAString& 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 BluetoothAddress& aDeviceAddress,
+ CreatePairedDeviceInternal(const nsAString& aAddress,
int aTimeout,
BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
- RemoveDeviceInternal(const BluetoothAddress& aDeviceAddress,
+ RemoveDeviceInternal(const nsAString& aObjectPath,
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 BluetoothAddress& aDeviceAddress,
+ SetPinCodeInternal(const nsAString& aDeviceAddress,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- SetPasskeyInternal(const BluetoothAddress& aDeviceAddress,
+ SetPasskeyInternal(const nsAString& aDeviceAddress,
uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- SetPairingConfirmationInternal(const BluetoothAddress& aDeviceAddress,
+ SetPairingConfirmationInternal(const nsAString& aDeviceAddress,
bool aConfirm,
BluetoothReplyRunnable* aRunnable)
override;
virtual void
- PinReplyInternal(const BluetoothAddress& aDeviceAddress,
+ PinReplyInternal(const nsAString& aDeviceAddress,
bool aAccept,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- SspReplyInternal(const BluetoothAddress& aDeviceAddress,
+ SspReplyInternal(const nsAString& aDeviceAddress,
BluetoothSspVariant aVariant,
bool aAccept,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- Connect(const BluetoothAddress& aDeviceAddress,
+ Connect(const nsAString& aDeviceAddress,
uint32_t aCod,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable) override;
virtual void
- Disconnect(const BluetoothAddress& aDeviceAddress,
+ Disconnect(const nsAString& 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,20 +7,17 @@
include protocol PBlob;
include protocol PBluetoothRequest;
include protocol PContent;
include BluetoothTypes;
include "mozilla/dom/bluetooth/ipc/BluetoothMessageUtils.h";
-using mozilla::dom::bluetooth::BluetoothAddress
- from "mozilla/dom/bluetooth/BluetoothCommon.h";
-using mozilla::dom::bluetooth::BluetoothObjectType
- 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.
*/
@@ -40,17 +37,17 @@ struct SetPropertyRequest
{
BluetoothObjectType type;
BluetoothNamedValue value;
};
struct GetPropertyRequest
{
BluetoothObjectType type;
- BluetoothAddress address;
+ nsString path;
};
struct StartDiscoveryRequest
{
};
struct StopDiscoveryRequest
{
@@ -63,86 +60,86 @@ struct StartLeScanRequest
struct StopLeScanRequest
{
nsString scanUuid;
};
struct PairRequest
{
- BluetoothAddress address;
+ nsString address;
uint32_t timeoutMS;
};
struct UnpairRequest
{
- BluetoothAddress address;
+ nsString address;
};
struct PinReplyRequest
{
- BluetoothAddress address;
+ nsString address;
bool accept;
nsString pinCode;
};
struct SspReplyRequest
{
- BluetoothAddress address;
+ nsString address;
BluetoothSspVariant variant;
bool accept;
};
struct SetPinCodeRequest
{
- BluetoothAddress address;
+ nsString path;
nsString pincode;
};
struct SetPasskeyRequest
{
- BluetoothAddress address;
+ nsString path;
uint32_t passkey;
};
struct ConfirmPairingConfirmationRequest
{
- BluetoothAddress address;
+ nsString path;
};
struct DenyPairingConfirmationRequest
{
- BluetoothAddress address;
+ nsString path;
};
struct PairedDevicePropertiesRequest
{
- BluetoothAddress[] addresses;
+ nsString[] addresses;
};
struct ConnectedDevicePropertiesRequest
{
uint16_t serviceUuid;
};
struct FetchUuidsRequest
{
- BluetoothAddress address;
+ nsString address;
};
struct ConnectRequest
{
- BluetoothAddress address;
+ nsString address;
uint32_t cod;
uint16_t serviceUuid;
};
struct DisconnectRequest
{
- BluetoothAddress address;
+ nsString address;
uint16_t serviceUuid;
};
struct SendFileRequest
{
nsString devicePath;
PBlob blob;
};