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_FG 3
109 #define PROC_STATUS_BG 4
110 #ifdef _APPFW_FEATURE_CPU_BOOST
111 #define APP_BOOSTING_PERIOD 1500 //msec
114 #ifdef _APPFW_FEATURE_PRIVATE_SERVICE
115 #define OSP_K_LAUNCH_TYPE "__OSP_LAUNCH_TYPE__"
116 #define OSP_V_LAUNCH_TYPE_DATACONTROL "datacontrol"
119 static char *amd_cmdline;
121 struct appinfomgr *_laf;
123 DBusConnection *conn;
124 #ifdef _APPFW_FEATURE_AMD_KEY
130 /*Unused data structure. Will be removed*/
132 char *pkg_name; /* package */
133 char *app_path; /* exec */
134 char *original_app_path; /* exec */
135 int multiple; /* x_slp_multiple */
137 } app_info_from_pkgmgr;
140 static GList *_kill_list;
145 guint tid; /* timer ID */
149 static const char *atom_name = "_E_COMP_FAKE_LAUNCH_IMAGE"; // Atomic ID string
150 static Ecore_X_Atom ATOM_IMAGE_EFFECT; //Atomic ID
151 static void __amd_effect_image_file_set(char *image_file);
152 static void __amd_send_message_to_e17(int screenmode, const char * indicator, int effect_type, int theme);
153 static void __set_reply_handler(int fd, int pid, int clifd, int cmd);
154 static void __real_send(int clifd, int ret);
155 static int __send_proc_prelaunch_signal(const char *appid, const char *pkgid, int attribute);
156 int invoke_dbus_method_sync(const char *dest, const char *path,
157 const char *interface, const char *method,
158 const char *sig, char *param[]);
160 static void _set_sdk_env(const char* appid, char* str) {
161 char buf[MAX_LOCAL_BUFSZ];
164 _D("key : %s / value : %s", AUL_K_SDK, str);
165 /* http://gcc.gnu.org/onlinedocs/gcc/Cross_002dprofiling.html*/
166 /* GCOV_PREFIX contains the prefix to add to the absolute paths in the object file. */
167 /* Prefix can be absolute, or relative. The default is no prefix. */
168 /* GCOV_PREFIX_STRIP indicates the how many initial directory names */
169 /* to stripoff the hardwired absolute paths. Default value is 0. */
170 if (strncmp(str, SDK_CODE_COVERAGE, strlen(str)) == 0) {
171 snprintf(buf, MAX_LOCAL_BUFSZ, PATH_APP_ROOT"/%s"PATH_DATA, appid);
172 ret = setenv("GCOV_PREFIX", buf, 1);
173 _D("GCOV_PREFIX : %d", ret);
174 ret = setenv("GCOV_PREFIX_STRIP", "4096", 1);
175 _D("GCOV_PREFIX_STRIP : %d", ret);
176 } else if (strncmp(str, SDK_DYNAMIC_ANALYSIS, strlen(str)) == 0) {
177 ret = setenv("LD_PRELOAD", PATH_DA_SO, 1);
178 _D("LD_PRELOAD : %d", ret);
182 #define USE_ENGINE(engine) setenv("ELM_ENGINE", engine, 1);
184 static void _set_env(const char *appid, bundle * kb, const char *hwacc)
187 const char **str_array;
191 setenv("PKG_NAME", appid, 1);
195 str = bundle_get_val(kb, AUL_K_STARTTIME);
197 setenv("APP_START_TIME", str, 1);
199 if(bundle_get_type(kb, AUL_K_SDK) & BUNDLE_TYPE_ARRAY) {
200 str_array = bundle_get_str_array(kb, AUL_K_SDK, &len);
201 if(str_array != NULL) {
202 for (i = 0; i < len; i++) {
203 _D("index : [%d]", i);
204 _set_sdk_env(appid, (char *)str_array[i]);
208 str = bundle_get_val(kb, AUL_K_SDK);
210 _set_sdk_env(appid, (char *)str);
214 setenv("HWACC", hwacc, 1);
217 static void __set_oom(void)
219 char buf[MAX_OOM_ADJ_BUFSZ] = {0,};
222 /* we should reset oomadj value as default because child
223 inherits from parent oom_adj*/
224 snprintf(buf, MAX_OOM_ADJ_BUFSZ, "/proc/%d/oom_score_adj", getpid());
225 fp = fopen(buf, "w");
228 fprintf(fp, "%d", 100);
232 static void _prepare_exec(const char *appid, bundle *kb)
234 const struct appinfo *ai;
235 const char *app_path = NULL;
236 const char *pkg_type = NULL;
238 char process_name[AUL_PR_NAME];
244 signal(SIGINT, SIG_DFL);
245 signal(SIGTERM, SIG_DFL);
246 signal(SIGCHLD, SIG_DFL);
250 ai = appinfo_find(_laf, appid);
252 app_path = appinfo_get_value(ai, AIT_EXEC);
253 pkg_type = appinfo_get_value(ai, AIT_TYPE);
254 hwacc = appinfo_get_value(ai, AIT_HWACC);
256 __preexec_run(pkg_type, appid, app_path);
259 SECURE_LOGD("appid : %s / pkg_type : %s / app_path : %s ", appid, pkg_type, app_path);
260 if (pkg_type && strncmp(pkg_type, "wgt", 3) !=0 && (ret = __set_access(appid, pkg_type, app_path)) < 0) {
261 _D("fail to set privileges - check your package's credential : %d\n", ret);
265 /* SET DUMPABLE - for coredump*/
266 prctl(PR_SET_DUMPABLE, 1);
268 /* SET PROCESS NAME*/
269 if (app_path == NULL) {
270 _D("app_path should not be NULL - check menu db");
273 file_name = strrchr(app_path, '/') + 1;
274 if (file_name == NULL) {
275 _D("can't locate file name to execute");
278 memset(process_name, '\0', AUL_PR_NAME);
279 snprintf(process_name, AUL_PR_NAME, "%s", file_name);
280 prctl(PR_SET_NAME, process_name);
283 _set_env(appid, kb, hwacc);
286 static char **__create_argc_argv(bundle * kb, int *margc)
291 argc = bundle_export_to_argv(kb, &argv);
296 static void _do_exec(const char *cmd, const char *group, bundle *kb)
304 b = g_shell_parse_argv(cmd, &argc, &argv, NULL);
307 b_argv = __create_argc_argv(kb, &b_argc);
308 b_argv[0] = strdup(argv[0]);
309 _prepare_exec(group, kb);
310 execv(b_argv[0], b_argv);
314 _prepare_exec(group, kb);
315 execv(argv[0], argv);
318 _E("exec error: %s", strerror(errno));
322 static inline int __send_app_launch_signal(int launch_pid)
324 DBusMessage *message;
329 message = dbus_message_new_signal(AUL_DBUS_PATH,
330 AUL_DBUS_SIGNAL_INTERFACE,
331 AUL_DBUS_APPLAUNCH_SIGNAL);
333 if (dbus_message_append_args(message,
334 DBUS_TYPE_UINT32, &launch_pid,
335 DBUS_TYPE_INVALID) == FALSE) {
336 _E("Failed to load data error");
340 if (dbus_connection_send(conn, message, NULL) == FALSE) {
341 _E("dbus send error");
345 dbus_connection_flush(conn);
346 dbus_message_unref(message);
348 _W("send launch signal done: %d", launch_pid);
353 static int __send_watchdog_signal(int pid, int signal_num)
355 DBusMessage *message;
360 if (!_get_platform_ready()) {
361 _E("[Info]_get_platform_ready return false");
365 #ifdef _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
366 if(_status_get_cooldown_status() == COOLDOWN_LIMIT) {
367 _E("[Info]cooldown status : LimitAction");
370 #endif // _APPFW_FEATURE_COOLDOWN_MODE_SUPPORT
372 message = dbus_message_new_signal(RESOURCED_PROC_OBJECT,
373 RESOURCED_PROC_INTERFACE,
374 RESOURCED_PROC_WATCHDOG_SIGNAL);
376 if (dbus_message_append_args(message,
377 DBUS_TYPE_INT32, &pid,
378 DBUS_TYPE_INT32, &signal_num,
379 DBUS_TYPE_INVALID) == FALSE) {
380 _E("Failed to load data error");
384 if (dbus_connection_send(conn, message, NULL) == FALSE) {
385 _E("dbus send error");
389 dbus_connection_flush(conn);
390 dbus_message_unref(message);
392 _W("send a watchdog signal done: %d", pid);
397 static int __send_proc_prelaunch_signal(const char *appid, const char *pkgid, int attribute)
399 DBusMessage *message;
404 message = dbus_message_new_signal(RESOURCED_PROC_OBJECT,
405 RESOURCED_PROC_INTERFACE,
406 RESOURCED_PROC_PRELAUNCH_SIGNAL);
408 if (dbus_message_append_args(message,
409 DBUS_TYPE_STRING, &appid,
410 DBUS_TYPE_STRING, &pkgid,
411 DBUS_TYPE_INT32, &attribute,
412 DBUS_TYPE_INVALID) == FALSE) {
413 _E("Failed to load data error");
417 if (dbus_connection_send(conn, message, NULL) == FALSE) {
418 _E("dbus send error");
422 dbus_connection_flush(conn);
423 dbus_message_unref(message);
425 SECURE_LOGW("send a prelaunch signal done: appid(%s) pkgid(%s) attribute(%x)", appid, pkgid, attribute);
430 static int __check_cmdline(int ret)
434 int cmdline_changed = 0;
435 int cmdline_exist = 0;
440 /* check normally was launched?*/
443 cmdline = __proc_get_cmdline_bypid(ret);
444 if (cmdline == NULL) {
445 _E("error founded when being launched with %d", ret);
446 if (cmdline_exist || cmdline_changed) {
447 _E("The app process might be terminated while we are wating %d", ret);
450 } else if (strcmp(cmdline, amd_cmdline)) {
459 _D("-- now wait to change cmdline --");
460 usleep(50 * 1000); /* 50ms sleep*/
462 } while (wait_count <= 20); /* max 50*20ms will be sleep*/
464 if ((!cmdline_exist) && (!cmdline_changed)) {
465 _E("cmdline_exist 0 & cmdline_changed 0");
469 if (!cmdline_changed)
470 _E("process launched, but cmdline not changed");
475 int start_process(const char *group, const char *cmd, bundle *kb)
482 case 0: /* child process */
483 _D("start application");
484 _signal_unblock_sigchld();
485 #ifdef _APPFW_FEATURE_PRIORITY_CHANGE
486 r = setpriority(PRIO_PROCESS, 0, 0);
489 SECURE_LOGE("Setting process (%d) priority to 0 failed, errno: %d (%s)",
490 getpid(), errno, strerror(errno));
493 _do_exec(cmd, group, kb);
499 _E("application start: fork: %s", strerror(errno));
502 default: /* parent process */
503 _W("child process: %d", p);
504 r = __check_cmdline(p);
506 __send_app_launch_signal(r);
508 _E("cmdline change failed.");
515 static int __check_ver(const char *required, const char *actual)
518 if (required && actual) {
519 ret = strverscmp(required, actual); // should 0 or less
527 static int __get_prelaunch_attribute(const struct appinfo *ai)
529 int attribute_val = 0;
530 const char *attribute_str = NULL;
532 attribute_str = appinfo_get_value(ai, AIT_ALLOWED_BG);
533 if (attribute_str && strncmp(attribute_str, "ALLOWED_BG", sizeof("ALLOWED_BG")) == 0) {
534 attribute_val |= RESOURCED_ALLOWED_BG_ATTRIBUTE;
537 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
538 attribute_val |= RESOURCED_BACKGROUND_MANAGEMENT_ATTRIBUTE;
541 attribute_str = appinfo_get_value(ai, AIT_API_VER);
542 if (attribute_str && __check_ver("2.4", attribute_str)) {
543 attribute_val |= RESOURCED_API_VER_2_4_ATTRIBUTE;
546 return attribute_val;
549 int _start_srv(const struct appinfo *ai)
556 const char *appid = NULL;
557 int prelaunch_attribute = 0;
559 group = appinfo_get_filename(ai);
561 cmd = appinfo_get_value(ai, AIT_EXEC);
563 _E("start service: '%s' has no exec", group);
567 appid = appinfo_get_value(ai, AIT_NAME);
568 pkgid = appinfo_get_value(ai, AIT_PKGID);
570 prelaunch_attribute = __get_prelaunch_attribute(ai);
571 if ((prelaunch_attribute & RESOURCED_ALLOWED_BG_ATTRIBUTE) ||
572 !(prelaunch_attribute & RESOURCED_API_VER_2_4_ATTRIBUTE)) {
573 SECURE_LOGD("[__SUSPEND__] allowed background, appid :%s, app_type: %s, api version: %s",
574 appid, APP_TYPE_SERVICE, appinfo_get_value(ai, AIT_API_VER));
579 bundle_add(b, AUL_K_ALLOWED_BG, "ALLOWED_BG");
582 __send_proc_prelaunch_signal(appid, pkgid, prelaunch_attribute);
584 r = start_process(group, cmd, b);
591 _E("start service: '%s': failed", group);
596 aul_send_app_launch_request_signal(r, group, pkgid, APP_TYPE_SERVICE);
597 _status_add_app_info_list(group, cmd, NULL, r, -1, 0);
602 static void _free_kt(struct ktimer *kt)
611 static void _kill_pid(struct cginfo *cg, const char *group, pid_t pid)
615 if (pid <= INIT_PID) /* block sending to all process or init */
618 /* TODO: check pid exist in group */
622 _E("send SIGKILL: pid %d not exist", pid);
626 r = kill(pid, SIGKILL);
628 _E("send SIGKILL: %s", strerror(errno));
631 static gboolean _ktimer_cb(gpointer data)
633 struct ktimer *kt = data;
635 _kill_pid(kt->cg, kt->group, kt->pid);
636 _kill_list = g_list_remove(_kill_list, kt);
642 static void _add_list(struct cginfo *cg, const char *group, pid_t pid)
646 kt = calloc(1, sizeof(*kt));
651 kt->group = strdup(group);
657 kt->tid = g_timeout_add_seconds(TERM_WAIT_SEC, _ktimer_cb, kt);
659 _kill_list = g_list_append(_kill_list, kt);
662 static inline void _del_list(GList *l)
671 g_source_remove(kt->tid);
673 _kill_list = g_list_delete_link(_kill_list, l);
676 static int _kill_pid_cb(void *user_data, const char *group, pid_t pid)
680 if (pid <= INIT_PID) /* block sending to all process or init */
683 r = kill(pid, SIGTERM);
685 _E("send SIGTERM: %s", strerror(errno));
687 _add_list(user_data, group, pid);
692 void service_release(const char *group)
697 if (!group || !*group)
700 group = FILENAME(group);
703 for (l = _kill_list; l; l = g_list_next(l)) {
704 struct ktimer *k = l->data;
708 if (k->group && !strcmp(k->group, group))
717 int _send_to_sigkill(int pid)
725 if (killpg(pgid, SIGKILL) < 0)
730 int _resume_app(int pid, int clifd)
735 __app_send_raw_with_delay_reply(pid, APP_RESUME_BY_PID, (unsigned char *)&dummy,
738 _E("resume packet timeout error");
740 _E("raise failed - %d resume fail\n", pid);
741 _E("we will term the app - %d\n", pid);
742 _send_to_sigkill(pid);
745 __real_send(clifd, ret);
750 __set_reply_handler(ret, pid, clifd, APP_RESUME_BY_PID);
755 int _pause_app(int pid, int clifd)
760 __app_send_raw_with_delay_reply(pid, APP_PAUSE_BY_PID, (unsigned char *)&dummy,
763 _E("pause packet timeout error");
765 _E("iconify failed - %d pause fail\n", pid);
766 _E("we will term the app - %d\n", pid);
767 _send_to_sigkill(pid);
774 __set_reply_handler(ret, pid, clifd, APP_PAUSE_BY_PID);
779 int _fake_launch_app(int cmd, int pid, bundle * kb, int clifd)
783 bundle_raw *kb_data = NULL;
786 __real_send(clifd, -EINVAL);
790 ret = bundle_encode(kb, &kb_data, &datalen);
791 if (ret != BUNDLE_ERROR_NONE) {
792 __real_send(clifd, -EINVAL);
795 if ((ret = __app_send_raw_with_delay_reply(pid, cmd, kb_data, datalen)) < 0) {
796 _E("error request fake launch - error code = %d", ret);
797 __real_send(clifd, ret);
802 __set_reply_handler(ret, pid, clifd, cmd);
807 static void __real_send(int clifd, int ret)
812 if (send(clifd, &ret, sizeof(int), MSG_NOSIGNAL) < 0) {
813 if (errno == EPIPE) {
814 _E("send failed due to EPIPE.\n");
816 _E("send fail to client");
822 static gboolean __au_glib_check(GSource *src)
827 fd_list = src->poll_fds;
829 tmp = (GPollFD *) fd_list->data;
830 if ((tmp->revents & (POLLIN | POLLPRI)))
832 fd_list = fd_list->next;
838 static gboolean __au_glib_dispatch(GSource *src, GSourceFunc callback,
845 static gboolean __au_glib_prepare(GSource *src, gint *timeout)
850 static GSourceFuncs funcs = {
851 .prepare = __au_glib_prepare,
852 .check = __au_glib_check,
853 .dispatch = __au_glib_dispatch,
866 static gboolean __reply_handler(gpointer data)
868 struct reply_info *r_info = (struct reply_info *) data;;
869 int fd = r_info->gpollfd->fd;
872 int clifd = r_info->clifd;
873 int pid = r_info->pid;
874 int cmd = r_info->cmd;
876 len = recv(fd, &res, sizeof(int), 0);
878 if (errno == EAGAIN) {
879 _E("recv timeout : %s", strerror(errno));
882 _E("recv error : %s", strerror(errno));
889 if (cmd == APP_TERM_BY_PID || cmd == APP_TERM_BGAPP_BY_PID) {
890 __real_send(clifd, -1);
891 } else if (cmd == APP_START_ASYNC || cmd == APP_PAUSE_BY_PID) {
894 __real_send(clifd, res);
897 if (cmd == APP_TERM_BY_PID || cmd == APP_TERM_BGAPP_BY_PID) {
898 __real_send(clifd, 0);
899 } else if (cmd == APP_START_ASYNC || cmd == APP_PAUSE_BY_PID) {
902 __real_send(clifd, pid);
906 _W("listen fd(%d) , send fd(%d), pid(%d), cmd(%d)", fd, clifd, pid, cmd);
908 g_source_remove(r_info->timer_id);
909 g_source_remove_poll(r_info->src, r_info->gpollfd);
910 g_source_destroy(r_info->src);
911 g_free(r_info->gpollfd);
917 static gboolean __recv_timeout_handler(gpointer data)
919 struct reply_info *r_info = (struct reply_info *) data;
920 int fd = r_info->gpollfd->fd;
922 const struct appinfo *ai;
925 _E("application is not responding : pid(%d) cmd(%d)", r_info->pid, r_info->cmd);
929 switch (r_info->cmd) {
934 case APP_START_ASYNC:
935 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
936 case APP_START_MULTI_INSTANCE:
938 appid = _status_app_get_appid_bypid(r_info->pid);
941 ai = appinfo_find(_laf, appid);
946 task_manage = appinfo_get_boolean(ai, AIT_TASKMANAGE);
948 __send_watchdog_signal(r_info->pid, SIGKILL);
951 case APP_TERM_BY_PID:
952 case APP_TERM_BGAPP_BY_PID:
953 if (_send_to_sigkill(r_info->pid) < 0) {
954 _E("fail to killing - %d\n", r_info->pid);
955 __real_send(r_info->clifd, -1);
957 __real_send(r_info->clifd, 0);
962 g_source_remove_poll(r_info->src, r_info->gpollfd);
963 g_source_destroy(r_info->src);
964 g_free(r_info->gpollfd);
970 static void __set_reply_handler(int fd, int pid, int clifd, int cmd)
974 struct reply_info *r_info;
976 src = g_source_new(&funcs, sizeof(GSource));
978 gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
979 if (gpollfd == NULL) {
984 gpollfd->events = POLLIN;
987 r_info = malloc(sizeof(*r_info));
988 if (r_info == NULL) {
995 r_info->clifd = clifd;
998 r_info->gpollfd = gpollfd;
1002 r_info->timer_id = g_timeout_add(5000, __recv_timeout_handler, (gpointer) r_info);
1003 g_source_add_poll(src, gpollfd);
1004 g_source_set_callback(src, (GSourceFunc) __reply_handler,
1005 (gpointer) r_info, NULL);
1006 g_source_set_priority(src, G_PRIORITY_DEFAULT);
1007 g_source_attach(src, NULL);
1009 _D("listen fd : %d, send fd : %d", fd, clifd);
1012 void _term_sub_app(int pid)
1017 if ( (ret = __app_send_raw_with_noreply(pid, APP_TERM_BY_PID_ASYNC,
1018 (unsigned char *)&dummy, sizeof(int))) < 0) {
1019 _E("terminate packet send error - use SIGKILL");
1020 if (_send_to_sigkill(pid) < 0) {
1021 _E("fail to killing - %d\n", pid);
1027 int _term_app(int pid, int clifd)
1032 if (app_group_is_leader_pid(pid)) {
1037 app_group_get_group_pids(pid, &cnt, &pids);
1039 for (i = cnt-1 ; i>=0; i--) {
1041 _term_sub_app(pids[i]);
1042 app_group_remove(pids[i]);
1050 if ( (ret = __app_send_raw_with_delay_reply
1051 (pid, APP_TERM_BY_PID, (unsigned char *)&dummy, sizeof(int))) < 0) {
1052 _D("terminate packet send error - use SIGKILL");
1053 if (_send_to_sigkill(pid) < 0) {
1054 _E("fail to killing - %d\n", pid);
1055 __real_send(clifd, -1);
1058 __real_send(clifd, 0);
1062 __set_reply_handler(ret, pid, clifd, APP_TERM_BY_PID);
1067 int _term_req_app(int pid, int clifd)
1072 if ( (ret = __app_send_raw_with_delay_reply
1073 (pid, APP_TERM_REQ_BY_PID, (unsigned char *)&dummy, sizeof(int))) < 0) {
1074 _D("terminate req send error");
1075 __real_send(clifd, ret);
1079 __set_reply_handler(ret, pid, clifd, APP_TERM_REQ_BY_PID);
1084 int _term_bgapp(int pid, int clifd)
1089 if (app_group_is_leader_pid(pid)) {
1095 app_group_get_group_pids(pid, &cnt, &pids);
1097 status = _status_get_app_info_status(pids[cnt-1]);
1098 if(status == STATUS_BG) {
1099 for (i = cnt-1 ; i>=0; i--) {
1101 _term_sub_app(pids[i]);
1102 app_group_remove(pids[i]);
1110 if ( (fd = __app_send_raw_with_delay_reply
1111 (pid, APP_TERM_BGAPP_BY_PID, (unsigned char *)&dummy, sizeof(int))) < 0) {
1112 _D("terminate packet send error - use SIGKILL");
1113 if (_send_to_sigkill(pid) < 0) {
1114 _E("fail to killing - %d\n", pid);
1115 __real_send(clifd, -1);
1118 __real_send(clifd, 0);
1120 _D("term_bgapp done\n");
1122 __set_reply_handler(fd, pid, clifd, APP_TERM_BGAPP_BY_PID);
1128 #include <sqlite3.h>
1129 static int __launchpad_update_task_managed_field(const char* app_id, int task_managed)
1132 char *sqlite3_error_msg = NULL;
1134 if (sqlite3_open("/opt/dbspace/.pkgmgr_parser.db", &db) != SQLITE_OK) {
1135 _E("sqlite3_open() failed! -> %s\n", sqlite3_errmsg(db));
1139 if (sqlite3_exec(db, "PRAGMA journal_mode = PERSIST", NULL, NULL, &sqlite3_error_msg) != SQLITE_OK) {
1140 _E("sqlite3_exec(\"PRAGMA journal_mode = PERSIST\") failed! -> %s", sqlite3_error_msg);
1141 sqlite3_free(sqlite3_error_msg);
1146 if (sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, &sqlite3_error_msg) != SQLITE_OK) {
1147 _E("sqlite3_exec(\"BEGIN EXCLUSIVE\") failed! -> %s", sqlite3_error_msg);
1148 sqlite3_free(sqlite3_error_msg);
1153 char query[1024] = {0, };
1154 snprintf(query, 1024,"update package_app_info set app_taskmanage='%s' where app_id='%s'",
1155 task_managed ? "true" : "false", app_id);
1157 if (sqlite3_exec(db, query, NULL, NULL, &sqlite3_error_msg) != SQLITE_OK) {
1158 _E("sqlite3_exec(\"%s\") failed! -> %s", query, sqlite3_error_msg);
1159 sqlite3_free(sqlite3_error_msg);
1163 if (sqlite3_exec(db, "COMMIT", NULL, NULL, NULL) != SQLITE_OK) {
1164 _E("sqlite3_exec(\"COMMIT\") failed!");
1165 if (sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL) != SQLITE_OK) {
1166 _E("sqlite3_exec(\"ROLLBACK\") failed!");
1177 static void __pre_launching_processing(const char* app_id)
1179 const char* const PRE_LAUNCHING_LIST_DIR = "/opt/usr/etc/wrt_launchpad_daemon/pre_launching_list";
1181 struct stat file_status;
1182 if (stat(PRE_LAUNCHING_LIST_DIR, &file_status) == 0) {
1183 if (S_ISDIR(file_status.st_mode)) {
1186 struct dirent entry, *result = NULL;
1188 dir = opendir(PRE_LAUNCHING_LIST_DIR);
1191 for (ret = readdir_r(dir, &entry, &result);
1192 result != NULL && ret == 0;
1193 ret = readdir_r(dir, &entry, &result)) {
1194 if (strncmp(entry.d_name, ".", 2) == 0 ||
1195 strncmp(entry.d_name, "..", 3) == 0) {
1199 if (strcmp(entry.d_name, app_id) == 0)
1201 __launchpad_update_task_managed_field(app_id, 1);
1208 _E("opendir(\"%s\") failed!", PRE_LAUNCHING_LIST_DIR);
1214 static int __nofork_processing(int cmd, int pid, bundle * kb, int clifd)
1217 #ifdef _APPFW_FEATURE_CPU_BOOST
1218 const char *operation;
1220 operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__");
1222 //TODO: CPU boosting for relaunching will be removed.
1223 //Home screen requests CPU boosting on launching or relaunching during 200 msec.
1224 if (cmd == APP_OPEN ||
1225 (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/main", 512) == 0)) {
1228 snprintf(val, sizeof(val), "%d", APP_BOOSTING_PERIOD);
1231 ret = invoke_dbus_method_sync(SYSTEM_BUS_NAME, SYSTEM_OBJECT_PATH,
1232 SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, "i", arr);
1233 _D("%s-%s : %d", SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, ret);
1236 _W("__nofork_processing, cmd: %d, pid: %d", cmd, pid);
1240 _D("resume app's pid : %d\n", pid);
1241 if ((ret = _resume_app(pid, clifd)) < 0)
1242 _E("__resume_app failed. error code = %d", ret);
1243 _D("resume app done");
1248 case APP_START_ASYNC:
1249 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
1250 case APP_START_MULTI_INSTANCE:
1252 _D("fake launch pid : %d\n", pid);
1253 if ((ret = _fake_launch_app(cmd, pid, kb, clifd)) < 0)
1254 _E("fake_launch failed. error code = %d", ret);
1255 _D("fake launch done");
1268 __amd_sysman_restore_hz_timer_cb(void *data)
1270 struct context *ctxt = data;
1275 sysman_release_cpu_min_frequency ();
1277 _D("*******[1.6MHZ Support] Released\n " );
1279 return ECORE_CALLBACK_CANCEL; // same as EINA_FALSE
1287 #ifdef _APPFW_FEATURE_FAKE_EFFECT
1288 static void __amd_effect_image_file_set(char *image_file)
1290 Ecore_X_Window root_win;
1292 if(!_window_is_initialized())
1295 root_win = ecore_x_window_root_first_get();
1296 SECURE_LOGD("path : %s", image_file);
1297 ecore_x_window_prop_string_set(root_win, ATOM_IMAGE_EFFECT,image_file);
1301 static void __amd_send_message_to_e17(int screenmode, const char * indicator, int effect_type, int theme)
1303 Ecore_X_Window root_win;
1306 if(!_window_is_initialized())
1309 root_win = ecore_x_window_root_first_get();
1310 _D("root win : %x",root_win);
1311 int screen_orientation[5]={0,0,270,180,90};
1312 if (screenmode > 4 || screenmode < 0)
1315 if (strncmp(indicator, "true", 4) == 0){
1316 _D("[LAUNCHING EFFECT]: screen mode(%d), effect type(%d), theme(%d), indicator show",
1317 screen_orientation[screenmode], effect_type, theme);
1318 ret = ecore_x_client_message32_send (root_win, ATOM_IMAGE_EFFECT,
1319 ECORE_X_EVENT_MASK_WINDOW_PROPERTY, effect_type,
1320 screen_orientation[screenmode],
1321 SHOW_INDICATOR, theme, 0);
1324 _D("[LAUNCHING EFFECT]: screen mode(%d), effect type(%d), theme(%d), indicator show",
1325 screen_orientation[screenmode], effect_type, theme);
1326 ret = ecore_x_client_message32_send (root_win, ATOM_IMAGE_EFFECT,
1327 ECORE_X_EVENT_MASK_WINDOW_PROPERTY, effect_type,
1328 screen_orientation[screenmode],
1329 HIDE_INDICATOR, theme, 0);
1332 _D("ecore_x_client_message32_send : %d",ret);
1336 static int append_variant(DBusMessageIter *iter, const char *sig, char *param[])
1341 uint64_t int64_type;
1346 for (ch = (char*)sig, i = 0; *ch != '\0'; ++i, ++ch) {
1349 int_type = atoi(param[i]);
1350 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &int_type);
1353 int_type = atoi(param[i]);
1354 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &int_type);
1357 int64_type = atoi(param[i]);
1358 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT64, &int64_type);
1361 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, param[i]);
1371 int invoke_dbus_method_sync(const char *dest, const char *path,
1372 const char *interface, const char *method,
1373 const char *sig, char *param[])
1376 DBusMessageIter iter;
1381 msg = dbus_message_new_method_call(dest, path, interface, method);
1383 _E("dbus_message_new_method_call(%s:%s-%s)", path, interface, method);
1388 dbus_message_iter_init_append(msg, &iter);
1389 r = append_variant(&iter, sig, param);
1391 _E("append_variant error(%d)", r);
1392 dbus_message_unref(msg);
1397 dbus_error_init(&err);
1399 reply = dbus_connection_send_with_reply_and_block(conn, msg, 500, &err);
1400 dbus_message_unref(msg);
1402 _E("dbus_connection_send error(%s:%s)", err.name, err.message);
1403 dbus_error_free(&err);
1407 r = dbus_message_get_args(reply, &err, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
1408 dbus_message_unref(reply);
1410 _E("no message : [%s:%s]", err.name, err.message);
1411 dbus_error_free(&err);
1418 #ifdef _APPFW_FEATURE_AMD_KEY
1419 static gboolean __grab_timeout_handler(gpointer data)
1421 int pid = (int) data;
1423 if(_input_window_get() != 0)
1424 ecore_x_pointer_ungrab();
1425 _D("pid(%d) ecore_x_pointer_ungrab", pid);
1426 if(_key_ungrab(KEY_BACK) < 0) {
1427 _W("back key ungrab error");
1429 _D("back key ungrab");
1436 #ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
1437 static int __tep_mount(char *mnt_path[])
1442 struct stat link_buf = {0,};
1444 rv = lstat(mnt_path[0], &link_buf);
1446 rv = unlink(mnt_path[0]);
1448 _E("Unable tp remove link file %s", mnt_path[0]);
1451 msg = dbus_message_new_method_call(TEP_BUS_NAME, TEP_OBJECT_PATH,
1452 TEP_INTERFACE_NAME, TEP_MOUNT_METHOD);
1454 _E("dbus_message_new_method_call(%s:%s-%s)", TEP_OBJECT_PATH,
1455 TEP_INTERFACE_NAME, TEP_MOUNT_METHOD);
1459 if (!dbus_message_append_args(msg,
1460 DBUS_TYPE_STRING, &mnt_path[0],
1461 DBUS_TYPE_STRING, &mnt_path[1],
1462 DBUS_TYPE_INVALID)) {
1463 _E("Ran out of memory while constructing args\n");
1468 if (dbus_connection_send(conn, msg, NULL) == FALSE) {
1469 _E("dbus_connection_send error");
1474 dbus_message_unref(msg);
1478 static void __send_mount_request(const struct appinfo *ai, const char *tep_name,
1481 SECURE_LOGD("tep name is: %s", tep_name);
1482 char *mnt_path[2] = {NULL, };
1483 const char *installed_storage = NULL;
1484 char tep_path[PATH_MAX] = {0, };
1486 const char *pkgid = appinfo_get_value(ai, AIT_PKGID);
1487 installed_storage = appinfo_get_value(ai, AIT_STORAGE_TYPE);
1488 if (installed_storage != NULL) {
1489 SECURE_LOGD("storage: %s", installed_storage);
1490 if (strncmp(installed_storage, "internal", 8) == 0) {
1491 snprintf(tep_path, PATH_MAX, "%s%s/res/%s", appfw_env_get_apps_path(), pkgid,
1493 mnt_path[1] = strdup(tep_path);
1494 snprintf(tep_path, PATH_MAX, "%s%s/res/tep", appfw_env_get_apps_path(), pkgid);
1495 mnt_path[0] = strdup(tep_path);
1496 } else if (strncmp(installed_storage, "external", 8) == 0) {
1497 snprintf(tep_path, PATH_MAX, "%step/%s", appfw_env_get_external_storage_path(),
1499 mnt_path[1] = strdup(tep_path);
1500 snprintf(tep_path, PATH_MAX, "%step/tep-access",
1501 appfw_env_get_external_storage_path()); /* TODO : keeping tep/tep-access for now for external storage */
1502 mnt_path[0] = strdup(tep_path);
1505 if (mnt_path[0] && mnt_path[1]) {
1506 bundle_add(kb, AUL_TEP_PATH, mnt_path[0]);
1508 ret = aul_is_tep_mount_dbus_done(mnt_path[0]);
1510 ret = __tep_mount(mnt_path);
1512 _E("dbus error %d", ret);
1523 static int __check_app_control_privilege(const char *operation, int caller_pid, const struct appinfo *caller)
1526 const char *api_ver;
1528 if (caller == NULL) // daemon
1531 if (operation == NULL || caller_pid < 1)
1534 if (strcmp(operation, AUL_SVC_OPERATION_DOWNLOAD) == 0) {
1535 api_ver = appinfo_get_value(caller, AIT_API_VER);
1538 _E("failed to get api version");
1542 if (api_ver && strverscmp("2.4", api_ver) < 1) { // ver 2.4 or later
1543 ret = security_server_check_privilege_by_pid(caller_pid, "privilege::tizen::download", "rw");
1544 if (ret != SECURITY_SERVER_API_SUCCESS) {
1545 _E("caller %d violates http://tizen.org/privilege/download privilege", caller_pid);
1546 return -EILLEGALACCESS;
1549 } else if (strcmp(operation, AUL_SVC_OPERATION_CALL) == 0) {
1550 // Check the privilege for call operation
1551 ret = security_server_check_privilege_by_pid(caller_pid, "privilege::tizen::call", "rw");
1552 if (ret != SECURITY_SERVER_API_SUCCESS) {
1553 _E("caller %d violates http://tizen.org/privilege/call privilege", caller_pid);
1554 return -EILLEGALACCESS;
1562 int __check_mode(const struct appinfo *ai)
1564 #ifdef _APPFW_FEATURE_TTS_MODE
1566 const char *tts_support = NULL;
1568 #ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
1572 #ifdef _APPFW_FEATURE_TTS_MODE
1573 vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &tts_mode);
1575 tts_support = appinfo_get_value(ai, AIT_TTS);
1576 _W("tts : %d %s", tts_mode, tts_support);
1577 if(strncmp(tts_support, "false", 5) == 0) {
1578 _W("Cannot launch this app in TTS mode");
1584 #ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
1585 vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &ups_mode);
1586 if (ups_mode == SETTING_PSMODE_EMERGENCY) {
1587 const char *ups_support = appinfo_get_value(ai, AIT_UPS);
1588 _W("ups : %d %s", ups_mode, ups_support);
1590 #endif //_APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
1595 static void __prepare_to_suspend_services(int pid)
1598 SECURE_LOGD("[__SUSPEND__] pid: %d", pid);
1599 __app_send_raw_with_noreply(pid, APP_SUSPEND, (unsigned char *)&dummy, sizeof(int));
1602 static void __prepare_to_wake_services(int pid)
1605 SECURE_LOGD("[__SUSPEND__] pid: %d", pid);
1606 __app_send_raw_with_noreply(pid, APP_WAKE, (unsigned char *)&dummy, sizeof(int));
1609 static gboolean __check_service_only(gpointer user_data)
1611 int pid = GPOINTER_TO_INT(user_data);
1612 SECURE_LOGD("[__SUSPEND__] pid :%d", pid);
1614 _status_check_service_only(pid, __prepare_to_suspend_services);
1619 #ifdef _APPFW_FEATURE_PRIVATE_SERVICE
1620 static int __get_visibility_from_cert_svc(const char *pkgid, int *visibility)
1623 const char *cert_value = NULL;
1624 pkgmgrinfo_certinfo_h certinfo = NULL;
1626 ret = pkgmgrinfo_pkginfo_create_certinfo(&certinfo);
1628 _E("pkgmgrinfo_pkginfo_create_certinfo() failed.");
1632 ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, certinfo);
1634 _E("pkgmgrinfo_pkginfo_load_certinfo() failed.");
1639 ret = pkgmgrinfo_pkginfo_get_cert_value(certinfo, PMINFO_DISTRIBUTOR_ROOT_CERT,
1641 if (ret != 0 || cert_value == NULL) {
1642 _E("pkgmgrinfo_pkginfo_get_cert_value() failed.");
1647 ret = cert_svc_get_visibility_by_root_certificate(cert_value,
1648 strlen(cert_value), visibility);
1650 _E("cert_svc_get_visibility_by_root_cert() failed. err = [%d]", ret);
1654 _D("visibility = [%d]", *visibility);
1657 pkgmgrinfo_pkginfo_destroy_certinfo(certinfo);
1662 static int __can_share(const char *path, const char *pkgid)
1664 struct stat path_stat;
1666 if (access(path, F_OK) != 0)
1669 if (stat(path, &path_stat) != 0)
1672 if (!S_ISREG(path_stat.st_mode))
1677 snprintf(buf, sizeof(buf) - 1, "/opt/usr/apps/%s/data/", pkgid);
1678 if (strncmp(path, buf, strlen(buf)) != 0)
1684 static int __get_current_security_attribute(int pid, char *buf, int size)
1688 char path[1024] = { 0, };
1690 snprintf(path, sizeof(path) - 1, "/proc/%d/attr/current", pid);
1691 fd = open(path, O_RDONLY);
1695 ret = read(fd, buf, size - 1);
1707 static int __get_exec_label_by_pid(int pid, char** exec_label)
1709 const char *appid = NULL;
1710 const char *exec = NULL;
1711 const char *type = NULL;
1712 const struct appinfo *ai = NULL;
1713 char attr[1024] = { 0, };
1715 if (__get_current_security_attribute(pid, attr, sizeof(attr)) == 0) {
1716 *exec_label = strdup(attr);
1720 appid = _status_app_get_appid_bypid(pid);
1722 ai = appinfo_find(_laf, appid);
1723 exec = appinfo_get_value(ai, AIT_EXEC);
1724 type = appinfo_get_value(ai, AIT_TYPE);
1727 if (strcmp("wgt", type) == 0) {
1728 if (smack_lgetlabel(exec, exec_label, SMACK_LABEL_EXEC) == 0)
1731 if (smack_getlabel(exec, exec_label, SMACK_LABEL_EXEC) == 0)
1740 static int __get_exec_label_by_appid(const char *appid, char** exec_label)
1742 const char *exec = NULL;
1743 const char *type = NULL;
1744 const struct appinfo *ai = NULL;
1747 ai = appinfo_find(_laf, appid);
1748 exec = appinfo_get_value(ai, AIT_EXEC);
1749 type = appinfo_get_value(ai, AIT_TYPE);
1752 if (strcmp("wgt", type) == 0) {
1753 if (smack_lgetlabel(exec, exec_label, SMACK_LABEL_EXEC) == 0)
1756 if (smack_getlabel(exec, exec_label, SMACK_LABEL_EXEC) == 0)
1765 static int __get_owner_pid(int caller_pid, bundle *kb)
1767 char *org_caller = NULL;
1769 if (bundle_get_str(kb, AUL_K_ORG_CALLER_PID, &org_caller) == BUNDLE_ERROR_NONE) {
1770 int org_caller_pid = atoi(org_caller);
1771 char *c_exec_label = NULL;
1773 if (__get_exec_label_by_pid(caller_pid, &c_exec_label) == 0) {
1776 (strcmp(APP_SELECTOR, c_exec_label) == 0 ||
1777 strcmp(SHARE_PANEL, c_exec_label) == 0))
1778 caller_pid = org_caller_pid;
1788 static int __get_exec_label(char **caller_exec_label, char **callee_exec_label,
1789 int caller_pid, const char *appid)
1791 char *label_caller = NULL;
1794 if (__get_exec_label_by_pid(caller_pid, &label_caller) != 0) {
1798 if (__get_exec_label_by_appid(appid, &label) != 0) {
1803 *caller_exec_label = label_caller;
1804 *callee_exec_label = label;
1808 static int __grant_temporary_permission(int caller_pid, const char *appid, bundle *kb,
1809 char **out_caller_exec_label, char **out_callee_exec_label,
1812 int type = bundle_get_type(kb, AUL_SVC_DATA_PATH);
1814 const char **path_array = NULL;
1816 char *caller_exec_label = NULL;
1817 char *callee_exec_label = NULL;
1819 char **paths = NULL;
1822 const char *tmp_appid = NULL;
1823 const char *pkgid = NULL;
1824 const struct appinfo *ai = NULL;
1827 case BUNDLE_TYPE_STR:
1828 bundle_get_str(kb, AUL_SVC_DATA_PATH, &path);
1831 _E("path was null");
1835 owner_pid = __get_owner_pid(caller_pid, kb);
1836 owner_pid = getpgid(owner_pid); /* for webapp */
1837 tmp_appid = _status_app_get_appid_bypid(owner_pid);
1839 ai = appinfo_find(_laf, tmp_appid);
1840 pkgid = appinfo_get_value(ai, AIT_PKGID);
1842 if (__can_share(path, pkgid) != 0) {
1843 _E("__can_share() returned an error");
1847 if (__get_exec_label(&caller_exec_label, &callee_exec_label, owner_pid,
1849 _E("__get_exec_label() returned an error");
1853 paths = (char**)malloc(sizeof(char*) * 3);
1855 _E("Out of memory");
1859 paths[0] = strdup(path);
1865 case BUNDLE_TYPE_STR_ARRAY:
1866 path_array = bundle_get_str_array(kb, AUL_SVC_DATA_PATH, &len);
1867 if (!path_array || len <= 0) {
1868 _E("path_array was null");
1872 owner_pid = __get_owner_pid(caller_pid, kb);
1873 owner_pid = getpgid(owner_pid); /* for webapp */
1874 tmp_appid = _status_app_get_appid_bypid(owner_pid);
1875 ai = appinfo_find(_laf, tmp_appid);
1876 pkgid = appinfo_get_value(ai, AIT_PKGID);
1878 if (__get_exec_label(&caller_exec_label, &callee_exec_label, owner_pid,
1880 _E("__get_exec_label() returned an error");
1884 paths = (char**)malloc(sizeof(char*) * (len + 2));
1886 _E("Out of memory");
1891 for (i = 0; i < len; i++) {
1892 if (__can_share(path_array[i], pkgid) == 0) {
1893 paths[cnt++] = strdup(path_array[i]);
1898 paths[cnt + 1] = NULL;
1908 if (bundle_get_str(kb, AUL_SVC_K_URI, &path) == BUNDLE_ERROR_NONE) {
1910 _E("path was null");
1914 if (strncmp(path, "file://", 7) == 0)
1917 _E("file wasn't started with file://");
1921 if (owner_pid == -1) {
1922 owner_pid = __get_owner_pid(caller_pid, kb);
1923 owner_pid = getpgid(owner_pid); /* for webapp */
1926 tmp_appid = _status_app_get_appid_bypid(owner_pid);
1927 ai = appinfo_find(_laf, tmp_appid);
1928 pkgid = appinfo_get_value(ai, AIT_PKGID);
1930 if (__can_share(path, pkgid) != 0) {
1931 _E("__can_share() returned an error");
1935 if (!caller_exec_label && !callee_exec_label)
1936 if (__get_exec_label(&caller_exec_label, &callee_exec_label, owner_pid,
1938 _E("__get_exec_label() returned an error");
1943 paths = (char**)malloc(sizeof(char*) * 2);
1945 _E("Out of memory");
1949 paths[0] = strdup(path);
1954 if (paths[i] == NULL) {
1955 paths[i] = strdup(path);
1964 if (ret == 0 && caller_exec_label && paths) {
1965 _D("grant permission %s : %s : %s", paths[0], caller_exec_label,
1967 int r = security_server_perm_apply_sharing(NULL, (const char**)paths, caller_exec_label, callee_exec_label);
1968 if (r != SECURITY_SERVER_API_SUCCESS) {
1969 _E("security_server_perm_apply_sharing() returned an error %d",r);
1972 *out_caller_exec_label = caller_exec_label;
1973 *out_callee_exec_label = callee_exec_label;
1976 caller_exec_label = NULL;
1977 callee_exec_label = NULL;
1982 if (caller_exec_label)
1983 free(caller_exec_label);
1984 if (callee_exec_label)
1985 free(callee_exec_label);
1989 if (paths[i] == NULL) {
2000 static void __add_shared_info(int pid, const char *caller_exec_label, const char *callee_exec_label, char **paths)
2002 _status_set_exec_label(pid, callee_exec_label);
2003 _status_add_shared_info(pid, caller_exec_label, paths);
2006 int _revoke_temporary_permission(int pid)
2008 GList *list = _status_get_shared_info_list(pid);
2009 const char *callee_label = _status_get_exec_label(pid);
2011 if (!list || !callee_label) {
2012 _E("list or callee_label was null");
2017 shared_info_t *sit = (shared_info_t*)list->data;
2019 _D("revoke permission %s : %s", sit->owner_exec_label, callee_label);
2020 int r = security_server_perm_drop_sharing(NULL, (const char**)sit->paths,
2021 sit->owner_exec_label, callee_label);
2023 if (r != SECURITY_SERVER_API_SUCCESS)
2024 _E("revoke error %d",r);
2026 list = g_list_next(list);
2028 return _status_clear_shared_info_list(pid);
2031 int _start_app(const char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_uid, int fd)
2033 const struct appinfo *ai;
2034 const struct appinfo *caller_ai;
2036 const char *multiple = NULL;
2037 const char *app_path = NULL;
2038 const char *pkg_type = NULL;
2039 const char *component_type = NULL;
2041 char tmp_pid[MAX_PID_STR_BUFSZ];
2042 const char *permission;
2044 const char *preload;
2045 const char *pkg_status;
2046 const char *operation;
2047 char caller_appid[256] = {0,};
2048 char* caller = NULL;
2049 char* old_caller = NULL;
2050 pkgmgrinfo_cert_compare_result_type_e compare_result;
2051 int delay_reply = 0;
2052 int pad_pid = NO_LAUNCHPAD_PID;
2055 char trm_buf[MAX_PACKAGE_STR_SIZE];
2056 gboolean is_group_app = FALSE;
2057 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2058 char log_status[AUL_PR_NAME] = {0,};
2061 #ifdef _APPFW_FEATURE_FAKE_EFFECT
2062 const char *fake_effect;
2063 int effect_mode = 0;
2064 #ifdef _APPFW_FEATURE_WMS_CONNECTION_CHECK
2065 int wmanager_connected = 0;
2068 #endif /* _APPFW_FEATURE_FAKE_EFFECT */
2070 #ifdef _APPFW_FEATURE_AMD_KEY
2071 const char *caller_component_type = NULL;
2073 int prelaunch_attribute = 0;
2075 bool bg_allowed = false;
2077 gboolean can_attach;
2078 app_group_launch_mode launch_mode;
2079 char *caller_exec_label = NULL;
2080 char *callee_exec_label = NULL;
2081 char **paths = NULL;
2082 int grant_permission = 0;
2084 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:AMD:START_APP");
2085 if (appid == NULL || kb == NULL
2086 || caller_pid < 0 || fd < 0) {
2087 _D("invalid parameter");
2089 __real_send(fd, -1);
2090 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2094 snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", caller_pid);
2095 bundle_add(kb, AUL_K_CALLER_PID, tmp_pid);
2097 if (cmd == APP_START_RES)
2098 bundle_add(kb, AUL_K_WAIT_RESULT, "1");
2100 caller = _status_app_get_appid_bypid(caller_pid);
2101 if(caller == NULL) {
2102 ret = aul_app_get_appid_bypid(caller_pid, caller_appid, sizeof(caller_appid));
2104 bundle_add(kb, AUL_K_CALLER_APPID, caller_appid);
2105 caller = caller_appid;
2107 _E("no caller appid info, ret: %d", ret);
2110 bundle_add(kb, AUL_K_CALLER_APPID, caller);
2114 SECURE_LOGW("caller appid : %s", caller);
2116 _W("caller pid : %d", caller_pid);
2118 ai = appinfo_find(_laf, appid);
2121 __real_send(fd, -ENOAPP);
2122 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2125 pkg_status = appinfo_get_value(ai, AIT_STATUS);
2126 if(pkg_status && (strncmp(pkg_status, "blocking", 8) == 0 || strncmp(pkg_status, "restart", 7) == 0) ) {
2128 __real_send(fd, -EREJECTED);
2129 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2131 } else if(pkg_status && strncmp(pkg_status, "unmounted", 9) == 0 ) {
2133 __real_send(fd, -1);
2134 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2139 app_path = appinfo_get_value(ai, AIT_EXEC);
2140 pkg_type = appinfo_get_value(ai, AIT_TYPE);
2141 permission = appinfo_get_value(ai, AIT_PERM);
2142 pkgid = appinfo_get_value(ai, AIT_PKGID);
2143 component_type = appinfo_get_value(ai, AIT_COMPTYPE);
2145 if (pkg_type == NULL)
2146 pkg_type = "unknown";
2148 #ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
2149 const char *tep_name = NULL;
2151 tep_name = appinfo_get_value(ai, AIT_TEP);
2152 if (tep_name != NULL) {
2153 __send_mount_request(ai, tep_name, kb);
2156 operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__");
2157 caller_ai = appinfo_find(_laf, caller);
2158 #ifdef _APPFW_FEATURE_AMD_KEY
2159 caller_component_type = appinfo_get_value(caller_ai, AIT_COMPTYPE);
2162 if(permission && strncmp(permission, "signature", 9) == 0 ) {
2163 if(caller_uid != 0 && (cmd == APP_START
2164 || cmd == APP_START_RES
2165 || cmd == APP_START_ASYNC
2166 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
2167 || cmd == APP_START_MULTI_INSTANCE
2171 preload = appinfo_get_value(caller_ai, AIT_PRELOAD);
2172 if( preload && strncmp(preload, "true", 4) != 0 ) {
2173 ret = pkgmgrinfo_pkginfo_compare_app_cert_info(caller, appid, &compare_result);
2174 if (ret != PMINFO_R_OK) {
2176 _E("compare app cert info failed : %d", ret);
2177 if(cmd == APP_START_ASYNC)
2180 __real_send(fd, pid);
2181 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2184 if(compare_result != PMINFO_CERT_COMPARE_MATCH) {
2185 pid = -EILLEGALACCESS;
2186 if(cmd == APP_START_ASYNC)
2189 __real_send(fd, pid);
2190 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2197 if(operation && caller_ai) {
2198 ret = __check_app_control_privilege(operation, caller_pid, caller_ai);
2200 if (cmd == APP_START_ASYNC)
2203 __real_send(fd, ret);
2204 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2209 if(__check_mode(ai) < 0) {
2211 if(cmd == APP_START_ASYNC)
2214 __real_send(fd, pid);
2215 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2219 pkgmgrinfo_client_request_enable_external_pkg((char *)pkgid);
2221 if (component_type && (strncmp(component_type, APP_TYPE_UI, strlen(APP_TYPE_UI)) == 0
2222 || strncmp(component_type, APP_TYPE_WATCH, strlen(APP_TYPE_WATCH)) == 0
2223 || strncmp(component_type, APP_TYPE_WIDGET, strlen(APP_TYPE_WIDGET)) == 0 )) {
2224 gboolean new_process = FALSE;
2226 multiple = appinfo_get_value(ai, AIT_MULTI);
2227 if (!multiple || strncmp(multiple, "false", 5) == 0) {
2228 pid = _status_app_is_running_v2(appid);
2229 } else if (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/view", 512) == 0){
2230 old_caller = _status_get_caller_by_appid(appid);
2231 if(old_caller && caller) {
2232 if(strncmp(old_caller, caller, MAX_PACKAGE_STR_SIZE) == 0) {
2233 pid = _status_app_is_running_v2(appid);
2238 if (strncmp(component_type, APP_TYPE_UI, strlen(APP_TYPE_UI)) == 0) {
2239 if (app_group_is_group_app(kb)) {
2241 is_group_app = TRUE;
2247 st = _status_get_app_info_status(pid);
2249 if (pid == -1 || st == STATUS_DYING) {
2251 int found_lpid = -1;
2253 if (app_group_find_singleton(appid, &found_pid, &found_lpid) == 0) {
2255 new_process = FALSE;
2260 if (app_group_can_start_app(appid, kb, &can_attach, &lpid, &launch_mode) != 0 ) {
2261 _E("can't make group info");
2262 pid = -EILLEGALACCESS;
2263 if (cmd == APP_START_ASYNC)
2266 __real_send(fd, pid);
2267 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2271 if (can_attach && lpid == found_lpid) {
2272 _E("can't launch singleton app in the same group");
2273 pid = -EILLEGALACCESS;
2274 if (cmd == APP_START_ASYNC)
2277 __real_send(fd, pid);
2278 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2282 if (found_pid != -1)
2283 app_group_clear_top(found_pid);
2286 if (pid == -1 && can_attach)
2287 pid = app_group_find_pid_from_recycle_bin(appid);
2290 #ifdef _APPFW_FEATURE_APP_CONTROL_LITE
2291 char app_path_link[512] = {0,};
2292 const char *caller_app_path = NULL;
2293 char caller_app_path_link[512] = {0,};
2295 caller_app_path = appinfo_get_value(caller_ai, AIT_EXEC);
2297 SECURE_LOGD("callee path(%s) caller path(%s)", app_path, caller_app_path);
2299 readlink(app_path, app_path_link, 512);
2300 readlink(caller_app_path, caller_app_path_link, 512);
2302 SECURE_LOGD("callee link(%s) caller link(%s)", app_path_link, caller_app_path_link);
2304 if(strncmp(app_path_link, "/usr/bin/ug-client", 512) == 0) {
2305 if (strcmp(caller, "org.tizen.app-selector") == 0){
2306 pid = atoi(bundle_get_val(kb,AUL_K_ORG_CALLER_PID));
2307 bundle_add(kb, "__AUL_UG_EXEC__", app_path);
2308 SECURE_LOGD("app_path : %s , ug id(%s)", app_path, bundle_get_val(kb, "__AUL_UG_ID__"));
2309 } else if(strncmp(caller_app_path_link, "/usr/bin/ug-client", 512) == 0) {
2310 __real_send(fd, -EUGLOCAL_LAUNCH);
2311 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2318 #ifdef _APPFW_FEATURE_AMD_KEY
2319 if (caller_component_type && strncmp(caller_component_type, APP_TYPE_UI, strlen(APP_TYPE_UI)) == 0) {
2320 Ecore_X_Window in_win;
2321 in_win = _input_window_get();
2323 ret = ecore_x_pointer_grab(in_win);
2324 _D("win(%x) ecore_x_pointer_grab(%d)", in_win, ret);
2326 if(_key_grab(KEY_BACK, EXCLUSIVE_GRAB) < 0) {
2327 _W("back key grab error");
2329 _D("back key grab");
2335 if (__grant_temporary_permission(caller_pid, appid, kb,
2336 &caller_exec_label, &callee_exec_label, &paths) == 0)
2337 grant_permission = 1;
2338 status = _status_get_app_info_status(pid);
2339 if (pid > 0 && status != STATUS_DYING) {
2340 if (caller_pid == pid) {
2341 SECURE_LOGD("caller process & callee process is same.[%s:%d]", appid, pid);
2342 pid = -ELOCALLAUNCH_ID;
2344 if(strncmp(pkg_type, "wgt", 3) == 0) {
2345 __pre_launching_processing(appid);
2348 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2349 strncpy(log_status, "RESUMING", strlen("RESUMING"));
2352 proc_group_change_status(PROC_CGROUP_SET_RESUME_REQUEST, pid, (char *)appid);
2354 if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) {
2360 } else if (cmd != APP_RESUME) {
2361 if(status == STATUS_DYING && pid > 0) {
2362 r = kill(pid, SIGKILL);
2364 _D("send SIGKILL: %s", strerror(errno));
2367 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2368 strncpy(log_status, "LAUNCHING", strlen("LAUNCHING"));
2371 // 2.4 bg categorized ui app || watch || widget -> bg allowed (2.3 ui app -> not allowed)
2372 prelaunch_attribute = __get_prelaunch_attribute(ai);
2373 if ((strncmp(component_type, APP_TYPE_UI, sizeof(APP_TYPE_UI)) == 0
2374 && (prelaunch_attribute & RESOURCED_ALLOWED_BG_ATTRIBUTE))
2375 || (strncmp(component_type, APP_TYPE_WATCH, sizeof(APP_TYPE_WATCH)) == 0)
2376 || (strncmp(component_type, APP_TYPE_WIDGET, sizeof(APP_TYPE_WIDGET)) == 0)) {
2377 _D("[__SUSPEND__] allowed background, appid: %s", appid);
2378 bundle_add(kb, AUL_K_ALLOWED_BG, "ALLOWED_BG");
2381 __send_proc_prelaunch_signal(appid, pkgid, prelaunch_attribute);
2383 #ifdef _APPFW_FEATURE_FAKE_EFFECT
2384 fake_effect = bundle_get_val(kb, "__FAKE_EFFECT__");
2387 #ifdef _APPFW_FEATURE_CPU_BOOST
2388 if (cmd == APP_OPEN || operation != NULL ||
2389 (caller != NULL && strcmp(caller, "org.tizen.wnotification2") == 0) ||
2390 (caller != NULL && strcmp(caller, "org.tizen.wnotiboard-popup") == 0)) {
2393 snprintf(val, sizeof(val), "%d", APP_BOOSTING_PERIOD);
2396 ret = invoke_dbus_method_sync(SYSTEM_BUS_NAME, SYSTEM_OBJECT_PATH,
2397 SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, "i", arr);
2398 _D("%s-%s : %d", SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, ret);
2402 #ifdef _APPFW_FEATURE_FAKE_EFFECT
2405 * default mode : fake effect off, 1.6 MHZ off
2407 * full mode : fake effect on, 1.6 MHZ on
2409 * fake effect mode : fake effect on, 1.6 MHZ off
2411 * 1.6 MHZ mode : faek effect off, 1.6MHZ on
2414 vconf_get_int(VCONFKEY_AMD_EFFECT_IMAGE_ENABLE, &effect_mode);
2415 #ifdef _APPFW_FEATURE_WMS_CONNECTION_CHECK
2416 vconf_get_bool(VCONFKEY_WMS_WMANAGER_CONNECTED, &wmanager_connected);
2418 //_D("*******[effect_mode] Mode : %d\n ", effect_mode );
2420 if ( ( cmd == APP_OPEN ||
2421 ( (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/main", 512) == 0)
2422 && !(fake_effect != NULL && strncmp(fake_effect, "OFF", 3) == 0) )
2423 ) && (effect_mode == 1 || effect_mode == 2)
2424 #ifdef _APPFW_FEATURE_WMS_CONNECTION_CHECK
2425 && wmanager_connected == true
2428 char image_filename[256] = {0,};
2429 const char *portraitimg = NULL;
2430 const char *landscapeimg = NULL;
2431 #ifdef _APPFW_FEATURE_CHANGEABLE_COLOR
2432 const char *effectimg_type = NULL;
2434 const char *indicator = NULL;
2435 int screen_mode = 0;
2436 int rotate_allowed = 0;
2440 //vconf_get_int(PHONE_ORIENTATION_MODE, &screen_mode);
2441 screen_mode = invoke_dbus_method_sync(ROTATION_BUS_NAME, ROTATION_OBJECT_PATH,
2442 ROTATION_INTERFACE_NAME, ROTATION_METHOD_NAME, "i", NULL);
2443 _D("%s-%s : %d", ROTATION_INTERFACE_NAME, ROTATION_METHOD_NAME, screen_mode);
2444 vconf_get_bool(PHONE_ROTATE_LOCK, &rotate_allowed); /*TODO: use vconf_notify_key_changed()*/
2445 portraitimg = appinfo_get_value(ai, AIT_EFFECTIMAGEPORT);
2446 landscapeimg = appinfo_get_value(ai, AIT_EFFECTIMAGELAND);
2447 #ifdef _APPFW_FEATURE_CHANGEABLE_COLOR
2448 effectimg_type = appinfo_get_value(ai, AIT_EFFECTTYPE);
2450 indicator = appinfo_get_value(ai, AIT_INDICATOR_DISP);
2451 /*Currently we assume apps supporting launching effect supports portrait mode*/
2452 if (indicator && portraitimg) {
2453 if (rotate_allowed == false) {
2456 if ((screen_mode == 2 || screen_mode == 4) && (rotate_allowed == true)) {
2457 /*if there is no landscape image, that means app supports only portrait mode.*/
2459 snprintf(image_filename, 255, "%s", landscapeimg);
2462 snprintf(image_filename, 255, "%s", portraitimg);
2464 if (access(image_filename, R_OK) == 0) {
2465 #ifdef _APPFW_FEATURE_CHANGEABLE_COLOR
2466 if(strncmp(effectimg_type, "edj-dark", strlen(effectimg_type)) == 0) {
2469 } else if (strncmp(effectimg_type, "edj-light", strlen(effectimg_type)) == 0) {
2472 } else if (strncmp(effectimg_type, "edj-default", strlen(effectimg_type)) == 0) {
2483 r = snprintf(xml_filename, 255, "/usr/apps/%s/shared/res/tables/%s_ChangeableColorInfo.xml", pkgid, pkgid);
2484 if (access(xml_filename, R_OK) == 0) {
2485 //snprintf(image_filename, 255, "%s:%s", image_filename, xml_filename);
2486 strcat(image_filename, ":");
2487 strcat(image_filename, xml_filename);
2490 r = snprintf(xml_filename, 255, "/opt/usr/apps/%s/shared/res/tables/%s_ChangeableColorInfo.xml", pkgid, pkgid);
2491 if (access(xml_filename, R_OK) == 0) {
2492 //snprintf(image_filename, 255, "%s:%s", image_filename, xml_filename);
2493 strcat(image_filename, ":");
2494 strcat(image_filename, xml_filename);
2499 #ifndef _APPFW_FEATURE_DEFAULT_FAKE_IMAGE
2500 __amd_effect_image_file_set(image_filename);
2502 if(file_type == 1) {
2503 __amd_effect_image_file_set("/usr/share/splash_images/type0_portrait.bmp");
2505 __amd_effect_image_file_set(image_filename);
2508 __amd_send_message_to_e17(screen_mode, indicator, file_type, theme);
2512 #endif /* _APPFW_FEATURE_FAKE_EFFECT */
2514 #ifdef _APPFW_FEATURE_DEBUG_LAUNCHPAD
2515 if (bundle_get_type(kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) {
2516 pad_pid = DEBUG_LAUNCHPAD_PID;
2517 } else if (strncmp(pkg_type, "wgt", 3) == 0) {
2518 pad_pid = WEB_LAUNCHPAD_PID;
2521 if (strncmp(pkg_type, "wgt", 3) == 0) {
2522 pad_pid = WEB_LAUNCHPAD_PID;
2525 #ifdef _APPFW_FEATURE_PROCESS_POOL
2527 const char *process_pool = appinfo_get_value(ai, AIT_POOL);
2528 _D("process_pool: %s", process_pool);
2530 const char *hwacc = appinfo_get_value(ai, AIT_HWACC);
2531 _D("h/w acceleration: %s", hwacc);
2533 SECURE_LOGD("appid: %s", appid);
2535 pad_pid = PROCESS_POOL_LAUNCHPAD_PID;
2536 char pad_sock[UNIX_PATH_MAX] = { 0, };
2537 snprintf(pad_sock, UNIX_PATH_MAX, "%s/%d", AUL_SOCK_PREFIX, pad_pid);
2538 if (access(pad_sock, F_OK) != 0)
2540 _W("Sending to legacy launchpad because process-pool launchpad is not initialized.");
2541 pad_pid = NO_LAUNCHPAD_PID;
2544 #endif //_APPFW_FEATURE_PROCESS_POOL
2545 _W("pad pid(%d)", pad_pid);
2546 __set_appinfo_for_launchpad(ai, kb);
2547 if (pad_pid == NO_LAUNCHPAD_PID)
2549 pid = start_process(appid, app_path, kb);
2553 pid = app_send_cmd(pad_pid, cmd, kb);
2554 if (pid == AUL_R_ENOLAUNCHPAD && pad_pid == PROCESS_POOL_LAUNCHPAD_PID) {
2555 _W("Launch with legacy way");
2556 pad_pid = NO_LAUNCHPAD_PID;
2557 pid = start_process(appid, app_path, kb);
2560 if(pid == AUL_R_ECOMM) {
2561 pid = -ENOLAUNCHPAD;
2563 aul_send_app_launch_request_signal(pid, appid, pkgid, component_type);
2564 snprintf(trm_buf, MAX_PACKAGE_STR_SIZE, "appinfo_launch:%s[PID]%d", appid, pid);
2565 __trm_app_info_send_socket(trm_buf);
2568 #ifdef _APPFW_FEATURE_AMD_KEY
2569 if(_input_window_get() != 0)
2570 ecore_x_pointer_ungrab();
2571 _D("pid(%d) ecore_x_pointer_ungrab", pid);
2572 if(_key_ungrab(KEY_BACK) < 0) {
2573 _W("back key ungrab error");
2575 _D("back key ungrab");
2580 _D("add app group info");
2581 app_group_start_app(pid, kb, lpid, can_attach, launch_mode);
2582 } else if (cmd == APP_START
2583 || cmd == APP_START_RES
2584 || cmd == APP_START_ASYNC
2585 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
2586 || cmd == APP_START_MULTI_INSTANCE
2589 app_group_restart_app(pid, kb);
2591 #ifdef _APPFW_FEATURE_AMD_KEY
2592 grab_timer_id = g_timeout_add(1000, __grab_timeout_handler, (void *)pid);
2596 else if (component_type && strncmp(component_type, APP_TYPE_SERVICE, sizeof(APP_TYPE_SERVICE)) == 0) {
2597 #ifdef _APPFW_FEATURE_PRIVATE_SERVICE
2598 const char *caller_appid = _status_app_get_appid_bypid(caller_pid);
2601 const struct appinfo *ai = NULL;
2602 const char *caller_pkgid = NULL;
2603 const char *pkgid = NULL;
2605 ai = appinfo_find(_laf, appid);
2606 pkgid = appinfo_get_value(ai, AIT_PKGID);
2607 ai = appinfo_find(_laf, caller_appid);
2608 caller_pkgid = appinfo_get_value(ai, AIT_PKGID);
2610 if (caller_pkgid && pkgid && strcmp(caller_pkgid, pkgid) != 0) {
2611 const char *launch_type = bundle_get_val(kb, OSP_K_LAUNCH_TYPE);
2613 if (launch_type == NULL || strcmp(launch_type, OSP_V_LAUNCH_TYPE_DATACONTROL) != 0) {
2614 const char *v = appinfo_get_value(ai, AIT_VISIBILITY);
2615 char num[256] = { 0, };
2620 if (__get_visibility_from_cert_svc(caller_pkgid, &vi_num) == 0) {
2621 snprintf(num, 255, "%d", vi_num);
2622 appinfo_set_value((struct appinfo*)ai, AIT_VISIBILITY, num);
2625 _E("Failed to get visibility");
2629 int visibility = atoi(v);
2630 if (!(visibility & CERT_SVC_VISIBILITY_PLATFORM)) {
2631 _E("Couldn't launch service app in other packages");
2632 __real_send(fd, -EREJECTED);
2633 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2641 pid = _status_app_is_running_v2(appid);
2643 prelaunch_attribute = __get_prelaunch_attribute(ai);
2645 // 2.4 bg-categorized svc app || 2.3 svc app -> bg allowed
2646 if ((prelaunch_attribute & RESOURCED_ALLOWED_BG_ATTRIBUTE)
2647 || !(prelaunch_attribute & RESOURCED_API_VER_2_4_ATTRIBUTE)) {
2648 _D("[__SUSPEND__] allowed backgroudn, appid: %s", appid);
2649 bundle_add(kb, AUL_K_ALLOWED_BG, "ALLOWED_BG");
2653 if (__grant_temporary_permission(caller_pid, appid, kb,
2654 &caller_exec_label, &callee_exec_label, &paths) == 0)
2655 grant_permission = 1;
2658 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2659 strncpy(log_status, "RESUMING", strlen("RESUMING"));
2661 aul_send_app_resume_request_signal(pid, appid, pkgid, APP_TYPE_SERVICE);
2664 __prepare_to_wake_services(pid);
2666 if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) {
2669 } else if (cmd != APP_RESUME) {
2670 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2671 strncpy(log_status, "LAUNCHING", strlen("LAUNCHING"));
2674 __send_proc_prelaunch_signal(appid, pkgid, prelaunch_attribute);
2676 #ifdef _APPFW_FEATURE_DEBUG_LAUNCHPAD
2677 if (bundle_get_type(kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) {
2678 SECURE_LOGD("The svcapp(%s) is launched by debug-launchpad", appid);
2679 __set_appinfo_for_launchpad(ai, kb);
2680 pid = app_send_cmd(DEBUG_LAUNCHPAD_PID, cmd, kb);
2681 if (pid == AUL_R_ECOMM) {
2682 pid = -ENOLAUNCHPAD;
2685 pid = start_process(appid, app_path, kb);
2688 pid = start_process(appid, app_path, kb);
2690 aul_send_app_launch_request_signal(pid, appid, pkgid, component_type);
2694 g_idle_add(__check_service_only, (gpointer)pid);
2698 _E("unkown application");
2702 if(cmd == APP_START_ASYNC)
2705 __real_send(fd, pid);
2708 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2709 _status_log_save(log_status, appid);
2713 _status_add_app_info_list(appid, app_path, caller, pid, pad_pid, is_group_app);
2714 _status_update_app_info_caller_pid(pid, caller_pid);
2715 if (grant_permission) {
2716 __add_shared_info(pid, caller_exec_label, callee_exec_label, paths);
2717 if (caller_exec_label) {
2718 free(caller_exec_label);
2719 caller_exec_label = NULL;
2721 if (callee_exec_label) {
2722 free(callee_exec_label);
2723 callee_exec_label = NULL;
2727 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2728 snprintf(log_status, AUL_PR_NAME, "SUCCESS: %d", pid);
2729 _status_log_save(log_status, appid);
2732 #ifdef _APPFW_FEATURE_APP_CHECKER
2733 pkg_type = appinfo_get_value(ai, AIT_TYPE);
2737 ret = ac_server_check_launch_privilege(appid, pkg_type, pid);
2738 if (ret != AC_R_ERROR) {
2739 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2742 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2747 #ifdef _APPFW_FEATURE_AMD_MODULE_LOG
2749 _status_log_save("FAILURE", appid);
2753 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
2757 int __e17_status_handler(int pid, int status, void *data)
2759 if (status == PROC_STATUS_FG) {
2760 #ifdef _APPFW_FEATURE_AMD_KEY
2761 _D("pid(%d) status(%d)", pid, status);
2762 if(_input_window_get() != 0)
2763 ecore_x_pointer_ungrab();
2764 if(_key_ungrab(KEY_BACK) < 0) {
2765 _W("back key ungrab error");
2767 _D("back key ungrab");
2769 g_source_remove(grab_timer_id);
2772 _status_update_app_info_list(pid, STATUS_VISIBLE);
2773 } else if (status == PROC_STATUS_BG) {
2774 _status_update_app_info_list(pid, STATUS_BG);
2780 int _launch_init(struct amdmgr* amd)
2786 amd_cmdline = __proc_get_cmdline_bypid(getpid());
2790 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
2792 _E("dbus_bus_get error");
2796 ret = aul_listen_e17_status_signal(__e17_status_handler, NULL);
2798 _D("ret : %d", ret);
2800 __preexec_init(0, NULL);
2805 void _set_atom_effect(void)
2807 ATOM_IMAGE_EFFECT = ecore_x_atom_get(atom_name);
2810 void __set_appinfo_for_launchpad(const struct appinfo *ai, bundle *kb) {
2813 _D("Add hwacc, taskmanage, app_path and pkg_type into bundle for sending those to launchpad.");
2814 ret = bundle_del(kb, AUL_K_HWACC);
2815 if (ret != BUNDLE_ERROR_NONE)
2816 _D("bundle_del error: %d", ret);
2817 ret = bundle_add(kb, AUL_K_HWACC, appinfo_get_value(ai, AIT_HWACC));
2818 if (ret != BUNDLE_ERROR_NONE)
2819 _E("failed to set AUL_K_HWACC: ret(%d)", ret);
2822 bundle_del(kb, AUL_K_TASKMANAGE);
2823 if (ret != BUNDLE_ERROR_NONE)
2824 _D("bundle_del error: %d", ret);
2825 bundle_add(kb, AUL_K_TASKMANAGE, appinfo_get_value(ai, AIT_TASKMANAGE));
2826 if (ret != BUNDLE_ERROR_NONE)
2827 _E("failed to set AUL_K_TASKMANAGE: ret(%d)", ret);
2829 bundle_del(kb, AUL_K_EXEC);
2830 if (ret != BUNDLE_ERROR_NONE)
2831 _D("bundle_del error: %d", ret);
2832 bundle_add(kb, AUL_K_EXEC, appinfo_get_value(ai, AIT_EXEC));
2833 if (ret != BUNDLE_ERROR_NONE)
2834 _E("failed to set AUL_K_EXEC: ret(%d)", ret);
2836 bundle_del(kb, AUL_K_PACKAGETYPE);
2837 if (ret != BUNDLE_ERROR_NONE)
2838 _D("bundle_del error: %d", ret);
2839 bundle_add(kb, AUL_K_PACKAGETYPE, appinfo_get_value(ai, AIT_TYPE));
2840 if (ret != BUNDLE_ERROR_NONE)
2841 _E("failed to set AUL_K_PACKAGETYPE: ret(%d)", ret);
2843 bundle_del(kb, AUL_K_INTERNAL_POOL);
2844 if (ret != BUNDLE_ERROR_NONE)
2845 _D("bundle_del error: %d", ret);
2846 bundle_add(kb, AUL_K_INTERNAL_POOL, appinfo_get_value(ai, AIT_POOL));
2847 if (ret != BUNDLE_ERROR_NONE)
2848 _E("failed to set AUL_K_INTERNAL_POOL: ret(%d)", ret);
2850 bundle_del(kb, AUL_K_PKGID);
2851 if (ret != BUNDLE_ERROR_NONE)
2852 _D("bundle_del error: %d", ret);
2853 bundle_add(kb, AUL_K_PKGID, appinfo_get_value(ai, AIT_PKGID));
2854 if (ret != BUNDLE_ERROR_NONE)
2855 _E("failed to set AUL_K_PKGID: ret(%d)", ret);