resetting manifest requested domain to floor
[platform/core/system/power-manager.git] / pm_setting.c
1 /*
2  * power-manager
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
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
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16 */
17
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include "pm_setting.h"
22 #include "pm_conf.h"
23 #include "util.h"
24
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,
33 };
34
35 static int (*update_setting) (int key_idx, int val);
36
37 int get_charging_status(int *val)
38 {
39         return vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, val);
40 }
41
42 int get_lowbatt_status(int *val)
43 {
44         return vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, val);
45 }
46
47 int get_usb_status(int *val)
48 {
49         return vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, val);
50 }
51
52 int set_setting_pmstate(int val)
53 {
54         return vconf_set_int(VCONFKEY_PM_STATE, val);
55 }
56
57 int get_setting_brightness(int *level)
58 {
59         return vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level);
60 }
61
62 int get_run_timeout(int *timeout)
63 {
64         int dim_timeout = -1, vconf_timeout = -1, ret;
65         get_dim_timeout(&dim_timeout);
66
67         if(dim_timeout < 0) {
68                 LOGERR("Can not get dim timeout. set default 5 seconds");
69                 dim_timeout = 5;
70         }
71
72         ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout);
73
74         if(vconf_timeout == 0)
75                 *timeout = 0; //timeout 0 : Always ON (Do not apply dim_timeout)
76         else
77                 *timeout = vconf_timeout - dim_timeout;
78         return ret;
79
80 }
81
82 int get_dim_timeout(int *timeout)
83 {
84         char buf[255];
85         /* TODO if needed */
86         *timeout = 5;           /* default timeout */
87         get_env("PM_TO_LCDDIM", buf, sizeof(buf));
88         LOGINFO("Get lcddim timeout [%s]", buf);
89         *timeout = atoi(buf);
90         return 0;
91 }
92
93 int get_off_timeout(int *timeout)
94 {
95         char buf[255];
96         /* TODO if needed */
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);
101         return 0;
102 }
103
104 static int setting_cb(keynode_t *key_nodes, void *data)
105 {
106         keynode_t *tmp = key_nodes;
107
108         if ((int)data > SETTING_END) {
109                 LOGERR("Unknown setting key: %s, idx= %d",
110                        vconf_keynode_get_name, (int)data);
111                 return -1;
112         }
113         if (update_setting != NULL) {
114                 if ((int)data >= SETTING_POWER_SAVING)
115                         update_setting((int)data, vconf_keynode_get_bool(tmp));
116                 else
117                         update_setting((int)data, vconf_keynode_get_int(tmp));
118         }
119
120         return 0;
121 }
122
123 int init_setting(int (*func) (int key_idx, int val))
124 {
125         int i;
126
127         if (func != NULL)
128                 update_setting = func;
129
130         for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) {
131                 vconf_notify_key_changed(setting_keys[i], (void *)setting_cb,
132                                          (void *)i);
133         }
134
135         return 0;
136 }
137
138 int exit_setting()
139 {
140         int i;
141         for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) {
142                 vconf_ignore_key_changed(setting_keys[i], (void *)setting_cb);
143         }
144
145         return 0;
146 }