2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <bundle_cpp.h>
19 #include <bundle_internal.h>
22 #include <iniparser.h>
28 #include <sys/types.h>
35 #include "aul/app_control/resolve_info.hh"
36 #include "include/aul.h"
37 #include "include/aul_app_group.h"
38 #include "include/aul_error.h"
39 #include "include/aul_sock.h"
40 #include "include/aul_svc.h"
41 #include "include/aul_svc_internal.h"
42 #include "src/aul_api.h"
43 #include "src/aul_svc_priv_key.h"
44 #include "src/aul_util.h"
45 #include "src/launch.h"
47 #undef MAX_MIME_STR_SIZE
48 #define MAX_MIME_STR_SIZE 256
50 #undef MAX_SCHEME_STR_SIZE
51 #define MAX_SCHEME_STR_SIZE 256
53 #undef MAX_HOST_STR_SIZE
54 #define MAX_HOST_STR_SIZE 256
56 #undef DEPRECATION_WARNING
57 #define DEPRECATION_WARNING() do { \
58 dlog_print(DLOG_WARN, LOG_TAG, \
59 "DEPRECATION WARNING: %s() is deprecated and " \
60 "will be removed from next release.", __FUNCTION__); \
65 constexpr const char kPathAmdReady[] = "/run/.amd_ready";
66 constexpr const char kPathLibAulServer[] = "/usr/lib/libaul-server.so.0";
67 constexpr const char kAulServiceForeachUsrAliasInfo[] =
68 "aul_service_foreach_usr_alias_info";
72 CbInfo(int request_code, aul_svc_res_fn res_fn,
73 aul_svc_err_cb err_cb, void* user_data)
74 : request_code_(request_code),
77 user_data_(user_data) {
81 aul_svc_res_fn res_fn_;
82 aul_svc_err_cb err_cb_;
88 AliasInfo(std::string alias_appid)
89 : alias_appid_(std::move(alias_appid)) {
92 std::string alias_appid_;
96 int SetBundle(bundle* b, const char* key, const char* value) {
97 if (bundle_get_type(b, key) != BUNDLE_TYPE_NONE) {
98 if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
99 return AUL_SVC_RET_ERROR;
102 if (value == nullptr)
103 return AUL_SVC_RET_EINVAL;
105 if (bundle_add(b, key, value) != BUNDLE_ERROR_NONE)
106 return AUL_SVC_RET_ERROR;
108 SECURE_LOGD("key(%s), value(%s)", key, value);
109 return AUL_SVC_RET_OK;
112 int SetBundleArray(bundle* b, const char* key, const char** value,
114 int is_array = aul_svc_data_is_array(b, key);
116 if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
117 return AUL_SVC_RET_ERROR;
120 if (value == nullptr)
121 return AUL_SVC_RET_EINVAL;
123 if (bundle_add_str_array(b, key, value, len) != BUNDLE_ERROR_NONE)
124 return AUL_SVC_RET_ERROR;
126 SECURE_LOGD("key(%s), length(%d)", key, len);
127 return AUL_SVC_RET_OK;
130 std::string GetAliasAppId(const char* appid) {
131 dictionary* dic = iniparser_load("/usr/share/appsvc/alias.ini");
135 auto dic_ptr = std::unique_ptr<dictionary, decltype(iniparser_freedict)*>(
136 dic, iniparser_freedict);
138 std::string key = std::string("Alias:") + appid;
139 const char* value = iniparser_getstring(dic, key.c_str(), nullptr);
140 SECURE_LOGD("appid(%s), alias_id(%s)", appid, value);
141 if (value == nullptr)
144 return std::string(value);
147 bool IsSpecialApp(const char* appid) {
148 if (!strcmp(appid, APP_SELECTOR) || !strcmp(appid, SHARE_PANEL))
154 bool IsSpecialOperation(const char* operation) {
155 if (operation == nullptr)
158 int ret = strcmp(operation,
159 "http://tizen.org/appcontrol/operation/guide_privacy_setting");
166 std::string GetAppId(bundle* request) {
167 const char* appid = aul_svc_get_pkgname(request);
168 if (appid == nullptr) {
169 if (aul_svc_get_operation(request) == nullptr) {
170 _E("Invalid request");
177 int ret = bundle_get_type(request, AUL_SVC_K_SELECTOR_EXTRA_LIST);
178 if (ret != BUNDLE_TYPE_NONE) {
179 if (appid == nullptr || !strcmp(appid, "@UNKNOWN"))
180 appid = APP_SELECTOR;
183 ret = bundle_get_type(request, AUL_K_FORCE_LAUNCH_APP_SELECTOR);
184 if (ret != BUNDLE_TYPE_NONE)
185 appid = APP_SELECTOR;
187 return std::string(appid);
190 void SetLaunchData(bundle* request, const std::string& appid) {
191 const char* operation = aul_svc_get_operation(request);
192 if (operation == nullptr)
193 aul_svc_set_operation(request, AUL_SVC_OPERATION_DEFAULT);
195 if (IsSpecialApp(appid.c_str()) || IsSpecialOperation(operation)) {
196 SetBundle(request, AUL_SVC_K_CAN_BE_LEADER, "true");
197 SetBundle(request, AUL_SVC_K_REROUTE, "true");
198 SetBundle(request, AUL_SVC_K_RECYCLE, "true");
201 const char* launch_mode = aul_svc_get_launch_mode(request);
202 if (launch_mode && !strcmp(launch_mode, "group")) {
203 int ret = bundle_get_type(request, AUL_K_INSTANCE_ID);
204 if (ret != BUNDLE_TYPE_NONE)
205 aul_set_instance_info(appid.c_str(), request);
209 int AulErrorConvert(int res) {
212 return AUL_SVC_RET_EILLACC;
214 return AUL_SVC_RET_EINVAL;
215 case AUL_R_ETERMINATING:
216 return AUL_SVC_RET_ETERMINATING;
217 case AUL_R_EREJECTED:
218 return AUL_SVC_RET_EREJECTED;
220 return AUL_SVC_RET_ENOMATCH;
221 case AUL_R_ECANCELED:
222 return AUL_SVC_RET_ECANCELED;
224 return AUL_SVC_RET_ELAUNCH;
228 void LaunchWithResultCb(bundle* b, int is_cancel, void* data) {
231 res = AUL_SVC_RES_CANCEL;
233 const char* val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
234 res = (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val);
237 bundle_del(b, AUL_SVC_K_RES_VAL);
238 auto* cb_info = static_cast<CbInfo*>(data);
239 if (cb_info == nullptr) {
240 _E("Invalid parameter");
244 if (cb_info->res_fn_) {
245 cb_info->res_fn_(b, cb_info->request_code_,
246 static_cast<aul_svc_result_val>(res), cb_info->user_data_);
247 cb_info->res_fn_ = nullptr;
250 if (cb_info->err_cb_ != nullptr)
256 void ErrorCb(int error, void* data) {
258 error = AulErrorConvert(error);
260 auto* cb_info = static_cast<CbInfo*>(data);
261 if (cb_info == nullptr) {
262 _E("Invalid parameter");
266 if (cb_info->err_cb_) {
267 cb_info->err_cb_(cb_info->request_code_, error, cb_info->user_data_);
268 cb_info->err_cb_ = nullptr;
271 if (cb_info->res_fn_)
277 using SendLaunchRequestCb =
278 int (*)(const std::string&, bundle*, uid_t, CbInfo*);
279 using SendLaunchRequestSyncCb =
280 int (*)(const std::string&, bundle*, uid_t, bundle**);
282 template <typename T, typename A>
283 int SendLaunchRequest(T cb, bundle* request, uid_t uid, A arg) {
284 if (request == nullptr) {
285 _E("Invalid parameter");
286 return AUL_SVC_RET_EINVAL;
289 std::string appid = GetAppId(request);
291 _E("GetAppId() is failed");
292 return AUL_SVC_RET_EINVAL;
295 SetLaunchData(request, appid);
296 return cb(appid, request, uid, arg);
299 int SendAndReceive(int cmd, uid_t uid, bundle* request, bundle** response) {
300 int fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, cmd, request,
303 return AUL_SVC_RET_ERROR;
305 app_pkt_t* pkt = nullptr;
306 int ret = aul_sock_recv_reply_pkt(fd, &pkt);
308 _E("Failed to receive reply packet. error(%d)", ret);
309 return AUL_SVC_RET_ERROR;
312 auto ptr = std::unique_ptr<app_pkt_t, decltype(std::free)*>(pkt, std::free);
313 if (pkt->cmd != APP_GET_INFO_OK && pkt->cmd != cmd) {
314 if (pkt->cmd == APP_GET_INFO_ERROR)
315 return AUL_SVC_RET_ERROR;
317 return AulErrorConvert(aul_error_convert(pkt->cmd));
321 if (pkt->opt & AUL_SOCK_BUNDLE) {
322 b = bundle_decode(pkt->data, pkt->len);
324 _E("bundle_decode() is failed");
325 return AUL_SVC_RET_ENOMEM;
328 _E("Invalid packet");
329 return AUL_SVC_RET_ERROR;
333 return AUL_SVC_RET_OK;
336 std::atomic<bool> amd_ready { false };
341 if (access(kPathAmdReady, F_OK) == 0) {
342 amd_ready.exchange(true);
349 using AulServiceAliasInfoCb =
350 bool (*)(const char*, const char*, void*);
351 using AulServiceForeachUsrAliasInfoFunc =
352 int (*)(AulServiceAliasInfoCb, uid_t, void*);
354 int GetAppIdByAliasAppIdFromDB(const char* alias_appid, char** app_id,
356 void* handle = dlopen(kPathLibAulServer, RTLD_LAZY | RTLD_GLOBAL);
357 if (handle == nullptr) {
358 _E("dlopen() is failed. path(%s), error(%s)", kPathLibAulServer, dlerror());
359 return AUL_SVC_RET_ERROR;
362 std::unique_ptr<void, decltype(dlclose)*> handle_auto(handle, dlclose);
363 auto* func = reinterpret_cast<AulServiceForeachUsrAliasInfoFunc>(
364 dlsym(handle, kAulServiceForeachUsrAliasInfo));
365 if (func == nullptr) {
366 _E("dlsym() is failed. error(%s)", dlerror());
367 return AUL_SVC_RET_ERROR;
370 AliasInfo info(alias_appid);
372 [](const char* alias_appid, const char* appid, void* user_data) -> bool {
373 auto* info = static_cast<AliasInfo*>(user_data);
374 if (info->alias_appid_ == alias_appid) {
375 info->appid_ = appid;
382 _E("%s() is failed. error(%d)", kAulServiceForeachUsrAliasInfo, ret);
383 return AUL_SVC_RET_ERROR;
386 if (info.appid_.empty())
387 return AUL_SVC_RET_ERROR;
389 *app_id = strdup(info.appid_.c_str());
390 if (*app_id == nullptr) {
391 _E("strdup() is failed");
392 return AUL_SVC_RET_ENOMEM;
395 return AUL_SVC_RET_OK;
400 extern "C" API int aul_svc_set_operation(bundle* b, const char* operation) {
402 _E("Invalid parameter");
403 return AUL_SVC_RET_EINVAL;
406 return ::SetBundle(b, AUL_SVC_K_OPERATION, operation);
409 extern "C" API int aul_svc_set_uri(bundle* b, const char* uri) {
411 _E("Invalid parameter");
412 return AUL_SVC_RET_EINVAL;
415 return ::SetBundle(b, AUL_SVC_K_URI, uri);
418 extern "C" API int aul_svc_set_mime(bundle* b, const char* mime) {
420 _E("Invalid parameter");
421 return AUL_SVC_RET_EINVAL;
424 return ::SetBundle(b, AUL_SVC_K_MIME, mime);
427 extern "C" API int aul_svc_add_data(bundle* b, const char* key,
429 if (b == nullptr || key == nullptr)
430 return AUL_SVC_RET_EINVAL;
432 return ::SetBundle(b, key, value);
435 extern "C" API int aul_svc_add_data_array(bundle* b, const char* key,
436 const char** value, int len) {
437 if (b == nullptr || key == nullptr)
438 return AUL_SVC_RET_EINVAL;
440 return ::SetBundleArray(b, key, value, len);
443 extern "C" API int aul_svc_set_pkgname(bundle* b, const char* pkg_name) {
445 _E("Invalid parameter");
446 return AUL_SVC_RET_EINVAL;
449 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
452 extern "C" API int aul_svc_set_appid(bundle* b, const char* appid) {
453 if (b == nullptr || appid == nullptr) {
454 _E("Invalid parameter");
455 return AUL_SVC_RET_EINVAL;
458 std::string alias_id = ::GetAliasAppId(appid);
459 if (!alias_id.empty())
460 appid = alias_id.c_str();
462 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, appid);
465 extern "C" API int aul_svc_set_category(bundle* b, const char* category) {
467 _E("Invalid parameter");
468 return AUL_SVC_RET_EINVAL;
471 return ::SetBundle(b, AUL_SVC_K_CATEGORY, category);
474 extern "C" API int aul_svc_set_launch_mode(bundle* b, const char* mode) {
476 _E("Invalid parameter");
477 return AUL_SVC_RET_EINVAL;
480 return ::SetBundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
483 extern "C" API int aul_svc_resolve(bundle* b, uid_t uid, char*** appid_array,
485 return aul_svc_get_appid_array(b, uid, appid_array, len);
488 extern "C" API int aul_svc_run_service(bundle* b, int request_code,
489 aul_svc_res_fn cbfunc, void* data) {
490 return aul_svc_run_service_for_uid(b, request_code, cbfunc, data, getuid());
493 extern "C" API int aul_svc_run_service_for_uid(bundle* b, int request_code,
494 aul_svc_res_fn cbfunc, void* data, uid_t uid) {
495 CbInfo* cb_info = nullptr;
497 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
498 if (cb_info == nullptr)
499 LOGE("Out of memory");
502 std::tuple<aul_svc_res_fn, void*> param { cbfunc, data };
503 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
504 [](const std::string& appid, bundle* request, uid_t uid,
505 CbInfo* cb_info) -> int {
508 ret = aul_launch_app_with_result_for_uid(appid.c_str(), request,
509 LaunchWithResultCb, cb_info, uid);
511 ret = aul_launch_app_for_uid(appid.c_str(), request, uid);
520 ret = AulErrorConvert(ret);
526 extern "C" API int aul_svc_get_list(bundle* b, aul_svc_info_iter_fn iter_fn,
528 return aul_svc_get_list_for_uid(b, iter_fn, data, getuid());
531 extern "C" API int aul_svc_get_list_for_uid(bundle* b,
532 aul_svc_info_iter_fn iter_fn, void* data, uid_t uid) {
533 if (b == nullptr || iter_fn == nullptr) {
534 _E("Invalid parameter");
535 return AUL_SVC_RET_EINVAL;
538 char** appid_array = nullptr;
539 unsigned int len = 0;
540 int ret = aul_svc_get_appid_array(b, uid, &appid_array, &len);
541 if (ret != AUL_SVC_RET_OK)
545 _E("Failed to find associated application");
546 aul_svc_free_appid_array(appid_array, len);
547 return AUL_SVC_RET_ENOMATCH;
550 for (unsigned int i = 0; i < len; ++i) {
551 SECURE_LOGD("APPID: %s", appid_array[i]);
552 if (iter_fn(appid_array[i], data) != 0)
556 aul_svc_free_appid_array(appid_array, len);
557 return AUL_SVC_RET_OK;
560 extern "C" API int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn,
562 return aul_svc_get_all_defapps_for_uid(iter_fn, data, getuid());
565 extern "C" API int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
566 void* data, uid_t uid) {
567 if (iter_fn == nullptr) {
568 _E("Invalid parameter");
569 return AUL_SVC_RET_EINVAL;
573 tizen_base::Bundle request;
574 int ret = ::SendAndReceive(APP_GET_APP_CONTROL_DEFAULT_APPS, uid,
575 request.GetHandle(), &response);
576 if (ret != AUL_SVC_RET_OK)
579 tizen_base::Bundle res(response, false, true);
580 auto appid_array = res.GetStringArray(AUL_K_APPID_LIST);
581 for (auto& appid : appid_array) {
582 if (iter_fn(appid.c_str(), data) != 0)
586 return AUL_SVC_RET_OK;
589 extern "C" API const char* aul_svc_get_operation(bundle* b) {
590 return bundle_get_val(b, AUL_SVC_K_OPERATION);
593 extern "C" API const char* aul_svc_get_uri(bundle* b) {
594 return bundle_get_val(b, AUL_SVC_K_URI);
597 extern "C" API const char* aul_svc_get_mime(bundle* b) {
598 return bundle_get_val(b, AUL_SVC_K_MIME);
601 extern "C" API const char* aul_svc_get_data(bundle* b, const char* key) {
602 return bundle_get_val(b, key);
605 extern "C" API const char** aul_svc_get_data_array(bundle* b, const char* key,
607 return bundle_get_str_array(b, key, len);
610 extern "C" API const char* aul_svc_get_pkgname(bundle* b) {
611 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
614 extern "C" API const char* aul_svc_get_appid(bundle* b) {
615 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
618 extern "C" API const char* aul_svc_get_category(bundle* b) {
619 return bundle_get_val(b, AUL_SVC_K_CATEGORY);
622 extern "C" API const char* aul_svc_get_launch_mode(bundle* b) {
623 return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
626 extern "C" API int aul_svc_create_result_bundle(bundle* inb, bundle** outb) {
627 if (inb == nullptr || outb == nullptr) {
628 _E("Invalid parameter");
629 return AUL_SVC_RET_EINVAL;
632 int ret = aul_create_result_bundle(inb, outb);
634 return AulErrorConvert(ret);
636 return AUL_SVC_RET_OK;
639 extern "C" API int aul_svc_send_result(bundle* b, aul_svc_result_val result) {
641 _E("Invalid parameter");
642 return AUL_SVC_RET_EINVAL;
645 int ret = ::SetBundle(b, AUL_SVC_K_RES_VAL, std::to_string(result).c_str());
647 return AUL_SVC_RET_ERROR;
649 if (result == AUL_SVC_RES_CANCEL)
650 ret = aul_send_result(b, 1);
652 ret = aul_send_result(b, 0);
654 bundle_del(b, AUL_SVC_K_RES_VAL);
658 extern "C" API int aul_svc_data_is_array(bundle* b, const char* key) {
659 int type = bundle_get_type(b, key);
663 if (type & BUNDLE_TYPE_ARRAY)
669 extern "C" API int aul_svc_allow_transient_app(bundle* b, int wid) {
671 _E("Invalid parameter");
672 return AUL_SVC_RET_EINVAL;
675 return ::SetBundle(b, AUL_SVC_K_WIN_ID, std::to_string(wid).c_str());
678 extern "C" API int aul_svc_request_transient_app(bundle* b, int callee_wid,
679 aul_svc_host_res_fn cbfunc, void* data) {
683 extern "C" API int aul_svc_subapp_terminate_request_pid(int pid) {
686 int* lpids = nullptr;
687 aul_app_group_get_leader_pids(&lcnt, &lpids);
688 for (int i = 0; i < lcnt; ++i) {
689 if (lpids[i] == cpid) {
692 aul_app_group_get_group_pids(cpid, &cnt, &pids);
698 return aul_subapp_terminate_request_pid(pid);
707 if (lpids != nullptr)
710 return aul_app_group_clear_top();
713 extern "C" API int aul_send_service_result(bundle* b) {
714 return aul_send_result(b, 0);
717 extern "C" API int aul_svc_subscribe_launch_result(bundle* b,
718 const char* result) {
720 _E("Invalid parameter");
721 return AUL_SVC_RET_EINVAL;
724 return ::SetBundle(b, result, "1");
727 extern "C" API int aul_svc_set_loader_id(bundle* b, int loader_id) {
728 if (b == nullptr || loader_id <= 0) {
729 _E("Invalid parameter");
730 return AUL_SVC_RET_EINVAL;
733 return ::SetBundle(b, AUL_K_LOADER_ID, std::to_string(loader_id).c_str());
736 extern "C" API int aul_svc_set_loader_name(bundle* b, const char* loader_name) {
737 if (b == nullptr || loader_name == nullptr) {
738 _E("Invalid parameter");
739 return AUL_SVC_RET_EINVAL;
742 return ::SetBundle(b, AUL_K_LOADER_NAME, loader_name);
745 extern "C" API int aul_svc_set_background_launch(bundle* b, int enabled) {
747 _E("Invalid parameter");
748 return AUL_SVC_RET_EINVAL;
751 return ::SetBundle(b, AUL_SVC_K_BG_LAUNCH, enabled ? "enable" : nullptr);
754 extern "C" API int aul_svc_get_appid_by_alias_appid(const char* alias_appid,
756 return aul_svc_get_appid_by_alias_appid_for_uid(alias_appid, appid, getuid());
759 extern "C" API int aul_svc_get_appid_by_alias_appid_for_uid(
760 const char* alias_appid, char** appid, uid_t uid) {
761 if (alias_appid == nullptr || appid == nullptr) {
762 _E("Invalid parameter");
763 return AUL_SVC_RET_EINVAL;
767 return GetAppIdByAliasAppIdFromDB(alias_appid, appid, uid);
770 tizen_base::Bundle request;
771 request.Add(AUL_K_ALIAS_APPID, alias_appid);
772 int ret = ::SendAndReceive(APP_GET_APPID_BY_ALIAS_APPID, uid,
773 request.GetHandle(), &response);
774 if (ret != AUL_SVC_RET_OK)
777 tizen_base::Bundle res(response, false, true);
778 auto val = res.GetString(AUL_K_APPID);
780 return AUL_SVC_RET_ERROR;
782 *appid = strdup(val.c_str());
783 if (*appid == nullptr) {
785 return AUL_SVC_RET_ENOMEM;
788 return AUL_SVC_RET_OK;
791 extern "C" API const char *aul_svc_get_instance_id(bundle* b) {
792 return bundle_get_val(b, AUL_K_INSTANCE_ID);
795 extern "C" API int aul_svc_set_instance_id(bundle* b, const char* instance_id) {
797 _E("Invalid parameter");
798 return AUL_SVC_RET_EINVAL;
801 return ::SetBundle(b, AUL_K_INSTANCE_ID, instance_id);
804 extern "C" API int aul_svc_run_service_async(bundle* b, int request_code,
805 aul_svc_res_fn cbfunc, void* data) {
806 return aul_svc_run_service_async_for_uid(b, request_code, cbfunc, data,
810 extern "C" API int aul_svc_run_service_async_for_uid(bundle* b,
811 int request_code, aul_svc_res_fn cbfunc, void* data, uid_t uid) {
812 CbInfo* cb_info = nullptr;
814 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
816 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
817 [](const std::string& appid, bundle* request, uid_t uid,
818 CbInfo* info) -> int {
820 return aul_launch_app_with_result_async_for_uid(appid.c_str(),
821 request, LaunchWithResultCb, info, uid);
824 return aul_launch_app_async_for_uid(appid.c_str(), request, uid);
830 ret = AulErrorConvert(ret);
836 extern "C" API int aul_svc_send_launch_request(bundle* b, int request_code,
837 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void* user_data) {
838 return aul_svc_send_launch_request_for_uid(b, request_code,
839 cbfunc, err_cb, user_data, getuid());
842 extern "C" API int aul_svc_send_launch_request_for_uid(bundle* b,
843 int request_code, aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
844 void* user_data, uid_t uid) {
845 if (b == nullptr || err_cb == nullptr) {
846 _E("Invalid parameter");
847 return AUL_SVC_RET_EINVAL;
850 CbInfo* cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, err_cb,
852 if (cb_info == nullptr)
855 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
856 [](const std::string& appid, bundle* request, uid_t uid,
857 CbInfo* info) -> int {
858 return aul_send_launch_request_for_uid(appid.c_str(), request, uid,
859 info->res_fn_ ? ::LaunchWithResultCb : nullptr, ::ErrorCb, info);
863 ret = ::AulErrorConvert(ret);
869 extern "C" API int aul_svc_send_launch_request_sync_for_uid(bundle* b,
870 int request_code, bundle** res_b, aul_svc_result_val* res, uid_t uid) {
871 if (b == nullptr || res_b == nullptr || res == nullptr) {
872 _E("Invalid parameter");
873 return AUL_SVC_RET_EINVAL;
876 int ret = ::SendLaunchRequest<::SendLaunchRequestSyncCb, bundle**>(
877 [](const std::string& appid, bundle* request, uid_t uid,
878 bundle** response) -> int {
879 return aul_send_launch_request_sync_for_uid(appid.c_str(), request,
883 auto* val = bundle_get_val(*res_b, AUL_SVC_K_RES_VAL);
884 *res = static_cast<aul_svc_result_val>(
885 (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val));
887 ret = ::AulErrorConvert(ret);
888 *res = AUL_SVC_RES_CANCEL;
894 extern "C" API int aul_svc_info_create(bundle* b, aul_svc_info_h* h) {
895 if (b == nullptr || h == nullptr) {
896 _E("Invalid parameter");
897 return AUL_SVC_RET_EINVAL;
900 aul::ResolveInfo* resolve_info = nullptr;
902 tizen_base::Bundle kb(b, false, false);
903 resolve_info = aul::ResolveInfo::Manager::Create(kb);
904 } catch (aul::Exception& e) {
905 return AUL_SVC_RET_ERROR;
908 *h = static_cast<aul_svc_info_h>(resolve_info);
909 return AUL_SVC_RET_OK;
912 extern "C" API int aul_svc_info_get_operation(aul_svc_info_h h,
914 if (h == nullptr || operation == nullptr) {
915 _E("Invalid parameter");
916 return AUL_SVC_RET_EINVAL;
919 auto* info = static_cast<aul::ResolveInfo*>(h);
920 auto& value = info->GetOperation();
921 *operation = strdup(value.empty() ? "NULL" : value.c_str());
922 if (*operation == nullptr) {
923 _E("Failed to duplicate operation");
924 return AUL_SVC_RET_ERROR;
927 return AUL_SVC_RET_OK;
930 extern "C" API int aul_svc_info_get_uri(aul_svc_info_h h, char** uri) {
931 if (h == nullptr || uri == nullptr) {
932 _E("Invalid parameter");
933 return AUL_SVC_RET_EINVAL;
936 auto* info = static_cast<aul::ResolveInfo*>(h);
937 auto& value = info->GetUri();
938 *uri = strdup(value.empty() ? "NULL" : value.c_str());
939 if (*uri == nullptr) {
940 _E("Failed to duplicate URI");
941 return AUL_SVC_RET_ERROR;
944 return AUL_SVC_RET_OK;
947 extern "C" API int aul_svc_info_get_uri_scheme(aul_svc_info_h h,
949 if (h == nullptr || uri_scheme == nullptr) {
950 _E("Invalid parameter");
951 return AUL_SVC_RET_EINVAL;
954 auto* info = static_cast<aul::ResolveInfo*>(h);
955 auto& value = info->GetScheme();
956 *uri_scheme = strdup(value.empty() ? "NULL" : value.c_str());
957 if (*uri_scheme == nullptr) {
958 _E("Failed to duplicate URI scheme");
959 return AUL_SVC_RET_ERROR;
962 return AUL_SVC_RET_OK;
965 extern "C" API int aul_svc_info_get_uri_host(aul_svc_info_h h,
967 if (h == nullptr || uri_host == nullptr) {
968 _E("Invalid parameter");
969 return AUL_SVC_RET_EINVAL;
972 auto* info = static_cast<aul::ResolveInfo*>(h);
973 auto& value = info->GetHost();
974 *uri_host = strdup(value.empty() ? "NULL" : value.c_str());
975 if (*uri_host == nullptr) {
976 _E("Failed to duplicate URI host");
977 return AUL_SVC_RET_ERROR;
980 return AUL_SVC_RET_OK;
983 extern "C" API int aul_svc_info_get_mime(aul_svc_info_h h, char** mime) {
984 if (h == nullptr || mime == nullptr) {
985 _E("Invalid parameter");
986 return AUL_SVC_RET_EINVAL;
989 auto* info = static_cast<aul::ResolveInfo*>(h);
990 auto& value = info->GetMime();
991 *mime = strdup(value.empty() ? "NULL" : value.c_str());
992 if (*mime == nullptr) {
993 _E("Failed to duplicate MIME-Type");
994 return AUL_SVC_RET_ERROR;
997 return AUL_SVC_RET_OK;
1000 extern "C" API int aul_svc_info_get_mime_type(aul_svc_info_h h,
1002 if (h == nullptr || mime_type == nullptr) {
1003 _E("Invalid parameter");
1004 return AUL_SVC_RET_EINVAL;
1007 auto* info = static_cast<aul::ResolveInfo*>(h);
1008 auto& value = info->GetMType();
1009 *mime_type = strdup(value.empty() ? "NULL" : value.c_str());
1010 if (*mime_type == nullptr) {
1011 _E("Failed to duplicate the type of MIME-Type");
1012 return AUL_SVC_RET_ERROR;
1015 return AUL_SVC_RET_OK;
1018 extern "C" API int aul_svc_info_get_mime_subtype(aul_svc_info_h h,
1019 char** mime_subtype) {
1020 if (h == nullptr || mime_subtype == nullptr) {
1021 _E("Invalid parameter");
1022 return AUL_SVC_RET_EINVAL;
1025 auto* info = static_cast<aul::ResolveInfo*>(h);
1026 auto& value = info->GetSType();
1027 *mime_subtype = strdup(value.empty() ? "NULL" : value.c_str());
1028 if (*mime_subtype == nullptr) {
1029 _E("Failed to duplicate the subtype of MIME-Type");
1030 return AUL_SVC_RET_ERROR;
1033 return AUL_SVC_RET_OK;
1036 extern "C" API int aul_svc_info_destroy(aul_svc_info_h h) {
1038 _E("Invalid parameter");
1039 return AUL_SVC_RET_EINVAL;
1042 auto* info = static_cast<aul::ResolveInfo*>(h);
1044 return AUL_SVC_RET_OK;
1047 extern "C" API int aul_svc_set_caller_instance_id(bundle* b,
1048 const char* instance_id) {
1050 _E("Invalid parameter");
1051 return AUL_SVC_RET_EINVAL;
1054 return ::SetBundle(b, AUL_K_CALLER_INSTANCE_ID, instance_id);
1057 extern "C" API int aul_svc_set_comp_id(bundle* b, const char* comp_id) {
1059 _E("Invalid parameter");
1060 return AUL_SVC_RET_EINVAL;
1063 return ::SetBundle(b, AUL_K_COMPONENT_ID, comp_id);
1066 extern "C" API const char *aul_svc_get_comp_id(bundle* b) {
1067 return bundle_get_val(b, AUL_K_COMPONENT_ID);
1070 extern "C" API int aul_svc_subapp_terminate_request(bundle* b, int pid) {
1071 if (b == nullptr || pid < 0) {
1072 _E("Invalid parameter");
1073 return AUL_SVC_RET_EINVAL;
1076 const char* inst_id = bundle_get_val(b, AUL_K_INSTANCE_ID);
1077 if (inst_id == nullptr) {
1078 _E("Invalid parameter");
1079 return AUL_SVC_RET_EINVAL;
1082 char buf[512] = { 0, };
1083 const char* caller_inst_id = bundle_get_val(b, AUL_K_CALLER_INSTANCE_ID);
1084 if (caller_inst_id == nullptr) {
1085 int ret = aul_app_get_instance_id_bypid(getpid(), buf, sizeof(buf));
1086 if (ret != AUL_R_OK) {
1087 _E("aul_app_get_instance_id_bypid() is failed. error(%d)", ret);
1088 return AUL_SVC_RET_ERROR;
1091 caller_inst_id = buf;
1095 aul_app_group_foreach_group_info(caller_inst_id,
1096 [](aul_app_group_info_h info, void* data) {
1097 int* count = static_cast<int*>(data);
1099 }, static_cast<void*>(&cnt));
1101 return aul_subapp_terminate_request(inst_id, pid);
1103 return aul_app_group_clear_top();
1106 extern "C" API int aul_svc_send_resume_request(bundle* b, int request_code,
1107 aul_svc_err_cb err_cb, void *user_data) {
1108 return aul_svc_send_resume_request_for_uid(b, request_code, err_cb, user_data,
1112 extern "C" API int aul_svc_send_resume_request_for_uid(bundle* b,
1113 int request_code, aul_svc_err_cb err_cb, void* user_data, uid_t uid) {
1114 if (b == nullptr || err_cb == nullptr) {
1115 _E("Invalid parameter");
1116 return AUL_SVC_RET_EINVAL;
1119 auto* cb_info = new (std::nothrow) CbInfo(request_code, nullptr, err_cb,
1121 if (cb_info == nullptr)
1122 _E("Out of memory");
1124 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
1125 [](const std::string& appid, bundle* request, uid_t uid,
1126 CbInfo* info) -> int {
1127 return aul_send_resume_request_for_uid(appid.c_str(), request, uid,
1129 }, b, uid, cb_info);
1132 ret = ::AulErrorConvert(ret);
1138 extern "C" API int aul_svc_get_appid_array(bundle* b, uid_t uid,
1139 char*** appid_array, unsigned int* len) {
1140 if (b == nullptr || appid_array == nullptr || len == nullptr) {
1141 _E("Invalid parameter");
1142 return AUL_SVC_RET_EINVAL;
1145 bundle_del(b, AUL_K_APPID);
1146 bundle_add(b, AUL_K_APPID, "@UNKNOWN");
1149 int ret = ::SendAndReceive(APP_GET_APPID_LIST, uid, b, &response);
1150 if (ret != AUL_SVC_RET_OK)
1153 tizen_base::Bundle res(response, false, true);
1154 auto str = res.GetString(AUL_SVC_K_URI_R_INFO);
1156 ::SetBundle(b, AUL_SVC_K_URI_R_INFO, str.c_str());
1158 auto str_arr = res.GetStringArray(AUL_K_APPID_LIST);
1159 if (str_arr.empty()) {
1160 _E("Failed to get appid list");
1161 return AUL_SVC_RET_ERROR;
1164 *appid_array = reinterpret_cast<char**>(
1165 calloc(str_arr.size(), sizeof(char*)));
1166 if (*appid_array == nullptr) {
1167 _E("Out of memory");
1168 return AUL_SVC_RET_ENOMEM;
1171 *len = str_arr.size();
1174 for (auto& appid : str_arr)
1175 (*appid_array)[i++] = strdup(appid.c_str());
1177 return AUL_SVC_RET_OK;
1180 extern "C" API void aul_svc_free_appid_array(char** appid_array,
1182 if (appid_array == nullptr)
1185 for (unsigned int i = 0; i < len; ++i)
1186 free(appid_array[i]);
1191 extern "C" API int aul_svc_set_defapp(const char* op, const char* mime_type,
1192 const char* uri, const char* defapp) {
1193 DEPRECATION_WARNING();
1194 return AUL_SVC_RET_OK;
1197 extern "C" API int aul_svc_set_defapp_for_uid(const char* op,
1198 const char* mime_type, const char* uri, const char* defapp, uid_t uid) {
1199 DEPRECATION_WARNING();
1200 return AUL_SVC_RET_OK;
1203 extern "C" API int aul_svc_unset_defapp(const char* defapp) {
1204 DEPRECATION_WARNING();
1205 return AUL_SVC_RET_OK;
1208 extern "C" API int aul_svc_unset_defapp_for_uid(const char* defapp, uid_t uid) {
1209 DEPRECATION_WARNING();
1210 return AUL_SVC_RET_OK;
1213 extern "C" API int aul_svc_unset_all_defapps(void) {
1214 DEPRECATION_WARNING();
1215 return AUL_SVC_RET_OK;
1218 extern "C" API int aul_svc_unset_all_defapps_for_uid(uid_t uid) {
1219 DEPRECATION_WARNING();
1220 return AUL_SVC_RET_OK;
1223 extern "C" API int aul_svc_is_defapp(const char* pkg_name) {
1224 DEPRECATION_WARNING();
1225 return AUL_SVC_RET_OK;
1228 extern "C" API int aul_svc_is_defapp_for_uid(const char* pkg_name, uid_t uid) {
1229 DEPRECATION_WARNING();
1230 return AUL_SVC_RET_OK;
1233 extern "C" API int aul_svc_set_alias_appid(const char* alias_appid,
1234 const char* appid) {
1235 DEPRECATION_WARNING();
1236 return AUL_SVC_RET_OK;
1239 extern "C" API int aul_svc_set_alias_appid_for_uid(const char* alias_appid,
1240 const char* appid, uid_t uid) {
1241 DEPRECATION_WARNING();
1242 return AUL_SVC_RET_OK;
1245 extern "C" API int aul_svc_unset_alias_appid(const char* alias_appid) {
1246 DEPRECATION_WARNING();
1247 return AUL_SVC_RET_OK;
1250 extern "C" API int aul_svc_unset_alias_appid_for_uid(const char* alias_appid,
1252 DEPRECATION_WARNING();
1253 return AUL_SVC_RET_OK;
1256 extern "C" API int aul_svc_foreach_alias_info(
1257 void (*callback)(const char *, const char *, void *),
1259 DEPRECATION_WARNING();
1260 return AUL_SVC_RET_OK;
1263 extern "C" API int aul_svc_foreach_alias_info_for_uid(
1264 void (*callback)(const char *, const char *, void *),
1265 uid_t uid, void* user_data) {
1266 DEPRECATION_WARNING();
1267 return AUL_SVC_RET_OK;
1270 extern "C" API int aul_svc_enable_alias_info(const char* appid) {
1271 DEPRECATION_WARNING();
1272 return AUL_SVC_RET_OK;
1275 extern "C" API int aul_svc_enable_alias_info_for_uid(const char* appid,
1277 DEPRECATION_WARNING();
1278 return AUL_SVC_RET_OK;
1281 extern "C" API int aul_svc_disable_alias_info(const char* appid) {
1282 DEPRECATION_WARNING();
1283 return AUL_SVC_RET_OK;
1286 extern "C" API int aul_svc_disable_alias_info_for_uid(const char* appid,
1288 DEPRECATION_WARNING();
1289 return AUL_SVC_RET_OK;
1292 extern "C" API int aul_svc_foreach_alias_info_by_appid(
1293 int (*callback)(const char *, const char *, void *),
1294 const char* appid, void* user_data) {
1295 DEPRECATION_WARNING();
1296 return AUL_SVC_RET_OK;
1299 extern "C" API int aul_svc_foreach_alias_info_by_appid_for_uid(
1300 int (*callback)(const char *, const char *, void *),
1301 const char* appid, uid_t uid, void* user_data) {
1302 DEPRECATION_WARNING();
1303 return AUL_SVC_RET_OK;
1306 extern "C" API int aul_svc_foreach_allowed_info(
1307 int (*callback)(const char *, const char *, void *),
1309 DEPRECATION_WARNING();
1310 return AUL_SVC_RET_OK;
1313 extern "C" API int aul_svc_foreach_allowed_info_for_uid(
1314 int (*callback)(const char *, const char *, void *),
1315 uid_t uid, void* user_data) {
1316 DEPRECATION_WARNING();
1317 return AUL_SVC_RET_OK;
1320 extern "C" API int aul_svc_foreach_allowed_info_by_appid(
1321 int (*callback)(const char *, const char *, void *),
1322 const char* appid, void* user_data) {
1323 DEPRECATION_WARNING();
1324 return AUL_SVC_RET_OK;
1327 extern "C" API int aul_svc_foreach_allowed_info_by_appid_for_uid(
1328 int (*callback)(const char *, const char *, void *),
1329 const char* appid, uid_t uid, void* user_data) {
1330 DEPRECATION_WARNING();
1331 return AUL_SVC_RET_OK;