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"
20 #include <pkgmgr-info.h>
23 #include "sst_vconf.h"
24 #include "sst_exclusive.h"
25 #include "sst_utils_wrapper.h"
27 int sst_screen_set_backlight_time(sst_interface *iface, int value)
29 if (value <= 0 || 600 < value) {
30 ERR("Invalid Value(%d)", value);
31 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
34 if (vconf_set_int(iface->vconf_key, value)) {
35 ERR("vconf_set_int(%s, %d) Fail", iface->vconf_key, value);
36 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
39 return SYSTEM_SETTINGS_ERROR_NONE;
42 int sst_screen_set_home_wallpaper(sst_interface *iface, const char *value)
44 bool valid = sstu_is_valid_image(value);
46 ERR("Invalid image file(%s)", value);
47 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
50 return sst_excl_set_wallpaper(iface->vconf_key, value);
53 int sst_screen_set_lock_wallpaper(sst_interface *iface, const char *value)
55 bool valid = sstu_is_valid_image(value);
57 ERR("Invalid image file(%s)", value);
58 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
61 if (vconf_set_str(iface->vconf_key, value)) {
62 ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, value);
63 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
66 return SYSTEM_SETTINGS_ERROR_NONE;
69 static int _category_func(const char *name, void *user_data)
71 const char *category = "lock-screen";
72 bool *found = user_data;
74 RETV_IF(NULL == name, PMINFO_R_OK);
76 if (SST_EQUAL == strcmp(name, category)) {
78 return PMINFO_R_ERROR; //not Error. It stops iteration.
80 DBG("Unexpeced category(%s)", name);
88 * set 'swipe type' if current lockscreen app is 'com.samsung.lockscreen'
90 int sst_screen_set_lockscreen(sst_interface *iface, const char *app_id)
94 RETV_IF(NULL == app_id, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
95 //ex) app_id = com.samsung.lockscreen
97 pkgmgrinfo_appinfo_h handle = NULL;
98 ret = pkgmgrinfo_appinfo_get_appinfo(app_id, &handle);
99 if (PMINFO_R_OK != ret) {
100 ERR("pkgmgrinfo_appinfo_get_appinfo(%s) Fail(%d)", app_id, ret);
101 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
104 bool is_lock_screen = false;
105 ret = pkgmgrinfo_appinfo_foreach_category(handle, _category_func, &is_lock_screen);
106 if (ret != PMINFO_R_OK) {
107 ERR("pkgmgrinfo_appinfo_foreach_category() Fail(%d)", ret);
108 pkgmgrinfo_appinfo_destroy_appinfo(handle);
109 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
111 pkgmgrinfo_appinfo_destroy_appinfo(handle);
113 if (false == is_lock_screen) {
114 ERR("Invalid Application(%s)", app_id);
115 //Todo: It should be enable.
116 //return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
120 if (vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &locktype)) {
121 ERR("vconf_get_int(lock_type) Fail");
122 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
125 if (locktype == SETTING_SCREEN_LOCK_TYPE_PASSWORD) {
126 ERR("Unsupported lock type");
127 return SYSTEM_SETTINGS_ERROR_LOCKSCREEN_APP_PASSWORD_MODE;
130 if (vconf_set_str(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, app_id)) {
131 ERR("vconf_set_str(3rd lock pkg) Fail");
132 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
135 if (SST_EQUAL == strcmp(app_id, "com.samsung.lockscreen")) {
136 const char *lock_type_key = VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT;
137 if (vconf_set_int(lock_type_key, SETTING_SCREEN_LOCK_TYPE_SWIPE)) {
138 ERR("vconf_set_int(%s) Fail", lock_type_key);
139 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
142 return SYSTEM_SETTINGS_ERROR_NONE;
145 int sst_screen_get_lockscreen(sst_interface *iface, char **value)
147 char *pkg_name = NULL;
150 if (vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &locktype)) {
151 ERR("vconf_get_int(lock_type) Fail");
152 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
155 if (sst_vconf_get_str_ally(iface->vconf_key, &pkg_name)) {
156 ERR("sst_vconf_get_str_ally(%s) Fail", iface->vconf_key);
157 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
160 if (SST_EQUAL == strcmp(pkg_name, "com.samsung.lockscreen")
161 && locktype == SETTING_SCREEN_LOCK_TYPE_PASSWORD) {
162 //if current lock type is 'password', return SYSTEM_SETTINGS_ERROR_LOCKSCREEN_APP_PASSWORD_MODE
164 return SYSTEM_SETTINGS_ERROR_LOCKSCREEN_APP_PASSWORD_MODE;
168 return SYSTEM_SETTINGS_ERROR_NONE;