2 * Copyright (c) 2000 - 2015 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 <Elementary.h>
20 #include <sys/types.h>
32 #include "starter-util.h"
34 #include "lock-daemon.h"
35 #include "lockd-debug.h"
36 #include "menu_daemon.h"
39 #define PACKAGE_NAME "com.samsung.starter"
42 #define DEFAULT_THEME "tizen"
43 #define PWLOCK_PATH "/usr/apps/com.samsung.pwlock/bin/pwlock"
44 #define PWLOCK_PKG_NAME "com.samsung.pwlock"
45 #define PWLOCK_LITE_PKG_NAME "com.samsung.pwlock-lite"
47 #define DATA_UNENCRYPTED "unencrypted"
48 #define DATA_MOUNTED "mounted"
49 #define SD_DATA_ENCRYPTED "encrypted"
50 #define SD_CRYPT_META_FILE ".MetaEcfsFile"
51 #define MMC_MOUNT_POINT "/opt/storage/sdcard"
59 static int _check_encrypt_sdcard()
61 const char *crypt_file = SD_CRYPT_META_FILE;
62 char *meta_data_file = NULL;
66 length = strlen(MMC_MOUNT_POINT) + strlen(crypt_file) + 2;
68 meta_data_file = malloc(length);
69 if (!meta_data_file) {
74 snprintf(meta_data_file, length, "%s/%s", MMC_MOUNT_POINT, crypt_file);
75 if (access(meta_data_file, F_OK) == 0) {
80 _DBG("Check sd card ecryption : %d", ret);
85 static void lock_menu_screen(void)
87 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 0);
90 static void unlock_menu_screen(void)
96 r = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &show_menu);
97 if (r || !show_menu) {
98 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 1);
102 static void _set_elm_theme(void)
106 Elm_Theme *th = NULL;
107 vstr = vconf_get_str(VCONFKEY_SETAPPL_WIDGET_THEME_STR);
109 theme = DEFAULT_THEME;
113 th = elm_theme_new();
114 _DBG("theme vconf[%s]\n set[%s]\n", vstr, theme);
115 elm_theme_set(th, theme);
122 static void _set_elm_entry(void)
127 r = vconf_get_bool(VCONFKEY_SETAPPL_AUTOCAPITAL_ALLOW_BOOL, &v);
129 prop_int_set("ENLIGHTENMENT_AUTOCAPITAL_ALLOW", v);
130 _DBG("vconf autocatipal[%d]", v);
133 r = vconf_get_bool(VCONFKEY_SETAPPL_AUTOPERIOD_ALLOW_BOOL, &v);
135 prop_int_set("ENLIGHTENMENT_AUTOPERIOD_ALLOW", v);
136 _DBG("vconf autoperiod[%d]", v);
141 static int _launch_pwlock(void)
146 _DBG("%s", __func__);
149 r = aul_launch_app(PWLOCK_LITE_PKG_NAME, NULL);
151 _ERR("PWLock launch error: error(%d)", r);
152 if (r == AUL_R_ETIMEOUT) {
153 _DBG("Launch pwlock is failed for AUL_R_ETIMEOUT, again launch pwlock-lite");
154 r = aul_launch_app(PWLOCK_LITE_PKG_NAME, NULL);
156 _ERR("2'nd PWLock launch error: error(%d)", r);
159 _DBG("Launch pwlock-lite");
166 _DBG("Launch pwlock-lite");
170 r = aul_launch_app(PWLOCK_LITE_PKG_NAME, NULL);
172 _ERR("PWLock launch error: error(%d)", r);
173 if (r == AUL_R_ETIMEOUT) {
174 _DBG("Launch pwlock is failed for AUL_R_ETIMEOUT, again launch pwlock");
175 r = aul_launch_app(PWLOCK_LITE_PKG_NAME, NULL);
177 _ERR("2'nd PWLock launch error: error(%d)", r);
180 _DBG("Launch pwlock");
187 _DBG("Launch pwlock");
193 r = aul_launch_app("com.samsung.pwlock", NULL);
195 _ERR("PWLock launch error: error(%d)", r);
196 if (r == AUL_R_ETIMEOUT) {
198 _DBG("Launching pwlock is failed [%d]times for AUL_R_ETIMEOUT ", i);
204 _DBG("Launch pwlock");
210 static void _signal_handler(int signum, siginfo_t *info, void *unused)
212 _DBG("_signal_handler : Terminated...");
217 static void _heynoti_event_power_off(void *data)
219 _DBG("_heynoti_event_power_off : Terminated...");
224 static void _poweroff_control_cb(keynode_t *in_key, void *data)
227 if (vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val) == 0 &&
228 (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART)) {
229 _DBG("_poweroff_control_cb : Terminated...");
234 #define APP_ID_SPLIT_LAUNCHER "com.samsung.split-launcher"
235 static Eina_Bool _fini_boot(void *data)
237 _DBG("%s %d\n", __func__, __LINE__);
239 int multiwindow_enabled = 0;
242 if (vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 1) != 0) {
243 _ERR("Failed to set boot animation finished set");
246 if (vconf_get_bool(VCONFKEY_QUICKSETTING_MULTIWINDOW_ENABLED, &multiwindow_enabled) < 0) {
247 _ERR("Cannot get VCONFKEY");
248 multiwindow_enabled = 0;
251 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &val) < 0) {
252 _DBG("Cannot get VCONFKEY");
256 if ((val == 1) || (multiwindow_enabled == 0)) {
257 _DBG("TTS : %d, Multiwindow enabled : %d", val, multiwindow_enabled);
258 return ECORE_CALLBACK_CANCEL;
261 _DBG("Launch the split-launcher");
263 int ret = aul_launch_app(APP_ID_SPLIT_LAUNCHER, NULL);
264 if (0 > ret) _ERR("cannot launch the split-launcher (%d)", ret);
266 return ECORE_CALLBACK_CANCEL;
270 static Eina_Bool _init_idle(void *data)
272 _DBG("%s %d\n", __func__, __LINE__);
274 if ((pwlock_pid = _launch_pwlock()) < 0) {
275 _ERR("launch pwlock error");
278 lockd_process_mgr_set_pwlock_priority(pwlock_pid);
281 return ECORE_CALLBACK_CANCEL;
284 static void _lock_state_cb(keynode_t * node, void *data)
286 _DBG("%s %d\n", __func__, __LINE__);
288 if (_launch_pwlock() < 0) {
289 _ERR("launch pwlock error");
291 menu_daemon_init(NULL);
295 if (vconf_ignore_key_changed(VCONFKEY_IDLE_LOCK_STATE,
296 _lock_state_cb) != 0) {
297 LOCKD_DBG("Fail to unregister");
301 static Eina_Bool _init_lock_lite(void *data)
306 _DBG("%s %d\n", __func__, __LINE__);
308 /* Check SD card encription */
309 file = vconf_get_str(VCONFKEY_SDE_CRYPTO_STATE);
310 if (file && !strncmp(SD_DATA_ENCRYPTED, file, strlen(file)) && _check_encrypt_sdcard() == 0) {
311 _ERR("SD card is encripted");
312 if (start_lock_daemon_lite(FALSE, FALSE) == 1) {
313 if ((pwlock_pid = _launch_pwlock()) < 0) {
314 _ERR("launch pwlock error");
317 lockd_process_mgr_set_pwlock_priority(pwlock_pid);
319 ecore_timer_add(0.5, _fini_boot, NULL);
324 if (start_lock_daemon_lite(TRUE, FALSE) == 1) {
325 if ((pwlock_pid = _launch_pwlock()) < 0) {
326 _ERR("launch pwlock error");
329 lockd_process_mgr_set_pwlock_priority(pwlock_pid);
331 if (vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE,
332 _lock_state_cb, NULL) != 0) {
333 _ERR("[Error] vconf notify : lock state");
334 ecore_timer_add(0.5, _fini_boot, NULL);
341 return ECORE_CALLBACK_CANCEL;
344 static Eina_Bool _init_lock(void *data)
348 _DBG("%s %d\n", __func__, __LINE__);
350 /* Check SD card encription */
351 file = vconf_get_str(VCONFKEY_SDE_CRYPTO_STATE);
352 if (file && !strncmp(SD_DATA_ENCRYPTED, file, strlen(file)) && _check_encrypt_sdcard() == 0) {
353 _ERR("SD card is encripted");
354 if (start_lock_daemon(FALSE, FALSE) == 1) {
355 if (_launch_pwlock() < 0) {
356 _ERR("launch pwlock error");
358 ecore_timer_add(0.5, _fini_boot, NULL);
363 if (start_lock_daemon(TRUE, FALSE) == 1) {
364 if (_launch_pwlock() < 0) {
365 _ERR("launch pwlock error");
367 if (vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE,
368 _lock_state_cb, NULL) != 0) {
369 _ERR("[Error] vconf notify : lock state");
370 ecore_timer_add(0.5, _fini_boot, NULL);
377 return ECORE_CALLBACK_CANCEL;
380 static void _data_encryption_cb(keynode_t * node, void *data)
384 _DBG("%s %d\n", __func__, __LINE__);
386 file = vconf_get_str(VCONFKEY_ODE_CRYPTO_STATE);
388 _DBG("get VCONFKEY : %s\n", file);
389 if (!strcmp(file, DATA_MOUNTED)) {
391 start_lock_daemon_lite(FALSE, FALSE);
393 start_lock_daemon(FALSE, FALSE);
395 menu_daemon_init(NULL);
401 static Eina_Bool _start_sequence_cb(void *data)
403 _DBG("%s, %d", __func__, __LINE__);
405 unlock_menu_screen();
407 return ECORE_CALLBACK_CANCEL;
410 static void _init(struct appdata *ad)
413 struct sigaction act;
418 memset(&act,0x00,sizeof(struct sigaction));
419 act.sa_sigaction = _signal_handler;
420 act.sa_flags = SA_SIGINFO;
422 int ret = sigemptyset(&act.sa_mask);
424 _ERR("Failed to sigemptyset[%s]", strerror(errno));
426 ret = sigaddset(&act.sa_mask, SIGTERM);
428 _ERR("Failed to sigaddset[%s]", strerror(errno));
430 ret = sigaction(SIGTERM, &act, NULL);
432 _ERR("Failed to sigaction[%s]", strerror(errno));
435 memset(ad, 0, sizeof(struct appdata));
437 gettimeofday(&ad->tv_start, NULL);
439 /* if (bincfg_is_factory_binary() == 1) {
440 _DBG("Factory binary..!!");
442 unlock_menu_screen();
443 menu_daemon_init(NULL);
445 */ _DBG("%s %d\n", __func__, __LINE__);
449 /* Check data encrption */
450 file = vconf_get_str(VCONFKEY_ODE_CRYPTO_STATE);
452 _DBG("get VCONFKEY : %s\n", file);
453 if (strncmp(DATA_UNENCRYPTED, file, strlen(file))) {
454 if (vconf_notify_key_changed(VCONFKEY_ODE_CRYPTO_STATE,
455 _data_encryption_cb, NULL) != 0) {
456 _ERR("[Error] vconf notify changed is failed: %s", VCONFKEY_ODE_CRYPTO_STATE);
458 _DBG("waiting mount..!!");
459 if ((pwlock_pid = _launch_pwlock()) < 0) {
460 _ERR("launch pwlock error");
463 lockd_process_mgr_set_pwlock_priority(pwlock_pid);
473 r = start_lock_daemon(TRUE);
475 if (vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE,
476 _lock_state_cb, NULL) != 0) {
477 _ERR("[Error] vconf notify : lock state");
478 ecore_timer_add(1.5, _init_idle, NULL);
481 if (_launch_pwlock() < 0) {
482 _ERR("launch pwlock error");
484 menu_daemon_init(NULL);
488 r = vconf_get_bool(VCONFKEY_PWLOCK_FIRST_BOOT, &first);
489 _ERR("vconf get First boot result:%d, get_value:%d", r, first);
490 if (r == 0 && first == 0){
491 _DBG("Not first booting time");
494 _DBG("Not First home");
495 unlock_menu_screen();
496 menu_daemon_init(NULL);
498 _init_lock_lite(NULL);
505 _init_lock_lite(NULL);
509 menu_daemon_init(NULL);
510 ecore_idler_add(_start_sequence_cb, NULL);
513 _ERR("First booting time");
514 menu_daemon_init(NULL);
516 r = start_lock_daemon_lite(TRUE, TRUE);
518 r = start_lock_daemon(TRUE, TRUE);
520 _DBG("start_lock_daemon ret:%d", r);
521 if ((pwlock_pid = _launch_pwlock()) < 0) {
522 _ERR("launch pwlock error");
523 if (vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 1) != 0) {
524 _ERR("Failed to set boot animation finished set");
526 unlock_menu_screen();
528 lockd_process_mgr_set_pwlock_priority(pwlock_pid);
529 ecore_timer_add(1, _fini_boot, NULL);
536 static void _fini(struct appdata *ad)
538 struct timeval tv, res;
541 fprintf(stderr, "Invalid argument: appdata is NULL\n");
545 unlock_menu_screen();
548 gettimeofday(&tv, NULL);
549 timersub(&tv, &ad->tv_start, &res);
550 _DBG("Total time: %d.%06d sec\n", (int)res.tv_sec, (int)res.tv_usec);
553 int main(int argc, char *argv[])
557 _DBG("starter is launched..!!");
559 set_window_scale(); /* not in loop */
563 int heyfd = heynoti_init();
565 _ERR("Failed to heynoti_init[%d]", heyfd);
569 int ret = heynoti_subscribe(heyfd, "power_off_start", _heynoti_event_power_off, NULL);
571 _ERR("Failed to heynoti_subscribe[%d]", ret);
573 ret = heynoti_attach_handler(heyfd);
575 _ERR("Failed to heynoti_attach_handler[%d]", ret);
578 if (vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, (void *)_poweroff_control_cb, NULL) < 0) {
579 _ERR("Vconf notify key chaneged failed: VCONFKEY_SYSMAN_POWER_OFF_STATUS");
583 elm_init(argc, argv);