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.
30 #define LCD_DIM_RATIO 0.3
31 #define LCD_MAX_DIM_TIMEOUT 7000
32 #define LCD_MIN_DIM_TIMEOUT 500
34 static const char *setting_keys[SETTING_GET_END] = {
35 [SETTING_TO_NORMAL] = VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL,
36 [SETTING_BRT_LEVEL] = VCONFKEY_SETAPPL_LCD_BRIGHTNESS,
37 [SETTING_LOCK_SCREEN] = VCONFKEY_IDLE_LOCK_STATE,
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 if (get_ambient_mode != NULL &&
126 get_ambient_mode() == true) {
127 *dim_timeout = LCD_MIN_DIM_TIMEOUT;
131 ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout);
133 _E("Failed ro get setting timeout!");
134 vconf_timeout = DEFAULT_NORMAL_TIMEOUT;
137 if (force_lcdtimeout > 0)
138 on_timeout = SEC_TO_MSEC(force_lcdtimeout);
140 on_timeout = SEC_TO_MSEC(vconf_timeout);
142 val = (double)on_timeout * LCD_DIM_RATIO;
143 if (val > LCD_MAX_DIM_TIMEOUT)
144 val = LCD_MAX_DIM_TIMEOUT;
151 int get_run_timeout(int *timeout)
153 int dim_timeout = -1;
154 int vconf_timeout = -1;
158 if (custom_normal_timeout > 0) {
159 *timeout = custom_normal_timeout;
163 ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout);
165 _E("Failed ro get setting timeout!");
166 vconf_timeout = DEFAULT_NORMAL_TIMEOUT;
169 if (force_lcdtimeout > 0)
170 on_timeout = SEC_TO_MSEC(force_lcdtimeout);
172 on_timeout = SEC_TO_MSEC(vconf_timeout);
177 if (on_timeout == 0) {
178 *timeout = on_timeout;
182 get_dim_timeout(&dim_timeout);
183 *timeout = on_timeout - dim_timeout;
187 int set_custom_lcdon_timeout(int timeout)
189 int changed = (custom_on_timeout == timeout ? false : true);
191 custom_on_timeout = timeout;
194 custom_normal_timeout = 0;
195 custom_dim_timeout = 0;
199 custom_dim_timeout = (double)timeout * LCD_DIM_RATIO;
200 custom_normal_timeout = timeout - custom_dim_timeout;
202 _I("custom normal(%d), dim(%d)", custom_normal_timeout,
208 static int setting_cb(keynode_t *key_nodes, void *data)
210 keynode_t *tmp = key_nodes;
212 if ((int)data > SETTING_END) {
213 _E("Unknown setting key: %s, idx=%d",
214 vconf_keynode_get_name(tmp), (int)data);
217 if (update_pm_setting != NULL) {
219 case SETTING_ACCESSIBILITY_TTS:
220 update_pm_setting((int)data, vconf_keynode_get_bool(tmp));
223 update_pm_setting((int)data, vconf_keynode_get_int(tmp));
231 int init_setting(int (*func) (int key_idx, int val))
236 update_pm_setting = func;
238 for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) {
239 vconf_notify_key_changed(setting_keys[i], (void *)setting_cb,
246 int exit_setting(void)
249 for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) {
250 vconf_ignore_key_changed(setting_keys[i], (void *)setting_cb);