Add feature LAZY_LOADER for wrt-loader 18/64118/2 accepted/tizen/common/20160406.144159 accepted/tizen/ivi/20160406.071941 accepted/tizen/mobile/20160406.071838 accepted/tizen/tv/20160406.071857 accepted/tizen/wearable/20160406.071919 submit/tizen/20160406.013051
authorJunghoon Park <jh9216.park@samsung.com>
Wed, 6 Apr 2016 01:13:04 +0000 (10:13 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Wed, 6 Apr 2016 01:13:04 +0000 (10:13 +0900)
 - wrt-loader should be prepared after the first launch of a web app

Change-Id: I55bfb2aac4c67d9c417088cfd534af55bffb8730
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
CMakeLists.txt
packaging/launchpad.spec
src/launchpad.c

index f3d80ba..d5fbc44 100755 (executable)
@@ -62,6 +62,9 @@ ADD_DEFINITIONS("-DSHARE_PREFIX=\"/usr/share/aul\"")
 IF(_APPFW_FEATURE_PRIORITY_CHANGE)
        ADD_DEFINITIONS("-D_APPFW_FEATURE_PRIORITY_CHANGE")
 ENDIF(_APPFW_FEATURE_PRIORITY_CHANGE)
+IF(_APPFW_FEATURE_LAZY_LOADER)
+       ADD_DEFINITIONS("-D_APPFW_FEATURE_LAZY_LOADER")
+ENDIF(_APPFW_FEATURE_LAZY_LOADER)
 
 ADD_DEFINITIONS("-DLAUNCHPAD_LOG")
 ADD_DEFINITIONS("-DPRELOAD_ACTIVATE")
index eb358ab..bfaec96 100644 (file)
@@ -28,6 +28,11 @@ Requires(postun): /usr/bin/systemctl
 Requires(preun): /usr/bin/systemctl
 
 %define appfw_feature_priority_change 0
+%if "%{?profile}" == "tv"
+%define appfw_feature_lazy_loader 0
+%else
+%define appfw_feature_lazy_loader 1
+%endif
 
 %description
 Launchpad for launching applications
@@ -52,9 +57,13 @@ export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
 %if 0%{?appfw_feature_priority_change}
 _APPFW_FEATURE_PRIORITY_CHANGE=ON
 %endif
+%if 0%{?appfw_feature_lazy_loader}
+_APPFW_FEATURE_LAZY_LOADER=ON
+%endif
 
 %cmake -DVERSION=%{version} \
        -D_APPFW_FEATURE_PRIORITY_CHANGE:BOOL=${_APPFW_FEATURE_PRIORITY_CHANGE} \
+       -D_APPFW_FEATURE_LAZY_LOADER:BOOL=${_APPFW_FEATURE_LAZY_LOADER} \
        .
 %__make %{?_smp_mflags}
 
index 25ff8a6..148c2a8 100755 (executable)
@@ -62,6 +62,7 @@ typedef struct {
        guint timer;
        char *loader_path;
        char *loader_extra;
+       bool enabled;
 } candidate_process_context_t;
 
 typedef struct {
@@ -72,7 +73,8 @@ typedef struct {
 
 static GList *candidate_slot_list;
 static int sys_hwacc = -1;
-static candidate_process_context_t* __add_slot(int type, int loader_id, int caller_pid, const char *loader_path, const char *extra);
+static candidate_process_context_t* __add_slot(int type, int loader_id, int caller_pid, const char *loader_path,
+               const char *extra, bool enabled);
 static int __remove_slot(int type, int loader_id);
 static int __add_default_slots();
 
@@ -384,6 +386,9 @@ static int __prepare_candidate_process(int type, int loader_id)
        if (cpt == NULL)
                return -1;
 
+       if (!cpt->enabled)
+               return -1;
+
        memset(argbuf, ' ', LOADER_ARG_LEN);
        argbuf[LOADER_ARG_LEN-1] = '\0';
        argv[4] = argbuf;
@@ -549,7 +554,7 @@ static int __prepare_exec(const char *appId, const char *app_path,
 }
 
 static int __launch_directly(const char *appid, const char *app_path, int clifd,
-                               bundle* kb, appinfo_t *menu_info)
+                               bundle* kb, appinfo_t *menu_info, candidate_process_context_t *cpc)
 {
        char sock_path[PATH_MAX];
        int pid = fork();
@@ -588,6 +593,13 @@ static int __launch_directly(const char *appid, const char *app_path, int clifd,
        }
        SECURE_LOGD("==> real launch pid : %d %s\n", pid, app_path);
 
+#ifdef _APPFW_FEATURE_LAZY_LOADER
+       if (cpc && !cpc->enabled) {
+               cpc->enabled = true;
+               cpc->timer = g_timeout_add(5000, __handle_preparing_candidate_process, cpc);
+       }
+#endif
+
        return pid;
 }
 
@@ -851,7 +863,7 @@ static int __dispatch_cmd_add_loader(bundle *kb)
 
        if (add_slot_str && caller_pid) {
                lid = __make_loader_id();
-               candidate_process_context_t *cpc = __add_slot(LAUNCHPAD_TYPE_DYNAMIC, lid, atoi(caller_pid), add_slot_str, extra);
+               candidate_process_context_t *cpc = __add_slot(LAUNCHPAD_TYPE_DYNAMIC, lid, atoi(caller_pid), add_slot_str, extra, true);
                if (cpc)
                        cpc->timer = g_timeout_add(2000, __handle_preparing_candidate_process, cpc);
 
@@ -1010,7 +1022,7 @@ static gboolean __handle_launch_event(gpointer data)
        if (loader_id == PAD_LOADER_ID_DIRECT ||
                (cpc = __find_slot(type, loader_id)) == NULL) {
                _W("Launch directly");
-               pid = __launch_directly(menu_info->appid, app_path, clifd, kb, menu_info);
+               pid = __launch_directly(menu_info->appid, app_path, clifd, kb, menu_info, NULL);
        } else {
                if (cpc->prepared) {
                        _W("Launch %d type process", type);
@@ -1022,11 +1034,11 @@ static gboolean __handle_launch_event(gpointer data)
                                        pid = __send_launchpad_loader(cpc, pkt, app_path, clifd, menu_info->comp_type);
                                } else {
                                        _W("Launch directly");
-                                       pid = __launch_directly(menu_info->appid, app_path, clifd, kb, menu_info);
+                                       pid = __launch_directly(menu_info->appid, app_path, clifd, kb, menu_info, NULL);
                                }
                } else {
                        _W("Launch directly");
-                       pid = __launch_directly(menu_info->appid, app_path, clifd, kb, menu_info);
+                       pid = __launch_directly(menu_info->appid, app_path, clifd, kb, menu_info, cpc);
                }
        }
 
@@ -1052,7 +1064,8 @@ end:
        return G_SOURCE_CONTINUE;
 }
 
-static candidate_process_context_t* __add_slot(int type, int loader_id, int caller_pid, const char *loader_path, const char *loader_extra)
+static candidate_process_context_t* __add_slot(int type, int loader_id, int caller_pid, const char *loader_path,
+               const char *loader_extra, bool enabled)
 {
        candidate_process_context_t *cpc;
        int fd = -1;
@@ -1075,6 +1088,7 @@ static candidate_process_context_t* __add_slot(int type, int loader_id, int call
        cpc->timer = 0;
        cpc->loader_path = strdup(loader_path);
        cpc->loader_extra = loader_extra ? strdup(loader_extra) : NULL;
+       cpc->enabled = enabled;
 
        fd = __listen_candidate_process(cpc->type, cpc->loader_id);
        if (fd == -1) {
@@ -1164,30 +1178,35 @@ static int __init_sigchild_fd(void)
 
 static int __add_default_slots()
 {
-       if (__add_slot(LAUNCHPAD_TYPE_COMMON, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_DEFAULT, NULL) == NULL)
+       if (__add_slot(LAUNCHPAD_TYPE_COMMON, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_DEFAULT, NULL, true) == NULL)
                return -1;
        if (__prepare_candidate_process(LAUNCHPAD_TYPE_COMMON, PAD_LOADER_ID_STATIC) != 0)
                return -1;
 
-       if (__add_slot(LAUNCHPAD_TYPE_SW, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_DEFAULT, NULL) == NULL)
+       if (__add_slot(LAUNCHPAD_TYPE_SW, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_DEFAULT, NULL, true) == NULL)
                return -1;
        if (__prepare_candidate_process(LAUNCHPAD_TYPE_SW, PAD_LOADER_ID_STATIC) != 0)
                return -1;
 
-       if (__add_slot(LAUNCHPAD_TYPE_HW, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_DEFAULT, NULL) == NULL)
+       if (__add_slot(LAUNCHPAD_TYPE_HW, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_DEFAULT, NULL, true) == NULL)
                return -1;
        if (__prepare_candidate_process(LAUNCHPAD_TYPE_HW, PAD_LOADER_ID_STATIC) != 0)
                return -1;
 
        if (access(LOADER_PATH_WRT, F_OK | X_OK) == 0) {
-               if (__add_slot(LAUNCHPAD_TYPE_WRT, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_WRT, NULL) == NULL)
+#ifdef _APPFW_FEATURE_LAZY_LOADER
+               if (__add_slot(LAUNCHPAD_TYPE_WRT, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_WRT, NULL, false) == NULL)
+                       return -1;
+#else
+               if (__add_slot(LAUNCHPAD_TYPE_WRT, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_WRT, NULL, true) == NULL)
                        return -1;
                if (__prepare_candidate_process(LAUNCHPAD_TYPE_WRT, PAD_LOADER_ID_STATIC) != 0)
                        return -1;
+#endif
        }
 
        if (access(LOADER_PATH_JS_NATIVE, F_OK | X_OK) == 0) {
-               if (__add_slot(LAUNCHPAD_TYPE_JS_NATIVE, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_JS_NATIVE, NULL) == NULL)
+               if (__add_slot(LAUNCHPAD_TYPE_JS_NATIVE, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_JS_NATIVE, NULL, true) == NULL)
                        return -1;
                if (__prepare_candidate_process(LAUNCHPAD_TYPE_JS_NATIVE, PAD_LOADER_ID_STATIC) != 0)
                        return -1;