From: Youngjae Shin Date: Fri, 12 Jun 2020 05:45:14 +0000 (+0900) Subject: [refactoring] revise interface X-Git-Tag: accepted/tizen/unified/20200616.171019^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F27%2F236027%2F3;p=platform%2Fcore%2Fapi%2Fsystem-settings.git [refactoring] revise interface Change-Id: I8edaea36967e383d7b9b5ed263e42a9ebcb78d32 --- diff --git a/common/sst_define.h b/common/sst_define.h index b1ca4cf..880560a 100644 --- a/common/sst_define.h +++ b/common/sst_define.h @@ -20,6 +20,14 @@ #endif #define API __attribute__((visibility("default"))) +#ifndef FALSE +#define FALSE (0) +#endif + +#ifndef TRUE +#define TRUE (1) +#endif + #define SST_EQUAL 0 #ifndef SST_RES_DIR diff --git a/libutil/sstu.c b/libutil/sstu.c index cebc179..109421d 100644 --- a/libutil/sstu.c +++ b/libutil/sstu.c @@ -22,7 +22,6 @@ #include #include "system_settings.h" #include "sst.h" -#include "sst_core.h" #ifdef TIZEN_WEARABLE #define SMALL_FONT_DPI (-90) @@ -89,7 +88,7 @@ static char* _get_main_font_family(char *alias) return ret; } -API bool sstu_is_valid_image(char *path) +API bool sstu_is_valid_image(const char *path) { void *ee; void *evas; @@ -122,7 +121,7 @@ API void sstu_font_config_set_notification() { } -API int sstu_is_available_font(char *font_name) +API int sstu_is_available_font(const char *font_name) { FcObjectSet *os; FcFontSet *fs; @@ -264,10 +263,10 @@ static int _get_font_size() return font_size; } -API bool sstu_set_font_config(char *font_name) +API bool sstu_set_font_config(const char *font_name) { int font_size = _get_font_size(); - return eext_config_font_set(font_name, font_size); + return eext_config_font_set((char*)font_name, font_size); } API void sstu_set_font_size() diff --git a/src/sst_api.c b/src/sst_api.c index 9d05632..0a35146 100644 --- a/src/sst_api.c +++ b/src/sst_api.c @@ -16,26 +16,33 @@ #include "system_settings.h" #include "sst.h" -#include "sst_core.h" -#include "sst_misc.h" #include "sst_vconf.h" +#include "sst_sound.h" #include "sst_interface.h" API int system_settings_set_value_int(system_settings_key_e key, int value) { int ret; + sst_interface *iface = NULL; + ret = sst_get_interface(key, &iface); + if (SYSTEM_SETTINGS_ERROR_NONE != ret) { + ERR("sst_get_interface(%d) Fail(%d)", key, ret); + return ret; + } - DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); + if (SYSTEM_SETTING_DATA_TYPE_INT != iface->data_type) { + ERR("Invalide type for key(%d) : %d", key, iface->data_type); + return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; + } - //todo: need to revise - int *ptr = &value; - int **p_ptr = &ptr; + if (NULL == iface->setter.i) { + ERR("No setter for key(%d)", key); + return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED; + } - ret = sst_set_value(key, SYSTEM_SETTING_DATA_TYPE_INT, (void*)p_ptr); + ret = iface->setter.i(iface, value); if (SYSTEM_SETTINGS_ERROR_NONE != ret) { - ERR("sst_set_value(%d) Fail(%d)", key, ret); + ERR("setter(%d) Fail(%d)", key, ret); return ret; } @@ -45,90 +52,152 @@ API int system_settings_set_value_int(system_settings_key_e key, int value) API int system_settings_get_value_int(system_settings_key_e key, int *value) { int ret; - int value_int = 0; - int *ptr = &value_int; - int **p_ptr = &ptr; + sst_interface *iface = NULL; + ret = sst_get_interface(key, &iface); + if (SYSTEM_SETTINGS_ERROR_NONE != ret) { + ERR("sst_get_interface(%d) Fail(%d)", key, ret); + return ret; + } - DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); + if (SYSTEM_SETTING_DATA_TYPE_INT != iface->data_type) { + ERR("Invalide type for key(%d) : %d", key, iface->data_type); + return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; + } + + if (NULL == iface->getter.i) { + ERR("No getter for key(%d)", key); + return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED; + } - ret = sst_get_value(key, SYSTEM_SETTING_DATA_TYPE_INT, (void **)p_ptr); + int result = 0; + ret = iface->getter.i(iface, &result); if (SYSTEM_SETTINGS_ERROR_NONE != ret) { - ERR("sst_get_value(%d) Fail(%d)", key, ret); + ERR("getter(%d) Fail(%d)", key, ret); return ret; } - *value = value_int; + + *value = result; return SYSTEM_SETTINGS_ERROR_NONE; } API int system_settings_set_value_bool(system_settings_key_e key, bool value) { - DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); + int ret; + sst_interface *iface = NULL; + ret = sst_get_interface(key, &iface); + if (SYSTEM_SETTINGS_ERROR_NONE != ret) { + ERR("sst_get_interface(%d) Fail(%d)", key, ret); + return ret; + } + + if (SYSTEM_SETTING_DATA_TYPE_BOOL != iface->data_type) { + ERR("Invalide type for key(%d) : %d", key, iface->data_type); + return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; + } - bool *ptr = &value; - int ret = sst_set_value(key, SYSTEM_SETTING_DATA_TYPE_BOOL, (void*)ptr); - if (SYSTEM_SETTINGS_ERROR_NONE != ret) - ERR("sst_set_value(%d), Fail(%d)", key, ret); + if (NULL == iface->setter.b) { + ERR("No setter for key(%d)", key); + return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED; + } - return ret; + ret = iface->setter.b(iface, value); + if (SYSTEM_SETTINGS_ERROR_NONE != ret) { + ERR("setter(%d) Fail(%d)", key, ret); + return ret; + } + + return SYSTEM_SETTINGS_ERROR_NONE; } API int system_settings_get_value_bool(system_settings_key_e key, bool *value) { int ret; - signed long flag = 0; + sst_interface *iface = NULL; + ret = sst_get_interface(key, &iface); + if (SYSTEM_SETTINGS_ERROR_NONE != ret) { + ERR("sst_get_interface(%d) Fail(%d)", key, ret); + return ret; + } - DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); - - ret = sst_get_value(key, SYSTEM_SETTING_DATA_TYPE_BOOL, (void **)&flag); - SECURE_ERR(" inf (flag) value : %ld ", flag); - if (flag == 0) { - *value = false; - SECURE_ERR(" flag == 0 "); - } else if (flag == 1) { - *value = true; - SECURE_ERR(" flag == 1 "); - } else { - *value = false; - SECURE_ERR(" exception here!!! "); - } - - return ret; -} + if (SYSTEM_SETTING_DATA_TYPE_BOOL != iface->data_type) { + ERR("Invalide type for key(%d) : %d", key, iface->data_type); + return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; + } + + if (NULL == iface->getter.b) { + ERR("No getter for key(%d)", key); + return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED; + } + + bool result = 0; + ret = iface->getter.b(iface, &result); + if (SYSTEM_SETTINGS_ERROR_NONE != ret) { + ERR("getter(%d) Fail(%d)", key, ret); + return ret; + } + *value = result; + return SYSTEM_SETTINGS_ERROR_NONE; +} API int system_settings_set_value_string(system_settings_key_e key, const char *value) { - DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); - RETVM_IF(key == SYSTEM_SETTINGS_KEY_DEFAULT_FONT_TYPE, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, - "The defualt font type is only support getter"); + int ret; + sst_interface *iface = NULL; + ret = sst_get_interface(key, &iface); + if (SYSTEM_SETTINGS_ERROR_NONE != ret) { + ERR("sst_get_interface(%d) Fail(%d)", key, ret); + return ret; + } - int ret = sst_set_value(key, SYSTEM_SETTING_DATA_TYPE_STRING, (void*)value); - if (SYSTEM_SETTINGS_ERROR_NONE != ret) - ERR("sst_set_value(%d), Fail(%d)", key, ret); + if (SYSTEM_SETTING_DATA_TYPE_STRING != iface->data_type) { + ERR("Invalide type for key(%d) : %d", key, iface->data_type); + return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; + } - return ret; + if (NULL == iface->setter.s) { + ERR("No setter for key(%d)", key); + return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED; + } + + ret = iface->setter.s(iface, value); + if (SYSTEM_SETTINGS_ERROR_NONE != ret) { + ERR("setter(%d) Fail(%d)", key, ret); + return ret; + } + + return SYSTEM_SETTINGS_ERROR_NONE; } API int system_settings_get_value_string(system_settings_key_e key, char **value) { - DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); + int ret; + sst_interface *iface = NULL; + ret = sst_get_interface(key, &iface); + if (SYSTEM_SETTINGS_ERROR_NONE != ret) { + ERR("sst_get_interface(%d) Fail(%d)", key, ret); + return ret; + } + + if (SYSTEM_SETTING_DATA_TYPE_STRING != iface->data_type) { + ERR("Invalide type for key(%d) : %d", key, iface->data_type); + return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; + } - int ret = sst_get_value(key, SYSTEM_SETTING_DATA_TYPE_STRING, (void **)value); - if (SYSTEM_SETTINGS_ERROR_NONE != ret) - ERR("sst_get_value(%d), Fail(%d)", key, ret); + if (NULL == iface->getter.s) { + ERR("No getter for key(%d)", key); + return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED; + } - return ret; + char *result = NULL; + ret = iface->getter.s(iface, &result); + if (SYSTEM_SETTINGS_ERROR_NONE != ret) { + ERR("getter(%d) Fail(%d)", key, ret); + return ret; + } + + *value = result; + return SYSTEM_SETTINGS_ERROR_NONE; } //todo: need to deprecate @@ -136,12 +205,6 @@ API int system_settings_set_changed_cb(system_settings_key_e key, system_setting { int ret; - DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); - RETVM_IF(key == SYSTEM_SETTINGS_KEY_DEFAULT_FONT_TYPE, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, - "The defualt font type is only supporting getter"); RETV_IF(NULL == callback, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); sst_interface *iface = NULL; @@ -162,13 +225,6 @@ API int system_settings_set_changed_cb(system_settings_key_e key, system_setting //todo: need to deprecate API int system_settings_unset_changed_cb(system_settings_key_e key) { - DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); - RETVM_IF(key == SYSTEM_SETTINGS_KEY_DEFAULT_FONT_TYPE, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, - "The defualt font type is only support getter"); - sst_interface *iface = NULL; int ret = sst_get_interface(key, &iface); if (SYSTEM_SETTINGS_ERROR_NONE != ret) { @@ -187,42 +243,37 @@ API int system_settings_unset_changed_cb(system_settings_key_e key) API int system_settings_foreach_value_string(system_settings_key_e key, system_settings_iter_cb callback, void *value) { DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); + RETVM_IF(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE != key, + SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, + "Invalid Key(%d)", key); - return sst_list_value(key, SYSTEM_SETTING_DATA_TYPE_STRING, callback, (void*)value); + return sst_sound_get_call_ringtone_list(key, callback, value); } API int system_settings_add_value_string(system_settings_key_e key, const char* value) { DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, + RETVM_IF(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE != key, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); - return sst_add_value(key, SYSTEM_SETTING_DATA_TYPE_STRING, (void*)value); + return sst_sound_add_call_ringtone(key, value); } API int system_settings_delete_value_string(system_settings_key_e key, const char* value) { DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, + RETVM_IF(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE != key, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); - return sst_del_value(key, SYSTEM_SETTING_DATA_TYPE_STRING, (void*)value); + return sst_sound_del_call_ringtone(key, value); } API int system_settings_add_changed_cb(system_settings_key_e key, system_settings_changed_cb callback, void *user_data) { int ret; - DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); - RETVM_IF(key == SYSTEM_SETTINGS_KEY_DEFAULT_FONT_TYPE, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, - "The defualt font type is only support getter"); RETV_IF(NULL == callback, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); sst_interface *iface = NULL; @@ -234,7 +285,7 @@ API int system_settings_add_changed_cb(system_settings_key_e key, system_setting if (NULL == iface->vconf_key) { ERR("NULL vconf_key of key(%d)", key); - return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; + return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED; } INFO("key = %d, %s", key, iface->vconf_key); @@ -252,12 +303,6 @@ API int system_settings_remove_changed_cb(system_settings_key_e key, system_sett { int ret; - DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); - RETVM_IF(key == SYSTEM_SETTINGS_KEY_DEFAULT_FONT_TYPE, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, - "The defualt font type is only support getter"); RETV_IF(NULL == callback, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); sst_interface *iface = NULL; @@ -267,6 +312,11 @@ API int system_settings_remove_changed_cb(system_settings_key_e key, system_sett return ret; } + if (NULL == iface->vconf_key) { + ERR("NULL vconf_key of key(%d)", key); + return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED; + } + ret = sst_vconf_del_multi_cb(iface, callback); if (SYSTEM_SETTINGS_ERROR_NONE != ret) { ERR("sst_vconf_del_multi_cb() Fail(%d)", ret); diff --git a/src/sst_core.c b/src/sst_core.c deleted file mode 100644 index 6dd9ad8..0000000 --- a/src/sst_core.c +++ /dev/null @@ -1,379 +0,0 @@ -/* - * Copyright (c) 2011-2020 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "sst_core.h" - -#include -#include -#include -#include -#include "sst.h" -#include "sst_misc.h" -#include "sst_vconf.h" -#include "sst_interface.h" - -int sst_get_value(system_settings_key_e key, sst_interface_data_type data_type, void **value) -{ - int ret; - - DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); - RETV_IF(NULL == value, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); - - sst_interface *iface = NULL; - ret = sst_get_interface(key, &iface); - if (SYSTEM_SETTINGS_ERROR_NONE != ret) { - ERR("sst_get_interface(%d) Fail(%d)", key, ret); - return ret; - } - - if (iface->data_type != data_type) { - ERR("Invalide type for key(%d) : Expected(%d), Actual(%d)", - key, iface->data_type, data_type); - return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; - } - - sst_get_value_fn getter = iface->get_value_cb; - if (NULL == getter) { - ERR("No getter for key(%d)", key); - return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED; - } - - ret = getter(iface, value); - if (SYSTEM_SETTINGS_ERROR_NONE != ret) - ERR("getter(%d) Fail(%d)", key, ret); - return ret; -} - -int sst_set_value(system_settings_key_e key, sst_interface_data_type data_type, void *value) -{ - int ret; - - DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); - RETV_IF(NULL == value, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); - - sst_interface *iface = NULL; - ret = sst_get_interface(key, &iface); - if (SYSTEM_SETTINGS_ERROR_NONE != ret) { - ERR("sst_get_interface(%d) Fail(%d)", key, ret); - return ret; - } - - if (iface->data_type != data_type) { - ERR("Invalide type for key(%d) : Expected(%d), Actual(%d)", - key, iface->data_type, data_type); - return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; - } - - sst_set_value_fn setter = iface->set_value_cb; - if (NULL == setter) { - ERR("No setter for key(%d)", key); - return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED; - } - - ret = setter(iface, value); - if (SYSTEM_SETTINGS_ERROR_NONE != ret) - ERR("setter(%d) Fail(%d)", key, ret); - return ret; -} - -int sst_list_value(system_settings_key_e key, sst_interface_data_type data_type, bool(*list_iterator_fn)(int, const char*, void *), void *user_data) -{ - int ret; - - DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); - - sst_interface *iface = NULL; - ret = sst_get_interface(key, &iface); - if (SYSTEM_SETTINGS_ERROR_NONE != ret) { - ERR("sst_get_interface(%d) Fail(%d)", key, ret); - return ret; - } - - if (iface->data_type != data_type) { - ERR("Invalide type for key(%d) : Expected(%d), Actual(%d)", - key, iface->data_type, data_type); - return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; - } - - sst_list_value_cb list_getter = iface->list_value_cb; - if (NULL == list_getter) { - ERR("No list_getter for key(%d)", key); - return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED; - } - - ret = list_getter(key, list_iterator_fn, user_data); - if (SYSTEM_SETTINGS_ERROR_NONE != ret) - ERR("list_getter(%d) Fail(%d)", key, ret); - return ret; -} - -int sst_add_value(system_settings_key_e key, sst_interface_data_type data_type, void *value) -{ - int ret; - - DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); - - sst_interface *iface = NULL; - ret = sst_get_interface(key, &iface); - if (SYSTEM_SETTINGS_ERROR_NONE != ret) { - ERR("sst_get_interface(%d) Fail(%d)", key, ret); - return ret; - } - - if (iface->data_type != data_type) { - ERR("Invalide type for key(%d) : Expected(%d), Actual(%d)", - key, iface->data_type, data_type); - return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; - } - - sst_add_value_fn adder = iface->add_value_cb; - if (NULL == adder) { - ERR("No adder for key(%d)", key); - return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED; - } - - ret = adder(key, value); - if (SYSTEM_SETTINGS_ERROR_NONE != ret) - ERR("adder(%d) Fail(%d)", key, ret); - return ret; -} - -int sst_del_value(system_settings_key_e key, sst_interface_data_type data_type, void *value) -{ - int ret; - - DBG("Enter"); - RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); - - sst_interface *iface = NULL; - ret = sst_get_interface(key, &iface); - if (SYSTEM_SETTINGS_ERROR_NONE != ret) { - ERR("sst_get_interface(%d) Fail(%d)", key, ret); - return ret; - } - - if (iface->data_type != data_type) { - ERR("Invalide type for key(%d) : Expected(%d), Actual(%d)", - key, iface->data_type, data_type); - return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; - } - - sst_del_value_fn deleter; - deleter = iface->del_value_cb; - if (NULL == deleter) { - ERR("No deleter for key(%d)", key); - return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED; - } - - ret = deleter(key, value); - if (SYSTEM_SETTINGS_ERROR_NONE != ret) - ERR("deleter(%d) Fail(%d)", key, ret); - return ret; - -} - -/** - * sound == false, vibration == false --> silent mode - * sound == true, vibration == false --> sound mode - * sound == false, vibration == true --> vibration mode - */ -int sst_get_sound_silent_mode(sst_interface *iface, void **value) -{ - bool sound_status = false; - if (sst_vconf_get_real_bool(iface->vconf_key, &sound_status)) { - ERR("sst_vconf_get_real_bool(%s) Fail", iface->vconf_key); - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - } - - bool vib_status = false; - const char *vibration_key = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL; - if (sst_vconf_get_real_bool(vibration_key, &vib_status)) { - ERR("sst_vconf_get_real_bool(%s) Fail", vibration_key); - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - } - - bool ret_val = (sound_status == false && vib_status == false); - *value = (void*)ret_val; - - return SYSTEM_SETTINGS_ERROR_NONE; -} - -/** - * sound == false, vibration == false --> silent mode - * sound == true, vibration == false --> sound mode - */ -//Todo: It should return to the old status. -int sst_set_sound_silent_mode(sst_interface *iface, void *value) -{ - bool *vconf_value = value; - - bool vconf_sound = !(*vconf_value); - if (vconf_set_bool(iface->vconf_key, vconf_sound)) { - ERR("vconf_set_bool(%s, %d) Fail", iface->vconf_key, vconf_sound); - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - } - - bool vconf_vib = false; - const char *vibration_key = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL; - if (vconf_set_bool(vibration_key, vconf_vib)) { - ERR("vconf_set_bool(%s) Fail", vibration_key); - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - } - - return SYSTEM_SETTINGS_ERROR_NONE; -} - -int sst_set_sound_notification(sst_interface *iface, void *value) -{ - char *vconf_value = value; - - bool is_valid = sst_misc_exist(vconf_value); - if (true == is_valid) { - if (vconf_set_str(iface->vconf_key, vconf_value)) { - ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, vconf_value); - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - } - } else { - ERR("sst_misc_exist(%s) Fail", vconf_value); - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - } - - return SYSTEM_SETTINGS_ERROR_NONE; -} - -int sst_set_device_name(system_settings_key_e key, void *value) -{ - char *vconf_value = value; - - const char *vconf_key = VCONFKEY_SETAPPL_DEVICE_NAME_STR; - if (vconf_set_str(vconf_key, vconf_value)) { - ERR("vconf_set_str(%s, %s) Fail", vconf_key, vconf_value); - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - } - - return SYSTEM_SETTINGS_ERROR_NONE; -} - -int sst_get_network_wifi_notification(sst_interface *iface, void **value) -{ - int vconf_value = 0; - if (vconf_get_int(iface->vconf_key, &vconf_value)) { - ERR("vconf_get_int(%s) Fail", iface->vconf_key); - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - } - - bool result; - result = (vconf_value == VCONFKEY_WIFI_QS_ENABLE) ? true : false; - - *value = (void*)result; - return SYSTEM_SETTINGS_ERROR_NONE; -} - -//It is related with Advertisements -#define DEFAULT_ADS_ID "00000000-0000-0000-0000-000000000000" -int sst_get_ads_id(sst_interface *iface, void **value) -{ - int result = 0; - const char *key = VCONFKEY_SETAPPL_AD_ID_OPT_OUT; - if (vconf_get_int(key, &result)) { - ERR("vconf_get_int(%s) Fail", key); - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - } - - if (result == 1) { - *value = strdup(DEFAULT_ADS_ID); - return SYSTEM_SETTINGS_ERROR_NONE; - } - - char *vconf_value = NULL; - if (sst_vconf_get_string(iface->vconf_key, &vconf_value)) { - ERR("sst_vconf_get_string(%s) Fail", iface->vconf_key); - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - } - - *value = vconf_value; - return SYSTEM_SETTINGS_ERROR_NONE; -} - -int sst_set_ads_id(sst_interface *iface, void *value) -{ - char *vconf_value = value; - - if (vconf_set_str(iface->vconf_key, vconf_value)) { - ERR("vconf_set_str(%s) Fail", iface->vconf_key); - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - } - - return SYSTEM_SETTINGS_ERROR_NONE; -} - -int sst_get_uds_state(sst_interface *iface, void **value) -{ - int **p_value = (int**)value; - int int_val; - char *str_val = NULL; - - if (vconf_get_int(iface->vconf_key, &int_val)) - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - - if (int_val == SYSTEM_SETTINGS_UDS_ON) { - const char *vconf_key = VCONFKEY_SETAPPL_UDSM_PKGID_LIST; - int ret = sst_vconf_get_string(vconf_key, &str_val); - if (SYSTEM_SETTINGS_ERROR_NONE != ret) { - ERR("sst_vconf_get_string(%s) Fail(%d)", vconf_key, ret); - return ret; - } - - if (SST_EQUAL != strcmp(str_val, "NONE")) { - char *app_id = NULL; - char *package_id = NULL; - pid_t pid = getpid(); - - int ret = app_manager_get_app_id(pid, &app_id); - if (ret != APP_MANAGER_ERROR_NONE) { - SECURE_ERR("app_manager_get_app_id(%d) Fail(%d)", pid, ret); - free(str_val); - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - } - - ret = package_manager_get_package_id_by_app_id(app_id, &package_id); - if (PACKAGE_MANAGER_ERROR_NONE != ret) { - SECURE_ERR("package_manager_get_package_id_by_app_id(%s) Fail(%d)", app_id, ret); - free(app_id); - free(str_val); - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - } - free(app_id); - - if (package_id && strstr(str_val, package_id)) - int_val = SYSTEM_SETTINGS_UDS_ON_WHITELISTED; - free(package_id); - } - free(str_val); - } - - **p_value = int_val; - - return SYSTEM_SETTINGS_ERROR_NONE; -} diff --git a/src/sst_core.h b/src/sst_core.h deleted file mode 100644 index 810dde8..0000000 --- a/src/sst_core.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2011-2020 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include "sst_interface.h" - -int sst_set_value(system_settings_key_e key, sst_interface_data_type data_type, void *value); -int sst_get_value(system_settings_key_e key, sst_interface_data_type data_type, void **value); -int sst_add_value(system_settings_key_e key, sst_interface_data_type data_type, void *value); -int sst_del_value(system_settings_key_e key, sst_interface_data_type data_type, void *value); -int sst_list_value(system_settings_key_e key, sst_interface_data_type data_type, bool(*system_setting_data_iterator)(int, const char*, void *), void *user_data); - -int sst_get_network_wifi_notification(sst_interface *iface, void **value); - -int sst_set_sound_notification(sst_interface *iface, void *value); -int sst_get_sound_silent_mode(sst_interface *iface, void **value); -int sst_set_sound_silent_mode(sst_interface *iface, void *value); - -int sst_get_ads_id(sst_interface *iface, void **value); -int sst_set_ads_id(sst_interface *iface, void *value); - -int sst_get_uds_state(sst_interface *iface, void **value); diff --git a/src/sst_font.c b/src/sst_font.c index ed93d07..446ca99 100644 --- a/src/sst_font.c +++ b/src/sst_font.c @@ -20,16 +20,13 @@ #include "sst.h" #include "sst_utils_wrapper.h" -int sst_font_set_size(sst_interface *iface, void *value) +int sst_font_set_size(sst_interface *iface, int value) { - int *vconf_value; - vconf_value = *(int **)value; + RETVM_IF(value < 0 || SYSTEM_SETTINGS_FONT_SIZE_GIANT < value, + SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid size(%d)", value); - RETVM_IF(*vconf_value < 0 || SYSTEM_SETTINGS_FONT_SIZE_GIANT < *vconf_value, - SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid value(%d)", *vconf_value); - - if (vconf_set_int(iface->vconf_key, *vconf_value)) { - ERR("vconf_set_int(%s) Fail", iface->vconf_key); + if (vconf_set_int(iface->vconf_key, value)) { + ERR("vconf_set_int(%s, %d) Fail", iface->vconf_key, value); return SYSTEM_SETTINGS_ERROR_IO_ERROR; } @@ -37,7 +34,7 @@ int sst_font_set_size(sst_interface *iface, void *value) return SYSTEM_SETTINGS_ERROR_NONE; } -static void* font_conf_doc_parse(char *doc_name, char *font_name) +static void* font_conf_doc_parse(const char *doc_name, const char *font_name) { xmlDocPtr doc = NULL; xmlNodePtr cur = NULL; @@ -46,9 +43,7 @@ static void* font_conf_doc_parse(char *doc_name, char *font_name) xmlChar *key = NULL; doc = xmlParseFile(doc_name); - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { xmlFreeDoc(doc); doc = NULL; @@ -132,17 +127,12 @@ static void* font_conf_doc_parse(char *doc_name, char *font_name) } } -int sst_font_set_type(sst_interface *iface, void *value) +int sst_font_set_type(sst_interface *iface, const char *font_name) { - char *font_name = NULL; - font_name = (char*)value; - /* get current font list */ int is_found = sstu_is_available_font(font_name); - if (is_found == 1) { - DBG("found font : %s ", font_name); - } else { - ERR(" NOT found font : %s ", font_name); + if (FALSE == is_found) { + ERR("NO font(%s)", font_name); return SYSTEM_SETTINGS_ERROR_IO_ERROR; } @@ -161,17 +151,15 @@ int sst_font_set_type(sst_interface *iface, void *value) sstu_font_config_set_notification(); - char *vconf_value; - vconf_value = (char*)value; - if (vconf_set_str(iface->vconf_key, vconf_value)) { - ERR("vconf_set_str(%s) Fail", iface->vconf_key); + if (vconf_set_str(iface->vconf_key, font_name)) { + ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, font_name); return SYSTEM_SETTINGS_ERROR_IO_ERROR; } return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_font_get_default_type(sst_interface *iface, void **value) +int sst_font_get_default_type(sst_interface *iface, char **value) { char *font_name = sstu_get_default_font(); if (NULL == font_name) { @@ -179,6 +167,6 @@ int sst_font_get_default_type(sst_interface *iface, void **value) return SYSTEM_SETTINGS_ERROR_IO_ERROR; } - *value = (void*)font_name; + *value = font_name; return SYSTEM_SETTINGS_ERROR_NONE; } diff --git a/src/sst_font.h b/src/sst_font.h index 25391b0..dc8ace6 100644 --- a/src/sst_font.h +++ b/src/sst_font.h @@ -17,6 +17,6 @@ #include "sst_interface.h" -int sst_font_set_size(sst_interface *iface, void *value); -int sst_font_set_type(sst_interface *iface, void *value); -int sst_font_get_default_type(sst_interface *iface, void **value); +int sst_font_set_size(sst_interface *iface, int value); +int sst_font_set_type(sst_interface *iface, const char *font_name); +int sst_font_get_default_type(sst_interface *iface, char **value); diff --git a/src/sst_interface.c b/src/sst_interface.c index 896091f..8934cee 100644 --- a/src/sst_interface.c +++ b/src/sst_interface.c @@ -17,491 +17,340 @@ #include #include "sst.h" -#include "sst_core.h" #include "sst_font.h" #include "sst_misc.h" #include "sst_vconf.h" +#include "sst_sound.h" #include "sst_screen.h" #include "sst_feature.h" -#include "sst_ringtones.h" #include "sst_time_N_locale.h" -#define SYSTEM_SETTINGS_MAX -1 - -struct _system_setting_s system_setting_table[] = { - { +static sst_interface sst_iface_table[] = { + [SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE] = { SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, SYSTEM_SETTING_DATA_TYPE_STRING, - sst_ringtone_get_incoming_call, - sst_ringtone_set_incoming_call, - sst_ringtone_add_incoming_call, /* ADD */ - sst_ringtone_del_incoming_call, /* DEL */ - sst_ringtone_list_incoming_call, /* LIST */ - sst_feature_check_incoming_call, /* feature check */ + .feature_checker = sst_feature_check_incoming_call, + .getter.s = sst_sound_get_call_ringtone, + .setter.s = sst_sound_set_call_ringtone }, - - { + [SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN] = { SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, VCONFKEY_BGSET, SYSTEM_SETTING_DATA_TYPE_STRING, - sst_vconf_get, - sst_screen_set_home_wallpaper, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - sst_feature_check_home_screen, /* feature check */ + .feature_checker = sst_feature_check_home_screen, + .getter.s = sst_vconf_get_str, + .setter.s = sst_screen_set_home_wallpaper }, - - { + [SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN] = { SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, VCONFKEY_IDLE_LOCK_BGSET, SYSTEM_SETTING_DATA_TYPE_STRING, - sst_vconf_get, - sst_screen_set_lock_wallpaper, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - sst_feature_check_lock_screen, /* feature check */ + .feature_checker = sst_feature_check_lock_screen, + .getter.s = sst_vconf_get_str, + .setter.s = sst_screen_set_lock_wallpaper }, - - { + [SYSTEM_SETTINGS_KEY_FONT_SIZE] = { SYSTEM_SETTINGS_KEY_FONT_SIZE, VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, SYSTEM_SETTING_DATA_TYPE_INT, - sst_vconf_get, - sst_font_set_size, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - sst_feature_check_font, /* feature check */ + .feature_checker = sst_feature_check_font, + .getter.i = sst_vconf_get_int, + .setter.i = sst_font_set_size }, - - { + [SYSTEM_SETTINGS_KEY_FONT_TYPE] = { SYSTEM_SETTINGS_KEY_FONT_TYPE, VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, SYSTEM_SETTING_DATA_TYPE_STRING, - sst_vconf_get, - sst_font_set_type, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - sst_feature_check_font, /* feature check */ + .feature_checker = sst_feature_check_font, + .getter.s = sst_vconf_get_str, + .setter.s = sst_font_set_type }, - - { + [SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION] = { SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, VCONFKEY_SETAPPL_MOTION_ACTIVATION, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_vconf_get, - sst_vconf_set, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ + .feature_checker = NULL, + .getter.b = sst_vconf_get_bool, + .setter.b = sst_vconf_set_bool }, - - { + [SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE] = { SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, SYSTEM_SETTING_DATA_TYPE_STRING, - sst_ringtone_get_email_alert, - sst_ringtone_set_email_alert, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - sst_feature_check_notification_email, /* feature check */ - }, - { + .feature_checker = sst_feature_check_notification_email, + .getter.s = sst_sound_get_email_alert, + .setter.s = sst_sound_set_email_alert + }, + [SYSTEM_SETTINGS_KEY_USB_DEBUGGING_ENABLED] = { SYSTEM_SETTINGS_KEY_USB_DEBUGGING_ENABLED, VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_vconf_get, - sst_vconf_set, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ - }, - { + .feature_checker = NULL, + .getter.b = sst_vconf_get_bool, + .setter.b = sst_vconf_set_bool + }, + [SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED] = { SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, VCONFKEY_3G_ENABLE, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_vconf_get, - sst_vconf_set, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ - }, - //{ /* Deprecated */ - // -5, NULL, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, { NULL, 0 }, NULL - //}, - { + .feature_checker = NULL, + .getter.b = sst_vconf_get_bool, + .setter.b = sst_vconf_set_bool + }, + [SYSTEM_SETTINGS_KEY_LOCKSCREEN_APP] = { SYSTEM_SETTINGS_KEY_LOCKSCREEN_APP, VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, SYSTEM_SETTING_DATA_TYPE_STRING, - sst_screen_get_lockscreen, - sst_screen_set_lockscreen, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - sst_feature_check_lock_screen, /* feature check */ - }, - { + .feature_checker = sst_feature_check_lock_screen, + .getter.s = sst_screen_get_lockscreen, + .setter.s = sst_screen_set_lockscreen + }, + [SYSTEM_SETTINGS_KEY_DEFAULT_FONT_TYPE] = { SYSTEM_SETTINGS_KEY_DEFAULT_FONT_TYPE, NULL, SYSTEM_SETTING_DATA_TYPE_STRING, - sst_font_get_default_type, - NULL, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - sst_feature_check_font, /* feature check */ + .feature_checker = sst_feature_check_font, + .getter.s = sst_font_get_default_type, + .setter.s = NULL }, - { + [SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY] = { SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, VCONFKEY_REGIONFORMAT, SYSTEM_SETTING_DATA_TYPE_STRING, - sst_locale_get_country, - sst_locale_set_country, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ - }, - { + .feature_checker = NULL, + .getter.s = sst_locale_get_country, + .setter.s = sst_locale_set_country + }, + [SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE] = { SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, VCONFKEY_LANGSET, SYSTEM_SETTING_DATA_TYPE_STRING, - sst_locale_get_language, - sst_locale_set_language, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ - }, - { + .feature_checker = NULL, + .getter.s = sst_locale_get_language, + .setter.s = sst_locale_set_language + }, + [SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR] = { SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, VCONFKEY_REGIONFORMAT_TIME1224, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_locale_get_timeformat_24hour, - sst_locale_set_timeformat_24hour, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ - }, - { + .feature_checker = NULL, + .getter.b = sst_locale_get_timeformat_24hour, + .setter.b = sst_locale_set_timeformat_24hour + }, + [SYSTEM_SETTINGS_KEY_LOCALE_TIMEZONE] = { SYSTEM_SETTINGS_KEY_LOCALE_TIMEZONE, VCONFKEY_SETAPPL_TIMEZONE_ID, SYSTEM_SETTING_DATA_TYPE_STRING, - sst_locale_get_timezone, - sst_locale_set_timezone, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ - }, - { + .feature_checker = NULL, + .getter.s = sst_locale_get_timezone, + .setter.s = sst_locale_set_timezone + }, + [SYSTEM_SETTINGS_KEY_TIME_CHANGED] = { SYSTEM_SETTINGS_KEY_TIME_CHANGED, VCONFKEY_SYSTEM_TIME_CHANGED, SYSTEM_SETTING_DATA_TYPE_INT, - sst_time_get_changed, - NULL, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ + .feature_checker = NULL, + .getter.i = sst_time_get_changed, + .setter.i = NULL }, - { + [SYSTEM_SETTINGS_KEY_SOUND_LOCK] = { SYSTEM_SETTINGS_KEY_SOUND_LOCK, VCONFKEY_SETAPPL_SOUND_LOCK_BOOL, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_vconf_get, - NULL, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ + .feature_checker = NULL, + .getter.b = sst_vconf_get_bool, + .setter.b = NULL }, - { + [SYSTEM_SETTINGS_KEY_SOUND_SILENT_MODE] = { SYSTEM_SETTINGS_KEY_SOUND_SILENT_MODE, VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_get_sound_silent_mode, - sst_set_sound_silent_mode, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ - }, - { + .feature_checker = NULL, + .getter.b = sst_sound_get_silent_mode, + .setter.b = sst_sound_set_silent_mode + }, + [SYSTEM_SETTINGS_KEY_SOUND_TOUCH] = { SYSTEM_SETTINGS_KEY_SOUND_TOUCH, VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_vconf_get, - sst_vconf_set, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ - }, - { + .feature_checker = NULL, + .getter.b = sst_vconf_get_bool, + .setter.b = sst_vconf_set_bool + }, + [SYSTEM_SETTINGS_KEY_DISPLAY_SCREEN_ROTATION_AUTO] = { SYSTEM_SETTINGS_KEY_DISPLAY_SCREEN_ROTATION_AUTO, VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_vconf_get, - sst_vconf_set, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ - }, - { + .feature_checker = NULL, + .getter.b = sst_vconf_get_bool, + .setter.b = sst_vconf_set_bool + }, + [SYSTEM_SETTINGS_KEY_DEVICE_NAME] = { SYSTEM_SETTINGS_KEY_DEVICE_NAME, VCONFKEY_SETAPPL_DEVICE_NAME_STR, SYSTEM_SETTING_DATA_TYPE_STRING, - sst_vconf_get, - NULL, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ + .feature_checker = NULL, + .getter.s = sst_vconf_get_str, + .setter.s = NULL }, - { + [SYSTEM_SETTINGS_KEY_MOTION_ENABLED] = { SYSTEM_SETTINGS_KEY_MOTION_ENABLED, VCONFKEY_SETAPPL_MOTION_ACTIVATION, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_vconf_get, - NULL, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ + .feature_checker = NULL, + .getter.b = sst_vconf_get_bool, + .setter.b = NULL }, - { + [SYSTEM_SETTINGS_KEY_NETWORK_WIFI_NOTIFICATION] = { SYSTEM_SETTINGS_KEY_NETWORK_WIFI_NOTIFICATION, VCONFKEY_WIFI_ENABLE_QS, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_get_network_wifi_notification, - NULL, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - sst_feature_check_wifi, /* feature check */ + .feature_checker = sst_feature_check_wifi, + .getter.b = sst_misc_get_wifi_QS_noti, + .setter.b = NULL }, - { + [SYSTEM_SETTINGS_KEY_NETWORK_FLIGHT_MODE] = { SYSTEM_SETTINGS_KEY_NETWORK_FLIGHT_MODE, VCONFKEY_TELEPHONY_FLIGHT_MODE, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_vconf_get, - NULL, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ + .feature_checker = NULL, + .getter.b = sst_vconf_get_bool, + .setter.b = NULL }, - { + [SYSTEM_SETTINGS_KEY_SCREEN_BACKLIGHT_TIME] = { SYSTEM_SETTINGS_KEY_SCREEN_BACKLIGHT_TIME, VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, SYSTEM_SETTING_DATA_TYPE_INT, - sst_vconf_get, - sst_screen_set_backlight_time, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ - }, - { + .feature_checker = NULL, + .getter.i = sst_vconf_get_int, + .setter.i = sst_screen_set_backlight_time + }, + [SYSTEM_SETTINGS_KEY_SOUND_NOTIFICATION] = { SYSTEM_SETTINGS_KEY_SOUND_NOTIFICATION, VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, SYSTEM_SETTING_DATA_TYPE_STRING, - sst_vconf_get, - sst_set_sound_notification, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - sst_feature_check_incoming_call, /* feature check */ - }, - { + .feature_checker = sst_feature_check_incoming_call, + .getter.s = sst_vconf_get_str, + .setter.s = sst_sound_set_notification + }, + [SYSTEM_SETTINGS_KEY_SOUND_NOTIFICATION_REPETITION_PERIOD] = { SYSTEM_SETTINGS_KEY_SOUND_NOTIFICATION_REPETITION_PERIOD, VCONFKEY_SETAPPL_NOTI_MSG_ALERT_REP_TYPE_INT, SYSTEM_SETTING_DATA_TYPE_INT, - sst_vconf_get, - sst_vconf_set, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ - }, - { + .feature_checker = NULL, + .getter.i = sst_vconf_get_int, + .setter.i = sst_vconf_set_int + }, + [SYSTEM_SETTINGS_KEY_LOCK_STATE] = { SYSTEM_SETTINGS_KEY_LOCK_STATE, VCONFKEY_IDLE_LOCK_STATE_READ_ONLY, SYSTEM_SETTING_DATA_TYPE_INT, - sst_vconf_get, - sst_vconf_set, - NULL, /* add */ - NULL, /* del */ - NULL, /* list */ - NULL, /* feature check */ - }, - { + .feature_checker = NULL, + .getter.i = sst_vconf_get_int, + .setter.i = sst_vconf_set_int + }, + [SYSTEM_SETTINGS_KEY_ADS_ID] = { SYSTEM_SETTINGS_KEY_ADS_ID, VCONFKEY_SETAPPL_AD_ID, SYSTEM_SETTING_DATA_TYPE_STRING, - sst_get_ads_id, - sst_set_ads_id, - NULL, /* add */ - NULL, /* del */ - NULL, /* list */ - NULL, /* feature check */ + .feature_checker = NULL, + .getter.s = sst_misc_get_ads_id, + .setter.s = sst_misc_set_ads_id }, - - { + [SYSTEM_SETTINGS_KEY_ULTRA_DATA_SAVE] = { SYSTEM_SETTINGS_KEY_ULTRA_DATA_SAVE, VCONFKEY_SETAPPL_UDSM, SYSTEM_SETTING_DATA_TYPE_INT, - sst_get_uds_state, - NULL, - NULL, /* add */ - NULL, /* del */ - NULL, /* list */ - sst_feature_check_telephony, /* feature check */ + .feature_checker = sst_feature_check_telephony, + .getter.i = sst_misc_get_uds_state, + .setter.i = NULL }, - { + [SYSTEM_SETTINGS_KEY_ULTRA_DATA_SAVE_PKG_LIST] = { SYSTEM_SETTINGS_KEY_ULTRA_DATA_SAVE_PKG_LIST, VCONFKEY_SETAPPL_UDSM_PKGID_LIST, SYSTEM_SETTING_DATA_TYPE_STRING, - NULL, - NULL, - NULL, /* add */ - NULL, /* del */ - NULL, /* list */ - sst_feature_check_telephony, /* feature check */ + .feature_checker = sst_feature_check_telephony, + .getter.s = NULL, + .setter.s = NULL }, - { + [SYSTEM_SETTINGS_KEY_ACCESSIBILITY_TTS] = { SYSTEM_SETTINGS_KEY_ACCESSIBILITY_TTS, VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_vconf_get, - sst_vconf_set, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ - }, - { + .feature_checker = NULL, + .getter.b = sst_vconf_get_bool, + .setter.b = sst_vconf_set_bool + }, + [SYSTEM_SETTINGS_KEY_VIBRATION] = { SYSTEM_SETTINGS_KEY_VIBRATION, VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_vconf_get, - sst_vconf_set, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ - }, - { + .feature_checker = NULL, + .getter.b = sst_vconf_get_bool, + .setter.b = sst_vconf_set_bool + }, + [SYSTEM_SETTINGS_KEY_AUTOMATIC_TIME_UPDATE] = { SYSTEM_SETTINGS_KEY_AUTOMATIC_TIME_UPDATE, VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_vconf_get, - sst_vconf_set, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - sst_feature_check_telephony, /* feature check */ - }, - { + .feature_checker = sst_feature_check_telephony, + .getter.b = sst_vconf_get_bool, + .setter.b = sst_vconf_set_bool + }, + [SYSTEM_SETTINGS_KEY_DEVELOPER_OPTION_STATE] = { SYSTEM_SETTINGS_KEY_DEVELOPER_OPTION_STATE, VCONFKEY_SETAPPL_DEVELOPER_OPTION_STATE, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_vconf_get, - sst_vconf_set, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - NULL, /* feature check */ - }, - { + .feature_checker = NULL, + .getter.b = sst_vconf_get_bool, + .setter.b = sst_vconf_set_bool + }, + [SYSTEM_SETTINGS_KEY_ACCESSIBILITY_GRAYSCALE] = { SYSTEM_SETTINGS_KEY_ACCESSIBILITY_GRAYSCALE, VCONFKEY_SETAPPL_ACCESSIBILITY_GREYSCALE, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_vconf_get, - sst_vconf_set, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - sst_feature_check_accessibility_grayscale, /* feature check */ - }, - { + .feature_checker = sst_feature_check_accessibility_grayscale, + .getter.b = sst_vconf_get_bool, + .setter.b = sst_vconf_set_bool + }, + [SYSTEM_SETTINGS_KEY_ACCESSIBILITY_NEGATIVE_COLOR] = { SYSTEM_SETTINGS_KEY_ACCESSIBILITY_NEGATIVE_COLOR, VCONFKEY_SETAPPL_ACCESSIBILITY_HIGH_CONTRAST, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_vconf_get, - sst_vconf_set, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - sst_feature_check_accessibility_negative, /* feature check */ - }, - { + .feature_checker = sst_feature_check_accessibility_negative, + .getter.b = sst_vconf_get_bool, + .setter.b = sst_vconf_set_bool + }, + [SYSTEM_SETTINGS_KEY_ROTARY_EVENT_ENABLED] = { SYSTEM_SETTINGS_KEY_ROTARY_EVENT_ENABLED, VCONFKEY_SETAPPL_ROTARY_EVENT_ENABLED_BOOL, SYSTEM_SETTING_DATA_TYPE_BOOL, - sst_vconf_get, - sst_vconf_set, - NULL, /* ADD */ - NULL, /* DEL */ - NULL, /* LIST */ - sst_feature_check_rotary, /* feature check */ - }, - { - SYSTEM_SETTINGS_MAX, NULL, -1, NULL, NULL, NULL, NULL, NULL, NULL + .feature_checker = sst_feature_check_rotary, + .getter.b = sst_vconf_get_bool, + .setter.b = sst_vconf_set_bool } }; -static int _search_item(system_settings_key_e key) -{ - int start = 0; - int end = SYSTEM_SETTINGS_KEY_MAX; - - while (start <= end) { - int mid = (start + end) / 2; - if (system_setting_table[mid].key == key) - return mid; - else if (system_setting_table[mid].key < key) - start = mid + 1; - else - end = mid - 1; - } - - ERR("key=%d, Can NOT find the key", key); - return -1; -} - int sst_get_interface(system_settings_key_e key, sst_interface **iface) { - DBG("Enter"); RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key); - int idx = _search_item(key); - if (-1 == idx) { - ERR("Unknown key(%d)", key); - return TIZEN_ERROR_INVALID_PARAMETER; + if (sst_iface_table[key].key != key) { + ERR("Invalid interface for key(%d)", key); + return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; } - if (system_setting_table[idx].feature_check_cb != NULL) { - int ret = system_setting_table[idx].feature_check_cb(iface); + if (sst_iface_table[key].feature_checker) { + int ret = sst_iface_table[key].feature_checker(iface); if (SYSTEM_SETTINGS_ERROR_NONE != ret) { - ERR("feature_check_cb(%d) Fail(%d)", key, ret); + ERR("feature_checker(%d) Fail(%d)", key, ret); return ret; } } - *iface = &system_setting_table[idx]; + *iface = &sst_iface_table[key]; INFO("key = %d, type = %d", key, (*iface)->data_type); return SYSTEM_SETTINGS_ERROR_NONE; diff --git a/src/sst_interface.h b/src/sst_interface.h index 61eece1..5e48209 100644 --- a/src/sst_interface.h +++ b/src/sst_interface.h @@ -15,7 +15,6 @@ */ #pragma once -#include #include "system_settings.h" typedef enum { @@ -26,29 +25,34 @@ typedef enum { //SYSTEM_SETTING_DATA_TYPE_DOULBE, } sst_interface_data_type; -typedef struct _system_setting_s sst_interface; - -typedef int (*sst_get_value_fn)(sst_interface *iface, void **value); -typedef int (*sst_set_value_fn)(sst_interface *iface, void *value); -typedef int (*sst_add_value_fn)(system_settings_key_e key, void *value); -typedef int (*sst_del_value_fn)(system_settings_key_e key, void *value); -typedef int (*sst_list_value_cb)(system_settings_key_e key, system_settings_iter_cb callback, void *user_data); +typedef struct sst_interface_s sst_interface; typedef int (*sst_check_feature_fn)(void *value); -struct _system_setting_s { - system_settings_key_e key; - const char* const vconf_key; - sst_interface_data_type data_type; +typedef int (*sst_get_int_fn)(sst_interface *iface, int *value); +typedef int (*sst_get_bool_fn)(sst_interface *iface, bool *value); +typedef int (*sst_get_str_fn)(sst_interface *iface, char **value); - sst_get_value_fn get_value_cb; - sst_set_value_fn set_value_cb; +typedef int (*sst_set_int_fn)(sst_interface *iface, int value); +typedef int (*sst_set_bool_fn)(sst_interface *iface, bool value); +typedef int (*sst_set_str_fn)(sst_interface *iface, const char *value); - sst_add_value_fn add_value_cb; - sst_del_value_fn del_value_cb; - sst_list_value_cb list_value_cb; - sst_check_feature_fn feature_check_cb; +struct sst_interface_s { + system_settings_key_e key; + const char* const vconf_key; + sst_interface_data_type data_type; + sst_check_feature_fn feature_checker; + union { + sst_get_int_fn i; + sst_get_bool_fn b; + sst_get_str_fn s; + } getter; + union { + sst_set_int_fn i; + sst_set_bool_fn b; + sst_set_str_fn s; + } setter; }; int sst_get_interface(system_settings_key_e key, sst_interface **iface); diff --git a/src/sst_json.c b/src/sst_json.c index b376d6c..d4cdf46 100644 --- a/src/sst_json.c +++ b/src/sst_json.c @@ -69,7 +69,7 @@ void sst_json_unref(sst_json_h *handle) free(handle); } -void sst_json_add_ringtone(sst_json_h *handle, char *nameval, char *pathval) +void sst_json_add_ringtone(sst_json_h *handle, const char *nameval, const char *pathval) { JsonNode *root = handle->root; JsonNode *menu_item = json_node_new(JSON_NODE_OBJECT); @@ -107,7 +107,7 @@ void sst_json_get_ringtones(sst_json_h *handle, system_settings_iter_cb cb, void } } -void sst_json_remove_ringtone(sst_json_h *handle, char *path_to_del) +void sst_json_remove_ringtone(sst_json_h *handle, const char *path_to_del) { int i; @@ -131,7 +131,7 @@ void sst_json_remove_ringtone(sst_json_h *handle, char *path_to_del) _json_save_ringtone(root); } -bool sst_json_contain_ringtone(sst_json_h *handle, char *ringtone_path) +bool sst_json_contain_ringtone(sst_json_h *handle, const char *ringtone_path) { int i; diff --git a/src/sst_json.h b/src/sst_json.h index 629b46a..b8e3a89 100644 --- a/src/sst_json.h +++ b/src/sst_json.h @@ -23,6 +23,6 @@ typedef struct sst_json_s sst_json_h; sst_json_h* sst_json_load_ringtone(); void sst_json_unref(sst_json_h *handle); void sst_json_get_ringtones(sst_json_h *handle, system_settings_iter_cb cb, void *user_data); -void sst_json_add_ringtone(sst_json_h *handle, char *nameval, char *pathval); -void sst_json_remove_ringtone(sst_json_h *handle, char *path_to_del); -bool sst_json_contain_ringtone(sst_json_h *handle, char *newfile); +void sst_json_add_ringtone(sst_json_h *handle, const char *nameval, const char *pathval); +void sst_json_remove_ringtone(sst_json_h *handle, const char *path_to_del); +bool sst_json_contain_ringtone(sst_json_h *handle, const char *newfile); diff --git a/src/sst_misc.c b/src/sst_misc.c index 064c228..18f19e5 100644 --- a/src/sst_misc.c +++ b/src/sst_misc.c @@ -15,17 +15,121 @@ */ #include "sst_misc.h" +#include #include #include +#include +#include +#include #include "sst.h" +#include "sst_vconf.h" -bool sst_misc_exist(const char *path) +bool sst_misc_file_exists(const char *path) { if (0 != access(path, R_OK)) { - /* error code : 13 */ ERR("access(%s) Fail(%d)", path, errno); return false; } return true; } +int sst_misc_get_wifi_QS_noti(sst_interface *iface, bool *value) +{ + int vconf_value = 0; + if (vconf_get_int(iface->vconf_key, &vconf_value)) { + ERR("vconf_get_int(%s) Fail", iface->vconf_key); + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + } + + bool result; + result = (vconf_value == VCONFKEY_WIFI_QS_ENABLE) ? true : false; + + *value = result; + return SYSTEM_SETTINGS_ERROR_NONE; +} + +//It is related with Advertisements +#define DEFAULT_ADS_ID "00000000-0000-0000-0000-000000000000" +int sst_misc_get_ads_id(sst_interface *iface, char **value) +{ + int result = 0; + const char *key = VCONFKEY_SETAPPL_AD_ID_OPT_OUT; + if (vconf_get_int(key, &result)) { + ERR("vconf_get_int(%s) Fail", key); + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + } + + if (result == 1) { + *value = strdup(DEFAULT_ADS_ID); + return SYSTEM_SETTINGS_ERROR_NONE; + } + + char *vconf_value = NULL; + if (sst_vconf_get_str_ally(iface->vconf_key, &vconf_value)) { + ERR("sst_vconf_get_str_ally(%s) Fail", iface->vconf_key); + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + } + + *value = vconf_value; + return SYSTEM_SETTINGS_ERROR_NONE; +} + +int sst_misc_set_ads_id(sst_interface *iface, const char *value) +{ + if (vconf_set_str(iface->vconf_key, value)) { + ERR("vconf_set_str(%s) Fail", iface->vconf_key); + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + } + + return SYSTEM_SETTINGS_ERROR_NONE; +} + +int sst_misc_get_uds_state(sst_interface *iface, int *value) +{ + int int_val; + char *str_val = NULL; + + if (vconf_get_int(iface->vconf_key, &int_val)) + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + + if (int_val == SYSTEM_SETTINGS_UDS_ON) { + const char *vconf_key = VCONFKEY_SETAPPL_UDSM_PKGID_LIST; + int ret = sst_vconf_get_str_ally(vconf_key, &str_val); + if (SYSTEM_SETTINGS_ERROR_NONE != ret) { + ERR("sst_vconf_get_str_ally(%s) Fail(%d)", vconf_key, ret); + return ret; + } + + if (SST_EQUAL != strcmp(str_val, "NONE")) { + char *app_id = NULL; + char *package_id = NULL; + pid_t pid = getpid(); + + int ret = app_manager_get_app_id(pid, &app_id); + if (ret != APP_MANAGER_ERROR_NONE) { + SECURE_ERR("app_manager_get_app_id(%d) Fail(%d)", pid, ret); + free(str_val); + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + } + + ret = package_manager_get_package_id_by_app_id(app_id, &package_id); + if (PACKAGE_MANAGER_ERROR_NONE != ret) { + SECURE_ERR("package_manager_get_package_id_by_app_id(%s) Fail(%d)", app_id, ret); + free(app_id); + free(str_val); + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + } + free(app_id); + + if (package_id && strstr(str_val, package_id)) + int_val = SYSTEM_SETTINGS_UDS_ON_WHITELISTED; + free(package_id); + } + free(str_val); + } + + *value = int_val; + + return SYSTEM_SETTINGS_ERROR_NONE; +} + diff --git a/src/sst_misc.h b/src/sst_misc.h index 2b2ec94..dbd0e3d 100644 --- a/src/sst_misc.h +++ b/src/sst_misc.h @@ -18,4 +18,10 @@ #include #include "sst_interface.h" -bool sst_misc_exist(const char *path); +bool sst_misc_file_exists(const char *path); +int sst_misc_get_wifi_QS_noti(sst_interface *iface, bool *value); + +int sst_misc_get_ads_id(sst_interface *iface, char **value); +int sst_misc_set_ads_id(sst_interface *iface, const char *value); + +int sst_misc_get_uds_state(sst_interface *iface, int *value); diff --git a/src/sst_ringtones.h b/src/sst_ringtones.h deleted file mode 100644 index 49da1e1..0000000 --- a/src/sst_ringtones.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2011-2020 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include "sst_core.h" - -int sst_ringtone_get_incoming_call(sst_interface *iface, void **value); -int sst_ringtone_set_incoming_call(sst_interface *iface, void *value); -int sst_ringtone_add_incoming_call(system_settings_key_e key, void *value); -int sst_ringtone_del_incoming_call(system_settings_key_e key, void *value); -int sst_ringtone_list_incoming_call(system_settings_key_e key, system_settings_iter_cb callback, void *data); - -int sst_ringtone_get_email_alert(sst_interface *iface, void **value); -int sst_ringtone_set_email_alert(sst_interface *iface, void *value); diff --git a/src/sst_screen.c b/src/sst_screen.c index f04cc79..8825e76 100644 --- a/src/sst_screen.c +++ b/src/sst_screen.c @@ -15,6 +15,7 @@ */ #include "sst_screen.h" +#include #include #include #include @@ -23,48 +24,42 @@ #include "sst_exclusive.h" #include "sst_utils_wrapper.h" -int sst_screen_set_backlight_time(sst_interface *iface, void *value) +int sst_screen_set_backlight_time(sst_interface *iface, int value) { - int *vconf_value = *(int **)value; - - if (*vconf_value <= 0 || 600 < *vconf_value) { - ERR("Invalid Value(%d)", *vconf_value); + if (value <= 0 || 600 < value) { + ERR("Invalid Value(%d)", value); return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; } - if (vconf_set_int(iface->vconf_key, *vconf_value)) { - ERR("vconf_set_int(%s, %d) Fail", iface->vconf_key, *vconf_value); + if (vconf_set_int(iface->vconf_key, value)) { + ERR("vconf_set_int(%s, %d) Fail", iface->vconf_key, value); return SYSTEM_SETTINGS_ERROR_IO_ERROR; } return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_screen_set_home_wallpaper(sst_interface *iface, void *value) +int sst_screen_set_home_wallpaper(sst_interface *iface, const char *value) { - char *vconf_value = value; - - bool valid = sstu_is_valid_image(vconf_value); + bool valid = sstu_is_valid_image(value); if (false == valid) { - ERR("Invalid image file(%s)", vconf_value); + ERR("Invalid image file(%s)", value); return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; } - return sst_excl_set_wallpaper(iface->vconf_key, vconf_value); + return sst_excl_set_wallpaper(iface->vconf_key, value); } -int sst_screen_set_lock_wallpaper(sst_interface *iface, void *value) +int sst_screen_set_lock_wallpaper(sst_interface *iface, const char *value) { - char *vconf_value = value; - - bool valid = sstu_is_valid_image(vconf_value); + bool valid = sstu_is_valid_image(value); if (false == valid) { - ERR("Invalid image file(%s)", vconf_value); + ERR("Invalid image file(%s)", value); return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; } - if (vconf_set_str(iface->vconf_key, vconf_value)) { - ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, vconf_value); + if (vconf_set_str(iface->vconf_key, value)) { + ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, value); return SYSTEM_SETTINGS_ERROR_IO_ERROR; } @@ -90,16 +85,14 @@ static int _category_func(const char *name, void *user_data) } /** - * * set 'swipe type' if current lockscreen app is 'com.samsung.lockscreen' - * */ -int sst_screen_set_lockscreen(sst_interface *iface, void *value) +int sst_screen_set_lockscreen(sst_interface *iface, const char *app_id) { int ret; - char *app_id = value; //ex) com.samsung.lockscreen - RETV_IF(NULL == value, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == app_id, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); + //ex) app_id = com.samsung.lockscreen pkgmgrinfo_appinfo_h handle = NULL; ret = pkgmgrinfo_appinfo_get_appinfo(app_id, &handle); @@ -149,7 +142,7 @@ int sst_screen_set_lockscreen(sst_interface *iface, void *value) return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_screen_get_lockscreen(sst_interface *iface, void **value) +int sst_screen_get_lockscreen(sst_interface *iface, char **value) { char *pkg_name = NULL; @@ -159,8 +152,8 @@ int sst_screen_get_lockscreen(sst_interface *iface, void **value) return SYSTEM_SETTINGS_ERROR_IO_ERROR; } - if (sst_vconf_get_string(iface->vconf_key, &pkg_name)) { - ERR("sst_vconf_get_string(%s) Fail", iface->vconf_key); + if (sst_vconf_get_str_ally(iface->vconf_key, &pkg_name)) { + ERR("sst_vconf_get_str_ally(%s) Fail", iface->vconf_key); return SYSTEM_SETTINGS_ERROR_IO_ERROR; } diff --git a/src/sst_screen.h b/src/sst_screen.h index 6610652..e74e2c0 100644 --- a/src/sst_screen.h +++ b/src/sst_screen.h @@ -18,11 +18,11 @@ #include "sst_interface.h" //set current path of the wallpaper -int sst_screen_set_home_wallpaper(sst_interface *iface, void *value); +int sst_screen_set_home_wallpaper(sst_interface *iface, const char *value); //set current path of the bg image of the lock screen -int sst_screen_set_lock_wallpaper(sst_interface *iface, void *value); +int sst_screen_set_lock_wallpaper(sst_interface *iface, const char *value); -int sst_screen_get_lockscreen(sst_interface *iface, void **value); -int sst_screen_set_lockscreen(sst_interface *iface, void *value); -int sst_screen_set_backlight_time(sst_interface *iface, void *value); +int sst_screen_get_lockscreen(sst_interface *iface, char **value); +int sst_screen_set_lockscreen(sst_interface *iface, const char *app_id); +int sst_screen_set_backlight_time(sst_interface *iface, int value); diff --git a/src/sst_ringtones.c b/src/sst_sound.c similarity index 66% rename from src/sst_ringtones.c rename to src/sst_sound.c index c85678b..fecc3df 100644 --- a/src/sst_ringtones.c +++ b/src/sst_sound.c @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "sst_ringtones.h" -#include +#include "sst_sound.h" + #include +#include #include #include #include #include - #include "sst.h" #include "sst_json.h" #include "sst_vconf.h" @@ -158,9 +158,9 @@ static void _get_user_ringtones(system_settings_iter_cb callback, void *user_dat sst_json_get_ringtones(handle, callback, user_data); sst_json_unref(handle); } -int sst_ringtone_add_incoming_call(system_settings_key_e key, void *value) +int sst_sound_add_call_ringtone(system_settings_key_e key, const char *value) { - char *path = value; + const char *path = value; sst_json_h *handle = sst_json_load_ringtone(); if (sst_json_contain_ringtone(handle, path)) { @@ -183,7 +183,7 @@ int sst_ringtone_add_incoming_call(system_settings_key_e key, void *value) return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_ringtone_del_incoming_call(system_settings_key_e key, void *value) +int sst_sound_del_call_ringtone(system_settings_key_e key, const char *value) { sst_json_h *handle = sst_json_load_ringtone(); sst_json_remove_ringtone(handle, value); @@ -192,7 +192,7 @@ int sst_ringtone_del_incoming_call(system_settings_key_e key, void *value) return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_ringtone_list_incoming_call(system_settings_key_e key, system_settings_iter_cb callback, void *data) +int sst_sound_get_call_ringtone_list(system_settings_key_e key, system_settings_iter_cb callback, void *data) { RETV_IF(NULL == callback, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); @@ -202,36 +202,32 @@ int sst_ringtone_list_incoming_call(system_settings_key_e key, system_settings_i return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_ringtone_set_incoming_call(sst_interface *iface, void *value) +int sst_sound_set_call_ringtone(sst_interface *iface, const char *value) { - char *vconf_value = value; - - bool is_valid = sst_misc_exist(vconf_value); + bool is_valid = sst_misc_file_exists(value); if (false == is_valid) { - ERR("sst_misc_exist(%s) Fail", vconf_value); + ERR("sst_misc_file_exists(%s) Fail", value); return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; } - if (vconf_set_str(iface->vconf_key, vconf_value)) { - ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, vconf_value); + if (vconf_set_str(iface->vconf_key, value)) { + ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, value); return SYSTEM_SETTINGS_ERROR_IO_ERROR; } return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_ringtone_set_email_alert(sst_interface *iface, void *value) +int sst_sound_set_email_alert(sst_interface *iface, const char *value) { - char *vconf_value = value; - - bool is_valid = sst_misc_exist(vconf_value); + bool is_valid = sst_misc_file_exists(value); if (false == is_valid) { - ERR("sst_misc_exist(%s) Fail", vconf_value); + ERR("sst_misc_file_exists(%s) Fail", value); return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; } - if (vconf_set_str(iface->vconf_key, vconf_value)) { - ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, vconf_value); + if (vconf_set_str(iface->vconf_key, value)) { + ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, value); return SYSTEM_SETTINGS_ERROR_IO_ERROR; } @@ -243,15 +239,15 @@ int sst_ringtone_set_email_alert(sst_interface *iface, void *value) * @return the ringtone file path specified by user in normal case * if it's not accessable, return the default ringtone path */ -int sst_ringtone_get_incoming_call(sst_interface *iface, void **value) +int sst_sound_get_call_ringtone(sst_interface *iface, char **value) { char *vconf_value = NULL; - if (sst_vconf_get_string(iface->vconf_key, &vconf_value)) + if (sst_vconf_get_str_ally(iface->vconf_key, &vconf_value)) return SYSTEM_SETTINGS_ERROR_IO_ERROR; /* check to see if it's accessable -> OK */ /* no --> default ringtone path VCONFKEY_SETAPPL_CALL_RINGTONE_DEFAULT_PATH_STR */ - bool is_valid = sst_misc_exist(vconf_value); + bool is_valid = sst_misc_file_exists(vconf_value); if (true == is_valid) { *value = vconf_value; } else { @@ -262,15 +258,15 @@ int sst_ringtone_get_incoming_call(sst_interface *iface, void **value) return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_ringtone_get_email_alert(sst_interface *iface, void **value) +int sst_sound_get_email_alert(sst_interface *iface, char **value) { char *vconf_value = NULL; - if (sst_vconf_get_string(iface->vconf_key, &vconf_value)) + if (sst_vconf_get_str_ally(iface->vconf_key, &vconf_value)) return SYSTEM_SETTINGS_ERROR_IO_ERROR; /* check to see if it's accessable -> OK */ /* no --> default ringtone path VCONFKEY_SETAPPL_NOTI_RINGTONE_DEFAULT_PATH_STR */ - bool is_valid = sst_misc_exist(vconf_value); + bool is_valid = sst_misc_file_exists(vconf_value); if (true == is_valid) { *value = vconf_value; } else { @@ -280,3 +276,68 @@ int sst_ringtone_get_email_alert(sst_interface *iface, void **value) return SYSTEM_SETTINGS_ERROR_NONE; } + +/** + * sound == false, vibration == false --> silent mode + * sound == true, vibration == false --> sound mode + * sound == false, vibration == true --> vibration mode + */ +int sst_sound_get_silent_mode(sst_interface *iface, bool *value) +{ + int sound_status = 0; + if (VCONF_OK != vconf_get_bool(iface->vconf_key, &sound_status)) { + ERR("vconf_get_bool(%s) Fail", iface->vconf_key); + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + } + + const char *vibration_key = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL; + int vib_status = 0; + if (VCONF_OK != vconf_get_bool(vibration_key, &vib_status)) { + ERR("vconf_get_bool(%s) Fail", vibration_key); + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + } + + bool result = (sound_status == FALSE && vib_status == FALSE); + *value = result; + + return SYSTEM_SETTINGS_ERROR_NONE; +} + +/** + * sound == false, vibration == false --> silent mode + * sound == true, vibration == false --> sound mode + */ +//Todo: It should return to the old status. +int sst_sound_set_silent_mode(sst_interface *iface, bool value) +{ + int sound_state = !value; + if (vconf_set_bool(iface->vconf_key, sound_state)) { + ERR("vconf_set_bool(%s, %d) Fail", iface->vconf_key, sound_state); + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + } + + int vib_state = FALSE; + const char *vibration_key = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL; + if (vconf_set_bool(vibration_key, vib_state)) { + ERR("vconf_set_bool(%s) Fail", vibration_key); + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + } + + return SYSTEM_SETTINGS_ERROR_NONE; +} + +int sst_sound_set_notification(sst_interface *iface, const char *value) +{ + bool is_valid = sst_misc_file_exists(value); + if (true == is_valid) { + if (vconf_set_str(iface->vconf_key, value)) { + ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, value); + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + } + } else { + ERR("sst_misc_file_exists(%s) Fail", value); + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + } + + return SYSTEM_SETTINGS_ERROR_NONE; +} diff --git a/src/sst_sound.h b/src/sst_sound.h new file mode 100644 index 0000000..5de35aa --- /dev/null +++ b/src/sst_sound.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011-2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include "sst_interface.h" + +int sst_sound_get_call_ringtone(sst_interface *iface, char **value); +int sst_sound_set_call_ringtone(sst_interface *iface, const char *value); +int sst_sound_add_call_ringtone(system_settings_key_e key, const char *value); +int sst_sound_del_call_ringtone(system_settings_key_e key, const char *value); +int sst_sound_get_call_ringtone_list(system_settings_key_e key, system_settings_iter_cb callback, void *data); + +int sst_sound_get_email_alert(sst_interface *iface, char **value); +int sst_sound_set_email_alert(sst_interface *iface, const char *value); + +int sst_sound_set_notification(sst_interface *iface, const char *value); +int sst_sound_get_silent_mode(sst_interface *iface, bool *value); +int sst_sound_set_silent_mode(sst_interface *iface, bool value); diff --git a/src/sst_time_N_locale.c b/src/sst_time_N_locale.c index 7f56925..35e707a 100644 --- a/src/sst_time_N_locale.c +++ b/src/sst_time_N_locale.c @@ -23,11 +23,11 @@ #include "sst_misc.h" #include "sst_interface.h" -int sst_locale_get_country(sst_interface *iface, void **value) +int sst_locale_get_country(sst_interface *iface, char **value) { char *locale = NULL; - if (sst_vconf_get_string(iface->vconf_key, &locale)) { - ERR("sst_vconf_get_string(%s) Fail", iface->vconf_key); + if (sst_vconf_get_str_ally(iface->vconf_key, &locale)) { + ERR("sst_vconf_get_str_ally(%s) Fail", iface->vconf_key); return SYSTEM_SETTINGS_ERROR_IO_ERROR; } @@ -52,9 +52,8 @@ int sst_locale_get_country(sst_interface *iface, void **value) return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_locale_set_country(sst_interface *iface, void *value) +int sst_locale_set_country(sst_interface *iface, const char *country) { - char *country = value; const char *codeset = "UTF-8"; char locale[100]; @@ -68,7 +67,7 @@ int sst_locale_set_country(sst_interface *iface, void *value) return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_locale_get_language(sst_interface *iface, void **value) +int sst_locale_get_language(sst_interface *iface, char **value) { //It is same data with sst_locale_get_country() int ret = sst_locale_get_country(iface, value); @@ -80,7 +79,7 @@ int sst_locale_get_language(sst_interface *iface, void **value) return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_locale_set_language(sst_interface *iface, void *value) +int sst_locale_set_language(sst_interface *iface, const char *value) { //It is same data with sst_locale_set_country() int ret = sst_locale_set_country(iface, value); @@ -92,29 +91,28 @@ int sst_locale_set_language(sst_interface *iface, void *value) return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_locale_get_timeformat_24hour(sst_interface *iface, void **value) +int sst_locale_get_timeformat_24hour(sst_interface *iface, bool *value) { - int int_val; + int time_fmt; - if (vconf_get_int(iface->vconf_key, &int_val)) { + if (vconf_get_int(iface->vconf_key, &time_fmt)) { ERR("vconf_get_int(%s) Fail", iface->vconf_key); return SYSTEM_SETTINGS_ERROR_IO_ERROR; } - bool ret_value = true; - if (int_val == VCONFKEY_TIME_FORMAT_12) - ret_value = false; - else if (int_val == VCONFKEY_TIME_FORMAT_24) - ret_value = true; + bool result = true; + if (time_fmt == VCONFKEY_TIME_FORMAT_12) + result = false; + else if (time_fmt == VCONFKEY_TIME_FORMAT_24) + result = true; - *value = (void*)ret_value; + *value = result; return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_locale_set_timeformat_24hour(sst_interface *iface, void *value) +int sst_locale_set_timeformat_24hour(sst_interface *iface, bool is_24hour) { - bool is_24hour = *(bool*)value; int vconf_val; if (is_24hour) @@ -130,7 +128,7 @@ int sst_locale_set_timeformat_24hour(sst_interface *iface, void *value) return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_locale_get_timezone(sst_interface *iface, void **value) +int sst_locale_get_timezone(sst_interface *iface, char **value) { char tzpath[PATH_MAX]; ssize_t len = readlink(SETTING_TZONE_SYMLINK_PATH, tzpath, sizeof(tzpath) - 1); @@ -147,15 +145,13 @@ int sst_locale_get_timezone(sst_interface *iface, void **value) return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_locale_set_timezone(sst_interface *iface, void *value) +int sst_locale_set_timezone(sst_interface *iface, const char *timezone) { - char *timezone = value; - char tzpath[PATH_MAX]; snprintf(tzpath, sizeof(tzpath), SETTING_TIME_ZONEINFO_PATH"/%s", timezone); - if (false == sst_misc_exist(tzpath)) { - ERR("sst_misc_exist(%s) Fail", tzpath); + if (false == sst_misc_file_exists(tzpath)) { + ERR("sst_misc_file_exists(%s) Fail", tzpath); return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER; } @@ -172,11 +168,12 @@ int sst_locale_set_timezone(sst_interface *iface, void *value) } //TODO : checking this function is being used or not. -int sst_time_get_changed(sst_interface *iface, void **value) +int sst_time_get_changed(sst_interface *iface, int *value) { time_t cur_tick; - int ** val = (int**)value; + cur_tick = time(NULL); - **val = cur_tick; + *value = cur_tick; + return SYSTEM_SETTINGS_ERROR_NONE; } diff --git a/src/sst_time_N_locale.h b/src/sst_time_N_locale.h index 74509ad..65282b0 100644 --- a/src/sst_time_N_locale.h +++ b/src/sst_time_N_locale.h @@ -15,14 +15,14 @@ */ #pragma once -#include "sst_core.h" +#include "sst_interface.h" -int sst_locale_get_country(sst_interface *iface, void **value); -int sst_locale_set_country(sst_interface *iface, void *value); -int sst_locale_get_language(sst_interface *iface, void **value); -int sst_locale_set_language(sst_interface *iface, void *value); -int sst_locale_get_timeformat_24hour(sst_interface *iface, void **value); -int sst_locale_set_timeformat_24hour(sst_interface *iface, void *value); -int sst_locale_get_timezone(sst_interface *iface, void **value); -int sst_locale_set_timezone(sst_interface *iface, void *value); -int sst_time_get_changed(sst_interface *iface, void **value); +int sst_locale_get_country(sst_interface *iface, char **value); +int sst_locale_set_country(sst_interface *iface, const char *value); +int sst_locale_get_language(sst_interface *iface, char **value); +int sst_locale_set_language(sst_interface *iface, const char *value); +int sst_locale_get_timeformat_24hour(sst_interface *iface, bool *value); +int sst_locale_set_timeformat_24hour(sst_interface *iface, bool is_24hour); +int sst_locale_get_timezone(sst_interface *iface, char **value); +int sst_locale_set_timezone(sst_interface *iface, const char *timezone); +int sst_time_get_changed(sst_interface *iface, int *value); diff --git a/src/sst_utils_wrapper.c b/src/sst_utils_wrapper.c index e6f5aea..f86ca50 100644 --- a/src/sst_utils_wrapper.c +++ b/src/sst_utils_wrapper.c @@ -35,9 +35,9 @@ static void* _utils_load_lib() return sst_utils_handle; } -bool sstu_set_font_config(char *font_name) +bool sstu_set_font_config(const char *font_name) { - static bool (*fn_impl)(char*); + static bool (*fn_impl)(const char*); if (fn_impl) return fn_impl(font_name); @@ -57,9 +57,9 @@ bool sstu_set_font_config(char *font_name) return fn_impl(font_name); } -int sstu_is_available_font(char *font_name) +int sstu_is_available_font(const char *font_name) { - static int (*fn_impl)(char*) = NULL; + static int (*fn_impl)(const char*) = NULL; if (fn_impl) return fn_impl(font_name); @@ -101,16 +101,16 @@ char* sstu_get_default_font() return fn_impl(); } -bool sstu_is_valid_image(char *path) +bool sstu_is_valid_image(const char *path) { - static bool (*fn_impl)(char*) = NULL; + static bool (*fn_impl)(const char*) = NULL; if (fn_impl) return fn_impl(path); void *handle = _utils_load_lib(); if (NULL == handle) { ERR("No Utils Library Handle"); - return sst_misc_exist(path); + return sst_misc_file_exists(path); } fn_impl = dlsym(handle, "sstu_is_valid_image"); @@ -174,4 +174,4 @@ __attribute__((destructor)) static void _utils_unload_lib() dlclose(sst_utils_handle); sst_utils_handle = NULL; } -*/ \ No newline at end of file +*/ diff --git a/src/sst_utils_wrapper.h b/src/sst_utils_wrapper.h index 7186889..0f53de0 100644 --- a/src/sst_utils_wrapper.h +++ b/src/sst_utils_wrapper.h @@ -18,9 +18,9 @@ #include //It is same with util Library -bool sstu_set_font_config(char *font_name); -int sstu_is_available_font(char *font_name); +bool sstu_set_font_config(const char *font_name); +int sstu_is_available_font(const char *font_name); char* sstu_get_default_font(); -bool sstu_is_valid_image(char *path); +bool sstu_is_valid_image(const char *path); void sstu_set_font_size(); void sstu_font_config_set_notification(); diff --git a/src/sst_vconf.c b/src/sst_vconf.c index 9597d20..54f6a56 100644 --- a/src/sst_vconf.c +++ b/src/sst_vconf.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "sst.h" @@ -33,83 +34,93 @@ struct sst_vconf_info_s { void *cb_data; }; -int sst_vconf_set(sst_interface *iface, void *value) +int sst_vconf_set_int(sst_interface *iface, int val) { - char *vconf_char; - int vconf_int; - bool vconf_bool; - - switch (iface->data_type) { - case SYSTEM_SETTING_DATA_TYPE_STRING: - vconf_char = (char*)value; - if (vconf_set_str(iface->vconf_key, vconf_char)) - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - break; - case SYSTEM_SETTING_DATA_TYPE_INT: - //todo: change double pointer to valide data type - vconf_int = **(int**)value; - if (vconf_set_int(iface->vconf_key, vconf_int)) - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - break; - case SYSTEM_SETTING_DATA_TYPE_BOOL: - vconf_bool = *(bool*)value; - if (vconf_set_bool(iface->vconf_key, vconf_bool)) - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - break; - default: - ERR("Unknown type(%d)", iface->data_type); + RETV_IF(NULL == iface, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == iface->vconf_key, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); + + if (VCONF_OK != vconf_set_int(iface->vconf_key, val)) { + ERR("vconf_set_int(%s, %d) Fail", iface->vconf_key, val); return SYSTEM_SETTINGS_ERROR_IO_ERROR; } return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_vconf_get(sst_interface *iface, void **value) +int sst_vconf_set_bool(sst_interface *iface, bool val) { - char *vconf_char; - int vconf_int; - int **val = (int**)value; - bool vconf_bool; - - switch (iface->data_type) { - case SYSTEM_SETTING_DATA_TYPE_STRING: - if (sst_vconf_get_string(iface->vconf_key, &vconf_char)) - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - *value = vconf_char; - break; - case SYSTEM_SETTING_DATA_TYPE_INT: - if (vconf_get_int(iface->vconf_key, &vconf_int)) - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - **val = vconf_int; - break; - case SYSTEM_SETTING_DATA_TYPE_BOOL: - if (sst_vconf_get_real_bool(iface->vconf_key, &vconf_bool)) - return SYSTEM_SETTINGS_ERROR_IO_ERROR; - *value = (void*)vconf_bool; - break; - default: - ERR("Unknown type(%d)", iface->data_type); + RETV_IF(NULL == iface, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == iface->vconf_key, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); + + if (VCONF_OK != vconf_set_bool(iface->vconf_key, val)) { + ERR("vconf_set_bool(%s, %d) Fail", iface->vconf_key, val); + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + } + + return SYSTEM_SETTINGS_ERROR_NONE; +} + +int sst_vconf_set_str(sst_interface *iface, const char *val) +{ + RETV_IF(NULL == iface, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == iface->vconf_key, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); + + if (VCONF_OK != vconf_set_str(iface->vconf_key, val)) { + ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, val); + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + } + + return SYSTEM_SETTINGS_ERROR_NONE; +} + +int sst_vconf_get_int(sst_interface *iface, int *val) +{ + RETV_IF(NULL == iface, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == iface->vconf_key, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); + + int result = 0; + if (VCONF_OK != vconf_get_int(iface->vconf_key, &result)) { + ERR("vconf_get_int(%s) Fail", iface->vconf_key); return SYSTEM_SETTINGS_ERROR_IO_ERROR; } + *val = result ? true : false; + return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_vconf_get_real_bool(const char *vconf_key, bool *value) +int sst_vconf_get_bool(sst_interface *iface, bool *val) { - int temp = 0; - int ret = vconf_get_bool(vconf_key, &temp); - if (VCONF_OK != ret) { - ERR("vconf_get_bool(%s) Fail(%d)", vconf_key, ret); + RETV_IF(NULL == iface, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == iface->vconf_key, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); + + int result = 0; + if (VCONF_OK != vconf_get_bool(iface->vconf_key, &result)) { + ERR("vconf_get_bool(%s) Fail", iface->vconf_key); return SYSTEM_SETTINGS_ERROR_IO_ERROR; } - *value = temp ? true : false; + *val = result ? true : false; + + return SYSTEM_SETTINGS_ERROR_NONE; +} + +int sst_vconf_get_str(sst_interface *iface, char **val) +{ + RETV_IF(NULL == iface, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == iface->vconf_key, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER); + + char *result = vconf_get_str(iface->vconf_key); + if (NULL == result) { + ERR("vconf_get_str(%s) Fail(NULL)", iface->vconf_key); + return SYSTEM_SETTINGS_ERROR_IO_ERROR; + } + *val = result; return SYSTEM_SETTINGS_ERROR_NONE; } -int sst_vconf_get_string(const char *vconf_key, char **value) +int sst_vconf_get_str_ally(const char *vconf_key, char **value) { char *str_value = vconf_get_str(vconf_key); if (NULL == str_value) { diff --git a/src/sst_vconf.h b/src/sst_vconf.h index 2a4a1e7..e118f25 100644 --- a/src/sst_vconf.h +++ b/src/sst_vconf.h @@ -15,16 +15,20 @@ */ #pragma once -#include "sst_core.h" +#include "sst_interface.h" -int sst_vconf_get_real_bool(const char *vconf_key, bool *value); -int sst_vconf_get_string(const char *vconf_key, char **value); +int sst_vconf_get_str_ally(const char *vconf_key, char **value); -int sst_vconf_get(sst_interface *iface, void **value); -int sst_vconf_set(sst_interface *iface, void *value); +int sst_vconf_set_int(sst_interface *iface, int val); +int sst_vconf_set_bool(sst_interface *iface, bool val); +int sst_vconf_set_str(sst_interface *iface, const char *val); + +int sst_vconf_get_int(sst_interface *iface, int *val); +int sst_vconf_get_bool(sst_interface *iface, bool *val); +int sst_vconf_get_str(sst_interface *iface, char **val); int sst_vconf_set_cb(sst_interface *iface, system_settings_changed_cb cb, void *user_data); int sst_vconf_unset_cb(sst_interface *iface); int sst_vconf_add_multi_cb(sst_interface *iface, system_settings_changed_cb cb, void *user_data); -int sst_vconf_del_multi_cb(sst_interface *iface, system_settings_changed_cb cb); \ No newline at end of file +int sst_vconf_del_multi_cb(sst_interface *iface, system_settings_changed_cb cb);