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>
34 #define LOG_TAG "TIZEN_N_SYSTEM_SETTINGS"
36 #define SYSTEM_SETTINGS_MAX -1
40 system_setting_s system_setting_table[] = {
43 SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE,
44 SYSTEM_SETTING_DATA_TYPE_STRING,
45 system_setting_get_incoming_call_ringtone,
46 system_setting_set_incoming_call_ringtone,
47 system_setting_set_changed_callback_incoming_call_ringtone,
48 system_setting_unset_changed_callback_incoming_call_ringtone,
54 SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN,
55 SYSTEM_SETTING_DATA_TYPE_STRING,
56 system_setting_get_wallpaper_home_screen,
57 system_setting_set_wallpaper_home_screen,
58 system_setting_set_changed_callback_wallpaper_home_screen,
59 system_setting_unset_changed_callback_wallpaper_home_screen,
65 SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN,
66 SYSTEM_SETTING_DATA_TYPE_STRING,
67 system_setting_get_wallpaper_lock_screen,
68 system_setting_set_wallpaper_lock_screen,
69 system_setting_set_changed_callback_wallpaper_lock_screen,
70 system_setting_unset_changed_callback_wallpaper_lock_screen,
76 SYSTEM_SETTINGS_KEY_FONT_SIZE,
77 SYSTEM_SETTING_DATA_TYPE_INT,
78 system_setting_get_font_size,
79 system_setting_set_font_size,
80 system_setting_set_changed_callback_font_size,
81 system_setting_unset_changed_callback_font_size,
87 SYSTEM_SETTINGS_KEY_FONT_TYPE,
88 SYSTEM_SETTING_DATA_TYPE_STRING,
89 system_setting_get_font_type,
90 system_setting_set_font_type,
91 system_setting_set_changed_callback_font_type,
92 system_setting_unset_changed_callback_font_type,
98 SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION,
99 SYSTEM_SETTING_DATA_TYPE_BOOL,
100 system_setting_get_motion_activation,
101 system_setting_set_motion_activation,
102 system_setting_set_changed_callback_motion_activation,
103 system_setting_unset_changed_callback_motion_activation,
109 SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE,
110 SYSTEM_SETTING_DATA_TYPE_STRING,
111 system_setting_get_email_alert_ringtone,
112 system_setting_set_email_alert_ringtone,
113 system_setting_set_changed_callback_email_alert_ringtone,
114 system_setting_unset_changed_callback_email_alert_ringtone,
119 SYSTEM_SETTINGS_KEY_USB_DEBUGGING_ENABLED,
120 SYSTEM_SETTING_DATA_TYPE_BOOL,
121 system_setting_get_usb_debugging_option,
122 system_setting_set_usb_debugging_option,
123 system_setting_set_changed_callback_usb_debugging_option,
124 system_setting_unset_changed_callback_usb_debugging_option,
129 SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED,
130 SYSTEM_SETTING_DATA_TYPE_BOOL,
131 system_setting_get_3g_data_network,
132 system_setting_set_3g_data_network,
133 system_setting_set_changed_callback_3g_data_network,
134 system_setting_unset_changed_callback_3g_data_network,
139 SYSTEM_SETTINGS_MAX, -1, NULL, NULL, NULL, NULL, NULL, NULL
143 int system_settings_get_item(system_settings_key_e key, system_setting_h *item)
147 while (system_setting_table[index].key != SYSTEM_SETTINGS_MAX)
149 if (system_setting_table[index].key == key)
151 *item = &system_setting_table[index];
161 int system_settings_get_value(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
163 system_setting_h system_setting_item;
164 system_setting_get_value_cb system_setting_getter;
166 if (system_settings_get_item(key, &system_setting_item))
168 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
169 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
172 if (system_setting_item->data_type != data_type)
174 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid data type", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
175 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
178 system_setting_getter = system_setting_item->get_value_cb;
180 if (system_setting_getter == NULL)
182 LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
183 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
186 return system_setting_getter(key, system_setting_item->data_type, value);
189 int system_settings_set_value(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
191 system_setting_h system_setting_item;
192 system_setting_set_value_cb system_setting_setter;
194 if (system_settings_get_item(key, &system_setting_item))
196 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
197 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
200 system_setting_setter = system_setting_item->set_value_cb;
202 if (system_setting_setter == NULL)
204 LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
205 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
208 return system_setting_setter(key, system_setting_item->data_type, value);
211 // typedef int (*system_setting_set_value_cb) (system_settings_key_e key, system_setting_data_type_e data_type, void* value);
212 int system_settings_set_value_int(system_settings_key_e key, int value)
214 // TODO: make sure the value is inside of enum.
216 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_INT,(void*)ptr);
219 int system_settings_get_value_int(system_settings_key_e key, int *value)
221 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_INT, (void**)value);
224 int system_settings_set_value_bool(system_settings_key_e key, bool value)
227 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_BOOL,(void*)ptr);
230 int system_settings_get_value_bool(system_settings_key_e key, bool *value)
232 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_BOOL, (void**)value);
236 int system_settings_set_value_double(system_settings_key_e key, double value)
238 double* ptr = &value;
239 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_DOUBLE,(void*)ptr);
242 int system_settings_get_value_double(system_settings_key_e key, double *value)
244 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_DOUBLE, (void**)value);
248 int system_settings_set_value_string(system_settings_key_e key, const char *value)
250 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_STRING,(void*)value);
253 int system_settings_get_value_string(system_settings_key_e key, char **value)
255 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_STRING, (void**)value);
261 - system_settings_set_changed_cb
262 -> int (*system_setting_set_changed_callback_cb)(key, callback, user_data)
266 int system_settings_set_changed_cb(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
268 system_setting_h system_setting_item;
269 system_setting_set_changed_callback_cb system_setting_set_changed_cb;
271 if (system_settings_get_item(key, &system_setting_item))
273 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
274 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
277 system_setting_set_changed_cb = system_setting_item->set_changed_cb;
280 // Store the callback function from application side
282 system_setting_item->changed_cb = callback;
285 system_setting_item->user_data = user_data;
287 if (system_setting_set_changed_cb == NULL)
289 LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
290 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
293 return system_setting_set_changed_cb(key, callback, user_data);
297 int system_settings_unset_changed_cb(system_settings_key_e key)
299 system_setting_h system_setting_item;
300 system_setting_unset_changed_callback_cb system_setting_unset_changed_cb;
302 if (system_settings_get_item(key, &system_setting_item))
304 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
305 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
308 system_setting_unset_changed_cb = system_setting_item->unset_changed_cb;
310 // free the callback function from application side
311 if (system_setting_item->changed_cb)
312 system_setting_item->changed_cb = NULL;
313 //-----------------------------------------------------
315 if (system_setting_unset_changed_cb == NULL)
317 LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
318 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
321 return system_setting_unset_changed_cb(key);