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>
28 #include <sys/types.h>
35 #include "aul/app_control/resolve_info.hh"
36 #include "include/aul.h"
37 #include "include/aul_app_group.h"
38 #include "include/aul_error.h"
39 #include "include/aul_sock.h"
40 #include "include/aul_svc.h"
41 #include "include/aul_svc_internal.h"
42 #include "src/aul_api.h"
43 #include "src/aul_svc_priv_key.h"
44 #include "src/aul_util.h"
45 #include "src/launch.h"
47 #undef MAX_MIME_STR_SIZE
48 #define MAX_MIME_STR_SIZE 256
50 #undef MAX_SCHEME_STR_SIZE
51 #define MAX_SCHEME_STR_SIZE 256
53 #undef MAX_HOST_STR_SIZE
54 #define MAX_HOST_STR_SIZE 256
56 #undef DEPRECATION_WARNING
57 #define DEPRECATION_WARNING() do { \
58 dlog_print(DLOG_WARN, LOG_TAG, \
59 "DEPRECATION WARNING: %s() is deprecated and " \
60 "will be removed from next release.", __FUNCTION__); \
65 constexpr const char kPathAmdReady[] = "/run/.amd_ready";
66 constexpr const char kPathLibAulServer[] = "/usr/lib/libaul-server.so.0";
67 constexpr const char kAulServiceForeachUsrAliasInfo[] =
68 "aul_service_foreach_usr_alias_info";
72 CbInfo(int request_code, aul_svc_res_fn res_fn,
73 aul_svc_err_cb err_cb, void* user_data)
74 : request_code_(request_code),
77 user_data_(user_data) {
81 aul_svc_res_fn res_fn_;
82 aul_svc_err_cb err_cb_;
88 AliasInfo(std::string alias_appid)
89 : alias_appid_(std::move(alias_appid)) {
92 std::string alias_appid_;
96 int SetBundle(bundle* b, const char* key, const char* value) {
97 if (bundle_get_type(b, key) != BUNDLE_TYPE_NONE) {
98 if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
99 return AUL_SVC_RET_ERROR;
102 if (value == nullptr)
103 return AUL_SVC_RET_EINVAL;
105 if (bundle_add(b, key, value) != BUNDLE_ERROR_NONE)
106 return AUL_SVC_RET_ERROR;
108 SECURE_LOGD("key(%s), value(%s)", key, value);
109 return AUL_SVC_RET_OK;
112 int SetBundleArray(bundle* b, const char* key, const char** value,
114 int is_array = aul_svc_data_is_array(b, key);
116 if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
117 return AUL_SVC_RET_ERROR;
120 if (value == nullptr)
121 return AUL_SVC_RET_EINVAL;
123 if (bundle_add_str_array(b, key, value, len) != BUNDLE_ERROR_NONE)
124 return AUL_SVC_RET_ERROR;
126 SECURE_LOGD("key(%s), length(%d)", key, len);
127 return AUL_SVC_RET_OK;
130 std::string GetAliasAppId(const char* appid) {
131 dictionary* dic = iniparser_load("/usr/share/appsvc/alias.ini");
135 auto dic_ptr = std::unique_ptr<dictionary, decltype(iniparser_freedict)*>(
136 dic, iniparser_freedict);
138 std::string key = std::string("Alias:") + appid;
139 const char* value = iniparser_getstring(dic, key.c_str(), nullptr);
140 SECURE_LOGD("appid(%s), alias_id(%s)", appid, value);
141 if (value == nullptr)
144 return std::string(value);
147 bool IsSpecialApp(const char* appid) {
148 if (!strcmp(appid, APP_SELECTOR) || !strcmp(appid, SHARE_PANEL))
154 bool IsSpecialOperation(const char* operation) {
155 if (operation == nullptr)
158 int ret = strcmp(operation,
159 "http://tizen.org/appcontrol/operation/guide_privacy_setting");
166 std::string GetAppId(bundle* request) {
167 const char* appid = aul_svc_get_pkgname(request);
168 if (appid == nullptr) {
169 if (aul_svc_get_operation(request) == nullptr) {
170 _E("Invalid request");
177 int ret = bundle_get_type(request, AUL_SVC_K_SELECTOR_EXTRA_LIST);
178 if (ret != BUNDLE_TYPE_NONE) {
179 if (appid == nullptr || !strcmp(appid, "@UNKNOWN"))
180 appid = APP_SELECTOR;
183 ret = bundle_get_type(request, AUL_K_FORCE_LAUNCH_APP_SELECTOR);
184 if (ret != BUNDLE_TYPE_NONE)
185 appid = APP_SELECTOR;
187 return std::string(appid);
190 void SetLaunchData(bundle* request, const std::string& appid) {
191 const char* operation = aul_svc_get_operation(request);
192 if (operation == nullptr)
193 aul_svc_set_operation(request, AUL_SVC_OPERATION_DEFAULT);
195 if (IsSpecialApp(appid.c_str()) || IsSpecialOperation(operation)) {
196 SetBundle(request, AUL_SVC_K_CAN_BE_LEADER, "true");
197 SetBundle(request, AUL_SVC_K_REROUTE, "true");
198 SetBundle(request, AUL_SVC_K_RECYCLE, "true");
201 const char* launch_mode = aul_svc_get_launch_mode(request);
202 if (launch_mode && !strcmp(launch_mode, "group")) {
203 int ret = bundle_get_type(request, AUL_K_INSTANCE_ID);
204 if (ret != BUNDLE_TYPE_NONE)
205 aul_set_instance_info(appid.c_str(), request);
209 int AulErrorConvert(int res) {
212 return AUL_SVC_RET_EILLACC;
214 return AUL_SVC_RET_EINVAL;
215 case AUL_R_ETERMINATING:
216 return AUL_SVC_RET_ETERMINATING;
217 case AUL_R_EREJECTED:
218 return AUL_SVC_RET_EREJECTED;
220 return AUL_SVC_RET_ENOMATCH;
221 case AUL_R_ECANCELED:
222 return AUL_SVC_RET_ECANCELED;
224 return AUL_SVC_RET_ELAUNCH;
228 void LaunchWithResultCb(bundle* b, int is_cancel, void* data) {
231 res = AUL_SVC_RES_CANCEL;
233 const char* val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
234 res = (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val);
237 bundle_del(b, AUL_SVC_K_RES_VAL);
238 auto* cb_info = static_cast<CbInfo*>(data);
239 if (cb_info == nullptr) {
240 _E("Invalid parameter");
244 if (cb_info->res_fn_) {
245 cb_info->res_fn_(b, cb_info->request_code_,
246 static_cast<aul_svc_result_val>(res), cb_info->user_data_);
247 cb_info->res_fn_ = nullptr;
250 if (cb_info->err_cb_ != nullptr)
256 void ErrorCb(int error, void* data) {
258 error = AulErrorConvert(error);
260 auto* cb_info = static_cast<CbInfo*>(data);
261 if (cb_info == nullptr) {
262 _E("Invalid parameter");
266 if (cb_info->err_cb_) {
267 cb_info->err_cb_(cb_info->request_code_, error, cb_info->user_data_);
268 cb_info->err_cb_ = nullptr;
271 if (cb_info->res_fn_)
277 using SendLaunchRequestCb =
278 int (*)(const std::string&, bundle*, uid_t, CbInfo*);
279 using SendLaunchRequestSyncCb =
280 int (*)(const std::string&, bundle*, uid_t, bundle**);
282 template <typename T, typename A>
283 int SendLaunchRequest(T cb, bundle* request, uid_t uid, A arg) {
284 if (request == nullptr) {
285 _E("Invalid parameter");
286 return AUL_SVC_RET_EINVAL;
289 std::string appid = GetAppId(request);
291 _E("GetAppId() is failed");
292 return AUL_SVC_RET_EINVAL;
295 SetLaunchData(request, appid);
296 return cb(appid, request, uid, arg);
299 int SendAndReceive(int cmd, uid_t uid, bundle* request, bundle** response) {
300 int fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, cmd, request,
303 return AUL_SVC_RET_ERROR;
305 app_pkt_t* pkt = nullptr;
306 int ret = aul_sock_recv_reply_pkt(fd, &pkt);
308 _E("Failed to receive reply packet. error(%d)", ret);
309 return AUL_SVC_RET_ERROR;
312 auto ptr = std::unique_ptr<app_pkt_t, decltype(std::free)*>(pkt, std::free);
313 if (pkt->cmd != APP_GET_INFO_OK && pkt->cmd != cmd) {
314 if (pkt->cmd == APP_GET_INFO_ERROR)
315 return AUL_SVC_RET_ERROR;
317 return AulErrorConvert(aul_error_convert(pkt->cmd));
321 if (pkt->opt & AUL_SOCK_BUNDLE) {
322 b = bundle_decode(pkt->data, pkt->len);
324 _E("bundle_decode() is failed");
325 return AUL_SVC_RET_ENOMEM;
328 _E("Invalid packet");
329 return AUL_SVC_RET_ERROR;
333 return AUL_SVC_RET_OK;
336 std::atomic<bool> amd_ready { false };
341 if (access(kPathAmdReady, F_OK) == 0) {
342 amd_ready.exchange(true);
349 using AulServiceAliasInfoCb =
350 bool (*)(const char*, const char*, void*);
351 using AulServiceForeachUsrAliasInfoFunc =
352 int (*)(AulServiceAliasInfoCb, uid_t, void*);
354 int GetAppIdByAliasAppIdFromDB(const char* alias_appid, char** app_id,
356 void* handle = dlopen(kPathLibAulServer, RTLD_LAZY | RTLD_GLOBAL);
357 if (handle == nullptr) {
358 _E("dlopen() is failed. path(%s), error(%s)", kPathLibAulServer, dlerror());
359 return AUL_SVC_RET_ERROR;
362 auto dl_closer = [](void* ptr) {
366 std::unique_ptr<void, decltype(dl_closer)> handle_auto(handle, dl_closer);
367 auto* func = reinterpret_cast<AulServiceForeachUsrAliasInfoFunc>(
368 dlsym(handle, kAulServiceForeachUsrAliasInfo));
369 if (func == nullptr) {
370 _E("dlsym() is failed. error(%s)", dlerror());
371 return AUL_SVC_RET_ERROR;
374 AliasInfo info(alias_appid);
376 [](const char* alias_appid, const char* appid, void* user_data) -> bool {
377 auto* info = static_cast<AliasInfo*>(user_data);
378 if (info->alias_appid_ == alias_appid) {
379 info->appid_ = appid;
386 _E("%s() is failed. error(%d)", kAulServiceForeachUsrAliasInfo, ret);
387 return AUL_SVC_RET_ERROR;
390 if (info.appid_.empty())
391 return AUL_SVC_RET_ERROR;
393 *app_id = strdup(info.appid_.c_str());
394 if (*app_id == nullptr) {
395 _E("strdup() is failed");
396 return AUL_SVC_RET_ENOMEM;
399 return AUL_SVC_RET_OK;
404 extern "C" API int aul_svc_set_operation(bundle* b, const char* operation) {
406 _E("Invalid parameter");
407 return AUL_SVC_RET_EINVAL;
410 return ::SetBundle(b, AUL_SVC_K_OPERATION, operation);
413 extern "C" API int aul_svc_set_uri(bundle* b, const char* uri) {
415 _E("Invalid parameter");
416 return AUL_SVC_RET_EINVAL;
419 return ::SetBundle(b, AUL_SVC_K_URI, uri);
422 extern "C" API int aul_svc_set_mime(bundle* b, const char* mime) {
424 _E("Invalid parameter");
425 return AUL_SVC_RET_EINVAL;
428 return ::SetBundle(b, AUL_SVC_K_MIME, mime);
431 extern "C" API int aul_svc_add_data(bundle* b, const char* key,
433 if (b == nullptr || key == nullptr)
434 return AUL_SVC_RET_EINVAL;
436 return ::SetBundle(b, key, value);
439 extern "C" API int aul_svc_add_data_array(bundle* b, const char* key,
440 const char** value, int len) {
441 if (b == nullptr || key == nullptr)
442 return AUL_SVC_RET_EINVAL;
444 return ::SetBundleArray(b, key, value, len);
447 extern "C" API int aul_svc_set_pkgname(bundle* b, const char* pkg_name) {
449 _E("Invalid parameter");
450 return AUL_SVC_RET_EINVAL;
453 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
456 extern "C" API int aul_svc_set_appid(bundle* b, const char* appid) {
457 if (b == nullptr || appid == nullptr) {
458 _E("Invalid parameter");
459 return AUL_SVC_RET_EINVAL;
462 std::string alias_id = ::GetAliasAppId(appid);
463 if (!alias_id.empty())
464 appid = alias_id.c_str();
466 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, appid);
469 extern "C" API int aul_svc_set_category(bundle* b, const char* category) {
471 _E("Invalid parameter");
472 return AUL_SVC_RET_EINVAL;
475 return ::SetBundle(b, AUL_SVC_K_CATEGORY, category);
478 extern "C" API int aul_svc_set_launch_mode(bundle* b, const char* mode) {
480 _E("Invalid parameter");
481 return AUL_SVC_RET_EINVAL;
484 return ::SetBundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
487 extern "C" API int aul_svc_resolve(bundle* b, uid_t uid, char*** appid_array,
489 return aul_svc_get_appid_array(b, uid, appid_array, len);
492 extern "C" API int aul_svc_run_service(bundle* b, int request_code,
493 aul_svc_res_fn cbfunc, void* data) {
494 return aul_svc_run_service_for_uid(b, request_code, cbfunc, data, getuid());
497 extern "C" API int aul_svc_run_service_for_uid(bundle* b, int request_code,
498 aul_svc_res_fn cbfunc, void* data, uid_t uid) {
499 CbInfo* cb_info = nullptr;
501 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
502 if (cb_info == nullptr)
503 LOGE("Out of memory");
506 std::tuple<aul_svc_res_fn, void*> param { cbfunc, data };
507 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
508 [](const std::string& appid, bundle* request, uid_t uid,
509 CbInfo* cb_info) -> int {
512 ret = aul_launch_app_with_result_for_uid(appid.c_str(), request,
513 LaunchWithResultCb, cb_info, uid);
515 ret = aul_launch_app_for_uid(appid.c_str(), request, uid);
524 ret = AulErrorConvert(ret);
530 extern "C" API int aul_svc_get_list(bundle* b, aul_svc_info_iter_fn iter_fn,
532 return aul_svc_get_list_for_uid(b, iter_fn, data, getuid());
535 extern "C" API int aul_svc_get_list_for_uid(bundle* b,
536 aul_svc_info_iter_fn iter_fn, void* data, uid_t uid) {
537 if (b == nullptr || iter_fn == nullptr) {
538 _E("Invalid parameter");
539 return AUL_SVC_RET_EINVAL;
542 char** appid_array = nullptr;
543 unsigned int len = 0;
544 int ret = aul_svc_get_appid_array(b, uid, &appid_array, &len);
545 if (ret != AUL_SVC_RET_OK)
549 _E("Failed to find associated application");
550 aul_svc_free_appid_array(appid_array, len);
551 return AUL_SVC_RET_ENOMATCH;
554 for (unsigned int i = 0; i < len; ++i) {
555 SECURE_LOGD("APPID: %s", appid_array[i]);
556 if (iter_fn(appid_array[i], data) != 0)
560 aul_svc_free_appid_array(appid_array, len);
561 return AUL_SVC_RET_OK;
564 extern "C" API int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn,
566 return aul_svc_get_all_defapps_for_uid(iter_fn, data, getuid());
569 extern "C" API int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
570 void* data, uid_t uid) {
571 if (iter_fn == nullptr) {
572 _E("Invalid parameter");
573 return AUL_SVC_RET_EINVAL;
577 tizen_base::Bundle request;
578 int ret = ::SendAndReceive(APP_GET_APP_CONTROL_DEFAULT_APPS, uid,
579 request.GetHandle(), &response);
580 if (ret != AUL_SVC_RET_OK)
583 tizen_base::Bundle res(response, false, true);
584 auto appid_array = res.GetStringArray(AUL_K_APPID_LIST);
585 for (auto& appid : appid_array) {
586 if (iter_fn(appid.c_str(), data) != 0)
590 return AUL_SVC_RET_OK;
593 extern "C" API const char* aul_svc_get_operation(bundle* b) {
594 return bundle_get_val(b, AUL_SVC_K_OPERATION);
597 extern "C" API const char* aul_svc_get_uri(bundle* b) {
598 return bundle_get_val(b, AUL_SVC_K_URI);
601 extern "C" API const char* aul_svc_get_mime(bundle* b) {
602 return bundle_get_val(b, AUL_SVC_K_MIME);
605 extern "C" API const char* aul_svc_get_data(bundle* b, const char* key) {
606 return bundle_get_val(b, key);
609 extern "C" API const char** aul_svc_get_data_array(bundle* b, const char* key,
611 return bundle_get_str_array(b, key, len);
614 extern "C" API const char* aul_svc_get_pkgname(bundle* b) {
615 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
618 extern "C" API const char* aul_svc_get_appid(bundle* b) {
619 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
622 extern "C" API const char* aul_svc_get_category(bundle* b) {
623 return bundle_get_val(b, AUL_SVC_K_CATEGORY);
626 extern "C" API const char* aul_svc_get_launch_mode(bundle* b) {
627 return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
630 extern "C" API int aul_svc_create_result_bundle(bundle* inb, bundle** outb) {
631 if (inb == nullptr || outb == nullptr) {
632 _E("Invalid parameter");
633 return AUL_SVC_RET_EINVAL;
636 int ret = aul_create_result_bundle(inb, outb);
638 return AulErrorConvert(ret);
640 return AUL_SVC_RET_OK;
643 extern "C" API int aul_svc_send_result(bundle* b, aul_svc_result_val result) {
645 _E("Invalid parameter");
646 return AUL_SVC_RET_EINVAL;
649 int ret = ::SetBundle(b, AUL_SVC_K_RES_VAL, std::to_string(result).c_str());
651 return AUL_SVC_RET_ERROR;
653 if (result == AUL_SVC_RES_CANCEL)
654 ret = aul_send_result(b, 1);
656 ret = aul_send_result(b, 0);
658 bundle_del(b, AUL_SVC_K_RES_VAL);
662 extern "C" API int aul_svc_data_is_array(bundle* b, const char* key) {
663 int type = bundle_get_type(b, key);
667 if (type & BUNDLE_TYPE_ARRAY)
673 extern "C" API int aul_svc_allow_transient_app(bundle* b, int wid) {
675 _E("Invalid parameter");
676 return AUL_SVC_RET_EINVAL;
679 return ::SetBundle(b, AUL_SVC_K_WIN_ID, std::to_string(wid).c_str());
682 extern "C" API int aul_svc_request_transient_app(bundle* b, int callee_wid,
683 aul_svc_host_res_fn cbfunc, void* data) {
687 extern "C" API int aul_svc_subapp_terminate_request_pid(int pid) {
690 int* lpids = nullptr;
691 aul_app_group_get_leader_pids(&lcnt, &lpids);
692 for (int i = 0; i < lcnt; ++i) {
693 if (lpids[i] == cpid) {
696 aul_app_group_get_group_pids(cpid, &cnt, &pids);
702 return aul_subapp_terminate_request_pid(pid);
711 if (lpids != nullptr)
714 return aul_app_group_clear_top();
717 extern "C" API int aul_send_service_result(bundle* b) {
718 return aul_send_result(b, 0);
721 extern "C" API int aul_svc_subscribe_launch_result(bundle* b,
722 const char* result) {
724 _E("Invalid parameter");
725 return AUL_SVC_RET_EINVAL;
728 return ::SetBundle(b, result, "1");
731 extern "C" API int aul_svc_set_loader_id(bundle* b, int loader_id) {
732 if (b == nullptr || loader_id <= 0) {
733 _E("Invalid parameter");
734 return AUL_SVC_RET_EINVAL;
737 return ::SetBundle(b, AUL_K_LOADER_ID, std::to_string(loader_id).c_str());
740 extern "C" API int aul_svc_set_loader_name(bundle* b, const char* loader_name) {
741 if (b == nullptr || loader_name == nullptr) {
742 _E("Invalid parameter");
743 return AUL_SVC_RET_EINVAL;
746 return ::SetBundle(b, AUL_K_LOADER_NAME, loader_name);
749 extern "C" API int aul_svc_set_background_launch(bundle* b, int enabled) {
751 _E("Invalid parameter");
752 return AUL_SVC_RET_EINVAL;
755 return ::SetBundle(b, AUL_SVC_K_BG_LAUNCH, enabled ? "enable" : nullptr);
758 extern "C" API int aul_svc_get_appid_by_alias_appid(const char* alias_appid,
760 return aul_svc_get_appid_by_alias_appid_for_uid(alias_appid, appid, getuid());
763 extern "C" API int aul_svc_get_appid_by_alias_appid_for_uid(
764 const char* alias_appid, char** appid, uid_t uid) {
765 if (alias_appid == nullptr || appid == nullptr) {
766 _E("Invalid parameter");
767 return AUL_SVC_RET_EINVAL;
771 return GetAppIdByAliasAppIdFromDB(alias_appid, appid, uid);
774 tizen_base::Bundle request;
775 request.Add(AUL_K_ALIAS_APPID, alias_appid);
776 int ret = ::SendAndReceive(APP_GET_APPID_BY_ALIAS_APPID, uid,
777 request.GetHandle(), &response);
778 if (ret != AUL_SVC_RET_OK)
781 tizen_base::Bundle res(response, false, true);
782 auto val = res.GetString(AUL_K_APPID);
784 return AUL_SVC_RET_ERROR;
786 *appid = strdup(val.c_str());
787 if (*appid == nullptr) {
789 return AUL_SVC_RET_ENOMEM;
792 return AUL_SVC_RET_OK;
795 extern "C" API const char *aul_svc_get_instance_id(bundle* b) {
796 return bundle_get_val(b, AUL_K_INSTANCE_ID);
799 extern "C" API int aul_svc_set_instance_id(bundle* b, const char* instance_id) {
801 _E("Invalid parameter");
802 return AUL_SVC_RET_EINVAL;
805 return ::SetBundle(b, AUL_K_INSTANCE_ID, instance_id);
808 extern "C" API int aul_svc_run_service_async(bundle* b, int request_code,
809 aul_svc_res_fn cbfunc, void* data) {
810 return aul_svc_run_service_async_for_uid(b, request_code, cbfunc, data,
814 extern "C" API int aul_svc_run_service_async_for_uid(bundle* b,
815 int request_code, aul_svc_res_fn cbfunc, void* data, uid_t uid) {
816 CbInfo* cb_info = nullptr;
818 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
820 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
821 [](const std::string& appid, bundle* request, uid_t uid,
822 CbInfo* info) -> int {
824 return aul_launch_app_with_result_async_for_uid(appid.c_str(),
825 request, LaunchWithResultCb, info, uid);
828 return aul_launch_app_async_for_uid(appid.c_str(), request, uid);
834 ret = AulErrorConvert(ret);
840 extern "C" API int aul_svc_send_launch_request(bundle* b, int request_code,
841 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void* user_data) {
842 return aul_svc_send_launch_request_for_uid(b, request_code,
843 cbfunc, err_cb, user_data, getuid());
846 extern "C" API int aul_svc_send_launch_request_for_uid(bundle* b,
847 int request_code, aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
848 void* user_data, uid_t uid) {
849 if (b == nullptr || err_cb == nullptr) {
850 _E("Invalid parameter");
851 return AUL_SVC_RET_EINVAL;
854 CbInfo* cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, err_cb,
856 if (cb_info == nullptr)
859 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
860 [](const std::string& appid, bundle* request, uid_t uid,
861 CbInfo* info) -> int {
862 return aul_send_launch_request_for_uid(appid.c_str(), request, uid,
863 info->res_fn_ ? ::LaunchWithResultCb : nullptr, ::ErrorCb, info);
867 ret = ::AulErrorConvert(ret);
873 extern "C" API int aul_svc_send_launch_request_sync_for_uid(bundle* b,
874 int request_code, bundle** res_b, aul_svc_result_val* res, uid_t uid) {
875 if (b == nullptr || res_b == nullptr || res == nullptr) {
876 _E("Invalid parameter");
877 return AUL_SVC_RET_EINVAL;
880 int ret = ::SendLaunchRequest<::SendLaunchRequestSyncCb, bundle**>(
881 [](const std::string& appid, bundle* request, uid_t uid,
882 bundle** response) -> int {
883 return aul_send_launch_request_sync_for_uid(appid.c_str(), request,
887 auto* val = bundle_get_val(*res_b, AUL_SVC_K_RES_VAL);
888 *res = static_cast<aul_svc_result_val>(
889 (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val));
891 ret = ::AulErrorConvert(ret);
892 *res = AUL_SVC_RES_CANCEL;
898 extern "C" API int aul_svc_info_create(bundle* b, aul_svc_info_h* h) {
899 if (b == nullptr || h == nullptr) {
900 _E("Invalid parameter");
901 return AUL_SVC_RET_EINVAL;
904 aul::ResolveInfo* resolve_info = nullptr;
906 tizen_base::Bundle kb(b, false, false);
907 resolve_info = aul::ResolveInfo::Manager::Create(kb);
908 } catch (aul::Exception& e) {
909 return AUL_SVC_RET_ERROR;
912 *h = static_cast<aul_svc_info_h>(resolve_info);
913 return AUL_SVC_RET_OK;
916 extern "C" API int aul_svc_info_get_operation(aul_svc_info_h h,
918 if (h == nullptr || operation == nullptr) {
919 _E("Invalid parameter");
920 return AUL_SVC_RET_EINVAL;
923 auto* info = static_cast<aul::ResolveInfo*>(h);
924 auto& value = info->GetOperation();
925 *operation = strdup(value.empty() ? "NULL" : value.c_str());
926 if (*operation == nullptr) {
927 _E("Failed to duplicate operation");
928 return AUL_SVC_RET_ERROR;
931 return AUL_SVC_RET_OK;
934 extern "C" API int aul_svc_info_get_uri(aul_svc_info_h h, char** uri) {
935 if (h == nullptr || uri == nullptr) {
936 _E("Invalid parameter");
937 return AUL_SVC_RET_EINVAL;
940 auto* info = static_cast<aul::ResolveInfo*>(h);
941 auto& value = info->GetUri();
942 *uri = strdup(value.empty() ? "NULL" : value.c_str());
943 if (*uri == nullptr) {
944 _E("Failed to duplicate URI");
945 return AUL_SVC_RET_ERROR;
948 return AUL_SVC_RET_OK;
951 extern "C" API int aul_svc_info_get_uri_scheme(aul_svc_info_h h,
953 if (h == nullptr || uri_scheme == nullptr) {
954 _E("Invalid parameter");
955 return AUL_SVC_RET_EINVAL;
958 auto* info = static_cast<aul::ResolveInfo*>(h);
959 auto& value = info->GetScheme();
960 *uri_scheme = strdup(value.empty() ? "NULL" : value.c_str());
961 if (*uri_scheme == nullptr) {
962 _E("Failed to duplicate URI scheme");
963 return AUL_SVC_RET_ERROR;
966 return AUL_SVC_RET_OK;
969 extern "C" API int aul_svc_info_get_uri_host(aul_svc_info_h h,
971 if (h == nullptr || uri_host == nullptr) {
972 _E("Invalid parameter");
973 return AUL_SVC_RET_EINVAL;
976 auto* info = static_cast<aul::ResolveInfo*>(h);
977 auto& value = info->GetHost();
978 *uri_host = strdup(value.empty() ? "NULL" : value.c_str());
979 if (*uri_host == nullptr) {
980 _E("Failed to duplicate URI host");
981 return AUL_SVC_RET_ERROR;
984 return AUL_SVC_RET_OK;
987 extern "C" API int aul_svc_info_get_mime(aul_svc_info_h h, char** mime) {
988 if (h == nullptr || mime == nullptr) {
989 _E("Invalid parameter");
990 return AUL_SVC_RET_EINVAL;
993 auto* info = static_cast<aul::ResolveInfo*>(h);
994 auto& value = info->GetMime();
995 *mime = strdup(value.empty() ? "NULL" : value.c_str());
996 if (*mime == nullptr) {
997 _E("Failed to duplicate MIME-Type");
998 return AUL_SVC_RET_ERROR;
1001 return AUL_SVC_RET_OK;
1004 extern "C" API int aul_svc_info_get_mime_type(aul_svc_info_h h,
1006 if (h == nullptr || mime_type == nullptr) {
1007 _E("Invalid parameter");
1008 return AUL_SVC_RET_EINVAL;
1011 auto* info = static_cast<aul::ResolveInfo*>(h);
1012 auto& value = info->GetMType();
1013 *mime_type = strdup(value.empty() ? "NULL" : value.c_str());
1014 if (*mime_type == nullptr) {
1015 _E("Failed to duplicate the type of MIME-Type");
1016 return AUL_SVC_RET_ERROR;
1019 return AUL_SVC_RET_OK;
1022 extern "C" API int aul_svc_info_get_mime_subtype(aul_svc_info_h h,
1023 char** mime_subtype) {
1024 if (h == nullptr || mime_subtype == nullptr) {
1025 _E("Invalid parameter");
1026 return AUL_SVC_RET_EINVAL;
1029 auto* info = static_cast<aul::ResolveInfo*>(h);
1030 auto& value = info->GetSType();
1031 *mime_subtype = strdup(value.empty() ? "NULL" : value.c_str());
1032 if (*mime_subtype == nullptr) {
1033 _E("Failed to duplicate the subtype of MIME-Type");
1034 return AUL_SVC_RET_ERROR;
1037 return AUL_SVC_RET_OK;
1040 extern "C" API int aul_svc_info_destroy(aul_svc_info_h h) {
1042 _E("Invalid parameter");
1043 return AUL_SVC_RET_EINVAL;
1046 auto* info = static_cast<aul::ResolveInfo*>(h);
1048 return AUL_SVC_RET_OK;
1051 extern "C" API int aul_svc_set_caller_instance_id(bundle* b,
1052 const char* instance_id) {
1054 _E("Invalid parameter");
1055 return AUL_SVC_RET_EINVAL;
1058 return ::SetBundle(b, AUL_K_CALLER_INSTANCE_ID, instance_id);
1061 extern "C" API int aul_svc_set_comp_id(bundle* b, const char* comp_id) {
1063 _E("Invalid parameter");
1064 return AUL_SVC_RET_EINVAL;
1067 return ::SetBundle(b, AUL_K_COMPONENT_ID, comp_id);
1070 extern "C" API const char *aul_svc_get_comp_id(bundle* b) {
1071 return bundle_get_val(b, AUL_K_COMPONENT_ID);
1074 extern "C" API int aul_svc_subapp_terminate_request(bundle* b, int pid) {
1075 if (b == nullptr || pid < 0) {
1076 _E("Invalid parameter");
1077 return AUL_SVC_RET_EINVAL;
1080 const char* inst_id = bundle_get_val(b, AUL_K_INSTANCE_ID);
1081 if (inst_id == nullptr) {
1082 _E("Invalid parameter");
1083 return AUL_SVC_RET_EINVAL;
1086 char buf[512] = { 0, };
1087 const char* caller_inst_id = bundle_get_val(b, AUL_K_CALLER_INSTANCE_ID);
1088 if (caller_inst_id == nullptr) {
1089 int ret = aul_app_get_instance_id_bypid(getpid(), buf, sizeof(buf));
1090 if (ret != AUL_R_OK) {
1091 _E("aul_app_get_instance_id_bypid() is failed. error(%d)", ret);
1092 return AUL_SVC_RET_ERROR;
1095 caller_inst_id = buf;
1099 aul_app_group_foreach_group_info(caller_inst_id,
1100 [](aul_app_group_info_h info, void* data) {
1101 int* count = static_cast<int*>(data);
1103 }, static_cast<void*>(&cnt));
1105 return aul_subapp_terminate_request(inst_id, pid);
1107 return aul_app_group_clear_top();
1110 extern "C" API int aul_svc_send_resume_request(bundle* b, int request_code,
1111 aul_svc_err_cb err_cb, void *user_data) {
1112 return aul_svc_send_resume_request_for_uid(b, request_code, err_cb, user_data,
1116 extern "C" API int aul_svc_send_resume_request_for_uid(bundle* b,
1117 int request_code, aul_svc_err_cb err_cb, void* user_data, uid_t uid) {
1118 if (b == nullptr || err_cb == nullptr) {
1119 _E("Invalid parameter");
1120 return AUL_SVC_RET_EINVAL;
1123 auto* cb_info = new (std::nothrow) CbInfo(request_code, nullptr, err_cb,
1125 if (cb_info == nullptr)
1126 _E("Out of memory");
1128 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
1129 [](const std::string& appid, bundle* request, uid_t uid,
1130 CbInfo* info) -> int {
1131 return aul_send_resume_request_for_uid(appid.c_str(), request, uid,
1133 }, b, uid, cb_info);
1136 ret = ::AulErrorConvert(ret);
1142 extern "C" API int aul_svc_get_appid_array(bundle* b, uid_t uid,
1143 char*** appid_array, unsigned int* len) {
1144 if (b == nullptr || appid_array == nullptr || len == nullptr) {
1145 _E("Invalid parameter");
1146 return AUL_SVC_RET_EINVAL;
1149 bundle_del(b, AUL_K_APPID);
1150 bundle_add(b, AUL_K_APPID, "@UNKNOWN");
1153 int ret = ::SendAndReceive(APP_GET_APPID_LIST, uid, b, &response);
1154 if (ret != AUL_SVC_RET_OK)
1157 tizen_base::Bundle res(response, false, true);
1158 auto str = res.GetString(AUL_SVC_K_URI_R_INFO);
1160 ::SetBundle(b, AUL_SVC_K_URI_R_INFO, str.c_str());
1162 auto str_arr = res.GetStringArray(AUL_K_APPID_LIST);
1163 if (str_arr.empty()) {
1164 _E("Failed to get appid list");
1165 return AUL_SVC_RET_ERROR;
1168 *appid_array = reinterpret_cast<char**>(
1169 calloc(str_arr.size(), sizeof(char*)));
1170 if (*appid_array == nullptr) {
1171 _E("Out of memory");
1172 return AUL_SVC_RET_ENOMEM;
1175 *len = str_arr.size();
1178 for (auto& appid : str_arr)
1179 (*appid_array)[i++] = strdup(appid.c_str());
1181 return AUL_SVC_RET_OK;
1184 extern "C" API void aul_svc_free_appid_array(char** appid_array,
1186 if (appid_array == nullptr)
1189 for (unsigned int i = 0; i < len; ++i)
1190 free(appid_array[i]);
1195 extern "C" API int aul_svc_set_defapp(const char* op, const char* mime_type,
1196 const char* uri, const char* defapp) {
1197 DEPRECATION_WARNING();
1198 return AUL_SVC_RET_OK;
1201 extern "C" API int aul_svc_set_defapp_for_uid(const char* op,
1202 const char* mime_type, const char* uri, const char* defapp, uid_t uid) {
1203 DEPRECATION_WARNING();
1204 return AUL_SVC_RET_OK;
1207 extern "C" API int aul_svc_unset_defapp(const char* defapp) {
1208 DEPRECATION_WARNING();
1209 return AUL_SVC_RET_OK;
1212 extern "C" API int aul_svc_unset_defapp_for_uid(const char* defapp, uid_t uid) {
1213 DEPRECATION_WARNING();
1214 return AUL_SVC_RET_OK;
1217 extern "C" API int aul_svc_unset_all_defapps(void) {
1218 DEPRECATION_WARNING();
1219 return AUL_SVC_RET_OK;
1222 extern "C" API int aul_svc_unset_all_defapps_for_uid(uid_t uid) {
1223 DEPRECATION_WARNING();
1224 return AUL_SVC_RET_OK;
1227 extern "C" API int aul_svc_is_defapp(const char* pkg_name) {
1228 DEPRECATION_WARNING();
1229 return AUL_SVC_RET_OK;
1232 extern "C" API int aul_svc_is_defapp_for_uid(const char* pkg_name, uid_t uid) {
1233 DEPRECATION_WARNING();
1234 return AUL_SVC_RET_OK;
1237 extern "C" API int aul_svc_set_alias_appid(const char* alias_appid,
1238 const char* appid) {
1239 DEPRECATION_WARNING();
1240 return AUL_SVC_RET_OK;
1243 extern "C" API int aul_svc_set_alias_appid_for_uid(const char* alias_appid,
1244 const char* appid, uid_t uid) {
1245 DEPRECATION_WARNING();
1246 return AUL_SVC_RET_OK;
1249 extern "C" API int aul_svc_unset_alias_appid(const char* alias_appid) {
1250 DEPRECATION_WARNING();
1251 return AUL_SVC_RET_OK;
1254 extern "C" API int aul_svc_unset_alias_appid_for_uid(const char* alias_appid,
1256 DEPRECATION_WARNING();
1257 return AUL_SVC_RET_OK;
1260 extern "C" API int aul_svc_foreach_alias_info(
1261 void (*callback)(const char *, const char *, void *),
1263 DEPRECATION_WARNING();
1264 return AUL_SVC_RET_OK;
1267 extern "C" API int aul_svc_foreach_alias_info_for_uid(
1268 void (*callback)(const char *, const char *, void *),
1269 uid_t uid, void* user_data) {
1270 DEPRECATION_WARNING();
1271 return AUL_SVC_RET_OK;
1274 extern "C" API int aul_svc_enable_alias_info(const char* appid) {
1275 DEPRECATION_WARNING();
1276 return AUL_SVC_RET_OK;
1279 extern "C" API int aul_svc_enable_alias_info_for_uid(const char* appid,
1281 DEPRECATION_WARNING();
1282 return AUL_SVC_RET_OK;
1285 extern "C" API int aul_svc_disable_alias_info(const char* appid) {
1286 DEPRECATION_WARNING();
1287 return AUL_SVC_RET_OK;
1290 extern "C" API int aul_svc_disable_alias_info_for_uid(const char* appid,
1292 DEPRECATION_WARNING();
1293 return AUL_SVC_RET_OK;
1296 extern "C" API int aul_svc_foreach_alias_info_by_appid(
1297 int (*callback)(const char *, const char *, void *),
1298 const char* appid, void* user_data) {
1299 DEPRECATION_WARNING();
1300 return AUL_SVC_RET_OK;
1303 extern "C" API int aul_svc_foreach_alias_info_by_appid_for_uid(
1304 int (*callback)(const char *, const char *, void *),
1305 const char* appid, uid_t uid, void* user_data) {
1306 DEPRECATION_WARNING();
1307 return AUL_SVC_RET_OK;
1310 extern "C" API int aul_svc_foreach_allowed_info(
1311 int (*callback)(const char *, const char *, void *),
1313 DEPRECATION_WARNING();
1314 return AUL_SVC_RET_OK;
1317 extern "C" API int aul_svc_foreach_allowed_info_for_uid(
1318 int (*callback)(const char *, const char *, void *),
1319 uid_t uid, void* user_data) {
1320 DEPRECATION_WARNING();
1321 return AUL_SVC_RET_OK;
1324 extern "C" API int aul_svc_foreach_allowed_info_by_appid(
1325 int (*callback)(const char *, const char *, void *),
1326 const char* appid, void* user_data) {
1327 DEPRECATION_WARNING();
1328 return AUL_SVC_RET_OK;
1331 extern "C" API int aul_svc_foreach_allowed_info_by_appid_for_uid(
1332 int (*callback)(const char *, const char *, void *),
1333 const char* appid, uid_t uid, void* user_data) {
1334 DEPRECATION_WARNING();
1335 return AUL_SVC_RET_OK;