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.
19 #include <Elementary.h>
22 #include <sys/types.h>
36 #include "starter-util.h"
38 #include "lock-daemon.h"
39 #include "lockd-debug.h"
40 #include "menu_daemon.h"
43 #define PACKAGE_NAME "org.tizen.starter"
46 #define DEFAULT_THEME "tizen"
47 #define PWLOCK_PATH "/usr/apps/org.tizen.pwlock/bin/pwlock"
49 #define DATA_ENCRYPTED "encrypted"
50 #define DATA_MOUNTED "mounted"
52 static void lock_menu_screen(void)
54 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 0);
57 static void unlock_menu_screen(void)
63 r = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &show_menu);
64 if (r || !show_menu) {
65 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 1);
69 static void _set_elm_theme(void)
74 vstr = vconf_get_str(VCONFKEY_SETAPPL_WIDGET_THEME_STR);
76 theme = DEFAULT_THEME;
81 _DBG("theme vconf[%s]\n set[%s]\n", vstr, theme);
82 elm_theme_set(th, theme);
89 static void _set_elm_entry(void)
94 r = vconf_get_bool(VCONFKEY_SETAPPL_AUTOCAPITAL_ALLOW_BOOL, &v);
96 prop_int_set("ENLIGHTENMENT_AUTOCAPITAL_ALLOW", v);
97 _DBG("vconf autocatipal[%d]", v);
100 r = vconf_get_bool(VCONFKEY_SETAPPL_AUTOPERIOD_ALLOW_BOOL, &v);
102 prop_int_set("ENLIGHTENMENT_AUTOPERIOD_ALLOW", v);
103 _DBG("vconf autoperiod[%d]", v);
108 static int _launch_pwlock(void)
113 _DBG("%s", __func__);
116 r = aul_launch_app("org.tizen.pwlock", NULL);
118 _ERR("PWLock launch error: error(%d)", r);
119 if (r == AUL_R_ETIMEOUT) {
120 _DBG("Launch pwlock is failed for AUL_R_ETIMEOUT, again launch pwlock");
121 r = aul_launch_app("org.tizen.pwlock", NULL);
123 _ERR("2'nd PWLock launch error: error(%d)", r);
126 _DBG("Launch pwlock");
133 _DBG("Launch pwlock");
138 r = aul_launch_app("org.tizen.pwlock", NULL);
140 _ERR("PWLock launch error: error(%d)", r);
141 if (r == AUL_R_ETIMEOUT) {
143 _DBG("Launching pwlock is failed [%d]times for AUL_R_ETIMEOUT ", i);
149 _DBG("Launch pwlock");
155 static void _signal_handler(int signum, siginfo_t *info, void *unused)
157 _DBG("_signal_handler : Terminated...");
161 static void _heynoti_event_power_off(void *data)
163 _DBG("_heynoti_event_power_off : Terminated...");
167 static Eina_Bool _init_idle(void *data)
169 _DBG("%s %d\n", __func__, __LINE__);
170 if (_launch_pwlock() < 0) {
171 _ERR("launch pwlock error");
173 menu_daemon_init(NULL);
175 return ECORE_CALLBACK_CANCEL;
178 static void _lock_state_cb(keynode_t * node, void *data)
180 _DBG("%s %d\n", __func__, __LINE__);
181 WRITE_FILE_LOG("%s", "Lock state is changed!");
183 if (_launch_pwlock() < 0) {
184 _ERR("launch pwlock error");
186 menu_daemon_init(NULL);
187 if (vconf_ignore_key_changed(VCONFKEY_IDLE_LOCK_STATE,
188 _lock_state_cb) != 0) {
189 LOCKD_DBG("Fail to unregister");
193 static void _data_encryption_cb(keynode_t * node, void *data)
198 _DBG("%s %d\n", __func__, __LINE__);
200 file = vconf_get_str(VCONFKEY_ODE_CRYPTO_STATE);
202 _DBG("get %s : %s\n", VCONFKEY_ODE_CRYPTO_STATE, file);
203 if (!strcmp(file, DATA_MOUNTED)) {
204 start_lock_daemon(FALSE);
205 menu_daemon_init(NULL);
211 static void _init(struct appdata *ad)
214 struct sigaction act;
217 memset(&act,0x00,sizeof(struct sigaction));
218 act.sa_sigaction = _signal_handler;
219 act.sa_flags = SA_SIGINFO;
221 int ret = sigemptyset(&act.sa_mask);
223 _ERR("Failed to sigemptyset[%s]", strerror(errno));
225 ret = sigaddset(&act.sa_mask, SIGTERM);
227 _ERR("Failed to sigaddset[%s]", strerror(errno));
229 ret = sigaction(SIGTERM, &act, NULL);
231 _ERR("Failed to sigaction[%s]", strerror(errno));
234 memset(ad, 0, sizeof(struct appdata));
236 gettimeofday(&ad->tv_start, NULL);
241 _DBG("%s %d\n", __func__, __LINE__);
243 /* Check data encrption */
244 file = vconf_get_str(VCONFKEY_ODE_CRYPTO_STATE);
246 _DBG("get %s : %s\n", VCONFKEY_ODE_CRYPTO_STATE, file);
247 if (!strcmp(file, DATA_ENCRYPTED)) {
248 if (vconf_notify_key_changed(VCONFKEY_ODE_CRYPTO_STATE,
249 _data_encryption_cb, NULL) != 0) {
250 _ERR("[Error] vconf notify changed : %s", VCONFKEY_ODE_CRYPTO_STATE);
252 _DBG("waiting mount..!!");
253 if (_launch_pwlock() < 0) {
254 _ERR("launch pwlock error");
263 /* change the launching order of pwlock and lock mgr in booting time */
264 /* TODO: menu screen is showed before phone lock is showed in booting time */
265 /* FIXME Here lock daemon start..!! */
266 r = start_lock_daemon(TRUE);
268 if (vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE,
269 _lock_state_cb, NULL) != 0) {
270 _ERR("[Error] vconf notify : lock state");
271 ecore_timer_add(1.5, _init_idle, NULL);
274 if (_launch_pwlock() < 0) {
275 _ERR("launch pwlock error");
277 menu_daemon_init(NULL);
281 static void _fini(struct appdata *ad)
283 struct timeval tv, res;
286 fprintf(stderr, "Invalid argument: appdata is NULL\n");
290 unlock_menu_screen();
293 gettimeofday(&tv, NULL);
294 timersub(&tv, &ad->tv_start, &res);
295 _DBG("Total time: %d.%06d sec\n", (int)res.tv_sec, (int)res.tv_usec);
298 int main(int argc, char *argv[])
302 WRITE_FILE_LOG("%s", "Main function is started in starter");
304 set_window_scale(); /* not in loop */
306 int heyfd = heynoti_init();
308 _ERR("Failed to heynoti_init[%d]", heyfd);
311 int ret = heynoti_subscribe(heyfd, "power_off_start", _heynoti_event_power_off, NULL);
313 _ERR("Failed to heynoti_subscribe[%d]", ret);
315 ret = heynoti_attach_handler(heyfd);
317 _ERR("Failed to heynoti_attach_handler[%d]", ret);
320 elm_init(argc, argv);