2 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include "net_nfc_typedef.h"
23 #include "net_nfc_server_vconf.h"
24 #include "net_nfc_server_common.h"
25 #include "net_nfc_server_manager.h"
27 #include "net_nfc_debug_internal.h"
29 static gboolean powered_off_by_flightmode = FALSE;
31 static void vconf_set_flight_mode(int boolval);
33 static void net_nfc_server_vconf_pm_state_changed(keynode_t *key,
36 static void net_nfc_server_vconf_flight_mode_changed(keynode_t *key,
40 static void vconf_set_flight_mode(int boolval)
45 /* set predefined item */
46 result = vconf_set_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, boolval);
48 NFC_ERR("can not set to %d: %s", boolval, "VCONKEY_NFC_PREDEFINED_ITEM_STATE");
52 static void net_nfc_server_vconf_pm_state_changed(keynode_t *key,
59 result = vconf_get_bool(VCONFKEY_NFC_STATE, &state);
61 NFC_ERR("can not get %s", "VCONFKEY_NFC_STATE");
69 result = vconf_get_int(VCONFKEY_PM_STATE, &pm_state);
71 NFC_ERR("can not get %s", "VCONFKEY_PM_STATE");
73 NFC_DBG("pm_state : %d", pm_state);
75 if (VCONFKEY_PM_STATE_NORMAL == pm_state || VCONFKEY_PM_STATE_LCDOFF == pm_state)
76 net_nfc_server_restart_polling_loop();
79 static void net_nfc_server_vconf_flight_mode_changed(keynode_t *key,
87 result = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
89 NFC_ERR("Can not get VCONFKEY_TELEPHONY_FLIGHT_MODE");
91 NFC_DBG("flight mode %d", flight_mode);
93 result = vconf_get_bool(VCONFKEY_NFC_STATE, &nfc_state);
95 NFC_ERR("Can not get VCONFKEY_NET_STATE");
97 NFC_DBG("nfc_state %d", nfc_state);
98 NFC_DBG("powerd_off_by_flightmode %d", powered_off_by_flightmode);
100 if (flight_mode) /* turn on flight mode */
102 /* nfc is already disabled ignore it */
103 if (VCONFKEY_NFC_STATE_OFF == nfc_state)
106 NFC_INFO("Turning NFC off");
107 net_nfc_server_manager_set_active(FALSE);
109 powered_off_by_flightmode = TRUE;
111 vconf_set_flight_mode(0);
113 else /* turn off flight mode */
115 /* nfc is already enabled, ignre it */
116 if (VCONFKEY_NFC_STATE_ON == nfc_state)
119 if (FALSE == powered_off_by_flightmode)
122 NFC_INFO("Turning NFC on");
123 net_nfc_server_manager_set_active(TRUE);
125 powered_off_by_flightmode = FALSE;
127 vconf_set_flight_mode(1);
131 void net_nfc_server_vconf_init(void)
133 vconf_notify_key_changed(VCONFKEY_PM_STATE,
134 net_nfc_server_vconf_pm_state_changed, NULL);
136 vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
137 net_nfc_server_vconf_flight_mode_changed, NULL);
140 void net_nfc_server_vconf_deinit(void)
142 vconf_ignore_key_changed(VCONFKEY_PM_STATE, net_nfc_server_vconf_pm_state_changed);
144 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
145 net_nfc_server_vconf_flight_mode_changed);