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"
39 static int __get_defapp_from_desktop(const char *svcname,
40 char *defapp, int len);
44 SLPAPI int aul_set_defapp_for_service(const char *svcname, const char *defapp)
46 if ((svcname == NULL) || (defapp == NULL))
49 if (!is_supported_svc(svcname))
52 if (svc_add_app(svcname, defapp) < 0) {
60 static ail_cb_ret_e __defapp_with_service_func(
61 const ail_appinfo_h appinfo, void *user_data)
63 char **package = (char **)user_data;
66 ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &str);
68 _D("defapp from desktop = %s", str);
70 *package = strdup(str);
72 return AIL_CB_RET_CANCEL; /*return AIL_CB_RET_CONTINUE;*/
76 static int __get_defapp_from_desktop(const char *svcname, char *defapp, int len)
84 _D("The svcname is: %s", svcname);
86 ail_ret = ail_filter_new(&filter);
87 if (ail_ret != AIL_ERROR_OK)
90 ail_ret = ail_filter_add_str(filter, AIL_PROP_X_SLP_SERVICE_STR, svcname);
91 if (ail_ret != AIL_ERROR_OK) {
92 _E("ail_filter_add_str failed");
96 ail_filter_count_appinfo(filter, &pkg_count);
99 /* TODO: Prioritizing inhouse app depending on the UX policy */
100 if (pkg_count == 1) {
101 ail_filter_list_appinfo_foreach(filter,
102 __defapp_with_service_func, (void *)&pkgname);
105 strncpy(defapp,pkgname,len);
106 _D("defapp from desktop = %s", defapp);
107 aul_set_defapp_for_service(svcname, defapp);
115 if (ail_filter_destroy(filter) != AIL_ERROR_OK)
116 _E("ail_filter_destroy failed");
120 SLPAPI int aul_get_defapp_for_service(const char *svcname, char *defapp,
125 if ((svcname == NULL) || (defapp == NULL) || len <= 0)
128 if (!is_supported_svc(svcname))
132 if ((res = svc_get_app(svcname)) != NULL) {
133 snprintf(defapp, len, "%s", res);
135 _D("Found %s for %s from svc db", defapp, svcname);
139 if (__get_defapp_from_desktop(svcname, defapp, len) < 0)
145 SLPAPI int aul_open_service(const char *svcname, bundle *kb,
146 aul_service_res_fn cbfunc, void *userdata)
148 char defapp[MAX_LOCAL_BUFSZ];
150 int ret = AUL_R_ERROR;
151 ail_appinfo_h handle;
157 if (!is_supported_svc(svcname))
161 kb = bundle_create();
164 bundle_add(kb, AUL_K_SERVICE_NAME, svcname);
167 if (aul_get_defapp_for_service(svcname, defapp, sizeof(defapp)) < 0) {
168 _D("service : %s, no default app", svcname);
175 ail_ret = ail_package_get_appinfo(defapp, &handle);
177 if (ail_ret == AIL_ERROR_OK) {
178 ail_destroy_appinfo(handle);
179 _D("svcname: %s, defapp : %s", svcname, defapp);
182 _D("svcname: %s, defapp : %s - with result",
185 aul_launch_app_with_result(defapp, kb,
189 _D("svcname: %s, defapp : %s - no result",
191 ret = aul_launch_app(defapp, kb);
193 } else if (ail_ret == AIL_ERROR_NO_DATA) {
194 _D("defapp %s for svcname: %s does NOT exist", defapp,
196 svc_delete_with_pkgname(defapp);
197 ail_destroy_appinfo(handle);
200 _E("ail_get_appinfo with %s failed", defapp);
215 SLPAPI int aul_send_service_result(bundle *b)
217 return aul_send_result(b, 0);