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;
205 return AUL_SVC_RET_ELAUNCH;
209 void LaunchWithResultCb(bundle* b, int is_cancel, void* data) {
212 res = AUL_SVC_RES_CANCEL;
214 const char* val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
215 res = (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val);
218 bundle_del(b, AUL_SVC_K_RES_VAL);
219 auto* cb_info = static_cast<CbInfo*>(data);
220 if (cb_info->res_fn_) {
221 cb_info->res_fn_(b, cb_info->request_code_,
222 static_cast<aul_svc_result_val>(res), cb_info->user_data_);
225 if (cb_info->err_cb_ != nullptr)
231 void ErrorCb(int error, void* data) {
233 error = AulErrorConvert(error);
235 auto* cb_info = static_cast<CbInfo*>(data);
236 if (cb_info->err_cb_) {
237 cb_info->err_cb_(cb_info->request_code_, error, cb_info->user_data_);
238 cb_info->err_cb_ = nullptr;
241 if (cb_info->res_fn_)
247 using SendLaunchRequestCb =
248 int (*)(const std::string&, bundle*, uid_t, CbInfo*);
249 using SendLaunchRequestSyncCb =
250 int (*)(const std::string&, bundle*, uid_t, bundle**);
252 template <typename T, typename A>
253 int SendLaunchRequest(T cb, bundle* request, uid_t uid, A arg) {
254 if (request == nullptr) {
255 _E("Invalid parameter");
256 return AUL_SVC_RET_EINVAL;
259 std::string appid = GetAppId(request);
261 _E("GetAppId() is failed");
262 return AUL_SVC_RET_EINVAL;
265 SetLaunchData(request, appid);
266 return cb(appid, request, uid, arg);
269 int SendAndReceive(int cmd, uid_t uid, bundle* request, bundle** response) {
270 int fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, cmd, request,
273 return AUL_SVC_RET_ERROR;
275 app_pkt_t* pkt = nullptr;
276 int ret = aul_sock_recv_reply_pkt(fd, &pkt);
278 _E("Failed to receive reply packet. error(%d)", ret);
279 return AUL_SVC_RET_ERROR;
282 auto ptr = std::unique_ptr<app_pkt_t, decltype(std::free)*>(pkt, std::free);
283 if (pkt->cmd != APP_GET_INFO_OK && pkt->cmd != cmd)
284 return AUL_SVC_RET_ERROR;
287 if (pkt->opt & AUL_SOCK_BUNDLE) {
288 b = bundle_decode(pkt->data, pkt->len);
290 _E("bundle_decode() is failed");
291 return AUL_SVC_RET_ENOMEM;
294 _E("Invalid packet");
295 return AUL_SVC_RET_ERROR;
299 return AUL_SVC_RET_OK;
304 extern "C" API int aul_svc_set_operation(bundle* b, const char* operation) {
306 _E("Invalid parameter");
307 return AUL_SVC_RET_EINVAL;
310 return ::SetBundle(b, AUL_SVC_K_OPERATION, operation);
313 extern "C" API int aul_svc_set_uri(bundle* b, const char* uri) {
315 _E("Invalid parameter");
316 return AUL_SVC_RET_EINVAL;
319 return ::SetBundle(b, AUL_SVC_K_URI, uri);
322 extern "C" API int aul_svc_set_mime(bundle* b, const char* mime) {
324 _E("Invalid parameter");
325 return AUL_SVC_RET_EINVAL;
328 return ::SetBundle(b, AUL_SVC_K_MIME, mime);
331 extern "C" API int aul_svc_add_data(bundle* b, const char* key,
333 if (b == nullptr || key == nullptr)
334 return AUL_SVC_RET_EINVAL;
336 return ::SetBundle(b, key, value);
339 extern "C" API int aul_svc_add_data_array(bundle* b, const char* key,
340 const char** value, int len) {
341 if (b == nullptr || key == nullptr)
342 return AUL_SVC_RET_EINVAL;
344 return ::SetBundleArray(b, key, value, len);
347 extern "C" API int aul_svc_set_pkgname(bundle* b, const char* pkg_name) {
349 _E("Invalid parameter");
350 return AUL_SVC_RET_EINVAL;
353 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
356 extern "C" API int aul_svc_set_appid(bundle* b, const char* appid) {
357 if (b == nullptr || appid == nullptr) {
358 _E("Invalid parameter");
359 return AUL_SVC_RET_EINVAL;
362 std::string alias_id = ::GetAliasAppId(appid);
363 if (!alias_id.empty())
364 appid = alias_id.c_str();
366 return ::SetBundle(b, AUL_SVC_K_PKG_NAME, appid);
369 extern "C" API int aul_svc_set_category(bundle* b, const char* category) {
371 _E("Invalid parameter");
372 return AUL_SVC_RET_EINVAL;
375 return ::SetBundle(b, AUL_SVC_K_CATEGORY, category);
378 extern "C" API int aul_svc_set_launch_mode(bundle* b, const char* mode) {
380 _E("Invalid parameter");
381 return AUL_SVC_RET_EINVAL;
384 return ::SetBundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
387 extern "C" API int aul_svc_resolve(bundle* b, uid_t uid, char*** appid_array,
389 return aul_svc_get_appid_array(b, uid, appid_array, len);
392 extern "C" API int aul_svc_run_service(bundle* b, int request_code,
393 aul_svc_res_fn cbfunc, void* data) {
394 return aul_svc_run_service_for_uid(b, request_code, cbfunc, data, getuid());
397 extern "C" API int aul_svc_run_service_for_uid(bundle* b, int request_code,
398 aul_svc_res_fn cbfunc, void* data, uid_t uid) {
399 CbInfo* cb_info = nullptr;
401 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
403 std::tuple<aul_svc_res_fn, void*> param { cbfunc, data };
404 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
405 [](const std::string& appid, bundle* request, uid_t uid,
406 CbInfo* cb_info) -> int {
409 ret = aul_launch_app_with_result_for_uid(appid.c_str(), request,
410 LaunchWithResultCb, cb_info, uid);
412 ret = aul_launch_app_for_uid(appid.c_str(), request, uid);
421 ret = AulErrorConvert(ret);
427 extern "C" API int aul_svc_get_list(bundle* b, aul_svc_info_iter_fn iter_fn,
429 return aul_svc_get_list_for_uid(b, iter_fn, data, getuid());
432 extern "C" API int aul_svc_get_list_for_uid(bundle* b,
433 aul_svc_info_iter_fn iter_fn, void* data, uid_t uid) {
434 if (b == nullptr || iter_fn == nullptr) {
435 _E("Invalid parameter");
436 return AUL_SVC_RET_EINVAL;
439 char** appid_array = nullptr;
440 unsigned int len = 0;
441 int ret = aul_svc_get_appid_array(b, uid, &appid_array, &len);
442 if (ret != AUL_SVC_RET_OK)
446 _E("Failed to find associated application");
447 aul_svc_free_appid_array(appid_array, len);
448 return AUL_SVC_RET_ENOMATCH;
451 for (unsigned int i = 0; i < len; ++i) {
452 SECURE_LOGD("APPID: %s", appid_array[i]);
453 if (iter_fn(appid_array[i], data) != 0)
457 aul_svc_free_appid_array(appid_array, len);
458 return AUL_SVC_RET_OK;
461 extern "C" API int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn,
463 return aul_svc_get_all_defapps_for_uid(iter_fn, data, getuid());
466 extern "C" API int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
467 void* data, uid_t uid) {
468 if (iter_fn == nullptr) {
469 _E("Invalid parameter");
470 return AUL_SVC_RET_EINVAL;
474 tizen_base::Bundle request;
475 int ret = ::SendAndReceive(APP_GET_APP_CONTROL_DEFAULT_APPS, uid,
476 request.GetHandle(), &response);
477 if (ret != AUL_SVC_RET_OK)
480 tizen_base::Bundle res(response, false, true);
481 auto appid_array = res.GetStringArray(AUL_K_APPID_LIST);
482 if (appid_array.size() == 0)
483 return AUL_SVC_RET_ERROR;
485 for (auto& appid : appid_array) {
486 if (iter_fn(appid.c_str(), data) != 0)
490 return AUL_SVC_RET_OK;
493 extern "C" API const char* aul_svc_get_operation(bundle* b) {
494 return bundle_get_val(b, AUL_SVC_K_OPERATION);
497 extern "C" API const char* aul_svc_get_uri(bundle* b) {
498 return bundle_get_val(b, AUL_SVC_K_URI);
501 extern "C" API const char* aul_svc_get_mime(bundle* b) {
502 return bundle_get_val(b, AUL_SVC_K_MIME);
505 extern "C" API const char* aul_svc_get_data(bundle* b, const char* key) {
506 return bundle_get_val(b, key);
509 extern "C" API const char** aul_svc_get_data_array(bundle* b, const char* key,
511 return bundle_get_str_array(b, key, len);
514 extern "C" API const char* aul_svc_get_pkgname(bundle* b) {
515 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
518 extern "C" API const char* aul_svc_get_appid(bundle* b) {
519 return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
522 extern "C" API const char* aul_svc_get_category(bundle* b) {
523 return bundle_get_val(b, AUL_SVC_K_CATEGORY);
526 extern "C" API const char* aul_svc_get_launch_mode(bundle* b) {
527 return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
530 extern "C" API int aul_svc_create_result_bundle(bundle* inb, bundle** outb) {
531 if (inb == nullptr || outb == nullptr) {
532 _E("Invalid parameter");
533 return AUL_SVC_RET_EINVAL;
536 int ret = aul_create_result_bundle(inb, outb);
538 return AulErrorConvert(ret);
540 return AUL_SVC_RET_OK;
543 extern "C" API int aul_svc_send_result(bundle* b, aul_svc_result_val result) {
545 _E("Invalid parameter");
546 return AUL_SVC_RET_EINVAL;
549 int ret = ::SetBundle(b, AUL_SVC_K_RES_VAL, std::to_string(result).c_str());
551 return AUL_SVC_RET_ERROR;
553 if (result == AUL_SVC_RES_CANCEL)
554 ret = aul_send_result(b, 1);
556 ret = aul_send_result(b, 0);
558 bundle_del(b, AUL_SVC_K_RES_VAL);
562 extern "C" API int aul_svc_data_is_array(bundle* b, const char* key) {
563 int type = bundle_get_type(b, key);
567 if (type & BUNDLE_TYPE_ARRAY)
573 extern "C" API int aul_svc_allow_transient_app(bundle* b, int wid) {
575 _E("Invalid parameter");
576 return AUL_SVC_RET_EINVAL;
579 return ::SetBundle(b, AUL_SVC_K_WIN_ID, std::to_string(wid).c_str());
582 extern "C" API int aul_svc_request_transient_app(bundle* b, int callee_wid,
583 aul_svc_host_res_fn cbfunc, void* data) {
587 extern "C" API int aul_svc_subapp_terminate_request_pid(int pid) {
590 int* lpids = nullptr;
591 aul_app_group_get_leader_pids(&lcnt, &lpids);
592 for (int i = 0; i < lcnt; ++i) {
593 if (lpids[i] == cpid) {
596 aul_app_group_get_group_pids(cpid, &cnt, &pids);
602 return aul_subapp_terminate_request_pid(pid);
611 if (lpids != nullptr)
614 return aul_app_group_clear_top();
617 extern "C" API int aul_send_service_result(bundle* b) {
618 return aul_send_result(b, 0);
621 extern "C" API int aul_svc_subscribe_launch_result(bundle* b,
622 const char* result) {
624 _E("Invalid parameter");
625 return AUL_SVC_RET_EINVAL;
628 return ::SetBundle(b, result, "1");
631 extern "C" API int aul_svc_set_loader_id(bundle* b, int loader_id) {
632 if (b == nullptr || loader_id <= 0) {
633 _E("Invalid parameter");
634 return AUL_SVC_RET_EINVAL;
637 return ::SetBundle(b, AUL_K_LOADER_ID, std::to_string(loader_id).c_str());
640 extern "C" API int aul_svc_set_loader_name(bundle* b, const char* loader_name) {
641 if (b == nullptr || loader_name == nullptr) {
642 _E("Invalid parameter");
643 return AUL_SVC_RET_EINVAL;
646 return ::SetBundle(b, AUL_K_LOADER_NAME, loader_name);
649 extern "C" API int aul_svc_set_background_launch(bundle* b, int enabled) {
651 _E("Invalid parameter");
652 return AUL_SVC_RET_EINVAL;
655 return ::SetBundle(b, AUL_SVC_K_BG_LAUNCH, enabled ? "enable" : nullptr);
658 extern "C" API int aul_svc_get_appid_by_alias_appid(const char* alias_appid,
660 return aul_svc_get_appid_by_alias_appid_for_uid(alias_appid, appid, getuid());
663 extern "C" API int aul_svc_get_appid_by_alias_appid_for_uid(
664 const char* alias_appid, char** appid, uid_t uid) {
665 if (alias_appid == nullptr || appid == nullptr) {
666 _E("Invalid parameter");
667 return AUL_SVC_RET_EINVAL;
671 tizen_base::Bundle request;
672 request.Add(AUL_K_ALIAS_APPID, alias_appid);
673 int ret = ::SendAndReceive(APP_GET_APPID_BY_ALIAS_APPID, uid,
674 request.GetHandle(), &response);
675 if (ret != AUL_SVC_RET_OK)
678 tizen_base::Bundle res(response, false, true);
679 auto val = res.GetString(AUL_K_APPID);
681 return AUL_SVC_RET_ERROR;
683 *appid = strdup(val.c_str());
684 if (*appid == nullptr) {
686 return AUL_SVC_RET_ENOMEM;
689 return AUL_SVC_RET_OK;
692 extern "C" API const char *aul_svc_get_instance_id(bundle* b) {
693 return bundle_get_val(b, AUL_K_INSTANCE_ID);
696 extern "C" API int aul_svc_set_instance_id(bundle* b, const char* instance_id) {
697 if (b == nullptr || instance_id == nullptr) {
698 _E("Invalid parameter");
699 return AUL_SVC_RET_EINVAL;
702 return ::SetBundle(b, AUL_K_INSTANCE_ID, instance_id);
705 extern "C" API int aul_svc_run_service_async(bundle* b, int request_code,
706 aul_svc_res_fn cbfunc, void* data) {
707 return aul_svc_run_service_async_for_uid(b, request_code, cbfunc, data,
711 extern "C" API int aul_svc_run_service_async_for_uid(bundle* b,
712 int request_code, aul_svc_res_fn cbfunc, void* data, uid_t uid) {
713 CbInfo* cb_info = nullptr;
715 cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
717 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
718 [](const std::string& appid, bundle* request, uid_t uid,
719 CbInfo* info) -> int {
721 return aul_launch_app_with_result_async_for_uid(appid.c_str(),
722 request, LaunchWithResultCb, info, uid);
725 return aul_launch_app_async_for_uid(appid.c_str(), request, uid);
731 ret = AulErrorConvert(ret);
737 extern "C" API int aul_svc_send_launch_request(bundle* b, int request_code,
738 aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void* user_data) {
739 return aul_svc_send_launch_request_for_uid(b, request_code,
740 cbfunc, err_cb, user_data, getuid());
743 extern "C" API int aul_svc_send_launch_request_for_uid(bundle* b,
744 int request_code, aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
745 void* user_data, uid_t uid) {
746 if (b == nullptr || err_cb == nullptr) {
747 _E("Invalid parameter");
748 return AUL_SVC_RET_EINVAL;
751 CbInfo* cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, err_cb,
753 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
754 [](const std::string& appid, bundle* request, uid_t uid,
755 CbInfo* info) -> int {
756 return aul_send_launch_request_for_uid(appid.c_str(), request, uid,
757 info->res_fn_ ? ::LaunchWithResultCb : nullptr, ::ErrorCb, info);
761 ret = ::AulErrorConvert(ret);
767 extern "C" API int aul_svc_send_launch_request_sync_for_uid(bundle* b,
768 int request_code, bundle** res_b, aul_svc_result_val* res, uid_t uid) {
769 if (b == nullptr || res_b == nullptr || res == nullptr) {
770 _E("Invalid parameter");
771 return AUL_SVC_RET_EINVAL;
774 int ret = ::SendLaunchRequest<::SendLaunchRequestSyncCb, bundle**>(
775 [](const std::string& appid, bundle* request, uid_t uid,
776 bundle** response) -> int {
777 return aul_send_launch_request_sync_for_uid(appid.c_str(), request,
781 auto* val = bundle_get_val(*res_b, AUL_SVC_K_RES_VAL);
782 *res = static_cast<aul_svc_result_val>(
783 (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val));
785 ret = ::AulErrorConvert(ret);
786 *res = AUL_SVC_RES_CANCEL;
792 extern "C" API int aul_svc_info_create(bundle* b, aul_svc_info_h* h) {
793 if (b == nullptr || h == nullptr) {
794 _E("Invalid parameter");
795 return AUL_SVC_RET_EINVAL;
798 aul::ResolveInfo* resolve_info = nullptr;
800 tizen_base::Bundle kb(b, false, false);
801 resolve_info = aul::ResolveInfo::Manager::Create(kb);
802 } catch (aul::Exception& e) {
803 return AUL_SVC_RET_ERROR;
806 *h = static_cast<aul_svc_info_h>(resolve_info);
807 return AUL_SVC_RET_OK;
810 extern "C" API int aul_svc_info_get_operation(aul_svc_info_h h,
812 if (h == nullptr || operation == nullptr) {
813 _E("Invalid parameter");
814 return AUL_SVC_RET_EINVAL;
817 auto* info = static_cast<aul::ResolveInfo*>(h);
818 auto& value = info->GetOperation();
819 *operation = strdup(value.empty() ? "NULL" : value.c_str());
820 if (*operation == nullptr) {
821 _E("Failed to duplicate operation");
822 return AUL_SVC_RET_ERROR;
825 return AUL_SVC_RET_OK;
828 extern "C" API int aul_svc_info_get_uri(aul_svc_info_h h, char** uri) {
829 if (h == nullptr || uri == nullptr) {
830 _E("Invalid parameter");
831 return AUL_SVC_RET_EINVAL;
834 auto* info = static_cast<aul::ResolveInfo*>(h);
835 auto& value = info->GetUri();
836 *uri = strdup(value.empty() ? "NULL" : value.c_str());
837 if (*uri == nullptr) {
838 _E("Failed to duplicate URI");
839 return AUL_SVC_RET_ERROR;
842 return AUL_SVC_RET_OK;
845 extern "C" API int aul_svc_info_get_uri_scheme(aul_svc_info_h h,
847 if (h == nullptr || uri_scheme == nullptr) {
848 _E("Invalid parameter");
849 return AUL_SVC_RET_EINVAL;
852 auto* info = static_cast<aul::ResolveInfo*>(h);
853 auto& value = info->GetScheme();
854 *uri_scheme = strdup(value.empty() ? "NULL" : value.c_str());
855 if (*uri_scheme == nullptr) {
856 _E("Failed to duplicate URI scheme");
857 return AUL_SVC_RET_ERROR;
860 return AUL_SVC_RET_OK;
863 extern "C" API int aul_svc_info_get_uri_host(aul_svc_info_h h,
865 if (h == nullptr || uri_host == nullptr) {
866 _E("Invalid parameter");
867 return AUL_SVC_RET_EINVAL;
870 auto* info = static_cast<aul::ResolveInfo*>(h);
871 auto& value = info->GetHost();
872 *uri_host = strdup(value.empty() ? "NULL" : value.c_str());
873 if (*uri_host == nullptr) {
874 _E("Failed to duplicate URI host");
875 return AUL_SVC_RET_ERROR;
878 return AUL_SVC_RET_OK;
881 extern "C" API int aul_svc_info_get_mime(aul_svc_info_h h, char** mime) {
882 if (h == nullptr || mime == nullptr) {
883 _E("Invalid parameter");
884 return AUL_SVC_RET_EINVAL;
887 auto* info = static_cast<aul::ResolveInfo*>(h);
888 auto& value = info->GetMime();
889 *mime = strdup(value.empty() ? "NULL" : value.c_str());
890 if (*mime == nullptr) {
891 _E("Failed to duplicate MIME-Type");
892 return AUL_SVC_RET_ERROR;
895 return AUL_SVC_RET_OK;
898 extern "C" API int aul_svc_info_get_mime_type(aul_svc_info_h h,
900 if (h == nullptr || mime_type == nullptr) {
901 _E("Invalid parameter");
902 return AUL_SVC_RET_EINVAL;
905 auto* info = static_cast<aul::ResolveInfo*>(h);
906 auto& value = info->GetMType();
907 *mime_type = strdup(value.empty() ? "NULL" : value.c_str());
908 if (*mime_type == nullptr) {
909 _E("Failed to duplicate the type of MIME-Type");
910 return AUL_SVC_RET_ERROR;
913 return AUL_SVC_RET_OK;
916 extern "C" API int aul_svc_info_get_mime_subtype(aul_svc_info_h h,
917 char** mime_subtype) {
918 if (h == nullptr || mime_subtype == nullptr) {
919 _E("Invalid parameter");
920 return AUL_SVC_RET_EINVAL;
923 auto* info = static_cast<aul::ResolveInfo*>(h);
924 auto& value = info->GetSType();
925 *mime_subtype = strdup(value.empty() ? "NULL" : value.c_str());
926 if (*mime_subtype == nullptr) {
927 _E("Failed to duplicate the subtype of MIME-Type");
928 return AUL_SVC_RET_ERROR;
931 return AUL_SVC_RET_OK;
934 extern "C" API int aul_svc_info_destroy(aul_svc_info_h h) {
936 _E("Invalid parameter");
937 return AUL_SVC_RET_EINVAL;
940 auto* info = static_cast<aul::ResolveInfo*>(h);
942 return AUL_SVC_RET_OK;
945 extern "C" API int aul_svc_set_caller_instance_id(bundle* b,
946 const char* instance_id) {
948 _E("Invalid parameter");
949 return AUL_SVC_RET_EINVAL;
952 return ::SetBundle(b, AUL_K_CALLER_INSTANCE_ID, instance_id);
955 extern "C" API int aul_svc_set_comp_id(bundle* b, const char* comp_id) {
957 _E("Invalid parameter");
958 return AUL_SVC_RET_EINVAL;
961 return ::SetBundle(b, AUL_K_COMPONENT_ID, comp_id);
964 extern "C" API const char *aul_svc_get_comp_id(bundle* b) {
965 return bundle_get_val(b, AUL_K_COMPONENT_ID);
968 extern "C" API int aul_svc_subapp_terminate_request(bundle* b, int pid) {
969 if (b == nullptr || pid < 0) {
970 _E("Invalid parameter");
971 return AUL_SVC_RET_EINVAL;
974 const char* inst_id = bundle_get_val(b, AUL_K_INSTANCE_ID);
975 if (inst_id == nullptr) {
976 _E("Invalid parameter");
977 return AUL_SVC_RET_EINVAL;
980 char buf[512] = { 0, };
981 const char* caller_inst_id = bundle_get_val(b, AUL_K_CALLER_INSTANCE_ID);
982 if (caller_inst_id == nullptr) {
983 int ret = aul_app_get_instance_id_bypid(getpid(), buf, sizeof(buf));
984 if (ret != AUL_R_OK) {
985 _E("aul_app_get_instance_id_bypid() is failed. error(%d)", ret);
986 return AUL_SVC_RET_ERROR;
989 caller_inst_id = buf;
993 aul_app_group_foreach_group_info(caller_inst_id,
994 [](aul_app_group_info_h info, void* data) {
995 int* count = static_cast<int*>(data);
997 }, static_cast<void*>(&cnt));
999 return aul_subapp_terminate_request(inst_id, pid);
1001 return aul_app_group_clear_top();
1004 extern "C" API int aul_svc_send_resume_request(bundle* b, int request_code,
1005 aul_svc_err_cb err_cb, void *user_data) {
1006 return aul_svc_send_resume_request_for_uid(b, request_code, err_cb, user_data,
1010 extern "C" API int aul_svc_send_resume_request_for_uid(bundle* b,
1011 int request_code, aul_svc_err_cb err_cb, void* user_data, uid_t uid) {
1012 if (b == nullptr || err_cb == nullptr) {
1013 _E("Invalid parameter");
1014 return AUL_SVC_RET_EINVAL;
1017 auto* cb_info = new (std::nothrow) CbInfo(request_code, nullptr, err_cb,
1019 int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
1020 [](const std::string& appid, bundle* request, uid_t uid,
1021 CbInfo* info) -> int {
1022 return aul_send_resume_request_for_uid(appid.c_str(), request, uid,
1024 }, b, uid, cb_info);
1027 ret = ::AulErrorConvert(ret);
1033 extern "C" API int aul_svc_get_appid_array(bundle* b, uid_t uid,
1034 char*** appid_array, unsigned int* len) {
1035 if (b == nullptr || appid_array == nullptr || len == nullptr) {
1036 _E("Invalid parameter");
1037 return AUL_SVC_RET_EINVAL;
1040 bundle_del(b, AUL_K_APPID);
1041 bundle_add(b, AUL_K_APPID, "@UNKNOWN");
1044 int ret = ::SendAndReceive(APP_GET_APPID_LIST, uid, b, &response);
1045 if (ret != AUL_SVC_RET_OK)
1048 tizen_base::Bundle res(response, false, true);
1049 auto str = res.GetString(AUL_SVC_K_URI_R_INFO);
1051 ::SetBundle(b, AUL_SVC_K_URI_R_INFO, str.c_str());
1053 auto str_arr = res.GetStringArray(AUL_K_APPID_LIST);
1054 if (str_arr.empty()) {
1055 _E("Failed to get appid list");
1056 return AUL_SVC_RET_ERROR;
1059 *appid_array = reinterpret_cast<char**>(
1060 calloc(str_arr.size(), sizeof(char*)));
1061 if (*appid_array == nullptr) {
1062 _E("Out of memory");
1063 return AUL_SVC_RET_ENOMEM;
1066 *len = str_arr.size();
1069 for (auto& appid : str_arr)
1070 (*appid_array)[i++] = strdup(appid.c_str());
1072 return AUL_SVC_RET_OK;
1075 extern "C" API void aul_svc_free_appid_array(char** appid_array,
1077 if (appid_array == nullptr)
1080 for (unsigned int i = 0; i < len; ++i)
1081 free(appid_array[i]);
1086 extern "C" API int aul_svc_set_defapp(const char* op, const char* mime_type,
1087 const char* uri, const char* defapp) {
1088 DEPRECATION_WARNING();
1089 return AUL_SVC_RET_OK;
1092 extern "C" API int aul_svc_set_defapp_for_uid(const char* op,
1093 const char* mime_type, const char* uri, const char* defapp, uid_t uid) {
1094 DEPRECATION_WARNING();
1095 return AUL_SVC_RET_OK;
1098 extern "C" API int aul_svc_unset_defapp(const char* defapp) {
1099 DEPRECATION_WARNING();
1100 return AUL_SVC_RET_OK;
1103 extern "C" API int aul_svc_unset_defapp_for_uid(const char* defapp, uid_t uid) {
1104 DEPRECATION_WARNING();
1105 return AUL_SVC_RET_OK;
1108 extern "C" API int aul_svc_unset_all_defapps(void) {
1109 DEPRECATION_WARNING();
1110 return AUL_SVC_RET_OK;
1113 extern "C" API int aul_svc_unset_all_defapps_for_uid(uid_t uid) {
1114 DEPRECATION_WARNING();
1115 return AUL_SVC_RET_OK;
1118 extern "C" API int aul_svc_is_defapp(const char* pkg_name) {
1119 DEPRECATION_WARNING();
1120 return AUL_SVC_RET_OK;
1123 extern "C" API int aul_svc_is_defapp_for_uid(const char* pkg_name, uid_t uid) {
1124 DEPRECATION_WARNING();
1125 return AUL_SVC_RET_OK;
1128 extern "C" API int aul_svc_set_alias_appid(const char* alias_appid,
1129 const char* appid) {
1130 DEPRECATION_WARNING();
1131 return AUL_SVC_RET_OK;
1134 extern "C" API int aul_svc_set_alias_appid_for_uid(const char* alias_appid,
1135 const char* appid, uid_t uid) {
1136 DEPRECATION_WARNING();
1137 return AUL_SVC_RET_OK;
1140 extern "C" API int aul_svc_unset_alias_appid(const char* alias_appid) {
1141 DEPRECATION_WARNING();
1142 return AUL_SVC_RET_OK;
1145 extern "C" API int aul_svc_unset_alias_appid_for_uid(const char* alias_appid,
1147 DEPRECATION_WARNING();
1148 return AUL_SVC_RET_OK;
1151 extern "C" API int aul_svc_foreach_alias_info(
1152 void (*callback)(const char *, const char *, void *),
1154 DEPRECATION_WARNING();
1155 return AUL_SVC_RET_OK;
1158 extern "C" API int aul_svc_foreach_alias_info_for_uid(
1159 void (*callback)(const char *, const char *, void *),
1160 uid_t uid, void* user_data) {
1161 DEPRECATION_WARNING();
1162 return AUL_SVC_RET_OK;
1165 extern "C" API int aul_svc_enable_alias_info(const char* appid) {
1166 DEPRECATION_WARNING();
1167 return AUL_SVC_RET_OK;
1170 extern "C" API int aul_svc_enable_alias_info_for_uid(const char* appid,
1172 DEPRECATION_WARNING();
1173 return AUL_SVC_RET_OK;
1176 extern "C" API int aul_svc_disable_alias_info(const char* appid) {
1177 DEPRECATION_WARNING();
1178 return AUL_SVC_RET_OK;
1181 extern "C" API int aul_svc_disable_alias_info_for_uid(const char* appid,
1183 DEPRECATION_WARNING();
1184 return AUL_SVC_RET_OK;
1187 extern "C" API int aul_svc_foreach_alias_info_by_appid(
1188 int (*callback)(const char *, const char *, void *),
1189 const char* appid, void* user_data) {
1190 DEPRECATION_WARNING();
1191 return AUL_SVC_RET_OK;
1194 extern "C" API int aul_svc_foreach_alias_info_by_appid_for_uid(
1195 int (*callback)(const char *, const char *, void *),
1196 const char* appid, uid_t uid, void* user_data) {
1197 DEPRECATION_WARNING();
1198 return AUL_SVC_RET_OK;
1201 extern "C" API int aul_svc_foreach_allowed_info(
1202 int (*callback)(const char *, const char *, void *),
1204 DEPRECATION_WARNING();
1205 return AUL_SVC_RET_OK;
1208 extern "C" API int aul_svc_foreach_allowed_info_for_uid(
1209 int (*callback)(const char *, const char *, void *),
1210 uid_t uid, void* user_data) {
1211 DEPRECATION_WARNING();
1212 return AUL_SVC_RET_OK;
1215 extern "C" API int aul_svc_foreach_allowed_info_by_appid(
1216 int (*callback)(const char *, const char *, void *),
1217 const char* appid, void* user_data) {
1218 DEPRECATION_WARNING();
1219 return AUL_SVC_RET_OK;
1222 extern "C" API int aul_svc_foreach_allowed_info_by_appid_for_uid(
1223 int (*callback)(const char *, const char *, void *),
1224 const char* appid, uid_t uid, void* user_data) {
1225 DEPRECATION_WARNING();
1226 return AUL_SVC_RET_OK;