tizen 2.4 release
[framework/appfw/aul-1.git] / src / 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 #define _GNU_SOURCE
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <sys/time.h>
26 #include <fcntl.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <dirent.h>
31 #include <glib.h>
32 #ifdef _APPFW_FEATURE_APP_CONTROL_LITE
33 #include <pkgmgr-info.h>
34 #include <pkgmgrinfo_zone.h>
35 #endif
36 #include <ttrace.h>
37 #include <bundle_internal.h>
38
39 #include "aul.h"
40 #include "aul_api.h"
41 #include "app_sock.h"
42 #include "perf.h"
43 #include "simple_util.h"
44 #include "launch.h"
45 #include "key.h"
46 #include "aul_util.h"
47 #include "aul_zone.h"
48 #ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
49 #include <dbus/dbus.h>
50 #include "app_signal.h"
51 #define TEP_ISMOUNT_MAX_RETRY_CNT 20
52 #endif
53
54 static int aul_initialized = 0;
55 static int aul_fd;
56
57 static int (*_aul_handler) (aul_type type, bundle *kb, void *data) = NULL;
58 static void *_aul_data;
59
60
61 static int app_resume();
62 static int app_terminate();
63 static void __clear_internal_key(bundle *kb);
64 static inline void __set_stime(bundle *kb);
65 static int __app_start_internal(gpointer data);
66 static int __app_launch_local(bundle *b);
67 static int __send_result_to_launchpad(int fd, int res);
68
69 #ifdef _APPFW_FEATURE_PROCESS_POOL
70 static void *__window_object = NULL;
71 static void *__bg_object = NULL;
72 static void *__conformant_object = NULL;
73 #endif
74
75 #ifdef _APPFW_FEATURE_DATA_CONTROL
76 static data_control_provider_handler_fn __dc_handler = NULL;
77 #endif
78
79 extern  int aul_launch_fini();
80
81 #ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
82 SLPAPI int aul_is_tep_mount_dbus_done(const char *tep_string)
83 {
84         DBusMessage *msg;
85         DBusMessage *reply;
86         DBusError err;
87         int ret = -1;
88         int r = -1;
89
90         DBusConnection *conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
91         if (!conn) {
92                 _E("dbus_bus_get error");
93                 return -EBADMSG;
94         }
95
96         msg = dbus_message_new_method_call(TEP_BUS_NAME, TEP_OBJECT_PATH, TEP_INTERFACE_NAME, TEP_IS_MOUNTED_METHOD);
97         if(!msg) {
98                 _E("dbus_message_new_method_call(%s:%s-%s)", TEP_OBJECT_PATH, TEP_INTERFACE_NAME, TEP_IS_MOUNTED_METHOD);
99                 return ret;
100         }
101
102         if (!dbus_message_append_args(msg,
103                                         DBUS_TYPE_STRING, &tep_string,
104                                         DBUS_TYPE_INVALID)) {
105                 _E("Ran out of memory while constructing args\n");
106                 dbus_message_unref(msg);
107                 return ret;
108         }
109
110         dbus_error_init(&err);
111         reply = dbus_connection_send_with_reply_and_block(conn, msg, 500, &err);
112         if (!reply) {
113                 _E("dbus_connection_send error(%s:%s)", err.name, err.message);
114                 goto func_out;
115         }
116
117         r = dbus_message_get_args(reply, &err, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
118         if (!r) {
119                 _E("no message : [%s:%s]", err.name, err.message);
120                 goto func_out;
121         }
122
123 func_out :
124         dbus_message_unref(msg);
125         dbus_error_free(&err);
126         return ret;
127 }
128
129 SLPAPI int aul_check_tep_mount(const char *tep_path)
130 {
131         if(tep_path) {
132                 int rv = -1;
133                 int cnt = 0;
134                 while(cnt < TEP_ISMOUNT_MAX_RETRY_CNT) {
135                         rv = aul_is_tep_mount_dbus_done(tep_path);
136                         if(rv == 1)
137                                 break;
138                         usleep(50 * 1000);
139                         cnt++;
140                 }
141                 /* incase after trying 1 sec, not getting mounted then quit */
142                 if( rv != 1) {
143                         _E("Not able to mount within 1 sec");
144                         return -1;
145                 }
146         }
147         return 0;
148 }
149 #endif
150
151 int aul_is_initialized()
152 {
153         return aul_initialized;
154 }
155
156 int __call_aul_handler(aul_type type, bundle *kb)
157 {
158         if (_aul_handler)
159                 _aul_handler(type, kb, _aul_data);
160         return 0;
161 }
162
163 int app_start(bundle *kb)
164 {
165         const char *str = NULL;
166
167         _app_start_res_prepare(kb);
168         __call_aul_handler(AUL_START, kb);
169
170 #ifdef _APPFW_FEATURE_DATA_CONTROL
171         // Handle the DataControl callback
172         str = bundle_get_val(kb, AUL_K_DATA_CONTROL_TYPE);
173         if (str != NULL && strcmp(str, "CORE") == 0)
174         {
175                 if (__dc_handler != NULL)
176                 {
177                         __dc_handler(kb, 0, NULL); // bundle, request_id, data
178                 }
179         }
180 #endif
181         return 0;
182 }
183
184 static int app_resume()
185 {
186         __call_aul_handler(AUL_RESUME, NULL);
187         return 0;
188 }
189
190 static int app_terminate()
191 {
192         __call_aul_handler(AUL_TERMINATE, NULL);
193         return 0;
194 }
195
196 static int bgapp_terminate()
197 {
198         __call_aul_handler(AUL_TERMINATE_BGAPP, NULL);
199         return 0;
200 }
201
202 static int app_pause()
203 {
204         __call_aul_handler(AUL_PAUSE, NULL);
205         return 0;
206 }
207
208 static int app_prepare_to_suspend()
209 {
210         _D("[__SUSPEND__]");
211         __call_aul_handler(AUL_SUSPEND, NULL);
212         return 0;
213 }
214
215 static int app_prepare_to_wake()
216 {
217         _D("[__WAKE__]");
218         __call_aul_handler(AUL_WAKE, NULL);
219         return 0;
220 }
221
222 /**
223  * @brief       encode kb and send it to 'pid'
224  * @param[in]   pid             receiver's pid
225  * @param[in]   cmd             message's status (APP_START | APP_RESULT)
226  * @param[in]   kb              data
227  */
228 SLPAPI int app_send_cmd(int pid, int cmd, bundle *kb)
229 {
230         int datalen;
231         bundle_raw *kb_data = NULL;
232         int res = AUL_R_OK;
233
234         res = bundle_encode(kb, &kb_data, &datalen);
235         if (res != BUNDLE_ERROR_NONE) {
236                 return AUL_R_EINVAL;
237         }
238         if ((res = __app_send_raw(pid, cmd, kb_data, datalen)) < 0) {
239                 switch (res) {
240                 case -EINVAL:
241                         res = AUL_R_EINVAL;
242                         break;
243                 case -ECOMM:
244                         res = AUL_R_ECOMM;
245                         break;
246                 case -EAGAIN:
247                         res = AUL_R_ETIMEOUT;
248                         break;
249                 case -ELOCALLAUNCH_ID:
250                         res = AUL_R_LOCAL;
251                         break;
252                 case -EILLEGALACCESS:
253                         res = AUL_R_EILLACC;
254                         break;
255                 case -ETERMINATING:
256                         res = AUL_R_ETERMINATING;
257                         break;
258                 case -ENOLAUNCHPAD:
259                         res = AUL_R_ENOLAUNCHPAD;
260                         break;
261 #ifdef _APPFW_FEATURE_APP_CONTROL_LITE
262                 case -EUGLOCAL_LAUNCH:
263                         res = AUL_R_UG_LOCAL;
264                         break;
265 #endif
266                 case -EREJECTED:
267                         res = AUL_R_EREJECTED;
268                         break;
269                 case -ENOAPP:
270                         res = AUL_R_ENOAPP;
271                         break;
272                 default:
273                         res = AUL_R_ERROR;
274                 }
275         }
276         free(kb_data);
277
278         return res;
279 }
280
281 SLPAPI int app_send_cmd_with_noreply(int pid, int cmd, bundle *kb)
282 {
283         int datalen;
284         bundle_raw *kb_data = NULL;
285         int res = AUL_R_OK;
286
287         res = bundle_encode(kb, &kb_data, &datalen);
288         if (res != BUNDLE_ERROR_NONE) {
289                 return AUL_R_EINVAL;
290         }
291         if ((res = __app_send_raw_with_noreply(pid, cmd, kb_data, datalen)) < 0) {
292                 switch (res) {
293                 case -EINVAL:
294                         res = AUL_R_EINVAL;
295                         break;
296                 case -ECOMM:
297                         res = AUL_R_ECOMM;
298                         break;
299                 case -EAGAIN:
300                         res = AUL_R_ETIMEOUT;
301                         break;
302                 case -ELOCALLAUNCH_ID:
303                         res = AUL_R_LOCAL;
304                         break;
305                 case -EILLEGALACCESS:
306                         res = AUL_R_EILLACC;
307                         break;
308                 default:
309                         res = AUL_R_ERROR;
310                 }
311         }
312         free(kb_data);
313
314         return res;
315 }
316
317 static void __clear_internal_key(bundle *kb)
318 {
319         bundle_del(kb, AUL_K_CALLER_PID);
320         bundle_del(kb, AUL_K_PKG_NAME);
321         bundle_del(kb, AUL_K_WAIT_RESULT);
322         bundle_del(kb, AUL_K_SEND_RESULT);
323         bundle_del(kb, AUL_K_ARGV0);
324 }
325
326 static inline void __set_stime(bundle *kb)
327 {
328         struct timeval tv;
329         char tmp[MAX_LOCAL_BUFSZ];
330
331         gettimeofday(&tv, NULL);
332         snprintf(tmp, MAX_LOCAL_BUFSZ, "%ld/%ld", tv.tv_sec, tv.tv_usec);
333         bundle_add(kb, AUL_K_STARTTIME, tmp);
334 }
335
336 static int __app_start_internal(gpointer data)
337 {
338         bundle *kb;
339
340         kb = (bundle *) data;
341         app_start(kb);
342         bundle_free(kb);
343
344         return 0;
345 }
346
347 static int __app_launch_local(bundle *b)
348 {
349         if (!aul_is_initialized())
350                 return AUL_R_ENOINIT;
351
352         if (b == NULL) {
353                 _E("bundle for APP_START is NULL");
354         }
355         if (g_idle_add(__app_start_internal, b) > 0)
356                 return AUL_R_OK;
357         else
358                 return AUL_R_ERROR;
359 }
360
361 static int __app_resume_local()
362 {
363         if (!aul_is_initialized())
364                 return AUL_R_ENOINIT;
365
366         app_resume();
367
368         return 0;
369 }
370
371 static int __app_pause_local()
372 {
373         if (!aul_is_initialized())
374                 return AUL_R_ENOINIT;
375
376         app_pause();
377
378         return 0;
379 }
380
381 /**
382  * @brief       start caller with kb
383  * @return      callee's pid
384  */
385 int app_request_to_launchpad(int cmd, const char *pkgname, bundle *kb)
386 {
387         int must_free = 0;
388         int ret = 0;
389
390 #ifdef _APPFW_FEATURE_APP_CONTROL_LITE
391         char oldZone[64] = { 0, };
392         pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
393 #endif
394
395         traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "AUL:REQ_TO_PAD");
396         SECURE_LOGD("launch request : %s", pkgname);
397         if (kb == NULL) {
398                 kb = bundle_create();
399                 if (kb == NULL)
400                         return AUL_R_ERROR;
401                 must_free = 1;
402         } else {
403                 __clear_internal_key(kb);
404         }
405
406         ret = bundle_add(kb, AUL_K_PKG_NAME, pkgname);
407         if (ret != BUNDLE_ERROR_NONE) {
408                 if (must_free)
409                         bundle_free(kb);
410                 return AUL_R_ERROR;
411         }
412         __set_stime(kb);
413
414         switch (cmd) {
415         case APP_START_ASYNC:
416         case APP_PAUSE:
417         case APP_PAUSE_BY_PID:
418                 ret = app_send_cmd_with_noreply(AUL_UTIL_PID, cmd, kb);
419                 break;
420         default:
421                 ret = app_send_cmd(AUL_UTIL_PID, cmd, kb);
422                 break;
423         }
424
425         _D("launch request result : %d", ret);
426         if (ret == AUL_R_LOCAL
427 #ifdef _APPFW_FEATURE_APP_CONTROL_LITE
428                 || ret == AUL_R_UG_LOCAL
429 #endif
430                 ) {
431                 _E("app_request_to_launchpad : Same Process Send Local");
432                 bundle *b = NULL;
433
434 #ifdef _APPFW_FEATURE_APP_CONTROL_LITE
435                 if(ret == AUL_R_UG_LOCAL) {
436                         pkgmgrinfo_appinfo_h handle;
437                         char *exec = NULL;
438
439                         pkgmgrinfo_appinfo_get_appinfo(pkgname, &handle);
440                         pkgmgrinfo_appinfo_get_exec(handle, &exec);
441
442                         bundle_add(kb, "__AUL_UG_EXEC__", exec);
443
444                         pkgmgrinfo_appinfo_destroy_appinfo(handle);
445                 }
446 #endif
447
448                 switch (cmd) {
449                         case APP_START:
450                         case APP_START_RES:
451 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
452                         case APP_START_MULTI_INSTANCE:
453 #endif
454                                 b = bundle_dup(kb);
455                                 ret = __app_launch_local(b);
456                                 break;
457                         case APP_OPEN:
458                         case APP_RESUME:
459                         case APP_RESUME_BY_PID:
460                                 ret = __app_resume_local();
461                                 break;
462                         case APP_PAUSE:
463                         case APP_PAUSE_BY_PID:
464                                 ret = __app_pause_local();
465                                 break;
466                         default:
467                                 _E("no support packet");
468                 }
469
470         }
471
472         /* cleanup */
473         if (must_free)
474                 bundle_free(kb);
475
476 #ifdef _APPFW_FEATURE_APP_CONTROL_LITE
477         pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
478 #endif
479
480         traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
481
482         return ret;
483 }
484
485 static int __send_result_to_launchpad(int fd, int res)
486 {
487         if (send(fd, &res, sizeof(int), MSG_NOSIGNAL) < 0) {
488                 if (errno == EPIPE) {
489                         _E("send failed due to EPIPE.\n");
490                         close(fd);
491                         return -1;
492                 }
493                 _E("send fail to client");
494         }
495         close(fd);
496         return 0;
497 }
498
499 /**
500  * @brief       caller & callee's sock handler
501  */
502 int aul_sock_handler(int fd)
503 {
504         app_pkt_t *pkt;
505         bundle *kbundle;
506         int clifd;
507         struct ucred cr;
508
509         const char *str = NULL;
510         int pid;
511         int ret;
512
513         if ((pkt = __app_recv_raw(fd, &clifd, &cr)) == NULL) {
514                 _E("recv error");
515                 return -1;
516         }
517
518         if (pkt->cmd != APP_RESULT && pkt->cmd != APP_CANCEL && pkt->cmd != APP_SUSPEND && pkt->cmd != APP_WAKE
519                 &&cr.uid != 0 && cr.uid != SYSTEM_UID) {
520                 _E("security error");
521                 __send_result_to_launchpad(clifd, -1);
522                 free(pkt);
523                 return -1;
524         }
525
526         if (pkt->cmd != APP_RESULT && pkt->cmd != APP_CANCEL && pkt->cmd != APP_KEY_EVENT && pkt->cmd != APP_TERM_BY_PID_ASYNC
527                 && pkt->cmd != APP_SUSPEND && pkt->cmd != APP_WAKE ) {
528                 ret = __send_result_to_launchpad(clifd, 0);
529                 if (ret < 0) {
530                         free(pkt);
531                         return -1;
532                 }
533         } else {
534                 close(clifd);
535         }
536
537         switch (pkt->cmd) {
538         case APP_START: /* run in callee */
539         case APP_START_RES:
540         case APP_START_ASYNC:
541 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
542         case APP_START_MULTI_INSTANCE:
543 #endif
544                 kbundle = bundle_decode(pkt->data, pkt->len);
545                 if (kbundle == NULL)
546                         goto err;
547                 app_start(kbundle);
548                 bundle_free(kbundle);
549                 break;
550
551         case APP_OPEN:  /* run in callee */
552         case APP_RESUME:
553         case APP_RESUME_BY_PID:
554                 app_resume();
555                 break;
556
557         case APP_SUSPEND:
558                 app_prepare_to_suspend();
559                 break;
560         case APP_WAKE:
561                 app_prepare_to_wake();
562                 break;
563         case APP_TERM_BY_PID:   /* run in callee */
564         case APP_TERM_BY_PID_ASYNC:
565                 app_terminate();
566                 break;
567
568         case APP_TERM_BGAPP_BY_PID:
569                 bgapp_terminate();
570                 break;
571
572         case APP_TERM_REQ_BY_PID:       /* run in callee */
573                 app_subapp_terminate_request();
574                 break;
575
576         case APP_RESULT:        /* run in caller */
577         case APP_CANCEL:
578                 kbundle = bundle_decode(pkt->data, pkt->len);
579                 if (kbundle == NULL)
580                         goto err;
581
582                 str = bundle_get_val(kbundle, AUL_K_CALLEE_PID);
583                 if(str) {
584                         pid = atoi(str);
585                         app_result(pkt->cmd, kbundle, pid);
586                 }
587                 bundle_free(kbundle);
588                 break;
589
590         case APP_KEY_EVENT:     /* run in caller */
591                 kbundle = bundle_decode(pkt->data, pkt->len);
592                 if (kbundle == NULL)
593                         goto err;
594                 app_key_event(kbundle);
595                 bundle_free(kbundle);
596                 break;
597
598         case APP_PAUSE_BY_PID:
599                 app_pause();
600                 break;
601
602         default:
603                 _E("no support packet");
604         }
605
606         free(pkt);
607         return 0;
608
609 err:
610         free(pkt);
611         return -1;
612 }
613
614 int aul_make_bundle_from_argv(int argc, char **argv, bundle **kb)
615 {
616         int ac = 1;
617
618         char *buf = NULL;
619
620         *kb = bundle_create();
621         if (*kb == NULL)
622                 return AUL_R_ERROR;
623
624         if (argv == NULL)
625                 return AUL_R_OK;
626
627         if ((argv != NULL) && (argv[0] != NULL)) {
628                 buf = strdup(argv[0]);
629                 if (NULL == buf) {
630                         _E("Malloc failed");
631                         return AUL_R_ERROR;
632                 }
633
634                 bundle_add(*kb, AUL_K_ARGV0, buf);
635         }
636         if (buf) {              /*Prevent FIX: ID 38717 */
637                 free(buf);
638                 buf = NULL;
639         }
640
641         while (ac < argc) {
642                 if (ac + 1 == argc) {
643                         if (bundle_add(*kb, argv[ac], "") < 0) {
644                                 _E("bundle add error pos - %d", ac);
645                                 return AUL_R_ECANCELED;
646                         }
647                 } else {
648                         if (bundle_add(*kb, argv[ac], argv[ac + 1]) < 0) {
649                                 _E("bundle add error pos - %d", ac);
650                                 return AUL_R_ECANCELED;
651                         }
652                 }
653                 ac = ac + 2;
654         }
655
656         return AUL_R_OK;
657 }
658
659 int aul_register_init_callback(
660         int (*aul_handler) (aul_type type, bundle *, void *), void *data)
661 {
662         /* Save start handler function in static var */
663         _aul_handler = aul_handler;
664         _aul_data = data;
665         return 0;
666 }
667
668 int aul_initialize()
669 {
670         if (aul_initialized) {
671                 _E("aul already initialized");
672                 return AUL_R_ECANCELED;
673         }
674         aul_fd = __create_server_sock(getpid() + _pid_offset);
675         if (aul_fd < 0) {
676                 _E("aul_init create sock failed");
677                 return AUL_R_ECOMM;
678         }
679         aul_initialized = 1;
680
681         return aul_fd;
682 }
683
684 SLPAPI void aul_finalize()
685 {
686
687         aul_launch_fini();
688
689         if (aul_initialized) {
690                 close(aul_fd);
691                 aul_initialized = 0;
692         }
693
694         return;
695 }
696
697
698 SLPAPI int aul_launch_app(const char *appid, bundle *kb)
699 {
700         if (appid == NULL)
701                 return AUL_R_EINVAL;
702
703         return app_request_to_launchpad(APP_START, appid, kb);
704 }
705
706 SLPAPI int aul_launch_app_async(const char *appid, bundle *kb)
707 {
708         if (appid == NULL)
709                 return AUL_R_EINVAL;
710
711         return app_request_to_launchpad(APP_START_ASYNC, appid, kb);
712 }
713
714 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
715 SLPAPI int aul_launch_app_for_multi_instance(const char *appid, bundle *kb)
716 {
717         if (appid == NULL)
718                 return AUL_R_EINVAL;
719
720         return app_request_to_launchpad(APP_START_MULTI_INSTANCE, appid, kb);
721 }
722 #endif
723
724 SLPAPI int aul_open_app(const char *appid)
725 {
726         if (appid == NULL)
727                 return AUL_R_EINVAL;
728
729         return app_request_to_launchpad(APP_OPEN, appid, NULL);
730 }
731
732 SLPAPI int aul_resume_app(const char *appid)
733 {
734         if (appid == NULL)
735                 return AUL_R_EINVAL;
736
737         return app_request_to_launchpad(APP_RESUME, appid, NULL);
738 }
739
740 SLPAPI int aul_resume_pid(int pid)
741 {
742         char pkgname[MAX_PID_STR_BUFSZ];
743         int ret;
744
745         if (pid <= 0)
746                 return AUL_R_EINVAL;
747
748         snprintf(pkgname, MAX_PID_STR_BUFSZ, "%d", pid);
749         ret = app_request_to_launchpad(APP_RESUME_BY_PID, pkgname, NULL);
750         return ret;
751 }
752
753 SLPAPI int aul_terminate_pid(int pid)
754 {
755         char pkgname[MAX_PID_STR_BUFSZ];
756         int ret;
757
758         if (pid <= 0)
759                 return AUL_R_EINVAL;
760
761         snprintf(pkgname, MAX_PID_STR_BUFSZ, "%d", pid);
762         ret = app_request_to_launchpad(APP_TERM_BY_PID, pkgname, NULL);
763         return ret;
764 }
765
766 SLPAPI int aul_terminate_bgapp_pid(int pid)
767 {
768         char pkgname[MAX_PID_STR_BUFSZ];
769         int ret;
770
771         if (pid <= 0)
772                 return AUL_R_EINVAL;
773
774         snprintf(pkgname, MAX_PID_STR_BUFSZ, "%d", pid);
775         ret = app_request_to_launchpad(APP_TERM_BGAPP_BY_PID, pkgname, NULL);
776         return ret;
777 }
778
779 SLPAPI int aul_terminate_pid_without_restart(int pid)
780 {
781         char pkgname[MAX_PID_STR_BUFSZ];
782         int ret;
783
784         if (pid <= 0)
785                 return AUL_R_EINVAL;
786
787         snprintf(pkgname, MAX_PID_STR_BUFSZ, "%d", pid);
788         ret = app_request_to_launchpad(APP_TERM_BY_PID_WITHOUT_RESTART, pkgname, NULL);
789         return ret;
790 }
791
792 SLPAPI int aul_terminate_pid_async(int pid)
793 {
794         char pkgname[MAX_PID_STR_BUFSZ];
795         int ret;
796
797         if (pid <= 0)
798                 return AUL_R_EINVAL;
799
800         snprintf(pkgname, MAX_PID_STR_BUFSZ, "%d", pid);
801         ret = app_request_to_launchpad(APP_TERM_BY_PID_ASYNC, pkgname, NULL);
802         return ret;
803 }
804
805 SLPAPI int aul_kill_pid(int pid)
806 {
807         char pkgname[MAX_PID_STR_BUFSZ];
808         int ret;
809
810         if (pid <= 0)
811                 return AUL_R_EINVAL;
812
813         snprintf(pkgname, MAX_PID_STR_BUFSZ, "%d", pid);
814         ret = app_request_to_launchpad(APP_KILL_BY_PID, pkgname, NULL);
815         return ret;
816 }
817
818 #ifdef _APPFW_FEATURE_PROCESS_POOL
819 SLPAPI void aul_set_preinit_window(void *evas_object)
820 {
821         __window_object = evas_object;
822 }
823
824 SLPAPI void* aul_get_preinit_window(const char *win_name)
825 {
826         return __window_object;
827 }
828
829 SLPAPI void aul_set_preinit_background(void *evas_object)
830 {
831         __bg_object = evas_object;
832 }
833
834 SLPAPI void* aul_get_preinit_background(void)
835 {
836         return __bg_object;
837 }
838
839 SLPAPI void aul_set_preinit_conformant(void *evas_object)
840 {
841         __conformant_object = evas_object;
842 }
843
844 SLPAPI void* aul_get_preinit_conformant(void)
845 {
846         return __conformant_object;
847 }
848 #endif
849
850 #ifdef _APPFW_FEATURE_DATA_CONTROL
851 SLPAPI int aul_set_data_control_provider_cb(data_control_provider_handler_fn handler)
852 {
853         __dc_handler = handler;
854         return 0;
855 }
856
857 SLPAPI int aul_unset_data_control_provider_cb(void)
858 {
859         __dc_handler = NULL;
860         return 0;
861 }
862 #endif
863
864 SLPAPI int aul_pause_app(const char *appid)
865 {
866         int ret;
867
868         if (appid == NULL)
869                 return AUL_R_EINVAL;
870
871         ret = app_request_to_launchpad(APP_PAUSE, appid, NULL);
872         return ret;
873 }
874
875 SLPAPI int aul_pause_pid(int pid)
876 {
877         char app_pid[MAX_PID_STR_BUFSZ];
878         int ret;
879
880         if (pid <= 0)
881                 return AUL_R_EINVAL;
882
883         snprintf(app_pid, MAX_PID_STR_BUFSZ, "%d", pid);
884         ret = app_request_to_launchpad(APP_PAUSE_BY_PID, app_pid, NULL);
885         return ret;
886 }
887
888 /* vi: set ts=8 sts=8 sw=8: */