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