Fix : Bluetooth disabled event is sent twice
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-event-receiver.c
index 09ec54a..49e8c77 100644 (file)
@@ -430,22 +430,6 @@ static void __bt_device_remote_connected_properties(
        BT_DBG("-");
 }
 
-gboolean __bt_handle_is_flight_mode_enabled(void)
-{
-#ifdef TIZEN_FEATURE_FLIGHTMODE_ENABLED
-       int is_flight_mode = 0;
-       int ret = -1;
-
-       ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &is_flight_mode);
-       if (ret != 0)
-               BT_ERR("vconf_get_bool failed");
-
-       return (is_flight_mode == 0) ? FALSE : TRUE;
-#else
-       return FALSE;
-#endif
-}
-
 void _bt_handle_adapter_event(GVariant *msg, const char *member)
 {
        BT_DBG("+");
@@ -790,33 +774,36 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                                BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
                                param);
                } else if (strcasecmp(property, "Powered") == 0) {
-                       /* TODO: Need to check this operation!! */
                        gboolean powered = FALSE;
-                       int bt_state;
+                       int bt_state = VCONFKEY_BT_STATUS_OFF;
+                       int le_state = VCONFKEY_BT_LE_STATUS_OFF;
 
                        g_variant_get(val, "b", &powered);
                        BT_DBG("Powered = %d", powered);
-                       if (powered == FALSE) {
-#ifdef USB_BLUETOOTH
-                               _bt_handle_adapter_removed();
-#else
-                               if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
-                               bt_state != VCONFKEY_BT_STATUS_OFF) {
-                                       if (__bt_handle_is_flight_mode_enabled() == FALSE)
-                                               _bt_disable_adapter();
-                                       else
-                                               _bt_handle_adapter_removed();
-                               }
-#endif
-                               if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
-                                       bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
-                                       _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
-                               }
-                       } else {
+
 #ifdef USB_BLUETOOTH
+                       if (powered) {
                                _bt_handle_adapter_added();
-#endif
+                               continue;
                        }
+
+                       _bt_handle_adapter_removed();
+
+                       vconf_get_int(VCONFKEY_BT_LE_STATUS, &le_state);
+                       if (le_state != VCONFKEY_BT_LE_STATUS_OFF)
+                               _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
+#else
+                       if (powered)
+                               continue;
+
+                       vconf_get_int(VCONFKEY_BT_STATUS, &bt_state);
+                       if (bt_state != VCONFKEY_BT_STATUS_OFF)
+                               _bt_disable_adapter();
+
+                       vconf_get_int(VCONFKEY_BT_LE_STATUS, &le_state);
+                       if (le_state != VCONFKEY_BT_LE_STATUS_OFF)
+                               _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
+#endif
                } else if (strcasecmp(property, "Connectable") == 0) {
                        gboolean connectable = FALSE;