runtime-info: added process Memory and CPU usage APIs
[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 int runtime_info_wifi_status_get_value(runtime_info_value_h value)
43 {
44         int vconf_value;
45
46         if (runtime_info_vconf_get_value_int(VCONF_WIFI_STATUS, &vconf_value))
47                 vconf_value = VCONFKEY_WIFI_OFF;
48
49         switch (vconf_value) {
50         case VCONFKEY_WIFI_OFF:
51                 value->i = RUNTIME_INFO_WIFI_STATUS_DISABLED;
52                 break;
53
54         case VCONFKEY_WIFI_UNCONNECTED:
55                 value->i = RUNTIME_INFO_WIFI_STATUS_UNCONNECTED;
56                 break;
57
58         case VCONFKEY_WIFI_CONNECTED:
59         case VCONFKEY_WIFI_TRANSFER:
60                 value->i = RUNTIME_INFO_WIFI_STATUS_CONNECTED;
61                 break;
62
63         default:
64                 return RUNTIME_INFO_ERROR_IO_ERROR;
65         }
66
67         return RUNTIME_INFO_ERROR_NONE;
68 }
69
70 int runtime_info_wifi_status_set_event_cb()
71 {
72         return runtime_info_vconf_set_event_cb(VCONF_WIFI_STATUS, RUNTIME_INFO_KEY_WIFI_STATUS, 0);
73 }
74
75 void runtime_info_wifi_status_unset_event_cb()
76 {
77         runtime_info_vconf_unset_event_cb(VCONF_WIFI_STATUS, 0);
78 }
79
80 int runtime_info_bt_enabled_get_value(runtime_info_value_h value)
81 {
82         int vconf_value;
83         int ret;
84
85         ret = runtime_info_vconf_get_value_int(VCONF_BT_ENABLED, &vconf_value);
86         if (ret != RUNTIME_INFO_ERROR_NONE)
87                 return ret;
88
89         switch (vconf_value) {
90         case VCONFKEY_BT_STATUS_OFF:
91                 value->b = false;
92                 break;
93
94         case VCONFKEY_BT_STATUS_ON:
95         case VCONFKEY_BT_STATUS_BT_VISIBLE:
96         case VCONFKEY_BT_STATUS_TRANSFER:
97                 value->b = true;
98                 break;
99
100         default:
101                 return RUNTIME_INFO_ERROR_IO_ERROR;
102         }
103
104         return ret;
105 }
106
107 int runtime_info_bt_enabled_set_event_cb()
108 {
109         return runtime_info_vconf_set_event_cb(VCONF_BT_ENABLED, RUNTIME_INFO_KEY_BLUETOOTH_ENABLED, 0);
110 }
111
112 void runtime_info_bt_enabled_unset_event_cb()
113 {
114         runtime_info_vconf_unset_event_cb(VCONF_BT_ENABLED, 0);
115 }
116
117
118 int runtime_info_wifi_hotspot_get_value(runtime_info_value_h value)
119 {
120         int vconf_value;
121         int ret;
122
123         ret = runtime_info_vconf_get_value_int(VCONF_WIFI_HOTSPOT_ENABLED, &vconf_value);
124         if (ret == RUNTIME_INFO_ERROR_NONE)
125                 value->b = (vconf_value&VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) ? true : false;
126
127         return ret;
128 }
129
130 int runtime_info_wifi_hotspot_set_event_cb()
131 {
132         return runtime_info_vconf_set_event_cb(VCONF_WIFI_HOTSPOT_ENABLED, RUNTIME_INFO_KEY_WIFI_HOTSPOT_ENABLED, 0);
133 }
134
135 void runtime_info_wifi_hotspot_unset_event_cb()
136 {
137         runtime_info_vconf_unset_event_cb(VCONF_WIFI_HOTSPOT_ENABLED, 0);
138 }
139
140 int runtime_info_bt_hotspot_get_value(runtime_info_value_h value)
141 {
142         int vconf_value;
143         int ret;
144
145         ret = runtime_info_vconf_get_value_int(VCONF_BT_HOTSPOT_ENABLED, &vconf_value);
146         if (ret == RUNTIME_INFO_ERROR_NONE)
147                 value->b = (vconf_value&VCONFKEY_MOBILE_HOTSPOT_MODE_BT) ? true : false;
148
149         return ret;
150 }
151
152 int runtime_info_bt_hotspot_set_event_cb()
153 {
154         return runtime_info_vconf_set_event_cb(VCONF_BT_HOTSPOT_ENABLED, RUNTIME_INFO_KEY_BLUETOOTH_TETHERING_ENABLED, 0);
155 }
156
157 void runtime_info_bt_hotspot_unset_event_cb()
158 {
159         runtime_info_vconf_unset_event_cb(VCONF_BT_HOTSPOT_ENABLED, 0);
160 }
161
162 int runtime_info_usb_hotspot_get_value(runtime_info_value_h value)
163 {
164         int vconf_value;
165         int ret;
166
167         ret = runtime_info_vconf_get_value_int(VCONF_USB_HOTSPOT_ENABLED, &vconf_value);
168         if (ret == RUNTIME_INFO_ERROR_NONE)
169                 value->b = (vconf_value&VCONFKEY_MOBILE_HOTSPOT_MODE_USB) ? true : false;
170
171         return ret;
172 }
173
174 int runtime_info_usb_hotspot_set_event_cb()
175 {
176         return runtime_info_vconf_set_event_cb(VCONF_USB_HOTSPOT_ENABLED, RUNTIME_INFO_KEY_USB_TETHERING_ENABLED, 0);
177 }
178
179 void runtime_info_usb_hotspot_unset_event_cb()
180 {
181         runtime_info_vconf_unset_event_cb(VCONF_USB_HOTSPOT_ENABLED, 0);
182 }
183
184 int runtime_info_packet_data_get_value(runtime_info_value_h value)
185 {
186         int vconf_value;
187         int ret;
188
189         ret = runtime_info_vconf_get_value_bool(VCONF_PACKET_DATA_ENABLED, &vconf_value);
190         if (ret == RUNTIME_INFO_ERROR_NONE)
191                 value->b = (bool)vconf_value;
192
193         return ret;
194 }
195
196 int runtime_info_packet_data_set_event_cb()
197 {
198         return runtime_info_vconf_set_event_cb(VCONF_PACKET_DATA_ENABLED, RUNTIME_INFO_KEY_PACKET_DATA_ENABLED, 0);
199 }
200
201 void runtime_info_packet_data_unset_event_cb()
202 {
203         runtime_info_vconf_unset_event_cb(VCONF_PACKET_DATA_ENABLED, 0);
204 }
205
206 int runtime_info_data_roaming_get_value(runtime_info_value_h value)
207 {
208         int vconf_value;
209         int ret;
210
211         ret = runtime_info_vconf_get_value_bool(VCONF_DATA_ROAMING_ENABLED, &vconf_value);
212         if (ret == RUNTIME_INFO_ERROR_NONE)
213                 value->b = (bool)vconf_value;
214
215         return ret;
216 }
217
218 int runtime_info_data_roaming_set_event_cb()
219 {
220         return runtime_info_vconf_set_event_cb(VCONF_DATA_ROAMING_ENABLED, RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED, 0);
221 }
222
223 void runtime_info_data_roaming_unset_event_cb()
224 {
225         runtime_info_vconf_unset_event_cb(VCONF_DATA_ROAMING_ENABLED, 0);
226 }
227
228 int runtime_info_gps_status_get_value(runtime_info_value_h value)
229 {
230         int vconf_value;
231         int ret;
232
233         ret = runtime_info_vconf_get_value_int(VCONF_GPS_STATUS, &vconf_value);
234         if (ret != RUNTIME_INFO_ERROR_NONE)
235                 return ret;
236
237         switch (vconf_value) {
238         case VCONFKEY_LOCATION_GPS_OFF:
239                 value->i = RUNTIME_INFO_GPS_STATUS_DISABLED;
240                 break;
241
242         case VCONFKEY_LOCATION_GPS_SEARCHING:
243                 value->i = RUNTIME_INFO_GPS_STATUS_SEARCHING;
244                 break;
245
246         case VCONFKEY_LOCATION_GPS_CONNECTED:
247                 value->i = RUNTIME_INFO_GPS_STATUS_CONNECTED;
248                 break;
249
250         default:
251                 return RUNTIME_INFO_ERROR_IO_ERROR;
252         }
253
254         return ret;
255 }
256
257 int runtime_info_gps_status_set_event_cb()
258 {
259         return runtime_info_vconf_set_event_cb(VCONF_GPS_STATUS, RUNTIME_INFO_KEY_GPS_STATUS, 0);
260 }
261
262 void runtime_info_gps_status_unset_event_cb()
263 {
264         runtime_info_vconf_unset_event_cb(VCONF_GPS_STATUS, 0);
265 }
266