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 "include/aul.h"
38 #include "include/aul_app_group.h"
39 #include "include/aul_error.h"
40 #include "include/aul_sock.h"
41 #include "include/aul_svc.h"
42 #include "include/aul_svc_internal.h"
43 #include "src/aul_api.h"
44 #include "src/aul_svc_priv_key.h"
45 #include "src/aul_util.h"
46 #include "src/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_;
99 AppSvcAlias() = default;
102 std::lock_guard<std::mutex> lock(mutex_);
106 dictionary* dict = iniparser_load("/usr/share/appsvc/alias.ini");
107 if (dict == nullptr) {
112 std::string delimiter = "Alias:";
113 for (int i = 0; i < dict->n; ++i) {
114 if (dict->key[i] == nullptr || dict->val[i] == nullptr)
117 std::string key = dict->key[i];
118 key.erase(0, key.find(delimiter) + delimiter.length() + 1);
119 std::string value = dict->val[i];
123 iniparser_freedict(dict);
127 std::string GetAliasAppId(const std::string& alias_appid) {
128 auto found = map_.find(alias_appid);
129 if (found == map_.end())
132 SECURE_LOGD("alias_appid: %s, appid: %s",
133 alias_appid.c_str(), found->second.c_str());
134 return found->second;
138 bool loaded_ = false;
139 std::unordered_map<std::string, std::string> map_;
143 AppSvcAlias appsvc_alias;
145 int SetBundle(bundle* b, const char* key, const char* value) {
146 if (bundle_get_type(b, key) != BUNDLE_TYPE_NONE) {
147 if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
148 return AUL_SVC_RET_ERROR;
151 if (value == nullptr)
152 return AUL_SVC_RET_EINVAL;
154 if (bundle_add(b, key, value) != BUNDLE_ERROR_NONE)
155 return AUL_SVC_RET_ERROR;
157 SECURE_LOGD("key(%s), value(%s)", key, value);
158 return AUL_SVC_RET_OK;
161 int SetBundleArray(bundle* b, const char* key, const char** value,
163 int is_array = aul_svc_data_is_array(b, key);
165 if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
166 return AUL_SVC_RET_ERROR;
169 if (value == nullptr)
170 return AUL_SVC_RET_EINVAL;
172 if (bundle_add_str_array(b, key, value, len) != BUNDLE_ERROR_NONE)
173 return AUL_SVC_RET_ERROR;
175 SECURE_LOGD("key(%s), length(%d)", key, len);
176 return AUL_SVC_RET_OK;
179 std::string GetAliasAppId(const char* appid) {
181 return appsvc_alias.GetAliasAppId(appid);
184 bool IsSpecialApp(const char* appid) {
185 if (!strcmp(appid, APP_SELECTOR) || !strcmp(appid, SHARE_PANEL))
191 bool IsSpecialOperation(const char* operation) {
192 if (operation == nullptr)
195 int ret = strcmp(operation,
196 "http://tizen.org/appcontrol/operation/guide_privacy_setting");
203 std::string GetAppId(bundle* request) {
204 const char* appid = aul_svc_get_pkgname(request);
205 if (appid == nullptr) {
206 if (aul_svc_get_operation(request) == nullptr) {
207 _E("Invalid request");
214 int ret = bundle_get_type(request, AUL_SVC_K_SELECTOR_EXTRA_LIST);
215 if (ret != BUNDLE_TYPE_NONE) {
216 if (appid == nullptr || !strcmp(appid, "@UNKNOWN"))
217 appid = APP_SELECTOR;
220 ret = bundle_get_type(request, AUL_K_FORCE_LAUNCH_APP_SELECTOR);
221 if (ret != BUNDLE_TYPE_NONE)
222 appid = APP_SELECTOR;
224 return std::string(appid);
227 void SetLaunchData(bundle* request, const std::string& appid) {
228 const char* operation = aul_svc_get_operation(request);
229 if (operation == nullptr)
230 aul_svc_set_operation(request, AUL_SVC_OPERATION_DEFAULT);
232 if (IsSpecialApp(appid.c_str()) || IsSpecialOperation(operation)) {
233 SetBundle(request, AUL_SVC_K_CAN_BE_LEADER, "true");
234 SetBundle(request, AUL_SVC_K_REROUTE, "true");
235 SetBundle(request, AUL_SVC_K_RECYCLE, "true");
238 const char* launch_mode = aul_svc_get_launch_mode(request);
239 if (launch_mode && !strcmp(launch_mode, "group")) {
240 int ret = bundle_get_type(request, AUL_K_INSTANCE_ID);
241 if (ret == BUNDLE_TYPE_NONE)
242 aul_set_instance_info(appid.c_str(), request);
246 int AulErrorConvert(int res) {
249 return AUL_SVC_RET_EILLACC;
251 return AUL_SVC_RET_EINVAL;
252 case AUL_R_ETERMINATING:
253 return AUL_SVC_RET_ETERMINATING;
254 case AUL_R_EREJECTED:
255 return AUL_SVC_RET_EREJECTED;
257 return AUL_SVC_RET_ENOMATCH;
258 case AUL_R_ECANCELED:
259 return AUL_SVC_RET_ECANCELED;
261 return AUL_SVC_RET_ETIMEOUT;
263 return AUL_SVC_RET_ELAUNCH;
267 void LaunchWithResultCb(bundle* b, int is_cancel, void* data) {
270 res = AUL_SVC_RES_CANCEL;
272 const char* val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
273 res = (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val);
276 bundle_del(b, AUL_SVC_K_RES_VAL);
277 auto* cb_info = static_cast<CbInfo*>(data);
278 if (cb_info == nullptr) {
279 _E("Invalid parameter");
283 if (cb_info->res_fn_) {
284 cb_info->res_fn_(b, cb_info->request_code_,
285 static_cast<aul_svc_result_val>(res), cb_info->user_data_);
286 cb_info->res_fn_ = nullptr;
289 if (cb_info->err_cb_ != nullptr)
295 void ErrorCb(int error, void* data) {
297 error = AulErrorConvert(error);
299 auto* cb_info = static_cast<CbInfo*>(data);
300 if (cb_info == nullptr) {
301 _E("Invalid parameter");
305 if (cb_info->err_cb_) {
306 cb_info->err_cb_(cb_info->request_code_, error, cb_info->user_data_);
307 cb_info->err_cb_ = nullptr;
310 if (cb_info->res_fn_)
316 using SendLaunchRequestCb =
317 int (*)(const std::string&, bundle*, uid_t, CbInfo*);
318 using SendLaunchRequestSyncCb =
319 int (*)(const std::string&, bundle*, uid_t, bundle**);
321 template <typename T, typename A>
322 int SendLaunchRequest(T cb, bundle* request, uid_t uid, A arg) {
323 if (request == nullptr) {
324 _E("Invalid parameter");
325 return AUL_SVC_RET_EINVAL;
328 std::string appid = GetAppId(request);
330 _E("GetAppId() is failed");
331 return AUL_SVC_RET_EINVAL;
334 SetLaunchData(request, appid);
335 return cb(appid, request, uid, arg);
338 int SendAndReceive(int cmd, uid_t uid, bundle* request, bundle** response) {
339 int fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, cmd, request,
342 return AUL_SVC_RET_ERROR;
344 app_pkt_t* pkt = nullptr;
345 int ret = aul_sock_recv_reply_pkt(fd, &pkt);
347 _E("Failed to receive reply packet. error(%d)", ret);
348 return AUL_SVC_RET_ERROR;
351 auto ptr = std::unique_ptr<app_pkt_t, decltype(std::free)*>(pkt, std::free);
352 if (pkt->cmd != APP_GET_INFO_OK && pkt->cmd != cmd) {
353 if (pkt->cmd == APP_GET_INFO_ERROR)
354 return AUL_SVC_RET_ERROR;
356 return AulErrorConvert(aul_error_convert(pkt->cmd));
360 if (pkt->opt & AUL_SOCK_BUNDLE) {
361 b = bundle_decode(pkt->data, pkt->len);
363 _E("bundle_decode() is failed");
364 return AUL_SVC_RET_ENOMEM;
367 _E("Invalid packet");
368 return AUL_SVC_RET_ERROR;
372 return AUL_SVC_RET_OK;
375 std::atomic<bool> amd_ready { false };
380 if (access(kPathAmdReady, F_OK) == 0) {
381 amd_ready.exchange(true);
388 using AulServiceAliasInfoCb =
389 bool (*)(const char*, const char*, void*);
390 using AulServiceForeachUsrAliasInfoFunc =
391 int (*)(AulServiceAliasInfoCb, uid_t, void*);
393 int GetAppIdByAliasAppIdFromDB(const char* alias_appid, char** app_id,
395 void* handle = dlopen(kPathLibAulServer, RTLD_LAZY | RTLD_GLOBAL);
396 if (handle == nullptr) {
397 _E("dlopen() is failed. path(%s), error(%s)", kPathLibAulServer, dlerror());
398 return AUL_SVC_RET_ERROR;
401 auto dl_closer = [](void* ptr) {
405 std::unique_ptr<void, decltype(dl_closer)> handle_auto(handle, dl_closer);
406 auto* func = reinterpret_cast<AulServiceForeachUsrAliasInfoFunc>(
407 dlsym(handle, kAulServiceForeachUsrAliasInfo));
408 if (func == nullptr) {
409 _E("dlsym() is failed. error(%s)", dlerror());
410 return AUL_SVC_RET_ERROR;
413 AliasInfo info(alias_appid);
415 [](const char* alias_appid, const char* appid, void* user_data) -> bool {
416 auto* info = static_cast<AliasInfo*>(user_data);
417 if (info->alias_appid_ == alias_appid) {
418 info->appid_ = appid;
425 _E("%s() is failed. error(%d)", kAulServiceForeachUsrAliasInfo, ret);
426 return AUL_SVC_RET_ERROR;
429 if (info.appid_.empty())
430 return AUL_SVC_RET_ERROR;
432 *app_id = strdup(info.appid_.c_str());
433 if (*app_id == nullptr) {
434 _E("strdup() is failed");
435 return AUL_SVC_RET_ENOMEM;
438 return AUL_SVC_RET_OK;
443 extern "C" API int aul_svc_set_operation(bundle* b, const char* operation) {
445 _E("Invalid parameter");
446 return AUL_SVC_RET_EINVAL;
449 return ::SetBundle(b, AUL_SVC_K_OPERATION, operation);
452 extern "C" API int aul_svc_set_uri(bundle* b, const char* uri) {
454 _E("Invalid parameter");
455 return AUL_SVC_RET_EINVAL;
458 return ::SetBundle(b, AUL_SVC_K_URI, uri);
461 extern "C" API int aul_svc_set_mime(bundle* b, const char* mime) {
463 _E("Invalid parameter");
464 return AUL_SVC_RET_EINVAL;
467 return ::SetBundle(b, AUL_SVC_K_MIME, mime);
470 extern "C" API int aul_svc_add_data(bundle* b, const char* key,
472 if (b == nullptr || key == nullptr)
473 return AUL_SVC_RET_EINVAL;
475 return ::SetBundle(b, key, value);
478 extern "C" API int aul_svc_add_data_array(bundle* b, const char* key,
479 const char** value, int len) {
480 if (b == nullptr || key == nullptr)
481 return AUL_SVC_RET_EINVAL;
483 return ::SetBundleArray(b, key, value, len);
486 extern "C" API int aul_svc_set_pkgname(bundle* b, const char* pkg_name) {
488 _E("Invalid parameter");
489 return AUL_SVC_RET_EINVAL;
492 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
495 extern "C" API int aul_svc_set_appid(bundle* b, const char* appid) {
496 if (b == nullptr || appid == nullptr) {
497 _E("Invalid parameter");
498 return AUL_SVC_RET_EINVAL;
501 if (TIZEN_FEATURE_APPSVC_ALIAS) {
502 std::string alias_id = ::GetAliasAppId(appid);
503 if (!alias_id.empty())
504 appid = alias_id.c_str();
507 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, appid);
510 extern "C" API int aul_svc_set_category(bundle* b, const char* category) {
512 _E("Invalid parameter");
513 return AUL_SVC_RET_EINVAL;
516 return ::SetBundle(b, AUL_SVC_K_CATEGORY, category);
519 extern "C" API int aul_svc_set_launch_mode(bundle* b, const char* mode) {
521 _E("Invalid parameter");
522 return AUL_SVC_RET_EINVAL;
525 return ::SetBundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
528 extern "C" API int aul_svc_resolve(bundle* b, uid_t uid, char*** appid_array,
530 return aul_svc_get_appid_array(b, uid, appid_array, len);
533 extern "C" API int aul_svc_run_service(bundle* b, int request_code,
534 aul_svc_res_fn cbfunc, void* data) {
535 return aul_svc_run_service_for_uid(b, request_code, cbfunc, data, getuid());
538 extern "C" API int aul_svc_run_service_for_uid(bundle* b, int request_code,
539 aul_svc_res_fn cbfunc, void* data, uid_t uid) {
540 CbInfo* cb_info = nullptr;
542 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
543 if (cb_info == nullptr)
544 LOGE("Out of memory");
547 std::tuple<aul_svc_res_fn, void*> param { cbfunc, data };
548 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
549 [](const std::string& appid, bundle* request, uid_t uid,
550 CbInfo* cb_info) -> int {
553 ret = aul_launch_app_with_result_for_uid(appid.c_str(), request,
554 LaunchWithResultCb, cb_info, uid);
556 ret = aul_launch_app_for_uid(appid.c_str(), request, uid);
565 ret = AulErrorConvert(ret);
571 extern "C" API int aul_svc_get_list(bundle* b, aul_svc_info_iter_fn iter_fn,
573 return aul_svc_get_list_for_uid(b, iter_fn, data, getuid());
576 extern "C" API int aul_svc_get_list_for_uid(bundle* b,
577 aul_svc_info_iter_fn iter_fn, void* data, uid_t uid) {
578 if (b == nullptr || iter_fn == nullptr) {
579 _E("Invalid parameter");
580 return AUL_SVC_RET_EINVAL;
583 char** appid_array = nullptr;
584 unsigned int len = 0;
585 int ret = aul_svc_get_appid_array(b, uid, &appid_array, &len);
586 if (ret != AUL_SVC_RET_OK)
590 _E("Failed to find associated application");
591 aul_svc_free_appid_array(appid_array, len);
592 return AUL_SVC_RET_ENOMATCH;
595 for (unsigned int i = 0; i < len; ++i) {
596 SECURE_LOGD("APPID: %s", appid_array[i]);
597 if (iter_fn(appid_array[i], data) != 0)
601 aul_svc_free_appid_array(appid_array, len);
602 return AUL_SVC_RET_OK;
605 extern "C" API int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn,
607 return aul_svc_get_all_defapps_for_uid(iter_fn, data, getuid());
610 extern "C" API int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
611 void* data, uid_t uid) {
612 if (iter_fn == nullptr) {
613 _E("Invalid parameter");
614 return AUL_SVC_RET_EINVAL;
618 tizen_base::Bundle request;
619 int ret = ::SendAndReceive(APP_GET_APP_CONTROL_DEFAULT_APPS, uid,
620 request.GetHandle(), &response);
621 if (ret != AUL_SVC_RET_OK)
624 tizen_base::Bundle res(response, false, true);
625 auto appid_array = res.GetStringArray(AUL_K_APPID_LIST);
626 for (auto& appid : appid_array) {
627 if (iter_fn(appid.c_str(), data) != 0)
631 return AUL_SVC_RET_OK;
634 extern "C" API const char* aul_svc_get_operation(bundle* b) {
635 return bundle_get_val(b, AUL_SVC_K_OPERATION);
638 extern "C" API const char* aul_svc_get_uri(bundle* b) {
639 return bundle_get_val(b, AUL_SVC_K_URI);
642 extern "C" API const char* aul_svc_get_mime(bundle* b) {
643 return bundle_get_val(b, AUL_SVC_K_MIME);
646 extern "C" API const char* aul_svc_get_data(bundle* b, const char* key) {
647 return bundle_get_val(b, key);
650 extern "C" API const char** aul_svc_get_data_array(bundle* b, const char* key,
652 return bundle_get_str_array(b, key, len);
655 extern "C" API const char* aul_svc_get_pkgname(bundle* b) {
656 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
659 extern "C" API const char* aul_svc_get_appid(bundle* b) {
660 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
663 extern "C" API const char* aul_svc_get_category(bundle* b) {
664 return bundle_get_val(b, AUL_SVC_K_CATEGORY);
667 extern "C" API const char* aul_svc_get_launch_mode(bundle* b) {
668 return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
671 extern "C" API int aul_svc_create_result_bundle(bundle* inb, bundle** outb) {
672 if (inb == nullptr || outb == nullptr) {
673 _E("Invalid parameter");
674 return AUL_SVC_RET_EINVAL;
677 int ret = aul_create_result_bundle(inb, outb);
679 return AulErrorConvert(ret);
681 return AUL_SVC_RET_OK;
684 extern "C" API int aul_svc_send_result(bundle* b, aul_svc_result_val result) {
686 _E("Invalid parameter");
687 return AUL_SVC_RET_EINVAL;
690 int ret = ::SetBundle(b, AUL_SVC_K_RES_VAL, std::to_string(result).c_str());
692 return AUL_SVC_RET_ERROR;
694 if (result == AUL_SVC_RES_CANCEL)
695 ret = aul_send_result(b, 1);
697 ret = aul_send_result(b, 0);
699 bundle_del(b, AUL_SVC_K_RES_VAL);
703 extern "C" API int aul_svc_data_is_array(bundle* b, const char* key) {
704 int type = bundle_get_type(b, key);
708 if (type & BUNDLE_TYPE_ARRAY)
714 extern "C" API int aul_svc_allow_transient_app(bundle* b, int wid) {
716 _E("Invalid parameter");
717 return AUL_SVC_RET_EINVAL;
720 return ::SetBundle(b, AUL_SVC_K_WIN_ID, std::to_string(wid).c_str());
723 extern "C" API int aul_svc_request_transient_app(bundle* b, int callee_wid,
724 aul_svc_host_res_fn cbfunc, void* data) {
728 extern "C" API int aul_svc_subapp_terminate_request_pid(int pid) {
731 int* lpids = nullptr;
732 aul_app_group_get_leader_pids(&lcnt, &lpids);
733 for (int i = 0; i < lcnt; ++i) {
734 if (lpids[i] == cpid) {
737 aul_app_group_get_group_pids(cpid, &cnt, &pids);
743 return aul_subapp_terminate_request_pid(pid);
752 if (lpids != nullptr)
755 return aul_app_group_clear_top();
758 extern "C" API int aul_send_service_result(bundle* b) {
759 return aul_send_result(b, 0);
762 extern "C" API int aul_svc_subscribe_launch_result(bundle* b,
763 const char* result) {
765 _E("Invalid parameter");
766 return AUL_SVC_RET_EINVAL;
769 return ::SetBundle(b, result, "1");
772 extern "C" API int aul_svc_set_loader_id(bundle* b, int loader_id) {
773 if (b == nullptr || loader_id <= 0) {
774 _E("Invalid parameter");
775 return AUL_SVC_RET_EINVAL;
778 return ::SetBundle(b, AUL_K_LOADER_ID, std::to_string(loader_id).c_str());
781 extern "C" API int aul_svc_set_loader_name(bundle* b, const char* loader_name) {
782 if (b == nullptr || loader_name == nullptr) {
783 _E("Invalid parameter");
784 return AUL_SVC_RET_EINVAL;
787 return ::SetBundle(b, AUL_K_LOADER_NAME, loader_name);
790 extern "C" API int aul_svc_set_background_launch(bundle* b, int enabled) {
792 _E("Invalid parameter");
793 return AUL_SVC_RET_EINVAL;
796 return ::SetBundle(b, AUL_SVC_K_BG_LAUNCH, enabled ? "enable" : nullptr);
799 extern "C" API int aul_svc_get_appid_by_alias_appid(const char* alias_appid,
801 return aul_svc_get_appid_by_alias_appid_for_uid(alias_appid, appid, getuid());
804 extern "C" API int aul_svc_get_appid_by_alias_appid_for_uid(
805 const char* alias_appid, char** appid, uid_t uid) {
806 if (alias_appid == nullptr || appid == nullptr) {
807 _E("Invalid parameter");
808 return AUL_SVC_RET_EINVAL;
812 return GetAppIdByAliasAppIdFromDB(alias_appid, appid, uid);
815 tizen_base::Bundle request;
816 request.Add(AUL_K_ALIAS_APPID, alias_appid);
817 int ret = ::SendAndReceive(APP_GET_APPID_BY_ALIAS_APPID, uid,
818 request.GetHandle(), &response);
819 if (ret != AUL_SVC_RET_OK)
822 tizen_base::Bundle res(response, false, true);
823 auto val = res.GetString(AUL_K_APPID);
825 return AUL_SVC_RET_ERROR;
827 *appid = strdup(val.c_str());
828 if (*appid == nullptr) {
830 return AUL_SVC_RET_ENOMEM;
833 return AUL_SVC_RET_OK;
836 extern "C" API const char *aul_svc_get_instance_id(bundle* b) {
837 return bundle_get_val(b, AUL_K_INSTANCE_ID);
840 extern "C" API int aul_svc_set_instance_id(bundle* b, const char* instance_id) {
842 _E("Invalid parameter");
843 return AUL_SVC_RET_EINVAL;
846 return ::SetBundle(b, AUL_K_INSTANCE_ID, instance_id);
849 extern "C" API int aul_svc_run_service_async(bundle* b, int request_code,
850 aul_svc_res_fn cbfunc, void* data) {
851 return aul_svc_run_service_async_for_uid(b, request_code, cbfunc, data,
855 extern "C" API int aul_svc_run_service_async_for_uid(bundle* b,
856 int request_code, aul_svc_res_fn cbfunc, void* data, uid_t uid) {
857 CbInfo* cb_info = nullptr;
859 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
861 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
862 [](const std::string& appid, bundle* request, uid_t uid,
863 CbInfo* info) -> int {
865 return aul_launch_app_with_result_async_for_uid(appid.c_str(),
866 request, LaunchWithResultCb, info, uid);
869 return aul_launch_app_async_for_uid(appid.c_str(), request, uid);
875 ret = AulErrorConvert(ret);
881 extern "C" API int aul_svc_send_launch_request(bundle* b, int request_code,
882 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void* user_data) {
883 return aul_svc_send_launch_request_for_uid(b, request_code,
884 cbfunc, err_cb, user_data, getuid());
887 extern "C" API int aul_svc_send_launch_request_for_uid(bundle* b,
888 int request_code, aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
889 void* user_data, uid_t uid) {
890 if (b == nullptr || err_cb == nullptr) {
891 _E("Invalid parameter");
892 return AUL_SVC_RET_EINVAL;
895 CbInfo* cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, err_cb,
897 if (cb_info == nullptr)
900 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
901 [](const std::string& appid, bundle* request, uid_t uid,
902 CbInfo* info) -> int {
903 return aul_send_launch_request_for_uid(appid.c_str(), request, uid,
904 info->res_fn_ ? ::LaunchWithResultCb : nullptr, ::ErrorCb, info);
908 ret = ::AulErrorConvert(ret);
914 extern "C" API int aul_svc_send_launch_request_sync_for_uid(bundle* b,
915 int request_code, bundle** res_b, aul_svc_result_val* res, uid_t uid) {
916 if (b == nullptr || res_b == nullptr || res == nullptr) {
917 _E("Invalid parameter");
918 return AUL_SVC_RET_EINVAL;
921 int ret = ::SendLaunchRequest<::SendLaunchRequestSyncCb, bundle**>(
922 [](const std::string& appid, bundle* request, uid_t uid,
923 bundle** response) -> int {
924 return aul_send_launch_request_sync_for_uid(appid.c_str(), request,
928 auto* val = bundle_get_val(*res_b, AUL_SVC_K_RES_VAL);
929 *res = static_cast<aul_svc_result_val>(
930 (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val));
932 ret = ::AulErrorConvert(ret);
933 *res = AUL_SVC_RES_CANCEL;
939 extern "C" API int aul_svc_info_create(bundle* b, aul_svc_info_h* h) {
940 if (b == nullptr || h == nullptr) {
941 _E("Invalid parameter");
942 return AUL_SVC_RET_EINVAL;
945 aul::ResolveInfo* resolve_info = nullptr;
947 tizen_base::Bundle kb(b, false, false);
948 resolve_info = aul::ResolveInfo::Manager::Create(kb);
949 } catch (aul::Exception& e) {
950 return AUL_SVC_RET_ERROR;
953 *h = static_cast<aul_svc_info_h>(resolve_info);
954 return AUL_SVC_RET_OK;
957 extern "C" API int aul_svc_info_get_operation(aul_svc_info_h h,
959 if (h == nullptr || operation == nullptr) {
960 _E("Invalid parameter");
961 return AUL_SVC_RET_EINVAL;
964 auto* info = static_cast<aul::ResolveInfo*>(h);
965 auto& value = info->GetOperation();
966 *operation = strdup(value.empty() ? "NULL" : value.c_str());
967 if (*operation == nullptr) {
968 _E("Failed to duplicate operation");
969 return AUL_SVC_RET_ERROR;
972 return AUL_SVC_RET_OK;
975 extern "C" API int aul_svc_info_get_uri(aul_svc_info_h h, char** uri) {
976 if (h == nullptr || uri == nullptr) {
977 _E("Invalid parameter");
978 return AUL_SVC_RET_EINVAL;
981 auto* info = static_cast<aul::ResolveInfo*>(h);
982 auto& value = info->GetUri();
983 *uri = strdup(value.empty() ? "NULL" : value.c_str());
984 if (*uri == nullptr) {
985 _E("Failed to duplicate URI");
986 return AUL_SVC_RET_ERROR;
989 return AUL_SVC_RET_OK;
992 extern "C" API int aul_svc_info_get_uri_scheme(aul_svc_info_h h,
994 if (h == nullptr || uri_scheme == nullptr) {
995 _E("Invalid parameter");
996 return AUL_SVC_RET_EINVAL;
999 auto* info = static_cast<aul::ResolveInfo*>(h);
1000 auto& value = info->GetScheme();
1001 *uri_scheme = strdup(value.empty() ? "NULL" : value.c_str());
1002 if (*uri_scheme == nullptr) {
1003 _E("Failed to duplicate URI scheme");
1004 return AUL_SVC_RET_ERROR;
1007 return AUL_SVC_RET_OK;
1010 extern "C" API int aul_svc_info_get_uri_host(aul_svc_info_h h,
1012 if (h == nullptr || uri_host == nullptr) {
1013 _E("Invalid parameter");
1014 return AUL_SVC_RET_EINVAL;
1017 auto* info = static_cast<aul::ResolveInfo*>(h);
1018 auto& value = info->GetHost();
1019 *uri_host = strdup(value.empty() ? "NULL" : value.c_str());
1020 if (*uri_host == nullptr) {
1021 _E("Failed to duplicate URI host");
1022 return AUL_SVC_RET_ERROR;
1025 return AUL_SVC_RET_OK;
1028 extern "C" API int aul_svc_info_get_mime(aul_svc_info_h h, char** mime) {
1029 if (h == nullptr || mime == nullptr) {
1030 _E("Invalid parameter");
1031 return AUL_SVC_RET_EINVAL;
1034 auto* info = static_cast<aul::ResolveInfo*>(h);
1035 auto& value = info->GetMime();
1036 *mime = strdup(value.empty() ? "NULL" : value.c_str());
1037 if (*mime == nullptr) {
1038 _E("Failed to duplicate MIME-Type");
1039 return AUL_SVC_RET_ERROR;
1042 return AUL_SVC_RET_OK;
1045 extern "C" API int aul_svc_info_get_mime_type(aul_svc_info_h h,
1047 if (h == nullptr || mime_type == nullptr) {
1048 _E("Invalid parameter");
1049 return AUL_SVC_RET_EINVAL;
1052 auto* info = static_cast<aul::ResolveInfo*>(h);
1053 auto& value = info->GetMType();
1054 *mime_type = strdup(value.empty() ? "NULL" : value.c_str());
1055 if (*mime_type == nullptr) {
1056 _E("Failed to duplicate the type of MIME-Type");
1057 return AUL_SVC_RET_ERROR;
1060 return AUL_SVC_RET_OK;
1063 extern "C" API int aul_svc_info_get_mime_subtype(aul_svc_info_h h,
1064 char** mime_subtype) {
1065 if (h == nullptr || mime_subtype == nullptr) {
1066 _E("Invalid parameter");
1067 return AUL_SVC_RET_EINVAL;
1070 auto* info = static_cast<aul::ResolveInfo*>(h);
1071 auto& value = info->GetSType();
1072 *mime_subtype = strdup(value.empty() ? "NULL" : value.c_str());
1073 if (*mime_subtype == nullptr) {
1074 _E("Failed to duplicate the subtype of MIME-Type");
1075 return AUL_SVC_RET_ERROR;
1078 return AUL_SVC_RET_OK;
1081 extern "C" API int aul_svc_info_destroy(aul_svc_info_h h) {
1083 _E("Invalid parameter");
1084 return AUL_SVC_RET_EINVAL;
1087 auto* info = static_cast<aul::ResolveInfo*>(h);
1089 return AUL_SVC_RET_OK;
1092 extern "C" API int aul_svc_set_caller_instance_id(bundle* b,
1093 const char* instance_id) {
1095 _E("Invalid parameter");
1096 return AUL_SVC_RET_EINVAL;
1099 return ::SetBundle(b, AUL_K_CALLER_INSTANCE_ID, instance_id);
1102 extern "C" API int aul_svc_set_comp_id(bundle* b, const char* comp_id) {
1104 _E("Invalid parameter");
1105 return AUL_SVC_RET_EINVAL;
1108 return ::SetBundle(b, AUL_K_COMPONENT_ID, comp_id);
1111 extern "C" API const char *aul_svc_get_comp_id(bundle* b) {
1112 return bundle_get_val(b, AUL_K_COMPONENT_ID);
1115 extern "C" API int aul_svc_subapp_terminate_request(bundle* b, int pid) {
1116 if (b == nullptr || pid < 0) {
1117 _E("Invalid parameter");
1118 return AUL_SVC_RET_EINVAL;
1121 const char* inst_id = bundle_get_val(b, AUL_K_INSTANCE_ID);
1122 if (inst_id == nullptr) {
1123 _E("Invalid parameter");
1124 return AUL_SVC_RET_EINVAL;
1127 char buf[512] = { 0, };
1128 const char* caller_inst_id = bundle_get_val(b, AUL_K_CALLER_INSTANCE_ID);
1129 if (caller_inst_id == nullptr) {
1130 int ret = aul_app_get_instance_id_bypid(getpid(), buf, sizeof(buf));
1131 if (ret != AUL_R_OK) {
1132 _E("aul_app_get_instance_id_bypid() is failed. error(%d)", ret);
1133 return AUL_SVC_RET_ERROR;
1136 caller_inst_id = buf;
1140 aul_app_group_foreach_group_info(caller_inst_id,
1141 [](aul_app_group_info_h info, void* data) {
1142 int* count = static_cast<int*>(data);
1144 }, static_cast<void*>(&cnt));
1146 return aul_subapp_terminate_request(inst_id, pid);
1148 return aul_app_group_clear_top();
1151 extern "C" API int aul_svc_send_resume_request(bundle* b, int request_code,
1152 aul_svc_err_cb err_cb, void *user_data) {
1153 return aul_svc_send_resume_request_for_uid(b, request_code, err_cb, user_data,
1157 extern "C" API int aul_svc_send_resume_request_for_uid(bundle* b,
1158 int request_code, aul_svc_err_cb err_cb, void* user_data, uid_t uid) {
1159 if (b == nullptr || err_cb == nullptr) {
1160 _E("Invalid parameter");
1161 return AUL_SVC_RET_EINVAL;
1164 auto* cb_info = new (std::nothrow) CbInfo(request_code, nullptr, err_cb,
1166 if (cb_info == nullptr)
1167 _E("Out of memory");
1169 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
1170 [](const std::string& appid, bundle* request, uid_t uid,
1171 CbInfo* info) -> int {
1172 return aul_send_resume_request_for_uid(appid.c_str(), request, uid,
1174 }, b, uid, cb_info);
1177 ret = ::AulErrorConvert(ret);
1183 extern "C" API int aul_svc_get_appid_array(bundle* b, uid_t uid,
1184 char*** appid_array, unsigned int* len) {
1185 if (b == nullptr || appid_array == nullptr || len == nullptr) {
1186 _E("Invalid parameter");
1187 return AUL_SVC_RET_EINVAL;
1190 bundle_del(b, AUL_K_APPID);
1191 bundle_add(b, AUL_K_APPID, "@UNKNOWN");
1194 int ret = ::SendAndReceive(APP_GET_APPID_LIST, uid, b, &response);
1195 if (ret != AUL_SVC_RET_OK)
1198 tizen_base::Bundle res(response, false, true);
1199 auto str = res.GetString(AUL_SVC_K_URI_R_INFO);
1201 ::SetBundle(b, AUL_SVC_K_URI_R_INFO, str.c_str());
1203 auto str_arr = res.GetStringArray(AUL_K_APPID_LIST);
1204 if (str_arr.empty()) {
1205 _E("Failed to get appid list");
1206 return AUL_SVC_RET_ERROR;
1209 *appid_array = reinterpret_cast<char**>(
1210 calloc(str_arr.size(), sizeof(char*)));
1211 if (*appid_array == nullptr) {
1212 _E("Out of memory");
1213 return AUL_SVC_RET_ENOMEM;
1216 *len = str_arr.size();
1219 for (auto& appid : str_arr)
1220 (*appid_array)[i++] = strdup(appid.c_str());
1222 return AUL_SVC_RET_OK;
1225 extern "C" API void aul_svc_free_appid_array(char** appid_array,
1227 if (appid_array == nullptr)
1230 for (unsigned int i = 0; i < len; ++i)
1231 free(appid_array[i]);
1236 extern "C" API int aul_svc_set_defapp(const char* op, const char* mime_type,
1237 const char* uri, const char* defapp) {
1238 DEPRECATION_WARNING();
1239 return AUL_SVC_RET_OK;
1242 extern "C" API int aul_svc_set_defapp_for_uid(const char* op,
1243 const char* mime_type, const char* uri, const char* defapp, uid_t uid) {
1244 DEPRECATION_WARNING();
1245 return AUL_SVC_RET_OK;
1248 extern "C" API int aul_svc_unset_defapp(const char* defapp) {
1249 DEPRECATION_WARNING();
1250 return AUL_SVC_RET_OK;
1253 extern "C" API int aul_svc_unset_defapp_for_uid(const char* defapp, uid_t uid) {
1254 DEPRECATION_WARNING();
1255 return AUL_SVC_RET_OK;
1258 extern "C" API int aul_svc_unset_all_defapps(void) {
1259 DEPRECATION_WARNING();
1260 return AUL_SVC_RET_OK;
1263 extern "C" API int aul_svc_unset_all_defapps_for_uid(uid_t uid) {
1264 DEPRECATION_WARNING();
1265 return AUL_SVC_RET_OK;
1268 extern "C" API int aul_svc_is_defapp(const char* pkg_name) {
1269 DEPRECATION_WARNING();
1270 return AUL_SVC_RET_OK;
1273 extern "C" API int aul_svc_is_defapp_for_uid(const char* pkg_name, uid_t uid) {
1274 DEPRECATION_WARNING();
1275 return AUL_SVC_RET_OK;
1278 extern "C" API int aul_svc_set_alias_appid(const char* alias_appid,
1279 const char* appid) {
1280 DEPRECATION_WARNING();
1281 return AUL_SVC_RET_OK;
1284 extern "C" API int aul_svc_set_alias_appid_for_uid(const char* alias_appid,
1285 const char* appid, uid_t uid) {
1286 DEPRECATION_WARNING();
1287 return AUL_SVC_RET_OK;
1290 extern "C" API int aul_svc_unset_alias_appid(const char* alias_appid) {
1291 DEPRECATION_WARNING();
1292 return AUL_SVC_RET_OK;
1295 extern "C" API int aul_svc_unset_alias_appid_for_uid(const char* alias_appid,
1297 DEPRECATION_WARNING();
1298 return AUL_SVC_RET_OK;
1301 extern "C" API int aul_svc_foreach_alias_info(
1302 void (*callback)(const char *, const char *, void *),
1304 DEPRECATION_WARNING();
1305 return AUL_SVC_RET_OK;
1308 extern "C" API int aul_svc_foreach_alias_info_for_uid(
1309 void (*callback)(const char *, const char *, void *),
1310 uid_t uid, void* user_data) {
1311 DEPRECATION_WARNING();
1312 return AUL_SVC_RET_OK;
1315 extern "C" API int aul_svc_enable_alias_info(const char* appid) {
1316 DEPRECATION_WARNING();
1317 return AUL_SVC_RET_OK;
1320 extern "C" API int aul_svc_enable_alias_info_for_uid(const char* appid,
1322 DEPRECATION_WARNING();
1323 return AUL_SVC_RET_OK;
1326 extern "C" API int aul_svc_disable_alias_info(const char* appid) {
1327 DEPRECATION_WARNING();
1328 return AUL_SVC_RET_OK;
1331 extern "C" API int aul_svc_disable_alias_info_for_uid(const char* appid,
1333 DEPRECATION_WARNING();
1334 return AUL_SVC_RET_OK;
1337 extern "C" API int aul_svc_foreach_alias_info_by_appid(
1338 int (*callback)(const char *, const char *, void *),
1339 const char* appid, void* user_data) {
1340 DEPRECATION_WARNING();
1341 return AUL_SVC_RET_OK;
1344 extern "C" API int aul_svc_foreach_alias_info_by_appid_for_uid(
1345 int (*callback)(const char *, const char *, void *),
1346 const char* appid, uid_t uid, void* user_data) {
1347 DEPRECATION_WARNING();
1348 return AUL_SVC_RET_OK;
1351 extern "C" API int aul_svc_foreach_allowed_info(
1352 int (*callback)(const char *, const char *, void *),
1354 DEPRECATION_WARNING();
1355 return AUL_SVC_RET_OK;
1358 extern "C" API int aul_svc_foreach_allowed_info_for_uid(
1359 int (*callback)(const char *, const char *, void *),
1360 uid_t uid, void* user_data) {
1361 DEPRECATION_WARNING();
1362 return AUL_SVC_RET_OK;
1365 extern "C" API int aul_svc_foreach_allowed_info_by_appid(
1366 int (*callback)(const char *, const char *, void *),
1367 const char* appid, void* user_data) {
1368 DEPRECATION_WARNING();
1369 return AUL_SVC_RET_OK;
1372 extern "C" API int aul_svc_foreach_allowed_info_by_appid_for_uid(
1373 int (*callback)(const char *, const char *, void *),
1374 const char* appid, uid_t uid, void* user_data) {
1375 DEPRECATION_WARNING();
1376 return AUL_SVC_RET_OK;