Bug 939669 - Append missed properties to BluetoothAdapter, r=gyeh
authorEric Chou <echou@mozilla.com>
Tue, 19 Nov 2013 11:12:17 +0800
changeset 156216 8df004b1a1ec05e05af40f33e2540dc9866733dc
parent 156215 c0822eb061f5ded45c8143525323800a2c66f367
child 156217 8eebd3c21b74b1fc571ba65ff52a15d470c5007c
push id2535
push userechou@mozilla.com
push dateTue, 19 Nov 2013 04:48:41 +0000
treeherderb2g-inbound@8df004b1a1ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgyeh
bugs939669
milestone28.0a1
Bug 939669 - Append missed properties to BluetoothAdapter, r=gyeh
dom/bluetooth/bluedroid/gonk/BluetoothServiceBluedroid.cpp
--- a/dom/bluetooth/bluedroid/gonk/BluetoothServiceBluedroid.cpp
+++ b/dom/bluetooth/bluedroid/gonk/BluetoothServiceBluedroid.cpp
@@ -155,86 +155,93 @@ ClassToIcon(uint32_t aClass, nsAString& 
         aRetIcon.AssignLiteral("camera-photo");
         break;
       }
       break;
   }
 }
 
 static void
-AdapterStateChangeCallback(bt_state_t aStatus)
+Setup()
 {
-  MOZ_ASSERT(!NS_IsMainThread());
+  // Bluetooth scan mode is NONE by default
+  bt_scan_mode_t mode = BT_SCAN_MODE_CONNECTABLE;
+  bt_property_t prop;
+  prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE;
+  prop.val = (void*)&mode;
+  prop.len = sizeof(mode);
+
+  NS_ENSURE_TRUE_VOID(sBtInterface);
 
-  BT_LOGD("%s, BT_STATE:%d", __FUNCTION__, aStatus);
-  nsAutoString signalName;
-  if (aStatus == BT_STATE_ON) {
-    sIsBtEnabled = true;
-    signalName = NS_LITERAL_STRING("AdapterAdded");
-    // by default bluetooth scan mode is NONE
-    bt_property_t prop;
-    prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE;
-    bt_scan_mode_t mode = BT_SCAN_MODE_CONNECTABLE;
-    prop.val = (void*) &mode;
-    prop.len = sizeof(mode);
-    if (sBtInterface) {
-      int ret = sBtInterface->set_adapter_property(&prop);
-      if (ret != BT_STATUS_SUCCESS) {
-        BT_LOGR("Warning! Fail to set property to BT_SCAN_MODE_CONNECTABLE");
-      }
-    }
-  } else {
-    sIsBtEnabled = false;
-    signalName = NS_LITERAL_STRING("Disabled");
+  int ret = sBtInterface->set_adapter_property(&prop);
+  if (ret != BT_STATUS_SUCCESS) {
+    BT_LOGR("%s: Fail to set: BT_SCAN_MODE_CONNECTABLE", __FUNCTION__);
   }
+}
 
-  BluetoothSignal signal(signalName, NS_LITERAL_STRING(KEY_MANAGER),
-                         BluetoothValue(true));
-  nsRefPtr<DistributeBluetoothSignalTask>
-    t = new DistributeBluetoothSignalTask(signal);
-  if (NS_FAILED(NS_DispatchToMainThread(t))) {
-    NS_WARNING("Failed to dispatch to main thread!");
+static bool
+IsReady()
+{
+  if (!sBtInterface || !sIsBtEnabled) {
+    BT_LOGR("Warning! Bluetooth Service is not ready");
+    return false;
   }
+  return true;
 }
 
 static void
 BdAddressTypeToString(bt_bdaddr_t* aBdAddressType, nsAString& aRetBdAddress)
 {
   uint8_t* addr = aBdAddressType->address;
   bdstr_t bdstr;
 
   sprintf((char*)bdstr, "%02x:%02x:%02x:%02x:%02x:%02x",
           (int)addr[0],(int)addr[1],(int)addr[2],
           (int)addr[3],(int)addr[4],(int)addr[5]);
 
   aRetBdAddress = NS_ConvertUTF8toUTF16((char*)bdstr);
 }
 
-static bool
-IsReady()
-{
-  if (!sBtInterface || !sIsBtEnabled) {
-    BT_LOGR("Warning! Bluetooth Service is not ready");
-    return false;
-  }
-  return true;
-}
-
 static void
 StringToBdAddressType(const nsAString& aBdAddress,
                       bt_bdaddr_t *aRetBdAddressType)
 {
   const char* str = NS_ConvertUTF16toUTF8(aBdAddress).get();
 
   for (int i = 0; i < 6; i++) {
     aRetBdAddressType->address[i] = (uint8_t) strtoul(str, (char **)&str, 16);
     str++;
   }
 }
 
+static void
+AdapterStateChangeCallback(bt_state_t aStatus)
+{
+  MOZ_ASSERT(!NS_IsMainThread());
+
+  BT_LOGR("%s, BT_STATE:%d", __FUNCTION__, aStatus);
+
+  nsAutoString signalName;
+  if (aStatus == BT_STATE_ON) {
+    Setup();
+    sIsBtEnabled = true;
+    signalName = NS_LITERAL_STRING("AdapterAdded");
+  } else {
+    sIsBtEnabled = false;
+    signalName = NS_LITERAL_STRING("Disabled");
+  }
+
+  BluetoothSignal signal(signalName, NS_LITERAL_STRING(KEY_MANAGER),
+                         BluetoothValue(true));
+  nsRefPtr<DistributeBluetoothSignalTask>
+    t = new DistributeBluetoothSignalTask(signal);
+  if (NS_FAILED(NS_DispatchToMainThread(t))) {
+    NS_WARNING("Failed to dispatch to main thread!");
+  }
+}
 /**
  * AdapterPropertiesChangeCallback will be called after enable() but before
  * AdapterStateChangeCallback sIsBtEnabled get updated.
  * At that moment, both BluetoothManager/BluetoothAdapter does not register
  * observer yet.
  */
 static void
 AdapterPropertiesChangeCallback(bt_status_t aStatus, int aNumProperties,
@@ -726,20 +733,32 @@ nsresult
 BluetoothServiceBluedroid::GetDefaultAdapterPathInternal(
   BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   nsRefPtr<BluetoothReplyRunnable> runnable(aRunnable);
 
   BluetoothValue v = InfallibleTArray<BluetoothNamedValue>();
+
+  v.get_ArrayOfBluetoothNamedValue().AppendElement(
+    BluetoothNamedValue(NS_LITERAL_STRING("Address"), sAdapterBdAddress));
+
   v.get_ArrayOfBluetoothNamedValue().AppendElement(
     BluetoothNamedValue(NS_LITERAL_STRING("Name"), sAdapterBdName));
 
   v.get_ArrayOfBluetoothNamedValue().AppendElement(
+    BluetoothNamedValue(NS_LITERAL_STRING("Discoverable"),
+                        sAdapterDiscoverable));
+
+  v.get_ArrayOfBluetoothNamedValue().AppendElement(
+    BluetoothNamedValue(NS_LITERAL_STRING("DiscoverableTimeout"),
+                        sAdapterDiscoverableTimeout));
+
+  v.get_ArrayOfBluetoothNamedValue().AppendElement(
     BluetoothNamedValue(NS_LITERAL_STRING("Devices"),
                         sAdapterBondedAddressArray));
 
   nsAutoString replyError;
   DispatchBluetoothReply(runnable.get(), v, replyError);
 
   runnable.forget();