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>
21 #include <iniparser.h>
27 #include <sys/types.h>
33 #include "aul/app_control/resolve_info.hh"
34 #include "include/aul.h"
35 #include "include/aul_app_group.h"
36 #include "include/aul_error.h"
37 #include "include/aul_sock.h"
38 #include "include/aul_svc.h"
39 #include "include/aul_svc_internal.h"
40 #include "src/aul_api.h"
41 #include "src/aul_svc_priv_key.h"
42 #include "src/aul_util.h"
43 #include "src/launch.h"
45 #undef MAX_MIME_STR_SIZE
46 #define MAX_MIME_STR_SIZE 256
48 #undef MAX_SCHEME_STR_SIZE
49 #define MAX_SCHEME_STR_SIZE 256
51 #undef MAX_HOST_STR_SIZE
52 #define MAX_HOST_STR_SIZE 256
54 #undef DEPRECATION_WARNING
55 #define DEPRECATION_WARNING() do { \
56 dlog_print(DLOG_WARN, LOG_TAG, \
57 "DEPRECATION WARNING: %s() is deprecated and " \
58 "will be removed from next release.", __FUNCTION__); \
65 CbInfo(int request_code, aul_svc_res_fn res_fn,
66 aul_svc_err_cb err_cb, void* user_data)
67 : request_code_(request_code),
70 user_data_(user_data) {
74 aul_svc_res_fn res_fn_;
75 aul_svc_err_cb err_cb_;
79 int SetBundle(bundle* b, const char* key, const char* value) {
80 if (bundle_get_type(b, key) != BUNDLE_TYPE_NONE) {
81 if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
82 return AUL_SVC_RET_ERROR;
86 return AUL_SVC_RET_EINVAL;
88 if (bundle_add(b, key, value) != BUNDLE_ERROR_NONE)
89 return AUL_SVC_RET_ERROR;
91 SECURE_LOGD("key(%s), value(%s)", key, value);
92 return AUL_SVC_RET_OK;
95 int SetBundleArray(bundle* b, const char* key, const char** value,
97 int is_array = aul_svc_data_is_array(b, key);
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_str_array(b, key, value, len) != BUNDLE_ERROR_NONE)
107 return AUL_SVC_RET_ERROR;
109 SECURE_LOGD("key(%s), length(%d)", key, len);
110 return AUL_SVC_RET_OK;
113 std::string GetAliasAppId(const char* appid) {
114 dictionary* dic = iniparser_load("/usr/share/appsvc/alias.ini");
118 auto dic_ptr = std::unique_ptr<dictionary, decltype(iniparser_freedict)*>(
119 dic, iniparser_freedict);
121 std::string key = std::string("Alias:") + appid;
122 const char* value = iniparser_getstring(dic, key.c_str(), nullptr);
123 SECURE_LOGD("appid(%s), alias_id(%s)", appid, value);
124 if (value == nullptr)
127 return std::string(value);
130 bool IsSpecialApp(const char* appid) {
131 if (!strcmp(appid, APP_SELECTOR) || !strcmp(appid, SHARE_PANEL))
137 bool IsSpecialOperation(const char* operation) {
138 if (operation == nullptr)
141 int ret = strcmp(operation,
142 "http://tizen.org/appcontrol/operation/guide_privacy_setting");
149 std::string GetAppId(bundle* request) {
150 const char* appid = aul_svc_get_pkgname(request);
151 if (appid == nullptr) {
152 if (aul_svc_get_operation(request) == nullptr) {
153 _E("Invalid request");
160 int ret = bundle_get_type(request, AUL_SVC_K_SELECTOR_EXTRA_LIST);
161 if (ret != BUNDLE_TYPE_NONE) {
162 if (appid == nullptr || !strcmp(appid, "@UNKNOWN"))
163 appid = APP_SELECTOR;
166 ret = bundle_get_type(request, AUL_K_FORCE_LAUNCH_APP_SELECTOR);
167 if (ret != BUNDLE_TYPE_NONE)
168 appid = APP_SELECTOR;
170 return std::string(appid);
173 void SetLaunchData(bundle* request, const std::string& appid) {
174 const char* operation = aul_svc_get_operation(request);
175 if (operation == nullptr)
176 aul_svc_set_operation(request, AUL_SVC_OPERATION_DEFAULT);
178 if (IsSpecialApp(appid.c_str()) || IsSpecialOperation(operation)) {
179 SetBundle(request, AUL_SVC_K_CAN_BE_LEADER, "true");
180 SetBundle(request, AUL_SVC_K_REROUTE, "true");
181 SetBundle(request, AUL_SVC_K_RECYCLE, "true");
184 const char* launch_mode = aul_svc_get_launch_mode(request);
185 if (launch_mode && !strcmp(launch_mode, "group")) {
186 int ret = bundle_get_type(request, AUL_K_INSTANCE_ID);
187 if (ret != BUNDLE_TYPE_NONE)
188 aul_set_instance_info(appid.c_str(), request);
192 int AulErrorConvert(int res) {
195 return AUL_SVC_RET_EILLACC;
197 return AUL_SVC_RET_EINVAL;
198 case AUL_R_ETERMINATING:
199 return AUL_SVC_RET_ETERMINATING;
200 case AUL_R_EREJECTED:
201 return AUL_SVC_RET_EREJECTED;
203 return AUL_SVC_RET_ENOMATCH;
204 case AUL_R_ECANCELED:
205 return AUL_SVC_RET_ECANCELED;
207 return AUL_SVC_RET_ELAUNCH;
211 void LaunchWithResultCb(bundle* b, int is_cancel, void* data) {
214 res = AUL_SVC_RES_CANCEL;
216 const char* val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
217 res = (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val);
220 bundle_del(b, AUL_SVC_K_RES_VAL);
221 auto* cb_info = static_cast<CbInfo*>(data);
222 if (cb_info == nullptr) {
223 _E("Invalid parameter");
227 if (cb_info->res_fn_) {
228 cb_info->res_fn_(b, cb_info->request_code_,
229 static_cast<aul_svc_result_val>(res), cb_info->user_data_);
230 cb_info->res_fn_ = nullptr;
233 if (cb_info->err_cb_ != nullptr)
239 void ErrorCb(int error, void* data) {
241 error = AulErrorConvert(error);
243 auto* cb_info = static_cast<CbInfo*>(data);
244 if (cb_info == nullptr) {
245 _E("Invalid parameter");
249 if (cb_info->err_cb_) {
250 cb_info->err_cb_(cb_info->request_code_, error, cb_info->user_data_);
251 cb_info->err_cb_ = nullptr;
254 if (cb_info->res_fn_)
260 using SendLaunchRequestCb =
261 int (*)(const std::string&, bundle*, uid_t, CbInfo*);
262 using SendLaunchRequestSyncCb =
263 int (*)(const std::string&, bundle*, uid_t, bundle**);
265 template <typename T, typename A>
266 int SendLaunchRequest(T cb, bundle* request, uid_t uid, A arg) {
267 if (request == nullptr) {
268 _E("Invalid parameter");
269 return AUL_SVC_RET_EINVAL;
272 std::string appid = GetAppId(request);
274 _E("GetAppId() is failed");
275 return AUL_SVC_RET_EINVAL;
278 SetLaunchData(request, appid);
279 return cb(appid, request, uid, arg);
282 int SendAndReceive(int cmd, uid_t uid, bundle* request, bundle** response) {
283 int fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, cmd, request,
286 return AUL_SVC_RET_ERROR;
288 app_pkt_t* pkt = nullptr;
289 int ret = aul_sock_recv_reply_pkt(fd, &pkt);
291 _E("Failed to receive reply packet. error(%d)", ret);
292 return AUL_SVC_RET_ERROR;
295 auto ptr = std::unique_ptr<app_pkt_t, decltype(std::free)*>(pkt, std::free);
296 if (pkt->cmd != APP_GET_INFO_OK && pkt->cmd != cmd) {
297 if (pkt->cmd == APP_GET_INFO_ERROR)
298 return AUL_SVC_RET_ERROR;
300 return AulErrorConvert(aul_error_convert(pkt->cmd));
304 if (pkt->opt & AUL_SOCK_BUNDLE) {
305 b = bundle_decode(pkt->data, pkt->len);
307 _E("bundle_decode() is failed");
308 return AUL_SVC_RET_ENOMEM;
311 _E("Invalid packet");
312 return AUL_SVC_RET_ERROR;
316 return AUL_SVC_RET_OK;
321 extern "C" API int aul_svc_set_operation(bundle* b, const char* operation) {
323 _E("Invalid parameter");
324 return AUL_SVC_RET_EINVAL;
327 return ::SetBundle(b, AUL_SVC_K_OPERATION, operation);
330 extern "C" API int aul_svc_set_uri(bundle* b, const char* uri) {
332 _E("Invalid parameter");
333 return AUL_SVC_RET_EINVAL;
336 return ::SetBundle(b, AUL_SVC_K_URI, uri);
339 extern "C" API int aul_svc_set_mime(bundle* b, const char* mime) {
341 _E("Invalid parameter");
342 return AUL_SVC_RET_EINVAL;
345 return ::SetBundle(b, AUL_SVC_K_MIME, mime);
348 extern "C" API int aul_svc_add_data(bundle* b, const char* key,
350 if (b == nullptr || key == nullptr)
351 return AUL_SVC_RET_EINVAL;
353 return ::SetBundle(b, key, value);
356 extern "C" API int aul_svc_add_data_array(bundle* b, const char* key,
357 const char** value, int len) {
358 if (b == nullptr || key == nullptr)
359 return AUL_SVC_RET_EINVAL;
361 return ::SetBundleArray(b, key, value, len);
364 extern "C" API int aul_svc_set_pkgname(bundle* b, const char* pkg_name) {
366 _E("Invalid parameter");
367 return AUL_SVC_RET_EINVAL;
370 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
373 extern "C" API int aul_svc_set_appid(bundle* b, const char* appid) {
374 if (b == nullptr || appid == nullptr) {
375 _E("Invalid parameter");
376 return AUL_SVC_RET_EINVAL;
379 std::string alias_id = ::GetAliasAppId(appid);
380 if (!alias_id.empty())
381 appid = alias_id.c_str();
383 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, appid);
386 extern "C" API int aul_svc_set_category(bundle* b, const char* category) {
388 _E("Invalid parameter");
389 return AUL_SVC_RET_EINVAL;
392 return ::SetBundle(b, AUL_SVC_K_CATEGORY, category);
395 extern "C" API int aul_svc_set_launch_mode(bundle* b, const char* mode) {
397 _E("Invalid parameter");
398 return AUL_SVC_RET_EINVAL;
401 return ::SetBundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
404 extern "C" API int aul_svc_resolve(bundle* b, uid_t uid, char*** appid_array,
406 return aul_svc_get_appid_array(b, uid, appid_array, len);
409 extern "C" API int aul_svc_run_service(bundle* b, int request_code,
410 aul_svc_res_fn cbfunc, void* data) {
411 return aul_svc_run_service_for_uid(b, request_code, cbfunc, data, getuid());
414 extern "C" API int aul_svc_run_service_for_uid(bundle* b, int request_code,
415 aul_svc_res_fn cbfunc, void* data, uid_t uid) {
416 CbInfo* cb_info = nullptr;
418 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
419 if (cb_info == nullptr)
420 LOGE("Out of memory");
422 std::tuple<aul_svc_res_fn, void*> param { cbfunc, data };
423 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
424 [](const std::string& appid, bundle* request, uid_t uid,
425 CbInfo* cb_info) -> int {
428 ret = aul_launch_app_with_result_for_uid(appid.c_str(), request,
429 LaunchWithResultCb, cb_info, uid);
431 ret = aul_launch_app_for_uid(appid.c_str(), request, uid);
440 ret = AulErrorConvert(ret);
446 extern "C" API int aul_svc_get_list(bundle* b, aul_svc_info_iter_fn iter_fn,
448 return aul_svc_get_list_for_uid(b, iter_fn, data, getuid());
451 extern "C" API int aul_svc_get_list_for_uid(bundle* b,
452 aul_svc_info_iter_fn iter_fn, void* data, uid_t uid) {
453 if (b == nullptr || iter_fn == nullptr) {
454 _E("Invalid parameter");
455 return AUL_SVC_RET_EINVAL;
458 char** appid_array = nullptr;
459 unsigned int len = 0;
460 int ret = aul_svc_get_appid_array(b, uid, &appid_array, &len);
461 if (ret != AUL_SVC_RET_OK)
465 _E("Failed to find associated application");
466 aul_svc_free_appid_array(appid_array, len);
467 return AUL_SVC_RET_ENOMATCH;
470 for (unsigned int i = 0; i < len; ++i) {
471 SECURE_LOGD("APPID: %s", appid_array[i]);
472 if (iter_fn(appid_array[i], data) != 0)
476 aul_svc_free_appid_array(appid_array, len);
477 return AUL_SVC_RET_OK;
480 extern "C" API int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn,
482 return aul_svc_get_all_defapps_for_uid(iter_fn, data, getuid());
485 extern "C" API int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
486 void* data, uid_t uid) {
487 if (iter_fn == nullptr) {
488 _E("Invalid parameter");
489 return AUL_SVC_RET_EINVAL;
493 tizen_base::Bundle request;
494 int ret = ::SendAndReceive(APP_GET_APP_CONTROL_DEFAULT_APPS, uid,
495 request.GetHandle(), &response);
496 if (ret != AUL_SVC_RET_OK)
499 tizen_base::Bundle res(response, false, true);
500 auto appid_array = res.GetStringArray(AUL_K_APPID_LIST);
501 for (auto& appid : appid_array) {
502 if (iter_fn(appid.c_str(), data) != 0)
506 return AUL_SVC_RET_OK;
509 extern "C" API const char* aul_svc_get_operation(bundle* b) {
510 return bundle_get_val(b, AUL_SVC_K_OPERATION);
513 extern "C" API const char* aul_svc_get_uri(bundle* b) {
514 return bundle_get_val(b, AUL_SVC_K_URI);
517 extern "C" API const char* aul_svc_get_mime(bundle* b) {
518 return bundle_get_val(b, AUL_SVC_K_MIME);
521 extern "C" API const char* aul_svc_get_data(bundle* b, const char* key) {
522 return bundle_get_val(b, key);
525 extern "C" API const char** aul_svc_get_data_array(bundle* b, const char* key,
527 return bundle_get_str_array(b, key, len);
530 extern "C" API const char* aul_svc_get_pkgname(bundle* b) {
531 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
534 extern "C" API const char* aul_svc_get_appid(bundle* b) {
535 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
538 extern "C" API const char* aul_svc_get_category(bundle* b) {
539 return bundle_get_val(b, AUL_SVC_K_CATEGORY);
542 extern "C" API const char* aul_svc_get_launch_mode(bundle* b) {
543 return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
546 extern "C" API int aul_svc_create_result_bundle(bundle* inb, bundle** outb) {
547 if (inb == nullptr || outb == nullptr) {
548 _E("Invalid parameter");
549 return AUL_SVC_RET_EINVAL;
552 int ret = aul_create_result_bundle(inb, outb);
554 return AulErrorConvert(ret);
556 return AUL_SVC_RET_OK;
559 extern "C" API int aul_svc_send_result(bundle* b, aul_svc_result_val result) {
561 _E("Invalid parameter");
562 return AUL_SVC_RET_EINVAL;
565 int ret = ::SetBundle(b, AUL_SVC_K_RES_VAL, std::to_string(result).c_str());
567 return AUL_SVC_RET_ERROR;
569 if (result == AUL_SVC_RES_CANCEL)
570 ret = aul_send_result(b, 1);
572 ret = aul_send_result(b, 0);
574 bundle_del(b, AUL_SVC_K_RES_VAL);
578 extern "C" API int aul_svc_data_is_array(bundle* b, const char* key) {
579 int type = bundle_get_type(b, key);
583 if (type & BUNDLE_TYPE_ARRAY)
589 extern "C" API int aul_svc_allow_transient_app(bundle* b, int wid) {
591 _E("Invalid parameter");
592 return AUL_SVC_RET_EINVAL;
595 return ::SetBundle(b, AUL_SVC_K_WIN_ID, std::to_string(wid).c_str());
598 extern "C" API int aul_svc_request_transient_app(bundle* b, int callee_wid,
599 aul_svc_host_res_fn cbfunc, void* data) {
603 extern "C" API int aul_svc_subapp_terminate_request_pid(int pid) {
606 int* lpids = nullptr;
607 aul_app_group_get_leader_pids(&lcnt, &lpids);
608 for (int i = 0; i < lcnt; ++i) {
609 if (lpids[i] == cpid) {
612 aul_app_group_get_group_pids(cpid, &cnt, &pids);
618 return aul_subapp_terminate_request_pid(pid);
627 if (lpids != nullptr)
630 return aul_app_group_clear_top();
633 extern "C" API int aul_send_service_result(bundle* b) {
634 return aul_send_result(b, 0);
637 extern "C" API int aul_svc_subscribe_launch_result(bundle* b,
638 const char* result) {
640 _E("Invalid parameter");
641 return AUL_SVC_RET_EINVAL;
644 return ::SetBundle(b, result, "1");
647 extern "C" API int aul_svc_set_loader_id(bundle* b, int loader_id) {
648 if (b == nullptr || loader_id <= 0) {
649 _E("Invalid parameter");
650 return AUL_SVC_RET_EINVAL;
653 return ::SetBundle(b, AUL_K_LOADER_ID, std::to_string(loader_id).c_str());
656 extern "C" API int aul_svc_set_loader_name(bundle* b, const char* loader_name) {
657 if (b == nullptr || loader_name == nullptr) {
658 _E("Invalid parameter");
659 return AUL_SVC_RET_EINVAL;
662 return ::SetBundle(b, AUL_K_LOADER_NAME, loader_name);
665 extern "C" API int aul_svc_set_background_launch(bundle* b, int enabled) {
667 _E("Invalid parameter");
668 return AUL_SVC_RET_EINVAL;
671 return ::SetBundle(b, AUL_SVC_K_BG_LAUNCH, enabled ? "enable" : nullptr);
674 extern "C" API int aul_svc_get_appid_by_alias_appid(const char* alias_appid,
676 return aul_svc_get_appid_by_alias_appid_for_uid(alias_appid, appid, getuid());
679 extern "C" API int aul_svc_get_appid_by_alias_appid_for_uid(
680 const char* alias_appid, char** appid, uid_t uid) {
681 if (alias_appid == nullptr || appid == nullptr) {
682 _E("Invalid parameter");
683 return AUL_SVC_RET_EINVAL;
687 tizen_base::Bundle request;
688 request.Add(AUL_K_ALIAS_APPID, alias_appid);
689 int ret = ::SendAndReceive(APP_GET_APPID_BY_ALIAS_APPID, uid,
690 request.GetHandle(), &response);
691 if (ret != AUL_SVC_RET_OK)
694 tizen_base::Bundle res(response, false, true);
695 auto val = res.GetString(AUL_K_APPID);
697 return AUL_SVC_RET_ERROR;
699 *appid = strdup(val.c_str());
700 if (*appid == nullptr) {
702 return AUL_SVC_RET_ENOMEM;
705 return AUL_SVC_RET_OK;
708 extern "C" API const char *aul_svc_get_instance_id(bundle* b) {
709 return bundle_get_val(b, AUL_K_INSTANCE_ID);
712 extern "C" API int aul_svc_set_instance_id(bundle* b, const char* instance_id) {
714 _E("Invalid parameter");
715 return AUL_SVC_RET_EINVAL;
718 return ::SetBundle(b, AUL_K_INSTANCE_ID, instance_id);
721 extern "C" API int aul_svc_run_service_async(bundle* b, int request_code,
722 aul_svc_res_fn cbfunc, void* data) {
723 return aul_svc_run_service_async_for_uid(b, request_code, cbfunc, data,
727 extern "C" API int aul_svc_run_service_async_for_uid(bundle* b,
728 int request_code, aul_svc_res_fn cbfunc, void* data, uid_t uid) {
729 CbInfo* cb_info = nullptr;
731 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
733 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
734 [](const std::string& appid, bundle* request, uid_t uid,
735 CbInfo* info) -> int {
737 return aul_launch_app_with_result_async_for_uid(appid.c_str(),
738 request, LaunchWithResultCb, info, uid);
741 return aul_launch_app_async_for_uid(appid.c_str(), request, uid);
747 ret = AulErrorConvert(ret);
753 extern "C" API int aul_svc_send_launch_request(bundle* b, int request_code,
754 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void* user_data) {
755 return aul_svc_send_launch_request_for_uid(b, request_code,
756 cbfunc, err_cb, user_data, getuid());
759 extern "C" API int aul_svc_send_launch_request_for_uid(bundle* b,
760 int request_code, aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
761 void* user_data, uid_t uid) {
762 if (b == nullptr || err_cb == nullptr) {
763 _E("Invalid parameter");
764 return AUL_SVC_RET_EINVAL;
767 CbInfo* cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, err_cb,
769 if (cb_info == nullptr)
772 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
773 [](const std::string& appid, bundle* request, uid_t uid,
774 CbInfo* info) -> int {
775 return aul_send_launch_request_for_uid(appid.c_str(), request, uid,
776 info->res_fn_ ? ::LaunchWithResultCb : nullptr, ::ErrorCb, info);
780 ret = ::AulErrorConvert(ret);
786 extern "C" API int aul_svc_send_launch_request_sync_for_uid(bundle* b,
787 int request_code, bundle** res_b, aul_svc_result_val* res, uid_t uid) {
788 if (b == nullptr || res_b == nullptr || res == nullptr) {
789 _E("Invalid parameter");
790 return AUL_SVC_RET_EINVAL;
793 int ret = ::SendLaunchRequest<::SendLaunchRequestSyncCb, bundle**>(
794 [](const std::string& appid, bundle* request, uid_t uid,
795 bundle** response) -> int {
796 return aul_send_launch_request_sync_for_uid(appid.c_str(), request,
800 auto* val = bundle_get_val(*res_b, AUL_SVC_K_RES_VAL);
801 *res = static_cast<aul_svc_result_val>(
802 (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val));
804 ret = ::AulErrorConvert(ret);
805 *res = AUL_SVC_RES_CANCEL;
811 extern "C" API int aul_svc_info_create(bundle* b, aul_svc_info_h* h) {
812 if (b == nullptr || h == nullptr) {
813 _E("Invalid parameter");
814 return AUL_SVC_RET_EINVAL;
817 aul::ResolveInfo* resolve_info = nullptr;
819 tizen_base::Bundle kb(b, false, false);
820 resolve_info = aul::ResolveInfo::Manager::Create(kb);
821 } catch (aul::Exception& e) {
822 return AUL_SVC_RET_ERROR;
825 *h = static_cast<aul_svc_info_h>(resolve_info);
826 return AUL_SVC_RET_OK;
829 extern "C" API int aul_svc_info_get_operation(aul_svc_info_h h,
831 if (h == nullptr || operation == nullptr) {
832 _E("Invalid parameter");
833 return AUL_SVC_RET_EINVAL;
836 auto* info = static_cast<aul::ResolveInfo*>(h);
837 auto& value = info->GetOperation();
838 *operation = strdup(value.empty() ? "NULL" : value.c_str());
839 if (*operation == nullptr) {
840 _E("Failed to duplicate operation");
841 return AUL_SVC_RET_ERROR;
844 return AUL_SVC_RET_OK;
847 extern "C" API int aul_svc_info_get_uri(aul_svc_info_h h, char** uri) {
848 if (h == nullptr || uri == nullptr) {
849 _E("Invalid parameter");
850 return AUL_SVC_RET_EINVAL;
853 auto* info = static_cast<aul::ResolveInfo*>(h);
854 auto& value = info->GetUri();
855 *uri = strdup(value.empty() ? "NULL" : value.c_str());
856 if (*uri == nullptr) {
857 _E("Failed to duplicate URI");
858 return AUL_SVC_RET_ERROR;
861 return AUL_SVC_RET_OK;
864 extern "C" API int aul_svc_info_get_uri_scheme(aul_svc_info_h h,
866 if (h == nullptr || uri_scheme == nullptr) {
867 _E("Invalid parameter");
868 return AUL_SVC_RET_EINVAL;
871 auto* info = static_cast<aul::ResolveInfo*>(h);
872 auto& value = info->GetScheme();
873 *uri_scheme = strdup(value.empty() ? "NULL" : value.c_str());
874 if (*uri_scheme == nullptr) {
875 _E("Failed to duplicate URI scheme");
876 return AUL_SVC_RET_ERROR;
879 return AUL_SVC_RET_OK;
882 extern "C" API int aul_svc_info_get_uri_host(aul_svc_info_h h,
884 if (h == nullptr || uri_host == nullptr) {
885 _E("Invalid parameter");
886 return AUL_SVC_RET_EINVAL;
889 auto* info = static_cast<aul::ResolveInfo*>(h);
890 auto& value = info->GetHost();
891 *uri_host = strdup(value.empty() ? "NULL" : value.c_str());
892 if (*uri_host == nullptr) {
893 _E("Failed to duplicate URI host");
894 return AUL_SVC_RET_ERROR;
897 return AUL_SVC_RET_OK;
900 extern "C" API int aul_svc_info_get_mime(aul_svc_info_h h, char** mime) {
901 if (h == nullptr || mime == nullptr) {
902 _E("Invalid parameter");
903 return AUL_SVC_RET_EINVAL;
906 auto* info = static_cast<aul::ResolveInfo*>(h);
907 auto& value = info->GetMime();
908 *mime = strdup(value.empty() ? "NULL" : value.c_str());
909 if (*mime == nullptr) {
910 _E("Failed to duplicate MIME-Type");
911 return AUL_SVC_RET_ERROR;
914 return AUL_SVC_RET_OK;
917 extern "C" API int aul_svc_info_get_mime_type(aul_svc_info_h h,
919 if (h == nullptr || mime_type == nullptr) {
920 _E("Invalid parameter");
921 return AUL_SVC_RET_EINVAL;
924 auto* info = static_cast<aul::ResolveInfo*>(h);
925 auto& value = info->GetMType();
926 *mime_type = strdup(value.empty() ? "NULL" : value.c_str());
927 if (*mime_type == nullptr) {
928 _E("Failed to duplicate the type of MIME-Type");
929 return AUL_SVC_RET_ERROR;
932 return AUL_SVC_RET_OK;
935 extern "C" API int aul_svc_info_get_mime_subtype(aul_svc_info_h h,
936 char** mime_subtype) {
937 if (h == nullptr || mime_subtype == nullptr) {
938 _E("Invalid parameter");
939 return AUL_SVC_RET_EINVAL;
942 auto* info = static_cast<aul::ResolveInfo*>(h);
943 auto& value = info->GetSType();
944 *mime_subtype = strdup(value.empty() ? "NULL" : value.c_str());
945 if (*mime_subtype == nullptr) {
946 _E("Failed to duplicate the subtype of MIME-Type");
947 return AUL_SVC_RET_ERROR;
950 return AUL_SVC_RET_OK;
953 extern "C" API int aul_svc_info_destroy(aul_svc_info_h h) {
955 _E("Invalid parameter");
956 return AUL_SVC_RET_EINVAL;
959 auto* info = static_cast<aul::ResolveInfo*>(h);
961 return AUL_SVC_RET_OK;
964 extern "C" API int aul_svc_set_caller_instance_id(bundle* b,
965 const char* instance_id) {
967 _E("Invalid parameter");
968 return AUL_SVC_RET_EINVAL;
971 return ::SetBundle(b, AUL_K_CALLER_INSTANCE_ID, instance_id);
974 extern "C" API int aul_svc_set_comp_id(bundle* b, const char* comp_id) {
976 _E("Invalid parameter");
977 return AUL_SVC_RET_EINVAL;
980 return ::SetBundle(b, AUL_K_COMPONENT_ID, comp_id);
983 extern "C" API const char *aul_svc_get_comp_id(bundle* b) {
984 return bundle_get_val(b, AUL_K_COMPONENT_ID);
987 extern "C" API int aul_svc_subapp_terminate_request(bundle* b, int pid) {
988 if (b == nullptr || pid < 0) {
989 _E("Invalid parameter");
990 return AUL_SVC_RET_EINVAL;
993 const char* inst_id = bundle_get_val(b, AUL_K_INSTANCE_ID);
994 if (inst_id == nullptr) {
995 _E("Invalid parameter");
996 return AUL_SVC_RET_EINVAL;
999 char buf[512] = { 0, };
1000 const char* caller_inst_id = bundle_get_val(b, AUL_K_CALLER_INSTANCE_ID);
1001 if (caller_inst_id == nullptr) {
1002 int ret = aul_app_get_instance_id_bypid(getpid(), buf, sizeof(buf));
1003 if (ret != AUL_R_OK) {
1004 _E("aul_app_get_instance_id_bypid() is failed. error(%d)", ret);
1005 return AUL_SVC_RET_ERROR;
1008 caller_inst_id = buf;
1012 aul_app_group_foreach_group_info(caller_inst_id,
1013 [](aul_app_group_info_h info, void* data) {
1014 int* count = static_cast<int*>(data);
1016 }, static_cast<void*>(&cnt));
1018 return aul_subapp_terminate_request(inst_id, pid);
1020 return aul_app_group_clear_top();
1023 extern "C" API int aul_svc_send_resume_request(bundle* b, int request_code,
1024 aul_svc_err_cb err_cb, void *user_data) {
1025 return aul_svc_send_resume_request_for_uid(b, request_code, err_cb, user_data,
1029 extern "C" API int aul_svc_send_resume_request_for_uid(bundle* b,
1030 int request_code, aul_svc_err_cb err_cb, void* user_data, uid_t uid) {
1031 if (b == nullptr || err_cb == nullptr) {
1032 _E("Invalid parameter");
1033 return AUL_SVC_RET_EINVAL;
1036 auto* cb_info = new (std::nothrow) CbInfo(request_code, nullptr, err_cb,
1038 if (cb_info == nullptr)
1039 _E("Out of memory");
1041 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
1042 [](const std::string& appid, bundle* request, uid_t uid,
1043 CbInfo* info) -> int {
1044 return aul_send_resume_request_for_uid(appid.c_str(), request, uid,
1046 }, b, uid, cb_info);
1049 ret = ::AulErrorConvert(ret);
1055 extern "C" API int aul_svc_get_appid_array(bundle* b, uid_t uid,
1056 char*** appid_array, unsigned int* len) {
1057 if (b == nullptr || appid_array == nullptr || len == nullptr) {
1058 _E("Invalid parameter");
1059 return AUL_SVC_RET_EINVAL;
1062 bundle_del(b, AUL_K_APPID);
1063 bundle_add(b, AUL_K_APPID, "@UNKNOWN");
1066 int ret = ::SendAndReceive(APP_GET_APPID_LIST, uid, b, &response);
1067 if (ret != AUL_SVC_RET_OK)
1070 tizen_base::Bundle res(response, false, true);
1071 auto str = res.GetString(AUL_SVC_K_URI_R_INFO);
1073 ::SetBundle(b, AUL_SVC_K_URI_R_INFO, str.c_str());
1075 auto str_arr = res.GetStringArray(AUL_K_APPID_LIST);
1076 if (str_arr.empty()) {
1077 _E("Failed to get appid list");
1078 return AUL_SVC_RET_ERROR;
1081 *appid_array = reinterpret_cast<char**>(
1082 calloc(str_arr.size(), sizeof(char*)));
1083 if (*appid_array == nullptr) {
1084 _E("Out of memory");
1085 return AUL_SVC_RET_ENOMEM;
1088 *len = str_arr.size();
1091 for (auto& appid : str_arr)
1092 (*appid_array)[i++] = strdup(appid.c_str());
1094 return AUL_SVC_RET_OK;
1097 extern "C" API void aul_svc_free_appid_array(char** appid_array,
1099 if (appid_array == nullptr)
1102 for (unsigned int i = 0; i < len; ++i)
1103 free(appid_array[i]);
1108 extern "C" API int aul_svc_set_defapp(const char* op, const char* mime_type,
1109 const char* uri, const char* defapp) {
1110 DEPRECATION_WARNING();
1111 return AUL_SVC_RET_OK;
1114 extern "C" API int aul_svc_set_defapp_for_uid(const char* op,
1115 const char* mime_type, const char* uri, const char* defapp, uid_t uid) {
1116 DEPRECATION_WARNING();
1117 return AUL_SVC_RET_OK;
1120 extern "C" API int aul_svc_unset_defapp(const char* defapp) {
1121 DEPRECATION_WARNING();
1122 return AUL_SVC_RET_OK;
1125 extern "C" API int aul_svc_unset_defapp_for_uid(const char* defapp, uid_t uid) {
1126 DEPRECATION_WARNING();
1127 return AUL_SVC_RET_OK;
1130 extern "C" API int aul_svc_unset_all_defapps(void) {
1131 DEPRECATION_WARNING();
1132 return AUL_SVC_RET_OK;
1135 extern "C" API int aul_svc_unset_all_defapps_for_uid(uid_t uid) {
1136 DEPRECATION_WARNING();
1137 return AUL_SVC_RET_OK;
1140 extern "C" API int aul_svc_is_defapp(const char* pkg_name) {
1141 DEPRECATION_WARNING();
1142 return AUL_SVC_RET_OK;
1145 extern "C" API int aul_svc_is_defapp_for_uid(const char* pkg_name, uid_t uid) {
1146 DEPRECATION_WARNING();
1147 return AUL_SVC_RET_OK;
1150 extern "C" API int aul_svc_set_alias_appid(const char* alias_appid,
1151 const char* appid) {
1152 DEPRECATION_WARNING();
1153 return AUL_SVC_RET_OK;
1156 extern "C" API int aul_svc_set_alias_appid_for_uid(const char* alias_appid,
1157 const char* appid, uid_t uid) {
1158 DEPRECATION_WARNING();
1159 return AUL_SVC_RET_OK;
1162 extern "C" API int aul_svc_unset_alias_appid(const char* alias_appid) {
1163 DEPRECATION_WARNING();
1164 return AUL_SVC_RET_OK;
1167 extern "C" API int aul_svc_unset_alias_appid_for_uid(const char* alias_appid,
1169 DEPRECATION_WARNING();
1170 return AUL_SVC_RET_OK;
1173 extern "C" API int aul_svc_foreach_alias_info(
1174 void (*callback)(const char *, const char *, void *),
1176 DEPRECATION_WARNING();
1177 return AUL_SVC_RET_OK;
1180 extern "C" API int aul_svc_foreach_alias_info_for_uid(
1181 void (*callback)(const char *, const char *, void *),
1182 uid_t uid, void* user_data) {
1183 DEPRECATION_WARNING();
1184 return AUL_SVC_RET_OK;
1187 extern "C" API int aul_svc_enable_alias_info(const char* appid) {
1188 DEPRECATION_WARNING();
1189 return AUL_SVC_RET_OK;
1192 extern "C" API int aul_svc_enable_alias_info_for_uid(const char* appid,
1194 DEPRECATION_WARNING();
1195 return AUL_SVC_RET_OK;
1198 extern "C" API int aul_svc_disable_alias_info(const char* appid) {
1199 DEPRECATION_WARNING();
1200 return AUL_SVC_RET_OK;
1203 extern "C" API int aul_svc_disable_alias_info_for_uid(const char* appid,
1205 DEPRECATION_WARNING();
1206 return AUL_SVC_RET_OK;
1209 extern "C" API int aul_svc_foreach_alias_info_by_appid(
1210 int (*callback)(const char *, const char *, void *),
1211 const char* appid, void* user_data) {
1212 DEPRECATION_WARNING();
1213 return AUL_SVC_RET_OK;
1216 extern "C" API int aul_svc_foreach_alias_info_by_appid_for_uid(
1217 int (*callback)(const char *, const char *, void *),
1218 const char* appid, uid_t uid, void* user_data) {
1219 DEPRECATION_WARNING();
1220 return AUL_SVC_RET_OK;
1223 extern "C" API int aul_svc_foreach_allowed_info(
1224 int (*callback)(const char *, const char *, void *),
1226 DEPRECATION_WARNING();
1227 return AUL_SVC_RET_OK;
1230 extern "C" API int aul_svc_foreach_allowed_info_for_uid(
1231 int (*callback)(const char *, const char *, void *),
1232 uid_t uid, void* user_data) {
1233 DEPRECATION_WARNING();
1234 return AUL_SVC_RET_OK;
1237 extern "C" API int aul_svc_foreach_allowed_info_by_appid(
1238 int (*callback)(const char *, const char *, void *),
1239 const char* appid, void* user_data) {
1240 DEPRECATION_WARNING();
1241 return AUL_SVC_RET_OK;
1244 extern "C" API int aul_svc_foreach_allowed_info_by_appid_for_uid(
1245 int (*callback)(const char *, const char *, void *),
1246 const char* appid, uid_t uid, void* user_data) {
1247 DEPRECATION_WARNING();
1248 return AUL_SVC_RET_OK;