Set the vconfkey as the default menu-screen/lock-screen when the app is not launched...
authorJin Yoon <jinny.yoon@samsung.com>
Mon, 22 Apr 2013 08:15:24 +0000 (17:15 +0900)
committerJin Yoon <jinny.yoon@samsung.com>
Mon, 22 Apr 2013 08:15:24 +0000 (17:15 +0900)
Change-Id: I8647124a2a18a82a47f01d909076e4029b6ef97b

CMakeLists.txt
debian/control
include/hw_key.h
include/menu_daemon.h
include/util.h
include/xmonitor.h
packaging/starter.spec
src/hw_key.c
src/lockd-process-mgr.c
src/menu_daemon.c

index fec3928..d563331 100755 (executable)
@@ -40,6 +40,7 @@ pkg_check_modules(pkgs REQUIRED
        bundle
        capi-appfw-application
        capi-system-info
+       pkgmgr-info
 )
 
 FOREACH(flag ${pkgs_CFLAGS})
index d62b6d2..557f975 100755 (executable)
@@ -2,7 +2,7 @@ Source: starter
 Section: devel
 Priority: extra
 Maintainer: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com>
-Build-Depends: debhelper (>= 5), libappcore-efl-dev, libglib2.0-dev, libslp-tapi-dev, libslp-setting-dev, libheynoti-dev, libaul-1-dev, libx11-dev, libelm-dev, libefreet-dev, dlog-dev, libecore-dev, libsvi-dev, libslp-utilx-dev, libail-0-dev, libui-gadget-dev, libslp-sysman-dev
+Build-Depends: debhelper (>= 5), libappcore-efl-dev, libglib2.0-dev, libslp-tapi-dev, libslp-setting-dev, libheynoti-dev, libaul-1-dev, libx11-dev, libelm-dev, libefreet-dev, dlog-dev, libecore-dev, libsvi-dev, libslp-utilx-dev, libail-0-dev, libui-gadget-dev, libslp-sysman-dev, pkgmgr-info-dev
 Standards-Version: 3.7.2
 
 Package: starter
index a55d78b..ffde950 100755 (executable)
@@ -18,3 +18,5 @@
 
 extern void destroy_key_window(void);
 extern void create_key_window(void);
+
+// End of a file
index 80d6939..994ff82 100755 (executable)
 
 
 
+#include <bundle.h>
 #include <sys/types.h>
 #include <stdbool.h>
 
 extern void menu_daemon_init(void *data);
 extern void menu_daemon_fini(void);
 
+extern int menu_daemon_open_app(const char *pkgname);
+extern int menu_daemon_launch_app(const char *pkgname, bundle *b);
+
 extern bool menu_daemon_is_homescreen(pid_t pid);
 
 extern int menu_daemon_check_dead_signal(int pid);
+
+extern char *menu_daemon_get_selected_pkgname(void);
+extern void menu_daemon_open_homescreen(const char *pkgname);
+
+// End of a file
index 92640ff..63262ac 100755 (executable)
@@ -19,6 +19,8 @@
 #ifndef __MENU_DAEMON_UTIL_H__
 #define __MENU_DAEMON_UTIL_H__
 #include <dlog.h>
+#include <stdio.h>
+#include <sys/time.h>
 
 #define HOME_SCREEN_PKG_NAME "org.tizen.menu-screen"
 #define CONF_PATH_NUMBER 1024
@@ -28,6 +30,7 @@
 #define LOG_TAG "starter"
 #endif
 
+/* Log */
 #if !defined(_W)
 #define _W(fmt, arg...) LOGW("[%s:%d] "fmt"\n", __func__, __LINE__, ##arg)
 #endif
        } \
 }
 
-#endif
+#define PRINT_TIME(str) do { \
+       struct timeval tv; \
+       gettimeofday(&tv, NULL); \
+       _D("[%s:%d] %s TIME=%u.%u", __func__, __LINE__, str, (int)tv.tv_sec, (int)tv.tv_usec); \
+} while (0)
+
+#define _F(fmt, arg...) do {            \
+       FILE *fp;\
+       fp = fopen("/var/log/starter.log", "a+");\
+       if (NULL == fp) break;\
+    fprintf(fp, "[%s:%d] "fmt"\n", __func__, __LINE__, ##arg); \
+       fclose(fp);\
+} while (0)
+
+
+
+#endif /* __MENU_DAEMON_UTIL_H__ */
index d1693b1..85ae907 100755 (executable)
@@ -22,4 +22,4 @@
 extern int xmonitor_init(void);
 extern void xmonitor_fini(void);
 
-#endif
+#endif /* __MENU_DAEMON_XMONITOR_H__ */
index 4695844..1f41a80 100644 (file)
@@ -1,6 +1,6 @@
 Name:       starter
 Summary:    starter
-Version: 0.4.60
+Version: 0.4.61
 Release:    3
 Group:      TO_BE/FILLED_IN
 License:    TO_BE/FILLED_IN
@@ -34,6 +34,7 @@ BuildRequires:  pkgconfig(x11)
 BuildRequires:  pkgconfig(xcomposite)
 BuildRequires:  pkgconfig(xext)
 BuildRequires:  pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(pkgmgr-info)
 BuildRequires:  cmake
 BuildRequires:  edje-bin
 BuildRequires: gettext-tools
index 9d9093d..7435107 100755 (executable)
@@ -17,7 +17,6 @@
 
 
 #include <ail.h>
-#include <aul.h>
 #include <bundle.h>
 #include <Elementary.h>
 #include <Ecore_X.h>
@@ -29,6 +28,7 @@
 #include <system/media_key.h>
 
 #include "hw_key.h"
+#include "menu_daemon.h"
 #include "util.h"
 
 #define TASKMGR_PKG_NAME "org.tizen.taskmgr"
@@ -79,7 +79,7 @@ static Eina_Bool _launch_taskmgr_cb(void* data)
 
        if ((val1 == VCONFKEY_PM_STATE_NORMAL) && (val2 == VCONFKEY_IDLE_UNLOCK)) {
                _D("LCD ON, UNLOCK state => launch taskmgr");
-               if (aul_open_app(TASKMGR_PKG_NAME) < 0)
+               if (menu_daemon_open_app(TASKMGR_PKG_NAME) < 0)
                        _E("Failed to launch the taskmgr");
        } else {
                _D("Can't launch TASKMGR pm state : %d lock state : %d", val1, val2);
@@ -90,42 +90,11 @@ static Eina_Bool _launch_taskmgr_cb(void* data)
 
 
 
-static Eina_Bool _launch_home_screen(void *data)
+static Eina_Bool _launch_by_home_key(void *data)
 {
-       char *package;
-       int ret;
-
-       syspopup_destroy_all();
        key_info.single_timer = NULL;
-
-       package = vconf_get_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME);
-       if (package) {
-               ret = aul_open_app(package);
-               if (ret < 0) {
-                       _E("cannot launch package %s(err:%d)", package, ret);
-
-                       if (-1 == ret) {
-                               ret = aul_open_app(HOME_SCREEN_PKG_NAME);
-                               if (ret < 0) {
-                                       _E("Failed to open a default home, %s(err:%d)", HOME_SCREEN_PKG_NAME, ret);
-                               }
-                       }
-               }
-
-               free(package);
-       } else {
-               ret = aul_open_app(HOME_SCREEN_PKG_NAME);
-               if (ret < 0) _E("Cannot open default home");
-       }
-
-       if (ret > 0) {
-               if (-1 == sysconf_set_mempolicy_bypid(ret, OOM_IGNORE)) {
-                       _E("Cannot set the memory policy for Home-screen(%d)", ret);
-               } else {
-                       _E("Set the memory policy for Home-screen(%d)", ret);
-               }
-       }
-
+       syspopup_destroy_all();
+       menu_daemon_open_homescreen(NULL);
        return ECORE_CALLBACK_CANCEL;
 }
 
@@ -138,7 +107,7 @@ inline static int _release_home_key(void)
        key_info.long_press = NULL;
 
        if (NULL == key_info.single_timer) {
-               key_info.single_timer = ecore_timer_add(0.3, _launch_home_screen, NULL);
+               key_info.single_timer = ecore_timer_add(0.3, _launch_by_home_key, NULL);
                return EXIT_SUCCESS;
        }
        ecore_timer_del(key_info.single_timer);
@@ -153,24 +122,24 @@ inline static int _release_home_key(void)
 
 inline static void _release_multimedia_key(const char *value)
 {
-       bundle *b;
-       int ret;
+       ret_if(NULL == value);
 
        _D("Multimedia key is released with %s", value);
-       ret_if(NULL == value);
 
+       bundle *b;
        b = bundle_create();
        if (!b) {
                _E("Cannot create bundle");
                return;
        }
-
        bundle_add(b, "multimedia_key", value);
-       ret = aul_launch_app(MUSIC_PLAYER_PKG_NAME, b);
-       bundle_free(b);
 
+       int ret;
+       ret = menu_daemon_launch_app(MUSIC_PLAYER_PKG_NAME, b);
        if (ret < 0)
                _E("Failed to launch the running apps, ret : %d", ret);
+
+       bundle_free(b);
 }
 
 
@@ -243,11 +212,11 @@ static Eina_Bool _key_press_cb(void *data, int type, void *event)
 
        if (!strcmp(ev->keyname, KEY_SEND)) {
                _D("Launch calllog");
-               if (aul_open_app(CALLLOG_PKG_NAME) < 0)
+               if (menu_daemon_open_app(CALLLOG_PKG_NAME) < 0)
                        _E("Failed to launch %s", CALLLOG_PKG_NAME);
        } else if(!strcmp(ev->keyname, KEY_CONFIG)) {
                _D("Launch camera");
-               if (aul_open_app(CAMERA_PKG_NAME) < 0)
+               if (menu_daemon_open_app(CAMERA_PKG_NAME) < 0)
                        _E("Failed to launch %s", CAMERA_PKG_NAME);
        } else if (!strcmp(ev->keyname, KEY_HOME)) {
                if (vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &val) < 0) {
@@ -262,7 +231,7 @@ static Eina_Bool _key_press_cb(void *data, int type, void *event)
                        key_info.long_press = NULL;
                }
 
-               key_info.long_press = ecore_timer_add(0.6, _launch_taskmgr_cb, NULL);
+               key_info.long_press = ecore_timer_add(0.5, _launch_taskmgr_cb, NULL);
                if (!key_info.long_press)
                        _E("Failed to add timer for long press detection");
        } else if (!strcmp(ev->keyname, KEY_CANCEL)) {
@@ -345,3 +314,7 @@ void destroy_key_window(void)
 
        media_key_release();
 }
+
+
+
+// End of a file
index d606566..aab2797 100755 (executable)
@@ -65,6 +65,7 @@ int lockd_process_mgr_start_lock(void *data, int (*dead_cb) (int, void *),
 {
        char *lock_app_path = NULL;
        int pid;
+       int ret;
 
        lock_app_path = _lockd_process_mgr_get_pkgname();
 
@@ -80,6 +81,10 @@ int lockd_process_mgr_start_lock(void *data, int (*dead_cb) (int, void *),
                        usleep(RELAUNCH_INTERVAL);
                } else if (pid == AUL_R_ERROR) {
                        LOCKD_DBG("launch[%s] is failed, launch default lock screen", lock_app_path);
+                       ret = vconf_set_str(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, LOCKD_DEFAULT_LOCKSCREEN);
+                       if (ret != 0) {
+                               LOCKD_ERR("set failed");
+                       }
                        pid = aul_launch_app(LOCKD_DEFAULT_LOCKSCREEN, NULL);
                        if (pid >0) {
                                return pid;
index 5697eb4..b400b5e 100755 (executable)
 #include <aul.h>
 #include <db-util.h>
 #include <Elementary.h>
+#include <errno.h>
 #include <fcntl.h>
+#include <pkgmgr-info.h>
 #include <stdio.h>
 #include <sysman.h>
 #include <syspopup_caller.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <unistd.h>
 #include <vconf.h>
-#include <errno.h>
 
 #include "hw_key.h"
 #include "pkg_event.h"
@@ -55,6 +57,45 @@ static struct info {
 
 
 
+#define RETRY_COUNT 5
+int menu_daemon_open_app(const char *pkgname)
+{
+       register int i;
+       int r = AUL_R_ETIMEOUT;
+       for (i = 0; AUL_R_ETIMEOUT == r && i < RETRY_COUNT; i ++) {
+               r = aul_open_app(pkgname);
+               if (0 <= r) return r;
+               else {
+                       _D("aul_open_app error(%d)", r);
+                       _F("cannot open an app(%s) by %d", pkgname, r);
+               }
+               usleep(500000);
+       }
+
+       return r;
+}
+
+
+
+int menu_daemon_launch_app(const char *pkgname, bundle *b)
+{
+       register int i;
+       int r = AUL_R_ETIMEOUT;
+       for (i = 0; AUL_R_ETIMEOUT == r && i < RETRY_COUNT; i ++) {
+               r = aul_launch_app(pkgname, b);
+               if (0 <= r) return r;
+               else {
+                       _D("aul_launch_app error(%d)", r);
+                       _F("cannot launch an app(%s) by %d", pkgname, r);
+               }
+               usleep(500000);
+       }
+
+       return r;
+}
+
+
+
 bool menu_daemon_is_homescreen(pid_t pid)
 {
        if (s_info.home_pid == pid) return true;
@@ -63,53 +104,84 @@ bool menu_daemon_is_homescreen(pid_t pid)
 
 
 
-static inline char *_get_selected_pkgname(void)
+inline char *menu_daemon_get_selected_pkgname(void)
 {
-       char *pkgname;
+       char *pkgname = NULL;
 
        pkgname = vconf_get_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME);
-       if (!pkgname) {
-               _E("Cannot get pkgname from vconf.");
+       retv_if(NULL == pkgname, NULL);
 
-               pkgname = strdup(HOME_SCREEN_PKG_NAME);
-               if (!pkgname) {
-                       _E("strdup error for pkgname, %s", strerror(errno));
-                       return NULL;
-               }
+       return pkgname;
+}
+
+
+
+static bool _exist_package(char *pkgid)
+{
+       int ret = 0;
+       pkgmgrinfo_pkginfo_h handle = NULL;
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+       if (PMINFO_R_OK != ret || NULL == handle) {
+               _D("%s doesn't exist in this binary", pkgid);
+               return false;
        }
 
-       return pkgname;
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+       return true;
 }
 
 
 
-static inline void _open_homescreen(const char *pkgname)
+inline void menu_daemon_open_homescreen(const char *pkgname)
 {
-       int ret;
-       char *homescreen = (char *) pkgname;
+       char *homescreen = NULL;
+       char *tmp = NULL;
 
        system("echo -e '[${_G}menu-daemon launches home-screen${C_}]' > /dev/kmsg");
-       ret = aul_open_app(homescreen);
+
+       if (NULL == pkgname) {
+               tmp = menu_daemon_get_selected_pkgname();
+               ret_if(NULL == tmp);
+               homescreen = tmp;
+       } else {
+               homescreen = (char *) pkgname;
+       }
+
+       syspopup_destroy_all();
+
+       int ret;
+       ret = menu_daemon_open_app(homescreen);
        _D("can%s launch %s now. (%d)", ret < 0 ? "not" : "", homescreen, ret);
-       if (ret < 0 && strcmp(homescreen, HOME_SCREEN_PKG_NAME)) {
+       if (ret < 0 && strcmp(homescreen, HOME_SCREEN_PKG_NAME) && _exist_package(HOME_SCREEN_PKG_NAME)) {
                _E("cannot launch package %s", homescreen);
 
-               if (-1 == ret) {
-                       ret = aul_open_app(HOME_SCREEN_PKG_NAME);
-                       if (ret < 0) {
-                               _E("Failed to open a default home, %s(err:%d)", HOME_SCREEN_PKG_NAME, ret);
-                       }
+               if (0 != vconf_set_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, HOME_SCREEN_PKG_NAME)) {
+                       _E("Cannot set value(%s) into key(%s)", VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, HOME_SCREEN_PKG_NAME);
+               }
+
+               while (AUL_R_ETIMEOUT == ret) {
+                       _E("Failed to open a default home, %s", HOME_SCREEN_PKG_NAME);
+                       ret = menu_daemon_open_app(HOME_SCREEN_PKG_NAME);
                }
        }
 
+       if (ret < 0) {
+               _E("Critical! Starter cannot launch anymore[%d]", ret);
+               _F("Critical! Starter cannot launch anymore[%d]", ret);
+       }
+
        s_info.home_pid = ret;
        if (ret > 0) {
                if (-1 == sysconf_set_mempolicy_bypid(ret, OOM_IGNORE)) {
                        _E("Cannot set the memory policy for Home-screen(%d)", ret);
                } else {
-                       _E("Set the memory policy for Home-screen(%d)", ret);
+                       _D("Set the memory policy for Home-screen(%d)", ret);
                }
        }
+
+       if (tmp) free(tmp);
 }
 
 
@@ -117,20 +189,14 @@ static inline void _open_homescreen(const char *pkgname)
 static void _show_cb(keynode_t* node, void *data)
 {
        int seq;
-       char *pkgname;
 
        _D("[MENU_DAEMON] _show_cb is invoked");
 
-       pkgname = _get_selected_pkgname();
-       if (!pkgname)
-               return;
-
        if (node) {
                seq = vconf_keynode_get_int(node);
        } else {
                if (vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &seq) < 0) {
                        _E("Failed to get sequence info");
-                       free(pkgname);
                        return;
                }
        }
@@ -140,7 +206,6 @@ static void _show_cb(keynode_t* node, void *data)
                        if (s_info.home_pid > 0) {
                                int pid;
                                _D("pid[%d] is terminated.", s_info.home_pid);
-
                                pid = s_info.home_pid;
                                s_info.home_pid = -1;
 
@@ -149,16 +214,14 @@ static void _show_cb(keynode_t* node, void *data)
                        }
                        break;
                case 1:
-                       _open_homescreen(pkgname);
+                       menu_daemon_open_homescreen(NULL);
                        break;
                default:
                        _E("False sequence [%d]", seq);
                        break;
        }
 
-       free(pkgname);
        return;
-
 }
 
 
@@ -180,7 +243,7 @@ static void _pkg_changed(keynode_t* node, void *data)
 
        _D("_pkg_changed is invoked");
 
-       pkgname = _get_selected_pkgname();
+       pkgname = menu_daemon_get_selected_pkgname();
        if (!pkgname)
                return;
 
@@ -197,16 +260,19 @@ static void _pkg_changed(keynode_t* node, void *data)
                        }
                }
 
-               if (aul_terminate_pid(s_info.home_pid) != AUL_R_OK)
+               if (AUL_R_OK != aul_terminate_pid(s_info.home_pid))
                        _D("Failed to terminate pid %d", s_info.home_pid);
        } else {
-               _open_homescreen(pkgname);
+               /* If there is no running home */
+               menu_daemon_open_homescreen(pkgname);
        }
 
        free(pkgname);
        return;
 }
 
+
+
 static void _launch_volume(void)
 {
        int pid;
@@ -231,8 +297,6 @@ static void _launch_volume(void)
 
 int menu_daemon_check_dead_signal(int pid)
 {
-       char *pkgname;
-
        if (s_info.power_off) {
                _D("Power off. ignore dead cb\n");
                return 0;
@@ -243,13 +307,14 @@ int menu_daemon_check_dead_signal(int pid)
        if (pid < 0)
                return 0;
 
-       pkgname = _get_selected_pkgname();
-       if (!pkgname)
-               return 0;
-
        if (pid == s_info.home_pid) {
+               char *pkgname = NULL;
+               pkgname = menu_daemon_get_selected_pkgname();
+               retv_if(NULL == pkgname, 0);
+
                _D("pkg_name : %s", pkgname);
-               _open_homescreen(pkgname);
+               menu_daemon_open_homescreen(pkgname);
+               free(pkgname);
        } else if (pid == s_info.volume_pid) {
                _launch_volume();
        } else {
@@ -257,7 +322,6 @@ int menu_daemon_check_dead_signal(int pid)
                                pid, s_info.home_pid);
        }
 
-       free(pkgname);
 
        return 0;
 }
@@ -280,10 +344,10 @@ void menu_daemon_init(void *data)
                _E("cannot remove sat-ui desktop.");
 
        if (vconf_notify_key_changed(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, _pkg_changed, NULL) < 0)
-               _E("Failed to add callback for package change event");
+               _E("Failed to add the callback for package change event");
 
        if (vconf_notify_key_changed(VCONFKEY_STARTER_SEQUENCE, _show_cb, NULL) < 0)
-               _E("Failed to add callback for show event");
+               _E("Failed to add the callback for show event");
 
        _pkg_changed(NULL, NULL);
        vconf_set_int(VCONFKEY_IDLE_SCREEN_LAUNCHED, VCONFKEY_IDLE_SCREEN_LAUNCHED_TRUE);
@@ -293,10 +357,17 @@ void menu_daemon_init(void *data)
 
 void menu_daemon_fini(void)
 {
-       vconf_ignore_key_changed(VCONFKEY_STARTER_SEQUENCE, _show_cb);
-       vconf_ignore_key_changed(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, _pkg_changed);
+       if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, _pkg_changed) < 0)
+               _E("Failed to ignore the callback for package change event");
+
+       if (vconf_ignore_key_changed(VCONFKEY_STARTER_SEQUENCE, _show_cb) < 0)
+               _E("Failed to ignore the callback for show event");
 
        xmonitor_fini();
        pkg_event_fini();
        destroy_key_window();
 }
+
+
+
+// End of a file