Bug 1029386: Asynchronous Bluedroid device bonding, r=shuang

This commit is contained in:
Thomas Zimmermann 2014-07-03 09:53:20 +02:00
Родитель ae524b159b
Коммит d03babe552
3 изменённых файлов: 77 добавлений и 25 удалений

Просмотреть файл

@ -711,22 +711,43 @@ BluetoothInterface::CancelDiscovery(BluetoothResultHandler* aRes)
/* Bonds */
int
BluetoothInterface::CreateBond(const bt_bdaddr_t* aBdAddr)
void
BluetoothInterface::CreateBond(const bt_bdaddr_t* aBdAddr,
BluetoothResultHandler* aRes)
{
return mInterface->create_bond(aBdAddr);
int status = mInterface->create_bond(aBdAddr);
if (aRes) {
DispatchBluetoothResult(aRes,
&BluetoothResultHandler::CreateBond,
status);
}
}
int
BluetoothInterface::RemoveBond(const bt_bdaddr_t* aBdAddr)
void
BluetoothInterface::RemoveBond(const bt_bdaddr_t* aBdAddr,
BluetoothResultHandler* aRes)
{
return mInterface->remove_bond(aBdAddr);
int status = mInterface->remove_bond(aBdAddr);
if (aRes) {
DispatchBluetoothResult(aRes,
&BluetoothResultHandler::RemoveBond,
status);
}
}
int
BluetoothInterface::CancelBond(const bt_bdaddr_t* aBdAddr)
void
BluetoothInterface::CancelBond(const bt_bdaddr_t* aBdAddr,
BluetoothResultHandler* aRes)
{
return mInterface->cancel_bond(aBdAddr);
int status = mInterface->cancel_bond(aBdAddr);
if (aRes) {
DispatchBluetoothResult(aRes,
&BluetoothResultHandler::CancelBond,
status);
}
}
/* Authentication */

Просмотреть файл

@ -271,9 +271,9 @@ public:
/* Bonds */
int CreateBond(const bt_bdaddr_t* aBdAddr);
int RemoveBond(const bt_bdaddr_t* aBdAddr);
int CancelBond(const bt_bdaddr_t* aBdAddr);
void CreateBond(const bt_bdaddr_t* aBdAddr, BluetoothResultHandler* aRes);
void RemoveBond(const bt_bdaddr_t* aBdAddr, BluetoothResultHandler* aRes);
void CancelBond(const bt_bdaddr_t* aBdAddr, BluetoothResultHandler* aRes);
/* Authentication */

Просмотреть файл

@ -1290,6 +1290,24 @@ BluetoothServiceBluedroid::UpdateSdpRecords(
return true;
}
class CreateBondResultHandler MOZ_FINAL : public BluetoothResultHandler
{
public:
CreateBondResultHandler(size_t aRunnableIndex)
: mRunnableIndex(aRunnableIndex)
{ }
void OnError(int aStatus) MOZ_OVERRIDE
{
BluetoothReplyRunnable* runnable = sBondingRunnableArray[mRunnableIndex];
sBondingRunnableArray[mRunnableIndex] = nullptr;
ReplyStatusError(runnable, aStatus, NS_LITERAL_STRING("CreatedPairedDevice"));
}
private:
PRUint32 mRunnableIndex;
};
nsresult
BluetoothServiceBluedroid::CreatePairedDeviceInternal(
const nsAString& aDeviceAddress, int aTimeout,
@ -1302,16 +1320,32 @@ BluetoothServiceBluedroid::CreatePairedDeviceInternal(
bt_bdaddr_t remoteAddress;
StringToBdAddressType(aDeviceAddress, &remoteAddress);
int ret = sBtInterface->CreateBond(&remoteAddress);
if (ret != BT_STATUS_SUCCESS) {
ReplyStatusError(aRunnable, ret, NS_LITERAL_STRING("CreatedPairedDevice"));
} else {
sBondingRunnableArray.AppendElement(aRunnable);
}
PRUint32 i = sBondingRunnableArray.Length();
sBondingRunnableArray.AppendElement(aRunnable);
sBtInterface->CreateBond(&remoteAddress, new CreateBondResultHandler(i));
return NS_OK;
}
class RemoveBondResultHandler MOZ_FINAL : public BluetoothResultHandler
{
public:
RemoveBondResultHandler(size_t aRunnableIndex)
: mRunnableIndex(aRunnableIndex)
{ }
void OnError(int aStatus) MOZ_OVERRIDE
{
BluetoothReplyRunnable* runnable = sUnbondingRunnableArray[mRunnableIndex];
sUnbondingRunnableArray[mRunnableIndex] = nullptr;
ReplyStatusError(runnable, aStatus, NS_LITERAL_STRING("RemoveDevice"));
}
private:
PRUint32 mRunnableIndex;
};
nsresult
BluetoothServiceBluedroid::RemoveDeviceInternal(
const nsAString& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
@ -1323,13 +1357,10 @@ BluetoothServiceBluedroid::RemoveDeviceInternal(
bt_bdaddr_t remoteAddress;
StringToBdAddressType(aDeviceAddress, &remoteAddress);
int ret = sBtInterface->RemoveBond(&remoteAddress);
if (ret != BT_STATUS_SUCCESS) {
ReplyStatusError(aRunnable, ret,
NS_LITERAL_STRING("RemoveDevice"));
} else {
sUnbondingRunnableArray.AppendElement(aRunnable);
}
PRUint32 i = sUnbondingRunnableArray.Length();
sUnbondingRunnableArray.AppendElement(aRunnable);
sBtInterface->RemoveBond(&remoteAddress, new RemoveBondResultHandler(i));
return NS_OK;
}