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