+static void __bt_set_flightmode_request(int value)
+{
+ BT_INFO("Setting flightmode request to %d", value);
+ flightmode_request = value;
+}
+
+static int __bt_is_flightmode_request(void)
+{
+ return flightmode_request;
+}
+
+static void __bt_service_handle_flight_mode(gboolean flight_mode, bt_status_t adapter_status)
+{
+ int flight_mode_value = 0;
+ int ps_mode_value = 0;
+
+ if (flight_mode == TRUE) {
+ BT_INFO_C("### Flight mode on. Turn off BT");
+
+ if (adapter_status != BT_ACTIVATED) {
+ BT_INFO("No need to control bt status");
+ if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &ps_mode_value))
+ BT_ERR("Fail get PS mode value");
+
+ BT_DBG("ps_mode_value %d", ps_mode_value);
+ if (ps_mode_value > 0) {
+ if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 1) != 0)
+ BT_ERR("Set vconf failed");
+ }
+ return;
+ }
+
+ __bt_set_flightmode_request(BT_ADAPTER_FLIGHT_MODE_ON);
+
+ if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 1) != 0)
+ BT_ERR("Set vconf failed");
+
+ if (adapter_status == BT_ACTIVATED)
+ _bt_disable_adapter();
+
+ } else {
+ BT_INFO_C("### Flight mode off. Turn on BT");
+
+ if (adapter_status == BT_ACTIVATED)
+ return;
+
+ if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_value))
+ BT_ERR("Fail get flight mode value");
+
+ BT_DBG("flight_mode_value %d", flight_mode_value);
+ if (flight_mode_value == 0)
+ return;
+
+ if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
+ BT_ERR("Set vconf failed");
+
+ if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &ps_mode_value))
+ BT_ERR("Fail get PS mode value");
+
+ BT_DBG("ps_mode_value %d", ps_mode_value);
+ if (ps_mode_value > 0) {
+ BT_DBG("Bt should not turn on");
+ return;
+ }
+
+ if (adapter_status == BT_DEACTIVATING) {
+ BT_INFO("BT adapter is deactivating. Turn on BT after deactivation");
+ __bt_set_flightmode_request(BT_ADAPTER_FLIGHT_MODE_OFF);
+ return;
+ }
+
+ if (adapter_status != BT_DEACTIVATED) {
+ BT_INFO("No need to control bt status");
+ return;
+ }
+ _bt_service_initialize();
+
+ if (adapter_status == BT_DEACTIVATED)
+ _bt_enable_adapter();
+
+ }
+}
+
+static void __bt_service_flight_ps_mode_cb(keynode_t *node, void *data)
+{
+ int type;
+ bt_status_t adapter_status = BT_DEACTIVATED;
+ gboolean flight_mode = FALSE;
+
+ adapter_status = _bt_adapter_get_status();
+ BT_INFO("Flight mode changed. Current bt status is %d", adapter_status);
+
+ DBG_SECURE("key=%s", vconf_keynode_get_name(node));
+ type = vconf_keynode_get_type(node);
+
+ if (type == VCONF_TYPE_BOOL) {
+ flight_mode = vconf_keynode_get_bool(node);
+ __bt_service_handle_flight_mode(flight_mode, adapter_status);
+ } else {
+ BT_ERR("Invaild vconf key type : %d", type);
+ }
+}
+
+void _bt_service_register_vconf_handler(void)
+{
+ BT_DBG("+");
+
+ if (vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
+ (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
+ BT_ERR("Unable to register key handler");
+ if (vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
+ (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
+ BT_ERR("Unable to register key handler");
+}
+
+void _bt_service_unregister_vconf_handler(void)
+{
+ BT_DBG("+");
+
+ vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
+ (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
+
+ vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
+ (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
+}
+