2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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.
17 #include <device/display.h>
18 #include <device/callback.h>
24 #define LOCK_LCD_OFF_TIMEOUT_TIME 10
26 static Ecore_Timer *lcd_off_timer;
27 int LOCKSCREEN_EVENT_DISPLAY_STATUS_CHANGED;
28 static int init_count;
29 static int display_off;
31 static Eina_Bool _time_elapsed(void *data)
33 int ret = device_display_change_state(DISPLAY_STATE_SCREEN_OFF);
34 if (ret != DEVICE_ERROR_NONE) {
35 ERR("device_display_change_state failed: %s", get_error_message(ret));
39 return ECORE_CALLBACK_CANCEL;
42 static void _timer_reset(void)
45 ecore_timer_reset(lcd_off_timer);
47 lcd_off_timer = ecore_timer_add(LOCK_LCD_OFF_TIMEOUT_TIME, _time_elapsed, NULL);
51 static void _display_status_changed(device_callback_e type, void *value, void *user_data)
53 if (type != DEVICE_CALLBACK_DISPLAY_STATE)
56 display_state_e state = (display_state_e)value;
59 case DISPLAY_STATE_NORMAL:
60 case DISPLAY_STATE_SCREEN_DIM:
65 case DISPLAY_STATE_SCREEN_OFF:
71 ecore_event_add(LOCKSCREEN_EVENT_DISPLAY_STATUS_CHANGED, NULL, NULL, NULL);
74 int lockscreen_display_init(void)
76 display_state_e state;
79 LOCKSCREEN_EVENT_DISPLAY_STATUS_CHANGED = ecore_event_type_new();
80 int ret = device_add_callback(DEVICE_CALLBACK_DISPLAY_STATE, _display_status_changed, NULL);
81 if (ret != DEVICE_ERROR_NONE) {
82 ERR("device_add_callback failed: %s", get_error_message(ret));
85 ret = device_display_get_state(&state);
86 if (ret != DEVICE_ERROR_NONE) {
87 ERR("device_display_get_state failed: %s", get_error_message(ret));
88 device_remove_callback(DEVICE_CALLBACK_DISPLAY_STATE, _display_status_changed);
93 case DISPLAY_STATE_NORMAL:
94 case DISPLAY_STATE_SCREEN_DIM:
97 case DISPLAY_STATE_SCREEN_OFF:
109 void lockscreen_display_shutdown(void)
115 if (lcd_off_timer) ecore_timer_del(lcd_off_timer);
116 device_remove_callback(DEVICE_CALLBACK_DISPLAY_STATE, _display_status_changed);
121 void lockscreen_display_timer_freeze(void)
124 ecore_timer_freeze(lcd_off_timer);
128 void lockscreen_display_timer_renew(void)
131 ecore_timer_thaw(lcd_off_timer);
132 ecore_timer_reset(lcd_off_timer);
136 bool lockscreen_display_is_off(void)