2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <sys/types.h>
24 #include <bundle_internal.h>
31 #include <iniparser.h>
32 #include <pkgmgr-info.h>
33 #include <pkgmgrinfo_zone.h>
37 #include "aul_svc_db.h"
38 #include "simple_util.h"
39 #include "aul_svc_priv_key.h"
41 #include "delegator_client.h"
44 /* callback handling */
45 typedef struct _aul_svc_cb_info_t {
46 aul_svc_res_fn cb_func;
51 typedef struct _aul_svc_resolve_info_t {
65 } aul_svc_resolve_info_t;
67 typedef struct _aul_svc_transient_cb_info_t {
68 aul_svc_host_res_fn cb_func;
69 Ecore_X_Window win_id;
71 } aul_svc_transient_cb_info_t;
73 pthread_mutex_t iniparser_lock = PTHREAD_MUTEX_INITIALIZER;
76 static aul_svc_cb_info_t *__create_rescb(int request_code,
77 aul_svc_res_fn cbfunc,
79 static void __remove_rescb(aul_svc_cb_info_t *info);
80 static int __set_bundle(bundle *b, const char *key, const char *value);
81 static void __aul_cb(bundle *b, int is_cancel, void *data);
82 static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
83 aul_svc_res_fn cbfunc, void *data);
84 static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info);
85 static int __free_resolve_info_data(aul_svc_resolve_info_t *info);
87 static void __set_transient_for(Ecore_X_Window callee, Ecore_X_Window caller,
90 static char *white_list[] = {
96 static bool __is_special_app(const char *appid)
104 while ((id = white_list[i]) != NULL) {
105 if (strcmp(id, appid) == 0)
112 static Eina_Bool __transient_cb(void *data, int type, void *event)
114 Ecore_X_Event_Window_Hide *ev;
115 aul_svc_transient_cb_info_t* cb_info;
117 if ((!event) || (!data)) {
118 _E("input param of transient cb is null");
119 return ECORE_CALLBACK_CANCEL;
123 cb_info = (aul_svc_transient_cb_info_t*) data;
125 if (ev->win == cb_info->win_id) {
126 if (cb_info->cb_func)
127 cb_info->cb_func(cb_info->data);
128 ecore_main_loop_quit();
131 return ECORE_CALLBACK_RENEW;
134 static int __aul_subapp_cb(void *data)
136 aul_svc_transient_cb_info_t* cb_info;
138 cb_info = (aul_svc_transient_cb_info_t*) data;
140 cb_info->cb_func(cb_info->data);
141 ecore_main_loop_quit();
146 static aul_svc_cb_info_t *__create_rescb(int request_code,
147 aul_svc_res_fn cbfunc,
150 aul_svc_cb_info_t* info;
152 info = (aul_svc_cb_info_t*)calloc(1, sizeof(aul_svc_cb_info_t));
156 info->request_code = request_code;
157 info->cb_func = cbfunc;
163 static void __remove_rescb(aul_svc_cb_info_t *info)
165 if (info) free(info);
168 static int __set_bundle(bundle *b, const char *key, const char *value)
170 const char *val = NULL;
172 val = bundle_get_val(b, key);
174 if ( bundle_del(b, key) != 0 ) {
175 return AUL_SVC_RET_ERROR;
180 return AUL_SVC_RET_EINVAL;
182 if ( bundle_add(b, key, value) != 0 ) {
183 return AUL_SVC_RET_ERROR;
188 return AUL_SVC_RET_OK;
191 static int __set_bundle_array(bundle *b, const char *key, const char **value,
196 type = aul_svc_data_is_array(b, key);
199 if ( bundle_del(b, key) != 0 ) {
200 return AUL_SVC_RET_ERROR;
205 return AUL_SVC_RET_EINVAL;
207 if ( bundle_add_str_array(b, key, value, len) != 0 ) {
208 return AUL_SVC_RET_ERROR;
211 _D("__set_bundle_array");
213 return AUL_SVC_RET_OK;
216 static void __aul_cb(bundle *b, int is_cancel, void *data)
218 const char *val = NULL;
219 aul_svc_cb_info_t* cb_info;
223 res = AUL_SVC_RES_CANCEL;
225 /* get result_code from bundle */
226 val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
227 res = (val == NULL) ? AUL_SVC_RES_NOT_OK : atoi(val);
230 /* remove result_code from bundle */
231 bundle_del(b, AUL_SVC_K_RES_VAL);
233 /* find corresponding callback */
234 cb_info = (aul_svc_cb_info_t*)data;
236 cb_info->cb_func(b, cb_info->request_code, (aul_svc_result_val)res,
238 __remove_rescb(cb_info);
244 static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
245 aul_svc_res_fn cbfunc, void *data)
247 aul_svc_cb_info_t *cb_info = NULL;
250 if ( bundle_get_type(b, AUL_SVC_K_SELECTOR_EXTRA_LIST) != BUNDLE_TYPE_NONE ) {
251 if ( !aul_svc_get_pkgname(b) ) {
252 pkgname = APP_SELECTOR;
256 if ( bundle_get_val(b, AUL_K_FORCE_LAUNCH_APP_SELECTOR) ) {
257 pkgname = APP_SELECTOR;
260 if ( __is_special_app(pkgname)) {
261 bundle_del(b, AUL_SVC_K_CAN_BE_LEADER);
262 bundle_add_str(b, AUL_SVC_K_CAN_BE_LEADER, "true");
263 bundle_del(b, AUL_SVC_K_REROUTE);
264 bundle_add_str(b, AUL_SVC_K_REROUTE, "true");
265 bundle_del(b, AUL_SVC_K_RECYCLE);
266 bundle_add_str(b, AUL_SVC_K_RECYCLE, "true");
271 SECURE_LOGD("pkg_name : %s - with result", pkgname);
273 cb_info = __create_rescb(request_code, cbfunc, data);
274 ret = aul_launch_app_with_result(pkgname, b, __aul_cb, cb_info);
276 SECURE_LOGD("pkg_name : %s - no result", pkgname);
278 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
279 const char* data = bundle_get_val(b, AUL_SVC_K_MULTI_INSTANCE);
281 SECURE_LOGD("multi_instance value = %s", data);
284 if (data && strncmp(data, "TRUE", strlen("TRUE")) == 0) {
285 ret = aul_launch_app_for_multi_instance(pkgname, b);
287 ret = aul_launch_app(pkgname, b);
290 ret = aul_launch_app(pkgname, b);
297 ret = AUL_SVC_RET_EILLACC;
300 ret = AUL_SVC_RET_EINVAL;
302 case AUL_R_ETERMINATING:
303 ret = AUL_SVC_RET_ETERMINATING;
305 case AUL_R_EREJECTED:
306 ret = AUL_SVC_RET_EREJECTED;
309 ret = AUL_SVC_RET_ENOMATCH;
312 ret = AUL_SVC_RET_ELAUNCH;
319 static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info)
322 char *strtok_buf = NULL;
325 info->op = (char *)aul_svc_get_operation(b);
326 info->uri = (char *)aul_svc_get_uri(b);
328 if ((info->uri) && (strcmp(info->uri, "") == 0)) {
330 return AUL_SVC_RET_EINVAL;
333 info->origin_mime = info->mime = (char *)aul_svc_get_mime(b);
334 info->pkgname = (char *)aul_svc_get_pkgname(b);
335 info->category = (char *)aul_svc_get_category(b);
336 info->win_id = (char *)bundle_get_val(b, AUL_SVC_K_WIN_ID);
338 _D("getting resolve info for: operation - %s / uri - %s / mime - %s\n",
339 info->op, info->uri, info->mime);
342 if (strncmp(info->uri, "/", 1) == 0) {
344 info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
345 if (info->mime == NULL) {
347 return AUL_SVC_RET_ERROR;
350 ret = aul_get_mime_from_file(info->uri, info->mime, MAX_MIME_STR_SIZE);
354 } else if (strncmp(info->uri, "file:///", 8) == 0) {
356 info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
357 if (info->mime == NULL) {
359 return AUL_SVC_RET_ERROR;
362 ret = aul_get_mime_from_file(&info->uri[7], info->mime, MAX_MIME_STR_SIZE);
365 } else if (strncmp(info->uri, "file:/", 6) == 0) {
367 info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
368 if (info->mime == NULL) {
370 return AUL_SVC_RET_ERROR;
373 ret = aul_get_mime_from_file(&info->uri[5], info->mime, MAX_MIME_STR_SIZE);
378 if (info->mime_set == 1 && ret < 0) {
379 _E("aul_get_mime_from_file : %d", ret);
381 info->origin_mime = info->mime = NULL;
388 GMatchInfo *match_info;
389 GError *error = NULL;
391 regex = g_regex_new ("^(([^:/?#]+):)?(//([^/?#]*))?", 0, 0, &error);
392 if (g_regex_match (regex, info->uri, 0, &match_info) == FALSE) {
393 g_regex_unref (regex);
394 return AUL_SVC_RET_EINVAL;
397 info->scheme = g_match_info_fetch (match_info, 2);
398 info->host = g_match_info_fetch (match_info, 4);
400 if (info->scheme && info->host) {
401 info->uri_r_info = malloc(MAX_SCHEME_STR_SIZE + MAX_HOST_STR_SIZE + 2);
402 if (info->uri_r_info == NULL) {
404 g_match_info_free(match_info);
405 g_regex_unref(regex);
406 return AUL_SVC_RET_ERROR;
409 snprintf(info->uri_r_info, MAX_SCHEME_STR_SIZE + MAX_HOST_STR_SIZE + 1,
410 "%s://%s", info->scheme, info->host);
413 g_match_info_free (match_info);
414 g_regex_unref (regex);
417 info->scheme = strdup("NULL");
421 info->mime = strdup("NULL");
423 info->m_type = malloc(MAX_LOCAL_BUFSZ);
424 if (info->m_type == NULL) {
426 return AUL_SVC_RET_ERROR;
429 info->s_type = malloc(MAX_LOCAL_BUFSZ);
430 if (info->s_type == NULL) {
433 return AUL_SVC_RET_ERROR;
436 tmp = strdup(info->mime);
437 strtok_buf = strtok(tmp, "/");
439 strncpy(info->m_type, strtok_buf, MAX_LOCAL_BUFSZ - 1);
440 strtok_buf = strtok(NULL, "/");
442 strncpy(info->s_type, strtok_buf, MAX_LOCAL_BUFSZ - 1);
445 if (strncmp(info->m_type, "*", 1) == 0) {
446 strncpy(info->m_type, "%", MAX_LOCAL_BUFSZ - 1);
448 if (strncmp(info->s_type, "*", 1) == 0) {
449 strncpy(info->s_type, "%", MAX_LOCAL_BUFSZ - 1);
452 info->mime = malloc(MAX_MIME_STR_SIZE);
453 if (info->mime == NULL) {
457 return AUL_SVC_RET_ERROR;
460 snprintf(info->mime, MAX_MIME_STR_SIZE - 1, "%s/%s", info->m_type,
467 static int __free_resolve_info_data(aul_svc_resolve_info_t *info)
479 if (info->uri_r_info)
480 free(info->uri_r_info);
482 free(info->origin_mime);
487 static void __set_transient_for(Ecore_X_Window callee, Ecore_X_Window caller,
490 void (*ecore_x_icccm_transient_for_set) (Ecore_X_Window, Ecore_X_Window);
491 void (*ecore_x_window_client_manage) (Ecore_X_Window);
492 int* ecore_x_event_window_destroy;
494 void *handle = dlopen("libecore_x.so.1", RTLD_LAZY | RTLD_LOCAL);
496 _E("dlopen error %s", dlerror());
500 ecore_x_icccm_transient_for_set = dlsym(handle,
501 "ecore_x_icccm_transient_for_set");
502 if (ecore_x_icccm_transient_for_set == NULL) {
508 ecore_x_icccm_transient_for_set(callee, caller);
510 ecore_x_window_client_manage = dlsym(handle, "ecore_x_window_client_manage");
511 if (ecore_x_window_client_manage == NULL) {
517 ecore_x_window_client_manage(caller);
519 ecore_x_event_window_destroy = dlsym(handle, "ECORE_X_EVENT_WINDOW_DESTROY");
520 if (ecore_x_event_window_destroy == NULL) {
526 ecore_event_handler_add(*ecore_x_event_window_destroy, __transient_cb, data);;
531 static char* __get_alias_appid(char *appid)
533 char *alias_id = NULL;
535 char key_string[MAX_PACKAGE_STR_SIZE + 5];
538 dic = iniparser_load("/usr/share/appsvc/alias.ini");
543 snprintf(key_string, sizeof(key_string), "Alias:%s", appid);
544 pthread_mutex_lock(&iniparser_lock);
545 val = iniparser_getstr(dic, key_string);
546 pthread_mutex_unlock(&iniparser_lock);
548 SECURE_LOGD("alias_id : %s", val);
551 alias_id = malloc(MAX_PACKAGE_STR_SIZE);
552 if (alias_id == NULL) {
554 iniparser_freedict(dic);
558 strncpy(alias_id, val, MAX_PACKAGE_STR_SIZE - 1);
561 iniparser_freedict(dic);
566 static int __get_list_with_condition_mime_extened(char *op, char *uri,
567 char *mime, char *m_type, char *s_type, GSList **pkg_list)
571 tmp = malloc(MAX_MIME_STR_SIZE);
577 _svc_db_get_list_with_condition(op, uri, mime, pkg_list);
578 if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(s_type, "%", 1) != 0)) {
579 snprintf(tmp, MAX_MIME_STR_SIZE - 1, "%s/*", m_type);
580 _svc_db_get_list_with_condition(op, uri, tmp, pkg_list);
582 if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(m_type, "%", 1) != 0)) {
583 snprintf(tmp, MAX_MIME_STR_SIZE - 1, "*/*");
584 _svc_db_get_list_with_condition(op, uri, tmp, pkg_list);
592 static int __get_list_with_condition_mime_extened_with_collation(char *op,
593 char *uri, char *mime, char *m_type, char *s_type, GSList **pkg_list)
597 tmp = malloc(MAX_MIME_STR_SIZE);
603 _svc_db_get_list_with_collation(op, uri, mime, pkg_list);
604 if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(s_type, "%", 1) != 0)) {
605 snprintf(tmp, MAX_MIME_STR_SIZE - 1, "%s/*", m_type);
606 _svc_db_get_list_with_collation(op, uri, tmp, pkg_list);
608 if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(m_type, "%", 1) != 0)) {
609 snprintf(tmp, MAX_MIME_STR_SIZE - 1, "*/*");
610 _svc_db_get_list_with_collation(op, uri, tmp, pkg_list);
619 static int __app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
622 GSList **app_list = (GSList **)user_data;
626 pkgmgrinfo_appinfo_get_appid(handle, &str);
627 _D("Matching application is %s", str);
629 for (iter = tmp_list; iter != NULL; iter = g_slist_next(iter)) {
630 if (strncmp(str, (char *)iter->data, MAX_PACKAGE_STR_SIZE - 1) == 0) {
632 *app_list = g_slist_append(*app_list, (void *)appid);
633 _D("%s is added", appid);
640 static int __get_list_with_category(char *category, GSList **pkg_list)
643 pkgmgrinfo_appinfo_filter_h handle;
644 GSList *app_list = NULL;
646 char *list_item = NULL;
648 ret = pkgmgrinfo_appinfo_filter_create(&handle);
649 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
650 PMINFO_APPINFO_PROP_APP_CATEGORY, category);
652 tmp_list = *pkg_list;
653 ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, __app_list_cb,
655 if (ret != PMINFO_R_OK) {
656 pkgmgrinfo_appinfo_filter_destroy(handle);
659 pkgmgrinfo_appinfo_filter_destroy(handle);
661 for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) {
662 list_item = (char *)iter->data;
665 g_slist_free(*pkg_list);
667 *pkg_list = app_list;
672 static int __appid_compare(gconstpointer data1, gconstpointer data2)
674 char *a = (char *)data1;
675 char *b = (char *)data2;
679 static int __check_mainapp_mode(char *operation)
684 static int __get_list_with_submode(char *operation, char *win_id,
688 int mainapp_mode = 0;
690 mainapp_mode = __check_mainapp_mode(operation);
692 SECURE_LOGD("mainapp_mode : %d", mainapp_mode);
694 ret = _svc_db_adjust_list_with_submode(mainapp_mode, win_id, pkg_list);
697 _E("error on get_list_with_submode :%d", ret);
704 SLPAPI int aul_svc_set_operation(bundle *b, const char *operation)
707 _E("bundle for aul_svc_set_operation is NULL");
708 return AUL_SVC_RET_EINVAL;
711 return __set_bundle(b, AUL_SVC_K_OPERATION, operation);
714 SLPAPI int aul_svc_set_uri(bundle *b, const char *uri)
717 _E("bundle for aul_svc_set_uri is NULL");
718 return AUL_SVC_RET_EINVAL;
721 return __set_bundle(b, AUL_SVC_K_URI, uri);
724 SLPAPI int aul_svc_set_mime(bundle *b, const char *mime)
727 _E("bundle for aul_svc_set_mime is NULL");
728 return AUL_SVC_RET_EINVAL;
731 return __set_bundle(b, AUL_SVC_K_MIME, mime);
734 SLPAPI int aul_svc_add_data(bundle *b, const char *key, const char *val)
736 if (b == NULL || key == NULL) {
737 return AUL_SVC_RET_EINVAL;
740 /* check key for data */
743 return __set_bundle(b, key, val);
746 SLPAPI int aul_svc_add_data_array(bundle *b, const char *key,
747 const char **val_array, int len)
749 if (b == NULL || key == NULL) {
750 return AUL_SVC_RET_EINVAL;
753 /* check key for data */
756 return __set_bundle_array(b, key, val_array, len);
760 SLPAPI int aul_svc_set_pkgname(bundle *b, const char *pkg_name)
763 _E("bundle for aul_svc_set_pkgname is NULL");
764 return AUL_SVC_RET_EINVAL;
767 return __set_bundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
771 SLPAPI int aul_svc_set_appid(bundle *b, const char *appid)
773 char *alias_id = NULL;
776 if (b == NULL || appid == NULL) {
777 _E("bundle for aul_svc_set_appid is NULL");
778 return AUL_SVC_RET_EINVAL;
781 alias_id = __get_alias_appid((char *)appid);
782 if (alias_id == NULL) {
783 ret = __set_bundle(b, AUL_SVC_K_PKG_NAME, appid);
785 ret = __set_bundle(b, AUL_SVC_K_PKG_NAME, alias_id);
792 SLPAPI int aul_svc_set_category(bundle *b, const char *category)
795 _E("bundle for aul_svc_set_category is NULL");
796 return AUL_SVC_RET_EINVAL;
799 return __set_bundle(b, AUL_SVC_K_CATEGORY, category);
802 SLPAPI int aul_svc_set_launch_mode(bundle *b, const char *mode)
805 _E("bundle for aul_svc_set_launch_mode is NULL");
806 return AUL_SVC_RET_EINVAL;
809 return __set_bundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
812 SLPAPI int aul_svc_run_service(bundle *b, int request_code,
813 aul_svc_res_fn cbfunc,
816 aul_svc_resolve_info_t info;
821 char oldZone[64] = { 0, };
823 GSList *pkg_list = NULL;
828 _E("bundle for aul_svc_set_appid is NULL");
829 return AUL_SVC_RET_EINVAL;
832 pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
833 pkgname = (char *)aul_svc_get_pkgname(b);
834 operation = (char *)aul_svc_get_operation(b);
838 if (delegator_client_can_jump(&zone, b) == AUL_SVC_RET_OK) {
839 ret = delegator_client_launch(zone, b);
847 if (operation == NULL)
848 aul_svc_set_operation(b, AUL_SVC_OPERATION_DEFAULT);
849 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
850 pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
855 if (operation && (strcmp(operation, AUL_SVC_OPERATION_SHARE) == 0
856 || strcmp(operation, AUL_SVC_OPERATION_MULTI_SHARE) == 0
857 || strcmp(operation, AUL_SVC_OPERATION_SHARE_TEXT) == 0)) {
858 ret = __run_svc_with_pkgname(SHARE_PANEL, b, request_code, cbfunc, data);
859 pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
863 memset(&info, 0, sizeof(aul_svc_resolve_info_t));
864 ret = __get_resolve_info(b, &info);
866 __free_resolve_info_data(&info);
867 pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
871 SECURE_LOGD("op - %s / mime - %s / scheme - %s\n", info.op, info.origin_mime,
874 ret = _svc_db_check_perm();
876 _E("permission error : %d", ret);
877 ret = AUL_SVC_RET_EILLACC;
882 pkgname = _svc_db_get_app(info.op, info.origin_mime, info.uri);
883 if (pkgname == NULL) {
884 __get_list_with_condition_mime_extened_with_collation(info.op, info.uri,
885 info.mime, info.m_type, info.s_type, &pkg_list);
886 pkg_count = g_slist_length(pkg_list);
889 if (info.uri_r_info) {
890 __get_list_with_condition_mime_extened(info.op, info.uri_r_info,
891 info.mime, info.m_type, info.s_type, &pkg_list);
894 __get_list_with_condition_mime_extened(info.op, info.scheme,
895 info.mime, info.m_type, info.s_type, &pkg_list);
897 __get_list_with_condition_mime_extened(info.op, "*",
898 info.mime, info.m_type, info.s_type, &pkg_list);
900 if (info.scheme && (strcmp(info.scheme, "file") == 0)
901 && info.mime && (strcmp(info.mime, "NULL") != 0)) {
902 __get_list_with_condition_mime_extened(info.op, "NULL",
903 info.mime, info.m_type, info.s_type, &pkg_list);
907 __get_list_with_category(info.category, &pkg_list);
910 __get_list_with_submode(info.op, info.win_id, &pkg_list);
912 pkg_count = g_slist_length(pkg_list);
913 _D("pkg_count : %d", pkg_count);
915 if (pkg_count == 1) {
916 pkgname = (char *)pkg_list->data;
917 if (pkgname != NULL) {
918 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
922 bundle_add(b, AUL_SVC_K_URI_R_INFO, info.uri);
923 ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data);
926 for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
927 list_item = (char *)iter->data;
930 g_slist_free(pkg_list);
934 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
940 if (info.uri_r_info) {
941 pkgname = _svc_db_get_app(info.op, info.origin_mime, info.uri_r_info);
943 if (pkgname == NULL) {
944 __get_list_with_condition_mime_extened(info.op, info.uri_r_info,
945 info.mime, info.m_type, info.s_type, &pkg_list);
946 pkg_count = g_slist_length(pkg_list);
948 __get_list_with_condition_mime_extened(info.op, info.scheme,
949 info.mime, info.m_type, info.s_type, &pkg_list);
951 __get_list_with_condition_mime_extened(info.op, "*",
952 info.mime, info.m_type, info.s_type, &pkg_list);
954 if (info.scheme && (strcmp(info.scheme, "file") == 0)
955 && info.mime && (strcmp(info.mime, "NULL") != 0)) {
956 __get_list_with_condition_mime_extened(info.op, "NULL",
957 info.mime, info.m_type, info.s_type, &pkg_list);
961 __get_list_with_category(info.category, &pkg_list);
964 __get_list_with_submode(info.op, info.win_id, &pkg_list);
966 pkg_count = g_slist_length(pkg_list);
967 _D("pkg_count : %d", pkg_count);
969 if (pkg_count == 1) {
970 pkgname = (char *)pkg_list->data;
971 if (pkgname != NULL) {
972 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
976 bundle_add(b, AUL_SVC_K_URI_R_INFO, info.uri_r_info);
977 ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data);
981 for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
982 list_item = (char *)iter->data;
985 g_slist_free(pkg_list);
988 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
995 pkgname = _svc_db_get_app(info.op, info.origin_mime, info.scheme);
997 if (pkgname == NULL) {
998 __get_list_with_condition_mime_extened(info.op, info.scheme,
999 info.mime, info.m_type, info.s_type, &pkg_list);
1001 __get_list_with_condition_mime_extened(info.op, "*",
1002 info.mime, info.m_type, info.s_type, &pkg_list);
1004 if (info.scheme && (strcmp(info.scheme, "file") == 0)
1005 && info.mime && (strcmp(info.mime, "NULL") != 0)) {
1006 __get_list_with_condition_mime_extened(info.op, "NULL",
1007 info.mime, info.m_type, info.s_type, &pkg_list);
1010 if (info.category) {
1011 __get_list_with_category(info.category, &pkg_list);
1014 __get_list_with_submode(info.op, info.win_id, &pkg_list);
1016 pkg_count = g_slist_length(pkg_list);
1017 _D("pkg_count : %d", pkg_count);
1019 if (pkg_count == 1) {
1020 pkgname = (char *)pkg_list->data;
1021 if (pkgname != NULL) {
1022 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
1024 } else if (pkg_count < 1) {
1025 __free_resolve_info_data(&info);
1026 pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
1027 return AUL_SVC_RET_ENOMATCH;
1029 bundle_add(b, AUL_SVC_K_URI_R_INFO, info.scheme);
1030 ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data);
1033 for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
1034 list_item = (char *)iter->data;
1037 g_slist_free(pkg_list);
1039 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
1044 __free_resolve_info_data(&info);
1046 pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
1050 SLPAPI int aul_svc_get_list(bundle *b, aul_svc_info_iter_fn iter_fn, void *data)
1052 aul_svc_resolve_info_t info;
1053 char *pkgname = NULL;
1056 char oldZone[64] = { 0, };
1058 GSList *pkg_list = NULL;
1059 GSList *iter = NULL;
1062 _E("bundle for aul_svc_run_service is NULL");
1063 return AUL_SVC_RET_EINVAL;
1066 if (iter_fn == NULL) {
1067 _E("iter_fn for aul_svc_run_service is NULL");
1068 return AUL_SVC_RET_EINVAL;
1071 pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
1074 memset(&info, 0, sizeof(aul_svc_resolve_info_t));
1075 ret = __get_resolve_info(b, &info);
1077 __free_resolve_info_data(&info);
1081 _D("operation - %s / shceme - %s / mime - %s\n", info.op, info.scheme,
1084 __get_list_with_condition_mime_extened_with_collation(info.op, info.uri,
1085 info.mime, info.m_type, info.s_type, &pkg_list);
1087 if (info.uri_r_info) {
1088 __get_list_with_condition_mime_extened(info.op, info.uri_r_info,
1089 info.mime, info.m_type, info.s_type, &pkg_list);
1092 __get_list_with_condition_mime_extened(info.op, info.scheme,
1093 info.mime, info.m_type, info.s_type, &pkg_list);
1095 __get_list_with_condition_mime_extened(info.op, "*",
1096 info.mime, info.m_type, info.s_type, &pkg_list);
1098 if (info.scheme && (strcmp(info.scheme, "file") == 0)
1099 && info.mime && (strcmp(info.mime, "NULL") != 0)) {
1100 __get_list_with_condition_mime_extened(info.op, "NULL",
1101 info.mime, info.m_type, info.s_type, &pkg_list);
1104 if (info.category) {
1105 __get_list_with_category(info.category, &pkg_list);
1108 __get_list_with_submode(info.op, info.win_id, &pkg_list);
1110 pkg_count = g_slist_length(pkg_list);
1111 if (pkg_count == 0) {
1112 _E("Cannot find associated application");
1114 __free_resolve_info_data(&info);
1115 pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
1116 return AUL_SVC_RET_ENOMATCH;
1119 for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
1120 pkgname = iter->data;
1121 SECURE_LOGD("PKGNAME : %s\n", pkgname);
1122 if ( iter_fn(pkgname, data) != 0)
1127 g_slist_free(pkg_list);
1128 __free_resolve_info_data(&info);
1130 pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
1131 return AUL_SVC_RET_OK;
1134 SLPAPI int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn, void *data)
1136 char *pkgname = NULL;
1138 char oldZone[64] = { 0, };
1140 GSList *pkg_list = NULL;
1141 GSList *iter = NULL;
1143 pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
1145 ret = _svc_db_check_perm();
1147 _E("permission error : %d", ret);
1148 return AUL_SVC_RET_EILLACC;
1151 ret = _svc_db_get_list_with_all_defapps(&pkg_list);
1155 for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
1156 pkgname = iter->data;
1157 if ( iter_fn(pkgname, data) != 0)
1162 g_slist_free(pkg_list);
1164 pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
1165 return AUL_SVC_RET_OK;
1168 SLPAPI const char *aul_svc_get_operation(bundle *b)
1170 return bundle_get_val(b, AUL_SVC_K_OPERATION);
1173 SLPAPI const char *aul_svc_get_uri(bundle *b)
1175 return bundle_get_val(b, AUL_SVC_K_URI);
1178 SLPAPI const char *aul_svc_get_mime(bundle *b)
1180 return bundle_get_val(b, AUL_SVC_K_MIME);
1183 SLPAPI const char *aul_svc_get_data(bundle *b, const char *key)
1185 return bundle_get_val(b, key);
1188 SLPAPI const char **aul_svc_get_data_array(bundle *b, const char *key, int *len)
1190 return bundle_get_str_array(b, key, len);
1193 SLPAPI const char *aul_svc_get_pkgname(bundle *b)
1195 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
1198 SLPAPI const char *aul_svc_get_appid(bundle *b)
1200 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
1203 SLPAPI const char *aul_svc_get_category(bundle *b)
1205 return bundle_get_val(b, AUL_SVC_K_CATEGORY);
1208 SLPAPI const char *aul_svc_get_launch_mode(bundle *b)
1210 return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
1213 SLPAPI int aul_svc_create_result_bundle(bundle *inb, bundle **outb)
1217 if (inb == NULL || outb == NULL) {
1218 _E("bundle is NULL");
1219 return AUL_SVC_RET_EINVAL;
1222 ret = aul_create_result_bundle(inb, outb);
1224 /* add additional bundle */
1225 /* bundle_add(outb, " ", " "); */
1227 if (ret == AUL_R_OK)
1228 ret = AUL_SVC_RET_OK;
1229 else if (ret == AUL_R_EINVAL)
1230 ret = AUL_SVC_RET_EINVAL;
1232 ret = AUL_SVC_RET_ERROR;
1237 SLPAPI int aul_svc_send_result(bundle *b, aul_svc_result_val result)
1240 char tmp[MAX_LOCAL_BUFSZ];
1243 _E("aul_svc_send_result is NULL");
1244 return AUL_SVC_RET_EINVAL;
1247 if (result != AUL_SVC_RES_OK && result != AUL_SVC_RES_NOT_OK) {
1248 _E("invalid result %d", (int)result);
1249 return AUL_SVC_RET_EINVAL;
1252 /* add result_code to bundle */
1253 snprintf(tmp, MAX_LOCAL_BUFSZ, "%d", (int)result);
1254 ret = __set_bundle(b, AUL_SVC_K_RES_VAL, tmp);
1256 return AUL_SVC_RET_ERROR;
1258 ret = aul_send_service_result(b);
1260 /* remove result_code from bundle */
1261 bundle_del(b, AUL_SVC_K_RES_VAL);
1266 SLPAPI int aul_svc_set_defapp(const char *op, const char *mime_type,
1272 if (op == NULL || defapp == NULL)
1273 return AUL_SVC_RET_EINVAL;
1275 ret = _svc_db_check_perm();
1277 _E("permission error : %d", ret);
1278 return AUL_SVC_RET_EILLACC;
1281 ret = _svc_db_add_app(op, mime_type, uri, defapp);
1284 return AUL_SVC_RET_ERROR;
1286 return AUL_SVC_RET_OK;
1289 SLPAPI int aul_svc_unset_defapp(const char *defapp)
1294 return AUL_SVC_RET_EINVAL;
1296 ret = _svc_db_check_perm();
1298 _E("permission error : %d", ret);
1299 return AUL_SVC_RET_EILLACC;
1302 ret = _svc_db_delete_with_pkgname(defapp);
1305 return AUL_SVC_RET_ERROR;
1307 return AUL_SVC_RET_OK;
1310 SLPAPI int aul_svc_unset_all_defapps()
1314 ret = _svc_db_check_perm();
1316 _E("permission error : %d", ret);
1317 return AUL_SVC_RET_EILLACC;
1320 ret = _svc_db_delete_all();
1323 return AUL_SVC_RET_ERROR;
1325 return AUL_SVC_RET_OK;
1328 SLPAPI int aul_svc_is_defapp(const char *pkg_name)
1332 ret = _svc_db_check_perm();
1334 _E("permission error : %d", ret);
1335 return AUL_SVC_RET_EILLACC;
1338 return _svc_db_is_defapp(pkg_name);
1341 SLPAPI int aul_svc_data_is_array(bundle *b, const char *key)
1344 type = bundle_get_type(b, key);
1349 if (type & BUNDLE_TYPE_ARRAY)
1354 SLPAPI int aul_svc_allow_transient_app(bundle *b, int wid)
1356 char win_id[MAX_LOCAL_BUFSZ];
1358 snprintf(win_id, MAX_LOCAL_BUFSZ, "%d", wid);
1361 _E("bundle for aul_svc_allow_transient_app is NULL");
1362 return AUL_SVC_RET_EINVAL;
1365 return __set_bundle(b, AUL_SVC_K_WIN_ID, win_id);
1368 SLPAPI int aul_svc_request_transient_app(bundle *b, int callee_wid,
1369 aul_svc_host_res_fn cbfunc, void *data)
1371 const char *caller = NULL;
1372 Ecore_X_Window caller_wid;
1373 aul_svc_transient_cb_info_t* info;
1375 caller = bundle_get_val(b, AUL_SVC_K_WIN_ID);
1377 return AUL_SVC_RET_ERROR;
1379 caller_wid = atoi(caller);
1381 if (callee_wid == caller_wid) {
1382 _E("callee window id is same as calleer window id. request will be ignored");
1383 return AUL_SVC_RET_EINVAL;
1386 info = (aul_svc_transient_cb_info_t*)calloc(1,
1387 sizeof(aul_svc_transient_cb_info_t));
1389 return AUL_SVC_RET_ERROR;
1391 info->win_id = caller_wid;
1392 info->cb_func = cbfunc;
1395 __set_transient_for(callee_wid, caller_wid, info);
1397 aul_set_subapp(__aul_subapp_cb, info);
1402 SLPAPI int aul_svc_subapp_terminate_request_pid(int pid)
1404 int cpid = getpid();
1409 aul_app_group_get_leader_pids(&lcnt, &lpids);
1410 for (i = 0; i < lcnt; i++) {
1411 if (lpids[i] == cpid) {
1415 aul_app_group_get_group_pids(cpid, &cnt, &pids);
1422 return aul_subapp_terminate_request_pid(pid);
1434 return aul_app_group_clear_top();
1437 SLPAPI int aul_send_service_result(bundle *b)
1439 return aul_send_result(b, 0);
1442 SLPAPI int aul_svc_subscribe_launch_result(bundle *b, const char *result)
1445 _E("bundle for aul_svc_subscribe_launch_result is NULL");
1446 return AUL_SVC_RET_EINVAL;
1449 return __set_bundle(b, result, "1");