Enable Wi-Fi status
[platform/core/api/runtime-info.git] / src / runtime_info_connectivity.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20
21 #include <vconf.h>
22 #include <dlog.h>
23
24 #include <runtime_info.h>
25 #include <runtime_info_private.h>
26
27 #include <system_info.h>
28
29 #ifdef LOG_TAG
30 #undef LOG_TAG
31 #endif
32
33 #define LOG_TAG "CAPI_SYSTEM_RUNTIME_INFO"
34
35 static const char *VCONF_WIFI_STATUS = VCONFKEY_WIFI_STATE;
36 static const char *VCONF_BT_ENABLED = VCONFKEY_BT_STATUS;
37 static const char *VCONF_WIFI_HOTSPOT_ENABLED = VCONFKEY_MOBILE_HOTSPOT_MODE;
38 static const char *VCONF_BT_HOTSPOT_ENABLED = VCONFKEY_MOBILE_HOTSPOT_MODE;
39 static const char *VCONF_USB_HOTSPOT_ENABLED = VCONFKEY_MOBILE_HOTSPOT_MODE;
40 static const char *VCONF_PACKET_DATA_ENABLED = VCONFKEY_3G_ENABLE;
41 static const char *VCONF_DATA_ROAMING_ENABLED = VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL;
42 static const char *VCONF_GPS_STATUS = VCONFKEY_LOCATION_GPS_STATE;
43
44 int runtime_info_wifi_status_get_value(runtime_info_value_h value)
45 {
46         int vconf_value;
47         int ret;
48
49         ret = runtime_info_vconf_get_value_int(VCONF_WIFI_STATUS, &vconf_value);
50         if (ret != RUNTIME_INFO_ERROR_NONE)
51                 return ret;
52
53         switch (vconf_value) {
54         case VCONFKEY_WIFI_OFF:
55                 value->i = RUNTIME_INFO_WIFI_STATUS_DISABLED;
56                 break;
57
58         case VCONFKEY_WIFI_UNCONNECTED:
59                 value->i = RUNTIME_INFO_WIFI_STATUS_UNCONNECTED;
60                 break;
61
62         case VCONFKEY_WIFI_CONNECTED:
63         case VCONFKEY_WIFI_TRANSFER:
64                 value->i = RUNTIME_INFO_WIFI_STATUS_CONNECTED;
65                 break;
66
67         default:
68                 return RUNTIME_INFO_ERROR_IO_ERROR;
69         }
70
71         return ret;
72 }
73
74 int runtime_info_wifi_status_set_event_cb()
75 {
76         return runtime_info_vconf_set_event_cb(VCONF_WIFI_STATUS, RUNTIME_INFO_INTERNAL_KEY_WIFI_STATUS, 0);
77 }
78
79 void runtime_info_wifi_status_unset_event_cb()
80 {
81         runtime_info_vconf_unset_event_cb(VCONF_WIFI_STATUS, 0);
82 }
83
84 int runtime_info_bt_enabled_get_value(runtime_info_value_h value)
85 {
86         int vconf_value;
87         int ret;
88
89         ret = runtime_info_vconf_get_value_int(VCONF_BT_ENABLED, &vconf_value);
90         if (ret != RUNTIME_INFO_ERROR_NONE)
91                 return ret;
92
93         switch (vconf_value) {
94         case VCONFKEY_BT_STATUS_OFF:
95                 value->b = false;
96                 break;
97
98         case VCONFKEY_BT_STATUS_ON:
99         case VCONFKEY_BT_STATUS_BT_VISIBLE:
100         case VCONFKEY_BT_STATUS_TRANSFER:
101                 value->b = true;
102                 break;
103
104         default:
105                 return RUNTIME_INFO_ERROR_IO_ERROR;
106         }
107
108         return ret;
109 }
110
111 int runtime_info_bt_enabled_set_event_cb()
112 {
113         return runtime_info_vconf_set_event_cb(VCONF_BT_ENABLED, RUNTIME_INFO_KEY_BLUETOOTH_ENABLED, 0);
114 }
115
116 void runtime_info_bt_enabled_unset_event_cb()
117 {
118         runtime_info_vconf_unset_event_cb(VCONF_BT_ENABLED, 0);
119 }
120
121
122 int runtime_info_wifi_hotspot_get_value(runtime_info_value_h value)
123 {
124         int vconf_value;
125         int ret;
126         bool supported;
127
128         ret = system_info_get_platform_bool("http://tizen.org/feature/network.tethering.wifi", &supported);
129         if (ret != SYSTEM_INFO_ERROR_NONE)
130                 return RUNTIME_INFO_ERROR_IO_ERROR;
131
132         if (!supported)
133                 return RUNTIME_INFO_ERROR_NOT_SUPPORTED;
134
135         ret = runtime_info_vconf_get_value_int(VCONF_WIFI_HOTSPOT_ENABLED, &vconf_value);
136         if (ret == RUNTIME_INFO_ERROR_NONE)
137                 value->b = (vconf_value&VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) ? true : false;
138
139         return ret;
140 }
141
142 int runtime_info_wifi_hotspot_set_event_cb()
143 {
144         return runtime_info_vconf_set_event_cb(VCONF_WIFI_HOTSPOT_ENABLED, RUNTIME_INFO_KEY_WIFI_HOTSPOT_ENABLED, 0);
145 }
146
147 void runtime_info_wifi_hotspot_unset_event_cb()
148 {
149         runtime_info_vconf_unset_event_cb(VCONF_WIFI_HOTSPOT_ENABLED, 0);
150 }
151
152 int runtime_info_bt_hotspot_get_value(runtime_info_value_h value)
153 {
154         int vconf_value;
155         int ret;
156         bool supported;
157
158         ret = system_info_get_platform_bool("http://tizen.org/feature/network.tethering.bluetooth", &supported);
159         if (ret != SYSTEM_INFO_ERROR_NONE)
160                 return RUNTIME_INFO_ERROR_IO_ERROR;
161
162         if (!supported)
163                 return RUNTIME_INFO_ERROR_NOT_SUPPORTED;
164
165         ret = runtime_info_vconf_get_value_int(VCONF_BT_HOTSPOT_ENABLED, &vconf_value);
166         if (ret == RUNTIME_INFO_ERROR_NONE)
167                 value->b = (vconf_value&VCONFKEY_MOBILE_HOTSPOT_MODE_BT) ? true : false;
168
169         return ret;
170 }
171
172 int runtime_info_bt_hotspot_set_event_cb()
173 {
174         return runtime_info_vconf_set_event_cb(VCONF_BT_HOTSPOT_ENABLED, RUNTIME_INFO_KEY_BLUETOOTH_TETHERING_ENABLED, 0);
175 }
176
177 void runtime_info_bt_hotspot_unset_event_cb()
178 {
179         runtime_info_vconf_unset_event_cb(VCONF_BT_HOTSPOT_ENABLED, 0);
180 }
181
182 int runtime_info_usb_hotspot_get_value(runtime_info_value_h value)
183 {
184         int vconf_value;
185         int ret;
186         bool supported;
187
188         ret = system_info_get_platform_bool("http://tizen.org/feature/network.tethering.usb", &supported);
189         if (ret != SYSTEM_INFO_ERROR_NONE)
190                 return RUNTIME_INFO_ERROR_IO_ERROR;
191
192         if (!supported)
193                 return RUNTIME_INFO_ERROR_NOT_SUPPORTED;
194
195         ret = runtime_info_vconf_get_value_int(VCONF_USB_HOTSPOT_ENABLED, &vconf_value);
196         if (ret == RUNTIME_INFO_ERROR_NONE)
197                 value->b = (vconf_value&VCONFKEY_MOBILE_HOTSPOT_MODE_USB) ? true : false;
198
199         return ret;
200 }
201
202 int runtime_info_usb_hotspot_set_event_cb()
203 {
204         return runtime_info_vconf_set_event_cb(VCONF_USB_HOTSPOT_ENABLED, RUNTIME_INFO_KEY_USB_TETHERING_ENABLED, 0);
205 }
206
207 void runtime_info_usb_hotspot_unset_event_cb()
208 {
209         runtime_info_vconf_unset_event_cb(VCONF_USB_HOTSPOT_ENABLED, 0);
210 }
211
212 int runtime_info_packet_data_get_value(runtime_info_value_h value)
213 {
214         int vconf_value;
215         int ret;
216
217         ret = runtime_info_vconf_get_value_bool(VCONF_PACKET_DATA_ENABLED, &vconf_value);
218         if (ret == RUNTIME_INFO_ERROR_NONE)
219                 value->b = (bool)vconf_value;
220
221         return ret;
222 }
223
224 int runtime_info_packet_data_set_event_cb()
225 {
226         return runtime_info_vconf_set_event_cb(VCONF_PACKET_DATA_ENABLED, RUNTIME_INFO_KEY_PACKET_DATA_ENABLED, 0);
227 }
228
229 void runtime_info_packet_data_unset_event_cb()
230 {
231         runtime_info_vconf_unset_event_cb(VCONF_PACKET_DATA_ENABLED, 0);
232 }
233
234 int runtime_info_data_roaming_get_value(runtime_info_value_h value)
235 {
236         int vconf_value;
237         int ret;
238
239         ret = runtime_info_vconf_get_value_bool(VCONF_DATA_ROAMING_ENABLED, &vconf_value);
240         if (ret == RUNTIME_INFO_ERROR_NONE)
241                 value->b = (bool)vconf_value;
242
243         return ret;
244 }
245
246 int runtime_info_data_roaming_set_event_cb()
247 {
248         return runtime_info_vconf_set_event_cb(VCONF_DATA_ROAMING_ENABLED, RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED, 0);
249 }
250
251 void runtime_info_data_roaming_unset_event_cb()
252 {
253         runtime_info_vconf_unset_event_cb(VCONF_DATA_ROAMING_ENABLED, 0);
254 }
255
256 int runtime_info_gps_status_get_value(runtime_info_value_h value)
257 {
258         int vconf_value;
259         int ret;
260
261         ret = runtime_info_vconf_get_value_int(VCONF_GPS_STATUS, &vconf_value);
262         if (ret != RUNTIME_INFO_ERROR_NONE)
263                 return ret;
264
265         switch (vconf_value) {
266         case VCONFKEY_LOCATION_GPS_OFF:
267                 value->i = RUNTIME_INFO_GPS_STATUS_DISABLED;
268                 break;
269
270         case VCONFKEY_LOCATION_GPS_SEARCHING:
271                 value->i = RUNTIME_INFO_GPS_STATUS_SEARCHING;
272                 break;
273
274         case VCONFKEY_LOCATION_GPS_CONNECTED:
275                 value->i = RUNTIME_INFO_GPS_STATUS_CONNECTED;
276                 break;
277
278         default:
279                 return RUNTIME_INFO_ERROR_IO_ERROR;
280         }
281
282         return ret;
283 }
284
285 int runtime_info_gps_status_set_event_cb()
286 {
287         return runtime_info_vconf_set_event_cb(VCONF_GPS_STATUS, RUNTIME_INFO_KEY_GPS_STATUS, 0);
288 }
289
290 void runtime_info_gps_status_unset_event_cb()
291 {
292         runtime_info_vconf_unset_event_cb(VCONF_GPS_STATUS, 0);
293 }
294