4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
28 #include <sys/types.h>
31 #include <libsoup/soup.h>
38 #include <iniparser.h>
39 #include <pkgmgr-info.h>
40 #include <tzplatform_config.h>
43 #include "appsvc_db.h"
50 #define SLPAPI __attribute__ ((visibility("default")))
54 /* callback handling */
55 typedef struct _appsvc_cb_info_t{
56 appsvc_res_fn cb_func;
61 typedef struct _appsvc_resolve_info_t{
75 }appsvc_resolve_info_t;
77 extern int aul_launch_app_with_result(const char *pkgname, bundle *kb,
78 void (*cbfunc) (bundle *, int, void *),
81 static appsvc_cb_info_t *__create_rescb(int request_code, appsvc_res_fn cbfunc,
83 static void __remove_rescb(appsvc_cb_info_t *info);
84 static int __set_bundle(bundle *b, const char *key, const char *value);
85 static void __aul_cb(bundle *b, int is_cancel, void *data);
86 static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
87 appsvc_res_fn cbfunc, void *data);
88 static int __get_resolve_info(bundle *b, appsvc_resolve_info_t *info);
89 static int __free_resolve_info_data(appsvc_resolve_info_t *info);
90 static int __get_list_with_condition(char *op, char *uri,
91 char *mime, GSList **pkg_list, uid_t uid);
94 static appsvc_cb_info_t *__create_rescb(int request_code, appsvc_res_fn cbfunc, void *data)
96 appsvc_cb_info_t* info;
98 info = (appsvc_cb_info_t*)calloc(1, sizeof(appsvc_cb_info_t));
102 info->request_code = request_code;
103 info->cb_func = cbfunc;
109 static void __remove_rescb(appsvc_cb_info_t *info)
114 static int __set_bundle(bundle *b, const char *key, const char *value)
116 const char *val = NULL;
118 val = bundle_get_val(b, key);
120 if( bundle_del(b, key) != 0 ){
121 return APPSVC_RET_ERROR;
126 return APPSVC_RET_EINVAL;
128 if( bundle_add(b, key, value) != 0 ){
129 return APPSVC_RET_ERROR;
133 // bundle_iterate(b, __bundle_iterate, NULL);
135 return APPSVC_RET_OK;
138 static int __set_bundle_array(bundle *b, const char *key, const char **value, int len)
142 type = appsvc_data_is_array(b, key);
145 if( bundle_del(b, key) != 0 ){
146 return APPSVC_RET_ERROR;
151 return APPSVC_RET_EINVAL;
153 if( bundle_add_str_array(b, key, value, len) != 0 ){
154 return APPSVC_RET_ERROR;
157 _D("__set_bundle_array");
158 // bundle_iterate(b, __bundle_iterate, NULL);
160 return APPSVC_RET_OK;
164 static void __aul_cb(bundle *b, int is_cancel, void *data)
166 const char *val = NULL;
167 appsvc_cb_info_t* cb_info;
171 res = APPSVC_RES_CANCEL;
173 /* get result_code from bundle */
174 val = bundle_get_val(b, APP_SVC_K_RES_VAL);
175 res = (val==NULL)? APPSVC_RES_NOT_OK : atoi(val);
178 /* remove result_code from bundle */
179 bundle_del(b, APP_SVC_K_RES_VAL);
181 /* find corresponding callback */
182 cb_info = (appsvc_cb_info_t*)data;
184 cb_info->cb_func(b, cb_info->request_code, (appsvc_result_val)res, cb_info->data);
185 __remove_rescb(cb_info);
191 static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code, appsvc_res_fn cbfunc, void *data)
193 appsvc_cb_info_t *cb_info = NULL;
197 _D("pkg_name : %s - with result", pkgname);
199 cb_info = __create_rescb(request_code, cbfunc, data);
200 ret = aul_launch_app_with_result(pkgname, b, __aul_cb, cb_info);
202 _D("pkg_name : %s - no result", pkgname);
203 ret = aul_launch_app(pkgname, b);
209 ret = APPSVC_RET_EILLACC;
212 ret = APPSVC_RET_EINVAL;
215 ret = APPSVC_RET_ENOMATCH;
218 ret = APPSVC_RET_ELAUNCH;
225 static int __get_resolve_info(bundle *b, appsvc_resolve_info_t *info)
228 char *strtok_buf = NULL;
231 info->op = (char *)appsvc_get_operation(b);
232 info->uri = (char *)appsvc_get_uri(b);
233 info->origin_mime = info->mime = (char *)appsvc_get_mime(b);
234 info->pkgname = (char *)appsvc_get_pkgname(b);
235 info->category = (char *)appsvc_get_category(b);
236 info->win_id = (char *)bundle_get_val(b, APP_SVC_K_WIN_ID);
239 if(strncmp(info->uri,"/",1) == 0){
241 info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
242 aul_get_mime_from_file(info->uri, info->mime, MAX_MIME_STR_SIZE);
246 } else if(strncmp(info->uri,"file:/",6)==0){
248 info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
249 aul_get_mime_from_file(&info->uri[5], info->mime, MAX_MIME_STR_SIZE);
253 } else if(strncmp(info->uri,"file:///",8) == 0){
255 info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
256 aul_get_mime_from_file(&info->uri[7], info->mime, MAX_MIME_STR_SIZE);
264 s_uri = soup_uri_new(info->uri);
267 return APPSVC_RET_EINVAL;
270 info->scheme = malloc(MAX_SCHEME_STR_SIZE);
271 strncpy(info->scheme, s_uri->scheme, MAX_SCHEME_STR_SIZE-1);
274 info->host = malloc(MAX_HOST_STR_SIZE);
275 strncpy(info->host, s_uri->host, MAX_HOST_STR_SIZE-1);
277 if(info->scheme && info->host) {
278 info->uri_r_info = malloc(MAX_SCHEME_STR_SIZE+MAX_HOST_STR_SIZE+2);
279 snprintf(info->uri_r_info, MAX_SCHEME_STR_SIZE+MAX_HOST_STR_SIZE+1,
280 "%s://%s", info->scheme, info->host);
283 soup_uri_free(s_uri);
285 info->scheme = strdup("NULL");
289 info->mime = strdup("NULL");
291 info->m_type = malloc(MAX_LOCAL_BUFSZ);
292 info->s_type = malloc(MAX_LOCAL_BUFSZ);
293 tmp = strdup(info->mime);
294 strtok_buf = strtok(tmp,"/");
296 strncpy(info->m_type, strtok_buf, MAX_LOCAL_BUFSZ-1);
297 strtok_buf = strtok(NULL,"/");
299 strncpy(info->s_type, strtok_buf, MAX_LOCAL_BUFSZ-1);
302 if(strncmp(info->m_type, "*", 1) == 0) {
303 strncpy(info->m_type, "%", MAX_LOCAL_BUFSZ-1);
305 if(strncmp(info->s_type, "*", 1) == 0) {
306 strncpy(info->s_type, "%", MAX_LOCAL_BUFSZ-1);
309 info->mime = malloc(MAX_MIME_STR_SIZE);
310 snprintf(info->mime, MAX_MIME_STR_SIZE-1, "%s/%s", info->m_type, info->s_type);
316 static int __free_resolve_info_data(appsvc_resolve_info_t *info)
328 if (info->uri_r_info)
329 free(info->uri_r_info);
331 free(info->origin_mime);
336 SLPAPI int appsvc_set_operation(bundle *b, const char *operation)
339 _E("bundle for appsvc_set_operation is NULL");
340 return APPSVC_RET_EINVAL;
343 return __set_bundle(b, APP_SVC_K_OPERATION, operation);
346 SLPAPI int appsvc_set_uri(bundle *b, const char *uri)
349 _E("bundle for appsvc_set_uri is NULL");
350 return APPSVC_RET_EINVAL;
353 return __set_bundle(b, APP_SVC_K_URI, uri);
356 SLPAPI int appsvc_set_mime(bundle *b, const char *mime)
359 _E("bundle for appsvc_set_mime is NULL");
360 return APPSVC_RET_EINVAL;
363 return __set_bundle(b, APP_SVC_K_MIME, mime);
366 SLPAPI int appsvc_add_data(bundle *b, const char *key, const char *val)
368 if(b == NULL || key == NULL) {
369 return APPSVC_RET_EINVAL;
372 /* check key for data */
375 return __set_bundle(b, key, val);
378 SLPAPI int appsvc_add_data_array(bundle *b, const char *key, const char **val_array, int len)
380 if(b == NULL || key == NULL) {
381 return APPSVC_RET_EINVAL;
384 /* check key for data */
387 return __set_bundle_array(b, key, val_array, len);
391 SLPAPI int appsvc_set_pkgname(bundle *b, const char *pkg_name)
394 _E("bundle for appsvc_set_pkgname is NULL");
395 return APPSVC_RET_EINVAL;
398 return __set_bundle(b, APP_SVC_K_PKG_NAME, pkg_name);
401 static char* __get_alias_appid(char *appid)
403 char *alias_id = NULL;
405 char key_string[MAX_PACKAGE_STR_SIZE+5];
408 dic = iniparser_load("/usr/share/appsvc/alias.ini");
413 sprintf(key_string, "Alias:%s", appid);
414 val = iniparser_getstring(dic, key_string, NULL);
416 _D("alias_id : %s", val);
419 alias_id = malloc(MAX_PACKAGE_STR_SIZE);
420 strncpy(alias_id, val, MAX_PACKAGE_STR_SIZE-1);
423 iniparser_freedict(dic);
428 SLPAPI int appsvc_set_appid(bundle *b, const char *appid)
430 char *alias_id = NULL;
433 if(b == NULL || appid == NULL){
434 _E("bundle for appsvc_set_appid is NULL");
435 return APPSVC_RET_EINVAL;
438 alias_id = __get_alias_appid(appid);
439 if(alias_id == NULL) {
440 ret = __set_bundle(b, APP_SVC_K_PKG_NAME, appid);
442 ret = __set_bundle(b, APP_SVC_K_PKG_NAME, alias_id);
449 SLPAPI int appsvc_set_category(bundle *b, const char *category)
452 _E("bundle for appsvc_set_category is NULL");
453 return APPSVC_RET_EINVAL;
456 return __set_bundle(b, APP_SVC_K_CATEGORY, category);
459 SLPAPI int appsvc_set_launch_mode(bundle *b, const char *mode)
462 _E("bundle for appsvc_set_launch_mode is NULL");
463 return APPSVC_RET_EINVAL;
466 return __set_bundle(b, APP_SVC_K_LAUNCH_MODE, mode);
468 static int __get_list_with_condition_mime_extened(char *op, char *uri, char *mime,
469 char *m_type, char *s_type, GSList **pkg_list, uid_t uid)
473 tmp = malloc(MAX_MIME_STR_SIZE);
475 _svc_db_get_list_with_condition(op, uri, mime, pkg_list, uid);
476 if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(s_type, "%", 1) != 0)) {
477 snprintf(tmp, MAX_MIME_STR_SIZE-1, "%s/*", m_type);
478 _svc_db_get_list_with_condition(op, uri, tmp, pkg_list, uid);
480 if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(m_type, "%", 1) != 0)) {
481 snprintf(tmp, MAX_MIME_STR_SIZE-1, "*/*");
482 _svc_db_get_list_with_condition(op, uri, tmp, pkg_list, uid);
489 static int __get_list_with_condition_mime_extened_with_collation(char *op, char *uri, char *mime,
490 char *m_type, char *s_type, GSList **pkg_list, uid_t uid)
494 tmp = malloc(MAX_MIME_STR_SIZE);
496 _svc_db_get_list_with_collation(op, uri, mime, pkg_list, uid);
497 if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(s_type, "%", 1) != 0)) {
498 snprintf(tmp, MAX_MIME_STR_SIZE-1, "%s/*", m_type);
499 _svc_db_get_list_with_collation(op, uri, tmp, pkg_list, uid);
501 if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(m_type, "%", 1) != 0)) {
502 snprintf(tmp, MAX_MIME_STR_SIZE-1, "*/*");
503 _svc_db_get_list_with_collation(op, uri, tmp, pkg_list, uid);
511 static int __app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
514 GSList **app_list = (GSList **)user_data;
518 pkgmgrinfo_appinfo_get_appid(handle, &str);
519 _D("Matching application is %s",str);
521 for (iter = tmp_list; iter != NULL; iter = g_slist_next(iter)) {
522 if (strncmp(str, (char *)iter->data, MAX_PACKAGE_STR_SIZE-1) == 0) {
524 *app_list = g_slist_append(*app_list, (void *)appid);
525 _D("%s is added",appid);
532 static int __get_list_with_category(char *category, GSList **pkg_list, uid_t uid)
535 pkgmgrinfo_appinfo_filter_h handle;
536 GSList *app_list = NULL;
538 char *list_item = NULL;
540 ret = pkgmgrinfo_appinfo_filter_create(&handle);
541 ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_CATEGORY, category);
543 tmp_list = *pkg_list;
544 ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, __app_list_cb, &app_list, uid);
545 if (ret != PMINFO_R_OK) {
546 pkgmgrinfo_appinfo_filter_destroy(handle);
549 pkgmgrinfo_appinfo_filter_destroy(handle);
551 for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) {
552 list_item = (char *)iter->data;
555 g_slist_free(*pkg_list);
557 *pkg_list = app_list;
562 static int __appid_compare(gconstpointer data1, gconstpointer data2)
564 char *a = (char *)data1;
565 char *b = (char *)data2;
569 static int __get_list_with_submode(char *win_id, GSList **pkg_list, uid_t uid)
574 GSList *find_item = NULL;
575 char *find_appid = NULL;
576 pkgmgrinfo_appinfo_h handle = NULL;
577 char *submode_mainid = NULL;
580 for (iter = *pkg_list; iter != NULL; ) {
582 submode_mainid = NULL;
583 appid = (char *)iter->data;
584 ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &handle);
585 SECURE_LOGD("ret %d, %s, %x", ret, appid, handle);
586 ret = pkgmgrinfo_appinfo_get_submode_mainid(handle, &submode_mainid);
587 SECURE_LOGD("appid(%s) submode_mainid(%s) win_id(%s)", appid, submode_mainid, win_id);
590 find_item = g_slist_find_custom(*pkg_list, submode_mainid, __appid_compare);
592 find_appid = find_item->data;
593 if(find_item == g_slist_next(iter)) {
594 iter = g_slist_next(find_item);
595 *pkg_list = g_slist_remove(*pkg_list, find_appid);
598 iter = g_slist_next(iter);
599 *pkg_list = g_slist_remove(*pkg_list, find_appid);
604 find_item = g_slist_find_custom(*pkg_list, submode_mainid, __appid_compare);
606 iter = g_slist_next(iter);
607 *pkg_list = g_slist_remove(*pkg_list, appid);
612 pkgmgrinfo_appinfo_destroy_appinfo(handle);
614 iter = g_slist_next(iter);
619 for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) {
620 appid = (char *)iter->data;
621 SECURE_LOGD("appid(%s)", appid);
627 SLPAPI int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data)
629 //using default user to allow app-svc API usage for deamon.
630 //App-svc run service leads to app launch that could require a graphical session.
631 //Indeed bluetooth_agent uses this API and is launched as bluetooth user (that not regular user).
632 return appsvc_usr_run_service(b, request_code, cbfunc, data, tzplatform_getuid(TZ_SYS_DEFAULT_USER));
635 SLPAPI int appsvc_usr_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data, uid_t uid)
637 appsvc_resolve_info_t info;
642 GSList *pkg_list = NULL;
647 _E("bundle for appsvc_set_appid is NULL");
648 return APPSVC_RET_EINVAL;
651 pkgname = (char *)appsvc_get_pkgname(b);
655 if(appsvc_get_operation(b) == NULL)
656 appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);
657 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
661 memset(&info, 0, sizeof(appsvc_resolve_info_t));
662 ret = __get_resolve_info(b, &info);
666 _D("op - %s / mime - %s / scheme - %s\n", info.op, info.origin_mime, info.scheme);
669 pkgname = _svc_db_get_app(info.op, info.origin_mime, info.uri, uid);
671 __get_list_with_condition_mime_extened_with_collation(info.op, info.uri,
672 info.mime, info.m_type, info.s_type, &pkg_list, uid);
673 pkg_count = g_slist_length(pkg_list);
676 if(info.uri_r_info) {
677 __get_list_with_condition_mime_extened(info.op, info.uri_r_info,
678 info.mime, info.m_type, info.s_type, &pkg_list, uid);
681 __get_list_with_condition_mime_extened(info.op, info.scheme,
682 info.mime, info.m_type, info.s_type, &pkg_list, uid);
684 __get_list_with_condition_mime_extened(info.op, "*",
685 info.mime, info.m_type, info.s_type, &pkg_list, uid);
688 __get_list_with_category(info.category, &pkg_list, uid);
691 __get_list_with_submode(info.win_id, &pkg_list, uid);
693 pkg_count = g_slist_length(pkg_list);
694 _D("pkg_count : %d", pkg_count);
697 pkgname = (char *)pkg_list->data;
699 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
703 bundle_add(b, APP_SVC_K_URI_R_INFO, info.uri);
704 ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data);
707 for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
708 list_item = (char *)iter->data;
711 g_slist_free(pkg_list);
715 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
721 if(info.uri_r_info) {
722 pkgname = _svc_db_get_app(info.op, info.origin_mime, info.uri_r_info, uid);
725 __get_list_with_condition_mime_extened(info.op, info.uri_r_info,
726 info.mime, info.m_type, info.s_type, &pkg_list, uid);
727 pkg_count = g_slist_length(pkg_list);
729 __get_list_with_condition_mime_extened(info.op, info.scheme,
730 info.mime, info.m_type, info.s_type, &pkg_list, uid);
732 __get_list_with_condition_mime_extened(info.op, "*",
733 info.mime, info.m_type, info.s_type, &pkg_list, uid);
736 __get_list_with_category(info.category, &pkg_list, uid);
739 __get_list_with_submode(info.win_id, &pkg_list, uid);
741 pkg_count = g_slist_length(pkg_list);
742 _D("pkg_count : %d", pkg_count);
745 pkgname = (char *)pkg_list->data;
747 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
751 bundle_add(b, APP_SVC_K_URI_R_INFO, info.uri_r_info);
752 ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data);
756 for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
757 list_item = (char *)iter->data;
760 g_slist_free(pkg_list);
763 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
770 pkgname = _svc_db_get_app(info.op, info.origin_mime, info.scheme, uid);
773 __get_list_with_condition_mime_extened(info.op, info.scheme,
774 info.mime, info.m_type, info.s_type, &pkg_list, uid);
776 __get_list_with_condition_mime_extened(info.op, "*",
777 info.mime, info.m_type, info.s_type, &pkg_list, uid);
780 __get_list_with_category(info.category, &pkg_list, uid);
783 __get_list_with_submode(info.win_id, &pkg_list, uid);
785 pkg_count = g_slist_length(pkg_list);
786 _D("pkg_count : %d", pkg_count);
789 pkgname = (char *)pkg_list->data;
791 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
793 } else if(pkg_count < 1) {
794 __free_resolve_info_data(&info);
795 return APPSVC_RET_ENOMATCH;
797 bundle_add(b, APP_SVC_K_URI_R_INFO, info.scheme);
798 ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data);
801 for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
802 list_item = (char *)iter->data;
805 g_slist_free(pkg_list);
807 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
812 __free_resolve_info_data(&info);
818 SLPAPI int appsvc_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data)
820 //using default user to allow app-svc API usage for deamon.
821 //App-svc run get list leads to app launch that could require a graphical session.
822 return appsvc_usr_get_list(b, iter_fn, data, tzplatform_getuid(TZ_SYS_DEFAULT_USER));
825 SLPAPI int appsvc_usr_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data, uid_t uid)
827 appsvc_resolve_info_t info;
828 char *pkgname = NULL;
832 GSList *pkg_list = NULL;
836 _E("bundle for appsvc_run_service is NULL");
837 return APPSVC_RET_EINVAL;
840 if (iter_fn == NULL){
841 _E("iter_fn for appsvc_run_service is NULL");
842 return APPSVC_RET_EINVAL;
846 memset(&info, 0, sizeof(appsvc_resolve_info_t));
847 ret = __get_resolve_info(b,&info);
851 _D("operation - %s / scheme - %s / mime - %s\n", info.op, info.scheme, info.mime);
853 __get_list_with_condition_mime_extened_with_collation(info.op, info.uri,
854 info.mime, info.m_type, info.s_type, &pkg_list, uid);
856 if(info.uri_r_info) {
857 __get_list_with_condition_mime_extened(info.op, info.uri_r_info,
858 info.mime, info.m_type, info.s_type, &pkg_list, uid);
861 __get_list_with_condition_mime_extened(info.op, info.scheme,
862 info.mime, info.m_type, info.s_type, &pkg_list, uid);
865 __get_list_with_category(info.category, &pkg_list, uid);
868 __get_list_with_submode(info.win_id, &pkg_list, uid);
870 pkg_count = g_slist_length(pkg_list);
871 if (pkg_count == 0) {
872 _E("Cannot find associated application");
873 return APPSVC_RET_ENOMATCH;
876 for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
877 pkgname = iter->data;
878 _D("PKGNAME : %s\n", pkgname);
879 if( iter_fn(pkgname,data) != 0)
884 g_slist_free(pkg_list);
885 __free_resolve_info_data(&info);
887 return APPSVC_RET_OK;
890 SLPAPI const char *appsvc_get_operation(bundle *b)
892 return bundle_get_val(b, APP_SVC_K_OPERATION);
895 SLPAPI const char *appsvc_get_uri(bundle *b)
897 return bundle_get_val(b, APP_SVC_K_URI);
900 SLPAPI const char *appsvc_get_mime(bundle *b)
902 return bundle_get_val(b, APP_SVC_K_MIME);
905 SLPAPI const char *appsvc_get_data(bundle *b, const char *key)
907 return bundle_get_val(b, key);
910 SLPAPI const char **appsvc_get_data_array(bundle *b, const char *key, int *len)
912 return bundle_get_str_array(b, key, len);
915 SLPAPI const char *appsvc_get_pkgname(bundle *b)
917 return bundle_get_val(b, APP_SVC_K_PKG_NAME);
920 SLPAPI const char *appsvc_get_appid(bundle *b)
922 return bundle_get_val(b, APP_SVC_K_PKG_NAME);
925 SLPAPI const char *appsvc_get_category(bundle *b)
927 return bundle_get_val(b, APP_SVC_K_CATEGORY);
930 SLPAPI const char *appsvc_get_launch_mode(bundle *b)
932 return bundle_get_val(b, APP_SVC_K_LAUNCH_MODE);
935 SLPAPI int appsvc_create_result_bundle(bundle *inb, bundle **outb)
939 if(inb == NULL || outb == NULL) {
940 _E("bundle is NULL");
941 return APPSVC_RET_EINVAL;
944 ret = aul_create_result_bundle(inb, outb);
946 /* add additional bundle */
947 /* bundle_add(outb, " ", " "); */
951 else if(ret == AUL_R_EINVAL)
952 ret = APPSVC_RET_EINVAL;
954 ret = APPSVC_RET_ERROR;
959 SLPAPI int appsvc_send_result(bundle *b, appsvc_result_val result)
962 char tmp[MAX_LOCAL_BUFSZ];
965 _E("appsvc_send_result is NULL");
966 return APPSVC_RET_EINVAL;
969 if(result != APPSVC_RES_OK && result != APPSVC_RES_NOT_OK){
970 _E("invalid result %d", (int)result);
971 return APPSVC_RET_EINVAL;
974 /* add result_code to bundle */
975 snprintf(tmp,MAX_LOCAL_BUFSZ,"%d", (int)result);
976 ret = __set_bundle(b, APP_SVC_K_RES_VAL, tmp);
978 return APPSVC_RET_ERROR;
980 ret = aul_send_service_result(b);
982 /* remove result_code from bundle */
983 bundle_del(b, APP_SVC_K_RES_VAL);
988 SLPAPI int appsvc_set_defapp(const char *op, const char *mime_type, const char *uri,
989 const char *defapp, uid_t uid)
993 if(op == NULL || defapp == NULL)
994 return APPSVC_RET_EINVAL;
996 ret = _svc_db_add_app(op, mime_type, uri, defapp, uid);
999 return APPSVC_RET_ERROR;
1001 return APPSVC_RET_OK;
1004 SLPAPI int appsvc_unset_defapp(const char *defapp, uid_t uid)
1009 return APPSVC_RET_EINVAL;
1011 ret = _svc_db_delete_with_pkgname(defapp, uid);
1014 return APPSVC_RET_ERROR;
1016 return APPSVC_RET_OK;
1019 SLPAPI int appsvc_is_defapp(const char *pkg_name, uid_t uid)
1021 return _svc_db_is_defapp(pkg_name, uid);
1024 SLPAPI int appsvc_data_is_array(bundle *b, const char *key)
1027 type = bundle_get_type(b, key);
1032 if(type & BUNDLE_TYPE_ARRAY)
1037 typedef struct _appsvc_transient_cb_info_t{
1038 appsvc_host_res_fn cb_func;
1041 Ecore_X_Window win_id;
1045 }appsvc_transient_cb_info_t;
1047 static Eina_Bool __transient_cb(void *data, int type, void *event)
1050 Ecore_X_Event_Window_Hide *ev;
1051 appsvc_transient_cb_info_t* cb_info;
1054 cb_info = (appsvc_transient_cb_info_t*) data;
1056 if(ev->win == cb_info->win_id) {
1057 cb_info->cb_func(cb_info->data);
1058 ecore_main_loop_quit();
1061 return ECORE_CALLBACK_RENEW;
1064 int __aul_subapp_cb(void *data)
1066 appsvc_transient_cb_info_t* cb_info;
1068 cb_info = (appsvc_transient_cb_info_t*) data;
1070 cb_info->cb_func(cb_info->data);
1071 ecore_main_loop_quit();
1077 SLPAPI int appsvc_allow_transient_app(bundle *b, Ecore_X_Window id)
1079 char win_id[MAX_LOCAL_BUFSZ];
1081 snprintf(win_id, MAX_LOCAL_BUFSZ, "%d", id);
1084 _E("bundle for appsvc_allow_transient_app is NULL");
1085 return APPSVC_RET_EINVAL;
1088 return __set_bundle(b, APP_SVC_K_WIN_ID, win_id);
1091 SLPAPI int appsvc_allow_transient_app(bundle *b, unsigned int id)
1098 SLPAPI int appsvc_request_transient_app(bundle *b, Ecore_X_Window callee_id, appsvc_host_res_fn cbfunc, void *data)
1100 char *caller = NULL;
1101 Ecore_X_Window caller_id;
1103 caller = bundle_get_val(b, APP_SVC_K_WIN_ID);
1105 return APPSVC_RET_ERROR;
1107 caller_id = atoi(caller);
1109 ecore_x_icccm_transient_for_set(callee_id, caller_id);
1111 ecore_x_window_client_manage(caller_id);
1113 appsvc_transient_cb_info_t* info;
1115 info = (appsvc_transient_cb_info_t*)calloc(1, sizeof(appsvc_transient_cb_info_t));
1117 return APPSVC_RET_ERROR;
1119 info->win_id = caller_id;
1120 info->cb_func = cbfunc;
1123 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_DESTROY, __transient_cb, info);
1124 aul_set_subapp(__aul_subapp_cb, info);
1129 SLPAPI int appsvc_request_transient_app(bundle *b, unsigned int callee_id, appsvc_host_res_fn cbfunc, void *data)
1135 SLPAPI int appsvc_subapp_terminate_request_pid(int pid)
1137 int cpid = getpid();
1142 aul_app_group_get_leader_pids(&lcnt, &lpids);
1143 for (i = 0; i < lcnt; i++) {
1144 if (lpids[i] == cpid) {
1148 aul_app_group_get_group_pids(cpid, &cnt, &pids);
1152 return aul_subapp_terminate_request_pid(pid);
1164 return aul_app_group_clear_top();
1167 SLPAPI int aul_svc_subscribe_launch_result(bundle *b, const char *result)
1170 _E("bundle for aul_svc_subscribe_launch_result is NULL");
1171 return APPSVC_RET_EINVAL;
1174 return __set_bundle(b, result, "1");