Fix: bt_adapter_get_connectable not working 91/222591/1
authorhimanshu <h.himanshu@samsung.com>
Thu, 16 Jan 2020 07:27:28 +0000 (12:57 +0530)
committerhimanshu <h.himanshu@samsung.com>
Thu, 16 Jan 2020 09:52:43 +0000 (15:22 +0530)
Change-Id: I3d1906eccc6be787402a8fe42521918ff9a39636
Signed-off-by: himanshu <h.himanshu@samsung.com>
bt-api/bt-adapter.c
bt-oal/include/oal-adapter-mgr.h
bt-oal/oal-adapter-mgr.c
bt-service-adaptation/services/adapter/bt-service-core-adapter.c
bt-service-adaptation/services/bt-request-handler.c
bt-service-adaptation/services/include/bt-service-core-adapter.h
include/bt-internal-types.h

index 81d5823..6a0ccb2 100644 (file)
@@ -550,7 +550,7 @@ BT_EXPORT_API int bluetooth_is_connectable(gboolean *is_connectable)
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
 
-       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_IS_CONNECTABLE,
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GET_CONNECTABLE,
                in_param1, in_param2, in_param3, in_param4, &out_param);
 
        if (result == BLUETOOTH_ERROR_NONE)
index 8e709f9..6189700 100644 (file)
@@ -297,6 +297,11 @@ oal_status_t adapter_is_discoverable(int *p_discoverable);
 oal_status_t adapter_is_connectable(int *p_connectable);
 
 /**
+ * @brief Gets the connectable state of the adapter.
+ */
+oal_status_t adapter_get_connectable(void);
+
+/**
  * @brief Sets output variable to value of current discoverable timeout.
  */
 oal_status_t adapter_get_discoverable_timeout(int *p_timeout);
index b2f718d..57e9755 100644 (file)
@@ -530,6 +530,23 @@ oal_status_t adapter_get_name(void)
        return OAL_STATUS_SUCCESS;
 }
 
+oal_status_t adapter_get_connectable(void)
+{
+       int ret;
+
+       CHECK_OAL_INITIALIZED();
+
+       API_TRACE();
+
+       ret = blued_api->get_adapter_property(BT_PROPERTY_ADAPTER_SCAN_MODE);
+       if (ret != BT_STATUS_SUCCESS) {
+               BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
+               return convert_to_oal_status(ret);
+       }
+
+       return OAL_STATUS_SUCCESS;
+}
+
 oal_status_t adapter_set_name(char * name)
 {
        int ret;
index fde1d1d..4941534 100644 (file)
@@ -674,6 +674,23 @@ int _bt_set_connectable(gboolean connectable)
        return result;
 }
 
+int _bt_get_connectable(void)
+{
+       int result;
+
+       BT_DBG("+");
+
+       result =  adapter_get_connectable();
+       if (result != OAL_STATUS_SUCCESS) {
+               BT_ERR("adapter_get_connectable failed: %d", result);
+               result = BLUETOOTH_ERROR_INTERNAL;
+       } else
+               result = BLUETOOTH_ERROR_NONE;
+
+       BT_DBG("-");
+       return result;
+}
+
 int _bt_is_service_used(void)
 {
        int result;
@@ -970,13 +987,20 @@ static void __bt_adapter_event_handler(int event_type, gpointer event_data)
 
                BT_INFO("Adapter discoverable mode:"
                                " BLUETOOTH_DISCOVERABLE_MODE_NON_CONNECTABLE");
-               _bt_send_event(BT_ADAPTER_EVENT,
-                               BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
-                               g_variant_new("(b)", connectable));
 
-               _bt_send_event(BT_ADAPTER_EVENT,
-                               BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
-                               g_variant_new("(in)", result, mode));
+               if (__bt_is_service_request_present(BT_GET_CONNECTABLE)) {
+                       __bt_adapter_handle_pending_requests(BT_GET_CONNECTABLE,
+                               (void *) &connectable, sizeof(gboolean));
+
+               } else {
+                       _bt_send_event(BT_ADAPTER_EVENT,
+                                       BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
+                                       g_variant_new("(b)", connectable));
+
+                       _bt_send_event(BT_ADAPTER_EVENT,
+                                       BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
+                                       g_variant_new("(in)", result, mode));
+               }
                break;
        }
        case OAL_EVENT_ADAPTER_MODE_CONNECTABLE: {
@@ -985,28 +1009,42 @@ static void __bt_adapter_event_handler(int event_type, gpointer event_data)
 
                BT_INFO("Adapter discoverable mode:"
                                " BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE");
-               _bt_send_event(BT_ADAPTER_EVENT,
-                               BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
-                               g_variant_new("(b)", connectable));
 
-               mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
-               _bt_send_event(BT_ADAPTER_EVENT,
-                               BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
-                               g_variant_new("(in)", result, mode));
+               if (__bt_is_service_request_present(BT_GET_CONNECTABLE)) {
+                       __bt_adapter_handle_pending_requests(BT_GET_CONNECTABLE,
+                               (void *) &connectable, sizeof(gboolean));
+
+               } else {
+
+                       _bt_send_event(BT_ADAPTER_EVENT,
+                                       BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
+                                       g_variant_new("(b)", connectable));
+
+                       mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
+                       _bt_send_event(BT_ADAPTER_EVENT,
+                                       BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
+                                       g_variant_new("(in)", result, mode));
+               }
                break;
        }
        case OAL_EVENT_ADAPTER_MODE_DISCOVERABLE: {
                int mode;
+               gboolean connectable = TRUE;
 
                BT_INFO("Adapter discoverable mode:"
                                " BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE");
 
-               /* Send event to application */
-               mode = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE;
-               _bt_send_event(BT_ADAPTER_EVENT,
-                               BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
-                               g_variant_new("(in)", result, mode));
+               if (__bt_is_service_request_present(BT_GET_CONNECTABLE)) {
+                       __bt_adapter_handle_pending_requests(BT_GET_CONNECTABLE,
+                               (void *) &connectable, sizeof(gboolean));
 
+               } else {
+                       /* Send event to application */
+                       mode = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE;
+                       _bt_send_event(BT_ADAPTER_EVENT,
+                                       BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
+                                       g_variant_new("(in)", result, mode));
+               }
                break;
        }
        case OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT: {
@@ -1238,6 +1276,7 @@ static void __bt_adapter_handle_pending_requests(int service_function, void *use
                        g_array_append_vals(out_param, &done, sizeof(gboolean));
                        break;
                }
+               case BT_GET_CONNECTABLE:
                case BT_GET_LOCAL_NAME:
                case BT_GET_LOCAL_ADDRESS:
                case BT_GET_LOCAL_VERSION:
index 42ed3dd..458da29 100644 (file)
@@ -222,6 +222,7 @@ static gboolean __bt_is_sync_function(int service_function)
                        || service_function == BT_GATT_SERVER_DELETE_SERVICE
                        || service_function == BT_START_LE_DISCOVERY
                        || service_function == BT_STOP_LE_DISCOVERY
+                       || service_function == BT_GET_CONNECTABLE
 #ifdef TIZEN_GATT_CLIENT
                        || service_function == BT_GATT_CLIENT_REGISTER
                        || service_function == BT_GATT_GET_PRIMARY_SERVICES
@@ -598,6 +599,17 @@ int __bt_bluez_request(int function_name,
                g_array_append_vals(*out_param1, &is_connectable, sizeof(gboolean));
                break;
        }
+       case BT_GET_CONNECTABLE: {
+               result  = _bt_get_connectable();
+
+               /* Save invocation */
+               if (result == BLUETOOTH_ERROR_NONE) {
+                        sender = (char*)g_dbus_method_invocation_get_sender(context);
+                        _bt_save_invocation_context(context, result, sender,
+                                        function_name, NULL);
+               }
+               break;
+       }
        case BT_SET_CONNECTABLE: {
                gboolean is_connectable;
 
@@ -4153,6 +4165,7 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_IS_DISCOVERYING:
        case BT_IS_LE_DISCOVERYING:
        case BT_IS_CONNECTABLE:
+       case BT_GET_CONNECTABLE:
        case BT_GET_BONDED_DEVICES:
        case BT_GET_PROFILE_CONNECTED_DEVICES:
        case BT_GET_BONDED_DEVICE:
index 0394fac..c937aa1 100644 (file)
@@ -89,6 +89,8 @@ gboolean _bt_is_connectable(void);
 
 int _bt_is_service_used(void);
 
+int _bt_get_connectable(void);
+
 int _bt_set_connectable(gboolean connectable);
 
 int _bt_adapter_get_bonded_devices(void);
index 5fee5c9..1ad6d00 100644 (file)
@@ -188,6 +188,7 @@ typedef enum {
        BT_GET_RSSI,
        BT_IS_CONNECTABLE,
        BT_SET_CONNECTABLE,
+       BT_GET_CONNECTABLE,
        BT_GET_BONDED_DEVICES,
        BT_RESET_ADAPTER,
        BT_SET_ADVERTISING,