Fixed AVRCP controller reply pending request
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-adapter.c
index 1ce4ca3..078bca7 100644 (file)
@@ -43,6 +43,8 @@
 #include "bt-service-main.h"
 #include "bt-service-avrcp.h"
 #include "bt-service-device.h"
+#include "bt-service-adapter-le.h"
+
 #ifdef TIZEN_DPM_ENABLE
 #include "bt-service-dpm.h"
 #endif
@@ -79,7 +81,9 @@ static GDBusProxy *core_proxy = NULL;
 static guint timer_id = 0;
 static guint le_timer_id = 0;
 static gboolean is_recovery_mode;
+static gboolean in_power_off;
 
+static guint poweroff_subscribe_id;
 static uint status_reg_id;
 
 #define BT_CORE_NAME "org.projectx.bt_core"
@@ -450,6 +454,17 @@ void _bt_set_le_intended_status(gboolean value)
        is_le_intended = value;
 }
 
+static void __bt_set_in_poweroff(void)
+{
+       BT_INFO("Set in_power_off to TRUE");
+       in_power_off = TRUE;
+}
+
+static gboolean __bt_is_in_poweroff(void)
+{
+       return in_power_off;
+}
+
 static void __bt_phone_name_changed_cb(keynode_t *node, void *data)
 {
        char *phone_name = NULL;
@@ -615,7 +630,11 @@ static int __bt_set_le_enabled(void)
 
        /* Update Bluetooth Status to notify other modules */
        if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_ON) != 0)
-               BT_ERR("Set vconf failed\n");
+               BT_ERR("Set vconf failed");
+
+       /* set packet length to max size to enable packet length extension */
+       if (BLUETOOTH_ERROR_NONE != _bt_le_set_max_packet_len())
+               BT_ERR("Fail to set max packet length");
 
        if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
                                                EVT_VAL_BT_LE_ON) != ES_R_OK)
@@ -736,6 +755,53 @@ static void __bt_service_flight_ps_mode_cb(keynode_t *node, void *data)
 }
 #endif
 
+static void __bt_poweroff_event_filter(GDBusConnection *connection,
+               const gchar *sender_name, const gchar *object_path,
+               const gchar *interface_name, const gchar *signal_name,
+               GVariant *parameters, gpointer user_data)
+{
+       int state = 0;
+
+       g_variant_get(parameters, "(i)", &state);
+
+       if (state != BT_DEVICED_POWEROFF_SIGNAL_POWEROFF &&
+           state != BT_DEVICED_POWEROFF_SIGNAL_REBOOT) {
+               BT_DBG("Not interested event : %d", state);
+               return;
+       }
+
+       if (_bt_adapter_get_status() == BT_ACTIVATING) {
+               BT_INFO("Just update VCONFKEY_BT_STATUS in Power off");
+               if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_ON))
+                       BT_ERR("Set VCONFKEY_BT_STATUS failed");
+       } else {
+               __bt_set_in_poweroff();
+       }
+}
+
+void _bt_service_register_poweroff_event(void)
+{
+       if (poweroff_subscribe_id)
+               return;
+
+       poweroff_subscribe_id = g_dbus_connection_signal_subscribe(
+                       _bt_gdbus_get_system_gconn(), NULL,
+                       BT_DEVICED_POWEROFF_INTERFACE,
+                       BT_DEVICED_POWEROFF_SIGNAL,
+                       BT_DEVICED_POWEROFF_OBJECT_PATH,
+                       NULL, 0, __bt_poweroff_event_filter, NULL, NULL);
+}
+
+void _bt_service_unregister_poweroff_event(void)
+{
+       if (poweroff_subscribe_id == 0)
+               return;
+
+       g_dbus_connection_signal_unsubscribe(_bt_gdbus_get_system_gconn(),
+                                            poweroff_subscribe_id);
+       poweroff_subscribe_id = 0;
+}
+
 void _bt_service_register_vconf_handler(void)
 {
        BT_DBG("+");
@@ -1096,6 +1162,13 @@ int _bt_enable_adapter(void)
 }
 #endif
 
+       if (__bt_is_in_poweroff() == TRUE) {
+               BT_INFO("Just update VCONFKEY_BT_STATUS in Power off");
+               if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_ON) != 0)
+                       BT_ERR("Set VCONFKEY_BT_STATUS failed");
+               return BLUETOOTH_ERROR_NONE;
+       }
+
        proxy = __bt_get_core_proxy();
        if (!proxy)
                return BLUETOOTH_ERROR_INTERNAL;
@@ -1155,7 +1228,7 @@ static gboolean __bt_disconnect_all(void)
        GVariant *result;
        GError *error = NULL;
        GArray *device_list;
-       bluetooth_device_info_t info;
+       bluetooth_device_info_t *info;
        guint size;
        char *device_path = NULL;
        char address[BT_ADDRESS_STRING_SIZE] = { 0 };
@@ -1177,12 +1250,12 @@ static gboolean __bt_disconnect_all(void)
 
        for (i = 0; i < size; i++) {
 
-               info = g_array_index(device_list,
+               info = &g_array_index(device_list,
                                bluetooth_device_info_t, i);
 
-               if (info.connected != BLUETOOTH_CONNECTED_LINK_NONE) {
+               if (info->connected != BLUETOOTH_CONNECTED_LINK_NONE) {
                        BT_DBG("Found Connected device");
-                       _bt_convert_addr_type_to_string(address, info.device_address.addr);
+                       _bt_convert_addr_type_to_string(address, info->device_address.addr);
                        device_path = _bt_get_device_object_path(address);
                        if (device_path == NULL)
                                continue;