2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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.
20 #include "pm_setting.h"
24 static const char *setting_keys[SETTING_GET_END] = {
25 [SETTING_TO_NORMAL] = VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL,
26 [SETTING_LOW_BATT] = VCONFKEY_SYSMAN_BATTERY_STATUS_LOW,
27 [SETTING_CHARGING] = VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW,
28 [SETTING_BRT_LEVEL] = VCONFKEY_SETAPPL_LCD_BRIGHTNESS,
29 [SETTING_LOCK_SCREEN] = VCONFKEY_IDLE_LOCK_STATE,
30 [SETTING_POWER_SAVING] = VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS,
31 [SETTING_POWER_SAVING_DISPLAY] = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_DISPLAY,
34 static int (*update_setting) (int key_idx, int val);
36 int get_charging_status(int *val)
38 return vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, val);
41 int get_lowbatt_status(int *val)
43 return vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, val);
46 int get_usb_status(int *val)
48 return vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, val);
51 int set_setting_pmstate(int val)
53 return vconf_set_int(VCONFKEY_PM_STATE, val);
56 int get_setting_brightness(int *level)
58 return vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level);
61 int get_run_timeout(int *timeout)
63 int dim_timeout = -1, vconf_timeout = -1, ret;
64 get_dim_timeout(&dim_timeout);
67 LOGERR("Can not get dim timeout. set default 5 seconds");
71 ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout);
73 if(vconf_timeout == 0)
74 *timeout = 0; //timeout 0 : Always ON (Do not apply dim_timeout)
76 *timeout = vconf_timeout - dim_timeout;
81 int get_dim_timeout(int *timeout)
85 *timeout = 5; /* default timeout */
86 get_env("PM_TO_LCDDIM", buf, sizeof(buf));
87 LOGINFO("Get lcddim timeout [%s]", buf);
92 int get_off_timeout(int *timeout)
96 *timeout = 5; /* default timeout */
97 get_env("PM_TO_LCDOFF", buf, sizeof(buf));
98 LOGINFO("Get lcdoff timeout [%s]", buf);
103 static int setting_cb(keynode_t *key_nodes, void *data)
105 keynode_t *tmp = key_nodes;
107 if ((int)data > SETTING_END) {
108 LOGERR("Unknown setting key: %s, idx= %d",
109 vconf_keynode_get_name, (int)data);
112 if (update_setting != NULL) {
113 if ((int)data >= SETTING_POWER_SAVING)
114 update_setting((int)data, vconf_keynode_get_bool(tmp));
116 update_setting((int)data, vconf_keynode_get_int(tmp));
122 int init_setting(int (*func) (int key_idx, int val))
127 update_setting = func;
129 for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) {
130 vconf_notify_key_changed(setting_keys[i], (void *)setting_cb,
140 for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) {
141 vconf_ignore_key_changed(setting_keys[i], (void *)setting_cb);