4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
29 #define LCD_DIM_RATIO 0.2
30 #define LCD_MAX_DIM_TIMEOUT 7000
32 static const char *setting_keys[SETTING_GET_END] = {
33 [SETTING_TO_NORMAL] = VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL,
34 [SETTING_BRT_LEVEL] = VCONFKEY_SETAPPL_LCD_BRIGHTNESS,
35 [SETTING_LOCK_SCREEN] = VCONFKEY_IDLE_LOCK_STATE,
36 [SETTING_POWER_SAVING] = VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS,
37 [SETTING_POWER_SAVING_DISPLAY] = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_DISPLAY,
38 [SETTING_SMART_STAY] = VCONFKEY_SETAPPL_SMARTSCREEN_SMARTSTAY_STATUS,
39 [SETTING_BOOT_POWER_ON_STATUS] = VCONFKEY_DEVICED_BOOT_POWER_ON_STATUS,
40 [SETTING_POWER_CUSTOM_BRIGHTNESS] = VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS,
41 [SETTING_ACCESSIBILITY_TTS] = VCONFKEY_SETAPPL_ACCESSIBILITY_TTS,
44 static int lock_screen_state = VCONFKEY_IDLE_UNLOCK;
45 static bool lock_screen_bg_state = false;
46 static int force_lcdtimeout = 0;
47 static int custom_on_timeout = 0;
48 static int custom_normal_timeout = 0;
49 static int custom_dim_timeout = 0;
51 int (*update_pm_setting) (int key_idx, int val);
53 int set_force_lcdtimeout(int timeout)
58 force_lcdtimeout = timeout;
63 int get_lock_screen_state(void)
65 return lock_screen_state;
68 void set_lock_screen_state(int state)
71 case VCONFKEY_IDLE_LOCK:
72 case VCONFKEY_IDLE_UNLOCK:
73 lock_screen_state = state;
76 lock_screen_state = VCONFKEY_IDLE_UNLOCK;
80 int get_lock_screen_bg_state(void)
82 return lock_screen_bg_state;
85 void set_lock_screen_bg_state(bool state)
87 _I("state is %d", state);
88 lock_screen_bg_state = state;
91 int get_charging_status(int *val)
93 return vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, val);
96 int get_lowbatt_status(int *val)
98 return vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, val);
101 int get_usb_status(int *val)
103 return vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, val);
106 int set_setting_pmstate(int val)
108 return vconf_set_int(VCONFKEY_PM_STATE, val);
111 int get_setting_brightness(int *level)
113 return vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level);
116 int get_dim_timeout(int *dim_timeout)
118 int vconf_timeout, on_timeout, val, ret;
120 if (custom_dim_timeout > 0) {
121 *dim_timeout = custom_dim_timeout;
125 ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout);
127 _E("Failed ro get setting timeout!");
128 vconf_timeout = DEFAULT_NORMAL_TIMEOUT;
131 if (force_lcdtimeout > 0)
132 on_timeout = SEC_TO_MSEC(force_lcdtimeout);
134 on_timeout = SEC_TO_MSEC(vconf_timeout);
136 val = (double)on_timeout * LCD_DIM_RATIO;
137 if (val > LCD_MAX_DIM_TIMEOUT)
138 val = LCD_MAX_DIM_TIMEOUT;
145 int get_run_timeout(int *timeout)
147 int dim_timeout = -1;
148 int vconf_timeout = -1;
152 if (custom_normal_timeout > 0) {
153 *timeout = custom_normal_timeout;
157 ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout);
159 _E("Failed ro get setting timeout!");
160 vconf_timeout = DEFAULT_NORMAL_TIMEOUT;
163 if (force_lcdtimeout > 0)
164 on_timeout = SEC_TO_MSEC(force_lcdtimeout);
166 on_timeout = SEC_TO_MSEC(vconf_timeout);
168 get_dim_timeout(&dim_timeout);
173 *timeout = on_timeout - dim_timeout;
178 int set_custom_lcdon_timeout(int timeout)
180 int changed = (custom_on_timeout == timeout ? false : true);
182 custom_on_timeout = timeout;
185 custom_normal_timeout = 0;
186 custom_dim_timeout = 0;
190 custom_dim_timeout = (double)timeout * LCD_DIM_RATIO;
191 custom_normal_timeout = timeout - custom_dim_timeout;
193 _I("custom normal(%d), dim(%d)", custom_normal_timeout,
199 static int setting_cb(keynode_t *key_nodes, void *data)
201 keynode_t *tmp = key_nodes;
203 if ((int)data > SETTING_END) {
204 _E("Unknown setting key: %s, idx=%d",
205 vconf_keynode_get_name(tmp), (int)data);
208 if (update_pm_setting != NULL) {
210 case SETTING_POWER_SAVING:
211 case SETTING_POWER_SAVING_DISPLAY:
212 case SETTING_ACCESSIBILITY_TTS:
213 update_pm_setting((int)data, vconf_keynode_get_bool(tmp));
216 update_pm_setting((int)data, vconf_keynode_get_int(tmp));
224 int init_setting(int (*func) (int key_idx, int val))
229 update_pm_setting = func;
231 for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) {
232 vconf_notify_key_changed(setting_keys[i], (void *)setting_cb,
239 int exit_setting(void)
242 for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) {
243 vconf_ignore_key_changed(setting_keys[i], (void *)setting_cb);