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