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