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>
25 #include <bundle_internal.h>
30 #include <iniparser.h>
31 #include <pkgmgr-info.h>
37 #include "aul_svc_db.h"
39 #include "aul_svc_priv_key.h"
41 #include "aul_svc_internal.h"
42 #include "aul_app_group.h"
44 #define MAX_CHECKSUM_BUF 2048
45 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
46 #define FREE_AND_NULL(x) do { \
53 /* callback handling */
54 typedef struct _aul_svc_cb_info_t {
56 aul_svc_res_fn cb_func;
57 aul_svc_err_cb err_cb;
61 typedef struct _aul_svc_resolve_info_t {
75 } aul_svc_resolve_info_t;
77 typedef struct _aul_svc_transient_cb_info_t {
78 aul_svc_host_res_fn cb_func;
80 } aul_svc_transient_cb_info_t;
82 pthread_mutex_t iniparser_lock = PTHREAD_MUTEX_INITIALIZER;
85 static aul_svc_cb_info_t *__create_rescb(int request_code,
86 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void *data);
87 static void __remove_rescb(aul_svc_cb_info_t *info);
88 static int __set_bundle(bundle *b, const char *key, const char *value);
89 static void __aul_cb(bundle *b, int is_cancel, void *data);
90 static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
91 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void *data,
92 uid_t uid, bool sync);
93 static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info);
94 static int __free_resolve_info_data(aul_svc_resolve_info_t *info);
96 static char *white_list[] = {
102 static bool __is_special_app(const char *appid)
110 while ((id = white_list[i]) != NULL) {
111 if (strcmp(id, appid) == 0)
118 static bool __is_special_operation(bundle *b)
120 const char *operation;
121 const char *white_operations[] = {
122 "http://tizen.org/appcontrol/operation/guide_privacy_setting",
127 operation = aul_svc_get_operation(b);
131 for (i = 0; white_operations[i]; ++i) {
132 if (!strcmp(operation, white_operations[i]))
139 static aul_svc_cb_info_t *__create_rescb(int request_code,
140 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void *data)
142 aul_svc_cb_info_t* info;
144 info = calloc(1, sizeof(aul_svc_cb_info_t));
150 info->request_code = request_code;
151 info->cb_func = cbfunc;
152 info->err_cb = err_cb;
158 static void __remove_rescb(aul_svc_cb_info_t *info)
164 static int __set_bundle(bundle *b, const char *key, const char *value)
166 const char *val = NULL;
168 val = bundle_get_val(b, key);
170 if (bundle_del(b, key) != 0)
171 return AUL_SVC_RET_ERROR;
175 return AUL_SVC_RET_EINVAL;
177 if (bundle_add(b, key, value) != 0)
178 return AUL_SVC_RET_ERROR;
182 return AUL_SVC_RET_OK;
185 static int __set_bundle_array(bundle *b, const char *key,
186 const char **value, int len)
190 type = aul_svc_data_is_array(b, key);
193 if (bundle_del(b, key) != 0)
194 return AUL_SVC_RET_ERROR;
198 return AUL_SVC_RET_EINVAL;
200 if (bundle_add_str_array(b, key, value, len) != 0)
201 return AUL_SVC_RET_ERROR;
203 _D("__set_bundle_array");
205 return AUL_SVC_RET_OK;
208 static void __aul_cb(bundle *b, int is_cancel, void *data)
210 const char *val = NULL;
211 aul_svc_cb_info_t* cb_info;
215 res = AUL_SVC_RES_CANCEL;
217 /* get result_code from bundle */
218 val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
219 res = (val == NULL) ? AUL_SVC_RES_NOT_OK : atoi(val);
222 /* remove result_code from bundle */
223 bundle_del(b, AUL_SVC_K_RES_VAL);
225 /* find corresponding callback */
226 cb_info = (aul_svc_cb_info_t*)data;
228 if (cb_info->cb_func) {
229 cb_info->cb_func(b, cb_info->request_code,
230 (aul_svc_result_val)res, cb_info->data);
231 cb_info->cb_func = NULL;
237 __remove_rescb(cb_info);
240 static int __error_convert(int res)
244 return AUL_SVC_RET_EILLACC;
246 return AUL_SVC_RET_EINVAL;
247 case AUL_R_ETERMINATING:
248 return AUL_SVC_RET_ETERMINATING;
249 case AUL_R_EREJECTED:
250 return AUL_SVC_RET_EREJECTED;
252 return AUL_SVC_RET_ENOMATCH;
254 return AUL_SVC_RET_ELAUNCH;
258 static void __aul_error_cb(int err, void *data)
260 aul_svc_cb_info_t *cb_info = (aul_svc_cb_info_t *)data;
263 _E("Critical error!");
268 err = __error_convert(err);
270 if (cb_info->err_cb) {
271 cb_info->err_cb(cb_info->request_code, err, cb_info->data);
272 cb_info->err_cb = NULL;
275 if (cb_info->cb_func)
278 __remove_rescb(cb_info);
281 static void __set_instance_id(bundle *b, const char *appid)
289 uuid_unparse(u, uuid);
291 comp_id = bundle_get_val(b, AUL_K_COMPONENT_ID);
293 snprintf(buf, sizeof(buf), "%s:%s:%s", uuid, appid, comp_id);
295 snprintf(buf, sizeof(buf), "%s:%s", uuid, appid);
297 bundle_add(b, AUL_K_INSTANCE_ID, buf);
300 static void __verify_request(bundle *b, char **appid)
302 const char *launch_mode;
305 ret = bundle_get_type(b, AUL_SVC_K_SELECTOR_EXTRA_LIST);
306 if (ret != BUNDLE_TYPE_NONE) {
307 if (!aul_svc_get_pkgname(b))
308 *appid = APP_SELECTOR;
311 if (bundle_get_val(b, AUL_K_FORCE_LAUNCH_APP_SELECTOR))
312 *appid = APP_SELECTOR;
314 if (__is_special_app(*appid) || __is_special_operation(b)) {
315 bundle_del(b, AUL_SVC_K_CAN_BE_LEADER);
316 bundle_add_str(b, AUL_SVC_K_CAN_BE_LEADER, "true");
317 bundle_del(b, AUL_SVC_K_REROUTE);
318 bundle_add_str(b, AUL_SVC_K_REROUTE, "true");
319 bundle_del(b, AUL_SVC_K_RECYCLE);
320 bundle_add_str(b, AUL_SVC_K_RECYCLE, "true");
323 launch_mode = aul_svc_get_launch_mode(b);
324 if (launch_mode && !strcmp(launch_mode, "group")) {
325 ret = bundle_get_type(b, AUL_K_INSTANCE_ID);
326 if (ret == BUNDLE_TYPE_NONE)
327 __set_instance_id(b, *appid);
331 static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
332 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
333 void *data, uid_t uid, bool sync)
335 aul_svc_cb_info_t *cb_info = NULL;
338 __verify_request(b, &pkgname);
340 if (cbfunc || err_cb) {
341 SECURE_LOGD("pkg_name : %s - with result", pkgname);
343 cb_info = __create_rescb(request_code, cbfunc, err_cb, data);
345 ret = aul_launch_app_with_result_for_uid(pkgname, b,
346 __aul_cb, cb_info, uid);
349 ret = aul_send_launch_request_for_uid(pkgname,
351 cbfunc ? __aul_cb : NULL,
355 ret = aul_launch_app_with_result_async_for_uid(
356 pkgname, b, __aul_cb,
361 SECURE_LOGD("pkg_name : %s - no result", pkgname);
363 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
364 const char* data = bundle_get_val(b, AUL_SVC_K_MULTI_INSTANCE);
366 SECURE_LOGD("multi_instance value = %s", data);
368 if (data && strncmp(data, "TRUE", strlen("TRUE")) == 0) {
370 ret = aul_launch_app_for_multi_instance(pkgname,
373 ret = aul_launch_app_for_multi_instance_async(
378 ret = aul_launch_app(pkgname, b);
380 ret = aul_launch_app_async(pkgname, b, uid);
384 ret = aul_launch_app_for_uid(pkgname, b, uid);
386 ret = aul_launch_app_async_for_uid(pkgname, b, uid);
392 __remove_rescb(cb_info);
393 ret = __error_convert(ret);
399 static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info)
402 char *saveptr = NULL;
403 char *strtok_buf = NULL;
406 info->op = (char *)aul_svc_get_operation(b);
407 info->uri = (char *)aul_svc_get_uri(b);
409 if ((info->uri) && (strcmp(info->uri, "") == 0)) {
411 return AUL_SVC_RET_EINVAL;
414 info->origin_mime = info->mime = (char *)aul_svc_get_mime(b);
415 info->pkgname = (char *)aul_svc_get_pkgname(b);
416 info->category = (char *)aul_svc_get_category(b);
417 info->win_id = (char *)bundle_get_val(b, AUL_SVC_K_WIN_ID);
419 SECURE_LOGD("getting resolve info for: operation - %s / uri - %s / mime - %s",
420 info->op, info->uri, info->mime);
423 if (strncmp(info->uri, "/", 1) == 0) {
425 info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
426 if (info->mime == NULL) {
428 return AUL_SVC_RET_ERROR;
431 ret = aul_get_mime_from_file(info->uri, info->mime, MAX_MIME_STR_SIZE);
435 } else if (strncmp(info->uri, "file:///", 8) == 0) {
437 info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
438 if (info->mime == NULL) {
440 return AUL_SVC_RET_ERROR;
443 ret = aul_get_mime_from_file(&info->uri[7], info->mime, MAX_MIME_STR_SIZE);
446 } else if (strncmp(info->uri, "file:/", 6) == 0) {
448 info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
449 if (info->mime == NULL) {
451 return AUL_SVC_RET_ERROR;
454 ret = aul_get_mime_from_file(&info->uri[5], info->mime, MAX_MIME_STR_SIZE);
459 if (info->mime_set == 1 && ret < 0) {
460 _E("aul_get_mime_from_file : %d", ret);
462 info->origin_mime = info->mime = NULL;
469 GMatchInfo *match_info;
470 GError *error = NULL;
472 regex = g_regex_new("^(([^:/?#]+):)?(//([^/?#]*))?", 0, 0, &error);
473 if (g_regex_match(regex, info->uri, 0, &match_info) == FALSE) {
474 g_regex_unref(regex);
475 return AUL_SVC_RET_EINVAL;
478 info->scheme = g_match_info_fetch(match_info, 2);
479 info->host = g_match_info_fetch(match_info, 4);
481 if (info->scheme && info->host) {
482 info->uri_r_info = malloc(MAX_SCHEME_STR_SIZE + MAX_HOST_STR_SIZE + 2);
483 if (info->uri_r_info == NULL) {
485 g_match_info_free(match_info);
486 g_regex_unref(regex);
487 return AUL_SVC_RET_ERROR;
490 snprintf(info->uri_r_info, MAX_SCHEME_STR_SIZE + MAX_HOST_STR_SIZE + 1,
491 "%s://%s", info->scheme, info->host);
494 g_match_info_free(match_info);
495 g_regex_unref(regex);
498 info->scheme = strdup("NULL");
502 info->mime = strdup("NULL");
506 info->m_type = calloc(1, MAX_LOCAL_BUFSZ);
507 if (info->m_type == NULL) {
509 return AUL_SVC_RET_ERROR;
512 info->s_type = calloc(1, MAX_LOCAL_BUFSZ);
513 if (info->s_type == NULL) {
516 return AUL_SVC_RET_ERROR;
519 tmp = strdup(info->mime);
524 return AUL_SVC_RET_ERROR;
527 strtok_buf = strtok_r(tmp, "/", &saveptr);
529 strncpy(info->m_type, strtok_buf, MAX_LOCAL_BUFSZ - 1);
530 strtok_buf = strtok_r(NULL, "/", &saveptr);
532 strncpy(info->s_type, strtok_buf, MAX_LOCAL_BUFSZ - 1);
535 if (strncmp(info->m_type, "*", 1) == 0)
536 strncpy(info->m_type, "%", MAX_LOCAL_BUFSZ - 1);
537 if (strncmp(info->s_type, "*", 1) == 0)
538 strncpy(info->s_type, "%", MAX_LOCAL_BUFSZ - 1);
540 info->mime = malloc(MAX_MIME_STR_SIZE);
541 if (info->mime == NULL) {
545 return AUL_SVC_RET_ERROR;
548 snprintf(info->mime, MAX_MIME_STR_SIZE - 1,
549 "%s/%s", info->m_type, info->s_type);
554 static int __free_resolve_info_data(aul_svc_resolve_info_t *info)
566 if (info->uri_r_info)
567 free(info->uri_r_info);
569 free(info->origin_mime);
574 static char* __get_alias_appid(char *appid)
576 char *alias_id = NULL;
577 const char *val = NULL;
578 char key_string[MAX_PACKAGE_STR_SIZE + 5];
581 dic = iniparser_load("/usr/share/appsvc/alias.ini");
586 snprintf(key_string, sizeof(key_string), "Alias:%s", appid);
587 pthread_mutex_lock(&iniparser_lock);
588 val = iniparser_getstring(dic, key_string, NULL);
589 pthread_mutex_unlock(&iniparser_lock);
591 SECURE_LOGD("alias_id : %s", val);
594 alias_id = malloc(MAX_PACKAGE_STR_SIZE);
595 if (alias_id == NULL) {
597 iniparser_freedict(dic);
601 strncpy(alias_id, val, MAX_PACKAGE_STR_SIZE - 1);
604 iniparser_freedict(dic);
609 static char* __make_query(char *query, char *op, char *uri,
610 char *mime, char *m_type, char *s_type)
612 char tmp[MAX_MIME_STR_SIZE] = { 0, };
614 query = _svc_db_query_builder_add(query, op, uri, mime, false);
615 if ((mime && strncmp(mime, "NULL", 4) != 0) &&
616 (s_type && strncmp(s_type, "%", 1) != 0)) {
617 snprintf(tmp, MAX_MIME_STR_SIZE - 1, "%s/*", m_type);
618 query = _svc_db_query_builder_add(query, op, uri, tmp, false);
621 if ((mime && strncmp(mime, "NULL", 4) != 0) &&
622 (m_type && strncmp(m_type, "%", 1) != 0)) {
623 snprintf(tmp, MAX_MIME_STR_SIZE - 1, "*/*");
624 query = _svc_db_query_builder_add(query, op, uri, tmp, false);
630 static char* __make_query_with_collation(char *op, char *uri, char *mime, char *m_type, char *s_type)
632 char tmp[MAX_MIME_STR_SIZE];
635 query = _svc_db_query_builder_add(query, op, uri, mime, true);
637 if (mime && (strncmp(mime, "NULL", 4) != 0) &&
638 s_type && (strncmp(s_type, "%", 1) != 0)) {
639 snprintf(tmp, MAX_MIME_STR_SIZE - 1, "%s/*", m_type);
640 query = _svc_db_query_builder_add(query, op, uri, tmp, true);
642 if (mime && (strncmp(mime, "NULL", 4) != 0) &&
643 m_type && (strncmp(m_type, "%", 1) != 0)) {
644 snprintf(tmp, MAX_MIME_STR_SIZE - 1, "*/*");
645 query = _svc_db_query_builder_add(query, op, uri, tmp, true);
648 query = _svc_db_query_builder_in("ac.app_control collate appsvc_collation ", query);
654 static int __app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
657 GSList **app_list = (GSList **)user_data;
661 pkgmgrinfo_appinfo_get_appid(handle, &str);
662 _D("Matching application is %s", str);
664 for (iter = tmp_list; iter != NULL; iter = g_slist_next(iter)) {
665 if (strncmp(str, (char *)iter->data, MAX_PACKAGE_STR_SIZE - 1) == 0) {
667 *app_list = g_slist_append(*app_list, (void *)appid);
668 _D("%s is added", appid);
675 static int __get_list_with_category(char *category, GSList **pkg_list, uid_t uid)
678 pkgmgrinfo_appinfo_filter_h handle;
679 GSList *app_list = NULL;
681 char *list_item = NULL;
683 ret = pkgmgrinfo_appinfo_filter_create(&handle);
684 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
685 PMINFO_APPINFO_PROP_APP_CATEGORY, category);
687 tmp_list = *pkg_list;
688 ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle,
689 __app_list_cb, &app_list, uid);
690 if (ret != PMINFO_R_OK) {
691 pkgmgrinfo_appinfo_filter_destroy(handle);
694 pkgmgrinfo_appinfo_filter_destroy(handle);
696 for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) {
697 list_item = (char *)iter->data;
700 g_slist_free(*pkg_list);
702 *pkg_list = app_list;
707 static int __check_mainapp_mode(char *operation)
712 static int __get_list_with_submode(char *operation, char *win_id,
713 GSList **pkg_list, uid_t uid)
716 int mainapp_mode = 0;
718 mainapp_mode = __check_mainapp_mode(operation);
720 SECURE_LOGD("mainapp_mode : %d", mainapp_mode);
722 ret = _svc_db_adjust_list_with_submode(mainapp_mode, win_id, pkg_list, uid);
725 _E("error: %d", ret);
732 static void __free_pkg_list(GSList *list)
740 for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
741 list_item = (char *)iter->data;
747 static gchar *__make_checksum(const char *op, const char *uri, const char *mime)
749 char buf[MAX_CHECKSUM_BUF];
752 snprintf(buf, sizeof(buf), "%s:%s:%s", op, uri, mime);
753 checksum = g_compute_checksum_for_string(G_CHECKSUM_MD5, buf, -1);
758 static char *__get_cache(const char *checksum, uid_t uid)
760 app_pkt_t *pkt = NULL;
764 char buf[MAX_PID_STR_BUFSZ];
773 snprintf(buf, sizeof(buf), "%d", uid);
774 bundle_add(b, AUL_K_TARGET_UID, buf);
775 bundle_add(b, AUL_K_CHECKSUM, checksum);
777 fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, APP_GET_APPID_FROM_CACHE,
783 ret = aul_sock_recv_reply_pkt(fd, &pkt);
787 if (pkt->cmd == APP_GET_APPID_FROM_CACHE) {
788 if (pkt->data[0] == 0) {
792 appid = strdup((const char *)(pkt->data));
801 static void __put_cache(const char *checksum, const char *appid, uid_t uid)
805 char buf[MAX_PID_STR_BUFSZ];
813 snprintf(buf, sizeof(buf), "%d", uid);
814 bundle_add(b, AUL_K_TARGET_UID, buf);
815 bundle_add(b, AUL_K_CHECKSUM, checksum);
816 bundle_add(b, AUL_K_APPID, appid);
818 ret = app_send_cmd_for_uid(AUL_UTIL_PID, uid, APP_SET_CACHE, b);
821 _E("Failed to set cache : %d", ret);
826 static void __put_cache_with_info(const char *checksum, const char *info, uid_t uid)
830 snprintf(buf, sizeof(buf), "@APP_SELECTOR %s", info);
831 __put_cache(checksum, buf, uid);
834 static void __invalidate_cache(uid_t uid)
838 char buf[MAX_PID_STR_BUFSZ];
846 snprintf(buf, sizeof(buf), "%d", uid);
847 bundle_add(b, AUL_K_TARGET_UID, buf);
848 ret = app_send_cmd_for_uid(AUL_UTIL_PID, uid, APP_INVALIDATE_CACHE, b);
851 _E("Failed to invalidate cache : %d", ret);
856 API int aul_svc_set_operation(bundle *b, const char *operation)
859 _E("bundle is NULL");
860 return AUL_SVC_RET_EINVAL;
863 return __set_bundle(b, AUL_SVC_K_OPERATION, operation);
866 API int aul_svc_set_uri(bundle *b, const char *uri)
869 _E("bundle is NULL");
870 return AUL_SVC_RET_EINVAL;
873 return __set_bundle(b, AUL_SVC_K_URI, uri);
876 API int aul_svc_set_mime(bundle *b, const char *mime)
879 _E("bundle is NULL");
880 return AUL_SVC_RET_EINVAL;
883 return __set_bundle(b, AUL_SVC_K_MIME, mime);
886 API int aul_svc_add_data(bundle *b, const char *key, const char *val)
888 if (b == NULL || key == NULL)
889 return AUL_SVC_RET_EINVAL;
891 /* check key for data */
894 return __set_bundle(b, key, val);
897 API int aul_svc_add_data_array(bundle *b, const char *key,
898 const char **val_array, int len)
900 if (b == NULL || key == NULL)
901 return AUL_SVC_RET_EINVAL;
903 /* check key for data */
906 return __set_bundle_array(b, key, val_array, len);
909 API int aul_svc_set_pkgname(bundle *b, const char *pkg_name)
912 _E("bundle is NULL");
913 return AUL_SVC_RET_EINVAL;
916 return __set_bundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
919 API int aul_svc_set_appid(bundle *b, const char *appid)
921 char *alias_id = NULL;
924 if (b == NULL || appid == NULL) {
925 _E("bundle is NULL");
926 return AUL_SVC_RET_EINVAL;
929 alias_id = __get_alias_appid((char *)appid);
930 if (alias_id == NULL) {
931 ret = __set_bundle(b, AUL_SVC_K_PKG_NAME, appid);
933 ret = __set_bundle(b, AUL_SVC_K_PKG_NAME, alias_id);
941 API int aul_svc_set_category(bundle *b, const char *category)
944 _E("bundle is NULL");
945 return AUL_SVC_RET_EINVAL;
948 return __set_bundle(b, AUL_SVC_K_CATEGORY, category);
951 API int aul_svc_set_launch_mode(bundle *b, const char *mode)
954 _E("bundle is NULL");
955 return AUL_SVC_RET_EINVAL;
958 return __set_bundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
961 typedef struct resolution_info_s {
963 const char *uri_r_info;
967 aul_svc_resolve_info_t ri;
972 typedef int (*resolution_handler)(resolution_info_t *info);
974 static int __resolution_pre(resolution_info_t *info)
976 aul_svc_resolve_info_t *ri = &info->ri;
980 ret = __get_resolve_info(info->b, ri);
984 SECURE_LOGD("op - %s / mime - %s / scheme - %s",
985 ri->op, ri->origin_mime, ri->scheme);
987 info->checksum = __make_checksum(ri->op, ri->uri, ri->origin_mime);
988 info->cache = __get_cache(info->checksum, info->uid);
990 _D("Hit! %s / %s", info->checksum, info->cache);
991 n = strlen("@APP_SELECTOR ");
992 if (!strncmp("@APP_SELECTOR ", info->cache, n)) {
993 bundle_add(info->b, AUL_SVC_K_URI_R_INFO,
995 info->appid = strdup(APP_SELECTOR);
996 if (info->appid == NULL) {
998 ret = AUL_SVC_RET_ERROR;
1001 } else if (!strcmp(info->cache, "^")) {
1002 ret = AUL_SVC_RET_ENOMATCH;
1005 info->appid = info->cache;
1008 return AUL_SVC_RET_OK;
1011 return AUL_SVC_RET_OK;
1019 if (info->checksum) {
1020 g_free(info->checksum);
1021 info->checksum = NULL;
1024 __free_resolve_info_data(ri);
1029 static int __resolution_uri(resolution_info_t *info)
1031 aul_svc_resolve_info_t *ri = &info->ri;
1035 if (info->appid || info->list)
1036 return AUL_SVC_RET_OK;
1038 id = _svc_db_get_app(ri->op, ri->origin_mime, ri->uri, info->uid);
1041 return AUL_SVC_RET_OK;
1044 query = __make_query_with_collation(ri->op, ri->uri, ri->mime,
1045 ri->m_type, ri->s_type);
1046 query = _svc_db_query_builder_build(query);
1047 _svc_db_exec_query(query, &info->list, info->uid);
1048 FREE_AND_NULL(query);
1051 return AUL_SVC_RET_OK;
1053 __free_pkg_list(info->list);
1056 if (ri->uri_r_info) {
1057 query = __make_query(query, ri->op, ri->uri_r_info,
1058 ri->mime, ri->m_type, ri->s_type);
1061 query = __make_query(query, ri->op, ri->scheme, ri->mime,
1062 ri->m_type, ri->s_type);
1063 query = __make_query(query, ri->op, "*", ri->mime,
1064 ri->m_type, ri->s_type);
1065 if ((ri->scheme && strcmp(ri->scheme, "file") == 0) &&
1066 (ri->mime && strcmp(ri->mime, "NULL") != 0)) {
1067 query = __make_query(query, ri->op, "NULL", ri->mime,
1068 ri->m_type, ri->s_type);
1070 query = _svc_db_query_builder_build(query);
1071 _svc_db_exec_query(query, &info->list, info->uid);
1072 FREE_AND_NULL(query);
1075 __get_list_with_category(ri->category, &info->list, info->uid);
1076 __get_list_with_submode(ri->op, ri->win_id, &info->list, info->uid);
1078 if (g_slist_length(info->list) > 1)
1079 info->uri_r_info = ri->uri;
1081 return AUL_SVC_RET_OK;
1084 static int __resolution_scheme_and_host(resolution_info_t *info)
1086 aul_svc_resolve_info_t *ri = &info->ri;
1090 if (info->appid || info->list)
1091 return AUL_SVC_RET_OK;
1093 if (!ri->uri_r_info)
1094 return AUL_SVC_RET_OK;
1096 id = _svc_db_get_app(ri->op, ri->origin_mime, ri->uri_r_info,
1100 return AUL_SVC_RET_OK;
1103 query = __make_query(query, ri->op, ri->uri_r_info, ri->mime,
1104 ri->m_type, ri->s_type);
1105 query = _svc_db_query_builder_build(query);
1106 _svc_db_exec_query(query, &info->list, info->uid);
1107 FREE_AND_NULL(query);
1110 return AUL_SVC_RET_OK;
1112 __free_pkg_list(info->list);
1115 query = __make_query(query, ri->op, "*", ri->mime, ri->m_type,
1117 if ((ri->scheme && strcmp(ri->scheme, "file") == 0) &&
1118 (ri->mime && strcmp(ri->mime, "NULL") != 0)) {
1119 query = __make_query(query, ri->op, "NULL", ri->mime,
1120 ri->m_type, ri->s_type);
1122 query = _svc_db_query_builder_build(query);
1123 _svc_db_exec_query(query, &info->list, info->uid);
1124 FREE_AND_NULL(query);
1127 __get_list_with_category(ri->category, &info->list, info->uid);
1128 __get_list_with_submode(ri->op, ri->win_id, &info->list, info->uid);
1130 if (g_slist_length(info->list) > 1)
1131 info->uri_r_info = ri->uri_r_info;
1133 return AUL_SVC_RET_OK;
1136 static int __resolution_scheme(resolution_info_t *info)
1138 aul_svc_resolve_info_t *ri = &info->ri;
1142 if (info->appid || info->list)
1143 return AUL_SVC_RET_OK;
1145 id = _svc_db_get_app(ri->op, ri->origin_mime, ri->scheme, info->uid);
1148 return AUL_SVC_RET_OK;
1151 query = __make_query(query, ri->op, ri->scheme, ri->mime,
1152 ri->m_type, ri->s_type);
1153 query = __make_query(query, ri->op, "*", ri->mime,
1154 ri->m_type, ri->s_type);
1155 if ((ri->scheme && strcmp(ri->scheme, "file") == 0) &&
1156 (ri->mime && strcmp(ri->mime, "NULL") != 0)) {
1157 query = __make_query(query, ri->op, "NULL", ri->mime,
1158 ri->m_type, ri->s_type);
1160 query = _svc_db_query_builder_build(query);
1161 _svc_db_exec_query(query, &info->list, info->uid);
1162 FREE_AND_NULL(query);
1165 __get_list_with_category(ri->category, &info->list, info->uid);
1166 __get_list_with_submode(ri->op, ri->win_id, &info->list, info->uid);
1168 if (g_slist_length(info->list) > 1)
1169 info->uri_r_info = ri->scheme;
1171 return AUL_SVC_RET_OK;
1174 static int __resolution_post(resolution_info_t *info)
1176 int ret = AUL_SVC_RET_OK;
1180 __put_cache(info->checksum, info->appid, info->uid);
1184 count = g_slist_length(info->list);
1185 _D("count: %d", count);
1187 info->appid = strdup((const char *)info->list->data);
1188 if (info->appid == NULL) {
1189 _E("Out of memory");
1190 ret = AUL_SVC_RET_ERROR;
1193 __put_cache(info->checksum, info->appid, info->uid);
1194 } else if (count < 1) {
1195 __put_cache(info->checksum, "^", info->uid);
1196 ret = AUL_SVC_RET_ENOMATCH;
1198 bundle_add(info->b, AUL_SVC_K_URI_R_INFO, info->uri_r_info);
1199 __put_cache_with_info(info->checksum, info->uri_r_info,
1201 info->appid = strdup(APP_SELECTOR);
1202 if (info->appid == NULL) {
1203 _E("Out of memory");
1204 ret = AUL_SVC_RET_ERROR;
1209 __free_pkg_list(info->list);
1210 __free_resolve_info_data(&info->ri);
1211 g_free(info->checksum);
1215 static int __get_appid(bundle *b, uid_t uid, char **appid)
1217 static const resolution_handler handlers[] = {
1220 __resolution_scheme_and_host,
1221 __resolution_scheme,
1224 resolution_info_t info = { 0, };
1230 if (b == NULL || appid == NULL) {
1231 _E("Invalid parameter");
1232 return AUL_SVC_RET_EINVAL;
1235 op = (char *)aul_svc_get_operation(b);
1236 id = (char *)aul_svc_get_pkgname(b);
1239 aul_svc_set_operation(b, AUL_SVC_OPERATION_DEFAULT);
1240 *appid = strdup(id);
1241 if (*appid == NULL) {
1242 _E("Out of memory");
1243 return AUL_SVC_RET_ERROR;
1245 return AUL_SVC_RET_OK;
1248 if (TIZEN_FEATURE_SHARE_PANEL &&
1249 (op && (!strcmp(op, AUL_SVC_OPERATION_SHARE) ||
1250 !strcmp(op, AUL_SVC_OPERATION_MULTI_SHARE) ||
1251 !strcmp(op, AUL_SVC_OPERATION_SHARE_TEXT)))) {
1252 *appid = strdup(SHARE_PANEL);
1253 if (*appid == NULL) {
1254 _E("Out of memory");
1255 return AUL_SVC_RET_ERROR;
1257 return AUL_SVC_RET_OK;
1263 for (i = 0; i < ARRAY_SIZE(handlers); i++) {
1265 ret = handlers[i](&info);
1266 if (ret != AUL_SVC_RET_OK)
1271 *appid = info.appid;
1273 return AUL_SVC_RET_OK;
1276 static int __run_service(bundle *b, int request_code,
1277 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
1278 void *data, uid_t uid, bool sync)
1283 ret = __get_appid(b, uid, &appid);
1284 if (ret != AUL_SVC_RET_OK) {
1285 _E("Failed to get appid");
1289 ret = __run_svc_with_pkgname(appid, b, request_code,
1290 cbfunc, err_cb, data, uid, sync);
1296 API int aul_svc_run_service(bundle *b, int request_code,
1297 aul_svc_res_fn cbfunc, void *data)
1299 return __run_service(b, request_code, cbfunc, NULL, data,
1303 API int aul_svc_run_service_for_uid(bundle *b, int request_code,
1304 aul_svc_res_fn cbfunc, void *data, uid_t uid)
1306 return __run_service(b, request_code, cbfunc, NULL, data, uid, true);
1309 API int aul_svc_get_list(bundle *b, aul_svc_info_iter_fn iter_fn,
1312 return aul_svc_get_list_for_uid(b, iter_fn, data, getuid());
1315 API int aul_svc_get_list_for_uid(bundle *b, aul_svc_info_iter_fn iter_fn,
1316 void *data, uid_t uid)
1318 aul_svc_resolve_info_t info;
1319 char *pkgname = NULL;
1323 GSList *pkg_list = NULL;
1324 GSList *iter = NULL;
1326 char *query2 = NULL;
1329 _E("bundle is NULL");
1330 return AUL_SVC_RET_EINVAL;
1333 if (iter_fn == NULL) {
1334 _E("iter_fn is NULL");
1335 return AUL_SVC_RET_EINVAL;
1340 memset(&info, 0, sizeof(aul_svc_resolve_info_t));
1341 ret = __get_resolve_info(b, &info);
1343 __free_resolve_info_data(&info);
1347 _D("operation - %s / shceme - %s / mime - %s", info.op, info.scheme,
1350 query2 = __make_query_with_collation(info.op, info.uri,
1351 info.mime, info.m_type, info.s_type);
1353 if (info.uri_r_info) {
1354 query = __make_query(query, info.op, info.uri_r_info,
1355 info.mime, info.m_type, info.s_type);
1358 query = __make_query(query, info.op, info.scheme,
1359 info.mime, info.m_type, info.s_type);
1361 query = __make_query(query, info.op, "*",
1362 info.mime, info.m_type, info.s_type);
1364 if (info.scheme && (strcmp(info.scheme, "file") == 0)
1365 && info.mime && (strcmp(info.mime, "NULL") != 0)) {
1366 query = __make_query(query, info.op, "NULL",
1367 info.mime, info.m_type, info.s_type);
1370 query = _svc_db_query_builder_or(query2, query);
1371 query = _svc_db_query_builder_build(query);
1372 _svc_db_exec_query(query, &pkg_list, uid);
1379 __get_list_with_category(info.category, &pkg_list, uid);
1381 __get_list_with_submode(info.op, info.win_id, &pkg_list, uid);
1383 pkg_count = g_slist_length(pkg_list);
1384 if (pkg_count == 0) {
1385 _E("Cannot find associated application");
1387 __free_resolve_info_data(&info);
1388 return AUL_SVC_RET_ENOMATCH;
1391 for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
1392 pkgname = iter->data;
1393 SECURE_LOGD("PKGNAME : %s", pkgname);
1394 if (iter_fn(pkgname, data) != 0)
1399 g_slist_free(pkg_list);
1400 __free_resolve_info_data(&info);
1402 return AUL_SVC_RET_OK;
1405 API int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn, void *data)
1407 return aul_svc_get_all_defapps_for_uid(iter_fn, data, getuid());
1410 API int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
1411 void *data, uid_t uid)
1413 char *pkgname = NULL;
1416 GSList *pkg_list = NULL;
1417 GSList *iter = NULL;
1419 ret = _svc_db_get_list_with_all_defapps(&pkg_list, uid);
1423 for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
1424 pkgname = iter->data;
1425 if (iter_fn(pkgname, data) != 0)
1430 g_slist_free(pkg_list);
1432 return AUL_SVC_RET_OK;
1435 API const char *aul_svc_get_operation(bundle *b)
1437 return bundle_get_val(b, AUL_SVC_K_OPERATION);
1440 API const char *aul_svc_get_uri(bundle *b)
1442 return bundle_get_val(b, AUL_SVC_K_URI);
1445 API const char *aul_svc_get_mime(bundle *b)
1447 return bundle_get_val(b, AUL_SVC_K_MIME);
1450 API const char *aul_svc_get_data(bundle *b, const char *key)
1452 return bundle_get_val(b, key);
1455 API const char **aul_svc_get_data_array(bundle *b, const char *key, int *len)
1457 return bundle_get_str_array(b, key, len);
1460 API const char *aul_svc_get_pkgname(bundle *b)
1462 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
1465 API const char *aul_svc_get_appid(bundle *b)
1467 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
1470 API const char *aul_svc_get_category(bundle *b)
1472 return bundle_get_val(b, AUL_SVC_K_CATEGORY);
1475 API const char *aul_svc_get_launch_mode(bundle *b)
1477 return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
1480 API int aul_svc_create_result_bundle(bundle *inb, bundle **outb)
1484 if (inb == NULL || outb == NULL) {
1485 _E("bundle is NULL");
1486 return AUL_SVC_RET_EINVAL;
1489 ret = aul_create_result_bundle(inb, outb);
1491 /* add additional bundle */
1492 /* bundle_add(outb, " ", " "); */
1494 if (ret == AUL_R_OK)
1495 ret = AUL_SVC_RET_OK;
1496 else if (ret == AUL_R_EINVAL)
1497 ret = AUL_SVC_RET_EINVAL;
1498 else if (ret == AUL_R_ECANCELED)
1499 ret = AUL_SVC_RET_ECANCELED;
1501 ret = AUL_SVC_RET_ERROR;
1506 API int aul_svc_send_result(bundle *b, aul_svc_result_val result)
1509 char tmp[MAX_LOCAL_BUFSZ];
1512 _E("aul_svc_send_result is NULL");
1513 return AUL_SVC_RET_EINVAL;
1516 /* add result_code to bundle */
1517 snprintf(tmp, MAX_LOCAL_BUFSZ, "%d", (int)result);
1518 ret = __set_bundle(b, AUL_SVC_K_RES_VAL, tmp);
1520 return AUL_SVC_RET_ERROR;
1522 if (result == AUL_SVC_RES_CANCEL)
1523 ret = aul_send_result(b, 1);
1525 ret = aul_send_result(b, 0);
1527 /* remove result_code from bundle */
1528 bundle_del(b, AUL_SVC_K_RES_VAL);
1533 API int aul_svc_set_defapp(const char *op, const char *mime_type,
1534 const char *uri, const char *defapp)
1536 return aul_svc_set_defapp_for_uid(op, mime_type, uri, defapp, getuid());
1539 API int aul_svc_set_defapp_for_uid(const char *op, const char *mime_type,
1540 const char *uri, const char *defapp, uid_t uid)
1544 if (op == NULL || defapp == NULL)
1545 return AUL_SVC_RET_EINVAL;
1547 ret = _svc_db_add_app(op, mime_type, uri, defapp, uid);
1549 return AUL_SVC_RET_ERROR;
1551 return AUL_SVC_RET_OK;
1554 API int aul_svc_unset_defapp(const char *defapp)
1556 return aul_svc_unset_defapp_for_uid(defapp, getuid());
1559 API int aul_svc_unset_defapp_for_uid(const char *defapp, uid_t uid)
1564 return AUL_SVC_RET_EINVAL;
1566 ret = _svc_db_delete_with_pkgname(defapp, uid);
1569 return AUL_SVC_RET_ERROR;
1571 return AUL_SVC_RET_OK;
1574 API int aul_svc_unset_all_defapps()
1576 return aul_svc_unset_all_defapps_for_uid(getuid());
1579 API int aul_svc_unset_all_defapps_for_uid(uid_t uid)
1583 ret = _svc_db_delete_all(uid);
1586 return AUL_SVC_RET_ERROR;
1588 __invalidate_cache(uid);
1589 return AUL_SVC_RET_OK;
1592 API int aul_svc_is_defapp(const char *pkg_name)
1594 return aul_svc_is_defapp_for_uid(pkg_name, getuid());
1597 API int aul_svc_is_defapp_for_uid(const char *pkg_name, uid_t uid)
1599 return _svc_db_is_defapp(pkg_name, uid);
1602 API int aul_svc_data_is_array(bundle *b, const char *key)
1605 type = bundle_get_type(b, key);
1610 if (type & BUNDLE_TYPE_ARRAY)
1615 API int aul_svc_allow_transient_app(bundle *b, int wid)
1617 char win_id[MAX_LOCAL_BUFSZ];
1619 snprintf(win_id, MAX_LOCAL_BUFSZ, "%d", wid);
1622 _E("bundle is NULL");
1623 return AUL_SVC_RET_EINVAL;
1626 return __set_bundle(b, AUL_SVC_K_WIN_ID, win_id);
1629 API int aul_svc_request_transient_app(bundle *b, int callee_wid,
1630 aul_svc_host_res_fn cbfunc, void *data)
1635 API int aul_svc_subapp_terminate_request_pid(int pid)
1637 int cpid = getpid();
1642 aul_app_group_get_leader_pids(&lcnt, &lpids);
1643 for (i = 0; i < lcnt; i++) {
1644 if (lpids[i] == cpid) {
1648 aul_app_group_get_group_pids(cpid, &cnt, &pids);
1655 return aul_subapp_terminate_request_pid(pid);
1667 return aul_app_group_clear_top();
1670 API int aul_send_service_result(bundle *b)
1672 return aul_send_result(b, 0);
1675 API int aul_svc_subscribe_launch_result(bundle *b, const char *result)
1678 _E("bundle is NULL");
1679 return AUL_SVC_RET_EINVAL;
1682 return __set_bundle(b, result, "1");
1685 API int aul_svc_set_loader_id(bundle *b, int loader_id)
1687 char tmp[MAX_LOCAL_BUFSZ];
1690 _E("bundle is NULL");
1691 return AUL_SVC_RET_EINVAL;
1694 if (loader_id <= 0) {
1695 _E("invalid loader id");
1696 return AUL_SVC_RET_EINVAL;
1699 snprintf(tmp, sizeof(tmp), "%d", loader_id);
1700 return __set_bundle(b, AUL_K_LOADER_ID, tmp);
1703 API int aul_svc_set_loader_name(bundle *b, const char *loader_name)
1706 _E("bundle is NULL");
1707 return AUL_SVC_RET_EINVAL;
1711 _E("invalid loader name");
1712 return AUL_SVC_RET_EINVAL;
1715 return __set_bundle(b, AUL_K_LOADER_NAME, loader_name);
1718 API int aul_svc_set_background_launch(bundle *b, int enabled)
1721 return AUL_R_EINVAL;
1723 if (bundle_get_type(b, AUL_SVC_K_BG_LAUNCH) != BUNDLE_TYPE_NONE)
1724 bundle_del(b, AUL_SVC_K_BG_LAUNCH);
1727 bundle_add_str(b, AUL_SVC_K_BG_LAUNCH, "enable");
1732 API int aul_svc_set_alias_appid(const char *alias_appid, const char *appid)
1734 return aul_svc_set_alias_appid_for_uid(alias_appid, appid, getuid());
1737 API int aul_svc_set_alias_appid_for_uid(const char *alias_appid,
1738 const char *appid, uid_t uid)
1742 ret = _svc_db_add_alias_appid(alias_appid, appid, uid);
1744 return AUL_SVC_RET_ERROR;
1746 return AUL_SVC_RET_OK;
1749 API int aul_svc_unset_alias_appid(const char *alias_appid)
1751 return aul_svc_unset_alias_appid_for_uid(alias_appid, getuid());
1754 API int aul_svc_unset_alias_appid_for_uid(const char *alias_appid, uid_t uid)
1758 ret = _svc_db_delete_alias_appid(alias_appid, uid);
1760 return AUL_SVC_RET_ERROR;
1762 return AUL_SVC_RET_OK;
1765 API int aul_svc_foreach_alias_info(void (*callback)(const char *alias_appid,
1766 const char *appid, void *data), void *user_data)
1768 return aul_svc_foreach_alias_info_for_uid(callback, getuid(),
1772 API int aul_svc_foreach_alias_info_for_uid(void (*callback)(
1773 const char *alias_appid, const char *appid,
1774 void *data), uid_t uid, void *user_data)
1778 if (callback == NULL) {
1779 _E("Invalid parameter");
1780 return AUL_SVC_RET_EINVAL;
1783 ret = _svc_db_foreach_alias_info(callback, uid, user_data);
1785 return AUL_SVC_RET_ERROR;
1787 return AUL_SVC_RET_OK;
1790 API int aul_svc_enable_alias_info(const char *appid)
1792 return aul_svc_enable_alias_info_for_uid(appid, getuid());
1795 API int aul_svc_enable_alias_info_for_uid(const char *appid, uid_t uid)
1799 ret = _svc_db_enable_alias_info(appid, uid);
1801 return AUL_SVC_RET_ERROR;
1803 return AUL_SVC_RET_OK;
1806 API int aul_svc_disable_alias_info(const char *appid)
1808 return aul_svc_disable_alias_info_for_uid(appid, getuid());
1811 API int aul_svc_disable_alias_info_for_uid(const char *appid, uid_t uid)
1815 ret = _svc_db_disable_alias_info(appid, uid);
1817 return AUL_SVC_RET_ERROR;
1819 return AUL_SVC_RET_OK;
1822 API int aul_svc_get_appid_by_alias_appid(const char *alias_appid, char **appid)
1824 return aul_svc_get_appid_by_alias_appid_for_uid(alias_appid,
1828 API int aul_svc_get_appid_by_alias_appid_for_uid(const char *alias_appid,
1829 char **appid, uid_t uid)
1833 ret = _svc_db_get_appid_from_alias_info(alias_appid, appid, uid);
1835 return AUL_SVC_RET_ERROR;
1837 return AUL_SVC_RET_OK;
1840 API int aul_svc_foreach_alias_info_by_appid(int (*callback)(
1841 const char *alias_appid, const char *appid, void *data),
1842 const char *appid, void *user_data)
1844 return aul_svc_foreach_alias_info_by_appid_for_uid(callback, appid,
1845 getuid(), user_data);
1848 API int aul_svc_foreach_alias_info_by_appid_for_uid(int (*callback)(
1849 const char *alias_appid, const char *appid, void *data),
1850 const char *appid, uid_t uid, void *user_data)
1854 if (callback == NULL || appid == NULL) {
1855 _E("Invalid parameter");
1856 return AUL_SVC_RET_EINVAL;
1859 ret = _svc_db_foreach_alias_info_by_appid(callback, appid,
1862 return AUL_SVC_RET_ERROR;
1864 return AUL_SVC_RET_OK;
1867 API int aul_svc_foreach_allowed_info(int (*callback)(const char *appid,
1868 const char *allowed_appid, void *data), void *user_data)
1870 return aul_svc_foreach_allowed_info_for_uid(callback,
1871 getuid(), user_data);
1874 API int aul_svc_foreach_allowed_info_for_uid(int (*callback)(const char *appid,
1875 const char *allowed_appid, void *data),
1876 uid_t uid, void *user_data)
1880 if (callback == NULL) {
1881 _E("Invalid parameter");
1882 return AUL_SVC_RET_EINVAL;
1885 ret = _svc_db_foreach_allowed_info(callback, uid, user_data);
1887 return AUL_SVC_RET_ERROR;
1889 return AUL_SVC_RET_OK;
1892 API int aul_svc_foreach_allowed_info_by_appid(int (*callback)(
1893 const char *appid, const char *allowed_appid, void *data),
1894 const char *appid, void *user_data)
1896 return aul_svc_foreach_allowed_info_by_appid_for_uid(callback,
1897 appid, getuid(), user_data);
1900 API int aul_svc_foreach_allowed_info_by_appid_for_uid(int (*callback)(
1901 const char *appid, const char *allowed_appid, void *data),
1902 const char *appid, uid_t uid, void *user_data)
1906 if (callback == NULL || appid == NULL) {
1907 _E("Invalid parameter");
1908 return AUL_SVC_RET_EINVAL;
1911 ret = _svc_db_foreach_allowed_info_by_appid(callback, appid,
1914 return AUL_SVC_RET_ERROR;
1916 return AUL_SVC_RET_OK;
1919 API const char *aul_svc_get_instance_id(bundle *b)
1921 return bundle_get_val(b, AUL_K_INSTANCE_ID);
1924 API int aul_svc_set_instance_id(bundle *b, const char *instance_id)
1926 if (b == NULL || instance_id == NULL) {
1927 _E("Invalid parameter");
1928 return AUL_SVC_RET_EINVAL;
1931 return __set_bundle(b, AUL_K_INSTANCE_ID, instance_id);
1934 API int aul_svc_run_service_async(bundle *b, int request_code,
1935 aul_svc_res_fn cbfunc, void *data)
1937 return __run_service(b, request_code, cbfunc, NULL, data,
1941 API int aul_svc_run_service_async_for_uid(bundle *b, int request_code,
1942 aul_svc_res_fn cbfunc, void *data, uid_t uid)
1944 return __run_service(b, request_code, cbfunc, NULL, data, uid, false);
1947 API int aul_svc_send_launch_request(bundle *b, int request_code,
1948 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
1951 return aul_svc_send_launch_request_for_uid(b, request_code,
1952 cbfunc, err_cb, user_data, getuid());
1955 API int aul_svc_send_launch_request_for_uid(bundle *b, int request_code,
1956 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
1957 void *user_data, uid_t uid)
1959 return __run_service(b, request_code, cbfunc, err_cb, user_data,
1963 API int aul_svc_send_launch_request_sync_for_uid(bundle *b, int request_code,
1964 bundle **res_b, aul_svc_result_val *res, uid_t uid)
1966 char *pkgname = NULL;
1971 ret = __get_appid(b, uid, &appid);
1972 if (ret != AUL_SVC_RET_OK) {
1973 _E("Failed to find appid");
1978 __verify_request(b, &pkgname);
1980 ret = aul_send_launch_request_sync_for_uid(pkgname, b, uid, res_b);
1982 val = bundle_get_val(*res_b, AUL_SVC_K_RES_VAL);
1983 *res = (val == NULL) ? AUL_SVC_RES_NOT_OK : atoi(val);
1985 ret = __error_convert(ret);
1986 *res = AUL_SVC_RES_CANCEL;
1993 API int aul_svc_info_create(bundle *b, aul_svc_info_h *h)
1995 aul_svc_resolve_info_t *info;
1999 _E("Invalid parameter");
2000 return AUL_SVC_RET_EINVAL;
2003 info = calloc(1, sizeof(aul_svc_resolve_info_t));
2005 _E("Out of memory");
2006 return AUL_SVC_RET_ERROR;
2009 r = __get_resolve_info(b, info);
2011 _E("Failed to get resolving info");
2012 __free_resolve_info_data(info);
2019 return AUL_SVC_RET_OK;
2022 API int aul_svc_info_get_operation(aul_svc_info_h h, char **operation)
2024 aul_svc_resolve_info_t *info;
2026 if (!h || !operation) {
2027 _E("Invalid parameter");
2028 return AUL_SVC_RET_EINVAL;
2031 info = (aul_svc_resolve_info_t *)h;
2032 *operation = strdup(info->op ? info->op : "NULL");
2033 if (*operation == NULL) {
2034 _E("Failed to duplicate operation");
2035 return AUL_SVC_RET_ERROR;
2038 return AUL_SVC_RET_OK;
2041 API int aul_svc_info_get_uri(aul_svc_info_h h, char **uri)
2043 aul_svc_resolve_info_t *info;
2046 _E("Invalid parameter");
2047 return AUL_SVC_RET_EINVAL;
2050 info = (aul_svc_resolve_info_t *)h;
2051 *uri = strdup(info->uri ? info->uri : "NULL");
2053 _E("Failed to duplicate URI");
2054 return AUL_SVC_RET_ERROR;
2057 return AUL_SVC_RET_OK;
2060 API int aul_svc_info_get_uri_scheme(aul_svc_info_h h, char **uri_scheme)
2062 aul_svc_resolve_info_t *info;
2064 if (!h || !uri_scheme) {
2065 _E("Invalid parameter");
2066 return AUL_SVC_RET_EINVAL;
2069 info = (aul_svc_resolve_info_t *)h;
2070 *uri_scheme = strdup(info->scheme ? info->scheme : "NULL");
2071 if (*uri_scheme == NULL) {
2072 _E("Failed to duplicate URI scheme");
2073 return AUL_SVC_RET_ERROR;
2076 return AUL_SVC_RET_OK;
2079 API int aul_svc_info_get_uri_host(aul_svc_info_h h, char **uri_host)
2081 aul_svc_resolve_info_t *info;
2083 if (!h || !uri_host) {
2084 _E("Invalid parameter");
2085 return AUL_SVC_RET_EINVAL;
2088 info = (aul_svc_resolve_info_t *)h;
2089 *uri_host = strdup(info->host ? info->host : "NULL");
2090 if (*uri_host == NULL) {
2091 _E("Failed to duplicate URI host");
2092 return AUL_SVC_RET_ERROR;
2095 return AUL_SVC_RET_OK;
2098 API int aul_svc_info_get_mime(aul_svc_info_h h, char **mime)
2100 aul_svc_resolve_info_t *info;
2103 _E("Invalid parameter");
2104 return AUL_SVC_RET_EINVAL;
2107 info = (aul_svc_resolve_info_t *)h;
2108 *mime = strdup(info->mime ? info->mime : "NULL");
2109 if (*mime == NULL) {
2110 _E("Failed to duplicate MIME-Type");
2111 return AUL_SVC_RET_ERROR;
2114 return AUL_SVC_RET_OK;
2117 API int aul_svc_info_get_mime_type(aul_svc_info_h h, char **mime_type)
2119 aul_svc_resolve_info_t *info;
2121 if (!h || !mime_type) {
2122 _E("Invalid parameter");
2123 return AUL_SVC_RET_EINVAL;
2126 info = (aul_svc_resolve_info_t *)h;
2127 *mime_type = strdup(info->m_type ? info->m_type : "NULL");
2128 if (*mime_type == NULL) {
2129 _E("Failed to duplicate the type of MIME-Type");
2130 return AUL_SVC_RET_ERROR;
2133 return AUL_SVC_RET_OK;
2136 API int aul_svc_info_get_mime_subtype(aul_svc_info_h h, char **mime_subtype)
2138 aul_svc_resolve_info_t *info;
2140 if (!h || !mime_subtype) {
2141 _E("Invalid parameter");
2142 return AUL_SVC_RET_EINVAL;
2145 info = (aul_svc_resolve_info_t *)h;
2146 *mime_subtype = strdup(info->s_type ? info->s_type : "NULL");
2147 if (*mime_subtype == NULL) {
2148 _E("Failed to duplicate the subtype of MIME-Type");
2149 return AUL_SVC_RET_ERROR;
2152 return AUL_SVC_RET_OK;
2155 API int aul_svc_info_destroy(aul_svc_info_h h)
2157 aul_svc_resolve_info_t *info;
2160 _E("Invalid parameter");
2161 return AUL_SVC_RET_EINVAL;
2164 info = (aul_svc_resolve_info_t *)h;
2165 __free_resolve_info_data(info);
2168 return AUL_SVC_RET_OK;
2171 API int aul_svc_set_caller_instance_id(bundle *b, const char *instance_id)
2174 _E("Invalid parameter");
2175 return AUL_SVC_RET_EINVAL;
2178 return __set_bundle(b, AUL_K_CALLER_INSTANCE_ID, instance_id);
2181 API int aul_svc_set_comp_id(bundle *b, const char *comp_id)
2184 _E("Invalid parameter");
2185 return AUL_SVC_RET_EINVAL;
2188 return __set_bundle(b, AUL_K_COMPONENT_ID, comp_id);
2191 API const char *aul_svc_get_comp_id(bundle *b)
2193 return bundle_get_val(b, AUL_K_COMPONENT_ID);
2196 static void __foreach_group_info(aul_app_group_info_h info, void *data)
2198 int *cnt = (int *)data;
2203 API int aul_svc_subapp_terminate_request(bundle *b, int pid)
2205 const char *caller_inst_id;
2206 const char *inst_id;
2207 char buf[512] = { 0, };
2211 if (!b || pid < 0) {
2212 _E("Invalid parameter");
2213 return AUL_SVC_RET_EINVAL;
2216 inst_id = bundle_get_val(b, AUL_K_INSTANCE_ID);
2218 _E("Invalid request");
2219 return AUL_SVC_RET_EINVAL;
2222 caller_inst_id = bundle_get_val(b, AUL_K_CALLER_INSTANCE_ID);
2223 if (!caller_inst_id) {
2224 ret = aul_app_get_instance_id_bypid(getpid(), buf, sizeof(buf));
2225 if (ret != AUL_R_OK) {
2226 _E("Failed to get caller instance ID");
2227 return AUL_SVC_RET_ERROR;
2229 caller_inst_id = buf;
2232 aul_app_group_foreach_group_info(caller_inst_id,
2233 __foreach_group_info, (void *)&cnt);
2235 return aul_subapp_terminate_request(inst_id, pid);
2237 return aul_app_group_clear_top();