return 0;
}
-
-static int ResInfoGetGadgetResPackagesInfo(uid_t uid, GList** pkgids,
- GList** allowed_paths, GList** global_paths) {
- std::shared_ptr<amd::ResInfo> resinfo = amd::ResInfoManager::GetInst()
- .GetUserResInfo(uid);
- if (!resinfo)
- return -1;
-
- pkgmgrinfo_version_compare_type ver_comp;
- std::unordered_map<std::string, std::shared_ptr<amd::ResPkgInfo>> gadget_map;
- for (const auto& [_, res_pkginfo] : resinfo->GetGadgetResPkgs()) {
- auto found = gadget_map.find(res_pkginfo->GetResType());
- if (found != gadget_map.end()) {
- if (pkgmgrinfo_compare_package_version(
- found->second->GetResVersion().c_str(),
- res_pkginfo->GetResVersion().c_str(),
- &ver_comp) != PMINFO_R_OK)
- continue;
-
- if (ver_comp != PMINFO_VERSION_NEW)
- continue;
-
- gadget_map.erase(found);
- }
-
- gadget_map[res_pkginfo->GetResType()] = res_pkginfo;
- }
-
- for (const auto& [_, res_pkginfo] : gadget_map) {
- *pkgids = g_list_append(*pkgids, strdup(res_pkginfo->GetPkgId().c_str()));
- std::string allowed_path = res_pkginfo->GetRootPath() + "/res/allowed/";
- *allowed_paths = g_list_append(*allowed_paths,
- strdup(allowed_path.c_str()));
- std::string global_path = res_pkginfo->GetRootPath() + "/res/global/";
- *global_paths = g_list_append(*global_paths, strdup(global_path.c_str()));
- }
-
- return 0;
-}
-
-int _resinfo_get_res_packages_info(const char* appid, uid_t uid,
- GList** pkgids, GList** allowed_paths, GList** global_paths) {
- if (!strcmp(appid, "org.tizen.NUIGadgetViewer")) {
- return ResInfoGetGadgetResPackagesInfo(uid, pkgids, allowed_paths,
- global_paths);
- }
-
- std::shared_ptr<amd::ResInfo> resinfo = amd::ResInfoManager::GetInst()
- .GetUserResInfo(uid);
- if (!resinfo)
- return -1;
-
- std::shared_ptr<amd::ResAppInfo> res_appinfo = resinfo->GetResAppInfo(appid);
- if (!res_appinfo)
- return 0;
-
- res_appinfo->ClearResControlMountInfo();
- res_appinfo->UpdateResControlMountInfo(resinfo->GetResPkgs());
-
- std::set<std::string> pkgid_s;
- std::vector<std::string> allowed_p;
- std::vector<std::string> global_p;
- res_appinfo->GetMountPackagesInfo(&pkgid_s, &allowed_p, &global_p);
-
- for (const auto& iter : pkgid_s)
- *pkgids = g_list_append(*pkgids, strdup(iter.c_str()));
-
- for (const std::string& root_path : allowed_p) {
- std::string p = root_path + "/res/allowed/";
- *allowed_paths = g_list_append(*allowed_paths, strdup(p.c_str()));
- }
-
- for (const std::string& root_path : global_p) {
- std::string p = root_path + "/res/global/";
- *global_paths = g_list_append(*global_paths, strdup(p.c_str()));
- }
-
- return 0;
-}
int _resinfo_init(void);
-int _resinfo_get_res_packages_info(const char *appid, uid_t uid,
- GList **pkgids, GList **allowed_paths, GList **global_paths);
-
#ifdef __cplusplus
}
#endif
#include "lib/app_info/app_info_manager.hh"
#include "lib/app_status/app_status_manager.hh"
#include "lib/common/log_private.hh"
+#include "lib/res_info/res_info_manager.hh"
+#include "lib/res_info/res_mount_package_info.hh"
namespace amd {
namespace {
return context->GetAppStatus()->GetStatus();
}
-void AddDataToBundle(GList* list, bundle* b, const char* key) {
+template <typename T>
+void AddDataToBundle(const T& list, bundle* b, const char* key) {
bundle_del(b, key);
- guint length = g_list_length(list);
+ int length = list.size();
if (length == 0)
return;
std::vector<const char*> paths(length);
int index = 0;
- GList* iter = list;
- while (iter != nullptr) {
- paths[index++] = static_cast<char*>(iter->data);
- iter = g_list_next(iter);
+ 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);
}
int StepPrepareStartingApp::SetResPackagePaths(LaunchContext* context) {
- GList* res_pkgids = nullptr;
- GList* allowed_paths = nullptr;
- GList* global_paths = nullptr;
- if (_resinfo_get_res_packages_info(context->GetAppId().c_str(),
- context->GetTargetUid(), &res_pkgids, &allowed_paths,
- &global_paths) < 0) {
+ std::optional<ResMountPackageInfo> info;
+ if (ResMountPackageInfo::GetMountPackageInfo(
+ context->GetAppId(), context->GetTargetUid(), &info) < 0) {
_E("Failed to get res package paths");
return -1;
}
- AddDataToBundle(res_pkgids, context->GetBundle(), AUL_K_MOUNT_RES_PKGIDS);
- AddDataToBundle(allowed_paths, context->GetBundle(),
+ if (!info)
+ return 0;
+
+ AddDataToBundle(info->GetPkgIds(), context->GetBundle(),
+ AUL_K_MOUNT_RES_PKGIDS);
+ AddDataToBundle(info->GetAllowedPaths(), context->GetBundle(),
AUL_K_MOUNT_ALLOWED_RES_DIR);
- AddDataToBundle(global_paths, context->GetBundle(),
+ AddDataToBundle(info->GetGlobalPaths(), context->GetBundle(),
AUL_K_MOUNT_GLOBAL_RES_DIR);
- g_list_free_full(res_pkgids, free);
- g_list_free_full(allowed_paths, free);
- g_list_free_full(global_paths, free);
+
return 0;
}
std::move(res_control_list), std::move(privilege_set)));
}
-const std::string& ResAppInfo::GetAppId() {
+const std::string& ResAppInfo::GetAppId() const {
return appid_;
}
-const std::vector<ResControl>& ResAppInfo::GetResControlList() {
+const std::vector<ResControl>& ResAppInfo::GetResControlList() const {
return res_control_list_;
}
}
}
-void ResAppInfo::GetMountPackagesInfo(std::set<std::string>* pkgids,
- std::vector<std::string>* allowed_paths,
- std::vector<std::string>* global_paths) {
- for (const auto& res_control : res_control_list_) {
- if (res_control.allowed_package) {
- pkgids->insert(res_control.allowed_package->GetPkgId());
- allowed_paths->push_back(res_control.allowed_package->GetRootPath());
- }
- if (res_control.global_package) {
- pkgids->insert(res_control.global_package->GetPkgId());
- global_paths->push_back(res_control.global_package->GetRootPath());
- }
- }
-}
-
} // namespace amd
static std::shared_ptr<ResAppInfo> CreateResAppInfo(
const pkgmgrinfo_appinfo_h handle, uid_t uid);
- const std::string& GetAppId();
- const std::vector<ResControl>& GetResControlList();
+ const std::string& GetAppId() const;
+ const std::vector<ResControl>& GetResControlList() const;
void ClearResControlMountInfo();
void UpdateResControlMountInfo(
const std::unordered_map<std::string,
std::shared_ptr<ResPkgInfo>>& res_pkgs);
- void UpdateResControlMountInfo(std::shared_ptr<ResPkgInfo> res_pkginfo);
- void GetMountPackagesInfo(std::set<std::string>* pkgids,
- std::vector<std::string>* allowed_paths,
- std::vector<std::string>* global_paths);
private:
ResAppInfo(std::string appid, std::string pkgid,
res_control_list_(std::move(res_control_list)),
privilege_set_(std::move(privilege_set)) {}
+ void UpdateResControlMountInfo(std::shared_ptr<ResPkgInfo> res_pkginfo);
+
std::string appid_;
std::string pkgid_;
std::vector<ResControl> res_control_list_;
--- /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 "lib/res_info/res_mount_package_info.hh"
+
+#include <unordered_map>
+
+#include "lib/common/log_private.hh"
+#include "lib/res_info/res_info.hh"
+#include "lib/res_info/res_info_manager.hh"
+#include "lib/res_info/res_pkg_info.hh"
+
+namespace amd {
+
+constexpr const char ALLOWED_SUFFIX[] = "/res/allowed";
+constexpr const char GLOBAL_SUFFIX[] = "/res/global";
+
+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) {
+ pkgids_.insert(pkg->GetPkgId());
+ allowed_paths_.emplace_back(pkg->GetRootPath() + ALLOWED_SUFFIX);
+ }
+ for (const auto& pkg : global_packages) {
+ pkgids_.insert(pkg->GetPkgId());
+ global_paths_.emplace_back(pkg->GetRootPath() + GLOBAL_SUFFIX);
+ }
+}
+
+static int ResInfoGetGadgetResPackagesInfo(uid_t uid,
+ std::optional<ResMountPackageInfo>* info) {
+ std::shared_ptr<ResInfo> resinfo = ResInfoManager::GetInst()
+ .GetUserResInfo(uid);
+ if (!resinfo)
+ return -1;
+
+ pkgmgrinfo_version_compare_type ver_comp;
+ std::unordered_map<std::string, std::shared_ptr<ResPkgInfo>> gadget_map;
+ for (const auto& [_, res_pkginfo] : resinfo->GetGadgetResPkgs()) {
+ auto found = gadget_map.find(res_pkginfo->GetResType());
+ if (found != gadget_map.end()) {
+ if (pkgmgrinfo_compare_package_version(
+ found->second->GetResVersion().c_str(),
+ res_pkginfo->GetResVersion().c_str(),
+ &ver_comp) != PMINFO_R_OK)
+ continue;
+
+ if (ver_comp != PMINFO_VERSION_NEW)
+ continue;
+
+ gadget_map.erase(found);
+ }
+
+ gadget_map[res_pkginfo->GetResType()] = res_pkginfo;
+ }
+
+ if (gadget_map.empty())
+ return 0;
+
+ std::vector<std::shared_ptr<ResPkgInfo>> packages;
+ for (auto& [_, res_pkginfo] : gadget_map)
+ packages.emplace_back(std::move(res_pkginfo));
+
+ *info = ResMountPackageInfo(packages, packages);
+
+ return 0;
+}
+
+int ResMountPackageInfo::GetMountPackageInfo(const std::string& appid,
+ uid_t uid, std::optional<ResMountPackageInfo>* info) {
+ if (appid == "org.tizen.NUIGadgetViewer") {
+ return ResInfoGetGadgetResPackagesInfo(uid, info);
+ }
+
+ std::shared_ptr<ResInfo> resinfo = ResInfoManager::GetInst()
+ .GetUserResInfo(uid);
+ if (!resinfo)
+ return -1;
+
+ std::shared_ptr<ResAppInfo> res_appinfo = resinfo->GetResAppInfo(appid);
+ if (!res_appinfo)
+ return 0;
+
+ res_appinfo->ClearResControlMountInfo();
+ res_appinfo->UpdateResControlMountInfo(resinfo->GetResPkgs());
+
+ std::vector<std::shared_ptr<ResPkgInfo>> allowed_packages;
+ std::vector<std::shared_ptr<ResPkgInfo>> global_packages;
+ for (const auto& res_control : res_appinfo->GetResControlList()) {
+ if (res_control.GetAllowedPackage())
+ allowed_packages.push_back(res_control.GetAllowedPackage());
+ if (res_control.GetGlobalPackage())
+ global_packages.push_back(res_control.GetGlobalPackage());
+ }
+
+ *info = ResMountPackageInfo(allowed_packages, global_packages);
+
+ return 0;
+}
+
+} // namespace amd
--- /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 LIB_RES_INFO_RES_MOUNT_PACKAGE_INFO_HH_
+#define LIB_RES_INFO_RES_MOUNT_PACKAGE_INFO_HH_
+
+#include <pkgmgr-info.h>
+
+#include <set>
+#include <string>
+#include <vector>
+
+#include "lib/res_info/res_pkg_info.hh"
+
+namespace amd {
+
+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(const std::string& appid, uid_t uid,
+ std::optional<ResMountPackageInfo>* info);
+
+ const std::set<std::string>& GetPkgIds() const { return pkgids_; }
+ const std::vector<std::string>& GetAllowedPaths() const {
+ return allowed_paths_;
+ }
+ const std::vector<std::string>& GetGlobalPaths() const {
+ return global_paths_;
+ }
+
+ private:
+ std::set<std::string> pkgids_;
+ std::vector<std::string> allowed_paths_;
+ std::vector<std::string> global_paths_;
+};
+
+} // namespace amd
+
+#endif // LIB_RES_INFO_RES_MOUNT_PACKAGE_INFO_HH_