[FEATURE] web app support 41/15541/1
authorNikita Kalyazin <n.kalyazin@samsung.com>
Wed, 22 Jan 2014 14:16:41 +0000 (18:16 +0400)
committerNikita Kalyazin <n.kalyazin@samsung.com>
Thu, 23 Jan 2014 05:58:01 +0000 (09:58 +0400)
Naive implementation of launch/kill web app (type 4).

Change-Id: Id047a329199b15a7992b94e59d0cbcbc3d7c4e0b
Signed-off-by: Nikita Kalyazin <n.kalyazin@samsung.com>
daemon/da_protocol.c
daemon/da_protocol.h
daemon/da_protocol_check.c
daemon/da_protocol_check.h
daemon/da_protocol_inst.c
daemon/daemon.c
daemon/utils.c
daemon/utils.h

index f850101..08c6479 100644 (file)
@@ -686,10 +686,25 @@ void stop_all_done(void)
        pthread_mutex_unlock(&stop_all_mutex);
 }
 
+static void stop_web_apps(void)
+{
+       const struct app_info_t *app_info;
+       struct app_list_t *app = NULL;
+
+       app_info = app_info_get_first(&app);
+       while (app_info) {
+               if (app_info->app_type == APP_TYPE_WEB)
+                       kill_app_web(app_info->app_id);
+               app_info = app_info_get_next(&app);
+       }
+}
+
 enum ErrorCode stop_all(void)
 {
        enum ErrorCode error_code = ERR_NO;
 
+       stop_web_apps();
+
        pthread_mutex_lock(&stop_all_mutex);
        error_code = stop_all_no_lock();
        pthread_mutex_unlock(&stop_all_mutex);
index ead76d1..86a245b 100644 (file)
@@ -195,6 +195,7 @@ enum app_type_t {
        APP_TYPE_TIZEN = 1,
        APP_TYPE_RUNNING = 2,
        APP_TYPE_COMMON = 3,
+       APP_TYPE_WEB = 4
 };
 
 struct app_info_t {
index 34ff3d3..d4076c4 100644 (file)
@@ -62,6 +62,9 @@ int check_app_id(uint32_t app_type, char *app_id)
                        if (!res)
                                LOGE("wrong app id for APP_COMMON\n");
                        break;
+               case APP_TYPE_WEB:
+                       res = 1;
+                       break;
                default :
                        LOGE("wrong app type\n");
                        return 0;
index b019413..76c952e 100644 (file)
@@ -30,7 +30,7 @@
 
 // Max values defines
 #define APP_INFO_TYPE_MIN 0x0001
-#define APP_INFO_TYPE_MAX 0x0003
+#define APP_INFO_TYPE_MAX 0x0004
 
 #define CONF_SYSTRACE_PERIOD_MIN 10
 #define CONF_SYSTRACE_PERIOD_MAX 1000
index f2586a6..d555b59 100644 (file)
@@ -217,7 +217,8 @@ int parse_inst_app(struct msg_buf_t *msg, struct app_list_t **dest)
                return 0;
        }
        if (!parse_string(msg, &app_info->exe_path) ||
-               !check_exec_path(app_info->exe_path))
+           ((app_info->app_type != APP_TYPE_WEB) &&
+            !check_exec_path(app_info->exe_path)))
        {
                LOGE("exec path parsing error\n");
                return 0;
index f84feb2..52990b4 100644 (file)
@@ -214,6 +214,9 @@ static int kill_app_by_info(const struct app_info_t *app_info)
        case APP_TYPE_COMMON:
                res = kill_app(app_info->exe_path);
                break;
+       case APP_TYPE_WEB:
+               /* do nothing (it is restarted by itself */
+               break;
        default:
                LOGE("Unknown app type %d\n", app_info->app_type);
                res = -1;
@@ -253,6 +256,12 @@ static int exec_app(const struct app_info_t *app_info)
                        inc_apps_to_run();
                }
                break;
+       case APP_TYPE_WEB:
+               if (exec_app_web(app_info->app_id)) {
+                       LOGE("Cannot exec web app %s\n", app_info->app_id);
+                       res = -1;
+               }
+               break;
        default:
                LOGE("Unknown app type %d\n", app_info->app_type);
                res = -1;
index f635b23..9e71b3b 100644 (file)
@@ -190,6 +190,66 @@ int exec_app_common(const char* exec_path)
        }
 }
 
+int exec_app_web(const char *app_id)
+{
+       pid_t pid;
+
+       LOGI("wrt-launcher path is %s,\n"
+            "wrt-launcher name (%s), app_id (%s)\n",
+            WRT_LAUNCHER_PATH, WRT_LAUNCHER_NAME, app_id);
+
+       pid = fork();
+       if (pid == -1)
+               return -1;
+
+       if (pid > 0) { /* parent */
+               int status, ret;
+               do
+                       ret = waitpid(pid, &status, 0);
+               while (ret == -1 && errno == EINTR);
+               return 0;
+       } else { /* child */
+               execl(WRT_LAUNCHER_PATH,
+                     WRT_LAUNCHER_NAME,
+                     WRT_LAUNCHER_LAUNCH,
+                     app_id,
+                     NULL);
+               /* FIXME: If code flows here, it deserves greater attention */
+               LOGE("Cannot run exec!\n");
+               _Exit(EXIT_FAILURE);
+       }
+}
+
+void kill_app_web(const char *app_id)
+{
+       pid_t pid;
+
+       LOGI("wrt-launcher path is %s,\n"
+            "wrt-launcher name (%s), app_id (%s)\n",
+            WRT_LAUNCHER_PATH, WRT_LAUNCHER_NAME, app_id);
+
+       pid = fork();
+       if (pid == -1)
+               return;
+
+       if (pid > 0) { /* parent */
+               int status, ret;
+               do
+                       ret = waitpid(pid, &status, 0);
+               while (ret == -1 && errno == EINTR);
+               return;
+       } else { /* child */
+               execl(WRT_LAUNCHER_PATH,
+                     WRT_LAUNCHER_NAME,
+                     WRT_LAUNCHER_KILL,
+                     app_id,
+                     NULL);
+               /* FIXME: If code flows here, it deserves greater attention */
+               LOGE("Cannot run exec!\n");
+               _Exit(EXIT_FAILURE);
+       }
+}
+
 // find process id from executable binary path
 pid_t find_pid_from_path(const char* path)
 {
index 585c4d3..bc12874 100644 (file)
@@ -42,6 +42,10 @@ extern "C" {
 #define LAUNCH_APP_PATH                        "/usr/bin/launch_app"
 #define KILL_APP_PATH                  "/usr/bin/pkill"
 #define LAUNCH_APP_NAME                        "launch_app"
+#define        WRT_LAUNCHER_PATH               "/usr/bin/wrt-launcher"
+#define        WRT_LAUNCHER_NAME               "wrt-launcher"
+#define        WRT_LAUNCHER_LAUNCH             "-s"
+#define        WRT_LAUNCHER_KILL               "-k"
 #define LAUNCH_APP_SDK                 "__AUL_SDK__"
 #define DA_PRELOAD_EXEC                        "DYNAMIC_ANALYSIS"
 #define DA_PRELOAD(AppType)            AppType ? DA_PRELOAD_OSP : DA_PRELOAD_TIZEN
@@ -72,6 +76,8 @@ int is_same_app_process(char* appPath, int pid);
 
 int exec_app_tizen(const char *app_id, const char *exec_path);
 int exec_app_common(const char* exec_path);
+int exec_app_web(const char *app_id);
+void kill_app_web(const char *app_id);
 char *dereference_tizen_exe_path(const char *path, char *resolved);
 void fd_setup_smack_attributes(int fd);
 float get_uptime(void);