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