2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "system_settings.h"
19 #include "sst_vconf.h"
20 #include "sst_sound.h"
21 #include "sst_interface.h"
23 API int system_settings_set_value_int(system_settings_key_e key, int value)
26 sst_interface *iface = NULL;
27 ret = sst_get_interface(key, &iface);
28 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
29 ERR("sst_get_interface(%d) Fail(%d)", key, ret);
33 if (SYSTEM_SETTING_DATA_TYPE_INT != iface->data_type) {
34 ERR("Invalide type for key(%d) : %d", key, iface->data_type);
35 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
38 if (NULL == iface->setter.i) {
39 ERR("No setter for key(%d)", key);
40 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
43 ret = iface->setter.i(iface, value);
44 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
45 ERR("setter(%d) Fail(%d)", key, ret);
49 return SYSTEM_SETTINGS_ERROR_NONE;
52 API int system_settings_get_value_int(system_settings_key_e key, int *value)
55 sst_interface *iface = NULL;
56 ret = sst_get_interface(key, &iface);
57 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
58 ERR("sst_get_interface(%d) Fail(%d)", key, ret);
62 if (SYSTEM_SETTING_DATA_TYPE_INT != iface->data_type) {
63 ERR("Invalide type for key(%d) : %d", key, iface->data_type);
64 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
67 if (NULL == iface->getter.i) {
68 ERR("No getter for key(%d)", key);
69 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
73 ret = iface->getter.i(iface, &result);
74 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
75 ERR("getter(%d) Fail(%d)", key, ret);
80 return SYSTEM_SETTINGS_ERROR_NONE;
83 API int system_settings_set_value_bool(system_settings_key_e key, bool value)
86 sst_interface *iface = NULL;
87 ret = sst_get_interface(key, &iface);
88 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
89 ERR("sst_get_interface(%d) Fail(%d)", key, ret);
93 if (SYSTEM_SETTING_DATA_TYPE_BOOL != iface->data_type) {
94 ERR("Invalide type for key(%d) : %d", key, iface->data_type);
95 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
98 if (NULL == iface->setter.b) {
99 ERR("No setter for key(%d)", key);
100 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
103 ret = iface->setter.b(iface, value);
104 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
105 ERR("setter(%d) Fail(%d)", key, ret);
109 return SYSTEM_SETTINGS_ERROR_NONE;
112 API int system_settings_get_value_bool(system_settings_key_e key, bool *value)
115 sst_interface *iface = NULL;
116 ret = sst_get_interface(key, &iface);
117 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
118 ERR("sst_get_interface(%d) Fail(%d)", key, ret);
122 if (SYSTEM_SETTING_DATA_TYPE_BOOL != iface->data_type) {
123 ERR("Invalide type for key(%d) : %d", key, iface->data_type);
124 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
127 if (NULL == iface->getter.b) {
128 ERR("No getter for key(%d)", key);
129 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
133 ret = iface->getter.b(iface, &result);
134 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
135 ERR("getter(%d) Fail(%d)", key, ret);
140 return SYSTEM_SETTINGS_ERROR_NONE;
143 API int system_settings_set_value_string(system_settings_key_e key, const char *value)
146 sst_interface *iface = NULL;
147 ret = sst_get_interface(key, &iface);
148 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
149 ERR("sst_get_interface(%d) Fail(%d)", key, ret);
153 if (SYSTEM_SETTING_DATA_TYPE_STRING != iface->data_type) {
154 ERR("Invalide type for key(%d) : %d", key, iface->data_type);
155 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
158 if (NULL == iface->setter.s) {
159 ERR("No setter for key(%d)", key);
160 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
163 ret = iface->setter.s(iface, value);
164 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
165 ERR("setter(%d) Fail(%d)", key, ret);
169 return SYSTEM_SETTINGS_ERROR_NONE;
172 API int system_settings_get_value_string(system_settings_key_e key, char **value)
175 sst_interface *iface = NULL;
176 ret = sst_get_interface(key, &iface);
177 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
178 ERR("sst_get_interface(%d) Fail(%d)", key, ret);
182 if (SYSTEM_SETTING_DATA_TYPE_STRING != iface->data_type) {
183 ERR("Invalide type for key(%d) : %d", key, iface->data_type);
184 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
187 if (NULL == iface->getter.s) {
188 ERR("No getter for key(%d)", key);
189 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
193 ret = iface->getter.s(iface, &result);
194 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
195 ERR("getter(%d) Fail(%d)", key, ret);
200 return SYSTEM_SETTINGS_ERROR_NONE;
203 //todo: need to deprecate
204 API int system_settings_set_changed_cb(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
208 RETV_IF(NULL == callback, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
210 sst_interface *iface = NULL;
211 ret = sst_get_interface(key, &iface);
212 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
213 ERR("sst_get_interface(%d) Fail(%d)", key, ret);
217 if (NULL == iface->vconf_key) {
218 ERR("NULL set_changed_cb of key(%d)", key);
219 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
222 return sst_vconf_set_cb(iface, callback, user_data);
225 //todo: need to deprecate
226 API int system_settings_unset_changed_cb(system_settings_key_e key)
228 sst_interface *iface = NULL;
229 int ret = sst_get_interface(key, &iface);
230 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
231 ERR("sst_get_interface(%d) Fail(%d)", key, ret);
235 if (NULL == iface->vconf_key) {
236 ERR("NULL set_changed_cb of key(%d)", key);
237 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
240 return sst_vconf_unset_cb(iface);
243 API int system_settings_foreach_value_string(system_settings_key_e key, system_settings_iter_cb callback, void *value)
246 RETVM_IF(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE != key,
247 SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER,
248 "Invalid Key(%d)", key);
250 return sst_sound_get_call_ringtone_list(key, callback, value);
253 API int system_settings_add_value_string(system_settings_key_e key, const char* value)
256 RETVM_IF(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE != key,
257 SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER,
258 "Invalid Key(%d)", key);
260 return sst_sound_add_call_ringtone(key, value);
263 API int system_settings_delete_value_string(system_settings_key_e key, const char* value)
266 RETVM_IF(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE != key,
267 SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER,
268 "Invalid Key(%d)", key);
270 return sst_sound_del_call_ringtone(key, value);
273 API int system_settings_add_changed_cb(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
277 RETV_IF(NULL == callback, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
279 sst_interface *iface = NULL;
280 ret = sst_get_interface(key, &iface);
281 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
282 ERR("sst_get_interface(%d) Fail(%d)", key, ret);
286 if (NULL == iface->vconf_key) {
287 ERR("NULL vconf_key of key(%d)", key);
288 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
291 INFO("key = %d, %s", key, iface->vconf_key);
293 ret = sst_vconf_add_multi_cb(iface, callback, user_data);
294 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
295 ERR("sst_vconf_add_multi_cb() Fail(%d)", ret);
299 return SYSTEM_SETTINGS_ERROR_NONE;
302 API int system_settings_remove_changed_cb(system_settings_key_e key, system_settings_changed_cb callback)
306 RETV_IF(NULL == callback, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
308 sst_interface *iface = NULL;
309 ret = sst_get_interface(key, &iface);
310 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
311 ERR("sst_get_interface(%d) Fail(%d)", key, ret);
315 if (NULL == iface->vconf_key) {
316 ERR("NULL vconf_key of key(%d)", key);
317 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
320 ret = sst_vconf_del_multi_cb(iface, callback);
321 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
322 ERR("sst_vconf_del_multi_cb() Fail(%d)", ret);
326 return SYSTEM_SETTINGS_ERROR_NONE;