Fix : Bluetooth disabled event is sent twice 92/184592/1
authorSeungyoun Ju <sy39.ju@samsung.com>
Tue, 19 Sep 2017 13:40:24 +0000 (22:40 +0900)
committerSeungyoun Ju <sy39.ju@samsung.com>
Thu, 19 Jul 2018 05:50:49 +0000 (14:50 +0900)
[Problem] Bluetooth disabled event is sent twice when it is turned off
 by entering flight mode. It causes applications malfunction.
 For example, normally disabled event is received by weconnd after all GATT
 services have been removed. But in problem situation, the first
 disabled event happens too early so bluetooth resources (GATT services)
 remain at that time. It makes weconnd enter to strange condition (BT off but
 there are some GATT services). And after bluetooth resources are
 cleared, the second disabled event happens again. But this event is not
 processed by weconnd because it is same state to previous one.

[Cause & Measure] The first event was sent in wrong context (at Powered
 property change). This patch makes the event happen only when
 bluetoothd is terminated. So that, only one disabled event is sent
 after all bluetooth resources are cleared.

[Checking Method] Check disabled event when entering to flight mode.
 This patch is tested under below situation also.
 1. BT on / off
 2. Flight mode on -> Flight mode off
 3. Flight mode on -> BT on -> Flight mode off
 4. Recovery (TxTimeout or Hardware error by sending dbus signal)

Change-Id: Ief9dff1b4074143e1cab41b688cc960f0c73760e

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;