Merge "Modified src about get/set func for 64bit-arch." into tizen
[platform/core/api/system-settings.git] / src / system_setting_platform.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 <unistd.h>
20 #include <errno.h>
21 #include <time.h>
22 #include <dlfcn.h>
23
24 #include <string.h>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <fcntl.h>
28 #include <aul.h>
29
30 #include <regex.h>
31
32 #include <dlog.h>
33 #include <vconf.h>
34
35 #include <glib.h>
36 #include <libxml/xmlmemory.h>
37 #include <libxml/parser.h>
38
39 #include <fontconfig/fontconfig.h>
40
41 #include <pkgmgr-info.h>
42
43 #include <system_settings.h>
44 #include <system_settings_private.h>
45 #include <system_settings_ringtones.h>
46 #include <system_settings_json.h>
47
48
49 #include <tzplatform_config.h>
50 #include <alarm.h>
51
52 #ifdef USE_EFL_ASSIST
53 #include <efl_assist.h>
54 #endif
55
56
57
58 #define SETTING_FONT_CONF_FILE _TZ_SYS_ETC"/fonts/conf.avail/99-tizen.conf"
59 #define SETTING_DEFAULT_FONT_CONF_FILE _TZ_SYS_ETC"/fonts/conf.avail/99-tizen.conf"
60
61 #define SETTING_TIME_ZONEINFO_PATH              "/usr/share/zoneinfo/"
62 #define SETTING_TIME_SHARE_LOCAL_PATH   "/usr/share/locale"
63 #define SETTING_TZONE_SYMLINK_PATH              "/opt/etc/localtime"
64
65
66 #define __FREE(del, arg) do { \
67                 if (arg) { \
68                         del((void *)(arg)); /*cast any argument to (void*) to avoid build warring*/\
69                         arg = NULL; \
70                 } \
71         } while (0);
72 #define FREE(arg) __FREE(free, arg)
73
74 #ifdef SETTING_ARCH_64
75 #define SETTING_UTILS_SO_FILE_PATH "/usr/lib64/libsystem-settings-util.so.0.1.0"
76 #else
77 #define SETTING_UTILS_SO_FILE_PATH "/usr/lib/libsystem-settings-util.so.0.1.0"
78 #endif
79
80 int _is_file_accessible(const char *path);
81
82 static bool dl_is_supported_image_type_load(char *path);
83 static bool dl_font_config_set(char *font_name);
84 static char *dl_get_font_info(char *str);
85 static int dl_is_available_font(char *str);
86 static void dl_font_size_set();
87 static void dl_font_config_set_notification();
88
89
90 /**
91  * VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR has a path of the ringtone file which user choose
92  * @return the ringtone file path specified by user in normal case
93  *                 if it's not accessable, return the default ringtone path
94  */
95 int system_setting_get_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
96 {
97         SETTING_TRACE_BEGIN;
98         char *vconf_value;
99         if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, &vconf_value)) {
100                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
101         }
102
103         /* check to see if it's accessable -> OK */
104         /* no --> default ringtone path VCONFKEY_SETAPPL_CALL_RINGTONE_DEFAULT_PATH_STR */
105         int is_load = _is_file_accessible(vconf_value);
106         if (is_load == 0) {
107                 *value = vconf_value;
108         } else { /* not zero on errro */
109                 *value = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_DEFAULT_PATH_STR);
110         }
111
112         /**value = vconf_value; */
113         return SYSTEM_SETTINGS_ERROR_NONE;
114 }
115
116
117 int system_setting_get_email_alert_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
118 {
119         SETTING_TRACE_BEGIN;
120         char *vconf_value;
121         if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, &vconf_value)) {
122                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
123         }
124
125         /* check to see if it's accessable -> OK */
126         /* no --> default ringtone path VCONFKEY_SETAPPL_NOTI_RINGTONE_DEFAULT_PATH_STR */
127         int is_load = _is_file_accessible(vconf_value);
128         if (is_load == 0) {
129                 *value = vconf_value;
130         } else { /* not zero on errro */
131                 *value = vconf_get_str(VCONFKEY_SETAPPL_NOTI_RINGTONE_DEFAULT_PATH_STR);
132         }
133
134         return SYSTEM_SETTINGS_ERROR_NONE;
135 }
136
137
138 int system_setting_get_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
139 {
140         SETTING_TRACE_BEGIN;
141         char *vconf_value;
142         if (system_setting_vconf_get_value_string(VCONFKEY_BGSET, &vconf_value)) {
143                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
144         }
145         *value = vconf_value;
146         return SYSTEM_SETTINGS_ERROR_NONE;
147 }
148
149
150 int system_setting_get_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
151 {
152         SETTING_TRACE_BEGIN;
153         char *vconf_value;
154
155         if (system_setting_vconf_get_value_string(VCONFKEY_IDLE_LOCK_BGSET, &vconf_value)) {
156                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
157         }
158         *value = vconf_value;
159
160         return SYSTEM_SETTINGS_ERROR_NONE;
161 }
162
163
164 /* [int] vconf GET */
165 int system_setting_get_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
166 {
167         SETTING_TRACE_BEGIN;
168         int vconf_value;
169         int ** val = (int**)value;
170
171         if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
172                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
173         }
174         **val = vconf_value;
175
176         return SYSTEM_SETTINGS_ERROR_NONE;
177 }
178
179
180 int system_setting_get_default_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
181 {
182         SETTING_TRACE_BEGIN;
183         char *font_name = dl_get_font_info("default");
184         if (font_name) {
185                 *value = (void *)font_name;
186                 return SYSTEM_SETTINGS_ERROR_NONE;
187         } else {
188                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
189         }
190 }
191
192 /* [int] vconf GET */
193 int system_setting_get_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
194 {
195         SETTING_TRACE_BEGIN;
196         char *font_name = dl_get_font_info("cur");
197         *value = (void *)font_name;
198
199         return SYSTEM_SETTINGS_ERROR_NONE;
200 }
201
202
203 int system_setting_get_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
204 {
205         SETTING_TRACE_BEGIN;
206         bool vconf_value;
207
208         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, &vconf_value)) {
209                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
210         }
211         *value = (void *)vconf_value;
212
213         return SYSTEM_SETTINGS_ERROR_NONE;
214 }
215
216 int system_setting_get_usb_debugging_option(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
217 {
218         SETTING_TRACE_BEGIN;
219         bool vconf_value;
220
221         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &vconf_value)) {
222                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
223         }
224         *value = (void *)vconf_value;
225
226         return SYSTEM_SETTINGS_ERROR_NONE;
227 }
228
229 int system_setting_get_3g_data_network(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
230 {
231         SETTING_TRACE_BEGIN;
232         bool vconf_value;
233
234         if (system_setting_vconf_get_value_bool(VCONFKEY_3G_ENABLE, &vconf_value)) {
235                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
236         }
237         *value = (void *)vconf_value;
238
239         return SYSTEM_SETTINGS_ERROR_NONE;
240 }
241 /*////////////////////////////////////////////////////////////////////////////////////////////////// */
242
243
244 /**
245  * get current lock scren app package name (string)
246  *
247  * @return SYSTEM_SETTINGS_ERROR_LOCKSCREEN_APP_PASSWORD_MODE raise exception if current lock type is 'password'
248  */
249 int system_setting_get_lockscreen_app(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
250 {
251         SETTING_TRACE_BEGIN;
252         char *pkg_name = NULL;
253         int locktype = -1;
254         system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &locktype);
255
256         if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, &pkg_name)) {
257                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
258         }
259
260         if (pkg_name && strcmp(pkg_name, "com.samsung.lockscreen") == 0 && locktype == SETTING_SCREEN_LOCK_TYPE_PASSWORD) {
261                 return SYSTEM_SETTINGS_ERROR_LOCKSCREEN_APP_PASSWORD_MODE;
262         }
263
264         *value = pkg_name;
265         return SYSTEM_SETTINGS_ERROR_NONE;
266 }
267
268
269 /*////////////////////////////////////////////////////////////////////////////////////////////////// */
270
271 int _is_file_accessible(const char *path)
272 {
273         SETTING_TRACE_BEGIN;
274         int ret = access(path , R_OK);
275         if (ret == 0) {
276                 SETTING_TRACE("found the file  %s", path);
277                 return 0;
278         } else {
279                 /* error code : 13 */
280                 SETTING_TRACE("found the file  %s --- error code : %d ", path, errno);
281                 return -errno;
282         }
283 }
284
285
286
287 /*////////////////////////////////////////////////////////////////////////////////////////////////// */
288 // @todo move to CMake
289 #define DEF_RINGTONE_FILE_PATH "/opt/share/settings/Ringtones"
290 #define USR_RINGTONE_FILE_PATH "/home/owner/content/Sounds/Ringtones"
291 #define JSONFILE "/opt/home/owner/apps_rw/org.tizen.setting/data/.user-ringtones.json"
292
293 #if 0
294 static char* _get_json_file_path()
295 {
296         // for testing
297         return JSONFILE;
298 }
299 #endif
300
301 int system_setting_add_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
302 {
303         SETTING_TRACE_BEGIN;
304         char* pathval = (char*)value;
305
306 #ifdef USE_JSONFILE
307         // NOT IN USE
308         JsonParser *parser = ss_json_ringtone_open_file(JSONFILE);
309 #else
310         JsonParser *parser = ss_json_ringtone_load_from_data();
311 #endif
312
313         JsonNode *root = json_parser_get_root(parser);
314
315         // dirname
316         // basename
317         int ret = SYSTEM_SETTINGS_ERROR_NONE;
318         if (false == ss_json_ringtone_contain(root, pathval)) {
319                 SETTING_TRACE("---> dirname is : %s ", dirname(strdup(pathval)));
320                 SETTING_TRACE("---> basename is : %s ", basename(strdup(pathval)));
321                 // @todo : MAKE SURE THE ACTUAL FILE IS THERE ON PATHVAL(SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
322                 ss_json_ringtone_add(root, JSONFILE, pathval, pathval);
323                 SETTING_TRACE("pathval is : %s -- OK", pathval);
324         } else {
325                 SETTING_TRACE("pathval is duplicated : %s", pathval);
326                 SETTING_TRACE("---> dirname is : %s ", dirname(strdup(pathval)));
327                 SETTING_TRACE("---> basename is : %s ", basename(strdup(pathval)));
328                 ret = SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
329         }
330
331         if (parser) {
332                 g_object_unref(parser);
333                 parser = NULL;
334         }
335
336         return ret;
337 }
338
339 int system_setting_del_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
340 {
341         SETTING_TRACE_BEGIN;
342         char* pathval = (char*)value;
343 #ifdef USE_JSONFILE
344         // NOT IN USE
345         JsonParser* parser = ss_json_ringtone_open_file(JSONFILE);
346 #else
347         JsonParser* parser = ss_json_ringtone_load_from_data();
348 #endif
349         JsonNode *root = json_parser_get_root(parser);
350
351         ss_json_ringtone_remove(root, JSONFILE, pathval);
352         //void ss_json_ringtone_remove(JsonNode *root,  char* filename, char* path_to_del)
353
354         ss_json_ringtone_print(root);
355         if (parser) {
356                 g_object_unref(parser);
357                 parser = NULL;
358         }
359
360         return SYSTEM_SETTINGS_ERROR_NONE;
361 }
362
363
364 static int _compare_cb(const void *d1, const void *d2)
365 {
366         fileNodeInfo *pNode1 = (fileNodeInfo *)d1;
367         fileNodeInfo *pNode2 = (fileNodeInfo *)d2;
368
369         return strcmp(pNode1->media_name, pNode2->media_name);
370 }
371
372 /*
373  * get the RINGTONE list
374  */
375 static void _get_default_ringtones(system_settings_key_e key, system_setting_data_type_e data_type,  system_settings_iter_cb callback, void *data)
376 {
377         SETTING_TRACE_BEGIN;
378         /*Get file list */
379         Eina_List *filelist = NULL;
380         Eina_List *l = NULL;
381         fileNodeInfo *node = NULL;
382         int idx = 0;
383
384         //-----------------------------------------------------------------------------------------------------------------
385         // 1. get the default ringtone list
386         //-----------------------------------------------------------------------------------------------------------------
387         int ret = get_filelist_from_dir_path(DEF_RINGTONE_FILE_PATH, &filelist);
388         if (ret != 0) {
389                 SETTING_TRACE("Failed to get filelist, ret = %d %s", ret, DEF_RINGTONE_FILE_PATH);
390         }
391         filelist = eina_list_sort(filelist, eina_list_count(filelist), _compare_cb);
392
393         EINA_LIST_FOREACH(filelist, l, node)
394         {
395                 SETTING_TRACE("file path = (%d) : name:%s path:%s [%s]", ret, node->name, node->path, node->media_name);
396                 // @todo assert NULL check
397                 if (callback) {
398                         char temp[1024];
399                         snprintf(temp, 1024, "%s/%s", node->path, node->name);
400                         char* path = strdup(temp);
401                         bool ret = callback(idx, (void *)(path), data);
402                         if (path) {
403                                 free(path);
404                                 path = NULL;
405                         }
406                         if (ret == false) {
407                                 SETTING_TRACE("quit the iteration by return value == false : %d", ret);
408                                 break;
409                         }
410
411                 } else {
412                         SETTING_TRACE("--> system_setting_data_iterator is NULL");
413                 }
414         }
415
416         l = NULL;
417         node = NULL;
418         EINA_LIST_FOREACH(filelist, l, node)
419         {
420                 FREE(node->path);
421                 FREE(node->name);
422                 FREE(node->media_name);
423                 FREE(node);
424         }
425         eina_list_free(filelist);
426         filelist = NULL;
427
428 }
429
430 static void _get_user_ringtones(system_settings_key_e key, system_setting_data_type_e data_type, system_settings_iter_cb callback, void *data)
431 {
432         SETTING_TRACE_BEGIN;
433
434 #ifdef USE_JSONFILE
435         // NOT IN USE
436         JsonParser* parser = ss_json_ringtone_open_file(JSONFILE);
437 #else
438         JsonParser* parser = ss_json_ringtone_load_from_data();
439 #endif
440
441         JsonNode *root = json_parser_get_root(parser);
442         int size = json_array_get_length(json_node_get_array(root));
443
444         int i = 0;
445         for (i = 0; i < size ; i++) {
446                 JsonObject *ringtone = json_array_get_object_element(json_node_get_array(root), i);
447                 char *nameval = (char *)json_object_get_string_member(ringtone, "name");
448                 char *pathval = (char *)json_object_get_string_member(ringtone, "path");
449                 SETTING_TRACE("(%s) --- (%s) \n", nameval, pathval);
450                 if (callback) {
451                         char* path = strdup(pathval);
452                         bool ret = callback(i, (void *)(path), data);
453                         if (ret == false) {
454                                 SETTING_TRACE("quit the iteration by return value == false : %d", ret);
455                                 break;
456                         }
457                 } else {
458                         SETTING_TRACE("--> callback is NULL");
459                 }
460         }
461 }
462
463 int system_setting_list_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, system_settings_iter_cb callback, void *data)
464 {
465         SETTING_TRACE_BEGIN;
466
467         _get_default_ringtones(key, data_type, callback, data);
468         //-----------------------------------------------------------------------------------------------------------------
469         // 2. get the USER ringtone list
470         //-----------------------------------------------------------------------------------------------------------------
471         _get_user_ringtones(key, data_type, callback, data);
472
473         return SYSTEM_SETTINGS_ERROR_NONE;
474 }
475
476
477 /*  LCOV_EXCL_START */
478 int system_setting_set_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
479 {
480         SETTING_TRACE_BEGIN;
481         char *vconf_value;
482         vconf_value = (char *)value;
483
484         int ret = _is_file_accessible(vconf_value);
485         if (ret == 0) {
486                 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, vconf_value)) {
487                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
488                 }
489         } else {
490                 /* @todo add a common ret_handler */
491                 return ret;
492         }
493
494         return SYSTEM_SETTINGS_ERROR_NONE;
495 }
496 /*  LCOV_EXCL_STOP */
497
498
499 /*  LCOV_EXCL_START */
500 int system_setting_set_email_alert_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
501 {
502         SETTING_TRACE_BEGIN;
503         char *vconf_value;
504         vconf_value = (char *)value;
505
506         int ret = _is_file_accessible(vconf_value);
507         if (ret == 0) {
508                 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, vconf_value)) {
509                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
510                 }
511         } else {
512                 /*return SYSTEM_SETTINGS_ERROR_IO_ERROR;*/
513                 /* @todo add a common ret_handler */
514                 return ret;
515         }
516
517         return SYSTEM_SETTINGS_ERROR_NONE;
518 }
519 /*  LCOV_EXCL_STOP */
520
521 /*  LCOV_EXCL_START */
522 static bool dl_is_supported_image_type_load(char *path)
523 {
524         void *handle = NULL;
525         char *error;
526         bool ret = false;
527         bool (*image_type_check)(char *path);
528
529         handle = dlopen(SETTING_UTILS_SO_FILE_PATH,  RTLD_LAZY);
530         if (!handle) {
531                 SETTING_TRACE("ERROR!! canNOT find libsystem-settings-util.so.0.1.0");
532                 return false;
533         }
534
535         image_type_check = dlsym(handle, "__is_supported_image_type_load");
536         if ((error = dlerror()) != NULL) {
537                 SETTING_TRACE("ERROR!! canNOT find __is_supported_image_type_load function at libsystem-settings-util.so.0.1.0");
538                 if (handle)
539                         dlclose(handle);
540                 return false;
541         }
542         ret = image_type_check(path);
543         if (handle)
544                 dlclose(handle);
545         return ret;
546 }
547 /*  LCOV_EXCL_STOP */
548
549 /*  LCOV_EXCL_START */
550 static int dl_is_available_font(char *str)
551 {
552         void *handle = NULL;
553         char *error;
554         int ret = false;
555         int (*check_available_font)(char *font_name);
556
557         handle = dlopen(SETTING_UTILS_SO_FILE_PATH,  RTLD_LAZY);
558         if (!handle) {
559                 SETTING_TRACE("ERROR!! canNOT find libsystem-settings-util.so.0.1.0");
560                 return false;
561         }
562
563         check_available_font = dlsym(handle, "__is_available_font");
564         if ((error = dlerror()) != NULL) {
565                 SETTING_TRACE("ERROR!! canNOT find __is_available_font function at libsystem-settings-util.so.0.1.0");
566                 if (handle)
567                         dlclose(handle);
568                 return false;
569         }
570         ret = check_available_font(str);
571         if (handle)
572                 dlclose(handle);
573         return ret;
574 }
575 /*  LCOV_EXCL_STOP */
576
577 /*  LCOV_EXCL_START */
578 static void dl_font_size_set()
579 {
580         void *handle = NULL;
581         char *error;
582         void (*set_font_size)();
583
584         handle = dlopen(SETTING_UTILS_SO_FILE_PATH,  RTLD_LAZY);
585         if (!handle) {
586                 SETTING_TRACE("ERROR!! canNOT find libsystem-settings-util.so.0.1.0");
587                 return;
588         }
589
590         set_font_size = dlsym(handle, "__font_size_set");
591         if ((error = dlerror()) != NULL) {
592                 SETTING_TRACE("ERROR!! canNOT find __font_size_set function at libsystem-settings-util.so.0.1.0");
593                 if (handle)
594                         dlclose(handle);
595                 return;
596         }
597         set_font_size();
598         if (handle)
599                 dlclose(handle);
600         return;
601 }
602 /*  LCOV_EXCL_STOP */
603
604 /*  LCOV_EXCL_START */
605 static void dl_font_config_set_notification()
606 {
607         void *handle = NULL;
608         char *error;
609         void (*set_font_nodification)();
610
611         handle = dlopen(SETTING_UTILS_SO_FILE_PATH,  RTLD_LAZY);
612         if (!handle) {
613                 SETTING_TRACE("ERROR!! canNOT find libsystem-settings-util.so.0.1.0");
614                 return;
615         }
616
617         set_font_nodification = dlsym(handle, "font_config_set_notification");
618         if ((error = dlerror()) != NULL) {
619                 SETTING_TRACE("ERROR!! canNOT find font_config_set_notification function at libsystem-settings-util.so.0.1.0");
620                 if (handle)
621                         dlclose(handle);
622                 return;
623         }
624         set_font_nodification();
625         if (handle)
626                 dlclose(handle);
627         return;
628 }
629 /*  LCOV_EXCL_STOP */
630
631 /*  LCOV_EXCL_START */
632 static bool dl_font_config_set(char *font_name)
633 {
634         void *handle = NULL;
635         char *error;
636         bool ret = false;
637         bool (*check_font_type)(char *font_name);
638
639         handle = dlopen(SETTING_UTILS_SO_FILE_PATH,  RTLD_LAZY);
640         if (!handle) {
641                 SETTING_TRACE("ERROR!! canNOT find libsystem-settings-util.so.0.1.0");
642                 return false;
643         }
644
645         check_font_type = dlsym(handle, "font_config_set");
646         if ((error = dlerror()) != NULL) {
647                 SETTING_TRACE("ERROR!! canNOT find font_config_set function at libsystem-settings-util.so.0.1.0");
648                 if (handle)
649                         dlclose(handle);
650                 return false;
651         }
652         ret = check_font_type(font_name);
653         if (handle)
654                 dlclose(handle);
655         return ret;
656 }
657 /*  LCOV_EXCL_STOP */
658
659 /*  LCOV_EXCL_START */
660 static char *dl_get_font_info(char *str)
661 {
662         void *handle = NULL;
663         char *error;
664         char *ret = NULL;
665         char *(*get_font_info)();
666
667         handle = dlopen(SETTING_UTILS_SO_FILE_PATH,  RTLD_LAZY);
668         if (!handle) {
669                 SETTING_TRACE("ERROR!! canNOT find libsystem-settings-util.so.0.1.0");
670                 return false;
671         }
672
673         if (strcmp(str, "cur") == 0)
674                 get_font_info = dlsym(handle, "_get_cur_font");
675         else
676                 get_font_info = dlsym(handle, "_get_default_font");
677
678         if ((error = dlerror()) != NULL) {
679                 SETTING_TRACE("ERROR!! canNOT find %s function at libsystem-settings-util.so.0.1.0", str);
680                 if (handle)
681                         dlclose(handle);
682                 return false;
683         }
684         ret = get_font_info();
685         if (handle)
686                 dlclose(handle);
687         return ret;
688 }
689 /*  LCOV_EXCL_STOP */
690
691 /*  LCOV_EXCL_START */
692 #define PATH_EXT_CHECK_REG ".(jpe?g|jpg|png|gif)$"
693 bool __is_supported_image_type_by_ext(char *file_path)
694 {
695         SETTING_TRACE_BEGIN;
696         regex_t fsm;
697         regmatch_t str[2048 + 1];
698
699         if (!file_path) return false;
700
701         int ret = false;
702         if ((ret = regcomp(&fsm, PATH_EXT_CHECK_REG, REG_ICASE | REG_EXTENDED))) {
703                 SETTING_TRACE("regular expresstion fail");
704                 return 1;
705         }
706
707         /* code */
708         if (regexec(&fsm, file_path, strlen(file_path) + 1, str, 0) == REG_NOMATCH) {
709                 /*SETTING_TRACE("FAILED - %s", file_path[i]); */
710                 ret = 0;
711         } else {
712                 /*SETTING_TRACE("MATCHED - %s", file_path[i]); */
713                 ret = 1;
714         }
715         return ret;
716 }
717 /*  LCOV_EXCL_STOP */
718 #ifdef TIZEN_WEARABLE
719 /*  LCOV_EXCL_START */
720 static int system_setting_get_extended_wallpaper_num(const char *file_path, unsigned int *num)
721 {
722         SETTING_TRACE_BEGIN;
723         char buffer[256];
724         const char *find_str = "extended_wallpaper_";
725         char *ch = NULL;
726
727         if (!(ch = strstr(file_path, find_str))) {
728                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
729         }
730         strncpy(buffer, file_path, ch - file_path);
731         buffer[ch - file_path] = 0;
732         sprintf(buffer + (ch - file_path), "%s%s", "", ch + strlen(find_str));
733
734         if (!isdigit(buffer[0])) {
735                 SETTING_TRACE("%s is not number", buffer);
736                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
737         }
738
739         *num = atoi(buffer);
740
741         return SYSTEM_SETTINGS_ERROR_NONE;
742 }
743 /*  LCOV_EXCL_STOP */
744
745 /*  LCOV_EXCL_START */
746 static int system_setting_copy_extended_wallpaper(const char *dest_file_path, const char *source_file_path)
747 {
748         SETTING_TRACE_BEGIN;
749         if (!source_file_path || !dest_file_path) {
750                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
751         }
752
753         char buf[1024];
754
755         int fd;
756         fd = open(source_file_path, O_RDONLY);
757         if (fd < 0) {
758                 SETTING_TRACE("file open failed: %s", source_file_path);
759                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
760         }
761
762         int fd2;
763         fd2 = open(dest_file_path, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
764         if (fd2 < 0) {
765                 SETTING_TRACE("file creation failed: %s", dest_file_path);
766                 close(fd);
767                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
768         }
769
770         while (read(fd, buf, sizeof(buf) - 1) > 0) {
771                 write(fd2, buf, sizeof(buf) - 1);
772         }
773
774         close(fd2);
775         close(fd);
776
777         if (chmod(dest_file_path, S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
778                 SETTING_TRACE("chmod failed: %s", dest_file_path);
779         }
780
781         return SYSTEM_SETTINGS_ERROR_NONE;
782 }
783 /*  LCOV_EXCL_STOP */
784
785 /*  LCOV_EXCL_START */
786 static int system_setting_remove_oldest_extended_wallpaper()
787 {
788         SETTING_TRACE_BEGIN;
789         DIR *dp;
790         struct dirent *dirp;
791         char *min_image_name = NULL;
792         unsigned int min_image_num = 0;
793         unsigned int temp_image_num = 0;
794         int image_count = 0;
795
796         if ((dp = opendir(_TZ_SYS_DATA"/setting/wallpaper")) == NULL) {
797                 SETTING_TRACE("opendir error");
798                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
799         }
800
801         while ((dirp = readdir(dp))) {
802                 if (!strcmp(dirp->d_name, ".") || !strcmp(dirp->d_name, ".."))
803                         continue;
804
805                 if (system_setting_get_extended_wallpaper_num(dirp->d_name, &temp_image_num)
806                     != SYSTEM_SETTINGS_ERROR_NONE) {
807                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
808                 }
809
810                 if ((image_count == 0) || (min_image_num > temp_image_num)) {
811                         min_image_num = temp_image_num;
812                         min_image_name = dirp->d_name;
813                 }
814
815                 image_count++;
816         }
817
818         char buf[512];
819         if (min_image_name) {
820                 snprintf(buf, sizeof(buf) - 1, _TZ_SYS_DATA"/setting/wallpaper/%s", min_image_name);
821                 if (remove(buf) < 0) {  /* remove oldest image */
822                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
823                 }
824         }
825
826         return SYSTEM_SETTINGS_ERROR_NONE;
827 }
828 /*  LCOV_EXCL_STOP */
829
830 /*  LCOV_EXCL_START */
831 static int system_setting_check_extended_wallpaper(const char *file_path)
832 {
833         char buffer[512];
834         SETTING_TRACE_BEGIN;
835         if (!file_path || !strlen(file_path))
836                 return 0;
837         snprintf(buffer, 512, "%s/.bgwallpaper", tzplatform_getenv(TZ_USER_CONTENT));
838         return (strstr(file_path, buffer) != NULL);
839 }
840 /*  LCOV_EXCL_STOP */
841
842 #define WALLPAPER_MAX_COUNT             10
843 #endif
844 /*  LCOV_EXCL_START */
845 int system_setting_set_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
846 {
847         SETTING_TRACE_BEGIN;
848         char *vconf_value;
849         vconf_value = (char *)value;
850
851         bool isok  = dl_is_supported_image_type_load(vconf_value);
852         if (!isok) {
853                 /* not supported */
854                 SETTING_TRACE("path : %s is not supported file format", vconf_value);
855                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
856         } else {
857                 SETTING_TRACE("path : %s is SUPPORT file format", vconf_value);
858         }
859
860         /* error handling here */
861         if (_is_file_accessible(vconf_value) != 0)
862                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
863 #ifdef TIZEN_MOBILE
864         if (system_setting_vconf_set_value_string(VCONFKEY_BGSET, vconf_value)) {
865                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
866         }
867 #endif
868
869 #ifdef TIZEN_WEARABLE
870         if (system_setting_check_extended_wallpaper(vconf_value)) {     /* New extended wallpaper */
871                 DIR *dp = NULL;
872                 struct dirent *dirp;
873                 unsigned int max_image_num = 0;
874                 unsigned int temp_image_num = 0;
875                 int image_count = 0;
876
877                 if ((dp = opendir(_TZ_SYS_DATA"/setting/wallpaper")) == NULL) {
878                         SETTING_TRACE("Setting - dir open error!");
879                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
880                 }
881
882                 /* Check a max number of wallpapers */
883                 while ((dirp = readdir(dp))) {
884                         if (!strcmp(dirp->d_name, ".") || !strcmp(dirp->d_name, ".."))
885                                 continue;
886
887                         if (system_setting_get_extended_wallpaper_num(dirp->d_name, &temp_image_num)
888                             != SYSTEM_SETTINGS_ERROR_NONE) {
889                                 if (dp)
890                                         closedir(dp);
891                                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
892                         }
893
894                         if ((image_count == 0) || (max_image_num < temp_image_num)) {
895                                 max_image_num = temp_image_num;
896                         }
897
898                         image_count++;
899                 }
900                 if (dp)
901                         closedir(dp);
902
903                 /* Numbering rule: Gear is odd number */
904                 max_image_num = (max_image_num % 2 == 0) ? max_image_num + 1
905                                                         : max_image_num + 2;
906
907                 char file_name_buffer[512];
908                 snprintf(file_name_buffer, sizeof(file_name_buffer) - 1,
909                                         _TZ_SYS_DATA"/setting/wallpaper/extended_wallpaper_%d.jpg", max_image_num);
910
911                 /* Copy image to _TZ_SYS_DATA/setting/wallpaper/ */
912                 if (system_setting_copy_extended_wallpaper(file_name_buffer, vconf_value)
913                     != SYSTEM_SETTINGS_ERROR_NONE) {
914                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
915                 }
916
917                 /* remove oldest wallpaper */
918                 if (image_count >= WALLPAPER_MAX_COUNT) {
919                         if (system_setting_remove_oldest_extended_wallpaper()
920                             != SYSTEM_SETTINGS_ERROR_NONE) {
921                                 remove(file_name_buffer);
922                                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
923                         }
924                 }
925
926                 if (system_setting_vconf_set_value_string(VCONFKEY_BGSET, file_name_buffer)) {
927                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
928                 }
929
930                 if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_WALLPAPER_CHANGED_NOTI_INT,
931                                                                                                         VCONFKEY_WALLPAPER_CHANGED_NOTI_GEAR)) {
932                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
933                 }
934         } else {
935                 if (system_setting_vconf_set_value_string(VCONFKEY_BGSET, vconf_value)) {
936                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
937                 }
938         }
939 #endif
940
941         return SYSTEM_SETTINGS_ERROR_NONE;
942 }
943 /*  LCOV_EXCL_STOP */
944
945 /*  LCOV_EXCL_START */
946 int system_setting_set_wallpaper_lock_screen(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
947 {
948         SETTING_TRACE_BEGIN;
949         char *vconf_value;
950         vconf_value = (char *)value;
951
952         bool isok  = dl_is_supported_image_type_load(vconf_value);
953         if (!isok) {
954                 /* not supported */
955                 SETTING_TRACE("path : %s is not supported file format", vconf_value);
956                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
957         } else {
958                 SETTING_TRACE("path : %s is SUPPORT file format", vconf_value);
959         }
960
961         /* error handling here */
962         if (_is_file_accessible(vconf_value) != 0)
963                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
964
965         if (system_setting_vconf_set_value_string(VCONFKEY_IDLE_LOCK_BGSET, vconf_value)) {
966                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
967         }
968
969         return SYSTEM_SETTINGS_ERROR_NONE;
970 }
971 /*  LCOV_EXCL_STOP */
972
973 /*  LCOV_EXCL_START */
974 int system_setting_set_font_size(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
975 {
976         SETTING_TRACE_BEGIN;
977         int *vconf_value;
978         vconf_value = *(int **)value;
979
980         if (*vconf_value < 0 || *vconf_value > SYSTEM_SETTINGS_FONT_SIZE_GIANT) {
981                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
982         }
983
984         if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, *vconf_value)) {
985                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
986         }
987         dl_font_size_set();
988         SETTING_TRACE_END;
989         return SYSTEM_SETTINGS_ERROR_NONE;
990 }
991 /*  LCOV_EXCL_STOP */
992 /**
993  * [internal API]
994  */
995 /*  LCOV_EXCL_START */
996 void *font_conf_doc_parse(char *doc_name, char *font_name)
997 {
998         SETTING_TRACE_BEGIN;
999         xmlDocPtr doc = NULL;
1000         xmlNodePtr cur = NULL;
1001         xmlNodePtr cur2 = NULL;
1002         xmlNodePtr cur3 = NULL;
1003         xmlChar *key = NULL;
1004
1005         doc = xmlParseFile(doc_name);
1006
1007         cur = xmlDocGetRootElement(doc);
1008
1009         if (cur == NULL) {
1010                 xmlFreeDoc(doc);
1011                 doc = NULL;
1012                 return NULL;
1013         }
1014
1015         if (xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
1016                 xmlFreeDoc(doc);
1017                 doc = NULL;
1018                 return NULL;
1019         }
1020
1021         cur = cur->xmlChildrenNode;
1022
1023         bool is_changed = false;
1024         while (cur != NULL) {
1025                 if ((!xmlStrcmp(cur->name, (const xmlChar *)"match"))) {
1026                         cur2 = cur->xmlChildrenNode;
1027                         while (cur2 != NULL) {
1028                                 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"edit"))) {
1029                                         xmlChar *name = xmlGetProp(cur2, (const xmlChar *)"name");
1030                                         /* if name is not 'family', break */
1031                                         if (xmlStrcmp(name, (const xmlChar *)"family")) {
1032                                                 xmlFree(name);
1033                                                 name = NULL;
1034                                                 break;
1035                                         }
1036                                         xmlFree(name);
1037                                         name = NULL;
1038
1039                                         cur3 = cur2->xmlChildrenNode;
1040                                         while (cur3 != NULL) {
1041                                                 if ((!xmlStrcmp(cur3->name, (const xmlChar *)"string"))) {
1042                                                         xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
1043                                                         key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
1044                                                         xmlFree(key);
1045                                                         key = NULL;
1046                                                         is_changed = true;
1047                                                 }
1048                                                 cur3 = cur3->next;
1049                                         }
1050                                 }
1051                                 cur2 = cur2->next;
1052                         }
1053                 } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"alias"))) {
1054                         cur2 = cur->xmlChildrenNode;
1055                         while (cur2 != NULL) {
1056                                 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"family"))) {
1057                                         xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar *)font_name);
1058                                         key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
1059                                         xmlFree(key);
1060                                         key = NULL;
1061                                         is_changed = true;
1062                                 } else if ((!xmlStrcmp(cur2->name, (const xmlChar *)"prefer"))) {
1063                                         cur3 = cur2->xmlChildrenNode;
1064                                         while (cur3 != NULL) {
1065                                                 if ((!xmlStrcmp(cur3->name, (const xmlChar *)"family"))) {
1066                                                         xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
1067                                                         key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
1068                                                         xmlFree(key);
1069                                                         key = NULL;
1070                                                         is_changed = true;
1071                                                         cur3 = cur3->next;
1072                                                         return doc;
1073                                                 }
1074                                                 cur3 = cur3->next;
1075                                         }
1076                                 }
1077                                 cur2 = cur2->next;
1078                         }
1079                 }
1080                 cur = cur->next;
1081         }
1082
1083         if (is_changed) {
1084                 return doc;
1085         } else {
1086                 xmlFreeDoc(doc);
1087                 doc = NULL;
1088                 return NULL;
1089         }
1090 }
1091 /*  LCOV_EXCL_STOP */
1092
1093 /*  LCOV_EXCL_START */
1094 int system_setting_set_font_type(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1095 {
1096         SETTING_TRACE_BEGIN;
1097         char *font_name = NULL;
1098         font_name = (char *)value;
1099
1100         /* get current font list */
1101         int is_found = dl_is_available_font(font_name);
1102
1103         if (is_found) {
1104                 SETTING_TRACE("found font : %s ", font_name);
1105         } else {
1106                 SETTING_TRACE(" NOT found font : %s ", font_name);
1107                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1108         }
1109
1110         bool bsave = dl_font_config_set(font_name);
1111
1112         if (!bsave) {
1113                 SETTING_TRACE(" font type save error by font_config_set() ");
1114                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1115         } else {
1116                 SETTING_TRACE(" save OK - font_config_set() ");
1117         }
1118
1119         xmlDocPtr doc = (xmlDocPtr)font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
1120         if (doc != NULL) {
1121                 xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
1122                 xmlFreeDoc(doc);
1123                 doc = NULL;
1124         }
1125
1126         dl_font_config_set_notification();
1127
1128         char *vconf_value;
1129         vconf_value = (char *)value;
1130
1131         if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, vconf_value)) {
1132                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1133         }
1134         return SYSTEM_SETTINGS_ERROR_NONE;
1135 }
1136 /*  LCOV_EXCL_STOP */
1137
1138 /*  LCOV_EXCL_START */
1139 int system_setting_set_motion_activation(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1140 {
1141         SETTING_TRACE_BEGIN;
1142         bool *vconf_value;
1143         vconf_value = (bool *)value;
1144         if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, *vconf_value)) {
1145                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1146         }
1147         return SYSTEM_SETTINGS_ERROR_NONE;
1148 }
1149 /*  LCOV_EXCL_STOP */
1150
1151 /*  LCOV_EXCL_START */
1152 int system_setting_set_usb_debugging_option(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1153 {
1154         SETTING_TRACE_BEGIN;
1155         bool *vconf_value;
1156         vconf_value = (bool *)value;
1157         if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, *vconf_value)) {
1158                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1159         }
1160         return SYSTEM_SETTINGS_ERROR_NONE;
1161
1162 }
1163 /*  LCOV_EXCL_STOP */
1164
1165 /*  LCOV_EXCL_START */
1166 int system_setting_set_3g_data_network(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1167 {
1168         SETTING_TRACE_BEGIN;
1169         bool *vconf_value;
1170         vconf_value = (bool *)value;
1171         if (system_setting_vconf_set_value_bool(VCONFKEY_3G_ENABLE, *vconf_value)) {
1172                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1173         }
1174
1175         return SYSTEM_SETTINGS_ERROR_NONE;
1176 }
1177 /*  LCOV_EXCL_STOP */
1178
1179 /*  LCOV_EXCL_START */
1180 static int category_func(const char *name, void *user_data)
1181 {
1182         SETTING_TRACE_BEGIN;
1183         static char *category = "lock-screen";
1184         if (name && !strcmp(name, category)) {
1185                 SETTING_TRACE(" SAME ");
1186                 return -1;
1187         } else {
1188                 SETTING_TRACE(" DIFFERENT -- %s, category -- %s ", name, category);
1189                 return 0;
1190         }
1191
1192         return 0;
1193 }
1194 /*  LCOV_EXCL_STOP */
1195
1196 /**
1197  *
1198  * set 'swipe type' if current lockscreen app is 'com.samsung.lockscreen'
1199  *
1200  */
1201
1202 /*  LCOV_EXCL_START */
1203 int system_setting_set_lockscreen_app(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1204 {
1205         SETTING_TRACE_BEGIN;
1206         char *vconf_value;
1207         vconf_value = (char *)value;            /* ex) com.samsung.lockscreen */
1208
1209         int r = 0;
1210         pkgmgrinfo_appinfo_h handle;
1211         r = pkgmgrinfo_appinfo_get_appinfo(vconf_value, &handle);
1212         if (r != PMINFO_R_OK) {
1213                 SETTING_TRACE("*** pkginfo failed ");
1214                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
1215         } else {
1216                 SETTING_TRACE("%x", handle);
1217         }
1218
1219         int ret = pkgmgrinfo_appinfo_foreach_category(handle, category_func, (void *)"lock-screen");
1220         if (ret != PMINFO_R_OK) {
1221                 pkgmgrinfo_appinfo_destroy_appinfo(handle);
1222                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
1223         }
1224
1225         pkgmgrinfo_appinfo_destroy_appinfo(handle);
1226         /*----------------------------------------------------------------------------------- */
1227         int locktype = -1;
1228         if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &locktype)) {
1229                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1230         }
1231
1232         if (locktype == SETTING_SCREEN_LOCK_TYPE_PASSWORD)
1233                 return SYSTEM_SETTINGS_ERROR_LOCKSCREEN_APP_PASSWORD_MODE;
1234
1235         if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, vconf_value)) {
1236                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1237         }
1238
1239         if (vconf_value && strcmp(vconf_value, "com.samsung.lockscreen") == 0) {
1240                 if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, SETTING_SCREEN_LOCK_TYPE_SWIPE)) {
1241                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1242                 }
1243         }
1244         return SYSTEM_SETTINGS_ERROR_NONE;
1245 }
1246 /*  LCOV_EXCL_STOP */
1247
1248 /*/////////////////////////////////////////////////////////////////////////////////////////////// */
1249 /* */
1250
1251 int system_setting_set_changed_callback_incoming_call_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1252 {
1253         SETTING_TRACE_BEGIN;
1254         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, 0, user_data);
1255 }
1256
1257 int system_setting_unset_changed_callback_incoming_call_ringtone(system_settings_key_e key)
1258 {
1259         SETTING_TRACE_BEGIN;
1260         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, 0);
1261 }
1262
1263 int system_setting_set_changed_callback_email_alert_ringtone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1264 {
1265         SETTING_TRACE_BEGIN;
1266         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, 0, user_data);
1267 }
1268
1269 int system_setting_unset_changed_callback_email_alert_ringtone(system_settings_key_e key)
1270 {
1271         SETTING_TRACE_BEGIN;
1272         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, 0);
1273 }
1274
1275 int system_setting_set_changed_callback_wallpaper_home_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1276 {
1277         SETTING_TRACE_BEGIN;
1278         return system_setting_vconf_set_changed_cb(VCONFKEY_BGSET, SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, 0, user_data);
1279 }
1280
1281 int system_setting_unset_changed_callback_wallpaper_home_screen(system_settings_key_e key)
1282 {
1283         SETTING_TRACE_BEGIN;
1284         return system_setting_vconf_unset_changed_cb(VCONFKEY_BGSET, 0);
1285 }
1286
1287 int system_setting_set_changed_callback_wallpaper_lock_screen(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1288 {
1289         SETTING_TRACE_BEGIN;
1290         return system_setting_vconf_set_changed_cb(VCONFKEY_IDLE_LOCK_BGSET, SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, 0, user_data);
1291 }
1292
1293 int system_setting_unset_changed_callback_wallpaper_lock_screen(system_settings_key_e key)
1294 {
1295         SETTING_TRACE_BEGIN;
1296         return system_setting_vconf_unset_changed_cb(VCONFKEY_IDLE_LOCK_BGSET, 0);
1297 }
1298
1299 int system_setting_set_changed_callback_font_size(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1300 {
1301         SETTING_TRACE_BEGIN;
1302         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, SYSTEM_SETTINGS_KEY_FONT_SIZE, 1, user_data);
1303 }
1304
1305 int system_setting_unset_changed_callback_font_size(system_settings_key_e key)
1306 {
1307         SETTING_TRACE_BEGIN;
1308         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, 1);
1309 }
1310
1311 int system_setting_set_changed_callback_usb_debugging_option(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1312 {
1313         SETTING_TRACE_BEGIN;
1314         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, SYSTEM_SETTINGS_KEY_USB_DEBUGGING_ENABLED, 1, user_data);
1315 }
1316
1317 int system_setting_unset_changed_callback_usb_debugging_option(system_settings_key_e key)
1318 {
1319         SETTING_TRACE_BEGIN;
1320         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, 1);
1321 }
1322
1323 int system_setting_set_changed_callback_3g_data_network(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1324 {
1325         SETTING_TRACE_BEGIN;
1326         return system_setting_vconf_set_changed_cb(VCONFKEY_3G_ENABLE, SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, 1, user_data);
1327 }
1328
1329 int system_setting_unset_changed_callback_3g_data_network(system_settings_key_e key)
1330 {
1331         SETTING_TRACE_BEGIN;
1332         return system_setting_vconf_unset_changed_cb(VCONFKEY_3G_ENABLE, 1);
1333 }
1334
1335 int system_setting_set_changed_callback_lockscreen_app(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1336 {
1337         SETTING_TRACE_BEGIN;
1338         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, SYSTEM_SETTINGS_KEY_LOCKSCREEN_APP, 1, user_data);
1339 }
1340
1341 int system_setting_unset_changed_callback_lockscreen_app(system_settings_key_e key)
1342 {
1343         SETTING_TRACE_BEGIN;
1344         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, 1);
1345 }
1346
1347
1348 /**
1349  * @todo need to add custom event notification method
1350  */
1351 int system_setting_set_changed_callback_font_type(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1352 {
1353         SETTING_TRACE_BEGIN;
1354         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, SYSTEM_SETTINGS_KEY_FONT_TYPE, 2, user_data);
1355 }
1356
1357 int system_setting_unset_changed_callback_font_type(system_settings_key_e key)
1358 {
1359         SETTING_TRACE_BEGIN;
1360         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, 2);
1361 }
1362
1363 /* TODO : 2th argument, callback, is not in use. */
1364 int system_setting_set_changed_callback_motion_activation(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1365 {
1366         SETTING_TRACE_BEGIN;
1367         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, 3, user_data);
1368 }
1369
1370 int system_setting_unset_changed_callback_motion_activation(system_settings_key_e key)
1371 {
1372         SETTING_TRACE_BEGIN;
1373         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_MOTION_ACTIVATION, 3);
1374 }
1375
1376 /*//////////////////////////////////////////////////////////////////////////////////////// */
1377 /*--------------------------------------- */
1378 int system_setting_get_locale_country(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1379 {
1380         SETTING_TRACE_BEGIN;
1381         char *vconf_value = NULL;
1382         if (system_setting_vconf_get_value_string(VCONFKEY_REGIONFORMAT, &vconf_value)) {
1383                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1384         }
1385
1386         /* parsing validation */
1387         /* en_US.UTF-8 */
1388         char arr[20];
1389         snprintf(arr, 20, "%s", vconf_value);
1390         arr[5] = '\0';
1391         *value = strdup(arr);
1392         free(vconf_value);
1393         vconf_value = NULL;
1394
1395         return SYSTEM_SETTINGS_ERROR_NONE;
1396 }
1397
1398 /*  LCOV_EXCL_START */
1399 int system_setting_set_locale_country(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1400 {
1401         SETTING_TRACE_BEGIN;
1402         char *vconf_value = NULL;
1403         vconf_value = (char *)value;
1404
1405         char *ext = "UTF-8";
1406
1407         char arr[20];
1408         snprintf(arr, 20, "%s.%s", vconf_value, ext);
1409
1410         if (system_setting_vconf_set_value_string(VCONFKEY_REGIONFORMAT, arr)) {
1411                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1412         }
1413         return SYSTEM_SETTINGS_ERROR_NONE;
1414 }
1415 /*  LCOV_EXCL_STOP */
1416
1417 int system_setting_set_changed_callback_locale_country(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1418 {
1419         SETTING_TRACE_BEGIN;
1420         return system_setting_vconf_set_changed_cb(VCONFKEY_REGIONFORMAT, SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, 3, user_data);
1421 }
1422
1423 int system_setting_unset_changed_callback_locale_country(system_settings_key_e key)
1424 {
1425         SETTING_TRACE_BEGIN;
1426         return system_setting_vconf_unset_changed_cb(VCONFKEY_REGIONFORMAT, 3);
1427 }
1428
1429
1430 /*--------------------------------------- */
1431 int system_setting_get_locale_language(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1432 {
1433         SETTING_TRACE_BEGIN;
1434         char *vconf_value = NULL;
1435         if (system_setting_vconf_get_value_string(VCONFKEY_LANGSET, &vconf_value)) {
1436                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1437         }
1438
1439         /* parsing validation */
1440         /* en_US.UTF-8 */
1441         char arr[20];
1442         snprintf(arr, 20, "%s", vconf_value);
1443         arr[5] = '\0';
1444         *value = strdup(arr);
1445         free(vconf_value);
1446         vconf_value = NULL;
1447         return SYSTEM_SETTINGS_ERROR_NONE;
1448 }
1449
1450 /*  LCOV_EXCL_START */
1451 int system_setting_set_locale_language(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1452 {
1453         SETTING_TRACE_BEGIN;
1454         char *vconf_value = NULL;
1455         vconf_value = (char *)value;
1456
1457         char *ext = "UTF-8";
1458
1459         char arr[20];
1460         snprintf(arr, 20, "%s.%s", vconf_value, ext);
1461
1462         if (system_setting_vconf_set_value_string(VCONFKEY_LANGSET, arr)) {
1463                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1464         }
1465         return SYSTEM_SETTINGS_ERROR_NONE;
1466 }
1467 /*  LCOV_EXCL_STOP */
1468
1469 int system_setting_set_changed_callback_locale_language(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1470 {
1471         SETTING_TRACE_BEGIN;
1472         /*return system_setting_vconf_set_changed_cb(VCONFKEY_LANGSET, SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, 3, user_data ); */
1473         return system_setting_vconf_set_changed_cb(VCONFKEY_LANGSET, SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, 100, user_data);
1474 }
1475
1476 int system_setting_unset_changed_callback_locale_language(system_settings_key_e key)
1477 {
1478         SETTING_TRACE_BEGIN;
1479         return system_setting_vconf_unset_changed_cb(VCONFKEY_LANGSET, 100);
1480 }
1481
1482 /*--------------------------------------- */
1483 /*  LCOV_EXCL_START */
1484 int system_setting_get_locale_timeformat_24hour(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1485 {
1486         SETTING_TRACE_BEGIN;
1487         int vconf_value;
1488
1489         if (system_setting_vconf_get_value_int(VCONFKEY_REGIONFORMAT_TIME1224, &vconf_value)) {
1490                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1491         }
1492
1493         bool ret_value = true;
1494         if (vconf_value == VCONFKEY_TIME_FORMAT_12)
1495                 ret_value = false;
1496         else if (vconf_value == VCONFKEY_TIME_FORMAT_24)
1497                 ret_value = true;
1498
1499         *value = (void *)ret_value;
1500
1501         return SYSTEM_SETTINGS_ERROR_NONE;
1502 }
1503 /*  LCOV_EXCL_STOP */
1504
1505 int system_setting_set_locale_timeformat_24hour(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1506 {
1507         SETTING_TRACE_BEGIN;
1508         bool *vconf_value;
1509
1510         vconf_value = (bool *)value;
1511
1512         if (*vconf_value) {
1513                 if (system_setting_vconf_set_value_int(VCONFKEY_REGIONFORMAT_TIME1224, VCONFKEY_TIME_FORMAT_24)) {
1514                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1515                 }
1516
1517         } else {
1518                 if (system_setting_vconf_set_value_int(VCONFKEY_REGIONFORMAT_TIME1224, VCONFKEY_TIME_FORMAT_12)) {
1519                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1520                 }
1521
1522         }
1523
1524         return SYSTEM_SETTINGS_ERROR_NONE;
1525 }
1526
1527 int system_setting_set_changed_callback_locale_timeformat_24hour(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1528 {
1529         SETTING_TRACE_BEGIN;
1530         return system_setting_vconf_set_changed_cb(VCONFKEY_REGIONFORMAT_TIME1224, SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, 3, user_data);
1531 }
1532
1533 int system_setting_unset_changed_callback_locale_timeformat_24hour(system_settings_key_e key)
1534 {
1535         SETTING_TRACE_BEGIN;
1536         return system_setting_vconf_unset_changed_cb(VCONFKEY_REGIONFORMAT_TIME1224, 3);
1537 }
1538
1539 int system_setting_get_locale_timezone(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1540 {
1541         char tzpath[256];
1542         ssize_t len = readlink(SETTING_TZONE_SYMLINK_PATH, tzpath, sizeof(tzpath)-1);
1543         if (len != -1) {
1544                 tzpath[len] = '\0';
1545         } else {
1546                 SETTING_TRACE("parse error for SETTING_TZONE_SYMLINK_PATH");
1547                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1548         }
1549
1550         SETTING_TRACE("tzpath : %s ", &tzpath[20]);
1551         *value = strdup(&tzpath[20]);
1552         return SYSTEM_SETTINGS_ERROR_NONE;
1553 }
1554
1555 /*  LCOV_EXCL_START */
1556 int system_setting_set_locale_timezone(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1557 {
1558         SETTING_TRACE_BEGIN;
1559         char *timezone_value = NULL;
1560         timezone_value = (char *)value;
1561
1562         char tz_path[1024];
1563         snprintf(tz_path, 1024, "/usr/share/zoneinfo/%s", timezone_value);
1564
1565         int is_load = _is_file_accessible(tz_path);
1566         if (is_load == 0) {
1567                 alarmmgr_set_timezone(tz_path);
1568
1569                 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_TIMEZONE_ID, timezone_value)) {
1570                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1571                 }
1572                 return SYSTEM_SETTINGS_ERROR_NONE;
1573         }
1574         return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
1575 }
1576 /*  LCOV_EXCL_STOP */
1577
1578
1579
1580 /*  LCOV_EXCL_START */
1581 int system_setting_set_changed_callback_locale_timezone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1582 {
1583         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_TIMEZONE_ID, SYSTEM_SETTINGS_KEY_LOCALE_TIMEZONE, 4, user_data);
1584 }
1585 /*  LCOV_EXCL_STOP */
1586
1587 /*  LCOV_EXCL_START */
1588 int system_setting_unset_changed_callback_locale_timezone(system_settings_key_e key)
1589 {
1590         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_TIMEZONE_ID, 4);
1591 }
1592 /*  LCOV_EXCL_STOP */
1593
1594 /*  LCOV_EXCL_START */
1595 int system_setting_set_changed_callback_locale_timezone_changed(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1596 {
1597         SETTING_TRACE_BEGIN;
1598         return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
1599 }
1600 /*  LCOV_EXCL_STOP */
1601
1602 /*  LCOV_EXCL_START */
1603 int system_setting_unset_changed_callback_locale_timezone_changed(system_settings_key_e key)
1604 {
1605         SETTING_TRACE_BEGIN;
1606         return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
1607 }
1608 /*  LCOV_EXCL_STOP */
1609
1610
1611 /*  LCOV_EXCL_START */
1612 int system_setting_get_time_changed(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1613 {
1614         SETTING_TRACE_BEGIN;
1615         time_t cur_tick;
1616         int ** val = (int**)value;
1617         cur_tick = time(NULL);
1618         **val = cur_tick;
1619         /* struct tm * localtime = time (cur_tick); */
1620         /* printf("%s\n", ctime(&cur_tick); */
1621         return SYSTEM_SETTINGS_ERROR_NONE;
1622
1623 }
1624 /*  LCOV_EXCL_STOP */
1625
1626 int system_setting_set_changed_callback_time_changed(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1627 {
1628         SETTING_TRACE_BEGIN;
1629         return system_setting_vconf_set_changed_cb(VCONFKEY_SYSTEM_TIME_CHANGED, SYSTEM_SETTINGS_KEY_TIME_CHANGED, 3, user_data);
1630 }
1631
1632 int system_setting_unset_changed_callback_time_changed(system_settings_key_e key)
1633 {
1634         SETTING_TRACE_BEGIN;
1635         return system_setting_vconf_unset_changed_cb(VCONFKEY_SYSTEM_TIME_CHANGED, 3);
1636 }
1637
1638
1639
1640 /* SYSTEM_SETTINGS_KEY_SOUND_LOCK */
1641 int system_setting_get_sound_lock(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1642 {
1643         SETTING_TRACE_BEGIN;
1644         bool vconf_value;
1645
1646         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_SOUND_LOCK_BOOL, &vconf_value)) {
1647                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1648         }
1649         *value = (void *)vconf_value;
1650
1651         return SYSTEM_SETTINGS_ERROR_NONE;
1652 }
1653
1654 int system_setting_set_changed_callback_sound_lock(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1655 {
1656         SETTING_TRACE_BEGIN;
1657         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_SOUND_LOCK_BOOL, SYSTEM_SETTINGS_KEY_SOUND_LOCK, 3, user_data);
1658 }
1659
1660 int system_setting_unset_changed_callback_sound_lock(system_settings_key_e key)
1661 {
1662         SETTING_TRACE_BEGIN;
1663         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_SOUND_LOCK_BOOL, 3);
1664 }
1665
1666 /**
1667  * a = VCONFKEY_SETAPPL_SOUND_STATUS_BOOL b = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL
1668  *
1669  * a == false, b == false --> silent mode
1670  * a == true, b == false --> sound mode
1671  * a == false, b == true --> vibration mode
1672  */
1673 /*  LCOV_EXCL_START */
1674 int system_setting_get_sound_silent_mode(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1675 {
1676         SETTING_TRACE_BEGIN;
1677         bool sound_cond;
1678         bool vib_cond;
1679
1680         bool vconf_value;
1681         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_cond)) {
1682                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1683         }
1684
1685         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vib_cond)) {
1686                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1687         }
1688
1689         if (sound_cond == false && vib_cond == false) {
1690                 vconf_value = true;
1691                 *value = (void *)vconf_value;
1692         } else {
1693                 vconf_value = false;
1694                 *value = (void *)vconf_value;
1695         }
1696         return SYSTEM_SETTINGS_ERROR_NONE;
1697 }
1698 /*  LCOV_EXCL_STOP */
1699
1700 /**
1701  * a = VCONFKEY_SETAPPL_SOUND_STATUS_BOOL b = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL
1702  *
1703  * a == false, b == false --> silent mode
1704  * a == true, b == false --> sound mode
1705  */
1706 int system_setting_set_sound_silent_mode(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1707 {
1708         SETTING_TRACE_BEGIN;
1709         bool *vconf_value;
1710
1711         vconf_value = (bool *)value;
1712
1713         bool vconf_sound = false;
1714         bool vconf_vib = false;
1715
1716         if (*vconf_value) {
1717                 vconf_sound = false;
1718                 vconf_vib = false;
1719         } else {
1720                 vconf_sound = true;
1721                 vconf_vib = false;
1722         }
1723
1724         if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, vconf_sound)) {
1725                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1726         }
1727         if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, vconf_vib)) {
1728                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1729         }
1730
1731         return SYSTEM_SETTINGS_ERROR_NONE;
1732 }
1733
1734
1735
1736 /* TODO */
1737 int system_setting_set_changed_callback_sound_silent_mode(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1738 {
1739         SETTING_TRACE_BEGIN;
1740         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, SYSTEM_SETTINGS_KEY_SOUND_SILENT_MODE, 3, user_data);
1741 }
1742
1743 /* TODO */
1744 int system_setting_unset_changed_callback_sound_silent_mode(system_settings_key_e key)
1745 {
1746         SETTING_TRACE_BEGIN;
1747         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, 3);
1748 }
1749
1750 /* SYSTEM_SETTINGS_KEY_SOUND_TOUCH */
1751 int system_setting_get_sound_touch(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1752 {
1753         SETTING_TRACE_BEGIN;
1754         bool vconf_value;
1755
1756         int ret = system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, &vconf_value);
1757         if (ret != SYSTEM_SETTINGS_ERROR_NONE) {
1758                 return ret;
1759         }
1760         *value = (void *)vconf_value;
1761         return ret;
1762 }
1763
1764 int system_setting_set_changed_callback_sound_touch(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1765 {
1766         SETTING_TRACE_BEGIN;
1767         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, SYSTEM_SETTINGS_KEY_SOUND_TOUCH, 2, user_data);
1768 }
1769
1770 int system_setting_unset_changed_callback_sound_touch(system_settings_key_e key)
1771 {
1772         SETTING_TRACE_BEGIN;
1773         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, 2);
1774 }
1775
1776 #if 0
1777 /* SYSTEM_SETTINGS_KEY_SOUND_LOCK */
1778 int system_setting_get_sound_lock(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1779 {
1780         bool vconf_value;
1781
1782         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_SOUND_LOCK_BOOL, &vconf_value)) {
1783                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1784         }
1785         *value = (void *)vconf_value;
1786
1787         return SYSTEM_SETTINGS_ERROR_NONE;
1788 }
1789 #endif
1790
1791 int system_setting_get_auto_rotation_mode(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1792 {
1793         SETTING_TRACE_BEGIN;
1794         bool vconf_value;
1795
1796         if (system_setting_vconf_get_value_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &vconf_value)) {
1797                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1798         }
1799         *value = (void *)vconf_value;
1800
1801         return SYSTEM_SETTINGS_ERROR_NONE;
1802 }
1803
1804 /*  LCOV_EXCL_START */
1805 int system_setting_set_auto_rotation_mode(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1806 {
1807         SETTING_TRACE_BEGIN;
1808         bool *vconf_value;
1809         vconf_value = (bool *)value;
1810         if (system_setting_vconf_set_value_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, *vconf_value)) {
1811                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1812         }
1813
1814         return SYSTEM_SETTINGS_ERROR_NONE;
1815 }
1816 /*  LCOV_EXCL_STOP */
1817
1818 int system_setting_set_changed_callback_auto_rotation_mode(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1819 {
1820         SETTING_TRACE_BEGIN;
1821         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, SYSTEM_SETTINGS_KEY_DISPLAY_SCREEN_ROTATION_AUTO, 2, user_data);
1822 }
1823
1824 int system_setting_unset_changed_callback_auto_rotation_mode(system_settings_key_e key)
1825 {
1826         SETTING_TRACE_BEGIN;
1827         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, 2);
1828 }
1829
1830 int system_setting_get_screen_backlight_time(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1831 {
1832         SETTING_TRACE_BEGIN;
1833         int vconf_value;
1834         int ** val = (int**)value;
1835
1836         if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, &vconf_value)) {
1837                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1838         }
1839         **val = vconf_value;
1840
1841         return SYSTEM_SETTINGS_ERROR_NONE;
1842 }
1843
1844
1845 /*  LCOV_EXCL_START */
1846 int system_setting_set_screen_backlight_time(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1847 {
1848         SETTING_TRACE_BEGIN;
1849         int *vconf_value;
1850         vconf_value = *(int **)value;
1851
1852         if (!(*vconf_value > 0 && *vconf_value < 600)) {
1853                 SETTING_TRACE(" ERR Betweeny here  0 ~ 600");
1854                 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
1855         }
1856
1857         if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, *vconf_value)) {
1858                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1859         }
1860         SETTING_TRACE_END;
1861         return SYSTEM_SETTINGS_ERROR_NONE;
1862 }
1863 /*  LCOV_EXCL_STOP */
1864
1865 int system_setting_set_changed_callback_screen_backlight_time(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1866 {
1867         SETTING_TRACE_BEGIN;
1868         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, SYSTEM_SETTINGS_KEY_DISPLAY_SCREEN_ROTATION_AUTO, 2, user_data);
1869 }
1870
1871 int system_setting_unset_changed_callback_screen_backlight_time(system_settings_key_e key)
1872 {
1873         SETTING_TRACE_BEGIN;
1874         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 2);
1875 }
1876
1877 int system_setting_get_sound_notification(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1878 {
1879         SETTING_TRACE_BEGIN;
1880         char *vconf_value = NULL;
1881         if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, &vconf_value)) {
1882                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1883         }
1884
1885         *value = vconf_value;
1886         return SYSTEM_SETTINGS_ERROR_NONE;
1887 }
1888
1889 /*  LCOV_EXCL_START */
1890 int system_setting_set_sound_notification(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1891 {
1892         SETTING_TRACE_BEGIN;
1893         char *vconf_value = NULL;
1894         vconf_value = (char *)value;
1895
1896         int is_load = _is_file_accessible(vconf_value);
1897         if (is_load == 0) {
1898                 if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, vconf_value)) {
1899                         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1900                 }
1901         } else {
1902                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1903         }
1904
1905         return SYSTEM_SETTINGS_ERROR_NONE;
1906 }
1907 /*  LCOV_EXCL_STOP */
1908
1909 int system_setting_set_changed_callback_sound_notification(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1910 {
1911         SETTING_TRACE_BEGIN;
1912         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, 0, user_data);
1913 }
1914
1915 int system_setting_unset_changed_callback_sound_notification(system_settings_key_e key)
1916 {
1917         SETTING_TRACE_BEGIN;
1918         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, 0);
1919 }
1920
1921 int system_setting_get_notification_repetition_period(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1922 {
1923         SETTING_TRACE_BEGIN;
1924         int ** val = (int**)value;
1925         int vconf_value;
1926
1927         if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_NOTI_MSG_ALERT_REP_TYPE_INT, &vconf_value)) {
1928                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1929         }
1930         **val = vconf_value;
1931
1932         return SYSTEM_SETTINGS_ERROR_NONE;
1933 }
1934
1935 /*  LCOV_EXCL_START */
1936 int system_setting_set_notification_repetition_period(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1937 {
1938         SETTING_TRACE_BEGIN;
1939         int *vconf_value;
1940         vconf_value = *(int **)value;
1941
1942         if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_NOTI_MSG_ALERT_REP_TYPE_INT, *vconf_value)) {
1943                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1944         }
1945         SETTING_TRACE_END;
1946         return SYSTEM_SETTINGS_ERROR_NONE;
1947 }
1948 /*  LCOV_EXCL_STOP */
1949
1950 int system_setting_set_changed_callback_notification_repetition_period(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1951 {
1952         SETTING_TRACE_BEGIN;
1953         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_NOTI_MSG_ALERT_REP_TYPE_INT, SYSTEM_SETTINGS_KEY_SOUND_NOTIFICATION_REPETITION_PERIOD, 1, user_data);
1954 }
1955
1956 int system_setting_unset_changed_callback_notification_repetition_period(system_settings_key_e key)
1957 {
1958         SETTING_TRACE_BEGIN;
1959         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_NOTI_MSG_ALERT_REP_TYPE_INT, 1);
1960 }
1961
1962 int system_setting_get_device_name(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
1963 {
1964         SETTING_TRACE_BEGIN;
1965         char *vconf_value = NULL;
1966         if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_DEVICE_NAME_STR, &vconf_value)) {
1967                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1968         }
1969
1970         *value = vconf_value;
1971         return SYSTEM_SETTINGS_ERROR_NONE;
1972 }
1973
1974 /*  LCOV_EXCL_START */
1975 int system_setting_set_device_name(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
1976 {
1977         SETTING_TRACE_BEGIN;
1978         char *vconf_value = NULL;
1979         vconf_value = (char *)value;
1980
1981         if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_DEVICE_NAME_STR, vconf_value)) {
1982                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
1983         }
1984
1985         return SYSTEM_SETTINGS_ERROR_NONE;
1986 }
1987 /*  LCOV_EXCL_STOP */
1988
1989 int system_setting_set_changed_callback_device_name(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
1990 {
1991         SETTING_TRACE_BEGIN;
1992         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_DEVICE_NAME_STR, SYSTEM_SETTINGS_KEY_DEVICE_NAME, 0, user_data);
1993 }
1994
1995 int system_setting_unset_changed_callback_device_name(system_settings_key_e key)
1996 {
1997         SETTING_TRACE_BEGIN;
1998         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_DEVICE_NAME_STR, 0);
1999 }
2000
2001 /*---------------------------------------------- */
2002 int system_setting_get_network_flight_mode(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
2003 {
2004         SETTING_TRACE_BEGIN;
2005         bool vconf_value;
2006         if (system_setting_vconf_get_value_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &vconf_value)) {
2007                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
2008         }
2009         *value = (void *)vconf_value;
2010
2011         return SYSTEM_SETTINGS_ERROR_NONE;
2012 }
2013
2014 int system_setting_set_changed_callback_network_flight_mode(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
2015 {
2016         SETTING_TRACE_BEGIN;
2017         return system_setting_vconf_set_changed_cb(VCONFKEY_TELEPHONY_FLIGHT_MODE, SYSTEM_SETTINGS_KEY_NETWORK_FLIGHT_MODE, 3, user_data);
2018 }
2019
2020 int system_setting_unset_changed_callback_network_flight_mode(system_settings_key_e key)
2021 {
2022         SETTING_TRACE_BEGIN;
2023         return system_setting_vconf_unset_changed_cb(VCONFKEY_TELEPHONY_FLIGHT_MODE, 3);
2024 }
2025
2026 int system_setting_get_network_wifi_notification(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
2027 {
2028         SETTING_TRACE_BEGIN;
2029         int vconf_value;
2030         if (system_setting_vconf_get_value_int(VCONFKEY_WIFI_ENABLE_QS, &vconf_value)) {
2031                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
2032         }
2033         bool bret ;
2034         bret = (vconf_value == VCONFKEY_WIFI_QS_ENABLE) ? true : false;
2035
2036         *value = (void *)bret;
2037         return SYSTEM_SETTINGS_ERROR_NONE;
2038 }
2039
2040 int system_setting_set_changed_callback_network_wifi_notification(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
2041 {
2042         SETTING_TRACE_BEGIN;
2043         return system_setting_vconf_set_changed_cb(VCONFKEY_WIFI_ENABLE_QS, SYSTEM_SETTINGS_KEY_NETWORK_WIFI_NOTIFICATION, 4, user_data);
2044 }
2045
2046 int system_setting_unset_changed_callback_network_wifi_notification(system_settings_key_e key)
2047 {
2048         SETTING_TRACE_BEGIN;
2049         return system_setting_vconf_unset_changed_cb(VCONFKEY_WIFI_ENABLE_QS, 4);
2050 }
2051
2052 /*  LCOV_EXCL_START */
2053 int system_setting_get_lock_state(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
2054 {
2055         int vconf_value;
2056         int ** val = (int**)value;
2057
2058         if (system_setting_vconf_get_value_int(VCONFKEY_IDLE_LOCK_STATE_READ_ONLY, &vconf_value)) {
2059                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
2060         }
2061         **val = vconf_value;
2062
2063         return SYSTEM_SETTINGS_ERROR_NONE;
2064 }
2065 /*  LCOV_EXCL_STOP */
2066
2067 /*  LCOV_EXCL_START */
2068 int system_setting_set_lock_state(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
2069 {
2070         SETTING_TRACE_BEGIN;
2071         int *vconf_value;
2072         vconf_value = *(int **)value;
2073
2074         if (system_setting_vconf_set_value_int(VCONFKEY_IDLE_LOCK_STATE_READ_ONLY, *vconf_value)) {
2075                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
2076         }
2077         SETTING_TRACE_END;
2078         return SYSTEM_SETTINGS_ERROR_NONE;
2079 }
2080 /*  LCOV_EXCL_STOP */
2081
2082 /*  LCOV_EXCL_START */
2083 int system_setting_set_changed_callback_lock_state(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
2084 {
2085         return system_setting_vconf_set_changed_cb(VCONFKEY_IDLE_LOCK_STATE_READ_ONLY, SYSTEM_SETTINGS_KEY_LOCK_STATE, 4, user_data);
2086 }
2087 /*  LCOV_EXCL_STOP */
2088
2089 /*  LCOV_EXCL_START */
2090 int system_setting_unset_changed_callback_lock_state(system_settings_key_e key)
2091 {
2092         return system_setting_vconf_unset_changed_cb(VCONFKEY_IDLE_LOCK_STATE_READ_ONLY, 4);
2093 }
2094 /*  LCOV_EXCL_STOP */
2095
2096 //----------------------------------------------------------------------------------------------------------------------------
2097
2098 #define DEFAULT_ADS_ID "00000000-0000-0000-0000-000000000000"
2099
2100 int system_setting_get_ads_id(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
2101 {
2102         SETTING_TRACE_BEGIN;
2103         int optout_value = 0;
2104         if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_AD_ID_OPT_OUT, &optout_value)) {
2105                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
2106         }
2107
2108         if (optout_value == 1) {
2109                 *value = strdup(DEFAULT_ADS_ID);
2110                 return SYSTEM_SETTINGS_ERROR_NONE;
2111         }
2112
2113         char *vconf_value = NULL;
2114         if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_AD_ID, &vconf_value)) {
2115                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
2116         }
2117
2118         *value = vconf_value;
2119         return SYSTEM_SETTINGS_ERROR_NONE;
2120 }
2121
2122
2123 #if 0
2124 void make_ad_id(void)
2125 {
2126         uuid_t uuid_value;
2127         char uuid_unparsed[50] = {0};
2128         uuid_generate(uuid_value);
2129         uuid_unparse(uuid_value, uuid_unparsed);
2130         system_setting_set_ad_id(key, uuid_unparsed); //example of setting the value
2131 }
2132 #endif
2133 /*  LCOV_EXCL_START */
2134 int system_setting_set_ads_id(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
2135 {
2136         SETTING_TRACE_BEGIN;
2137         char *vconf_value = NULL;
2138         vconf_value = (char *)value;
2139
2140         if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_AD_ID, vconf_value)) {
2141                 SETTING_TRACE("Setting VCONFKEY_SETAPPL_AD_ID failed");
2142                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
2143         }
2144
2145         return SYSTEM_SETTINGS_ERROR_NONE;
2146 }
2147 /*  LCOV_EXCL_STOP */
2148
2149 int system_setting_set_changed_callback_ads_id(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
2150 {
2151         SETTING_TRACE_BEGIN;
2152         return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_AD_ID, SYSTEM_SETTINGS_KEY_ADS_ID, 0, user_data);
2153 }
2154
2155 int system_setting_unset_changed_callback_ads_id(system_settings_key_e key)
2156 {
2157         SETTING_TRACE_BEGIN;
2158         return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_AD_ID, 0);
2159 }
2160
2161