AUX_SOURCE_DIRECTORY(src SRCS)
AUX_SOURCE_DIRECTORY(aul AUL_SRCS)
AUX_SOURCE_DIRECTORY(aul/api AUL_API_SRCS)
+AUX_SOURCE_DIRECTORY(aul/app_control AUL_APP_CONTROL_SRCS)
AUX_SOURCE_DIRECTORY(aul/app_manager AUL_APP_MANAGER_SRCS)
AUX_SOURCE_DIRECTORY(aul/common AUL_COMMON_SRCS)
AUX_SOURCE_DIRECTORY(aul/component AUL_COMPONENT_SRCS)
${SRCS}
${AUL_SRCS}
${AUL_API_SRCS}
+ ${AUL_APP_CONTROL_SRCS}
${AUL_APP_MANAGER_SRCS}
${AUL_COMMON_SRCS}
${AUL_COMPONENT_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/include/internal
${CMAKE_CURRENT_SOURCE_DIR}/aul/
${CMAKE_CURRENT_SOURCE_DIR}/aul/api
+ ${CMAKE_CURRENT_SOURCE_DIR}/aul/app_control
${CMAKE_CURRENT_SOURCE_DIR}/aul/app_manager
${CMAKE_CURRENT_SOURCE_DIR}/aul/common
${CMAKE_CURRENT_SOURCE_DIR}/aul/component
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <errno.h>
+#include <glib.h>
+
+#include "aul/app_control/resolve_info.hh"
+#include "aul/common/exception.hh"
+#include "aul/common/log_private.hh"
+#include "aul/common/util.hh"
+#include "include/aul.h"
+#include "src/aul_svc_priv_key.h"
+
+namespace aul {
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetPkgName(std::string pkg_name) {
+ pkg_name_ = std::move(pkg_name_);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetOperation(
+ std::string operation) {
+ operation_ = std::move(operation);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetUri(std::string uri) {
+ uri_ = std::move(uri);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetScheme(std::string scheme) {
+ scheme_ = std::move(scheme);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetHost(std::string host) {
+ host_ = std::move(host);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetUriRInfo(
+ std::string uri_r_info) {
+ uri_r_info_ = std::move(uri_r_info);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetOriginMime(
+ std::string origin_mime) {
+ origin_mime_ = std::move(origin_mime);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetMime(std::string mime) {
+ mime_ = std::move(mime);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetMType(std::string m_type) {
+ m_type_ = std::move(m_type);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetSType(std::string s_type) {
+ s_type_ = std::move(s_type);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetCategory(std::string category) {
+ category_ = std::move(category);
+ return *this;
+}
+
+ResolveInfo::Builder& ResolveInfo::Builder::SetWinId(std::string win_id) {
+ win_id_ = std::move(win_id);
+ return *this;
+}
+
+ResolveInfo* ResolveInfo::Builder::Build() {
+ return new (std::nothrow) ResolveInfo(pkg_name_, operation_,
+ uri_, scheme_, host_, uri_r_info_, origin_mime_, mime_,
+ m_type_, s_type_, category_, win_id_);
+}
+
+void ResolveInfo::Manager::GetMime(std::string& uri, std::string& mime) {
+ if (uri.empty())
+ return;
+
+ bool need_check = false;
+ int index;
+ if (uri.compare(0, 1, "/") == 0) {
+ if (mime.empty()) {
+ need_check = true;
+ index = 0;
+ }
+ } else if (uri.compare(0, 8, "file:///") == 0) {
+ if (mime.empty()) {
+ need_check = true;
+ index = 7;
+ }
+ } else if (uri.compare(0, 6, "file:/") == 0) {
+ if (mime.empty()) {
+ need_check = true;
+ index = 5;
+ }
+ }
+
+ if (need_check) {
+ char mime_buf[256] = { 0, };
+ int ret;
+ if (index > 0) {
+ ret = aul_get_mime_from_file(&(uri.c_str()[index]), mime_buf,
+ sizeof(mime_buf));
+ } else {
+ ret = aul_get_mime_from_file(uri.c_str(), mime_buf, sizeof(mime_buf));
+ uri = "";
+ }
+
+ if (ret != AUL_R_OK) {
+ _E("aul_get_mime_from_file() is failed. error(%d)", ret);
+ } else {
+ mime = mime_buf;
+ }
+ }
+}
+
+int ResolveInfo::Manager::GetSchemeAndHost(const std::string& uri,
+ std::string& scheme, std::string& host, std::string& uri_r_info) {
+ if (uri.empty()) {
+ scheme = "NULL";
+ return 0;
+ }
+
+ GError* error = nullptr;
+ GRegex* regex = g_regex_new("^(([^:/?#]+):)?(//([^/?#]*))?",
+ static_cast<GRegexCompileFlags>(0),
+ static_cast<GRegexMatchFlags>(0),
+ &error);
+ if (regex == nullptr) {
+ _E("g_regex_new() is failed");
+ g_clear_error(&error);
+ return -ENOMEM;
+ }
+ std::unique_ptr<GRegex, decltype(g_regex_unref)*> regex_ptr(
+ regex, g_regex_unref);
+
+ GMatchInfo* match_info = nullptr;
+ gboolean ret = g_regex_match(regex, uri.c_str(),
+ static_cast<GRegexMatchFlags>(0), &match_info);
+ if (!ret)
+ return -EINVAL;
+
+ std::unique_ptr<GMatchInfo, decltype(g_match_info_free)*>
+ match_info_ptr(match_info, g_match_info_free);
+
+ gchar* scheme_ptr = g_match_info_fetch(match_info, 2);
+ auto scheme_p = std::unique_ptr<gchar, decltype(g_free)*>(scheme_ptr, g_free);
+ if (scheme_ptr)
+ scheme = scheme_ptr;
+
+ gchar* host_ptr = g_match_info_fetch(match_info, 4);
+ auto host_p = std::unique_ptr<gchar, decltype(g_free)*>(host_ptr, g_free);
+ if (host_ptr)
+ host = host_ptr;
+
+ if (scheme_ptr && host_ptr)
+ uri_r_info = scheme + "://" + host;
+
+ return 0;
+}
+
+ResolveInfo* ResolveInfo::Manager::Create(const tizen_base::Bundle& b) {
+ ResolveInfo::Builder builder;
+ builder.SetPkgName(b.GetString(AUL_SVC_K_PKG_NAME));
+ builder.SetOperation(b.GetString(AUL_SVC_K_OPERATION));
+ builder.SetCategory(b.GetString(AUL_SVC_K_CATEGORY));
+ builder.SetWinId(b.GetString(AUL_SVC_K_WIN_ID));
+
+ std::string uri = b.GetString(AUL_SVC_K_URI);
+ std::string mime = b.GetString(AUL_SVC_K_MIME);
+ SECURE_LOGD("operation(%s), uri(%s), mime(%s)",
+ b.GetString(AUL_SVC_K_OPERATION).c_str(), uri.c_str(), mime.c_str());
+
+ GetMime(uri, mime);
+ builder.SetOriginMime(mime);
+
+ std::string scheme;
+ std::string host;
+ std::string uri_r_info;
+ int ret = GetSchemeAndHost(uri, scheme, host, uri_r_info);
+ if (ret != 0)
+ THROW(ret);
+
+ builder.SetUriRInfo(uri_r_info);
+ builder.SetScheme(scheme);
+ builder.SetHost(host);
+ builder.SetUri(uri);
+
+ if (mime.empty()) {
+ mime = "NULL";
+ } else {
+ auto vec = Util::Split(mime, "/");
+ if (vec.size() > 1) {
+ std::string m_type = vec[0];
+ if (strncmp(m_type.c_str(), "*", 1) == 0)
+ m_type = "%";
+
+ std::string s_type = vec[1];
+ if (strncmp(s_type.c_str(), "*", 1) == 0)
+ s_type = "%";
+
+ mime = m_type + "/" + s_type;
+
+ builder.SetMType(m_type);
+ builder.SetSType(s_type);
+ }
+ }
+ builder.SetMime(mime);
+
+ return builder.Build();
+}
+
+ResolveInfo::ResolveInfo(std::string pkg_name, std::string operation,
+ std::string uri, std::string scheme,
+ std::string host, std::string uri_r_info,
+ std::string origin_mime, std::string mime,
+ std::string m_type, std::string s_type,
+ std::string category, std::string win_id)
+ : pkg_name_(std::move(pkg_name)),
+ operation_(std::move(operation)),
+ uri_(std::move(uri)),
+ scheme_(std::move(scheme)),
+ host_(std::move(host)),
+ uri_r_info_(std::move(uri_r_info)),
+ origin_mime_(std::move(origin_mime)),
+ mime_(std::move(mime)),
+ m_type_(std::move(m_type)),
+ s_type_(std::move(s_type)),
+ category_(std::move(category)),
+ win_id_(std::move(win_id)) {
+}
+
+ResolveInfo::~ResolveInfo() = default;
+
+void ResolveInfo::SetUriRInfo(std::string uri_r_info) {
+ uri_r_info_ = std::move(uri_r_info);
+}
+
+const std::string& ResolveInfo::GetPkgName() const {
+ return pkg_name_;
+}
+
+const std::string& ResolveInfo::GetOperation() const {
+ return operation_;
+}
+
+const std::string& ResolveInfo::GetUri() const {
+ return uri_;
+}
+
+const std::string& ResolveInfo::GetScheme() const {
+ return scheme_;
+}
+
+const std::string& ResolveInfo::GetHost() const {
+ return host_;
+}
+
+const std::string& ResolveInfo::GetUriRInfo() const {
+ return uri_r_info_;
+}
+
+const std::string& ResolveInfo::GetOriginMime() const {
+ return origin_mime_;
+}
+
+const std::string& ResolveInfo::GetMime() const {
+ return mime_;
+}
+
+const std::string& ResolveInfo::GetMType() const {
+ return m_type_;
+}
+
+const std::string& ResolveInfo::GetSType() const {
+ return s_type_;
+}
+
+const std::string& ResolveInfo::GetCategory() const {
+ return category_;
+}
+
+const std::string& ResolveInfo::GetWinId() const {
+ return win_id_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AUL_APP_CONTROL_RESOLVE_INFO_HH_
+#define AUL_APP_CONTROL_RESOLVE_INFO_HH_
+
+#include <bundle_cpp.h>
+
+#include <string>
+
+#include "aul/common/exception.hh"
+
+namespace aul {
+
+class ResolveInfo {
+ public:
+ class Builder {
+ public:
+ Builder& SetPkgName(std::string pkg_name);
+ Builder& SetOperation(std::string operation);
+ Builder& SetUri(std::string uri);
+ Builder& SetScheme(std::string scheme);
+ Builder& SetHost(std::string host);
+ Builder& SetUriRInfo(std::string uri_r_info);
+ Builder& SetOriginMime(std::string origin_mime);
+ Builder& SetMime(std::string mime);
+ Builder& SetMType(std::string m_type);
+ Builder& SetSType(std::string s_type);
+ Builder& SetCategory(std::string category);
+ Builder& SetWinId(std::string win_id);
+ ResolveInfo* Build();
+
+ private:
+ std::string pkg_name_;
+ std::string operation_;
+ std::string uri_;
+ std::string scheme_;
+ std::string host_;
+ std::string uri_r_info_;
+ std::string origin_mime_;
+ std::string mime_;
+ std::string m_type_;
+ std::string s_type_;
+ std::string category_;
+ std::string win_id_;
+ };
+
+ class Manager {
+ public:
+ static ResolveInfo* Create(const tizen_base::Bundle& b);
+ private:
+ static int GetSchemeAndHost(const std::string& uri,
+ std::string& scheme, std::string& host, std::string& uri_r_info);
+ static void GetMime(std::string& uri, std::string& mime);
+ };
+
+ ResolveInfo() = default;
+ ResolveInfo(std::string pkg_name, std::string operation,
+ std::string uri, std::string scheme,
+ std::string host, std::string uri_r_info,
+ std::string origin_mime, std::string mime,
+ std::string m_type, std::string s_type,
+ std::string category, std::string win_id);
+ virtual ~ResolveInfo();
+
+ void SetUriRInfo(std::string uri_r_info);
+
+ const std::string& GetPkgName() const;
+ const std::string& GetOperation() const;
+ const std::string& GetUri() const;
+ const std::string& GetScheme() const;
+ const std::string& GetHost() const;
+ const std::string& GetUriRInfo() const;
+ const std::string& GetOriginMime() const;
+ const std::string& GetMime() const;
+ const std::string& GetMType() const;
+ const std::string& GetSType() const;
+ const std::string& GetCategory() const;
+ const std::string& GetWinId() const;
+
+ private:
+ std::string pkg_name_;
+ std::string operation_;
+ std::string uri_;
+ std::string scheme_;
+ std::string host_;
+ std::string uri_r_info_;
+ std::string origin_mime_;
+ std::string mime_;
+ std::string m_type_;
+ std::string s_type_;
+ std::string category_;
+ std::string win_id_;
+};
+
+} // namespace aul
+
+#endif // AUL_APP_CONTROL_RESOLVE_INFO_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AUL_COMMON_UTIL_HH_
+#define AUL_COMMON_UTIL_HH_
+
+#include <algorithm>
+#include <string>
+#include <vector>
+
+namespace aul {
+
+class Util {
+ public:
+ static std::vector<std::string> Split(const std::string& str,
+ const std::string& delimiter) {
+ std::string string(str);
+ std::vector<std::string> result;
+ std::size_t pos;
+ while ((pos = string.find(delimiter)) != std::string::npos) {
+ std::string token = string.substr(0, pos);
+ result.push_back(token);
+ string.erase(0, pos + delimiter.length());
+ }
+ result.push_back(string);
+ return result;
+ }
+};
+
+} // namespace aul
+
+#endif // AUL_COMMON_UTIL_HH_
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <bundle.h>
+#include <bundle_cpp.h>
+#include <bundle_internal.h>
+#include <glib.h>
+#include <iniparser.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "aul/app_control/resolve_info.hh"
+#include "include/aul.h"
+#include "include/aul_app_group.h"
+#include "include/aul_error.h"
+#include "include/aul_sock.h"
+#include "include/aul_svc.h"
+#include "include/aul_svc_internal.h"
+#include "src/aul_api.h"
+#include "src/aul_svc_priv_key.h"
+#include "src/aul_util.h"
+#include "src/launch.h"
+
+#undef MAX_MIME_STR_SIZE
+#define MAX_MIME_STR_SIZE 256
+
+#undef MAX_SCHEME_STR_SIZE
+#define MAX_SCHEME_STR_SIZE 256
+
+#undef MAX_HOST_STR_SIZE
+#define MAX_HOST_STR_SIZE 256
+
+#undef DEPRECATION_WARNING
+#define DEPRECATION_WARNING() do { \
+ dlog_print(DLOG_WARN, LOG_TAG, \
+ "DEPRECATION WARNING: %s() is deprecated and " \
+ "will be removed from next release.", __FUNCTION__); \
+} while (0)
+
+namespace {
+
+class CbInfo {
+ public:
+ CbInfo(int request_code, aul_svc_res_fn res_fn,
+ aul_svc_err_cb err_cb, void* user_data)
+ : request_code_(request_code),
+ res_fn_(res_fn),
+ err_cb_(err_cb),
+ user_data_(user_data) {
+ }
+
+ int request_code_;
+ aul_svc_res_fn res_fn_;
+ aul_svc_err_cb err_cb_;
+ void* user_data_;
+};
+
+int SetBundle(bundle* b, const char* key, const char* value) {
+ if (bundle_get_type(b, key) != BUNDLE_TYPE_NONE) {
+ if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
+ return AUL_SVC_RET_ERROR;
+ }
+
+ if (value == nullptr)
+ return AUL_SVC_RET_EINVAL;
+
+ if (bundle_add(b, key, value) != BUNDLE_ERROR_NONE)
+ return AUL_SVC_RET_ERROR;
+
+ SECURE_LOGD("key(%s), value(%s)", key, value);
+ return AUL_SVC_RET_OK;
+}
+
+int SetBundleArray(bundle* b, const char* key, const char** value,
+ int len) {
+ int is_array = aul_svc_data_is_array(b, key);
+ if (is_array) {
+ if (bundle_del(b, key) != BUNDLE_ERROR_NONE)
+ return AUL_SVC_RET_ERROR;
+ }
+
+ if (value == nullptr)
+ return AUL_SVC_RET_EINVAL;
+
+ if (bundle_add_str_array(b, key, value, len) != BUNDLE_ERROR_NONE)
+ return AUL_SVC_RET_ERROR;
+
+ SECURE_LOGD("key(%s), length(%d)", key, len);
+ return AUL_SVC_RET_OK;
+}
+
+std::string GetAliasAppId(const char* appid) {
+ dictionary* dic = iniparser_load("/usr/share/appsvc/alias.ini");
+ if (dic == nullptr)
+ return {};
+
+ auto dic_ptr = std::unique_ptr<dictionary, decltype(iniparser_freedict)*>(
+ dic, iniparser_freedict);
+
+ std::string key = std::string("Alias:") + appid;
+ const char* value = iniparser_getstring(dic, key.c_str(), nullptr);
+ SECURE_LOGD("appid(%s), alias_id(%s)", appid, value);
+ if (value == nullptr)
+ return {};
+
+ return std::string(value);
+}
+
+bool IsSpecialApp(const char* appid) {
+ if (!strcmp(appid, APP_SELECTOR) || !strcmp(appid, SHARE_PANEL))
+ return true;
+
+ return false;
+}
+
+bool IsSpecialOperation(const char* operation) {
+ if (operation == nullptr)
+ return false;
+
+ int ret = strcmp(operation,
+ "http://tizen.org/appcontrol/operation/guide_privacy_setting");
+ if (ret == 0)
+ return true;
+
+ return false;
+}
+
+std::string GetAppId(bundle* request) {
+ const char* appid = aul_svc_get_pkgname(request);
+ if (appid == nullptr) {
+ if (aul_svc_get_operation(request) == nullptr) {
+ _E("Invalid request");
+ return {};
+ }
+
+ appid = "@UNKNOWN";
+ }
+
+ int ret = bundle_get_type(request, AUL_SVC_K_SELECTOR_EXTRA_LIST);
+ if (ret != BUNDLE_TYPE_NONE) {
+ if (appid == nullptr || !strcmp(appid, "@UNKNOWN"))
+ appid = APP_SELECTOR;
+ }
+
+ ret = bundle_get_type(request, AUL_K_FORCE_LAUNCH_APP_SELECTOR);
+ if (ret != BUNDLE_TYPE_NONE)
+ appid = APP_SELECTOR;
+
+ return std::string(appid);
+}
+
+void SetLaunchData(bundle* request, const std::string& appid) {
+ const char* operation = aul_svc_get_operation(request);
+ if (operation == nullptr)
+ aul_svc_set_operation(request, AUL_SVC_OPERATION_DEFAULT);
+
+ if (IsSpecialApp(appid.c_str()) || IsSpecialOperation(operation)) {
+ SetBundle(request, AUL_SVC_K_CAN_BE_LEADER, "true");
+ SetBundle(request, AUL_SVC_K_REROUTE, "true");
+ SetBundle(request, AUL_SVC_K_RECYCLE, "true");
+ }
+
+ const char* launch_mode = aul_svc_get_launch_mode(request);
+ if (launch_mode && !strcmp(launch_mode, "group")) {
+ int ret = bundle_get_type(request, AUL_K_INSTANCE_ID);
+ if (ret != BUNDLE_TYPE_NONE)
+ aul_set_instance_info(appid.c_str(), request);
+ }
+}
+
+int AulErrorConvert(int res) {
+ switch (res) {
+ case AUL_R_EILLACC:
+ return AUL_SVC_RET_EILLACC;
+ case AUL_R_EINVAL:
+ return AUL_SVC_RET_EINVAL;
+ case AUL_R_ETERMINATING:
+ return AUL_SVC_RET_ETERMINATING;
+ case AUL_R_EREJECTED:
+ return AUL_SVC_RET_EREJECTED;
+ case AUL_R_ENOAPP:
+ return AUL_SVC_RET_ENOMATCH;
+ default:
+ return AUL_SVC_RET_ELAUNCH;
+ }
+}
+
+void LaunchWithResultCb(bundle* b, int is_cancel, void* data) {
+ int res;
+ if (is_cancel) {
+ res = AUL_SVC_RES_CANCEL;
+ } else {
+ const char* val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
+ res = (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val);
+ }
+
+ bundle_del(b, AUL_SVC_K_RES_VAL);
+ auto* cb_info = static_cast<CbInfo*>(data);
+ if (cb_info->res_fn_) {
+ cb_info->res_fn_(b, cb_info->request_code_,
+ static_cast<aul_svc_result_val>(res), cb_info->user_data_);
+ }
+
+ if (cb_info->err_cb_ != nullptr)
+ return;
+
+ delete cb_info;
+}
+
+void ErrorCb(int error, void* data) {
+ if (error < 0)
+ error = AulErrorConvert(error);
+
+ auto* cb_info = static_cast<CbInfo*>(data);
+ if (cb_info->err_cb_) {
+ cb_info->err_cb_(cb_info->request_code_, error, cb_info->user_data_);
+ cb_info->err_cb_ = nullptr;
+ }
+
+ if (cb_info->res_fn_)
+ return;
+
+ delete cb_info;
+}
+
+using SendLaunchRequestCb =
+ int (*)(const std::string&, bundle*, uid_t, CbInfo*);
+using SendLaunchRequestSyncCb =
+ int (*)(const std::string&, bundle*, uid_t, bundle**);
+
+template <typename T, typename A>
+int SendLaunchRequest(T cb, bundle* request, uid_t uid, A arg) {
+ if (request == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ std::string appid = GetAppId(request);
+ if (appid.empty()) {
+ _E("GetAppId() is failed");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ SetLaunchData(request, appid);
+ return cb(appid, request, uid, arg);
+}
+
+int SendAndReceive(int cmd, uid_t uid, bundle* request, bundle** response) {
+ int fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, cmd, request,
+ AUL_SOCK_ASYNC);
+ if (fd < 0)
+ return AUL_SVC_RET_ERROR;
+
+ app_pkt_t* pkt = nullptr;
+ int ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret < 0) {
+ _E("Failed to receive reply packet. error(%d)", ret);
+ return AUL_SVC_RET_ERROR;
+ }
+
+ auto ptr = std::unique_ptr<app_pkt_t, decltype(std::free)*>(pkt, std::free);
+ if (pkt->cmd != APP_GET_INFO_OK && pkt->cmd != cmd)
+ return AUL_SVC_RET_ERROR;
+
+ bundle* b = nullptr;
+ if (pkt->opt & AUL_SOCK_BUNDLE) {
+ b = bundle_decode(pkt->data, pkt->len);
+ if (b == nullptr) {
+ _E("bundle_decode() is failed");
+ return AUL_SVC_RET_ENOMEM;
+ }
+ } else {
+ _E("Invalid packet");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ *response = b;
+ return AUL_SVC_RET_OK;
+}
+
+} // namespace
+
+extern "C" API int aul_svc_set_operation(bundle* b, const char* operation) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_OPERATION, operation);
+}
+
+extern "C" API int aul_svc_set_uri(bundle* b, const char* uri) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_URI, uri);
+}
+
+extern "C" API int aul_svc_set_mime(bundle* b, const char* mime) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_MIME, mime);
+}
+
+extern "C" API int aul_svc_add_data(bundle* b, const char* key,
+ const char* value) {
+ if (b == nullptr || key == nullptr)
+ return AUL_SVC_RET_EINVAL;
+
+ return ::SetBundle(b, key, value);
+}
+
+extern "C" API int aul_svc_add_data_array(bundle* b, const char* key,
+ const char** value, int len) {
+ if (b == nullptr || key == nullptr)
+ return AUL_SVC_RET_EINVAL;
+
+ return ::SetBundleArray(b, key, value, len);
+}
+
+extern "C" API int aul_svc_set_pkgname(bundle* b, const char* pkg_name) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
+}
+
+extern "C" API int aul_svc_set_appid(bundle* b, const char* appid) {
+ if (b == nullptr || appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ std::string alias_id = ::GetAliasAppId(appid);
+ if (!alias_id.empty())
+ appid = alias_id.c_str();
+
+ return ::SetBundle(b, AUL_SVC_K_PKG_NAME, appid);
+}
+
+extern "C" API int aul_svc_set_category(bundle* b, const char* category) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_CATEGORY, category);
+}
+
+extern "C" API int aul_svc_set_launch_mode(bundle* b, const char* mode) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
+}
+
+extern "C" API int aul_svc_resolve(bundle* b, uid_t uid, char*** appid_array,
+ unsigned int* len) {
+ return aul_svc_get_appid_array(b, uid, appid_array, len);
+}
+
+extern "C" API int aul_svc_run_service(bundle* b, int request_code,
+ aul_svc_res_fn cbfunc, void* data) {
+ return aul_svc_run_service_for_uid(b, request_code, cbfunc, data, getuid());
+}
+
+extern "C" API int aul_svc_run_service_for_uid(bundle* b, int request_code,
+ aul_svc_res_fn cbfunc, void* data, uid_t uid) {
+ CbInfo* cb_info = nullptr;
+ if (cbfunc)
+ cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
+
+ std::tuple<aul_svc_res_fn, void*> param { cbfunc, data };
+ int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
+ [](const std::string& appid, bundle* request, uid_t uid,
+ CbInfo* cb_info) -> int {
+ int ret;
+ if (cb_info) {
+ ret = aul_launch_app_with_result_for_uid(appid.c_str(), request,
+ LaunchWithResultCb, cb_info, uid);
+ } else {
+ ret = aul_launch_app_for_uid(appid.c_str(), request, uid);
+ }
+
+ return ret;
+ }, b, uid, cb_info);
+ if (ret < 0) {
+ if (cb_info)
+ delete cb_info;
+
+ ret = AulErrorConvert(ret);
+ }
+
+ return ret;
+}
+
+extern "C" API int aul_svc_get_list(bundle* b, aul_svc_info_iter_fn iter_fn,
+ void* data) {
+ return aul_svc_get_list_for_uid(b, iter_fn, data, getuid());
+}
+
+extern "C" API int aul_svc_get_list_for_uid(bundle* b,
+ aul_svc_info_iter_fn iter_fn, void* data, uid_t uid) {
+ if (b == nullptr || iter_fn == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ char** appid_array = nullptr;
+ unsigned int len = 0;
+ int ret = aul_svc_get_appid_array(b, uid, &appid_array, &len);
+ if (ret != AUL_SVC_RET_OK)
+ return ret;
+
+ if (len == 0) {
+ _E("Failed to find associated application");
+ aul_svc_free_appid_array(appid_array, len);
+ return AUL_SVC_RET_ENOMATCH;
+ }
+
+ for (unsigned int i = 0; i < len; ++i) {
+ SECURE_LOGD("APPID: %s", appid_array[i]);
+ if (iter_fn(appid_array[i], data) != 0)
+ break;
+ }
+
+ aul_svc_free_appid_array(appid_array, len);
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn,
+ void* data) {
+ return aul_svc_get_all_defapps_for_uid(iter_fn, data, getuid());
+}
+
+extern "C" API int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
+ void* data, uid_t uid) {
+ if (iter_fn == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ bundle* response;
+ tizen_base::Bundle request;
+ int ret = ::SendAndReceive(APP_GET_APP_CONTROL_DEFAULT_APPS, uid,
+ request.GetHandle(), &response);
+ if (ret != AUL_SVC_RET_OK)
+ return ret;
+
+ tizen_base::Bundle res(response, false, true);
+ auto appid_array = res.GetStringArray(AUL_K_APPID_LIST);
+ if (appid_array.size() == 0)
+ return AUL_SVC_RET_ERROR;
+
+ for (auto& appid : appid_array) {
+ if (iter_fn(appid.c_str(), data) != 0)
+ break;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API const char* aul_svc_get_operation(bundle* b) {
+ return bundle_get_val(b, AUL_SVC_K_OPERATION);
+}
+
+extern "C" API const char* aul_svc_get_uri(bundle* b) {
+ return bundle_get_val(b, AUL_SVC_K_URI);
+}
+
+extern "C" API const char* aul_svc_get_mime(bundle* b) {
+ return bundle_get_val(b, AUL_SVC_K_MIME);
+}
+
+extern "C" API const char* aul_svc_get_data(bundle* b, const char* key) {
+ return bundle_get_val(b, key);
+}
+
+extern "C" API const char** aul_svc_get_data_array(bundle* b, const char* key,
+ int* len) {
+ return bundle_get_str_array(b, key, len);
+}
+
+extern "C" API const char* aul_svc_get_pkgname(bundle* b) {
+ return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
+}
+
+extern "C" API const char* aul_svc_get_appid(bundle* b) {
+ return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
+}
+
+extern "C" API const char* aul_svc_get_category(bundle* b) {
+ return bundle_get_val(b, AUL_SVC_K_CATEGORY);
+}
+
+extern "C" API const char* aul_svc_get_launch_mode(bundle* b) {
+ return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
+}
+
+extern "C" API int aul_svc_create_result_bundle(bundle* inb, bundle** outb) {
+ if (inb == nullptr || outb == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ int ret = aul_create_result_bundle(inb, outb);
+ if (ret != AUL_R_OK)
+ return AulErrorConvert(ret);
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_send_result(bundle* b, aul_svc_result_val result) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ int ret = ::SetBundle(b, AUL_SVC_K_RES_VAL, std::to_string(result).c_str());
+ if (ret < 0)
+ return AUL_SVC_RET_ERROR;
+
+ if (result == AUL_SVC_RES_CANCEL)
+ ret = aul_send_result(b, 1);
+ else
+ ret = aul_send_result(b, 0);
+
+ bundle_del(b, AUL_SVC_K_RES_VAL);
+ return ret;
+}
+
+extern "C" API int aul_svc_data_is_array(bundle* b, const char* key) {
+ int type = bundle_get_type(b, key);
+ if (type <= 0)
+ return 0;
+
+ if (type & BUNDLE_TYPE_ARRAY)
+ return 1;
+
+ return 0;
+}
+
+extern "C" API int aul_svc_allow_transient_app(bundle* b, int wid) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_WIN_ID, std::to_string(wid).c_str());
+}
+
+extern "C" API int aul_svc_request_transient_app(bundle* b, int callee_wid,
+ aul_svc_host_res_fn cbfunc, void* data) {
+ return 0;
+}
+
+extern "C" API int aul_svc_subapp_terminate_request_pid(int pid) {
+ int cpid = getpid();
+ int lcnt;
+ int* lpids = nullptr;
+ aul_app_group_get_leader_pids(&lcnt, &lpids);
+ for (int i = 0; i < lcnt; ++i) {
+ if (lpids[i] == cpid) {
+ int cnt;
+ int* pids = nullptr;
+ aul_app_group_get_group_pids(cpid, &cnt, &pids);
+ if (cnt == 0) {
+ free(lpids);
+ if (pids)
+ free(pids);
+
+ return aul_subapp_terminate_request_pid(pid);
+ }
+
+ if (pids != nullptr)
+ free(pids);
+ break;
+ }
+ }
+
+ if (lpids != nullptr)
+ free(lpids);
+
+ return aul_app_group_clear_top();
+}
+
+extern "C" API int aul_send_service_result(bundle* b) {
+ return aul_send_result(b, 0);
+}
+
+extern "C" API int aul_svc_subscribe_launch_result(bundle* b,
+ const char* result) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, result, "1");
+}
+
+extern "C" API int aul_svc_set_loader_id(bundle* b, int loader_id) {
+ if (b == nullptr || loader_id <= 0) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_K_LOADER_ID, std::to_string(loader_id).c_str());
+}
+
+extern "C" API int aul_svc_set_loader_name(bundle* b, const char* loader_name) {
+ if (b == nullptr || loader_name == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_K_LOADER_NAME, loader_name);
+}
+
+extern "C" API int aul_svc_set_background_launch(bundle* b, int enabled) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_SVC_K_BG_LAUNCH, enabled ? "enable" : nullptr);
+}
+
+extern "C" API int aul_svc_get_appid_by_alias_appid(const char* alias_appid,
+ char** appid) {
+ return aul_svc_get_appid_by_alias_appid_for_uid(alias_appid, appid, getuid());
+}
+
+extern "C" API int aul_svc_get_appid_by_alias_appid_for_uid(
+ const char* alias_appid, char** appid, uid_t uid) {
+ if (alias_appid == nullptr || appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ bundle* response;
+ tizen_base::Bundle request;
+ request.Add(AUL_K_ALIAS_APPID, alias_appid);
+ int ret = ::SendAndReceive(APP_GET_APPID_BY_ALIAS_APPID, uid,
+ request.GetHandle(), &response);
+ if (ret != AUL_SVC_RET_OK)
+ return ret;
+
+ tizen_base::Bundle res(response, false, true);
+ auto val = res.GetString(AUL_K_APPID);
+ if (val.empty())
+ return AUL_SVC_RET_ERROR;
+
+ *appid = strdup(val.c_str());
+ if (*appid == nullptr) {
+ _E("Out of memory");
+ return AUL_SVC_RET_ENOMEM;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API const char *aul_svc_get_instance_id(bundle* b) {
+ return bundle_get_val(b, AUL_K_INSTANCE_ID);
+}
+
+extern "C" API int aul_svc_set_instance_id(bundle* b, const char* instance_id) {
+ if (b == nullptr || instance_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_K_INSTANCE_ID, instance_id);
+}
+
+extern "C" API int aul_svc_run_service_async(bundle* b, int request_code,
+ aul_svc_res_fn cbfunc, void* data) {
+ return aul_svc_run_service_async_for_uid(b, request_code, cbfunc, data,
+ getuid());
+}
+
+extern "C" API int aul_svc_run_service_async_for_uid(bundle* b,
+ int request_code, aul_svc_res_fn cbfunc, void* data, uid_t uid) {
+ CbInfo* cb_info = nullptr;
+ if (cbfunc)
+ cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
+
+ int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
+ [](const std::string& appid, bundle* request, uid_t uid,
+ CbInfo* info) -> int {
+ if (info) {
+ return aul_launch_app_with_result_async_for_uid(appid.c_str(),
+ request, LaunchWithResultCb, info, uid);
+ }
+
+ return aul_launch_app_async_for_uid(appid.c_str(), request, uid);
+ }, b, uid, cb_info);
+ if (ret < 0) {
+ if (cb_info)
+ delete cb_info;
+
+ ret = AulErrorConvert(ret);
+ }
+
+ return ret;
+}
+
+extern "C" API int aul_svc_send_launch_request(bundle* b, int request_code,
+ aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void* user_data) {
+ return aul_svc_send_launch_request_for_uid(b, request_code,
+ cbfunc, err_cb, user_data, getuid());
+}
+
+extern "C" API int aul_svc_send_launch_request_for_uid(bundle* b,
+ int request_code, aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
+ void* user_data, uid_t uid) {
+ if (b == nullptr || err_cb == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ CbInfo* cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, err_cb,
+ user_data);
+ int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
+ [](const std::string& appid, bundle* request, uid_t uid,
+ CbInfo* info) -> int {
+ return aul_send_launch_request_for_uid(appid.c_str(), request, uid,
+ info->res_fn_ ? ::LaunchWithResultCb : nullptr, ::ErrorCb, info);
+ }, b, uid, cb_info);
+ if (ret < 0) {
+ delete cb_info;
+ ret = ::AulErrorConvert(ret);
+ }
+
+ return ret;
+}
+
+extern "C" API int aul_svc_send_launch_request_sync_for_uid(bundle* b,
+ int request_code, bundle** res_b, aul_svc_result_val* res, uid_t uid) {
+ if (b == nullptr || res_b == nullptr || res == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ int ret = ::SendLaunchRequest<::SendLaunchRequestSyncCb, bundle**>(
+ [](const std::string& appid, bundle* request, uid_t uid,
+ bundle** response) -> int {
+ return aul_send_launch_request_sync_for_uid(appid.c_str(), request,
+ uid, response);
+ }, b, uid, res_b);
+ if (ret > 0) {
+ auto* val = bundle_get_val(*res_b, AUL_SVC_K_RES_VAL);
+ *res = static_cast<aul_svc_result_val>(
+ (val == nullptr) ? AUL_SVC_RES_NOT_OK : atoi(val));
+ } else {
+ ret = ::AulErrorConvert(ret);
+ *res = AUL_SVC_RES_CANCEL;
+ }
+
+ return ret;
+}
+
+extern "C" API int aul_svc_info_create(bundle* b, aul_svc_info_h* h) {
+ if (b == nullptr || h == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ aul::ResolveInfo* resolve_info = nullptr;
+ try {
+ tizen_base::Bundle kb(b, false, false);
+ resolve_info = aul::ResolveInfo::Manager::Create(kb);
+ } catch (aul::Exception& e) {
+ return AUL_SVC_RET_ERROR;
+ }
+
+ *h = static_cast<aul_svc_info_h>(resolve_info);
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_get_operation(aul_svc_info_h h,
+ char** operation) {
+ if (h == nullptr || operation == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ auto& value = info->GetOperation();
+ *operation = strdup(value.empty() ? "NULL" : value.c_str());
+ if (*operation == nullptr) {
+ _E("Failed to duplicate operation");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_get_uri(aul_svc_info_h h, char** uri) {
+ if (h == nullptr || uri == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ auto& value = info->GetUri();
+ *uri = strdup(value.empty() ? "NULL" : value.c_str());
+ if (*uri == nullptr) {
+ _E("Failed to duplicate URI");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_get_uri_scheme(aul_svc_info_h h,
+ char** uri_scheme) {
+ if (h == nullptr || uri_scheme == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ auto& value = info->GetScheme();
+ *uri_scheme = strdup(value.empty() ? "NULL" : value.c_str());
+ if (*uri_scheme == nullptr) {
+ _E("Failed to duplicate URI scheme");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_get_uri_host(aul_svc_info_h h,
+ char** uri_host) {
+ if (h == nullptr || uri_host == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ auto& value = info->GetHost();
+ *uri_host = strdup(value.empty() ? "NULL" : value.c_str());
+ if (*uri_host == nullptr) {
+ _E("Failed to duplicate URI host");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_get_mime(aul_svc_info_h h, char** mime) {
+ if (h == nullptr || mime == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ auto& value = info->GetMime();
+ *mime = strdup(value.empty() ? "NULL" : value.c_str());
+ if (*mime == nullptr) {
+ _E("Failed to duplicate MIME-Type");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_get_mime_type(aul_svc_info_h h,
+ char** mime_type) {
+ if (h == nullptr || mime_type == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ auto& value = info->GetMType();
+ *mime_type = strdup(value.empty() ? "NULL" : value.c_str());
+ if (*mime_type == nullptr) {
+ _E("Failed to duplicate the type of MIME-Type");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_get_mime_subtype(aul_svc_info_h h,
+ char** mime_subtype) {
+ if (h == nullptr || mime_subtype == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ auto& value = info->GetSType();
+ *mime_subtype = strdup(value.empty() ? "NULL" : value.c_str());
+ if (*mime_subtype == nullptr) {
+ _E("Failed to duplicate the subtype of MIME-Type");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_info_destroy(aul_svc_info_h h) {
+ if (h == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* info = static_cast<aul::ResolveInfo*>(h);
+ delete info;
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_set_caller_instance_id(bundle* b,
+ const char* instance_id) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_K_CALLER_INSTANCE_ID, instance_id);
+}
+
+extern "C" API int aul_svc_set_comp_id(bundle* b, const char* comp_id) {
+ if (b == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ return ::SetBundle(b, AUL_K_COMPONENT_ID, comp_id);
+}
+
+extern "C" API const char *aul_svc_get_comp_id(bundle* b) {
+ return bundle_get_val(b, AUL_K_COMPONENT_ID);
+}
+
+extern "C" API int aul_svc_subapp_terminate_request(bundle* b, int pid) {
+ if (b == nullptr || pid < 0) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ const char* inst_id = bundle_get_val(b, AUL_K_INSTANCE_ID);
+ if (inst_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ char buf[512] = { 0, };
+ const char* caller_inst_id = bundle_get_val(b, AUL_K_CALLER_INSTANCE_ID);
+ if (caller_inst_id == nullptr) {
+ int ret = aul_app_get_instance_id_bypid(getpid(), buf, sizeof(buf));
+ if (ret != AUL_R_OK) {
+ _E("aul_app_get_instance_id_bypid() is failed. error(%d)", ret);
+ return AUL_SVC_RET_ERROR;
+ }
+
+ caller_inst_id = buf;
+ }
+
+ int cnt = 0;
+ aul_app_group_foreach_group_info(caller_inst_id,
+ [](aul_app_group_info_h info, void* data) {
+ int* count = static_cast<int*>(data);
+ (*count)++;
+ }, static_cast<void*>(&cnt));
+ if (cnt == 0)
+ return aul_subapp_terminate_request(inst_id, pid);
+
+ return aul_app_group_clear_top();
+}
+
+extern "C" API int aul_svc_send_resume_request(bundle* b, int request_code,
+ aul_svc_err_cb err_cb, void *user_data) {
+ return aul_svc_send_resume_request_for_uid(b, request_code, err_cb, user_data,
+ getuid());
+}
+
+extern "C" API int aul_svc_send_resume_request_for_uid(bundle* b,
+ int request_code, aul_svc_err_cb err_cb, void* user_data, uid_t uid) {
+ if (b == nullptr || err_cb == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ auto* cb_info = new (std::nothrow) CbInfo(request_code, nullptr, err_cb,
+ user_data);
+ int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
+ [](const std::string& appid, bundle* request, uid_t uid,
+ CbInfo* info) -> int {
+ return aul_send_resume_request_for_uid(appid.c_str(), request, uid,
+ ErrorCb, info);
+ }, b, uid, cb_info);
+ if (ret < 0) {
+ delete cb_info;
+ ret = ::AulErrorConvert(ret);
+ }
+
+ return ret;
+}
+
+extern "C" API int aul_svc_get_appid_array(bundle* b, uid_t uid,
+ char*** appid_array, unsigned int* len) {
+ if (b == nullptr || appid_array == nullptr || len == nullptr) {
+ _E("Invalid parameter");
+ return AUL_SVC_RET_EINVAL;
+ }
+
+ bundle_del(b, AUL_K_APPID);
+ bundle_add(b, AUL_K_APPID, "@UNKNOWN");
+
+ bundle* response;
+ int ret = ::SendAndReceive(APP_GET_APPID_LIST, uid, b, &response);
+ if (ret != AUL_SVC_RET_OK)
+ return ret;
+
+ tizen_base::Bundle res(response, false, true);
+ auto str = res.GetString(AUL_SVC_K_URI_R_INFO);
+ if (!str.empty())
+ ::SetBundle(b, AUL_SVC_K_URI_R_INFO, str.c_str());
+
+ auto str_arr = res.GetStringArray(AUL_K_APPID_LIST);
+ if (str_arr.empty()) {
+ _E("Failed to get appid list");
+ return AUL_SVC_RET_ERROR;
+ }
+
+ *appid_array = reinterpret_cast<char**>(
+ calloc(str_arr.size(), sizeof(char*)));
+ if (*appid_array == nullptr) {
+ _E("Out of memory");
+ return AUL_SVC_RET_ENOMEM;
+ }
+
+ *len = str_arr.size();
+
+ int i = 0;
+ for (auto& appid : str_arr)
+ (*appid_array)[i++] = strdup(appid.c_str());
+
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API void aul_svc_free_appid_array(char** appid_array,
+ unsigned int len) {
+ if (appid_array == nullptr)
+ return;
+
+ for (unsigned int i = 0; i < len; ++i)
+ free(appid_array[i]);
+
+ free(appid_array);
+}
+
+extern "C" API int aul_svc_set_defapp(const char* op, const char* mime_type,
+ const char* uri, const char* defapp) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_set_defapp_for_uid(const char* op,
+ const char* mime_type, const char* uri, const char* defapp, uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_unset_defapp(const char* defapp) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_unset_defapp_for_uid(const char* defapp, uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_unset_all_defapps(void) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_unset_all_defapps_for_uid(uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_is_defapp(const char* pkg_name) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_is_defapp_for_uid(const char* pkg_name, uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_set_alias_appid(const char* alias_appid,
+ const char* appid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_set_alias_appid_for_uid(const char* alias_appid,
+ const char* appid, uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_unset_alias_appid(const char* alias_appid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_unset_alias_appid_for_uid(const char* alias_appid,
+ uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_alias_info(
+ void (*callback)(const char *, const char *, void *),
+ void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_alias_info_for_uid(
+ void (*callback)(const char *, const char *, void *),
+ uid_t uid, void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_enable_alias_info(const char* appid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_enable_alias_info_for_uid(const char* appid,
+ uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_disable_alias_info(const char* appid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_disable_alias_info_for_uid(const char* appid,
+ uid_t uid) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_alias_info_by_appid(
+ int (*callback)(const char *, const char *, void *),
+ const char* appid, void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_alias_info_by_appid_for_uid(
+ int (*callback)(const char *, const char *, void *),
+ const char* appid, uid_t uid, void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_allowed_info(
+ int (*callback)(const char *, const char *, void *),
+ void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_allowed_info_for_uid(
+ int (*callback)(const char *, const char *, void *),
+ uid_t uid, void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_allowed_info_by_appid(
+ int (*callback)(const char *, const char *, void *),
+ const char* appid, void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+
+extern "C" API int aul_svc_foreach_allowed_info_by_appid_for_uid(
+ int (*callback)(const char *, const char *, void *),
+ const char* appid, uid_t uid, void* user_data) {
+ DEPRECATION_WARNING();
+ return AUL_SVC_RET_OK;
+}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <sqlite3.h>
-#include <stdbool.h>
-#include <time.h>
-#include <sys/types.h>
-#include <glib.h>
-
-#define MAX_FILTER_STR_SIZE 1024
-#define MAX_PACKAGE_STR_SIZE 512
-#define MAX_URI_STR_SIZE 256
-#define MAX_MIME_STR_SIZE 256
-#define MAX_SCHEME_STR_SIZE 256
-#define MAX_HOST_STR_SIZE 256
-#define MAX_OP_STR_SIZE 128
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-int _svc_db_add_app(const char *op, const char *mime_type, const char *uri, const char *pkg_name, uid_t uid);
-int _svc_db_delete_with_pkgname(const char *pkg_name, uid_t uid);
-char* _svc_db_get_app(const char *op, const char *mime_type, const char *uri, uid_t uid);
-int _svc_db_is_defapp(const char *pkg_name, uid_t uid);
-int _svc_db_adjust_list_with_submode(int mainapp_mode, char *win_id, GSList **pkg_list, uid_t uid);
-int _svc_db_get_list_with_all_defapps(GSList **pkg_list, uid_t uid);
-int _svc_db_delete_all(uid_t uid);
-
-char *_svc_db_query_builder_in(const char *field, char *args);
-char *_svc_db_query_builder_or(char *q1, char *q2);
-char *_svc_db_query_builder_add(char *old_query, char *op, char *uri, char *mime, bool collate);
-char *_svc_db_query_builder_build(char *old_query);
-int _svc_db_exec_query(const char *query, GSList **pkg_list, uid_t uid);
-
-int _svc_db_add_alias_appid(const char *alias_appid, const char *appid,
- uid_t uid);
-int _svc_db_delete_alias_appid(const char *alias_appid, uid_t uid);
-int _svc_db_get_appid_from_alias_info(const char *alias_appid,
- char **appid, uid_t uid);
-int _svc_db_foreach_alias_info(void (*callback)(const char *alias_appid, const
- char *appid, void *data),
- uid_t uid, void *user_data);
-int _svc_db_enable_alias_info(const char *appid, uid_t uid);
-int _svc_db_disable_alias_info(const char *appid, uid_t uid);
-int _svc_db_foreach_alias_info_by_appid(int (*callback)(
- const char *alias_appid, const char *appid, void *data),
- const char *appid, uid_t uid, void *user_data);
-int _svc_db_foreach_allowed_info(int (*callback)(const char *appid,
- const char *allowed_appid, void *data),
- uid_t uid, void *user_data);
-int _svc_db_foreach_allowed_info_by_appid(int (*callback)(const char *appid,
- const char *allowed_appid, void *data),
- const char *appid, uid_t uid, void *user_data);
-
-#ifdef __cplusplus
-}
-#endif
-
-
#undef LOG_TAG
#define LOG_TAG "AUL"
+#undef _E
#define _E(fmt, arg...) LOGE(fmt, ##arg)
+
+#undef _D
#define _D(fmt, arg...) LOGD(fmt, ##arg)
+
+#undef _W
#define _W(fmt, arg...) LOGW(fmt, ##arg)
+
+#undef _I
#define _I(fmt, arg...) LOGI(fmt, ##arg)
#define AUL_UTIL_PID -2
#include <glib.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
int aul_initialize(void);
int aul_is_initialized(void);
int aul_app_register_pid(const char *appid, int pid);
int aul_send_resume_request_for_uid(const char *appid, bundle *b, uid_t uid,
void (*error_cb)(int, void *), void *user_data);
void aul_set_instance_info(const char *app_id, bundle *kb);
+
+#ifdef __cplusplus
+}
+#endif
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define _GNU_SOURCE
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <uuid.h>
-#include <bundle.h>
-#include <bundle_internal.h>
-#include <glib.h>
-#include <string.h>
-#include <pthread.h>
-#include <dlfcn.h>
-#include <iniparser.h>
-#include <pkgmgr-info.h>
-
-#include "aul.h"
-#include "aul_api.h"
-#include "aul_app_group.h"
-#include "aul_error.h"
-#include "aul_sock.h"
-#include "aul_svc.h"
-#include "aul_svc_internal.h"
-#include "aul_svc_priv_key.h"
-#include "aul_util.h"
-#include "launch.h"
-
-#undef MAX_MIME_STR_SIZE
-#define MAX_MIME_STR_SIZE 256
-
-#undef MAX_SCHEME_STR_SIZE
-#define MAX_SCHEME_STR_SIZE 256
-
-#undef MAX_HOST_STR_SIZE
-#define MAX_HOST_STR_SIZE 256
-
-#undef DEPRECATION_WARNING
-#define DEPRECATION_WARNING() do { \
- dlog_print(DLOG_WARN, LOG_TAG, \
- "DEPRECATION WARNING: %s() is deprecated and " \
- "will be removed from next release.", __FUNCTION__); \
-} while (0)
-
-/* callback handling */
-typedef struct _aul_svc_cb_info_t {
- int request_code;
- aul_svc_res_fn cb_func;
- aul_svc_err_cb err_cb;
- void *data;
-} aul_svc_cb_info_t;
-
-typedef struct _aul_svc_resolve_info_t {
- char *pkgname;
- char *op;
- char *uri;
- char *scheme;
- char *host;
- char *uri_r_info;
- char *origin_mime;
- char *mime;
- char *m_type;
- char *s_type;
- char *category;
- char *win_id;
- int mime_set;
-} aul_svc_resolve_info_t;
-
-typedef struct _aul_svc_transient_cb_info_t {
- aul_svc_host_res_fn cb_func;
- void *data;
-} aul_svc_transient_cb_info_t;
-
-static pthread_mutex_t iniparser_lock = PTHREAD_MUTEX_INITIALIZER;
-
-static aul_svc_cb_info_t *__create_rescb(int request_code,
- aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void *data);
-static void __remove_rescb(aul_svc_cb_info_t *info);
-static int __set_bundle(bundle *b, const char *key, const char *value);
-static void __aul_cb(bundle *b, int is_cancel, void *data);
-static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
- aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void *data,
- uid_t uid, bool sync);
-static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info);
-static int __free_resolve_info_data(aul_svc_resolve_info_t *info);
-
-static bool __is_special_app(const char *appid)
-{
- static char *allowed_apps[] = {
- APP_SELECTOR,
- SHARE_PANEL,
- NULL
- };
- int i;
-
- if (appid == NULL)
- return false;
-
- for (i = 0; allowed_apps[i]; ++i) {
- if (!strcmp(allowed_apps[i], appid))
- return true;
- }
- return false;
-}
-
-static bool __is_special_operation(bundle *b)
-{
- static const char *allowed_operations[] = {
- "http://tizen.org/appcontrol/operation/guide_privacy_setting",
- NULL
- };
- const char *operation;
- int i;
-
- operation = aul_svc_get_operation(b);
- if (!operation)
- return false;
-
- for (i = 0; allowed_operations[i]; ++i) {
- if (!strcmp(allowed_operations[i], operation))
- return true;
- }
-
- return false;
-}
-
-static aul_svc_cb_info_t *__create_rescb(int request_code,
- aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void *data)
-{
- aul_svc_cb_info_t* info;
-
- info = calloc(1, sizeof(aul_svc_cb_info_t));
- if (info == NULL) {
- _E("Out of memory");
- return NULL;
- }
-
- info->request_code = request_code;
- info->cb_func = cbfunc;
- info->err_cb = err_cb;
- info->data = data;
-
- return info;
-}
-
-static void __remove_rescb(aul_svc_cb_info_t *info)
-{
- if (info)
- free(info);
-}
-
-static int __set_bundle(bundle *b, const char *key, const char *value)
-{
- const char *val = NULL;
-
- val = bundle_get_val(b, key);
- if (val) {
- if (bundle_del(b, key) != 0)
- return AUL_SVC_RET_ERROR;
- }
-
- if (!value)
- return AUL_SVC_RET_EINVAL;
-
- if (bundle_add(b, key, value) != 0)
- return AUL_SVC_RET_ERROR;
-
- _D("__set_bundle");
-
- return AUL_SVC_RET_OK;
-}
-
-static int __set_bundle_array(bundle *b, const char *key,
- const char **value, int len)
-{
-
- int type;
- type = aul_svc_data_is_array(b, key);
-
- if (type == 1) {
- if (bundle_del(b, key) != 0)
- return AUL_SVC_RET_ERROR;
- }
-
- if (!value)
- return AUL_SVC_RET_EINVAL;
-
- if (bundle_add_str_array(b, key, value, len) != 0)
- return AUL_SVC_RET_ERROR;
-
- _D("__set_bundle_array");
-
- return AUL_SVC_RET_OK;
-}
-
-static void __aul_cb(bundle *b, int is_cancel, void *data)
-{
- const char *val = NULL;
- aul_svc_cb_info_t* cb_info;
- int res;
-
- if (is_cancel)
- res = AUL_SVC_RES_CANCEL;
- else {
- /* get result_code from bundle */
- val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
- res = (val == NULL) ? AUL_SVC_RES_NOT_OK : atoi(val);
- }
-
- /* remove result_code from bundle */
- bundle_del(b, AUL_SVC_K_RES_VAL);
-
- /* find corresponding callback */
- cb_info = (aul_svc_cb_info_t*)data;
-
- if (cb_info->cb_func) {
- cb_info->cb_func(b, cb_info->request_code,
- (aul_svc_result_val)res, cb_info->data);
- cb_info->cb_func = NULL;
- }
-
- if (cb_info->err_cb)
- return;
-
- __remove_rescb(cb_info);
-}
-
-static int __error_convert(int res)
-{
- switch (res) {
- case AUL_R_EILLACC:
- return AUL_SVC_RET_EILLACC;
- case AUL_R_EINVAL:
- return AUL_SVC_RET_EINVAL;
- case AUL_R_ETERMINATING:
- return AUL_SVC_RET_ETERMINATING;
- case AUL_R_EREJECTED:
- return AUL_SVC_RET_EREJECTED;
- case AUL_R_ENOAPP:
- return AUL_SVC_RET_ENOMATCH;
- default:
- return AUL_SVC_RET_ELAUNCH;
- }
-}
-
-static void __aul_error_cb(int err, void *data)
-{
- aul_svc_cb_info_t *cb_info = (aul_svc_cb_info_t *)data;
-
- if (!cb_info) {
- _E("Critical error!");
- return;
- }
-
- if (err < 0)
- err = __error_convert(err);
-
- if (cb_info->err_cb) {
- cb_info->err_cb(cb_info->request_code, err, cb_info->data);
- cb_info->err_cb = NULL;
- }
-
- if (cb_info->cb_func)
- return;
-
- __remove_rescb(cb_info);
-}
-
-static void __verify_request(bundle *b, char **appid)
-{
- const char *launch_mode;
- int ret;
-
- ret = bundle_get_type(b, AUL_SVC_K_SELECTOR_EXTRA_LIST);
- if (ret != BUNDLE_TYPE_NONE) {
- if (!aul_svc_get_pkgname(b))
- *appid = APP_SELECTOR;
- }
-
- if (bundle_get_val(b, AUL_K_FORCE_LAUNCH_APP_SELECTOR))
- *appid = APP_SELECTOR;
-
- if (__is_special_app(*appid) || __is_special_operation(b)) {
- bundle_del(b, AUL_SVC_K_CAN_BE_LEADER);
- bundle_add_str(b, AUL_SVC_K_CAN_BE_LEADER, "true");
- bundle_del(b, AUL_SVC_K_REROUTE);
- bundle_add_str(b, AUL_SVC_K_REROUTE, "true");
- bundle_del(b, AUL_SVC_K_RECYCLE);
- bundle_add_str(b, AUL_SVC_K_RECYCLE, "true");
- }
-
- launch_mode = aul_svc_get_launch_mode(b);
- if (launch_mode && !strcmp(launch_mode, "group")) {
- ret = bundle_get_type(b, AUL_K_INSTANCE_ID);
- if (ret == BUNDLE_TYPE_NONE)
- aul_set_instance_info(*appid, b);
- }
-}
-
-static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
- aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
- void *data, uid_t uid, bool sync)
-{
- aul_svc_cb_info_t *cb_info = NULL;
- int ret = -1;
-
- __verify_request(b, &pkgname);
-
- if (cbfunc || err_cb) {
- SECURE_LOGD("pkg_name : %s - with result", pkgname);
-
- cb_info = __create_rescb(request_code, cbfunc, err_cb, data);
- if (sync) {
- ret = aul_launch_app_with_result_for_uid(pkgname, b,
- __aul_cb, cb_info, uid);
- } else {
- if (err_cb) {
- ret = aul_send_launch_request_for_uid(pkgname,
- b, uid,
- cbfunc ? __aul_cb : NULL,
- __aul_error_cb,
- cb_info);
- } else {
- ret = aul_launch_app_with_result_async_for_uid(
- pkgname, b, __aul_cb,
- cb_info, uid);
- }
- }
- } else {
- SECURE_LOGD("pkg_name : %s - no result", pkgname);
-
-#ifdef _APPFW_FEATURE_MULTI_INSTANCE
- const char* data = bundle_get_val(b, AUL_SVC_K_MULTI_INSTANCE);
- if (data)
- SECURE_LOGD("multi_instance value = %s", data);
-
- if (data && strncmp(data, "TRUE", strlen("TRUE")) == 0) {
- if (sync) {
- ret = aul_launch_app_for_multi_instance(pkgname,
- b);
- } else {
- ret = aul_launch_app_for_multi_instance_async(
- pkgname, b);
- }
- } else {
- if (sync)
- ret = aul_launch_app(pkgname, b);
- else
- ret = aul_launch_app_async(pkgname, b, uid);
- }
-#else
- if (sync)
- ret = aul_launch_app_for_uid(pkgname, b, uid);
- else
- ret = aul_launch_app_async_for_uid(pkgname, b, uid);
-#endif
- }
-
- if (ret < 0) {
- if (cb_info)
- __remove_rescb(cb_info);
- ret = __error_convert(ret);
- }
-
- return ret;
-}
-
-static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info)
-{
- char *tmp = NULL;
- char *saveptr = NULL;
- char *strtok_buf = NULL;
- int ret = -1;
-
- info->op = (char *)aul_svc_get_operation(b);
- info->uri = (char *)aul_svc_get_uri(b);
-
- if ((info->uri) && (strcmp(info->uri, "") == 0)) {
- _E("Uri is empty");
- return AUL_SVC_RET_EINVAL;
- }
-
- info->origin_mime = info->mime = (char *)aul_svc_get_mime(b);
- info->pkgname = (char *)aul_svc_get_pkgname(b);
- info->category = (char *)aul_svc_get_category(b);
- info->win_id = (char *)bundle_get_val(b, AUL_SVC_K_WIN_ID);
-
- SECURE_LOGD("getting resolve info for: operation - %s / uri - %s / mime - %s",
- info->op, info->uri, info->mime);
-
- if (info->uri) {
- if (strncmp(info->uri, "/", 1) == 0) {
- if (!info->mime) {
- info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
- if (info->mime == NULL) {
- _E("out of memory");
- return AUL_SVC_RET_ERROR;
- }
-
- ret = aul_get_mime_from_file(info->uri, info->mime, MAX_MIME_STR_SIZE);
- info->mime_set = 1;
- }
- info->uri = NULL;
- } else if (strncmp(info->uri, "file:///", 8) == 0) {
- if (!info->mime) {
- info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
- if (info->mime == NULL) {
- _E("out of memory");
- return AUL_SVC_RET_ERROR;
- }
-
- ret = aul_get_mime_from_file(&info->uri[7], info->mime, MAX_MIME_STR_SIZE);
- info->mime_set = 1;
- }
- } else if (strncmp(info->uri, "file:/", 6) == 0) {
- if (!info->mime) {
- info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
- if (info->mime == NULL) {
- _E("out of memory");
- return AUL_SVC_RET_ERROR;
- }
-
- ret = aul_get_mime_from_file(&info->uri[5], info->mime, MAX_MIME_STR_SIZE);
- info->mime_set = 1;
- }
- }
-
- if (info->mime_set == 1 && ret < 0) {
- _E("aul_get_mime_from_file : %d", ret);
- free(info->mime);
- info->origin_mime = info->mime = NULL;
- info->mime_set = 0;
- }
- }
-
- if (info->uri) {
- GRegex *regex;
- GMatchInfo *match_info;
- GError *error = NULL;
-
- regex = g_regex_new("^(([^:/?#]+):)?(//([^/?#]*))?", 0, 0, &error);
- if (g_regex_match(regex, info->uri, 0, &match_info) == FALSE) {
- g_regex_unref(regex);
- return AUL_SVC_RET_EINVAL;
- }
-
- info->scheme = g_match_info_fetch(match_info, 2);
- info->host = g_match_info_fetch(match_info, 4);
-
- if (info->scheme && info->host) {
- info->uri_r_info = malloc(MAX_SCHEME_STR_SIZE + MAX_HOST_STR_SIZE + 2);
- if (info->uri_r_info == NULL) {
- _E("out of memory");
- g_match_info_free(match_info);
- g_regex_unref(regex);
- return AUL_SVC_RET_ERROR;
- }
-
- snprintf(info->uri_r_info, MAX_SCHEME_STR_SIZE + MAX_HOST_STR_SIZE + 1,
- "%s://%s", info->scheme, info->host);
- }
-
- g_match_info_free(match_info);
- g_regex_unref(regex);
-
- } else {
- info->scheme = strdup("NULL");
- }
-
- if (!info->mime) {
- info->mime = strdup("NULL");
- return 0;
- }
-
- info->m_type = calloc(1, MAX_LOCAL_BUFSZ);
- if (info->m_type == NULL) {
- _E("ouf of memory");
- return AUL_SVC_RET_ERROR;
- }
-
- info->s_type = calloc(1, MAX_LOCAL_BUFSZ);
- if (info->s_type == NULL) {
- _E("out of memory");
- free(info->m_type);
- return AUL_SVC_RET_ERROR;
- }
-
- tmp = strdup(info->mime);
- if (tmp == NULL) {
- _E("out of memory");
- free(info->s_type);
- free(info->m_type);
- return AUL_SVC_RET_ERROR;
- }
-
- strtok_buf = strtok_r(tmp, "/", &saveptr);
- if (strtok_buf)
- strncpy(info->m_type, strtok_buf, MAX_LOCAL_BUFSZ - 1);
- strtok_buf = strtok_r(NULL, "/", &saveptr);
- if (strtok_buf)
- strncpy(info->s_type, strtok_buf, MAX_LOCAL_BUFSZ - 1);
- free(tmp);
-
- if (strncmp(info->m_type, "*", 1) == 0)
- strncpy(info->m_type, "%", MAX_LOCAL_BUFSZ - 1);
- if (strncmp(info->s_type, "*", 1) == 0)
- strncpy(info->s_type, "%", MAX_LOCAL_BUFSZ - 1);
-
- info->mime = malloc(MAX_MIME_STR_SIZE);
- if (info->mime == NULL) {
- _E("out of memory");
- free(info->s_type);
- free(info->m_type);
- return AUL_SVC_RET_ERROR;
- }
-
- snprintf(info->mime, MAX_MIME_STR_SIZE - 1,
- "%s/%s", info->m_type, info->s_type);
-
- return 0;
-}
-
-static int __free_resolve_info_data(aul_svc_resolve_info_t *info)
-{
- if (info->mime)
- free(info->mime);
- if (info->scheme)
- free(info->scheme);
- if (info->host)
- free(info->host);
- if (info->m_type)
- free(info->m_type);
- if (info->s_type)
- free(info->s_type);
- if (info->uri_r_info)
- free(info->uri_r_info);
- if (info->mime_set)
- free(info->origin_mime);
-
- return 0;
-}
-
-static char* __get_alias_appid(char *appid)
-{
- char *alias_id = NULL;
- const char *val = NULL;
- char key_string[MAX_PACKAGE_STR_SIZE + 5];
- dictionary *dic;
-
- dic = iniparser_load("/usr/share/appsvc/alias.ini");
-
- if (dic == NULL)
- return NULL;
-
- snprintf(key_string, sizeof(key_string), "Alias:%s", appid);
- pthread_mutex_lock(&iniparser_lock);
- val = iniparser_getstring(dic, key_string, NULL);
- pthread_mutex_unlock(&iniparser_lock);
-
- SECURE_LOGD("alias_id : %s", val);
-
- if (val != NULL) {
- alias_id = malloc(MAX_PACKAGE_STR_SIZE);
- if (alias_id == NULL) {
- _E("out of memory");
- iniparser_freedict(dic);
- return NULL;
- }
-
- strncpy(alias_id, val, MAX_PACKAGE_STR_SIZE - 1);
- }
-
- iniparser_freedict(dic);
-
- return alias_id;
-}
-
-API int aul_svc_set_operation(bundle *b, const char *operation)
-{
- if (b == NULL) {
- _E("bundle is NULL");
- return AUL_SVC_RET_EINVAL;
- }
-
- return __set_bundle(b, AUL_SVC_K_OPERATION, operation);
-}
-
-API int aul_svc_set_uri(bundle *b, const char *uri)
-{
- if (b == NULL) {
- _E("bundle is NULL");
- return AUL_SVC_RET_EINVAL;
- }
-
- return __set_bundle(b, AUL_SVC_K_URI, uri);
-}
-
-API int aul_svc_set_mime(bundle *b, const char *mime)
-{
- if (b == NULL) {
- _E("bundle is NULL");
- return AUL_SVC_RET_EINVAL;
- }
-
- return __set_bundle(b, AUL_SVC_K_MIME, mime);
-}
-
-API int aul_svc_add_data(bundle *b, const char *key, const char *val)
-{
- if (b == NULL || key == NULL)
- return AUL_SVC_RET_EINVAL;
-
- /* check key for data */
- /******************/
-
- return __set_bundle(b, key, val);
-}
-
-API int aul_svc_add_data_array(bundle *b, const char *key,
- const char **val_array, int len)
-{
- if (b == NULL || key == NULL)
- return AUL_SVC_RET_EINVAL;
-
- /* check key for data */
- /******************/
-
- return __set_bundle_array(b, key, val_array, len);
-}
-
-API int aul_svc_set_pkgname(bundle *b, const char *pkg_name)
-{
- if (b == NULL) {
- _E("bundle is NULL");
- return AUL_SVC_RET_EINVAL;
- }
-
- return __set_bundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
-}
-
-API int aul_svc_set_appid(bundle *b, const char *appid)
-{
- char *alias_id = NULL;
- int ret;
-
- if (b == NULL || appid == NULL) {
- _E("bundle is NULL");
- return AUL_SVC_RET_EINVAL;
- }
-
- alias_id = __get_alias_appid((char *)appid);
- if (alias_id == NULL) {
- ret = __set_bundle(b, AUL_SVC_K_PKG_NAME, appid);
- } else {
- ret = __set_bundle(b, AUL_SVC_K_PKG_NAME, alias_id);
- free(alias_id);
- alias_id = NULL;
- }
-
- return ret;
-}
-
-API int aul_svc_set_category(bundle *b, const char *category)
-{
- if (b == NULL) {
- _E("bundle is NULL");
- return AUL_SVC_RET_EINVAL;
- }
-
- return __set_bundle(b, AUL_SVC_K_CATEGORY, category);
-}
-
-API int aul_svc_set_launch_mode(bundle *b, const char *mode)
-{
- if (b == NULL) {
- _E("bundle is NULL");
- return AUL_SVC_RET_EINVAL;
- }
-
- return __set_bundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
-}
-
-API int aul_svc_resolve(bundle *b, uid_t uid, char ***appid_array,
- unsigned int *len)
-{
- return aul_svc_get_appid_array(b, uid, appid_array, len);
-}
-
-static int __get_appid(bundle *b, char **appid)
-{
- const char *operation;
- const char *pkgname;
- char *app_id;
-
- if (!b || !appid) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- operation = aul_svc_get_operation(b);
- pkgname = aul_svc_get_pkgname(b);
- if (!operation && !pkgname) {
- _E("Invalid request");
- return AUL_SVC_RET_EINVAL;
- }
-
- if (pkgname) {
- if (!operation)
- aul_svc_set_operation(b, AUL_SVC_OPERATION_DEFAULT);
-
- app_id = strdup(pkgname);
- } else {
- app_id = strdup("@UNKNOWN");
- }
-
- if (!app_id) {
- _E("Out of memory");
- return AUL_SVC_RET_ERROR;
- }
-
- *appid = app_id;
- return AUL_SVC_RET_OK;
-}
-
-static int __run_service(bundle *b, int request_code,
- aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
- void *data, uid_t uid, bool sync)
-{
- char *appid = NULL;
- int ret;
-
- ret = __get_appid(b, &appid);
- if (ret != AUL_SVC_RET_OK) {
- _E("Failed to get appid");
- return ret;
- }
-
- ret = __run_svc_with_pkgname(appid, b, request_code,
- cbfunc, err_cb, data, uid, sync);
- free(appid);
-
- return ret;
-}
-
-API int aul_svc_run_service(bundle *b, int request_code,
- aul_svc_res_fn cbfunc, void *data)
-{
- return __run_service(b, request_code, cbfunc, NULL, data,
- getuid(), true);
-}
-
-API int aul_svc_run_service_for_uid(bundle *b, int request_code,
- aul_svc_res_fn cbfunc, void *data, uid_t uid)
-{
- return __run_service(b, request_code, cbfunc, NULL, data, uid, true);
-}
-
-API int aul_svc_get_list(bundle *b, aul_svc_info_iter_fn iter_fn,
- void *data)
-{
- return aul_svc_get_list_for_uid(b, iter_fn, data, getuid());
-}
-
-API int aul_svc_get_list_for_uid(bundle *b, aul_svc_info_iter_fn iter_fn,
- void *data, uid_t uid)
-{
- char **appid_array = NULL;
- unsigned int len = 0;
- unsigned int i;
- int ret;
-
- if (!b || !iter_fn) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- ret = aul_svc_get_appid_array(b, uid, &appid_array, &len);
- if (ret != AUL_SVC_RET_OK)
- return ret;
-
- if (len == 0) {
- _E("Failed to find associated application");
- aul_svc_free_appid_array(appid_array, len);
- return AUL_SVC_RET_ENOMATCH;
- }
-
-
- for (i = 0; i < len; ++i) {
- SECURE_LOGD("APPID: %s", appid_array[i]);
- if (iter_fn(appid_array[i], data) != 0)
- break;
- }
-
- aul_svc_free_appid_array(appid_array, len);
-
- return AUL_SVC_RET_OK;
-}
-
-static int __send_and_receive(int cmd, bundle *request, bundle **response)
-{
- app_pkt_t *pkt = NULL;
- bundle *b = NULL;
- int ret;
- int fd;
-
- fd = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), cmd,
- request, AUL_SOCK_ASYNC);
- if (fd < 0)
- return AUL_SVC_RET_ERROR;
-
- ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0) {
- _E("Failed to recieve reply packet. error(%d)", ret);
- return AUL_SVC_RET_ERROR;
- }
-
- if (pkt->cmd != APP_GET_INFO_OK) {
- free(pkt);
- return AUL_SVC_RET_ERROR;
- }
-
- if (pkt->opt & AUL_SOCK_BUNDLE) {
- b = bundle_decode(pkt->data, pkt->len);
- if (!b) {
- _E("Failed to decode bundle");
- free(pkt);
- return AUL_SVC_RET_ENOMEM;
- }
- }
- free(pkt);
-
- if (!b) {
- _E("Invalid packet");
- return AUL_SVC_RET_ERROR;
- }
-
- *response = b;
-
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn, void *data)
-{
- return aul_svc_get_all_defapps_for_uid(iter_fn, data, getuid());
-}
-
-API int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
- void *data, uid_t uid)
-{
- const char **appid_list;
- int len = 0;
- bundle *request;
- bundle *response;
- int ret;
- int i;
-
- if (!iter_fn) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- request = bundle_create();
- if (!request) {
- _E("Out of memory");
- return AUL_SVC_RET_ENOMEM;
- }
-
- ret = __send_and_receive(APP_GET_APP_CONTROL_DEFAULT_APPS, request,
- &response);
- bundle_free(request);
- if (ret != AUL_SVC_RET_OK)
- return ret;
-
- appid_list = bundle_get_str_array(response, AUL_K_APPID_LIST, &len);
- if (!appid_list) {
- bundle_free(response);
- return AUL_SVC_RET_ERROR;
- }
-
- for (i = 0; i < len; ++i) {
- if (iter_fn(appid_list[i], data) != 0)
- break;
- }
- bundle_free(response);
-
- return AUL_SVC_RET_OK;
-}
-
-API const char *aul_svc_get_operation(bundle *b)
-{
- return bundle_get_val(b, AUL_SVC_K_OPERATION);
-}
-
-API const char *aul_svc_get_uri(bundle *b)
-{
- return bundle_get_val(b, AUL_SVC_K_URI);
-}
-
-API const char *aul_svc_get_mime(bundle *b)
-{
- return bundle_get_val(b, AUL_SVC_K_MIME);
-}
-
-API const char *aul_svc_get_data(bundle *b, const char *key)
-{
- return bundle_get_val(b, key);
-}
-
-API const char **aul_svc_get_data_array(bundle *b, const char *key, int *len)
-{
- return bundle_get_str_array(b, key, len);
-}
-
-API const char *aul_svc_get_pkgname(bundle *b)
-{
- return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
-}
-
-API const char *aul_svc_get_appid(bundle *b)
-{
- return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
-}
-
-API const char *aul_svc_get_category(bundle *b)
-{
- return bundle_get_val(b, AUL_SVC_K_CATEGORY);
-}
-
-API const char *aul_svc_get_launch_mode(bundle *b)
-{
- return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
-}
-
-API int aul_svc_create_result_bundle(bundle *inb, bundle **outb)
-{
- int ret = -1;
-
- if (inb == NULL || outb == NULL) {
- _E("bundle is NULL");
- return AUL_SVC_RET_EINVAL;
- }
-
- ret = aul_create_result_bundle(inb, outb);
-
- /* add additional bundle */
- /* bundle_add(outb, " ", " "); */
-
- if (ret == AUL_R_OK)
- ret = AUL_SVC_RET_OK;
- else if (ret == AUL_R_EINVAL)
- ret = AUL_SVC_RET_EINVAL;
- else if (ret == AUL_R_ECANCELED)
- ret = AUL_SVC_RET_ECANCELED;
- else
- ret = AUL_SVC_RET_ERROR;
-
- return ret;
-}
-
-API int aul_svc_send_result(bundle *b, aul_svc_result_val result)
-{
- int ret;
- char tmp[MAX_LOCAL_BUFSZ];
-
- if (b == NULL) {
- _E("aul_svc_send_result is NULL");
- return AUL_SVC_RET_EINVAL;
- }
-
- /* add result_code to bundle */
- snprintf(tmp, MAX_LOCAL_BUFSZ, "%d", (int)result);
- ret = __set_bundle(b, AUL_SVC_K_RES_VAL, tmp);
- if (ret < 0)
- return AUL_SVC_RET_ERROR;
-
- if (result == AUL_SVC_RES_CANCEL)
- ret = aul_send_result(b, 1);
- else
- ret = aul_send_result(b, 0);
-
- /* remove result_code from bundle */
- bundle_del(b, AUL_SVC_K_RES_VAL);
-
- return ret;
-}
-
-API int aul_svc_data_is_array(bundle *b, const char *key)
-{
- int type;
- type = bundle_get_type(b, key);
-
- if (type <= 0)
- return 0;
-
- if (type & BUNDLE_TYPE_ARRAY)
- return 1;
- return 0;
-}
-
-API int aul_svc_allow_transient_app(bundle *b, int wid)
-{
- char win_id[MAX_LOCAL_BUFSZ];
-
- snprintf(win_id, MAX_LOCAL_BUFSZ, "%d", wid);
-
- if (b == NULL) {
- _E("bundle is NULL");
- return AUL_SVC_RET_EINVAL;
- }
-
- return __set_bundle(b, AUL_SVC_K_WIN_ID, win_id);
-}
-
-API int aul_svc_request_transient_app(bundle *b, int callee_wid,
- aul_svc_host_res_fn cbfunc, void *data)
-{
- return 0;
-}
-
-API int aul_svc_subapp_terminate_request_pid(int pid)
-{
- int cpid = getpid();
- int lcnt;
- int *lpids = NULL;
- int i;
-
- aul_app_group_get_leader_pids(&lcnt, &lpids);
- for (i = 0; i < lcnt; i++) {
- if (lpids[i] == cpid) {
- int cnt;
- int *pids = NULL;
-
- aul_app_group_get_group_pids(cpid, &cnt, &pids);
-
- if (cnt == 0) {
- free(lpids);
- if (pids)
- free(pids);
-
- return aul_subapp_terminate_request_pid(pid);
- }
-
- if (pids != NULL)
- free(pids);
- break;
- }
- }
-
- if (lpids != NULL)
- free(lpids);
-
- return aul_app_group_clear_top();
-}
-
-API int aul_send_service_result(bundle *b)
-{
- return aul_send_result(b, 0);
-}
-
-API int aul_svc_subscribe_launch_result(bundle *b, const char *result)
-{
- if (b == NULL) {
- _E("bundle is NULL");
- return AUL_SVC_RET_EINVAL;
- }
-
- return __set_bundle(b, result, "1");
-}
-
-API int aul_svc_set_loader_id(bundle *b, int loader_id)
-{
- char tmp[MAX_LOCAL_BUFSZ];
-
- if (b == NULL) {
- _E("bundle is NULL");
- return AUL_SVC_RET_EINVAL;
- }
-
- if (loader_id <= 0) {
- _E("invalid loader id");
- return AUL_SVC_RET_EINVAL;
- }
-
- snprintf(tmp, sizeof(tmp), "%d", loader_id);
- return __set_bundle(b, AUL_K_LOADER_ID, tmp);
-}
-
-API int aul_svc_set_loader_name(bundle *b, const char *loader_name)
-{
- if (b == NULL) {
- _E("bundle is NULL");
- return AUL_SVC_RET_EINVAL;
- }
-
- if (!loader_name) {
- _E("invalid loader name");
- return AUL_SVC_RET_EINVAL;
- }
-
- return __set_bundle(b, AUL_K_LOADER_NAME, loader_name);
-}
-
-API int aul_svc_set_background_launch(bundle *b, int enabled)
-{
- if (b == NULL)
- return AUL_R_EINVAL;
-
- if (bundle_get_type(b, AUL_SVC_K_BG_LAUNCH) != BUNDLE_TYPE_NONE)
- bundle_del(b, AUL_SVC_K_BG_LAUNCH);
-
- if (enabled)
- bundle_add_str(b, AUL_SVC_K_BG_LAUNCH, "enable");
-
- return AUL_R_OK;
-}
-
-API int aul_svc_get_appid_by_alias_appid(const char *alias_appid, char **appid)
-{
- return aul_svc_get_appid_by_alias_appid_for_uid(alias_appid,
- appid, getuid());
-}
-
-API int aul_svc_get_appid_by_alias_appid_for_uid(const char *alias_appid,
- char **appid, uid_t uid)
-{
- const char *val;
- bundle *request;
- bundle *response;
- int ret;
-
- if (!alias_appid || !appid) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- request = bundle_create();
- if (!request) {
- _E("Out of memory");
- return AUL_SVC_RET_ENOMEM;
- }
-
- bundle_add(request, AUL_K_ALIAS_APPID, alias_appid);
- ret = __send_and_receive(APP_GET_APPID_BY_ALIAS_APPID, request,
- &response);
- bundle_free(request);
- if (ret != AUL_SVC_RET_OK)
- return ret;
-
- val = bundle_get_val(response, AUL_K_APPID);
- if (!val) {
- bundle_free(response);
- return AUL_SVC_RET_ERROR;
- }
-
- *appid = strdup(val);
- bundle_free(response);
- if (!*appid) {
- _E("Out of memory");
- return AUL_SVC_RET_ENOMEM;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-API const char *aul_svc_get_instance_id(bundle *b)
-{
- return bundle_get_val(b, AUL_K_INSTANCE_ID);
-}
-
-API int aul_svc_set_instance_id(bundle *b, const char *instance_id)
-{
- if (b == NULL || instance_id == NULL) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return __set_bundle(b, AUL_K_INSTANCE_ID, instance_id);
-}
-
-API int aul_svc_run_service_async(bundle *b, int request_code,
- aul_svc_res_fn cbfunc, void *data)
-{
- return __run_service(b, request_code, cbfunc, NULL, data,
- getuid(), false);
-}
-
-API int aul_svc_run_service_async_for_uid(bundle *b, int request_code,
- aul_svc_res_fn cbfunc, void *data, uid_t uid)
-{
- return __run_service(b, request_code, cbfunc, NULL, data, uid, false);
-}
-
-API int aul_svc_send_launch_request(bundle *b, int request_code,
- aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
- void *user_data)
-{
- return aul_svc_send_launch_request_for_uid(b, request_code,
- cbfunc, err_cb, user_data, getuid());
-}
-
-API int aul_svc_send_launch_request_for_uid(bundle *b, int request_code,
- aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb,
- void *user_data, uid_t uid)
-{
- return __run_service(b, request_code, cbfunc, err_cb, user_data,
- uid, false);
-}
-
-API int aul_svc_send_launch_request_sync_for_uid(bundle *b, int request_code,
- bundle **res_b, aul_svc_result_val *res, uid_t uid)
-{
- char *pkgname = NULL;
- const char *val;
- char *appid = NULL;
- int ret;
-
- ret = __get_appid(b, &appid);
- if (ret != AUL_SVC_RET_OK) {
- _E("Failed to find appid");
- return ret;
- }
-
- pkgname = appid;
- __verify_request(b, &pkgname);
-
- ret = aul_send_launch_request_sync_for_uid(pkgname, b, uid, res_b);
- if (ret > 0) {
- val = bundle_get_val(*res_b, AUL_SVC_K_RES_VAL);
- *res = (val == NULL) ? AUL_SVC_RES_NOT_OK : atoi(val);
- } else {
- ret = __error_convert(ret);
- *res = AUL_SVC_RES_CANCEL;
- }
- free(appid);
-
- return ret;
-}
-
-API int aul_svc_info_create(bundle *b, aul_svc_info_h *h)
-{
- aul_svc_resolve_info_t *info;
- int r;
-
- if (!b || !h) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- info = calloc(1, sizeof(aul_svc_resolve_info_t));
- if (!info) {
- _E("Out of memory");
- return AUL_SVC_RET_ERROR;
- }
-
- r = __get_resolve_info(b, info);
- if (r < 0) {
- _E("Failed to get resolving info");
- __free_resolve_info_data(info);
- free(info);
- return r;
- }
-
- *h = info;
-
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_info_get_operation(aul_svc_info_h h, char **operation)
-{
- aul_svc_resolve_info_t *info;
-
- if (!h || !operation) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- info = (aul_svc_resolve_info_t *)h;
- *operation = strdup(info->op ? info->op : "NULL");
- if (*operation == NULL) {
- _E("Failed to duplicate operation");
- return AUL_SVC_RET_ERROR;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_info_get_uri(aul_svc_info_h h, char **uri)
-{
- aul_svc_resolve_info_t *info;
-
- if (!h || !uri) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- info = (aul_svc_resolve_info_t *)h;
- *uri = strdup(info->uri ? info->uri : "NULL");
- if (*uri == NULL) {
- _E("Failed to duplicate URI");
- return AUL_SVC_RET_ERROR;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_info_get_uri_scheme(aul_svc_info_h h, char **uri_scheme)
-{
- aul_svc_resolve_info_t *info;
-
- if (!h || !uri_scheme) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- info = (aul_svc_resolve_info_t *)h;
- *uri_scheme = strdup(info->scheme ? info->scheme : "NULL");
- if (*uri_scheme == NULL) {
- _E("Failed to duplicate URI scheme");
- return AUL_SVC_RET_ERROR;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_info_get_uri_host(aul_svc_info_h h, char **uri_host)
-{
- aul_svc_resolve_info_t *info;
-
- if (!h || !uri_host) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- info = (aul_svc_resolve_info_t *)h;
- *uri_host = strdup(info->host ? info->host : "NULL");
- if (*uri_host == NULL) {
- _E("Failed to duplicate URI host");
- return AUL_SVC_RET_ERROR;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_info_get_mime(aul_svc_info_h h, char **mime)
-{
- aul_svc_resolve_info_t *info;
-
- if (!h || !mime) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- info = (aul_svc_resolve_info_t *)h;
- *mime = strdup(info->mime ? info->mime : "NULL");
- if (*mime == NULL) {
- _E("Failed to duplicate MIME-Type");
- return AUL_SVC_RET_ERROR;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_info_get_mime_type(aul_svc_info_h h, char **mime_type)
-{
- aul_svc_resolve_info_t *info;
-
- if (!h || !mime_type) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- info = (aul_svc_resolve_info_t *)h;
- *mime_type = strdup(info->m_type ? info->m_type : "NULL");
- if (*mime_type == NULL) {
- _E("Failed to duplicate the type of MIME-Type");
- return AUL_SVC_RET_ERROR;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_info_get_mime_subtype(aul_svc_info_h h, char **mime_subtype)
-{
- aul_svc_resolve_info_t *info;
-
- if (!h || !mime_subtype) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- info = (aul_svc_resolve_info_t *)h;
- *mime_subtype = strdup(info->s_type ? info->s_type : "NULL");
- if (*mime_subtype == NULL) {
- _E("Failed to duplicate the subtype of MIME-Type");
- return AUL_SVC_RET_ERROR;
- }
-
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_info_destroy(aul_svc_info_h h)
-{
- aul_svc_resolve_info_t *info;
-
- if (!h) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- info = (aul_svc_resolve_info_t *)h;
- __free_resolve_info_data(info);
- free(info);
-
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_set_caller_instance_id(bundle *b, const char *instance_id)
-{
- if (!b) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return __set_bundle(b, AUL_K_CALLER_INSTANCE_ID, instance_id);
-}
-
-API int aul_svc_set_comp_id(bundle *b, const char *comp_id)
-{
- if (!b) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- return __set_bundle(b, AUL_K_COMPONENT_ID, comp_id);
-}
-
-API const char *aul_svc_get_comp_id(bundle *b)
-{
- return bundle_get_val(b, AUL_K_COMPONENT_ID);
-}
-
-static void __foreach_group_info(aul_app_group_info_h info, void *data)
-{
- int *cnt = (int *)data;
-
- (*cnt)++;
-}
-
-API int aul_svc_subapp_terminate_request(bundle *b, int pid)
-{
- const char *caller_inst_id;
- const char *inst_id;
- char buf[512] = { 0, };
- int cnt = 0;
- int ret;
-
- if (!b || pid < 0) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- inst_id = bundle_get_val(b, AUL_K_INSTANCE_ID);
- if (!inst_id) {
- _E("Invalid request");
- return AUL_SVC_RET_EINVAL;
- }
-
- caller_inst_id = bundle_get_val(b, AUL_K_CALLER_INSTANCE_ID);
- if (!caller_inst_id) {
- ret = aul_app_get_instance_id_bypid(getpid(), buf, sizeof(buf));
- if (ret != AUL_R_OK) {
- _E("Failed to get caller instance ID");
- return AUL_SVC_RET_ERROR;
- }
- caller_inst_id = buf;
- }
-
- aul_app_group_foreach_group_info(caller_inst_id,
- __foreach_group_info, (void *)&cnt);
- if (cnt == 0)
- return aul_subapp_terminate_request(inst_id, pid);
-
- return aul_app_group_clear_top();
-}
-
-API int aul_svc_send_resume_request(bundle *b, int request_code,
- aul_svc_err_cb err_cb, void *user_data)
-{
- int ret;
-
- ret = aul_svc_send_resume_request_for_uid(b, request_code,
- err_cb, user_data, getuid());
- return ret;
-}
-
-API int aul_svc_send_resume_request_for_uid(bundle *b, int request_code,
- aul_svc_err_cb err_cb, void *user_data, uid_t uid)
-{
- aul_svc_cb_info_t *cb_info;
- char *appid = NULL;
- int ret;
-
- if (!b || !err_cb) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- ret = __get_appid(b, &appid);
- if (ret != AUL_SVC_RET_OK) {
- _E("Failed to get appid");
- return ret;
- }
-
- cb_info = __create_rescb(request_code, NULL, err_cb, user_data);
- ret = aul_send_resume_request_for_uid(appid, b, uid, __aul_error_cb,
- cb_info);
- if (ret < 0) {
- __remove_rescb(cb_info);
- ret = __error_convert(ret);
- }
- free(appid);
-
- return ret;
-}
-
-API int aul_svc_get_appid_array(bundle *b, uid_t uid, char ***appid_array,
- unsigned int *len)
-{
- bundle *res_b = NULL;
- app_pkt_t *pkt;
- const char *str;
- const char **str_arr;
- int arr_len = 0;
- int ret;
- int fd;
- int i;
-
- if (!b || !appid_array || !len) {
- _E("Invalid parameter");
- return AUL_SVC_RET_EINVAL;
- }
-
- str = bundle_get_val(b, AUL_K_APPID);
- if (str && !strcmp(str, "@UNKNOWN")) {
- *appid_array = calloc(1, sizeof(char *));
- (*appid_array)[0] = strdup(str);
- *len = 1;
- return AUL_SVC_RET_OK;
- }
-
- bundle_del(b, AUL_K_APPID);
- bundle_add(b, AUL_K_APPID, "@UNKNOWN");
-
- fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, APP_GET_APPID_LIST,
- b, AUL_SOCK_ASYNC);
- if (fd < 0)
- return __error_convert(aul_error_convert(fd));
-
- ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0)
- return __error_convert(aul_error_convert(ret));
-
- if (pkt->cmd != APP_GET_APPID_LIST) {
- ret = pkt->cmd;
- _E("Error(%d) occurs", ret);
- free(pkt);
- return __error_convert(aul_error_convert(ret));
- }
-
- if (pkt->opt & AUL_SOCK_BUNDLE)
- res_b = bundle_decode(pkt->data, pkt->len);
-
- free(pkt);
-
- if (!res_b) {
- _E("result bundle is nullptr");
- return AUL_SVC_RET_ERROR;
- }
-
- str = bundle_get_val(res_b, AUL_SVC_K_URI_R_INFO);
- if (str) {
- bundle_del(b, AUL_SVC_K_URI_R_INFO);
- bundle_add(b, AUL_SVC_K_URI_R_INFO, str);
- }
-
- str_arr = bundle_get_str_array(res_b, AUL_K_APPID_LIST, &arr_len);
- if (!str_arr) {
- _E("Failed to get appid list. str_arr(%p), arr_len(%d)",
- str_arr, arr_len);
- bundle_free(res_b);
- return AUL_SVC_RET_ERROR;
- }
-
- *appid_array = calloc(arr_len, sizeof(char *));
- if (*appid_array == NULL) {
- _E("Out of memory");
- bundle_free(res_b);
- return AUL_SVC_RET_ENOMEM;
- }
- *len = arr_len;
-
- for (i = 0; i < arr_len; ++i)
- (*appid_array)[i] = strdup(str_arr[i]);
-
- bundle_free(res_b);
-
- return AUL_SVC_RET_OK;
-}
-
-API void aul_svc_free_appid_array(char **appid_array, unsigned int len)
-{
- unsigned int i;
-
- if (!appid_array)
- return;
-
- for (i = 0; i < len; ++i)
- free(appid_array[i]);
-
- free(appid_array);
-}
-
-API int aul_svc_set_defapp(const char *op, const char *mime_type,
- const char *uri, const char *defapp)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_set_defapp_for_uid(const char *op, const char *mime_type,
- const char *uri, const char *defapp, uid_t uid)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_unset_defapp(const char *defapp)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_unset_defapp_for_uid(const char *defapp, uid_t uid)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_unset_all_defapps()
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_unset_all_defapps_for_uid(uid_t uid)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_is_defapp(const char *pkg_name)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_is_defapp_for_uid(const char *pkg_name, uid_t uid)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_set_alias_appid(const char *alias_appid, const char *appid)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_set_alias_appid_for_uid(const char *alias_appid,
- const char *appid, uid_t uid)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_unset_alias_appid(const char *alias_appid)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_unset_alias_appid_for_uid(const char *alias_appid, uid_t uid)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_foreach_alias_info(
- void (*callback)(const char *, const char *, void *),
- void *user_data)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_foreach_alias_info_for_uid(
- void (*callback)(const char *, const char *, void *),
- uid_t uid, void *user_data)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_enable_alias_info(const char *appid)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_enable_alias_info_for_uid(const char *appid, uid_t uid)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_disable_alias_info(const char *appid)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_disable_alias_info_for_uid(const char *appid, uid_t uid)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_foreach_alias_info_by_appid(
- int (*callback)(const char *, const char *, void *),
- const char *appid, void *user_data)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_foreach_alias_info_by_appid_for_uid(
- int (*callback)(const char *, const char *, void *),
- const char *appid, uid_t uid, void *user_data)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_foreach_allowed_info(
- int (*callback)(const char *, const char *, void *),
- void *user_data)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_foreach_allowed_info_for_uid(
- int (*callback)(const char *, const char *, void *),
- uid_t uid, void *user_data)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_foreach_allowed_info_by_appid(
- int (*callback)(const char *, const char *, void *),
- const char *appid, void *user_data)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_foreach_allowed_info_by_appid_for_uid(
- int (*callback)(const char *, const char *, void *),
- const char *appid, uid_t uid, void *user_data)
-{
- DEPRECATION_WARNING();
- return AUL_SVC_RET_OK;
-}
-