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.
23 #include <sys/types.h>
31 #include "aul_service.h"
35 #include "menu_db_util.h"
36 #include "simple_util.h"
38 static int __get_defapp_from_desktop(const char *svcname,
39 char *defapp, int len);
43 SLPAPI int aul_set_defapp_for_service(const char *svcname, const char *defapp)
45 if ((svcname == NULL) || (defapp == NULL))
48 if (!is_supported_svc(svcname))
51 if (svc_add_app(svcname, defapp) < 0) {
59 static ail_cb_ret_e __defapp_with_service_func(
60 const ail_appinfo_h appinfo, void *user_data)
62 char **package = (char **)user_data;
65 ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &str);
67 _D("defapp from desktop = %s", str);
69 *package = strdup(str);
71 return AIL_CB_RET_CANCEL; /*return AIL_CB_RET_CONTINUE;*/
75 static int __get_defapp_from_desktop(const char *svcname, char *defapp, int len)
83 _D("The svcname is: %s", svcname);
85 ail_ret = ail_filter_new(&filter);
86 if (ail_ret != AIL_ERROR_OK)
89 ail_ret = ail_filter_add_str(filter, AIL_PROP_X_SLP_SERVICE_STR, svcname);
90 if (ail_ret != AIL_ERROR_OK) {
91 _E("ail_filter_add_str failed");
95 ail_filter_count_appinfo(filter, &pkg_count);
98 /* TODO: Prioritizing inhouse app depending on the UX policy */
100 ail_filter_list_appinfo_foreach(filter,
101 __defapp_with_service_func, (void *)&pkgname);
104 strncpy(defapp,pkgname,len);
105 _D("defapp from desktop = %s", defapp);
106 aul_set_defapp_for_service(svcname, defapp);
114 if (ail_filter_destroy(filter) != AIL_ERROR_OK)
115 _E("ail_filter_destroy failed");
119 SLPAPI int aul_get_defapp_for_service(const char *svcname, char *defapp,
124 if ((svcname == NULL) || (defapp == NULL) || len <= 0)
127 if (!is_supported_svc(svcname))
131 if ((res = svc_get_app(svcname)) != NULL) {
132 snprintf(defapp, len, "%s", res);
134 _D("Found %s for %s from svc db", defapp, svcname);
138 if (__get_defapp_from_desktop(svcname, defapp, len) < 0)
144 SLPAPI int aul_open_service(const char *svcname, bundle *kb,
145 aul_service_res_fn cbfunc, void *userdata)
147 char defapp[MAX_LOCAL_BUFSZ];
149 int ret = AUL_R_ERROR;
150 ail_appinfo_h handle;
156 if (!is_supported_svc(svcname))
160 kb = bundle_create();
163 bundle_add(kb, AUL_K_SERVICE_NAME, svcname);
166 if (aul_get_defapp_for_service(svcname, defapp, sizeof(defapp)) < 0) {
167 _D("service : %s, no default app", svcname);
174 ail_ret = ail_package_get_appinfo(defapp, &handle);
176 if (ail_ret == AIL_ERROR_OK) {
177 ail_package_destroy_appinfo(handle);
178 _D("svcname: %s, defapp : %s", svcname, defapp);
181 _D("svcname: %s, defapp : %s - with result",
184 aul_launch_app_with_result(defapp, kb,
188 _D("svcname: %s, defapp : %s - no result",
190 ret = aul_launch_app(defapp, kb);
192 } else if (ail_ret == AIL_ERROR_NO_DATA) {
193 _D("defapp %s for svcname: %s does NOT exist", defapp,
195 svc_delete_with_pkgname(defapp);
196 ail_package_destroy_appinfo(handle);
199 _E("ail_package_get_appinfo with %s failed", defapp);
214 SLPAPI int aul_send_service_result(bundle *b)
216 return aul_send_result(b, 0);