4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
25 #include <Ecore_Input.h>
26 #ifdef _APPFW_FEATURE_AMD_KEY
31 #include <Ecore_Evas.h>
32 #include <security-server.h>
35 #include <bundle_internal.h>
38 #include <aul_svc_priv_key.h>
40 #ifdef _APPFW_FEATURE_APP_CHECKER
41 #include <app-checker-server.h>
47 #include <sys/types.h>
50 #include <sys/prctl.h>
51 #include <sys/resource.h>
52 #include <pkgmgr-info.h>
54 #include <proc_stat.h>
57 #include <sys/smack.h>
58 #include <security-server-perm.h>
60 #ifdef _APPFW_FEATURE_PRIVATE_SERVICE
61 #include <cert-service.h>
64 #include "amd_config.h"
65 #include "amd_launch.h"
66 #include "amd_appinfo.h"
67 #include "amd_status.h"
70 #include "simple_util.h"
72 #include "app_signal.h"
73 #include "amd_app_group.h"
74 #include "amd_request.h"
76 #define PREEXEC_ACTIVATE
80 #include "access_control.h"
82 #ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
83 #include "appfw_env.h"
86 #define TERM_WAIT_SEC 3
89 #define AUL_PR_NAME 16
90 #define PATH_APP_ROOT "/opt/usr/apps"
91 #define PATH_DATA "/data"
92 #define SDK_CODE_COVERAGE "CODE_COVERAGE"
93 #define SDK_DYNAMIC_ANALYSIS "DYNAMIC_ANALYSIS"
94 #define PATH_DA_SO "/home/developer/sdk_tools/da/da_probe.so"
96 #ifdef _APPFW_FEATURE_FAKE_EFFECT
97 #define PHONE_ORIENTATION_MODE "memory/private/sensor/10001"
98 #define PHONE_ROTATE_LOCK "db/setting/auto_rotate_screen"
101 #define SYS_MIN_CPU_LOCK_FILE "/sys/devices/system/cpu/cpufreq/slp/min_cpu_lock"
102 #define MIN_CPU_LCK_CNT 0
103 #define MAX_CPU_LCK_CNT 2
105 #define HIDE_INDICATOR 0
106 #define SHOW_INDICATOR 1
108 #define PROC_STATUS_LAUNCH 0
109 #define PROC_STATUS_FG 3
110 #define PROC_STATUS_BG 4
111 #ifdef _APPFW_FEATURE_CPU_BOOST
112 #define APP_BOOSTING_PERIOD 1500 //msec
115 #ifdef _APPFW_FEATURE_PRIVATE_SERVICE
116 #define OSP_K_LAUNCH_TYPE "__OSP_LAUNCH_TYPE__"
117 #define OSP_V_LAUNCH_TYPE_DATACONTROL "datacontrol"
120 static char *amd_cmdline;
122 struct appinfomgr *_laf;
124 DBusConnection *conn;
125 #ifdef _APPFW_FEATURE_AMD_KEY
129 static GList *_fgmgr_list;
137 /*Unused data structure. Will be removed*/
139 char *pkg_name; /* package */
140 char *app_path; /* exec */
141 char *original_app_path; /* exec */
142 int multiple; /* x_slp_multiple */
144 } app_info_from_pkgmgr;
147 static GList *_kill_list;
152 guint tid; /* timer ID */
156 static const char *atom_name = "_E_COMP_FAKE_LAUNCH_IMAGE"; // Atomic ID string
157 static Ecore_X_Atom ATOM_IMAGE_EFFECT; //Atomic ID
158 static void __amd_effect_image_file_set(char *image_file);
159 static void __amd_send_message_to_e17(int screenmode, const char * indicator, int effect_type, int theme);
160 static void __set_reply_handler(int fd, int pid, int clifd, int cmd);
161 static void __real_send(int clifd, int ret);
162 static int __send_proc_prelaunch_signal(const char *appid, const char *pkgid, int attribute);
163 int invoke_dbus_method_sync(const char *dest, const char *path,
164 const char *interface, const char *method,
165 const char *sig, char *param[]);
167 static void _set_sdk_env(const char* appid, char* str) {
168 char buf[MAX_LOCAL_BUFSZ];
171 _D("key : %s / value : %s", AUL_K_SDK, str);
172 /* http://gcc.gnu.org/onlinedocs/gcc/Cross_002dprofiling.html*/
173 /* GCOV_PREFIX contains the prefix to add to the absolute paths in the object file. */
174 /* Prefix can be absolute, or relative. The default is no prefix. */
175 /* GCOV_PREFIX_STRIP indicates the how many initial directory names */
176 /* to stripoff the hardwired absolute paths. Default value is 0. */
177 if (strncmp(str, SDK_CODE_COVERAGE, strlen(str)) == 0) {
178 snprintf(buf, MAX_LOCAL_BUFSZ, PATH_APP_ROOT"/%s"PATH_DATA, appid);
179 ret = setenv("GCOV_PREFIX", buf, 1);
180 _D("GCOV_PREFIX : %d", ret);
181 ret = setenv("GCOV_PREFIX_STRIP", "4096", 1);
182 _D("GCOV_PREFIX_STRIP : %d", ret);
183 } else if (strncmp(str, SDK_DYNAMIC_ANALYSIS, strlen(str)) == 0) {
184 ret = setenv("LD_PRELOAD", PATH_DA_SO, 1);
185 _D("LD_PRELOAD : %d", ret);
189 #define USE_ENGINE(engine) setenv("ELM_ENGINE", engine, 1);
191 static void _set_env(const char *appid, bundle * kb, const char *hwacc)
194 const char **str_array;
198 setenv("PKG_NAME", appid, 1);
202 str = bundle_get_val(kb, AUL_K_STARTTIME);
204 setenv("APP_START_TIME", str, 1);
206 if(bundle_get_type(kb, AUL_K_SDK) & BUNDLE_TYPE_ARRAY) {
207 str_array = bundle_get_str_array(kb, AUL_K_SDK, &len);
208 if(str_array != NULL) {
209 for (i = 0; i < len; i++) {
210 _D("index : [%d]", i);
211 _set_sdk_env(appid, (char *)str_array[i]);
215 str = bundle_get_val(kb, AUL_K_SDK);
217 _set_sdk_env(appid, (char *)str);
221 setenv("HWACC", hwacc, 1);
224 static void __set_oom(void)
226 char buf[MAX_OOM_ADJ_BUFSZ] = {0,};
229 /* we should reset oomadj value as default because child
230 inherits from parent oom_adj*/
231 snprintf(buf, MAX_OOM_ADJ_BUFSZ, "/proc/%d/oom_score_adj", getpid());
232 fp = fopen(buf, "w");
235 fprintf(fp, "%d", 100);
239 static void _prepare_exec(const char *appid, bundle *kb)
241 const struct appinfo *ai;
242 const char *app_path = NULL;
243 const char *pkg_type = NULL;
245 char process_name[AUL_PR_NAME];
251 signal(SIGINT, SIG_DFL);
252 signal(SIGTERM, SIG_DFL);
253 signal(SIGCHLD, SIG_DFL);
257 ai = appinfo_find(_laf, appid);
259 app_path = appinfo_get_value(ai, AIT_EXEC);
260 pkg_type = appinfo_get_value(ai, AIT_TYPE);
261 hwacc = appinfo_get_value(ai, AIT_HWACC);
263 __preexec_run(pkg_type, appid, app_path);
266 SECURE_LOGD("appid : %s / pkg_type : %s / app_path : %s ", appid, pkg_type, app_path);
267 if (pkg_type && strncmp(pkg_type, "wgt", 3) !=0 && (ret = __set_access(appid, pkg_type, app_path)) < 0) {
268 _D("fail to set privileges - check your package's credential : %d\n", ret);
272 /* SET DUMPABLE - for coredump*/
273 prctl(PR_SET_DUMPABLE, 1);
275 /* SET PROCESS NAME*/
276 if (app_path == NULL) {
277 _D("app_path should not be NULL - check menu db");
280 file_name = strrchr(app_path, '/') + 1;
281 if (file_name == NULL) {
282 _D("can't locate file name to execute");
285 memset(process_name, '\0', AUL_PR_NAME);
286 snprintf(process_name, AUL_PR_NAME, "%s", file_name);
287 prctl(PR_SET_NAME, process_name);
290 _set_env(appid, kb, hwacc);
293 static char **__create_argc_argv(bundle * kb, int *margc)
298 argc = bundle_export_to_argv(kb, &argv);
303 static void _do_exec(const char *cmd, const char *group, bundle *kb)
311 b = g_shell_parse_argv(cmd, &argc, &argv, NULL);
314 b_argv = __create_argc_argv(kb, &b_argc);
315 b_argv[0] = strdup(argv[0]);
316 _prepare_exec(group, kb);
317 execv(b_argv[0], b_argv);
321 _prepare_exec(group, kb);
322 execv(argv[0], argv);
325 _E("exec error: %s", strerror(errno));
329 static inline int __send_app_launch_signal(int launch_pid, const char *app_id)
331 DBusMessage *message;
336 message = dbus_message_new_signal(AUL_DBUS_PATH,
337 AUL_DBUS_SIGNAL_INTERFACE,
338 AUL_DBUS_APPLAUNCH_SIGNAL);
340 if (dbus_message_append_args(message,
341 DBUS_TYPE_UINT32, &launch_pid,
342 DBUS_TYPE_STRING, &app_id,
343 DBUS_TYPE_INVALID) == FALSE) {
344 _E("Failed to load data error");
348 if (dbus_connection_send(conn, message, NULL) == FALSE) {
349 _E("dbus send error");
353 dbus_connection_flush(conn);
354 dbus_message_unref(message);
356 _W("send launch signal done: %d, %s", launch_pid, app_id);
361 static int __send_watchdog_signal(int pid, int signal_num)
363 DBusMessage *message;
368 if (!_get_platform_ready()) {
369 _E("[Info]_get_platform_ready return false");
373 #ifdef _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
374 if(_status_get_cooldown_status() == COOLDOWN_LIMIT) {
375 _E("[Info]cooldown status : LimitAction");
378 #endif // _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
380 message = dbus_message_new_signal(RESOURCED_PROC_OBJECT,
381 RESOURCED_PROC_INTERFACE,
382 RESOURCED_PROC_WATCHDOG_SIGNAL);
384 if (dbus_message_append_args(message,
385 DBUS_TYPE_INT32, &pid,
386 DBUS_TYPE_INT32, &signal_num,
387 DBUS_TYPE_INVALID) == FALSE) {
388 _E("Failed to load data error");
392 if (dbus_connection_send(conn, message, NULL) == FALSE) {
393 _E("dbus send error");
397 dbus_connection_flush(conn);
398 dbus_message_unref(message);
400 _W("send a watchdog signal done: %d", pid);
405 static int __send_proc_prelaunch_signal(const char *appid, const char *pkgid, int attribute)
407 DBusMessage *message;
412 message = dbus_message_new_signal(RESOURCED_PROC_OBJECT,
413 RESOURCED_PROC_INTERFACE,
414 RESOURCED_PROC_PRELAUNCH_SIGNAL);
416 if (dbus_message_append_args(message,
417 DBUS_TYPE_STRING, &appid,
418 DBUS_TYPE_STRING, &pkgid,
419 DBUS_TYPE_INT32, &attribute,
420 DBUS_TYPE_INVALID) == FALSE) {
421 _E("Failed to load data error");
425 if (dbus_connection_send(conn, message, NULL) == FALSE) {
426 _E("dbus send error");
430 dbus_connection_flush(conn);
431 dbus_message_unref(message);
433 SECURE_LOGW("send a prelaunch signal done: appid(%s) pkgid(%s) attribute(%x)", appid, pkgid, attribute);
438 static int __check_cmdline(int ret)
442 int cmdline_changed = 0;
443 int cmdline_exist = 0;
448 /* check normally was launched?*/
451 cmdline = __proc_get_cmdline_bypid(ret);
452 if (cmdline == NULL) {
453 _E("error founded when being launched with %d", ret);
454 if (cmdline_exist || cmdline_changed) {
455 _E("The app process might be terminated while we are wating %d", ret);
458 } else if (strcmp(cmdline, amd_cmdline)) {
467 _D("-- now wait to change cmdline --");
468 usleep(50 * 1000); /* 50ms sleep*/
470 } while (wait_count <= 20); /* max 50*20ms will be sleep*/
472 if ((!cmdline_exist) && (!cmdline_changed)) {
473 _E("cmdline_exist 0 & cmdline_changed 0");
477 if (!cmdline_changed)
478 _E("process launched, but cmdline not changed");
483 int start_process(const char *appid, const char *cmd, bundle *kb)
490 case 0: /* child process */
491 _D("start application");
492 _signal_unblock_sigchld();
493 #ifdef _APPFW_FEATURE_PRIORITY_CHANGE
494 r = setpriority(PRIO_PROCESS, 0, 0);
497 SECURE_LOGE("Setting process (%d) priority to 0 failed, errno: %d (%s)",
498 getpid(), errno, strerror(errno));
501 _do_exec(cmd, appid, kb);
507 _E("application start: fork: %s", strerror(errno));
510 default: /* parent process */
511 _W("child process: %d", p);
512 r = __check_cmdline(p);
514 __send_app_launch_signal(r, appid);
516 _E("cmdline change failed.");
523 static int __check_ver(const char *required, const char *actual)
526 if (required && actual) {
527 ret = strverscmp(required, actual); // should 0 or less
535 static int __get_prelaunch_attribute(const struct appinfo *ai)
537 int attribute_val = 0;
538 const char *attribute_str = NULL;
540 attribute_str = appinfo_get_value(ai, AIT_ALLOWED_BG);
541 if (attribute_str && strncmp(attribute_str, "ALLOWED_BG", sizeof("ALLOWED_BG")) == 0) {
542 attribute_val |= RESOURCED_ALLOWED_BG_ATTRIBUTE;
545 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
546 attribute_val |= RESOURCED_BACKGROUND_MANAGEMENT_ATTRIBUTE;
549 attribute_str = appinfo_get_value(ai, AIT_API_VER);
550 if (attribute_str && __check_ver("2.4", attribute_str)) {
551 attribute_val |= RESOURCED_API_VER_2_4_ATTRIBUTE;
554 return attribute_val;
557 int _start_srv(const struct appinfo *ai)
564 const char *appid = NULL;
565 int prelaunch_attribute = 0;
567 group = appinfo_get_filename(ai);
569 cmd = appinfo_get_value(ai, AIT_EXEC);
571 _E("start service: '%s' has no exec", group);
575 appid = appinfo_get_value(ai, AIT_NAME);
576 pkgid = appinfo_get_value(ai, AIT_PKGID);
578 prelaunch_attribute = __get_prelaunch_attribute(ai);
579 if ((prelaunch_attribute & RESOURCED_ALLOWED_BG_ATTRIBUTE) ||
580 !(prelaunch_attribute & RESOURCED_API_VER_2_4_ATTRIBUTE)) {
581 SECURE_LOGD("[__SUSPEND__] allowed background, appid :%s, app_type: %s, api version: %s",
582 appid, APP_TYPE_SERVICE, appinfo_get_value(ai, AIT_API_VER));
587 bundle_add(b, AUL_K_ALLOWED_BG, "ALLOWED_BG");
590 __send_proc_prelaunch_signal(appid, pkgid, prelaunch_attribute);
592 r = start_process(group, cmd, b);
599 _E("start service: '%s': failed", group);
604 aul_send_app_launch_request_signal(r, group, pkgid, APP_TYPE_SERVICE);
605 _status_add_app_info_list(group, cmd, NULL, r, -1, 0);
610 static void _free_kt(struct ktimer *kt)
619 static void _kill_pid(struct cginfo *cg, const char *group, pid_t pid)
623 if (pid <= INIT_PID) /* block sending to all process or init */
626 /* TODO: check pid exist in group */
630 _E("send SIGKILL: pid %d not exist", pid);
634 r = kill(pid, SIGKILL);
636 _E("send SIGKILL: %s", strerror(errno));
639 static gboolean _ktimer_cb(gpointer data)
641 struct ktimer *kt = data;
643 _kill_pid(kt->cg, kt->group, kt->pid);
644 _kill_list = g_list_remove(_kill_list, kt);
650 static void _add_list(struct cginfo *cg, const char *group, pid_t pid)
654 kt = calloc(1, sizeof(*kt));
659 kt->group = strdup(group);
665 kt->tid = g_timeout_add_seconds(TERM_WAIT_SEC, _ktimer_cb, kt);
667 _kill_list = g_list_append(_kill_list, kt);
670 static inline void _del_list(GList *l)
679 g_source_remove(kt->tid);
681 _kill_list = g_list_delete_link(_kill_list, l);
684 static int _kill_pid_cb(void *user_data, const char *group, pid_t pid)
688 if (pid <= INIT_PID) /* block sending to all process or init */
691 r = kill(pid, SIGTERM);
693 _E("send SIGTERM: %s", strerror(errno));
695 _add_list(user_data, group, pid);
700 void service_release(const char *group)
705 if (!group || !*group)
708 group = FILENAME(group);
711 for (l = _kill_list; l; l = g_list_next(l)) {
712 struct ktimer *k = l->data;
716 if (k->group && !strcmp(k->group, group))
725 int _send_to_sigkill(int pid)
733 if (killpg(pgid, SIGKILL) < 0)
738 int _resume_app(int pid, int clifd)
743 __app_send_raw_with_delay_reply(pid, APP_RESUME_BY_PID, (unsigned char *)&dummy,
746 _E("resume packet timeout error");
748 _E("raise failed - %d resume fail\n", pid);
749 _E("we will term the app - %d\n", pid);
750 _send_to_sigkill(pid);
753 __real_send(clifd, ret);
758 __set_reply_handler(ret, pid, clifd, APP_RESUME_BY_PID);
763 int _pause_app(int pid, int clifd)
768 __app_send_raw_with_delay_reply(pid, APP_PAUSE_BY_PID, (unsigned char *)&dummy,
771 _E("pause packet timeout error");
773 _E("iconify failed - %d pause fail\n", pid);
774 _E("we will term the app - %d\n", pid);
775 _send_to_sigkill(pid);
786 int _fake_launch_app(int cmd, int pid, bundle * kb, int clifd)
790 bundle_raw *kb_data = NULL;
793 __real_send(clifd, -EINVAL);
797 ret = bundle_encode(kb, &kb_data, &datalen);
798 if (ret != BUNDLE_ERROR_NONE) {
799 __real_send(clifd, -EINVAL);
802 if ((ret = __app_send_raw_with_delay_reply(pid, cmd, kb_data, datalen)) < 0) {
803 _E("error request fake launch - error code = %d", ret);
804 __real_send(clifd, ret);
809 __set_reply_handler(ret, pid, clifd, cmd);
814 static void __real_send(int clifd, int ret)
819 if (send(clifd, &ret, sizeof(int), MSG_NOSIGNAL) < 0) {
820 if (errno == EPIPE) {
821 _E("send failed due to EPIPE.\n");
823 _E("send fail to client");
829 static gboolean __au_glib_check(GSource *src)
834 fd_list = src->poll_fds;
836 tmp = (GPollFD *) fd_list->data;
837 if ((tmp->revents & (POLLIN | POLLPRI)))
839 fd_list = fd_list->next;
845 static gboolean __au_glib_dispatch(GSource *src, GSourceFunc callback,
852 static gboolean __au_glib_prepare(GSource *src, gint *timeout)
857 static GSourceFuncs funcs = {
858 .prepare = __au_glib_prepare,
859 .check = __au_glib_check,
860 .dispatch = __au_glib_dispatch,
873 static gboolean __reply_handler(gpointer data)
875 struct reply_info *r_info = (struct reply_info *) data;;
876 int fd = r_info->gpollfd->fd;
879 int clifd = r_info->clifd;
880 int pid = r_info->pid;
881 int cmd = r_info->cmd;
883 len = recv(fd, &res, sizeof(int), 0);
885 if (errno == EAGAIN) {
886 _E("recv timeout : %s", strerror(errno));
889 _E("recv error : %s", strerror(errno));
896 if (cmd == APP_TERM_BY_PID || cmd == APP_TERM_BGAPP_BY_PID) {
897 __real_send(clifd, -1);
898 } else if (cmd == APP_START_ASYNC || cmd == APP_PAUSE_BY_PID) {
901 __real_send(clifd, res);
904 if (cmd == APP_TERM_BY_PID || cmd == APP_TERM_BGAPP_BY_PID) {
905 __real_send(clifd, 0);
906 } else if (cmd == APP_START_ASYNC || cmd == APP_PAUSE_BY_PID) {
909 __real_send(clifd, pid);
913 _W("listen fd(%d) , send fd(%d), pid(%d), cmd(%d)", fd, clifd, pid, cmd);
915 g_source_remove(r_info->timer_id);
916 g_source_remove_poll(r_info->src, r_info->gpollfd);
917 g_source_destroy(r_info->src);
918 g_free(r_info->gpollfd);
924 static gboolean __recv_timeout_handler(gpointer data)
926 struct reply_info *r_info = (struct reply_info *) data;
927 int fd = r_info->gpollfd->fd;
929 const struct appinfo *ai;
932 _E("application is not responding : pid(%d) cmd(%d)", r_info->pid, r_info->cmd);
936 switch (r_info->cmd) {
941 case APP_START_ASYNC:
942 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
943 case APP_START_MULTI_INSTANCE:
945 appid = _status_app_get_appid_bypid(r_info->pid);
948 ai = appinfo_find(_laf, appid);
953 task_manage = appinfo_get_boolean(ai, AIT_TASKMANAGE);
955 __send_watchdog_signal(r_info->pid, SIGKILL);
958 case APP_TERM_BY_PID:
959 case APP_TERM_BGAPP_BY_PID:
960 if (_send_to_sigkill(r_info->pid) < 0) {
961 _E("fail to killing - %d\n", r_info->pid);
962 __real_send(r_info->clifd, -1);
964 __real_send(r_info->clifd, 0);
969 g_source_remove_poll(r_info->src, r_info->gpollfd);
970 g_source_destroy(r_info->src);
971 g_free(r_info->gpollfd);
977 static void __set_reply_handler(int fd, int pid, int clifd, int cmd)
981 struct reply_info *r_info;
983 src = g_source_new(&funcs, sizeof(GSource));
985 gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
986 if (gpollfd == NULL) {
991 gpollfd->events = POLLIN;
994 r_info = malloc(sizeof(*r_info));
995 if (r_info == NULL) {
1002 r_info->clifd = clifd;
1005 r_info->gpollfd = gpollfd;
1008 r_info->timer_id = g_timeout_add(5000, __recv_timeout_handler, (gpointer) r_info);
1009 g_source_add_poll(src, gpollfd);
1010 g_source_set_callback(src, (GSourceFunc) __reply_handler,
1011 (gpointer) r_info, NULL);
1012 g_source_set_priority(src, G_PRIORITY_DEFAULT);
1013 g_source_attach(src, NULL);
1015 _D("listen fd : %d, send fd : %d", fd, clifd);
1018 void _term_sub_app(int pid)
1023 const char *pkgid = NULL;
1024 const char *type = NULL;
1025 const struct appinfo *ai = NULL;
1027 appid = _status_app_get_appid_bypid(pid);
1028 ai = appinfo_find(_laf, appid);
1029 pkgid = appinfo_get_value(ai, AIT_PKGID);
1030 type = appinfo_get_value(ai, AIT_COMPTYPE);
1032 aul_send_app_terminate_request_signal(pid, appid, pkgid, type);
1033 if ( (ret = __app_send_raw_with_noreply(pid, APP_TERM_BY_PID_ASYNC,
1034 (unsigned char *)&dummy, sizeof(int))) < 0) {
1035 _E("terminate packet send error - use SIGKILL");
1036 if (_send_to_sigkill(pid) < 0) {
1037 _E("fail to killing - %d\n", pid);
1043 int _term_app(int pid, int clifd)
1048 if (app_group_is_leader_pid(pid)) {
1053 app_group_get_group_pids(pid, &cnt, &pids);
1055 for (i = cnt-1 ; i>=0; i--) {
1057 _term_sub_app(pids[i]);
1058 app_group_remove(pids[i]);
1066 if ( (ret = __app_send_raw_with_delay_reply
1067 (pid, APP_TERM_BY_PID, (unsigned char *)&dummy, sizeof(int))) < 0) {
1068 _D("terminate packet send error - use SIGKILL");
1069 if (_send_to_sigkill(pid) < 0) {
1070 _E("fail to killing - %d\n", pid);
1071 __real_send(clifd, -1);
1074 __real_send(clifd, 0);
1078 __set_reply_handler(ret, pid, clifd, APP_TERM_BY_PID);
1083 int _term_req_app(int pid, int clifd)
1088 if ( (ret = __app_send_raw_with_delay_reply
1089 (pid, APP_TERM_REQ_BY_PID, (unsigned char *)&dummy, sizeof(int))) < 0) {
1090 _D("terminate req send error");
1091 __real_send(clifd, ret);
1095 __set_reply_handler(ret, pid, clifd, APP_TERM_REQ_BY_PID);
1100 int _term_bgapp(int pid, int clifd)
1105 if (app_group_is_leader_pid(pid)) {
1111 app_group_get_group_pids(pid, &cnt, &pids);
1113 status = _status_get_app_info_status(pids[cnt-1]);
1114 if(status == STATUS_BG) {
1115 for (i = cnt-1 ; i>=0; i--) {
1117 _term_sub_app(pids[i]);
1118 app_group_remove(pids[i]);
1126 if ( (fd = __app_send_raw_with_delay_reply
1127 (pid, APP_TERM_BGAPP_BY_PID, (unsigned char *)&dummy, sizeof(int))) < 0) {
1128 _D("terminate packet send error - use SIGKILL");
1129 if (_send_to_sigkill(pid) < 0) {
1130 _E("fail to killing - %d\n", pid);
1131 __real_send(clifd, -1);
1134 __real_send(clifd, 0);
1136 _D("term_bgapp done\n");
1138 __set_reply_handler(fd, pid, clifd, APP_TERM_BGAPP_BY_PID);
1144 #include <sqlite3.h>
1145 static int __launchpad_update_task_managed_field(const char* app_id, int task_managed)
1148 char *sqlite3_error_msg = NULL;
1150 if (sqlite3_open("/opt/dbspace/.pkgmgr_parser.db", &db) != SQLITE_OK) {
1151 _E("sqlite3_open() failed! -> %s\n", sqlite3_errmsg(db));
1155 if (sqlite3_exec(db, "PRAGMA journal_mode = PERSIST", NULL, NULL, &sqlite3_error_msg) != SQLITE_OK) {
1156 _E("sqlite3_exec(\"PRAGMA journal_mode = PERSIST\") failed! -> %s", sqlite3_error_msg);
1157 sqlite3_free(sqlite3_error_msg);
1162 if (sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, &sqlite3_error_msg) != SQLITE_OK) {
1163 _E("sqlite3_exec(\"BEGIN EXCLUSIVE\") failed! -> %s", sqlite3_error_msg);
1164 sqlite3_free(sqlite3_error_msg);
1169 char query[1024] = {0, };
1170 snprintf(query, 1024,"update package_app_info set app_taskmanage='%s' where app_id='%s'",
1171 task_managed ? "true" : "false", app_id);
1173 if (sqlite3_exec(db, query, NULL, NULL, &sqlite3_error_msg) != SQLITE_OK) {
1174 _E("sqlite3_exec(\"%s\") failed! -> %s", query, sqlite3_error_msg);
1175 sqlite3_free(sqlite3_error_msg);
1179 if (sqlite3_exec(db, "COMMIT", NULL, NULL, NULL) != SQLITE_OK) {
1180 _E("sqlite3_exec(\"COMMIT\") failed!");
1181 if (sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL) != SQLITE_OK) {
1182 _E("sqlite3_exec(\"ROLLBACK\") failed!");
1193 static void __pre_launching_processing(const char* app_id)
1195 const char* const PRE_LAUNCHING_LIST_DIR = "/opt/usr/etc/wrt_launchpad_daemon/pre_launching_list";
1197 struct stat file_status;
1198 if (stat(PRE_LAUNCHING_LIST_DIR, &file_status) == 0) {
1199 if (S_ISDIR(file_status.st_mode)) {
1202 struct dirent entry, *result = NULL;
1204 dir = opendir(PRE_LAUNCHING_LIST_DIR);
1207 for (ret = readdir_r(dir, &entry, &result);
1208 result != NULL && ret == 0;
1209 ret = readdir_r(dir, &entry, &result)) {
1210 if (strncmp(entry.d_name, ".", 2) == 0 ||
1211 strncmp(entry.d_name, "..", 3) == 0) {
1215 if (strcmp(entry.d_name, app_id) == 0)
1217 __launchpad_update_task_managed_field(app_id, 1);
1224 _E("opendir(\"%s\") failed!", PRE_LAUNCHING_LIST_DIR);
1230 static int __nofork_processing(int cmd, int pid, bundle * kb, int clifd)
1233 #ifdef _APPFW_FEATURE_CPU_BOOST
1234 const char *operation;
1236 operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__");
1238 //TODO: CPU boosting for relaunching will be removed.
1239 //Home screen requests CPU boosting on launching or relaunching during 200 msec.
1240 if (cmd == APP_OPEN ||
1241 (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/main", 512) == 0)) {
1244 snprintf(val, sizeof(val), "%d", APP_BOOSTING_PERIOD);
1247 ret = invoke_dbus_method_sync(SYSTEM_BUS_NAME, SYSTEM_OBJECT_PATH,
1248 SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, "i", arr);
1249 _D("%s-%s : %d", SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, ret);
1252 _W("__nofork_processing, cmd: %d, pid: %d", cmd, pid);
1256 _D("resume app's pid : %d\n", pid);
1257 if ((ret = _resume_app(pid, clifd)) < 0)
1258 _E("__resume_app failed. error code = %d", ret);
1259 _D("resume app done");
1264 case APP_START_ASYNC:
1265 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
1266 case APP_START_MULTI_INSTANCE:
1268 _D("fake launch pid : %d\n", pid);
1269 if ((ret = _fake_launch_app(cmd, pid, kb, clifd)) < 0)
1270 _E("fake_launch failed. error code = %d", ret);
1271 _D("fake launch done");
1284 __amd_sysman_restore_hz_timer_cb(void *data)
1286 struct context *ctxt = data;
1291 sysman_release_cpu_min_frequency ();
1293 _D("*******[1.6MHZ Support] Released\n " );
1295 return ECORE_CALLBACK_CANCEL; // same as EINA_FALSE
1303 #ifdef _APPFW_FEATURE_FAKE_EFFECT
1304 static void __amd_effect_image_file_set(char *image_file)
1306 Ecore_X_Window root_win;
1308 if(!_window_is_initialized())
1311 root_win = ecore_x_window_root_first_get();
1312 SECURE_LOGD("path : %s", image_file);
1313 ecore_x_window_prop_string_set(root_win, ATOM_IMAGE_EFFECT, image_file);
1317 static void __amd_send_message_to_e17(int screenmode, const char * indicator, int effect_type, int theme)
1319 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:AMD:EFFECT_START");
1320 Ecore_X_Window root_win;
1323 if (!_window_is_initialized()) {
1324 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1328 root_win = ecore_x_window_root_first_get();
1329 _D("root win : %x",root_win);
1330 int screen_orientation[5]={0,0,270,180,90};
1331 if (screenmode > 4 || screenmode < 0)
1334 if (strncmp(indicator, "true", 4) == 0) {
1335 _D("[LAUNCHING EFFECT]: screen mode(%d), effect type(%d), theme(%d), indicator show",
1336 screen_orientation[screenmode], effect_type, theme);
1337 ret = ecore_x_client_message32_send (root_win, ATOM_IMAGE_EFFECT,
1338 ECORE_X_EVENT_MASK_WINDOW_PROPERTY, effect_type,
1339 screen_orientation[screenmode],
1340 SHOW_INDICATOR, theme, 0);
1343 _D("[LAUNCHING EFFECT]: screen mode(%d), effect type(%d), theme(%d), indicator show",
1344 screen_orientation[screenmode], effect_type, theme);
1345 ret = ecore_x_client_message32_send (root_win, ATOM_IMAGE_EFFECT,
1346 ECORE_X_EVENT_MASK_WINDOW_PROPERTY, effect_type,
1347 screen_orientation[screenmode],
1348 HIDE_INDICATOR, theme, 0);
1351 _D("ecore_x_client_message32_send : %d",ret);
1352 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1356 static int append_variant(DBusMessageIter *iter, const char *sig, char *param[])
1361 uint64_t int64_type;
1366 for (ch = (char*)sig, i = 0; *ch != '\0'; ++i, ++ch) {
1369 int_type = atoi(param[i]);
1370 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &int_type);
1373 int_type = atoi(param[i]);
1374 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &int_type);
1377 int64_type = atoi(param[i]);
1378 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT64, &int64_type);
1381 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, param[i]);
1391 int invoke_dbus_method_sync(const char *dest, const char *path,
1392 const char *interface, const char *method,
1393 const char *sig, char *param[])
1396 DBusMessageIter iter;
1401 msg = dbus_message_new_method_call(dest, path, interface, method);
1403 _E("dbus_message_new_method_call(%s:%s-%s)", path, interface, method);
1408 dbus_message_iter_init_append(msg, &iter);
1409 r = append_variant(&iter, sig, param);
1411 _E("append_variant error(%d)", r);
1412 dbus_message_unref(msg);
1417 dbus_error_init(&err);
1419 reply = dbus_connection_send_with_reply_and_block(conn, msg, 500, &err);
1420 dbus_message_unref(msg);
1422 _E("dbus_connection_send error(%s:%s)", err.name, err.message);
1423 dbus_error_free(&err);
1427 r = dbus_message_get_args(reply, &err, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
1428 dbus_message_unref(reply);
1430 _E("no message : [%s:%s]", err.name, err.message);
1431 dbus_error_free(&err);
1438 #ifdef _APPFW_FEATURE_AMD_KEY
1439 static gboolean __grab_timeout_handler(gpointer data)
1441 int pid = (int) data;
1443 if(_input_window_get() != 0)
1444 ecore_x_pointer_ungrab();
1445 _D("pid(%d) ecore_x_pointer_ungrab", pid);
1446 if(_key_ungrab(KEY_BACK) < 0) {
1447 _W("back key ungrab error");
1449 _D("back key ungrab");
1456 static gboolean __fg_timeout_handler(gpointer data)
1458 struct fgmgr *fg = data;
1463 _status_update_app_info_list(fg->pid, STATUS_BG, TRUE);
1465 _fgmgr_list = g_list_remove(_fgmgr_list, fg);
1471 static void __add_fgmgr_list(int pid)
1475 fg = calloc(1, sizeof(struct fgmgr));
1480 fg->tid = g_timeout_add(5000, __fg_timeout_handler, fg);
1482 _fgmgr_list = g_list_append(_fgmgr_list, fg);
1485 static void __del_fgmgr_list(int pid)
1493 for (iter = _fgmgr_list; iter != NULL; iter = g_list_next(iter)) {
1494 fg = (struct fgmgr *)iter->data;
1495 if (fg->pid == pid) {
1496 g_source_remove(fg->tid);
1497 _fgmgr_list = g_list_remove(_fgmgr_list, fg);
1504 #ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
1505 static int __tep_mount(char *mnt_path[])
1510 struct stat link_buf = {0,};
1512 rv = lstat(mnt_path[0], &link_buf);
1514 rv = unlink(mnt_path[0]);
1516 _E("Unable tp remove link file %s", mnt_path[0]);
1519 msg = dbus_message_new_method_call(TEP_BUS_NAME, TEP_OBJECT_PATH,
1520 TEP_INTERFACE_NAME, TEP_MOUNT_METHOD);
1522 _E("dbus_message_new_method_call(%s:%s-%s)", TEP_OBJECT_PATH,
1523 TEP_INTERFACE_NAME, TEP_MOUNT_METHOD);
1527 if (!dbus_message_append_args(msg,
1528 DBUS_TYPE_STRING, &mnt_path[0],
1529 DBUS_TYPE_STRING, &mnt_path[1],
1530 DBUS_TYPE_INVALID)) {
1531 _E("Ran out of memory while constructing args\n");
1536 if (dbus_connection_send(conn, msg, NULL) == FALSE) {
1537 _E("dbus_connection_send error");
1542 dbus_message_unref(msg);
1546 static void __send_mount_request(const struct appinfo *ai, const char *tep_name,
1549 SECURE_LOGD("tep name is: %s", tep_name);
1550 char *mnt_path[2] = {NULL, };
1551 const char *installed_storage = NULL;
1552 char tep_path[PATH_MAX] = {0, };
1554 const char *pkgid = appinfo_get_value(ai, AIT_PKGID);
1555 installed_storage = appinfo_get_value(ai, AIT_STORAGE_TYPE);
1556 if (installed_storage != NULL) {
1557 SECURE_LOGD("storage: %s", installed_storage);
1558 if (strncmp(installed_storage, "internal", 8) == 0) {
1559 snprintf(tep_path, PATH_MAX, "%s%s/res/%s", appfw_env_get_apps_path(), pkgid,
1561 mnt_path[1] = strdup(tep_path);
1562 snprintf(tep_path, PATH_MAX, "%s%s/res/tep", appfw_env_get_apps_path(), pkgid);
1563 mnt_path[0] = strdup(tep_path);
1564 } else if (strncmp(installed_storage, "external", 8) == 0) {
1565 snprintf(tep_path, PATH_MAX, "%step/%s", appfw_env_get_external_storage_path(),
1567 mnt_path[1] = strdup(tep_path);
1568 snprintf(tep_path, PATH_MAX, "%step/tep-access",
1569 appfw_env_get_external_storage_path()); /* TODO : keeping tep/tep-access for now for external storage */
1570 mnt_path[0] = strdup(tep_path);
1573 if (mnt_path[0] && mnt_path[1]) {
1574 bundle_add(kb, AUL_TEP_PATH, mnt_path[0]);
1576 ret = aul_is_tep_mount_dbus_done(mnt_path[0]);
1578 ret = __tep_mount(mnt_path);
1580 _E("dbus error %d", ret);
1591 static int __check_app_control_privilege(const char *operation, int caller_pid, const struct appinfo *caller)
1594 const char *api_ver;
1596 if (caller == NULL) // daemon
1599 if (operation == NULL || caller_pid < 1)
1602 if (strcmp(operation, AUL_SVC_OPERATION_DOWNLOAD) == 0) {
1603 api_ver = appinfo_get_value(caller, AIT_API_VER);
1606 _E("failed to get api version");
1610 if (api_ver && strverscmp("2.4", api_ver) < 1) { // ver 2.4 or later
1611 ret = security_server_check_privilege_by_pid(caller_pid, "privilege::tizen::download", "rw");
1612 if (ret != SECURITY_SERVER_API_SUCCESS) {
1613 _E("caller %d violates http://tizen.org/privilege/download privilege (%d)", caller_pid, ret);
1614 return -EILLEGALACCESS;
1617 } else if (strcmp(operation, AUL_SVC_OPERATION_CALL) == 0) {
1618 // Check the privilege for call operation
1619 ret = security_server_check_privilege_by_pid(caller_pid, "privilege::tizen::call", "rw");
1620 if (ret != SECURITY_SERVER_API_SUCCESS) {
1621 _E("caller %d violates http://tizen.org/privilege/call privilege (%d)", caller_pid, ret);
1622 return -EILLEGALACCESS;
1630 int __check_mode(const struct appinfo *ai)
1632 #ifdef _APPFW_FEATURE_TTS_MODE
1634 const char *tts_support = NULL;
1636 #ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
1640 #ifdef _APPFW_FEATURE_TTS_MODE
1641 vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &tts_mode);
1643 tts_support = appinfo_get_value(ai, AIT_TTS);
1644 _W("tts : %d %s", tts_mode, tts_support);
1645 if(strncmp(tts_support, "false", 5) == 0) {
1646 _W("Cannot launch this app in TTS mode");
1652 #ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
1653 vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &ups_mode);
1654 if (ups_mode == SETTING_PSMODE_EMERGENCY) {
1655 const char *ups_support = appinfo_get_value(ai, AIT_UPS);
1656 _W("ups : %d %s", ups_mode, ups_support);
1658 #endif //_APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
1663 static void __prepare_to_suspend_services(int pid)
1666 SECURE_LOGD("[__SUSPEND__] pid: %d", pid);
1667 __app_send_raw_with_noreply(pid, APP_SUSPEND, (unsigned char *)&dummy, sizeof(int));
1670 static void __prepare_to_wake_services(int pid)
1673 SECURE_LOGD("[__SUSPEND__] pid: %d", pid);
1674 __app_send_raw_with_noreply(pid, APP_WAKE, (unsigned char *)&dummy, sizeof(int));
1677 static gboolean __check_service_only(gpointer user_data)
1679 int pid = GPOINTER_TO_INT(user_data);
1680 SECURE_LOGD("[__SUSPEND__] pid :%d", pid);
1682 _status_check_service_only(pid, __prepare_to_suspend_services);
1687 #ifdef _APPFW_FEATURE_PRIVATE_SERVICE
1688 static int __get_visibility_from_cert_svc(const char *pkgid, int *visibility)
1691 const char *cert_value = NULL;
1692 pkgmgrinfo_certinfo_h certinfo = NULL;
1694 ret = pkgmgrinfo_pkginfo_create_certinfo(&certinfo);
1696 _E("pkgmgrinfo_pkginfo_create_certinfo() failed.");
1700 ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, certinfo);
1702 _E("pkgmgrinfo_pkginfo_load_certinfo() failed.");
1707 ret = pkgmgrinfo_pkginfo_get_cert_value(certinfo, PMINFO_DISTRIBUTOR_ROOT_CERT,
1709 if (ret != 0 || cert_value == NULL) {
1710 _E("pkgmgrinfo_pkginfo_get_cert_value() failed.");
1715 ret = cert_svc_get_visibility_by_root_certificate(cert_value,
1716 strlen(cert_value), visibility);
1718 _E("cert_svc_get_visibility_by_root_cert() failed. err = [%d]", ret);
1722 _D("visibility = [%d]", *visibility);
1725 pkgmgrinfo_pkginfo_destroy_certinfo(certinfo);
1730 static int __can_share(const char *path, const char *pkgid)
1732 struct stat path_stat;
1734 if (access(path, F_OK) != 0)
1737 if (stat(path, &path_stat) != 0)
1740 if (!S_ISREG(path_stat.st_mode))
1745 snprintf(buf, sizeof(buf) - 1, "/opt/usr/apps/%s/data/", pkgid);
1746 if (strncmp(path, buf, strlen(buf)) != 0)
1752 static int __get_current_security_attribute(int pid, char *buf, int size)
1756 char path[1024] = { 0, };
1758 snprintf(path, sizeof(path) - 1, "/proc/%d/attr/current", pid);
1759 fd = open(path, O_RDONLY);
1763 ret = read(fd, buf, size - 1);
1775 static int __get_exec_label_by_pid(int pid, char** exec_label)
1777 const char *appid = NULL;
1778 const char *exec = NULL;
1779 const char *type = NULL;
1780 const struct appinfo *ai = NULL;
1781 char attr[1024] = { 0, };
1783 if (__get_current_security_attribute(pid, attr, sizeof(attr)) == 0) {
1784 *exec_label = strdup(attr);
1788 appid = _status_app_get_appid_bypid(pid);
1790 ai = appinfo_find(_laf, appid);
1791 exec = appinfo_get_value(ai, AIT_EXEC);
1792 type = appinfo_get_value(ai, AIT_TYPE);
1795 if (strcmp("wgt", type) == 0) {
1796 if (smack_lgetlabel(exec, exec_label, SMACK_LABEL_EXEC) == 0)
1799 if (smack_getlabel(exec, exec_label, SMACK_LABEL_EXEC) == 0)
1808 static int __get_exec_label_by_appid(const char *appid, char** exec_label)
1810 const char *exec = NULL;
1811 const char *type = NULL;
1812 const struct appinfo *ai = NULL;
1815 ai = appinfo_find(_laf, appid);
1816 exec = appinfo_get_value(ai, AIT_EXEC);
1817 type = appinfo_get_value(ai, AIT_TYPE);
1820 if (strcmp("wgt", type) == 0) {
1821 if (smack_lgetlabel(exec, exec_label, SMACK_LABEL_EXEC) == 0)
1824 if (smack_getlabel(exec, exec_label, SMACK_LABEL_EXEC) == 0)
1833 static int __get_owner_pid(int caller_pid, bundle *kb)
1835 char *org_caller = NULL;
1837 if (bundle_get_str(kb, AUL_K_ORG_CALLER_PID, &org_caller) == BUNDLE_ERROR_NONE) {
1838 int org_caller_pid = atoi(org_caller);
1839 char *c_exec_label = NULL;
1841 if (__get_exec_label_by_pid(caller_pid, &c_exec_label) == 0) {
1844 (strcmp(APP_SELECTOR, c_exec_label) == 0 ||
1845 strcmp(SHARE_PANEL, c_exec_label) == 0))
1846 caller_pid = org_caller_pid;
1856 static int __get_exec_label(char **caller_exec_label, char **callee_exec_label,
1857 int caller_pid, const char *appid)
1859 char *label_caller = NULL;
1862 if (__get_exec_label_by_pid(caller_pid, &label_caller) != 0) {
1866 if (__get_exec_label_by_appid(appid, &label) != 0) {
1871 *caller_exec_label = label_caller;
1872 *callee_exec_label = label;
1876 static int __grant_temporary_permission(int caller_pid, const char *appid, bundle *kb,
1877 char **out_caller_exec_label, char **out_callee_exec_label,
1880 int type = bundle_get_type(kb, AUL_SVC_DATA_PATH);
1882 const char **path_array = NULL;
1884 char *caller_exec_label = NULL;
1885 char *callee_exec_label = NULL;
1887 char **paths = NULL;
1890 const char *tmp_appid = NULL;
1891 const char *pkgid = NULL;
1892 const struct appinfo *ai = NULL;
1895 case BUNDLE_TYPE_STR:
1896 bundle_get_str(kb, AUL_SVC_DATA_PATH, &path);
1899 _E("path was null");
1903 owner_pid = __get_owner_pid(caller_pid, kb);
1904 owner_pid = getpgid(owner_pid); /* for webapp */
1905 tmp_appid = _status_app_get_appid_bypid(owner_pid);
1907 ai = appinfo_find(_laf, tmp_appid);
1908 pkgid = appinfo_get_value(ai, AIT_PKGID);
1910 if (__can_share(path, pkgid) != 0) {
1911 _E("__can_share() returned an error");
1915 if (__get_exec_label(&caller_exec_label, &callee_exec_label, owner_pid,
1917 _E("__get_exec_label() returned an error");
1921 paths = (char**)malloc(sizeof(char*) * 3);
1923 _E("Out of memory");
1927 paths[0] = strdup(path);
1933 case BUNDLE_TYPE_STR_ARRAY:
1934 path_array = bundle_get_str_array(kb, AUL_SVC_DATA_PATH, &len);
1935 if (!path_array || len <= 0) {
1936 _E("path_array was null");
1940 owner_pid = __get_owner_pid(caller_pid, kb);
1941 owner_pid = getpgid(owner_pid); /* for webapp */
1942 tmp_appid = _status_app_get_appid_bypid(owner_pid);
1943 ai = appinfo_find(_laf, tmp_appid);
1944 pkgid = appinfo_get_value(ai, AIT_PKGID);
1946 if (__get_exec_label(&caller_exec_label, &callee_exec_label, owner_pid,
1948 _E("__get_exec_label() returned an error");
1952 paths = (char**)malloc(sizeof(char*) * (len + 2));
1954 _E("Out of memory");
1959 for (i = 0; i < len; i++) {
1960 if (__can_share(path_array[i], pkgid) == 0) {
1961 paths[cnt++] = strdup(path_array[i]);
1966 paths[cnt + 1] = NULL;
1976 if (bundle_get_str(kb, AUL_SVC_K_URI, &path) == BUNDLE_ERROR_NONE) {
1978 _E("path was null");
1982 if (strncmp(path, "file://", 7) == 0)
1985 _E("file wasn't started with file://");
1989 if (owner_pid == -1) {
1990 owner_pid = __get_owner_pid(caller_pid, kb);
1991 owner_pid = getpgid(owner_pid); /* for webapp */
1994 tmp_appid = _status_app_get_appid_bypid(owner_pid);
1995 ai = appinfo_find(_laf, tmp_appid);
1996 pkgid = appinfo_get_value(ai, AIT_PKGID);
1998 if (__can_share(path, pkgid) != 0) {
1999 _E("__can_share() returned an error");
2003 if (!caller_exec_label && !callee_exec_label)
2004 if (__get_exec_label(&caller_exec_label, &callee_exec_label, owner_pid,
2006 _E("__get_exec_label() returned an error");
2011 paths = (char**)malloc(sizeof(char*) * 2);
2013 _E("Out of memory");
2017 paths[0] = strdup(path);
2022 if (paths[i] == NULL) {
2023 paths[i] = strdup(path);
2032 if (ret == 0 && caller_exec_label && paths) {
2033 _D("grant permission %s : %s : %s", paths[0], caller_exec_label,
2035 int r = security_server_perm_apply_sharing(NULL, (const char**)paths, caller_exec_label, callee_exec_label);
2036 if (r != SECURITY_SERVER_API_SUCCESS) {
2037 _E("security_server_perm_apply_sharing() returned an error %d",r);
2040 *out_caller_exec_label = caller_exec_label;
2041 *out_callee_exec_label = callee_exec_label;
2044 caller_exec_label = NULL;
2045 callee_exec_label = NULL;
2050 if (caller_exec_label)
2051 free(caller_exec_label);
2052 if (callee_exec_label)
2053 free(callee_exec_label);
2057 if (paths[i] == NULL) {
2068 static void __add_shared_info(int pid, const char *caller_exec_label, const char *callee_exec_label, char **paths)
2070 _status_set_exec_label(pid, callee_exec_label);
2071 _status_add_shared_info(pid, caller_exec_label, paths);
2074 #ifdef _APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP
2075 #ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
2076 static void __check_home_app(int pid)
2078 const char *home_app = _get_home_appid();
2079 const char *appid = NULL;
2081 if (home_app == NULL)
2084 appid = _status_app_get_appid_bypid(pid);
2086 if (appid && strcmp(appid, home_app) == 0) {
2090 const char *taskmanage = NULL;
2091 const struct appinfo *ai = NULL;
2092 const char* bg = NULL;
2094 app_group_get_leader_pids(&cnt, &pids);
2096 for (i = 0; i < cnt; ++i) {
2097 appid = _status_app_get_appid_bypid(pids[i]);
2098 if (appid == NULL || strcmp(appid, home_app) == 0)
2101 ai = appinfo_find(_laf, appid);
2102 taskmanage = appinfo_get_value(ai, AIT_TASKMANAGE);
2103 bg = appinfo_get_value(ai, AIT_ALLOWED_BG);
2105 if (taskmanage && strcmp("false", taskmanage) == 0
2106 && bg && strcmp("NONE", bg) == 0) {
2107 int st = _status_get_app_info_status(pids[i]);
2108 if (st != STATUS_DYING) {
2109 _W("terminate %d %s %d", pids[i], appid, st);
2110 aul_update_freezer_status(pids[i], "wakeup");
2111 _term_sub_app(pids[i]);
2123 int _revoke_temporary_permission(int pid)
2125 GList *list = _status_get_shared_info_list(pid);
2126 const char *callee_label = _status_get_exec_label(pid);
2128 if (!list || !callee_label) {
2129 _E("list or callee_label was null");
2134 shared_info_t *sit = (shared_info_t*)list->data;
2136 _D("revoke permission %s : %s", sit->owner_exec_label, callee_label);
2137 int r = security_server_perm_drop_sharing(NULL, (const char**)sit->paths,
2138 sit->owner_exec_label, callee_label);
2140 if (r != SECURITY_SERVER_API_SUCCESS)
2141 _E("revoke error %d",r);
2143 list = g_list_next(list);
2145 return _status_clear_shared_info_list(pid);
2148 int _start_app(const char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_uid, int fd)
2150 const struct appinfo *ai;
2151 const struct appinfo *caller_ai;
2153 const char *multiple = NULL;
2154 const char *app_path = NULL;
2155 const char *pkg_type = NULL;
2156 const char *component_type = NULL;
2158 char tmp_pid[MAX_PID_STR_BUFSZ];
2159 const char *permission;
2161 const char *preload;
2162 const char *pkg_status;
2163 const char *operation;
2164 char caller_appid[256] = {0,};
2165 char* caller = NULL;
2166 char* old_caller = NULL;
2167 pkgmgrinfo_cert_compare_result_type_e compare_result;
2168 int delay_reply = 0;
2169 int pad_pid = NO_LAUNCHPAD_PID;
2172 char trm_buf[MAX_PACKAGE_STR_SIZE];
2173 gboolean is_group_app = FALSE;
2174 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2175 char log_status[AUL_PR_NAME] = {0,};
2178 #ifdef _APPFW_FEATURE_FAKE_EFFECT
2179 const char *fake_effect;
2180 int effect_mode = 0;
2181 #ifdef _APPFW_FEATURE_WMS_CONNECTION_CHECK
2182 int wmanager_connected = 0;
2185 #endif /* _APPFW_FEATURE_FAKE_EFFECT */
2187 #ifdef _APPFW_FEATURE_AMD_KEY
2188 const char *caller_component_type = NULL;
2190 int prelaunch_attribute = 0;
2192 bool bg_allowed = false;
2194 gboolean can_attach;
2195 app_group_launch_mode launch_mode;
2196 char *caller_exec_label = NULL;
2197 char *callee_exec_label = NULL;
2198 char **paths = NULL;
2199 int grant_permission = 0;
2201 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:AMD:START_APP");
2202 if (appid == NULL || kb == NULL
2203 || caller_pid < 0 || fd < 0) {
2204 _D("invalid parameter");
2206 __real_send(fd, -1);
2207 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2211 snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", caller_pid);
2212 bundle_add(kb, AUL_K_CALLER_PID, tmp_pid);
2214 if (cmd == APP_START_RES)
2215 bundle_add(kb, AUL_K_WAIT_RESULT, "1");
2217 caller = _status_app_get_appid_bypid(caller_pid);
2218 if(caller == NULL) {
2219 ret = aul_app_get_appid_bypid(caller_pid, caller_appid, sizeof(caller_appid));
2221 bundle_add(kb, AUL_K_CALLER_APPID, caller_appid);
2222 caller = caller_appid;
2224 _E("no caller appid info, ret: %d", ret);
2227 bundle_add(kb, AUL_K_CALLER_APPID, caller);
2231 SECURE_LOGW("caller appid : %s", caller);
2233 _W("caller pid : %d", caller_pid);
2235 ai = appinfo_find(_laf, appid);
2238 __real_send(fd, -ENOAPP);
2239 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2242 pkg_status = appinfo_get_value(ai, AIT_STATUS);
2243 if(pkg_status && (strncmp(pkg_status, "blocking", 8) == 0 || strncmp(pkg_status, "restart", 7) == 0) ) {
2245 __real_send(fd, -EREJECTED);
2246 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2248 } else if(pkg_status && strncmp(pkg_status, "unmounted", 9) == 0 ) {
2250 __real_send(fd, -1);
2251 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2256 app_path = appinfo_get_value(ai, AIT_EXEC);
2257 pkg_type = appinfo_get_value(ai, AIT_TYPE);
2258 permission = appinfo_get_value(ai, AIT_PERM);
2259 pkgid = appinfo_get_value(ai, AIT_PKGID);
2260 component_type = appinfo_get_value(ai, AIT_COMPTYPE);
2262 if (pkg_type == NULL)
2263 pkg_type = "unknown";
2265 #ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
2266 const char *tep_name = NULL;
2268 tep_name = appinfo_get_value(ai, AIT_TEP);
2269 if (tep_name != NULL) {
2270 __send_mount_request(ai, tep_name, kb);
2273 operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__");
2274 caller_ai = appinfo_find(_laf, caller);
2275 #ifdef _APPFW_FEATURE_AMD_KEY
2276 caller_component_type = appinfo_get_value(caller_ai, AIT_COMPTYPE);
2279 if(permission && strncmp(permission, "signature", 9) == 0 ) {
2280 if(caller_uid != 0 && (cmd == APP_START
2281 || cmd == APP_START_RES
2282 || cmd == APP_START_ASYNC
2283 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
2284 || cmd == APP_START_MULTI_INSTANCE
2288 preload = appinfo_get_value(caller_ai, AIT_PRELOAD);
2289 if( preload && strncmp(preload, "true", 4) != 0 ) {
2290 ret = pkgmgrinfo_pkginfo_compare_app_cert_info(caller, appid, &compare_result);
2291 if (ret != PMINFO_R_OK) {
2293 _E("compare app cert info failed : %d", ret);
2294 if(cmd == APP_START_ASYNC)
2297 __real_send(fd, pid);
2298 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2301 if(compare_result != PMINFO_CERT_COMPARE_MATCH) {
2302 pid = -EILLEGALACCESS;
2303 if(cmd == APP_START_ASYNC)
2306 __real_send(fd, pid);
2307 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2314 if(operation && caller_ai) {
2315 ret = __check_app_control_privilege(operation, caller_pid, caller_ai);
2317 if (cmd == APP_START_ASYNC)
2320 __real_send(fd, ret);
2321 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2326 if(__check_mode(ai) < 0) {
2328 if(cmd == APP_START_ASYNC)
2331 __real_send(fd, pid);
2332 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2336 pkgmgrinfo_client_request_enable_external_pkg((char *)pkgid);
2338 if (component_type && (strncmp(component_type, APP_TYPE_UI, strlen(APP_TYPE_UI)) == 0
2339 || strncmp(component_type, APP_TYPE_WATCH, strlen(APP_TYPE_WATCH)) == 0
2340 || strncmp(component_type, APP_TYPE_WIDGET, strlen(APP_TYPE_WIDGET)) == 0 )) {
2341 gboolean new_process = FALSE;
2343 multiple = appinfo_get_value(ai, AIT_MULTI);
2344 if (!multiple || strncmp(multiple, "false", 5) == 0) {
2345 pid = _status_app_is_running_v2(appid);
2346 } else if (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/view", 512) == 0){
2347 old_caller = _status_get_caller_by_appid(appid);
2348 if(old_caller && caller) {
2349 if(strncmp(old_caller, caller, MAX_PACKAGE_STR_SIZE) == 0) {
2350 pid = _status_app_is_running_v2(appid);
2355 if (strncmp(component_type, APP_TYPE_UI, strlen(APP_TYPE_UI)) == 0) {
2356 if (app_group_is_group_app(kb)) {
2358 is_group_app = TRUE;
2364 st = _status_get_app_info_status(pid);
2366 if (pid == -1 || st == STATUS_DYING) {
2368 int found_lpid = -1;
2370 if (app_group_find_singleton(appid, &found_pid, &found_lpid) == 0) {
2372 new_process = FALSE;
2377 if (app_group_can_start_app(appid, kb, &can_attach, &lpid, &launch_mode) != 0 ) {
2378 _E("can't make group info");
2379 pid = -EILLEGALACCESS;
2380 if (cmd == APP_START_ASYNC)
2383 __real_send(fd, pid);
2384 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2388 if (can_attach && lpid == found_lpid) {
2389 _E("can't launch singleton app in the same group");
2390 pid = -EILLEGALACCESS;
2391 if (cmd == APP_START_ASYNC)
2394 __real_send(fd, pid);
2395 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2399 if (found_pid != -1) {
2400 _W("app_group_clear_top, pid: %d", found_pid);
2401 app_group_clear_top(found_pid);
2405 if (pid == -1 && can_attach)
2406 pid = app_group_find_pid_from_recycle_bin(appid);
2409 #ifdef _APPFW_FEATURE_APP_CONTROL_LITE
2410 char app_path_link[512] = {0,};
2411 const char *caller_app_path = NULL;
2412 char caller_app_path_link[512] = {0,};
2414 caller_app_path = appinfo_get_value(caller_ai, AIT_EXEC);
2416 SECURE_LOGD("callee path(%s) caller path(%s)", app_path, caller_app_path);
2418 readlink(app_path, app_path_link, 512);
2419 readlink(caller_app_path, caller_app_path_link, 512);
2421 SECURE_LOGD("callee link(%s) caller link(%s)", app_path_link, caller_app_path_link);
2423 if(strncmp(app_path_link, "/usr/bin/ug-client", 512) == 0) {
2424 if (strcmp(caller, "org.tizen.app-selector") == 0){
2425 pid = atoi(bundle_get_val(kb,AUL_K_ORG_CALLER_PID));
2426 bundle_add(kb, "__AUL_UG_EXEC__", app_path);
2427 SECURE_LOGD("app_path : %s , ug id(%s)", app_path, bundle_get_val(kb, "__AUL_UG_ID__"));
2428 } else if(strncmp(caller_app_path_link, "/usr/bin/ug-client", 512) == 0) {
2429 __real_send(fd, -EUGLOCAL_LAUNCH);
2430 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2437 #ifdef _APPFW_FEATURE_AMD_KEY
2438 if (caller_component_type && strncmp(caller_component_type, APP_TYPE_UI, strlen(APP_TYPE_UI)) == 0) {
2439 Ecore_X_Window in_win;
2440 in_win = _input_window_get();
2442 ret = ecore_x_pointer_grab(in_win);
2443 _D("win(%x) ecore_x_pointer_grab(%d)", in_win, ret);
2445 if(_key_grab(KEY_BACK, EXCLUSIVE_GRAB) < 0) {
2446 _W("back key grab error");
2448 _D("back key grab");
2454 if (__grant_temporary_permission(caller_pid, appid, kb,
2455 &caller_exec_label, &callee_exec_label, &paths) == 0)
2456 grant_permission = 1;
2458 status = _status_get_app_info_status(pid);
2459 if (pid > 0 && status != STATUS_DYING) {
2460 if (caller_pid == pid) {
2461 SECURE_LOGD("caller process & callee process is same.[%s:%d]", appid, pid);
2462 pid = -ELOCALLAUNCH_ID;
2464 if(strncmp(pkg_type, "wgt", 3) == 0) {
2465 __pre_launching_processing(appid);
2468 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2469 strncpy(log_status, "RESUMING", strlen("RESUMING"));
2472 proc_group_change_status(PROC_CGROUP_SET_RESUME_REQUEST, pid, (char *)appid);
2474 if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) {
2480 } else if (cmd != APP_RESUME) {
2481 if(status == STATUS_DYING && pid > 0) {
2482 r = kill(pid, SIGKILL);
2484 _D("send SIGKILL: %s", strerror(errno));
2487 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2488 strncpy(log_status, "LAUNCHING", strlen("LAUNCHING"));
2491 // 2.4 bg categorized ui app || watch || widget -> bg allowed (2.3 ui app -> not allowed)
2492 prelaunch_attribute = __get_prelaunch_attribute(ai);
2493 if ((strncmp(component_type, APP_TYPE_UI, sizeof(APP_TYPE_UI)) == 0
2494 && (prelaunch_attribute & RESOURCED_ALLOWED_BG_ATTRIBUTE))
2495 || (strncmp(component_type, APP_TYPE_WATCH, sizeof(APP_TYPE_WATCH)) == 0)
2496 || (strncmp(component_type, APP_TYPE_WIDGET, sizeof(APP_TYPE_WIDGET)) == 0)) {
2497 _D("[__SUSPEND__] allowed background, appid: %s", appid);
2498 bundle_add(kb, AUL_K_ALLOWED_BG, "ALLOWED_BG");
2501 __send_proc_prelaunch_signal(appid, pkgid, prelaunch_attribute);
2503 #ifdef _APPFW_FEATURE_FAKE_EFFECT
2504 fake_effect = bundle_get_val(kb, "__FAKE_EFFECT__");
2507 #ifdef _APPFW_FEATURE_CPU_BOOST
2508 if (cmd == APP_OPEN || operation != NULL ||
2509 (caller != NULL && strcmp(caller, "org.tizen.wnotification2") == 0) ||
2510 (caller != NULL && strcmp(caller, "org.tizen.wnotiboard-popup") == 0)) {
2513 snprintf(val, sizeof(val), "%d", APP_BOOSTING_PERIOD);
2516 ret = invoke_dbus_method_sync(SYSTEM_BUS_NAME, SYSTEM_OBJECT_PATH,
2517 SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, "i", arr);
2518 _D("%s-%s : %d", SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, ret);
2522 #ifdef _APPFW_FEATURE_FAKE_EFFECT
2525 * default mode : fake effect off, 1.6 MHZ off
2527 * full mode : fake effect on, 1.6 MHZ on
2529 * fake effect mode : fake effect on, 1.6 MHZ off
2531 * 1.6 MHZ mode : faek effect off, 1.6MHZ on
2534 vconf_get_int(VCONFKEY_AMD_EFFECT_IMAGE_ENABLE, &effect_mode);
2535 #ifdef _APPFW_FEATURE_WMS_CONNECTION_CHECK
2536 vconf_get_bool(VCONFKEY_WMS_WMANAGER_CONNECTED, &wmanager_connected);
2538 //_D("*******[effect_mode] Mode : %d\n ", effect_mode );
2540 if ( ( cmd == APP_OPEN ||
2541 ( (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/main", 512) == 0)
2542 && !(fake_effect != NULL && strncmp(fake_effect, "OFF", 3) == 0) )
2543 ) && (effect_mode == 1 || effect_mode == 2)
2544 #ifdef _APPFW_FEATURE_WMS_CONNECTION_CHECK
2545 && wmanager_connected == true
2548 char image_filename[256] = {0,};
2549 const char *portraitimg = NULL;
2550 const char *landscapeimg = NULL;
2551 #ifdef _APPFW_FEATURE_CHANGEABLE_COLOR
2552 const char *effectimg_type = NULL;
2554 const char *indicator = NULL;
2555 int screen_mode = 0;
2556 int rotate_allowed = 0;
2560 //vconf_get_int(PHONE_ORIENTATION_MODE, &screen_mode);
2561 screen_mode = invoke_dbus_method_sync(ROTATION_BUS_NAME, ROTATION_OBJECT_PATH,
2562 ROTATION_INTERFACE_NAME, ROTATION_METHOD_NAME, "i", NULL);
2563 _D("%s-%s : %d", ROTATION_INTERFACE_NAME, ROTATION_METHOD_NAME, screen_mode);
2564 vconf_get_bool(PHONE_ROTATE_LOCK, &rotate_allowed); /*TODO: use vconf_notify_key_changed()*/
2565 portraitimg = appinfo_get_value(ai, AIT_EFFECTIMAGEPORT);
2566 landscapeimg = appinfo_get_value(ai, AIT_EFFECTIMAGELAND);
2567 #ifdef _APPFW_FEATURE_CHANGEABLE_COLOR
2568 effectimg_type = appinfo_get_value(ai, AIT_EFFECTTYPE);
2570 indicator = appinfo_get_value(ai, AIT_INDICATOR_DISP);
2571 /*Currently we assume apps supporting launching effect supports portrait mode*/
2572 if (indicator && portraitimg) {
2573 if (rotate_allowed == false) {
2576 if ((screen_mode == 2 || screen_mode == 4) && (rotate_allowed == true)) {
2577 /*if there is no landscape image, that means app supports only portrait mode.*/
2579 snprintf(image_filename, 255, "%s", landscapeimg);
2582 snprintf(image_filename, 255, "%s", portraitimg);
2584 if (access(image_filename, R_OK) == 0) {
2585 #ifdef _APPFW_FEATURE_CHANGEABLE_COLOR
2586 if(strncmp(effectimg_type, "edj-dark", strlen(effectimg_type)) == 0) {
2589 } else if (strncmp(effectimg_type, "edj-light", strlen(effectimg_type)) == 0) {
2592 } else if (strncmp(effectimg_type, "edj-default", strlen(effectimg_type)) == 0) {
2603 r = snprintf(xml_filename, 255, "/usr/apps/%s/shared/res/tables/%s_ChangeableColorInfo.xml", pkgid, pkgid);
2604 if (access(xml_filename, R_OK) == 0) {
2605 //snprintf(image_filename, 255, "%s:%s", image_filename, xml_filename);
2606 strcat(image_filename, ":");
2607 strcat(image_filename, xml_filename);
2610 r = snprintf(xml_filename, 255, "/opt/usr/apps/%s/shared/res/tables/%s_ChangeableColorInfo.xml", pkgid, pkgid);
2611 if (access(xml_filename, R_OK) == 0) {
2612 //snprintf(image_filename, 255, "%s:%s", image_filename, xml_filename);
2613 strcat(image_filename, ":");
2614 strcat(image_filename, xml_filename);
2619 #ifndef _APPFW_FEATURE_DEFAULT_FAKE_IMAGE
2620 __amd_effect_image_file_set(image_filename);
2622 if(file_type == 1) {
2623 __amd_effect_image_file_set("/usr/share/splash_images/type0_portrait.bmp");
2625 __amd_effect_image_file_set(image_filename);
2628 __amd_send_message_to_e17(screen_mode, indicator, file_type, theme);
2632 #endif /* _APPFW_FEATURE_FAKE_EFFECT */
2634 #ifdef _APPFW_FEATURE_DEBUG_LAUNCHPAD
2635 if (bundle_get_type(kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) {
2636 pad_pid = DEBUG_LAUNCHPAD_PID;
2637 } else if (strncmp(pkg_type, "wgt", 3) == 0) {
2638 pad_pid = WEB_LAUNCHPAD_PID;
2641 if (strncmp(pkg_type, "wgt", 3) == 0) {
2642 pad_pid = WEB_LAUNCHPAD_PID;
2645 #ifdef _APPFW_FEATURE_PROCESS_POOL
2647 const char *process_pool = appinfo_get_value(ai, AIT_POOL);
2648 _D("process_pool: %s", process_pool);
2650 const char *hwacc = appinfo_get_value(ai, AIT_HWACC);
2651 _D("h/w acceleration: %s", hwacc);
2653 SECURE_LOGD("appid: %s", appid);
2655 pad_pid = PROCESS_POOL_LAUNCHPAD_PID;
2656 char pad_sock[UNIX_PATH_MAX] = { 0, };
2657 snprintf(pad_sock, UNIX_PATH_MAX, "%s/%d", AUL_SOCK_PREFIX, pad_pid);
2658 if (access(pad_sock, F_OK) != 0)
2660 _W("Sending to legacy launchpad because process-pool launchpad is not initialized.");
2661 pad_pid = NO_LAUNCHPAD_PID;
2664 #endif //_APPFW_FEATURE_PROCESS_POOL
2665 _W("pad pid(%d)", pad_pid);
2666 __set_appinfo_for_launchpad(ai, kb);
2667 if (pad_pid == NO_LAUNCHPAD_PID)
2669 pid = start_process(appid, app_path, kb);
2673 pid = app_send_cmd(pad_pid, cmd, kb);
2674 if (pid == AUL_R_ENOLAUNCHPAD && pad_pid == PROCESS_POOL_LAUNCHPAD_PID) {
2675 _W("Launch with legacy way");
2676 pad_pid = NO_LAUNCHPAD_PID;
2677 pid = start_process(appid, app_path, kb);
2680 if(pid == AUL_R_ECOMM) {
2681 pid = -ENOLAUNCHPAD;
2683 aul_send_app_launch_request_signal(pid, appid, pkgid, component_type);
2684 snprintf(trm_buf, MAX_PACKAGE_STR_SIZE, "appinfo_launch:%s[PID]%d", appid, pid);
2685 __trm_app_info_send_socket(trm_buf);
2688 #ifdef _APPFW_FEATURE_AMD_KEY
2689 if(_input_window_get() != 0)
2690 ecore_x_pointer_ungrab();
2691 _D("pid(%d) ecore_x_pointer_ungrab", pid);
2692 if(_key_ungrab(KEY_BACK) < 0) {
2693 _W("back key ungrab error");
2695 _D("back key ungrab");
2700 _D("add app group info");
2701 app_group_start_app(pid, kb, lpid, can_attach, launch_mode);
2703 if (component_type && strncmp(component_type, APP_TYPE_UI, strlen(APP_TYPE_UI)) == 0)
2704 __add_fgmgr_list(pid);
2705 } else if (cmd == APP_START
2706 || cmd == APP_START_RES
2707 || cmd == APP_START_ASYNC
2708 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
2709 || cmd == APP_START_MULTI_INSTANCE
2712 app_group_restart_app(pid, kb);
2715 #ifdef _APPFW_FEATURE_AMD_KEY
2716 grab_timer_id = g_timeout_add(1000, __grab_timeout_handler, (void *)pid);
2720 else if (component_type && strncmp(component_type, APP_TYPE_SERVICE, sizeof(APP_TYPE_SERVICE)) == 0) {
2721 #ifdef _APPFW_FEATURE_PRIVATE_SERVICE
2722 const char *caller_appid = _status_app_get_appid_bypid(caller_pid);
2725 const struct appinfo *ai = NULL;
2726 const char *caller_pkgid = NULL;
2727 const char *pkgid = NULL;
2729 ai = appinfo_find(_laf, appid);
2730 pkgid = appinfo_get_value(ai, AIT_PKGID);
2731 ai = appinfo_find(_laf, caller_appid);
2732 caller_pkgid = appinfo_get_value(ai, AIT_PKGID);
2734 if (caller_pkgid && pkgid && strcmp(caller_pkgid, pkgid) != 0) {
2735 const char *launch_type = bundle_get_val(kb, OSP_K_LAUNCH_TYPE);
2737 if (launch_type == NULL || strcmp(launch_type, OSP_V_LAUNCH_TYPE_DATACONTROL) != 0) {
2738 const char *v = appinfo_get_value(ai, AIT_VISIBILITY);
2739 char num[256] = { 0, };
2744 if (__get_visibility_from_cert_svc(caller_pkgid, &vi_num) == 0) {
2745 snprintf(num, 255, "%d", vi_num);
2746 appinfo_set_value((struct appinfo*)ai, AIT_VISIBILITY, num);
2749 _E("Failed to get visibility");
2753 int visibility = atoi(v);
2754 if (!(visibility & CERT_SVC_VISIBILITY_PLATFORM)) {
2755 _E("Couldn't launch service app in other packages");
2756 __real_send(fd, -EREJECTED);
2757 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2765 pid = _status_app_is_running_v2(appid);
2767 prelaunch_attribute = __get_prelaunch_attribute(ai);
2769 // 2.4 bg-categorized svc app || 2.3 svc app -> bg allowed
2770 if ((prelaunch_attribute & RESOURCED_ALLOWED_BG_ATTRIBUTE)
2771 || !(prelaunch_attribute & RESOURCED_API_VER_2_4_ATTRIBUTE)) {
2772 _D("[__SUSPEND__] allowed backgroudn, appid: %s", appid);
2773 bundle_add(kb, AUL_K_ALLOWED_BG, "ALLOWED_BG");
2777 if (__grant_temporary_permission(caller_pid, appid, kb,
2778 &caller_exec_label, &callee_exec_label, &paths) == 0)
2779 grant_permission = 1;
2782 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2783 strncpy(log_status, "RESUMING", strlen("RESUMING"));
2785 aul_send_app_resume_request_signal(pid, appid, pkgid, APP_TYPE_SERVICE);
2788 __prepare_to_wake_services(pid);
2790 if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) {
2795 } else if (cmd != APP_RESUME) {
2796 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2797 strncpy(log_status, "LAUNCHING", strlen("LAUNCHING"));
2800 __send_proc_prelaunch_signal(appid, pkgid, prelaunch_attribute);
2802 #ifdef _APPFW_FEATURE_DEBUG_LAUNCHPAD
2803 if (bundle_get_type(kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) {
2804 SECURE_LOGD("The svcapp(%s) is launched by debug-launchpad", appid);
2805 __set_appinfo_for_launchpad(ai, kb);
2806 pid = app_send_cmd(DEBUG_LAUNCHPAD_PID, cmd, kb);
2807 if (pid == AUL_R_ECOMM) {
2808 pid = -ENOLAUNCHPAD;
2811 pid = start_process(appid, app_path, kb);
2814 pid = start_process(appid, app_path, kb);
2816 aul_send_app_launch_request_signal(pid, appid, pkgid, component_type);
2820 g_idle_add(__check_service_only, (gpointer)pid);
2824 _E("unkown application");
2828 if(cmd == APP_START_ASYNC)
2831 __real_send(fd, pid);
2834 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2835 _status_log_save(log_status, appid);
2839 _status_add_app_info_list(appid, app_path, caller, pid, pad_pid, is_group_app);
2840 _status_update_app_info_caller_pid(pid, caller_pid);
2841 if (grant_permission) {
2842 __add_shared_info(pid, caller_exec_label, callee_exec_label, paths);
2843 if (caller_exec_label) {
2844 free(caller_exec_label);
2845 caller_exec_label = NULL;
2847 if (callee_exec_label) {
2848 free(callee_exec_label);
2849 callee_exec_label = NULL;
2853 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2854 snprintf(log_status, AUL_PR_NAME, "SUCCESS: %d", pid);
2855 _status_log_save(log_status, appid);
2858 #ifdef _APPFW_FEATURE_APP_CHECKER
2859 pkg_type = appinfo_get_value(ai, AIT_TYPE);
2861 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2865 ret = ac_server_check_launch_privilege(appid, pkg_type, pid);
2866 if (ret != AC_R_ERROR) {
2867 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2870 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2875 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2877 _status_log_save("FAILURE", appid);
2881 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2885 int __e17_status_handler(int pid, int status, void *data)
2887 if (status == PROC_STATUS_FG) {
2888 __del_fgmgr_list(pid);
2890 #ifdef _APPFW_FEATURE_AMD_KEY
2891 _D("pid(%d) status(%d)", pid, status);
2892 if(_input_window_get() != 0)
2893 ecore_x_pointer_ungrab();
2894 if(_key_ungrab(KEY_BACK) < 0) {
2895 _W("back key ungrab error");
2897 _D("back key ungrab");
2899 g_source_remove(grab_timer_id);
2901 _status_update_app_info_list(pid, STATUS_VISIBLE, FALSE);
2902 #ifdef _APPFW_FEATURE_TERMINATE_UNMANAGEABLE_APP
2903 #ifdef _APPFW_FEATURE_SEND_HOME_LAUNCH_SIGNAL
2904 __check_home_app(pid);
2907 } else if (status == PROC_STATUS_BG) {
2908 _status_update_app_info_list(pid, STATUS_BG, FALSE);
2909 } else if (status == PROC_STATUS_LAUNCH) {
2910 _D("pid(%d) status(%d)", pid, status);
2911 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:AMD:EFFECT_DONE");
2912 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2918 int _launch_init(struct amdmgr* amd)
2924 amd_cmdline = __proc_get_cmdline_bypid(getpid());
2928 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
2930 _E("dbus_bus_get error");
2934 ret = aul_listen_e17_status_signal(__e17_status_handler, NULL);
2936 _D("ret : %d", ret);
2938 __preexec_init(0, NULL);
2943 void _set_atom_effect(void)
2945 ATOM_IMAGE_EFFECT = ecore_x_atom_get(atom_name);
2948 void __set_appinfo_for_launchpad(const struct appinfo *ai, bundle *kb) {
2951 _D("Add hwacc, taskmanage, app_path and pkg_type into bundle for sending those to launchpad.");
2952 ret = bundle_del(kb, AUL_K_HWACC);
2953 if (ret != BUNDLE_ERROR_NONE)
2954 _D("bundle_del error: %d", ret);
2955 ret = bundle_add(kb, AUL_K_HWACC, appinfo_get_value(ai, AIT_HWACC));
2956 if (ret != BUNDLE_ERROR_NONE)
2957 _E("failed to set AUL_K_HWACC: ret(%d)", ret);
2960 bundle_del(kb, AUL_K_TASKMANAGE);
2961 if (ret != BUNDLE_ERROR_NONE)
2962 _D("bundle_del error: %d", ret);
2963 bundle_add(kb, AUL_K_TASKMANAGE, appinfo_get_value(ai, AIT_TASKMANAGE));
2964 if (ret != BUNDLE_ERROR_NONE)
2965 _E("failed to set AUL_K_TASKMANAGE: ret(%d)", ret);
2967 bundle_del(kb, AUL_K_EXEC);
2968 if (ret != BUNDLE_ERROR_NONE)
2969 _D("bundle_del error: %d", ret);
2970 bundle_add(kb, AUL_K_EXEC, appinfo_get_value(ai, AIT_EXEC));
2971 if (ret != BUNDLE_ERROR_NONE)
2972 _E("failed to set AUL_K_EXEC: ret(%d)", ret);
2974 bundle_del(kb, AUL_K_PACKAGETYPE);
2975 if (ret != BUNDLE_ERROR_NONE)
2976 _D("bundle_del error: %d", ret);
2977 bundle_add(kb, AUL_K_PACKAGETYPE, appinfo_get_value(ai, AIT_TYPE));
2978 if (ret != BUNDLE_ERROR_NONE)
2979 _E("failed to set AUL_K_PACKAGETYPE: ret(%d)", ret);
2981 bundle_del(kb, AUL_K_INTERNAL_POOL);
2982 if (ret != BUNDLE_ERROR_NONE)
2983 _D("bundle_del error: %d", ret);
2984 bundle_add(kb, AUL_K_INTERNAL_POOL, appinfo_get_value(ai, AIT_POOL));
2985 if (ret != BUNDLE_ERROR_NONE)
2986 _E("failed to set AUL_K_INTERNAL_POOL: ret(%d)", ret);
2988 bundle_del(kb, AUL_K_PKGID);
2989 if (ret != BUNDLE_ERROR_NONE)
2990 _D("bundle_del error: %d", ret);
2991 bundle_add(kb, AUL_K_PKGID, appinfo_get_value(ai, AIT_PKGID));
2992 if (ret != BUNDLE_ERROR_NONE)
2993 _E("failed to set AUL_K_PKGID: ret(%d)", ret);