Add lcov comments for coverage measurement
[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_BT_ENABLED = VCONFKEY_BT_STATUS;
34 static const char *VCONF_WIFI_HOTSPOT_ENABLED = VCONFKEY_MOBILE_HOTSPOT_MODE;
35 static const char *VCONF_BT_HOTSPOT_ENABLED = VCONFKEY_MOBILE_HOTSPOT_MODE;
36 static const char *VCONF_USB_HOTSPOT_ENABLED = VCONFKEY_MOBILE_HOTSPOT_MODE;
37 static const char *VCONF_PACKET_DATA_ENABLED = VCONFKEY_3G_ENABLE;
38 static const char *VCONF_DATA_ROAMING_ENABLED = VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL;
39 static const char *VCONF_GPS_STATUS = VCONFKEY_LOCATION_GPS_STATE;
40
41 int runtime_info_bt_enabled_get_value(runtime_info_value_h value)
42 {
43         int vconf_value;
44         int ret;
45
46         ret = runtime_info_vconf_get_value_int(VCONF_BT_ENABLED, &vconf_value);
47         if (ret != RUNTIME_INFO_ERROR_NONE)
48                 return ret;
49
50         switch (vconf_value) {
51         case VCONFKEY_BT_STATUS_OFF:
52                 value->b = false;
53                 break;
54
55         case VCONFKEY_BT_STATUS_ON:
56         case VCONFKEY_BT_STATUS_BT_VISIBLE:
57         case VCONFKEY_BT_STATUS_TRANSFER:
58                 value->b = true;
59                 break;
60
61         default:
62                 return RUNTIME_INFO_ERROR_IO_ERROR;
63         }
64
65         return ret;
66 }
67
68 int runtime_info_bt_enabled_set_event_cb()
69 {
70         return runtime_info_vconf_set_event_cb(VCONF_BT_ENABLED, RUNTIME_INFO_KEY_BLUETOOTH_ENABLED, 0);
71 }
72
73 void runtime_info_bt_enabled_unset_event_cb()
74 {
75         runtime_info_vconf_unset_event_cb(VCONF_BT_ENABLED, 0);
76 }
77
78
79 int runtime_info_wifi_hotspot_get_value(runtime_info_value_h value)
80 {
81         int vconf_value;
82         int ret;
83
84         ret = runtime_info_vconf_get_value_int(VCONF_WIFI_HOTSPOT_ENABLED, &vconf_value);
85         if (ret == RUNTIME_INFO_ERROR_NONE)
86                 value->b = (vconf_value&VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) ? true : false;
87
88         return ret;
89 }
90
91 int runtime_info_wifi_hotspot_set_event_cb()
92 {
93         return runtime_info_vconf_set_event_cb(VCONF_WIFI_HOTSPOT_ENABLED, RUNTIME_INFO_KEY_WIFI_HOTSPOT_ENABLED, 0);
94 }
95
96 void runtime_info_wifi_hotspot_unset_event_cb()
97 {
98         runtime_info_vconf_unset_event_cb(VCONF_WIFI_HOTSPOT_ENABLED, 0);
99 }
100
101 int runtime_info_bt_hotspot_get_value(runtime_info_value_h value)
102 {
103         int vconf_value;
104         int ret;
105
106         ret = runtime_info_vconf_get_value_int(VCONF_BT_HOTSPOT_ENABLED, &vconf_value);
107         if (ret == RUNTIME_INFO_ERROR_NONE)
108                 value->b = (vconf_value&VCONFKEY_MOBILE_HOTSPOT_MODE_BT) ? true : false;
109
110         return ret;
111 }
112
113 int runtime_info_bt_hotspot_set_event_cb()
114 {
115         return runtime_info_vconf_set_event_cb(VCONF_BT_HOTSPOT_ENABLED, RUNTIME_INFO_KEY_BLUETOOTH_TETHERING_ENABLED, 0);
116 }
117
118 void runtime_info_bt_hotspot_unset_event_cb()
119 {
120         runtime_info_vconf_unset_event_cb(VCONF_BT_HOTSPOT_ENABLED, 0);
121 }
122
123 int runtime_info_usb_hotspot_get_value(runtime_info_value_h value)
124 {
125         int vconf_value;
126         int ret;
127
128         ret = runtime_info_vconf_get_value_int(VCONF_USB_HOTSPOT_ENABLED, &vconf_value);
129         if (ret == RUNTIME_INFO_ERROR_NONE)
130                 value->b = (vconf_value&VCONFKEY_MOBILE_HOTSPOT_MODE_USB) ? true : false;
131
132         return ret;
133 }
134
135 int runtime_info_usb_hotspot_set_event_cb()
136 {
137         return runtime_info_vconf_set_event_cb(VCONF_USB_HOTSPOT_ENABLED, RUNTIME_INFO_KEY_USB_TETHERING_ENABLED, 0);
138 }
139
140 void runtime_info_usb_hotspot_unset_event_cb()
141 {
142         runtime_info_vconf_unset_event_cb(VCONF_USB_HOTSPOT_ENABLED, 0);
143 }
144
145 int runtime_info_packet_data_get_value(runtime_info_value_h value)
146 {
147         int vconf_value;
148         int ret;
149
150         ret = runtime_info_vconf_get_value_bool(VCONF_PACKET_DATA_ENABLED, &vconf_value);
151         if (ret == RUNTIME_INFO_ERROR_NONE)
152                 value->b = (bool)vconf_value;
153
154         return ret;
155 }
156
157 int runtime_info_packet_data_set_event_cb()
158 {
159         return runtime_info_vconf_set_event_cb(VCONF_PACKET_DATA_ENABLED, RUNTIME_INFO_KEY_PACKET_DATA_ENABLED, 0);
160 }
161
162 void runtime_info_packet_data_unset_event_cb()
163 {
164         runtime_info_vconf_unset_event_cb(VCONF_PACKET_DATA_ENABLED, 0);
165 }
166
167 int runtime_info_data_roaming_get_value(runtime_info_value_h value)
168 {
169         int vconf_value;
170         int ret;
171
172         ret = runtime_info_vconf_get_value_bool(VCONF_DATA_ROAMING_ENABLED, &vconf_value);
173         if (ret == RUNTIME_INFO_ERROR_NONE)
174                 value->b = (bool)vconf_value;
175
176         return ret;
177 }
178
179 int runtime_info_data_roaming_set_event_cb()
180 {
181         return runtime_info_vconf_set_event_cb(VCONF_DATA_ROAMING_ENABLED, RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED, 0);
182 }
183
184 void runtime_info_data_roaming_unset_event_cb()
185 {
186         runtime_info_vconf_unset_event_cb(VCONF_DATA_ROAMING_ENABLED, 0);
187 }
188
189 int runtime_info_gps_status_get_value(runtime_info_value_h value)
190 {
191         int vconf_value;
192         int ret;
193
194         ret = runtime_info_vconf_get_value_int(VCONF_GPS_STATUS, &vconf_value);
195         if (ret != RUNTIME_INFO_ERROR_NONE)
196                 return ret;
197
198         switch (vconf_value) {
199         case VCONFKEY_LOCATION_GPS_OFF:
200                 value->i = RUNTIME_INFO_GPS_STATUS_DISABLED;
201                 break;
202
203         case VCONFKEY_LOCATION_GPS_SEARCHING:
204                 value->i = RUNTIME_INFO_GPS_STATUS_SEARCHING;
205                 break;
206
207         case VCONFKEY_LOCATION_GPS_CONNECTED:
208                 value->i = RUNTIME_INFO_GPS_STATUS_CONNECTED;
209                 break;
210
211         default:
212                 return RUNTIME_INFO_ERROR_IO_ERROR;
213         }
214
215         return ret;
216 }
217
218 int runtime_info_gps_status_set_event_cb()
219 {
220         return runtime_info_vconf_set_event_cb(VCONF_GPS_STATUS, RUNTIME_INFO_KEY_GPS_STATUS, 0);
221 }
222
223 void runtime_info_gps_status_unset_event_cb()
224 {
225         runtime_info_vconf_unset_event_cb(VCONF_GPS_STATUS, 0);
226 }
227