mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 21:35:39 +00:00
Bug 850157 - Add GetConnectedDevices() in nsIDOMBluetoothAdapter.idl, r=echou, sr= mrbkap
This commit is contained in:
parent
be5d6421da
commit
5b81eec10f
@ -54,10 +54,10 @@ NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
|
||||
NS_IMPL_ADDREF_INHERITED(BluetoothAdapter, nsDOMEventTargetHelper)
|
||||
NS_IMPL_RELEASE_INHERITED(BluetoothAdapter, nsDOMEventTargetHelper)
|
||||
|
||||
class GetPairedDevicesTask : public BluetoothReplyRunnable
|
||||
class GetDevicesTask : public BluetoothReplyRunnable
|
||||
{
|
||||
public:
|
||||
GetPairedDevicesTask(BluetoothAdapter* aAdapterPtr,
|
||||
GetDevicesTask(BluetoothAdapter* aAdapterPtr,
|
||||
nsIDOMDOMRequest* aReq) :
|
||||
BluetoothReplyRunnable(aReq),
|
||||
mAdapterPtr(aAdapterPtr)
|
||||
@ -237,6 +237,12 @@ BluetoothAdapter::SetPropertyByValue(const BluetoothNamedValue& aValue)
|
||||
Root();
|
||||
} else if (name.EqualsLiteral("Devices")) {
|
||||
mDeviceAddresses = value.get_ArrayOfnsString();
|
||||
|
||||
uint32_t length = mDeviceAddresses.Length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
mDeviceAddresses[i] = GetAddressFromObjectPath(mDeviceAddresses[i]);
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
@ -453,23 +459,40 @@ BluetoothAdapter::SetDiscoverableTimeout(const uint32_t aDiscoverableTimeout,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::GetPairedDevices(nsIDOMDOMRequest** aRequest)
|
||||
BluetoothAdapter::GetConnectedDevices(uint16_t aProfileId,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv;
|
||||
rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<BluetoothReplyRunnable> results =
|
||||
new GetPairedDevicesTask(this, req);
|
||||
new GetDevicesTask(this, req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
if (NS_FAILED(bs->GetPairedDevicePropertiesInternal(mDeviceAddresses,
|
||||
results))) {
|
||||
NS_WARNING("GetPairedDevices failed!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
rv = bs->GetConnectedDevicePropertiesInternal(aProfileId, results);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::GetPairedDevices(nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<BluetoothReplyRunnable> results =
|
||||
new GetDevicesTask(this, req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
rv = bs->GetPairedDevicePropertiesInternal(mDeviceAddresses, results);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
@ -481,8 +504,7 @@ BluetoothAdapter::PairUnpair(bool aPair,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv;
|
||||
rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
@ -530,8 +552,7 @@ BluetoothAdapter::SetPinCode(const nsAString& aDeviceAddress,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv;
|
||||
rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
@ -553,8 +574,7 @@ BluetoothAdapter::SetPasskey(const nsAString& aDeviceAddress, uint32_t aPasskey,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv;
|
||||
rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
@ -577,8 +597,7 @@ BluetoothAdapter::SetPairingConfirmation(const nsAString& aDeviceAddress,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv;
|
||||
rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
@ -602,8 +621,7 @@ BluetoothAdapter::SetAuthorization(const nsAString& aDeviceAddress, bool aAllow,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv;
|
||||
rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
@ -626,8 +644,7 @@ BluetoothAdapter::Connect(const nsAString& aDeviceAddress,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv;
|
||||
rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
@ -646,8 +663,7 @@ BluetoothAdapter::Disconnect(uint16_t aProfileId,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv;
|
||||
rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
@ -667,8 +683,7 @@ BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv;
|
||||
rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
@ -694,8 +709,7 @@ BluetoothAdapter::StopSendingFile(const nsAString& aDeviceAddress,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv;
|
||||
rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
@ -715,8 +729,7 @@ BluetoothAdapter::ConfirmReceivingFile(const nsAString& aDeviceAddress,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv;
|
||||
rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
|
@ -1455,3 +1455,9 @@ BluetoothHfpManager::IsConnected()
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::GetAddress(nsAString& aDeviceAddress)
|
||||
{
|
||||
return mSocket->GetAddress(aDeviceAddress);
|
||||
}
|
||||
|
@ -75,6 +75,7 @@ public:
|
||||
void HandleCallStateChanged(uint32_t aCallIndex, uint16_t aCallState,
|
||||
const nsAString& aNumber, bool aSend);
|
||||
bool IsConnected();
|
||||
void GetAddress(nsAString& aDeviceAddress);
|
||||
|
||||
private:
|
||||
class GetVolumeTask;
|
||||
|
@ -1165,6 +1165,12 @@ BluetoothOppManager::IsTransferring()
|
||||
return (mConnected && !mSendTransferCompleteFlag);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothOppManager::GetAddress(nsAString& aDeviceAddress)
|
||||
{
|
||||
return mSocket->GetAddress(aDeviceAddress);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothOppManager::ReplyToConnect()
|
||||
{
|
||||
|
@ -73,6 +73,7 @@ public:
|
||||
// Return true if there is an ongoing file-transfer session, please see
|
||||
// Bug 827267 for more information.
|
||||
bool IsTransferring();
|
||||
void GetAddress(nsAString& aDeviceAddress);
|
||||
|
||||
// Implement interface BluetoothSocketObserver
|
||||
void ReceiveSocketData(
|
||||
|
@ -131,7 +131,17 @@ public:
|
||||
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
|
||||
GetConnectedDevicePropertiesInternal(uint16_t aProfileId,
|
||||
BluetoothReplyRunnable* aRunnable) = 0;
|
||||
|
||||
/**
|
||||
* Stop device discovery (platform specific implementation)
|
||||
*
|
||||
* @return NS_OK if discovery stopped correctly, false otherwise
|
||||
|
@ -197,8 +197,10 @@ BluetoothParent::RecvPBluetoothRequestConstructor(
|
||||
return actor->DoRequest(aRequest.get_PairRequest());
|
||||
case Request::TUnpairRequest:
|
||||
return actor->DoRequest(aRequest.get_UnpairRequest());
|
||||
case Request::TDevicePropertiesRequest:
|
||||
return actor->DoRequest(aRequest.get_DevicePropertiesRequest());
|
||||
case Request::TPairedDevicePropertiesRequest:
|
||||
return actor->DoRequest(aRequest.get_PairedDevicePropertiesRequest());
|
||||
case Request::TConnectedDevicePropertiesRequest:
|
||||
return actor->DoRequest(aRequest.get_ConnectedDevicePropertiesRequest());
|
||||
case Request::TSetPinCodeRequest:
|
||||
return actor->DoRequest(aRequest.get_SetPinCodeRequest());
|
||||
case Request::TSetPasskeyRequest:
|
||||
@ -372,15 +374,26 @@ BluetoothRequestParent::DoRequest(const UnpairRequest& aRequest)
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothRequestParent::DoRequest(const DevicePropertiesRequest& aRequest)
|
||||
BluetoothRequestParent::DoRequest(const PairedDevicePropertiesRequest& aRequest)
|
||||
{
|
||||
MOZ_ASSERT(mService);
|
||||
MOZ_ASSERT(mRequestType == Request::TDevicePropertiesRequest);
|
||||
MOZ_ASSERT(mRequestType == Request::TPairedDevicePropertiesRequest);
|
||||
|
||||
nsresult rv =
|
||||
mService->GetPairedDevicePropertiesInternal(aRequest.addresses(),
|
||||
mReplyRunnable.get());
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
return true;
|
||||
}
|
||||
bool
|
||||
BluetoothRequestParent::DoRequest(const ConnectedDevicePropertiesRequest& aRequest)
|
||||
{
|
||||
MOZ_ASSERT(mService);
|
||||
MOZ_ASSERT(mRequestType == Request::TConnectedDevicePropertiesRequest);
|
||||
nsresult rv =
|
||||
mService->GetConnectedDevicePropertiesInternal(aRequest.profileId(),
|
||||
mReplyRunnable.get());
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -146,7 +146,9 @@ protected:
|
||||
DoRequest(const UnpairRequest& aRequest);
|
||||
|
||||
bool
|
||||
DoRequest(const DevicePropertiesRequest& aRequest);
|
||||
DoRequest(const PairedDevicePropertiesRequest& aRequest);
|
||||
bool
|
||||
DoRequest(const ConnectedDevicePropertiesRequest& aRequest);
|
||||
|
||||
bool
|
||||
DoRequest(const SetPinCodeRequest& aRequest);
|
||||
|
@ -110,12 +110,20 @@ BluetoothServiceChildProcess::GetDevicePropertiesInternal(
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothServiceChildProcess::GetConnectedDevicePropertiesInternal(
|
||||
uint16_t aProfileId,
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
{
|
||||
SendRequest(aRunnable, ConnectedDevicePropertiesRequest(aProfileId));
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult
|
||||
BluetoothServiceChildProcess::GetPairedDevicePropertiesInternal(
|
||||
const nsTArray<nsString>& aDeviceAddresses,
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
{
|
||||
DevicePropertiesRequest request;
|
||||
PairedDevicePropertiesRequest request;
|
||||
request.addresses().AppendElements(aDeviceAddresses);
|
||||
|
||||
SendRequest(aRunnable, request);
|
||||
|
@ -52,6 +52,10 @@ public:
|
||||
MOZ_OVERRIDE;
|
||||
|
||||
virtual nsresult
|
||||
GetConnectedDevicePropertiesInternal(uint16_t aProfileId,
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
MOZ_OVERRIDE;
|
||||
virtual nsresult
|
||||
StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
|
||||
|
||||
virtual nsresult
|
||||
|
@ -88,10 +88,14 @@ struct DenyAuthorizationRequest
|
||||
nsString path;
|
||||
};
|
||||
|
||||
struct DevicePropertiesRequest
|
||||
struct PairedDevicePropertiesRequest
|
||||
{
|
||||
nsString[] addresses;
|
||||
};
|
||||
struct ConnectedDevicePropertiesRequest
|
||||
{
|
||||
uint16_t profileId;
|
||||
};
|
||||
|
||||
struct ConnectRequest
|
||||
{
|
||||
@ -140,7 +144,8 @@ union Request
|
||||
DenyPairingConfirmationRequest;
|
||||
ConfirmAuthorizationRequest;
|
||||
DenyAuthorizationRequest;
|
||||
DevicePropertiesRequest;
|
||||
ConnectedDevicePropertiesRequest;
|
||||
PairedDevicePropertiesRequest;
|
||||
ConnectRequest;
|
||||
DisconnectRequest;
|
||||
SendFileRequest;
|
||||
|
@ -147,6 +147,7 @@ static int32_t sIsPairing = 0;
|
||||
static nsString sAdapterPath;
|
||||
|
||||
typedef void (*UnpackFunc)(DBusMessage*, DBusError*, BluetoothValue&, nsAString&);
|
||||
typedef bool (*FilterFunc)(const BluetoothValue&);
|
||||
|
||||
class RemoveDeviceTask : public nsRunnable {
|
||||
public:
|
||||
@ -191,6 +192,34 @@ private:
|
||||
nsRefPtr<BluetoothReplyRunnable> mRunnable;
|
||||
};
|
||||
|
||||
static bool
|
||||
GetConnectedDevicesFilter(const BluetoothValue& aValue)
|
||||
{
|
||||
// We don't have to filter device here
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
GetPairedDevicesFilter(const BluetoothValue& aValue)
|
||||
{
|
||||
// Check property 'Paired' and only paired device will be returned
|
||||
if (aValue.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
|
||||
NS_WARNING("Not a BluetoothNamedValue array!");
|
||||
return false;
|
||||
}
|
||||
|
||||
const InfallibleTArray<BluetoothNamedValue>& deviceProperties =
|
||||
aValue.get_ArrayOfBluetoothNamedValue();
|
||||
uint32_t length = deviceProperties.Length();
|
||||
for (uint32_t p = 0; p < length; ++p) {
|
||||
if (deviceProperties[p].name().EqualsLiteral("Paired")) {
|
||||
return deviceProperties[p].value().get_bool();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
class SendDiscoveryTask : public nsRunnable {
|
||||
public:
|
||||
SendDiscoveryTask(const char* aMessageName,
|
||||
@ -1911,14 +1940,16 @@ private:
|
||||
BluetoothSignal mSignal;
|
||||
};
|
||||
|
||||
class BluetoothPairedDevicePropertiesRunnable : public nsRunnable
|
||||
class BluetoothArrayOfDevicePropertiesRunnable : public nsRunnable
|
||||
{
|
||||
public:
|
||||
BluetoothPairedDevicePropertiesRunnable(
|
||||
BluetoothArrayOfDevicePropertiesRunnable(
|
||||
const nsTArray<nsString>& aDeviceAddresses,
|
||||
BluetoothReplyRunnable* aRunnable,
|
||||
const nsTArray<nsString>& aDeviceAddresses)
|
||||
: mRunnable(dont_AddRef(aRunnable)),
|
||||
mDeviceAddresses(aDeviceAddresses)
|
||||
FilterFunc aFilterFunc)
|
||||
: mDeviceAddresses(aDeviceAddresses)
|
||||
, mRunnable(dont_AddRef(aRunnable))
|
||||
, mFilterFunc(aFilterFunc)
|
||||
{
|
||||
}
|
||||
|
||||
@ -1930,51 +1961,39 @@ public:
|
||||
dbus_error_init(&err);
|
||||
|
||||
BluetoothValue values = InfallibleTArray<BluetoothNamedValue>();
|
||||
nsAutoString errorStr;
|
||||
|
||||
for (uint32_t i = 0; i < mDeviceAddresses.Length(); i++) {
|
||||
BluetoothValue v;
|
||||
if (!GetPropertiesInternal(mDeviceAddresses[i], DBUS_DEVICE_IFACE, v)) {
|
||||
nsAutoString errorStr;
|
||||
nsString objectPath = GetObjectPathFromAddress(sAdapterPath, mDeviceAddresses[i]);
|
||||
|
||||
if (!GetPropertiesInternal(objectPath, DBUS_DEVICE_IFACE, v)) {
|
||||
errorStr.AssignLiteral("Getting properties failed!");
|
||||
NS_WARNING(NS_ConvertUTF16toUTF8(errorStr).get());
|
||||
mRunnable->SetReply(new BluetoothReply(BluetoothReplyError(errorStr)));
|
||||
if (NS_FAILED(NS_DispatchToMainThread(mRunnable))) {
|
||||
NS_WARNING("Failed to dispatch to main thread!");
|
||||
}
|
||||
DispatchBluetoothReply(mRunnable, values, errorStr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// We have to manually attach the path to the rest of the elements
|
||||
v.get_ArrayOfBluetoothNamedValue().AppendElement(
|
||||
BluetoothNamedValue(NS_LITERAL_STRING("Path"), mDeviceAddresses[i])
|
||||
BluetoothNamedValue(NS_LITERAL_STRING("Path"), objectPath)
|
||||
);
|
||||
|
||||
InfallibleTArray<BluetoothNamedValue>& deviceProperties =
|
||||
v.get_ArrayOfBluetoothNamedValue();
|
||||
for (uint32_t p = 0;
|
||||
p < v.get_ArrayOfBluetoothNamedValue().Length(); ++p) {
|
||||
BluetoothNamedValue& property = v.get_ArrayOfBluetoothNamedValue()[p];
|
||||
// Only paired devices will be return back to main thread
|
||||
if (property.name().EqualsLiteral("Paired")) {
|
||||
bool paired = property.value();
|
||||
if (paired) {
|
||||
values.get_ArrayOfBluetoothNamedValue().AppendElement(
|
||||
BluetoothNamedValue(mDeviceAddresses[i], deviceProperties)
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (mFilterFunc(v)) {
|
||||
values.get_ArrayOfBluetoothNamedValue().AppendElement(
|
||||
BluetoothNamedValue(mDeviceAddresses[i],
|
||||
v.get_ArrayOfBluetoothNamedValue())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mRunnable->SetReply(new BluetoothReply(BluetoothReplySuccess(values)));
|
||||
if (NS_FAILED(NS_DispatchToMainThread(mRunnable))) {
|
||||
NS_WARNING("Failed to dispatch to main thread!");
|
||||
}
|
||||
DispatchBluetoothReply(mRunnable, values, errorStr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
nsRefPtr<BluetoothReplyRunnable> mRunnable;
|
||||
nsTArray<nsString> mDeviceAddresses;
|
||||
nsRefPtr<BluetoothReplyRunnable> mRunnable;
|
||||
FilterFunc mFilterFunc;
|
||||
};
|
||||
|
||||
nsresult
|
||||
@ -1996,6 +2015,55 @@ BluetoothDBusService::GetDevicePropertiesInternal(const BluetoothSignal& aSignal
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothDBusService::GetConnectedDevicePropertiesInternal(uint16_t aProfileId,
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
{
|
||||
nsAutoString errorStr;
|
||||
BluetoothValue values = InfallibleTArray<BluetoothNamedValue>();
|
||||
if (!IsReady()) {
|
||||
errorStr.AssignLiteral("Bluetooth service is not ready yet!");
|
||||
DispatchBluetoothReply(aRunnable, values, errorStr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsTArray<nsString> deviceAddresses;
|
||||
if (aProfileId == BluetoothServiceClass::HANDSFREE ||
|
||||
aProfileId == BluetoothServiceClass::HEADSET) {
|
||||
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
|
||||
if (hfp->IsConnected()) {
|
||||
nsString address;
|
||||
hfp->GetAddress(address);
|
||||
deviceAddresses.AppendElement(address);
|
||||
}
|
||||
} else if (aProfileId == BluetoothServiceClass::OBJECT_PUSH) {
|
||||
BluetoothOppManager* opp = BluetoothOppManager::Get();
|
||||
if (opp->IsTransferring()) {
|
||||
nsString address;
|
||||
opp->GetAddress(address);
|
||||
deviceAddresses.AppendElement(address);
|
||||
}
|
||||
} else {
|
||||
errorStr.AssignLiteral("Unknown profile");
|
||||
DispatchBluetoothReply(aRunnable, values, errorStr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsRefPtr<BluetoothReplyRunnable> runnable = aRunnable;
|
||||
nsRefPtr<nsRunnable> func(
|
||||
new BluetoothArrayOfDevicePropertiesRunnable(deviceAddresses,
|
||||
runnable,
|
||||
GetConnectedDevicesFilter));
|
||||
|
||||
if (NS_FAILED(mBluetoothCommandThread->Dispatch(func, NS_DISPATCH_NORMAL))) {
|
||||
NS_WARNING("Cannot dispatch task!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
runnable.forget();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothDBusService::GetPairedDevicePropertiesInternal(
|
||||
const nsTArray<nsString>& aDeviceAddresses,
|
||||
@ -2011,7 +2079,9 @@ BluetoothDBusService::GetPairedDevicePropertiesInternal(
|
||||
|
||||
nsRefPtr<BluetoothReplyRunnable> runnable = aRunnable;
|
||||
nsRefPtr<nsRunnable> func(
|
||||
new BluetoothPairedDevicePropertiesRunnable(runnable, aDeviceAddresses));
|
||||
new BluetoothArrayOfDevicePropertiesRunnable(aDeviceAddresses,
|
||||
runnable,
|
||||
GetPairedDevicesFilter));
|
||||
if (NS_FAILED(mBluetoothCommandThread->Dispatch(func, NS_DISPATCH_NORMAL))) {
|
||||
NS_WARNING("Cannot dispatch task!");
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -2487,7 +2557,8 @@ BluetoothDBusService::Connect(const nsAString& aDeviceAddress,
|
||||
DispatchBluetoothReply(aRunnable, v, errorStr);
|
||||
}
|
||||
} else {
|
||||
NS_WARNING("Unknown Profile");
|
||||
errorStr.AssignLiteral("Unknown profile");
|
||||
DispatchBluetoothReply(aRunnable, v, errorStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,10 +32,15 @@ public:
|
||||
|
||||
virtual bool IsEnabledInternal();
|
||||
|
||||
virtual nsresult GetDefaultAdapterPathInternal(BluetoothReplyRunnable* aRunnable);
|
||||
virtual nsresult GetDefaultAdapterPathInternal(
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual nsresult GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddresses,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
virtual nsresult GetConnectedDevicePropertiesInternal(uint16_t aProfileId,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual nsresult GetPairedDevicePropertiesInternal(
|
||||
const nsTArray<nsString>& aDeviceAddresses,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual nsresult StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
|
@ -10,7 +10,7 @@ interface nsIDOMDOMRequest;
|
||||
interface nsIDOMBlob;
|
||||
interface nsIDOMBluetoothDevice;
|
||||
|
||||
[scriptable, builtinclass, uuid(4321647b-0d45-4231-920b-8d238b6d1700)]
|
||||
[scriptable, builtinclass, uuid(88a5638f-f55a-4d67-8437-392d0a9a87c7)]
|
||||
interface nsIDOMBluetoothAdapter : nsIDOMEventTarget
|
||||
{
|
||||
readonly attribute DOMString address;
|
||||
@ -36,6 +36,7 @@ interface nsIDOMBluetoothAdapter : nsIDOMEventTarget
|
||||
nsIDOMDOMRequest pair(in nsIDOMBluetoothDevice aDevice);
|
||||
nsIDOMDOMRequest unpair(in nsIDOMBluetoothDevice aDevice);
|
||||
nsIDOMDOMRequest getPairedDevices();
|
||||
nsIDOMDOMRequest getConnectedDevices(in unsigned short aProfile);
|
||||
nsIDOMDOMRequest setPinCode(in DOMString aDeviceAddress, in DOMString aPinCode);
|
||||
nsIDOMDOMRequest setPasskey(in DOMString aDeviceAddress, in unsigned long aPasskey);
|
||||
nsIDOMDOMRequest setPairingConfirmation(in DOMString aDeviceAddress, in bool aConfirmation);
|
||||
|
Loading…
Reference in New Issue
Block a user