2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include <system_settings.h>
25 #include <system_settings_private.h>
31 #define LOG_TAG "TIZEN_N_SYSTEM_SETTINGS"
33 static char *_system_settings_vconf_table[] = {
34 VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR,
36 VCONFKEY_IDLE_LOCK_BGSET,
37 VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE,
38 VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME,
39 VCONFKEY_SETAPPL_MOTION_ACTIVATION,
40 VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR,
41 VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL,
44 VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR,
46 VCONFKEY_REGIONFORMAT,
48 VCONFKEY_REGIONFORMAT_TIME1224,
49 VCONFKEY_SETAPPL_TIMEZONE_ID,
50 VCONFKEY_SYSTEM_TIME_CHANGED,
51 VCONFKEY_SETAPPL_SOUND_LOCK_BOOL,
52 VCONFKEY_SETAPPL_SOUND_STATUS_BOOL,
53 VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL,
54 VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL,
55 VCONFKEY_SETAPPL_DEVICE_NAME_STR,
56 VCONFKEY_SETAPPL_MOTION_ACTIVATION,
57 VCONFKEY_WIFI_ENABLE_QS,
58 VCONFKEY_TELEPHONY_FLIGHT_MODE,
59 VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL,
60 VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR,
61 VCONFKEY_SETAPPL_NOTI_MSG_ALERT_REP_TYPE_INT,
62 VCONFKEY_IDLE_LOCK_STATE_READ_ONLY,
63 VCONFKEY_SETAPPL_AD_ID,
64 VCONFKEY_SETAPPL_UDSM,
65 VCONFKEY_SETAPPL_UDSM_PKGID_LIST,
66 VCONFKEY_SETAPPL_ACCESSIBILITY_TTS,
67 VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL,
68 VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL,
69 VCONFKEY_SETAPPL_DEVELOPER_OPTION_STATE,
73 int system_setting_vconf_get_value_int(const char *vconf_key, int *value)
75 return vconf_get_int(vconf_key, value);
78 int system_setting_vconf_get_value_bool(const char *vconf_key, bool *value)
81 int ret = vconf_get_bool(vconf_key, &tempvalue);
91 int system_setting_vconf_get_value_string(const char *vconf_key, char **value)
93 char *str_value = NULL;
95 str_value = vconf_get_str(vconf_key);
97 if (str_value != NULL) {
105 int system_setting_vconf_set_value_int(const char *vconf_key, int value)
107 return vconf_set_int(vconf_key, value);
110 int system_setting_vconf_set_value_bool(const char *vconf_key, bool value)
112 return vconf_set_bool(vconf_key, (int)value);
115 int system_setting_vconf_set_value_string(const char *vconf_key, char *value)
117 return vconf_set_str(vconf_key, value);
120 /*/////////////////////////////////////////////////////////////////////////////////////////// */
122 typedef void (*system_setting_vconf_event_cb)(keynode_t *node, void *event_data);
124 /* LCOV_EXCL_START */
125 static void system_setting_vconf_event_cb0(keynode_t *node, void *event_data)
127 system_settings_key_e pkey = (system_settings_key_e)event_data;
130 system_setting_h system_setting_item;
132 int ret = system_settings_get_item(pkey, &system_setting_item);
134 if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
135 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
138 void *user_data = NULL;
139 user_data = system_setting_item->user_data;
140 system_setting_item->changed_cb(pkey, user_data);
145 /* LCOV_EXCL_START */
146 static void system_setting_vconf_event_cb1(keynode_t *node, void *event_data)
148 system_settings_key_e pkey = (system_settings_key_e)event_data;
151 system_setting_h system_setting_item;
153 int ret = system_settings_get_item(pkey, &system_setting_item);
155 if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
156 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
159 void *user_data = NULL;
160 user_data = system_setting_item->user_data;
161 system_setting_item->changed_cb(pkey, user_data);
166 /* LCOV_EXCL_START */
167 static void system_setting_vconf_event_cb2(keynode_t *node, void *event_data)
169 system_settings_key_e pkey = (system_settings_key_e)event_data;
172 system_setting_h system_setting_item;
174 int ret = system_settings_get_item(pkey, &system_setting_item);
176 if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
177 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
180 void *user_data = NULL;
181 user_data = system_setting_item->user_data;
182 system_setting_item->changed_cb(pkey, user_data);
187 /* LCOV_EXCL_START */
188 static void system_setting_vconf_event_cb3(keynode_t *node, void *event_data)
190 system_settings_key_e pkey = (system_settings_key_e)event_data;
193 system_setting_h system_setting_item;
195 int ret = system_settings_get_item(pkey, &system_setting_item);
197 if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
198 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
201 void *user_data = NULL;
202 user_data = system_setting_item->user_data;
203 system_setting_item->changed_cb(pkey, user_data);
208 /* LCOV_EXCL_START */
209 static void system_setting_vconf_event_cb4(keynode_t *node, void *event_data)
211 system_settings_key_e pkey = (system_settings_key_e)event_data;
214 system_setting_h system_setting_item;
216 int ret = system_settings_get_item(pkey, &system_setting_item);
218 if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
219 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
222 void *user_data = NULL;
223 user_data = system_setting_item->user_data;
224 system_setting_item->changed_cb(pkey, user_data);
229 /* LCOV_EXCL_START */
230 static void system_setting_vconf_event_cb100(keynode_t *node, void *event_data)
232 system_settings_key_e pkey = (system_settings_key_e)event_data;
235 system_setting_h system_setting_item;
237 int ret = system_settings_get_item(pkey, &system_setting_item);
239 if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
240 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
243 void *user_data = NULL;
244 user_data = system_setting_item->user_data;
245 system_setting_item->changed_cb(pkey, user_data);
251 /* LCOV_EXCL_START */
252 static system_setting_vconf_event_cb system_setting_vconf_get_event_cb_slot(int slot)
256 return system_setting_vconf_event_cb0;
259 return system_setting_vconf_event_cb1;
262 return system_setting_vconf_event_cb2;
265 return system_setting_vconf_event_cb3;
268 return system_setting_vconf_event_cb4;
270 return system_setting_vconf_event_cb100;
278 int system_setting_vconf_set_changed_cb(const char *vconf_key, system_settings_key_e key, int slot, void *user_data)
280 system_setting_vconf_event_cb vconf_event_cb;
282 vconf_event_cb = system_setting_vconf_get_event_cb_slot(slot);
284 if (vconf_event_cb == NULL) {
285 LOGE("[%s] INVALID_error , %s", __FUNCTION__, "vconf_event_cb == 0");
286 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
290 if (vconf_notify_key_changed(vconf_key, vconf_event_cb, (void *)key))
292 if (vconf_notify_key_changed(vconf_key, vconf_event_cb, (void *)user_data))
295 LOGE("[%s] INVALID_error , %s", __FUNCTION__, "vconf_notify_key_changed error");
296 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
299 return SYSTEM_SETTINGS_ERROR_NONE;
302 int system_setting_vconf_unset_changed_cb(const char *vconf_key, int slot)
304 system_setting_vconf_event_cb vconf_event_cb;
306 vconf_event_cb = system_setting_vconf_get_event_cb_slot(slot);
308 if (vconf_event_cb != NULL) {
309 vconf_ignore_key_changed(vconf_key, vconf_event_cb);
312 return SYSTEM_SETTINGS_ERROR_NONE;
315 int system_settings_vconf_get_key_string(system_settings_key_e key, char **key_string)
317 if (key == SYSTEM_SETTINGS_KEY_DEFAULT_FONT_TYPE) {
318 *key_string = NULL; /* Not Supported changed callback*/
319 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
322 *key_string = _system_settings_vconf_table[(int)key];
324 if (*key_string == NULL)
325 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
327 return SYSTEM_SETTINGS_ERROR_NONE;
330 static void system_setting_vconf_event_multi_cb(keynode_t *node, void *event_data)
332 LOGE("Enter [%s]", __FUNCTION__);
333 system_settings_key_e pkey = (system_settings_key_e)event_data;
336 system_setting_h system_setting_item;
338 int ret = system_settings_get_item(pkey, &system_setting_item);
340 if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
341 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
344 invoke_callback_list(&system_setting_item->changed_cb_list, pkey);
346 LOGE("Leave [%s]", __FUNCTION__);
349 /* LCOV_EXCL_START */
350 static void system_setting_vconf_event_multi_cb_slot_0(keynode_t *node, void *event_data)
352 system_setting_vconf_event_multi_cb(node, event_data);
356 /* LCOV_EXCL_START */
357 static void system_setting_vconf_event_multi_cb_slot_1(keynode_t *node, void *event_data)
359 system_setting_vconf_event_multi_cb(node, event_data);
363 /* LCOV_EXCL_START */
364 static void system_setting_vconf_event_multi_cb_slot_2(keynode_t *node, void *event_data)
366 system_setting_vconf_event_multi_cb(node, event_data);
370 /* LCOV_EXCL_START */
371 static void system_setting_vconf_event_multi_cb_slot_3(keynode_t *node, void *event_data)
373 system_setting_vconf_event_multi_cb(node, event_data);
377 static system_setting_vconf_event_cb system_setting_vconf_get_event_multi_cb_slot(system_settings_key_e key)
384 return system_setting_vconf_event_multi_cb_slot_0;
387 return system_setting_vconf_event_multi_cb_slot_1;
390 return system_setting_vconf_event_multi_cb_slot_2;
393 return system_setting_vconf_event_multi_cb_slot_3;
400 int system_setting_vconf_set_changed_multi_cb(const char *vconf_key, system_settings_key_e key)
402 LOGE("Enter [%s]", __FUNCTION__);
403 system_setting_vconf_event_cb vconf_event_cb;
405 vconf_event_cb = system_setting_vconf_get_event_multi_cb_slot(key);
407 if (vconf_event_cb == NULL)
408 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
410 int ret = vconf_notify_key_changed(vconf_key, vconf_event_cb, (void *)key);
412 LOGE("[%s] INVALID_error , ret = %d, %s", __FUNCTION__, ret, "vconf_notify_key_changed error");
413 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
416 LOGE("Leave [%s]", __FUNCTION__);
417 return SYSTEM_SETTINGS_ERROR_NONE;
420 int system_setting_vconf_unset_changed_multi_cb(const char *vconf_key, system_settings_key_e key)
422 LOGE("Enter [%s]", __FUNCTION__);
423 system_setting_vconf_event_cb vconf_event_cb;
425 vconf_event_cb = system_setting_vconf_get_event_multi_cb_slot(key);
427 if (vconf_event_cb == NULL)
428 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
430 int ret = vconf_ignore_key_changed(vconf_key, vconf_event_cb);
432 LOGE("[%s] INVALID_error , ret = %d, %s", __FUNCTION__, ret, "vconf_ignore_key_changed error");
433 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
436 LOGE("Leave [%s]", __FUNCTION__);
437 return SYSTEM_SETTINGS_ERROR_NONE;