#include "lib/amd_noti.h"
#include "lib/amd_proc.h"
#include "lib/amd_request.h"
-#include "lib/amd_res_info.h"
#include "lib/amd_restart_manager.h"
#include "lib/amd_signal.h"
#include "lib/amd_suspend.h"
#include "lib/common/cpu_boost_controller.hh"
#include "lib/common/exception.hh"
+#include "lib/res_info/res_info_manager.hh"
typedef int (*amd_mod_init_func)(void);
typedef void (*amd_mod_fini_func)(void);
_noti_init();
_compinfo_init();
_direct_launch_init();
- _resinfo_init();
+ amd::ResInfoManager::GetInst().Init();
if (_appinfo_init() != 0) {
_E("_appinfo_init() is failed");
return -1;
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "lib/amd_res_info.h"
-
-#include <glib.h>
-#include <linux/limits.h>
-#include <pkgmgr-info.h>
-#include <stdio.h>
-
-#include <memory>
-#include <set>
-#include <string>
-#include <tuple>
-#include <unordered_map>
-#include <utility>
-#include <vector>
-
-#include "lib/app_status/app_status_manager.hh"
-#include "lib/amd_app_status.h"
-#include "lib/amd_login_monitor.h"
-#include "lib/amd_noti.h"
-#include "lib/amd_util.h"
-#include "lib/res_info/res_app_info.hh"
-#include "lib/res_info/res_info.hh"
-#include "lib/res_info/res_info_manager.hh"
-#include "lib/res_info/res_pkg_info.hh"
-
-static int __on_login_monitor_login_start(const char* msg, int arg1, int arg2,
- void* arg3, bundle* b) {
- uid_t uid = (uid_t)arg1;
- amd::ResInfoManager& manager = amd::ResInfoManager::GetInst();
-
- if (manager.IsUserExist(uid))
- return NOTI_CONTINUE;
-
- if (!manager.CreateNewUser(uid))
- _E("Fail to create new user");
-
- return NOTI_CONTINUE;
-}
-
-static int __on_login_monitor_logout(const char* msg, int arg1, int arg2,
- void* arg3, bundle* b) {
- amd::ResInfoManager& manager = amd::ResInfoManager::GetInst();
- manager.RemoveUserResInfo((uid_t)arg1);
-
- return NOTI_CONTINUE;
-}
-
-static int __on_appinfo_insert(const char* msg, int arg1, int arg2,
- void* arg3, bundle* b) {
- pkgmgrinfo_appinfo_h handle = static_cast<pkgmgrinfo_appinfo_h>(arg3);
- uid_t uid = static_cast<uid_t>(arg1);
- int res_control_cnt = 0;
-
- amd::ResInfoManager& manager = amd::ResInfoManager::GetInst();
- if (!manager.IsUserExist(uid)) {
- if (!manager.CreateNewUser(uid))
- _E("Failed to create new user. uid(%u)", uid);
- }
-
- if (pkgmgrinfo_appinfo_foreach_res_control(handle,
- [](const char*, const char*, const char*,
- const char*, void* user_data) -> int {
- int* cnt = reinterpret_cast<int*>(user_data);
- (*cnt)++;
-
- return 0;
- }, &res_control_cnt) != PMINFO_R_OK)
- return NOTI_CONTINUE;
-
- if (!res_control_cnt)
- return NOTI_CONTINUE;
-
- manager.AddUserResAppInfo(handle, uid);
- return NOTI_CONTINUE;
-}
-
-static int __on_appinfo_remove(const char* msg, int arg1, int arg2,
- void* arg3, bundle* b) {
- uid_t uid = (uid_t)arg1;
- char* appid = reinterpret_cast<char*>(arg3);
- amd::ResInfoManager& manager = amd::ResInfoManager::GetInst();
-
- manager.RemoveUserResAppInfo(appid, uid);
- std::shared_ptr<amd::ResInfo> resinfo = manager.GetUserResInfo(uid);
- if (!resinfo)
- return NOTI_CONTINUE;
-
- resinfo->DeleteAppInfo(appid);
- return NOTI_CONTINUE;
-}
-
-static int __on_package_update_start(const char* msg, int arg1, int arg2,
- void* arg3, bundle* b) {
- uid_t uid = (uid_t)arg1;
- uid_t* uids = NULL;
- char* pkgid = reinterpret_cast<char*>(arg3);
- int r;
- amd::ResInfoManager& manager = amd::ResInfoManager::GetInst();
-
- if (uid < REGULAR_UID_MIN) {
- r = _login_monitor_get_uids(&uids);
- if (r <= 0)
- return NOTI_CONTINUE;
-
- for (int i = 0; i < r; i++) {
- std::shared_ptr<amd::ResPkgInfo> res_pkginfo =
- manager.GetUserResPkgInfo(pkgid, uids[i]);
- if (!res_pkginfo)
- continue;
-
- res_pkginfo->SetBlocking();
- amd::AppStatusManager::GetInst().TerminateAppsByResPackageID(
- pkgid, uids[i]);
- }
- free(uids);
- return NOTI_CONTINUE;
- }
-
- std::shared_ptr<amd::ResPkgInfo> res_pkginfo = manager.GetUserResPkgInfo(
- pkgid, uid);
- if (!res_pkginfo)
- return NOTI_CONTINUE;
-
- res_pkginfo->SetBlocking();
- amd::AppStatusManager::GetInst().TerminateAppsByResPackageID(pkgid, uid);
-
- return NOTI_CONTINUE;
-}
-
-static int __on_package_uninstall_end(const char* msg, int arg1, int arg2,
- void* arg3, bundle* b) {
- uid_t uid = (uid_t)arg1;
- uid_t* uids = NULL;
- char* pkgid = reinterpret_cast<char*>(arg3);
- int r;
- amd::ResInfoManager& manager = amd::ResInfoManager::GetInst();
-
- if (uid < REGULAR_UID_MIN) {
- r = _login_monitor_get_uids(&uids);
- if (r <= 0)
- return NOTI_CONTINUE;
-
- for (int i = 0; i < r; i++)
- manager.RemoveUserResPkgInfo(pkgid, uids[i]);
-
- free(uids);
- return NOTI_CONTINUE;
- }
-
- manager.RemoveUserResPkgInfo(pkgid, uid);
- return NOTI_CONTINUE;
-}
-
-static int __on_package_install_end(const char* msg, int arg1, int arg2,
- void* arg3, bundle* b) {
- int r;
- uid_t uid = (uid_t)arg1;
- uid_t* uids = NULL;
- char* pkgid = reinterpret_cast<char*>(arg3);
- amd::ResInfoManager& manager = amd::ResInfoManager::GetInst();
-
- if (uid < REGULAR_UID_MIN) {
- r = _login_monitor_get_uids(&uids);
- if (r <= 0)
- return NOTI_CONTINUE;
-
- for (int i = 0; i < r; i++)
- manager.AddUserResPkgInfo(pkgid, uids[i]);
-
- free(uids);
- return NOTI_CONTINUE;
- }
-
- manager.AddUserResPkgInfo(pkgid, uid);
- return NOTI_CONTINUE;
-}
-
-static int __on_package_update_end(const char* msg, int arg1, int arg2,
- void* arg3, bundle* b) {
- int r;
- uid_t uid = (uid_t)arg1;
- uid_t* uids = NULL;
- char* pkgid = reinterpret_cast<char*>(arg3);
- amd::ResInfoManager& manager = amd::ResInfoManager::GetInst();
-
- if (uid < REGULAR_UID_MIN) {
- r = _login_monitor_get_uids(&uids);
- if (r <= 0)
- return NOTI_CONTINUE;
-
- for (int i = 0; i < r; i++) {
- if (!manager.RemoveUserResPkgInfo(pkgid, uids[i]))
- continue;
-
- manager.AddUserResPkgInfo(pkgid, uids[i]);
- }
-
- free(uids);
- return NOTI_CONTINUE;
- }
-
- if (!manager.RemoveUserResPkgInfo(pkgid, uid))
- return NOTI_CONTINUE;
-
- manager.AddUserResPkgInfo(pkgid, uid);
- return NOTI_CONTINUE;
-}
-
-static int __on_package_update_error(const char* msg, int arg1, int arg2,
- void* arg3, bundle* b) {
- uid_t uid = (uid_t)arg1;
- uid_t* uids = NULL;
- char* pkgid = reinterpret_cast<char*>(arg3);
- int r;
- amd::ResInfoManager& manager = amd::ResInfoManager::GetInst();
-
- if (uid < REGULAR_UID_MIN) {
- r = _login_monitor_get_uids(&uids);
- if (r <= 0)
- return NOTI_CONTINUE;
-
- for (int i = 0; i < r; i++) {
- std::shared_ptr<amd::ResPkgInfo> res_pkginfo = manager.GetUserResPkgInfo(
- pkgid, uids[i]);
- if (!res_pkginfo)
- continue;
-
- res_pkginfo->UnsetBlocking();
- }
-
- free(uids);
- return NOTI_CONTINUE;
- }
-
- std::shared_ptr<amd::ResPkgInfo> res_pkginfo =
- manager.GetUserResPkgInfo(pkgid, uid);
- if (!res_pkginfo)
- return NOTI_CONTINUE;
-
- res_pkginfo->UnsetBlocking();
- return NOTI_CONTINUE;
-}
-
-static int __on_app_status_add(const char* msg, int arg1, int arg2,
- void* arg3, bundle* b) {
- auto* app_status = static_cast<amd::AppStatus*>(arg3);
- std::string appid = app_status->GetAppID();
- uid_t uid = app_status->GetUID();
- std::shared_ptr<amd::ResAppInfo> res_appinfo =
- amd::ResInfoManager::GetInst().GetUserResAppInfo(appid, uid);
- if (!res_appinfo)
- return NOTI_CONTINUE;
-
- GHashTable* res_pkg_tbl = g_hash_table_new_full(g_str_hash,
- g_str_equal, free, free);
- if (!res_pkg_tbl) {
- _E("Out of memory");
- return NOTI_CONTINUE;
- }
-
- for (const auto& rc : res_appinfo->GetResControlList()) {
- auto& allowed_package = rc.GetAllowedPackage();
- auto& global_package = rc.GetGlobalPackage();
- const std::string& auto_close = rc.GetAutoClose();
- if (allowed_package) {
- g_hash_table_insert(res_pkg_tbl,
- strdup(allowed_package->GetPkgId().c_str()),
- strdup(auto_close.c_str()));
- }
- if (global_package) {
- g_hash_table_insert(res_pkg_tbl,
- strdup(global_package->GetPkgId().c_str()),
- strdup(auto_close.c_str()));
- }
- }
-
- app_status->SetExtraData(APP_STATUS_RES_PACKAGE, res_pkg_tbl);
- return NOTI_CONTINUE;
-}
-
-static int __on_app_status_destroy(const char* msg, int arg1, int arg2,
- void* arg3, bundle* data) {
- auto* app_status = static_cast<amd::AppStatus*>(arg3);
- GHashTable* res_pkg_tbl = reinterpret_cast<GHashTable*>(
- app_status->GetExtraData(APP_STATUS_RES_PACKAGE));
-
- if (res_pkg_tbl)
- g_hash_table_destroy(res_pkg_tbl);
-
- return NOTI_CONTINUE;
-}
-
-int _resinfo_init(void) {
- _noti_listen(AMD_NOTI_MSG_LOGIN_MONITOR_LOGIN_START,
- __on_login_monitor_login_start);
- _noti_listen(AMD_NOTI_MSG_LOGIN_MONITOR_LOGOUT,
- __on_login_monitor_logout);
- _noti_listen(AMD_NOTI_MSG_APPINFO_INSERT,
- __on_appinfo_insert);
- _noti_listen(AMD_NOTI_MSG_APPINFO_REMOVE,
- __on_appinfo_remove);
- _noti_listen(AMD_NOTI_MSG_APPINFO_PACKAGE_UPDATE_START,
- __on_package_update_start);
- _noti_listen(AMD_NOTI_MSG_APPINFO_PACKAGE_UNINSTALL_END,
- __on_package_uninstall_end);
- _noti_listen(AMD_NOTI_MSG_APPINFO_PACKAGE_INSTALL_END,
- __on_package_install_end);
- _noti_listen(AMD_NOTI_MSG_APPINFO_PACKAGE_UPDATE_END,
- __on_package_update_end);
- _noti_listen(AMD_NOTI_MSG_APPINFO_PACKAGE_UPDATE_ERROR,
- __on_package_update_error);
- _noti_listen(AMD_NOTI_MSG_APP_STATUS_ADD,
- __on_app_status_add);
- _noti_listen(AMD_NOTI_MSG_APP_STATUS_DESTROY,
- __on_app_status_destroy);
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __AMD_RES_INFO_H__
-#define __AMD_RES_INFO_H__
-
-#include <glib.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int _resinfo_init(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __AMD_RES_INFO_H__ */
#include "lib/amd_app_property.h"
#include "lib/amd_launch.h"
#include "lib/amd_noti.h"
-#include "lib/amd_res_info.h"
#include "lib/amd_signal.h"
#include "lib/amd_suspend.h"
#include "lib/amd_util.h"
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2021 - 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.
* limitations under the License.
*/
-#include "lib/common/log_private.hh"
#include "lib/res_info/res_app_info.hh"
-namespace amd {
+#include <utility>
-const std::string& ResControl::GetResType() const {
- return res_type;
-}
+#include "lib/common/exception.hh"
+#include "lib/common/log_private.hh"
-const std::string& ResControl::GetMinResVersion() const {
- return min_res_version;
-}
+namespace amd {
+namespace {
+
+class ResAppInfoBuilder {
+ public:
+ ResAppInfoBuilder() = default;
+
+ ResAppInfoBuilder& SetAppId(const pkgmgrinfo_appinfo_h handle) {
+ char* appid;
+ int ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
+ if (ret != PMINFO_R_OK) {
+ _E("pkgmgrinfo_appinfo_get_appid() is failed");
+ THROW(ret);
+ }
-const std::string& ResControl::GetMaxResVersion() const {
- return max_res_version;
-}
+ appid_ = appid;
+ return *this;
+ }
-const std::string& ResControl::GetAutoClose() const {
- return auto_close;
-}
+ ResAppInfoBuilder& SetPkgId(const pkgmgrinfo_appinfo_h handle) {
+ char* pkgid;
+ int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
+ if (ret!= PMINFO_R_OK) {
+ _E("pkgmgrinfo_appinfo_get_pkgid() is failed");
+ THROW(ret);
+ }
-const std::shared_ptr<ResPkgInfo>& ResControl::GetAllowedPackage() const {
- return allowed_package;
-}
+ pkgid_ = pkgid;
+ return *this;
+ }
-const std::shared_ptr<ResPkgInfo>& ResControl::GetGlobalPackage() const {
- return global_package;
-}
+ ResAppInfoBuilder& SetResControls(const pkgmgrinfo_appinfo_h handle) {
+ int ret = pkgmgrinfo_appinfo_foreach_res_control(
+ handle,
+ [](const char* res_type, const char* min_res_version,
+ const char* max_res_version, const char* auto_close,
+ void* user_data) {
+ if (res_type == nullptr) return 0;
+
+ std::vector<amd::ResControl>* res_controls =
+ reinterpret_cast<std::vector<amd::ResControl>*>(user_data);
+ res_controls->emplace_back(res_type,
+ min_res_version ? min_res_version : "",
+ max_res_version ? max_res_version : "",
+ auto_close ? auto_close : "");
+ return 0;
+ },
+ &res_controls_);
+ if (ret != PMINFO_R_OK) {
+ _E("pkgmgrinfo_appinfo_foreach_res_control() is failed");
+ THROW(ret);
+ }
-std::shared_ptr<ResAppInfo> ResAppInfo::CreateResAppInfo(
- const pkgmgrinfo_appinfo_h handle, uid_t uid) {
- char* appid;
- char* pkgid;
- pkgmgrinfo_pkginfo_h p_handle;
- std::vector<ResControl> res_control_list;
- std::set<std::string> privilege_set;
-
- if (pkgmgrinfo_appinfo_get_appid(handle, &appid) != PMINFO_R_OK) {
- _E("Fail to get appid");
- return nullptr;
+ return *this;
}
- if (pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid) != PMINFO_R_OK)
- return nullptr;
-
- if (pkgmgrinfo_appinfo_foreach_res_control(handle,
- [](const char* res_type, const char* min_res_version,
- const char* max_res_version, const char* auto_close,
- void* user_data) -> int {
- if (!res_type)
- return 0;
- std::vector<ResControl>* res_control_list =
- reinterpret_cast<std::vector<ResControl>*>(user_data);
+ ResAppInfoBuilder& SetPrivileges(uid_t uid) {
+ pkgmgrinfo_pkginfo_h handle;
+ 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);
+ THROW(ret);
+ }
- res_control_list->emplace_back(res_type,
- min_res_version ? min_res_version : "",
- max_res_version ? max_res_version : "",
- auto_close ? auto_close : "");
+ ret = pkgmgrinfo_pkginfo_foreach_privilege(
+ handle,
+ [](const char* privilege_name, void* user_data) {
+ if (privilege_name == nullptr) return 0;
- return 0;
- }, &res_control_list) != PMINFO_R_OK)
- return nullptr;
+ std::set<std::string>* privileges =
+ reinterpret_cast<std::set<std::string>*>(user_data);
+ privileges->insert(privilege_name);
+ return 0;
+ },
+ &privileges_);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ if (ret != PMINFO_R_OK) {
+ _E("pkgmgrinfo_pkginfo_foreach_privilege() is failed. pkgid(%s)",
+ pkgid_.c_str());
+ THROW(ret);
+ }
- if (pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid,
- uid, &p_handle) != PMINFO_R_OK) {
- _E("Fail to get pkginfo pkgid : %s, uid : %d", pkgid, uid);
- return nullptr;
+ return *this;
}
- std::unique_ptr<std::remove_pointer<pkgmgrinfo_pkginfo_h>::type,
- decltype(pkgmgrinfo_pkginfo_destroy_pkginfo)*>handle_auto(
- p_handle, pkgmgrinfo_pkginfo_destroy_pkginfo);
+ ResAppInfo* Build() {
+ return new ResAppInfo(std::move(appid_), std::move(pkgid_),
+ std::move(res_controls_), std::move(privileges_));
+ }
- if (pkgmgrinfo_pkginfo_foreach_privilege(handle_auto.get(),
- [](const char* privilege_name, void* user_data) -> int {
- if (!privilege_name)
- return 0;
+ private:
+ std::string appid_;
+ std::string pkgid_;
+ std::vector<ResControl> res_controls_;
+ std::set<std::string> privileges_;
+};
- std::set<std::string>* privilege_set =
- reinterpret_cast<std::set<std::string>*>(user_data);
- privilege_set->insert(privilege_name);
+} // namespace
- return 0;
- }, &privilege_set) != PMINFO_R_OK)
+std::shared_ptr<ResAppInfo> ResAppInfo::CreateResAppInfo(
+ const pkgmgrinfo_appinfo_h handle, uid_t uid) {
+ try {
+ ResAppInfoBuilder builder;
+ return std::shared_ptr<ResAppInfo>(builder.SetAppId(handle)
+ .SetPkgId(handle)
+ .SetResControls(handle)
+ .SetPrivileges(uid)
+ .Build());
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%d)", e.GetErrorCode());
return nullptr;
-
- return std::shared_ptr<ResAppInfo>(new ResAppInfo(appid, pkgid,
- std::move(res_control_list), std::move(privilege_set)));
+ }
}
-const std::string& ResAppInfo::GetAppId() const {
- return appid_;
-}
+ResAppInfo::ResAppInfo(std::string appid, std::string pkgid,
+ std::vector<ResControl> res_control_list,
+ std::set<std::string> privilege_set)
+ : appid_(std::move(appid)),
+ pkgid_(std::move(pkgid)),
+ res_control_list_(std::move(res_control_list)),
+ privilege_set_(std::move(privilege_set)) {}
+
+const std::string& ResAppInfo::GetAppId() const { return appid_; }
const std::vector<ResControl>& ResAppInfo::GetResControlList() const {
return res_control_list_;
if (res_pkginfo->IsBlocked())
return;
- pkgmgrinfo_version_compare_type ver_comp;
+ pkgmgrinfo_version_compare_type version_compare;
+ int ret;
for (auto& res_control : res_control_list_) {
if (res_control.res_type != res_pkginfo->GetResType())
continue;
if (!res_control.min_res_version.empty()) {
- if (pkgmgrinfo_compare_package_version(
+ ret = pkgmgrinfo_compare_package_version(
res_control.min_res_version.c_str(),
- res_pkginfo->GetResVersion().c_str(),
- &ver_comp) != PMINFO_R_OK)
- continue;
+ res_pkginfo->GetResVersion().c_str(), &version_compare);
+ if (ret != PMINFO_R_OK) continue;
- if (ver_comp == PMINFO_VERSION_OLD)
- continue;
+ if (version_compare == PMINFO_VERSION_OLD) continue;
}
if (!res_control.max_res_version.empty()) {
- if (pkgmgrinfo_compare_package_version(
+ ret = pkgmgrinfo_compare_package_version(
res_pkginfo->GetResVersion().c_str(),
- res_control.max_res_version.c_str(),
- &ver_comp) != PMINFO_R_OK)
- continue;
+ res_control.max_res_version.c_str(), &version_compare);
+ if (ret != PMINFO_R_OK) continue;
- if (ver_comp == PMINFO_VERSION_OLD)
- continue;
+ if (version_compare == PMINFO_VERSION_OLD) continue;
}
if (!res_control.global_package) {
res_control.global_package = res_pkginfo;
} else {
- if (pkgmgrinfo_compare_package_version(
+ ret = pkgmgrinfo_compare_package_version(
res_control.global_package->GetResVersion().c_str(),
- res_pkginfo->GetResVersion().c_str(),
- &ver_comp) != PMINFO_R_OK)
- continue;
+ res_pkginfo->GetResVersion().c_str(), &version_compare);
+ if (ret != PMINFO_R_OK) continue;
- if (ver_comp == PMINFO_VERSION_NEW)
+ if (version_compare == PMINFO_VERSION_NEW)
res_control.global_package = res_pkginfo;
}
if (!res_control.allowed_package) {
res_control.allowed_package = res_pkginfo;
} else {
- if (pkgmgrinfo_compare_package_version(
+ ret = pkgmgrinfo_compare_package_version(
res_control.allowed_package->GetResVersion().c_str(),
- res_pkginfo->GetResVersion().c_str(),
- &ver_comp) != PMINFO_R_OK)
- continue;
+ res_pkginfo->GetResVersion().c_str(), &version_compare);
+ if (ret != PMINFO_R_OK) continue;
- if (ver_comp == PMINFO_VERSION_NEW)
+ if (version_compare == PMINFO_VERSION_NEW)
res_control.allowed_package = res_pkginfo;
}
}
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2021 - 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.
#include <utility>
#include <vector>
-#include "lib/res_info/res_pkg_info.hh"
+#include "lib/res_info/res_control.hh"
namespace amd {
-class ResAppInfo;
-
-struct ResControl {
- public:
- ResControl(std::string res_type, std::string min_res_version,
- std::string max_res_version, std::string auto_close)
- : res_type(std::move(res_type)),
- min_res_version(std::move(min_res_version)),
- max_res_version(std::move(max_res_version)),
- auto_close(std::move(auto_close)),
- allowed_package(nullptr),
- global_package(nullptr) {}
-
- const std::string& GetResType() const;
- const std::string& GetMinResVersion() const;
- const std::string& GetMaxResVersion() const;
- const std::string& GetAutoClose() const;
- const std::shared_ptr<ResPkgInfo>& GetAllowedPackage() const;
- const std::shared_ptr<ResPkgInfo>& GetGlobalPackage() const;
-
- private:
- std::string res_type;
- std::string min_res_version;
- std::string max_res_version;
- std::string auto_close;
- std::shared_ptr<ResPkgInfo> allowed_package;
- std::shared_ptr<ResPkgInfo> global_package;
-
- friend class ResAppInfo;
-};
-
class ResAppInfo {
public:
static std::shared_ptr<ResAppInfo> CreateResAppInfo(
const std::vector<ResControl>& GetResControlList() const;
void ClearResControlMountInfo();
void UpdateResControlMountInfo(
- const std::unordered_map<std::string,
- std::shared_ptr<ResPkgInfo>>& res_pkgs);
+ const std::unordered_map<std::string, std::shared_ptr<ResPkgInfo>>&
+ res_pkgs);
- private:
ResAppInfo(std::string appid, std::string pkgid,
- std::vector<ResControl> res_control_list,
- std::set<std::string> privilege_set)
- : appid_(std::move(appid)),
- pkgid_(std::move(pkgid)),
- res_control_list_(std::move(res_control_list)),
- privilege_set_(std::move(privilege_set)) {}
+ std::vector<ResControl> res_control_list,
+ std::set<std::string> privilege_set);
+ private:
void UpdateResControlMountInfo(std::shared_ptr<ResPkgInfo> res_pkginfo);
+ private:
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_control.hh"
+
+#include <utility>
+
+#include "lib/common/log_private.hh"
+
+namespace amd {
+
+ResControl::ResControl(std::string res_type, std::string min_res_version,
+ std::string max_res_version, std::string auto_close)
+ : res_type(std::move(res_type)),
+ min_res_version(std::move(min_res_version)),
+ max_res_version(std::move(max_res_version)),
+ auto_close(std::move(auto_close)),
+ allowed_package(nullptr),
+ global_package(nullptr) {}
+
+const std::string& ResControl::GetResType() const { return res_type; }
+
+const std::string& ResControl::GetMinResVersion() const {
+ return min_res_version;
+}
+
+const std::string& ResControl::GetMaxResVersion() const {
+ return max_res_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 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_CONTROL_HH_
+#define LIB_RES_INFO_RES_CONTROL_HH_
+
+#include <memory>
+#include <string>
+
+#include "lib/res_info/res_pkg_info.hh"
+
+namespace amd {
+
+class ResAppInfo;
+
+struct ResControl {
+ public:
+ ResControl(std::string res_type, std::string min_res_version,
+ std::string max_res_version, std::string auto_close);
+
+ const std::string& GetResType() const;
+ const std::string& GetMinResVersion() const;
+ const std::string& GetMaxResVersion() 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_res_version;
+ std::string max_res_version;
+ std::string auto_close;
+ std::shared_ptr<ResPkgInfo> allowed_package = nullptr;
+ std::shared_ptr<ResPkgInfo> global_package = nullptr;
+};
+
+} // namespace amd
+
+#endif // LIB_RES_INFO_RES_CONTROL_HH_
#include "lib/common/log_private.hh"
#include "lib/res_info/res_app_info.hh"
-namespace amd {
namespace {
constexpr const char kResTypeGadget[] = "org.tizen.appfw.gadget.";
} // namespace
+namespace amd {
+
std::shared_ptr<ResAppInfo> ResInfo::GetResAppInfo(const std::string& appid) {
if (!res_appinfo_.count(appid))
return nullptr;
res_pkginfo_.erase(pkgid);
gadget_pkginfo_.erase(pkgid);
-
return true;
}
const std::unordered_map<std::string, std::shared_ptr<ResPkgInfo>>&
- ResInfo::GetResPkgs() {
+ ResInfo::GetResPkgs() const {
return res_pkginfo_;
}
const std::unordered_map<std::string, std::shared_ptr<ResPkgInfo>>&
- ResInfo::GetGadgetResPkgs() {
+ ResInfo::GetGadgetResPkgs() const {
return gadget_pkginfo_;
}
bool ResInfo::ResPkgInit() {
pkgmgrinfo_pkginfo_filter_h filter;
-
- if (pkgmgrinfo_pkginfo_filter_create(&filter) != PMINFO_R_OK) {
- _E("out of memory");
+ int ret = pkgmgrinfo_pkginfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK) {
+ _E("pkgmgrinfo_pkginfo_filter_create() is failed. error(%d)", ret);
return false;
}
- std::unique_ptr<std::remove_pointer<pkgmgrinfo_pkginfo_filter_h>::type,
- decltype(pkgmgrinfo_pkginfo_filter_destroy)*>handle_auto(
+ auto handle_auto =
+ std::unique_ptr<std::remove_pointer<pkgmgrinfo_pkginfo_filter_h>::type,
+ decltype(pkgmgrinfo_pkginfo_filter_destroy)*>(
filter, pkgmgrinfo_pkginfo_filter_destroy);
- if (pkgmgrinfo_pkginfo_filter_add_string(handle_auto.get(),
- PMINFO_PKGINFO_PROP_PACKAGE_RES_TYPE, "") != PMINFO_R_OK) {
- _E("pkgmgrinfo_pkginfo_filter_add_string() failed");
+ 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;
}
- if (pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle_auto.get(),
- [](const pkgmgrinfo_pkginfo_h handle, void* data) -> int {
- ResInfo* resinfo = reinterpret_cast<ResInfo*>(data);
-
+ ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
+ filter,
+ [](const pkgmgrinfo_pkginfo_h handle, void* user_data) {
std::shared_ptr<ResPkgInfo> res_pkg_info =
ResPkgInfo::CreateResPkgInfo(handle);
- if (!res_pkg_info)
- return 0;
+ if (!res_pkg_info) return 0;
+ ResInfo* res_info = reinterpret_cast<ResInfo*>(user_data);
char* res_type = nullptr;
pkgmgrinfo_pkginfo_get_res_type(handle, &res_type);
- if (res_type != nullptr &&
- strlen(res_type) > strlen(kResTypeGadget) &&
+ if (res_type != nullptr && strlen(res_type) > strlen(kResTypeGadget) &&
!strncmp(res_type, kResTypeGadget, strlen(kResTypeGadget)))
- resinfo->InsertGadgetPkgInfo(res_pkg_info);
+ res_info->InsertGadgetPkgInfo(res_pkg_info);
- resinfo->InsertPkgInfo(std::move(res_pkg_info));
+ res_info->InsertPkgInfo(std::move(res_pkg_info));
return 0;
- }, this, uid_) != PMINFO_R_OK) {
- _E("pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo() failed");
+ },
+ this, uid_);
+ if (ret != PMINFO_R_OK) {
+ _E("pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo() is failed. error(%d)",
+ ret);
return false;
}
bool DeleteAppInfo(const std::string& appid);
bool DeletePkgInfo(const std::string& pkgid);
const std::unordered_map<std::string, std::shared_ptr<ResPkgInfo>>&
- GetResPkgs();
+ GetResPkgs() const;
const std::unordered_map<std::string, std::shared_ptr<ResPkgInfo>>&
- GetGadgetResPkgs();
+ GetGadgetResPkgs() const;
private:
uid_t uid_;
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2021 -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.
* limitations under the License.
*/
-#include "lib/common/log_private.hh"
#include "lib/res_info/res_info_manager.hh"
+
+#include <glib.h>
+
+#include <utility>
+
+#include "lib/amd_app_status.h"
+#include "lib/amd_login_monitor.h"
+#include "lib/amd_noti.h"
+#include "lib/amd_util.h"
+#include "lib/app_status/app_status_manager.hh"
+#include "lib/common/log_private.hh"
#include "lib/res_info/res_info.hh"
namespace amd {
+static int OnLoginMonitorLoginStart(const char* msg, int arg1, int arg2,
+ void* arg3, bundle* b) {
+ uid_t uid = static_cast<uid_t>(arg1);
+ auto& manager = ResInfoManager::GetInst();
+ if (manager.IsUserExist(uid)) return NOTI_CONTINUE;
+
+ if (!manager.CreateNewUser(uid)) _E("Fail to create new user(%u)", uid);
+
+ return NOTI_CONTINUE;
+}
+
+static int OnLoginMonitorLogout(const char* msg, int arg1, int arg2, void* arg3,
+ bundle* b) {
+ uid_t uid = static_cast<uid_t>(arg1);
+ ResInfoManager::GetInst().RemoveUserResInfo(uid);
+ return NOTI_CONTINUE;
+}
+
+static int ResControlCb(const char* res_type, const char* min_res_version,
+ const char* max_res_version, const char* auto_close,
+ void* user_data) {
+ bool* exists = static_cast<bool*>(user_data);
+ *exists = true;
+ return -1;
+}
+
+static int OnAppinfoInsert(const char* msg, int arg1, int arg2, void* arg3,
+ bundle* b) {
+ uid_t uid = static_cast<uid_t>(arg1);
+ auto& manager = ResInfoManager::GetInst();
+ if (!manager.IsUserExist(uid)) {
+ if (!manager.CreateNewUser(uid))
+ _E("Failed to create new user. uid(%u)", uid);
+ }
+
+ pkgmgrinfo_appinfo_h handle = static_cast<pkgmgrinfo_appinfo_h>(arg3);
+ bool res_control_exists = false;
+ int ret = pkgmgrinfo_appinfo_foreach_res_control(handle, ResControlCb,
+ &res_control_exists);
+ if (ret != PMINFO_R_OK) return NOTI_CONTINUE;
+
+ if (!res_control_exists) return NOTI_CONTINUE;
+
+ manager.AddUserResAppInfo(handle, uid);
+ return NOTI_CONTINUE;
+}
+
+static int OnAppinfoRemove(const char* msg, int arg1, int arg2, void* arg3,
+ bundle* b) {
+ uid_t uid = static_cast<uid_t>(arg1);
+ char* appid = reinterpret_cast<char*>(arg3);
+ auto& manager = ResInfoManager::GetInst();
+ manager.RemoveUserResAppInfo(appid, uid);
+ std::shared_ptr<ResInfo> resinfo = manager.GetUserResInfo(uid);
+ if (!resinfo) return NOTI_CONTINUE;
+
+ resinfo->DeleteAppInfo(appid);
+ return NOTI_CONTINUE;
+}
+
+static int OnAppinfoPackageUpdateStart(const char* msg, int arg1, int arg2,
+ void* arg3, bundle* b) {
+ uid_t uid = static_cast<uid_t>(arg1);
+ char* pkgid = reinterpret_cast<char*>(arg3);
+ auto& manager = ResInfoManager::GetInst();
+
+ if (uid < REGULAR_UID_MIN) {
+ uid_t* uids = nullptr;
+ int length = _login_monitor_get_uids(&uids);
+ if (length <= 0) return NOTI_CONTINUE;
+
+ for (int i = 0; i < length; i++) {
+ std::shared_ptr<ResPkgInfo> res_pkginfo =
+ manager.GetUserResPkgInfo(pkgid, uids[i]);
+ if (!res_pkginfo) continue;
+
+ res_pkginfo->SetBlocking();
+ AppStatusManager::GetInst().TerminateAppsByResPackageID(pkgid, uids[i]);
+ }
+ free(uids);
+ return NOTI_CONTINUE;
+ }
+
+ std::shared_ptr<ResPkgInfo> res_pkginfo =
+ manager.GetUserResPkgInfo(pkgid, uid);
+ if (!res_pkginfo) return NOTI_CONTINUE;
+
+ res_pkginfo->SetBlocking();
+ AppStatusManager::GetInst().TerminateAppsByResPackageID(pkgid, uid);
+ return NOTI_CONTINUE;
+}
+
+static int OnAppinfoPackageUninstallEnd(const char* msg, int arg1, int arg2,
+ void* arg3, bundle* b) {
+ uid_t uid = static_cast<uid_t>(arg1);
+ char* pkgid = reinterpret_cast<char*>(arg3);
+ auto& manager = ResInfoManager::GetInst();
+
+ if (uid < REGULAR_UID_MIN) {
+ uid_t* uids = nullptr;
+ int length = _login_monitor_get_uids(&uids);
+ if (length <= 0) return NOTI_CONTINUE;
+
+ for (int i = 0; i < length; i++)
+ manager.RemoveUserResPkgInfo(pkgid, uids[i]);
+
+ free(uids);
+ return NOTI_CONTINUE;
+ }
+
+ manager.RemoveUserResPkgInfo(pkgid, uid);
+ return NOTI_CONTINUE;
+}
+
+static int OnAppinfoPackageInstallEnd(const char* msg, int arg1, int arg2,
+ void* arg3, bundle* b) {
+ uid_t uid = static_cast<uid_t>(arg1);
+ char* pkgid = reinterpret_cast<char*>(arg3);
+ auto& manager = ResInfoManager::GetInst();
+
+ if (uid < REGULAR_UID_MIN) {
+ uid_t* uids = nullptr;
+ int length = _login_monitor_get_uids(&uids);
+ if (length <= 0) return NOTI_CONTINUE;
+
+ for (int i = 0; i < length; i++) manager.AddUserResPkgInfo(pkgid, uids[i]);
+
+ free(uids);
+ return NOTI_CONTINUE;
+ }
+
+ manager.AddUserResPkgInfo(pkgid, uid);
+ return NOTI_CONTINUE;
+}
+
+static int OnAppInfoPackageUpdateEnd(const char* msg, int arg1, int arg2,
+ void* arg3, bundle* b) {
+ uid_t uid = static_cast<uid_t>(arg1);
+ char* pkgid = reinterpret_cast<char*>(arg3);
+ auto& manager = ResInfoManager::GetInst();
+
+ if (uid < REGULAR_UID_MIN) {
+ uid_t* uids = nullptr;
+ int length = _login_monitor_get_uids(&uids);
+ if (length <= 0) return NOTI_CONTINUE;
+
+ for (int i = 0; i < length; i++) {
+ if (!manager.RemoveUserResPkgInfo(pkgid, uids[i])) continue;
+
+ manager.AddUserResPkgInfo(pkgid, uids[i]);
+ }
+
+ free(uids);
+ return NOTI_CONTINUE;
+ }
+
+ if (!manager.RemoveUserResPkgInfo(pkgid, uid)) return NOTI_CONTINUE;
+
+ manager.AddUserResPkgInfo(pkgid, uid);
+ return NOTI_CONTINUE;
+}
+
+static int OnAppInfoPackageUpdateError(const char* msg, int arg1, int arg2,
+ void* arg3, bundle* b) {
+ uid_t uid = static_cast<uid_t>(arg1);
+ char* pkgid = reinterpret_cast<char*>(arg3);
+ auto& manager = ResInfoManager::GetInst();
+
+ if (uid < REGULAR_UID_MIN) {
+ uid_t* uids = nullptr;
+ int length = _login_monitor_get_uids(&uids);
+ if (length <= 0) return NOTI_CONTINUE;
+
+ for (int i = 0; i < length; i++) {
+ std::shared_ptr<ResPkgInfo> res_pkginfo =
+ manager.GetUserResPkgInfo(pkgid, uids[i]);
+ if (!res_pkginfo) continue;
+
+ res_pkginfo->UnsetBlocking();
+ }
+
+ free(uids);
+ return NOTI_CONTINUE;
+ }
+
+ std::shared_ptr<amd::ResPkgInfo> res_pkginfo =
+ manager.GetUserResPkgInfo(pkgid, uid);
+ if (!res_pkginfo) return NOTI_CONTINUE;
+
+ res_pkginfo->UnsetBlocking();
+ return NOTI_CONTINUE;
+}
+
+static int OnAppStatusAdd(const char* msg, int arg1, int arg2, void* arg3,
+ bundle* b) {
+ auto* app_status = static_cast<AppStatus*>(arg3);
+ std::string appid = app_status->GetAppID();
+ uid_t uid = app_status->GetUID();
+ std::shared_ptr<ResAppInfo> res_appinfo =
+ ResInfoManager::GetInst().GetUserResAppInfo(appid, uid);
+ if (!res_appinfo) return NOTI_CONTINUE;
+
+ GHashTable* res_pkg_tbl =
+ g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
+ if (!res_pkg_tbl) {
+ _E("Out of memory");
+ return NOTI_CONTINUE;
+ }
+
+ for (const auto& res_control : res_appinfo->GetResControlList()) {
+ auto allowed_package = res_control.GetAllowedPackage();
+ auto global_package = res_control.GetGlobalPackage();
+ const std::string& auto_close = res_control.GetAutoClose();
+ if (allowed_package) {
+ g_hash_table_insert(res_pkg_tbl,
+ strdup(allowed_package->GetPkgId().c_str()),
+ strdup(auto_close.c_str()));
+ }
+ if (global_package) {
+ g_hash_table_insert(res_pkg_tbl,
+ strdup(global_package->GetPkgId().c_str()),
+ strdup(auto_close.c_str()));
+ }
+ }
+
+ app_status->SetExtraData(APP_STATUS_RES_PACKAGE, res_pkg_tbl);
+ return NOTI_CONTINUE;
+}
+
+static int OnAppStatusDestroy(const char* msg, int arg1, int arg2, void* arg3,
+ bundle* data) {
+ auto* app_status = static_cast<AppStatus*>(arg3);
+ GHashTable* res_pkg_tbl = reinterpret_cast<GHashTable*>(
+ app_status->GetExtraData(APP_STATUS_RES_PACKAGE));
+
+ if (res_pkg_tbl) g_hash_table_destroy(res_pkg_tbl);
+
+ return NOTI_CONTINUE;
+}
+
+ResInfoManager& ResInfoManager::GetInst() {
+ static ResInfoManager inst;
+ return inst;
+}
+
+void ResInfoManager::Init() {
+ _noti_listen(AMD_NOTI_MSG_LOGIN_MONITOR_LOGIN_START,
+ OnLoginMonitorLoginStart);
+ _noti_listen(AMD_NOTI_MSG_LOGIN_MONITOR_LOGOUT, OnLoginMonitorLogout);
+ _noti_listen(AMD_NOTI_MSG_APPINFO_INSERT, OnAppinfoInsert);
+ _noti_listen(AMD_NOTI_MSG_APPINFO_REMOVE, OnAppinfoRemove);
+ _noti_listen(AMD_NOTI_MSG_APPINFO_PACKAGE_UPDATE_START,
+ OnAppinfoPackageUpdateStart);
+ _noti_listen(AMD_NOTI_MSG_APPINFO_PACKAGE_UNINSTALL_END,
+ OnAppinfoPackageUninstallEnd);
+ _noti_listen(AMD_NOTI_MSG_APPINFO_PACKAGE_INSTALL_END,
+ OnAppinfoPackageInstallEnd);
+ _noti_listen(AMD_NOTI_MSG_APPINFO_PACKAGE_UPDATE_END,
+ OnAppInfoPackageUpdateEnd);
+ _noti_listen(AMD_NOTI_MSG_APPINFO_PACKAGE_UPDATE_ERROR,
+ OnAppInfoPackageUpdateError);
+ _noti_listen(AMD_NOTI_MSG_APP_STATUS_ADD, OnAppStatusAdd);
+ _noti_listen(AMD_NOTI_MSG_APP_STATUS_DESTROY, OnAppStatusDestroy);
+}
+
bool ResInfoManager::CreateNewUser(uid_t uid) {
- auto resinfo = std::make_shared<ResInfo>(uid);
- if (!resinfo->ResPkgInit()) {
+ auto res_info = std::make_shared<ResInfo>(uid);
+ if (!res_info->ResPkgInit()) {
_E("Failed to initialize res pkg info for uid(%d)", uid);
return false;
}
- resinfo_map_[uid] = std::move(resinfo);
-
+ res_infos_[uid] = std::move(res_info);
return true;
}
bool ResInfoManager::IsUserExist(uid_t uid) {
- if (!resinfo_map_.count(uid))
+ if (!res_infos_.count(uid))
return false;
return true;
}
std::shared_ptr<ResInfo> ResInfoManager::GetUserResInfo(uid_t uid) {
- if (!resinfo_map_.count(uid))
+ if (!res_infos_.count(uid))
return nullptr;
- return resinfo_map_.at(uid);
+ return res_infos_.at(uid);
}
std::shared_ptr<ResAppInfo> ResInfoManager::GetUserResAppInfo(
const std::string& appid, uid_t uid) {
- std::shared_ptr<ResInfo> resinfo = GetUserResInfo(uid);
- if (!resinfo)
- return nullptr;
+ std::shared_ptr<ResInfo> res_info = GetUserResInfo(uid);
+ if (!res_info) return nullptr;
- return resinfo->GetResAppInfo(appid);
+ return res_info->GetResAppInfo(appid);
}
std::shared_ptr<ResPkgInfo> ResInfoManager::GetUserResPkgInfo(
const std::string& pkgid, uid_t uid) {
- std::shared_ptr<ResInfo> resinfo = GetUserResInfo(uid);
- if (!resinfo)
- return nullptr;
+ std::shared_ptr<ResInfo> res_info = GetUserResInfo(uid);
+ if (!res_info) return nullptr;
- return resinfo->GetResPkgInfo(pkgid);
+ return res_info->GetResPkgInfo(pkgid);
}
void ResInfoManager::RemoveUserResInfo(uid_t uid) {
- resinfo_map_.erase(uid);
+ res_infos_.erase(uid);
}
-bool ResInfoManager::RemoveUserResPkgInfo(std::string pkgid, uid_t uid) {
- std::shared_ptr<ResInfo> resinfo = GetUserResInfo(uid);
- if (!resinfo)
- return false;
+bool ResInfoManager::RemoveUserResPkgInfo(const std::string& pkgid, uid_t uid) {
+ std::shared_ptr<ResInfo> res_info = GetUserResInfo(uid);
+ if (!res_info) return false;
- return resinfo->DeletePkgInfo(pkgid);
+ return res_info->DeletePkgInfo(pkgid);
}
-bool ResInfoManager::AddUserResPkgInfo(std::string pkgid, uid_t uid) {
- std::shared_ptr<ResInfo> resinfo = GetUserResInfo(uid);
- if (!resinfo)
- return false;
+bool ResInfoManager::AddUserResPkgInfo(const std::string& pkgid, uid_t uid) {
+ std::shared_ptr<ResInfo> res_info = GetUserResInfo(uid);
+ if (!res_info) return false;
std::shared_ptr<ResPkgInfo> res_pkginfo =
ResPkgInfo::CreateResPkgInfo(pkgid, uid);
- if (!res_pkginfo)
- return false;
-
- resinfo->InsertPkgInfo(std::move(res_pkginfo));
+ if (!res_pkginfo) return false;
+ res_info->InsertPkgInfo(std::move(res_pkginfo));
return true;
}
-bool ResInfoManager::AddUserResAppInfo(
- pkgmgrinfo_appinfo_h handle, uid_t uid) {
- std::shared_ptr<ResInfo> resinfo = GetUserResInfo(uid);
- if (!resinfo)
- return false;
+bool ResInfoManager::AddUserResAppInfo(pkgmgrinfo_appinfo_h handle, uid_t uid) {
+ std::shared_ptr<ResInfo> res_info = GetUserResInfo(uid);
+ if (!res_info) return false;
std::shared_ptr<ResAppInfo> res_appinfo =
ResAppInfo::CreateResAppInfo(handle, uid);
- if (!res_appinfo)
- return false;
-
- resinfo->InsertAppInfo(std::move(res_appinfo));
+ if (!res_appinfo) return false;
+ res_info->InsertAppInfo(std::move(res_appinfo));
return true;
}
-bool ResInfoManager::RemoveUserResAppInfo(std::string appid, uid_t uid) {
- std::shared_ptr<ResInfo> resinfo = GetUserResInfo(uid);
- if (!resinfo)
- return false;
-
- resinfo->DeleteAppInfo(appid);
+bool ResInfoManager::RemoveUserResAppInfo(const std::string& appid, uid_t uid) {
+ std::shared_ptr<ResInfo> res_info = GetUserResInfo(uid);
+ if (!res_info) return false;
+ res_info->DeleteAppInfo(appid);
return true;
}
~ResInfoManager() = default;
public:
- static ResInfoManager& GetInst() {
- static ResInfoManager inst;
- return inst;
- }
+ static ResInfoManager& GetInst();
+ void Init();
bool CreateNewUser(uid_t uid);
bool IsUserExist(uid_t uid);
std::shared_ptr<ResInfo> GetUserResInfo(uid_t uid);
- std::shared_ptr<ResAppInfo> GetUserResAppInfo(
- const std::string& appid, uid_t uid);
- std::shared_ptr<ResPkgInfo> GetUserResPkgInfo(
- const std::string& pkgid, uid_t uid);
+ std::shared_ptr<ResAppInfo> GetUserResAppInfo(const std::string& appid,
+ uid_t uid);
+ std::shared_ptr<ResPkgInfo> GetUserResPkgInfo(const std::string& pkgid,
+ uid_t uid);
void RemoveUserResInfo(uid_t uid);
- bool RemoveUserResPkgInfo(std::string pkgid, uid_t uid);
- bool AddUserResPkgInfo(std::string pkgid, uid_t uid);
+ bool RemoveUserResPkgInfo(const std::string& pkgid, uid_t uid);
+ bool AddUserResPkgInfo(const std::string& pkgid, uid_t uid);
bool AddUserResAppInfo(pkgmgrinfo_appinfo_h handle, uid_t uid);
- bool RemoveUserResAppInfo(std::string appid, uid_t uid);
+ bool RemoveUserResAppInfo(const std::string& appid, uid_t uid);
private:
- std::unordered_map<uid_t, std::shared_ptr<ResInfo>> resinfo_map_;
+ std::unordered_map<uid_t, std::shared_ptr<ResInfo>> res_infos_;
};
} // namespace amd
#include "lib/res_info/res_mount_package_info.hh"
#include <unordered_map>
+#include <utility>
#include "lib/common/log_private.hh"
#include "lib/res_info/res_info.hh"
const std::vector<std::shared_ptr<ResPkgInfo>>& global_packages) {
for (const auto& pkg : allowed_packages) {
pkgids_.insert(pkg->GetPkgId());
- if (pkg->IsLib())
- allowed_lib_paths_.emplace_back(
- pkg->GetRootPath() + ALLOWED_SUFFIX + "/" + pkg->GetResType());
- else
+ if (pkg->IsLib()) {
+ allowed_lib_paths_.emplace_back(pkg->GetRootPath() + ALLOWED_SUFFIX +
+ "/" + pkg->GetResType());
+ } else {
allowed_paths_.emplace_back(pkg->GetRootPath() + ALLOWED_SUFFIX);
+ }
- if (pkg->GetResType().length() < strlen(kGadgetPrefix))
- continue;
+ if (pkg->GetResType().length() < strlen(kGadgetPrefix)) continue;
if (!pkg->GetResType().compare(0, strlen(kGadgetPrefix), kGadgetPrefix)) {
gadget_pkgids_.insert(pkg->GetPkgId());
for (const auto& pkg : global_packages) {
pkgids_.insert(pkg->GetPkgId());
- if (pkg->IsLib())
- global_lib_paths_.emplace_back(
- pkg->GetRootPath() + GLOBAL_SUFFIX + "/" + pkg->GetResType());
- else
+ if (pkg->IsLib()) {
+ global_lib_paths_.emplace_back(pkg->GetRootPath() + GLOBAL_SUFFIX + "/" +
+ pkg->GetResType());
+ } else {
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;
+static int ResInfoGetGadgetResPackagesInfo(
+ uid_t uid, std::optional<ResMountPackageInfo>* info) {
+ std::shared_ptr<ResInfo> res_info =
+ ResInfoManager::GetInst().GetUserResInfo(uid);
+ if (!res_info) return -1;
- pkgmgrinfo_version_compare_type ver_comp;
+ int ret;
+ pkgmgrinfo_version_compare_type version_compare;
std::unordered_map<std::string, std::shared_ptr<ResPkgInfo>> gadget_map;
- for (const auto& [_, res_pkginfo] : resinfo->GetGadgetResPkgs()) {
+ for (const auto& [_, res_pkginfo] : res_info->GetGadgetResPkgs()) {
auto found = gadget_map.find(res_pkginfo->GetResType());
if (found != gadget_map.end()) {
- if (pkgmgrinfo_compare_package_version(
+ ret = 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;
+ res_pkginfo->GetResVersion().c_str(), &version_compare);
+ if (ret != PMINFO_R_OK) continue;
+ if (version_compare != PMINFO_VERSION_NEW) continue;
gadget_map.erase(found);
}
gadget_map[res_pkginfo->GetResType()] = res_pkginfo;
}
- if (gadget_map.empty())
- return 0;
+ 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") {
+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<ResInfo> res_info =
+ ResInfoManager::GetInst().GetUserResInfo(uid);
+ if (!res_info) return -1;
- std::shared_ptr<ResAppInfo> res_appinfo = resinfo->GetResAppInfo(appid);
- if (!res_appinfo)
- return 0;
+ std::shared_ptr<ResAppInfo> res_appinfo = res_info->GetResAppInfo(appid);
+ if (!res_appinfo) return 0;
res_appinfo->ClearResControlMountInfo();
- res_appinfo->UpdateResControlMountInfo(resinfo->GetResPkgs());
+ res_appinfo->UpdateResControlMountInfo(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_appinfo->GetResControlList()) {
- if (res_control.GetAllowedPackage())
- allowed_packages.push_back(res_control.GetAllowedPackage());
- if (res_control.GetGlobalPackage())
- global_packages.push_back(res_control.GetGlobalPackage());
+ 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::set<std::string>& ResMountPackageInfo::GetPkgIds() const {
+ return pkgids_;
+}
+
+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::GetAllowedLibPaths() const {
+ return allowed_lib_paths_;
+}
+
+const std::vector<std::string>& ResMountPackageInfo::GetGlobalLibPaths() const {
+ return global_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 amd
#ifndef LIB_RES_INFO_RES_MOUNT_PACKAGE_INFO_HH_
#define LIB_RES_INFO_RES_MOUNT_PACKAGE_INFO_HH_
-#include <pkgmgr-info.h>
-
+#include <memory>
#include <set>
#include <string>
#include <vector>
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_;
- }
-
- const std::vector<std::string>& GetAllowedLibPaths() const {
- return allowed_lib_paths_;
- }
-
- const std::vector<std::string>& GetGlobalLibPaths() const {
- return global_lib_paths_;
- }
-
- const std::set<std::string>& GetGadgetPkgIds() const {
- return gadget_pkgids_;
- }
-
- const std::vector<std::string>& GetGadgetPaths() const {
- return gadget_paths_;
- }
+ std::optional<ResMountPackageInfo>* info);
+
+ const std::set<std::string>& GetPkgIds() const;
+ const std::vector<std::string>& GetAllowedPaths() const;
+ const std::vector<std::string>& GetGlobalPaths() const;
+ const std::vector<std::string>& GetAllowedLibPaths() const;
+ const std::vector<std::string>& GetGlobalLibPaths() const;
+ const std::set<std::string>& GetGadgetPkgIds() const;
+ const std::vector<std::string>& GetGadgetPaths() const;
private:
std::set<std::string> pkgids_;
#include <fnmatch.h>
+#include <utility>
+
#include "lib/common/log_private.hh"
namespace amd {
+namespace {
+
+class ResPkgInfoBuilder {
+ public:
+ ResPkgInfoBuilder() = default;
+ ~ResPkgInfoBuilder() = default;
+
+ ResPkgInfoBuilder& SetPkgId(const pkgmgrinfo_pkginfo_h handle) {
+ char* pkgid;
+ if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) != PMINFO_R_OK)
+ _E("pkgmgrinfo_pkginfo_get_pkgid() is failed");
+ else
+ pkgid_ = pkgid;
+ return *this;
+ }
-const std::string& ResPkgInfo::GetPkgId() {
- return pkgid_;
-}
+ ResPkgInfoBuilder& SetResType(const pkgmgrinfo_pkginfo_h handle) {
+ char* res_type;
+ 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;
+ }
-const std::string& ResPkgInfo::GetResType() {
- return res_type_;
-}
+ ResPkgInfoBuilder& SetResVersion(const pkgmgrinfo_pkginfo_h handle) {
+ char* res_version;
+ 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;
+ }
-const std::string& ResPkgInfo::GetResVersion() {
- return res_version_;
-}
+ ResPkgInfoBuilder& SetRootPath(const pkgmgrinfo_pkginfo_h handle) {
+ char* root_path;
+ 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;
+ }
-const std::string& ResPkgInfo::GetRootPath() {
- return root_path_;
-}
+ ResPkgInfoBuilder& SetIsLib(const pkgmgrinfo_pkginfo_h handle) {
+ bool is_lib;
+ 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;
+ }
-bool ResPkgInfo::IsLib() {
- return is_lib_;
-}
+ ResPkgInfoBuilder& SetAllowedPkgPrivList(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");
-bool ResPkgInfo::IsBlocked() {
- return is_blocked_;
-}
+ return *this;
+ }
+
+ ResPkgInfo* 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_priv_list_));
+ }
+
+ private:
+ static int ResAllowedPackageCb(const char* allowed_package,
+ required_privilege_h privilege_handle,
+ void* user_data) {
+ if (!allowed_package) return 0;
+
+ auto* builder = reinterpret_cast<ResPkgInfoBuilder*>(user_data);
+ std::set<std::string> privileges;
+ if (pkgmgrinfo_pkginfo_foreach_required_privilege(
+ privilege_handle, RequiredPrivilegeCb, &privileges) !=
+ PMINFO_R_OK)
+ return 0;
+
+ builder->allowed_pkg_priv_list_.emplace_back(
+ std::make_pair(allowed_package, std::move(privileges)));
+ return 0;
+ }
+
+ static int RequiredPrivilegeCb(const char* privilege_name, void* user_data) {
+ if (!privilege_name) return 0;
+
+ auto* privileges = reinterpret_cast<std::set<std::string>*>(user_data);
+ privileges->insert(privilege_name);
+ return 0;
+ }
+
+ private:
+ std::string pkgid_;
+ std::string res_type_;
+ std::string res_version_;
+ std::string root_path_;
+ bool is_lib_ = false;
+ AllowedPkgPrivList allowed_pkg_priv_list_;
+};
+
+} // namespace
+
+ResPkgInfo::ResPkgInfo(std::string pkgid, std::string res_type,
+ std::string res_version, std::string root_path,
+ bool is_lib, AllowedPkgPrivList priv_list)
+ : 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_priv_list_(std::move(priv_list)) {}
+
+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::IsBlocked() const { return is_blocked_; }
bool ResPkgInfo::IsAllowedPkg(const std::string& pkgid,
- const std::set<std::string>& app_priv) {
+ const std::set<std::string>& app_priv) const {
for (const auto& it : allowed_pkg_priv_list_) {
- if (fnmatch(it.first.c_str(), pkgid.c_str(), FNM_NOESCAPE))
- continue;
+ if (fnmatch(it.first.c_str(), pkgid.c_str(), FNM_NOESCAPE)) continue;
bool has_required_priv = true;
for (const std::string& required_priv : it.second) {
break;
}
}
- if (has_required_priv)
- return true;
+
+ if (has_required_priv) return true;
}
return false;
}
-void ResPkgInfo::SetBlocking() {
- is_blocked_ = true;
-}
+void ResPkgInfo::SetBlocking() { is_blocked_ = true; }
-void ResPkgInfo::UnsetBlocking() {
- is_blocked_ = false;
-}
+void ResPkgInfo::UnsetBlocking() { is_blocked_ = false; }
std::shared_ptr<ResPkgInfo> ResPkgInfo::CreateResPkgInfo(
const pkgmgrinfo_pkginfo_h handle) {
- char* pkgid;
- char* res_type;
- char* res_version;
- char* root_path;
- bool is_lib;
- AllowedPkgPrivList allowed_pkg_priv_list;
-
- if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) != PMINFO_R_OK)
- return nullptr;
-
- if (pkgmgrinfo_pkginfo_get_res_type(handle, &res_type) != PMINFO_R_OK)
- return nullptr;
-
- if (pkgmgrinfo_pkginfo_get_res_version(handle, &res_version) != PMINFO_R_OK)
- return nullptr;
-
- if (pkgmgrinfo_pkginfo_get_root_path(handle, &root_path) != PMINFO_R_OK)
- return nullptr;
-
- if (pkgmgrinfo_pkginfo_is_lib(handle, &is_lib) != PMINFO_R_OK)
- return nullptr;
-
- if (pkgmgrinfo_pkginfo_foreach_res_allowed_package(handle,
- [](const char* allowed_package, required_privilege_h privilege_handle,
- void* user_data) -> int {
- if (!allowed_package)
- return 0;
-
- AllowedPkgPrivList* allowed_pkg_priv_list =
- reinterpret_cast<AllowedPkgPrivList*>(user_data);
-
- std::set<std::string> priv_set;
-
- if (pkgmgrinfo_pkginfo_foreach_required_privilege(privilege_handle,
- [](const char* privilege_name, void* user_data) -> int {
- if (!privilege_name)
- return 0;
-
- auto priv_set =
- reinterpret_cast<std::set<std::string>*>(user_data);
- priv_set->insert(privilege_name);
-
- return 0;
- }, &priv_set) != PMINFO_R_OK)
- return 0;
-
- allowed_pkg_priv_list->emplace_back(
- std::make_pair(allowed_package, std::move(priv_set)));
- return 0;
- }, &allowed_pkg_priv_list) != PMINFO_R_OK)
- return nullptr;
-
- return std::shared_ptr<ResPkgInfo>(new ResPkgInfo(pkgid, res_type,
- res_version, root_path, is_lib, std::move(allowed_pkg_priv_list)));
+ ResPkgInfoBuilder builder;
+ return std::shared_ptr<ResPkgInfo>(builder.SetPkgId(handle)
+ .SetResType(handle)
+ .SetResVersion(handle)
+ .SetRootPath(handle)
+ .SetIsLib(handle)
+ .SetAllowedPkgPrivList(handle)
+ .Build());
}
std::shared_ptr<ResPkgInfo> ResPkgInfo::CreateResPkgInfo(
- const std::string pkgid, uid_t uid) {
+ const std::string& pkgid, uid_t uid) {
pkgmgrinfo_pkginfo_h handle;
-
- if (pkgmgrinfo_pkginfo_get_usr_pkginfo(
- pkgid.c_str(), uid, &handle) != PMINFO_R_OK)
+ if (pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid.c_str(), uid, &handle) !=
+ PMINFO_R_OK)
return nullptr;
std::unique_ptr<std::remove_pointer<pkgmgrinfo_pkginfo_h>::type,
- decltype(pkgmgrinfo_pkginfo_destroy_pkginfo)*>handle_auto(
- handle, pkgmgrinfo_pkginfo_destroy_pkginfo);
-
- std::shared_ptr<ResPkgInfo> res_pkginfo = CreateResPkgInfo(handle_auto.get());
+ decltype(pkgmgrinfo_pkginfo_destroy_pkginfo)*>
+ handle_auto(handle, pkgmgrinfo_pkginfo_destroy_pkginfo);
- return res_pkginfo;
+ return CreateResPkgInfo(handle_auto.get());
}
} // namespace amd
class ResPkgInfo {
public:
+ ResPkgInfo(std::string pkgid, std::string res_type, std::string res_version,
+ std::string root_path, bool is_lib, AllowedPkgPrivList priv_list);
+
static std::shared_ptr<ResPkgInfo> CreateResPkgInfo(
const pkgmgrinfo_pkginfo_h handle);
static std::shared_ptr<ResPkgInfo> CreateResPkgInfo(
- const std::string pkgid, uid_t uid);
+ const std::string& pkgid, uid_t uid);
- const std::string& GetPkgId();
- const std::string& GetResType();
- const std::string& GetResVersion();
- const std::string& GetRootPath();
- bool IsLib();
- bool IsBlocked();
+ const std::string& GetPkgId() const;
+ const std::string& GetResType() const;
+ const std::string& GetResVersion() const;
+ const std::string& GetRootPath() const;
+ bool IsLib() const;
+ bool IsBlocked() const;
bool IsAllowedPkg(const std::string& pkgid,
- const std::set<std::string>& app_priv);
+ const std::set<std::string>& app_priv) const;
void SetBlocking();
void UnsetBlocking();
private:
- ResPkgInfo(std::string pkgid, std::string res_type, std::string res_version,
- std::string root_path, bool is_lib, AllowedPkgPrivList priv_list)
- : 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_priv_list_(std::move(priv_list)),
- is_blocked_(false) {}
-
std::string pkgid_;
std::string res_type_;
std::string res_version_;
std::string root_path_;
bool is_lib_;
AllowedPkgPrivList allowed_pkg_priv_list_;
- bool is_blocked_;
+ bool is_blocked_ = false;
};
} // namespace amd