mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1015819 - Part 1: [bluedroid] Restore CoD value based on SDP records. r=echou, f=btian
This commit is contained in:
parent
357617eb7a
commit
1ce0b655c9
@ -51,6 +51,7 @@ BluetoothUuidHelper::GetBluetoothServiceClass(uint16_t aServiceUuid)
|
||||
BluetoothServiceClass retValue = BluetoothServiceClass::UNKNOWN;
|
||||
switch (aServiceUuid) {
|
||||
case BluetoothServiceClass::A2DP:
|
||||
case BluetoothServiceClass::A2DP_SINK:
|
||||
case BluetoothServiceClass::HANDSFREE:
|
||||
case BluetoothServiceClass::HANDSFREE_AG:
|
||||
case BluetoothServiceClass::HEADSET:
|
||||
|
@ -25,6 +25,7 @@ class BluetoothProfileManagerBase;
|
||||
enum BluetoothServiceClass
|
||||
{
|
||||
A2DP = 0x110D,
|
||||
A2DP_SINK = 0x110B,
|
||||
HANDSFREE = 0x111E,
|
||||
HANDSFREE_AG = 0x111F,
|
||||
HEADSET = 0x1108,
|
||||
|
@ -42,6 +42,12 @@
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define MAX_UUID_SIZE 16
|
||||
// Audio: Major service class = 0x100 (Bit 21 is set)
|
||||
#define SET_AUDIO_BIT(cod) (cod |= 0x200000)
|
||||
// Rendering: Major service class = 0x20 (Bit 18 is set)
|
||||
#define SET_RENDERING_BIT(cod) (cod |= 0x40000)
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::ipc;
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
@ -482,6 +488,7 @@ RemoteDevicePropertiesCallback(bt_status_t aStatus, bt_bdaddr_t *aBdAddress,
|
||||
BdAddressTypeToString(aBdAddress, remoteDeviceBdAddress);
|
||||
BT_APPEND_NAMED_VALUE(props, "Address", remoteDeviceBdAddress);
|
||||
|
||||
bool isCodInvalid = false;
|
||||
for (int i = 0; i < aNumProperties; ++i) {
|
||||
bt_property_t p = aProperties[i];
|
||||
|
||||
@ -490,11 +497,53 @@ RemoteDevicePropertiesCallback(bt_status_t aStatus, bt_bdaddr_t *aBdAddress,
|
||||
BT_APPEND_NAMED_VALUE(props, "Name", propertyValue);
|
||||
} else if (p.type == BT_PROPERTY_CLASS_OF_DEVICE) {
|
||||
uint32_t cod = *(uint32_t*)p.val;
|
||||
BT_APPEND_NAMED_VALUE(props, "Class", cod);
|
||||
|
||||
nsString icon;
|
||||
ClassToIcon(cod, icon);
|
||||
BT_APPEND_NAMED_VALUE(props, "Icon", icon);
|
||||
if (!icon.IsEmpty()) {
|
||||
// Valid CoD
|
||||
BT_APPEND_NAMED_VALUE(props, "Class", cod);
|
||||
BT_APPEND_NAMED_VALUE(props, "Icon", icon);
|
||||
} else {
|
||||
// If Cod is invalid, fallback to check UUIDs. It usually happens due to
|
||||
// NFC directly trigger pairing. bluedroid sends wrong CoD due to missing
|
||||
// EIR query records.
|
||||
isCodInvalid = true;
|
||||
}
|
||||
} else if (p.type == BT_PROPERTY_UUIDS) {
|
||||
InfallibleTArray<nsString> uuidsArray;
|
||||
int uuidListLength = p.len / MAX_UUID_SIZE;
|
||||
uint32_t cod = 0;
|
||||
|
||||
for (int i = 0; i < uuidListLength; i++) {
|
||||
uint16_t uuidServiceClass = UuidToServiceClassInt((bt_uuid_t*)(p.val +
|
||||
(i * MAX_UUID_SIZE)));
|
||||
BluetoothServiceClass serviceClass = BluetoothUuidHelper::
|
||||
GetBluetoothServiceClass(uuidServiceClass);
|
||||
|
||||
// Get Uuid string from BluetoothServiceClass
|
||||
nsString uuid;
|
||||
BluetoothUuidHelper::GetString(serviceClass, uuid);
|
||||
uuidsArray.AppendElement(uuid);
|
||||
|
||||
// Restore CoD value
|
||||
if (isCodInvalid) {
|
||||
if (serviceClass == BluetoothServiceClass::HANDSFREE ||
|
||||
serviceClass == BluetoothServiceClass::HEADSET) {
|
||||
BT_LOGD("Restore Class Of Device to Audio bit");
|
||||
SET_AUDIO_BIT(cod);
|
||||
} else if (serviceClass == BluetoothServiceClass::A2DP_SINK) {
|
||||
BT_LOGD("Restore Class of Device to Rendering bit");
|
||||
SET_RENDERING_BIT(cod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isCodInvalid) {
|
||||
BT_APPEND_NAMED_VALUE(props, "Class", cod);
|
||||
// 'audio-card' refers to 'Audio' device
|
||||
BT_APPEND_NAMED_VALUE(props, "Icon", NS_LITERAL_STRING("audio-card"));
|
||||
}
|
||||
BT_APPEND_NAMED_VALUE(props, "UUIDS", uuidsArray);
|
||||
} else {
|
||||
BT_LOGD("Other non-handled device properties. Type: %d", p.type);
|
||||
}
|
||||
|
@ -55,6 +55,15 @@ BdAddressTypeToString(bt_bdaddr_t* aBdAddressType, nsAString& aRetBdAddress)
|
||||
aRetBdAddress = NS_ConvertUTF8toUTF16(bdstr);
|
||||
}
|
||||
|
||||
uint16_t
|
||||
UuidToServiceClassInt(bt_uuid_t* p_uuid)
|
||||
{
|
||||
// extract short UUID 0000xxxx-0000-1000-8000-00805f9b34fb
|
||||
uint16_t shortUuid;
|
||||
memcpy(&shortUuid, &(p_uuid->uu[2]), sizeof(uint16_t));
|
||||
return ntohs(shortUuid);
|
||||
}
|
||||
|
||||
bool
|
||||
SetJsObject(JSContext* aContext,
|
||||
const BluetoothValue& aValue,
|
||||
|
@ -29,6 +29,9 @@ void
|
||||
BdAddressTypeToString(bt_bdaddr_t* aBdAddressType,
|
||||
nsAString& aRetBdAddress);
|
||||
|
||||
uint16_t
|
||||
UuidToServiceClassInt(bt_uuid_t* p_uuid);
|
||||
|
||||
bool
|
||||
SetJsObject(JSContext* aContext,
|
||||
const BluetoothValue& aValue,
|
||||
|
Loading…
Reference in New Issue
Block a user