Bug 1065999: Ignore unknown Bluetooth properties, r=shuang
This patch is a workaround for unknown Bluetooth properties. Instead of
failing completely, we simply ignore them.
--- a/dom/bluetooth/BluetoothCommon.h
+++ b/dom/bluetooth/BluetoothCommon.h
@@ -154,16 +154,17 @@ enum BluetoothBondState {
enum BluetoothDeviceType {
DEVICE_TYPE_BREDR,
DEVICE_TYPE_BLE,
DEVICE_TYPE_DUAL
};
enum BluetoothPropertyType {
+ PROPERTY_UNKNOWN,
PROPERTY_BDNAME,
PROPERTY_BDADDR,
PROPERTY_UUIDS,
PROPERTY_CLASS_OF_DEVICE,
PROPERTY_TYPE_OF_DEVICE,
PROPERTY_SERVICE_RECORD,
PROPERTY_ADAPTER_SCAN_MODE,
PROPERTY_ADAPTER_BONDED_DEVICES,
--- a/dom/bluetooth/bluedroid/BluetoothHALHelpers.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothHALHelpers.cpp
@@ -219,16 +219,19 @@ Convert(const bt_property_t& aIn, Blueto
nsresult rv = Convert(aIn.type, aOut.mType);
if (NS_FAILED(rv)) {
return rv;
}
/* value conversion */
switch (aOut.mType) {
+ case PROPERTY_UNKNOWN:
+ /* Bug 1065999: working around unknown properties */
+ break;
case PROPERTY_BDNAME:
/* fall through */
case PROPERTY_REMOTE_FRIENDLY_NAME:
{
// We construct an nsCString here because bdname
// returned from Bluedroid is not 0-terminated.
aOut.mString = NS_ConvertUTF8toUTF16(
nsCString(static_cast<char*>(aIn.val), aIn.len));
--- a/dom/bluetooth/bluedroid/BluetoothHALHelpers.h
+++ b/dom/bluetooth/bluedroid/BluetoothHALHelpers.h
@@ -202,17 +202,19 @@ Convert(bt_property_type_t aIn, Bluetoot
};
if (aIn == BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP) {
/* This case is handled separately to not populate
* |sPropertyType| with empty entries. */
aOut = PROPERTY_REMOTE_DEVICE_TIMESTAMP;
return NS_OK;
}
if (!aIn || aIn >= MOZ_ARRAY_LENGTH(sPropertyType)) {
- return NS_ERROR_ILLEGAL_VALUE;
+ /* Bug 1065999: working around unknown properties */
+ aOut = PROPERTY_UNKNOWN;
+ return NS_OK;
}
aOut = sPropertyType[aIn];
return NS_OK;
}
inline nsresult
Convert(bt_discovery_state_t aIn, bool& aOut)
{
--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
@@ -1318,16 +1318,19 @@ BluetoothServiceBluedroid::AdapterProper
}
propertyValue = sAdapterBondedAddressArray;
BT_APPEND_NAMED_VALUE(props, "Devices", propertyValue);
} else if (p.mType == PROPERTY_UUIDS) {
//FIXME: This will be implemented in the later patchset
continue;
+ } else if (p.mType == PROPERTY_UNKNOWN) {
+ /* Bug 1065999: working around unknown properties */
+ continue;
} else {
BT_LOGD("Unhandled adapter property type: %d", p.mType);
continue;
}
}
NS_ENSURE_TRUE_VOID(props.Length() > 0);
@@ -1410,16 +1413,18 @@ BluetoothServiceBluedroid::RemoteDeviceP
}
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 if (p.mType == PROPERTY_UNKNOWN) {
+ /* Bug 1065999: working around unknown properties */
} else {
BT_LOGD("Other non-handled device properties. Type: %d", p.mType);
}
}
if (sRequestedDeviceCountArray.IsEmpty()) {
// This is possible because the callback would be called after turning
// Bluetooth on.
@@ -1470,16 +1475,18 @@ BluetoothServiceBluedroid::DeviceFoundNo
uint32_t cod = p.mUint32;
propertyValue = cod;
BT_APPEND_NAMED_VALUE(propertiesArray, "Class", propertyValue);
nsString icon;
ClassToIcon(cod, icon);
propertyValue = icon;
BT_APPEND_NAMED_VALUE(propertiesArray, "Icon", propertyValue);
+ } else if (p.mType == PROPERTY_UNKNOWN) {
+ /* Bug 1065999: working around unknown properties */
} else {
BT_LOGD("Not handled remote device property: %d", p.mType);
}
}
DistributeSignal(BluetoothSignal(NS_LITERAL_STRING("DeviceFound"),
NS_LITERAL_STRING(KEY_ADAPTER),
BluetoothValue(propertiesArray)));
--- a/dom/bluetooth2/BluetoothCommon.h
+++ b/dom/bluetooth2/BluetoothCommon.h
@@ -218,16 +218,17 @@ enum BluetoothBondState {
enum BluetoothTypeOfDevice {
TYPE_OF_DEVICE_BREDR,
TYPE_OF_DEVICE_BLE,
TYPE_OF_DEVICE_DUAL
};
enum BluetoothPropertyType {
+ PROPERTY_UNKNOWN,
PROPERTY_BDNAME,
PROPERTY_BDADDR,
PROPERTY_UUIDS,
PROPERTY_CLASS_OF_DEVICE,
PROPERTY_TYPE_OF_DEVICE,
PROPERTY_SERVICE_RECORD,
PROPERTY_ADAPTER_SCAN_MODE,
PROPERTY_ADAPTER_BONDED_DEVICES,
--- a/dom/bluetooth2/bluedroid/BluetoothHALHelpers.cpp
+++ b/dom/bluetooth2/bluedroid/BluetoothHALHelpers.cpp
@@ -337,16 +337,19 @@ Convert(const bt_property_t& aIn, Blueto
nsresult rv = Convert(aIn.type, aOut.mType);
if (NS_FAILED(rv)) {
return rv;
}
/* value conversion */
switch (aOut.mType) {
+ case PROPERTY_UNKNOWN:
+ /* Bug 1065999: working around unknown properties */
+ break;
case PROPERTY_BDNAME:
/* fall through */
case PROPERTY_REMOTE_FRIENDLY_NAME:
{
// We construct an nsCString here because bdname
// returned from Bluedroid is not 0-terminated.
aOut.mString = NS_ConvertUTF8toUTF16(
nsCString(static_cast<char*>(aIn.val), aIn.len));
--- a/dom/bluetooth2/bluedroid/BluetoothHALHelpers.h
+++ b/dom/bluetooth2/bluedroid/BluetoothHALHelpers.h
@@ -200,17 +200,19 @@ Convert(bt_property_type_t aIn, Bluetoot
};
if (aIn == BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP) {
/* This case is handled separately to not populate
* |sPropertyType| with empty entries. */
aOut = PROPERTY_REMOTE_DEVICE_TIMESTAMP;
return NS_OK;
}
if (!aIn || aIn >= MOZ_ARRAY_LENGTH(sPropertyType)) {
- return NS_ERROR_ILLEGAL_VALUE;
+ /* Bug 1065999: working around unknown properties */
+ aOut = PROPERTY_UNKNOWN;
+ return NS_OK;
}
aOut = sPropertyType[aIn];
return NS_OK;
}
inline nsresult
Convert(bt_discovery_state_t aIn, bool& aOut)
{
--- a/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.cpp
+++ b/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.cpp
@@ -1298,16 +1298,18 @@ BluetoothServiceBluedroid::AdapterProper
nsTArray<nsString> pairedDeviceAddresses;
for (size_t index = 0; index < p.mStringArray.Length(); index++) {
pairedDeviceAddresses.AppendElement(p.mStringArray[index]);
}
BT_APPEND_NAMED_VALUE(propertiesArray, "PairedDevices", pairedDeviceAddresses);
+ } else if (p.mType == PROPERTY_UNKNOWN) {
+ /* Bug 1065999: working around unknown properties */
} else {
BT_LOGD("Unhandled adapter property type: %d", p.mType);
continue;
}
}
NS_ENSURE_TRUE_VOID(propertiesArray.Length() > 0);
@@ -1365,16 +1367,18 @@ BluetoothServiceBluedroid::RemoteDeviceP
}
}
BT_APPEND_NAMED_VALUE(propertiesArray, "UUIDs", uuids);
} else if (p.mType == PROPERTY_TYPE_OF_DEVICE) {
BT_APPEND_NAMED_VALUE(propertiesArray, "Type",
static_cast<uint32_t>(p.mTypeOfDevice));
+ } else if (p.mType == PROPERTY_UNKNOWN) {
+ /* Bug 1065999: working around unknown properties */
} else {
BT_LOGD("Other non-handled device properties. Type: %d", p.mType);
}
}
// The order of operations below is
//
// (1) modify global state (i.e., the variables starting with 's'),
@@ -1462,16 +1466,18 @@ BluetoothServiceBluedroid::DeviceFoundNo
}
}
BT_APPEND_NAMED_VALUE(propertiesArray, "UUIDs", uuids);
} else if (p.mType == PROPERTY_TYPE_OF_DEVICE) {
BT_APPEND_NAMED_VALUE(propertiesArray, "Type",
static_cast<uint32_t>(p.mTypeOfDevice));
+ } else if (p.mType == PROPERTY_UNKNOWN) {
+ /* Bug 1065999: working around unknown properties */
} else {
BT_LOGD("Not handled remote device property: %d", p.mType);
}
}
DistributeSignal(BluetoothSignal(NS_LITERAL_STRING("DeviceFound"),
NS_LITERAL_STRING(KEY_ADAPTER),
BluetoothValue(propertiesArray)));