Backed out changeset 4a99cfd718aa (bug 1215525)

This commit is contained in:
Carsten "Tomcat" Book 2015-10-29 14:37:34 +01:00
parent c99fbefe39
commit aa4d7353fb
43 changed files with 523 additions and 604 deletions

View File

@ -411,7 +411,7 @@ BluetoothA2dpManager::OnConnectError()
mController->NotifyCompletion(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
mController = nullptr;
mDeviceAddress.Clear();
mDeviceAddress.Truncate();
}
class BluetoothA2dpManager::ConnectResultHandler final
@ -428,11 +428,11 @@ public:
};
void
BluetoothA2dpManager::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothA2dpManager::Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!aDeviceAddress.IsCleared());
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
MOZ_ASSERT(aController);
BluetoothService* bs = BluetoothService::Get();
@ -455,7 +455,13 @@ BluetoothA2dpManager::Connect(const BluetoothAddress& aDeviceAddress,
return;
}
sBtA2dpInterface->Connect(mDeviceAddress, new ConnectResultHandler());
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(aDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
return;
}
sBtA2dpInterface->Connect(deviceAddress, new ConnectResultHandler());
}
void
@ -503,7 +509,7 @@ BluetoothA2dpManager::Disconnect(BluetoothProfileController* aController)
return;
}
MOZ_ASSERT(!mDeviceAddress.IsCleared());
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
mController = aController;
@ -516,7 +522,13 @@ BluetoothA2dpManager::Disconnect(BluetoothProfileController* aController)
return;
}
sBtA2dpInterface->Disconnect(mDeviceAddress, new DisconnectResultHandler());
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(mDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
return;
}
sBtA2dpInterface->Disconnect(deviceAddress, new DisconnectResultHandler());
}
void
@ -576,15 +588,14 @@ BluetoothA2dpManager::HandleSinkPropertyChanged(const BluetoothSignal& aSignal)
MOZ_ASSERT(aSignal.value().type() ==
BluetoothValue::TArrayOfBluetoothNamedValue);
BluetoothAddress address;
NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(StringToAddress(aSignal.path(), address)));
const nsString& address = aSignal.path();
/**
* Update sink property only if
* - mDeviceAddress is empty (A2dp is disconnected), or
* - this property change is from the connected sink.
*/
NS_ENSURE_TRUE_VOID(mDeviceAddress.IsCleared() || mDeviceAddress == address);
NS_ENSURE_TRUE_VOID(mDeviceAddress.IsEmpty() ||
mDeviceAddress.Equals(address));
const InfallibleTArray<BluetoothNamedValue>& arr =
aSignal.value().get_ArrayOfBluetoothNamedValue();
@ -647,7 +658,7 @@ BluetoothA2dpManager::HandleSinkPropertyChanged(const BluetoothSignal& aSignal)
mA2dpConnected = false;
NotifyConnectionStatusChanged();
mDeviceAddress.Clear();
mDeviceAddress.Truncate();
OnDisconnect(EmptyString());
break;
default:
@ -663,8 +674,14 @@ void
BluetoothA2dpManager::HandleBackendError()
{
if (mSinkState != SinkState::SINK_DISCONNECTED) {
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(mDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
return;
}
ConnectionStateNotification(A2DP_CONNECTION_STATE_DISCONNECTED,
mDeviceAddress);
deviceAddress);
}
}
@ -677,34 +694,31 @@ BluetoothA2dpManager::NotifyConnectionStatusChanged()
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
NS_ENSURE_TRUE_VOID(obs);
nsAutoString deviceAddressStr;
AddressToString(mDeviceAddress, deviceAddressStr);
if (NS_FAILED(obs->NotifyObservers(this,
BLUETOOTH_A2DP_STATUS_CHANGED_ID,
deviceAddressStr.get()))) {
mDeviceAddress.get()))) {
BT_WARNING("Failed to notify bluetooth-a2dp-status-changed observsers!");
}
// Dispatch an event of status change
DispatchStatusChangedEvent(
NS_LITERAL_STRING(A2DP_STATUS_CHANGED_ID), deviceAddressStr, mA2dpConnected);
NS_LITERAL_STRING(A2DP_STATUS_CHANGED_ID), mDeviceAddress, mA2dpConnected);
}
void
BluetoothA2dpManager::OnGetServiceChannel(const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
BluetoothA2dpManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel)
{
}
void
BluetoothA2dpManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
BluetoothA2dpManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
{
}
void
BluetoothA2dpManager::GetAddress(BluetoothAddress& aDeviceAddress)
BluetoothA2dpManager::GetAddress(nsAString& aDeviceAddress)
{
aDeviceAddress = mDeviceAddress;
}

View File

@ -66,7 +66,7 @@ private:
void AudioStateNotification(BluetoothA2dpAudioState aState,
const BluetoothAddress& aBdAddr) override;
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
RefPtr<BluetoothProfileController> mController;
// A2DP data member

View File

@ -441,11 +441,11 @@ private:
};
void
BluetoothAvrcpManager::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothAvrcpManager::Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!aDeviceAddress.IsCleared());
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
MOZ_ASSERT(aController);
// AVRCP doesn't require connecting. We just set the remote address here.
@ -479,7 +479,7 @@ BluetoothAvrcpManager::Disconnect(BluetoothProfileController* aController)
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mController);
mDeviceAddress.Clear();
mDeviceAddress.Truncate();
mController = aController;
SetConnected(false);
@ -519,19 +519,17 @@ BluetoothAvrcpManager::OnDisconnect(const nsAString& aErrorStr)
}
void
BluetoothAvrcpManager::OnGetServiceChannel(
const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
int aChannel)
BluetoothAvrcpManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel)
{ }
void
BluetoothAvrcpManager::OnUpdateSdpRecords(
const BluetoothAddress& aDeviceAddress)
BluetoothAvrcpManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
{ }
void
BluetoothAvrcpManager::GetAddress(BluetoothAddress& aDeviceAddress)
BluetoothAvrcpManager::GetAddress(nsAString& aDeviceAddress)
{
aDeviceAddress = mDeviceAddress;
}

View File

@ -109,7 +109,7 @@ private:
void PassthroughCmdNotification(int aId, int aKeyState) override;
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
RefPtr<BluetoothProfileController> mController;
bool mAvrcpConnected;

View File

@ -1709,7 +1709,7 @@ public:
, mDeviceAddr(aDeviceAddr)
{
MOZ_ASSERT(mServer);
MOZ_ASSERT(!mDeviceAddr.IsCleared());
MOZ_ASSERT(mDeviceAddr != BluetoothAddress::ANY);
}
void OnError(BluetoothStatus aStatus) override

View File

@ -91,6 +91,7 @@ BluetoothMapSmsManager::BluetoothMapSmsManager() : mMasConnected(false),
mMnsConnected(false),
mNtfRequired(false)
{
mDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
BuildDefaultFolderStructure();
}
@ -482,7 +483,7 @@ BluetoothMapSmsManager::IsConnected()
}
void
BluetoothMapSmsManager::GetAddress(BluetoothAddress& aDeviceAddress)
BluetoothMapSmsManager::GetAddress(nsAString& aDeviceAddress)
{
return mMasSocket->GetAddress(aDeviceAddress);
}
@ -1234,7 +1235,7 @@ BluetoothMapSmsManager::OnSocketDisconnect(BluetoothSocket* aSocket)
// MAS socket is disconnected
AfterMapSmsDisconnected();
mDeviceAddress.Clear();
mDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
mMasSocket = nullptr;
Listen();
@ -1254,23 +1255,22 @@ BluetoothMapSmsManager::Disconnect(BluetoothProfileController* aController)
NS_IMPL_ISUPPORTS(BluetoothMapSmsManager, nsIObserver)
void
BluetoothMapSmsManager::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothMapSmsManager::Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController)
{
MOZ_ASSERT(false);
}
void
BluetoothMapSmsManager::OnGetServiceChannel(
const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
int aChannel)
BluetoothMapSmsManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel)
{
MOZ_ASSERT(false);
}
void
BluetoothMapSmsManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
BluetoothMapSmsManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
{
MOZ_ASSERT(false);
}

View File

@ -243,7 +243,7 @@ private:
// MNS OBEX session status. Set when MNS OBEX session is established.
bool mMnsConnected;
bool mNtfRequired;
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
unsigned int mRemoteMaxPacketLength;
// If a connection has been established, mMasSocket will be the socket

View File

@ -71,13 +71,13 @@ BEGIN_BLUETOOTH_NAMESPACE
class BluetoothOppManager::SendFileBatch final
{
public:
SendFileBatch(const BluetoothAddress& aDeviceAddress, Blob* aBlob)
SendFileBatch(const nsAString& aDeviceAddress, Blob* aBlob)
: mDeviceAddress(aDeviceAddress)
{
mBlobs.AppendElement(aBlob);
}
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
nsTArray<RefPtr<Blob>> mBlobs;
};
@ -209,7 +209,9 @@ BluetoothOppManager::BluetoothOppManager() : mConnected(false)
, mSentFileLength(0)
, mWaitingToSendPutFinal(false)
, mCurrentBlobIndex(-1)
{ }
{
mDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
}
BluetoothOppManager::~BluetoothOppManager()
{
@ -274,7 +276,7 @@ BluetoothOppManager::Get()
}
void
BluetoothOppManager::ConnectInternal(const BluetoothAddress& aDeviceAddress)
BluetoothOppManager::ConnectInternal(const nsAString& aDeviceAddress)
{
MOZ_ASSERT(NS_IsMainThread());
@ -294,7 +296,10 @@ BluetoothOppManager::ConnectInternal(const BluetoothAddress& aDeviceAddress)
mNeedsUpdatingSdpRecords = true;
if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress, kObexObjectPush, this))) {
nsString uuid;
BluetoothUuidHelper::GetString(BluetoothServiceClass::OBJECT_PUSH, uuid);
if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress, uuid, this))) {
OnSocketConnectError(mSocket);
return;
}
@ -404,7 +409,7 @@ BluetoothOppManager::StartSendingNextFile()
}
bool
BluetoothOppManager::SendFile(const BluetoothAddress& aDeviceAddress,
BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
BlobParent* aActor)
{
MOZ_ASSERT(NS_IsMainThread());
@ -416,7 +421,7 @@ BluetoothOppManager::SendFile(const BluetoothAddress& aDeviceAddress,
}
bool
BluetoothOppManager::SendFile(const BluetoothAddress& aDeviceAddress,
BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
Blob* aBlob)
{
MOZ_ASSERT(NS_IsMainThread());
@ -430,7 +435,7 @@ BluetoothOppManager::SendFile(const BluetoothAddress& aDeviceAddress,
}
void
BluetoothOppManager::AppendBlobToSend(const BluetoothAddress& aDeviceAddress,
BluetoothOppManager::AppendBlobToSend(const nsAString& aDeviceAddress,
Blob* aBlob)
{
MOZ_ASSERT(NS_IsMainThread());
@ -1317,7 +1322,7 @@ BluetoothOppManager::IsConnected()
}
void
BluetoothOppManager::GetAddress(BluetoothAddress& aDeviceAddress)
BluetoothOppManager::GetAddress(nsAString& aDeviceAddress)
{
return mSocket->GetAddress(aDeviceAddress);
}
@ -1418,13 +1423,10 @@ BluetoothOppManager::FileTransferComplete()
return;
}
nsAutoString deviceAddressStr;
AddressToString(mDeviceAddress, deviceAddressStr);
NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-transfer-complete");
InfallibleTArray<BluetoothNamedValue> parameters;
AppendNamedValue(parameters, "address", deviceAddressStr);
AppendNamedValue(parameters, "address", mDeviceAddress);
AppendNamedValue(parameters, "success", mSuccessFlag);
AppendNamedValue(parameters, "received", mIsServer);
AppendNamedValue(parameters, "fileName", mFileName);
@ -1439,13 +1441,10 @@ BluetoothOppManager::FileTransferComplete()
void
BluetoothOppManager::StartFileTransfer()
{
nsAutoString deviceAddressStr;
AddressToString(mDeviceAddress, deviceAddressStr);
NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-transfer-start");
InfallibleTArray<BluetoothNamedValue> parameters;
AppendNamedValue(parameters, "address", deviceAddressStr);
AppendNamedValue(parameters, "address", mDeviceAddress);
AppendNamedValue(parameters, "received", mIsServer);
AppendNamedValue(parameters, "fileName", mFileName);
AppendNamedValue(parameters, "fileLength", mFileLength);
@ -1459,13 +1458,10 @@ BluetoothOppManager::StartFileTransfer()
void
BluetoothOppManager::UpdateProgress()
{
nsAutoString deviceAddressStr;
AddressToString(mDeviceAddress, deviceAddressStr);
NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-update-progress");
InfallibleTArray<BluetoothNamedValue> parameters;
AppendNamedValue(parameters, "address", deviceAddressStr);
AppendNamedValue(parameters, "address", mDeviceAddress);
AppendNamedValue(parameters, "received", mIsServer);
AppendNamedValue(parameters, "processedLength", mSentFileLength);
AppendNamedValue(parameters, "fileLength", mFileLength);
@ -1476,13 +1472,10 @@ BluetoothOppManager::UpdateProgress()
void
BluetoothOppManager::ReceivingFileConfirmation()
{
nsAutoString deviceAddressStr;
AddressToString(mDeviceAddress, deviceAddressStr);
NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-receiving-file-confirmation");
InfallibleTArray<BluetoothNamedValue> parameters;
AppendNamedValue(parameters, "address", deviceAddressStr);
AppendNamedValue(parameters, "address", mDeviceAddress);
AppendNamedValue(parameters, "fileName", mFileName);
AppendNamedValue(parameters, "fileLength", mFileLength);
AppendNamedValue(parameters, "contentType", mContentType);
@ -1581,7 +1574,7 @@ BluetoothOppManager::OnSocketDisconnect(BluetoothSocket* aSocket)
}
AfterOppDisconnected();
mDeviceAddress.Clear();
mDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
mSuccessFlag = false;
mSocket = nullptr;
@ -1619,11 +1612,13 @@ BluetoothOppManager::AcquireSdcardMountLock()
}
void
BluetoothOppManager::OnGetServiceChannel(
const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
int aChannel)
BluetoothOppManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel)
{
BluetoothUuid serviceUuid;
StringToUuid(aServiceUuid, serviceUuid);
if (aChannel < 0) {
BluetoothService* bs = BluetoothService::Get();
if (!bs || sInShutdown) {
@ -1650,13 +1645,13 @@ BluetoothOppManager::OnGetServiceChannel(
}
}
mSocket->Connect(aDeviceAddress, aServiceUuid,
mSocket->Connect(aDeviceAddress, serviceUuid,
BluetoothSocketType::RFCOMM, aChannel,
false, true);
}
void
BluetoothOppManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
BluetoothOppManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
{
BluetoothService* bs = BluetoothService::Get();
if (!bs || sInShutdown) {
@ -1664,14 +1659,17 @@ BluetoothOppManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
return;
}
if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress, kObexObjectPush, this))) {
nsString uuid;
BluetoothUuidHelper::GetString(BluetoothServiceClass::OBJECT_PUSH, uuid);
if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress, uuid, this))) {
OnSocketConnectError(mSocket);
return;
}
}
void
BluetoothOppManager::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothOppManager::Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController)
{
MOZ_ASSERT(false);

View File

@ -54,8 +54,8 @@ public:
bool Listen();
bool SendFile(const BluetoothAddress& aDeviceAddress, BlobParent* aActor);
bool SendFile(const BluetoothAddress& aDeviceAddress, Blob* aBlob);
bool SendFile(const nsAString& aDeviceAddress, BlobParent* aActor);
bool SendFile(const nsAString& aDeviceAddress, Blob* aBlob);
bool StopSendingFile();
bool ConfirmReceivingFile(bool aConfirm);
@ -101,10 +101,10 @@ private:
void NotifyAboutFileChange();
bool AcquireSdcardMountLock();
void SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
void AppendBlobToSend(const BluetoothAddress& aDeviceAddress, Blob* aBlob);
void AppendBlobToSend(const nsAString& aDeviceAddress, Blob* aBlob);
void DiscardBlobsToSend();
bool ProcessNextBatch();
void ConnectInternal(const BluetoothAddress& aDeviceAddress);
void ConnectInternal(const nsAString& aDeviceAddress);
/**
* Usually we won't get a full PUT packet in one operation, which means that
@ -123,7 +123,7 @@ private:
* Set when OBEX session is established.
*/
bool mConnected;
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
/**
* Remote information

View File

@ -100,6 +100,7 @@ BluetoothPbapManager::BluetoothPbapManager() : mPhonebookSizeRequired(false)
, mConnected(false)
, mRemoteMaxPacketLength(0)
{
mDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
mCurrentPath.AssignLiteral("");
}
@ -654,7 +655,7 @@ BluetoothPbapManager::IsConnected()
}
void
BluetoothPbapManager::GetAddress(BluetoothAddress& aDeviceAddress)
BluetoothPbapManager::GetAddress(nsAString& aDeviceAddress)
{
return mSocket->GetAddress(aDeviceAddress);
}
@ -1012,7 +1013,7 @@ BluetoothPbapManager::OnSocketDisconnect(BluetoothSocket* aSocket)
}
AfterPbapDisconnected();
mDeviceAddress.Clear();
mDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
mSocket = nullptr;
Listen();
@ -1032,24 +1033,22 @@ BluetoothPbapManager::Disconnect(BluetoothProfileController* aController)
NS_IMPL_ISUPPORTS(BluetoothPbapManager, nsIObserver)
void
BluetoothPbapManager::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothPbapManager::Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController)
{
MOZ_ASSERT(false);
}
void
BluetoothPbapManager::OnGetServiceChannel(
const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
int aChannel)
BluetoothPbapManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel)
{
MOZ_ASSERT(false);
}
void
BluetoothPbapManager::OnUpdateSdpRecords(
const BluetoothAddress& aDeviceAddress)
BluetoothPbapManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
{
MOZ_ASSERT(false);
}

View File

@ -169,7 +169,7 @@ private:
* OBEX session status. Set when OBEX session is established
*/
bool mConnected;
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
/**
* Current phonebook path

View File

@ -902,8 +902,15 @@ BluetoothServiceBluedroid::GetConnectedDevicePropertiesInternal(
}
// Get address of the connected device
nsString addressString;
profile->GetAddress(addressString);
BluetoothAddress address;
profile->GetAddress(address);
nsresult rv = StringToAddress(addressString, address);
if (NS_FAILED(rv)) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return rv;
}
// Append request of the connected device
GetDeviceRequest request(1, aRunnable);
@ -1098,8 +1105,11 @@ public:
// Signal error to profile manager
nsAutoString addressStr, uuidStr;
AddressToString(mDeviceAddress, addressStr);
UuidToString(mUuid, uuidStr);
mGetRemoteServiceRecordArray[i].mManager->OnGetServiceChannel(
mDeviceAddress, mUuid, -1);
addressStr, uuidStr, -1);
mGetRemoteServiceRecordArray.RemoveElementAt(i);
}
@ -1129,16 +1139,25 @@ private:
nsresult
BluetoothServiceBluedroid::GetServiceChannel(
const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
BluetoothProfileManagerBase* aManager)
{
BluetoothAddress address;
nsresult rv = StringToAddress(aDeviceAddress, address);
if (NS_FAILED(rv)) {
return rv;
}
BluetoothUuid uuid;
StringToUuid(aServiceUuid, uuid);
mGetRemoteServiceRecordArray.AppendElement(
GetRemoteServiceRecordRequest(aDeviceAddress, aServiceUuid, aManager));
GetRemoteServiceRecordRequest(address, uuid, aManager));
RefPtr<BluetoothResultHandler> res =
new GetRemoteServiceRecordResultHandler(mGetRemoteServiceRecordArray,
aDeviceAddress, aServiceUuid);
address, uuid);
/* Stop discovery of remote devices here, because SDP operations
* won't be performed while the adapter is in discovery mode.
@ -1146,7 +1165,7 @@ BluetoothServiceBluedroid::GetServiceChannel(
if (mDiscovering) {
sBtInterface->CancelDiscovery(res);
} else {
sBtInterface->GetRemoteServiceRecord(aDeviceAddress, aServiceUuid, res);
sBtInterface->GetRemoteServiceRecord(address, uuid, res);
}
return NS_OK;
@ -1194,7 +1213,9 @@ public:
mGetRemoteServicesArray.RemoveElementAt(i);
// There's no error-signaling mechanism; just call manager
mManager->OnUpdateSdpRecords(mDeviceAddress);
nsAutoString addressStr;
AddressToString(mDeviceAddress, addressStr);
mManager->OnUpdateSdpRecords(addressStr);
}
void CancelDiscovery() override
@ -1223,15 +1244,21 @@ private:
bool
BluetoothServiceBluedroid::UpdateSdpRecords(
const BluetoothAddress& aDeviceAddress,
const nsAString& aDeviceAddress,
BluetoothProfileManagerBase* aManager)
{
BluetoothAddress address;
nsresult rv = StringToAddress(aDeviceAddress, address);
if (NS_FAILED(rv)) {
return false;
}
mGetRemoteServicesArray.AppendElement(
GetRemoteServicesRequest(aDeviceAddress, aManager));
GetRemoteServicesRequest(address, aManager));
RefPtr<BluetoothResultHandler> res =
new GetRemoteServicesResultHandler(mGetRemoteServicesArray,
aDeviceAddress, aManager);
address, aManager);
/* Stop discovery of remote devices here, because SDP operations
* won't be performed while the adapter is in discovery mode.
@ -1239,7 +1266,7 @@ BluetoothServiceBluedroid::UpdateSdpRecords(
if (mDiscovering) {
sBtInterface->CancelDiscovery(res);
} else {
sBtInterface->GetRemoteServices(aDeviceAddress, res);
sBtInterface->GetRemoteServices(address, res);
}
return true;
@ -1429,15 +1456,8 @@ BluetoothServiceBluedroid::ConnectDisconnect(
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);
@ -1477,20 +1497,13 @@ BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress,
{
MOZ_ASSERT(NS_IsMainThread());
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(aDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
// Currently we only support one device sending one file at a time,
// so we don't need aDeviceAddress here because the target device
// has been determined when calling 'Connect()'. Nevertheless, keep
// it for future use.
BluetoothOppManager* opp = BluetoothOppManager::Get();
if (!opp || !opp->SendFile(deviceAddress, aBlobParent)) {
if (!opp || !opp->SendFile(aDeviceAddress, aBlobParent)) {
DispatchReplyError(aRunnable, NS_LITERAL_STRING("SendFile failed"));
return;
}
@ -1505,20 +1518,13 @@ BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress,
{
MOZ_ASSERT(NS_IsMainThread());
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(aDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
// Currently we only support one device sending one file at a time,
// so we don't need aDeviceAddress here because the target device
// has been determined when calling 'Connect()'. Nevertheless, keep
// it for future use.
BluetoothOppManager* opp = BluetoothOppManager::Get();
if (!opp || !opp->SendFile(deviceAddress, aBlob)) {
if (!opp || !opp->SendFile(aDeviceAddress, aBlob)) {
DispatchReplyError(aRunnable, NS_LITERAL_STRING("SendFile failed"));
return;
}
@ -2250,7 +2256,7 @@ BluetoothServiceBluedroid::RemoteDevicePropertiesNotification(
}
if (index < mGetRemoteServicesArray.Length()) {
mGetRemoteServicesArray[index].mManager->OnUpdateSdpRecords(aBdAddr);
mGetRemoteServicesArray[index].mManager->OnUpdateSdpRecords(bdAddrStr);
mGetRemoteServicesArray.RemoveElementAt(index);
continue; // continue with outer loop
}
@ -2285,10 +2291,11 @@ BluetoothServiceBluedroid::RemoteDevicePropertiesNotification(
(mGetRemoteServiceRecordArray[i].mUuid == p.mServiceRecord.mUuid)) {
// Signal channel to profile manager
nsAutoString uuidStr;
UuidToString(mGetRemoteServiceRecordArray[i].mUuid, uuidStr);
mGetRemoteServiceRecordArray[i].mManager->OnGetServiceChannel(
aBdAddr,
mGetRemoteServiceRecordArray[i].mUuid,
p.mServiceRecord.mChannel);
bdAddrStr, uuidStr, p.mServiceRecord.mChannel);
mGetRemoteServiceRecordArray.RemoveElementAt(i);
break;

View File

@ -66,12 +66,12 @@ public:
BluetoothReplyRunnable* aRunnable);
virtual nsresult
GetServiceChannel(const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
GetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
BluetoothProfileManagerBase* aManager);
virtual bool
UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
UpdateSdpRecords(const nsAString& aDeviceAddress,
BluetoothProfileManagerBase* aManager);
virtual nsresult

View File

@ -403,7 +403,10 @@ public:
return;
}
mImpl->mConsumer->SetAddress(aBdAddress);
nsAutoString addressStr;
AddressToString(aBdAddress, addressStr);
mImpl->mConsumer->SetAddress(addressStr);
mImpl->GetIOLoop()->PostTask(FROM_HERE,
new AcceptTask(mImpl, fd.forget()));
}
@ -590,6 +593,7 @@ BluetoothSocket::BluetoothSocket(BluetoothSocketObserver* aObserver)
MOZ_COUNT_CTOR_INHERITED(BluetoothSocket, DataSocket);
EnsureBluetoothSocketHalLoad();
mDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
}
BluetoothSocket::~BluetoothSocket()
@ -621,7 +625,10 @@ public:
return;
}
mImpl->mConsumer->SetAddress(aBdAddress);
nsAutoString addressStr;
AddressToString(aBdAddress, addressStr);
mImpl->mConsumer->SetAddress(addressStr);
mImpl->GetIOLoop()->PostTask(FROM_HERE,
new SocketConnectTask(mImpl, aFd));
}
@ -645,7 +652,7 @@ private:
};
nsresult
BluetoothSocket::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothSocket::Connect(const nsAString& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
BluetoothSocketType aType,
int aChannel,
@ -662,8 +669,14 @@ BluetoothSocket::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothSocketResultHandler* res = new ConnectSocketResultHandler(mImpl);
SetCurrentResultHandler(res);
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(aDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
return rv;
}
sBluetoothSocketInterface->Connect(
aDeviceAddress, aType,
deviceAddress, aType,
aServiceUuid, aChannel,
aEncrypt, aAuth, res);
@ -671,7 +684,7 @@ BluetoothSocket::Connect(const BluetoothAddress& aDeviceAddress,
}
nsresult
BluetoothSocket::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothSocket::Connect(const nsAString& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
BluetoothSocketType aType,
int aChannel,

View File

@ -24,7 +24,7 @@ public:
BluetoothSocket(BluetoothSocketObserver* aObserver);
~BluetoothSocket();
nsresult Connect(const BluetoothAddress& aDeviceAddress,
nsresult Connect(const nsAString& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
BluetoothSocketType aType,
int aChannel,
@ -32,7 +32,7 @@ public:
MessageLoop* aConsumerLoop,
MessageLoop* aIOLoop);
nsresult Connect(const BluetoothAddress& aDeviceAddress,
nsresult Connect(const nsAString& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
BluetoothSocketType aType,
int aChannel,
@ -60,12 +60,12 @@ public:
*/
void ReceiveSocketData(nsAutoPtr<mozilla::ipc::UnixSocketBuffer>& aBuffer);
inline void GetAddress(BluetoothAddress& aDeviceAddress)
inline void GetAddress(nsAString& aDeviceAddress)
{
aDeviceAddress = mDeviceAddress;
}
inline void SetAddress(const BluetoothAddress& aDeviceAddress)
inline void SetAddress(const nsAString& aDeviceAddress)
{
mDeviceAddress = aDeviceAddress;
}
@ -93,7 +93,7 @@ private:
BluetoothSocketObserver* mObserver;
BluetoothSocketResultHandler* mCurrentRes;
DroidSocketImpl* mImpl;
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
};
END_BLUETOOTH_NAMESPACE

View File

@ -42,7 +42,7 @@ BluetoothHfpManager::Observe(nsISupports* aSubject,
* BluetoothProfileManagerBase functions
*/
void
BluetoothHfpManager::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController)
{
MOZ_ASSERT(aController);
@ -77,16 +77,15 @@ BluetoothHfpManager::OnDisconnect(const nsAString& aErrorStr)
}
void
BluetoothHfpManager::GetAddress(BluetoothAddress& aDeviceAddress)
BluetoothHfpManager::GetAddress(nsAString& aDeviceAddress)
{
aDeviceAddress.Clear();
aDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
}
void
BluetoothHfpManager::OnGetServiceChannel(
const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
int aChannel)
BluetoothHfpManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel)
{
MOZ_ASSERT(false);
}

View File

@ -602,11 +602,8 @@ BluetoothHfpManager::NotifyConnectionStateChanged(const nsAString& aType)
do_GetService("@mozilla.org/observer-service;1");
NS_ENSURE_TRUE_VOID(obs);
nsAutoString deviceAddressStr;
AddressToString(mDeviceAddress, deviceAddressStr);
if (NS_FAILED(obs->NotifyObservers(this, NS_ConvertUTF16toUTF8(aType).get(),
deviceAddressStr.get()))) {
mDeviceAddress.get()))) {
BT_WARNING("Failed to notify observsers!");
}
@ -624,7 +621,7 @@ BluetoothHfpManager::NotifyConnectionStateChanged(const nsAString& aType)
return;
}
DispatchStatusChangedEvent(eventName, deviceAddressStr, status);
DispatchStatusChangedEvent(eventName, mDeviceAddress, status);
// Notify profile controller
if (aType.EqualsLiteral(BLUETOOTH_HFP_STATUS_CHANGED_ID)) {
@ -636,7 +633,7 @@ BluetoothHfpManager::NotifyConnectionStateChanged(const nsAString& aType)
OnConnect(EmptyString());
} else if (mConnectionState == HFP_CONNECTION_STATE_DISCONNECTED) {
mDeviceAddress.Clear();
mDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
if (mPrevConnectionState == HFP_CONNECTION_STATE_DISCONNECTED) {
// Bug 979160: This implies the outgoing connection failure.
// When the outgoing hfp connection fails, state changes to disconnected
@ -702,9 +699,15 @@ BluetoothHfpManager::HandleVolumeChanged(nsISupports* aSubject)
// Only send volume back when there's a connected headset
if (IsConnected()) {
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(mDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
return;
}
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
sBluetoothHfpInterface->VolumeControl(
HFP_VOLUME_TYPE_SPEAKER, mCurrentVgs, mDeviceAddress,
HFP_VOLUME_TYPE_SPEAKER, mCurrentVgs, deviceAddress,
new VolumeControlResultHandler());
}
}
@ -839,10 +842,16 @@ BluetoothHfpManager::SendCLCC(Call& aCall, int aIndex)
callState = HFP_CALL_STATE_WAITING;
}
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(mDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
return;
}
sBluetoothHfpInterface->ClccResponse(
aIndex, aCall.mDirection, callState, HFP_CALL_MODE_VOICE,
HFP_CALL_MPTY_TYPE_SINGLE, aCall.mNumber,
aCall.mType, mDeviceAddress, new ClccResponseResultHandler());
aCall.mType, deviceAddress, new ClccResponseResultHandler());
}
class BluetoothHfpManager::FormattedAtResponseResultHandler final
@ -861,8 +870,14 @@ BluetoothHfpManager::SendLine(const char* aMessage)
{
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(mDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
return;
}
sBluetoothHfpInterface->FormattedAtResponse(
aMessage, mDeviceAddress, new FormattedAtResponseResultHandler());
aMessage, deviceAddress, new FormattedAtResponseResultHandler());
}
class BluetoothHfpManager::AtResponseResultHandler final
@ -881,8 +896,14 @@ BluetoothHfpManager::SendResponse(BluetoothHandsfreeAtResponse aResponseCode)
{
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(mDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
return;
}
sBluetoothHfpInterface->AtResponse(
aResponseCode, 0, mDeviceAddress, new AtResponseResultHandler());
aResponseCode, 0, deviceAddress, new AtResponseResultHandler());
}
class BluetoothHfpManager::PhoneStateChangeResultHandler final
@ -1183,13 +1204,19 @@ BluetoothHfpManager::HandleBackendError()
{
MOZ_ASSERT(NS_IsMainThread());
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(mDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
return;
}
if (mConnectionState != HFP_CONNECTION_STATE_DISCONNECTED) {
ConnectionStateNotification(HFP_CONNECTION_STATE_DISCONNECTED,
mDeviceAddress);
deviceAddress);
}
if (mAudioState != HFP_AUDIO_STATE_DISCONNECTED) {
AudioStateNotification(HFP_AUDIO_STATE_DISCONNECTED, mDeviceAddress);
AudioStateNotification(HFP_AUDIO_STATE_DISCONNECTED, deviceAddress);
}
}
@ -1213,7 +1240,13 @@ BluetoothHfpManager::ConnectSco()
NS_ENSURE_TRUE(IsConnected() && !IsScoConnected(), false);
NS_ENSURE_TRUE(sBluetoothHfpInterface, false);
sBluetoothHfpInterface->ConnectAudio(mDeviceAddress,
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(mDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
return false;
}
sBluetoothHfpInterface->ConnectAudio(deviceAddress,
new ConnectAudioResultHandler());
return true;
@ -1236,7 +1269,13 @@ BluetoothHfpManager::DisconnectSco()
NS_ENSURE_TRUE(IsScoConnected(), false);
NS_ENSURE_TRUE(sBluetoothHfpInterface, false);
sBluetoothHfpInterface->DisconnectAudio(mDeviceAddress,
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(mDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
return false;
}
sBluetoothHfpInterface->DisconnectAudio(deviceAddress,
new DisconnectAudioResultHandler());
return true;
@ -1268,7 +1307,7 @@ BluetoothHfpManager::OnConnectError()
mController->NotifyCompletion(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
mController = nullptr;
mDeviceAddress.Clear();
mDeviceAddress.Truncate();
}
class BluetoothHfpManager::ConnectResultHandler final
@ -1293,7 +1332,7 @@ private:
};
void
BluetoothHfpManager::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController)
{
MOZ_ASSERT(NS_IsMainThread());
@ -1313,7 +1352,13 @@ BluetoothHfpManager::Connect(const BluetoothAddress& aDeviceAddress,
mDeviceAddress = aDeviceAddress;
mController = aController;
sBluetoothHfpInterface->Connect(mDeviceAddress,
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(mDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
return;
}
sBluetoothHfpInterface->Connect(deviceAddress,
new ConnectResultHandler(this));
}
@ -1364,7 +1409,13 @@ BluetoothHfpManager::Disconnect(BluetoothProfileController* aController)
mController = aController;
sBluetoothHfpInterface->Disconnect(mDeviceAddress,
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(mDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
return;
}
sBluetoothHfpInterface->Disconnect(deviceAddress,
new DisconnectResultHandler(this));
}
@ -1399,25 +1450,23 @@ BluetoothHfpManager::OnDisconnect(const nsAString& aErrorStr)
}
void
BluetoothHfpManager::OnUpdateSdpRecords(
const BluetoothAddress& aDeviceAddress)
BluetoothHfpManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
{
// Bluedroid handles this part
MOZ_ASSERT(false);
}
void
BluetoothHfpManager::OnGetServiceChannel(
const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
int aChannel)
BluetoothHfpManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel)
{
// Bluedroid handles this part
MOZ_ASSERT(false);
}
void
BluetoothHfpManager::GetAddress(BluetoothAddress& aDeviceAddress)
BluetoothHfpManager::GetAddress(nsAString& aDeviceAddress)
{
aDeviceAddress = mDeviceAddress;
}
@ -1438,7 +1487,7 @@ BluetoothHfpManager::ConnectionStateNotification(
mConnectionState = aState;
if (aState == HFP_CONNECTION_STATE_SLC_CONNECTED) {
mDeviceAddress = aBdAddress;
AddressToString(aBdAddress, mDeviceAddress);
NotifyConnectionStateChanged(
NS_LITERAL_STRING(BLUETOOTH_HFP_STATUS_CHANGED_ID));
@ -1448,8 +1497,14 @@ BluetoothHfpManager::ConnectionStateNotification(
NS_LITERAL_STRING(BLUETOOTH_HFP_STATUS_CHANGED_ID));
} else if (aState == HFP_CONNECTION_STATE_CONNECTED) {
BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(mDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
return;
}
// Once RFCOMM is connected, enable NREC before each new SLC connection
NRECNotification(HFP_NREC_STARTED, mDeviceAddress);
NRECNotification(HFP_NREC_STARTED, deviceAddress);
}
}
@ -1544,13 +1599,10 @@ BluetoothHfpManager::NRECNotification(BluetoothHandsfreeNRECState aNrec,
mNrecEnabled = static_cast<bool>(aNrec);
nsAutoString deviceAddressStr;
AddressToString(mDeviceAddress, deviceAddressStr);
// Notify audio manager
if (NS_FAILED(obs->NotifyObservers(this,
BLUETOOTH_HFP_NREC_STATUS_CHANGED_ID,
deviceAddressStr.get()))) {
mDeviceAddress.get()))) {
BT_WARNING("Failed to notify bluetooth-hfp-nrec-status-changed observsers!");
}

View File

@ -222,7 +222,7 @@ private:
bool mDialingRequestProcessed;
bool mNrecEnabled;
PhoneType mPhoneType;
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
nsString mMsisdn;
nsString mOperatorName;

View File

@ -132,11 +132,11 @@ BluetoothA2dpManager::HandleShutdown()
}
void
BluetoothA2dpManager::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothA2dpManager::Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!aDeviceAddress.IsCleared());
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
MOZ_ASSERT(aController && !mController);
BluetoothService* bs = BluetoothService::Get();
@ -153,10 +153,7 @@ BluetoothA2dpManager::Connect(const BluetoothAddress& aDeviceAddress,
mDeviceAddress = aDeviceAddress;
mController = aController;
nsAutoString deviceAddressStr;
AddressToString(aDeviceAddress, deviceAddressStr);
if (NS_FAILED(bs->SendSinkMessage(deviceAddressStr,
if (NS_FAILED(bs->SendSinkMessage(aDeviceAddress,
NS_LITERAL_STRING("Connect")))) {
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
return;
@ -183,15 +180,12 @@ BluetoothA2dpManager::Disconnect(BluetoothProfileController* aController)
return;
}
MOZ_ASSERT(!mDeviceAddress.IsCleared());
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
MOZ_ASSERT(!mController);
mController = aController;
nsAutoString deviceAddressStr;
AddressToString(mDeviceAddress, deviceAddressStr);
if (NS_FAILED(bs->SendSinkMessage(deviceAddressStr,
if (NS_FAILED(bs->SendSinkMessage(mDeviceAddress,
NS_LITERAL_STRING("Disconnect")))) {
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
return;
@ -255,17 +249,14 @@ BluetoothA2dpManager::HandleSinkPropertyChanged(const BluetoothSignal& aSignal)
MOZ_ASSERT(aSignal.value().type() ==
BluetoothValue::TArrayOfBluetoothNamedValue);
const nsString& addressStr = aSignal.path();
BluetoothAddress address;
StringToAddress(addressStr, address);
const nsString& address = aSignal.path();
/**
* Update sink property only if
* - mDeviceAddress is empty (A2dp is disconnected), or
* - this property change is from the connected sink.
*/
NS_ENSURE_TRUE_VOID(mDeviceAddress.IsCleared() || mDeviceAddress == address);
NS_ENSURE_TRUE_VOID(mDeviceAddress.IsEmpty() ||
mDeviceAddress.Equals(address));
const InfallibleTArray<BluetoothNamedValue>& arr =
aSignal.value().get_ArrayOfBluetoothNamedValue();
@ -338,7 +329,7 @@ BluetoothA2dpManager::HandleSinkPropertyChanged(const BluetoothSignal& aSignal)
mA2dpConnected = false;
NotifyConnectionStatusChanged();
mDeviceAddress.Clear();
mDeviceAddress.Truncate();
OnDisconnect(EmptyString());
break;
default:
@ -355,34 +346,31 @@ BluetoothA2dpManager::NotifyConnectionStatusChanged()
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
NS_ENSURE_TRUE_VOID(obs);
nsAutoString deviceAddressStr;
AddressToString(mDeviceAddress, deviceAddressStr);
if (NS_FAILED(obs->NotifyObservers(this,
BLUETOOTH_A2DP_STATUS_CHANGED_ID,
deviceAddressStr.get()))) {
mDeviceAddress.get()))) {
BT_WARNING("Failed to notify bluetooth-a2dp-status-changed observsers!");
}
// Dispatch an event of status change
DispatchStatusChangedEvent(
NS_LITERAL_STRING(A2DP_STATUS_CHANGED_ID), deviceAddressStr, mA2dpConnected);
NS_LITERAL_STRING(A2DP_STATUS_CHANGED_ID), mDeviceAddress, mA2dpConnected);
}
void
BluetoothA2dpManager::OnGetServiceChannel(const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
BluetoothA2dpManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel)
{
}
void
BluetoothA2dpManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
BluetoothA2dpManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
{
}
void
BluetoothA2dpManager::GetAddress(BluetoothAddress& aDeviceAddress)
BluetoothA2dpManager::GetAddress(nsAString& aDeviceAddress)
{
aDeviceAddress = mDeviceAddress;
}

View File

@ -46,7 +46,7 @@ private:
void HandleShutdown();
void NotifyConnectionStatusChanged();
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
RefPtr<BluetoothProfileController> mController;
// A2DP data member

View File

@ -116,11 +116,11 @@ BluetoothAvrcpManager::HandleShutdown()
}
void
BluetoothAvrcpManager::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothAvrcpManager::Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!aDeviceAddress.IsCleared());
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
MOZ_ASSERT(aController && !mController);
mDeviceAddress = aDeviceAddress;
@ -130,7 +130,7 @@ BluetoothAvrcpManager::Connect(const BluetoothAddress& aDeviceAddress,
void
BluetoothAvrcpManager::Disconnect(BluetoothProfileController* aController)
{
mDeviceAddress.Clear();
mDeviceAddress.Truncate();
OnDisconnect(EmptyString());
}
@ -167,18 +167,17 @@ BluetoothAvrcpManager::OnDisconnect(const nsAString& aErrorStr)
}
void
BluetoothAvrcpManager::OnGetServiceChannel(
const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
int aChannel)
BluetoothAvrcpManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel)
{ }
void
BluetoothAvrcpManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
BluetoothAvrcpManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
{ }
void
BluetoothAvrcpManager::GetAddress(BluetoothAddress& aDeviceAddress)
BluetoothAvrcpManager::GetAddress(nsAString& aDeviceAddress)
{
aDeviceAddress = mDeviceAddress;
}

View File

@ -52,7 +52,7 @@ private:
void HandleShutdown();
void NotifyConnectionStatusChanged();
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
RefPtr<BluetoothProfileController> mController;
// AVRCP data member

View File

@ -20,7 +20,6 @@
#include "BluetoothDBusService.h"
#include "BluetoothA2dpManager.h"
#include "BluetoothAvrcpManager.h"
#include "BluetoothHashKeys.h"
#include "BluetoothHfpManager.h"
#include "BluetoothHidManager.h"
#include "BluetoothOppManager.h"
@ -358,7 +357,7 @@ static StaticAutoPtr<RawDBusConnection> sDBusConnection;
// Keep the pairing requests.
static unsigned int sIsPairing = 0;
static nsDataHashtable<BluetoothAddressHashKey, DBusMessage* >* sPairingReqTable;
static nsDataHashtable<nsStringHashKey, DBusMessage* >* sPairingReqTable;
// The object path of the adapter that should
// be updated after switching Bluetooth.
@ -450,16 +449,6 @@ GetObjectPathFromAddress(const nsAString& aAdapterPath,
return devicePath;
}
static nsString
GetObjectPathFromAddress(const nsAString& aAdapterPath,
const BluetoothAddress& aDeviceAddress)
{
nsAutoString deviceAddressStr;
AddressToString(aDeviceAddress, deviceAddressStr);
return GetObjectPathFromAddress(aAdapterPath, deviceAddressStr);
}
static nsString
GetAddressFromObjectPath(const nsAString& aObjectPath)
{
@ -477,15 +466,6 @@ GetAddressFromObjectPath(const nsAString& aObjectPath)
return address;
}
static void
GetAddressFromObjectPath(const nsAString& aObjectPath,
BluetoothAddress& aAddress)
{
DebugOnly<nsresult> rv =
StringToAddress(GetAddressFromObjectPath(aObjectPath), aAddress);
MOZ_ASSERT(NS_SUCCEEDED(rv));
}
static bool
GetConnectedDevicesFilter(const BluetoothValue& aValue)
{
@ -1260,14 +1240,14 @@ AppendDeviceName(BluetoothSignal& aSignal)
class SetPairingConfirmationTask : public Task
{
public:
SetPairingConfirmationTask(const BluetoothAddress& aDeviceAddress,
SetPairingConfirmationTask(const nsAString& aDeviceAddress,
bool aConfirm,
BluetoothReplyRunnable* aRunnable)
: mDeviceAddress(aDeviceAddress)
, mConfirm(aConfirm)
, mRunnable(aRunnable)
{
MOZ_ASSERT(!mDeviceAddress.IsCleared());
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
}
void Run() override
@ -1320,7 +1300,7 @@ public:
}
private:
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
bool mConfirm;
RefPtr<BluetoothReplyRunnable> mRunnable;
};
@ -1506,9 +1486,8 @@ AgentEventFilter(DBusConnection *conn, DBusMessage *msg, void *data)
goto handle_error;
}
BluetoothAddress address;
GetAddressFromObjectPath(NS_ConvertUTF8toUTF16(objectPath), address);
nsString address =
GetAddressFromObjectPath(NS_ConvertUTF8toUTF16(objectPath));
sPairingReqTable->Put(address, msg);
Task* task = new SetPairingConfirmationTask(address, true, nullptr);
DispatchToDBusThread(task);
@ -1533,11 +1512,8 @@ AgentEventFilter(DBusConnection *conn, DBusMessage *msg, void *data)
signal.value() = v;
if (isPairingReq) {
BluetoothAddress address;
GetAddressFromObjectPath(NS_ConvertUTF8toUTF16(objectPath), address);
sPairingReqTable->Put(address, msg);
sPairingReqTable->Put(
GetAddressFromObjectPath(NS_ConvertUTF8toUTF16(objectPath)), msg);
// Increase ref count here because we need this message later.
// It'll be unrefed when set*Internal() is called.
@ -2108,7 +2084,7 @@ public:
mConnection->Watch();
if (!sPairingReqTable) {
sPairingReqTable = new nsDataHashtable<BluetoothAddressHashKey, DBusMessage* >;
sPairingReqTable = new nsDataHashtable<nsStringHashKey, DBusMessage* >;
}
sDBusConnection = mConnection.forget();
@ -2302,7 +2278,7 @@ public:
private:
static PLDHashOperator
UnrefDBusMessage(const BluetoothAddress& key, DBusMessage* value, void* arg)
UnrefDBusMessage(const nsAString& key, DBusMessage* value, void* arg)
{
dbus_message_unref(value);
return PL_DHASH_NEXT;
@ -2878,13 +2854,9 @@ BluetoothDBusService::GetConnectedDevicePropertiesInternal(
}
if (profile->IsConnected()) {
BluetoothAddress address;
nsString address;
profile->GetAddress(address);
nsAutoString addressStr;
AddressToString(address, addressStr);
deviceAddresses.AppendElement(addressStr);
deviceAddresses.AppendElement(address);
}
BluetoothArrayOfDevicePropertiesReplyHandler* handler =
@ -3167,12 +3139,12 @@ BluetoothDBusService::CreatePairedDeviceInternal(
class RemoveDeviceTask : public Task
{
public:
RemoveDeviceTask(const BluetoothAddress& aDeviceAddress,
RemoveDeviceTask(const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable)
: mDeviceAddress(aDeviceAddress)
, mRunnable(aRunnable)
{
MOZ_ASSERT(!mDeviceAddress.IsCleared());
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
MOZ_ASSERT(mRunnable);
}
@ -3216,7 +3188,7 @@ protected:
}
private:
const BluetoothAddress mDeviceAddress;
const nsString mDeviceAddress;
RefPtr<BluetoothReplyRunnable> mRunnable;
};
@ -3232,14 +3204,7 @@ BluetoothDBusService::RemoveDeviceInternal(const nsAString& aDeviceAddress,
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;
@ -3248,14 +3213,14 @@ BluetoothDBusService::RemoveDeviceInternal(const nsAString& aDeviceAddress,
class SetPinCodeTask : public Task
{
public:
SetPinCodeTask(const BluetoothAddress& aDeviceAddress,
SetPinCodeTask(const nsAString& aDeviceAddress,
const nsACString& aPinCode,
BluetoothReplyRunnable* aRunnable)
: mDeviceAddress(aDeviceAddress)
, mPinCode(aPinCode)
, mRunnable(aRunnable)
{
MOZ_ASSERT(!mDeviceAddress.IsCleared());
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
MOZ_ASSERT(mRunnable);
}
@ -3303,7 +3268,7 @@ public:
}
private:
const BluetoothAddress mDeviceAddress;
const nsString mDeviceAddress;
const nsCString mPinCode;
RefPtr<BluetoothReplyRunnable> mRunnable;
};
@ -3329,14 +3294,7 @@ BluetoothDBusService::SetPinCodeInternal(const nsAString& 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);
@ -3345,14 +3303,14 @@ BluetoothDBusService::SetPinCodeInternal(const nsAString& aDeviceAddress,
class SetPasskeyTask : public Task
{
public:
SetPasskeyTask(const BluetoothAddress& aDeviceAddress,
SetPasskeyTask(const nsAString& aDeviceAddress,
uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable)
: mDeviceAddress(aDeviceAddress)
, mPasskey(aPasskey)
, mRunnable(aRunnable)
{
MOZ_ASSERT(!mDeviceAddress.IsCleared());
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
MOZ_ASSERT(mRunnable);
}
@ -3400,7 +3358,7 @@ public:
}
private:
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
uint32_t mPasskey;
RefPtr<BluetoothReplyRunnable> mRunnable;
};
@ -3410,13 +3368,7 @@ BluetoothDBusService::SetPasskeyInternal(const nsAString& 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);
@ -3430,13 +3382,7 @@ BluetoothDBusService::SetPairingConfirmationInternal(
{
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);
@ -3464,15 +3410,8 @@ ConnectDisconnect(bool aConnect, const nsAString& aDeviceAddress,
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);
@ -3549,9 +3488,7 @@ public:
MOZ_ASSERT(!aObjectPath.IsEmpty());
MOZ_ASSERT(aManager);
const nsString deviceAddressStr = GetAddressFromObjectPath(aObjectPath);
StringToAddress(deviceAddressStr, mDeviceAddress);
mDeviceAddress = GetAddressFromObjectPath(aObjectPath);
}
nsresult
@ -3565,15 +3502,15 @@ public:
}
private:
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
BluetoothProfileManagerBase* mManager;
};
class OnGetServiceChannelRunnable : public nsRunnable
{
public:
OnGetServiceChannelRunnable(const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
OnGetServiceChannelRunnable(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel,
BluetoothProfileManagerBase* aManager)
: mDeviceAddress(aDeviceAddress)
@ -3581,8 +3518,8 @@ public:
, mChannel(aChannel)
, mManager(aManager)
{
MOZ_ASSERT(!aDeviceAddress.IsCleared());
MOZ_ASSERT(!aServiceUuid.IsCleared());
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
MOZ_ASSERT(!aServiceUuid.IsEmpty());
MOZ_ASSERT(aManager);
}
@ -3596,8 +3533,8 @@ public:
}
private:
BluetoothAddress mDeviceAddress;
BluetoothUuid mServiceUuid;
nsString mDeviceAddress;
nsString mServiceUuid;
int mChannel;
BluetoothProfileManagerBase* mManager;
};
@ -3606,12 +3543,11 @@ class OnGetServiceChannelReplyHandler : public DBusReplyHandler
{
public:
OnGetServiceChannelReplyHandler(
const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUUID,
const nsAString& aDeviceAddress, const nsAString& aServiceUUID,
BluetoothProfileManagerBase* aBluetoothProfileManager)
: mDeviceAddress(aDeviceAddress),
mServiceUUID(aServiceUUID),
mBluetoothProfileManager(aBluetoothProfileManager)
: mDeviceAddress(aDeviceAddress),
mServiceUUID(aServiceUUID),
mBluetoothProfileManager(aBluetoothProfileManager)
{
MOZ_ASSERT(mBluetoothProfileManager);
}
@ -3639,22 +3575,22 @@ public:
}
private:
BluetoothAddress mDeviceAddress;
BluetoothUuid mServiceUUID;
nsString mDeviceAddress;
nsString mServiceUUID;
BluetoothProfileManagerBase* mBluetoothProfileManager;
};
class GetServiceChannelTask : public Task
{
public:
GetServiceChannelTask(const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUUID,
GetServiceChannelTask(const nsAString& aDeviceAddress,
const nsAString& aServiceUUID,
BluetoothProfileManagerBase* aBluetoothProfileManager)
: mDeviceAddress(aDeviceAddress)
, mServiceUUID(aServiceUUID)
, mBluetoothProfileManager(aBluetoothProfileManager)
{
MOZ_ASSERT(!mDeviceAddress.IsCleared());
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
MOZ_ASSERT(mBluetoothProfileManager);
}
@ -3666,17 +3602,14 @@ public:
MOZ_ASSERT(sDBusConnection);
MOZ_ASSERT(!sAdapterPath.IsEmpty());
const nsString objectPath =
nsString objectPath =
GetObjectPathFromAddress(sAdapterPath, mDeviceAddress);
RefPtr<OnGetServiceChannelReplyHandler> handler =
new OnGetServiceChannelReplyHandler(mDeviceAddress, mServiceUUID,
mBluetoothProfileManager);
nsAutoString serviceUuidStr;
UuidToString(mServiceUUID, serviceUuidStr);
nsCString serviceUUID = NS_ConvertUTF16toUTF8(serviceUuidStr);
nsCString serviceUUID = NS_ConvertUTF16toUTF8(mServiceUUID);
const char* cstrServiceUUID = serviceUUID.get();
bool success = sDBusConnection->SendWithReply(
@ -3693,14 +3626,14 @@ public:
}
private:
BluetoothAddress mDeviceAddress;
BluetoothUuid mServiceUUID;
nsString mDeviceAddress;
nsString mServiceUUID;
BluetoothProfileManagerBase* mBluetoothProfileManager;
};
nsresult
BluetoothDBusService::GetServiceChannel(const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUUID,
BluetoothDBusService::GetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUUID,
BluetoothProfileManagerBase* aManager)
{
MOZ_ASSERT(NS_IsMainThread());
@ -3737,12 +3670,12 @@ BluetoothDBusService::GetServiceChannel(const BluetoothAddress& aDeviceAddress,
class UpdateSdpRecordsTask : public Task
{
public:
UpdateSdpRecordsTask(const BluetoothAddress& aDeviceAddress,
UpdateSdpRecordsTask(const nsAString& aDeviceAddress,
BluetoothProfileManagerBase* aBluetoothProfileManager)
: mDeviceAddress(aDeviceAddress)
, mBluetoothProfileManager(aBluetoothProfileManager)
{
MOZ_ASSERT(!mDeviceAddress.IsCleared());
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
MOZ_ASSERT(mBluetoothProfileManager);
}
@ -3781,12 +3714,12 @@ protected:
}
private:
const BluetoothAddress mDeviceAddress;
const nsString mDeviceAddress;
BluetoothProfileManagerBase* mBluetoothProfileManager;
};
bool
BluetoothDBusService::UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
BluetoothDBusService::UpdateSdpRecords(const nsAString& aDeviceAddress,
BluetoothProfileManagerBase* aManager)
{
MOZ_ASSERT(NS_IsMainThread());
@ -3805,19 +3738,13 @@ BluetoothDBusService::SendFile(const nsAString& aDeviceAddress,
{
MOZ_ASSERT(NS_IsMainThread());
BluetoothAddress deviceAddress;
if (NS_FAILED(StringToAddress(aDeviceAddress, deviceAddress))) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
// Currently we only support one device sending one file at a time,
// so we don't need aDeviceAddress here because the target device
// has been determined when calling 'Connect()'. Nevertheless, keep
// it for future use.
BluetoothOppManager* opp = BluetoothOppManager::Get();
nsAutoString errorStr;
if (!opp || !opp->SendFile(deviceAddress, aBlobParent)) {
if (!opp || !opp->SendFile(aDeviceAddress, aBlobParent)) {
errorStr.AssignLiteral("Calling SendFile() failed");
}
@ -3831,19 +3758,13 @@ BluetoothDBusService::SendFile(const nsAString& aDeviceAddress,
{
MOZ_ASSERT(NS_IsMainThread());
BluetoothAddress deviceAddress;
if (NS_FAILED(StringToAddress(aDeviceAddress, deviceAddress))) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
// Currently we only support one device sending one file at a time,
// so we don't need aDeviceAddress here because the target device
// has been determined when calling 'Connect()'. Nevertheless, keep
// it for future use.
BluetoothOppManager* opp = BluetoothOppManager::Get();
nsAutoString errorStr;
if (!opp || !opp->SendFile(deviceAddress, aBlob)) {
if (!opp || !opp->SendFile(aDeviceAddress, aBlob)) {
errorStr.AssignLiteral("Calling SendFile() failed");
}
@ -3934,7 +3855,7 @@ BluetoothDBusService::IsScoConnected(BluetoothReplyRunnable* aRunnable)
class SendMetadataTask : public Task
{
public:
SendMetadataTask(const BluetoothAddress& aDeviceAddress,
SendMetadataTask(const nsAString& aDeviceAddress,
const nsACString& aTitle,
const nsACString& aArtist,
const nsACString& aAlbum,
@ -3951,7 +3872,7 @@ public:
, mDuration(aDuration)
, mRunnable(aRunnable)
{
MOZ_ASSERT(!mDeviceAddress.IsCleared());
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
MOZ_ASSERT(mRunnable);
}
@ -4010,7 +3931,7 @@ public:
}
private:
const BluetoothAddress mDeviceAddress;
const nsString mDeviceAddress;
const nsCString mTitle;
const nsCString mArtist;
const nsCString mAlbum;
@ -4057,7 +3978,7 @@ BluetoothDBusService::SendMetaData(const nsAString& aTitle,
UpdateNotification(ControlEventId::EVENT_TRACK_CHANGED, aMediaNumber);
}
BluetoothAddress deviceAddress;
nsAutoString deviceAddress;
avrcp->GetAddress(deviceAddress);
Task* task = new SendMetadataTask(
@ -4099,7 +4020,7 @@ PlayStatusStringToControlPlayStatus(const nsAString& aPlayStatus)
class SendPlayStatusTask : public Task
{
public:
SendPlayStatusTask(const BluetoothAddress& aDeviceAddress,
SendPlayStatusTask(const nsAString& aDeviceAddress,
int64_t aDuration,
int64_t aPosition,
ControlPlayStatus aPlayStatus,
@ -4110,7 +4031,7 @@ public:
, mPlayStatus(aPlayStatus)
, mRunnable(aRunnable)
{
MOZ_ASSERT(!mDeviceAddress.IsCleared());
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
MOZ_ASSERT(mRunnable);
}
@ -4140,7 +4061,7 @@ public:
}
private:
const BluetoothAddress mDeviceAddress;
const nsString mDeviceAddress;
int64_t mDuration;
int64_t mPosition;
ControlPlayStatus mPlayStatus;
@ -4193,7 +4114,7 @@ BluetoothDBusService::SendPlayStatus(int64_t aDuration,
UpdateNotification(ControlEventId::EVENT_PLAYBACK_POS_CHANGED, aPosition);
}
BluetoothAddress deviceAddress;
nsAutoString deviceAddress;
avrcp->GetAddress(deviceAddress);
Task* task = new SendPlayStatusTask(deviceAddress,
@ -4222,7 +4143,7 @@ ControlCallback(DBusMessage* aMsg, void* aParam)
class UpdatePlayStatusTask : public Task
{
public:
UpdatePlayStatusTask(const BluetoothAddress& aDeviceAddress,
UpdatePlayStatusTask(const nsAString& aDeviceAddress,
int32_t aDuration,
int32_t aPosition,
ControlPlayStatus aPlayStatus)
@ -4231,7 +4152,7 @@ public:
, mPosition(aPosition)
, mPlayStatus(aPlayStatus)
{
MOZ_ASSERT(!mDeviceAddress.IsCleared());
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
}
void Run() override
@ -4258,7 +4179,7 @@ public:
}
private:
const BluetoothAddress mDeviceAddress;
const nsString mDeviceAddress;
int32_t mDuration;
int32_t mPosition;
ControlPlayStatus mPlayStatus;
@ -4277,7 +4198,7 @@ BluetoothDBusService::UpdatePlayStatus(uint32_t aDuration,
MOZ_ASSERT(avrcp->IsConnected());
MOZ_ASSERT(!sAdapterPath.IsEmpty());
BluetoothAddress deviceAddress;
nsAutoString deviceAddress;
avrcp->GetAddress(deviceAddress);
Task* task = new UpdatePlayStatusTask(deviceAddress,
@ -4290,14 +4211,14 @@ BluetoothDBusService::UpdatePlayStatus(uint32_t aDuration,
class UpdateNotificationTask : public Task
{
public:
UpdateNotificationTask(const BluetoothAddress& aDeviceAddress,
UpdateNotificationTask(const nsAString& aDeviceAddress,
BluetoothDBusService::ControlEventId aEventId,
uint64_t aData)
: mDeviceAddress(aDeviceAddress)
, mEventId(aEventId)
, mData(aData)
{
MOZ_ASSERT(!mDeviceAddress.IsCleared());
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
}
void Run() override
@ -4323,7 +4244,7 @@ public:
}
private:
const BluetoothAddress mDeviceAddress;
const nsString mDeviceAddress;
int16_t mEventId;
int32_t mData;
};
@ -4340,7 +4261,7 @@ BluetoothDBusService::UpdateNotification(ControlEventId aEventId,
MOZ_ASSERT(avrcp->IsConnected());
MOZ_ASSERT(!sAdapterPath.IsEmpty());
BluetoothAddress deviceAddress;
nsAutoString deviceAddress;
avrcp->GetAddress(deviceAddress);
Task* task = new UpdateNotificationTask(deviceAddress, aEventId, aData);

View File

@ -78,12 +78,12 @@ public:
BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
GetServiceChannel(const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
GetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
BluetoothProfileManagerBase* aManager) override;
virtual bool
UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
UpdateSdpRecords(const nsAString& aDeviceAddress,
BluetoothProfileManagerBase* aManager) override;
virtual nsresult

View File

@ -525,11 +525,8 @@ BluetoothHfpManager::NotifyConnectionStatusChanged(const nsAString& aType)
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
NS_ENSURE_TRUE_VOID(obs);
nsAutoString deviceAddressStr;
AddressToString(mDeviceAddress, deviceAddressStr);
if (NS_FAILED(obs->NotifyObservers(this, NS_ConvertUTF16toUTF8(aType).get(),
deviceAddressStr.get()))) {
mDeviceAddress.get()))) {
BT_WARNING("Failed to notify observsers!");
}
@ -547,7 +544,7 @@ BluetoothHfpManager::NotifyConnectionStatusChanged(const nsAString& aType)
return;
}
DispatchStatusChangedEvent(eventName, deviceAddressStr, status);
DispatchStatusChangedEvent(eventName, mDeviceAddress, status);
}
#ifdef MOZ_B2G_RIL
@ -1110,7 +1107,7 @@ respond_with_ok:
}
void
BluetoothHfpManager::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController)
{
MOZ_ASSERT(NS_IsMainThread());
@ -1131,7 +1128,8 @@ BluetoothHfpManager::Connect(const BluetoothAddress& aDeviceAddress,
return;
}
const BluetoothUuid uuid(HANDSFREE);
nsString uuid;
BluetoothUuidHelper::GetString(BluetoothServiceClass::HANDSFREE, uuid);
if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress, uuid, this))) {
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
@ -1868,7 +1866,7 @@ BluetoothHfpManager::OnSocketDisconnect(BluetoothSocket* aSocket)
}
void
BluetoothHfpManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
BluetoothHfpManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
{
// UpdateSdpRecord() is not called so this callback function should not
// be invoked.
@ -1876,13 +1874,12 @@ BluetoothHfpManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
}
void
BluetoothHfpManager::OnGetServiceChannel(
const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
int aChannel)
BluetoothHfpManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!aDeviceAddress.IsCleared());
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
@ -1890,12 +1887,13 @@ BluetoothHfpManager::OnGetServiceChannel(
if (aChannel < 0) {
// If we can't find Handsfree server channel number on the remote device,
// try to create HSP connection instead.
const BluetoothUuid uuid(HEADSET);
nsString hspUuid;
BluetoothUuidHelper::GetString(BluetoothServiceClass::HEADSET, hspUuid);
if (aServiceUuid == uuid) {
if (aServiceUuid.Equals(hspUuid)) {
OnConnect(NS_LITERAL_STRING(ERR_SERVICE_CHANNEL_NOT_FOUND));
} else if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress,
uuid, this))) {
hspUuid, this))) {
OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
} else {
mIsHsp = true;
@ -1965,7 +1963,7 @@ BluetoothHfpManager::IsConnected()
}
void
BluetoothHfpManager::GetAddress(BluetoothAddress& aDeviceAddress)
BluetoothHfpManager::GetAddress(nsAString& aDeviceAddress)
{
return mSocket->GetAddress(aDeviceAddress);
}

View File

@ -197,7 +197,7 @@ private:
#ifdef MOZ_B2G_RIL
bool mDialingRequestProcessed;
#endif
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
#ifdef MOZ_B2G_RIL
nsString mMsisdn;
nsString mOperatorName;

View File

@ -71,13 +71,13 @@ namespace {
class mozilla::dom::bluetooth::SendFileBatch
{
public:
SendFileBatch(const BluetoothAddress& aDeviceAddress, Blob* aBlob)
SendFileBatch(const nsAString& aDeviceAddress, Blob* aBlob)
: mDeviceAddress(aDeviceAddress)
{
mBlobs.AppendElement(aBlob);
}
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
nsTArray<RefPtr<Blob>> mBlobs;
};
@ -209,7 +209,9 @@ BluetoothOppManager::BluetoothOppManager()
, mWaitingToSendPutFinal(false)
, mCurrentBlobIndex(-1)
, mSocketType(static_cast<BluetoothSocketType>(0))
{ }
{
mConnectedDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
}
BluetoothOppManager::~BluetoothOppManager()
{
@ -258,7 +260,7 @@ BluetoothOppManager::Get()
}
void
BluetoothOppManager::ConnectInternal(const BluetoothAddress& aDeviceAddress)
BluetoothOppManager::ConnectInternal(const nsAString& aDeviceAddress)
{
MOZ_ASSERT(NS_IsMainThread());
@ -283,8 +285,10 @@ BluetoothOppManager::ConnectInternal(const BluetoothAddress& aDeviceAddress)
mNeedsUpdatingSdpRecords = true;
auto rv = bs->GetServiceChannel(aDeviceAddress, kObexObjectPush, this);
if (NS_FAILED(rv)) {
nsString uuid;
BluetoothUuidHelper::GetString(BluetoothServiceClass::OBJECT_PUSH, uuid);
if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress, uuid, this))) {
OnSocketConnectError(mSocket);
return;
}
@ -380,7 +384,7 @@ BluetoothOppManager::StartSendingNextFile()
}
bool
BluetoothOppManager::SendFile(const BluetoothAddress& aDeviceAddress,
BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
BlobParent* aActor)
{
MOZ_ASSERT(NS_IsMainThread());
@ -392,7 +396,7 @@ BluetoothOppManager::SendFile(const BluetoothAddress& aDeviceAddress,
}
bool
BluetoothOppManager::SendFile(const BluetoothAddress& aDeviceAddress,
BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
Blob* aBlob)
{
MOZ_ASSERT(NS_IsMainThread());
@ -406,7 +410,7 @@ BluetoothOppManager::SendFile(const BluetoothAddress& aDeviceAddress,
}
void
BluetoothOppManager::AppendBlobToSend(const BluetoothAddress& aDeviceAddress,
BluetoothOppManager::AppendBlobToSend(const nsAString& aDeviceAddress,
Blob* aBlob)
{
MOZ_ASSERT(NS_IsMainThread());
@ -1280,7 +1284,7 @@ BluetoothOppManager::IsConnected()
}
void
BluetoothOppManager::GetAddress(BluetoothAddress& aDeviceAddress)
BluetoothOppManager::GetAddress(nsAString& aDeviceAddress)
{
return mSocket->GetAddress(aDeviceAddress);
}
@ -1375,16 +1379,13 @@ BluetoothOppManager::FileTransferComplete()
return;
}
nsAutoString connectedDeviceAddressStr;
AddressToString(mConnectedDeviceAddress, connectedDeviceAddressStr);
nsString type, name;
BluetoothValue v;
InfallibleTArray<BluetoothNamedValue> parameters;
type.AssignLiteral("bluetooth-opp-transfer-complete");
name.AssignLiteral("address");
v = connectedDeviceAddressStr;
v = mConnectedDeviceAddress;
parameters.AppendElement(BluetoothNamedValue(name, v));
name.AssignLiteral("success");
@ -1418,16 +1419,13 @@ BluetoothOppManager::FileTransferComplete()
void
BluetoothOppManager::StartFileTransfer()
{
nsAutoString connectedDeviceAddressStr;
AddressToString(mConnectedDeviceAddress, connectedDeviceAddressStr);
nsString type, name;
BluetoothValue v;
InfallibleTArray<BluetoothNamedValue> parameters;
type.AssignLiteral("bluetooth-opp-transfer-start");
name.AssignLiteral("address");
v = connectedDeviceAddressStr;
v = mConnectedDeviceAddress;
parameters.AppendElement(BluetoothNamedValue(name, v));
name.AssignLiteral("received");
@ -1457,16 +1455,13 @@ BluetoothOppManager::StartFileTransfer()
void
BluetoothOppManager::UpdateProgress()
{
nsAutoString connectedDeviceAddressStr;
AddressToString(mConnectedDeviceAddress, connectedDeviceAddressStr);
nsString type, name;
BluetoothValue v;
InfallibleTArray<BluetoothNamedValue> parameters;
type.AssignLiteral("bluetooth-opp-update-progress");
name.AssignLiteral("address");
v = connectedDeviceAddressStr;
v = mConnectedDeviceAddress;
parameters.AppendElement(BluetoothNamedValue(name, v));
name.AssignLiteral("received");
@ -1490,16 +1485,13 @@ BluetoothOppManager::UpdateProgress()
void
BluetoothOppManager::ReceivingFileConfirmation()
{
nsAutoString connectedDeviceAddressStr;
AddressToString(mConnectedDeviceAddress, connectedDeviceAddressStr);
nsString type, name;
BluetoothValue v;
InfallibleTArray<BluetoothNamedValue> parameters;
type.AssignLiteral("bluetooth-opp-receiving-file-confirmation");
name.AssignLiteral("address");
v = connectedDeviceAddressStr;
v = mConnectedDeviceAddress;
parameters.AppendElement(BluetoothNamedValue(name, v));
name.AssignLiteral("fileName");
@ -1622,7 +1614,7 @@ BluetoothOppManager::OnSocketDisconnect(BluetoothSocket* aSocket)
}
AfterOppDisconnected();
mConnectedDeviceAddress.Clear();
mConnectedDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
mSuccessFlag = false;
mSocket = nullptr;
@ -1645,13 +1637,12 @@ BluetoothOppManager::Disconnect(BluetoothProfileController* aController)
}
void
BluetoothOppManager::OnGetServiceChannel(
const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
int aChannel)
BluetoothOppManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!aDeviceAddress.IsCleared());
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
@ -1683,16 +1674,18 @@ BluetoothOppManager::OnGetServiceChannel(
}
void
BluetoothOppManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
BluetoothOppManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!aDeviceAddress.IsCleared());
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
auto rv = bs->GetServiceChannel(aDeviceAddress, kObexObjectPush, this);
if (NS_FAILED(rv)) {
nsString uuid;
BluetoothUuidHelper::GetString(BluetoothServiceClass::OBJECT_PUSH, uuid);
if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress, uuid, this))) {
OnSocketConnectError(mSocket);
}
}
@ -1713,7 +1706,7 @@ BluetoothOppManager::AcquireSdcardMountLock()
}
void
BluetoothOppManager::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothOppManager::Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController)
{
MOZ_ASSERT(false);

View File

@ -50,8 +50,8 @@ public:
bool Listen();
bool SendFile(const BluetoothAddress& aDeviceAddress, BlobParent* aActor);
bool SendFile(const BluetoothAddress& aDeviceAddress, Blob* aBlob);
bool SendFile(const nsAString& aDeviceAddress, BlobParent* aActor);
bool SendFile(const nsAString& aDeviceAddress, Blob* aBlob);
bool StopSendingFile();
bool ConfirmReceivingFile(bool aConfirm);
@ -96,10 +96,10 @@ private:
void NotifyAboutFileChange();
bool AcquireSdcardMountLock();
void SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
void AppendBlobToSend(const BluetoothAddress& aDeviceAddress, Blob* aBlob);
void AppendBlobToSend(const nsAString& aDeviceAddress, Blob* aBlob);
void DiscardBlobsToSend();
bool ProcessNextBatch();
void ConnectInternal(const BluetoothAddress& aDeviceAddress);
void ConnectInternal(const nsAString& aDeviceAddress);
/**
* Usually we won't get a full PUT packet in one operation, which means that
@ -118,7 +118,7 @@ private:
* Set when OBEX session is established.
*/
bool mConnected;
BluetoothAddress mConnectedDeviceAddress;
nsString mConnectedDeviceAddress;
/**
* Remote information

View File

@ -8,7 +8,6 @@
#include <fcntl.h>
#include "BluetoothSocketObserver.h"
#include "BluetoothUnixSocketConnector.h"
#include "BluetoothUtils.h"
#include "mozilla/RefPtr.h"
#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
#include "nsXULAppAPI.h"
@ -31,10 +30,10 @@ public:
BluetoothSocketIO(MessageLoop* aConsumerLoop,
MessageLoop* aIOLoop,
BluetoothSocket* aConsumer,
BluetoothUnixSocketConnector* aConnector);
UnixSocketConnector* aConnector);
~BluetoothSocketIO();
void GetSocketAddr(BluetoothAddress& aAddress) const;
void GetSocketAddr(nsAString& aAddrStr) const;
BluetoothSocket* GetBluetoothSocket();
DataSocket* GetDataSocket();
@ -104,7 +103,7 @@ private:
/**
* Connector object used to create the connection we are currently using.
*/
nsAutoPtr<BluetoothUnixSocketConnector> mConnector;
nsAutoPtr<UnixSocketConnector> mConnector;
/**
* If true, do not requeue whatever task we're running
@ -137,7 +136,7 @@ BluetoothSocket::BluetoothSocketIO::BluetoothSocketIO(
MessageLoop* aConsumerLoop,
MessageLoop* aIOLoop,
BluetoothSocket* aConsumer,
BluetoothUnixSocketConnector* aConnector)
UnixSocketConnector* aConnector)
: UnixSocketWatcher(aIOLoop)
, DataSocketIO(aConsumerLoop)
, mConsumer(aConsumer)
@ -161,22 +160,24 @@ BluetoothSocket::BluetoothSocketIO::~BluetoothSocketIO()
}
void
BluetoothSocket::BluetoothSocketIO::GetSocketAddr(
BluetoothAddress& aAddress) const
BluetoothSocket::BluetoothSocketIO::GetSocketAddr(nsAString& aAddrStr) const
{
if (!mConnector) {
NS_WARNING("No connector to get socket address from!");
aAddress.Clear();
aAddrStr.Truncate();
return;
}
nsresult rv = mConnector->ConvertAddress(
*reinterpret_cast<const struct sockaddr*>(&mAddress), sizeof(mAddress),
aAddress);
nsCString addressString;
nsresult rv = mConnector->ConvertAddressToString(
*reinterpret_cast<const struct sockaddr*>(&mAddress), mAddressLength,
addressString);
if (NS_FAILED(rv)) {
aAddress.Clear();
aAddrStr.Truncate();
return;
}
aAddrStr.Assign(NS_ConvertUTF8toUTF16(addressString));
}
BluetoothSocket*
@ -578,28 +579,24 @@ BluetoothSocket::~BluetoothSocket()
}
nsresult
BluetoothSocket::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothSocket::Connect(const nsAString& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
BluetoothSocketType aType,
int aChannel,
bool aAuth, bool aEncrypt)
{
MOZ_ASSERT(!aDeviceAddress.IsCleared());
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
nsAutoPtr<BluetoothUnixSocketConnector> connector(
new BluetoothUnixSocketConnector(aDeviceAddress, aType, aChannel,
aAuth, aEncrypt));
new BluetoothUnixSocketConnector(NS_ConvertUTF16toUTF8(aDeviceAddress),
aType, aChannel, aAuth, aEncrypt));
nsresult rv = Connect(connector);
if (NS_FAILED(rv)) {
BluetoothAddress address;
GetAddress(address);
nsAutoString addressStr;
AddressToString(address, addressStr);
nsAutoString addr;
GetAddress(addr);
BT_LOGD("%s failed. Current connected device address: %s",
__FUNCTION__, NS_ConvertUTF16toUTF8(addressStr).get());
__FUNCTION__, NS_ConvertUTF16toUTF8(addr).get());
return rv;
}
connector.forget();
@ -615,19 +612,15 @@ BluetoothSocket::Listen(const nsAString& aServiceName,
bool aAuth, bool aEncrypt)
{
nsAutoPtr<BluetoothUnixSocketConnector> connector(
new BluetoothUnixSocketConnector(BluetoothAddress::ANY, aType,
aChannel, aAuth, aEncrypt));
new BluetoothUnixSocketConnector(NS_LITERAL_CSTRING(BLUETOOTH_ADDRESS_NONE),
aType, aChannel, aAuth, aEncrypt));
nsresult rv = Listen(connector);
if (NS_FAILED(rv)) {
BluetoothAddress address;
GetAddress(address);
nsAutoString addressStr;
AddressToString(address, addressStr);
nsAutoString addr;
GetAddress(addr);
BT_LOGD("%s failed. Current connected device address: %s",
__FUNCTION__, NS_ConvertUTF16toUTF8(addressStr).get());
__FUNCTION__, NS_ConvertUTF16toUTF8(addr).get());
return rv;
}
connector.forget();
@ -711,15 +704,14 @@ BluetoothSocket::Listen(BluetoothUnixSocketConnector* aConnector)
}
void
BluetoothSocket::GetAddress(BluetoothAddress& aAddress)
BluetoothSocket::GetAddress(nsAString& aAddrStr)
{
aAddrStr.Truncate();
if (!mIO || GetConnectionStatus() != SOCKET_CONNECTED) {
NS_WARNING("No socket currently open!");
aAddress.Clear();
return;
}
mIO->GetSocketAddr(aAddress);
mIO->GetSocketAddr(aAddrStr);
}
// |DataSocket|

View File

@ -26,7 +26,7 @@ public:
BluetoothSocket(BluetoothSocketObserver* aObserver);
~BluetoothSocket();
nsresult Connect(const BluetoothAddress& aDeviceAddress,
nsresult Connect(const nsAString& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
BluetoothSocketType aType,
int aChannel,
@ -105,9 +105,9 @@ public:
/**
* Get the current socket address.
*
* @param[out] aDeviceAddress Returns the address.
* @param[out] aDeviceAddress Returns the address string.
*/
void GetAddress(BluetoothAddress& aDeviceAddress);
void GetAddress(nsAString& aDeviceAddress);
// Methods for |DataSocket|
//

View File

@ -43,12 +43,12 @@ static const int L2CAP_SO_RCVBUF = 400 * 1024; // 400 KB receive buffer
static const int L2CAP_MAX_MTU = 65000;
BluetoothUnixSocketConnector::BluetoothUnixSocketConnector(
const BluetoothAddress& aAddress,
const nsACString& aAddressString,
BluetoothSocketType aType,
int aChannel,
bool aAuth,
bool aEncrypt)
: mAddress(aAddress)
: mAddressString(aAddressString)
, mType(aType)
, mChannel(aChannel)
, mAuth(aAuth)
@ -238,7 +238,8 @@ BluetoothUnixSocketConnector::CreateAddress(struct sockaddr& aAddress,
struct sockaddr_rc* rc =
reinterpret_cast<struct sockaddr_rc*>(&aAddress);
rc->rc_family = AF_BLUETOOTH;
nsresult rv = ConvertAddress(mAddress, rc->rc_bdaddr);
nsresult rv = ConvertAddressString(mAddressString.get(),
rc->rc_bdaddr);
if (NS_FAILED(rv)) {
return rv;
}
@ -252,7 +253,8 @@ BluetoothUnixSocketConnector::CreateAddress(struct sockaddr& aAddress,
reinterpret_cast<struct sockaddr_l2*>(&aAddress);
l2->l2_family = AF_BLUETOOTH;
l2->l2_psm = mChannel;
nsresult rv = ConvertAddress(mAddress, l2->l2_bdaddr);
nsresult rv = ConvertAddressString(mAddressString.get(),
l2->l2_bdaddr);
if (NS_FAILED(rv)) {
return rv;
}
@ -264,7 +266,8 @@ BluetoothUnixSocketConnector::CreateAddress(struct sockaddr& aAddress,
struct sockaddr_sco* sco =
reinterpret_cast<struct sockaddr_sco*>(&aAddress);
sco->sco_family = AF_BLUETOOTH;
nsresult rv = ConvertAddress(mAddress, sco->sco_bdaddr);
nsresult rv = ConvertAddressString(mAddressString.get(),
sco->sco_bdaddr);
if (NS_FAILED(rv)) {
return rv;
}
@ -281,69 +284,20 @@ BluetoothUnixSocketConnector::CreateAddress(struct sockaddr& aAddress,
}
nsresult
BluetoothUnixSocketConnector::ConvertAddress(const BluetoothAddress& aAddress,
bdaddr_t& aBdAddr)
BluetoothUnixSocketConnector::ConvertAddressString(const char* aAddressString,
bdaddr_t& aAddress)
{
MOZ_ASSERT(MOZ_ARRAY_LENGTH(aBdAddr.b) == MOZ_ARRAY_LENGTH(aAddress.mAddr));
char* d = reinterpret_cast<char*>(aAddress.b) + 5;
/* read source address from end backwards */
auto src = aAddress.mAddr + MOZ_ARRAY_LENGTH(aAddress.mAddr) - 1;
for (size_t i = 0ul; i < MOZ_ARRAY_LENGTH(aBdAddr.b); ++i) {
aBdAddr.b[i] = *src--;
for (size_t i = 0; i < MOZ_ARRAY_LENGTH(aAddress.b); ++i) {
char* endp;
*d-- = strtoul(aAddressString, &endp, 16);
MOZ_ASSERT(!(*endp != ':' && i != 5));
aAddressString = endp + 1;
}
return NS_OK;
}
nsresult
BluetoothUnixSocketConnector::ConvertAddress(const bdaddr_t& aBdAddr,
BluetoothAddress& aAddress)
{
MOZ_ASSERT(MOZ_ARRAY_LENGTH(aBdAddr.b) == MOZ_ARRAY_LENGTH(aAddress.mAddr));
/* read source address from end backwards */
auto src = aBdAddr.b + MOZ_ARRAY_LENGTH(aBdAddr.b) - 1;
for (size_t i = 0ul; i < MOZ_ARRAY_LENGTH(aAddress.mAddr); ++i) {
aAddress.mAddr[i] = *src--;
}
return NS_OK;
}
nsresult
BluetoothUnixSocketConnector::ConvertAddress(
const struct sockaddr& aAddress, socklen_t aAddressLength,
BluetoothAddress& aAddressOut)
{
MOZ_ASSERT(aAddress.sa_family == AF_BLUETOOTH);
switch (mType) {
case BluetoothSocketType::RFCOMM: {
const struct sockaddr_rc* rc =
reinterpret_cast<const struct sockaddr_rc*>(&aAddress);
return ConvertAddress(rc->rc_bdaddr, aAddressOut);
}
break;
case BluetoothSocketType::SCO: {
const struct sockaddr_sco* sco =
reinterpret_cast<const struct sockaddr_sco*>(&aAddress);
return ConvertAddress(sco->sco_bdaddr, aAddressOut);
}
break;
case BluetoothSocketType::L2CAP:
case BluetoothSocketType::EL2CAP: {
const struct sockaddr_l2* l2 =
reinterpret_cast<const struct sockaddr_l2*>(&aAddress);
return ConvertAddress(l2->l2_bdaddr, aAddressOut);
}
break;
default:
BT_LOGR("Unknown socket type %d", static_cast<int>(mType));
return NS_ERROR_ILLEGAL_VALUE;
}
}
// |UnixSocketConnector|
nsresult

View File

@ -17,15 +17,11 @@ class BluetoothUnixSocketConnector final
: public mozilla::ipc::UnixSocketConnector
{
public:
BluetoothUnixSocketConnector(const BluetoothAddress& aAddress,
BluetoothUnixSocketConnector(const nsACString& aAddressString,
BluetoothSocketType aType,
int aChannel, bool aAuth, bool aEncrypt);
~BluetoothUnixSocketConnector();
nsresult ConvertAddress(const struct sockaddr& aAddress,
socklen_t aAddressLength,
BluetoothAddress& aAddressOut);
// Methods for |UnixSocketConnector|
//
@ -49,18 +45,14 @@ public:
nsresult Duplicate(UnixSocketConnector*& aConnector) override;
private:
static nsresult ConvertAddress(const BluetoothAddress& aAddress,
bdaddr_t& aBdAddr);
static nsresult ConvertAddress(const bdaddr_t& aBdAddr,
BluetoothAddress& aAddress);
nsresult CreateSocket(int& aFd) const;
nsresult SetSocketFlags(int aFd) const;
nsresult CreateAddress(struct sockaddr& aAddress,
socklen_t& aAddressLength) const;
static nsresult ConvertAddressString(const char* aAddressString,
bdaddr_t& aAddress);
BluetoothAddress mAddress;
nsCString mAddressString;
BluetoothSocketType mType;
int mChannel;
bool mAuth;

View File

@ -449,15 +449,6 @@ struct BluetoothAddress {
operator=(ANY);
}
/**
* |IsCleared| returns true if the address doesn not contain a
* specific value (i.e., it contains ANY).
*/
bool IsCleared() const
{
return operator==(ANY);
}
/*
* Getter and setter methods for the address parts. The figure
* below illustrates the mapping to bytes; from LSB to MSB.

View File

@ -110,11 +110,11 @@ BluetoothHidManager::HandleShutdown()
}
void
BluetoothHidManager::Connect(const BluetoothAddress& aDeviceAddress,
BluetoothHidManager::Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!aDeviceAddress.IsCleared());
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
MOZ_ASSERT(aController && !mController);
BluetoothService* bs = BluetoothService::Get();
@ -131,10 +131,7 @@ BluetoothHidManager::Connect(const BluetoothAddress& aDeviceAddress,
mDeviceAddress = aDeviceAddress;
mController = aController;
nsAutoString deviceAddressStr;
AddressToString(mDeviceAddress, deviceAddressStr);
if (NS_FAILED(bs->SendInputMessage(deviceAddressStr,
if (NS_FAILED(bs->SendInputMessage(aDeviceAddress,
NS_LITERAL_STRING("Connect")))) {
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
return;
@ -163,15 +160,12 @@ BluetoothHidManager::Disconnect(BluetoothProfileController* aController)
return;
}
MOZ_ASSERT(!mDeviceAddress.IsCleared());
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
MOZ_ASSERT(!mController);
mController = aController;
nsAutoString deviceAddressStr;
AddressToString(mDeviceAddress, deviceAddressStr);
if (NS_FAILED(bs->SendInputMessage(deviceAddressStr,
if (NS_FAILED(bs->SendInputMessage(mDeviceAddress,
NS_LITERAL_STRING("Disconnect")))) {
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
return;
@ -247,35 +241,31 @@ BluetoothHidManager::NotifyStatusChanged()
{
MOZ_ASSERT(NS_IsMainThread());
nsAutoString deviceAddressStr;
AddressToString(mDeviceAddress, deviceAddressStr);
NS_NAMED_LITERAL_STRING(type, BLUETOOTH_HID_STATUS_CHANGED_ID);
InfallibleTArray<BluetoothNamedValue> parameters;
AppendNamedValue(parameters, "connected", mConnected);
AppendNamedValue(parameters, "address", deviceAddressStr);
AppendNamedValue(parameters, "address", mDeviceAddress);
BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
}
void
BluetoothHidManager::OnGetServiceChannel(
const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
int aChannel)
BluetoothHidManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel)
{
// Do nothing here as bluez acquires service channel and connects for us
}
void
BluetoothHidManager::OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress)
BluetoothHidManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
{
// Do nothing here as bluez acquires service channel and connects for us
}
void
BluetoothHidManager::GetAddress(BluetoothAddress& aDeviceAddress)
BluetoothHidManager::GetAddress(nsAString& aDeviceAddress)
{
aDeviceAddress = mDeviceAddress;
}

View File

@ -40,7 +40,7 @@ private:
// data member
bool mConnected;
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
RefPtr<BluetoothProfileController> mController;
};

View File

@ -51,7 +51,7 @@ private:
BluetoothProfileController::BluetoothProfileController(
bool aConnect,
const BluetoothAddress& aDeviceAddress,
const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable,
BluetoothProfileControllerCallback aCallback,
uint16_t aServiceUuid,
@ -64,7 +64,7 @@ BluetoothProfileController::BluetoothProfileController(
, mSuccess(false)
, mProfilesIndex(-1)
{
MOZ_ASSERT(!aDeviceAddress.IsCleared());
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
MOZ_ASSERT(aRunnable);
MOZ_ASSERT(aCallback);
@ -230,6 +230,7 @@ void
BluetoothProfileController::StartSession()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
MOZ_ASSERT(mProfilesIndex == -1);
MOZ_ASSERT(mTimer);
@ -284,6 +285,7 @@ void
BluetoothProfileController::Next()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
MOZ_ASSERT(mProfilesIndex < (int)mProfiles.Length());
MOZ_ASSERT(mTimer);

View File

@ -93,7 +93,7 @@ public:
* aCod or disconnect all connected profiles.
*/
BluetoothProfileController(bool aConnect,
const BluetoothAddress& aDeviceAddress,
const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable,
BluetoothProfileControllerCallback aCallback,
uint16_t aServiceUuid,
@ -139,7 +139,7 @@ private:
bool IsBtServiceAvailable() const;
const bool mConnect;
BluetoothAddress mDeviceAddress;
nsString mDeviceAddress;
RefPtr<BluetoothReplyRunnable> mRunnable;
BluetoothProfileControllerCallback mCallback;

View File

@ -44,15 +44,15 @@ protected:
class BluetoothProfileManagerBase : public nsIObserver
{
public:
virtual void OnGetServiceChannel(const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
virtual void OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel) = 0;
virtual void OnUpdateSdpRecords(const BluetoothAddress& aDeviceAddress) = 0;
virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) = 0;
/**
* Return the address of the connected device.
*/
virtual void GetAddress(BluetoothAddress& aDeviceAddress) = 0;
virtual void GetAddress(nsAString& aDeviceAddress) = 0;
/**
* Return true if the profile is connected.
@ -63,7 +63,7 @@ public:
* Connect to a specific remote device. When it has been done, the
* callback "OnConnect" will be invoked.
*/
virtual void Connect(const BluetoothAddress& aDeviceAddress,
virtual void Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController) = 0;
/**
@ -93,14 +93,13 @@ public:
public: \
NS_DECL_ISUPPORTS \
NS_DECL_NSIOBSERVER \
virtual void OnGetServiceChannel(const BluetoothAddress& aDeviceAddress, \
const BluetoothUuid& aServiceUuid, \
virtual void OnGetServiceChannel(const nsAString& aDeviceAddress, \
const nsAString& aServiceUuid, \
int aChannel) override; \
virtual void OnUpdateSdpRecords( \
const BluetoothAddress& aDeviceAddress) override; \
virtual void GetAddress(BluetoothAddress& aDeviceAddress) override; \
virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) override; \
virtual void GetAddress(nsAString& aDeviceAddress) override; \
virtual bool IsConnected() override; \
virtual void Connect(const BluetoothAddress& aDeviceAddress, \
virtual void Connect(const nsAString& aDeviceAddress, \
BluetoothProfileController* aController) override; \
virtual void Disconnect(BluetoothProfileController* aController) override; \
virtual void OnConnect(const nsAString& aErrorStr) override; \

View File

@ -225,19 +225,19 @@ public:
* 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 aObjectPath Object path of remote device
* @param aServiceUuid UUID of the target service
* @param aManager Instance which has callback function OnGetServiceChannel()
*
* @return NS_OK if the task begins, NS_ERROR_FAILURE otherwise
*/
virtual nsresult
GetServiceChannel(const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
GetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
BluetoothProfileManagerBase* aManager) = 0;
virtual bool
UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
UpdateSdpRecords(const nsAString& aDeviceAddress,
BluetoothProfileManagerBase* aManager) = 0;
virtual void

View File

@ -14,6 +14,17 @@
USING_BLUETOOTH_NAMESPACE
void
BluetoothUuidHelper::GetString(BluetoothServiceClass aServiceClass,
nsAString& aRetUuidStr)
{
aRetUuidStr.Truncate();
aRetUuidStr.AppendLiteral("0000");
aRetUuidStr.AppendInt(aServiceClass, 16);
aRetUuidStr.AppendLiteral("-0000-1000-8000-00805F9B34FB");
}
BluetoothServiceClass
BluetoothUuidHelper::GetBluetoothServiceClass(const nsAString& aUuidStr)
{

View File

@ -16,6 +16,15 @@ class BluetoothProfileManagerBase;
class BluetoothUuidHelper
{
public:
/**
* Get a 128-bit uuid string calculated from a 16-bit service class UUID and
* BASE_UUID
*
* @param aServiceClassUuid 16-bit service class UUID
* @param aRetUuidStr out parameter, 128-bit uuid string
*/
static void
GetString(BluetoothServiceClass aServiceClassUuid, nsAString& aRetUuidStr);
/**
* Convert a 128-bit uuid string to a value of BluetoothServiceClass

View File

@ -208,15 +208,15 @@ BluetoothServiceChildProcess::RemoveDeviceInternal(
}
nsresult
BluetoothServiceChildProcess::GetServiceChannel(const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
BluetoothServiceChildProcess::GetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
BluetoothProfileManagerBase* aManager)
{
MOZ_CRASH("This should never be called!");
}
bool
BluetoothServiceChildProcess::UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
BluetoothServiceChildProcess::UpdateSdpRecords(const nsAString& aDeviceAddress,
BluetoothProfileManagerBase* aManager)
{
MOZ_CRASH("This should never be called!");

View File

@ -82,12 +82,12 @@ public:
BluetoothReplyRunnable* aRunnable) override;
virtual nsresult
GetServiceChannel(const BluetoothAddress& aDeviceAddress,
const BluetoothUuid& aServiceUuid,
GetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
BluetoothProfileManagerBase* aManager) override;
virtual bool
UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
UpdateSdpRecords(const nsAString& aDeviceAddress,
BluetoothProfileManagerBase* aManager) override;
virtual void