4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
25 #include "display-ops.h"
27 #include "core/edbus-handler.h"
28 #include "core/devices.h"
31 * this definition will be removed,
32 * after the key is merge to all branch.
34 #ifndef VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL
35 #define VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL "db/setting/ambient_mode"
38 #define ALPM_BUS_NAME "org.tizen.graphics.alpmclock"
39 #define ALPM_OBJECT_PATH "/Org/Tizen/Graphics/AlpmClock"
40 #define ALPM_PATH_LCD ALPM_OBJECT_PATH"/LCD"
41 #define ALPM_INTERFACE_LCD ALPM_BUS_NAME".LCD"
42 #define ALPM_NODE_STATUS "alpm_node_status"
47 #define SIGNAL_ALPM_ON "ALPMOn"
48 #define SIGNAL_ALPM_OFF "ALPMOff"
49 #define CLOCK_START "clockstart"
50 #define CLOCK_END "clockend"
51 #define TIMEOUT_NONE (-1)
52 #define ALPM_CLOCK_WAITING_TIME 5000 /* ms */
54 static char *alpm_path;
55 static int update_count;
56 static int alpm_state;
57 static pid_t alpm_pid;
58 static int ambient_mode;
60 int get_ambient_mode(void)
65 void broadcast_alpm_state(int state)
69 signal = (state == true ? SIGNAL_ALPM_ON : SIGNAL_ALPM_OFF);
71 broadcast_edbus_signal(DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
75 bool check_suspend_direct(pid_t pid)
79 if (pm_cur_state == S_NORMAL ||
80 pm_cur_state == S_LCDDIM)
86 if (check_lock_state(S_SLEEP) == true)
89 if (backlight_ops.get_lcd_power() != PM_LCD_POWER_OFF)
92 _I("goto sleep state direct!");
94 reset_timeout(TIMEOUT_NONE);
95 pm_old_state = pm_cur_state;
96 pm_cur_state = S_SLEEP;
97 st = &states[pm_cur_state];
100 st->action(TIMEOUT_NONE);
105 int alpm_get_state(void)
113 ret = sys_get_str(alpm_path, state);
117 if (!strncmp(state, ON, strlen(ON)))
119 else if (!strncmp(state, OFF, strlen(OFF)))
127 int alpm_set_state(int on)
135 broadcast_alpm_state(on);
142 _D("ALPM is %s", (on ? ON : OFF));
146 return sys_set_str(alpm_path, (on ? ON : OFF));
149 int check_alpm_lcdon_ready(void)
154 _E("It's not always on mode");
158 if (alpm_get_state() == false) {
159 _E("Now alpm node is off!");
163 _D("wating until updating alpm clock");
165 ret = dbus_method_sync(ALPM_BUS_NAME,
166 ALPM_PATH_LCD, ALPM_INTERFACE_LCD,
167 ALPM_NODE_STATUS, NULL, NULL);
169 _D("it's ready for lcd on");
174 void check_alpm_invalid_state(void)
176 if (backlight_ops.get_lcd_power() == PM_LCD_POWER_OFF)
179 if (alpm_get_state() == false)
182 _E("Invalid state! alpm state is change to off!");
184 /* If lcd_power is on and alpm state is true
185 * when pm state is changed to sleep
186 * deviced doesn't get the clock signal.
187 * deviced just turns off lcd in this case. */
189 alpm_set_state(false);
190 backlight_ops.off(NORMAL_MODE);
193 static void start_clock(void)
195 if (pm_cur_state == S_NORMAL ||
196 pm_cur_state == S_LCDDIM ||
200 pm_lock_internal(INTERNAL_LOCK_ALPM,
201 LCD_OFF, STAY_CUR_STATE, ALPM_CLOCK_WAITING_TIME);
204 static void end_clock(pid_t pid)
206 if (pm_cur_state == S_NORMAL ||
207 pm_cur_state == S_LCDDIM ||
211 if (update_count == 0) {
213 backlight_ops.off(NORMAL_MODE);
214 pm_unlock_internal(INTERNAL_LOCK_ALPM,
215 LCD_OFF, PM_SLEEP_MARGIN);
220 _I("enter real alpm state by %d (%d)",
221 alpm_pid, update_count);
226 int set_alpm_screen(char *screen, pid_t pid)
234 if (!strncmp(screen, CLOCK_START,
235 strlen(CLOCK_START))) {
237 } else if (!strncmp(screen, CLOCK_END,
238 strlen(CLOCK_END))) {
245 static void set_ambient_mode(keynode_t *key_nodes, void *data)
247 if (key_nodes == NULL) {
248 _E("wrong parameter, key_nodes is null");
252 ambient_mode = vconf_keynode_get_bool(key_nodes);
253 _I("ambient mode is %d", ambient_mode);
256 pm_unlock_internal(INTERNAL_LOCK_ALPM, LCD_OFF,
259 set_dim_state(ambient_mode ? false : true);
262 static void alpm_init(void *data)
267 ret = vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL,
270 _E("Failed to get ambient mode! (%d)", ret);
271 ambient_mode = false;
273 _I("ambient mode is %d", ambient_mode);
275 vconf_notify_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL,
276 set_ambient_mode, NULL);
278 alpm_path = getenv("ALPM_NODE");
280 /* Check alpm node is valid */
281 fd = open(alpm_path, O_RDONLY);
283 _E("alpm node is invalid");
287 _I("alpm path[%s] is initialized!", alpm_path);
292 static void alpm_exit(void *data)
294 alpm_set_state(false);
297 static const struct display_ops display_alpm_ops = {
303 DISPLAY_OPS_REGISTER(&display_alpm_ops)