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.
27 #include "display-ops.h"
28 #include "core/common.h"
29 #include "core/device-handler.h"
32 #define SMART_DETECTION_LIB "/usr/lib/sensor_framework/libsmart_detection.so"
33 #define CB_TIMEOUT 3 /* seconds */
34 #define OCCUPIED_FAIL -2
36 typedef void (*detection_cb)(int result, void *data);
38 static void *detect_handle = NULL;
39 static int (*get_detection)(detection_cb callback, int type, void* user_data1, void* user_data2);
40 static bool block_state = EINA_FALSE;
41 static bool cb_state = EINA_FALSE;
42 static Ecore_Timer *cb_timeout_id = NULL;
44 static void init_smart_lib(void)
46 detect_handle = dlopen(SMART_DETECTION_LIB, RTLD_LAZY);
51 get_detection = (int (*)(detection_cb, int, void *, void *))
52 dlsym(detect_handle, "get_smart_detection");
56 dlclose(detect_handle);
62 static Eina_Bool check_cb_state(void *data)
66 int user_data = (int)(data);
71 _I("smart detection cb is already working!");
72 return ECORE_CALLBACK_CANCEL;
76 _I("input event occur, smart detection is ignored!");
77 block_state = EINA_FALSE;
78 return ECORE_CALLBACK_CANCEL;
81 if (user_data < S_START || user_data > S_LCDOFF) {
82 _E("next state is wrong [%d], set to [%d]",
87 _I("smart detection cb is failed, goes to [%d]", user_data);
89 next_state = user_data;
90 pm_old_state = pm_cur_state;
91 pm_cur_state = next_state;
93 st = &states[pm_cur_state];
95 st->action(st->timeout);
97 if (pm_cur_state == S_LCDOFF)
98 update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT);
100 return ECORE_CALLBACK_CANCEL;
103 static void detection_callback(int degree, void *data)
107 int user_data = (int)(data);
109 cb_state = EINA_TRUE;
112 _I("input event occur, face detection is ignored!");
113 block_state = EINA_FALSE;
117 if (!get_hallic_open()) {
118 _I("hallic is closed! Skip detection logic!");
122 _I("degree = [%d], user_data = [%d]", degree, user_data);
130 _I("face detection success, goes to [%d]",
132 pm_old_state = pm_cur_state;
133 pm_cur_state = S_NORMAL;
136 _I("camera is occupied, stay current state");
139 if (user_data < S_START || user_data > S_LCDOFF) {
140 _E("next state is wrong [%d], set to [%d]",
141 user_data, S_NORMAL);
142 user_data = S_NORMAL;
145 next_state = user_data;
147 pm_old_state = pm_cur_state;
148 pm_cur_state = next_state;
150 if (check_lcdoff_direct() == true)
151 pm_cur_state = S_LCDOFF;
153 _I("smart detection is failed, goto [%d]state", pm_cur_state);
158 st = &states[pm_cur_state];
160 st->action(st->timeout);
162 if (pm_cur_state == S_LCDOFF)
163 update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT);
166 static int check_face_detection(int evt, int pm_cur_state, int next_state)
168 int lock_state = EINA_FALSE;
172 ecore_timer_del(cb_timeout_id);
173 cb_timeout_id = NULL;
176 if (evt == EVENT_INPUT) {
177 block_state = EINA_TRUE;
180 block_state = EINA_FALSE;
182 if (evt != EVENT_TIMEOUT)
185 if (pm_cur_state != S_NORMAL)
188 if (!get_detection) {
190 if (!get_detection) {
191 _E("%s load failed!", SMART_DETECTION_LIB);
196 state = get_detection(detection_callback, SMART_STAY, NULL, (void*)next_state);
199 _E("get detection FAIL [%d]", state);
201 _I("get detection success");
203 cb_state = EINA_FALSE;
204 cb_timeout_id = ecore_timer_add(CB_TIMEOUT,
205 (Ecore_Task_Cb)check_cb_state, (void*)next_state);
209 static void smartstay_init(void *data)
211 display_info.face_detection = check_face_detection;
214 static void smartstay_exit(void *data)
217 dlclose(detect_handle);
218 detect_handle = NULL;
219 _D("detect handle is closed!");
221 get_detection = NULL;
222 display_info.face_detection = NULL;
225 static const struct display_ops display_smartstay_ops = {
227 .init = smartstay_init,
228 .exit = smartstay_exit,
231 DISPLAY_OPS_REGISTER(&display_smartstay_ops)