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[] = "/usr/lib/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_ELAUNCH;
227 void LaunchWithResultCb(bundle* b, int is_cancel, void* data) {
230 res = AUL_SVC_RES_CANCEL;
232 const char* val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
233 res = (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val);
236 bundle_del(b, AUL_SVC_K_RES_VAL);
237 auto* cb_info = static_cast<CbInfo*>(data);
238 if (cb_info == nullptr) {
239 _E("Invalid parameter");
243 if (cb_info->res_fn_) {
244 cb_info->res_fn_(b, cb_info->request_code_,
245 static_cast<aul_svc_result_val>(res), cb_info->user_data_);
246 cb_info->res_fn_ = nullptr;
249 if (cb_info->err_cb_ != nullptr)
255 void ErrorCb(int error, void* data) {
257 error = AulErrorConvert(error);
259 auto* cb_info = static_cast<CbInfo*>(data);
260 if (cb_info == nullptr) {
261 _E("Invalid parameter");
265 if (cb_info->err_cb_) {
266 cb_info->err_cb_(cb_info->request_code_, error, cb_info->user_data_);
267 cb_info->err_cb_ = nullptr;
270 if (cb_info->res_fn_)
276 using SendLaunchRequestCb =
277 int (*)(const std::string&, bundle*, uid_t, CbInfo*);
278 using SendLaunchRequestSyncCb =
279 int (*)(const std::string&, bundle*, uid_t, bundle**);
281 template <typename T, typename A>
282 int SendLaunchRequest(T cb, bundle* request, uid_t uid, A arg) {
283 if (request == nullptr) {
284 _E("Invalid parameter");
285 return AUL_SVC_RET_EINVAL;
288 std::string appid = GetAppId(request);
290 _E("GetAppId() is failed");
291 return AUL_SVC_RET_EINVAL;
294 SetLaunchData(request, appid);
295 return cb(appid, request, uid, arg);
298 int SendAndReceive(int cmd, uid_t uid, bundle* request, bundle** response) {
299 int fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, cmd, request,
302 return AUL_SVC_RET_ERROR;
304 app_pkt_t* pkt = nullptr;
305 int ret = aul_sock_recv_reply_pkt(fd, &pkt);
307 _E("Failed to receive reply packet. error(%d)", ret);
308 return AUL_SVC_RET_ERROR;
311 auto ptr = std::unique_ptr<app_pkt_t, decltype(std::free)*>(pkt, std::free);
312 if (pkt->cmd != APP_GET_INFO_OK && pkt->cmd != cmd) {
313 if (pkt->cmd == APP_GET_INFO_ERROR)
314 return AUL_SVC_RET_ERROR;
316 return AulErrorConvert(aul_error_convert(pkt->cmd));
320 if (pkt->opt & AUL_SOCK_BUNDLE) {
321 b = bundle_decode(pkt->data, pkt->len);
323 _E("bundle_decode() is failed");
324 return AUL_SVC_RET_ENOMEM;
327 _E("Invalid packet");
328 return AUL_SVC_RET_ERROR;
332 return AUL_SVC_RET_OK;
335 std::atomic<bool> amd_ready { false };
340 if (access(kPathAmdReady, F_OK) == 0) {
341 amd_ready.exchange(true);
348 using AulServiceAliasInfoCb =
349 bool (*)(const char*, const char*, void*);
350 using AulServiceForeachUsrAliasInfoFunc =
351 int (*)(AulServiceAliasInfoCb, uid_t, void*);
353 int GetAppIdByAliasAppIdFromDB(const char* alias_appid, char** app_id,
355 void* handle = dlopen(kPathLibAulServer, RTLD_LAZY | RTLD_GLOBAL);
356 if (handle == nullptr) {
357 _E("dlopen() is failed. path(%s), error(%s)", kPathLibAulServer, dlerror());
358 return AUL_SVC_RET_ERROR;
361 auto dl_closer = [](void* ptr) {
365 std::unique_ptr<void, decltype(dl_closer)> handle_auto(handle, dl_closer);
366 auto* func = reinterpret_cast<AulServiceForeachUsrAliasInfoFunc>(
367 dlsym(handle, kAulServiceForeachUsrAliasInfo));
368 if (func == nullptr) {
369 _E("dlsym() is failed. error(%s)", dlerror());
370 return AUL_SVC_RET_ERROR;
373 AliasInfo info(alias_appid);
375 [](const char* alias_appid, const char* appid, void* user_data) -> bool {
376 auto* info = static_cast<AliasInfo*>(user_data);
377 if (info->alias_appid_ == alias_appid) {
378 info->appid_ = appid;
385 _E("%s() is failed. error(%d)", kAulServiceForeachUsrAliasInfo, ret);
386 return AUL_SVC_RET_ERROR;
389 if (info.appid_.empty())
390 return AUL_SVC_RET_ERROR;
392 *app_id = strdup(info.appid_.c_str());
393 if (*app_id == nullptr) {
394 _E("strdup() is failed");
395 return AUL_SVC_RET_ENOMEM;
398 return AUL_SVC_RET_OK;
403 extern "C" API int aul_svc_set_operation(bundle* b, const char* operation) {
405 _E("Invalid parameter");
406 return AUL_SVC_RET_EINVAL;
409 return ::SetBundle(b, AUL_SVC_K_OPERATION, operation);
412 extern "C" API int aul_svc_set_uri(bundle* b, const char* uri) {
414 _E("Invalid parameter");
415 return AUL_SVC_RET_EINVAL;
418 return ::SetBundle(b, AUL_SVC_K_URI, uri);
421 extern "C" API int aul_svc_set_mime(bundle* b, const char* mime) {
423 _E("Invalid parameter");
424 return AUL_SVC_RET_EINVAL;
427 return ::SetBundle(b, AUL_SVC_K_MIME, mime);
430 extern "C" API int aul_svc_add_data(bundle* b, const char* key,
432 if (b == nullptr || key == nullptr)
433 return AUL_SVC_RET_EINVAL;
435 return ::SetBundle(b, key, value);
438 extern "C" API int aul_svc_add_data_array(bundle* b, const char* key,
439 const char** value, int len) {
440 if (b == nullptr || key == nullptr)
441 return AUL_SVC_RET_EINVAL;
443 return ::SetBundleArray(b, key, value, len);
446 extern "C" API int aul_svc_set_pkgname(bundle* b, const char* pkg_name) {
448 _E("Invalid parameter");
449 return AUL_SVC_RET_EINVAL;
452 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
455 extern "C" API int aul_svc_set_appid(bundle* b, const char* appid) {
456 if (b == nullptr || appid == nullptr) {
457 _E("Invalid parameter");
458 return AUL_SVC_RET_EINVAL;
461 std::string alias_id = ::GetAliasAppId(appid);
462 if (!alias_id.empty())
463 appid = alias_id.c_str();
465 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, appid);
468 extern "C" API int aul_svc_set_category(bundle* b, const char* category) {
470 _E("Invalid parameter");
471 return AUL_SVC_RET_EINVAL;
474 return ::SetBundle(b, AUL_SVC_K_CATEGORY, category);
477 extern "C" API int aul_svc_set_launch_mode(bundle* b, const char* mode) {
479 _E("Invalid parameter");
480 return AUL_SVC_RET_EINVAL;
483 return ::SetBundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
486 extern "C" API int aul_svc_resolve(bundle* b, uid_t uid, char*** appid_array,
488 return aul_svc_get_appid_array(b, uid, appid_array, len);
491 extern "C" API int aul_svc_run_service(bundle* b, int request_code,
492 aul_svc_res_fn cbfunc, void* data) {
493 return aul_svc_run_service_for_uid(b, request_code, cbfunc, data, getuid());
496 extern "C" API int aul_svc_run_service_for_uid(bundle* b, int request_code,
497 aul_svc_res_fn cbfunc, void* data, uid_t uid) {
498 CbInfo* cb_info = nullptr;
500 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
501 if (cb_info == nullptr)
502 LOGE("Out of memory");
505 std::tuple<aul_svc_res_fn, void*> param { cbfunc, data };
506 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
507 [](const std::string& appid, bundle* request, uid_t uid,
508 CbInfo* cb_info) -> int {
511 ret = aul_launch_app_with_result_for_uid(appid.c_str(), request,
512 LaunchWithResultCb, cb_info, uid);
514 ret = aul_launch_app_for_uid(appid.c_str(), request, uid);
523 ret = AulErrorConvert(ret);
529 extern "C" API int aul_svc_get_list(bundle* b, aul_svc_info_iter_fn iter_fn,
531 return aul_svc_get_list_for_uid(b, iter_fn, data, getuid());
534 extern "C" API int aul_svc_get_list_for_uid(bundle* b,
535 aul_svc_info_iter_fn iter_fn, void* data, uid_t uid) {
536 if (b == nullptr || iter_fn == nullptr) {
537 _E("Invalid parameter");
538 return AUL_SVC_RET_EINVAL;
541 char** appid_array = nullptr;
542 unsigned int len = 0;
543 int ret = aul_svc_get_appid_array(b, uid, &appid_array, &len);
544 if (ret != AUL_SVC_RET_OK)
548 _E("Failed to find associated application");
549 aul_svc_free_appid_array(appid_array, len);
550 return AUL_SVC_RET_ENOMATCH;
553 for (unsigned int i = 0; i < len; ++i) {
554 SECURE_LOGD("APPID: %s", appid_array[i]);
555 if (iter_fn(appid_array[i], data) != 0)
559 aul_svc_free_appid_array(appid_array, len);
560 return AUL_SVC_RET_OK;
563 extern "C" API int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn,
565 return aul_svc_get_all_defapps_for_uid(iter_fn, data, getuid());
568 extern "C" API int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
569 void* data, uid_t uid) {
570 if (iter_fn == nullptr) {
571 _E("Invalid parameter");
572 return AUL_SVC_RET_EINVAL;
576 tizen_base::Bundle request;
577 int ret = ::SendAndReceive(APP_GET_APP_CONTROL_DEFAULT_APPS, uid,
578 request.GetHandle(), &response);
579 if (ret != AUL_SVC_RET_OK)
582 tizen_base::Bundle res(response, false, true);
583 auto appid_array = res.GetStringArray(AUL_K_APPID_LIST);
584 for (auto& appid : appid_array) {
585 if (iter_fn(appid.c_str(), data) != 0)
589 return AUL_SVC_RET_OK;
592 extern "C" API const char* aul_svc_get_operation(bundle* b) {
593 return bundle_get_val(b, AUL_SVC_K_OPERATION);
596 extern "C" API const char* aul_svc_get_uri(bundle* b) {
597 return bundle_get_val(b, AUL_SVC_K_URI);
600 extern "C" API const char* aul_svc_get_mime(bundle* b) {
601 return bundle_get_val(b, AUL_SVC_K_MIME);
604 extern "C" API const char* aul_svc_get_data(bundle* b, const char* key) {
605 return bundle_get_val(b, key);
608 extern "C" API const char** aul_svc_get_data_array(bundle* b, const char* key,
610 return bundle_get_str_array(b, key, len);
613 extern "C" API const char* aul_svc_get_pkgname(bundle* b) {
614 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
617 extern "C" API const char* aul_svc_get_appid(bundle* b) {
618 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
621 extern "C" API const char* aul_svc_get_category(bundle* b) {
622 return bundle_get_val(b, AUL_SVC_K_CATEGORY);
625 extern "C" API const char* aul_svc_get_launch_mode(bundle* b) {
626 return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
629 extern "C" API int aul_svc_create_result_bundle(bundle* inb, bundle** outb) {
630 if (inb == nullptr || outb == nullptr) {
631 _E("Invalid parameter");
632 return AUL_SVC_RET_EINVAL;
635 int ret = aul_create_result_bundle(inb, outb);
637 return AulErrorConvert(ret);
639 return AUL_SVC_RET_OK;
642 extern "C" API int aul_svc_send_result(bundle* b, aul_svc_result_val result) {
644 _E("Invalid parameter");
645 return AUL_SVC_RET_EINVAL;
648 int ret = ::SetBundle(b, AUL_SVC_K_RES_VAL, std::to_string(result).c_str());
650 return AUL_SVC_RET_ERROR;
652 if (result == AUL_SVC_RES_CANCEL)
653 ret = aul_send_result(b, 1);
655 ret = aul_send_result(b, 0);
657 bundle_del(b, AUL_SVC_K_RES_VAL);
661 extern "C" API int aul_svc_data_is_array(bundle* b, const char* key) {
662 int type = bundle_get_type(b, key);
666 if (type & BUNDLE_TYPE_ARRAY)
672 extern "C" API int aul_svc_allow_transient_app(bundle* b, int wid) {
674 _E("Invalid parameter");
675 return AUL_SVC_RET_EINVAL;
678 return ::SetBundle(b, AUL_SVC_K_WIN_ID, std::to_string(wid).c_str());
681 extern "C" API int aul_svc_request_transient_app(bundle* b, int callee_wid,
682 aul_svc_host_res_fn cbfunc, void* data) {
686 extern "C" API int aul_svc_subapp_terminate_request_pid(int pid) {
689 int* lpids = nullptr;
690 aul_app_group_get_leader_pids(&lcnt, &lpids);
691 for (int i = 0; i < lcnt; ++i) {
692 if (lpids[i] == cpid) {
695 aul_app_group_get_group_pids(cpid, &cnt, &pids);
701 return aul_subapp_terminate_request_pid(pid);
710 if (lpids != nullptr)
713 return aul_app_group_clear_top();
716 extern "C" API int aul_send_service_result(bundle* b) {
717 return aul_send_result(b, 0);
720 extern "C" API int aul_svc_subscribe_launch_result(bundle* b,
721 const char* result) {
723 _E("Invalid parameter");
724 return AUL_SVC_RET_EINVAL;
727 return ::SetBundle(b, result, "1");
730 extern "C" API int aul_svc_set_loader_id(bundle* b, int loader_id) {
731 if (b == nullptr || loader_id <= 0) {
732 _E("Invalid parameter");
733 return AUL_SVC_RET_EINVAL;
736 return ::SetBundle(b, AUL_K_LOADER_ID, std::to_string(loader_id).c_str());
739 extern "C" API int aul_svc_set_loader_name(bundle* b, const char* loader_name) {
740 if (b == nullptr || loader_name == nullptr) {
741 _E("Invalid parameter");
742 return AUL_SVC_RET_EINVAL;
745 return ::SetBundle(b, AUL_K_LOADER_NAME, loader_name);
748 extern "C" API int aul_svc_set_background_launch(bundle* b, int enabled) {
750 _E("Invalid parameter");
751 return AUL_SVC_RET_EINVAL;
754 return ::SetBundle(b, AUL_SVC_K_BG_LAUNCH, enabled ? "enable" : nullptr);
757 extern "C" API int aul_svc_get_appid_by_alias_appid(const char* alias_appid,
759 return aul_svc_get_appid_by_alias_appid_for_uid(alias_appid, appid, getuid());
762 extern "C" API int aul_svc_get_appid_by_alias_appid_for_uid(
763 const char* alias_appid, char** appid, uid_t uid) {
764 if (alias_appid == nullptr || appid == nullptr) {
765 _E("Invalid parameter");
766 return AUL_SVC_RET_EINVAL;
770 return GetAppIdByAliasAppIdFromDB(alias_appid, appid, uid);
773 tizen_base::Bundle request;
774 request.Add(AUL_K_ALIAS_APPID, alias_appid);
775 int ret = ::SendAndReceive(APP_GET_APPID_BY_ALIAS_APPID, uid,
776 request.GetHandle(), &response);
777 if (ret != AUL_SVC_RET_OK)
780 tizen_base::Bundle res(response, false, true);
781 auto val = res.GetString(AUL_K_APPID);
783 return AUL_SVC_RET_ERROR;
785 *appid = strdup(val.c_str());
786 if (*appid == nullptr) {
788 return AUL_SVC_RET_ENOMEM;
791 return AUL_SVC_RET_OK;
794 extern "C" API const char *aul_svc_get_instance_id(bundle* b) {
795 return bundle_get_val(b, AUL_K_INSTANCE_ID);
798 extern "C" API int aul_svc_set_instance_id(bundle* b, const char* instance_id) {
800 _E("Invalid parameter");
801 return AUL_SVC_RET_EINVAL;
804 return ::SetBundle(b, AUL_K_INSTANCE_ID, instance_id);
807 extern "C" API int aul_svc_run_service_async(bundle* b, int request_code,
808 aul_svc_res_fn cbfunc, void* data) {
809 return aul_svc_run_service_async_for_uid(b, request_code, cbfunc, data,
813 extern "C" API int aul_svc_run_service_async_for_uid(bundle* b,
814 int request_code, aul_svc_res_fn cbfunc, void* data, uid_t uid) {
815 CbInfo* cb_info = nullptr;
817 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
819 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
820 [](const std::string& appid, bundle* request, uid_t uid,
821 CbInfo* info) -> int {
823 return aul_launch_app_with_result_async_for_uid(appid.c_str(),
824 request, LaunchWithResultCb, info, uid);
827 return aul_launch_app_async_for_uid(appid.c_str(), request, uid);
833 ret = AulErrorConvert(ret);
839 extern "C" API int aul_svc_send_launch_request(bundle* b, int request_code,
840 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void* user_data) {
841 return aul_svc_send_launch_request_for_uid(b, request_code,
842 cbfunc, err_cb, user_data, getuid());
845 extern "C" API int aul_svc_send_launch_request_for_uid(bundle* b,
846 int request_code, aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
847 void* user_data, uid_t uid) {
848 if (b == nullptr || err_cb == nullptr) {
849 _E("Invalid parameter");
850 return AUL_SVC_RET_EINVAL;
853 CbInfo* cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, err_cb,
855 if (cb_info == nullptr)
858 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
859 [](const std::string& appid, bundle* request, uid_t uid,
860 CbInfo* info) -> int {
861 return aul_send_launch_request_for_uid(appid.c_str(), request, uid,
862 info->res_fn_ ? ::LaunchWithResultCb : nullptr, ::ErrorCb, info);
866 ret = ::AulErrorConvert(ret);
872 extern "C" API int aul_svc_send_launch_request_sync_for_uid(bundle* b,
873 int request_code, bundle** res_b, aul_svc_result_val* res, uid_t uid) {
874 if (b == nullptr || res_b == nullptr || res == nullptr) {
875 _E("Invalid parameter");
876 return AUL_SVC_RET_EINVAL;
879 int ret = ::SendLaunchRequest<::SendLaunchRequestSyncCb, bundle**>(
880 [](const std::string& appid, bundle* request, uid_t uid,
881 bundle** response) -> int {
882 return aul_send_launch_request_sync_for_uid(appid.c_str(), request,
886 auto* val = bundle_get_val(*res_b, AUL_SVC_K_RES_VAL);
887 *res = static_cast<aul_svc_result_val>(
888 (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val));
890 ret = ::AulErrorConvert(ret);
891 *res = AUL_SVC_RES_CANCEL;
897 extern "C" API int aul_svc_info_create(bundle* b, aul_svc_info_h* h) {
898 if (b == nullptr || h == nullptr) {
899 _E("Invalid parameter");
900 return AUL_SVC_RET_EINVAL;
903 aul::ResolveInfo* resolve_info = nullptr;
905 tizen_base::Bundle kb(b, false, false);
906 resolve_info = aul::ResolveInfo::Manager::Create(kb);
907 } catch (aul::Exception& e) {
908 return AUL_SVC_RET_ERROR;
911 *h = static_cast<aul_svc_info_h>(resolve_info);
912 return AUL_SVC_RET_OK;
915 extern "C" API int aul_svc_info_get_operation(aul_svc_info_h h,
917 if (h == nullptr || operation == nullptr) {
918 _E("Invalid parameter");
919 return AUL_SVC_RET_EINVAL;
922 auto* info = static_cast<aul::ResolveInfo*>(h);
923 auto& value = info->GetOperation();
924 *operation = strdup(value.empty() ? "NULL" : value.c_str());
925 if (*operation == nullptr) {
926 _E("Failed to duplicate operation");
927 return AUL_SVC_RET_ERROR;
930 return AUL_SVC_RET_OK;
933 extern "C" API int aul_svc_info_get_uri(aul_svc_info_h h, char** uri) {
934 if (h == nullptr || uri == nullptr) {
935 _E("Invalid parameter");
936 return AUL_SVC_RET_EINVAL;
939 auto* info = static_cast<aul::ResolveInfo*>(h);
940 auto& value = info->GetUri();
941 *uri = strdup(value.empty() ? "NULL" : value.c_str());
942 if (*uri == nullptr) {
943 _E("Failed to duplicate URI");
944 return AUL_SVC_RET_ERROR;
947 return AUL_SVC_RET_OK;
950 extern "C" API int aul_svc_info_get_uri_scheme(aul_svc_info_h h,
952 if (h == nullptr || uri_scheme == nullptr) {
953 _E("Invalid parameter");
954 return AUL_SVC_RET_EINVAL;
957 auto* info = static_cast<aul::ResolveInfo*>(h);
958 auto& value = info->GetScheme();
959 *uri_scheme = strdup(value.empty() ? "NULL" : value.c_str());
960 if (*uri_scheme == nullptr) {
961 _E("Failed to duplicate URI scheme");
962 return AUL_SVC_RET_ERROR;
965 return AUL_SVC_RET_OK;
968 extern "C" API int aul_svc_info_get_uri_host(aul_svc_info_h h,
970 if (h == nullptr || uri_host == nullptr) {
971 _E("Invalid parameter");
972 return AUL_SVC_RET_EINVAL;
975 auto* info = static_cast<aul::ResolveInfo*>(h);
976 auto& value = info->GetHost();
977 *uri_host = strdup(value.empty() ? "NULL" : value.c_str());
978 if (*uri_host == nullptr) {
979 _E("Failed to duplicate URI host");
980 return AUL_SVC_RET_ERROR;
983 return AUL_SVC_RET_OK;
986 extern "C" API int aul_svc_info_get_mime(aul_svc_info_h h, char** mime) {
987 if (h == nullptr || mime == nullptr) {
988 _E("Invalid parameter");
989 return AUL_SVC_RET_EINVAL;
992 auto* info = static_cast<aul::ResolveInfo*>(h);
993 auto& value = info->GetMime();
994 *mime = strdup(value.empty() ? "NULL" : value.c_str());
995 if (*mime == nullptr) {
996 _E("Failed to duplicate MIME-Type");
997 return AUL_SVC_RET_ERROR;
1000 return AUL_SVC_RET_OK;
1003 extern "C" API int aul_svc_info_get_mime_type(aul_svc_info_h h,
1005 if (h == nullptr || mime_type == nullptr) {
1006 _E("Invalid parameter");
1007 return AUL_SVC_RET_EINVAL;
1010 auto* info = static_cast<aul::ResolveInfo*>(h);
1011 auto& value = info->GetMType();
1012 *mime_type = strdup(value.empty() ? "NULL" : value.c_str());
1013 if (*mime_type == nullptr) {
1014 _E("Failed to duplicate the type of MIME-Type");
1015 return AUL_SVC_RET_ERROR;
1018 return AUL_SVC_RET_OK;
1021 extern "C" API int aul_svc_info_get_mime_subtype(aul_svc_info_h h,
1022 char** mime_subtype) {
1023 if (h == nullptr || mime_subtype == nullptr) {
1024 _E("Invalid parameter");
1025 return AUL_SVC_RET_EINVAL;
1028 auto* info = static_cast<aul::ResolveInfo*>(h);
1029 auto& value = info->GetSType();
1030 *mime_subtype = strdup(value.empty() ? "NULL" : value.c_str());
1031 if (*mime_subtype == nullptr) {
1032 _E("Failed to duplicate the subtype of MIME-Type");
1033 return AUL_SVC_RET_ERROR;
1036 return AUL_SVC_RET_OK;
1039 extern "C" API int aul_svc_info_destroy(aul_svc_info_h h) {
1041 _E("Invalid parameter");
1042 return AUL_SVC_RET_EINVAL;
1045 auto* info = static_cast<aul::ResolveInfo*>(h);
1047 return AUL_SVC_RET_OK;
1050 extern "C" API int aul_svc_set_caller_instance_id(bundle* b,
1051 const char* instance_id) {
1053 _E("Invalid parameter");
1054 return AUL_SVC_RET_EINVAL;
1057 return ::SetBundle(b, AUL_K_CALLER_INSTANCE_ID, instance_id);
1060 extern "C" API int aul_svc_set_comp_id(bundle* b, const char* comp_id) {
1062 _E("Invalid parameter");
1063 return AUL_SVC_RET_EINVAL;
1066 return ::SetBundle(b, AUL_K_COMPONENT_ID, comp_id);
1069 extern "C" API const char *aul_svc_get_comp_id(bundle* b) {
1070 return bundle_get_val(b, AUL_K_COMPONENT_ID);
1073 extern "C" API int aul_svc_subapp_terminate_request(bundle* b, int pid) {
1074 if (b == nullptr || pid < 0) {
1075 _E("Invalid parameter");
1076 return AUL_SVC_RET_EINVAL;
1079 const char* inst_id = bundle_get_val(b, AUL_K_INSTANCE_ID);
1080 if (inst_id == nullptr) {
1081 _E("Invalid parameter");
1082 return AUL_SVC_RET_EINVAL;
1085 char buf[512] = { 0, };
1086 const char* caller_inst_id = bundle_get_val(b, AUL_K_CALLER_INSTANCE_ID);
1087 if (caller_inst_id == nullptr) {
1088 int ret = aul_app_get_instance_id_bypid(getpid(), buf, sizeof(buf));
1089 if (ret != AUL_R_OK) {
1090 _E("aul_app_get_instance_id_bypid() is failed. error(%d)", ret);
1091 return AUL_SVC_RET_ERROR;
1094 caller_inst_id = buf;
1098 aul_app_group_foreach_group_info(caller_inst_id,
1099 [](aul_app_group_info_h info, void* data) {
1100 int* count = static_cast<int*>(data);
1102 }, static_cast<void*>(&cnt));
1104 return aul_subapp_terminate_request(inst_id, pid);
1106 return aul_app_group_clear_top();
1109 extern "C" API int aul_svc_send_resume_request(bundle* b, int request_code,
1110 aul_svc_err_cb err_cb, void *user_data) {
1111 return aul_svc_send_resume_request_for_uid(b, request_code, err_cb, user_data,
1115 extern "C" API int aul_svc_send_resume_request_for_uid(bundle* b,
1116 int request_code, aul_svc_err_cb err_cb, void* user_data, uid_t uid) {
1117 if (b == nullptr || err_cb == nullptr) {
1118 _E("Invalid parameter");
1119 return AUL_SVC_RET_EINVAL;
1122 auto* cb_info = new (std::nothrow) CbInfo(request_code, nullptr, err_cb,
1124 if (cb_info == nullptr)
1125 _E("Out of memory");
1127 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
1128 [](const std::string& appid, bundle* request, uid_t uid,
1129 CbInfo* info) -> int {
1130 return aul_send_resume_request_for_uid(appid.c_str(), request, uid,
1132 }, b, uid, cb_info);
1135 ret = ::AulErrorConvert(ret);
1141 extern "C" API int aul_svc_get_appid_array(bundle* b, uid_t uid,
1142 char*** appid_array, unsigned int* len) {
1143 if (b == nullptr || appid_array == nullptr || len == nullptr) {
1144 _E("Invalid parameter");
1145 return AUL_SVC_RET_EINVAL;
1148 bundle_del(b, AUL_K_APPID);
1149 bundle_add(b, AUL_K_APPID, "@UNKNOWN");
1152 int ret = ::SendAndReceive(APP_GET_APPID_LIST, uid, b, &response);
1153 if (ret != AUL_SVC_RET_OK)
1156 tizen_base::Bundle res(response, false, true);
1157 auto str = res.GetString(AUL_SVC_K_URI_R_INFO);
1159 ::SetBundle(b, AUL_SVC_K_URI_R_INFO, str.c_str());
1161 auto str_arr = res.GetStringArray(AUL_K_APPID_LIST);
1162 if (str_arr.empty()) {
1163 _E("Failed to get appid list");
1164 return AUL_SVC_RET_ERROR;
1167 *appid_array = reinterpret_cast<char**>(
1168 calloc(str_arr.size(), sizeof(char*)));
1169 if (*appid_array == nullptr) {
1170 _E("Out of memory");
1171 return AUL_SVC_RET_ENOMEM;
1174 *len = str_arr.size();
1177 for (auto& appid : str_arr)
1178 (*appid_array)[i++] = strdup(appid.c_str());
1180 return AUL_SVC_RET_OK;
1183 extern "C" API void aul_svc_free_appid_array(char** appid_array,
1185 if (appid_array == nullptr)
1188 for (unsigned int i = 0; i < len; ++i)
1189 free(appid_array[i]);
1194 extern "C" API int aul_svc_set_defapp(const char* op, const char* mime_type,
1195 const char* uri, const char* defapp) {
1196 DEPRECATION_WARNING();
1197 return AUL_SVC_RET_OK;
1200 extern "C" API int aul_svc_set_defapp_for_uid(const char* op,
1201 const char* mime_type, const char* uri, const char* defapp, uid_t uid) {
1202 DEPRECATION_WARNING();
1203 return AUL_SVC_RET_OK;
1206 extern "C" API int aul_svc_unset_defapp(const char* defapp) {
1207 DEPRECATION_WARNING();
1208 return AUL_SVC_RET_OK;
1211 extern "C" API int aul_svc_unset_defapp_for_uid(const char* defapp, uid_t uid) {
1212 DEPRECATION_WARNING();
1213 return AUL_SVC_RET_OK;
1216 extern "C" API int aul_svc_unset_all_defapps(void) {
1217 DEPRECATION_WARNING();
1218 return AUL_SVC_RET_OK;
1221 extern "C" API int aul_svc_unset_all_defapps_for_uid(uid_t uid) {
1222 DEPRECATION_WARNING();
1223 return AUL_SVC_RET_OK;
1226 extern "C" API int aul_svc_is_defapp(const char* pkg_name) {
1227 DEPRECATION_WARNING();
1228 return AUL_SVC_RET_OK;
1231 extern "C" API int aul_svc_is_defapp_for_uid(const char* pkg_name, uid_t uid) {
1232 DEPRECATION_WARNING();
1233 return AUL_SVC_RET_OK;
1236 extern "C" API int aul_svc_set_alias_appid(const char* alias_appid,
1237 const char* appid) {
1238 DEPRECATION_WARNING();
1239 return AUL_SVC_RET_OK;
1242 extern "C" API int aul_svc_set_alias_appid_for_uid(const char* alias_appid,
1243 const char* appid, uid_t uid) {
1244 DEPRECATION_WARNING();
1245 return AUL_SVC_RET_OK;
1248 extern "C" API int aul_svc_unset_alias_appid(const char* alias_appid) {
1249 DEPRECATION_WARNING();
1250 return AUL_SVC_RET_OK;
1253 extern "C" API int aul_svc_unset_alias_appid_for_uid(const char* alias_appid,
1255 DEPRECATION_WARNING();
1256 return AUL_SVC_RET_OK;
1259 extern "C" API int aul_svc_foreach_alias_info(
1260 void (*callback)(const char *, const char *, void *),
1262 DEPRECATION_WARNING();
1263 return AUL_SVC_RET_OK;
1266 extern "C" API int aul_svc_foreach_alias_info_for_uid(
1267 void (*callback)(const char *, const char *, void *),
1268 uid_t uid, void* user_data) {
1269 DEPRECATION_WARNING();
1270 return AUL_SVC_RET_OK;
1273 extern "C" API int aul_svc_enable_alias_info(const char* appid) {
1274 DEPRECATION_WARNING();
1275 return AUL_SVC_RET_OK;
1278 extern "C" API int aul_svc_enable_alias_info_for_uid(const char* appid,
1280 DEPRECATION_WARNING();
1281 return AUL_SVC_RET_OK;
1284 extern "C" API int aul_svc_disable_alias_info(const char* appid) {
1285 DEPRECATION_WARNING();
1286 return AUL_SVC_RET_OK;
1289 extern "C" API int aul_svc_disable_alias_info_for_uid(const char* appid,
1291 DEPRECATION_WARNING();
1292 return AUL_SVC_RET_OK;
1295 extern "C" API int aul_svc_foreach_alias_info_by_appid(
1296 int (*callback)(const char *, const char *, void *),
1297 const char* appid, void* user_data) {
1298 DEPRECATION_WARNING();
1299 return AUL_SVC_RET_OK;
1302 extern "C" API int aul_svc_foreach_alias_info_by_appid_for_uid(
1303 int (*callback)(const char *, const char *, void *),
1304 const char* appid, uid_t uid, void* user_data) {
1305 DEPRECATION_WARNING();
1306 return AUL_SVC_RET_OK;
1309 extern "C" API int aul_svc_foreach_allowed_info(
1310 int (*callback)(const char *, const char *, void *),
1312 DEPRECATION_WARNING();
1313 return AUL_SVC_RET_OK;
1316 extern "C" API int aul_svc_foreach_allowed_info_for_uid(
1317 int (*callback)(const char *, const char *, void *),
1318 uid_t uid, void* user_data) {
1319 DEPRECATION_WARNING();
1320 return AUL_SVC_RET_OK;
1323 extern "C" API int aul_svc_foreach_allowed_info_by_appid(
1324 int (*callback)(const char *, const char *, void *),
1325 const char* appid, void* user_data) {
1326 DEPRECATION_WARNING();
1327 return AUL_SVC_RET_OK;
1330 extern "C" API int aul_svc_foreach_allowed_info_by_appid_for_uid(
1331 int (*callback)(const char *, const char *, void *),
1332 const char* appid, uid_t uid, void* user_data) {
1333 DEPRECATION_WARNING();
1334 return AUL_SVC_RET_OK;