Add new method to disconnect device 86/197186/1 accepted/tizen/unified/20190115.055940 submit/tizen/20190111.043317 submit/tizen/20190114.060943
authorDeokhyun Kim <dukan.kim@samsung.com>
Thu, 10 Jan 2019 07:20:01 +0000 (16:20 +0900)
committerDeokhyun Kim <dukan.kim@samsung.com>
Thu, 10 Jan 2019 07:20:01 +0000 (16:20 +0900)
Change-Id: Ia0dd37ce4cd13b2666c3e8f6f112ed0b8321d4b6
Signed-off-by: Deokhyun Kim <dukan.kim@samsung.com>
bt-api/bt-common.c
bt-api/bt-device.c
bt-service/bt-request-handler.c
bt-service/bt-service-common.c
bt-service/bt-service-device.c
bt-service/include/bt-service-device.h
include/bluetooth-api.h
include/bt-internal-types.h

index 93d4b41..ca76fa0 100644 (file)
@@ -512,6 +512,7 @@ const char *_bt_convert_service_function_to_string(int function)
                {BT_UPDATE_LE_CONNECTION_MODE, "BT_UPDATE_LE_CONNECTION_MODE"},
                {BT_SET_PROFILE_TRUSTED, "BT_SET_PROFILE_TRUSTED"},
                {BT_GET_PROFILE_TRUSTED, "BT_GET_PROFILE_TRUSTED"},
+               {BT_DISCONNECT_DEVICE, "BT_DISCONNECT_DEVICE"},
                {BT_HID_CONNECT, "BT_HID_CONNECT"},
                {BT_HID_DISCONNECT, "BT_HID_DISCONNECT"},
                {BT_HID_DEVICE_ACTIVATE, "BT_HID_DEVICE_ACTIVATE"},
index fff273a..ebbb4c6 100644 (file)
 #include "bt-dpm.h"
 #endif
 
+BT_EXPORT_API int bluetooth_disconnect_device(const bluetooth_device_address_t *remote_address)
+{
+       int result;
+
+       BT_CHECK_PARAMETER(remote_address, return);
+       BT_CHECK_ENABLED(return);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, remote_address, sizeof(bluetooth_device_address_t));
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_DISCONNECT_DEVICE,
+               in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
 BT_EXPORT_API int bluetooth_bond_device(const bluetooth_device_address_t *device_address)
 {
        int result;
index 6650376..53de4ba 100644 (file)
@@ -811,6 +811,17 @@ int __bt_bluez_request(int function_name,
 
                break;
        }
+       case BT_DISCONNECT_DEVICE: {
+               bluetooth_device_address_t addr = { {0} };
+               char address[BLUETOOTH_ADDRESS_STRING_LENGTH + 1];
+
+               __bt_service_get_parameters(in_param1,
+                               &addr, sizeof(bluetooth_device_address_t));
+               _bt_convert_addr_type_to_string(address, addr.addr);
+
+               result = _bt_disconnect_all(address);
+               break;
+       }
        case BT_BOND_DEVICE: {
                bluetooth_device_address_t address = { {0} };
 
@@ -2858,6 +2869,7 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_SET_PASSKEY_NOTIFICATION:
        case BT_SET_PROFILE_RESTRICTED:
 
+       case BT_DISCONNECT_DEVICE:
        case BT_CANCEL_SEARCH_SERVICE:
        case BT_ENABLE_RSSI:
 
index 1ccdb49..e50f6f6 100644 (file)
@@ -1139,6 +1139,7 @@ const char *_bt_convert_service_function_to_string(int function)
                {BT_GET_PROFILE_CONNECTED_DEVICES, "BT_GET_PROFILE_CONNECTED_DEVICES"},
                {BT_ENABLE_FORCE_HCI_DUMP, "BT_ENABLE_FORCE_HCI_DUMP"},
                {BT_SET_PASSKEY_NOTIFICATION, "BT_SET_PASSKEY_NOTIFICATION"},
+               {BT_DISCONNECT_DEVICE, "BT_DISCONNECT_DEVICE"},
                {BT_BOND_DEVICE, "BT_BOND_DEVICE"},
                {BT_BOND_DEVICE_BY_TYPE, "BT_BOND_DEVICE_BY_TYPE"},
                {BT_CANCEL_BONDING, "BT_CANCEL_BONDING"},
index 21cf691..3b33125 100644 (file)
@@ -2273,6 +2273,47 @@ int _bt_connect_profile(char *address, char *uuid,
        return BLUETOOTH_ERROR_NONE;
 }
 
+int _bt_disconnect_all(char *address)
+{
+       int ret = BLUETOOTH_ERROR_NONE;
+       char *object_path;
+       GDBusProxy *proxy;
+       GDBusConnection *conn;
+       GVariant *result = NULL;
+       GError *err = NULL;
+
+       BT_DBG("");
+       conn = _bt_gdbus_get_system_gconn();
+       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       object_path = _bt_get_device_object_path(address);
+       retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                                       NULL, BT_BLUEZ_NAME,
+                                       object_path, BT_DEVICE_INTERFACE,  NULL, NULL);
+       g_free(object_path);
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       result = g_dbus_proxy_call_sync(proxy, "Disconnect",
+               NULL,
+               G_DBUS_CALL_FLAGS_NONE,
+               -1, NULL,
+               &err);
+
+       if (err != NULL) {
+               BT_ERR("Dbus Call Error:[%s]", err->message);
+               g_error_free(err);
+               ret = BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       g_object_unref(proxy);
+       if (result)
+               g_variant_unref(result);
+
+       return ret;
+}
+
 int _bt_disconnect_profile(char *address, char *uuid,
                                                void *cb, gpointer func_data)
 {
index bd1b426..671d4e9 100644 (file)
@@ -103,6 +103,8 @@ int _bt_get_le_connection_parameter(bluetooth_le_connection_mode_t mode,
 int _bt_connect_profile(char *address, char *uuid,
                                                void *cb, gpointer func_data);
 
+int _bt_disconnect_all(char *address);
+
 int _bt_disconnect_profile(char *address, char *uuid,
                                                void *cb, gpointer func_data);
 
index f63b194..f7ee242 100644 (file)
@@ -3321,6 +3321,8 @@ int bluetooth_set_connectable(gboolean is_connectable);
 
 int bluetooth_is_connectable(gboolean *is_connectable);
 
+int bluetooth_disconnect_device(const bluetooth_device_address_t *device_address);
+
 /**
  * @fn int bluetooth_bond_device(const bluetooth_device_address_t *device_address)
  * @brief Initiate a bonding process
index 949571b..6601c22 100644 (file)
@@ -223,6 +223,7 @@ typedef enum {
        BT_UPDATE_LE_CONNECTION_MODE,
        BT_SET_PROFILE_TRUSTED,
        BT_GET_PROFILE_TRUSTED,
+       BT_DISCONNECT_DEVICE,
        BT_HID_CONNECT = BT_FUNC_HID_BASE,
        BT_HID_DISCONNECT,
        BT_HID_DEVICE_ACTIVATE,