#include <stdio.h>
#include <stdlib.h>
#include <bluetooth.h>
+#include <vconf.h>
#include "common.h"
#include "indicator.h"
#include "icon.h"
#endif
};
+#define NO_DEVICE (0x00)
+#define HEADSET_CONNECTED (0x01)
+#define DEVICE_CONNECTED (0x02)
+#define DATA_TRANSFER (0x04)
+
enum {
LEVEL_MIN = 0,
LEVEL_BT_NOT_CONNECTED = LEVEL_MIN,
index = LEVEL_MIN;
if(prevIndex == index)
- {
return;
- }
+
bluetooth.img_obj.data = icon_path[index];
icon_show(&bluetooth);
util_signal_emit(bluetooth.ad,"indicator.bluetooth.hide","indicator.prog");
}
-#define NO_DEVICE (0x00)
-#define HEADSET_CONNECTED (0x01)
-#define DEVICE_CONNECTED (0x02)
-#define DATA_TRANSFER (0x04)
-
static void show_bluetooth_icon(void *data, int status)
{
if (status == NO_DEVICE) {
return;
}
- if (status & HEADSET_CONNECTED) {
+ if (status & HEADSET_CONNECTED)
show_image_icon(data, LEVEL_BT_HEADSET);
- }
- else if (status & DEVICE_CONNECTED) {
- show_image_icon(data, LEVEL_BT_CONNECTED);
- }
- return;
-}
-static void indicator_bluetooth_adapter_state_changed_cb(int result, bt_adapter_state_e adapter_state, void *user_data)
-{
- _D("BT STATUS: %d", adapter_state);
- if (adapter_state != BT_ADAPTER_ENABLED) { // If adapter_state is NULL. hide_image_icon().
- _D("BT is not enabled. So hide BT icon.");
- hide_image_icon();
- } else
- show_bluetooth_icon(user_data, NO_DEVICE);
-}
-
-static bool _connected_cb(bt_profile_e profile, void *user_data)
-{
- int *result = (int *)user_data;
-
- if (profile == BT_PROFILE_HSP) {
- *result = (*result | HEADSET_CONNECTED);
- _D("BT_HEADSET_CONNECTED(%x)", result);
- }
- else {
- *result = (*result | DEVICE_CONNECTED);
- _D("BT_DEVICE_CONNECTED(%x)", result);
- }
+ else if (status & DEVICE_CONNECTED)
+ show_image_icon(data, LEVEL_BT_CONNECTED);
- return true;
+ return;
}
-static bool _bt_cb(bt_device_info_s *device_info, void *user_data)
-{
- // For every paired device check if it's connected with any profile
- int ret = bt_device_foreach_connected_profiles(device_info->remote_address, _connected_cb, user_data);
- retvm_if(ret != BT_ERROR_NONE, true, "bt_device_foreach_connected_profiles failed[%d]", ret);
- return true;
-}
-
-static void indicator_bluetooth_change_cb(bool connected, bt_device_connection_info_s *conn_info, void *data)
+static void indicator_bluetooth_change_cb(keynode_t *node, void *data)
{
_D("indicator_bluetooth_change_cb");
+ int dev = 0;
int ret = 0;
int result = NO_DEVICE;
bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED;
- retm_if(data == NULL, "Invalid parameter!");
+ retm_if(!data, "Invalid parameter!");
if (icon_get_update_flag() == 0) {
updated_while_lcd_off = 1;
ret = bt_adapter_get_state(&adapter_state);
retm_if(ret != BT_ERROR_NONE, "bt_adapter_get_state failed");
if (adapter_state != BT_ADAPTER_ENABLED) { // If adapter_state is NULL. hide_image_icon().
- _D("BT is not enabled. So don't need to update BT icon.");
+ _D("BT is not enabled.");
+ hide_image_icon();
return;
}
- ret = bt_adapter_foreach_bonded_device(_bt_cb, (void *)&result);
- retm_if(ret != BT_ERROR_NONE, "bt_adapter_foreach_bonded_device failed");
- show_bluetooth_icon(data, result);
-
+ ret = vconf_get_int(VCONFKEY_BT_DEVICE, &dev);
+ if (ret == OK) {
+ DBG("Show BT ICON (BT DEVICE: %d)", dev);
+
+ if (dev == VCONFKEY_BT_DEVICE_NONE) {
+ show_bluetooth_icon(data, NO_DEVICE);
+ return;
+ }
+ if ((dev & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) ||
+ (dev & VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED)) {
+ result = HEADSET_CONNECTED;
+ DBG("BT_HEADSET_CONNECTED(%x)", result);
+ }
+ if ((dev & VCONFKEY_BT_DEVICE_SAP_CONNECTED)
+ || (dev & VCONFKEY_BT_DEVICE_PBAP_CONNECTED)
+ || (dev & VCONFKEY_BT_DEVICE_HID_CONNECTED)
+ || (dev & VCONFKEY_BT_DEVICE_PAN_CONNECTED)) {
+ result = (result | DEVICE_CONNECTED);
+ DBG("BT_DEVICE_CONNECTED(%x)", result);
+ }
+ show_bluetooth_icon(data, result);
+ } else
+ hide_image_icon();
return;
}
return OK;
}
- indicator_bluetooth_change_cb(false, NULL, data);
+ indicator_bluetooth_change_cb(NULL, data);
return OK;
}
}
#endif
+
static int register_bluetooth_module(void *data)
{
- int r = 0, ret = -1;
- bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED;
+ int ret = -1;
- retvm_if(data == NULL, FAIL, "Invalid parameter!");
+ retvm_if(!data, FAIL, "Invalid parameter!");
set_app_state(data);
- // Register bluetooth adapter state call-back.
- ret = bt_initialize();
- if(ret != BT_ERROR_NONE) _E("bt_initialize failed");
- ret = bt_adapter_set_state_changed_cb(indicator_bluetooth_adapter_state_changed_cb, data);
- if(ret != BT_ERROR_NONE) _E("bt_adapter_set_state_changed_cb failed");
-
- ret = bt_device_set_connection_state_changed_cb(indicator_bluetooth_change_cb, data);
- if (ret != BT_ERROR_NONE)
- r = -1;
-
- ret = bt_adapter_get_state(&adapter_state);
- retvm_if(ret != BT_ERROR_NONE, -1, "bt_adapter_get_state failed");
+ ret = vconf_notify_key_changed(VCONFKEY_BT_DEVICE, indicator_bluetooth_change_cb, data);
+ if(ret != OK) {
+ _E("vconf_notify_key_changed failed");
+ return FAIL;
+ }
- indicator_bluetooth_change_cb(false, NULL, data);
- indicator_bluetooth_adapter_state_changed_cb(0, adapter_state, data);
+ indicator_bluetooth_change_cb(NULL, data);
- return r;
+ return OK;
}
static int unregister_bluetooth_module(void)
{
+ _E("unregister_bluetooth_module");
int ret = 0;
- // Unregister bluetooth adapter state call-back.
- ret = bt_adapter_unset_state_changed_cb();
- if(ret != BT_ERROR_NONE) _E("bt_adapter_unset_state_changed_cb failed");
- ret = bt_deinitialize();
- if(ret != BT_ERROR_NONE) _E("bt_deinitialize failed");
+ ret = vconf_ignore_key_changed(VCONFKEY_BT_DEVICE, indicator_bluetooth_change_cb);
+ if(ret != OK) _E("vconf_ignore_key_changed failed");
return ret;
}