Bug 791650 - Final version: 'Connected' attribute in device should a 2-byte array, r=qdot
authorGina Yeh <gyeh@mozilla.com>
Wed, 19 Sep 2012 11:22:38 +0800
changeset 107565 c9c8d79d3419d833b4474b00f9be706fbf6af14e
parent 107564 20ba45df0a7372fff61dd3ec09b1167ad59066ad
child 107566 0a28200d2954d5b625f47cadae71156c96131d12
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersqdot
bugs791650
milestone18.0a1
Bug 791650 - Final version: 'Connected' attribute in device should a 2-byte array, r=qdot
dom/bluetooth/BluetoothDevice.cpp
dom/bluetooth/ipc/BluetoothTypes.ipdlh
dom/bluetooth/linux/BluetoothDBusService.cpp
--- a/dom/bluetooth/BluetoothDevice.cpp
+++ b/dom/bluetooth/BluetoothDevice.cpp
@@ -110,17 +110,25 @@ BluetoothDevice::SetPropertyByValue(cons
     }
   } else if (name.EqualsLiteral("Address")) {
     mAddress = value.get_nsString();
   } else if (name.EqualsLiteral("Class")) {
     mClass = value.get_uint32_t();
   } else if (name.EqualsLiteral("Icon")) {
     mIcon = value.get_nsString();
   } else if (name.EqualsLiteral("Connected")) {
+#ifdef MOZ_WIDGET_GONK
+    // Connected is an 2-byte array
+    // arr[0]: boolean value, true means connected, false means disconnected
+    // arr[1]: disconnection reason
+    InfallibleTArray<uint8_t> arr = value.get_ArrayOfuint8_t();
+    mConnected = (arr[0] == 1);
+#else
     mConnected = value.get_bool();
+#endif
   } else if (name.EqualsLiteral("Paired")) {
     mPaired = value.get_bool();
   } else if (name.EqualsLiteral("UUIDs")) {
     mUuids = value.get_ArrayOfnsString();
     nsresult rv;
     nsIScriptContext* sc = GetContextForEventHandlers(&rv);
     if (sc) {
       rv =
@@ -188,35 +196,34 @@ BluetoothDevice::Notify(const BluetoothS
     NS_ASSERTION(aData.value().type() == BluetoothValue::TArrayOfBluetoothNamedValue,
                  "PropertyChanged: Invalid value type");
     InfallibleTArray<BluetoothNamedValue> arr = aData.value().get_ArrayOfBluetoothNamedValue();
 
     NS_ASSERTION(arr.Length() == 1, "Got more than one property in a change message!");
     BluetoothNamedValue v = arr[0];
     nsString name = v.name();
 
+    SetPropertyByValue(v);
     if (name.EqualsLiteral("Connected")) {
-      bool isConnected = v.value();
       nsRefPtr<nsDOMEvent> event = new nsDOMEvent(nullptr, nullptr);
       nsresult rv;
-      if (isConnected) {
+      if (mConnected) {
         rv = event->InitEvent(NS_LITERAL_STRING("connected"), false, false);
       } else {
         rv = event->InitEvent(NS_LITERAL_STRING("disconnected"), false, false);
       }
       if (NS_FAILED(rv)) {
         NS_WARNING("Failed to init the connected/disconnected event!!!");
         return;
       }
 
       event->SetTrusted(true);
       bool dummy;
       DispatchEvent(event, &dummy);
     } else {
-      SetPropertyByValue(v);
       nsRefPtr<BluetoothPropertyEvent> e = BluetoothPropertyEvent::Create(name);
       e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("propertychanged"));
     }
   } else {
 #ifdef DEBUG
     nsCString warningMsg;
     warningMsg.AssignLiteral("Not handling device signal: ");
     warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name()));
--- a/dom/bluetooth/ipc/BluetoothTypes.ipdlh
+++ b/dom/bluetooth/ipc/BluetoothTypes.ipdlh
@@ -15,16 +15,17 @@ namespace bluetooth {
  * 
  */
 union BluetoothValue
 {
   uint32_t;
   nsString;
   bool;
   nsString[];
+  uint8_t[];
   BluetoothNamedValue[];
 };
 
 /**
  * Key-value pair for dicts returned by the bluetooth backend. Used for things
  * like property updates, where the property will have a name and a type.
  * 
  */
--- a/dom/bluetooth/linux/BluetoothDBusService.cpp
+++ b/dom/bluetooth/linux/BluetoothDBusService.cpp
@@ -75,17 +75,21 @@ typedef struct {
 
 static Properties sDeviceProperties[] = {
   {"Address", DBUS_TYPE_STRING},
   {"Name", DBUS_TYPE_STRING},
   {"Icon", DBUS_TYPE_STRING},
   {"Class", DBUS_TYPE_UINT32},
   {"UUIDs", DBUS_TYPE_ARRAY},
   {"Paired", DBUS_TYPE_BOOLEAN},
+#ifdef MOZ_WIDGET_GONK
+  {"Connected", DBUS_TYPE_ARRAY},
+#else
   {"Connected", DBUS_TYPE_BOOLEAN},
+#endif
   {"Trusted", DBUS_TYPE_BOOLEAN},
   {"Blocked", DBUS_TYPE_BOOLEAN},
   {"Alias", DBUS_TYPE_STRING},
   {"Nodes", DBUS_TYPE_ARRAY},
   {"Adapter", DBUS_TYPE_OBJECT_PATH},
   {"LegacyPairing", DBUS_TYPE_BOOLEAN},
   {"RSSI", DBUS_TYPE_INT16},
   {"TX", DBUS_TYPE_UINT32},
@@ -701,26 +705,34 @@ GetProperty(DBusMessageIter aIter, Prope
       bool b;
       dbus_message_iter_get_basic(&prop_val, &b);
       propertyValue = b;
       break;
     case DBUS_TYPE_ARRAY:
       dbus_message_iter_recurse(&prop_val, &array_val_iter);
       array_type = dbus_message_iter_get_arg_type(&array_val_iter);
       if (array_type == DBUS_TYPE_OBJECT_PATH ||
-          array_type == DBUS_TYPE_STRING){
+          array_type == DBUS_TYPE_STRING) {
         InfallibleTArray<nsString> arr;
         do {
           const char* tmp;
           dbus_message_iter_get_basic(&array_val_iter, &tmp);
           nsString s;
           s = NS_ConvertUTF8toUTF16(tmp);
           arr.AppendElement(s);
         } while (dbus_message_iter_next(&array_val_iter));
         propertyValue = arr;
+      } else if (array_type == DBUS_TYPE_BYTE) {
+        InfallibleTArray<uint8_t> arr;
+        do {
+          uint8_t tmp;
+          dbus_message_iter_get_basic(&array_val_iter, &tmp);
+          arr.AppendElement(tmp);
+        } while (dbus_message_iter_next(&array_val_iter));
+        propertyValue = arr;
       } else {
         // This happens when the array is 0-length. Apparently we get a
         // DBUS_TYPE_INVALID type.
         propertyValue = InfallibleTArray<nsString>();
 #ifdef DEBUG
         NS_WARNING("Received array type that's not a string array!");
 #endif
       }