tizen 2.3 release
[framework/appfw/aul-1.git] / am_daemon / amd_launch.c
1 /*
2  *  aul
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21
22 #include <signal.h>
23 #include <Ecore_X.h>
24 #include <Ecore_Input.h>
25 #include <utilX.h>
26 #include <Ecore.h>
27 #include <Evas.h>
28 #include <Ecore_Evas.h>
29
30 #include <bundle.h>
31 #include <aul.h>
32 #include <glib.h>
33 #ifdef _APPFW_FEATURE_APP_CHECKER
34 #include <app-checker-server.h>
35 #endif
36 #include <string.h>
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <stdbool.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #include <fcntl.h>
43 #include <sys/prctl.h>
44 #include <sys/resource.h>
45 #include <pkgmgr-info.h>
46 #include <vconf.h>
47 #include <proc_stat.h>
48 #include <poll.h>
49
50 #include "amd_config.h"
51 #include "amd_launch.h"
52 #include "amd_appinfo.h"
53 #include "amd_status.h"
54 #include "amd_key.h"
55 #include "app_sock.h"
56 #include "simple_util.h"
57 #include "amd_cgutil.h"
58 #include "launch.h"
59 #include "app_signal.h"
60
61 #define DAC_ACTIVATE
62
63 #include "access_control.h"
64
65
66 #define TERM_WAIT_SEC 3
67 #define INIT_PID 1
68
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"
75
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"
79
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
83
84 #define HIDE_INDICATOR 0
85 #define SHOW_INDICATOR 1
86
87 #ifdef _APPFW_FEATURE_CPU_BOOST
88 #define APP_BOOSTING_PERIOD 1500 //msec
89 #endif
90
91 static char *amd_cmdline;
92
93 struct appinfomgr *_laf;
94 struct cginfo *_lcg;
95
96 DBusConnection *conn;
97 guint grab_timer_id;
98
99
100 #if 0
101 /*Unused data structure. Will be removed*/
102 typedef struct {
103         char *pkg_name;         /* package */
104         char *app_path;         /* exec */
105         char *original_app_path;        /* exec */
106         int multiple;           /* x_slp_multiple */
107         char *pkg_type;
108 } app_info_from_pkgmgr;
109 #endif
110
111 static GList *_kill_list;
112
113 struct ktimer {
114         pid_t pid;
115         char *group;
116         guint tid; /* timer ID */
117         struct cginfo *cg;
118 };
119
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);
128
129 static void _set_sdk_env(const char* appid, char* str) {
130         char buf[MAX_LOCAL_BUFSZ];
131         int ret;
132
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);
148         }
149 }
150
151 #define USE_ENGINE(engine) setenv("ELM_ENGINE", engine, 1);
152
153 static void _set_env(const char *appid, bundle * kb, const char *hwacc)
154 {
155         const char *str;
156         const char **str_array;
157         int len;
158         int i;
159
160         setenv("PKG_NAME", appid, 1);
161
162         USE_ENGINE("gl")
163
164         str = bundle_get_val(kb, AUL_K_STARTTIME);
165         if (str != NULL)
166                 setenv("APP_START_TIME", str, 1);
167
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]);
174                         }
175                 }
176         } else {
177                 str = bundle_get_val(kb, AUL_K_SDK);
178                 if(str != NULL) {
179                         _set_sdk_env(appid, (char *)str);
180                 }
181         }
182         if (hwacc != NULL)
183                 setenv("HWACC", hwacc, 1);
184 }
185
186 static void _prepare_exec(const char *appid, bundle *kb)
187 {
188         const struct appinfo *ai;
189         const char *app_path = NULL;
190         const char *pkg_type = NULL;
191         char *file_name;
192         char process_name[AUL_PR_NAME];
193         const char *hwacc;
194         int ret;
195
196         setsid();
197
198         signal(SIGINT, SIG_DFL);
199         signal(SIGTERM, SIG_DFL);
200         signal(SIGCHLD, SIG_DFL);
201
202         ai = appinfo_find(_laf, appid);
203
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);
207
208         /* SET PRIVILEGES*/
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);
212                 return;
213         }
214
215         /* SET DUMPABLE - for coredump*/
216         prctl(PR_SET_DUMPABLE, 1);
217
218         /* SET PROCESS NAME*/
219         if (app_path == NULL) {
220                 _D("app_path should not be NULL - check menu db");
221                 return;
222         }
223         file_name = strrchr(app_path, '/') + 1;
224         if (file_name == NULL) {
225                 _D("can't locate file name to execute");
226                 return;
227         }
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);
231
232         /* SET ENVIROMENT*/
233         _set_env(appid, kb, hwacc);
234 }
235
236 static int _add_cgroup(struct cginfo *cg, const char *group, int pid)
237 {
238         int r;
239
240         r = cgutil_exist_group(cg, CTRL_MGR, group);
241         if (r == -1) {
242                 _E("exist check error: %s", strerror(errno));
243                 return -1;
244         }
245
246         if (r == 0) { /* not exist */
247                 r = cgutil_create_group(cg, CTRL_MGR, group);
248                 if (r == -1) {
249                         _E("create group error");
250                         return -1;
251                 }
252         }
253
254         r = cgutil_group_add_pid(cg, CTRL_MGR, group, pid);
255         if (r == -1) {
256                 _E("add pid to group error");
257                 cgutil_remove_group(cg, CTRL_MGR, group);
258                 return -1;
259         }
260
261         return 0;
262 }
263
264 static char **__create_argc_argv(bundle * kb, int *margc)
265 {
266         char **argv;
267         int argc;
268
269         argc = bundle_export_to_argv(kb, &argv);
270
271         *margc = argc;
272         return argv;
273 }
274 static void _do_exec(struct cginfo *cg, const char *cmd, const char *group, bundle *kb)
275 {
276         gchar **argv;
277         gint argc;
278         char **b_argv;
279         int b_argc;
280         gboolean b;
281         int r;
282
283         r = _add_cgroup(cg, group, getpid());
284         if (r == -1)
285                 return;
286
287         b = g_shell_parse_argv(cmd, &argc, &argv, NULL);
288
289         if (kb) {
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);
294         }
295
296         if (b) {
297                 _prepare_exec(group, kb);
298                 execv(argv[0], argv);
299         }
300
301         _E("exec error: %s", strerror(errno));
302         g_strfreev(argv);
303 }
304
305 static inline int __send_app_launch_signal(int launch_pid)
306 {
307         DBusMessage *message;
308
309         if (conn == NULL)
310                 return -1;
311
312         message = dbus_message_new_signal(AUL_DBUS_PATH,
313                                           AUL_DBUS_SIGNAL_INTERFACE,
314                                           AUL_DBUS_APPLAUNCH_SIGNAL);
315
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");
320                 return -1;
321         }
322
323         if (dbus_connection_send(conn, message, NULL) == FALSE) {
324                 _E("dbus send error");
325                 return -1;
326         }
327
328         dbus_connection_flush(conn);
329         dbus_message_unref(message);
330
331         _D("send launch signal done\n");
332
333         return 0;
334 }
335
336 static int __send_watchdog_signal(int pid, int signal_num)
337 {
338         DBusMessage *message;
339
340         if (conn == NULL)
341                 return -1;
342
343         if (!_get_platform_ready()) {
344                 _E("[Info]_get_platform_ready return false");
345                 return -1;
346         }
347
348         if(_status_get_cooldown_status() == COOLDOWN_LIMIT) {
349                 _E("[Info]cooldown status : LimitAction");
350                 return -1;
351         }
352
353         message = dbus_message_new_signal(RESOURCED_PROC_OBJECT,
354                                           RESOURCED_PROC_INTERFACE,
355                                           RESOURCED_PROC_WATCHDOG_SIGNAL);
356
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");
362                 return -1;
363         }
364
365         if (dbus_connection_send(conn, message, NULL) == FALSE) {
366                 _E("dbus send error");
367                 return -1;
368         }
369
370         dbus_connection_flush(conn);
371         dbus_message_unref(message);
372
373         _D("send launch signal done\n");
374
375         return 0;
376 }
377
378 static int __check_cmdline(int ret)
379 {
380         char *cmdline;
381         int wait_count;
382         int cmdline_changed = 0;
383         int cmdline_exist = 0;
384         int r;
385
386         if (ret <= 1)
387                 return -1;
388
389         /* check normally was launched?*/
390         wait_count = 1;
391         do {
392                 cmdline = __proc_get_cmdline_bypid(ret);
393                 if (cmdline == NULL) {
394                         _E("error founded when being launched with %d", ret);
395
396                 } else if (strcmp(cmdline, amd_cmdline)) {
397                         free(cmdline);
398                         cmdline_changed = 1;
399                         break;
400                 } else {
401                         cmdline_exist = 1;
402                         free(cmdline);
403                 }
404
405                 _D("-- now wait to change cmdline --");
406                 usleep(50 * 1000);      /* 50ms sleep*/
407                 wait_count++;
408         } while (wait_count <= 20);     /* max 50*20ms will be sleep*/
409
410         if ((!cmdline_exist) && (!cmdline_changed)) {
411                 return -1;
412         }
413
414         if (!cmdline_changed)
415                 _E("process launched, but cmdline not changed");
416
417         return ret;
418 }
419
420 int service_start(struct cginfo *cg, const char *group, const char *cmd, bundle *kb)
421 {
422         int r;
423         pid_t p;
424
425         if (!cg || !group || !*group || !cmd || !*cmd) {
426                 errno = EINVAL;
427                 _E("service start: %s", strerror(errno));
428                 return -1;
429         }
430
431         p = fork();
432         switch (p) {
433         case 0: /* child process */
434                 _D("start service");
435 #ifdef _APPFW_FEATURE_PRIORITY_CHANGE
436                 r = setpriority(PRIO_PROCESS, 0, 0);
437                 if (r == -1)
438                 {
439                         SECURE_LOGE("Setting process (%d) priority to 0 failed, errno: %d (%s)",
440                                         getpid(), errno, strerror(errno));
441                 }
442 #endif
443                 _do_exec(cg, cmd, group, kb);
444                 /* exec error */
445
446                 exit(0);
447                 break;
448         case -1:
449                 _E("service start: fork: %s", strerror(errno));
450                 r = -1;
451                 break;
452         default: /* parent process */
453                 _D("child process: %d", p);
454                 r = __check_cmdline(p);
455                 if(r > 0)
456                         __send_app_launch_signal(r);
457                 break;
458         }
459
460         return r;
461 }
462
463 int _start_srv(const struct appinfo *ai, bundle *kb)
464 {
465         int r;
466         const char *group;
467         const char *cmd;
468         const char *pkgid;
469
470         group = appinfo_get_filename(ai);
471
472         cmd = appinfo_get_value(ai, AIT_EXEC);
473         if (!cmd) {
474                 _E("start service: '%s' has no exec", group);
475                 return -1;
476         }
477
478         r = service_start(_lcg, group, cmd, kb);
479         if (r == -1) {
480                 _E("start service: '%s': failed", group);
481                 return -1;
482         }
483
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);
487
488         return 0;
489 }
490
491 static void _free_kt(struct ktimer *kt)
492 {
493         if (!kt)
494                 return;
495
496         cgutil_unref(&kt->cg);
497         free(kt->group);
498         free(kt);
499 }
500
501 static void _kill_pid(struct cginfo *cg, const char *group, pid_t pid)
502 {
503         int r;
504
505         if (pid <= INIT_PID) /* block sending to all process or init */
506                 return;
507
508         r = cgutil_exist_group(cg, CTRL_MGR, group);
509         if (r == -1) {
510                 _E("send SIGKILL: exist: %s", strerror(errno));
511                 return;
512         }
513         if (r == 0) {
514                 _D("send SIGKILL: '%s' not exist", group);
515                 return;
516         }
517
518         /* TODO: check pid exist in group */
519
520         r = kill(pid, 0);
521         if (r == -1) {
522                 _D("send SIGKILL: pid %d not exist", pid);
523                 return;
524         }
525
526         r = kill(pid, SIGKILL);
527         if (r == -1)
528                 _E("send SIGKILL: %s", strerror(errno));
529 }
530
531 static gboolean _ktimer_cb(gpointer data)
532 {
533         struct ktimer *kt = data;
534
535         _kill_pid(kt->cg, kt->group, kt->pid);
536         _kill_list = g_list_remove(_kill_list, kt);
537         _free_kt(kt);
538
539         return FALSE;
540 }
541
542 static void _add_list(struct cginfo *cg, const char *group, pid_t pid)
543 {
544         struct ktimer *kt;
545
546         kt = calloc(1, sizeof(*kt));
547         if (!kt)
548                 return;
549
550         kt->pid = pid;
551         kt->group = strdup(group);
552         if (!kt->group) {
553                 free(kt);
554                 return;
555         }
556
557         kt->cg = cgutil_ref(cg);
558         kt->tid = g_timeout_add_seconds(TERM_WAIT_SEC, _ktimer_cb, kt);
559
560         _kill_list = g_list_append(_kill_list, kt);
561 }
562
563 static inline void _del_list(GList *l)
564 {
565         struct ktimer *kt;
566
567         if (!l)
568                 return;
569
570         kt = l->data;
571
572         g_source_remove(kt->tid);
573         _free_kt(kt);
574         _kill_list = g_list_delete_link(_kill_list, l);
575 }
576
577 static int _kill_pid_cb(void *user_data, const char *group, pid_t pid)
578 {
579         int r;
580
581         if (pid <= INIT_PID) /* block sending to all process or init */
582                 return 0;
583
584         r = kill(pid, SIGTERM);
585         if (r == -1)
586                 _E("send SIGTERM: %s", strerror(errno));
587
588         _add_list(user_data, group, pid);
589
590         return 0;
591 }
592
593 int service_stop(struct cginfo *cg, const char *group)
594 {
595         if (!cg || !group || !*group) {
596                 errno = EINVAL;
597                 return -1;
598         }
599
600         _D("service_stop, group %s", group);
601
602         return cgutil_group_foreach_pid(cg, CTRL_MGR, FILENAME(group),
603                         _kill_pid_cb, cg);
604 }
605
606 void service_release(const char *group)
607 {
608         GList *l;
609         GList *d;
610
611         if (!group || !*group)
612                 return;
613
614         group = FILENAME(group);
615
616         d = NULL;
617         for (l = _kill_list; l; l = g_list_next(l)) {
618                 struct ktimer *k = l->data;
619
620                 _del_list(d);
621
622                 if (k->group && !strcmp(k->group, group))
623                         d = l;
624                 else
625                         d = NULL;
626         }
627
628         _del_list(d);
629 }
630
631 int _send_to_sigkill(int pid)
632 {
633         int pgid;
634
635         pgid = getpgid(pid);
636         if (pgid <= 1)
637                 return -1;
638
639         if (killpg(pgid, SIGKILL) < 0)
640                 return -1;
641
642         return 0;
643 }
644 int _resume_app(int pid, int clifd)
645 {
646         int dummy;
647         int ret;
648         if ((ret =
649              __app_send_raw_with_delay_reply(pid, APP_RESUME_BY_PID, (unsigned char *)&dummy,
650                             sizeof(int))) < 0) {
651                 if (ret == -EAGAIN)
652                         _E("resume packet timeout error");
653                 else {
654                         _E("raise failed - %d resume fail\n", pid);
655                         _E("we will term the app - %d\n", pid);
656                         _send_to_sigkill(pid);
657                         ret = -1;
658                 }
659                 __real_send(clifd, ret);
660         }
661         _D("resume done\n");
662
663         if (ret > 0)
664                 __set_reply_handler(ret, pid, clifd, APP_RESUME_BY_PID);
665
666         return ret;
667 }
668
669 int _fake_launch_app(int cmd, int pid, bundle * kb, int clifd)
670 {
671         int datalen;
672         int ret;
673         bundle_raw *kb_data;
674
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);
679         }
680         free(kb_data);
681
682         if (ret > 0)
683                 __set_reply_handler(ret, pid, clifd, cmd);
684
685         return ret;
686 }
687
688 static void __real_send(int clifd, int ret)
689 {
690         if (send(clifd, &ret, sizeof(int), MSG_NOSIGNAL) < 0) {
691                 if (errno == EPIPE) {
692                         _E("send failed due to EPIPE.\n");
693                 }
694                 _E("send fail to client");
695         }
696
697         close(clifd);
698 }
699
700 static gboolean __au_glib_check(GSource *src)
701 {
702         GSList *fd_list;
703         GPollFD *tmp;
704
705         fd_list = src->poll_fds;
706         do {
707                 tmp = (GPollFD *) fd_list->data;
708                 if ((tmp->revents & (POLLIN | POLLPRI)))
709                         return TRUE;
710                 fd_list = fd_list->next;
711         } while (fd_list);
712
713         return FALSE;
714 }
715
716 static gboolean __au_glib_dispatch(GSource *src, GSourceFunc callback,
717                 gpointer data)
718 {
719         callback(data);
720         return TRUE;
721 }
722
723 static gboolean __au_glib_prepare(GSource *src, gint *timeout)
724 {
725         return FALSE;
726 }
727
728 static GSourceFuncs funcs = {
729         .prepare = __au_glib_prepare,
730         .check = __au_glib_check,
731         .dispatch = __au_glib_dispatch,
732         .finalize = NULL
733 };
734
735 struct reply_info {
736         GSource *src;
737         GPollFD *gpollfd;
738         guint timer_id;
739         int clifd;
740         int pid;
741         int cmd;
742 };
743
744 static gboolean __reply_handler(gpointer data)
745 {
746         struct reply_info *r_info = (struct reply_info *) data;;
747         int fd = r_info->gpollfd->fd;
748         int len;
749         int res = 0;
750         int clifd = r_info->clifd;
751         int pid = r_info->pid;
752         int cmd = r_info->cmd;
753
754         len = recv(fd, &res, sizeof(int), 0);
755         if (len == -1) {
756                 if (errno == EAGAIN) {
757                         _E("recv timeout : %s", strerror(errno));
758                         res = -EAGAIN;
759                 } else {
760                         _E("recv error : %s", strerror(errno));
761                         res = -ECOMM;
762                 }
763         }
764         close(fd);
765
766         if(res < 0) {
767                 if ( cmd == APP_TERM_BY_PID ) {
768                         __real_send(clifd, -1);
769                 } else if ( cmd == APP_START_ASYNC ) {
770                         close(clifd);
771                 } else {
772                         __real_send(clifd, res);
773                 }
774         } else {
775                 if ( cmd == APP_TERM_BY_PID ) {
776                         __real_send(clifd, 0);
777                 } else if ( cmd == APP_START_ASYNC ) {
778                         close(clifd);
779                 } else {
780                         __real_send(clifd, pid);
781                 }
782         }
783
784         _D("listen fd(%d) , send fd(%d), pid(%d), cmd(%d)", fd, clifd, pid, cmd);
785
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);
790         free(r_info);
791
792         return TRUE;
793 }
794
795 static gboolean __recv_timeout_handler(gpointer data)
796 {
797         struct reply_info *r_info = (struct reply_info *) data;
798         int fd = r_info->gpollfd->fd;
799
800         _E("application is not responding : pid(%d) cmd(%d)", r_info->pid, r_info->cmd);
801
802         close(fd);
803
804         switch (r_info->cmd) {
805         case APP_OPEN:
806         case APP_RESUME:
807         case APP_START:
808         case APP_START_RES:
809         case APP_START_ASYNC:
810 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
811         case APP_START_MULTI_INSTANCE:
812 #endif
813                 __send_watchdog_signal(r_info->pid, SIGKILL);
814                 break;
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);
819                         return -1;
820                 }
821                 __real_send(r_info->clifd, 0);
822                 break;
823         }
824
825         g_source_remove_poll(r_info->src, r_info->gpollfd);
826         g_source_destroy(r_info->src);
827         g_free(r_info->gpollfd);
828         free(r_info);
829
830         return FALSE;
831 }
832
833 static void __set_reply_handler(int fd, int pid, int clifd, int cmd)
834 {
835         GPollFD *gpollfd;
836         GSource *src;
837         struct reply_info *r_info;
838
839         src = g_source_new(&funcs, sizeof(GSource));
840
841         gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
842         gpollfd->events = POLLIN;
843         gpollfd->fd = fd;
844
845         r_info = malloc(sizeof(*r_info));
846         r_info->clifd = clifd;
847         r_info->pid = pid;
848         r_info->src = src;
849         r_info->gpollfd = gpollfd;
850         r_info->cmd = cmd;
851
852
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);
859
860         _D("listen fd : %d, send fd : %d", fd, clifd);
861 }
862
863 int _term_app(int pid, int clifd)
864 {
865         int dummy;
866         int ret;
867
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);
874                         return -1;
875                 }
876                 __real_send(clifd, 0);
877         }
878         _D("term done\n");
879         if (ret > 0)
880                 __set_reply_handler(ret, pid, clifd, APP_TERM_BY_PID);
881
882         return 0;
883 }
884
885 #include <dirent.h>
886 #include <sqlite3.h>
887 static int __launchpad_update_task_managed_field(const char* app_id, int task_managed)
888 {
889         sqlite3 *db = NULL;
890         char *sqlite3_error_msg = NULL;
891
892         if (sqlite3_open("/opt/dbspace/.pkgmgr_parser.db", &db) != SQLITE_OK) {
893             _E("sqlite3_open() failed! -> %s\n", sqlite3_errmsg(db));
894             return -1;
895         }
896
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);
900             sqlite3_close(db);
901             return -1;
902         }
903
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);
907                 sqlite3_close(db);
908                 return -1;
909         }
910
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);
914
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);
918                 return -1;
919         }
920
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!");
925                 }
926                 sqlite3_close(db);
927                 return -1;
928         }
929
930         sqlite3_close(db);
931
932 return 0;
933 }
934
935 static void __pre_launching_processing(const char* app_id)
936 {
937     const char* const PRE_LAUNCHING_LIST_DIR = "/opt/usr/etc/wrt_launchpad_daemon/pre_launching_list";
938
939     struct stat file_status;
940     if (stat(PRE_LAUNCHING_LIST_DIR, &file_status) == 0) {
941         if (S_ISDIR(file_status.st_mode)) {
942             int ret;
943             DIR *dir = NULL;
944             struct dirent entry, *result;
945
946             dir = opendir(PRE_LAUNCHING_LIST_DIR);
947
948             if (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) {
954                         continue;
955                     }
956
957                     if (strcmp(entry.d_name, app_id) == 0)
958                     {
959                         __launchpad_update_task_managed_field(app_id, 1);
960                     }
961                 }
962
963                 closedir(dir);
964             }
965             else {
966                 _E("opendir(\"%s\") failed!", PRE_LAUNCHING_LIST_DIR);
967             }
968         }
969     }
970 }
971
972 static int __nofork_processing(int cmd, int pid, bundle * kb, int clifd)
973 {
974         int ret = -1;
975         int r;
976         const char *operation;
977
978         operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__");
979
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)) {
985                 char *arr[2];
986                 char val[32];
987                 snprintf(val, sizeof(val), "%d", APP_BOOSTING_PERIOD);
988                 arr[0] = val;
989                 arr[1] = NULL;
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);
993         }
994 #endif
995         _D("__nofork_processing, cmd: %d, pid: %d", cmd, pid);
996         switch (cmd) {
997         case APP_OPEN:
998         case APP_RESUME:
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");
1003                 break;
1004
1005         case APP_START:
1006         case APP_START_RES:
1007         case APP_START_ASYNC:
1008 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
1009         case APP_START_MULTI_INSTANCE:
1010 #endif
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");
1015                 break;
1016         }
1017
1018         return ret;
1019 }
1020
1021 #if __CPU_FREQ_CON
1022 #include <sysman.h>
1023 static Eina_Bool
1024 __amd_sysman_restore_hz_timer_cb(void *data)
1025 {
1026    struct context *ctxt = data;
1027
1028    if (ctxt->timer)
1029      ctxt->timer = NULL;
1030
1031    sysman_release_cpu_min_frequency ();
1032
1033    _D("*******[1.6MHZ Support] Released\n " );
1034
1035    return ECORE_CALLBACK_CANCEL; // same as EINA_FALSE
1036 }
1037 #endif
1038
1039 struct context{
1040         Ecore_Timer *timer;
1041 };
1042
1043 static int __amd_change_min_cpulock_count(int value)
1044 {
1045         int fd = -1;
1046         char buf[16]={0,};
1047         fd = open(SYS_MIN_CPU_LOCK_FILE, O_WRONLY);
1048         if (fd == -1)
1049                 return -1;
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));
1053                 close(fd);
1054                 return -1;
1055         }
1056         close(fd);
1057         _D("[AMD]: Succesfully changed min cpu value to %d\n", value);
1058         return 0;
1059 }
1060
1061 static Eina_Bool __amd_restore_min_cpulock_count_cb(void *data)
1062 {
1063         struct context *ctxt = data;
1064         if (ctxt->timer)
1065                 ctxt->timer = NULL;
1066         __amd_change_min_cpulock_count(MIN_CPU_LCK_CNT);
1067         return ECORE_CALLBACK_CANCEL;
1068 }
1069
1070 static void __amd_effect_image_file_set(char *image_file)
1071 {
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);
1076 }
1077
1078
1079 static void __amd_send_message_to_e17(int screenmode, const char * indicator, int effect_type, int theme)
1080 {
1081         Ecore_X_Window root_win;
1082         int ret;
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)
1087                 screenmode=0;
1088
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);
1096
1097         }else{
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);
1104         }
1105         ecore_x_flush();
1106         _D("ecore_x_client_message32_send : %d",ret);
1107 }
1108
1109
1110
1111 static int append_variant(DBusMessageIter *iter, const char *sig, char *param[])
1112 {
1113         char *ch;
1114         int i;
1115         int int_type;
1116         uint64_t int64_type;
1117
1118         if (!sig || !param)
1119                 return 0;
1120
1121         for (ch = (char*)sig, i = 0; *ch != '\0'; ++i, ++ch) {
1122                 switch (*ch) {
1123                 case 'i':
1124                         int_type = atoi(param[i]);
1125                         dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &int_type);
1126                         break;
1127                 case 'u':
1128                         int_type = atoi(param[i]);
1129                         dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &int_type);
1130                         break;
1131                 case 't':
1132                         int64_type = atoi(param[i]);
1133                         dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT64, &int64_type);
1134                         break;
1135                 case 's':
1136                         dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, param[i]);
1137                         break;
1138                 default:
1139                         return -EINVAL;
1140                 }
1141         }
1142
1143         return 0;
1144 }
1145
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[])
1149 {
1150         DBusMessage *msg;
1151         DBusMessageIter iter;
1152         DBusMessage *reply;
1153         DBusError err;
1154         int r, ret;
1155
1156         msg = dbus_message_new_method_call(dest, path, interface, method);
1157         if (!msg) {
1158                 _E("dbus_message_new_method_call(%s:%s-%s)", path, interface, method);
1159                 return -EBADMSG;
1160         }
1161
1162         if( param ) {
1163                 dbus_message_iter_init_append(msg, &iter);
1164                 r = append_variant(&iter, sig, param);
1165                 if (r < 0) {
1166                         _E("append_variant error(%d)", r);
1167                         dbus_message_unref(msg);
1168                         return -EBADMSG;
1169                 }
1170         }
1171
1172         dbus_error_init(&err);
1173
1174         reply = dbus_connection_send_with_reply_and_block(conn, msg, 500, &err);
1175         dbus_message_unref(msg);
1176         if (!reply) {
1177                 _E("dbus_connection_send error(%s:%s)", err.name, err.message);
1178                 dbus_error_free(&err);
1179                 return -EBADMSG;
1180         }
1181
1182         r = dbus_message_get_args(reply, &err, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
1183         dbus_message_unref(reply);
1184         if (!r) {
1185                 _E("no message : [%s:%s]", err.name, err.message);
1186                 dbus_error_free(&err);
1187                 return -EBADMSG;
1188         }
1189
1190         return ret;
1191 }
1192
1193 static gboolean __grab_timeout_handler(gpointer data)
1194 {
1195         int pid = (int) data;
1196
1197         if(_input_window_get() != 0)
1198                 ecore_x_pointer_ungrab();
1199         _D("pid(%d) ecore_x_pointer_ungrab", pid);
1200
1201         return FALSE;
1202 }
1203
1204 static bool __check_ug_client_process_pool(const char *app_path)
1205 {
1206         char sympath[MAX_PACKAGE_APP_PATH_SIZE] = {0,};
1207         int ret;
1208         bool func_ret = true;
1209
1210         if(!app_path) {
1211                 _E("invalid input param");
1212                 func_ret = false;
1213                 goto func_out;
1214         }
1215
1216         if(strncmp(app_path, "/usr/ug/bin/", strlen("/usr/ug/bin")) != 0) {
1217                 func_ret = false;
1218                 goto func_out;
1219         }
1220
1221         if(readlink(app_path, sympath, MAX_PACKAGE_APP_PATH_SIZE-1) == -1) {
1222                 _E("read app path link error(%d)", errno);
1223                 func_ret = false;
1224                 goto func_out;
1225         }
1226
1227         if(strncmp(sympath, "/usr/bin/ug-client", strlen("/usr/bin/ug-client")) != 0) {
1228                 func_ret = false;
1229         }
1230
1231 func_out :
1232         _D("ug process pool check result : %d", func_ret);
1233         return func_ret;
1234 }
1235
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)
1238 {
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;
1249         int ret = 0;
1250         int multiwindow_enabled = 0;
1251
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");
1256                 return;
1257         }
1258
1259         SECURE_LOGD("callee appid : %s / caller_appid : %s", callee_appid, caller_appid);
1260
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");
1265                 return;
1266         }
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");
1270                 return;
1271         }
1272         callee_ai = appinfo_find(_laf, callee_appid);
1273         if(callee_ai == NULL) {
1274                 _D("no callee appinfo");
1275                 return;
1276         }
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");
1280                 return;
1281         }
1282
1283         /* check aul_forwad_app case */
1284         if((caller_appid) && (strcmp(caller_appid, "org.tizen.app-selector") == 0)) {
1285                 _D("forward app case");
1286                 return;
1287         }
1288
1289         /* get multi window layout value */
1290         caller = bundle_get_val(kb, "__APP_SVC_K_WIN_ID__");
1291         if(caller) {
1292                 caller_win_id = atoi(caller);
1293         } else {
1294                 _D("caller win id is null");
1295                 return;
1296         }
1297         if(caller_win_id == 0) {
1298                 _D("caller id is 0");
1299                 return;
1300         }
1301
1302         if( ecore_x_window_prop_card32_get(caller_win_id,
1303                 ECORE_X_ATOM_E_WINDOW_DESKTOP_LAYOUT, &layout, 1 ) != -1 )
1304         {
1305                 if(layout == 0 || layout == 1) {
1306                         _D("layout : %d", layout);
1307                 } else {
1308                         _W("x_window__prop_get layout value error : %d", layout);
1309                         return;
1310                 }
1311         } else {
1312                 layout = -1;
1313         }
1314
1315         do {
1316                 const char *operation = NULL;
1317                 operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__");
1318                 if(operation == NULL) {
1319                         _D("operation is null");
1320                         break;
1321                 }
1322
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 */
1330                                 if(caller) {
1331                                         if(bundle_del(kb, "__APP_SVC_K_WIN_ID__") == -1) {
1332                                                 _D("failed to remove window id of bundle (errno : %d)", errno);
1333                                         }
1334                                 }
1335                                 break;
1336                         }
1337                 }
1338         } while (0);
1339
1340         if(is_open_via_multi) {
1341                 if(layout == 1)
1342                         layout = 0;
1343                 else
1344                         layout = 1;
1345
1346                 _D("open via multi scenario. reverted layout id is %d", layout);
1347         } else {
1348                 /* multi window support app need be launched with full view
1349                 when app is launched from multi window support app with full view. */
1350                 if(layout == -1) {
1351                         startup_type = 0;
1352                 }
1353         }
1354
1355         char tmp_layout[128];
1356         char tmp_startup[128];
1357
1358         snprintf(tmp_layout, 128, "%d", layout);
1359         snprintf(tmp_startup, 128, "%d", startup_type);
1360
1361         if(bundle_add(kb, "window_layout_id", tmp_layout) != 0) {
1362                 _W("winow layout id bundle add error");
1363         }
1364         if(bundle_add(kb, "window_startup_type", tmp_startup) != 0) {
1365                 _W("winow startup type bundle add error");
1366         }
1367
1368         SECURE_LOGD("window startup type(%d) and layout id(%d) is added", startup_type, layout);
1369
1370         return;
1371 }
1372 #endif
1373
1374 int __check_mode(const struct appinfo *ai)
1375 {
1376 #ifdef _APPFW_FEATURE_TTS_MODE
1377         int tts_mode = 0;
1378         const char *tts_support = NULL;
1379 #endif
1380 #ifdef _APPFW_FEATURE_ULTRA_POWER_SAVING_MODE
1381         int ups_mode = 0;
1382         const char *ups_support = NULL;
1383 #endif
1384
1385 #ifdef _APPFW_FEATURE_TTS_MODE
1386         vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &tts_mode);
1387         if(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)
1391                         return -1;
1392         }
1393 #endif
1394
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)
1401                         return -1;
1402         }
1403 #endif
1404
1405         return 0;
1406 }
1407
1408 int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_uid, int fd)
1409 {
1410         const struct appinfo *ai;
1411         const struct appinfo *caller_ai;
1412         int ret = -1;
1413         const char *multiple = NULL;
1414         const char *app_path = NULL;
1415         const char *pkg_type = NULL;
1416         const char *component_type = NULL;
1417         int pid = -1;
1418         char tmp_pid[MAX_PID_STR_BUFSZ];
1419         const char *permission;
1420         const char *pkgid;
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;
1432         int status = -1;
1433         int r = -1;
1434         char trm_buf[MAX_PACKAGE_STR_SIZE];
1435
1436         int effect_mode = 0;
1437 #ifdef _APPFW_FEATURE_WMS_CONNECTION_CHECK
1438         int wmanager_connected = 0;
1439 #endif
1440         char *caller_component_type = NULL;
1441
1442         if (appid == NULL || kb == NULL
1443                 || caller_pid < 0 || caller_uid < 0 || fd < 0) {
1444                 _D("invalid parameter");
1445                 if (fd >= 0)
1446                         __real_send(fd, -1);
1447                 return -1;
1448         }
1449
1450         snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", caller_pid);
1451         bundle_add(kb, AUL_K_CALLER_PID, tmp_pid);
1452
1453         if (cmd == APP_START_RES)
1454                 bundle_add(kb, AUL_K_WAIT_RESULT, "1");
1455
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));
1459                 if(ret == 0) {
1460                         bundle_add(kb, AUL_K_CALLER_APPID, caller_appid);
1461                 }
1462         } else {
1463                 bundle_add(kb, AUL_K_CALLER_APPID, caller);
1464         }
1465         curr_caller = bundle_get_val(kb,AUL_K_CALLER_APPID);
1466         SECURE_LOGD("caller : %s", curr_caller);
1467
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)
1472         {
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);
1475         }
1476 #endif
1477         ai = appinfo_find(_laf, appid);
1478         if(ai == NULL) {
1479                 _D("no appinfo");
1480                 __real_send(fd, -1);
1481                 return -1;
1482         } else {
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) ) {
1485                         _D("blocking");
1486                         __real_send(fd, -EREJECTED);
1487                         return -EREJECTED;
1488                 } else if(pkg_status && strncmp(pkg_status, "unmounted", 9) == 0 ) {
1489                         _D("unmounted");
1490                         __real_send(fd, -1);
1491                         return -1;
1492                 }
1493         }
1494
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);
1500
1501         operation = bundle_get_val(kb, "__APP_SVC_OP_TYPE__");
1502         caller_ai = appinfo_find(_laf, curr_caller);
1503
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
1510 #endif
1511                                         ))
1512                 {
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)
1519                                                 close(fd);
1520                                         else
1521                                                 __real_send(fd, pid);
1522                                         return pid;
1523                                 }
1524                         }
1525                 }
1526         }
1527
1528         if(__check_mode(ai) < 0) {
1529                 pid = -EREJECTED;
1530                 if(cmd == APP_START_ASYNC)
1531                         close(fd);
1532                 else
1533                         __real_send(fd, pid);
1534                 return pid;
1535         }
1536
1537         pkgmgrinfo_client_request_enable_external_pkg(pkgid);
1538
1539         if (component_type && strncmp(component_type, "uiapp", 5) == 0) {
1540
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));
1544                 }
1545 #endif
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);
1554                                 }
1555                         }
1556                 }
1557
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,};
1562
1563                 caller_app_path = appinfo_get_value(caller_ai, AIT_EXEC);
1564
1565                 SECURE_LOGD("callee path(%s) caller path(%s)", app_path, caller_app_path);
1566
1567                 readlink(app_path, app_path_link, 512);
1568                 readlink(caller_app_path, caller_app_path_link, 512);
1569
1570                 SECURE_LOGD("callee link(%s) caller link(%s)", app_path_link, caller_app_path_link);
1571
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);
1579                                 return -1;
1580                         }
1581                 }
1582 #endif
1583
1584                 if(curr_caller) {
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();
1589                                 if(in_win) {
1590                                         ret = ecore_x_pointer_grab(in_win);
1591                                         _D("win(%x) ecore_x_pointer_grab(%d)", in_win, ret);
1592                                 }
1593                         }
1594                 }
1595
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;
1601                         } else {
1602                                 if(strncmp(pkg_type, "wgt", 3) == 0) {
1603                                         __pre_launching_processing(appid);
1604                                 }
1605                                 proc_group_change_status(PROC_CGROUP_SET_RESUME_REQUEST, pid, appid);
1606                                 if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) {
1607                                         pid = ret;
1608                                 } else {
1609                                         delay_reply = 1;
1610                                 }
1611                         }
1612                 } else if (cmd != APP_RESUME) {
1613                         if(status == STATUS_DYING && pid > 0) {
1614                                 r = kill(pid, SIGKILL);
1615                                 if (r == -1)
1616                                         _D("send SIGKILL: %s", strerror(errno));
1617                         }
1618                         fake_effect = bundle_get_val(kb, "__FAKE_EFFECT__");
1619
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)) {
1624                                 char *arr[2];
1625                                 char val[32];
1626                                 snprintf(val, sizeof(val), "%d", APP_BOOSTING_PERIOD);
1627                                 arr[0] = val;
1628                                 arr[1] = NULL;
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);
1632                         }
1633 #endif
1634                         /*
1635                          *      effect_mode = 0
1636                          *              default mode : fake effect off, 1.6 MHZ off
1637                          *      effect_mode = 1
1638                          *              full mode : fake effect on, 1.6 MHZ on
1639                          *      effect_mode = 2
1640                          *              fake effect mode : fake effect on, 1.6 MHZ off
1641                          *      effect_mode = 3
1642                          *              1.6 MHZ mode : faek effect off, 1.6MHZ on
1643                          *
1644                          */
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);
1648 #endif
1649                         //_D("*******[effect_mode] Mode : %d\n ", effect_mode );
1650
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
1657 #endif
1658                                 ){
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;
1665 #endif
1666                                 const char *indicator = NULL;
1667                                 int screen_mode = 0;
1668                                 bool rotate_allowed = false;
1669                                 int file_type = 1;
1670                                 int theme = 0;
1671
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);
1681 #endif
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) {
1686                                                 screen_mode = 1;
1687                                         }
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.*/
1690                                                 if (landscapeimg) {
1691                                                         snprintf(image_filename, 255, "%s", landscapeimg);
1692                                                 }
1693                                         } else {
1694                                                 snprintf(image_filename, 255, "%s", portraitimg);
1695                                         }
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) {
1699                                                         file_type = 0;
1700                                                         theme = 0;
1701                                                 } else if (strncmp(effectimg_type, "edj-light", strlen(effectimg_type)) == 0) {
1702                                                         file_type = 0;
1703                                                         theme = 1;
1704                                                 } else if (strncmp(effectimg_type, "edj-default", strlen(effectimg_type)) == 0) {
1705                                                         file_type = 0;
1706                                                         theme = 2;
1707                                                 } else {
1708                                                         file_type = 1;
1709                                                         theme = 0;
1710                                                 }
1711
1712                                                 do {
1713                                                         if (file_type == 1)
1714                                                                 break;
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);
1720                                                                 break;
1721                                                         }
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);
1727                                                                 break;
1728                                                         }
1729                                                 } while(0);
1730 #endif
1731 #ifndef _APPFW_FEATURE_DEFAULT_FAKE_IMAGE
1732                                                 __amd_effect_image_file_set(image_filename);
1733 #else
1734                                                 if(file_type == 1) {
1735                                                         __amd_effect_image_file_set("/usr/share/splash_images/type0_portrait.bmp");
1736                                                 } else {
1737                                                         __amd_effect_image_file_set(image_filename);
1738                                                 }
1739 #endif
1740                                                 __amd_send_message_to_e17(screen_mode, indicator, file_type, theme);
1741                                         }
1742                                 }
1743                         }
1744
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;
1750                         }
1751 #else
1752                         if (strncmp(pkg_type, "wgt", 3) == 0) {
1753                                 pad_pid = WEB_LAUNCHPAD_PID;
1754                         }
1755 #endif
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.");
1762                                 } else {
1763                                     pad_pid = NATIVE_LAUNCHPAD_PID;
1764                 }
1765                         }
1766 #endif
1767 #ifdef _APPFW_FEATURE_PROCESS_POOL
1768                         else {
1769                                 const char *process_pool = appinfo_get_value(ai, AIT_POOL);
1770                                 _D("process_pool: %s", process_pool);
1771
1772                                 const char *hwacc = appinfo_get_value(ai, AIT_HWACC);
1773                                 _D("h/w acceleration: %s", hwacc);
1774
1775                                 SECURE_LOGD("appid: %s", appid);
1776
1777                                 if (strncmp(process_pool, "true", strlen("true")) == 0)
1778                                 {
1779  #ifndef _APPFW_FEATURE_PROCESS_POOL_COMMON
1780                                         if (strncmp(hwacc, "USE", strlen("USE")) != 0)
1781                                         {
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;
1785                                         }
1786                                         else
1787                                         {
1788   #ifndef _APPFW_FEATURE_PROCESS_POOL_HW_RENDERING
1789                                                 _D("Sending to legacy launchpad because launchpad type2 is not supported.");
1790   #else
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;
1794   #endif
1795                                         }
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
1801
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)
1805                                         {
1806                                                 _D("Sending to legacy launchpad because process-pool launchpad is not initialized.");
1807                                                 pad_pid = LAUNCHPAD_PID;
1808                                         }
1809                                 }
1810                         }
1811 #endif //_APPFW_FEATURE_PROCESS_POOL
1812
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;
1817                         }
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);
1822                 }
1823                 if(pid < 0) {
1824                         if(_input_window_get() != 0)
1825                                 ecore_x_pointer_ungrab();
1826                         _D("pid(%d) ecore_x_pointer_ungrab", pid);
1827                 } else {
1828                         grab_timer_id = g_timeout_add(1000, __grab_timeout_handler, pid);
1829                 }
1830         }
1831         else if (component_type && strncmp(component_type, "svcapp", 6) == 0) {
1832                 pid = _status_app_is_running_v2(appid);
1833                 if (pid > 0) {
1834                         if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) {
1835                                 pid = ret;
1836                         }
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;
1845                                 }
1846                                 proc_cgroup_launch(PROC_CGROUP_SET_LAUNCH_REQUEST, pid, appid, pkgid);
1847                         } else {
1848                                 pid = service_start(_lcg, appid, app_path, kb);
1849                                 proc_cgroup_launch(PROC_CGROUP_SET_SERVICE_REQUEST, pid, appid, pkgid);
1850                         }
1851 #else
1852                         pid = service_start(_lcg, appid, app_path, kb);
1853                         proc_cgroup_launch(PROC_CGROUP_SET_SERVICE_REQUEST, pid, appid, pkgid);
1854 #endif
1855                 }
1856         } else {
1857                 _E("unkown application");
1858         }
1859
1860         if(!delay_reply) {
1861                 if(cmd == APP_START_ASYNC)
1862                         close(fd);
1863                 else
1864                         __real_send(fd, pid);
1865         }
1866
1867         if(pid > 0) {
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);
1872                 else
1873 #endif
1874                         _status_add_app_info_list(appid, app_path, curr_caller, pid, pad_pid);
1875
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;
1879 #endif
1880         }
1881
1882         return pid;
1883 }
1884
1885 int __e17_status_handler(int pid, int status, void *data)
1886 {
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);
1892         }
1893
1894         return 0;
1895 }
1896
1897 int _launch_init(struct amdmgr* amd)
1898 {
1899         int ret = 0;
1900
1901         _D("_launch_init");
1902
1903         amd_cmdline = __proc_get_cmdline_bypid(getpid());
1904
1905         _laf = amd->af;
1906         _lcg = amd->cg;
1907
1908         conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1909         if (!conn) {
1910                 _E("dbus_bus_get error");
1911                 return -EBADMSG;
1912         }
1913
1914         ret = aul_listen_e17_status_signal(__e17_status_handler, NULL);
1915
1916         _D("ret : %d", ret);
1917
1918         return 0;
1919 }
1920
1921 void _set_atom_effect(void)
1922 {
1923         ATOM_IMAGE_EFFECT = ecore_x_atom_get(atom_name);
1924 }
1925
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));
1932 }