3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 #include "pm_setting.h"
25 static const char *setting_keys[SETTING_GET_END] = {
26 [SETTING_TO_NORMAL] = VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL,
27 [SETTING_LOW_BATT] = VCONFKEY_SYSMAN_BATTERY_STATUS_LOW,
28 [SETTING_CHARGING] = VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW,
29 [SETTING_BRT_LEVEL] = VCONFKEY_SETAPPL_LCD_BRIGHTNESS,
30 [SETTING_LOCK_SCREEN] = VCONFKEY_IDLE_LOCK_STATE,
31 [SETTING_POWER_SAVING] = VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS,
32 [SETTING_POWER_SAVING_DISPLAY] = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_DISPLAY,
35 static int (*update_setting) (int key_idx, int val);
37 int get_charging_status(int *val)
39 return vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, val);
42 int get_lowbatt_status(int *val)
44 return vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, val);
47 int get_usb_status(int *val)
49 return vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, val);
52 int set_setting_pmstate(int val)
54 return vconf_set_int(VCONFKEY_PM_STATE, val);
57 int get_setting_brightness(int *level)
59 return vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level);
62 int get_run_timeout(int *timeout)
64 int dim_timeout = -1, vconf_timeout = -1, ret;
65 get_dim_timeout(&dim_timeout);
68 LOGERR("Can not get dim timeout. set default 5 seconds");
72 ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout);
74 if(vconf_timeout == 0)
75 *timeout = 0; //timeout 0 : Always ON (Do not apply dim_timeout)
77 *timeout = vconf_timeout - dim_timeout;
82 int get_dim_timeout(int *timeout)
86 *timeout = 5; /* default timeout */
87 get_env("PM_TO_LCDDIM", buf, sizeof(buf));
88 LOGINFO("Get lcddim timeout [%s]", buf);
93 int get_off_timeout(int *timeout)
97 *timeout = 5; /* default timeout */
98 get_env("PM_TO_LCDOFF", buf, sizeof(buf));
99 LOGINFO("Get lcdoff timeout [%s]", buf);
100 *timeout = atoi(buf);
104 static int setting_cb(keynode_t *key_nodes, void *data)
106 keynode_t *tmp = key_nodes;
108 if ((int)data > SETTING_END) {
109 LOGERR("Unknown setting key: %s, idx= %d",
110 vconf_keynode_get_name, (int)data);
113 if (update_setting != NULL) {
114 if ((int)data >= SETTING_POWER_SAVING)
115 update_setting((int)data, vconf_keynode_get_bool(tmp));
117 update_setting((int)data, vconf_keynode_get_int(tmp));
123 int init_setting(int (*func) (int key_idx, int val))
128 update_setting = func;
130 for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) {
131 vconf_notify_key_changed(setting_keys[i], (void *)setting_cb,
141 for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) {
142 vconf_ignore_key_changed(setting_keys[i], (void *)setting_cb);