These APIs implement the functionality of app_launcher -f as an API.
Adds:
- aul_launch_app_fast()
- aul_launch_app_fast_for_uid()
Change-Id: I3b20918e9cec8fc4fa376e49adb2ca76a326bc1f
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/common AUL_COMMON_SRCS)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/component AUL_COMPONENT_SRCS)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/socket AUL_SOCKET_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/res_info AUL_RES_INFO_SRCS)
ADD_LIBRARY(${TARGET_AUL} SHARED
${SRCS}
${AUL_COMPONENT_SRCS}
${AUL_SOCKET_SRCS}
${AUL_BOOT_SEQUENCE_SRCS}
+ ${AUL_RES_INFO_SRCS}
)
TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL} PUBLIC
*/
int aul_terminate_pid_for_oom(pid_t pid);
+/**
+ * @brief Sends an application launch request before amd ready.
+ * @since_tizen 10.0
+ * @details This is fast version of aul_launch_app().
+ * This is functionally similar to the app_launcher -f option.
+ * @param[in] appid application name to be run as callee
+ * @param[in] kb bundle to be passed to callee
+ * @return callee's pid if success, negative value(<0) if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_EINVAL - invaild application name
+ * @retval AUL_R_ECOM - internal AUL IPC error
+ * @retval AUL_R_ERROR - general error
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_launch_app_fast(const char *appid, bundle *bundle);
+
+int aul_launch_app_fast_for_uid(const char *appid, bundle *bundle, uid_t uid);
+
#ifdef __cplusplus
}
#endif
#include <gio/gio.h>
#include <glib-unix.h>
#include <glib.h>
+#include <pkgmgr-info.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <filesystem>
#include <memory>
#include <string>
+#include <string_view>
#include <utility>
#include "aul/app_request.h"
#include "aul/aul_api.h"
#include "aul/aul_util.h"
#include "aul/include/aul.h"
+#include "aul/include/aul_svc.h"
#include "aul/include/aul_app_com.h"
#include "aul/include/aul_error.h"
#include "aul/include/aul_sock.h"
+#include "aul/res_info/res_info_manager.hh"
using namespace aul::internal;
const int kPadCmdKillLoader = 19;
const int kPadCmdRestartLoader = 20;
constexpr const int TEP_ISMOUNT_MAX_RETRY_CNT = 20;
+constexpr const char kAmdReadyPath[] = "/run/.amd_ready";
+constexpr const char kAppTypeUI[] = "uiapp";
+constexpr const char kAppTypeService[] = "svcapp";
class ResultInfo {
public:
return fd;
}
+template <typename T>
+void AddDataToBundle(const T& list, bundle* b, const char* key) {
+ bundle_del(b, key);
+ int length = list.size();
+ if (length == 0) return;
+
+ std::vector<const char*> paths(length);
+ int index = 0;
+ auto iter = list.begin();
+ while (iter != list.end()) {
+ paths[index++] = static_cast<const char*>(iter->c_str());
+ iter++;
+ }
+
+ bundle_add_str_array(b, key, paths.data(), length);
+}
+
+bool SetResInfo(const pkgmgrinfo_appinfo_h handle, uid_t uid, bundle* b) {
+ std::optional<aul::ResMountPackageInfo> info;
+ int ret =
+ aul::ResInfoManager::GetInst().GetMountPackageInfo(handle, uid, &info);
+ if (ret < 0) return -1;
+
+ if (!info) return 0;
+
+ AddDataToBundle(info->GetAllowedPaths(), b, AUL_K_MOUNT_ALLOWED_RES_DIR);
+ AddDataToBundle(info->GetGlobalPaths(), b, AUL_K_MOUNT_GLOBAL_RES_DIR);
+ AddDataToBundle(info->GetLibPaths(), b, AUL_K_MOUNT_LIB_DIR);
+ AddDataToBundle(info->GetGadgetPkgIds(), b, AUL_K_MOUNT_GADGET_PKGIDS);
+ AddDataToBundle(info->GetGadgetPaths(), b, AUL_K_MOUNT_GADGET_PATHS);
+ return 0;
+}
+
+static int GetGles(void)
+{
+ FILE *fp;
+ char buf[LINE_MAX];
+ char *tmp;
+ int gles = 1;
+
+ fp = fopen("/proc/cmdline", "r");
+ if (fp == nullptr)
+ return gles;
+
+ if (fgets(buf, sizeof(buf), fp) != nullptr) {
+ tmp = strstr(buf, "gles");
+ if (tmp != nullptr)
+ sscanf(tmp, "gles=%d", &gles);
+ }
+
+ fclose(fp);
+
+ return gles;
+}
+
+bool SetAppinfoForLaunchpad(bundle* kb, std::string_view appid, uid_t uid) {
+ char *pkgid = nullptr;
+ char *exec = nullptr;
+ char *apptype = nullptr;
+ char *pkgtype = nullptr;
+ char *component_type = nullptr;
+ char *root_path = nullptr;
+ char *api_version = nullptr;
+ pkgmgrinfo_app_hwacceleration hwacc = PMINFO_HWACCELERATION_OFF;
+ const char *hwacc_str = "NOT_USE";
+ bool process_pool = false;
+
+ if (kb == nullptr)
+ return false;
+
+ pkgmgrinfo_appinfo_h handle = nullptr;
+ int ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid.data(), uid, &handle);
+ if (ret != PMINFO_R_OK)
+ return false;
+
+ auto handle_auto =
+ std::unique_ptr<std::remove_pointer_t<pkgmgrinfo_appinfo_h>,
+ decltype(pkgmgrinfo_appinfo_destroy_appinfo)*>(
+ handle, pkgmgrinfo_appinfo_destroy_appinfo);
+ ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
+ if (ret != PMINFO_R_OK)
+ return false;
+
+ ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
+ if (ret != PMINFO_R_OK)
+ return false;
+
+ ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
+ if (ret != PMINFO_R_OK)
+ return false;
+
+ ret = pkgmgrinfo_appinfo_get_pkgtype(handle, &pkgtype);
+ if (ret != PMINFO_R_OK)
+ return false;
+
+ ret = pkgmgrinfo_appinfo_get_component_type(handle, &component_type);
+ if (ret != PMINFO_R_OK)
+ return false;
+
+ if (!component_type || (strcmp(component_type, kAppTypeService) != 0 &&
+ strcmp(component_type, kAppTypeUI) != 0)) {
+ ret = -1;
+ return false;
+ }
+
+ ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
+ if (ret != PMINFO_R_OK)
+ return false;
+
+ ret = pkgmgrinfo_appinfo_is_process_pool(handle, &process_pool);
+ if (ret != PMINFO_R_OK)
+ return false;
+
+ if (GetGles() && hwacc == PMINFO_HWACCELERATION_ON)
+ hwacc_str = "USE";
+ else if (hwacc == PMINFO_HWACCELERATION_OFF)
+ hwacc_str = "NOT_USE";
+ else
+ hwacc_str = "SYS";
+
+ ret = pkgmgrinfo_appinfo_get_root_path(handle, &root_path);
+ if (ret != PMINFO_R_OK)
+ return false;
+
+ ret = pkgmgrinfo_appinfo_get_api_version(handle, &api_version);
+ if (ret != PMINFO_R_OK)
+ return false;
+
+ bundle_add(kb, AUL_K_APPID, appid.data());
+ bundle_add(kb, AUL_K_HWACC, hwacc_str);
+ bundle_add(kb, AUL_K_EXEC, exec);
+ bundle_add(kb, AUL_K_APP_TYPE, apptype);
+ bundle_add(kb, AUL_K_PKGID, pkgid);
+ bundle_add(kb, AUL_K_INTERNAL_POOL, process_pool ? "true" : "false");
+ bundle_add(kb, AUL_K_COMP_TYPE, component_type);
+ bundle_add(kb, AUL_K_PACKAGETYPE, pkgtype);
+ bundle_add(kb, AUL_K_ROOT_PATH, root_path);
+ bundle_add(kb, AUL_K_API_VERSION, api_version);
+ bundle_add(kb, AUL_K_FAST_LAUNCH, "true");
+
+ aul_svc_set_loader_id(kb, PAD_LOADER_ID_DIRECT);
+ SetResInfo(handle, uid, kb);
+ return true;
+}
+
} // namespace
extern "C" int aul_is_initialized() {
.SetAppIdAsPid(pid)
.Send();
}
+
+extern "C" int aul_launch_app_fast(const char* appid, bundle* bundle) {
+ return aul_launch_app_fast_for_uid(appid, bundle, getuid());
+}
+
+extern "C" int aul_launch_app_fast_for_uid(const char *appid,
+ bundle* bundle, uid_t uid) {
+ if (appid == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (access(kAmdReadyPath, F_OK) == 0) {
+ bundle_del(bundle, AUL_K_FAST_LAUNCH);
+ return aul_launch_app_for_uid(appid, bundle, uid);
+ }
+
+ if (!SetAppinfoForLaunchpad(bundle, appid, uid)) {
+ _E("Failed to set appinfo. appid: %s, uid: %u", appid, uid);
+ return AUL_R_ERROR;
+ }
+
+ std::string socket_path = "/run/aul/daemons/" + std::to_string(uid) + "/" +
+ kLaunchpadProcessPoolSock;
+
+ int retry_count = 0;
+ while (access(socket_path.c_str(), F_OK) != 0) {
+ usleep(100 * 1000);
+ if (++retry_count > 100) {
+ _E("%s is not created. appid: %s, uid: %u", socket_path.c_str(), appid,
+ uid);
+ break;
+ }
+ }
+
+ int fd = aul_sock_create_launchpad_client_without_timeout(
+ kLaunchpadProcessPoolSock, uid);
+ if (fd < 0) {
+ _E("Failed to create client socket. appid: %s, error: %d", appid, fd);
+ return AUL_R_ERROR;
+ }
+
+ pid_t pid = aul_sock_send_bundle_with_fd(fd, 0, bundle, AUL_SOCK_NONE);
+ if (pid <= 0) {
+ _E("Failed to send request. appid: %s, error: %d", appid, pid);
+ return AUL_R_ERROR;
+ }
+
+ return pid;
+}
--- /dev/null
+/*
+ * Copyright (c) 2024 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 "allowed_pkg_info.hh"
+
+#include <utility>
+
+#include "common/log_private.hh"
+
+namespace aul {
+
+AllowedPkgInfo::AllowedPkgInfo(
+ std::string pkgid, std::unordered_set<std::string> required_privileges)
+ : pkgid_(std::move(pkgid)),
+ required_privileges_(std::move(required_privileges)) {}
+
+const std::string& AllowedPkgInfo::GetPkgId() const { return pkgid_; }
+
+const std::unordered_set<std::string>& AllowedPkgInfo::GetRequiredPrivileges()
+ const {
+ return required_privileges_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2024 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 TOOL_APP_LAUNCHER_ALLOWED_PKG_INFO_HH_
+#define TOOL_APP_LAUNCHER_ALLOWED_PKG_INFO_HH_
+
+#include <string>
+#include <unordered_set>
+
+namespace aul {
+
+class AllowedPkgInfo {
+ public:
+ AllowedPkgInfo(std::string pkgid,
+ std::unordered_set<std::string> required_privileges);
+
+ const std::string& GetPkgId() const;
+ const std::unordered_set<std::string>& GetRequiredPrivileges() const;
+
+ private:
+ std::string pkgid_;
+ std::unordered_set<std::string> required_privileges_;
+};
+
+} // namespace aul
+
+#endif // TOOL_APP_LAUNCHER_ALLOWED_PKG_INFO_HH_
--- /dev/null
+/*
+ * Copyright (c) 2024 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 "res_app_info.hh"
+
+#include <utility>
+
+#include "log_private.hh"
+
+namespace aul {
+
+ResAppInfo::Builder& ResAppInfo::Builder::SetAppId(
+ const pkgmgrinfo_appinfo_h handle) {
+ char* appid = nullptr;
+ if (pkgmgrinfo_appinfo_get_appid(handle, &appid) != PMINFO_R_OK)
+ _E("pkgmgrinfo_appinfo_Get_appid() is failed");
+ else
+ appid_ = appid;
+ return *this;
+}
+
+ResAppInfo::Builder& ResAppInfo::Builder::SetPkgId(
+ const pkgmgrinfo_appinfo_h handle) {
+ char* pkgid = nullptr;
+ if (pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid) != PMINFO_R_OK)
+ _E("pkgmgrinfo_appinfo_get_pkgid() is failed");
+ else
+ pkgid_ = pkgid;
+ return *this;
+}
+
+ResAppInfo::Builder& ResAppInfo::Builder::SetResControls(
+ const pkgmgrinfo_appinfo_h handle) {
+ int ret = pkgmgrinfo_appinfo_foreach_res_control(
+ handle,
+ [](const char* res_type, const char* min_version, const char* max_version,
+ const char* auto_close, void* user_data) {
+ if (!res_type) return 0;
+
+ auto* res_controls =
+ reinterpret_cast<std::vector<ResControl>*>(user_data);
+ res_controls->emplace_back(res_type, min_version ? min_version : "",
+ max_version ? max_version : "",
+ auto_close ? auto_close : "");
+ return 0;
+ },
+ &res_controls_);
+ if (ret != PMINFO_R_OK)
+ _E("pkgmgrinfo_appinfo_foreach_res_control() is failed");
+
+ return *this;
+}
+
+ResAppInfo::Builder& ResAppInfo::Builder::SetPrivileges(uid_t uid) {
+ pkgmgrinfo_pkginfo_h handle = nullptr;
+ int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid_.c_str(), uid, &handle);
+ if (ret != PMINFO_R_OK) {
+ _E("pkgmgrinfo_pkginfo_get_usr_pkginfo() is failed. pkgid=%s, uid=%u",
+ pkgid_.c_str(), uid);
+ }
+
+ ret = pkgmgrinfo_pkginfo_foreach_privilege(
+ handle,
+ [](const char* privilege_name, void* user_data) {
+ if (!privilege_name) return 0;
+
+ auto* privileges =
+ reinterpret_cast<std::unordered_set<std::string>*>(user_data);
+ privileges->insert(privilege_name);
+ return 0;
+ },
+ &privileges_);
+ if (ret != PMINFO_R_OK) {
+ _E("pkgmgrinfo_pkginfo_foreach_privilege() is failed. pkgid=%s",
+ pkgid_.c_str());
+ }
+
+ return *this;
+}
+
+ResAppInfo* ResAppInfo::Builder::Build() {
+ return new ResAppInfo(std::move(appid_), std::move(pkgid_),
+ std::move(res_controls_), std::move(privileges_));
+}
+
+ResAppInfo::ResAppInfo(std::string appid, std::string pkgid,
+ std::vector<ResControl> res_controls,
+ std::unordered_set<std::string> privileges)
+ : appid_(std::move(appid)),
+ pkgid_(std::move(pkgid)),
+ res_controls_(std::move(res_controls)),
+ privileges_(std::move(privileges)) {}
+
+std::shared_ptr<ResAppInfo> ResAppInfo::CreateResAppInfo(
+ const pkgmgrinfo_appinfo_h handle, uid_t uid) {
+ ResAppInfo::Builder builder;
+ return std::shared_ptr<ResAppInfo>(builder.SetAppId(handle)
+ .SetPkgId(handle)
+ .SetResControls(handle)
+ .SetPrivileges(uid)
+ .Build());
+}
+
+const std::string& ResAppInfo::GetAppId() const { return appid_; }
+
+const std::string& ResAppInfo::GetPkgId() const { return pkgid_; }
+
+const std::vector<ResControl>& ResAppInfo::GetResControls() const {
+ return res_controls_;
+}
+
+void ResAppInfo::UpdateResControls(
+ const std::vector<std::shared_ptr<ResPkgInfo>>& res_pkg_infos) {
+ for (const auto& res_pkg_info : res_pkg_infos)
+ UpdateResControl(res_pkg_info);
+}
+
+void ResAppInfo::UpdateResControl(std::shared_ptr<ResPkgInfo> res_pkg_info) {
+ int ret;
+ pkgmgrinfo_version_compare_type version_compare;
+ for (auto& res_control : res_controls_) {
+ if (res_control.res_type_ != res_pkg_info->GetResType()) continue;
+
+ if (!res_control.min_version_.empty()) {
+ ret = pkgmgrinfo_compare_package_version(
+ res_control.min_version_.c_str(),
+ res_pkg_info->GetResVersion().c_str(), &version_compare);
+ if (ret != PMINFO_R_OK) continue;
+
+ if (version_compare == PMINFO_VERSION_OLD) continue;
+ }
+
+ if (!res_control.max_version_.empty()) {
+ ret = pkgmgrinfo_compare_package_version(
+ res_pkg_info->GetResVersion().c_str(),
+ res_control.max_version_.c_str(), &version_compare);
+ if (ret != PMINFO_R_OK) continue;
+
+ if (version_compare == PMINFO_VERSION_OLD) continue;
+ }
+
+ if (!res_control.global_package_) {
+ res_control.global_package_ = res_pkg_info;
+ } else {
+ ret = pkgmgrinfo_compare_package_version(
+ res_control.global_package_->GetResVersion().c_str(),
+ res_pkg_info->GetResVersion().c_str(), &version_compare);
+ if (ret != PMINFO_R_OK) continue;
+
+ if (version_compare == PMINFO_VERSION_NEW)
+ res_control.global_package_ = res_pkg_info;
+ }
+
+ if (!res_pkg_info->CheckAllowedPackage(pkgid_, privileges_)) continue;
+
+ if (!res_control.allowed_package_) {
+ res_control.allowed_package_ = res_pkg_info;
+ } else {
+ ret = pkgmgrinfo_compare_package_version(
+ res_control.allowed_package_->GetResVersion().c_str(),
+ res_pkg_info->GetResVersion().c_str(), &version_compare);
+ if (ret != PMINFO_R_OK) continue;
+
+ if (version_compare == PMINFO_VERSION_NEW)
+ res_control.allowed_package_ = res_pkg_info;
+ }
+ }
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2024 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 TOOL_APP_LAUNCHER_RES_APP_INFO_HH_
+#define TOOL_APP_LAUNCHER_RES_APP_INFO_HH_
+
+#include <pkgmgr-info.h>
+
+#include <memory>
+#include <string>
+#include <unordered_set>
+#include <vector>
+
+#include "res_control.hh"
+#include "res_pkg_info.hh"
+
+namespace aul {
+
+class ResAppInfo {
+ public:
+ class Builder {
+ public:
+ Builder& SetAppId(const pkgmgrinfo_appinfo_h handle);
+ Builder& SetPkgId(const pkgmgrinfo_appinfo_h handle);
+ Builder& SetResControls(const pkgmgrinfo_appinfo_h handle);
+ Builder& SetPrivileges(uid_t uid);
+ ResAppInfo* Build();
+
+ private:
+ std::string appid_;
+ std::string pkgid_;
+ std::vector<ResControl> res_controls_;
+ std::unordered_set<std::string> privileges_;
+ };
+
+ ResAppInfo(std::string appid, std::string pkgid,
+ std::vector<ResControl> res_controls,
+ std::unordered_set<std::string> privileges);
+
+ static std::shared_ptr<ResAppInfo> CreateResAppInfo(
+ const pkgmgrinfo_appinfo_h handle, uid_t uid);
+
+ const std::string& GetAppId() const;
+ const std::string& GetPkgId() const;
+ const std::vector<ResControl>& GetResControls() const;
+
+ void UpdateResControls(
+ const std::vector<std::shared_ptr<ResPkgInfo>>& res_pkg_infos);
+
+ private:
+ void UpdateResControl(std::shared_ptr<ResPkgInfo> res_pkg_info);
+
+ private:
+ std::string appid_;
+ std::string pkgid_;
+ std::vector<ResControl> res_controls_;
+ std::unordered_set<std::string> privileges_;
+};
+
+} // namespace aul
+
+#endif // TOOL_APP_LAUNCHER_RES_APP_INFO_HH_
--- /dev/null
+/*
+ * Copyright (c) 2024 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 "res_control.hh"
+
+#include <utility>
+
+#include "log_private.hh"
+
+namespace aul {
+
+ResControl::ResControl(std::string res_type, std::string min_version,
+ std::string max_version, std::string auto_close)
+ : res_type_(std::move(res_type)),
+ min_version_(std::move(min_version)),
+ max_version_(std::move(max_version)),
+ auto_close_(std::move(auto_close)) {}
+
+const std::string& ResControl::GetResType() const { return res_type_; }
+
+const std::string& ResControl::GetMinVersion() const { return min_version_; }
+
+const std::string& ResControl::GetMaxVersion() const { return max_version_; }
+
+const std::string& ResControl::GetAutoClose() const { return auto_close_; }
+
+std::shared_ptr<ResPkgInfo> ResControl::GetAllowedPackage() const {
+ return allowed_package_;
+}
+
+std::shared_ptr<ResPkgInfo> ResControl::GetGlobalPackage() const {
+ return global_package_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2024 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 TOOL_APP_LAUNCHER_RES_CONTROL_HH_
+#define TOOL_APP_LAUNCHER_RES_CONTROL_HH_
+
+#include <memory>
+#include <string>
+
+#include "res_pkg_info.hh"
+
+namespace aul {
+
+class ResControl {
+ public:
+ ResControl(std::string res_type, std::string min_version,
+ std::string max_version, std::string auto_close);
+
+ const std::string& GetResType() const;
+ const std::string& GetMinVersion() const;
+ const std::string& GetMaxVersion() const;
+ const std::string& GetAutoClose() const;
+ std::shared_ptr<ResPkgInfo> GetAllowedPackage() const;
+ std::shared_ptr<ResPkgInfo> GetGlobalPackage() const;
+
+ private:
+ friend class ResAppInfo;
+
+ std::string res_type_;
+ std::string min_version_;
+ std::string max_version_;
+ std::string auto_close_;
+ std::shared_ptr<ResPkgInfo> allowed_package_ = nullptr;
+ std::shared_ptr<ResPkgInfo> global_package_ = nullptr;
+};
+
+} // namespace aul
+
+#endif // TOOL_APP_LAUNCHER_RES_CONTROL_HH_
--- /dev/null
+/*
+ * Copyright (c) 2024 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 "res_info.hh"
+
+#include <utility>
+
+#include "log_private.hh"
+
+namespace aul {
+
+ResInfo::ResInfo(uid_t uid) : uid_(uid) {}
+
+bool ResInfo::Init() {
+ pkgmgrinfo_pkginfo_filter_h filter = nullptr;
+ int ret = pkgmgrinfo_pkginfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK) {
+ _E("pkgmgrinfo_pkginfo_filter_create() is failed. error=%d", ret);
+ return false;
+ }
+
+ auto filter_auto =
+ std::unique_ptr<std::remove_pointer<pkgmgrinfo_pkginfo_filter_h>::type,
+ decltype(pkgmgrinfo_pkginfo_filter_destroy)*>(
+ filter, pkgmgrinfo_pkginfo_filter_destroy);
+
+ ret = pkgmgrinfo_pkginfo_filter_add_string(
+ filter, PMINFO_PKGINFO_PROP_PACKAGE_RES_TYPE, "");
+ if (ret != PMINFO_R_OK) {
+ _E("pkgmgrinfo_pkginfo_filter_add_string() is failed. error=%d", ret);
+ return false;
+ }
+
+ ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
+ filter,
+ [](const pkgmgrinfo_pkginfo_h handle, void* user_data) {
+ auto res_pkg_info = ResPkgInfo::CreateResPkgInfo(handle);
+ if (!res_pkg_info) return 0;
+
+ auto* res_info = reinterpret_cast<ResInfo*>(user_data);
+ res_info->InsertPkgInfo(std::move(res_pkg_info));
+ return 0;
+ },
+ this, uid_);
+ if (ret != PMINFO_R_OK) {
+ _E("pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo() is failed. error=%d",
+ ret);
+ return false;
+ }
+
+ return true;
+}
+
+void ResInfo::InsertPkgInfo(std::shared_ptr<ResPkgInfo> res_pkg_info) {
+ res_pkg_infos_.push_back(std::move(res_pkg_info));
+}
+
+const std::vector<std::shared_ptr<ResPkgInfo>>& ResInfo::GetResPkgs() const {
+ return res_pkg_infos_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2024 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 __RES_INFO_H__
+#define __RES_INFO_H__
+
+#include <bundle.h>
+#include <pkgmgr-info.h>
+#include <unistd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int _res_info_set(const pkgmgrinfo_appinfo_h handle, uid_t uid, bundle* b);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __RES_INFO_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2024 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 TOOL_APP_LAUNCHER_RES_INFO_HH_
+#define TOOL_APP_LAUNCHER_RES_INFO_HH_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "res_pkg_info.hh"
+
+namespace aul {
+
+class ResInfo {
+ public:
+ explicit ResInfo(uid_t uid);
+ bool Init();
+ void InsertPkgInfo(std::shared_ptr<ResPkgInfo> res_pkginfo);
+ const std::vector<std::shared_ptr<ResPkgInfo>>& GetResPkgs() const;
+
+ private:
+ uid_t uid_;
+ std::vector<std::shared_ptr<ResPkgInfo>> res_pkg_infos_;
+};
+
+} // namespace aul
+
+#endif // TOOL_APP_LAUNCHER_RES_INFO_HH_
--- /dev/null
+/*
+ * Copyright (c) 2024 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 "res_info_manager.hh"
+#include "res_info.h"
+
+#include <aul.h>
+#include <bundle.h>
+
+#include "log_private.hh"
+#include "res_app_info.hh"
+#include "res_info.hh"
+#include "res_mount_package_info.hh"
+
+namespace aul {
+
+ResInfoManager& ResInfoManager::GetInst() {
+ static ResInfoManager inst;
+ return inst;
+}
+
+int ResInfoManager::GetMountPackageInfo(
+ pkgmgrinfo_appinfo_h handle, uid_t uid,
+ std::optional<ResMountPackageInfo>* info) {
+ auto res_app_info = ResAppInfo::CreateResAppInfo(handle, uid);
+ if (!res_app_info) return -1;
+
+ if (res_app_info->GetResControls().empty())
+ return 0;
+
+ auto res_info = std::make_shared<ResInfo>(uid);
+ if (!res_info->Init()) {
+ _E("Failed to initialize res pkg info. uid=%u", uid);
+ return -1;
+ }
+
+ return ResMountPackageInfo::GetMountPackageInfo(
+ std::move(res_info), std::move(res_app_info), info);
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2024 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 TOOL_APP_LAUNCHER_RES_INFO_MANAGER_HH_
+#define TOOL_APP_LAUNCHER_RES_INFO_MANAGER_HH_
+
+#include <pkgmgr-info.h>
+
+#include <memory>
+#include <string>
+#include <unordered_map>
+
+#include "res_info.hh"
+#include "res_mount_package_info.hh"
+
+namespace aul {
+
+class ResInfoManager {
+ public:
+ static ResInfoManager& GetInst();
+
+ int GetMountPackageInfo(pkgmgrinfo_appinfo_h handle, uid_t uid,
+ std::optional<ResMountPackageInfo>* info);
+
+ private:
+ ResInfoManager() = default;
+ ~ResInfoManager() = default;
+};
+
+} // namespace aul
+
+#endif // TOOL_APP_LAUNCHER_RES_INFO_MANAGER_HH_
--- /dev/null
+/*
+ * Copyright (c) 2024 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 "res_mount_package_info.hh"
+
+#include <optional>
+#include <unordered_map>
+#include <utility>
+
+#include "log_private.hh"
+#include "res_info.hh"
+#include "res_info_manager.hh"
+#include "res_pkg_info.hh"
+
+namespace {
+
+constexpr const char ALLOWED_SUFFIX[] = "/res/allowed";
+constexpr const char GLOBAL_SUFFIX[] = "/res/global";
+constexpr const char kLibDir[] = "/lib";
+
+} // namespace
+
+namespace aul {
+
+ResMountPackageInfo::ResMountPackageInfo() {}
+
+ResMountPackageInfo::ResMountPackageInfo(
+ const std::vector<std::shared_ptr<ResPkgInfo>>& allowed_packages,
+ const std::vector<std::shared_ptr<ResPkgInfo>>& global_packages) {
+ for (const auto& pkg : allowed_packages) {
+ if (pkg->IsGadget()) {
+ gadget_pkgids_.insert(pkg->GetPkgId());
+ gadget_paths_.emplace_back(pkg->GetRootPath() + ALLOWED_SUFFIX + "/" +
+ pkg->GetResType());
+ }
+
+ if (pkg->IsLib()) lib_paths_.emplace_back(pkg->GetRootPath() + kLibDir);
+
+ allowed_paths_.emplace_back(pkg->GetRootPath() + ALLOWED_SUFFIX);
+ }
+
+ for (const auto& pkg : global_packages)
+ global_paths_.emplace_back(pkg->GetRootPath() + GLOBAL_SUFFIX);
+}
+
+int ResMountPackageInfo::GetMountPackageInfo(
+ std::shared_ptr<ResInfo> res_info, std::shared_ptr<ResAppInfo> res_app_info,
+ std::optional<ResMountPackageInfo>* info) {
+ res_app_info->UpdateResControls(res_info->GetResPkgs());
+ std::vector<std::shared_ptr<ResPkgInfo>> allowed_packages;
+ std::vector<std::shared_ptr<ResPkgInfo>> global_packages;
+ for (const auto& res_control : res_app_info->GetResControls()) {
+ auto allowed_package = res_control.GetAllowedPackage();
+ if (allowed_package) allowed_packages.push_back(std::move(allowed_package));
+
+ auto global_package = res_control.GetGlobalPackage();
+ if (global_package) global_packages.push_back(std::move(global_package));
+ }
+
+ *info = ResMountPackageInfo(allowed_packages, global_packages);
+ return 0;
+}
+
+const std::vector<std::string>& ResMountPackageInfo::GetAllowedPaths() const {
+ return allowed_paths_;
+}
+
+const std::vector<std::string>& ResMountPackageInfo::GetGlobalPaths() const {
+ return global_paths_;
+}
+
+const std::vector<std::string>& ResMountPackageInfo::GetLibPaths() const {
+ return lib_paths_;
+}
+
+const std::set<std::string>& ResMountPackageInfo::GetGadgetPkgIds() const {
+ return gadget_pkgids_;
+}
+
+const std::vector<std::string>& ResMountPackageInfo::GetGadgetPaths() const {
+ return gadget_paths_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2024 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 TOOL_APP_LAUNCHER_RES_MOUNT_PACKAGE_INFO_HH_
+#define TOOL_APP_LAUNCHER_RES_MOUNT_PACKAGE_INFO_HH_
+
+#include <memory>
+#include <optional>
+#include <set>
+#include <string>
+#include <vector>
+
+#include "res_app_info.hh"
+#include "res_info.hh"
+#include "res_pkg_info.hh"
+
+namespace aul {
+
+class ResMountPackageInfo {
+ public:
+ ResMountPackageInfo();
+ ResMountPackageInfo(
+ const std::vector<std::shared_ptr<ResPkgInfo>>& allowed_packages,
+ const std::vector<std::shared_ptr<ResPkgInfo>>& global_packages);
+
+ static int GetMountPackageInfo(std::shared_ptr<ResInfo> res_info,
+ std::shared_ptr<ResAppInfo> res_app_info,
+ std::optional<ResMountPackageInfo>* info);
+
+ const std::vector<std::string>& GetAllowedPaths() const;
+ const std::vector<std::string>& GetGlobalPaths() const;
+ const std::vector<std::string>& GetLibPaths() const;
+ const std::set<std::string>& GetGadgetPkgIds() const;
+ const std::vector<std::string>& GetGadgetPaths() const;
+
+ private:
+ std::vector<std::string> allowed_paths_;
+ std::vector<std::string> global_paths_;
+ std::vector<std::string> lib_paths_;
+ std::set<std::string> gadget_pkgids_;
+ std::vector<std::string> gadget_paths_;
+};
+
+} // namespace aul
+
+#endif // TOOL_APP_LAUNCHER_RES_MOUNT_PACKAGE_INFO_HH_
--- /dev/null
+/*
+ * Copyright (c) 2024 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 "res_pkg_info.hh"
+
+#include <fnmatch.h>
+
+#include <utility>
+
+#include "log_private.hh"
+
+namespace {
+
+constexpr const char kGadgetPrefix[] = "org.tizen.appfw.gadget.";
+
+} // namespace
+
+namespace aul {
+
+ResPkgInfo::Builder& ResPkgInfo::Builder::SetPkgId(
+ const pkgmgrinfo_pkginfo_h handle) {
+ char* pkgid = nullptr;
+ if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) != PMINFO_R_OK)
+ _E("pkgmgrinfo_pkginfo_get_pkgid() is failed");
+ else
+ pkgid_ = pkgid;
+ return *this;
+}
+
+ResPkgInfo::Builder& ResPkgInfo::Builder::SetResType(
+ const pkgmgrinfo_pkginfo_h handle) {
+ char* res_type = nullptr;
+ if (pkgmgrinfo_pkginfo_get_res_type(handle, &res_type) != PMINFO_R_OK)
+ _E("pkgmgrinfo_pkginfo_get_res_type() is failed");
+ else
+ res_type_ = res_type;
+ return *this;
+}
+
+ResPkgInfo::Builder& ResPkgInfo::Builder::SetResVersion(
+ const pkgmgrinfo_pkginfo_h handle) {
+ char* res_version = nullptr;
+ if (pkgmgrinfo_pkginfo_get_res_version(handle, &res_version) != PMINFO_R_OK)
+ _E("pkgmgrinfo_pkginfo_get_res_version() is failed");
+ else
+ res_version_ = res_version;
+ return *this;
+}
+
+ResPkgInfo::Builder& ResPkgInfo::Builder::SetRootPath(
+ const pkgmgrinfo_pkginfo_h handle) {
+ char* root_path = nullptr;
+ if (pkgmgrinfo_pkginfo_get_root_path(handle, &root_path) != PMINFO_R_OK)
+ _E("pkgmgrinfo_pkginfo_get_root_path() is failed");
+ else
+ root_path_ = root_path;
+ return *this;
+}
+
+ResPkgInfo::Builder& ResPkgInfo::Builder::SetIsLib(
+ const pkgmgrinfo_pkginfo_h handle) {
+ bool is_lib = false;
+ if (pkgmgrinfo_pkginfo_is_lib(handle, &is_lib) != PMINFO_R_OK)
+ _E("pkgmgrinfo_pkginfo_is_lib() is failed");
+ else
+ is_lib_ = is_lib;
+ return *this;
+}
+
+ResPkgInfo::Builder& ResPkgInfo::Builder::SetAllowedPkgInfos(
+ const pkgmgrinfo_pkginfo_h handle) {
+ if (pkgmgrinfo_pkginfo_foreach_res_allowed_package(
+ handle, ResAllowedPackageCb, this) != PMINFO_R_OK)
+ _E("pkgmgrinfo_pkginfo_foreach_res_allowed_package() is failed");
+
+ return *this;
+}
+
+ResPkgInfo* ResPkgInfo::Builder::Build() {
+ return new ResPkgInfo(std::move(pkgid_), std::move(res_type_),
+ std::move(res_version_), std::move(root_path_), is_lib_,
+ std::move(allowed_pkg_infos_));
+}
+
+int ResPkgInfo::Builder::ResAllowedPackageCb(const char* allowed_package,
+ required_privilege_h handle,
+ void* user_data) {
+ if (!allowed_package) return 0;
+
+ std::unordered_set<std::string> required_privileges;
+ int ret = pkgmgrinfo_pkginfo_foreach_required_privilege(
+ handle, [](const char* privilege_name, void* data) {
+ if (!privilege_name) return 0;
+
+ auto* privileges =
+ reinterpret_cast<std::unordered_set<std::string>*>(data);
+ privileges->insert(privilege_name);
+ return 0;
+ }, &required_privileges);
+ if (ret != PMINFO_R_OK)
+ return 0;
+
+ auto* builder = reinterpret_cast<ResPkgInfo::Builder*>(user_data);
+ builder->allowed_pkg_infos_.push_back(
+ AllowedPkgInfo(allowed_package, std::move(required_privileges)));
+ return 0;
+}
+
+ResPkgInfo::ResPkgInfo(std::string pkgid, std::string res_type,
+ std::string res_version, std::string root_path,
+ bool is_lib,
+ std::vector<AllowedPkgInfo> allowed_pkg_infos)
+ : pkgid_(std::move(pkgid)),
+ res_type_(std::move(res_type)),
+ res_version_(std::move(res_version)),
+ root_path_(std::move(root_path)),
+ is_lib_(is_lib),
+ allowed_pkg_infos_(std::move(allowed_pkg_infos)) {}
+
+std::shared_ptr<ResPkgInfo> ResPkgInfo::CreateResPkgInfo(
+ const pkgmgrinfo_pkginfo_h handle) {
+ ResPkgInfo::Builder builder;
+ return std::shared_ptr<ResPkgInfo>(builder.SetPkgId(handle)
+ .SetResType(handle)
+ .SetResVersion(handle)
+ .SetRootPath(handle)
+ .SetIsLib(handle)
+ .SetAllowedPkgInfos(handle)
+ .Build());
+}
+
+const std::string& ResPkgInfo::GetPkgId() const { return pkgid_; }
+
+const std::string& ResPkgInfo::GetResType() const { return res_type_; }
+
+const std::string& ResPkgInfo::GetResVersion() const { return res_version_; }
+
+const std::string& ResPkgInfo::GetRootPath() const { return root_path_; }
+
+bool ResPkgInfo::IsLib() const { return is_lib_; }
+
+bool ResPkgInfo::IsGadget() const {
+ return (res_type_.length() > strlen(kGadgetPrefix) &&
+ !res_type_.compare(0, strlen(kGadgetPrefix), kGadgetPrefix));
+}
+
+bool ResPkgInfo::CheckAllowedPackage(
+ const std::string& pkgid,
+ const std::unordered_set<std::string>& privileges) const {
+ for (const auto& info : allowed_pkg_infos_) {
+ if (fnmatch(info.GetPkgId().c_str(), pkgid.c_str(), FNM_NOESCAPE)) continue;
+
+ bool has_required_privileges = true;
+ for (const auto& required_privilege : info.GetRequiredPrivileges()) {
+ if (!privileges.count(required_privilege)) {
+ has_required_privileges = false;
+ break;
+ }
+ }
+
+ if (has_required_privileges) return true;
+ }
+
+ return false;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2024 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 TOOL_APP_LAUNCHER_RES_PKG_INFO_HH_
+#define TOOL_APP_LAUNCHER_RES_PKG_INFO_HH_
+
+#include <pkgmgr-info.h>
+
+#include <memory>
+#include <string>
+#include <unordered_set>
+#include <vector>
+
+#include "allowed_pkg_info.hh"
+
+namespace aul {
+
+class ResPkgInfo {
+ public:
+ class Builder {
+ public:
+ Builder& SetPkgId(const pkgmgrinfo_pkginfo_h handle);
+ Builder& SetResType(const pkgmgrinfo_pkginfo_h handle);
+ Builder& SetResVersion(const pkgmgrinfo_pkginfo_h handle);
+ Builder& SetRootPath(const pkgmgrinfo_pkginfo_h handle);
+ Builder& SetIsLib(const pkgmgrinfo_pkginfo_h handle);
+ Builder& SetAllowedPkgInfos(const pkgmgrinfo_pkginfo_h handle);
+ ResPkgInfo* Build();
+
+ private:
+ static int ResAllowedPackageCb(const char* allowed_package,
+ required_privilege_h handle,
+ void* user_data);
+
+ private:
+ std::string pkgid_;
+ std::string res_type_;
+ std::string res_version_;
+ std::string root_path_;
+ bool is_lib_ = false;
+ std::vector<AllowedPkgInfo> allowed_pkg_infos_;
+ };
+
+ ResPkgInfo(std::string pkgid, std::string res_type, std::string res_version,
+ std::string root_path, bool is_lib,
+ std::vector<AllowedPkgInfo> allowed_pkg_infos);
+
+ static std::shared_ptr<ResPkgInfo> CreateResPkgInfo(
+ const pkgmgrinfo_pkginfo_h handle);
+
+ const std::string& GetPkgId() const;
+ const std::string& GetResType() const;
+ const std::string& GetResVersion() const;
+ const std::string& GetRootPath() const;
+ bool IsLib() const;
+ bool IsGadget() const;
+ bool CheckAllowedPackage(
+ const std::string& pkgid,
+ const std::unordered_set<std::string>& privileges) const;
+
+ private:
+ std::string pkgid_;
+ std::string res_type_;
+ std::string res_version_;
+ std::string root_path_;
+ bool is_lib_;
+ std::vector<AllowedPkgInfo> allowed_pkg_infos_;
+};
+
+} // namespace aul
+
+#endif // TOOL_APP_LAUNCHER_RES_PKG_INFO_HH_
SET(TARGET_APP_LAUNCHER "app_launcher")
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_LAUNCHER_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../aul/res_info AUL_RES_INFO_SRCS)
-ADD_EXECUTABLE(${TARGET_APP_LAUNCHER} ${APP_LAUNCHER_SRCS})
+ADD_EXECUTABLE(${TARGET_APP_LAUNCHER} ${APP_LAUNCHER_SRCS} ${AUL_RES_INFO_SRCS})
IF(_TIZEN_FEATURE_PRELINK)
MESSAGE(STATUS "[__PRELINK__] Enable")
${CMAKE_CURRENT_SOURCE_DIR}/../
${CMAKE_CURRENT_SOURCE_DIR}/../aul
${CMAKE_CURRENT_SOURCE_DIR}/../aul/include
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../aul/res_info
)
INSTALL(TARGETS ${TARGET_APP_LAUNCHER} DESTINATION bin)
+++ /dev/null
-/*
- * Copyright (c) 2024 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 "app_launcher/allowed_pkg_info.hh"
-
-#include <utility>
-
-#include "app_launcher/log_private.hh"
-
-namespace aul {
-
-AllowedPkgInfo::AllowedPkgInfo(
- std::string pkgid, std::unordered_set<std::string> required_privileges)
- : pkgid_(std::move(pkgid)),
- required_privileges_(std::move(required_privileges)) {}
-
-const std::string& AllowedPkgInfo::GetPkgId() const { return pkgid_; }
-
-const std::unordered_set<std::string>& AllowedPkgInfo::GetRequiredPrivileges()
- const {
- return required_privileges_;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2024 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 TOOL_APP_LAUNCHER_ALLOWED_PKG_INFO_HH_
-#define TOOL_APP_LAUNCHER_ALLOWED_PKG_INFO_HH_
-
-#include <string>
-#include <unordered_set>
-
-namespace aul {
-
-class AllowedPkgInfo {
- public:
- AllowedPkgInfo(std::string pkgid,
- std::unordered_set<std::string> required_privileges);
-
- const std::string& GetPkgId() const;
- const std::unordered_set<std::string>& GetRequiredPrivileges() const;
-
- private:
- std::string pkgid_;
- std::unordered_set<std::string> required_privileges_;
-};
-
-} // namespace aul
-
-#endif // TOOL_APP_LAUNCHER_ALLOWED_PKG_INFO_HH_
#include "launch.h"
#include "res_info.h"
-#define LAUNCHPAD_PROCESS_POOL_SOCK ".launchpad-process-pool-sock"
-#define PATH_AUL_DAEMONS "/run/aul/daemons"
-#define PATH_AMD_READY "/run/.amd_ready"
-#define APP_TYPE_UI "uiapp"
-#define APP_TYPE_SERVICE "svcapp"
-#define INOTIFY_BUF (1024 * ((sizeof(struct inotify_event)) + 16))
-
#ifndef PR_TASK_PERF_USER_TRACE
#define PR_TASK_PERF_USER_TRACE 666
#endif
return 0;
}
-static int __get_gles(void)
-{
- FILE *fp;
- char buf[LINE_MAX];
- char *tmp;
- int gles = 1;
-
- fp = fopen("/proc/cmdline", "r");
- if (fp == NULL)
- return gles;
-
- if (fgets(buf, sizeof(buf), fp) != NULL) {
- tmp = strstr(buf, "gles");
- if (tmp != NULL)
- sscanf(tmp, "gles=%d", &gles);
- }
-
- fclose(fp);
-
- return gles;
-}
-
-static int __set_appinfo_for_launchpad(bundle *kb, const char *appid, uid_t uid)
-{
- pkgmgrinfo_appinfo_h handle;
- int ret;
- char *pkgid = NULL;
- char *exec = NULL;
- char *apptype = NULL;
- char *pkgtype = NULL;
- char *component_type = NULL;
- char *root_path = NULL;
- char *api_version = NULL;
- pkgmgrinfo_app_hwacceleration hwacc = PMINFO_HWACCELERATION_OFF;
- const char *hwacc_str = "NOT_USE";
- bool process_pool = false;
-
- if (kb == NULL)
- return -1;
-
- ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &handle);
- if (ret != PMINFO_R_OK)
- return -1;
-
- ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_get_pkgtype(handle, &pkgtype);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_get_component_type(handle, &component_type);
- if (ret != PMINFO_R_OK)
- goto end;
-
- if (!component_type || (strcmp(component_type, APP_TYPE_SERVICE) != 0 &&
- strcmp(component_type, APP_TYPE_UI) != 0)) {
- ret = -1;
- goto end;
- }
-
- ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_is_process_pool(handle, &process_pool);
- if (ret != PMINFO_R_OK)
- goto end;
-
- if (__get_gles() && hwacc == PMINFO_HWACCELERATION_ON)
- hwacc_str = "USE";
- else if (hwacc == PMINFO_HWACCELERATION_OFF)
- hwacc_str = "NOT_USE";
- else
- hwacc_str = "SYS";
-
- ret = pkgmgrinfo_appinfo_get_root_path(handle, &root_path);
- if (ret != PMINFO_R_OK)
- goto end;
-
- ret = pkgmgrinfo_appinfo_get_api_version(handle, &api_version);
- if (ret != PMINFO_R_OK)
- goto end;
-
- bundle_add(kb, AUL_K_APPID, appid);
- bundle_add(kb, AUL_K_HWACC, hwacc_str);
- bundle_add(kb, AUL_K_EXEC, exec);
- bundle_add(kb, AUL_K_APP_TYPE, apptype);
- bundle_add(kb, AUL_K_PKGID, pkgid);
- bundle_add(kb, AUL_K_INTERNAL_POOL, process_pool ? "true" : "false");
- bundle_add(kb, AUL_K_COMP_TYPE, component_type);
- bundle_add(kb, AUL_K_PACKAGETYPE, pkgtype);
- bundle_add(kb, AUL_K_ROOT_PATH, root_path);
- bundle_add(kb, AUL_K_API_VERSION, api_version);
- bundle_add(kb, AUL_K_FAST_LAUNCH, "true");
-
- aul_svc_set_loader_id(kb, PAD_LOADER_ID_DIRECT);
- _res_info_set(handle, uid, kb);
-
-end:
- pkgmgrinfo_appinfo_destroy_appinfo(handle);
-
- return ret;
-}
-
static int __cmd_fast_start_init(struct launch_arg *arg)
{
- char buf[PATH_MAX];
- int retry_count = 0;
-
- if (!access(PATH_AMD_READY, F_OK)) {
- arg->amd_ready = true;
- return 0;
- }
-
- if (__set_appinfo_for_launchpad(arg->b, arg->appid, arg->uid) < 0) {
- fprintf(stderr, "Failed to set appinfo. appid(%s), uid(%u)\n",
- arg->appid, arg->uid);
- return -1;
- }
-
- snprintf(buf, sizeof(buf), "/run/aul/daemons/%u/%s",
- arg->uid, LAUNCHPAD_PROCESS_POOL_SOCK);
- while (access(buf, F_OK) != 0) {
- usleep(100 * 1000);
- if (++retry_count > 100) {
- fprintf(stderr, "%s is not created\n", buf);
- break;
- }
- }
-
return 0;
}
static int __cmd_fast_start_run(struct launch_arg *arg)
{
- int fd;
-
- if (arg->amd_ready) {
- bundle_del(arg->b, AUL_K_FAST_LAUNCH);
- return __cmd_start_run(arg);
- }
-
- fd = aul_sock_create_launchpad_client_without_timeout(
- LAUNCHPAD_PROCESS_POOL_SOCK, arg->uid);
- if (fd < 0) {
- fprintf(stderr, "Failed to create client socket. error: %d\n",
- fd);
- return -1;
- }
-
- arg->pid = aul_sock_send_bundle_with_fd(fd, 0, arg->b, AUL_SOCK_NONE);
+ arg->pid = aul_launch_app_fast_for_uid(arg->appid, arg->b, arg->uid);
if (arg->pid <= 0) {
fprintf(stderr, "... launch failed\n");
return -1;
+++ /dev/null
-/*
- * Copyright (c) 2024 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 "app_launcher/res_app_info.hh"
-
-#include <utility>
-
-#include "app_launcher/log_private.hh"
-
-namespace aul {
-
-ResAppInfo::Builder& ResAppInfo::Builder::SetAppId(
- const pkgmgrinfo_appinfo_h handle) {
- char* appid = nullptr;
- if (pkgmgrinfo_appinfo_get_appid(handle, &appid) != PMINFO_R_OK)
- _E("pkgmgrinfo_appinfo_Get_appid() is failed");
- else
- appid_ = appid;
- return *this;
-}
-
-ResAppInfo::Builder& ResAppInfo::Builder::SetPkgId(
- const pkgmgrinfo_appinfo_h handle) {
- char* pkgid = nullptr;
- if (pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid) != PMINFO_R_OK)
- _E("pkgmgrinfo_appinfo_get_pkgid() is failed");
- else
- pkgid_ = pkgid;
- return *this;
-}
-
-ResAppInfo::Builder& ResAppInfo::Builder::SetResControls(
- const pkgmgrinfo_appinfo_h handle) {
- int ret = pkgmgrinfo_appinfo_foreach_res_control(
- handle,
- [](const char* res_type, const char* min_version, const char* max_version,
- const char* auto_close, void* user_data) {
- if (!res_type) return 0;
-
- auto* res_controls =
- reinterpret_cast<std::vector<ResControl>*>(user_data);
- res_controls->emplace_back(res_type, min_version ? min_version : "",
- max_version ? max_version : "",
- auto_close ? auto_close : "");
- return 0;
- },
- &res_controls_);
- if (ret != PMINFO_R_OK)
- _E("pkgmgrinfo_appinfo_foreach_res_control() is failed");
-
- return *this;
-}
-
-ResAppInfo::Builder& ResAppInfo::Builder::SetPrivileges(uid_t uid) {
- pkgmgrinfo_pkginfo_h handle = nullptr;
- int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid_.c_str(), uid, &handle);
- if (ret != PMINFO_R_OK) {
- _E("pkgmgrinfo_pkginfo_get_usr_pkginfo() is failed. pkgid=%s, uid=%u",
- pkgid_.c_str(), uid);
- }
-
- ret = pkgmgrinfo_pkginfo_foreach_privilege(
- handle,
- [](const char* privilege_name, void* user_data) {
- if (!privilege_name) return 0;
-
- auto* privileges =
- reinterpret_cast<std::unordered_set<std::string>*>(user_data);
- privileges->insert(privilege_name);
- return 0;
- },
- &privileges_);
- if (ret != PMINFO_R_OK) {
- _E("pkgmgrinfo_pkginfo_foreach_privilege() is failed. pkgid=%s",
- pkgid_.c_str());
- }
-
- return *this;
-}
-
-ResAppInfo* ResAppInfo::Builder::Build() {
- return new ResAppInfo(std::move(appid_), std::move(pkgid_),
- std::move(res_controls_), std::move(privileges_));
-}
-
-ResAppInfo::ResAppInfo(std::string appid, std::string pkgid,
- std::vector<ResControl> res_controls,
- std::unordered_set<std::string> privileges)
- : appid_(std::move(appid)),
- pkgid_(std::move(pkgid)),
- res_controls_(std::move(res_controls)),
- privileges_(std::move(privileges)) {}
-
-std::shared_ptr<ResAppInfo> ResAppInfo::CreateResAppInfo(
- const pkgmgrinfo_appinfo_h handle, uid_t uid) {
- ResAppInfo::Builder builder;
- return std::shared_ptr<ResAppInfo>(builder.SetAppId(handle)
- .SetPkgId(handle)
- .SetResControls(handle)
- .SetPrivileges(uid)
- .Build());
-}
-
-const std::string& ResAppInfo::GetAppId() const { return appid_; }
-
-const std::string& ResAppInfo::GetPkgId() const { return pkgid_; }
-
-const std::vector<ResControl>& ResAppInfo::GetResControls() const {
- return res_controls_;
-}
-
-void ResAppInfo::UpdateResControls(
- const std::vector<std::shared_ptr<ResPkgInfo>>& res_pkg_infos) {
- for (const auto& res_pkg_info : res_pkg_infos)
- UpdateResControl(res_pkg_info);
-}
-
-void ResAppInfo::UpdateResControl(std::shared_ptr<ResPkgInfo> res_pkg_info) {
- int ret;
- pkgmgrinfo_version_compare_type version_compare;
- for (auto& res_control : res_controls_) {
- if (res_control.res_type_ != res_pkg_info->GetResType()) continue;
-
- if (!res_control.min_version_.empty()) {
- ret = pkgmgrinfo_compare_package_version(
- res_control.min_version_.c_str(),
- res_pkg_info->GetResVersion().c_str(), &version_compare);
- if (ret != PMINFO_R_OK) continue;
-
- if (version_compare == PMINFO_VERSION_OLD) continue;
- }
-
- if (!res_control.max_version_.empty()) {
- ret = pkgmgrinfo_compare_package_version(
- res_pkg_info->GetResVersion().c_str(),
- res_control.max_version_.c_str(), &version_compare);
- if (ret != PMINFO_R_OK) continue;
-
- if (version_compare == PMINFO_VERSION_OLD) continue;
- }
-
- if (!res_control.global_package_) {
- res_control.global_package_ = res_pkg_info;
- } else {
- ret = pkgmgrinfo_compare_package_version(
- res_control.global_package_->GetResVersion().c_str(),
- res_pkg_info->GetResVersion().c_str(), &version_compare);
- if (ret != PMINFO_R_OK) continue;
-
- if (version_compare == PMINFO_VERSION_NEW)
- res_control.global_package_ = res_pkg_info;
- }
-
- if (!res_pkg_info->CheckAllowedPackage(pkgid_, privileges_)) continue;
-
- if (!res_control.allowed_package_) {
- res_control.allowed_package_ = res_pkg_info;
- } else {
- ret = pkgmgrinfo_compare_package_version(
- res_control.allowed_package_->GetResVersion().c_str(),
- res_pkg_info->GetResVersion().c_str(), &version_compare);
- if (ret != PMINFO_R_OK) continue;
-
- if (version_compare == PMINFO_VERSION_NEW)
- res_control.allowed_package_ = res_pkg_info;
- }
- }
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2024 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 TOOL_APP_LAUNCHER_RES_APP_INFO_HH_
-#define TOOL_APP_LAUNCHER_RES_APP_INFO_HH_
-
-#include <pkgmgr-info.h>
-
-#include <memory>
-#include <string>
-#include <unordered_set>
-#include <vector>
-
-#include "app_launcher/res_control.hh"
-#include "app_launcher/res_pkg_info.hh"
-
-namespace aul {
-
-class ResAppInfo {
- public:
- class Builder {
- public:
- Builder& SetAppId(const pkgmgrinfo_appinfo_h handle);
- Builder& SetPkgId(const pkgmgrinfo_appinfo_h handle);
- Builder& SetResControls(const pkgmgrinfo_appinfo_h handle);
- Builder& SetPrivileges(uid_t uid);
- ResAppInfo* Build();
-
- private:
- std::string appid_;
- std::string pkgid_;
- std::vector<ResControl> res_controls_;
- std::unordered_set<std::string> privileges_;
- };
-
- ResAppInfo(std::string appid, std::string pkgid,
- std::vector<ResControl> res_controls,
- std::unordered_set<std::string> privileges);
-
- static std::shared_ptr<ResAppInfo> CreateResAppInfo(
- const pkgmgrinfo_appinfo_h handle, uid_t uid);
-
- const std::string& GetAppId() const;
- const std::string& GetPkgId() const;
- const std::vector<ResControl>& GetResControls() const;
-
- void UpdateResControls(
- const std::vector<std::shared_ptr<ResPkgInfo>>& res_pkg_infos);
-
- private:
- void UpdateResControl(std::shared_ptr<ResPkgInfo> res_pkg_info);
-
- private:
- std::string appid_;
- std::string pkgid_;
- std::vector<ResControl> res_controls_;
- std::unordered_set<std::string> privileges_;
-};
-
-} // namespace aul
-
-#endif // TOOL_APP_LAUNCHER_RES_APP_INFO_HH_
+++ /dev/null
-/*
- * Copyright (c) 2024 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 "app_launcher/res_control.hh"
-
-#include <utility>
-
-#include "app_launcher/log_private.hh"
-
-namespace aul {
-
-ResControl::ResControl(std::string res_type, std::string min_version,
- std::string max_version, std::string auto_close)
- : res_type_(std::move(res_type)),
- min_version_(std::move(min_version)),
- max_version_(std::move(max_version)),
- auto_close_(std::move(auto_close)) {}
-
-const std::string& ResControl::GetResType() const { return res_type_; }
-
-const std::string& ResControl::GetMinVersion() const { return min_version_; }
-
-const std::string& ResControl::GetMaxVersion() const { return max_version_; }
-
-const std::string& ResControl::GetAutoClose() const { return auto_close_; }
-
-std::shared_ptr<ResPkgInfo> ResControl::GetAllowedPackage() const {
- return allowed_package_;
-}
-
-std::shared_ptr<ResPkgInfo> ResControl::GetGlobalPackage() const {
- return global_package_;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2024 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 TOOL_APP_LAUNCHER_RES_CONTROL_HH_
-#define TOOL_APP_LAUNCHER_RES_CONTROL_HH_
-
-#include <memory>
-#include <string>
-
-#include "app_launcher/res_pkg_info.hh"
-
-namespace aul {
-
-class ResControl {
- public:
- ResControl(std::string res_type, std::string min_version,
- std::string max_version, std::string auto_close);
-
- const std::string& GetResType() const;
- const std::string& GetMinVersion() const;
- const std::string& GetMaxVersion() const;
- const std::string& GetAutoClose() const;
- std::shared_ptr<ResPkgInfo> GetAllowedPackage() const;
- std::shared_ptr<ResPkgInfo> GetGlobalPackage() const;
-
- private:
- friend class ResAppInfo;
-
- std::string res_type_;
- std::string min_version_;
- std::string max_version_;
- std::string auto_close_;
- std::shared_ptr<ResPkgInfo> allowed_package_ = nullptr;
- std::shared_ptr<ResPkgInfo> global_package_ = nullptr;
-};
-
-} // namespace aul
-
-#endif // TOOL_APP_LAUNCHER_RES_CONTROL_HH_
+++ /dev/null
-/*
- * Copyright (c) 2024 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 "app_launcher/res_info.hh"
-
-#include <utility>
-
-#include "app_launcher/log_private.hh"
-
-namespace aul {
-
-ResInfo::ResInfo(uid_t uid) : uid_(uid) {}
-
-bool ResInfo::Init() {
- pkgmgrinfo_pkginfo_filter_h filter = nullptr;
- int ret = pkgmgrinfo_pkginfo_filter_create(&filter);
- if (ret != PMINFO_R_OK) {
- _E("pkgmgrinfo_pkginfo_filter_create() is failed. error=%d", ret);
- return false;
- }
-
- auto filter_auto =
- std::unique_ptr<std::remove_pointer<pkgmgrinfo_pkginfo_filter_h>::type,
- decltype(pkgmgrinfo_pkginfo_filter_destroy)*>(
- filter, pkgmgrinfo_pkginfo_filter_destroy);
-
- ret = pkgmgrinfo_pkginfo_filter_add_string(
- filter, PMINFO_PKGINFO_PROP_PACKAGE_RES_TYPE, "");
- if (ret != PMINFO_R_OK) {
- _E("pkgmgrinfo_pkginfo_filter_add_string() is failed. error=%d", ret);
- return false;
- }
-
- ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
- filter,
- [](const pkgmgrinfo_pkginfo_h handle, void* user_data) {
- auto res_pkg_info = ResPkgInfo::CreateResPkgInfo(handle);
- if (!res_pkg_info) return 0;
-
- auto* res_info = reinterpret_cast<ResInfo*>(user_data);
- res_info->InsertPkgInfo(std::move(res_pkg_info));
- return 0;
- },
- this, uid_);
- if (ret != PMINFO_R_OK) {
- _E("pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo() is failed. error=%d",
- ret);
- return false;
- }
-
- return true;
-}
-
-void ResInfo::InsertPkgInfo(std::shared_ptr<ResPkgInfo> res_pkg_info) {
- res_pkg_infos_.push_back(std::move(res_pkg_info));
-}
-
-const std::vector<std::shared_ptr<ResPkgInfo>>& ResInfo::GetResPkgs() const {
- return res_pkg_infos_;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2024 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 __RES_INFO_H__
-#define __RES_INFO_H__
-
-#include <bundle.h>
-#include <pkgmgr-info.h>
-#include <unistd.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int _res_info_set(const pkgmgrinfo_appinfo_h handle, uid_t uid, bundle* b);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __RES_INFO_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2024 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 TOOL_APP_LAUNCHER_RES_INFO_HH_
-#define TOOL_APP_LAUNCHER_RES_INFO_HH_
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "app_launcher/res_pkg_info.hh"
-
-namespace aul {
-
-class ResInfo {
- public:
- explicit ResInfo(uid_t uid);
- bool Init();
- void InsertPkgInfo(std::shared_ptr<ResPkgInfo> res_pkginfo);
- const std::vector<std::shared_ptr<ResPkgInfo>>& GetResPkgs() const;
-
- private:
- uid_t uid_;
- std::vector<std::shared_ptr<ResPkgInfo>> res_pkg_infos_;
-};
-
-} // namespace aul
-
-#endif // TOOL_APP_LAUNCHER_RES_INFO_HH_
+++ /dev/null
-/*
- * Copyright (c) 2024 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 "app_launcher/res_info_manager.hh"
-#include "app_launcher/res_info.h"
-
-#include <aul.h>
-#include <bundle.h>
-
-#include "app_launcher/log_private.hh"
-#include "app_launcher/res_app_info.hh"
-#include "app_launcher/res_info.hh"
-#include "app_launcher/res_mount_package_info.hh"
-
-namespace {
-
-template <typename T>
-void AddDataToBundle(const T& list, bundle* b, const char* key) {
- bundle_del(b, key);
- int length = list.size();
- if (length == 0) return;
-
- std::vector<const char*> paths(length);
- int index = 0;
- auto iter = list.begin();
- while (iter != list.end()) {
- paths[index++] = static_cast<const char*>(iter->c_str());
- iter++;
- }
-
- bundle_add_str_array(b, key, paths.data(), length);
-}
-
-} // namespace
-
-namespace aul {
-
-ResInfoManager& ResInfoManager::GetInst() {
- static ResInfoManager inst;
- return inst;
-}
-
-int ResInfoManager::GetMountPackageInfo(
- pkgmgrinfo_appinfo_h handle, uid_t uid,
- std::optional<ResMountPackageInfo>* info) {
- auto res_app_info = ResAppInfo::CreateResAppInfo(handle, uid);
- if (!res_app_info) return -1;
-
- if (res_app_info->GetResControls().empty())
- return 0;
-
- auto res_info = std::make_shared<ResInfo>(uid);
- if (!res_info->Init()) {
- _E("Failed to initialize res pkg info. uid=%u", uid);
- return -1;
- }
-
- return ResMountPackageInfo::GetMountPackageInfo(
- std::move(res_info), std::move(res_app_info), info);
-}
-
-} // namespace aul
-
-extern "C" int _res_info_set(const pkgmgrinfo_appinfo_h handle, uid_t uid,
- bundle* b) {
- std::optional<aul::ResMountPackageInfo> info;
- int ret =
- aul::ResInfoManager::GetInst().GetMountPackageInfo(handle, uid, &info);
- if (ret < 0) return -1;
-
- if (!info) return 0;
-
- AddDataToBundle(info->GetAllowedPaths(), b, AUL_K_MOUNT_ALLOWED_RES_DIR);
- AddDataToBundle(info->GetGlobalPaths(), b, AUL_K_MOUNT_GLOBAL_RES_DIR);
- AddDataToBundle(info->GetLibPaths(), b, AUL_K_MOUNT_LIB_DIR);
- AddDataToBundle(info->GetGadgetPkgIds(), b, AUL_K_MOUNT_GADGET_PKGIDS);
- AddDataToBundle(info->GetGadgetPaths(), b, AUL_K_MOUNT_GADGET_PATHS);
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2024 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 TOOL_APP_LAUNCHER_RES_INFO_MANAGER_HH_
-#define TOOL_APP_LAUNCHER_RES_INFO_MANAGER_HH_
-
-#include <pkgmgr-info.h>
-
-#include <memory>
-#include <string>
-#include <unordered_map>
-
-#include "app_launcher/res_info.hh"
-#include "app_launcher/res_mount_package_info.hh"
-
-namespace aul {
-
-class ResInfoManager {
- public:
- static ResInfoManager& GetInst();
-
- int GetMountPackageInfo(pkgmgrinfo_appinfo_h handle, uid_t uid,
- std::optional<ResMountPackageInfo>* info);
-
- private:
- ResInfoManager() = default;
- ~ResInfoManager() = default;
-};
-
-} // namespace aul
-
-#endif // TOOL_APP_LAUNCHER_RES_INFO_MANAGER_HH_
+++ /dev/null
-/*
- * Copyright (c) 2024 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 "app_launcher/res_mount_package_info.hh"
-
-#include <optional>
-#include <unordered_map>
-#include <utility>
-
-#include "app_launcher/log_private.hh"
-#include "app_launcher/res_info.hh"
-#include "app_launcher/res_info_manager.hh"
-#include "app_launcher/res_pkg_info.hh"
-
-namespace {
-
-constexpr const char ALLOWED_SUFFIX[] = "/res/allowed";
-constexpr const char GLOBAL_SUFFIX[] = "/res/global";
-constexpr const char kLibDir[] = "/lib";
-
-} // namespace
-
-namespace aul {
-
-ResMountPackageInfo::ResMountPackageInfo() {}
-
-ResMountPackageInfo::ResMountPackageInfo(
- const std::vector<std::shared_ptr<ResPkgInfo>>& allowed_packages,
- const std::vector<std::shared_ptr<ResPkgInfo>>& global_packages) {
- for (const auto& pkg : allowed_packages) {
- if (pkg->IsGadget()) {
- gadget_pkgids_.insert(pkg->GetPkgId());
- gadget_paths_.emplace_back(pkg->GetRootPath() + ALLOWED_SUFFIX + "/" +
- pkg->GetResType());
- }
-
- if (pkg->IsLib()) lib_paths_.emplace_back(pkg->GetRootPath() + kLibDir);
-
- allowed_paths_.emplace_back(pkg->GetRootPath() + ALLOWED_SUFFIX);
- }
-
- for (const auto& pkg : global_packages)
- global_paths_.emplace_back(pkg->GetRootPath() + GLOBAL_SUFFIX);
-}
-
-int ResMountPackageInfo::GetMountPackageInfo(
- std::shared_ptr<ResInfo> res_info, std::shared_ptr<ResAppInfo> res_app_info,
- std::optional<ResMountPackageInfo>* info) {
- res_app_info->UpdateResControls(res_info->GetResPkgs());
- std::vector<std::shared_ptr<ResPkgInfo>> allowed_packages;
- std::vector<std::shared_ptr<ResPkgInfo>> global_packages;
- for (const auto& res_control : res_app_info->GetResControls()) {
- auto allowed_package = res_control.GetAllowedPackage();
- if (allowed_package) allowed_packages.push_back(std::move(allowed_package));
-
- auto global_package = res_control.GetGlobalPackage();
- if (global_package) global_packages.push_back(std::move(global_package));
- }
-
- *info = ResMountPackageInfo(allowed_packages, global_packages);
- return 0;
-}
-
-const std::vector<std::string>& ResMountPackageInfo::GetAllowedPaths() const {
- return allowed_paths_;
-}
-
-const std::vector<std::string>& ResMountPackageInfo::GetGlobalPaths() const {
- return global_paths_;
-}
-
-const std::vector<std::string>& ResMountPackageInfo::GetLibPaths() const {
- return lib_paths_;
-}
-
-const std::set<std::string>& ResMountPackageInfo::GetGadgetPkgIds() const {
- return gadget_pkgids_;
-}
-
-const std::vector<std::string>& ResMountPackageInfo::GetGadgetPaths() const {
- return gadget_paths_;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2024 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 TOOL_APP_LAUNCHER_RES_MOUNT_PACKAGE_INFO_HH_
-#define TOOL_APP_LAUNCHER_RES_MOUNT_PACKAGE_INFO_HH_
-
-#include <memory>
-#include <optional>
-#include <set>
-#include <string>
-#include <vector>
-
-#include "app_launcher/res_app_info.hh"
-#include "app_launcher/res_info.hh"
-#include "app_launcher/res_pkg_info.hh"
-
-namespace aul {
-
-class ResMountPackageInfo {
- public:
- ResMountPackageInfo();
- ResMountPackageInfo(
- const std::vector<std::shared_ptr<ResPkgInfo>>& allowed_packages,
- const std::vector<std::shared_ptr<ResPkgInfo>>& global_packages);
-
- static int GetMountPackageInfo(std::shared_ptr<ResInfo> res_info,
- std::shared_ptr<ResAppInfo> res_app_info,
- std::optional<ResMountPackageInfo>* info);
-
- const std::vector<std::string>& GetAllowedPaths() const;
- const std::vector<std::string>& GetGlobalPaths() const;
- const std::vector<std::string>& GetLibPaths() const;
- const std::set<std::string>& GetGadgetPkgIds() const;
- const std::vector<std::string>& GetGadgetPaths() const;
-
- private:
- std::vector<std::string> allowed_paths_;
- std::vector<std::string> global_paths_;
- std::vector<std::string> lib_paths_;
- std::set<std::string> gadget_pkgids_;
- std::vector<std::string> gadget_paths_;
-};
-
-} // namespace aul
-
-#endif // TOOL_APP_LAUNCHER_RES_MOUNT_PACKAGE_INFO_HH_
+++ /dev/null
-/*
- * Copyright (c) 2024 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 "app_launcher/res_pkg_info.hh"
-
-#include <fnmatch.h>
-
-#include <utility>
-
-#include "app_launcher/log_private.hh"
-
-namespace {
-
-constexpr const char kGadgetPrefix[] = "org.tizen.appfw.gadget.";
-
-} // namespace
-
-namespace aul {
-
-ResPkgInfo::Builder& ResPkgInfo::Builder::SetPkgId(
- const pkgmgrinfo_pkginfo_h handle) {
- char* pkgid = nullptr;
- if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) != PMINFO_R_OK)
- _E("pkgmgrinfo_pkginfo_get_pkgid() is failed");
- else
- pkgid_ = pkgid;
- return *this;
-}
-
-ResPkgInfo::Builder& ResPkgInfo::Builder::SetResType(
- const pkgmgrinfo_pkginfo_h handle) {
- char* res_type = nullptr;
- if (pkgmgrinfo_pkginfo_get_res_type(handle, &res_type) != PMINFO_R_OK)
- _E("pkgmgrinfo_pkginfo_get_res_type() is failed");
- else
- res_type_ = res_type;
- return *this;
-}
-
-ResPkgInfo::Builder& ResPkgInfo::Builder::SetResVersion(
- const pkgmgrinfo_pkginfo_h handle) {
- char* res_version = nullptr;
- if (pkgmgrinfo_pkginfo_get_res_version(handle, &res_version) != PMINFO_R_OK)
- _E("pkgmgrinfo_pkginfo_get_res_version() is failed");
- else
- res_version_ = res_version;
- return *this;
-}
-
-ResPkgInfo::Builder& ResPkgInfo::Builder::SetRootPath(
- const pkgmgrinfo_pkginfo_h handle) {
- char* root_path = nullptr;
- if (pkgmgrinfo_pkginfo_get_root_path(handle, &root_path) != PMINFO_R_OK)
- _E("pkgmgrinfo_pkginfo_get_root_path() is failed");
- else
- root_path_ = root_path;
- return *this;
-}
-
-ResPkgInfo::Builder& ResPkgInfo::Builder::SetIsLib(
- const pkgmgrinfo_pkginfo_h handle) {
- bool is_lib = false;
- if (pkgmgrinfo_pkginfo_is_lib(handle, &is_lib) != PMINFO_R_OK)
- _E("pkgmgrinfo_pkginfo_is_lib() is failed");
- else
- is_lib_ = is_lib;
- return *this;
-}
-
-ResPkgInfo::Builder& ResPkgInfo::Builder::SetAllowedPkgInfos(
- const pkgmgrinfo_pkginfo_h handle) {
- if (pkgmgrinfo_pkginfo_foreach_res_allowed_package(
- handle, ResAllowedPackageCb, this) != PMINFO_R_OK)
- _E("pkgmgrinfo_pkginfo_foreach_res_allowed_package() is failed");
-
- return *this;
-}
-
-ResPkgInfo* ResPkgInfo::Builder::Build() {
- return new ResPkgInfo(std::move(pkgid_), std::move(res_type_),
- std::move(res_version_), std::move(root_path_), is_lib_,
- std::move(allowed_pkg_infos_));
-}
-
-int ResPkgInfo::Builder::ResAllowedPackageCb(const char* allowed_package,
- required_privilege_h handle,
- void* user_data) {
- if (!allowed_package) return 0;
-
- std::unordered_set<std::string> required_privileges;
- int ret = pkgmgrinfo_pkginfo_foreach_required_privilege(
- handle, [](const char* privilege_name, void* data) {
- if (!privilege_name) return 0;
-
- auto* privileges =
- reinterpret_cast<std::unordered_set<std::string>*>(data);
- privileges->insert(privilege_name);
- return 0;
- }, &required_privileges);
- if (ret != PMINFO_R_OK)
- return 0;
-
- auto* builder = reinterpret_cast<ResPkgInfo::Builder*>(user_data);
- builder->allowed_pkg_infos_.push_back(
- AllowedPkgInfo(allowed_package, std::move(required_privileges)));
- return 0;
-}
-
-ResPkgInfo::ResPkgInfo(std::string pkgid, std::string res_type,
- std::string res_version, std::string root_path,
- bool is_lib,
- std::vector<AllowedPkgInfo> allowed_pkg_infos)
- : pkgid_(std::move(pkgid)),
- res_type_(std::move(res_type)),
- res_version_(std::move(res_version)),
- root_path_(std::move(root_path)),
- is_lib_(is_lib),
- allowed_pkg_infos_(std::move(allowed_pkg_infos)) {}
-
-std::shared_ptr<ResPkgInfo> ResPkgInfo::CreateResPkgInfo(
- const pkgmgrinfo_pkginfo_h handle) {
- ResPkgInfo::Builder builder;
- return std::shared_ptr<ResPkgInfo>(builder.SetPkgId(handle)
- .SetResType(handle)
- .SetResVersion(handle)
- .SetRootPath(handle)
- .SetIsLib(handle)
- .SetAllowedPkgInfos(handle)
- .Build());
-}
-
-const std::string& ResPkgInfo::GetPkgId() const { return pkgid_; }
-
-const std::string& ResPkgInfo::GetResType() const { return res_type_; }
-
-const std::string& ResPkgInfo::GetResVersion() const { return res_version_; }
-
-const std::string& ResPkgInfo::GetRootPath() const { return root_path_; }
-
-bool ResPkgInfo::IsLib() const { return is_lib_; }
-
-bool ResPkgInfo::IsGadget() const {
- return (res_type_.length() > strlen(kGadgetPrefix) &&
- !res_type_.compare(0, strlen(kGadgetPrefix), kGadgetPrefix));
-}
-
-bool ResPkgInfo::CheckAllowedPackage(
- const std::string& pkgid,
- const std::unordered_set<std::string>& privileges) const {
- for (const auto& info : allowed_pkg_infos_) {
- if (fnmatch(info.GetPkgId().c_str(), pkgid.c_str(), FNM_NOESCAPE)) continue;
-
- bool has_required_privileges = true;
- for (const auto& required_privilege : info.GetRequiredPrivileges()) {
- if (!privileges.count(required_privilege)) {
- has_required_privileges = false;
- break;
- }
- }
-
- if (has_required_privileges) return true;
- }
-
- return false;
-}
-
-} // namespace aul
+++ /dev/null
-/*
- * Copyright (c) 2024 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 TOOL_APP_LAUNCHER_RES_PKG_INFO_HH_
-#define TOOL_APP_LAUNCHER_RES_PKG_INFO_HH_
-
-#include <pkgmgr-info.h>
-
-#include <memory>
-#include <string>
-#include <unordered_set>
-#include <vector>
-
-#include "app_launcher/allowed_pkg_info.hh"
-
-namespace aul {
-
-class ResPkgInfo {
- public:
- class Builder {
- public:
- Builder& SetPkgId(const pkgmgrinfo_pkginfo_h handle);
- Builder& SetResType(const pkgmgrinfo_pkginfo_h handle);
- Builder& SetResVersion(const pkgmgrinfo_pkginfo_h handle);
- Builder& SetRootPath(const pkgmgrinfo_pkginfo_h handle);
- Builder& SetIsLib(const pkgmgrinfo_pkginfo_h handle);
- Builder& SetAllowedPkgInfos(const pkgmgrinfo_pkginfo_h handle);
- ResPkgInfo* Build();
-
- private:
- static int ResAllowedPackageCb(const char* allowed_package,
- required_privilege_h handle,
- void* user_data);
-
- private:
- std::string pkgid_;
- std::string res_type_;
- std::string res_version_;
- std::string root_path_;
- bool is_lib_ = false;
- std::vector<AllowedPkgInfo> allowed_pkg_infos_;
- };
-
- ResPkgInfo(std::string pkgid, std::string res_type, std::string res_version,
- std::string root_path, bool is_lib,
- std::vector<AllowedPkgInfo> allowed_pkg_infos);
-
- static std::shared_ptr<ResPkgInfo> CreateResPkgInfo(
- const pkgmgrinfo_pkginfo_h handle);
-
- const std::string& GetPkgId() const;
- const std::string& GetResType() const;
- const std::string& GetResVersion() const;
- const std::string& GetRootPath() const;
- bool IsLib() const;
- bool IsGadget() const;
- bool CheckAllowedPackage(
- const std::string& pkgid,
- const std::unordered_set<std::string>& privileges) const;
-
- private:
- std::string pkgid_;
- std::string res_type_;
- std::string res_version_;
- std::string root_path_;
- bool is_lib_;
- std::vector<AllowedPkgInfo> allowed_pkg_infos_;
-};
-
-} // namespace aul
-
-#endif // TOOL_APP_LAUNCHER_RES_PKG_INFO_HH_