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