2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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 <Elementary.h>
20 #include <sys/types.h>
35 #include "lock-daemon.h"
36 #include "lockd-debug.h"
38 #define DEFAULT_THEME "tizen"
40 #define HIB_CAPTURING "/opt/etc/.hib_capturing"
41 #define STR_STARTER_READY "/tmp/hibernation/starter_ready"
43 static void lock_menu_screen(void)
45 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 0);
48 static void unlock_menu_screen(void)
54 r = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &show_menu);
55 if (r || !show_menu) {
56 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 1);
60 static void _set_elm_theme(void)
65 vstr = vconf_get_str(VCONFKEY_SETAPPL_WIDGET_THEME_STR);
67 theme = DEFAULT_THEME;
72 _DBG("theme vconf[%s]\n set[%s]\n", vstr, theme);
73 elm_theme_set(th, theme);
78 static int _launch_pwlock(void)
84 r = aul_launch_app("org.tizen.pwlock", NULL);
86 _ERR("PWLock launch error: error(%d)", r);
87 if (r == AUL_R_ETIMEOUT) {
88 _DBG("Launch pwlock is failed for AUL_R_ETIMEOUT, again launch pwlock");
89 r = aul_launch_app("org.tizen.pwlock", NULL);
91 _ERR("2'nd PWLock launch error: error(%d)", r);
94 _DBG("Launch pwlock");
101 _DBG("Launch pwlock");
107 static void hib_leave(void *data)
109 struct appdata *ad = data;
111 fprintf(stderr, "Invalid argument: appdata is NULL\n");
115 _DBG("%s", __func__);
118 if (_launch_pwlock() < 0) {
119 _ERR("launch pwlock error");
123 static int add_noti(struct appdata *ad)
127 _DBG("%s %d\n", __func__, __LINE__);
130 fprintf(stderr, "Invalid argument: appdata is NULL\n");
136 _ERR("Noti init error");
141 r = heynoti_subscribe(fd, "HIBERNATION_PRELEAVE", hib_leave, ad);
143 _ERR("Noti subs error");
147 r = heynoti_attach_handler(fd);
149 _ERR("Noti attach error");
153 _DBG("Waiting for hib leave");
154 _DBG("%s %d\n", __func__, __LINE__);
159 static void _signal_handler(int signum, siginfo_t *info, void *unused)
161 _DBG("_signal_handler : Terminated...");
164 static void _heynoti_event_power_off(void *data)
166 _DBG("_heynoti_event_power_off : Terminated...");
170 static int _init(struct appdata *ad)
176 struct sigaction act;
177 act.sa_sigaction = _signal_handler;
178 act.sa_flags = SA_SIGINFO;
180 int ret = sigemptyset(&act.sa_mask);
182 _ERR("Failed to sigemptyset[%s]", strerror(errno));
184 ret = sigaddset(&act.sa_mask, SIGTERM);
186 _ERR("Failed to sigaddset[%s]", strerror(errno));
188 ret = sigaction(SIGTERM, &act, NULL);
190 _ERR("Failed to sigaction[%s]", strerror(errno));
193 memset(ad, 0, sizeof(struct appdata));
196 gettimeofday(&ad->tv_start, NULL);
201 _DBG("%s %d\n", __func__, __LINE__);
203 fd = open(HIB_CAPTURING, O_RDONLY);
204 _DBG("fd = %d\n", fd);
206 _DBG("fd = %d\n", fd);
208 if (_launch_pwlock() < 0) {
209 _ERR("launch pwlock error");
217 fd1 = open(STR_STARTER_READY, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
219 _DBG("Hibernation ready.\n");
226 static void _fini(struct appdata *ad)
228 struct timeval tv, res;
231 fprintf(stderr, "Invalid argument: appdata is NULL\n");
235 heynoti_close(ad->noti);
237 unlock_menu_screen();
239 gettimeofday(&tv, NULL);
240 timersub(&tv, &ad->tv_start, &res);
241 _DBG("Total time: %d.%06d sec\n", (int)res.tv_sec, (int)res.tv_usec);
244 int main(int argc, char *argv[])
248 int heyfd = heynoti_init();
250 _ERR("Failed to heynoti_init[%d]", heyfd);
253 int ret = heynoti_subscribe(heyfd, "power_off_start", _heynoti_event_power_off, NULL);
255 _ERR("Failed to heynoti_subscribe[%d]", ret);
257 ret = heynoti_attach_handler(heyfd);
259 _ERR("Failed to heynoti_attach_handler[%d]", ret);
262 elm_init(argc, argv);