Tizen 2.4 SDK Rev6 Release accepted/tizen_2.4_mobile tizen_2.4 accepted/tizen/2.4/mobile/20160530.220353 submit/tizen_2.4/20160530.023155
authorJaekyu Park <jk7744.park@samsung.com>
Fri, 27 May 2016 07:54:48 +0000 (16:54 +0900)
committerJaekyu Park <jk7744.park@samsung.com>
Fri, 27 May 2016 07:54:48 +0000 (16:54 +0900)
12 files changed:
CMakeLists.txt
am_daemon/amd_app_group.c
am_daemon/amd_app_group.h
am_daemon/amd_launch.c
am_daemon/amd_main.c
am_daemon/amd_request.c
am_daemon/amd_request.h
am_daemon/amd_status.c
am_daemon/amd_status.h
include/aul.h
packaging/aul.spec
src/app_signal.c

index 9bff6df..3f803ac 100755 (executable)
@@ -138,6 +138,9 @@ ENDIF(_APPFW_FEATURE_EFFECTIVE_APPID)
 IF(_APPFW_FEATURE_PRIVATE_SERVICE)
        ADD_DEFINITIONS("-D_APPFW_FEATURE_PRIVATE_SERVICE")
 ENDIF(_APPFW_FEATURE_PRIVATE_SERVICE)
+IF(_APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP)
+       ADD_DEFINITIONS("-D_APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP")
+ENDIF(_APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP)
 
 # Linker flags
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
index fb7fb76..da71af3 100644 (file)
@@ -142,7 +142,7 @@ static void __prepare_to_wake_services(int pid)
        __app_send_raw_with_noreply(pid, APP_WAKE, (unsigned char *)&dummy, sizeof(int));
 }
 
-static void __set_fg_flag(int cpid, int flag)
+static void __set_fg_flag(int cpid, int flag, gboolean force)
 {
        int lpid = app_group_get_leader_pid(cpid);
        GHashTableIter iter;
@@ -159,7 +159,7 @@ static void __set_fg_flag(int cpid, int flag)
                        while (i != NULL) {
                                ac = (app_group_context_t*) i->data;
 
-                               if (ac->fg != flag) {
+                               if (ac->fg != flag || force == TRUE) {
                                        const char *appid = NULL;
                                        const char *pkgid = NULL;
                                        const struct appinfo *ai = NULL;
@@ -393,7 +393,7 @@ static void __group_remove(int pid)
                        GINT_TO_POINTER(pid));
 
        if (ppid != -1) {
-               app_group_set_status(ppid, -1);
+               app_group_set_status(ppid, -1, FALSE);
        }
 }
 
@@ -825,7 +825,7 @@ int app_group_get_status(int pid)
        return -1;
 }
 
-int app_group_set_status(int pid, int status)
+int app_group_set_status(int pid, int status, gboolean force)
 {
        GHashTableIter iter;
        gpointer key, value;
@@ -844,9 +844,9 @@ int app_group_set_status(int pid, int status)
                                GList *last = g_list_last(list);
                                app_group_context_t *last_ac = (app_group_context_t*) last->data;
 
-                               if (last_ac->wid != 0 || status == STATUS_VISIBLE) {
+                               if (last_ac->wid != 0 || status == STATUS_VISIBLE || force == TRUE) {
                                        if (__is_visible(pid)) {
-                                               __set_fg_flag(pid, 1);
+                                               __set_fg_flag(pid, 1, force);
                                                if (!ac->group_sig && (int)key != pid) {
                                                        char *appid = NULL;
                                                        const char *pkgid = NULL;
@@ -861,7 +861,7 @@ int app_group_set_status(int pid, int status)
                                                        ac->group_sig = 1;
                                                }
                                        } else
-                                               __set_fg_flag(pid, 0);
+                                               __set_fg_flag(pid, 0, force);
                                }
                                return 0;
                        }
@@ -940,6 +940,7 @@ int app_group_find_second_leader(int lpid)
                if (list != NULL) {
                        app_group_context_t *ac = (app_group_context_t*) list->data;
                        if (ac->can_be_leader) {
+                               _W("found the second leader, lpid: %d, pid: %d", lpid, ac->pid);
                                return ac->pid;
                        }
                }
@@ -1252,3 +1253,32 @@ void app_group_get_idle_pids(int *cnt, int **pids)
        *pids = idle_pids;
 }
 
+int app_group_get_next_caller_pid(int pid)
+{
+       GHashTableIter iter;
+       gpointer key, value;
+
+       g_hash_table_iter_init(&iter, app_group_hash);
+       while (g_hash_table_iter_next(&iter, &key, &value)) {
+               GList *list = (GList*) value;
+               GList *i = g_list_first(list);
+
+               while (i != NULL) {
+                       app_group_context_t *ac = (app_group_context_t*) i->data;
+
+                       if (ac->pid == pid) {
+                               i = g_list_next(i);
+                               if (i == NULL)
+                                       return -1;
+
+                               ac = (app_group_context_t*) i->data;
+                               return ac->caller_pid;
+                       }
+                       i = g_list_next(i);
+               }
+       }
+
+       return -1;
+}
+
+
index 19629ca..9d23295 100644 (file)
@@ -26,7 +26,7 @@ void app_group_clear_top(int pid);
 int app_group_get_leader_pid(int pid);
 void app_group_set_dead_pid(int pid);
 int app_group_get_status(int pid);
-int app_group_set_status(int pid, int status);
+int app_group_set_status(int pid, int status, gboolean force);
 int app_group_get_fg_flag(int pid);
 int app_group_set_hint(int pid, bundle *kb);
 int app_group_find_second_leader(int lpid);
@@ -40,5 +40,6 @@ void app_group_restart_app(int pid, bundle *b);
 int app_group_find_pid_from_recycle_bin(const char *appid);
 void app_group_get_idle_pids(int *cnt, int **pids);
 void app_group_remove_from_recycle_bin(int pid);
+int app_group_get_next_caller_pid(int pid);
 #endif
 
index 6e78add..756d8bb 100755 (executable)
 #define HIDE_INDICATOR 0
 #define SHOW_INDICATOR 1
 
-#define PROC_STATUS_FG 3
-#define PROC_STATUS_BG 4
+#define PROC_STATUS_LAUNCH 0
+#define PROC_STATUS_FG 3
+#define PROC_STATUS_BG 4
 #ifdef _APPFW_FEATURE_CPU_BOOST
 #define APP_BOOSTING_PERIOD 1500 //msec
 #endif
@@ -125,6 +126,12 @@ DBusConnection *conn;
 guint grab_timer_id;
 #endif
 
+static GList *_fgmgr_list;
+
+struct fgmgr {
+       guint tid;
+       int pid;
+};
 
 #if 0
 /*Unused data structure. Will be removed*/
@@ -319,7 +326,7 @@ static void _do_exec(const char *cmd, const char *group, bundle *kb)
        g_strfreev(argv);
 }
 
-static inline int __send_app_launch_signal(int launch_pid)
+static inline int __send_app_launch_signal(int launch_pid, const char *app_id)
 {
        DBusMessage *message;
 
@@ -331,8 +338,9 @@ static inline int __send_app_launch_signal(int launch_pid)
                                          AUL_DBUS_APPLAUNCH_SIGNAL);
 
        if (dbus_message_append_args(message,
-                                    DBUS_TYPE_UINT32, &launch_pid,
-                                    DBUS_TYPE_INVALID) == FALSE) {
+                               DBUS_TYPE_UINT32, &launch_pid,
+                               DBUS_TYPE_STRING, &app_id,
+                               DBUS_TYPE_INVALID) == FALSE) {
                _E("Failed to load data error");
                return -1;
        }
@@ -345,7 +353,7 @@ static inline int __send_app_launch_signal(int launch_pid)
        dbus_connection_flush(conn);
        dbus_message_unref(message);
 
-       _W("send launch signal done: %d", launch_pid);
+       _W("send launch signal done: %d, %s", launch_pid, app_id);
 
        return 0;
 }
@@ -472,7 +480,7 @@ static int __check_cmdline(int ret)
        return ret;
 }
 
-int start_process(const char *group, const char *cmd, bundle *kb)
+int start_process(const char *appid, const char *cmd, bundle *kb)
 {
        int r;
        pid_t p;
@@ -490,7 +498,7 @@ int start_process(const char *group, const char *cmd, bundle *kb)
                                        getpid(), errno, strerror(errno));
                }
 #endif
-               _do_exec(cmd, group, kb);
+               _do_exec(cmd, appid, kb);
                /* exec error */
 
                exit(0);
@@ -503,7 +511,7 @@ int start_process(const char *group, const char *cmd, bundle *kb)
                _W("child process: %d", p);
                r = __check_cmdline(p);
                if(r > 0)
-                       __send_app_launch_signal(r);
+                       __send_app_launch_signal(r, appid);
                else
                        _E("cmdline change failed.");
                break;
@@ -768,10 +776,9 @@ int _pause_app(int pid, int clifd)
                        ret = -1;
                }
        }
-       _D("pause done\n");
 
-       if (ret > 0)
-               __set_reply_handler(ret, pid, clifd, APP_PAUSE_BY_PID);
+       _D("pause done\n");
+       close(clifd);
 
        return ret;
 }
@@ -998,7 +1005,6 @@ static void __set_reply_handler(int fd, int pid, int clifd, int cmd)
        r_info->gpollfd = gpollfd;
        r_info->cmd = cmd;
 
-
        r_info->timer_id = g_timeout_add(5000, __recv_timeout_handler, (gpointer) r_info);
        g_source_add_poll(src, gpollfd);
        g_source_set_callback(src, (GSourceFunc) __reply_handler,
@@ -1013,7 +1019,17 @@ void _term_sub_app(int pid)
 {
        int dummy;
        int ret;
+       char *appid = NULL;
+       const char *pkgid = NULL;
+       const char *type = NULL;
+       const struct appinfo *ai = NULL;
+
+       appid = _status_app_get_appid_bypid(pid);
+       ai = appinfo_find(_laf, appid);
+       pkgid = appinfo_get_value(ai, AIT_PKGID);
+       type = appinfo_get_value(ai, AIT_COMPTYPE);
 
+       aul_send_app_terminate_request_signal(pid, appid, pkgid, type);
        if ( (ret = __app_send_raw_with_noreply(pid, APP_TERM_BY_PID_ASYNC,
                                        (unsigned char *)&dummy, sizeof(int))) < 0) {
                _E("terminate packet send error - use SIGKILL");
@@ -1294,17 +1310,20 @@ static void __amd_effect_image_file_set(char *image_file)
 
        root_win = ecore_x_window_root_first_get();
        SECURE_LOGD("path : %s", image_file);
-       ecore_x_window_prop_string_set(root_win, ATOM_IMAGE_EFFECT,image_file);
+       ecore_x_window_prop_string_set(root_win, ATOM_IMAGE_EFFECT, image_file);
 }
 
 
 static void __amd_send_message_to_e17(int screenmode, const char * indicator, int effect_type, int theme)
 {
+       traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:AMD:EFFECT_START");
        Ecore_X_Window root_win;
        int ret;
 
-       if(!_window_is_initialized())
+       if (!_window_is_initialized()) {
+               traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
                return;
+       }
 
        root_win = ecore_x_window_root_first_get();
         _D("root win : %x",root_win);
@@ -1312,7 +1331,7 @@ static void __amd_send_message_to_e17(int screenmode, const char * indicator, in
        if (screenmode > 4 || screenmode < 0)
                screenmode=0;
 
-       if (strncmp(indicator, "true", 4) == 0){
+       if (strncmp(indicator, "true", 4) == 0) {
                _D("[LAUNCHING EFFECT]: screen mode(%d), effect type(%d), theme(%d), indicator show",
                        screen_orientation[screenmode], effect_type, theme);
                ret = ecore_x_client_message32_send (root_win, ATOM_IMAGE_EFFECT,
@@ -1320,7 +1339,7 @@ static void __amd_send_message_to_e17(int screenmode, const char * indicator, in
                        screen_orientation[screenmode],
                        SHOW_INDICATOR, theme, 0);
 
-       }else{
+       } else {
                _D("[LAUNCHING EFFECT]: screen mode(%d), effect type(%d), theme(%d), indicator show",
                        screen_orientation[screenmode], effect_type, theme);
                ret = ecore_x_client_message32_send (root_win, ATOM_IMAGE_EFFECT,
@@ -1330,6 +1349,7 @@ static void __amd_send_message_to_e17(int screenmode, const char * indicator, in
        }
        ecore_x_flush();
        _D("ecore_x_client_message32_send : %d",ret);
+       traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
 }
 #endif
 
@@ -1433,6 +1453,54 @@ static gboolean __grab_timeout_handler(gpointer data)
 }
 #endif
 
+static gboolean __fg_timeout_handler(gpointer data)
+{
+       struct fgmgr *fg = data;
+
+       if (!fg)
+               return FALSE;
+
+       _status_update_app_info_list(fg->pid, STATUS_BG, TRUE);
+
+       _fgmgr_list = g_list_remove(_fgmgr_list, fg);
+       free(fg);
+
+       return FALSE;
+}
+
+static void __add_fgmgr_list(int pid)
+{
+       struct fgmgr *fg;
+
+       fg = calloc(1, sizeof(struct fgmgr));
+       if (!fg)
+               return;
+
+       fg->pid = pid;
+       fg->tid = g_timeout_add(5000, __fg_timeout_handler, fg);
+
+       _fgmgr_list = g_list_append(_fgmgr_list, fg);
+}
+
+static void __del_fgmgr_list(int pid)
+{
+       GList *iter = NULL;
+       struct fgmgr *fg;
+
+       if (pid < 0)
+               return;
+
+       for (iter = _fgmgr_list; iter != NULL; iter = g_list_next(iter)) {
+               fg = (struct fgmgr *)iter->data;
+               if (fg->pid == pid) {
+                       g_source_remove(fg->tid);
+                       _fgmgr_list = g_list_remove(_fgmgr_list, fg);
+                       free(fg);
+                       return;
+               }
+       }
+}
+
 #ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
 static int __tep_mount(char *mnt_path[])
 {
@@ -1542,7 +1610,7 @@ static int __check_app_control_privilege(const char *operation, int caller_pid,
                if (api_ver && strverscmp("2.4", api_ver) < 1) { // ver 2.4 or later
                        ret = security_server_check_privilege_by_pid(caller_pid, "privilege::tizen::download", "rw");
                        if (ret != SECURITY_SERVER_API_SUCCESS) {
-                               _E("caller %d violates http://tizen.org/privilege/download privilege", caller_pid);
+                               _E("caller %d violates http://tizen.org/privilege/download privilege (%d)", caller_pid, ret);
                                return -EILLEGALACCESS;
                        }
                }
@@ -1550,7 +1618,7 @@ static int __check_app_control_privilege(const char *operation, int caller_pid,
                // Check the privilege for call operation
                ret = security_server_check_privilege_by_pid(caller_pid, "privilege::tizen::call", "rw");
                if (ret != SECURITY_SERVER_API_SUCCESS) {
-                       _E("caller %d violates http://tizen.org/privilege/call privilege", caller_pid);
+                       _E("caller %d violates http://tizen.org/privilege/call privilege (%d)", caller_pid, ret);
                        return -EILLEGALACCESS;
                }
        }
@@ -2003,6 +2071,55 @@ static void __add_shared_info(int pid, const char *caller_exec_label, const char
        _status_add_shared_info(pid, caller_exec_label, paths);
 }
 
+#ifdef _APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP
+#ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
+static void __check_home_app(int pid)
+{
+       const char *home_app = _get_home_appid();
+       const char *appid = NULL;
+
+       if (home_app == NULL)
+               return;
+
+       appid = _status_app_get_appid_bypid(pid);
+
+       if (appid && strcmp(appid, home_app) == 0) {
+               int cnt = 0;
+               int *pids = NULL;
+               int i;
+               const char *taskmanage = NULL;
+               const struct appinfo *ai = NULL;
+               const char* bg = NULL;
+
+               app_group_get_leader_pids(&cnt, &pids);
+               if (pids) {
+                       for (i = 0; i < cnt; ++i) {
+                               appid = _status_app_get_appid_bypid(pids[i]);
+                               if (appid == NULL || strcmp(appid, home_app) == 0)
+                                       continue;
+
+                               ai = appinfo_find(_laf, appid);
+                               taskmanage = appinfo_get_value(ai, AIT_TASKMANAGE);
+                               bg = appinfo_get_value(ai, AIT_ALLOWED_BG);
+
+                               if (taskmanage && strcmp("false", taskmanage) == 0
+                                       && bg && strcmp("NONE", bg) == 0) {
+                                       int st = _status_get_app_info_status(pids[i]);
+                                       if (st != STATUS_DYING) {
+                                               _W("terminate %d %s %d", pids[i], appid, st);
+                                               aul_update_freezer_status(pids[i], "wakeup");
+                                               _term_sub_app(pids[i]);
+                                       }
+                               }
+                       }
+
+                       free(pids);
+               }
+       }
+}
+#endif
+#endif
+
 int _revoke_temporary_permission(int pid)
 {
        GList *list = _status_get_shared_info_list(pid);
@@ -2279,8 +2396,10 @@ int _start_app(const char* appid, bundle* kb, int cmd, int caller_pid, uid_t cal
                                        return pid;
                                }
 
-                               if (found_pid != -1)
+                               if (found_pid != -1) {
+                                       _W("app_group_clear_top, pid: %d", found_pid);
                                        app_group_clear_top(found_pid);
+                               }
                        }
 
                        if (pid == -1 && can_attach)
@@ -2335,6 +2454,7 @@ int _start_app(const char* appid, bundle* kb, int cmd, int caller_pid, uid_t cal
                if (__grant_temporary_permission(caller_pid, appid, kb,
                        &caller_exec_label, &callee_exec_label, &paths) == 0)
                        grant_permission = 1;
+
                status = _status_get_app_info_status(pid);
                if (pid > 0 && status != STATUS_DYING) {
                        if (caller_pid == pid) {
@@ -2579,6 +2699,9 @@ int _start_app(const char* appid, bundle* kb, int cmd, int caller_pid, uid_t cal
                        if (new_process) {
                                _D("add app group info");
                                app_group_start_app(pid, kb, lpid, can_attach, launch_mode);
+
+                               if (component_type && strncmp(component_type, APP_TYPE_UI, strlen(APP_TYPE_UI)) == 0)
+                                       __add_fgmgr_list(pid);
                        } else if (cmd == APP_START
                                        || cmd == APP_START_RES
                                        || cmd == APP_START_ASYNC
@@ -2588,6 +2711,7 @@ int _start_app(const char* appid, bundle* kb, int cmd, int caller_pid, uid_t cal
                                 ) {
                                app_group_restart_app(pid, kb);
                        }
+
 #ifdef _APPFW_FEATURE_AMD_KEY
                        grab_timer_id = g_timeout_add(1000, __grab_timeout_handler, (void *)pid);
 #endif
@@ -2665,6 +2789,8 @@ int _start_app(const char* appid, bundle* kb, int cmd, int caller_pid, uid_t cal
 
                        if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) {
                                pid = ret;
+                       } else {
+                               delay_reply = 1;
                        }
                } else if (cmd != APP_RESUME) {
 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
@@ -2731,8 +2857,10 @@ int _start_app(const char* appid, bundle* kb, int cmd, int caller_pid, uid_t cal
 
 #ifdef _APPFW_FEATURE_APP_CHECKER
                pkg_type = appinfo_get_value(ai, AIT_TYPE);
-               if (!pkg_type)
+               if (!pkg_type) {
+                       traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
                        return -1;
+               }
 
                ret = ac_server_check_launch_privilege(appid, pkg_type, pid);
                if (ret != AC_R_ERROR) {
@@ -2757,6 +2885,8 @@ int _start_app(const char* appid, bundle* kb, int cmd, int caller_pid, uid_t cal
 int __e17_status_handler(int pid, int status, void *data)
 {
        if (status == PROC_STATUS_FG) {
+               __del_fgmgr_list(pid);
+
 #ifdef _APPFW_FEATURE_AMD_KEY
                _D("pid(%d) status(%d)", pid, status);
                if(_input_window_get() != 0)
@@ -2768,10 +2898,18 @@ int __e17_status_handler(int pid, int status, void *data)
                }
                g_source_remove(grab_timer_id);
 #endif
-
-               _status_update_app_info_list(pid, STATUS_VISIBLE);
+               _status_update_app_info_list(pid, STATUS_VISIBLE, FALSE);
+#ifdef _APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP
+#ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
+               __check_home_app(pid);
+#endif
+#endif
        } else if (status == PROC_STATUS_BG) {
-               _status_update_app_info_list(pid, STATUS_BG);
+               _status_update_app_info_list(pid, STATUS_BG, FALSE);
+       } else if (status == PROC_STATUS_LAUNCH) {
+               _D("pid(%d) status(%d)", pid, status);
+               traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:AMD:EFFECT_DONE");
+               traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
        }
 
        return 0;
index 45355ca..952581d 100755 (executable)
@@ -321,7 +321,7 @@ static int __app_dead_handler(int pid, void *data)
        char trm_buf[MAX_PACKAGE_STR_SIZE];
        char buf[MAX_LOCAL_BUFSZ];
 
-       _I("__app_dead_handler, pid: %d", pid);
+       _W("__app_dead_handler, pid: %d", pid);
 
        if(pid <= 0)
                return 0;
@@ -331,6 +331,7 @@ static int __app_dead_handler(int pid, void *data)
 #endif
 
        if (app_group_is_leader_pid(pid)) {
+               _W("app_group_leader_app, pid: %d", pid);
                if (app_group_find_second_leader(pid) == -1) {
                        app_group_clear_top(pid);
                        app_group_set_dead_pid(pid);
@@ -338,10 +339,16 @@ static int __app_dead_handler(int pid, void *data)
                } else
                        app_group_remove_leader_pid(pid);
        } else if (app_group_is_sub_app(pid)) {
-               if (app_group_can_reroute(pid))
+               _W("app_group_sub_app, pid: %d", pid);
+               int caller_pid = app_group_get_next_caller_pid(pid);
+
+               if (app_group_can_reroute(pid) || (caller_pid > 0 && caller_pid != pid)) {
+                       _W("app_group reroute");
                        app_group_reroute(pid);
-               else
+               } else {
+                       _W("app_group clear top");
                        app_group_clear_top(pid);
+               }
                app_group_set_dead_pid(pid);
                app_group_remove(pid);
        }
@@ -443,9 +450,7 @@ static void __window_init(void)
 
        ecore_x_init(NULL);
        _set_atom_effect();
-#ifndef __i386__
        _key_init();
-#endif
        window_initialized = 1;
 }
 
index 7d47d6d..b0195b6 100755 (executable)
@@ -144,6 +144,9 @@ static int __send_result_data(int fd, int cmd, unsigned char *kb_data, int datal
 
 static int __send_result_to_client(int fd, int res)
 {
+       if (fd < 0)
+               return -1;
+
        _W("__send_result_to_client, pid: %d", res);
 
        if (send(fd, &res, sizeof(int), MSG_NOSIGNAL) < 0) {
@@ -159,9 +162,9 @@ static int __send_result_to_client(int fd, int res)
 
 static void __real_send(int clifd, int ret)
 {
-       if(clifd <= 0) {
+       if(clifd < 0)
                return;
-       }
+
        if (send(clifd, &ret, sizeof(int), MSG_NOSIGNAL) < 0) {
                if (errno == EPIPE) {
                        _E("send failed due to EPIPE.\n");
@@ -258,6 +261,7 @@ static int __app_process_by_pid(int cmd,
                char buf[512];
                if (_status_get_pkgname_bypid(pid, buf, 512) == -1) {
                        _E("request for unknown pid. It might not be a pid of app: %d", pid);
+                       __real_send(clifd, -1);
                        return -1;
                }
        }
@@ -883,7 +887,7 @@ static gboolean __request_handler(gpointer data)
                                ret = _start_app(appid, kb, pkt->cmd, cr.pid, cr.uid, clifd);
 #endif
 
-                               if(ret > 0 && bundle_get_type(kb, AUL_K_PRELAUCHING) == BUNDLE_TYPE_NONE) {
+                               if (ret > 0 && bundle_get_type(kb, AUL_K_PRELAUCHING) == BUNDLE_TYPE_NONE) {
 #ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT
                                        if (!app_group_is_group_app(kb)) {
                                                item_pkt_t *item = g_malloc0(sizeof(item_pkt_t));
@@ -919,7 +923,7 @@ static gboolean __request_handler(gpointer data)
                                ret = _start_app(appid, kb, pkt->cmd, cr.pid, cr.uid, clifd);
                        }
 
-                       if(ret > 0) {
+                       if (ret > 0) {
 #ifdef _APPFW_FEATURE_BG_PROCESS_LIMIT
                                if (!app_group_is_group_app(kb)) {
                                        item_pkt_t *item = g_malloc0(sizeof(item_pkt_t));
@@ -945,7 +949,6 @@ static gboolean __request_handler(gpointer data)
                case APP_RESULT:
                case APP_CANCEL:
                        ret = __foward_cmd(pkt->cmd, kb, cr.pid);
-                       //__real_send(clifd, ret);
                        close(clifd);
                        break;
                case APP_PAUSE:
@@ -975,12 +978,12 @@ static gboolean __request_handler(gpointer data)
                                term_pid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
                                appid = _status_app_get_appid_bypid(atoi(term_pid));
                                ai = appinfo_find(_raf, appid);
-                               if(ai) {
+                               if (ai) {
                                        appinfo_set_value((struct appinfo *)ai, AIT_STATUS, "norestart");
                                        ret = __app_process_by_pid(pkt->cmd, term_pid, &cr, clifd);
                                } else {
                                        ret = -1;
-                                       close(clifd);
+                                       __send_result_to_client(clifd, ret);
                                }
                        }
                        break;
@@ -1056,9 +1059,8 @@ static gboolean __request_handler(gpointer data)
                                ai = appinfo_find(_raf, appid);
                                appinfo_set_value((struct appinfo *)ai, AIT_STATUS, "norestart");
                        } else {
-                               ret = _status_update_app_info_list(cr.pid, *status);
+                               ret = _status_update_app_info_list(cr.pid, *status, FALSE);
                        }
-                       //__send_result_to_client(clifd, ret);
                        close(clifd);
                        break;
                case APP_GET_STATUS:
@@ -1400,4 +1402,10 @@ int _request_init(struct amdmgr *amd, int fd_sig)
        return 0;
 }
 
+#ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
+const char* _get_home_appid(void)
+{
+       return home_appid;
+}
+#endif
 
index 7f0b36b..4bf1310 100755 (executable)
@@ -28,6 +28,9 @@ int _release_srv(const char *appid);
 int _send_set_process_group_signal_signal(int owner_pid, int child_pid);
 int _signal_block_sigchld(void);
 int _signal_unblock_sigchld(void);
+#ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
+const char* _get_home_appid(void);
+#endif
 
 #endif
 
index 68b73f6..fb39993 100755 (executable)
@@ -59,14 +59,30 @@ GHashTable *app_running_cache = NULL;
 struct appinfomgr *_saf = NULL;
 
 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
-#define AMD_LOG_BUFFER_SIZE                            10000
-#define AMD_LOG_BUFFER_STRING_SIZE             128
-#define AMD_LOG_FILE                              "/var/log/amd.log"
+#define AMD_LOG_BUFFER_SIZE 10000
+#define AMD_LOG_BUFFER_STRING_SIZE 128
+#define AMD_LOG_FILE "/var/log/amd.log"
 
 static int log_index = 0;
 static int log_fd = 0;
 #endif
 
+static int __send_result_to_client(int clifd, int res)
+{
+       if (clifd < 0)
+               return -1;
+
+       if (send(clifd, &res, sizeof(int), MSG_NOSIGNAL) < 0) {
+               if (errno == EPIPE)
+                       _E("send failed due to EPIPE.\n");
+               _E("send fail to client");
+       }
+
+       close(clifd);
+
+       return 0;
+}
+
 static app_status_info_t* __get_app_status_info(int pid)
 {
        GSList *iter = NULL;
@@ -432,7 +448,7 @@ static Eina_Bool __app_terminate_timer_cb(void *data)
        return ECORE_CALLBACK_CANCEL;
 }
 
-int _status_update_app_info_list(int pid, int status)
+int _status_update_app_info_list(int pid, int status, gboolean force)
 {
        GSList *iter = NULL;
        app_status_info_t *info_t = NULL;
@@ -454,7 +470,7 @@ int _status_update_app_info_list(int pid, int status)
                }
        }
 
-       app_group_set_status(pid, status);
+       app_group_set_status(pid, status, force);
 
        return 0;
 }
@@ -716,10 +732,11 @@ int _status_send_running_appinfo(int fd)
        app_pkt_t *pkt = NULL;
        char tmp_pid[MAX_PID_STR_BUFSZ];
 
-       pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
-       if(!pkt) {
+       pkt = (app_pkt_t *)malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
+       if (!pkt) {
                _E("malloc fail");
-               return 0;
+               __send_result_to_client(fd, -1);
+               return -1;
        }
 
        memset(pkt, 0, AUL_SOCK_MAXBUFF);
@@ -748,7 +765,7 @@ int _status_send_running_appinfo(int fd)
                _E("send fail to client");
        }
 
-       if(pkt)
+       if (pkt)
                free(pkt);
 
        close(fd);
@@ -885,10 +902,10 @@ int _status_send_running_appinfo_v2(int fd)
        app_pkt_t *pkt = NULL;
 
        pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
-       if(!pkt) {
+       if (!pkt) {
                _E("malloc fail");
-               close(fd);
-               return 0;
+               __send_result_to_client(fd, -1);
+               return -1;
        }
 
        memset(pkt, 0, AUL_SOCK_MAXBUFF);
@@ -904,7 +921,7 @@ int _status_send_running_appinfo_v2(int fd)
                _E("send fail to client");
        }
 
-       if(pkt)
+       if (pkt)
                free(pkt);
 
        close(fd);
@@ -1058,7 +1075,7 @@ int _status_get_cmdline(int fd, int pid)
        char *cmdline;
 
        pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
-       if(!pkt) {
+       if (!pkt) {
                _E("malloc fail");
                close(fd);
                return 0;
@@ -1107,9 +1124,10 @@ int _status_send_group_info(int fd)
        char buf[2048];
 
        pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
-       if(!pkt) {
+       if (!pkt) {
                _E("malloc fail");
-               return 0;
+               __send_result_to_client(fd, -1);
+               return -1;
        }
 
        memset(pkt, 0, AUL_SOCK_MAXBUFF);
@@ -1244,7 +1262,7 @@ int _status_send_group_info(int fd)
                _E("send fail to client");
        }
 
-       if(pkt)
+       if (pkt)
                free(pkt);
 
        close(fd);
index ae8c1d9..7110527 100755 (executable)
@@ -26,7 +26,7 @@
 
 int _status_add_app_info_list(const char *appid, const char *app_path,
        const char *caller, int pid, int pad_pid, int is_subapp);
-int _status_update_app_info_list(int pid, int status);
+int _status_update_app_info_list(int pid, int status, gboolean force);
 int _status_update_app_info_caller_pid(int pid, int caller_pid);
 int _status_get_app_info_last_caller_pid(int pid);
 int _status_remove_app_info_list(int pid);
index 6cc46c9..8d66511 100755 (executable)
@@ -1355,6 +1355,8 @@ int aul_listen_app_dead_signal(int (*func) (int, void *), void *data);
  */
 int aul_listen_app_launch_signal(int (*func) (int, void *), void *data);
 
+int aul_listen_app_launch_signal_v2(int (*func) (int, const char *, void *), void *data);
+
 int aul_listen_booting_done_signal(int (*func) (int, void *), void *data);
 
 int aul_listen_cooldown_signal(int (*func) (const char *, void *), void *data);
index 0434351..585b43d 100755 (executable)
@@ -49,6 +49,7 @@ BuildRequires: pkgconfig(cert-svc)
 %define appfw_feature_data_control 1
 %define appfw_feature_debug_launchpad 1
 %define appfw_feature_app_control_lite 0
+%define appfw_feature_terminate_unmanageable_app 0
 %if "%{?tizen_profile_name}" == "wearable"
 %define appfw_feature_bg_process_limit 0
 %define appfw_feature_app_checker 0
@@ -196,7 +197,9 @@ _APPFW_FEATURE_EFFECTIVE_APPID=ON
 %if 0%{?appfw_feature_private_service}
 _APPFW_FEATURE_PRIVATE_SERVICE=ON
 %endif
-
+%if 0%{?appfw_feature_terminate_unmanageable_app}
+_APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP=ON
+%endif
 
 cmake -DCMAKE_INSTALL_PREFIX=%{_prefix} \
        -D_APPFW_FEATURE_PROCESS_POOL:BOOL=${_APPFW_FEATURE_PROCESS_POOL} \
@@ -224,6 +227,7 @@ cmake -DCMAKE_INSTALL_PREFIX=%{_prefix} \
        -D_APPFW_FEATURE_FAKE_EFFECT:BOOL=${_APPFW_FEATURE_FAKE_EFFECT} \
        -D_APPFW_FEATURE_EFFECTIVE_APPID:BOOL=${_APPFW_FEATURE_EFFECTIVE_APPID} \
        -D_APPFW_FEATURE_PRIVATE_SERVICE:BOOL=${_APPFW_FEATURE_PRIVATE_SERVICE} \
+       -D_APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP:BOOL=${_APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP} \
        .
 
 make %{?jobs:-j%jobs}
index 9d08f87..e1cb8d8 100755 (executable)
@@ -35,6 +35,9 @@ static void *_app_dead_data;
 static int (*_app_launch_handler) (int pid, void *data);
 static void *_app_launch_data;
 
+static int (*_app_launch_handler2) (int pid, const char *app_id, void *data);
+static void *_app_launch_data2;
+
 static int (*_booting_done_handler) (int pid, void *data);
 static void *_booting_done_data;
 
@@ -81,48 +84,65 @@ __app_dbus_signal_filter(DBusConnection *conn, DBusMessage *message,
 
        if (dbus_message_is_signal(
          message, interface, AUL_DBUS_APPDEAD_SIGNAL)) {
-               if (dbus_message_get_args(message, &error, DBUS_TYPE_UINT32,
-                    &pid, DBUS_TYPE_INVALID) == FALSE) {
-                       _E("Failed to get data: %s", error.message);
-                       dbus_error_free(&error);
-                       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-               }
-               if (_app_dead_handler)
+               if (_app_dead_handler) {
+                       if (dbus_message_get_args(message, &error,
+                                       DBUS_TYPE_UINT32, &pid,
+                                       DBUS_TYPE_INVALID) == FALSE) {
+                               _E("Failed to get data: %s", error.message);
+                               dbus_error_free(&error);
+                               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+                       }
                        _app_dead_handler(pid, _app_dead_data);
+               }
        } else if (dbus_message_is_signal(
          message, interface, AUL_DBUS_APPLAUNCH_SIGNAL)) {
-               if (dbus_message_get_args(message, &error, DBUS_TYPE_UINT32,
-                    &pid, DBUS_TYPE_INVALID) == FALSE) {
-                       _E("Failed to get data: %s", error.message);
-                       dbus_error_free(&error);
-                       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+               if (_app_launch_handler || _app_launch_handler2) {
+                       const char *app_id = NULL;
+
+                       if (dbus_message_get_args(message, &error,
+                                       DBUS_TYPE_UINT32, &pid,
+                                       DBUS_TYPE_STRING, &app_id,
+                                       DBUS_TYPE_INVALID) == FALSE) {
+                               _E("Failed to get data: %s", error.message);
+                               dbus_error_free(&error);
+                               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+                       }
+
+                       if (_app_launch_handler)
+                               _app_launch_handler(pid, _app_launch_data);
+
+                       if (_app_launch_handler2)
+                               _app_launch_handler2(pid, app_id, _app_launch_data2);
                }
-               if (_app_launch_handler)
-                       _app_launch_handler(pid, _app_launch_data);
        } else if (dbus_message_is_signal(
          message, interface, SYSTEM_SIGNAL_BOOTING_DONE)) {
                if (_booting_done_handler)
                        _booting_done_handler(pid, _booting_done_data);
        } else if (dbus_message_is_signal(
          message, interface, RESOURCED_SIGNAL_PROCESS_STATUS)) {
-               if (dbus_message_get_args(message, &error, DBUS_TYPE_INT32,&status,
-                       DBUS_TYPE_INT32,&pid, DBUS_TYPE_INVALID) == FALSE) {
-                       _E("Failed to get data: %s", error.message);
-                       dbus_error_free(&error);
-                       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-               }
-               if (_status_handler)
+               if (_status_handler) {
+                       if (dbus_message_get_args(message, &error,
+                                       DBUS_TYPE_INT32,&status,
+                                       DBUS_TYPE_INT32,&pid,
+                                       DBUS_TYPE_INVALID) == FALSE) {
+                               _E("Failed to get data: %s", error.message);
+                               dbus_error_free(&error);
+                               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+                       }
                        _status_handler(pid, status, _status_data);
+               }
        } else if (dbus_message_is_signal(
          message, interface, SYSTEM_SIGNAL_COOLDOWN_CHANGED)) {
-               if (dbus_message_get_args(message, &error, DBUS_TYPE_STRING, &cooldown_status,
-                       DBUS_TYPE_INVALID) == FALSE) {
-                       _E("Failed to get data: %s", error.message);
-                       dbus_error_free(&error);
-                       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-               }
-               if (_cooldown_handler)
+               if (_cooldown_handler) {
+                       if (dbus_message_get_args(message, &error,
+                                       DBUS_TYPE_STRING, &cooldown_status,
+                                       DBUS_TYPE_INVALID) == FALSE) {
+                               _E("Failed to get data: %s", error.message);
+                               dbus_error_free(&error);
+                               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+                       }
                        _cooldown_handler(cooldown_status, _cooldown_data);
+               }
        }
 
        return DBUS_HANDLER_RESULT_HANDLED;
@@ -225,7 +245,7 @@ SLPAPI int aul_listen_app_dead_signal(int (*func) (int, void *), void *data)
                        _E("error app signal init");
                        return AUL_R_ERROR;
                }
-       } else if (_app_launch_handler == NULL) {
+       } else if (_app_launch_handler == NULL && _app_launch_handler2 == NULL) {
                if (__app_dbus_signal_handler_fini() < 0) {
                        _E("error app signal fini");
                        return AUL_R_ERROR;
@@ -244,7 +264,7 @@ SLPAPI int aul_listen_app_launch_signal(int (*func) (int, void *), void *data)
                        _E("error app signal init");
                        return AUL_R_ERROR;
                }
-       } else if (_app_dead_handler == NULL) {
+       } else if (_app_launch_handler2 == NULL && _app_dead_handler == NULL) {
                if (__app_dbus_signal_handler_fini() < 0) {
                        _E("error app signal fini");
                        return AUL_R_ERROR;
@@ -256,6 +276,26 @@ SLPAPI int aul_listen_app_launch_signal(int (*func) (int, void *), void *data)
        return AUL_R_OK;
 }
 
+SLPAPI int aul_listen_app_launch_signal_v2(int (*func) (int, const char *, void *), void *data)
+{
+       if (func) {
+               if (__app_dbus_signal_handler_init() < 0) {
+                       _E("error app signal init");
+                       return AUL_R_ERROR;
+               }
+       } else if (_app_launch_handler == NULL && _app_dead_handler == NULL) {
+               if (__app_dbus_signal_handler_fini() < 0) {
+                       _E("error app signal fini");
+                       return AUL_R_ERROR;
+               }
+       }
+
+       _app_launch_handler2 = func;
+       _app_launch_data2 = data;
+
+       return AUL_R_OK;
+}
+
 SLPAPI int aul_listen_booting_done_signal(int (*func) (int, void *), void *data)
 {
        if (func) {
@@ -321,6 +361,8 @@ SLPAPI int aul_update_freezer_status(int pid, const char* type)
 
        dbus_error_init(&err);
 
+       _W("send_update_freezer_status, pid: %d, type: %s", pid, type);
+
        conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
        if (!conn) {
                _E("Fail to dbus_bus_get : %s", err.message);
@@ -344,8 +386,6 @@ SLPAPI int aul_update_freezer_status(int pid, const char* type)
                ret = -1;
        }
 
-       _D("Send a freezer signal pid: %d, type: %s", pid, type);
-
        if (!dbus_connection_send(conn, msg, &serial)) {
                _E("Failed to send a D-Bus Message.");
                ret = -1;
@@ -390,6 +430,8 @@ SLPAPI int aul_send_app_launch_request_signal(int pid, const char* appid, const
 
        __app_status_dbus_init();
 
+       _W("send_app_launch_signal, pid: %d, appid: %s", pid, appid);
+
        msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
                        AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
                        AUL_APP_STATUS_DBUS_LAUNCH_REQUEST);
@@ -433,6 +475,8 @@ SLPAPI int aul_send_app_resume_request_signal(int pid, const char* appid, const
 
        __app_status_dbus_init();
 
+       _W("send_app_resume_signal, pid: %d, appid: %s", pid, appid);
+
        msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
                        AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
                        AUL_APP_STATUS_DBUS_RESUME_REQUEST);
@@ -544,6 +588,8 @@ SLPAPI int aul_send_app_status_change_signal(int pid, const char* appid, const c
 
        int ret = -1;
 
+       _W("send_app_status_change_signal, pid: %d, appid: %s, status: %s", pid, appid, status);
+
        __app_status_dbus_init();
 
        msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
@@ -641,6 +687,8 @@ SLPAPI int aul_send_app_group_signal(int owner_pid, int child_pid, const char *c
 
        int ret = -1;
 
+       _W("send_app_group_signal, owner: %d, child: %d", owner_pid, child_pid);
+
        __app_status_dbus_init();
 
        msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
@@ -686,4 +734,3 @@ end:
 
        return ret;
 }
-