Bug 1102703: (4/10) Porting bluetooth interface of android lollipop (core) r=btian, r=tzimmermann, r=shawnjohnjr

This commit is contained in:
Bruce Sun 2015-01-09 13:36:32 +08:00
parent 9fdb3ecbb3
commit d21f24e0c8
3 changed files with 148 additions and 5 deletions

View File

@ -211,6 +211,39 @@ Convert(const btrc_player_settings_t& aIn, BluetoothAvrcpPlayerSettings& aOut)
}
#endif // ANDROID_VERSION >= 18
#if ANDROID_VERSION >= 21
nsresult
Convert(const bt_activity_energy_info& aIn, BluetoothActivityEnergyInfo& aOut)
{
nsresult rv = Convert(aIn.status, aOut.mStatus);
if (NS_FAILED(rv)) {
return rv;
}
rv = Convert(aIn.ctrl_state, aOut.mStackState);
if (NS_FAILED(rv)) {
return rv;
}
rv = Convert(aIn.tx_time, aOut.mTxTime);
if (NS_FAILED(rv)) {
return rv;
}
rv = Convert(aIn.rx_time, aOut.mRxTime);
if (NS_FAILED(rv)) {
return rv;
}
rv = Convert(aIn.idle_time, aOut.mIdleTime);
if (NS_FAILED(rv)) {
return rv;
}
rv = Convert(aIn.energy_used, aOut.mEnergyUsed);
if (NS_FAILED(rv)) {
return rv;
}
return NS_OK;
}
#endif // ANDROID_VERSION >= 21
nsresult
Convert(const bt_property_t& aIn, BluetoothProperty& aOut)
{

View File

@ -765,6 +765,26 @@ Convert(btrc_remote_features_t aIn, unsigned long& aOut)
}
#endif // ANDROID_VERSION >= 19
#if ANDROID_VERSION >= 21
inline nsresult
Convert(BluetoothTransport aIn, int& aOut)
{
static const int sTransport[] = {
CONVERT(TRANSPORT_AUTO, 0),
CONVERT(TRANSPORT_BREDR, 1),
CONVERT(TRANSPORT_LE, 2)
};
if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sTransport))) {
return NS_ERROR_ILLEGAL_VALUE;
}
aOut = sTransport[aIn];
return NS_OK;
}
nsresult
Convert(const bt_activity_energy_info& aIn, BluetoothActivityEnergyInfo& aOut);
#endif // ANDROID_VERSION >= 21
/* |ConvertArray| is a helper for converting arrays. Pass an
* instance of this structure as the first argument to |Convert|
* to convert an array. The output type has to support the array

View File

@ -318,8 +318,57 @@ struct BluetoothCallback
&BluetoothNotificationHandler::LeTestModeNotification,
aStatus, aNumPackets);
}
#if ANDROID_VERSION >= 21
static void
EnergyInfo(bt_activity_energy_info* aEnergyInfo)
{
if (NS_WARN_IF(!aEnergyInfo)) {
return;
}
EnergyInfoNotification::Dispatch(
&BluetoothNotificationHandler::EnergyInfoNotification,
*aEnergyInfo);
}
#endif
};
#if ANDROID_VERSION >= 21
struct BluetoothOsCallout
{
static bool
SetWakeAlarm(uint64_t aDelayMilliseconds,
bool aShouldWake,
void (* aAlarmCallback)(void*),
void* aData)
{
// FIXME: need to be implemented in later patches
// HAL wants to manage an wake_alarm but Gecko cannot fulfill it for now.
// Simply pass the request until a proper implementation has been added.
return true;
}
static int
AcquireWakeLock(const char* aLockName)
{
// FIXME: need to be implemented in later patches
// HAL wants to manage an wake_lock but Gecko cannot fulfill it for now.
// Simply pass the request until a proper implementation has been added.
return BT_STATUS_SUCCESS;
}
static int
ReleaseWakeLock(const char* aLockName)
{
// FIXME: need to be implemented in later patches
// HAL wants to manage an wake_lock but Gecko cannot fulfill it for now.
// Simply pass the request until a proper implementation has been added.
return BT_STATUS_SUCCESS;
}
};
#endif
// Interface
//
@ -414,14 +463,35 @@ BluetoothHALInterface::Init(
BluetoothCallback::ThreadEvt,
BluetoothCallback::DutModeRecv,
#if ANDROID_VERSION >= 18
BluetoothCallback::LeTestMode
BluetoothCallback::LeTestMode,
#endif
#if ANDROID_VERSION >= 21
BluetoothCallback::EnergyInfo
#endif
};
#if ANDROID_VERSION >= 21
static bt_os_callouts_t sBluetoothOsCallouts = {
sizeof(sBluetoothOsCallouts),
BluetoothOsCallout::SetWakeAlarm,
BluetoothOsCallout::AcquireWakeLock,
BluetoothOsCallout::ReleaseWakeLock
};
#endif
sNotificationHandler = aNotificationHandler;
int status = mInterface->init(&sBluetoothCallbacks);
#if ANDROID_VERSION >= 21
if (status == BT_STATUS_SUCCESS) {
status = mInterface->set_os_callouts(&sBluetoothOsCallouts);
if (status != BT_STATUS_SUCCESS) {
mInterface->cleanup();
}
}
#endif
if (aRes) {
DispatchBluetoothHALResult(aRes, &BluetoothResultHandler::Init,
ConvertDefault(status, STATUS_FAIL));
@ -676,8 +746,16 @@ BluetoothHALInterface::CreateBond(const nsAString& aBdAddr,
bt_bdaddr_t bdAddr;
int status;
#if ANDROID_VERSION >= 21
int transport = 0; /* TRANSPORT_AUTO */
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr)) &&
NS_SUCCEEDED(Convert(aTransport, transport))) {
status = mInterface->create_bond(&bdAddr, transport);
#else
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
status = mInterface->create_bond(&bdAddr);
#endif
} else {
status = BT_STATUS_PARM_INVALID;
}
@ -735,9 +813,19 @@ void
BluetoothHALInterface::GetConnectionState(const nsAString& aBdAddr,
BluetoothResultHandler* aRes)
{
// TODO: to be implemented
int status;
int status = BT_STATUS_UNSUPPORTED;
#if ANDROID_VERSION >= 21
bt_bdaddr_t bdAddr;
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
status = mInterface->get_connection_state(&bdAddr);
} else {
status = BT_STATUS_PARM_INVALID;
}
#else
status = BT_STATUS_UNSUPPORTED;
#endif
if (aRes) {
DispatchBluetoothHALResult(aRes,
@ -858,9 +946,11 @@ BluetoothHALInterface::LeTestMode(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
void
BluetoothHALInterface::ReadEnergyInfo(BluetoothResultHandler* aRes)
{
// TODO: to be implemented
#if ANDROID_VERSION >= 21
int status = mInterface->read_energy_info();
#else
int status = BT_STATUS_UNSUPPORTED;
#endif
if (aRes) {
DispatchBluetoothHALResult(aRes,