display: Remove unused ambient code from headed plugin
[platform/core/system/deviced.git] / plugins / iot-headed / display / key-filter.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <stdlib.h>
23 #include <stdbool.h>
24 #include <assert.h>
25 #include <vconf.h>
26 #include <sys/types.h>
27 #include <libsyscommon/libgdbus.h>
28 #include <libsyscommon/resource-manager.h>
29 #include <system/syscommon-plugin-deviced-common-interface.h>
30 #include <system/syscommon-plugin-deviced-display-interface.h>
31 #include <linux/input.h>
32
33 #include "core.h"
34 #include "poll.h"
35 #include "device-interface.h"
36 #include "display-actor.h"
37 #include "display-panel.h"
38 #include "display-backlight.h"
39 #include "display-ops.h"
40 #include "display-config.h"
41 #include "display-misc.h"
42 #include "display-state-transition.h"
43 #include "display-util.h"
44 #include "shared/common.h"
45 #include "shared/devices.h"
46 #include "shared/device-notifier.h"
47 #include "shared/common.h"
48 #include "shared/apps.h"
49 #include "shared/log.h"
50 #include "power/power-off.h"
51 #include "power/power-suspend.h"
52 #include "led/touch-key.h"
53 #include "display-lock.h"
54 #include "input/input.h"
55
56 #ifndef KEY_SCREENLOCK
57 #define KEY_SCREENLOCK          0x98
58 #endif
59 #ifndef SW_GLOVE
60 #define SW_GLOVE                0x16
61 #endif
62
63 #define USEC_PER_SEC                    1000000
64
65 #define CAPTURE_COMBINATION_INTERVAL            0.5     /* 0.5 second */
66 #define TORCH_COMBINATION_INTERVAL                      0.1 /* 0.1 second */
67 #define DEFAULT_COMBINATION_INTERVAL            0.1 /* 0.1 second */
68
69 #define LONGKEY_PRESSED_TIME    4       /* 4 second */
70
71 #define SIGNAL_CHANGE_HARDKEY           "ChangeHardkey"
72 #define SIGNAL_LCDON_BY_POWERKEY        "LCDOnByPowerkey"
73 #define SIGNAL_LCDOFF_BY_POWERKEY       "LCDOffByPowerkey"
74
75 enum key_combination_flags {
76         KEY_COMBINATION_STOP            = 0,
77         KEY_COMBINATION_POWERKEY        = BIT(0),
78         KEY_COMBINATION_MENUKEY         = BIT(1),
79         KEY_COMBINATION_VOLUMEUP        = BIT(2),
80         KEY_COMBINATION_VOLUMEDOWN      = BIT(3),
81 };
82
83 enum combination_process {
84         COMBINATION_STOP        = KEY_COMBINATION_STOP,
85         COMBINATION_SCREENCAPTURE       = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_MENUKEY,
86         COMBINATION_TORCH       = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_VOLUMEUP,
87         COMBINATION_QUICKTALK   = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_VOLUMEDOWN,
88 };
89
90 static struct timeval pressed_time;
91 static guint longkey_timeout_id = 0;
92 static guint longkey_restore_id = 0;
93 static guint displayon_by_powerkey_timeout_id = 0;
94 static int cancel_lcdoff;
95 static int key_combination = KEY_COMBINATION_STOP;
96 static double combination_pressed_time;
97 static bool touch_pressed = false;
98 static int skip_lcd_off = false;
99 static int skip_combination = false;
100 static int bezel_wakeup = true;
101 static int booting_check = true;
102
103 static inline int current_state_in_on(void)
104 {
105         int ret;
106         enum deviced_display_state current;
107
108         ret = syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
109                 DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE, (int32_t *) &current);
110         if (ret < 0)
111                 return 0;
112
113         return ((current == DEVICED_DISPLAY_STATE_DIM) || (current == DEVICED_DISPLAY_STATE_ON));
114 }
115
116 static inline void restore_custom_brightness(void)
117 {
118         bool custom_status;
119         int ret;
120         enum deviced_display_state current;
121
122         ret = syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
123                 DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE, (int32_t *) &current);
124         if (ret < 0)
125                 return;
126
127         display_backlight_get_custom_status(&custom_status);
128         if (current == DEVICED_DISPLAY_STATE_DIM && custom_status)
129                 display_backlight_update_by_custom_brightness();
130 }
131
132 static void pwroff_popup(void)
133 {
134         int ret;
135
136         ret = launch_system_app(APP_POWERKEY, 2, APP_KEY_TYPE, APP_POWERKEY);
137         if (ret < 0)
138                 _E("Failed to launch power off popup.");
139 }
140
141 static void longkey_pressed(void)
142 {
143         unsigned int caps;
144
145         _I("Power key long pressed!");
146         cancel_lcdoff = 1;
147
148         caps = display_get_caps(DISPLAY_ACTOR_POWER_KEY);
149
150         if (display_has_caps(caps, DISPLAY_CAPA_LCDON)) {
151                 /* change state - LCD on */
152                 syscommon_resman_set_resource_attr_uint64_2(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
153                         DEVICED_DISPLAY_ATTR_TUPLE2_SET_CURRENT_STATE,
154                         DEVICED_DISPLAY_STATE_ON, DEVICED_EVENT_INPUT_POWERKEY);
155         }
156
157         if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF)) {
158                 _D("No poweroff capability!");
159                 return;
160         }
161
162         pwroff_popup();
163 }
164
165 static gboolean longkey_restore_cb(void *data)
166 {
167         syscommon_notifier_emit_notify(DEVICED_NOTIFIER_LONGKEY_RESTORE, (void *)NULL);
168         longkey_restore_id = 0;
169
170         return G_SOURCE_REMOVE;
171 }
172
173 static gboolean longkey_pressed_cb(void *data)
174 {
175         longkey_pressed();
176         longkey_timeout_id = 0;
177
178         return G_SOURCE_REMOVE;
179 }
180
181 static unsigned long timediff_usec(struct timeval t1, struct timeval t2)
182 {
183         unsigned long udiff;
184
185         udiff = (t2.tv_sec - t1.tv_sec) * USEC_PER_SEC;
186         udiff += (t2.tv_usec - t1.tv_usec);
187
188         return udiff;
189 }
190
191 static inline void check_key_pair(int code, int new, int *old)
192 {
193         if (new == *old)
194                 _E("key pair is not matched! (%d, %d)", code, new);
195         else
196                 *old = new;
197 }
198
199 static inline void broadcast_lcdon_by_powerkey(void)
200 {
201         gdbus_signal_emit(NULL,
202                                         DEVICED_PATH_DISPLAY,
203                                         DEVICED_INTERFACE_DISPLAY,
204                                         SIGNAL_LCDON_BY_POWERKEY,
205                                         NULL);
206 }
207
208 static inline void broadcast_lcdoff_by_powerkey(void)
209 {
210         gdbus_signal_emit(NULL,
211                                         DEVICED_PATH_DISPLAY,
212                                         DEVICED_INTERFACE_DISPLAY,
213                                         SIGNAL_LCDOFF_BY_POWERKEY,
214                                         NULL);
215 }
216
217 static inline bool switch_on_lcd(enum device_flags flags)
218 {
219         if (current_state_in_on())
220                 return false;
221
222         if (display_panel_get_dpms_cached_state() == DPMS_ON)
223                 return false;
224
225         if (flags & LCD_ON_BY_POWER_KEY)
226                 broadcast_lcdon_by_powerkey();
227         else if (flags & LCD_ON_BY_TOUCH)
228                 _I("Display on by Touch_wakeup event");
229
230         display_panel_lcd_on_direct(flags);
231
232         return true;
233 }
234
235 static inline void switch_off_lcd(void)
236 {
237         if (!current_state_in_on())
238                 return;
239
240         if (display_panel_get_dpms_cached_state() == DPMS_OFF)
241                 return;
242
243         broadcast_lcdoff_by_powerkey();
244
245         display_panel_lcd_off_procedure(LCD_OFF_BY_POWER_KEY);
246 }
247
248 static void check_key_combination(struct input_event *pinput)
249 {
250         double press_time, diff_time;
251         press_time = (pinput->time).tv_sec + USEC_TO_SEC((pinput->time).tv_usec);
252         diff_time = press_time - combination_pressed_time;
253
254         switch (key_combination) {
255         case COMBINATION_SCREENCAPTURE:
256                 if (diff_time <= CAPTURE_COMBINATION_INTERVAL) {
257                         _I("Combination key : SCREENCAPTURE mode");
258                         skip_combination = true;
259                 }
260                 break;
261         case COMBINATION_TORCH:
262                 if (diff_time <= TORCH_COMBINATION_INTERVAL) {
263                         /* When torch combination, display control should be not change. */
264                         if (displayon_by_powerkey_timeout_id) {
265                                 g_source_remove(displayon_by_powerkey_timeout_id);
266                                 displayon_by_powerkey_timeout_id = 0;
267                         }
268                         _I("Combination key : TORCH mode");
269                         skip_combination = true;
270                 } else
271                         key_combination = COMBINATION_STOP;
272                 break;
273         case COMBINATION_QUICKTALK:
274                 if (diff_time <= DEFAULT_COMBINATION_INTERVAL) {
275                         _I("Combination key : QUICK-TALK mode");
276                         skip_combination = true;
277                         if (longkey_timeout_id) {
278                                 g_source_remove(longkey_timeout_id);
279                                 longkey_timeout_id = 0;
280                         }
281                 }
282                 break;
283         default:
284                 combination_pressed_time = press_time;
285                 return;
286         }
287
288 }
289
290 static void start_key_combination(struct input_event *pinput)
291 {
292         switch (pinput->code) {
293         case KEY_POWER:
294                 key_combination |= KEY_COMBINATION_POWERKEY;
295                 break;
296         case KEY_MENU:
297                 key_combination |= KEY_COMBINATION_MENUKEY;
298                 break;
299         case KEY_VOLUMEUP:
300                 key_combination |= KEY_COMBINATION_VOLUMEUP;
301                 break;
302         case KEY_VOLUMEDOWN:
303                 key_combination |= KEY_COMBINATION_VOLUMEDOWN;
304                 break;
305         default:
306                 return;
307         }
308
309         check_key_combination(pinput);
310 }
311
312 static void stop_key_combination(struct input_event *pinput)
313 {
314         if (pinput == NULL) {
315                 key_combination = KEY_COMBINATION_STOP;
316                 return;
317         }
318
319         switch (pinput->code) {
320         case KEY_POWER:
321                 key_combination &= ~KEY_COMBINATION_POWERKEY;
322                 break;
323         case KEY_MENU:
324                 key_combination &= ~KEY_COMBINATION_MENUKEY;
325                 break;
326         case KEY_VOLUMEUP:
327                 key_combination &= ~KEY_COMBINATION_VOLUMEUP;
328                 break;
329         case KEY_VOLUMEDOWN:
330                 key_combination &= ~KEY_COMBINATION_VOLUMEDOWN;
331                 break;
332         default:
333                 _E("This code(%d) is not combination type.", pinput->code);
334                 break;
335         }
336 }
337
338 static void process_combination_key(struct input_event *pinput)
339 {
340         if (pinput->value == KEY_PRESSED)
341                 start_key_combination(pinput);
342         else if (pinput->value == KEY_RELEASED)
343                 stop_key_combination(pinput);
344 }
345
346 static int process_menu_key(struct input_event *pinput)
347 {
348         int caps;
349
350         caps = display_get_caps(DISPLAY_ACTOR_MENU_KEY);
351
352         if (!display_has_caps(caps, DISPLAY_CAPA_LCDON)) {
353                 if (current_state_in_on())
354                         return false;
355                 _D("No lcd-on capability!");
356                 return true;
357         } else if (pinput->value == KEY_PRESSED)
358                 switch_on_lcd(LCD_ON_BY_POWER_KEY);
359
360         return false;
361 }
362
363 static int decide_lcdoff(void)
364 {
365         /* It's not needed if it's already LCD off state */
366         if (!current_state_in_on() &&
367             display_panel_get_dpms_cached_state() != DPMS_ON)
368                 return false;
369
370         /*
371          * This flag is set at the moment
372          * that LCD is turned on by power key
373          * LCD has not to turned off in the situation.
374          */
375         if (skip_lcd_off)
376                 return false;
377
378         /* LCD is not turned off when powerkey is pressed,not released */
379         if (key_combination == KEY_COMBINATION_POWERKEY)
380                 return false;
381
382         /* LCD-off is blocked at the moment poweroff popup shows */
383         if (cancel_lcdoff)
384                 return false;
385
386         /* LCD-off is blocked when powerkey and volmedown key are pressed */
387         if (skip_combination)
388                 return false;
389
390         /* At booting time, display must do not turn off */
391         if (booting_check)
392                 return false;
393
394         return true;
395 }
396
397 static int lcdoff_powerkey(void)
398 {
399         int ignore = true;
400
401         if (decide_lcdoff() == true) {
402                 switch_off_lcd();
403                 display_lock_release_lock_all(DEVICED_DISPLAY_STATE_ON);
404                 display_lock_release_lock_all(DEVICED_DISPLAY_STATE_DIM);
405                 display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY);
406                 syscommon_resman_set_resource_attr_uint64_2(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
407                         DEVICED_DISPLAY_ATTR_TUPLE2_SET_CURRENT_STATE,
408                         DEVICED_DISPLAY_STATE_OFF, DEVICED_EVENT_INPUT_POWERKEY);
409         } else {
410                 ignore = false;
411                 skip_combination = false;
412         }
413         cancel_lcdoff = 0;
414
415         return ignore;
416 }
417
418 static int process_back_key(struct input_event *pinput)
419 {
420         int ignore = true;
421
422         if (pinput->value == KEY_PRESSED) {
423                 switch_on_lcd(LCD_ON_BY_BACK_KEY);
424                 _I("back key pressed");
425                 ignore = false;
426         }
427
428         return ignore;
429 }
430
431 static int process_power_key(struct input_event *pinput)
432 {
433         int ignore = true;
434         static int value = KEY_RELEASED;
435         unsigned int caps;
436         const struct display_config *display_conf = get_var_display_config();
437         if (!display_conf) {
438                 _E("Failed to get display configuration variable.");
439                 return ignore;
440         }
441
442         caps = display_get_caps(DISPLAY_ACTOR_POWER_KEY);
443
444         switch (pinput->value) {
445         case KEY_RELEASED:
446                 check_key_pair(pinput->code, pinput->value, &value);
447
448                 if (!display_conf->powerkey_doublepress) {
449                         if (display_has_caps(caps, DISPLAY_CAPA_LCDOFF))
450                                 lcdoff_powerkey();
451                         else
452                                 _D("No lcdoff capability!");
453                 } else if (skip_lcd_off)
454                         ignore = false;
455
456                 if (!display_has_caps(caps, DISPLAY_CAPA_LCDON))
457                         ignore = true;
458
459                 if (longkey_timeout_id > 0) {
460                         g_source_remove(longkey_timeout_id);
461                         longkey_timeout_id = 0;
462                 }
463
464                 if (longkey_restore_id > 0) {
465                         g_source_remove(longkey_restore_id);
466                         longkey_restore_id = 0;
467                 }
468
469                 break;
470         case KEY_PRESSED:
471                 if (display_has_caps(caps, DISPLAY_CAPA_LCDON)) {
472                         skip_lcd_off = switch_on_lcd(LCD_ON_BY_POWER_KEY);
473                 } else {
474                         _D("No lcdon capability!");
475                         skip_lcd_off = false;
476                 }
477                 check_key_pair(pinput->code, pinput->value, &value);
478                 _I("power key pressed");
479                 pressed_time.tv_sec = (pinput->time).tv_sec;
480                 pressed_time.tv_usec = (pinput->time).tv_usec;
481                 if (key_combination == KEY_COMBINATION_POWERKEY) {
482                         /* add long key timer */
483                         longkey_timeout_id = g_timeout_add_seconds(
484                                     display_conf->longpress_interval,
485                                     longkey_pressed_cb, NULL);
486                         /* add long key restore timer */
487                         longkey_restore_id = g_timeout_add_seconds(
488                                     LONGKEY_PRESSED_TIME,
489                                     longkey_restore_cb, NULL);
490                 }
491                 cancel_lcdoff = 0;
492
493                 break;
494         case KEY_BEING_PRESSED:
495                 if (timediff_usec(pressed_time, pinput->time) >
496                     (display_conf->longpress_interval * USEC_PER_SEC))
497                         longkey_pressed();
498                 break;
499         }
500         return ignore;
501 }
502
503 static int process_screenlock_key(struct input_event *pinput)
504 {
505         if (pinput->value != KEY_RELEASED) {
506                 stop_key_combination(NULL);
507                 return true;
508         }
509
510         if (!current_state_in_on())
511                 return false;
512
513         display_lock_release_lock_all(DEVICED_DISPLAY_STATE_ON);
514         display_lock_release_lock_all(DEVICED_DISPLAY_STATE_DIM);
515         display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY);
516
517         /* LCD off forcly */
518         syscommon_resman_set_resource_attr_uint64_2(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
519                 DEVICED_DISPLAY_ATTR_TUPLE2_SET_CURRENT_STATE,
520                 DEVICED_DISPLAY_STATE_OFF, DEVICED_EVENT_INPUT_POWERKEY);
521
522         return true;
523 }
524
525 static void sound_vibrate_hardkey(void)
526 {
527         /* device notify(vibrator) */
528         /* sound(dbus) */
529         /* Need to notify to deviced-vibrator. deviced-vibrator receives ChangedHardKey signal */
530         gdbus_signal_emit(NULL,
531                                         DEVICED_PATH_KEY,
532                                         DEVICED_INTERFACE_KEY,
533                                         SIGNAL_CHANGE_HARDKEY,
534                                         NULL);
535 }
536
537 static void process_hardkey_backlight(struct input_event *pinput)
538 {
539         _E("pinput->value : %d", pinput->value);
540         if (pinput->value == KEY_PRESSED) {
541                 /* Sound & Vibrate only in unlock state */
542                 if (__get_lock_screen_state() == VCONFKEY_IDLE_UNLOCK
543                     || get_lock_screen_bg_state())
544                         sound_vibrate_hardkey();
545
546                 touchled_control_backlight(TOUCHLED_PRESS);
547         } else if (pinput->value == KEY_RELEASED) {
548                 /* if lockscreen is idle lock */
549                 if (__get_lock_screen_state() == VCONFKEY_IDLE_LOCK) {
550                         _D("Lock state, key backlight is off when phone is unlocked!");
551                         return;
552                 }
553
554                 touchled_control_backlight(TOUCHLED_RELEASE);
555         }
556 }
557
558 static void update_vital_state(struct input_event *pinput)
559 {
560         int type;
561
562         /* Change vital state to  VITAL_EXIT only if vital mode is active */
563         if (!vital_mode())
564                 return;
565
566         /* Touch or Menu Key Release Event */
567         if (pinput->type == EV_ABS || (pinput->type == EV_KEY &&
568             pinput->value == KEY_RELEASED && pinput->code == KEY_MENU)) {
569                 /* Enable all services upon receiving user input, else maintain same state */
570                 type = VITAL_EXIT;
571                 syscommon_notifier_emit_notify(DEVICED_NOTIFIER_VITAL_STATE, &type);
572         }
573 }
574
575 static int check_key(struct input_event *pinput)
576 {
577         int ignore = true;
578
579         process_combination_key(pinput);
580         switch (pinput->code) {
581         case KEY_MENU:
582                 ignore = process_menu_key(pinput);
583                 break;
584         case KEY_POWER:
585                 ignore = process_power_key(pinput);
586                 if (current_state_in_on())
587                         ignore = false;
588                 break;
589         case KEY_SCREENLOCK:
590                 ignore = process_screenlock_key(pinput);
591                 break;
592         case KEY_BACK:
593                 ignore = process_back_key(pinput);
594                 stop_key_combination(NULL);
595                 if (current_state_in_on()) {
596                         process_hardkey_backlight(pinput);
597                         ignore = false;
598                 }
599                 break;
600         case KEY_PHONE:
601                 stop_key_combination(NULL);
602                 if (current_state_in_on()) {
603                         process_hardkey_backlight(pinput);
604                         ignore = false;
605                 }
606                 break;
607         case KEY_VOLUMEUP:
608         case KEY_VOLUMEDOWN:
609                 if (current_state_in_on())
610                         ignore = false;
611                 break;
612         case KEY_CAMERA:
613         case KEY_EXIT:
614         case KEY_CONFIG:
615         case KEY_MEDIA:
616         case KEY_MUTE:
617         case KEY_PLAYPAUSE:
618         case KEY_PLAYCD:
619         case KEY_PAUSECD:
620         case KEY_STOPCD:
621         case KEY_NEXTSONG:
622         case KEY_PREVIOUSSONG:
623         case KEY_REWIND:
624         case KEY_FASTFORWARD:
625                 stop_key_combination(NULL);
626                 if (current_state_in_on())
627                         ignore = false;
628                 break;
629         case 0x1DB:
630         case 0x1DC:
631         case 0x1DD:
632         case 0x1DE:
633                 stop_key_combination(NULL);
634                 break;
635         default:
636                 stop_key_combination(NULL);
637                 ignore = false;
638         }
639 #ifdef ENABLE_PM_LOG
640         if (pinput->value == KEY_PRESSED)
641                 pm_history_save(PM_LOG_KEY_PRESS, pinput->code);
642         else if (pinput->value == KEY_RELEASED)
643                 pm_history_save(PM_LOG_KEY_RELEASE, pinput->code);
644 #endif
645         return ignore;
646 }
647
648 static void check_key_filter(struct timeval time, unsigned short type, unsigned short keycode, unsigned int keyvalue)
649 {
650         struct input_event *pinput = &(struct input_event) {
651                 .time = time,
652                 .type = type,
653                 .code = keycode,
654                 .value = keyvalue
655         };
656         int ignore = true;
657         static int code, value;
658         int ret;
659         enum deviced_display_state current;
660
661         assert(pinput);
662
663         switch (pinput->type) {
664         case EV_KEY:
665                 if (pinput->code == BTN_TOUCH &&
666                         pinput->value == KEY_RELEASED)
667                         touch_pressed = false;
668                 /*
669                  * Normally, touch press/release events don't occur
670                  * in lcd off state. But touch release events can occur
671                  * in the state abnormally. Then touch events are ignored
672                  * when lcd is off state.
673                  */
674                 if (pinput->code == BTN_TOUCH && !current_state_in_on())
675                         break;
676                 if (pinput->code == code && pinput->value == value) {
677                         _E("Same key(%d, %d) is polled", code, value);
678                 }
679                 gdbus_signal_emit(NULL,
680                                  DEVICED_PATH_INPUT,
681                                  DEVICED_INTERFACE_INPUT,
682                                  "key",
683                                  g_variant_new("(iiii)", pinput->code, pinput->value, pinput->time.tv_sec, pinput->time.tv_usec));
684
685                 code = pinput->code;
686                 value = pinput->value;
687
688                 update_vital_state(pinput);
689                 ignore = check_key(pinput);
690                 restore_custom_brightness();
691
692                 break;
693         case EV_REL:
694                 ret = syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
695                         DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE, (int32_t *) &current);
696                 if (ret < 0)
697                         break;
698
699                 if (current == DEVICED_DISPLAY_STATE_OFF && bezel_wakeup) {
700                         switch_on_lcd(LCD_ON_BY_BEZEL);
701                         ignore = false;
702                 } else if (current != DEVICED_DISPLAY_STATE_OFF)
703                         ignore = false;
704                 break;
705         case EV_ABS:
706                 if (display_misc_is_touch_event_blocked()
707                         && !g_display_plugin.config->touch_wakeup
708                         && pinput->value == KEY_BEING_PRESSED)
709                         return;
710
711                 update_vital_state(pinput);
712                 if (pinput->value == KEY_PRESSED) {
713                         switch_on_lcd(LCD_ON_BY_TOUCH);
714                         ignore = false;
715                 }
716
717                 if (current_state_in_on())
718                         ignore = false;
719
720                 restore_custom_brightness();
721
722                 if (pinput->value == KEY_PRESSED)
723                         touch_pressed = true;
724                 else if (pinput->value == KEY_RELEASED)
725                         touch_pressed = false;
726                 break;
727         case EV_SW:
728                 break;
729         }
730
731         if (ignore)
732                 return;
733
734         /* lcd on or update lcd timeout */
735         syscommon_resman_set_resource_attr_uint64_2(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
736                 DEVICED_DISPLAY_ATTR_TUPLE2_SET_CURRENT_STATE,
737                 DEVICED_DISPLAY_STATE_ON, DEVICED_EVENT_INPUT);
738 }
739
740 static int delayed_init_done(void *data)
741 {
742         booting_check = 0;
743
744         return 0;
745 }
746
747 static int bezel_wakeup_cb(void *data)
748 {
749         bezel_wakeup = (int)((intptr_t)data);
750
751         return 0;
752 }
753
754 /*
755  * Default capability
756  * powerkey := LCDON | LCDOFF | POWEROFF
757  * homekey  := LCDON
758  */
759 static struct display_actor_ops display_powerkey_actor = {
760         .id     = DISPLAY_ACTOR_POWER_KEY,
761         .caps   = DISPLAY_CAPA_LCDON |
762                   DISPLAY_CAPA_LCDOFF |
763                   DISPLAY_CAPA_POWEROFF,
764 };
765
766 static struct display_actor_ops display_menukey_actor = {
767         .id     = DISPLAY_ACTOR_MENU_KEY,
768         .caps   = DISPLAY_CAPA_LCDON,
769 };
770
771 static void __CONSTRUCTOR__ initialize(void)
772 {
773         display_add_actor(&display_powerkey_actor);
774         display_add_actor(&display_menukey_actor);
775
776         syscommon_notifier_subscribe_notify(DEVICED_NOTIFIER_DELAYED_INIT, delayed_init_done);
777         syscommon_notifier_subscribe_notify(DEVICED_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb);
778
779         input_register_event_callback(check_key_filter, NULL, NULL, NULL);
780 }