2 * Copyright (c) 2011-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.
19 #include <app_manager.h>
20 #include <package_manager.h>
24 #include "sst_vconf.h"
25 #include "sst_interface.h"
27 int sst_get_value(system_settings_key_e key, sst_interface_data_type data_type, void **value)
32 RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key,
33 SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key);
34 RETV_IF(NULL == value, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
36 sst_interface *iface = NULL;
37 ret = sst_get_interface(key, &iface);
38 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
39 ERR("sst_get_interface(%d) Fail(%d)", key, ret);
43 if (iface->data_type != data_type) {
44 ERR("Invalide type for key(%d) : Expected(%d), Actual(%d)",
45 key, iface->data_type, data_type);
46 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
49 sst_get_value_fn getter = iface->get_value_cb;
51 ERR("No getter for key(%d)", key);
52 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
55 ret = getter(iface, value);
56 if (SYSTEM_SETTINGS_ERROR_NONE != ret)
57 ERR("getter(%d) Fail(%d)", key, ret);
61 int sst_set_value(system_settings_key_e key, sst_interface_data_type data_type, void *value)
66 RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key,
67 SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key);
68 RETV_IF(NULL == value, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
70 sst_interface *iface = NULL;
71 ret = sst_get_interface(key, &iface);
72 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
73 ERR("sst_get_interface(%d) Fail(%d)", key, ret);
77 if (iface->data_type != data_type) {
78 ERR("Invalide type for key(%d) : Expected(%d), Actual(%d)",
79 key, iface->data_type, data_type);
80 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
83 sst_set_value_fn setter = iface->set_value_cb;
85 ERR("No setter for key(%d)", key);
86 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
89 ret = setter(iface, value);
90 if (SYSTEM_SETTINGS_ERROR_NONE != ret)
91 ERR("setter(%d) Fail(%d)", key, ret);
95 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)
100 RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key,
101 SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key);
103 sst_interface *iface = NULL;
104 ret = sst_get_interface(key, &iface);
105 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
106 ERR("sst_get_interface(%d) Fail(%d)", key, ret);
110 if (iface->data_type != data_type) {
111 ERR("Invalide type for key(%d) : Expected(%d), Actual(%d)",
112 key, iface->data_type, data_type);
113 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
116 sst_list_value_cb list_getter = iface->list_value_cb;
117 if (NULL == list_getter) {
118 ERR("No list_getter for key(%d)", key);
119 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
122 ret = list_getter(key, list_iterator_fn, user_data);
123 if (SYSTEM_SETTINGS_ERROR_NONE != ret)
124 ERR("list_getter(%d) Fail(%d)", key, ret);
128 int sst_add_value(system_settings_key_e key, sst_interface_data_type data_type, void *value)
133 RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key,
134 SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key);
136 sst_interface *iface = NULL;
137 ret = sst_get_interface(key, &iface);
138 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
139 ERR("sst_get_interface(%d) Fail(%d)", key, ret);
143 if (iface->data_type != data_type) {
144 ERR("Invalide type for key(%d) : Expected(%d), Actual(%d)",
145 key, iface->data_type, data_type);
146 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
149 sst_add_value_fn adder = iface->add_value_cb;
151 ERR("No adder for key(%d)", key);
152 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
155 ret = adder(key, value);
156 if (SYSTEM_SETTINGS_ERROR_NONE != ret)
157 ERR("adder(%d) Fail(%d)", key, ret);
161 int sst_del_value(system_settings_key_e key, sst_interface_data_type data_type, void *value)
166 RETVM_IF(key < 0 || SYSTEM_SETTINGS_KEY_MAX <= key,
167 SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid Key(%d)", key);
169 sst_interface *iface = NULL;
170 ret = sst_get_interface(key, &iface);
171 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
172 ERR("sst_get_interface(%d) Fail(%d)", key, ret);
176 if (iface->data_type != data_type) {
177 ERR("Invalide type for key(%d) : Expected(%d), Actual(%d)",
178 key, iface->data_type, data_type);
179 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
182 sst_del_value_fn deleter;
183 deleter = iface->del_value_cb;
184 if (NULL == deleter) {
185 ERR("No deleter for key(%d)", key);
186 return SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED;
189 ret = deleter(key, value);
190 if (SYSTEM_SETTINGS_ERROR_NONE != ret)
191 ERR("deleter(%d) Fail(%d)", key, ret);
197 * sound == false, vibration == false --> silent mode
198 * sound == true, vibration == false --> sound mode
199 * sound == false, vibration == true --> vibration mode
201 int sst_get_sound_silent_mode(sst_interface *iface, void **value)
203 bool sound_status = false;
204 if (sst_vconf_get_real_bool(iface->vconf_key, &sound_status)) {
205 ERR("sst_vconf_get_real_bool(%s) Fail", iface->vconf_key);
206 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
209 bool vib_status = false;
210 const char *vibration_key = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL;
211 if (sst_vconf_get_real_bool(vibration_key, &vib_status)) {
212 ERR("sst_vconf_get_real_bool(%s) Fail", vibration_key);
213 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
216 bool ret_val = (sound_status == false && vib_status == false);
217 *value = (void*)ret_val;
219 return SYSTEM_SETTINGS_ERROR_NONE;
223 * sound == false, vibration == false --> silent mode
224 * sound == true, vibration == false --> sound mode
226 //Todo: It should return to the old status.
227 int sst_set_sound_silent_mode(sst_interface *iface, void *value)
229 bool *vconf_value = value;
231 bool vconf_sound = !(*vconf_value);
232 if (vconf_set_bool(iface->vconf_key, vconf_sound)) {
233 ERR("vconf_set_bool(%s, %d) Fail", iface->vconf_key, vconf_sound);
234 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
237 bool vconf_vib = false;
238 const char *vibration_key = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL;
239 if (vconf_set_bool(vibration_key, vconf_vib)) {
240 ERR("vconf_set_bool(%s) Fail", vibration_key);
241 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
244 return SYSTEM_SETTINGS_ERROR_NONE;
247 int sst_set_sound_notification(sst_interface *iface, void *value)
249 char *vconf_value = value;
251 bool is_valid = sst_misc_exist(vconf_value);
252 if (true == is_valid) {
253 if (vconf_set_str(iface->vconf_key, vconf_value)) {
254 ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, vconf_value);
255 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
258 ERR("sst_misc_exist(%s) Fail", vconf_value);
259 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
262 return SYSTEM_SETTINGS_ERROR_NONE;
265 int sst_set_device_name(system_settings_key_e key, void *value)
267 char *vconf_value = value;
269 const char *vconf_key = VCONFKEY_SETAPPL_DEVICE_NAME_STR;
270 if (vconf_set_str(vconf_key, vconf_value)) {
271 ERR("vconf_set_str(%s, %s) Fail", vconf_key, vconf_value);
272 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
275 return SYSTEM_SETTINGS_ERROR_NONE;
278 int sst_get_network_wifi_notification(sst_interface *iface, void **value)
281 if (vconf_get_int(iface->vconf_key, &vconf_value)) {
282 ERR("vconf_get_int(%s) Fail", iface->vconf_key);
283 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
287 result = (vconf_value == VCONFKEY_WIFI_QS_ENABLE) ? true : false;
289 *value = (void*)result;
290 return SYSTEM_SETTINGS_ERROR_NONE;
293 //It is related with Advertisements
294 #define DEFAULT_ADS_ID "00000000-0000-0000-0000-000000000000"
295 int sst_get_ads_id(sst_interface *iface, void **value)
298 const char *key = VCONFKEY_SETAPPL_AD_ID_OPT_OUT;
299 if (vconf_get_int(key, &result)) {
300 ERR("vconf_get_int(%s) Fail", key);
301 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
305 *value = strdup(DEFAULT_ADS_ID);
306 return SYSTEM_SETTINGS_ERROR_NONE;
309 char *vconf_value = NULL;
310 if (sst_vconf_get_string(iface->vconf_key, &vconf_value)) {
311 ERR("sst_vconf_get_string(%s) Fail", iface->vconf_key);
312 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
315 *value = vconf_value;
316 return SYSTEM_SETTINGS_ERROR_NONE;
319 int sst_set_ads_id(sst_interface *iface, void *value)
321 char *vconf_value = value;
323 if (vconf_set_str(iface->vconf_key, vconf_value)) {
324 ERR("vconf_set_str(%s) Fail", iface->vconf_key);
325 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
328 return SYSTEM_SETTINGS_ERROR_NONE;
331 int sst_get_uds_state(sst_interface *iface, void **value)
333 int **p_value = (int**)value;
335 char *str_val = NULL;
337 if (vconf_get_int(iface->vconf_key, &int_val))
338 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
340 if (int_val == SYSTEM_SETTINGS_UDS_ON) {
341 const char *vconf_key = VCONFKEY_SETAPPL_UDSM_PKGID_LIST;
342 int ret = sst_vconf_get_string(vconf_key, &str_val);
343 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
344 ERR("sst_vconf_get_string(%s) Fail(%d)", vconf_key, ret);
348 if (SST_EQUAL != strcmp(str_val, "NONE")) {
350 char *package_id = NULL;
351 pid_t pid = getpid();
353 int ret = app_manager_get_app_id(pid, &app_id);
354 if (ret != APP_MANAGER_ERROR_NONE) {
355 SECURE_ERR("app_manager_get_app_id(%d) Fail(%d)", pid, ret);
357 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
360 ret = package_manager_get_package_id_by_app_id(app_id, &package_id);
361 if (PACKAGE_MANAGER_ERROR_NONE != ret) {
362 SECURE_ERR("package_manager_get_package_id_by_app_id(%s) Fail(%d)", app_id, ret);
365 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
369 if (package_id && strstr(str_val, package_id))
370 int_val = SYSTEM_SETTINGS_UDS_ON_WHITELISTED;
378 return SYSTEM_SETTINGS_ERROR_NONE;