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>
33 #include <unordered_map>
36 #include "aul/app_control/resolve_info.hh"
37 #include "aul/include/aul.h"
38 #include "aul/include/aul_app_group.h"
39 #include "aul/include/aul_error.h"
40 #include "aul/include/aul_sock.h"
41 #include "aul/include/aul_svc.h"
42 #include "aul/include/aul_svc_internal.h"
43 #include "aul/aul_api.h"
44 #include "aul/aul_svc_priv_key.h"
45 #include "aul/aul_util.h"
46 #include "aul/launch.h"
48 #undef MAX_MIME_STR_SIZE
49 #define MAX_MIME_STR_SIZE 256
51 #undef MAX_SCHEME_STR_SIZE
52 #define MAX_SCHEME_STR_SIZE 256
54 #undef MAX_HOST_STR_SIZE
55 #define MAX_HOST_STR_SIZE 256
57 #undef DEPRECATION_WARNING
58 #define DEPRECATION_WARNING() do { \
59 dlog_print(DLOG_WARN, LOG_TAG, \
60 "DEPRECATION WARNING: %s() is deprecated and " \
61 "will be removed from next release.", __FUNCTION__); \
66 constexpr const char kPathAmdReady[] = "/run/.amd_ready";
67 constexpr const char kPathLibAulServer[] = LIBDIR "/libaul-server.so.0";
68 constexpr const char kAulServiceForeachUsrAliasInfo[] =
69 "aul_service_foreach_usr_alias_info";
73 CbInfo(int request_code, aul_svc_res_fn res_fn,
74 aul_svc_err_cb err_cb, void* user_data)
75 : request_code_(request_code),
78 user_data_(user_data) {
82 aul_svc_res_fn res_fn_;
83 aul_svc_err_cb err_cb_;
89 explicit AliasInfo(std::string alias_appid)
90 : alias_appid_(std::move(alias_appid)) {
93 std::string alias_appid_;
97 int SetBundle(bundle* b, const char* key, const char* value) {
98 if (bundle_get_type(b, key) != BUNDLE_TYPE_NONE) {
99 if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
100 return AUL_SVC_RET_ERROR;
103 if (value == nullptr)
104 return AUL_SVC_RET_EINVAL;
106 if (bundle_add(b, key, value) != BUNDLE_ERROR_NONE)
107 return AUL_SVC_RET_ERROR;
109 SECURE_LOGD("key(%s), value(%s)", key, value);
110 return AUL_SVC_RET_OK;
113 int SetBundleArray(bundle* b, const char* key, const char** value,
115 int is_array = aul_svc_data_is_array(b, key);
117 if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
118 return AUL_SVC_RET_ERROR;
121 if (value == nullptr)
122 return AUL_SVC_RET_EINVAL;
124 if (bundle_add_str_array(b, key, value, len) != BUNDLE_ERROR_NONE)
125 return AUL_SVC_RET_ERROR;
127 SECURE_LOGD("key(%s), length(%d)", key, len);
128 return AUL_SVC_RET_OK;
131 bool IsSpecialApp(const char* appid) {
132 if (!strcmp(appid, APP_SELECTOR) || !strcmp(appid, SHARE_PANEL))
138 bool IsSpecialOperation(const char* operation) {
139 if (operation == nullptr)
142 int ret = strcmp(operation,
143 "http://tizen.org/appcontrol/operation/guide_privacy_setting");
150 std::string GetAppId(bundle* request) {
151 const char* appid = aul_svc_get_pkgname(request);
152 if (appid == nullptr) {
153 if (aul_svc_get_operation(request) == nullptr) {
154 _E("Invalid request");
161 int ret = bundle_get_type(request, AUL_SVC_K_SELECTOR_EXTRA_LIST);
162 if (ret != BUNDLE_TYPE_NONE) {
163 if (appid == nullptr || !strcmp(appid, "@UNKNOWN"))
164 appid = APP_SELECTOR;
167 ret = bundle_get_type(request, AUL_K_FORCE_LAUNCH_APP_SELECTOR);
168 if (ret != BUNDLE_TYPE_NONE)
169 appid = APP_SELECTOR;
171 return std::string(appid);
174 void SetLaunchData(bundle* request, const std::string& appid) {
175 const char* operation = aul_svc_get_operation(request);
176 if (operation == nullptr)
177 aul_svc_set_operation(request, AUL_SVC_OPERATION_DEFAULT);
179 if (IsSpecialApp(appid.c_str()) || IsSpecialOperation(operation)) {
180 SetBundle(request, AUL_SVC_K_CAN_BE_LEADER, "true");
181 SetBundle(request, AUL_SVC_K_REROUTE, "true");
182 SetBundle(request, AUL_SVC_K_RECYCLE, "true");
185 const char* launch_mode = aul_svc_get_launch_mode(request);
186 if (launch_mode && !strcmp(launch_mode, "group")) {
187 int ret = bundle_get_type(request, AUL_K_INSTANCE_ID);
188 if (ret == BUNDLE_TYPE_NONE)
189 aul_set_instance_info(appid.c_str(), request);
193 int AulErrorConvert(int res) {
196 return AUL_SVC_RET_EILLACC;
198 return AUL_SVC_RET_EINVAL;
199 case AUL_R_ETERMINATING:
200 return AUL_SVC_RET_ETERMINATING;
201 case AUL_R_EREJECTED:
202 return AUL_SVC_RET_EREJECTED;
204 return AUL_SVC_RET_ENOMATCH;
205 case AUL_R_ECANCELED:
206 return AUL_SVC_RET_ECANCELED;
208 return AUL_SVC_RET_ETIMEOUT;
210 return AUL_SVC_RET_ELAUNCH;
214 void LaunchWithResultCb(bundle* b, int is_cancel, void* data) {
217 res = AUL_SVC_RES_CANCEL;
219 const char* val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
220 res = (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val);
223 bundle_del(b, AUL_SVC_K_RES_VAL);
224 auto* cb_info = static_cast<CbInfo*>(data);
225 if (cb_info == nullptr) {
226 _E("Invalid parameter");
230 if (cb_info->res_fn_) {
231 cb_info->res_fn_(b, cb_info->request_code_,
232 static_cast<aul_svc_result_val>(res), cb_info->user_data_);
233 cb_info->res_fn_ = nullptr;
236 if (cb_info->err_cb_ != nullptr)
242 void ErrorCb(int error, void* data) {
244 error = AulErrorConvert(error);
246 auto* cb_info = static_cast<CbInfo*>(data);
247 if (cb_info == nullptr) {
248 _E("Invalid parameter");
252 if (cb_info->err_cb_) {
253 cb_info->err_cb_(cb_info->request_code_, error, cb_info->user_data_);
254 cb_info->err_cb_ = nullptr;
257 if (cb_info->res_fn_)
263 using SendLaunchRequestCb =
264 int (*)(const std::string&, bundle*, uid_t, CbInfo*);
265 using SendLaunchRequestSyncCb =
266 int (*)(const std::string&, bundle*, uid_t, bundle**);
268 template <typename T, typename A>
269 int SendLaunchRequest(T cb, bundle* request, uid_t uid, A arg) {
270 if (request == nullptr) {
271 _E("Invalid parameter");
272 return AUL_SVC_RET_EINVAL;
275 std::string appid = GetAppId(request);
277 _E("GetAppId() is failed");
278 return AUL_SVC_RET_EINVAL;
281 SetLaunchData(request, appid);
282 return cb(appid, request, uid, arg);
285 int SendAndReceive(int cmd, uid_t uid, bundle* request, bundle** response) {
286 int fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, cmd, request,
289 return AUL_SVC_RET_ERROR;
291 app_pkt_t* pkt = nullptr;
292 int ret = aul_sock_recv_reply_pkt(fd, &pkt);
294 _E("Failed to receive reply packet. error(%d)", ret);
295 return AUL_SVC_RET_ERROR;
298 auto ptr = std::unique_ptr<app_pkt_t, decltype(std::free)*>(pkt, std::free);
299 if (pkt->cmd != APP_GET_INFO_OK && pkt->cmd != cmd) {
300 if (pkt->cmd == APP_GET_INFO_ERROR)
301 return AUL_SVC_RET_ERROR;
303 return AulErrorConvert(aul_error_convert(pkt->cmd));
307 if (pkt->opt & AUL_SOCK_BUNDLE) {
308 b = bundle_decode(pkt->data, pkt->len);
310 _E("bundle_decode() is failed");
311 return AUL_SVC_RET_ENOMEM;
314 _E("Invalid packet");
315 return AUL_SVC_RET_ERROR;
319 return AUL_SVC_RET_OK;
322 std::atomic<bool> amd_ready { false };
327 if (access(kPathAmdReady, F_OK) == 0) {
328 amd_ready.exchange(true);
335 using AulServiceAliasInfoCb =
336 bool (*)(const char*, const char*, void*);
337 using AulServiceForeachUsrAliasInfoFunc =
338 int (*)(AulServiceAliasInfoCb, uid_t, void*);
340 int GetAppIdByAliasAppIdFromDB(const char* alias_appid, char** app_id,
342 void* handle = dlopen(kPathLibAulServer, RTLD_LAZY | RTLD_GLOBAL);
343 if (handle == nullptr) {
344 _E("dlopen() is failed. path(%s), error(%s)", kPathLibAulServer, dlerror());
345 return AUL_SVC_RET_ERROR;
348 auto dl_closer = [](void* ptr) {
352 std::unique_ptr<void, decltype(dl_closer)> handle_auto(handle, dl_closer);
353 auto* func = reinterpret_cast<AulServiceForeachUsrAliasInfoFunc>(
354 dlsym(handle, kAulServiceForeachUsrAliasInfo));
355 if (func == nullptr) {
356 _E("dlsym() is failed. error(%s)", dlerror());
357 return AUL_SVC_RET_ERROR;
360 AliasInfo info(alias_appid);
362 [](const char* alias_appid, const char* appid, void* user_data) -> bool {
363 auto* info = static_cast<AliasInfo*>(user_data);
364 if (info->alias_appid_ == alias_appid) {
365 info->appid_ = appid;
372 _E("%s() is failed. error(%d)", kAulServiceForeachUsrAliasInfo, ret);
373 return AUL_SVC_RET_ERROR;
376 if (info.appid_.empty())
377 return AUL_SVC_RET_ERROR;
379 *app_id = strdup(info.appid_.c_str());
380 if (*app_id == nullptr) {
381 _E("strdup() is failed");
382 return AUL_SVC_RET_ENOMEM;
385 return AUL_SVC_RET_OK;
390 extern "C" API int aul_svc_set_operation(bundle* b, const char* operation) {
392 _E("Invalid parameter");
393 return AUL_SVC_RET_EINVAL;
396 return ::SetBundle(b, AUL_SVC_K_OPERATION, operation);
399 extern "C" API int aul_svc_set_uri(bundle* b, const char* uri) {
401 _E("Invalid parameter");
402 return AUL_SVC_RET_EINVAL;
405 return ::SetBundle(b, AUL_SVC_K_URI, uri);
408 extern "C" API int aul_svc_set_mime(bundle* b, const char* mime) {
410 _E("Invalid parameter");
411 return AUL_SVC_RET_EINVAL;
414 return ::SetBundle(b, AUL_SVC_K_MIME, mime);
417 extern "C" API int aul_svc_add_data(bundle* b, const char* key,
419 if (b == nullptr || key == nullptr)
420 return AUL_SVC_RET_EINVAL;
422 return ::SetBundle(b, key, value);
425 extern "C" API int aul_svc_add_data_array(bundle* b, const char* key,
426 const char** value, int len) {
427 if (b == nullptr || key == nullptr)
428 return AUL_SVC_RET_EINVAL;
430 return ::SetBundleArray(b, key, value, len);
433 extern "C" API int aul_svc_set_pkgname(bundle* b, const char* pkg_name) {
435 _E("Invalid parameter");
436 return AUL_SVC_RET_EINVAL;
439 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
442 extern "C" API int aul_svc_set_appid(bundle* b, const char* appid) {
443 if (b == nullptr || appid == nullptr) {
444 _E("Invalid parameter");
445 return AUL_SVC_RET_EINVAL;
448 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, appid);
451 extern "C" API int aul_svc_set_category(bundle* b, const char* category) {
453 _E("Invalid parameter");
454 return AUL_SVC_RET_EINVAL;
457 return ::SetBundle(b, AUL_SVC_K_CATEGORY, category);
460 extern "C" API int aul_svc_set_launch_mode(bundle* b, const char* mode) {
462 _E("Invalid parameter");
463 return AUL_SVC_RET_EINVAL;
466 return ::SetBundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
469 extern "C" API int aul_svc_resolve(bundle* b, uid_t uid, char*** appid_array,
471 return aul_svc_get_appid_array(b, uid, appid_array, len);
474 extern "C" API int aul_svc_run_service(bundle* b, int request_code,
475 aul_svc_res_fn cbfunc, void* data) {
476 return aul_svc_run_service_for_uid(b, request_code, cbfunc, data, getuid());
479 extern "C" API int aul_svc_run_service_for_uid(bundle* b, int request_code,
480 aul_svc_res_fn cbfunc, void* data, uid_t uid) {
481 CbInfo* cb_info = nullptr;
483 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
484 if (cb_info == nullptr)
485 LOGE("Out of memory");
488 std::tuple<aul_svc_res_fn, void*> param { cbfunc, data };
489 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
490 [](const std::string& appid, bundle* request, uid_t uid,
491 CbInfo* cb_info) -> int {
494 ret = aul_launch_app_with_result_for_uid(appid.c_str(), request,
495 LaunchWithResultCb, cb_info, uid);
497 ret = aul_launch_app_for_uid(appid.c_str(), request, uid);
506 ret = AulErrorConvert(ret);
512 extern "C" API int aul_svc_get_list(bundle* b, aul_svc_info_iter_fn iter_fn,
514 return aul_svc_get_list_for_uid(b, iter_fn, data, getuid());
517 extern "C" API int aul_svc_get_list_for_uid(bundle* b,
518 aul_svc_info_iter_fn iter_fn, void* data, uid_t uid) {
519 if (b == nullptr || iter_fn == nullptr) {
520 _E("Invalid parameter");
521 return AUL_SVC_RET_EINVAL;
524 char** appid_array = nullptr;
525 unsigned int len = 0;
526 int ret = aul_svc_get_appid_array(b, uid, &appid_array, &len);
527 if (ret != AUL_SVC_RET_OK)
531 _E("Failed to find associated application");
532 aul_svc_free_appid_array(appid_array, len);
533 return AUL_SVC_RET_ENOMATCH;
536 for (unsigned int i = 0; i < len; ++i) {
537 SECURE_LOGD("APPID: %s", appid_array[i]);
538 if (iter_fn(appid_array[i], data) != 0)
542 aul_svc_free_appid_array(appid_array, len);
543 return AUL_SVC_RET_OK;
546 extern "C" API int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn,
548 return aul_svc_get_all_defapps_for_uid(iter_fn, data, getuid());
551 extern "C" API int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
552 void* data, uid_t uid) {
553 if (iter_fn == nullptr) {
554 _E("Invalid parameter");
555 return AUL_SVC_RET_EINVAL;
559 tizen_base::Bundle request;
560 int ret = ::SendAndReceive(APP_GET_APP_CONTROL_DEFAULT_APPS, uid,
561 request.GetHandle(), &response);
562 if (ret != AUL_SVC_RET_OK)
565 tizen_base::Bundle res(response, false, true);
566 auto appid_array = res.GetStringArray(AUL_K_APPID_LIST);
567 for (auto& appid : appid_array) {
568 if (iter_fn(appid.c_str(), data) != 0)
572 return AUL_SVC_RET_OK;
575 extern "C" API const char* aul_svc_get_operation(bundle* b) {
576 return bundle_get_val(b, AUL_SVC_K_OPERATION);
579 extern "C" API const char* aul_svc_get_uri(bundle* b) {
580 return bundle_get_val(b, AUL_SVC_K_URI);
583 extern "C" API const char* aul_svc_get_mime(bundle* b) {
584 return bundle_get_val(b, AUL_SVC_K_MIME);
587 extern "C" API const char* aul_svc_get_data(bundle* b, const char* key) {
588 return bundle_get_val(b, key);
591 extern "C" API const char** aul_svc_get_data_array(bundle* b, const char* key,
593 return bundle_get_str_array(b, key, len);
596 extern "C" API const char* aul_svc_get_pkgname(bundle* b) {
597 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
600 extern "C" API const char* aul_svc_get_appid(bundle* b) {
601 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
604 extern "C" API const char* aul_svc_get_category(bundle* b) {
605 return bundle_get_val(b, AUL_SVC_K_CATEGORY);
608 extern "C" API const char* aul_svc_get_launch_mode(bundle* b) {
609 return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
612 extern "C" API int aul_svc_create_result_bundle(bundle* inb, bundle** outb) {
613 if (inb == nullptr || outb == nullptr) {
614 _E("Invalid parameter");
615 return AUL_SVC_RET_EINVAL;
618 int ret = aul_create_result_bundle(inb, outb);
620 return AulErrorConvert(ret);
622 return AUL_SVC_RET_OK;
625 extern "C" API int aul_svc_send_result(bundle* b, aul_svc_result_val result) {
627 _E("Invalid parameter");
628 return AUL_SVC_RET_EINVAL;
631 int ret = ::SetBundle(b, AUL_SVC_K_RES_VAL, std::to_string(result).c_str());
633 return AUL_SVC_RET_ERROR;
635 if (result == AUL_SVC_RES_CANCEL)
636 ret = aul_send_result(b, 1);
638 ret = aul_send_result(b, 0);
640 bundle_del(b, AUL_SVC_K_RES_VAL);
644 extern "C" API int aul_svc_data_is_array(bundle* b, const char* key) {
645 int type = bundle_get_type(b, key);
649 if (type & BUNDLE_TYPE_ARRAY)
655 extern "C" API int aul_svc_allow_transient_app(bundle* b, int wid) {
657 _E("Invalid parameter");
658 return AUL_SVC_RET_EINVAL;
661 return ::SetBundle(b, AUL_SVC_K_WIN_ID, std::to_string(wid).c_str());
664 extern "C" API int aul_svc_request_transient_app(bundle* b, int callee_wid,
665 aul_svc_host_res_fn cbfunc, void* data) {
669 extern "C" API int aul_svc_subapp_terminate_request_pid(int pid) {
672 int* lpids = nullptr;
673 aul_app_group_get_leader_pids(&lcnt, &lpids);
674 for (int i = 0; i < lcnt; ++i) {
675 if (lpids[i] == cpid) {
678 aul_app_group_get_group_pids(cpid, &cnt, &pids);
684 return aul_subapp_terminate_request_pid(pid);
693 if (lpids != nullptr)
696 return aul_app_group_clear_top();
699 extern "C" API int aul_send_service_result(bundle* b) {
700 return aul_send_result(b, 0);
703 extern "C" API int aul_svc_subscribe_launch_result(bundle* b,
704 const char* result) {
706 _E("Invalid parameter");
707 return AUL_SVC_RET_EINVAL;
710 return ::SetBundle(b, result, "1");
713 extern "C" API int aul_svc_set_loader_id(bundle* b, int loader_id) {
714 if (b == nullptr || loader_id <= 0) {
715 _E("Invalid parameter");
716 return AUL_SVC_RET_EINVAL;
719 return ::SetBundle(b, AUL_K_LOADER_ID, std::to_string(loader_id).c_str());
722 extern "C" API int aul_svc_set_loader_name(bundle* b, const char* loader_name) {
723 if (b == nullptr || loader_name == nullptr) {
724 _E("Invalid parameter");
725 return AUL_SVC_RET_EINVAL;
728 return ::SetBundle(b, AUL_K_LOADER_NAME, loader_name);
731 extern "C" API int aul_svc_set_background_launch(bundle* b, int enabled) {
733 _E("Invalid parameter");
734 return AUL_SVC_RET_EINVAL;
737 return ::SetBundle(b, AUL_SVC_K_BG_LAUNCH, enabled ? "enable" : nullptr);
740 extern "C" API int aul_svc_get_appid_by_alias_appid(const char* alias_appid,
742 return aul_svc_get_appid_by_alias_appid_for_uid(alias_appid, appid, getuid());
745 extern "C" API int aul_svc_get_appid_by_alias_appid_for_uid(
746 const char* alias_appid, char** appid, uid_t uid) {
747 if (alias_appid == nullptr || appid == nullptr) {
748 _E("Invalid parameter");
749 return AUL_SVC_RET_EINVAL;
753 return GetAppIdByAliasAppIdFromDB(alias_appid, appid, uid);
756 tizen_base::Bundle request;
757 request.Add(AUL_K_ALIAS_APPID, alias_appid);
758 int ret = ::SendAndReceive(APP_GET_APPID_BY_ALIAS_APPID, uid,
759 request.GetHandle(), &response);
760 if (ret != AUL_SVC_RET_OK)
763 tizen_base::Bundle res(response, false, true);
764 auto val = res.GetString(AUL_K_APPID);
766 return AUL_SVC_RET_ERROR;
768 *appid = strdup(val.c_str());
769 if (*appid == nullptr) {
771 return AUL_SVC_RET_ENOMEM;
774 return AUL_SVC_RET_OK;
777 extern "C" API const char *aul_svc_get_instance_id(bundle* b) {
778 return bundle_get_val(b, AUL_K_INSTANCE_ID);
781 extern "C" API int aul_svc_set_instance_id(bundle* b, const char* instance_id) {
783 _E("Invalid parameter");
784 return AUL_SVC_RET_EINVAL;
787 return ::SetBundle(b, AUL_K_INSTANCE_ID, instance_id);
790 extern "C" API int aul_svc_run_service_async(bundle* b, int request_code,
791 aul_svc_res_fn cbfunc, void* data) {
792 return aul_svc_run_service_async_for_uid(b, request_code, cbfunc, data,
796 extern "C" API int aul_svc_run_service_async_for_uid(bundle* b,
797 int request_code, aul_svc_res_fn cbfunc, void* data, uid_t uid) {
798 CbInfo* cb_info = nullptr;
800 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
802 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
803 [](const std::string& appid, bundle* request, uid_t uid,
804 CbInfo* info) -> int {
806 return aul_launch_app_with_result_async_for_uid(appid.c_str(),
807 request, LaunchWithResultCb, info, uid);
810 return aul_launch_app_async_for_uid(appid.c_str(), request, uid);
816 ret = AulErrorConvert(ret);
822 extern "C" API int aul_svc_send_launch_request(bundle* b, int request_code,
823 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void* user_data) {
824 return aul_svc_send_launch_request_for_uid(b, request_code,
825 cbfunc, err_cb, user_data, getuid());
828 extern "C" API int aul_svc_send_launch_request_for_uid(bundle* b,
829 int request_code, aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
830 void* user_data, uid_t uid) {
831 if (b == nullptr || err_cb == nullptr) {
832 _E("Invalid parameter");
833 return AUL_SVC_RET_EINVAL;
836 CbInfo* cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, err_cb,
838 if (cb_info == nullptr)
841 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
842 [](const std::string& appid, bundle* request, uid_t uid,
843 CbInfo* info) -> int {
844 return aul_send_launch_request_for_uid(appid.c_str(), request, uid,
845 info->res_fn_ ? ::LaunchWithResultCb : nullptr, ::ErrorCb, info);
849 ret = ::AulErrorConvert(ret);
855 extern "C" API int aul_svc_send_launch_request_sync_for_uid(bundle* b,
856 int request_code, bundle** res_b, aul_svc_result_val* res, uid_t uid) {
857 if (b == nullptr || res_b == nullptr || res == nullptr) {
858 _E("Invalid parameter");
859 return AUL_SVC_RET_EINVAL;
862 int ret = ::SendLaunchRequest<::SendLaunchRequestSyncCb, bundle**>(
863 [](const std::string& appid, bundle* request, uid_t uid,
864 bundle** response) -> int {
865 return aul_send_launch_request_sync_for_uid(appid.c_str(), request,
869 auto* val = bundle_get_val(*res_b, AUL_SVC_K_RES_VAL);
870 *res = static_cast<aul_svc_result_val>(
871 (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val));
873 ret = ::AulErrorConvert(ret);
874 *res = AUL_SVC_RES_CANCEL;
880 extern "C" API int aul_svc_info_create(bundle* b, aul_svc_info_h* h) {
881 if (b == nullptr || h == nullptr) {
882 _E("Invalid parameter");
883 return AUL_SVC_RET_EINVAL;
886 aul::ResolveInfo* resolve_info = nullptr;
888 tizen_base::Bundle kb(b, false, false);
889 resolve_info = aul::ResolveInfo::Manager::Create(kb);
890 } catch (aul::Exception& e) {
891 return AUL_SVC_RET_ERROR;
894 *h = static_cast<aul_svc_info_h>(resolve_info);
895 return AUL_SVC_RET_OK;
898 extern "C" API int aul_svc_info_get_operation(aul_svc_info_h h,
900 if (h == nullptr || operation == nullptr) {
901 _E("Invalid parameter");
902 return AUL_SVC_RET_EINVAL;
905 auto* info = static_cast<aul::ResolveInfo*>(h);
906 auto& value = info->GetOperation();
907 *operation = strdup(value.empty() ? "NULL" : value.c_str());
908 if (*operation == nullptr) {
909 _E("Failed to duplicate operation");
910 return AUL_SVC_RET_ERROR;
913 return AUL_SVC_RET_OK;
916 extern "C" API int aul_svc_info_get_uri(aul_svc_info_h h, char** uri) {
917 if (h == nullptr || uri == nullptr) {
918 _E("Invalid parameter");
919 return AUL_SVC_RET_EINVAL;
922 auto* info = static_cast<aul::ResolveInfo*>(h);
923 auto& value = info->GetUri();
924 *uri = strdup(value.empty() ? "NULL" : value.c_str());
925 if (*uri == nullptr) {
926 _E("Failed to duplicate URI");
927 return AUL_SVC_RET_ERROR;
930 return AUL_SVC_RET_OK;
933 extern "C" API int aul_svc_info_get_uri_scheme(aul_svc_info_h h,
935 if (h == nullptr || uri_scheme == nullptr) {
936 _E("Invalid parameter");
937 return AUL_SVC_RET_EINVAL;
940 auto* info = static_cast<aul::ResolveInfo*>(h);
941 auto& value = info->GetScheme();
942 *uri_scheme = strdup(value.empty() ? "NULL" : value.c_str());
943 if (*uri_scheme == nullptr) {
944 _E("Failed to duplicate URI scheme");
945 return AUL_SVC_RET_ERROR;
948 return AUL_SVC_RET_OK;
951 extern "C" API int aul_svc_info_get_uri_host(aul_svc_info_h h,
953 if (h == nullptr || uri_host == nullptr) {
954 _E("Invalid parameter");
955 return AUL_SVC_RET_EINVAL;
958 auto* info = static_cast<aul::ResolveInfo*>(h);
959 auto& value = info->GetHost();
960 *uri_host = strdup(value.empty() ? "NULL" : value.c_str());
961 if (*uri_host == nullptr) {
962 _E("Failed to duplicate URI host");
963 return AUL_SVC_RET_ERROR;
966 return AUL_SVC_RET_OK;
969 extern "C" API int aul_svc_info_get_mime(aul_svc_info_h h, char** mime) {
970 if (h == nullptr || mime == nullptr) {
971 _E("Invalid parameter");
972 return AUL_SVC_RET_EINVAL;
975 auto* info = static_cast<aul::ResolveInfo*>(h);
976 auto& value = info->GetMime();
977 *mime = strdup(value.empty() ? "NULL" : value.c_str());
978 if (*mime == nullptr) {
979 _E("Failed to duplicate MIME-Type");
980 return AUL_SVC_RET_ERROR;
983 return AUL_SVC_RET_OK;
986 extern "C" API int aul_svc_info_get_mime_type(aul_svc_info_h h,
988 if (h == nullptr || mime_type == nullptr) {
989 _E("Invalid parameter");
990 return AUL_SVC_RET_EINVAL;
993 auto* info = static_cast<aul::ResolveInfo*>(h);
994 auto& value = info->GetMType();
995 *mime_type = strdup(value.empty() ? "NULL" : value.c_str());
996 if (*mime_type == nullptr) {
997 _E("Failed to duplicate the type of MIME-Type");
998 return AUL_SVC_RET_ERROR;
1001 return AUL_SVC_RET_OK;
1004 extern "C" API int aul_svc_info_get_mime_subtype(aul_svc_info_h h,
1005 char** mime_subtype) {
1006 if (h == nullptr || mime_subtype == nullptr) {
1007 _E("Invalid parameter");
1008 return AUL_SVC_RET_EINVAL;
1011 auto* info = static_cast<aul::ResolveInfo*>(h);
1012 auto& value = info->GetSType();
1013 *mime_subtype = strdup(value.empty() ? "NULL" : value.c_str());
1014 if (*mime_subtype == nullptr) {
1015 _E("Failed to duplicate the subtype of MIME-Type");
1016 return AUL_SVC_RET_ERROR;
1019 return AUL_SVC_RET_OK;
1022 extern "C" API int aul_svc_info_destroy(aul_svc_info_h h) {
1024 _E("Invalid parameter");
1025 return AUL_SVC_RET_EINVAL;
1028 auto* info = static_cast<aul::ResolveInfo*>(h);
1030 return AUL_SVC_RET_OK;
1033 extern "C" API int aul_svc_set_caller_instance_id(bundle* b,
1034 const char* instance_id) {
1036 _E("Invalid parameter");
1037 return AUL_SVC_RET_EINVAL;
1040 return ::SetBundle(b, AUL_K_CALLER_INSTANCE_ID, instance_id);
1043 extern "C" API int aul_svc_set_comp_id(bundle* b, const char* comp_id) {
1045 _E("Invalid parameter");
1046 return AUL_SVC_RET_EINVAL;
1049 return ::SetBundle(b, AUL_K_COMPONENT_ID, comp_id);
1052 extern "C" API const char *aul_svc_get_comp_id(bundle* b) {
1053 return bundle_get_val(b, AUL_K_COMPONENT_ID);
1056 extern "C" API int aul_svc_subapp_terminate_request(bundle* b, int pid) {
1057 if (b == nullptr || pid < 0) {
1058 _E("Invalid parameter");
1059 return AUL_SVC_RET_EINVAL;
1062 const char* inst_id = bundle_get_val(b, AUL_K_INSTANCE_ID);
1063 if (inst_id == nullptr) {
1064 _E("Invalid parameter");
1065 return AUL_SVC_RET_EINVAL;
1068 char buf[512] = { 0, };
1069 const char* caller_inst_id = bundle_get_val(b, AUL_K_CALLER_INSTANCE_ID);
1070 if (caller_inst_id == nullptr) {
1071 int ret = aul_app_get_instance_id_bypid(getpid(), buf, sizeof(buf));
1072 if (ret != AUL_R_OK) {
1073 _E("aul_app_get_instance_id_bypid() is failed. error(%d)", ret);
1074 return AUL_SVC_RET_ERROR;
1077 caller_inst_id = buf;
1081 aul_app_group_foreach_group_info(caller_inst_id,
1082 [](aul_app_group_info_h info, void* data) {
1083 int* count = static_cast<int*>(data);
1085 }, static_cast<void*>(&cnt));
1087 return aul_subapp_terminate_request(inst_id, pid);
1089 return aul_app_group_clear_top();
1092 extern "C" API int aul_svc_send_resume_request(bundle* b, int request_code,
1093 aul_svc_err_cb err_cb, void *user_data) {
1094 return aul_svc_send_resume_request_for_uid(b, request_code, err_cb, user_data,
1098 extern "C" API int aul_svc_send_resume_request_for_uid(bundle* b,
1099 int request_code, aul_svc_err_cb err_cb, void* user_data, uid_t uid) {
1100 if (b == nullptr || err_cb == nullptr) {
1101 _E("Invalid parameter");
1102 return AUL_SVC_RET_EINVAL;
1105 auto* cb_info = new (std::nothrow) CbInfo(request_code, nullptr, err_cb,
1107 if (cb_info == nullptr)
1108 _E("Out of memory");
1110 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
1111 [](const std::string& appid, bundle* request, uid_t uid,
1112 CbInfo* info) -> int {
1113 return aul_send_resume_request_for_uid(appid.c_str(), request, uid,
1115 }, b, uid, cb_info);
1118 ret = ::AulErrorConvert(ret);
1124 extern "C" API int aul_svc_get_appid_array(bundle* b, uid_t uid,
1125 char*** appid_array, unsigned int* len) {
1126 if (b == nullptr || appid_array == nullptr || len == nullptr) {
1127 _E("Invalid parameter");
1128 return AUL_SVC_RET_EINVAL;
1131 bundle_del(b, AUL_K_APPID);
1132 bundle_add(b, AUL_K_APPID, "@UNKNOWN");
1135 int ret = ::SendAndReceive(APP_GET_APPID_LIST, uid, b, &response);
1136 if (ret != AUL_SVC_RET_OK)
1139 tizen_base::Bundle res(response, false, true);
1140 auto str = res.GetString(AUL_SVC_K_URI_R_INFO);
1142 ::SetBundle(b, AUL_SVC_K_URI_R_INFO, str.c_str());
1144 auto str_arr = res.GetStringArray(AUL_K_APPID_LIST);
1145 if (str_arr.empty()) {
1146 _E("Failed to get appid list");
1147 return AUL_SVC_RET_ERROR;
1150 *appid_array = reinterpret_cast<char**>(
1151 calloc(str_arr.size(), sizeof(char*)));
1152 if (*appid_array == nullptr) {
1153 _E("Out of memory");
1154 return AUL_SVC_RET_ENOMEM;
1157 *len = str_arr.size();
1160 for (auto& appid : str_arr)
1161 (*appid_array)[i++] = strdup(appid.c_str());
1163 return AUL_SVC_RET_OK;
1166 extern "C" API void aul_svc_free_appid_array(char** appid_array,
1168 if (appid_array == nullptr)
1171 for (unsigned int i = 0; i < len; ++i)
1172 free(appid_array[i]);
1177 extern "C" API int aul_svc_set_window_position(bundle* b,
1178 int x, int y, int w, int h) {
1180 _E("Invalid parameter");
1181 return AUL_SVC_RET_EINVAL;
1184 ::SetBundle(b, AUL_K_HINT_SCREEN_POS_X, std::to_string(x).c_str());
1185 ::SetBundle(b, AUL_K_HINT_SCREEN_POS_Y, std::to_string(y).c_str());
1186 ::SetBundle(b, AUL_K_HINT_SCREEN_WIDTH, std::to_string(w).c_str());
1187 ::SetBundle(b, AUL_K_HINT_SCREEN_HEIGHT, std::to_string(h).c_str());
1189 return AUL_SVC_RET_OK;
1192 extern "C" API int aul_svc_get_window_position(bundle* b,
1193 int* x, int* y, int* w, int* h) {
1199 _E("Invalid parameter");
1200 return AUL_SVC_RET_EINVAL;
1203 char* x_str = nullptr;
1204 char* y_str = nullptr;
1205 char* w_str = nullptr;
1206 char* h_str = nullptr;
1208 bundle_get_str(b , AUL_K_HINT_SCREEN_POS_X, &x_str);
1209 bundle_get_str(b , AUL_K_HINT_SCREEN_POS_Y, &y_str);
1210 bundle_get_str(b , AUL_K_HINT_SCREEN_WIDTH, &w_str);
1211 bundle_get_str(b , AUL_K_HINT_SCREEN_HEIGHT, &h_str);
1213 if (x_str == nullptr ||
1217 _E("failed to get position");
1218 return AUL_SVC_RET_ERROR;
1226 return AUL_SVC_RET_OK;
1229 extern "C" API int aul_svc_set_defapp(const char* op, const char* mime_type,
1230 const char* uri, const char* defapp) {
1231 DEPRECATION_WARNING();
1232 return AUL_SVC_RET_OK;
1235 extern "C" API int aul_svc_set_defapp_for_uid(const char* op,
1236 const char* mime_type, const char* uri, const char* defapp, uid_t uid) {
1237 DEPRECATION_WARNING();
1238 return AUL_SVC_RET_OK;
1241 extern "C" API int aul_svc_unset_defapp(const char* defapp) {
1242 DEPRECATION_WARNING();
1243 return AUL_SVC_RET_OK;
1246 extern "C" API int aul_svc_unset_defapp_for_uid(const char* defapp, uid_t uid) {
1247 DEPRECATION_WARNING();
1248 return AUL_SVC_RET_OK;
1251 extern "C" API int aul_svc_unset_all_defapps(void) {
1252 DEPRECATION_WARNING();
1253 return AUL_SVC_RET_OK;
1256 extern "C" API int aul_svc_unset_all_defapps_for_uid(uid_t uid) {
1257 DEPRECATION_WARNING();
1258 return AUL_SVC_RET_OK;
1261 extern "C" API int aul_svc_is_defapp(const char* pkg_name) {
1262 DEPRECATION_WARNING();
1263 return AUL_SVC_RET_OK;
1266 extern "C" API int aul_svc_is_defapp_for_uid(const char* pkg_name, uid_t uid) {
1267 DEPRECATION_WARNING();
1268 return AUL_SVC_RET_OK;
1271 extern "C" API int aul_svc_set_alias_appid(const char* alias_appid,
1272 const char* appid) {
1273 DEPRECATION_WARNING();
1274 return AUL_SVC_RET_OK;
1277 extern "C" API int aul_svc_set_alias_appid_for_uid(const char* alias_appid,
1278 const char* appid, uid_t uid) {
1279 DEPRECATION_WARNING();
1280 return AUL_SVC_RET_OK;
1283 extern "C" API int aul_svc_unset_alias_appid(const char* alias_appid) {
1284 DEPRECATION_WARNING();
1285 return AUL_SVC_RET_OK;
1288 extern "C" API int aul_svc_unset_alias_appid_for_uid(const char* alias_appid,
1290 DEPRECATION_WARNING();
1291 return AUL_SVC_RET_OK;
1294 extern "C" API int aul_svc_foreach_alias_info(
1295 void (*callback)(const char *, const char *, void *),
1297 DEPRECATION_WARNING();
1298 return AUL_SVC_RET_OK;
1301 extern "C" API int aul_svc_foreach_alias_info_for_uid(
1302 void (*callback)(const char *, const char *, void *),
1303 uid_t uid, void* user_data) {
1304 DEPRECATION_WARNING();
1305 return AUL_SVC_RET_OK;
1308 extern "C" API int aul_svc_enable_alias_info(const char* appid) {
1309 DEPRECATION_WARNING();
1310 return AUL_SVC_RET_OK;
1313 extern "C" API int aul_svc_enable_alias_info_for_uid(const char* appid,
1315 DEPRECATION_WARNING();
1316 return AUL_SVC_RET_OK;
1319 extern "C" API int aul_svc_disable_alias_info(const char* appid) {
1320 DEPRECATION_WARNING();
1321 return AUL_SVC_RET_OK;
1324 extern "C" API int aul_svc_disable_alias_info_for_uid(const char* appid,
1326 DEPRECATION_WARNING();
1327 return AUL_SVC_RET_OK;
1330 extern "C" API int aul_svc_foreach_alias_info_by_appid(
1331 int (*callback)(const char *, const char *, void *),
1332 const char* appid, void* user_data) {
1333 DEPRECATION_WARNING();
1334 return AUL_SVC_RET_OK;
1337 extern "C" API int aul_svc_foreach_alias_info_by_appid_for_uid(
1338 int (*callback)(const char *, const char *, void *),
1339 const char* appid, uid_t uid, void* user_data) {
1340 DEPRECATION_WARNING();
1341 return AUL_SVC_RET_OK;
1344 extern "C" API int aul_svc_foreach_allowed_info(
1345 int (*callback)(const char *, const char *, void *),
1347 DEPRECATION_WARNING();
1348 return AUL_SVC_RET_OK;
1351 extern "C" API int aul_svc_foreach_allowed_info_for_uid(
1352 int (*callback)(const char *, const char *, void *),
1353 uid_t uid, void* user_data) {
1354 DEPRECATION_WARNING();
1355 return AUL_SVC_RET_OK;
1358 extern "C" API int aul_svc_foreach_allowed_info_by_appid(
1359 int (*callback)(const char *, const char *, void *),
1360 const char* appid, void* user_data) {
1361 DEPRECATION_WARNING();
1362 return AUL_SVC_RET_OK;
1365 extern "C" API int aul_svc_foreach_allowed_info_by_appid_for_uid(
1366 int (*callback)(const char *, const char *, void *),
1367 const char* appid, uid_t uid, void* user_data) {
1368 DEPRECATION_WARNING();
1369 return AUL_SVC_RET_OK;