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