Bug 1065999 - Ignore unknown Bluetooth properties. r=shuang, a=bajaj
authorThomas Zimmermann <tdz@users.sourceforge.net>
Mon, 29 Sep 2014 04:53:00 -0400
changeset 225270 2010c1973dedd5a360faf26219e78c4cdba7a8f9
parent 225269 c93ccef3df6438c283829571fd0866a42c16c9a4
child 225271 7c07c64662360fa356bdc373658557b046d58b7e
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshuang, bajaj
bugs1065999
milestone34.0a2
Bug 1065999 - Ignore unknown Bluetooth properties. r=shuang, a=bajaj This patch is a workaround for unknown Bluetooth properties. Instead of failing completely, we simply ignore them.
dom/bluetooth/BluetoothCommon.h
dom/bluetooth/bluedroid/BluetoothInterface.cpp
dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
--- 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/BluetoothInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothInterface.cpp
@@ -334,17 +334,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;
 }
 
 static nsresult
 Convert(bt_discovery_state_t aIn, bool& aOut)
 {
@@ -1009,16 +1011,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/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)));