removed log messages from process usage info APIs
[platform/core/api/runtime-info.git] / src / runtime_info_system.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_AUDIO_JACK = VCONFKEY_SYSMAN_EARJACK;
34 static const char *VCONF_VIBRATION_ENABLED = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL;
35 static const char *VCONF_ROTATION_LOCK_ENABLED = VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL;
36 static const char *VCONF_BATTERY_CHARGING = VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW;
37 static const char *VCONF_TVOUT_CONNECTED = VCONFKEY_SYSMAN_EARJACK;
38 static const char *VCONF_AUDIO_JACK_STATUS = VCONFKEY_SYSMAN_EARJACK;
39 static const char *VCONF_USB_CONNECTED = VCONFKEY_SYSMAN_USB_STATUS;
40 static const char *VCONF_CHARGER_CONNECTED = VCONFKEY_SYSMAN_CHARGER_STATUS;
41
42
43 int runtime_info_audiojack_get_value(runtime_info_value_h value)
44 {
45         int vconf_value;
46         int ret;
47
48         ret = runtime_info_vconf_get_value_int(VCONF_AUDIO_JACK, &vconf_value);
49         if (ret != RUNTIME_INFO_ERROR_NONE)
50                 return ret;
51
52         switch (vconf_value) {
53         case VCONFKEY_SYSMAN_EARJACK_3WIRE:
54         case VCONFKEY_SYSMAN_EARJACK_4WIRE:
55                 value->b = true;
56                 break;
57
58         default:
59                 value->b = false;
60                 break;
61         }
62
63         return ret;
64 }
65
66 int runtime_info_audiojack_set_event_cb(void)
67 {
68         return runtime_info_vconf_set_event_cb(VCONF_AUDIO_JACK, RUNTIME_INFO_KEY_AUDIO_JACK_CONNECTED, 0);
69 }
70
71 void runtime_info_audiojack_unset_event_cb(void)
72 {
73         runtime_info_vconf_unset_event_cb(VCONF_AUDIO_JACK, 0);
74 }
75
76 int runtime_info_vibration_enabled_get_value(runtime_info_value_h value)
77 {
78         int vconf_value;
79         int ret;
80
81         ret = runtime_info_vconf_get_value_bool(VCONF_VIBRATION_ENABLED, &vconf_value);
82         if (ret == RUNTIME_INFO_ERROR_NONE)
83                 value->b = (bool)vconf_value;
84
85         return ret;
86 }
87
88 int runtime_info_vibration_enabled_set_event_cb(void)
89 {
90         return runtime_info_vconf_set_event_cb(VCONF_VIBRATION_ENABLED, RUNTIME_INFO_KEY_VIBRATION_ENABLED, 0);
91 }
92
93 void runtime_info_vibration_enabled_unset_event_cb(void)
94 {
95         runtime_info_vconf_unset_event_cb(VCONF_VIBRATION_ENABLED, 0);
96 }
97
98 int runtime_info_auto_rotation_enabled_get_value(runtime_info_value_h value)
99 {
100         int vconf_value;
101         int ret;
102
103         ret = runtime_info_vconf_get_value_bool(VCONF_ROTATION_LOCK_ENABLED, &vconf_value);
104         if (ret == RUNTIME_INFO_ERROR_NONE)
105                 value->b = (bool)vconf_value;
106
107         return ret;
108 }
109
110 int runtime_info_auto_rotation_enabled_set_event_cb(void)
111 {
112         return runtime_info_vconf_set_event_cb(VCONF_ROTATION_LOCK_ENABLED, RUNTIME_INFO_KEY_AUTO_ROTATION_ENABLED, 0);
113 }
114
115 void runtime_info_auto_rotation_enabled_unset_event_cb(void)
116 {
117         runtime_info_vconf_unset_event_cb(VCONF_ROTATION_LOCK_ENABLED, 0);
118 }
119
120 int runtime_info_battery_charging_get_value(runtime_info_value_h value)
121 {
122         int vconf_value;
123         int ret;
124
125         ret = runtime_info_vconf_get_value_int(VCONF_BATTERY_CHARGING, &vconf_value);
126         if (ret == RUNTIME_INFO_ERROR_NONE)
127                 value->b = vconf_value;
128
129         return ret;
130 }
131
132 int runtime_info_battery_charging_set_event_cb(void)
133 {
134         return runtime_info_vconf_set_event_cb(VCONF_BATTERY_CHARGING, RUNTIME_INFO_KEY_BATTERY_IS_CHARGING, 0);
135 }
136
137 void runtime_info_battery_charging_unset_event_cb(void)
138 {
139         runtime_info_vconf_unset_event_cb(VCONF_BATTERY_CHARGING, 0);
140 }
141
142
143 int runtime_info_tvout_connected_get_value(runtime_info_value_h value)
144 {
145         int vconf_value;
146         int ret;
147
148         ret = runtime_info_vconf_get_value_int(VCONF_TVOUT_CONNECTED, &vconf_value);
149         if (ret != RUNTIME_INFO_ERROR_NONE)
150                 return ret;
151
152         switch (vconf_value) {
153         case VCONFKEY_SYSMAN_EARJACK_TVOUT:
154                 value->b = true;
155                 break;
156
157         default:
158                 value->b = false;
159                 break;
160         }
161
162         return ret;
163 }
164
165 int runtime_info_tvout_connected_set_event_cb(void)
166 {
167         return runtime_info_vconf_set_event_cb(VCONF_TVOUT_CONNECTED, RUNTIME_INFO_KEY_TV_OUT_CONNECTED, 1);
168 }
169
170 void runtime_info_tvout_connected_unset_event_cb(void)
171 {
172         runtime_info_vconf_unset_event_cb(VCONF_TVOUT_CONNECTED, 1);
173 }
174
175
176 int runtime_info_audio_jack_status_get_value(runtime_info_value_h value)
177 {
178         int vconf_value;
179         int ret;
180
181         ret = runtime_info_vconf_get_value_int(VCONF_AUDIO_JACK_STATUS, &vconf_value);
182         if (ret != RUNTIME_INFO_ERROR_NONE)
183                 return ret;
184
185         switch (vconf_value) {
186         case VCONFKEY_SYSMAN_EARJACK_3WIRE:
187                 value->i = RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_3WIRE;
188                 break;
189
190         case VCONFKEY_SYSMAN_EARJACK_4WIRE:
191                 value->i = RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_4WIRE;
192                 break;
193
194         default:
195                 value->i = RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED;
196                 break;
197         }
198
199         return ret;
200 }
201
202 int runtime_info_audio_jack_status_set_event_cb(void)
203 {
204         return runtime_info_vconf_set_event_cb(VCONF_AUDIO_JACK_STATUS, RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, 2);
205 }
206
207 void runtime_info_audio_jack_status_unset_event_cb(void)
208 {
209         runtime_info_vconf_unset_event_cb(VCONF_AUDIO_JACK_STATUS, 2);
210 }
211
212 int runtime_info_usb_connected_get_value(runtime_info_value_h value)
213 {
214         int vconf_value;
215         int ret;
216
217         ret = runtime_info_vconf_get_value_int(VCONF_USB_CONNECTED, &vconf_value);
218         if (ret != RUNTIME_INFO_ERROR_NONE)
219                 return ret;
220
221         switch (vconf_value) {
222         case VCONFKEY_SYSMAN_USB_DISCONNECTED:
223                 value->b = false;
224                 break;
225
226         case VCONFKEY_SYSMAN_USB_CONNECTED:
227                 value->b = false;
228                 break;
229
230         case VCONFKEY_SYSMAN_USB_AVAILABLE:
231                 value->b = true;
232                 break;
233
234         default:
235                 return RUNTIME_INFO_ERROR_IO_ERROR;
236         }
237
238         return ret;
239 }
240
241 int runtime_info_usb_connected_set_event_cb(void)
242 {
243         return runtime_info_vconf_set_event_cb(VCONF_USB_CONNECTED, RUNTIME_INFO_KEY_USB_CONNECTED, 0);
244 }
245
246 void runtime_info_usb_connected_unset_event_cb(void)
247 {
248         runtime_info_vconf_unset_event_cb(VCONF_USB_CONNECTED, 0);
249 }
250
251 int runtime_info_charger_connected_get_value(runtime_info_value_h value)
252 {
253         int vconf_value;
254         int ret;
255
256         ret = runtime_info_vconf_get_value_int(VCONF_CHARGER_CONNECTED, &vconf_value);
257         if (ret != RUNTIME_INFO_ERROR_NONE)
258                 return ret;
259
260         switch (vconf_value) {
261         case VCONFKEY_SYSMAN_CHARGER_DISCONNECTED:
262                 value->b = false;
263                 break;
264
265         case VCONFKEY_SYSMAN_CHARGER_CONNECTED:
266                 value->b = true;
267                 break;
268
269         default:
270                 return RUNTIME_INFO_ERROR_IO_ERROR;
271         }
272
273         return ret;
274 }
275
276 int runtime_info_charger_connected_set_event_cb(void)
277 {
278         return runtime_info_vconf_set_event_cb(VCONF_CHARGER_CONNECTED, RUNTIME_INFO_KEY_CHARGER_CONNECTED, 0);
279 }
280
281 void runtime_info_charger_connected_unset_event_cb(void)
282 {
283         runtime_info_vconf_unset_event_cb(VCONF_CHARGER_CONNECTED, 0);
284 }