Fix LE discovery state miss-matching issue 24/245924/1 accepted/tizen/unified/20201029.125006 submit/tizen/20201027.003129
authorDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 20 Oct 2020 02:39:49 +0000 (11:39 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 20 Oct 2020 02:39:49 +0000 (11:39 +0900)
Change-Id: I30300567d185d493f840217706f7011d9ebb72a2
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
bt-service/services/adapter/bt-service-core-adapter-le.c

index 187bd7f..c2a9748 100644 (file)
@@ -104,6 +104,7 @@ typedef struct {
 static GSList *scanner_list = NULL;
 static gboolean is_le_set_scan_parameter = FALSE;
 static gboolean is_le_scanning = FALSE;
+static gboolean is_le_actual_scanning_state = FALSE;
 static gboolean is_le_scan_hold = FALSE;
 static gboolean scan_filter_enabled = FALSE;
 static gboolean scan_stop_requested = FALSE;
@@ -1026,6 +1027,8 @@ static void __bt_le_event_handler(int event_type, gpointer event_data)
                break;
        }
        case OAL_EVENT_BLE_DISCOVERY_STARTED: {
+               is_le_actual_scanning_state = TRUE;
+
                __bt_set_le_scan_status(TRUE);
                __bt_adapter_le_handle_pending_request_info(
                                BLUETOOTH_ERROR_NONE,
@@ -1033,6 +1036,8 @@ static void __bt_le_event_handler(int event_type, gpointer event_data)
                break;
        }
        case OAL_EVENT_BLE_DISCOVERY_STOPPED: {
+               is_le_actual_scanning_state = FALSE;
+
                if (!_bt_is_le_scanning()) {
                        BT_ERR("LE discovery start failed");
                        __bt_adapter_le_handle_pending_request_info(
@@ -2071,7 +2076,7 @@ int _bt_start_le_scan(const char *sender, uid_t uid, pid_t pid)
        scanner->is_scanning = TRUE;
 
        /* Check scanning is in progress or not by other users */
-       if (_bt_is_le_scanning()) {
+       if (is_le_actual_scanning_state == TRUE) {
                int value = 1;
                BT_INFO("LE Full Scan is already on progress");
                g_idle_add(__send_le_scan_reply, (void *)(intptr_t)value);
@@ -2162,10 +2167,12 @@ int _bt_stop_le_scan(const char *sender)
                result = BLUETOOTH_ERROR_NONE;
        } else {
                if (is_le_scan_hold == TRUE) {
+                       /* Don't change any status, because the stack stops LE discovery internaly */
                        BT_INFO("Just remove LE scan hold info");
                        _bt_set_le_scan_stop_requested(FALSE);
                        is_le_scan_hold = FALSE;
-                       result = BLUETOOTH_ERROR_INTERNAL;
+                       scanner->is_scanning = TRUE;
+                       return BLUETOOTH_ERROR_DEVICE_BUSY;
                } else if (_bt_is_mesh_initialized()) {
                        /* Do not stop LE scan if BLE mesh running */
                        int value = 0;
@@ -2285,6 +2292,7 @@ static void _bt_disable_all_scanner_status(void)
 
        for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
                scanner = l->data;
+
                scanner->is_scanning = FALSE;
        }
 }