2 * Copyright (c) 2021 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 <bundle_cpp.h>
19 #include <bundle_internal.h>
22 #include <iniparser.h>
27 #include <sys/types.h>
34 #include "aul/app_control/resolve_info.hh"
35 #include "include/aul.h"
36 #include "include/aul_app_group.h"
37 #include "include/aul_error.h"
38 #include "include/aul_sock.h"
39 #include "include/aul_svc.h"
40 #include "include/aul_svc_internal.h"
41 #include "src/aul_api.h"
42 #include "src/aul_svc_priv_key.h"
43 #include "src/aul_util.h"
44 #include "src/launch.h"
46 #undef MAX_MIME_STR_SIZE
47 #define MAX_MIME_STR_SIZE 256
49 #undef MAX_SCHEME_STR_SIZE
50 #define MAX_SCHEME_STR_SIZE 256
52 #undef MAX_HOST_STR_SIZE
53 #define MAX_HOST_STR_SIZE 256
55 #undef DEPRECATION_WARNING
56 #define DEPRECATION_WARNING() do { \
57 dlog_print(DLOG_WARN, LOG_TAG, \
58 "DEPRECATION WARNING: %s() is deprecated and " \
59 "will be removed from next release.", __FUNCTION__); \
64 constexpr const char kPathAmdReady[] = "/run/.amd_ready";
65 constexpr const char kPathLibAulServer[] = LIBDIR "/libaul-server.so.0";
66 constexpr const char kAulServiceForeachUsrAliasInfo[] =
67 "aul_service_foreach_usr_alias_info";
71 CbInfo(int request_code, aul_svc_res_fn res_fn,
72 aul_svc_err_cb err_cb, void* user_data)
73 : request_code_(request_code),
76 user_data_(user_data) {
80 aul_svc_res_fn res_fn_;
81 aul_svc_err_cb err_cb_;
87 explicit AliasInfo(std::string alias_appid)
88 : alias_appid_(std::move(alias_appid)) {
91 std::string alias_appid_;
95 int SetBundle(bundle* b, const char* key, const char* value) {
96 if (bundle_get_type(b, key) != BUNDLE_TYPE_NONE) {
97 if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
98 return AUL_SVC_RET_ERROR;
101 if (value == nullptr)
102 return AUL_SVC_RET_EINVAL;
104 if (bundle_add(b, key, value) != BUNDLE_ERROR_NONE)
105 return AUL_SVC_RET_ERROR;
107 SECURE_LOGD("key(%s), value(%s)", key, value);
108 return AUL_SVC_RET_OK;
111 int SetBundleArray(bundle* b, const char* key, const char** value,
113 int is_array = aul_svc_data_is_array(b, key);
115 if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
116 return AUL_SVC_RET_ERROR;
119 if (value == nullptr)
120 return AUL_SVC_RET_EINVAL;
122 if (bundle_add_str_array(b, key, value, len) != BUNDLE_ERROR_NONE)
123 return AUL_SVC_RET_ERROR;
125 SECURE_LOGD("key(%s), length(%d)", key, len);
126 return AUL_SVC_RET_OK;
129 std::string GetAliasAppId(const char* appid) {
130 dictionary* dic = iniparser_load("/usr/share/appsvc/alias.ini");
134 auto dic_ptr = std::unique_ptr<dictionary, decltype(iniparser_freedict)*>(
135 dic, iniparser_freedict);
137 std::string key = std::string("Alias:") + appid;
138 const char* value = iniparser_getstring(dic, key.c_str(), nullptr);
139 SECURE_LOGD("appid(%s), alias_id(%s)", appid, value);
140 if (value == nullptr)
143 return std::string(value);
146 bool IsSpecialApp(const char* appid) {
147 if (!strcmp(appid, APP_SELECTOR) || !strcmp(appid, SHARE_PANEL))
153 bool IsSpecialOperation(const char* operation) {
154 if (operation == nullptr)
157 int ret = strcmp(operation,
158 "http://tizen.org/appcontrol/operation/guide_privacy_setting");
165 std::string GetAppId(bundle* request) {
166 const char* appid = aul_svc_get_pkgname(request);
167 if (appid == nullptr) {
168 if (aul_svc_get_operation(request) == nullptr) {
169 _E("Invalid request");
176 int ret = bundle_get_type(request, AUL_SVC_K_SELECTOR_EXTRA_LIST);
177 if (ret != BUNDLE_TYPE_NONE) {
178 if (appid == nullptr || !strcmp(appid, "@UNKNOWN"))
179 appid = APP_SELECTOR;
182 ret = bundle_get_type(request, AUL_K_FORCE_LAUNCH_APP_SELECTOR);
183 if (ret != BUNDLE_TYPE_NONE)
184 appid = APP_SELECTOR;
186 return std::string(appid);
189 void SetLaunchData(bundle* request, const std::string& appid) {
190 const char* operation = aul_svc_get_operation(request);
191 if (operation == nullptr)
192 aul_svc_set_operation(request, AUL_SVC_OPERATION_DEFAULT);
194 if (IsSpecialApp(appid.c_str()) || IsSpecialOperation(operation)) {
195 SetBundle(request, AUL_SVC_K_CAN_BE_LEADER, "true");
196 SetBundle(request, AUL_SVC_K_REROUTE, "true");
197 SetBundle(request, AUL_SVC_K_RECYCLE, "true");
200 const char* launch_mode = aul_svc_get_launch_mode(request);
201 if (launch_mode && !strcmp(launch_mode, "group")) {
202 int ret = bundle_get_type(request, AUL_K_INSTANCE_ID);
203 if (ret == BUNDLE_TYPE_NONE)
204 aul_set_instance_info(appid.c_str(), request);
208 int AulErrorConvert(int res) {
211 return AUL_SVC_RET_EILLACC;
213 return AUL_SVC_RET_EINVAL;
214 case AUL_R_ETERMINATING:
215 return AUL_SVC_RET_ETERMINATING;
216 case AUL_R_EREJECTED:
217 return AUL_SVC_RET_EREJECTED;
219 return AUL_SVC_RET_ENOMATCH;
220 case AUL_R_ECANCELED:
221 return AUL_SVC_RET_ECANCELED;
223 return AUL_SVC_RET_ETIMEOUT;
225 return AUL_SVC_RET_ELAUNCH;
229 void LaunchWithResultCb(bundle* b, int is_cancel, void* data) {
232 res = AUL_SVC_RES_CANCEL;
234 const char* val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
235 res = (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val);
238 bundle_del(b, AUL_SVC_K_RES_VAL);
239 auto* cb_info = static_cast<CbInfo*>(data);
240 if (cb_info == nullptr) {
241 _E("Invalid parameter");
245 if (cb_info->res_fn_) {
246 cb_info->res_fn_(b, cb_info->request_code_,
247 static_cast<aul_svc_result_val>(res), cb_info->user_data_);
248 cb_info->res_fn_ = nullptr;
251 if (cb_info->err_cb_ != nullptr)
257 void ErrorCb(int error, void* data) {
259 error = AulErrorConvert(error);
261 auto* cb_info = static_cast<CbInfo*>(data);
262 if (cb_info == nullptr) {
263 _E("Invalid parameter");
267 if (cb_info->err_cb_) {
268 cb_info->err_cb_(cb_info->request_code_, error, cb_info->user_data_);
269 cb_info->err_cb_ = nullptr;
272 if (cb_info->res_fn_)
278 using SendLaunchRequestCb =
279 int (*)(const std::string&, bundle*, uid_t, CbInfo*);
280 using SendLaunchRequestSyncCb =
281 int (*)(const std::string&, bundle*, uid_t, bundle**);
283 template <typename T, typename A>
284 int SendLaunchRequest(T cb, bundle* request, uid_t uid, A arg) {
285 if (request == nullptr) {
286 _E("Invalid parameter");
287 return AUL_SVC_RET_EINVAL;
290 std::string appid = GetAppId(request);
292 _E("GetAppId() is failed");
293 return AUL_SVC_RET_EINVAL;
296 SetLaunchData(request, appid);
297 return cb(appid, request, uid, arg);
300 int SendAndReceive(int cmd, uid_t uid, bundle* request, bundle** response) {
301 int fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, cmd, request,
304 return AUL_SVC_RET_ERROR;
306 app_pkt_t* pkt = nullptr;
307 int ret = aul_sock_recv_reply_pkt(fd, &pkt);
309 _E("Failed to receive reply packet. error(%d)", ret);
310 return AUL_SVC_RET_ERROR;
313 auto ptr = std::unique_ptr<app_pkt_t, decltype(std::free)*>(pkt, std::free);
314 if (pkt->cmd != APP_GET_INFO_OK && pkt->cmd != cmd) {
315 if (pkt->cmd == APP_GET_INFO_ERROR)
316 return AUL_SVC_RET_ERROR;
318 return AulErrorConvert(aul_error_convert(pkt->cmd));
322 if (pkt->opt & AUL_SOCK_BUNDLE) {
323 b = bundle_decode(pkt->data, pkt->len);
325 _E("bundle_decode() is failed");
326 return AUL_SVC_RET_ENOMEM;
329 _E("Invalid packet");
330 return AUL_SVC_RET_ERROR;
334 return AUL_SVC_RET_OK;
337 std::atomic<bool> amd_ready { false };
342 if (access(kPathAmdReady, F_OK) == 0) {
343 amd_ready.exchange(true);
350 using AulServiceAliasInfoCb =
351 bool (*)(const char*, const char*, void*);
352 using AulServiceForeachUsrAliasInfoFunc =
353 int (*)(AulServiceAliasInfoCb, uid_t, void*);
355 int GetAppIdByAliasAppIdFromDB(const char* alias_appid, char** app_id,
357 void* handle = dlopen(kPathLibAulServer, RTLD_LAZY | RTLD_GLOBAL);
358 if (handle == nullptr) {
359 _E("dlopen() is failed. path(%s), error(%s)", kPathLibAulServer, dlerror());
360 return AUL_SVC_RET_ERROR;
363 auto dl_closer = [](void* ptr) {
367 std::unique_ptr<void, decltype(dl_closer)> handle_auto(handle, dl_closer);
368 auto* func = reinterpret_cast<AulServiceForeachUsrAliasInfoFunc>(
369 dlsym(handle, kAulServiceForeachUsrAliasInfo));
370 if (func == nullptr) {
371 _E("dlsym() is failed. error(%s)", dlerror());
372 return AUL_SVC_RET_ERROR;
375 AliasInfo info(alias_appid);
377 [](const char* alias_appid, const char* appid, void* user_data) -> bool {
378 auto* info = static_cast<AliasInfo*>(user_data);
379 if (info->alias_appid_ == alias_appid) {
380 info->appid_ = appid;
387 _E("%s() is failed. error(%d)", kAulServiceForeachUsrAliasInfo, ret);
388 return AUL_SVC_RET_ERROR;
391 if (info.appid_.empty())
392 return AUL_SVC_RET_ERROR;
394 *app_id = strdup(info.appid_.c_str());
395 if (*app_id == nullptr) {
396 _E("strdup() is failed");
397 return AUL_SVC_RET_ENOMEM;
400 return AUL_SVC_RET_OK;
405 extern "C" API int aul_svc_set_operation(bundle* b, const char* operation) {
407 _E("Invalid parameter");
408 return AUL_SVC_RET_EINVAL;
411 return ::SetBundle(b, AUL_SVC_K_OPERATION, operation);
414 extern "C" API int aul_svc_set_uri(bundle* b, const char* uri) {
416 _E("Invalid parameter");
417 return AUL_SVC_RET_EINVAL;
420 return ::SetBundle(b, AUL_SVC_K_URI, uri);
423 extern "C" API int aul_svc_set_mime(bundle* b, const char* mime) {
425 _E("Invalid parameter");
426 return AUL_SVC_RET_EINVAL;
429 return ::SetBundle(b, AUL_SVC_K_MIME, mime);
432 extern "C" API int aul_svc_add_data(bundle* b, const char* key,
434 if (b == nullptr || key == nullptr)
435 return AUL_SVC_RET_EINVAL;
437 return ::SetBundle(b, key, value);
440 extern "C" API int aul_svc_add_data_array(bundle* b, const char* key,
441 const char** value, int len) {
442 if (b == nullptr || key == nullptr)
443 return AUL_SVC_RET_EINVAL;
445 return ::SetBundleArray(b, key, value, len);
448 extern "C" API int aul_svc_set_pkgname(bundle* b, const char* pkg_name) {
450 _E("Invalid parameter");
451 return AUL_SVC_RET_EINVAL;
454 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
457 extern "C" API int aul_svc_set_appid(bundle* b, const char* appid) {
458 if (b == nullptr || appid == nullptr) {
459 _E("Invalid parameter");
460 return AUL_SVC_RET_EINVAL;
463 std::string alias_id = ::GetAliasAppId(appid);
464 if (!alias_id.empty())
465 appid = alias_id.c_str();
467 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, appid);
470 extern "C" API int aul_svc_set_category(bundle* b, const char* category) {
472 _E("Invalid parameter");
473 return AUL_SVC_RET_EINVAL;
476 return ::SetBundle(b, AUL_SVC_K_CATEGORY, category);
479 extern "C" API int aul_svc_set_launch_mode(bundle* b, const char* mode) {
481 _E("Invalid parameter");
482 return AUL_SVC_RET_EINVAL;
485 return ::SetBundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
488 extern "C" API int aul_svc_resolve(bundle* b, uid_t uid, char*** appid_array,
490 return aul_svc_get_appid_array(b, uid, appid_array, len);
493 extern "C" API int aul_svc_run_service(bundle* b, int request_code,
494 aul_svc_res_fn cbfunc, void* data) {
495 return aul_svc_run_service_for_uid(b, request_code, cbfunc, data, getuid());
498 extern "C" API int aul_svc_run_service_for_uid(bundle* b, int request_code,
499 aul_svc_res_fn cbfunc, void* data, uid_t uid) {
500 CbInfo* cb_info = nullptr;
502 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
503 if (cb_info == nullptr)
504 LOGE("Out of memory");
507 std::tuple<aul_svc_res_fn, void*> param { cbfunc, data };
508 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
509 [](const std::string& appid, bundle* request, uid_t uid,
510 CbInfo* cb_info) -> int {
513 ret = aul_launch_app_with_result_for_uid(appid.c_str(), request,
514 LaunchWithResultCb, cb_info, uid);
516 ret = aul_launch_app_for_uid(appid.c_str(), request, uid);
525 ret = AulErrorConvert(ret);
531 extern "C" API int aul_svc_get_list(bundle* b, aul_svc_info_iter_fn iter_fn,
533 return aul_svc_get_list_for_uid(b, iter_fn, data, getuid());
536 extern "C" API int aul_svc_get_list_for_uid(bundle* b,
537 aul_svc_info_iter_fn iter_fn, void* data, uid_t uid) {
538 if (b == nullptr || iter_fn == nullptr) {
539 _E("Invalid parameter");
540 return AUL_SVC_RET_EINVAL;
543 char** appid_array = nullptr;
544 unsigned int len = 0;
545 int ret = aul_svc_get_appid_array(b, uid, &appid_array, &len);
546 if (ret != AUL_SVC_RET_OK)
550 _E("Failed to find associated application");
551 aul_svc_free_appid_array(appid_array, len);
552 return AUL_SVC_RET_ENOMATCH;
555 for (unsigned int i = 0; i < len; ++i) {
556 SECURE_LOGD("APPID: %s", appid_array[i]);
557 if (iter_fn(appid_array[i], data) != 0)
561 aul_svc_free_appid_array(appid_array, len);
562 return AUL_SVC_RET_OK;
565 extern "C" API int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn,
567 return aul_svc_get_all_defapps_for_uid(iter_fn, data, getuid());
570 extern "C" API int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
571 void* data, uid_t uid) {
572 if (iter_fn == nullptr) {
573 _E("Invalid parameter");
574 return AUL_SVC_RET_EINVAL;
578 tizen_base::Bundle request;
579 int ret = ::SendAndReceive(APP_GET_APP_CONTROL_DEFAULT_APPS, uid,
580 request.GetHandle(), &response);
581 if (ret != AUL_SVC_RET_OK)
584 tizen_base::Bundle res(response, false, true);
585 auto appid_array = res.GetStringArray(AUL_K_APPID_LIST);
586 for (auto& appid : appid_array) {
587 if (iter_fn(appid.c_str(), data) != 0)
591 return AUL_SVC_RET_OK;
594 extern "C" API const char* aul_svc_get_operation(bundle* b) {
595 return bundle_get_val(b, AUL_SVC_K_OPERATION);
598 extern "C" API const char* aul_svc_get_uri(bundle* b) {
599 return bundle_get_val(b, AUL_SVC_K_URI);
602 extern "C" API const char* aul_svc_get_mime(bundle* b) {
603 return bundle_get_val(b, AUL_SVC_K_MIME);
606 extern "C" API const char* aul_svc_get_data(bundle* b, const char* key) {
607 return bundle_get_val(b, key);
610 extern "C" API const char** aul_svc_get_data_array(bundle* b, const char* key,
612 return bundle_get_str_array(b, key, len);
615 extern "C" API const char* aul_svc_get_pkgname(bundle* b) {
616 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
619 extern "C" API const char* aul_svc_get_appid(bundle* b) {
620 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
623 extern "C" API const char* aul_svc_get_category(bundle* b) {
624 return bundle_get_val(b, AUL_SVC_K_CATEGORY);
627 extern "C" API const char* aul_svc_get_launch_mode(bundle* b) {
628 return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
631 extern "C" API int aul_svc_create_result_bundle(bundle* inb, bundle** outb) {
632 if (inb == nullptr || outb == nullptr) {
633 _E("Invalid parameter");
634 return AUL_SVC_RET_EINVAL;
637 int ret = aul_create_result_bundle(inb, outb);
639 return AulErrorConvert(ret);
641 return AUL_SVC_RET_OK;
644 extern "C" API int aul_svc_send_result(bundle* b, aul_svc_result_val result) {
646 _E("Invalid parameter");
647 return AUL_SVC_RET_EINVAL;
650 int ret = ::SetBundle(b, AUL_SVC_K_RES_VAL, std::to_string(result).c_str());
652 return AUL_SVC_RET_ERROR;
654 if (result == AUL_SVC_RES_CANCEL)
655 ret = aul_send_result(b, 1);
657 ret = aul_send_result(b, 0);
659 bundle_del(b, AUL_SVC_K_RES_VAL);
663 extern "C" API int aul_svc_data_is_array(bundle* b, const char* key) {
664 int type = bundle_get_type(b, key);
668 if (type & BUNDLE_TYPE_ARRAY)
674 extern "C" API int aul_svc_allow_transient_app(bundle* b, int wid) {
676 _E("Invalid parameter");
677 return AUL_SVC_RET_EINVAL;
680 return ::SetBundle(b, AUL_SVC_K_WIN_ID, std::to_string(wid).c_str());
683 extern "C" API int aul_svc_request_transient_app(bundle* b, int callee_wid,
684 aul_svc_host_res_fn cbfunc, void* data) {
688 extern "C" API int aul_svc_subapp_terminate_request_pid(int pid) {
691 int* lpids = nullptr;
692 aul_app_group_get_leader_pids(&lcnt, &lpids);
693 for (int i = 0; i < lcnt; ++i) {
694 if (lpids[i] == cpid) {
697 aul_app_group_get_group_pids(cpid, &cnt, &pids);
703 return aul_subapp_terminate_request_pid(pid);
712 if (lpids != nullptr)
715 return aul_app_group_clear_top();
718 extern "C" API int aul_send_service_result(bundle* b) {
719 return aul_send_result(b, 0);
722 extern "C" API int aul_svc_subscribe_launch_result(bundle* b,
723 const char* result) {
725 _E("Invalid parameter");
726 return AUL_SVC_RET_EINVAL;
729 return ::SetBundle(b, result, "1");
732 extern "C" API int aul_svc_set_loader_id(bundle* b, int loader_id) {
733 if (b == nullptr || loader_id <= 0) {
734 _E("Invalid parameter");
735 return AUL_SVC_RET_EINVAL;
738 return ::SetBundle(b, AUL_K_LOADER_ID, std::to_string(loader_id).c_str());
741 extern "C" API int aul_svc_set_loader_name(bundle* b, const char* loader_name) {
742 if (b == nullptr || loader_name == nullptr) {
743 _E("Invalid parameter");
744 return AUL_SVC_RET_EINVAL;
747 return ::SetBundle(b, AUL_K_LOADER_NAME, loader_name);
750 extern "C" API int aul_svc_set_background_launch(bundle* b, int enabled) {
752 _E("Invalid parameter");
753 return AUL_SVC_RET_EINVAL;
756 return ::SetBundle(b, AUL_SVC_K_BG_LAUNCH, enabled ? "enable" : nullptr);
759 extern "C" API int aul_svc_get_appid_by_alias_appid(const char* alias_appid,
761 return aul_svc_get_appid_by_alias_appid_for_uid(alias_appid, appid, getuid());
764 extern "C" API int aul_svc_get_appid_by_alias_appid_for_uid(
765 const char* alias_appid, char** appid, uid_t uid) {
766 if (alias_appid == nullptr || appid == nullptr) {
767 _E("Invalid parameter");
768 return AUL_SVC_RET_EINVAL;
772 return GetAppIdByAliasAppIdFromDB(alias_appid, appid, uid);
775 tizen_base::Bundle request;
776 request.Add(AUL_K_ALIAS_APPID, alias_appid);
777 int ret = ::SendAndReceive(APP_GET_APPID_BY_ALIAS_APPID, uid,
778 request.GetHandle(), &response);
779 if (ret != AUL_SVC_RET_OK)
782 tizen_base::Bundle res(response, false, true);
783 auto val = res.GetString(AUL_K_APPID);
785 return AUL_SVC_RET_ERROR;
787 *appid = strdup(val.c_str());
788 if (*appid == nullptr) {
790 return AUL_SVC_RET_ENOMEM;
793 return AUL_SVC_RET_OK;
796 extern "C" API const char *aul_svc_get_instance_id(bundle* b) {
797 return bundle_get_val(b, AUL_K_INSTANCE_ID);
800 extern "C" API int aul_svc_set_instance_id(bundle* b, const char* instance_id) {
802 _E("Invalid parameter");
803 return AUL_SVC_RET_EINVAL;
806 return ::SetBundle(b, AUL_K_INSTANCE_ID, instance_id);
809 extern "C" API int aul_svc_run_service_async(bundle* b, int request_code,
810 aul_svc_res_fn cbfunc, void* data) {
811 return aul_svc_run_service_async_for_uid(b, request_code, cbfunc, data,
815 extern "C" API int aul_svc_run_service_async_for_uid(bundle* b,
816 int request_code, aul_svc_res_fn cbfunc, void* data, uid_t uid) {
817 CbInfo* cb_info = nullptr;
819 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
821 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
822 [](const std::string& appid, bundle* request, uid_t uid,
823 CbInfo* info) -> int {
825 return aul_launch_app_with_result_async_for_uid(appid.c_str(),
826 request, LaunchWithResultCb, info, uid);
829 return aul_launch_app_async_for_uid(appid.c_str(), request, uid);
835 ret = AulErrorConvert(ret);
841 extern "C" API int aul_svc_send_launch_request(bundle* b, int request_code,
842 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void* user_data) {
843 return aul_svc_send_launch_request_for_uid(b, request_code,
844 cbfunc, err_cb, user_data, getuid());
847 extern "C" API int aul_svc_send_launch_request_for_uid(bundle* b,
848 int request_code, aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
849 void* user_data, uid_t uid) {
850 if (b == nullptr || err_cb == nullptr) {
851 _E("Invalid parameter");
852 return AUL_SVC_RET_EINVAL;
855 CbInfo* cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, err_cb,
857 if (cb_info == nullptr)
860 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
861 [](const std::string& appid, bundle* request, uid_t uid,
862 CbInfo* info) -> int {
863 return aul_send_launch_request_for_uid(appid.c_str(), request, uid,
864 info->res_fn_ ? ::LaunchWithResultCb : nullptr, ::ErrorCb, info);
868 ret = ::AulErrorConvert(ret);
874 extern "C" API int aul_svc_send_launch_request_sync_for_uid(bundle* b,
875 int request_code, bundle** res_b, aul_svc_result_val* res, uid_t uid) {
876 if (b == nullptr || res_b == nullptr || res == nullptr) {
877 _E("Invalid parameter");
878 return AUL_SVC_RET_EINVAL;
881 int ret = ::SendLaunchRequest<::SendLaunchRequestSyncCb, bundle**>(
882 [](const std::string& appid, bundle* request, uid_t uid,
883 bundle** response) -> int {
884 return aul_send_launch_request_sync_for_uid(appid.c_str(), request,
888 auto* val = bundle_get_val(*res_b, AUL_SVC_K_RES_VAL);
889 *res = static_cast<aul_svc_result_val>(
890 (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val));
892 ret = ::AulErrorConvert(ret);
893 *res = AUL_SVC_RES_CANCEL;
899 extern "C" API int aul_svc_info_create(bundle* b, aul_svc_info_h* h) {
900 if (b == nullptr || h == nullptr) {
901 _E("Invalid parameter");
902 return AUL_SVC_RET_EINVAL;
905 aul::ResolveInfo* resolve_info = nullptr;
907 tizen_base::Bundle kb(b, false, false);
908 resolve_info = aul::ResolveInfo::Manager::Create(kb);
909 } catch (aul::Exception& e) {
910 return AUL_SVC_RET_ERROR;
913 *h = static_cast<aul_svc_info_h>(resolve_info);
914 return AUL_SVC_RET_OK;
917 extern "C" API int aul_svc_info_get_operation(aul_svc_info_h h,
919 if (h == nullptr || operation == nullptr) {
920 _E("Invalid parameter");
921 return AUL_SVC_RET_EINVAL;
924 auto* info = static_cast<aul::ResolveInfo*>(h);
925 auto& value = info->GetOperation();
926 *operation = strdup(value.empty() ? "NULL" : value.c_str());
927 if (*operation == nullptr) {
928 _E("Failed to duplicate operation");
929 return AUL_SVC_RET_ERROR;
932 return AUL_SVC_RET_OK;
935 extern "C" API int aul_svc_info_get_uri(aul_svc_info_h h, char** uri) {
936 if (h == nullptr || uri == nullptr) {
937 _E("Invalid parameter");
938 return AUL_SVC_RET_EINVAL;
941 auto* info = static_cast<aul::ResolveInfo*>(h);
942 auto& value = info->GetUri();
943 *uri = strdup(value.empty() ? "NULL" : value.c_str());
944 if (*uri == nullptr) {
945 _E("Failed to duplicate URI");
946 return AUL_SVC_RET_ERROR;
949 return AUL_SVC_RET_OK;
952 extern "C" API int aul_svc_info_get_uri_scheme(aul_svc_info_h h,
954 if (h == nullptr || uri_scheme == nullptr) {
955 _E("Invalid parameter");
956 return AUL_SVC_RET_EINVAL;
959 auto* info = static_cast<aul::ResolveInfo*>(h);
960 auto& value = info->GetScheme();
961 *uri_scheme = strdup(value.empty() ? "NULL" : value.c_str());
962 if (*uri_scheme == nullptr) {
963 _E("Failed to duplicate URI scheme");
964 return AUL_SVC_RET_ERROR;
967 return AUL_SVC_RET_OK;
970 extern "C" API int aul_svc_info_get_uri_host(aul_svc_info_h h,
972 if (h == nullptr || uri_host == nullptr) {
973 _E("Invalid parameter");
974 return AUL_SVC_RET_EINVAL;
977 auto* info = static_cast<aul::ResolveInfo*>(h);
978 auto& value = info->GetHost();
979 *uri_host = strdup(value.empty() ? "NULL" : value.c_str());
980 if (*uri_host == nullptr) {
981 _E("Failed to duplicate URI host");
982 return AUL_SVC_RET_ERROR;
985 return AUL_SVC_RET_OK;
988 extern "C" API int aul_svc_info_get_mime(aul_svc_info_h h, char** mime) {
989 if (h == nullptr || mime == nullptr) {
990 _E("Invalid parameter");
991 return AUL_SVC_RET_EINVAL;
994 auto* info = static_cast<aul::ResolveInfo*>(h);
995 auto& value = info->GetMime();
996 *mime = strdup(value.empty() ? "NULL" : value.c_str());
997 if (*mime == nullptr) {
998 _E("Failed to duplicate MIME-Type");
999 return AUL_SVC_RET_ERROR;
1002 return AUL_SVC_RET_OK;
1005 extern "C" API int aul_svc_info_get_mime_type(aul_svc_info_h h,
1007 if (h == nullptr || mime_type == nullptr) {
1008 _E("Invalid parameter");
1009 return AUL_SVC_RET_EINVAL;
1012 auto* info = static_cast<aul::ResolveInfo*>(h);
1013 auto& value = info->GetMType();
1014 *mime_type = strdup(value.empty() ? "NULL" : value.c_str());
1015 if (*mime_type == nullptr) {
1016 _E("Failed to duplicate the type of MIME-Type");
1017 return AUL_SVC_RET_ERROR;
1020 return AUL_SVC_RET_OK;
1023 extern "C" API int aul_svc_info_get_mime_subtype(aul_svc_info_h h,
1024 char** mime_subtype) {
1025 if (h == nullptr || mime_subtype == nullptr) {
1026 _E("Invalid parameter");
1027 return AUL_SVC_RET_EINVAL;
1030 auto* info = static_cast<aul::ResolveInfo*>(h);
1031 auto& value = info->GetSType();
1032 *mime_subtype = strdup(value.empty() ? "NULL" : value.c_str());
1033 if (*mime_subtype == nullptr) {
1034 _E("Failed to duplicate the subtype of MIME-Type");
1035 return AUL_SVC_RET_ERROR;
1038 return AUL_SVC_RET_OK;
1041 extern "C" API int aul_svc_info_destroy(aul_svc_info_h h) {
1043 _E("Invalid parameter");
1044 return AUL_SVC_RET_EINVAL;
1047 auto* info = static_cast<aul::ResolveInfo*>(h);
1049 return AUL_SVC_RET_OK;
1052 extern "C" API int aul_svc_set_caller_instance_id(bundle* b,
1053 const char* instance_id) {
1055 _E("Invalid parameter");
1056 return AUL_SVC_RET_EINVAL;
1059 return ::SetBundle(b, AUL_K_CALLER_INSTANCE_ID, instance_id);
1062 extern "C" API int aul_svc_set_comp_id(bundle* b, const char* comp_id) {
1064 _E("Invalid parameter");
1065 return AUL_SVC_RET_EINVAL;
1068 return ::SetBundle(b, AUL_K_COMPONENT_ID, comp_id);
1071 extern "C" API const char *aul_svc_get_comp_id(bundle* b) {
1072 return bundle_get_val(b, AUL_K_COMPONENT_ID);
1075 extern "C" API int aul_svc_subapp_terminate_request(bundle* b, int pid) {
1076 if (b == nullptr || pid < 0) {
1077 _E("Invalid parameter");
1078 return AUL_SVC_RET_EINVAL;
1081 const char* inst_id = bundle_get_val(b, AUL_K_INSTANCE_ID);
1082 if (inst_id == nullptr) {
1083 _E("Invalid parameter");
1084 return AUL_SVC_RET_EINVAL;
1087 char buf[512] = { 0, };
1088 const char* caller_inst_id = bundle_get_val(b, AUL_K_CALLER_INSTANCE_ID);
1089 if (caller_inst_id == nullptr) {
1090 int ret = aul_app_get_instance_id_bypid(getpid(), buf, sizeof(buf));
1091 if (ret != AUL_R_OK) {
1092 _E("aul_app_get_instance_id_bypid() is failed. error(%d)", ret);
1093 return AUL_SVC_RET_ERROR;
1096 caller_inst_id = buf;
1100 aul_app_group_foreach_group_info(caller_inst_id,
1101 [](aul_app_group_info_h info, void* data) {
1102 int* count = static_cast<int*>(data);
1104 }, static_cast<void*>(&cnt));
1106 return aul_subapp_terminate_request(inst_id, pid);
1108 return aul_app_group_clear_top();
1111 extern "C" API int aul_svc_send_resume_request(bundle* b, int request_code,
1112 aul_svc_err_cb err_cb, void *user_data) {
1113 return aul_svc_send_resume_request_for_uid(b, request_code, err_cb, user_data,
1117 extern "C" API int aul_svc_send_resume_request_for_uid(bundle* b,
1118 int request_code, aul_svc_err_cb err_cb, void* user_data, uid_t uid) {
1119 if (b == nullptr || err_cb == nullptr) {
1120 _E("Invalid parameter");
1121 return AUL_SVC_RET_EINVAL;
1124 auto* cb_info = new (std::nothrow) CbInfo(request_code, nullptr, err_cb,
1126 if (cb_info == nullptr)
1127 _E("Out of memory");
1129 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
1130 [](const std::string& appid, bundle* request, uid_t uid,
1131 CbInfo* info) -> int {
1132 return aul_send_resume_request_for_uid(appid.c_str(), request, uid,
1134 }, b, uid, cb_info);
1137 ret = ::AulErrorConvert(ret);
1143 extern "C" API int aul_svc_get_appid_array(bundle* b, uid_t uid,
1144 char*** appid_array, unsigned int* len) {
1145 if (b == nullptr || appid_array == nullptr || len == nullptr) {
1146 _E("Invalid parameter");
1147 return AUL_SVC_RET_EINVAL;
1150 bundle_del(b, AUL_K_APPID);
1151 bundle_add(b, AUL_K_APPID, "@UNKNOWN");
1154 int ret = ::SendAndReceive(APP_GET_APPID_LIST, uid, b, &response);
1155 if (ret != AUL_SVC_RET_OK)
1158 tizen_base::Bundle res(response, false, true);
1159 auto str = res.GetString(AUL_SVC_K_URI_R_INFO);
1161 ::SetBundle(b, AUL_SVC_K_URI_R_INFO, str.c_str());
1163 auto str_arr = res.GetStringArray(AUL_K_APPID_LIST);
1164 if (str_arr.empty()) {
1165 _E("Failed to get appid list");
1166 return AUL_SVC_RET_ERROR;
1169 *appid_array = reinterpret_cast<char**>(
1170 calloc(str_arr.size(), sizeof(char*)));
1171 if (*appid_array == nullptr) {
1172 _E("Out of memory");
1173 return AUL_SVC_RET_ENOMEM;
1176 *len = str_arr.size();
1179 for (auto& appid : str_arr)
1180 (*appid_array)[i++] = strdup(appid.c_str());
1182 return AUL_SVC_RET_OK;
1185 extern "C" API void aul_svc_free_appid_array(char** appid_array,
1187 if (appid_array == nullptr)
1190 for (unsigned int i = 0; i < len; ++i)
1191 free(appid_array[i]);
1196 extern "C" API int aul_svc_set_defapp(const char* op, const char* mime_type,
1197 const char* uri, const char* defapp) {
1198 DEPRECATION_WARNING();
1199 return AUL_SVC_RET_OK;
1202 extern "C" API int aul_svc_set_defapp_for_uid(const char* op,
1203 const char* mime_type, const char* uri, const char* defapp, uid_t uid) {
1204 DEPRECATION_WARNING();
1205 return AUL_SVC_RET_OK;
1208 extern "C" API int aul_svc_unset_defapp(const char* defapp) {
1209 DEPRECATION_WARNING();
1210 return AUL_SVC_RET_OK;
1213 extern "C" API int aul_svc_unset_defapp_for_uid(const char* defapp, uid_t uid) {
1214 DEPRECATION_WARNING();
1215 return AUL_SVC_RET_OK;
1218 extern "C" API int aul_svc_unset_all_defapps(void) {
1219 DEPRECATION_WARNING();
1220 return AUL_SVC_RET_OK;
1223 extern "C" API int aul_svc_unset_all_defapps_for_uid(uid_t uid) {
1224 DEPRECATION_WARNING();
1225 return AUL_SVC_RET_OK;
1228 extern "C" API int aul_svc_is_defapp(const char* pkg_name) {
1229 DEPRECATION_WARNING();
1230 return AUL_SVC_RET_OK;
1233 extern "C" API int aul_svc_is_defapp_for_uid(const char* pkg_name, uid_t uid) {
1234 DEPRECATION_WARNING();
1235 return AUL_SVC_RET_OK;
1238 extern "C" API int aul_svc_set_alias_appid(const char* alias_appid,
1239 const char* appid) {
1240 DEPRECATION_WARNING();
1241 return AUL_SVC_RET_OK;
1244 extern "C" API int aul_svc_set_alias_appid_for_uid(const char* alias_appid,
1245 const char* appid, uid_t uid) {
1246 DEPRECATION_WARNING();
1247 return AUL_SVC_RET_OK;
1250 extern "C" API int aul_svc_unset_alias_appid(const char* alias_appid) {
1251 DEPRECATION_WARNING();
1252 return AUL_SVC_RET_OK;
1255 extern "C" API int aul_svc_unset_alias_appid_for_uid(const char* alias_appid,
1257 DEPRECATION_WARNING();
1258 return AUL_SVC_RET_OK;
1261 extern "C" API int aul_svc_foreach_alias_info(
1262 void (*callback)(const char *, const char *, void *),
1264 DEPRECATION_WARNING();
1265 return AUL_SVC_RET_OK;
1268 extern "C" API int aul_svc_foreach_alias_info_for_uid(
1269 void (*callback)(const char *, const char *, void *),
1270 uid_t uid, void* user_data) {
1271 DEPRECATION_WARNING();
1272 return AUL_SVC_RET_OK;
1275 extern "C" API int aul_svc_enable_alias_info(const char* appid) {
1276 DEPRECATION_WARNING();
1277 return AUL_SVC_RET_OK;
1280 extern "C" API int aul_svc_enable_alias_info_for_uid(const char* appid,
1282 DEPRECATION_WARNING();
1283 return AUL_SVC_RET_OK;
1286 extern "C" API int aul_svc_disable_alias_info(const char* appid) {
1287 DEPRECATION_WARNING();
1288 return AUL_SVC_RET_OK;
1291 extern "C" API int aul_svc_disable_alias_info_for_uid(const char* appid,
1293 DEPRECATION_WARNING();
1294 return AUL_SVC_RET_OK;
1297 extern "C" API int aul_svc_foreach_alias_info_by_appid(
1298 int (*callback)(const char *, const char *, void *),
1299 const char* appid, void* user_data) {
1300 DEPRECATION_WARNING();
1301 return AUL_SVC_RET_OK;
1304 extern "C" API int aul_svc_foreach_alias_info_by_appid_for_uid(
1305 int (*callback)(const char *, const char *, void *),
1306 const char* appid, uid_t uid, void* user_data) {
1307 DEPRECATION_WARNING();
1308 return AUL_SVC_RET_OK;
1311 extern "C" API int aul_svc_foreach_allowed_info(
1312 int (*callback)(const char *, const char *, void *),
1314 DEPRECATION_WARNING();
1315 return AUL_SVC_RET_OK;
1318 extern "C" API int aul_svc_foreach_allowed_info_for_uid(
1319 int (*callback)(const char *, const char *, void *),
1320 uid_t uid, void* user_data) {
1321 DEPRECATION_WARNING();
1322 return AUL_SVC_RET_OK;
1325 extern "C" API int aul_svc_foreach_allowed_info_by_appid(
1326 int (*callback)(const char *, const char *, void *),
1327 const char* appid, void* user_data) {
1328 DEPRECATION_WARNING();
1329 return AUL_SVC_RET_OK;
1332 extern "C" API int aul_svc_foreach_allowed_info_by_appid_for_uid(
1333 int (*callback)(const char *, const char *, void *),
1334 const char* appid, uid_t uid, void* user_data) {
1335 DEPRECATION_WARNING();
1336 return AUL_SVC_RET_OK;