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_SYSMAN_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,
32 static int (*update_setting) (int key_idx, int val);
34 int get_charging_status(int *val)
36 return vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, val);
39 int get_lowbatt_status(int *val)
41 return vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, val);
44 int get_usb_status(int *val)
46 return vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, val);
49 int set_setting_pmstate(int val)
51 return vconf_set_int(VCONFKEY_PM_STATE, val);
54 int get_setting_brightness(int *level)
56 return vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level);
59 int get_run_timeout(int *timeout)
61 int dim_timeout = -1, vconf_timeout = -1, ret;
62 get_dim_timeout(&dim_timeout);
65 LOGERR("Can not get dim timeout. set default 5 seconds");
69 ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout);
70 *timeout = vconf_timeout - dim_timeout;
75 int get_dim_timeout(int *timeout)
79 *timeout = 5; /* default timeout */
80 get_env("PM_TO_LCDDIM", buf, sizeof(buf));
81 LOGDBG("Get lcddim timeout [%s]", buf);
86 int get_off_timeout(int *timeout)
90 *timeout = 5; /* default timeout */
91 get_env("PM_TO_LCDOFF", buf, sizeof(buf));
92 LOGDBG("Get lcdoff timeout [%s]", buf);
97 static int setting_cb(keynode_t *key_nodes, void *data)
99 keynode_t *tmp = key_nodes;
101 if ((int)data > SETTING_END) {
102 LOGERR("Unknown setting key: %s, idx= %d",
103 vconf_keynode_get_name, (int)data);
106 if (update_setting != NULL) {
107 update_setting((int)data, vconf_keynode_get_int(tmp));
113 int init_setting(int (*func) (int key_idx, int val))
118 update_setting = func;
120 for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) {
121 vconf_notify_key_changed(setting_keys[i], (void *)setting_cb,
131 for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) {
132 vconf_ignore_key_changed(setting_keys[i], (void *)setting_cb);