Previsouly when bt-service was started, it always tries to enable the bluetooth.
Therefore when the bluetooth is already enabled when starting bt-service,
it was not clean.
This patch allows to keep consistency between bluez and tizen bluetooth states.
By this way, if bluetooth is enabled when starting bt-service, bt-service just set vconf
and other variables. Following same logic, if bluetooth is down when starting
bt-service, we keep it down and align vconf status.
Change-Id: Iaf9170a739aa4a4c0ac37f1d98caafea1df50643
Signed-off-by: Corentin Lecouvey <corentin.lecouvey@open.eurogiciel.org>
-static int __bt_set_enabled(void)
+void _bt_set_enabled(void)
int result = BLUETOOTH_ERROR_NONE;
int result = BLUETOOTH_ERROR_NONE;
- _bt_check_adapter(&enabled);
+ _bt_adapter_set_status(BT_ACTIVATED);
- if (enabled == FALSE) {
- BT_ERR("Bluetoothd is not running");
- return BLUETOOTH_ERROR_INTERNAL;
+ // register agent if it was not previously done.
+ if (!adapter_agent) {
+ BT_DBG("");
+ _bt_handle_adapter_added();
}
__bt_set_visible_mode();
}
__bt_set_visible_mode();
/* Send enabled event to API */
_bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_ENABLED,
DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
/* Send enabled event to API */
_bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_ENABLED,
DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
-
- return BLUETOOTH_ERROR_NONE;
-static void __bt_set_disabled(int result)
+void _bt_set_disabled(void)
+ int result = BLUETOOTH_ERROR_NONE;
+
+ _bt_adapter_set_status(BT_DEACTIVATED);
+
/* Update Bluetooth Status to notify other modules */
if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
BT_ERR("Set vconf failed\n");
/* Update Bluetooth Status to notify other modules */
if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
BT_ERR("Set vconf failed\n");
void _bt_handle_adapter_added(void)
{
void _bt_handle_adapter_added(void)
{
- adapter_agent = _bt_create_agent(BT_ADAPTER_AGENT_PATH, TRUE);
- if (!adapter_agent) {
+ BT_DBG("");
+
+ adapter_agent = _bt_create_agent(BT_ADAPTER_AGENT_PATH, TRUE);
+ if (!adapter_agent) {
BT_ERR("Fail to register agent");
return;
BT_ERR("Fail to register agent");
return;
#ifdef __TIZEN_MOBILE__
if (_bt_register_media_player() != BLUETOOTH_ERROR_NONE)
#ifdef __TIZEN_MOBILE__
if (_bt_register_media_player() != BLUETOOTH_ERROR_NONE)
vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
__bt_flight_mode_cb, NULL);
vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
__bt_flight_mode_cb, NULL);
-
- __bt_set_enabled();
-
- _bt_adapter_set_status(BT_ACTIVATED);
}
void _bt_handle_adapter_removed(void)
{
}
void _bt_handle_adapter_removed(void)
{
- _bt_adapter_set_status(BT_DEACTIVATED);
vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
(vconf_callback_fn)__bt_phone_name_changed_cb);
vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
(vconf_callback_fn)__bt_phone_name_changed_cb);
_bt_destroy_agent(adapter_agent);
adapter_agent = NULL;
_bt_destroy_agent(adapter_agent);
adapter_agent = NULL;
- __bt_set_disabled(BLUETOOTH_ERROR_NONE);
-
_bt_terminate_service(NULL);
}
DBusGProxy *_bt_init_core_proxy(void)
{
_bt_terminate_service(NULL);
}
DBusGProxy *_bt_init_core_proxy(void)
{
DBusGConnection *conn;
conn = _bt_get_system_gconn();
if (!conn)
return NULL;
DBusGConnection *conn;
conn = _bt_get_system_gconn();
if (!conn)
return NULL;
- proxy = dbus_g_proxy_new_for_name(conn, BT_CORE_NAME,
+ proxy = dbus_g_proxy_new_for_name(conn, BT_CORE_NAME,
BT_CORE_PATH, BT_CORE_INTERFACE);
if (!proxy)
return NULL;
BT_CORE_PATH, BT_CORE_INTERFACE);
if (!proxy)
return NULL;
}
static DBusGProxy *__bt_get_core_proxy(void)
{
}
static DBusGProxy *__bt_get_core_proxy(void)
{
- return (core_proxy) ? core_proxy : _bt_init_core_proxy();
+ return (core_proxy) ? core_proxy : _bt_init_core_proxy();
}
int _bt_enable_adapter(void)
}
int _bt_enable_adapter(void)
}
/* Display notification */
}
/* Display notification */
- status_message_post(BT_STR_NOT_SUPPORT);
+ notification_status_message_post(BT_STR_NOT_SUPPORT);
/* Terminate myself */
g_idle_add((GSourceFunc)_bt_terminate_service, NULL);
/* Terminate myself */
g_idle_add((GSourceFunc)_bt_terminate_service, NULL);
BT_ERR("Bt core call failed");
_bt_adapter_set_status(BT_ACTIVATED);
return BLUETOOTH_ERROR_INTERNAL;
BT_ERR("Bt core call failed");
_bt_adapter_set_status(BT_ACTIVATED);
return BLUETOOTH_ERROR_INTERNAL;
return BLUETOOTH_ERROR_NONE;
}
return BLUETOOTH_ERROR_NONE;
}
DBUS_TYPE_INVALID);
} else if (strcasecmp(property, "Powered") == 0) {
gboolean power = FALSE;
DBUS_TYPE_INVALID);
} else if (strcasecmp(property, "Powered") == 0) {
gboolean power = FALSE;
dbus_message_iter_recurse(&dict_iter, &value_iter);
dbus_message_iter_get_basic(&value_iter, &power);
dbus_message_iter_recurse(&dict_iter, &value_iter);
dbus_message_iter_get_basic(&value_iter, &power);
- if (power == TRUE) {
- power_event = BLUETOOTH_EVENT_ENABLED;
- _bt_adapter_set_status(BT_ACTIVATED);
- } else {
- power_event = BLUETOOTH_EVENT_DISABLED;
- _bt_adapter_set_status(BT_DEACTIVATED);
- }
+ BT_DBG("power state changed: %d", power);
+
+ if (power == TRUE)
+ _bt_set_enabled();
+ else
+ _bt_set_disabled();
- BT_ERR("send power state: %d", power);
- /* Send event to application */
- _bt_send_event(BT_ADAPTER_EVENT,
- power_event,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INVALID);
} else if (strcasecmp(property, "Discoverable") == 0) {
gboolean discoverable = FALSE;
} else if (strcasecmp(property, "Discoverable") == 0) {
gboolean discoverable = FALSE;
+/* align bt-service state (adapter_status and vconf keys) on BlueZ state */
static gboolean __bt_check_bt_service(void *data)
{
int bt_status = VCONFKEY_BT_STATUS_OFF;
int flight_mode_deactivation = 0;
static gboolean __bt_check_bt_service(void *data)
{
int bt_status = VCONFKEY_BT_STATUS_OFF;
int flight_mode_deactivation = 0;
+ int adapter_enabled = 0;
+
if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0) {
BT_DBG("no bluetooth device info, so BT was disabled at previous session");
}
if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_deactivation) != 0)
if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0) {
BT_DBG("no bluetooth device info, so BT was disabled at previous session");
}
if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_deactivation) != 0)
- BT_ERR("Fail to get the flight_mode_deactivated value");
+ BT_ERR("Fail to get the flight_mode_deactivated value");
- if (bt_status != VCONFKEY_BT_STATUS_OFF) {
- BT_DBG("Previous session was enabled.");
+ _bt_check_adapter(&adapter_enabled);
- /* Enable the BT */
- _bt_enable_adapter();
- } else if (bt_status == VCONFKEY_BT_STATUS_OFF &&
- flight_mode_deactivation == 1) {
- _bt_handle_flight_mode_noti();
- } else {
- bt_status_t status = _bt_adapter_get_status();
- int adapter_enabled = 0;
+ BT_DBG("get bt adapter status: %d when starting bt-service ", adapter_enabled);
+
+ _bt_adapter_set_status(adapter_enabled);
- _bt_check_adapter(&adapter_enabled);
+ if (adapter_enabled != bt_status) {
+ BT_DBG("align vconf bt status key with real bluetooth status");
+ if (vconf_set_int(VCONFKEY_BT_STATUS, adapter_enabled) != 0)
+ BT_ERR("Set vconf key %s failed", VCONFKEY_BT_STATUS);
- BT_DBG("State: %d", status);
- BT_DBG("Adapter enabled: %d", adapter_enabled);
+ bt_status = adapter_enabled;
+ }
- if (adapter_enabled == 1) {
- _bt_handle_adapter_added();
- return FALSE;
- }
+ if (bt_status == VCONFKEY_BT_STATUS_OFF && flight_mode_deactivation == 1) {
+ BT_ERR("call _bt_handle_flight_mode_noti()");
+ _bt_handle_flight_mode_noti();
+ return FALSE;
+ }
- if (status != BT_ACTIVATING && status != BT_ACTIVATED) {
- _bt_terminate_service(NULL);
- }
+ if (adapter_enabled == TRUE) {
+ BT_DBG("");
+ _bt_handle_adapter_added();
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
if (perm_app_set_privilege("bluetooth-frwk-service", NULL, NULL) !=
PC_OPERATION_SUCCESS)
BT_ERR("Failed to set app privilege.\n");
if (perm_app_set_privilege("bluetooth-frwk-service", NULL, NULL) !=
PC_OPERATION_SUCCESS)
BT_ERR("Failed to set app privilege.\n");
int _bt_check_adapter(int *status);
int _bt_check_adapter(int *status);
+void _bt_set_enabled(void);
+
+void _bt_set_disabled(void);
+
void *_bt_get_adapter_agent(void);
void _bt_set_discovery_status(gboolean mode);
void *_bt_get_adapter_agent(void);
void _bt_set_discovery_status(gboolean mode);