Bug 1029386: Asynchronous Bluedroid device bonding, r=shuang

This commit is contained in:
Thomas Zimmermann 2014-07-03 09:53:20 +02:00
parent ae524b159b
commit d03babe552
3 changed files with 77 additions and 25 deletions

View File

@ -711,22 +711,43 @@ BluetoothInterface::CancelDiscovery(BluetoothResultHandler* aRes)
/* Bonds */ /* Bonds */
int void
BluetoothInterface::CreateBond(const bt_bdaddr_t* aBdAddr) 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 void
BluetoothInterface::RemoveBond(const bt_bdaddr_t* aBdAddr) 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 void
BluetoothInterface::CancelBond(const bt_bdaddr_t* aBdAddr) 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 */ /* Authentication */

View File

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

View File

@ -1290,6 +1290,24 @@ BluetoothServiceBluedroid::UpdateSdpRecords(
return true; 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 nsresult
BluetoothServiceBluedroid::CreatePairedDeviceInternal( BluetoothServiceBluedroid::CreatePairedDeviceInternal(
const nsAString& aDeviceAddress, int aTimeout, const nsAString& aDeviceAddress, int aTimeout,
@ -1302,16 +1320,32 @@ BluetoothServiceBluedroid::CreatePairedDeviceInternal(
bt_bdaddr_t remoteAddress; bt_bdaddr_t remoteAddress;
StringToBdAddressType(aDeviceAddress, &remoteAddress); StringToBdAddressType(aDeviceAddress, &remoteAddress);
int ret = sBtInterface->CreateBond(&remoteAddress); PRUint32 i = sBondingRunnableArray.Length();
if (ret != BT_STATUS_SUCCESS) { sBondingRunnableArray.AppendElement(aRunnable);
ReplyStatusError(aRunnable, ret, NS_LITERAL_STRING("CreatedPairedDevice"));
} else { sBtInterface->CreateBond(&remoteAddress, new CreateBondResultHandler(i));
sBondingRunnableArray.AppendElement(aRunnable);
}
return NS_OK; 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 nsresult
BluetoothServiceBluedroid::RemoveDeviceInternal( BluetoothServiceBluedroid::RemoveDeviceInternal(
const nsAString& aDeviceAddress, BluetoothReplyRunnable* aRunnable) const nsAString& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
@ -1323,13 +1357,10 @@ BluetoothServiceBluedroid::RemoveDeviceInternal(
bt_bdaddr_t remoteAddress; bt_bdaddr_t remoteAddress;
StringToBdAddressType(aDeviceAddress, &remoteAddress); StringToBdAddressType(aDeviceAddress, &remoteAddress);
int ret = sBtInterface->RemoveBond(&remoteAddress); PRUint32 i = sUnbondingRunnableArray.Length();
if (ret != BT_STATUS_SUCCESS) { sUnbondingRunnableArray.AppendElement(aRunnable);
ReplyStatusError(aRunnable, ret,
NS_LITERAL_STRING("RemoveDevice")); sBtInterface->RemoveBond(&remoteAddress, new RemoveBondResultHandler(i));
} else {
sUnbondingRunnableArray.AppendElement(aRunnable);
}
return NS_OK; return NS_OK;
} }