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.
24 #include <Ecore_Input.h>
28 #include <Ecore_Evas.h>
33 #ifdef _APPFW_FEATURE_APP_CHECKER
34 #include <app-checker-server.h>
40 #include <sys/types.h>
43 #include <sys/prctl.h>
44 #include <sys/resource.h>
45 #include <pkgmgr-info.h>
47 #include <proc_stat.h>
50 #include "amd_config.h"
51 #include "amd_launch.h"
52 #include "amd_appinfo.h"
53 #include "amd_status.h"
56 #include "simple_util.h"
57 #include "amd_cgutil.h"
59 #include "app_signal.h"
63 #include "access_control.h"
66 #define TERM_WAIT_SEC 3
69 #define AUL_PR_NAME 16
70 #define PATH_APP_ROOT "/opt/usr/apps"
71 #define PATH_DATA "/data"
72 #define SDK_CODE_COVERAGE "CODE_COVERAGE"
73 #define SDK_DYNAMIC_ANALYSIS "DYNAMIC_ANALYSIS"
74 #define PATH_DA_SO "/home/developer/sdk_tools/da/da_probe.so"
76 #define PHONE_ORIENTATION_MODE "memory/private/sensor/10001"
77 #define AMD_EFFECT_IMAGE_ENABLE "db/setting/effect_image"
78 #define PHONE_ROTATE_LOCK "db/setting/auto_rotate_screen"
80 #define SYS_MIN_CPU_LOCK_FILE "/sys/devices/system/cpu/cpufreq/slp/min_cpu_lock"
81 #define MIN_CPU_LCK_CNT 0
82 #define MAX_CPU_LCK_CNT 2
84 #define HIDE_INDICATOR 0
85 #define SHOW_INDICATOR 1
87 #ifdef _APPFW_FEATURE_CPU_BOOST
88 #define APP_BOOSTING_PERIOD 1500 //msec
91 static char *amd_cmdline;
93 struct appinfomgr *_laf;
101 /*Unused data structure. Will be removed*/
103 char *pkg_name; /* package */
104 char *app_path; /* exec */
105 char *original_app_path; /* exec */
106 int multiple; /* x_slp_multiple */
108 } app_info_from_pkgmgr;
111 static GList *_kill_list;
116 guint tid; /* timer ID */
120 static const char *atom_name = "_E_COMP_FAKE_LAUNCH_IMAGE"; // Atomic ID string
121 static Ecore_X_Atom ATOM_IMAGE_EFFECT; //Atomic ID
122 static void __amd_effect_image_file_set(char *image_file);
123 static void __amd_send_message_to_e17(int screenmode, const char * indicator, int effect_type, int theme);
124 static int __amd_change_min_cpulock_count(int value);
125 static Eina_Bool __amd_restore_min_cpulock_count_cb(void *data);
126 static void __set_reply_handler(int fd, int pid, int clifd, int cmd);
127 static void __real_send(int clifd, int ret);
129 static void _set_sdk_env(const char* appid, char* str) {
130 char buf[MAX_LOCAL_BUFSZ];
133 _D("key : %s / value : %s", AUL_K_SDK, str);
134 /* http://gcc.gnu.org/onlinedocs/gcc/Cross_002dprofiling.html*/
135 /* GCOV_PREFIX contains the prefix to add to the absolute paths in the object file. */
136 /* Prefix can be absolute, or relative. The default is no prefix. */
137 /* GCOV_PREFIX_STRIP indicates the how many initial directory names */
138 /* to stripoff the hardwired absolute paths. Default value is 0. */
139 if (strncmp(str, SDK_CODE_COVERAGE, strlen(str)) == 0) {
140 snprintf(buf, MAX_LOCAL_BUFSZ, PATH_APP_ROOT"/%s"PATH_DATA, appid);
141 ret = setenv("GCOV_PREFIX", buf, 1);
142 _D("GCOV_PREFIX : %d", ret);
143 ret = setenv("GCOV_PREFIX_STRIP", "4096", 1);
144 _D("GCOV_PREFIX_STRIP : %d", ret);
145 } else if (strncmp(str, SDK_DYNAMIC_ANALYSIS, strlen(str)) == 0) {
146 ret = setenv("LD_PRELOAD", PATH_DA_SO, 1);
147 _D("LD_PRELOAD : %d", ret);
151 #define USE_ENGINE(engine) setenv("ELM_ENGINE", engine, 1);
153 static void _set_env(const char *appid, bundle * kb, const char *hwacc)
156 const char **str_array;
160 setenv("PKG_NAME", appid, 1);
164 str = bundle_get_val(kb, AUL_K_STARTTIME);
166 setenv("APP_START_TIME", str, 1);
168 if(bundle_get_type(kb, AUL_K_SDK) & BUNDLE_TYPE_ARRAY) {
169 str_array = bundle_get_str_array(kb, AUL_K_SDK, &len);
170 if(str_array != NULL) {
171 for (i = 0; i < len; i++) {
172 _D("index : [%d]", i);
173 _set_sdk_env(appid, (char *)str_array[i]);
177 str = bundle_get_val(kb, AUL_K_SDK);
179 _set_sdk_env(appid, (char *)str);
183 setenv("HWACC", hwacc, 1);
186 static void _prepare_exec(const char *appid, bundle *kb)
188 const struct appinfo *ai;
189 const char *app_path = NULL;
190 const char *pkg_type = NULL;
192 char process_name[AUL_PR_NAME];
198 signal(SIGINT, SIG_DFL);
199 signal(SIGTERM, SIG_DFL);
200 signal(SIGCHLD, SIG_DFL);
202 ai = appinfo_find(_laf, appid);
204 app_path = appinfo_get_value(ai, AIT_EXEC);
205 pkg_type = appinfo_get_value(ai, AIT_TYPE);
206 hwacc = appinfo_get_value(ai, AIT_HWACC);
209 _D("appid : %s / pkg_type : %s / app_path : %s ", appid, pkg_type, app_path);
210 if (strncmp(pkg_type, "wgt", 3) !=0 && (ret = __set_access(appid, pkg_type, app_path)) < 0) {
211 _D("fail to set privileges - check your package's credential : %d\n", ret);
215 /* SET DUMPABLE - for coredump*/
216 prctl(PR_SET_DUMPABLE, 1);
218 /* SET PROCESS NAME*/
219 if (app_path == NULL) {
220 _D("app_path should not be NULL - check menu db");
223 file_name = strrchr(app_path, '/') + 1;
224 if (file_name == NULL) {
225 _D("can't locate file name to execute");
228 memset(process_name, '\0', AUL_PR_NAME);
229 snprintf(process_name, AUL_PR_NAME, "%s", file_name);
230 prctl(PR_SET_NAME, process_name);
233 _set_env(appid, kb, hwacc);
236 static int _add_cgroup(struct cginfo *cg, const char *group, int pid)
240 r = cgutil_exist_group(cg, CTRL_MGR, group);
242 _E("exist check error: %s", strerror(errno));
246 if (r == 0) { /* not exist */
247 r = cgutil_create_group(cg, CTRL_MGR, group);
249 _E("create group error");
254 r = cgutil_group_add_pid(cg, CTRL_MGR, group, pid);
256 _E("add pid to group error");
257 cgutil_remove_group(cg, CTRL_MGR, group);
264 static char **__create_argc_argv(bundle * kb, int *margc)
269 argc = bundle_export_to_argv(kb, &argv);
274 static void _do_exec(struct cginfo *cg, const char *cmd, const char *group, bundle *kb)
283 r = _add_cgroup(cg, group, getpid());
287 b = g_shell_parse_argv(cmd, &argc, &argv, NULL);
290 b_argv = __create_argc_argv(kb, &b_argc);
291 b_argv[0] = strdup(argv[0]);
292 _prepare_exec(group, kb);
293 execv(b_argv[0], b_argv);
297 _prepare_exec(group, kb);
298 execv(argv[0], argv);
301 _E("exec error: %s", strerror(errno));
305 static inline int __send_app_launch_signal(int launch_pid)
307 DBusMessage *message;
312 message = dbus_message_new_signal(AUL_DBUS_PATH,
313 AUL_DBUS_SIGNAL_INTERFACE,
314 AUL_DBUS_APPLAUNCH_SIGNAL);
316 if (dbus_message_append_args(message,
317 DBUS_TYPE_UINT32, &launch_pid,
318 DBUS_TYPE_INVALID) == FALSE) {
319 _E("Failed to load data error");
323 if (dbus_connection_send(conn, message, NULL) == FALSE) {
324 _E("dbus send error");
328 dbus_connection_flush(conn);
329 dbus_message_unref(message);
331 _D("send launch signal done\n");
336 static int __send_watchdog_signal(int pid, int signal_num)
338 DBusMessage *message;
343 if (!_get_platform_ready()) {
344 _E("[Info]_get_platform_ready return false");
348 if(_status_get_cooldown_status() == COOLDOWN_LIMIT) {
349 _E("[Info]cooldown status : LimitAction");
353 message = dbus_message_new_signal(RESOURCED_PROC_OBJECT,
354 RESOURCED_PROC_INTERFACE,
355 RESOURCED_PROC_WATCHDOG_SIGNAL);
357 if (dbus_message_append_args(message,
358 DBUS_TYPE_INT32, &pid,
359 DBUS_TYPE_INT32, &signal_num,
360 DBUS_TYPE_INVALID) == FALSE) {
361 _E("Failed to load data error");
365 if (dbus_connection_send(conn, message, NULL) == FALSE) {
366 _E("dbus send error");
370 dbus_connection_flush(conn);
371 dbus_message_unref(message);
373 _D("send launch signal done\n");
378 static int __check_cmdline(int ret)
382 int cmdline_changed = 0;
383 int cmdline_exist = 0;
389 /* check normally was launched?*/
392 cmdline = __proc_get_cmdline_bypid(ret);
393 if (cmdline == NULL) {
394 _E("error founded when being launched with %d", ret);
396 } else if (strcmp(cmdline, amd_cmdline)) {
405 _D("-- now wait to change cmdline --");
406 usleep(50 * 1000); /* 50ms sleep*/
408 } while (wait_count <= 20); /* max 50*20ms will be sleep*/
410 if ((!cmdline_exist) && (!cmdline_changed)) {
414 if (!cmdline_changed)
415 _E("process launched, but cmdline not changed");
420 int service_start(struct cginfo *cg, const char *group, const char *cmd, bundle *kb)
425 if (!cg || !group || !*group || !cmd || !*cmd) {
427 _E("service start: %s", strerror(errno));
433 case 0: /* child process */
435 #ifdef _APPFW_FEATURE_PRIORITY_CHANGE
436 r = setpriority(PRIO_PROCESS, 0, 0);
439 SECURE_LOGE("Setting process (%d) priority to 0 failed, errno: %d (%s)",
440 getpid(), errno, strerror(errno));
443 _do_exec(cg, cmd, group, kb);
449 _E("service start: fork: %s", strerror(errno));
452 default: /* parent process */
453 _D("child process: %d", p);
454 r = __check_cmdline(p);
456 __send_app_launch_signal(r);
463 int _start_srv(const struct appinfo *ai, bundle *kb)
470 group = appinfo_get_filename(ai);
472 cmd = appinfo_get_value(ai, AIT_EXEC);
474 _E("start service: '%s' has no exec", group);
478 r = service_start(_lcg, group, cmd, kb);
480 _E("start service: '%s': failed", group);
484 pkgid = appinfo_get_value(ai, AIT_PKGID);
485 proc_cgroup_launch(PROC_CGROUP_SET_SERVICE_REQUEST, r, group, pkgid);
486 _status_add_app_info_list(group, cmd, NULL, r, -1);
491 static void _free_kt(struct ktimer *kt)
496 cgutil_unref(&kt->cg);
501 static void _kill_pid(struct cginfo *cg, const char *group, pid_t pid)
505 if (pid <= INIT_PID) /* block sending to all process or init */
508 r = cgutil_exist_group(cg, CTRL_MGR, group);
510 _E("send SIGKILL: exist: %s", strerror(errno));
514 _D("send SIGKILL: '%s' not exist", group);
518 /* TODO: check pid exist in group */
522 _D("send SIGKILL: pid %d not exist", pid);
526 r = kill(pid, SIGKILL);
528 _E("send SIGKILL: %s", strerror(errno));
531 static gboolean _ktimer_cb(gpointer data)
533 struct ktimer *kt = data;
535 _kill_pid(kt->cg, kt->group, kt->pid);
536 _kill_list = g_list_remove(_kill_list, kt);
542 static void _add_list(struct cginfo *cg, const char *group, pid_t pid)
546 kt = calloc(1, sizeof(*kt));
551 kt->group = strdup(group);
557 kt->cg = cgutil_ref(cg);
558 kt->tid = g_timeout_add_seconds(TERM_WAIT_SEC, _ktimer_cb, kt);
560 _kill_list = g_list_append(_kill_list, kt);
563 static inline void _del_list(GList *l)
572 g_source_remove(kt->tid);
574 _kill_list = g_list_delete_link(_kill_list, l);
577 static int _kill_pid_cb(void *user_data, const char *group, pid_t pid)
581 if (pid <= INIT_PID) /* block sending to all process or init */
584 r = kill(pid, SIGTERM);
586 _E("send SIGTERM: %s", strerror(errno));
588 _add_list(user_data, group, pid);
593 int service_stop(struct cginfo *cg, const char *group)
595 if (!cg || !group || !*group) {
600 _D("service_stop, group %s", group);
602 return cgutil_group_foreach_pid(cg, CTRL_MGR, FILENAME(group),
606 void service_release(const char *group)
611 if (!group || !*group)
614 group = FILENAME(group);
617 for (l = _kill_list; l; l = g_list_next(l)) {
618 struct ktimer *k = l->data;
622 if (k->group && !strcmp(k->group, group))
631 int _send_to_sigkill(int pid)
639 if (killpg(pgid, SIGKILL) < 0)
644 int _resume_app(int pid, int clifd)
649 __app_send_raw_with_delay_reply(pid, APP_RESUME_BY_PID, (unsigned char *)&dummy,
652 _E("resume packet timeout error");
654 _E("raise failed - %d resume fail\n", pid);
655 _E("we will term the app - %d\n", pid);
656 _send_to_sigkill(pid);
659 __real_send(clifd, ret);
664 __set_reply_handler(ret, pid, clifd, APP_RESUME_BY_PID);
669 int _fake_launch_app(int cmd, int pid, bundle * kb, int clifd)
675 bundle_encode(kb, &kb_data, &datalen);
676 if ((ret = __app_send_raw_with_delay_reply(pid, cmd, kb_data, datalen)) < 0) {
677 _E("error request fake launch - error code = %d", ret);
678 __real_send(clifd, ret);
683 __set_reply_handler(ret, pid, clifd, cmd);
688 static void __real_send(int clifd, int ret)
690 if (send(clifd, &ret, sizeof(int), MSG_NOSIGNAL) < 0) {
691 if (errno == EPIPE) {
692 _E("send failed due to EPIPE.\n");
694 _E("send fail to client");
700 static gboolean __au_glib_check(GSource *src)
705 fd_list = src->poll_fds;
707 tmp = (GPollFD *) fd_list->data;
708 if ((tmp->revents & (POLLIN | POLLPRI)))
710 fd_list = fd_list->next;
716 static gboolean __au_glib_dispatch(GSource *src, GSourceFunc callback,
723 static gboolean __au_glib_prepare(GSource *src, gint *timeout)
728 static GSourceFuncs funcs = {
729 .prepare = __au_glib_prepare,
730 .check = __au_glib_check,
731 .dispatch = __au_glib_dispatch,
744 static gboolean __reply_handler(gpointer data)
746 struct reply_info *r_info = (struct reply_info *) data;;
747 int fd = r_info->gpollfd->fd;
750 int clifd = r_info->clifd;
751 int pid = r_info->pid;
752 int cmd = r_info->cmd;
754 len = recv(fd, &res, sizeof(int), 0);
756 if (errno == EAGAIN) {
757 _E("recv timeout : %s", strerror(errno));
760 _E("recv error : %s", strerror(errno));
767 if ( cmd == APP_TERM_BY_PID ) {
768 __real_send(clifd, -1);
769 } else if ( cmd == APP_START_ASYNC ) {
772 __real_send(clifd, res);
775 if ( cmd == APP_TERM_BY_PID ) {
776 __real_send(clifd, 0);
777 } else if ( cmd == APP_START_ASYNC ) {
780 __real_send(clifd, pid);
784 _D("listen fd(%d) , send fd(%d), pid(%d), cmd(%d)", fd, clifd, pid, cmd);
786 g_source_remove(r_info->timer_id);
787 g_source_remove_poll(r_info->src, r_info->gpollfd);
788 g_source_destroy(r_info->src);
789 g_free(r_info->gpollfd);
795 static gboolean __recv_timeout_handler(gpointer data)
797 struct reply_info *r_info = (struct reply_info *) data;
798 int fd = r_info->gpollfd->fd;
800 _E("application is not responding : pid(%d) cmd(%d)", r_info->pid, r_info->cmd);
804 switch (r_info->cmd) {
809 case APP_START_ASYNC:
810 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
811 case APP_START_MULTI_INSTANCE:
813 __send_watchdog_signal(r_info->pid, SIGKILL);
815 case APP_TERM_BY_PID:
816 if (_send_to_sigkill(r_info->pid) < 0) {
817 _E("fail to killing - %d\n", r_info->pid);
818 __real_send(r_info->clifd, -1);
821 __real_send(r_info->clifd, 0);
825 g_source_remove_poll(r_info->src, r_info->gpollfd);
826 g_source_destroy(r_info->src);
827 g_free(r_info->gpollfd);
833 static void __set_reply_handler(int fd, int pid, int clifd, int cmd)
837 struct reply_info *r_info;
839 src = g_source_new(&funcs, sizeof(GSource));
841 gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
842 gpollfd->events = POLLIN;
845 r_info = malloc(sizeof(*r_info));
846 r_info->clifd = clifd;
849 r_info->gpollfd = gpollfd;
853 r_info->timer_id = g_timeout_add(5000, __recv_timeout_handler, (gpointer) r_info);
854 g_source_add_poll(src, gpollfd);
855 g_source_set_callback(src, (GSourceFunc) __reply_handler,
856 (gpointer) r_info, NULL);
857 g_source_set_priority(src, G_PRIORITY_DEFAULT);
858 g_source_attach(src, NULL);
860 _D("listen fd : %d, send fd : %d", fd, clifd);
863 int _term_app(int pid, int clifd)
868 if ( (ret = __app_send_raw_with_delay_reply
869 (pid, APP_TERM_BY_PID, (unsigned char *)&dummy, sizeof(int))) < 0) {
870 _D("terminate packet send error - use SIGKILL");
871 if (_send_to_sigkill(pid) < 0) {
872 _E("fail to killing - %d\n", pid);
873 __real_send(clifd, -1);
876 __real_send(clifd, 0);
880 __set_reply_handler(ret, pid, clifd, APP_TERM_BY_PID);
887 static int __launchpad_update_task_managed_field(const char* app_id, int task_managed)
890 char *sqlite3_error_msg = NULL;
892 if (sqlite3_open("/opt/dbspace/.pkgmgr_parser.db", &db) != SQLITE_OK) {
893 _E("sqlite3_open() failed! -> %s\n", sqlite3_errmsg(db));
897 if (sqlite3_exec(db, "PRAGMA journal_mode = PERSIST", NULL, NULL, &sqlite3_error_msg) != SQLITE_OK) {
898 _E("sqlite3_exec(\"PRAGMA journal_mode = PERSIST\") failed! -> %s", sqlite3_error_msg);
899 sqlite3_free(sqlite3_error_msg);
904 if (sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, &sqlite3_error_msg) != SQLITE_OK) {
905 _E("sqlite3_exec(\"BEGIN EXCLUSIVE\") failed! -> %s", sqlite3_error_msg);
906 sqlite3_free(sqlite3_error_msg);
911 char query[1024] = {0, };
912 snprintf(query, 1024,"update package_app_info set app_taskmanage='%s' where app_id='%s'",
913 task_managed ? "true" : "false", app_id);
915 if (sqlite3_exec(db, query, NULL, NULL, &sqlite3_error_msg) != SQLITE_OK) {
916 _E("sqlite3_exec(\"%s\") failed! -> %s", query, sqlite3_error_msg);
917 sqlite3_free(sqlite3_error_msg);
921 if (sqlite3_exec(db, "COMMIT", NULL, NULL, NULL) != SQLITE_OK) {
922 _E("sqlite3_exec(\"COMMIT\") failed!");
923 if (sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL) != SQLITE_OK) {
924 _E("sqlite3_exec(\"ROLLBACK\") failed!");
935 static void __pre_launching_processing(const char* app_id)
937 const char* const PRE_LAUNCHING_LIST_DIR = "/opt/usr/etc/wrt_launchpad_daemon/pre_launching_list";
939 struct stat file_status;
940 if (stat(PRE_LAUNCHING_LIST_DIR, &file_status) == 0) {
941 if (S_ISDIR(file_status.st_mode)) {
944 struct dirent entry, *result;
946 dir = opendir(PRE_LAUNCHING_LIST_DIR);
949 for (ret = readdir_r(dir, &entry, &result);
950 result != NULL && ret == 0;
951 ret = readdir_r(dir, &entry, &result)) {
952 if (strncmp(entry.d_name, ".", 2) == 0 ||
953 strncmp(entry.d_name, "..", 3) == 0) {
957 if (strcmp(entry.d_name, app_id) == 0)
959 __launchpad_update_task_managed_field(app_id, 1);
966 _E("opendir(\"%s\") failed!", PRE_LAUNCHING_LIST_DIR);
972 static int __nofork_processing(int cmd, int pid, bundle * kb, int clifd)
976 const char *operation;
978 operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__");
980 #ifdef _APPFW_FEATURE_CPU_BOOST
981 //TODO: CPU boosting for relaunching will be removed.
982 //Home screen requests CPU boosting on launching or relaunching during 200 msec.
983 if (cmd == APP_OPEN ||
984 (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/main", 512) == 0)) {
987 snprintf(val, sizeof(val), "%d", APP_BOOSTING_PERIOD);
990 ret = invoke_dbus_method_sync(SYSTEM_BUS_NAME, SYSTEM_OBJECT_PATH,
991 SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, "i", arr);
992 _D("%s-%s : %d", SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, ret);
995 _D("__nofork_processing, cmd: %d, pid: %d", cmd, pid);
999 _D("resume app's pid : %d\n", pid);
1000 if ((ret = _resume_app(pid, clifd)) < 0)
1001 _E("__resume_app failed. error code = %d", ret);
1002 _D("resume app done");
1007 case APP_START_ASYNC:
1008 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
1009 case APP_START_MULTI_INSTANCE:
1011 _D("fake launch pid : %d\n", pid);
1012 if ((ret = _fake_launch_app(cmd, pid, kb, clifd)) < 0)
1013 _E("fake_launch failed. error code = %d", ret);
1014 _D("fake launch done");
1024 __amd_sysman_restore_hz_timer_cb(void *data)
1026 struct context *ctxt = data;
1031 sysman_release_cpu_min_frequency ();
1033 _D("*******[1.6MHZ Support] Released\n " );
1035 return ECORE_CALLBACK_CANCEL; // same as EINA_FALSE
1043 static int __amd_change_min_cpulock_count(int value)
1047 fd = open(SYS_MIN_CPU_LOCK_FILE, O_WRONLY);
1050 snprintf(buf, sizeof(buf), "%d", value);
1051 if (write(fd, buf, strlen(buf)) < 0) {
1052 _E("[AMD]: Unable to change min_cpu_lock value!, err: %s\n",strerror(errno));
1057 _D("[AMD]: Succesfully changed min cpu value to %d\n", value);
1061 static Eina_Bool __amd_restore_min_cpulock_count_cb(void *data)
1063 struct context *ctxt = data;
1066 __amd_change_min_cpulock_count(MIN_CPU_LCK_CNT);
1067 return ECORE_CALLBACK_CANCEL;
1070 static void __amd_effect_image_file_set(char *image_file)
1072 Ecore_X_Window root_win;
1073 root_win = ecore_x_window_root_first_get();
1074 SECURE_LOGD("path : %s", image_file);
1075 ecore_x_window_prop_string_set(root_win, ATOM_IMAGE_EFFECT,image_file);
1079 static void __amd_send_message_to_e17(int screenmode, const char * indicator, int effect_type, int theme)
1081 Ecore_X_Window root_win;
1083 root_win = ecore_x_window_root_first_get();
1084 _D("root win : %x",root_win);
1085 int screen_orientation[5]={0,0,270,180,90};
1086 if (screenmode > 4 || screenmode < 0)
1089 if (strncmp(indicator, "true", 4) == 0){
1090 _D("[LAUNCHING EFFECT]: screen mode(%d), effect type(%d), theme(%d), indicator show",
1091 screen_orientation[screenmode], effect_type, theme);
1092 ret = ecore_x_client_message32_send (root_win, ATOM_IMAGE_EFFECT,
1093 ECORE_X_EVENT_MASK_WINDOW_PROPERTY, effect_type,
1094 screen_orientation[screenmode],
1095 SHOW_INDICATOR, theme, 0);
1098 _D("[LAUNCHING EFFECT]: screen mode(%d), effect type(%d), theme(%d), indicator show",
1099 screen_orientation[screenmode], effect_type, theme);
1100 ret = ecore_x_client_message32_send (root_win, ATOM_IMAGE_EFFECT,
1101 ECORE_X_EVENT_MASK_WINDOW_PROPERTY, effect_type,
1102 screen_orientation[screenmode],
1103 HIDE_INDICATOR, theme, 0);
1106 _D("ecore_x_client_message32_send : %d",ret);
1111 static int append_variant(DBusMessageIter *iter, const char *sig, char *param[])
1116 uint64_t int64_type;
1121 for (ch = (char*)sig, i = 0; *ch != '\0'; ++i, ++ch) {
1124 int_type = atoi(param[i]);
1125 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &int_type);
1128 int_type = atoi(param[i]);
1129 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &int_type);
1132 int64_type = atoi(param[i]);
1133 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT64, &int64_type);
1136 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, param[i]);
1146 int invoke_dbus_method_sync(const char *dest, const char *path,
1147 const char *interface, const char *method,
1148 const char *sig, char *param[])
1151 DBusMessageIter iter;
1156 msg = dbus_message_new_method_call(dest, path, interface, method);
1158 _E("dbus_message_new_method_call(%s:%s-%s)", path, interface, method);
1163 dbus_message_iter_init_append(msg, &iter);
1164 r = append_variant(&iter, sig, param);
1166 _E("append_variant error(%d)", r);
1167 dbus_message_unref(msg);
1172 dbus_error_init(&err);
1174 reply = dbus_connection_send_with_reply_and_block(conn, msg, 500, &err);
1175 dbus_message_unref(msg);
1177 _E("dbus_connection_send error(%s:%s)", err.name, err.message);
1178 dbus_error_free(&err);
1182 r = dbus_message_get_args(reply, &err, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
1183 dbus_message_unref(reply);
1185 _E("no message : [%s:%s]", err.name, err.message);
1186 dbus_error_free(&err);
1193 static gboolean __grab_timeout_handler(gpointer data)
1195 int pid = (int) data;
1197 if(_input_window_get() != 0)
1198 ecore_x_pointer_ungrab();
1199 _D("pid(%d) ecore_x_pointer_ungrab", pid);
1204 static bool __check_ug_client_process_pool(const char *app_path)
1206 char sympath[MAX_PACKAGE_APP_PATH_SIZE] = {0,};
1208 bool func_ret = true;
1211 _E("invalid input param");
1216 if(strncmp(app_path, "/usr/ug/bin/", strlen("/usr/ug/bin")) != 0) {
1221 if(readlink(app_path, sympath, MAX_PACKAGE_APP_PATH_SIZE-1) == -1) {
1222 _E("read app path link error(%d)", errno);
1227 if(strncmp(sympath, "/usr/bin/ug-client", strlen("/usr/bin/ug-client")) != 0) {
1232 _D("ug process pool check result : %d", func_ret);
1236 #ifdef _APPFW_FEATURE_MULTI_WINDOW
1237 static void __add_multi_window_info(bundle* kb, const struct appinfo *ai, const char* callee_appid, const char* caller_appid)
1239 const struct appinfo *caller_ai;
1240 const struct appinfo *callee_ai;
1241 unsigned int layout = -1; // 0 : top of split window / 1 : bottom of split window
1242 const char *caller = NULL;
1243 Ecore_X_Window caller_win_id = 0;
1244 const char *bundle_layout = NULL;
1245 int is_open_via_multi = 0;
1246 int startup_type = 2; //2 means callee will be displayed as split view
1247 const char *caller_ai_multi_window = NULL;
1248 const char *callee_ai_multi_window = NULL;
1250 int multiwindow_enabled = 0;
1252 /* check multi window is enabled or not */
1253 ret = vconf_get_bool(VCONFKEY_QUICKSETTING_MULTIWINDOW_ENABLED, &multiwindow_enabled);
1254 if((ret != VCONF_OK) || (multiwindow_enabled == 0)) {
1255 _D("multiwindow is disabled");
1259 SECURE_LOGD("callee appid : %s / caller_appid : %s", callee_appid, caller_appid);
1261 /* check whether caller & callee ui app support multi window or not */
1262 caller_ai = appinfo_find(_laf, caller_appid);
1263 if(caller_ai == NULL) {
1264 _D("no caller appinfo");
1267 caller_ai_multi_window = appinfo_get_value(caller_ai, AIT_MULTI_WINDOW);
1268 if((caller_ai_multi_window == NULL) || (strcmp(caller_ai_multi_window, "true") != 0)) {
1269 _D("caller app does not support multi window");
1272 callee_ai = appinfo_find(_laf, callee_appid);
1273 if(callee_ai == NULL) {
1274 _D("no callee appinfo");
1277 callee_ai_multi_window = appinfo_get_value(callee_ai, AIT_MULTI_WINDOW);
1278 if((callee_ai_multi_window == NULL) || (strcmp(callee_ai_multi_window, "true") != 0)) {
1279 _D("callee app does not support multi window");
1283 /* check aul_forwad_app case */
1284 if((caller_appid) && (strcmp(caller_appid, "org.tizen.app-selector") == 0)) {
1285 _D("forward app case");
1289 /* get multi window layout value */
1290 caller = bundle_get_val(kb, "__APP_SVC_K_WIN_ID__");
1292 caller_win_id = atoi(caller);
1294 _D("caller win id is null");
1297 if(caller_win_id == 0) {
1298 _D("caller id is 0");
1302 if( ecore_x_window_prop_card32_get(caller_win_id,
1303 ECORE_X_ATOM_E_WINDOW_DESKTOP_LAYOUT, &layout, 1 ) != -1 )
1305 if(layout == 0 || layout == 1) {
1306 _D("layout : %d", layout);
1308 _W("x_window__prop_get layout value error : %d", layout);
1316 const char *operation = NULL;
1317 operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__");
1318 if(operation == NULL) {
1319 _D("operation is null");
1323 if(strcmp(operation,"http://tizen.org/appcontrol/operation/view") == 0) {
1324 int open_via_multi = 0;
1325 ret = vconf_get_bool(VCONFKEY_SETAPPL_OPEN_VIA_MULTI, &open_via_multi);
1326 _D("open_via_multi : %d", open_via_multi);
1327 if((ret == VCONF_OK) && (open_via_multi == 1)) {
1328 is_open_via_multi = 1;
1329 /* callee window should not be transient for caller window under "open in multi window" mode */
1331 if(bundle_del(kb, "__APP_SVC_K_WIN_ID__") == -1) {
1332 _D("failed to remove window id of bundle (errno : %d)", errno);
1340 if(is_open_via_multi) {
1346 _D("open via multi scenario. reverted layout id is %d", layout);
1348 /* multi window support app need be launched with full view
1349 when app is launched from multi window support app with full view. */
1355 char tmp_layout[128];
1356 char tmp_startup[128];
1358 snprintf(tmp_layout, 128, "%d", layout);
1359 snprintf(tmp_startup, 128, "%d", startup_type);
1361 if(bundle_add(kb, "window_layout_id", tmp_layout) != 0) {
1362 _W("winow layout id bundle add error");
1364 if(bundle_add(kb, "window_startup_type", tmp_startup) != 0) {
1365 _W("winow startup type bundle add error");
1368 SECURE_LOGD("window startup type(%d) and layout id(%d) is added", startup_type, layout);
1374 int __check_mode(const struct appinfo *ai)
1376 #ifdef _APPFW_FEATURE_TTS_MODE
1378 const char *tts_support = NULL;
1380 #ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
1382 const char *ups_support = NULL;
1385 #ifdef _APPFW_FEATURE_TTS_MODE
1386 vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &tts_mode);
1388 tts_support = appinfo_get_value(ai, AIT_TTS);
1389 _D("tts : %d %s", tts_mode, tts_support);
1390 if(strncmp(tts_support, "false", 5) == 0)
1395 #ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
1396 vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &ups_mode);
1397 if(ups_mode == SETTING_PSMODE_WEARABLE) {
1398 ups_support = appinfo_get_value(ai, AIT_UPS);
1399 _D("ups : %d %s", ups_mode, ups_support);
1400 if(strncmp(ups_support, "false", 5) == 0)
1408 int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_uid, int fd)
1410 const struct appinfo *ai;
1411 const struct appinfo *caller_ai;
1413 const char *multiple = NULL;
1414 const char *app_path = NULL;
1415 const char *pkg_type = NULL;
1416 const char *component_type = NULL;
1418 char tmp_pid[MAX_PID_STR_BUFSZ];
1419 const char *permission;
1421 const char *preload;
1422 const char *pkg_status;
1423 const char *operation;
1424 const char *fake_effect;
1425 char caller_appid[256];
1426 char* caller = NULL;
1427 char* curr_caller = NULL;
1428 char* old_caller = NULL;
1429 pkgmgrinfo_cert_compare_result_type_e compare_result;
1430 int delay_reply = 0;
1431 int pad_pid = LAUNCHPAD_PID;
1434 char trm_buf[MAX_PACKAGE_STR_SIZE];
1436 int effect_mode = 0;
1437 #ifdef _APPFW_FEATURE_WMS_CONNECTION_CHECK
1438 int wmanager_connected = 0;
1440 char *caller_component_type = NULL;
1442 if (appid == NULL || kb == NULL
1443 || caller_pid < 0 || caller_uid < 0 || fd < 0) {
1444 _D("invalid parameter");
1446 __real_send(fd, -1);
1450 snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", caller_pid);
1451 bundle_add(kb, AUL_K_CALLER_PID, tmp_pid);
1453 if (cmd == APP_START_RES)
1454 bundle_add(kb, AUL_K_WAIT_RESULT, "1");
1456 caller = _status_app_get_appid_bypid(caller_pid);
1457 if(caller == NULL) {
1458 ret = aul_app_get_appid_bypid(caller_pid, caller_appid, sizeof(caller_appid));
1460 bundle_add(kb, AUL_K_CALLER_APPID, caller_appid);
1463 bundle_add(kb, AUL_K_CALLER_APPID, caller);
1465 curr_caller = bundle_get_val(kb,AUL_K_CALLER_APPID);
1466 SECURE_LOGD("caller : %s", curr_caller);
1468 #ifdef _APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP
1469 // Add the appid into bundle to distinguish between Contacts and Phone.
1470 if (strncmp(appid, "org.tizen.contacts", strlen("org.tizen.contacts")) == 0
1471 || strncmp(appid, "org.tizen.phone", strlen("org.tizen.phone")) == 0)
1473 bundle_add(kb, AUL_K_INTERNAL_APPID, appid);
1474 SECURE_LOGD("Add the appid[%s] into bundle to distinguish between Contacts and Phone.", appid);
1477 ai = appinfo_find(_laf, appid);
1480 __real_send(fd, -1);
1483 pkg_status = appinfo_get_value(ai, AIT_STATUS);
1484 if(pkg_status && (strncmp(pkg_status, "blocking", 8) == 0 || strncmp(pkg_status, "restart", 7) == 0) ) {
1486 __real_send(fd, -EREJECTED);
1488 } else if(pkg_status && strncmp(pkg_status, "unmounted", 9) == 0 ) {
1490 __real_send(fd, -1);
1495 app_path = appinfo_get_value(ai, AIT_EXEC);
1496 pkg_type = appinfo_get_value(ai, AIT_TYPE);
1497 permission = appinfo_get_value(ai, AIT_PERM);
1498 pkgid = appinfo_get_value(ai, AIT_PKGID);
1499 component_type = appinfo_get_value(ai, AIT_COMPTYPE);
1501 operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__");
1502 caller_ai = appinfo_find(_laf, curr_caller);
1504 if(permission && strncmp(permission, "signature", 9) == 0 ) {
1505 if(caller_uid != 0 && (cmd == APP_START
1506 || cmd == APP_START_RES
1507 || cmd == APP_START_ASYNC
1508 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
1509 || cmd == APP_START_MULTI_INSTANCE
1513 preload = appinfo_get_value(caller_ai, AIT_PRELOAD);
1514 if( preload && strncmp(preload, "true", 4) != 0 ) {
1515 pkgmgrinfo_pkginfo_compare_app_cert_info(caller_appid, appid, &compare_result);
1516 if(compare_result != PMINFO_CERT_COMPARE_MATCH) {
1517 pid = -EILLEGALACCESS;
1518 if(cmd == APP_START_ASYNC)
1521 __real_send(fd, pid);
1528 if(__check_mode(ai) < 0) {
1530 if(cmd == APP_START_ASYNC)
1533 __real_send(fd, pid);
1537 pkgmgrinfo_client_request_enable_external_pkg(pkgid);
1539 if (component_type && strncmp(component_type, "uiapp", 5) == 0) {
1541 #ifdef _APPFW_FEATURE_MULTI_WINDOW
1542 if((cmd != APP_RESUME) && (cmd != APP_OPEN)) {
1543 __add_multi_window_info(kb, ai, (const char*) appid, (const char*)bundle_get_val(kb,AUL_K_CALLER_APPID));
1546 multiple = appinfo_get_value(ai, AIT_MULTI);
1547 if (!multiple || strncmp(multiple, "false", 5) == 0) {
1548 pid = _status_app_is_running_v2(appid);
1549 } else if (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/view", 512) == 0){
1550 old_caller = _status_get_caller_by_appid(appid);
1551 if(old_caller && curr_caller) {
1552 if(strncmp(old_caller, curr_caller, MAX_PACKAGE_STR_SIZE) == 0) {
1553 pid = _status_app_is_running_v2(appid);
1558 #ifdef _APPFW_FEATURE_APP_CONTROL_LITE
1559 char app_path_link[512] = {0,};
1560 const char *caller_app_path = NULL;
1561 char caller_app_path_link[512] = {0,};
1563 caller_app_path = appinfo_get_value(caller_ai, AIT_EXEC);
1565 SECURE_LOGD("callee path(%s) caller path(%s)", app_path, caller_app_path);
1567 readlink(app_path, app_path_link, 512);
1568 readlink(caller_app_path, caller_app_path_link, 512);
1570 SECURE_LOGD("callee link(%s) caller link(%s)", app_path_link, caller_app_path_link);
1572 if(strncmp(app_path_link, "/usr/bin/ug-client", 512) == 0) {
1573 if (strcmp(caller, "org.tizen.app-selector") == 0){
1574 pid = atoi(bundle_get_val(kb,AUL_K_ORG_CALLER_PID));
1575 bundle_add(kb, "__AUL_UG_EXEC__", app_path);
1576 SECURE_LOGD("app_path : %s , ug id(%s)", app_path, bundle_get_val(kb, "__AUL_UG_ID__"));
1577 } else if(strncmp(caller_app_path_link, "/usr/bin/ug-client", 512) == 0) {
1578 __real_send(fd, -EUGLOCAL_LAUNCH);
1585 caller_component_type = appinfo_get_value(caller_ai, AIT_COMPTYPE);
1586 if (caller_component_type && strncmp(caller_component_type, "uiapp", 5) == 0) {
1587 Ecore_X_Window in_win;
1588 in_win = _input_window_get();
1590 ret = ecore_x_pointer_grab(in_win);
1591 _D("win(%x) ecore_x_pointer_grab(%d)", in_win, ret);
1596 status = _status_get_app_info_status(pid);
1597 if (pid > 0 && status != STATUS_DYING) {
1598 if (caller_pid == pid) {
1599 SECURE_LOGD("caller process & callee process is same.[%s:%d]", appid, pid);
1600 pid = -ELOCALLAUNCH_ID;
1602 if(strncmp(pkg_type, "wgt", 3) == 0) {
1603 __pre_launching_processing(appid);
1605 proc_group_change_status(PROC_CGROUP_SET_RESUME_REQUEST, pid, appid);
1606 if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) {
1612 } else if (cmd != APP_RESUME) {
1613 if(status == STATUS_DYING && pid > 0) {
1614 r = kill(pid, SIGKILL);
1616 _D("send SIGKILL: %s", strerror(errno));
1618 fake_effect = bundle_get_val(kb, "__FAKE_EFFECT__");
1620 #ifdef _APPFW_FEATURE_CPU_BOOST
1621 if (cmd == APP_OPEN || operation != NULL ||
1622 (caller != NULL && strcmp(caller, "org.tizen.wnotification2") == 0) ||
1623 (caller != NULL && strcmp(caller, "org.tizen.wnotiboard-popup") == 0)) {
1626 snprintf(val, sizeof(val), "%d", APP_BOOSTING_PERIOD);
1629 ret = invoke_dbus_method_sync(SYSTEM_BUS_NAME, SYSTEM_OBJECT_PATH,
1630 SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, "i", arr);
1631 _D("%s-%s : %d", SYSTEM_INTERFACE_NAME, SYSTEM_METHOD_NAME, ret);
1636 * default mode : fake effect off, 1.6 MHZ off
1638 * full mode : fake effect on, 1.6 MHZ on
1640 * fake effect mode : fake effect on, 1.6 MHZ off
1642 * 1.6 MHZ mode : faek effect off, 1.6MHZ on
1645 vconf_get_int(AMD_EFFECT_IMAGE_ENABLE, &effect_mode);
1646 #ifdef _APPFW_FEATURE_WMS_CONNECTION_CHECK
1647 vconf_get_bool(VCONFKEY_WMS_WMANAGER_CONNECTED, &wmanager_connected);
1649 //_D("*******[effect_mode] Mode : %d\n ", effect_mode );
1651 if ( ( cmd == APP_OPEN ||
1652 ( (operation != NULL && strncmp(operation, "http://tizen.org/appcontrol/operation/main", 512) == 0)
1653 && !(fake_effect != NULL && strncmp(fake_effect, "OFF", 3) == 0) )
1654 ) && (effect_mode == 1 || effect_mode == 2)
1655 #ifdef _APPFW_FEATURE_WMS_CONNECTION_CHECK
1656 && wmanager_connected == true
1659 char image_filename[256] = {0,};
1660 char xml_filename[256] = {0,};
1661 const char *portraitimg = NULL;
1662 const char *landscapeimg = NULL;
1663 #ifdef _APPFW_FEATURE_CHANGEABLE_COLOR
1664 char *effectimg_type = NULL;
1666 const char *indicator = NULL;
1667 int screen_mode = 0;
1668 bool rotate_allowed = false;
1672 //vconf_get_int(PHONE_ORIENTATION_MODE, &screen_mode);
1673 screen_mode = invoke_dbus_method_sync(ROTATION_BUS_NAME, ROTATION_OBJECT_PATH,
1674 ROTATION_INTERFACE_NAME, ROTATION_METHOD_NAME, "i", NULL);
1675 _D("%s-%s : %d", ROTATION_INTERFACE_NAME, ROTATION_METHOD_NAME, screen_mode);
1676 vconf_get_bool(PHONE_ROTATE_LOCK, &rotate_allowed); /*TODO: use vconf_notify_key_changed()*/
1677 portraitimg = appinfo_get_value(ai, AIT_EFFECTIMAGEPORT);
1678 landscapeimg = appinfo_get_value(ai, AIT_EFFECTIMAGELAND);
1679 #ifdef _APPFW_FEATURE_CHANGEABLE_COLOR
1680 effectimg_type = appinfo_get_value(ai, AIT_EFFECTTYPE);
1682 indicator = appinfo_get_value(ai, AIT_INDICATOR_DISP);
1683 /*Currently we assume apps supporting launching effect supports portrait mode*/
1684 if (indicator && portraitimg) {
1685 if (rotate_allowed == false) {
1688 if ((screen_mode == 2 || screen_mode == 4) && (rotate_allowed == true)) {
1689 /*if there is no landscape image, that means app supports only portrait mode.*/
1691 snprintf(image_filename, 255, "%s", landscapeimg);
1694 snprintf(image_filename, 255, "%s", portraitimg);
1696 if (access(image_filename, R_OK) == 0) {
1697 #ifdef _APPFW_FEATURE_CHANGEABLE_COLOR
1698 if(strncmp(effectimg_type, "edj-dark", strlen(effectimg_type)) == 0) {
1701 } else if (strncmp(effectimg_type, "edj-light", strlen(effectimg_type)) == 0) {
1704 } else if (strncmp(effectimg_type, "edj-default", strlen(effectimg_type)) == 0) {
1715 r = snprintf(xml_filename, 255, "/usr/apps/%s/shared/res/tables/%s_ChangeableColorInfo.xml", pkgid, pkgid);
1716 if (access(xml_filename, R_OK) == 0) {
1717 //snprintf(image_filename, 255, "%s:%s", image_filename, xml_filename);
1718 strcat(image_filename, ":");
1719 strcat(image_filename, xml_filename);
1722 r = snprintf(xml_filename, 255, "/opt/usr/apps/%s/shared/res/tables/%s_ChangeableColorInfo.xml", pkgid, pkgid);
1723 if (access(xml_filename, R_OK) == 0) {
1724 //snprintf(image_filename, 255, "%s:%s", image_filename, xml_filename);
1725 strcat(image_filename, ":");
1726 strcat(image_filename, xml_filename);
1731 #ifndef _APPFW_FEATURE_DEFAULT_FAKE_IMAGE
1732 __amd_effect_image_file_set(image_filename);
1734 if(file_type == 1) {
1735 __amd_effect_image_file_set("/usr/share/splash_images/type0_portrait.bmp");
1737 __amd_effect_image_file_set(image_filename);
1740 __amd_send_message_to_e17(screen_mode, indicator, file_type, theme);
1745 #ifdef _APPFW_FEATURE_DEBUG_LAUNCHPAD
1746 if (bundle_get_type(kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) {
1747 pad_pid = DEBUG_LAUNCHPAD_PID;
1748 } else if (strncmp(pkg_type, "wgt", 3) == 0) {
1749 pad_pid = WEB_LAUNCHPAD_PID;
1752 if (strncmp(pkg_type, "wgt", 3) == 0) {
1753 pad_pid = WEB_LAUNCHPAD_PID;
1756 #ifdef _APPFW_FEATURE_NATIVE_LAUNCHPAD
1757 else if (strncmp(pkg_type, "tpk", 3) == 0) {
1758 char native_sock[UNIX_PATH_MAX] = { 0, };
1759 snprintf(native_sock, UNIX_PATH_MAX, "%s/%d", AUL_SOCK_PREFIX, pad_pid);
1760 if (access(native_sock, F_OK) != 0) {
1761 _D("Sending to native launchpad because native launchpad is not initialized.");
1763 pad_pid = NATIVE_LAUNCHPAD_PID;
1767 #ifdef _APPFW_FEATURE_PROCESS_POOL
1769 const char *process_pool = appinfo_get_value(ai, AIT_POOL);
1770 _D("process_pool: %s", process_pool);
1772 const char *hwacc = appinfo_get_value(ai, AIT_HWACC);
1773 _D("h/w acceleration: %s", hwacc);
1775 SECURE_LOGD("appid: %s", appid);
1777 if (strncmp(process_pool, "true", strlen("true")) == 0)
1779 #ifndef _APPFW_FEATURE_PROCESS_POOL_COMMON
1780 if (strncmp(hwacc, "USE", strlen("USE")) != 0)
1782 _D("Sending to process-pool launchpad (type1).");
1783 bundle_add(kb, AUL_K_LAUNCHPAD_TYPE, "1"); //sw rendering
1784 pad_pid = PROCESS_POOL_LAUNCHPAD_PID;
1788 #ifndef _APPFW_FEATURE_PROCESS_POOL_HW_RENDERING
1789 _D("Sending to legacy launchpad because launchpad type2 is not supported.");
1791 _D("Sending to process-pool launchpad (type2).");
1792 bundle_add(kb, AUL_K_LAUNCHPAD_TYPE, "2"); //hw rendering
1793 pad_pid = PROCESS_POOL_LAUNCHPAD_PID;
1796 #else //_APPFW_FEATURE_PROCESS_POOL_COMMON
1797 _D("Sending to process-pool launchpad (combine mode).");
1798 bundle_add(kb, AUL_K_LAUNCHPAD_TYPE, "1");
1799 pad_pid = PROCESS_POOL_LAUNCHPAD_PID;
1800 #endif //_APPFW_FEATURE_PROCESS_POOL_COMMON
1802 char pad_sock[UNIX_PATH_MAX] = { 0, };
1803 snprintf(pad_sock, UNIX_PATH_MAX, "%s/%d", AUL_SOCK_PREFIX, pad_pid);
1804 if (access(pad_sock, F_OK) != 0)
1806 _D("Sending to legacy launchpad because process-pool launchpad is not initialized.");
1807 pad_pid = LAUNCHPAD_PID;
1811 #endif //_APPFW_FEATURE_PROCESS_POOL
1813 __set_appinfo_for_launchpad(ai, kb);
1814 pid = app_send_cmd(pad_pid, cmd, kb);
1815 if(pid == AUL_R_ECOMM) {
1816 pid = -ENOLAUNCHPAD;
1818 //_add_cgroup(_lcg, appid, pid);
1819 proc_cgroup_launch(PROC_CGROUP_SET_LAUNCH_REQUEST, pid, appid, pkgid);
1820 snprintf(trm_buf, MAX_PACKAGE_STR_SIZE, "appinfo_launch:%s[PID]%d", appid, pid);
1821 __trm_app_info_send_socket(trm_buf);
1824 if(_input_window_get() != 0)
1825 ecore_x_pointer_ungrab();
1826 _D("pid(%d) ecore_x_pointer_ungrab", pid);
1828 grab_timer_id = g_timeout_add(1000, __grab_timeout_handler, pid);
1831 else if (component_type && strncmp(component_type, "svcapp", 6) == 0) {
1832 pid = _status_app_is_running_v2(appid);
1834 if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) {
1837 } else if (cmd != APP_RESUME) {
1838 #ifdef _APPFW_FEATURE_DEBUG_LAUNCHPAD
1839 if (bundle_get_type(kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) {
1840 _D("The svcapp(%s) is launched by debug-launchpad", appid);
1841 __set_appinfo_for_launchpad(ai, kb);
1842 pid = app_send_cmd(DEBUG_LAUNCHPAD_PID, cmd, kb);
1843 if (pid == AUL_R_ECOMM) {
1844 pid = -ENOLAUNCHPAD;
1846 proc_cgroup_launch(PROC_CGROUP_SET_LAUNCH_REQUEST, pid, appid, pkgid);
1848 pid = service_start(_lcg, appid, app_path, kb);
1849 proc_cgroup_launch(PROC_CGROUP_SET_SERVICE_REQUEST, pid, appid, pkgid);
1852 pid = service_start(_lcg, appid, app_path, kb);
1853 proc_cgroup_launch(PROC_CGROUP_SET_SERVICE_REQUEST, pid, appid, pkgid);
1857 _E("unkown application");
1861 if(cmd == APP_START_ASYNC)
1864 __real_send(fd, pid);
1868 #ifdef _APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP
1869 // Add the appid into bundle to distinguish between Contacts and Phone.
1870 if (strncmp(appid, "org.tizen.phone", strlen("org.tizen.phone")) == 0)
1871 _status_add_app_info_list("org.tizen.contacts", app_path, curr_caller, pid, pad_pid);
1874 _status_add_app_info_list(appid, app_path, curr_caller, pid, pad_pid);
1876 #ifdef _APPFW_FEATURE_APP_CHECKER
1877 ret = ac_server_check_launch_privilege(appid, appinfo_get_value(ai, AIT_TYPE), pid);
1878 return ret != AC_R_ERROR ? pid : -1;
1885 int __e17_status_handler(int pid, int status, void *data)
1887 if( status == 0 || status == 3) {
1888 _D("pid(%d) status(%d)", pid, status);
1889 if(_input_window_get() != 0)
1890 ecore_x_pointer_ungrab();
1891 g_source_remove(grab_timer_id);
1897 int _launch_init(struct amdmgr* amd)
1903 amd_cmdline = __proc_get_cmdline_bypid(getpid());
1908 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1910 _E("dbus_bus_get error");
1914 ret = aul_listen_e17_status_signal(__e17_status_handler, NULL);
1916 _D("ret : %d", ret);
1921 void _set_atom_effect(void)
1923 ATOM_IMAGE_EFFECT = ecore_x_atom_get(atom_name);
1926 void __set_appinfo_for_launchpad(const struct appinfo *ai, bundle *kb) {
1927 _D("Add hwacc, taskmanage, app_path and pkg_type into bundle for sending those to launchpad.");
1928 bundle_add(kb, AUL_K_HWACC, appinfo_get_value(ai, AIT_HWACC));
1929 bundle_add(kb, AUL_K_TASKMANAGE, appinfo_get_value(ai, AIT_TASKMANAGE));
1930 bundle_add(kb, AUL_K_EXEC, appinfo_get_value(ai, AIT_EXEC));
1931 bundle_add(kb, AUL_K_PACKAGETYPE, appinfo_get_value(ai, AIT_TYPE));