Bug 1007576 - [bluez] Update CoD value after device found while doing NFC pairing. r=echou, a=2.0+
authorShawn Huang <shuang@mozilla.com>
Fri, 27 Jun 2014 11:43:01 +0800
changeset 207436 da6103e874b6217d462783654f76e61da73f1cdf
parent 207435 1e4a2e728730d4cb1b7325c6bc57722f905edf5d
child 207437 c996b80f1ec1ce6c24a8347da092fd169513e7b2
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechou, 2
bugs1007576
milestone32.0a2
Bug 1007576 - [bluez] Update CoD value after device found while doing NFC pairing. r=echou, a=2.0+
dom/bluetooth/bluez/BluetoothDBusService.cpp
--- a/dom/bluetooth/bluez/BluetoothDBusService.cpp
+++ b/dom/bluetooth/bluez/BluetoothDBusService.cpp
@@ -1783,16 +1783,50 @@ EventFilter(DBusConnection* aConn, DBusM
               v.get_ArrayOfBluetoothNamedValue().AppendElement(
                 BluetoothNamedValue(NS_LITERAL_STRING("Icon"),
                                     NS_LITERAL_STRING("audio-card")));
             }
             break;
           }
         }
       }
+
+      if (FindProperty(properties, "Class") < 0) {
+        // Check whether the properties array contains CoD. If it doesn't,
+        // fallback to restore CoD value. This usually happens due to NFC
+        // directly triggers pairing that makes bluez not update CoD value.
+        uint32_t cod = 0;
+        int uuidIndex = FindProperty(properties, "UUIDs");
+        if (uuidIndex >= 0) {
+          BluetoothNamedValue& deviceProperty = properties[uuidIndex];
+          const InfallibleTArray<nsString>& uuids =
+            deviceProperty.value().get_ArrayOfnsString();
+
+          for (uint32_t i = 0; i < uuids.Length(); ++i) {
+            BluetoothServiceClass serviceClass =
+              BluetoothUuidHelper::GetBluetoothServiceClass(uuids[i]);
+            if (serviceClass == BluetoothServiceClass::HANDSFREE ||
+                serviceClass == BluetoothServiceClass::HEADSET) {
+              BT_LOGD("Restore CoD value, set Audio bit");
+              SET_AUDIO_BIT(cod);
+            } else if (serviceClass == BluetoothServiceClass::A2DP_SINK) {
+              BT_LOGD("Restore CoD value, set A2DP_SINK bit");
+              SET_RENDERING_BIT(cod);
+            }
+          }
+
+          // Add both CoD and Icon information anyway, 'audio-card' refers to
+          // 'Audio' device.
+          properties.AppendElement(
+            BluetoothNamedValue(NS_LITERAL_STRING("Class"), cod));
+          properties.AppendElement(
+            BluetoothNamedValue(NS_LITERAL_STRING("Icon"),
+              NS_LITERAL_STRING("audio-card")));
+        }
+      }
     }
   } else if (dbus_message_is_signal(aMsg, DBUS_ADAPTER_IFACE,
                                     "DeviceDisappeared")) {
     const char* str;
     if (!dbus_message_get_args(aMsg, &err,
                                DBUS_TYPE_STRING, &str,
                                DBUS_TYPE_INVALID)) {
       LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, aMsg);