Removing dependency of ode package.
[apps/native/starter.git] / src / mobile / starter.c
old mode 100644 (file)
new mode 100755 (executable)
index 7c09b1c..2ff0ea8
 #include <fcntl.h>
 #include <unistd.h>
 #include <string.h>
+#include <malloc.h>
+#include <Ecore_Wl2.h>
+
+#include <E_DBus.h>
+#include <systemd/sd-daemon.h>
+//#include <ode/internal-encryption.h>
 
 #include <aul.h>
 #include <vconf.h>
 #include <signal.h>
 
 #include "starter.h"
-//#include "lock_mgr.h"
+#include "lock_mgr.h"
 #include "home_mgr.h"
 #include "hw_key.h"
 #include "process_mgr.h"
 #include "util.h"
 #include "status.h"
+#include "hw_key.h"
+#include "dbus_util.h"
 
-#define PWLOCK_LITE_PKG_NAME "org.tizen.pwlock-lite"
-
-#define DATA_UNENCRYPTED "unencrypted"
-#define DATA_MOUNTED "mounted"
-#define SD_DATA_ENCRYPTED "encrypted"
-#define SD_CRYPT_META_FILE ".MetaEcfsFile"
-#define MMC_MOUNT_POINT        "/opt/storage/sdcard"
-
-
-
-static void _hide_home(void)
-{
-       vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 0);
-}
-
-
-
-static void _show_home(void)
-{
-       int show_menu = 0;
-
-       if (status_active_get()->starter_sequence || !show_menu) {
-               vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 1);
-       }
-}
-
-
-
-static Eina_Bool _finish_boot_animation(void *data)
-{
-       if (vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 1) != 0) {
-               _E("Failed to set boot animation finished set");
-       }
-       _show_home();
-
-       return ECORE_CALLBACK_CANCEL;
-}
-
-
-
-static int _fail_to_launch_pwlock(const char *appid, const char *key, const char *value, void *cfn, void *afn)
-{
-       _finish_boot_animation(NULL);
-       return 0;
-}
-
-
-
-static void _after_launch_pwlock(int pid)
+static void _set_starter_sequence(int val)
 {
-       process_mgr_set_pwlock_priority(pid);
-       ecore_timer_add(0.5, _finish_boot_animation, NULL);
+       vconf_set_int(VCONFKEY_STARTER_SEQUENCE, val);
 }
 
 
 
 static void _signal_handler(int signum, siginfo_t *info, void *unused)
 {
-    _D("_signal_handler : Terminated...");
-    elm_exit();
+       _D("_signal_handler : Terminated...");
+       elm_exit();
 }
 
 
@@ -103,9 +62,7 @@ static int _power_off_cb(status_active_key_e key, void *data)
 {
        int val = status_active_get()->sysman_power_off_status;
 
-       if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT
-               || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART)
-       {
+       if (val > VCONFKEY_SYSMAN_POWER_OFF_NONE) {
            _D("_power_off_cb : Terminated...");
            elm_exit();
        }
@@ -115,24 +72,19 @@ static int _power_off_cb(status_active_key_e key, void *data)
 
 
 
-#if 0
-static void _data_encryption_cb(keynode_t * node, void *data)
+static void _language_changed_cb(keynode_t *node, void *data)
 {
-       char *file = NULL;
+       char *lang = NULL;
 
-       file = vconf_get_str(VCONFKEY_ODE_CRYPTO_STATE);
-       if (!file) {
-               return;
-       }
+       ret_if(!node);
 
-       _D("get the value : %s",  file);
-       if (!strcmp(file, DATA_MOUNTED)) {
-               lock_mgr_daemon_start();
-               home_mgr_init(NULL);
-       }
-       free(file);
+       lang = vconf_keynode_get_str(node);
+       ret_if(!lang);
+
+       _D("language is changed : %s", lang);
+
+       elm_language_set(lang);
 }
-#endif
 
 
 
@@ -164,31 +116,116 @@ static int _set_i18n(const char *domain, const char *dir)
                _E("textdomain() error");
        }
 
+       if (vconf_notify_key_changed(VCONFKEY_LANGSET, _language_changed_cb, NULL) < 0) {
+               _E("Failed to register changed cb : %s", VCONFKEY_LANGSET);
+       }
+
        return 0;
 }
 
 
 
-static void _init(struct appdata *ad)
+static int _check_dead_signal(int pid, void *data)
+{
+       int home_pid = 0;
+       int volume_pid = 0;
+       int indicator_pid = 0;
+       int quickpanel_pid = 0;
+       int taskbar_pid = 0;
+       int lock_pid = 0;
+
+       _D("Process %d is termianted", pid);
+
+       if (pid < 0) {
+               _E("pid : %d", pid);
+               return 0;
+       }
+
+       /*
+        * starter try to re-launch these apps when the app is dead.
+        */
+       home_pid = home_mgr_get_home_pid();
+       volume_pid = home_mgr_get_volume_pid();
+       indicator_pid = home_mgr_get_indicator_pid();
+       quickpanel_pid = home_mgr_get_quickpanel_pid();
+       taskbar_pid = home_mgr_get_taskbar_pid();
+       lock_pid = lock_mgr_get_lock_pid();
+
+       if (pid == home_pid) {
+               _D("Homescreen is dead");
+               home_mgr_relaunch_homescreen();
+       } else if (pid == volume_pid) {
+               _D("volume is dead");
+               home_mgr_relaunch_volume();
+       } else if (pid == indicator_pid) {
+               _D("indicator is dead");
+               home_mgr_relaunch_indicator();
+       } else if (pid == quickpanel_pid) {
+               _D("quickpanel is dead");
+               home_mgr_relaunch_quickpanel();
+       } else if (pid == taskbar_pid) {
+               _D("taskbar is dead");
+               home_mgr_relaunch_taskbar();
+       } else if (pid == lock_pid) {
+               _D("lockscreen is dead");
+               lock_mgr_unlock();
+       } else {
+               _D("Unknown process, ignore it");
+       }
+
+       return 0;
+}
+
+
+
+static void _launch_apps(void)
+{
+       /* Tells the service manager that service startup is finished */
+       sd_notify(0, "READY=1");
+
+       /*
+        * After user data partition mount,
+        * launch lockscreen, homescreen, etc.
+        */
+       lock_mgr_init();
+       home_mgr_init(NULL);
+
+       /*
+        * Set the starter sequence vconfkey.
+        * '1' menas that booting seqeunce is done.
+        */
+       _set_starter_sequence(1);
+}
+
+
+
+static void _init(void)
 {
        struct sigaction act;
-       char *file = NULL;
+       char err_buf[128] = { 0, };
+       int ret = 0;
 
-       memset(&act,0x00,sizeof(struct sigaction));
+       memset(&act, 0x00, sizeof(struct sigaction));
        act.sa_sigaction = _signal_handler;
        act.sa_flags = SA_SIGINFO;
 
-       int ret = sigemptyset(&act.sa_mask);
+       ret = sigemptyset(&act.sa_mask);
        if (ret < 0) {
-               _E("Failed to sigemptyset[%s]", strerror(errno));
+               if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
+                       _E("Failed to sigemptyset[%d / %s]", errno, err_buf);
+               }
        }
        ret = sigaddset(&act.sa_mask, SIGTERM);
        if (ret < 0) {
-               _E("Failed to sigaddset[%s]", strerror(errno));
+               if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
+                       _E("Failed to sigaddset[%d / %s]", errno, err_buf);
+               }
        }
        ret = sigaction(SIGTERM, &act, NULL);
        if (ret < 0) {
-               _E("Failed to sigaction[%s]", strerror(errno));
+               if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
+                       _E("Failed to sigaction[%d / %s]", errno, err_buf);
+               }
        }
 
        _set_i18n(PACKAGE, LOCALEDIR);
@@ -196,60 +233,142 @@ static void _init(struct appdata *ad)
        status_register();
        status_active_register_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb, NULL);
 
-       /* Ordering : _hide_home -> process_mgr_must_launch(pwlock) -> _show_home */
-       _hide_home();
-       process_mgr_must_launch(PWLOCK_LITE_PKG_NAME, NULL, NULL, _fail_to_launch_pwlock, _after_launch_pwlock);
-
-#if 0
-       /* Check data encrption */
-       file = vconf_get_str(VCONFKEY_ODE_CRYPTO_STATE);
-       if (file) {
-               _D("get VCONFKEY : %s\n",  file);
-               if (strncmp(DATA_UNENCRYPTED, file, strlen(file))) {
-                       if (vconf_notify_key_changed(VCONFKEY_ODE_CRYPTO_STATE, _data_encryption_cb, NULL) != 0) {
-                               _E("[Error] vconf notify changed is failed: %s", VCONFKEY_ODE_CRYPTO_STATE);
-                       } else {
-                               _D("waiting mount..!!");
-                               free(file);
-                               return;
-                       }
-               }
-               free(file);
-       }
-#endif
+       e_dbus_init();
 
-       //lock_mgr_daemon_start();
        hw_key_create_window();
-       home_mgr_init(NULL);
+
+       /*
+        * Initialize starter sequence vconfkey.
+        */
+       _set_starter_sequence(0);
+
+       // ret = starter_execute_ode_process(BEFORE_LOCKSCREEN);
+       // if (!ret) {
+               // _E("Failed to execute ode process");
+       // }
+
+       aul_listen_app_dead_signal(_check_dead_signal, NULL);
 }
 
 
 
-static void _fini(struct appdata *ad)
+static void _fini(void)
 {
        home_mgr_fini();
+       lock_mgr_fini();
+
        hw_key_destroy_window();
-       //lock_mgr_daemon_end();
+
+       e_dbus_shutdown();
 
        status_active_unregister_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb);
        status_unregister();
+
+       if (vconf_ignore_key_changed(VCONFKEY_LANGSET, _language_changed_cb) < 0) {
+               _E("Failed to unregister changed cb : %s", VCONFKEY_LANGSET);
+       }
 }
 
 
 
 int main(int argc, char *argv[])
 {
-       struct appdata ad;
+       int ret = 0;
+       Ecore_Wl2_Display *display = NULL;
+       struct wl_display *displ = NULL;
 
        _D("starter is launched..!!");
 
-       elm_init(argc, argv);
-       _init(&ad);
+       ret = elm_init(argc, argv);
+       if (!ret) {
+               _E("elm_init() failed : %d", ret);
+               return -1;
+       }
+
+       ret = ecore_wl2_init();
+       if (!ret) {
+               _E("ecore_wl2_init() failed : %d", ret);
+               elm_shutdown();
+               return -1;
+       }
 
+       displ = ecore_wl2_display_get(NULL);
+       if (!displ) {
+               _W("There's no display");
+               display = ecore_wl2_display_connect(NULL);
+               if (!display) {
+                       _E("Failed to connect display");
+                       return -1;
+               }
+       }
+
+       _init();
+
+       malloc_trim(0);
        elm_run();
 
-       _fini(&ad);
+       _fini();
+
+       if (display) {
+               ecore_wl2_display_disconnect(display);
+               ecore_wl2_shutdown();
+       }
+
        elm_shutdown();
 
        return 0;
 }
+
+
+
+static void _mount_complete_cb(void *user_data)
+{
+       _D("Mount is successfully completed");
+}
+
+
+
+// int starter_execute_ode_process(int booting_state)
+// {
+       // _D("This call is before or after Lockscreen: %d", booting_state);
+       // int ret = ODE_ERROR_NONE;
+       // int ode_state = 0;
+
+       // ret = ode_internal_encryption_get_state(&ode_state);
+       // if (ret != ODE_ERROR_NONE) {
+               // _E("Failed to get ODE state, ret: %d", ret);
+               // return 0;
+       // }
+
+       // if (booting_state == BEFORE_LOCKSCREEN) {
+               // if (ode_state == ODE_STATE_ENCRYPTED) {
+                       // lock_mgr_init();
+
+                       // ret = ode_internal_encryption_set_mount_event_cb(_mount_complete_cb, NULL);
+                       // if (ret != ODE_ERROR_NONE) {
+                               // _E("Failed to set mount event cb");
+                       // }
+               // } else {
+                       // _launch_apps();
+               // }
+       // } else if (booting_state == AFTER_LOCKSCREEN) {
+               // if (ode_state == ODE_STATE_ENCRYPTED) {
+                       // _D("ODE state is: %d, and we should mount at this time", ode_state);
+
+                       // ret = ode_internal_encryption_mount();
+                       // if (ret != ODE_ERROR_NONE) {
+                               // _E("Failed to mount");
+                               // return 0;
+                       // }
+
+                       // sd_notify(0, "READY=1");
+                       // home_mgr_init(NULL);
+
+                       // vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 1);
+               // } else {
+                       // _D("ODE state is: %d, Do nothing", ode_state);
+               // }
+       // }
+
+       // return 1;
+// }