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 "sst_screen.h"
19 #include <pkgmgr-info.h>
22 #include "sst_vconf.h"
23 #include "sst_utils.h"
24 #include "sst_exclusive.h"
26 int sst_screen_set_backlight_time(sst_interface *iface, void *value)
28 int *vconf_value = *(int **)value;
30 if (*vconf_value <= 0 || 600 < *vconf_value) {
31 ERR("Invalid Value(%d)", *vconf_value);
32 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
35 if (vconf_set_int(iface->vconf_key, *vconf_value)) {
36 ERR("vconf_set_int(%s, %d) Fail", iface->vconf_key, *vconf_value);
37 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
40 return SYSTEM_SETTINGS_ERROR_NONE;
43 static bool _screen_is_valid_img(char *path)
48 bool (*image_type_check)(char *path);
50 handle = dlopen(SETTING_UTILS_SO_FILE_PATH, RTLD_LAZY | RTLD_GLOBAL);
52 ERR("dlopen(%s) Fail(%d)", SETTING_UTILS_SO_FILE_PATH, errno);
56 image_type_check = dlsym(handle, "sstu_is_valid_image");
57 if ((error = dlerror()) != NULL) {
58 ERR("dlsym(sstu_is_valid_image) Fail(%s)", error);
63 ret = image_type_check(path);
68 int sst_screen_set_home_wallpaper(sst_interface *iface, void *value)
70 char *vconf_value = value;
72 bool valid = _screen_is_valid_img(vconf_value);
74 ERR("Invalid image file(%s)", vconf_value);
75 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
78 return sst_excl_set_wallpaper(iface->vconf_key, vconf_value);
81 int sst_screen_set_lock_wallpaper(sst_interface *iface, void *value)
83 char *vconf_value = value;
85 bool valid = _screen_is_valid_img(vconf_value);
87 ERR("Invalid image file(%s)", vconf_value);
88 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
91 if (vconf_set_str(iface->vconf_key, vconf_value)) {
92 ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, vconf_value);
93 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
96 return SYSTEM_SETTINGS_ERROR_NONE;
99 static int _category_func(const char *name, void *user_data)
101 const char *category = "lock-screen";
102 bool *found = user_data;
104 RETV_IF(NULL == name, PMINFO_R_OK);
106 if (SST_EQUAL == strcmp(name, category)) {
108 return PMINFO_R_ERROR; //not Error. It stops iteration.
110 DBG("Unexpeced category(%s)", name);
119 * set 'swipe type' if current lockscreen app is 'com.samsung.lockscreen'
122 int sst_screen_set_lockscreen(sst_interface *iface, void *value)
125 char *app_id = value; //ex) com.samsung.lockscreen
127 RETV_IF(NULL == value, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
129 pkgmgrinfo_appinfo_h handle = NULL;
130 ret = pkgmgrinfo_appinfo_get_appinfo(app_id, &handle);
131 if (PMINFO_R_OK != ret) {
132 ERR("pkgmgrinfo_appinfo_get_appinfo(%s) Fail(%d)", app_id, ret);
133 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
136 bool is_lock_screen = false;
137 ret = pkgmgrinfo_appinfo_foreach_category(handle, _category_func, &is_lock_screen);
138 if (ret != PMINFO_R_OK) {
139 ERR("pkgmgrinfo_appinfo_foreach_category() Fail(%d)", ret);
140 pkgmgrinfo_appinfo_destroy_appinfo(handle);
141 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
143 pkgmgrinfo_appinfo_destroy_appinfo(handle);
145 if (false == is_lock_screen) {
146 ERR("Invalid Application(%s)", app_id);
147 //Todo: It should be enable.
148 //return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
152 if (vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &locktype)) {
153 ERR("vconf_get_int(lock_type) Fail");
154 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
157 if (locktype == SETTING_SCREEN_LOCK_TYPE_PASSWORD) {
158 ERR("Unsupported lock type");
159 return SYSTEM_SETTINGS_ERROR_LOCKSCREEN_APP_PASSWORD_MODE;
162 if (vconf_set_str(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, app_id)) {
163 ERR("vconf_set_str(3rd lock pkg) Fail");
164 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
167 if (SST_EQUAL == strcmp(app_id, "com.samsung.lockscreen")) {
168 const char *lock_type_key = VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT;
169 if (vconf_set_int(lock_type_key, SETTING_SCREEN_LOCK_TYPE_SWIPE)) {
170 ERR("vconf_set_int(%s) Fail", lock_type_key);
171 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
174 return SYSTEM_SETTINGS_ERROR_NONE;
177 int sst_screen_get_lockscreen(sst_interface *iface, void **value)
179 char *pkg_name = NULL;
182 if (vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &locktype)) {
183 ERR("vconf_get_int(lock_type) Fail");
184 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
187 if (sst_vconf_get_string(iface->vconf_key, &pkg_name)) {
188 ERR("sst_vconf_get_string(%s) Fail", iface->vconf_key);
189 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
192 if (SST_EQUAL == strcmp(pkg_name, "com.samsung.lockscreen")
193 && locktype == SETTING_SCREEN_LOCK_TYPE_PASSWORD) {
194 //if current lock type is 'password', return SYSTEM_SETTINGS_ERROR_LOCKSCREEN_APP_PASSWORD_MODE
196 return SYSTEM_SETTINGS_ERROR_LOCKSCREEN_APP_PASSWORD_MODE;
200 return SYSTEM_SETTINGS_ERROR_NONE;