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->res_fn_) {
223 cb_info->res_fn_(b, cb_info->request_code_,
224 static_cast<aul_svc_result_val>(res), cb_info->user_data_);
227 if (cb_info->err_cb_ != nullptr)
233 void ErrorCb(int error, void* data) {
235 error = AulErrorConvert(error);
237 auto* cb_info = static_cast<CbInfo*>(data);
238 if (cb_info->err_cb_) {
239 cb_info->err_cb_(cb_info->request_code_, error, cb_info->user_data_);
240 cb_info->err_cb_ = nullptr;
243 if (cb_info->res_fn_)
249 using SendLaunchRequestCb =
250 int (*)(const std::string&, bundle*, uid_t, CbInfo*);
251 using SendLaunchRequestSyncCb =
252 int (*)(const std::string&, bundle*, uid_t, bundle**);
254 template <typename T, typename A>
255 int SendLaunchRequest(T cb, bundle* request, uid_t uid, A arg) {
256 if (request == nullptr) {
257 _E("Invalid parameter");
258 return AUL_SVC_RET_EINVAL;
261 std::string appid = GetAppId(request);
263 _E("GetAppId() is failed");
264 return AUL_SVC_RET_EINVAL;
267 SetLaunchData(request, appid);
268 return cb(appid, request, uid, arg);
271 int SendAndReceive(int cmd, uid_t uid, bundle* request, bundle** response) {
272 int fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, cmd, request,
275 return AUL_SVC_RET_ERROR;
277 app_pkt_t* pkt = nullptr;
278 int ret = aul_sock_recv_reply_pkt(fd, &pkt);
280 _E("Failed to receive reply packet. error(%d)", ret);
281 return AUL_SVC_RET_ERROR;
284 auto ptr = std::unique_ptr<app_pkt_t, decltype(std::free)*>(pkt, std::free);
285 if (pkt->cmd != APP_GET_INFO_OK && pkt->cmd != cmd) {
286 if (pkt->cmd == APP_GET_INFO_ERROR)
287 return AUL_SVC_RET_ERROR;
289 return AulErrorConvert(aul_error_convert(pkt->cmd));
293 if (pkt->opt & AUL_SOCK_BUNDLE) {
294 b = bundle_decode(pkt->data, pkt->len);
296 _E("bundle_decode() is failed");
297 return AUL_SVC_RET_ENOMEM;
300 _E("Invalid packet");
301 return AUL_SVC_RET_ERROR;
305 return AUL_SVC_RET_OK;
310 extern "C" API int aul_svc_set_operation(bundle* b, const char* operation) {
312 _E("Invalid parameter");
313 return AUL_SVC_RET_EINVAL;
316 return ::SetBundle(b, AUL_SVC_K_OPERATION, operation);
319 extern "C" API int aul_svc_set_uri(bundle* b, const char* uri) {
321 _E("Invalid parameter");
322 return AUL_SVC_RET_EINVAL;
325 return ::SetBundle(b, AUL_SVC_K_URI, uri);
328 extern "C" API int aul_svc_set_mime(bundle* b, const char* mime) {
330 _E("Invalid parameter");
331 return AUL_SVC_RET_EINVAL;
334 return ::SetBundle(b, AUL_SVC_K_MIME, mime);
337 extern "C" API int aul_svc_add_data(bundle* b, const char* key,
339 if (b == nullptr || key == nullptr)
340 return AUL_SVC_RET_EINVAL;
342 return ::SetBundle(b, key, value);
345 extern "C" API int aul_svc_add_data_array(bundle* b, const char* key,
346 const char** value, int len) {
347 if (b == nullptr || key == nullptr)
348 return AUL_SVC_RET_EINVAL;
350 return ::SetBundleArray(b, key, value, len);
353 extern "C" API int aul_svc_set_pkgname(bundle* b, const char* pkg_name) {
355 _E("Invalid parameter");
356 return AUL_SVC_RET_EINVAL;
359 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
362 extern "C" API int aul_svc_set_appid(bundle* b, const char* appid) {
363 if (b == nullptr || appid == nullptr) {
364 _E("Invalid parameter");
365 return AUL_SVC_RET_EINVAL;
368 std::string alias_id = ::GetAliasAppId(appid);
369 if (!alias_id.empty())
370 appid = alias_id.c_str();
372 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, appid);
375 extern "C" API int aul_svc_set_category(bundle* b, const char* category) {
377 _E("Invalid parameter");
378 return AUL_SVC_RET_EINVAL;
381 return ::SetBundle(b, AUL_SVC_K_CATEGORY, category);
384 extern "C" API int aul_svc_set_launch_mode(bundle* b, const char* mode) {
386 _E("Invalid parameter");
387 return AUL_SVC_RET_EINVAL;
390 return ::SetBundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
393 extern "C" API int aul_svc_resolve(bundle* b, uid_t uid, char*** appid_array,
395 return aul_svc_get_appid_array(b, uid, appid_array, len);
398 extern "C" API int aul_svc_run_service(bundle* b, int request_code,
399 aul_svc_res_fn cbfunc, void* data) {
400 return aul_svc_run_service_for_uid(b, request_code, cbfunc, data, getuid());
403 extern "C" API int aul_svc_run_service_for_uid(bundle* b, int request_code,
404 aul_svc_res_fn cbfunc, void* data, uid_t uid) {
405 CbInfo* cb_info = nullptr;
407 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
409 std::tuple<aul_svc_res_fn, void*> param { cbfunc, data };
410 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
411 [](const std::string& appid, bundle* request, uid_t uid,
412 CbInfo* cb_info) -> int {
415 ret = aul_launch_app_with_result_for_uid(appid.c_str(), request,
416 LaunchWithResultCb, cb_info, uid);
418 ret = aul_launch_app_for_uid(appid.c_str(), request, uid);
427 ret = AulErrorConvert(ret);
433 extern "C" API int aul_svc_get_list(bundle* b, aul_svc_info_iter_fn iter_fn,
435 return aul_svc_get_list_for_uid(b, iter_fn, data, getuid());
438 extern "C" API int aul_svc_get_list_for_uid(bundle* b,
439 aul_svc_info_iter_fn iter_fn, void* data, uid_t uid) {
440 if (b == nullptr || iter_fn == nullptr) {
441 _E("Invalid parameter");
442 return AUL_SVC_RET_EINVAL;
445 char** appid_array = nullptr;
446 unsigned int len = 0;
447 int ret = aul_svc_get_appid_array(b, uid, &appid_array, &len);
448 if (ret != AUL_SVC_RET_OK)
452 _E("Failed to find associated application");
453 aul_svc_free_appid_array(appid_array, len);
454 return AUL_SVC_RET_ENOMATCH;
457 for (unsigned int i = 0; i < len; ++i) {
458 SECURE_LOGD("APPID: %s", appid_array[i]);
459 if (iter_fn(appid_array[i], data) != 0)
463 aul_svc_free_appid_array(appid_array, len);
464 return AUL_SVC_RET_OK;
467 extern "C" API int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn,
469 return aul_svc_get_all_defapps_for_uid(iter_fn, data, getuid());
472 extern "C" API int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
473 void* data, uid_t uid) {
474 if (iter_fn == nullptr) {
475 _E("Invalid parameter");
476 return AUL_SVC_RET_EINVAL;
480 tizen_base::Bundle request;
481 int ret = ::SendAndReceive(APP_GET_APP_CONTROL_DEFAULT_APPS, uid,
482 request.GetHandle(), &response);
483 if (ret != AUL_SVC_RET_OK)
486 tizen_base::Bundle res(response, false, true);
487 auto appid_array = res.GetStringArray(AUL_K_APPID_LIST);
488 for (auto& appid : appid_array) {
489 if (iter_fn(appid.c_str(), data) != 0)
493 return AUL_SVC_RET_OK;
496 extern "C" API const char* aul_svc_get_operation(bundle* b) {
497 return bundle_get_val(b, AUL_SVC_K_OPERATION);
500 extern "C" API const char* aul_svc_get_uri(bundle* b) {
501 return bundle_get_val(b, AUL_SVC_K_URI);
504 extern "C" API const char* aul_svc_get_mime(bundle* b) {
505 return bundle_get_val(b, AUL_SVC_K_MIME);
508 extern "C" API const char* aul_svc_get_data(bundle* b, const char* key) {
509 return bundle_get_val(b, key);
512 extern "C" API const char** aul_svc_get_data_array(bundle* b, const char* key,
514 return bundle_get_str_array(b, key, len);
517 extern "C" API const char* aul_svc_get_pkgname(bundle* b) {
518 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
521 extern "C" API const char* aul_svc_get_appid(bundle* b) {
522 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
525 extern "C" API const char* aul_svc_get_category(bundle* b) {
526 return bundle_get_val(b, AUL_SVC_K_CATEGORY);
529 extern "C" API const char* aul_svc_get_launch_mode(bundle* b) {
530 return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
533 extern "C" API int aul_svc_create_result_bundle(bundle* inb, bundle** outb) {
534 if (inb == nullptr || outb == nullptr) {
535 _E("Invalid parameter");
536 return AUL_SVC_RET_EINVAL;
539 int ret = aul_create_result_bundle(inb, outb);
541 return AulErrorConvert(ret);
543 return AUL_SVC_RET_OK;
546 extern "C" API int aul_svc_send_result(bundle* b, aul_svc_result_val result) {
548 _E("Invalid parameter");
549 return AUL_SVC_RET_EINVAL;
552 int ret = ::SetBundle(b, AUL_SVC_K_RES_VAL, std::to_string(result).c_str());
554 return AUL_SVC_RET_ERROR;
556 if (result == AUL_SVC_RES_CANCEL)
557 ret = aul_send_result(b, 1);
559 ret = aul_send_result(b, 0);
561 bundle_del(b, AUL_SVC_K_RES_VAL);
565 extern "C" API int aul_svc_data_is_array(bundle* b, const char* key) {
566 int type = bundle_get_type(b, key);
570 if (type & BUNDLE_TYPE_ARRAY)
576 extern "C" API int aul_svc_allow_transient_app(bundle* b, int wid) {
578 _E("Invalid parameter");
579 return AUL_SVC_RET_EINVAL;
582 return ::SetBundle(b, AUL_SVC_K_WIN_ID, std::to_string(wid).c_str());
585 extern "C" API int aul_svc_request_transient_app(bundle* b, int callee_wid,
586 aul_svc_host_res_fn cbfunc, void* data) {
590 extern "C" API int aul_svc_subapp_terminate_request_pid(int pid) {
593 int* lpids = nullptr;
594 aul_app_group_get_leader_pids(&lcnt, &lpids);
595 for (int i = 0; i < lcnt; ++i) {
596 if (lpids[i] == cpid) {
599 aul_app_group_get_group_pids(cpid, &cnt, &pids);
605 return aul_subapp_terminate_request_pid(pid);
614 if (lpids != nullptr)
617 return aul_app_group_clear_top();
620 extern "C" API int aul_send_service_result(bundle* b) {
621 return aul_send_result(b, 0);
624 extern "C" API int aul_svc_subscribe_launch_result(bundle* b,
625 const char* result) {
627 _E("Invalid parameter");
628 return AUL_SVC_RET_EINVAL;
631 return ::SetBundle(b, result, "1");
634 extern "C" API int aul_svc_set_loader_id(bundle* b, int loader_id) {
635 if (b == nullptr || loader_id <= 0) {
636 _E("Invalid parameter");
637 return AUL_SVC_RET_EINVAL;
640 return ::SetBundle(b, AUL_K_LOADER_ID, std::to_string(loader_id).c_str());
643 extern "C" API int aul_svc_set_loader_name(bundle* b, const char* loader_name) {
644 if (b == nullptr || loader_name == nullptr) {
645 _E("Invalid parameter");
646 return AUL_SVC_RET_EINVAL;
649 return ::SetBundle(b, AUL_K_LOADER_NAME, loader_name);
652 extern "C" API int aul_svc_set_background_launch(bundle* b, int enabled) {
654 _E("Invalid parameter");
655 return AUL_SVC_RET_EINVAL;
658 return ::SetBundle(b, AUL_SVC_K_BG_LAUNCH, enabled ? "enable" : nullptr);
661 extern "C" API int aul_svc_get_appid_by_alias_appid(const char* alias_appid,
663 return aul_svc_get_appid_by_alias_appid_for_uid(alias_appid, appid, getuid());
666 extern "C" API int aul_svc_get_appid_by_alias_appid_for_uid(
667 const char* alias_appid, char** appid, uid_t uid) {
668 if (alias_appid == nullptr || appid == nullptr) {
669 _E("Invalid parameter");
670 return AUL_SVC_RET_EINVAL;
674 tizen_base::Bundle request;
675 request.Add(AUL_K_ALIAS_APPID, alias_appid);
676 int ret = ::SendAndReceive(APP_GET_APPID_BY_ALIAS_APPID, uid,
677 request.GetHandle(), &response);
678 if (ret != AUL_SVC_RET_OK)
681 tizen_base::Bundle res(response, false, true);
682 auto val = res.GetString(AUL_K_APPID);
684 return AUL_SVC_RET_ERROR;
686 *appid = strdup(val.c_str());
687 if (*appid == nullptr) {
689 return AUL_SVC_RET_ENOMEM;
692 return AUL_SVC_RET_OK;
695 extern "C" API const char *aul_svc_get_instance_id(bundle* b) {
696 return bundle_get_val(b, AUL_K_INSTANCE_ID);
699 extern "C" API int aul_svc_set_instance_id(bundle* b, const char* instance_id) {
701 _E("Invalid parameter");
702 return AUL_SVC_RET_EINVAL;
705 return ::SetBundle(b, AUL_K_INSTANCE_ID, instance_id);
708 extern "C" API int aul_svc_run_service_async(bundle* b, int request_code,
709 aul_svc_res_fn cbfunc, void* data) {
710 return aul_svc_run_service_async_for_uid(b, request_code, cbfunc, data,
714 extern "C" API int aul_svc_run_service_async_for_uid(bundle* b,
715 int request_code, aul_svc_res_fn cbfunc, void* data, uid_t uid) {
716 CbInfo* cb_info = nullptr;
718 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
720 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
721 [](const std::string& appid, bundle* request, uid_t uid,
722 CbInfo* info) -> int {
724 return aul_launch_app_with_result_async_for_uid(appid.c_str(),
725 request, LaunchWithResultCb, info, uid);
728 return aul_launch_app_async_for_uid(appid.c_str(), request, uid);
734 ret = AulErrorConvert(ret);
740 extern "C" API int aul_svc_send_launch_request(bundle* b, int request_code,
741 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void* user_data) {
742 return aul_svc_send_launch_request_for_uid(b, request_code,
743 cbfunc, err_cb, user_data, getuid());
746 extern "C" API int aul_svc_send_launch_request_for_uid(bundle* b,
747 int request_code, aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
748 void* user_data, uid_t uid) {
749 if (b == nullptr || err_cb == nullptr) {
750 _E("Invalid parameter");
751 return AUL_SVC_RET_EINVAL;
754 CbInfo* cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, err_cb,
756 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
757 [](const std::string& appid, bundle* request, uid_t uid,
758 CbInfo* info) -> int {
759 return aul_send_launch_request_for_uid(appid.c_str(), request, uid,
760 info->res_fn_ ? ::LaunchWithResultCb : nullptr, ::ErrorCb, info);
764 ret = ::AulErrorConvert(ret);
770 extern "C" API int aul_svc_send_launch_request_sync_for_uid(bundle* b,
771 int request_code, bundle** res_b, aul_svc_result_val* res, uid_t uid) {
772 if (b == nullptr || res_b == nullptr || res == nullptr) {
773 _E("Invalid parameter");
774 return AUL_SVC_RET_EINVAL;
777 int ret = ::SendLaunchRequest<::SendLaunchRequestSyncCb, bundle**>(
778 [](const std::string& appid, bundle* request, uid_t uid,
779 bundle** response) -> int {
780 return aul_send_launch_request_sync_for_uid(appid.c_str(), request,
784 auto* val = bundle_get_val(*res_b, AUL_SVC_K_RES_VAL);
785 *res = static_cast<aul_svc_result_val>(
786 (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val));
788 ret = ::AulErrorConvert(ret);
789 *res = AUL_SVC_RES_CANCEL;
795 extern "C" API int aul_svc_info_create(bundle* b, aul_svc_info_h* h) {
796 if (b == nullptr || h == nullptr) {
797 _E("Invalid parameter");
798 return AUL_SVC_RET_EINVAL;
801 aul::ResolveInfo* resolve_info = nullptr;
803 tizen_base::Bundle kb(b, false, false);
804 resolve_info = aul::ResolveInfo::Manager::Create(kb);
805 } catch (aul::Exception& e) {
806 return AUL_SVC_RET_ERROR;
809 *h = static_cast<aul_svc_info_h>(resolve_info);
810 return AUL_SVC_RET_OK;
813 extern "C" API int aul_svc_info_get_operation(aul_svc_info_h h,
815 if (h == nullptr || operation == nullptr) {
816 _E("Invalid parameter");
817 return AUL_SVC_RET_EINVAL;
820 auto* info = static_cast<aul::ResolveInfo*>(h);
821 auto& value = info->GetOperation();
822 *operation = strdup(value.empty() ? "NULL" : value.c_str());
823 if (*operation == nullptr) {
824 _E("Failed to duplicate operation");
825 return AUL_SVC_RET_ERROR;
828 return AUL_SVC_RET_OK;
831 extern "C" API int aul_svc_info_get_uri(aul_svc_info_h h, char** uri) {
832 if (h == nullptr || uri == nullptr) {
833 _E("Invalid parameter");
834 return AUL_SVC_RET_EINVAL;
837 auto* info = static_cast<aul::ResolveInfo*>(h);
838 auto& value = info->GetUri();
839 *uri = strdup(value.empty() ? "NULL" : value.c_str());
840 if (*uri == nullptr) {
841 _E("Failed to duplicate URI");
842 return AUL_SVC_RET_ERROR;
845 return AUL_SVC_RET_OK;
848 extern "C" API int aul_svc_info_get_uri_scheme(aul_svc_info_h h,
850 if (h == nullptr || uri_scheme == nullptr) {
851 _E("Invalid parameter");
852 return AUL_SVC_RET_EINVAL;
855 auto* info = static_cast<aul::ResolveInfo*>(h);
856 auto& value = info->GetScheme();
857 *uri_scheme = strdup(value.empty() ? "NULL" : value.c_str());
858 if (*uri_scheme == nullptr) {
859 _E("Failed to duplicate URI scheme");
860 return AUL_SVC_RET_ERROR;
863 return AUL_SVC_RET_OK;
866 extern "C" API int aul_svc_info_get_uri_host(aul_svc_info_h h,
868 if (h == nullptr || uri_host == nullptr) {
869 _E("Invalid parameter");
870 return AUL_SVC_RET_EINVAL;
873 auto* info = static_cast<aul::ResolveInfo*>(h);
874 auto& value = info->GetHost();
875 *uri_host = strdup(value.empty() ? "NULL" : value.c_str());
876 if (*uri_host == nullptr) {
877 _E("Failed to duplicate URI host");
878 return AUL_SVC_RET_ERROR;
881 return AUL_SVC_RET_OK;
884 extern "C" API int aul_svc_info_get_mime(aul_svc_info_h h, char** mime) {
885 if (h == nullptr || mime == nullptr) {
886 _E("Invalid parameter");
887 return AUL_SVC_RET_EINVAL;
890 auto* info = static_cast<aul::ResolveInfo*>(h);
891 auto& value = info->GetMime();
892 *mime = strdup(value.empty() ? "NULL" : value.c_str());
893 if (*mime == nullptr) {
894 _E("Failed to duplicate MIME-Type");
895 return AUL_SVC_RET_ERROR;
898 return AUL_SVC_RET_OK;
901 extern "C" API int aul_svc_info_get_mime_type(aul_svc_info_h h,
903 if (h == nullptr || mime_type == nullptr) {
904 _E("Invalid parameter");
905 return AUL_SVC_RET_EINVAL;
908 auto* info = static_cast<aul::ResolveInfo*>(h);
909 auto& value = info->GetMType();
910 *mime_type = strdup(value.empty() ? "NULL" : value.c_str());
911 if (*mime_type == nullptr) {
912 _E("Failed to duplicate the type of MIME-Type");
913 return AUL_SVC_RET_ERROR;
916 return AUL_SVC_RET_OK;
919 extern "C" API int aul_svc_info_get_mime_subtype(aul_svc_info_h h,
920 char** mime_subtype) {
921 if (h == nullptr || mime_subtype == nullptr) {
922 _E("Invalid parameter");
923 return AUL_SVC_RET_EINVAL;
926 auto* info = static_cast<aul::ResolveInfo*>(h);
927 auto& value = info->GetSType();
928 *mime_subtype = strdup(value.empty() ? "NULL" : value.c_str());
929 if (*mime_subtype == nullptr) {
930 _E("Failed to duplicate the subtype of MIME-Type");
931 return AUL_SVC_RET_ERROR;
934 return AUL_SVC_RET_OK;
937 extern "C" API int aul_svc_info_destroy(aul_svc_info_h h) {
939 _E("Invalid parameter");
940 return AUL_SVC_RET_EINVAL;
943 auto* info = static_cast<aul::ResolveInfo*>(h);
945 return AUL_SVC_RET_OK;
948 extern "C" API int aul_svc_set_caller_instance_id(bundle* b,
949 const char* instance_id) {
951 _E("Invalid parameter");
952 return AUL_SVC_RET_EINVAL;
955 return ::SetBundle(b, AUL_K_CALLER_INSTANCE_ID, instance_id);
958 extern "C" API int aul_svc_set_comp_id(bundle* b, const char* comp_id) {
960 _E("Invalid parameter");
961 return AUL_SVC_RET_EINVAL;
964 return ::SetBundle(b, AUL_K_COMPONENT_ID, comp_id);
967 extern "C" API const char *aul_svc_get_comp_id(bundle* b) {
968 return bundle_get_val(b, AUL_K_COMPONENT_ID);
971 extern "C" API int aul_svc_subapp_terminate_request(bundle* b, int pid) {
972 if (b == nullptr || pid < 0) {
973 _E("Invalid parameter");
974 return AUL_SVC_RET_EINVAL;
977 const char* inst_id = bundle_get_val(b, AUL_K_INSTANCE_ID);
978 if (inst_id == nullptr) {
979 _E("Invalid parameter");
980 return AUL_SVC_RET_EINVAL;
983 char buf[512] = { 0, };
984 const char* caller_inst_id = bundle_get_val(b, AUL_K_CALLER_INSTANCE_ID);
985 if (caller_inst_id == nullptr) {
986 int ret = aul_app_get_instance_id_bypid(getpid(), buf, sizeof(buf));
987 if (ret != AUL_R_OK) {
988 _E("aul_app_get_instance_id_bypid() is failed. error(%d)", ret);
989 return AUL_SVC_RET_ERROR;
992 caller_inst_id = buf;
996 aul_app_group_foreach_group_info(caller_inst_id,
997 [](aul_app_group_info_h info, void* data) {
998 int* count = static_cast<int*>(data);
1000 }, static_cast<void*>(&cnt));
1002 return aul_subapp_terminate_request(inst_id, pid);
1004 return aul_app_group_clear_top();
1007 extern "C" API int aul_svc_send_resume_request(bundle* b, int request_code,
1008 aul_svc_err_cb err_cb, void *user_data) {
1009 return aul_svc_send_resume_request_for_uid(b, request_code, err_cb, user_data,
1013 extern "C" API int aul_svc_send_resume_request_for_uid(bundle* b,
1014 int request_code, aul_svc_err_cb err_cb, void* user_data, uid_t uid) {
1015 if (b == nullptr || err_cb == nullptr) {
1016 _E("Invalid parameter");
1017 return AUL_SVC_RET_EINVAL;
1020 auto* cb_info = new (std::nothrow) CbInfo(request_code, nullptr, err_cb,
1022 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
1023 [](const std::string& appid, bundle* request, uid_t uid,
1024 CbInfo* info) -> int {
1025 return aul_send_resume_request_for_uid(appid.c_str(), request, uid,
1027 }, b, uid, cb_info);
1030 ret = ::AulErrorConvert(ret);
1036 extern "C" API int aul_svc_get_appid_array(bundle* b, uid_t uid,
1037 char*** appid_array, unsigned int* len) {
1038 if (b == nullptr || appid_array == nullptr || len == nullptr) {
1039 _E("Invalid parameter");
1040 return AUL_SVC_RET_EINVAL;
1043 bundle_del(b, AUL_K_APPID);
1044 bundle_add(b, AUL_K_APPID, "@UNKNOWN");
1047 int ret = ::SendAndReceive(APP_GET_APPID_LIST, uid, b, &response);
1048 if (ret != AUL_SVC_RET_OK)
1051 tizen_base::Bundle res(response, false, true);
1052 auto str = res.GetString(AUL_SVC_K_URI_R_INFO);
1054 ::SetBundle(b, AUL_SVC_K_URI_R_INFO, str.c_str());
1056 auto str_arr = res.GetStringArray(AUL_K_APPID_LIST);
1057 if (str_arr.empty()) {
1058 _E("Failed to get appid list");
1059 return AUL_SVC_RET_ERROR;
1062 *appid_array = reinterpret_cast<char**>(
1063 calloc(str_arr.size(), sizeof(char*)));
1064 if (*appid_array == nullptr) {
1065 _E("Out of memory");
1066 return AUL_SVC_RET_ENOMEM;
1069 *len = str_arr.size();
1072 for (auto& appid : str_arr)
1073 (*appid_array)[i++] = strdup(appid.c_str());
1075 return AUL_SVC_RET_OK;
1078 extern "C" API void aul_svc_free_appid_array(char** appid_array,
1080 if (appid_array == nullptr)
1083 for (unsigned int i = 0; i < len; ++i)
1084 free(appid_array[i]);
1089 extern "C" API int aul_svc_set_defapp(const char* op, const char* mime_type,
1090 const char* uri, const char* defapp) {
1091 DEPRECATION_WARNING();
1092 return AUL_SVC_RET_OK;
1095 extern "C" API int aul_svc_set_defapp_for_uid(const char* op,
1096 const char* mime_type, const char* uri, const char* defapp, uid_t uid) {
1097 DEPRECATION_WARNING();
1098 return AUL_SVC_RET_OK;
1101 extern "C" API int aul_svc_unset_defapp(const char* defapp) {
1102 DEPRECATION_WARNING();
1103 return AUL_SVC_RET_OK;
1106 extern "C" API int aul_svc_unset_defapp_for_uid(const char* defapp, uid_t uid) {
1107 DEPRECATION_WARNING();
1108 return AUL_SVC_RET_OK;
1111 extern "C" API int aul_svc_unset_all_defapps(void) {
1112 DEPRECATION_WARNING();
1113 return AUL_SVC_RET_OK;
1116 extern "C" API int aul_svc_unset_all_defapps_for_uid(uid_t uid) {
1117 DEPRECATION_WARNING();
1118 return AUL_SVC_RET_OK;
1121 extern "C" API int aul_svc_is_defapp(const char* pkg_name) {
1122 DEPRECATION_WARNING();
1123 return AUL_SVC_RET_OK;
1126 extern "C" API int aul_svc_is_defapp_for_uid(const char* pkg_name, uid_t uid) {
1127 DEPRECATION_WARNING();
1128 return AUL_SVC_RET_OK;
1131 extern "C" API int aul_svc_set_alias_appid(const char* alias_appid,
1132 const char* appid) {
1133 DEPRECATION_WARNING();
1134 return AUL_SVC_RET_OK;
1137 extern "C" API int aul_svc_set_alias_appid_for_uid(const char* alias_appid,
1138 const char* appid, uid_t uid) {
1139 DEPRECATION_WARNING();
1140 return AUL_SVC_RET_OK;
1143 extern "C" API int aul_svc_unset_alias_appid(const char* alias_appid) {
1144 DEPRECATION_WARNING();
1145 return AUL_SVC_RET_OK;
1148 extern "C" API int aul_svc_unset_alias_appid_for_uid(const char* alias_appid,
1150 DEPRECATION_WARNING();
1151 return AUL_SVC_RET_OK;
1154 extern "C" API int aul_svc_foreach_alias_info(
1155 void (*callback)(const char *, const char *, void *),
1157 DEPRECATION_WARNING();
1158 return AUL_SVC_RET_OK;
1161 extern "C" API int aul_svc_foreach_alias_info_for_uid(
1162 void (*callback)(const char *, const char *, void *),
1163 uid_t uid, void* user_data) {
1164 DEPRECATION_WARNING();
1165 return AUL_SVC_RET_OK;
1168 extern "C" API int aul_svc_enable_alias_info(const char* appid) {
1169 DEPRECATION_WARNING();
1170 return AUL_SVC_RET_OK;
1173 extern "C" API int aul_svc_enable_alias_info_for_uid(const char* appid,
1175 DEPRECATION_WARNING();
1176 return AUL_SVC_RET_OK;
1179 extern "C" API int aul_svc_disable_alias_info(const char* appid) {
1180 DEPRECATION_WARNING();
1181 return AUL_SVC_RET_OK;
1184 extern "C" API int aul_svc_disable_alias_info_for_uid(const char* appid,
1186 DEPRECATION_WARNING();
1187 return AUL_SVC_RET_OK;
1190 extern "C" API int aul_svc_foreach_alias_info_by_appid(
1191 int (*callback)(const char *, const char *, void *),
1192 const char* appid, void* user_data) {
1193 DEPRECATION_WARNING();
1194 return AUL_SVC_RET_OK;
1197 extern "C" API int aul_svc_foreach_alias_info_by_appid_for_uid(
1198 int (*callback)(const char *, const char *, void *),
1199 const char* appid, uid_t uid, void* user_data) {
1200 DEPRECATION_WARNING();
1201 return AUL_SVC_RET_OK;
1204 extern "C" API int aul_svc_foreach_allowed_info(
1205 int (*callback)(const char *, const char *, void *),
1207 DEPRECATION_WARNING();
1208 return AUL_SVC_RET_OK;
1211 extern "C" API int aul_svc_foreach_allowed_info_for_uid(
1212 int (*callback)(const char *, const char *, void *),
1213 uid_t uid, void* user_data) {
1214 DEPRECATION_WARNING();
1215 return AUL_SVC_RET_OK;
1218 extern "C" API int aul_svc_foreach_allowed_info_by_appid(
1219 int (*callback)(const char *, const char *, void *),
1220 const char* appid, void* user_data) {
1221 DEPRECATION_WARNING();
1222 return AUL_SVC_RET_OK;
1225 extern "C" API int aul_svc_foreach_allowed_info_by_appid_for_uid(
1226 int (*callback)(const char *, const char *, void *),
1227 const char* appid, uid_t uid, void* user_data) {
1228 DEPRECATION_WARNING();
1229 return AUL_SVC_RET_OK;