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