Block the code to prevent build error
[platform/core/connectivity/nfc-manager-neard.git] / daemon / net_nfc_server_vconf.c
1 /*
2  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  *                               http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17
18 #include <glib.h>
19 #include <vconf.h>
20
21 #include "net_nfc_typedef.h"
22
23 #include "net_nfc_server_vconf.h"
24 #include "net_nfc_server_common.h"
25 #include "net_nfc_server_manager.h"
26
27 #include "net_nfc_debug_internal.h"
28
29 static gboolean powered_off_by_flightmode = FALSE;
30
31 static void vconf_set_flight_mode(int boolval);
32
33 static void net_nfc_server_vconf_pm_state_changed(keynode_t *key,
34                 void *user_data);
35
36 static void net_nfc_server_vconf_flight_mode_changed(keynode_t *key,
37                 void *user_data);
38
39
40 static void vconf_set_flight_mode(int boolval)
41 {
42 #if 0
43         gint result;
44
45         /* set predefined item */
46         result = vconf_set_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, boolval);
47         if (result != 0)
48                 NFC_ERR("can not set to %d: %s", boolval, "VCONKEY_NFC_PREDEFINED_ITEM_STATE");
49 #endif
50 }
51
52 static void net_nfc_server_vconf_pm_state_changed(keynode_t *key,
53                 void *user_data)
54 {
55         gint result;
56         gint state = 0;
57         gint pm_state = 0;
58
59         result = vconf_get_bool(VCONFKEY_NFC_STATE, &state);
60         if (result != 0)
61                 NFC_ERR("can not get %s", "VCONFKEY_NFC_STATE");
62
63         if (false == state)
64         {
65                 NFC_DBG("NFC off");
66                 return;
67         }
68
69         result = vconf_get_int(VCONFKEY_PM_STATE, &pm_state);
70         if (result != 0)
71                 NFC_ERR("can not get %s", "VCONFKEY_PM_STATE");
72
73         NFC_DBG("pm_state : %d", pm_state);
74
75         if (VCONFKEY_PM_STATE_NORMAL == pm_state || VCONFKEY_PM_STATE_LCDOFF == pm_state)
76                 net_nfc_server_restart_polling_loop();
77 }
78
79 static void net_nfc_server_vconf_flight_mode_changed(keynode_t *key,
80                 void *user_data)
81 {
82         gint result = 0;
83         gint nfc_state = 0;
84         gint flight_mode = 0;
85
86
87         result = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
88         if (result != 0)
89                 NFC_ERR("Can not get VCONFKEY_TELEPHONY_FLIGHT_MODE");
90
91         NFC_DBG("flight mode %d", flight_mode);
92
93         result = vconf_get_bool(VCONFKEY_NFC_STATE, &nfc_state);
94         if (result != 0)
95                 NFC_ERR("Can not get VCONFKEY_NET_STATE");
96
97         NFC_DBG("nfc_state %d", nfc_state);
98         NFC_DBG("powerd_off_by_flightmode %d", powered_off_by_flightmode);
99
100         if (flight_mode) /* turn on flight mode */
101         {
102                 /* nfc is already disabled ignore it */
103                 if (VCONFKEY_NFC_STATE_OFF == nfc_state)
104                         return;
105
106                 NFC_INFO("Turning NFC off");
107                 net_nfc_server_manager_set_active(FALSE);
108
109                 powered_off_by_flightmode = TRUE;
110
111                 vconf_set_flight_mode(0);
112         }
113         else /* turn off flight mode */
114         {
115                 /* nfc is already enabled, ignre it */
116                 if (VCONFKEY_NFC_STATE_ON == nfc_state)
117                         return;
118
119                 if (FALSE == powered_off_by_flightmode)
120                         return;
121
122                 NFC_INFO("Turning NFC on");
123                 net_nfc_server_manager_set_active(TRUE);
124
125                 powered_off_by_flightmode = FALSE;
126
127                 vconf_set_flight_mode(1);
128         }
129 }
130
131 void net_nfc_server_vconf_init(void)
132 {
133         vconf_notify_key_changed(VCONFKEY_PM_STATE,
134                         net_nfc_server_vconf_pm_state_changed, NULL);
135
136         vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
137                         net_nfc_server_vconf_flight_mode_changed, NULL);
138 }
139
140 void net_nfc_server_vconf_deinit(void)
141 {
142         vconf_ignore_key_changed(VCONFKEY_PM_STATE, net_nfc_server_vconf_pm_state_changed);
143
144         vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
145                         net_nfc_server_vconf_flight_mode_changed);
146 }