error type: add error type RUNTIME_INFO_ERROR_NOT_SUPPORTED
[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_FLIGHT_MODE = VCONFKEY_TELEPHONY_FLIGHT_MODE;
34 static const char *VCONF_AUDIO_JACK = VCONFKEY_SYSMAN_EARJACK;
35 static const char *VCONF_SOUND_ENABLED = VCONFKEY_SETAPPL_SOUND_STATUS_BOOL;
36 static const char *VCONF_VIBRATION_ENABLED = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL;
37 static const char *VCONF_ROTATION_LOCK_ENABLED = VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL;
38 static const char *VCONF_BATTERY_CHARGING = VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW;
39 static const char *VCONF_TVOUT_CONNECTED = VCONFKEY_SYSMAN_EARJACK;
40 static const char *VCONF_AUDIO_JACK_STATUS = VCONFKEY_SYSMAN_EARJACK;
41 static const char *VCONF_SLIDING_KEYBOARD_STATUS = VCONFKEY_SYSMAN_SLIDING_KEYBOARD;
42 static const char *VCONF_USB_CONNECTED = VCONFKEY_SYSMAN_USB_STATUS;
43 static const char *VCONF_CHARGER_CONNECTED = VCONFKEY_SYSMAN_CHARGER_STATUS;
44
45
46 int runtime_info_flightmode_get_value(runtime_info_value_h value)
47 {
48         int vconf_value;
49
50         if (runtime_info_vconf_get_value_bool(VCONF_FLIGHT_MODE, &vconf_value))
51                 vconf_value = 0;
52
53         value->b = (bool)vconf_value;
54
55         return RUNTIME_INFO_ERROR_NONE;
56 }
57
58 int runtime_info_flightmode_set_event_cb(void)
59 {
60         return runtime_info_vconf_set_event_cb(VCONF_FLIGHT_MODE, RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED, 0);
61 }
62
63 void runtime_info_flightmode_unset_event_cb(void)
64 {
65         runtime_info_vconf_unset_event_cb(VCONF_FLIGHT_MODE, 0);
66 }
67
68 int runtime_info_audiojack_get_value(runtime_info_value_h value)
69 {
70         int vconf_value;
71         int ret;
72
73         ret = runtime_info_vconf_get_value_int(VCONF_AUDIO_JACK, &vconf_value);
74         if (ret != RUNTIME_INFO_ERROR_NONE)
75                 return ret;
76
77         switch (vconf_value) {
78         case VCONFKEY_SYSMAN_EARJACK_3WIRE:
79         case VCONFKEY_SYSMAN_EARJACK_4WIRE:
80                 value->b = true;
81                 break;
82
83         default:
84                 value->b = false;
85                 break;
86         }
87
88         return ret;
89 }
90
91 int runtime_info_audiojack_set_event_cb(void)
92 {
93         return runtime_info_vconf_set_event_cb(VCONF_AUDIO_JACK, RUNTIME_INFO_KEY_AUDIO_JACK_CONNECTED, 0);
94 }
95
96 void runtime_info_audiojack_unset_event_cb(void)
97 {
98         runtime_info_vconf_unset_event_cb(VCONF_AUDIO_JACK, 0);
99 }
100
101 int runtime_info_silent_mode_get_value(runtime_info_value_h value)
102 {
103         int sound, vib;
104
105         if (runtime_info_vconf_get_value_bool(VCONF_SOUND_ENABLED, &sound))
106                 return RUNTIME_INFO_ERROR_IO_ERROR;
107
108         if (runtime_info_vconf_get_value_bool(VCONF_VIBRATION_ENABLED, &vib))
109                 return RUNTIME_INFO_ERROR_IO_ERROR;
110
111         if (sound == 0 && vib == 0)
112                 value->b = true;
113         else
114                 value->b = false;
115
116         return RUNTIME_INFO_ERROR_NONE;
117 }
118
119 int runtime_info_silent_mode_set_event_cb(void)
120 {
121         int ret;
122
123         ret = runtime_info_vconf_set_event_cb(VCONF_SOUND_ENABLED, RUNTIME_INFO_KEY_SILENT_MODE_ENABLED, 0);
124         if (ret != RUNTIME_INFO_ERROR_NONE)
125                 return ret;
126
127         ret = runtime_info_vconf_set_event_cb(VCONF_VIBRATION_ENABLED, RUNTIME_INFO_KEY_SILENT_MODE_ENABLED, 1);
128         if (ret != RUNTIME_INFO_ERROR_NONE)
129                 runtime_info_vconf_unset_event_cb(VCONF_SOUND_ENABLED, 0);
130
131         return ret;
132 }
133
134 void runtime_info_silent_mode_unset_event_cb(void)
135 {
136         runtime_info_vconf_unset_event_cb(VCONF_SOUND_ENABLED, 0);
137         runtime_info_vconf_unset_event_cb(VCONF_VIBRATION_ENABLED, 1);
138 }
139
140 int runtime_info_vibration_enabled_get_value(runtime_info_value_h value)
141 {
142         int vconf_value;
143         int ret;
144
145         ret = runtime_info_vconf_get_value_bool(VCONF_VIBRATION_ENABLED, &vconf_value);
146         if (ret == RUNTIME_INFO_ERROR_NONE)
147                 value->b = (bool)vconf_value;
148
149         return ret;
150 }
151
152 int runtime_info_vibration_enabled_set_event_cb(void)
153 {
154         return runtime_info_vconf_set_event_cb(VCONF_VIBRATION_ENABLED, RUNTIME_INFO_KEY_VIBRATION_ENABLED, 0);
155 }
156
157 void runtime_info_vibration_enabled_unset_event_cb(void)
158 {
159         runtime_info_vconf_unset_event_cb(VCONF_VIBRATION_ENABLED, 0);
160 }
161
162 int runtime_info_auto_rotation_enabled_get_value(runtime_info_value_h value)
163 {
164         int vconf_value;
165         int ret;
166
167         ret = runtime_info_vconf_get_value_bool(VCONF_ROTATION_LOCK_ENABLED, &vconf_value);
168         if (ret == RUNTIME_INFO_ERROR_NONE)
169                 value->b = (bool)vconf_value;
170
171         return ret;
172 }
173
174 int runtime_info_auto_rotation_enabled_set_event_cb(void)
175 {
176         return runtime_info_vconf_set_event_cb(VCONF_ROTATION_LOCK_ENABLED, RUNTIME_INFO_KEY_AUTO_ROTATION_ENABLED, 0);
177 }
178
179 void runtime_info_auto_rotation_enabled_unset_event_cb(void)
180 {
181         runtime_info_vconf_unset_event_cb(VCONF_ROTATION_LOCK_ENABLED, 0);
182 }
183
184 int runtime_info_battery_charging_get_value(runtime_info_value_h value)
185 {
186         int vconf_value;
187         int ret;
188
189         ret = runtime_info_vconf_get_value_int(VCONF_BATTERY_CHARGING, &vconf_value);
190         if (ret == RUNTIME_INFO_ERROR_NONE)
191                 value->b = vconf_value;
192
193         return ret;
194 }
195
196 int runtime_info_battery_charging_set_event_cb(void)
197 {
198         return runtime_info_vconf_set_event_cb(VCONF_BATTERY_CHARGING, RUNTIME_INFO_KEY_BATTERY_IS_CHARGING, 0);
199 }
200
201 void runtime_info_battery_charging_unset_event_cb(void)
202 {
203         runtime_info_vconf_unset_event_cb(VCONF_BATTERY_CHARGING, 0);
204 }
205
206
207 int runtime_info_tvout_connected_get_value(runtime_info_value_h value)
208 {
209         int vconf_value;
210         int ret;
211
212         ret = runtime_info_vconf_get_value_int(VCONF_TVOUT_CONNECTED, &vconf_value);
213         if (ret != RUNTIME_INFO_ERROR_NONE)
214                 return ret;
215
216         switch (vconf_value) {
217         case VCONFKEY_SYSMAN_EARJACK_TVOUT:
218                 value->b = true;
219                 break;
220
221         default:
222                 value->b = false;
223                 break;
224         }
225
226         return ret;
227 }
228
229 int runtime_info_tvout_connected_set_event_cb(void)
230 {
231         return runtime_info_vconf_set_event_cb(VCONF_TVOUT_CONNECTED, RUNTIME_INFO_KEY_TV_OUT_CONNECTED, 1);
232 }
233
234 void runtime_info_tvout_connected_unset_event_cb(void)
235 {
236         runtime_info_vconf_unset_event_cb(VCONF_TVOUT_CONNECTED, 1);
237 }
238
239
240 int runtime_info_audio_jack_status_get_value(runtime_info_value_h value)
241 {
242         int vconf_value;
243         int ret;
244
245         ret = runtime_info_vconf_get_value_int(VCONF_AUDIO_JACK_STATUS, &vconf_value);
246         if (ret != RUNTIME_INFO_ERROR_NONE)
247                 return ret;
248
249         switch (vconf_value) {
250         case VCONFKEY_SYSMAN_EARJACK_3WIRE:
251                 value->i = RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_3WIRE;
252                 break;
253
254         case VCONFKEY_SYSMAN_EARJACK_4WIRE:
255                 value->i = RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_4WIRE;
256                 break;
257
258         default:
259                 value->i = RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED;
260                 break;
261         }
262
263         return ret;
264 }
265
266 int runtime_info_audio_jack_status_set_event_cb(void)
267 {
268         return runtime_info_vconf_set_event_cb(VCONF_AUDIO_JACK_STATUS, RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, 2);
269 }
270
271 void runtime_info_audio_jack_status_unset_event_cb(void)
272 {
273         runtime_info_vconf_unset_event_cb(VCONF_AUDIO_JACK_STATUS, 2);
274 }
275
276
277 int runtime_info_sliding_keyboard_opened_get_value(runtime_info_value_h value)
278 {
279         int vconf_value;
280
281         if (runtime_info_vconf_get_value_int(VCONF_SLIDING_KEYBOARD_STATUS, &vconf_value))
282                 vconf_value = VCONFKEY_SYSMAN_SLIDING_KEYBOARD_NOT_SUPPORTED;
283
284         switch (vconf_value) {
285         case VCONFKEY_SYSMAN_SLIDING_KEYBOARD_NOT_AVAILABE:
286                 value->b = false;
287                 break;
288
289         case VCONFKEY_SYSMAN_SLIDING_KEYBOAED_AVAILABLE:
290                 value->b = true;
291                 break;
292
293         case VCONFKEY_SYSMAN_SLIDING_KEYBOARD_NOT_SUPPORTED:
294                 value->b = false;
295                 break;
296
297         default:
298                 return RUNTIME_INFO_ERROR_IO_ERROR;
299         }
300
301         return RUNTIME_INFO_ERROR_NONE;
302 }
303
304 int runtime_info_sliding_keyboard_opened_set_event_cb(void)
305 {
306         return runtime_info_vconf_set_event_cb(VCONF_SLIDING_KEYBOARD_STATUS, RUNTIME_INFO_KEY_SLIDING_KEYBOARD_OPENED, 0);
307 }
308
309 void runtime_info_sliding_keyboard_opened_unset_event_cb(void)
310 {
311         runtime_info_vconf_unset_event_cb(VCONF_SLIDING_KEYBOARD_STATUS, 0);
312 }
313
314
315 int runtime_info_usb_connected_get_value(runtime_info_value_h value)
316 {
317         int vconf_value;
318         int ret;
319
320         ret = runtime_info_vconf_get_value_int(VCONF_USB_CONNECTED, &vconf_value);
321         if (ret != RUNTIME_INFO_ERROR_NONE)
322                 return ret;
323
324         switch (vconf_value) {
325         case VCONFKEY_SYSMAN_USB_DISCONNECTED:
326                 value->b = false;
327                 break;
328
329         case VCONFKEY_SYSMAN_USB_CONNECTED:
330                 value->b = false;
331                 break;
332
333         case VCONFKEY_SYSMAN_USB_AVAILABLE:
334                 value->b = true;
335                 break;
336
337         default:
338                 return RUNTIME_INFO_ERROR_IO_ERROR;
339         }
340
341         return ret;
342 }
343
344 int runtime_info_usb_connected_set_event_cb(void)
345 {
346         return runtime_info_vconf_set_event_cb(VCONF_USB_CONNECTED, RUNTIME_INFO_KEY_USB_CONNECTED, 0);
347 }
348
349 void runtime_info_usb_connected_unset_event_cb(void)
350 {
351         runtime_info_vconf_unset_event_cb(VCONF_USB_CONNECTED, 0);
352 }
353
354 int runtime_info_charger_connected_get_value(runtime_info_value_h value)
355 {
356         int vconf_value;
357         int ret;
358
359         ret = runtime_info_vconf_get_value_int(VCONF_CHARGER_CONNECTED, &vconf_value);
360         if (ret != RUNTIME_INFO_ERROR_NONE)
361                 return ret;
362
363         switch (vconf_value) {
364         case VCONFKEY_SYSMAN_CHARGER_DISCONNECTED:
365                 value->b = false;
366                 break;
367
368         case VCONFKEY_SYSMAN_CHARGER_CONNECTED:
369                 value->b = true;
370                 break;
371
372         default:
373                 return RUNTIME_INFO_ERROR_IO_ERROR;
374         }
375
376         return ret;
377 }
378
379 int runtime_info_charger_connected_set_event_cb(void)
380 {
381         return runtime_info_vconf_set_event_cb(VCONF_CHARGER_CONNECTED, RUNTIME_INFO_KEY_CHARGER_CONNECTED, 0);
382 }
383
384 void runtime_info_charger_connected_unset_event_cb(void)
385 {
386         runtime_info_vconf_unset_event_cb(VCONF_CHARGER_CONNECTED, 0);
387 }
388
389
390 int runtime_info_vibration_level_haptic_feedback_get_value(runtime_info_value_h value)
391 {
392         int vconf_value;
393
394         if (runtime_info_vconf_get_value_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &vconf_value))
395                 return RUNTIME_INFO_ERROR_IO_ERROR;
396
397         value->i = vconf_value;
398
399         return RUNTIME_INFO_ERROR_NONE;
400 }
401
402 int runtime_info_vibration_level_haptic_feedback_set_event_cb(void)
403 {
404         return runtime_info_vconf_set_event_cb(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, RUNTIME_INFO_KEY_VIBRATION_LEVEL_HAPTIC_FEEDBACK, 0);
405 }
406
407 void runtime_info_vibration_level_haptic_feedback_unset_event_cb(void)
408 {
409         runtime_info_vconf_unset_event_cb(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, 0);
410 }
411
412