Add disconnect logic when dpm policy is updated 14/176914/2
authorWootak Jung <wootak.jung@samsung.com>
Fri, 20 Apr 2018 01:16:23 +0000 (10:16 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Tue, 24 Apr 2018 07:24:22 +0000 (16:24 +0900)
Change-Id: I9aaaf07e823c7a123478e7221fabe27be61797d5

bt-service-adaptation/services/bt-service-dpm.c

index 15320d5966c291ea6f28d88f05f30b598e7dd539..7cc21b82e180e49c2d438728ce4f293d34bfa501 100644 (file)
@@ -177,6 +177,9 @@ dpm_result_t _bt_dpm_add_bluetooth_devices_to_blacklist(bluetooth_device_address
 
        policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list  = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, dev_addr);
 
+       /* Disconnect if connected blacklist device is existing */
+       // TODO: need to implement disconnect logic
+
        return BLUETOOTH_ERROR_NONE;
 }
 
@@ -269,6 +272,8 @@ int _bt_dpm_add_bluetooth_uuids_to_blacklist(const char *uuid)
 {
        char *l_uuid;
        int allow_bt = DPM_BT_ERROR;
+       GArray *addr_list = NULL;
+       int i = 0;
 
        BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blacklist");
 
@@ -281,6 +286,20 @@ int _bt_dpm_add_bluetooth_uuids_to_blacklist(const char *uuid)
                return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
 
        policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list  = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
+
+       /* Disconnect if connected blacklist uuid is existing */
+       addr_list = g_array_new(FALSE, FALSE, sizeof(gchar));
+       _bt_get_profile_connected_devices(uuid, &addr_list);
+       for (i = 0; i < (addr_list->len / sizeof(bluetooth_device_address_t)); i++) {
+               char address[BT_ADDRESS_STRING_SIZE];
+
+               bluetooth_device_address_t addr = g_array_index(addr_list, bluetooth_device_address_t, i);
+               _bt_convert_addr_type_to_string(address, addr.addr);
+               BT_INFO("device[%s] is in blacklist uuid, will be disconnected", address);
+               // TODO: need to implement disconnect logic
+       }
+       g_array_free(addr_list, TRUE);
+
        return BLUETOOTH_ERROR_NONE;
 }
 
@@ -540,6 +559,58 @@ int _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t valu
 
        dpm_profile_state[profile].value = value;
 
+       /* In case of restriction, disconnect if connected profile is existing */
+       if (value == DPM_RESTRICTED) {
+               char *uuid = NULL;
+               GArray *addr_list = NULL;
+               int i = 0;
+
+               switch (profile) {
+               case DPM_POLICY_BLUETOOTH_A2DP_PROFILE_STATE:
+                       uuid = BT_A2DP_UUID;
+                       break;
+               case DPM_POLICY_BLUETOOTH_AVRCP_PROFILE_STATE:
+                       uuid = BT_AVRCP_TARGET_UUID;
+                       break;
+               case DPM_POLICY_BLUETOOTH_BPP_PROFILE_STATE:
+                       uuid = "00001118-0000-1000-8000-00805f9b34fb"; // TODO: need to add definition and below also.
+                       break;
+               case DPM_POLICY_BLUETOOTH_DUN_PROFILE_STATE:
+                       uuid = "00001103-0000-1000-8000-00805f9b34fb";
+                       break;
+               case DPM_POLICY_BLUETOOTH_FTP_PROFILE_STATE:
+                       uuid = BT_FTP_UUID;
+                       break;
+               case DPM_POLICY_BLUETOOTH_HFP_PROFILE_STATE:
+                       uuid = "0000111e-0000-1000-8000-00805f9b34fb";
+                       break;
+               case DPM_POLICY_BLUETOOTH_HSP_PROFILE_STATE:
+                       uuid = "00001108-0000-1000-8000-00805f9b34fb";
+                       break;
+               case DPM_POLICY_BLUETOOTH_PBAP_PROFILE_STATE:
+                       uuid = BT_OBEX_PSE_UUID;
+                       break;
+               case DPM_POLICY_BLUETOOTH_SAP_PROFILE_STATE:
+                       uuid = "0000112d-0000-1000-8000-00805f9b34fb";
+                       break;
+               case DPM_POLICY_BLUETOOTH_SPP_PROFILE_STATE:
+                       uuid = BT_SPP_UUID;
+                       break;
+               }
+
+               addr_list = g_array_new(FALSE, FALSE, sizeof(gchar));
+               _bt_get_profile_connected_devices(uuid, &addr_list);
+               for (i = 0; i < (addr_list->len / sizeof(bluetooth_device_address_t)); i++) {
+                       char address[BT_ADDRESS_STRING_SIZE];
+
+                       bluetooth_device_address_t addr = g_array_index(addr_list, bluetooth_device_address_t, i);
+                       _bt_convert_addr_type_to_string(address, addr.addr);
+                       BT_INFO("device[%s] is in blacklist uuid, will be disconnected", address);
+                       // TODO: need to implement disconnect logic
+               }
+               g_array_free(addr_list, TRUE);
+       }
+
        return BLUETOOTH_ERROR_NONE;
 }