summaryrefslogtreecommitdiff
path: root/pm_setting.c
blob: c552edb134469619b87f2f928b66f742cd7e7072 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * power-manager
 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/


#include <stdio.h>
#include <stdlib.h>
#include "pm_setting.h"
#include "pm_conf.h"
#include "util.h"

static const char *setting_keys[SETTING_GET_END] = {
	[SETTING_TO_NORMAL] = VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL,
	[SETTING_LOW_BATT] = VCONFKEY_SYSMAN_BATTERY_STATUS_LOW,
	[SETTING_CHARGING] = VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW,
	[SETTING_BRT_LEVEL] = VCONFKEY_SETAPPL_LCD_BRIGHTNESS,
	[SETTING_LOCK_SCREEN] = VCONFKEY_IDLE_LOCK_STATE,
	[SETTING_POWER_SAVING] = VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS,
	[SETTING_POWER_SAVING_DISPLAY] = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_DISPLAY,
};

static int (*update_setting) (int key_idx, int val);

int get_charging_status(int *val)
{
	return vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, val);
}

int get_lowbatt_status(int *val)
{
	return vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, val);
}

int get_usb_status(int *val)
{
	return vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, val);
}

int set_setting_pmstate(int val)
{
	return vconf_set_int(VCONFKEY_PM_STATE, val);
}

int get_setting_brightness(int *level)
{
	return vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level);
}

int get_run_timeout(int *timeout)
{
	int dim_timeout = -1, vconf_timeout = -1, ret;
	get_dim_timeout(&dim_timeout);

	if(dim_timeout < 0) {
		LOGERR("Can not get dim timeout. set default 5 seconds");
		dim_timeout = 5;
	}

	ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout);

	if(vconf_timeout == 0)
		*timeout = 0; //timeout 0 : Always ON (Do not apply dim_timeout)
	else
		*timeout = vconf_timeout - dim_timeout;
	return ret;

}

int get_dim_timeout(int *timeout)
{
	char buf[255];
	/* TODO if needed */
	*timeout = 5;		/* default timeout */
	get_env("PM_TO_LCDDIM", buf, sizeof(buf));
	LOGINFO("Get lcddim timeout [%s]", buf);
	*timeout = atoi(buf);
	return 0;
}

int get_off_timeout(int *timeout)
{
	char buf[255];
	/* TODO if needed */
	*timeout = 5;		/* default timeout */
	get_env("PM_TO_LCDOFF", buf, sizeof(buf));
	LOGINFO("Get lcdoff timeout [%s]", buf);
	*timeout = atoi(buf);
	return 0;
}

static int setting_cb(keynode_t *key_nodes, void *data)
{
	keynode_t *tmp = key_nodes;

	if ((int)data > SETTING_END) {
		LOGERR("Unknown setting key: %s, idx= %d",
		       vconf_keynode_get_name, (int)data);
		return -1;
	}
	if (update_setting != NULL) {
		if ((int)data >= SETTING_POWER_SAVING)
			update_setting((int)data, vconf_keynode_get_bool(tmp));
		else
			update_setting((int)data, vconf_keynode_get_int(tmp));
	}

	return 0;
}

int init_setting(int (*func) (int key_idx, int val))
{
	int i;

	if (func != NULL)
		update_setting = func;

	for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) {
		vconf_notify_key_changed(setting_keys[i], (void *)setting_cb,
					 (void *)i);
	}

	return 0;
}

int exit_setting()
{
	int i;
	for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) {
		vconf_ignore_key_changed(setting_keys[i], (void *)setting_cb);
	}

	return 0;
}